Skip to content

fix(cli): report worktree-listing host coverage and stop the row cap starving remote hosts (#18104) - #18417

Merged
nwparker merged 1 commit into
mainfrom
fix/worktree-listing-host-scope
Sep 3, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/worktree-listing-host-scope

Conversation

@nwparker

@nwparker nwparker commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​557 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​554
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​338 $\color{#cf222e}{\Huge{\mathbf{−}}}$​62 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​276

Fixes #18104. Also fixes the hostScope.omittedHostIds data-quality defect
found alongside it.

1. worktree list returned zero of 24 SSH worktrees

totalCount: 521  truncated: True  returned: 200
returned 200 -> {'local': 200}
all 521      -> {'local': 497, 'ssh:…': 24}

Rows are resolved repo by repo (computeResolvedWorktrees maps over
store.getRepos() and flattens), so every SSH repo's rows land contiguously at
the 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 521 and JSON carries totalCount /
truncated. What is missing is that the omission is categorically every
remote host
— there was no host column and no hostScope, so nothing
distinguished "200 of 521" from "one whole host is absent".
docs/reference/ssh-execution-boundary.md: a listing that does not name its
scope reads as absolute.

Fix — adopt the mechanism terminal list already has

  • RuntimeTerminalListHostScope is now an alias of a shared
    RuntimeListingHostScope (src/shared/runtime-listing-host-scope.ts), also
    carried by worktree.list and worktree.ps. Optional field, so old hosts and
    old clients are unaffected.
  • src/shared/host-balanced-listing-page.ts round-robins the row cap across
    hosts. 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 ps text output gains a host= column and the
    same trailing scope: line terminal list prints.
  • --repo-scoped listings do not report configured hosts as omitted; the caller
    scoped it themselves.

No --host filter was added (it was optional in the report) — the host column
plus the scope line covers the reported need without a new selector axis.

2. omittedHostIds advertised unqueryable stale hosts

terminal list named 9 omitted runtime hosts; only 3 were paired environments.
The other 6 hard-error when queried, so an agent looping over omittedHostIds
to complete a partial listing fails 6 of 9 — and hostScope is the documented
mechanism 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.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:

scope: local — not covered: runtime:paired (--environment m4air), runtime:retired (not selectable from this machine)
"omittedHostSelectors": [
  { "hostId": "runtime:paired",  "selector": "--environment m4air" },
  { "hostId": "runtime:retired", "selector": null }
]

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 live or
exited on this path. The SSH round trip is only paid when an ssh: host was
actually 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 exact
    orca 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 a
    real OrcaRuntimeService with a local and an SSH repo.
  • src/cli/index-omitted-host-scope-selectors.test.ts — a stale runtime: host
    in 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 selectHostBalancedPage unit tests plus the
two assertions that behavior is unchanged for uncapped listings and ordering).

  • pnpm tc clean
  • pnpm test src/cli — 110 files passing
  • pnpm run check:code-quality:changed — 0 new findings across 21 files
  • No max-lines disables or bumps: src/cli/specs/core.ts and
    runtime-managed-worktree-queries.ts both stayed under 300 by extracting
    worktree-listing-scope-notes.ts and buildWorktreeListingPage respectively
    (rule verified firing with a positive control).

@coderabbitai

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 c50ba

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 explanat… Add the missing template sections. For this non-visual behavior change, include N/A with a brief reason under Visual Proof. Complete or explicitly address the required testing, review, compatibility, and checklist items.
Out of Scope Changes check ⚠️ Warning The worktree listing changes are in scope for issue #18104. The additional CLI feature that resolves and attaches selectable selectors for omitted hosts in terminal list is not requested by the linked… Move the terminal-list omitted-host selector annotation into a separate PR with an appropriate linked issue, or provide an explicit linked issue and scope justification for including it here.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 22 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the two primary changes: host-coverage reporting and prevention of remote-host starvation in worktree listings.
Linked Issues check ✅ Passed The PR satisfies issue #18104. It adds hostScope reporting to worktree list and ps, adds host identifiers to text output, uses host-balanced pagination, preserves remote rows under the cap, and avoids…
Full details: Description check

Explanation

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 check

Explanation

The PR satisfies issue #18104. It adds hostScope reporting to worktree list and ps, adds host identifiers to text output, uses host-balanced pagination, preserves remote rows under the cap, and avoids marking hosts omitted for repository-scoped listings.

Full details: Out of Scope Changes check

Explanation

The worktree listing changes are in scope for issue #18104. The additional CLI feature that resolves and attaches selectable selectors for omitted hosts in terminal list is not requested by the linked issue and changes behavior outside worktree listings.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker force-pushed the fix/worktree-listing-host-scope branch from 02c4db0 to f24b4b2 Compare September 3, 2026 10:42

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 — selectHostBalancedPage round-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 / buildWorktreeListingHostScope compute a hostScope for worktree list and worktree ps, naming every host the page covers plus the ones it does not (including a configured host that contributed no rows).
  • Shared scope type — RuntimeTerminalListHostScope becomes an alias of the new RuntimeListingHostScope; RuntimeWorktreeListResult / RuntimeWorktreePsResult gain an optional hostScope.
  • CLI omitted-host annotation — resolveOmittedHostScopeSelectors maps each omittedHostIds entry to the flag that reaches it (--environment for runtime, --host for local/ssh), rendered in a trailing scope: line and a new host= column.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread src/cli/omitted-host-scope-selectors.ts Outdated
Comment on lines +77 to +82
if (kind === 'local') {
return '--host local'
}
if (kind === 'ssh' && parsed?.kind === 'ssh') {
return findSshTargetByName(sshTargets, parsed.targetId) ? `--host ssh:${parsed.targetId}` : null
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

--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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No new issues in this delta. The follow-up commit is a mechanical refactor of resolveOmittedHostScopeSelectors; behavior is unchanged, and the --host selector concern from the prior review remains open (not re-flagged here).

Reviewed changes (since prior pullfrog review)

  • Parse into ParsedExecutionHost — resolveOmittedHostScopeSelectors now carries the full parsed host instead of just kind, so resolveSelector reads host.targetId / host.environmentId directly rather than re-parsing the id.
  • Extract listPairedEnvironments — the dynamic runtime/environments + runtime-client import is hoisted into a helper, invoked only when a runtime host is actually omitted.
  • Drop the empty-input early return — dead code: annotateOmittedHostScope already bails on an empty omittedHostIds, and mapping an empty array still yields [].

Pullfrog  | Fix it ➔ | View workflow run | Using 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.
@nwparker
nwparker force-pushed the fix/worktree-listing-host-scope branch from f24b4b2 to c50bab7 Compare September 3, 2026 11:02
@nwparker

nwparker commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Full-suite verification: pnpm test src → 7521 files, 69,924 tests. One real assertion needed updating (orca-runtime-tests/mobile-creation-and-orchestration-part-04.spec.ts asserts getWorktreePs() by exact equality, so it now pins hostScope: { hostIds: ['local'], omittedHostIds: [] }) — pushed. The other 6 reported failures were timing flakes from a saturated machine and all pass in isolation: git-handler-remote-sync, ssh-remote-commands, terminal-output-frame-chunks-equivalence, AgentMapWorkspaceContextMenu, ai-vault-session-worktree-map.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/cli/omitted-host-scope-selectors.ts (1)

97-113: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Localize 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 the host= label with a localized output template.
  • src/cli/workspace-format.ts#L184-L184: replace the host= 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3eec77c and c50bab7.

📒 Files selected for processing (22)
  • src/cli/handlers/terminal.ts
  • src/cli/handlers/worktree.ts
  • src/cli/index-omitted-host-scope-selectors.test.ts
  • src/cli/index-terminal-list-host-scope.test.ts
  • src/cli/omitted-host-scope-selectors.ts
  • src/cli/specs/core.ts
  • src/cli/specs/worktree-listing-scope-notes.ts
  • src/cli/terminal-format.ts
  • src/cli/workspace-format.ts
  • src/main/runtime/orca-runtime-get-worktree-ps.ts
  • src/main/runtime/orca-runtime-stop-requested-pty-ids.ts
  • src/main/runtime/orca-runtime-tests/mobile-creation-and-orchestration-part-04.spec.ts
  • src/main/runtime/runtime-managed-worktree-metadata-sweep.test.ts
  • src/main/runtime/runtime-managed-worktree-queries.test.ts
  • src/main/runtime/runtime-managed-worktree-queries.ts
  • src/main/runtime/worktree-list-host-scope.test.ts
  • src/main/runtime/worktree-listing-host-scope.ts
  • src/main/runtime/worktree-ps-host-scope.test.ts
  • src/shared/host-balanced-listing-page.ts
  • src/shared/runtime-listing-host-scope.ts
  • src/shared/runtime-terminal-contracts.ts
  • src/shared/runtime-worktree-contracts.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit 95eed52 into main Sep 3, 2026
32 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… 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.
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.

orca worktree list silently omits all SSH worktrees at the default limit

1 participant