Repository navigation
Conversation
…s to a session release hasPendingBackgroundWork reported no work between a background task's task_notification and the first frame of the wake turn Claude opens for it, so an idle, linked-environment, or detach release could close the CLI mid-wake and lose the wake. A buffered notification that recorded a wake report now counts as pending until the wake run takes it. Fixes pingdotgg#37252
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Claude sessions now remain alive when a buffered task notification matches a recorded wake, preventing premature release before the wake turn starts. The change is narrowly scoped and retains existing idle-pin limits. You can add or adjust custom eligibility rules. Learn more. |
|
Thanks for this. #36029 makes the same change and is the one being kept. #36029 addresses the same session-release race using the adapter's existing owed-wake tracking. It also protects the interval after the roster empties but before the completion notification arrives, which makes it the more complete fix to keep. Your incident logs establish the impact of this race, and the notification-ordering and model-switch cases provide useful evidence for validating that fix. Closing as a duplicate. |
Problem
When a background Bash task finishes after the root turn has ended, the Claude CLI emits
task_notificationandbackground_tasks_changed [], then opens its own wake turn. Until that turn's first frame arrives,hasPendingBackgroundWorkreports no work: the internal roster is already empty, and the wake buffer holds only the notification, which the probe does not count. Any session release in that window (idle release, a linked-environment change on open, or a detach) closes the CLI mid-wake. The wake is lost, and the thread stays silent until the user sends another message.Seen in the field: the notification arrived at 02:12:27.305Z,
query.closewent out at 02:12:27.316Z, and the CLI's wake request was still in flight. The thread then sat silent for 13 hours. Details are in #37252.Change
hasPendingBackgroundWorkalso counts a bufferedtask_notificationwhose task recorded a wake report, until the wake run takes the buffer. Only wake-eligible notifications get a report. Nested subagent notifications, which never wake the root, still don't count.Model and policy switches read
hasPendingBackgroundWorkForThread/liveProcessRunsBackgroundWork, which are unchanged, so a switch during that window is still allowed and still carries the buffered notification into the new process.Scope
A reliability bug fix in the Claude adapter. Fixes #37252.
Verification
ClaudeAdapterV2.test.ts:local_bashtask, root settled, notification plus an emptybackground_tasks_changed, in each order) now assert that the session-wide probe holds right after the notification, and that it clears once the wake run finishes.ClaudeAdapterV2.test.ts, and 71/71 inProviderSessionManager.test.ts.vp run check:changedpasses: format, lint, knip, typecheck, and the tests beside the change.Runtime transcript from the incident (provider event log):
Model: Claude Opus 5.5, harness: Claude Code.
🤖 Generated with Claude Code