Repository navigation
Conversation
…ding A turn that ends while subagents or background shells are still running is a pause, not a session end. The done push should land when the turn that wakes on task completion finishes, not on every intermediate result. Track live background work from the SDK's background_tasks_changed system messages — each payload is a full replacement set, and ambient tasks (CLI housekeeping) are excluded. The launcher holds the done notification while non-ambient tasks are in flight. Fail-open for wire messages from older CLI builds, and the /clear and failed paths are unchanged. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
Author
|
Closing as this approach is no longer needed on our side — we are going with a client-agnostic Claude Code hook instead. Thanks for maintaining happy! |
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.
Problem
When a Claude turn dispatches subagents (or background shells), the CLI emits an SDK result for the turn while that background work is still running.
claudeRemoteLaunchertreats every result as a session end and fires thedonesession notification — so a single user-visible task produces one mobile push per subagent completion, and the last push can arrive before the final answer is even composed.Fix
Track live background work at the
claudeRemotelevel from the SDK'sbackground_tasks_changedsystem messages (type: 'system',subtype: 'background_tasks_changed'):ambient: trueare CLI housekeeping and do not count as user-visible work.onReady(status, hasPendingBackgroundTasks); the launcher holds thedonepush whilestatus !== 'failed' && !pending && queue empty && hasPendingBackgroundTasks.The turn that wakes on task completion sends the real final push, so behavior for ordinary turns is unchanged.
Compatibility
message.tasks?.some(...) ?? false, so wire messages from older CLI builds (notasksfield) behave exactly as before./clearearly-return path callsonReady()with no args → push behavior unchanged.failedturns still notify immediately (thestatus !== 'failed'check short-circuits first).claudeRemoteinvocation, so it resets to empty on every CLI process (re)start — matching the SDK's per-process level semantics.Tests
pnpm exec vitest run --project unit— 2 touched test files, 17 tests passing (rebased on currentmain):claudeRemote.test.ts(12): flag true while tasks in flight · replacement set empties the flag · ambient-only ignored · ambient coexisting with real work keeps the flag · flag persists across two results (multi-turn).claudeRemoteLauncher.test.ts: holds thedonepush while pending and sends it once tasks drain;closeClaudeSessionTurnstill called with'completed'.review: L2 fresh-context reviewer + real-data verification subagent passed (no BLOCKER/MAJOR; 4 findings applied: launcher-side gating test, multi-turn persistence test, optional-chain fail-open guard, ambient-mix test)
todo: none — task tracking for this change lives in the author's separate ~/.claude setup repository, outside this upstream contribution
🤖 Generated with Claude Code