fix: defer early session.idle instead of dropping it (#1517)#1537
Open
code-yeongyu wants to merge 1 commit intodevfrom
Open
fix: defer early session.idle instead of dropping it (#1517)#1537code-yeongyu wants to merge 1 commit intodevfrom
code-yeongyu wants to merge 1 commit intodevfrom
Conversation
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.
Summary
Fixes #1517 — Background tasks launched via
delegate_task(run_in_background=true)permanently hang when the agent responds in under 5 seconds.Root Cause
The
session.idlehandler inBackgroundManagerhas a guard that rejects idle events that fire withinMIN_IDLE_TIME_MS(5s) of task start. Sincesession.idleis edge-triggered (fires once, not periodically), dropping the early event means it never fires again → task stuck forever.Fix
Instead of dropping the early idle event, defer it using
setTimeout(remainingMs). When the deferred timer fires, it re-checks whether the task is still running before proceeding with completion validation. This preserves the original intent (don't complete prematurely) while not losing the idle signal.Changes
src/features/background-agent/manager.ts: Replace early idlereturnwithsetTimeoutdeferral + cleanup logicsrc/features/background-agent/manager.test.ts: Add TDD tests for early idle deferral behaviorTesting
bun run typecheckpassesbun run buildpassesSummary by cubic
Prevents background tasks from hanging when session.idle fires within 5s by deferring the event instead of dropping it. Keeps the minimum idle window while ensuring the idle signal is not lost.
Written for commit 796bf79. Summary will update on new commits.