Main no longer opens desktop business SQLite. A single utility-process
storage owner holds the Assistant, Knowledge, attachment, document-result,
remote-binding and native model-ledger databases and runs whole domain
transactions; Main and Runtime callers use explicit async domain operations.
- Remove the Main readWithFallback path and the supervision worker's
separate business write connection; manifests are scanned read-only and
committed by the sole writer.
- Remote events are ACKed only after commit; process loss reports
unconfirmed writes instead of replaying them.
- Use native utilityProcess messaging with one in-flight bound (32) and
ordered waiting instead of capacity rejection and retries.
- Start the storage process before the window so startup overlaps.
- Keep short tool output in memory and store full output once in owned
storage; paging, branching, restart and deletion reuse that copy.
- Put required runtime launch files under goodbuddy-prefixed owned temp
directories and reclaim confirmed stale ones; stop writing duplicate
parsed.md.
- Add lint guards for SQLite ownership and architecture, concurrency
acceptance fixtures, and maintenance/architecture documentation.
Validation: typecheck and lint pass. Alternating baseline (edf019aa) vs
candidate runs show no regression on single-session, C01, C02, C04 and a
5-minute C06; Main p99 drops from ~21 ms to ~16.7 ms under concurrency.
Fresh portable copy (1.75M events) upgrade content unchanged; real-model
output paging passes with 4 external requests. Full npm test runs had
1-9 different timing-sensitive failures per run that pass when rerun.
Not covered: C03 review publication, C07 source body, app-level C05.
36 lines
2.5 KiB
TypeScript
36 lines
2.5 KiB
TypeScript
import type { AssistantDatabase } from '../../src/main/assistant/assistant-database'
|
|
import { createSupervisionDomainPorts } from '../../src/main/assistant/supervision-domain-ports'
|
|
import type { DesktopStorageClient } from '../../src/main/desktop-storage-client'
|
|
import { storageDataBytes } from '../../src/main/desktop-storage-contracts'
|
|
import type { ReadonlyQueryReader } from '../../src/main/readonly-query-reader'
|
|
import type { ReviewState } from '../../src/main/assistant/supervision-review-store'
|
|
|
|
/** Exercise the real caller facades and repository commits across an asynchronous data boundary. */
|
|
export function asyncSupervisionStorage(database: AssistantDatabase, before?: (domain: string, method: string, args: unknown[]) => Promise<void>, reader?: ReadonlyQueryReader) {
|
|
const call = async (domain: string, method: string, args: unknown[], options?: { signal?: AbortSignal }) => {
|
|
storageDataBytes(args)
|
|
const data = structuredClone(args)
|
|
if (before) await before(domain, method, data)
|
|
options?.signal?.throwIfAborted()
|
|
if (domain === 'assistant' && method === 'supervisionContext') {
|
|
if (reader) return reader.call('reviewContext', data, options?.signal)
|
|
const { scope } = data[0] as ReviewState['request']
|
|
return database.readSnapshot(() => ({ summary: database.reviewSummary(scope, 'supervisor'), background: database.reviewBackground(scope) }))
|
|
}
|
|
if (domain === 'assistant' && method === 'listSupervisionCandidates' && reader) return reader.call('reviewCandidates', data, options?.signal)
|
|
if (domain === 'review' && reader && (method === 'initialize' || method === 'resume')) {
|
|
const store = database.supervisionReviewStore()
|
|
const runId = String(data[0])
|
|
return method === 'initialize'
|
|
? store.initializeWithReader(runId, data[1] as ReviewState, reader.reviewManifest(runId), options?.signal)
|
|
: store.resumeWithReader(runId, reader.reviewManifest(runId), options?.signal)
|
|
}
|
|
const target = domain === 'assistant' ? database : domain === 'review' ? database.supervisionReviewStore(options?.signal)
|
|
: domain === 'stories' ? database.supervisionStories() : domain === 'experiences' ? database.supervisionExperiences()
|
|
: database.supervisionSuggestions()
|
|
const operation = (target as unknown as Record<string, (...input: unknown[]) => unknown>)[method]!
|
|
return structuredClone(await operation.apply(target, data))
|
|
}
|
|
return createSupervisionDomainPorts({ call: call as DesktopStorageClient['call'] })
|
|
}
|