Skip to content

test(runtime): pin the fail-closed contract for bare Cursor titles - #12816

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
bbingz:fix/cursor-bare-title-guarded-sends
Aug 6, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
bbingz:fix/cursor-bare-title-guarded-sends

Conversation

@bbingz

@bbingz bbingz commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Negative result: this reverts the behavior change and lands as a tests-only regression contract.

cursor-agent's native OSC title is the bare literal Cursor Agent and never carries a status word, so it names the agent without proving one is present. Classifying it as an agent looked right, but it removes a refusal rather than adding evidence — and guarded sends auto-submit Enter, so the false positive types into the user's shell.

Behavior is now identical to base. The production diff is 6 comment lines with zero semantic tokens changed; everything else is tests.

Why the fix could not stand

  • The title tracker drops the bare native title live (src/shared/terminal-output-side-effects.ts), so main only records it when the stale-working timer strips the spinner off the synthesized ⠋ Cursor Agent. That timer fires both when Cursor parks idle and when cursor-agent exited and the shell reclaimed the pane.
  • Those two states are observationally identical — same title, same null foreground read. Driving the real assertTerminalAgentSendable: base rejects with terminal_guard_no_agent; with the change it accepts and sends text + Enter into a bare shell. Confirmed end-to-end in the running app.
  • classifyAgentTitle is also consumed by the session-tab agent-status projection, so the change reintroduced [Mobile-Beta-Feedback]: terminal icon aways loading #1437-style stuck status for dead Cursor panes.
  • A narrower variant — trust the title only when the foreground read fails — is also wrong: getForegroundProcess() returning null is the exit signal on the default local provider (src/main/providers/local-pty-provider.ts), not "unreadable".
  • hasPty, probePtyLiveness, hasChildProcesses and inspectProcess were each evaluated as corroborating signals. None separates alive-with-agent from alive-with-shell when the foreground read is unavailable.

What ships

Tests pinning every no-evidence branch fail-closed, plus a characterization test documenting how the bare title reaches main's records at all. Both tempting fixes fail loudly if reintroduced: reapplying the original change fails 8 tests; reapplying the narrower variant is caught too.

The real gap (tracked separately)

When a foreground read is genuinely unavailable — pre-v11 daemon, or the blanket catch { return null } flattening SSH/relay transport throws — guarded sends refuse any agent whose title isn't status-decorated, not just Cursor. "Cannot read" needs to stop being flattened into "nothing there" at the controller/daemon layer, so the UI can ask the user instead of the runtime guessing.

Testing

  • pnpm lint — passes
  • pnpm typecheck — passes
  • pnpm test — src/main/runtime/orca-runtime.test.ts: 1056 passed, 1 skipped. Wider: src/main/runtime/ 3723 passed, src/shared/ 4031 passed, terminal-pane/+lib/ 6761 passed.
  • Reproduced against the real cursor-agent CLI (2026.08.04) under node-pty, and end-to-end in the Electron app via the real terminal.send guard.
  • Added tests that fail when either rejected approach is reintroduced.

Screenshots

No visual change — behavior is identical to base.

detectAgentStatusFromTitle intentionally returns null for the bare
Cursor Agent title (hooks own status). classifyAgentTitle still needs
to treat that title as agent so guarded sends protect the pane.
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The runtime now accepts agent launch preferences in startup configuration and propagates them through normal and draft startup planning as overriding session options. Cursor Agent liveness checks no longer treat a bare Cursor Agent title as sufficient evidence. Runtime and service tests cover missing, stale, failed, shell-owned, wrapper, and confirmed foreground-process cases.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a detailed summary, testing results, and screenshots statement, but it omits the required AI Review Report, Security Audit, and Notes sections. Add the AI Review Report, Security Audit, and Notes sections, including explicit cross-platform compatibility coverage and any identified security or follow-up items.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly identifies the runtime test change and its fail-closed contract for bare Cursor titles.

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.

Reverts the classification change and keeps the behavior at base.

cursor-agent's native OSC title is the bare literal "Cursor Agent" and never
carries a status word, so it names the agent without proving one is present.
The title tracker drops it live (terminal-output-side-effects.ts), which means
main records it only when the stale-working timer strips the spinner off the
synthesized "⠋ Cursor Agent" — and that timer fires both when Cursor parks idle
and when cursor-agent exited and the shell reclaimed the pane. The two states
are observationally identical: same title, same null foreground read.

Classifying it as an agent therefore removes a refusal rather than adding
evidence. Guarded sends auto-submit Enter, so the false positive types into the
user's shell. A null foreground is also not "unreadable" on the default local
provider — local-pty-provider.ts returns null when the pty is gone, so a bare
identity title must not substitute for corroboration there either.

hasPty, probePtyLiveness, hasChildProcesses and inspectProcess were each checked
as corroborating signals; none separates alive-with-agent from alive-with-shell
when the foreground read is unavailable.

Tests pin every no-evidence branch fail-closed and document the mechanism, so
both tempting fixes fail loudly if reintroduced.

The real gap is at the controller/daemon layer, where "cannot read" is flattened
into "nothing there" — tracked separately.
@Jinwoo-H Jinwoo-H changed the title fix(runtime): treat bare Cursor native titles as agent for guarded sends test(runtime): pin the fail-closed contract for bare Cursor titles Aug 6, 2026

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

Thanks for re-cutting this — the underlying complaint is real and it was worth chasing down.

I reproduced it against the real cursor-agent CLI, and the result went against the fix:

  • Your premise checks out: cursor-agent's native title is the bare literal Cursor Agent and never carries a status word.
  • But the tracker drops that title live, so main only records it when the stale-working timer strips the spinner off the synthesized ⠋ Cursor Agent. That fires both when Cursor parks idle and when cursor-agent exited and the shell reclaimed the pane — same title, same null foreground read.
  • So classifying it as an agent doesn't add evidence, it removes a refusal. Driving the real send guard: base rejects with terminal_guard_no_agent; with the patch it accepts and sends text + Enter into a bare shell. I hit this end-to-end in the app too.
  • classifyAgentTitle is also consumed by the session-tab status projection, so the change reintroduced #1437-style stuck status for dead Cursor panes.

I tried a narrower version — trust the title only when the foreground read fails — and that's wrong as well: getForegroundProcess() returning null is the exit signal on the local provider, not "unreadable". hasPty, probePtyLiveness, hasChildProcesses and inspectProcess were each checked as corroboration; none separates alive-with-agent from alive-with-shell.

So I've reverted the behavior and kept your branch as the regression contract — your test is still here, inverted to assert the safe direction. Retitled to match. Your original commit is untouched; my work is one commit on top.

The real bug is one layer down: when a foreground read is genuinely unavailable, "cannot read" gets flattened into "nothing there", which refuses any agent whose title isn't status-decorated. Filed separately.

@Jinwoo-H

Jinwoo-H commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Follow-up for the underlying bug filed as #12946 — "cannot read" being flattened into "nothing there" at the controller/daemon layer.

@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

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.test.ts (1)

8555-8580: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the retained null status for the accepted bare-title case.

This test is the only one that exercises the accept path for a bare Cursor title (confirmed cursor-agent foreground). It asserts only isTerminalRunningAgent resolves true. It does not call getTerminalAgentStatus to confirm status: null.

The PR objective states that accepted panes must be "recognized as running agents while retaining a null status". No test locks in this exact status shape for the accept path. Add an assertion for getTerminalAgentStatus, matching the pattern used in the sibling refusal tests at Line 8508-8512 and Line 8543-8547.

✅ Suggested assertion to add
       foreground = 'cursor-agent'
       const terminal = (await runtime.listTerminals()).terminals[0]
       await expect(runtime.isTerminalRunningAgent(terminal.handle)).resolves.toBe(true)
+      await expect(runtime.getTerminalAgentStatus(terminal.handle)).resolves.toEqual({
+        handle: terminal.handle,
+        isRunningAgent: true,
+        status: null
+      })

Based on learnings from the PR objectives: "these panes should be recognized as running agents while retaining a null status".


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a0496183-72eb-4554-a3eb-50f0052c99e0

📥 Commits

Reviewing files that changed from the base of the PR and between f2fb03b and 82b78dc.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

Comment on lines +20960 to +20961
prompt: string | undefined,
launchPreferences?: AgentLaunchPreferences

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.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Inspect how buildAgentStartupPlan/buildAgentResumeStartupPlan/buildAgentDraftLaunchPlan consume sessionOptions.
set -euo pipefail

fd -a 'tui-agent-startup.ts' | while IFS= read -r file; do
  echo "=== $file ==="
  rg -n -C 6 'sessionOptions' "$file"
done

Repository: stablyai/orca

Length of output: 220


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Candidate files"
fd -a 'orca-runtime.ts|tui-agent-startup.ts' .

echo
echo "Orca runtime lines around toAgentSessionOptions"
file=$(fd 'orca-runtime.ts' . | head -n1)
echo "file=$file"
sed -n '20920,20995p' "$file"

echo
echo "Search sessionOptionsOverrideAgentArgs / sessionOptions across repo"
rg -n 'sessionOptionsOverrideAgentArgs|toAgentSessionOptions|buildAgentStartupPlan|buildAgentResumeStartupPlan|buildAgentDraftLaunchPlan|tui-agent-startup' .

Repository: stablyai/orca

Length of output: 27017


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "shared tui-agent-startup sessionOptions usages"
sed -n '1,130p' src/shared/tui-agent-startup.ts
echo
sed -n '180,315p' src/shared/tui-agent-startup.ts

echo
echo "shell helpers/sessionOptions and command construction"
fd -a 'tui-agent-startup-shell.ts|agent-launch-command.ts' . | while IFS= read -r file; do
  echo "=== $file ==="
  rg -n -C 8 'sessionOptions|launchCommand|spawn\(|child_process|quote|format|concat|join' "$file"
done

echo
echo "toAgentSessionOptions callers and values"
sed -n '20895,20990p' src/main/runtime/orca-runtime.ts
sed -n '24620,24690p' src/main/runtime/orca-runtime.ts
sed -n '24705,24755p' src/main/runtime/orca-runtime.ts
sed -n '24765,24792p' src/main/runtime/orca-runtime.ts
sed -n '24938,24960p' src/main/runtime/orca-runtime.ts

echo
echo "Type definitions for AgentLaunchPreferences"
rg -n 'interface AgentLaunchPreferences|type AgentLaunchPreferences|AgentLaunchPreferences\s*=' .

Repository: stablyai/orca

Length of output: 25133


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Session option launch implementation"
sed -n '1,220p' src/shared/agent-session-option-launch.ts
echo
echo "Session option related tests"
rg -n -C 6 "model|effort|mode|SessionOptionValue|quoteStartupArg|inject|commandWithOptions|sessionOptions" src/shared src/renderer mobile/src --glob '!**/*.png'

echo
echo "Agent session create operation preferences source"
sed -n '1,130p' src/renderer/src/runtime/agent-session-create-operation.ts

echo
echo "Agent launch preferences declarations"
sed -n '1,130p' src/shared/agent-session-host-authority.ts

echo
echo "Programmatic quote/startup-shape probe"
node - <<'JS'
const shell = process.platform === 'win32' ? 'powershell' : 'posix';
function quoteStartupArg(value) {
  if (shell === 'powershell') return `'${value.replace(/'/g, "''")}'`;
  return `'${value.replace(/'/g, `'\\''`)}`;
}

const maliciousModel = `a --eval "shutil" --`;
const optionSuffix = [
  '--session-option', 'model', quoteStartupArg(maliciousModel, shell),
  '--session-option', 'effort', quoteStartupArg("normal", shell),
].join(' ');

console.log({ shell, optionSuffix });
console.log("unquoted_command: \"orca\" " + optionSuffix);
console.log("tokens_for_shell: " + JSON.stringify(optionSuffix.trim().split(/\s+/)));
JS

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "$file" | sed -n '1,220p'
sed -n '1,220p' src/shared/agent-session-option-launch.ts

echo
echo "Agent launch preferences declaration"
sed -n '85,115p' src/shared/agent-session-host-authority.ts

echo
echo "Narrow quote/startup-shape probe"
node - <<'JS'
const cases = ['posix', 'powershell', 'cmd'];
for (const shell of cases) {
  function quoteStartupArg(value) {
    if (shell === 'powershell') return `'${value.replace(/'/g, "''")}'`;
    if (shell === 'cmd') return `"${value.replace(/([\^&|<>()%!"])/g, '^$1')}"`;
    return `'${value.replace(/'/g, `'\\''`)}`;
  }
  const maliciousModel = 'a --eval "python -c print(1)" --';
  const optionSuffix = [
    '--session-option', 'model', quoteStartupArg(maliciousModel, shell),
    '--session-option', 'effort', quoteStartupArg(' normal ', shell),
  ].join(' ');
  console.log(JSON.stringify({ shell, optionSuffix, command: `orca ${optionSuffix}` }));
}
JS

Repository: stablyai/orca

Length of output: 188


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "agent-session-option-launch.ts"
sed -n '1,220p' src/shared/agent-session-option-launch.ts

echo
echo "Agent launch preferences declaration"
sed -n '85,115p' src/shared/agent-session-host-authority.ts

echo
echo "Narrow quote/startup-shape probe"
node - <<'JS'
const cases = ['posix', 'powershell', 'cmd'];
for (const shell of cases) {
  function quoteStartupArg(value) {
    if (shell === 'powershell') return `'${value.replace(/'/g, "''")}'`;
    if (shell === 'cmd') return `"${value.replace(/([\^&|<>()%!"])/g, '^$1')}"`;
    return `'${value.replace(/'/g, `'\\''`)}`;
  }
  const maliciousModel = 'a --eval "python -c print(1)" --';
  const optionSuffix = [
    '--session-option', 'model', quoteStartupArg(maliciousModel, shell),
    '--session-option', 'effort', quoteStartupArg(' normal ', shell),
  ].join(' ');
  console.log(JSON.stringify({ shell, optionSuffix, command: `orca ${optionSuffix}` }));
}
JS

Repository: stablyai/orca

Length of output: 3983


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Session option catalog definitions"
fd -a 'agent-session-option-catalog.ts' . | while IFS= read -r file; do
  echo "=== $file ==="
  sed -n '1,260p' "$file"
done

echo
echo "Native chat session option types"
sed -n '1,140p' src/shared/native-chat-session-options.ts

echo
echo "Session option validation tests around options"
rg -n -C 5 'quoteStartupArg|resolveAgentSessionOptionLaunch|resolveAgentLaunchCommand|session-options|sessionOptions|validate|catalog|modelOptions|optionApply|apply.launchArgs' src/shared/tui-agent-startup-session-options.test.ts src shared src/renderer/mobile --glob '*.test.ts' --glob '*.ts' --max-count 8

Repository: stablyai/orca

Length of output: 50370


Validate session option values before they reach the agent launch command.

launchPreferences.model/effort/mode are trimmed strings that are quoted when appended to the shell command, but the quotes do not prevent shell metacharacters from being interpreted by the shell. The values should be allowed only if the session option catalog accepts them before resolveAgentSessionOptionLaunch renders shell args, or the rendered arg values should be rejected after catalog resolution before command construction.

@Jinwoo-H Jinwoo-H closed this Aug 6, 2026
@Jinwoo-H Jinwoo-H reopened this Aug 6, 2026
@Jinwoo-H
Jinwoo-H merged commit 74e1678 into stablyai:main Aug 6, 2026
@bbingz

bbingz commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@Jinwoo-H thanks for the real cursor-agent end-to-end repro — that is exactly the falsification the original direction needed, and inverting the test into a fail-closed regression contract is the right land.

Agree the remaining bug is #12946 (foreground-read unavailability flattened into "nothing there"), not title classification. Leaving that for the core path unless you want an external PR against a narrower surface.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#12816)

Reverts the classification change and keeps behavior at base.

cursor-agent's native OSC title is the bare literal "Cursor Agent" and never
carries a status word, so it names the agent without proving one is present.
The title tracker drops it live, so main records it only when the stale-working
timer strips the spinner off the synthesized "⠋ Cursor Agent" — and that fires
both when Cursor parks idle and when cursor-agent exited and the shell reclaimed
the pane. The two states are observationally identical: same title, same null
foreground read.

Classifying it as an agent therefore removes a refusal rather than adding
evidence. Guarded sends auto-submit Enter, so the false positive types into the
user's shell. A null foreground is also not "unreadable" on the default local
provider, which returns null when the pty is gone.

hasPty, probePtyLiveness, hasChildProcesses and inspectProcess were each checked
as corroborating signals; none separates alive-with-agent from alive-with-shell
when the foreground read is unavailable.

Tests pin every no-evidence branch fail-closed and document the mechanism, so
both attempted fixes fail loudly if reintroduced.

Real gap tracked in stablyai#12946.
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.

4 participants