Skip to content

fix(test): stop migration script exit assertion from flaking on slow runners - #1536

Merged
bkudiess merged 2 commits into
openclaw:mainfrom
natalie-aguinaldo:user/natalie-aguinaldo/fix-migration-script-exit-flake
Sep 28, 2026
Merged

bkudiess merged 2 commits into
openclaw:mainfrom
natalie-aguinaldo:user/natalie-aguinaldo/fix-migration-script-exit-flake

Conversation

@natalie-aguinaldo

@natalie-aguinaldo natalie-aguinaldo commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CleanupScript_CompletedReceiptPreservesFilesWithoutCallingWsl flakes on CI. The parentShare: None, expectedExit: 2 case timed out on a correct run of the uninstall script. This raises that caller's deadline and fixes a timeout diagnostic that was reporting the wrong thing.

The test and its 30-second budget were added in #1461 (the migration foundation). No production code changes.

What actually happened

The case deliberately holds prepare.lock with FileShare.None so scripts/Uninstall-LocalGateway.ps1 fails to acquire it and exits 2. In the failing CI run:

  • The script's own log did contain the contention line, timestamped ~300 ms after start.
  • Starting local gateway cleanup was absent, proving cleanup correctly did not continue.
  • Captured stdout was empty, and the test was killed at 30 s.

So the script reached its failure handler almost immediately and then the run stalled before its output and result files landed.

Reproduction

A five-iteration local harness mirroring the test exactly (same env vars, same args, same FileShare.None parent lock):

stdout stderr duration exit
Local repro, 5/5 245 chars 0 ~0.6 s 2
CI (failed) empty empty > 30 s killed

The script is correct and prompt. The 30 s budget was not sized for its work; it was being asked to absorb a windows-latest I/O stall on the small log and result files the failure path creates.

Changes

1. Scope the larger budget to the one affected caller. The helper default stays at 30 s so the other 23 call sites keep failing fast. Only the lock-contention theory passes TimeSpan.FromSeconds(120).

The other default call sites cannot hit this stall structurally, not just by luck: Test-InnoMigration.ps1 (the L244 caller) contains no Set-Content, Out-File, New-Item, Add-Content, or Start-Transcript at all, and the L348 caller runs an AST-extracted predicate over in-memory ACLs. Neither creates the files the stall depends on, and neither holds a FileShare.None handle in the directory the child touches.

2. Fix the timeout diagnostic. It seeded cleanup with "Root process exit confirmed." and only overwrote it when cleanup threw, so every timeout report claimed a confirmed exit regardless of what happened. Now it samples HasExited before killing, reports the observed state, appends rather than overwrites when the kill races the process exiting, and adds the final exit code once known. It also notes that killing discards PowerShell's buffered stdout, so a future reader does not mistake an empty output section for a silent script. The process id is cached up front to keep the diagnostic path off live process state.

What is deliberately not changed

scripts/Uninstall-LocalGateway.ps1 is untouched.

An automated suggestion on the original failure proposed rewriting its lock acquisition to use FileShare.None and a hardcoded exit 2. That was rejected:

  • The guard it asks for already exists. The script catches, logs, writes its result, and exits before any cleanup.
  • The script deliberately opens the lock with FileAccess.Read, FileShare.Read to join the Inno parent's read lock. Switching to FileShare.None would break the sibling parentShare: Read, expectedExit: 10 case, which passed in the same CI run - trading an intermittent flake for a deterministic regression.
  • A hardcoded exit 2 would discard $script:MigrationAdmissionPhase, which selects exit 1 vs 2.

Required proof pools

none. This is a test-only change to a timeout budget and a diagnostic message. It touches no installer artifact, WSL gateway, MXC containment, ARM64 path, or WinUI surface, so no named pool in docs/PROOF_POOLS.md applies.

Validation

Run in a clean worktree off main at 19d317e5:

  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --filter "FullyQualifiedName~MigrationRecordTests" - 53 passed, 0 failed (32 s), including all five cases of the affected theory.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj - 4145 passed, 0 failed, 34 skipped.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj - 3180 passed, 0 failed.

Also dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --filter "FullyQualifiedName~MigrationRecordTests" re-run after the review fixes - 53 passed, 0 failed, and .\scripts\validate-docs.ps1 - passed, 51 Markdown files and 7 named proof pools checked.

Full build: blocked, not skipped

.\build.ps1 did not complete on this head. It fails at restore with NU1100 resolving Microsoft.WindowsAppSDK 2.5.1, which main bumped in #1522.

The cause is environmental and confirmed at the network layer, not a repository break:

  • 2.4.0 is present in the local NuGet cache; 2.5.1 is not.
  • Every client fails the same way reaching nuget.org from this machine. curl.exe returns schannel: SEC_E_ILLEGAL_MESSAGE (TLS alert, handshake failed) and PowerShell reports HandshakeFailure, so this is TLS interception on the network path rather than a NuGet or NuGet.Config problem. Source mapping is a single nuget.org source with a * pattern.
  • The failure is confined to the three WinUI-referencing projects. OpenClaw.Shared, OpenClaw.Connection, OpenClaw.SetupEngine, OpenClaw.Cli, and OpenClaw.WinNode.Cli all restored and built.

This PR changes one test file and one documentation table. It references no WinUI type, so the unbuilt projects cannot be affected by it, and the suites above cover every project that can be. CI's own change-classification job evaluated this head and skipped the build and publish jobs for the same reason.

I cannot clear this locally without network access to nuget.org. Any machine that can reach nuget.org, including CI, resolves 2.5.1 normally.

Dual-model adversarial review was run on the change and re-run after fixes; both models report no remaining issues.

Real behavior proof

The reproduction table above is the behavioral evidence: five consecutive runs of the exact failing scenario, each exiting 2 in ~0.6 s with full stdout. That is what establishes the script is correct and the CI timeout was environmental rather than a hang.

…runners

CleanupScript_CompletedReceiptPreservesFilesWithoutCallingWsl gave the
uninstall script 30 seconds to exit. A local five-iteration reproduction shows
the lock-contention path deciding and exiting in about 0.6 seconds, but CI
timed out a correct exit-2 run with empty stdout while the script's own log
already held the contention line, so the runner stalled while the failure path
created its small log and result files rather than the script doing slow work.
Give that caller 120 seconds and leave the helper default at 30 so the other
call sites still fail fast; neither runs a script that creates files on the
path this stall depends on.

Also fix the timeout diagnostic. It seeded the cleanup message with "Root
process exit confirmed." and only replaced it when cleanup threw, so every
timeout report claimed a confirmed exit no matter what happened. Sample
HasExited before killing, report the observed state, append rather than
overwrite when cleanup races the process exiting, and add the final exit code
once it is known. Note that killing discards PowerShell's buffered stdout so a
future reader does not mistake an empty output section for a silent script.
Cache the process id up front to keep the diagnostic path off live process
state.

scripts/Uninstall-LocalGateway.ps1 is intentionally unchanged; it already
aborts and exits under contention, and its shared read lock is required by the
sibling parentShare: Read case.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b5aa05ec-0a5a-461e-aef9-52c6a9c92ba2
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. 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 Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex review: blocked before merge. Reviewed September 28, 2026, 6:55 PM ET / 22:55 UTC (Revision 2).

ClawSweeper review

What this changes

The branch gives the migration cleanup test a 120-second subprocess deadline, improves its timeout report, and updates the test-coverage guide.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open. Current main still has the 30-second test deadline, and the follow-up commit resolves the earlier documentation finding. The timeout diagnostic retains a small kill-race error, and the required full build has not completed on this head.

Priority: P3
Reviewed head: bb214a94b3087a87833e73d19344bb5b7dd51680

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused real-script validation supports a small, well-scoped patch, with one minor diagnostic correction and full-build validation outstanding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The updated connection test invokes the real Windows PowerShell uninstall script with an isolated lock fixture; the contributor reports 53 focused tests passing on this head after the earlier CI timeout. A slow-runner stall and the kill race were not separately captured. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The updated connection test invokes the real Windows PowerShell uninstall script with an isolated lock fixture; the contributor reports 53 focused tests passing on this head after the earlier CI timeout. A slow-runner stall and the kill race were not separately captured. No stored-data contract changes.
Evidence reviewed 7 items Introduced test change: The five-case cleanup theory now passes a 120-second deadline; the helper default remains 30 seconds.
Prior finding resolved: The new guide text describes both the 30-second default and the cleanup theory’s 120-second override. The previous reviewed head differed from this head only in this documentation file.
Kill-race diagnostic: The message says the process was killed before Kill runs. If the process exits after the HasExited sample, Kill can fail and the report can contain both that assertion and a cleanup-failed message.
Findings 1 actionable finding [P3] Report a kill attempt separately from a confirmed kill
Security None None.

How this fits together

The connection test suite launches the real Windows PowerShell uninstall script with isolated migration files and a held lock. It checks the script’s exit and preservation behavior before reporting a test result to CI.

flowchart LR
  A[Migration test fixture] --> B[Held preparation lock]
  B --> C[PowerShell uninstall script]
  C --> D[Process deadline]
  D --> E{Exited in time?}
  E -->|Yes| F[Assert exit and preserved files]
  E -->|No| G[Terminate process and report diagnostics]
Loading

Before merge

  • Report a kill attempt separately from a confirmed kill (P3) - This string asserts that the root process “was killed” before Kill executes. If the process exits between the HasExited sample and Kill, cleanup can report a failure while retaining that false assertion. This diagnostic race was also visible in the earlier reviewed head; I missed it in that review.
  • Resolve merge risk (P1) - The repository-required full build has not completed on this head: local package restore failed, while the supplied CI state skipped the full-build lane.
  • Complete next step (P2) - Correct the kill-race diagnostic and obtain a completed repository build before merge.

Findings

  • [P3] Report a kill attempt separately from a confirmed kill — tests/OpenClaw.Connection.Tests/MigrationRecordTests.cs:545-546
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Cleanup test deadline 5 cases: 30 to 120 seconds; helper default: 30 seconds The longer wait is confined to one theory, though it affects all five of its cases.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the scoped deadline, make the diagnostic distinguish a kill attempt from confirmed termination, and complete the required build on a host that can restore the package.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the scoped deadline, make the diagnostic distinguish a kill attempt from confirmed termination, and complete the required build on a host that can restore the package.

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

No independent slow-runner reproduction was established in this read-only review. Current main has the reported 30-second path, and the PR supplies the failing CI observation and Windows PowerShell test runs.

Is this the best way to solve the issue?

Mostly yes. A caller-scoped deadline preserves the other tests’ fast failure, but the kill-result wording should reflect what cleanup actually confirmed.

Full review comments:

  • [P3] Report a kill attempt separately from a confirmed kill — tests/OpenClaw.Connection.Tests/MigrationRecordTests.cs:545-546
    This string asserts that the root process “was killed” before Kill executes. If the process exits between the HasExited sample and Kill, cleanup can report a failure while retaining that false assertion. This diagnostic race was also visible in the earlier reviewed head; I missed it in that review.
    Confidence: 0.91
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is correct
Overall confidence: 0.87

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 19d317e5398a.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is a narrow test-reliability and diagnostic change with no production-code change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 updated connection test invokes the real Windows PowerShell uninstall script with an isolated lock fixture; the contributor reports 53 focused tests passing on this head after the earlier CI timeout. A slow-runner stall and the kill race were not separately captured. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated connection test invokes the real Windows PowerShell uninstall script with an isolated lock fixture; the contributor reports 53 focused tests passing on this head after the earlier CI timeout. A slow-runner stall and the kill race were not separately captured. No stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj --filter FullyQualifiedName~MigrationRecordTests.
  • [P1] ./build.ps1.
  • [P1] dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore.
  • [P1] dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore.
  • [P1] ./scripts/validate-docs.ps1.

What I checked:

Likely related people:

  • Natalie Aguinaldo: Raw commit 5a59535 adds tests/OpenClaw.Connection.Tests/MigrationRecordTests.cs:385 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5a59535216ee; files: tests/OpenClaw.Connection.Tests/MigrationRecordTests.cs)

Rank-up moves

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

  • Make the timeout message report the observed state and the actual kill outcome.
  • Complete the repository-required full build on a host that can restore Microsoft.WindowsAppSDK 2.5.1.

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 (1 earlier review cycle)
  • reviewed 2026-09-28T22:41:33.690Z sha cc7fec9 :: blocked before merge. :: [P3] Update the documented cleanup-test deadline

The coverage guide still described a flat 30-second subprocess deadline for
MigrationRecordTests. The helper default is still 30 seconds, but the cleanup
lock-contention theory now overrides it to 120 seconds because its failure path
writes log and result files a loaded runner can stall on. Record both, and note
that timeout reports now include the observed process state.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: b5aa05ec-0a5a-461e-aef9-52c6a9c92ba2
@bkudiess
bkudiess merged commit 0158970 into openclaw:main Sep 28, 2026
23 checks passed
@natalie-aguinaldo
natalie-aguinaldo deleted the user/natalie-aguinaldo/fix-migration-script-exit-flake branch September 28, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants