Files
orca/src/main/runtime/structured-agent-session-journal-open.ts
T
Brennan Benson acea59c6d8 refactor(native-chat): remove the records-file and per-chat journal imports (#26038)
* refactor(native-chat): remove the records-file and per-chat journal imports

Every native chat user is on a build that already moved chat records and
history into the app-wide database, so the one-time copies are dead code:
the agent-sessions.json import and its owed-copy flag, the per-chat
journal.db import and the write-queue hold behind it, and the pre-SQLite
log.jsonl notice.

* refactor(native-chat): remove what only the deleted imports used

- JournalHostDatabase.unsyncedTransaction and the synchronous-pragma reset
  that undid it; JOURNAL_SYNCHRONOUS is now module-local. The stranded
  rollback test drives transaction() instead.
- deleteUnpublishedJournalRows and its SQL, plus its test.
- boundJournalStatusText.
- Stale comments naming the removed first-use copy (queued messages,
  send refusal example, JOURNAL_SYNCHRONOUS doc).
- Write-queue and readInOrder comments: a write also lags when issued
  behind one still waiting in line.
- Resolved-append ordering test binds the sink from inside a running read,
  so a resolver that read at handover now fails it.

* test(native-chat): run resolved-append in the SQLite runtime project
2026-10-06 23:03:32 -07:00

45 lines
1.8 KiB
TypeScript

// Opening the chat journal database for the host install.
import { JournalHostDatabase } from '../native-chat/agent-session-journal/journal-host-database'
import { journalOpenRefusalError } from '../native-chat/agent-session-journal/journal-open-failure'
import { recordStructuredAgentSessionHostInstallRefusal } from './structured-agent-session-host-refusal'
import type { StructuredAgentSessionLogger } from '../native-chat/agent-session-wire/structured-agent-session-logger'
// Every chat request retries a failed open, so each distinct failure is logged once, with its stack.
let lastLoggedOpenFailure: string | null = null
function logOpenFailureOnce(logger: StructuredAgentSessionLogger, error: unknown): void {
const failure =
error instanceof Error
? `${'code' in error ? String(error.code) : ''}:${error.message}`
: String(error)
if (failure === lastLoggedOpenFailure) {
return
}
lastLoggedOpenFailure = failure
logger.error('opening the chat journal database failed', {
scope: 'journal-database-open',
error
})
}
/** The journal database. A refusal is recorded for the gate and thrown to the caller; the next
* install tries again. */
export function openStructuredAgentSessionJournalDatabase(args: {
stateDirectory: string
logger: StructuredAgentSessionLogger
}): JournalHostDatabase {
try {
const opened = JournalHostDatabase.open(args.stateDirectory)
recordStructuredAgentSessionHostInstallRefusal(null)
lastLoggedOpenFailure = null
return opened
} catch (error) {
logOpenFailureOnce(args.logger, error)
// Nothing is renamed, deleted or rebuilt: the file is left exactly as it is.
const refusal = journalOpenRefusalError(error)
recordStructuredAgentSessionHostInstallRefusal(refusal)
throw refusal
}
}