openclaw - 💡(How to fix) Fix CLI transcript persistence fails: "Context engine \"legacy\" is not registered" in cli-compaction [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

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#75548Fetched 2026-05-02 05:33:17
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Timeline (top)
closed ×1commented ×1cross-referenced ×1

On every CLI agent turn (channels: telegram, openclaw CLI), the gateway logs:

[WARN] {agents/agent-command} - CLI transcript persistence failed for agent:main:main: Context engine "legacy" is not registered. Available engines: (none)

Transcripts are not persisted via this code path. openclaw doctor reports orphan transcript files and missing-transcript sessions as a downstream symptom.

Error Message

[WARN] {agents/agent-command} - CLI transcript persistence failed for agent:main:main: Context engine "legacy" is not registered. Available engines: (none)

Root Cause

dist/cli-compaction-*.js calls resolveContextEngine(params.cfg) without first calling ensureContextEnginesInitialized().

ensureContextEnginesInitialized() (defined in dist/init-*.js from src/context-engine/init.ts) is the function responsible for registering the built-in legacy engine. Its source comment states:

The legacy engine is always registered as a safe fallback so that resolveContextEngine() can resolve the default "legacy" slot without callers needing to remember manual registration.

In the shipped 2026.4.26 build, the only call sites for that function are:

  • dist/pi-embedded-*.js (embedded Pi runner)
  • dist/subagent-registry-*.js

For pure CLI sessions that never spawn a subagent or run an embedded Pi attempt, neither path runs before cli-compaction.runCliTurnCompactionLifecycle calls resolveContextEngine("legacy"). The registry has no engines registered, resolution throws, and the catch in agent-command.ts logs the warning quoted above. Transcript persistence is silently skipped.

Fix Action

Fix / Workaround

Drop-in workaround patch on the shipped JS:

Verified locally: with this two-line patch, both the transcript persistence failed and Context engine "legacy" is not registered warnings stop firing, and CLI transcript persistence proceeds normally across multiple turns.

Code Example

[WARN] {agents/agent-command} - CLI transcript persistence failed for agent:main:main: Context engine "legacy" is not registered. Available engines: (none)

---

--- a/dist/cli-compaction-*.js
+++ b/dist/cli-compaction-*.js
@@
 import { i as resolveContextEngine } from "./registry-*.js";
+import { t as ensureContextEnginesInitialized } from "./init-*.js";
 ...
 async function runCliTurnCompactionLifecycle(params) {
   const sessionFile = params.sessionEntry?.sessionFile;
   const contextTokenBudget = resolvePositiveInteger(params.sessionEntry?.contextTokens);
   if (!sessionFile || !contextTokenBudget) return params.sessionEntry;
+  ensureContextEnginesInitialized();
   const contextEngine = await cliCompactionDeps.resolveContextEngine(params.cfg);
RAW_BUFFERClick to expand / collapse

Summary

On every CLI agent turn (channels: telegram, openclaw CLI), the gateway logs:

[WARN] {agents/agent-command} - CLI transcript persistence failed for agent:main:main: Context engine "legacy" is not registered. Available engines: (none)

Transcripts are not persisted via this code path. openclaw doctor reports orphan transcript files and missing-transcript sessions as a downstream symptom.

Environment

  • openclaw 2026.4.26 (commit be8c246)
  • Node 22.22.2 (nvm)
  • WSL2 Ubuntu on Windows
  • gateway.bind: loopback
  • Reproduced via Telegram channel and via openclaw CLI (sessions that never spawn a subagent or run an embedded Pi attempt)

Root cause

dist/cli-compaction-*.js calls resolveContextEngine(params.cfg) without first calling ensureContextEnginesInitialized().

ensureContextEnginesInitialized() (defined in dist/init-*.js from src/context-engine/init.ts) is the function responsible for registering the built-in legacy engine. Its source comment states:

The legacy engine is always registered as a safe fallback so that resolveContextEngine() can resolve the default "legacy" slot without callers needing to remember manual registration.

In the shipped 2026.4.26 build, the only call sites for that function are:

  • dist/pi-embedded-*.js (embedded Pi runner)
  • dist/subagent-registry-*.js

For pure CLI sessions that never spawn a subagent or run an embedded Pi attempt, neither path runs before cli-compaction.runCliTurnCompactionLifecycle calls resolveContextEngine("legacy"). The registry has no engines registered, resolution throws, and the catch in agent-command.ts logs the warning quoted above. Transcript persistence is silently skipped.

Reproduction

  1. Fresh openclaw 2026.4.26 install on Linux/WSL2.
  2. openclaw configure for a Telegram (or any) channel; default config (no plugins.slots.contextEngine set).
  3. Start the gateway via systemd user service.
  4. Send any message through the channel (or run an openclaw CLI prompt).
  5. Tail /tmp/openclaw/openclaw-<date>.log — the warning fires every turn.

Suggested fix

Add a call to ensureContextEnginesInitialized() in src/agents/command/cli-compaction.ts (or in agent-command.ts before runCliTurnCompactionLifecycle is invoked), matching the pattern already used in the embedded Pi runner and subagent registry.

Drop-in workaround patch on the shipped JS:

--- a/dist/cli-compaction-*.js
+++ b/dist/cli-compaction-*.js
@@
 import { i as resolveContextEngine } from "./registry-*.js";
+import { t as ensureContextEnginesInitialized } from "./init-*.js";
 ...
 async function runCliTurnCompactionLifecycle(params) {
   const sessionFile = params.sessionEntry?.sessionFile;
   const contextTokenBudget = resolvePositiveInteger(params.sessionEntry?.contextTokens);
   if (!sessionFile || !contextTokenBudget) return params.sessionEntry;
+  ensureContextEnginesInitialized();
   const contextEngine = await cliCompactionDeps.resolveContextEngine(params.cfg);

Verified locally: with this two-line patch, both the transcript persistence failed and Context engine "legacy" is not registered warnings stop firing, and CLI transcript persistence proceeds normally across multiple turns.

Unrelated note

While debugging I noticed the systemd unit description for openclaw-gateway.service still reads (v2026.4.22) after upgrading to 2026.4.26. Cosmetic, but suggests the unit isn't regenerated on upgrade. Happy to file separately if useful.

extent analysis

TL;DR

Add a call to ensureContextEnginesInitialized() before resolveContextEngine("legacy") to register the built-in legacy engine.

Guidance

  • Verify that ensureContextEnginesInitialized() is called before resolveContextEngine("legacy") in src/agents/command/cli-compaction.ts or agent-command.ts.
  • Apply the suggested fix by adding the two-line patch to dist/cli-compaction-*.js as shown in the issue.
  • Test the fix by reproducing the issue and checking that the transcript persistence failed and Context engine "legacy" is not registered warnings no longer appear.
  • Consider filing a separate issue for the outdated systemd unit description.

Example

The suggested fix can be applied as a drop-in patch:

--- a/dist/cli-compaction-*.js
+++ b/dist/cli-compaction-*.js
@@
 import { i as resolveContextEngine } from "./registry-*.js";
+import { t as ensureContextEnginesInitialized } from "./init-*.js";
 ...
 async function runCliTurnCompactionLifecycle(params) {
   const sessionFile = params.sessionEntry?.sessionFile;
   const contextTokenBudget = resolvePositiveInteger(params.sessionEntry?.contextTokens);
   if (!sessionFile || !contextTokenBudget) return params.sessionEntry;
+  ensureContextEnginesInitialized();
   const contextEngine = await cliCompactionDeps.resolveContextEngine(params.cfg);

Notes

The fix assumes that the ensureContextEnginesInitialized() function is correctly implemented and registers the built-in legacy engine.

Recommendation

Apply the workaround patch to dist/cli-compaction-*.js to fix the issue, as it has been verified to work locally.

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 CLI transcript persistence fails: "Context engine \"legacy\" is not registered" in cli-compaction [1 comments, 2 participants]