Skip to content

feat: add cache-aware incremental compaction#315

Closed
jalehman wants to merge 1 commit intomainfrom
codex/cache-aware-incremental-compaction
Closed

feat: add cache-aware incremental compaction#315
jalehman wants to merge 1 commit intomainfrom
codex/cache-aware-incremental-compaction

Conversation

@jalehman
Copy link
Copy Markdown
Contributor

@jalehman jalehman commented Apr 7, 2026

What

This PR implements cache-aware incremental compaction for lossless-claw using OpenClaw prompt-cache telemetry. It persists per-conversation cache observations after each turn, defers best-effort incremental leaf compaction while the prompt cache is hot, and allows bounded catch-up passes once the cache goes cold. This depends on openclaw/openclaw#62179, which provides the runtime prompt-cache signals.

Why

The spec here is to avoid churning the prompt-cache prefix when the session is actively benefiting from cache reuse, while still letting lossless-claw catch up once that benefit is gone. The existing token-driven incremental behavior had no visibility into real cache state, so it could compact at the wrong time.

Changes

  • Persist prompt-cache telemetry per conversation
  • Add cache-aware incremental compaction policy
  • Allow bounded cold-cache catch-up passes
  • Add config, schema, and docs support
  • Cover hot/cold/unknown behavior with tests

Testing

  • npx vitest run test/config.test.ts test/engine.test.ts test/session-operation-queues.test.ts test/expansion.test.ts test/circuit-breaker.test.ts --exclude='.worktrees/**' --exclude='**/.worktrees/**'
  • Expected: all targeted tests pass

Persist prompt-cache telemetry after turns and use it to gate incremental
leaf compaction. Hot cache sessions now defer best-effort incremental
passes unless raw history pressure is clearly above target, while cold
cache sessions can run bounded catch-up passes in a single maintenance
cycle. Full threshold sweeps keep their existing behavior.

Also add cacheAwareCompaction config/schema support, docs, a changeset,
and regression coverage for hot/cold/unknown prompt-cache behavior.

Regeneration-Prompt: |
  Implement the cache-aware incremental compaction spec for lossless-claw
  using the new prompt-cache telemetry exposed by the dependent OpenClaw
  branch tied to openclaw/openclaw#62179. Persist lightweight per-
  conversation cache telemetry after each turn, classify sessions as hot,
  cold, or unknown, and use that state to decide whether afterTurn()
  should run incremental leaf compaction. Preserve the existing full-sweep
  compaction behavior, but let cold-cache sessions do a bounded number of
  extra leaf passes to catch up while hot-cache sessions defer passes
  unless raw history pressure is clearly above target. Add the minimal
  config surface for enabling the feature and setting the cold-cache pass
  cap, keep the plugin manifest and docs in sync, and cover the behavior
  with focused engine and config tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant