Repository navigation
fix(cli): report worktree-listing host coverage and stop the row cap starving remote hosts (#18104) - #18417
Conversation
📝 WalkthroughWalkthroughThe change adds shared host-scope contracts and host-balanced pagination for worktree listings. Runtime worktree results now report covered and omitted hosts. CLI handlers annotate omitted hosts with environment or host selectors when available. Terminal and worktree formatters render scope details, host identifiers, and unverifiable scope states. Worktree command notes document scope behavior. Tests cover runtime pagination, host reporting, selector resolution, JSON output, and human-readable output. Merge Risk: 🟡 Moderate · up to Worktree and terminal listings now report host coverage and suggest selectors for omitted hosts. The new output needs localization, and the suggested local or SSH host flags need confirmation that they can be used with these listing commands before merge. 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
Full details: Description checkExplanation The description explains the problem, implementation, linked issue, and verification in detail. However, it omits several required template sections, including Visual Proof or an explicit N/A explanation, Review, Notes, the Agent skill boundary checkbox, and the Checklist. Full details: Linked Issues checkExplanation The PR satisfies issue Full details: Out of Scope Changes checkExplanation The worktree listing changes are in scope for issue
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
02c4db0 to
f24b4b2
Compare
There was a problem hiding this comment.
Important
The --host selectors this PR attaches to omittedHostIds are not valid flags on the three commands that print them (worktree list, worktree ps, terminal list). Emitting --host local / --host ssh:<id> re-introduces the exact failure mode the annotation exists to fix: an agent that follows the hint hard-errors with Unknown flag --host.
Reviewed changes
- Host-balanced row cap —
selectHostBalancedPageround-robins the cap across execution hosts so a host whose rows sort last is no longer starved out of the page; survivors keep original relative order (page stays a subsequence). - Worktree listing host scope —
buildWorktreeListingPage/buildWorktreeListingHostScopecompute ahostScopeforworktree listandworktree ps, naming every host the page covers plus the ones it does not (including a configured host that contributed no rows). - Shared scope type —
RuntimeTerminalListHostScopebecomes an alias of the newRuntimeListingHostScope;RuntimeWorktreeListResult/RuntimeWorktreePsResultgain an optionalhostScope. - CLI omitted-host annotation —
resolveOmittedHostScopeSelectorsmaps eachomittedHostIdsentry to the flag that reaches it (--environmentfor runtime,--hostfor local/ssh), rendered in a trailingscope:line and a newhost=column.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| if (kind === 'local') { | ||
| return '--host local' | ||
| } | ||
| if (kind === 'ssh' && parsed?.kind === 'ssh') { | ||
| return findSshTargetByName(sshTargets, parsed.targetId) ? `--host ssh:${parsed.targetId}` : null | ||
| } |
There was a problem hiding this comment.
--host is not accepted by any of the three commands that surface this annotation. worktree list declares allowedFlags: ['repo', 'limit'], worktree ps ['limit'], and terminal list ['worktree', 'limit', 'include-visual-layouts']; --host is not a global flag (GLOBAL_FLAGS is help/json/pairing-code/environment), so validateCommandAndFlags rejects it with Unknown flag --host. Only the --environment branch is actually valid on these commands. An agent that re-issues the same listing with --host ssh:box-1 (the exact hint this field exists to give) hard-errors.
Technical details
# Title
`--host`-prefixed omitted-host selectors are invalid on the listing commands
## Affected sites
- `src/cli/omitted-host-scope-selectors.ts:77-82` — `resolveSelector` returns `--host local` and `--host ssh:<targetId>` for the `local` and `ssh` kinds.
- `src/cli/specs/core.ts` — `worktree list` / `worktree ps` / `terminal list` `allowedFlags` do not include `host`; `--host` is not in `GLOBAL_FLAGS` (`src/shared/cli-argument-boundary.ts`).
## Required outcome
- A selector must name a flag the annotated command actually accepts. For `local` and `ssh` hosts there is no `--host` filter on `worktree list` / `worktree ps` / `terminal list`, so the selector must be `null` (not selectable via a listing flag) or the annotation must point at a flag that genuinely reaches the host (only `--environment` does today).
## Open questions for the human
- Is the intent that the selector be re-used with a *different* command that does accept `--host` (e.g. `worktree create`, `project list`)? If so, the annotation's inline scope-line rendering (`ssh:box-1 (--host ssh:box-1)`) still reads as a re-run of the same listing and needs a disambiguating label.There was a problem hiding this comment.
ℹ️ No new issues in this delta. The follow-up commit is a mechanical refactor of
resolveOmittedHostScopeSelectors; behavior is unchanged, and the--hostselector concern from the prior review remains open (not re-flagged here).
Reviewed changes (since prior pullfrog review)
- Parse into
ParsedExecutionHost—resolveOmittedHostScopeSelectorsnow carries the full parsed host instead of justkind, soresolveSelectorreadshost.targetId/host.environmentIddirectly rather than re-parsing the id. - Extract
listPairedEnvironments— the dynamicruntime/environments+runtime-clientimport is hoisted into a helper, invoked only when aruntimehost is actually omitted. - Drop the empty-input early return — dead code:
annotateOmittedHostScopealready bails on an emptyomittedHostIds, and mapping an empty array still yields[].
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
… cap starving remote ones `orca worktree list` returned zero of 24 SSH worktrees at the default limit (#18104). Rows are resolved repo by repo, so every SSH repo's rows land contiguously at the end of the fleet order — the 24 remote rows sat at indices 496-520 of 521 and a plain `slice(0, 200)` never reached them. The omission was not fully silent: text output printed `truncated: showing 200 of 521` and JSON carried `totalCount` / `truncated`. What was missing is that the omission was *categorically every remote host* — no host column, no `hostScope`, nothing to distinguish "200 of 521" from "one host is entirely absent". Per docs/reference/ssh-execution-boundary.md, a listing that does not name its scope reads as absolute. Adopt the mechanism `terminal list` already has rather than inventing a second one: - `RuntimeTerminalListHostScope` becomes an alias of a shared `RuntimeListingHostScope`, now also carried (optional, so old hosts are unaffected) on `worktree.list` and `worktree.ps` results. - `src/shared/host-balanced-listing-page.ts` round-robins the row cap across hosts and returns the survivors in the caller's original relative order, so the page stays a subsequence of the unbounded listing and nothing downstream re-sorts. An uncapped listing is returned unchanged. - `worktree list` / `worktree ps` text output gains a `host=` column and the same trailing `scope:` line `terminal list` prints. Third defect, same mechanism: `hostScope.omittedHostIds` is built from the runtime's own bookkeeping, so it names `runtime:` ids for servers that are no longer paired — 6 of 9 in the recorded QA run hard-error when queried. Since `hostScope` is *the* documented way to complete a partial listing, that makes the mechanism unreliable for its intended use. Annotate rather than filter. Dropping an id would shrink what the listing admits it did not cover, and the boundary doc requires a listing to name its gaps — the gap is real whether or not this machine can name the host that owns it. `src/cli/omitted-host-scope-selectors.ts` resolves each omitted id against this machine's pairing store and the runtime's SSH-target registry and attaches the exact flag that reaches it, or `null` marked "not selectable from this machine". This is a client-side annotation: nothing new goes over the wire, it answers "can I select it" and never "is it up", and the SSH round trip is only paid when an `ssh:` host was actually omitted. No `--host` filter was added; the host column plus scope line covers the reported need without a new selector axis.
f24b4b2 to
c50bab7
Compare
|
Full-suite verification: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/cli/omitted-host-scope-selectors.ts (1)
97-113: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftLocalize the new listing output.
The new scope messages and
host=labels are user-facing text. Use intent-named localization IDs. Use named placeholders for covered hosts, omitted hosts, and counts.
src/cli/omitted-host-scope-selectors.ts#L97-L113: replace scope messages with localized templates.src/cli/workspace-format.ts#L142-L142: replace thehost=label with a localized output template.src/cli/workspace-format.ts#L184-L184: replace thehost=label with the same localized output template.Based on learnings: new user-facing strings must use intent-named localization IDs with named interpolation placeholders.
Source: Learnings
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: a3b82229-ea11-4489-92e3-6c533a670c95
📒 Files selected for processing (22)
src/cli/handlers/terminal.tssrc/cli/handlers/worktree.tssrc/cli/index-omitted-host-scope-selectors.test.tssrc/cli/index-terminal-list-host-scope.test.tssrc/cli/omitted-host-scope-selectors.tssrc/cli/specs/core.tssrc/cli/specs/worktree-listing-scope-notes.tssrc/cli/terminal-format.tssrc/cli/workspace-format.tssrc/main/runtime/orca-runtime-get-worktree-ps.tssrc/main/runtime/orca-runtime-stop-requested-pty-ids.tssrc/main/runtime/orca-runtime-tests/mobile-creation-and-orchestration-part-04.spec.tssrc/main/runtime/runtime-managed-worktree-metadata-sweep.test.tssrc/main/runtime/runtime-managed-worktree-queries.test.tssrc/main/runtime/runtime-managed-worktree-queries.tssrc/main/runtime/worktree-list-host-scope.test.tssrc/main/runtime/worktree-listing-host-scope.tssrc/main/runtime/worktree-ps-host-scope.test.tssrc/shared/host-balanced-listing-page.tssrc/shared/runtime-listing-host-scope.tssrc/shared/runtime-terminal-contracts.tssrc/shared/runtime-worktree-contracts.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
… cap starving remote ones (stablyai#18417) `orca worktree list` returned zero of 24 SSH worktrees at the default limit (stablyai#18104). Rows are resolved repo by repo, so every SSH repo's rows land contiguously at the end of the fleet order — the 24 remote rows sat at indices 496-520 of 521 and a plain `slice(0, 200)` never reached them. The omission was not fully silent: text output printed `truncated: showing 200 of 521` and JSON carried `totalCount` / `truncated`. What was missing is that the omission was *categorically every remote host* — no host column, no `hostScope`, nothing to distinguish "200 of 521" from "one host is entirely absent". Per docs/reference/ssh-execution-boundary.md, a listing that does not name its scope reads as absolute. Adopt the mechanism `terminal list` already has rather than inventing a second one: - `RuntimeTerminalListHostScope` becomes an alias of a shared `RuntimeListingHostScope`, now also carried (optional, so old hosts are unaffected) on `worktree.list` and `worktree.ps` results. - `src/shared/host-balanced-listing-page.ts` round-robins the row cap across hosts and returns the survivors in the caller's original relative order, so the page stays a subsequence of the unbounded listing and nothing downstream re-sorts. An uncapped listing is returned unchanged. - `worktree list` / `worktree ps` text output gains a `host=` column and the same trailing `scope:` line `terminal list` prints. Third defect, same mechanism: `hostScope.omittedHostIds` is built from the runtime's own bookkeeping, so it names `runtime:` ids for servers that are no longer paired — 6 of 9 in the recorded QA run hard-error when queried. Since `hostScope` is *the* documented way to complete a partial listing, that makes the mechanism unreliable for its intended use. Annotate rather than filter. Dropping an id would shrink what the listing admits it did not cover, and the boundary doc requires a listing to name its gaps — the gap is real whether or not this machine can name the host that owns it. `src/cli/omitted-host-scope-selectors.ts` resolves each omitted id against this machine's pairing store and the runtime's SSH-target registry and attaches the exact flag that reaches it, or `null` marked "not selectable from this machine". This is a client-side annotation: nothing new goes over the wire, it answers "can I select it" and never "is it up", and the SSH round trip is only paid when an `ssh:` host was actually omitted. No `--host` filter was added; the host column plus scope line covers the reported need without a new selector axis.

Fixes #18104. Also fixes the
hostScope.omittedHostIdsdata-quality defectfound alongside it.
1.
worktree listreturned zero of 24 SSH worktreesRows are resolved repo by repo (
computeResolvedWorktreesmaps overstore.getRepos()and flattens), so every SSH repo's rows land contiguously atthe end of the fleet order. The 24 remote rows sat at indices 496-520 and
worktrees.slice(0, 200)never reached them.Correction to the issue as filed: it is not fully silent. Text output
prints
truncated: showing 200 of 521and JSON carriestotalCount/truncated. What is missing is that the omission is categorically everyremote host — there was no host column and no
hostScope, so nothingdistinguished "200 of 521" from "one whole host is absent".
docs/reference/ssh-execution-boundary.md: a listing that does not name itsscope reads as absolute.
Fix — adopt the mechanism
terminal listalready hasRuntimeTerminalListHostScopeis now an alias of a sharedRuntimeListingHostScope(src/shared/runtime-listing-host-scope.ts), alsocarried by
worktree.listandworktree.ps. Optional field, so old hosts andold clients are unaffected.
src/shared/host-balanced-listing-page.tsround-robins the row cap acrosshosts. Survivors keep the caller's original relative order, so the page is a
subsequence of the unbounded listing — nothing downstream re-sorts, and an
uncapped listing is returned unchanged.
worktree list/worktree pstext output gains ahost=column and thesame trailing
scope:lineterminal listprints.--repo-scoped listings do not report configured hosts as omitted; the callerscoped it themselves.
No
--hostfilter was added (it was optional in the report) — the host columnplus the scope line covers the reported need without a new selector axis.
2.
omittedHostIdsadvertised unqueryable stale hoststerminal listnamed 9 omitted runtime hosts; only 3 were paired environments.The other 6 hard-error when queried, so an agent looping over
omittedHostIdsto complete a partial listing fails 6 of 9 — and
hostScopeis the documentedmechanism for exactly that.
Chose to annotate, not filter. Dropping an id would shrink what the listing
admits it did not cover, and the boundary doc requires a listing to name its
gaps: the gap is real whether or not this machine can name the host that owns
it. Filtering would make the listing look more complete than it is.
src/cli/omitted-host-scope-selectors.tsresolves each omitted id against thismachine's pairing store and the runtime's SSH-target registry, and attaches the
exact flag that reaches it:
This is a client-side annotation — nothing new goes over the wire. It answers
"can I select this host", never "is it up", so no host is claimed
liveorexitedon this path. The SSH round trip is only paid when anssh:host wasactually omitted; a listing with no omitted hosts costs nothing extra
(asserted in test).
Verification
src/main/runtime/worktree-list-host-scope.test.ts— replays the exactorca worktree list silently omits all SSH worktrees at the default limit #18104 shape (497 local + 24 SSH, 200-row cap) and asserts all 24 remote rows
survive, the page stays a subsequence, an uncapped listing is byte-identical,
and a configured host contributing no rows is named as omitted.
src/main/runtime/worktree-ps-host-scope.test.ts— same starvation through areal
OrcaRuntimeServicewith a local and an SSH repo.src/cli/index-omitted-host-scope-selectors.test.ts— a staleruntime:hostin
omittedHostIds, JSON and human output, the no-extra-round-trip guarantee,and that no id is ever filtered out.
Failed-first: 10 of 17 fail with the call sites reverted to
origin/main(the 7 that pass both sides are the
selectHostBalancedPageunit tests plus thetwo assertions that behavior is unchanged for uncapped listings and ordering).
pnpm tccleanpnpm test src/cli— 110 files passingpnpm run check:code-quality:changed— 0 new findings across 21 filesmax-linesdisables or bumps:src/cli/specs/core.tsandruntime-managed-worktree-queries.tsboth stayed under 300 by extractingworktree-listing-scope-notes.tsandbuildWorktreeListingPagerespectively(rule verified firing with a positive control).