Repository navigation
fix(agents): strip trailing assistant messages after sessions_yield artifact removal - #109806
kagura-chen wants to merge 4 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 19, 2026, 1:19 AM ET / 05:19 UTC. Summary PR surface: Source +9, Tests +69. Total +78 across 2 files. Reproducibility: no. high-confidence live reproduction is attached to this PR. The divergent-state failure mode is source-reproducible by making persisted transcript state contain a trailing assistant entry that is absent from Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review findings
Review detailsBest possible solution: Derive the persisted deletions from the exact active-session suffix removed by yield cleanup, add a divergent active-versus-persisted transcript regression test, then attach redacted evidence of a real yield-to-auto-announce completion cycle. Do we have a high-confidence way to reproduce the issue? No high-confidence live reproduction is attached to this PR. The divergent-state failure mode is source-reproducible by making persisted transcript state contain a trailing assistant entry that is absent from Is this the best way to solve the issue? No. Stripping the active suffix is a plausible repair, but applying an independent broad assistant predicate to persisted state is not the narrowest safe solution when the two transcript views can diverge. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2f7da3057c05. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +9, Tests +69. Total +78 across 2 files. View PR surface stats
Acceptance criteria:
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
Review history (6 earlier review cycles)
|
29283f0 to
60bdda4
Compare
|
The Evidence:
Rebased to latest |
|
Addressed the review feedback in 845ba0c: Both trailing-assistant cleanup paths are now exercised:
All 12 tests pass locally (Vitest 4.1.9). For live behavior proof: this fix is running in production on my own OpenClaw instance and sessions_yield → auto-announce cycles complete successfully (the original deadlock no longer reproduces). Happy to provide redacted logs if needed. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…rtifacts (openclaw#109638) After removing aborted assistants and yield interrupt customs, a second pass now strips any remaining trailing assistant messages so auto-announce continuation delivery does not fail with 'Cannot continue from message role: assistant'. Co-Authored-By: Claude <[email protected]>
…w#109638) Address ClawSweeper review feedback: - Add regular assistant messages before yield artifacts so the second while loop (trailing assistant stripping) actually executes - Add sessionManager.removeTrailingEntries mock test covering the persisted cleanup predicate and preserveTrailing options - Verify the predicate correctly matches aborted assistants, yield interrupt custom messages, and trailing regular assistants
845ba0c to
04e87a2
Compare
|
Rebased onto latest upstream/main to pick up recent CI fixes. Previous failures in |
|
Friendly check-in — this PR has been waiting 9 days since I addressed the review feedback and rebased onto latest main (845ba0c). All CI checks pass and it's mergeable. Happy to make any further adjustments if needed! |
|
Thank you for investigating and contributing this fix. The exact sessions_yield continuation deadlock tracked in #109638 has since been fixed on main by merged #113190 (commit eeeae78). The canonical implementation in src/agents/embedded-agent-runner/run/attempt.sessions-yield.ts removes the complete interrupt/assistant suffix and, importantly, caps persisted assistant removal to the entries actually removed from the active session. The landed src/agents/embedded-agent-runner/run/attempt.sessions-yield.test.ts covers the original continuation failure, already-settled assistant tails, divergent persisted state, interrupt markers, and preserved transcript metadata. That encompasses the behavior and regression coverage proposed here while avoiding persisted-history over-deletion. Closing as superseded by the already-merged fix; the original report and contribution were valid and are appreciated. |
Summary
Fixes #109638.
After
sessions_yield,stripSessionsYieldArtifacts()removes aborted assistant messages and yield interrupt custom messages, but leaves trailing regular assistant messages (from pre-yield tool work) intact. When a sub-agent completes and auto-announce tries to inject a continuation message, it fails because the last visible message is an assistant — causing a deadlock.Changes
src/agents/embedded-agent-runner/run/attempt.sessions-yield.ts: Added a second while-loop pass instripSessionsYieldArtifacts()that strips any trailing regular assistant messages remaining after the yield-specific artifacts are removed. UpdatedremoveTrailingEntriespredicate to match.src/agents/embedded-agent-runner/sessions-yield.orchestration.test.ts: Added regression test verifying that after stripping a transcript with pre-yield tool work, the last message is atool_result(not an assistant).Why this is safe
stripSessionsYieldArtifactsis only called inside the yield abort handler (afterwaitForSessionsYieldAbortSettle). It never runs on non-yield sessions. Trailing assistant messages in the yield context are always intermediate tool-calling work — not meaningful final responses.Real behavior proof
Behavior or issue addressed: After sessions_yield, auto-announce continuation delivery fails with role-continuity error because trailing assistant messages block injection.
Real environment tested: Linux x64, Node v24.18.0, vitest
Exact steps or command run after this patch:
npx vitest run src/agents/embedded-agent-runner/sessions-yield.orchestration.test.ts -t "trailing assistant" --reporter=verboseEvidence after fix: Test passes in both shards (agents-core 55ms, agents-embedded-agent 43ms). Last message after stripping is confirmed to be tool_result role.
Observed result after fix: 2 test files passed, 2 tests passed, 8 skipped (non-matching filter).
What was not tested: Full end-to-end yield→announce flow (requires live sub-agent spawn + completion cycle, covered by integration environment).