fix(runtime): self-heal orphaned tool_result blocks on load + compact#5853
fix(runtime): self-heal orphaned tool_result blocks on load + compact#5853itripn wants to merge 3 commits intozeroclaw-labs:masterfrom
Conversation
|
The commit doesn't seem to be associated with a GitHub account: https://github.com/zeroclaw-labs/zeroclaw/commit/9a8eba4eb7143b42e7c23118de0aafa6ff3761ae.patch Is your |
|
I'm not at a computer to review this, but I definitely want this bug to die. I'll self-assign. Before I review, though: One minor thing: the channel orchestrator patch at line 5600 runs |
|
@WareWolf-MoonWall , could you do a review? This is the bug that refuses to die. |
Run remove_orphaned_tool_messages as the final mutation before pushing to conversation_histories, rather than mid-pipeline. Any future trim or rewrite step inserted into the hydration loop is now automatically covered by the heal guard. Addresses reviewer feedback on zeroclaw-labs#5853: the previous ordering worked, but coupled the heal's correctness to the current shape of the pipeline. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for the review! Addressed in b944428 — moved On the commit-author note: that's my gitconfig email not being linked to the GitHub profile — I'll rebase the trailers once I've added it at https://github.com/settings/emails so the history attributes cleanly. |
|
Heads up: about to force-push this branch to re-author the three commits under a GitHub-linked email. No content changes |
…zeroclaw-labs#5813) Orphaned tool_result messages (whose paired assistant tool_use was lost to compaction or a crash) bricked Signal-channel sessions with repeated Anthropic 400 "unexpected tool_use_id in tool_result blocks" errors. - Load paths (CLI session file + orchestrator channel hydration) now run remove_orphaned_tool_messages so a corrupt persisted session heals instead of requiring manual file deletion. - Compaction's repair pass now delegates to the canonical remove_orphaned_tool_messages instead of a weak adjacency heuristic. - Orphan detection parses the assistant's structured tool_calls array instead of substring-matching content — summaries that preserve the orphan's id in prose no longer fool the check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CI clippy (1.93) flagged clippy::useless_format on a format!() with no interpolation args. Replace with a plain &str literal. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Run remove_orphaned_tool_messages as the final mutation before pushing to conversation_histories, rather than mid-pipeline. Any future trim or rewrite step inserted into the hydration loop is now automatically covered by the heal guard. Addresses reviewer feedback on zeroclaw-labs#5853: the previous ordering worked, but coupled the heal's correctness to the current shape of the pipeline. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
b944428 to
8061121
Compare
Summary
mastertool_resultmessages (whose paired assistanttool_usewas lost to compaction or a crash) bricked Signal-channel sessions with repeated Anthropic 400 "unexpected tool_use_id in tool_result blocks" errors. Users had to manually delete the session file.load_interactive_session_history+ channel orchestrator hydration) now runremove_orphaned_tool_messagesso a corrupt persisted session heals on startup.repair_tool_pairsnow delegates to the canonicalremove_orphaned_tool_messagesrather than a weak "tool adjacent to[CONTEXT SUMMARY]" heuristic — it catches orphans wherever they sit after splice.tool_callsarray instead of substring-matching content. Compaction summaries are instructed to preserve identifiers, so an orphan'stool_call_idcan legitimately appear in summary prose — string matching falsely concluded the orphan was paired.remove_orphaned_tool_messagesfunction; this PR only strengthens it and wires it into the remaining gaps.Closes #5813Validation Evidence (required)
test result: ok. 1607 passed; 0 failed; 1 ignoredzeroclaw-providers::compatible::tests::flatten_system_messages_*and 2 inzeroclaw-channels::orchestrator::tests::build_channel_by_id_*_telegram*— verified they fail on unmodifiedmaster(git stash+ re-run).remove_orphaned_tool_messagesnot being fooled bytool_call_idappearing in[CONTEXT SUMMARY]prose../dev/ci.sh allwas not run end-to-end given the pre-existing failures unrelated to this change.Security & Privacy Impact (required)
NoNoNoNoCompatibility (required)
YesNoRollback (required for
risk: mediumandrisk: high)git revert <sha>— self-healing is additive; reverting restores prior behavior (sessions remain bricked until manual deletion, matching pre-fix state).Removed N orphaned tool message(s) from historywarn-level tracing events (emitted byremove_orphaned_tool_messages). Sudden spike in those after deploy = many sessions needed healing; absence = healthy. Anthropic 400 errors mentioningunexpected tool_use_idshould disappear.🤖 Generated with Claude Code