Skip to content

Fix duplicate assistant tool-call replay - #2312

Merged
steve8708 merged 2 commits into
BuilderIO:mainfrom
CheckPickerUpper:codex/fix-openai-compatible-tool-results
Jul 22, 2026
Merged

steve8708 merged 2 commits into
BuilderIO:mainfrom
CheckPickerUpper:codex/fix-openai-compatible-tool-results

Conversation

@CheckPickerUpper

@CheckPickerUpper CheckPickerUpper commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a replay-history failure where a normalized assistant turn can contain the same tool-call id more than once. The shared agent loop now collapses duplicate assistant tool-call ids before executing tools or persisting the assistant turn for the next model request.

Why

I hit this through PR Visual Recap on a DeepSeek-backed repo. The agent got as far as preparing to write recap-source.json, then DeepSeek rejected the next request with:

Duplicate value for 'tool_call_id' of call_00_... in message[11]

The visible recap error was just recap-source.json was not created, but the source artifact showed the actual provider 400. The bad state is not DeepSeek-specific: any engine path that hands the loop duplicate assistant tool-call ids could execute/replay an invalid assistant turn. Keeping the invariant in runAgentLoop closes that class instead of patching one provider translator.

Testing

  • pnpm --filter @agent-native/core exec vitest --run src/agent/production-agent.spec.ts --testNamePattern "collapses duplicate assistant tool-call ids|executes a streamed tool call|does not carry streamed tool calls"
  • pnpm --filter @agent-native/core exec vitest --run src/agent/engine/translate-ai-sdk.spec.ts
  • pnpm --filter @agent-native/core typecheck
  • git diff --check

@netlify

This comment has been minimized.

@netlify

This comment has been minimized.

@netlify

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Visual recap — skipped

The visual recap job did not run for this pull request. This is informational only and does not block the PR.

Recap skipped for 4d003fd: external fork PR requires a maintainer to apply the recap label to the current head SHA.

@CheckPickerUpper
CheckPickerUpper force-pushed the codex/fix-openai-compatible-tool-results branch from c0f2509 to 3f03997 Compare July 22, 2026 02:39
@CheckPickerUpper CheckPickerUpper changed the title Fix duplicate AI SDK tool-call replay Fix duplicate assistant tool-call replay Jul 22, 2026
builder-io-integration[bot]

This comment was marked as outdated.

@builder-io-integration builder-io-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builder reviewed your changes — looks good ✅

Review Details

Code Review Summary

This incremental review covers the new PR head, which retains the duplicate assistant tool-call ID normalization and regression test and additionally raises the fast-test CI job timeout from 20 to 30 minutes. The core fix still deduplicates assistant tool calls after all streamed/error content is merged and before both tool execution and assistant-history replay.

The approach remains sound for this standard-risk shared-core change. Two independent balanced reviews found no confirmed bugs, compatibility regressions, security issues, or performance/reliability concerns. The regression test verifies that duplicate IDs execute once and that only one call is present in the next model request; the bounded CI timeout increase is reasonable and does not alter product behavior.

Risk assessment: Standard. The previous review had no inline findings, so there were no addressed threads to resolve or duplicate comments to suppress.

🧪 Browser testing: Skipped — PR changes core agent-loop logic, tests, changeset metadata, and CI configuration; it has no user-facing UI impact.

@steve8708

Copy link
Copy Markdown
Contributor

awesome, thanks @CheckPickerUpper!

@steve8708
steve8708 merged commit f0601ec into BuilderIO:main Jul 22, 2026
26 checks passed
steve8708 pushed a commit that referenced this pull request Sep 3, 2026
* Fix duplicate assistant tool-call replay

* Give fast tests enough CI time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants