Skip to content

cli-backend never triggers compaction (native or plugin) — context grows unbounded #68329

@jacko2bot

Description

@jacko2bot

Summary

The cli-backend (provider=claude-cli) never triggers any form of context compaction — neither native (agents.defaults.compaction.reserveTokens) nor plugin-based (lossless-claw). Context grows unbounded past the model window with zero compactions.

Environment

  • OpenClaw 2026.4.15
  • Provider: claude-cli (model: opus)
  • Session: agent:main:main
  • Native compaction: reserveTokens: 30000 (should trigger ~85% / 170k)
  • lossless-claw: tested both enabled and disabled

What happens

  1. Messages arrive via chat.send, cli-backend bootstraps workspace files, runs cli exec
  2. No compaction activity occurs between turns — no threshold evaluation, no compaction attempt, no skip/defer decisions logged
  3. Context reaches 200%+ of the model window with zero compactions
  4. This happens regardless of whether lossless-claw is enabled or disabled

Test results

Test 1: lossless-claw enabled

  • LCM loads and announces config correctly
  • No LCM activity between turns — plugin is completely silent after init
  • Context reached 161% with 0 compactions
  • Native compaction also did not fire (gateway defers to LCM as active context engine)

Test 2: lossless-claw disabled

  • LCM disabled to rule out it blocking native compaction
  • Deliberately loaded ~20 large files to push context to 201%
  • Native compaction still did not fire — 0 compactions at 201%
  • Confirms the issue is in the cli-backend, not LCM

Root cause

The cli-backend execution path does not emit the per-turn lifecycle events (token-usage telemetry, turn-complete signals) that the compaction pipeline hooks into. The backend shells out to the Claude Code CLI, which manages its own context internally and doesn't feed telemetry back through the gateway's plugin/compaction event system.

Evidence: gateway logs show only cli exec: provider=claude-cli model=opus promptChars=N with no subsequent compaction activity. Both native and plugin compaction systems are never evaluated — not "evaluated and deferred" but "never called."

Expected behavior

After each turn completes, the cli-backend should report token usage back to the gateway so the compaction pipeline can evaluate context utilization and trigger compaction when thresholds are exceeded.

Notes

  • proactiveThresholdCompactionMode tested in both inline and deferred modes — neither triggers
  • Cache hit rate is 89%, but at 200%+ utilization headroom checks should fail
  • The cli-backend likely needs to emit a turn-complete event with token counts after cli exec returns, similar to what the native provider backends do

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