Skip to content

[Bug]: Auto-compaction silently fails after context overflow (attempt 1/3 with no follow-up) #90526

Description

@paris1231

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

After accumulating ~217 messages during a tool loop, the embedded agent emits [context-overflow-diag] with compactionAttempts=0 and logs "attempt 1/3; attempting auto-compaction", but never proceeds to attempt 2/3 or 3/3. No compaction completed/failed signal is emitted. The prompt silently returns stopReason=end_turn as if it succeeded.

Steps to reproduce

  1. Configure OpenClaw with a model provider (tested with bailian/qwen3.7-max)
  2. Start a session and issue a prompt that triggers a long tool loop (e.g., repeated CLI/API calls against a failing endpoint that keeps producing error outputs)
  3. Let the tool loop run until messages accumulate to ~200+ entries (took ~12 minutes in our case)
  4. Observe stderr for [context-overflow-diag] output
  5. Check whether attempt 2/3 or compaction completed/failed appears in stderr after attempt 1/3

Expected behavior

After "attempt 1/3; attempting auto-compaction" is logged, the agent should either:
(a) Proceed to attempt 2/3 and 3/3 if the first compaction attempt fails, OR
(b) Emit a clear "compaction completed" or "compaction failed" signal.
If all 3 attempts fail, the prompt should return stopReason="error" (not "end_turn") so the caller knows the session is no longer usable.

Actual behavior

Only "attempt 1/3" is logged. No "attempt 2/3", no "attempt 3/3", no "completed", no "failed" signal ever appears in stderr. The agent silently returns stopReason=end_turn (appears as success). Subsequent prompts to the same session produce degraded sentinel outputs (NO_REPLY, HEARTBEAT_OK) instead of meaningful responses.

OpenClaw version

2026.3.13

Operating system

Linux (Alibaba Cloud Function Compute container)

Install method

docker

Model

bailian/qwen3.7-max

Provider / routing chain

openclaw -> bailian (Alibaba Cloud Model Studio) -> qwen3.7-max

Additional provider/model setup details

Compaction mode is set to "safeguard" in openclaw.json (agents.defaults.compaction.mode).
tools.deny includes ["sessions_spawn", "subagents"].

Logs, screenshots, and evidence

**stderr output (redacted):**


[agent/embedded] [context-overflow-diag]
  sessionKey=agent:main:proxy:XXXXXXXX
  provider=bailian/qwen3.7-max
  source=assistantError
  messages=217
  sessionFile=/root/.openclaw/agents/main/sessions/XXXXXXXX.jsonl
  diagId=ovf-XXXXXXXX
  compactionAttempts=0
  observedTokens=unknown
  error=Context overflow: estimated context size exceeds safe threshold during tool loop.

[agent/embedded] context overflow detected (attempt 1/3); attempting auto-compaction for bailian/qwen3.7-max


**Grepped full session log (~500 lines) for follow-up — 0 hits:**
- `attempt 2/3` — not found
- `attempt 3/3` — not found
- `compaction completed` — not found
- `compaction failed` — not found

**Degraded output after silent failure (subsequent prompts to same session):**
- First retry: agent responded with "...\n\nNO_REPLY"
- Second retry: agent responded with only "HEARTBEAT_OK"

Impact and severity

Affected: Any user whose session accumulates enough messages to trigger context overflow during a tool loop
Severity: High (silent failure — caller receives end_turn "success" but session is permanently degraded)
Frequency: 1/1 observed in production when messages reached 217
Consequence: No error is surfaced to the user or ACP caller; session silently becomes unusable

Additional information

No response

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.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.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.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions