Skip to content

fix(plugins): iterate all providers in wrapProviderStreamFn - #64800

Closed
klin3867 wants to merge 1 commit into
openclaw:mainfrom
klin3867:fix/wrap-stream-fn-iterate-all-providers
Closed

klin3867 wants to merge 1 commit into
openclaw:mainfrom
klin3867:fix/wrap-stream-fn-iterate-all-providers

Conversation

@klin3867

Copy link
Copy Markdown

Summary

  • Problem: wrapProviderStreamFn() only checked a single provider via resolveProviderHookPlugin(). When a built-in provider (e.g. Anthropic) owned the provider ID, external plugins with matching hookAliases could never contribute their own wrapStreamFn.
  • Why it matters: External plugins that want to compose stream transformations (e.g. injecting custom tool types into the API payload) on top of a built-in provider's wrapper are silently ignored.
  • What changed: Applied the same iteration pattern already used by normalizeProviderTransportWithPlugin() and normalizeProviderConfigWithPlugin(): check the primary matched plugin first, then iterate all providers from resolveProviderPluginsForHooks().
  • Scope: Only wrapProviderStreamFn() in src/plugins/provider-runtime.ts. No other functions changed.

Change Type

Bug fix — wrapStreamFn on external plugins with hookAliases is accepted at registration but never called when a built-in provider matches.

Root Cause

wrapProviderStreamFn() called resolveProviderHookPlugin() which returns the first matching provider (typically the built-in). The built-in provider's wrapStreamFn was used exclusively. External plugins registered via hookAliases were discovered by resolveProviderPluginsForHooks() but never consulted for wrapStreamFn.

The pattern for iterating all providers already existed in normalizeProviderTransportWithPlugin() (line 457) and normalizeProviderConfigWithPlugin() (line 486) — wrapProviderStreamFn was the only provider hook that didn't follow it.

Regression Test Plan

Added test: "chains wrapStreamFn from primary provider and hookAlias plugin"

  • Registers two providers: a primary (id: "anthropic") and an external plugin (id: "custom-anthropic", hookAliases: ["anthropic"])
  • Both have wrapStreamFn
  • Verifies the external plugin receives the primary's wrapped stream as ctx.streamFn
  • Verifies the final result is the external plugin's wrapped function

Run: pnpm vitest run src/plugins/provider-runtime.test.ts

Security Impact

  • Auth/credentials: No — does not touch auth flows
  • File system: No
  • Network: No — stream wrapping is in-process function composition
  • User data: No

Human Verification

  • Confirmed test passes locally (18/18 in provider-runtime.test.ts)
  • Confirmed the pattern matches normalizeProviderTransportWithPlugin exactly
  • Confirmed chaining semantics: each subsequent plugin gets the previous wrapper's output as ctx.streamFn

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes wrapProviderStreamFn to chain all matching providers (primary + hookAliases) in the same way normalizeProviderTransportWithPlugin and normalizeProviderConfigWithPlugin already do. Previously, only resolveProviderHookPlugin (first match) was consulted, silently dropping any external plugin's wrapStreamFn when a built-in provider owned the ID.

Confidence Score: 5/5

Safe to merge — focused one-function fix with a targeted regression test and no surface-area expansion.

