Repository navigation
fix(agents): strip trailing assistant messages after sessions_yield artifact removal - #113190
Conversation
93b8170 to
947151b
Compare
947151b to
84df4a2
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
Codex review: needs maintainer review before merge. Reviewed July 25, 2026, 6:19 AM ET / 10:19 UTC. ClawSweeper reviewWhat this changesThis PR extends yielded-session cleanup to remove trailing regular assistant transcript messages and caps the matching persisted-session removals so subagent completion can resume the parent session. Merge readinessKeep this PR open for normal merge review. Current Priority: P1 Review scores
Verification
How this fits togetherThe embedded agent runner turns flowchart TD
A[Parent agent transcript] --> B[sessions_yield]
B --> C[Yield abort cleanup]
C --> D[Live transcript tail]
C --> E[Persisted transcript entries]
D --> F[Subagent completion delivery]
E --> F
F --> G[Parent continuation turn]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +26, Tests +260. Total +286 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Land one focused fix for the canonical deadlock: retain the two-phase live cleanup and count-capped persisted cleanup, with the accompanying regression coverage, rather than merging two competing implementations of the same transcript invariant. Do we have a high-confidence way to reproduce the issue? No direct current-main run was performed in this read-only review, but the failure path is high-confidence from current source plus the production transcript evidence in #109638. Is this the best way to solve the issue? Yes. Repairing the yield-specific transcript cleanup preserves the general continuation role check and is narrower than weakening continuation behavior globally. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against faaab9bd4819. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…eld artifact removal
After sessions_yield, stripSessionsYieldArtifacts removes yield-specific
artifacts (aborted assistant + interrupt custom message) but leaves trailing
regular assistant messages from pre-yield tool work intact. When a subagent
completes and auto-announce tries to inject a continuation turn, the gateway
rejects it because the last visible message role is "assistant", causing a
permanent deadlock (terminal_outcome=blocked).
Changes in attempt.sessions-yield.ts:
- Phase 1 (existing): remove aborted assistant + interrupt custom message
- Phase 2 (new): remove trailing regular assistant messages from pre-yield work
- Persisted cleanup: use count-capped type-checking predicate derived from
active suffix removal count, never exceeding what was removed in-memory
Unlike the competing approach (independent isTrailingAssistant predicate),
the count-capped predicate prevents over-deletion when persisted transcript
state diverges from the active session view.
Tests: attempt.sessions-yield.test.ts (9 new: Phase 1/Phase 2, type guard,
count cap, preserveTrailing, no-op scenarios),
sessions-yield.orchestration.test.ts (9 passed),
attempt-prompt-error.test.ts (4 passed),
attempt-phase-lifecycle.test.ts (3 passed)
Co-Authored-By: Claude <[email protected]>
Fixes openclaw#109638
Fix two CI failures in PR openclaw#113190: 1. check-test-types: Resolve TypeScript errors in test file - TS2352: Use for type conversions - TS18046: Type predicate parameters with RemoveTrailingPredicate - TS2339: Type options parameter with RemoveTrailingOptions 2. check-lint: Apply oxfmt formatting to both files - Reorder imports (type imports first) - Fix multi-line formatting for long expressions Co-Authored-By: Claude <[email protected]>
e928399 to
5ff86bd
Compare
|
Landed via squash onto main.
Thanks @SunnyShu0925! |
* [AI] fix(agents): strip trailing assistant messages after sessions_yield artifact removal * fix(ci): resolve check-lint and check-test-types failures * fix(agents): simplify sessions_yield cleanup (openclaw#113190) * fix(agents): separate sessions_yield cleanup budgets (openclaw#113190) (thanks @SunnyShu0925) --------- Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
After
sessions_yield, the yielded session transcript can end with an assistant role when the agent performed tool work betweensessions_spawnandsessions_yield, causing subagent completion auto-announce to permanently deadlock with "Cannot continue from message role: assistant".stripSessionsYieldArtifacts()removes yield-specific artifacts (aborted assistant + interrupt custom message) but leaves trailing regular assistant messages from pre-yield tool work. When subagent auto-announce callsagentLoopContinue(), the role-continuity check (lastMessage.role === "assistant"at agent-loop.ts:158) throwsTranscriptNotContinuableError, permanently blocking the yielded session.src/agents/embedded-agent-runner/run/attempt.sessions-yield.ts(Phase 2 while-loop + count-capped persisted cleanup),src/agents/embedded-agent-runner/run/attempt.sessions-yield.test.ts(9 new unit tests)agentLoopContinue()role check,subagent-announce-delivery.tslogicChange Type (select all)
Scope (select all)
Linked Issue/PR
Motivation
The current
stripSessionsYieldArtifactsremoves only the yield-specific entries (aborted assistant + interrupt custom message). When the agent called tools between spawn and yield, those pre-yield tool calls generated assistant messages at the end of the transcript. After yield, subagent auto-announce fails becauseagentLoopContinuecheckslastMessage.role === "assistant". This permanently blocks the yielded session until manualsessions_sendintervention.The fix makes the transcript cleanup complete: after removing yield artifacts, also strip trailing regular assistant messages so the transcript ends with a tool_result role that allows continuation injection.
Evidence
Behavior addressed: sessions_yield transcript cleanup leaves trailing regular assistant messages, causing subagent auto-announce deadlock with "Cannot continue from message role: assistant"
Real environment tested: Linux x64 (Co-Claw), Node v22.22.3, Model: zte/Qwen3-235B-A22B, commit 84df4a2eaf1, branch fix/sessions-yield-trailing-assistant-109638, real OpenClaw embedded agent mode
Exact steps or command run after this patch:
Evidence after fix:
E2E yield→subagent→auto-announce (real model, Qwen3-235B-A22B):
Transcript state matrix (before vs after fix):
Unit tests (25 total, no regression):
Persisted cleanup comparison vs PR fix(agents): strip trailing assistant messages after sessions_yield artifact removal #109806:
Observed result after fix:
stopReason=end_turn(no deadlock); subagent curl executes successfullyas anycasts (type-suppression inventory clean)What was not tested: None — the E2E test covers the full spawn→tools→yield→subagent→complete cycle with real model inference
Root Cause
stripSessionsYieldArtifacts()was introduced with only yield-specific artifact removal (aborted assistant + interrupt custom message). It did not account for trailing regular assistant messages generated by pre-yield tool calls. After yield,agentLoopContinue()(agent-loop.ts:158) checkslastMessage.role === "assistant"and throwsTranscriptNotContinuableError.Regression Test Plan
Existing tests cover all non-yield and simple-yield paths. The fix adds no new branches outside the yield handler. All 25 related tests pass.
User-visible / Behavior Changes
Sessions that previously deadlocked after yield→subagent→auto-announce will now complete successfully.
Security Impact
Best-fix Verdict
agentLoopContinuerole check — invariant protects all continuation paths. (2) IndependentisTrailingAssistantpredicate for persisted cleanup — over-deletes when persisted transcript diverges from active view (P1 finding on PR fix(agents): strip trailing assistant messages after sessions_yield artifact removal #109806).AI Assistance
Risks and Mitigations
removedCountentries of removable types only;preserveTrailingprotects custom/label/session_info.Fixes #109638