Skip to content

Preserve delivered assistant replies in session repair#76420

Merged
clawsweeper[bot] merged 3 commits intoopenclaw:mainfrom
obviyus:fix/session-repair-preserve-assistant-history
May 3, 2026
Merged

Preserve delivered assistant replies in session repair#76420
clawsweeper[bot] merged 3 commits intoopenclaw:mainfrom
obviyus:fix/session-repair-preserve-assistant-history

Conversation

@obviyus
Copy link
Copy Markdown
Contributor

@obviyus obviyus commented May 3, 2026

Summary

  • stop session-file repair from trimming delivered trailing assistant replies
  • keep assistant-prefill handling on outbound payloads, not durable history
  • update regression coverage, transcript hygiene docs, and changelog

Validation

  • OPENCLAW_LOCAL_CHECK=1 OPENCLAW_LOCAL_CHECK_MODE=throttled pnpm check:changed
  • pnpm test src/agents/session-file-repair.test.ts
  • pnpm exec oxfmt --check --threads=1 src/agents/session-file-repair.ts src/agents/session-file-repair.test.ts docs/reference/transcript-hygiene.md CHANGELOG.md
  • git diff --check

Fixes #76329

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels May 3, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 3, 2026

Codex review: passed.

Summary
The PR removes session-file repair's trailing-assistant disk trim, updates regression coverage, clarifies transcript hygiene docs, and adds a changelog entry for the Telegram/WebChat history loss fix.

Reproducibility: yes. Current main has a clear source path: a normal trailing assistant JSONL record is popped by repairSessionFileIfNeeded, and the main-branch test suite asserts that deletion.

Next step before merge
No repair lane is needed; the patch is clean and should proceed through the existing automerge and required-check gates.

Security
Cleared: The diff touches session repair logic, tests, docs, and changelog only; it adds no CI, dependency, secret, package-resolution, or code-execution surface.

Review details

Best possible solution:

Land one branch that preserves delivered assistant replies on disk, keep provider-specific assistant-prefill stripping at the outbound replay boundary, then close the linked bug and supersede the duplicate PR path.

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

Yes. Current main has a clear source path: a normal trailing assistant JSONL record is popped by repairSessionFileIfNeeded, and the main-branch test suite asserts that deletion.

Is this the best way to solve the issue?

Yes. The PR removes only the durable-history trim while retaining malformed-record repair and outbound Anthropic/Gemini prefill stripping, which is the narrowest maintainable boundary for the reported bug.

What I checked:

  • Protected and automerge labels present: Live PR metadata shows the PR is open at head 66c187f with labels maintainer and clawsweeper:automerge, so this is not a cleanup-close item and exact-head gating applies. (66c187fd7648)
  • Current main trims durable assistant replies: Current main parses session JSONL, then pops trailing non-tool assistant entries before rewriting the file, which matches the linked Telegram/WebChat history-loss report. (src/agents/session-file-repair.ts:271, 6a3f5d0b1f35)
  • Current main has regression coverage for the old behavior: The existing test on main expects a normal trailing assistant message to be trimmed and the repaired file to shrink to two JSONL records, confirming the behavior is source-reproducible. (src/agents/session-file-repair.test.ts:315, 6a3f5d0b1f35)
  • PR removes durable trailing-assistant trimming: The PR head removes isTrimmableTrailingAssistantEntry, the pop loop, and trimmedTrailingAssistantMessages from the session repair report, leaving malformed-line, empty-error-assistant, and blank-user repairs intact. (src/agents/session-file-repair.ts:236, 66c187fd7648)
  • PR adds preservation regression tests: The PR head now expects trailing assistant, multiple assistant, tool-call assistant, adjacent assistant, and assistant-only histories to remain byte-identical after repair. (src/agents/session-file-repair.test.ts:315, 66c187fd7648)
  • Outbound provider guard remains separate: Current main still strips trailing assistant prefill turns from outbound replay when Anthropic or Gemini turn validation is active, so removing disk trimming does not remove the strict-provider request guard. (src/agents/pi-embedded-runner/run/attempt.tool-call-normalization.ts:539, 6a3f5d0b1f35)

Likely related people:

  • amknight: Merged fix(agents): trim trailing assistant turns and rewrite blank user messages in session repair #75606 added the disk-level trailing assistant trim and related session-file repair tests that this PR reverses for delivered replies. (role: introduced behavior; confidence: high; commits: 524528944f05, deaa6f656758; files: src/agents/session-file-repair.ts, src/agents/session-file-repair.test.ts, CHANGELOG.md)
  • steipete: Recently changed the same session-repair logging path and previously added the outbound Anthropic assistant-prefill stripping that remains the durable-history-safe provider boundary. (role: recent maintainer; confidence: high; commits: 929df0f5567f, e21c909bd020; files: src/agents/session-file-repair.ts, src/agents/pi-embedded-runner/run/attempt.ts, src/agents/pi-embedded-runner/run/attempt.tool-call-normalization.ts)
  • openperf: Added the earlier empty-assistant Bedrock session-file repair and transcript hygiene docs that this PR deliberately preserves while narrowing durable repairs. (role: adjacent owner; confidence: medium; commits: 930d81aa41d2; files: src/agents/session-file-repair.ts, src/agents/session-file-repair.test.ts, docs/reference/transcript-hygiene.md)

