Skip to content

fix(agents): session-less CLI backends forget the conversation until the first compaction - #168244

Merged
obviyus merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/cli-stateless-history-reseed
Oct 17, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
masatohoshino:fix/cli-stateless-history-reseed

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Related: #132758

What Problem This Solves

Fixes: a CLI backend with sessionMode: "none" and reseedFromRawTranscriptWhenUncompacted: true forgets prior turns until the first compaction.

User Impact

User impact: opted-in session-less CLI backends receive the previous user and assistant exchange on ordinary turns. The independent account boundary still prevents recovery under another account; backends without the opt-in and native-session reuse are unchanged. No new configuration, schema, or protocol is introduced.

Why This Change Was Made

src/agents/cli-runner/prepare.ts:1474-1478 previously selected no raw-transcript reseed reason for ordinary stateless turns. src/agents/cli-runner/session-history.ts:682-687 correctly requires an opt-in and a reason before replaying uncompacted durable history, so those turns lost their only continuity.

The fix by @masatohoshino assigns the private stateless reason at the existing preparation owner, after transcript account authorization. The existing history loader still owns bounds, current-turn exclusion, and compacted-summary selection; there is no second replay path. The contributor's commits are preserved. Main was merged once for takeover and once to include the shared CI repair.

The complete change adds 5/removes 2 production lines, adds 47 regression-test lines, and changes one documentation line. The two regression cases cover same-account recovery and changed-account refusal. The issue's separate intermittent sessionMode: "always" observation is not claimed fixed.

Evidence

The same Gateway/CLI fixture E2E was run on frozen main 25933024a1e197fa1a503e84b573a47203fc674f and candidate 0bb3c48750e8316f90563b3290f7a6706dcc78a8. Only the checkout and recorded SHA changed. Each fresh session seeds the invoice fact, then asks for recall; the fixture records the exact backend stdin and answers from the context it actually receives.

Cell Before: 25933024a1e197fa1a503e84b573a47203fc674f After: 0bb3c48750e8316f90563b3290f7a6706dcc78a8
Stateless fresh session 1 831 chars; prior user fact and assistant reply absent; NO_PRIOR_CONTEXT_168244 1311 chars; prior fact and reply present; one history block; BLUE_FOLDER_168244
Stateless fresh session 2 831 chars; prior user fact and assistant reply absent; NO_PRIOR_CONTEXT_168244 1311 chars; prior fact and reply present; one history block; BLUE_FOLDER_168244
Control: sessionMode: "existing", no native handle 1311 chars; prior fact and reply present; BLUE_FOLDER_168244 Unchanged: 1311 chars; prior fact and reply present; BLUE_FOLDER_168244
Direct-input control BLUE_FOLDER_168244 BLUE_FOLDER_168244
Gateway health Initial, after each repeat, and final checks healthy Initial, after each repeat, and final checks healthy; no plugin errors

The final candidate was rebuilt and the complete core E2E repeated after merging main 1acc60d4a153bc0bb637e9ceffd6f22ebfbfc43a, which contains CI repair 4513e9e0963. The merge brought only upstream changes, including an upstream session-history.ts renderer/type simplification; no PR-authored fix changes were added. Because that owner file changed, old E2E results were not substituted for the final-head rerun. pnpm install --frozen-lockfile and the initial build passed; the final-head build also passed. Changed-file oxfmt --check and oxlint passed before the upstream merge. The local focused test command reached passing existing cases but exceeded its command deadline under host saturation; a narrowed run also exceeded its command deadline during worker preparation. Neither is recorded as a passing suite.

Known pre-existing limitation, outside this fix: a separate cell forces a real sessions.compact through a loopback OpenAI-compatible summarizer, then sends another stateless turn. Frozen main 25933024a1e197fa1a503e84b573a47203fc674f fails identically in two fresh sessions: compaction succeeds, then the CLI receives 666 chars, zero history blocks, and answers NO_PRIOR_CONTEXT_168244. The earlier candidate f7e886da31390ac06a83cd0a6fd5e91df1fdbf84 has the same result. An untouched sessionMode: "existing" session recalled after the other session compacted still receives one history block (1450 chars), answers BLUE_FOLDER_168244, and Gateway health remains good. src/agents/cli-runner/history-boundary.ts:303-312,341-352 detects that the summary rewrite's transcript watermark no longer matches the recorded CLI coverage and writes the boundary as unknown. This is tracked separately rather than weakening the account gate in this change. Retained evidence: compaction-triage/168244/after-compaction/baseline-repeat-1/observed.json, baseline-repeat-2/observed.json, and separate-finding.json. No external model provider or real third-party CLI was called.

Final-head CI run 38995442247 is green on 0bb3c48750e8316f90563b3290f7a6706dcc78a8. The earlier CI run 38993251384 hit the inherited mock-exports failure also present on main run 38993173197; the final head includes its upstream repair. Exact-head ClawSweeper review is still pending; re-review requested.

The contributor's earlier account-change proof remains available: before, after.

Merge danger: two-way door; reverting fully restores the prior behavior without a migration. Blast radius is opted-in stateless CLI backends before first compaction. An incorrect change could omit or replay conversation context; the existing account-ownership gate and compacted-history selector remain unchanged.

…the first compaction

An opted-in sessionMode none backend starts every turn as a fresh process, but preparation gave its uncompacted transcript no reseed reason, so the model only saw the current message. Use the independent history boundary as the gate and give session-less turns their own non-auth reason; account changes still refuse history.
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The PR restores bounded conversation history for opted-in session-less CLI backends before their first compaction.

Example: A backend uses sessionMode "none" with reseedFromRawTranscriptWhenUncompacted enabled.

  • Before: After “Remember that the invoice is in the blue folder,” the follow-up receives no prior exchange.
  • After: The follow-up receives the prior user and assistant exchange, while changing credentials withholds that history.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong proof and a focused repair; this intentionally addresses only part of the linked issue.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Final-head Gateway/CLI fixture results exercise stateless follow-up delivery twice and preserve the existing-mode control; inspected built-CLI captures additionally show same-account history reaching actual backend stdin and credential reassignment excluding the previous account’s history. Existing transports retain final-disclosure authority checks.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: An opted-in session-less backend cannot remember the immediately preceding exchange before compaction.
Reason: The repair restores expected continuity using established recovery infrastructure; Related linkage correctly preserves the broader issue.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a current stateless-history failure through the existing owner, with no introduced defect found.

Priority: P1
Reviewed head: 0bb3c48750e8316f90563b3290f7a6706dcc78a8

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI preparation combines the current request with eligible transcript history, then execution checks live history authority before sending input to the backend.

flowchart TD
U[Current user request] --> P[CLI preparation]
T[Session transcript] --> A[Account and coverage checks]
A --> P
P --> H[Bounded history prompt]
H --> E[Execution authority check]
E --> B[CLI backend input]
Loading

Technical review

Best possible solution:

Land the focused stateless repair while keeping the broader report open for intermittent resume and diagnostic behavior.

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

Current-main reason selection and loader gating establish the failure; supplied built-CLI captures and the final-head Gateway results demonstrate the corresponding before-and-after behavior.

Is this the best way to solve the issue?

The change repairs reason selection at its existing owner while preserving opt-in, account authorization, history bounds, and current-turn exclusion.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fe265106c397.

Provenance checked

  • Raw-history opt-in and authentication exclusions keeps the original intent (aeb7d07: Make uncompacted transcript recovery explicit and prevent replay across authentication changes.)
  • Independent transcript account ownership keeps the original intent (e20b56c: Retain account ownership independently of native handles and revalidate recovery reads before execution.)
  • Stateless reseed reason selection changes intended behavior with a stated reason (e32c358: Consolidate reply execution while preserving independent native-session and transcript-history gates.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vito Cappello: Raw commit e20b56c adds src/agents/cli-runner/session-history.ts:51 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e20b56c0b26e; files: src/agents/cli-runner/session-history.ts)

PR surface

Source +3, Tests +47, Docs 0. Total +50 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 5 2 +3
Tests 1 47 0 +47
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 53 3 +50

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +5/-2 lines; tests +47 lines The small owner-level repair is supported by same-account recovery and changed-account refusal cases.

Root-cause cluster

Relationship: partial_overlap
Canonical: #132758
Summary: This PR repairs the canonical report’s stateless-history path; intermittent native resume and diagnostic accuracy remain separate portions.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Ordinary follow-up turns lose conversation context for affected opted-in stateless CLI backends, breaking an established agent workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-10T05:46:50.112Z sha 750c501 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T10:29:28.616Z sha 750c501 :: needs maintainer review before merge. :: none

Reviewed October 16, 2026, 11:39 PM ET / October 17, 2026, 03:39 UTC (Revision 3).

@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@obviyus
obviyus merged commit 53cfc94 into openclaw:main Oct 17, 2026
142 of 152 checks passed
@obviyus

obviyus commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Landed as 53cfc94. Thanks @masatohoshino for the fix.

  • Bug: a CLI backend with sessionMode: "none" and reseedFromRawTranscriptWhenUncompacted: true sent no prior conversation on ordinary turns before the first compaction, so follow-ups lost the previous turn.
  • Fix: ordinary stateless turns now pass a reseed reason, so the existing uncompacted-history gate includes prior turns.
  • Proof: real Gateway + CLI backend: main sent 831 chars with no prior turn (2 fresh sessions); with the fix 1,311 chars with the prior turn and the fact recalled; existing-mode control unchanged. The separate post-compaction case is being fixed in its own PR.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…the first compaction (openclaw#168244)

Related: openclaw#132758

## What Problem This Solves

Fixes: a CLI backend with `sessionMode: "none"` and `reseedFromRawTranscriptWhenUncompacted: true` forgets prior turns until the first compaction.

## User Impact

User impact: opted-in session-less CLI backends receive the previous user and assistant exchange on ordinary turns. The independent account boundary still prevents recovery under another account; backends without the opt-in and native-session reuse are unchanged. No new configuration, schema, or protocol is introduced.

## Why This Change Was Made

`src/agents/cli-runner/prepare.ts:1474-1478` previously selected no raw-transcript reseed reason for ordinary stateless turns. `src/agents/cli-runner/session-history.ts:682-687` correctly requires an opt-in and a reason before replaying uncompacted durable history, so those turns lost their only continuity.

The fix by @masatohoshino assigns the private `stateless` reason at the existing preparation owner, after transcript account authorization. The existing history loader still owns bounds, current-turn exclusion, and compacted-summary selection; there is no second replay path. The contributor's commits are preserved. Main was merged once for takeover and once to include the shared CI repair.

The complete change adds 5/removes 2 production lines, adds 47 regression-test lines, and changes one documentation line. The two regression cases cover same-account recovery and changed-account refusal. The issue's separate intermittent `sessionMode: "always"` observation is not claimed fixed.

## Evidence

The same Gateway/CLI fixture E2E was run on frozen main `964a9ea2957cdb7a6566daf3d927691ad06a8557` and candidate `0bb3c48750e8316f90563b3290f7a6706dcc78a8`. Only the checkout and recorded SHA changed. Each fresh session seeds the invoice fact, then asks for recall; the fixture records the exact backend stdin and answers from the context it actually receives.

| Cell | Before: `964a9ea2957cdb7a6566daf3d927691ad06a8557` | After: `0bb3c48750e8316f90563b3290f7a6706dcc78a8` |
| --- | --- | --- |
| Stateless fresh session 1 | 831 chars; prior user fact and assistant reply absent; `NO_PRIOR_CONTEXT_168244` | 1311 chars; prior fact and reply present; one history block; `BLUE_FOLDER_168244` |
| Stateless fresh session 2 | 831 chars; prior user fact and assistant reply absent; `NO_PRIOR_CONTEXT_168244` | 1311 chars; prior fact and reply present; one history block; `BLUE_FOLDER_168244` |
| Control: `sessionMode: "existing"`, no native handle | 1311 chars; prior fact and reply present; `BLUE_FOLDER_168244` | Unchanged: 1311 chars; prior fact and reply present; `BLUE_FOLDER_168244` |
| Direct-input control | `BLUE_FOLDER_168244` | `BLUE_FOLDER_168244` |
| Gateway health | Initial, after each repeat, and final checks healthy | Initial, after each repeat, and final checks healthy; no plugin errors |

The final candidate was rebuilt and the complete core E2E repeated after merging main `43c4becf48da787f2cff77ffb519c03b0b92fc88`, which contains CI repair `01edef4f3f3`. The merge brought only upstream changes, including an upstream `session-history.ts` renderer/type simplification; no PR-authored fix changes were added. Because that owner file changed, old E2E results were not substituted for the final-head rerun. `pnpm install --frozen-lockfile` and the initial build passed; the final-head build also passed. Changed-file `oxfmt --check` and `oxlint` passed before the upstream merge. The local focused test command reached passing existing cases but exceeded its command deadline under host saturation; a narrowed run also exceeded its command deadline during worker preparation. Neither is recorded as a passing suite.

**Known pre-existing limitation, outside this fix:** a separate cell forces a real `sessions.compact` through a loopback OpenAI-compatible summarizer, then sends another stateless turn. Frozen main `964a9ea2957cdb7a6566daf3d927691ad06a8557` fails identically in two fresh sessions: compaction succeeds, then the CLI receives 666 chars, zero history blocks, and answers `NO_PRIOR_CONTEXT_168244`. The earlier candidate `f7e886da31390ac06a83cd0a6fd5e91df1fdbf84` has the same result. An untouched `sessionMode: "existing"` session recalled after the other session compacted still receives one history block (1450 chars), answers `BLUE_FOLDER_168244`, and Gateway health remains good. `src/agents/cli-runner/history-boundary.ts:303-312,341-352` detects that the summary rewrite's transcript watermark no longer matches the recorded CLI coverage and writes the boundary as unknown. This is tracked separately rather than weakening the account gate in this change. Retained evidence: `compaction-triage/168244/after-compaction/baseline-repeat-1/observed.json`, `baseline-repeat-2/observed.json`, and `separate-finding.json`. No external model provider or real third-party CLI was called.

Final-head [CI run 38995442247](https://github.com/openclaw/openclaw/actions/runs/38995442247) is **green** on `0bb3c48750e8316f90563b3290f7a6706dcc78a8`. The earlier [CI run 38993251384](https://github.com/openclaw/openclaw/actions/runs/38993251384) hit the inherited mock-exports failure also present on [main run 38993173197](https://github.com/openclaw/openclaw/actions/runs/38993173197); the final head includes its upstream repair. Exact-head ClawSweeper review is still pending; [re-review requested](openclaw#168244 (comment)).

The contributor's earlier account-change proof remains available: [before](https://raw.githubusercontent.com/masatohoshino/openclaw/proof-assets/20261009-issue-132758/before.txt), [after](https://raw.githubusercontent.com/masatohoshino/openclaw/proof-assets/20261009-issue-132758/after.txt).

Merge danger: **two-way door**; reverting fully restores the prior behavior without a migration. Blast radius is opted-in stateless CLI backends before first compaction. An incorrect change could omit or replay conversation context; the existing account-ownership gate and compacted-history selector remain unchanged.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 17, 2026
)

Related: #132758

## What Problem This Solves

Fixes fresh CLI turns forgetting the conversation after successful Gateway `sessions.compact`, including stateless `sessionMode: "none"` backends.

## User Impact

The next fresh CLI turn receives the saved compaction summary and retained recent history once, instead of receiving no history. Unknown or mixed-account history remains ineligible for automatic recovery. No configuration or schema migration is required; this does not relabel already-unknown history as trusted.

## Why This Change Was Made

Compaction writes thinking/model bookkeeping before its summary, outside the original CLI writer. The [existing boundary check](https://github.com/openclaw/openclaw/blob/25933024a1e197fa1a503e84b573a47203fc674f/src/agents/cli-runner/history-boundary.ts#L303-L312) then rejects the changed transcript watermark and stores an unknown boundary.

The CLI history owner now captures a fully covered source before compaction and re-anchors its unchanged account provenance after successful same-transcript compaction and maintenance. The commit checks the original session, writer, lifecycle, provenance and current transcript watermark. It preserves the exact admitted storage target, including legacy session-store markers. There is no alternative replay path or relaxation of the account check.

This restores the documented [CLI recovery contract](https://docs.openclaw.ai/gateway/cli-backends#sessions) and [compaction view](https://docs.openclaw.ai/concepts/compaction#how-it-works): a saved summary plus retained recent messages, not a second copy of raw pre-compaction history.

## Evidence

Identical isolated Gateway/CLI E2E cells, with two independent repetitions. The fixture uses a loopback OpenAI-compatible summarizer because the synthetic CLI cannot summarize; no external provider or credentials are involved.

| Check | Before: `25933024a1e197fa1a503e84b573a47203fc674f` | After: `eafef138cc674cc8beaa3f93a3b23cc35b4e7250` |
| --- | --- | --- |
| `sessions.compact` | Successful in both repetitions | Successful in both repetitions |
| Next stateless turn | 666-character prompt, zero history blocks; `NO_PRIOR_CONTEXT_168244` | 1,824-character prompt, one history block; `BLUE_FOLDER_168244` |
| Compacted view | Missing | Complete saved summary once and the service-selected retained assistant turn once; no raw pre-compaction conversation duplicated alongside it |
| Untouched existing-mode control | 1,450 characters, one history block; `BLUE_FOLDER_168244` | Unchanged in both repetitions |
| Uncompacted stateless recall | Covered by #168244 | Both independent sessions recalled `BLUE_FOLDER_168244` in each repetition |
| Gateway health | Healthy | Healthy after both repetitions |

The queued-compaction regression also fails on main `53cfc947f0c6d8c9e2fd8b0a50fb1a5aec89fd17`: a fully covered source stays at sequence 2 instead of the compacted sequence 5. Its foreign-prefix control passes. The candidate's three focused owner suites passed all 49 tests; the five affected regressions passed again after preserving the exact storage-target identity. Direct Oxfmt, Oxlint and whitespace checks passed. The focused tests cover durable and incognito recovery, missing/foreign provenance, writer takeover, cancellation and same-target compaction.

### Authority-chain proof on the exact head

Real isolated Gateway + generic stateless CLI backend, two repetitions per cell, repeated on frozen main `53cfc947f0c6d8c9e2fd8b0a50fb1a5aec89fd17` and candidate `eafef138cc674cc8beaa3f93a3b23cc35b4e7250`. Both build stamps match those SHAs. Each run uses a fresh nonsymlinked state directory, an ephemeral loopback port, synthetic credentials and a loopback-only egress guard.

| Cell | Frozen main (2/2) | Candidate (2/2) |
| --- | --- | --- |
| Account A compacts; its next turn is the positive control | 666-character stdin, no summary/history, `NO_PRIOR_CONTEXT_168244` | 1,824-character stdin, saved summary/history, `BLUE_FOLDER_168244` |
| Same agent/backend/session is explicitly reassigned to account B using `sessions.patch` (`ctri-none/fixture@ctri-none:account-b`) | B gets 666-character stdin with neither A's folder marker nor A's compaction marker | Identical exclusion: no `BLUE_FOLDER_168244`, no `COMPACTED_ONCE_168244`, no history block; `NO_PRIOR_CONTEXT_168244` |
| Live reset/compaction race | Reset queues behind the compaction lifecycle fence, then rotates the lifecycle and clears history provenance | Same ordering; after reset there is no history boundary, no intervening CLI backend call, and the next legitimate turn has neither stale marker |
| Retained re-anchor closure guard — **observation-only, not a user path** | Not applicable: main has no re-anchor closure | After real `sessions.reset`, re-invoking the captured production closure rejects with `queued compaction is no longer active`; zero boundary changes and zero CLI backend calls |

**Live race ordering:** the synthetic summarizer holds the real `sessions.compact` request after the source boundary is captured. A concurrent real `sessions.reset` remains queued while compaction owns its exclusive lifecycle fence. Releasing the summarizer allows compaction to finish; reset then rotates `lifecycleRevision` (it intentionally preserves this explicit `sessionId`) and removes `cliHistoryBoundary`. The next legitimate CLI turn returns `NO_PRIOR_CONTEXT_168244`, as on main. This is serialization evidence, not a claim that reset interleaves with re-anchoring.

**Separate retained-work guard:** an observation-only Node loader retains a reference to the actual production re-anchor closure while returning that same closure unchanged to its normal caller. A fixture-only RPC invokes the retained reference after reset. It fails before any boundary mutation or backend I/O in both repetitions. This is a stale-capability guard check, **not a reproduced user-path race**; no production source or built files were changed. The captured built module's SHA-256 is `b6045a65badfdfebcabe4d9d5cfcadf02e72d37d1651bfcf8b22d668b8844be9`.

<details>
<summary>Redacted backend-input captures and trace locations</summary>

Capture excerpts (synthetic data only; repeated results agree):

```text
Account A, candidate:
Continue this conversation using the OpenClaw transcript below as prior session history.
<conversation_history>
... Compaction summary: ...
The invoice remains in BLUE_FOLDER_168244. COMPACTED_ONCE_168244.
... </conversation_history>
... RECALL_168244: Which folder holds the invoice?
=> BLUE_FOLDER_168244

Account B, both heads (complete 666-character stdin except timestamp):
[Sat 2026-10-17 10:11 GMT+5:30] RECALL_168244: Which folder holds the invoice?

For the current source conversation, reply normally in your final assistant message; OpenClaw will deliver it through the active source conversation.

Commentary is optional progress and may be hidden. Include answers to every still-pending user question, including questions received during ongoing work, in your final response.

OpenClaw runtime context:
## Temporal Context
Current date: 2026-10-17
Time zone: Asia/Calcutta
End OpenClaw runtime context.

Current active computer (latest reported app/system input, not message origin): active_node=unknown active_node_identity=unknown
=> NO_PRIOR_CONTEXT_168244

After reset, retained closure (candidate, both repetitions):
{"retained":true,"rejected":true,"error":"Error: queued compaction is no longer active"}
boundary before retained invocation == boundary after retained invocation == absent
CLI backend calls during compaction/reset/retained invocation: 0
next legitimate CLI turn => NO_PRIOR_CONTEXT_168244
```

Redacted full stdin and ordering traces are preserved under these local proof-relative paths (not public downloads):

- `tmp/cli-history-after-compaction/authority-candidate-final/backend-input.redacted.json`
- `tmp/cli-history-after-compaction/authority-candidate-final/trace.redacted.json`
- `tmp/cli-history-after-compaction/authority-baseline-final/backend-input.redacted.json`
- `tmp/cli-history-after-compaction/authority-baseline-final/trace.redacted.json`
- `tmp/cli-history-after-compaction/authority-evidence.json`

The actual artifact root is the task's isolated handoff directory; paths above deliberately omit workstation identity. No account-isolation leak, stale boundary mutation, or stale CLI backend invocation was observed.

</details>

### Merge danger

Two-way code change using the existing private boundary format. Reverting removes preservation for future compactions without requiring a data migration. The blast radius is CLI history recovery after context-engine compaction; an incorrect boundary could withhold or misattribute context, so source coverage, account provenance and current-writer guards remain mandatory.

Co-authored-by: Ayaan Zaidi <[email protected]>
etzelm added a commit to etzelm/openclaw that referenced this pull request Oct 18, 2026
- prepare.ts: main's comment lines (openclaw#175226, openclaw#168244) kept; the history
  gate stays inline on replayableTarget(cliHistoryWriter) as on the
  branch, so the file does not grow past its line-cap count
- cli-runtime.test.ts: main's rewrite (openclaw#174630); the branch's it.for over
  assertCurrent and assertPrivateInputCurrent and its two private-input
  tests move into it, and createContext takes ClaudeCliExecuteContext
  overrides; cli-runtime.test-harness.ts and
  cli-runtime.private-input.test.ts deleted (the split only kept the old
  file under the line cap)
- history-boundary.test.ts: branch fixture import plus main's
  prepareCliHistoryCompactionBoundary import (openclaw#175090)
- docs/.generated config baseline regenerated with pnpm config:docs:gen
- cli-backends.md: main's opaque-login paragraphs (openclaw#174457) now name the
  attestNativeLogin opt-in
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…claw#175090)

Related: openclaw#132758

## What Problem This Solves

Fixes fresh CLI turns forgetting the conversation after successful Gateway `sessions.compact`, including stateless `sessionMode: "none"` backends.

## User Impact

The next fresh CLI turn receives the saved compaction summary and retained recent history once, instead of receiving no history. Unknown or mixed-account history remains ineligible for automatic recovery. No configuration or schema migration is required; this does not relabel already-unknown history as trusted.

## Why This Change Was Made

Compaction writes thinking/model bookkeeping before its summary, outside the original CLI writer. The [existing boundary check](https://github.com/openclaw/openclaw/blob/964a9ea2957cdb7a6566daf3d927691ad06a8557/src/agents/cli-runner/history-boundary.ts#L303-L312) then rejects the changed transcript watermark and stores an unknown boundary.

The CLI history owner now captures a fully covered source before compaction and re-anchors its unchanged account provenance after successful same-transcript compaction and maintenance. The commit checks the original session, writer, lifecycle, provenance and current transcript watermark. It preserves the exact admitted storage target, including legacy session-store markers. There is no alternative replay path or relaxation of the account check.

This restores the documented [CLI recovery contract](https://docs.openclaw.ai/gateway/cli-backends#sessions) and [compaction view](https://docs.openclaw.ai/concepts/compaction#how-it-works): a saved summary plus retained recent messages, not a second copy of raw pre-compaction history.

## Evidence

Identical isolated Gateway/CLI E2E cells, with two independent repetitions. The fixture uses a loopback OpenAI-compatible summarizer because the synthetic CLI cannot summarize; no external provider or credentials are involved.

| Check | Before: `964a9ea2957cdb7a6566daf3d927691ad06a8557` | After: `eafef138cc674cc8beaa3f93a3b23cc35b4e7250` |
| --- | --- | --- |
| `sessions.compact` | Successful in both repetitions | Successful in both repetitions |
| Next stateless turn | 666-character prompt, zero history blocks; `NO_PRIOR_CONTEXT_168244` | 1,824-character prompt, one history block; `BLUE_FOLDER_168244` |
| Compacted view | Missing | Complete saved summary once and the service-selected retained assistant turn once; no raw pre-compaction conversation duplicated alongside it |
| Untouched existing-mode control | 1,450 characters, one history block; `BLUE_FOLDER_168244` | Unchanged in both repetitions |
| Uncompacted stateless recall | Covered by openclaw#168244 | Both independent sessions recalled `BLUE_FOLDER_168244` in each repetition |
| Gateway health | Healthy | Healthy after both repetitions |

The queued-compaction regression also fails on main `e679d022d16fbd0ceac094ee2ecc582125266b58`: a fully covered source stays at sequence 2 instead of the compacted sequence 5. Its foreign-prefix control passes. The candidate's three focused owner suites passed all 49 tests; the five affected regressions passed again after preserving the exact storage-target identity. Direct Oxfmt, Oxlint and whitespace checks passed. The focused tests cover durable and incognito recovery, missing/foreign provenance, writer takeover, cancellation and same-target compaction.

### Authority-chain proof on the exact head

Real isolated Gateway + generic stateless CLI backend, two repetitions per cell, repeated on frozen main `e679d022d16fbd0ceac094ee2ecc582125266b58` and candidate `eafef138cc674cc8beaa3f93a3b23cc35b4e7250`. Both build stamps match those SHAs. Each run uses a fresh nonsymlinked state directory, an ephemeral loopback port, synthetic credentials and a loopback-only egress guard.

| Cell | Frozen main (2/2) | Candidate (2/2) |
| --- | --- | --- |
| Account A compacts; its next turn is the positive control | 666-character stdin, no summary/history, `NO_PRIOR_CONTEXT_168244` | 1,824-character stdin, saved summary/history, `BLUE_FOLDER_168244` |
| Same agent/backend/session is explicitly reassigned to account B using `sessions.patch` (`ctri-none/fixture@ctri-none:account-b`) | B gets 666-character stdin with neither A's folder marker nor A's compaction marker | Identical exclusion: no `BLUE_FOLDER_168244`, no `COMPACTED_ONCE_168244`, no history block; `NO_PRIOR_CONTEXT_168244` |
| Live reset/compaction race | Reset queues behind the compaction lifecycle fence, then rotates the lifecycle and clears history provenance | Same ordering; after reset there is no history boundary, no intervening CLI backend call, and the next legitimate turn has neither stale marker |
| Retained re-anchor closure guard — **observation-only, not a user path** | Not applicable: main has no re-anchor closure | After real `sessions.reset`, re-invoking the captured production closure rejects with `queued compaction is no longer active`; zero boundary changes and zero CLI backend calls |

**Live race ordering:** the synthetic summarizer holds the real `sessions.compact` request after the source boundary is captured. A concurrent real `sessions.reset` remains queued while compaction owns its exclusive lifecycle fence. Releasing the summarizer allows compaction to finish; reset then rotates `lifecycleRevision` (it intentionally preserves this explicit `sessionId`) and removes `cliHistoryBoundary`. The next legitimate CLI turn returns `NO_PRIOR_CONTEXT_168244`, as on main. This is serialization evidence, not a claim that reset interleaves with re-anchoring.

**Separate retained-work guard:** an observation-only Node loader retains a reference to the actual production re-anchor closure while returning that same closure unchanged to its normal caller. A fixture-only RPC invokes the retained reference after reset. It fails before any boundary mutation or backend I/O in both repetitions. This is a stale-capability guard check, **not a reproduced user-path race**; no production source or built files were changed. The captured built module's SHA-256 is `b6045a65badfdfebcabe4d9d5cfcadf02e72d37d1651bfcf8b22d668b8844be9`.

<details>
<summary>Redacted backend-input captures and trace locations</summary>

Capture excerpts (synthetic data only; repeated results agree):

```text
Account A, candidate:
Continue this conversation using the OpenClaw transcript below as prior session history.
<conversation_history>
... Compaction summary: ...
The invoice remains in BLUE_FOLDER_168244. COMPACTED_ONCE_168244.
... </conversation_history>
... RECALL_168244: Which folder holds the invoice?
=> BLUE_FOLDER_168244

Account B, both heads (complete 666-character stdin except timestamp):
[Sat 2026-10-17 10:11 GMT+5:30] RECALL_168244: Which folder holds the invoice?

For the current source conversation, reply normally in your final assistant message; OpenClaw will deliver it through the active source conversation.

Commentary is optional progress and may be hidden. Include answers to every still-pending user question, including questions received during ongoing work, in your final response.

OpenClaw runtime context:
## Temporal Context
Current date: 2026-10-17
Time zone: Asia/Calcutta
End OpenClaw runtime context.

Current active computer (latest reported app/system input, not message origin): active_node=unknown active_node_identity=unknown
=> NO_PRIOR_CONTEXT_168244

After reset, retained closure (candidate, both repetitions):
{"retained":true,"rejected":true,"error":"Error: queued compaction is no longer active"}
boundary before retained invocation == boundary after retained invocation == absent
CLI backend calls during compaction/reset/retained invocation: 0
next legitimate CLI turn => NO_PRIOR_CONTEXT_168244
```

Redacted full stdin and ordering traces are preserved under these local proof-relative paths (not public downloads):

- `tmp/cli-history-after-compaction/authority-candidate-final/backend-input.redacted.json`
- `tmp/cli-history-after-compaction/authority-candidate-final/trace.redacted.json`
- `tmp/cli-history-after-compaction/authority-baseline-final/backend-input.redacted.json`
- `tmp/cli-history-after-compaction/authority-baseline-final/trace.redacted.json`
- `tmp/cli-history-after-compaction/authority-evidence.json`

The actual artifact root is the task's isolated handoff directory; paths above deliberately omit workstation identity. No account-isolation leak, stale boundary mutation, or stale CLI backend invocation was observed.

</details>

### Merge danger

Two-way code change using the existing private boundary format. Reverting removes preservation for future compactions without requiring a data migration. The blast radius is CLI history recovery after context-engine compaction; an incorrect boundary could withhold or misattribute context, so source coverage, account provenance and current-writer guards remain mandatory.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants