Repository navigation
Description
Found in the sage's repo pass (T206, run R713) of PRs #83 and #89 (lead build step 1, #62). Size: small. Risk: auth (2 clean review cycles). Must be fixed before the lead build's step 2 and before any sage:lead agent exists. No lead agent exists yet, so none of this is live today.
What holds (sage mode on, leads active): only the main session starts a lead; an agent that is not a lead starts nothing; a lead starts only its team; a 4th child and a 4th lead are refused; a third layer is refused; a one-word brief from a lead is refused; the lower limit wins; two spawns at the last free slot never both get it (20 of 20 trials); a missing or bad agent_id fails closed.
H1 (high): an idle lead loses its slot, so a 4th lead can start
packages/sage-claude/hooks/sage-hook.mjs (about lines 1312, 1355 to 1361 and 1400). A lead's slot is renewed only by the lead's own events, not by its children's. Steps: start leads a, b and c; give lead a a running implementer; age the lead slots past 60 minutes; send an event from the implementer; the main session can then start leads 4, 5 and 6. Sage decision (default, the owner may change it): a child's events also renew its lead's slot, and a lead's slot never expires while it has a running child.
H2 (high): the spawn rules check the caller, not the spawned type
About lines 267 and 272. With sage mode off, a non-sage caller passes every rule: a general-purpose subagent can start sage:lead with a one-word brief, an Explore subagent can start sage:implementer, and that lead can start sage:qa (a third layer). The same would hold in sage mode if subagent events carried a different session_id from the main session (the open question of the live check, #68). Sage decision (default): "only the main session starts a lead", the brief check and the third-layer refusal apply to every spawn of a sage: type, in any mode.
M1 (medium): children outlive their lead's slots
About line 1352. When a lead stops, the hook frees the slots of its started children even if they still run, so the project cap can be exceeded (cap 4: lead a with two running children stops, slots go from 4 to 1, then lead b and two children start: 5 or 6 agents). Keep a child's slot until the child's own stop, or its lease ends.
M2 (medium): SendMessage is not checked
SendMessage, which can continue a stopped agent, is not in AGENT_TOOLS (about line 55). It takes no slot and meets no rule: a lead or a child can wake a stopped agent. Treat SendMessage to a stopped agent as a spawn (the same rules and a slot), or refuse it for agents. Check live whether it restarts the agent.
M3 (medium, pre-existing): any agent can free another agent's slot
About line 247. TaskStop frees an older-format slot by tool_input.task_id, before the stop is done, for any caller. A lead's TaskStop of a main-session agent frees its slot while it still runs. Free a slot only on the agent's own stop event, or only for a TaskStop from the main session.
L1 (low): the lead's spawn name is not checked
The design (sections 6 and 8 of the lead design on #62) says the main session starts a lead only with the name lead-T of a task with a running lead run. The hook does not check it. This may belong to step 3; say which.
L2 (low): a spawn that never runs keeps its slot for 60 minutes
About lines 1258 and 1312. Limited to a lead's 3 children. Release it on the spawn's failure or after a shorter grace time with a reason.
Acceptance
- A test for each item, sent as events to handle(), that fails on main and passes on the branch.
- The existing rule tests still pass. npm run build, npm run check and npm test pass with fake ps, pgrep and kill first on PATH.
Activity
erickb336 commentedon Oct 11, 2026
Update on H2 from the live check (#68, 2026-10-11): in a session with sage mode on, a plain subagent's events carry agent_id and share the main session's hook state, so the in-sage-mode variant of H2 does not happen. The sage-mode-off case still needs the fix: check the spawned sage: type in any mode.
erickb336 commentedon Oct 11, 2026
Live check result (#68): in sage mode, a subagent's events carry the main session's session_id. So H2's sage-mode case does not happen in practice; the sage-mode-off case still stands as written. Steps 2 to 4 (#117, #118, #119) wait for this issue.
erickb336 commentedon Oct 12, 2026
Note from the sage (Claude), for Codex: while Codex's usage was out, the sage took this issue over. PR #121 (branch sage/t255-lead-followups) builds it and is in a repair round. Please do not start work on this issue.