Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/continuum-persona-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description = "The persona engine (CONTINUUM-ENGINE 4.14): one mind decodes at a

[dependencies]
uuid.workspace = true
futures.workspace = true
thiserror.workspace = true

[lints.clippy]
Expand Down
7 changes: 6 additions & 1 deletion core/continuum-persona-engine/src/persona.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
//! A persona's execution state, owned once and moved only whole.

mod id;
mod lifecycle;
mod unit;

pub use id::{Epoch, PersonaId};
pub use unit::{PersonaParts, PersonaUnit, PartialMove};
pub use lifecycle::{Lifecycle, PersonaParts, Preservation, Suspension};
pub use unit::{PersonaUnit, PartialMove};

#[cfg(test)]
mod lifecycle_tests;
60 changes: 60 additions & 0 deletions core/continuum-persona-engine/src/persona/lifecycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Each owner suspends its children and returns their preservation results.
use std::future::Future;

/// Repeated suspension must preserve the same state. The owner retains custody on
/// cancellation and on refusal. A poll must yield promptly while I/O or GPU work is pending. Implementations can return a nested child report.
pub trait Lifecycle {
type Suspension: Suspension;
fn suspend(&mut self) -> impl Future<Output = Self::Suspension> + Send;
}

pub trait Suspension {
fn is_preserved(&self) -> bool;
}

#[derive(Debug, PartialEq, Eq)]
pub enum Preservation<P, E> {
Preserved,
Pending(P),
Failed(E),
}

impl<P, E> Suspension for Preservation<P, E> {
fn is_preserved(&self) -> bool {
matches!(self, Self::Preserved)
}
}

// One declaration supplies the owned fields, traversal, and typed report shape.
macro_rules! persona_parts {
($($field:ident: $part:ident),+ $(,)?) => {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PersonaParts<$($part),+> {
$(pub $field: $part),+
}

impl<$($part: Lifecycle + Send),+> Lifecycle for PersonaParts<$($part),+>
where $($part::Suspension: Send),+
{
type Suspension = PersonaParts<$($part::Suspension),+>;
async fn suspend(&mut self) -> Self::Suspension {
let ($($field,)+) = futures::join!($(self.$field.suspend()),+);
PersonaParts { $($field),+ }
}
}

impl<$($part: Suspension),+> Suspension for PersonaParts<$($part),+> {
fn is_preserved(&self) -> bool {
$(self.$field.is_preserved())&&+
}
}
};
}

persona_parts! {
blocks: Blocks,
tokens: Tokens,
genome: Genome,
learning: Learning,
decode: Decode,
}
94 changes: 94 additions & 0 deletions core/continuum-persona-engine/src/persona/lifecycle_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use super::*;
use futures::executor::block_on;

struct Part {
release_after_retry: bool,
failure: bool,
attempts: usize,
}

impl Part {
fn ready() -> Self {
Self { release_after_retry: false, failure: false, attempts: 0 }
}
}

impl Lifecycle for Part {
type Suspension = Preservation<u64, &'static str>;

async fn suspend(&mut self) -> Self::Suspension {
self.attempts += 1;
if self.failure {
Preservation::Failed("storage unavailable")
} else if self.release_after_retry && self.attempts == 1 {
Preservation::Pending(17)
} else {
Preservation::Preserved
}
}
}

#[test]
fn root_reports_pending_and_failed_children_and_keeps_custody_for_retry() {
let mut parts = PersonaParts {
blocks: Part::ready(),
tokens: Part::ready(),
genome: Part::ready(),
learning: Part { release_after_retry: true, ..Part::ready() },
decode: Part::ready(),
};
parts.tokens.failure = true;
let mut persona = PersonaUnit::new(PersonaId(uuid::Uuid::nil()), Epoch(1), parts);
let report = block_on(persona.suspend());
assert_eq!(report.tokens, Preservation::Failed("storage unavailable"));
assert_eq!(report.learning, Preservation::Pending(17));
assert!(report.decode.is_preserved());
assert!(!report.is_preserved());

let retried = block_on(persona.suspend());
assert!(retried.learning.is_preserved());
assert!(!retried.is_preserved());
assert_eq!(persona.parts().learning.attempts, 2);
}

#[test]
fn one_pending_fence_leaves_all_siblings_free_to_start() {
use futures::channel::oneshot;
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};

struct Gated {
started: Arc<AtomicUsize>,
fence: oneshot::Receiver<()>,
}
impl Lifecycle for Gated {
type Suspension = Preservation<(), oneshot::Canceled>;

async fn suspend(&mut self) -> Self::Suspension {
self.started.fetch_add(1, Ordering::SeqCst);
match (&mut self.fence).await {
Ok(()) => Preservation::Preserved,
Err(error) => Preservation::Failed(error),
}
}
}

let started = Arc::new(AtomicUsize::new(0));
let mut signals = Vec::new();
let mut part = || {
let (signal, fence) = oneshot::channel();
signals.push(signal);
Gated { started: started.clone(), fence }
};
let mut persona = PersonaUnit::new(PersonaId(uuid::Uuid::nil()), Epoch(1), PersonaParts {
blocks: part(), tokens: part(), genome: part(), learning: part(), decode: part(),
});
block_on(async {
let mut suspend = Box::pin(persona.suspend());
assert!(futures::poll!(&mut suspend).is_pending());
assert_eq!(started.load(Ordering::SeqCst), 5);
for signal in signals.into_iter().rev() {
assert!(signal.send(()).is_ok());
}
assert!(suspend.await.is_preserved());
});
}
23 changes: 12 additions & 11 deletions core/continuum-persona-engine/src/persona/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

use super::{Epoch, PersonaId};

/// Her five parts (4.14 "The object design"): execution blocks, token history, the genome
/// generation her decode binds, learning custody, decode state (drafts, sampler, rollback).
/// Generic so each part is the native handle in the engine and a plain value in a contract test.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PersonaParts<Blocks, Tokens, Genome, Learning, Decode> {
pub blocks: Blocks,
pub tokens: Tokens,
pub genome: Genome,
pub learning: Learning,
pub decode: Decode,
}
use super::{Lifecycle, PersonaParts};

/// A part was missing from a move: the unit is refused whole, never assembled from pieces.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
Expand Down Expand Up @@ -78,3 +68,14 @@ impl<B, T, G, L, D> PersonaUnit<B, T, G, L, D> {
self.parts
}
}

impl<B, T, G, L, D> Lifecycle for PersonaUnit<B, T, G, L, D>
where
PersonaParts<B, T, G, L, D>: Lifecycle + Send,
{
type Suspension = <PersonaParts<B, T, G, L, D> as Lifecycle>::Suspension;

async fn suspend(&mut self) -> Self::Suspension {
self.parts.suspend().await
}
}
5 changes: 3 additions & 2 deletions tools/scripts/tests/ci-change-scope.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const select = (...paths) => {
// Tested crates a kernel change does not reach: the floor (base, host, git, service, saved-state) and
// the leaves that depend on nothing in the workspace (the codec continuum-context, the flow
// continuum-flow, the proving ground's types continuum-proving-types).
const BELOW_KERNEL = ['continuum-base', 'continuum-host', 'continuum-git', 'continuum-service', 'continuum-saved-state', 'continuum-context', 'continuum-flow', 'continuum-proving-types'];
const BELOW_KERNEL = ['continuum-base', 'continuum-host', 'continuum-git', 'continuum-service', 'continuum-saved-state', 'continuum-context', 'continuum-flow', 'continuum-proving-types', 'continuum-persona-engine'];

test('installer repairs run installer checks without unrelated Rust builds', () => {
for (const file of ['install.ps1', 'tools/scripts/lib/install-common.ps1', 'tools/scripts/lib/win-modules.ps1', 'tools/scripts/lib/win-engine.ps1', 'tools/scripts/lib/windows-engine-receipt.ps1', 'tools/scripts/lib/windows-service.ps1', 'tools/scripts/lib/windows-media-reconciliation.ps1', 'tools/scripts/lib/windows-elevation.ps1', 'tools/scripts/tests/windows-process.test.ps1', 'tools/scripts/tests/windows-airc-download.test.ps1', 'tools/scripts/tests/windows-xz.test.ps1', 'tools/scripts/sync-windows-bootstrap.ps1'])
Expand Down Expand Up @@ -148,10 +148,11 @@ test('a crate-local change runs that crate and every crate that depends on it',
const belowMind = crates('continuum-engine', 'continuum-vitals', 'continuum-prompt', 'continuum-engram', 'continuum-capture', 'continuum-embedding', 'continuum-store', 'continuum-models', 'continuum-hands', 'continuum-live', 'continuum-perception', 'continuum-genome', 'continuum-memory', 'continuum-cognition', 'continuum-academy', 'continuum-sentinel', 'continuum-mind', 'continuum-dreaming', 'continuum-grid', 'continuum-serving', 'continuum-core', 'continuum-gateway');
assert.deepEqual(scope(['core/continuum-engine/src/lib.rs']), belowMind);
// The floor crates (base, host, git) sit below the kernel: a kernel change runs everything above them.
assert.deepEqual(scope(['core/continuum-persona-engine/src/persona/unit.rs']), crates('continuum-persona-engine'));
const aboveFloor = TESTED_CRATES.filter(n => !BELOW_KERNEL.includes(n));
assert.deepEqual(scope(['core/continuum-kernel/src/lib.rs']), { crates: aboveFloor, cli: false });
// A floor change runs the floor crate and every crate built on it.
assert.deepEqual(scope(['core/continuum-host/src/durable/mod.rs']), { crates: TESTED_CRATES.filter(n => !['continuum-base', 'continuum-service', 'continuum-context', 'continuum-flow', 'continuum-proving-types'].includes(n)), cli: true });
assert.deepEqual(scope(['core/continuum-host/src/durable/mod.rs']), { crates: TESTED_CRATES.filter(n => !['continuum-base', 'continuum-service', 'continuum-context', 'continuum-flow', 'continuum-proving-types', 'continuum-persona-engine'].includes(n)), cli: true });
// continuum-git is used by hands (a citizen's git) and core (the deploy tree): both run, and every crate above hands.
assert.deepEqual(scope(['core/continuum-git/src/index_lock.rs']), crates('continuum-git', 'continuum-hands', 'continuum-cognition', 'continuum-academy', 'continuum-mind', 'continuum-dreaming', 'continuum-grid', 'continuum-serving', 'continuum-core'));
// Untested crates reach the tested ones through the graph: llama -> engine -> ...
Expand Down
Loading