Repository navigation
Description
What happened
On 2026-09-17 a single hide-agent-context-labels watch process (built from #48, started 2026-09-15) had accumulated 1,699 descendant processes and 11.6 GB RSS, with swap at 29/30 GB and the boot volume at 100%. The machine was effectively unusable.
hide-agent-context-labels watch (ppid 1 - Herdr had exited 1d 18h earlier)
└ node codex.js app-server
└ codex app-server -c mcp_servers={} ... --listen stdio://
├ 356 x node lsp-mcp-bridge/server.mjs 1.5 GB
├ 356 x mcp-server-darwin-arm64 --app desktop (ChatGPT computer-use)
├ 356 x cua_node node_repl 0.8 GB
└ 315 x npm exec @figwright/mcp@latest 7.2 GB
356 = one full MCP server set per label request. Every child was older than 24 h; nothing was in flight, they were simply never reaped.
Causes (all present on main @ 93a7b00; #79 changes none of them)
-c mcp_servers={}does not disable MCP servers.hide-ai/src/codex.rs:119expects an empty map; codex 0.154 merges the override into~/.codex/config.toml's[mcp_servers.*]tables, so every user-configured server starts per thread.--disable plugins/computer_usedoes not stop MCP spawning either.- Threads are never closed.
run_turn(codex.rs:160) sendsthread/startand onlyturn/interrupton cancel. Codex keeps the thread's MCP set alive for the thread's lifetime; theSessionis reused across requests, so the app-server, and every set it spawned, never exits.Session::dropleaves the child running. - The watcher outlives Herdr. Herdr runs
[[startup]]commands but does not end them when it exits, and the watcher does not watch its host: the event loop (plugins/agent-context-labels/src/lib.rs:2629) reconnects forever. An orphaned watcher keeps its app-server and all leaked children alive indefinitely. - No budget, no observation. Nothing counted the app-server's children or RSS, so a 2-day leak produced no signal.
Why this is bigger than a patch
More AI-backed plugins are planned. Each one written like agent-context-labels re-implements the same ~60% of its lib.rs (state paths, lock, log, settings follow, Herdr subscribe/reconnect, wake socket) and, with the codex backend, owns its own resident app-server. N plugins = N resident app-servers, N separate leak surfaces, and no single place that can say how much AI the machine is running.
The operator also uses exactly one provider at a time. AiSettings.provider and AiRouter already hide that choice from the plugin (chosen provider first, failover to the other under cooldown). The claude backend is claude -p one child per request and has no resident process; only the codex backend does. So the thing that needs a single, well-guarded owner is precisely "the resident provider process", and that owner should exist once per machine.
Scope
Two parts, delivered together.
Part A - hide-ai owns its backend processes correctly
- Start the codex app-server with a private
CODEX_HOME(empty temp dir, or one holding only what hide-ai needs). Drop-c mcp_servers={}. Test asserts, against a real spawned app-server, that it reports zero MCP servers. thread/closeafter every turn: success, error, cancel, timeout. Failure to close within a grace period drops and respawns the app-server.Session::dropends the child. The child is started so that it also dies if hide-ai dies without running drop (parent-death signal on Linux,kqueue EVFILT_PROCor an inherited pipe whose EOF ends the child on macOS).RouterConfiggains a budget: max in-flight requests, max requests per minute, and for the codex backend a cap on app-server descendant count and RSS. Crossing a cap returnsAiError::OverBudgetto the caller and, for the process caps, restarts the app-server and logsai.app_server.over_budgetwith the measured values.- Log at
ai.request.*level: provider, request id, client id, duration, tokens, and after each request the app-server's descendant count and RSS.
Part B - one AI broker per machine
A resident process, hide-ai-broker, that embeds the hide-ai crate and is the only holder of AiRouter, AiSettings, the budgets, and the codex app-server. Plugins talk to it over a unix socket.
Ownership and lifetime
Herdr
├ hide-ai-broker dies with Herdr; Herdr restarts it and reports the restart
│ ├ codex app-server x1 dies with the broker (Part A)
│ └ claude -p per request
├ plugin agent-context-labels ─┐
├ plugin <next> ─┼─ unix socket, JSON-RPC ─→ broker
└ plugin ... ─┘
- Herdr owns every
[[startup]]process: it starts them in their own process group and ends the group when it exits. This is the fix for cause 3 on Herdr's side; the broker and each plugin additionally exit when their Herdr parent is gone (client side, inhide-herdr-client). Both halves are required; either alone leaves a window. - A plugin never starts a provider process. If a plugin is found spawning
codexorclaudedirectly after this lands, that is a bug.
Protocol (JSON-RPC over $XDG_RUNTIME_DIR-style socket under the Herdr state dir)
| Method | Params | Result |
|---|---|---|
ai/execute |
AiRequest + clientId |
AiResult or AiError (incl. OverBudget, Unavailable) |
ai/cancel |
requestId |
ack |
ai/status |
- | provider, availability per provider, queue depth, per-client in-flight and counts, app-server pid/RSS/descendants, budget values and how close each is |
ai/settingsChanged |
(notification, broker -> clients) | new provider/model |
AiRequest/AiResult/AiError are the existing hide-ai types serialized; the plugin-side AiClient::execute(&AiRequest, &CancelToken) keeps AiRouter::execute's signature so the swap in agent-context-labels is a type change plus connection setup. An in-process mode (AiRouter directly) remains for analyze-once-style CLI use and tests.
Budget
- Global: from Part A, applied once for the machine.
- Per client: in-flight 1, requests per minute N (default to be set from observed label traffic, see Observation). A client over budget gets
OverBudget; the plugin degrades (keeps its last label) rather than retrying in a loop. - Fairness: FIFO queue; a client cannot hold more than its in-flight cap regardless of queue position.
Failure paths (#10)
- Broker down: plugin gets a connection error, maps it to
Unavailable, degrades, reconnects with backoff. Herdr restarts the broker and shows the restart in the plugin status area; a broker that restarts more than K times in M minutes stays down with a visible reason. - Provider unavailable / cooldown: unchanged from
AiRoutertoday, now reported once from the broker instead of once per plugin. - Over budget:
OverBudgetto the caller,ai.budget.exceededevent, visible inai/status.
Observation
ai/status is the source for a Herdr panel: current provider, availability, queue, per-client request counts and tokens, resident process RSS and descendant count, budget headroom. This is what lets the default budget values be set from data instead of guesses, and what would have made this incident a line in a panel on day one instead of an unusable machine on day three.
Migration
- Part A lands in
hide-aiwith tests;agent-context-labelsis rebuilt against it. This alone stops the leak. - Broker binary +
[[startup]]entry + Herdr process-group ownership + client-side host-lifetime inhide-herdr-client. agent-context-labelsswitches fromAiRoutertoAiClient; itsprovider.rsand settings-follow code move to the broker.- Extract the plugin-generic part of
agent-context-labels/lib.rs(state, lock, log, retention, Herdr subscribe loop) into ahide-plugincrate when the second AI plugin is written, not before; until then splitlib.rsintolabel/anddaemon/modules so the extraction is a file move.
Acceptance
- After 500 label requests against the codex backend, the app-server's descendant count is stable and below the cap; test drives this with a fake app-server that spawns a child per
thread/startand exits it onthread/close. - Killing Herdr ends the broker, every plugin startup process, and the app-server within 5 s; no
hide-*orcodex app-serverprocess survives. - Killing the broker leaves plugins running and degraded; Herdr restarts it and the plugins recover without restart.
ai/statusreports the numbers above and a Herdr panel shows them.agent-context-labelshas no code path that spawns a provider binary.
Out of scope
- Streaming responses; per-request model override by plugins (the operator's choice stands).
- Multiple operators / multiple Herdr instances sharing one broker.
- The
hide-pluginextraction (step 4 above) beyond the module split.
Open questions
- Does Herdr's plugin manifest need a distinct
[[services]]kind (restart policy, health) or is[[startup]]plus process-group ownership enough for now? - Where the broker socket lives so that plugins from different plugin roots find it: Herdr passes it in the environment of every startup/action command is the simplest answer.
- Budget defaults: set after one week of
ai/statusdata from the label plugin.
Evidence
pssnapshot and per-ancestor aggregation from the incident are on the operator's machine; attach on request.- Installed plugin at the time:
hide.agent-context-labels-edba8aea440b@ 4b6203b (Reuse the machine's Rust toolchain under a verification HOME #48). codex@openai/[email protected].
Activity
[-]agent-context-labels leaks one MCP server set per label request and outlives Herdr (1,699 procs / 11.6 GB)[/-][+]hide-ai: own provider processes correctly and serve all plugins from one AI broker (agent-context-labels leaked 1,699 procs / 11.6 GB)[/+]yansfil commentedon Sep 17, 2026
#82 분리: Part A는 PR로, Part B는 후속 이슈로
PR #92 가 이 이슈의 Part A + watcher host-death exit 를 구현합니다:
hide-ai가 codex app-server 를 소유 — 사설CODEX_HOME(0700,auth.jsonsymlink 만, config.toml 없음 → MCP 자식 0), graceful 종료(stdin close → SIGTERM → SIGKILL), 유휴 10분 종료,RouterConfigbudget(동시 1 / 분당 30 / 자손 4 / RSS 1 GiB)과OverBudget, 프로세스 상한 초과 시 재시작(연속 3회 상한), 요청마다 자손 수·RSS 기록(macOS libproc).watcher_host_gone을 남기고 exit 0 하며 app-server 를 데리고 내려갑니다.Part B 는 이 PR 범위 밖이며 별도 이슈로 다시 봅니다. Part B 는
hide-ai-broker상주 프로세스, unix socket JSON-RPCai/*, Herdr[[startup]]의 process-group 소유,ai/statusHerdr 패널, 클라이언트별 budget 입니다. 이는docs/AI_PROVIDERS.md의 "daemon/socket 거부" 결정을 뒤집고 herdr fork(별도 저장소) 변경을 수반하므로, 두 번째 AI 플러그인이 생겨 공유 상주 프로세스가 실제로 필요해질 때 별도 PRD 로 설계합니다. 그때까지 플러그인은 계속AiRouter를 직접 링크하고 각자 app-server 를 띄웁니다.참고: 실제 codex turn 관찰은 codex 주간 한도 리셋(2026-09-19 17:10 KST) 이후에 가능하여 PR #92 에는 unrun 으로 명시돼 있습니다.
hide-ai owns the codex app-server and the label watcher exits with it…
yansfil commentedon Sep 20, 2026
Part A는 #92로 main(a3d9bd2, 2026-09-20)에 들어갔습니다. 실기동 검증에서 자손 수 측정이 항상 0이던 버그(
proc_listchildpids반환값을 바이트로 나눔)를 같은 PR에서 고쳤고, 정상 트리는descendants=1(node 래퍼 -> app-server)로 측정됩니다.auth.json갱신은 codex 0.155.1file저장소가 제자리 쓰기라 symlink를 통해 실파일에 닿는 것을 소스로 확인했습니다.Part A 후속으로 #116(kill -9로 죽은 소유자가 남기는 사설 CODEX_HOME 정리)을 열었습니다. 이 이슈는 Part B(broker) 때문에 계속 열어둡니다.
yansfil commentedon Oct 5, 2026
Part A는 #92로, 사설
CODEX_HOME정리는 #116으로 끝났습니다.이 이슈를 열어 둔 이유였던 Part B(broker)는 "AI 플러그인마다 별도 프로세스가 각자 app-server를 띄운다"는 구조가 전제였습니다.
지금은 에이전트 라벨, Project Memory, Settings의 provider 조회가 모두 hided 코어 안에서
hide-ai를 직접 씁니다(herdr-core/src/ai.rs).프로세스 사이에 공유할 broker가 필요 없어졌으므로 닫습니다.
남은 차이 하나:
labels_router와memory_router가 각자AiRouter를 만들기 때문에, codex를 쓰면 hided 안에 app-server가 둘까지 뜰 수 있습니다.둘 다 Part A의 budget과 유휴 종료를 따르므로 누수는 아닙니다.
하나로 합칠 필요가 측정으로 드러나면 그때 새 이슈로 다룹니다.