Skip to content

Gateway becomes completely unresponsive after compaction triggers #76467

Closed as not planned

Description

@njuboy11

Bug Report: Gateway becomes completely unresponsive after compaction triggers

Issue Description

After a compaction event fires on the main session, the Gateway stops responding to all messages (webchat). Messages are sent but receive no reply. Gateway restart is required to recover.

Environment:

  • Platform: Ubuntu (VM on Tencent Cloud)
  • OpenClaw version: v2026.5.2
  • Node version: v24.14.1
  • Memory: 3.7GB total
  • Webchat channel (direct conversation, not Feishu)

Compaction config:

"compaction": {
  "truncateAfterCompaction": true,
  "maxActiveTranscriptBytes": "10mb"
}

Steps to Reproduce

  1. Main session runs for an extended period with significant conversation history
  2. Compaction triggers (context overflow or byte threshold reached)
  3. User sends a message via webchat after the system prompt about compaction appears
  4. Gateway becomes completely unresponsive — no reply, no error, no feedback
  5. Only Gateway restart (systemctl --user restart openclaw-gateway) restores functionality

Actual Behavior

After compaction triggers:

  • Compaction itself completes successfully (seen in logs: [compaction] rotated active transcript after compaction in ~30 seconds)
  • But subsequent messages get no response
  • Session shows state=processing queueDepth=1 reason=queued_behind_active_work for extended periods
  • Log shows agent cleanup timed out events
  • Liveness warnings show high eventLoopDelayMaxMs values (up to 3454ms)
  • WebSocket connections (sessions.list, chat.history) continue to work for other sessions but main session is stuck

Expected Behavior

Messages sent during/after compaction should either:

  • Be processed after compaction completes, or
  • Return an error message indicating the session is busy with compaction

Log Evidence

# Stuck session during compaction window
12:36:04 long-running session: sessionId=main sessionKey=agent:main:main state=processing age=125s queueDepth=1 reason=queued_behind_active_work classification=long_running
12:36:34 long-running session: sessionId=main sessionKey=agent:main:main state=processing age=155s queueDepth=1 reason=queued_behind_active_work
12:37:21 [compaction] rotated active transcript after compaction (sessionKey=agent:main:main)
12:39:37 long-running session: sessionId=main sessionKey=agent:main:main state=processing age=135s queueDepth=0 reason=active_work classification=long_running

# Cleanup timeouts during the stuck period
12:30:36 agent cleanup timed out: runId=... sessionId=... step=pi-trajectory-flush timeoutMs=
12:33:05 agent cleanup timed out: runId=... sessionId=... step=pi-trajectory-flush timeoutMs=

# Event loop delays
12:21:55 liveness warning: reasons=event_loop_delay interval=31s eventLoopDelayP99Ms=897.1 eventLoopDelayMaxMs=1784.7
12:22:55 liveness warning: reasons=event_loop_delay,cpu interval=30s eventLoopDelayP99Ms=1891.6 eventLoopDelayMaxMs=3454 eventLoopUtilization=0.852
12:24:56 liveness warning: reasons=event_loop_delay,event_loop_utilization,cpu interval=30s eventLoopDelayP99Ms=3259 eventLoopDelayMaxMs=3259 eventLoopUtilization=0.999

Preliminary Root Cause Analysis

The issue appears to be in how messages are handled during/after preflightCompaction:

  1. preflightCompaction executes synchronously inside the session lane (via enqueueCommandInLane in agent-runner.runtime-DCKwkWFL.js line ~1742)
  2. setPhase("preflight_compacting") is set but has no timeout protection
  3. During compaction, new messages from webchat arrive and are queued (queueDepth=1)
  4. After compaction completes, queued messages appear to not be properly dequeued/processed
  5. The session remains in state=processing indefinitely

The replyOperation.abortSignal passed to compaction does not have a timeout that would interrupt a slow compaction.

Possible Related Factors

  • Session file: /root/.openclaw/agents/main/sessions/b84aa148-4a29-4f2f-94e5-9b7296aabbf3.jsonl
  • Context overflow events: Context overflow: estimated context size exceeds safe threshold during tool loop (compaction attempts: 0 — meaning preflight compaction didn't run before overflow)
  • Compaction succeeded but didn't prevent the stuck state
  • Recovery required full Gateway restart, not just session reset

Tags

bug compaction session-lane webchat v2026.5.2

Activity

  1. clawsweeper commented on May 3, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

    Close as duplicate/superseded: the remaining compaction-causes-unresponsive-session behavior is already tracked by the open compaction lane-starvation issue, with the successful-compaction stuck path tracked separately; the same-author fix PR for this issue is closed unmerged and is no longer an implementation path.

    Canonical path: Keep the remaining compaction lane-starvation work on #53008 and the successful-compaction stuck proof on #70334, linking this issue's WebChat logs there if needed.

    So I’m closing this here and keeping the remaining discussion on #53008 and #70334.

    Review details

    Best possible solution:

    Keep the remaining compaction lane-starvation work on #53008 and the successful-compaction stuck proof on #70334, linking this issue's WebChat logs there if needed.

    Do we have a high-confidence way to reproduce the issue?

    Yes, at source level: current main still awaits preflight compaction inside the foreground reply path and serializes same-session work while that operation is active. I did not run a live WebChat replay.

    Is this the best way to solve the issue?

    Yes for tracker cleanup: closing this as a duplicate of the canonical lane-starvation tracker is the narrowest maintainer outcome because the attempted fix PR is closed unmerged and the remaining work needs the broader compaction scheduling decision already tracked elsewhere.

    Security review:

    Security review: This is non-PR issue triage with no patch or security-sensitive report to review.

    What I checked:

    Likely related people:

    • steipete: Authored oversized-transcript preflight compaction and adjacent preflight rotation/async transcript work in the affected reply and compaction paths. (role: recent area contributor; confidence: high; commits: 29af4add2a8e, 1882a8e5eace, 6147e1b91d3e; files: src/auto-reply/reply/agent-runner-memory.ts, src/auto-reply/reply/reply-run-registry.ts, src/agents/pi-embedded-runner/compact.ts)
    • vincentkoc: Recent history shows work on pre-compaction memory flush, bounded Gateway transcript reads, and restart drain preservation near the affected Gateway/session reliability paths. (role: adjacent area contributor; confidence: medium; commits: 7fd9c152d122, aec83af23d49, ec1f72b6c58f; files: src/auto-reply/reply/agent-runner-memory.ts, src/gateway/server-methods/chat.ts, src/process/command-queue.ts)
    • jared596: Authored the transcript-estimate-triggered preflight compaction commit that is part of the current preflight compaction route. (role: introduced related behavior; confidence: medium; commits: c6d8318d07f5; files: src/auto-reply/reply/agent-runner-memory.ts)

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 333f65fc8a12.

  2. njuboy11 commented on May 3, 2026

    @njuboy11
    ContributorAuthor

    Update: Fix submitted

    We found and fixed the root cause. PR: #76485

    Root cause: queueReplyRunMessage() only accepted messages when operation.phase === 'running', silently dropping messages sent during preflight_compacting or memory_flushing. This caused queued webchat messages to never be drained after compaction completed.

    Fix: Expanded accepting phases in queueReplyRunMessage to include 'preflight_compacting' and 'memory_flushing'.

    5 regression tests added, all passing. Existing registry tests: still 5/5 passing.

  3. locked as resolved and limited conversation to collaborators on May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions