Skip to content

fix(runtime): add opt-in agentWait to worktree ps agent rows - #24142

Merged
nwparker merged 1 commit into
stablyai:mainfrom
ggbdpq:fix/worktree-ps-agent-wait
Oct 28, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
ggbdpq:fix/worktree-ps-agent-wait

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

orca worktree ps --json gives an agent one call that shows every worktree and the agents running in it. It already told you an agent's rough state, but not the more precise "this agent is stuck waiting for a human" verdict that orca terminal show gives. To get that, a watcher had to call terminal show once for every terminal. Now you can pass --agent-wait to worktree ps and each agent row includes that same verdict.

What Changed

  • Before: agent rows in worktree ps --json never had agentWait. Getting it meant one orca terminal show --terminal <handle> --json call per terminal.
  • After: orca worktree ps --agent-wait --json adds agentWait to every terminal-backed agent row on the returned page. It uses the same contract as terminal show: a { source, reason?, since? } descriptor when the agent is waiting on a human, null when it checked and found no wait, and no field at all when it couldn't evaluate (structured-worker rows, older hosts). Without the flag the output is unchanged.

Mechanism:

  • The worktree.ps RPC accepts a new optional includeAgentWait: true param. The CLI sends it only for --json + --agent-wait.
  • Hook-backed row sources now keep the terminalHandle they were observed under, not just the resolved ptyId.
  • getWorktreePs paginates first. When the caller opts in, attachRuntimeWorktreeAgentRowWaits() then runs getTerminalInteractiveWait() in parallel, only for the rows on the returned page. A hook row's handle is used only when a connected PTY confirms it. Rows that reported only a pane key (HTTP hook posts) find their live terminal by pane key, the same way terminal show does.
  • Help text, the CLI spec notes, the bundled skill guide, and the boolean-flag registry all list the new flag.

Why

worktree ps is meant to cover the whole fleet in one call. Making the caller fan out to terminal show per terminal defeats that. The lookup reads screens and can probe PTYs, so it's opt-in and limited to the returned page. That keeps default pollers (desktop, mobile, scripts) at today's cost. Mixed versions are safe: a new CLI talking to an old host just doesn't get the field (absent means "not evaluated"), and an old CLI never sends the param.

Linked Issue

Fixes #23921

Visual Proof

N/A: this changes CLI JSON output, not UI. Here's the before/after from a runtime probe that compares terminal show with worktree ps for the same waiting agent:

Before (main)
PROBE show.agentWait= {"source":"hook","since":1793150063163} ps.agentWait=
 FAIL worktree ps agentWait > reports the terminal hook wait only when requested
AssertionError: expected undefined to match object { source: 'hook' }
 FAIL worktree ps agentWait > resolves the live terminal for a hook row that reported only its pane
 FAIL worktree ps agentWait > reports null when the terminal shows no wait
AssertionError: expected undefined to be null
After (this PR)
PROBE show.agentWait= {"source":"hook","since":1793149936569} ps.agentWait= {"source":"hook","since":1793149936569}
 Tests  8 passed

Testing

  • Reproduced on main: terminal show reports a hook wait, but the worktree ps row for the same agent has no agentWait. Verified the branch reports the identical descriptor.

  • New worktree-ps-agent-wait.spec.ts runs through the real getWorktreePs. It checks that the wait is reported only on request (and nothing is probed otherwise), that pane-only hook rows find their live terminal, and that a working agent gets null.

  • Updated worktree-catalog-snapshot-method.test.ts for the new RPC param.

  • pnpm test src/main/runtime/rpc/methods/worktree-catalog-snapshot-method.test.ts src/main/runtime/orca-runtime.test.ts src/cli: 187 files, 3671 tests pass.

  • oxlint (anti-slop, code-quality native plugins), ast-grep, the changed-code quality gate, and oxfmt are clean on the touched files.

  • Platforms: macOS. The change is platform-neutral runtime/CLI logic with no paths, shells, or native modules involved.

  • I manually tested these changes locally

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

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: read-only data that the authenticated terminal show already exposes. Remote/SSH: works per host, and older hosts omit the field. Mobile: default calls are unchanged. Folder workspaces: rows are keyed by pane/terminal, not git. Performance: opt-in, page-scoped, parallel, and reuses the existing deduplicated and timeout-bounded probe.

Original fix by @ggbdpq in #24142 (authorship preserved; maintainer follow-ups made the lookup opt-in, limited it to the returned page, and added pane-only hook rows).

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds terminal wait signals to worktree process status rows.

The PR appears safe to merge; no new actionable issue remains.

Summary

The PR adds agentWait to terminal-backed worktree agent rows while preserving an absent field for unevaluated and structured-worker rows. The changes since the previous review scope test setup to its own suite, preventing it from overriding the shared scan mock in sibling tests.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Agent status snapshot] --> B[Collect row sources]
  B --> C{Terminal handle present?}
  C -->|Yes| D[Resolve terminal interactive wait]
  C -->|No| E[Leave agentWait absent]
  D --> F[Build worktree agent row]
  E --> F
Loading

Reviews (3) · Last reviewed commit: "test(runtime): scope the structured-host..."

@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 critical issues — one minor, non-blocking suggestion.

Reviewed changes

A focused, well-scoped fix that threads the richer agentWait human-wait signal onto worktree ps agent rows.

  • terminalHandle retained on the row source — runtime-worktree-pty-agent-sources.ts now carries the observed handle alongside the resolved ptyId, giving the assembly its lookup key.
  • New wait-threading pass — runtime-worktree-agent-row-waits.ts resolves getTerminalInteractiveWait once per handle-ful source in parallel and leaves unresolved (undefined) sources untouched.
  • Wiring in getWorktreePs — orca-runtime-get-worktree-ps.ts:102 wraps the collected sources before row assembly.
  • Row builder + wire contract — the field is copied only when present, and RuntimeWorktreeAgentRow.agentWait is an additive optional field with the documented null-vs-absent semantics.
  • Tests — four new cases in runtime-worktree-agent-rows-agent-wait.test.ts plus a structured-absence assertion in worktree-ps-structured-host.spec.ts.

I verified the getter's null/undefined semantics match the documented contract, that the conditional-poll snapshot id hashes the whole result (so agentWait participates in change detection), that structured rows genuinely have no terminalHandle, and that formatWorktreePs does not print agent rows.

ℹ️ No test drives a pty row's agentWait through the real getWorktreePs

The new unit tests compose attachRuntimeWorktreeAgentRowWaits and attachRuntimeWorktreeAgentRows by hand, and the one test that executes the production read (worktree-ps-structured-host.spec.ts) only covers the structured absence path. Because orca-runtime-get-worktree-ps.ts is @ts-nocheck, dropping the attachRuntimeWorktreeAgentRowWaits(...) wrapper at the call site would leave every test green while the feature silently reverts. Since the adjacent spec exists precisely to exercise that file, an end-to-end pty case would close the loop. Non-blocking.

Technical details
# Integration coverage for the pty happy path

## Affected sites
- `src/main/runtime/orca-runtime-get-worktree-ps.ts:102` — the only production call site; `@ts-nocheck` means a wiring regression is invisible to typecheck.
- `src/main/runtime/orca-runtime-tests/worktree-ps-structured-host.spec.ts:34` — exercises the real `getWorktreePs` but asserts only that structured rows lack `agentWait`.

## Required outcome
- A test that runs the real `getWorktreePs` with a pty-backed agent row whose handle resolves to a populated wait, and asserts the row carries `agentWait` (and, optionally, an explicit `null` when the getter evaluates to no wait).
- Such a test must fail if the `attachRuntimeWorktreeAgentRowWaits` call is removed.

## Suggested approach (optional)
- Extend the existing structured-host spec (or add a sibling) using a runtime test double that stubs `getTerminalInteractiveWait` to return a descriptor for the hook snapshot's `terminalHandle`.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 99d9aea0-9208-4bbe-b52a-89edd07fe60b

📥 Commits

Reviewing files that changed from the base of the PR and between 138849be610593c7097afc86e267d32d8894f062 and a6ec30d41f8390fc949fd7d1ba1b1c065822dfe3.

📒 Files selected for processing (1)
  • src/main/runtime/orca-runtime-tests/worktree-ps-structured-host.spec.ts

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

Walkthrough

Worktree agent rows now include agentWait when a terminal handle is available. The runtime resolves wait signals before constructing the rows. A resolved wait is included, null represents an evaluated result with no wait, and an absent field indicates that no lookup was performed. Structured workers without terminal handles omit the field.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to a6ec3

The change exposes terminal wait signals while preserving unevaluated and no-wait states. No concrete merge-blocking risk remains; merge after normal checks.

Security architecture risk: Low · up to a6ec3

The change exposes richer wait metadata without adding terminal-control capabilities. Known evaluation failures preserve an unknown result rather than falsely reporting that no wait exists. Remaining uncertainty concerns concurrent reads, probe cleanup, and access differences between fleet-wide and individual-terminal reads.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The visible exposure change is richer terminal-wait metadata on existing fleet-read rows, together with evaluation across the runtime's collected handle-bearing sources. The added path does not itself write to terminals or execute commands; downstream access and interpretation are not fully mapped.

Trust Boundaries and Controls

  • observed — Terminal text, title, and explicit status influence the wait descriptor. Live-terminal resolution binds evaluation to a PTY, and the status query rechecks that binding after asynchronous process checks. These are identity and observation controls, not proof of caller authorization.

Resilience and Maintainability Implications

  • observed — Concurrent reads share in-flight status queries by handle and wait probes by PTY. Entries are removed when their underlying operations settle. Timeout bounds the caller's wait but does not cancel the probe, so cleanup of a permanently hung operation is not established. This behavior belongs to the reused getter; an introduced security impact is not demonstrated.

Hardening Proposals

  • proposed — Consider cancellation or bounded recovery for underlying status probes, with concurrent fleet-read and interruption coverage. This would strengthen cleanup guarantees as the existing getter gains a fleet-wide caller; it is not a verified PR defect.
Pre-merge checks: Passed 4
Check name Status Explanation
Linked Issues check Passed Issue #23921 requires a richer agentWait signal in fleet agent rows. The PR carries terminal handles from PTY sources, resolves waits in parallel, and copies populated waits or explicit null into …
Out of Scope Changes check Passed The source-handle propagation, wait enrichment, shared row projection, runtime wiring, and tests directly support issue #23921. No unrelated change is demonstrated by the reviewed evidence.
Title check Passed The title clearly and concisely describes the opt-in addition of agentWait to worktree ps agent rows.
Description check Passed The description is complete and focused. It explains the user impact, implementation, rationale, linked issue, testing, visual proof, compatibility, and performance considerations. The AI Disclosure a…
Full details: Linked Issues check

Explanation

Issue #23921 requires a richer agentWait signal in fleet agent rows. The PR carries terminal handles from PTY sources, resolves waits in parallel, and copies populated waits or explicit null into RuntimeWorktreeAgentRow; unresolved lookups remain absent. Tests cover populated, null, unevaluated, missing-handle, and structured-worker cases. This implements the requested worktree ps --json behavior and preserves the documented row contract.

Full details: Description check

Explanation

The description is complete and focused. It explains the user impact, implementation, rationale, linked issue, testing, visual proof, compatibility, and performance considerations. The AI Disclosure and Checklist sections are not explicitly included, but the required substantive information is present.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@ggbdpq

ggbdpq commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Done in 138849be61 (see the detail in the greptile thread): three pty-path cases now run through the real getWorktreePs — stubbed-getter wiring proof, a real-getter populated {source: 'hook'} resolution, and an explicit null on a no-wait row. With the attachRuntimeWorktreeAgentRowWaits(...) call temporarily removed, exactly those three fail while the structured cases stay green, so the @ts-nocheck wiring regression you describe is now caught. The spec also pins the unconfigured scanLocalRepoWorktreesForResolutionMock that was leaving every case in the file listing nothing. Honest caveat, also posted on the thread: these orca-runtime-tests/*.spec.ts suites are not in the CI unit lanes (UNIT_INCLUDE only globs *.test.ts), so they run wherever someone extends the vitest config locally.

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

Caution

This PR breaks the aggregate runtime unit suite. A new top-level beforeEach in worktree-ps-structured-host.spec.ts clobbers the shared scan mock for every test in the aggregate orca-runtime.test.ts, so worktree-scan-cache-ttl.spec.ts fails. CI globs src/**/*.test.ts, which includes the aggregate, so this is red until scoped.

Reviewed changes

  • Added pty end-to-end coverage — three cases in worktree-ps-structured-host.spec.ts now drive a handle-carrying hook row through the real getWorktreePs (stubbed getter proves the wiring; the real getter resolves a populated { source: 'hook' }; a working row carries an explicit null). This closes the prior review's @ts-nocheck-wiring gap.
  • Primed the shared scan mock — a top-level beforeEach sets scanLocalRepoWorktreesForResolutionMock.mockResolvedValue(...) so the spec's cases have a resolved worktree snapshot.
  • Pinned structured absence — expect(worktree?.agents[0]).not.toHaveProperty('agentWait') for a host-held structured session.

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

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

Reviewed changes

The only delta since the prior review is the fix for the aggregate-suite regression, and it is correct.

  • Scoped the scan-mock override — the beforeEach that primes scanLocalRepoWorktreesForResolutionMock moved from module top level into an outer describe, so it registers only for this file's tests and the shared scan mock that resetRuntimeTestMocks delegates to listWorktrees survives for every other spec.

I verified the fix independently: pnpm vitest run src/main/runtime/orca-runtime.test.ts -t "keeps a scratch repo scan cached past the base TTL" (the case that previously failed at worktree-scan-cache-ttl.spec.ts:73) now passes, and both new specs are green (9/9). The pty end-to-end coverage added earlier still drives the real getWorktreePs through attachRuntimeWorktreeAgentRowWaits.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@ggbdpq
ggbdpq force-pushed the fix/worktree-ps-agent-wait branch from a6ec30d to 8e39345 Compare October 25, 2026 12:46
@ggbdpq

ggbdpq commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 7d18e19907 today; the conflicts from the upstream getWorktreePs move were resolved by carrying the wait-threading into workspaces/workspace-process-listing.ts and adapting the tests to the current attachRuntimeWorktreeAgentRows lookup convention and the narrowed RuntimeTerminalWaitBlockedReason union. All review threads are resolved (the scan-mock scope leak was fixed in e933876ff2; the 2s probe stays per the Option A ruling). Verification on the rebased head: the agent-wait row unit tests pass 4/4, the worktree ps structured host suites pass 5/5 through the aggregate, pnpm run typecheck is green, and the full orca-runtime.test.ts aggregate shows only the two pre-existing macOS /private/var path-normalization failures that reproduce identically on a clean upstream/main checkout.

@nwparker gentle ping — happy to adjust anything.

@ggbdpq
ggbdpq force-pushed the fix/worktree-ps-agent-wait branch from 8e39345 to 3d46d70 Compare October 27, 2026 14:05
@ggbdpq

ggbdpq commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (f61e7f8) and force-pushed. One mechanical adaptation: upstream renamed the worktree-ps evidence field to terminalTitleEvidenceByWorktreeId and reworked the row-source call site; the conflict resolution keeps this PR's attachRuntimeWorktreeAgentRowWaits threading on top of the renamed source, and the agent-wait fixture follows the current field name. Targeted suites 9/9 (agent-wait rows + structured-host spec), typecheck:node clean, oxlint clean.

@nwparker gentle ping whenever you get a chance — happy to adjust anything.

`orca worktree ps --agent-wait --json` now reports, on each terminal-backed
agent row of the returned page, the same agentWait verdict
`orca terminal show --json` gives for that terminal. The lookup is opt-in
(RPC `includeAgentWait: true`) because it reads screens and may probe PTYs,
which is too costly for default pollers. Hook rows use their terminal handle
only when a connected PTY confirms it, and pane-only hook rows resolve the
live terminal by pane key. Structured-worker rows and older hosts omit the
field (absent = not evaluated; null = looked, no wait).

Fixes stablyai#23921

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/worktree-ps-agent-wait branch from 3d46d70 to 01ec475 Compare October 28, 2026 03:24
@nwparker nwparker changed the title fix(runtime): carry agentWait on worktree ps agent rows fix(runtime): add opt-in agentWait to worktree ps agent rows Oct 28, 2026
@nwparker
nwparker merged commit ea6c69b into stablyai:main Oct 28, 2026
47 checks passed
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.

[Bug]: worktree ps --json agent rows carry no agentWait — only terminal show does, forcing a second call per lane to detect a human-wait

2 participants