Delete unused semantic projection subsystem
This commit is contained in:
parent
b33244bee4
commit
856648decc
41 changed files with 72 additions and 32866 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,301 +0,0 @@
|
|||
use anyhow::{Context, Result, anyhow};
|
||||
use epiphany_core::{
|
||||
EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshDaemonHeartbeatEventEntry, EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry,
|
||||
MemorySemanticIndexConfig, MemorySemanticProjectionInput, MemorySemanticProjectorPulseStatus,
|
||||
SemanticProjectorServiceBody, authenticate_epiphany_cultmesh_semantic_projector_launch,
|
||||
authorize_memory_semantic_physical_retirements, execute_memory_semantic_physical_retirement,
|
||||
load_epiphany_cultmesh_daemon_service_lifecycle_receipt,
|
||||
publish_epiphany_cultmesh_semantic_projection_health,
|
||||
retain_memory_semantic_projection_lifecycles, write_epiphany_cultmesh_daemon_heartbeat_event,
|
||||
};
|
||||
use serde_json::json;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use uuid::Uuid;
|
||||
|
||||
const DAEMON_ID: &str = "epiphany-memory-semantic-projector";
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
if args.requires_managed_launch {
|
||||
if args.startup_lifecycle_receipt_id.trim().is_empty() {
|
||||
return Err(anyhow!(
|
||||
"managed projector requires its startup launch receipt id"
|
||||
));
|
||||
}
|
||||
let receipt = authenticate_managed_launch(&args)?;
|
||||
if receipt.process_id != Some(std::process::id()) {
|
||||
return Err(anyhow!(
|
||||
"managed projector process disagrees with its launch receipt"
|
||||
));
|
||||
}
|
||||
let executable = env::current_exe().context("failed to resolve projector executable")?;
|
||||
let executable_sha256 = format!(
|
||||
"sha256-{:x}",
|
||||
Sha256::digest(fs::read(&executable).with_context(|| {
|
||||
format!(
|
||||
"failed to fingerprint projector executable {}",
|
||||
executable.display()
|
||||
)
|
||||
})?)
|
||||
);
|
||||
if receipt.executable_sha256 != executable_sha256 {
|
||||
return Err(anyhow!(
|
||||
"managed projector executable disagrees with its launch receipt"
|
||||
));
|
||||
}
|
||||
}
|
||||
let mut semantic_config = MemorySemanticIndexConfig::from_env();
|
||||
semantic_config.qdrant_url = args.qdrant_url.clone();
|
||||
semantic_config.ollama_base_url = args.ollama_base_url.clone();
|
||||
semantic_config.ollama_model = args.ollama_model.clone();
|
||||
let projector =
|
||||
SemanticProjectorServiceBody::new(&args.runtime_store, semantic_config.clone())?;
|
||||
let provider_incarnation = projector.provider_incarnation().to_string();
|
||||
let mut sequence = 0_u64;
|
||||
loop {
|
||||
sequence = sequence.saturating_add(1);
|
||||
let pulse = projector.pulse();
|
||||
let outcome = pulse.outcome;
|
||||
let inputs = pulse.inputs;
|
||||
let source_faults = pulse.source_fault_count;
|
||||
let mut retention_faults = Vec::new();
|
||||
let mut retention_mutation_count = 0_u32;
|
||||
for input in &inputs {
|
||||
let store = source_store(&args, input)?;
|
||||
match authorize_memory_semantic_physical_retirements(
|
||||
store,
|
||||
input,
|
||||
args.retained_generations,
|
||||
&chrono::Utc::now().to_rfc3339(),
|
||||
) {
|
||||
Ok(retirements) => {
|
||||
for retirement in retirements {
|
||||
if let Err(error) = execute_memory_semantic_physical_retirement(
|
||||
store,
|
||||
input,
|
||||
&retirement.retirement_id,
|
||||
&semantic_config,
|
||||
&chrono::Utc::now().to_rfc3339(),
|
||||
) {
|
||||
retention_faults.push(format!(
|
||||
"{} physical: {error:#}",
|
||||
input.obligation().partition
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => retention_faults.push(format!(
|
||||
"{} physical authorization: {error:#}",
|
||||
input.obligation().partition
|
||||
)),
|
||||
}
|
||||
match retain_memory_semantic_projection_lifecycles(
|
||||
store,
|
||||
input,
|
||||
args.retained_generations,
|
||||
&chrono::Utc::now().to_rfc3339(),
|
||||
) {
|
||||
Ok(Some(_)) => retention_mutation_count += 1,
|
||||
Ok(None) => {}
|
||||
Err(error) => {
|
||||
retention_faults.push(format!("{}: {error:#}", input.obligation().partition))
|
||||
}
|
||||
}
|
||||
}
|
||||
let retention_fault_count = retention_faults.len() as u32;
|
||||
let mut health_publication_faults = Vec::new();
|
||||
for input in &inputs {
|
||||
let store = source_store(&args, input)?;
|
||||
if let Err(error) = publish_epiphany_cultmesh_semantic_projection_health(
|
||||
&args.local_verse_store,
|
||||
args.runtime_id.clone(),
|
||||
store,
|
||||
input,
|
||||
&provider_incarnation,
|
||||
) {
|
||||
health_publication_faults
|
||||
.push(format!("{}: {error:#}", input.obligation().partition));
|
||||
}
|
||||
}
|
||||
let health_faults = health_publication_faults.len() as u32;
|
||||
let degraded = source_faults > 0
|
||||
|| retention_fault_count > 0
|
||||
|| health_faults > 0
|
||||
|| matches!(
|
||||
outcome.status,
|
||||
MemorySemanticProjectorPulseStatus::Contended
|
||||
| MemorySemanticProjectorPulseStatus::Refused
|
||||
);
|
||||
let heartbeat = write_epiphany_cultmesh_daemon_heartbeat_event(
|
||||
&args.local_verse_store,
|
||||
args.runtime_id.clone(),
|
||||
EpiphanyCultMeshDaemonHeartbeatEventEntry {
|
||||
schema_version: EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION.to_string(),
|
||||
heartbeat_id: Uuid::new_v4().to_string(),
|
||||
daemon_id: DAEMON_ID.to_string(),
|
||||
cluster_id: "local".to_string(),
|
||||
provider_incarnation: provider_incarnation.clone(),
|
||||
sequence,
|
||||
status: if degraded { "degraded" } else { "ready" }.to_string(),
|
||||
heartbeat_at: chrono::Utc::now().to_rfc3339(),
|
||||
private_state_exposed: false,
|
||||
startup_lifecycle_receipt_id: args.startup_lifecycle_receipt_id.clone(),
|
||||
},
|
||||
)?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string(&json!({
|
||||
"schemaVersion": "epiphany.memory_semantic_projector_pulse.v0",
|
||||
"pulseSequence": sequence,
|
||||
"providerIncarnation": provider_incarnation,
|
||||
"heartbeatId": heartbeat.heartbeat_id,
|
||||
"providerStatus": heartbeat.status,
|
||||
"pulseStatus": pulse_status(outcome.status),
|
||||
"inspectedSourceCount": outcome.inspections.len(),
|
||||
"sourceFaultCount": source_faults,
|
||||
"retentionMutationCount": retention_mutation_count,
|
||||
"retentionFaultCount": retention_fault_count,
|
||||
"retentionFaults": retention_faults,
|
||||
"healthPublicationFaultCount": health_faults,
|
||||
"healthPublicationFaults": health_publication_faults,
|
||||
"selectedScopeId": outcome.selected_scope_id,
|
||||
"privateStateExposed": false,
|
||||
"authoritative": false
|
||||
}))?
|
||||
);
|
||||
if args.max_iterations != 0 && sequence >= args.max_iterations {
|
||||
break;
|
||||
}
|
||||
thread::sleep(Duration::from_secs(args.interval_seconds));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn authenticate_managed_launch(
|
||||
args: &Args,
|
||||
) -> Result<EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry> {
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
loop {
|
||||
if load_epiphany_cultmesh_daemon_service_lifecycle_receipt(
|
||||
&args.local_verse_store,
|
||||
args.runtime_id.clone(),
|
||||
&args.startup_lifecycle_receipt_id,
|
||||
)?
|
||||
.is_some()
|
||||
{
|
||||
return authenticate_epiphany_cultmesh_semantic_projector_launch(
|
||||
&args.local_verse_store,
|
||||
args.runtime_id.clone(),
|
||||
&args.startup_lifecycle_receipt_id,
|
||||
);
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
return Err(anyhow!(
|
||||
"managed projector startup launch receipt was not persisted"
|
||||
));
|
||||
}
|
||||
thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
}
|
||||
|
||||
fn source_store<'a>(args: &'a Args, input: &MemorySemanticProjectionInput) -> Result<&'a PathBuf> {
|
||||
match input.obligation().partition.as_str() {
|
||||
"modeling" => Ok(&args.runtime_store),
|
||||
other => Err(anyhow!(
|
||||
"unsupported semantic projection partition {other:?}"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn pulse_status(status: MemorySemanticProjectorPulseStatus) -> &'static str {
|
||||
match status {
|
||||
MemorySemanticProjectorPulseStatus::Idle => "idle",
|
||||
MemorySemanticProjectorPulseStatus::Executed => "executed",
|
||||
MemorySemanticProjectorPulseStatus::Contended => "contended",
|
||||
MemorySemanticProjectorPulseStatus::Refused => "refused",
|
||||
MemorySemanticProjectorPulseStatus::Busy => "busy",
|
||||
}
|
||||
}
|
||||
|
||||
struct Args {
|
||||
runtime_store: PathBuf,
|
||||
local_verse_store: PathBuf,
|
||||
runtime_id: String,
|
||||
interval_seconds: u64,
|
||||
max_iterations: u64,
|
||||
retained_generations: usize,
|
||||
startup_lifecycle_receipt_id: String,
|
||||
qdrant_url: String,
|
||||
ollama_base_url: String,
|
||||
ollama_model: String,
|
||||
requires_managed_launch: bool,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut values = env::args().skip(1);
|
||||
let command = values.next().unwrap_or_else(|| "pulse".to_string());
|
||||
if !matches!(command.as_str(), "pulse" | "once" | "serve" | "daemon") {
|
||||
return Err(anyhow!("unknown command {command:?}; use pulse or serve"));
|
||||
}
|
||||
let mut runtime_store = None;
|
||||
let mut local_verse_store = None;
|
||||
let mut runtime_id = "epiphany-local".to_string();
|
||||
let mut interval_seconds = 60_u64;
|
||||
let mut max_iterations = if matches!(command.as_str(), "pulse" | "once") {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let mut retained_generations = 256_usize;
|
||||
let mut qdrant_url = None;
|
||||
let mut ollama_base_url = None;
|
||||
let mut ollama_model = "qwen3-embedding:0.6b".to_string();
|
||||
while let Some(flag) = values.next() {
|
||||
let mut value = || {
|
||||
values
|
||||
.next()
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
};
|
||||
match flag.as_str() {
|
||||
"--runtime-store" => runtime_store = Some(PathBuf::from(value()?)),
|
||||
"--local-verse-store" => local_verse_store = Some(PathBuf::from(value()?)),
|
||||
"--runtime-id" => runtime_id = value()?,
|
||||
"--interval-seconds" => interval_seconds = value()?.parse()?,
|
||||
"--max-iterations" => max_iterations = value()?.parse()?,
|
||||
"--retained-generations" => retained_generations = value()?.parse()?,
|
||||
"--qdrant-url" => qdrant_url = Some(value()?),
|
||||
"--ollama-base-url" => ollama_base_url = Some(value()?),
|
||||
"--ollama-model" => ollama_model = value()?,
|
||||
_ => return Err(anyhow!("unexpected argument {flag:?}")),
|
||||
}
|
||||
}
|
||||
if interval_seconds == 0 {
|
||||
return Err(anyhow!("--interval-seconds must be positive"));
|
||||
}
|
||||
if retained_generations == 0 {
|
||||
return Err(anyhow!("--retained-generations must be positive"));
|
||||
}
|
||||
Ok(Self {
|
||||
runtime_store: runtime_store.context("missing --runtime-store")?,
|
||||
local_verse_store: local_verse_store.context("missing --local-verse-store")?,
|
||||
runtime_id,
|
||||
interval_seconds,
|
||||
max_iterations,
|
||||
retained_generations,
|
||||
startup_lifecycle_receipt_id: env::var("EPIPHANY_STARTUP_LIFECYCLE_RECEIPT_ID")
|
||||
.unwrap_or_default(),
|
||||
qdrant_url: qdrant_url.context("missing --qdrant-url")?,
|
||||
ollama_base_url: ollama_base_url.context("missing --ollama-base-url")?,
|
||||
ollama_model,
|
||||
requires_managed_launch: matches!(command.as_str(), "serve" | "daemon"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
use anyhow::{Context, Result, anyhow};
|
||||
use epiphany_core::{
|
||||
EpiphanyMemoryContextQuery, EpiphanyMemoryGraphSnapshot, MemorySemanticIndexConfig,
|
||||
MemorySemanticProjectionInput, WORKSPACE_COVERAGE_MAXIMUM_FILE_BYTES,
|
||||
WorkspaceCoveragePolicy, WorkspaceProjectionIdentity,
|
||||
load_memory_semantic_projection_readiness, observe_repository_readiness,
|
||||
publish_epiphany_cultmesh_semantic_projection_health,
|
||||
runtime_modeling_semantic_projection_input, semantic_memory_context,
|
||||
};
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut args = env::args().skip(1);
|
||||
let command = args.next().ok_or_else(|| usage_error("missing command"))?;
|
||||
let options = Options::parse(args)?;
|
||||
let config = MemorySemanticIndexConfig::from_env();
|
||||
match command.as_str() {
|
||||
"health" => {
|
||||
let (input, source_store) = options.load_projection_input()?;
|
||||
let verse_store = options
|
||||
.local_verse_store
|
||||
.as_ref()
|
||||
.ok_or_else(|| usage_error("health requires --local-verse-store <path>"))?;
|
||||
let health = publish_epiphany_cultmesh_semantic_projection_health(
|
||||
verse_store,
|
||||
options.runtime_id.clone(),
|
||||
source_store,
|
||||
&input,
|
||||
options.provider_incarnation()?,
|
||||
)?;
|
||||
print_semantic_health(&health)?;
|
||||
}
|
||||
"context" => {
|
||||
let (snapshot, swarm_id) = options.load_source()?;
|
||||
let text = options
|
||||
.text
|
||||
.clone()
|
||||
.ok_or_else(|| usage_error("context requires --text <query>"))?;
|
||||
let projection_input = options.load_projection_input().ok().map(|(input, _)| input);
|
||||
let readiness = match (&projection_input, options.source_store()) {
|
||||
(Some(input), Some(store)) => {
|
||||
load_memory_semantic_projection_readiness(store, input)?
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let packet = semantic_memory_context(
|
||||
&snapshot,
|
||||
&swarm_id,
|
||||
&EpiphanyMemoryContextQuery {
|
||||
id: options
|
||||
.query_id
|
||||
.clone()
|
||||
.unwrap_or_else(|| "memory-semantic-context".to_string()),
|
||||
profile: options.profile,
|
||||
text: Some(text),
|
||||
budget: options.budget,
|
||||
..Default::default()
|
||||
},
|
||||
readiness.as_ref(),
|
||||
&config,
|
||||
);
|
||||
print_json(&packet)?;
|
||||
}
|
||||
"repository-readiness" => {
|
||||
let runtime_store = options.runtime_store.as_ref().ok_or_else(|| {
|
||||
usage_error("repository-readiness requires --runtime-store <path>")
|
||||
})?;
|
||||
let workspace_identity = WorkspaceProjectionIdentity {
|
||||
policy: WorkspaceCoveragePolicy::bounded_regular_files_v0(
|
||||
WORKSPACE_COVERAGE_MAXIMUM_FILE_BYTES,
|
||||
)?,
|
||||
qdrant_url: config.qdrant_url.clone(),
|
||||
qdrant_api_key: config.qdrant_api_key.clone(),
|
||||
qdrant_timeout_ms: config.qdrant_timeout_ms,
|
||||
embedding_provider_id: options.workspace_embedding_provider_id.clone().ok_or_else(
|
||||
|| {
|
||||
usage_error(
|
||||
"repository-readiness requires --workspace-embedding-provider-id <id>",
|
||||
)
|
||||
},
|
||||
)?,
|
||||
embedding_model: options.workspace_embedding_model.clone().ok_or_else(|| {
|
||||
usage_error("repository-readiness requires --workspace-embedding-model <model>")
|
||||
})?,
|
||||
vector_dimensions: options.workspace_vector_dimensions.ok_or_else(|| {
|
||||
usage_error("repository-readiness requires --workspace-vector-dimensions <n>")
|
||||
})?,
|
||||
};
|
||||
print_json(&observe_repository_readiness(
|
||||
runtime_store,
|
||||
&config,
|
||||
&workspace_identity,
|
||||
)?)?;
|
||||
}
|
||||
_ => return Err(usage_error(&format!("unknown command {command:?}"))),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct Options {
|
||||
runtime_store: Option<PathBuf>,
|
||||
local_verse_store: Option<PathBuf>,
|
||||
runtime_id: String,
|
||||
provider_incarnation: Option<String>,
|
||||
swarm_id: Option<String>,
|
||||
text: Option<String>,
|
||||
query_id: Option<String>,
|
||||
budget: Option<u32>,
|
||||
profile: Option<epiphany_core::EpiphanyMemoryProfile>,
|
||||
workspace_embedding_provider_id: Option<String>,
|
||||
workspace_embedding_model: Option<String>,
|
||||
workspace_vector_dimensions: Option<u32>,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
fn parse(args: impl Iterator<Item = String>) -> Result<Self> {
|
||||
let mut options = Self {
|
||||
runtime_store: None,
|
||||
local_verse_store: None,
|
||||
runtime_id: "epiphany-memory-semantic".to_string(),
|
||||
provider_incarnation: None,
|
||||
swarm_id: None,
|
||||
text: None,
|
||||
query_id: None,
|
||||
budget: None,
|
||||
profile: None,
|
||||
workspace_embedding_provider_id: None,
|
||||
workspace_embedding_model: None,
|
||||
workspace_vector_dimensions: None,
|
||||
};
|
||||
let mut args = args.peekable();
|
||||
while let Some(flag) = args.next() {
|
||||
let mut value = || {
|
||||
args.next()
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
};
|
||||
match flag.as_str() {
|
||||
"--runtime-store" => options.runtime_store = Some(PathBuf::from(value()?)),
|
||||
"--local-verse-store" => options.local_verse_store = Some(PathBuf::from(value()?)),
|
||||
"--runtime-id" => options.runtime_id = value()?,
|
||||
"--provider-incarnation" => options.provider_incarnation = Some(value()?),
|
||||
"--swarm-id" => options.swarm_id = Some(value()?),
|
||||
"--text" => options.text = Some(value()?),
|
||||
"--query-id" => options.query_id = Some(value()?),
|
||||
"--budget" => options.budget = Some(value()?.parse().context("invalid budget")?),
|
||||
"--profile" => options.profile = Some(parse_profile(&value()?)?),
|
||||
"--workspace-embedding-provider-id" => {
|
||||
options.workspace_embedding_provider_id = Some(value()?)
|
||||
}
|
||||
"--workspace-embedding-model" => options.workspace_embedding_model = Some(value()?),
|
||||
"--workspace-vector-dimensions" => {
|
||||
options.workspace_vector_dimensions = Some(
|
||||
value()?
|
||||
.parse()
|
||||
.context("invalid workspace vector dimensions")?,
|
||||
)
|
||||
}
|
||||
_ => return Err(usage_error(&format!("unexpected argument {flag:?}"))),
|
||||
}
|
||||
}
|
||||
if options
|
||||
.swarm_id
|
||||
.as_ref()
|
||||
.is_some_and(|id| id.trim().is_empty())
|
||||
{
|
||||
return Err(usage_error("--swarm-id must not be empty"));
|
||||
}
|
||||
if options.runtime_store.is_none() {
|
||||
return Err(usage_error("provide --runtime-store"));
|
||||
}
|
||||
Ok(options)
|
||||
}
|
||||
|
||||
fn load_source(&self) -> Result<(EpiphanyMemoryGraphSnapshot, String)> {
|
||||
let (input, _) = self.load_projection_input()?;
|
||||
Ok((
|
||||
input.snapshot().clone(),
|
||||
input.obligation().swarm_id.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
fn load_projection_input(&self) -> Result<(MemorySemanticProjectionInput, &PathBuf)> {
|
||||
let store = self
|
||||
.runtime_store
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow!("semantic projection requires the runtime store"))?;
|
||||
let input = runtime_modeling_semantic_projection_input(store)?;
|
||||
if self
|
||||
.swarm_id
|
||||
.as_ref()
|
||||
.is_some_and(|claimed| claimed != &input.obligation().swarm_id)
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"--swarm-id does not match canonical source identity"
|
||||
));
|
||||
}
|
||||
Ok((input, store))
|
||||
}
|
||||
|
||||
fn source_store(&self) -> Option<&PathBuf> {
|
||||
self.runtime_store.as_ref()
|
||||
}
|
||||
|
||||
fn provider_incarnation(&self) -> Result<&str> {
|
||||
self.provider_incarnation
|
||||
.as_deref()
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.ok_or_else(|| {
|
||||
usage_error("CultMesh health publication requires --provider-incarnation <id>")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_profile(value: &str) -> Result<epiphany_core::EpiphanyMemoryProfile> {
|
||||
serde_json::from_str(&format!("\"{value}\""))
|
||||
.with_context(|| format!("unknown memory profile {value:?}"))
|
||||
}
|
||||
|
||||
fn usage_error(message: &str) -> anyhow::Error {
|
||||
anyhow!(
|
||||
"{message}\nusage: epiphany-memory-semantic <context|health|repository-readiness> --runtime-store <path> [--swarm-id <id>] [--local-verse-store <path> --runtime-id <id> --provider-incarnation <id>] [--text <query>] [--query-id <id>] [--budget <n>] [--profile <profile>] [--workspace-embedding-provider-id <id> --workspace-embedding-model <model> --workspace-vector-dimensions <n>]"
|
||||
)
|
||||
}
|
||||
|
||||
fn print_json(value: &impl serde::Serialize) -> Result<()> {
|
||||
println!("{}", serde_json::to_string_pretty(value)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_semantic_health(
|
||||
health: &epiphany_core::EpiphanyCultMeshSemanticProjectionHealthEntry,
|
||||
) -> Result<()> {
|
||||
print_json(&serde_json::json!({
|
||||
"schemaVersion": health.schema_version,
|
||||
"verseId": health.verse_id,
|
||||
"verseTier": health.verse_tier,
|
||||
"swarmId": health.swarm_id,
|
||||
"partition": health.partition,
|
||||
"obligationId": health.obligation_id,
|
||||
"sourceGeneration": health.source_generation,
|
||||
"canonicalModelHash": health.canonical_model_hash,
|
||||
"canonicalContentSetHash": health.canonical_content_set_hash,
|
||||
"status": health.status,
|
||||
"receiptId": health.receipt_id,
|
||||
"indexedDocumentCount": health.indexed_document_count,
|
||||
"vectorDimensions": health.vector_dimensions,
|
||||
"observedAt": health.observed_at,
|
||||
"observedSourceAt": health.observed_source_at,
|
||||
"providerId": health.provider_id,
|
||||
"providerIncarnation": health.provider_incarnation,
|
||||
"authoritative": health.authoritative,
|
||||
"nonAuthoritative": !health.authoritative,
|
||||
"authority": "sight-only",
|
||||
"queryEligibleDisplayOnly": health.query_eligible_display_only,
|
||||
"privateStateExposed": health.private_state_exposed,
|
||||
}))
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ use epiphany_core::{
|
|||
EpiphanyMemoryNodeKind, EpiphanyMemoryProfile, EpiphanyRepoModelSeed,
|
||||
EpiphanyRepoModelSeedDocuments, ObserveOutcome, RuntimeSpineInitOptions,
|
||||
admit_repository_body_observation, bind_repository_body, bind_runtime_to_swarm,
|
||||
bind_runtime_workspace_coverage_store, initialize_keyed_repo_model, initialize_runtime_spine,
|
||||
initialize_keyed_repo_model, initialize_runtime_spine,
|
||||
load_current_runtime_repository_body_basis, load_repository_body_status,
|
||||
observe_repository_body,
|
||||
};
|
||||
|
|
@ -21,8 +21,6 @@ fn main() -> Result<()> {
|
|||
let repo = PathBuf::from(required(&args, "--repo")?);
|
||||
let store = PathBuf::from(required(&args, "--store")?);
|
||||
let runtime_store = PathBuf::from(required(&args, "--runtime-store")?);
|
||||
let workspace_coverage_store =
|
||||
PathBuf::from(required(&args, "--workspace-coverage-store")?);
|
||||
let workspace_id = required(&args, "--workspace-id")?;
|
||||
let runtime_id = required(&args, "--runtime-id")?;
|
||||
let swarm_id = required(&args, "--swarm-id")?;
|
||||
|
|
@ -37,7 +35,6 @@ fn main() -> Result<()> {
|
|||
)?;
|
||||
bind_runtime_to_swarm(&runtime_store, swarm_id, &at)?;
|
||||
let binding = bind_repository_body(&repo, &store, &runtime_store, workspace_id)?;
|
||||
bind_runtime_workspace_coverage_store(&runtime_store, &workspace_coverage_store, &at)?;
|
||||
observe_repository_body(&repo, &store, &runtime_store)?;
|
||||
let body_basis = load_current_runtime_repository_body_basis(&runtime_store)?;
|
||||
admit_repository_body_observation(&runtime_store, &body_basis)?;
|
||||
|
|
@ -173,7 +170,7 @@ fn required<'a>(args: &'a [String], name: &str) -> Result<&'a str> {
|
|||
}
|
||||
fn usage<T>() -> Result<T> {
|
||||
bail!(
|
||||
"usage: epiphany-repository-body bootstrap --repo PATH --store PATH --runtime-store PATH --workspace-coverage-store PATH --workspace-id ID --runtime-id ID --swarm-id ID | bind --repo PATH --store PATH --runtime-store PATH --workspace-id ID | observe --repo PATH --store PATH --runtime-store PATH | status --store PATH | smoke"
|
||||
"usage: epiphany-repository-body bootstrap --repo PATH --store PATH --runtime-store PATH --workspace-id ID --runtime-id ID --swarm-id ID | bind --repo PATH --store PATH --runtime-store PATH --workspace-id ID | observe --repo PATH --store PATH --runtime-store PATH | status --store PATH | smoke"
|
||||
)
|
||||
}
|
||||
fn smoke() -> Result<()> {
|
||||
|
|
@ -183,7 +180,6 @@ fn smoke() -> Result<()> {
|
|||
uuid::Uuid::new_v4()
|
||||
));
|
||||
let runtime_store = store.with_extension("runtime.cc");
|
||||
let workspace_coverage_store = store.with_extension("workspace-coverage.cc");
|
||||
initialize_runtime_spine(
|
||||
&runtime_store,
|
||||
RuntimeSpineInitOptions {
|
||||
|
|
@ -203,11 +199,6 @@ fn smoke() -> Result<()> {
|
|||
&runtime_store,
|
||||
"epiphany-repository-body-smoke",
|
||||
)?;
|
||||
bind_runtime_workspace_coverage_store(
|
||||
&runtime_store,
|
||||
&workspace_coverage_store,
|
||||
"2026-07-15T00:00:02Z",
|
||||
)?;
|
||||
let outcome = observe_repository_body(&root, &store, &runtime_store)?;
|
||||
let basis = load_current_runtime_repository_body_basis(&runtime_store)?;
|
||||
admit_repository_body_observation(&runtime_store, &basis)?;
|
||||
|
|
@ -215,8 +206,6 @@ fn smoke() -> Result<()> {
|
|||
.ok_or_else(|| anyhow::anyhow!("smoke observation missing after commit"))?;
|
||||
std::fs::remove_file(&store)?;
|
||||
std::fs::remove_file(&runtime_store)?;
|
||||
std::fs::remove_file(&workspace_coverage_store)?;
|
||||
let _ = std::fs::remove_file(workspace_coverage_store.with_extension("cc.lock"));
|
||||
let generation = match outcome {
|
||||
ObserveOutcome::Created(value) | ObserveOutcome::Unchanged(value) => value.generation,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,370 +0,0 @@
|
|||
use anyhow::{Context, Result, anyhow};
|
||||
use ed25519_dalek::SigningKey;
|
||||
use epiphany_core::{
|
||||
WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_SCHEMA_VERSION,
|
||||
WorkspaceCoverageManagedProcessLaunchEntry, WorkspaceCoverageProjectorConfig,
|
||||
WorkspaceCoverageProjectorPulseStatus, WorkspaceCoverageProjectorServiceBody,
|
||||
WorkspaceCoverageProviderHeartbeatEntry,
|
||||
authenticate_workspace_coverage_managed_process_launch, capture_process_instance,
|
||||
load_workspace_coverage_managed_process_launch,
|
||||
load_workspace_coverage_managed_process_launch_with_digest, native_boot_identity,
|
||||
open_default_host_identity, read_workspace_coverage_process_bootstrap,
|
||||
sign_workspace_coverage_heartbeat, write_workspace_coverage_provider_heartbeat,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
use uuid::Uuid;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse()?;
|
||||
let mut bootstrap = read_workspace_coverage_process_bootstrap(io::stdin().lock())?;
|
||||
if bootstrap.launch_id.to_string() != args.managed_process_launch_id {
|
||||
return Err(anyhow!(
|
||||
"bootstrap launch id disagrees with launch environment"
|
||||
));
|
||||
}
|
||||
let provider_key = SigningKey::from_bytes(&bootstrap.provider_signing_seed);
|
||||
bootstrap.provider_signing_seed.zeroize();
|
||||
let (launch, launch_digest) = authenticate_managed_launch(&args, &provider_key)?;
|
||||
|
||||
let mut config = WorkspaceCoverageProjectorConfig::from_env();
|
||||
config.qdrant_url = args.qdrant_url.clone();
|
||||
config.ollama_base_url = args.ollama_base_url.clone();
|
||||
config.ollama_model = args.ollama_model.clone();
|
||||
let mut projector = WorkspaceCoverageProjectorServiceBody::new(
|
||||
&args.runtime_store,
|
||||
&args.runtime_id,
|
||||
config,
|
||||
&launch.provider_incarnation_id,
|
||||
&launch.launch_id,
|
||||
)?;
|
||||
let trusted_host = open_default_host_identity()?;
|
||||
projector.install_execution_authority(
|
||||
&args.local_verse_store,
|
||||
&args.runtime_id,
|
||||
trusted_host.entry().clone(),
|
||||
provider_key.clone(),
|
||||
)?;
|
||||
|
||||
let first_heartbeat = publish_heartbeat(&args, &launch, &launch_digest, &provider_key, 1)?;
|
||||
let latest_heartbeat = Arc::new(Mutex::new(HeartbeatProjection {
|
||||
heartbeat_id: first_heartbeat.heartbeat_id,
|
||||
provider_status: first_heartbeat.status,
|
||||
}));
|
||||
spawn_heartbeat_nerve(
|
||||
&args,
|
||||
&launch,
|
||||
&launch_digest,
|
||||
&provider_key,
|
||||
Arc::clone(&latest_heartbeat),
|
||||
)?;
|
||||
|
||||
let mut pulse_sequence = 0_u64;
|
||||
loop {
|
||||
pulse_sequence = pulse_sequence
|
||||
.checked_add(1)
|
||||
.ok_or_else(|| anyhow!("workspace coverage pulse sequence exhausted"))?;
|
||||
let pulse = projector.pulse();
|
||||
let heartbeat = latest_heartbeat
|
||||
.lock()
|
||||
.map_err(|_| anyhow!("workspace coverage heartbeat projection lock poisoned"))?
|
||||
.clone();
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string(&json!({
|
||||
"schemaVersion": "epiphany.workspace_coverage_projector_pulse.v0",
|
||||
"pulseSequence": pulse_sequence,
|
||||
"providerIncarnation": projector.provider_incarnation(),
|
||||
"heartbeatId": heartbeat.heartbeat_id,
|
||||
"providerStatus": heartbeat.provider_status,
|
||||
"pulseStatus": pulse_status(pulse.status),
|
||||
"bodyObservationId": pulse.body_observation_id,
|
||||
"bodyGeneration": pulse.body_generation,
|
||||
"planId": pulse.plan_id,
|
||||
"receiptId": pulse.receipt_id,
|
||||
"fault": pulse.fault,
|
||||
"privateStateExposed": false,
|
||||
"authoritative": false
|
||||
}))?
|
||||
);
|
||||
thread::sleep(Duration::from_secs(args.interval_seconds));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct HeartbeatProjection {
|
||||
heartbeat_id: String,
|
||||
provider_status: String,
|
||||
}
|
||||
|
||||
fn spawn_heartbeat_nerve(
|
||||
args: &Args,
|
||||
launch: &WorkspaceCoverageManagedProcessLaunchEntry,
|
||||
launch_digest: &str,
|
||||
provider_key: &SigningKey,
|
||||
latest: Arc<Mutex<HeartbeatProjection>>,
|
||||
) -> Result<()> {
|
||||
let local_verse_store = args.local_verse_store.clone();
|
||||
let runtime_id = args.runtime_id.clone();
|
||||
let interval = Duration::from_secs(args.heartbeat_interval_seconds);
|
||||
let launch = launch.clone();
|
||||
let launch_digest = launch_digest.to_string();
|
||||
let provider_key = provider_key.clone();
|
||||
thread::Builder::new()
|
||||
.name("workspace-coverage-heartbeat".into())
|
||||
.spawn(move || {
|
||||
let mut sequence = 1_u64;
|
||||
loop {
|
||||
thread::sleep(interval);
|
||||
sequence = match sequence.checked_add(1) {
|
||||
Some(sequence) => sequence,
|
||||
None => {
|
||||
fatal_heartbeat_nerve("workspace coverage heartbeat sequence exhausted");
|
||||
}
|
||||
};
|
||||
let heartbeat = match publish_heartbeat_to(
|
||||
&local_verse_store,
|
||||
&runtime_id,
|
||||
&launch,
|
||||
&launch_digest,
|
||||
&provider_key,
|
||||
sequence,
|
||||
) {
|
||||
Ok(heartbeat) => heartbeat,
|
||||
Err(error) => {
|
||||
fatal_heartbeat_nerve(&format!(
|
||||
"workspace coverage heartbeat publication failed: {error:#}"
|
||||
));
|
||||
}
|
||||
};
|
||||
match latest.lock() {
|
||||
Ok(mut projection) => {
|
||||
projection.heartbeat_id = heartbeat.heartbeat_id;
|
||||
projection.provider_status = heartbeat.status;
|
||||
}
|
||||
Err(_) => {
|
||||
fatal_heartbeat_nerve(
|
||||
"workspace coverage heartbeat projection lock poisoned",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.context("failed to start workspace coverage heartbeat nerve")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fatal_heartbeat_nerve(message: &str) -> ! {
|
||||
eprintln!("{message}");
|
||||
// This exact process owns both projection and its authenticated liveness
|
||||
// publisher. Continuing after the nerve dies would leave an unfenced
|
||||
// actuator relying on an external repair loop to notice the corpse.
|
||||
std::process::exit(1)
|
||||
}
|
||||
|
||||
fn publish_heartbeat(
|
||||
args: &Args,
|
||||
launch: &WorkspaceCoverageManagedProcessLaunchEntry,
|
||||
launch_digest: &str,
|
||||
provider_key: &SigningKey,
|
||||
sequence: u64,
|
||||
) -> Result<WorkspaceCoverageProviderHeartbeatEntry> {
|
||||
publish_heartbeat_to(
|
||||
&args.local_verse_store,
|
||||
&args.runtime_id,
|
||||
launch,
|
||||
launch_digest,
|
||||
provider_key,
|
||||
sequence,
|
||||
)
|
||||
}
|
||||
|
||||
fn publish_heartbeat_to(
|
||||
local_verse_store: &PathBuf,
|
||||
runtime_id: &str,
|
||||
launch: &WorkspaceCoverageManagedProcessLaunchEntry,
|
||||
launch_digest: &str,
|
||||
provider_key: &SigningKey,
|
||||
sequence: u64,
|
||||
) -> Result<WorkspaceCoverageProviderHeartbeatEntry> {
|
||||
let mut heartbeat = WorkspaceCoverageProviderHeartbeatEntry {
|
||||
schema_version: WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_SCHEMA_VERSION.to_string(),
|
||||
heartbeat_id: Uuid::new_v4().to_string(),
|
||||
launch_id: launch.launch_id.clone(),
|
||||
launch_envelope_digest: launch_digest.to_string(),
|
||||
service_id: launch.service_id.clone(),
|
||||
provider_daemon_id: launch.provider_daemon_id.clone(),
|
||||
runtime_id: launch.runtime_id.clone(),
|
||||
host_identity_id: launch.host_identity_id.clone(),
|
||||
host_identity_record_digest: launch.host_identity_record_digest.clone(),
|
||||
boot_identity: launch.boot_identity.clone(),
|
||||
process_id: launch.process_id,
|
||||
process_creation_token: launch.process_creation_token,
|
||||
process_executable_path: launch.process_executable_path.clone(),
|
||||
provider_incarnation_id: launch.provider_incarnation_id.clone(),
|
||||
provider_public_key: launch.provider_public_key.clone(),
|
||||
sequence,
|
||||
// Heartbeat proves only that this exact provider process remains able
|
||||
// to publish. Projection faults and progress belong to separate state.
|
||||
status: "ready".to_string(),
|
||||
observed_at_utc: chrono::Utc::now().to_rfc3339(),
|
||||
provider_signature: Vec::new(),
|
||||
signature_algorithm: "ed25519".to_string(),
|
||||
};
|
||||
sign_workspace_coverage_heartbeat(&mut heartbeat, provider_key)?;
|
||||
write_workspace_coverage_provider_heartbeat(
|
||||
local_verse_store,
|
||||
runtime_id.to_string(),
|
||||
heartbeat,
|
||||
)
|
||||
}
|
||||
|
||||
fn authenticate_managed_launch(
|
||||
args: &Args,
|
||||
provider_key: &SigningKey,
|
||||
) -> Result<(WorkspaceCoverageManagedProcessLaunchEntry, String)> {
|
||||
let host = open_default_host_identity()?;
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
loop {
|
||||
if load_workspace_coverage_managed_process_launch(
|
||||
&args.local_verse_store,
|
||||
args.runtime_id.clone(),
|
||||
&args.managed_process_launch_id,
|
||||
)?
|
||||
.is_some()
|
||||
{
|
||||
let launch = authenticate_workspace_coverage_managed_process_launch(
|
||||
&args.local_verse_store,
|
||||
args.runtime_id.clone(),
|
||||
&args.managed_process_launch_id,
|
||||
host.entry(),
|
||||
)?;
|
||||
let own = capture_process_instance(std::process::id())?;
|
||||
let boot = native_boot_identity()
|
||||
.ok_or_else(|| anyhow!("native boot identity is not provable"))?;
|
||||
if launch.boot_identity != boot
|
||||
|| launch.process_id != own.process_id
|
||||
|| launch.process_creation_token != own.creation_token
|
||||
|| PathBuf::from(&launch.process_executable_path) != own.executable_path
|
||||
|| launch.provider_public_key != provider_key.verifying_key().to_bytes()
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"managed launch disagrees with this exact provider process"
|
||||
));
|
||||
}
|
||||
let (_, digest) = load_workspace_coverage_managed_process_launch_with_digest(
|
||||
&args.local_verse_store,
|
||||
args.runtime_id.clone(),
|
||||
&args.managed_process_launch_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("managed launch disappeared"))?;
|
||||
return Ok((launch, digest));
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
return Err(anyhow!(
|
||||
"managed workspace coverage projector launch was not persisted"
|
||||
));
|
||||
}
|
||||
thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
}
|
||||
|
||||
fn pulse_status(status: WorkspaceCoverageProjectorPulseStatus) -> &'static str {
|
||||
match status {
|
||||
WorkspaceCoverageProjectorPulseStatus::Idle => "idle",
|
||||
WorkspaceCoverageProjectorPulseStatus::Executed => "executed",
|
||||
WorkspaceCoverageProjectorPulseStatus::Contended => "contended",
|
||||
WorkspaceCoverageProjectorPulseStatus::Refused => "refused",
|
||||
}
|
||||
}
|
||||
|
||||
struct Args {
|
||||
runtime_store: PathBuf,
|
||||
local_verse_store: PathBuf,
|
||||
runtime_id: String,
|
||||
interval_seconds: u64,
|
||||
heartbeat_interval_seconds: u64,
|
||||
managed_process_launch_id: String,
|
||||
qdrant_url: String,
|
||||
ollama_base_url: String,
|
||||
ollama_model: String,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self> {
|
||||
let mut values = env::args().skip(1);
|
||||
let command = values.next().context("missing command; use serve")?;
|
||||
if command != "serve" {
|
||||
return Err(anyhow!("unknown command {command:?}; use serve"));
|
||||
}
|
||||
let mut runtime_store = None;
|
||||
let mut local_verse_store = None;
|
||||
let mut runtime_id = None;
|
||||
let mut interval_seconds = None;
|
||||
let mut heartbeat_interval_seconds = None;
|
||||
let mut qdrant_url = None;
|
||||
let mut ollama_base_url = None;
|
||||
let mut ollama_model = None;
|
||||
while let Some(flag) = values.next() {
|
||||
let mut value = || {
|
||||
values
|
||||
.next()
|
||||
.with_context(|| format!("missing value for {flag}"))
|
||||
};
|
||||
match flag.as_str() {
|
||||
"--runtime-store" => runtime_store = Some(PathBuf::from(value()?)),
|
||||
"--local-verse-store" => local_verse_store = Some(PathBuf::from(value()?)),
|
||||
"--runtime-id" => runtime_id = Some(value()?),
|
||||
"--interval-seconds" => interval_seconds = Some(value()?.parse::<u64>()?),
|
||||
"--heartbeat-interval-seconds" => {
|
||||
heartbeat_interval_seconds = Some(value()?.parse::<u64>()?)
|
||||
}
|
||||
"--qdrant-url" => qdrant_url = Some(value()?),
|
||||
"--ollama-base-url" => ollama_base_url = Some(value()?),
|
||||
"--ollama-model" => ollama_model = Some(value()?),
|
||||
_ => return Err(anyhow!("unexpected argument {flag:?}")),
|
||||
}
|
||||
}
|
||||
let interval_seconds = interval_seconds.context("missing --interval-seconds")?;
|
||||
if interval_seconds == 0 {
|
||||
return Err(anyhow!("--interval-seconds must be positive"));
|
||||
}
|
||||
let heartbeat_interval_seconds =
|
||||
heartbeat_interval_seconds.context("missing --heartbeat-interval-seconds")?;
|
||||
if heartbeat_interval_seconds == 0 {
|
||||
return Err(anyhow!("--heartbeat-interval-seconds must be positive"));
|
||||
}
|
||||
let managed_process_launch_id =
|
||||
env::var("EPIPHANY_WORKSPACE_COVERAGE_LAUNCH_ID").unwrap_or_default();
|
||||
if managed_process_launch_id.trim().is_empty() {
|
||||
return Err(anyhow!(
|
||||
"managed workspace coverage projector requires its managed process launch id"
|
||||
));
|
||||
}
|
||||
Ok(Self {
|
||||
runtime_store: runtime_store.context("missing --runtime-store")?,
|
||||
local_verse_store: local_verse_store.context("missing --local-verse-store")?,
|
||||
runtime_id: runtime_id.context("missing --runtime-id")?,
|
||||
interval_seconds,
|
||||
heartbeat_interval_seconds,
|
||||
managed_process_launch_id,
|
||||
qdrant_url: required_nonempty(qdrant_url, "--qdrant-url")?,
|
||||
ollama_base_url: required_nonempty(ollama_base_url, "--ollama-base-url")?,
|
||||
ollama_model: required_nonempty(ollama_model, "--ollama-model")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn required_nonempty(value: Option<String>, flag: &str) -> Result<String> {
|
||||
let value = value.with_context(|| format!("missing {flag}"))?;
|
||||
if value.trim().is_empty() {
|
||||
return Err(anyhow!("{flag} must not be empty"));
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
Reference in a new issue