Skip to content

fix: #24090 preserve assistant tool_calls in openai-compatible replay#24170

Open
supernovae wants to merge 1 commit intoanomalyco:devfrom
supernovae:fix/openai-tool-calls-replay-24090
Open

fix: #24090 preserve assistant tool_calls in openai-compatible replay#24170
supernovae wants to merge 1 commit intoanomalyco:devfrom
supernovae:fix/openai-tool-calls-replay-24090

Conversation

@supernovae
Copy link
Copy Markdown

@supernovae supernovae commented Apr 24, 2026

Issue for this PR

Closes #24090

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This fixes missing assistant tool_calls during OpenAI-compatible history replay.

I added a focused repair in MessageV2.toModelMessagesEffect so when replay contains tool result messages, the nearest preceding assistant message is guaranteed to include matching tool-call entries (rehydrated from recorded session tool parts, including original tool name/input).

I also added a send-time guard in session/llm middleware for OpenAI-compatible models. If tool-call parts are dropped during prompt conversion, the guard restores them from the original model-message source before provider serialization, keeping tool_calls and tool_call_id paired.

Regression coverage was added in:

  • packages/opencode/test/session/message-v2.test.ts
  • packages/opencode/test/session/llm.test.ts

How did you verify your code works?

  • Ran bun --config=./bunfig.test.toml test test/session/llm.test.ts locally (from packages/opencode) and all tests passed, including the new replay pairing case.
  • Attempted bun --config=./bunfig.test.toml test test/session/message-v2.test.ts; this currently fails before test execution due a pre-existing initialization error in src/session/session.ts (ReferenceError: Cannot access 'Assistant' before initialization), not from this diff.

Screenshots / recordings

N/A (non-UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Rehydrate missing assistant tool-call entries when replay history includes tool results, and add a send-time guard so outbound OpenAI-compatible payloads keep `tool_calls` aligned with `tool_call_id` results.

Made-with: Cursor
@github-actions github-actions Bot added needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@supernovae
Copy link
Copy Markdown
Author

#24090

@supernovae supernovae changed the title fix: preserve assistant tool_calls in openai-compatible replay fixes: (24090) preserve assistant tool_calls in openai-compatible replay Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title fixes: (24090) preserve assistant tool_calls in openai-compatible replay doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@supernovae supernovae changed the title fixes: (24090) preserve assistant tool_calls in openai-compatible replay fixes: #24090 preserve assistant tool_calls in openai-compatible replay Apr 24, 2026
@supernovae supernovae changed the title fixes: #24090 preserve assistant tool_calls in openai-compatible replay fix: #24090 preserve assistant tool_calls in openai-compatible replay Apr 24, 2026
@github-actions github-actions Bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Assistant messages in history replay are missing tool_calls field, breaking OpenAI-compatible providers

1 participant