Repository navigation
fix(web): coordinator and sprint panels keep their finished children - #589
Conversation
Shell snapshots leave out idle subagents and settled threads beyond the 25 newest, so a coordinator's finished children and a sprint's or Petal's settled launched threads dropped out of the Threads panel after a reload or reconnect. The panel now holds the owner's thread family while it lists, and a bot's family read also returns the threads it launched (bot-work:<id>), gated so other family reads keep the root index alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR changes the test suite by +3 test cases (browser +1, unit +2, server 0). New browser test files: Keep tests that would fail for a real reason, and test logic below the UI where it can be. See Testing. |
|
Keeping the browser test: the bug is the panel not mounting the owner's thread family, which is a component wired to its hooks, and this file fails on |
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code review: 01447c7aae0461da45c6b33d94eaa0795e43de82
I found nothing blocking. I read the diff and traced the paths it depends on, and I ran its three tests at this commit. All three pass:
- the
ProjectionStorefamily case forkPanelTrimmedChildrenCoordinatorPanel.browser
What I checked
The client keeps the rows it reads. The family read runs once per shell generation and is merged in behind the shell's rows. ShellStream sends thread.removed only when a thread is archived or deleted. So when a child goes idle or settles mid-session, it stays in the shell until the next snapshot. That new snapshot starts a new generation, which runs a fresh family read. No removal outranks the family copy, so finished children don't flicker out of the panel while it's open.
Coordinator children. Every coordinator child is a delegate_task subagent, own-checkout ones included, so it shares the coordinator's lineage.rootThreadId. Mounting the family is enough for coordinators, as the description says. useOpenThreadFamily in ThreadRouteView only mounts when the open thread is missing from the shell, so the new hook is needed.
The SQL keeps upstream's results. The familyOf filter moved from a predicate on t to t.thread_id IN (…):
- The root branch uses the same
CASE WHEN json_valid(...)expression, so the expression index still applies. - A missing or deleted
familyOfstill gives an empty set or the deleted thread's root, as before. - The bot branch begins with
CROSS JOIN, which pins the join order. Thebotrow looks upownerby primary key first, so for a thread that isn't a bot, the tag scan overworknever runs. json_each(NULL, …)returns no rows.- Archived and deleted bot-work threads are still excluded, because
readOmittableShellRowsuseslocation: "active"and the query excludes deleted threads by default. The new test covers the archived case.
Other readers of the family. ForkSubagentLinkChip, the scheduled-task editors (web and mobile), and olderSettledThreads all look threads up by id or check read status. Extra bot-work rows in a bot's family don't change what they decide. In the sidebar, those rows stay hidden by isBotWorkOffSidebar while their bot is listed.
Surfaces. Mobile only counts bot work into the bot grid. It has no per-bot Threads list, so leaving mobile out is right. No contract change.
Non-blocking notes
- Cost per read for large Petals. The family read for a bot builds full shell rows for every active
bot-work:<id>thread, including the ones already in the shell. The description gives 20 ms for the SQL, but that excludes the per-row shell subqueries (messages, runs, plans, report). It runs once per generation per mounted owner, so it's fine now. If a Petal builds up hundreds of unarchived launched threads, check this read first. - Stale doc comment. The doc comment on
createThreadFamilyAtoms(packages/client-runtime/src/state/threadFamilies.ts) still says a family is "every active thread sharing alineage.rootThreadId". For bots that's no longer the whole set. The manifest entry and theShellSnapshotOptions.familyOfdoc already note it. Leaving the upstream file alone to keep the fork's footprint small is reasonable.
🤖 Review: Claude Opus 5.5 (claude-opus-5-5) via Claude Code, single pass, reviewed 01447c7aae
NoahHendrickson
left a comment
There was a problem hiding this comment.
Thermo-nuclear code-quality review of 01447c7 (base 435c741).
The client half is right: it's upstream's on-demand family read, mounted while a panel lists. The server half is where this falls short. It quietly changes what a "thread family" means for every caller, it fetches more rows than the panel can show, and it rewrites upstream's predicate in a way the fork now has to carry on every sync. Not approving. Findings, most structural first:
1. The bot-work branch fetches far more than "the threads a bot launched". WHERE tag.value = forkBotWorkTag(familyOf) has no lineage filter. Subagents inherit bot-work:<bot> (provider-core subagentProjection → forkSubagentTags keeps every tag except bot, coordinator and mascot). So a sprint's family read now returns every idle subagent of every work thread the sprint launched. Those are the rows omitIdleSubagents exists to keep off the wire, and the panel never shows them: groupBotWork goes through threadParentOf, which resolves a subagent to its own parent, not to the bot. On a long-lived sprint that is a lot of shells shipped and merged into the shell rows for nothing. Limit the branch to what the panel lists: top-level work (relationshipToParent IS NOT 'subagent', plus side chats if groupBotWork excludes them). Then add a row to the ProjectionStore family case (a subagent of bot-work stays out) so the server's definition and the panel's are pinned to each other.
2. This changes the meaning of a shared contract without saying so. OrchestrationV2ThreadFamily (packages/contracts) still documents a family as "the active threads that share the requested thread's lineage.rootThreadId". createThreadFamilyAtoms in client-runtime says the same. Both are now false for bots, and only ShellSnapshotOptions got a one-line note. This is bot-feature logic leaking into a general read. Every family read of a bot now pays for the bot's work, not just the panel: the ThreadRouteView / split-pane open-thread mount, ForkSubagentLinkChip, ScheduledTasksSettings, and mobile. There are two honest options:
- (a) Make it an explicit opt-in, e.g.
includeBotWorkonGetThreadFamilyInput, passed only byuseHeldBotWork. That is a contract change and needs the maintainer's sign-off, but then the panel is the only caller that pays and "family" keeps its meaning. - (b) If staying contract-free is a firm rule, rewrite the contract and client-runtime docs so the invariant they state is true. Don't leave a doc that lies.
3. The SQL rewrites upstream's predicate instead of adding to it. Upstream's single root comparison became t.thread_id IN (… UNION ALL …). The gate is a derived table cross-joined first, with a comment that only says "bot drives first". It is correct (SQLite does keep CROSS JOIN order), but a reader can't see it's a short-circuit, and every upstream edit to the family predicate will now conflict with a differently shaped fenced block.
There's a simpler move: decide bot-ness in TypeScript before building the query. A primary-key lookup of the requested thread's tags in readShellSnapshot/readShellSnapshotRows would be enough, and the bot-work tag (or null) is passed into selectShellThreadRows.
- Non-bot family reads then run upstream's SQL byte for byte, so the 0.1 ms path is provably unchanged.
- The fork part becomes one small fragment with no ordering trick.
- The derived table, the second
json_validCASE and the IN/UNION wrapper all go away. - The cost is one extra indexed read on the family path, which is cheap next to the shell build it precedes.
4. Tests: the new browser test duplicates the guard. CoordinatorPanel.browser.test.tsx boots AppRoot plus ChatView (the comment admits the transform cost) to assert that one useEffect mounts a family. That is callback wiring, and forkPanelTrimmedChildren already pins it in text. The merge behaviour it relies on (threadFamilyRowsMissingFromShell) is upstream's and already tested. The coverage that matters here is server-side, and finding 1 shows it is missing a case. I'd drop the browser test, or fold one assertion into an existing appScenarios/ChatView olderSettled case if you want a UI-level check.
Minor: useHeldBotWork holds a coordinator's family too, so "bot work" undersells it. Something like useHeldPanelFamily would read truer. Not blocking.
No file-size concerns: ProjectionStore.ts was already over 10k lines before this PR, and the web files stay small.
| ) bot | ||
| CROSS JOIN orchestration_v2_projection_threads work | ||
| CROSS JOIN json_each(CASE WHEN json_valid(work.payload_json) THEN work.payload_json END, '$.tags') tag | ||
| WHERE tag.value = ${forkBotWorkTag(familyOf)} |
There was a problem hiding this comment.
No lineage filter here. Subagents inherit bot-work:<bot> via forkSubagentTags, so this returns every idle subagent of every launched thread. omitIdleSubagents trims exactly those rows, and groupBotWork (via threadParentOf) never lists them. Limit this to top-level work, e.g. AND json_extract(work.payload_json, '$.lineage.relationshipToParent') IS NOT 'subagent'.
There was a problem hiding this comment.
Fixed in feb5e41. The bot-work read now adds json_extract(t.payload_json, '$.lineage.relationshipToParent') IS NOT 'subagent', so only top-level launched threads come back.
| FROM orchestration_v2_projection_threads member | ||
| WHERE member.thread_id = ${familyOf} | ||
| : /* fork:begin fork-panel-trimmed-children — see .fork/customizations.yaml#fork-panel-trimmed-children */ | ||
| // A bot's family also holds the threads it launched (bot-work:<id>), which share no |
There was a problem hiding this comment.
This rewrites upstream's family predicate rather than adding to it, and the gate depends on the CROSS JOIN order of a derived table. Could we decide bot-ness in TS first (a PK lookup of the requested thread's tags) and pass the bot-work tag, or null, into selectShellThreadRows? Non-bot reads would then keep upstream's SQL verbatim (no sync conflicts, perf provably unchanged), and the fork part shrinks to one plain optional fragment.
There was a problem hiding this comment.
Done in feb5e41. Upstream's familyOf SQL is restored byte for byte. forkBotWorkFamilyRows does a primary-key lookup of the requested thread's tags. Only for a bot does it run a second selectShellThreadRows with a fork-only forkBotWorkOf filter, appended with AND, so there's no ordering trick. Non-bot reads cost one extra indexed read.
| archived: true, | ||
| }); | ||
| yield* createThread({ name: "plain-work", tags: [`bot-work:${id("root")}`] }); | ||
| assert.sameMembers( |
There was a problem hiding this comment.
Please add a row: a subagent of bot-work (parent bot-work, root bot-work, carrying the inherited tag) stays out of the bot's family. Today it would be returned (see the comment on the SQL).
There was a problem hiding this comment.
Added in feb5e41: bot-work-subagent (parent and root bot-work, inheriting the tag) stays out of the bot's family. The case would fail on the round-1 SQL.
| trackRpcRequestSent: () => {}, | ||
| })); | ||
|
|
||
| it("lists a finished child the shell snapshot leaves out", async () => { |
There was a problem hiding this comment.
This boots the whole AppRoot plus ChatView to check that one effect mounts a family. That is wiring the fork guard already pins, and the merge itself is upstream's and already tested. Per the repo's test rules (one layer, no wiring tests, browser tests only where a browser is needed), I'd drop this and put the coverage in the server family case.
There was a problem hiding this comment.
Keeping this one. The bug is that the panel never asked for the rows the shell leaves out. The guard pins source text, so it would still pass if the hook moved somewhere that doesn't run while the panel lists, or if the family read never reached the listing. This test renders the real panel against a shell that omits the child, and it fails on custom without the hook. The server case covers the SQL; this covers the client half the server test can't. It costs one browser file (~10 s locally).
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
… untouched Review of #589: subagents inherit bot-work:<id>, so the family read shipped every idle subagent of a bot's work, which the panel never lists. Bot-ness is now decided by a primary-key check in TypeScript, and only a bot gets a second read of its top-level bot-work threads; every other family read runs upstream's query unchanged. The family docs in contracts and client-runtime note the bot case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review follow-up, pushed as feb5e41:
Sol round 2 (GPT-6.1 Sol, high): APPROVE, no findings. |
Children dropped out of a coordinator's Threads panel after a while, and settled work dropped out of sprint and Petal panels too. The panel list never hides them; the server never sent them. Web shell snapshots trim idle subagents (
omitIdleSubagents) and keep only the 25 newest settled top-level threads (omitOlderSettled, seeShellStream.ts). A coordinator's delegated children are subagents, and a sprint's or Petal's launched threads are top-levelbot-work:<id>threads. So on the next snapshot (a reload or a reconnect), a finished child was left out. In the live data, coordinator fad7fd93's five idle children were all missing, as were 5 of the no3y code sprint's settled threads and all 12 of a Petal's.Fix
custom/bots/useHeldBotWork.ts: while a Threads panel lists (Petal, sprint and coordinator shareuseBotThreadsListing), it mounts the owner's thread family. That is upstream's on-demand read for rows the shell leaves out, merged in behind the shell's rows. A coordinator's children share its root, so this alone fixes coordinators.ProjectionStore: for a thread taggedbot(a primary-key check of its tags), the family read also returns its active top-levelbot-work:<id>threads, which have their own roots. Their subagents, which inherit the tag, are left out. Every other family read runs upstream's query unchanged. No contract change; the family docs in contracts and client-runtime note the bot case.Sprint panels show settled work on purpose (their "Settled" section), so they get the same fix.
Tests
ProjectionStore.test.tsfamily case: a bot's family includes its active launched threads, not archived ones, and not those of a non-bot. It fails without the server change.CoordinatorPanel.browser.test.tsx: a settled child the shell leaves out is still listed under Settled. It fails without the hook.forkPanelTrimmedChildrenand manifest entryfork-panel-trimmed-children.Checked against a scratch dev server seeded with copies of the live coordinator's rows. Before the fix, the panel says "This coordinator has not delegated any work." After it, all five children are listed, and one marked settled sits under Settled.
Reviewed with sol-loop: 2 rounds with GPT-6.1 Sol. Sol verdict: approved
🤖 Signed: Claude Opus 5.5 (
claude-opus-5-5) via Claude Code🤖 Review: GPT-6.1 Sol (
gpt-6.1-sol, high effort) via Codex, two sol-loop rounds, no findings🤖 Generated with Claude Code