detached 3d031dd

Merge #21: repair dangling tool_use on every request, not just load

Run repairToolUseResultPairs on outbound messages in oneTurn so an
in-process aborted turn (cancel, connection drop, ECONNREFUSED) no
longer leaves a dangling tool_use that gets rejected by Anthropic/OpenAI
on the next request. Pure and idempotent, no-op on valid transcripts.
commit
3d031dde263236f77cdd2cb6a7ac69fbce71d278
author
patriceckhart · · 2026-06-09 10:58 UTC
merge of
f7bf4a9 + b25b860 · diff against the first parent
signature
unsigned
refs
tag: v0.2.22
1 file · +11 -3
M packages/core/agent.go +11 -3
@@ -502,9 +502,17 @@ func (a *Agent) dropLastAssistantMessage() {
502502 // and the assembled assistant message (already appended to the transcript).
503503 func (a *Agent) oneTurn(ctx context.Context, sink func(AgentEvent)) (provider.StopReason, provider.Message, error) {
504504 req := provider.Request{
505- Model: a.Model,
506- System: a.System,
507- Messages: a.Messages(),
505+ Model: a.Model,
506+ System: a.System,
507+ // Repair any dangling tool_use blocks before sending. A turn
508+ // aborted mid-flight (cancel, connection drop, ECONNREFUSED to a
509+ // dev server, etc.) can leave an assistant tool_use with no
510+ // matching tool_result in the live transcript. The load-time
511+ // repair in OpenSession only runs on restart, so without this the
512+ // next in-process request is rejected by providers like Anthropic
513+ // with "tool_use ids were found without tool_result blocks". The
514+ // repair is pure and a no-op on already-valid transcripts.
515+ Messages: repairToolUseResultPairs(a.Messages()),
508516 Tools: a.Tools.Specs(),
509517 Reasoning: a.Reasoning,
510518 }
@@ -502,9 +502,17 @@ func (a *Agent) dropLastAssistantMessage() {
502 // and the assembled assistant message (already appended to the transcript).502 // and the assembled assistant message (already appended to the transcript).
503 func (a *Agent) oneTurn(ctx context.Context, sink func(AgentEvent)) (provider.StopReason, provider.Message, error) {503 func (a *Agent) oneTurn(ctx context.Context, sink func(AgentEvent)) (provider.StopReason, provider.Message, error) {
504 req := provider.Request{504 req := provider.Request{
505- Model: a.Model,505+ Model: a.Model,
506- System: a.System,506+ System: a.System,
507- Messages: a.Messages(),507+ // Repair any dangling tool_use blocks before sending. A turn
508+ // aborted mid-flight (cancel, connection drop, ECONNREFUSED to a
509+ // dev server, etc.) can leave an assistant tool_use with no
510+ // matching tool_result in the live transcript. The load-time
511+ // repair in OpenSession only runs on restart, so without this the
512+ // next in-process request is rejected by providers like Anthropic
513+ // with "tool_use ids were found without tool_result blocks". The
514+ // repair is pure and a no-op on already-valid transcripts.
515+ Messages: repairToolUseResultPairs(a.Messages()),
508 Tools: a.Tools.Specs(),516 Tools: a.Tools.Specs(),
509 Reasoning: a.Reasoning,517 Reasoning: a.Reasoning,
510 }518 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close