Skip to content

fix: don't clobber attached runtime's cancel in RunSession/recallSession#3525

Merged
Sayt-0 merged 1 commit into
mainfrom
worktree-board-e24afe8043392316
Jul 8, 2026
Merged

fix: don't clobber attached runtime's cancel in RunSession/recallSession#3525
Sayt-0 merged 1 commit into
mainfrom
worktree-board-e24afe8043392316

Conversation

@dgageot

@dgageot dgageot commented Jul 8, 2026

Copy link
Copy Markdown
Member

go test -race ./pkg/server/ made TestAttachedServer_DeleteWithWaitBlocksUntilStreamStops fail roughly 25% of runs with "DELETE returned before the stream goroutine exited". The race was introduced by commit 064a464 ("fix: wake idle sessions on tool recall"), which unconditionally overwrote runtimeSession.cancel in SessionManager.RunSession and rt.cancel in recallSession with the per-stream cancel. DeleteSession then aborted the in-flight stream instead of cancelling the attach context, so WaitStopped returned as soon as the aborted stream unwound — breaking the graceful-delete contract established in e73a2c0 (DELETE /api/sessions/:id?wait=true must block until the stream ends naturally).

The fix guards both cancel assignments with done == nil. The done channel is only set by AttachRuntime, so server-owned sessions continue to get the abort-on-delete behaviour from 064a464, while attached (TUI-owned) sessions keep their attach-lifetime cancel intact. The previously flaky test now passes 50/50 under -race, and a full go test -race ./... reports zero data races.

…ssion/recallSession

Commit 064a464 made both RunSession and recallSession unconditionally
overwrite the cancel stored on an attached runtime with the per-stream
cancel, so DeleteSession was aborting the in-flight stream instead of
cancelling the attach context. That broke the graceful-delete contract
(DELETE ?wait=true must block until the stream ends naturally) and made
TestAttachedServer_DeleteWithWaitBlocksUntilStreamStops flaky under
-race. Guard both assignments with a done==nil check so only
server-owned runtimes track the per-stream cancel.

Assisted-By: Claude
@dgageot
dgageot requested a review from a team as a code owner July 8, 2026 08:54
@aheritier aheritier added area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Jul 8, 2026
@Sayt-0
Sayt-0 merged commit 3f68a00 into main Jul 8, 2026
14 checks passed
@Sayt-0
Sayt-0 deleted the worktree-board-e24afe8043392316 branch July 8, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions For features/issues/fixes related to session lifecycle (resume, persistence, export) kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants