Skip to content

fix: resolve citations when model prepends a toolu_ prefix#888

Merged
miurla merged 1 commit into
mainfrom
fix/citation-toolu-prefix-resolution
Jun 11, 2026
Merged

fix: resolve citations when model prepends a toolu_ prefix#888
miurla merged 1 commit into
mainfrom
fix/citation-toolu-prefix-resolution

Conversation

@miurla

@miurla miurla commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

Some models cite search results as [n](#toolu_<id>) even though the search tool's call id has no prefix. The exact-match lookup in processCitations missed these and silently dropped the citation on render.

Changes

  • lib/utils/citation.ts: try an exact toolCallId match first, then fall back to prefix-normalized matching (toolu_ / call_ / search-) on both the cited id and the citation map keys. This also retroactively fixes already-persisted messages.
  • lib/agents/prompts/search-mode-prompts.ts: drop the toolu_ prefix from citation examples and instruct the model not to add any prefix to the toolCallId.
  • lib/utils/__tests__/citation.test.ts: add coverage for prefixed-id resolution and confirm exact matches still take precedence.

Verification

  • bun run test
  • bun lint
  • bun typecheck
  • bun format:check (changed files) ✅
  • bun run build

Some models cite search results as [n](#toolu_<id>) even though the
search tool's call id has no prefix, which broke the exact-match lookup
in processCitations and silently dropped the citation.

- citation.ts: fall back to prefix-normalized matching (toolu_/call_/
  search-) after trying an exact match first
- search-mode-prompts.ts: drop the toolu_ prefix from citation examples
  and tell the model not to add any prefix to the toolCallId
- add tests covering prefixed and exact-match resolution
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
morphic Ready Ready Preview, Comment Jun 11, 2026 7:21am

@miurla miurla merged commit 3a9399b into main Jun 11, 2026
8 checks passed
@miurla miurla deleted the fix/citation-toolu-prefix-resolution branch June 11, 2026 07:24
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.

1 participant