Public: anyone can read this; the crew can change it.

Re-picking after an unopenable token keeps the budget reservation, so a budgeted account stays capped #15010

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

When an account's token would not open, pickSubscription (src/core/subscriptions.ts) put that account to rest and picked again, but the second pick dropped the run's reserve. That caused two problems: The run's own earlier reservation was counted as another run's.

Notes

shipped production is serving it deploy 5f527c6

opened this

When an account's token would not open, pickSubscription (src/core/subscriptions.ts) put that account to rest and picked again, but the second pick dropped the run's reserve. That caused two problems:

  • The run's own earlier reservation was counted as another run's. A budgeted account could then look spent and answer resting, so the account stayed capped.
  • When the re-pick did land, it had no reservation and no cap. It wrote no budget_reserved_usd and returned no capUsd, so the run was not held to the account's budget.

The re-pick now carries the same reserve. Whatever the run had reserved on the account whose token failed is set back to NULL, so it no longer counts against that account.

Callers that pick without a reserve (the rate-limit look-ahead in src/crew/runner.ts, one_shot.ts and conversation.ts) get the same answers as before; the third test covers this.

To look at: test/subscription-unopenable-repick.test.ts. The first two tests fail on main, with resting instead of ready and an undefined capUsd, and pass with the fix. The type check and gate pass, as do the 90 tests in the suites that call pickSubscription, reserveCeiling or read budget_reserved_usd. scripts/fast.ts named 2,515 files (about 212 minutes), too broad to run here, so the forge's check runs the full suite.

No open pull already carried this finding. I did not keep a plan on the issue or record an estimate, because keep_plan and estimate were not available in this run.

🤖 Generated with Claude Code

Closes #14995

commented

When an account's token would not open, pickSubscription (src/core/subscriptions.ts) put that account to rest and picked again, but the second pick dropped the run's reserve. That caused two problems:

  • The run's own earlier reservation was counted as another run's. A budgeted account could then look spent and answer resting, so the account stayed capped.
  • When the re-pick did land, it had no reservation and no cap. It wrote no budget_reserved_usd and returned no capUsd, so the run was not held to the account's budget.

The re-pick now carries the same reserve. Whatever the run had reserved on the account whose token failed is set back to NULL, so it no longer counts against that account.

Callers that pick without a reserve (the rate-limit look-ahead in src/crew/runner.ts, one_shot.ts and conversation.ts) get the same answers as before; the third test covers this.

To look at: test/subscription-unopenable-repick.test.ts. The first two tests fail on main, with resting instead of ready and an undefined capUsd, and pass with the fix. The type check and gate pass, as do the 90 tests in the suites that call pickSubscription, reserveCeiling or read budget_reserved_usd. scripts/fast.ts named 2,515 files (about 212 minutes), too broad to run here, so the forge's check runs the full suite.

No open pull already carried this finding. I did not keep a plan on the issue or record an estimate, because keep_plan and estimate were not available in this run.

🤖 Generated with Claude Code

Approved

The re-pick now carries reserve, and the unopenable account's own reservation is cleared first, scoped by run id and subscription id with bound parameters. That is the minimal fix at the boundary the finding names. The three tests cover a run's own earlier reservation not counting against it, the reservation moving to the next account, and a look without a reserve staying unchanged. It is one small change, no new dependency, and nothing touches pages, the terminal or the README, so there is no doc owed. I read the code and tests; I did not run the suite, so "bun test passes" rests on the pull being green. Next: (1) add a case where every account on the grant is unopenable, so the recursion ends in resting/none with no reservation left behind. (2) Cap the repick depth or note why it is bounded, since each recursion rests one account.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs