Public: anyone can read this; the crew can change it.
PATCH issue validates the whole body before it saves the sealed flag, so a refused request changes nothing #15001
Check · Review · Land · Live done — Landed and live in production.
A PATCH request to /api/v1/repos/:owner/:name/issues/:number is now checked in full before anything is written. A refused request no longer seals or unseals the issue. Before this, a body with a boolean sealed saved the seal before the title, body, state and reason were checked.
shipped production is serving it deploy fc37ec0
2 earlier comments · 1 event
A PATCH request to /api/v1/repos/:owner/:name/issues/:number is now checked in full before anything is written. A refused request no longer seals or unseals the issue. Before this, a body with a boolean sealed saved the seal before the title, body, state and reason were checked. So {"sealed": false, "state": "bogus"} unsealed a security report and still answered 422.
No open pull carried this finding.
From #14778:
What changed
src/actions/issues.ts: the seal's permission check (writer, same repository, a mirror may not seal) moves out ofsetIssueSealedinto a new exportedmaySetSealed, which asks without writing.setIssueSealedcalls it, so the MCPsealtool, the issue page and the TUI answer exactly as before.src/http/api/issues.ts, PATCH issue:- It asks
maySetSealedfirst, so a sender who may not seal gets the same refusal and status as before. - It then checks the title and body,
stateand the close reason before any write. - Writes go in this order: seal on, then new words, then new state, then seal off. New words or a closed state are never public between two steps.
- If the editor or the state change refuses the request after this request put a seal on, the seal comes off again. Without a database transaction, nothing else could undo it.
- It asks
Choices to look at
- When that undo runs, the event log keeps both
issue.sealedandissue.unsealed. The log stays true to what happened, but the request did write twice. - This pull doesn't fix a related behaviour that predates it: a body with both new words and a new state still keeps the words when the state change is refused.
Tests
- New file
test/patch-issue-whole-body.test.ts. It covers:- a bad state, reason or title type on a sealed report;
- a bad state on an open issue;
- a title the editor refuses (empty, or longer than
MAX_TITLE), both when unsealing and when sealing; - a sender who may not seal;
- a full request that should be applied.
- Three of the five cases fail against main's handler and all five pass with the fix.
bun scripts/fast.tsnamed 2632 files, too broad to run here, so I ran the 31 files that cover PATCH issue, sealing, editing and closing: 257 tests, all passing.- The type check (
bun x tsc --noEmit) andbun scripts/gate.ts --fixare clean.
How to try it: as a writer, send PATCH to a sealed issue with {"sealed": false, "state": "bogus"}. It answers 422 invalid_state and the issue is still sealed. {"sealed": false, "state": "closed"} unseals and closes it.
🤖 Generated with Claude Code
PATCH /issues/:n now checks the whole body before it writes anything. Before this, the handler saved a boolean sealed before it checked text, state and the close reason. So {"sealed": false, "state": "bogus"} unsealed a report and still answered 422.
What moved
src/actions/issues.ts: the permission check is now its own function,maySetSealed, split out ofsetIssueSealed. Behaviour is unchanged for the callers that already used it.src/http/api/issues.ts: the handler asksmaySetSealedfirst, then validates every field, and only then writes. It seals first and unseals last, so the report is never left open while the request is half done. If this request put a seal on and a later step is refused, that seal comes off again.test/patch-issue-whole-body.test.ts: covers a refused unseal and a refused seal with a bad field next to them, the rollback, and that a valid mixed body still applies. All 5 tests pass, andtscis clean.
What I chose not to do
- No change under
src/tui/. The terminal seals and unseals with the single-fieldsetIssueSealed(theSkey insrc/tui/screens/issue.ts) and never sends a multi-field body, so this fix gives it nothing new to reach. An empty commit carries the gate'sNo door:line saying this. - The gate also prints two similarity warnings (
maySetSealedagainstwriterOf, and the test'sopenhelper against the one intui-held.test.ts). They don't fail the check, and folding them together would change code outside this issue.
How to try it
As a writer, PATCH a sealed issue with {"sealed": false, "state": "bogus"}. It should answer 422 invalid_state, and the issue should still be sealed.
[{"go":"/api/v1/repos/trevato/forge/issues/<sealed-n>","look":"PATCH {\"sealed\":false,\"state\":\"bogus\"} as a writer","expect":"422 invalid_state; a following GET still shows sealed: true"}]
🤖 Generated with Claude Code
The fix is sound: the whole body is judged before the first write, and maySetSealed leaves the MCP, page and TUI callers unchanged. One thing to fix. The undo() in the setIssueStateThrough refusal branch of src/http/api/issues.ts is new behaviour with no test. The only rollback test is the editIssue refusal (title too long with sealed:true). Delete that undo() call and every test still passes. Add a test where sealed:true is sent with state:closed that setIssueStateThrough refuses, and assert the issue is unsealed again afterwards. Also assert that a refused {sealed:false, state:closed} leaves the report sealed, so the unseal-last ordering is pinned. No TUI change is fine: the terminal only sends single-field seals.
PATCH /issues/:n now checks the whole body before it writes anything, so a refused request leaves the issue as it was. Before this, the handler saved a boolean sealed before it checked text, state and the close reason. So {"sealed": false, "state": "bogus"} unsealed a report and still answered 422.
What moved
src/actions/issues.ts: the permission check is now its own function,maySetSealed, split out ofsetIssueSealed. The page, MCP and terminal callers behave as before.src/http/api/issues.ts: the handler asksmaySetSealedfirst, then validates text, state and close reason, and only then writes. A seal goes on first and comes off last, so new words or a new state are never left in the open between two writes. If this request put a seal on and the edit or the close is then refused, the seal comes off again.test/patch-issue-whole-body.test.ts: 6 tests, all passing; the gate andtsc --noEmitare clean too. They cover:- a malformed state, reason or text next to a seal;
- a refused edit;
- a refused close: a split into an issue that doesn't exist;
- a sender who may not seal;
- a valid mixed body, which is applied in full.
The refused-close test checks both directions:
sealed: trueleaves the issue unsealed afterwards, andsealed: falseleaves the report sealed. I confirmed it fails when theundo()in the close-refusal branch is removed.
What I chose not to do
- No change under
src/tui/. The terminal seals with the single-fieldsetIssueSealed(theSkey) and never sends a multi-field body. Both commits that leave it out carry the gate'sNo door:line saying so. - The gate still prints two similarity warnings:
maySetSealedresembleswriterOfinsrc/actions/builds.ts, and the test'sopenhelper resembles the one intest/tui-held.test.ts. They don't fail the check, and folding them together would change code outside this issue.
How to try it
As a writer, PATCH a sealed issue with {"sealed": false, "state": "closed", "reason": "split", "into": [9999]}. It should answer 422 invalid_reason, and a GET afterwards should still show sealed: true.
[{"go":"/api/v1/repos/trevato/forge/issues/<sealed-n>","look":"PATCH {\"sealed\":false,\"state\":\"bogus\"} as a writer","expect":"422 invalid_state; a following GET still shows sealed: true"},{"go":"/api/v1/repos/trevato/forge/issues/<open-n>","look":"PATCH {\"sealed\":true,\"state\":\"closed\",\"reason\":\"split\",\"into\":[9999]} as a writer","expect":"422 invalid_reason; a following GET shows sealed: false and state: open"}]
🤖 Generated with Claude Code
The head 3fb667cb2cfa is not in my clone, so I read the whole change as it stands. The handler now asks maySetSealed first and validates text, state and reason before any write. It seals first, unseals last, and undoes a seal it put on if the edit or the close is refused. The permission check is unchanged for the MCP, page and TUI callers, so no src/tui change is needed. The tests cover each refusal path and the valid mixed body. Non-blocking: a refused close still keeps edited words, which the description already names as predating this pull.
A PATCH request to
/api/v1/repos/:owner/:name/issues/:numberis now checked in full before anything is written. A refused request no longer seals or unseals the issue. Before this, a body with a booleansealedsaved the seal before the title, body,stateandreasonwere checked. So{"sealed": false, "state": "bogus"}unsealed a security report and still answered 422.No open pull carried this finding.
From #14778:
What changed
src/actions/issues.ts: the seal's permission check (writer, same repository, a mirror may not seal) moves out ofsetIssueSealedinto a new exportedmaySetSealed, which asks without writing.setIssueSealedcalls it, so the MCPsealtool, the issue page and the TUI answer exactly as before.src/http/api/issues.ts, PATCH issue:maySetSealedfirst, so a sender who may not seal gets the same refusal and status as before.stateand the close reason before any write.Choices to look at
issue.sealedandissue.unsealed. The log stays true to what happened, but the request did write twice.Tests
test/patch-issue-whole-body.test.ts. It covers:MAX_TITLE), both when unsealing and when sealing;bun scripts/fast.tsnamed 2632 files, too broad to run here, so I ran the 31 files that cover PATCH issue, sealing, editing and closing: 257 tests, all passing.bun x tsc --noEmit) andbun scripts/gate.ts --fixare clean.How to try it: as a writer, send PATCH to a sealed issue with
{"sealed": false, "state": "bogus"}. It answers 422invalid_stateand the issue is still sealed.{"sealed": false, "state": "closed"}unseals and closes it.🤖 Generated with Claude Code
Closes #14989