Skip to content

fix(coding/acp): deliver the controller cancel before a cancelled turn ends - #36

Merged
rsbin1178 merged 1 commit into
mainfrom
fix/acp-cancel-delivery
Oct 8, 2026
Merged

rsbin1178 merged 1 commit into
mainfrom
fix/acp-cancel-delivery

Conversation

@rsbin1178

Copy link
Copy Markdown
Owner

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 -race runs (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/ and golangci-lint run --new-from-rev=HEAD~ ./... (0 issues) are clean.

…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.
@rsbin1178
rsbin1178 merged commit 6099a09 into main Oct 8, 2026
4 checks passed
@rsbin1178
rsbin1178 deleted the fix/acp-cancel-delivery branch October 8, 2026 15:12
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.

1 participant