meerkat-mobkit 0.8.21

Companion orchestration platform for the Meerkat multi-agent runtime
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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
//! A2 decouple: the BASIC agent-memory surface (recorder `memory` tool +
//! build-time injection + Memory panel store) works on the classic mob path
//! for any member keyed on its meerkat `AgentIdentity`, WITHOUT a roster
//! provider or an `IdentityRuntime`. The identity-first path (roster present)
//! is untouched — its own suites cover it.
#![allow(clippy::expect_used, clippy::unwrap_used, clippy::panic)]

use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::time::Duration;

use axum::body::{Body, to_bytes};
use axum::http::{Request, StatusCode, header};
use meerkat_client::{LlmClient, LlmDoneOutcome, LlmError, LlmEvent, LlmRequest};
use meerkat_core::types::StopReason;
use meerkat_mob::{MobDefinition, SpawnMemberSpec};
use meerkat_mobkit::memory::MemoryAuthor;
use meerkat_mobkit::{
    AgentMemoryConfig, AgentMemoryPerTurnInjection, AgentMemoryProvider, AgentMemorySelection,
    AuthPolicy, BigQueryNaming, ConsolePolicy, MemoryKind, MemoryScope, NewMemoryRecord,
    RuntimeDecisionInputs, RuntimeOpsPolicy, SqliteAgentMemoryStore, TrustedOidcRuntimeConfig,
    UnifiedRuntime, build_runtime_decision_state,
};
use serde_json::{Value, json};
use tower::ServiceExt;

/// Per-test mob id counter: 0.8.23's fail-closed in-proc registration
/// means concurrently running tests must not share a supervisor route.
static NEXT_TEST_MOB_ID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);

/// Per-call mob id: 0.8.23's fail-closed in-proc registration means
/// concurrently running tests must not share a supervisor route.
fn classic_mob_toml() -> String {
    format!(
        r#"
[mob]
id = "classic-memory-mob-{}"

[profiles.worker]
model = "gpt-5.5"
runtime_mode = "autonomous_host"
external_addressable = true

[profiles.worker.tools]
comms = true
"#,
        NEXT_TEST_MOB_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
    )
}

fn test_definition() -> MobDefinition {
    MobDefinition::from_toml(&classic_mob_toml()).expect("parse test mob definition")
}

// A commander-like profile that ALSO enables meerkat's built-in tool
// categories (builtins/mob/mob_tasks) — the incident-pack commander shape.
// Guards that the recorder `memory` external tool still registers when those
// categories are on (they compose, they do not suppress it). Diagnoses the
// live finding that the commander reached for `task_create` (a mob_tasks tool)
// instead of `memory`: that is tool *competition*, not a missing recorder.
/// Per-call mob id: 0.8.23's fail-closed in-proc registration means
/// concurrently running tests must not share a supervisor route.
fn commander_like_mob_toml() -> String {
    format!(
        r#"
[mob]
id = "classic-memory-mob-{}"

[profiles.worker]
model = "gpt-5.5"
runtime_mode = "autonomous_host"
external_addressable = true

[profiles.worker.tools]
builtins = true
comms = true
mob = true
mob_tasks = true
"#,
        NEXT_TEST_MOB_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
    )
}

fn commander_like_definition() -> MobDefinition {
    MobDefinition::from_toml(&commander_like_mob_toml()).expect("parse commander-like definition")
}

/// LLM stub that records every request (tool names + full JSON) so tests can
/// assert on the member's build surface: registered tools and the system
/// instructions the memory customizer injected.
#[derive(Clone, Default)]
struct CaptureClient {
    requests: Arc<std::sync::Mutex<Vec<CapturedRequest>>>,
    notify: Arc<tokio::sync::Notify>,
}

#[derive(Clone)]
struct CapturedRequest {
    tool_names: Vec<String>,
    request_json: String,
}

impl CaptureClient {
    fn captured(&self) -> Vec<CapturedRequest> {
        self.requests.lock().unwrap().clone()
    }

    async fn wait_for_request(&self, minimum: usize) -> Vec<CapturedRequest> {
        tokio::time::timeout(Duration::from_secs(20), async {
            loop {
                let captured = self.captured();
                if captured.len() >= minimum {
                    return captured;
                }
                self.notify.notified().await;
            }
        })
        .await
        .expect("member turn should reach the LLM client")
    }
}

impl LlmClient for CaptureClient {
    fn project_replay_messages(
        &self,
        messages: &[meerkat_core::Message],
    ) -> Result<Vec<meerkat_core::Message>, LlmError> {
        Ok(messages.to_vec())
    }

    fn stream<'a>(
        &'a self,
        request: &'a LlmRequest,
    ) -> Pin<Box<dyn futures::Stream<Item = Result<LlmEvent, LlmError>> + Send + 'a>> {
        let captured = CapturedRequest {
            tool_names: request
                .tools
                .iter()
                .map(|tool| tool.name.to_string())
                .collect(),
            request_json: serde_json::to_string(request).unwrap_or_default(),
        };
        self.requests.lock().unwrap().push(captured);
        self.notify.notify_waiters();
        Box::pin(async_stream::stream! {
            yield Ok(LlmEvent::TextDelta {
                delta: "ok".to_string(),
                meta: None,
            });
            yield Ok(LlmEvent::Done {
                outcome: LlmDoneOutcome::Success {
                    stop_reason: StopReason::EndTurn,
                },
            });
        })
    }

    fn provider(&self) -> meerkat::Provider {
        meerkat::Provider::OpenAI
    }

    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), LlmError>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait,
    {
        Box::pin(async { Ok(()) })
    }
}

async fn seed_identity_record(
    store: &SqliteAgentMemoryStore,
    identity: &str,
    title: &str,
    body: &str,
) {
    store
        .remember_authored(
            &MemoryScope::Identity {
                realm: "default".to_string(),
                identity: identity.to_string(),
            },
            NewMemoryRecord {
                kind: MemoryKind::Fact,
                title: title.to_string(),
                description: title.to_string(),
                body: body.to_string(),
                tags: vec![],
                evidence: vec![],
                verification: None,
            },
            MemoryAuthor::Operator,
        )
        .await
        .expect("seed memory record");
}

async fn build_classic_runtime(
    store: SqliteAgentMemoryStore,
    config: AgentMemoryConfig,
    client: CaptureClient,
) -> UnifiedRuntime {
    Box::pin(
        UnifiedRuntime::builder()
            .definition(test_definition())
            .agent_memory(Arc::new(store), config)
            .default_llm_client(Arc::new(client))
            .build(),
    )
    .await
    .expect("classic runtime with agent memory and NO roster must build")
}

// ---------------------------------------------------------------------------
// Build succeeds without a roster; no IdentityRuntime is constructed; the
// panel store is auto-wired.
// ---------------------------------------------------------------------------

#[tokio::test(flavor = "multi_thread")]
async fn classic_agent_memory_builds_without_roster_and_without_identity_runtime() {
    let memory_dir = tempfile::tempdir().expect("memory dir");
    let store = SqliteAgentMemoryStore::open(memory_dir.path()).expect("sqlite store");

    let runtime = build_classic_runtime(
        store,
        AgentMemoryConfig::default(),
        CaptureClient::default(),
    )
    .await;

    assert!(
        runtime.identity_runtime().is_none(),
        "classic memory must not construct an IdentityRuntime"
    );
    assert!(
        runtime.identity_first_context().is_none(),
        "classic memory must not construct an identity-first context"
    );
    assert!(
        runtime.memory_panel_store().is_some(),
        "bundled sqlite provider must auto-wire the Memory panel store"
    );
    runtime.mob_handle().stop().await.expect("stop");
}

// ---------------------------------------------------------------------------
// Member builds get the recorder tool + the build-time memory injection.
// ---------------------------------------------------------------------------

#[tokio::test(flavor = "multi_thread")]
async fn classic_member_build_registers_recorder_and_injects_memory() {
    let memory_dir = tempfile::tempdir().expect("memory dir");
    let store = SqliteAgentMemoryStore::open(memory_dir.path()).expect("sqlite store");
    seed_identity_record(
        &store,
        "helper",
        "Deploy window",
        "Deploys are frozen on Fridays.",
    )
    .await;

    let client = CaptureClient::default();
    let runtime = build_classic_runtime(
        store,
        AgentMemoryConfig {
            selection: AgentMemorySelection::Always,
            ..AgentMemoryConfig::default()
        },
        client.clone(),
    )
    .await;

    runtime
        .spawn_many(vec![SpawnMemberSpec::from_wire(
            "worker".to_string(),
            "helper".to_string(),
            None,
            None,
            None,
        )])
        .await
        .expect("spawn member on the classic path");
    meerkat_mobkit::send_message_on_mob(&runtime.mob_handle(), "helper", "hello".to_string())
        .await
        .expect("send message");

    let captured = client.wait_for_request(1).await;
    let first = &captured[0];
    assert!(
        first.tool_names.iter().any(|name| name == "memory"),
        "recorder tool must be registered on the member build: {:?}",
        first.tool_names
    );
    assert!(
        first
            .request_json
            .contains("Deploys are frozen on Fridays."),
        "build-time injection must carry the seeded record body"
    );
    assert!(
        first.request_json.contains("Memory recorder protocol"),
        "recorder protocol instructions must be injected"
    );
    runtime.mob_handle().stop().await.expect("stop");
}

// ---------------------------------------------------------------------------
// Reconcile-spawned members ALSO get the recorder tool. The incident-command
// pack (and every roster-less console example) populates its roster via
// `reconcile`, not `spawn_many`; this guards that the customizer fires on the
// reconcile spawn path too (regression: the panel stayed empty because the
// memory tool never reached reconcile-spawned members).
// ---------------------------------------------------------------------------

#[tokio::test(flavor = "multi_thread")]
async fn classic_reconcile_spawned_member_registers_recorder() {
    use meerkat_mob::runtime::reconcile::ReconcileOptions;

    let memory_dir = tempfile::tempdir().expect("memory dir");
    let store = SqliteAgentMemoryStore::open(memory_dir.path()).expect("sqlite store");
    seed_identity_record(
        &store,
        "helper",
        "Deploy window",
        "Deploys are frozen on Fridays.",
    )
    .await;

    let client = CaptureClient::default();
    let runtime = build_classic_runtime(
        store,
        AgentMemoryConfig {
            selection: AgentMemorySelection::Always,
            ..AgentMemoryConfig::default()
        },
        client.clone(),
    )
    .await;

    runtime
        .mob_handle()
        .reconcile(
            vec![SpawnMemberSpec::from_wire(
                "worker".to_string(),
                "helper".to_string(),
                None,
                None,
                None,
            )],
            ReconcileOptions { retire_stale: true },
        )
        .await
        .expect("reconcile roster on the classic path");
    meerkat_mobkit::send_message_on_mob(&runtime.mob_handle(), "helper", "hello".to_string())
        .await
        .expect("send message");

    let captured = client.wait_for_request(1).await;
    let first = &captured[0];
    assert!(
        first.tool_names.iter().any(|name| name == "memory"),
        "recorder tool must be registered on the reconcile-spawned member: {:?}",
        first.tool_names
    );
    assert!(
        first
            .request_json
            .contains("Deploys are frozen on Fridays."),
        "build-time injection must carry the seeded record body on reconcile"
    );
    runtime.mob_handle().stop().await.expect("stop");
}

// ---------------------------------------------------------------------------
// The recorder `memory` tool survives on a member whose profile also enables
// meerkat's built-in tool categories (builtins/mob/mob_tasks) — the incident
// commander shape. Diagnoses the live finding that the commander called
// `task_create` (a mob_tasks tool) when asked to "remember": the recorder is
// present, so that is tool *competition* in the model's selection, not a
// missing/suppressed recorder.
// ---------------------------------------------------------------------------

#[tokio::test(flavor = "multi_thread")]
async fn classic_recorder_survives_alongside_mob_tool_categories() {
    use meerkat_mob::runtime::reconcile::ReconcileOptions;

    let memory_dir = tempfile::tempdir().expect("memory dir");
    let store = SqliteAgentMemoryStore::open(memory_dir.path()).expect("sqlite store");

    let client = CaptureClient::default();
    let runtime = Box::pin(
        UnifiedRuntime::builder()
            .definition(commander_like_definition())
            .agent_memory(Arc::new(store), AgentMemoryConfig::default())
            .default_llm_client(Arc::new(client.clone()))
            .build(),
    )
    .await
    .expect("commander-like classic runtime with agent memory must build");

    runtime
        .mob_handle()
        .reconcile(
            vec![SpawnMemberSpec::from_wire(
                "worker".to_string(),
                "helper".to_string(),
                None,
                None,
                None,
            )],
            ReconcileOptions { retire_stale: true },
        )
        .await
        .expect("reconcile commander-like member");
    meerkat_mobkit::send_message_on_mob(&runtime.mob_handle(), "helper", "hello".to_string())
        .await
        .expect("send message");

    let captured = client.wait_for_request(1).await;
    let first = &captured[0];
    // Both tools are present in the same (large) surface: the recorder is NOT
    // suppressed by the mob categories — the live "commander used task_create
    // to remember" behavior is model mis-selection among the competing tools,
    // not a missing recorder. Guarding both documents that root cause.
    assert!(
        first.tool_names.iter().any(|name| name == "memory"),
        "recorder `memory` tool must register even when builtins/mob/mob_tasks are enabled: {:?}",
        first.tool_names
    );
    assert!(
        first.tool_names.iter().any(|name| name == "task_create"),
        "the mob_tasks `task_create` tool must also be present (it is what the recorder competes \
         with for \"remember\" instructions): {:?}",
        first.tool_names
    );
    runtime.mob_handle().stop().await.expect("stop");
}

// ---------------------------------------------------------------------------
// Per-turn ambient injection is Off/no-op on the classic path: even the
// explicit `budgeted` opt-in must not prepend memory into delivered turns
// (there is no classic send-path hook yet — documented follow-up).
// ---------------------------------------------------------------------------

#[tokio::test(flavor = "multi_thread")]
async fn classic_per_turn_injection_is_a_noop_even_when_budgeted() {
    let memory_dir = tempfile::tempdir().expect("memory dir");
    let store = SqliteAgentMemoryStore::open(memory_dir.path()).expect("sqlite store");
    seed_identity_record(
        &store,
        "helper",
        "Deploy window",
        "Deploys are frozen on Fridays.",
    )
    .await;

    let client = CaptureClient::default();
    let runtime = build_classic_runtime(
        store,
        AgentMemoryConfig {
            per_turn_injection: AgentMemoryPerTurnInjection::Budgeted,
            ..AgentMemoryConfig::default()
        },
        client.clone(),
    )
    .await;

    runtime
        .spawn_many(vec![SpawnMemberSpec::from_wire(
            "worker".to_string(),
            "helper".to_string(),
            None,
            None,
            None,
        )])
        .await
        .expect("spawn member");
    meerkat_mobkit::send_message_on_mob(
        &runtime.mob_handle(),
        "helper",
        "what changed?".to_string(),
    )
    .await
    .expect("send message");

    let captured = client.wait_for_request(1).await;
    let latest = captured.last().expect("delivered turn");
    assert!(
        !latest.request_json.contains("<mobkit_memory_observation"),
        "per-turn memory envelope must not appear in classic-path turns"
    );
    runtime.mob_handle().stop().await.expect("stop");
}

// ---------------------------------------------------------------------------
// The console Memory panel RPC is serviceable on the classic path (the
// builder auto-wires the panel store; experience.memory follows from it).
// ---------------------------------------------------------------------------

fn decision_state() -> meerkat_mobkit::RuntimeDecisionState {
    build_runtime_decision_state(RuntimeDecisionInputs {
        bigquery: BigQueryNaming {
            dataset: "classic_memory_dataset".to_string(),
            table: "classic_memory_table".to_string(),
        },
        trusted_mobkit_toml: r#"
[[modules]]
id = "router"
command = "router-bin"
args = []
restart_policy = "always"
"#
        .to_string(),
        auth: AuthPolicy {
            default_provider: meerkat_mobkit::AuthProvider::GoogleOAuth,
            email_allowlist: vec!["root@example.test".to_string()],
        },
        trusted_oidc: TrustedOidcRuntimeConfig {
            discovery_json:
                r#"{"issuer":"https://trusted.mobkit.local","jwks_uri":"https://trusted.mobkit.local/.well-known/jwks.json"}"#
                    .to_string(),
            jwks_json: r#"{"keys":[{"kid":"kid-current","kty":"oct","alg":"HS256","k":"cGhhc2U3LXRydXN0ZWQtY3VycmVudC1zZWNyZXQ"}]}"#
                .to_string(),
            audience: "meerkat-console".to_string(),
        },
        console: ConsolePolicy {
            require_app_auth: false,
            ..ConsolePolicy::default()
        },
        ops: RuntimeOpsPolicy::default(),
        release_metadata_json: include_str!("../assets/release-targets.json").to_string(),
    })
    .expect("decision state builds")
}

async fn rpc(app: &axum::Router, method: &str, params: Value) -> Value {
    let payload = json!({
        "jsonrpc": "2.0",
        "id": "test",
        "method": method,
        "params": params,
    });
    let response = app
        .clone()
        .oneshot(
            Request::builder()
                .method("POST")
                .uri("/console/rpc")
                .header(header::CONTENT_TYPE, "application/json")
                .body(Body::from(payload.to_string()))
                .expect("rpc request"),
        )
        .await
        .expect("rpc response");
    assert_eq!(response.status(), StatusCode::OK);
    let body = to_bytes(response.into_body(), 1024 * 1024)
        .await
        .expect("rpc body");
    serde_json::from_slice(&body).expect("rpc json")
}

#[tokio::test(flavor = "multi_thread")]
async fn classic_memory_panel_records_rpc_is_serviceable() {
    let memory_dir = tempfile::tempdir().expect("memory dir");
    let store = SqliteAgentMemoryStore::open(memory_dir.path()).expect("sqlite store");
    seed_identity_record(&store, "helper", "Panel fact", "Visible from the panel.").await;

    let runtime = build_classic_runtime(
        store,
        AgentMemoryConfig::default(),
        CaptureClient::default(),
    )
    .await;
    let app = runtime.build_reference_app_router(decision_state());

    let records = rpc(&app, "mobkit/memory/panel/records", json!({})).await;
    assert_eq!(records["error"], Value::Null, "{records:#?}");
    let rows = records["result"]["records"].as_array().expect("records");
    assert!(
        rows.iter().any(|row| row["title"] == json!("Panel fact")),
        "seeded record must be readable through the panel RPC: {rows:#?}"
    );

    // experience.memory affordance follows the wired panel store.
    let response = app
        .clone()
        .oneshot(
            Request::builder()
                .method("GET")
                .uri("/console/experience")
                .body(Body::empty())
                .expect("experience request"),
        )
        .await
        .expect("experience response");
    assert_eq!(response.status(), StatusCode::OK);
    let body = to_bytes(response.into_body(), 1024 * 1024)
        .await
        .expect("experience body");
    let experience: Value = serde_json::from_slice(&body).expect("experience json");
    assert_eq!(
        experience["memory"]["available"],
        json!(true),
        "experience.memory must be available on the classic path: {experience:#?}"
    );
    runtime.mob_handle().stop().await.expect("stop");
}

// Control experiment: turn reaches LLM without memory configured.
#[tokio::test(flavor = "multi_thread")]
async fn control_member_turn_reaches_llm_without_memory() {
    let client = CaptureClient::default();
    let runtime = Box::pin(
        UnifiedRuntime::builder()
            .definition(test_definition())
            .default_llm_client(Arc::new(client.clone()))
            .build(),
    )
    .await
    .expect("classic runtime without memory");
    runtime
        .spawn_many(vec![SpawnMemberSpec::from_wire(
            "worker".to_string(),
            "helper".to_string(),
            None,
            None,
            None,
        )])
        .await
        .expect("spawn member");
    meerkat_mobkit::send_message_on_mob(&runtime.mob_handle(), "helper", "hello".to_string())
        .await
        .expect("send message");
    client.wait_for_request(1).await;
    runtime.mob_handle().stop().await.expect("stop");
}

// ---------------------------------------------------------------------------
// Gate: genuinely-invalid combinations still error.
// ---------------------------------------------------------------------------

async fn build_err(builder: meerkat_mobkit::UnifiedRuntimeBuilder) -> String {
    match Box::pin(builder.build()).await {
        Ok(_) => panic!("build should have failed"),
        Err(err) => err.to_string(),
    }
}

/// The full-stack builder path (OB3 deployment shape): store + firewall +
/// judgment engines assembled from `UnifiedRuntimeBuilder` alone — no
/// gateway. Asserts the panel store registers (proving the SQLite stack, not
/// the markdown fallback, is live) and that the recorder-facing provider
/// writes into it.
#[tokio::test(flavor = "multi_thread")]
async fn builder_full_memory_stack_installs_engines_and_panel() {
    let dir = tempfile::tempdir().expect("state dir");
    let engines = meerkat_mobkit::memory_wiring::MemoryEnginesConfig {
        steward: meerkat_mobkit::memory::steward::StewardConfig {
            enabled: true,
            ..Default::default()
        },
        distiller: meerkat_mobkit::memory::distiller::DistillerConfig {
            enabled: true,
            ..Default::default()
        },
    };
    let runtime = UnifiedRuntime::builder()
        .definition(test_definition())
        .persistent_state(dir.path().join("state"))
        .persistent_agent_memory_stack(AgentMemoryConfig::default(), engines)
        .build()
        .await
        .expect("build full memory stack");

    let store = runtime
        .memory_panel_store()
        .expect("panel store registered by the builder stack path");
    // The provider is the same bundled store: a write through it is visible
    // via the panel handle (recorder-path smoke).
    store
        .remember_authored(
            &meerkat_mobkit::memory::records::MemoryScope::Identity {
                realm: "default".to_string(),
                identity: "worker:one".to_string(),
            },
            meerkat_mobkit::memory::records::NewMemoryRecord {
                kind: meerkat_mobkit::memory::records::MemoryKind::Fact,
                title: "builder stack fact".to_string(),
                description: String::new(),
                body: "written through the builder-assembled stack".to_string(),
                tags: Vec::new(),
                evidence: Vec::new(),
                verification: None,
            },
            meerkat_mobkit::memory::records::MemoryAuthor::Operator,
        )
        .await
        .expect("write through the stack store");
    runtime.shutdown().await;

    // Requires persistent_state, loudly.
    let err = build_err(
        UnifiedRuntime::builder()
            .definition(test_definition())
            .persistent_agent_memory_stack(
                AgentMemoryConfig::default(),
                meerkat_mobkit::memory_wiring::MemoryEnginesConfig::default(),
            ),
    )
    .await;
    assert!(err.contains("requires persistent_state"), "{err}");
}

#[tokio::test]
async fn gate_still_rejects_invalid_memory_combinations() {
    // Identity-first inputs (a custom AgentCustomizer) still require the
    // roster even when memory is configured.
    struct NoopCustomizer;
    #[async_trait::async_trait]
    impl meerkat_mobkit::identity_first::contracts::AgentCustomizer for NoopCustomizer {
        async fn customize_build(
            &self,
            _context: &meerkat_mobkit::identity_first::AgentBuildContext,
            _spec: &meerkat_mobkit::identity_first::DurableAgentSpec,
            _draft: &mut meerkat_mobkit::identity_first::AgentBuildDraft,
        ) -> Result<(), meerkat_mobkit::identity_first::CustomizerError> {
            Ok(())
        }
    }
    let memory_dir2 = tempfile::tempdir().expect("memory dir");
    let store2 = SqliteAgentMemoryStore::open(memory_dir2.path()).expect("sqlite store");
    let err = build_err(
        UnifiedRuntime::builder()
            .definition(test_definition())
            .agent_customizer(Arc::new(NoopCustomizer))
            .agent_memory(Arc::new(store2), AgentMemoryConfig::default()),
    )
    .await;
    assert!(err.contains("roster_provider"), "{err}");
}