feat(agents): generalized native compaction ownership for CLI backends#88315
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 2, 2026, 4:55 AM ET / 08:55 UTC. Summary PR surface: Source +25, Tests +217, Docs +42. Total +284 across 8 files. Reproducibility: not applicable. as a bug reproduction; this is a feature/API PR, though the changed branch has deterministic tests and PR-body live logs from a lowered-budget real Review metrics: 3 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the generic backend hook only after agent/plugin owners accept the public SDK contract and Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction; this is a feature/API PR, though the changed branch has deterministic tests and PR-body live logs from a lowered-budget real Is this the best way to solve the issue? The generic backend hook is the right owner-boundary shape if maintainers want this public contract; the unresolved question is API and upgrade ownership, not a discrete code defect. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against dcf21ac3adaf. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +25, Tests +217, Docs +42. Total +284 across 8 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
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 re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
09120c8 to
36c34e6
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
36c34e6 to
6fdaaec
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
bf6e8eb to
8b8c599
Compare
|
@clawsweeper re-review |
8b8c599 to
02a2856
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
02a2856 to
6a4b5e7
Compare
6fd1c07 to
a1516cc
Compare
Add `ownsNativeCompaction` capability to CliBackendPlugin so backends that manage their own transcript compaction (e.g. Claude Code) can declare it once and OpenClaw defers instead of fighting or failing. Today only Codex declares compaction ownership (via the embedded runner path + agentHarnessId). Claude-cli never reaches that path because it runs as a CLI subprocess with no harness id set, so the safeguard summarizer fires and hard-fails the turn. This PR: - Adds `ownsNativeCompaction?: boolean` to the backend plugin type - Propagates it through all 4 backend resolution paths - In `runCliTurnCompactionLifecycle`, when a backend declares ownership but has no harness endpoint, returns a no-op instead of falling through to the safeguard - Sets the flag on claude-cli (first adopter) Codex's existing native-harness path is unchanged: when `isNativeHarnessCompactionSession` matches, the harness compaction endpoint is still called as before. Generalizes the partial fix in openclaw#87785 (codex-scoped) to a capability any backend can opt into.
a1516cc to
2384d73
Compare
|
Landed via rebase onto main.
Thanks @anagnorisis2peripeteia! |
Summary
Generalizes native-compaction ownership for CLI backends via a new
ownsNativeCompactioncapability flag.When a CLI backend owns transcript compaction and the session has no native-harness compaction endpoint, OpenClaw's CLI compaction lifecycle returns a no-op instead of running its safeguard summarizer. This avoids fighting backend-owned compaction or hard-failing the turn.
ownsNativeCompaction: true.claude-cli: Claude Code compacts internally and exposes no OpenClaw harness compaction endpoint.agentHarnessId; the no-op applies only when no harness endpoint exists.Scope: generalized mechanism plus the
claude-clideclaration. Opting in other backends is out of scope.What changed since review
This PR is purely the opt-out. The earlier
contextTokenscap-precedence change was removed: once a backend owns compaction, its budget never drives OpenClaw compaction, so capping below the native window solved a problem that no longer exists.src/agents/context.ts,src/agents/context.test.ts, and generated SDK baseline files are not part of this PR.Testing
src/agents/command/cli-compaction.test.tscovers over-budgetownsNativeCompaction+ no harness endpoint -> no-op defer; native-harness sessions still route to the harness endpoint; non-owning backends still run the safeguard summarizer.src/agents/cli-backends.test.tscovers capability registration.node scripts/run-vitest.mjs src/agents/command/cli-compaction.test.ts src/agents/cli-backends.test.ts.Real behavior proof
Behavior addressed:
claude-clisessions that own native compaction defer to Claude Code instead of triggering OpenClaw safeguard summarization when over budget and no harness compaction endpoint exists.Real environment tested: local OpenClaw source checkout with installed Claude CLI
2.1.150 (Claude Code).Exact steps or command run after this patch: one-off Node/tsx smoke registered the bundled Anthropic CLI backend, invoked OpenClaw
runCliAgentwithprovider=claude-cliandmodel=claude-sonnet-4-6, then invokedrunCliTurnCompactionLifecyclewith a synthetic over-budget session entry for the returnedclaude-clisession.Evidence after fix:
Observed result after fix: Claude CLI returned the expected response token, the OpenClaw session had a Claude CLI session id, compaction deferred with
deferred=true,compactionCount=0, and token counts stayed at the synthetic over-budget values.What was not tested: an organically over-budget live Claude GA session, because current GA models report a 1M-token window; the over-budget condition was forced only for the lifecycle proof.