8000 fix: contain a thread's Windows processes in a Job by aorumbayev · Pull Request #138 · kagan-sh/kagan · GitHub
[go: up one dir, main page]

Skip to content

fix: contain a thread's Windows processes in a Job - #138

Merged
aorumbayev merged 21 commits into
mainfrom
fix/windows-containment
Nov 11, 2026
Merged

aorumbayev merged 21 commits into
mainfrom
fix/windows-containment

Conversation

@aorumbayev
Copy link
Copy Markdown
Member

Ends a thread's Windows processes with a Job Object that the program joins right after the pty starts it, and makes failure visible.

  • Windows containment is a typed state: Tree (macOS and Linux), Job, or Unavailable with the OS error. A failed job is no longer dropped by .ok(). It is logged once with its pid and listed by kg diagnostics export. Stop then ends only the program.
  • Clippy runs on Windows in CI (decision 249), and the Unix-only test helpers are gated so it passes.
  • Windows tests cover stop and drop ending every grandchild through the job, a control showing an own-console grandchild survives without one, a forced assign failure, and finish settling large submits to a program that never reads.
  • The early-run gap (a process started before the join is outside the job) is documented, not closed (decision 250).

…tics

A job that cannot be made or assigned is kept as unavailable with its OS error, logged once, and listed by kg diagnostics export. Stop then ends only the program. Windows tests cover a grandchild under stop and drop, a forced assign failure, and finish settling a submit queued behind a program that never reads.
Gate test helpers that only Unix tests use, box the terminal in its Shown state, keep the Unix-only executable step, and find the grandchild by its parent pid instead of PowerShell output. Give the Windows capture timeout room to start its child.
The grandchild tests assert the job, check every ping, and a control test shows a console close alone leaves an own-console grandchild alive. Unavailable keeps the io::Error and the log names the pid. A core test checks live_containments for the program and an extra terminal. The clippy job uses its own rust-cache key, and ToolHelp moves to a Windows dev-dependency.
@aorumbayev
aorumbayev merged commit d4dd431 into main Nov 11, 2026
20 checks passed
@aorumbayev
aorumbayev deleted the fix/windows-containment branch November 11, 2026 20:04
aorumbayev added a commit that referenced this pull request Nov 12, 2026
## What changed

On Windows, an update started the installer while kagan was still
running. The installer cannot replace a running `kg.exe`, and the early
start cut short kagan's quit handlers. Both Windows install paths
(install at quit, and Restart and install) now start a hidden PowerShell
waiter. It waits up to 120 seconds for kagan's process to end, then runs
the setup with `/P`, or `/P /R` to open kagan again.

- `windows_setup` in `crates/core/src/update/install.rs` builds the
waiter. Its inputs come through `KAGAN_UPDATE_*` variables set on the
waiter only, so no `KG_` variable reaches kagan's children.
- Tests check the waiter's program, process id, setup path and flags on
every OS.
- `docs/behaviour.md` (Update) and decision 270 describe it. Size
ceiling: 82758 (+66), with a Cost line.

## Root cause: likely, not proven

Starting the installer during quit is the likely cause. The live proof
is missing: in the test VM, windows did not show up in the test session,
so I could not watch a real relaunch. The person will confirm with the
next release.

## Checked and ruled out

- The Job Object change (#138) only wraps thread programs, not kagan
itself.
- `KG_NO_START` is set only in tests.
- A wait inside `lock_data_dir` was rejected, because it would delay
every app start.

## Gate

- `cargo fmt --check`, `cargo clippy --workspace --all-targets --locked
-- -D warnings`, `cargo t --workspace --locked --no-fail-fast` (2305
passed).
- `scripts/decisions-check.sh`, `glossary-check.sh`,
`crate-boundaries.sh`, `test-env-check.sh`, `size-budget.sh`.
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

0