Skip to content

refactor(providers): shared generated-media download guard and binary-response adoption - #120351

Merged
steipete merged 4 commits into
mainfrom
steipete/loc5-providers-8e4c
Aug 7, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/loc5-providers-8e4c

Conversation

@steipete

@steipete steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Generated video, music, and speech providers repeated the same bounded binary download checks, deadline handling, filename derivation, and payload-patch stream wrappers. The shared binary reader also leaked an unread response body when content-type validation rejected a successful response before body consumption.

Why This Change Was Made

  • Cancel unread bodies when readProviderBinaryResponse rejects text/JSON content, without awaiting cancellation on capture-backed tee streams.
  • Add a generated-video download seam on the local-only media-generation-runtime Plugin SDK surface, while preserving provider-owned guarded acquisition, retry, SSRF/dispatcher policy, and release behavior.
  • Let readProviderBinaryResponse preserve caller-specific overflow messages and migrate the behavior-identical TTS/video/music guards.
  • Replace 13 low-level payload-patch invocations across 10 provider files with createPayloadPatchStreamWrapper.

Exact provider error strings, media filenames, MIME fallbacks, size caps, timeout behavior, retry/provider attribution, and guarded transport cleanup are preserved.

User Impact

Malformed provider binary responses now release their unread socket instead of leaving the connection open. Valid generated-media and stream behavior is unchanged; providers continue to report their existing error messages and enforce their existing caps and transport policies.

Evidence

  • Focused core seams: 27 assertions passed (provider-http-errors, generated video assets, generated music assets).
  • BytePlus/Runway/Together video downloads: 57 assertions passed.
  • Remaining generated-media/TTS providers: 177 assertions passed; the excluded MiniMax file-id path was rerun separately (7 assertions passed).
  • Payload-patch wrapper seam and 10 provider files: 325 assertions passed across 5 Vitest shards.
  • Follow-up MiniMax/helper regression pass: 37 assertions passed.
  • node scripts/run-oxlint.mjs <all touched paths> passed.
  • pnpm plugin-sdk:surface:check passed.
  • pnpm plugin-sdk:api:gen completed; the hash stayed unchanged because media-generation-runtime is a local-only subpath, so no public surface-budget ledger increment applies.
  • node scripts/check-changed.mjs could not acquire any remote backend (Blacksmith doctor failed; Daytona/Azure/AWS doctors timed out). The named local fallback, OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs, passed all core/core-test/extension/extension-test typecheck, lint, SDK, boundary, deadcode, cycle, format, and guard lanes.
  • Final autoreview: clean, no accepted/actionable findings.

Production vs test numstat against the requested base c691f2e41cd61:

  • Production: +514 / -582 (net -68).
  • Tests: +102 / -2 (net +100).
  • Total: +616 / -584 (net +32).

The production reduction is smaller than the research target because exact behavior preservation required retaining guarded acquisition callbacks for MiniMax, xAI, and OpenAI, and excluding non-identical Vydra/Google paths rather than flattening their security/lifecycle contracts.

Migration counts:

  • Socket leak: 1/1 fixed with focused cancellation proof.
  • Generated-media helper: 7/8 named sites migrated (6 video + MiniMax music); Vydra skipped because its three-kind owner preserves same-origin credential forwarding and absolute-deadline error precedence.
  • Guarded binary blocks: 8/9 migrated or absorbed; Google skipped because it currently accepts text/JSON and empty 2xx bodies and has distinct chunk-idle semantics.
  • Payload-patch wrappers: 10/10 files, 13/13 low-level calls migrated.

Premise mismatches / explicit exclusions:

  • The “10 sites” stream list contains 13 low-level invocations (Ollama, Bedrock, and Anthropic each have two).
  • Vydra is not character-identical at the acquisition/timeout boundary and remains on its existing three-kind owner.
  • Google is not currently a guarded-binary block: adopting the shared reader would add content-type and non-empty rejection beyond the requested behavior.
  • OpenRouter retains its overflow-to-deliveryUrl fallback; MiniMax’s two-hop file-id flow and fal remain excluded as requested.
  • This checkout does not contain scripts/committer; commits used the allowed git commit --no-verify fallback after focused proof and autoreview.

Intentional behavior fixes

  • Before: readProviderBinaryResponse threw on a text/JSON success response without cancelling the unread body, which could leave the underlying socket open.
  • After: it fire-and-forget cancels the unread body, preserving the same thrown error while avoiding tee-stream cancellation deadlock.

@clawsweeper

clawsweeper Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 7, 2026, 5:54 PM ET / 21:54 UTC.

ClawSweeper review

What this changes

The branch centralizes generated-media download handling and stream payload patching, and cancels unread binary response bodies rejected by content-type validation.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review: current main does not contain this refactor, and source review found no concrete patch defect. The protected maintainer label prevents automated cleanup.

Priority: P2
Reviewed head: e488a14543f6c5935d92d4cb80b10cddb57f3cd6
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A well-scoped provider refactor with focused regression coverage and no confirmed correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies the author as a member, so the external-contributor real-behavior-proof gate does not apply; the PR body and CI provide focused regression evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies the author as a member, so the external-contributor real-behavior-proof gate does not apply; the PR body and CI provide focused regression evidence.
Evidence reviewed 5 items Rejected-body cleanup: The shared binary reader cancels text/JSON responses before rethrowing, avoiding an unread body while deliberately not awaiting tee-stream cancellation.
Shared media owner boundary: The video helper centralizes only deadlines, bounds, metadata, and cleanup; provider callbacks retain guarded fetch, retry, dispatcher, and SSRF policy.
Existing stream seam: The payload-patch wrapper predates this PR, so the extension changes adopt an established seam rather than introduce a new plugin API.
Findings None None.
Security None None.

How this fits together

Provider plugins fetch generated media and stream model requests through Plugin SDK seams. Those seams preserve provider-owned transport policy while returning bounded media assets or patched model streams to the agent runtime.

flowchart LR
A[Provider plugin] --> B[Plugin SDK seam]
B --> C[Guarded download or payload wrapper]
C --> D[Provider transport]
D --> E[Bounded response reader]
E --> F[Media asset or model stream]
Loading

Decision needed

Question Recommendation
Do the latest ClawSweeper Rank-up moves apply to head e488a14, and are they satisfied or explicitly waived before merge? Verify prior review moves: Read the latest ClawSweeper comment against this exact head and merge only after every applicable move is satisfied or explicitly waived.

Why: The existing ClawSweeper comment is known to exist but its body was unavailable in this review context, so its merge gate cannot be reconstructed safely.

Before merge

  • Resolve merge risk (P1) - The latest ClawSweeper comment was filtered from the supplied context, so its Rank-up moves must be checked against the exact head before landing.
  • Complete next step (P2) - No repair dispatch is needed; protected maintainer handling must verify the prior ClawSweeper merge gate on the exact head.
Agent review details

Security

None.

PR surface

Source -68, Tests +100. Total +32 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 25 514 582 -68
Tests 3 102 2 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 28 616 584 +32

Review metrics

Metric Value Why it matters
Production versus test delta production -68 net, tests +100 net The refactor removes repeated provider logic while adding focused regression coverage for the new shared seams.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/deepinfra/cache-wrapper.ts, vector/embedding metadata: src/media-generation/provider-assets.test.ts, vector/embedding metadata: src/media-generation/provider-assets.ts, vector/embedding metadata: src/music-generation/provider-assets.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the canonical shared seams after confirming the prior ClawSweeper rank-up moves are satisfied or explicitly waived, while retaining provider-owned guarded acquisition paths.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the canonical shared seams after confirming the prior ClawSweeper rank-up moves are satisfied or explicitly waived, while retaining provider-owned guarded acquisition paths.

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

No live provider reproduction was run in this read-only review; source and focused tests establish the rejected-content path and the intended cancellation behavior.

Is this the best way to solve the issue?

Yes: keeping guarded fetch, retry, and dispatcher policy in each provider while centralizing behaviorally identical response consumption is the narrowest maintainable boundary.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The PR changes bounded provider download and stream-wrapper behavior across multiple extensions, but review found no confirmed user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a member, so the external-contributor real-behavior-proof gate does not apply; the PR body and CI provide focused regression evidence.

Label justifications:

  • P2: The PR changes bounded provider download and stream-wrapper behavior across multiple extensions, but review found no confirmed user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a member, so the external-contributor real-behavior-proof gate does not apply; the PR body and CI provide focused regression evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the pre-existing shared payload helper and all commits on this provider refactor. (role: introduced shared helper and recent area contributor; confidence: high; commits: 74500f334ed1, 4bcbeb939436, 65e42b1063e9; files: src/agents/provider-http-errors.ts, src/plugin-sdk/provider-stream-shared.ts, src/media-generation/provider-assets.ts)
  • Vincent Koc: History identifies this contributor on the bounded music-download contract now being generalized. (role: adjacent provider-media contributor; confidence: medium; commits: 036298fba; files: src/music-generation/provider-assets.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Check the latest ClawSweeper comment’s Rank-up moves against the exact head before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit bc0c3fc into main Aug 7, 2026
191 checks passed
@steipete
steipete deleted the steipete/loc5-providers-8e4c branch August 7, 2026 22:45
@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 8, 2026
…-response adoption (openclaw#120351)

* fix(agents): cancel rejected provider binary bodies

* refactor(providers): share generated media downloads

* refactor(providers): adopt payload patch stream wrapper

* fix(providers): preserve generated media helper contracts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant