fix(agents): trim trailing assistant turns during session file repair (#75271)#75284
fix(agents): trim trailing assistant turns during session file repair (#75271)#75284hclsys wants to merge 4 commits intoopenclaw:mainfrom
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded. The same user-visible session-repair problem is already covered by merged PR #75606, and current main now trims trailing assistant session entries before replay, preserves tool-call assistant tails, has focused regression coverage, and includes a changelog entry for the linked reports. So I’m closing this here and keeping the remaining discussion on the canonical linked item. Review detailsBest possible solution: Close this PR without merging and keep the merged #75606 implementation as the canonical mainline fix; any further docs refinement can be handled separately if maintainers want the transcript-hygiene page to spell out the on-disk tail trim. Do we have a high-confidence way to reproduce the issue? Yes. A session JSONL ending in a non-tool-call assistant message exercises the repaired path, and current-main tests cover single, multiple, non-trailing, tool-call, and header-only edge cases. Is this the best way to solve the issue? No for landing this branch now. The best path is the already-merged #75606 fix because it supersedes this narrower branch on current main and also covers the paired blank-user transcript rejection report. Security review: Security review cleared: The PR diff only touches session JSONL repair logic, tests, docs, and changelog text; it adds no dependency, workflow, permission, secret, install, release, or package-resolution surface. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 53593f0683fa; fix evidence: commit deaa6f656758, main fix timestamp 2026-05-01T11:24:51Z. |
6e39bbe to
f1bc36c
Compare
…openclaw#75271) Sessions ending on role=assistant are rejected by Anthropic with HTTP 400 "This model does not support assistant message prefill". The repair loop now pops trailing assistant entries from the parsed entry list before rewriting so the file always ends on a user turn (or just the session header). Regression: drops trailing assistant messages on resume so the session can resubmit without a prefill. Mid-transcript assistant entries are unaffected. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…openclaw#75271) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Add a note to the Bedrock Converse section explaining that trailing repaired failed-stream artifacts are dropped (not just repaired) since replaying them as assistant prefill causes provider rejections. Normal completed assistant turns at the end of a session are preserved. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
f1bc36c to
8c3e1ad
Compare
Summary
Fixes #75271.
repairSessionFileIfNeededdid not handle sessions whose JSONL ends on arole=assistantentry. Anthropic (and Anthropic-compatible) APIs reject such transcripts with HTTP 400 "This model does not support assistant message prefill", producing a silent loop with no forward progress.Root cause
Session files can end on an assistant turn when a previous run was interrupted after the assistant response was written but before the next user turn was appended. The existing repair logic handled empty-content assistant entries, blank user messages, and malformed JSON lines — but not the trailing-assistant constraint.
Fix
After parsing all JSONL lines into
entries, pop trailingrole=assistantmessage entries until the last entry is not an assistant message. The trimmed entries are counted asdroppedTrailingAssistantMessagesand included in the repair warn log.Existing repair behaviors are unaffected: mid-transcript assistant entries (followed by at least one later user turn) are not touched.
Pre-implement audit
session-file-repair.ts. ✓repairSessionFileIfNeededhas two call sites (compact.ts:805,attempt.ts:1305) — both use the same{sessionFile, warn}params, no contract change. ✓session-file-repair.tsor the trailing-assistant issue. ✓Tests
"rewrites persisted assistant messages with empty content arrays"→ now a mid-transcript test (poisoned assistant followed by user turn), since a session that ends on assistant should be trimmed."is a no-op on a session that was already repaired"→ healed assistant followed by user turn, confirming no second-pass changes."does not rewrite silent-reply turns"→ mid-transcript variant (followed by user), confirming mid-transcript entries are not dropped."drops trailing assistant turns to prevent Anthropic 400 prefill rejection (#75271)"— single trailing assistant entry dropped, warn message verified."drops multiple consecutive trailing assistant turns"— two consecutive trailing entries both dropped.All 24 tests pass.