Skip to content
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
aea0ffc
Agent message cards keep their sender's agent icon when the agent can…
brennanb2025 Oct 31, 2026
850b7f3
Preserve known worker agents on federated cards and mail
brennanb2025 Oct 31, 2026
1668b25
Resolve agent message senders through shared host identity
brennanb2025 Oct 31, 2026
be364a5
Retain acquired worker launch identity for later sender snapshots
brennanb2025 Oct 31, 2026
33bc763
Prune repeated worker sender contract checks
brennanb2025 Oct 31, 2026
ce8fffd
Merge main into worker card icon branch
brennanb2025 Oct 31, 2026
c27de2a
Combine worker command contract projection imports
brennanb2025 Oct 31, 2026
d471882
Keep sender identity bounded and scoped per worktree
brennanb2025 Oct 31, 2026
c4d23de
Save each agent card's sender identity and open the pane it names
brennanb2025 Oct 31, 2026
baf7258
Resolve agent card senders by the terminal handle every card saves
brennanb2025 Oct 31, 2026
37fb76a
Send sender identity once per revision and judge every host by one rule
brennanb2025 Oct 31, 2026
6ea5f4a
CI: keep the sender delivery contract test out of the web project and…
brennanb2025 Oct 31, 2026
ce6d1bb
Merge #36653 (worker card icon) head into worker card identity
brennanb2025 Oct 31, 2026
fa037fd
CI: share the dispatch-address link rule and align the merged view te…
brennanb2025 Oct 31, 2026
a62d7f4
Merge origin/main into worker-card-icon
brennanb2025 Oct 31, 2026
fe50fad
Use the sender snapshot resolver in main's new receiving-account tests
brennanb2025 Oct 31, 2026
b7c70ba
Read a saved "unknown" agent kind as no kind for the card's icon and …
brennanb2025 Oct 31, 2026
fc12196
Apply a frame's sender scopes when the window receives it, ordered by…
brennanb2025 Oct 31, 2026
9f888e6
Read chat senders from open chats and their /clear predecessors, not …
brennanb2025 Oct 31, 2026
9193070
Walk live terminals once per session-tab inventory or broadcast, not …
brennanb2025 Oct 31, 2026
1b5fea2
Re-read a tab bucket's sender aliases only when a host it read changes
brennanb2025 Oct 31, 2026
05877ec
Merge #36653 (worker card icon, with main) into worker card identity
brennanb2025 Oct 31, 2026
1bb54d8
CI: restore the single-frame builder declaration and compare sender c…
brennanb2025 Oct 31, 2026
e0d165f
CI: give the sender no-op test's heartbeat a fixed timestamp instead …
brennanb2025 Oct 31, 2026
318e1a7
CI: assert one terminal walk per orchestration RPC and no identity re…
brennanb2025 Oct 31, 2026
be536c7
CI: reach the sender pass methods through a typed view of their proto…
brennanb2025 Oct 31, 2026
9f92519
CI: list every sender target kind in the link switch and merge the du…
brennanb2025 Oct 31, 2026
24bbddb
Skip a paired host's floating-terminal sender scope at receipt, as th…
brennanb2025 Oct 31, 2026
e876313
Read /clear predecessors through the record store's existing successo…
brennanb2025 Oct 31, 2026
65ff22d
Keep live workers' sender history between builds and re-read only wha…
brennanb2025 Oct 31, 2026
7bece8c
CI: build each sender trigger from a typed event list so its SQL part…
brennanb2025 Oct 31, 2026
4454c4f
CI: give startup runtime fakes the sender peer-key setter and drop ne…
brennanb2025 Oct 31, 2026
b7f201b
Ask the host to reveal a located sender this window holds no tab for,…
brennanb2025 Oct 31, 2026
b1783ea
Keep no worker history read inside an open transaction, and forget wo…
brennanb2025 Oct 31, 2026
d6647be
Test that sender names render only when what they show changes
brennanb2025 Oct 31, 2026
e81a6aa
CI: pass the sender target's dispatch id explicitly and write a real …
brennanb2025 Oct 31, 2026
5bbacf6
Read terminals' existing handles for sender rows instead of issuing them
brennanb2025 Oct 31, 2026
fda6d36
Open a located sender's own pane through its host when this window ha…
brennanb2025 Oct 31, 2026
30b1176
Merge origin/main into worker-card-icon
brennanb2025 Oct 31, 2026
b669dbd
Read a terminal's start-time handle for its sender row while no windo…
brennanb2025 Oct 31, 2026
5c00b08
Merge #36653 (worker card icon, with main 24d1d10da81) into worker ca…
brennanb2025 Oct 31, 2026
3d89386
CI: type the open helper's target as any runtime target so the paired…
brennanb2025 Oct 31, 2026
425c2b6
Lease the sidebar rows a sender name's link check reads, as its avata…
brennanb2025 Oct 31, 2026
f67edc5
Index a build's terminal handle records once instead of scanning them…
brennanb2025 Oct 31, 2026
507b2c0
Lease a replaced card's sidebar rows from where its sender runs befor…
brennanb2025 Oct 31, 2026
80920f0
Merge main (10e35fd76d7) into worker card identity: accept main's rem…
brennanb2025 Oct 31, 2026
0d2eff6
Show a paired host's worker status dot on its card when this window m…
brennanb2025 Oct 31, 2026
35e6c55
Publish a chat sender change even when the terminal read in the same …
brennanb2025 Oct 31, 2026
6124954
Merge main into sender identity review
brennanb2025 Nov 2, 2026
b83bbe4
Merge main into worker sender identity review
brennanb2025 Nov 2, 2026
2653684
Bound sender projection work to current consumers and lineage facts
brennanb2025 Nov 2, 2026
bb89101
Update runtime call assertions for sender demand options
brennanb2025 Nov 2, 2026
37abb7c
Merge current main to resolve sender lineage conflicts
brennanb2025 Nov 2, 2026
01a65ba
Preserve mobile sender navigation availability
brennanb2025 Nov 2, 2026
781bfff
Merge main into worker card identity
brennanb2025 Nov 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
journalStateScalars
} from './journal-state-layout'
import { readStoredQueuedMessageRow } from './queued-message-stored-row'
import { readAgentMessageSource } from '../../../shared/agent-session/agent-session-message-source'
import { projectStructuredAgentStartItem } from '../../../shared/structured-agent-start-projection'

// Admission keeps the in-memory chat within what this build declares on every path a saved value
// takes into it, so restating that chat on a new epoch never drops a newer build's key.
Expand Down Expand Up @@ -288,6 +290,62 @@ it('reads an open string such as an agent type as a value, and still refuses a k
expect(declared<UndeclaredStorageKeys<Later, Stored>>()).toBeUndefined()
})

it.each(['codex', 'future-agent', undefined, 42])(
'admits actual start, message and queued sender kind %j without losing the sender',
async (agent) => {
const journal = await open(journals)
const sender = {
party: { address: 'term_worker', terminalHandle: 'term_worker', orcaSessionId: null },
name: 'Inspect parser',
agent: 'codex'
}
const body = {
kind: 'message' as const,
role: 'user' as const,
blocks: [{ type: 'text' as const, text: 'Mail' }],
from: { kind: 'agent' as const, senders: [sender], orchestration: null }
}
await journal.appendItem(
item(0),
{ kind: 'agent-start', dispatchId: 'dispatch-1', task: 'Inspect parser', worker: sender },
SCOPE
)
await journal.appendItem(item(1), body, SCOPE)
await journal.queuedMessages.insert({ messageId: 'queued-1', body })
await journals.closeAll()
// A later or damaged writer can change this declared optional value without adding any key.
const records = db()
.prepare(
"SELECT generation, seq, ordinal, value_json FROM journal_outcomes WHERE field IN ('items', 'queue.cards')"
)
.all()
expect(records.length).toBeGreaterThanOrEqual(3)
for (const row of records) {
const json = JSON.stringify(JSON.parse(String(row.value_json)), (key, value) =>
key === 'agent' ? agent : value
)
db()
.prepare(
'UPDATE journal_outcomes SET value_json = ? WHERE generation = ? AND seq = ? AND ordinal = ?'
)
.run(json, Number(row.generation), Number(row.seq), String(row.ordinal))
}
const reopened = await open(journals)
const restored = reopened.snapshot().items
expect(restored).toHaveLength(2)
const fromStart = projectStructuredAgentStartItem(restored[0])?.from
const fromMessage = readAgentMessageSource(
restored[1].body.kind === 'message' ? restored[1].body.from : undefined
)
const expected = typeof agent === 'string' ? agent : undefined
const queued = reopened.queuedMessages.list()[0]
for (const from of [fromStart, fromMessage, readAgentMessageSource(queued.body.from)]) {
expect(from?.senders[0]).toMatchObject({ party: sender.party, name: sender.name })
expect(from?.senders[0].agent).toBe(expected)
}
}
)

it('keeps explicitly opaque annotation values whole without hiding sibling or nested structured keys', () => {
type Actual = { annotation: { future: { keys: number[] } }; nested: { kept: string } }
type Stored = { annotation?: unknown; nested: { kept: string } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const sender = z.object({
.nullable()
.optional(),
name: salvaged,
agent: salvaged,
relation: salvaged
})
const orchestration = z.discriminatedUnion('message', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function createQueuedRigProvider(
link: {
linkId: `link-${fence}`,
handle:
options.agent === 'claude'
identity.agent === 'claude'
? claudeProviderHandle(thread, null)
: codexProviderHandle(thread),
origin: resumes ? ('resumed' as const) : ('created' as const),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ it.each([
dispatchId: null,
batch: { messages: [message], heldDeliveryId: undefined },
cliCommand: 'orca-dev',
senderName: () => null
senderSnapshot: () => ({ name: null, agent: null })
})
)
await decide(RECEIVING_A)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export async function createReceivingAccountFixture() {
dispatchId: null,
batch: { messages: [message], heldDeliveryId: undefined },
cliCommand: 'orca-dev',
senderName: () => null
senderSnapshot: () => ({ name: null, agent: null })
})
return {
rig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('nested receiving work follows its current consumer', () => {
getMessageWaiters: () => undefined,
resolveStructuredTarget: (handle) => f.runtime.mailTarget(handle),
getCliCommand: () => 'orca-dev',
senderName: () => null,
senderSnapshot: () => ({ name: null, agent: null }),
host: createStructuredMailboxPointerHost(),
onRetain: retained
})
Expand Down
1 change: 1 addition & 0 deletions src/main/orcad/orcad-duplicate-pty-repair-startup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ vi.mock('../runtime/orca-runtime', () => ({
}
async closeNotificationDismissals() {}
syncWindowGraph() {}
setAgentSenderPeerKey() {}
}
}))
vi.mock('../runtime/runtime-rpc', () => ({
Expand Down
1 change: 1 addition & 0 deletions src/main/orcad/orcad-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ async function startOrcadRuntime(
webClientRoot: resolveOrcadWebClientRoot(options.webClientRoot),
...orcadWsPortOptions(options.port)
})
runtime.setAgentSenderPeerKey(() => rpc.getE2EEPublicKey())
// Stop RPC before cleanup can tear down writers and runtime state.
registerCleanup(() => rpc.stop())
await timed('rpc', () => rpc.start())
Expand Down
1 change: 1 addition & 0 deletions src/main/orcad/orcad-push-startup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ vi.mock('../runtime/orca-runtime', () => ({
return null
}
syncWindowGraph() {}
setAgentSenderPeerKey() {}
setMobilePushRegistrar(
registrar: Parameters<RuntimeMobileNotificationController['setPushRegistrar']>[0]
) {
Expand Down
19 changes: 17 additions & 2 deletions src/main/runtime/agent-session-record-lineage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import type Database from '../sqlite/sync-database'
import type { AgentSessionRecord } from '../../shared/agent-session-record'

export const AGENT_SESSION_PREDECESSOR_IDS = `SELECT session_id FROM agent_session_records
WHERE CASE WHEN json_valid(record_json) THEN json_extract(record_json, '$.conversationCommand.replacementSessionId') END = ?`
let predecessorWork = { seeks: 0, rows: 0 }
export const agentSessionPredecessorWorkForTest = () => predecessorWork

/** Every saved record whose clear command names this session, any phase, through the clear
* successor index: candidates for callers to validate, never proof of a committed clear. */
export function agentSessionRecordPredecessorIds(
db: Database.Database,
sessionId: string
): string[] {
const rows = db.prepare(AGENT_SESSION_PREDECESSOR_IDS).all(sessionId)
predecessorWork = { seeks: predecessorWork.seeks + 1, rows: predecessorWork.rows + rows.length }
return rows.flatMap((row) => (typeof row.session_id === 'string' ? [row.session_id] : []))
}

/** Indexed reverse links cover historical clear successors without scanning every conversation. */
export function agentSessionRecordLineage(
db: Database.Database,
Expand All @@ -9,8 +25,7 @@ export function agentSessionRecordLineage(
): AgentSessionRecord[] {
const records = [record]
const seen = new Set([record.sessionId])
const prior = db.prepare(`SELECT session_id FROM agent_session_records
WHERE CASE WHEN json_valid(record_json) THEN json_extract(record_json, '$.conversationCommand.replacementSessionId') END = ?`)
const prior = db.prepare(AGENT_SESSION_PREDECESSOR_IDS)
for (let current = record; ;) {
const rows = prior.all(current.sessionId)
if (
Expand Down
13 changes: 12 additions & 1 deletion src/main/runtime/agent-session-record-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { agentSessionRecordLineage } from './agent-session-record-lineage'
import {
agentSessionRecordLineage,
agentSessionRecordPredecessorIds
} from './agent-session-record-lineage'
import { clearSuccessor } from './agent-session-sender-identity-revision'
import type Database from '../sqlite/sync-database'
import { createAgentSessionOwnerProof } from './agent-session-owner-proof'
import { backfillAgentSessionPermissionModes } from './agent-session/ownership/agent-session-permission-backfill'
Expand Down Expand Up @@ -135,6 +139,13 @@ export class AgentSessionRecordStore extends AgentSessionRecordTabs {

getConversation = (sessionId: string) => getAgentSessionConversation(this.state, sessionId)
listConversations = () => listAgentSessionConversations(this.state)
senderIdentityRevision = (): number => this.transactions.senderIdentityRevision
/** Sessions a committed /clear continued into this one, read through the clear-successor index;
* each candidate is checked on its conversation, so unreadable leases still count. */
listClearedFrom = (sessionId: string): string[] =>
agentSessionRecordPredecessorIds(this.database, sessionId).filter(
(id) => clearSuccessor(this.getConversation(id)) === sessionId
)
selectWritableRecord = (sessionId: string) =>
selectWritableAgentSessionRecord(this.state, sessionId)
requireWritableRecord = (sessionId: string) =>
Expand Down
37 changes: 37 additions & 0 deletions src/main/runtime/agent-session-sender-identity-revision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { agentSessionScopeKey, type AgentSessionRecord } from '../../shared/agent-session-record'
import type { AgentSessionConversationView } from '../../shared/agent-session-conversation-view'
import type { AgentSessionStoreState } from './agent-session-store-state'
import type { AgentSessionStoreRowWrites } from './agent-session-store-draft'

/** The session a committed /clear continued this one in: the durable forward pointer. */
export function clearSuccessor(
record: Pick<AgentSessionConversationView, 'conversationCommand'> | null | undefined
): string | null {
const command = record?.conversationCommand
return command?.command === 'clear' && command.phase === 'committed'
? (command.replacementSessionId ?? null)
: null
}

function senderFacts(record: AgentSessionRecord | undefined): string | undefined {
return record
? JSON.stringify([agentSessionScopeKey(record.location), clearSuccessor(record)])
: undefined
}

/** Whether a commit changed what chat sender identity reads: which chats exist, where they run,
* their committed /clear successor, or which have open tabs. Lease renewals and receipts don't. */
export function changesAgentSenderIdentity(
published: AgentSessionStoreState,
draft: AgentSessionStoreState,
writes: AgentSessionStoreRowWrites
): boolean {
return (
writes.sessionTabs !== null ||
writes.records.remove.length > 0 ||
writes.records.upsert.some(
([sessionId]) =>
senderFacts(published.records.get(sessionId)) !== senderFacts(draft.records.get(sessionId))
)
)
}
6 changes: 6 additions & 0 deletions src/main/runtime/agent-session-store-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
draftAgentSessionStoreState,
type AgentSessionStoreRowWrites
} from './agent-session-store-draft'
import { changesAgentSenderIdentity } from './agent-session-sender-identity-revision'

// Commit validated draft rows atomically before publication; failures discard the draft.
// The promise queue preserves FIFO and defers BEGIN beyond the caller's open journal transaction.
Expand Down Expand Up @@ -88,6 +89,8 @@ export class AgentSessionStoreTransactions {
private readonly admittedSends = new Map<string, number>()
readonly acceptedSendListeners = new Set<(sessionId: string) => void>()
private published: AgentSessionStoreState
/** Moves only when a commit changes what chat sender identity reads. */
senderIdentityRevision = 0
/** Loaded takeover evidence; immutable for this runtime. */
readonly replacedRuntimes: ReadonlyMap<string, AgentSessionReplacedRuntime>

Expand Down Expand Up @@ -227,6 +230,9 @@ export class AgentSessionStoreTransactions {
adopt: () => {
if (writes) {
freezeRows(draft, writes)
if (changesAgentSenderIdentity(published, draft, writes)) {
this.senderIdentityRevision++
}
this.published = draft
}
}
Expand Down
79 changes: 79 additions & 0 deletions src/main/runtime/construction/runtime-agent-projections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { RuntimeAgentSenderAssociations } from '../runtime-agent-sender-associations'
import { fingerprintOrchestrationPeer } from '../orchestration/environment-transport'
import {
RuntimeAgentOrchestrationProjection,
type RuntimeAgentOrchestrationDependencies
} from '../runtime-agent-orchestration-projection'
import type { RuntimeConstructionServices } from './runtime-construction-services'
import { environmentStoreWriteCount } from '../../../shared/runtime-environment-store-file'
import type { AgentSenderPrincipal } from '../runtime-agent-sender-history'
import type { AgentSenderHandleReads } from '../runtime-agent-sender-associations'

type SenderHost = Pick<
RuntimeConstructionServices,
'getExistingOrchestrationDb' | 'resolveOrchestrationWorkerServer'
>

export function createRuntimeAgentProjections(
host: SenderHost,
dependencies: RuntimeAgentOrchestrationDependencies & AgentSenderHandleReads
) {
let historyChecked = false
let peerKey: () => string | null = () => null
// Pairings change only by registry writes; resolving reads several files, so not per Dispatch change.
const principals = new Map<string, AgentSenderPrincipal | undefined>()
let pairing = environmentStoreWriteCount()
const senders = new RuntimeAgentSenderAssociations({
...dependencies,
getDb: () => {
const db = dependencies.getDb()
if (db || historyChecked) {
return db
}
historyChecked = true
try {
return host.getExistingOrchestrationDb()
} catch (error) {
// Display bookkeeping must not surface an open failure; orchestration's own use reports it.
console.warn('[runtime] Sender identity history unavailable', error)
return null
}
},
peerFingerprint: () => {
const key = peerKey()
return key ? fingerprintOrchestrationPeer(key) : undefined
},
pairingGeneration: environmentStoreWriteCount,
principal: (environmentId) => {
if (pairing !== environmentStoreWriteCount()) {
pairing = environmentStoreWriteCount()
principals.clear()
}
if (!principals.has(environmentId)) {
principals.set(environmentId, resolvePrincipal(host, environmentId))
}
return principals.get(environmentId)
}
})
return {
orchestration: new RuntimeAgentOrchestrationProjection(dependencies),
senders,
/** The RPC server owns the pairing key clients authenticate this host by. */
setPeerKey: (read: () => string | null) => {
peerKey = read
}
}
}

function resolvePrincipal(
host: SenderHost,
environmentId: string
): AgentSenderPrincipal | undefined {
try {
const { peerFingerprint, homePeerFingerprint } =
host.resolveOrchestrationWorkerServer(environmentId)
return homePeerFingerprint ? { peerFingerprint, homePeerFingerprint } : undefined
} catch {
return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type { PtyPane, PtyPaneSource } from '../terminal/surface/pty-pane-query'

export abstract class RuntimeConstructionServices {
abstract getOrchestrationDb(): OrchestrationDb
abstract getExistingOrchestrationDb(): OrchestrationDb | null
abstract listRepos(): Repo[]
abstract invalidateResolvedWorktreeCache(): void
abstract invalidateWorktreeScanCacheForRepo(repoId: string): void
Expand Down
2 changes: 2 additions & 0 deletions src/main/runtime/construction/runtime-identity-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ import {
import { RuntimeTerminalWait as RuntimeTerminalWaitController } from '../terminal/wait/terminal-wait'
import type { PtyLivenessVerdict } from '../../../shared/pty-liveness-verdict'
import type { HostScopedWorktreeKey } from '../../../shared/worktree/host-qualified-identity'
import type { TerminalHandleAccess } from '../runtime-agent-sender-associations'

import { RuntimeConstructionServices } from './runtime-construction-services'

export abstract class OrcaRuntimeWithRuntimeId extends RuntimeConstructionServices {
protected abstract claimIdleShellPromptForPty(ptyId: string): Promise<boolean>
protected abstract terminalHandleAccess(): TerminalHandleAccess
protected readonly runtimeId = randomUUID()

protected readonly startedAt = Date.now()
Expand Down
Loading
Loading