ORB-91: Reserve AI quota atomically - #460
Conversation
|
Implementation approach
Expected files are the pay gate interface and service, the two chat partials, the two suggestion handlers, and the existing chat and pay gate test files. I am using the repository's existing optimistic concurrency retry support instead of an application lock or a detached increment because the database concurrency token provides cross instance serialization without a process local critical section. |
|
Approach correction after the required call site audit Current The atomic reservation change remains scoped to chat, where the count is still detached into post response work and the acceptance test requires a ten request burst. I will add a consuming pay gate operation for chat, reserve through the existing |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 44d9440ad1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
DEGRADED: same-vendor review Independent xhigh review found two blocking items on the current implementation:
These findings are frozen for one focused fixer round. No merge was performed. |
|
I will close the three blocking findings in three narrow slices:
The implementation will stay in the existing pay-gate contract and handler files. I am not adding process locks, a second quota abstraction, or post-provider metering because those shapes either do not coordinate across instances or reopen the original race. |
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |



DEGRADED: same-vendor review
Closes ORB-91.
What changed
All ORB-91 gated AI provider paths now use
TryConsumeAiMessageto reserve quota atomically at the provider boundary. Habit setup checks its response cache first. Tag suggestions load existing tags first. Chat finishes its non-provider context and prompt work first. Each path reserves immediately before its provider call.Chat FAQ cache hits return without reserving quota. Cache misses reserve exactly once. A reservation is retained when a provider call fails because provider work may already have incurred cost.
The old post-provider counter writes in habit setup and tag suggestions were removed, along with their unused repository and logging dependencies.
Concurrency proof
The chat race regression now creates ten request-local repository and unit-of-work scopes over ten distinct stale
Usersnapshots. One request persists the twentieth free-plan message. The other nine saves throwDbUpdateConcurrencyException; the real pay-gate retry discards pending changes, reloads the persisted count, and rejects them at the quota guard. The result is one successful response, nine pay-gate failures, one model call, and a persisted count of 20.Verification
dotnet build Orbit.slnx --no-restore: 0 errorsdotnet test tests/Orbit.Application.Tests --no-build --no-restore: 2,978 passeddotnet test --no-build --no-restore: 5,597 passednode tools/arch-map.mjs: regenerated both architecture artifacts with 0 orphan endpoints and 0 untested feature foldersNo external response field, flag, exit code, or API response shape is read by this change.