Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
4f20e4b
fix(native-chat): decide Claude restart delivery by the message's own…
brennanb2025 Sep 28, 2026
07368bb
perf(native-chat): read Claude history on restart only for sends that…
brennanb2025 Sep 28, 2026
f1ba667
fix(native-chat): find a Claude send folded or merged into a running …
brennanb2025 Sep 28, 2026
2f34ca0
test(native-chat): pin a running turn keeping a Claude send unconfirmed
brennanb2025 Sep 28, 2026
f3c6bf1
docs(native-chat): say where Claude keeps a folded frame's id
brennanb2025 Sep 28, 2026
4e261d0
fix(native-chat): keep a merged Claude send unconfirmed once the row'…
brennanb2025 Sep 28, 2026
2aeb8b0
test(native-chat): pin the Claude adapter sending a frame under its r…
brennanb2025 Sep 28, 2026
50b9bf2
fix(native-chat): decide a restarted Claude send only by finding its …
brennanb2025 Sep 28, 2026
9a773b5
Merge remote-tracking branch 'origin/main' into brennanb2025/sta-7416…
brennanb2025 Sep 28, 2026
bfd12f7
revert(native-chat): drop the transcript id lookup for restarted sends
brennanb2025 Sep 28, 2026
460cd0f
fix(native-chat): end a restarted session with one row instead of rea…
brennanb2025 Sep 28, 2026
f00a880
fix(native-chat): word the restart row and retire the unconfirmed-id …
brennanb2025 Sep 28, 2026
632e5eb
fix(native-chat): draw a send left in doubt as sent, with no barrier …
brennanb2025 Sep 28, 2026
8083343
test(native-chat): read the new cases' calls without casts
brennanb2025 Sep 28, 2026
ddd9c15
test(native-chat): name the drawn-as-sent projection cases plainly
brennanb2025 Sep 28, 2026
96134dc
test(native-chat): read the sent requests by shape, not through the n…
brennanb2025 Sep 28, 2026
0140e10
fix(native-chat): keep a live unknown send until it settles, so a lat…
brennanb2025 Sep 28, 2026
ef56226
docs(native-chat): say an older host's not-delivered send carries no …
brennanb2025 Sep 28, 2026
9d62068
chore: restore pnpm-lock.yaml
brennanb2025 Sep 28, 2026
84c3bed
Merge origin/main into brennanb2025/sta-7416-delivery-by-message-id
brennanb2025 Sep 28, 2026
d25b69b
fix(native-chat): draw an older host's restart-doubted send as sent too
brennanb2025 Sep 28, 2026
a72f755
refactor(native-chat): decide a send's settlement in one classifier
brennanb2025 Sep 28, 2026
328fbed
fix(native-chat): settle a dispatch state this build cannot place as …
brennanb2025 Sep 28, 2026
0862016
fix(native-chat): keep a failure row outside a settled turn's fold
brennanb2025 Sep 28, 2026
2ce2803
docs(agent-status): list a crash-doubted send as a request
brennanb2025 Sep 28, 2026
fb06b52
docs(native-chat): name failure rows where the fold skips them; a dou…
brennanb2025 Sep 28, 2026
b75ef65
Merge remote-tracking branch 'origin/main' into brennanb2025/sta-7416…
brennanb2025 Sep 28, 2026
7a97fdb
test(native-chat): name the settlement classifier's input for the sub…
brennanb2025 Sep 28, 2026
4002f3c
fix(native-chat): explain a send retired in doubt with no exit or res…
brennanb2025 Sep 29, 2026
d6d00bf
test(native-chat): pin that the unanswered-send row stays outside a f…
brennanb2025 Sep 29, 2026
0a9a356
fix(native-chat): say Claude stopped when its exit is settled after t…
brennanb2025 Sep 29, 2026
b7c37f7
revert(native-chat): drop the "didn't respond to your last message" row
brennanb2025 Sep 29, 2026
1c50e6e
fix(native-chat): keep an agent running while a send it took is unans…
brennanb2025 Sep 29, 2026
03e44d2
fix(native-chat): keep a failure row in view only when the turn ended…
brennanb2025 Sep 29, 2026
c309dfc
feat(native-chat): draw a crash-doubted send as sent on released clie…
brennanb2025 Sep 29, 2026
71dd198
test(native-chat): assert the projected stream without a type assertion
brennanb2025 Sep 29, 2026
a8949ab
fix(native-chat): name the crash-doubted send capability without a ra…
brennanb2025 Sep 29, 2026
a0ca713
fix(native-chat): publish an older host's "not delivered" as sent to …
brennanb2025 Sep 29, 2026
6e7ebc5
fix(native-chat): keep only the failure a turn ended in outside its fold
brennanb2025 Sep 29, 2026
cd2da8e
refactor(native-chat): read the in-flight send at teardown through th…
brennanb2025 Sep 29, 2026
7cb874a
Merge origin/main into brennanb2025/sta-7416-delivery-by-message-id
brennanb2025 Sep 29, 2026
c2004eb
test(native-chat): read the Claude crash-restart journal as a current…
brennanb2025 Sep 29, 2026
f395e98
Merge remote-tracking branch 'origin/main' into brennanb2025/sta-7416…
brennanb2025 Sep 29, 2026
f71d13b
fix(i18n): drop the wait-for-setup help keys main removed, which the …
brennanb2025 Sep 29, 2026
e69eee9
Merge remote-tracking branch 'origin/main' into brennanb2025/sta-7416…
brennanb2025 Sep 29, 2026
0e4263f
fix(native-chat): give a doubted send a way to die at its turn end, a…
brennanb2025 Sep 29, 2026
c709f01
fix(native-chat): word a crash row by the boundary it crossed, not by…
brennanb2025 Sep 29, 2026
58f406f
test(native-chat): type the turn-end and crash-boundary fixtures agai…
brennanb2025 Sep 29, 2026
8e25362
fix(native-chat): settle a doubted send at the provider's turn-over, …
brennanb2025 Sep 29, 2026
3361da8
fix(native-chat): keep a failed turn-over settle from stalling the ev…
brennanb2025 Sep 29, 2026
76c2d5b
test(codex): leave the cast journal fake untouched; the turn-over set…
brennanb2025 Sep 29, 2026
814cf11
test(codex): pin that a subagent thread's turn end leaves the user's …
brennanb2025 Sep 29, 2026
6ea9c3d
Merge origin/main into brennanb2025/sta-7416-delivery-by-message-id
brennanb2025 Sep 29, 2026
726cf30
fix(native-chat): read main's two new send-state checks through the s…
brennanb2025 Sep 29, 2026
2586cf9
test(codex): give main's turn-grouping fold rows the failure field th…
brennanb2025 Sep 29, 2026
c9ecc80
test(native-chat): pin that a Stop naming no turn settles the send it…
brennanb2025 Sep 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/main/claude/claude-structured-dispatch-content.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createHash } from 'node:crypto'
import { createHash, randomUUID } from 'node:crypto'
import { open } from 'node:fs/promises'
import { extname } from 'node:path'
import type { AgentJournalMessageItem } from '../../shared/agent-session-journal-types'
import type {
AgentJournalItemIdentity,
AgentJournalMessageItem
} from '../../shared/agent-session-journal-types'
import type { NativeChatBlock } from '../../shared/native-chat-types'
import {
agentSessionFailureFact,
Expand Down Expand Up @@ -257,3 +260,31 @@ export function claudeDispatchContentKey(content: readonly unknown[]): string {
const key = `v1:${summary.slice(0, 128)}:${digest.digest('hex')}`
return key.slice(0, MAX_REPLAY_CONTENT_KEY_BYTES)
}

/**
* Claude records a user frame under the frame's own `uuid` — its row's, or for a frame folded into
* a running turn its attachment's `source_uuid` — so the id is chosen before the hand-over is
* journaled. A command is left to content: what Claude writes for one is not the prompt Orca sent.
*/
export function mintClaudeDispatchIdentity(
providerSessionId: string,
body: AgentJournalMessageItem
): AgentJournalItemIdentity | null {
const prompt = body.blocks.flatMap((block) =>
block.type === 'text' && block.text ? [block.text] : []
)
if (claudeDispatchInvokesSlashCommand([{ type: 'text', text: prompt.join('\n') }])) {
Comment thread
pullfrog[bot] marked this conversation as resolved.
Resolved
return null
}
return { provider: 'claude', sessionId: providerSessionId, uuid: randomUUID() }
}

/** The recorded id's uuid when it names this session; a stale one names a record Claude never wrote. */
export function claudeRecordedFrameUuid(
providerSessionId: string,
identity: AgentJournalItemIdentity | undefined
): string | undefined {
return identity?.provider === 'claude' && identity.sessionId === providerSessionId
? identity.uuid
: undefined
}
153 changes: 153 additions & 0 deletions src/main/claude/claude-structured-dispatch-identity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// The id a restart decides delivery by: chosen before the hand-over, durable with it, and the
// exact id the frame Claude records carries.

import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
agentJournalItemKey,
parseAgentJournalItemKey
} from '../../shared/agent-session-journal-item-key'
import type { AgentSessionJournalIdentity } from '../../shared/agent-session-journal-types'
import { createTrackedJournalOpener } from '../native-chat/agent-session-journal/journal-store-test-open'
import type { StructuredAgentSessionAdapter } from '../native-chat/agent-session-wire/structured-agent-session-adapter'
import { handOverSubmission } from '../native-chat/agent-session-wire/structured-agent-session-turns'
import { dispatchClaudeTurn } from './claude-structured-dispatch'
import {
claudeRecordedFrameUuid,
mintClaudeDispatchIdentity
} from './claude-structured-dispatch-content'
import { sessionFor, userMessage } from './claude-structured-dispatch-test-support'
import {
acquired,
fakeClaude,
PROVIDER_SESSION_ID,
USER_MESSAGE
} from './claude-structured-session-test-support'

const IDENTITY: AgentSessionJournalIdentity = {
sessionId: 'session-1',
workspaceId: 'workspace-1',
hostId: 'local',
agent: 'claude',
providerHandle: { kind: 'claude', sessionId: 'provider-session', leafUuid: null }
}

const journals = createTrackedJournalOpener()
let root: string

beforeEach(async () => {
root = await mkdtemp(join(tmpdir(), 'orca-dispatch-identity-'))
})

afterEach(async () => {
await journals.closeAll()
await rm(root, { recursive: true, force: true })
})

describe('the Claude dispatch identity', () => {
it('names a plain prompt by a fresh uuid in the live session', () => {
const identity = mintClaudeDispatchIdentity(
'provider-session',
userMessage([{ type: 'text', text: 'ship it' }])
)
expect(identity).toMatchObject({ provider: 'claude', sessionId: 'provider-session' })
})

it('leaves a slash command to content, since Claude records no prompt for it', () => {
expect(
mintClaudeDispatchIdentity(
'provider-session',
userMessage([{ type: 'text', text: '/compact' }])
)
).toBeNull()
})

it('stamps the recorded uuid on the frame, and only for the session it names', async () => {
const send = vi.fn().mockResolvedValue(undefined)
const session = sessionFor(send)
const recorded = { provider: 'claude', sessionId: 'provider-session', uuid: 'frame-1' } as const
const sentUuid = claudeRecordedFrameUuid(session.providerSessionId, recorded)

await dispatchClaudeTurn(session, {
body: userMessage([{ type: 'text', text: 'ship it' }]),
sentUuid
})

expect(send.mock.calls[0]?.[0]).toMatchObject({ uuid: 'frame-1' })
expect(claudeRecordedFrameUuid('another-session', recorded)).toBeUndefined()
})
})

describe('handing a send over under its identity', () => {
it('records the id before dispatch and keeps it through a crash', async () => {
const journal = await journals.open({ identity: IDENTITY, journalDir: root })
await journal.appendSubmission({
clientMessageId: 'cm-1',
payloadFingerprint: 'fingerprint',
body: userMessage([{ type: 'text', text: 'ship it' }]),
fence: 1,
handoverRecorded: true
})
const identity = { provider: 'claude', sessionId: 'provider-session', uuid: 'frame-1' } as const
let recordedAtDispatch: string | undefined
const dispatch = vi.fn(async () => {
recordedAtDispatch = journal.submissions()[0]?.handedOverItemId
return { state: 'admitted' as const }
})
const adapter: Pick<StructuredAgentSessionAdapter, 'dispatch' | 'mintDispatchIdentity'> = {
dispatch,
mintDispatchIdentity: () => identity
}

await handOverSubmission(
{
sessionId: 'session-1',
journal,
fence: 1,
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: A hand-over calls only these two members.
adapter: adapter as StructuredAgentSessionAdapter
},
journal.submissions()[0]!
)

expect(dispatch).toHaveBeenCalledWith(expect.objectContaining({ providerIdentity: identity }))
expect(recordedAtDispatch).toBe(agentJournalItemKey(identity))
await journal.close()
const reopened = await journals.open({ identity: IDENTITY, journalDir: root })
await reopened.markPendingSubmissionsUnknown(2)
expect(reopened.submissions()[0]).toMatchObject({
dispatchState: 'unknown',
handedOverItemId: agentJournalItemKey(identity)
})
})
})

