Skip to content

Follow-up to #329: four deferred CodeRabbit findings on the signing-key pre-charge check #413

Open

Description

@PetrefiedThunder

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 gets internal_error instead of the retryable signing_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 from ensure_active_key) leaves the record begun until stuck-record reconciliation, so a retry of the same Idempotency-Key can 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)

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_credits before 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

  1. 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, not signing_key_unavailable.
  2. Finding 2: make ensure_active_key raise a non-signing error during an AWI HTTP governed call, then retry with the same Idempotency-Key.
  3. 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

Refs #329, #280.

Activity

  1. added
    bug
    on Nov 19, 2026
  2. PetrefiedThunder commented on Nov 25, 2026

    @PetrefiedThunder
    CollaboratorAuthor

    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.

    • Where: 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 in begin_awi_http_governed (about lines 401 to 424).
    • Order today:
      1. The idempotency record is begun.
      2. validate_for_action runs. A denial goes through raise_awi_http_error (403).
      3. The call-limit check runs. A refusal goes through raise_awi_http_error (403).
      4. Only then does _admit_awi_http_governed run assert_ready_to_sign(), which abandons the record and answers 503 signing_key_unavailable.
    • Actual: on a replica whose signing key cannot sign, a permit denial or call-limit refusal reaches raise_awi_http_error, which calls _finalize_awi_http to sign a denial receipt. create_receipt fails three times, and the function raises 503 awi_finalization_incomplete. The complete call for the idempotency record is inside the same try block, so it is never reached, and nothing abandons the record. The Idempotency-Key stays in progress until stuck-record reconciliation. The caller sees awi_finalization_incomplete instead of the retryable signing_key_unavailable.
    • Expected: run assert_ready_to_sign() before the permit and call-limit denial paths, release the begun record on refusal, and keep the 503 signing_key_unavailable mapping.
    • Money: none moves. Both denials happen before any reservation or charge.
    • Other entry points: the MCP, /mcp and billing entry points check the key at the top of the request, so this ordering gap is in the AWI route only.
    • Not run: I did not execute a test. That create_receipt fails 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.
    • Test to add: with a key that cannot sign, send an AWI request that the permit denies. Expect 503 signing_key_unavailable, and expect a retry with the same Idempotency-Key after the key is restored to run normally.
    • Thread: fix(trust): a retired signing key refuses to sign instead of reactivating #331 (comment)

    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

  3. PetrefiedThunder commented on Nov 30, 2026

    @PetrefiedThunder
    CollaboratorAuthor

    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).

    • Finding 3 above: keep the behavior and correct the runbook row, so it says that readiness stays up when the key row read raises.
    • The new comment: change the behavior, so a failed read of the configured key's row does not report signing_key as up. It leaves the database outage case with the postgres check, and it leaves the status and reason to the author.
    • These are two remedies for the same gap. Whoever picks this issue up needs to choose one. If the behavior changes, test_health_logs_a_key_row_read_that_fails in gateway/tests/test_signing_key_precharge.py changes with it, because it asserts up today.
    • The thread on fix(trust): refuse before the charge when the signing key cannot sign #329 was resolved as a duplicate of finding 3. Nothing in fix(trust): refuse before the charge when the signing key cannot sign #329 was changed for it. No money moves on this path.

    Generated by Claude Code

  4. PetrefiedThunder commented on Dec 1, 2026

    @PetrefiedThunder
    CollaboratorAuthor

    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).

    • Finding 5 above: run the signing-key check before the permit denial and the call-limit refusal, and release the begun record on refusal.
    • The new comment: run the check before begin_with_record(), so that no idempotency record is created for a request the gateway cannot sign.
    • These are two variants of one fix. Whoever picks this issue up needs to choose one. By reading, the test in finding 5 fits both.
    • gateway/app/services/awi_http_governance.py is the same blob (d2bb393) at b1614c3 as at ec50507, where finding 5 was read. Line numbers at b1614c3: begin_with_record() 358, permit denial 410, call-limit refusal 418, key check 461.
    • The thread on fix(trust): refuse before the charge when the signing key cannot sign #329 was resolved as a duplicate of finding 5. Nothing in fix(trust): refuse before the charge when the signing key cannot sign #329 was changed for it. No money moves on this path.

    Generated by Claude Code

  5. PetrefiedThunder commented on Dec 1, 2026

    @PetrefiedThunder
    CollaboratorAuthor

    Note added at the maintainer's request on 2026-12-01. CodeRabbit reviewed #331 at head 000f974262c641731cf234530a2700eed8886f4a and 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 at 000f974 by two independent read-only checks, and on main 37618e0 by one of them:

    • No cleanup pass releases the begun record. In reconcile_stuck_records (gateway/app/services/idempotency.py at 000f974) the first pass covers upstream_mcp records 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 as needs_review because it has no receipt (lines 1274 to 1276). The cleanup then logs that count in cleanup_completed, field idempotency_records_needing_review (gateway/app/main.py lines 392 to 397).
    • So the key answers 409 idempotency_in_progress until an operator deletes the row, even after the signing key is fixed. A new Idempotency-Key works. No money moves.
    • New with fix(trust): a retired signing key refuses to sign instead of reactivating #331, tested at 000f974 by one of the two checks: a key row that is retired refuses 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.
    • Thread: fix(trust): a retired signing key refuses to sign instead of reactivating #331 (comment)

    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 000f974 a retired key refuses with signing_key_retired. Tested at 000f974 with a retired key on both legacy entrypoints: the demo call answers internal_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 report signing_key down 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_credits before 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions