Skip to content

fix(mobile): open native chat when a new worktree launches a default agent - #19850

Merged
brennanb2025 merged 37 commits into
mainfrom
brennanb2025/agent-launch-mobile
Sep 16, 2026
Merged

brennanb2025 merged 37 commits into
mainfrom
brennanb2025/agent-launch-mobile

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​625 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​604
Prod 40 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​600 $\color{#cf222e}{\Huge{\mathbf{−}}}$​309 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​291

ELI5

On your phone, creating a new worktree with a default agent (Claude/Codex) opened the old terminal chat instead of the new native chat — even though the "+ new agent tab" button in an existing workspace opened native chat correctly. Same phone, two flows, two answers. This makes the create flow ask the same question the rest of the app asks.

Stack: 3 of 5. Stacked on #19849. This is the PR that fixes the reported bug.

What Changed

  • Mobile advertises agent.launch.v1 (mobile-runtime-client-capabilities.ts) — without it the method is refused outright.
  • The existing status.get probe in worktree-create-capability.ts is extended, not duplicated: it already read create-idempotency from that response, and now reads agent.launch.v1 from the same shared promise.
  • New mobile/src/tasks/agent-launch-worktree-create.ts builds the launch request from an existing create payload and decodes the receipt.
  • worktree-create-retry.ts gained an optional agentLaunch; the route settles once, before the first attempt, so a name-collision retry cannot land on a different method than the attempt it replaced.
  • Blank and branch/new-branch creates route through agent.launch. agentLaunchCreateFields renamed startupAgentCreateFields — it means "create agent-first", now one of two routes.
  • agent.launch moved into the shared params catalog, and mobile sends it through a typed RpcOperation rather than the raw request port. See Shared-contract move below — this was forced by gates that postdate the branch, not a drive-by.

Why

Mobile's create paths put startupAgent on worktree.create, which creates the worktree agent-first, so the structured branch was unreachable. Meanwhile the in-workspace "+" button called createMobileStructuredAgentSession directly — which is why one flow worked and the other didn't.

Scope boundary: work-item creates deliberately excluded

buildTaskWorkspaceCreateParams sets startupDraft: item.source.url whenever an agent is picked, unconditionally — so every agent-carrying work-item create has an unsent draft. Structured sessions cannot hold an unsent draft today, and three call sites already forward drafts as prompt, which the structured outbox sends immediately (its states are queued | dispatching | unconfirmed; there is no held state). Routing work items now would silently turn the issue URL into a submitted first turn nobody pressed enter on, with nothing going red.

So both work-item entry points stay on worktree.create. createWorkItemWorkspace does not accept agentLaunchSupported, so it cannot be wired up by accident. Pinned by a test.

Shared-contract move: forced, and why this shape

src/main/runtime/rpc/methods/agent-launch-schemas.ts became a re-export of a new src/shared/rpc-contract/agent-launch-params.ts, and the generated params catalog was regenerated. Reviewers will reasonably ask why a mobile PR moves shared-contract files, so:

  • The raw port was not available. mobile/src/transport/unvalidated-rpc-request-port-boundary.test.ts holds the raw-sendRequest boundary as an inventory and fails with "New code must send through an RpcOperation. Nothing may be added to unvalidated-rpc-request-port-inventory.ts." Upstream had also just migrated worktree-create-retry.ts off that port, so re-introducing a raw sender there was closed.
  • The typed route needs a catalog entry. defineRpcOperation requires Method extends RpcMethodName, and agent.launch sat in RPC_METHODS_WITHOUT_SHARED_PARAMS.
  • That exclusion was an artifact of file location, not of the value graph. The catalog's stated reason for exclusion is a schema whose value graph reaches into src/main. AgentLaunch binds only zod, isTuiAgent, TuiAgent and WorktreeCreate — and src/main/.../worktree-create-schemas.ts is itself a bare re-export of src/shared/rpc-contract/worktree-create-params. Nothing reached into src/main.
  • The shape follows existing precedent: worktree-create-schemas.ts is exactly this re-export pattern.

RPC_METHODS_WITHOUT_SHARED_PARAMS drops to three entries, and 'agent.launch' was removed from the hand-maintained UncataloguedMethod twin in rpc-params-type-parity.ts. verify:rpc-params-catalog --check passes, so the generated file is not hand-edited drift.

Behaviour changes a reviewer must see

Two, both deliberate and neither a fixture bump:

  1. Malformed create reply no longer throws. readCreateResult previously read result.worktree.displayName unguarded, so a reply missing worktree surfaced as TypeError: Cannot read properties of undefined (reading 'worktree'). It now returns { error: 'Failed to create workspace' }. The launch route requires this: a launch receipt can legitimately arrive without a worktreeId. This is visible as a recorded-behaviour change in matrix-worktree.create-retry-worktree.create-1.
  2. The host's warning is carried on both routes. Upstream added warning passthrough on worktree.create while this branch was out; it would have been silently dropped on the new agent.launch route. A terminal launch that seats the workspace but cannot start the pty now still reports why — dropping it is what leaves the phone on an unexplained empty session. Newly pinned by test, including the absent, blank, non-string and structured-surface cases.

Merge notes

Merged brennanb2025/agent-launch-rpc rather than rebasing. Five conflicts, all in mobile/; four were plain unions. Three things auto-merged outside any conflict region and are worth naming, since zero conflict markers did not mean a correct tree:

  • WorkspaceCreateParams (now RpcSendParams<'worktree.create'>) silently replaced Record<string, unknown> in untouched regions.
  • The worktreeCreateRun.interpret contract replaced the old RpcSuccess cast.
  • The warning passthrough above.

The golden RPC recordings (mobile/rpc-foundation/goldens) landed upstream and met agent.launch here for the first time. Seventeen were updated: twelve are header-only (adapterSha256, bodies byte-identical) because the settings mount adapter was edited, and five changed behaviourally for the two reasons above. The adapter edit itself is a fixture gap, not a product change — observableModel throws on any member it was not given, so the newly required getAgentLaunchSupport made the recorded submit abort before issuing its create. It is pinned false, like the cutover probe beside it.

CI gap this PR closes

Mobile Checks is path-filtered to mobile/**, but mobile imports the negotiated capability names directly from src/shared/protocol-version.ts and records the whole capability read verbatim in its goldens. So agent.launch.v1 — added desktop-side in #19849 — rewrote a mobile fixture without ever triggering the suite that would have caught it, and the breakage surfaced only here, in the first PR of the stack that touches mobile/**.

Verified at the run level rather than by check name (the workflow is named Mobile Checks but its job is verify, so filtering check names for "mobile" returns zero even for PRs where it demonstrably ran): the window-free check-runs API on the base commit returns 49 check-runs across six runs — PR Checks ×2, PR test LoC ×2, Track Community PRs, Review — and no Mobile Checks among them.

mobile.yml now lists src/shared/protocol-version.ts in its paths filter, matching the existing src/shared/terminal-file-link-conformance.ts precedent, which is there for the same reason.

Linked Issue

Fixes #

Visual Proof

None. No device or emulator QA was performed on this PR. The constraint under which it was revived prohibits computer-use and OS-level automation, so the mobile UI was not exercised end to end by anything here. Coverage is unit/integration only.

This is an outstanding gap before merge, not a completed step — the user-visible behaviour this PR claims to fix has not been observed on a device.

Testing

All figures measured at the current head, not carried over from an earlier one.

  • Mobile suite: 586 files / 5,078 passed, 6 skipped, 0 failed.
  • Mobile tsc --noEmit: clean. Mobile oxlint: clean. Mobile oxfmt --check: clean across 1,974 files.
  • pnpm tc does not cover mobile/. It checks tsconfig.node.json, tsconfig.tc.cli.json and tsconfig.tc.web.json only; mobile has its own tsconfig and is typechecked by the Mobile Checks workflow. A green pnpm tc on a mobile PR says nothing about mobile, and mobile/node_modules is empty until you install that workspace separately. Mobile's typecheck above was run explicitly.
  • Desktop/host: 284 files / 2,545 passed, 1 skipped across src/main/runtime/rpc and src/shared/rpc-contract. Root pnpm tc, oxlint and oxfmt --check clean. verify:rpc-params-catalog --check clean.
  • Changed-code quality gate: passes with 0 findings across all six scans (code quality, casting, type-aware, React Doctor, design system, casting SAFETY). It previously failed with 8 consistent-type-assertions findings; those were removed rather than suppressed — the production one by narrowing the receipt with in instead of asserting it, the test ones by building a typed RpcClient literal and asserting payloads with toMatchObject.
  • Golden RPC recordings: 10 files / 274 passed, 3 skipped.
  • Old-host fallback is proven, not just typechecked: tests drive creates with agentLaunchSupported: false and assert the wire call is worktree.create with startupAgent/createdWithAgent. Every pre-existing create test is pinned to false, so they guard the legacy payload byte-for-byte.
  • Second-line downgrade: if the probe says yes but the host refuses the method (method_not_found / forbidden / agent_launch_unsupported — the advertisement race), the same candidate re-sends as worktree.create and stays downgraded.
  • No max-lines disable or cap bump. No lockfile in any commit; pnpm-lock.yaml and mobile/pnpm-lock.yaml are byte-identical to the merge base.

Ablations: recorded at 57883f0e19 (the pre-merge head) and NOT re-proven across the merge. Eleven ablations were red on their intended tests and reverted — including A2 (ignore the probe), A3 (don't strip reserved fields), A6 (route work-items), A7 (remove the method-refusal downgrade). Treat them as evidence about that commit only: a later commit can add a second reason an assertion holds, so ablation evidence does not automatically survive a merge. The newly added warning-passthrough test was written against the fixed reader and has not been ablated either, though it is deterministic that it discriminates — it asserts a field the unfixed reader omitted.

Reviewer attention: post-create navigation is unverified against a live host

No route param or pending tab id was seeded. The reasoning: agent.launch creates the session with activate: true, and the host sets activeTabId before the RPC answers, so the fresh route's first snapshot already marks the chat active and resolveActiveSessionTab's snapshot-active fallback selects it. Same ordering keeps shouldAutoCreateInitialSessionTerminal from firing.

That avoided re-pinning ~10 SHA constants in the route-parity ratchet for a mechanism argued to be redundant with host activation — but it is the exact user-visible step this PR claims to fix, and it has not been exercised end to end. A contract pin was added in active-session-tab.test.ts; it is a pin, not an ablation, and is green either way by design.

Platforms: macOS host. mobile/ is a separate pnpm workspace and was installed with --frozen-lockfile; zero lockfile drift.

  • 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

Mixed versions: old mobile + new host keeps working (worktree.create unchanged). New mobile + old host falls back via the capability probe, proven by test rather than inspection. New mobile + new host routes correctly.

Note mobile/src/session/mobile-session-route-parity.test.ts is a re-pin ratchet over the session route source family; it passes unmodified here because no file in that family was touched. Its toHaveLength(5) is over calls inside SessionScreen and is unrelated to the advertised capability list.

Security: no new surface beyond the allowlisted method — agent.launch was already in the mobile method allowlist. Cross-platform: no platform-dependent paths. Remote SSH: remote hosts downgrade to terminal. Performance: one extra capability read on an existing probe response — no additional round-trip.

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)

Merge Sim and others added 12 commits September 9, 2026 17:19
`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.
…uns it

The sequencing around the launch decision was duplicated per surface, and the
duplicate is where the bug lives. A new worktree was created agent-first, so
its startup terminal WAS the agent and the structured branch below it could
never be reached — every new-worktree launch was a PTY regardless of the user's
default. Orchestration fixed that for itself in #19431; mobile and the CLI
still have it.

`executeAgentLaunch` inverts the order once, for everyone. When the preference
is structured the worktree is created with NO startup agent, the executing host
is then asked whether it can host a session for the workspace that now exists,
and only then is a surface created. The host verdict cannot be hoisted above
creation: `agentSession.createSupport` only answers for a workspace it can
resolve, which is why the decision stays in two halves.

Agent-first creation is deliberately preserved for PTY launches — it is what
sequences the agent's startup command behind the setup runner, so wait-for-setup
comes for free there.

What actually differs per surface is only how a surface is built (an
orchestration worker's session takes a dispatch hold and a mailbox a plain
launch must not take), so that is injected as a factory rather than branched on.

The intent also strips the reserved agent fields from a migrated create payload:
a caller moving off `worktree.create` passes its existing params, and a stale
`startupAgent` in there would re-create the very path this replaces.

Tests assert order and arguments, not just the resulting mode. Reintroducing
agent-first creation reddens 4 of 11.
Adds `agent.launch` — one host-side method that decides structured-vs-terminal and
creates the surface — wired to the real runtime factories: `createManagedWorktree`
for the workspace, forking on `startupAgent` exactly as the orchestration worker
path does; `createStructuredAgentSessionForWorktree` for a chat session; and
`createTerminal` for a PTY agent. Allowlisted for mobile, which is the surface the
routing gap was reported on.

`worktree.create` is untouched. Its `startupAgent` keeps meaning "spawn a PTY agent"
verbatim, because it answers with `agentTerminalHandle` only on that path: a host
that quietly routed it to a structured session would hand every older client a
response with no handle and no error. All new behaviour sits behind
`agent.launch.v1`, which the host now advertises and a remote client must negotiate,
so a client that does not gets today's behaviour unchanged.
Picking an agent on the mobile create sheet always produced a terminal, even
when the user's default was native chat, because all three create paths put
`startupAgent` on `worktree.create`. That means "create the worktree
agent-first", so its startup terminal IS the agent and the structured branch
below it is unreachable — while the same phone's in-workspace "+" button opened
a chat.

The blank, branch and new-branch creates now send the same payload through
`agent.launch` and let the host settle the surface. `worktree.create` is
untouched, and a host that does not advertise `agent.launch.v1` (read from the
existing `status.get` probe) keeps today's path exactly.

Work-item creates stay on `worktree.create`: they pre-fill the issue/PR URL as
an unsent `startupDraft`, which a structured session cannot hold yet, so routing
them would submit the URL as a first turn.
…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.
…into brennanb2025/revive-agent-launch-rpc

# Conflicts:
#	src/shared/protocol-version.ts
… casting gates

The typed-method contract, the generated params catalog and the
`assertionStyle: never` casting scan all landed after this branch's base.

- AGENT_LAUNCH_METHODS kept an `RpcMethod[]` annotation, which widened its
  method name to `string` and broke assignability; every sibling infers instead.
- `agent.launch` binds a schema under src/main, so it joins the catalog's
  RPC_METHODS_WITHOUT_SHARED_PARAMS and the parity gate's hand-listed twin.
- The now-typed methods make most test casts unnecessary; the few that remain
  carry the line-specific SAFETY rationale the casting gate requires.
…launch-mobile

Mobile's create path moved onto the typed RpcOperation contract upstream, so the
two-method dispatch this branch added had to move with it rather than keep its
own raw sender.

- worktree-create-retry.ts picks between the worktree.create and agent.launch
  bound operations instead of reaching the raw request port, which the mobile
  boundary ratchet forbids for new code.
- agent.launch was uncatalogued only because its schema literal sat under
  src/main; every field it binds is already shared. Moved it to
  src/shared/rpc-contract/agent-launch-params.ts - the same re-export shape
  worktree-create-schemas.ts uses - and regenerated the catalog, so
  RpcSendParams<'agent.launch'> exists and the method is sendable type-safely.
- Both create routes carry the host's warning through, so a create that seats the
  workspace but cannot start the agent surface still reports why.

Work-item creates stay on worktree.create with their unsent startupDraft.
@brennanb2025
brennanb2025 marked this pull request as ready for review September 15, 2026 07:11
…ding needs

The golden RPC recordings landed upstream while this branch was out, so they
first met agent.launch here. Three things had to happen, and only one of them is
a fixture bump.

1. workspace-settings-mounts.ts mounts useNewWorkspaceCreateSubmit against a
   fixture model that throws on any member it was not given. This PR added a
   required getAgentLaunchSupport, so the submit aborted with "Missing model
   fixture" before it ever issued the create, and three cleanup checkpoints
   vanished. That read like a product regression and was not one. Supplying the
   member restores the recording byte-for-byte; it is pinned false for the same
   reason the cutover probe is, so the baseline stays on worktree.create.

2. Editing that adapter moves adapterSha256 for the twelve settings goldens it
   mounts. Their recordings are unchanged - header only, by design: the digest
   is per-golden so editing a module fails exactly the goldens that mounted it.

3. Five goldens changed behaviourally, and both changes are this PR's:
   the capability probe now reports agentLaunch, and a create whose reply
   carries no worktree returns "Failed to create workspace" instead of throwing
   a TypeError off an unguarded result.worktree read. The launch route needs
   that guard, since a receipt can arrive without a worktreeId.
…shape

The changed-code quality gate refuses type assertions, and the eight it flagged
were worth removing rather than suppressing.

The production one was the point. readAgentLaunchCreateOutcome asserted the RPC
payload into Partial<AgentLaunchResult> and then runtime-checked it anyway, so
the assertion bought nothing and claimed a contract the host had not proven. It
now narrows with `in` and validates each hop, which is the same nullability
question readCreateResult already answers on the sibling path - a launch receipt
can legitimately arrive without a worktreeId. AgentLaunchCreateOutcome ties
worktreeId to the shared contract so a change there fails this reader's
typecheck rather than passing a differently-typed field through.

The test fakes claimed a whole RpcClient via `as unknown as RpcClient` while
implementing one member. They now build a typed literal, matching the pattern in
use-mobile-structured-agent-options.test.ts. The read sites cast params and then
read one field; they now assert the payload with toMatchObject, which removes
the cast and pins more of the shape than the cast did.

Also pins the warning passthrough, which nothing covered: a terminal launch that
seats the workspace but cannot start the pty reports why, and the absent, blank,
non-string and structured-surface cases report nothing. Writing that test caught
a real drop I had introduced in the reader.

@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 critical issues — one small behavioral gap inline, plus a coverage ask on the fixed navigation path.

Reviewed changes

This reviews the mobile slice stacked on brennanb2025/agent-launch-rpc (the host-side agent.launch implementation lives on the base branch, not here).

  • Mobile advertises agent.launch.v1 — mobile-runtime-client-capabilities.ts opts in, and the existing status.get create-capability probe (worktree-create-capability.ts) now reports agentLaunch from the same shared promise.
  • Agent-carrying creates route through agent.launch — the blank path (blank-workspace-create.ts) and the branch/new-branch composer paths pass an agentLaunch route; worktree-create-retry.ts settles it once before the first attempt so a name-collision retry cannot switch methods.
  • Method refusal downgrades once — a method_not_found / forbidden / agent_launch_unsupported refusal re-sends the same params as worktree.create and stays downgraded.
  • Receipts are read per route — readAgentLaunchCreateOutcome reads worktreeId plus a terminal outcome.warning; the legacy branch keeps worktree.{id,displayName} + warning.
  • agent.launch params move to shared — src/shared/rpc-contract/agent-launch-params.ts plus the regenerated catalog and the rpc-params-type-parity.ts exception removal, so RpcSendParams<'agent.launch'> exists for the client. pnpm run verify:rpc-params-catalog is clean.
  • Work-item creates deliberately stay on worktree.create — their unsent startupDraft would otherwise be submitted as a first turn.
Verification this run
  • pnpm run verify:rpc-params-catalog — clean.
  • Desktop src/main/runtime/rpc/methods/agent-launch.test.ts — 16/16 pass.
  • The mobile suite could not be run here (mobile/node_modules is not installed in this environment), so the mobile claims are taken from the diff and author's reported run.

ℹ️ The navigation this PR fixes still has no end-to-end exercise

The user-visible step this PR exists to fix — landing on the new native chat instead of the old terminal — is covered only by the pin added in active-session-tab.test.ts:138, which stays green whether or not the host activates the launch's tab before it answers. No create test seeds a route whose first snapshot carries an activated agent-session tab, and no ablation touches it (the author calls this out in the PR body). Since this is the behaviour the bug report is about, it is worth one real pass before merge.

Technical details
# Post-create navigation coverage

## Affected sites
- `mobile/src/session/active-session-tab.test.ts:138` — pins `resolveActiveSessionTab`'s existing snapshot-active fallback; passes with or without the fix.
- `mobile/src/session/use-mobile-session-startup.ts:148` — only auto-creates an initial terminal when no tabs hydrated (`visibleTabCount === 0`), so with the launch tab present the active-tab marking comes entirely from the host.
- `mobile/src/host-screen/host-screen-overlays.tsx:225` — `onCreated` navigates to the session route with no pending tab id, relying on that host marking.

## Required outcome
- Confidence that a real `agent.launch` create lands the phone on the structured chat on the first snapshot, not the workspace shell.

## Suggested approach (optional)
- One emulator/device create against a host whose default is structured, or seed `pendingActiveSessionTabId` with the receipt handle in a create-level test.

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

Mobile Checks is path-filtered to mobile/**, but mobile imports the negotiated
capability names straight from src/shared/protocol-version.ts and records the
whole capability read verbatim in its goldens. So a capability added desktop-side
rewrites a mobile fixture while never triggering the suite that would catch it.

That is what happened here: #19849 introduced agent.launch.v1 and Mobile Checks
never ran on it. Verified at the run level rather than by check name - the
window-free check-runs API on 3837ae8 returns 49 check-runs across six runs
(PR Checks x2, PR test LoC x2, Track Community PRs, Review) and no Mobile Checks
among them. The breakage surfaced only in this PR, which happens to touch mobile/**.

The workflow already concedes this pattern for terminal-file-link-conformance.ts;
protocol-version.ts has the stronger claim, since mobile records its output.

Also corrects the mount adapter's SAFETY comment. It claimed the recorder supplies
only the members the hook reads, which was false the moment the hook gained a
required getAgentLaunchSupport - and the assertion it annotates is exactly what
stopped the compiler from saying so. The twelve goldens are adapterSha256 churn
from that comment: every body is byte-identical, which is the digest doing its job.

@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 in the incremental changes. The two notes from the prior review still stand and are not addressed by this delta.

Reviewed changes (delta since 9edaccc)

  • Launch receipt is narrowed, not asserted — readAgentLaunchCreateOutcome now uses in-narrowing over the raw payload and delegates the terminal warning to a new terminalLaunchWarning, and AgentLaunchCreateOutcome['worktreeId'] is tied to AgentLaunchResult['worktreeId'] so a contract change fails this reader's typecheck.
  • Warning tests added — a terminal launch warning is carried through, while blank / absent / non-string / structured-surface warnings report none.
  • Test assertions de-casted — the create tests replace as casts with toMatchObject / not.toHaveProperty.
  • Recording fixture supplied — workspace-settings-mounts.ts passes getAgentLaunchSupport: async () => false (old-host baseline), and 18 create/capability goldens were regenerated. The matrix-worktree.create-retry golden now records a clean Failed to create workspace instead of the previous TypeError on a malformed legacy reply, which matches the new readCreateResult null path.
Verification this run
  • No non-generated production code changed in this delta beyond readAgentLaunchCreateOutcome / terminalLaunchWarning; the narrowing is sound for null, arrays, and non-object warnings.
  • Mobile suite still could not be run here (mobile/node_modules absent).
Prior review findings still open
  • The launch path does not surface the worktree-create warning (e.g. a skipped worktree-include copy) that worktree.create returned; agent-launch-worktree-creation.ts:67 drops result.warning.
  • Post-create navigation is still only pinned, not exercised end to end.

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.
…at has not happened

The header asserted two things the tree does not support: that every launch
surface routes through the executor, and that the mode decision "already lived"
in `agent-launch-mode`. `agent.launch` is the executor's only consumer, and
`orchestration-worker-start-mode.ts` is byte-identical (blob 92dc5c6, 217
lines) at the merge base and all three stack heads, still used by workers.ts.
Describe the two live copies and leave the cutover to later stack work.
…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.
…oundary

anti-slop/no-object-parameters flagged terminalLaunchWarning's `result: object`.
The rule is pointing at a real seam rather than a style nit: the helper advertised
a loose object and did the narrowing inside itself, so every caller handed it
unparsed wire data and nothing downstream held a real type.

Parsed at the boundary instead. parseTerminalLaunchOutcome takes `unknown` and
returns TerminalLaunchOutcome | null, so the narrowing happens once, where the
untrusted payload enters, and the consumer works with a named type.

The type is taken from the shared contract rather than restated - a Pick over the
terminal member of AgentLaunchOutcome - so a change to that union fails here
instead of flowing through. `handle` is deliberately excluded: nothing reads it,
and requiring it would drop the warning off a reply that omitted one, which is a
behaviour change smuggled in under a typing change.

No assertion and no config exemption: reintroducing `as Partial<AgentLaunchResult>`
would trade this finding for the defect removed earlier in this branch, and the
rule is correct here.

The rule arrived with the merge-forward (#20781, newer than this branch's
merge-base), and anti-slop is not one of the changed-code gate's six scans - it
runs only repo-wide - which is why a clean local gate did not predict it.

Behaviour is unchanged across all five warning cases, and the positive case was
re-ablated on the new parser: dropping the warning reddens exactly it,
1 failed | 18 passed, restored byte-identical to 19 passed.
… second session

A replayed agent.launch could create a second structured session in the same
worktree, with activate: true.

dedupeWorktreeCreate wrapped only the worktree half, inside the workspace
factory. On a replay the create was reused, and the executor then continued to
createSurface and built another surface inside it. The terminal route hid this:
its cached create carries a startup terminal handle, so the executor returns on
early. A structured create has no handle by construction - that is the whole
point of the structured fork - so it fell through every time. Mobile replays
this method deliberately on a delivery-ambiguous response, up to five attempts,
so the path is reachable by design rather than in theory.

The handler now wraps the entire launch in the same dedupe, on the same
(repo, clientMutationId) identity, exactly as worktree.create wraps its own
body. A replay returns the original AgentLaunchResult instead of re-running
createSurface, which makes the two routes replay-identical.

The inner dedupe is removed rather than kept. Wrapping both levels on one key
deadlocks: dedupeWorktreeCreate stores the in-flight promise before the inner
call runs, so the inner call would be handed the outer's promise, which is
waiting on it. The launch-level memo subsumes the worktree-level one.

Failures are still dropped rather than cached, so an unknown outcome stays
unknown instead of replaying as a fabricated success.

The guard replays a STRUCTURED launch: the terminal route cannot reproduce this
and a test there would pass either way. Ablated against the pre-fix files -
1 failed | 22 passed, "expected vi.fn() to be called 1 times, but got 2 times",
which is the duplicate session - then restored to 23 passed. The stub's dedupe
had to be made faithful for that to be observable; the shared one passes through
so other tests can see raw calls.
…t mint a second session"

This reverts commit 59bc5e9.

The same defect was already fixed upstream on this stack's base branch by
539e283, which landed while this was being written. That change is broader
(it also cancels the setup wait) and namespaces the dedupe key, so it supersedes
this one. Reverting rather than hand-merging keeps a single implementation
instead of a hybrid nobody chose.

The behavioural guard from this commit is ported back on top of the upstream
implementation separately: it asserts exactly one structured session survives a
replay, where the upstream tests assert the dedupe wiring.

@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

Moving the replay dedupe to wrap the whole agent.launch launch fixes the success path but drops the create-level memo, so a same-clientMutationId replay after a post-create failure now re-creates the worktree. dedupeWorktreeCreate deletes its key on rejection and createManagedWorktree has no idempotency of its own, so the retry resolves past the now-existing branch to name-2 and strands the first workspace. Detail inline.

Reviewed changes

This run reviews the delta since the prior pullfrog review at 2f602f1b2e — commit 59bc5e9b04 ("memoize the whole launch so a replay cannot mint a second session").

  • Replay identity moved to the whole launch — agent.launch now wraps executeAgentLaunch in runtime.dedupeWorktreeCreate for create-worktree targets, and the create-level wrapper was removed from agent-launch-worktree-creation.ts, so a replayed structured launch returns the memoized receipt instead of minting a second session.
  • Replay tests added — agent-launch.test.ts gains a memoizing dedupeWorktreeCreate stub shape (memoizeCreates) plus three cases: same-mutation replay returns the original receipt, a different mutation id still launches, and a failed launch is not memoized.
  • agent.launch exception list tidied — rpc-params-type-parity.ts collapses UncataloguedMethod to emulator.install | orchestration.send | orchestration.taskUpdate, following through the earlier shared-catalog move.

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

Comment on lines +117 to +121
return context.runtime.dedupeWorktreeCreate(
params.target.create.repo,
params.target.create.clientMutationId,
run
)

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.

dedupeWorktreeCreate drops its entry the moment the launch rejects, and this commit removed the create-level memo that used to survive a post-create failure. A delivery-ambiguous replay after the worktree exists but a later step failed therefore re-enters createManagedWorktree with the same clientMutationId, which has no idempotency — the candidate resolver suffixes the now-existing branch to name-2 and a second workspace is created while the first is stranded. The removed inner wrapper returned the cached worktree for the full TTL window, so this replay could not duplicate before.

Technical details
# Whole-launch memo trades duplicate-surface for duplicate-worktree on the failure path

## Affected sites
- `src/main/runtime/rpc/methods/agent-launch.ts:117` — the launch is now the memoized unit; `dedupeWorktreeCreate` (`orca-runtime-terminal-create-deduplication.ts:193-203`) deletes the key on rejection (`void created.then(() => {…}, drop)`), before the host even serializes the error.
- `src/main/runtime/rpc/methods/agent-launch-worktree-creation.ts:42-55` — the create-level `dedupeWorktreeCreate` was removed, so `createManagedWorktree` is now a bare call.
- `src/main/runtime/runtime-local-worktree-create-candidate.ts:94,171-173` — on a local branch conflict it `continue`s to suffix 2; `createManagedWorktree` never receives `clientMutationId` (`worktree-create-args.ts:20-92`), so the second call is a genuine second create.
- `mobile/src/tasks/worktree-create-retry.ts:204,213` — mobile replays the same `clientMutationId` on cutover / delivery-unknown, independent of whether the host's launch failed.
- `src/main/runtime/orca-runtime-core.ts:69-72` — the doc on `WORKTREE_CREATE_RESULT_TTL_MS` states the guarantee this now breaks on the failure path.

## Trigger
1. Mobile sends `agent.launch` with mutation id `M`; `createManagedWorktree` succeeds (worktree + branch `task`).
2. A later step rejects the outer `run` with the worktree already on disk: `createSurface` throws a non-definitive error (`agent-launch-executor.ts:145-156`), or the terminal downgrade / terminal-surface create throws (`:158-168`, `:225-229`).
3. The memo is dropped; the host returns an error response; the transport loses it.
4. Mobile replays `M`; the memo is gone, so `createManagedWorktree` re-runs, sees branch `task` as a local conflict, and creates `task-2`.

## Required outcome
- A same-`clientMutationId` replay after a post-create launch failure must reuse the worktree that was already created; worktree-create idempotency must not depend on the later surface/mode step succeeding.

## Suggested approach (optional)
- Keep the create-level memo and make the surface step idempotent per launch, or cache the launch rejection too (the shared `dedupeWorktreeCreate` deliberately drops failures), or give `createManagedWorktree` its own `clientMutationId` idempotency. Author's call.

## Note
- `agent-launch.test.ts:404-414` asserts `createStructuredSession` twice but never asserts `runtime.createManagedWorktree`; it passes while encoding this duplicate create.

…launch-mobile

Takes 539e283's replay fix wholesale. This branch's own attempt at the same
defect was reverted first, so the merge is clean and there is one implementation
rather than a hand-merged hybrid.

@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 in this delta — the host-side replay fix this PR carried was superseded by the base branch and reverted onto it.

Reviewed changes

This run reviews the delta since the prior pullfrog review at 59bc5e9b04 — commits d464adf718 (revert) and 272d2a7eed (merge of base 539e283c0f).

  • Host-side replay fix reverted — d464adf reverts 59bc5e9; the base branch's 539e283 ("dedupe complete launch and cancel setup wait") already carries a broader version — a namespaced agent.launch:<mutationId> dedupe key plus an abortable setup wait — so agent-launch.ts, agent-launch-worktree-creation.ts and agent-launch.test.ts are now identical to base and drop out of this PR's diff.
  • Base merged in — 272d2a7 merges brennanb2025/agent-launch-rpc; no mobile file changed in either new commit, so the behaviour the earlier reviews covered is untouched.
  • Behaviour now inherited from base — a replayed create-worktree launch memoizes the whole launch (successes reused, failures still dropped), and a structured launch's setup wait aborts on its 60s timeout.

The two findings from earlier reviews — the create-level warning dropped on the launch path, and the failure-path duplicate worktree on a replayed launch — remain open; neither is touched by these commits.

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

Three review findings, all narrow.

Mobile Checks is path-filtered, and this branch made mobile's types depend on the
shared RPC contract: rpc-params-contract.ts is a type-only re-export of the
generated params catalog, and mobile/tsconfig.json includes **/*.ts. So a
desktop-only edit under src/shared/rpc-contract/ could break mobile's typecheck
with no mobile signal at all - the same blind spot the protocol-version.ts entry
closed, one directory over. Added src/shared/rpc-contract/** to the paths filter.

agent.launch had no cross-version trigger. Added the three prefixes a paired peer
actually exchanges: the intent contract, the wire schema, and the RPC method.
src/main/agent-launch/ is deliberately NOT listed - the executor shapes behaviour
but is not itself wire, and AgentLaunchResult's shape is already covered by
agent-launch-intent. Extending the cross-version SUITE to cover a negotiated
handshake is separate work, not this.

The break branch that answers an accepted-but-empty reply with "Failed to create
workspace" had no unit coverage; the golden that used to discriminate it
collapsed five partitions into one shared error when the null guard replaced the
unchecked read. Covered on BOTH routes - worktree.create with no worktree.id and
agent.launch with no worktreeId - since the branch serves both. Ablated by
bypassing the guard: 2 failed | 11 passed, the two new cases returning a
fabricated worktree instead of the error, restored to 13 passed.

@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

This run reviews the delta since the prior pullfrog review at 272d2a7 — commit b9dfdcad ("ci(mobile): close the round-1 signal gaps around agent.launch"). All three files are CI/test surface; no mobile product code changed.

  • Added src/shared/rpc-contract/** to Mobile Checks' path filter — mobile's rpc-params-contract.ts is a type-only re-export of the generated params catalog, so a desktop-only schema edit can break mobile's typecheck with no other mobile signal; the glob is valid and covers the catalog plus rpc-send-params.
  • Extended the cross-version-wire trigger with three agent.launch prefixes — src/shared/agent-launch-intent, src/shared/rpc-contract/agent-launch-params and src/main/runtime/rpc/methods/agent-launch. Verified the shipped CLI classifies all three as cross-version-wire=true, and config/scripts/pr-code-change-scope.test.mjs still passes 31/31.
  • Covered the accepted-but-empty reply break branch on both routes — the new it.each in blank-workspace-create.test.ts drives legacy worktree.create with no worktree.id and agent.launch with no worktreeId, asserting Failed to create workspace with a single call. The guard is discriminating: an unchecked reader returns a fabricated worktree instead.

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

…complete

createManagedWorktree reports an unspawned startup terminal or an uncopied
working tree as a top-level `warning`, and worktree.create hands it straight to
mobile. The launch path narrowed that result down to
{worktreeId, startupTerminalHandle} and dropped it, so every agent.launch create
lost a warning the old method surfaces - on both arms.

The channel was also asymmetric by accident rather than design: a terminal
outcome could carry `warning`, a structured one had nowhere to put it, so the
arm this PR exists to enable was the arm that could not report an incomplete
create at all.

Now there is exactly one place a launch warning lives: AgentLaunchResult.warning,
at the top level. It is about the create as often as the surface, it applies to a
structured session and a terminal alike, and a reader should not branch on
outcome.kind to discover the workspace it just opened is missing something. The
terminal arm's own `warning?` is removed rather than left beside it - two homes
for one fact is how they drift. Every producer folds in: the create, the surface,
and the refusal downgrade.

Consumer census before removing it: one production reader (mobile's
readAgentLaunchCreateOutcome) and no others - the renderer and mobile launch
call sites never read it. The mobile reader now reads the top-level field, which
also lets its outcome parser go away entirely.

Guard ablated by restoring the pre-fix narrowing: 2 failed | 24 passed, both
carriers reporting `expected undefined`, which is the dropped warning itself;
restored to 26 passed. The third case asserts an absence and stays green under
the mutation by construction - it pins shape, not the defect.

@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 — the previous warning-passthrough finding is now addressed. Two small accuracy notes, one inline.

Reviewed changes

This run reviews the delta since the prior pullfrog review at b9dfdcad28 — commit e970278166 ("fix(agent-launch): give a launch one place to say the workspace is incomplete").

  • Launch warning moved to one top-level home — AgentLaunchResult.warning is now the single place an incomplete launch is reported; AgentLaunchOutcome's terminal variant loses its own warning, so a reader never has to branch on outcome.kind.
  • Host threads the create warning through — AgentLaunchWorkspaceFactory.createWorktree now returns result.warning from createManagedWorktree, resolveWorkspace carries it, and executeAgentLaunch emits it on both the agent-first terminal early return and the main path.
  • Mobile reads the new shape — readAgentLaunchCreateOutcome reads top-level warning instead of outcome.warning, and a new test pins that a warning left on the old outcome surface is ignored.
  • Coverage added — desktop agent-launch.test.ts gains a "create that succeeded but is incomplete" suite (structured and agent-first terminal arms); withoutReservedAgentCreateFields is now generic so the stripped create keeps the caller's type.

Verification this run: desktop agent-launch.test.ts 26/26; mobile agent-launch-worktree-create / worktree-create-retry / blank-workspace-create 59/59; pnpm tc:node, tc:web and mobile tsc --noEmit clean; verify:rpc-params-catalog clean; changed-code quality gate 0 findings across 34 files.

ℹ️ Nitpicks

  • The PR body still describes the pre-e970278 contract: item 2 under "Behaviour changes a reviewer must see" says a terminal launch carries the warning on its outcome and lists a "structured-surface" no-warning case. The warning now lives at AgentLaunchResult.warning for both surfaces, and that case was replaced by "ignores a warning left on the outcome".

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

Picks up #20874 (6c03bb6), which removes the Reflect.get this branch was
carrying as an inherited anti-slop error. The file arrives from main untouched -
its blob here is now main's 6a85b39 - and audit:anti-slop reports zero
findings for the first time on this branch.

Twelve settings goldens conflicted, the same set as before and for the same
reason: main moved recorderSha256 while this branch owns adapterSha256, so
neither side's header describes the merged tree. Resolved by re-recording from
the merged sources so both digests derive from what is actually there.

Unlike the previous merge, the BODIES changed too, and that is correct rather
than a regression: main rewrote the recording harness and run-recording.ts now
projects a `sent` counter on every effect. The re-recorded bodies gain only
`sent` lines - pure additions, no deletions, no modifications - matching the
~629 goldens that took main's side cleanly. The header delta is baseline
(main repinned it) and recorderSha256; adapterSha256 is unchanged because this
branch already held the right one. The golden set is unchanged in both
directions at 641.
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/agent-launch-rpc to main September 15, 2026 23:42
Round 2 found the comment here was false. A create warning and a surface warning
CAN both be set, on two reachable paths:

  1. The create warns precisely BECAUSE it produced no startup terminal -
     didSpawnStartup stays false when that spawn throws, and
     orca-runtime-create-managed-worktree.ts:283 gates startupTerminal on it - so
     the executor's early return is skipped and a second surface is built, which
     can warn too.
  2. An untracked-copy warning, then a definitive structured refusal downgrading
     to a terminal that also warns.

`??` kept the first and lost the second with nothing saying so. They are now
combined the way the create combines its own failures - appendFailure in
runtime-local-worktree-terminal-startup.ts, and the startup-terminal catch in
runtime-remote-managed-worktree-create.ts - which append rather than replace.

The comment is rewritten to say what is true, and records the gap NOT fixed
here: a create warning about a failed startup terminal is stale once the launch
recovers by building a working one, so a user can be told the agent did not start
while looking at it. Distinguishing those needs createManagedWorktree to stop
multiplexing two unrelated failures into one string.

Guarded and ablated: restoring `??` reddens exactly the new test, with the
surface clause missing from the received string; restored to 27 passed. The
structured-create stub had to admit its real ok-or-refusal union for the
downgrade path to be modellable at all - it previously declared only the ok arm.

Also: mobile.yml gains src/shared/agent-launch-intent.ts. It is the sole holder
of the agent.launch RESULT shape - the rpc-contract catalog holds params only -
and mobile imports it as a value. CROSS_VERSION_WIRE_PREFIXES already treats it
as wire-critical; without this, one gate does and the other cannot see it.

And the agent-first warning test no longer pairs "startup terminal failed" with a
returned handle, a combination the producer cannot emit.
@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: aa843c0e-d723-4b21-9b0a-b3400ee0ca02

📥 Commits

Reviewing files that changed from the base of the PR and between e8df34b and 617f131.

📒 Files selected for processing (18)
  • mobile/rpc-foundation/goldens/matrix-settings.task-workspace-create-settings.get-1.json
  • mobile/rpc-foundation/goldens/matrix-settings.task-workspace-create-worktree.create-1.json
  • mobile/rpc-foundation/goldens/matrix-settings.task-workspace-settings.get-1.json
  • mobile/rpc-foundation/goldens/matrix-settings.workspace-submit-settings.get-1.json
  • mobile/rpc-foundation/goldens/matrix-worktree.create-retry-worktree.create-1.json
  • mobile/rpc-foundation/goldens/matrix-worktree.runtime-capabilities-status.get-1.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-create-linear.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-create-pr-start-point.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-fulfilled.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-refused.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-transport-error.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-fulfilled.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-refused.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-transport-error.json
  • mobile/rpc-foundation/goldens/tw-capabilities-advertised.json
  • mobile/rpc-foundation/goldens/tw-capabilities-cutover-retried.json
  • mobile/rpc-foundation/goldens/tw-capabilities-legacy-idempotency.json
  • src/main/agent-launch/agent-launch-executor.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • mobile/rpc-foundation/goldens/settings-task-workspace-create-pr-start-point.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-transport-error.json
  • mobile/rpc-foundation/goldens/matrix-settings.task-workspace-create-worktree.create-1.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-fulfilled.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-fulfilled.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-transport-error.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-refused.json

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


📝 Walkthrough

Walkthrough

The pull request adds the shared agent.launch contract and host execution flow. Mobile detects host support and routes eligible workspace creates through agent.launch, with fallback to worktree.create. The host supports structured sessions, terminal launches, setup waits, deduplication, warnings, and structured-session fallback. Tests and recorded capability scenarios cover the new behavior. CI path filters now include the shared and agent-launch paths.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 617f1

A creation that succeeds but returns an incomplete receipt may be presented as failed. Retrying could create another workspace, so this behavior should be resolved or explicitly accepted before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed and covers the implementation, rationale, testing, limitations, and checklist. However, the required Linked Issue is missing, and the required visual proof for this UI beha… Add a valid issue number to the Fixes # section and attach before/after screenshots or a video showing the changed mobile behavior. Update the related checklist item after completing these requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.26% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 46 functions across 33 files. (17 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary mobile behavior fix: opening native chat when a new worktree launches a default agent.
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.
Full details: Description check

Explanation

The description is detailed and covers the implementation, rationale, testing, limitations, and checklist. However, the required Linked Issue is missing, and the required visual proof for this UI behavior change is not attached.

Full details: Docstring Coverage

Explanation

Docstring coverage is 28.26% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 46 functions across 33 files. (17 skipped: 17 unsupported.)

✨ 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: 90b7a655-a1d9-4cfd-9775-e1795778380b

📥 Commits

Reviewing files that changed from the base of the PR and between 6da7238 and eac3e56.

⛔ Files ignored due to path filters (1)
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (52)
  • .github/workflows/mobile.yml
  • config/scripts/pr-code-change-scope.mjs
  • mobile/rpc-foundation/goldens/matrix-settings.task-workspace-create-settings.get-1.json
  • mobile/rpc-foundation/goldens/matrix-settings.task-workspace-create-worktree.create-1.json
  • mobile/rpc-foundation/goldens/matrix-settings.task-workspace-settings.get-1.json
  • mobile/rpc-foundation/goldens/matrix-settings.workspace-submit-settings.get-1.json
  • mobile/rpc-foundation/goldens/matrix-worktree.create-retry-worktree.create-1.json
  • mobile/rpc-foundation/goldens/matrix-worktree.runtime-capabilities-status.get-1.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-create-linear.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-create-pr-start-point.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-fulfilled.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-refused.json
  • mobile/rpc-foundation/goldens/settings-task-workspace-transport-error.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-fulfilled.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-refused.json
  • mobile/rpc-foundation/goldens/settings-workspace-submit-transport-error.json
  • mobile/rpc-foundation/goldens/tw-capabilities-advertised.json
  • mobile/rpc-foundation/goldens/tw-capabilities-cutover-retried.json
  • mobile/rpc-foundation/goldens/tw-capabilities-legacy-idempotency.json
  • mobile/src/components/NewWorktreeModal.tsx
  • mobile/src/components/use-new-workspace-create-submit.ts
  • mobile/src/session/active-session-tab.test.ts
  • mobile/src/tasks/agent-launch-worktree-create.test.ts
  • mobile/src/tasks/agent-launch-worktree-create.ts
  • mobile/src/tasks/blank-workspace-create.test.ts
  • mobile/src/tasks/blank-workspace-create.ts
  • mobile/src/tasks/mobile-workspace-create-operations.ts
  • mobile/src/tasks/source-workspace-create.test.ts
  • mobile/src/tasks/source-workspace-create.ts
  • mobile/src/tasks/workspace-create-params.test.ts
  • mobile/src/tasks/workspace-create-params.ts
  • mobile/src/tasks/worktree-create-capability.test.ts
  • mobile/src/tasks/worktree-create-capability.ts
  • mobile/src/tasks/worktree-create-retry.ts
  • mobile/src/test-support/rpc-recording/adapters/workspace-settings-mounts.ts
  • mobile/src/transport/mobile-runtime-client-capabilities.test.ts
  • mobile/src/transport/mobile-runtime-client-capabilities.ts
  • src/main/agent-launch/agent-launch-executor.test.ts
  • src/main/agent-launch/agent-launch-executor.ts
  • src/main/runtime/orca-runtime-start-tui-idle-visible-read-probe.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-06.spec.ts
  • src/main/runtime/rpc/methods/agent-launch-schemas.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/main/runtime/rpc/methods/agent-launch-worktree-creation.ts
  • src/main/runtime/rpc/methods/agent-launch.test.ts
  • src/main/runtime/rpc/methods/agent-launch.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-allowlist.ts
  • src/shared/agent-launch-intent.ts
  • src/shared/protocol-version.ts
  • src/shared/rpc-contract/agent-launch-params.ts
  • src/shared/source-scan/source-tree-walk.test.ts
💤 Files with no reviewable changes (1)
  • src/shared/source-scan/source-tree-walk.test.ts

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

Comment on lines +123 to +124
lastError = 'Failed to create workspace'
break

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 | 🏗️ Heavy lift

Preserve an uncertain result for an invalid create receipt.

Both deferred operations accept an ok response before readCreateResult validates the receipt. A missing or invalid worktreeId then reaches mobile/src/tasks/worktree-create-retry.ts:123-124, which reports a definite failure. The submit hook leaves the modal open and re-enables Create. With idempotency enabled, the next submission mints a new clientMutationId; host deduplication only matches the original repository and mutation ID. If the first request committed before returning the malformed receipt, the retry can create another workspace, including after a name-collision suffix.

Return an explicit uncertain state that blocks a new mutation ID. Replay the original mutation ID within the host dedupe window, or require a workspace refresh before enabling another create.

#19850 was retargeted to main after #19849 landed as a SQUASH, so this branch
held #19849's original commits while main held the squashed equivalent - the
same content under different SHAs, which git reported as dirty.

Five files conflicted add/add, all of them files this PR also edits. Neither
side was takeable wholesale: theirs would have discarded this PR's work, ours
would have discarded anything main gained. Verified first that main's blob for
each is byte-identical to 539e283 - the #19849 head this work builds on - so
ours is a strict superset and the conflict is purely the squash artifact. Then
took ours on all five.

Two things auto-merged WRONG, outside any conflict region, and neither showed a
marker:

  - rpc-params-type-parity.ts silently reverted to main's copy, putting
    'agent.launch' back in UncataloguedMethod while the catalog still holds the
    entry. Typecheck caught it: TS2344 at :45. Re-applied.
  - the generated params catalog was stale against main's new methods.
    Regenerated; agent.launch stays catalogued and the uncatalogued list is
    back to three.

Audited every file this branch authored against main's copy afterwards: none
other reverted. The only file matching main verbatim is src/relay/pty-handler.ts,
which this branch never touched.

@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 in this delta. Approval is withheld only because an earlier Pullfrog thread on the base branch's replay behavior (agent-launch.ts, now outside this PR's diff) is still open — nothing in these commits touches it.

Reviewed changes

This run reviews the delta since the prior pullfrog review at e970278166 — the main merge b625f55e84 (no PR-owned source change) and commit eac3e56351 ("fix(agent-launch): combine both launch warnings instead of dropping one").

  • Both launch warnings are now combined, not preferred — executeAgentLaunch replaces placed.warning ?? created.warning with combineLaunchWarnings, which appends the surface warning to the create one instead of silently dropping it. The comment is rewritten to state the real invariant and records the deliberately-unfixed staleness gap (createManagedWorktree multiplexing untracked-copy and startup-terminal failures into one string).
  • A discriminating test pins the co-occurrence — the structured-create stub now models its real ok-or-refusal union (it previously declared only the ok arm, so the downgrade path was unmodellable), and the new case asserts the exact combined string (the old ?? reddens it). The agent-first warning test no longer pairs "startup terminal failed" with a returned handle, a combination the producer cannot emit.
  • Mobile Checks now re-runs for src/shared/agent-launch-intent.ts — mobile imports withoutReservedAgentCreateFields as a value from it, and CROSS_VERSION_WIRE_PREFIXES already classifies it as wire-critical.

Verification this run: desktop agent-launch.test.ts 27/27 + agent-launch-executor.test.ts 13/13. The prior thread on agent-launch-executor.ts:176 was replied to and resolved.

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

@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 — this delta is a merge-only sync of main with no PR-authored change.

Reviewed changes

This run reviews the delta since the prior pullfrog review at eac3e56351 — commit 55327fe893 ("Merge branch 'main' into brennanb2025/agent-launch-mobile").

  • Merge of main, no PR source changed — git diff eac3e56351 55327fe893 lists only main-side files (terminal shell-override, CLI help text, pty spawn preflight, protocol-version), none under mobile/, src/main/agent-launch/, or the agent.launch RPC family. The merged tree's agent-launch-executor.ts — including combineLaunchWarnings and the warning comment the previous review covered — is byte-identical to the reviewed version.
  • Diff-base files shifted, not the branch — several base-branch files now resolve identically on both sides and drop out of the PR diff (45 files vs 53); that is the merge base advancing past them, not a change in this branch.

Verification this run at the merged head 55327fe893: pnpm run verify:rpc-params-catalog --check clean; desktop agent-launch.test.ts 27/27 + agent-launch-executor.test.ts 13/13.

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

agent.launch moved `warning` from the terminal outcome to the top level of the
result. That is the right shape - a reader should not branch on `outcome.kind`
to learn the workspace it just opened is incomplete - but on the wire it is a
REMOVAL, and mobile only read the new place.

A host built before the move still advertises the same `agent.launch.v1`
capability, so the capability probe cannot tell the two apart and mobile takes
this route against one:

  protocol-version.ts:360       AGENT_LAUNCH_RUNTIME_CAPABILITY is in
                                RUNTIME_CAPABILITIES, the host list
  orca-runtime-get-status.ts:64 publishes it via status.get; the filter drops
                                only browser.screencast.v1 and three E2E-gated
                                capabilities, never agent.launch
  agent-launch-executor.ts      such a host writes warning INSIDE outcome

The result was a regression rather than a contract cleanup: the worktree.create
path this replaces returned the warning at the top level and mobile read it, so
a create that seated the workspace but could not start the agent surface - pty
exhaustion, untracked files not copied - stopped explaining itself on the phone.

Read both shapes for as long as such a host can be paired. Top level wins, and
cannot be shadowed: AgentLaunchOutcome has no `warning` on either arm, so a
current host cannot nest one.

The test that pinned the old behaviour is inverted here. Its comment was the
actual defect - it framed a legitimate warning from an older peer as a stale
shape to defend against, which is what made dropping it look deliberate.

@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 in this delta. Approval is withheld only because the earlier Pullfrog thread on the base branch's replay behavior (agent-launch.ts, now outside this PR's diff) is still open — nothing in this commit touches it.

Reviewed changes

This run reviews the delta since the prior pullfrog review at 55327fe893 — commit 5c58ad38fd ("fix(mobile): read a launch warning an older host nests on the outcome").

  • The launch reader now also reads a warning nested on the terminal outcome — readAgentLaunchCreateOutcome falls back to outcome.warning when the top level carries none, with the top-level value winning. A host from the base branch nests the warning there and advertises the same agent.launch.v1, so this mobile-only upgrade path would otherwise lose the incomplete-create notice the worktree.create path already delivered. The fallback is live rather than dead code: the reply is read through rpcUncheckedPayloadReader('agent-launch-receipt'), so outcome.warning is not stripped before the reader sees it.
  • Both directions are pinned — one test reads a nested warning the previous top-level-only reader would have dropped (it reddens against that reader); another pins that a top-level warning shadows a nested one, so the migration fallback can never mask the fresher value.
  • No host change — the diff is confined to mobile/src/tasks/agent-launch-worktree-create.ts and its test; the earlier agent-launch-worktree-create.ts:61 thread stays resolved and is unaffected.

Verification this run: mobile/node_modules is absent in this environment, so the mobile suite could not be run here. The change is confined to one reader function and its tests, and no host file changed.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review + QA status

Readiness review: PASS — no P0, no P1. Head e8df34b1d3, merged forward on current main.

Fixed during review

A shipped-wire regression that 5,551 green mobile tests could not see. Mobile's new reader took only the top-level warning. A desktop host built from main between #19849 and this PR advertises the same single agent.launch.v1 capability but nests that warning inside outcome — so a create that succeeded yet could not start the agent surface produced a warning the phone silently discarded. It is a regression, not a pre-existing gap: the previous worktree.create path returned the warning at top level and mobile did read it. Hourly builds ship from main, so the window is live rather than theoretical.

It survived every gate because the reader dropped the field and a test asserted the drop — code and test written from the same premise, agreeing with each other while both were wrong. Fixed mobile-side in two files (executor blob byte-identical, zero goldens touched), and ablated at the final head: RED on exactly the nested-read test, byte-identical restore verified by hash, GREEN. The precedence test still passes in the RED arm, which is what shows the new test targets the fallback specifically rather than being incidentally coupled to it.

Validation at e8df34b1d3

Root tc 0 · mobile tsc 0 · catalog drift 0 · mobile suite 594 files / 5,567 passed · host suite 27 · anti-slop 0 · changed-code gate CI-shaped against the current base: 0 findings / 27 files · lint + format clean · both lockfiles byte-identical to main · two parents · silent-revert audit across all 45 authored files: zero.

Mobile Checks ran and passed, so the path-filter blind spot that hid #19849's breakage does not apply here.

Device QA

Scenario 1 — create with an agent and an empty prompt: PASS. Usable workspace in ~4s, one tab, no error state.

Scenario 3 — does the create travel via agent.launch: NOT VERIFIED. Not a failure — untested. Both QA rigs paired using the runtime pairing URL, which mints scope: 'runtime'; the capability updater is wired only for scope: 'mobile', so the capability update bound nothing and the gate refused every create. That is correct behaviour for a runtime-scope client and says nothing about the mobile path. An earlier conclusion drawn from those captures has been retracted.

A valid re-run needs getPairingQR({ connectionMode: 'local-only' }) — which mints the mobile-scope offer without Relay — gated on mobile.listDevices() being non-empty before any evidence is recorded.

One QA finding worth keeping regardless: the created surface is a PTY terminal, and the phone renders it as chat because of a device-side view preference. Judging this flow from a screenshot alone produces the wrong conclusion.

Known gaps, disclosed rather than fixed here

  • Stale startup-terminal warning. A create warning about a failed startup terminal goes stale once the launch recovers by building a working one, so a user can be told the agent did not start while looking at it running. Recorded as a known gap at the site; separating it needs createManagedWorktree to stop multiplexing two unrelated failures into one string.
  • Downgrade re-send can create a second workspace. An ambiguous launch that downgrades to worktree.create re-sends the same clientMutationId, but the launch was memoized under a namespaced key while the create path keys it bare, so the downgrade misses the cache. Narrow, non-destructive, reversible — follow-up, since a fix here would re-open every host gate and expire the ablation evidence.
  • prompt is declared in the contract and implemented at neither end. AgentLaunchIntent declares prompt?: {text, delivery}; the mobile caller never sets it and the executor reads .text in zero places, returning a hardcoded delivered: false. Top-ranked follow-up, since this contract is meant to be the simple plugin-facing surface.

Wire-compatibility note for release timing

Removing warning from the outcome union is safe only because agent.launch is capability-gated and no shipped client can call it yet. That window closes at release; the same removal afterwards would need a deprecation path.

#20911 retired the duplicated launch-mode policy, so main now describes
`agent-launch-mode` as the single owner with `orchestration-worker-start-mode`
as a thin adapter over it.

The executor did NOT conflict. Main's only change there is the module header
prose (lines 3-12); every change this branch makes to that file starts at line
81, so the two auto-merged cleanly. Verified both halves survived rather than
assuming: main's "shared, not copied" wording is present, the stale "duplicated
rather than shared" wording is gone, and combineLaunchWarnings is intact.

Fifteen mobile RPC goldens conflicted, all on recorderSha256/adapterSha256 plus
value-pool entries. Both sides had legitimately re-recorded them - this branch
for the getAgentLaunchSupport adapter, main for its own new recordings - so
NEITHER side's hashes are correct for the merged source and picking a side is
wrong in both directions. Resolved by re-recording instead.

Seeded from main's side deliberately, so a re-record that failed to run would
drop this branch's agentLaunch fields and fail loudly rather than silently
keeping stale local values.

The re-record touched 16 files, not the whole corpus: the 15 conflicted plus
tw-capabilities-cutover-retried.json, which auto-merged but still needed its
hash refreshed. Proven behaviour-preserving by comparing added and removed
content lines as multisets, with pool keys and hash fields normalised out:

  added 127 / removed 119 content lines
  net added:   8x  "agentLaunch": false
  net removed: none

So every value main recorded is preserved, and the only semantic delta is this
branch's own adapter field. Goldens then re-validated in normal (non-record)
mode: 17 files, 793 passed.
32 commits, the largest forward on this branch so far. No agent-launch file
moved on main: the executor, agent-launch-intent, the shared launch params and
both mobile task modules are all byte-identical to the merge base, so nothing
in the contract shifted underneath this work.

Twelve mobile RPC goldens conflicted, every hunk on recorderSha256/adapterSha256.
Both sides re-record, so neither side's hashes are right for the merged source
and picking a side is wrong in both directions. Re-recorded instead, seeded from
theirs so a recorder that failed to run would fail loudly rather than preserve
stale local values.

The re-record touched exactly those 12 files; the other 694 changed goldens were
staged by the merge itself and are main's, not mine.

Behaviour-preserving, proven by comparing added and removed content lines as
multisets with pool keys and hash fields normalised out:

  net added:   0
  net removed: 0

so the only delta is the source hashes themselves - 24 hash lines - which is the
signature of a pure recorder-source shift with no semantic change. Re-validated
in normal (non-record) mode afterwards: 17 files, 810 passed.
Six commits. No agent-launch contract moved: agent-launch-intent, the shared
launch params, the executor and the mobile task module are all byte-identical
to the merge base.

protocol-version.ts did change, but not for this work - #20767 adds
BROWSER_IDENTITY_RUNTIME_CAPABILITY ('browser.identity.v1'). Checked rather than
assumed, because that file is one of the ones #20999 moves; agent.launch.v2 is
still absent from main, so nothing here adapts to it.

Twelve goldens conflicted, all on recorderSha256/adapterSha256. Both sides
re-record, so neither side's hashes fit the merged source. Re-recorded, seeded
from theirs so a recorder that failed to run would fail loudly.

Twelve files written by the re-record; the other 705 changed goldens were staged
by the merge and are main's. Behaviour-preserving, by multiset comparison of
added vs removed content lines with pool keys and hash fields normalised out:

  net added:   0
  net removed: 0

Only the 24 source-hash lines moved - a pure recorder-source shift with no
semantic change. Re-validated in normal (non-record) mode: 17 files, 821 passed.
…h receipt

main landed `unchecked-rpc-reader-inventory.ts`, a ratchet on RpcOperation
readers that re-type their reply instead of validating it. Its ceiling for
mobile-workspace-create-operations.ts is 4, counted on a tree without this
branch's `agentLaunchRun`, so the merge produced "listed 4, found 5".

The inventory's own header prescribes this case: a merge is the one time a line
goes up without a migration undoing itself, and the instruction is to raise it
and name the PR that brought it. It describes main landing an operation the
branch never saw; here it is the mirror - the branch holds one main had not
seen - so the line is annotated with #19850 rather than left bare.

Not converted to `rpcResultVariant(variant, schema)`, which would lower the line
instead. That is a validation change rather than a migration, which is exactly
what the file's own comment says these five readers deliberately are not; the
agent.launch reply is already guarded at the consumer, where
readAgentLaunchCreateOutcome returns null on a malformed payload and the create
surfaces "Failed to create workspace". Writing a schema now would also target a
reply shape #20999 is actively redefining.

Ablated: with the line back at 4 the ratchet fails "listed 4, found 5"; at 5 it
passes.

@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 in this delta. Approval is withheld only because an earlier Pullfrog thread on the base branch's replay behavior (agent-launch.ts, now outside this PR's diff) is still open — nothing in these commits touches it.

Reviewed changes

This run reviews the delta since the prior pullfrog review at 5c58ad38fd — merge a599c3bca1 ("Merge branch 'main' ...") and commit 313f356a32 ("chore(mobile): raise the unchecked-reader ceiling for the agent.launch receipt").

  • main merged in, with a mechanical golden re-record — all 705 goldens now carry one uniform recorderSha256 d08bf9cd… and baseline a28085ad…; the 12 settings goldens keep adapterSha256 c2eed306…. No golden body changed, so every PR behavioural assertion still holds. The merge also re-wrapped two main-side files (serve-stdout-boundary.ts, BrowserPane.tsx) into their single-line form; oxfmt --check passes on the merged tree and fails on main's multi-line version, so that is a formatting fix rather than a formatting violation.
  • The agent.launch reader is named in the unchecked-reader inventory — mobile-workspace-create-operations.ts's ceiling moves 4 → 5 with a comment naming #19850, following the inventory's own merge rule. The file holds five rpcUncheckedPayloadReader calls, so the listed ceiling matches what the ratchet will observe, and no other entry changed.

Verification this run: all 705 goldens share the single new recorder hash and baseline; oxfmt --check clean on the two re-wrapped files. mobile/node_modules is absent here, so the mobile suite was not run.

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

@brennanb2025
brennanb2025 merged commit 97aa5ff into main Sep 16, 2026
29 checks passed
Jinwoo-H added a commit that referenced this pull request Sep 16, 2026
Every golden and the scenario manifest take main's fenced corpus: the 705
shared goldens are byte-identical to `origin/main` and the manifest keeps
main's `baseline` (9add08b). The branch's 11 scenarios and 31 goldens
ride along unrecorded here; the next commit repins and re-records them.

`unchecked-rpc-reader-inventory.ts` auto-merged cleanly: the session block
stays deleted, and main's raise of `mobile-workspace-create-operations`
from four readers to five (#19850's `agent-launch-receipt`) survives.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…agent (stablyai#19850)

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

* feat(agent-launch): add the launch intent and the one executor that runs it

The sequencing around the launch decision was duplicated per surface, and the
duplicate is where the bug lives. A new worktree was created agent-first, so
its startup terminal WAS the agent and the structured branch below it could
never be reached — every new-worktree launch was a PTY regardless of the user's
default. Orchestration fixed that for itself in stablyai#19431; mobile and the CLI
still have it.

`executeAgentLaunch` inverts the order once, for everyone. When the preference
is structured the worktree is created with NO startup agent, the executing host
is then asked whether it can host a session for the workspace that now exists,
and only then is a surface created. The host verdict cannot be hoisted above
creation: `agentSession.createSupport` only answers for a workspace it can
resolve, which is why the decision stays in two halves.

Agent-first creation is deliberately preserved for PTY launches — it is what
sequences the agent's startup command behind the setup runner, so wait-for-setup
comes for free there.

What actually differs per surface is only how a surface is built (an
orchestration worker's session takes a dispatch hold and a mailbox a plain
launch must not take), so that is injected as a factory rather than branched on.

The intent also strips the reserved agent fields from a migrated create payload:
a caller moving off `worktree.create` passes its existing params, and a stale
`startupAgent` in there would re-create the very path this replaces.

Tests assert order and arguments, not just the resulting mode. Reintroducing
agent-first creation reddens 4 of 11.

* feat(agent-launch): expose the launch executor as the agent.launch RPC

Adds `agent.launch` — one host-side method that decides structured-vs-terminal and
creates the surface — wired to the real runtime factories: `createManagedWorktree`
for the workspace, forking on `startupAgent` exactly as the orchestration worker
path does; `createStructuredAgentSessionForWorktree` for a chat session; and
`createTerminal` for a PTY agent. Allowlisted for mobile, which is the surface the
routing gap was reported on.

`worktree.create` is untouched. Its `startupAgent` keeps meaning "spawn a PTY agent"
verbatim, because it answers with `agentTerminalHandle` only on that path: a host
that quietly routed it to a structured session would hand every older client a
response with no handle and no error. All new behaviour sits behind
`agent.launch.v1`, which the host now advertises and a remote client must negotiate,
so a client that does not gets today's behaviour unchanged.

* feat(mobile): route workspace creates through agent.launch

Picking an agent on the mobile create sheet always produced a terminal, even
when the user's default was native chat, because all three create paths put
`startupAgent` on `worktree.create`. That means "create the worktree
agent-first", so its startup terminal IS the agent and the structured branch
below it is unreachable — while the same phone's in-workspace "+" button opened
a chat.

The blank, branch and new-branch creates now send the same payload through
`agent.launch` and let the host settle the surface. `worktree.create` is
untouched, and a host that does not advertise `agent.launch.v1` (read from the
existing `status.get` probe) keeps today's path exactly.

Work-item creates stay on `worktree.create`: they pre-fill the issue/PR URL as
an unsent `startupDraft`, which a structured session cannot hold yet, so routing
them would submit the URL as a first turn.

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

* chore(agent-launch): carry agent.launch through main's RPC typing and casting gates

The typed-method contract, the generated params catalog and the
`assertionStyle: never` casting scan all landed after this branch's base.

- AGENT_LAUNCH_METHODS kept an `RpcMethod[]` annotation, which widened its
  method name to `string` and broke assignability; every sibling infers instead.
- `agent.launch` binds a schema under src/main, so it joins the catalog's
  RPC_METHODS_WITHOUT_SHARED_PARAMS and the parity gate's hand-listed twin.
- The now-typed methods make most test casts unnecessary; the few that remain
  carry the line-specific SAFETY rationale the casting gate requires.

* test(mobile): supply the agent-launch fixture the create-submit recording needs

The golden RPC recordings landed upstream while this branch was out, so they
first met agent.launch here. Three things had to happen, and only one of them is
a fixture bump.

1. workspace-settings-mounts.ts mounts useNewWorkspaceCreateSubmit against a
   fixture model that throws on any member it was not given. This PR added a
   required getAgentLaunchSupport, so the submit aborted with "Missing model
   fixture" before it ever issued the create, and three cleanup checkpoints
   vanished. That read like a product regression and was not one. Supplying the
   member restores the recording byte-for-byte; it is pinned false for the same
   reason the cutover probe is, so the baseline stays on worktree.create.

2. Editing that adapter moves adapterSha256 for the twelve settings goldens it
   mounts. Their recordings are unchanged - header only, by design: the digest
   is per-golden so editing a module fails exactly the goldens that mounted it.

3. Five goldens changed behaviourally, and both changes are this PR's:
   the capability probe now reports agentLaunch, and a create whose reply
   carries no worktree returns "Failed to create workspace" instead of throwing
   a TypeError off an unguarded result.worktree read. The launch route needs
   that guard, since a receipt can arrive without a worktreeId.

* refactor(mobile): decode the launch receipt instead of asserting its shape

The changed-code quality gate refuses type assertions, and the eight it flagged
were worth removing rather than suppressing.

The production one was the point. readAgentLaunchCreateOutcome asserted the RPC
payload into Partial<AgentLaunchResult> and then runtime-checked it anyway, so
the assertion bought nothing and claimed a contract the host had not proven. It
now narrows with `in` and validates each hop, which is the same nullability
question readCreateResult already answers on the sibling path - a launch receipt
can legitimately arrive without a worktreeId. AgentLaunchCreateOutcome ties
worktreeId to the shared contract so a change there fails this reader's
typecheck rather than passing a differently-typed field through.

The test fakes claimed a whole RpcClient via `as unknown as RpcClient` while
implementing one member. They now build a typed literal, matching the pattern in
use-mobile-structured-agent-options.test.ts. The read sites cast params and then
read one field; they now assert the payload with toMatchObject, which removes
the cast and pins more of the shape than the cast did.

Also pins the warning passthrough, which nothing covered: a terminal launch that
seats the workspace but cannot start the pty reports why, and the absent, blank,
non-string and structured-surface cases report nothing. Writing that test caught
a real drop I had introduced in the reader.

* ci(mobile): re-run Mobile Checks when a shared capability changes

Mobile Checks is path-filtered to mobile/**, but mobile imports the negotiated
capability names straight from src/shared/protocol-version.ts and records the
whole capability read verbatim in its goldens. So a capability added desktop-side
rewrites a mobile fixture while never triggering the suite that would catch it.

That is what happened here: stablyai#19849 introduced agent.launch.v1 and Mobile Checks
never ran on it. Verified at the run level rather than by check name - the
window-free check-runs API on 3837ae8 returns 49 check-runs across six runs
(PR Checks x2, PR test LoC x2, Track Community PRs, Review) and no Mobile Checks
among them. The breakage surfaced only in this PR, which happens to touch mobile/**.

The workflow already concedes this pattern for terminal-file-link-conformance.ts;
protocol-version.ts has the stronger claim, since mobile records its output.

Also corrects the mount adapter's SAFETY comment. It claimed the recorder supplies
only the members the hook reads, which was false the moment the hook gained a
required getAgentLaunchSupport - and the assertion it annotates is exactly what
stopped the compiler from saying so. The twelve goldens are adapterSha256 churn
from that comment: every body is byte-identical, which is the digest doing its job.

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

* docs(agent-launch): stop the executor comment claiming a migration that has not happened

The header asserted two things the tree does not support: that every launch
surface routes through the executor, and that the mode decision "already lived"
in `agent-launch-mode`. `agent.launch` is the executor's only consumer, and
`orchestration-worker-start-mode.ts` is byte-identical (blob 92dc5c6, 217
lines) at the merge base and all three stack heads, still used by workers.ts.
Describe the two live copies and leave the cutover to later stack work.

* fix(agent-launch): preserve setup and refusal fallbacks

* refactor(mobile): parse the launch outcome into a named type at its boundary

anti-slop/no-object-parameters flagged terminalLaunchWarning's `result: object`.
The rule is pointing at a real seam rather than a style nit: the helper advertised
a loose object and did the narrowing inside itself, so every caller handed it
unparsed wire data and nothing downstream held a real type.

Parsed at the boundary instead. parseTerminalLaunchOutcome takes `unknown` and
returns TerminalLaunchOutcome | null, so the narrowing happens once, where the
untrusted payload enters, and the consumer works with a named type.

The type is taken from the shared contract rather than restated - a Pick over the
terminal member of AgentLaunchOutcome - so a change to that union fails here
instead of flowing through. `handle` is deliberately excluded: nothing reads it,
and requiring it would drop the warning off a reply that omitted one, which is a
behaviour change smuggled in under a typing change.

No assertion and no config exemption: reintroducing `as Partial<AgentLaunchResult>`
would trade this finding for the defect removed earlier in this branch, and the
rule is correct here.

The rule arrived with the merge-forward (stablyai#20781, newer than this branch's
merge-base), and anti-slop is not one of the changed-code gate's six scans - it
runs only repo-wide - which is why a clean local gate did not predict it.

Behaviour is unchanged across all five warning cases, and the positive case was
re-ablated on the new parser: dropping the warning reddens exactly it,
1 failed | 18 passed, restored byte-identical to 19 passed.

* fix(agent-launch): dedupe complete launch and cancel setup wait

* fix(agent-launch): memoize the whole launch so a replay cannot mint a second session

A replayed agent.launch could create a second structured session in the same
worktree, with activate: true.

dedupeWorktreeCreate wrapped only the worktree half, inside the workspace
factory. On a replay the create was reused, and the executor then continued to
createSurface and built another surface inside it. The terminal route hid this:
its cached create carries a startup terminal handle, so the executor returns on
early. A structured create has no handle by construction - that is the whole
point of the structured fork - so it fell through every time. Mobile replays
this method deliberately on a delivery-ambiguous response, up to five attempts,
so the path is reachable by design rather than in theory.

The handler now wraps the entire launch in the same dedupe, on the same
(repo, clientMutationId) identity, exactly as worktree.create wraps its own
body. A replay returns the original AgentLaunchResult instead of re-running
createSurface, which makes the two routes replay-identical.

The inner dedupe is removed rather than kept. Wrapping both levels on one key
deadlocks: dedupeWorktreeCreate stores the in-flight promise before the inner
call runs, so the inner call would be handed the outer's promise, which is
waiting on it. The launch-level memo subsumes the worktree-level one.

Failures are still dropped rather than cached, so an unknown outcome stays
unknown instead of replaying as a fabricated success.

The guard replays a STRUCTURED launch: the terminal route cannot reproduce this
and a test there would pass either way. Ablated against the pre-fix files -
1 failed | 22 passed, "expected vi.fn() to be called 1 times, but got 2 times",
which is the duplicate session - then restored to 23 passed. The stub's dedupe
had to be made faithful for that to be observable; the shared one passes through
so other tests can see raw calls.

* Revert "fix(agent-launch): memoize the whole launch so a replay cannot mint a second session"

This reverts commit 59bc5e9.

The same defect was already fixed upstream on this stack's base branch by
539e283, which landed while this was being written. That change is broader
(it also cancels the setup wait) and namespaces the dedupe key, so it supersedes
this one. Reverting rather than hand-merging keeps a single implementation
instead of a hybrid nobody chose.

The behavioural guard from this commit is ported back on top of the upstream
implementation separately: it asserts exactly one structured session survives a
replay, where the upstream tests assert the dedupe wiring.

* ci(mobile): close the round-1 signal gaps around agent.launch

Three review findings, all narrow.

Mobile Checks is path-filtered, and this branch made mobile's types depend on the
shared RPC contract: rpc-params-contract.ts is a type-only re-export of the
generated params catalog, and mobile/tsconfig.json includes **/*.ts. So a
desktop-only edit under src/shared/rpc-contract/ could break mobile's typecheck
with no mobile signal at all - the same blind spot the protocol-version.ts entry
closed, one directory over. Added src/shared/rpc-contract/** to the paths filter.

agent.launch had no cross-version trigger. Added the three prefixes a paired peer
actually exchanges: the intent contract, the wire schema, and the RPC method.
src/main/agent-launch/ is deliberately NOT listed - the executor shapes behaviour
but is not itself wire, and AgentLaunchResult's shape is already covered by
agent-launch-intent. Extending the cross-version SUITE to cover a negotiated
handshake is separate work, not this.

The break branch that answers an accepted-but-empty reply with "Failed to create
workspace" had no unit coverage; the golden that used to discriminate it
collapsed five partitions into one shared error when the null guard replaced the
unchecked read. Covered on BOTH routes - worktree.create with no worktree.id and
agent.launch with no worktreeId - since the branch serves both. Ablated by
bypassing the guard: 2 failed | 11 passed, the two new cases returning a
fabricated worktree instead of the error, restored to 13 passed.

* fix(agent-launch): give a launch one place to say the workspace is incomplete

createManagedWorktree reports an unspawned startup terminal or an uncopied
working tree as a top-level `warning`, and worktree.create hands it straight to
mobile. The launch path narrowed that result down to
{worktreeId, startupTerminalHandle} and dropped it, so every agent.launch create
lost a warning the old method surfaces - on both arms.

The channel was also asymmetric by accident rather than design: a terminal
outcome could carry `warning`, a structured one had nowhere to put it, so the
arm this PR exists to enable was the arm that could not report an incomplete
create at all.

Now there is exactly one place a launch warning lives: AgentLaunchResult.warning,
at the top level. It is about the create as often as the surface, it applies to a
structured session and a terminal alike, and a reader should not branch on
outcome.kind to discover the workspace it just opened is missing something. The
terminal arm's own `warning?` is removed rather than left beside it - two homes
for one fact is how they drift. Every producer folds in: the create, the surface,
and the refusal downgrade.

Consumer census before removing it: one production reader (mobile's
readAgentLaunchCreateOutcome) and no others - the renderer and mobile launch
call sites never read it. The mobile reader now reads the top-level field, which
also lets its outcome parser go away entirely.

Guard ablated by restoring the pre-fix narrowing: 2 failed | 24 passed, both
carriers reporting `expected undefined`, which is the dropped warning itself;
restored to 26 passed. The third case asserts an absence and stays green under
the mutation by construction - it pins shape, not the defect.

* fix(agent-launch): combine both launch warnings instead of dropping one

Round 2 found the comment here was false. A create warning and a surface warning
CAN both be set, on two reachable paths:

  1. The create warns precisely BECAUSE it produced no startup terminal -
     didSpawnStartup stays false when that spawn throws, and
     orca-runtime-create-managed-worktree.ts:283 gates startupTerminal on it - so
     the executor's early return is skipped and a second surface is built, which
     can warn too.
  2. An untracked-copy warning, then a definitive structured refusal downgrading
     to a terminal that also warns.

`??` kept the first and lost the second with nothing saying so. They are now
combined the way the create combines its own failures - appendFailure in
runtime-local-worktree-terminal-startup.ts, and the startup-terminal catch in
runtime-remote-managed-worktree-create.ts - which append rather than replace.

The comment is rewritten to say what is true, and records the gap NOT fixed
here: a create warning about a failed startup terminal is stale once the launch
recovers by building a working one, so a user can be told the agent did not start
while looking at it. Distinguishing those needs createManagedWorktree to stop
multiplexing two unrelated failures into one string.

Guarded and ablated: restoring `??` reddens exactly the new test, with the
surface clause missing from the received string; restored to 27 passed. The
structured-create stub had to admit its real ok-or-refusal union for the
downgrade path to be modellable at all - it previously declared only the ok arm.

Also: mobile.yml gains src/shared/agent-launch-intent.ts. It is the sole holder
of the agent.launch RESULT shape - the rpc-contract catalog holds params only -
and mobile imports it as a value. CROSS_VERSION_WIRE_PREFIXES already treats it
as wire-critical; without this, one gate does and the other cannot see it.

And the agent-first warning test no longer pairs "startup terminal failed" with a
returned handle, a combination the producer cannot emit.

* fix(mobile): read a launch warning an older host nests on the outcome

agent.launch moved `warning` from the terminal outcome to the top level of the
result. That is the right shape - a reader should not branch on `outcome.kind`
to learn the workspace it just opened is incomplete - but on the wire it is a
REMOVAL, and mobile only read the new place.

A host built before the move still advertises the same `agent.launch.v1`
capability, so the capability probe cannot tell the two apart and mobile takes
this route against one:

  protocol-version.ts:360       AGENT_LAUNCH_RUNTIME_CAPABILITY is in
                                RUNTIME_CAPABILITIES, the host list
  orca-runtime-get-status.ts:64 publishes it via status.get; the filter drops
                                only browser.screencast.v1 and three E2E-gated
                                capabilities, never agent.launch
  agent-launch-executor.ts      such a host writes warning INSIDE outcome

The result was a regression rather than a contract cleanup: the worktree.create
path this replaces returned the warning at the top level and mobile read it, so
a create that seated the workspace but could not start the agent surface - pty
exhaustion, untracked files not copied - stopped explaining itself on the phone.

Read both shapes for as long as such a host can be paired. Top level wins, and
cannot be shadowed: AgentLaunchOutcome has no `warning` on either arm, so a
current host cannot nest one.

The test that pinned the old behaviour is inverted here. Its comment was the
actual defect - it framed a legitimate warning from an older peer as a stale
shape to defend against, which is what made dropping it look deliberate.

* chore(mobile): raise the unchecked-reader ceiling for the agent.launch receipt

main landed `unchecked-rpc-reader-inventory.ts`, a ratchet on RpcOperation
readers that re-type their reply instead of validating it. Its ceiling for
mobile-workspace-create-operations.ts is 4, counted on a tree without this
branch's `agentLaunchRun`, so the merge produced "listed 4, found 5".

The inventory's own header prescribes this case: a merge is the one time a line
goes up without a migration undoing itself, and the instruction is to raise it
and name the PR that brought it. It describes main landing an operation the
branch never saw; here it is the mirror - the branch holds one main had not
seen - so the line is annotated with stablyai#19850 rather than left bare.

Not converted to `rpcResultVariant(variant, schema)`, which would lower the line
instead. That is a validation change rather than a migration, which is exactly
what the file's own comment says these five readers deliberately are not; the
agent.launch reply is already guarded at the consumer, where
readAgentLaunchCreateOutcome returns null on a malformed payload and the create
surfaces "Failed to create workspace". Writing a schema now would also target a
reply shape stablyai#20999 is actively redefining.

Ablated: with the line back at 4 the ratchet fails "listed 4, found 5"; at 5 it
passes.

---------

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