Repository navigation
fix(staging): keep new Durable Object migrations off primary staging - #2809
Merged
simple-agent-manager[bot] merged 10 commits intoNov 16, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reservations are append-only deployment records written by a new queue job outside any concurrency group, so no later dispatch can cancel a waiting agent's place. Only a branch that holds the lease or whose turn it is reaches the serialized lease job. At release or expiry the head of the queue gets a configurable grace period, then the next entry; a releasing holder queues behind existing waiters; reservations expire. Records are version 2, which older workflow copies refuse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- An expired holder's reservation is no longer dropped, so it can take the slot again or queue behind waiters. - A release enters the serialized group only when the branch holds the lease or is queued, and the lease job uses its own group (staging-lease-<installation>), so stray releases and older workflow copies cannot displace an entitled pending run. - The lease job honours the turn the queue job saw (bounded to three grace periods), so a runner or group wait cannot cost the head its turn. - History is read across up to five pages before failing closed. - status parses string payloads for the recorded grace period. - Docs: release only after your own deploy run finished. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A reservation made after the branch's old one expired goes to the back. - A missed head that reserves again is placed by when it reserved, ahead of later reservations. - When a waiter ahead leaves, every remaining entry keeps the end of the turn it was told (promisedEnd), so a sleeping agent cannot miss it. - Snapshots keep recently missed entries for the admission slack, so a delayed lease job can still prove the turn it was let through on. - Reservations record the grace period, so status is right before the first snapshot. - Docs: release comes after every live check; rule 13 states the early-release turn window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A workflow copy from before the queue refuses any version-2 record, so a reservation written over its live lease locks it out of renewing or releasing. While the holder's record is version 1, the queue job writes nothing and tells the caller to wake at the legacy expiry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…imary staging Durable Object migrations only move forward, so a branch that deploys a migration tag main lacks blocks every main-based branch on that installation until it merges. deploy-staging.yml now refuses such deploys on primary staging before a place is reserved, and tells the agent to use staging2. The comparison reads apps/api/wrangler.toml on the branch and on origin/main, and fails closed when it cannot read every tag. Documents the clean-up duty: tear staging2 down and redeploy main before releasing if the branch has not merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 37 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
… deploy condition Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
@coderabbitai review |
Action not completed
|
|
This was referenced Nov 16, 2026
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
Part 2 of SAM task
01M7HK7TY9GA8DTV3BGS4QYNM8(part 1 was #2783, the lease queue). This change keeps branches that add a Durable Object migration off primary staging.Problem: Durable Object migrations only move forward. Draft PR #2721 deployed DO migration tag v23 to primary staging while main was at v22. After that, the migration preflight (
scripts/deploy/durable-object-migrations.ts) failed closed for every main-based branch there until #2721 merged, which collapsed two stagings back to one lane.Change:
scripts/deploy/staging-migration-guard.mjs, run in thequeuejob ofdeploy-staging.yml. It runs only for primary-stagingdeploys, and before a place is reserved.[[migrations]]tags in the branch'sapps/api/wrangler.tomlagainstorigin/main's copy (a shallowgit fetchof main, thengit show FETCH_HEAD:…).staging2.[[migrations]]block's tag can't be parsed.reserve,acquire,releaseand deploys tostaging2are not checked.deploy-reusable.yml,deploy.ymlor the sync script. A test asserts that the reusable workflow does not reference the guard.Clean-up duty (documented, not automated): when such a branch is done on
staging2and has not merged, the lease holder tearsstaging2down (Teardown →staging2→DELETE) and redeploysmainbefore releasing. staging2 rebuilds from nothing.Primary staging today: #2721 merged at 08:11Z, so main is at v23 and primary's earlier v23 state has cleared. Nothing to repair.
Validation
pnpm lint(eslint on changed files). SonarCloud S4036 (git resolved via PATH) fixed in b58aa96: absolute/usr/bin/giton runnerspnpm typecheck(N/A to.mjs)pnpm test:node --test scripts/deploy/staging-migration-guard.test.mjs5 pass (against the realapps/api/wrangler.toml);deploy-staging-permissions.test.ts28 pass (it runs the guard's node tests in CI and pins the step's position and condition)v99tag →Staging deploy refused: This branch adds Durable Object migration tag(s) v99 … Use -f environment=staging2 …(exit 1); the same branch withLEASE_ENVIRONMENT=staging2→ allowedStaging Verification (REQUIRED for all code changes — merge-blocking)
Staging Verification Evidence
Live refusal, 16:18Z (run 43906017573): I pushed a throwaway branch (
sam/migration-guard-proof, since deleted) that adds av99migration tag, and dispatched a primary-staging deploy.Staging deploy refused: This branch adds Durable Object migration tag(s) v99 that origin/main does not have. … Use -f environment=staging2; if the branch has not merged when you are done, tear staging2 down and redeploy main before releasing.Main-based deploys are unaffected: the guard passes when no tag is new. That is shown by the local CLI run and the new git-backed CLI test. The dry-run deploy on #2783 (43901912468) exercised the same queue job.
Design choice: a dry run of a migration branch on primary is also refused. It would be refused for real anyway, and staging2 is where such branches belong.
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
gh workflow run deploy-staging.yml -f environment=staging→ jobqueue→ step "Keep new Durable Object migrations off primary staging" →staging-migration-guard.mjsmain (git fetch origin main,checkInstallation→newMigrationTags→migrationTags) → exit 1 stops the job before thestaging-lease.mjs queuestep, so no reservation is written andlease/deployare skipped.Untested Gaps
N/A: the GitHub step wiring is pinned by the workflow test and shown live in the staging evidence.
Post-Mortem (Required for bug fix PRs)
What broke
A draft PR's DO migration v23 deployed to primary staging blocked every main-based branch there until it merged.
Root cause
Nothing stopped a branch with new forward-only migrations from deploying to the shared primary installation.
Class of bug
An irreversible state change in a shared environment, made by unmerged work.
Why it wasn't caught
The migration preflight protects against inconsistent history, but nothing chose which installation such branches may use.
Process fix included in this PR
The guard itself, plus
.claude/rules/13-staging-verification.md,.claude/commands/do.md,.agents/skills/do/SKILL.mdand the full reference (clean-up duty).Post-mortem file
tasks/archive/2026-11-16-staging-lease-fair-queue.mdSpecialist Review Evidence (Required for agent-authored PRs)
needs-human-reviewlabel added and merge deferred to humanif:could drift from the deploy job → the test now asserts it contains the deploy job's condition. LOW 4 → doc sentence (the guard runs from the branch's workflow copy; the preflight is the backstop). LOW 5 →::error::annotation. LOW 3 (a dry run of a migration branch on primary is refused) is kept by design. LOW 6 (name-only comparison) is accepted: it does not cause the ordering problem.CodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
coderabbit-reviewlabel applied when marked ready. The label-triggeredcoderabbit-bot-review.ymlruns ended instartup_failure(43906434315, 43906446710).coderabbit-bot-review.ymlfrom main once (43909800652). CodeRabbit replied at 16:39Z: "Action not completed. Review rate limited."Exceptions (If any)
Agent Preflight (Required)
Classification
External References
N/A: no external API; the change uses git and the existing wrangler.toml format (
[[migrations]]withtag = "vN"), as read byscripts/deploy/durable-object-migrations.ts.Codebase Impact Analysis
.github/workflows/deploy-staging.yml(jobqueue), newscripts/deploy/staging-migration-guard.mjswith its test,scripts/quality/deploy-staging-permissions.test.ts. No production workflow and no app code.Documentation & Specs
.claude/rules/13-staging-verification.md,.claude/commands/do.md,.agents/skills/do/SKILL.md,.agent-instructions/reference/rules/13-staging-verification-full.md.Constitution & Risk Check
Principle X: the smallest check, at the point where the installation is chosen. Fail closed on an unreadable comparison. Risk: a branch that only reorders or renames tags would be refused on primary; that is acceptable and easy to diagnose from the message.
🤖 Generated with Claude Code