Skip to content

fix(agents): resolve effective runtime before preflight byte-guard compaction - #115284

Merged
steipete merged 1 commit into
mainfrom
steipete/cli-compaction-ownership-108984
Jul 28, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/cli-compaction-ownership-108984

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Sessions whose provider is embedded-capable (e.g. Anthropic) but whose model policy routes the turn to a CLI backend (claude-cli) were still hit by OpenClaw's preflight byte-guard compaction and memory flush: followupUsesCliRuntime checked only the provider string and the persisted session runtime pin, never the effective resolved runtime. OpenClaw maintenance then compacted transcript state the CLI backend owns (#108984). The recently landed retirement of truncateAfterCompaction (#115206) makes the byte guard armable by maxActiveTranscriptBytes alone, widening exposure.

Closes #108984. Supersedes #109096, whose approach and diagnosis this reimplements on current main with credit to @ATKasem (Co-authored-by on the commit).

Why This Change Was Made

runPreflightCompactionIfNeeded and runMemoryFlushIfNeeded (src/auto-reply/reply/agent-runner-memory.ts) now resolve the effective runtime once via resolveFollowupAgentRuntimeId (model policy included) and gate on it twice: followupUsesCliRuntime accepts the resolved runtime alongside the persisted pin, and a new followupOwnsNativeCompaction check honors resolveCliBackendConfig(...).ownsNativeCompaction as defense-in-depth — backends that persist resumable native transcripts stay the sole compaction owner. The old followupUsesCodexRuntime helper is absorbed into the already-resolved runtime id (one resolution instead of two, net −6 production lines).

User Impact

claude-cli-routed sessions (and any CLI backend declaring ownsNativeCompaction) are no longer compacted or memory-flushed by OpenClaw's embedded maintenance, regardless of how the routing was expressed (provider, persisted pin, or model policy). Embedded sessions keep the byte guard unchanged.

Evidence

  • node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-memory.test.ts — 57 tests passed, including new SQLite-era regressions: policy-routed CLI session with maxActiveTranscriptBytes set skips the byte guard; genuine embedded session still byte-guards.
  • Codex-backed autoreview on the commit: clean, no accepted findings (0.87).
  • Original diagnosis independently verified against main before rework (followupUsesCliRuntime at the old lines 258-275 never resolving effective runtime; Codex skip already doing so).

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 28, 2026
@steipete
steipete marked this pull request as ready for review July 28, 2026 16:13
@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 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 28, 2026, 12:17 PM ET / 16:17 UTC.

ClawSweeper review

What this changes

This PR resolves the effective follow-up runtime before memory-flush and transcript-byte preflight checks, so CLI backends that own native compaction are not compacted or flushed by embedded-runtime maintenance when model policy routes a turn to them.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 5 items remain

Keep this PR open for maintainer review: it targets the live session-continuity defect tracked by #108984, and it carries the protected maintainer label. The supplied patch and regression-test evidence support the intended ownership boundary, but the PR body provides test-only evidence rather than after-fix behavior from a real CLI-routed session, so it needs real behavior proof before merge.

Likely related people: steipete is a high-confidence recent contributor to the adjacent byte-guard configuration change; ATKasem is a high-confidence prior contributor to the same effective-runtime diagnosis and proposed fix.

Priority: P1
Reviewed head: 13c224cb83a9dc1f07c8c90de8e0970fff6bed3c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused regression patch is promising, but test-only evidence does not yet clear the real-behavior proof gate for a session-continuity fix.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR body reports focused Vitest coverage and autoreview, but no redacted after-fix runtime output, recording, screenshot, or log from a real policy-routed CLI session; add that proof and redact private endpoints, keys, IP addresses, and session data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports focused Vitest coverage and autoreview, but no redacted after-fix runtime output, recording, screenshot, or log from a real policy-routed CLI session; add that proof and redact private endpoints, keys, IP addresses, and session data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Reported defect and proposed ownership boundary: The PR body identifies a policy-routed anthropic run whose effective runtime is claude-cli; the branch changes the memory-maintenance path to use that resolved runtime and ownsNativeCompaction before preflight compaction or flushing.
Regression coverage added: The supplied PR diff adds a reusable claude-cli backend fixture and regression cases for policy-routed CLI sessions while retaining the embedded-session byte-guard case.
Current related work remains open: #108984 remains open and the PR explicitly presents itself as its candidate fix; the related prior PR #109096 addresses the same mechanism but is also still open.
Findings None None.
Security None None.

How this fits together

Agent runs can be routed from an embedded-capable provider to a CLI backend through model policy or a persisted runtime selection. Before an agent continues, the memory-maintenance layer may flush or compact the OpenClaw transcript; this change makes that layer defer when the resolved CLI backend owns its native transcript state.

flowchart TD
  A[Session and follow-up run] --> B[Resolve effective runtime]
  C[Model policy and runtime pin] --> B
  B --> D{CLI backend owns native compaction?}
  D -- Yes --> E[Skip OpenClaw flush and byte compaction]
  D -- No --> F[Evaluate transcript byte guard]
  F --> G[Embedded compaction or memory flush]
  E --> H[CLI backend preserves native transcript]
Loading

Decision needed

Question Recommendation
Should maintainers accept this branch as the canonical replacement for the overlapping open PR #109096 after it supplies real CLI-routed behavior proof? Adopt this canonical fix: Request redacted real-session proof, then land this branch if the effective-runtime and native-compaction behavior match the existing backend contract.

Why: Both PRs address the same user-visible session-state failure, but selecting one as the landing path and accepting the scope of the new ownership gate requires maintainer intent; the current protected label prevents automated cleanup.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports focused Vitest coverage and autoreview, but no redacted after-fix runtime output, recording, screenshot, or log from a real policy-routed CLI session; add that proof and redact private endpoints, keys, IP addresses, and session data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - This changes which existing sessions bypass memory flushing and byte-triggered compaction; a real policy-routed CLI session should demonstrate that native transcript continuity is retained while an embedded session still compacts normally.
  • Resolve merge risk (P1) - The protected maintainer label requires explicit maintainer handling even if focused CI completes successfully.
  • Complete next step (P2) - A protected-label PR with an overlapping open implementation needs maintainer selection and contributor-supplied real-session proof, not an automated repair.
Agent review details

Security

None.

PR surface

Source -6, Tests +76. Total +70 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 38 44 -6
Tests 1 97 21 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 135 65 +70

Review metrics

Metric Value Why it matters
Compaction ownership gates 2 maintenance paths changed Both memory flush and transcript-byte preflight now depend on the resolved runtime/CLI ownership decision, so an error affects session continuity across both safeguards.

Merge-risk options

Maintainer options:

  1. Prove the policy-routed CLI path before merge (recommended)
    Run a redacted real anthropic-provider session resolved to claude-cli past the byte threshold and show that OpenClaw skips embedded compaction while an embedded control session still takes its normal path.
  2. Accept the regression-test-only evidence
    Maintainers may land based on the focused regressions and backend contract, accepting that the reported production routing shape has not been demonstrated after the fix.
  3. Choose a single overlapping implementation
    Pause this branch until maintainers decide whether it or fix(agents): claude-cli sessions wiped by preflight byte-guard compaction #109096 is the canonical landing path for the same defect.

Technical review

Best possible solution:

Land one canonical fix for #108984 that resolves the effective runtime once, honors ownsNativeCompaction before embedded maintenance, and includes redacted after-fix proof from a CLI-routed session plus the existing focused regression coverage.

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

No high-confidence live reproduction is included in this PR. The supplied regression tests make the policy-routed CLI path source-reproducible, but they do not demonstrate an after-fix real session.

Is this the best way to solve the issue?

Unclear: resolving the effective runtime and honoring native-compaction ownership is consistent with the reported failure and focused tests, but a direct current-main/source-contract comparison could not be completed after the read-only shell failed before file inspection.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The linked report describes active CLI-routed sessions losing working context when byte-triggered compaction runs against a backend-owned transcript.
  • add merge-risk: 🚨 session-state: The patch changes whether established sessions are flushed or compacted, which can either protect or inadvertently retain/alter transcript state depending on effective runtime resolution.
  • 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 body reports focused Vitest coverage and autoreview, but no redacted after-fix runtime output, recording, screenshot, or log from a real policy-routed CLI session; add that proof and redact private endpoints, keys, IP addresses, and session data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: The linked report describes active CLI-routed sessions losing working context when byte-triggered compaction runs against a backend-owned transcript.
  • merge-risk: 🚨 session-state: The patch changes whether established sessions are flushed or compacted, which can either protect or inadvertently retain/alter transcript state depending on effective runtime resolution.
  • 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 body reports focused Vitest coverage and autoreview, but no redacted after-fix runtime output, recording, screenshot, or log from a real policy-routed CLI session; add that proof and redact private endpoints, keys, IP addresses, and session data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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
steipete merged commit 942d3d7 into main Jul 28, 2026
190 of 195 checks passed
@steipete
steipete deleted the steipete/cli-compaction-ownership-108984 branch July 28, 2026 17:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR 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: M 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

1 participant