Repository navigation
[AISAGE-503] feat(gateway): enqueue finalized usage in background shadow mode - #7296
Merged
johnnyeric merged 1 commit intoOct 8, 2026
Conversation
4 tasks done
johnnyeric
marked this pull request as ready for review
October 8, 2026 13:50
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (6 files)
Reviewed by deepseek-v4.1-flash · Input: 80.5K · Output: 21.4K · Cached: 1.1M Review guidance: REVIEW.md from base branch |
joshburt
self-requested a review
October 8, 2026 14:06
joshburt
approved these changes
Oct 8, 2026
This was referenced Oct 9, 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
With
USAGE_SHADOW_PUBLISH_ENABLED=true, the gateway sends its finalized usage event to the queue-backed ingestion endpoint in both Frankfurt and SFO. It reuses the existing event and ID while current billing remains authoritative and independent of enqueue acceptance. The switch defaults off.Enqueue runs in its own tracked
afterpromise, including when earlier request-cleanup callbacks have finished. Publishing starts only after lifetime registration succeeds; missing request scope or lifetime support performs no network work. Acceptance and failure logs contain safe identifiers and categories. Staging enables the ingestion Worker'sworkers.devURL for testing after deployment; production public URLs and preview URLs remain disabled.Verification
Visual Changes
N/A
Reviewer Notes
Depends on #7295 (usage enqueue helper); this PR contains only gateway integration, its configuration/tests, and staging endpoint configuration/docs.
Validation: 214 focused tests and 43 selected processUsage tests pass; 22 DB-backed cases excluded. Both typechecks, scoped lint, formatting and diff checks pass. The real Next lifecycle regression fails on the previous callback implementation in both regions and passes with independent promise registration. Staging and production deployment dry runs passed.
Database writes, authoritative writer transport and provider behavior are mocked/synthetic, and request lifecycle hooks are synthetic. Worker/HTTP/local queue components run in the actual local runtime with a temporary receipt consumer. No hosted gateway verification or real billing/inference was performed.
The existing Worker schema strips redundant runtime
metadata.requested_model;core.requested_modelis retained. The gateway sends the unchanged event, and queue receipts match its validated contract fields. HTTP 202 means enqueued, not processed or billed.