Fix openRouter streamed citation end offsets overwrite start offsets - #7128
Conversation
🦋 Changeset detectedLatest commit: cf473f8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Important
The PR title and commit claim this is a fix, but the diff only adds the regression test. The one-line implementation fix in OpenRouterLanguageModel.ts is still missing, so the new test fails and CI cannot pass.
Reviewed changes
packages/ai/openrouter/test/OpenRouterLanguageModel.test.ts: added astreamTextregression test that asserts streamed URL citations preserve bothstartIndexandendIndexundermetadata.openrouter.- Confirmed the test reproduces the described bug: the current source emits
{ openrouter: { startIndex: 9 } }instead of{ openrouter: { startIndex: 2, endIndex: 9 } }.
⚠️ Implementation fix is missing
The regression test is correct and well-targeted, but this branch does not yet contain the actual fix. The streaming citation path in packages/ai/openrouter/src/OpenRouterLanguageModel.ts still has the typo at line 1364:
...(Predicate.isNotUndefined(annotation.url_citation.end_index)
? { startIndex: annotation.url_citation.end_index } // should be endIndex
: undefined)The non-streaming path at lines 1099–1104 already uses endIndex correctly, so the fix is a one-line key rename in the streaming branch.
Suggested next steps
- Apply the one-line fix in
OpenRouterLanguageModel.ts(change the duplicatedstartIndexkey toendIndexin the streaming citation block). - Re-run
pnpm test --run packages/ai/openrouter/test/OpenRouterLanguageModel.test.ts -t "preserves streamed citation start and end indexes"to confirm the test passes. - Add a changeset for the runtime fix before merging.
@v0 or keep the SHA fresh with Dependabot | Fix it ➔ | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This incremental review covers the commits pushed since the prior Pullfrog review. The previously missing implementation fix is now present, along with a changeset.
- Fixed the streaming citation key typo in
packages/ai/openrouter/src/OpenRouterLanguageModel.ts: theend_indexvalue is now assigned toendIndexinstead of overwritingstartIndex, matching the non-streaming path. - Added a changeset for
@effect/ai-openrouterdescribing the streamed citation offset fix. - Reformatted the
HttpClientResponse.fromWebcall in the newmakeStreamTestLayerhelper for readability.
Validation run: pnpm --filter @effect/ai-openrouter test --run test/OpenRouterLanguageModel.test.ts, pnpm lint-fix, and pnpm check all passed.
@v0 or keep the SHA fresh with Dependabot | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
The stream output contains metadata.openrouter.startIndex = 9 and no endIndex; non-stream conversion correctly emits startIndex = 2 and endIndex = 9.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
OpenRouter streamed citation end offsets overwrite start offsets
Module:
packages/ai/openrouter/src/OpenRouterLanguageModel.tsAudit ID:
relsem-openrouter-citation-end-indexSeverity / confidence: medium / high
What happens
The stream output contains metadata.openrouter.startIndex = 9 and no endIndex; non-stream conversion correctly emits startIndex = 2 and endIndex = 9.
Why it happens
The end_index conditional creates another startIndex property instead of endIndex; object spread order overwrites the real start value.
Expected behavior
Equivalent citations preserve distinct startIndex and endIndex fields under metadata.openrouter in both modes.
Relevant implementation
These links and excerpts are pinned to audit base
b206fa5d7655c1634c9993410a9203f6616a5ca2.packages/ai/openrouter/src/OpenRouterLanguageModel.ts:1View problematic code at
packages/ai/openrouter/src/OpenRouterLanguageModel.ts:1View exact lines on GitHub
Reproduction
Observed failure: Independently rerun; failed at the intended semantic assertion.
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
Audit provenance
b206fa5d7655c1634c9993410a9203f6616a5ca2b206fa5d7655c1634c9993410a9203f6616a5ca2relsem-openrouter-citation-end-indexCloses EFF-562