From f80202be1ee121fa34079db4a287ba4c5871fb0a Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Tue, 8 Sep 2026 15:04:28 -0700 Subject: [PATCH] Resolve run mailbox owners by agent session id --- .../runtime/orchestration/db/runs/run-lookup.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/runtime/orchestration/db/runs/run-lookup.ts b/src/main/runtime/orchestration/db/runs/run-lookup.ts index 7563effa8c3..56ecf752740 100644 --- a/src/main/runtime/orchestration/db/runs/run-lookup.ts +++ b/src/main/runtime/orchestration/db/runs/run-lookup.ts @@ -65,6 +65,18 @@ export function getRunMailboxOwnerIdsForHandle( return [...new Set(runIds)].sort() } +/** Resolves mailbox ownership by durable agent session identity. */ +export function getRunMailboxOwnerIdsForAgentSession( + this: OrchestrationDb, + agentSessionId: string +): string[] { + return ( + this.db + .prepare('SELECT id FROM runs WHERE legacy = 0 AND coordinator_agent_session_id = ?') + .all(agentSessionId) as { id: string }[] + ).map((row) => row.id) +} + export function listRuns( this: OrchestrationDb, params: { limit?: number; cursor?: string } = {} @@ -160,6 +172,7 @@ export type RunLookupMethods = { getRun: typeof getRun getLegacyAdoptedRunMailboxOwner: typeof getLegacyAdoptedRunMailboxOwner getRunMailboxOwnerIdsForHandle: typeof getRunMailboxOwnerIdsForHandle + getRunMailboxOwnerIdsForAgentSession: typeof getRunMailboxOwnerIdsForAgentSession listRuns: typeof listRuns getCurrentRunForPane: typeof getCurrentRunForPane runsBoundToPane: typeof runsBoundToPane @@ -174,6 +187,7 @@ export function attachRunLookup(ctor: { prototype: object }): void { getRun, getLegacyAdoptedRunMailboxOwner, getRunMailboxOwnerIdsForHandle, + getRunMailboxOwnerIdsForAgentSession, listRuns, getCurrentRunForPane, runsBoundToPane,