Skip to content

fix(agents): claude-cli sessions wiped by preflight byte-guard compaction - #109096

Closed
ATKasem wants to merge 2 commits into
openclaw:mainfrom
ATKasem:fix/cli-owns-native-compaction-preflight
Closed

ATKasem wants to merge 2 commits into
openclaw:mainfrom
ATKasem:fix/cli-owns-native-compaction-preflight

Conversation

@ATKasem

@ATKasem ATKasem commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #108984

What Problem This Solves

Fixes an issue where users running long claude-cli sessions (including Anthropic models routed to claude-cli via model policy) would lose conversation continuity when OpenClaw's transcript-byte preflight compaction fired. The OpenClaw message view for those sessions is near-empty, so the summarizer produced an empty summary and truncateAfterCompaction rotated the session mid-thread.

Why This Change Was Made

Preflight only deferred for CLI when the provider string or a persisted session runtime pin looked like CLI. Routes that keep provider=anthropic while the effective turn runtime is claude-cli still reached the transcript_bytes path. The CLI backend contract already says ownsNativeCompaction: true backends own context management; preflight now resolves that effective backend the same way execution does and defers when ownership is set. Memory flush uses the same gate so it stays consistent.

User Impact

claude-cli / native-compaction-owning backends no longer get empty OpenClaw safeguard summaries that wipe active context. Embedded non-CLI compaction behavior is unchanged.

Evidence

  • Added regression: Anthropic provider + model policy agentRuntime: claude-cli, no session runtime pin, oversized transcript + truncateAfterCompaction — preflight must not call compactEmbeddedAgentSession.
  • node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-memory.test.ts src/auto-reply/reply/agent-runner-memory.preflight-stale-tokens.test.ts — 55 passed.

@ATKasem
ATKasem force-pushed the fix/cli-owns-native-compaction-preflight branch 3 times, most recently from dbcdc44 to b173659 Compare July 16, 2026 15:45
ATKasem added 2 commits July 16, 2026 10:45
Preflight compaction only skipped CLI backends when the provider string
or a persisted session runtime pin looked like CLI. Anthropic sessions
routed to claude-cli via model policy still hit transcript_bytes
compaction and could truncate an empty OpenClaw message view.

Defer preflight (and memory flush) when the effective turn runtime's
CLI backend declares ownsNativeCompaction, and cover Anthropic→claude-cli
routing without a session runtime pin.

Fixes openclaw#108984
resolveFollowupAgentRuntimeId only needs sessionId and runtime pin
fields, so share FollowupCliRuntimeParams instead of requiring a full
SessionEntry. Unblocks tsgo after the ownsNativeCompaction preflight gate.
@ATKasem
ATKasem force-pushed the fix/cli-owns-native-compaction-preflight branch from b173659 to a654666 Compare July 16, 2026 15:46
@ATKasem

ATKasem commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Wanted to make sure the CI passes

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 16, 2026, 11:57 AM ET / 15:57 UTC.

Summary
The PR makes preflight compaction and memory-flush gating resolve the effective CLI backend, honor ownsNativeCompaction, and adds regression coverage for an Anthropic model-policy route to claude-cli without a persisted runtime pin.

PR surface: Source +41, Tests +68. Total +109 across 2 files.

Reproducibility: yes. at source level: current main has a concrete Anthropic-to-claude-cli model-policy path without a persisted runtime pin that bypasses the existing CLI guard. A live current-main reproduction was not performed in this read-only review.

Review metrics: 1 noteworthy metric.

  • Compaction ownership gates: 2 aligned. The patch applies the same effective-runtime ownership decision to preflight compaction and memory flush, which must remain behaviorally consistent.

Stored data model
Persistent data-model change detected: serialized state: src/auto-reply/reply/agent-runner-memory.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #108984
Summary: This PR is the focused candidate fix for the linked claude-cli session-compaction issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Post a redacted live claude-cli transcript or log showing an oversized routed session preserves the same native conversation after preflight.
  • Include visible evidence that OpenClaw's embedded compactor was not invoked; redact keys, phone numbers, IP addresses, and non-public endpoints.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR provides focused tests and CI but no after-fix live claude-cli session proof; add a redacted terminal transcript or runtime log, update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review.

Risk before merge

  • [P1] The PR changes a session-state decision boundary: a resolver mismatch could allow destructive OpenClaw compaction for a CLI-owned session or suppress host compaction for a runtime that does not own it.
  • [P1] The supplied evidence is unit-test and CI output only; it does not demonstrate a real long-running claude-cli session crossing the byte threshold and retaining continuity.

Maintainer options:

  1. Prove native-session continuity (recommended)
    Require a redacted live claude-cli run or runtime log showing an oversized routed session stays on the same native thread and OpenClaw compaction is skipped.
  2. Accept source-only confidence
    Merge with the focused regression and green CI while explicitly accepting that the real subprocess and session path was not exercised.

Next step before merge

  • [P1] Keep the PR in normal review while the contributor supplies required live runtime proof; there is no concrete code defect for an automated repair lane.

Security
Cleared: The TypeScript runtime and test changes introduce no concrete credential, authorization, dependency, workflow, or supply-chain concern.

Review details

Best possible solution:

Keep the generic effective-runtime plus backend-capability gate, cover both preflight and memory-flush callers, and land only after a redacted live claude-cli run shows the byte threshold no longer invokes OpenClaw compaction or resets the native session.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: current main has a concrete Anthropic-to-claude-cli model-policy path without a persisted runtime pin that bypasses the existing CLI guard. A live current-main reproduction was not performed in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing effective-runtime resolver and the backend's ownsNativeCompaction contract is narrower and more maintainable than hardcoding Anthropic or claude-cli behavior, though real subprocess proof remains required.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c46cc1e2d458.

Label changes

Label changes:

  • add P1: The linked report shows active long-running agent sessions losing conversation continuity mid-thread.
  • add merge-risk: 🚨 session-state: The patch changes whether OpenClaw may compact or rotate persisted session context based on effective runtime ownership.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused tests and CI but no after-fix live claude-cli session proof; add a redacted terminal transcript or runtime log, update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review.

Label justifications:

  • P1: The linked report shows active long-running agent sessions losing conversation continuity mid-thread.
  • merge-risk: 🚨 session-state: The patch changes whether OpenClaw may compact or rotate persisted session context based on effective runtime ownership.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides focused tests and CI but no after-fix live claude-cli session proof; add a redacted terminal transcript or runtime log, update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +41, Tests +68. Total +109 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 74 33 +41
Tests 1 68 0 +68
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 142 33 +109

What I checked:

Likely related people:

  • obviyus: Recent merged work covers memory-flush behavior and CLI session-binding preservation, making this the strongest runtime-specific routing candidate. (role: recent CLI session and memory contributor; confidence: high; commits: f2c813c, 731814c; files: src/auto-reply/reply/agent-runner-memory.ts, src/agents/cli-runner.ts)
  • steipete: Recent history connects this person to several preflight, context-compaction, and runtime-state changes in the central module. (role: recent compaction and runtime contributor; confidence: high; commits: aada44f, ed3ae0d, f4cfa01; files: src/auto-reply/reply/agent-runner-memory.ts)
  • mcaxtr: Authored a recent preflight no-op budget fix in the same compaction decision path. (role: adjacent preflight compaction contributor; confidence: medium; commits: bcde7b1; files: src/auto-reply/reply/agent-runner-memory.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor

Closing as landed via #115284 (942d3d76008) — with your credit: the commit carries Co-authored-by: ATKasem <[email protected]>.

Your diagnosis and approach were correct and are what shipped: followupUsesCliRuntime now resolves the effective runtime (model policy included) and a followupOwnsNativeCompaction gate honors resolveCliBackendConfig(...).ownsNativeCompaction for both preflight compaction and memory flush. This branch had drifted into conflict (import-block churn from #113233/#114819) and its regression test targeted the deleted file-era JSONL session runtime, so we reimplemented on current main with SQLite-era tests rather than asking you to rebase — the ownership fix also became more urgent after #115206 made the byte guard armable by maxActiveTranscriptBytes alone.

Thanks for the report, the fix, and confirming the diagnosis on #108984 — much appreciated.

@steipete steipete closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-cli sessions get wiped by OpenClaw's byte-guard compaction despite the ownsNativeCompaction short-circuit

2 participants