The change is minimal and consistent with the established normalizeProviderTransportWithPlugin / normalizeProviderConfigWithPlugin pattern. The new test covers the chaining semantics, and no existing tests broke. No security, data, or auth paths are touched.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(plugins): iterate all providers in w..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52d72471a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +644 to +646
for (const candidate of resolveProviderPluginsForHooks(params)) {
if (!candidate.wrapStreamFn || candidate === matchedPlugin) {
continue;

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.

P1 Badge Filter wrapStreamFn candidates to matching providers

wrapProviderStreamFn now iterates resolveProviderPluginsForHooks(params) without checking whether each candidate matches params.provider, so any enabled provider plugin with a wrapStreamFn can wrap every request. This is a behavioral regression from the previous single-owner path and can corrupt non-target providers (for example, extensions/openrouter/stream.ts always applies the OpenRouter thinking wrapper, which mutates payload reasoning fields, even when the active provider is unrelated). Please gate the loop to candidates that match the provider id/aliases before calling their wrapper.

Useful? React with 👍 / 👎.

@klin3867
klin3867 force-pushed the fix/wrap-stream-fn-iterate-all-providers branch from 52d7247 to 8eddeec Compare April 11, 2026 13:50

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8eddeecdea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/plugins/provider-runtime.ts Outdated
// wrap the already-wrapped stream. This enables external plugins to compose
// additional stream transformations on top of the built-in provider's wrapper.
for (const candidate of resolveProviderPluginsForHooks(params)) {
if (!candidate.wrapStreamFn || candidate === matchedPlugin) {

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.

P1 Badge Avoid double-invoking the matched provider stream wrapper

The dedupe guard in wrapProviderStreamFn uses reference equality (candidate === matchedPlugin), but matchedPlugin is resolved through a providerRefs lookup while the loop resolves the full provider list, and each lookup rebuilds provider objects (src/plugins/providers.runtime.ts:216-219), so the same provider is not reference-equal and its wrapStreamFn runs twice for provider-owned requests. This introduces duplicate wrapping (e.g., repeated header/payload mutations) on normal traffic; dedupe should use a stable identity like pluginId + id or a shared candidate list.

Useful? React with 👍 / 👎.

wrapProviderStreamFn() previously only checked a single provider via
resolveProviderHookPlugin(). When a built-in provider (e.g. Anthropic)
owned the provider ID, external plugins with matching hookAliases could
never contribute their own wrapStreamFn.

Apply the same iteration pattern already used by
normalizeProviderTransportWithPlugin() and
normalizeProviderConfigWithPlugin(): check the primary matched plugin
first, then iterate all providers from resolveProviderPluginsForHooks()
to let hookAlias plugins compose additional stream wrappers on top.

This enables external plugins to chain stream transformations (e.g.
injecting custom tool types into the API payload) without replacing the
built-in provider's wrapper.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@klin3867
klin3867 force-pushed the fix/wrap-stream-fn-iterate-all-providers branch from 8eddeec to 63df5c7 Compare April 11, 2026 14:33
@klin3867

Copy link
Copy Markdown
Author

Both P1 issues addressed in the latest push:

  1. Provider filter — Added matchesProviderId(candidate, params.provider) gate so only providers matching the target provider ID or hookAliases are considered. Unrelated providers (e.g. OpenRouter) are skipped.

  2. ID-based dedup — Changed candidate === matchedPlugin to candidate.id === matchedPluginId to handle rebuilt provider objects from separate resolution paths.

Test updated to include an unrelated openrouter provider with wrapStreamFn that verifies it is never called for anthropic requests. 18/18 tests passing.

@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: the provider stream-wrapper composition bug remains source-visible on current main, but this PR is not merge-ready because it targets the pre-split wrapper location, is now conflicting, and only has unit/mock proof.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: current main's active wrapper invokes only the resolved provider plugin wrapper and does not iterate additional matching hookAlias providers. No live external-plugin reproduction was run in this read-only review.

Is this the best way to solve the issue?

No as submitted: the fix idea is plausible, but the PR targets the old file and is now conflicting. The best fix is a current-main port into provider-hook-runtime.ts plus real behavior proof.

Security review:

Security review cleared: The diff changes in-process provider hook composition and a unit test only, with no dependency, workflow, permission, download, or secret-handling changes.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-04-11T12:28:43Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is mock_only and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • vincentkoc: Authored the split that moved provider hook runtime behavior into the current provider-hook-runtime.ts seam. (role: provider hook seam contributor; confidence: high; commits: a7436c8b4a93, e085fa1a3ffd; files: src/plugins/provider-hook-runtime.ts, src/plugins/provider-runtime.ts, src/plugins/provider-runtime.test.ts)
  • steipete: Introduced the provider runtime hook surface, including wrapStreamFn and related tests/types. (role: provider runtime surface contributor; confidence: high; commits: 4a0f72866b4d; files: src/plugins/provider-runtime.ts, src/plugins/types.ts, src/plugins/provider-runtime.test.ts)
  • obviyus: Recently changed targeted provider runtime hook resolution and tests in the same current-main provider hook seam. (role: adjacent provider hook cache contributor; confidence: medium; commits: 354084b1b320; files: src/plugins/provider-hook-runtime.ts, src/plugins/provider-runtime.ts, src/plugins/provider-runtime.test.ts)

Codex review notes: model internal, reasoning high; reviewed against c5afa92c1f8a.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 4, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 4, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 5, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 5, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 2, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 2, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(plugins): iterate all providers in wrapProviderStreamFn This is item 1/1 in the current shard. Shard 8/22.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant