Skip to content

fix(workbench): bound the run_python budget by tokens, not just by script count - #3

Merged
Alevsk merged 1 commit into
mainfrom
fix/workbench-token-bound
Aug 11, 2026
Merged

Alevsk merged 1 commit into
mainfrom
fix/workbench-token-bound

Conversation

@AsherDLL

Copy link
Copy Markdown
Member

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:

run A run B
workbench executions 49 91
tokens 5.19M 11.6M
run total 7.7M 18.3M
peak context 207k 228k

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 stage
being 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 accumulator
the 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

ceiling: 16,000,000 tokens

run A (49 calls, measured)      5,190,000  ->  allowed
run B (91 calls, measured)     11,642,265  ->  allowed
run B doubled (runaway)        23,284,530  ->  STOPPED

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 exact
result shape — a before_tool return value is the tool response, so a wrong
shape 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.

…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.
@Alevsk
Alevsk merged commit b70fe2e into main Aug 11, 2026
2 checks passed
@Alevsk
Alevsk deleted the fix/workbench-token-bound branch August 11, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants