Repository navigation
fix(refunds): no unsigned pending refund for an already refunded charge, plus test gaps (issue #435) [claude] - #467
Draft
PetrefiedThunder wants to merge 1 commit into
Conversation
…efunded An upstream call's live refund fails, the terminal audit event is written, and the signing key is then disabled. If the dispatch reconciler handles the attempt before create_pending writes, through a retry of the same key or through its sweep, it refunds the charge and releases the reservation. create_pending then stored "refund pending, receipt unsigned" for a debt that was gone: no pass could sign it, the reconciler skipped it, no operator list showed it, and a replay kept answering that a refund was pending. The unsigned write now checks, inside its own transaction and with the dispatch attempt locked, whether the refund landed and the reservation was released. If so it stores nothing and the signing error propagates as it did before unsigned items existed, so the record stays open and the reconciler writes the failed_refunded receipt once a key can sign. Tests added for the gaps listed in the issue: the race above (refund and checkpoint failure, retry and sweep), a key disabled or retired before the terminal audit write, a second key signing while the permit key stays disabled, a refund checkpoint that commits before the request fails, and the reconciler's attempt listing checked by its result. Part of #435 Signed-off-by: PetrefiedThunder <131207452+PetrefiedThunder@users.noreply.github.com> Generated-by: Grok Build (bot=grok-bot, job=amw-b005-i435-x)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Collaborator
Author
|
Cross engine review (round 1): Codex CLI, read only, of claude authored work, head 6d09c8c. VERDICT: CHANGES REQUESTED
|
This branch was successfully deployed
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.
Fixes #435
Draft PR from the AMW fleet cohort, job amw-b005-i435-x. Merges only after green CI and a PASS from a different engine; this repo deploys to production on merge, so it also waits for C.Lee's deploy yes.
Job brief and acceptance criteria
Implementer report (claude)
Report: AMW-B005 (issue #435)
The race in part 1 is fixed and committed as
6d09c8cdonclaude/grok-bot/amw-b005-i435-x(one commit ahead oforigin/pr/330, not pushed, no PR). The fix narrows the window but does not close it from the reconciler side (see "Not done or not verified").What changed
gateway/app/services/refund_reconciliation.py(on the open-PR list): the unsigned write now checks, inside its own transaction and with the dispatch attempt row locked, whether the refund landed and the reservation was released. If both are true it stores nothing and the original signing error propagates. The record stays open, and the dispatch reconciler writes thefailed_refundedreceipt once a key can sign.-32603 internal_errorinstead of a pending item with no receipt.gateway/tests/test_unsigned_pending_refund_followups.py(new, 9 tests). It imports private helpers fromtests/test_mcp_upstream_governed.py, which is on the open-PR list but is not edited.Tests added
disabledandretired.response_json IS NULLalternative makes it fail.Gate (run from
gateway/, Python 3.12, SQLite)test_mcp_upstream_governed.py,test_mcp_dispatch_reconciliation.py, the lost refund demo, and the two AGENTS.md files): 133 passed.test_refund_reconciliation_unsigned.pyandtest_signing_key_lifecycle.py: 33 passed.ruff check .andruff format --check .with the pinned version: clean.mypy app/: no issues in 214 files.Part 2, current behaviour (PR-body ready, not changed)
While the key that signed a permit is
disabled, the operator retry of that call's pending refund refuses with 409refund_reconciliation_permit_invalid, even after a second key has signed the item's receipt. The charge stays unrefunded for as long as that key row staysdisabled. Once the row isactiveagain, one retry refunds the charge once and a second retry refunds nothing more. The new test pins exactly this. The issue states no decision, so the behaviour is unchanged and the commit says "Part of #435".Not done or not verified
release_dispatch_budget_onceinpermits.py, which would also flip an existing test.FOR UPDATEon the attempt row is unexercised. The CI gap for PostgreSQL is not done; the issue says the harness fails there andci.ymlbelongs to other PRs.abandon_effect_free_prepared_attemptlocks attempt then record, but only for a prepared, uncharged attempt, which cannot overlap a charged terminal one. This is by reading only.retiredrow is reactivated and signs. It will flip when fix(trust): a retired signing key refuses to sign instead of reactivating #331 merges.Local gate re-run by the operator on the Mac
Commits:
Cross engine review by a different engine is posted as a PR comment.
Generated by claude for grok-bot through grok-job (job amw-b005-i435-x).