Skip to content

fix(runtime): resolve the pane agent from flagged --command launches - #25320

Closed
ggbdpq wants to merge 1 commit into
stablyai:mainfrom
ggbdpq:fix/command-flags-agent-identity
Closed

ggbdpq wants to merge 1 commit into
stablyai:mainfrom
ggbdpq:fix/command-flags-agent-identity

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

ELI5

When you launch an agent through terminal create --command "omp --model x" (flags included), Orca could not tell which agent the pane belongs to — it only recognized the bare command omp. With the agent unknown, terminal wait --for tui-idle declared "ready" about 2 seconds in, while the screen was still blank, and a prompt sent at that moment was silently dropped. This PR makes Orca read the agent's name from the first word of the launch command, so waits and identities behave exactly like the no-flags launch.

What Changed

  • Each runtime-owned spawn now records its launch command line on the pty record (launchCommandLine), seeded at create/split time; adopted and restored panes have no seed and keep today's behavior.
  • A new resolveLaunchCommandPaneAgent resolves the pane's agent from that command's first token, reusing the existing process-command recognition (including its headless/one-shot filtering) with a isTuiAgent guard. It is only a fallback in the existing chains: wait ranking (getPaneAgentForTuiIdle) and the published agentIdentity now read launchAgent ?? foregroundAgent ?? commandAgent.
  • Retiring a pane's launch authority on exit (agent quit, 133;D) also clears the seeded command, so a pane returning to a shell prompt is not mistaken for the agent.
  • Nothing else changes: managed launches (no flags) resolve exactly as before, no spawn arguments are rewritten, and no readiness/screen rule is touched.

Why

The root cause is identity resolution, not the wait itself: the bare-command matcher (resolveBareAgentLaunchCommand) requires an exact full-string match, so "omp --model x" correctly stays an unmanaged launch but left the pane agentless, and the agent-null wait lane is satisfied by generic evidence a real composer would never produce. Fixing the wait instead of the identity would have loosened readiness for every agent; seeding identity from the launch command fixes the one broken link and lets the existing agent-aware OMP lane (title-age + screen veto) do its job.

Linked Issue

Fixes #25264

Visual Proof

N/A for attached media in this environment (headless run, no OMP environment locally). Behavior is pinned by tests: new runtime cases assert getPaneAgentForTuiIdle returns omp for a flagged --command launch (red before: expected null to be 'omp') and that the inherited identity retires with the launch authority; 5 unit cases cover the resolver (first-token recognition, non-agent and headless commands stay null).

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Commands actually run locally (macOS, clean source tree): new unit tests 5/5; the two new runtime cases plus the retirement case via -t filters; the full pnpm test src/main/runtime/orca-runtime.test.ts suite 1351 passed | 1 skipped (re-run by the integrating agent on a clean tree); adjacent suites (agent-process-recognition, terminal-wait-detection, tui-idle-evidence) 194 passed; npx tsc -b config/tsconfig.node.json --force exit 0; oxlint and oxfmt --check clean on all 11 touched files. Real-hardware OMP timing (13–21 s composer wait reported in the issue) was not reproduced locally — the fix is pinned at the identity layer, and the OMP readiness lane itself is pre-existing, transcript-backed logic this PR does not modify.

AI Disclosure

Investigation, coding and verification by GLM-5.3-Flash (ZCode agent); orchestrated, reviewed and committed by a main agent with the same model, with a human overseeing.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Identity-only change: no wire compatibility impact (the published agentIdentity field gains values it was already typed for), no Windows-specific paths touched, SSH spawns unchanged (the seed rides runtime-owned records, not spawn arguments), mobile unaffected. Known scope limit, stated in the issue's terms: plain-SSH flagged launches whose process read has not landed yet still report null identity until their foreground read arrives — same as today.

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)

`terminal wait --for tui-idle` after `terminal create --command
"omp <flags>"` satisfied in ~2s on a blank screen with agentIdentity
null, and a prompt sent at that point was silently dropped: the
bare-command matcher only recognizes exact launch commands, so any
flags left the pane's agent unknown and the wait fell into the
agent-null generic lane. Seed each runtime-owned spawn with its launch
command line and resolve the pane agent from its first token for the
wait ranking and the published identity; retiring the launch authority
on exit also clears the seed so a pane returning to a shell prompt is
not mistaken for the agent. Managed launches (no flags) are unchanged,
no readiness rule is touched, and adopted or restored panes (no seeded
command) keep their existing behavior.

Fixes stablyai#25264

Generated-by: GLM-5.3-Flash (ZCode)
@coderabbitai

coderabbitai Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

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: fdeb1139-efd5-4c16-b449-5a83906f9db5
📥 Commits

Reviewing files that changed from the base of the PR and between a753aff and f10fe13.

📒 Files selected for processing (11)
  • src/main/runtime/orca-runtime-build-pty-terminal-summary.ts
  • src/main/runtime/orca-runtime-create-terminal.ts
  • src/main/runtime/orca-runtime-get-orchestration-dispatch-authority.ts
  • src/main/runtime/orca-runtime-record-pty-worktree.ts
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/orca-runtime-split-pty-backed-terminal.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness.spec.ts
  • src/main/runtime/orca-runtime-write-orchestration-pointer-pty.ts
  • src/main/runtime/runtime-agent-launch-resolution.test.ts
  • src/main/runtime/runtime-agent-launch-resolution.ts
  • src/main/runtime/runtime-terminal-state-records.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

Walkthrough

Runtime-owned PTY records now store the requested launch command. When launchAgent is absent, terminal summaries can derive agent identity from that command. TUI-idle lookup uses the same fallback when neither launchAgent nor foregroundAgent is set. Tests cover flagged omp launches and the removal of published agent identity after the shell command finishes.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to f10fe

Flagged agent launches can receive an identity before foreground detection without displacing a later detected foreground agent. No merge-blocking issue was established; normal validation remains appropriate.

Security Architecture Review

Security architecture risk: 🔵 Low · up to f10fe

The change affects how terminals are identified and when they are considered ready. Existing access controls remain separate, but startup and reconnection edge cases are not fully established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated propagation is from requested launch commands to the corresponding PTY's readiness classification and published terminal identity. The inspected paths do not establish additional credential, tenant, or service authority from that classification.

Trust Boundaries and Controls

  • observed — Command-derived identity is separate from orchestration authorization. Dispatch authority does not consult launchCommandLine, and compatibility verification requires matching launch-token or restored-receipt evidence with host, process, and pane checks, plus hook attestation when required.

Resilience and Maintainability Implications

  • inferred — The lifecycle evidence leaves two unresolved containment cases: completion before post-spawn command metadata assignment, and retained command metadata during same-ID incarnation replacement. Normal retirement and early process-exit fencing provide counterevidence, but provider ordering and replacement guarantees were not established. Incorrect identity or readiness in these cases remains a possibility, not a verified attack path.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 11 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 states the main change: resolving pane-agent identity for launches with command flags.
Description check ✅ Passed The description explains the problem, the implementation, scope, linked issue, and testing. The Visual Proof section says media was unavailable, but the template asks for proof for behavior changes or…
Linked Issues check ✅ Passed Issue #25264 asks Orca to recognize flagged agent launch commands so tui-idle does not use the generic agent-null lane before the agent renders. resolveLaunchCommandPaneAgent uses the existing com…
Out of Scope Changes check ✅ Passed The changes in the PR support issue #25264: they record the launch command, resolve the pane agent for wait ranking and published identity, retire that identity on exit, and test these behaviors. No u…
  • Fix all pre-merge checks with AI
  • 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.

@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

  • Seed launchCommandLine on runtime-owned spawns — orca-runtime-create-terminal.ts (only when not adopting a stable pane) and orca-runtime-split-pty-backed-terminal.ts record the requested command; record-pty-worktree.ts initializes it to null so adopted/restored panes keep today's behavior.
  • Resolve the pane agent from that command — resolveLaunchCommandPaneAgent reuses recognizeAgentProcessFromCommandLine (headless one-shot filter intact) and gates on isTuiAgent, then feeds getPaneAgentForTuiIdle and the published agentIdentity (build-pty-terminal-summary.ts, write-orchestration-pointer-pty.ts, runtime-id.ts) as a fallback behind launchAgent/foregroundAgent.
  • Retire the seeded command with launch authority — retirePtyAgentLaunchAuthority now also keys on !pty.launchCommandLine and clears it, so a pane back at a shell prompt is not mistaken for the agent.
  • Tests — new runtime-agent-launch-resolution.test.ts (5 cases: first-token recognition, headless filter, non-TuiAgent and non-agent commands) plus two runtime cases proving wait ranking/published identity see omp for omp --model x and that the identity retires on 133;D.

Verified the resolver unit tests pass locally (5/5), and traced the wait path: getPaneAgent flows into tui-idle-evidence-source.ts, which hands agent to isKnownReadyPromptBody and the agent state rules — so a flagged omp launch now takes the OMP lane instead of the agent-null quiescence fallback, which is the reported failure. The retirement-guard widening is broader than "names an agent" (any --command pane retires on its first 133;D), but 133;D is the shell wrapper reporting the foreground command ended, managed launches already reached this path via launchAgent, and the hook server's retirePaneAuthority is designed to be called there. No blocking issues.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @ggbdpq! Your commit was carried into #33466 (rebased onto current main, with identity resolved once at pane creation) and is now merged with your co-author credit. Closing this one in favor of it.

nwparker added a commit that referenced this pull request Oct 25, 2026
… TUI (#33466)

Terminals created with a flagged agent command (e.g. `omp --thinking high`) now get the agent's identity at creation, so `tui-idle` waits for the agent instead of reporting ready early.

Fixes #25264
Supersedes #25320

Co-authored-by: ggbdpq <[email protected]>
@nwparker nwparker closed this Oct 25, 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