Skip to content

perf: bake vm-agent into instant container image to cut cold-start latency#1566

Merged
simple-agent-manager[bot] merged 8 commits into
mainfrom
sam/priority-4-materially-reduce-dg2m5w
Jul 12, 2026
Merged

perf: bake vm-agent into instant container image to cut cold-start latency#1566
simple-agent-manager[bot] merged 8 commits into
mainfrom
sam/priority-4-materially-reduce-dg2m5w

Conversation

@simple-agent-manager

@simple-agent-manager simple-agent-manager Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Materially reduces instant Cloudflare Container cold-start latency by removing the per-container network install of vm-agent and baking the deployment-built binary into the runtime image. It also adds bounded phase timings so the remaining latency is attributable.

Key changes:

  • Builds/version-tags Linux AMD64 vm-agent before Wrangler deploy, then copies the binary and vm-agent-version.json into Dockerfile.vm-agent-container.
  • Removes the mandatory fresh-container download; bootstrap validates the baked binary/version, emits secret-free timing/version telemetry, and fails fast if either artifact is absent.
  • Adds totalDurationMs, preContainerDurationMs, and containerLaunchDurationMs, while retaining deprecated response aliases for compatibility.
  • Preserves PR Runtime-neutral env/file/secret injection for instant cf-container ACP #1561's runtime-assets boundary: user/project/profile/skill files and secrets are still resolved only at ACP session start and never enter image layers or launch configuration.
  • Adds behavioral, contract, timing, cleanup, no-secret, version-parity, and deploy-ordering coverage.

Validation

  • True linear rebase onto ad7044fde (PR Phase 3a: runtime-neutral session hibernate/wake #1562); rebased tree matched the reviewed merge resolution
  • pnpm lint
  • pnpm typecheck
  • pnpm test (404 API files / 5,918 tests; 217 web files / 2,668 tests)
  • pnpm build
  • /usr/local/go/bin/go test ./... with Go 1.25.0
  • Targeted cold-start tests (16 API + 7 deploy-workflow)
  • Actual container-image build and normal-entrypoint probe; /health returned healthy and baked bootstrap-ready telemetry emitted in 3 ms

Staging Verification (REQUIRED — merge-blocking)

  • Staging deployment green
  • Live app verified
  • New feature verified with a genuinely fresh container and real ACP response
  • Temporary staging resources cleaned up
  • N/A: no UI-visual changes — backend and infrastructure only

Staging Verification Evidence

Deployment run 29185746568 passed Cloudflare deploy, backup/count baseline, migration integrity, API health, and Playwright smoke tests. It deployed implementation commit fc22f3e80c8ab436cab63e3e50fdf1008b24554c with baked artifact sha256:3653de9b288c7bed684b72dc84fd0f033835f0170cf19e58a479b9984554e949 and VmAgentContainer image digest sha256:b50c3fb289b42c39284ea07dd85f7af073119953aeaf4b6ee7a53dba1a04d408.

A fresh launch created node 01KXAQFTDZBGFGPX5XZ0RSYTC9, workspace 01KXAQFTJW9YVZCVB1A8T5JXJP, and session 1637b2b0-a9cb-4e56-b0ad-5c7733dc4fa1. The API returned HTTP 201 and the agent completed a real response.

Measurement Baseline PR #1566 Change
Server-side total 16,674 ms 9,161 ms -7,513 ms / 45.1%
Client-observed request 13.408 s

Post-change phase slices: pre-container 724 ms; container launch 2,584 ms; agent-ready 567 ms; workspace create 2,898 ms; ACP session create 2,237 ms; ACP session start 842 ms.

Authenticated browser checks for dashboard, the new session, and project agent settings all returned HTTP 200. Session content rendered with no unexpected console, page, or network errors. The API health endpoint returned HTTP 200/healthy. The temporary session was stopped; staging D1 confirmed the node was deleted and its workspace row removed.

The result is materially improved but remains above the <5s target. Evidence and the next dominant slices (workspace creation, container launch, ACP creation) were appended to SAM idea 01KX6JK8ZFC1EFWGYQENRMFWFK rather than claiming the target was met.

End-to-End Verification (multi-component)

  • Build/deploy path verified: workflow → Go build/version metadata → Docker context → Wrangler container image
  • Runtime path verified: container bootstrap → baked artifact validation → vm-agent ready → workspace/ACP creation → real agent response
  • Security boundary verified by negative contract tests and staging launch configuration
  • Cleanup path verified through product API and staging D1
  • pnpm quality:observability-noise found no significant noise; D1/Workers telemetry subchecks were explicitly unavailable in this environment

Specialist Review Evidence (agent-authored PR)

  • All local reviewers completed and findings addressed
Reviewer Status Outcome
cloudflare-specialist ADDRESSED Local Docker prerequisite documented; timing aliases deprecated; minor DB-write timing note accepted
test-engineer ADDRESSED Added no-secret assertions, executed bootstrap tests, timing invariants, failure cleanup, and version-shape tests
security-auditor ADDRESSED Secret boundary held; version parity and negative contracts added; runtime re-hash declined because it adds cold-path cost without a separate trust root
doc-sync-validator ADDRESSED Architecture and API/self-host docs synchronized
env-validator PASS Go setup ordering and version parity covered
go-specialist PASS Portable sha256sum/shasum fallback added
constitution-validator PASS No hardcoded business values introduced
task-completion-validator ADDRESSED Research/checklist/diff/criteria paths covered; staging vertical slice documented; only merge/production monitoring remains intentionally open

No reviewer is pending or failed. All CRITICAL/HIGH findings were addressed.

Post-Mortem

N/A: performance and observability improvement, not an incident fix.

Agent Preflight (Required)

  • Preflight completed before code changes

Classification

  • external-api-change
  • cross-component-change
  • business-logic-change
  • public-surface-change
  • docs-sync-change
  • security-sensitive-change
  • ui-change
  • infra-change

External References

N/A: this uses the repository's existing Cloudflare Containers, Wrangler, Go, and Make deployment path.

Codebase Impact Analysis

  • Workflow and Makefile generate/version the container binary before Wrangler deploy.
  • Dockerfile/bootstrap consume and validate the baked artifact without embedding runtime secrets.
  • Instant-session API and web response type expose bounded timing fields with compatible aliases.
  • Contract, behavioral, workflow, Go, and staging E2E verification cover the affected boundaries.

Documentation & Specs

Updated architecture overview, API reference, and self-hosting guide for baked artifact/version behavior.

Constitution & Risk Check

Generated version metadata derives from the deployment commit; artifact paths remain configurable; no new manual secret or environment prerequisite was added. Missing/mismatched baked artifacts fail fast and are observable rather than silently downloading on the cold path.

@simple-agent-manager simple-agent-manager Bot added the needs-human-review Agent could not complete all review gates — human must approve before merge label Jul 11, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing sam/priority-4-materially-reduce-dg2m5w (7c2ec9f) with main (ad7044f)

Open in CodSpeed

@simple-agent-manager simple-agent-manager Bot removed the needs-human-review Agent could not complete all review gates — human must approve before merge label Jul 11, 2026
raphaeltm and others added 7 commits July 12, 2026 08:00
Autofix simple-import-sort in the deploy-reusable workflow contract test
and apply prettier table alignment to the architecture overview doc so the
lint and format CI gates pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes HIGH and consensus-MEDIUM findings from the specialist review of the
baked vm-agent container image:

- test: assert the image bakes no secrets (no ARG / secret-bearing ENV) and
  that vm-agent-version.json carries only build metadata (test-engineer H1)
- test: add behavioral vm-agent-bootstrap.sh tests exercising the fail-fast
  missing-artifact path and the success path (test-engineer H2). Parameterize
  the bootstrap binary/version/state paths (env with prod defaults) so the
  script is executable in a test sandbox
- test: assert timing monotonicity + all timing fields, and add a launch
  failure-path test proving the container is destroyed and the workspace is
  marked error (test-engineer H3/M1)
- ci: version R2 vm-agent binaries with $GITHUB_SHA so they match the
  container-baked binary; assert Go setup precedes prepare-container and the
  version parity in the workflow contract test (4-reviewer consensus)
- build: make prepare-container sha256 portable (sha256sum or shasum)
- docs: mark setup/install timings as deprecated aliases; note the container
  image bakes the binary so /api/agent/download is VM/cloud-init only; add the
  bake step to the deploy pipeline diagram; document the local docker build
  prerequisite in the Dockerfile

Deliberately NOT adding runtime sha256 verification in the bootstrap: the
Makefile computes the digest from the same binary it bakes in the same step,
so a binary<->version.json comparison cannot fail from a supply-chain angle,
and hashing a ~25MB binary on every boot works against the cold-start goal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@simple-agent-manager simple-agent-manager Bot marked this pull request as ready for review July 12, 2026 09:10
@simple-agent-manager simple-agent-manager Bot merged commit 085943a into main Jul 12, 2026
40 of 41 checks passed
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.

1 participant