Skip to content

fix(core): keep zombie leaders with live threads in containment; deflake boot mode test - #330

Merged
ElbertePlinio merged 11 commits into
mainfrom
fix/322-328-containment-zombie-boot-log
Oct 12, 2026
Merged

ElbertePlinio merged 11 commits into
mainfrom
fix/322-328-containment-zombie-boot-log

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Containment cleanup now treats a zombie thread-group leader that still has live threads as present, using the same num_threads > 1 rule as the group stop in proc.ts. Such a leader's own /proc/<pid>/environ cannot be read: depending on the kernel it fails with ESRCH (7.2) or EACCES (6.17 on the CI runner), or reads as empty. When the stat shows state Z with more than one thread, containment reads the environment through a live thread, so the normal token and foreign-member checks still run. A process that is live again by the time of the stat read, for example after a surviving thread exec'd, stays unverified and is never reported gone. The Android boot-mode test no longer races the fake emulator's log line.

Closes #322
Closes #328

Requirement Verified by Scenario Result Evidence
#322: decide whether a Z with live threads counts as present Automated test, real kernel Python fixture whose main thread calls pthread_exit while another thread runs. The host kernel shows State Z, Threads 2, and /proc/<pid>/environ returns ESRCH. A live thread's task/<tid>/environ reads normally. Yes: Z with num_threads > 1 is present. Z with one thread stays gone. "cleans up a real zombie leader with a live thread" in containment.test.ts fails on main with expected [] to include <pid> and passes here
#322: effect on cgroup emptiness and #310 foreign-member rules Automated tests A proven zombie leader is signalled. A foreign zombie leader with a running thread is refused and not signalled. An unreadable thread environment gives "unknown", which is refused. A "gone" verdict still waits for the PID to leave cgroup.procs. Emptiness is not declared while the zombie's threads live. Foreign and unknown members are never signalled. containment-cgroup-sim.test.ts: "signals a proven zombie leader…" and "refuses a foreign zombie leader…". Both failed on main.
#322: containment does not report a Z member with live threads as gone Automated tests Marker path with a mocked zombie whose leader environ fails with ESRCH or EACCES, or reads as empty, plus the real-kernel test above on the host (7.2) and the CI runner (6.17) Pass. The EACCES and empty cases failed before their fixes. containment.test.ts
#322: an exec between reads is not taken as gone Automated test A live single-thread process whose environ fails with ESRCH Cleanup is not confirmed. The process stays a survivor and gets no signal. "does not call a live process gone when its environ fails with ESRCH" fails at 4d692b1
#328: decide between a product fix and a test fix Code review A real emulator logs the snapshot line before the guest can answer getprop sys.boot_completed. detectBootMode output is only reported. Test-only fix: the fake adb reports boot only after the snapshot line is in the log emulator.test.ts
#328: keep the warm and cold assertions Automated test Warm and cold boot runs Unchanged and passing emulator.test.ts
#328: holds under concurrent runs Stress runs 20 sequential runs plus 3 rounds of 8 parallel runs under 16 CPU busy loops (44/44). The old test fails with an injected 0.3 s log delay, and the new one passes with it. Pass Local runs
Repo checks Full suite with coverage, tsc, oxlint, build, PickCheck PICKFORGE_REQUIRE_BROWSER=1 vitest run --coverage 3094 passed, 6 skipped. Typecheck, lint and build pass. PickCheck has no new or worsened findings (one unchanged existing warning in listContainedIdentities). Local run at da7fb35. Later commits change only test text and merge main's osv-scanner.toml.

QA pass skipped: this changes internal process-teardown logic with no UI or CLI output to drive. The real-kernel test exercises the behaviour end to end.

Reviews: Astra and Fable (xhigh) both reviewed every round. Fable asked for a real-kernel test, which then showed that the runner kernel answers with EACCES. Astra found an exec race between the environ read and the stat read, fixed in 981be6c. Both reviewers confirmed every fix, and the last rechecks found nothing blocking. Fable's suggestion to share the zombie rule with proc.ts waits until the parallel proc.ts change lands.

A zombie thread-group leader can still have live threads. Its own environ
fails with ESRCH, so containment probes treated it as gone and could
confirm an empty scope while its threads ran.

Count a zombie as gone only when num_threads is at most one. Read the
environment of such a leader through a live thread, so it goes through
the normal token and foreign-member checks.

Closes #322
…shot line

The fake adb reported a finished boot at once, so startEmulator could read
the log before the fake emulator wrote its snapshot line and report an
unknown boot mode. A real emulator logs that line before the guest can
report boot, so gate the fake adb on it.

Closes #328
…t reads empty

Some kernels return an empty environ for a thread-group leader that has
no memory of its own, instead of failing with ESRCH.
…es it exec

A surviving thread can exec between the environ read and the stat read.
A live process then proves nothing, so do not report it gone.
…nviron

On kernel 6.17 a zombie leader's own environ fails with EACCES, while a
live thread still shows the environment.
@ElbertePlinio
ElbertePlinio merged commit 421adda into main Oct 12, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/322-328-containment-zombie-boot-log branch October 12, 2026 15:59
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.

test(android): boot mode test can read the emulator log before the snapshot line core: containment probes treat a zombie with live threads as gone

1 participant