desktop/src-tauri/crates/core/src/adapters/kilo/common.rs
Comment 1, line 1
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:1
//! Kilo Code CLI helpers moved from root usage_map.rs under the V30 directory convention.Comment 2, line 2
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:2
//! - map_kilo/KiloUsage maps mutually exclusive usage buckets.Comment 3, line 3
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:3
//! - Read-only source SQLite access follows architecture.md#database:Comment 4, line 4
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:4
//! direct connection/short probe, with Online Backup to system temp on busy-like probe failure.Comment 5, line 5
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:5
//! Staging has page/time/size limits and cleanup; errors propagate so existing results survive.Comment 6, line 6
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:6
//! Never checkpoint or alter source journal/schema, or create source-side files.Comment 7, line 7
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:7
//!Comment 8, line 8
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:8
//! Cross-Agent usage_map.rs retains MappedUsage/finish/sub_checked and contradiction checks.Comment 9, line 19
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:19
/// OpenCode-derived Kilo message.data.tokens has five mutually exclusive components:Comment 10, line 20
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:20
/// total = input + output + reasoning + cache.read + cache.write, verified inComment 11, line 21
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:21
/// m0-agent-fixtures.md. Add reasoning to canonical output_total as derived outputComment 12, line 22
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:22
/// to satisfy normalized total_tokens = input_total + output_total when required buckets are known.Comment 13, line 23
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:23
///Comment 14, line 24
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:24
/// total is optional: unfinished/failed messages may omit it (two/one records in realComment 15, line 25
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:25
/// 7.4.8/7.4.9 samples; 42 of 13,342 local assistant rows). Missing source_total remainsComment 16, line 26
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:26
/// None, without zero-filling; complete known components can still derive total.Comment 17, line 99
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:99
/// Read-only source access; busy-like probe failures switch to a staging snapshot.Comment 18, line 100
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:100
/// _staging owns the snapshot guard; drop cleans up even after query failure.Comment 19, line 124
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:124
/// SQLite busy/locked/CANTOPEN errors prevent a successful consistency probe.Comment 20, line 134
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:134
/// Staging page/time/size limits and cleanup follow architecture.md.Comment 21, line 137
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:137
/// Pages copied per backup step, bounding work while holding locks.Comment 22, line 139
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:139
/// Snapshot byte limit; abort oversized backups rather than filling the disk.Comment 23, line 141
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:141
/// Overall backup timeout.Comment 24, line 149
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:149
// Default 2 GiB staging limit; do not force-copy larger live databases, preserving prior results.Comment 25, line 151
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:151
// Default 30-second staging timeout; exceeding it returns busy rather than completing the snapshot.Comment 26, line 157
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:157
/// Open read-only with short busy_timeout so probe waits are boundedComment 27, line 158
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:158
/// without blocking the collection thread for long periods.Comment 28, line 171
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:171
/// Online Backup creates a consistent system-temp snapshot without writing the source.Comment 29, line 172
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:172
/// Copy in steps, aborting at limits; close destination handles before removing partial files.Comment 30, line 173
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:173
/// Windows remove_file can otherwise fail because an open handle denies shared deletion.Comment 31, line 190
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:190
// ? exits this closure only; every failure reaches common cleanup after handles close.Comment 32, line 205
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:205
// StepResult is non-exhaustive; retryable results remain within the configured limits.Comment 33, line 206
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:206
// More means pages were copied; count those pages toward the size limit.Comment 34, line 217
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:217
// Busy/Locked or other non-exhaustive results retry without progress, within the timeout.Comment 35, line 218
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:218
// 2026-09-30 fix: retries previously added pages and raced the timeout, causingComment 36, line 219
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:219
// platform-specific false size-limit failures (Linux CI hit the page cap before timeout).Comment 37, line 227
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:227
// Destination/backup handles have closed with the closure; they no longer prevent removal.Comment 38, line 239
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:239
/// Open kilo.db for read-only access:Comment 39, line 240
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:240
///Comment 40, line 241
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:241
/// 1. Open directly and run the short probe; this function creates no explicit read transaction.Comment 41, line 242
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:242
/// 2. On busy-like probe failure, create/read an Online Backup snapshot.Comment 42, line 243
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:243
/// 3. Other failures become CoreError; callers retain existing results and report the error.Comment 43, line 244
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:244
///Comment 44, line 245
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:245
/// Never write the source database.Comment 45, line 261
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:261
// The consistency probe failed; back up through the same read-only source connection.Comment 46, line 273
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:273
/// kilo.db schema fingerprint covers required tables/columns, without records or conversations.Comment 47, line 274
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:274
/// Require five message columns and eight session columns, including five reconciliation token columns.Comment 48, line 288
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:288
/// Missing tables/columns return None; the persisted fingerprint contains only table/column names.Comment 49, line 356
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:356
// Missing native total keeps source_total unknown while known components can still derive total.Comment 50, line 369
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:369
// Diagnose disagreement between comparable reported and derived totals.Comment 51, line 396
desktop/src-tauri/crates/core/src/adapters/kilo/common.rs:396
// Overflowed derived fields stay None; do not panic or truncate numeric values.