Skip to content

feat(agent-launch): deliver a launch prompt from the host - #21155

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/agent-launch-prompt-delivery
Sep 17, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/agent-launch-prompt-delivery

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​247
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​178

The gap

agent.launch is the one RPC every "start an agent here" entry point is converging onto, so a plugin that calls it with a prompt must get that prompt delivered without implementing delivery itself.

It did not. agentLaunchExecutor's promptReceipt had exactly one behaviour — not-delivered, always — with a comment stating the design: prompt delivery is the caller's. That was workable only while the one surface able to send a structured turn was also the one issuing the launch. Every producer and consumer of a launch-sourced outbox entry is renderer-side (structured-agent-session-outbox-storage.ts, structured-agent-session-outbox-dispatch.ts, use-structured-agent-session-outbox.ts), which is precisely why mobile and a future plugin get an agent and no prompt.

The mechanism

The host now commits a submit prompt to the structured session the launch just created, through the same path agentSession.send runs:

  1. createStructuredSession carries the create's fence out alongside sessionId/handle. A send must name the lease it was admitted against; re-reading the fence later would read whatever the session has by then.
  2. The executor, after the surface exists, calls the injected deliverStructuredPrompt. Sequencing stays in the executor (its stated job); the wire-shaped half stays in the RPC-layer surface factory (its stated job), matching how surface construction is already injected rather than branched on.
  3. commitStructuredAgentSessionLaunchPrompt builds an outbox entry and its envelope from the shared builders and calls host.send once. It answers with the committed row's id, or null.

ok is the host's own proof of the commit: performSend (structured-agent-session-turns.ts:115) appends the journal submission before dispatching and returns a refusal when the append fails, never after it. So journaled + messageId is a consequence of the commit, never a write-ahead — the id cannot name a row that does not exist.

It deliberately does not wait for the dispatch to settle. The row is committed either way, and whether the provider took the turn is the submission's own dispatchState to carry.

Why there is no fourth unknown arm

In Orca's own terms:

  • The commit is observable, so there is nothing to be unsure about at this tier. A send either appended the row or refused before appending. ok separates those two, and nothing else.
  • Ambiguity already has a tier, and it is the effect tier. AgentJournalSubmission.dispatchState is where unknown lives, and reconcileStructuredAgentSessionOutbox / the attach path already re-derive it. A second unknown beside it would be a copy that can disagree.
  • Orca's unknown in the agent-session operation ledger is the root of a documented multi-PR bug class — nothing re-derives it and it exits only by clock. A durable "still owed" verdict with no re-derivation behind it strands.
  • A fourth arm would give callers a verdict with no defined action. They could neither resend (duplicate) nor skip (lose text). not-delivered always has one: resend. A wasted resend beats silent loss.

So every non-commit is not-delivered: a refused send, an unreachable host, a throw, a terminal outcome, and a draft.

draft is not-delivered honestly, not lazily: the host has no composer. I checked — there is no host-side draft store for a structured session anywhere in src/main/native-chat or on the session record; a draft lives in the renderer composer. Claiming otherwise would be a receipt with no backing.

A delivery failure never fails the launch. The agent is already running and the workspace already exists; failing the RPC would send the caller into a retry that can produce a second workspace. The failure is reported as not-delivered and logged.

Terminal outcomes

Unchanged, and still not-delivered. createTerminalAgent passes only startupAgent to runtime.createTerminal — the host does not fold the launch text into the startup command, so it genuinely does not hand text to a PTY and must not claim handed-to-terminal. That arm stays unreachable until a host path actually writes to the pane.

Known gap, named and deliberately not fixed here: the terminal route has its own prompt transport — desktop folds the text into the launch command's argv (launch-agent-startup-prompt-plan.ts:72-77), or launches empty and pastes after readiness (:41-43). A structured session has no argv, so that transport is a terminal-route construction with no structured counterpart, and closing it is a separate PR.

Reused vs. newly written

Reused — no second queue was written:

  • createStructuredAgentSessionOutboxEntry, structuredAgentSessionSendBody, and the envelope/fingerprint construction from src/shared/structured-agent-session-outbox.ts, so the host's send is shaped exactly like the renderer's and mobile's: same body, operation id as client message id, same payloadFingerprint (the host recomputes and compares it, so a divergent shape would be refused).
  • createStructuredAgentSessionOperationId for the id.
  • host.send — the same mutation path, admission, serialize chain and journal append every client send uses.

Newly written — one 67-line module (agent-launch-structured-prompt.ts) and one field on the surface contract.

Refactored, not duplicated: structuredAgentSessionSendRequest now delegates to a typed structuredAgentSessionSendMutation. The wire-shaped Record<string, unknown> export is kept verbatim for its renderer and mobile callers; the host needs the typed shape. One body, two views.

On relocating the outbox

The task asked whether host-side ownership requires moving the outbox out of the renderer. I concluded it does not, and this is a claim worth checking rather than accepting:

The outbox is a client-side queue. Its entire job is surviving a client that loses contact with the host — recoverDispatching, unconfirmed, the Retry affordance, localStorage. Inside agent.launch there is no transport between the sender and the host to lose: the host is the sender. The durable "this text is owed" record on the host side already exists and is the journal submission row. Relocating the renderer's queue here would add a second durable copy of a fact the journal already holds, which is the failure mode this codebase has paid for before.

What is not done, named explicitly: the desktop renderer still delivers its own launch prompts, because launchAgentInNewTab → launchAgentInStructuredNewTab does not route through agent.launch yet. Once it does, source: 'launch' outbox entries and structured-agent-session-launch-prompt.ts become this call and can be deleted. That is the next slice, not this one.

Verified

  • pnpm tc — exit 0 at the pushed head 81088337a0.
  • pnpm test src/main/agent-launch src/main/runtime/rpc/methods — 197 files, 1973 tests passed at the pushed head.
  • Wider affected run before the final commit, covering the outbox and its renderer consumers (structured-agent-session-outbox-storage, use-structured-agent-session-outbox, structured-agent-session-launch-prompt, structured-agent-session-launch, structured-agent-session-send-disposition) — 202 files, 2037 tests passed.
  • oxlint on the six changed files — exit 0. pnpm run check:code-quality:changed — 0 new findings across 6 changed files, all seven sub-gates.
  • Ablation: replacing the delivery guard with an unconditional early return (asserted to match exactly once, so the edit could not silently no-op) turned the new assertion from journaled/msg-1 into not-delivered and failed 1 of 17. The change is pinned, not merely accompanied by a green suite.
  • pnpm-lock.yaml verified byte-identical to origin/main and absent from the commit: git diff origin/main HEAD --name-only lists exactly the six source files.
  • No max-lines disable and no per-file cap bump anywhere in the diff.

Not verified

  • No end-to-end run. Every test here is a unit test against stubs. Nothing exercised a real structured session created by a real agent.launch and then read the prompt back out of a real transcript.
  • No live caller. No production caller sends agent.launch with a prompt today — mobile's agentLaunchCreateParams sends agent and target only. So this path is reachable but currently unexercised in production, which is why the regression risk is low and also why the integration behaviour is unproven.
  • Provider readiness immediately after create is not measured. The journal row is committed regardless, so journaled holds either way; what is untested is which dispatchState a send lands in when it is issued this soon after the session is created.
  • Host-side draft support was ruled out by searching src/main/native-chat and the shared session record for a draft store and finding none. That is an absence-of-evidence argument over the paths I searched.

Mobile

No files under mobile/ were touched — verified with git status --porcelain -- mobile/ (empty). No predicted conflict with #21137.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 5391fd3c-71d0-4ac3-9385-95390848bd50

📥 Commits

Reviewing files that changed from the base of the PR and between 940cea6 and ec95914.

📒 Files selected for processing (7)
  • src/main/agent-launch/agent-launch-executor.test.ts
  • src/main/agent-launch/agent-launch-executor.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-launch-send-after-create.test.ts
  • src/main/runtime/rpc/methods/agent-launch-structured-prompt.test.ts
  • src/main/runtime/rpc/methods/agent-launch-structured-prompt.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/shared/structured-agent-session-outbox.ts

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


📝 Walkthrough

Walkthrough

Structured launches now return the created session fence and commit the launch prompt through an optional delivery hook. Successful commits return a message ID and produce a journaled receipt. Missing, refused, or failed delivery produces a not-delivered receipt. The commit helper inspects the journal after ambiguous sends. Tests cover commit payloads, failure handling, fence usage, adapter liveness, and terminal or draft launch paths.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to ec959

A transient delivery failure can either permit a duplicate prompt retry or fail a launch after its session has been created. Handle these paths before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives detailed context, implementation rationale, testing results, and known limitations. However, it does not follow the repository template and omits required information, including … Update the description to include the required template sections. Add a linked issue using Fixes #..., provide before/after visual proof or state N/A with a reason, complete the Testing and Checklist sections, provide the AI disclosure …
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 7 files. 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 describes the primary change: delivering launch prompts from the host during agent launch.
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 gives detailed context, implementation rationale, testing results, and known limitations. However, it does not follow the repository template and omits required information, including a linked issue, visual proof or an explicit N/A statement, the checklist items, AI disclosure, and the agent skill boundary declaration.

Resolution

Update the description to include the required template sections. Add a linked issue using Fixes #..., provide before/after visual proof or state N/A with a reason, complete the Testing and Checklist sections, provide the AI disclosure when applicable, and complete the Agent skill upstream boundary section.

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

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

❤️ Share

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

@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 found. The core mechanism holds up under independent review; one coverage note below.

Reviewed changes

  • Host-side launch-prompt delivery — agent.launch now commits a submit prompt to the structured session it just created through an injected deliverStructuredPrompt, reporting journaled with the committed row's id, and under-claiming not-delivered for everything else.
  • Fence plumbed out of the create — createStructuredSession returns { sessionId, handle, fence } so the send names the lease the create was admitted against instead of re-reading it.
  • Typed send mutation — structuredAgentSessionSendRequest now delegates to a new typed structuredAgentSessionSendMutation; the runtime shape is unchanged for the renderer and mobile callers.
  • Tests — new agent-launch-structured-prompt.test.ts, plus executor assertions pinning sequencing, the fence passed, and the draft / terminal / reused-terminal under-claims.

I verified the two load-bearing claims rather than taking them on faith:

  • The fence returned by attach is the live lease fence at send time — publishStructuredAgentSessionTab / setSessionTabVisibility do not touch lease.runtimeFence, lease renewal and the onAttached recovery helpers do not move it, and send admission requires only a present journal, a writable lease, and strict fence equality (no hold). A stale fence fails closed to not-delivered, which is the stated polarity.
  • For the fresh clientMessageId minted per call, ok: true implies an appended submission row: admission is admit (not replay), so sendPlan's fabricated-unknown replay row is unreachable, and performSend returns ok only after appendSubmission commits. Worth keeping in mind that this guarantee depends on the id being fresh each call.

ℹ️ The executor-to-host seam is only exercised against stubs

The executor test stubs deliverStructuredPrompt and the new module test stubs host.send, so neither suite drives agentLaunchSurfaceFactory.deliverStructuredPrompt through commitStructuredAgentSessionLaunchPrompt against a real StructuredAgentSessionHost. A wiring defect in agent-launch-surfaces.ts — a wrong caller key, a missing or stale fence, a null host — or a mismatch between the constructed envelope and host admission would pass both suites. Given the PR body's own "Not verified" section, this is the gap most worth closing.

Technical details
# The seam has no test at the level it is wired

