Skip to content

session host: a signal between the child's reap and its record is treated as one after - #517

Merged
SSFSKIM merged 2 commits into
masterfrom
fix/session-host-reap-race
Nov 7, 2026
Merged

SSFSKIM merged 2 commits into
masterfrom
fix/session-host-reap-race

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Fixes the TestASignalAfterTheReapIsRefused flake: 9 reruns of the static job on trees whose native/session-host matched master. The latest was static run 42389297575.

The cause, and why the fix is in the host

wait() records the reap under mu right after cmd.Wait() returns. A signal sent between those two steps passed signallable() and reached the kernel, which no longer knows the pid, so the reply was signal: no such process. A real client can hit this whenever its signal lands as the engine exits; it is the same microsecond that D66(3) accepts for pid reuse. So the host is fixed (option b), not the test's wait.

Two more cases came up along the way.

  • Linux. dash has no job control without a tty, so the child's descendants stay in its process group, as an engine's tool processes do. Between the reap and its record, a group signal reached those live descendants. The record would have refused that signal. This failed the first gate run (42391503459).
  • macOS. Signalling the group of a zombie that has no live member returns EPERM, not ESRCH. I probed this locally. It means a group signal between the child's exit and its reap came back as signal: operation not permitted.

The change

  • signalChild (host/signals.go) is the one way the host signals its child. It treats a child that is already gone as gone, not as an error:
    • On ESRCH it reports the child gone.
    • It signals the group only while the child itself still answers kill(pid, 0).
    • A group EPERM counts as gone only when that probe succeeded (the macOS zombie case). A live child that refuses on its credentials refuses both.
  • A writer's signal that finds the child gone is answered no running child, the same answer as after the record.
  • The host's own SIGTERM relay, when it finds the child gone, waits only for the reap's record. It no longer waits out the grace. This is the same path as a child already reaped: the roster entry is removed and nobody is signalled.
  • reaped is now a channel, so the relay can wait on it. afterReap is a test seam, like beforeSpawn.

Tests

The three after-the-reap tests now each run twice: once with the reap recorded, and once with the record held open by the seam. Both paths are deterministic. Other changes:

  • The fixture leaves its descendant in the child's group on both platforms.
  • The recorded cases assert that no signal is attempted. The unrecorded writer case asserts that no exit follows, which shows the descendant received nothing.
  • TestASignalToAnExitedChildFindsItGone pins the kernel replies that signalChild relies on, using a real zombie and then the reaped child.

Each regression fails at least one test:

  • master's plain kill: every unrecorded case fails with the CI message, and the kernel test fails.
  • the group probe removed: the unrecorded cases fail.
  • the guard bypassed at both call sites: the recorded cases fail.

Local runs (macOS, Go 1.25.3):

  • before: widening the window by 50 ms in a scratch copy fails all three tests, 20 of 20 runs.
  • after: -count=300 gives 300/300 for both subtests; -race -count=100 passes all four tests 100/100; go vet is clean; go test -race ./... passes.

The prebuilds are rebuilt, and 3 of 3 match their source. The tech-debt row for this flake is removed.

Gate: --gates static,unit,probes, run 42393161302 on bbf6bc8, green; the Linux Go tests pass. The earlier run, 42391503459 on bd755d7, is the one that found the Linux group case. Its unit 2/4 failure was the known desk-hub audience-reads flake.

Still open

The pid-reuse microsecond that D66(3) accepts is still there. Closing it would mean reaping under mu, for example wait4(WNOHANG) driven by SIGCHLD in place of cmd.Wait(). That is a reaper redesign, which this PR does not do.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)

… of it is treated as one after (TestASignalAfterTheReapIsRefused's flake, 9 static reruns). The kernel's refusal of a child already gone (ESRCH; on macOS a zombie's group, EPERM) reads as gone: a writer's signal is answered 'no running child', the host's own SIGTERM relay waits only for the reap's record, not the grace. The three after-the-reap tests run with the reap recorded and held unrecorded by a test seam (afterReap), so both paths are deterministic; a kernel test pins the refusals childGone reads. Prebuilds rebuilt (3 of 3 match); the tech-debt row closes.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…x CI, 42391503459): dash without a tty leaves a descendant in the child's group, as an engine's tool processes are, and a group signal between the reap and its record reached it. signalChild probes the child first and reads the kernel's refusals; the fixture leaves its descendant in the group on both platforms, the recorded cases assert no signal is tried, and the unrecorded writer case that no exit follows (the descendant took nothing). The PID 1 credentials case is gone (a container's init may share the test's uid). Prebuilds rebuilt (3 of 3 match).

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T17:00:26.025203Z bbf6bc8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SSFSKIM
SSFSKIM merged commit 6f89f9d into master Nov 7, 2026
@SSFSKIM
SSFSKIM deleted the fix/session-host-reap-race branch November 7, 2026 19:53
SSFSKIM added a commit that referenced this pull request Nov 7, 2026
…eek runs on M7b, M6a and #517; the render readings over DAEMON_IDLE_BOUND attributed, the fix in flight

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
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