Repository navigation
fix(coding/acp): deliver the controller cancel before a cancelled turn ends - #36
Merged
Merged
Conversation
…n ends A turn arms its controller cancellation with context.AfterFunc and disarms it in finish, and AfterFunc delivers on its own goroutine: when the prompt returns on its own cancellation before that goroutine is scheduled, the disarm prevents the delivery and the controller is never cancelled. The session test then waited its full thirty seconds for a cancelCount that could never move, which is what main hit. deliverCancelOnDone now owns that pairing and guarantees the delivery: the disarm waits for a callback that has already started, and delivers itself when the callback was prevented and the context is done anyway. The session test asserts the count directly instead of waiting, and a unit test of the helper pins all three orderings — cancelled before the disarm, disarmed before the cancel, and an open context — because nothing here may depend on which goroutine the scheduler runs first. Measured: the strengthened guard fails against the previous implementation within two hundred runs (0.8s) and passes two hundred runs with this change, both under -race.
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.
A turn arms its controller cancellation with context.AfterFunc and disarms it in
finish, and AfterFunc delivers on its own goroutine: when the prompt returns on its
own cancellation before that goroutine is scheduled, the disarm prevents the
delivery and the controller is never cancelled. The session test then waited its
full thirty seconds for a cancelCount that could never move, which is what main hit.
deliverCancelOnDone now owns that pairing and guarantees the delivery: the disarm
waits for a callback that has already started, and delivers itself when the callback
was prevented and the context is done anyway. The session test asserts the count
directly instead of waiting, and a unit test of the helper pins all three orderings
— cancelled before the disarm, disarmed before the cancel, and an open context —
because nothing here may depend on which goroutine the scheduler runs first.
Measured: the strengthened guard fails against the previous implementation within
two hundred runs (0.8s) and passes two hundred runs with this change, both under
-race.
Evidence
The strengthened session guard fails against the previous implementation within two hundred
-raceruns (0.8s) and passes two hundred runs with this change. The new helper test pins the three orderings deterministically: cancelled before the disarm delivers exactly once, a disarm before the cancel delivers nothing (a turn that ends on its own must not cancel the controller), and an open context delivers nothing.TERM=xterm-256color go test ./...(89 packages),go test -race ./internal/coding/acp/andgolangci-lint run --new-from-rev=HEAD~ ./...(0 issues) are clean.