From af7315b98bc45adfdf98e276ce5c16a7f24c1b90 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 19 Nov 2026 21:52:42 +0100 Subject: [PATCH 01/45] Persona door: a second RUDP listener that answers reads and her persona, never an admission HuginnMindRequest::reaches_persona_door classifies every request with no wildcard; Daemon::handle_at refuses what the persona door does not answer with MindRefusal::NotThisDoor before the mind is asked; --persona-bind binds the second hub, and run serves both, a search answering by the door it came in at. Map: docs/persona-only-heartbeat-map.md (d861574), cut C1. Co-Authored-By: Claude Opus 5.5 --- crates/eureka-state/tests/common/mod.rs | 2 +- crates/huginn-daemon/src/daemon.rs | 91 +++++++ crates/huginn-daemon/src/desk_door_tests.rs | 4 +- crates/huginn-daemon/src/main.rs | 11 +- crates/huginn-daemon/src/semantic_tests.rs | 2 +- crates/huginn-daemon/src/serve.rs | 223 +++++++++++++----- crates/huginn-mind/src/refusal.rs | 4 + crates/huginn-mind/src/wire.rs | 23 ++ .../huginn.desk_response.v1.schema.json | 5 + .../huginn.mind_response.v1.schema.json | 5 + 10 files changed, 297 insertions(+), 73 deletions(-) diff --git a/crates/eureka-state/tests/common/mod.rs b/crates/eureka-state/tests/common/mod.rs index 2358f09..00dd9e6 100644 --- a/crates/eureka-state/tests/common/mod.rs +++ b/crates/eureka-state/tests/common/mod.rs @@ -172,7 +172,7 @@ pub fn serve + Send + 'static>( let loop_stopping = Arc::clone(&stopping); let registry = schema_registry().unwrap(); let thread = std::thread::spawn(move || { - run(&mut daemon, &mut hub, ®istry, None, &loop_stopping, &ServeOptions::default()).unwrap(); + run(&mut daemon, &mut hub, None, ®istry, None, &loop_stopping, &ServeOptions::default()).unwrap(); }); Server { addr, stopping, thread: Some(thread), ended: Arc::default(), _root: Some(root) } } diff --git a/crates/huginn-daemon/src/daemon.rs b/crates/huginn-daemon/src/daemon.rs index 1be6aae..8bcd222 100644 --- a/crates/huginn-daemon/src/daemon.rs +++ b/crates/huginn-daemon/src/daemon.rs @@ -109,6 +109,17 @@ impl Handled { } } +/// Which RUDP listener a request arrived on. `Full` is `--bind`, which the +/// faculties that write the mind reach. `Persona` is `--persona-bind`, the +/// only listener a Persona's uid can reach (the host fence decides that): it +/// answers what `HuginnMindRequest::reaches_persona_door` accepts and refuses +/// the rest with `MindRefusal::NotThisDoor` before the mind is asked. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Door { + Full, + Persona, +} + /// The door checks an account id; the Mind's desk calls take it as the text it is. fn short_id(id: AccountId) -> Short { Short(id.0) @@ -177,6 +188,16 @@ impl> Daemon { runtime_id(self.mind.instance()) } + /// One request as it arrived at `door`: a request the door does not + /// answer is refused before the mind sees it, and every other goes to + /// `handle`. The wire reaches the mind only through here. + pub fn handle_at(&mut self, door: Door, request: HuginnMindRequest, now: DateTime) -> Handled { + if door == Door::Persona && !request.reaches_persona_door() { + return Handled::Answered(HuginnMindResponse::Refused(MindRefusal::NotThisDoor)); + } + self.handle(request, now) + } + /// One request, one answer, or a search to finish. `Admit` goes to the mind whole, because the /// batch declares its own instance and admission's A1 is the check. Every /// other request names an instance: `require_instance` now applies the @@ -1011,6 +1032,76 @@ pub(crate) mod tests { assert_eq!(status(&mut daemon).persona, huginn_mind::wire::PersonaStatus::Absent); } + /// The persona door refuses an admission before the mind sees it, so the + /// store is unchanged, and answers the reads and her own persona put; the + /// full door admits the same batch. + #[test] + fn the_persona_door_refuses_an_admission_and_answers_reads_and_her_persona() { + let (_root, mut daemon) = seeded(); + let before = status(&mut daemon); + let admit = || HuginnMindRequest::Admit(batch(INSTANCE, vec![identity(INSTANCE)])); + assert_eq!( + daemon.handle_at(Door::Persona, admit(), now()).answered(), + HuginnMindResponse::Refused(MindRefusal::NotThisDoor) + ); + assert_eq!(status(&mut daemon), before, "nothing was written"); + + let state = serde_json::json!({ + "schemaVersion": "gamecult.persona_state.v0", + "provenance": { + "sourceSystem": "huginn", "sourceDocumentId": INSTANCE, "sourceUpdatedAt": "2026-11-19T10:00:00Z", + "exportedAt": "2026-11-19T10:00:00Z", "authority": "canonical" + }, + "personaId": INSTANCE, + "publicName": "Test Persona", + "presentation": { "voiceSummary": "plain" }, + "activationProfile": { + "underlyingOrganization": {}, "stableDispositions": {}, "behavioralDimensions": {}, + "presentationStrategy": {}, "voiceStyle": {}, "situationalState": {} + }, + "thoughtMemory": { "shortTerm": [], "memories": [], "incubation": [] }, + "agencyPressure": { "pressures": [] }, + "candidateActions": { "actions": [] }, + "affect": { + "needs": [], "socialBonds": [], "statusReads": [], "moodDimensions": [], + "socialBiases": [], "doctrineStances": [] + }, + "updatedAt": "2026-11-19T10:00:00Z" + }); + let put = HuginnMindRequest::PersonaPut { + instance: slug(INSTANCE), + provenance: provenance(), + state, + expected_updated_at: None, + }; + assert!(matches!( + daemon.handle_at(Door::Persona, put, now()).answered(), + HuginnMindResponse::PersonaPut(huginn_mind::PersonaPutOutcome::Committed { .. }) + )); + assert!(matches!( + daemon.handle_at(Door::Persona, HuginnMindRequest::PersonaGet { instance: slug(INSTANCE) }, now()).answered(), + HuginnMindResponse::Persona(Some(_)) + )); + let query = HuginnMindRequest::Query { instance: slug(INSTANCE), selection: Selection::default(), semantic: None }; + let HuginnMindResponse::Query(page) = daemon.handle_at(Door::Persona, query, now()).answered() else { + panic!("a query answers a page at the persona door") + }; + let id = match page.items { + PipelinePageItems::Headers(items) => items[0].id.clone(), + PipelinePageItems::Documents(items) => items[0].id.clone(), + }; + assert!(matches!( + daemon.handle_at(Door::Persona, HuginnMindRequest::View { instance: slug(INSTANCE), id }, now()).answered(), + HuginnMindResponse::View(Some(_)) + )); + assert_eq!(status(&mut daemon).documents, before.documents, "a persona put writes no pipeline document"); + + assert!( + matches!(daemon.handle_at(Door::Full, admit(), now()).answered(), HuginnMindResponse::Admit(_)), + "the full door hands the same batch to admission" + ); + } + /// A declared instance outside `Slug`'s grammar is refused by its own /// name, `InvalidFormat`, on the read path, before the identity /// comparison ever runs: it is not merely a foreign mind, it names no diff --git a/crates/huginn-daemon/src/desk_door_tests.rs b/crates/huginn-daemon/src/desk_door_tests.rs index 2acb80e..16f6522 100644 --- a/crates/huginn-daemon/src/desk_door_tests.rs +++ b/crates/huginn-daemon/src/desk_door_tests.rs @@ -467,7 +467,7 @@ mod door_smoke { let stopping = Arc::new(AtomicBool::new(false)); let loop_stopping = Arc::clone(&stopping); let serving = std::thread::spawn(move || { - run(&mut daemon, &mut hub, ®istry, Some(&mut door), &loop_stopping, &ServeOptions::default()).unwrap(); + run(&mut daemon, &mut hub, None, ®istry, Some(&mut door), &loop_stopping, &ServeOptions::default()).unwrap(); }); let mut stalled = connect(&path); @@ -591,7 +591,7 @@ mod door_smoke { let registry = schema_registry().unwrap(); let mut bodies = crate::bodies::DeferredBodies::new(1 << 20, Duration::from_secs(60)); let desk = raw(MIND_SERVICE_ID, DESK_REQUEST_SCHEMA, "answer", "m-1", rmp_serde::to_vec_named(&answer("x", DeskAuthority::Operator, &["x"], wire(&hash, R1))).unwrap()); - let CultNetMessage::OperationResponse { payload_schema, diagnostics, .. } = crate::serve::answer(&mut daemon, ®istry, &mut bodies, desk, now()).reply() else { + let CultNetMessage::OperationResponse { payload_schema, diagnostics, .. } = crate::serve::answer(&mut daemon, crate::daemon::Door::Full, ®istry, &mut bodies, desk, now()).reply() else { panic!("expected a response") }; assert_eq!(payload_schema, huginn_mind::envelope::FAILURE_SCHEMA); diff --git a/crates/huginn-daemon/src/main.rs b/crates/huginn-daemon/src/main.rs index 8b27ff0..0d0ed7d 100644 --- a/crates/huginn-daemon/src/main.rs +++ b/crates/huginn-daemon/src/main.rs @@ -1,5 +1,5 @@ -//! The process: open one instance's mind, bind one socket, serve until a stop -//! signal. A mind that will not open ends the process with the refusal on +//! The process: open one instance's mind, bind its socket (and the persona +//! door's, when asked), serve until a stop signal. A mind that will not open ends the process with the refusal on //! stderr and no socket ever bound. use std::sync::Arc; @@ -15,7 +15,7 @@ fn main() -> Result<()> { let options = parse_options(std::env::args().skip(1))?; let embedder = pool(&options.ollama_urls, &options.reserve_ollama_urls, &options.embedding_model); let index = QdrantIndex::new(&options.qdrant_url); - let Started { mut daemon, mut hub, registry, mut desk } = match startup(&options, embedder, index, Backoff::default()) { + let Started { mut daemon, mut hub, mut persona, registry, mut desk } = match startup(&options, embedder, index, Backoff::default()) { Ok(started) => started, Err(error) => { eprintln!("huginn-daemon refuses to serve {}: {error:#}", options.instance.0); @@ -33,8 +33,11 @@ fn main() -> Result<()> { } eprintln!("huginn-daemon serving {} on {}", options.instance.0, hub.local_addr()?); + if let Some(door) = &persona { + eprintln!("huginn-daemon serving the persona door on {}", door.local_addr()?); + } if let Some(door) = &desk { eprintln!("huginn-daemon serving the desk door on {}", door.path().display()); } - run(&mut daemon, &mut hub, ®istry, desk.as_mut(), &stopping, &ServeOptions::default()) + run(&mut daemon, &mut hub, persona.as_mut(), ®istry, desk.as_mut(), &stopping, &ServeOptions::default()) } diff --git a/crates/huginn-daemon/src/semantic_tests.rs b/crates/huginn-daemon/src/semantic_tests.rs index 321b446..d35aa91 100644 --- a/crates/huginn-daemon/src/semantic_tests.rs +++ b/crates/huginn-daemon/src/semantic_tests.rs @@ -176,7 +176,7 @@ impl Harness { let stopping = Arc::new(AtomicBool::new(false)); let loop_stopping = Arc::clone(&stopping); let options = ServeOptions::default(); - let serving = std::thread::spawn(move || run(&mut daemon, &mut hub, ®istry, None, &loop_stopping, &options)); + let serving = std::thread::spawn(move || run(&mut daemon, &mut hub, None, ®istry, None, &loop_stopping, &options)); Self { endpoint, stopping, serving: Some(serving), embedder, index, _root: root } } diff --git a/crates/huginn-daemon/src/serve.rs b/crates/huginn-daemon/src/serve.rs index 22c27df..a28cdb9 100644 --- a/crates/huginn-daemon/src/serve.rs +++ b/crates/huginn-daemon/src/serve.rs @@ -78,7 +78,7 @@ use huginn_mind::{Mind, MindRefusal, MindStore, OwnedRedbMessagePackBackingStore use crate::bodies::{ DEFERRED_BUDGET_BYTES, DEFERRED_CHUNK_BYTES, DeferredBodies, }; -use crate::daemon::{Daemon, Handled, IndexSink, Search, SearchTicket, runtime_id}; +use crate::daemon::{Daemon, Door, Handled, IndexSink, Search, SearchTicket, runtime_id}; use crate::desk_door::{DeskDoor, bind_desk}; use huginn_mind::envelope::{OperationFailure, decode_request, encode_failure, encode_response}; use huginn_mind::MAX_DEFERRED_BODY_BYTES; @@ -111,6 +111,10 @@ pub struct Options { pub state_root: PathBuf, pub instance: Slug, pub bind: SocketAddr, + /// The persona door (`--persona-bind`): a second RUDP listener answering + /// only what `HuginnMindRequest::reaches_persona_door` accepts. Absent, + /// the daemon has no persona door. + pub persona_bind: Option, pub qdrant_url: String, /// The GPU hosts: all take embedding at once. One is the plain case. pub ollama_urls: Vec, @@ -134,7 +138,7 @@ pub struct DeskOptions { /// Exactly `--state-root`, `--instance`, `--bind`, `--qdrant-url`, /// `--ollama-url` and `--embedding-model`, each required, each once, except /// `--ollama-url`, which repeats for each GPU host, and the optional -/// `--reserve-ollama-url`, which repeats for each CPU host, and the optional `--forge-url`, once, and the optional pair `--desk-socket` (an absolute path) and `--desk-peer-uid` (a uid other than 0), both or neither, each once. The URLs are plain +/// `--reserve-ollama-url`, which repeats for each CPU host, and the optional `--forge-url` and `--persona-bind` (an ip:port other than `--bind`), each once, and the optional pair `--desk-socket` (an absolute path) and `--desk-peer-uid` (a uid other than 0), both or neither, each once. The URLs are plain /// `http://`: this build carries no TLS. pub fn parse_options(args: impl Iterator) -> Result { let mut args = args; @@ -143,7 +147,7 @@ pub fn parse_options(args: impl Iterator) -> Result { while let Some(name) = args.next() { let name = name.strip_prefix("--").with_context(|| format!("expected --option, got {name:?}"))?; ensure!( - matches!(name, "state-root" | "instance" | "bind" | "qdrant-url" | "ollama-url" | "reserve-ollama-url" | "embedding-model" | "forge-url" | "desk-socket" | "desk-peer-uid"), + matches!(name, "state-root" | "instance" | "bind" | "persona-bind" | "qdrant-url" | "ollama-url" | "reserve-ollama-url" | "embedding-model" | "forge-url" | "desk-socket" | "desk-peer-uid"), "unsupported Huginn option --{name}" ); let value = args.next().with_context(|| format!("missing value for --{name}"))?; @@ -167,10 +171,20 @@ pub fn parse_options(args: impl Iterator) -> Result { }; let embedding_model = take("embedding-model")?; ensure!(!embedding_model.is_empty(), "--embedding-model must name a model"); + let bind: SocketAddr = bind.parse().with_context(|| format!("--bind must be an ip:port, got {bind:?}"))?; + let persona_bind = match values.get("persona-bind") { + None => None, + Some(door) => { + let door: SocketAddr = door.parse().with_context(|| format!("--persona-bind must be an ip:port, got {door:?}"))?; + ensure!(door != bind, "--persona-bind must not be --bind: the persona door is its own listener"); + Some(door) + } + }; Ok(Options { state_root, instance: Slug(take("instance")?), - bind: bind.parse().with_context(|| format!("--bind must be an ip:port, got {bind:?}"))?, + bind, + persona_bind, qdrant_url: url("qdrant-url")?, ollama_urls: { ensure!(!ollama_urls.is_empty(), "--ollama-url is required; repeat it for each GPU host"); @@ -206,6 +220,7 @@ where { let mind = Mind::open(&options.state_root, &options.instance)?; let hub = bind(options.bind, &runtime_id(&options.instance))?; + let persona = options.persona_bind.map(|door| bind(door, &runtime_id(&options.instance))).transpose()?; let desk = options.desk.as_ref().map(|desk| bind_desk(&desk.socket, desk.peer_uid)).transpose()?; let startup_entries = mind.index_entries(None)?; let sink = WorkerSink::spawn(embedder, index, &options.instance, mind.genesis_receipt_id()?, startup_entries, backoff); @@ -214,14 +229,16 @@ where Some(url) => daemon.with_forge(crate::sources::forge::HttpForge::new(url)), None => daemon, }; - Ok(Started { daemon, hub, registry: schema_registry()?, desk }) + Ok(Started { daemon, hub, persona, registry: schema_registry()?, desk }) } /// What `startup` hands the loop: the daemon over the opened mind, the bound RUDP hub, the -/// catalog the RUDP door advertises, and the desk door when one was asked for. +/// persona door's hub when one was asked for, the catalog both RUDP doors advertise, and the +/// desk door when one was asked for. pub struct Started { pub daemon: Daemon, pub hub: CultNetRudpServerHub, + pub persona: Option, pub registry: CultNetSchemaRegistry, pub desk: Option, } @@ -321,12 +338,14 @@ impl Routed { } /// One message in, one message out, or a search to wait for. Nothing here -/// reaches a mind except through `Daemon::handle`, and an envelope that does +/// reaches a mind except through `Daemon::handle_at`, at the `door` the message +/// arrived on, and an envelope that does /// not decode never gets that far. A chunk request is answered from `bodies` /// alone, on the session it came in on; every operation's reply leaves through /// `respond`. pub fn answer>( daemon: &mut Daemon, + door: Door, registry: &CultNetSchemaRegistry, bodies: &mut DeferredBodies, message: CultNetMessage, @@ -345,7 +364,7 @@ pub fn answer>( CultNetMessage::OperationRequest { message_id, operation, .. } => match decode_request(&message) { Ok((message_id, request)) => { let operation = request.operation(); - match daemon.handle(request, now) { + match daemon.handle_at(door, request, now) { Handled::Answered(response) => respond(&response, &message_id, operation, &runtime_id, bodies, now), Handled::Searching(search) => return Routed::Search { message_id, operation, search }, } @@ -483,9 +502,11 @@ fn deliver( deferred } -/// A semantic query on its way through the index: who asked, what to call the -/// answer, the search to finish, and when the client stops being promised one. +/// A semantic query on its way through the index: who asked, at which door, +/// what to call the answer, the search to finish, and when the client stops +/// being promised one. struct Waiting { + door: Door, session: CultNetRudpServerSessionContext, message_id: String, operation: &'static str, @@ -494,9 +515,11 @@ struct Waiting { } /// Until `stopping`: expire what timed out, resend what was not acknowledged, -/// answer every frame waiting on the socket, then answer every semantic query -/// the index has finished or that has waited out the index's own -/// `search_deadline`. A semantic +/// answer every frame waiting on either RUDP door's socket, then answer every +/// semantic query the index has finished or that has waited out the index's +/// own `search_deadline`. A frame on `hub` is asked at `Door::Full`, one on +/// `persona` at `Door::Persona`, and a search's answer leaves by the door it +/// came in at. A semantic /// query is never answered inline: `answer` hands back a `Search`, the loop /// holds it beside its session and goes on serving, and the embedder and the /// vector store are the worker's to wait on. A hostile datagram and a departed @@ -505,51 +528,18 @@ struct Waiting { pub fn run>( daemon: &mut Daemon, hub: &mut CultNetRudpServerHub, + mut persona: Option<&mut CultNetRudpServerHub>, registry: &CultNetSchemaRegistry, mut desk: Option<&mut DeskDoor>, stopping: &AtomicBool, options: &ServeOptions, ) -> Result<()> { - let timeout_ms = options.session_timeout.as_millis() as u64; let mut bodies = DeferredBodies::new(DEFERRED_BUDGET_BYTES, options.deferred_ttl); let mut waiting: BTreeMap = BTreeMap::new(); while !stopping.load(Ordering::Relaxed) { - hub.remove_timed_out_sessions(timeout_ms); - if let Err(error) = hub.poll_resends() { - eprintln!("huginn: resending to a peer failed: {error:#}"); - } - let mut served = 0_u32; - loop { - let event = match hub.receive_event_once() { - Ok(Some(event)) => event, - Ok(None) => break, - Err(error) => { - eprintln!("huginn: a datagram was not readable and was discarded: {error:#}"); - break; - } - }; - let CultNetRudpServerEvent::Frame { session, frame } = event else { - continue; - }; - if frame.channel_id != "schema" { - continue; - } - let message = match decode_cultnet_message_from_slice(&frame.payload, CultNetWireContract::CultNetSchemaV0) - { - Ok(message) => message, - Err(error) => { - eprintln!("huginn: a frame was not a CultNet message and was discarded: {error:#}"); - continue; - } - }; - match answer(daemon, registry, &mut bodies, message, Utc::now()) { - Routed::Reply(reply) => send(hub, &session, &reply), - Routed::Search { message_id, operation, search } => { - let until = Instant::now() + daemon.search_deadline(); - waiting.insert(search.ticket, Waiting { session, message_id, operation, search, until }); - } - } - served += 1; + let mut served = serve_frames(daemon, hub, Door::Full, registry, &mut bodies, &mut waiting, options); + if let Some(door) = persona.as_deref_mut() { + served += serve_frames(daemon, door, Door::Persona, registry, &mut bodies, &mut waiting, options); } let desk_served = desk.as_deref_mut().map_or(0, |door| door.serve_ready(daemon, Utc::now())); let finished = collect_searches(daemon, &waiting); @@ -558,7 +548,14 @@ pub fn run>( let Some(asked) = waiting.remove(&ticket) else { continue }; let response = daemon.finish(asked.search, found); let reply = respond(&response, &asked.message_id, asked.operation, &daemon.runtime_id(), &mut bodies, Utc::now()); - send(hub, &asked.session, &reply); + let out = match asked.door { + Door::Full => &mut *hub, + Door::Persona => match persona.as_deref_mut() { + Some(door) => door, + None => continue, + }, + }; + send(out, &asked.session, &reply); } if served == 0 && desk_served == 0 && !answered { std::thread::sleep(options.idle_sleep); @@ -567,6 +564,57 @@ pub fn run>( Ok(()) } +/// One pass over one RUDP door: expire its idle sessions, resend what it has +/// unacknowledged, and answer every frame waiting on its socket as asked at +/// `door`. Returns how many frames it answered or queued. +fn serve_frames>( + daemon: &mut Daemon, + hub: &mut CultNetRudpServerHub, + door: Door, + registry: &CultNetSchemaRegistry, + bodies: &mut DeferredBodies, + waiting: &mut BTreeMap, + options: &ServeOptions, +) -> u32 { + hub.remove_timed_out_sessions(options.session_timeout.as_millis() as u64); + if let Err(error) = hub.poll_resends() { + eprintln!("huginn: resending to a peer failed: {error:#}"); + } + let mut served = 0_u32; + loop { + let event = match hub.receive_event_once() { + Ok(Some(event)) => event, + Ok(None) => break, + Err(error) => { + eprintln!("huginn: a datagram was not readable and was discarded: {error:#}"); + break; + } + }; + let CultNetRudpServerEvent::Frame { session, frame } = event else { + continue; + }; + if frame.channel_id != "schema" { + continue; + } + let message = match decode_cultnet_message_from_slice(&frame.payload, CultNetWireContract::CultNetSchemaV0) { + Ok(message) => message, + Err(error) => { + eprintln!("huginn: a frame was not a CultNet message and was discarded: {error:#}"); + continue; + } + }; + match answer(daemon, door, registry, bodies, message, Utc::now()) { + Routed::Reply(reply) => send(hub, &session, &reply), + Routed::Search { message_id, operation, search } => { + let until = Instant::now() + daemon.search_deadline(); + waiting.insert(search.ticket, Waiting { door, session, message_id, operation, search, until }); + } + } + served += 1; + } + served +} + /// What the index has finished, then what has waited too long: the latter as /// an `Unavailable` detail, and abandoned, so the index does not start a search /// nobody is waiting for. A search that finishes after its deadline finds @@ -680,14 +728,14 @@ mod tests { ("m-5b", request("m-5b", MIND_SERVICE_ID, "Admit", MIND_REQUEST_SCHEMA, admit), "operation-mismatch"), ]; for (id, message, code) in cases { - let reply = answer(&mut daemon, ®istry, &mut fresh_bodies(), message, now()).reply(); + let reply = answer(&mut daemon, Door::Full, ®istry, &mut fresh_bodies(), message, now()).reply(); assert_eq!(rejected(&reply).0, id, "the client's own correlation key is echoed"); assert_eq!(rejected(&reply).1, code); } // The sixth code, `not-an-operation-request`, is the codec's and is // pinned in `huginn_mind::envelope::tests`: `answer` never produces it, because a // message of another family is answered with `Error` instead. - let reply = answer(&mut daemon, ®istry, &mut fresh_bodies(), CultNetMessage::Error { error: "hello".into(), code: None, details: None }, now()).reply(); + let reply = answer(&mut daemon, Door::Full, ®istry, &mut fresh_bodies(), CultNetMessage::Error { error: "hello".into(), code: None, details: None }, now()).reply(); let CultNetMessage::Error { error, .. } = &reply else { panic!("expected an error, got {reply:?}") }; assert!( !error.is_empty() && error.contains("cultnet.operation_request.v0") && error.contains("cultnet.schema_catalog_request.v0"), @@ -699,7 +747,7 @@ mod tests { // A mind's refusal is an answer on the response schema, not a failure // of the envelope: the client decodes it as the typed refusal it is. let read = HuginnMindRequest::Query { instance: slug(OTHER), selection: Selection::default(), semantic: None }; - let reply = answer(&mut daemon, ®istry, &mut fresh_bodies(), encode_request("m-r", &read, None).unwrap(), now()).reply(); + let reply = answer(&mut daemon, Door::Full, ®istry, &mut fresh_bodies(), encode_request("m-r", &read, None).unwrap(), now()).reply(); let CultNetMessage::OperationResponse { status, payload_schema, .. } = &reply else { panic!("expected an operation response, got {reply:?}"); }; @@ -717,7 +765,7 @@ mod tests { schema_ids: None, kinds: None, }; - let reply = answer(&mut daemon, ®istry, &mut fresh_bodies(), catalog, now()).reply(); + let reply = answer(&mut daemon, Door::Full, ®istry, &mut fresh_bodies(), catalog, now()).reply(); let CultNetMessage::SchemaCatalogResponse { message_id, schemas } = reply else { panic!("expected a catalog response"); }; @@ -785,7 +833,7 @@ mod tests { let loop_stopping = Arc::clone(&stopping); let serving = std::thread::spawn(move || { - let result = run(&mut daemon, &mut hub, ®istry, None, &loop_stopping, &ServeOptions::default()); + let result = run(&mut daemon, &mut hub, None, ®istry, None, &loop_stopping, &ServeOptions::default()); (result, daemon) }); @@ -874,6 +922,43 @@ mod tests { panic!("{name} never connected"); } + /// Over loopback, the persona door's listener refuses an admission by name and answers a + /// read, and the full door's listener admits the same batch: only that admission lands. + #[test] + fn the_persona_listener_refuses_an_admission_the_full_listener_takes() { + let root = tempfile::tempdir().unwrap(); + let mut daemon = open_unindexed(root.path(), &slug(INSTANCE)).unwrap(); + let mut hub = bind("127.0.0.1:0".parse().unwrap(), &daemon.runtime_id()).unwrap(); + let mut door = bind("127.0.0.1:0".parse().unwrap(), &daemon.runtime_id()).unwrap(); + let full = format!("rudp://{}", hub.local_addr().unwrap()); + let persona = format!("rudp://{}", door.local_addr().unwrap()); + let registry = schema_registry().unwrap(); + let stopping = Arc::new(AtomicBool::new(false)); + let loop_stopping = Arc::clone(&stopping); + let serving = std::thread::spawn(move || { + let result = run(&mut daemon, &mut hub, Some(&mut door), ®istry, None, &loop_stopping, &ServeOptions::default()); + (result, daemon) + }); + + let admit = HuginnMindRequest::Admit(batch(INSTANCE, vec![identity(INSTANCE)])); + let mut her = connect(&persona, "persona"); + assert_eq!(ask(&mut her, "p-admit", &admit), HuginnMindResponse::Refused(MindRefusal::NotThisDoor)); + let HuginnMindResponse::Whoami(status) = ask(&mut her, "p-whoami", &HuginnMindRequest::Whoami) else { + panic!("the persona door answers whoami") + }; + assert_eq!(status.documents, 0, "the refused admission wrote nothing"); + let mut self_faculty = connect(&full, "full"); + assert!(matches!( + ask(&mut self_faculty, "f-admit", &admit), + HuginnMindResponse::Admit(PipelineAdmissionOutcome::Committed { .. }) + )); + + stopping.store(true, Ordering::Relaxed); + let (result, mut daemon) = serving.join().unwrap(); + result.unwrap(); + assert_eq!(documents(&mut daemon), 1, "only the full door's admission landed"); + } + /// One client admits batches that close, withdraw and re-open records while three others read /// the same mind: fresh queries, cursor walks across commits, a hop and whoami. The loop is /// serial, so every answer is one snapshot's; at quiesce each answer must equal what a fresh @@ -892,7 +977,7 @@ mod tests { let stopping = Arc::new(AtomicBool::new(false)); let loop_stopping = Arc::clone(&stopping); let serving = std::thread::spawn(move || { - let result = run(&mut daemon, &mut hub, ®istry, None, &loop_stopping, &ServeOptions::default()); + let result = run(&mut daemon, &mut hub, None, ®istry, None, &loop_stopping, &ServeOptions::default()); (result, daemon) }); @@ -1057,7 +1142,7 @@ mod tests { at: DateTime, ) -> CultMeshCdnArtifactManifest { let registry = schema_registry().unwrap(); - deferred_manifest(&answer(daemon, ®istry, bodies, encode_request(message_id, read, None).unwrap(), at).reply()) + deferred_manifest(&answer(daemon, Door::Full, ®istry, bodies, encode_request(message_id, read, None).unwrap(), at).reply()) } /// Whether the first chunk of a manifest is still served at an injected time. @@ -1068,7 +1153,7 @@ mod tests { at: DateTime, ) -> bool { let registry = schema_registry().unwrap(); - found(&answer(daemon, ®istry, bodies, chunk_request(manifest, 0), at).reply()) + found(&answer(daemon, Door::Full, ®istry, bodies, chunk_request(manifest, 0), at).reply()) } /// An answer larger than one send can carry is deferred to the body plane @@ -1133,7 +1218,7 @@ mod tests { let stopping = Arc::new(AtomicBool::new(false)); let loop_stopping = Arc::clone(&stopping); let serving = std::thread::spawn(move || { - let result = run(&mut daemon, &mut hub, ®istry, None, &loop_stopping, &ServeOptions::default()); + let result = run(&mut daemon, &mut hub, None, ®istry, None, &loop_stopping, &ServeOptions::default()); (result, daemon) }); @@ -1381,7 +1466,7 @@ mod tests { let manifest = ask_deferred(&mut daemon, &mut bodies, "m-v", &read, t0); assert!(manifest.chunks.len() >= 2, "the fixture needs a second chunk to serve"); let mut chunk = |index: usize, at: i64| { - answer(&mut daemon, ®istry, &mut bodies, chunk_request(&manifest, index), after(at)).reply() + answer(&mut daemon, Door::Full, ®istry, &mut bodies, chunk_request(&manifest, index), after(at)).reply() }; assert!(found(&chunk(0, 59)), "inside the TTL"); assert!(found(&chunk(1, 118)), "serving a chunk slid the expiry past the first TTL"); @@ -1394,7 +1479,7 @@ mod tests { let again = ask_deferred(&mut daemon, &mut bodies, "m-v2", &read, after(179)); assert_eq!(again.content_hash, manifest.content_hash, "the same answer is the same body"); let bytes = fetch_content(&again, MAX_DEFERRED_BODY_BYTES, |request| { - Ok(answer(&mut daemon, ®istry, &mut bodies, request, after(180)).reply()) + Ok(answer(&mut daemon, Door::Full, ®istry, &mut bodies, request, after(180)).reply()) }) .unwrap(); assert_eq!(bytes, expected); @@ -1494,7 +1579,7 @@ mod tests { ("record_key", chunk("m", "abc", &huge)), ]; for (case, message) in refused { - let reply = answer(&mut daemon, ®istry, &mut bodies, message, now()).reply(); + let reply = answer(&mut daemon, Door::Full, ®istry, &mut bodies, message, now()).reply(); let CultNetMessage::Error { error, .. } = &reply else { panic!("{case}: expected a transport error, got {reply:?}"); }; @@ -1503,9 +1588,9 @@ mod tests { } assert_eq!(documents(&mut daemon), 0); - let reply = answer(&mut daemon, ®istry, &mut bodies, whoami(&at, MIND_SERVICE_ID, "whoami", MIND_REQUEST_SCHEMA), now()).reply(); + let reply = answer(&mut daemon, Door::Full, ®istry, &mut bodies, whoami(&at, MIND_SERVICE_ID, "whoami", MIND_REQUEST_SCHEMA), now()).reply(); assert_eq!(decode_response(&reply).unwrap().0, at, "a field of exactly the bound is served"); - let reply = answer(&mut daemon, ®istry, &mut bodies, chunk(&at, &at, &at), now()).reply(); + let reply = answer(&mut daemon, Door::Full, ®istry, &mut bodies, chunk(&at, &at, &at), now()).reply(); assert!(!found(&reply), "an unknown chunk is answered found: false, not refused at the door"); } @@ -1565,6 +1650,7 @@ mod tests { state_root: root.path().to_path_buf(), instance: slug(INSTANCE), bind: port, + persona_bind: None, qdrant_url: "http://127.0.0.1:1".into(), ollama_urls: vec!["http://127.0.0.1:1".into()], reserve_ollama_urls: Vec::new(), @@ -1604,6 +1690,7 @@ mod tests { state_root: PathBuf::from(root), instance: slug("yggdrasil"), bind: "127.0.0.1:17872".parse().unwrap(), + persona_bind: None, qdrant_url: "http://127.0.0.1:6333".into(), ollama_urls: vec!["http://10.77.0.4:11434".into()], reserve_ollama_urls: Vec::new(), @@ -1647,5 +1734,11 @@ mod tests { assert_eq!(parse_options(args(&forged)).unwrap().forge_url.as_deref(), Some("http://127.0.0.1:3310")); assert!(parse_options(args(&[good.to_vec(), vec!["--forge-url", "https://127.0.0.1:3310"]].concat())).is_err()); assert!(parse_options(args(&[forged.clone(), vec!["--forge-url", "http://127.0.0.1:3311"]].concat())).is_err()); + // The persona door is optional, once, an ip:port, and never the full door's. + let door = [good.to_vec(), vec!["--persona-bind", "127.0.0.1:17862"]].concat(); + assert_eq!(parse_options(args(&door)).unwrap().persona_bind, Some("127.0.0.1:17862".parse().unwrap())); + assert!(parse_options(args(&[door.clone(), vec!["--persona-bind", "127.0.0.1:17863"]].concat())).is_err()); + assert!(parse_options(args(&[good.to_vec(), vec!["--persona-bind", "not-an-address"]].concat())).is_err()); + assert!(parse_options(args(&[good.to_vec(), vec!["--persona-bind", "127.0.0.1:17872"]].concat())).is_err()); } } diff --git a/crates/huginn-mind/src/refusal.rs b/crates/huginn-mind/src/refusal.rs index 06dfb10..bc905d9 100644 --- a/crates/huginn-mind/src/refusal.rs +++ b/crates/huginn-mind/src/refusal.rs @@ -117,6 +117,10 @@ pub enum MindRefusal { /// reached. CursorInvalid { message: String }, Unavailable { detail: String }, + /// The request reached the persona door, which answers reads and the + /// mind's own persona document and nothing that writes the mind + /// (`HuginnMindRequest::reaches_persona_door`). Nothing was written. + NotThisDoor, } impl std::fmt::Display for MindRefusal { diff --git a/crates/huginn-mind/src/wire.rs b/crates/huginn-mind/src/wire.rs index 8ac65dc..0c9bcc0 100644 --- a/crates/huginn-mind/src/wire.rs +++ b/crates/huginn-mind/src/wire.rs @@ -430,6 +430,28 @@ impl HuginnMindRequest { } } + /// Whether the persona door answers this request. The persona door is the + /// daemon's second listener, the only one a Persona's uid can reach: it + /// serves the mind's reads and her own persona document, and refuses + /// every write to the mind (`MindRefusal::NotThisDoor`). The match has no + /// wildcard, so a new request does not compile until it is classified + /// here. + pub fn reaches_persona_door(&self) -> bool { + match self { + Self::Whoami + | Self::View { .. } + | Self::Query { .. } + | Self::PersonaGet { .. } + | Self::PersonaPut { .. } + | Self::SearchSources { .. } + | Self::SearchChat { .. } + | Self::ChatWindow { .. } + | Self::StewardedActivity { .. } + | Self::RootsTouched { .. } => true, + Self::Admit(_) => false, + } + } + /// The instance the request declares; `Whoami` declares none. pub fn instance(&self) -> Option<&Slug> { match self { @@ -633,6 +655,7 @@ mod tests { scores: Some(vec![0.5]), }), HuginnMindResponse::Refused(refusal), + HuginnMindResponse::Refused(MindRefusal::NotThisDoor), HuginnMindResponse::Persona(None), HuginnMindResponse::Persona(Some(PersonaStateView { value: serde_json::json!({ "personaId": INSTANCE }), diff --git a/schemas/cultnet/huginn.desk_response.v1.schema.json b/schemas/cultnet/huginn.desk_response.v1.schema.json index d9bfc68..33c480f 100644 --- a/schemas/cultnet/huginn.desk_response.v1.schema.json +++ b/schemas/cultnet/huginn.desk_response.v1.schema.json @@ -1656,6 +1656,11 @@ "required": [ "Unavailable" ] + }, + { + "description": "The request reached the persona door, which answers reads and the\nmind's own persona document and nothing that writes the mind\n(`HuginnMindRequest::reaches_persona_door`). Nothing was written.", + "type": "string", + "const": "NotThisDoor" } ] }, diff --git a/schemas/cultnet/huginn.mind_response.v1.schema.json b/schemas/cultnet/huginn.mind_response.v1.schema.json index 30fc70a..eb82133 100644 --- a/schemas/cultnet/huginn.mind_response.v1.schema.json +++ b/schemas/cultnet/huginn.mind_response.v1.schema.json @@ -2302,6 +2302,11 @@ "required": [ "Unavailable" ] + }, + { + "description": "The request reached the persona door, which answers reads and the\nmind's own persona document and nothing that writes the mind\n(`HuginnMindRequest::reaches_persona_door`). Nothing was written.", + "type": "string", + "const": "NotThisDoor" } ] }, From df3272d2f25183bde88b16e3bff72887753057d1 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 19 Nov 2026 21:56:26 +0100 Subject: [PATCH 02/45] desk_door integration test: run takes the persona door's hub Co-Authored-By: Claude Opus 5.5 --- crates/huginn-daemon/tests/desk_door.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/huginn-daemon/tests/desk_door.rs b/crates/huginn-daemon/tests/desk_door.rs index de401ad..7f15bd4 100644 --- a/crates/huginn-daemon/tests/desk_door.rs +++ b/crates/huginn-daemon/tests/desk_door.rs @@ -549,13 +549,13 @@ fn a_busy_pass_is_not_followed_by_the_idle_sleep() { ]; let options = parse_options(args.iter().map(|arg| arg.to_string())).unwrap(); let embedder = pool(&options.ollama_urls, &options.reserve_ollama_urls, &options.embedding_model); - let Started { mut daemon, mut hub, registry, desk: mut door } = + let Started { mut daemon, mut hub, persona: _, registry, desk: mut door } = startup(&options, embedder, QdrantIndex::new(&options.qdrant_url), Backoff::default()).unwrap(); let stopping = Arc::new(AtomicBool::new(false)); let loop_stopping = Arc::clone(&stopping); let serving = std::thread::spawn(move || { let serve = ServeOptions { idle_sleep: Duration::from_millis(600), ..ServeOptions::default() }; - run(&mut daemon, &mut hub, ®istry, door.as_mut(), &loop_stopping, &serve) + run(&mut daemon, &mut hub, None, ®istry, door.as_mut(), &loop_stopping, &serve) }); std::thread::sleep(Duration::from_millis(100)); let frame = framed(&catalog_request()); From e5d1984dc17e373113d1f82f8963884f8a55aaf7 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 19 Nov 2026 21:57:34 +0100 Subject: [PATCH 03/45] Persona door: startup binds it when asked; the desk test names no door Co-Authored-By: Claude Opus 5.5 --- crates/huginn-daemon/src/desk_door_tests.rs | 1 + crates/huginn-daemon/src/serve.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/huginn-daemon/src/desk_door_tests.rs b/crates/huginn-daemon/src/desk_door_tests.rs index 16f6522..d32888a 100644 --- a/crates/huginn-daemon/src/desk_door_tests.rs +++ b/crates/huginn-daemon/src/desk_door_tests.rs @@ -686,6 +686,7 @@ mod door_smoke { state_root: root.path().to_path_buf(), instance: slug(INSTANCE), bind: "127.0.0.1:0".parse().unwrap(), + persona_bind: None, qdrant_url: "http://127.0.0.1:1".into(), ollama_urls: vec!["http://127.0.0.1:1".into()], reserve_ollama_urls: Vec::new(), diff --git a/crates/huginn-daemon/src/serve.rs b/crates/huginn-daemon/src/serve.rs index a28cdb9..a0296a5 100644 --- a/crates/huginn-daemon/src/serve.rs +++ b/crates/huginn-daemon/src/serve.rs @@ -1650,7 +1650,7 @@ mod tests { state_root: root.path().to_path_buf(), instance: slug(INSTANCE), bind: port, - persona_bind: None, + persona_bind: Some("127.0.0.1:0".parse().unwrap()), qdrant_url: "http://127.0.0.1:1".into(), ollama_urls: vec!["http://127.0.0.1:1".into()], reserve_ollama_urls: Vec::new(), @@ -1674,6 +1674,8 @@ mod tests { drop(occupied); let started = started(&options).expect("both gates open"); assert_eq!(started.hub.local_addr().unwrap(), port); + let door = started.persona.as_ref().expect("the persona door was asked for and bound"); + assert_ne!(door.local_addr().unwrap(), port, "the persona door is its own listener"); } #[test] From cf2729147164f175e3b8a76d327fdf880b96322c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 19 Nov 2026 22:19:15 +0100 Subject: [PATCH 04/45] Persona door: tests pin every read at the door and a semantic answer by its hub Soul C1 F4: the source, chat, chat-window, activity and roots reads are handed to the mind at the persona door (none refused NotThisDoor, each answered the same at both doors); the semantic wire test also runs through the persona door, so a held search answers by the persona hub. Co-Authored-By: Claude Opus 5.5 --- crates/huginn-daemon/src/daemon.rs | 41 ++++++++++++++++++++++ crates/huginn-daemon/src/semantic_tests.rs | 34 +++++++++++++++--- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/crates/huginn-daemon/src/daemon.rs b/crates/huginn-daemon/src/daemon.rs index 8bcd222..03cc29c 100644 --- a/crates/huginn-daemon/src/daemon.rs +++ b/crates/huginn-daemon/src/daemon.rs @@ -1102,6 +1102,47 @@ pub(crate) mod tests { ); } + /// Every read the persona door answers reaches the mind there: none of the + /// source, chat, activity and roots reads is refused as `NotThisDoor`. + /// What the mind then says (a search, or `Unavailable` with no index or + /// forge) is the mind's, the same at either door. + #[test] + fn the_persona_door_hands_every_other_read_to_the_mind() { + use huginn_mind::wire::{ChatWindowQuery, SourceQuery}; + let (_root, mut daemon) = seeded(); + let reads = [ + HuginnMindRequest::SearchSources { + instance: slug(INSTANCE), + query: SourceQuery { text: Line("reconcile".into()), texts: vec![], top_k: 5, repo: None, front: false }, + }, + HuginnMindRequest::SearchChat { + instance: slug(INSTANCE), + query: ChatQuery { texts: vec![Line("release".into())], rooms: vec![], after_ms: None, before_ms: None, top_k: 5 }, + }, + HuginnMindRequest::ChatWindow { + instance: slug(INSTANCE), + query: ChatWindowQuery { event_id: Short("$a".into()), before: 5, after: 0 }, + }, + HuginnMindRequest::StewardedActivity { instance: slug(INSTANCE), repos: vec![], after: None }, + HuginnMindRequest::RootsTouched { instance: slug(INSTANCE) }, + ]; + for read in reads { + let operation = read.operation(); + let at_door = daemon.handle_at(Door::Persona, read.clone(), now()); + assert!( + !matches!(at_door, Handled::Answered(HuginnMindResponse::Refused(MindRefusal::NotThisDoor))), + "{operation} is refused at the persona door" + ); + if let (Handled::Answered(at_door), Handled::Answered(at_full)) = (at_door, daemon.handle_at(Door::Full, read, now())) { + assert_eq!(at_door, at_full, "{operation} answers the same at either door"); + } + } + assert!(matches!( + daemon.handle_at(Door::Persona, HuginnMindRequest::RootsTouched { instance: slug(INSTANCE) }, now()).answered(), + HuginnMindResponse::RootsTouched(_) + )); + } + /// A declared instance outside `Slug`'s grammar is refused by its own /// name, `InvalidFormat`, on the read path, before the identity /// comparison ever runs: it is not merely a foreign mind, it names no diff --git a/crates/huginn-daemon/src/semantic_tests.rs b/crates/huginn-daemon/src/semantic_tests.rs index d35aa91..98b4967 100644 --- a/crates/huginn-daemon/src/semantic_tests.rs +++ b/crates/huginn-daemon/src/semantic_tests.rs @@ -143,9 +143,10 @@ fn quick() -> Backoff { Backoff { initial: Duration::from_millis(1), max: Duration::from_millis(2), recheck: Duration::from_secs(3600), search_deadline: Duration::from_secs(30) } } -/// A daemon serving a mind over a real socket, with the ports the test gave it. +/// A daemon serving a mind over real sockets, its full door and its persona door, with the ports the test gave it. struct Harness { endpoint: String, + persona_endpoint: String, stopping: Arc, serving: Option>>, embedder: FakeEmbedder, @@ -172,19 +173,31 @@ impl Harness { let mut daemon: Daemon = Daemon::new(mind, sink); let mut hub = bind("127.0.0.1:0".parse().unwrap(), &daemon.runtime_id()).unwrap(); let endpoint = format!("rudp://{}", hub.local_addr().unwrap()); + let mut door = bind("127.0.0.1:0".parse().unwrap(), &daemon.runtime_id()).unwrap(); + let persona_endpoint = format!("rudp://{}", door.local_addr().unwrap()); let registry = schema_registry().unwrap(); let stopping = Arc::new(AtomicBool::new(false)); let loop_stopping = Arc::clone(&stopping); let options = ServeOptions::default(); - let serving = std::thread::spawn(move || run(&mut daemon, &mut hub, None, ®istry, None, &loop_stopping, &options)); - Self { endpoint, stopping, serving: Some(serving), embedder, index, _root: root } + let serving = + std::thread::spawn(move || run(&mut daemon, &mut hub, Some(&mut door), ®istry, None, &loop_stopping, &options)); + Self { endpoint, persona_endpoint, stopping, serving: Some(serving), embedder, index, _root: root } } fn client(&self) -> Client { + Self::client_at(&self.endpoint) + } + + /// A client of the persona door. + fn persona_client(&self) -> Client { + Self::client_at(&self.persona_endpoint) + } + + fn client_at(endpoint: &str) -> Client { let mut client = CultMesh::create_rudp_client_for_endpoint( "semantic-test".to_string(), CULTNET_OPERATION_CONNECTION_ID, - &self.endpoint, + endpoint, CultMeshRudpSocketOptions::default(), ) .unwrap(); @@ -272,8 +285,19 @@ fn healthy() -> Harness { /// the members. #[test] fn a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits() { + a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits_at(Harness::client); +} + +/// The same semantic read asked at the persona door: the search is held while the index works, and its answer leaves by +/// the persona door's own hub to the session that asked there. +#[test] +fn a_semantic_query_at_the_persona_door_is_answered_through_the_persona_door() { + a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits_at(Harness::persona_client); +} + +fn a_semantic_query_returns_only_documents_the_mind_holds_and_the_selection_admits_at(client_of: fn(&Harness) -> Client) { let harness = healthy(); - let mut client = harness.client(); + let mut client = client_of(&harness); until_index(&mut client, "Current", |status| *status == IndexStatus::Current); harness.index.state.lock().unwrap().hits = vec![ hit("question", id("question", "Q1"), 0.95), From 3e6554ca5a98f764648636a6775dd746559ba84b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 19 Nov 2026 22:19:45 +0100 Subject: [PATCH 05/45] Cargo.lock as cargo writes it for the baf4ecf7 pin (duplicate CultLib entries reordered) Soul C1 F5: the lock from the pin merge was accepted by --locked but rewritten by an unlocked cargo; this is cargo's own rewrite. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ca536c..4901631 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,6 +350,26 @@ dependencies = [ "cipher", ] +[[package]] +name = "cultcache-rs" +version = "0.3.1" +source = "git+https://github.com/GameCult/CultLib.git?rev=a4eae9056152335662f1115f97bf35fb00ab6d23#a4eae9056152335662f1115f97bf35fb00ab6d23" +dependencies = [ + "anyhow", + "chrono", + "cultcache-rs-derive 0.2.0 (git+https://github.com/GameCult/CultLib.git?rev=a4eae9056152335662f1115f97bf35fb00ab6d23)", + "fs2", + "redb", + "rmp-serde", + "serde", + "serde_bytes", + "serde_json", + "serde_stacker", + "stacker", + "uuid", + "windows-sys 0.59.0", +] + [[package]] name = "cultcache-rs" version = "0.3.1" @@ -371,30 +391,10 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "cultcache-rs" -version = "0.3.1" -source = "git+https://github.com/GameCult/CultLib.git?rev=a4eae9056152335662f1115f97bf35fb00ab6d23#a4eae9056152335662f1115f97bf35fb00ab6d23" -dependencies = [ - "anyhow", - "chrono", - "cultcache-rs-derive 0.2.0 (git+https://github.com/GameCult/CultLib.git?rev=a4eae9056152335662f1115f97bf35fb00ab6d23)", - "fs2", - "redb", - "rmp-serde", - "serde", - "serde_bytes", - "serde_json", - "serde_stacker", - "stacker", - "uuid", - "windows-sys 0.59.0", -] - [[package]] name = "cultcache-rs-derive" version = "0.2.0" -source = "git+https://github.com/GameCult/CultLib.git?rev=baf4ecf78fae634fafef956d3b85420162c074bb#baf4ecf78fae634fafef956d3b85420162c074bb" +source = "git+https://github.com/GameCult/CultLib.git?rev=a4eae9056152335662f1115f97bf35fb00ab6d23#a4eae9056152335662f1115f97bf35fb00ab6d23" dependencies = [ "proc-macro2", "quote", @@ -404,7 +404,7 @@ dependencies = [ [[package]] name = "cultcache-rs-derive" version = "0.2.0" -source = "git+https://github.com/GameCult/CultLib.git?rev=a4eae9056152335662f1115f97bf35fb00ab6d23#a4eae9056152335662f1115f97bf35fb00ab6d23" +source = "git+https://github.com/GameCult/CultLib.git?rev=baf4ecf78fae634fafef956d3b85420162c074bb#baf4ecf78fae634fafef956d3b85420162c074bb" dependencies = [ "proc-macro2", "quote", From e011c2aa215d3b55414760ba821bd4fc1eb2594c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 19 Nov 2026 22:40:02 +0100 Subject: [PATCH 06/45] Body map after C2: the persona-only body, stale rows marked, READMEs corrected Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 +- crates/mind-body/README.md | 8 ++- docs/eureka-body-map.md | 116 ++++++++++++++++++++++++++++------- docs/swarm-revival-target.md | 2 + 4 files changed, 103 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 9fea14c..b3e08be 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ edits `.cc` state. Huginn reads and writes minds. ## Layout -A Cargo workspace of five crates (`crates/eureka-pipeline` holds the document shapes and keys, `crates/mind-body` the control store, launch primitive and `mind-heartbeat` timeline; the three below are the mind, the daemon and the client): +A Cargo workspace of five crates (`crates/eureka-pipeline` holds the document shapes and keys, `crates/mind-body` the control store, unit launcher, `mind-heartbeat`, the inert `mind-persona` organ and the `mind-self-run` actuator; the three below are the mind, the daemon and the client): - `crates/huginn-mind`: storage, identity, admission, and queries and derived status over memory documents. diff --git a/crates/mind-body/README.md b/crates/mind-body/README.md index 9645ff1..540da22 100644 --- a/crates/mind-body/README.md +++ b/crates/mind-body/README.md @@ -1,7 +1,7 @@ # mind-body -The Mind's body: the control store, the launch primitive, the `mind-heartbeat` -timeline and the `mind-self-run` actuator. +The Mind's body: the control store, the unit launcher, the `mind-heartbeat`, the +inert `mind-persona` organ and the `mind-self-run` actuator. `mind-self-run --instance [--endpoint rudp://:]` runs inside `mind-self@`. It finds her one open Self run, starts `claude` over @@ -12,7 +12,9 @@ wrong or the mind cannot be reached. ## The heartbeat -`mind-heartbeat` is the one process that decides who wakes and when: each beat falls when the Minds' voted tempo has passed and goes to the Mind that has waited longest, bent by the urgency she declares and a member addressing her; the operator tagging or naming a Persona launches her at once. `mind-heartbeat timeline` prints its latest record. +`mind-heartbeat` is the one process that decides who wakes and when. It starts a Persona's unit and writes no Mind: the beat (`HEARTBEAT_BEAT_S`, default 1800 s) goes to the idle, released Mind that has waited longest, bent by a member addressing her, and the operator or another Mind naming a Persona wakes her at once, once per message. `mind-heartbeat timeline` prints its latest record. + +`mind-persona` is inert: it reads the brakes and exits `dead` or `no organ`. It writes nothing. Nothing launches `mind-self-run`. The actuator has its own ignored test, `the_real_bin_finds_her_run_...` in `tests/self_run.rs`: the real `mind-self-run` against the real daemon with a diff --git a/docs/eureka-body-map.md b/docs/eureka-body-map.md index 506e495..0ec94e9 100644 --- a/docs/eureka-body-map.md +++ b/docs/eureka-body-map.md @@ -99,6 +99,70 @@ and the governance list are added, model-page rows for the session, sandbox, fen set are added, and facts F36-F40 are new. Claims the source note marks as inference or unconfirmed keep that marking here. +Revised 2026-11-19 by Modeling (session `modeling-body-map-after-c2`) at Huginn `66b85c8`, after C2 (PR #75) cut +the mission organ and every Persona-side Mind write. New section "The persona-only body (after C2)", placed before +"Pinned heads", is the current map of the Persona, heartbeat and Self-run rows. Older rows it contradicts carry a +"Superseded by C2" marker; facts F1-F40 and the specs they cite keep their tense. C1 (persona door, PR #74 and +gamecult-ops PR #126) and C3a (Projector, PR #76) are pending, not live. + +## The persona-only body (after C2, Huginn `66b85c8`) + +Modeling, 2026-11-19. Read from source at `66b85c8` (merge of PR #75, cut C2 "cut the mission organ and every Persona-side Mind write"). Design source: Huginn `docs/persona-only-heartbeat-map.md` at `d861574` (Imagination's heartbeat map; read it with `git show d861574:docs/persona-only-heartbeat-map.md`). Governing rulings, admitted 2026-11-19: `eureka-body:ruling:persona-only-heartbeat` (the Persona reads her Mind and never writes it; her own memories live in her persona state), `persona-only-interpreter-agentic`, `persona-only-deltas-from-trace`, `persona-only-divergence-parked` and `persona-only-state-writers-self-and-life`. + +This section is the current map of the Persona, heartbeat, Self-run and Mind-write rows. Where an older row, section or fact below disagrees with it, this section wins; those rows carry a "Superseded by C2" marker and keep their history. The deployed state of `66b85c8` on Yggdrasil was not probed in this pass. The last deploy the design map names is `ecf147d`. + +### The invariant, and what enforces it today + +Nothing that acts for a Persona writes her Mind. At `66b85c8` that holds by absence of callers, not by type: + +- `persona::carry` reads the instance and swarm brakes once and returns `Dead(reason)` or `NoOrgan`. It holds no Mind client, no chat client and no trace writer. The binary `mind-persona` parses the persona flags (`--rooms`, `--operator`, `--minds`, `--self-sender`, and `MIND_PERSONA_*` from `persona.env`), reads the brakes, prints `dead: ...` or `no organ: ...` and exits 0 (2 on bad arguments). It makes no call to the daemon. +- `heartbeat::poll` starts a unit and nothing else. Its only Mind read is `stewardships_of`: one in-force `Stewardship` query per Persona, made only when she has pending chat, to learn the names her projects go by. +- Seam, not yet structural: `MindPort` (`crates/mind-body/src/queue.rs`) still carries `admit`, and each heartbeat `Seat` holds a `&dyn MindPort`. The only non-test caller of `admit` in `mind-body` is `self_run`. "The heartbeat cannot admit" is true of the code and false of the type. The structural cut is C1 (below); until then the test `no_poll_admits_anything_to_any_mind_whatever_it_wakes` is the check. + +### Organs + +| Thing | Owner | Inputs | Outputs | Derived state | Forbidden writers | Shared paths | Cut line | Verification layer | +|---|---|---|---|---|---|---|---|---| +| Persona organ (`mind-persona@`; `crates/mind-body/src/persona.rs`, `src/bin/mind-persona.rs`) | Huginn `mind-body`. Inert: no turn until the three-stage turn (Projector, Persona, Interpreter) lands (C3). | `persona.env` flags; the instance brake and the swarm brake (`control::derive`), read once per start. | One stdout line (`dead` or `no organ`) and an exit status. No Mind write, no persona-state write, no chat, no trace. | None. `Outcome` is `Dead(HeldReason)` or `NoOrgan`. | Everything. It has no write path. | Brake stores `/etc/gamecult/minds//control.cc` and `swarm.cc`, read only. | C2 deleted the session driver, the reply schema, `act`, the run opener and every admit (parked at `parked/self-run-launch`). It kept `Config`, `sender_role`, `addressees`, `addressing_of`, `render_tail` and `FileTrace` for C3; each unused item carries an `allow(dead_code)` that its first caller removes. | `persona/tests.rs` (`a_held_brake_is_dead_and_a_released_one_has_no_organ`); `tests/persona_bin.rs` (a unit configured from its environment ends dead; a missing or wrong setting ends 2 naming the setting, never the value); `tests/public_surface.txt`. | +| Heartbeat (`mind-heartbeat.service`; `heartbeat.rs`, `tempo.rs`, `bin/mind-heartbeat.rs`) | Huginn `mind-body`. The one process deciding which Persona wakes and when. Sole writer of `heartbeat.cc`. | Swarm envelope and each Persona's brake (`read_effective`); each Persona's pending chat from Bifrost's mouth (`chat.pending`, read only, never acked, at most 16 pages); the unit table through `Launcher::alive`; `stewardships_of` on her Mind; `HEARTBEAT_PERSONAS`, `MIND_PERSONA_OPERATOR`, `HEARTBEAT_POLL_S` (20), `HEARTBEAT_BEAT_S` (1800), `BIFROST_CHAT_ENDPOINT`, `BIFROST_CHAT_KEY_FILE`, `STATE_DIRECTORY`. It holds no connector key. | `systemctl start mind-persona@` through `SystemdLauncher`; `heartbeat.cc` (state, addressing table, poll traces). No run, no brief, no Self-run launch. | Off the beat: the operator, or another Mind of the roster, naming her wakes her once per message (`handled_mentions`, 64 kept). On the beat: when `beat_s` has passed since `last_beat_at`, `tempo::pick` over idle, released Minds by wait since the heartbeat last woke each, bent by a member addressing her. Busy is systemd's: an active unit is busy and a start is a no-op. | Her Mind (a Persona wake is a unit start); `heartbeat.cc` by anything but the heartbeat; the brakes. | `heartbeat.cc` under the unit's `STATE_DIRECTORY`, world-readable: Personas read the addressing table through `HeartbeatView`. `mind-heartbeat timeline` prints the latest poll. | C2 deleted the claimable-brief and Self-run branch, tempo votes and the PID fallback (`tally`, `fallback_beat`), the urgency pulse, `sleep.rs` (no night wake until C4) and `attachment.rs`. It kept `tempo::pick` and `score`. `vote_beat_s` in `InstanceTrace` is retired and always none, kept so old trace records decode. A `heartbeat.cc` holding an older document is refused by name and never migrated. | `heartbeat/tests.rs`: `a_mind_whose_self_holds_briefs_gets_a_persona_wake_and_no_self_run`, `no_poll_admits_anything_to_any_mind_whatever_it_wakes`, the mention and beat tests. | +| Self-run actuator (`mind-self@`; `self_run.rs`, `bin/mind-self-run.rs`) | Huginn `mind-body`. Carries the one in-force Self run of its instance. | The run document (the grant), the lease socket, the Mind, the clock. | One `claude` child, its flush, its stop. | Request prefix, session id (UUIDv5 of the run id), kept transcript. | Nothing launches it. `launch::open_and_launch`, the work queue and the repetition breaker are gone (tag `parked/self-run-launch`). No organ opens a Self run, so `mind-self-run` with no open run exits 3. | The run slot in the Mind; `/var/lib/gamecult/minds//` state. | Left in place on purpose (C2 keep list): C3b's Interpreter reuses its spawn and sandbox and `lease_client`. `inbox` still reads briefs admitted by agent `mind-persona`; nothing admits them now. | `tests/self_run.rs` (ignored lane: the real binary against the real daemon with a fake `claude`); `self_run/tests.rs`. | +| Persona state (`gamecult.persona_state.v0`, one per mind, `personaId` = instance) | The Persona. No organ of Huginn writes it today. Target writers (ruling `persona-only-state-writers-self-and-life`): her commit step (C3c), and Self and Life on Starfire through `mind-persona edit`. | `PersonaGet`, `PersonaPut` on the daemon. | A receipt per put. | None stored. | The Projector, the Persona stage and the Interpreter never put. A raw `huginn persona put` is detected and recorded `unexplained`, not sanctioned. | The Mind store; the persona door once C1 lands. | `huginn-mind/src/persona.rs` keeps the document and its CAS. C2 removed the organ that was its only writer. | `huginn-mind` persona tests. The target's host negative check belongs to C1. | +| Persona turn trace (`eureka.persona.turn_trace.v1`, `FileTrace`) | The Persona organ, when C3 lands. | Nothing writes it today. | None. | None. | Any Mind writer; any model. | The unit's state directory. | Kept for C3c (trace v2 with `outside_put` and `tuning_changed`). Deltas are read from it over ssh (`persona-only-deltas-from-trace`). | `persona/tests.rs` `the_trace_store_keeps_each_turn_under_its_run_and_turn`. | +| Brake and the stop on hold | Operator. `mind-control brake hold` writes the brake, then stops the instance's units. | The operator's word. | `control.cc`; a blocking `systemctl stop`. | `read_effective` is the one reader. | Every organ of hers. | `/etc/gamecult/minds//`, `swarm.cc`. | `StopScope` still names three templates: `mind-self@`, `mind-persona@` and `mind-stream@`. The stream organ is parked; its unit name stays on the stop list so a host that still has it installed is stopped. | `tests/cli.rs` and the `launch.rs` stop tests (they spell `mind-stream@`). | +| Parked and deleted organs | Tags on the forge, not main. | n/a | n/a | n/a | Main must not regrow them without a ruling. | n/a | `parked/divergence-stream` holds `stream.rs` and `bin/mind-stream` (ruling `persona-only-divergence-parked`; return condition: measured narrations converge, judged by the eval of the design map's section 3.4; its Projector code is reused by C3a). `parked/self-run-launch` holds `open_and_launch`, the work queue and its breaker (a future spend owner may restore Self runs on address). `sleep.rs` and `attachment.rs` are deleted, not parked: consolidation returns in C4 as a retarget onto `thoughtMemory`. | The C2 negative greps: `start_self_run`, `WORK_QUESTION`, `WAKE_ASK`, `TURN_INSTRUCTION`, `Pulse`, `tempo_vote` absent from `crates/mind-body/src`. | + +### What touches the Mind now + +| Process | Reads | Writes | +|---|---|---| +| `mind-persona` | nothing | nothing | +| `mind-heartbeat` | `Stewardship` documents of each Persona with pending chat | nothing | +| `mind-self-run` | its run, briefs, the Mind | what a Self session admits (unchanged); nothing starts one | +| Self on Starfire | all | the Mind, and persona state through `mind-persona edit` (target; the subcommand is C3c) | + +### Pending, not live + +- **C1, the persona door** (Huginn PR #74 and gamecult-ops PR #126, not merged). Target per the design map: a read-and-own-persona-only listener at the huginn port + 1000 that refuses `Admit`, and an nft fence change that routes Persona uids only to it. Until both merge and deploy, the Persona uid's route to the full door is unchanged. Do not read C1 as live. +- **C3a, the Projector** (Huginn PR #76, not merged). Select stage, Projector, `persona-tuning.toml` and `mind-persona project`. Until it merges, `mind-persona` has no `project` subcommand. +- **C3b, C3c, C4, C5, C6** are follow-ups in the design map: the Persona stage and Interpreter; the commit and `edit`; reflection and consolidation; the delta reader `mind-persona since`; identity diff posting. Nothing in main implements them. + +### Stale surfaces found in this pass + +Fixed here: + +- `docs/eureka-body-map.md`: the rows and sections marked "Superseded by C2" (the model page, the units table, the Persona session section and its table, the tempo controller row, and the sections on the live-run decider, the breaker and the Self run). Markers are prefixes; the old text under them was not rewritten. +- `docs/swarm-revival-target.md`: status banner added. +- `crates/mind-body/README.md`: the heartbeat paragraph described voted tempo, declared urgency and an immediate launch, and the intro omitted the Persona organ. +- `README.md` (repo root): the layout line named `mind-heartbeat` timeline as `mind-body`'s only organ; it now names the live organs. + +Listed, not fixed: + +- `crates/mind-body/src/launch.rs` stop templates and tests still spell `mind-stream@`. Intended; see the Brake row. +- `docs/chat-retrieval-map.md`: describes Persona turns, a Persona shell and `huginn sources` as the Persona's lookup. The Persona has no turn and no shell now; the Interpreter's read tools are the future owner (`persona-only-interpreter-agentic`). +- `docs/eureka-self-cut.md`, `docs/eureka-substrate-map.md`, `docs/prose-knowledge-target.md`, `docs/eureka-substrate-target.md`, `docs/desk-feed-door.md`: mention the Persona organ, persona state or the waker as of their own dates; not rewritten. `prose-knowledge-target.md` says persona state is "rewritten by its own Persona turns"; no writer exists until C3c. +- `docs/research/2026-11-02-persona-*`, `2026-11-03-persona-projector-facts.md`, `2026-11-02-soul-queue-and-one-shot-trace.md`, `2026-10-31-live-mind-sessions-sequence.md`, `2026-11-01-tempo-pid-sim.md`: dated research on the deleted session, queue and PID controller. Evidence, not maps. +- gamecult-ops (not read in this pass): the installed `mind-persona@.service` and its drop-ins, `persona.env`, `MIND_PERSONA_DOCTRINE`, the `persona-seed`, any `mind-stream@` template, and `HEARTBEAT_CLASSIFIER_MODEL` or `MIND_CONNECTOR_*` in the heartbeat unit's environment describe a Persona that no longer runs. `mind-heartbeat` reads none of the connector or classifier variables. + ## Pinned heads (fetched 2026-10-08 ~12:10 UTC) | Repo | Ref | Commit | Note | @@ -518,25 +582,25 @@ pipeline kinds are in Huginn `docs/eureka-substrate-map.md`. | --- | --- | --- | --- | | Pipeline wire ids | `epiphany.pipeline..v2`, epoch `epiphany.pipeline.epoch.v2`, defined by the leaf, the Huginn crate `crates/eureka-pipeline` (lib `eureka_pipeline`), ids unchanged. | Renamed once to `eureka.pipeline..v3` by one `mind.redb` migration, at the next breaking leaf change or before the first hosted mind (ruling `wire-names-rename-before-hosting`). Adding the `run` kind or the `Mind` authority variant is additive (old stored documents decode; no migration), so it does not trigger the rename; a field added with the leaf's `= absent` marker is additive too (leaf-read-anchors r2: old bytes decode, empty fields encode byte-identically, `golden/envelopes.txt` gains lines and loses none); a field added any other way would. | Huginn owns the leaf. The migration is a live-mind upgrade, which is the operator's (`mind-rules-which-forks`). | | Leaf crate and schema catalogue | Huginn `crates/eureka-pipeline`, `schemas/cultnet/` (13 pipeline schemas, `gamecult.persona_state.v0`, index, README). `epiphany.work_organ_state.v0` dies: no reader outside Epiphany (grep, F1/F3). | Landed at Huginn `afc35f9` (leaf-into-huginn). Wire pinned by `crates/eureka-pipeline/golden/envelopes.txt` and huginn-mind's opt-in `query::tests::stored_documents_read_back`. Huginn is AGPL-3.0-only (ruling `eureka-body:ruling:leaf-relicensed-agpl`). | Huginn. Forbidden: any Cargo source resolving into GameCult/Epiphany (`nothing-runs-from-epiphany`). | -| `run` | `:run: