Skip to content

fix(provider): backfill Name in pairToolResults for existing tool res…#5353

Merged
SivanCola merged 2 commits into
esengine:main-v2from
liugh-dev:fix/backfill-tool-result-name
Jun 27, 2026
Merged

fix(provider): backfill Name in pairToolResults for existing tool res…#5353
SivanCola merged 2 commits into
esengine:main-v2from
liugh-dev:fix/backfill-tool-result-name

Conversation

@liugh-dev

@liugh-dev liugh-dev commented Jun 26, 2026

Copy link
Copy Markdown

Summary

pairToolResults already set Name on backfilled new tool results, but left it empty when reusing an existing result. If a saved session carried a tool message without Name, SanitizeToolPairing would not repair it, and DeepSeek's API rejects tool-role messages with a missing name field (HTTP 400). GLM's endpoint does not validate this, so the bug only surfaced after switching providers.

This PR now sets r.Name = tc.Name on both the id-matched and positional result reuse paths, matching the placeholder backfill behavior. A follow-up fix also treats tool results whose Name does not match the paired tool call as malformed in the fast path, so the repair path actually runs for saved sessions with missing tool-result names.

Verification

  • go test ./internal/provider -run TestSanitizeToolPairingBackfillsMissingToolResultName -count=1
  • go test ./internal/provider/... -count=1
  • go test ./...

Cache impact

Cache-impact: low - only malformed histories with missing or mismatched tool-result names are rewritten immediately before provider sends; stable system prompts, tool schemas, tool order, and healthy session prefixes stay unchanged. Affected old sessions may get a one-time provider-visible message repair so DeepSeek receives the required name field instead of returning HTTP 400.
Cache-guard: TestSanitizeToolPairingBackfillsMissingToolResultName plus go test ./internal/provider/... -count=1 verify the malformed-history repair path and provider package behavior.
System-prompt-review: N/A - no system prompt, memory prefix, output style, or skill index behavior changed.

Authorship note

@liugh-dev is the primary author of this PR. @SivanCola contributed as a collaborator by reviewing the provider fast path, adding the follow-up regression fix, and verifying the final state.

…ults

pairToolResults already set Name on backfill (new) tool results but
left it empty when reusing an existing result.  If a saved session
carried a tool message without Name, SanitizeToolPairing would not
repair it, and DeepSeek's API rejects tool-role messages with a
missing 'name' field (HTTP 400).  GLM's endpoint does not validate
this, so the bug only surfaced after switching.

Now set r.Name = tc.Name on both the id-matched and positional
paths, matching the backfill behaviour.
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development provider Model providers & selection (internal/provider) labels Jun 26, 2026
Treat a tool result whose name does not match its paired tool call as malformed so SanitizeToolPairing takes the slow path and backfills the name before provider serialization.

Add regression coverage for saved sessions that carried a tool result with an empty name.

Co-authored-by: SivanCola <32437197+SivanCola@users.noreply.github.com>
@SivanCola

Copy link
Copy Markdown
Collaborator

Pushed follow-up commit 009017e.

What changed:

  • toolTurnWellFormed now treats missing or mismatched tool-result names as malformed, so SanitizeToolPairing takes the repair path instead of fast-pathing the bad history.
  • Added regression coverage for saved sessions with an empty tool-result Name.

Verified:

  • go test ./internal/provider -run TestSanitizeToolPairingBackfillsMissingToolResultName -count=1
  • go test ./internal/provider/... -count=1
  • go test ./...

@SivanCola SivanCola merged commit c9df209 into esengine:main-v2 Jun 27, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

provider Model providers & selection (internal/provider) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants