[PR #3254] [CLOSED] [TUI] procs: find engine orphans adopted by systemd --user, and wait until they are really gone #4532

Closed
opened 2026-11-07 15:36:52 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3254
Author: @toel1234
Created: 10/19/2026
Status: ❌ Closed

Base: main ← Head: fix/orphans-systemd-user


📝 Commits (1)

  • dc36dfe [TUI] procs: find engine orphans adopted by systemd --user, and wait until they are really gone

📊 Changes

1 file changed (+8 additions, -4 deletions)

View changed files

📝 strata_control/procs.py (+8 -4)

📄 Description

Problem and result

On a systemd Linux desktop, strata never found an engine left behind by an earlier run without a launch record. systemd --user both adopts orphans (subreaper) and is an ancestor of every desktop terminal. orphans_of() put every ancestor except pid 1 into "my own processes", so an orphan whose new parent is systemd --user looked started by this server and was skipped. The orphan kept holding the GPU.

After that was fixed, a second Linux issue showed: end_one() returned "ended" while the process was still exiting. It waited on is_same() (start token and command line), and an exiting Linux process has an empty /proc/<pid>/cmdline before it is gone.

After: ancestors named like an init (INIT_NAMES, already used for the adopted-parent check) are not counted as starters, the same as pid 1. After the signal, end_one() waits on the start token alone, which is unique per process lifetime and never matches a reused PID. The kill itself is still only sent after the full is_same() check.

none. Focused fix.

Approach

Two small changes in strata_control/procs.py. Both are needed for the existing test test_an_engine_orphan_of_this_executable_is_found_and_a_live_one_is_not: with only the first it still fails (process reported ended, start token still live), with both it passes. Windows behaviour is unchanged apart from the wait loop now comparing the start token, which is the same value is_same() compared first.

Validation

Passed:

  • python -m pytest tests/terminal/test_procs.py 5 times in a row: 7 passed each. Ubuntu, GNOME on Wayland, Python 3.12.3, the process tree systemd(1) > systemd --user > gnome-shell > … > pytest.
  • Full python -m pytest tests/terminal -q with this branch and #3255 merged: 852 passed, 17 skipped, 0 failed (445.96 s).
  • Diagnosis: an orphan of this test is reparented to systemd --user (pid 5687 here), which psutil.Process().parents() also lists.

Failed:
none observed.

Not run:

  • Windows and macOS: not available. The Windows branch of end_one() only changes which check the wait loop uses.
  • A real engine orphan: tested with the existing Python sleeper fixture only.

Limits

A process stuck in exit (empty command line, start token still live) is now reported "stuck" after the 10 s wait instead of "ended".

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3254 **Author:** [@toel1234](https://github.com/toel1234) **Created:** 10/19/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/orphans-systemd-user` --- ### 📝 Commits (1) - [`dc36dfe`](https://github.com/Niko1221/Strata/commit/dc36dfe901333a3392c2df8c607701317ae035d4) [TUI] procs: find engine orphans adopted by systemd --user, and wait until they are really gone ### 📊 Changes **1 file changed** (+8 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `strata_control/procs.py` (+8 -4) </details> ### 📄 Description ## Problem and result On a systemd Linux desktop, `strata` never found an engine left behind by an earlier run without a launch record. `systemd --user` both adopts orphans (subreaper) and is an ancestor of every desktop terminal. `orphans_of()` put every ancestor except pid 1 into "my own processes", so an orphan whose new parent is `systemd --user` looked started by this server and was skipped. The orphan kept holding the GPU. After that was fixed, a second Linux issue showed: `end_one()` returned "ended" while the process was still exiting. It waited on `is_same()` (start token and command line), and an exiting Linux process has an empty `/proc/<pid>/cmdline` before it is gone. After: ancestors named like an init (`INIT_NAMES`, already used for the adopted-parent check) are not counted as starters, the same as pid 1. After the signal, `end_one()` waits on the start token alone, which is unique per process lifetime and never matches a reused PID. The kill itself is still only sent after the full `is_same()` check. ## Related discussion none. Focused fix. ## Approach Two small changes in `strata_control/procs.py`. Both are needed for the existing test `test_an_engine_orphan_of_this_executable_is_found_and_a_live_one_is_not`: with only the first it still fails (process reported ended, start token still live), with both it passes. Windows behaviour is unchanged apart from the wait loop now comparing the start token, which is the same value `is_same()` compared first. ## Validation **Passed:** - `python -m pytest tests/terminal/test_procs.py` 5 times in a row: 7 passed each. Ubuntu, GNOME on Wayland, Python 3.12.3, the process tree `systemd(1) > systemd --user > gnome-shell > … > pytest`. - Full `python -m pytest tests/terminal -q` with this branch and #3255 merged: 852 passed, 17 skipped, 0 failed (445.96 s). - Diagnosis: an orphan of this test is reparented to `systemd --user` (pid 5687 here), which `psutil.Process().parents()` also lists. **Failed:** none observed. **Not run:** - Windows and macOS: not available. The Windows branch of `end_one()` only changes which check the wait loop uses. - A real engine orphan: tested with the existing Python sleeper fixture only. ## Limits A process stuck in exit (empty command line, start token still live) is now reported "stuck" after the 10 s wait instead of "ended". 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:36:52 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4532
No description provided.