Skip to content

feat(cli): accept pty:<ptyId> as a terminal selector - #13219

Open
bbingz wants to merge 9 commits into
stablyai:mainfrom
bbingz:fix/13206-terminal-pty-selector
Open

bbingz wants to merge 9 commits into
stablyai:mainfrom
bbingz:fix/13206-terminal-pty-selector

Conversation

@bbingz

@bbingz bbingz commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Canonical terminal commands accept --terminal pty:<ptyId> and resolve the stable PTY ID to its current live handle. Ordinary handles remain pass-through and orchestration terminal flags retain their existing handle-only contract. Fixes #13206.

An optional bounded terminal.list PTY filter runs before pagination. Older hosts can strip the field and return a capped 200-entry page for client matching; a miss on a truncated response reports recovery guidance. Fresh liveness is preferred, with one cached-state retry when unavailable or when the target SSH/runtime host is explicitly omitted. Visual layouts are omitted. Resolution uses target runtime metadata and has no client-cwd or Git-worktree dependency.

The existing RPC listing test seeds a second terminal to prove filtering precedes limit and asserts both entries in order. Existing assertions are preserved. New tests cover disconnected records, old-host responses, unavailable/omitted liveness and the 512-character boundary.

Validation on current head (2026-09-09):

  • Cursor exact-commit PASS; Codex independently inspected the production diff and raw check evidence.
  • Focused selector/help/RPC: 45 tests passed. CLI and Node non-composite typechecks, changed-file oxlint/oxfmt, and diff checks passed.
  • Full Vitest, excluding Docker: 8,241 files / 76,605 tests passed; 11 files / 28 tests failed; 61 files / 391 tests skipped. All 28 failing test names match prior pristine-main reproduction with the same dependencies; no candidate-only failing test name.
  • The full run also caught one ECONNRESET while the unchanged remote-browser SOCKS test ran. Isolated candidate and pristine-main reruns each passed all 7 tests without that error. The full suite was not rerun afterward and is not claimed green.
  • Full build and live Windows/WSL/SSH manual checks were not run. Default composite typecheck retains the known baseline TS2883; only the explicit non-composite checks above are claimed.
  • The root flag-help function was extracted unchanged to satisfy max-lines; terminal-only help remains separate so orchestration flags keep their existing handle-only description.

Reviewed commit: 4713db35de7ee61ac8673af32c47eae601bd83d0; base: bba68b1bddf1276c8bd27ad4ca41efcbd4260321. No rendered UI change.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 9be87a75-93db-4ec5-9de6-3bec2a17ba9e

📥 Commits

Reviewing files that changed from the base of the PR and between 0176f3a5f0a88712381cf1991f64684fa4aa0984 and 5843af1.

📒 Files selected for processing (8)
  • src/cli/flag-help-text.ts
  • src/cli/help.ts
  • src/cli/root-help-text-secondary.ts
  • src/cli/selectors-pty-terminal.test.ts
  • src/cli/specs/core.ts
  • src/cli/specs/terminal-read.ts
  • src/cli/terminal-selector.ts
  • src/shared/rpc-contract/terminal-unary-params.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/flag-help-text.ts

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


📝 Walkthrough

Walkthrough

The runtime terminal-list contract now accepts PTY identifiers and filters results before applying limits. The CLI resolves pty:<ptyId> selectors to connected terminal handles, with fresh-liveness and cached fallbacks. Terminal command specifications and help text document PTY selectors, including the extracted terminal read specification. Tests cover runtime filtering, selector resolution, fallback behavior, errors, and help consistency.

Priority: ➖ Normal

Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 6 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: accepting pty: as a terminal selector.
Description check ✅ Passed The description explains the user-facing change, resolution behavior, compatibility handling, linked issue, testing results, known limitations, and absence of rendered UI changes. It does not reproduc…
Linked Issues check ✅ Passed The PR satisfies the coding requirements in #13206. Canonical terminal commands accept pty:<ptyId> selectors and resolve them to the current live handle. Runtime filtering passes ptyId through the…
Out of Scope Changes check ✅ Passed The changes stay within #13206. Runtime protocol changes enable PTY lookup. CLI selector resolution, command specifications, help text, and focused tests implement or document stable terminal selectio…
  • Fix all pre-merge checks with AI

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.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cd539c4e-5638-451a-9684-49caf41a541f

📥 Commits

Reviewing files that changed from the base of the PR and between 6da7b8e and d6411d36418202026da932a75f4c716ebf7c1bb6.

📒 Files selected for processing (4)
  • src/cli/help.ts
  • src/cli/selectors-pty-terminal.test.ts
  • src/cli/selectors.ts
  • src/cli/specs/core.ts

Comment thread src/cli/specs/core.ts Resolved

@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/selectors-pty-terminal.test.ts (1)

53-65: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the actionable truncation details.

The current matcher accepts any message that contains truncated. A regression can remove the returned-count and total-count details while this test still passes. Assert the diagnostic context that tells users why the PTY ID may be outside the result page.

Proposed test update
     await expect(resolveTerminalSelector('pty:beyond-page', client)).rejects.toMatchObject({
       code: 'terminal_not_found',
-      message: expect.stringMatching(/truncated/i)
+      message: expect.stringMatching(
+        /ptyId beyond-page in the first 1 of 900 terminals \(list truncated\)/i
+      )
     })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c88cd68-2d6f-48a3-a4f7-a70bf7d42e62

📥 Commits

Reviewing files that changed from the base of the PR and between d6411d36418202026da932a75f4c716ebf7c1bb6 and 1f76ccb2f1db6145a73283fe89a9a7304a17fb91.

📒 Files selected for processing (2)
  • src/cli/selectors-pty-terminal.test.ts
  • src/cli/selectors.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/selectors.ts

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f741de9a-9ff8-4c09-8541-3a03c7d416e8

📥 Commits

Reviewing files that changed from the base of the PR and between 1f76ccb2f1db6145a73283fe89a9a7304a17fb91 and 21bd788ac604b74f493f687d27c2a73717f754a8.

📒 Files selected for processing (3)
  • src/cli/handlers/terminal.test.ts
  • src/cli/help.ts
  • src/cli/specs/core.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/help.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review.

Comment thread src/cli/handlers/terminal.test.ts Resolved
Comment thread src/cli/handlers/terminal.test.ts Resolved
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@bbingz

bbingz commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed onto main@9e3e583a with the transport-safe ptyId filter and stale/disconnected guard. Local verification passed: focused 27/27, CLI 807/807, cross-version wire 5/5, full pnpm test 53,671/53,671, typecheck, lint, and build. Independent final review: APPROVED with no confirmed findings. Please approve and run the workflows for head 61b578bf2eac6f664967c74a34b942a94145f5dd.

@bbingz

bbingz commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

1 similar comment
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@bbingz

bbingz commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Full PR Checks run for this exact head, green.

8190c7205e — https://github.com/bbingz/orca/actions/runs/32265867029

The fork workflow run on this PR sits at action_required and never executes, so this PR has shown an empty check list since it was opened. I enabled Actions on my own fork and ran the repository's own pr.yml there against this exact SHA, so there is at least verifiable evidence while the upstream run stays unapproved.

Happy to re-run it after any change you'd like.

@nwparker nwparker removed the P1 label Aug 19, 2026
@bbingz
bbingz force-pushed the fix/13206-terminal-pty-selector branch from 8190c72 to 4713db3 Compare September 8, 2026 17:50
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 52744b9e-e453-419a-9212-8ddac4ba1084

📥 Commits

Reviewing files that changed from the base of the PR and between bba68b1 and 4713db35de7ee61ac8673af32c47eae601bd83d0.

📒 Files selected for processing (16)
  • src/cli/handlers/terminal.test.ts
  • src/cli/help.ts
  • src/cli/root-flag-help.ts
  • src/cli/root-help-text-secondary.ts
  • src/cli/selectors-pty-terminal.test.ts
  • src/cli/selectors.ts
  • src/cli/specs/core.ts
  • src/cli/specs/terminal-close.ts
  • src/cli/specs/terminal-send.ts
  • src/cli/terminal-command-flag-help.ts
  • src/cli/terminal-selector.ts
  • src/main/runtime/orca-runtime-subscribe-to-terminal-resize.ts
  • src/main/runtime/rpc/methods/terminal/terminal-query-methods.ts
  • src/main/runtime/rpc/methods/terminal/unary-schemas.ts
  • src/main/runtime/runtime-rpc-terminal-list.test.ts
  • src/main/runtime/runtime-terminal-list.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/cli/specs/core.ts
  • src/main/runtime/runtime-rpc-terminal-list.test.ts
  • src/cli/selectors.ts
  • src/cli/selectors-pty-terminal.test.ts
  • src/cli/terminal-selector.ts

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

Comment thread src/cli/specs/terminal-close.ts Resolved
@bbingz
bbingz force-pushed the fix/13206-terminal-pty-selector branch from 4713db3 to bcece41 Compare September 14, 2026 16:42
@bbingz

bbingz commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current origin/main (e53f1557e1). Fork CI still needs maintainer Approve and run workflows. Focused tests passed locally; no origin push and no merge.

@bbingz

bbingz commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current origin/main (357c9780f8). Fork CI still needs maintainer Approve and run workflows. Focused tests passed locally; no origin push and no merge.

@bbingz
bbingz force-pushed the fix/13206-terminal-pty-selector branch from bcece41 to 0176f3a Compare September 16, 2026 04:50
Handles rotate across restarts and rehydration; list still exposes a
stable ptyId. Resolve --terminal pty:<id> via terminal.list so fleet
tooling can address the surviving identity.

Closes stablyai#13206
Skip visualLayouts on the resolve list (other programmatic callers already
do) and raise the cap; when still truncated and unmatched, error clearly
instead of a bare not-found for large fleets (stablyai#13206/stablyai#13219).
Port the published lease selector: target terminal.list by ptyId, require
fresh liveness with a cached fallback, and skip disconnected or omitted
SSH hosts so large fleets and old hosts still resolve a stable id.
Keep help.ts at the main line budget by moving the pty selector and close
--tab copy next to the existing skills flag helper.
help.ts was already at the max-lines cap on main. Moving the generic
flag catalog keeps the pty-selector override without a disable.
Terminal verbs already override --terminal help to accept pty:<ptyId>.
The shared flag table stays handle-only so orchestration check does not
advertise a selector it cannot resolve.
@bbingz
bbingz force-pushed the fix/13206-terminal-pty-selector branch from 0176f3a to 5843af1 Compare September 19, 2026 03:21
@brynnclaw

Copy link
Copy Markdown
Contributor

Independent Linux run of this PR's current head, for reference. No Windows run is included here.

What was tested

  • PR head 5843af149c121db4d498bc25455179f1c0c8fc24 (fetched as pull/13219/head), measured as-is.
  • Its merge-base with main is cd81725d701cc29202c67fc5e9cb0fa27e86ff2d. main at the time was 27b823f934f739bc85914dd717b776835f60bcf7, 642 commits ahead of that merge-base. git merge-tree --write-tree origin/main pr13219 merges cleanly with no conflicts. I did not run tests on the merged tree.
  • Environment: Ubuntu 24.04 (x86_64, kernel 7.0), Node v24.21.0, pnpm 12.0.0, TypeScript 7.0.2, Vitest 4.1.11. The machine is a shared workstation with 12 cores and 15 GB RAM, and other jobs were running on it at the same time. I ran each heavy command in its own cgroup capped at 4 GB of memory and 580 s of runtime, and kept each test run to 4 workers and 4 CPUs. Those caps limited how much of the full suite I could run (see below).
  • Install: pnpm install --frozen-lockfile --prefer-offline: rc 0.

This PR's own tests

  • pnpm exec vitest run --config config/vitest.config.ts src/cli/selectors-pty-terminal.test.ts src/cli/handlers/terminal.test.ts src/main/runtime/runtime-rpc-terminal-list.test.ts: rc 0, 3 files / 49 tests passed.

Tests in the areas the PR touches

  • vitest run src/cli src/shared/rpc-contract: rc 0, 130 files passed; 1,340 tests passed, 4 skipped.
  • vitest run on the 125 test files under src/main/runtime whose file name contains terminal: 124 files passed; 1,004 tests passed, 1 failed, 1 skipped. The one failure was terminal-output-frame-chunks-equivalence.test.ts > ... fuzzes 800 near-cap payloads whose split point lands in the random region, which hit its 30 s timeout while the machine was under load.
    • The PR changes neither that test file nor any module it imports.
    • The case is sensitive to machine load. Solo runs of the file on this machine:
      • 20/20 passed.
      • A verbose run at a load average of about 15: 20/20 passed, and the fuzz case took about 21 s of its 30 s budget.
      • A verbose run at a load average of about 5: 20/20 passed, and the fuzz case took 20.0 s.
      • A verbose run at a load average of about 25: 19/20 passed. The fuzz case hit its 30 s timeout (Vitest reported 38 s).
    • So the case uses about two-thirds of its 30 s budget even on a lightly loaded machine, and it only fails under heavy load.
  • All of src/main/runtime (819 test files) plus src/cli together did not finish within the 580 s cap on this machine, so I have no full count for that combination.

Full pnpm test

  • This did not complete: it reached the 580 s cap and was stopped, so I have no full-suite count. Before the stop, Vitest had reported 9 failing files. The PR changes none of them.
  • I re-ran those 9 files with a clean environment: 8 passed, 1 failed; 157 tests passed, 11 failed.
  • 5 of the 8 files that then passed are the src/main/claude-accounts/runtime-auth-service-* tests. In the full run their log shows "Unexpected Claude config dir": the shell had a Claude config-directory environment variable set, and the tests picked it up. They passed once that variable was unset.
  • The other 3, src/main/claude/claude-stream-json-connection.test.ts, src/main/skills/skill-freshness-inventory.test.ts and src/main/skills/discovery.test.ts, failed only in the full run and passed in the clean-env re-run. I did not narrow down whether the environment or the machine load caused those three.
  • The 11 remaining failures are all in src/relay/git-handler-remote-sync.test.ts, at the git push to a temporary bare repository. This machine has a global git pre-push hook that refuses every push, so these failures come from the machine's setup, not the PR.

Typecheck

  • Full pnpm typecheck runs 4 tsc projects at once. Inside the 4 GB cap, the OOM killer stopped it after about 5 s, so I have no result for it.
  • One project at a time, each capped at 4 GB:
    • tsc --noEmit -p config/tsconfig.tc.cli.json: rc 0.
    • tsc --noEmit -p config/tsconfig.tc.web.json: rc 0.
    • tsc --noEmit -p config/tsconfig.mobile-web.json: rc 0.
    • These three reused .tsbuildinfo files that an earlier uncapped run had written on the same unchanged tree.
    • tsc --noEmit -p config/tsconfig.node.json alone also went over 4 GB and was OOM-killed after about 12 s.
  • Narrower check instead: a temporary tsconfig that extends config/tsconfig.node.json with composite and incremental off. Its include held only the four changed src/main files plus src/types, which pulled in about 4,900 source files. Result: rc 0, no errors. This is narrower than the project's full Node typecheck.

Not run: pnpm lint, pnpm build, and any Windows, macOS, WSL or SSH manual check.

@bbingz

bbingz commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @brynnclaw for the independent Linux run. The one failure was the fuzz test timing out under load, and the full-suite failures are in files this PR doesn't touch.

This branch has not been deployed

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

Terminal identity: handles change across restarts and rehydration; make ptyId a first-class selector

5 participants