Skip to content

Fix openRouter emits cumulative tool-parameter prefixes as deltas - #7132

Merged
tim-smart merged 3 commits into
mainfrom
audit/repro-b206fa5d76-openrouter-cumulative-tool-delta
Aug 8, 2026
Merged

Fix openRouter emits cumulative tool-parameter prefixes as deltas#7132
tim-smart merged 3 commits into
mainfrom
audit/repro-b206fa5d76-openrouter-cumulative-tool-delta

Conversation

@fubhy

@fubhy fubhy commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Emit each OpenRouter tool-call argument fragment as received while separately accumulating the complete JSON for final tool-call decoding.
  • Suppress empty tool-params-delta parts when a continuation chunk carries no arguments.
  • Add regression coverage for multi-chunk tool arguments, including an argument-less continuation chunk.
  • Add a patch changeset for @effect/ai-openrouter.

Validation

  • pnpm test --run packages/ai/openrouter/test
  • pnpm lint
  • pnpm check

Closes EFF-564

@fubhy fubhy added the audit Findings originating from the Effect runtime correctness audit label Aug 7, 2026
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 457824f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@effect/ai-openrouter Patch
effect Patch
@effect/ai-anthropic Patch
@effect/ai-openai Patch
@effect/ai-openai-compat Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node Patch
@effect/platform-node-shared Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/vitest Patch

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

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Aug 7, 2026
@pullfrog

pullfrog Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

no API key found — this repo is configured to use moonshotai/kimi-k2.7-code, which needs MOONSHOT_API_KEY, but the runner has no key for it.

To fix: add the key as a GitHub Actions secret (referenced from your workflow's env: block) or as a Pullfrog secret in the console — or switch this repo to a different model (free models need no key).

Open repo secrets → · Configure model → · Setup docs → · Ask in Discord →

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Rerun failed job ➔View workflow run | via Pullfrog | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Fixed cumulative tool-parameter deltas in OpenRouterLanguageModel.makeStreamResponse: the continuation branch now emits toolCall.function?.arguments ?? "" as the incremental tool-params-delta instead of the accumulated activeToolCall.params.
  • Added a regression test that streams two argument fragments ({"a": and 1}) and asserts the deltas are exactly those fragments, not the accumulated prefixes.
  • Added a patch changeset for @effect/ai-openrouter.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.92 KB 6.92 KB 0.00 KB (0.00%)
batching.ts 9.72 KB 9.72 KB 0.00 KB (0.00%)
brand.ts 6.60 KB 6.60 KB 0.00 KB (0.00%)
cache.ts 10.59 KB 10.59 KB 0.00 KB (0.00%)
config.ts 20.88 KB 20.88 KB 0.00 KB (0.00%)
differ.ts 19.74 KB 19.74 KB 0.00 KB (0.00%)
http-client.ts 21.52 KB 21.52 KB 0.00 KB (0.00%)
logger.ts 10.81 KB 10.81 KB 0.00 KB (0.00%)
metric.ts 8.86 KB 8.86 KB 0.00 KB (0.00%)
optic.ts 6.68 KB 6.68 KB 0.00 KB (0.00%)
pubsub.ts 14.86 KB 14.86 KB 0.00 KB (0.00%)
queue.ts 11.54 KB 11.54 KB 0.00 KB (0.00%)
schedule.ts 10.71 KB 10.71 KB 0.00 KB (0.00%)
schema-class.ts 19.45 KB 19.45 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.32 KB 29.32 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 25.59 KB 25.59 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.52 KB 13.52 KB 0.00 KB (0.00%)
schema-string.ts 11.05 KB 11.05 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.35 KB 15.35 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.48 KB 21.48 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 23.96 KB 23.96 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.70 KB 18.70 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.53 KB 18.53 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.39 KB 18.39 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.16 KB 22.16 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.05 KB 19.05 KB 0.00 KB (0.00%)
schema.ts 18.69 KB 18.69 KB 0.00 KB (0.00%)
stm.ts 12.59 KB 12.59 KB 0.00 KB (0.00%)
stream.ts 9.67 KB 9.67 KB 0.00 KB (0.00%)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes (delta since prior Pullfrog review at 7428eca1d)

  • Extracted argumentsDelta into a single const and re-used it across tool-call start init, params accumulation, and delta emission, moving the tool-params-delta push out of the start/continuation branch into one shared site guarded by argumentsDelta.length > 0.
  • Unified the branch logic so the start and continuation paths converge, eliminating the duplicated activeToolCall.params reads in favor of the incremental argumentsDelta.
  • Extended the regression test with an argument-less continuation chunk (delta: { tool_calls: [{ index: 0 }] }) to verify empty tool-params-delta parts are suppressed; asserts the emitted deltas are exactly ["{\"a\":", "1}"].

The refactor brings OpenRouterLanguageModel.makeStreamResponse into exact alignment with the reference pattern in openai-compat/src/OpenAiLanguageModel.ts:1301, and the added regression chunk proves the empty-delta suppression. All 8 tests in the file pass (pnpm vitest run packages/ai/openrouter/test/OpenRouterLanguageModel.test.ts).

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@tim-smart
tim-smart enabled auto-merge (squash) August 8, 2026 01:14
@tim-smart
tim-smart force-pushed the audit/repro-b206fa5d76-openrouter-cumulative-tool-delta branch from 9d712f4 to 57f965d Compare August 8, 2026 01:18
@tim-smart
tim-smart force-pushed the audit/repro-b206fa5d76-openrouter-cumulative-tool-delta branch from 57f965d to 457824f Compare August 8, 2026 01:20
@tim-smart
tim-smart merged commit 3f01731 into main Aug 8, 2026
18 checks passed
@tim-smart
tim-smart deleted the audit/repro-b206fa5d76-openrouter-cumulative-tool-delta branch August 8, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 audit Findings originating from the Effect runtime correctness audit bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants