lean-ctx 3.8.8

Context Runtime for AI Agents with CCP. 71 MCP tools, 10 read modes, 95+ compression patterns, cross-session memory (CCP), persistent AI knowledge with temporal facts + contradiction detection, multi-agent context sharing, LITM-aware positioning, AAAK compact format, adaptive compression with Thompson Sampling bandits. Supports 24+ AI tools. Reduces LLM token consumption by up to 99%.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
use crate::core::config::Config;

/// Outcome of one background Personal-Cloud auto-push (GL #384).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AutoSyncOutcome {
    /// At least one surface pushed (or there was nothing to push).
    Synced,
    /// The server gated sync behind Pro (HTTP 402) — stop for today.
    Gated,
    /// Every push failed without a 402 (offline / server down) — try again
    /// at the next opportunity, do not consume today's slot.
    NetworkFailure,
}

/// Whether the auto-sync should run now: opt-in flag, logged in, and not
/// already synced today (the debounce). Pure for unit testing.
#[must_use]
pub fn should_auto_sync(
    auto_sync: bool,
    logged_in: bool,
    last_auto_sync: Option<&str>,
    today: &str,
) -> bool {
    auto_sync && logged_in && last_auto_sync != Some(today)
}

/// Whether the background index push should run for this project (GL #392):
/// separate opt-in, logged in, a local index actually exists, and this
/// project hasn't pushed today. Pure for unit testing.
#[must_use]
pub fn should_auto_push_index(
    auto_index: bool,
    logged_in: bool,
    local_index_exists: bool,
    last_push_for_project: Option<&str>,
    today: &str,
) -> bool {
    auto_index && logged_in && local_index_exists && last_push_for_project != Some(today)
}

/// Classify per-surface push results into one [`AutoSyncOutcome`]. A 402
/// anywhere wins (the account is gated); otherwise total failure means the
/// network is down; anything else counts as synced.
#[must_use]
pub fn classify_outcomes(results: &[Result<(), String>]) -> AutoSyncOutcome {
    if results
        .iter()
        .any(|r| r.as_ref().is_err_and(|e| e.contains("402")))
    {
        return AutoSyncOutcome::Gated;
    }
    if !results.is_empty() && results.iter().all(Result::is_err) {
        return AutoSyncOutcome::NetworkFailure;
    }
    AutoSyncOutcome::Synced
}

pub fn cloud_background_tasks() {
    let mut config = Config::load();
    let today = chrono::Local::now().format("%Y-%m-%d").to_string();

    let already_contributed = config
        .cloud
        .last_contribute
        .as_deref()
        .is_some_and(|d| d == today);
    let already_synced = config
        .cloud
        .last_sync
        .as_deref()
        .is_some_and(|d| d == today);
    let already_gain_synced = config
        .cloud
        .last_gain_sync
        .as_deref()
        .is_some_and(|d| d == today);
    let already_pulled = config
        .cloud
        .last_model_pull
        .as_deref()
        .is_some_and(|d| d == today);

    if config.cloud.contribute_enabled && !already_contributed {
        let entries = collect_contribute_entries();
        if !entries.is_empty() && crate::cloud_client::contribute(&entries).is_ok() {
            config.cloud.last_contribute = Some(today.clone());
        }
    }

    if crate::cloud_client::is_logged_in() {
        if !already_synced {
            let store = crate::core::stats::load();
            let entries = build_sync_entries(&store);
            if !entries.is_empty() && crate::cloud_client::sync_stats(&entries).is_ok() {
                config.cloud.last_sync = Some(today.clone());
            }
        }

        if !already_gain_synced {
            let engine = crate::core::gain::GainEngine::load();
            let summary = engine.summary(None);
            let trend = match summary.score.trend {
                crate::core::gain::gain_score::Trend::Rising => "rising",
                crate::core::gain::gain_score::Trend::Stable => "stable",
                crate::core::gain::gain_score::Trend::Declining => "declining",
            };
            let entry = serde_json::json!({
                "recorded_at": format!("{today}T00:00:00Z"),
                "total": summary.score.total as f64,
                "compression": summary.score.compression as f64,
                "cost_efficiency": summary.score.cost_efficiency as f64,
                "quality": summary.score.quality as f64,
                "consistency": summary.score.consistency as f64,
                "trend": trend,
                "avoided_usd": summary.avoided_usd,
                "tool_spend_usd": summary.tool_spend_usd,
                "model_key": summary.model.model_key,
            });
            if crate::cloud_client::push_gain(&[entry]).is_ok() {
                config.cloud.last_gain_sync = Some(today.clone());
            }
        }

        if !already_pulled && let Ok(data) = crate::cloud_client::pull_cloud_models() {
            let _ = crate::cloud_client::save_cloud_models(&data);
            config.cloud.last_model_pull = Some(today.clone());
        }

        // Opt-in Personal-Cloud auto-push (GL #384): silent, once per day,
        // offline-tolerant. A network failure leaves the slot open so the
        // next background cycle retries; a Pro gate consumes it (one quiet
        // attempt per day on a Free account, never error spam).
        if should_auto_sync(
            config.cloud.auto_sync,
            true,
            config.cloud.last_auto_sync.as_deref(),
            &today,
        ) && auto_sync_personal_cloud() != AutoSyncOutcome::NetworkFailure
        {
            config.cloud.last_auto_sync = Some(today.clone());
        }

        // Opt-in hosted-index auto-push (GL #392): once per project per day,
        // only when a local index exists. Quota/Pro rejections consume the
        // slot (one quiet attempt per day); network failures leave it open.
        if let Ok(root) = std::env::current_dir() {
            let project_hash = crate::core::index_namespace::namespace_hash(&root);
            if should_auto_push_index(
                config.cloud.auto_index,
                true,
                crate::core::index_bundle::local_index_present(&root),
                config
                    .cloud
                    .last_index_push
                    .get(&project_hash)
                    .map(String::as_str),
                &today,
            ) {
                match crate::cloud_client::push_index_bundle(&root) {
                    Ok((hash, bytes)) => {
                        tracing::debug!(project = %hash, bytes, "auto-index: pushed");
                        config
                            .cloud
                            .last_index_push
                            .insert(project_hash, today.clone());
                    }
                    Err(e) if e.contains("Pro") || e.contains("Quota") => {
                        tracing::debug!(error = %e, "auto-index: gated, retry tomorrow");
                        config
                            .cloud
                            .last_index_push
                            .insert(project_hash, today.clone());
                    }
                    Err(e) => {
                        tracing::debug!(error = %e, "auto-index: push failed, slot stays open");
                    }
                }
            }
        }
    }

    let _ = config.save();
}

/// Push every Personal-Cloud surface silently (background variant of
/// `lean-ctx sync`'s interactive flow — tracing instead of stdout).
fn auto_sync_personal_cloud() -> AutoSyncOutcome {
    let store = crate::core::stats::load();
    let mut results: Vec<Result<(), String>> = Vec::new();

    let mut push = |label: &str, result: Result<String, String>| match result {
        Ok(_) => {
            tracing::debug!(surface = label, "auto-sync: pushed");
            results.push(Ok(()));
        }
        Err(e) => {
            tracing::debug!(surface = label, error = %e, "auto-sync: push failed");
            results.push(Err(e));
        }
    };

    let commands = collect_command_entries(&store);
    if !commands.is_empty() {
        push("commands", crate::cloud_client::push_commands(&commands));
    }
    let cep = collect_cep_entries(&store);
    if !cep.is_empty() {
        push("cep", crate::cloud_client::push_cep(&cep));
    }
    let knowledge = collect_knowledge_entries();
    if !knowledge.is_empty() {
        push("knowledge", crate::cloud_client::push_knowledge(&knowledge));
    }
    let gotchas = collect_gotcha_entries();
    if !gotchas.is_empty() {
        push("gotchas", crate::cloud_client::push_gotchas(&gotchas));
    }
    let buddy = crate::core::buddy::BuddyState::compute();
    if let Ok(buddy_data) = serde_json::to_value(&buddy) {
        push("buddy", crate::cloud_client::push_buddy(&buddy_data));
    }
    let feedback = collect_feedback_entries();
    if !feedback.is_empty() {
        push("feedback", crate::cloud_client::push_feedback(&feedback));
    }

    let outcome = classify_outcomes(&results);
    tracing::info!(
        ?outcome,
        surfaces = results.len(),
        "personal-cloud auto-sync done"
    );
    outcome
}

pub fn build_sync_entries(store: &crate::core::stats::StatsStore) -> Vec<serde_json::Value> {
    let mut entries = Vec::new();
    let cep = &store.cep;
    let today = chrono::Local::now().format("%Y-%m-%d").to_string();

    let mut cep_cache_by_day: std::collections::HashMap<String, (u64, u64)> =
        std::collections::HashMap::new();
    for s in &cep.scores {
        if let Some(date) = s.timestamp.get(..10) {
            let entry = cep_cache_by_day.entry(date.to_string()).or_default();
            let calls = s.tool_calls.max(1);
            let hits = (calls as f64 * s.cache_hit_rate as f64 / 100.0).round() as u64;
            entry.0 += calls;
            entry.1 += hits;
        }
    }

    let mut mcp_saved_total = 0u64;
    for (cmd, s) in &store.commands {
        if cmd.starts_with("ctx_") {
            mcp_saved_total += s.input_tokens.saturating_sub(s.output_tokens);
        }
    }
    let global_saved = store
        .total_input_tokens
        .saturating_sub(store.total_output_tokens)
        .max(1);
    let mcp_ratio = mcp_saved_total as f64 / global_saved as f64;

    for day in &store.daily {
        let tokens_original = day.input_tokens;
        let tokens_compressed = day.output_tokens;
        let tokens_saved = tokens_original.saturating_sub(tokens_compressed);
        let (day_calls, day_hits) = cep_cache_by_day.get(&day.date).copied().unwrap_or((0, 0));
        let day_mcp_saved = (tokens_saved as f64 * mcp_ratio).round() as u64;
        let day_hook_saved = tokens_saved.saturating_sub(day_mcp_saved);
        entries.push(serde_json::json!({
            "date": day.date,
            "tokens_original": tokens_original,
            "tokens_compressed": tokens_compressed,
            "tokens_saved": tokens_saved,
            "mcp_tokens_saved": day_mcp_saved,
            "hook_tokens_saved": day_hook_saved,
            "tool_calls": day.commands,
            "cache_hits": day_hits,
            "cache_misses": day_calls.saturating_sub(day_hits),
        }));
    }

    let has_today = entries.iter().any(|e| e["date"].as_str() == Some(&today));
    if !has_today && (cep.total_tokens_original > 0 || store.total_commands > 0) {
        let today_saved = cep
            .total_tokens_original
            .saturating_sub(cep.total_tokens_compressed);
        let today_mcp = (today_saved as f64 * mcp_ratio).round() as u64;
        entries.push(serde_json::json!({
            "date": today,
            "tokens_original": cep.total_tokens_original,
            "tokens_compressed": cep.total_tokens_compressed,
            "tokens_saved": today_saved,
            "mcp_tokens_saved": today_mcp,
            "hook_tokens_saved": today_saved.saturating_sub(today_mcp),
            "tool_calls": store.total_commands,
            "cache_hits": cep.total_cache_hits,
            "cache_misses": cep.total_cache_reads.saturating_sub(cep.total_cache_hits),
        }));
    }

    entries
}

// ── Personal-Cloud surface collectors ────────────────────────────────────────
// Shared by the interactive `lean-ctx sync` flow and the background auto-sync
// (GL #384): pure local reads, no network, no stdout.

pub fn collect_knowledge_entries() -> Vec<serde_json::Value> {
    let Ok(data_dir) = crate::core::paths::data_dir() else {
        return Vec::new();
    };
    let knowledge_dir = data_dir.join("knowledge");
    if !knowledge_dir.is_dir() {
        return Vec::new();
    }

    let mut entries = Vec::new();

    for project_entry in std::fs::read_dir(&knowledge_dir).into_iter().flatten() {
        let Ok(project_entry) = project_entry else {
            continue;
        };
        let project_path = project_entry.path();
        if !project_path.is_dir() {
            continue;
        }

        for file_entry in std::fs::read_dir(&project_path).into_iter().flatten() {
            let Ok(file_entry) = file_entry else { continue };
            let file_path = file_entry.path();
            if file_path.extension().and_then(|e| e.to_str()) != Some("json") {
                continue;
            }
            let Ok(data) = std::fs::read_to_string(&file_path) else {
                continue;
            };
            let parsed: serde_json::Value = match serde_json::from_str(&data) {
                Ok(v) => v,
                Err(_) => continue,
            };

            if let Some(facts) = parsed["facts"].as_array() {
                for fact in facts {
                    let cat = fact["category"].as_str().unwrap_or("general");
                    let key = fact["key"].as_str().unwrap_or("");
                    let val = fact["value"]
                        .as_str()
                        .or_else(|| fact["description"].as_str())
                        .unwrap_or("");
                    if !key.is_empty() {
                        entries.push(serde_json::json!({
                            "category": cat,
                            "key": key,
                            "value": val,
                        }));
                    }
                }
            }

            if let Some(gotchas) = parsed["gotchas"].as_array() {
                for g in gotchas {
                    let pattern = g["pattern"].as_str().unwrap_or("");
                    let fix = g["fix"].as_str().unwrap_or("");
                    if !pattern.is_empty() {
                        entries.push(serde_json::json!({
                            "category": "gotcha",
                            "key": pattern,
                            "value": fix,
                        }));
                    }
                }
            }
        }
    }

    entries
}

pub fn collect_command_entries(store: &crate::core::stats::StatsStore) -> Vec<serde_json::Value> {
    store
        .commands
        .iter()
        .map(|(name, stats)| {
            let tokens_saved = stats.input_tokens.saturating_sub(stats.output_tokens);
            serde_json::json!({
                "command": name,
                "source": if name.starts_with("ctx_") { "mcp" } else { "hook" },
                "count": stats.count,
                "input_tokens": stats.input_tokens,
                "output_tokens": stats.output_tokens,
                "tokens_saved": tokens_saved,
            })
        })
        .collect()
}

fn complexity_to_float(s: &str) -> f64 {
    match s.to_lowercase().as_str() {
        "trivial" => 0.1,
        "simple" => 0.3,
        "moderate" => 0.5,
        "complex" => 0.7,
        "architectural" => 0.9,
        other => other.parse::<f64>().unwrap_or(0.5),
    }
}

pub fn collect_cep_entries(store: &crate::core::stats::StatsStore) -> Vec<serde_json::Value> {
    store
        .cep
        .scores
        .iter()
        .map(|s| {
            serde_json::json!({
                "recorded_at": s.timestamp,
                "score": s.score as f64 / 100.0,
                "cache_hit_rate": s.cache_hit_rate as f64 / 100.0,
                "mode_diversity": s.mode_diversity as f64 / 100.0,
                "compression_rate": s.compression_rate as f64 / 100.0,
                "tool_calls": s.tool_calls,
                "tokens_saved": s.tokens_saved,
                "complexity": complexity_to_float(&s.complexity),
            })
        })
        .collect()
}

pub fn collect_gotcha_entries() -> Vec<serde_json::Value> {
    let mut all_gotchas = crate::core::gotcha_tracker::load_universal_gotchas();

    if let Ok(knowledge_dir) = crate::core::paths::data_dir().map(|d| d.join("knowledge"))
        && let Ok(entries) = std::fs::read_dir(&knowledge_dir)
    {
        for entry in entries.flatten() {
            let gotcha_path = entry.path().join("gotchas.json");
            if gotcha_path.exists()
                && let Ok(content) = std::fs::read_to_string(&gotcha_path)
                && let Ok(store) =
                    serde_json::from_str::<crate::core::gotcha_tracker::GotchaStore>(&content)
            {
                for g in store.gotchas {
                    if !all_gotchas
                        .iter()
                        .any(|existing| existing.trigger == g.trigger)
                    {
                        all_gotchas.push(g);
                    }
                }
            }
        }
    }

    all_gotchas
        .iter()
        .map(|g| {
            serde_json::json!({
                "pattern": g.trigger,
                "fix": g.resolution,
                "severity": format!("{:?}", g.severity).to_lowercase(),
                "category": format!("{:?}", g.category).to_lowercase(),
                "occurrences": g.occurrences,
                "prevented_count": g.prevented_count,
                "confidence": g.confidence,
            })
        })
        .collect()
}

pub fn collect_feedback_entries() -> Vec<serde_json::Value> {
    let store = crate::core::feedback::FeedbackStore::load();
    store
        .learned_thresholds
        .iter()
        .map(|(lang, thresholds)| {
            serde_json::json!({
                "language": lang,
                "entropy": thresholds.entropy,
                "jaccard": thresholds.jaccard,
                "sample_count": thresholds.sample_count,
                "avg_efficiency": thresholds.avg_efficiency,
            })
        })
        .collect()
}

pub fn collect_contribute_entries() -> Vec<serde_json::Value> {
    let mut entries = Vec::new();

    if let Ok(data_dir) = crate::core::data_dir::lean_ctx_data_dir() {
        let mode_stats_path = data_dir.join("mode_stats.json");
        if let Ok(data) = std::fs::read_to_string(&mode_stats_path)
            && let Ok(predictor) = serde_json::from_str::<serde_json::Value>(&data)
            && let Some(history) = predictor["history"].as_object()
        {
            for (_key, outcomes) in history {
                if let Some(arr) = outcomes.as_array() {
                    for outcome in arr.iter().rev().take(3) {
                        let ext = outcome["ext"].as_str().unwrap_or("unknown");
                        let mode = outcome["mode"].as_str().unwrap_or("full");
                        let t_in = outcome["tokens_in"].as_u64().unwrap_or(0);
                        let t_out = outcome["tokens_out"].as_u64().unwrap_or(0);
                        let ratio = if t_in > 0 {
                            1.0 - t_out as f64 / t_in as f64
                        } else {
                            0.0
                        };
                        let bucket = match t_in {
                            0..=500 => "0-500",
                            501..=2000 => "500-2k",
                            2001..=10000 => "2k-10k",
                            _ => "10k+",
                        };
                        entries.push(serde_json::json!({
                            "file_ext": format!(".{ext}"),
                            "size_bucket": bucket,
                            "best_mode": mode,
                            "compression_ratio": (ratio * 100.0).round() / 100.0,
                        }));
                        if entries.len() >= 200 {
                            return entries;
                        }
                    }
                }
            }
        }
    }

    if entries.is_empty() {
        let stats_data = crate::core::stats::format_gain_json();
        if let Ok(parsed) = serde_json::from_str::<serde_json::Value>(&stats_data) {
            let original = parsed["cep"]["total_tokens_original"].as_u64().unwrap_or(0);
            let compressed = parsed["cep"]["total_tokens_compressed"]
                .as_u64()
                .unwrap_or(0);
            let ratio = if original > 0 {
                1.0 - compressed as f64 / original as f64
            } else {
                0.0
            };
            if let Some(modes) = parsed["cep"]["modes"].as_object() {
                let read_modes = [
                    "full",
                    "map",
                    "signatures",
                    "auto",
                    "aggressive",
                    "entropy",
                    "diff",
                    "lines",
                    "task",
                    "reference",
                ];
                for (mode, count) in modes {
                    if !read_modes.contains(&mode.as_str()) || count.as_u64().unwrap_or(0) == 0 {
                        continue;
                    }
                    entries.push(serde_json::json!({
                        "file_ext": "mixed",
                        "size_bucket": "mixed",
                        "best_mode": mode,
                        "compression_ratio": (ratio * 100.0).round() / 100.0,
                    }));
                }
            }
        }
    }

    entries
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn auto_sync_requires_flag_login_and_unused_slot() {
        // Disabled flag blocks everything else.
        assert!(!should_auto_sync(false, true, None, "2026-06-10"));
        // Logged out never syncs.
        assert!(!should_auto_sync(true, false, None, "2026-06-10"));
        // Fresh slot + flag + login → go.
        assert!(should_auto_sync(true, true, None, "2026-06-10"));
        // Already synced today → debounced.
        assert!(!should_auto_sync(
            true,
            true,
            Some("2026-06-10"),
            "2026-06-10"
        ));
        // Synced yesterday → today's slot is free.
        assert!(should_auto_sync(
            true,
            true,
            Some("2026-06-09"),
            "2026-06-10"
        ));
    }

    #[test]
    fn auto_index_push_needs_flag_login_index_and_fresh_slot() {
        let t = "2026-06-10";
        // All preconditions met → push.
        assert!(should_auto_push_index(true, true, true, None, t));
        // Separate opt-in: auto_sync users are NOT auto-enrolled.
        assert!(!should_auto_push_index(false, true, true, None, t));
        // Logged out / no local index → silently skip, no error path.
        assert!(!should_auto_push_index(true, false, true, None, t));
        assert!(!should_auto_push_index(true, true, false, None, t));
        // Per-project debounce: today consumed, yesterday frees the slot.
        assert!(!should_auto_push_index(true, true, true, Some(t), t));
        assert!(should_auto_push_index(
            true,
            true,
            true,
            Some("2026-06-09"),
            t
        ));
    }

    #[test]
    fn outcome_classification_is_gate_then_network_then_synced() {
        // Nothing to push counts as synced (slot consumed, no retry storm).
        assert_eq!(classify_outcomes(&[]), AutoSyncOutcome::Synced);
        // Any 402 means the account is gated, even with other failures.
        assert_eq!(
            classify_outcomes(&[
                Err("HTTP 402: upgrade required".into()),
                Err("connection refused".into()),
            ]),
            AutoSyncOutcome::Gated
        );
        // All failed without a 402 → offline, keep the slot open.
        assert_eq!(
            classify_outcomes(&[Err("connection refused".into()), Err("timeout".into()),]),
            AutoSyncOutcome::NetworkFailure
        );
        // Partial success is success.
        assert_eq!(
            classify_outcomes(&[Ok(()), Err("timeout".into())]),
            AutoSyncOutcome::Synced
        );
    }
}