Repository navigation
fix(sidebar): nest a delegated remote worker under its coordinator - #4
Conversation
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>
|
Review complete. 🟡 4 medium 💬 Inline comments (3)
📍 Outside the diff (1)
🧹 Nitpicks (1) — 🟢 1 low
Reviewed commit: 2fc332e |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| ? resolveDelegatedWorktreeNesting({ | ||
| worktrees, | ||
| edges: delegatedWorktreeEdges, | ||
| homeHostId: defaultHostId, |
There was a problem hiding this comment.
🟡 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.
| @@ -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) | |||
There was a problem hiding this comment.
🟡 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.
| build(): DelegatedWorktreeEdge[] | undefined { | ||
| const db = this.deps.getDb() | ||
| if (!db?.listDelegatedWorktreePlacements) { | ||
| return undefined | ||
| } |
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
💡 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".
| if (!parentWorktreeId || parentWorktreeId === placement.remote_worktree_id) { | ||
| continue |
There was a problem hiding this comment.
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 👍 / 👎.
| ? resolveDelegatedWorktreeNesting({ | ||
| worktrees, | ||
| edges: delegatedWorktreeEdges, | ||
| homeHostId: defaultHostId, |
There was a problem hiding this comment.
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 👍 / 👎.
| childHostId: ExecutionHostId | ||
| childWorktreeId: string | ||
| dispatchId: string |
There was a problem hiding this comment.
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 👍 / 👎.
| const delegatedNesting = | ||
| nestLineage && delegatedWorktreeEdges.length > 0 | ||
| ? resolveDelegatedWorktreeNesting({ |
There was a problem hiding this comment.
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 👍 / 👎.
| cyclicLineageIds, | ||
| delegatedParentIdentityByChildIdentity: delegatedNesting?.parentIdentityByChildIdentity |
There was a problem hiding this comment.
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>
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
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 |
There was a problem hiding this comment.
💡 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, |
There was a problem hiding this comment.
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 ?` |
There was a problem hiding this comment.
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>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
Reviewed commit: 0537cf2 |
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 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.
A newer Tenki review found issues on this pull request.
There was a problem hiding this comment.
💡 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() |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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>
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
Reviewed commit: 4b5d038 |
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 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.
| 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 } |
There was a problem hiding this comment.
🟡 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>
|
Review complete. 🟡 4 medium 💬 Inline comments (3)
📍 Outside the diff (1)
Reviewed commit: 96c76d5 |
| 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 |
There was a problem hiding this comment.
🟡 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.
| 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 |
There was a problem hiding this comment.
🟡 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.
| 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[] | ||
| } |
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
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.After:
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:
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.tsasserts 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 testoversrc/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
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.