Skip to content

feat(fork): lens_start tool, and lens start after CI (T3b, #888) - #1042

Merged
scuttletoby merged 7 commits into
mainfrom
feat/888-lens-start-tool
Nov 23, 2026
Merged

scuttletoby merged 7 commits into
mainfrom
feat/888-lens-start-tool

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Part of #888 (row T3b: lens_start as 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 the orchestration group of MCP profiles (it starts delegated children, so it goes with delegate_task).

  • Reads, at the PR's base: the review config (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 with lensStart.ts (T3a).
  • Starts one read-only child per lens through the server's own delegate_task (McpServer.callTool, role review), 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).
  • The server writes the prompt: read-only frame, the base's lens prompt, the state question word for word plus "Answer it in a line starting state:", one line per finding starting blocker:/major:/minor:, and from round 2 "check each earlier finding first, then the changes since …".
  • Idempotent: request id lens/<repo>#<pr>/<head>/<lens>; delegate_task runs 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).
  • Refuses: review rules off; a read past 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).
  • Off means off: while the project's effective reviewRules is off, lens_start is not in tools/list, is refused on tools/call and is not found by tool_search (the fork's T3 tool rule).

afterCi: true returns at once. It plans and refuses now (a refusal never waits), then registers a wait through the existing waits feature: a pr wait narrowed to the config's required_checks minus its head_check (the gate's own check is red until the lenses read; the fork's config gives fork-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 in delegate_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:

  • The stored wait record gets an optional action: "lens_start", and its pr spec gets optional checks and head (only lens_start sets them; wait_for's input is unchanged). A head that moves ends the wait with a new outcome, moved.
  • WaitService takes an optional action hook. 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 is lens_start for 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".
  • No new line in any upstream file. The reads are built in WaitWorker (the Waits service 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)

  • Runs again: the same call for the same head returns the running child (from the store), or nothing when every needed lens read this head. The same afterCi call while its wait is open is the same wait (same key). After a wait was delivered, the action's repeat start is the same delegate_task command (same namespace and request id), so it returns the same task.
  • Stops half-way:
    • Crash after delegate_task accepted a child but before the store write: the next call plans the same id, and delegate_task returns that task from its receipt, also from a new session.
    • Crash after the wake was sent but before the delivery was written: the wait is still 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.
    • A restart before CI ends: the wait is in waits.json and 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.
    • The MCP server not built yet after a restart: the wake is held (retry), not delivered without its action.
  • Old or empty state: no 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 no action/checks/head and behave as before. A downgrade to an older build drops action from a stored wait (its wake then comes without the start). A stored moved outcome 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 (no only narrowing, no moved, no action in 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:

  • Plan → children: one review child per lens; id; prompt holds the frame, base lens prompt, state question and state: line, finding lines, round 2 context; the delegate_task input (role, request id, runner).
  • Repeat: running child returned; read head not started again; dead child → attempt 2 with a new id; empty store.
  • Each refusal: rules off; forbidden runner (stops further starts on it); round above max; dirty; unpushed; another branch not checked; moved head (asked, and before the start); unknown PR; unreadable config.
  • afterCi: wait registered on the config checks minus head_check; already green starts; already red starts nothing and says why; a refusal comes before any wait; nothing to read means no wait.
  • Waits: green at the same head runs the action once; red, moved and timeout start nothing; runs again means no second start; restart half-way; not ready; problem message; problem message refused once.
  • Off means off over the real /mcp transport (mcpT3ToolFilter.test.ts): off by default, on, and a project override off.
  • Each guard was spot-checked by removing it: 12 lines, each turned a test red (two did not at first; their tests were made stricter).

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 contracts waitFor. All pass. vp run check:changed: format, lint, knip, typecheck pass; tests 458 passed, 1 failed. That failure is WaitService.checks.test.ts "on a server without systemd…", which also fails on main on macOS (checked with this change stashed; it asserts the Linux wording).

Other changes:

  • The lens prompt (T3a's lensStart.ts) now tells the child to post one new comment with gh pr comment, its first line the lens header, until lens_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.json is set to the measured 3675 bytes (a new tool; nothing cut).

Limits

  • T3 does not read the gate caller's required-lenses input (it lives in a caller workflow). In enforce the config's path rules name the lenses (the fork's config is enforce). Outside enforce lens_start refuses ("not read"), as T3a does.
  • Changed paths come from GitHub's compare API: at 300 files or more it refuses, never plans from a partial list.
  • sameChange / changeOf are not given to the plan, so only the exact head counts as read and a rebase counts as a new round. This fails closed.
  • The after-CI start waits up to a minute for the woken run, inside the delivery sweep. If the orchestrator's run has already ended, the second message says why and it calls lens_start itself.

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 no fork-seams.json change. The tool registers through the existing fork toolkit (layerForkTools) and starts children through upstream's own delegate_task.

Round 1 (lenses code and state at b4d129f)

Finding Fix Test (red without the fix)
major (both): afterCi when the config requires only its head_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 it No CI checks means nothing to wait for, so the lenses start at once (with a note). Refusing instead would block a config the gate accepts; its own check needs the lenses first. WaitService.register also refuses a narrowed pr spec 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"
major (state): the GitHub and disk side had no tests New lensStartServer.test.ts (fake gh/git runner), lensStartChildren.test.ts (temp folder), lensStartTool.test.ts (handler) base-ref read and 404 = missing; missing later page; 20-page cap; 300-file compare; 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 service
minor: a compare answer with no files, or a file without a name, read as no changes Refused, like the 300-file case lensStartServer.test.ts "the compare: …"
minor: inline comments read without state/publishedAt Read as pr_queue.review_flags/inline_post do: reviews with their inline comments, PENDING reviews and comments skipped, an inline comment dated by publishedAt, in review order lensStartServer.test.ts "reads comments, then submitted reviews, then their published inline comments"
minor: the action runs under the shared sweep lock action.run gets 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"
minor: say what a failed children write means lensStartChildren.ts doc: only logged; the stable request id is the guard n/a (doc)
r2 minor (code, state): no test asserts the per-thread request namespace on either start path Test only: the start test now checks that startInRequest and startForWait both run delegate_task in lens_start:<thread>, not the provider session's namespace lensStartServer.test.ts "the after-CI start waits for its thread's run…" (red with either namespace line removed)
r2 minor (code, state): the 100-inline-comment cap is untested Test only: a review with totalCount: 101 refuses lensStartServer.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

  • Runs again: a config with no CI checks starts at once on every call. The plan returns the running or already-read lenses, so a repeat starts nothing new. A retried delivery after a timeout finds the wake and repeats the start, which returns the same tasks.
  • Stops half-way:
    • An action cut off at 90 s, or a crash before the delivery is written: the wait stays delivering, and the next delivery runs it again.
    • A crash between a child's start and the children write: the same request id gives the same task.
    • A refused narrowed wait stores nothing.
  • Old or empty children file: a missing or unreadable file is read as none known (logged), and the next add writes a good one. Only the newest 500 are kept. A stored wait from before this round decodes as before. A narrowed one never had empty checks, because register now refuses that.

Runs: each changed test file alone (lensStartServer 7, lensStartChildren 3, lensStartTool 4, lensStartRun 24, WaitService.action 9, WaitService 68, comments.test.py 44: 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 clean origin/main checkout (macOS).

🤖 Generated with Claude Code

scuttletoby and others added 3 commits November 23, 2026 00:08
`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>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 lens agent · read at: b4d129f
covered: the full diff against main; lensStartRun.ts, lensStartServer.ts, lensStartChildren.ts, lensStartTool.ts, lensStartVisibility.ts, mcpT3ToolRule.ts, WaitService.ts (register, delivery and action), WaitPrJudge.ts, judgePrChecks and the wake text in packages/shared/src/waitFor.ts, the contract in packages/contracts/src/waitFor.ts; docs/fork/README.md, go-live.md and fork-kit/review/REVIEW.md compared with the code; the gate's lens.py and pr_queue.py for how it reads posts.
checks: ran each changed test file alone (waitFor.lensStart 7, lensStartRun 23, WaitService.action 7, mcpT3ToolFilter 29, lensStart 48, waits 17, comments.test.py 44: all pass). Undo checks, each red: config and prompts read at the head instead of the base (18 fail); no confirm read before the start (1 fail); no moved-head rule in judgePrChecks (1 fail); the action never runs on delivery (5 fail). A scratch test, not committed: judgePrChecks with only.checks [] and green CI ends "no_checks" after the grace period, never "passed"; a stored wait with spec.checks [] does not decode.
state: runs again for the same PR and head: the stored children are seen running or their read is seen, so nothing new starts, and request ids are stable so a repeated delegate_task returns the same task. Stops half-way: a child started but not stored is found again by its request id. Head moves while waiting: the wait ends "moved" and starts nothing. Closed or merged PR: refused. Missing config at the base: refused. Lens comments from an older head do not count as reads of this head. Restart while waiting: the stored wait is decoded again and the action runs again on delivery (safe by the stable ids), except the case in the major below.
blocker: none
major: lens_start {afterCi: true} never starts a lens when the base config's only required check is its head_check, which the gate README allows. ciChecksOf (lensStartRun.ts:213) then returns [] and lensStartRun.ts:441 registers the wait with checks []; judgePrChecks (packages/shared/src/waitFor.ts, the named filter) can only end such a wait as "no_checks", and actionText then tells the agent "No review lens starts for this head. Fix and push", which is wrong. The same wait breaks the contract (checks: 1 to 20 names), so after a restart WaitStore drops it as a lost wait. WaitService.ts:800 copies narrow.checks without checking it against the contract. Fix: with no CI checks, start now as for an already green head (or refuse with a clear reason), decode narrow against WaitPrSpec in register, and add a test for each.
minor: readChanges (lensStartServer.ts:372) reads a compare answer with no files array, or a file with no filename, as no changes, which can mean too few lenses; refuse instead, as the 300-file case does.
minor: inline review comments (lensStartServer.ts:310) are read without state and publishedAt, so a comment of a review not yet submitted (PENDING) counts as a lens read and createdAt is its time; the gate skips PENDING and uses publishedAt (pr_queue.py inline_post). Add both fields and match the gate.
minor: the lens_start action runs inside deliverSweep under the shared sweep lock (WaitService.ts:2112); with up to 60 s of waiting for the parent run (lensStartServer.ts startForWait) plus about ten gh calls of up to 60 s each, every other wait's judging and delivery stalls server-wide meanwhile. Put a timeout on action.run, so a slow start returns a problem text and is retried later.
docs: README lens_start section, go-live.md row 4 and REVIEW.md match the code; config, prompts and changes are read at the base tip, the plan comes from the shared planLensStart, and the prompt carries only base files, settings and shas, so a PR author cannot steer which lenses start or what they are told.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: Claude Opus 5.5 lens agent · read at: b4d129f
covered: the full diff against main, with the state question on lensStartRun.ts, lensStartServer.ts, lensStartChildren.ts, lensStartTool.ts, the wait record contract, WaitService register and delivery, and the tests of each.
checks: ran each changed test file alone (all pass: 7, 23, 7, 29, 48, 17 and comments.test.py 44). Undo checks, each red: reads at the head instead of the base (18 fail), no confirm read (1 fail), no moved-head rule (1 fail), action not run on delivery (5 fail). Scratch test, not committed: a wait record with spec.checks [] does not decode.
state: runs again for the same PR and head: stored children are seen running, or their lens read is seen, so nothing new starts; request ids are stable, so a repeat delegate_task returns the same task. Stops half-way (some started, some not): the next call starts only the missing lenses, and a child started but not yet stored is found by its request id. Old head: refused before any start, and the head is read again just before the start. Closed or merged PR: refused. Empty or missing config at the base: refused, "no lens rather than too few". Lens comments from an older head: not a read of this head, so the lens starts again. T3 restart while afterCi waits: the stored record is decoded again and the action runs on delivery; a rerun is safe by the stable ids. Unreadable children file: read as no children, which is still safe by the stable ids.
blocker: none
major: the code that meets GitHub and the disk has no test: lensStartServer.ts (545 lines), lensStartChildren.ts and lensStartCall in lensStartTool.ts are not imported by any test; lensStartRun.test.ts uses an injected world only. Untested: config and prompts read at the base ref, a 404 read as a missing file, partial pages and the MAX_PAGES refusal, the 300-file compare refusal, a compare answer with no files (see the code lens minor), startForWait waiting for the parent run, childRunning, the action wrapper's error text, and the children file kept across a restart and cut to 500. Add a test of the server world with a fake ProcessRunner (gh and git answers) and one of the children store on a temp dir, each red without its code.
major: an afterCi wait with no CI checks (base config whose only required check is the head_check) is stored with spec.checks [], which the contract refuses, so a T3 restart drops it as a lost wait; before a restart it can only end "no_checks", never start the lenses. Same root and fix as the code lens major (lensStartRun.ts:213 and :441, WaitService.ts:800).
minor: lensStartChildren.ts only logs a failed write, so a lost write is found again only through the stable request id; say so in its doc comment.

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 23, 2026 01:07
…-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>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code r2 · reviewer: Claude Opus 5.5 lens agent · read at: 7e8fd0c
covered: the full diff against main and the round-1 fix commit 7e8fd0c: lensStartRun.ts (the no-CI branch), WaitService.ts (register's spec check, the 90 s action limit, the retry path), lensStartServer.ts (compare, reviews and inline comments, startForWait), lensStartChildren.ts, lensStartTool.ts, and the four new or changed test files; delegate_task in OrchestratorMcpService.ts (command id, receipt, uninterruptible dispatch) and the gate's pr_queue.py inline_post and config.py (head_check).
checks: ran each changed test file alone: lensStartServer 7, lensStartChildren 3, lensStartTool 4, lensStartRun 24, WaitService.action 9, waitFor.lensStart 7, mcpT3ToolFilter 29, lensStart 48, waits 17, comments.test.py 44, all pass. Undid each round-1 fix alone, each red: no-CI start (1 fail), register spec check (1), 90 s limit (1, hangs), no-files compare refusal (1), 300-file boundary (1), PENDING review skip (1), PENDING inline skip (1), publishedAt (1), 404 as missing (1), 20-page cap (1), parent-run wait once per action (1), children replace by id (1), newest 500 (1), childRunning's 120 s grace (1).
state: runs again: a head_check-only config starts at once on each call, and the plan returns the running or read lenses, so a repeat starts nothing new. Cut off at 90 s: the wait stays delivering, the retry finds the wake (same message and command id) and reruns the action; delegate_task's command id is the per-thread namespace plus the request id, and its dispatch is uninterruptible, so a cut during a start cannot make a second child; the problem message keeps its own id and command id. A narrowed spec the store cannot decode is refused before anything is stored.
round 1, fixed: afterCi with only the head_check required now starts at once with a note saying there is no CI to wait for (lensStartRun.ts:440). This matches the gate: required_checks is what the ruleset requires, so with only the head_check there is no CI the gate waits for, and only the lenses can turn that check green.
round 1, fixed: WaitService.register refuses a pr spec that does not decode as WaitPrSpec (WaitService.ts:823), so empty checks, more than 20 or a bad head are never stored.
round 1, fixed: a compare answer with no file list, or a nameless file, is refused (lensStartServer.ts:400).
round 1, fixed: PENDING reviews and inline comments are skipped and an inline comment is dated by publishedAt, the same as pr_queue.py inline_post.
round 1, fixed: action.run has a 90 s limit (WaitService.ts:2131) and is then retried; the parent-run wait is 40 s, once per action.
blocker: none
major: none

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state r2 · reviewer: Claude Opus 5.5 lens agent · read at: 7e8fd0c
covered: the full diff against main and the round-1 fix commit 7e8fd0c, with the state question on the no-CI start, register's spec check, the 90 s action limit and its retry, startForWait, the children store, and the tests of each (lensStartServer, lensStartChildren, lensStartTool, lensStartRun, WaitService.action); delegate_task's command id and receipt in OrchestratorMcpService.ts.
checks: ran each changed test file alone, all pass (lensStartServer 7, lensStartChildren 3, lensStartTool 4, lensStartRun 24, WaitService.action 9, waitFor.lensStart 7, mcpT3ToolFilter 29, lensStart 48, waits 17, comments.test.py 44). Undid 14 fix lines one at a time, each red: no-CI start, register spec check, 90 s limit, no-files compare, 300-file boundary, PENDING review, PENDING inline, publishedAt, 404, 20-page cap, parent-run wait once, replace by id, newest 500, 120 s grace. Not red when undone: the per-thread request namespace in startInRequest and startForWait, and the 100-inline-comment cap (minors below).
state: runs again: the same head starts nothing new (running or read lenses come back from the plan), and a head_check-only config starts at once with a note. Stops half-way: if the action is cut at 90 s, the T3 is killed or it restarts while the action runs, the wait stays delivering. The retry or restart holds it until the MCP server is installed, finds the wake by its message and command id (no second wake) and runs the action again. A cut between two child starts: started children are stored or found by their stable request id (delegate_task dispatch is uninterruptible, command id = namespace + request id), so only the missing ones start. A cut after the children write but before the delivery write: the rerun sees them running and returns null, so no problem message. Old, empty or corrupt children file: read as none (logged), and the next add writes a good file. A lens whose child ended unrecorded asks again with the same id and gets the old task back; after the 120 s grace that child counts as ended and the next call starts attempt 2. Two waits firing at once: in one thread they get one joined wake, and the actions run one after another, each with its own limit; a cut reruns both, which is safe. In two threads for the same head, both may start the lens, because the namespaces differ and both can read the store before either writes. That costs a duplicate read only; the gate counts the newest. Dropped as a finding: one orchestrator per PR, and a cross-thread lock is not a small fix.
round 1, fixed: an afterCi wait with no CI checks is gone: it starts at once, and register refuses such a spec, so a restart cannot drop it.
round 1, fixed: the GitHub and disk side now has tests over a fake gh/git runner and a temp folder. They drive the real code: base-ref read, 404, missing page, 20-page cap, 300-file and no-files compare, pending reviews, childRunning, the parent-run wait, children across a restart, newest 500, unreadable file.
round 1, fixed: lensStartChildren.ts says a failed write is only logged and the request id is the guard.
blocker: none
major: none
minor: the per-thread request namespace has no test, yet the 90 s retry, a restart half-way and a lost children write all rely on it to give the same delegate_task command. Replacing it at lensStartServer.ts:499 (startInRequest) or :533 (startForWait) leaves lensStartServer, lensStartTool and lensStartRun green. Fix: in "the after-CI start waits for its thread's run", have the fake callTool read McpInvocationContext and assert requestNamespace is lensStartNamespace(THREAD); add the same assert for startInRequest given a scope from another session of that thread.
minor: the refusal of a review with more than 100 inline comments (lensStartServer.ts:345) has no test: raising the limit leaves every test green. Add a review with totalCount 101 to the reviews test and expect "not all read".

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: merge-path · reviewer: Claude Opus 5.5 lens agent · read at: 7e8fd0c
verdict: safe to merge
covered: the full diff against main (lensStart*.ts, mcpT3ToolRule/visibility, WaitService register and deliverSweep action, WaitPrJudge, shared judgePrChecks only and actionText, contracts WaitPrSpec and the record action, fork-kit/review docs and comments.test.py), read against .github/fork-lens-merge-path.md, #888 row T3b, #870 step 1 and the gate's lens.py and pr_queue.py
checks: each changed test file alone (10 files: 9 vitest, comments.test.py), all green. Removed each round-1 fix and ran its test, each red: the no-CI-checks start now (lensStartRun.ts:441), the narrowed-spec refusal in register (WaitService.ts:823), the compare with no files list (lensStartServer.ts:400), the PENDING review and inline skips (lensStartServer.ts:342 and :351), the 90 s action limit (WaitService.ts:2131), the passed-only action filter (WaitService.ts:2113) and the off-means-off tool check (mcpT3ToolRule.ts:230). Worked through each attack in the brief, below.
attack (a) fewer or other lenses: the lens set comes from the base config and prompts (read at the base ref, never the head) and the compare of base...head; a compare with no files list, a nameless file, 300 or more files, a partial page or more than 20 pages refuses rather than starting too few. A non-enforce config or a missing one refuses. lens_start does not read the gate's own required-lenses input (documented); that only costs a start, the gate still blocks the head.
attack (b) head text as instructions: the prompt carries only base-ref lens text, settings, repo, PR number, lens names and shas; no PR title, body, branch name, comments or head file text.
attack (c) gate counts a read it should not: no gate code changed. lensPosts mirrors lens.py (author associations, bots skipped, edited or hidden posts read nothing, override needs an unedited post), and reviews and inline comments skip PENDING and use publishedAt like the gate. A wrong count here only skips or repeats a start; the gate judges on its own.
attack (d) not green or not current: the after-CI wait is pinned to the head (moved ends it, the action starts nothing), the action passes that head and the plan refuses a moved head, and the head is read again just before each start. A named check that is missing is not yet met; a renamed check times out. Only a passed wait runs the action; red, moved and timeout wake the caller with "no review lens starts". A head workflow that fakes a required check name can only start the lenses early, which adds reads but never a pass: branch rules and the gate still require the real checks.
attack (e) block or flood other waits: the action runs after its wake is delivered, with a 90 s limit, and a timeout is a retry with backoff, not a stall; the stable request id (per repo, PR, head, lens) means a re-run or a restart finds the same child instead of a duplicate, and repeats are capped. slots_full is a refusal, not a queued child.
attack (f) another repo or project: the repo comes from the calling thread's project remote and the wait's repo from the same project; a mismatch ends the wait as moved. The tool is off unless that project's review rules are on (tools/list, tools/call and tool_search).
no CI checks, start at once: safe. With required_checks only the head_check, the gate needs nothing but the lens reads, so starting the lenses now only adds reads; it cannot let the head pass unread.
public repo: nothing personal in the diff or this comment; no tokens.
fork-ci-result: success on this head.
state: runs again for the same PR and head: stored or found-by-request-id children are seen running or their read is seen, so nothing new starts. Stops half-way (action cut at 90 s, or a crash after a start but before the children file is written): the next delivery runs the action again and the stable request id returns the same child. Old head: refused, and a pinned wait ends moved. Empty or missing base config: refused. Unreadable children file: read as none, still safe by the request id. Restart while waiting: the stored narrowed wait decodes (register refuses any narrowed spec the store could not read back) and the action runs on delivery.
round 1, fixed: no-CI-checks start now; narrowed spec checked in register; compare with no files or a nameless file refused; PENDING reviews and inline comments skipped with publishedAt; 90 s action limit; server-side reads and children store now tested; children file doc comment says a lost write is found by the request id.
blocker: none
major: none
minor: none

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 23, 2026 02:01
- 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>
@scuttletoby
scuttletoby merged commit c773477 into main Nov 23, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant