Skip to content

fix(agent-launch): refuse a disabled agent on the chat route too - #23043

Closed
brennanb2025 wants to merge 5 commits into
mainfrom
brennanb2025/agent-launch-disabled-chat
Closed

brennanb2025 wants to merge 5 commits into
mainfrom
brennanb2025/agent-launch-disabled-chat

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​430 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​427
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​124 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116

ELI5

When you turn an agent off in Settings, Orca should refuse to start it. Terminal launches already did. Chat launches didn't: a phone (or any client) asking the host to start a turned-off agent while "open agent tabs in chat" was on got a running chat anyway. Now chat launches refuse too. The chat routes, agent.launch and the terminal-create route share one message: "Agent claude is disabled. Choose an enabled agent." Older refusals elsewhere keep their own wording.

What Changed

Before: the host checked whether an agent was enabled only on the terminal route. A launch that the host sent to a chat (agent.launch / agent.launchReplay with the chat default on, or agentSession.create, which the desktop's own new-chat path uses) started the agent even when it was turned off. Live repro: open the phone's "+" menu, turn Claude off on the desktop, tap Claude in the still-open menu with the chat default on: a Claude chat and a real claude process started.

After:

  • agent.launch checks enablement once, before it decides chat or terminal. A turned-off agent is refused before any workspace, chat or terminal is created. On agent.launchReplay the refusal is recorded as failed with the real message, so a retry of the same operation id gets the same answer and never launches. A launch that only hands a prompt to an agent already running in a terminal (reuseTerminal) is not refused, because it starts nothing.
  • The chat host's attach step, where every new chat starts its agent (agentSession.create, agentSession.ensure for a session it has never seen, /clear's fresh conversation, orchestration's chat workers), refuses to start a brand-new session for a turned-off agent, before it reserves or spawns anything. The client gets the definitive "nothing was created" refusal it already understands, carrying the user's reason as its message. /clear reports the same reason and leaves the current chat as it was. The host reads the setting on every attach through a callback it is given when it is built, so it needs no settings access of its own. That callback is required: the app refuses to install the chat host without it, the same way it already refuses without a Claude sign-in policy, because the file that wires it is not type-checked and a dropped callback would otherwise silently let new chats start turned-off agents.
  • A chat that already exists on the host is not affected: reopening, recovering, restarting or sending to it works as before. That includes the retry of a chat create that already succeeded, which is answered from the chat's record.
  • The chat-create step (agentSession.create, agent.launch's chat route, orchestration's chat workers) also refuses a new chat for a turned-off agent before it resolves the workspace, because that resolution prepares the agent's home (for Codex it marks the workspace trusted in the user's Codex settings). It asks the chat host the same question the attach step asks, through one host method (disabledAgentRefusal): the same setting reader and the same "no record means new" rule, so a retry of a committed create still reaches its record. To ask, the create step now installs the chat host before resolving the workspace instead of just after. So a create whose workspace can't be resolved, or can't host a chat, now installs it too; installing opens the host's local chat record store and starts no agent, and any chat create that gets further installs it anyway.
  • The chat routes, agent.launch and the terminal-create route throw or report one shared error, AgentDisabledLaunchError, so the message cannot drift between them. The terminal route's text is unchanged.

The chat route checks in layers on purpose. The upfront check in agent.launch refuses before anything is created. Without it, the later chat refusal would still stop the agent (the terminal fallback it triggers is refused by the terminal route's own check), but: a launch into a new workspace would create that workspace first, because in chat mode the workspace is created without a startup agent and the workspace-create check never runs; the launch would take the "host refused the chat, start a terminal instead" fallback only to fail there; and on agent.launchReplay a failure that late is recorded as outcome unknown, so the caller and every retry get "unknown" instead of failed with the real message. The attach check is the one every new chat passes, including agentSession.ensure and /clear, which never go through the create step. The create-step check only keeps a refused create from preparing the agent's home first.

Why

A turned-off agent is a user decision, so no launch path should get around it, and the refusal should say why. Checking once per entry point would miss the chat starts that don't come through agent.launch or the create step (agentSession.ensure, /clear); checking only where the chat starts its agent would leave agent.launch creating a workspace and attempting a terminal fallback before failing with an unknown outcome. So the check lives at the start of agent.launch and at the attach step where every new chat starts its agent, which already carries the host's other "can this start here" check. Refusing only brand-new sessions there keeps existing chats and retries of committed creates answered from their records, as before.

A new wire refusal code ("agent disabled") was considered and rejected: older clients check the refusal code against a fixed list, and the existing definitive code already means "the host refused and created nothing", which is exactly what happened. The message carries the reason.

Other existing refusals of a turned-off agent stay where they are, because they serve other methods: terminal creates with a startup agent (session.tabs.createTerminal, also the backstop if the setting changes between the check and the spawn), terminal.createAgentSession, worktree.create with a startup agent, the phone's older create path, session resume, and orchestration's launcher check.

Linked Issue

No linked issue.

Visual Proof

Desktop at the current head (7feaf73dbc), dev host on a separate Mac with a fresh profile, compared with main (484598b18e). Claude turned off while the new-tab menu was open, chat default on:

main: a Claude chat starts anyway This PR: refused with the reason and Retry; nothing created This PR: after turning Claude back on, Retry in the same tab starts the chat
Disabled Claude chat started on main Chat could not be started. Agent claude is disabled. Retry after re-enabling starts the chat
main: /clear in an open Claude chat after turning Claude off starts a fresh session This PR: /clear is refused with the reason; the open chat is unchanged This PR: that existing chat still answers a normal message (deliberate scope)
clear on main starts a fresh session clear refused existing chat still works

At this head the phone route (agent.launchReplay) with Claude off was refused with the real message, recorded as failed, and a replay of the same id after turning Claude back on returned that refusal and created nothing; in every refusal no tab, chat session or claude session process was created. The earlier evidence below is from 69673322ef.

Dev host built from this branch (69673322ef) on a separate Mac, with its own fresh profile, launched in the background; every scripted host call was pinned to that profile and checked its runtime id.

Before (host without this change, phone): Claude turned off while the "+" menu is open, then tapped with the chat default on — a Claude chat opens and a claude process starts After (desktop): the refused chat shows the reason, with Retry; nothing is created
Disabled Claude chat started Chat could not be started. Agent claude is disabled.

Phone (Android emulator on the same Mac as the dev host, driven only through orca emulator; phone build #22954 81e471b094). Claude turned off on the host while the "+" menu was open, then tapped:

Chat default on, empty session Chat default on, beside an open shell (toast) Chat default off, beside an open shell (toast) Control: Claude enabled → chat opens
Refusal on empty session Refusal toast, chat default on Refusal toast, chat default off Enabled Claude chat opened

In all three refusals the host's tab, terminal and chat-session lists were unchanged and no claude process started. In the control, closing the chat through the host ended its process.

  • Phone route (agent.launchReplay, the call the phone's "+" menu makes), with Claude turned off: chat default on in an empty session, chat default on beside an open shell tab, and chat default off were all refused with "Agent claude is disabled. Choose an enabled agent." In each case the host's tab and terminal lists were unchanged before and after, and no agent process started. With Claude enabled, the same call opened a chat (control).
  • Desktop new chat (agentSession.create): the desktop's new-tab menu drops a turned-off agent within about 1.5 s, so a click can't reach it (menu after turning Claude off). To exercise the path, I called the menu's own launch function in the renderer; the chat showed the refusal above, with no tab, terminal or agent session created. agentSession.create over the host connection returned structured_agent_session_unsupported with the same message.
  • Seen during QA, not changed here: opening the refused chat still runs Claude's short model-list probe (claude -p … stream-json) for under a second, from the chat's model picker. No agent session starts. The desktop also shows a generic "could not open a structured Claude chat" toast beside the specific inline reason. Also on main for any refused chat start: while the refused chat's tab stays open, the new-tab menu keeps that agent's row disabled (it treats the failed start as still in progress) until the tab is closed; and a refused /clear leaves /clear in the composer, as any command the host doesn't accept does.

Testing

  • agent-launch-disabled-agent.test.ts (real RPC handler and durable operation ledger; chat create mocked): with Claude turned off,

    • chat default on, agent.launchReplay → refused with the real message, ledger row failed with that message, no chat/terminal/workspace created; a retry of the same id after Claude is turned back on is answered from the record and creates nothing;
    • plain agent.launch → same refusal;
    • chat default off → refused before any terminal is created;
    • a launch that would create a new workspace → refused before the workspace exists;
    • a prompt handed to an already-running agent terminal (reuseTerminal) is still delivered, with nothing created;
    • a different, enabled agent still launches (control).
  • structured-agent-session-disabled-agent.test.ts (real host and record store): with Codex turned off,

    • a brand-new attach → definitive refusal with the real message, no record, no operation row, no agent started;
    • /clear on an open chat → completes with the real message as its error, no replacement chat, the open chat stays;
    • a retry of a create that already succeeded before Codex was turned off → answered from its record as a replay, no new agent started;
    • with only Claude turned off, a new Codex chat still starts (control).
  • structured-agent-session-precommit-refusal.test.ts: agentSession.create (the desktop's new-chat path) for an agent the chat host's reader reports as turned off → definitive refusal whose message is the user's reason, nothing resolved or attached, no warning logged; the retry of a create whose session the host already holds is attached, not refused. The stub host answers through the same rule the real host uses.

  • orca-runtime-structured-agent-enablement-wiring.test.ts: the app's chat host is built with a reader of the live on/off setting, and installing the host without a reader is refused. The file that wires it is not type-checked, so without these, dropping that one line would silently remove the attach check (the only one agentSession.ensure and /clear pass); removing the line fails the first test, and removing the install check fails the second.

  • Existing chat-host test setups now pass an "every agent enabled" reader, since the runtime requires one.

  • Red on main: all five refusal tests fail against main's source; the control passes. On main the terminal-default case is already refused later, by the terminal route's own check; it fails here only because the test's terminal create is a stub, and it pins that the refusal now comes first.

  • Ablations: removing only the agent.launch check fails its four tests; removing only the create-step check fails the agentSession.create test; dropping the refusal's message handling fails that test too; removing only the attach check fails the new-attach and /clear tests; making the create-step check ignore the existing record (this PR's first version) fails the committed-create retry test; removing the install check for the reader fails its test.

  • Native-chat, agent-launch, runtime, RPC and shared suites: 1297 files passed (two load timeouts in unrelated suites passed on a rerun). tc:node, oxlint, format and the changed-code gate clean.

  • After moving the rule onto the chat host: native-chat wire, structured runtime, structured RPC, agent-launch, orchestration and agent-launch-helper suites, 256 files. The only deterministic failures were test stubs of the chat host missing the new method (fixed); three unrelated suites that timed out under load passed when rerun alone. The cross-version wire harness could not extract the release checkout locally (tar timeout), so its run is left to CI; its host stub gained the new method.

  • Platforms: macOS (tests); macOS live on a separate Mac (desktop and the host route the phone uses). Android phone live (emulator on the same Mac as the dev host). iOS not run on that Mac.

  • I manually tested these changes locally

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

AI Disclosure

Review

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

  • Wire compatibility: no new fields or codes. An agent.launch caller gets an error it already handles as "not started", now with the real message on the chat route too. An agentSession.create caller gets the definitive refusal code it already treats as "nothing was created"; only the message text is more specific.
  • SSH: enablement is the desktop user's setting, read on the host that owns the launch, before any remote work, so remote workspaces are refused the same way and nothing reaches the remote host. Chats only run on the machine whose Orca hosts them; a headless Orca server builds the same chat host and reads its own settings.
  • Retry of a committed chat create: if the user turns an agent off after a chat create succeeded but before its reply arrived (a lost reply, a reloaded window), the retry is answered from the chat's record and the client gets its chat, not a refusal for a chat that exists.
  • Existing sessions of a turned-off agent (deliberate scope): this PR refuses only new sessions.
    • Sending to, reopening, restarting, recovering, or retrying a failed start of an existing chat still starts its agent.
    • /clear (which starts a fresh session) and resuming an old conversation into a new chat are refused.
    • A prompt sent into an agent terminal that is already running is delivered.
  • Setting changed mid-start: the attach check runs once, before anything is reserved. An agent turned off in the moment between that check and the spawn still starts that one chat; there is no second check after the reservation.
  • Related: fix(agent-launch): report a launch that failed before spawning as failed, with its cause #22913 moves its pre-spawn failure tests off the disabled-agent example, since that case is now refused before the terminal route.

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)

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready, with one product decision open

Head: 7feaf73dbc, rebased on current main. CI green: 30 passed, 11 skipped. Merge state clean.

Review loops. Five, with fixes pushed as they were found:

  • Loop 1: the chat check sat above where chats actually start, so /clear and agentSession.ensure could still start a turned-off agent. A retry of a chat create that had already succeeded was also told that nothing was created. Fixed by refusing at the point every new chat starts, and only for sessions that have no record yet.
  • Loop 2: nothing tested that the chat host is actually given the enablement setting. Added a wiring test.
  • Loop 3: the up-front agent.launch check refused reuseTerminal launches, which only type a prompt into an agent that is already running. They are now exempt.
  • Architecture review (after three loops that each found something): keep the design, with two adjustments. The host's enablement reader is now required and checked when the host is installed. The rule "a new session for a turned-off agent" now has one definition, shared by the create step and the attach step. The PR body was also corrected where it overstated what the early check prevents and claimed every path uses the same message.
  • Loop 5: clean.

Readiness checklist. PASS at the start and at the end of the review, with no P0, P1 or P2 findings.

Live desktop QA. A dev host on a separate Mac, with a fresh profile, run on main and on this branch. Screenshots are in the Visual Proof section of the PR body.

  • Desktop new chat, Claude turned off. main starts a chat and a claude process. This branch shows "Chat could not be started. Agent claude is disabled. Choose an enabled agent." with Retry, and creates no session and no process.
  • Phone route (agent.launchReplay). Refused with the real message and recorded as failed. Replaying the same id after turning Claude back on returns that refusal and creates nothing.
  • /clear after turning Claude off. main starts a fresh session. This branch shows the reason and leaves the open chat unchanged.
  • Retry. Pressing Retry after turning Claude back on starts the chat in the same tab. Pressing it while Claude is still off stays refused.
  • Control. With Claude enabled, a chat starts normally.
  • Existing chat. An open chat still answers a normal message after Claude is turned off.

Open product decision (existing sessions). This PR only refuses new sessions. Existing chats of a turned-off agent keep working: sending, reopening, restarting, recovery, and Retry of a start that failed for some other reason. That means /clear, which starts a fresh session, is refused in a chat that otherwise still works, while resuming a turned-off agent from terminal session history is already refused on main. Whether existing chats should also stop is a separate call.

Also seen during QA, already on main, not changed here:

  • A generic "could not open a structured Claude chat" toast appears beside the specific inline reason.
  • While a refused chat's tab is open, the new-tab menu keeps that agent's row disabled, even after the agent is turned back on. The tab's Retry works; closing the tab clears the row.
  • A refused /clear stays in the composer.
  • The refused chat's model picker runs a short model-list probe.

@brennanb2025
brennanb2025 marked this pull request as ready for review September 27, 2026 21:22
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

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: 85415db7-0a96-4aa6-b18d-c23c46246b43

📥 Commits

Reviewing files that changed from the base of the PR and between 7feaf73 and 5d30c1a.

📒 Files selected for processing (1)
  • src/main/runtime/rpc/methods/agent-launch.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 change adds runtime-specific agent enablement checks and a shared disabled-agent error. Agent launches and structured-session attachment or creation now refuse disabled agents in the covered paths. Recorded sessions remain eligible for attachment, and terminal reuse skips the launch check. The runtime requires an enablement reader for structured-session host installation. Tests cover refusal timing, replay, existing sessions, and enabled-agent cases.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 5d30c

A failed settings read can leave disabled-agent enforcement ineffective. Merge with owner awareness of this bounded failure mode.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 5d30c

The change closes a path that could start a turned-off agent through chat. Review found no demonstrated new security exposure, but a setting changed during an in-flight launch may not be enforced at the final creation step.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The controlled outcome is creation of an agent process and its chat, terminal, or workspace state on the host. The inspected change narrows that outcome for disabled agents; it does not establish a change to tenant, infrastructure, or secret authority.

Trust Boundaries and Controls

  • observed — The host checks the requested agent against runtime settings before a new launch reaches either creation route. The structured-session check separately protects its other creation callers.

Resilience and Maintainability Implications

  • inferred — An enablement change during structured-session reservation could leave the initial decision stale before acquisition. The inspected flow shows no atomic coupling or second enablement check, but this is a residual limit on a newly added control, not evidence that this PR worsens the prior exposure.

Hardening Proposals

  • proposed — If disabling an agent must stop every not-yet-acquired new session, recheck enablement at the reservation effect boundary and settle any reservation rejected there.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 26 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: disabled agents are now refused on the chat route.
Description check ✅ Passed The description is comprehensive and covers the user impact, implementation, rationale, testing, visual proof, compatibility considerations, and checklist. It states that no linked issue exists and le…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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: 14d7a958-b31d-47da-a498-fe7140306ef5

📥 Commits

Reviewing files that changed from the base of the PR and between 484598b and 7feaf73.

📒 Files selected for processing (26)
  • src/main/agent-launch/agent-launch-enablement.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-orchestration.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-disabled-agent-refusal.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-disabled-agent.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-types.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
  • src/main/runtime/claude-structured-session-integration.test.ts
  • src/main/runtime/orca-runtime-get-worktree-ps.ts
  • src/main/runtime/orca-runtime-resolve-worktree-removal-target.ts
  • src/main/runtime/orca-runtime-structured-agent-enablement-wiring.test.ts
  • src/main/runtime/rpc/methods/agent-launch-disabled-agent.test.ts
  • src/main/runtime/rpc/methods/agent-launch.ts
  • src/main/runtime/rpc/methods/orchestration/worker/structured-worker-launch-seed-options.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-create.ts
  • src/main/runtime/rpc/methods/structured-agent-session-precommit-refusal.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-precommit-refusal.ts
  • src/main/runtime/rpc/methods/structured-agent-session-rpc.test-fixture.ts
  • src/main/runtime/structured-agent-session-integration-replay.test.ts
  • src/main/runtime/structured-agent-session-integration.test.ts
  • src/main/runtime/structured-agent-session-runtime-exit.test.ts
  • src/main/runtime/structured-agent-session-runtime.test.ts
  • src/main/runtime/structured-agent-session-runtime.ts
  • src/main/runtime/structured-claude-scripted-runtime-test-support.ts
  • src/shared/agent-disabled-launch-refusal.ts
  • tests/e2e/cross-version-wire/structured-agent-session-host-fixture.ts

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

Comment on lines +7 to +18
export function isAgentEnabledForRuntime(
runtime: Pick<OrcaRuntimeService, 'getClientSettings'>,
agent: TuiAgent
): boolean {
let disabled: Iterable<unknown> | undefined
try {
disabled = runtime.getClientSettings().disabledTuiAgents
} catch {
return true
}
return isTuiAgentEnabled(agent, disabled)
}

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:

rg -n 'getClientSettings\s*\(' src/main/runtime src/main/agent-launch | head -90
rg -n 'prepareStructuredAgentSessionCreateForWorktree|resolveUnlaunchedIntent|performAttach|disabledAgentRefusal' src/main/runtime/rpc/methods/structured-agent-session-create.ts src/main/runtime/rpc/methods/agent-launch.ts src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
sed -n '75,140p' src/main/runtime/rpc/methods/structured-agent-session-create.ts
sed -n '120,250p' src/main/runtime/rpc/methods/agent-launch.ts

Repository: stablyai/orca

Length of output: 11941


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- settings getter and nearby runtime state ---'
sed -n '150,225p' src/main/runtime/orca-runtime-pty-foreground-process-reads.ts
printf '%s\n' '--- enablement and host reader bindings ---'
sed -n '1,90p' src/main/agent-launch/agent-launch-enablement.ts
sed -n '135,190p' src/main/runtime/orca-runtime-get-worktree-ps.ts
rg -n 'disabledAgentRefusal|isAgentEnabled|structured-agent-session-runtime|createStructuredAgent|attachStructuredAgent|executeAgentLaunch|agentLaunchIntent' src/main/native-chat src/main/runtime src/main/agent-launch
printf '%s\n' '--- structured session host/runtime definitions ---'
fd -i 'structured-agent-session-runtime|structured-agent-session-create|structured-agent-session-attach-flow' src/main
for f in $(fd -i 'structured-agent-session-runtime|structured-agent-session-create' src/main); do
  echo "--- $f ---"
  wc -l "$f"
  rg -n 'isAgentEnabled|disabledAgentRefusal|create|attach|launch|throw|settings' "$f"
done
printf '%s\n' '--- structured session create and attach implementation ---'
sed -n '1,230p' src/main/runtime/rpc/methods/structured-agent-session-create.ts
sed -n '1,180p' src/main/native-chat/agent-session-wire/structured-agent-session-attach-flow.ts
printf '%s\n' '--- launch execution definitions and relevant callers ---'
rg -n 'function executeAgentLaunch|async function executeAgentLaunch|executeAgentLaunch\\(|agentLaunchSurfaceFactory|runAgentLaunch' src/main
for f in $(rg -l 'function executeAgentLaunch|async function executeAgentLaunch' src/main); do
  echo "--- $f ---"
  rg -n -A120 -B20 'function executeAgentLaunch|async function executeAgentLaunch' "$f"
done

Repository: stablyai/orca

Length of output: 42455


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- client settings binding and getter ---'
rg -n -C 8 'clientSettings|class .*ClientSettings|function .*ClientSettings|get\(\)' src/main/runtime --glob '*.ts' | head -240
printf '%s\n' '--- structured disabled-agent refusal ---'
sed -n '175,215p' src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
sed -n '1,100p' src/main/native-chat/agent-session-wire/structured-agent-session-disabled-agent-refusal.ts
printf '%s\n' '--- structured runtime install and required readers ---'
sed -n '75,115p' src/main/runtime/structured-agent-session-runtime.ts
sed -n '190,215p' src/main/runtime/structured-agent-session-runtime.ts
sed -n '305,328p' src/main/runtime/structured-agent-session-runtime.ts
printf '%s\n' '--- launch executor ---'
sed -n '1,220p' src/main/agent-launch/agent-launch-executor.ts
printf '%s\n' '--- launch surface factories ---'
sed -n '1,220p' src/main/agent-launch/agent-launch-surface-factories.ts

Repository: stablyai/orca

Length of output: 42685


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- runtime client settings controller ---'
wc -l src/main/runtime/runtime-client-settings.ts
sed -n '1,260p' src/main/runtime/runtime-client-settings.ts
printf '%s\n' '--- launch mode resolver ---'
sed -n '220,285p' src/main/agent-launch/agent-launch-mode.ts
printf '%s\n' '--- executor remainder ---'
sed -n '200,430p' src/main/agent-launch/agent-launch-executor.ts
printf '%s\n' '--- runtime store accessors used by structured host ---'
rg -n -C 4 'requireStore\\(|getSettings\\(' src/main/runtime/orca-runtime*.ts src/main/runtime/structured-agent-session-runtime.ts | head -220

Repository: stablyai/orca

Length of output: 18146


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- launch mode defaults and decision ---'
sed -n '1,230p' src/main/agent-launch/agent-launch-mode.ts
printf '%s\n' '--- structured create intent and runtime store access ---'
rg -n -C 8 'resolveStructuredAgentSessionCreateIntent|requireStore\\b|clientSettings =|new RuntimeClientSettingsController' src/main/runtime src/main | head -260
printf '%s\n' '--- host acquisition settings reads ---'
rg -n -C 6 'resolveLaunchEnvOverlay|resolveClaudeLaunchEnv|resolveShellEnvironmentPolicy|resolveClaudeAuthPolicy|resolveClaudePermissionMode|resolveCodexPermissionPolicy|getClaudeManagedAccountGateSettings|resolveAgentAccountHome' src/main/native-chat src/main/runtime --glob '*.ts' | head -300
printf '%s\n' '--- host installation and structured create RPC binding ---'
rg -n -C 10 'createStructuredAgentSessionForWorktree|prepareStructuredAgentSessionCreateForWorktree|ensureStructuredAgentSessionHost\\(' src/main/runtime/rpc src/main/runtime src/main/native-chat --glob '*.ts' | head -300

Repository: stablyai/orca

Length of output: 42443


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- runtime store/controller construction ---'
rg -n -C 10 'new RuntimeClientSettingsController|protected readonly store|requireStore\\(\\)|constructor\\(' src/main/runtime/orca-runtime-runtime-id.ts src/main/runtime/orca-runtime*.ts | head -260
printf '%s\n' '--- projection helper implementations ---'
rg -n -C 12 'function getHostDisplayLabelOverrides|export .*getHostDisplayLabelOverrides|function isArtifactSharingEnabled|function isAgentSkillSharingEnabled' src/shared src/main --glob '*.ts' | head -240

Repository: stablyai/orca

Length of output: 5344


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- controller construction references ---'
rg -n 'RuntimeClientSettingsController' src/main/runtime
printf '%s\n' '--- runtime id constructor and store accessor ---'
sed -n '50,145p' src/main/runtime/orca-runtime-runtime-id.ts
printf '%s\n' '--- requireStore definitions ---'
rg -n 'requireStore' src/main/runtime --glob '*.ts'

Repository: stablyai/orca

Length of output: 18460


🏁 Script executed:

#!/bin/bash
set -e
sed -n '185,210p' src/main/runtime/orca-runtime-state-fields.ts
sed -n '160,185p' src/main/runtime/orca-runtime-resolve-worktree-selector.ts

Repository: stablyai/orca

Length of output: 2277


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- agent launch intent and settings reads ---'
rg -n -C 10 'function agentLaunchIntent|async function agentLaunchIntent|agentLaunchIntent\\(' src/main/agent-launch src/main/runtime/rpc/methods/agent-launch.ts
printf '%s\n' '--- launch surface factory bindings ---'
rg -n -C 12 'createTerminalAgent:|createStructuredSession:|agentLaunchSurfaceFactory|AgentLaunchSurfaceFactory' src/main/runtime src/main/agent-launch --glob '*.ts'
printf '%s\n' '--- terminal creation implementations ---'
rg -n -C 15 'createTerminalAgent|createTerminal|spawn.*Agent|startupAgent' src/main/runtime src/main/agent-launch --glob '*.ts' | head -360

Repository: stablyai/orca

Length of output: 338


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- launch intent symbols ---'
rg -n 'agentLaunchIntent' src/main
rg -n 'createTerminalAgent' src/main
rg -n 'createStructuredSession' src/main
printf '%s\n' '--- matched context ---'
for f in $(rg -l 'agentLaunchIntent' src/main); do
  echo "--- $f ---"
  rg -n -A80 -B20 'agentLaunchIntent' "$f"
done
for f in $(rg -l 'createTerminalAgent' src/main); do
  echo "--- $f ---"
  rg -n -A100 -B25 'createTerminalAgent' "$f"
done

Repository: stablyai/orca

Length of output: 42179


🏁 Script executed:

#!/bin/bash
set -e
rg -n 'createTerminal' src/main/runtime --glob '*.ts' | head -120
for f in $(rg -l 'createTerminal' src/main/runtime --glob '*.ts' | head -20); do
  echo "--- $f ---"
  rg -n -A90 -B20 'createTerminal' "$f" | head -180
done

Repository: stablyai/orca

Length of output: 42277


🏁 Script executed:

#!/bin/bash
set -e
wc -l src/main/runtime/orca-runtime-create-terminal.ts
sed -n '1,180p' src/main/runtime/orca-runtime-create-terminal.ts
sed -n '180,310p' src/main/runtime/orca-runtime-create-terminal.ts

Repository: stablyai/orca

Length of output: 13885


Fail closed when client settings are unreadable.

isAgentEnabledForRuntime returns true after getClientSettings() throws. This skips the disabled-agent refusal for structured attach and agent.launch. agent.launch then falls back to terminal mode when mode settings are unavailable. If the settings read recovers before the later surface or provider read, a disabled agent can start. The absent-store case fails later, but it does not make this fallback safe for transient read failures.

Return false when settings cannot be read.

Suggested fix
   } catch {
-    return true
+    return false
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function isAgentEnabledForRuntime(
runtime: Pick<OrcaRuntimeService, 'getClientSettings'>,
agent: TuiAgent
): boolean {
let disabled: Iterable<unknown> | undefined
try {
disabled = runtime.getClientSettings().disabledTuiAgents
} catch {
return true
}
return isTuiAgentEnabled(agent, disabled)
}
export function isAgentEnabledForRuntime(
runtime: Pick<OrcaRuntimeService, 'getClientSettings'>,
agent: TuiAgent
): boolean {
let disabled: Iterable<unknown> | undefined
try {
disabled = runtime.getClientSettings().disabledTuiAgents
} catch {
return false
}
return isTuiAgentEnabled(agent, disabled)
}

@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

  • Shared refusal — AgentDisabledLaunchError / refuseDisabledAgentLaunch (src/shared/agent-disabled-launch-refusal.ts) give the chat and terminal routes one message: Agent <agent> is disabled. Choose an enabled agent.
  • agent.launch / agent.launchReplay — resolveUnlaunchedIntent refuses a disabled agent before the surface decision, except for reuseTerminal (which delivers to an already-running agent and starts nothing). A replay-safe refusal settles the ledger row failed with the real message, so a retry replays it instead of launching.
  • Chat host attach step — structuredAgentSessionDisabledAgentRefusal refuses only a session with no record, so agentSession.create, agentSession.ensure, /clear, and orchestration chat workers cannot start a turned-off agent, while existing chats and committed-create retries still resolve from their records (structured-agent-session-attach-flow.ts:96-103).
  • Create-step ordering — agentSession.create's prepare step now installs the host first and asks host.disabledAgentRefusal before intent resolution, so a refused create cannot prepare the agent's home; AgentDisabledLaunchError maps to the existing definitive structured_agent_session_unsupported refusal (structured-agent-session-precommit-refusal.ts:45-48).
  • Runtime plumbing — isAgentEnabled is now a required runtime dep, asserted at install (structured-agent-session-runtime.ts:200-203) and wired to a live reader of disabledTuiAgents (orca-runtime-get-worktree-ps.ts:166); the terminal route was refactored onto the shared helper with its message unchanged.
  • Tests — new attach/create/launch refusal suites plus stub and fixture updates; the wiring test pins the live setting read and the install-time requirement.

I traced the intent-coverage, create-step reorder, and refusal-code handling paths. The existing terminal fallback on a definitive structured refusal is unreachable for a disabled agent (the upfront check fires first, and the terminal lane refuses independently), and other new-session entry points retain their own guards. No blocking concerns.

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

Only the terminal route checked whether an agent was enabled, so a launch the
host routed to a chat, and agentSession.create, started a turned-off agent.
agent.launch now refuses before it picks a route, and the shared chat-create
step refuses before it commits; both throw the terminal route's error.
…arts

Every new structured chat (create, ensure, /clear) starts its provider in
attach, so attach now refuses a brand-new session for an agent the user
turned off, before anything is reserved or spawned. The create path keeps
its earlier check, now skipped for a session that already has a record, so
the retry of a committed create is answered from that record.
… agent

A reused terminal starts nothing; its agent was already running, so the
launch-time enablement refusal must not stop a prompt reaching it.
…'s new chat

The chat host now owns the single rule for "a new session for an agent the
user turned off": the create step and the attach step both ask it, so both
read the same setting reader and the same no-record-means-new rule. The
runtime requires that reader and refuses to install the chat host without
it, since the file that wires it is not type-checked.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-launch-disabled-chat branch from 7feaf73 to 5d30c1a Compare September 28, 2026 03:06
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: disabling an agent is meant to hide it from the places you start agents (see #2972 / #2907), not to block launching it. Refusing a chat that is already open, or /clear inside one, is the wrong model for that setting. The launch menus already filter disabled agents.

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