Skip to content

Session context lost after agent run timeout — background exec results injected into new session without history #20436

@4ier

Description

@4ier

Summary

When an agent run times out (embedded run timeout, default 600s), background exec processes continue running independently. When those exec processes later complete, their results are injected as System: messages into a new session that has zero context from the previous session. If the user then sends a message (e.g. "continue"), the agent has no idea what was being worked on and may start an entirely unrelated task.

Reproduction Steps

  1. Start a task that involves long-running background exec commands (e.g. npm install in a slow environment, CI pipeline polling)
  2. The agent run hits the 600s timeout → run is killed
  3. Background exec processes keep running (they are independent OS processes)
  4. Wait for exec to complete (could be minutes to hours later)
  5. User sends a message in the same topic/chat (e.g. "continue")
  6. A new session is created for that topic
  7. The accumulated System: Exec completed/failed messages + the user message are bundled into a single first user message in the new session

What Happens

The new session receives something like:

System: [01:51] Exec completed (session-a, code 0) :: apt done configure done
System: [01:57] Exec completed (session-b, code 0) :: 1min
System: [01:59] Exec failed (session-c, signal SIGKILL) :: proot warning...

[User]: continue

The agent has no prior conversation context. It:

  1. Sees cryptic exec output snippets with no semantic meaning
  2. Interprets "continue" by searching memory files
  3. Finds the most prominent recent TODO in memory (which may belong to a different topic/session)
  4. Starts working on the wrong task in the wrong topic

Root Causes

  1. Agent run timeout kills the run but not background exec processes — This creates orphaned exec results that arrive later with no consumer context
  2. Session rotation drops all conversation history — The new session has zero knowledge of what the old session was doing
  3. Accumulated System messages are batched with user messages — The signal-to-noise ratio is very low; the agent cannot distinguish which exec results are relevant
  4. No per-topic/per-session state persistence — There is no mechanism to carry forward "this session was working on task X" across session boundaries

Observed Impact

  • Agent started working on Project A in a topic that was dedicated to Project B
  • Cross-topic contamination: work intended for one topic bled into another
  • User had to re-explain context that was already established in the previous session
  • Wasted tokens and time on duplicate/wrong work

Suggested Improvements

  1. Carry forward session summary on rotation — When a session times out and a new one is created for the same topic, inject a compact summary of the previous session's last N messages as context
  2. Kill or re-parent orphaned exec processes — When an agent run times out, either kill associated exec processes or tag their results with the original session context
  3. Separate System exec results from user messages — Don't batch them into a single user turn; deliver them as distinct system events that the agent can triage
  4. Per-topic persistent state — Allow sessions to write a small state blob (e.g. "current task", "last working context") that survives session rotation

Environment

  • OpenClaw latest (npm)
  • Telegram channel with topic-based group chat
  • Agent run timeout: 600000ms (default)
  • Multiple background exec processes running concurrently

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions