Skip to content

refactor(agent-launch): make the launch-mode decision surface-neutral - #19848

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/agent-launch-mode
Sep 15, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/agent-launch-mode

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​144 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​144
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​248 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​248

ELI5

There is one question — "should this agent open as a chat, or as a terminal?" — and the code that answers it lives inside orchestration's folder, speaking orchestration's words, where other parts of the app cannot use it. This PR writes a neutral home for that question so everyone can eventually ask it. Orchestration is not moved onto it here: its copy stays exactly where it is, so for now the same policy exists in two places.

Stack: 1 of 5. This PR alone changes no behavior.

What Changed

Two files, both purely added. Nothing is moved, deleted, or rewritten.

  • Adds src/main/agent-launch/agent-launch-mode.ts (+248) — the decision in surface-neutral form, with the receipt noun parameterized so a phone does not read "worker". It has no callers in this PR.
  • Adds orchestration-worker-start-receipt-wording.test.ts (+140), pinning the exact receipt sentences of orchestration-worker-start-mode.ts.
  • src/main/runtime/rpc/methods/orchestration-worker-start-mode.ts is untouched — byte-identical to main (blob 92dc5c644a89, 217 lines). It does not shrink, does not become an adapter, and re-exports nothing.

Two copies exist as of this PR

This is the honest state a reviewer should merge with, not a migration:

  • The modules are parallel twins — WorkerStartMode↔AgentLaunchMode, WorkerStartModeReceipt↔AgentLaunchModeReceipt, decideWorkerStartMode↔decideAgentLaunchMode, downgradeWorkerStartModeForHost↔downgradeAgentLaunchModeForHost, readWorkerStartModeSettings↔readAgentLaunchModeSettings — with identical ten-member reason vocabularies in the same order.
  • Orchestration's copy imports nothing from agent-launch/, and nothing enforces that the two agree. A reason added to one can silently diverge from the other.
  • The new test exercises orchestration's module only. agent-launch-mode.ts has no test and no importer in this PR.

The cutover — orchestration reduced to a thin adapter over the shared module — is later stack work (PRs 4–5, which do not exist yet). Do not merge this believing orchestration is already migrated.

Why

A worker is not a special kind of launch — it is the same launch with a dispatch attached. The only thing orchestration genuinely contributes to this decision is the noun in the receipt ("worker") and the --terminal wording, which reads as nonsense on a surface where no --terminal flag exists. That is why the neutral module parameterizes the vocabulary: so the later cutover can keep orchestration's wording without keeping orchestration's copy of the policy.

This is groundwork for the rest of the stack, where mobile and the CLI ask the same question instead of each routing for themselves.

Why the new test

The receipt wording was not pinned by anything. The vocabulary was corrupted deliberately and all six candidate suites stayed green:

  • orchestration-worker-start-mode.test.ts asserts toContain('terminal agent') — the corrupted string 'ABLATION terminal agent worker' still contains it.
  • orchestration-worker-cli.test.ts asserts the full sentence, but against a receipt handed to it by a mock rather than one this code produced.

A dispatch receipt is the only place a structured-to-terminal downgrade explains itself, so the whole sentence is the contract, not a fragment of it.

Linked Issue

Fixes #

Visual Proof

N/A — no UI and no behavior change. Both files are additions and neither is reachable from a running surface: the new module has no callers, and the new test only asserts sentences orchestration already produced.

Testing

Verified at head 1dd74f6309:

  • New pin: 11/11 passing, covering every reachable receipt of orchestration-worker-start-mode.ts. Because that module is unchanged by this PR, the pin is a characterization test of existing behavior — it locks today's sentences rather than proving a migration preserved them.
  • pnpm tc clean; oxlint clean; changed-code quality gate 0 findings across all six scans.
  • CI on this head: 28 checks — 17 pass, 0 fail, 0 pending, 11 skipping.

Not re-verified at this head, and carried over from the original authoring: the claim that ablating the vocabulary reddens 9 of 11, and the "81 tests across 6 files" affected-set count.

Platforms: macOS. No platform-dependent code paths touched.

  • 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

Security: no new surface. Cross-platform: no platform-dependent paths. Remote SSH: the remote_execution_host downgrade reason and its wording are preserved exactly. Mobile: untouched by this PR. Backwards compatibility: no wire change, no capability change, no RPC change. Performance: neutral.

Duplication is the known cost of this step and is intentional for reviewability; it is discharged by PRs 4–5, not by this one.

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, and pnpm build pass (or CI will cover; local preferred)

`decideWorkerStartMode` was the only shared answer to "structured chat session
or terminal agent?", but it lived in an orchestration-named module and spoke
orchestration's vocabulary, so the other launch surfaces could not call it.
Move the decision to `main/agent-launch/agent-launch-mode` unchanged and leave
`orchestration-worker-start-mode` as the adapter that supplies the noun.

A worker is not a special kind of launch; it is the same launch with a dispatch
attached. Naming the receipt's subject is the only thing orchestration actually
contributed, so that is the only thing the adapter keeps: "worker" in both
sentences, plus the `--terminal` wording, which reads as nonsense anywhere a
`--terminal` flag does not exist. Both are pinned, because they are asserted.

No behavior change. The receipts are byte-identical for every reachable case,
proven by running the new pin against both implementations.

Also pins the wording, which nothing was holding. The existing suites assert
`toContain` fragments ('terminal agent', 'cannot create') and the CLI suite
asserts a receipt handed to it by a mock rather than one this code produced;
all six files stayed green against a deliberately corrupted vocabulary. A
dispatch receipt is the only place a structured-to-terminal downgrade explains
itself, so the whole sentence is the contract, not a fragment of it.

@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

  • Extract shared launch-mode decision — moves decideWorkerStartMode and its host-resolution half into src/main/agent-launch/agent-launch-mode.ts (decideAgentLaunchMode, resolveAgentLaunchModeOnHost, downgradeAgentLaunchModeForHost, readAgentLaunchModeSettings), parameterizing the receipt noun and per-reason wording through AgentLaunchModeVocabulary.
  • Thin orchestration adapter — orchestration-worker-start-mode.ts re-exports the old names and contributes only WORKER_START_VOCABULARY ("…worker" nouns plus detailOverrides for remote_execution_host and reused_terminal), preserving the --terminal and "worker" wording.
  • Receipt-wording pin — new orchestration-worker-start-receipt-wording.test.ts asserts 11 exact receipt sentences that were previously unpinned.

I verified the receipts are byte-identical: the old orchestration wording differed from the neutral defaults only on remote_execution_host and reused_terminal, exactly the two reasons the adapter overrides. The decision mappings (BLOCKER_REASON, HOST_SUPPORT_REASON, resolveStructuredNativeChatSupport input) moved verbatim, and every old export is re-exported so no caller breaks. The new test is load-bearing by construction — it toEquals full detail strings rather than toContain fragments — and the affected suites pass (36/36 across the new pin and the existing mode test).

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

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 48376083-9cb1-4e1d-826c-0585de8f934c

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd74f6 and 7a72fc0.

📒 Files selected for processing (1)
  • src/main/runtime/rpc/methods/orchestration-worker-start-receipt-wording.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/rpc/methods/orchestration-worker-start-receipt-wording.test.ts

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


📝 Walkthrough

Walkthrough

The pull request adds a launch-mode module for structured and terminal agent sessions. It produces receipts with the selected mode, preference, reason, and detail. The decision runs before workspace resolution and then applies host support results. Settings reads return null when the runtime call fails. New tests pin complete receipt wording for default modes, downgrade reasons, host outcomes, and settled terminal receipts.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 7a72f

No concrete merge-blocking issue remains established.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed and covers the required sections, testing, scope, platform impact, and visual proof. However, the required Linked Issue entry is missing: it contains Fixes # and states t… Provide a valid linked issue after Fixes #. If no issue exists, create one before merging and update the description with its issue number.
✅ Passed checks (3 passed)
Check name Status Explanation
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 main change: introducing a surface-neutral agent launch-mode decision. It is accurate for the added module, although the orchestration migration is not completed in th…
Full details: Description check

Explanation

The description is detailed and covers the required sections, testing, scope, platform impact, and visual proof. However, the required Linked Issue entry is missing: it contains Fixes # and states that no issue was filed.

  • Fix all pre-merge checks with AI
✨ 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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b5d309c6-8531-410e-91f4-18031a15dac1

📥 Commits

Reviewing files that changed from the base of the PR and between dda103d and f34d08a.

📒 Files selected for processing (3)
  • src/main/agent-launch/agent-launch-mode.ts
  • src/main/runtime/rpc/methods/orchestration-worker-start-mode.ts
  • src/main/runtime/rpc/methods/orchestration-worker-start-receipt-wording.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment on lines +24 to +26
export type WorkerStartMode = AgentLaunchMode
export type WorkerStartModeReason = AgentLaunchModeReason
export type WorkerStartModeReceipt = AgentLaunchModeReceipt

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Restore the WorkerStartModeSettings export.

The adapter no longer exports the existing WorkerStartModeSettings name. Existing consumers that import this type will fail type checking.

Add an alias and retain it in the worker-facing signatures. This keeps the adapter API stable as required by the PR objective.

Proposed fix
 export type WorkerStartMode = AgentLaunchMode
 export type WorkerStartModeReason = AgentLaunchModeReason
 export type WorkerStartModeReceipt = AgentLaunchModeReceipt
+export type WorkerStartModeSettings = AgentLaunchModeSettings

 export function decideWorkerStartMode(args: {
   params: WorkerStartModePlacement
-  settings: AgentLaunchModeSettings | null | undefined
+  settings: WorkerStartModeSettings | null | undefined
 }): WorkerStartModeReceipt {

 export function readWorkerStartModeSettings(
   runtime: Pick<OrcaRuntimeService, 'getClientSettings'>
-): AgentLaunchModeSettings | null {
+): WorkerStartModeSettings | null {

Also applies to: 53-53, 80-80

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review completed.

  • No unresolved merge conflicts; worktree is clean.
  • Targeted receipt-wording tests pass (11/11).
  • Node typecheck passes (pnpm tc:node).
  • Readiness review found no proven P0/P1/P2 issues; the refactor preserves launch-mode behavior and keeps orchestration wording in its adapter.
  • Electron validation was attempted with background launch and CDP, but the endpoint never became available, so no screenshot evidence was captured.

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

Caution

The origin/main merge (9b5188c) reverted the refactor of orchestration-worker-start-mode.ts, so this PR no longer does what it claims: the surface-neutral decision module it introduces is now orphaned dead code, and the typecheck is red.

Reviewed changes

  • Merged origin/main — brought the branch up to date, but the merge resolved orchestration-worker-start-mode.ts back to its pre-refactor form and pulled in an unrelated console.log reformat in tests/e2e/worktree-switch-first-paint.spec.ts.

🚨 The merge undid the refactor, leaving the new decision module orphaned

The merge commit reverted orchestration-worker-start-mode.ts to its original 217-line form (inline decision logic, orchestration vocabulary), while src/main/agent-launch/agent-launch-mode.ts (248 lines) remains in the tree as a new file. Nothing imports it — a repo-wide search finds zero references outside a comment. The decision is back to living inside the orchestration module, which is exactly the state this PR exists to change, and the new orchestration-worker-start-receipt-wording.test.ts now imports decideWorkerStartMode/downgradeWorkerStartModeForHost from the reverted module, so it pins the old code while its own doc comment claims the decision "moved to main/agent-launch/agent-launch-mode".

Technical details
# Restore the refactor lost in the merge

## Affected sites
- `src/main/runtime/rpc/methods/orchestration-worker-start-mode.ts` — reverted to the pre-refactor implementation; should be the thin adapter that re-exports the `WorkerStart*` names and supplies `WORKER_START_VOCABULARY`.
- `src/main/agent-launch/agent-launch-mode.ts` — new module, currently orphaned (no importers).
- `src/main/runtime/rpc/methods/orchestration-worker-start-receipt-wording.test.ts` — currently asserts the reverted module's output, not the new module's.

## Required outcome
- The `orchestration-worker-start-mode.ts` adapter (as it existed at `f34d08a`) is restored so it imports and delegates to `agent-launch-mode`.
- `agent-launch-mode.ts` has at least one real consumer.

## Open questions for the human
- Was the merge conflict resolved by taking `main`'s version of the file? If so, re-apply the adapter change on top.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…son map

main removed the draft-prompt blocker in #19681 (a structured session now holds
an unsent draft), so the exhaustive Record no longer typechecks.
…cast

The type-assertion gate landed after this branch's base, so the new file's
copy of the worker-start cast is now a changed-code finding.

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

Important

The new commits fix the stale 'draft-prompt' entry, and the typecheck is green again. But the prior review's central requested change — restoring the refactor the merge reverted — is still absent. orchestration-worker-start-mode.ts remains main's original, so agent-launch-mode.ts is orphaned and this PR does not yet do what its title and body claim.

Reviewed changes

  • Fixed the stale 'draft-prompt' entry — dropped it from BLOCKER_REASON in agent-launch-mode.ts; tsc --noEmit -p config/tsconfig.node.json now exits clean.
  • Carried a SAFETY: rationale on the placement.agent as TuiAgent cast.
  • Reverted the unrelated tests/e2e/worktree-switch-first-paint.spec.ts console.log reformat pulled in by the earlier merge.
  • Merged origin/main forward (base is now 18d0afc).

⚠️ The refactor is still missing, so agent-launch-mode has no consumer

src/main/runtime/rpc/methods/orchestration-worker-start-mode.ts is unchanged from main — the same 217-line implementation with inline decision logic and orchestration vocabulary, no import of agent-launch-mode and no WORKER_START_VOCABULARY. A repo-wide search for agent-launch-mode finds only the new test's doc comment, so the 248-line module is dead code. The new orchestration-worker-start-receipt-wording.test.ts imports decideWorkerStartMode/downgradeWorkerStartModeForHost from that reverted module, so it still passes against main's existing code, and its own comment ("the decision moved to main/agent-launch/agent-launch-mode") is false. Net effect of the PR today is two added files, one of them unreferenced.

Technical details
# Restore the orchestration adapter lost in the merge

## Affected sites
- `src/main/runtime/rpc/methods/orchestration-worker-start-mode.ts` — still the pre-refactor implementation; should be the thin adapter as of `f34d08a`: import `decideAgentLaunchMode`, `downgradeAgentLaunchModeForHost`, `readAgentLaunchModeSettings`, `resolveAgentLaunchModeOnHost` from `../../../agent-launch/agent-launch-mode`, re-export the `WorkerStart*` names as aliases of the `AgentLaunchMode*` types, and export `WORKER_START_VOCABULARY` (`structured: 'a structured chat session worker'`, `terminal: 'a terminal agent worker'`, `detailOverrides` for `remote_execution_host` and `reused_terminal`).
- `src/main/agent-launch/agent-launch-mode.ts` — new module, currently zero importers.
- `src/main/runtime/rpc/methods/orchestration-worker-start-receipt-wording.test.ts` — pins the reverted module's output; will exercise the new module once the adapter is re-applied.

## Required outcome
- `orchestration-worker-start-mode.ts` delegates to `agent-launch-mode` and is the module's consumer.
- The receipts stay byte-identical to `main`'s (the new pin covers this), so the move remains behavior-preserving.

## Suggested approach (optional)
Re-apply the `f34d08a` version of `orchestration-worker-start-mode.ts` on top of the current tree; the merge conflict was resolved by taking `main`'s side, so nothing in that file needs reconciling.

## Open questions for the human (optional)
- Was it intentional to land the neutral module ahead of its consumer, with the adapter deferred to a later PR in the stack? If so, the PR title/body and the new test's doc comment need to say that.

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

…tion

The decision was never moved out of orchestration-worker-start-mode; this PR
adds a second copy beside it. Say so, and name the unenforced agreement.

@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

The only commit since the prior pullfrog review (1dd74f6) is documentation-only: it corrects the receipt-wording test's doc comment, with no behavioral surface touched. The pin still passes 11/11.

  • Corrected the receipt-wording test's premise — its doc comment no longer claims the decision "moved to main/agent-launch/agent-launch-mode". It now states that the test pins orchestration's own module, that the neutral module is a second copy of the same policy, and that nothing yet enforces the two agree. This matches the PR body, which documents the two-copy state as intentional stack groundwork rather than a migration.

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

@brennanb2025
brennanb2025 merged commit 2eb9320 into main Sep 15, 2026
28 checks passed
brennanb2025 added a commit that referenced this pull request Sep 15, 2026
…launch-mobile

The base moved 31 commits: #19849 merged main forward, #19848 landed on main as a
squash, and several mobile domains migrated onto typed RpcOperations.

The only conflicts were 12 settings goldens, and only in two header digests.
Both sides had moved a digest for a legitimate and different reason: upstream
added ~35 files under src/test-support/rpc-recording/, which recorderSha256
covers, while this branch edited workspace-settings-mounts.ts, which
adapterSha256 covers - and upstream never touched that adapter. So neither
side's pair described the merged tree, and taking either wholesale would have
committed a header that lies about the sources it was recorded from.

Resolved by re-recording from the merged tree, which computes both digests from
the actual merged files. The result pairs upstream's recorderSha256 with this
branch's adapterSha256. All 12 bodies are byte-identical to what was already on
disk, so nothing behavioural changed: the conflict was entirely provenance.

The golden set grew 208 -> 509 with upstream's new scenarios; recorded set and
on-disk set match exactly, with no stale and no missing files.
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…stablyai#19848)

* refactor(agent-launch): make the launch-mode decision surface-neutral

`decideWorkerStartMode` was the only shared answer to "structured chat session
or terminal agent?", but it lived in an orchestration-named module and spoke
orchestration's vocabulary, so the other launch surfaces could not call it.
Move the decision to `main/agent-launch/agent-launch-mode` unchanged and leave
`orchestration-worker-start-mode` as the adapter that supplies the noun.

A worker is not a special kind of launch; it is the same launch with a dispatch
attached. Naming the receipt's subject is the only thing orchestration actually
contributed, so that is the only thing the adapter keeps: "worker" in both
sentences, plus the `--terminal` wording, which reads as nonsense anywhere a
`--terminal` flag does not exist. Both are pinned, because they are asserted.

No behavior change. The receipts are byte-identical for every reachable case,
proven by running the new pin against both implementations.

Also pins the wording, which nothing was holding. The existing suites assert
`toContain` fragments ('terminal agent', 'cannot create') and the CLI suite
asserts a receipt handed to it by a mock rather than one this code produced;
all six files stayed green against a deliberately corrupted vocabulary. A
dispatch receipt is the only place a structured-to-terminal downgrade explains
itself, so the whole sentence is the contract, not a fragment of it.

* fix(agent-launch): drop the deleted draft-prompt blocker from the reason map

main removed the draft-prompt blocker in stablyai#19681 (a structured session now holds
an unsent draft), so the exhaustive Record no longer typechecks.

* chore(agent-launch): carry a SAFETY rationale on the agent placement cast

The type-assertion gate landed after this branch's base, so the new file's
copy of the worker-start cast is now a changed-code finding.

* docs(agent-launch): stop the receipt-wording comment claiming a migration

The decision was never moved out of orchestration-worker-start-mode; this PR
adds a second copy beside it. Say so, and name the unenforced agreement.

---------

Co-authored-by: Merge Sim <sim@local>
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