Skip to content

fix(runtime): name a launched agent by its foreground process before tui-idle settles - #26490

Closed
Jinwoo-H wants to merge 5 commits into
mainfrom
readiness/agent-identity
Closed

Jinwoo-H wants to merge 5 commits into
mainfrom
readiness/agent-identity

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​208 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​206
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​58

ELI5

When you start an agent with extra options, like omp --thinking high, Orca didn't recognise it as an agent. It guessed "ready" about 2 seconds in, before the agent had drawn anything, and the first message you sent was lost. Orca now checks which program is actually running as soon as the launched command first draws something, and waits for that agent properly.

What Changed

Before:

  • terminal create --command "omp --thinking high" → terminal wait --for tui-idle returned ready about 2 s after creating the terminal, on a blank screen.
  • The next terminal send was silently dropped.
  • Codex with -c … flags, and DSH started as dsh-tui . --yolo or through a wrapper script, had the same problem.

After: these launches are named by their real foreground process and wait for that agent's own ready signal.

Mechanism, all through existing paths:

  • Identity is still launchAgent ?? foregroundAgent.
    • The existing foreground re-check (RuntimePtyForegroundAgent.refresh) used to run only after the agent set a terminal title. It now also runs when a command Orca launched first draws to the screen.
    • Whether Orca launched the pane comes from the existing spawn-command record (terminalSpawnCommandsByPtyId).
  • Agents run by a runtime (node, python) are named from their command line. This uses the existing readLocalPtyForegroundCommandLine + recognizeAgentProcessFromCommandLine pair, which OpenCode's run tracking already uses. The local-only check (not SSH or WSL) is now shared with that code.
  • An unknown command Orca launched has to draw something before it can count as quiet. Its quiet-foreground lane changes from open to after-paint. Panes Orca didn't launch keep today's behaviour.
  • What doesn't change:
    • every existing launchAgent consumer (startup plan, prompt gate, resume, mobile status, orchestration);
    • the user's command, which is never rebuilt.

Why

  • This fixes the input Orca's per-agent readiness rules depend on, which agent is running, through the code that already answers that question.
  • No new identity field, no work inside the readiness poll, no per-agent branches, no timing waits.
  • Alternatives considered:
    • Loosen the exact-match launch resolver to a prefix match. Rejected: that resolver also lets Orca rewrite the launch command.
    • A separate parser for the command's first word. Rejected: it would add a third identity source, and every live case was named by its real process anyway.

Linked Issue

Fixes #25264

Related: #17291. Its worker-start prompt gate keys on launchAgent, which this PR deliberately doesn't change.

Visual Proof

N/A: no UI change. This changes when a readiness wait settles; live timings are under Testing.

Testing

  • I manually tested these changes locally

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

  • Unit and runtime tests. These fail on the base commit:

    • a flagged agent with no output;
    • a flagged Codex launch showing only its splash screen;
    • a flagged DSH launch;
    • a wrapper that runs DSH;
    • an unknown launched command before it draws.

    These pass on both, as intended:

    New foreground-recognition cases cover: node running dsh-tui, a direct process name, node running something else, and an unreadable command line.

  • Live, macOS, isolated background dev runtime. DSH rows were run with fix(runtime): settle a cold-started DSH pane on its idle composer #26691's DSH screen rules merged locally:

Command Ready after Result
omp --thinking high 8.4–8.9 s (base: ~2 s) pong delivered
omp 6.6–6.9 s pong delivered
codex -c model_reasoning_effort="high" (folder trusted) 7.0 s pong delivered
vim / less 4.7 s / 4.6 s settled after drawing
dsh-tui . --yolo 4.5 s composer up; process node named dsh
DSH wrapper script (0.12 / 0.13) 2.4 s composer up; named dsh
  • Checks: pnpm tc, check:code-quality:changed, and 19 related test files (1613 tests) are clean.

Review

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

  • SSH/WSL: the foreground command line isn't readable from this host, so a runtime-hosted agent there stays unnamed until its first title. Until then it gets the safer after-paint lane.
  • Launches with no command-start marker (Windows argument launches, some shells) still name the agent at its first title, as before.
  • Reattach/restore: a warm reattach records no spawn command. A cold-restore resume always carries launchAgent, so neither path changes.
  • Wire: no change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Jinwoo-H and others added 2 commits October 8, 2026 03:01
…hed commands to their paint (STA-9412)

terminal create --command "omp --thinking high" settled tui-idle about 2s after
create: readiness only knew the pane's agent from an exact launch-command match or
a later OSC title, so the pane read as unknown, and the unknown lane treated a
pane with no output clock as quiet.

Record the agent the launch command's argv names (env prefixes, paths, quoted
Windows paths, .exe/.cmd, user overrides by command words, disabled agents) on the
PTY record for readiness only, leaving the startup plan and launchAgent consumers
untouched. A command Orca launched that names no agent now waits for its own
paint instead of settling on silence.

Co-Authored-By: Claude <[email protected]>
…le settles

A launched command whose argv names only a wrapper script that execs an agent
(DSH via a wrapper) still read as an unknown command: once it painted a splash
and went quiet, the foreground poll settled tui-idle before the composer.

When the foreground process of a launched pane names an agent the pane does not
know yet, refresh the pane's foreground agent instead of settling, so the next
evaluation ranks it by that agent's own lanes. Panes Orca did not launch keep
the uncorroborated quiet-foreground settle. Test fixtures now use neutral
command names.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 8, 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: 31a6b6a2-1fe0-4904-93fd-9ab641282ef4
📥 Commits

Reviewing files that changed from the base of the PR and between 6aeaf75 and ee7d74f.

📒 Files selected for processing (1)
  • src/main/runtime/tui-idle-launch-command-identity.test.ts

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


📝 Walkthrough

Walkthrough

The terminal pane harness now records startup commands. PTY paint observation reports the first visible command paint and can trigger foreground-agent refresh. Wrapper processes can be identified through foreground command-line lookup. TUI idle evidence includes launch-command status, and launched unknown or non-TUI panes use the after-paint lane.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to ee7d7

A locally launched wrapper can be reported ready while its agent is still starting, potentially losing an immediate prompt. Resolve or explicitly accept this readiness risk before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 13.64% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 24 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 primary change: naming launched agents from their foreground process before tui-idle settles.
Description check Passed The description includes the required sections, linked issue, user-facing behavior, implementation details, rationale, testing evidence, platform considerations, and checklist status. It is complete e…
Linked Issues check Passed Issue #25264 requires that a launched agent is not reported idle before it renders. The current code observes first command paint in onPtyData, refreshes foreground-agent identity for Orca-launched …
Out of Scope Changes check Passed The production changes stay within launched-command identity and tui-idle readiness. The shared local-readability check supports runtime command recognition. The command-paint, harness, and readines…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

@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: 3a349a91-d7cf-4200-b5fb-8b56509150fd
📥 Commits

Reviewing files that changed from the base of the PR and between 0eee1ce and ebfb569.

📒 Files selected for processing (18)
  • src/main/runtime/agent-transcript-pane-test-harness.ts
  • src/main/runtime/orca-runtime-create-terminal-dependencies.ts
  • src/main/runtime/orca-runtime-create-terminal-desktop.ts
  • src/main/runtime/orca-runtime-create-terminal.ts
  • src/main/runtime/orca-runtime-resolve-worktree-removal-target.ts
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/runtime-agent-launch-resolution.test.ts
  • src/main/runtime/runtime-agent-launch-resolution.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/runtime-terminal-idle-polls.test.ts
  • src/main/runtime/runtime-terminal-idle-polls.ts
  • src/main/runtime/runtime-terminal-state-records.ts
  • src/main/runtime/terminal-wait-name-only-idle.test.ts
  • src/main/runtime/tui-idle-evidence-source.ts
  • src/main/runtime/tui-idle-evidence.test.ts
  • src/main/runtime/tui-idle-evidence.ts
  • src/main/runtime/tui-idle-launch-command-identity.test.ts
  • src/shared/agent-process-recognition.ts

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

Comment on lines +83 to +86
const pty = runtime.ptysById.get(runtime.handles.get(handle)?.ptyId)
if (pty && launchOpts.launchCommandIdentity) {
pty.launchCommandIdentity ??= launchOpts.launchCommandIdentity
}

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C12 'waitForTerminalHandle\s*\(' src/main/runtime --type=ts | head -80

Repository: stablyai/orca

Length of output: 6127


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- waitForTerminalHandle and nearby declarations ---'
sed -n '90,190p' src/main/runtime/orca-runtime-restore-live-paired-renderer-session-owned-mobile-terminals.ts
printf '%s\n' '--- resolveHandleForTab and related handle/PTY registration references ---'
rg -n -F --glob '*.ts' -e 'resolveHandleForTab' -e 'handles.set' -e 'ptysById.set' -e 'ptyId' src/main/runtime | head -160
printf '%s\n' '--- runtime declarations and graph-sync handlers ---'
rg -n -F --glob '*.ts' -e 'handles:' -e 'ptysById:' -e 'graphSyncCallbacks' -e 'register.*Pty' -e 'register.*Handle' src/main/runtime | head -200

Repository: stablyai/orca

Length of output: 35885


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- exact resolveHandleForTab declaration and references ---'
rg -n -F --glob '*.ts' -- 'resolveHandleForTab' src | head -120
printf '%s\n' '--- handle map declarations and writes ---'
rg -n -F --glob '*.ts' -- 'handleByPtyId' src/main/runtime | head -120
rg -n -F --glob '*.ts' -- 'handles.set' src/main/runtime | head -120
printf '%s\n' '--- PTY registration implementation ---'
sed -n '1,180p' src/main/runtime/orca-runtime-register-pty.ts
printf '%s\n' '--- graph sync handler around callback dispatch ---'
sed -n '260,335p' src/main/runtime/orca-runtime-sync-window-graph.ts

Repository: stablyai/orca

Length of output: 20520


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- resolveHandleForTab and surrounding methods ---'
sed -n '120,185p' src/main/runtime/orca-runtime-wait-for-leaf-pty-id.ts
printf '%s\n' '--- adoptPreAllocatedHandle declaration and implementation ---'
rg -n -F --glob '*.ts' -- 'adoptPreAllocatedHandle' src/main/runtime
sed -n '1,220p' src/main/runtime/orca-runtime-bind-pty-incarnation-handle.ts
printf '%s\n' '--- handle and PTY map declarations ---'
sed -n '285,315p' src/main/runtime/orca-runtime-runtime-id.ts
rg -n -F --glob '*.ts' -- 'ptysById = ' src/main/runtime

Repository: stablyai/orca

Length of output: 10620


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- issueHandle declaration and callers ---'
rg -n -F --glob '*.ts' -- 'issueHandle' src/main/runtime | head -120
printf '%s\n' '--- likely owning implementation ---'
rg -n -F --glob '*.ts' -- 'protected issueHandle' src/main/runtime

Repository: stablyai/orca

Length of output: 2945


🏁 Script executed:

#!/bin/bash
set -e
sed -n '135,205p' src/main/runtime/orca-runtime-build-pty-terminal-summary.ts

Repository: stablyai/orca

Length of output: 2401


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- registerPty call sites ---'
rg -n -F --glob '*.ts' -- 'registerPty(' src/main | head -120
printf '%s\n' '--- graph leaf update and PTY identity handling ---'
rg -n -F --glob '*.ts' -e 'ptyId:' -e 'this.leaves' -e 'setLeaf' src/main/runtime/orca-runtime-sync-window-graph.ts | head -120
sed -n '1,130p' src/main/runtime/orca-runtime-sync-window-graph.ts

Repository: stablyai/orca

Length of output: 21762


Do not lose the launch identity before the PTY is registered.

waitForTerminalHandle waits for a non-null leaf ptyId, but it does not require that ID to exist in runtime.ptysById. If graph sync publishes the leaf before registerPty records the PTY, the post-wait lookup skips launchCommandIdentity, and the new readiness handling does not apply. Tie identity assignment to PTY registration, or make waitForTerminalHandle wait for both conditions.

Jinwoo-H and others added 2 commits October 8, 2026 19:18
…irst paint

Rework of the launch-identity fix onto Orca's existing identity path, per review.

Drop the PTY record's launchCommandIdentity slot, the argv first-word resolver,
the desktop-create patch and the idle poll's identity side effect. Instead the
existing foreground-agent refresh, which ran only after a title observation,
also runs when a launched command first paints, so a flagged agent launch or a
wrapper that execs an agent is named by its real process via the existing
recognizer before tui-idle reads its boot as rest. tui-idle keeps
launchAgent ?? foregroundAgent; the poll only evaluates.

Whether a pane was launched with a command comes from the existing spawn
command map; an unknown launched command keeps the 'after-paint' lane, and
panes Orca did not launch keep 'open'.

Co-Authored-By: Claude <[email protected]>
… line

dsh-tui runs as a `node` process, so the foreground-agent refresh could not
name `dsh-tui . --yolo` or a wrapper that execs it, and tui-idle read the pane
as an unknown command. When the foreground process is a runtime, read its
command line on this host and recognise it there, as the OpenCode run-lifetime
reader already does. SSH and WSL panes, whose command line this host cannot
read, keep the process-name recognition.

Co-Authored-By: Claude <[email protected]>
@Jinwoo-H Jinwoo-H changed the title fix(runtime): recognise flagged agent launches before tui-idle settles fix(runtime): name a launched agent by its foreground process before tui-idle settles Oct 8, 2026

@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: 2c127327-d6a6-4dbf-9acd-b4458c35c56c
📥 Commits

Reviewing files that changed from the base of the PR and between ebfb569 and 6aeaf75.

📒 Files selected for processing (10)
  • src/main/runtime/agent-transcript-pane-test-harness.ts
  • src/main/runtime/orca-runtime-on-pty-data.ts
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/orca-runtime-stop-requested-pty-ids.ts
  • src/main/runtime/runtime-pty-foreground-agent.test.ts
  • src/main/runtime/runtime-pty-foreground-agent.ts
  • src/main/runtime/terminal-command-paint.test.ts
  • src/main/runtime/terminal-command-paint.ts
  • src/main/runtime/tui-idle-evidence-source.ts
  • src/main/runtime/tui-idle-launch-command-identity.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/tui-idle-evidence-source.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.

!pty.foregroundAgent &&
this.terminalSpawnCommandsByPtyId.has(ptyId)
) {
void this.ptyForegroundAgent.refresh(ptyId)

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep the first-paint refresh pending during quiet readiness.

If a launched wrapper paints a splash and command-line lookup takes longer than the quiescence interval, this fire-and-forget refresh leaves foregroundAgent null. The idle poll can then use the unknown-command after-paint lane, read a non-shell foreground process, and settle before the wrapper’s agent is named. A prompt can reach a TUI that is still booting. Make the poll defer quiet settlement while this refresh is pending, and test with a delayed command-line lookup. The poll’s foreground read does not wait for agent recognition. (raw.githubusercontent.com)

…ignal

The flagged-launch and wrapper cases settled DSH through its first-party OSC
done, a lane the DSH hook-store work removes. Settle them on Codex's explicit
idle title instead, which tui-idle reads for any agent, and make the wrapper
case a runtime-hosted agent named from its foreground command line. Both still
stay pending on the splash until the agent's own rest signal.

Co-Authored-By: Claude <[email protected]>
@nwparker

nwparker commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue (#25264) has been resolved on main by #33466 (1e221ceb7d). Thanks for the contribution!

@nwparker nwparker closed this Nov 5, 2026
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]: tui-idle reports a flagged terminal create --command "omp …" launch idle after ~2s (agentIdentity null, blank screen); the next prompt is lost

2 participants