openclaw - 💡(How to fix) Fix claude-cli backend skips runContextEngineMaintenance — LCM/transcript persistence broken for all CLI-routed turns [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#81558Fetched 2026-05-14 03:30:51
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Author
Timeline (top)
commented ×1cross-referenced ×1

The claude-cli backend code path (execute.runtime, claude-live-session, prepare.runtime) never calls runContextEngineMaintenance or finalizeHarnessContextEngineTurn after a turn completes. The embedded backend (pi-embedded) calls both consistently.

As a result, every turn routed through provider=claude-cli/* bypasses the entire context-engine / LCM persistence pipeline. LCM stays empty, session JSONL stops being appended, and historyPrompt=none is forced in every CLI exec — making missing-transcript resets unrecoverable.

Root Cause

Users running subscription-only Anthropic via claude-cli with LCM as memory infrastructure get zero return on the LCM investment for their primary setup.

Cross-session memory, semantic search, summary recall, dreaming, compaction summaries — all stay empty for claude-cli turns.

The “context loss” UX symptom in #77974 is a downstream effect of this gap: when claude-cli's own transcript is lost, OpenClaw has nothing in LCM to feed back as historyPrompt, so historyPrompt=none is unavoidable.

Fix Action

Fix / Workaround

Tested workaround

Code Example

$ grep -nE "resolveContextEngine|runContextEngineMaintenance" dist/pi-embedded-Bcz04p2i.js
88: const contextEngine = await resolveContextEngine(params.config, ...)
210: await runContextEngineMaintenance({..., reason: "compaction"})
2064: const contextEngine = await resolveContextEngine(...)
2561: await runContextEngineMaintenance({..., reason: "compaction"})

---

$ grep -nE "contextEngine|runContextEngineMaintenance|finalizeHarnessContextEngineTurn" \
  dist/execute.runtime-CBFsBosL.js \
  dist/claude-live-session-C0vmXU_W.js \
  dist/prepare.runtime-COrRiEYB.js

# zero hits

---

2026-05-13T01:00:44.045+02:00 [agent/embedded]
[context-engine] deferred turn maintenance queued
taskId=9e272442-961f-4823-8da2-e84db26c3359
sessionKey=agent:main:main
lane=context-engine-turn-maintenance:agent:main:main
RAW_BUFFERClick to expand / collapse

Summary

The claude-cli backend code path (execute.runtime, claude-live-session, prepare.runtime) never calls runContextEngineMaintenance or finalizeHarnessContextEngineTurn after a turn completes. The embedded backend (pi-embedded) calls both consistently.

As a result, every turn routed through provider=claude-cli/* bypasses the entire context-engine / LCM persistence pipeline. LCM stays empty, session JSONL stops being appended, and historyPrompt=none is forced in every CLI exec — making missing-transcript resets unrecoverable.

Environment

  • OpenClaw 2026.5.7 (eeef486)
  • Node 22.22.2 on macOS 25.4.0 (Darwin arm64)
  • LCM / lossless-claw 0.9.4 loaded successfully
    • peer-deps already fixed per Martian-Engineering/lossless-claw#636
  • Telegram DM channel
  • sessionKey=agent:main:main

Static Code Evidence

Embedded path — has maintenance hooks:

$ grep -nE "resolveContextEngine|runContextEngineMaintenance" dist/pi-embedded-Bcz04p2i.js
88: const contextEngine = await resolveContextEngine(params.config, ...)
210: await runContextEngineMaintenance({..., reason: "compaction"})
2064: const contextEngine = await resolveContextEngine(...)
2561: await runContextEngineMaintenance({..., reason: "compaction"})

CLI backend — 2378 LOC across 3 files, zero maintenance hooks:

$ grep -nE "contextEngine|runContextEngineMaintenance|finalizeHarnessContextEngineTurn" \
  dist/execute.runtime-CBFsBosL.js \
  dist/claude-live-session-C0vmXU_W.js \
  dist/prepare.runtime-COrRiEYB.js

# zero hits

Live A/B Repro — same session, only provider changed

Identical:

  • agent: main
  • sessionKey=agent:main:main
  • sessionId=769b5dec-5478-4107-a4a6-26948c4da7b6
  • LCM conversation: 640
  • same Telegram DM chat

Only the model/provider slot was switched mid-session.

Phase A — provider=claude-cli/claude-opus-4-7

~5 hours of normal Telegram DM turns, 2026-05-12 22:59 → 2026-05-13 00:53 CEST:

  • Gateway log shows [agent/cli-backend] cli exec + claude live session turn events normally
  • [context-engine] deferred turn maintenance queued sessionKey=agent:main:main events: 0
  • LCM messages for conv 640 frozen at:
    • max(seq)=306
    • max(created_at)=2026-05-12 18:28:50 UTC
  • Session JSONL 769b5dec-...jsonl frozen at 36 lines
    • last write: 2026-05-12 18:28:52
  • Every CLI exec line carries historyPrompt=none
  • Multiple cli session reset: reason=missing-transcript
  • User-visible result: amnesia / lost conversational continuity

Phase B — provider=openai-codex/gpt-5.5

Single Telegram DM turn at 2026-05-13 01:00 CEST, same session:

After-turn ingest + maintenance scheduling fire immediately (both gated by finalizeHarnessContextEngineTurn, which the CLI backend skips):

2026-05-13T01:00:44.045+02:00 [agent/embedded]
[context-engine] deferred turn maintenance queued
taskId=9e272442-961f-4823-8da2-e84db26c3359
sessionKey=agent:main:main
lane=context-engine-turn-maintenance:agent:main:main

Result:

  • LCM conv 640: seq=310 (+4 new rows)
  • Session JSONL: 41 lines (+5 new events)
  • LCM receives data again

Conclusion: nothing about transcript timing, retry logic, or claude-cli's own state changed between the phases — only the routing into the CLI backend vs. embedded code path.

Why this matters

Users running subscription-only Anthropic via claude-cli with LCM as memory infrastructure get zero return on the LCM investment for their primary setup.

Cross-session memory, semantic search, summary recall, dreaming, compaction summaries — all stay empty for claude-cli turns.

The “context loss” UX symptom in #77974 is a downstream effect of this gap: when claude-cli's own transcript is lost, OpenClaw has nothing in LCM to feed back as historyPrompt, so historyPrompt=none is unavoidable.

Proposed fix

Add equivalents of finalizeHarnessContextEngineTurn (dist/attempt.tool-run-context-DWgSdeV1.js:465-520) to the CLI backend code path:

  1. contextEngine.afterTurn(...) / ingestBatch(...) to populate LCM after each successful CLI turn
  2. runContextEngineMaintenance({ ..., reason: "turn" }) to schedule deferred maintenance

Most natural call site: after a successful claude live session turn completion in execute.runtime-CBFsBosL.js, or as a wrapper around runCliAgent().

Related — do not mark as duplicate of

  • #77974 — same Telegram-DM amnesia symptom, but proposes a missing-transcript retry fix. That does not appear sufficient on its own: even with perfect transcript flush, LCM stays empty for claude-cli turns.
  • #57326 — opposite direction: helper paths bypass CLI to embedded. Confirms the two backends are structurally separate.
  • #78506 — closed as duplicate of #77974.
  • #78669 — closed; PR #77839 ship status.
  • #77518 — closed; embedded persist regression, different bug.

Tested workaround

Switch to openai-codex/gpt-5.5 or any non-CLI embedded provider.

LCM persistence + maintenance pipeline works immediately, but this breaks subscription-only Anthropic setups.

Repro artifacts available

If maintainers need more data, I can provide:

  • gateway.log excerpts for the A/B phase
  • sqlite dumps of LCM conv 640 before/after the provider switch
  • sessions.json snapshot
  • exact grep output with byte counts

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix claude-cli backend skips runContextEngineMaintenance — LCM/transcript persistence broken for all CLI-routed turns [1 comments, 2 participants]