Skip to content

Recover guest voucher approval after post-commit failures - #55

Open
compnew2006 wants to merge 1 commit into
UserJoo9:mainfrom
compnew2006:codex/qm-03-voucher-recovery
Open

compnew2006 wants to merge 1 commit into
UserJoo9:mainfrom
compnew2006:codex/qm-03-voucher-recovery

Conversation

@compnew2006

Copy link
Copy Markdown
Contributor

Problem

Voucher redemption committed the one-time claim and the guest's allowance, then updated the derived allowance snapshot and wrote an audit event. A failure in either follow-up step could return HTTP 500 despite the committed grant. When the guest retried, the original flow could return HTTP 403 because the guest was no longer pending.

Changes

  • Return the established approval response once the claim is committed. Keep audit errors visible in the logs without reporting the claim as failed.
  • Bind new claims to the original user and device. A retry can return the original result only while that guest, device, and grant still match. It does not issue a new allowance or duplicate the audit event.
  • Persist an allowance-refresh marker in the claim transaction. Refresh from current policy on a later request, startup or maintenance tick. Serialize allowance recomputation with period changes, and write only the relevant bundle fields so refresh does not overwrite policy settings.

Before and after

Scenario Before After
Allowance snapshot write fails after the claim commits The guest sees HTTP 500, but the code is spent The guest receives the committed approval and the refresh remains queued
The original guest retries after losing the response The guest can get HTTP 403 even though the grant was saved The original grant can be reported again without a second redemption
The device was deleted, reassigned, blocked, or its grant changed The original claim cannot safely establish current approval The retry is rejected without restoring old access
The service restarts before allowance refresh The stale snapshot can persist Startup and maintenance retry the durable marker

The public success response shape and existing one-use guarantee are preserved. New nullable identity columns and a pending flag are additive. Vouchers redeemed by an older build remain spent and have no new replay identity. Audit writes remain best-effort. An audit write that fails is logged and is not backfilled. Voucher approval remains separate from the kernel's next enforcement update.

Verification

  • Reproduced HTTP 500 after the voucher had already committed and exercised the successful retry.
  • Tests cover failures before and after commit, one-time spending, eligibility and same-owner replay, restart recovery, and concurrent allowance refresh alongside administrator policy changes.
  • The independent focused run passed 34 tests. The worker's broader API, voucher, quota-service and run-wiring run passed 290. The final audit-log test, pyflakes and Git whitespace checks also passed.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant