Skip to content

fix(core): settle malformed tool input on failure - #36477

Merged
kitlangton merged 1 commit into
v2from
tool-input-settle
Jul 12, 2026
Merged

kitlangton merged 1 commit into
v2from
tool-input-settle

Conversation

@kitlangton

@kitlangton kitlangton commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

What

Malformed streamed tool JSON now produces one truthful failure at the point where it occurs. Previously, the malformed call remained unresolved until the next prompt, so the transcript made one provider failure look like two separate failures.

Before

1. The provider returns malformed tool input
The step reports the provider error, but the started tool remains unresolved.

Assistant

Invalid JSON input for tool call echo

2. The user continues the session
The next prompt discovers the stale tool and adds a second, misleading interruption.

You
Continue

Echo failed
Tool execution interrupted: echo

After

1. The malformed call fails with the step
The tool is settled immediately with the original provider error.

Echo failed
Invalid JSON input for tool call echo

Assistant
Invalid JSON input for tool call echo

2. The user continues normally
There is no stale tool left to repair and no delayed interruption appears.

You
Continue

Assistant
...

Fixes #36421

How

  • packages/core/src/session/runner/publish-llm-event.ts flushes partial input, fails only started tools that never reached tool-call, then publishes the terminal step failure.
  • Existing hosted/all unsettled-tool settlement continues through the same event publisher helper.
  • packages/core/test/session-runner.test.ts covers partial malformed input, an InvalidProviderOutput stream failure, durable event ordering, and a later resume with no second repair failure.

Scope

This is limited to started-but-uncalled tool input at the provider failure boundary. It does not redesign general step settlement, running tool execution, or event architecture.

Testing

Red on origin/v2 (02e22770573078e346ccc573c4f784d5dc0054a9)

cd packages/core
bun run test test/session-runner.test.ts -t "settles malformed streamed tool input before the provider failure"

Failed at expect(terminal).toMatchObject(...): received session.step.failed.1 with Invalid JSON input for tool call echo, followed only after resume by session.tool.failed.1 with Tool execution interrupted; expected the tool failure first with the original invalid-output message.

Green

bun run test test/session-runner.test.ts -t "settles malformed streamed tool input before the provider failure"
# 1 pass, 0 fail

bun run test test/session-runner.test.ts
# 121 pass, 0 fail

bun run test test/session-runner-tool-events.test.ts
# 10 pass, 0 fail

bun typecheck
# passed

The push hook also completed the repository Turbo typecheck: 31 successful tasks.

Flow

sequenceDiagram
  participant Provider
  participant Publisher
  participant Store
  Provider->>Publisher: tool-input-start + partial input
  Provider--xPublisher: InvalidProviderOutput
  Publisher->>Store: tool input ended
  Publisher->>Store: tool failed (original provider message)
  Publisher->>Store: step failed
  Note over Store: Later resume finds no unsettled tool
Loading

@kitlangton
kitlangton changed the base branch from dev to v2 July 12, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: malformed tool input remains unresolved until the next prompt

1 participant