Skip to content

fix(windows): reclaim runtime trees after root exit - #12005

Merged
bolichen97 merged 1 commit into
mainfrom
fix/windows-runtime-root-exit
Sep 20, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/windows-runtime-root-exit

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

On Windows, closing a session after its root process had already exited could leave the agent and MCP child processes running. The direct client returned early, and the shared runtime tried to stop a root that was already gone. Each repeat left more abandoned processes and memory behind. A follow-up review then showed the first fix's failure state was itself unbounded: a tree whose cleanup kept failing retained handles forever, and nothing stopped new trees from being admitted on top of that debt.

Why it matters

A dead root is not evidence that its children have stopped. A self-owned three-generation Python tree reproduced two surviving descendants after the previous cleanup paths returned. PR #11935 added simulated regression contracts, not native Windows reclamation. And a retry registry with no ceiling turns "we never lose an identity" into "we can never stop growing".

What changed (motivation -> approach -> change)

Closing a Windows session stops its children even if the root has exited. Cleanup keeps the original process identities, checks which children belong to that tree, and confirms they have stopped before reporting success. If cleanup fails, it keeps only the handles needed to retry, even after the session object is discarded; the existing maintenance tick retries those trees without letting a busy or refused tree block its peers, and retires tracking while the exact root handle still pins the incarnation.

On top of that, Windows cleanup bookkeeping is now bounded and admitted up front:

  • Admission before spawn. A Windows physical ACP start atomically reserves a cleanup slot before the spawn await. _WINDOWS_CLEANUP_ROOT_LIMIT (64) counts starting, live, failed and quarantined trees together, so simultaneous failures cannot exhaust the space needed to keep already-admitted roots. Only an empty failed-launch reservation or an exact-handle-verified retired tree is refunded.
  • Capture at process creation. The cleanup owner receives the native process handle at the successful CreateProcess return, before CPython publishes the Popen handle or connects pipes. A failure after creation still publishes the owner for maintenance; a failure before creation refunds the empty reservation. Only the standard CPython Proactor subprocess implementation is admitted here; any other refuses before creation. The exact handle is recorded before the tree's identity is read, and that read runs on subprocess_executor() rather than the starting loop, so a child that dies as it resumes cannot stall the loop serving every other session. Recording the handle first is what makes the hop safe: a cancellation during the read still leaves that child retained.
  • Bounded retained state. _WINDOWS_CLEANUP_IDENTITY_LIMIT (4096 exact objects per tree, root included) bounds retained handles, signalled identities and terminal-scan identities together; Toolhelp enumeration is bounded at _WINDOWS_CLEANUP_SNAPSHOT_LIMIT (65536) during the walk, not after allocating the whole table. Overflow is incomplete evidence, never an empty tree.
  • Manual-handling quarantine. Any identity/snapshot overflow permanently marks that tree manual-handling-required in this gateway process: it keeps its pins and tracking, is never refunded or retried, and new Windows physical starts are refused while any such mark exists. Other admitted trees keep draining. Ordinary transient failures without overflow still retry automatically.
  • Liveness decided by a zero-timeout handle wait. Exit code 259 is both STILL_ACTIVE and an ordinary exit status, so a child returning it read back as running forever and no drain could reach a terminal scan. A zero-timeout WaitForSingleObject is now authoritative wherever the handle carries SYNCHRONIZE; query-only callers, whose handles cannot be waited on, keep the exit-code reading.
  • The start-time identity read stays off the event loop. get_process_start_id publishes itself as non-blocking, so its Windows arm asks the handle read for the creation half alone -- the whole identity -- with no liveness wait and no exit-FILETIME poll. Drain callers keep the exit bound and the poll.
Case Before After
Windows root exits first Children could remain running Verified children are stopped and checked
Cleanup is refused, then the owner is discarded Retry identity could be lost Exact handles survive for the existing maintenance tick
Tracking removal fails No independent completion receipt Keep the pin and retry without blocking peers
Process created, later launch step fails Child could escape cleanup ownership Owner captured at CreateProcess, published for maintenance
Permanent cleanup failure / descendant overflow Retained state grew without bound Bounded; tree quarantined, new Windows starts refused
Mac/Linux teardown and resource limits Existing behavior Unchanged

An unfinished cleanup keeps enough identity to try again; a missing root cannot hide its children; and the bookkeeping that makes that promise now has a ceiling.

Backwards compatibility

Behavior change on Windows (intentional, maintainer-approved): three new refusal conditions exist that did not before.

  1. More than 64 concurrently admitted Windows physical trees (starting, live, failed or quarantined) refuses a new start with WindowsCleanupCapacityError.
  2. After any tree overflows its identity or snapshot budget, all new Windows physical starts are refused in this gateway process until an operator has independently accounted for and stopped the workload and restarted the gateway. This is bookkeeping quarantine, not OS isolation: unobserved descendants may still run, no API clears the mark, and deleting tracking files is not recovery. The transition emits an error with the root PID and retained count, and the refusal itself names the quarantined root PID and the restart remedy: the refusal outlives the tree that caused it, so an operator meeting a failed session start hours later does not have to find the log line.
  3. A non-Proactor asyncio loop implementation refuses the Windows physical launch before creation.

The capture predicate reads private CPython shapes, so it is version-coupled, and the coupling is measured rather than assumed. The shipped coroutine was lifted out of platform_compat.py by AST and run unmodified on stock Windows CPython 3.12.10, 3.13.15 and 3.14.7 (official python.org amd64 builds, unpacked verbatim, sha256 d1f04d99...a2cf and d297e5ff...1f15): each one admitted the launch, spawned a real child, and captured that child's own pid, exact handle, reference-counted pin and (pid, 0) identity, while the same call on a SelectorEventLoop was refused before creation in the same run. A later interpreter that reshapes those internals refuses tracked Windows starts instead of silently capturing nothing; re-running that measurement is the gate for adopting one, and its committed form is test/test_runtime_cleanup_windows.py::test_native_admission_and_owner_shutdown_refund_after_verified_drain, which spawns a real admitted tree through this capture on whichever interpreter is running. It runs on the Windows shards, so a minor that reshapes these internals turns adoption into a failing check rather than an archaeology exercise.

Everything else is compatible for confirmed, owned trees: no configuration, dependency, credential, permission, timeout, pool size, RSS ceiling or Job limit changes; no new background timer or service; POSIX teardown and untracked Windows launches keep their original path. Windows cleanup failures are not success. An unreadable or missing original identity never authorizes killing a numeric PID. This is not gateway-crash recovery and cannot reconstruct an intermediary that disappeared before any handle observed it.

Tests

Implementation: src/kiro_crew/platform_compat.py; integration: src/kiro_crew/acp/runtime.py, src/kiro_crew/acp/client.py, src/kiro_crew/session_pid.py, src/kiro_crew/sandbox.py (5 lines: create_subprocess_limited accepts an optional cleanup owner and, on Windows, routes an owned launch through the owned creation path; unowned launches are unchanged). The two existing stale-reap calls in src/kiro_crew/apps/backend.py also consume kill_process_tree_pinned; they inherit exact-handle draining and same-process retry, not app-specific crash-durable retirement.

New/changed tests:

  • test/test_windows_cleanup_capacity.py (new): concurrent reservation across threads/loops, capacity exhaustion refuses a new start without dropping existing handles, launch failure/cancel refunds only empty reservations, cancelled launch takes ownership of a returned child, refund after verified retirement, post-creation failure publishes the owner, identity/snapshot overflow -> sticky quarantine, quarantine excluded from retries and never reports success, non-Proactor loop refusal.
  • test/test_windows_tree_reap.py (new): late-child discovery, final post-exit scans, unknown identities, unsuccessful draining, repeated cancellation, retained intermediary handles, duplicate attempts, busy-state fairness, failed metadata-write fairness, retirement while the root handle is still open (tests inspect handles, not PIDs or return codes).
  • test/test_runtime_cleanup_windows.py (new, native): repeated three-generation teardown, root-first exit through shared runtime and direct client, synchronous fallback, independent child process groups, an unrelated surviving control, and a refused drain that survives owner-reference removal and completes through the real maintenance entry.
  • test/test_pid_lifecycle.py: the synchronous Windows refusal contract moved out of the POSIX-only class; both an unpinnable identity and a failed drain must avoid pinned-root, unpinned-root and unpinned-tree fallback. Restoring the base implementation fails this at the forbidden root-only call.
  • test/acp_launch_capture.py (test harness): the launch-goldens capture stubs create_windows_cleanup_owned_process as a passthrough for both the client and runtime capture paths. Without it the harness's handle-less MagicMock child was classified as manual-handling debt and poisoned every later spawn in the same pytest worker (found by the local backend batch run, below). The admission is a collaborator with its own tests above, not a launch answer; production code did not change for this.

Negative controls: restoring either old root-exit path fails at the surviving-descendant assertion without a teardown error; the owner-drop, metadata-fairness, creation-boundary and goldens-poisoning regressions each failed before their fix.

Not in this diff: .github/black-baseline.txt is unchanged, so test/test_app_backend_stale_reap.py stays listed. That file is not Black-clean at the repository's configured line-length = 100 (five pre-existing spans would be reformatted), while the two lambda signatures this change edits inside it already match Black output. The gate needs no new exemption here, and none of that unrelated formatting churn is carried.

Local validation on this head (rebased onto a4e397193, Windows Server 2025, Python 3.12):

  • Python: compile of all changed files, repo Black gate, isort, flake8, full mypy (1,647 source files) pass; wheel build succeeds with changed production blobs byte-identical.
  • Frontend: all 12 static/build gates; Electron 1,950 passed / 5 skipped; related vitest set 1,272 files, 24,848 passed / 2 skipped.
  • Core Windows lifecycle group on this head, run serially (-n 0, one process per file): 493 passed / 370 skipped / 0 failed across test_platform_compat, test_platform_compat_coverage, test_xdist_auto_cap, test_windows_cleanup_capacity, test_runtime_cleanup_windows (native), test_windows_tree_reap, test_acp_runtime_kill and test_acp_launch_goldens. Earlier heads of this branch additionally ran test_acp_runtime (425 + 1 xfail), test_acp_spawn_offload (24) and test_runtime_cleanup_regression (5) green in the same serial shape. test_platform_compat_coverage skips itself on Windows by design (it simulates POSIX attributes that do not exist here and is coverage-measured on the ubuntu shards), so its TestWindowsHandleIdentity cases were additionally executed on this host by calling them directly with a real MonkeyPatch: 14/14 pass, and stripping WaitForSingleObject from the fake fails exactly the four cases that read liveness.
  • Three pre-existing test doubles were taught the call the identity read now makes. Deciding liveness by a zero-timeout wait means the two kernel32 fakes that drive _windows_process_handle_identity must answer WaitForSingleObject; the coverage fake derives it from the exit code it already scripts (WAIT_TIMEOUT for live, WAIT_OBJECT_0 for exited) with an override so a test can script a handle that cannot be waited on, and two new cases pin the branches the fix introduced -- an exit status of 259 read as exited, and a query-only handle falling back to the exit code. Separately, test_xdist_auto_cap's two spawn-env tests mock asyncio.create_subprocess_exec, which the Windows owned-capture route does not go through, so they now also stub the capture seam to its POSIX pass-through; without it they attempted a real launch of the fixture's synthetic binary.
  • Backend related set (1,742 files, 28 batches of <=64 files): batches 0-2 passed (5,940 passed / 500 skipped / 7 xfail); batch 3: 3,323 passed / 29 skipped / 13 xfail / 5 failed, where all 5 failures are test-internal python.exe child launches returning 0xC0000142 (STATUS_DLL_INIT_FAILED) in test_agent_home_isolation / test_agent_lifecycle_cycle subprocess probes; batches 4-27 were not run locally. The gateway hosting this session runs in Windows Session 0 with a 768 KB non-interactive desktop heap, and concurrent console-child spawning from xdist workers exhausts it (the pytest re-run child and git rev-parse died with the same status). No host setting was changed. Remote CI's Linux/Windows/macOS backend shards are the coverage for those batches; one earlier batch-4 failure was a sandbox carve-out refusal caused by pytest's basetemp sitting under a masked scratch path, logic this PR does not touch.
  • Local model review: two independent read-only lanes on this content (gpt-5.6-sol, claude-opus-4.8), each given the repository's own CI review contract. Both report no code findings; the Opus lane raised and then falsified three candidates itself (a preexec_fn crash on the Windows spawn, double-retirement in maintenance, a stranded drain after a cancelled kill). The GPT lane raised two documentation-accuracy findings, both verified true against the code and corrected in this commit: platform-compat.md had overclaimed that incomplete ancestry is always a refusal (a live grandchild whose only edge ran through an intermediary that exited before the first Toolhelp scan is invisible to the walk, so completeness is scoped to retained/observed members and that residue stays with the pre-existing orphan sweep), and acp-client.md still justified the POSIX-only escaped-child sweep by taskkill /T walking the tree, which this PR's _kill_process does not do on Windows. On a later head the CI GPT lane raised two blocking findings that were both upheld and both fixed here rather than rebutted: a PID-file sweep that retired rows still owned by a pending cleanup pin, and the identity read above running on the event loop. Each carries a regression test that fails when only the fix is neutralized.

Manual verification

The native tests use real Windows kernel processes and pair each PID with its original creation FILETIME. They are Python stand-ins, not authenticated Kiro CLI/model turns. Assertions run before the independent fixture finalizer. No existing gateway or user session was restarted or terminated. Native macOS execution was not verified on this Windows host.

Related Issues

Follow-up to PR #11935. Windows counterpart to PR #11720, without absorbing its POSIX process-group implementation. Scope of the capacity admission and manual-handling quarantine was agreed on this PR after the GPT lane's a-bound-bounds-every-field-it-retains finding.

Pattern harvest

Rule candidate: review-prompt
Pattern: A dead root or successful termination call does not prove tree cleanup; exact identity ownership must survive failure, remain pinned through tracking retirement, and every retained-identity container needs a declared ceiling with a defined overflow behavior that never reports success.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing relevant lifecycle tests pass and new tests added for the Windows behavior; locally unverified backend batches are disclosed above
  • Self-review completed; code follows project style guidelines
  • Documentation updated (docs/system-specs/common/platform-compat.md, acp-client, app-kit-platform, security, session)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and iamwhatever September 19, 2026 10:22
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 19, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Intent: Reclaim verified Windows agent/MCP descendant trees when their runtime root exits first, and preserve exact cleanup identity through a failed attempt until the existing maintenance path can finish.
Not a goal: POSIX teardown redesign, resource-limit or permission changes, a new background service, gateway-crash recovery, or proof of authenticated Kiro CLI/model turns.

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 67f12d29a8269ff1ad87de35c6682c88a337fb8d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 67f12d2

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 67f12d29a8269ff1ad87de35c6682c88a337fb8d: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 67f12d29a8269ff1ad87de35c6682c88a337fb8d — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The quarantine's process-wide start refusal is stricter than its named harm — the 64-slot admission cap this same PR adds already bounds that debt.

Not justified as shipped

  • Item 4 — oversized: the support given is "nothing stopped new trees from being admitted on top of that debt," but the diff's own admission cap answers that — quarantined trees keep their reservation (release_windows_tree_reservation refuses refund on manual_required) and count against _WINDOWS_CLEANUP_ROOT_LIMIT, so retention is already capped at 64 trees × 4096 identities; blanket refusal after ONE overflow rests only on the description's unverifiable "intentional, maintainer-approved."
    Subtraction: delete the manual-roots refusal block in reserve_windows_tree_cleanup (src/kiro_crew/platform_compat.py); per-tree quarantine plus the held slot already refuses starts once quarantined debt fills capacity.
    Clears when: a named harm from admitting new trees while one tree is quarantined that the slot cap does not already contain — or the deletion made.
  • Item 9 — rides along: a pre-existing event-loop stall (get_process_start_id's exit-FILETIME poll) fixed alongside the reclamation fix; declared and tested, no premise risk.

What this change ships

Inventory (10 items) — 8 justified

Intent: Closing a Windows session must actually stop its agent/MCP children even when the root already exited, with the cleanup bookkeeping bounded — a FIX (reproduction described, native failing-on-base Windows tests added, PR #11935 linked).

  1. Windows session close now stops the whole child tree even after the root exited — justified
  2. A failed cleanup keeps exact handles; the existing maintenance tick retries and retires tracking — justified
  3. More than 64 concurrent Windows trees refuses a new session start — justified
  4. One identity/snapshot overflow refuses ALL new Windows starts until gateway restart — oversized (see above)
  5. Unmeasured/non-Proactor interpreters refuse Windows launch before creation; premise confirmed on CPython 3.12–3.14 with a committed Windows-CI test — justified
  6. Child ownership captured at CreateProcess return, so a launch failing after creation cannot leak the child — justified
  7. Retained cleanup state bounded: 4096 identities per tree, 65536 snapshot entries — justified
  8. A child exiting with code 259 no longer reads back as running forever — justified
  9. Reading a process's start identity no longer stalls the event loop — rides along (declared, tested, harm-free)
  10. Windows kill/reap paths never fall back to root-only or numeric-PID kills; refusals keep the tree and its PID-file rows — justified

The change has a few more minor differences (client reset refusing an unretired cleanup, sweep guards for pinned rows); list capped at 10, those fold into items 2 and 10. The deleted pin test_windows_fallback_kill_keeps_the_identity_pin is replaced with evidence the old fallback was the defect itself (root-only kill leaves descendants), and the replacement pin is in the diff.

[FIRST-PRINCIPLES-REVIEWED] 67f12d2

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 67f12d29a8269ff1ad87de35c6682c88a337fb8d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify Windows CI shards are green on this head — backend batches 4–27 were not run locally, and the native capture test must execute, not skip.

[DESIGN-REVIEWED] 67f12d2

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 67f12d29a8269ff1ad87de35c6682c88a337fb8d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 67f12d2

Verdict parsed from the review's SHA-scoped output markers for commit 67f12d29a8269ff1ad87de35c6682c88a337fb8d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 67f12d29a8269ff1ad87de35c6682c88a337fb8d: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 19, 2026
@bolichen97

bolichen97 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • App stale-reap consumers span=c88ca923b86d

Disposition: rebutted — the two existing app consumers do not lose same-process cleanup authority or acquire authority over another process. The PR description will explicitly name them.
Both calls in apps/backend.py:_reap_stale_app_backends run off-loop. The supplied base already catches OSError and conditionally removes the old app row; that error contract was not introduced here.
A closed-kernel composition probe exercised the real app caller, pinned helper, pending registry, and cleanup_orphaned_session_roots: temporary refusal returned 0, retained exact root/intermediary handles, and a later maintenance pass completed the tree.
The probe preserved a replacement app generation, another app row, unrelated generic/session PID records and its protected-PID entry. Completion untracks while the exact root is pinned; its PID cannot denote an unrelated live process then.
App-row loss across a gateway crash during refusal is an existing separate durability gap. This PR expressly promises same-process retry, not crash recovery; no app-specific persistence redesign is adopted here.

@bolichen97

bolichen97 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Tripwire cleanup error precedence span=3e6cc5af68ac

Disposition: rebutted as a required change — an incomplete Windows teardown must surface its failure rather than claim that the harness was stopped. The narrower domain-error clarity tradeoff is acknowledged.
Goose startup and Pi tripwire paths are Windows-reachable. The probe reproduces OSError taking precedence over AcpToolGateUnroutable; BASE was not generally non-raising either, although it swallowed ordinary terminate failures.
This does not grant tool authority or suppress the Pi bypass audit: logging/SEL occurs before teardown. The later domain message says the harness was stopped, which is not established when exact cleanup refuses. Retained-state guards continue to reject replacement until cleanup is confirmed.
A separate closed-kernel probe used production _kill_process, maintenance, _reset_state and ensure_ready: refusal kept the pin, maintenance completed it, and the retained client then spawned and initialized a replacement successfully. No cleanup or recovery failure was found.
Preserve the strict cleanup failure and its retained state in this PR rather than add a new cross-harness exception-precedence policy. No security gate is weakened by this disposition.

@bolichen97

bolichen97 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Finite maintenance delay and fairness span=5382d82bde0a

Disposition: rebutted — the probe confirms bounded delay, not starvation or a full timeout on every refusal.
An immediate identity/access/discovery refusal used 0.0 controlled-clock seconds and issued no termination. Eight genuinely non-draining entries consumed 40.05 controlled-clock seconds of polling, consistent with eight finite 5-second attempts; native enumeration/I/O time is not claimed to be preemptible by that budget.
In that same cleanup_orphaned_session_roots invocation, the normal dead-gateway orphan pass still ran and removed its candidate. A healthy ninth pending tree rotated to the front and completed on the next pass. Busy-state locks are tried nonblockingly.
session_cleanup runs the current watchdog tick before this off-loop sweep. Later maintenance can incur the stated delay; that tradeoff remains explicit. Dropping entries at an attempt cap would discard needed identity, and a separate backoff/single-step scheduling policy is not needed to close the demonstrated root-exit leak.

@bolichen97

bolichen97 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Separate Job ownership redesign span=07a2c5930480

Disposition: rebutted as an addition to this PR — retaining resource Job handles and introducing TerminateJobObject teardown changes a separate ownership/containment contract.
The intent explicitly preserves Windows resource Job limits and excludes gateway-crash recovery or reconstructing intermediaries never observed through a handle. The implemented exact-handle path addresses the reproduced owned runtime tree without changing those boundaries.
No Job redesign is approved or scheduled by this change. Such a design would need its own containment, nested-job and ownership evidence rather than being introduced as an advisory-driven extension here.

@bolichen97

bolichen97 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Historical response: the GPT rerun replaced finding 60eee5df9fed in place on the same SHA. Retained below for context; this is not a disposition of the new retention-cap finding.

  • Completed runtime PID retirement span=60eee5df9fed

Disposition: rebutted — consistent with the independent downgrade, the normal successful teardown path has no live-tree or PID-reuse defect at this site.
runtime._kill_inner keeps its local original process object while awaiting both untracks, even after self._process is cleared; the original Popen handle therefore continues to pin that incarnation. The separate legacy client reset still uses its existing _pid_gone_or_unmanaged check and is not claimed to hold this same pin.
Reaching this branch requires a verified complete tree drain. A best-effort PID-file rewrite failure leaves a dead entry for the existing sweep, not an untracked live tree.
The materially different deferred path can outlive its provider: there the maintenance callback must check both write results under the exact root pin, and it already retains state on failure before closing handles. The regression exercises actual _rewrite_pid_file False, not only an invented throwing callback.
No new ordering mechanism is required on the already-completed normal teardown path, and no review override is requested.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Bound pending cleanup ownership span=eeb991b58a1d

Disposition: needs-a-decision. The uncapped registry and nested retained-handle sets are real; the eight-entry retry budget limits work per tick, not retained state.
Dropping or evicting an already-owned failed tree at capacity would reopen the original lost-identity cleanup defect. A complete bound therefore needs admission/reservation before Windows physical process creation, and a bound on retained descendants, not merely truncating the pending dictionary.
Proposed direction: a separate Windows cleanup-capacity budget that refuses new physical runtimes at saturation, preserves all already-owned cleanup identity and recovers capacity after verified drain. Existing timeout/pool/RSS/Job settings would not be changed.
Maintainer decision requested: may this PR introduce that additional startup-refusal condition and its required spawn/retention integration? This extends the published start contract beyond the current root-exit fix; no override or cap implementation is being assumed.

@bolichen97

Copy link
Copy Markdown
Contributor Author

The author has approved adding a separate Windows cleanup-capacity admission budget to address eeb991b58a1d. New physical starts may be refused at saturation and resume after verified cleanup releases capacity. Existing owned handles must not be evicted, and existing pool size, RSS, timeout and resource Job settings stay unchanged. Implementation and regression verification are in progress; this records scope consent, not a review override or a claim that the blocker is fixed.

@bolichen97

Copy link
Copy Markdown
Contributor Author

The author has accepted manual handling for extreme descendant-budget overflow. Normal verified trees and transient failures keep automatic cleanup/retry. If observing a tree would exceed the bounded identity budget, preserve existing pins/tracking, mark cleanup unresolved, do not infer success or automatically refund that capacity, and refuse new Windows physical starts while manual handling is required. This is bookkeeping quarantine, NOT OS isolation or proof that unobserved descendants stopped. Existing pool/RSS/timeout/Job settings remain unchanged. This records scope consent, not a review override or completed repair.

@bolichen97
bolichen97 force-pushed the fix/windows-runtime-root-exit branch from 9639bee to c22c148 Compare September 20, 2026 02:22
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 20, 2026
@bolichen97
bolichen97 force-pushed the fix/windows-runtime-root-exit branch from c22c148 to 29eeeff Compare September 20, 2026 02:35
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 20, 2026
@bolichen97
bolichen97 force-pushed the fix/windows-runtime-root-exit branch from 29eeeff to da93ada Compare September 20, 2026 03:02
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 20, 2026
@bolichen97
bolichen97 force-pushed the fix/windows-runtime-root-exit branch from da93ada to 8418639 Compare September 20, 2026 03:20
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 20, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) September 20, 2026 08:17
@bolichen97
bolichen97 merged commit 1e40f7f into main Sep 20, 2026
100 of 114 checks passed
@bolichen97
bolichen97 deleted the fix/windows-runtime-root-exit branch September 20, 2026 08:17
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 20, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

First Principles disposition — 67f12d29a8269ff1ad87de35c6682c88a337fb8d

  • Item 4 — the process-wide start refusal is stricter than its named harm, because the 64-slot admission cap this PR adds already bounds the quarantined debt. — REBUTTED on the subtraction, ACCEPTED on the record.

    The two caps do not bound the same quantity. _WINDOWS_CLEANUP_ROOT_LIMIT bounds TREES the gateway has admitted; the identity and snapshot budgets bound members it can still NAME. An identity or snapshot overflow is precisely the moment a tree acquires descendants the drain can no longer enumerate, so what grows without bound after an overflow is not retained state — that stays capped at 64 trees x 4096 identities, exactly as the lane says — but LIVE PROCESSES no reclamation path can ever reach again. Refusing only at 64 roots keeps the bookkeeping finite while permitting the one situation this change exists to stop: new trees admitted on top of a tree whose members are no longer knowable.

    The record the lane calls unverifiable prose is on this thread: comment 5743971580, where the author accepted manual handling for extreme descendant overflow in these exact terms — keep the pins and the tracking, never refund or retry that tree, and pause new Windows physical starts until an operator has looked. The clearing condition's own second branch is therefore met by an author decision recorded before the branch was written.

    What the lane identified correctly on the previous head was discoverability, and that was fixed rather than argued: the refusal names every quarantined root pid and the restart remedy instead of leaving an operator one scrolled-away log line.

@bolichen97

Copy link
Copy Markdown
Contributor Author

First Principles disposition — 67f12d29a8269ff1ad87de35c6682c88a337fb8d

  • Item 9 — the non-blocking start-identity read rides along as a second fix. — ACCEPTED; already declared, and it cannot honestly be split out of this PR.

    The lane's own reading is agreed: it is a separate defect, it is declared in the change list, it carries a red-first test, and it poses no premise risk. It is not severable, though, and that is why it ships here. get_process_start_id documents itself as non-blocking and safe to call from the asyncio event loop, while its Windows arm reached the exit-FILETIME poll; this PR's own exit-code-259 liveness change is what newly routes a child into that poll, so the PR makes a pre-existing stall reachable from a path it creates. Shipping the reclamation fix without it would leave the gateway loop stalling on a route this change introduced.

    Scope was kept minimal: the identity read takes await_exit_time (default True, byte-for-byte unchanged for every drain, scan and sweep caller) and exactly one call site — process_start_time's Windows arm — asks for the creation-only read, where the third tuple element is None by construction rather than conflated with 'still active'.

iamwhatever pushed a commit that referenced this pull request Sep 20, 2026
…e harness

Four reds on the first push, each its own thing:

- mypy: `policy` was read back out of `extra`, whose values are a mix of
  strings and counts, so it typed as the union where the outcome row wants a
  string. Bound to a local `str` and used at both sites.
- `test_security_posture` omission guard: `tool_risk.py` calls a redactor and
  was classified as neither sink nor allowlisted. Registered as a SINK, not
  allowlisted, and the entry states why it differs from its own sibling
  `decisions/gate.py`: the gate SCANS the same request and refuses on a hit,
  emitting nothing, while this module scrubs and the scrubbed bytes are what
  leaves the machine.
- cross-layer settings fixture: it held the card's one point EQUAL to the whole
  backend tuple, which only worked while the seam shipped one point. Now
  membership plus "and not the annotating point", which is what the test's own
  name and docstring already claimed -- membership alone would accept a card
  naming `tool.risk` as the live point and promising the switch changes a
  decision it does not touch.
- locale style gates: the French strings used a plain space before double
  punctuation instead of U+202F, and the Bengali one used Bengali digits where
  that gate's ceiling counts Western. Both fixed in place.

Also adds `website/scripts/capture-tool-risk-badge.mjs`, the sibling of
`capture-decision-strip.mjs`, which is how the PR's screenshots are produced.
It carries two guards it earned the hard way: `assertPaintable` refuses to
photograph a row whose ancestor sits at computed opacity 0 (a collapsed turn
wrapper reports perfectly correct layout numbers behind a blank rectangle), and
the two badge clips are asserted distinct. Without them the harness wrote two
byte-identical files under two correct names.

Not touched, both main-side: the four `test_acp_runtime.py` failures on
Backend Tests (Windows) (1), which the base commit #12005 introduced and two
sibling PRs share, and the Python dependency audit line.
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