Skip to content

Unhandled rejection: Agent listener invoked outside active run (background exec) #61592

@kagura-agent

Description

@kagura-agent

Bug

Gateway crashes with an unhandled promise rejection when a background exec process emits output after the agent run that spawned it has already completed.

Error

Unhandled promise rejection: Error: Agent listener invoked outside active run
    at Agent.processEvents (pi-agent-core/src/agent.ts:533:10)
    at pi-agent-core/src/agent.ts:380:21
    at Object.onUpdate (pi-agent-core/src/agent-loop.ts:539:7)
    at emitUpdate (exec-defaults-BjdtpCtu.js:1524:8)
    at handleStdout (exec-defaults-BjdtpCtu.js:1546:4)
    at Object.onSupervisorStdout (exec-defaults-BjdtpCtu.js:1610:3)

Reproduction

  1. Agent run starts a long-running background exec (e.g. curl ... | sudo sh to install software)
  2. Agent run completes and replies to user
  3. Background process continues emitting stdout (download progress)
  4. Stdout handler calls emitUpdateAgent.processEvents → throws because no active run

Expected behavior

Background exec output after the spawning run completes should either be silently buffered or ignored, not crash the gateway.

Impact

Gateway process exits, requiring manual restart. Any ongoing conversations and cron jobs are interrupted.

Environment

  • OpenClaw 2026.4.5, running from source on Linux
  • Triggered by exec tool with background: true and timeout: 300
  • Crash timestamp: 2026-04-06T09:10:54+08:00

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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