Remaining risk / open question:

Codex review notes: model gpt-5.5, reasoning high; reviewed against 6a3f5d0b1f35.

@obviyus obviyus force-pushed the fix/session-repair-preserve-assistant-history branch from 87ae220 to 7af9c49 Compare May 3, 2026 03:42
@obviyus
Copy link
Copy Markdown
Contributor Author

obviyus commented May 3, 2026

@clawsweeper automerge

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label May 3, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 3, 2026

🦞🦞
ClawSweeper merged this PR after the passing review.

Source: clawsweeper[bot]
Feedback: structured ClawSweeper verdict: pass (sha=66c187fd7648b3daf2b042ddea1a0bf10f254c16)
Merge status: merged by ClawSweeper automerge
Merged at: 2026-05-03T04:04:12Z
Merge commit: e8756d99aef0

What merged:

  • The PR removes session-file repair's trailing-assistant disk trim, updates regression coverage, clarifies transcript hygiene docs, and adds a changelog entry for the Telegram/WebChat history loss fix.
  • Reproducibility: yes. Current main has a clear source path: a normal trailing assistant JSONL record is popped by repairSessionFileIfNeeded, and the main-branch test suite asserts that deletion.

Automerge notes:

  • PR branch already contained follow-up commit before automerge: docs(agents): clarify session repair preservation
  • PR branch already contained follow-up commit before automerge: fix(agents): preserve delivered assistant replies in session repair

The automerge loop is complete.

Automerge progress:

  • 2026-05-03 03:49:37 UTC review queued [`7af9c49d3bad`](https://github.com/openclaw/openclaw/commit/7af9c49d3bad82c1846eb09760c805ddadf285cb) (queued)
  • 2026-05-03 03:50:53 UTC repair queued [`7af9c49d3bad`](https://github.com/openclaw/openclaw/commit/7af9c49d3bad82c1846eb09760c805ddadf285cb) (autonomous) Run: https://github.com/openclaw/clawsweeper/actions/runs/25269174793
  • 2026-05-03 04:00:16 UTC repair completed [`66c187fd7648`](https://github.com/openclaw/openclaw/commit/66c187fd7648b3daf2b042ddea1a0bf10f254c16) (branch updated) in 6m 33s Run: https://github.com/openclaw/clawsweeper/actions/runs/25269174793 initial automerge rebase is delegated to Codex repair
  • 2026-05-03 04:00:16 UTC review queued [`66c187fd7648`](https://github.com/openclaw/openclaw/commit/66c187fd7648b3daf2b042ddea1a0bf10f254c16) (after repair)
  • 2026-05-03 04:03:27 UTC review passed [`66c187fd7648`](https://github.com/openclaw/openclaw/commit/66c187fd7648b3daf2b042ddea1a0bf10f254c16) (structured ClawSweeper verdict: pass (sha=66c187fd7648b3daf2b042ddea1a0bf10f254...)
  • 2026-05-03 04:04:13 UTC merged [`66c187fd7648`](https://github.com/openclaw/openclaw/commit/66c187fd7648b3daf2b042ddea1a0bf10f254c16) (merged by ClawSweeper automerge)

@clawsweeper clawsweeper Bot force-pushed the fix/session-repair-preserve-assistant-history branch from 7af9c49 to 66c187f Compare May 3, 2026 04:00
@clawsweeper clawsweeper Bot merged commit e8756d9 into openclaw:main May 3, 2026
100 of 101 checks passed
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
Summary:
- The PR removes session-file repair's trailing-assistant disk trim, updates regression coverage, clarifies transcript hygiene docs, and adds a changelog entry for the Telegram/WebChat history loss fix.
- Reproducibility: yes. Current main has a clear source path: a normal trailing assistant JSONL record is popped by `repairSessionFileIfNeeded`, and the main-branch test suite asserts that deletion.

Automerge notes:
- PR branch already contained follow-up commit before automerge: docs(agents): clarify session repair preservation
- PR branch already contained follow-up commit before automerge: fix(agents): preserve delivered assistant replies in session repair

Validation:
- ClawSweeper review passed for head 66c187f.
- Required merge gates passed before the squash merge.

Prepared head SHA: 66c187f
Review: openclaw#76420 (comment)

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Summary:
- The PR removes session-file repair's trailing-assistant disk trim, updates regression coverage, clarifies transcript hygiene docs, and adds a changelog entry for the Telegram/WebChat history loss fix.
- Reproducibility: yes. Current main has a clear source path: a normal trailing assistant JSONL record is popped by `repairSessionFileIfNeeded`, and the main-branch test suite asserts that deletion.

Automerge notes:
- PR branch already contained follow-up commit before automerge: docs(agents): clarify session repair preservation
- PR branch already contained follow-up commit before automerge: fix(agents): preserve delivered assistant replies in session repair

Validation:
- ClawSweeper review passed for head 66c187f.
- Required merge gates passed before the squash merge.

Prepared head SHA: 66c187f
Review: openclaw#76420 (comment)

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge docs Improvements or additions to documentation maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram session repair deletes previous assistant response from transcript

1 participant