feat(storage): move desktop SQLite ownership into a storage utility process
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.
This commit is contained in:
@@ -17,7 +17,7 @@ import type { DocumentParsingSettingsStore } from './document-parsing-settings-s
|
||||
import { HttpDocumentOcr } from './http-document-ocr'
|
||||
import { hasExtractedDocumentText } from './document-extracted-text'
|
||||
import { renderOcrPdf, renderSelectedOcrPdf } from './render-ocr-pdf'
|
||||
import type { DocumentResultStorage } from './document-result-storage'
|
||||
import type { DocumentResultStorageAccess } from './desktop-storage-files'
|
||||
import {
|
||||
extractPdfTextPagesOffMain,
|
||||
extractPptxPagesOffMain,
|
||||
@@ -161,11 +161,13 @@ function nativePdfSections(pages: PdfTextPage[]): ParsedSection[] {
|
||||
|
||||
export class DocumentParsingService {
|
||||
private readonly diagnosticOperations = new Map<string, AbortController>()
|
||||
private readonly diagnostics = new Map<AbortController, Promise<void>>()
|
||||
private disposed = false
|
||||
constructor(
|
||||
private readonly settingsStore: DocumentParsingSettingsStore,
|
||||
private readonly modelManager: DocumentOcrModelManager,
|
||||
private readonly ocrBroker: DocumentOcrBroker,
|
||||
readonly results?: DocumentResultStorage
|
||||
readonly results?: DocumentResultStorageAccess
|
||||
) {}
|
||||
|
||||
async snapshot(): Promise<DocumentParsingSnapshot> {
|
||||
@@ -633,12 +635,15 @@ export class DocumentParsingService {
|
||||
purpose: DocumentParsingPurpose = 'diagnostic',
|
||||
operationId?: string
|
||||
): Promise<DocumentParsingDiagnostic> {
|
||||
if (this.disposed) throw new Error('Document parsing service is closed')
|
||||
const startedAt = Date.now()
|
||||
const controller = new AbortController()
|
||||
if (operationId) {
|
||||
if (this.diagnosticOperations.has(operationId)) throw new Error('解析任务已在运行')
|
||||
this.diagnosticOperations.set(operationId, controller)
|
||||
}
|
||||
let settle!: () => void
|
||||
this.diagnostics.set(controller, new Promise(resolve => { settle = resolve }))
|
||||
try {
|
||||
const parsed = await this.parse(name, buffer, purpose, controller.signal)
|
||||
controller.signal.throwIfAborted()
|
||||
@@ -673,6 +678,8 @@ export class DocumentParsingService {
|
||||
})
|
||||
} finally {
|
||||
if (operationId) this.diagnosticOperations.delete(operationId)
|
||||
this.diagnostics.delete(controller)
|
||||
settle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,7 +688,9 @@ export class DocumentParsingService {
|
||||
}
|
||||
|
||||
async dispose(): Promise<void> {
|
||||
for (const controller of this.diagnosticOperations.values()) controller.abort(new Error('应用正在退出'))
|
||||
this.disposed = true
|
||||
for (const controller of this.diagnostics.keys()) controller.abort(new Error('应用正在退出'))
|
||||
await Promise.all(this.diagnostics.values())
|
||||
await this.results?.close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user