Skip to content

Agent launches carry the surface that started them - #23697

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/agent-launch-caller-source
Sep 29, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/agent-launch-caller-source

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​301 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​288
Prod 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​100 $\color{#cf222e}{\Huge{\mathbf{−}}}$​70 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30

ELI5

When Orca itself builds an AI agent's launch, it now always notes which part of Orca asked for it — the desktop app, the orca command line, or an orchestration worker, or unknown when the caller did not say. Before, agents started from the command line or by orchestration carried no such note, so Orca could not tell where they came from. Today that note is used in one place: Orca's record that an agent started (the agent_started event), which is how launches are counted per surface.

What Changed

Before: the host recorded which surface started an agent only when the caller happened to name one, and silently recorded nothing otherwise. The orca CLI (worktree create --agent/--prompt, and orchestration worker-start, which the host runs as an orchestration worker) never named one, so those launches were invisible.
After: every agent the host builds is attributed to a surface. A caller that names none — including older CLIs and phones — is recorded as unknown rather than dropped.

Mechanism:

  • One resolver, agentStartedTelemetry in src/main/agent-launch/agent-started-telemetry.ts, replaces two identical private copies. It keeps a known surface and resolves a missing or unrecognized one to unknown.
  • It is applied where the host builds a fresh agent's startup command: the runtime's terminal create for a named startupAgent (used by agent.launch, orchestration workers in an existing worktree, and federation); the worktree-create builder for a named agent (used by worktree.create, agent.launch into a new worktree, orchestration workers in a new worktree, and headless-server automations, both the ones that create a workspace and the ones that run in an existing one); the worktree-create builder for a startupDraft, where the host picks the agent itself (the task-driven create from the phone and from a desktop connected to a remote Orca server); and terminal.createAgentSession, which a desktop connected to a remote Orca server, and the web client, use to start a new agent tab. The draft builder and terminal.createAgentSession previously recorded nothing at all; terminal.createAgentSession names no surface on the wire (its params are strict), so it records unknown.
  • createTerminal takes the caller's launchSource string instead of a prebuilt record, and derives the record only from it, so the host takes the agent kind from the agent it actually resolved.
  • worktree.create gains an optional launchSource, sharing one open-string schema (LaunchSourceParam) with agent.launch. The CLI sends cli. Inside an agent.launch create, the launch's own launchSource is authoritative, so a copy in the create payload is stripped with the other reserved agent fields.
  • Orchestration workers name themselves orchestration host-side; nothing new crosses the wire for them.
  • Two guards keep the next host builder from forgetting the record, the mistake review caught twice: the worktree startup builders' return type requires telemetry, so dropping it fails to compile; and a test lists every host-side call that builds an agent's startup command with its decision (attributes, resume, or the phone follow-up), so a new call fails until its author decides whether it is a fresh start.
  • The surface vocabulary gains cli, mobile and orchestration. mobile is added now so hosts from this release already recognise it when the phone starts sending it; the phone change is a separate follow-up.

Not changed: a bare agent command typed into terminal create --command stays unattributed, as before. Structured chat sessions still report no start on any surface, desktop included. Three host paths still record nothing, as before: the startup command a desktop connected to a remote Orca server prebuilds for a new workspace (it arrives as a plain command); an agent tab the phone opens with session.tabs.createTerminal (the host builds that launch, but when a desktop window is open it hands the spawn to that window, where no record travels today); and resuming an agent session (a resume, not a new start). These gaps predate this change. Headless automations name no surface, so they are now recorded as unknown, which is what desktop automations already report.

Why

Launches are converging on one entry point used by desktop, phone, CLI, orchestration and later plugins, so the surface that started each launch has to come with the launch itself. Today the host uses it only for the agent_started record; it is not stored with the agent, and no host behaviour depends on it. The desktop does read launch_source in one place, a Windows focus guard for its own sidebar history resumes, which a host-built launch (always a new start) can never match. Resolving the default in the host, at the point the agent is built, means a new caller cannot silently opt out — the alternative, asking each caller to remember, is exactly how the CLI and orchestration went missing.
Deriving the surface from the connection type was considered and rejected: it only distinguishes phones, since the CLI and a remote desktop connect the same way, so it would be a second, partial defaulting rule.
Mixed versions stay safe: the wire field is an open string, so an older host receives a newer client's surface without refusing the launch (it records nothing, as today), an older host without the field ignores it, and an older client sending nothing to a new host is recorded as unknown.

Linked Issue

None; part of the agent-launch series.

Visual Proof

N/A — no UI or interaction change; this changes what the host records about a launch, not what the user sees.

Testing

  • I manually tested these changes locally

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

  • New tests fail without the change (11 failing when the source files are reverted to main) and pass with it: runtime attribution for a named, missing and unrecognized surface; the startup builder's unknown default; worktree.create passing the surface through (including an unrecognized one without refusing the create); the CLI sending cli; orchestration workers sending orchestration in both the new-worktree and existing-worktree paths.

  • Agent sessions the host builds (terminal.createAgentSession, added in review) are recorded as unknown; this fails without the fix.

  • Startup-draft creates (added in review): the draft builder attributes both of its launch shapes, a named surface or unknown, and a runtime create passes the caller's surface through to the spawned agent. These fail without the fix.

  • Attribution guards (added in review): host-agent-startup-attribution.test.ts fails on a new builder call in a new or already-listed file (reformatted across lines too), on a stale count, and on an unknown decision; commented-out calls are ignored. Dropping telemetry from a worktree startup builder is a compile error.

  • Regression guards that pass on both: a bare typed command stays unattributed; an agent.launch create uses the launch's own surface, never the create payload's copy.

  • Existing agent.launch tests updated: the handler now forwards the caller's surface to the runtime instead of building the record itself.

  • pnpm tc:node and pnpm tc:cli pass; oxlint and check:code-quality:changed are clean; 1,512 test files pass across src/cli, src/shared, src/main/runtime/rpc, the runtime service suite, src/main/agent-launch, src/main/ipc/pty and src/main/agent-hooks. One timing test (src/cli/runtime/transport.test.ts keepalive) failed once under full load and passed 3/3 in isolation; it is unrelated.

  • Live host check on a separate Mac, with a development build of this branch and of main (a QA-only log line prints each record the host would send, since development builds send none; every agent was a stand-in process): CLI worktree create --agent records cli; orchestration workers in a new and an existing worktree record orchestration; agent.launch with no surface or an unknown one records unknown and is not refused; a startup-draft create records the named surface or unknown; terminal.createAgentSession records unknown once and a replay adds nothing; a bare terminal create --command claude records nothing; the desktop quick launch records tab_bar_quick_launch on both builds; and a CLI built from main against this build records unknown while the create succeeds. main records nothing for any of the host-built launches.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: no new input is trusted; the surface is a label parsed leniently, and the host never reads it as behaviour.
Cross-platform: no platform-dependent code.
SSH/remote: the resolver runs in the Orca host that builds the launch, the same place for local, SSH and folder workspaces, through the same create paths.
Mobile: no mobile code changes and no recorded fixtures move. Phones keep working unchanged; their agent.launch and task-driven creates are recorded as unknown until the follow-up sends mobile, and their session-tab agents stay unattributed (see Not changed).
Desktop fallback: when the host cannot spawn a startup it built and hands it to the desktop to spawn instead, that startup now carries the record, so the desktop's spawn records agent_started (or agent_error for that agent if the spawn fails). The desktop also reads the record's agent kind, as it already does for startups it builds itself, to mark the tab as that agent and to treat the tab's output while hidden as an agent's (restored from a snapshot on reveal, with its startup terminal queries still answered). Before, such a tab was left unmarked and got that hidden-output handling only when the desktop recognised the launch command.
Backwards compatibility: covered in Why; the new field is optional and open, and no capability or opcode is added.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The host now attributes every agent it builds to the surface that asked for
it, resolving a missing or unrecognized surface to 'unknown' in one place
instead of silently skipping it. The CLI names itself on worktree.create and
orchestration workers name themselves host-side.
The host builds a third kind of agent launch: a worktree.create with a
startupDraft and no startupAgent, where the host picks the agent itself.
It carried no launch record at all and ignored the caller's launchSource.
Route it through the same resolver as the other two builders, and derive
the startupAgent terminal record only from the resolver so no prebuilt
record can stand in for it.
…nches

terminal.createAgentSession builds a fresh agent's launch on the host, like the
other startup builders, but spawned it with no launch record, so those launches
were never counted. Record them through the same resolver; the request names no
surface, so they count as unknown.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready for review (still a draft; not merged)

Head 63a5a48ee32. Four review loops, one independent architecture challenge, readiness checks at the start and end, and a live host check on a separate Mac.

What review changed

  • 63fa9e4fb0a: a workspace created with a drafted prompt, where the host picks the agent (the phone's task create, and a desktop connected to a remote Orca server), started an agent with no record at all. It now goes through the same resolver.
  • c66d104d10b: terminal.createAgentSession, which a desktop connected to a remote Orca server and the web client use to open a new agent tab, also recorded nothing. It now records unknown, since its request names no surface.
  • 63a5a48ee32: two review loops found the same kind of miss, a host builder that forgot the record, so an architecture review was run. It kept the design: every single choke point would also count resumes, desktop-supplied launches, or bare typed commands. It added two guards instead. The worktree startup builders' return type now requires the record, and a test lists every host-side call that builds an agent's startup command with its decision, so a new one fails until someone decides.
  • The description was rewritten to match the code, including what is still unattributed and why.

Verification

  • Typecheck tc:node passes at 63a5a48ee32. tc:cli passes at 63fa9e4fb0a; no CLI file changed after that.
  • Focused suites pass (105 tests), and so does the runtime suite (1,324 passed, 1 skipped). Every new test was shown to fail without its fix.
  • CI: every check passes except RPC recording pin (Mobile Checks). That check is also red on main at 29c7d5d9835 and e8e144bf3ca, and this PR changes nothing under mobile/, so it is not caused by this change.

Live host check (separate Mac, development build of this branch vs main)

  • Development builds never send telemetry, so a QA-only log line printed each record the host would send. Every agent was a stand-in process.
  • Branch results:
    • CLI worktree create --agent → cli.
    • Orchestration workers in a new and in an existing worktree → orchestration.
    • agent.launch with no surface, or an unknown one → unknown, and the launch is not refused.
    • A draft create → the named surface, or unknown.
    • terminal.createAgentSession → unknown once; a replay adds nothing.
    • A bare terminal create --command claude → nothing.
    • The desktop quick launch → tab_bar_quick_launch, on both builds.
    • A CLI built from main against this build → unknown, and the create succeeds.
  • main records nothing for any host-built launch.

Round 1 results (head 63fa9e4):

Live host check results table

CLI worktree create --agent claude --prompt "qa ping" launched a stand-in agent, recorded as cli:

CLI-created worktree with its agent terminal

terminal.createAgentSession agent tab, recorded as unknown, at head 63a5a48:

Agent session tab created by the host

Desktop quick launch at head 63a5a48, still recorded as tab_bar_quick_launch:

Desktop quick launch

Known gaps (all predate this PR and are listed in the description)

  • An agent tab the phone opens with session.tabs.createTerminal still records nothing. That is part of the phone follow-up.
  • The startup command a desktop prebuilds for a new workspace on a remote Orca server still records nothing.
  • Resumes are not new starts and record nothing.

Not covered live: orchestration federation to a paired server (the rig had no paired server), and desktop entry points other than the quick launch, which this PR does not change.

@brennanb2025
brennanb2025 marked this pull request as ready for review September 29, 2026 00:25
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Adds launch-source tracking to agent startup telemetry.

The PR should not merge until replay fingerprints ignore the newly reserved nested launch source.

Findings

  1. P1 Ignored source causes replay conflict ▶
  2. P2 Call counts miss replacements ▶

Summary

The PR centralizes host-built agent-start attribution, adds CLI and orchestration surface labels, and records missing or unrecognized labels as unknown.

  • Propagates launch sources through terminal and worktree creation.
  • Adds tests and a call-site guard for host startup builders.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  C[CLI or orchestration caller] --> R[Runtime create path]
  R --> B[Host startup builder]
  B --> A[Resolve launch source or unknown]
  A --> P[PTY spawn]
  P --> E[agent_started]
Loading

Reviews (1) · Last reviewed commit: "test(agent-launch): require an attributi..."

'startupCommandDelivery'
'startupCommandDelivery',
// The launch carries its own; a create's copy would be a second, possibly contradicting, answer.
'launchSource'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Ignored source causes replay conflict A create payload's launchSource is now ignored when the launch runs, but it is still included when the host fingerprints the request. If a retry uses the same operation ID and changes or omits only that ignored copy, the host returns agent_session_operation_conflict instead of replaying the launch result. Exclude the reserved field from the fingerprint too.

Knowledge Base Used: Relay protocol and transport

Comment on lines +75 to +87
it('has an attribution decision for every builder call', () => {
const undecided = [...found]
.filter(([path, calls]) => calls > (LISTED.get(path)?.calls ?? 0))
.map(([path, calls]) => `${path}: ${calls} calls, ${LISTED.get(path)?.calls ?? 0} decided`)
expect(undecided, `New host-built agent startup. ${DECIDE}`).toEqual([])
})

it('has no stale entry', () => {
// A count left above reality lets the next call in that file land without a decision.
const stale = [...LISTED]
.filter(([path, entry]) => entry.calls > (found.get(path) ?? 0))
.map(([path, entry]) => `${path}: ${found.get(path) ?? 0} calls, ${entry.calls} listed`)
expect(stale, 'Lower or delete the entry to match the calls that remain.').toEqual([])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Call counts miss replacements The guard compares only the number of builder calls in each file. Replacing an attributed call with an unattributed one leaves that number unchanged, so all these checks pass and the new launch can go uncounted. Checking call-site identity or attribution at each site would close this non-blocking coverage gap.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b4ca4d37-8d25-49c4-9f6d-4bda2d19453e

📥 Commits

Reviewing files that changed from the base of the PR and between 409462a and 63a5a48.

📒 Files selected for processing (29)
  • src/cli/handlers/worktree.ts
  • src/cli/index-worktree-create-agent.test.ts
  • src/main/agent-launch/__fixtures__/host-agent-startup-call-sites.txt
  • src/main/agent-launch/agent-started-telemetry.ts
  • src/main/agent-launch/host-agent-startup-attribution.test.ts
  • src/main/runtime/orca-runtime-activate-managed-worktree.ts
  • src/main/runtime/orca-runtime-create-agent-session.ts
  • src/main/runtime/orca-runtime-create-managed-worktree.ts
  • src/main/runtime/orca-runtime-resolve-worktree-removal-target.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-12.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-04.spec.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/main/runtime/rpc/methods/agent-launch.test.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation.ts
  • src/main/runtime/rpc/methods/orchestration/worker/composed-workers.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-topology.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-worktree-creation.ts
  • src/main/runtime/rpc/methods/orchestration/worker/workers-new-worktree.test.ts
  • src/main/runtime/rpc/methods/worktree-create-args.ts
  • src/main/runtime/rpc/methods/worktree-create-launch-source.test.ts
  • src/main/runtime/runtime-managed-worktree-create-types.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/runtime-worktree-agent-startup.test.ts
  • src/main/runtime/runtime-worktree-agent-startup.ts
  • src/shared/agent-launch-intent.ts
  • src/shared/rpc-contract/agent-launch-params.ts
  • src/shared/rpc-contract/launch-source-param.ts
  • src/shared/rpc-contract/worktree-create-params.ts
  • src/shared/telemetry-property-schemas.ts

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


📝 Walkthrough

Walkthrough

The change forwards launch-source values from CLI, RPC, and orchestration callers into worktree and terminal startup paths. Runtime startup builders now attach agent-start telemetry to host-built agent launches. Missing or unrecognized sources are recorded as unknown. Tests cover source forwarding, telemetry values, and startup call-site attribution.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 63a5a

No actionable issue remains identified for this change; it is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 63a5a

Launch-origin reporting changes across several launch paths, but the inspected behavior does not let an origin label authorize a launch or select a workspace. The main residual risk is that callers can claim an origin for reporting; the effect of that claim outside launch counts is not established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — For the inspected flow, a falsely claimed origin can affect agent-start reporting for a launch the caller can already request; it does not change the checked spawn-authority decision. The independent reach and uses of downstream reports remain unknown.

Trust Boundaries and Controls

  • observed — RPC launchSource is caller-asserted. The host constrains the emitted value to a known telemetry enum or unknown, but that validation does not bind a claimed surface to caller identity.

Resilience and Maintainability Implications

  • observed — The inspected operation identity excludes launch attribution, so changing the label does not create a distinct worktree retry identity. Telemetry is emitted on the inspected PTY path only after spawn commit.

Hardening Proposals

  • proposed — If launch-origin counts are later used for auditing or access decisions, derive or verify the surface from authenticated caller context rather than treating the supplied label as proof of origin.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 28 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: agent launches now carry their originating surface.
Description check ✅ Passed The description is complete and aligned with the template. It explains the change, rationale, testing, compatibility, known gaps, and the lack of UI impact. The linked issue is listed as none, and the…
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: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 28 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@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

  • Host-side attribution resolver — new agentStartedTelemetry unifies the two private copies and resolves a missing/unrecognized surface to 'unknown' instead of dropping the record, so a launch is never silently uncounted.
  • Runtime terminal attribution — createTerminal now takes the caller's launchSource and derives the triple from the agent it actually resolved (resolveAgentTerminalCreateOptions), leaving a bare typed command unattributed.
  • Create-path propagation — worktree.create gains an open-string launchSource, mapped to startupLaunchSource; the worktree startup builders always attach telemetry, with AttributedWorktreeStartupLaunch making omission a compile error.
  • Producer wiring — CLI sends cli, orchestration workers name orchestration host-side, terminal.createAgentSession records unknown, and launchSource is added to the reserved create fields so a launch's own source outranks a create payload's copy.
  • Vocabulary + guard — cli/mobile/orchestration added to launchSourceSchema, plus a source-scanning test that requires an attribution decision for every host-side startup builder call.

I traced every host-side builder call site in the diff and its immediate callers in src/main. Each fresh start reaches the telemetry attachment except the three gaps the description declares as pre-existing (desktop prebuilt startupCommand at worktree.create, the phone's session.tabs.createTerminal, and agent-session resume). The new tests are meaningful (they assert the exact triple, and the unchanged source would leave it undefined), pnpm tc:node passes, and oxlint is clean on the changed files. The runtime-service specs (orca-runtime-tests/*.spec.ts) fail in this container with selector_not_found, including their pre-existing tests, because no real git worktree exists here — environment, not this PR.

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

@brennanb2025
brennanb2025 merged commit a5ce825 into main Sep 29, 2026
73 of 74 checks passed
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