Repository navigation
fix: ephemeral budget gate no longer counts the execution's own pre-created row (#1601) - #1602
Merged
Merged
Conversation
… own pre-created row (#1601) The /task and scheduler paths pre-create the execution row with status=RUNNING before execute_task → CapacityManager.acquire, so the #69 admission gate's terminal+active count included the row being admitted: a max_executions=1 ghost denied its first (only) run with 410 ephemeral_budget_exhausted, and every N-budget ghost lost its final run. Fix: acquire already knows the execution_id being admitted — thread it through as count_ephemeral_budget_usage(exclude_execution_id=...) and exclude that row from the count. Paths that acquire before creating the row are unaffected (the id isn't in the table yet — exclusion is a no-op). The terminal discard hook keeps the un-excluded count (the just-finished row must count). Concurrency overshoot bound preserved: two racing admissions for the last budget slot each exclude only their own row, so they still see each other and both deny. Found by the live activation smoke required by trinity-enterprise#148. Verified live: a max_executions=1 ghost admits, runs (SMOKE-OK), and hard-discards via the terminal hook within seconds. Fixes #1601 Co-Authored-By: Claude Fable 5 <[email protected]>
…ow (#1601) Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
Review — LGTMTraced the logic and the race analysis holds. The root cause (the Non-blocking notes:
Nice catch surfacing it via the trinity-enterprise#148 activation smoke. |
dolho
approved these changes
Jul 14, 2026
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.
Summary
/taskand scheduler paths pre-create the execution row withstatus=RUNNINGbeforeexecute_task→CapacityManager.acquire, so the Filter agents by owner on Dashboard and Agents pages #69 ephemeral admission gate'sterminal + activecount included the row being admitted: amax_executions=1ghost denied its first (only) run with 410ephemeral_budget_exhausted, and every N-budget ghost lost its final run. Found by the live activation smoke required by trinity-enterprise#148.acquirealready knows theexecution_idbeing admitted — thread it through ascount_ephemeral_budget_usage(exclude_execution_id=...)and exclude that row from the count. Paths that acquire before creating the row are unaffected (the id isn't in the table yet — exclusion is a no-op). The terminal discard hook keeps the un-excluded count (the just-finished row must count).Changes
src/backend/db/agent_settings/ephemeral.py— optionalexclude_execution_idoncount_ephemeral_budget_usagesrc/backend/services/capacity_manager.py— gate passes the admittedexecution_idsrc/backend/database.py— facade delegation carries the kwargtests/unit/test_69_ephemeral_agents.py— new: DB-layer exclusion (own row / unknown id no-op) + gate-level bug: ephemeral budget gate counts the execution's own pre-created row — max_executions=1 ghosts can never run #1601 scenario (own row admits, racing sibling still denies, id threaded through); existing monkeypatched doubles updated to the new signatureTest plan
tests/unit/test_69_ephemeral_agents.py— 42 passed (40 existing + 2 new)test_capacity_manager.py,test_backlog.py— 101 passed combinedmax_executions=1ghost 410'd its first/task; post-fix the same flow admits, runs (SMOKE-OK), and hard-discards via the terminal hook within seconds (container removed, ownership purged, auditephemeral_discardrow)Fixes #1601
🤖 Generated with Claude Code