Skip to content

[Bug]: sessions_yield subagent wake can compact parent branch at low context usage #86684

Description

@Thinkscape

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

A parent session parked with sessions_yield was compacted during subagent completion/direct-announce handling despite being around 65k/1.05M context, with the compaction parented to hidden openclaw.sessions_yield entries rather than the visible branch.

This triggers excessive compactions, loss of relevant information on the main session (spawning subagents), and excessive API costs.

Steps to reproduce

Observed reproduction path:

  1. Run OpenClaw 2026.5.22 with agents.defaults.compaction.mode: "safeguard".
  2. Use a parent/main session on openai-codex/gpt-5.4 with effective context window 1050000.
  3. In the parent session, spawn subagents with sessions_spawn.
  4. Have the parent call sessions_yield while waiting for subagent completion.
  5. Let a subagent complete and have OpenClaw attempt completion direct-announce / parent wake-up.
  6. Observe that the parent transcript receives a compaction entry parented to the hidden openclaw.sessions_yield custom message even though visible context usage is far below the configured window.

Expected behavior

A subagent completion/direct-announce wake-up should resume, notify, or append to the parent session without compacting the parent branch unless the parent is genuinely near context overflow or the user
explicitly requested compaction.

This regression started happening some time between .5.10 and .5.22

Actual behavior

The parent session compacted while far below the configured context window. The compaction entry 9386dd5e was created at 2026-05-25T02:59:25.241Z, parented to hidden custom_message 2355e2ea of type
openclaw.sessions_yield, with tokensBefore: 65320 and fromHook: true.

A visible /status reply on a sibling branch shortly before this showed Context: 63k/1.1m (6%). The compaction was therefore not caused by visible branch context exhaustion.

OpenClaw version

2026.5.22, gitSha ef17290

Operating system

Linux 6.8.0-107-generic x64 inside Docker; host is Ubuntu 24.04

Install method

Docker / docker compose

Model

openai-codex/gpt-5.4

Provider / routing chain

OpenClaw embedded Pi runtime -> openai-codex provider -> openai-codex-responses API via OAuth profile

Additional provider/model setup details

Relevant live config/effective model details:

  • agents.defaults.compaction: { "mode": "safeguard" }
  • No global agents.defaults.contextTokens override was set.
  • openai-codex/gpt-5.4 resolves to:
    • contextWindow: 1050000
    • contextTokens: 1050000
    • maxTokens: 128000
  • The selected session model at the time was openai-codex/gpt-5.4.

Logs, screenshots, and evidence

Session key:
   agent:cassian-vale:discord:channel:1505134791992017047

   Session id/file:
   22a471aa-ada5-424a-aeed-2ed3774edeaf
   /home/node/.openclaw/agents/cassian-vale/sessions/22a471aa-ada5-424a-aeed-2ed3774edeaf.jsonl

   Relevant transcript entries:

   2026-05-25T02:50:38.542Z
   id=2355e2ea
   type=custom_message
   customType=openclaw.sessions_yield
   parent=26daf018

   2026-05-25T02:54:36.433Z
   id=12d95196-c43f-4844-8e5d-066fb384d79e
   type=message
   role=assistant
   parent=2355e2ea
   provider=openclaw
   model=gateway-injected
   visible status included:
   Context: 63k/1.1m (6%)

   2026-05-25T02:59:25.241Z
   id=9386dd5e
   type=compaction
   parent=2355e2ea
   firstKeptEntryId=bd581ef0
   tokensBefore=65320
   fromHook=true
   details={"readFiles":[],"modifiedFiles":[]}

   Earlier same yielded-session pattern:

   2026-05-25T02:41:03.689Z
   id=307e723f
   type=custom_message
   customType=openclaw.sessions_yield

   2026-05-25T02:46:34.716Z
   id=18f9eadb
   type=compaction
   parent=307e723f
   firstKeptEntryId=12e34dba
   tokensBefore=115283
   fromHook=true

   Gateway log correlation:

   2026-05-25T12:49:31.309+10:00 [ws] ⇄ res ✓ agent.wait 525686ms ...
   2026-05-25T12:49:32.878+10:00 Done. Artifacts created: ...
   2026-05-25T12:50:49.450+10:00 [compaction-safeguard] Compaction safeguard: using session branch messages after compaction preparation omitted real conversation content.
   2026-05-25T12:51:33.124+10:00 [warn] Subagent completion direct announce failed for run cde2b626-62d2-4f92-a391-5cda394af32f: gateway request timeout for agent

   Related lock evidence from same session window:

   2026-05-25T12:42:51.044+10:00 [agent/embedded] embedded run agent end: runId=announce:v1:agent:cassian-vale:subagent:6219020e-e36a-414f-bd0a-0dc273514e61:7fa82631-db86-42f3-8b55-a53165cc3a66 isError=true
 model=gpt-5.4 provider=openai-codex error=LLM request timed out. rawError=session file locked (timeout 60000ms): pid=8
 /home/node/.openclaw/agents/cassian-vale/sessions/22a471aa-ada5-424a-aeed-2ed3774edeaf.jsonl.lock

   Checkpoint evidence:

   A retained pre-compaction checkpoint exists for the second compaction:
   22a471aa-ada5-424a-aeed-2ed3774edeaf.checkpoint.aa66c107-fd92-4108-a024-4e2cbc0b4315.jsonl

   Its last pre-compaction leaf was:
   2355e2ea custom_message openclaw.sessions_yield

   This confirms the compaction boundary was the hidden yielded-session branch, not the visible `/status` branch.

Impact and severity

Affected: At least one observed long-running Discord parent session using subagents and sessions_yield.

Severity: High for subagent-heavy workflows. The parent/main branch can lose exact history unexpectedly even when visible context usage is low.

Frequency: Observed twice in the same session window: compaction 18f9eadb and compaction 9386dd5e, both parented to hidden openclaw.sessions_yield custom messages. Not yet minimized into a
deterministic standalone repro.

Consequence: Parent session history is compacted earlier than expected, making it harder to audit exact orchestration decisions and confusing users because /status reports low context usage while
background wake-up handling still compacts the parent branch.

Additional information

fromHook: true appears to indicate that the compaction safeguard hook supplied the summary. It does not identify the caller/trigger that decided compaction should happen.

No exact duplicate found. Related issues/PRs found during issue search:

Requested behavior/policy:

  • Subagent completion/direct-announce wake-up should not compact the requester/parent branch unless there is a real context-overflow condition or explicit user/manual compaction.
  • If compaction is unavoidable, persist trigger metadata on the compaction entry, e.g. trigger=direct_announce, trigger=sessions_yield_wake, trigger=overflow, trigger=manual, so future triage can
    distinguish summary source (fromHook) from compaction cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.regressionBehavior that previously worked and now fails

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions