Skip to content

fix: stop a leaked console-routing latch from flaking CLI failure-output tests - #127604

Merged
steipete merged 1 commit into
mainfrom
steipete/quizzical-swartz-55cf8f
Aug 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/quizzical-swartz-55cf8f

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where src/entry.run-main.test.ts > entry run-main boundary > keeps expected conditions at exit 1 without crash framing failed intermittently in CI and
blocked unrelated PRs (seen on #127011 and #127075, always in shard
core-unit-src-security-2):

AssertionError: expected [] to deeply equal [ Array(1) ]
- [ [ "The `openclaw workboard` command is provided by the \"workboard\" plugin, ..." ] ]
+ []

Rerunning the failed job turned the run green, so it was order-dependent, not
deterministic. Maintainers lost time to a red gate on changes that had nothing to do
with CLI failure output.

Why This Change Was Made

Root cause is a global that no test owned.

enableConsoleCapture() (src/logging/console.ts:253) replaces every console.*
method with a forwarder, and routeLogsToStderr() / --json one-shot mode latch
loggingState.forceConsoleToStderr. Production never unwinds either: a stdio MCP
server (serveCodexSupervisionToolsMcp -> routeLogsToStderr,
src/mcp/codex-supervision-tools-serve.ts:107) and runMainOrRootHelp's
retainConsoleRoutingUntilProcessExit: true both own the console until the process
exits. That is correct for a CLI process and wrong for a Vitest worker, which never
exits. loggingState is deliberately keyed off globalThis
(src/logging/state.ts:41) so it survives module reloads, so the runner's existing
vi.resetModules() cleanup could not undo it either.

The failing test spies on console.error, then onError (src/entry.ts:315) calls
enableConsoleCapture() and writes through the forwarder. When the worker had
already inherited forceConsoleToStderr = true from an earlier file,
writeFormattedConsoleOutput took its process.stderr.write branch
(src/logging/console.ts:210) and never called the captured original, so the spy
recorded nothing. Whether the latching file landed in the same worker first was pure
scheduling luck, which is exactly the observed rerun-and-it-passes behavior.

The architectural owner is OpenClawNonIsolatedRunner.onAfterRunFiles, whose stated
job is to "mirror the missing cleanup from Vitest isolate mode so shared workers do
not carry file-scoped timers, stubs, spies, or stale module state forward into the
next file". Console routing belongs in that list. The fix restores the worker's
baseline console methods and loggingState there, and drops the two consumer-side
workarounds that were compensating downstream:

  • src/entry.run-main.test.ts no longer needs a pre-emptive enableConsoleCapture()
    to make its spy the outermost sink; it exercises the real forwarder path again.
  • src/mcp/codex-supervision-tools-serve.test.ts no longer hand-rolls a
    save/restore of forceConsoleToStderr around a describe block.

streamErrorHandlersInstalled is deliberately retained across the reset: those EPIPE
handlers really are attached to the worker's stdout/stderr, and clearing the flag
would let the next enableConsoleCapture() stack a second pair on every file.

User Impact

None at runtime. Test-harness only; production LOC delta is 0.

Evidence

Failure mechanism, reproduced in the original execution order with the real files
(forced sequencer so codex-supervision-tools-serve.test.ts runs first in one
worker):

  • Without the runner fix: FAIL src/entry.run-main.test.ts > keeps expected conditions at exit 1 without crash framing, AssertionError: expected [] to deeply equal [ Array(1) ] — byte-identical to the CI failure.
  • With the runner fix: Test Files 2 passed (2) / Tests 6 passed (6).

Regression coverage lands in test/non-isolated-runner.test.ts as a 06-a/06-b
fixture pair (file A latches capture + stderr routing, file B asserts a clean start
and that its own console.error spy still receives the line). Against the pre-fix
runner it fails with expected true to be false on
loggingState.forceConsoleToStderr; with the fix the child run reports
1 failed | 11 passed as asserted.

Local proof on this branch (rebased onto origin/main @ 41acededbc5):

  • node scripts/run-vitest.mjs --config test/vitest/vitest.unit-src.config.ts (full
    project, owns both changed test files) — green.
  • node scripts/run-vitest.mjs src/logging src/mcp test/non-isolated-runner.test.ts
    — 555 + 60 + 45 + 1 tests passed.
  • Shard core-unit-src-security-2 (146 files, pre-rebase membership that co-located
    the two files) — 145 passed | 1 skipped.
  • node scripts/check-changed.mjs — exit 0.
  • autoreview --mode uncommitted (codex/gpt-5.6-sol) — clean, no accepted findings.

Note on shard membership: the stripe split is content-derived, so the latching file
and entry.run-main.test.ts only co-locate in core-unit-src-security-2 for some
bases. After this rebase they no longer share that shard, which is why the flake
appeared on some PRs and not others.

Unrelated local-only failures, confirmed pre-existing (they reproduce with this
change stashed and on a clean origin/main, and main's CI check-runs are green):
src/infra/system-run-approval-binding.test.ts, test/scripts/telegram-user-observer.test.ts,
and test/scripts/telegram-mantis-lane.test.ts all fail on this Mac's Python 3.14
setup. Worth a follow-up to make those tests environment-independent; out of scope
here.

enableConsoleCapture() replaces every console method with a forwarder and
routeLogsToStderr()/`--json` mode latch loggingState.forceConsoleToStderr,
which production only unwinds at process exit. loggingState is keyed off
globalThis so it survives vi.resetModules(), so a shared Vitest worker carried
both into the next file: the inherited forwarder writes to process.stderr and
the next file's console.error spy records nothing.

That is the source of the order-dependent
`src/entry.run-main.test.ts > keeps expected conditions at exit 1` flake in
shard core-unit-src-security-2 — it failed only on workers that ran
src/mcp/codex-supervision-tools-serve.test.ts (serveCodexSupervisionToolsMcp
-> routeLogsToStderr) first.

Restore the worker's baseline console methods and logging state in the
runner's existing cross-file cleanup, and drop the two consumer-side
workarounds that were compensating for it.
@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 21, 2026 21:31
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 21, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Aug 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

This PR restores baseline console methods and logging state after each non-isolated Vitest file, removes two consumer-side test workarounds, and adds ordered cross-file regression coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still relies on test-local console-routing workarounds and lacks the shared-worker cleanup. Source review found no blocking defect in the runner-owned reset; automated autoreview could not run because TruffleHog is unavailable in this review environment.

Priority: P2
Reviewed head: b6a1e244b4732d00e65f406632e66edd584d9643

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused owner-boundary repair with credible ordered regression coverage; the remaining gate is unavailable autoreview and exact-head CI completion.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored, runner-only test change has no separate external contributor real-behavior-proof requirement; the PR body supplies ordered before/after test evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored, runner-only test change has no separate external contributor real-behavior-proof requirement; the PR body supplies ordered before/after test evidence.
Evidence reviewed 6 items Current-main failure path: Current main’s console forwarder writes directly to stderr when forceConsoleToStderr is latched, bypassing the original console spy; its logging state is deliberately globalThis-backed across module reloads.
Current-main workaround evidence: Current main pre-enables console capture in the CLI assertion and manually restores forceConsoleToStderr in the Codex-supervision MCP test, while current-main runner cleanup has no console-state reset.
Owner-boundary repair: The PR adds console and logging baseline restoration inside onAfterRunFiles, after mock restoration and before module reset; it preserves stream error-handler installation because those listeners remain process-owned.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs test/non-isolated-runner.test.ts

Result: PASS (completed)

node scripts/run-vitest.mjs test/non-isolated-runner.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127604-LPYJIw/target$ node scripts/run-vitest.mjs test/non-isolated-runner.test.ts
node scripts/run-vitest.mjs test/non-isolated-runner.test.ts
[test] starting test/vitest/vitest.tooling.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127604-LPYJIw/target

 ✓  tooling  test/non-isolated-runner.test.ts (1 test) 9201ms
   ✓ cleans every shared runner surface between files  9199ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  21:37:53
   Duration  9.66s (transform 241ms, setup 64ms, import 20ms, tests 9.20s, environment 0ms)

[test] passed 1 Vitest shard in 15.70s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127604-LPYJIw/target$ node scripts/run-vitest.mjs test/non-isolated-runner.test.ts


































Assertions:

  • PASS expect_output: 1 passed

How this fits together

The non-isolated Vitest runner reuses one worker across test files. CLI and stdio-MCP tests can latch console capture and stderr routing, so the runner must clear those file-scoped effects before the next test file runs.

flowchart LR
  A[Test file] --> B[Console capture and stderr routing]
  B --> C[Shared Vitest worker]
  C --> D[Runner cross-file cleanup]
  D --> E[Clean console and logging baseline]
  E --> F[Next test file and CLI assertion]
Loading

Before merge

  • Resolve merge risk (P1) - Autoreview could not complete locally because its required TruffleHog binary is absent; exact-head CI and a maintainer-side autoreview run remain needed before landing.
  • Complete next step (P2) - This protected maintainer PR needs normal exact-head validation rather than an automated repair job.
Agent review details

Security

None.

PR surface

Tests +52. Total +52 across 4 files.

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

Review metrics

Metric Value Why it matters
Production versus test delta production 0; tests/test-support +63/-11 The change is contained to the Vitest runner and its tests, preserving the production runtime surface.

Stored data model

Persistent data-model change detected: serialized state: test/non-isolated-runner.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the runner-owned reset with the ordered regression fixture after the unavailable autoreview closeout is completed and exact-head CI is green.
  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 runner-owned reset with the ordered regression fixture after the unavailable autoreview closeout is completed and exact-head CI is green.

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

Yes, source provides a high-confidence ordered path: latch stderr routing and console capture in one non-isolated file, then run a CLI failure-output assertion in the same worker. This review did not execute tests because the checkout is read-only.

Is this the best way to solve the issue?

Yes. Resetting the shared worker at onAfterRunFiles fixes the producer-owned lifecycle leak; current main’s per-test capture and afterEach restoration only compensate at individual consumers.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This removes an order-dependent CI failure that blocks unrelated changes but does not alter user-facing runtime behavior.
  • 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: This maintainer-authored, runner-only test change has no separate external contributor real-behavior-proof requirement; the PR body supplies ordered before/after test evidence.

Label justifications:

  • P2: This removes an order-dependent CI failure that blocks unrelated changes but does not alter user-facing runtime behavior.
  • 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: This maintainer-authored, runner-only test change has no separate external contributor real-behavior-proof requirement; the PR body supplies ordered before/after test evidence.

Evidence

What I checked:

  • Current-main failure path: Current main’s console forwarder writes directly to stderr when forceConsoleToStderr is latched, bypassing the original console spy; its logging state is deliberately globalThis-backed across module reloads. (src/logging/console.ts:209, 69e4fbbeb5f8)
  • Current-main workaround evidence: Current main pre-enables console capture in the CLI assertion and manually restores forceConsoleToStderr in the Codex-supervision MCP test, while current-main runner cleanup has no console-state reset. (src/entry.run-main.test.ts:29, 69e4fbbeb5f8)
  • Owner-boundary repair: The PR adds console and logging baseline restoration inside onAfterRunFiles, after mock restoration and before module reset; it preserves stream error-handler installation because those listeners remain process-owned. (test/non-isolated-runner.ts:161, b6a1e244b473)
  • Regression coverage: The child-run fixture deterministically runs a latching file before an observer file and checks both reset state and that the next file’s console.error spy receives output. (test/non-isolated-runner.test.ts:166, b6a1e244b473)
  • Area history: History identifies prior non-isolated shared-worker cleanup work, including Vincent Koc’s shared-state isolation commit and Peter Steinberger’s runner cleanup and mock-serialization work; the available history is grafted, so attribution is routing evidence rather than regression blame. (test/non-isolated-runner.ts:416, 45643863d713)
  • Autoreview closeout: The required bundled autoreview was invoked for the stated PR base but stopped before review because TruffleHog is not installed; no reviewer finding was produced.

Likely related people:

  • steipete: Visible history includes the current reset and earlier runner cleanup and mock-serialization work. (role: recent non-isolated-runner contributor; confidence: medium; commits: b6a1e244b473, b2e34b03b5cb, 883995f08dc1; files: test/non-isolated-runner.ts, test/non-isolated-runner.test.ts)
  • Vincent Koc: Commit 4564386 covers isolation of shared test state in the same runner path. (role: adjacent shared-state cleanup contributor; confidence: medium; commits: 45643863d713; files: test/non-isolated-runner.ts)

Rank-up moves

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

  • Run the bundled autoreview after TruffleHog is available, then confirm exact-head CI is green.

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 75b736c into main Aug 21, 2026
236 checks passed
@steipete
steipete deleted the steipete/quizzical-swartz-55cf8f branch August 21, 2026 21:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 22, 2026
…law#127604)

enableConsoleCapture() replaces every console method with a forwarder and
routeLogsToStderr()/`--json` mode latch loggingState.forceConsoleToStderr,
which production only unwinds at process exit. loggingState is keyed off
globalThis so it survives vi.resetModules(), so a shared Vitest worker carried
both into the next file: the inherited forwarder writes to process.stderr and
the next file's console.error spy records nothing.

That is the source of the order-dependent
`src/entry.run-main.test.ts > keeps expected conditions at exit 1` flake in
shard core-unit-src-security-2 — it failed only on workers that ran
src/mcp/codex-supervision-tools-serve.test.ts (serveCodexSupervisionToolsMcp
-> routeLogsToStderr) first.

Restore the worker's baseline console methods and logging state in the
runner's existing cross-file cleanup, and drop the two consumer-side
workarounds that were compensating for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant