Repository navigation
fix(deploy): automatic production gate deploys the current main tip - #2777
Merged
simple-agent-manager[bot] merged 3 commits intoNov 16, 2026
Merged
Conversation
Overlapping main CI runs finish out of order and GitHub keeps one pending run in the deploy-production group, so an older commit's deploy run could replace the tip's pending run and then fail closed, leaving the tip undeployed until the next merge. The automatic gate now treats the triggering SHA as a wake-up signal only: after the queue it reads the current main tip and deploys it only when the tip has its own successful CI push run on main, skipping when the tip's CI is not green yet (its own completion triggers a later run) or when the latest production marker already records the tip. API errors fail closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
@coderabbitai review |
Action not completed
|
Address review: a run triggered by the tip's own successful CI that cannot find that run now fails closed instead of skipping silently; the already-deployed skip records the marker deployment id; deployment pagination is tested; the architecture overview and security docs describe the tip-selecting gate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
simple-agent-manager
Bot
deleted the
sam/close-gap-automatic-production-qaqp1h
branch
November 16, 2026 04:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Closes the automatic production deploy queue gap left by #2763 (idea
01M7FYGMEESYH3AJZJ0CT3NKCZ, "Known limit").Problem. Since #2763 main CI runs overlap and can finish out of order.
deploy.ymlputs every trusted candidate in the singledeploy-productionconcurrency group (cancel-in-progress: false), and GitHub keeps one pending run per group. If deploy W is running, the tip Y's CI finishes (Y's run goes pending), then an older commit X's CI finishes (X's run replaces Y's), X ran after W, failed closed at the tip check, and nothing deployed Y until the next merge or a manual dispatch.Fix (design A). On the automatic path the triggering SHA is only a wake-up signal. After the queue,
validateAutomaticProductionDispatch(scripts/deploy/validate-production-dispatch.ts):maintip;ci.ymlruns for that exact SHA (event=push,branch=main) and requires one accepted by the existingselectSuccessfulCiRun(nameCI,push,main, this repository,success);mark-production-deploymentwrites (same rule asrelease.yml: newestdeploy.yml, non-dry-run marker whose latest status issuccess);deploy_sha=<tip>.Any GitHub API error or malformed response throws, so the run fails closed before production mutation.
deploy.ymlnow also skips thedeployjob whendeploy_shais empty, becausedeploy-reusable.ymlwould otherwise fall back togithub.sha.Why not re-dispatch (design B). Re-dispatching
deploy.ymlfor the tip when a stale candidate is detected needsactions: writeon the token, starts a second run that goes through the same queue (where it can itself be displaced), and spreads the decision over two runs. Design A keeps one run, one decision, and adds only read-onlydeployments: readon the singlevalidate-automatic-dispatchjob, used to read the markers. The marker read is required for the "already deployed" check; nobody without write access can create a deployment, and a forged marker could only cause a skip, never a deploy.Invariants kept. Deploys stay serialized (concurrency unchanged). The deployed SHA is always the trusted main tip read after the queue, with a successful CI push run on main in this repository on that exact SHA. Fail closed on API error or ambiguity. The manual
workflow_dispatchpath and its audited emergency override are untouched.Behaviour change worth knowing: if the tip's deploy failed (no marker), a later out-of-order CI completion retries the tip's deploy. Deploys are idempotent, and previously a failed tip stayed undeployed until the next merge.
Also: a run triggered by the tip's own successful CI that cannot find that run (API/filter inconsistency) fails red rather than skipping, since no later event would retry it.
Docs: the
ci.ymlconcurrency comment,/doPhase 7b, andarchitecture/overview.md/architecture/security.mdnow describe the tip-selecting gate. The Codexdoskill had no copy of the recovery wording;CLAUDE.mddid not describe the old behaviour.Validation
pnpm lint(eslint on changed files: new test clean; validator/old test errors are pre-existing onmain)pnpm typecheck(npx tsc --project scripts/deploy/tsconfig.json --noEmit, the CI command for these scripts)pnpm test—pnpm quality:scripts:test: 70 files, 1151 tests passedNew
scripts/quality/automatic-production-deploy-queue.test.tsmodels thedeploy-productiongroup (one running, one pending, newer queued run replaces pending) and drives the real validator against a stubbed GitHub API, asserting at every start that anything deployed is the tip with its own green CI:deploy_shawritten.Mutation checks (each reverted afterwards): reinstating the old "trigger must equal tip" check reddened 12/16, including the reported sequence; removing the already-deployed check reddened the 2 double-deploy tests; removing the tip-CI gate reddened 5 (pending, failed control, non-tip green, untrusted runs, decision).
deploy-safety.test.tsnow asserts thedeploy_sha != ''guard on thedeployjob and the job's exact permissions.Staging Verification (REQUIRED for all code changes — merge-blocking)
deploy.yml'sworkflow_runproduction pathscripts/deploychange is the production gate only)Staging Verification Evidence
N/A: this changes only the production
workflow_rundeploy gate, whichdeploy-staging.ymldoes not run. The dispatcher stated that the proof is the tests plus watching real production deploys after merge; post-merge evidence will be added to idea01M7FYGMEESYH3AJZJ0CT3NKCZ.UI Compliance Checklist (Required for UI changes)
N/A: no UI changes.
UI Screenshot Evidence
N/A: no UI changes.
End-to-End Verification (Required for multi-component changes)
Data Flow Trace
CI
pushon main completes →deploy.ymlon.workflow_run→ concurrency groupdeploy-production(queue) → jobvalidate-automatic-dispatch→validate-production-dispatch.ts:validateAutomaticProductionDispatch()→getCurrentMainTip()→listCiRuns()+selectSuccessfulCiRun()→getLatestProductionDeployedSha()→$GITHUB_OUTPUT deploy_sha→ jobdeploy(if … outputs.deploy_sha != '') →deploy-reusable.ymlwithtarget_commit_sha→mark-production-deploymentwrites the marker read by the next run.Untested Gaps
GitHub's real concurrency queue and API are modelled, not exercised. After merge I will watch the production Deploy Production runs (including, if two merges land close together, that the tip is deployed) and record the evidence on the idea.
Post-Mortem (Required for bug fix PRs)
What broke
A merged change could sit undeployed after main CI runs finished out of order: the tip's pending deploy run was replaced by an older commit's run, which failed closed.
Root cause
#2763 made main CI runs overlap (one concurrency group per commit) while
deploy.ymlstill validated the triggering run's SHA, which only matched the tip when completion order matched commit order.Class of bug
A queued job that validates its trigger instead of the current state, under a queue that drops intermediate entries.
Why it wasn't caught
Known and documented by the #2763 author as a limit, with /do papering over it by manual recovery.
Process fix included in this PR
.claude/commands/do.mdPhase 7b no longer asks agents to recover by hand;ci.ymlcomment updated; queue-simulation tests guard the sequence.Post-mortem file
Idea
01M7FYGMEESYH3AJZJ0CT3NKCZ(note added with design and evidence).Specialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to humandeploy-reusable.ymlgithub.shafallback) guarded indeploy.yml; fail-fast in the reusable workflow requested from its owner (PR #2770) onfeature.ship-faster, since this task must not edit it. LOW 4 hardening accepted as-is (manual-pathselectSuccessfulCiRunkept unchanged by constraint).architecture/overview.mdsentence fixed in a4e3591 (andsecurity.mdaligned); task file checkboxes ticked; deployments-pagination test and retry-on-failed-deploy note added.CodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
Requested at 03:00Z by applying
coderabbit-reviewwhen the PR was marked ready; the trusted workflow posted the review command and CodeRabbit replied "Review triggered" at 03:00:39Z. Its check on heada4e3591concludedskippedwith "Review skipped: automatic reviews are disabled", and no review or review comment arrived by 04:28Z (~87 min). Outcome: no CodeRabbit review; merging on the remaining gates per rule 25.Exceptions (If any)
main.Agent Preflight (Required)
Classification
External References
GitHub REST API (official docs):
GET /repos/{owner}/{repo}/git/ref/heads/main,GET /repos/{owner}/{repo}/actions/workflows/{id}/runs(head_sha,branch,eventfilters),GET /repos/{owner}/{repo}/deployments?environment=(newest first, needsdeployments: read),GET …/deployments/{id}/statuses. GitHub Actions concurrency docs: one running and one pending run per group; a newly queued run replaces the pending one. Existing marker-reading logic in.github/workflows/release.ymlreused as the rule.Codebase Impact Analysis
.github/workflows/deploy.yml(automatic validate job, deploy jobif),scripts/deploy/validate-production-dispatch.ts(automatic path; manual path unchanged apart from shared request helpers),scripts/quality/*tests,.github/workflows/ci.ymlcomment,.claude/commands/do.mdPhase 7b.deploy-reusable.ymluntouched (owned by PR #2770).Documentation & Specs
.claude/commands/do.md,ci.ymlcomment,apps/www/src/content/docs/docs/architecture/overview.md,apps/www/src/content/docs/docs/architecture/security.md.Constitution & Risk Check
Principle XI: no new tunables, URLs derived from
GITHUB_REPOSITORY. Principle X (simplicity): one run, one decision, read-only permission instead ofactions: write. Risk: a skipped deploy job if the marker lookup misreads; covered by tests and fails toward deploying (no marker ⇒ deploy), never toward deploying a non-tip SHA.🤖 Generated with Claude Code