Skip to content

fix(terminal): require agent identity for guarded sends (STA-4028) - #14092

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/sta-4028-fix
Aug 12, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/sta-4028-fix

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

ELI5

Some agents draw a little spinning circle (◐ ◑ ◒ ◓) in their terminal title while they think. We started reading that spinner as "an agent is running here," and that alone was enough to let Orca type a prompt into the pane and press Enter. But any program can draw those circles — an installer, a build script, a release tool. This PR keeps the spinner as a "something is happening" hint, but requires real proof of which program owns the pane before Orca is allowed to type into it.

What Changed

  • New shared predicate isQuarterCircleSpinnerOnlyAgentTitle(title): true when stripping the quarter circles leaves a title with no agent evidence at all.
  • OrcaRuntimeService.getTerminalAgentStatus no longer short-circuits to isRunningAgent: true for such a title; it resolves through the same identity/foreground path already used for OpenCode markers.
  • isTerminalRunningAgent / isPtyRunningAgent no longer accept a quarter-circle-only title as agent-presence evidence (via the new agentTitleProvesAgentPresence helper, which also folds in the existing OpenCode check the four call sites duplicated).

Unchanged on purpose:

Why

#13925 taught the title parser that U+25D0–U+25D3 mean "working" (Claude Code 2.1.228 swapped its busy spinner to quarter circles). That was correct as a status signal, but getTerminalAgentStatus treats any non-null title status as proof an agent owns the pane, and assertTerminalAgentSendable authorizes a guarded send on isRunningAgent. Guarded sends auto-submit with Enter, so a title like ◑ Deploying release 4.2 — from a release script, ora, or any TUI that animates those glyphs — was enough to inject a prompt and press Enter into a non-agent process.

Quarter circles are ordinary progress glyphs in a way braille dots largely are not, so the safe rule is: glyph proves activity, identity must come from the title's agent token or the foreground process. That is exactly what the pre-#13925 code did for these titles (they classified as neutral and fell through to the foreground check), so this restores the prior authorization contract without reverting the status fix.

Linked Issue

STA-4028 — https://linear.app/stably/issue/STA-4028

Fixes the regression introduced by #13925.

Visual Proof

N/A — no UI change. The rendered agent status for a quarter-circle busy title is unchanged (still working, asserted in the new test); only the main-process send-authorization decision changed.

Testing

New focused regression test: src/main/runtime/quarter-circle-title-send-authorization.test.ts, driving the real OrcaRuntimeService + assertTerminalAgentSendable:

  • ◑ Deploying release 4.2 with foreground node → isRunningAgent: false, guard throws terminal_guard_no_agent (failed before this fix)
  • same title with no readable foreground (SSH / folder-workspace case) → terminal_guard_no_agent (failed before this fix)
  • same title with foreground claude → authorized, status: working (no false-negative for a real agent)
  • ◐ Claude Code with no foreground read → authorized
  • ⠂ Deploying release 4.2 → authorized (braille behavior unchanged)
  • detectAgentStatusFromTitle still returns working for both quarter-circle titles ([Bug]: Chat UI falls back to CLI view on every message with Claude Code 2.1.228 (new busy title glyphs read as agent exit) #13889 intact)

Commands actually run on macOS (Darwin 25.5.0):

npx vitest run --config config/vitest.config.ts src/main/runtime/quarter-circle-title-send-authorization.test.ts
  → 6 passed (2 of them fail on the parent commit)
npx vitest run --config config/vitest.config.ts src/main/runtime
  → 265 files passed | 1 skipped, 3929 tests passed
npx vitest run --config config/vitest.config.ts src/shared src/main/runtime/rpc/terminal-agent-send-guard.test.ts src/renderer/src/lib/worktree-status.test.ts
  → 444 files passed | 3 skipped, 4530 tests passed
npm run typecheck   → exit 0
npm run lint        → exit 0
  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Platforms: automated tests run on macOS. The change is pure title/string classification plus an existing foreground-process lookup, with no platform-conditional code paths, so Linux/Windows behave identically; the SSH / unreadable-foreground case is covered explicitly by a test rather than a live host.

AI Disclosure

N/A (internal).

Review

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Security: this is the security fix — it removes an authorization path that let a non-agent TUI receive an auto-submitted prompt.
  • Cross-platform: no platform branches added; classification is on the OSC title string, and the foreground lookup is the existing per-host controller call.
  • Remote SSH / folder workspaces: SSH and folder-workspace panes can fail the foreground read. Those panes now refuse a guarded send when the only evidence is a quarter circle, which is the pre-fix(agent-title): treat Claude Code quarter-circle spinners as working (#13889) #13925 behavior and the intended fail-closed direction; a title naming the agent still authorizes, so agents that set a normal title are unaffected.
  • Mobile / wire: no RPC params, stream opcodes, or published payload shapes changed — only the value of an existing boolean under a narrow condition.
  • Backwards compatibility: braille spinners, OpenCode markers, Gemini glyphs, Pi synthetic titles and hook-derived status all take unchanged paths.
  • Performance: one extra regex replace + re-parse, only for titles that actually contain a quarter circle.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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 pass locally (pnpm build left to CI)

Quarter-circle spinner glyphs (U+25D0-U+25D3) started classifying a title
as "working" in #13925, and that status alone authorized guarded agent
sends — which auto-submit with Enter — into any pane whose TUI animates
those generic progress frames.

Keep the glyphs as an activity signal, but stop treating a title whose
only agent evidence is a quarter circle as proof an agent owns the pane:
send authorization now falls through to recognized-agent identity in the
title or a recognized foreground process. Braille-spinner behavior is
unchanged.
@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds quarter-circle spinner-only title detection and re-exports it through the shared agent-detection module. Runtime checks now track PTY launch incarnations and require title, foreground-process, or verified launch evidence. Regression tests cover authorization, refusal cases, replacement PTY incarnations, braille spinners, and working-status classification. Reliability-gate records document the updated behavior and test evidence.

Mergeability Score: 🟠 High · up to 069e8

The change tightens guarded terminal sends, but the current code can still authorize spinner-only titles when process identity is missing or stale launch authority survives a provider replacement. That could send and auto-submit a prompt to the wrong process, so the PR is not merge-ready until these identity checks are fixed.

🚥 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%. 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 summarizes the main change: guarded terminal sends now require agent identity.
Description check ✅ Passed The description covers the required sections, linked issue, rationale, testing, visual proof, review considerations, and checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@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

🔇 Additional comments (7)
src/main/runtime/orca-runtime.ts (3)

10-10: 🗄️ Data Integrity & Integration

⚠️ Unverified finding
Sandbox verification was unavailable.

Verify the new import resolves from the compatibility barrel.

isQuarterCircleSpinnerOnlyAgentTitle is imported from ../../shared/agent-detection. Confirm that agent-detection.ts re-exports this symbol from the module that defines spinner-only title detection (per the PR stack's dependency on "Define spinner-only title detection").


16799-16814: LGTM!

Also applies to: 37583-37608


31549-31566: LGTM!

Also applies to: 31615-31623

src/main/runtime/quarter-circle-title-send-authorization.test.ts (3)

21-90: LGTM!


137-143: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

⚠️ Unverified finding
Sandbox verification was unavailable.

Remove the duplicated ptysById property in the type cast.

The cast at lines 139-141 declares ptysById: Map<string, { launchAgent: string | null; launchToken: string | null }> three times in a row inside the same object type literal. One declaration is enough. This looks like a copy-paste artifact rather than intended code.

Keep one ptysById line in the cast.

♻️ Proposed cleanup
     expect(
       (
         runtime as unknown as {
           ptysById: Map<string, { launchAgent: string | null; launchToken: string | null }>
-          ptysById: Map<string, { launchAgent: string | null; launchToken: string | null }>
-          ptysById: Map<string, { launchAgent: string | null; launchToken: string | null }>
         }
       ).ptysById.get(PTY_ID)
     ).toMatchObject({ launchAgent: 'claude', launchToken: expect.any(String) })

Run the following to confirm the actual file content at these lines:


131-136: LGTM!

Also applies to: 144-162

config/reliability-gates.jsonc (1)

7536-7539: LGTM!

Also applies to: 7544-7556, 7558-7565, 7633-7641, 7662-7666, 7679-7679


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bb655101-54d0-4f1f-a9a0-a567859868d7

📥 Commits

Reviewing files that changed from the base of the PR and between cfcd8d6 and ceff8eb.

📒 Files selected for processing (3)
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/quarter-circle-title-send-authorization.test.ts

Comment thread config/reliability-gates.jsonc Resolved
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA (STA-4028) — both directions

Isolated dev instance from the QA canvas (ORCA_DEV_USER_DATA_PATH + CDP 9337 / renderer 5176). window.api.app.getIdentity() was Orca: brennanb2025/qa-14092-sta4028 / devRepoRoot=/Users/brennanbenson/orca/workspaces/orca/qa-14092-sta4028 before every capture. Canvas HEAD 60afb4839d contains 1aa739ff3d (cherry-picked, not pushed).

(A) DENY — spinner-only shell does not authorize

Before (looks busy, no agent owner): a plain shell emitted OSC title ◑ Deploying release 4.2. The tab shows working activity. That is the #13925 false-positive shape.

01-deny-spinner-shell-before-send.png

After (send refused): terminal.agentStatus → isRunningAgent: false. Guarded terminal.send → accepted: false, refusedReason: no-agent. Product notes send returned no-agent (“The active terminal is not a recognized agent session.”). The PTY was not injected.

02-deny-send-refused-toast.png

(B) ALLOW — real managed Claude 2.1.228 still accepts while showing ◑

This is the false-negative that would hurt users. A real Orca-launched Claude Code 2.1.228 pane went busy with title ◑ Reply with ping (isRunningAgent: true, status: working). Guarded paste of STA4028_BUSY_ALLOW_PROBE returned accepted: true and landed in the Claude composer.

04-allow-claude-busy-quarter-circle.png

Same session, earlier in the turn, for context that this is a live Claude TUI (not a mock):

03-claude-tab-current.png

(C) Braille left alone (STA-4048)

A second plain shell with OSC title ⠂ Deploying release 4.2 still authorized a guarded paste (accepted: true). Unchanged, as designed.

05-braille-spinner-still-authorized.png

Verdict: DENY and ALLOW both passed on the rendered app. No blocking regression. SSH / incarnation / unverified-launch cases were not restaged live (unit-covered).

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/runtime/orca-runtime.ts (2)

25784-25789: 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

Require a non-null incarnation before spinner-only title proof.

Legacy SSH pty.spawn replies can omit incarnationId. In that case, createTerminal stores launchIncarnationId as null, and ptyTitleProvesAgentPresence accepts null === null. Set launch authority only when pty.incarnationId is non-null, and require that value in the predicate.


10465-10493: 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

Invalidate launch authority on provider reset

When replacement output arrives before spawn reconciliation, postSpawnSequence > 0 skips resetTrackedTerminalStateForProviderGeneration. The old launch fields and pty.incarnationId then remain active, so a spinner-only title can pass for the replacement process. Providers may also omit incarnationId, making null === null pass. Require non-null matching incarnations and rebind launch authority only after the replacement identity is established.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ef141ea4-0f1f-41f3-9d69-5915b2645725

📥 Commits

Reviewing files that changed from the base of the PR and between ceff8eb and 069e8dd.

📒 Files selected for processing (3)
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/quarter-circle-title-send-authorization.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/runtime/quarter-circle-title-send-authorization.test.ts
  • config/reliability-gates.jsonc

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron UI validation (STA-4028)

Validated on the exact PR worktree via Playwright CDP (isolated ORCA_DEV_USER_DATA_PATH, CDP 9335, renderer 5175). No Computer Use / AppleScript / OS input. No product code changes.

Identity: window.api.app.getIdentity() → Orca: brennanb2025/sta-4028-fix (isDev: true, devRepoRoot: /Users/brennanbenson/orca/workspaces/orca/sta-4028-fix).

Exercised

  1. Added this worktree as a project in a fresh profile, opened it, and used the auto-created shell terminal (foreground=zsh, launchAgent=null).
  2. Set OSC title ◑ Deploying release 4.2 (quarter-circle only). Tab showed the glyph as an activity title; worktree card stayed Active (no live agent row). terminal.agentStatus → isRunningAgent: false, status: null. Guarded terminal.send with requireAgentStatus: 'sendable' → accepted: false, bytesWritten: 0, refusedReason: "no-agent".
  3. Contrast: OSC title ◐ Claude Code (names the agent). Sidebar grew a Claude Code row; isRunningAgent: true, status: working; guarded send accepted (bytesWritten: 28, enter: false). Foreground remained zsh.

Console / app logs: renderer 0 errors. Pre-existing noise only (tooltip controlled/uncontrolled, React Grab, xterm deadline, isolated-profile legacy-worker terminal_liveness_unavailable). Nothing STA-4028-specific.

Automation boundary (not fabricated): I did not launch a managed Claude and then replace the PTY incarnation, so the “verified managed-Claude identity is valid only for the matching incarnation” branch was not proven in the live UI. That remains covered by quarter-circle-title-send-authorization.test.ts. There is also no dedicated renderer toast for terminal_guard_no_agent; the refusal is a main-process send-guard result, observed here through the same runtime.call('terminal.send') path the desktop note-send UI uses.

Baseline (plain Terminal 1, Active):
02-worktree-active-plain-terminal.png

Quarter-circle-only title on a zsh pane (activity title, not treated as a sendable agent):
04-quarter-circle-title-zsh-foreground.png

Agents pane after that title — session history only, no live send target:
05-agents-pane-no-live-agent.png

Named ◐ Claude Code title contrast (Claude row appears; guarded send accepted without Enter):
06-named-claude-title-working.png

@brennanb2025
brennanb2025 merged commit cb41f3c into main Aug 12, 2026
86 of 88 checks passed
AmethystLiang pushed a commit that referenced this pull request Aug 12, 2026
…14092)

* fix(terminal): require agent identity for guarded sends (STA-4028)

Quarter-circle spinner glyphs (U+25D0-U+25D3) started classifying a title
as "working" in #13925, and that status alone authorized guarded agent
sends — which auto-submit with Enter — into any pane whose TUI animates
those generic progress frames.

Keep the glyphs as an activity signal, but stop treating a title whose
only agent evidence is a quarter circle as proof an agent owns the pane:
send authorization now falls through to recognized-agent identity in the
title or a recognized foreground process. Braille-spinner behavior is
unchanged.

* fix(terminal): preserve verified managed busy identity

* fix(terminal): bind busy identity to process incarnation

* chore(test): avoid duplicate terminal gate suite

(cherry picked from commit cb41f3c)
zpyoung pushed a commit to zpyoung/orca that referenced this pull request Aug 14, 2026
…tablyai#14092)

* fix(terminal): require agent identity for guarded sends (STA-4028)

Quarter-circle spinner glyphs (U+25D0-U+25D3) started classifying a title
as "working" in stablyai#13925, and that status alone authorized guarded agent
sends — which auto-submit with Enter — into any pane whose TUI animates
those generic progress frames.

Keep the glyphs as an activity signal, but stop treating a title whose
only agent evidence is a quarter circle as proof an agent owns the pane:
send authorization now falls through to recognized-agent identity in the
title or a recognized foreground process. Braille-spinner behavior is
unchanged.

* fix(terminal): preserve verified managed busy identity

* fix(terminal): bind busy identity to process incarnation

* chore(test): avoid duplicate terminal gate suite

(cherry picked from commit cb41f3c)
hyoteis pushed a commit to hyoteis/orca that referenced this pull request Aug 15, 2026
…tablyai#14092)

* fix(terminal): require agent identity for guarded sends (STA-4028)

Quarter-circle spinner glyphs (U+25D0-U+25D3) started classifying a title
as "working" in stablyai#13925, and that status alone authorized guarded agent
sends — which auto-submit with Enter — into any pane whose TUI animates
those generic progress frames.

Keep the glyphs as an activity signal, but stop treating a title whose
only agent evidence is a quarter circle as proof an agent owns the pane:
send authorization now falls through to recognized-agent identity in the
title or a recognized foreground process. Braille-spinner behavior is
unchanged.

* fix(terminal): preserve verified managed busy identity

* fix(terminal): bind busy identity to process incarnation

* chore(test): avoid duplicate terminal gate suite

(cherry picked from commit cb41f3c)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#14092)

* fix(terminal): require agent identity for guarded sends (STA-4028)

Quarter-circle spinner glyphs (U+25D0-U+25D3) started classifying a title
as "working" in stablyai#13925, and that status alone authorized guarded agent
sends — which auto-submit with Enter — into any pane whose TUI animates
those generic progress frames.

Keep the glyphs as an activity signal, but stop treating a title whose
only agent evidence is a quarter circle as proof an agent owns the pane:
send authorization now falls through to recognized-agent identity in the
title or a recognized foreground process. Braille-spinner behavior is
unchanged.

* fix(terminal): preserve verified managed busy identity

* fix(terminal): bind busy identity to process incarnation

* chore(test): avoid duplicate terminal gate suite
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.

1 participant