Skip to content

Scopes systemd fails to unload stay loaded and block later scopes of the same name #1895

Closed

Description

@JacobStephens2

This was generated by AI during triage.

From the 2026-11-09 retro of thirdshift's own runs.

Agent Brief

Category: bug
Summary: thirdshift leaves a finished scope for systemd to unload, and names scopes by process ID plus a per-process counter. When systemd misses that a scope has emptied, the unit stays loaded for good, and a later process that gets the same PID can't start its scope.

Current behavior:

A Session, Trial, Grader or scope-backed test runs in a transient unit started with systemd-run --user --scope --collect. unit_name names it thirdshift-<kind>-<pid>-<count>-<detail>.scope, and <count> restarts at 0 in every process. thirdshift never stops the unit. It relies on the user manager noticing that the cgroup is empty and collecting it.

On thirdshift.app, in bursts between 2026-11-03 18:03 and 11-05 15:07 (host time), the user manager could not watch new cgroups, because the account had run out of inotify watches. Its journal has 7,042 lines of this form:

<unit>: Failed to add control inotify watch descriptor for control group …: No space left on device

Every scope it could not watch is still loaded: 7,039 thirdshift-session-…-harness.scope units showing active (running) with TasksCurrent=0 and populated 0 in cgroup.events. The ones sampled were started by test fixtures' fake Harnesses. Other tests on that host failed in the same window with No space left on device (os error 28), the error an exhausted watch limit also gives a file watcher.

Since then, whenever a process gets a PID that one of those units carries, systemd-run refuses to start its scope:

Failed to start transient scope unit: Unit thirdshift-session-<pid>-<n>-harness.scope was already loaded or has a fragment file.

That failed 20 full-suite runs across 19 issues on that host between 11-03 and 11-09. No real Session's launch has failed this way in the Command logs so far, but real Sessions use the same names.

Desired behavior:

  • A scope's unit name is unique across processes, including two processes that hold the same PID at different times. A unit left over from an earlier process can't collide with it.
  • When a scope's command has ended and its cgroup holds no processes, thirdshift makes sure the unit is unloaded, without depending on the manager's own notification. When the unit is already gone, nothing happens and nothing is reported.
  • Survivor handling is unchanged: thirdshift ends a scope's remaining processes the way it does today before it treats the scope as finished.
  • Trial and Grader memory caps and OOM reporting keep working.

Key interfaces:

  • unit_name(kind, detail): the name gains a part that differs between processes sharing a PID. It stays a valid systemd unit name and keeps its thirdshift-<kind>- prefix, which operators and tests list units by.
  • Scope and its Observation: own unloading the unit when the Session, Trial or Grader ends, on every path that today leaves the unit to --collect.
  • The fake systemd-run and systemctl the scope tests use: extended as needed to model a unit the manager never collects.

Acceptance criteria:

  • Two names built for the same kind, detail, PID and counter value, as two processes would build them, differ.
  • A test in which the manager keeps a finished scope loaded shows thirdshift unloading it when the Session ends. The same holds for a Trial and for a Grader.
  • A test in which the unit is already gone shows no failure and no warning.
  • An OOM-killed Trial still reports its OOM result.
  • systemd-run is still called with --collect.

Out of scope:

  • Removing the units already left on a host. That is a host action.
  • Finding what used up that account's inotify watches, or raising fs.inotify.max_user_watches.
  • Retrying a launch that fails for another reason.

Activity

  1. added
    bug
    ready-for-agent
    on Nov 9, 2026
  2. JacobStephens2 commented on Nov 9, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    A scope can be left behind without the inotify failure too.

    While the leftover units on thirdshift.app were being cleared on 2026-11-09, one more turned up: a test fixture's thirdshift-session-…-harness.scope, started at 04:57 that day. It showed active (running), TasksCurrent=0 and populated 0, with CollectMode=inactive-or-failed. The user manager's journal has no warning near it, and no inotify failure since 11-05. So the manager can miss an emptied scope even with watches to spare.

    This doesn't change the brief. A unit that thirdshift unloads itself, under a name no other process can produce, covers both cases.

    The leftover units on that host were stopped on 2026-11-09 (7,038 scopes, and 131 failed units reset), so the collisions there have stopped for now. A reproduction needs a fake manager that keeps a finished scope loaded, as the acceptance criteria describe.

  3. added
    in-progress
    agent-failed
    ready-for-agent
    and removed
    ready-for-agent
    in-progress
    on Nov 9, 2026
  4. JacobStephens2 commented on Nov 10, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Handed back to Pickup. in-progress is off and ready-for-agent is on, so the next thirdshift Pickup that is not skipped for the Command limit can continue this issue. Where agent-failed is still present, that pass takes it off as the Day shift's acknowledgement.

  5. added
    in-progress
    agent-failed
    ready-for-agent
    and removed
    agent-failed
    ready-for-agent
    in-progress
    on Nov 10, 2026
  6. JacobStephens2 commented on Nov 10, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Handed back to Pickup. in-progress is off and ready-for-agent is on, so the next thirdshift Pickup that is not skipped for the Command limit can continue this issue. Where agent-failed is still present, that pass takes it off as the Day shift's acknowledgement.

  7. added
    in-progress
    and removed
    agent-failed
    ready-for-agent
    on Nov 10, 2026
  8. removed
    in-progress
    on Nov 10, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions