Repository navigation
feat(fork): lens_start tool, and lens start after CI (T3b, #888) - #1042
Conversation
`lens_start {pr, head?, afterCi?}` starts the review lenses a pull request's
head still needs: it reads the review config, prompt files, changed paths and
lens comments at the base, plans with lensStart.ts, and starts one read-only
review child per lens through the server's own delegate_task (slot gate,
usage pacing and model policy apply). The server writes each prompt. Children
are stored (lens-children.json) so a repeat returns them and a dead one
starts again as its next attempt. Refuses: rules off, a round past
rounds.max, a refused runner, a dirty or unpushed checkout, a moved head,
anything unread. Not listed, refused and not searchable while review rules
are off; in the orchestration group.
afterCi registers a wait through the existing waits feature: a pr wait
narrowed to the config's required checks (head_check left out) at that head,
carrying `action: "lens_start"` in the stored record. Once its wake is in the
thread, the server starts the lenses in the run that wake starts; red, a
moved head (new outcome `moved`) or the deadline start nothing and the wake
says why. The action runs before the delivery is written, so a restart
half-way runs it again (it is idempotent).
The lens prompt tells the child to post its report with gh pr comment until
lens_report (T4) exists.
Part of #888. Part of #870.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tart) REVIEW.md, go-live.md and the contracts header still said nothing in T3 reads `reviewRules`; lens_start now does. REVIEW.md says which decides the runner (#797): T3's setting for every lens lens_start starts (only for a review block in enforce mode), the kit's file for lenses started by hand. The kit test checks the new statements in REVIEW.md and docs/fork/README.md and that the old one is gone. Part of #888. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
lens: code · reviewer: Claude Opus 5.5 lens agent · read at: b4d129f 🤖 Generated with Claude Code |
|
lens: state · reviewer: Claude Opus 5.5 lens agent · read at: b4d129f 🤖 Generated with Claude Code |
…-like reads - afterCi with no CI checks (the config requires only its head_check): there is no CI to wait for, so the lenses start at once (before: a wait on no checks that could only end "no checks", and that a restart drops). WaitService.register refuses a narrowed pr spec the store could not read back (no checks, more than 20, a bad head). - Tests for the GitHub and disk side over a fake gh/git runner and a temp folder: base-ref reads and 404, a missing page and the 20-page cap, the compare's 300-file cap, no file list and a nameless file, childRunning, the after-CI start's wait for its thread's run, the children file across a restart; and the lens_start handler's wait registration. - The compare answer with no file list, or a file with no name, refuses. - Reviews and inline comments are read as the gate reads them: pending ones skipped, an inline comment dated by when it was published, in review order. - The wait action runs at most 90 s per delivery (then the delivery is tried again), so a slow start cannot stall the other waits. - lensStartChildren.ts says a failed write is only logged and the stable request id is the guard against duplicates. Part of #888. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
lens: code r2 · reviewer: Claude Opus 5.5 lens agent · read at: 7e8fd0c 🤖 Generated with Claude Code |
|
lens: state r2 · reviewer: Claude Opus 5.5 lens agent · read at: 7e8fd0c 🤖 Generated with Claude Code |
|
lens: merge-path · reviewer: Claude Opus 5.5 lens agent · read at: 7e8fd0c 🤖 Generated with Claude Code |
- Both start paths (startInRequest and startForWait) are asserted to run
delegate_task in the thread's own request namespace (lens_start:<thread>),
not the provider session's.
- A review with 101 inline comments refuses ("not all read").
Each goes red when its line in lensStartServer.ts is removed.
Part of #888.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Part of #888 (row T3b:
lens_startas a T3 tool). Part of #870 (step 1: lenses start when CI is green, by code).What
lens_start {pr, head?, afterCi?}, a T3 tool in the fork's waits toolkit, in theorchestrationgroup of MCP profiles (it starts delegated children, so it goes withdelegate_task).reviewRules.configPath), each lens prompt file, the changed paths (GitHub compare,base...head) and the lens comments (comments, reviews, inline comments, with author association, edit and hidden flags, overrides as the gate counts them). Plans withlensStart.ts(T3a).delegate_task(McpServer.callTool, rolereview), so the slot gate, usage pacing and model policy all apply. One lens per child, never two; only the server's prompt is passed on (no orchestrator context).state:", one line per finding startingblocker:/major:/minor:, and from round 2 "check each earlier finding first, then the changes since …".lens/<repo>#<pr>/<head>/<lens>;delegate_taskruns in one namespace per orchestrator thread (lens_start:<thread>), not per provider session. The children started are stored in<stateDir>/lens-children.json(lens_start: separate same-change check for 'already read' (T3b first item) #841's last item), so a repeat returns the running child, a lens whose newest read is this head starts nothing, and a child that ended without a read starts again as the next attempt (cap 3 per head, from T3a).rounds.max; a runner the model policy refuses (nothing more starts on that runner); a checkout of the PR's branch with uncommitted or unpushed commits; a head that moved (asked, or between plan and start); anything it could not read (it starts nothing rather than too few).reviewRulesis off,lens_startis not intools/list, is refused ontools/calland is not found bytool_search(the fork's T3 tool rule).afterCi: truereturns at once. It plans and refuses now (a refusal never waits), then registers a wait through the existing waits feature: aprwait narrowed to the config'srequired_checksminus itshead_check(the gate's own check is red until the lenses read; the fork's config givesfork-ci-result,No database schema changes,Outside pull request), pinned to that head. Already green: starts now. Already red: nothing starts, and the result says why.Why the waits feature needed an addition, and what it is
The waits feature can only send a message. Upstream also refuses a delegated child unless its parent has an active run (
Parent run … is not active, in the orchestration engine and indelegate_task's caller check). So a server that starts the lenses when CI goes green, while the orchestrator has pushed and stopped, has no run to attach them to. The smallest addition, one fact in one home:action: "lens_start", and itsprspec gets optionalchecksandhead(onlylens_startsets them;wait_for's input is unchanged). A head that moves ends the wait with a new outcome,moved.WaitServicetakes an optionalactionhook. For a wait that passed, it sends the wake (which starts the receiver's run), then runs the action before the delivery is written. The action islens_startfor that head as that thread, which waits up to a minute, once, for the run. A problem goes back as a second message (its own message id); if that one cannot be sent, the whole delivery is tried again (the wake is found, not sent twice). Red,moved, a timeout or a closed PR: the wake itself says "No review lens starts for this head".WaitWorker(theWaitsservice carries them to the tool). The fork's T3 tool rule, already in the MCP layer, gives the action the MCP server once it is built; until then such a wake is held, not sent.State question (runs again, stops half-way, old or empty state)
afterCicall while its wait is open is the same wait (same key). After a wait was delivered, the action's repeat start is the samedelegate_taskcommand (same namespace and request id), so it returns the same task.delegate_taskaccepted a child but before the store write: the next call plans the same id, anddelegate_taskreturns that task from its receipt, also from a new session.delivering. After the restart the wake is found (not sent again) and the action runs again (idempotent). Tested with a second service over the same store file.waits.jsonand is judged again. A store that cannot be read gives the existing lost-wait notice. So a wait is resumed or reported, never silently lost.lens-children.json(or an unreadable one, logged) means no children known: a first start, with no attempt counted. Waits stored before this change have noaction/checks/headand behave as before. A downgrade to an older build dropsactionfrom a stored wait (its wake then comes without the start). A storedmovedoutcome is a value an older build does not know.Tests (key ones red before the code)
Red on the old code (run before the implementation):
packages/shared/src/waitFor.lensStart.test.ts: 5 of 7 failed (noonlynarrowing, nomoved, noactionin the record, no wake line).apps/server/src/waits/WaitService.action.test.ts(then named.then.test.ts): 6 of 6 failed (spec not narrowed, no wake line, action never ran after a restart, ready gate).apps/server/src/fork/reviewRules/lensStartRun.test.ts:Cannot find module './lensStartRun.ts'.What they cover:
state:line, finding lines, round 2 context; thedelegate_taskinput (role, request id, runner).afterCi: wait registered on the config checks minushead_check; already green starts; already red starts nothing and says why; a refusal comes before any wait; nothing to read means no wait.movedand timeout start nothing; runs again means no second start; restart half-way; not ready; problem message; problem message refused once./mcptransport (mcpT3ToolFilter.test.ts): off by default, on, and a project override off.Run (one file at a time): the four new or changed test files above, plus
mcpT3ToolFilter,personOnlySettings,ForkAgentContextBudget,waits,taskList,playtest,WaitService,WaitPrJudge,lensStart, shared and contractswaitFor. All pass.vp run check:changed: format, lint, knip, typecheck pass; tests 458 passed, 1 failed. That failure isWaitService.checks.test.ts"on a server without systemd…", which also fails onmainon macOS (checked with this change stashed; it asserts the Linux wording).Other changes:
lensStart.ts) now tells the child to post one new comment withgh pr comment, its first line the lens header, untillens_report(T4) exists. Before, it named a tool that does not exist yet, so a lens could never post and would restart up to the cap.forkAgentContextBudget.jsonis set to the measured 3675 bytes (a new tool; nothing cut).Limits
required-lensesinput (it lives in a caller workflow). Inenforcethe config's path rules name the lenses (the fork's config isenforce). Outsideenforcelens_start refuses ("not read"), as T3a does.sameChange/changeOfare not given to the plan, so only the exact head counts as read and a rebase counts as a new round. This fails closed.lens_startitself.General vs project
General: the tool, the wait narrowing and action, and the store work for any project with a review config. The project gives its lenses, prompt files, rounds and required checks in its own config (
reviewRules.configPath). Nothing names this fork's checks or paths; tests use made-up repos and check names.Upstream fit
Fork files only.
fork-seam-check: "only the pinned seams", so there are no new lines in upstream files and nofork-seams.jsonchange. The tool registers through the existing fork toolkit (layerForkTools) and starts children through upstream's owndelegate_task.Round 1 (lenses code and state at b4d129f)
afterCiwhen the config requires only itshead_check: a wait on no checks, which could only end "no checks", with the wrong wake text, and which breaks the 1-20 check contract, so a restart drops itWaitService.registeralso refuses a narrowedprspec the store could not read back (invalid), so nothing like it is stored.lensStartRun.test.ts"a config whose only required check is the gate's own";WaitService.action.test.ts"a narrowed wait the store could not read back is refused"lensStartServer.test.ts(fakegh/gitrunner),lensStartChildren.test.ts(temp folder),lensStartTool.test.ts(handler)childRunning(new, running, ended, no thread); after-CI start waits for the thread's run, once per action; children file across a restart, replace by id, newest 500, unreadable = none; handler registers the narrowed wait with the action, a refused wait, start in the caller's scope, no servicefiles, or a file without a name, read as no changeslensStartServer.test.ts"the compare: …"state/publishedAtpr_queue.review_flags/inline_postdo: reviews with their inline comments, PENDING reviews and comments skipped, an inline comment dated bypublishedAt, in review orderlensStartServer.test.ts"reads comments, then submitted reviews, then their published inline comments"action.rungets a 90 s limit (WAIT_ACTION_LIMIT); past it the delivery is retried (the wake is found, the start is idempotent). The thread-run wait is cut to 40 s, once per action.WaitService.action.test.ts"an action that does not finish in time"lensStartChildren.tsdoc: only logged; the stable request id is the guardstartInRequestandstartForWaitboth rundelegate_taskinlens_start:<thread>, not the provider session's namespacelensStartServer.test.ts"the after-CI start waits for its thread's run…" (red with either namespace line removed)totalCount: 101refuseslensStartServer.test.ts"a review with more than 100 inline comments refuses…" (red with the limit removed)Every new guard was removed one at a time and turned a test red (20 of 20; the "new child runs" test had to be reordered first).
State question for the new code
delivering, and the next delivery runs it again.Runs: each changed test file alone (
lensStartServer7,lensStartChildren3,lensStartTool4,lensStartRun24,WaitService.action9,WaitService68,comments.test.py44: all pass).vp run check:changed: format, lint, knip, typecheck pass; tests 534 passed, 1 failed,WaitService.checks.test.ts"on a server without systemd…", which fails the same on a cleanorigin/maincheckout (macOS).🤖 Generated with Claude Code