Conversation
A parked graph used to resume with budget=None, so the ceiling that held before request_approval did not hold after it. Persist the allowance and spend in graph context and rebuild BudgetedGateway on resume. Co-authored-by: Cursor <cursoragent@cursor.com>
Owner
Session 16 — graded ✅Score: +100. The run budget was lost across wait/resume, so a run that survived a restart came back unbounded. |
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.
What breaks
A budgeted run that parks on
request_approval(or any other wait) resumes withbudget=None. HTTP resume, channel-thread approval, job completions, and the UI/v1/actionpath all callruntime.run(..., resume=True)without the original ceiling. Graph context restored the prompt and side-effects, not the allowance or spend, soBudgetedGatewaywas never rebuilt. The control that held before the wait did not hold after it: the same run could continue unmetered.Restoring only the original ceiling with spend reset to zero would still be a bypass (a second full allowance after every wait). Spend has to come back too.
Reproduction
On current
main, this test fails because the resumed body hasbudget: null:Steps without the test:
POST /v1/agent/runswith"budget": 0.05andallowed_side_effects: ["request_approval"]until a node iswaiting.POST /v1/agent/runs/{run_id}/resume(no budget in the body; the route does not accept one)."budget": nulland gateway calls are not metered throughBudgetedGateway. After it,budget.totalis still0.05andbudget.spentis at least what the parked run had already charged.Fix
budget,principal, andbudget_spentin graph context on start and after everyrun()return (including waits).resume=True, rebuildRunBudget+BudgetedGatewayfrom that context even when the caller passesbudget=None, and restore prior spend.transporton the HTTP resume and UI action routes so the metered seam can actually be reconstructed.uv run pytest tests/test_budget_runtime.py tests/test_runtime.py tests/test_channel_connections.py tests/test_control_plane_auth.pyanduv run ruff checkon the touched files pass. No.env, tokens, or real messages in the diff.