Repository navigation
fix(session): repair dangling tool_calls anywhere in journal, not only at end - #69
Merged
Merged
Conversation
ace331
force-pushed
the
fix/repair-dangling-tool-calls-all-assistants
branch
from
July 30, 2026 05:46
575b71e to
93c8477
Compare
ace331
enabled auto-merge (squash)
July 30, 2026 05:47
ace331
force-pushed
the
fix/repair-dangling-tool-calls-all-assistants
branch
from
July 30, 2026 06:51
93c8477 to
2581153
Compare
added 2 commits
July 31, 2026 11:15
…y at end When a crash happens mid-turn (assistant-with-tool_calls persisted but tool results not), and a subsequent restart appends run markers + new user messages via append_run_start, the orphaned assistant is buried in the middle of the journal. repair_dangling_tool_calls only checked the LAST entry, missing it entirely. The conversation then hits HTTP 400 from the LLM API: 'assistant message with tool_calls must be followed by tool messages'. Rewrite repair_dangling_tool_calls to walk every assistant entry with tool_calls, scan forward for matching tool responses (stopping at the next user/system/assistant or run marker), and insert placeholder tool results immediately after each orphaned assistant. Add regression test that reproduces the crash-then-restart scenario and validates placeholder insertion position + API-validity of the resulting entries_to_agent_messages output.
fgclaw01
force-pushed
the
fix/repair-dangling-tool-calls-all-assistants
branch
from
July 31, 2026 03:17
2581153 to
18eab73
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
repair_dangling_tool_callsonly checked the last entry in the journal for dangling tool_calls. When a crash happens mid-turn and a subsequent restart appends run markers + new user messages viaappend_run_start, the orphaned assistant(tool_calls) is buried in the middle of the journal — and the check misses it entirely.The conversation then hits HTTP 400 from the LLM API:
Trigger scenario
append_run_startappendsrun_terminal+ new user + newrun_starteduser → run_started → assistant(tool_calls) → run_terminal → user → run_startedrepair_dangling_tool_callschecks last entry (run_started) → no-opentries_to_agent_messagesfilters out markers → orphaned assistant(tool_calls) sent to API → 💥Fix
Rewrite
repair_dangling_tool_callsto walk every assistant entry with tool_calls:Test
Added
repair_dangling_tool_calls_finds_orphan_after_restart: reproduces the exact crash-then-restart scenario, validates placeholder insertion position, and verifiesentries_to_agent_messagesoutput is API-valid (every assistant tool_call has a matching tool response).All 185 existing session tests pass unchanged.