Repository navigation
Refuse and close decision requests after their run ends - #2140
Merged
Merged
Conversation
ppXD
force-pushed
the
fix/refuse-decisions-after-run-end
branch
from
November 7, 2026 18:11
6142c90 to
6235157
Compare
A run's normal completion keeps its fence epoch, so a decision.request already past the authority guard could still claim a ledger row and park it on a finished run, leaving an open question that accepts answers into nothing. A row claimed before the end but parked after it was likewise skipped by the end's close, which only covered AwaitingApproval. TryClaimAsync now reads the run's status together with its epoch under the same FOR SHARE and refuses a new claim on a terminal run with AgentRunEndedException before comparing the fence, so a run ended by a stop, abandon or recovery (which bump the epoch) answers "ended" rather than lost ownership. An existing key still replays and a run with no row keeps the epoch-0 rule. The park is guarded against ended runs without taking a run lock ahead of the row lock, which would deadlock against the terminal. StoppedRunDecisions.ExpireAsync now closes Pending as well as AwaitingApproval rows. The MCP handler answers a refused call as final instead of "retry shortly", and a re-call of a still-Pending decision re-parks it, posting exactly one card.
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
AgentRunEndedException. The run's status is read with its fence epoch under the sameFOR SHAREand checked before the fence, so a run ended by completion, stop, abandon or recovery always answers "ended". An existing key still replays asDuplicate, and a run with no row keeps the epoch-0 rule. The park never parks a row whose run ended, and takes no run lock ahead of the row lock.StoppedRunDecisions.ExpireAsynccloses Pending as well as AwaitingApproval decisions.Known gaps (follow-up)
decision.requestrows are closed by the stop's own close.ReplayOnEndedRunAsyncreturns InFlight for a Pending write row on an ended run, andResumeOrTicketAsyncthen blocks until the lease reaper.Test plan