Repository navigation
fix(api): account for worker-interrupted usage and block unconfirmed spend - #452
Open
shuntianyifang wants to merge 3 commits into
Open
shuntianyifang wants to merge 3 commits into
shuntianyifang wants to merge 3 commits into
Conversation
shuntianyifang
marked this pull request as ready for review
October 7, 2026 10:49
This branch has not been 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.
When a worker died during an agent call, recovery marked the turn failed without recording provider usage. Project spending stayed understated and later calls could pass a budget that should have blocked them.
This change retains per-turn numerical usage in the workspace independently of the worker's observation connection, reconciles confirmed charges once, and records incomplete spending as unpriced. Enabled budgets enter
unconfirmedand block new agent and title-generation calls until final retained usage is reconciled. Raising the limit, resolving attention, or a calendar rollover does not clear uncertainty. Recovery also handles missing bills left by older workers, without waking compute or rerunning a model. Confirmed charges count when settled, consistent with live-worker accounting.API/OpenAPI/SDK types, spend presentation, and operator documentation describe the new state. No database migration or dependency change is required.
Closes #399.
Validation
Follow-up validation at
45dc057(2026-10-07):pnpm test:criticalpassed 865 tests across 79 isolated processes, no skips, using a fresh dedicated PostgreSQL 16.15 database. API typecheck and repository lint passed. Two additional regressions verify that every unknown bill must settle before admission resumes, and competing final reports settle exactly once without replay changing the charge. Only test code changed after the full validation below.Full validation at
ea4da90(2026-10-07), against upstream main38ec556:pnpm verifypassed lint, typecheck (14 tasks), clean full workspace build (8 tasks, no cache hits), 863 critical tests and 320 remaining tests, unused-reference checks, and both guards. No normal-suite skips. The final dependency audit exits nonzero; see below.ghcr.io/theam/facility/runner@sha256:9aad7af6b96b36c31f2e20806c19fea08e066af9d9aa412a961b4c3c5c1032a0.Dependency audit remains failing
The lockfile, manifests, and audit policy match upstream
38ec556; this PR adds no exceptions. The current audit reports 3 unignored findings, plus 3 existing ignored high findings:shell-quote, GHSA-pqg4-j6r4-53mv, fixed in 1.11.0 or later.sharp, GHSA-wq5f-xc86-pv6w, fixed in 0.35.5 or later.@modelcontextprotocol/sdk, GHSA-6qxp-vccf-f47h, fixed in 1.31.0 or later.Limits and coordination
c7473f9conflicts with this branch in README, costs.ts, story service, and titles.ts. Both heads require an explicit resolution; choosing either side wholesale is unsafe. See the tested integration requirements below.Compatibility with #440
A separate local combined candidate passed 79 related API tests across six files, no skips, and API typecheck, with the same local PostgreSQL 16.15 / deterministic engine setup. This is validation of an explicit conflict resolution, not of the unmodified heads. The required resolution is:
budget_usage_unconfirmedpolicy alongside feat(api): reserve monthly budget before a turn runs #440's measured usage + open holds + settled title totals.reserveTurnafter locking the budget row, using the claim transaction. Check it inreserveTitlebefore either creating or reusing an existing hold; propagate anunconfirmedoutcome to title fallback.completeflag. Write measured/unknown usage and release the turn reservation in one transaction. Final usage must replace the placeholder once; feat(api): reserve monthly budget before a turn runs #440's conflict-ignore insertion cannot do that.Four combined-candidate regressions verify unknown recovery blocks turn/title reservation after releasing the hold, title hold reuse cannot bypass uncertainty, confirmed journal replaces a hold exactly once, and pre-engine recovery releases without a bill. Removing the admission guards causes two tests to fail; restoring conflict-ignore causes the late-final-report regression to fail. The normal candidate suite has no skips; filtered negative controls intentionally skip unrelated tests. The candidate and its extra reservation tests are retained separately and are not part of this PR's code or migration scope. Revalidate the combined implementation when either PR changes.
Upstream CI and review status
At
45dc057, the pull-requestciand conventional-subject workflow runs reportaction_required; the conventional-subject run has zero jobs. The account has upstreampull: true,push: false,maintain: false,admin: false. Maintainer approval is required before upstream workflows can execute. There are no reviews or comments to resolve yet. The new test-only commit does not claim successful remote CI, and this PR remains draft. No workflow permission changes or audit exceptions were made.