Repository navigation
fix(workbench): bound the run_python budget by tokens, not just by script count - #3
Merged
Merged
Conversation
…ript count The execution cap counted how many scripts an agent could run and said nothing about what they cost. That is a proxy, and it was wrong by two orders of magnitude. The validation run made the case better than the original incident did. On the same sample, with nothing failing and no cap reached, the workbench went from 49 executions costing 5.19M tokens to 91 costing 11.6M -- the run total doubling from 7.7M to 18.3M. Peak context reached 228k, above the old 200k ceiling, so raising that budget had gone from precaution to load-bearing in a single run. The count never noticed any of it. What actually ends a run is not the number of scripts but the conversation they grow, which every later stage inherits. LESSONS_LEARNED #20 records the ILSpy stage being killed before its first tool call for exactly this reason, while the stage that had spent the budget looked perfectly successful. So the guard gains a second axis, reading the same usage accumulator the cost report renders from -- the governor and the report can never disagree about what a run cost. The ceiling is measured from the workbench's own first script rather than from the start of the run, so a sample with an expensive triage does not arrive with its allowance already gone. It is a backstop, not a routine limit. Set above both observed healthy runs so it never truncates work that was going to succeed, and below a further doubling so a genuine runaway stops. Both measured runs are pinned as tests alongside the runaway case, because a ceiling that cuts short a good analysis would be a worse failure than the one it was written to prevent. Fails open throughout: a governor that cannot read usage lets work through rather than blocking it, so an observability gap never becomes a stalled analysis. The short-circuit keeps run_python's exact result shape, since a before_tool return value IS the tool response -- a wrong shape would reach the model as a malformed result instead of a finalize advisory.
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.
The execution cap counted how many scripts an agent could run and said nothing
about what they cost. That is a proxy, and it was wrong by two orders of
magnitude.
The validation run made the case better than the incident did
Same sample, nothing failing, no cap reached:
228k is above the old 200k ceiling — raising that budget went from precaution
to load-bearing in a single run. The execution count never noticed any of it.
What ends a run is not the number of scripts but the conversation they grow,
which every later stage inherits.
LESSONS_LEARNED#20 records the ILSpy stagebeing killed before its first tool call for exactly this reason, while the stage
that had spent the budget looked perfectly successful.
The fix
A second axis on
run_python_budget_guard, reading the same usage accumulatorthe cost report renders from — so the governor and the report can never
disagree about what a run cost.
Measured from the workbench's own first script, not from the start of the
run: a sample with an expensive triage must not arrive with its allowance
already gone.
Calibrated against real runs, not guessed
A backstop, not a routine limit. Both measured runs are pinned as tests — a
ceiling that cuts short a good analysis would be a worse failure than the one it
was written to prevent.
Fails open
A governor that cannot read usage lets work through rather than blocking it, so
an observability gap never becomes a stalled analysis (tested against
None,junk, and malformed accumulators). The short-circuit keeps
run_python's exactresult shape — a
before_toolreturn value is the tool response, so a wrongshape would reach the model as a malformed result instead of a finalize advisory.
make check: 2478 passed, 1 skipped. 9 new tests.Not yet exercised by a live run — the ceiling sits above both observed runs,
so a normal analysis should not notice it. That is the intended outcome and also
means the next live run confirms only that it does not misfire.