Repository navigation
Open
Labels
bugSomething isn't working
Description
Summary
CodeRabbit raised four findings on #329 (signing-key pre-charge check). Each was verified as valid on head 10f834c. The maintainer decided on 2026-11-19 to leave them out of #329 so the head under QA review does not move, and to track them here. None of them moves money: on each path nothing is reserved or charged.
This issue exists so the fixes are not lost if #329 merges as it stands. The review threads on #329 say the fixes ride "this PR's next push"; if there is no next push, they land through this issue.
Affected area
- spec
- verifier
- Python SDK
- TypeScript SDK
- integration
- example
- gateway
- build or tooling
- Other:
Version or commit
#329 at head 10f834ce6dfd04e373942035c33075b272bf36c8.
The four findings
1. Legacy demo path mints a permit before the signing-key check (minor)
- Where:
gateway/app/routers/mcp.py, the two legacy entrypoints that call_maybe_mint_demo_permit(JSON-RPC path near line 5163, REST invoke path near line 5391). The existing check is at line 1202. - Actual: on a demo call without a permit, the mint signs a permit before
assert_ready_to_sign()runs. With a key that cannot sign, the caller getsinternal_errorinstead of the retryablesigning_key_unavailable. Nothing is charged. - Expected: call
assert_ready_to_sign()before the demo mint in both entrypoints, and keep the existing check. - Scope: demo tenant, legacy entrypoints only. Present before fix(trust): refuse before the charge when the signing key cannot sign #329 and stated in its description (Info section).
- Thread: fix(trust): refuse before the charge when the signing key cannot sign #329 (comment)
2. AWI route releases its idempotency record only for one error type (minor)
- Where:
gateway/app/services/awi_http_governance.py,_admit_awi_http_governed, around lines 461 to 462. - Actual: the begun record is abandoned only for
SigningKeyUnavailableError. Any other exception from the check (for example a storage error fromensure_active_key) leaves the record begun until stuck-record reconciliation, so a retry of the sameIdempotency-Keycan be blocked until then. Nothing is reserved or charged on this path. - Expected: abandon the record for any exception raised by the check, keep the 503 mapping for
SigningKeyUnavailableError, and re-raise other exceptions unchanged. - Thread: fix(trust): refuse before the charge when the signing key cannot sign #329 (comment)
3. Runbook overstates what /health/ready proves (docs only)
- Where:
gateway/docs/backup-restore-runbook.md, theGET /health/readyrow near line 460. - Actual: the row says readiness proves the configured key's row can sign. When the row read itself raises, readiness stays up and only logs
signing key row check raisedat warning (the postgres check owns a database outage). - Expected: the row says so, and tells operators to check for that log line during restore verification.
- Note: fix(trust): a retired signing key refuses to sign instead of reactivating #331 changes the read from
configured_key_status()toconfigured_key_problem(); the limitation is the same on both. - Thread: fix(trust): refuse before the charge when the signing key cannot sign #329 (comment)
4. AWI refusal test does not check the permit reservation (test only)
- Where:
gateway/tests/test_awi_http_governance.py,test_rag_query_refuses_before_reserving_when_the_key_cannot_sign, near line 857. - Actual: the test asserts wallet debits only. A reservation leaked before the refusal would not fail it.
- Expected: read the permit's
spent_creditsbefore the refused request, assert it is unchanged after the refusal, and assert it is up by the reserved amount after the successful retry. - Thread: fix(trust): refuse before the charge when the signing key cannot sign #329 (comment)
Steps to reproduce
- Finding 1: disable the configured signing key row, then make a demo-tenant call without a permit through a legacy entrypoint. The answer is
internal_error, notsigning_key_unavailable. - Finding 2: make
ensure_active_keyraise a non-signing error during an AWI HTTP governed call, then retry with the sameIdempotency-Key. - Findings 3 and 4 are a documentation line and a test assertion; see the locations above.
Steps 1 and 2 are derived from reading the code and the review threads. They were not run for this issue.
Expected behavior
As listed under each finding.
Actual behavior
As listed under each finding.
Notes for whoever picks this up
- If fix(trust): refuse before the charge when the signing key cannot sign #329 has not merged yet and gets another push for any reason, these four can ride that push and this issue can be closed against it.
- If fix(trust): refuse before the charge when the signing key cannot sign #329 has merged, one small PR on main covers all four. Finding 3 must then match whichever read fix(trust): a retired signing key refuses to sign instead of reactivating #331 left in
gateway/app/core/health.py. - Add or update tests for findings 1 and 2 (behavior changes), per the pull request template.
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
PetrefiedThunder commentedon Nov 25, 2026
Finding 5 (raised on #331): AWI signing key check runs after the denial receipt paths (medium)
Added 2026-11-25 at the maintainer's request. The issue body above lists findings 1 to 4 from #329 and its title still says four. This comment adds a fifth, raised by Cursor Bugbot on #331 and verified by reading the code at #331 head
ec5050720773898751c63f1c09b36c54bad5d3f7. The code is #329's and reaches #331 through the stack.gateway/app/services/awi_http_governance.py. The key check is in_admit_awi_http_governed(about lines 455 to 472). The earlier steps are inbegin_awi_http_governed(about lines 401 to 424).validate_for_actionruns. A denial goes throughraise_awi_http_error(403).raise_awi_http_error(403)._admit_awi_http_governedrunassert_ready_to_sign(), which abandons the record and answers503 signing_key_unavailable.raise_awi_http_error, which calls_finalize_awi_httpto sign a denial receipt.create_receiptfails three times, and the function raises503 awi_finalization_incomplete. Thecompletecall for the idempotency record is inside the same try block, so it is never reached, and nothing abandons the record. TheIdempotency-Keystays in progress until stuck-record reconciliation. The caller seesawi_finalization_incompleteinstead of the retryablesigning_key_unavailable.assert_ready_to_sign()before the permit and call-limit denial paths, release the begun record on refusal, and keep the503 signing_key_unavailablemapping./mcpand billing entry points check the key at the top of the request, so this ordering gap is in the AWI route only.create_receiptfails for a retired key is the behavior fix(trust): a retired signing key refuses to sign instead of reactivating #331 adds. I read it from the code and the PR description and did not re-run it for this comment.503 signing_key_unavailable, and expect a retry with the sameIdempotency-Keyafter the key is restored to run normally.Where it can ride: the same options as the notes above. If #329 gets another push, this can ride it, and #331 then needs #329's new head merged in. If #329 merges as it stands, one small PR on main covers findings 1 to 5.
Refs #329, #331, #280.
Generated by Claude Code
PetrefiedThunder commentedon Nov 30, 2026
Note added at the maintainer's request on 2026-11-30, for finding 3.
CodeRabbit raised the same behavior again on #329 at head
9f0aad92420813f9d517ddb1fe05397255c07e1b, this time against the code: #329 (comment) (labelled Minor).signing_keyasup. It leaves the database outage case with the postgres check, and it leaves the status and reason to the author.test_health_logs_a_key_row_read_that_failsingateway/tests/test_signing_key_precharge.pychanges with it, because it assertsuptoday.Generated by Claude Code
PetrefiedThunder commentedon Dec 1, 2026
Note added at the maintainer's request on 2026-12-01, for finding 5.
CodeRabbit raised the same behavior on #329 at head
b1614c32834d3ba483def138ab54a2651f645d6c: #329 (comment) (labelled Minor).begin_with_record(), so that no idempotency record is created for a request the gateway cannot sign.gateway/app/services/awi_http_governance.pyis the same blob (d2bb393) atb1614c3as atec50507, where finding 5 was read. Line numbers atb1614c3:begin_with_record()358, permit denial 410, call-limit refusal 418, key check 461.Generated by Claude Code
PetrefiedThunder commentedon Dec 1, 2026
Note added at the maintainer's request on 2026-12-01. CodeRabbit reviewed #331 at head
000f974262c641731cf234530a2700eed8886f4aand raised findings 1, 3, 4 and 5 again. The four threads on #331 were resolved as duplicates. Nothing in #331 was changed for them. What the review and the check of it add:Finding 5: a correction. The text above says the
Idempotency-Key"stays in progress until stuck-record reconciliation". That is wrong. Tested at000f974by two independent read-only checks, and on main37618e0by one of them:reconcile_stuck_records(gateway/app/services/idempotency.pyat000f974) the first pass coversupstream_mcprecords only (lines 1036 to 1103). The second pass skips the record because it has no debit (lines 1183 to 1191). The third pass counts it asneeds_reviewbecause it has no receipt (lines 1274 to 1276). The cleanup then logs that count incleanup_completed, fieldidempotency_records_needing_review(gateway/app/main.pylines 392 to 397).409 idempotency_in_progressuntil an operator deletes the row, even after the signing key is fixed. A newIdempotency-Keyworks. No money moves.000f974by one of the two checks: a key row that isretiredrefuses to sign, so a replica that is still configured with a retired key id after a rotation reaches this state. By reading, on main a retired row is reactivated, and a key reaches this state when it is disabled, does not match its key material, or cannot sign for another reason.Finding 2: the same wording. Finding 2 also says "until stuck-record reconciliation". By reading, the same correction applies, because that record has no debit and no receipt either. Not run.
Finding 1: a new trigger with #331. At #329's head a retired key row is reactivated, so a retired key does not reach the gap there, and a disabled or mismatched key does. At
000f974a retired key refuses withsigning_key_retired. Tested at000f974with a retired key on both legacy entrypoints: the demo call answersinternal_error, no debit is written, no idempotency record is left and no permit is stored. CodeRabbit proposes one check inside_maybe_mint_demo_permit, which covers both entrypoints. The text above puts one check in each entrypoint. These are two variants of one fix. Thread: #331 (comment)Finding 3: a caveat. It was raised again as a behavior change (a failed row read must not report
up), as in the note of 2026-11-30. The comment's first option is to let the exception reach_run_check. That would also reportsigning_keydown during a plain database outage, which the code comments leave to the postgres check. Thread: #331 (comment)Finding 4: a stronger remedy. A comparison of
spent_creditsbefore and after would still pass if the route reserved budget and released it before the 503. CodeRabbit proposes to observe the reservation call and to assert that the refused request never reaches it. Thread: #331 (comment)Generated by Claude Code