Skip to content

fix(media): release rejected BytePlus and Runway video downloads under debug capture - #119257

Merged
Takhoffman merged 1 commit into
openclaw:mainfrom
Yigtwxx:fix/video-download-tee-cancel-parity
Aug 4, 2026
Merged

Takhoffman merged 1 commit into
openclaw:mainfrom
Yigtwxx:fix/video-download-tee-cancel-parity

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users generating video with BytePlus or Runway while the debug proxy is enabled would see the generation hang instead of failing, when the provider returns a successful HTTP 200 whose body is not video (a JSON error page, an HTML sign-in page) and that body does not finish arriving.

The download never returns, so the request sits pending until the surrounding timeout fires, and the user never sees the malformed video response error the provider already knows how to raise.

Why This Change Was Made

OPENCLAW_DEBUG_PROXY_ENABLED installs a global-fetch patch that clones every captured response (src/proxy-capture/runtime.ts:292-320, :51). A clone tees the body, and the repo already documents the consequence at src/proxy-capture/runtime.ts:41-46:

cancelling such a branch never settles (it only resolves once BOTH branches cancel)

Both providers resolve their download fetchFn to the global fetch (extensions/byteplus/video-generation-provider.ts:281, extensions/runway/video-generation-provider.ts:394), so under capture the response they hold is exactly such a branch — and both await its cancellation when the binary check rejects. The capture branch is read concurrently and captureHttpExchange is not awaited, so while that read is still in flight nothing releases the awaited cancel.

This switches the two rejected-download paths to the fire-and-forget release used by the other generated-media owners, matching the decision already merged for the Ollama setup path in #111802 (extensions/ollama/src/setup.ts:147). Scope is deliberately limited to these two call sites; the surrounding validation, error wording, and byte caps are untouched.

User Impact

With the debug proxy on, a malformed BytePlus or Runway video download now fails immediately with the existing ... generated video download: malformed video response error instead of hanging until a timeout. With the proxy off, behavior is unchanged — the socket is still released, just without waiting on it.

Evidence

The mechanism, measured with a control arm (node v22.20.0, plain web streams):

control (no clone)                : settled
teed, sibling live (await cancel) : PENDING
teed, both branches cancel        : settled

Only the teed-with-live-sibling arm fails to settle, which is the shape the capture clone produces.

Regression tests. One per provider, each building a real Response, cloning it as the debug proxy does, leaving the capture branch mid-read, then racing the download against a 500 ms deadline:

extensions/byteplus/video-generation-provider.test.ts
  ✓ releases a rejected download body without awaiting a debug-capture tee branch
extensions/runway/video-generation-provider.test.ts
  ✓ releases a rejected download body without awaiting a debug-capture tee branch

Test Files  2 passed (2)
     Tests  35 passed (35)

Mutation control. Reverting only the two production lines and re-running the same suites fails exactly the two new tests and nothing else, at the deadline rather than on the assertion:

× releases a rejected download body without awaiting a debug-capture tee branch 510ms
  Received: "BytePlus download waited for a captured response clone"
× releases a rejected download body without awaiting a debug-capture tee branch 521ms
  Received: "Runway download waited for a captured response clone"

Test Files  2 failed (2)
     Tests  2 failed | 33 passed (35)

The pre-existing cancels the unread response body when a generated-video MIME type is rejected tests pass either way — their stubbed cancel resolves immediately, so they cannot see this — which is why the new coverage builds a real tee.

Gates. oxfmt --check clean on the four files, oxlint clean on both extensions, check-max-lines-ratchet OK, and tsgo --noEmit reports nothing in these files.

Real-runtime proof: shipped capture patch, real socket

Added after review. Harness on node v24.15.0 that runs the real provider entry point
(buildBytePlusVideoGenerationProvider().generateVideo / the Runway equivalent) through the
real capture patch:

  • initializeDebugProxyCapture() installs the shipped global-fetch patch;
    isDebugProxyGlobalFetchPatchInstalled() is asserted true before the run.
  • A real node:http loopback origin serves the generated-media URL: HTTP 200,
    content-type: application/json, one chunk written and the body never ended.
  • The media download is issued over real undici through that patched global fetch, so the
    response the provider holds is a live capture-clone tee branch, not a modeled one.
  • Only the provider task API (create + poll) is served by a local stand-in, because it needs a
    paid account. It sits below the capture patch, so the download path is untouched. The SSRF
    guard dials undici directly when the caller fetch is identity-equal to globalThis.fetch
    (src/infra/net/fetch-guard.ts:645-658), so the harness re-wraps the patched chain under a
    fresh identity; that affects only the two task-API calls.

After fix, BytePlus:

[t+  807ms] debug-capture global fetch patch installed: true
[t+ 3039ms] calling byteplus generateVideo()
[t+ 5941ms] provider task API <- POST https://example.com/v1/contents/generations/tasks
[t+ 5951ms] provider task API <- GET  https://example.com/v1/contents/generations/tasks/proof-task
[t+ 5953ms] real undici fetch     -> GET http://127.0.0.1:52996/generated-video.mp4
[t+ 5962ms] loopback origin       <- GET /generated-video.mp4
[t+ 5963ms] loopback origin       -> headers sent, body left open (no end())
[t+ 5967ms] RESULT after 14ms after the media download started:
            BytePlus generated video download: malformed video response

After fix, Runway:

[t+ 5858ms] real undici fetch     -> GET http://127.0.0.1:50303/generated-video.mp4
[t+ 5868ms] loopback origin       -> headers sent, body left open (no end())
[t+ 5872ms] RESULT after 14ms after the media download started:
            Runway generated video download: malformed video response

Same harness, reverting only the two production lines to await response.body?.cancel():

[t+ 8227ms] loopback origin       -> headers sent, body left open (no end())
[t+14835ms] RESULT after 6620ms after the media download started:
            HUNG: no result after 10000ms          (byteplus)

[t+ 6284ms] loopback origin       -> headers sent, body left open (no end())
[t+13429ms] RESULT after 7155ms after the media download started:
            HUNG: no result after 10000ms          (runway)

The full matrix isolates debug capture as the cause rather than the loopback origin or the
never-ending body:

Provider Debug capture Rejected-download release Outcome, measured from download start
BytePlus on await (before this PR) hung, no result within the 10 s budget
BytePlus on void (this PR) malformed video response after 14 ms
BytePlus off await (before this PR) malformed video response after 64 ms
BytePlus off void (this PR) malformed video response after 15 ms
Runway on await (before this PR) hung, no result within the 10 s budget
Runway on void (this PR) malformed video response after 14 ms

The hang appears only in the capture-on, await cell, which is the cell this PR removes.

…r debug capture

When the debug proxy is enabled it patches global fetch and clones every
response, so the caller-facing body is one branch of a live tee. Cancelling
such a branch settles only after both branches cancel, so awaiting it in the
rejected-download path leaves the download pending instead of surfacing the
malformed-response error.

Both providers read the completed media URL through the global fetch, so they
reach the capture clone. Switch them to the fire-and-forget release the other
generated-media owners already use, and cover each with a regression that keeps
a capture clone live while the download is rejected.
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 12:07 PM ET / 16:07 UTC.

ClawSweeper review

What this changes

This PR makes BytePlus and Runway return their existing malformed-video error without waiting for a debug-captured response tee to finish cancellation.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: current main still awaits cancellation on both affected provider paths, while the PR’s tee-safe cancellation matches existing provider behavior and the updated real-runtime proof addresses the prior proof gap. No blocking patch defect found.

Priority: P2
Reviewed head: 9efe142e8293a468e9d53027d2767a4bea4aa65d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong runtime proof and a narrowly scoped, sibling-consistent repair make this a normal mergeable-quality fix.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body contains after-fix and reverted real-runtime terminal output through the actual capture patch, provider entry points, and a real loopback socket; expired loopback URLs in the prepared manifest are expected after the harness exits.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body contains after-fix and reverted real-runtime terminal output through the actual capture patch, provider entry points, and a real loopback socket; expired loopback URLs in the prepared manifest are expected after the harness exits.
Evidence reviewed 6 items Current-main defect: Current main rejects non-video content before consuming the body, then awaits cancellation; with a live capture tee this waits indefinitely instead of surfacing the malformed-video error.
Shared capture contract: Debug capture clones a response and explicitly documents that cancellation of one tee branch does not settle until both branches cancel; capture is launched without awaiting it.
Sibling implementation: Current OpenAI video handling uses the same fire-and-forget cancellation on malformed binary responses, supporting this as the established owner-boundary pattern.
Findings None None.
Security None None.

How this fits together

Generated-video providers poll a task, then download its resulting media URL. Debug capture clones global-fetch responses for recording; providers must validate the download and either return video bytes or promptly report a malformed response.

flowchart LR
  A[Video task completes] --> B[Provider downloads media URL]
  B --> C[Debug capture clones response]
  C --> D[Provider validates media type]
  D -->|Malformed| E[Start body cancellation]
  E --> F[Return malformed-video error]
  D -->|Valid video| G[Read and return video]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because the current branch has no actionable review finding.
Agent review details

Security

None.

PR surface

Source +4, Tests +108. Total +112 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 6 2 +4
Tests 2 108 0 +108
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 114 2 +112

Review metrics

Metric Value Why it matters
Production vs test delta production +6/-2; tests +108/-0 The small production change implements the existing tee-safe cleanup contract, while two focused regressions cover the independent provider owners.

Technical review

Best possible solution:

Land the focused provider-owned cancellation change after normal exact-head merge and check gates; keep any broader capture-read timeout work separate from this visible-error repair.

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

Yes. The supplied real-runtime harness uses the actual provider entry points, patched global fetch, and a real never-ending loopback response; its reverted awaited-cancel arm matches the unchanged current-main lines.

Is this the best way to solve the issue?

Yes. The provider-owned fire-and-forget cancellation is the narrowest fix for the visible hang and matches current OpenAI video and other tee-safe provider paths.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The defect can stall malformed video downloads for two optional providers when debug capture is enabled, with bounded provider-specific impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body contains after-fix and reverted real-runtime terminal output through the actual capture patch, provider entry points, and a real loopback socket; expired loopback URLs in the prepared manifest are expected after the harness exits.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body contains after-fix and reverted real-runtime terminal output through the actual capture patch, provider entry points, and a real loopback socket; expired loopback URLs in the prepared manifest are expected after the harness exits.

Evidence

What I checked:

  • Current-main defect: Current main rejects non-video content before consuming the body, then awaits cancellation; with a live capture tee this waits indefinitely instead of surfacing the malformed-video error. (extensions/byteplus/video-generation-provider.ts:204, 50a30b7373d7)
  • Shared capture contract: Debug capture clones a response and explicitly documents that cancellation of one tee branch does not settle until both branches cancel; capture is launched without awaiting it. (src/proxy-capture/runtime.ts:41, 50a30b7373d7)
  • Sibling implementation: Current OpenAI video handling uses the same fire-and-forget cancellation on malformed binary responses, supporting this as the established owner-boundary pattern. (extensions/openai/video-generation-provider.ts:267, 50a30b7373d7)
  • Clean current-main merge: A three-way merge of the PR with current main applies all four changed paths without conflicts. (9efe142e8293)
  • Runtime proof and release state: The PR body records actual-provider, patched-global-fetch, real-loopback before/after runs; current main has not incorporated the PR, and the latest supplied release predates the affected provider implementation. (9efe142e8293)
  • History routing: Blame attributes the current awaited-cancellation lines to a shallow/promisor-boundary commit, so it is useful only as a low-confidence area-routing signal. (extensions/runway/video-generation-provider.ts:323, 196d81195bf4)

Likely related people:

  • steipete: Commit 870c6b2 introduced the current shared malformed-media validation pattern that the provider-local repair follows. (role: shared media-validation contributor; confidence: high; commits: 870c6b240ef6; files: src/agents/provider-http-errors.ts, extensions/openai/video-generation-provider.ts)
  • MertBasar0: Available blame attributes both affected provider paths to this shallow-history boundary, but it cannot establish feature origin. (role: recent area contributor; confidence: low; commits: 196d81195bf4; files: extensions/byteplus/video-generation-provider.ts, extensions/runway/video-generation-provider.ts)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-04T14:36:01.078Z sha 9efe142 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-04T15:09:04.754Z sha 9efe142 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 4, 2026
@Takhoffman Takhoffman self-assigned this Aug 4, 2026
@Takhoffman
Takhoffman merged commit 0d18bde into openclaw:main Aug 4, 2026
234 of 252 checks passed
@Takhoffman

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 5, 2026
Punchcard-Session: crisp-lantern-orchard-nv

* origin/main:
  perf(memory): defer session backfill runtime (#119372)
  fix(ci): isolate built TUI PTY fixture (#119339)
  fix(commands): restore tool inventory for dynamic models (#119306)
  fix(media): release rejected BytePlus and Runway video downloads under debug capture (#119257)
  docs: add ChromeOS (Crostini) platform install guide (#107663)
  test(msteams): serve JWKS from in-process server in auth coverage (#119354)
  fix(qa): enable OpenAI for stored audio scenario (#119349)
  test(agents): realpath apply-patch temp dir fixture (#119353)
  test(slack): drop redundant .js-suffixed system-event mock (#119352)
  fix(exec): leave safe builtins unrewritten in enforced mode (#119351)
  fix(sessions): keep gateway responsive while large transcript archives are built (#112424)
  fix(tui): restore provider auth in installed local mode (#119283)
vincentkoc added a commit that referenced this pull request Aug 5, 2026
…time

* origin/main: (75 commits)
  fix(commands): restore tool inventory for dynamic models (#119306)
  fix(media): release rejected BytePlus and Runway video downloads under debug capture (#119257)
  docs: add ChromeOS (Crostini) platform install guide (#107663)
  test(msteams): serve JWKS from in-process server in auth coverage (#119354)
  fix(qa): enable OpenAI for stored audio scenario (#119349)
  test(agents): realpath apply-patch temp dir fixture (#119353)
  test(slack): drop redundant .js-suffixed system-event mock (#119352)
  fix(exec): leave safe builtins unrewritten in enforced mode (#119351)
  fix(sessions): keep gateway responsive while large transcript archives are built (#112424)
  fix(tui): restore provider auth in installed local mode (#119283)
  fix(release): accept legacy empty core artifacts (#119337)
  fix(qa): carry selected runtime into flow scenarios (#119324)
  fix(ci): retry interrupted Windows dashboard release checks (#119095)
  fix(release): filter validation ancestry fetch (#119334)
  fix(release): accept trusted extended-stable validation evidence (#119264)
  fix(sessions): preserve recorder-owned user turns (#119307)
  perf(cli): split plugin registry startup timing (#119318)
  fix(qa): align release scenario setup and compaction proof (#119188)
  fix(ci): avoid duplicate Matrix release QA runs (#119171)
  perf(agents): reuse provider policy manifest registry (#119305)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
…r debug capture (openclaw#119257)

…r debug capture

When the debug proxy is enabled it patches global fetch and clones every
response, so the caller-facing body is one branch of a live tee. Cancelling
such a branch settles only after both branches cancel, so awaiting it in the
rejected-download path leaves the download pending instead of surfacing the
malformed-response error.

Both providers read the completed media URL through the global fetch, so they
reach the capture clone. Switch them to the fire-and-forget release the other
generated-media owners already use, and cover each with a regression that keeps
a capture clone live while the download is rejected.

Co-authored-by: Tak Hoffman <[email protected]>
@Yigtwxx
Yigtwxx deleted the fix/video-download-tee-cancel-parity branch August 23, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: byteplus P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants