Repository navigation
Lead build step 3: the hook's write list for leads (T273) - #124
Merged
Merged
Conversation
…yte limit (T273) taskFor becomes rowFor: the hook needs a run's role (run done only for the five team roles) and a finding's severity (a lead dismisses only a low finding). With max, a table over max bytes throws, so a caller fails closed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…T273) A state tool write by an agent passes only for agent type sage:lead in the bound slot of its lead-T<n> spawn, which now records the task. The command must be on the lead list of #62 section 8; each task word must be the lead's task, and each run id or finding key a row of that task (rowFor, 4 MiB per table). A lead's write runs from Bash with no --project and no SAGE_PROJECT, and the hook resolves the folder's links as process.cwd() does. Children and other agents stay refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…run (T273, #118 point 4) In sage mode, the main session's spawn of sage:lead named lead-T<n> passes only when T<n> has one running lead run in the logbook of the event's folder (through its links, the logbook that the lead's writes use). The state tool's leadRunFor reads it with the same 4 MiB limit per table as rowFor, through one shared reader. A refusal names the run add command; an unreadable logbook or an event with no folder refuses too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd branch rules (T273 round 1) F-T273-1: the slot records the lead's logbook folder; a write from a folder of another logbook is refused. F-T273-4: it records the running lead run, and a write needs that run still running. F-T273-5: a second lead-T<n> is refused while a slot for that task lives, in any session. F-T273-2/6: pr= only while the task has none, to a PR of no other task; each verdict names the task's PR. F-T273-7: no move from held, and only the cycle's next state move. F-T273-3: run add --branch is a branch of the task. One bounded logbook read, logbookView, replaces rowFor and leadRunFor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…73 round 2) F-T273-8: for each merge, the hook reads the PR's head branch with gh pr view (read only, 5 seconds, no fork) in the merge's folder and passes it to the merge check. The merge check refuses unless each task that is or was on the PR owns that branch: its branch=, or a branch of the task (ofTask). A failed or slow read refuses. merge-check --head runs the same check by hand. T275: a lead never clears its branch, and gives each option once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…und 3) F-T273-9: the merge check takes the project being merged; only a task of its logbook counts as a task of the pull request. A task of another logbook with verdicts on the SHA must still pass. The hook passes the merge's folder; the hand-run merge-check uses the project that the state tool resolves. F-T273-10: an empty --head refuses. F-T273-11: the branch-rule refusal says to rename the branch to a task name, or that the user lands the pull request. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t waits (T273 round 4) F-T273-12: while its task is held, a lead writes nothing; the merge check refuses a held task. F-T273-13: the main session's TaskStop of lead-T<n> frees that task's lead slot; the one-lead refusal names both forms. F-T273-14: the main session's TaskStop records an end, so a stopped lead starts no child. F-T273-15: each hook call in the hook tests has a 60 s bound and each test a 5 minute timeout, so a hang fails instead of stalling the file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…state tool (T273 round 5) F-T273-16: a session holds one lead of a name lead-T<n> in any logbook, and TaskStop by that name stops only it. F-T273-17: a spawn result that arrives after the TaskStop freed its slot ends the agent. F-T273-18: the state tool refuses run add, finding add/triage/close and verdict on a held task, for every caller. F-T273-19: TaskStop comment, and release has no unused argument. F-T273-20: every sync child call of the hook tests goes through bounded(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #118
What this is
Step 3 of the lead build (design: #62, section 8, "Logbook writes"). Until now the sage hook refused every state tool write by an agent. Now an agent of the type
sage:lead, in the lead slot that the chief started aslead-T<n>, may run a short list of state tool commands on that task only. Every other agent, and every child of a lead, is still refused. The lead agent file and the chief's instructions are step 4 (#119).How it works
lead-T<n>(marktask-T<n>). The slot binds to the lead'sagent_idonly from the Agent tool's result, as before.slots.leadTask(agent_id)gives the task of the bound, live lead slot of this session, or nothing.agentCheck, a command that is not a read goes toleadProblemwhenagent_typeis exactlysage:lead. It checks the slot, the tool,--projectandSAGE_PROJECT, the command's words, and each id through the logbook view.taskForis nowlogbookView(project, env, { max }): one bounded read of every table (a byte limit per table) that gives the logbook folder, a task's row, the row of a run id or a finding key, a task's one running lead run, and the tasks that are or were on a PR.taskForhad no other caller, so it is gone (no second path).Each decision and its test
All tests are in
scripts/sage-hook.test.mjs(events sent to the hook, which callshandle()), except where the test namesscripts/sage.test.mjs.agent_typeexactlysage:lead, with a bound lead slot, and only the lead listleadProblemandLEAD_WRITES. Reads (status,standing,merge-check, and alsologbookandconfig) stay as for every agent. A refusal ends with "Report to the sage what else the logbook needs."verdict --run); nothing or a throw refusesview.row(id)?.task === own.run donealso needs a run of the five team roles, so a lead cannot close its own lead run. A dismissal needs a low finding and--reason. Each command has a fixed count of words, so no word goes unread.--keyonfinding addopt.key === undefined, in both forms (--key X,--key=X)--projectandSAGE_PROJECTrealpath, because the state tool usesprocess.cwd(), which is the physical path: without it, a folder through a link (/varon macOS) gave another logbook. A mutant withresolvefails 2 of the T273 tests.LEAD_READ_MAX= 4 MiB per table: the state tool's own limit for its observations file. The largest real table on 2026-10-11 was 0.35 MB.scripts/sage.test.mjs"T266-TASK-FOR: logbookView gives the row ..." (exactly max reads, max + 1 throws)sage:lead; asage:leadtype with no bound lead slot (a child that claims it, another session, after the lead's stop) is refused| #118 point 4 | In sage mode, the main session's spawn of
sage:leadnamedlead-T<n>passes only when T has a running lead run |logbookView(...).leadRun(task)reads the runs with the same 4 MiB limit per table. The hook reads the logbook of the event's folder through its links, the one that the lead's writes use. No running lead run: the refusal namesrun add T<n> --role lead --project <folder>. A logbook that cannot be read, or an event with no folder: refused. | "#118 point 4: in sage mode the main session starts lead-T only when T has a running lead run in the logbook";scripts/sage.test.mjs"#118 point 4: logbookView gives a task's one running lead run, ..." |Each of the 10 new hook tests (9 for T273, 1 for point 4) fails on main and passes on this branch: a detached worktree of main with this test file gives 245 pass and 10 fail, and the 10 that fail are exactly the new ones. The older lead tests now spawn leads in a fixture folder whose logbook has running lead runs, and they still pass on main.
Repair round 1 (R886)
Each fix has a test that fails on daac31f and passes now: a detached worktree of daac31f with this branch's two test files gives 11 failures, among them each test below.
task set pr=passes only while the task has no PR, and only to a PR that no other task has or had (the state tool's own PR history: tasks, decision rows, ledger).pr=(clear), a secondpr=in one command, and a PR with a leading zero are refused. Every leadverdictneeds--prequal to its task's PR; a task with no PR takes no lead verdict.task seton a held task is refused.state=passes only as the cycle's next move from the task's current state: briefed to building, building to reviewing, reviewing to verifying, repairing to reviewing, verifying to verified, verified to reviewing. One key per command.run add --branchmust pass the state tool'sofTaskfor the lead's task.lead-T<n>is refused while any slot, in any session, holds a lead of that task in that logbook.Every lead write now reads the logbook once (to check the logbook and the lead run), so the oversized-table test now expects
roundto be refused too.Repair round 2 (R890)
Each test below fails on 29e9f82 and passes now: a detached worktree of 29e9f82 with this branch's hook test file gives 5 failures, exactly these 5 tests.
gh pr view <n> --json headRefName,isCrossRepositoryin the merge's folder (the repository thatgh pr mergeacts on), read only, at most 5 seconds. It passes the branch to the merge check, which refuses unless each task that is or was on the PR owns that branch: itsbranch=, or a branch of the task by the state tool'sofTask. A failed or slow read, or a PR from a fork, refuses with a sentence. The rule runs after each task's own judgment, so a refusal still names missing verdicts first.merge-check --head <branch>(with--pr) runs the same check by hand; the sage skill and the README describe it. A state tool that cannot load refuses before the hook asks GitHub.task set branch=with an empty value is refused; an option given twice in a lead command is refused.In the tests, gh is a fake first on PATH for every hook session: it answers
gh pr viewwith a set head branch, a failure, a fork or no answer. No test reaches GitHub.Repair round 3 (R894)
origin/main (e8b823d, #75) is merged in first, with no conflict. Each test below fails on f569116 and passes now: a detached worktree of f569116 with this branch's hook test file gives 4 failures, these 3 tests and the older test whose expected sentence changed ("the merge check gets the pull request's number from the merge command").
merge-checkuses the project that the state tool resolves (--project,SAGE_PROJECT, the current folder).merge-check --head=(empty) refuses, next to the "--head needs --pr" check.branch=.The hook test sessions now keep their logbook for the checkout where
bash()runs commands (FEATURE), because a merge counts only the tasks of its own project's logbook. Two older tests now expect the new "in this project's logbook" sentence.Repair round 4 (R901)
origin/main (bb9a7ab, #125) is merged in first, with no conflict. A detached worktree of f16cea0 with this branch's hook test file gives 3 failures, exactly the tests of F-T273-12, -13 and -14.
lead-T<n>ends and frees that task's lead slot in this session, as TaskStop by the agent id does. The one-lead refusal names both forms: "stop it with TaskStop (by its agent id or by its name lead-T)". An agent's TaskStop still frees nothing.send(spawnSync with no timeout),sendAsync(a promise that resolved only onclose, with no timeout and noerrorhandler, so a spawn that fails under load never settled), andsage. Each hook call now has a 60-second bound with SIGKILL,sendAsyncrejects onerror, on its bound and on a non-zero exit, and each test of the file has a 5-minute timeout, so a hang fails fast.--test-timeout=30000did not stop it, because the hook child kept the runner alive, and I stopped the run by hand.Repair round 5 (R905)
origin/main had not moved. A detached worktree of fee07bf with this branch's two test files gives 4 failures: the tests of F-T273-16, -17 and -18, and the F-T273-5 test, whose expected sentence changed. The F-T273-20 test fails with fee07bf's own harness ("bounded is not defined"); its fix is in the test file itself.
lead-T<n>is refused while this session holds a live lead slot of that name in any logbook (and, as before, while any session holds one for this logbook). (2) TaskStop bylead-T<n>frees this session's one slot of that name. The refusal now reads "a lead named lead-T already holds a slot, in this session or for this logbook (…)".spawnSyncandexecFileSyncofscripts/sage-hook.test.mjsgoes through one helper,bounded(): a 60-second timeout with SIGKILL, unless the call gives its own timeout.run add,finding add,finding triage,finding closeandverdicton a held task, for every caller. The chief's own moves stay:task set state=(held to building or briefed),round,run doneandfinding move. A lead command that the hook checked before the round set held now stops in the state tool.scripts/sage.test.mjs)releaselost its unusedattemptedargument.Not verified live
sage:leadagent in Claude Code: its events'agent_typeandagent_id, and that itsagent_idis theagentIdof the spawn's result. The lead agent file comes in step 4.gh pr viewagainst real GitHub: the tests use a fake gh. The repository thatgh pr viewreads is the one thatgh pr mergein the same folder acts on; I did not run a real merge.cwdis the folder where its command runs, and that the hook's environment has the sameSAGE_PROJECT,SAGE_HOMEandCLAUDE_CONFIG_DIRas the lead's shell.Limits to know
--summary=no-test-for-empty-input,--reason=covered-by-T5. Step 4's agent file must say so.SAGE_PROJECTis set in the session's environment, or when a table of the logbook is over 4 MiB.Checks
npm run build,npm run checkandnpm testpass on the head commit. Each commit builds and passes the check on its own.🤖 Generated with Claude Code