## Affected sites
- `src/main/runtime/rpc/methods/agent-launch-surfaces.ts:70-85` — the real `createStructuredSession` / `deliverStructuredPrompt` wiring (caller, host, fence) is untested.
- `src/main/runtime/rpc/methods/agent-launch-structured-prompt.test.ts:17-20` — `hostWith` replaces the host with a bare `{ send }` stub.
- `src/main/agent-launch/agent-launch-executor.test.ts:60-63` — `deliverStructuredPrompt` is a `vi.fn`.

## Required outcome
- A test that drives the real surface factory against a real (or existing integration-fixture) host and asserts the prompt is admitted and appended, and that a refused/stale-fence send surfaces as `not-delivered` rather than `journaled`.

## Suggested approach (optional)
- `src/main/runtime/structured-agent-session-integration.test.ts` already builds a live host; extending it (or adding a sibling) is likely the least-cost home.

## Open questions for the human (optional)
- Is the intended home one of the existing host integration tests, or a new `agent-launch-surfaces` test?

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron evidence on 81088337a0a1dd1291da35558d938fe7d5e5c2a2 (isolated profile, hidden renderer, CDP identity verified). The real agent.launch runtime RPC with a submitted Codex prompt returned journaled; the rendered chat showed that exact prompt once, and host history confirmed one user item with an accepted submission. A draft launch returned not-delivered with zero transcript items/submissions.

Submitted launch prompt in the real app

Limits: the requested Grok QA worker was blocked by its weekly account limit, so this check was performed by the review agent. Provider completion was not proven: the accepted Codex turn remained working for 2m24s and was stopped through the UI. Idempotent replay was not tested through this desktop RPC channel because it lacks the required caller identity. SSH, Windows/WSL, and mobile UI are not covered by this evidence.

@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 reviewed the delta since the prior pullfrog review (8108833 → 940cea6): the throw-recovery added to launch-prompt commit, plus the new real-host ordering test.

  • Post-append throw recovery — commitStructuredAgentSessionLaunchPrompt now re-reads host.journalSnapshot(sessionId).submissions on a throw and returns the committed row's id when a submission matches the freshly minted operation id, instead of always under-claiming not-delivered.
  • Real-host ordering test — new structured-agent-session-launch-send-after-create.test.ts drives attach then the commit against the wire test host, with a positive control that strands the row (dispatchState: 'unknown') when the modeled adapter registers late.
  • Unit-test coverage for the recovery — agent-launch-structured-prompt.test.ts stubs journalSnapshot and pins both the recovered-row and no-row cases.

The recovery is reachable and safe: runSettledAgentSessionMutation rethrows after settling the operation ledger unknown, so host.send really can throw after performSend appended the submission row, and the id is minted fresh per call (createStructuredAgentSessionOperationId(randomUUID)), so a journalSnapshot match is necessarily this call's row — it cannot over-claim. I also confirmed the new test's ordering premise by reading both adapters: claude-structured-session-acquisition.ts:278 and codex-structured-session-acquire.ts:275 publish into the live map as the last step before acquire resolves, and both dispatch paths throw when the session is absent. The three changed suites pass locally (3 files, 24 tests).

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

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 8c3677fd-792d-4281-800f-46a7c2f4cc7d

📥 Commits

Reviewing files that changed from the base of the PR and between fbe7b19 and 940cea6.

📒 Files selected for processing (7)
  • src/main/agent-launch/agent-launch-executor.test.ts
  • src/main/agent-launch/agent-launch-executor.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-launch-send-after-create.test.ts
  • src/main/runtime/rpc/methods/agent-launch-structured-prompt.test.ts
  • src/main/runtime/rpc/methods/agent-launch-structured-prompt.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/shared/structured-agent-session-outbox.ts

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

Comment on lines +229 to +233
(await surfaces.deliverStructuredPrompt?.({
sessionId: structured.sessionId,
fence: structured.fence,
prompt: intent.prompt
})) ?? null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '120,250p' src/main/agent-launch/agent-launch-executor.ts
sed -n '320,375p' src/main/agent-launch/agent-launch-executor.ts
sed -n '220,310p' src/main/agent-launch/agent-launch-executor.test.ts

