Skip to content

fix(agents): preserve trailing assistant session history#76280

Open
jalehman wants to merge 2 commits intoopenclaw:mainfrom
jalehman:trailingtrimfix-d0115041-fix-session-trim-regression
Open

fix(agents): preserve trailing assistant session history#76280
jalehman wants to merge 2 commits intoopenclaw:mainfrom
jalehman:trailingtrimfix-d0115041-fix-session-trim-regression

Conversation

@jalehman
Copy link
Copy Markdown
Contributor

@jalehman jalehman commented May 2, 2026

What

Preserves delivered assistant final replies in session JSONL repair instead of trimming every plain trailing assistant message from disk.

Why

The 2026.5.2 session repair path was trimming healthy assistant finals before subsequent runs. In live Telegram/heartbeat sessions this repeatedly erased valid replies like HEARTBEAT_OK and status responses, producing noisy repair warnings and losing transcript history.

Changes

  • Remove disk-level assistant-final trimming
  • Preserve normal assistant history
  • Keep outbound provider replay guards covered
  • Update session repair regression tests

Testing

  • pnpm test src/agents/session-file-repair.test.ts src/agents/pi-embedded-runner/run/attempt.test.ts
  • git diff --check
  • Live gateway smoke: no new session file repaired: trimmed ... trailing assistant logs after running on this commit and sending turns

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels May 2, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 2, 2026

Codex review: needs maintainer review before merge.

Summary
The PR removes session-file repair's disk-level trailing assistant trimming, updates regression tests to preserve assistant final replies, and adds a changelog entry.

Reproducibility: yes. Current main can be reproduced statically with a JSONL session ending in a plain assistant message: repairSessionFileIfNeeded pops that entry, and the PR adds focused tests for HEARTBEAT_OK and consecutive trailing assistant finals staying unchanged.

Next step before merge
The PR has a protected maintainer label and needs maintainer review/rebase handling rather than an automated repair lane.

Security
Cleared: The diff only touches session repair logic, tests, and changelog text; it does not change CI, dependencies, secrets, package resolution, or other supply-chain surfaces.

Review details

Best possible solution:

Keep normal assistant final replies in stored session history while preserving provider-specific outbound prefill stripping; land after maintainer review and a rebase/merge that keeps the current debug logging behavior.

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

Yes. Current main can be reproduced statically with a JSONL session ending in a plain assistant message: repairSessionFileIfNeeded pops that entry, and the PR adds focused tests for HEARTBEAT_OK and consecutive trailing assistant finals staying unchanged.

Is this the best way to solve the issue?

Yes, directionally. Removing persistent disk trimming is the narrowest fix for transcript history loss because current main already has outbound Anthropic/Gemini prefill stripping at the stream boundary; the final branch should preserve the newer debug logging change.

What I checked:

Likely related people:

  • amknight: Merged fix(agents): trim trailing assistant turns and rewrite blank user messages in session repair #75606 introduced the disk-level trailing assistant trim and blank-user rewrite in the central session-file repair path. (role: introduced behavior; confidence: high; commits: 524528944f05; files: src/agents/session-file-repair.ts, src/agents/session-file-repair.test.ts, CHANGELOG.md)
  • steipete: Recently changed the same session repair logging surface and has adjacent replay-history maintenance commits in the agents area. (role: recent maintainer; confidence: high; commits: 929df0f5567f, d80a8eb3adb6, c5c08c074a44; files: src/agents/session-file-repair.ts, src/agents/session-file-repair.test.ts, src/agents/pi-embedded-runner/replay-history.ts)
  • openperf: Added the earlier empty-assistant Bedrock session repair behavior that this file still preserves. (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)
  • shakkernerd: Earlier session-file repair hardening and malformed session repair work appear in the history for this module. (role: feature-history maintainer; confidence: medium; commits: e6fdac7bfb6d, 0da6de6624a9; files: src/agents/session-file-repair.ts)

Remaining risk / open question:

  • This read-only review did not run the PR's tests; validation here is static plus the PR author's reported targeted test and live gateway smoke.
  • The branch predates current main's 929df0f session-repair debug logging change, so a maintainer should ensure the final merge preserves debug-level success logging while removing only disk-level assistant-final trimming.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7f83ba8ddf84.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant