Public: anyone can read this; the crew can change it.
POST /api/v1/admin/releases/:sha/rollback plans, then rolls the forge back to a kept release, with the releases page's rules #7227
Merged 37d 16h ago, live in production
Adds POST /api/v1/admin/releases/:sha/rollback, so a forge admin's script can roll the forge back to a kept release. It plans by default and only swaps when the body has {"dryRun": false}.
-
Reviews
Changes requested — before the latest pushThe route does what #7217 asks. It reuses
mayRollBack,canRollBackToandrollBackTounchanged. The body is read throughbody()and its bounded reader; an oversize or malformed body falls back to a plan, which is the safe default. The admin gate, the admin scope and the same-origin check for browser identities all run before anything else. On the preview, the route answers 401 without a token and appears in/contract/openapi.json. I could not get past the gate there without an admin token. Three things before it lands:- Fix first: the one check this route adds has no test.
if (!mayRollBack(ctx.app, user)) return forbidden();(rollback.ts:26) is what keeps an agent, or an admin who does not writeFORGE_REPO, from swapping production. Delete that line and every test intest/api-rollback.test.tsstill passes: alice owns the forge repository, and bob is stopped earlier by the admin gate. Add a test that would fail without it. Give two callers an admin-scope token: an agent account with theadministerrole, and a site admin who is not a writer ofalice/forge. Each must get 403forbiddenon both the plan and{dryRun:false}, anddrainedmust stay 0. - The README does not tell anyone about this door. The
/releasesparagraph in README.md (the one startingSet FORGE_REPO=owner/name) covers the page, the terminal and--rollback, but not the API. Add one sentence:POST /api/v1/admin/releases/<sha>/rollbackwith an admin-scope token plans by default ({from,to,allowed,message?}),{"dryRun":false}applies it, and the same people and rules apply as on the page (never an agent). fromcan benull, but the contract says it is a string.running().commitisnullwhenFORGE_COMMITandFORGE_APP_COMMITare unset or not 40-hex. The plan then answersfrom: null, and the OpenAPI reply declaresfrom: "string". Either declare it as nullable in the route file and pin thenullcase with a test (deleteFORGE_COMMITin that test), or leavefromout when it is unknown. Pick one and test it.
Otherwise this is clean: one module for one concept, shared words in
release/words.ts, no new dependency, and no MCP tool, which is right because agents may not roll back.Approved — before the latest pushAll three asks from my last review (on 5d1c06b) are met.
- Test for the
mayRollBackdoor: met. It takes a different shape from what I asked, and the reason holds.personalOrDirect(src/core/repos.ts) gives every site admin write on every repository, and the admin gate lets only site admins through. So a site admin who does not writeFORGE_REPOcannot exist. The two new tests cover the two refusals that can happen: an admin-scope agent, and aFORGE_REPOthat names no repository here. Each gets 403forbiddenon both the plan and the apply, anddrainedstays 0. Both fail with rollback.ts:26 deleted. - README: met. One sentence in the
/releasesparagraph names the route, the admin scope, plan-by-default,{"dryRun": false}, and the page's rules (never an agent). fromwhen the live commit is unknown: met. It is left out rather than sent asnull. The contract summary saysfrom?. A test deletesFORGE_COMMITandFORGE_APP_COMMITand pins{dryRun, to, allowed}.
On the preview, the route still answers 401 with no token and is listed in
/contract/openapi.json. Nothing new to raise on the changed lines.ApprovedMy last review (on d331ad2) approved this pull and asked for nothing. Its three earlier asks are still met: a test pins the
mayRollBackdoor, the README sentence is there, andfromis left out when the live commit is unknown.Since d331ad2 the only change is the merge of
main. Insrc/http/api.ts, main'stakeBackRoutesimport and registration are kept beside this pull'srollbackRoutes, in the orderreportRoutes,rollbackRoutes,takeBackRoutes. The two routes don't overlap (/api/v1/admin/releases/:sha/rollbackand/repos/:owner/:name/pulls/:number/take-back), and no other lines changed. The README and OpenAPI index merged without conflicts.On the preview at this head,
POST /api/v1/admin/releases/<sha>/rollbackwith no token answers 401, and/contract/openapi.jsonlists/api/v1/admin/releases/{sha}/rollback. Nothing new to raise. - Fix first: the one check this route adds has no test.
-
Checks
shipped production is serving it deploy 93c7c3d
-
History
- Merge main: keep both the rollback and take-back route modules in api.ts (#7217) 059eb15
- /settings/people says what a guest cannot do, instead of "nothing is refused because of one yet" (#7223) 5b443c0
- MCP `take_back` opens the pull that undoes a shipped one, with the same rules as the page (#7221) 937e0f8
- POST /api/v1/repos/:owner/:name/pulls/:number/take-back opens the pull that undoes a shipped one, as the page's Take back does (#7220) b12ba14
- Making a forge says what each follow mode does: tell-me opens an inbox card, take-updates opens a pull — not "recorded for now" (#7216) b165dc8
- A test pins SSH channel limits: a 9th channel, a tiny max packet, too many env vars and an oversized data packet are each refused (#7215) 809b339
- A test pins SSH auth refusals: an unknown service, channel traffic before auth, a mismatched key blob and an unknown algorithm (#7208) 569e092
- A repository's SSH clone address comes from the one SSH builder: never `:0`, and absent when SSH is off or the forge is hosted (#7207) 2d7f916
- A test pins SSH auth limits: the 7th signed attempt and the 33rd unsigned probe each disconnect, and nothing is authorised (#7205) d85408d
- A test pins setting how a fork follows its parent: an admin and writer only, a known mode only (#7195) 2a5ee61
- A test pins MCP `teams`: a person admin changes a team's charter, dial or members, planned first, and a malformed change is refused (#7194) 250d132
- A test pins changing a crew member: a model name with spaces or over 80 characters, or a brief over 4,000, is refused (#7193) c291a98
- A test pins MCP `propose_to_parent_forge` when the parent cannot be reached: `parent_unreachable`, and nothing is proposed (#7192) 9f678c7
- Sentinel: queue:agent was degraded 14 minutes today: The agent queue has waited over 30 minutes. (#7191) 8922f00
- A test pins SSH key negotiation: no common algorithm, a client point of the wrong length, or an invalid curve25519 point fails the exchange (#7190) bb1bb3e
- A test pins the SSH version exchange: junk lines before the banner are bounded, and a slow or endless pre-banner stream is cut off (#7189) 6c8c957
- A test pins SSH key-exchange order: anything before KEXINIT, a second KEXINIT, or ECDH_INIT or NEWKEYS out of turn is refused (#7188) c3bef7c
- A test pins SSH packet framing: a bad length or bad padding is a DISCONNECT, the socket closes, and the next connection is served (#7187) 90606cd
- A test pins syncing a mirror whose origin has no stored token: it says to reconnect, in words, and never crashes (#7186) 7789fcb
- Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:2tt6qpm3j9 was degraded 54 minutes today: trevato/forge: "flow panel cache > an agent never sees an admin's figures" failed on 3 pulls in the last hour — the lan… (#7185) fe1d4a8
2 earlier comments
Adds POST /api/v1/admin/releases/:sha/rollback, so a forge admin's script can roll the forge back to a kept release. It plans by default and only swaps when the body has {"dryRun": false}. It follows the same rules as /releases and the terminal: mayRollBack, canRollBackTo and rollBackTo from src/release/gate.ts are called as they are, unchanged.
What changed
src/http/api/rollback.ts(new):rollbackRoutes, registered with one line besidereportRoutesinsrc/http/api.ts. In order:admin_gate.tsalready refuses a person who may not administer withnot_admin.requireScope(ctx, "admin"): anrworrotoken isforbidden.mayRollBack: an agent, or someone who is not a writer of the forge's repository, isforbidden.- The sha must be one the page lists and its checkout must still be on disk; otherwise
not_found. - A plan answers 200 with
{ dryRun: true, from, to, allowed, message? }and changes nothing. - An apply answers 409
not_rollablewhen the page would offer no button, 409not_rolled_backwithrollBackTo's own line when the swap refuses, and{ dryRun: false, from, to, rolledBack: true }on success, before this process drains.
src/release/words.ts: two shared sentences,ALREADY_LIVEandNOT_ROLLABLE, for the case where the page shows no Roll back button. The page itself has no sentence for this today; it just hides the button.src/contract/openapi/routes/postApiV1AdminReleasesShaRollback.ts: the route's OpenAPI description. The index line was written bybun scripts/openapi-routes.ts.test/api-rollback.test.tscovers:- the plan is the default and nothing drains (a spy on
handover.drain); - the plan explains why the live release and a release whose schema is behind are not allowed;
- applying a schema-behind release is 409 with those words;
- applying with self-swap off goes through
rollBackToand refuses with its own line; - a member gets
not_admin, and an admin'srworrotoken getsforbidden; - no token gets 401;
- an unknown sha, a malformed sha, or a release whose checkout was pruned gets
not_found; - a
dryRunthat is not a boolean gets 422.
- the plan is the default and nothing drains (a spy on
What to look at
- Release lookup: it uses
listReleases, the page's newest-20 list, so the API offers exactly what the page offers. - Plan with a refusal: a refused plan still answers 200 with
allowed: false. Only an apply turns a refusal into a 409.
Not done
- No MCP tool. The issue limited the change to these three files, and undoing a deploy stays a person's call:
mayRollBackalready refuses agents. /releasesand the terminal are untouched.
bun x tsc --noEmit is clean. Run here and passing: the new test plus the openapi*, admin*, release-gate, releases-page, hollow, api-list-shape, mcp-releases and token-admin-scope suites (452 tests). scripts/fast.ts named 946 test files for this diff (about 82 minutes), over its budget, so I chose those suites by hand instead. The forge's check runs everything on the push.
To try it: with an admin-scope token, send curl -X POST -H "authorization: Bearer $T" $FORGE/api/v1/admin/releases/<sha>/rollback to get the plan. Add -d '{"dryRun":false}' to apply it.
🤖 Generated with Claude Code
Adds POST /api/v1/admin/releases/:sha/rollback, so a forge admin's script can roll the forge back to a kept release. It plans by default and only swaps on {"dryRun": false}. It uses mayRollBack, canRollBackTo and rollBackTo from src/release/gate.ts unchanged, so the API follows the same rules as /releases and the terminal.
What changed
src/http/api/rollback.ts(new):rollbackRoutes, registered with one line besidereportRoutesinsrc/http/api.ts. In order:admin_gate.tsrefuses a person who may not administer withnot_admin.requireScope(ctx, "admin"): anrworrotoken isforbidden.mayRollBack: an agent isforbidden, and so is everyone whenFORGE_REPOnames no repository on this forge.- The sha must be one the page lists and its checkout must still be on disk; otherwise
not_found. - A plan answers 200 with
{ dryRun, from?, to, allowed, message? }and changes nothing. - An apply answers 409
not_rollablewhen the page would offer no Roll back button, and 409not_rolled_backwithrollBackTo's own line when the swap refuses. On success it answers{ dryRun, from?, to, rolledBack }, then this process drains. fromis the live commit, and is left out when the forge does not know which commit is live.
src/release/words.ts: two shared sentences,ALREADY_LIVEandNOT_ROLLABLE, for the case where the page shows no Roll back button.src/contract/openapi/routes/postApiV1AdminReleasesShaRollback.ts: the route's OpenAPI description, withfrommarked optional. The index line was generated bybun scripts/openapi-routes.ts.- README.md: one sentence in the
/releasesparagraph names the API route and says it has the same rules as the page (never an agent). test/api-rollback.test.tscovers:- the plan is the default and nothing drains (a spy on
handover.drain); - the plan leaves out
fromwhen neitherFORGE_COMMITnorFORGE_APP_COMMITis set; - the plan explains why the live release and a release whose schema is behind are not allowed;
- applying a schema-behind release is 409 with those words;
- applying with self-swap off goes through
rollBackToand refuses; - a member gets
not_admin, and an admin'srworrotoken getsforbidden; - an admin-scope agent, and an admin on a forge whose
FORGE_REPOnames no repository, getforbiddenon both the plan and the apply, and nothing drains; - no token gets 401, and an unknown, malformed or pruned sha gets
not_found; - a
dryRunthat is not a boolean gets 422.
- the plan is the default and nothing drains (a spy on
Where I departed from the review
- The second
mayRollBackcaller: the review asked for a site admin who does not writealice/forge. That account can't exist.personalOrDirect(src/core/repos.ts:925) gives every site admin write on every repository, and the admin gate lets a person through only if they are a site admin. So the test pins the other case wheremayRollBackrefuses a person:FORGE_REPOnames no repository here. - Proof the line is covered: with line 26 of
rollback.ts(if (!mayRollBack(...)) return forbidden();) deleted, both new tests fail. fromwhen unknown: I left it out rather than declaring it nullable. That keeps the field a plain string in the contract.
Not done: no MCP tool, because agents may not roll back.
Checks: bun x tsc --noEmit is clean. The new test passes, along with the openapi*, admin*, releases-page, readme-front-door and policy suites.
To try it: send curl -X POST -H "authorization: Bearer $ADMIN_TOKEN" $FORGE/api/v1/admin/releases/<sha>/rollback to get the plan. Add -d '{"dryRun":false}' to apply it.
🤖 Generated with Claude Code
This pull adds POST /api/v1/admin/releases/:sha/rollback (src/http/api/rollback.ts), so an admin can roll back through the API. It works in two steps: it first plans the rollback, then rolls back to a release the forge has kept. It follows the same rules as the admin releases page. mayRollBack is pinned by a test, and the README describes the endpoint. A from the forge doesn't recognise is left out of the answer rather than guessed at.
This update merges main again. The only conflict was in src/http/api.ts: main added takeBackRoutes (./api/take_back.ts) in the same two places this branch added rollbackRoutes. Both imports and both registrations are kept, rollbackRoutes(router) then takeBackRoutes(router), right after reportRoutes(router). The README and the OpenAPI route index merged without conflicts.
bun x tsc --noEmit passes, and the rollback, take-back, release-rollback and OpenAPI admin, route and coverage tests pass (318 tests, 0 failures).
🤖 Generated with Claude Code
Adds
POST /api/v1/admin/releases/:sha/rollback, so a forge admin's script can roll the forge back to a kept release. It plans by default and only swaps when the body has{"dryRun": false}. It follows the same rules as/releasesand the terminal:mayRollBack,canRollBackToandrollBackTofromsrc/release/gate.tsare called as they are, unchanged.What changed
src/http/api/rollback.ts(new):rollbackRoutes, registered with one line besidereportRoutesinsrc/http/api.ts. In order:admin_gate.tsalready refuses a person who may not administer withnot_admin.requireScope(ctx, "admin"): anrworrotoken isforbidden.mayRollBack: an agent, or someone who is not a writer of the forge's repository, isforbidden.not_found.{ dryRun: true, from, to, allowed, message? }and changes nothing.not_rollablewhen the page would offer no button, 409not_rolled_backwithrollBackTo's own line when the swap refuses, and{ dryRun: false, from, to, rolledBack: true }on success, before this process drains.src/release/words.ts: two shared sentences,ALREADY_LIVEandNOT_ROLLABLE, for the case where the page shows no Roll back button. The page itself has no sentence for this today; it just hides the button.src/contract/openapi/routes/postApiV1AdminReleasesShaRollback.ts: the route's OpenAPI description. The index line was written bybun scripts/openapi-routes.ts.test/api-rollback.test.tscovers:handover.drain);rollBackToand refuses with its own line;not_admin, and an admin'srworrotoken getsforbidden;not_found;dryRunthat is not a boolean gets 422.What to look at
listReleases, the page's newest-20 list, so the API offers exactly what the page offers.allowed: false. Only an apply turns a refusal into a 409.Not done
mayRollBackalready refuses agents./releasesand the terminal are untouched.bun x tsc --noEmitis clean. Run here and passing: the new test plus theopenapi*,admin*,release-gate,releases-page,hollow,api-list-shape,mcp-releasesandtoken-admin-scopesuites (452 tests).scripts/fast.tsnamed 946 test files for this diff (about 82 minutes), over its budget, so I chose those suites by hand instead. The forge's check runs everything on the push.To try it: with an admin-scope token, send
curl -X POST -H "authorization: Bearer $T" $FORGE/api/v1/admin/releases/<sha>/rollbackto get the plan. Add-d '{"dryRun":false}'to apply it.🤖 Generated with Claude Code
Closes #7217