Skip to content

fix(async-tasks): auto-wakeup notification not firing when parent session is idle #193

@randomm

Description

@randomm

Bug

When an async task completes, the parent session is NOT automatically woken up to deliver the result. The PM only discovers task completion when explicitly polling via check_task or list_tasks.

Observed Behavior

  1. PM dispatches task (async mode)
  2. Subagent completes in ~7s
  3. PM sits idle for 50+ seconds with no notification
  4. User asks 'did the agent finish?'
  5. PM calls check_task and discovers it completed

Expected Behavior

When subagent completes, parent session should receive an automatic notification injecting [System: Background tasks completed] into context, triggering the PM to respond.

Root Cause Analysis

enableAutoWakeup() in async-tasks.ts subscribes to BackgroundTaskEvent.Completed on the Bus. When the event fires, triggerWakeup() calls SessionPrompt.prompt() with empty parts — relying on getAndClearCompletedTasks() to inject the completed task notification.

Suspected causes:

  1. wakeupInProgress guard blocking re-entry if parent session was still processing
  2. hasUndeliveredCompletedTasks(sessionID) filtering by wrong sessionID (child vs parent)
  3. Race condition: task completes before enableAutoWakeup subscription is fully registered
  4. Bus pub/sub not crossing ACP session boundary correctly

Key Code

  • src/session/async-tasks.tsenableAutoWakeup(), triggerWakeup()
  • src/tool/task.ts — calls enableAutoWakeup(ctx.sessionID) before spawning task
  • Bus event published with parentSessionID = ctx.sessionID
  • Handler filters: event.properties.parentSessionID !== sessionID

Quality Gates

  • Reproduce with test
  • Fix root cause
  • Verify auto-notification fires reliably
  • No regression in sync mode

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions