Repository navigation
Stop runs at a hard budget cap per thread and per automation - #1690
Conversation
thread.budget {usd,tokens,turns,minutes} is harness state on the thread
row, so compaction cannot drop it. Agent profiles and automations carry a
default stamped onto the thread; forks inherit it. The start gate refuses
an over-cap run; a 15 s watchdog sweep stops a run that crosses a cap.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shared BudgetFields in the thread budget card (thread menu, and shown on its own once over the cap), the agent profile editor and the automation form. Workflow runs get the same start gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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: fabd36d566
ℹ️ 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".
| if (!entry || entry.stopping || budgetStopping.has(threadId)) continue; | ||
| const thread = store.getThread(threadId); | ||
| if (!thread || !thread.budget || thread.memoryConsolidate === true) continue; | ||
| const why = budgetBreach(thread, store.getUsage(threadId), now); |
There was a problem hiding this comment.
Use in-flight workflow usage for cap enforcement
When the active entry is a workflow, completed agents accumulate spend and tokens in entry.runUsage, while store.getUsage(threadId) is not updated until finishSuccess in electron/workflow.js. Consequently, a workflow whose first agent exceeds its USD or token cap continues launching later agents and phases, and stopped or failed workflow usage may never affect the next-start gate. Include the workflow's in-flight usage in this check and persist billed usage on every terminal path.
Useful? React with 👍 / 👎.
| setDraft(budgetToDraft(thread.budget)); | ||
| setError(null); | ||
| }, [thread.id, budgetKey]); | ||
| if (!onSetBudget || (!open && !reached)) return null; |
There was a problem hiding this comment.
Show minute-cap stops in the budget card
When a minutes-only cap fires, stopRun clears runStartedAt, and budgetReached intentionally checks only lifetime USD/token/turn usage, so reached is false here. Because open is also false for an automatic stop, the watchdog marks the thread awaitingInput and instructs the user to raise or clear the cap, but the card containing those actions remains hidden; preserve a budget-stop reason/state and use it to display the card after minute-cap stops.
Useful? React with 👍 / 👎.
# Conflicts: # electron/services-settings.js # src/shared/ipc.ts
A thread or automation can now carry a hard cap on spend, tokens, turns or minutes per run. Hitting any of them stops the run and asks the user instead of continuing. Closes #286.
Changes
thread.budget(usd,tokens,turnscount lifetime usage;minutesis per run) lives on the thread row, so context compaction, reloads and session resets can't drop it.solenta.json) stamps its cap on every thread it fires. Forks and orchestration workers inherit the cap with fresh counters, so fanning out doesn't get around it.Verification
npm run test:electronin a CI-like env (inheritedCODER_*vars and provider CLIs stripped): 4960 pass, 0 fail.electron/test/budget-caps.test.js(10 tests): the cap survives compaction and reload; profile, fork and automation stamping;solenta.jsonparsing; a real fake-claude run refused after crossing a $ cap until the cap is raised; a hung run stopped by the minutes cap.test/budgetCard.test.tsx, plus budget cases inautomationsViewandsettingsModal. Those files and the ThreadView/plan card/find files pass. I didn't rerun the whole renderer suite after fixing a duplicate React key I had introduced (the fix is in this PR).npm run typecheck(with the preload sync check) andnpx vite buildare clean.Notes for reviewers
usdmoves only when a provider reports usage. Claude reports once per turn, so a single long turn can overshoot a $ or token cap;minutesis the hard stop partway through a turn.tokensis input + output as the ledger records them, which excludes Claude's cached input. Live per-message metering is a follow-up.solenta.json: a row without a cap keeps its existing hash, so trusted files stay trusted. Adding or changing a cap needs a re-trust, on purpose.automation_create(the agents' MCP tool) doesn't take a budget yet; that's a follow-up.claude-opus-5-5 via Claude Code