fix(sdk): an authored budget refusal names the limit it crossed - #594
Conversation
The kernel refuses admission of an authored flow's next step with only `budget_exceeded`, and the authored runner reported "Flow budget exceeded before the next step." — no limit, no numbers. Cloud run f28314ed stopped on it after 26 successful steps, and the operator had to reconstruct from step durations that the flow header's `wallclock: "2h"` (summed step time, 132.9 min) had tripped, not the dollars cap or the Cloud run budget. The accumulator already carries the exact totals it sends as prior_spend, so the refusal now names each declared limit the carried spend crossed, with used vs declared, using the kernel's strict comparisons, and names the refused step when the child spec has exactly one: Flow budget exceeded before step "run-27": wallclock 132.9m used of 2h declared in the flow's budget header. Dollars say when some charges were unmetered, and a day-window budget says so. When the carried totals cannot explain the refusal, the original wording stays, so the SDK never invents a reason. Error code and completion reason are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee2383c567
ℹ️ 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".
Review of #594: rounding both durations to one decimal minute/second could render a strict overrun as "2m used of 2m declared" (120001 vs 120000 ms) or a sub-second one as "0s used of 0s"; both now fall back to exact milliseconds when the rounded forms coincide. A legacy maxDollars with more than six decimals was dropped from the message although the kernel compares it as written; the carried microdollars are now compared at the limit's own precision and the limit is printed as declared. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dca79253a9
ℹ️ 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".
Review of #594 (Codex): an exact-hour limit renders in hours and the spend in rounded minutes, so 7200001 ms against 2h printed "120m used of 2h" and the string-equality fallback missed it. The fallback now compares the quantities the texts denote and drops to exact milliseconds unless the displayed spend itself reads as over the displayed limit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
Problem
When the kernel refuses an authored flow's next step for budget, the authored runner reports only:
It says nothing about which limit tripped or by how much. Cloud run
f28314ed(software-factory, cloud#4033) stopped with exactly this message after 26 successful steps. From the message alone, the operator couldn't tell whether the flow header'swallclock: "2h", itsdollars: 25, or Cloud's per-launch run budget (180m) had fired. It took summing the step durations to show that the header's wallclock was the limit: 132.9 min of summed step time against 2h.Change
packages/sdk/src/authored-budget.ts: the accumulator already holds the exact totals it sends to the kernel asprior_spend. On abudget_exceededadmission, the error now names each declared limit the carried spend crossed, using the kernel's strict>comparisons frommachine/budget.rs:;.metered (some steps unmetered)when any charge was unmetered, because the figure is then a lower bound./daybudget saysin today's window of the flow's budget header.step_failed) and completion reason (budget_exceeded) are unchanged. The kernel is untouched.Tests
packages/sdk/tests/budget-attribution.test.tsadds three tests:AuthoredBudget.executerefusal with the f28314ed totals, checking the full message, code and completion reason.Mutation check: I reverted
src/authored-budget.tstoorigin/mainand stubbed the new export so the file compiled.Then I restored the file (
cmpidentical) and re-ran:Full SDK suite (
npm test: kernel build, typecheck, build, test typecheck, vitest), run locally:The 13 failures are live-daemon, webhook and trigger tests (
webhook-live,provider-trigger-executor,live-kernel,event-await-cli,communication-mixed-resume,mcp,cloud-run,authored-node-runtime). None of them touch the budget code. Re-running those 8 files withsrc/authored-budget.tsswapped back toorigin/main(rebuilt) gives the identical13 failed | 115 passed | 20 skipped. They fail on this machine regardless of the change, and CI is the authority for them.Related finding (not changed here)
The same run spent $39.34 by Claude's
total_cost_usdunderdollars: 25without the dollar cap tripping. The kernel's metered dollars come frompricedUsage(model, input_tokens, output_tokens), usingworker-usage.tsusageResultandmodel-pricing.ts. Claude'susage.input_tokensexcludescache_read_input_tokensandcache_creation_input_tokens. Recomputing the run's Claude steps with the publishedworkerSpendgives $6.45 metered against $39.34 reported, so a dollar cap on a cache-heavy Claude flow cannot trip near its declared value. That is reported separately and not fixed in this PR.🤖 Generated with Claude Code
Note
Cursor Bugbot is generating a summary for commit ee2383c. Configure here.
Summary by cubic
The kernel refuses an authored flow's next step for budget with only
budget_exceeded, so the SDK now names which declared limit the carried spend crossed and by how much, instead of the generic "Flow budget exceeded before the next step."Written for commit 2847595. Summary will update on new commits.