Skip to content

fix(chat): clear pendingToolUseID in EndSession to prevent reaper leak - #142

Merged
mhersson merged 1 commit into
mainfrom
ctxmax-626/follow-up-endsession-reaper-path-leaks-pendingtool
May 23, 2026
Merged

fix(chat): clear pendingToolUseID in EndSession to prevent reaper leak#142
mhersson merged 1 commit into
mainfrom
ctxmax-626/follow-up-endsession-reaper-path-leaks-pendingtool

Conversation

@contextmatrix-runner

Copy link
Copy Markdown
Contributor

Summary

Fixes the pendingToolUseID map leak in EndSession — the reaper-eviction path mirror of the DeleteSession leak fixed previously.

  • Adds delete(m.pendingToolUseID, id) under m.mu guard in EndSession, symmetric with the existing cleanup in DeleteSession
  • A session TTL-evicted by the reaper retained its stale tool_use_id; on openCold, SendUserMessage would forward the ID referencing a tool_use block that no longer exists in the new container
  • Adds TestManager_EndSession_ClearsPendingToolUseID regression test mirroring TestManager_DeleteSession_ClearsPendingToolUseID
  • Two follow-up cards spawned for Minor findings: CTXMAX-635 (StatusCold early-return path) and CTXMAX-636 (test comment precision)

Test plan

  • go test ./internal/chat/... — all chat package tests pass (verified)
  • TestManager_EndSession_ClearsPendingToolUseID — new regression test passes

- Add `delete(m.pendingToolUseID, id)` under `m.mu` guard in `EndSession`,
  mirroring the identical cleanup already performed by `DeleteSession`
- Fixes the defect where a session TTL-evicted by the reaper retained its
  stale `tool_use_id` in the map; on next `openCold`, `SendUserMessage`
  would forward the ID to a container that no longer has the matching
  `tool_use` block
- Add regression test `TestManager_EndSession_ClearsPendingToolUseID`
  mirroring `TestManager_DeleteSession_ClearsPendingToolUseID`
@mhersson
mhersson merged commit 1d8be0e into main May 23, 2026
7 checks passed
@mhersson
mhersson deleted the ctxmax-626/follow-up-endsession-reaper-path-leaks-pendingtool branch May 23, 2026 17:35
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