-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Main session prompt crash: Cannot read properties of undefined (reading 'length') in compaction token estimation #63612
Copy link
Copy link
Closed as not planned
BingqingLyu/openclaw
#2207Closed as not planned
Copy link
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivityMarked as stale due to inactivity
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.ClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Give feedbackNo fields configured for issues without a type.
Main session prompt crash:
Cannot read properties of undefined (reading 'length')Date: 2026-04-09
Host: macOS
OpenClaw version: 2026.4.8
Summary
A long-lived
mainsession can become unrecoverable with the error:Agent failed before reply: Cannot read properties of undefined (reading 'length')This is not a provider/model error. The crash happens before prompt submission, during pre-prompt compaction token estimation.
Exact stack
Observed via added local diagnostic logging:
Impact
mainsession cannot reply at all.What seems to trigger it
Root cause
The crash point is in
pi-coding-agentcompaction token estimation logic.estimateTokens()assumes message block fields always exist:assistant.contentis iterableblock.text.lengthis always safeblock.thinking.lengthis always safeblock.name.lengthis always safe for tool callstoolResult/custom.contentis always an array or stringThat assumption breaks on malformed or partially-normalized history blocks.
Local evidence from runtime logs
Representative runtime log lines:
Local mitigation that restored the session
Two layers were patched locally:
dist/pi-embedded-CNTNdlGw.jsnode_modules/@mariozechner/pi-coding-agent/dist/core/compaction/compaction.jsSpecifically, local guards were added for:
assistant.contenttoolResult/custom.contentblock.textblock.thinkingblock.nameAfter patching the compaction
estimateTokens()path, the main session recovered.Suggested upstream fix
In
pi-coding-agentcompaction token estimation, treat malformed blocks as zero-length instead of throwing.Minimal expectation:
0for invalid message objectscontentas empty.lengthaccess behind type checksWhy this matters
This is a high-impact session-killer bug because it affects the recovery path itself:
Notes
This issue was observed on a heavily-used
mainsession, but the underlying bug looks general and could affect any long-running session that accumulates malformed history blocks.