Skip to content

fix(sidebar): nest a delegated remote worker under its coordinator - #4

Merged
kiwidream merged 5 commits into
mainfrom
kiwidream/resume-nesting-research
Sep 23, 2026
Merged

kiwidream merged 5 commits into
mainfrom
kiwidream/resume-nesting-research

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 23, 2026 •

Copy link
Copy Markdown

ELI5

When you hand a job to an agent on another machine, its workspace shows up in the sidebar as its own card, off on its own, with nothing tying it to the workspace you started it from. This makes it appear underneath the workspace that sent the work, the way a local helper already does.

What Changed

Before: a worker started with orca orchestration worker-start --on <server> gets a top-level card, filed under the remote machine's own repository section. People look for delegated work under the coordinator's card and don't find it there.

▼ orca  (this Mac)
  ▣ my-workspace              ← the coordinator
▼ orca  (dev box)
  ▣ worker-1
  ▣ worker-2

After:

▼ orca  (this Mac)
  ▣ my-workspace              ← the coordinator
     ├─ ▣ worker-1   dev box
     └─ ▣ worker-2   dev box

The mechanism. Nesting has always come from git lineage, which only links a worktree to a parent in the same repository on the same execution host (runtime-worktree-lineage-controller.ts:89). Every host mints its own repository ids, so a cross-host parent can never satisfy that rule, and the remote create path records no parent at all (federation.ts:116).

The coordinator's own runtime already knows both ends: which terminal dispatched each worker, and which remote worktree it landed in. This adds a small projection that pairs the two, publishes the pairs on the existing renderer graph sync, and lets the sidebar nest a card from one when the card has no git lineage of its own.

Scope guards, on purpose:

  • The pair is never written as lineage, so removal, "delete all", drag-to-reparent and base-branch behaviour are untouched and stay host-local.
  • Git lineage always wins; the pair is only a fallback where lineage cannot be recorded.
  • Both ends are host-qualified (STA-4343), so a repository id registered on two machines cannot nest the wrong card.
  • Edges that would close a cycle, or whose coordinator row is not on this machine, are dropped.
  • Repo grouping renders the child in its coordinator's section; status and PR lanes keep lane membership, exactly as lineage does today.

Why

The alternative was letting lineage itself span hosts: host-qualified worktree ids, a lineage store shared across machines, a relaxed parent rule, and "delete all" routed per host. That is a redesign of a safety boundary, and the payoff here is a display relationship, so this keeps the boundary and treats the grouping as what it is — presentation owned by the orchestration records, the same division the agent status store already uses.

A skills-side workaround was tried first (coordinate from the worker host, or pre-create the child there and place the worker on it). It works, but it asks every coordinator to change how it delegates to get a card in the right place.

Nothing crosses the client/host wire: the data is already on the coordinator's machine, so no capability negotiation is needed, and a coordinator with no remote workers publishes nothing.

Linked Issue

Fixes #

Visual Proof

Not captured, and I want to be straight about why: reproducing this needs a coordinator on one machine and a paired server on another, and I only had the server side. The behaviour is pinned by tests instead — delegated-worktree-nesting.test.ts asserts the remote card renders at depth 1 inside the coordinator's section with an edge, and top-level in its own section without one.

Before/after screenshots from a real pair would be a genuinely useful addition from a reviewer who has both machines.

Testing

  • pnpm tc — clean.

  • pnpm run check:code-quality:changed — passes.

  • pnpm test over src/renderer/src/components/sidebar, src/renderer/src/store, src/renderer/src/runtime, src/main/runtime: 16,221 passed, 31 skipped.

  • 12 new tests: the nesting rule (lineage precedence, foreign coordinator, cycle, repeated dispatch onto one worktree), row placement in repo grouping, and the producer (handle lookup, pane-key fallback after a restart, missing coordinator, self-reference, host that cannot answer).

  • Platforms: run on Linux. Not exercised on macOS or Windows; the change is host-agnostic TypeScript with no path or shell handling.

  • Manual cross-host check not done — see Visual Proof.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Written by Claude Opus 5 via Claude Code.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Backwards compatibility: the published field is optional; a renderer that never receives it behaves exactly as before.
  • Remote/SSH: no wire change. An SSH-hosted coordinator worktree is not stamped with the publishing runtime's host, so its edges are dropped rather than guessed — the card stays top-level, as today.
  • Performance: one indexed query per graph sync, capped at 500 rows, and the result is identity-compared before it reaches the store, so an unchanged set triggers no re-render.
  • Security: no new input path; the data never leaves the coordinator's machine.
  • Mobile: untouched.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

A worker started with `--on <server>` becomes a top-level card, because git
lineage only nests a worktree under a parent in the same repository on the
same host and each host mints its own repo ids. The coordinator's own runtime
already records which terminal dispatched the worker and which remote worktree
it landed in, so publish that pairing to the sidebar and nest the card from it.

Presentation only: the edge never becomes lineage, so removal, "delete all"
and base-branch rules stay host-local.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 4 medium

💬 Inline comments (3)

📍 Outside the diff (1)

  • 🟡 Pinned section drops delegated-worktree nesting (pinned-group-rows.ts:80–87) — The Pinned section's appendWorktreeRows call does not receive delegatedParentIdentityByChildIdentity, unlike the flat and per-section paths that both pass it (build-rows.ts:210, build-rows.ts:258).
🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Reuse-ordering test contradicts newest-first DB order (delegated-worktree-nesting.test.ts:90) — listDelegatedWorktreePlacements orders rowid DESC, so a reused worktree's newest dispatch reaches the renderer first (federated-dispatch-store.ts:113).

Reviewed commit: 2fc332e

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T17:26:41.054620Z 96c76d5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand to see previous review

Adds cross-host delegated-worktree sidebar nesting via a new host-qualified edge projection published through the runtime graph sync, with grouping, store, and contract updates plus tests.

? resolveDelegatedWorktreeNesting({
worktrees,
edges: delegatedWorktreeEdges,
homeHostId: defaultHostId,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Nesting homeHostId gets focused host, not publishing runtime's

resolveDelegatedWorktreeNesting documents homeHostId as the host the publishing runtime stamps its own worktrees with, but its only caller passes defaultHostId, which getSettingsFocusedExecutionHostId derives from settings.activeRuntimeEnvironmentId (build-rows.ts:97, WorktreeList.tsx:99). Once the user focuses a remote runtime environment, edge parents are host-qualified with that remote id while coordinator rows carry the local stamp, so the byIdentity lookup misses and every delegated edge silently disappears from the sidebar — or nests under a same-id row on the wrong host.

📋 Prompt for AI Agents

In src/renderer/src/components/sidebar/worktree-list/grouping/build-rows.ts around line 97, stop passing defaultHostId as homeHostId to resolveDelegatedWorktreeNesting; pass LOCAL_EXECUTION_HOST_ID (already imported) instead, since the edges come only from this runtime's own graph sync and the focused host changes with settings.activeRuntimeEnvironmentId, which would drop all delegated edges whenever the user focuses a remote runtime environment.

Comment on lines 90 to +111
@@ -103,7 +108,7 @@ export function buildOrderedGroups(args: {
}
const group = grouped.get(key)!
group.items.push(w)
addRepoIdToGroup(group, w.repoId)
addRepoIdToGroup(group, anchor.repoId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Anchored delegated child's repo loses fallback cards

A delegated child is bucketed into its coordinator's repo section, so only anchor.repoId enters the group's repoIds (worktree-grouping.ts:111) and the child's own repo renders no section. But getRenderedNaturalAnchorRepoIds still marks the child's own repoId as rendered (section-order.ts:44-46), and emitPinnedGroup suppresses the imported-worktrees fallback whenever that set contains the repo (pinned-group-rows.ts:66,103). A repo whose only natural worktree is a delegated child therefore loses its imported-worktrees card, inbox and pending-creation rows entirely instead of showing them somewhere.

📋 Prompt for AI Agents

In src/renderer/src/components/sidebar/worktree-list/grouping/worktree-grouping.ts, in the naturalWorktrees loop (around lines 86-112), when anchor !== w (a delegated child was re-bucketed), also call addRepoIdToGroup(group, w.repoId) in addition to addRepoIdToGroup(group, anchor.repoId), so the child's own repo keeps its imported-worktrees card, external-worktrees inbox row, and pending-creation rows inside the coordinator's section; verify getRenderedNaturalAnchorRepoIds in section-order.ts stays consistent with the rendered repoIds.

Comment on lines +31 to +35
build(): DelegatedWorktreeEdge[] | undefined {
const db = this.deps.getDb()
if (!db?.listDelegatedWorktreePlacements) {
return undefined
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

DB-unavailable window publishes absent, clearing live edges

build() returns undefined for three different conditions — DB not yet available, DB lacking the placement query, and genuinely zero placements (runtime-delegated-worktree-edge-projection.ts:31-35). The sync window omits the field when build() is undefined, and the renderer commits result?.delegatedWorktreeEdges ?? [] (graph-publication.ts:193), so during a transient DB-unavailable window previously published edges are wiped from the sidebar even though the placements still exist. Delegated cards briefly un-nest and then re-nest on the next sync after the DB returns.

📋 Prompt for AI Agents

In src/main/runtime/runtime-delegated-worktree-edge-projection.ts, separate the three undefined cases in build(): when getDb() returns null or the db lacks listDelegatedWorktreePlacements, return a distinct sentinel the sync publisher in orca-runtime-sync-window-graph.ts can use to omit the field as unsupported, and reserve the plain-empty case for genuinely zero placements. Keep the contract comment in src/shared/runtime-session-contracts.ts consistent with whichever encoding you choose, so a transient DB-unavailable window never clears edges the renderer already holds.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fc332e66a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +39 to +40
if (!parentWorktreeId || parentWorktreeId === placement.remote_worktree_id) {
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compare self-references with host-qualified identities

When a local coordinator and remote worker happen to have the same bare worktree ID, this condition drops their edge even though they are on different hosts. Bare-ID collisions are valid in the multi-host catalog, and resolveDelegatedWorktreeNesting already rejects a true self-reference after composing both host-qualified identities, so this early comparison prevents an otherwise valid worker from nesting.

Useful? React with 👍 / 👎.

Comment on lines +94 to +97
? resolveDelegatedWorktreeNesting({
worktrees,
edges: delegatedWorktreeEdges,
homeHostId: defaultHostId,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Anchor coordinator edges to the publishing host

When activeRuntimeEnvironmentId is set, defaultHostId names the focused remote environment rather than the local runtime whose orchestration database published these edges. A local coordinator row is therefore looked up as runtime:<focused-env>|<id> instead of local|<id>, so all locally coordinated remote workers stop nesting while a remote environment is focused; use the publishing runtime's host identity independently of the sidebar focus.

Useful? React with 👍 / 👎.

Comment on lines +16 to +18
childHostId: ExecutionHostId
childWorktreeId: string
dispatchId: string

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fence delegated edges by worktree instance

Because settled dispatch placements are intentionally retained, deleting a remote worker worktree and later creating an unrelated worktree at the same ID/path causes the new card to match this stale edge and nest under the old coordinator. Worktree lineage uses instanceId specifically to fence path reuse; the delegated edge likewise needs the child's instance identity or another validation/removal mechanism before matching the current catalog row.

Useful? React with 👍 / 👎.

Comment on lines +92 to +94
const delegatedNesting =
nestLineage && delegatedWorktreeEdges.length > 0
? resolveDelegatedWorktreeNesting({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate delegated descendants into the pinned section

With the default single-location pinned policy, pinning the coordinator does not pull its delegated child into the Pinned section because getPinnedSectionWorktrees traverses only git lineage and emitPinnedGroup never receives this delegated projection. The parent is removed from the natural groups while the worker remains there, so the worker is rendered top-level instead of beneath its pinned coordinator; delegated descendants need to participate in pinned membership and row emission just like lineage descendants.

Useful? React with 👍 / 👎.

Comment on lines +257 to +258
cyclicLineageIds,
delegatedParentIdentityByChildIdentity: delegatedNesting?.parentIdentityByChildIdentity

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid orphaning nested rows in host-section views

When the user explicitly selects two or more hosts, addHostSectionRows later partitions rows by their actual host. This delegated map has already assigned the remote child depth 1 beneath a local parent, so the partition moves the child into the remote host section while leaving its parent and repo header in the local section, producing an indented orphan row. Cross-host nesting should be disabled or flattened for host-partitioned views, or the hierarchy must be kept together deliberately.

Useful? React with 👍 / 👎.

…cused host

The edges arrive on this window's own graph sync, so their coordinator is
always a local row, but the lookup composed the parent identity with the
focused execution host. Focusing a remote environment — the very case this
nests for — made every edge miss and the cards fall back to top-level.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Edge cap silently drops older placements (runtime-delegated-worktree-edge-projection.ts:6) — MAX_DELEGATED_EDGES = 500 limits the placement query, and rows beyond the cap are silently excluded (runtime-delegated-worktree-edge-projection.ts:6).

This PR wires delegated-worktree edges from the federation dispatch store through graph sync into the sidebar, so delegated child worktrees nest under their coordinator worktree in repo-grouped lists.

Reviewed commit: 67f213e

luxor-code-review[bot]
luxor-code-review Bot previously approved these changes Sep 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67f213e709

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const delegatedNesting =
nestLineage && delegatedWorktreeEdges.length > 0
? resolveDelegatedWorktreeNesting({
worktrees,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include folder workspaces in delegated nesting

When either endpoint is an exact folder workspace—a supported federated placement—the edge can never match because only worktrees are passed into the resolver, while folder workspace cards are maintained and emitted separately. Consequently a remote worker delegated from or into a folder workspace remains top-level even though the dispatch records contain both endpoints; include folder workspace identities and row emission in the delegated projection.

AGENTS.md reference: AGENTS.md:L93-L95

Useful? React with 👍 / 👎.

INNER JOIN dispatch_contexts dc ON dc.id = fd.dispatch_id
WHERE fd.remote_worktree_id IS NOT NULL
ORDER BY fd.rowid DESC
LIMIT ?`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve live placements beyond the dispatch cap

Once the database contains more than 500 newer federated dispatch rows, this unconditional limit omits older placements even when their remote workspaces are still visible, causing those cards to jump back to top level. Repeated dispatches onto one shared workspace make this especially easy because duplicate placements consume the entire cap; deduplicate/filter by current child workspace before applying the limit so historical rows cannot evict unrelated live edges.

Useful? React with 👍 / 👎.

Four review findings on delegated-worker nesting.

The edge projection returned undefined for three different conditions, and the
sync window omitted the field for all of them, so a renderer committing `[]`
could not tell "this runtime coordinated nothing" from "the orchestration db
is not up yet". A transient gap un-nested every delegated card until the db
came back. build() now answers known/unknown, the window publishes
delegatedWorktreeEdgesUnavailable instead of an empty list when the db cannot
be asked, and the renderer keeps the edges it already holds. The flag is a new
optional field, so an older client simply ignores it and behaves as it does
today.

The projection also dropped an edge whenever a coordinator and its worker
happened to share a bare worktree id. Those ids collide legitimately across
hosts, and a real self-reference is only decidable once both ends are
host-qualified, which resolveDelegatedWorktreeNesting already does.

A delegated child renders inside its coordinator's repo section, which left
its own repo with no section and silently dropped that repo's imported
-worktrees card, external-worktrees inbox and pending-creation rows. Those
notice rows now follow the child into the section it actually renders in,
unless the repo turns out to have a section of its own.

The homeHostId fix the reviewers asked for is already present at the base
commit; its test now derives the focused host through
getSettingsFocusedExecutionHostId, the production path, so it fails if that
regresses.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

Reviewed commit: 0537cf2

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand to see previous review

Adds delegated-worktree nesting to the sidebar grouping, publishing parent-child edges through the runtime graph sync, with duplicated notice rows when an anchored repo also gets its own section.

Comment on lines 121 to 127
for (const [repoId, sectionKey] of anchoredSectionKeyByRepoId) {
const ownKey = getProjectGroupingForRepo(repoId, repoMap, projectIndex).key
if (ownKey === sectionKey || grouped.has(ownKey)) {
// The repo has a section of its own after all; leave its notice rows there.
anchoredSectionKeyByRepoId.delete(repoId)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Notice rows duplicate when anchored repo gets own section

When a delegated child's repo also has a section of its own, buildOrderedGroups deletes the anchoredSectionKeyByRepoId entry but never removes that repoId from the anchor group's repoIds set (src/renderer/src/components/sidebar/worktree-list/grouping/worktree-grouping.ts:121-127).

appendOrderedGroups then iterates group.repoIds and emits the imported-card, inbox, and pending-creation rows for the child's repo in the coordinator section as well, with the same repo-only row keys (e.g. imported-worktrees-card:repo-group:<repoId>), duplicating the notice card across two sections and breaking row-key uniqueness for the virtualizer. The foreign repoId also flows into getManualOrderAnchorRepo, so the coordinator section's manual-order rank and drag anchor can be taken over by the remote repo.

📋 Prompt for AI Agents

In src/renderer/src/components/sidebar/worktree-list/grouping/worktree-grouping.ts lines 113-127, restructure the anchoring bookkeeping: add the child's repoId to the coordinator group's repoIds only tentatively during the naturalWorktrees loop, then after the existing deletion loop (which drops repos that ended up with their own section) remove the child's repoId from the coordinator group's repoIds for every repo whose anchor entry was deleted, so notice rows (imported card, inbox, pending) render in exactly one section and getManualOrderAnchorRepo is not polluted by the remote repo.

@luxor-code-review
luxor-code-review Bot dismissed their stale review September 23, 2026 17:08

A newer Tenki review found issues on this pull request.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0537cf2cd7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

const agentOrchestrationByPaneKey = this.agentOrchestrationProjection.buildByPaneKey()
const delegatedEdges = this.delegatedWorktreeEdgeProjection.build()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Republish edges when placements change

When a remote worker becomes ready after the renderer's last graph publication, updateFederatedDispatchResources changes only SQLite and does not schedule another renderer graph sync, while this projection is sampled only inside syncWindowGraph. The remote-worktree refresh can therefore make the worker card appear at top level, where it remains until an unrelated tab, title, or status event triggers another sync; publish or invalidate the edge projection when the placement is written.

Useful? React with 👍 / 👎.

repoMap,
worktreeMap,
worktreeLineageById,
delegatedWorktreeEdges,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Feed delegated ancestry into collapsed-group reveals

When the coordinator's repo section or lineage fold is collapsed, selecting its delegated worker through pending reveal or the agent-send picker cannot expose the card. The edge is passed only to row construction here, while useEffectiveCollapsedGroups and pending-reveal handling derive section and ancestor keys solely from the worker's own repo and Git lineage, so they open the wrong repo section and never open the coordinator's fold; use delegated ancestry when computing reveal keys as well.

Useful? React with 👍 / 👎.

Review follow-up on the previous commit. Redirecting a delegated child's
notice rows into its coordinator's section dropped the redirect when the repo
turned out to have a section of its own, but left that repo in the coordinator
group's repoIds. Both sections then emitted the imported-worktrees card, the
external-worktrees inbox and the pending-creation rows under identical
repo-keyed ids — a duplicated card and a React key collision.

Releasing the claim now releases the repoId too. A coordinator section that is
already the repo's own section keeps it, since the rows belong there once.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (2)

Reviewed commit: 4b5d038

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand to see previous review

Adds delegated worktree edges (cross-host worker placements) projected from the orchestration db into sidebar nesting, with two medium-confidence defects around duplicate anchored sections and a truncating edge cap.

Comment on lines +116 to 135
if (anchor !== w) {
addRepoIdToGroup(group, w.repoId)
anchoredSectionKeyByRepoId.set(w.repoId, key)
}
}
for (const [repoId, sectionKey] of anchoredSectionKeyByRepoId) {
const ownKey = getProjectGroupingForRepo(repoId, repoMap, projectIndex).key
if (ownKey === sectionKey) {
// The coordinator's section is this repo's own section, so its rows already belong here.
anchoredSectionKeyByRepoId.delete(repoId)
continue
}
if (grouped.has(ownKey)) {
// The repo has a section of its own after all. Drop the claim here as well as the
// redirect: the repo-keyed row ids are identical in both sections, so emitting from
// each would duplicate the card and collide the keys.
grouped.get(sectionKey)?.repoIds.delete(repoId)
anchoredSectionKeyByRepoId.delete(repoId)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Overwritten repo anchor leaves stale repoIds in previous section

When two delegated children of the same repo anchor to coordinators in different sections, anchoredSectionKeyByRepoId.set(w.repoId, key) overwrites the first claim but the first coordinator's group keeps the child repo in its repoIds (worktree-grouping.ts:117-118). The cleanup loop at lines 121-135 only examines the one surviving claim, so nothing deletes the repoId from the earlier section. appendOrderedGroups emits imported-card, inbox and pending rows for every repoId in each group's repoIds (group-sections.ts:162-192), so both coordinator sections emit the same repo-keyed notice rows with identical React keys — duplicate cards and key collisions in the sidebar.

📋 Prompt for AI Agents

In src/renderer/src/components/sidebar/worktree-list/grouping/worktree-grouping.ts around lines 116-135, fix duplicate notice-row emission when a child repo is anchored by multiple coordinators. Change anchoredSectionKeyByRepoId (line ~89) from Map<string, string> to Map<string, Set<string>>: at line 118 add the section key to the repoId's set instead of overwriting. Then make the cleanup loop (lines 121-135) reconcile every claim per repo — deleting the repoId from each claiming group's repoIds when the repo has its own section — since the imported/inbox/pending row keys are repo-keyed without a section prefix and double membership means duplicate React keys.

Comment on lines +48 to +64
const edges: DelegatedWorktreeEdge[] = []
for (const placement of db.listDelegatedWorktreePlacements(MAX_DELEGATED_EDGES)) {
// No bare-id comparison here: ids collide across hosts, and a genuine
// self-reference is only decidable once both ends are host-qualified,
// which resolveDelegatedWorktreeNesting already does.
const parentWorktreeId = this.resolveCoordinatorWorktreeId(placement)
if (!parentWorktreeId) {
continue
}
edges.push({
parentWorktreeId,
childHostId: toRuntimeExecutionHostId(placement.environment_id),
childWorktreeId: placement.remote_worktree_id,
dispatchId: placement.dispatch_id
})
}
return { known: true, edges }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

500-placement cap evicts live edges over time

RuntimeDelegatedWorktreeEdgeProjection.build caps the placement query at MAX_DELEGATED_EDGES = 500 and still returns known: true (runtime-delegated-worktree-edge-projection.ts:48-64), so the sync result replaces the reader's prior edge set with the truncated list (orca-runtime-sync-window-graph.ts:328-330). Settled dispatches are included on purpose and federated_dispatches has no pruning path (federated-dispatch-store.ts:95-119), so the newest-first LIMIT 500 window is eventually filled with stale settled placements and the edges of still-live workers fall off the tail. Because this is published as a real answer, the affected delegated cards silently un-nest for readers.

📋 Prompt for AI Agents

In src/main/runtime/runtime-delegated-worktree-edge-projection.ts line 8 and src/main/runtime/orchestration/db/federation/federated-dispatch-store.ts lines 102-119, make the placement query retention-aware instead of a bare LIMIT 500 over all federated_dispatches history: settled dispatches are intentionally kept and the table has no pruning path, so the newest-first cap is eventually dominated by stale settled rows and silently evicts placements of still-live workers. Either join against worker_dispatches/dispatch status to restrict to live plus recently settled dispatches before applying the LIMIT, or signal truncation (e.g. return { known: false } when exactly MAX rows come back) so readers keep their prior edges; add a test that a live worker's edge survives when 500+ older settled dispatches exist.

Two delegated children of the same repo can anchor to coordinators in
different sections. The redirect was last-write-wins, so the earlier
coordinator kept the repo in its repoIds and emitted the imported-worktrees
card, the inbox row and the pending-creation rows a second time under the same
repo-keyed ids.

Track every section that claims a repo this way and leave exactly one holding
it: the repo's own section when it has one, otherwise the last coordinator to
anchor a child of it. The others release the repoId along with the redirect.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@luxor-code-review

luxor-code-review Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 4 medium

💬 Inline comments (3)

📍 Outside the diff (1)

  • 🟡 Web runtime path never receives delegated edges (web-runtime-api.ts:13) — The new delegatedWorktreeEdges/delegatedWorktreeEdgesUnavailable fields are only published on the desktop IPC reply from syncWindowGraph (src/main/runtime/orca-runtime-sync-window-graph.ts:328-330), but the web preload substitutes getRemoteRuntimeStatus() — a plain RuntimeStatus from the status.get RPC that carries neither field (src/renderer/src/web/preload-api/web-runtime-api.ts:13).

Reviewed commit: 96c76d5

@luxor-code-review luxor-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds delegated-worktree edge projection from the federated dispatch store, plumbing placements through the runtime graph sync into the sidebar's delegated nesting and rendering.

Comment on lines +71 to +80
const byHandle = placement.creator_handle
? this.deps.getWorktreeId(placement.creator_handle)
: null
if (byHandle) {
return byHandle
}
const handle = placement.creator_pane_key
? this.deps.getHandleForPaneKey(placement.creator_pane_key)
: null
return handle ? this.deps.getWorktreeId(handle) : null

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Pane-key fallback rebinds settled placements to wrong coordinator

The projection resolves the coordinator worktree by creator_handle first, then falls back to creator_pane_key → getHandleForPaneKey → getWorktreeId (src/main/runtime/runtime-delegated-worktree-edge-projection.ts:71-80). getTerminalHandleForPaneKey issues a handle for whatever terminal currently occupies that pane, and settled dispatches are retained forever, so after a restart — when the original handle no longer resolves — a placement whose coordinator terminal was closed or whose pane now hosts a different worktree's terminal is re-parented onto the pane's current occupant. The sidebar then nests the worker card under the wrong coordinator for as long as the stale placement row stays in the 500-row window.

📋 Prompt for AI Agents

In src/main/runtime/runtime-delegated-worktree-edge-projection.ts lines 67-81, tighten resolveCoordinatorWorktreeId: the creator_pane_key fallback must not bind a historical placement to the pane's current occupant. Either record and compare a terminal incarnation/pane-generation alongside creator_pane_key so a reminted handle for a different terminal is rejected, or drop placements whose creator_handle no longer resolves instead of falling back to the pane key. Settled placements are retained forever by listDelegatedWorktreePlacements, so the fallback can permanently re-parent an old worker under whichever coordinator terminal now occupies the reused pane after a restart.

Comment on lines +92 to +105
const delegatedNesting =
nestLineage && delegatedWorktreeEdges.length > 0
? resolveDelegatedWorktreeNesting({
worktrees,
edges: delegatedWorktreeEdges,
// Not defaultHostId: the edges arrive on this window's own graph sync, so their
// coordinator is always a local row, while the focused host follows the host filter.
homeHostId: LOCAL_EXECUTION_HOST_ID,
getLineageParentIdentity: (worktree) => {
const info = getLineageRenderInfo(worktree, lineageById, worktreeMap, cyclicLineageIds)
return info.state === 'valid' ? getWorktreeHostIdentity(info.parent) : undefined
}
})
: undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Delegated child of pinned coordinator renders unnested

A delegated worker whose coordinator worktree is pinned is anchored by sectionAnchorByChildIdentity into the coordinator's repo section (src/renderer/src/components/sidebar/worktree-list/grouping/build-rows.ts:92-105), but under the default pinned policy the coordinator row itself lives in the Pinned section, so visibleByIdentity in appendWorktreeRows does not contain the parent and the delegated attach is dropped — the child renders as a depth-0 root. Git-lineage children of the same pinned coordinator instead follow it into the Pinned section, so the two sibling kinds of one coordinator render in different places with different nesting.

📋 Prompt for AI Agents

In src/renderer/src/components/sidebar/worktree-list/grouping/build-rows.ts around lines 92-107, delegated nesting does not account for pinned coordinators: resolveDelegatedWorktreeNesting anchors a delegated child to its coordinator even when the coordinator is pinned, so buildOrderedGroups places the child in the coordinator's repo section while the coordinator row is in the Pinned section, and appendWorktreeRows (row-builders.ts:165) cannot find the parent in that section's visibleByIdentity — the child renders as an unnested root. Fix by skipping edges whose resolved parent is in pinnedSectionWorktrees when building sectionAnchorByChildIdentity, or by passing the delegated parent map into the pinned-section emission so the child nests there, matching how git-lineage children of pinned worktrees are handled. Add a test covering a pinned coordinator with a delegated remote worker.

Comment on lines +102 to +119
export function listDelegatedWorktreePlacements(
this: OrchestrationDb,
limit: number
): DelegatedWorktreePlacementRow[] {
const rows = this.db
.prepare(
`SELECT fd.dispatch_id, fd.environment_id, fd.remote_worktree_id,
dc.creator_handle, dc.creator_pane_key
FROM federated_dispatches fd
INNER JOIN dispatch_contexts dc ON dc.id = fd.dispatch_id
WHERE fd.remote_worktree_id IS NOT NULL
ORDER BY fd.rowid DESC
LIMIT ?`
)
.all(limit)
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the SELECT list names exactly these five columns.
return rows as DelegatedWorktreePlacementRow[]
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 performance · medium

Per-graph-sync SQL scan of unbounded dispatch table

Every syncWindowGraph call now runs RuntimeDelegatedWorktreeEdgeProjection.build() (src/main/runtime/orca-runtime-sync-window-graph.ts:318), which executes listDelegatedWorktreePlacements synchronously on the main process (src/main/runtime/orchestration/db/federation/federated-dispatch-store.ts:102-119). Graph syncs are coalesced at 16ms and fire on every terminal title/status/store change, so the query sits on a hot per-frame path; it re-compiles the prepared statement on every call, filters remote_worktree_id IS NOT NULL with no index on that column, and scans an append-only table whose settled dispatches are deliberately retained forever. Main-process CPU cost per sync grows monotonically with accumulated dispatch history.

📋 Prompt for AI Agents

Two changes: (1) in src/main/runtime/orchestration/db/schema/create-graph-tables-sql.ts add a partial index CREATE INDEX IF NOT EXISTS idx_federated_dispatches_remote_worktree ON federated_dispatches(remote_worktree_id) WHERE remote_worktree_id IS NOT NULL so the placement query in federated-dispatch-store.ts:102-119 stops scanning the whole append-only table; also hoist the db.prepare call so the statement is compiled once. (2) In src/main/runtime/runtime-delegated-worktree-edge-projection.ts cache the built edges and invalidate on a dispatch-store mutation hook (or throttle rebuilds) instead of querying synchronously on every syncWindowGraph — syncs are coalesced at 16ms in src/renderer/src/runtime/sync-runtime-graph/graph-state.ts and fire on every terminal status change.

@kiwidream
kiwidream merged commit e14cded into main Sep 23, 2026
2 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96c76d58d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

addRepoIdToGroup(group, w.repoId)
addRepoIdToGroup(group, anchor.repoId)
if (anchor !== w) {
addRepoIdToGroup(group, w.repoId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the coordinator repo as the section anchor

When the delegated worker is the only visible worktree from its repo and that remote repo precedes the coordinator in repoOrder, adding the child's repo ID to group.repoIds lets getManualOrderAnchorRepo replace group.repo with the child's repo. The section still has the coordinator's key and label, but it is placed under the child's project group and its header actions—settings, create workspace, and remove project—operate on the remote child repo. Track notice-row ownership separately from the repo IDs eligible to become the section's anchor.

Useful? React with 👍 / 👎.

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