Skip to content

[Bug]: Background task completion reminder does not wake parent assistant #5147

Closed

Description

@yansongda

Prerequisites

  • I will write this issue in English (see the Language Policy)
  • I have searched existing issues to avoid duplicates
  • I am using the latest version of oh-my-openagent
  • I have read the documentation or asked an AI coding agent with this project's GitHub URL loaded and couldn't find the answer

Bug Description

When background tasks complete, oh-my-openagent injects a final system reminder into the parent session:

<system-reminder>
[BACKGROUND TASK COMPLETED]
[ALL BACKGROUND TASKS COMPLETE]

**Completed:**
- `bg_xxx`: ...
- `bg_yyy`: ...

Use `background_output(task_id="<id>")` to retrieve each result.
</system-reminder>
<!-- OMO_INTERNAL_INITIATOR -->

This final notification should wake the parent assistant so it can call background_output(...) and continue the workflow.

Instead, the notification appears in the session, but the assistant does not continue until a real user message is sent manually.

Steps to Reproduce

  1. Start a parent OpenCode session with oh-my-openagent enabled.

  2. Launch two background tasks from the assistant.

  3. End the assistant turn and wait for background completion.

  4. Runtime injects the final completion reminder:

    <system-reminder>
    [BACKGROUND TASK COMPLETED]
    [ALL BACKGROUND TASKS COMPLETE]
    ...
    </system-reminder>
    <!-- OMO_INTERNAL_INITIATOR -->
  5. Observe that the parent assistant does not respond automatically.

  6. Send any real user message.

  7. The assistant is then awakened and can retrieve background outputs.

Expected Behavior

After [ALL BACKGROUND TASKS COMPLETE] is injected, the parent assistant should automatically receive a turn and continue, typically by calling:

background_output(task_id="bg_xxx")
background_output(task_id="bg_yyy")

The background-agent workflow should not require the user to send another message after the final system reminder.

Actual Behavior

The final background completion system reminder is written into the session, but no assistant turn follows.

In reproduced sessions, the message history ended with:

<system-reminder>
[BACKGROUND TASK COMPLETED]
[ALL BACKGROUND TASKS COMPLETE]
...
</system-reminder>
<!-- OMO_INTERNAL_INITIATOR -->

There was no assistant response after this runtime-injected message. The assistant only continued after a real user message was sent.

Evidence from reproduced sessions:

  • The messages were stored as role: "user".
  • They included <system-reminder>...</system-reminder>.
  • They included <!-- OMO_INTERNAL_INITIATOR -->.
  • The task IDs matched real background task IDs.
  • No assistant message appeared after the final all-complete notification.

The same behavior was reproduced in an active session: background tasks completed, the final [ALL BACKGROUND TASKS COMPLETE] notification appeared, but the assistant did not automatically continue until the user sent another message.

Doctor Output

Resolving dependencies
Resolved, downloaded and extracted [341]
Saved lockfile

Doctor failed unexpectedly: ResolveMessage: Cannot find module 'oh-my-opencode/package.json' from '/private/var/folders/r5/xdvc0dcn4vq2dzqg08hst7q80000gn/T/bunx-501-oh-my-openagent@latest/node_modules/oh-my-openagent/dist/cli/index.js'
This may indicate memory pressure (OOM/SIGKILL) or a corrupted installation.
Try: OMO_DISABLE_POSTHOG=1 bunx oh-my-opencode doctor --verbose

Error Logs

No thrown runtime error was shown in the UI. The observable failure is that the parent assistant is not awakened after the final completion reminder.

Relevant suspected flow:

background task completes
→ notifyParentSession()
→ queuePendingParentWake()
→ flushPendingParentWake()
→ sendParentWakePrompt()
→ dispatchInternalPrompt()
→ dispatchAfterSessionIdle()
→ promptAsync()
→ assistant should reply, but does not

For final completion notifications, the code appears to set:

shouldReply = allComplete || isTaskFailure

So [ALL BACKGROUND TASKS COMPLETE] should require a reply.

However, before dispatching the parent wake, dispatchAfterSessionIdle() checks whether the latest assistant turn blocks internal prompts, via logic equivalent to:

latestAssistantTurnBlocksInternalPrompt(messages)

The problematic logic appears to be:

if (role === "user") {
  if (messageIsSyntheticOrInternalUser(message)) {
    if (!sawAssistantAfterLatestUser) {
      return true;
    }
    continue;
  }

  return false;
}

The final completion notification is itself an internal/synthetic user message because it contains:

<!-- OMO_INTERNAL_INITIATOR -->

So after the final notification is injected:

  1. The latest message is a synthetic/internal user message.
  2. There is no assistant message after it yet.
  3. latestAssistantTurnBlocksInternalPrompt() returns true.
  4. dispatchAfterSessionIdle() treats the session as blocked/active.
  5. The parent wake does not produce an assistant reply.
  6. The assistant never calls background_output(...).

This looks like a self-blocking loop: the completion notification that should wake the assistant becomes the reason the wake is blocked.

Configuration

{}

No special per-project oh-my-openagent configuration is required to reproduce this. The issue was observed with the normal background task workflow.

Additional Context

Why this appears to be a bug:

[ALL BACKGROUND TASKS COMPLETE] is an actionable runtime notification. It should not be treated the same way as an arbitrary internal user message that blocks additional internal prompts.

The notification explicitly tells the assistant what to do:

Use background_output(task_id="<id>") to retrieve each result.

But the assistant never gets a turn to do it.

Possible fixes:

Option A: Special-case final background completion reminders

If the latest synthetic/internal user message is a final background completion notification, do not let it block parent wake dispatch.

For example, detect headers like:

[ALL BACKGROUND TASKS COMPLETE]
[ALL BACKGROUND TASKS FINISHED - N FAILED]

and allow the wake.

Option B: Bypass latestAssistantTurnBlocksInternalPrompt() for shouldReply=true parent wakes

If a parent wake has shouldReply=true, especially for final completion or failure notifications, avoid treating the just-injected internal reminder as a blocker.

Option C: Dispatch the wake before writing the notification as a blocking internal user message

Avoid a state where the notification becomes the latest synthetic user message before the wake prompt is dispatched.

Suggested regression test:

[user] original request
[assistant] launches background tasks and stops
[user/internal] <system-reminder>[BACKGROUND TASK COMPLETED][ALL BACKGROUND TASKS COMPLETE]...</system-reminder><!-- OMO_INTERNAL_INITIATOR -->

Expected result:

assistant turn is dispatched
assistant can call background_output(...)

This currently breaks the documented background-agent workflow:

  • Agents are told to stop and wait for <system-reminder>.
  • Runtime injects the reminder.
  • But the assistant is not woken up to collect results.

As a result, workflows depending on background agents stall until the user manually sends another message.

Operating System

macOS

OpenCode Version

1.17.2

Activity

  1. changed the title [-]Background task completion reminder does not wake parent assistant[/-] [+][Bug]: Background task completion reminder does not wake parent assistant[/+] on Jun 10, 2026
  2. vboufleur commented on Jun 10, 2026

    @vboufleur

    Great analysis here. I also investigated this bug and can confirm your findings. latestAssistantTurnBlocksInternalPrompt() indeed blocks the wake dispatch by treating the synthetic notification message as a blocker.

    The Permanent Deadlock Path

    My investigation tracked the complete state machine through the flush runner, showing this is a permanent infinite loop rather than a temporary block:

    1. Two-phase dispatch: The flush runner fires an initial admit-only dispatch (noReply: true) when there's recent activity, creating the synthetic user message but no assistant response.
    2. Activity window self-refresh: This dispatch fires a message.updated event, calling recordParentSessionActivity() at manager.ts:1584. Since this function doesn't filter out internal messages, it refreshes the 5-second activity window. This traps subsequent flushes in the "recent activity" path.
    3. The safety catch: Once noReplyAdmittedAt is set, later flushes detecting shouldReply && noReplyAdmittedAt !== undefined constantly reschedule themselves without dispatching.
    4. No stale-tool escape: When the activity window finally expires, the stale-tool escape doesn't help because latestAssistantTurnHasToolBlock(messages) is false once the agent finishes normally.
    5. Infinite loop: The deferral decision permanently returns { defer: true }, causing deferReplyWakeWhileUnsafe to reschedule forever. The wake never dispatches with noReply: false.

    Proposed Escape Hatch Fix

    Instead of the proposed options in the issue, I added a targeted escape hatch inside getParentWakeSessionHistoryDeferralDecision in parent-wake-session-history.ts:

    if (
      now - input.wake.toolCallDeferralStartedAt >= input.toolCallDeferMaxMs
      && !latestAssistantTurnHasToolBlock(messages)
      && input.wake.noReplyAdmittedAt !== undefined
    ) {
      delete input.wake.toolCallDeferralStartedAt
      log("[background-agent] Retrying parent wake after retained no-reply admission deferral timeout:", { sessionID: input.sessionID })
      return { defer: false, skipPromptGateToolStateCheck: true }
    }

    This is safer and more precise than the alternatives:

    • Avoids parsing notification content (safer than Option A).
    • Gates strictly on noReplyAdmittedAt, isolating the exact deadlock scenario (safer than Option B).
    • Prevents broad architectural changes (simpler than Option C).
    • Recovers in ~10 seconds (5s activity window + 5s deferral timeout) rather than looping infinitely.

    Testing

    I implemented this fix and added three regression tests covering:

    • Positive path where the escape hatch fires.
    • Negative path with no noReplyAdmittedAt to ensure it still defers.
    • Tool-block scenario verifying the existing stale-tool escape still handles standard blocks.

    Verified

    To confirm the fix in a production-like environment, I built the package locally and pointed OpenCode's configuration to this build. During a live session, the main agent successfully launched background agents and resumed right after they completed. This verified that the deadlock is fully resolved under real-world conditions.

    I'm opening a PR with the changes.

  3. vboufleur commented on Jun 10, 2026

    @vboufleur

    Here's the PR: #5148

    @code-yeongyu Ping

  4. zsj0613 commented on Jun 11, 2026

    @zsj0613

    this is very Annoying, please fix it quick

  5. airnayden commented on Jun 11, 2026

    @airnayden

    Can confirm the issue as well.

  6. cpt-sd76vg commented on Jun 11, 2026

    @cpt-sd76vg
    Contributor

    I’m really hoping PR #5148 gets merged soon....

    At the moment, Sisyphus gets stuck without picking up the results from parallel agents, which makes it very hard to use in practice.

  7. vboufleur commented on Jun 11, 2026

    @vboufleur

    While we wait for #5148 to be merged, you can apply the fix locally by pointing OpenCode at my fork's branch. This is what I did on my machine and it fully resolves the deadlock.

    1. Clone the fork and check out the fix branch:

    git clone https://github.com/vboufleur/oh-my-openagent.git /tmp/omo-fix
    cd /tmp/omo-fix
    git checkout fix/parent-wake-noreply-admission-deadlock

    2. Install deps and build:

    bun install
    bun run build

    This produces dist/index.js at the repo root.

    3. Point OpenCode at the local build. Edit ~/.config/opencode/opencode.json and replace the published plugin entry with a file:// path to the cloned repo:

    "plugin": [
      // before: "[email protected]"
      "file:///tmp/omo-fix"
    ]

    (Keep any other plugins you already have in that array.)

    4. Restart OpenCode.

    Verify: Start a session, have the assistant launch 2 background agents, then end the turn and wait. Once the tasks complete and the [ALL BACKGROUND TASKS COMPLETE] reminder appears, the assistant should automatically resume (~10s later) and call background_output(...) on its own — no manual user message needed.

    If you'd rather not build from source, you can also wait for #5148 this is just a stopgap to unblock the background-agent workflow in the meantime.


    Note: I used /tmp/omo-fix as an example path — adjust to wherever you cloned it, and make sure the file:// path in the config matches. The fix is a targeted escape hatch in parent-wake-session-history.ts (plus 3 regression tests), so the build is the standard package build with no extra steps.

  8. cpt-sd76vg commented on Jun 11, 2026

    @cpt-sd76vg
    Contributor

    @vboufleur

    Thanks for sharing the workaround. I was able to get it working with a couple of additional steps in my environment.

    In addition to the steps you described, I temporarily disabled only this entry in tui.jsonc:

    "plugin": [ "oh-my-openagent/tui" ]

    I left my other plugin entries unchanged.

    Also, some of the LSP-related tools were not working at first, so I changed the build steps to:

    bun install
    bun run build:lsp-tools-mcp
    bun run build:lsp-daemon
    bun run build

    With those steps, everything started working properly.

    I briefly tested it with Sisyphus, and for the first time in a while it actually picked up the sub-agent results and continued correctly. Thank you so much for the fix and the clear instructions!


    Also, I know @code-yeongyu must be very busy, but I’m looking forward to the official optimization/merge when possible.

  9. added a commit that references this issue on Jun 11, 2026
    1f6d0e4
  10. acamq commented on Jun 11, 2026

    @acamq
    Contributor

    Hello everyone! Thank you for your patience, fix has been merged and will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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