fix: cross-message reasoning dedup to prevent OpenAI rs_* ID poisoning#804
Open
JasonOA888 wants to merge 2 commits into
Open
fix: cross-message reasoning dedup to prevent OpenAI rs_* ID poisoning#804JasonOA888 wants to merge 2 commits into
JasonOA888 wants to merge 2 commits into
Conversation
When a workflow stream is resumed or replayed, entire assistant messages can be duplicated with blank reasoning parts that carry the same rs_* item IDs as earlier messages. OpenAI requires item IDs to be unique across the input history, so these duplicates cause follow-up turns to fail. Add dedupeCrossMessageReasoning() which: - Tracks rs_* item IDs across all messages in order - Removes blank reasoning-only assistant messages whose IDs were already seen in an earlier message (replay artifacts) - Strips individual blank-text reasoning parts from mixed messages while preserving non-blank multi-summary segments - Returns the same array reference when no dedup is needed Integrate into convertMessages as a second pass after the existing per-message dedup (dedupeMessageReasoning). Closes vercel-labs#545 (immediate guardrail portion)
|
@JasonOA888 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
…metadata Add messageIds.length > 0 check to prevent incorrectly dropping reasoning-only assistant messages that lack rs_* item IDs. Co-authored-by: VADE <vade@vercel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #545 (immediate guardrail portion)
When a workflow stream is resumed/replayed, entire assistant messages can be duplicated with blank reasoning parts that carry the same
rs_*item IDs as earlier messages. OpenAI requires item IDs to be unique across input history, so these duplicates cause follow-up turns to fail.Problem
The existing
dedupeMessageReasoningonly deduplicates within a single message. But the replay bug produces cross-message duplicates — a new assistant message containing only blank reasoning parts with IDs that already appeared in a previous message.Changes
dedupe-message-reasoning.tsdedupeCrossMessageReasoning()— processes the full message array and:rs_*item IDs across all messages in orderchat.ts(workflow)convertMessagesnow applies cross-message dedup as a second pass after the existing per-message dedupdedupe-message-reasoning.test.tsTest results
All existing tests continue to pass.
Scope
This PR addresses the immediate guardrail from #545 — preventing poisoned messages from reaching the OpenAI API. The root fix (chunk-index-aware workflow resume with
startIndex) is a larger change that should be handled separately.