pensieve-server 0.1.0

HTTP + gRPC query API, auth stub, health, observability.
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
use std::sync::Arc;

use serde_json::{json, Value};
use uuid::Uuid;

use super::cc_curate::{
    commit_guard_stamps, plan_curation, CurationConfig, CurationInput, FileAction, GuardStamp,
};
use super::{execute_sql, SharedToolCtx};
use pensieve_core::catalog::Catalog;
use pensieve_core::segment_format::SegmentFormat;
use pensieve_embed::{EmbedError, EmbeddingBackend};
use pensieve_format_tlm::TelemetryFormat;
use pensieve_memory::{CreateMemory, MemoryType, MemoryWriter};
use pensieve_storage::{build_object_store, StorageConfig};

/// Deterministic in-process embedding stub (dim 8) — no model downloads.
#[derive(Debug)]
struct TestEmbed;

#[async_trait::async_trait]
impl EmbeddingBackend for TestEmbed {
    fn id(&self) -> &'static str {
        "test/stub-8"
    }
    fn dimension(&self) -> u16 {
        8
    }
    async fn embed(&self, texts: &[String]) -> Result<Vec<Vec<f32>>, EmbedError> {
        Ok(texts
            .iter()
            .map(|t| {
                let mut v = vec![0.0f32; 8];
                for (i, b) in t.bytes().enumerate() {
                    v[i % 8] += f32::from(b) / 255.0;
                }
                v
            })
            .collect())
    }
}

async fn engine() -> (tempfile::TempDir, MemoryWriter, SharedToolCtx) {
    let tmp = tempfile::tempdir().expect("tmp");
    let sqlite = Arc::new(
        pensieve_catalog_sqlite::SqliteCatalog::connect(
            &tmp.path().join("catalog.db").display().to_string(),
        )
        .await
        .expect("catalog"),
    );
    let catalog: Arc<dyn Catalog> = sqlite;
    let data_root = tmp.path().join("data");
    std::fs::create_dir_all(&data_root).expect("data dir");
    let store = build_object_store(&StorageConfig::Local {
        root: data_root.display().to_string(),
    })
    .expect("store");
    let format: Arc<dyn SegmentFormat> = Arc::new(TelemetryFormat::new(store, "pensieve-test"));
    let writer = MemoryWriter::new(catalog.clone(), format.clone(), Arc::new(TestEmbed));
    let shared = SharedToolCtx {
        realm_scope: Default::default(),
        consumer_sink: None,
        federation: None,
        catalog,
        format,
        pool: None,
        memory: None,
        hitl: None,
        memory_settings_path: None,
    };
    (tmp, writer, shared)
}

#[allow(clippy::too_many_arguments)]
async fn seed(
    writer: &MemoryWriter,
    realm: &str,
    title: &str,
    content: &str,
    mtype: MemoryType,
    importance: f32,
    topic_key: Option<&str>,
    provenance: Option<Value>,
) -> Uuid {
    let mut cm = CreateMemory::new(content);
    cm.title = Some(title.to_string());
    cm.memory_type = mtype;
    cm.realm = realm.to_string();
    cm.importance = importance;
    cm.topic_key = topic_key.map(str::to_string);
    cm.provenance = provenance;
    writer.save(&cm).await.expect("seed")
}

async fn rows(shared: &SharedToolCtx, sql: &str) -> Vec<Value> {
    let res = execute_sql(shared, pensieve_memory::DEFAULT_DATABASE, sql, 10_000).await;
    res.get("rows")
        .and_then(Value::as_array)
        .cloned()
        .unwrap_or_default()
}

const LATEST: &str = "WITH latest AS (SELECT *, row_number() OVER (PARTITION BY id ORDER BY updated_at DESC) AS rn FROM memory_nodes)";

/// Append a new version of a node with `invalid_at` set (bi-temporal
/// invalidation, as the conflict pipeline would do).
async fn invalidate(writer: &MemoryWriter, shared: &SharedToolCtx, id: Uuid) {
    let got = rows(
        &shared.clone(),
        &format!(
            "{LATEST} SELECT id, labels, realm, memory_type, title, content, content_preview, tags, importance, status, source_session_id, source_run_id, embedding, created_at, updated_at, valid_at, invalid_at, superseded_by, provenance, topic_key FROM latest WHERE rn = 1 AND id = 'memory:{id}'"
        ),
    )
    .await;
    let mut row = got.first().cloned().expect("node row");
    let now = chrono::Utc::now().to_rfc3339();
    row["invalid_at"] = json!(now);
    row["updated_at"] = json!(now);
    writer
        .append_node_rows(vec![row])
        .await
        .expect("invalidate");
}

fn input(now: &str) -> CurationInput<'_> {
    CurationInput {
        realm: "proj",
        path_slug: "-tmp-proj",
        now,
    }
}

/// Simulate a fully successful apply: commit every guard stamp.
async fn commit_all(
    shared: &SharedToolCtx,
    writer: &MemoryWriter,
    actions: &[FileAction],
    stamps: &[GuardStamp],
    now: &str,
) {
    commit_guard_stamps(shared, writer, stamps, &vec![true; actions.len()], now)
        .await
        .expect("commit stamps");
}

fn writes(actions: &[FileAction]) -> Vec<&FileAction> {
    actions
        .iter()
        .filter(|a| matches!(a, FileAction::WriteMemoryFile { .. }))
        .collect()
}

fn archives(actions: &[FileAction]) -> Vec<&FileAction> {
    actions
        .iter()
        .filter(|a| matches!(a, FileAction::ArchiveFile { .. }))
        .collect()
}

fn index_entries(actions: &[FileAction]) -> Vec<super::cc_curate::IndexEntry> {
    actions
        .iter()
        .find_map(|a| match a {
            FileAction::SetIndex { entries } => Some(entries.clone()),
            _ => None,
        })
        .unwrap_or_default()
}

#[test]
fn parses_curation_decisions_tolerantly() {
    use super::cc_curate::{parse_curation_decision, CurationOp};

    let d = parse_curation_decision(r#"{"op": "ARCHIVE", "reason": "obsolete since the rewrite"}"#);
    assert_eq!(d.op, CurationOp::Archive);
    assert_eq!(d.reason.as_deref(), Some("obsolete since the rewrite"));

    // Fenced + lowercase + refreshed description.
    let d = parse_curation_decision(
        "```json\n{\"op\": \"refresh\", \"refreshed_description\": \"clearer one-liner\"}\n```",
    );
    assert_eq!(d.op, CurationOp::Refresh);
    assert_eq!(
        d.refreshed_description.as_deref(),
        Some("clearer one-liner")
    );

    // Garbage degrades to the safe default: KEEP.
    let d = parse_curation_decision("I think we should probably keep it?");
    assert_eq!(d.op, CurationOp::Keep);
    let d = parse_curation_decision(r#"{"op": "DELETE EVERYTHING"}"#);
    assert_eq!(d.op, CurationOp::Keep);
}

#[test]
fn cosine_similarity_behaves() {
    use super::cc_curate::cosine;
    assert!((cosine(&[1.0, 0.0], &[1.0, 0.0]) - 1.0).abs() < 1e-9);
    assert!(cosine(&[1.0, 0.0], &[0.0, 1.0]).abs() < 1e-9);
    assert!(
        cosine(&[0.0, 0.0], &[1.0, 0.0]).abs() < 1e-12,
        "zero vector is not NaN"
    );
}

#[test]
fn staleness_respects_age_and_review_stamps() {
    use super::cc_curate::is_stale;
    let now = "2026-06-05T00:00:00+00:00";
    let old = "2026-01-01T00:00:00+00:00"; // ~155 days
    let fresh = "2026-06-01T00:00:00+00:00";
    assert!(is_stale(old, None, now, 90));
    assert!(!is_stale(fresh, None, now, 90));
    assert!(
        !is_stale(old, Some(fresh), now, 90),
        "recently reviewed → not re-questioned"
    );
    assert!(
        is_stale(old, Some(old), now, 90),
        "stale review re-questions"
    );
}

#[tokio::test]
async fn llm_pass_without_engine_is_a_clean_noop() {
    use super::cc_curate::{llm_curation_pass, LlmCurationConfig};
    let (_tmp, writer, shared) = engine().await;
    seed(
        &writer,
        "proj",
        "Old note",
        "Quite old.",
        MemoryType::Fact,
        0.7,
        Some("claude-md:-tmp-proj/old-note"),
        Some(json!({"source": "claude-code-file", "cc_file": "old-note.md"})),
    )
    .await;

    let now = chrono::Utc::now().to_rfc3339();
    let mut actions = Vec::new();
    let mut stamps = Vec::new();
    let mut outcome = super::cc_curate::CurationOutcome::default();
    llm_curation_pass(
        &shared,
        &writer,
        None,
        &input(&now),
        &LlmCurationConfig::default(),
        &mut actions,
        &mut stamps,
        &mut outcome,
    )
    .await
    .expect("noop");
    assert!(actions.is_empty());
    assert!(stamps.is_empty());
    assert_eq!(outcome.llm_reviewed, 0);
}

#[tokio::test]
async fn promotes_top_memories_capped_ordered_and_idempotent() {
    let (_tmp, writer, shared) = engine().await;
    let id_decision = seed(
        &writer,
        "proj",
        "Auth Model Decision",
        "We chose session tokens over JWTs because of revocation.",
        MemoryType::Decision,
        0.9,
        None,
        None,
    )
    .await;
    seed(
        &writer,
        "proj",
        "Prefer Nextest",
        "Always run tests with cargo nextest.",
        MemoryType::Preference,
        0.7,
        None,
        None,
    )
    .await;
    seed(
        &writer,
        "proj",
        "Low signal",
        "Probably noise.",
        MemoryType::Fact,
        0.3,
        None,
        None,
    )
    .await;
    seed(
        &writer,
        "proj",
        "Session summary",
        "Did some work.",
        MemoryType::Summary,
        0.95,
        None,
        None,
    )
    .await;

    let now = chrono::Utc::now().to_rfc3339();
    let cfg = CurationConfig {
        promote_max: 2,
        ..CurationConfig::default()
    };
    let (actions, stamps, outcome) = plan_curation(&shared, &writer, &input(&now), &cfg)
        .await
        .expect("plan");

    let w = writes(&actions);
    assert_eq!(w.len(), 2, "cap 2: decision + preference, no summary/low");
    assert_eq!(outcome.promoted, 2);

    let FileAction::WriteMemoryFile {
        file,
        content,
        node_id,
        content_hash,
    } = w[0]
    else {
        unreachable!()
    };
    assert_eq!(file, "pensieve-auth-model-decision.md");
    assert_eq!(node_id, &format!("memory:{id_decision}"));
    let parsed = pensieve_ccmem::frontmatter::parse(content).expect("rendered file parses");
    assert!(parsed.is_pensieve_authored());
    assert_eq!(
        parsed.front.name.as_deref(),
        Some("pensieve-auth-model-decision")
    );
    assert_eq!(parsed.front.cc_type.as_deref(), Some("project")); // decision → project
    assert_eq!(
        parsed.front.pensieve_memory_id.as_deref(),
        Some(node_id.as_str())
    );
    assert_eq!(
        parsed.front.content_hash.as_deref(),
        Some(content_hash.as_str())
    );
    assert!(parsed.body.contains("session tokens over JWTs"));
    // The stamped hash matches a recompute over the rendered file.
    let recomputed = pensieve_ccmem::hash::content_hash(
        parsed.front.name.as_deref().unwrap_or_default(),
        parsed.front.cc_type.as_deref(),
        &parsed.body,
    );
    assert_eq!(&recomputed, content_hash);

    let idx = index_entries(&actions);
    assert_eq!(idx.len(), 2);
    assert_eq!(idx[0].file, "pensieve-auth-model-decision.md", "score order");
    assert_eq!(idx[1].file, "pensieve-prefer-nextest.md");
    assert_eq!(outcome.index_entries, 2);

    // Apply succeeds → stamps commit; second pass: no rewrites, no churn.
    commit_all(&shared, &writer, &actions, &stamps, &now).await;
    let now2 = chrono::Utc::now().to_rfc3339();
    let (actions2, _, outcome2) = plan_curation(&shared, &writer, &input(&now2), &cfg)
        .await
        .expect("plan 2");
    assert!(writes(&actions2).is_empty(), "idempotent: no rewrites");
    assert_eq!(outcome2.promoted, 0);
    assert_eq!(index_entries(&actions2), idx);
}

#[tokio::test]
async fn dry_run_plans_without_stamping_the_store() {
    let (_tmp, writer, shared) = engine().await;
    seed(
        &writer,
        "proj",
        "Big Decision",
        "We chose X.",
        MemoryType::Decision,
        0.9,
        None,
        None,
    )
    .await;

    let now = chrono::Utc::now().to_rfc3339();
    let cfg = CurationConfig {
        dry_run: true,
        ..CurationConfig::default()
    };
    let (actions, _stamps, _) = plan_curation(&shared, &writer, &input(&now), &cfg)
        .await
        .expect("plan");
    assert_eq!(writes(&actions).len(), 1);

    // A second dry-run plan must emit the same writes — nothing was stamped.
    let now2 = chrono::Utc::now().to_rfc3339();
    let (actions2, _, _) = plan_curation(&shared, &writer, &input(&now2), &cfg)
        .await
        .expect("plan 2");
    assert_eq!(
        writes(&actions2).len(),
        1,
        "dry run must not persist promotion stamps"
    );
}

#[tokio::test]
async fn excludes_file_born_and_user_owned_from_promotion() {
    let (_tmp, writer, shared) = engine().await;
    // File-born memory (came from a Claude Code file) — never promoted back.
    seed(
        &writer,
        "proj",
        "From a file",
        "Born as a memory file.",
        MemoryType::Fact,
        0.9,
        Some("claude-md:-tmp-proj/from-a-file"),
        Some(json!({"source": "claude-code-file", "cc_file": "from-a-file.md"})),
    )
    .await;
    // Previously promoted, then user-edited → user-owned: indexed, never rewritten.
    seed(
        &writer,
        "proj",
        "User Owned Note",
        "The user edited this promoted file.",
        MemoryType::Decision,
        0.9,
        Some("promo/user-owned"),
        Some(json!({
            "cc_user_owned": true,
            "cc_promoted_file": "pensieve-user-owned-note.md",
            "cc_content_hash": "stale",
        })),
    )
    .await;

    let now = chrono::Utc::now().to_rfc3339();
    let (actions, _stamps, _) =
        plan_curation(&shared, &writer, &input(&now), &CurationConfig::default())
            .await
            .expect("plan");

    assert!(
        writes(&actions).is_empty(),
        "file-born and user-owned must not be (re)written"
    );
    let idx = index_entries(&actions);
    assert_eq!(idx.len(), 1, "user-owned file keeps its index entry");
    assert_eq!(idx[0].file, "pensieve-user-owned-note.md");
}

#[tokio::test]
async fn superseded_file_born_archives_its_file_once() {
    let (_tmp, writer, shared) = engine().await;
    let id = seed(
        &writer,
        "proj",
        "Old note",
        "This was true once.",
        MemoryType::Fact,
        0.7,
        Some("claude-md:-tmp-proj/old-note"),
        Some(json!({"source": "claude-code-file", "cc_file": "old-note.md"})),
    )
    .await;
    invalidate(&writer, &shared, id).await;

    // A node archived because its file was deleted must NOT round-trip back
    // into an archive action.
    seed(
        &writer,
        "proj",
        "Deleted on disk",
        "Gone already.",
        MemoryType::Fact,
        0.7,
        Some("claude-md:-tmp-proj/deleted-on-disk"),
        Some(json!({
            "source": "claude-code-file",
            "cc_file": "deleted-on-disk.md",
            "cc_archived_reason": "file_deleted",
        })),
    )
    .await;

    let now = chrono::Utc::now().to_rfc3339();
    let cfg = CurationConfig::default();
    let (actions, stamps, outcome) = plan_curation(&shared, &writer, &input(&now), &cfg)
        .await
        .expect("plan");
    let arch = archives(&actions);
    assert_eq!(arch.len(), 1);
    let FileAction::ArchiveFile { file, .. } = arch[0] else {
        unreachable!()
    };
    assert_eq!(file, "old-note.md");
    assert_eq!(outcome.archived_files, 1);

    // Once the archive lands (stamps commit), the next pass is quiet.
    commit_all(&shared, &writer, &actions, &stamps, &now).await;
    let now2 = chrono::Utc::now().to_rfc3339();
    let (actions2, _, _) = plan_curation(&shared, &writer, &input(&now2), &cfg)
        .await
        .expect("plan 2");
    assert!(
        archives(&actions2).is_empty(),
        "archive emitted exactly once"
    );
}

#[tokio::test]
async fn exact_duplicate_file_born_memories_merge() {
    let (_tmp, writer, shared) = engine().await;
    let keep = seed(
        &writer,
        "proj",
        "Build tip",
        "Use cargo nextest for the suite.",
        MemoryType::Fact,
        0.8,
        Some("claude-md:-tmp-proj/build-tip"),
        Some(json!({"source": "claude-code-file", "cc_file": "build-tip.md"})),
    )
    .await;
    let lose = seed(
        &writer,
        "proj",
        "Build tip again",
        "Use cargo nextest for the suite.",
        MemoryType::Fact,
        0.6,
        Some("claude-md:-tmp-proj/build-tip-again"),
        Some(json!({"source": "claude-code-file", "cc_file": "build-tip-again.md"})),
    )
    .await;

    let now = chrono::Utc::now().to_rfc3339();
    let (actions, _stamps, outcome) =
        plan_curation(&shared, &writer, &input(&now), &CurationConfig::default())
            .await
            .expect("plan");

    let arch = archives(&actions);
    assert_eq!(arch.len(), 1);
    let FileAction::ArchiveFile { file, reason, .. } = arch[0] else {
        unreachable!()
    };
    assert_eq!(file, "build-tip-again.md", "lower importance loses");
    assert!(reason.contains("duplicate"));
    assert_eq!(outcome.merged, 1);

    // DB mirrored in the same pass: loser archived + superseded_by + edge.
    let got = rows(
        &shared,
        &format!("{LATEST} SELECT status, superseded_by FROM latest WHERE rn = 1 AND id = 'memory:{lose}'"),
    )
    .await;
    assert_eq!(got[0]["status"], "archived");
    assert_eq!(got[0]["superseded_by"], format!("memory:{keep}"));
    let edges = rows(
        &shared,
        &format!("SELECT DISTINCT id FROM memory_edges WHERE type = 'MERGED_INTO' AND src = 'memory:{lose}' AND dst = 'memory:{keep}'"),
    )
    .await;
    assert_eq!(edges.len(), 1);
}

#[tokio::test]
async fn demoted_promotion_is_archived_and_unstamped() {
    let (_tmp, writer, shared) = engine().await;
    // Stamped as promoted earlier, but importance has since dropped far
    // below the floor (0.6 × 0.8 = 0.48 threshold).
    seed(
        &writer,
        "proj",
        "Faded Note",
        "Used to matter.",
        MemoryType::Decision,
        0.3,
        Some("promo/faded"),
        Some(json!({
            "cc_promoted_file": "pensieve-faded-note.md",
            "cc_content_hash": "whatever",
        })),
    )
    .await;

    let now = chrono::Utc::now().to_rfc3339();
    let cfg = CurationConfig::default();
    let (actions, stamps, _) = plan_curation(&shared, &writer, &input(&now), &cfg)
        .await
        .expect("plan");
    let arch = archives(&actions);
    assert_eq!(arch.len(), 1);
    let FileAction::ArchiveFile { file, reason, .. } = arch[0] else {
        unreachable!()
    };
    assert_eq!(file, "pensieve-faded-note.md");
    assert!(reason.contains("demoted"));
    assert!(index_entries(&actions).is_empty());

    // Once the archive lands (stamps commit, clearing the promotion stamp),
    // the next pass is quiet.
    commit_all(&shared, &writer, &actions, &stamps, &now).await;
    let now2 = chrono::Utc::now().to_rfc3339();
    let (actions2, _, _) = plan_curation(&shared, &writer, &input(&now2), &cfg)
        .await
        .expect("plan 2");
    assert!(archives(&actions2).is_empty());
}

#[test]
fn synthesize_title_prefers_first_sentence() {
    let t = super::cc_curate::synthesize_title(
        "We chose session tokens over JWTs because of revocation. Some more detail follows.",
    );
    assert_eq!(t, "We chose session tokens over JWTs because of revocation");
}

#[test]
fn synthesize_title_clips_long_single_sentence_at_word_boundary() {
    let content = "This is a very long single sentence with no punctuation to stop at \
        so it just keeps going and going and going without ever ending at all";
    let t = super::cc_curate::synthesize_title(content);
    assert!(t.chars().count() <= 72, "clipped to the length cap: {t:?}");
    assert!(t.ends_with(''), "marks that it was clipped: {t:?}");
    assert!(!t.contains("  "), "no doubled whitespace from the clip: {t:?}");
    // Clipped at a word boundary, not mid-word.
    assert!(content.starts_with(t.trim_end_matches('').trim_end()));
}

#[test]
fn synthesize_title_falls_back_on_empty_content() {
    assert_eq!(super::cc_curate::synthesize_title("   "), "Untitled memory");
}

/// Regression test for the promoted-memory quality bug: a memory saved
/// without a `title` (exactly what `save_memory`/extraction used to produce
/// before this fix) used to promote with a mangled title — the raw first six
/// words of `content`, reused verbatim as *both* the link label and the
/// frontmatter description, with no regard for word or sentence boundaries.
#[tokio::test]
async fn promotion_synthesizes_a_clean_title_when_none_was_saved() {
    let (_tmp, writer, shared) = engine().await;
    // Bypass `seed()` (which always sets a title) — this is exactly the
    // shape `CreateMemory::new` produces when a caller omits `title`.
    let content =
        "Decision: build S3 native graph engine, do NOT add an external graph DB.";
    let mut cm = CreateMemory::new(content);
    cm.memory_type = MemoryType::Decision;
    cm.realm = "proj".to_string();
    cm.importance = 0.9;
    writer.save(&cm).await.expect("seed untitled");

    let now = chrono::Utc::now().to_rfc3339();
    let (actions, _stamps, outcome) =
        plan_curation(&shared, &writer, &input(&now), &CurationConfig::default())
            .await
            .expect("plan");
    assert_eq!(outcome.promoted, 1);

    let w = writes(&actions);
    let FileAction::WriteMemoryFile {
        file: _,
        content: file_content,
        ..
    } = w[0]
    else {
        unreachable!()
    };
    let parsed = pensieve_ccmem::frontmatter::parse(file_content).expect("rendered file parses");
    let desc = parsed.front.description.clone().unwrap_or_default();
    let old_buggy: String = content.split_whitespace().take(6).collect::<Vec<_>>().join(" ");

    assert!(!desc.is_empty());
    assert_ne!(desc, old_buggy, "must not reproduce the raw 6-word fallback");
    assert!(
        content.starts_with(desc.trim_end_matches('').trim_end()),
        "synthesized title should be a clean prefix of the content, not a mid-word cut: {desc:?}"
    );
}