Repository navigation
agent-slots hook: read T3's slot gate count instead of counting processes (#849) - #1292
Conversation
…sses (#849) The server writes its slot gate's machine count (SlotGate.usage, the line wait_list shows) to agent-slots.json beside server-runtime.json, at start and every 20 s (fork/agentSlotsCountFile.ts). The agent-slots hook reads it when the new agentSlots.t3ServerState names that server-runtime.json: only for the pid there, only while under 90 s old, no link, no fifo, size cap. Anything else falls back to the process count and the context line says why. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fork-kit/agent-guards/tests/agent-slots.test.py reads the server's slot count file name and interval from apps/server/src/fork/agentSlotsCountFile.ts, which the sparse checkouts did not include, so its tests failed with FileNotFoundError. Add it to the three lists kept in step. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The branch conflicted with main, so GitHub kept the pull request's old merge commit and the head run of Fork tests failed. Both sides are kept: the agent-slots count import beside main's sender-role import, and main's README tables with this branch's agent-slots rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
lens: code · reviewer: Claude Opus 5.5 (medium) · read at: 37e5a9e blocker: none Checked:
State question: running again rewrites the same file atomically every 20 s. Stopping half-way leaves the last whole file, which goes stale after 90 s or is dropped at once on a pid change. Old, empty or missing state, or a setting left empty, falls back to the process count and names the reason. 🤖 Generated with Claude Code |
… shared reader (#849) (#1437) fork-kit/heavy's agent-slots hook counted pgrep processes while agent-guards' read server.agentSlots (#1292). Both now read agent-slots.json through fork-kit/common/t3_slot_count.py, which both installers copy. Co-authored-by: Claude Opus 5.5 <[email protected]>
Part of #849.
State question: what part of #849 does this cover? The hook.
fork-kit/agent-guards'agent-slotshook now reads T3's own slot gate count (server.agentSlots, the machine linewait_listshows) instead of runningpgrep -c claude. Not covered yet: "every tool reads it" beyond this hook, and the orchestrator's private state file (not in this repository; once a machine setst3ServerState, the slot line in that file can go).What
apps/server/src/fork/agentSlotsCountFile.ts(new fork file). It writesagent-slots.jsonnext to the home'sserver-runtime.json:{"version":1,"pid","writtenAt","slots":{"used","max"}}. It writes once at start, before the layer is built, then every 20 s. It readsSlotGate.usage, the same countwait_listuses (running agents, starting entries, held slots and pending wake-ups).slotsisnullwhile slots are off or the count cannot be read.maxisnullwhen there is no machine limit. A failed write is only logged. It is wired inforkLayers.ts(a fork file) next to the work panel, under the oneSlotGate.layer, so no second gate is made. No upstream file changes.agentSlots.t3ServerState(default"", which keeps today's process count). Set it to the home'suserdata/server-runtime.jsonand the hook uses the server's count. It only uses that count when the file's pid matches the pid inserver-runtime.jsonand the file is under 90 s old. It reads no links, does not wait on a fifo, and caps the read at 64 KiB. In every other case (no server, no file, another process, stale or future time, slots off, wrong version, bad numbers) it falls back to the process count, and the context line says why:Agent slots: 3/10 claude processes alive (T3's slot count not read: agent-slots.json is stale (600 s old)), 7 free. When T3 sets no machine limit,maxAliveis the limit.server.agentSlotssection ofdocs/fork/README.md, the kit README's hook row and key table (the formatter re-aligned the table), the hook's own docstring, andmachine.example.json.Tests (red on main, then green)
fork-kit/agent-guards/tests/agent-slots.test.py: 6 new tests. Against main's hook they give 17 failures; with the change all 12 tests pass. Each answers one question:maxAlivethe limit?apps/server/src/fork/agentSlotsCountFile.test.ts(new, 6 tests): the first write at start holds the gate's count and this pid; off/unread and no machine limit are written asnull; each write has the count at that moment, so a finished child frees its slot; the count is read again one interval later (TestClock); an unwritable path fails nothing;forkLayers.tshas exactly oneSlotGate.layer.config.test.pyandcommon/tests/machine_file.test.pypass.vp run check:changedpasses (format, lint, knip, typecheck, the 2 test files). The fork-checks scripts pass: schema, upstream files, seams.holdWork.boot.test.ts) need a local socket, which this machine blocks. CI runs them..github/fork-ci-tests.txtis unchanged:agent-slots.test.pystill runs in about 1 s.🤖 Generated with Claude Code