Repository navigation
[AISAGE-503] feat(usage): add opt-in queued accounting for staging - #8081
Merged
johnnyeric merged 1 commit intoOct 19, 2026
Merged
johnnyeric merged 1 commit into
johnnyeric merged 1 commit into
Conversation
johnnyeric
force-pushed
the
johnnyeric/usage-staging-queue-only
branch
from
October 19, 2026 12:51
9d20acb to
99a8928
Compare
johnnyeric
marked this pull request as ready for review
October 19, 2026 13:24
chrarnoldus
approved these changes
Oct 19, 2026
This was referenced Oct 19, 2026
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.
Summary
Add default-off, opt-in queued accounting for staging with direct fallback.
USAGE_QUEUE_ONLY_ENABLED=truetakes effect only withVERCEL_TARGET_ENV=stagingand a non-production Vercel environment. Confirmed HTTP 202 publication skips the gateway direct usage write in either function region. Missing configuration, failed lifetime registration, unavailable publication or unexpected rejection uses the existing writer with the same finalized usage ID and payload. Queue mode takes precedence over shadow mode, preventing a second publication. Production cannot enable queue-preferred accounting.Move immediate spend-watched Bouncer reporting into the writer's existing post-commit tasks for both direct and queued writes. Billing and the Bouncer outbox commit together; the writer then attempts delivery without turning a delivery failure into a billing failure. Duplicate usage writes do not repeat delivery or bypass outbox backoff, and cron retries unsuccessful delivery. The gateway retains best-effort reporting if its direct write fails. Accounting returns an explicit queued or recorded status; queue acceptance does not imply a committed database row or a durable production publication guarantee.
Verification
Visual Changes
N/A
Reviewer Notes
Stacked on the staging processing prerequisite, PR #8074. Review the production veto, tracked acceptance lifetime, same-ID fallback and writer-owned Bouncer delivery after commit. Publish/deploy the updated writer before relying on prompt reporting from the updated gateway; older writer deployments must preserve the Bouncer outbox payload. Publisher timeout can add up to two seconds before direct fallback starts; the writer now awaits the existing bounded Bouncer delivery attempt after commit (up to five seconds). Bouncer failure leaves the successful billing outcome and outbox retry intact. The consumer's retry/DLQ policy is unchanged.
Automated checks: 71 publisher/lifecycle tests, 82 writer/accounting/outbox tests, 10 composed FRA/SFO scenarios, shared and targeted route typechecks, focused lint, formatting and whitespace checks.