Skip to content

fix(lib): default 'agentex agents build' to --no-cache so stale layers can't ship stale source - #476

Merged
deepthi-rao-scale merged 3 commits into
nextfrom
fix/tutorial-agent-latest-no-cache
Jul 29, 2026
Merged

fix(lib): default 'agentex agents build' to --no-cache so stale layers can't ship stale source#476
deepthi-rao-scale merged 3 commits into
nextfrom
fix/tutorial-agent-latest-no-cache

Conversation

@deepthi-rao-scale

@deepthi-rao-scale deepthi-rao-scale commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Problem

The tutorial-agent build/publish pipeline can silently republish a stale image to the moving :latest tag. agentex agents build calls docker.buildx.build(...) with no cache control, so a cached layer can ship source that no longer matches the checkout — and the publish job still reports success, so the staleness is invisible.

Concrete failure: the mcp<2 pin merged for the 020_state_machine agent (2b7649c) never reached …/020_state_machine:latest. The build re-published a byte-identical December 2025 image (pre-pin source). scale-agentex's integration suite pulls :latest, so the 10-async-10-temporal-020-state-machine test runs the months-old image, uvx mcp-server-time resolves mcp==2.0.0, and the McpErrorMCPError rename crashes it:

ImportError: cannot import name 'McpError' from 'mcp.shared.exceptions'. Did you mean: 'MCPError'?

This currently reddens that required check on unrelated PRs (e.g. scale-agentex #384, #385).

Fix

Make the build cache-free by default and expose a toggle:

  • build_agent() gains cache: bool = False → passed through to docker.buildx.build (cache=Falsedocker buildx build --no-cache).
  • agentex agents build exposes --cache/--no-cache, defaulting to --no-cache.

So a bare agentex agents build no longer caches — which means the existing build-and-push-tutorial-agent.yml needs no change (it already runs a bare build). A stale cached layer can no longer get published. --cache is available to opt back in for faster local rebuilds when you know the cache is safe.

Effect / rollout

This changes the SDK CLI, and the build workflow installs agentex-sdk from PyPI (pip install agentex-sdk==<latest>), not from the repo checkout. So it takes effect once:

  1. this merges and agentex-sdk is released to PyPI with it, then
  2. a tutorial-agent build runs (push to main touching examples/tutorials/**, or a rebuild_all dispatch) and pip-installs that version.

That rebuild will produce 020_state_machine:latest from current source (which already has the mcp<2 pin), turning the scale-agentex integration check green. It also prevents this silent-stale-publish class for every tutorial agent.

Related

Build-provenance work (#454, releasing in #475) records a deterministic working-tree hash; if later wired in as a cache key it would be a more surgical fix. This is the immediate, guaranteed prevention and doesn't touch those files.

Testing

  • python -m py_compile on both changed modules ✓
  • cache=False maps to python-on-whales docker.buildx.build(cache=False) → buildx --no-cache

🤖 Generated with Claude Code

Greptile Summary

This PR fixes a silent stale-layer problem where agentex agents build could republish a byte-identical cached image to a moving tag like :latest without any indication that the source had changed.

  • Adds cache: bool = False to build_agent() in agent_handlers.py, passing it directly into docker_build_kwargs["cache"] before both docker.buildx.build() call-sites; the python-on-whales library maps cache=False to docker buildx build --no-cache.
  • Exposes --cache/--no-cache on the agentex agents build CLI command (via typer.Option), defaulting to --no-cache, so existing bare invocations in CI workflows immediately benefit without any workflow changes.

Confidence Score: 5/5

Safe to merge — a two-parameter addition with no behavioural regressions on the happy path.

Both changed files are small and self-contained. The cache parameter maps correctly to the python-on-whales docker.buildx.build(cache=False) API (confirmed via docs), the typer option is wired end-to-end without any intermediate transform, the default of False matches the stated intent, and the pre-existing --push/--registry guard is untouched. No edge-case issues were found.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/agentex/lib/cli/handlers/agent_handlers.py Adds cache: bool = False to build_agent(), correctly threads it into docker_build_kwargs["cache"] before both docker.buildx.build() calls; python-on-whales API confirms cache=False emits --no-cache.
src/agentex/lib/cli/commands/agents.py Exposes --cache/--no-cache via a typer.Option defaulting to False; wires the value through to build_agent(). No logic issues.

Sequence Diagram

sequenceDiagram
    participant User as CLI User
    participant CLI as agents.py (build cmd)
    participant Handler as agent_handlers.py (build_agent)
    participant Docker as docker.buildx.build (python-on-whales)

    User->>CLI: "agentex agents build [--cache | --no-cache]"
    Note over CLI: cache: bool = False (default = --no-cache)
    CLI->>Handler: "build_agent(..., cache=cache)"
    Handler->>Handler: "Assemble docker_build_kwargs {cache: cache}"
    alt "cache == False (default)"
        Handler->>Handler: logger.info(Build cache disabled)
        Handler->>Docker: "docker.buildx.build(**kwargs) → --no-cache"
    else "cache == True"
        Handler->>Docker: "docker.buildx.build(**kwargs) → with cache"
    end
    Docker-->>Handler: image built
    Handler-->>CLI: image_name
    CLI-->>User: Successfully built image: ...
Loading

Reviews (3): Last reviewed commit: "make no-cache the default and drop the w..." | Re-trigger Greptile

@deepthi-rao-scale
deepthi-rao-scale marked this pull request as draft July 29, 2026 19:56
@deepthi-rao-scale deepthi-rao-scale changed the title fix(lib): build ':latest' tutorial agents with --no-cache to stop shipping stale source fix(lib): default 'agentex agents build' to --no-cache so stale layers can't ship stale source Jul 29, 2026
@deepthi-rao-scale
deepthi-rao-scale marked this pull request as ready for review July 29, 2026 20:32
deepthi-rao-scale and others added 3 commits July 29, 2026 16:42
…pping stale source

The tutorial-agent build/publish pipeline could silently republish a stale
image to the moving ':latest' tag. 'agentex agents build' invoked
'docker.buildx.build' with no cache control, so a cached layer could ship
source that no longer matched the checkout -- e.g. the merged 'mcp<2' pin for
the 020_state_machine agent never reached ':latest', leaving integration tests
pulling a months-old image and failing on the mcp 2.0.0 'McpError' rename.

- add a 'cache' param to build_agent() -> passes cache=False (buildx
  --no-cache) through to the build
- expose '--cache/--no-cache' on 'agentex agents build' (default: cache on, so
  local dev and immutable SHA builds stay fast)
- build-and-push-tutorial-agent.yml uses --no-cache only for the ':latest'
  publish path; SHA-tagged validation builds keep the cache

Related: build-provenance work (#454) records a working-tree hash and could
later provide a more surgical cache-key-based fix; this is the immediate,
guaranteed prevention.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Force --no-cache on every build in the publish workflow (both the ':latest'
push path and SHA-tagged validation builds), not just the mutable-tag path.
Simpler and removes any chance of a stale cached layer shipping outdated
source; costs only a few minutes of build time.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Default 'agentex agents build' to --no-cache instead of forcing it in the
publish workflow. A bare 'agentex agents build' is now cache-free, so the
build-and-push workflow needs no change and the diff shrinks to the CLI.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@deepthi-rao-scale
deepthi-rao-scale changed the base branch from main to next July 29, 2026 20:42
@deepthi-rao-scale
deepthi-rao-scale force-pushed the fix/tutorial-agent-latest-no-cache branch from 12e43ca to 951e7dc Compare July 29, 2026 20:42
@deepthi-rao-scale
deepthi-rao-scale merged commit 632d82c into next Jul 29, 2026
48 checks passed
@deepthi-rao-scale
deepthi-rao-scale deleted the fix/tutorial-agent-latest-no-cache branch July 29, 2026 20:51
@stainless-app stainless-app Bot mentioned this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants