feat(cli): add openclaw sessions compact and fail loudly on CLI /compact (fixes #90640)#91378
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 19, 2026, 3:45 PM ET / 19:45 UTC. Summary PR surface: Source +474, Tests +758, Docs +51. Total +1283 across 15 files. Reproducibility: yes. source-level: current main has Review metrics: 2 noteworthy metrics.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 this PR after exact-head required checks are green, preserving the Gateway-owned compaction boundary and closing #90640 after merge. Do we have a high-confidence way to reproduce the issue? Yes, source-level: current main has Is this the best way to solve the issue? Yes. Wrapping the existing Gateway RPC and failing the unsupported CLI slash-command path is narrower than bypassing the authorized-sender checks, and it keeps target resolution and transcript mutation in the Gateway/session accessor owner boundary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bb1043b14c46. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +474, Tests +758, Docs +51. Total +1283 across 15 files. View PR surface stats
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
|
|
Maintainer fix pushed in f284d57. This addresses the local autoreview P2 finding: The fix adds a non-mutating manual-trim preflight and only interrupts the active run when preflight proves archive/rewrite is needed. It also adds regression coverage for active-run no-op cases: already-short transcript and missing transcript. Local proof before push:
|
|
Maintainer review: merge-ready once checks are green. This is a narrow fix for a real user-facing gap: the existing Maintainer fix f284d57 addressed the local autoreview P2 by ensuring Validation:
No unintended breaking changes found. The compatibility-visible |
…mpact` `sessions.compact` was reachable only as an internal Gateway RPC — no CLI command, no docs — and `openclaw agent --message '/compact'` silently no-opped with exit 0 because the slash-command handler rejects CLI-originated senders, so the message fell through to an ordinary agent turn that compacted nothing. - Add `openclaw sessions compact <key>` wrapping the existing `sessions.compact` RPC; exit non-zero on a transport error or an `ok:false` payload so automation never mistakes a silent no-op for success. - Reject `openclaw agent --message '/compact'` with a redirect to the new command and exit 1 instead of a silent exit 0. The shared chat-side `/compact` handler is left untouched (no compatibility / message-delivery blast radius). - Strictly validate `--max-lines` and `--timeout` (positive integers only). - Document the command and the `sessions.compact` RPC in docs/cli/sessions.md. Fixes openclaw#90640.
`openclaw sessions compact <key>` did not merge the parent `sessions` command options the way its sibling subcommands (list/cleanup/info/…) do, so a parent-level `--agent`/`--json` was silently dropped. In particular `openclaw sessions --agent work compact <key>` compacted the default agent's session instead of the work agent's — a wrong-target session-state mutation. Merge the parent options in the compact action (parent `--agent`/`--json`, with the compact-level option taking precedence) and add regression coverage for parent `--agent`, parent `--json`, and the compact-level override. Refs openclaw#90640.
…nt options Address two ClawSweeper review findings on the `sessions compact` command: - `sessions-compact.ts`: the Codex app-server `thread/compact/start` path returns `ok:true / compacted:false` with a pending marker, meaning the compaction was *started* asynchronously. The formatter collapsed every non-compacted success into "No compaction needed", so Codex users were told nothing happened. Report it as a started/pending compaction instead. - `register.status-health-sessions.ts`: the parent `sessions` command defines list-only options (`--store`/`--all-agents`/`--active`/`--limit`) that the compact action previously ignored. Silently dropping a parent `--store` is dangerous — the gateway resolves the target store itself, so a user could believe they targeted one store while another is mutated. Reject any unsupported inherited parent option with a clear error and a non-zero exit. Add regression tests for the pending-compaction message and the rejected parent options. Refs openclaw#90640.
…ve runs The non-maxLines (LLM) compact branch interrupts an active session run before compacting, but the maxLines truncate branch read the tail, archived, and overwrote the transcript in place without that guard. Exposing `--max-lines` as a documented CLI command (this PR) would make the active-run data-loss mode tracked by openclaw#72765 easy to trigger from ordinary CLI usage. Run the same interruptSessionRunIfActive guard in the maxLines branch before reading the tail and truncating, matching the LLM compact path. Add gateway regression coverage over a real in-process Gateway: with no active run, the maxLines branch truncates the on-disk transcript 500 -> 50 and preserves the original 500 lines in the .bak archive; with an active embedded run, the maxLines branch fires the same interrupt (abort + wait-for-end) before archiving and truncating.
The new "Compact a session" section was inserted between the cleanup section's inline "Related:" list and the page's final "## Related" block, splitting related-link content around the command docs. Move the compact section above the related-links area and merge the orphaned "Session config" link into the single final "## Related" block.
Signed-off-by: sallyom <[email protected]>
Signed-off-by: sallyom <[email protected]>
|
Maintainer verification complete.
Land-ready at |
|
Merged as Maintainer proof before merge:
Closes #90640. |
|
Thanks @sallyom for catching the regression and getting it across the line — appreciate it! 🙏 |
|
Flagging: issue #90640 was closed on 2026-06-19 with this PR listed as the implementation candidate, but the PR is still open and unmerged. From the outside it looks like the issue was closed prematurely — the CLI Not a blocker just wanted to flag in case the premature issue-close caused it to drop off the board. |
Summary
Fixes #90640.
openclaw sessions compact <key>over the existingsessions.compactGateway RPC.agent --message '/compact'fail with a redirect instead of silently running an ordinary turn.sessions --agent/--json; rejects unsupported inherited list options, including--store,--all-agents,--active,--limit, and--verbose.thread/compact/startas pending instead of a no-op.--max-linesrecovery.0600, rollback, and partial-temp cleanup.ok:trueRPC result before the CLI exits successfully.Implementation notes
The Gateway remains the owner of target resolution and active-run interruption. Transcript mutation stays behind
src/config/sessions/session-accessor.ts; it archives the original before installing the normalized replacement and clears stale token metadata only after success.The Codex pending behavior was checked directly against sibling Codex source:
thread/compact/startreturns immediately and completion is reported asynchronously through turn/item notifications.Real behavior proof
Behavior addressed: The production CLI reaches real Gateway compaction, CLI slash-command misuse exits non-zero, Codex pending results render correctly, unsupported inherited options fail before mutation, and manual trimming produces a private transcript that
SessionManagercan reopen without changing the selected branch.Real environment tested: Local Node checkout plus AWS Crabbox Linux lease
cbx_a5289b2e7c04(swift-lobster, c7a.32xlarge). Gateway tests use a real in-process Gateway WebSocket and on-disk session stores/transcripts. Codex tests use the production compact adapter and an on-disk binding.Exact steps or command run after this patch:
Evidence after fix: Crabbox run
run_ccc2ece105cbpassed 239 tests across CLI, Gateway, filesystem, and Codex shards. Final-delta runrun_4e6bfe528bcapassed all 42 accessor reopen/tree tests. The Gateway regression proves canonical 500-line JSONL becomes a reopenable 50-line transcript, the original remains in.bak, and active-run interruption precedes mutation. Type-aware oxlint is clean. Final autoreview is clean with 0.89 confidence after all accepted findings were repaired.Observed result after fix: Successful native trim reports
compacted:true, retains the newest bounded suffix plus the session header, writes mode0600, and reopens with the expected context. An active run that cannot be interrupted leaves the transcript and archive state untouched. Codex returnsok:true / compacted:false / pending:trueand the CLI prints “Compaction started” without treating it as a no-op. Missing or falseokexits 1.What was not tested: No GUI/screenshot path; this is CLI, Gateway, filesystem, and adapter behavior. No live external Codex account call; the exact upstream app-server protocol and request processor were inspected, and the production OpenClaw adapter was exercised with its real disk binding.
Tests
run_ccc2ece105cb: 239 passed.run_4e6bfe528bca: 42 passed on the final transcript-tree delta.