Strip OpenAI itemId from persisted AI messages to prevent stale reference errors…
Strip OpenAI itemId from persisted AI messages to prevent stale reference errors but keep encrypted reasoning content (#2468)
## Summary
- Strip `providerOptions.openai.itemId` (and `azure.itemId`) from
persisted AI messages when parsing from DB
- Prevents "Item with id not found" errors when OpenAI expires
server-side stored items and the AI SDK sends `item_reference` payloads
instead of full content
- Adds comprehensive unit tests covering text parts, tool-call parts,
reasoning parts (preserving `reasoningEncryptedContent`), legacy
formats, and mixed provider options
## Test plan
- [x] Unit tests added in `ai_messages_utils.test.ts` covering all
stripping scenarios
- [ ] Verify existing conversations with OpenAI models continue to work
correctly
- [ ] Verify that long conversations no longer produce "Item with id not
found" errors
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2468">
<picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img
src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open with Devin">
</picture>
</a>
<!-- devin-review-badge-end -->
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Prevents "Item with id not found" errors by stripping openai/azure
itemId from persisted message parts during parse, so the SDK always
sends full content. Keeps long conversations stable without losing
content.
- **Bug Fixes**
- Remove itemId under providerOptions/providerMetadata for openai and
azure across text, tool-call, and reasoning parts, including legacy
formats.
- Preserve reasoningEncryptedContent and request encrypted reasoning via
provider options; leave non-openai provider data and string-only
messages unchanged.
- Add unit tests covering stripping, legacy formats, mixed providers,
and no-op cases.
<sup>Written for commit a4c02d52ea9f25139d4b77bf1a2bdb9f663065f7.
Summary will update on new commits.</sup>
<!-- End of auto-generated description by cubic. -->
---------
Co-authored-by:
Will Chen <willchen90@gmail.com>
Co-authored-by:
Claude Opus 4.5 <noreply@anthropic.com>
正在显示
请
注册
或者
登录
后发表评论