Skip to content

[Bug]: Background exec completion notifications can interrupt active agent turn #8997

@svenssonaxel

Description

@svenssonaxel

This report is completely AI generated.

Summary

When tools.exec.notifyOnExit is enabled (the default), completion notifications for backgrounded exec sessions are delivered as system messages immediately upon process exit. If an agent turn is actively in progress (streaming a response, making tool calls, etc.), this notification can interrupt the flow, causing the agent to context-switch or respond to the notification rather than completing its current task.

Environment

  • OpenClaw version: 2026.2.1
  • Node.js version: v22.22.0
  • OS: Linux 6.1.0-42-amd64 (Debian, x64)
  • Channel: webchat (also observed in Telegram)
  • Config: Default tools.exec.notifyOnExit: true

Steps to Reproduce

  1. Start a conversation with the agent in webchat or Telegram
  2. Have the agent run a backgrounded exec command (e.g., a long-running process using yieldMs or background: true)
  3. While the background process is running, continue chatting with the agent about a different topic
  4. When the background process exits, observe the notification arriving

Expected Behavior

Exec completion notifications should either:

  • Be queued until the current agent turn completes
  • Be batched with other pending notifications
  • At minimum, not interrupt an actively streaming response

Actual Behavior

Notifications arrive as system messages immediately when the process exits, regardless of whether the agent is mid-turn. Example observed sequence:

[12:01:30] User: Can you explain how the calendar script works?
[12:01:31] Agent: Sure! The calendar script uses khal via nix-shell to...
[12:01:32] System: [2026-02-04 12:01:32 EST] Exec completed (salty-wh, code 0) :: chromium --version
[12:01:33] Agent: ...I see a background task completed. Anyway, as I was saying about the calendar...

The agent acknowledges the notification mid-explanation, breaking the flow.

Impact

  • Conversation coherence: Agent may lose track of what it was explaining
  • User confusion: Sudden topic switches feel jarring
  • Token waste: Agent spends tokens acknowledging routine notifications
  • Compounding effect: Multiple rapid notifications (e.g., several background tasks finishing) can derail a turn entirely

Related Issues

Suggested Solutions

  1. Queue notifications: Hold notifyOnExit messages until the current turn completes, then deliver them before the next user message
  2. Batch notifications: If multiple background tasks complete in quick succession, combine them into a single notification
  3. Config option: Add tools.exec.notifyTiming: "immediate" | "queued" | "batched" to let users choose behavior
  4. Silent mode: Add tools.exec.notifySilent: true option that logs completions without injecting system messages

Workaround

Set tools.exec.notifyOnExit: false in config, but this loses visibility into background task completion entirely.

Additional Context

This issue was observed during a session where multiple web searches and file operations were running in background. Each completion notification would briefly distract the agent from its current explanation.


This issue was drafted with AI assistance (Claude/OpenClaw). The bug was observed directly during normal usage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions