Registry Mirror
Skip to content

Catch leftover processes automatically (heavy cleans up its scope, a leftover sweep, capacity check names them) #159

Closed

Description

@scuttletoby

Problem (owner, 2026-11-15): leftover processes must be caught automatically, not found by hand when the machine is already overloaded.

What happened: test helpers from one test file (a background job loop) kept spinning after their test runs ended: 73 of them, about 3 CPU cores, for hours. Earlier, test-harness runs of another tool lived 9 to 85 hours. Nothing noticed until the load reached about 13x the core count and agents stalled.

Root cause: the heavy wrapper (runs builds and tests in a capped systemd user slice) uses systemd-run --scope. A scope lives as long as any process in it, so when the test command ends, everything it left behind keeps running inside the slice, with no report. Processes started outside heavy have no owner check at all.

Fix, in layers (enforced, not trusted):

  1. heavy cleans up after itself. When the command ends (or is stopped), it stops its own scope, so every leftover dies with it, and prints heavy: stopped N leftover processes (<names>) on stderr so the leak is seen and fixed at its source. An explicit opt-out for commands that must leave a daemon (named, logged). Source in a repository with tests (it has none today), installed like the other host tools.
  2. Leftover sweep for everything else. A small user timer finds processes whose owner is gone (reparented to the user manager, not a known service, older than a few minutes) and either busy or long-lived. Test-shaped ones are stopped; others are reported. Every action goes to a log and a short report.
  3. The capacity check says why. t3-capacity names leftover processes and their CPU when it says NOT OK, so agents and the orchestrator see the cause at once.
  4. Tests prove it. Each layer has a test that fails without it (a command that leaves a spinning child; an orphan older than the limit).

General vs project: the wrapper, sweep and checks are general (any Linux host with systemd user slices); slice name, limits, sweep patterns and age come from a config file. Project parts (which test patterns count, where reports go) are a thin adapter.

Related: host tools without a source in a repository; finished agents keep their process; a test-harness leak in the project repo.

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    on Nov 15, 2026
  2. scuttletoby commented on Nov 15, 2026

    @scuttletoby
    OwnerAuthor

    Found on 2026-11-15 while agents were waiting for memory: 11 leftover test database containers (MariaDB, up to 3 days old, made by database tests whose process had died) held about 1.2 GB of swap, plus one orphaned test harness that polled for a file every 0.05 s for over 2 hours after its CI job ended. Removing them by hand freed the swap.

    Root-cause note for this issue: containers run under the Docker daemon, outside the heavy cgroup, so killing the test's process tree never removes them. The cleanup needs to cover them too, for example: tests label their containers with an owner (heavy run id or pid), and the sweep removes labelled containers whose owner is gone. Unlabelled containers should be reported, not removed.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions