Skip to content

test(launcher): WaitForPidAsync names its role, bound and stderr on timeout - #889

Merged
Blind-Striker merged 1 commit into
masterfrom
tests/787-waitforpid-timeout
Nov 15, 2026
Merged

Blind-Striker merged 1 commit into
masterfrom
tests/787-waitforpid-timeout

Conversation

@Blind-Striker

@Blind-Striker Blind-Striker commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #787

The #789 review found that LadderTree.WaitForPidAsync (tests/OpenCode.Sdk.Tests/Hosting/Launcher/Support/LadderTree.cs) surfaced a bare TaskCanceledException naming no role and no stderr when its hang guard fired, while the non-waiting LadderTree.Pid names both. This PR fixes that finding and leaves the issue open: it stays open for its 14-day quiet window from the 2026-11-05 sighting, and the coordinator ends it by hand on 2026-11-19 if no new sighting appears.

Change

  • When the guard's cancellation makes the pause throw, the helper throws TimeoutException: The ladder tree reported no '<role>' pid within <seconds> s: <stderr lines joined with " | ">. Seconds use the invariant culture, as ServerStartupTreeHandshake.HandshakeStep.Timeout formats its bound; stderr is a fresh snapshot read in the catch; the caught cancellation is the inner exception. The catch wraps only the pause and filters on the guard's own token.
  • The guard and the pause run on a TimeProvider through a new overload, so the timeout can be tested on ManualTimeProvider (testing-style.md: "The event decides a verdict, never the clock"). The three-argument method the nine callers use chains to it with TimeProvider.System; their success path is unchanged (read before pause, fresh Pids(output) each turn, 10 ms pause). The #if NET split for the delay follows the six existing src sites.
  • tests/OpenCode.Sdk.Tools.Tests/RepositoryGates/real-clock.txt: LadderTree.cs drops from 2 real-clock sites to 1 (the guard no longer sees new CancellationTokenSource(hangGuard); it still counts the NET arm's Task.Delay(..., time, ...)).

Tests: Support/LadderTreeTests.cs (new, mirror rule)

  1. WaitForPidAsync_Should_Name_The_Role_Bound_And_Stderr_When_The_Guard_Fires: one stderr line before the wait and one after it starts; the wait is asserted incomplete once the guard is armed and before the clock moves; then the exact message and an inner cancelled OperationCanceledException.
  2. WaitForPidAsync_Should_Return_The_Pid_That_Arrives_During_The_Wait: the pid line arrives after the pause is armed; the exact pid comes back.

Red proof (worker, with analyzers): with only the catch removed, test 1 fails at Throws<TimeoutException> because a TaskCanceledException arrives, on net472, net10.0 and net11.0; test 2 passes either way.

Verification

  • Full local check on the pre-squash head b6f704fb, under the machine's gate lock: slopwatch, Release build, both format passes, clone gate, OpenCode.Sdk.Tools.Tests, and the whole OpenCode.Sdk.Tests filter ((Category!=ServiceElection)&(Category!=NativeAot)): 12,631/12,631.
  • Recheck on this head 94a9f4c2 (squash and one doc-comment change): static steps, Tools tests 2,792/2,792, and LadderTreeTests 2/2 on each of net472, net10.0 and net11.0.
  • Reviews: Sol contradiction scan of the brief (moved the verdict onto ManualTimeProvider, added the mid-wait cases); Opus review of the diff (no blocker or major; two minors fixed).

…imeout

When its hang guard fires, LadderTree.WaitForPidAsync now throws a
TimeoutException instead of a bare TaskCanceledException:
"The ladder tree reported no '<role>' pid within <seconds> s: <stderr lines
joined with ' | '>", seconds in invariant culture, stderr read fresh in the
catch, the caught cancellation as the inner exception. The catch wraps only
the pause and filters on the guard's own token.

The guard and the pause run on an injected TimeProvider through a new
overload; the three-argument method the nine callers use chains to it with
TimeProvider.System, so their success path is unchanged.

LadderTreeTests runs both cases on ManualTimeProvider: the named timeout
(with a stderr line appended after the wait starts and the wait asserted
incomplete before the clock moves) and a pid that arrives during the wait.

real-clock.txt: LadderTree.cs drops from 2 sites to 1. The guard no longer
sees new CancellationTokenSource(hangGuard); it still counts the NET arm's
Task.Delay(..., time, ...).

Refs #787
@Blind-Striker Blind-Striker added this to the Next milestone Nov 15, 2026
@Blind-Striker
Blind-Striker added this pull request to the merge queue Nov 15, 2026
Merged via the queue into master with commit faf56f4 Nov 15, 2026
15 checks passed
@Blind-Striker
Blind-Striker deleted the tests/787-waitforpid-timeout branch November 15, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant