Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions src/main/ipc/register-core-handlers/register-core-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ import {
} from '../../ai-vault/runtime-hosts/runtime-session-scanner'
import { callRuntimeSessionSearch } from '../../ai-vault/runtime-hosts/runtime-session-search-call'
import { configureRuntimeAiVaultSessionDelete } from '../ai-vault/ai-vault-delete'
import { ensureStructuredAgentSessionHostUnlessRefused } from '../../runtime/agent-session/installation/structured-agent-session-host-refusal'
import {
ensurePersistedStructuredAgentSessionHostUnlessRefused,
ensureStructuredAgentSessionHostUnlessRefused
} from '../../runtime/agent-session/installation/structured-agent-session-host-refusal'
import { getAgentSessionAttachmentStore } from '../../native-chat/agent-session-attachments/agent-session-attachment-store-registry'
import type { PluginService } from '../../plugins/plugin-service'
import type { PluginMarketplaceHandlerServices } from '../plugins/plugin-marketplaces'
Expand Down Expand Up @@ -225,9 +228,9 @@ export async function registerCoreHandlers(
registerWslDriveProjectHandlers(store, runtime)
installProjectRuntimeGitRouter(store)
registerEphemeralVmHandlers(store, pluginService)
// Session history and terminal resume are not chats; a refused host leaves nothing to check.
// Session history and terminal resume are not chats; skip booting an empty chat journal host.
const ensureStructuredSessionOwnership = () =>
ensureStructuredAgentSessionHostUnlessRefused(() =>
ensurePersistedStructuredAgentSessionHostUnlessRefused(() =>
runtime.ensureStructuredAgentSessionHost()
)
registerAiVaultSearchHandlers({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {
isAgentSessionRefusalError,
type AgentSessionRefusalError
} from '../../../../shared/agent-session/failures/agent-session-wire-refusals'
import { getStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/host/structured-agent-session-registry'
import { getProfileUserDataPath } from '../../../orca-profiles/profile-storage-paths'
import { hasPersistedStructuredAgentSessionDatabaseFile } from '../records/persisted-agent-session-database-file'

let installRefusal: AgentSessionRefusalError | null = null

Expand Down Expand Up @@ -32,6 +35,19 @@ export async function ensureStructuredAgentSessionHostUnlessRefused(
}
}

/** Skip booting the chat journal host for ownership lookups when no chat store exists yet. */
export async function ensurePersistedStructuredAgentSessionHostUnlessRefused(
ensureHost: () => Promise<unknown>
): Promise<void> {
if (
!getStructuredAgentSessionHost() &&
!(await hasPersistedStructuredAgentSessionDatabaseFile(getProfileUserDataPath()))
) {
return
}
await ensureStructuredAgentSessionHostUnlessRefused(ensureHost)
}

/** Chat-host setup is bookkeeping for a terminal resume; an existing owner is checked afterward. */
export async function tryEnsureStructuredAgentSessionHostForResume(
ensureHost: () => Promise<unknown>
Expand Down
19 changes: 18 additions & 1 deletion src/main/runtime/agent-session/lifecycle/pr-watch-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import type { JournalWriterCommit } from '../../../native-chat/agent-session-jou
import type { AgentSessionJournal } from '../../../native-chat/agent-session-journal/journal-store'
import type { StructuredAgentSessionLogger } from '../../../native-chat/agent-session-wire/host/structured-agent-session-logger'
import { getStructuredAgentSessionHost } from '../../../native-chat/agent-session-wire/host/structured-agent-session-registry'
import { openAgentSessionRecordStoreOnce } from '../records/agent-session-record-store-slot'
import {
openAgentSessionRecordStoreOnce,
peekOpenedAgentSessionRecordStore
} from '../records/agent-session-record-store-slot'
import { hasPersistedStructuredAgentSessionDatabaseFile } from '../records/persisted-agent-session-database-file'
import { isHostShuttingDown } from '../../../startup/quit/host-shutdown-state'

export type PRWatchRuntimeDeps = {
Expand Down Expand Up @@ -48,6 +52,16 @@ export function startPRWatchRuntime(
admittedDeps = deps
const startedIn = generation
starting ??= (async () => {
// Skip opening the chat journal writer/reader workers when no structured chat DB exists yet.
if (
!peekOpenedAgentSessionRecordStore() &&
!(await hasPersistedStructuredAgentSessionDatabaseFile(deps.stateDirectory))
) {
if (startedIn === generation) {
starting = null
}
return
}
const { store, journalDatabase } = await openAgentSessionRecordStoreOnce(
withPRWatchRecovery({
stateDirectory: deps.stateDirectory,
Expand Down Expand Up @@ -124,6 +138,9 @@ export function observePRWatchCommittedRows(
journal: AgentSessionJournal,
rows: JournalWriterCommit | undefined
): void {
if (!running && !starting && admittedDeps) {
resumePRWatchRuntime()
}
// Before watches start, captured obligations simply wait in their table for the first drain.
running?.observeCommittedRows(sessionId, journal, rows)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { access } from 'node:fs/promises'
import {
journalDatabasePath,
journalDomainDatabasePath
} from '../../../native-chat/agent-session-journal/database/journal-host-database'

/** Non-blocking existence check so async callers skip spawning journal workers on empty profiles.
* Lives apart from the record-store slot so the host-refusal gate can use it without an import cycle. */
export async function hasPersistedStructuredAgentSessionDatabaseFile(
stateDirectory: string
): Promise<boolean> {
for (const candidate of [
journalDomainDatabasePath(stateDirectory),
journalDatabasePath(stateDirectory)
]) {
try {
await access(candidate)
return true
} catch {
// Absent file; check the next candidate.
}
}
return false
}
16 changes: 11 additions & 5 deletions src/main/runtime/rpc/methods/history/ai-vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
searchWithStructuredOwners
} from '../../../../ai-vault/structured-sessions/structured-session-ownership'
import {
ensureStructuredAgentSessionHostUnlessRefused,
ensurePersistedStructuredAgentSessionHostUnlessRefused,
tryEnsureStructuredAgentSessionHostForResume
} from '../../../agent-session/installation/structured-agent-session-host-refusal'
import {
Expand Down Expand Up @@ -53,7 +53,10 @@ export const AI_VAULT_METHODS = [
// A client that reads no structured sessions keeps the transcript hit, as before.
return supportsStructuredAgentSessions(context)
? searchWithStructuredOwners(response, {
ensureHost: () => context.runtime.ensureStructuredAgentSessionHost(),
ensureHost: () =>
ensurePersistedStructuredAgentSessionHostUnlessRefused(() =>
context.runtime.ensureStructuredAgentSessionHost()
),
transport,
opensChat: (agent) => clientOpensStructuredChatFromHistory(context, agent)
})
Expand Down Expand Up @@ -100,7 +103,7 @@ export const AI_VAULT_METHODS = [
permission: 'workspace',
params: AiVaultListSessionsParams,
handler: async (params, { runtime, clientKind, clientCapabilities, signal }) => {
await ensureStructuredAgentSessionHostUnlessRefused(() =>
await ensurePersistedStructuredAgentSessionHostUnlessRefused(() =>
runtime.ensureStructuredAgentSessionHost()
)
let result
Expand Down Expand Up @@ -157,10 +160,13 @@ export const AI_VAULT_METHODS = [
executionHostId: LOCAL_EXECUTION_HOST_ID
}
if (!isWslUncPath(args.filePath)) {
const ensureHost = () => runtime.ensureStructuredAgentSessionHost()
const ensureHost = () =>
ensurePersistedStructuredAgentSessionHostUnlessRefused(() =>
runtime.ensureStructuredAgentSessionHost()
)
await (args.codexHome === null && !args.fork
? tryEnsureStructuredAgentSessionHostForResume(ensureHost)
: ensureStructuredAgentSessionHostUnlessRefused(ensureHost))
: ensureHost())
assertLegacyAiVaultResumeAllowed(args)
}
return (
Expand Down
Loading