fix: finalize circuit-broken agent runs through usage accounting#4178
fix: finalize circuit-broken agent runs through usage accounting#4178orange-dot wants to merge 9 commits intosuperplanehq:mainfrom
Conversation
Signed-off-by: Bojan Janjatović <bojan.janjatovic@mamut-studio.com>
|
👋 Commands for maintainers:
|
Signed-off-by: Bojan Janjatović <bojan.janjatovic@mamut-studio.com>
d37d65c to
3038dcc
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4d3be70. Configure here.
Signed-off-by: Bojan Janjatović <bojan.janjatovic@mamut-studio.com>
Signed-off-by: Bojan Janjatović <bojan.janjatovic@mamut-studio.com>
|
Observation from local follow-up on April 16, The public Semaphore run failed on I ran the same targeted test locally in an
All three passed locally. Not claiming the PR is clean from this alone, |
Signed-off-by: Bojan Janjatović <bojan.janjatovic@mamut-studio.com>

Summary
This fixes the circuit-break finalization path so agent runs record and publish usage through the same run-level accounting surface used by the normal completion path.
Why
Circuit-broken runs can terminate after real model usage has already accumulated. If that path does not finalize through the same run-level accounting source as normal completion, the recorded totals can drift from the actual run state.
What changed
agent_run.usage()in the web agent flowScope guardrails
Validation
agents_testDB recreate plus agent migrationsdocker compose -f docker-compose.dev.yml run --rm -e DB_NAME=agents_test agent uv run --group dev python -m pytest tests/test_agent_http.py tests/test_tool_loop_guard.py tests/test_list_integration_resources.pydocker compose -f docker-compose.dev.yml run --rm -e DB_NAME=agents_test agent uv run --group dev python -m pytest testsObserved results:
12 passed172 passedRequest for review
Would appreciate a close look at whether this keeps the accounting/finalization contract tight enough around circuit-broken runs without widening scope beyond the runtime paths that actually participate in usage publication.