Repository: stablyai/orca

Length of output: 9987


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- executor outline ---'
ast-grep outline src/main/agent-launch/agent-launch-executor.ts
printf '%s\n' '--- executeAgentLaunch callers and boundaries ---'
rg -n -C 5 'executeAgentLaunch|deliverLaunchPrompt|deliverStructuredPrompt' src/main/agent-launch src/main/runtime
printf '%s\n' '--- executor test setup ---'
sed -n '1,230p' src/main/agent-launch/agent-launch-executor.test.ts
printf '%s\n' '--- executor test remainder ---'
sed -n '230,430p' src/main/agent-launch/agent-launch-executor.test.ts

Repository: stablyai/orca

Length of output: 28499


🏁 Script executed:

set -e
printf '%s\n' '--- executor outline ---'
ast-grep outline src/main/agent-launch/agent-launch-executor.ts
printf '%s\n' '--- executeAgentLaunch callers and boundaries ---'
rg -n -C 5 'executeAgentLaunch|deliverLaunchPrompt|deliverStructuredPrompt' src/main/agent-launch src/main/runtime
printf '%s\n' '--- executor test setup ---'
sed -n '1,230p' src/main/agent-launch/agent-launch-executor.test.ts
printf '%s\n' '--- executor test remainder ---'
sed -n '230,430p' src/main/agent-launch/agent-launch-executor.test.ts

Repository: stablyai/orca

Length of output: 28499


🏁 Script executed:

set -e
rg -n -C 8 'executeAgentLaunch|deliverLaunchPrompt|deliverStructuredPrompt' src/main/agent-launch src/main/runtime
sed -n '1,430p' src/main/agent-launch/agent-launch-executor.test.ts

Repository: stablyai/orca

Length of output: 33167


Handle a rejected delivery hook.

If deliverStructuredPrompt rejects, deliverLaunchPrompt propagates the rejection. runAgentLaunch returns executeAgentLaunch directly, so no outer boundary converts it to a not-delivered receipt after session creation.

Catch the rejection and return null. Add a regression test with a rejecting delivery mock.

Proposed fix
-  return (
-    (await surfaces.deliverStructuredPrompt?.({
-      sessionId: structured.sessionId,
-      fence: structured.fence,
-      prompt: intent.prompt
-    })) ?? null
-  )
+  try {
+    return (
+      (await surfaces.deliverStructuredPrompt?.({
+        sessionId: structured.sessionId,
+        fence: structured.fence,
+        prompt: intent.prompt
+      })) ?? null
+    )
+  } catch {
+    return null
+  }

Comment on lines +72 to +76
} catch {
// The host may have gone away before the snapshot; the caller retains the text in that case.
}
console.warn('[agent-launch] the session was created, its launch prompt was not sent', error)
return null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,110p' src/main/runtime/rpc/methods/agent-launch-structured-prompt.ts
sed -n '57,216p' src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
rg -n 'journalSnapshot|createStructuredAgentSessionOperationId|executeAgentLaunch|agent\.launch|agentLaunch' src/main src/shared | head -300

Repository: stablyai/orca

Length of output: 28346


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings

Length of output: 29930


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- agent-launch RPC ---'
sed -n '1,290p' src/main/runtime/rpc/methods/agent-launch.ts
printf '%s\n' '--- launch surface factory ---'
sed -n '1,130p' src/main/runtime/rpc/methods/agent-launch-surfaces.ts
printf '%s\n' '--- launch executor ---'
sed -n '100,270p' src/main/agent-launch/agent-launch-executor.ts
printf '%s\n' '--- host send/snapshot declarations ---'
rg -n -C 8 'journalSnapshot|performSend|send\s*=|send\(' src/main/native-chat/agent-session-wire/structured-agent-session-host.ts src/main/native-chat/agent-session-wire src/shared/structured-agent-session-outbox.ts
printf '%s\n' '--- operation ledger and replay helpers ---'
sed -n '1,180p' src/shared/agent-launch-operation.ts
sed -n '1,180p' src/main/runtime/rpc/methods/agent-launch-replay.ts
printf '%s\n' '--- relevant tests ---'
sed -n '1,125p' src/main/runtime/rpc/methods/agent-launch-structured-prompt.test.ts
sed -n '1,125p' src/main/runtime/rpc/methods/agent-launch-replay.test.ts

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -e
sed -n '1,290p' src/main/runtime/rpc/methods/agent-launch.ts
sed -n '1,130p' src/main/runtime/rpc/methods/agent-launch-surfaces.ts
sed -n '100,270p' src/main/agent-launch/agent-launch-executor.ts
rg -n -C 8 'journalSnapshot|performSend|send\s*=|send\(' src/main/native-chat/agent-session-wire/structured-agent-session-host.ts src/main/native-chat/agent-session-wire src/shared/structured-agent-session-outbox.ts
sed -n '1,180p' src/shared/agent-launch-operation.ts
sed -n '1,180p' src/main/runtime/rpc/methods/agent-launch-replay.ts
sed -n '1,125p' src/main/runtime/rpc/methods/agent-launch-structured-prompt.test.ts
sed -n '1,125p' src/main/runtime/rpc/methods/agent-launch-replay.test.ts

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- performSend ---'
sed -n '1,230p' src/main/native-chat/agent-session-wire/structured-agent-session-turns.ts
printf '%s\n' '--- journal snapshot implementation ---'
rg -n -C 12 'snapshot\s*=|snapshot\(\)|class .*Journal|function .*snapshot|appendSubmission' src/main/native-chat/agent-session-journal src/main/native-chat/agent-session-wire/structured-agent-session-turns.ts
printf '%s\n' '--- launch call sites and operation IDs ---'
rg -n -C 5 'agent\.launch|operationId:|createStructuredAgentSessionOperationId|AGENT_LAUNCH' src mobile tests --glob '*.{ts,tsx}' | head -500
printf '%s\n' '--- launch result and prompt receipt types ---'
rg -n -C 8 'type AgentLaunchResult|interface AgentLaunchResult|promptReceipt|prompt\.' src/shared src/main/agent-launch/agent-launch-executor.ts

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- performSend exact body ---'
sed -n '80,190p' src/main/native-chat/agent-session-wire/structured-agent-session-turns.ts
printf '%s\n' '--- journal store snapshot declarations ---'
rg -n 'snapshot' src/main/native-chat/agent-session-journal/journal-store.ts src/main/native-chat/agent-session-journal
printf '%s\n' '--- journal store implementation ---'
sed -n '1,220p' src/main/native-chat/agent-session-journal/journal-store.ts
printf '%s\n' '--- launch call-site matches ---'
rg -n -C 4 'agent\.launch|operationId' src mobile tests --glob '*.{ts,tsx}' --glob '!**/*.map' | head -300

Repository: stablyai/orca

Length of output: 49578


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- exact agent.launch references ---'
rg -n -C 3 'agent\.launch' src mobile --glob '*.{ts,tsx}' --glob '!**/*.test.ts' || true
printf '%s\n' '--- host session lookup ---'
rg -n -C 8 'requireSession\s*=|requireSession\(' src/main/native-chat/agent-session-wire/structured-agent-session-host.ts
printf '%s\n' '--- dispatch failure boundary ---'
rg -n -C 10 'function dispatchSafely|dispatchSafely|resolveDispatch' src/main/native-chat/agent-session-wire/structured-agent-session-turns.ts src/main/native-chat/agent-session-wire

Repository: stablyai/orca

Length of output: 50369


Retry an unavailable journal snapshot before reporting the prompt as undelivered.

performSend appends the submission before dispatch settlement, and a later settlement failure can still make host.send throw. journalSnapshot reads the current journal state, but it can throw when the session is no longer attached. The current code then returns null without determining whether the submission exists.

A launch retry without a stable operationId invokes this helper again, which creates a new clientMessageId. That retry can create a second turn. Callers that reuse the same replay-safe operationId are protected, but mobile currently sends no operationId.

Retry journalSnapshot with bounded backoff. Return null only after a full snapshot confirms that the operation is absent. If all snapshots remain unavailable, preserve an indeterminate result instead of treating the prompt as not delivered. Add a regression test where the first snapshot throws and a later snapshot contains the committed operation.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: land after fixes.

  • Found and fixed a real reliability bug: agent.launch previously reported not-delivered for any send throw, including failures after the journal row had already been appended. A retry could therefore create a duplicate model turn. The host now re-reads the authoritative journal on the error path and returns the committed message id when present; tests cover both post-append and pre-append failures.
  • Fix pushed in 940cea6b54.
  • Validation: targeted Vitest (3 files, 24 tests) passed; pnpm tc:node passed; lint/format hooks passed; git diff --check clean.
  • Hidden Electron + CDP validation proved a real submitted prompt was journaled once, appeared once in the transcript, and reached an accepted submission. Draft and terminal paths remained not-delivered as designed. Screenshot evidence: https://github.com/user-attachments/assets/1841f8c6-a98f-4e49-85bf-d6ddf863059d
  • Grok orchestration was attempted and stopped after the account reported its weekly quota; no Grok result is claimed.
  • No mobile files or SSH/relay transport code are touched. Remaining risk is limited to broader production/provider coverage beyond the exercised local Electron path.

`agent.launch` created the surface and then reported the caller's text as
`not-delivered`, always: delivery lived in the renderer, so mobile and any
other caller got an agent and no prompt.

The host now commits a `submit` prompt to the structured session it just
created, through the same send path `agentSession.send` runs, and reports
`journaled` with the transcript row's id. Nothing is queued — the durable
record that the text is owed is the journal's own submission row, which the
send appends before dispatching, so a host-side copy could only disagree with
it. The outbox's entry and envelope builders are reused so this send is shaped
exactly like a client's, fingerprint included.

Everything else under-claims as `not-delivered`: a terminal's paste is
observed by whoever owns the pane, a `draft` has no host-side home, and a
refused or thrown send commits nothing. There is no fourth "maybe" arm — a
caller holding one could neither resend nor drop the text — and dispatch doubt
stays on the submission row where it already lives.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/agent-launch-prompt-delivery branch from 940cea6 to ec95914 Compare September 17, 2026 20:16
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Resolved merge conflicts by rebasing onto current main. Preserved the workspace-kind launch fix and structured prompt delivery/recovery changes. Focused tests pass: 27 tests.

@brennanb2025
brennanb2025 merged commit 754134f into main Sep 17, 2026
28 of 30 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…1155)

* feat(agent-launch): deliver a launch prompt from the host

`agent.launch` created the surface and then reported the caller's text as
`not-delivered`, always: delivery lived in the renderer, so mobile and any
other caller got an agent and no prompt.

The host now commits a `submit` prompt to the structured session it just
created, through the same send path `agentSession.send` runs, and reports
`journaled` with the transcript row's id. Nothing is queued — the durable
record that the text is owed is the journal's own submission row, which the
send appends before dispatching, so a host-side copy could only disagree with
it. The outbox's entry and envelope builders are reused so this send is shaped
exactly like a client's, fingerprint included.

Everything else under-claims as `not-delivered`: a terminal's paste is
observed by whoever owns the pane, a `draft` has no host-side home, and a
refused or thrown send commits nothing. There is no fourth "maybe" arm — a
caller holding one could neither resend nor drop the text — and dispatch doubt
stays on the submission row where it already lives.

* fix(agent-launch): recover committed prompt after send errors
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