Skip to content

[Bug] Context engine lifecycle hooks (assemble/afterTurn) don't fire for CLI backend sessions — plugin compaction engines non-functional #69016

@Adam-Researchh

Description

@Adam-Researchh

Description

When using a CLI backend (e.g., claude-cli) as the primary model provider, context engine plugin lifecycle hooks (assemble(), afterTurn(), ingestion) either don't fire or fire without token count data. This makes plugin-based compaction engines like lossless-claw non-functional on CLI-routed sessions.

Background

The session management docs confirm: "The flush runs only for embedded Pi sessions (CLI backends skip it)." However, the downstream impact on context engine plugins is not documented — users can configure plugins.slots.contextEngine: "lossless-claw" alongside a CLI backend primary model and have no indication that compaction will silently never trigger.

Symptoms

  • compactionCount: 0 indefinitely on CLI sessions regardless of conversation length
  • totalTokensFresh: True never transitions — openclaw has no real token count for CLI sessions
  • lcm_grep over summaries returns nothing for CLI-routed conversations (no summaries generated)
  • lcm_expand_query can't expand into conversations that were never summarized
  • TUI token counter fluctuates wildly (showing per-call counts, not cumulative session size)
  • Context engine plugin effectively becomes read-only (can search old API-era summaries, but nothing new accumulates)

Root Cause

CLI backends delegate context management to the external CLI process (e.g., Claude Code manages its own --session-id history internally). OpenClaw doesn't own the message history for CLI sessions the way it does for API sessions, so:

  1. assemble() is never called — the CLI owns context assembly internally
  2. afterTurn() fires without currentTokenCount — lossless-claw's threshold check always passes ("context looks fine") and compaction never triggers
  3. The pre-compaction memory flush is explicitly skipped for CLI backends
  4. OpenClaw sends only ~200-300 chars per turn (just the new user message), relying on --session-id for history, so the openclaw-side transcript doesn't reflect true context size

Impact

Users who configure a CLI backend as primary alongside a context engine plugin get:

  • No compaction
  • No new summary generation
  • No FTS indexing of new conversations
  • Gradual loss of the "lossless recall" capability as the conversation grows beyond the CLI's own context management

This is particularly impactful for users who chose CLI backends for billing reasons (subscription vs per-token) while depending on lossless-claw for long-term memory.

Expected Behavior

Either:

  1. Context engine hooks should fire with accurate token data for CLI sessions (preferred — makes plugins work transparently)
  2. Or openclaw should warn at startup: "CLI backend primary detected with context engine plugin — plugin compaction will not function. Use an API-routed model for full context engine support."
  3. Or the context engine should receive the CLI's reported token usage from the JSON output (Claude Code's --output-format json includes usage.input_tokens and cumulative session data) and use that to drive compaction decisions

Environment

  • OpenClaw 2026.4.15
  • lossless-claw 0.9.2
  • CLI backend: claude-cli (Claude Code /opt/homebrew/bin/claude)
  • CLI config: sessionArg: "--session-id", sessionMode: "always", output: "json"
  • macOS 26.3.1 (arm64), Node 25.8.0

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions