Run processes — the run tag, attribution, usage readout, reaper and sweeps, idle reap, left commands, resource alerts. A repository rule for apps/daemon/src/v1/agents/**/run-process*, apps/daemon/src/v1/agents/**/run-idle-reap*, apps/daemon/src/v1/agents/**/run-teardown*, apps/daemon/src/v1/agents/**/resource-*, apps/daemon/src/v1/agents/**/process-*, apps/daemon/src/v1/agents/**/stranded-*, apps/daemon/src/v1/agents/**/kill-tree*, apps/daemon/src/v1/agents/**/child-*, apps/daemon/src/v1/agen...
8 stars
0 votes
0 copies
1 view
Added November 17, 2026
ai-agentspythongoshellbashnodeapidatabase
Works with
cursor
terminal
cli
api
mcp
Security analysis
B75/100
criticalModifies startup scripts or system services for persistence
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Rule Daemon Run Processes?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/geniro-io-rule-daemon-run-processes)
---
name: rule-daemon-run-processes
description: "Run processes — the run tag, attribution, usage readout, reaper and sweeps, idle reap, left commands, resource alerts. A repository rule for apps/daemon/src/v1/agents/**/run-process*, apps/daemon/src/v1/agents/**/run-idle-reap*, apps/daemon/src/v1/agents/**/run-teardown*, apps/daemon/src/v1/agents/**/resource-*, apps/daemon/src/v1/agents/**/process-*, apps/daemon/src/v1/agents/**/stranded-*, apps/daemon/src/v1/agents/**/kill-tree*, apps/daemon/src/v1/agents/**/child-*, apps/daemon/src/v1/agents/**/run-ps*, apps/daemon/src/v1/agents/**/managed-*, apps/daemon/src/v1/agents/**/action-command*, apps/daemon/src/v1/agents/**/chat-shells*, apps/daemon/src/utils/process-identity*, apps/daemon/src/v1/agents/**/monitor.registry*, apps/daemon/src/v1/agents/**/agent-session*; read it before editing a file there."
---
<!-- GENERATED by scripts/sync-agent-rules.mjs from .claude/rules/daemon-run-processes.md. DO NOT EDIT: edit the source, then run `pnpm sync:agent-rules`. -->
# Run processes
`utils/run-process-scan.ts`, `services/run-process-attribution.service.ts`.
- Every run-scoped CLI, and every command action a user runs, is spawned with `runTagEnv` — `GENIRO_RUN_ID=<runId>` plus `GENIRO_RUN_OWNER=<currentRunOwner()>` (a hash of userData) — merged last so no adapter or caller env replaces it. `RunProcessAttribution` (over `attributeRunProcesses`) is the ONE answer to "which processes are this run's": tagged processes (this owner only; the env is the text AFTER the argv in `ps -E`) plus their descendants, each process in exactly one run. The one exception is what a CLI left running when it died, found by the groups its session recorded (Left commands below). The usage readout (`RunProcessesService`: `detached`, then app-wide `leftover`), the reaper and the sweep all ask it, so what a thread shows as detached is what archiving it ends; its kept CLI trees end with `closeRun`. Readouts may share a reading up to `READOUT_SCAN_MAX_AGE_MS` old; kills always take a fresh one.
- What is never attributed is decided by STRUCTURE, never by a program's name: the daemon and its ancestors, a run the daemon itself carries the tag of, pid ≤ 1, another uid, a process on a terminal (and what it runs) while that terminal is open, and `isOutsideAnyRun` (executables under `/System`, `/usr/libexec`, `/Applications`, `~/Applications`, and the container VM — matched by lima's own `/_lima/` directory under any home — the one named exception). Never the HOST of a terminal: codex runs commands on a pseudo-terminal, and a whole agent must not vanish behind one. Do not add name lists here: macOS offers no process containment to apps (no cgroups; coalitions are launchd's), and a name decides nothing reliably.
- Known limits: a tmux an agent started is its thread's, so ending the thread ends it, shells the user opened in it included; a shared helper an agent first started (gpg-agent, watchman, a Gradle daemon) stops with that thread and restarts on demand; a job the user orphans from a session an agent started, after its terminal closed, carries the run's tag and is stopped with it. Nothing in the process table tells these from what the agent detached. A system binary (`sh`, `zsh`, `sleep`, `tail`) whose parent is gone shows no tag — macOS withholds the env of `cs_restricted` processes — so it is a run's only through the left-command stop below. What the agent detached itself — `cmd &`, `nohup cmd &`, a daemon that leaves for launchd — is never recorded and outlives even a clean quit. Two commands started in one burst whose processes read alike can, at the reading that first finds them, both record the same process, so a Stop of one can stop the other's too. Under codex, which keeps no record of its own, a heredoc fed to `python3` is not found: macOS relaunches it as `Python -`. A command that starts yet another session after its last recording escapes that stop; so does one whose CLI dies before a reading finds it, and a claude command that dies with claude in its first seconds, before claude reports it as a task. After a daemon death, a command group the boot stop finds is stopped only once the stop's own kill grace has passed; a second death inside that window loses the record.
- Kills (`RunProcessReaper`): explicit pids only, each re-confirmed by start time before TERM and KILL; nothing over `RUN_PROCESS_CAP` or when `ps` fails. Archive/sweep never reap a run the registry holds a live agent under, asked after the scan. A confirmed process-panel stop may stop selected detached pids while an agent is live, but excludes every registry-held CLI tree, including orphaned group members, after fresh attribution and usage scans; any selected pid outside the run's detached set refuses the entire request. An agent's stop action (`stopCandidates` / `stopRecorded`) is the one path that may stop a process under a LIVE CLI: it excludes only each registry-held CLI and the members of a CLI's own process group (its MCP servers and helpers; a backgrounded command runs in a group of its own), records each target's start time at publish from the fresh scan, and at the press stops the targets still the same process and still a candidate, plus their current candidate descendants (what they have started by the press) — a target gone or whose pid was reused is `gone`, one alive but no longer a candidate refuses the whole press (`PROCESS_CHANGED`). Both stop paths share one fresh reading (`freshReading`). A reap the sweep queued for a gone run re-asks the database that the run is still gone (`stillGone`); an idle reap re-asks nothing but `held`; queued reaps share one scan; logs name the executable, never the argv.
- Left commands (`stopLeftGroups`): every CLI runs its detached commands in sessions of their own and stops them only on its own shutdown, so a CLI that dies without one (crash, OOM, Force Quit, a close whose escalation cut it short) leaves them running, and a system binary among them no longer shows the run tag once its parent is gone. From the moment the CLI reports a command running until it reports it ended, its session records, from the CLI's own tree, the process groups the command's own processes run in and their members' start times (`recordCommandGroups` over `commandWork`; the command is found by its text through `commandTargets` — its whole text first, then each command of it, one per line and per separator, without a trailing `#` comment or a heredoc's body, and compared without its quoting once those match nothing, since the table never shows an agent's quotes as written — plus the groups of every process a matched one started, such as a browser leading a group of its own; a heredoc's program, which once exec'd reads as nothing but its name (`perl -`, `node -`), is taken for the record by that whole line alone and only where no other running command reads as that process, and never by a Stop; once a command holds groups it is searched for only among them and what they started, and never among the processes another running command already holds. A per-command Stop (`ChatShellsService`'s foreground arm, `ActionStopService`) never takes, through a single command of a script, a process another open command matches): background shells, delegates' commands, commands the agent waits on (claude's foreground tasks, every command codex runs) and, for a CLI that reports no units (cursor), its execute calls until the turn's sweep finds them gone or detached — once cursor answers a call, only what still runs in its tree. One reading per burst of starts, answers and allowed approvals, `COMMAND_GROUP_READ_DELAY_MS` after the first (a call can be reported before its command spawns), one more that long after it when the burst went on, then every `COMMAND_GROUP_REFRESH_MS` while any runs. A reading that finds nothing of a command drops it. Never the CLI's own group, which claude's MCP servers share; codex gives each MCP server a group of its own, recorded only if the agent ran that same command line. When the process ends, whatever ended it but shutdown, `AgentSessionRegistry.onLeftCommands` hands `endedRunning.groups` to the reaper (`createRunProcessReaper` wires it). After the kill grace, a group is acted on only while a recorded member is still alive in it with its recorded start time (a pgid cannot be reused while a member lives), never the daemon's own group; then its current members as explicit pids, minus `daemonChain`, `fencedPids` without the terminal fence, and every registry-held tree (`processTreeOf`). The terminal fence is skipped because the groups were the agent's by structure when recorded and codex runs its commands on a pseudo-terminal. Every change to what a session records is mirrored into the child journal (`children.json`, `ChildJournal.recordCommandGroups`, keyed by the CLI's pid with the run from its tag; a write only when the record changed), and the record outlives the CLI's own entry: it is dropped once that stop has run (`StoppedCommands.pid`, `forgetCommandGroups`). A shutdown hands nothing over and a daemon death skips the hand-over altogether, so at the next boot `StrandedChildReaper`, after its group kills and under the same owner check, hands every journaled entry to `stopLeftGroups` without awaiting it — the same anchoring, fences and cap, so a group whose recorded members are gone or whose pids now name other processes is left alone.
- Archive and delete reap through `RunTeardownService.endProcesses` (the run's command actions aborted and monitors stopped, `closeRun`, then the reaper). A card whose work is finished reaps through `RunIdleReapService.reap` (cause `finished-card`: the agent is owed the same prompt line as an idle reap, below, but no row is written, since the user has already called the work done), after its own graceful `closeFinishedRun` has resolved and the kill grace has passed (`afterExitGrace`). It does not run for a run `endProcesses` has ended, asked after the grace (`RunTeardownService.hasEnded`: archived or deleted, until `resumeProcesses`; an archive or delete that fails hands the run back through `resumeIfLive` only when its row is still there and unarchived), so the run is reaped once. `RunProcessSweep` (15 s after boot, then every 5 min) reaps what runs that are gone or archived in THIS database still run, never a run the registry holds a process for.
- Monitors (the `monitor` tool) are daemon-owned and found by `MonitorRegistry`, never by attribution: a tagged `/bin/sh` root is invisible to `ps -E`, and a wrapper of the packaged daemon's own runtime would be fenced as an installed-app executable. `RunProcessesService` reports each as one `monitors` row with its whole process group (`processTreeOf` from the shell's pid), claimed out of `detached` and the app-wide `leftover`; Stop stops it through the registry. A running monitor holds its run like a command action (`held`). Known limit: a child that calls `setsid` leaves the group and shows as an ordinary detached process, which the detached Stop and the reaper still reach.
- Idle (`RunIdleReapService`): once a run has sat unused for the kept-session window, what its agents left running outside any CLI is stopped too, whatever the run is (chat, card, team) and whatever column its card is in. Two ways in: the registry's idle close, once the CLI has EXITED and its group kill's grace has passed (`AgentSessionRegistry.onIdleClosed`: never for an eviction, a stale replacement, a teardown or shutdown; withdrawn when a teardown or shutdown escalates the close; and not while another conversation of the run was used within the window, `runUsedAt`), and the sweep, for a live run the registry holds no process for whose newest transcript row (`ItemDao.latestItemAtPerRun`, the run's `lastActivityAt`: its last turn's end, its last message, its off-turn rows — the one time only the conversation moves) is older than the window, counted from the last wake too and only once Electron has pushed the user's window (`hasUserIdleWindow`) — after a restart or an eviction. The reap is `RunProcessReaper.reapIdle`: unconditional but for `held` asked after the scan, since a run used again always holds a kept CLI, a command action the user is running (`ActionCommandRegistry.isRunning`) or a monitor (`MonitorRegistry.isRunning`) — archive and delete end those first; two asking for one run in the same reap share it and only the first is handed what it stopped; the sweep skips a run whose CLI exited within the kill grace (`awaitingGrace`), when its own MCP servers may still be stopping. When it stopped anything it writes one run-level `warning` row naming the commands that started the rest (`maskedCommand`) and owes the run's next turn a prompt line naming only their executables, since an argv read from the process table can carry a credential no agent typed (`oweRunNote`; in a team the first conversation to take a turn carries it); an archived or deleted run gets neither. The row is the run's newest, so the chat rises in the sidebar as for any event. Accepted: a dev server the user keeps using in a browser without writing to the chat for the window is stopped; the agent restarts it on the next message. It reaches only what attribution reaches (Known limits above): an orphaned system binary (`/bin/sleep`, `tail`, an `sh` loop) shows no tag and is neither stopped nor named, as with archive. A command the CLI tracks (`shellsRunning`) keeps the session, and so the run, from going idle at all.
- Resource watch (`ResourceWatchService`, `utils/resource-alert-rules.ts`): every `RESOURCE_WATCH_EVERY_MS` it reads only while some thread has processes (a registry-held CLI, a monitor, or what its last reading found under a live thread) — one `RunProcessesService.sampleThreads` (the `readAll` attribution), `sysctl kern.memorystatus_vm_pressure_level` and `statfs` of the Data volume — and keeps `GET /v1/resource-alerts`: a thread over `threadMemoryBytes`, one growing at `growthBytesPerMinute` above 2 GB in each of three consecutive windows of at least 60 s (`sustainedGrowthPerMinute`: the lowest rate across them starts and holds the alert; the displayed figure is the newest window's), critical pressure, free disk under `minFreeDiskBytes` (`PUT /v1/resource-alerts/config`, pushed by Electron). A condition fires once and clears only `RE_ARM_RATIO` below its line; an unreadable value never starts one and keeps the last figure. Thread alerts end when their thread has no processes; system alerts are kept while nothing is read and are cleared only by a reading. Memory pressure names the heaviest thread at its raise; low disk names no thread, agent or command and never offers Stop, since no process figure shows what fills a disk — it carries only `freeDiskBytes` and its line (`minFreeDiskBytes`, the current one while it holds). Each change is broadcast bare as `resource_alerts_changed`. It never stops anything itself: `POST /v1/resource-alerts/:alertId/stop` is the user's press, through `stopRecorded`, and only for a heaviest process that was a `stopCandidates` entry when the alert was raised (its start time recorded then). A growth alert that clears, is stopped, or is put away with `POST /v1/resource-alerts/:alertId/dismiss` (any other kind answers 400) starts a 30-minute quiet period for its thread (`quietUntil`, memory only, cleared by a switch-off); a quiet thread's growth cannot start, and a held one keeps holding.
- `ps` reads go through `runPs` (`LC_ALL=C`); the boot-time identity probe in `utils/process-identity.ts` pins the locale itself. `lstart` follows the locale, and an unparsed table reads as unreadable. macOS hides the env of its own platform binaries, and turbo's strict env mode strips the tag from its tasks, which is why descendants are included.
- Kill guard (`utils/child-kill-guard.ts`): `main.ts` writes `<userData>/kill-guard/` right after the debug sink, before any child, and `buildChildEnv` points every child at it last (after `extra`): `ZDOTDIR` (proxies for `.zshenv`, `.zprofile`, `.zshrc`, `.zlogin`, `.zlogout` that source the user's own file under the user's own ZDOTDIR, follow a ZDOTDIR the user's `.zshenv` moves to, then define a `kill` function), `BASH_ENV` (the user's own sourced first) and a `bin/kill` shim first on `PATH`, so each sees the argv the shell already expanded and hands it to one POSIX-sh checker. It refuses a target whose value is 1, 0 or -1 (any spelling, an argument holding several PIDs split on whitespace) and more than `KILL_GUARD_TARGET_LIMIT` (60) targets in one call, with one `geniro: refused kill:` line and exit 1; anything else reaches the real kill unchanged. The user's original ZDOTDIR and BASH_ENV ride `__GENIRO_USER_ZDOTDIR` / `__GENIRO_USER_BASH_ENV` (not `GENIRO_`, so a daemon started from an agent's shell still finds them); a guard never chains to a folder holding `.geniro-kill-guard`, and a removed folder is rewritten by the next `buildChildEnv`. A failed write is logged and leaves children unguarded. It is a backstop, not containment — not covered: `builtin kill`, an absolute `/bin/kill`, bash's `command kill` (its builtin), `/bin/sh` (posix-mode bash reads no `BASH_ENV`), a non-login `bash -c` whose stdin is a socket (bash's rshd rule reads `~/.bashrc` instead of `BASH_ENV`), an interactive bash (`bash -i`, `bash -lic`: it reads `~/.bashrc` or the login profiles instead of `BASH_ENV`, so a bare `kill` runs its builtin; an external `kill` through `PATH` still meets the shim), `zsh -f`, `pkill`/`killall`, other languages' kill calls, and a list split across many calls. Its specs generate the guard with a recorder in place of both kills, disable the shell's builtin and give it a PATH holding only the shim; never let a test reach a real kill.