Skip to content

test(scripts): stop managed-child descendant checks racing process startup - #125441

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-managed-child-descendant-race
Aug 17, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-managed-child-descendant-race

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

test/scripts/managed-child-process.test.ts fails intermittently on loaded CI runners — most recently
blocking PR #124950, which went green on rerun with no code change. The failing assertion was
expect(isProcessAlive(descendantPid)).toBe(true) in "kills managed child process group descendants when
the runner is terminated".

The race was in the fixture, not the assertion. The generated child spawned its descendant and then wrote
the descendant's pid itself:

const descendant = spawn(process.execPath, ["-e", "…setInterval…"], { stdio: "ignore" });
fs.writeFileSync(process.argv[3], String(descendant.pid));

spawn() returns a pid the moment the process is forked, before the descendant's Node runtime has booted.
So the test's await waitFor(() => fs.existsSync(descendantPidPath)) proved only that a pid had been
written
, never that the process was running — and under load the liveness check could observe a descendant
that had not finished starting.

Why This Change Was Made

A flaky assertion guarding real process-group cleanup is worth fixing rather than rerunning: it fails often
enough to train people to hit retry, which is how a genuine cleanup regression would slip through.

The pid file becomes a genuine readiness signal — the descendant writes its own pid once its runtime is up,
so the existing waitFor(existsSync) now implies liveness. The lingering-child fixture, whose parent exits
immediately, uses an IPC process.send('ready') handshake instead, since a pid file alone cannot order
against the parent's exit. Two sibling fixtures carried the same optimistic-pid pattern and were fixed
identically.

Deliberately unchanged: every assertion, including the liveness check, and the waitFor(..., 1_500)
teardown bounds. Weakening the assertion, wrapping it in a retry, or stretching the timeouts would have hidden
the race rather than removed it — and would have left a test that can no longer fail.

User Impact

None. Test-only; no production file is touched.

Evidence

Ten consecutive runs of the file, since a single green run proves nothing about a race:

10/10 passed
pnpm test test/scripts/managed-child-process.test.ts
 Test Files  1 passed (1)
      Tests  19 passed (19)

pnpm check:changed green; Codex autoreview clean.

reviewMetrics — production vs test LOC: production 0, tests +12 / −10 (net +2).

No CHANGELOG.md edit — release-only per repo policy; test-only change.

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 17, 2026
@steipete
steipete marked this pull request as ready for review August 17, 2026 23:09
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@steipete steipete self-assigned this Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 17, 2026, 7:15 PM ET / 23:15 UTC.

ClawSweeper review

What this changes

This PR changes managed-child test fixtures so descendant PID files and an IPC message indicate that descendants have started before lifecycle assertions run.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: the liveness-race fix is sound for the signal test, but it introduces a new timeout-fixture race that can make CI fail while reading a PID file. Likely related people: Peter Steinberger (high confidence) and Vincent Koc (medium confidence).

Priority: P3
Reviewed head: 5f5f407225859694bc25faaeb1e8cfd1d27ac011

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The intended readiness repair is useful, but one changed fixture can itself flake under the same scheduling pressure.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored test-only PR is outside the external real-behavior-proof gate; its supplied repeated targeted test result is supplemental validation.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored test-only PR is outside the external real-behavior-proof gate; its supplied repeated targeted test result is supplemental validation.
Evidence reviewed 5 items Current-main timeout fixture: Current main records the descendant PID from the parent immediately after spawn, then reads it only after timeout cleanup; this fixture asserts cleanup, not pre-termination liveness.
Introduced race: The PR moves PID-file creation into the descendant, while the test synchronously reads that file after the 500 ms timeout; if group termination occurs before the descendant executes, the read fails with a missing file.
Timeout owner boundary: The unchanged process runner arms the timeout immediately after spawning the parent and kills the whole process group when it fires, before the test can rely on descendant-owned startup work.
Findings 1 actionable finding [P2] Keep the timeout fixture PID available before cleanup
Security None None.

How this fits together

The managed-child script tests spawn Node process trees, terminate a managed process group, and verify descendant cleanup. The fixtures communicate process identity and readiness to the test before teardown and liveness checks.

flowchart LR
A[Test launches managed command] --> B[Parent fixture starts descendant]
B --> C[Fixture publishes PID or readiness]
C --> D[Test observes process state]
D --> E[Timeout or termination]
E --> F[Process-group cleanup]
F --> G[Cleanup assertions]
Loading

Before merge

  • Keep the timeout fixture PID available before cleanup (P2) - The timeout starts immediately after spawning the parent, and on expiry kills its whole process group. This new descendant-owned write can therefore never run on a loaded runner, but the test then synchronously reads descendantPidPath; restore the parent-owned PID write here, since this case verifies post-timeout cleanup rather than pre-timeout liveness.
  • Complete next step (P2) - Repair the one test-fixture regression before merge; it is a narrow mechanical change with a clear owner boundary.

Findings

  • [P2] Keep the timeout fixture PID available before cleanup — test/scripts/managed-child-process.test.ts:245-246
Agent review details

Security

None.

PR surface

Tests +2. Total +2 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 12 10 +2
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 12 10 +2

Review metrics

Metric Value Why it matters
Production vs test LOC production 0; tests +12/-10 (net +2) The patch is fixture-only, but those fixture changes directly affect required CI process-lifecycle coverage.

Merge-risk options

  • Merging this test-only diff can reintroduce flaky CI: the 500 ms timeout may kill the process group before the descendant creates its new PID file, after which the fixture reads a nonexistent path.

Maintainer options:

  1. Separate cleanup tracking from readiness (recommended)
    Restore parent-written descendant PID recording in the timeout fixture while retaining descendant-owned readiness only for the liveness assertion cases.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Restore parent-owned PID recording in the timeout-cleanup fixture; retain descendant-owned readiness only where liveness is asserted, then run the targeted managed-child test.

Technical review

Best possible solution:

Keep parent-owned PID recording in the timeout-cleanup fixture, and reserve descendant-owned readiness signals for fixtures that assert a descendant is alive before termination.

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

Yes—delay the descendant’s Node startup beyond the existing 500 ms timeout; cleanup kills its process group before it writes the PID file, and the following synchronous read fails. This is source-reproducible; no test was run in this read-only review.

Is this the best way to solve the issue?

No—the descendant-owned PID is the right readiness signal only where liveness is asserted; the timeout-cleanup fixture needs a PID recorded before descendant boot or an explicit pre-timeout readiness phase.

Full review comments:

  • [P2] Keep the timeout fixture PID available before cleanup — test/scripts/managed-child-process.test.ts:245-246
    The timeout starts immediately after spawning the parent, and on expiry kills its whole process group. This new descendant-owned write can therefore never run on a loaded runner, but the test then synchronously reads descendantPidPath; restore the parent-owned PID write here, since this case verifies post-timeout cleanup rather than pre-timeout liveness.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a contained internal test-stability repair with no production behavior change.
  • add merge-risk: 🚨 automation: The changed timeout fixture can fail required CI when descendant startup loses the race to its existing 500 ms timeout.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored test-only PR is outside the external real-behavior-proof gate; its supplied repeated targeted test result is supplemental validation.

Label justifications:

  • P3: This is a contained internal test-stability repair with no production behavior change.
  • merge-risk: 🚨 automation: The changed timeout fixture can fail required CI when descendant startup loses the race to its existing 500 ms timeout.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored test-only PR is outside the external real-behavior-proof gate; its supplied repeated targeted test result is supplemental validation.

Evidence

Acceptance criteria:

  • [P1] pnpm test test/scripts/managed-child-process.test.ts.
  • [P1] pnpm check:changed -- test/scripts/managed-child-process.test.ts.

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the timeout fixture’s original PID handling to this contributor, who also authored the present focused change. (role: feature owner and recent area contributor; confidence: high; commits: eb38d5e4863a, 5f5f40722585; files: test/scripts/managed-child-process.test.ts, scripts/lib/managed-child-process.mts)
  • Vincent Koc: Recent history credits this contributor for related process-tree lifecycle and QA probe coverage that uses the same cleanup invariant. (role: adjacent lifecycle-test contributor; confidence: medium; commits: 2de88241a437, 7c7057168389; files: test/e2e/qa-lab/plugins/plugin-lifecycle-probe.e2e.test.ts, test/scripts/test-live.test.ts)

Rank-up moves

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

  • Restore parent-owned PID publication in the timeout cleanup fixture.
  • Run pnpm test test/scripts/managed-child-process.test.ts after the fixture split and add the result to the PR body.

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

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 5f5f407225859694bc25faaeb1e8cfd1d27ac011:

  • Required post-rebase local proof: pnpm test ui/src/pages/chat/components/chat-sidebar-region.test.ts ui/src/e2e/chat-sidebar-panel-contract.e2e.test.ts ui/src/e2e/chat-session-diff.e2e.test.ts ui/src/e2e/terminal-open.e2e.test.ts — 2 Vitest shards, 4 files, 29 tests passed.
  • Focused race proof recorded in the PR body: 10 consecutive managed-child-process runs, one focused 19-test pass, and pnpm check:changed green.
  • Fresh review: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main — clean, no accepted/actionable findings.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32079238341 — green for the SHA above.
  • Native landing artifacts: review-init, review-artifacts-init, and review-validate-artifacts completed with READY FOR /prepare-pr; OPENCLAW_TESTBOX=1 scripts/pr prepare-run 125441 accepted the exact hosted gate and verified the remote PR tree.
  • ClawSweeper rank-up moves: the latest live comment is still the review-start placeholder and contains no Rank-up moves: items, so there is nothing to apply or skip. Per repository policy, a queued review does not block landing.

Proof gap: none for this test-only change. No production, user-visible, docs, or changelog surface changed.

@steipete
steipete merged commit 47afdd9 into main Aug 17, 2026
187 checks passed
@steipete
steipete deleted the steipete/fix-managed-child-descendant-race branch August 17, 2026 23:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant