FULL_REPO_EVIDENCE_THREADS_AUDIT_VERIFICATION.mdHistoricalView source

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

  1. 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 .notDetermined PCC 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.
  2. 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?
  3. 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?
  4. 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?
  5. 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?
  6. Concurrency Locking in Index: Does writing to the thread index.json file concurrently with streaming token writes to thread_<id>.json introduce file lock contentions under NSFileCoordinator?
  7. Legacy Chat History Cleanup: When migrating legacy chat_history_<containerId>.json files to Design B threads, are they completely deleted or moved to an offline quarantine path to prevent data loss?
  8. PCC Performance Cooldown: How frequently does the system trigger isPCCSuppressed due to rate limits or context cooldowns, and how does this affect thread query routing?
  9. Memory Footprint of Pinned Findings: Are EvidenceFinding objects loaded into memory globally on app launch, or are they lazily evaluated on thread selection?
  10. Entitlement Store Cache Invalidation: Does purchasing a doc_pack_addon instantly refresh active thread limits, or does it require an app relaunch to recalculate limits?

Top 10 Files to Be Manually Reviewed Before Implementation

  1. ChatMessage.swift (Verify properties, coding keys, and chunk sanitization).
  2. RAGService.swift (Verify chat history save/load and trim logic).
  3. ChatScreen.swift (Verify UI state binding, preloading, and lifecycle hooks).
  4. WorkspaceSyncService.swift (Verify path-exclusion boundaries and coordinated file utilities).
  5. KnowledgeContainer.swift (Verify AppSupportPaths static directory structure).
  6. EntitlementStore.swift (Verify quota limits, active tier evaluations, and legacy protection).
  7. FoundationModelRoutePolicy.swift (Verify 4K routing limit and query type mapping).
  8. RAGAppIntents.swift (Verify background execution contexts and registered shortcut list).
  9. SettingsStore.swift (Verify PCC consent keys).
  10. 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 (Contains EvidenceThread and EvidenceFinding structs).
  • OpenIntelligence/Services/Storage/EvidenceThreadStore.swift (Coordinates file operations, directory indexing, and thread caching).

Exact Files to Modify

  • OpenIntelligence/Core/Models/ChatMessage.swift (Add optional threadId: UUID? to properties and CodingKeys to preserve schema safety).
  • OpenIntelligence/Features/Chat/Conversation/ChatScreen.swift (Inject EvidenceThreadStore, 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

  1. 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).
  2. iCloud Sandbox Sync Dry Run: Enable iCloud sync in sandbox mode and confirm that NO EvidenceThreads directories or JSON files are copied to the ubiquity container.
  3. App Launch State Restoration Test: Select an active thread, terminate the app, relaunch, and verify that the UI restores the selected thread transcript.
  4. Siri Intent Background Timeout Validation: Trigger QueryDocumentsIntent via Siri in a .notDetermined PCC consent state and confirm that it handles context overflows gracefully without deadlocking background threads.
  5. Legacy History Migration verification: Preload a Version 2.6 chat_history_<containerId>.json file, launch Version 27, and confirm that the messages are successfully migrated to a default thread under LocalCache/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/BehaviorStatusSource FilesExact Symbols / FunctionsEvidence & Verification Notes
ChatV2 PersistenceContradictedChatMessage.swiftLine 37 commentCode 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].jsonVerifiedKnowledgeContainer.swiftAppSupportPaths.chatHistoryURLPath resolves to baseDir()/chat_history_\(containerId.uuidString).json.
sanitizedForPersistence()VerifiedChatMessage.swiftsanitizedForPersistenceTruncates retrieved chunks to 12 items and trims content to 600 characters.
pipelineTrace ExclusionVerifiedChatMessage.swiftCodingKeyspipelineTrace and thinkingEvents are omitted from CodingKeys to exclude them from disk persistence.
Active Container SwitchingVerifiedChatScreen.swift.task(id: activeContainerId)Fires a reload that loads the target history on container switch.
Relaunch RestorationVerifiedContainerService.swiftactiveContainerIdRestores active ID from UserDefaults and loads the history from disk.
iCloud Sync BoundariesContradictedWorkspaceSyncService.swiftlocalContents sync sweepThe 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 SyncVerifiedWorkspaceSyncService.swiftcriticalMetadataFileNamesSyncs containers.json, documents_metadata.json, and ingestion_queue.json.
Last-Write-Wins SyncVerifiedWorkspaceSyncService.swiftsynchronizeAuxiliaryFileEvaluates file modification dates and overwrites local/remote data using the newest file.
PCC RoutingVerifiedFoundationModelRoutePolicy.swiftdetermineRouteRoutes to Private Cloud Compute if context token counts exceed limits.
Cloud ConsentPartially SupportedSettingsStore.swiftapplePCCConsent keyPrior audit claimed the UserDefaults key is "applePCCConsent". The actual key is "cloudConsent.applePCC".
StoreKit GatesVerifiedWorkspaceSyncService.swiftisAtLeast(.pro) gateRestricts iCloud shared workspace sync to Pro and Lifetime subscribers.
App Shortcut CountVerifiedRAGAppIntents.swiftRAGAppShortcutsProviderThe 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 through RAGService.persistChatHistory to chat_history_<containerId>.json.
  • Restoration works on relaunch: The app restores the active container ID from UserDefaults and 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:

SubstrateData StoredRead FunctionWrite FunctionAtomic Safeguard
JSONContainers list, Document metadata, Chat history, Ingestion queue, Suggested questionsJSONDecoder.decode()JSONEncoder.encode()Yes (Using WorkspaceSyncService.coordinatedWriteData writing to .tmp first)
SQLite (FTS5)Indexed document chunks and lexical metadataSQLiteFullTextService.sharedSQLiteFullTextService.sharedYes (SQL transactions managed locally; database can be rebuilt from source files)
Vector Store384D float embeddings mapped to chunk IDsBNNSVectorDatabase.load()BNNSVectorDatabase.persist()Yes (Uses temporary files and swaps them on completion)
UserDefaultsScalar user settings, PCC consent state, active container IDUserDefaults.string(forKey:)UserDefaults.set()Yes (Managed by system property list syncing)
KeychainStoreKit receipts and credentialsStoreKitBillingServiceStoreKitBillingServiceYes (Hardware-secured)
iCloud ContainerWorkspace files synced across devicesNSMetadataQueryWorkspaceSyncServiceYes (NSFileCoordinator locks)
CloudKitNot PresentN/AN/AN/A
In-MemoryLLM session transcripts, pipeline traces, thinking eventsRead properties directlyAppend properties directlyNo (Transient state only)
Local CacheBackground ingestion and query continuation status JSON filesBackgroundTaskService.loadBackgroundTaskService.saveYes (Direct atomic file writes)

Reusing Coordination Utilities

  • Reusing coordinatedWriteData is Unsafe for local-only threads: WorkspaceSyncService.coordinatedWriteData posts a .localWorkspaceDidChange notification. 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 coordinatedWriteLocalOnlyData in the new EvidenceThreadStore.swift to use NSFileCoordinator and 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 under ImportedDocuments/ are synced.
  • Local-Only Files: Directory LocalCache/ and its subdirectories (like FTS5/) are explicitly excluded.
  • Accidental Sync Risk: If Evidence Threads are stored as baseDir()/threads/ or baseDir()/evidence_thread_<id>.json, they will NOT match the localOnlyEntryNames list 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 by WorkspaceSyncService.localOnlyEntryNames rules, guaranteeing Phase 1 threads remain local-only.

8. Routing and PCC Verification

  • Token Thresholds:
    • Routing Limit: Hardcoded to 4,096 tokens in FoundationModelRoutePolicy.swift line 42.
    • Token Budget: Calculated as 8,192 tokens minus 800 token buffer (7,392 tokens) for on-device in FoundationModelTokenBudget.swift line 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.
  • 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 withCheckedContinuation if consent is .notDetermined because there is no UI view to present the sheet.
  • 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 AppShortcutsProvider causes 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:
    • legacyProtectionState values (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.