Skip to content

fix(test): stop cross-file state leaks in media suites - #116027

Merged
steipete merged 1 commit into
mainfrom
fix/media-test-isolation
Jul 29, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/media-test-isolation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

main is red on the core-runtime-media-ui shard, and the failures rotate rather than repeat, which makes them read as flake and get rerun instead of fixed.

Reproduced on clean main:

  • node scripts/run-vitest.mjs src/media/playback-transcode.test.ts alone → 26/26 pass
  • node scripts/run-vitest.mjs src/media (whole directory, shared workers) → 24 failed across 7 files, 783 passed

And in CI (checks-node-compact-large-4, run 30473348999):

FAIL src/media/playback-transcode.test.ts > resolvePlaybackTranscode > passes already portable
AssertionError: expected { kind: 'preparing' } to deeply equal { kind: 'passthrough' }

The repo runs Vitest with isolate: false deliberately, so shared workers surface module-registry and module-state leaks close to whatever introduced them. These are real defects in the tests, not an argument for turning isolation on.

Why This Change Was Made

Diagnosis established concrete poisoner→victim edges rather than guessing:

  • web-media.test.ts → fetch (3 failures), ffmpeg-exec (4), media-probe (9), audio-transcode (5)
  • qr-image.test.ts ↔ qr-terminal.test.ts — reversing the seed moved 2 terminal failures into 5 image failures
  • store.test.ts ↔ store.outside-workspace.test.ts — reversing order produced 1 versus 8 failures
  • image-ops.helpers.test.ts → Rastermill adapter (1 failure)
  • The playback saturated-pool test → the portable-media test, via background continuations that were never awaited

Two root-cause clusters. The { kind: 'preparing' } leak is legitimate playback runtime state (a transcode registry) combined with tests that finished without draining their background work, so a later "already portable" input observed an in-flight job from an earlier file. The rest are leaked module and mock caches, where a vi.mock from one file survived into a file expecting the real module.

Fixes are test-only: reset module state before dynamic imports, unmock and reset afterward, preserve the actual QR and Rastermill exports and error identities rather than substituting stub classes, and await all background transcodes before a test completes. No production code changed — the runtime registries are correct; the tests were not draining them.

User Impact

None at runtime. This restores a trustworthy signal from the core-runtime-media-ui shard so genuine regressions there stop being masked by rotating noise, and unrelated PRs stop being blocked by breakage they did not cause.

Evidence

  • src/media run three consecutive times, since these failures are order and timing sensitive: 58 files / 807 tests green each time (12.61s, 11.51s, 12.17s).
  • All 11 edited files still pass individually: 264 tests.
  • Exact six-config core-runtime-media-ui shard grouping reproduced on Blacksmith Testbox tbx_01kyqg0x52h90562qpqc0st6b3 (Actions run 30477215921): passed in 158.68s.
  • pnpm check:test-types, both deadcode lanes (zero unused exports), full lint (zero warnings/errors), formatting, git diff --check: all passing.
  • Autoreview clean, no findings.
  • No --isolate, no .skip, no retries, no baseline or ignore-file edits, no weakened assertions.

@steipete
steipete marked this pull request as ready for review July 29, 2026 18:10
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 29, 2026
@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. P2 Normal backlog priority with limited blast radius. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 2:55 PM ET / 18:55 UTC.

ClawSweeper review

What this changes

The branch changes eleven media test files to reset mocked module state and drain pending playback transcodes, preventing shared Vitest workers from leaking state into later media tests.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This test-only repair has credible after-fix evidence and no definite patch defect in the supplied diff, but the current PR is behind main after the order-sensitive validation ran. Because shared worker/module-cache behavior can change with the merge base, keep it open for a rebase plus a fresh src/media/target-shard run before maintainer merge; the maintainer label also requires explicit human handling.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused test reliability fix with strong repeated runtime-test evidence; only the final current-base refresh remains before maintainer merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body and follow-up comment provide after-fix terminal/Testbox evidence, including three successful full media-suite runs on the rebased head; refresh it once more after rebasing to the current base.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body and follow-up comment provide after-fix terminal/Testbox evidence, including three successful full media-suite runs on the rebased head; refresh it once more after rebasing to the current base.
Evidence reviewed 4 items Changed test boundary: The PR head changes only src/media/*.test.ts files, moving affected module imports behind reset boundaries, undoing mocks during teardown, and adding a wait for pending playback transcodes.
After-fix behavior proof: The contributor’s July 29, 2026 comment reports three consecutive successful node scripts/run-vitest.mjs src/media runs after rebasing to 0ed6589e792, with 58 files and 807 tests passing each time; the PR body also reports an exact shard run on Testbox.
Current-base refresh remains necessary: GitHub reports head 0ed6589e792 as cleanly mergeable but behind current main 83aca8a59c7. The previous review correctly identified that module-cache and worker-order proof does not automatically transfer across a changed merge base.
Findings None None.
Security None None.

How this fits together

OpenClaw’s media suite tests fetching, probing, QR rendering, storage, and playback transcoding under shared Vitest workers. Test setup, module mocking, and teardown feed the CI shard that validates media behavior and determines whether later test files see clean state.

flowchart LR
  A[Media test files] --> B[Shared Vitest workers]
  B --> C[Module and mock registry]
  B --> D[Playback transcode jobs]
  C --> E[Test setup and teardown]
  D --> E
  E --> F[Media CI shard results]
Loading

Decision needed

Question Recommendation
Should this PR be merged after the contributor refreshes its order-sensitive media-suite proof against the current main merge result? Require current-base proof: Ask for a rebase to current main and repeated src/media plus target-shard results from that final head before merge.

Why: The patch is test-only and the supplied proof is strong, but shared-worker ordering and module-cache behavior are explicitly base-sensitive; the protected maintainer label requires a human merge decision after the refresh.

Before merge

  • Resolve merge risk (P1) - main advanced after the reported rebase and repeated media-suite proof. Since this PR specifically changes shared-worker module and asynchronous-state cleanup, maintainers should require validation against the current merge result rather than assume the earlier run transfers unchanged.
  • Complete next step (P2) - The concrete remaining action is a current-base rebase and proof refresh followed by protected-label maintainer merge review, not an automated repair.
Agent review details

Security

None.

PR surface

Tests +100. Total +100 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 11 152 52 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 152 52 +100

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Refresh proof on the final merge base (recommended)
    Rebase the test-only patch onto current main and repeat the order-sensitive media-suite and shard validation before merge.
  2. Accept the base-drift risk
    Merge using the existing proof if maintainers judge the intervening main changes unable to affect shared-worker ordering or module-state behavior.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase onto current main, then attach redacted output for repeated `node scripts/run-vitest.mjs src/media` runs and the exact core-runtime-media-ui shard from the final head.

Technical review

Best possible solution:

Rebase onto current main, then rerun the complete src/media suite repeatedly and the exact core-runtime-media-ui shard on that rebased head; retain the focused cleanup approach if those runs remain stable.

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

Yes, with medium confidence: the PR documents a concrete current-main failure mode where the single playback file passes but the shared-worker src/media run fails, and it supplies repeated after-fix suite results. The exact failing state should be rechecked on the current merge base because it is order-sensitive.

Is this the best way to solve the issue?

Yes, provisionally: resetting test-owned module/mock state and draining test-created background transcodes is narrower and safer than enabling Vitest isolation or weakening assertions. The final rebased run is still required to establish that this is the best durable cleanup on current main.

AGENTS.md: unclear because the file could not be read completely.

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

Labels

Label changes:

  • add merge-risk: 🚨 automation: The patch changes shared Vitest-worker cleanup, so proof must be refreshed when the base changes to avoid reintroducing or masking CI flake.

Label justifications:

  • P2: Rotating media-suite failures reduce CI reliability and can block unrelated work, but the PR does not alter shipped runtime behavior.
  • merge-risk: 🚨 automation: The patch changes shared Vitest-worker cleanup, so proof must be refreshed when the base changes to avoid reintroducing or masking CI flake.
  • 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 (terminal): The PR body and follow-up comment provide after-fix terminal/Testbox evidence, including three successful full media-suite runs on the rebased head; refresh it once more after rebasing to the current base.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and follow-up comment provide after-fix terminal/Testbox evidence, including three successful full media-suite runs on the rebased head; refresh it once more after rebasing to the current base.

Evidence

What I checked:

  • Changed test boundary: The PR head changes only src/media/*.test.ts files, moving affected module imports behind reset boundaries, undoing mocks during teardown, and adding a wait for pending playback transcodes. (src/media/playback-transcode.test.ts:24, 0ed6589e7929)
  • After-fix behavior proof: The contributor’s July 29, 2026 comment reports three consecutive successful node scripts/run-vitest.mjs src/media runs after rebasing to 0ed6589e792, with 58 files and 807 tests passing each time; the PR body also reports an exact shard run on Testbox. (src/media/playback-transcode.test.ts:793, 0ed6589e7929)
  • Current-base refresh remains necessary: GitHub reports head 0ed6589e792 as cleanly mergeable but behind current main 83aca8a59c7. The previous review correctly identified that module-cache and worker-order proof does not automatically transfer across a changed merge base. (src/media/web-media.test.ts:68, 83aca8a59c7c)
  • Prior review continuity: The preceding ClawSweeper cycle had no code findings and requested exactly a rebase plus order-sensitive revalidation. The contributor addressed that request for base 0ed6589e792, but the supplied current base has advanced again. (80cf629e25b4)

Likely related people:

  • steipete: Authored the current focused repair and supplied the reproduction, rebased validation, and Testbox evidence for the affected media test boundary; broader current-main ownership could not be verified from the read-only inspection environment. (role: recent media-test contributor; confidence: low; commits: 0ed6589e7929; files: src/media/playback-transcode.test.ts, src/media/web-media.test.ts, src/media/qr-image.test.ts)

Rank-up moves

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

  • Rebase onto current main and attach fresh repeated src/media and target-shard output from that final head.

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-07-29T18:15:58.726Z sha 80cf629 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-29T18:47:12.621Z sha 80cf629 :: needs maintainer review before merge. :: none

@steipete steipete closed this Jul 29, 2026
@steipete steipete reopened this Jul 29, 2026
@steipete
steipete force-pushed the fix/media-test-isolation branch from 80cf629 to 0ed6589 Compare July 29, 2026 18:50
@steipete

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and re-ran the order-sensitive validation, since for this PR class proof against a stale merge base genuinely does not transfer — module-cache and worker-order behavior are exactly what changes underneath a rebase.

Branch was 13 commits behind; now rebased to 0ed6589e792.

Re-ran node scripts/run-vitest.mjs src/media three consecutive times on the rebased tree:

=== run 1 ===  Test Files  58 passed (58)    Tests  807 passed (807)
=== run 2 ===  Test Files  58 passed (58)    Tests  807 passed (807)
=== run 3 ===  Test Files  58 passed (58)    Tests  807 passed (807)

Three runs rather than one because these failures are order and timing sensitive; a single green run would not distinguish a fix from a lucky scheduling.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Jul 29, 2026
@steipete
steipete merged commit 5d02f42 into main Jul 29, 2026
97 checks passed
@steipete
steipete deleted the fix/media-test-isolation branch July 29, 2026 18:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to sunlit-deng/openclaw that referenced this pull request Jul 29, 2026
* origin/main:
  fix(codex): avoid transcript mirror snapshot churn (openclaw#115070)
  fix(test): stop cross-file state leaks in media suites (openclaw#116027)
  feat(hooks): add persistent hook session mode (openclaw#75918)
vincentkoc added a commit to masatohoshino/openclaw that referenced this pull request Jul 29, 2026
* origin/main: (151 commits)
  feat(plugins): allow per-turn tool narrowing in prompt hooks (openclaw#114151)
  docs(hooks): mark pairing hook observation-only (openclaw#116055)
  docs(control-ui): document composer capability menu (openclaw#115858)
  fix(build): bound declaration memory use (openclaw#116021)
  fix: Slack replies recover after gateway startup replay (openclaw#115991)
  fix(azure-speech): keep valid voices from malformed catalogs (openclaw#115067)
  fix(agents): prevent model runtime startup timeout (openclaw#116039)
  fix(ui): explain unavailable MCP tool catalogs (openclaw#115994)
  fix(skills): run experience review outside released request roots (openclaw#116040)
  docs(security): add safe Gmail reader setup (openclaw#116041)
  chore: refresh browser gateway runtime (openclaw#116043)
  test: isolate gateway sequence lifecycle coverage
  docs: note gateway reconnect sequence fix
  test: cover gateway sequence reset on restart
  test: cover gateway sequence reset on reconnect
  fix: reset gateway event sequence on reconnect
  fix(codex): avoid transcript mirror snapshot churn (openclaw#115070)
  fix(test): stop cross-file state leaks in media suites (openclaw#116027)
  feat(hooks): add persistent hook session mode (openclaw#75918)
  fix(memory): return early for blank searches (openclaw#116034)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. 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: M 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.

1 participant