eidetic-engine 0.16.0

Durable, local-first, explainable memory for coding agents.
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
/// The public importer must reconcile an existing transcript even when
/// CASS discovery metadata is unchanged and the initial index job finished.
#[cfg(unix)]
#[test]
fn reimport_backfills_existing_transcripts_and_reconciles_snapshot_jobs() -> TestResult {
    for (initially_include_spans, migrated_history) in [(false, false), (true, false), (true, true)]
    {
        let root = unique_test_dir("cass-public-backfill")?;
        let bin_dir = root.join("bin");
        let workspace = root.join("workspace");
        let source = root.join("session.jsonl");
        fs::create_dir_all(&bin_dir).map_err(|e| e.to_string())?;
        fs::create_dir_all(&workspace).map_err(|e| e.to_string())?;
        fs::write(&source, "{}\n").map_err(|e| e.to_string())?;
        let binary = bin_dir.join("cass");
        write_fake_cass_binary_with_view_lines(&binary, &workspace, &source, 1)?;
        let database = root.join("ee.db");
        let client = CassClient::with_binary(binary.clone()).with_timeout(Duration::from_secs(5));
        let mut options = CassImportOptions {
            workspace_path: workspace.clone(),
            database_path: Some(database.clone()),
            limit: 1,
            since: None,
            dry_run: false,
            include_spans: initially_include_spans,
        };
        let first = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
        ensure_equal(&first.sessions_imported, &1, "one initial session")?;
        let first_spans = if initially_include_spans { 1_u32 } else { 0 };
        ensure_equal(
            &first.spans_imported,
            &first_spans,
            "initial transcript count",
        )?;
        let id = first.sessions[0]
            .session_id
            .clone()
            .ok_or_else(|| "initial session ID missing".to_owned())?;
        let old_job = first.sessions[0]
            .index_job_id
            .clone()
            .ok_or_else(|| "initial index job missing".to_owned())?;
        let db = DbConnection::open_file(&database).map_err(|e| e.to_string())?;
        let old_session = db
            .get_session(&id)
            .map_err(|e| e.to_string())?
            .ok_or_else(|| "initial session not durable".to_owned())?;
        if migrated_history {
            // Reproduce an evolved store, not just a pristine current import.
            // Retaining a raw locator must never re-admit this denied evidence.
            let reference = format!("{}:1", source.to_string_lossy()).replace('\'', "''");
            db.execute_raw(&format!(
                "UPDATE evidence_spans SET producer_kind = 'legacy_unknown', cass_span_id = '{reference}', search_eligibility = 'denied', pack_eligibility = 'denied'"
            ))
            .map_err(|e| e.to_string())?;
        }
        let old_spans = db
            .list_evidence_spans_for_session(&id)
            .map_err(|e| e.to_string())?;
        db.execute_raw("UPDATE search_index_jobs SET status = 'completed'")
            .map_err(|e| e.to_string())?;

        // The fixture deliberately keeps discovery's message_count and
        // modified values unchanged. Only the complete view reveals growth.
        write_fake_cass_binary_with_view_lines(&binary, &workspace, &source, 4)?;
        options.include_spans = true;
        let grown = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
        ensure_equal(&grown.sessions_imported, &1, "one session backfilled")?;
        ensure_equal(&grown.sessions_skipped, &0, "backfill is not a skip")?;
        ensure_equal(
            &grown.spans_imported,
            &(4 - first_spans),
            "only missing spans counted",
        )?;
        ensure_equal(&grown.index_jobs_queued, &1, "new snapshot must publish")?;
        ensure_equal(
            &grown.sessions[0].session_id.as_ref(),
            &Some(&id),
            "stable session ID",
        )?;
        let new_job = grown.sessions[0]
            .index_job_id
            .clone()
            .ok_or_else(|| "backfill publication job missing".to_owned())?;
        ensure(
            new_job != old_job,
            "completed job cannot attest a newer transcript",
        )?;
        ensure_equal(
            &db.count_table_rows("sessions").map_err(|e| e.to_string())?,
            &1,
            "no duplicate session",
        )?;
        ensure_equal(
            &db.list_evidence_spans_for_session(&id)
                .map_err(|e| e.to_string())?
                .len(),
            &4,
            "complete transcript",
        )?;
        let refreshed_session = db
            .get_session(&id)
            .map_err(|e| e.to_string())?
            .ok_or_else(|| "refreshed session not durable".to_owned())?;
        let mut metadata: JsonValue = serde_json::from_str(
            refreshed_session
                .metadata_json
                .as_deref()
                .ok_or_else(|| "refresh checkpoint metadata missing".to_owned())?,
        )
        .map_err(|e| e.to_string())?;
        let checkpoint = metadata
            .as_object_mut()
            .and_then(|object| object.remove("eeCassImportCheckpoint"))
            .ok_or_else(|| "refresh must persist its publication checkpoint".to_owned())?;
        ensure_equal(
            &checkpoint["schema"],
            &json!("ee.cass.session_checkpoint.v1"),
            "checkpoint schema",
        )?;
        ensure_equal(
            &checkpoint["indexJobId"],
            &json!(new_job),
            "current snapshot job",
        )?;
        ensure_equal(
            &checkpoint["previousIndexJobId"],
            &json!(old_job),
            "checkpoint predecessor",
        )?;
        ensure(
            checkpoint["snapshotRevision"]
                .as_str()
                .and_then(|revision| revision.strip_prefix("blake3:"))
                .is_some_and(|hash| {
                    hash.len() == 64
                        && hash
                            .bytes()
                            .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))
                }),
            "checkpoint must attest a canonical transcript revision",
        )?;
        let original_metadata: JsonValue =
            serde_json::from_str(old_session.metadata_json.as_deref().unwrap_or("{}"))
                .map_err(|e| e.to_string())?;
        ensure_equal(
            &metadata,
            &original_metadata,
            "original metadata remains exact",
        )?;
        let mut expected_session = old_session;
        expected_session.metadata_json = refreshed_session.metadata_json.clone();
        ensure_equal(
            &refreshed_session,
            &expected_session,
            "only the validated publication checkpoint may change",
        )?;
        for span in old_spans {
            if migrated_history {
                ensure(
                    db.get_search_admitted_evidence_span(&span.id, &span.workspace_id)
                        .map_err(|e| e.to_string())?
                        .is_none(),
                    "recognizing legacy history cannot restore its search authority",
                )?;
            }
            ensure_equal(
                &db.get_evidence_span(&span.id).map_err(|e| e.to_string())?,
                &Some(span),
                "retained evidence remains exact",
            )?;
        }
        for line in (first_spans + 1)..=4 {
            let reference = format!("{}:{line}", source.to_string_lossy());
            let evidence_id = stable_evidence_id(&id, &reference);
            ensure(
                db.get_search_admitted_evidence_span(&evidence_id, &refreshed_session.workspace_id)
                    .map_err(|e| e.to_string())?
                    .is_some(),
                "newly imported evidence must be search-admitted through the normal boundary",
            )?;
        }

        let durable_counts = || {
            [
                "sessions",
                "evidence_spans",
                "search_index_jobs",
                "audit_log",
            ]
            .into_iter()
            .map(|table| db.count_table_rows(table).map_err(|e| e.to_string()))
            .collect::<Result<Vec<_>, String>>()
        };
        let before_retry = durable_counts()?;
        for status in ["pending", "failed", "cancelled", "running"] {
            db.execute_raw(&format!(
                "UPDATE search_index_jobs SET status = '{status}' WHERE id = '{new_job}'"
            ))
            .map_err(|e| e.to_string())?;
            let retry = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
            ensure_equal(
                &retry.sessions_imported,
                &0,
                "unchanged retry does not import",
            )?;
            ensure_equal(&retry.sessions_skipped, &1, "unchanged retry skips")?;
            ensure_equal(&retry.spans_imported, &0, "no repeated span accounting")?;
            ensure_equal(
                &retry.index_jobs_queued,
                &1,
                "unfinished publication remains visible",
            )?;
            ensure_equal(
                &retry.sessions[0].index_job_id.as_ref(),
                &Some(&new_job),
                "pending snapshot job recovered",
            )?;
            ensure_equal(
                &durable_counts()?,
                &before_retry,
                "retry cannot duplicate durable work",
            )?;
            ensure_equal(
                &db.get_session(&id).map_err(|e| e.to_string())?,
                &Some(refreshed_session.clone()),
                "retry preserves the exact committed checkpoint",
            )?;
        }

        db.execute_raw("UPDATE search_index_jobs SET status = 'completed'")
            .map_err(|e| e.to_string())?;
        let published = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
        ensure_equal(
            &published.index_jobs_queued,
            &0,
            "completed snapshot needs no new job",
        )?;
        ensure_equal(
            &published.spans_imported,
            &0,
            "completed snapshot is idempotent",
        )?;

        write_fake_cass_binary_with_view_lines(&binary, &workspace, &source, 2)?;
        let before_refusal = durable_counts()?;
        ensure(
            import_cass_sessions(&client, &options).is_err(),
            "shortened history must fail closed",
        )?;
        ensure_equal(
            &durable_counts()?,
            &before_refusal,
            "refused refresh cannot partially mutate evidence",
        )?;
        options.include_spans = false;
        let metadata_only = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
        ensure_equal(
            &metadata_only.spans_imported,
            &0,
            "metadata-only import never reads a changed view",
        )?;
        options.include_spans = true;
        options.dry_run = true;
        let dry_run = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
        ensure(dry_run.dry_run, "dry run stays non-mutating")?;
        ensure_equal(
            &durable_counts()?,
            &before_refusal,
            "dry run and metadata-only preserve evidence",
        )?;
        db.close().map_err(|e| e.to_string())?;
    }
    Ok(())
}

/// Capture and publication recovery are independent: declining another CASS
/// view cannot erase work already recorded by a newer transcript checkpoint.
#[cfg(unix)]
#[test]
fn metadata_only_reimport_recovers_latest_publication_without_reading_transcript() -> TestResult {
    let root = unique_test_dir("cass-metadata-publication")?;
    let bin_dir = root.join("bin");
    let workspace = root.join("workspace");
    let source = root.join("session.jsonl");
    fs::create_dir_all(&bin_dir).map_err(|e| e.to_string())?;
    fs::create_dir_all(&workspace).map_err(|e| e.to_string())?;
    fs::write(&source, "{}\n").map_err(|e| e.to_string())?;
    let binary = bin_dir.join("cass");
    write_fake_cass_binary_with_view_lines(&binary, &workspace, &source, 1)?;
    let database = root.join("ee.db");
    let client = CassClient::with_binary(binary.clone()).with_timeout(Duration::from_secs(5));
    let mut options = CassImportOptions {
        workspace_path: workspace.clone(),
        database_path: Some(database.clone()),
        limit: 1,
        since: None,
        dry_run: false,
        include_spans: true,
    };
    let first = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
    let id = first.sessions[0]
        .session_id
        .clone()
        .ok_or_else(|| "initial session missing".to_owned())?;
    let original = first.sessions[0]
        .index_job_id
        .clone()
        .ok_or_else(|| "initial publication missing".to_owned())?;
    let db = DbConnection::open_file(&database).map_err(|e| e.to_string())?;
    db.execute_raw("UPDATE search_index_jobs SET status = 'completed'")
        .map_err(|e| e.to_string())?;
    write_fake_cass_binary_with_view_lines(&binary, &workspace, &source, 4)?;
    let grown = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
    let latest = grown.sessions[0]
        .index_job_id
        .clone()
        .ok_or_else(|| "refreshed publication missing".to_owned())?;
    ensure(
        latest != original,
        "growth requires a new publication identity",
    )?;
    let stored = db.get_session(&id).map_err(|e| e.to_string())?;
    let evidence = db
        .list_evidence_spans_for_session(&id)
        .map_err(|e| e.to_string())?;
    ensure_equal(&evidence.len(), &4, "growth was committed")?;
    let counts = || {
        [
            "sessions",
            "evidence_spans",
            "search_index_jobs",
            "audit_log",
        ]
        .into_iter()
        .map(|table| db.count_table_rows(table).map_err(|e| e.to_string()))
        .collect::<Result<Vec<_>, String>>()
    };
    let before = counts()?;
    // This output cannot be imported. A successful metadata-only retry thus
    // proves that publication recovery did not secretly fetch the transcript.
    write_fake_cass_binary_with_verbatim_view(
        &binary,
        &workspace,
        &source,
        "not JSON PRIVATE_RAW_SENTINEL\n",
    )?;
    options.include_spans = false;
    for status in ["pending", "failed", "cancelled", "running"] {
        db.execute_raw(&format!(
            "UPDATE search_index_jobs SET status = '{status}' WHERE id = '{latest}'"
        ))
        .map_err(|e| e.to_string())?;
        let retry = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
        ensure_equal(
            &retry.sessions_imported,
            &0,
            "recovery must not recapture evidence",
        )?;
        ensure_equal(
            &retry.spans_imported,
            &0,
            "metadata-only means no new spans",
        )?;
        ensure_equal(
            &retry.index_jobs_queued,
            &1,
            "latest unfinished work stays visible",
        )?;
        ensure_equal(
            &retry.sessions[0].index_job_id.as_ref(),
            &Some(&latest),
            "recover current checkpoint, not original job",
        )?;
        ensure_equal(&counts()?, &before, "retry does not duplicate durable work")?;
        ensure_equal(
            &db.get_session(&id).map_err(|e| e.to_string())?,
            &stored,
            "checkpoint stays exact",
        )?;
        ensure_equal(
            &db.list_evidence_spans_for_session(&id)
                .map_err(|e| e.to_string())?,
            &evidence,
            "history stays exact",
        )?;
        let job = db
            .get_search_index_job(&latest)
            .map_err(|e| e.to_string())?
            .ok_or_else(|| "latest job disappeared".to_owned())?;
        ensure_equal(
            &job.status.as_str(),
            &status,
            "recovery never steals a live publisher",
        )?;
    }
    db.execute_raw(&format!(
        "UPDATE search_index_jobs SET status = 'completed' WHERE id = '{latest}'"
    ))
    .map_err(|e| e.to_string())?;
    let published = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
    ensure_equal(
        &published.index_jobs_queued,
        &0,
        "completed latest snapshot needs no work",
    )?;
    // Loss of rebuildable queue state must not force another upstream read.
    db.execute_raw(&format!(
        "DELETE FROM search_index_jobs WHERE id = '{latest}'"
    ))
    .map_err(|e| e.to_string())?;
    let recovered = import_cass_sessions(&client, &options).map_err(|e| e.to_string())?;
    ensure_equal(
        &recovered.sessions[0].index_job_id.as_ref(),
        &Some(&latest),
        "recreate the exact checkpoint job",
    )?;
    ensure_equal(
        &counts()?,
        &before,
        "only the missing queue row is recreated",
    )?;
    ensure_equal(
        &db.get_session(&id).map_err(|e| e.to_string())?,
        &stored,
        "recovery preserves the checkpoint",
    )?;
    ensure_equal(
        &db.list_evidence_spans_for_session(&id)
            .map_err(|e| e.to_string())?,
        &evidence,
        "recovery preserves evidence",
    )?;
    // Negative control: actually asking to capture the invalid view must fail.
    options.include_spans = true;
    ensure(
        import_cass_sessions(&client, &options).is_err(),
        "the transcript fixture is genuinely invalid",
    )?;
    ensure_equal(
        &counts()?,
        &before,
        "failed capture cannot undo publication recovery",
    )?;
    db.close().map_err(|e| e.to_string())?;
    Ok(())
}

/// A recent source modification must reach the live refresh path even when
/// both the original start and the retained end predate the --since window.
#[cfg(unix)]
#[test]
fn since_reimport_captures_resumed_session_growth_and_retains_end_provenance() -> TestResult {
    let root = unique_test_dir("cass-since-resumed")?;
    let bin_dir = root.join("bin");
    let workspace = root.join("workspace");
    let source = root.join("session.jsonl");
    fs::create_dir_all(&bin_dir).map_err(|error| error.to_string())?;
    fs::create_dir_all(&workspace).map_err(|error| error.to_string())?;
    fs::write(&source, "{}\n").map_err(|error| error.to_string())?;
    let binary = bin_dir.join("cass");
    let database = root.join("ee.db");
    let write_snapshot = |modified: &str, count: u32| -> TestResult {
        let sessions = json!({"sessions": [{
            "path": source.to_string_lossy(),
            "workspace": workspace.to_string_lossy(),
            "agent": "codex",
            "started_at": "2026-09-01T00:00:00Z",
            "ended_at": "2026-09-02T00:00:00Z",
            "modified": modified,
            "message_count": count
        }]});
        let lines: Vec<_> = (1..=count)
            .map(|line| json!({"line": line, "content": format!("Resumed build observation {line}.")}))
            .collect();
        let view = json!({
            "path": source.to_string_lossy(),
            "target_line": 1,
            "context": DEFAULT_VIEW_CONTEXT,
            "lines": lines,
            "total_lines": count
        });
        let script = format!(
            "#!/bin/sh\ncase \"$1\" in\n  sessions) cat <<'EE_CASS_SESSIONS'\n{sessions}\nEE_CASS_SESSIONS\n;;\n  view) cat <<'EE_CASS_VIEW'\n{view}\nEE_CASS_VIEW\n;;\n  *) exit 2;;\nesac\n"
        );
        fs::write(&binary, script).map_err(|error| error.to_string())?;
        let mut permissions = fs::metadata(&binary)
            .map_err(|error| error.to_string())?
            .permissions();
        permissions.set_mode(0o755);
        fs::set_permissions(&binary, permissions).map_err(|error| error.to_string())
    };
    write_snapshot("2026-09-02T00:00:00Z", 1)?;
    let cutoff = DateTime::parse_from_rfc3339("2026-09-20T00:00:00Z")
        .map_err(|error| error.to_string())?
        .with_timezone(&Utc);
    let client = CassClient::with_binary(binary.clone()).with_timeout(Duration::from_secs(5));
    let mut options = CassImportOptions {
        workspace_path: workspace.clone(),
        database_path: Some(database.clone()),
        limit: 1,
        since: Some(cutoff),
        dry_run: true,
        include_spans: true,
    };
    let old = import_cass_sessions(&client, &options).map_err(|error| error.to_string())?;
    ensure_equal(&old.sessions_discovered, &0, "old activity is excluded")?;
    ensure(!database.exists(), "dry-run selection creates no database")?;

    options.since = None;
    options.dry_run = false;
    let first = import_cass_sessions(&client, &options).map_err(|error| error.to_string())?;
    let id = first.sessions[0]
        .session_id
        .clone()
        .ok_or_else(|| "initial session missing".to_owned())?;
    let original_job = first.sessions[0]
        .index_job_id
        .clone()
        .ok_or_else(|| "initial job missing".to_owned())?;
    let db = DbConnection::open_file(&database).map_err(|error| error.to_string())?;
    let retained = db
        .list_evidence_spans_for_session(&id)
        .map_err(|error| error.to_string())?;
    db.execute_raw("UPDATE search_index_jobs SET status = 'completed'")
        .map_err(|error| error.to_string())?;

    // Exactly the cutoff instant in another timezone. Start/end stay old, so
    // neither can substitute for the independent modification timestamp.
    write_snapshot("2026-09-19T20:00:00-04:00", 3)?;
    options.since = Some(cutoff);
    let grown = import_cass_sessions(&client, &options).map_err(|error| error.to_string())?;
    ensure_equal(&grown.sessions_imported, &1, "resumed session refreshed")?;
    ensure_equal(
        &grown.spans_imported,
        &2,
        "only newly observed turns imported",
    )?;
    ensure_equal(
        &grown.index_jobs_queued,
        &1,
        "new transcript queues publication",
    )?;
    ensure_equal(
        &grown.sessions[0].session_id.as_ref(),
        &Some(&id),
        "stable session identity",
    )?;
    let latest_job = grown.sessions[0]
        .index_job_id
        .clone()
        .ok_or_else(|| "resumed snapshot job missing".to_owned())?;
    ensure(
        latest_job != original_job,
        "completed original job cannot publish resumed activity",
    )?;
    let stored = db
        .get_session(&id)
        .map_err(|error| error.to_string())?
        .ok_or_else(|| "refreshed session missing".to_owned())?;
    ensure_equal(
        &stored.started_at.as_deref(),
        &Some("2026-09-01T00:00:00Z"),
        "retain start provenance",
    )?;
    ensure_equal(
        &stored.ended_at.as_deref(),
        &Some("2026-09-02T00:00:00Z"),
        "retain explicit end provenance",
    )?;
    for span in retained {
        ensure_equal(
            &db.get_evidence_span(&span.id)
                .map_err(|error| error.to_string())?,
            &Some(span),
            "earlier evidence is unchanged",
        )?;
    }
    for line in 2..=3 {
        let evidence_id = stable_evidence_id(&id, &format!("{}:{line}", source.to_string_lossy()));
        ensure(
            db.get_search_admitted_evidence_span(&evidence_id, &stored.workspace_id)
                .map_err(|error| error.to_string())?
                .is_some(),
            "new activity is searchable under its native evidence identity",
        )?;
    }
    let retry = import_cass_sessions(&client, &options).map_err(|error| error.to_string())?;
    ensure_equal(
        &retry.sessions_imported,
        &0,
        "unchanged recent activity is idempotent",
    )?;
    ensure_equal(
        &retry.spans_imported,
        &0,
        "retry does not duplicate evidence",
    )?;
    ensure_equal(
        &retry.sessions[0].index_job_id.as_ref(),
        &Some(&latest_job),
        "retry retains pending snapshot work",
    )?;
    ensure_equal(
        &db.count_table_rows("sessions")
            .map_err(|error| error.to_string())?,
        &1,
        "one durable session",
    )?;
    ensure_equal(
        &db.list_evidence_spans_for_session(&id)
            .map_err(|error| error.to_string())?
            .len(),
        &3,
        "complete durable transcript",
    )?;
    db.close().map_err(|error| error.to_string())?;
    Ok(())
}