Documentation status: [Archived]. This document is kept for historical evidence. Do not use as the source of truth for OpenIntelligence v4.3.
OpenIntelligence Evidence Threads Audit Verification Report
Adversarial Verification & Architecture Audit
This report presents a read-only adversarial verification pass against the prior Docs/FULL_REPO_EVIDENCE_THREADS_ARCHITECTURE_AUDIT.md report. The objective is to verify repo-wide coverage, identify stale or contradicted claims, resolve architectural inconsistencies, and establish the safety parameters for a Phase 1 local-only Evidence Threads implementation.
1. Final Go/No-Go Gate
Can Phase 1 local Evidence Threads proceed?
Yes. The implementation of local-only Evidence Threads can proceed, provided it uses Design B (isolated thread files stored within the local cache directory) and bypasses the main application support folder to avoid accidental iCloud sync.
Confidence Score
95 / 100
(5% deduction due to the risk of background Siri app intents blocking indefinitely on Private Cloud Compute consent dialogs).
Top 10 Unresolved Uncertainties
- Siri Background Deadlock: What is the system behavior when a background Siri intent (e.g., QueryDocumentsIntent) triggers a context window overflow (> 4,096 tokens) in a
.notDeterminedPCC consent state? The current codebase halts on a Swift CheckedContinuation that awaits a UI sheet resolution, which will block background intent execution until timed out by the OS. - iCloud Auto-migration Sweeps: Will future updates to WorkspaceSyncService.swift alter directory listing sweeps to include subdirectories of
LocalCache/, accidentally pulling thread files into the sync boundary? - Core Data / SwiftData Adoption: Is there a parallel roadmap to migrate document metadata from JSON to SwiftData in Version 27, which would instantly deprecate local-only JSON thread files?
- Token Count Discrepancy: Why does FoundationModelRoutePolicy.swift enforce a hardcoded 4,096-token on-device limit for routing standard/deep think queries, while FoundationModelTokenBudget.swift declares the on-device Apple FM context size is 8,192 tokens?
- StoreKit 2 Sandbox Compilation: Will testing StoreKit 2 receipt validation fail in local CI pipelines without a StoreKit configuration file attached to the testing scheme?
- Concurrency Locking in Index: Does writing to the thread
index.jsonfile concurrently with streaming token writes tothread_<id>.jsonintroduce file lock contentions underNSFileCoordinator? - Legacy Chat History Cleanup: When migrating legacy
chat_history_<containerId>.jsonfiles to Design B threads, are they completely deleted or moved to an offline quarantine path to prevent data loss? - PCC Performance Cooldown: How frequently does the system trigger
isPCCSuppresseddue to rate limits or context cooldowns, and how does this affect thread query routing? - Memory Footprint of Pinned Findings: Are
EvidenceFindingobjects loaded into memory globally on app launch, or are they lazily evaluated on thread selection? - Entitlement Store Cache Invalidation: Does purchasing a
doc_pack_addoninstantly refresh active thread limits, or does it require an app relaunch to recalculate limits?
Top 10 Files to Be Manually Reviewed Before Implementation
- ChatMessage.swift (Verify properties, coding keys, and chunk sanitization).
- RAGService.swift (Verify chat history save/load and trim logic).
- ChatScreen.swift (Verify UI state binding, preloading, and lifecycle hooks).
- WorkspaceSyncService.swift (Verify path-exclusion boundaries and coordinated file utilities).
- KnowledgeContainer.swift (Verify
AppSupportPathsstatic directory structure). - EntitlementStore.swift (Verify quota limits, active tier evaluations, and legacy protection).
- FoundationModelRoutePolicy.swift (Verify 4K routing limit and query type mapping).
- RAGAppIntents.swift (Verify background execution contexts and registered shortcut list).
- SettingsStore.swift (Verify PCC consent keys).
- DocumentPicker.swift (Verify workspace directory interactions).
Chosen Storage Design
Design B (Isolated Thread Files)
Thread transcripts will be stored in individual thread_<threadId>.json files, managed via a central index.json under the LocalCache/EvidenceThreads/ directory to prevent data loss via the 200-message pruning cap.
Exact Files to Create
OpenIntelligence/Core/Models/EvidenceThread.swift(ContainsEvidenceThreadandEvidenceFindingstructs).OpenIntelligence/Services/Storage/EvidenceThreadStore.swift(Coordinates file operations, directory indexing, and thread caching).
Exact Files to Modify
OpenIntelligence/Core/Models/ChatMessage.swift(Add optionalthreadId: UUID?to properties andCodingKeysto preserve schema safety).OpenIntelligence/Features/Chat/Conversation/ChatScreen.swift(InjectEvidenceThreadStore, switch rendering based on the active thread ID, and display a thread creation button).
Exact Files Not to Touch
OpenIntelligence/Services/Infrastructure/Storage/WorkspaceSyncService.swift(Do not modify sync logic; thread paths are already excluded via parent directory rules).OpenIntelligence/Services/Billing/StoreKitBillingService.swift(Do not disturb pricing models or StoreKit APIs).OpenIntelligence/Services/AIPlatform/AppleFoundationModels/FoundationModelRoutePolicy.swift(Do not edit LLM routing policies).
Required Tests/Manual QA Before Merge
- Pruning Cap Boundary Test: Run a test verifying that adding > 200 messages in one thread does not prune messages in other threads (confirming Design B isolation).
- iCloud Sandbox Sync Dry Run: Enable iCloud sync in sandbox mode and confirm that NO
EvidenceThreadsdirectories or JSON files are copied to the ubiquity container. - App Launch State Restoration Test: Select an active thread, terminate the app, relaunch, and verify that the UI restores the selected thread transcript.
- Siri Intent Background Timeout Validation: Trigger
QueryDocumentsIntentvia Siri in a.notDeterminedPCC consent state and confirm that it handles context overflows gracefully without deadlocking background threads. - Legacy History Migration verification: Preload a Version 2.6
chat_history_<containerId>.jsonfile, launch Version 27, and confirm that the messages are successfully migrated to a default thread underLocalCache/EvidenceThreads/.
2. Repository Inventory Verification
The repository file inventory has been verified by traversing the workspace tree, excluding non-tracked local directories (.git/, .build/, .swiftpm/, .gemini/):
- Total Checked Files: 543 files.
- Source File Inventory: repo_file_inventory.csv
- Excluded Directories:
.git/(Git repository metadata directory)..build/(Local Swift Package Manager build products and dependencies)..swiftpm/(Swift Package Manager configuration caches)..gemini/(AI agent workspace configuration files).- Justification: These directories contain intermediate compiler caches, dependency checkouts, and local workspace metadata. Including them in audits would result in false positives (e.g., auditing vendor dependencies) and cause extreme performance degradation.
3. Swift Symbol Inventory Verification
The codebase has been scanned to catalog all top-level types, protocols, extensions, and functions:
- Total Cataloged Symbols: 997 Swift symbols.
- Symbol Inventory: swift_symbol_inventory.csv
- Verification Statement: Every first-party symbol has been successfully tagged by its functional area (chat, persistence, RAG, retrieval, citation, ingestion, sync, billing, routing, App Intents, export, diagnostics, UI, unknown). All symbols tagged “unknown” have been manually audited or verified as helper utilities.
4. Prior Claim Verification Table
Every major claim from the previous audit has been audited against the codebase for verification:
| Claimed Feature/Behavior | Status | Source Files | Exact Symbols / Functions | Evidence & Verification Notes |
|---|---|---|---|---|
| ChatV2 Persistence | Contradicted | ChatMessage.swift | Line 37 comment | Code comment states that ChatV2 only stores messages in-memory. However, ChatScreen.swift and RAGService.swift explicitly write to disk via persistChatHistory. The comment is stale. |
| chat_history_[containerId].json | Verified | KnowledgeContainer.swift | AppSupportPaths.chatHistoryURL | Path resolves to baseDir()/chat_history_\(containerId.uuidString).json. |
| sanitizedForPersistence() | Verified | ChatMessage.swift | sanitizedForPersistence | Truncates retrieved chunks to 12 items and trims content to 600 characters. |
| pipelineTrace Exclusion | Verified | ChatMessage.swift | CodingKeys | pipelineTrace and thinkingEvents are omitted from CodingKeys to exclude them from disk persistence. |
| Active Container Switching | Verified | ChatScreen.swift | .task(id: activeContainerId) | Fires a reload that loads the target history on container switch. |
| Relaunch Restoration | Verified | ContainerService.swift | activeContainerId | Restores active ID from UserDefaults and loads the history from disk. |
| iCloud Sync Boundaries | Contradicted | WorkspaceSyncService.swift | localContents sync sweep | The prior audit claimed creating threads under baseDir()/threads/ would be local-only. However, WorkspaceSyncService syncs everything in baseDir() except files in localOnlyEntryNames. Thus, threads/ would sync, creating a risk. Storing threads in LocalCache/EvidenceThreads is required. |
| Auxiliary File Sync | Verified | WorkspaceSyncService.swift | criticalMetadataFileNames | Syncs containers.json, documents_metadata.json, and ingestion_queue.json. |
| Last-Write-Wins Sync | Verified | WorkspaceSyncService.swift | synchronizeAuxiliaryFile | Evaluates file modification dates and overwrites local/remote data using the newest file. |
| PCC Routing | Verified | FoundationModelRoutePolicy.swift | determineRoute | Routes to Private Cloud Compute if context token counts exceed limits. |
| Cloud Consent | Partially Supported | SettingsStore.swift | applePCCConsent key | Prior audit claimed the UserDefaults key is "applePCCConsent". The actual key is "cloudConsent.applePCC". |
| StoreKit Gates | Verified | WorkspaceSyncService.swift | isAtLeast(.pro) gate | Restricts iCloud shared workspace sync to Pro and Lifetime subscribers. |
| App Shortcut Count | Verified | RAGAppIntents.swift | RAGAppShortcutsProvider | The provider registers exactly 9 shortcuts, leaving 1 slot free before hitting the system limit of 10. |
5. Resolution of the ChatV2 Persistence Contradiction
The Contradiction
A comment in ChatMessage.swift says:
// Note: ChatV2 currently stores messages in-memory only (not persisted), so this is intentionally lightweight.
However, the previous audit claimed ChatV2 persists via chat_history_<containerId>.json.
Verification Findings
- The Comment is Stale: The comment was added during an early prototype phase.
- ChatV2 is Fully Persistent: The active UI binds to the messages array in
ChatScreen.swift. Changes are saved throughRAGService.persistChatHistorytochat_history_<containerId>.json. - Restoration works on relaunch: The app restores the active container ID from
UserDefaultsand loads the history from disk, displaying it in the V2 UI.
Chat Lifecycle Callgraph
[User submits query in ChatComposerV2]
│
▼
[Append ChatMessage to ChatScreen.messages array]
│
▼
[ChatScreen.persistChatHistory(for: activeContainerId)]
│
▼
[RAGService.persistChatHistory(messages, for: activeId)]
│
▼
(Prune to max 200 messages)
│
▼
(Map to sanitizedForPersistence()) ──► [ChatMessage.sanitizedForPersistence()]
│ │
▼ ▼
[WorkspaceSyncService.coordinatedWriteData] (Exclude pipelineTrace/thinkingEvents)
│ (Truncate retrievedChunks content to 600 chars)
▼ (Prune vector embeddings float arrays to [])
[Write to baseDir()/chat_history_<containerId>.json]
[App Relaunch]
│
▼
[ContainerService restores activeContainerId from UserDefaults]
│
▼
[ChatScreen task(id: activeContainerId) fires]
│
▼
[RAGService.preloadChatHistory(for: activeId)]
│
▼
[WorkspaceSyncService.coordinatedReadData]
│
▼
[Decode JSON array to [ChatMessage]]
│
▼
[Assign to ChatScreen.messages] ──► [Renders in MessageListV2 / MessageBubbleV2]
6. Storage Substrate Verification
OpenIntelligence utilizes ten distinct storage mechanisms. Thread implementation must be isolated to prevent conflicts:
| Substrate | Data Stored | Read Function | Write Function | Atomic Safeguard |
|---|---|---|---|---|
| JSON | Containers list, Document metadata, Chat history, Ingestion queue, Suggested questions | JSONDecoder.decode() | JSONEncoder.encode() | Yes (Using WorkspaceSyncService.coordinatedWriteData writing to .tmp first) |
| SQLite (FTS5) | Indexed document chunks and lexical metadata | SQLiteFullTextService.shared | SQLiteFullTextService.shared | Yes (SQL transactions managed locally; database can be rebuilt from source files) |
| Vector Store | 384D float embeddings mapped to chunk IDs | BNNSVectorDatabase.load() | BNNSVectorDatabase.persist() | Yes (Uses temporary files and swaps them on completion) |
| UserDefaults | Scalar user settings, PCC consent state, active container ID | UserDefaults.string(forKey:) | UserDefaults.set() | Yes (Managed by system property list syncing) |
| Keychain | StoreKit receipts and credentials | StoreKitBillingService | StoreKitBillingService | Yes (Hardware-secured) |
| iCloud Container | Workspace files synced across devices | NSMetadataQuery | WorkspaceSyncService | Yes (NSFileCoordinator locks) |
| CloudKit | Not Present | N/A | N/A | N/A |
| In-Memory | LLM session transcripts, pipeline traces, thinking events | Read properties directly | Append properties directly | No (Transient state only) |
| Local Cache | Background ingestion and query continuation status JSON files | BackgroundTaskService.load | BackgroundTaskService.save | Yes (Direct atomic file writes) |
Reusing Coordination Utilities
- Reusing
coordinatedWriteDatais Unsafe for local-only threads:WorkspaceSyncService.coordinatedWriteDataposts a.localWorkspaceDidChangenotification. This triggers a full workspace sync evaluation and database reconfigure cycle every time a local file is modified. Since threads are written to disk on every token update during LLM generation, this would cause extreme CPU overhead and continuous sync loops. - Recommendation: Implement
coordinatedWriteLocalOnlyDatain the newEvidenceThreadStore.swiftto useNSFileCoordinatorand write atomically without posting.localWorkspaceDidChange.
7. iCloud Sync Verification
- Files Synced Today: All files in the workspace base directory (e.g.,
containers.json,documents_metadata.json,ingestion_queue.json,chat_history_<containerId>.json) and files underImportedDocuments/are synced. - Local-Only Files: Directory
LocalCache/and its subdirectories (likeFTS5/) are explicitly excluded. - Accidental Sync Risk: If Evidence Threads are stored as
baseDir()/threads/orbaseDir()/evidence_thread_<id>.json, they will NOT match thelocalOnlyEntryNameslist and will be synced to iCloud by the directory sweep. - Safe Storage Path Recommendation: Threads must be stored under the local cache directory:
AppSupportPaths.localCacheDir().appendingPathComponent("EvidenceThreads", isDirectory: true)
This path is excluded from iCloud sync byWorkspaceSyncService.localOnlyEntryNamesrules, guaranteeing Phase 1 threads remain local-only.
8. Routing and PCC Verification
- Token Thresholds:
- Routing Limit: Hardcoded to 4,096 tokens in
FoundationModelRoutePolicy.swiftline 42. - Token Budget: Calculated as 8,192 tokens minus 800 token buffer (7,392 tokens) for on-device in
FoundationModelTokenBudget.swiftline 29. - Conflict: The routing policy uses a conservative 4,096 limit to trigger PCC routing, even though the token budget claims on-device can process up to 8,192 tokens.
- Routing Limit: Hardcoded to 4,096 tokens in
- Apple Private Cloud Compute (PCC) Limit: Up to 32,768 tokens is verified in
EngineSDKCompatibility.swift(line 159). - Deep Think and Maximum Routing Rules:
- Deep Think: Prioritizes local advanced model (on iOS 27+ / macOS 27+) if within the 4,096 limit. Falls back to PCC if allowed and context overflows.
- Maximum: Always scales to PCC (providing deep reasoning) if allowed, prioritizing local advanced only if PCC is offline or quota is exceeded.
- Cloud Consent Gate:
- PCC consent state is stored under key
"cloudConsent.applePCC". - If state is
.allowed, queries route to PCC. If.denied, they fallback to local-only with a hard 4,096 cap. If.notDetermined, it suspends the execution task. - App Intents Background Block Risk: Siri background queries will block indefinitely on
withCheckedContinuationif consent is.notDeterminedbecause there is no UI view to present the sheet.
- PCC consent state is stored under key
- Marketing Copy Guidelines:
- Unsafe Copy: “100% On-Device”, “Zero-Knowledge”, “Data never leaves device”.
- Safe Copy: “Local-First Processing”, “Transparent Routing Boundaries”, “Secure Scaling to Apple Private Cloud Compute”.
9. App Intents Shortcut Count Verification
- Registered App Shortcuts: Exactly 9 shortcuts are registered in
RAGAppShortcutsProvider.appShortcuts(Query, List, Import Status, Ask, Summarize, Compare, Search, Ingest Document, Ingest Webpage). - Apple System Limit: Exposing more than 10 App Shortcuts in
AppShortcutsProvidercauses OS registration failures. - Safety Handoff: Since only 1 shortcut slot remains, Phase 1 Evidence Threads must NOT register any app shortcuts. Thread interactions must remain strictly in-app.
10. Billing and Entitlement Verification
- Product Identifiers:
pro_monthly($5.99/month)pro_annual($49.99/year)lifetime_cohort($59.99 one-time)doc_pack_addon($2.99 consumable, adds 10 document slots)
- Quota Limits:
- Free: 1 library, 5 documents, 3 daily Maximum mode runs, no iCloud sync.
- Pro: 10 libraries, 1,000 documents (note: not unlimited), unlimited Maximum mode, iCloud sync enabled.
- Lifetime: 20 libraries, unlimited documents (
.max), unlimited Maximum mode, iCloud sync enabled.
- Legacy User Protection:
legacyProtectionStatevalues (historicalPaidPurchase,legacyDocumentPackOwner) bypass StoreKit active tier checks and grant effective Lifetime tier allowances.
- Entitlement Safety: The thread store must read the effective tier via
EntitlementStore.currentEffectiveTier()to apply quota limits (e.g., capping Free users to 3 threads) without altering StoreKit receipt validation.