describe('the Claude adapter handing a send over', () => {
it('writes the frame under the id the journal recorded for it', async () => {
const claude = fakeClaude({ replayUuid: null })
const adapter = await acquired(claude)
const journal = await journals.open({ identity: IDENTITY, journalDir: root })
await journal.appendSubmission({
clientMessageId: 'cm-1',
payloadFingerprint: 'fingerprint',
body: USER_MESSAGE,
fence: 7,
handoverRecorded: true
})

await handOverSubmission(
{ sessionId: 'session-1', journal, fence: 7, adapter },
journal.submissions()[0]!
)

const recorded = parseAgentJournalItemKey(journal.submissions()[0]?.handedOverItemId ?? '')
const uuid =
recorded?.provider === 'claude' && recorded.sessionId === PROVIDER_SESSION_ID
? recorded.uuid
: null
expect(uuid).toEqual(expect.any(String))
expect(claude.connections[0]?.sent[0]).toMatchObject({ uuid })
})
})
10 changes: 8 additions & 2 deletions src/main/claude/claude-structured-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ function claudeWriteFailureRejection(error: unknown): AgentJournalDispatchReject

export async function dispatchClaudeTurn(
session: ClaudeSession,
input: { clientMessageId?: string; body: AgentJournalMessageItem; requestedAt?: number },
input: {
clientMessageId?: string
body: AgentJournalMessageItem
requestedAt?: number
/** The frame's uuid, when the caller already recorded it. */
sentUuid?: string
},
beforeDispatch?: () => Promise<void>
): Promise<AgentSessionDispatchOutcome> {
let content: unknown[]
Expand All @@ -258,7 +264,7 @@ export async function dispatchClaudeTurn(
// Read the sent content, not the journal blocks: only the mapped trailing prompt decides
// whether Claude runs a command, so the two cannot disagree about which frame settles this.
const acceptsResult = claudeDispatchInvokesSlashCommand(content)
const sentUuid = randomUUID()
const sentUuid = input.sentUuid ?? randomUUID()
const arm = () => {
++session.dispatchSequence
// A context report asked for before this send may land after it and misstate the context.
Expand Down
Loading
Loading