Move workspace projection authority out of Body
This commit is contained in:
parent
7559419f14
commit
e23330b415
10 changed files with 3061 additions and 556 deletions
|
|
@ -70,8 +70,8 @@ use epiphany_core::{
|
|||
write_workspace_coverage_process_termination_observation,
|
||||
};
|
||||
use epiphany_core::{
|
||||
authenticate_current_workspace_coverage_advancement,
|
||||
authenticate_current_workspace_coverage_terminal_authority,
|
||||
authenticate_current_workspace_coverage_advancement_sight,
|
||||
authenticate_current_workspace_coverage_terminal_sight,
|
||||
};
|
||||
use epiphany_core::{
|
||||
epiphany_packaged_release_binary_path, epiphany_packaged_release_witness_sha256,
|
||||
|
|
@ -898,7 +898,21 @@ fn publish_managed_service_iteration_health(
|
|||
continue;
|
||||
}
|
||||
};
|
||||
match authenticate_current_workspace_coverage_terminal_authority(runtime_store) {
|
||||
let host = match open_default_host_identity() {
|
||||
Ok(host) => host,
|
||||
Err(error) => {
|
||||
contradictions.push(format!(
|
||||
"workspace health cannot authenticate host: {error:#}"
|
||||
));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
match authenticate_current_workspace_coverage_terminal_sight(
|
||||
runtime_store,
|
||||
&args.store,
|
||||
&args.runtime_id,
|
||||
host.entry(),
|
||||
) {
|
||||
Ok(Some(authority)) => {
|
||||
terminal_current += 1;
|
||||
workspace_evidence = Some(format!(
|
||||
|
|
@ -910,15 +924,6 @@ fn publish_managed_service_iteration_health(
|
|||
));
|
||||
}
|
||||
Ok(None) => {
|
||||
let host = match open_default_host_identity() {
|
||||
Ok(host) => host,
|
||||
Err(error) => {
|
||||
contradictions.push(format!(
|
||||
"workspace health cannot authenticate host: {error:#}"
|
||||
));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let launch = match load_latest_workspace_coverage_managed_process_launch(
|
||||
&args.store,
|
||||
args.runtime_id.clone(),
|
||||
|
|
@ -932,26 +937,30 @@ fn publish_managed_service_iteration_health(
|
|||
continue;
|
||||
}
|
||||
};
|
||||
match authenticate_current_workspace_coverage_advancement(
|
||||
match authenticate_current_workspace_coverage_advancement_sight(
|
||||
runtime_store,
|
||||
&args.store,
|
||||
&args.runtime_id,
|
||||
&launch.launch_id,
|
||||
host.entry(),
|
||||
Utc::now(),
|
||||
Duration::seconds(WORKSPACE_PROGRESS_NO_ADVANCE_LEASE_SECONDS),
|
||||
) {
|
||||
Ok(Some(authority)) => {
|
||||
warming += 1;
|
||||
workspace_evidence = Some(format!(
|
||||
"workspaceProgressId={} workspaceCheckpointId={} workspacePlanId={} workspaceCompletedUnits={} workspaceTotalUnits={} workspaceLastAdvancedAt={}",
|
||||
authority.progress_id,
|
||||
authority.checkpoint_id,
|
||||
authority.plan_id,
|
||||
authority.completed_units,
|
||||
authority.total_units,
|
||||
authority.last_advanced_at_utc
|
||||
));
|
||||
let advanced =
|
||||
DateTime::parse_from_rfc3339(&authority.last_advanced_at_utc)
|
||||
.map(|time| time.with_timezone(&Utc));
|
||||
match advanced {
|
||||
Ok(advanced) if Utc::now().signed_duration_since(advanced) >= Duration::zero()
|
||||
&& Utc::now().signed_duration_since(advanced) <= Duration::seconds(WORKSPACE_PROGRESS_NO_ADVANCE_LEASE_SECONDS) => {
|
||||
warming += 1;
|
||||
workspace_evidence = Some(format!(
|
||||
"workspaceProgressId={} workspaceCheckpointId={} workspacePlanId={} workspaceCompletedUnits={} workspaceTotalUnits={} workspaceLastAdvancedAt={}",
|
||||
authority.progress_id, authority.checkpoint_id, authority.plan_id,
|
||||
authority.completed_units, authority.total_units, authority.last_advanced_at_utc
|
||||
));
|
||||
}
|
||||
Ok(_) => contradictions.push("workspace advancement sight exceeded the supervisor no-advance lease".into()),
|
||||
Err(error) => contradictions.push(format!("workspace advancement sight time is invalid: {error:#}")),
|
||||
}
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(error) => contradictions.push(format!(
|
||||
|
|
@ -4032,6 +4041,30 @@ mod semantic_projector_authority_tests {
|
|||
assert!(source.contains("WindowsIdentity]::GetCurrent().User.Value"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workspace_health_reads_signed_sight_and_never_opens_owned_coverage_store() {
|
||||
let source = include_str!("epiphany-daemon-supervisor.rs");
|
||||
let start = source
|
||||
.find("fn publish_managed_service_iteration_health")
|
||||
.unwrap();
|
||||
let tail = &source[start..];
|
||||
let end = tail.find("\nfn ").unwrap();
|
||||
let body = &tail[..end];
|
||||
let terminal = body
|
||||
.find("authenticate_current_workspace_coverage_terminal_sight")
|
||||
.unwrap();
|
||||
let advancement = body
|
||||
.find("authenticate_current_workspace_coverage_advancement_sight")
|
||||
.unwrap();
|
||||
assert!(
|
||||
terminal < advancement,
|
||||
"terminal sight must be preferred before warming sight"
|
||||
);
|
||||
assert!(!body.contains("open_workspace_coverage_authority"));
|
||||
assert!(!body.contains("authenticate_current_workspace_coverage_terminal_authority"));
|
||||
assert!(!body.contains("authenticate_current_workspace_coverage_advancement("));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_argv_quoting_preserves_paths_and_escapes_parser_boundaries() {
|
||||
assert_eq!(
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ use epiphany_core::{
|
|||
EpiphanyMemoryLifecycle, EpiphanyMemoryNode, EpiphanyMemoryNodeKind, EpiphanyMemoryProfile,
|
||||
MEMORY_GRAPH_SCHEMA_VERSION, ObserveOutcome, RuntimeSpineInitOptions,
|
||||
admit_legacy_agent_memory_generation, bind_repository_body, bind_runtime_to_agent_memory_swarm,
|
||||
ensure_agent_memory_swarm_identity, ensure_runtime_repo_model, initialize_runtime_spine,
|
||||
load_repository_body_status, observe_repository_body,
|
||||
bind_runtime_workspace_coverage_store, ensure_agent_memory_swarm_identity,
|
||||
ensure_runtime_repo_model, initialize_runtime_spine, load_repository_body_status,
|
||||
observe_repository_body,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
@ -21,6 +22,8 @@ fn main() -> Result<()> {
|
|||
let store = PathBuf::from(required(&args, "--store")?);
|
||||
let runtime_store = PathBuf::from(required(&args, "--runtime-store")?);
|
||||
let agent_store = PathBuf::from(required(&args, "--agent-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,6 +40,7 @@ fn main() -> Result<()> {
|
|||
admit_legacy_agent_memory_generation(&agent_store)?;
|
||||
bind_runtime_to_agent_memory_swarm(&runtime_store, &agent_store, &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 bootstrap = EpiphanyMemoryGraphSnapshot {
|
||||
schema_version: Some(MEMORY_GRAPH_SCHEMA_VERSION.to_string()),
|
||||
|
|
@ -163,7 +167,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 --agent-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 --agent-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"
|
||||
)
|
||||
}
|
||||
fn smoke() -> Result<()> {
|
||||
|
|
@ -174,6 +178,7 @@ fn smoke() -> Result<()> {
|
|||
));
|
||||
let runtime_store = store.with_extension("runtime.cc");
|
||||
let agent_store = store.with_extension("agents.cc");
|
||||
let workspace_coverage_store = store.with_extension("workspace-coverage.cc");
|
||||
initialize_runtime_spine(
|
||||
&runtime_store,
|
||||
RuntimeSpineInitOptions {
|
||||
|
|
@ -190,12 +195,19 @@ 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 observed = load_repository_body_status(&store)?
|
||||
.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(&agent_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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,12 +7,15 @@ use crate::default_soul_cultnet_contracts;
|
|||
use crate::default_substrate_gate_cultnet_contracts;
|
||||
use crate::packaged_release::{EpiphanyPackagedReleaseEntry, EpiphanyPackagedReleaseHead};
|
||||
use crate::workspace_coverage_process_documents::{
|
||||
WORKSPACE_COVERAGE_ADVANCEMENT_SIGHT_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_PROCESS_EVIDENCE_HEAD_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_PROCESS_LAUNCH_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_PROCESS_TERMINATION_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_TERMINAL_SIGHT_SCHEMA_VERSION, WorkspaceCoverageAdvancementSightEntry,
|
||||
WorkspaceCoverageManagedProcessLaunchEntry, WorkspaceCoverageProcessEvidenceHead,
|
||||
WorkspaceCoverageProcessTerminationObservationEntry, WorkspaceCoverageProviderHeartbeatEntry,
|
||||
WorkspaceCoverageTerminalSightEntry,
|
||||
};
|
||||
use crate::workspace_coverage_projection_progress::{
|
||||
WORKSPACE_COVERAGE_PROJECTION_PROGRESS_SCHEMA_VERSION, WorkspaceCoverageProjectionProgressEntry,
|
||||
|
|
@ -2661,6 +2664,8 @@ cultmesh_documents!(EpiphanyCultMeshDocuments {
|
|||
WorkspaceCoverageProviderHeartbeatEntry => WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_SCHEMA_VERSION,
|
||||
WorkspaceCoverageProcessTerminationObservationEntry => WORKSPACE_COVERAGE_PROCESS_TERMINATION_SCHEMA_VERSION,
|
||||
WorkspaceCoverageProjectionProgressEntry => WORKSPACE_COVERAGE_PROJECTION_PROGRESS_SCHEMA_VERSION,
|
||||
WorkspaceCoverageAdvancementSightEntry => WORKSPACE_COVERAGE_ADVANCEMENT_SIGHT_SCHEMA_VERSION,
|
||||
WorkspaceCoverageTerminalSightEntry => WORKSPACE_COVERAGE_TERMINAL_SIGHT_SCHEMA_VERSION,
|
||||
EpiphanyPackagedReleaseEntry => crate::packaged_release::EPIPHANY_PACKAGED_RELEASE_SCHEMA_VERSION,
|
||||
EpiphanyPackagedReleaseHead => crate::packaged_release::EPIPHANY_PACKAGED_RELEASE_HEAD_SCHEMA_VERSION,
|
||||
EpiphanyCultMeshIdunnDeploymentReceiptEntry => EPIPHANY_CULTMESH_IDUNN_DEPLOYMENT_RECEIPT_SCHEMA_VERSION,
|
||||
|
|
|
|||
|
|
@ -1196,12 +1196,17 @@ pub use workspace_coverage_process_bootstrap::{
|
|||
write_workspace_coverage_process_bootstrap,
|
||||
};
|
||||
pub use workspace_coverage_process_documents::{
|
||||
WORKSPACE_COVERAGE_ADVANCEMENT_SIGHT_SCHEMA_VERSION, WORKSPACE_COVERAGE_ADVANCEMENT_SIGHT_TYPE,
|
||||
WORKSPACE_COVERAGE_PROCESS_LAUNCH_LATEST_KEY, WORKSPACE_COVERAGE_PROCESS_LAUNCH_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_PROCESS_LAUNCH_TYPE, WORKSPACE_COVERAGE_PROCESS_TERMINATION_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_PROCESS_TERMINATION_TYPE, WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_LATEST_KEY,
|
||||
WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_TYPE, WorkspaceCoverageManagedProcessLaunchEntry,
|
||||
WORKSPACE_COVERAGE_PROVIDER_HEARTBEAT_TYPE, WORKSPACE_COVERAGE_TERMINAL_SIGHT_SCHEMA_VERSION,
|
||||
WORKSPACE_COVERAGE_TERMINAL_SIGHT_TYPE, WorkspaceCoverageAdvancementSightEntry,
|
||||
WorkspaceCoverageManagedProcessLaunchEntry,
|
||||
WorkspaceCoverageProcessTerminationObservationEntry, WorkspaceCoverageProviderHeartbeatEntry,
|
||||
WorkspaceCoverageTerminalSightEntry, authenticate_current_workspace_coverage_advancement_sight,
|
||||
authenticate_current_workspace_coverage_terminal_sight,
|
||||
authenticate_workspace_coverage_managed_process_launch,
|
||||
authenticate_workspace_coverage_process_termination_observation,
|
||||
authenticate_workspace_coverage_provider_heartbeat,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,9 +1,9 @@
|
|||
use crate::workspace_coverage_process_documents::authenticate_workspace_coverage_managed_process_launch_with_envelope_digest;
|
||||
use crate::workspace_coverage_projector::{
|
||||
ATTEMPT_TYPE, CLAIM_KEY, CLAIM_TYPE, OBLIGATION_TYPE, PLAN_TYPE,
|
||||
WorkspaceCoverageProjectionAttempt, WorkspaceCoverageProjectionClaim,
|
||||
exact_obligation_body_authority, payload_for, validate_claim_attempt_link,
|
||||
validate_projection_attempt, validate_projection_claim,
|
||||
ATTEMPT_TYPE, CLAIM_TYPE, OBLIGATION_TYPE, PLAN_TYPE, WorkspaceCoverageProjectionAttempt,
|
||||
WorkspaceCoverageProjectionClaim, exact_obligation_body_authority, payload_for,
|
||||
validate_claim_attempt_link, validate_projection_attempt, validate_projection_claim,
|
||||
workspace_coverage_claim_key,
|
||||
};
|
||||
use crate::workspace_retrieval_coverage::{
|
||||
WorkspaceCoverageObligation, WorkspaceCoverageProjectionPlan,
|
||||
|
|
@ -19,7 +19,8 @@ use crate::{
|
|||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use chrono::DateTime;
|
||||
use cultcache_rs::{
|
||||
CacheBackingStore, CultCacheEnvelope, DatabaseEntry, SingleFileMessagePackBackingStore,
|
||||
CacheBackingStore, CultCacheEnvelope, DatabaseEntry, OwnedRedbMessagePackBackingStore,
|
||||
SingleFileMessagePackBackingStore,
|
||||
};
|
||||
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
||||
use serde::Serialize;
|
||||
|
|
@ -31,7 +32,9 @@ pub const WORKSPACE_COVERAGE_PROJECTION_BATCH_CHECKPOINT_TYPE: &str =
|
|||
pub const WORKSPACE_COVERAGE_PROJECTION_BATCH_CHECKPOINT_SCHEMA_VERSION: &str =
|
||||
"gamecult.epiphany.workspace_coverage_projection_batch_checkpoint.v0";
|
||||
pub const WORKSPACE_COVERAGE_BATCH_CHECKPOINT_MAX_POINTS: usize = 128;
|
||||
const HEAD_TYPE: &str = "gamecult.epiphany.workspace_coverage_projection_batch_checkpoint_head";
|
||||
pub(crate) const WORKSPACE_COVERAGE_PROJECTION_BATCH_CHECKPOINT_HEAD_TYPE: &str =
|
||||
"gamecult.epiphany.workspace_coverage_projection_batch_checkpoint_head";
|
||||
const HEAD_TYPE: &str = WORKSPACE_COVERAGE_PROJECTION_BATCH_CHECKPOINT_HEAD_TYPE;
|
||||
const HEAD_SCHEMA: &str =
|
||||
"gamecult.epiphany.workspace_coverage_projection_batch_checkpoint_head.v0";
|
||||
const OBSERVATION_METHOD: &str = "provider-attested-qdrant-readback-v0";
|
||||
|
|
@ -184,7 +187,8 @@ pub(crate) struct ObservedWorkspaceCoverageBatchInput {
|
|||
}
|
||||
|
||||
pub(crate) fn admit_observed_workspace_coverage_batch(
|
||||
body_store: impl AsRef<Path>,
|
||||
body_store: &Path,
|
||||
coverage_store: &OwnedRedbMessagePackBackingStore,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
runtime_id: &str,
|
||||
trusted_host: &HostIncarnationIdentityEntry,
|
||||
|
|
@ -192,9 +196,9 @@ pub(crate) fn admit_observed_workspace_coverage_batch(
|
|||
observed: ObservedWorkspaceCoverageBatchInput,
|
||||
) -> Result<WorkspaceCoverageProjectionBatchCheckpointAdmission> {
|
||||
validate_observed_batch_input(&observed)?;
|
||||
let body_store = body_store.as_ref();
|
||||
let opening = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
let claim_env = find(&opening, CLAIM_TYPE, CLAIM_KEY)?;
|
||||
let opening = coverage_store.pull_all()?;
|
||||
let body_opening = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
let claim_env = find_current_claim(&opening, &body_opening)?;
|
||||
let claim: WorkspaceCoverageProjectionClaim = decode(claim_env)?;
|
||||
let attempt_env = find(&opening, ATTEMPT_TYPE, &claim.attempt_id)?;
|
||||
let attempt: WorkspaceCoverageProjectionAttempt = decode(attempt_env)?;
|
||||
|
|
@ -211,7 +215,7 @@ pub(crate) fn admit_observed_workspace_coverage_batch(
|
|||
let obligation: WorkspaceCoverageObligation = decode(obligation_env)?;
|
||||
let plan: WorkspaceCoverageProjectionPlan = decode(plan_env)?;
|
||||
validate_workspace_coverage_projection_plan(&obligation, &plan)?;
|
||||
let authority = exact_obligation_body_authority(&opening, &obligation)?;
|
||||
let authority = exact_obligation_body_authority(&body_opening, &obligation)?;
|
||||
let binding_env = find(&authority, BODY_BINDING_TYPE, BODY_BINDING_KEY)?;
|
||||
let body_head_env = find(&authority, BODY_HEAD_TYPE, BODY_HEAD_KEY)?;
|
||||
let observation_env = find(
|
||||
|
|
@ -242,36 +246,6 @@ pub(crate) fn admit_observed_workspace_coverage_batch(
|
|||
{
|
||||
bail!("observed batch signer/launch disagrees with claim executor");
|
||||
}
|
||||
if let Some(current) = load_authenticated_current_checkpoint(
|
||||
body_store,
|
||||
local_verse_store.as_ref(),
|
||||
trusted_host,
|
||||
&claim.claim_id,
|
||||
claim.claim_epoch,
|
||||
)? {
|
||||
let progress = crate::workspace_coverage_projection_progress::load_latest_workspace_coverage_projection_progress(
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
&claim.managed_process_launch_id,
|
||||
&claim.claim_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("current checkpoint exists without canonical progress genesis"))?;
|
||||
if progress.sequence
|
||||
!= current
|
||||
.checkpoint
|
||||
.sequence
|
||||
.checked_add(1)
|
||||
.ok_or_else(|| anyhow!("checkpoint sequence exhausted"))?
|
||||
|| progress.checkpoint_id.as_deref() != Some(current.checkpoint.checkpoint_id.as_str())
|
||||
|| progress.checkpoint_binding_sha256.as_deref()
|
||||
!= Some(current.checkpoint_envelope_digest.as_str())
|
||||
|| progress.completed_units != current.checkpoint.cumulative_point_count
|
||||
{
|
||||
bail!(
|
||||
"current checkpoint is ahead of progress; reconcile before admitting a new batch"
|
||||
);
|
||||
}
|
||||
}
|
||||
let head_key = checkpoint_head_key(&claim.claim_id, claim.claim_epoch);
|
||||
let prior: Option<WorkspaceCoverageProjectionBatchCheckpointHeadEntry> = opening
|
||||
.iter()
|
||||
|
|
@ -353,20 +327,23 @@ pub(crate) fn admit_observed_workspace_coverage_batch(
|
|||
sign_workspace_coverage_projection_batch_checkpoint(&mut entry, provider_signing_key)?;
|
||||
admit_workspace_coverage_projection_batch_checkpoint(
|
||||
body_store,
|
||||
coverage_store,
|
||||
local_verse_store,
|
||||
trusted_host,
|
||||
provider_signing_key,
|
||||
entry,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn load_authenticated_current_checkpoint(
|
||||
body_store: impl AsRef<Path>,
|
||||
body_store: &Path,
|
||||
coverage_store: &OwnedRedbMessagePackBackingStore,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
trusted_host: &HostIncarnationIdentityEntry,
|
||||
claim_id: &str,
|
||||
claim_epoch: u64,
|
||||
) -> Result<Option<WorkspaceCoverageProjectionBatchCheckpointAdmission>> {
|
||||
let opening = SingleFileMessagePackBackingStore::new(body_store.as_ref()).pull_all()?;
|
||||
let opening = coverage_store.pull_all()?;
|
||||
let head_key = checkpoint_head_key(claim_id, claim_epoch);
|
||||
let Some(head_env) = opening
|
||||
.iter()
|
||||
|
|
@ -402,21 +379,26 @@ pub(crate) fn load_authenticated_current_checkpoint(
|
|||
)?;
|
||||
validate_launch(&checkpoint, &launch, &launch_digest)?;
|
||||
validate_current_head_event_identity(&checkpoint, &head)?;
|
||||
let binding_env = find(&opening, BODY_BINDING_TYPE, BODY_BINDING_KEY)?;
|
||||
let body_head_env = find(&opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?;
|
||||
let body_opening = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
let binding_env = find(&body_opening, BODY_BINDING_TYPE, BODY_BINDING_KEY)?;
|
||||
let body_head_env = find(&body_opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?;
|
||||
let observation_env = find(
|
||||
&opening,
|
||||
&body_opening,
|
||||
BODY_OBSERVATION_TYPE,
|
||||
&checkpoint.body_observation_id,
|
||||
)?;
|
||||
let manifest_env = find(
|
||||
&opening,
|
||||
&body_opening,
|
||||
BODY_MANIFEST_TYPE,
|
||||
&checkpoint.manifest_root_sha256,
|
||||
)?;
|
||||
let obligation_env = find(&opening, OBLIGATION_TYPE, &checkpoint.obligation_id)?;
|
||||
let plan_env = find(&opening, PLAN_TYPE, &checkpoint.plan_id)?;
|
||||
let claim_env = find(&opening, CLAIM_TYPE, CLAIM_KEY)?;
|
||||
let claim_env = find(
|
||||
&opening,
|
||||
CLAIM_TYPE,
|
||||
&workspace_coverage_claim_key(&checkpoint.body_observation_id, checkpoint.body_generation),
|
||||
)?;
|
||||
let attempt_env = find(&opening, ATTEMPT_TYPE, &checkpoint.attempt_id)?;
|
||||
let binding: RepositoryBodyBinding = decode(binding_env)?;
|
||||
let body_head: RepositoryBodyHead = decode(body_head_env)?;
|
||||
|
|
@ -452,7 +434,7 @@ pub(crate) fn load_authenticated_current_checkpoint(
|
|||
},
|
||||
)?;
|
||||
validate_workspace_coverage_projection_plan(&obligation, &plan)?;
|
||||
exact_obligation_body_authority(&opening, &obligation)?;
|
||||
let body_authority = exact_obligation_body_authority(&body_opening, &obligation)?;
|
||||
validate_authority(
|
||||
&checkpoint,
|
||||
&binding,
|
||||
|
|
@ -473,21 +455,34 @@ pub(crate) fn load_authenticated_current_checkpoint(
|
|||
attempt_env,
|
||||
)?;
|
||||
validate_batch_against_plan(&checkpoint, &obligation, &plan)?;
|
||||
Ok(Some(WorkspaceCoverageProjectionBatchCheckpointAdmission {
|
||||
let admission = WorkspaceCoverageProjectionBatchCheckpointAdmission {
|
||||
checkpoint,
|
||||
checkpoint_envelope_digest: head.checkpoint_envelope_digest,
|
||||
}))
|
||||
};
|
||||
let closing_body = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
for expected in body_authority {
|
||||
if closing_body
|
||||
.iter()
|
||||
.find(|row| row.r#type == expected.r#type && row.key == expected.key)
|
||||
!= Some(&expected)
|
||||
{
|
||||
bail!("Repository Body changed while loading current workspace checkpoint");
|
||||
}
|
||||
}
|
||||
Ok(Some(admission))
|
||||
}
|
||||
|
||||
pub(crate) fn load_authenticated_checkpoint_chain(
|
||||
body_store: impl AsRef<Path>,
|
||||
body_store: &Path,
|
||||
coverage_store: &OwnedRedbMessagePackBackingStore,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
trusted_host: &HostIncarnationIdentityEntry,
|
||||
claim_id: &str,
|
||||
claim_epoch: u64,
|
||||
) -> Result<Vec<WorkspaceCoverageProjectionBatchCheckpointAdmission>> {
|
||||
let Some(current) = load_authenticated_current_checkpoint(
|
||||
body_store.as_ref(),
|
||||
body_store,
|
||||
coverage_store,
|
||||
local_verse_store.as_ref(),
|
||||
trusted_host,
|
||||
claim_id,
|
||||
|
|
@ -496,7 +491,7 @@ pub(crate) fn load_authenticated_checkpoint_chain(
|
|||
else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
let opening = SingleFileMessagePackBackingStore::new(body_store.as_ref()).pull_all()?;
|
||||
let opening = coverage_store.pull_all()?;
|
||||
let head_env = find(
|
||||
&opening,
|
||||
HEAD_TYPE,
|
||||
|
|
@ -508,21 +503,29 @@ pub(crate) fn load_authenticated_checkpoint_chain(
|
|||
{
|
||||
bail!("checkpoint head changed while reconstructing authenticated chain");
|
||||
}
|
||||
let binding_env = find(&opening, BODY_BINDING_TYPE, BODY_BINDING_KEY)?;
|
||||
let body_head_env = find(&opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?;
|
||||
let body_opening = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
let binding_env = find(&body_opening, BODY_BINDING_TYPE, BODY_BINDING_KEY)?;
|
||||
let body_head_env = find(&body_opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?;
|
||||
let observation_env = find(
|
||||
&opening,
|
||||
&body_opening,
|
||||
BODY_OBSERVATION_TYPE,
|
||||
¤t.checkpoint.body_observation_id,
|
||||
)?;
|
||||
let manifest_env = find(
|
||||
&opening,
|
||||
&body_opening,
|
||||
BODY_MANIFEST_TYPE,
|
||||
¤t.checkpoint.manifest_root_sha256,
|
||||
)?;
|
||||
let obligation_env = find(&opening, OBLIGATION_TYPE, ¤t.checkpoint.obligation_id)?;
|
||||
let plan_env = find(&opening, PLAN_TYPE, ¤t.checkpoint.plan_id)?;
|
||||
let claim_env = find(&opening, CLAIM_TYPE, CLAIM_KEY)?;
|
||||
let claim_env = find(
|
||||
&opening,
|
||||
CLAIM_TYPE,
|
||||
&workspace_coverage_claim_key(
|
||||
¤t.checkpoint.body_observation_id,
|
||||
current.checkpoint.body_generation,
|
||||
),
|
||||
)?;
|
||||
let attempt_env = find(&opening, ATTEMPT_TYPE, ¤t.checkpoint.attempt_id)?;
|
||||
let binding: RepositoryBodyBinding = decode(binding_env)?;
|
||||
let body_head: RepositoryBodyHead = decode(body_head_env)?;
|
||||
|
|
@ -558,7 +561,7 @@ pub(crate) fn load_authenticated_checkpoint_chain(
|
|||
},
|
||||
)?;
|
||||
validate_workspace_coverage_projection_plan(&obligation, &plan)?;
|
||||
exact_obligation_body_authority(&opening, &obligation)?;
|
||||
let body_authority = exact_obligation_body_authority(&body_opening, &obligation)?;
|
||||
let (launch, launch_digest) =
|
||||
authenticate_workspace_coverage_managed_process_launch_with_envelope_digest(
|
||||
local_verse_store,
|
||||
|
|
@ -616,6 +619,16 @@ pub(crate) fn load_authenticated_checkpoint_chain(
|
|||
}
|
||||
reversed.reverse();
|
||||
validate_reconstructed_chain(&reversed, &head)?;
|
||||
let closing_body = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
for expected in body_authority {
|
||||
if closing_body
|
||||
.iter()
|
||||
.find(|row| row.r#type == expected.r#type && row.key == expected.key)
|
||||
!= Some(&expected)
|
||||
{
|
||||
bail!("Repository Body changed while reconstructing workspace checkpoint chain");
|
||||
}
|
||||
}
|
||||
Ok(reversed)
|
||||
}
|
||||
|
||||
|
|
@ -759,9 +772,11 @@ pub(crate) fn sign_workspace_coverage_projection_batch_checkpoint(
|
|||
}
|
||||
|
||||
pub(crate) fn admit_workspace_coverage_projection_batch_checkpoint(
|
||||
body_store: impl AsRef<Path>,
|
||||
body_store: &Path,
|
||||
coverage_store: &OwnedRedbMessagePackBackingStore,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
trusted_host: &HostIncarnationIdentityEntry,
|
||||
provider_signing_key: &SigningKey,
|
||||
entry: WorkspaceCoverageProjectionBatchCheckpointEntry,
|
||||
) -> Result<WorkspaceCoverageProjectionBatchCheckpointAdmission> {
|
||||
validate_shape(&entry, true)?;
|
||||
|
|
@ -774,15 +789,27 @@ pub(crate) fn admit_workspace_coverage_projection_batch_checkpoint(
|
|||
trusted_host,
|
||||
)?;
|
||||
validate_launch(&entry, &launch, &launch_envelope_digest)?;
|
||||
let backing = SingleFileMessagePackBackingStore::new(body_store.as_ref());
|
||||
let opening = backing.pull_all()?;
|
||||
let binding_env = find(&opening, BODY_BINDING_TYPE, BODY_BINDING_KEY)?;
|
||||
let head_env = find(&opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?;
|
||||
let observation_env = find(&opening, BODY_OBSERVATION_TYPE, &entry.body_observation_id)?;
|
||||
let manifest_env = find(&opening, BODY_MANIFEST_TYPE, &entry.manifest_root_sha256)?;
|
||||
let opening = coverage_store.pull_all()?;
|
||||
let body_opening = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
let binding_env = find(&body_opening, BODY_BINDING_TYPE, BODY_BINDING_KEY)?;
|
||||
let head_env = find(&body_opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?;
|
||||
let observation_env = find(
|
||||
&body_opening,
|
||||
BODY_OBSERVATION_TYPE,
|
||||
&entry.body_observation_id,
|
||||
)?;
|
||||
let manifest_env = find(
|
||||
&body_opening,
|
||||
BODY_MANIFEST_TYPE,
|
||||
&entry.manifest_root_sha256,
|
||||
)?;
|
||||
let obligation_env = find(&opening, OBLIGATION_TYPE, &entry.obligation_id)?;
|
||||
let plan_env = find(&opening, PLAN_TYPE, &entry.plan_id)?;
|
||||
let claim_env = find(&opening, CLAIM_TYPE, CLAIM_KEY)?;
|
||||
let claim_env = find(
|
||||
&opening,
|
||||
CLAIM_TYPE,
|
||||
&workspace_coverage_claim_key(&entry.body_observation_id, entry.body_generation),
|
||||
)?;
|
||||
let attempt_env = find(&opening, ATTEMPT_TYPE, &entry.attempt_id)?;
|
||||
let binding: RepositoryBodyBinding = decode(binding_env)?;
|
||||
let body_head: RepositoryBodyHead = decode(head_env)?;
|
||||
|
|
@ -796,7 +823,7 @@ pub(crate) fn admit_workspace_coverage_projection_batch_checkpoint(
|
|||
validate_projection_attempt(&attempt)?;
|
||||
validate_claim_attempt_link(&claim, &attempt)?;
|
||||
validate_workspace_coverage_projection_plan(&obligation, &plan)?;
|
||||
exact_obligation_body_authority(&opening, &obligation)?;
|
||||
let body_authority = exact_obligation_body_authority(&body_opening, &obligation)?;
|
||||
validate_authority(
|
||||
&entry,
|
||||
&binding,
|
||||
|
|
@ -872,10 +899,6 @@ pub(crate) fn admit_workspace_coverage_projection_batch_checkpoint(
|
|||
collection_name: entry.collection_name.clone(),
|
||||
};
|
||||
let authority = vec![
|
||||
binding_env.clone(),
|
||||
head_env.clone(),
|
||||
observation_env.clone(),
|
||||
manifest_env.clone(),
|
||||
obligation_env.clone(),
|
||||
plan_env.clone(),
|
||||
claim_env.clone(),
|
||||
|
|
@ -892,13 +915,36 @@ pub(crate) fn admit_workspace_coverage_projection_batch_checkpoint(
|
|||
}
|
||||
replacements.push(event_env);
|
||||
replacements.push(envelope(HEAD_TYPE, &head_key, &next_head)?);
|
||||
if !backing.compare_and_swap_batch(&expected, replacements)? {
|
||||
bail!("workspace coverage checkpoint lost exact Body/plan/claim/head compare-and-swap");
|
||||
}
|
||||
Ok(WorkspaceCoverageProjectionBatchCheckpointAdmission {
|
||||
let admission = WorkspaceCoverageProjectionBatchCheckpointAdmission {
|
||||
checkpoint: entry,
|
||||
checkpoint_envelope_digest: next_head.checkpoint_envelope_digest,
|
||||
})
|
||||
};
|
||||
let (progress_expected, progress_replacements, progress) =
|
||||
crate::workspace_coverage_projection_progress::prepare_workspace_coverage_progress_for_checkpoint(
|
||||
coverage_store,
|
||||
provider_signing_key,
|
||||
&admission,
|
||||
)?;
|
||||
expected.extend(progress_expected);
|
||||
replacements.extend(progress_replacements);
|
||||
if !coverage_store.compare_and_swap_batch(&expected, replacements)? {
|
||||
bail!("workspace coverage checkpoint lost exact coverage authority compare-and-swap");
|
||||
}
|
||||
let closing_body = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
for expected in body_authority {
|
||||
if closing_body
|
||||
.iter()
|
||||
.find(|row| row.r#type == expected.r#type && row.key == expected.key)
|
||||
!= Some(&expected)
|
||||
{
|
||||
bail!("Repository Body changed during workspace coverage checkpoint admission");
|
||||
}
|
||||
}
|
||||
debug_assert_eq!(
|
||||
progress.completed_units,
|
||||
admission.checkpoint.cumulative_point_count
|
||||
);
|
||||
Ok(admission)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
|
@ -1235,6 +1281,17 @@ fn find<'a>(v: &'a [CultCacheEnvelope], t: &str, k: &str) -> Result<&'a CultCach
|
|||
.find(|e| e.r#type == t && e.key == k)
|
||||
.ok_or_else(|| anyhow!("missing authority envelope {t}/{k}"))
|
||||
}
|
||||
fn find_current_claim<'a>(
|
||||
coverage_opening: &'a [CultCacheEnvelope],
|
||||
body_opening: &[CultCacheEnvelope],
|
||||
) -> Result<&'a CultCacheEnvelope> {
|
||||
let head: RepositoryBodyHead = decode(find(body_opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?)?;
|
||||
find(
|
||||
coverage_opening,
|
||||
CLAIM_TYPE,
|
||||
&workspace_coverage_claim_key(&head.observation_id, head.generation),
|
||||
)
|
||||
}
|
||||
fn decode<T: serde::de::DeserializeOwned>(e: &CultCacheEnvelope) -> Result<T> {
|
||||
Ok(rmp_serde::from_slice(&e.payload)?)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,26 +3,25 @@ use crate::workspace_coverage_projection_batch_checkpoint::{
|
|||
WorkspaceCoverageProjectionBatchCheckpointAdmission, load_authenticated_current_checkpoint,
|
||||
};
|
||||
use crate::workspace_coverage_projector::{
|
||||
ATTEMPT_TYPE, CHUNKER_ID, CLAIM_KEY, CLAIM_TYPE, OBLIGATION_TYPE, PLAN_TYPE, PROJECTION_SCHEMA,
|
||||
ATTEMPT_TYPE, CHUNKER_ID, CLAIM_TYPE, OBLIGATION_TYPE, PLAN_TYPE, PROJECTION_SCHEMA,
|
||||
WorkspaceCoverageProjectionAttempt, WorkspaceCoverageProjectionClaim,
|
||||
exact_obligation_body_authority, validate_claim_attempt_link, validate_projection_attempt,
|
||||
validate_projection_claim,
|
||||
validate_projection_claim, workspace_coverage_claim_key,
|
||||
};
|
||||
use crate::workspace_retrieval_coverage::{
|
||||
WorkspaceCoverageObligation, WorkspaceCoverageProjectionPlan,
|
||||
validate_workspace_coverage_projection_plan,
|
||||
};
|
||||
use crate::{
|
||||
HostIncarnationIdentityEntry, WORKSPACE_COVERAGE_MAXIMUM_FILE_BYTES,
|
||||
WorkspaceCoverageManagedProcessLaunchEntry, WorkspaceCoveragePolicy,
|
||||
authenticate_workspace_coverage_managed_process_launch,
|
||||
load_workspace_coverage_managed_process_launch_with_digest, open_epiphany_cultmesh_node,
|
||||
runtime_repository_body_store_binding,
|
||||
BODY_HEAD_KEY, BODY_HEAD_TYPE, HostIncarnationIdentityEntry, RepositoryBodyHead,
|
||||
WORKSPACE_COVERAGE_MAXIMUM_FILE_BYTES, WorkspaceCoverageManagedProcessLaunchEntry,
|
||||
WorkspaceCoveragePolicy, authenticate_workspace_coverage_managed_process_launch,
|
||||
};
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use chrono::DateTime;
|
||||
use cultcache_rs::{
|
||||
CacheBackingStore, CultCacheEnvelope, DatabaseEntry, SingleFileMessagePackBackingStore,
|
||||
CacheBackingStore, CultCacheEnvelope, DatabaseEntry, OwnedRedbMessagePackBackingStore,
|
||||
SingleFileMessagePackBackingStore,
|
||||
};
|
||||
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
||||
use serde::Serialize;
|
||||
|
|
@ -204,7 +203,8 @@ pub(crate) fn sign_workspace_coverage_projection_progress(
|
|||
}
|
||||
|
||||
pub(crate) fn publish_workspace_coverage_progress_genesis(
|
||||
body_store: impl AsRef<Path>,
|
||||
body_store: &Path,
|
||||
coverage_store: &OwnedRedbMessagePackBackingStore,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
runtime_id: &str,
|
||||
trusted_host: &HostIncarnationIdentityEntry,
|
||||
|
|
@ -214,8 +214,9 @@ pub(crate) fn publish_workspace_coverage_progress_genesis(
|
|||
if operation_timeout_ms == 0 {
|
||||
bail!("workspace coverage progress operation timeout must be positive");
|
||||
}
|
||||
let opening = SingleFileMessagePackBackingStore::new(body_store.as_ref()).pull_all()?;
|
||||
let claim_env = find_authority(&opening, CLAIM_TYPE, CLAIM_KEY)?;
|
||||
let opening = coverage_store.pull_all()?;
|
||||
let body_opening = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
let claim_env = find_current_claim(&opening, &body_opening)?;
|
||||
let claim: WorkspaceCoverageProjectionClaim = rmp_serde::from_slice(&claim_env.payload)?;
|
||||
let attempt_env = find_authority(&opening, ATTEMPT_TYPE, &claim.attempt_id)?;
|
||||
let attempt: WorkspaceCoverageProjectionAttempt = rmp_serde::from_slice(&attempt_env.payload)?;
|
||||
|
|
@ -230,7 +231,7 @@ pub(crate) fn publish_workspace_coverage_progress_genesis(
|
|||
let obligation: WorkspaceCoverageObligation = rmp_serde::from_slice(&obligation_env.payload)?;
|
||||
let plan: WorkspaceCoverageProjectionPlan = rmp_serde::from_slice(&plan_env.payload)?;
|
||||
validate_workspace_coverage_projection_plan(&obligation, &plan)?;
|
||||
exact_obligation_body_authority(&opening, &obligation)?;
|
||||
let body_authority = exact_obligation_body_authority(&body_opening, &obligation)?;
|
||||
let (launch, launch_digest) =
|
||||
authenticate_workspace_coverage_managed_process_launch_with_envelope_digest(
|
||||
local_verse_store.as_ref(),
|
||||
|
|
@ -247,8 +248,7 @@ pub(crate) fn publish_workspace_coverage_progress_genesis(
|
|||
bail!("workspace coverage progress genesis signer/launch/Body authority disagrees");
|
||||
}
|
||||
if load_latest_workspace_coverage_projection_progress(
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
coverage_store,
|
||||
&launch.launch_id,
|
||||
&claim.claim_id,
|
||||
)?
|
||||
|
|
@ -289,54 +289,44 @@ pub(crate) fn publish_workspace_coverage_progress_genesis(
|
|||
signature_algorithm: "ed25519".into(),
|
||||
};
|
||||
sign_workspace_coverage_projection_progress(&mut entry, provider_signing_key)?;
|
||||
let admitted = write_workspace_coverage_projection_progress(
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
entry,
|
||||
)?;
|
||||
// Body and Verse are distinct stores and cannot share an atomic CAS. A
|
||||
// progress event is therefore provider observation only. Reopen Body after
|
||||
// Verse admission and require the exact authority envelopes used above;
|
||||
// downstream use must repeat Body/checkpoint authentication rather than
|
||||
// treating this event as a capability.
|
||||
let after = SingleFileMessagePackBackingStore::new(body_store.as_ref()).pull_all()?;
|
||||
for expected in [claim_env, attempt_env, obligation_env, plan_env] {
|
||||
let current = find_authority(&after, &expected.r#type, &expected.key)?;
|
||||
if current.r#type != expected.r#type
|
||||
|| current.key != expected.key
|
||||
|| current.payload != expected.payload
|
||||
let published = write_workspace_coverage_projection_progress(coverage_store, entry)?;
|
||||
let closing_body = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
for expected in body_authority {
|
||||
if closing_body
|
||||
.iter()
|
||||
.find(|entry| entry.r#type == expected.r#type && entry.key == expected.key)
|
||||
!= Some(&expected)
|
||||
{
|
||||
bail!("Body authority changed during cross-store progress genesis admission");
|
||||
bail!("Repository Body changed during workspace coverage progress genesis");
|
||||
}
|
||||
}
|
||||
exact_obligation_body_authority(&after, &obligation)?;
|
||||
Ok(admitted)
|
||||
Ok(published)
|
||||
}
|
||||
|
||||
pub(crate) fn publish_workspace_coverage_progress_for_checkpoint(
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
runtime_id: &str,
|
||||
pub(crate) fn prepare_workspace_coverage_progress_for_checkpoint(
|
||||
coverage_store: &OwnedRedbMessagePackBackingStore,
|
||||
provider_signing_key: &SigningKey,
|
||||
admission: &WorkspaceCoverageProjectionBatchCheckpointAdmission,
|
||||
) -> Result<WorkspaceCoverageProjectionProgressEntry> {
|
||||
) -> Result<(
|
||||
Vec<CultCacheEnvelope>,
|
||||
Vec<CultCacheEnvelope>,
|
||||
WorkspaceCoverageProjectionProgressEntry,
|
||||
)> {
|
||||
let checkpoint = &admission.checkpoint;
|
||||
if checkpoint.runtime_id != runtime_id {
|
||||
bail!("checkpoint progress runtime disagrees with admission");
|
||||
}
|
||||
let prior = load_latest_workspace_coverage_projection_progress(
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
&checkpoint.managed_process_launch_id,
|
||||
&checkpoint.claim_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("checkpoint progress requires canonical genesis"))?;
|
||||
let prior_key = latest_key(&checkpoint.managed_process_launch_id, &checkpoint.claim_id);
|
||||
let opening = coverage_store.pull_all()?;
|
||||
let prior_env = opening
|
||||
.iter()
|
||||
.find(|env| {
|
||||
env.r#type == WORKSPACE_COVERAGE_PROJECTION_PROGRESS_TYPE && env.key == prior_key
|
||||
})
|
||||
.cloned()
|
||||
.ok_or_else(|| anyhow!("checkpoint progress requires canonical genesis"))?;
|
||||
let prior: WorkspaceCoverageProjectionProgressEntry = decode(&prior_env)?;
|
||||
let expected_sequence = checkpoint
|
||||
.sequence
|
||||
.checked_add(1)
|
||||
.ok_or_else(|| anyhow!("checkpoint sequence exhausted"))?;
|
||||
if checkpoint_progress_alignment(&prior, admission)? == CheckpointProgressAlignment::Current {
|
||||
return Ok(prior);
|
||||
}
|
||||
if prior.sequence != checkpoint.sequence
|
||||
|| checkpoint.cumulative_point_count <= prior.completed_units
|
||||
{
|
||||
|
|
@ -346,7 +336,7 @@ pub(crate) fn publish_workspace_coverage_progress_for_checkpoint(
|
|||
let mut entry = WorkspaceCoverageProjectionProgressEntry {
|
||||
schema_version: WORKSPACE_COVERAGE_PROJECTION_PROGRESS_SCHEMA_VERSION.into(),
|
||||
progress_id: uuid::Uuid::new_v4().to_string(),
|
||||
runtime_id: runtime_id.into(),
|
||||
runtime_id: checkpoint.runtime_id.clone(),
|
||||
launch_id: checkpoint.managed_process_launch_id.clone(),
|
||||
launch_envelope_digest: checkpoint.managed_process_launch_envelope_digest.clone(),
|
||||
provider_incarnation_id: checkpoint.provider_incarnation_id.clone(),
|
||||
|
|
@ -375,19 +365,22 @@ pub(crate) fn publish_workspace_coverage_progress_for_checkpoint(
|
|||
signature_algorithm: "ed25519".into(),
|
||||
};
|
||||
sign_workspace_coverage_projection_progress(&mut entry, provider_signing_key)?;
|
||||
write_workspace_coverage_projection_progress(local_verse_store, runtime_id, entry)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum CheckpointProgressAlignment {
|
||||
NeedsReconciliation,
|
||||
Current,
|
||||
validate_shape(&entry, true)?;
|
||||
validate_transition(&prior, &entry)?;
|
||||
let event_key = progress_key(&entry.progress_id);
|
||||
let latest_key = latest_key(&entry.launch_id, &entry.claim_id);
|
||||
let expected = vec![prior_env];
|
||||
let replacements = vec![
|
||||
progress_envelope(&event_key, &entry)?,
|
||||
progress_envelope(&latest_key, &entry)?,
|
||||
];
|
||||
Ok((expected, replacements, entry))
|
||||
}
|
||||
|
||||
fn checkpoint_progress_alignment(
|
||||
progress: &WorkspaceCoverageProjectionProgressEntry,
|
||||
admission: &WorkspaceCoverageProjectionBatchCheckpointAdmission,
|
||||
) -> Result<CheckpointProgressAlignment> {
|
||||
) -> Result<()> {
|
||||
let checkpoint = &admission.checkpoint;
|
||||
checkpoint_progress_binding_alignment(
|
||||
progress,
|
||||
|
|
@ -404,83 +397,43 @@ fn checkpoint_progress_binding_alignment(
|
|||
checkpoint_id: &str,
|
||||
checkpoint_digest: &str,
|
||||
cumulative_point_count: u64,
|
||||
) -> Result<CheckpointProgressAlignment> {
|
||||
) -> Result<()> {
|
||||
let expected = checkpoint_sequence
|
||||
.checked_add(1)
|
||||
.ok_or_else(|| anyhow!("checkpoint sequence exhausted"))?;
|
||||
if progress.sequence == checkpoint_sequence {
|
||||
return Ok(CheckpointProgressAlignment::NeedsReconciliation);
|
||||
}
|
||||
if progress.sequence == expected
|
||||
&& progress.checkpoint_id.as_deref() == Some(checkpoint_id)
|
||||
&& progress.checkpoint_binding_sha256.as_deref() == Some(checkpoint_digest)
|
||||
&& progress.completed_units == cumulative_point_count
|
||||
{
|
||||
return Ok(CheckpointProgressAlignment::Current);
|
||||
return Ok(());
|
||||
}
|
||||
bail!("progress does not map exactly to the authenticated current checkpoint")
|
||||
}
|
||||
|
||||
pub(crate) fn reconcile_workspace_coverage_checkpoint_progress(
|
||||
body_store: impl AsRef<Path>,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
runtime_id: &str,
|
||||
trusted_host: &HostIncarnationIdentityEntry,
|
||||
provider_signing_key: &SigningKey,
|
||||
claim_id: &str,
|
||||
claim_epoch: u64,
|
||||
) -> Result<Option<WorkspaceCoverageProjectionProgressEntry>> {
|
||||
let Some(admission) = load_authenticated_current_checkpoint(
|
||||
body_store,
|
||||
local_verse_store.as_ref(),
|
||||
trusted_host,
|
||||
claim_id,
|
||||
claim_epoch,
|
||||
)?
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
if admission.checkpoint.runtime_id != runtime_id {
|
||||
bail!("current checkpoint runtime disagrees with reconciliation runtime");
|
||||
}
|
||||
publish_workspace_coverage_progress_for_checkpoint(
|
||||
local_verse_store,
|
||||
runtime_id,
|
||||
provider_signing_key,
|
||||
&admission,
|
||||
)
|
||||
.map(Some)
|
||||
}
|
||||
|
||||
pub(crate) fn write_workspace_coverage_projection_progress(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
store: &OwnedRedbMessagePackBackingStore,
|
||||
entry: WorkspaceCoverageProjectionProgressEntry,
|
||||
) -> Result<WorkspaceCoverageProjectionProgressEntry> {
|
||||
validate_shape(&entry, true)?;
|
||||
let runtime_id = runtime_id.into();
|
||||
if runtime_id != entry.runtime_id {
|
||||
bail!("workspace coverage progress runtime argument disagrees with signed runtime id");
|
||||
}
|
||||
let store_path = store_path.as_ref();
|
||||
let (launch, launch_digest) = load_workspace_coverage_managed_process_launch_with_digest(
|
||||
store_path,
|
||||
runtime_id.clone(),
|
||||
&entry.launch_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("workspace coverage progress launch is absent"))?;
|
||||
authenticate_against_launch(&entry, &launch, &launch_digest)?;
|
||||
let node = open_epiphany_cultmesh_node(store_path, runtime_id)?;
|
||||
verify_signature(&entry)?;
|
||||
let opening = store.pull_all()?;
|
||||
let event_key = progress_key(&entry.progress_id);
|
||||
if let Some(existing) = node.get::<WorkspaceCoverageProjectionProgressEntry>(&event_key)? {
|
||||
if let Some(existing_env) = opening.iter().find(|env| {
|
||||
env.r#type == WORKSPACE_COVERAGE_PROJECTION_PROGRESS_TYPE && env.key == event_key
|
||||
}) {
|
||||
let existing: WorkspaceCoverageProjectionProgressEntry = decode(existing_env)?;
|
||||
if existing_event_is_idempotent(&existing, &entry)? {
|
||||
return Ok(existing);
|
||||
}
|
||||
}
|
||||
let latest_key = latest_key(&entry.launch_id, &entry.claim_id);
|
||||
let latest = node
|
||||
.cache()
|
||||
.get_envelope::<WorkspaceCoverageProjectionProgressEntry>(&latest_key)?;
|
||||
let latest = opening
|
||||
.iter()
|
||||
.find(|env| {
|
||||
env.r#type == WORKSPACE_COVERAGE_PROJECTION_PROGRESS_TYPE && env.key == latest_key
|
||||
})
|
||||
.cloned();
|
||||
let mut expected = Vec::new();
|
||||
if let Some(envelope) = latest.as_ref() {
|
||||
let prior: WorkspaceCoverageProjectionProgressEntry =
|
||||
|
|
@ -491,62 +444,54 @@ pub(crate) fn write_workspace_coverage_projection_progress(
|
|||
bail!("first workspace coverage progress sequence must be one");
|
||||
}
|
||||
let replacements = vec![
|
||||
node.cache().prepare_entry(&event_key, &entry)?.0,
|
||||
node.cache().prepare_entry(&latest_key, &entry)?.0,
|
||||
progress_envelope(&event_key, &entry)?,
|
||||
progress_envelope(&latest_key, &entry)?,
|
||||
];
|
||||
if !SingleFileMessagePackBackingStore::new(store_path)
|
||||
.compare_and_swap_batch(&expected, replacements)?
|
||||
{
|
||||
if !store.compare_and_swap_batch(&expected, replacements)? {
|
||||
bail!("workspace coverage progress lost exact launch/claim latest compare-and-swap");
|
||||
}
|
||||
Ok(entry)
|
||||
}
|
||||
|
||||
pub fn load_workspace_coverage_projection_progress(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
store: &OwnedRedbMessagePackBackingStore,
|
||||
progress_id: &str,
|
||||
) -> Result<Option<WorkspaceCoverageProjectionProgressEntry>> {
|
||||
require("progress id", progress_id)?;
|
||||
open_epiphany_cultmesh_node(store_path, runtime_id)?.get(&progress_key(progress_id))
|
||||
load_progress(store, &progress_key(progress_id))
|
||||
}
|
||||
|
||||
pub fn load_latest_workspace_coverage_projection_progress(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
store: &OwnedRedbMessagePackBackingStore,
|
||||
launch_id: &str,
|
||||
claim_id: &str,
|
||||
) -> Result<Option<WorkspaceCoverageProjectionProgressEntry>> {
|
||||
require("launch id", launch_id)?;
|
||||
require("claim id", claim_id)?;
|
||||
open_epiphany_cultmesh_node(store_path, runtime_id)?.get(&latest_key(launch_id, claim_id))
|
||||
load_progress(store, &latest_key(launch_id, claim_id))
|
||||
}
|
||||
|
||||
pub fn authenticate_workspace_coverage_projection_progress(
|
||||
store_path: impl AsRef<Path>,
|
||||
runtime_id: impl Into<String>,
|
||||
store: &OwnedRedbMessagePackBackingStore,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
runtime_id: &str,
|
||||
progress_id: &str,
|
||||
host: &HostIncarnationIdentityEntry,
|
||||
) -> Result<WorkspaceCoverageProjectionProgressEntry> {
|
||||
let runtime_id = runtime_id.into();
|
||||
let entry = load_workspace_coverage_projection_progress(
|
||||
store_path.as_ref(),
|
||||
runtime_id.clone(),
|
||||
progress_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("workspace coverage progress is absent"))?;
|
||||
let entry = load_workspace_coverage_projection_progress(store, progress_id)?
|
||||
.ok_or_else(|| anyhow!("workspace coverage progress is absent"))?;
|
||||
let launch = authenticate_workspace_coverage_managed_process_launch(
|
||||
store_path.as_ref(),
|
||||
runtime_id.clone(),
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
&entry.launch_id,
|
||||
host,
|
||||
)?;
|
||||
let (_, digest) = load_workspace_coverage_managed_process_launch_with_digest(
|
||||
store_path.as_ref(),
|
||||
runtime_id.clone(),
|
||||
let (_, digest) = authenticate_workspace_coverage_managed_process_launch_with_envelope_digest(
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
&entry.launch_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("workspace coverage progress launch is absent"))?;
|
||||
host,
|
||||
)?;
|
||||
authenticate_against_launch(&entry, &launch, &digest)?;
|
||||
Ok(entry)
|
||||
}
|
||||
|
|
@ -556,7 +501,8 @@ pub fn authenticate_workspace_coverage_projection_progress(
|
|||
/// consulted here. The supervisor separately joins this evidence to the exact
|
||||
/// live managed process and applies its own no-advance lease.
|
||||
pub fn authenticate_current_workspace_coverage_advancement(
|
||||
runtime_store: impl AsRef<Path>,
|
||||
body_store: &Path,
|
||||
coverage_store: &OwnedRedbMessagePackBackingStore,
|
||||
local_verse_store: impl AsRef<Path>,
|
||||
runtime_id: &str,
|
||||
launch_id: &str,
|
||||
|
|
@ -567,11 +513,10 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
if no_advance_lease <= chrono::Duration::zero() {
|
||||
bail!("workspace coverage no-advance lease must be positive");
|
||||
}
|
||||
let route = runtime_repository_body_store_binding(runtime_store.as_ref())?
|
||||
.ok_or_else(|| anyhow!("runtime has no repository Body-store binding"))?;
|
||||
let opening = SingleFileMessagePackBackingStore::new(&route.body_store_path).pull_all()?;
|
||||
let opening = coverage_store.pull_all()?;
|
||||
let body_opening = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
let claim: WorkspaceCoverageProjectionClaim =
|
||||
decode(find_authority(&opening, CLAIM_TYPE, CLAIM_KEY)?)?;
|
||||
decode(find_current_claim(&opening, &body_opening)?)?;
|
||||
validate_projection_claim(&claim)?;
|
||||
let attempt: WorkspaceCoverageProjectionAttempt =
|
||||
decode(find_authority(&opening, ATTEMPT_TYPE, &claim.attempt_id)?)?;
|
||||
|
|
@ -588,7 +533,7 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
let plan: WorkspaceCoverageProjectionPlan =
|
||||
decode(find_authority(&opening, PLAN_TYPE, &claim.plan_id)?)?;
|
||||
validate_workspace_coverage_projection_plan(&obligation, &plan)?;
|
||||
exact_obligation_body_authority(&opening, &obligation)?;
|
||||
let body_authority = exact_obligation_body_authority(&body_opening, &obligation)?;
|
||||
let policy =
|
||||
WorkspaceCoveragePolicy::bounded_regular_files_v0(WORKSPACE_COVERAGE_MAXIMUM_FILE_BYTES)?;
|
||||
let policy_sha256 = format!(
|
||||
|
|
@ -604,8 +549,7 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
}
|
||||
|
||||
let Some(latest) = load_latest_workspace_coverage_projection_progress(
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
coverage_store,
|
||||
launch_id,
|
||||
&claim.claim_id,
|
||||
)?
|
||||
|
|
@ -613,6 +557,7 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
return Ok(None);
|
||||
};
|
||||
let progress = authenticate_workspace_coverage_projection_progress(
|
||||
coverage_store,
|
||||
local_verse_store.as_ref(),
|
||||
runtime_id,
|
||||
&latest.progress_id,
|
||||
|
|
@ -631,7 +576,8 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
return Ok(None);
|
||||
}
|
||||
let Some(checkpoint) = load_authenticated_current_checkpoint(
|
||||
&route.body_store_path,
|
||||
body_store,
|
||||
coverage_store,
|
||||
local_verse_store.as_ref(),
|
||||
host,
|
||||
&claim.claim_id,
|
||||
|
|
@ -640,11 +586,7 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
if checkpoint_progress_alignment(&progress, &checkpoint)?
|
||||
!= CheckpointProgressAlignment::Current
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
checkpoint_progress_alignment(&progress, &checkpoint)?;
|
||||
if !progress_is_within_no_advance_lease(
|
||||
&progress.last_advanced_at_utc,
|
||||
observed_at,
|
||||
|
|
@ -652,7 +594,7 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
)? {
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(WorkspaceCoverageAdvancingAuthority {
|
||||
let authority = WorkspaceCoverageAdvancingAuthority {
|
||||
progress_id: progress.progress_id,
|
||||
checkpoint_id: checkpoint.checkpoint.checkpoint_id,
|
||||
checkpoint_binding_sha256: checkpoint.checkpoint_envelope_digest,
|
||||
|
|
@ -662,7 +604,18 @@ pub fn authenticate_current_workspace_coverage_advancement(
|
|||
completed_units: progress.completed_units,
|
||||
total_units: progress.total_units,
|
||||
last_advanced_at_utc: progress.last_advanced_at_utc,
|
||||
}))
|
||||
};
|
||||
let closing_body = SingleFileMessagePackBackingStore::new(body_store).pull_all()?;
|
||||
for expected in body_authority {
|
||||
if closing_body
|
||||
.iter()
|
||||
.find(|row| row.r#type == expected.r#type && row.key == expected.key)
|
||||
!= Some(&expected)
|
||||
{
|
||||
bail!("Repository Body changed while authenticating workspace advancement");
|
||||
}
|
||||
}
|
||||
Ok(Some(authority))
|
||||
}
|
||||
|
||||
fn progress_is_within_no_advance_lease(
|
||||
|
|
@ -924,12 +877,47 @@ fn find_authority<'a>(
|
|||
.find(|entry| entry.r#type == ty && entry.key == key)
|
||||
.ok_or_else(|| anyhow!("workspace coverage progress authority {ty}/{key} is absent"))
|
||||
}
|
||||
fn find_current_claim<'a>(
|
||||
coverage_opening: &'a [CultCacheEnvelope],
|
||||
body_opening: &[CultCacheEnvelope],
|
||||
) -> Result<&'a CultCacheEnvelope> {
|
||||
let head: RepositoryBodyHead =
|
||||
decode(find_authority(body_opening, BODY_HEAD_TYPE, BODY_HEAD_KEY)?)?;
|
||||
find_authority(
|
||||
coverage_opening,
|
||||
CLAIM_TYPE,
|
||||
&workspace_coverage_claim_key(&head.observation_id, head.generation),
|
||||
)
|
||||
}
|
||||
fn decode<T: serde::de::DeserializeOwned>(entry: &CultCacheEnvelope) -> Result<T> {
|
||||
rmp_serde::from_slice(&entry.payload).context("decoding workspace coverage progress authority")
|
||||
}
|
||||
fn progress_key(id: &str) -> String {
|
||||
format!("epiphany-local/workspace-coverage/projection-progress/event/{id}")
|
||||
}
|
||||
fn progress_envelope(
|
||||
key: &str,
|
||||
entry: &WorkspaceCoverageProjectionProgressEntry,
|
||||
) -> Result<CultCacheEnvelope> {
|
||||
Ok(CultCacheEnvelope {
|
||||
r#type: WORKSPACE_COVERAGE_PROJECTION_PROGRESS_TYPE.into(),
|
||||
key: key.into(),
|
||||
payload: rmp_serde::to_vec(entry)?,
|
||||
stored_at: chrono::Utc::now().to_rfc3339(),
|
||||
schema_id: Some(WORKSPACE_COVERAGE_PROJECTION_PROGRESS_TYPE.into()),
|
||||
})
|
||||
}
|
||||
fn load_progress(
|
||||
store: &OwnedRedbMessagePackBackingStore,
|
||||
key: &str,
|
||||
) -> Result<Option<WorkspaceCoverageProjectionProgressEntry>> {
|
||||
store
|
||||
.pull_all()?
|
||||
.iter()
|
||||
.find(|env| env.r#type == WORKSPACE_COVERAGE_PROJECTION_PROGRESS_TYPE && env.key == key)
|
||||
.map(decode)
|
||||
.transpose()
|
||||
}
|
||||
fn latest_key(launch: &str, claim: &str) -> String {
|
||||
format!("epiphany-local/workspace-coverage/projection-progress/latest/{launch}/{claim}")
|
||||
}
|
||||
|
|
@ -1030,10 +1018,10 @@ mod tests {
|
|||
}
|
||||
}
|
||||
#[test]
|
||||
fn checkpoint_progress_restart_mapping_is_exact_and_idempotent() {
|
||||
fn checkpoint_progress_mapping_rejects_every_split_state() {
|
||||
let k = SigningKey::from_bytes(&[7; 32]);
|
||||
let genesis = entry(&k);
|
||||
assert_eq!(
|
||||
assert!(
|
||||
checkpoint_progress_binding_alignment(
|
||||
&genesis,
|
||||
1,
|
||||
|
|
@ -1041,20 +1029,15 @@ mod tests {
|
|||
&format!("sha256-{}", "b".repeat(64)),
|
||||
1
|
||||
)
|
||||
.unwrap(),
|
||||
CheckpointProgressAlignment::NeedsReconciliation
|
||||
.is_err()
|
||||
);
|
||||
let current = advance(&genesis, &k);
|
||||
let digest = current.checkpoint_binding_sha256.clone().unwrap();
|
||||
let id = current.checkpoint_id.clone().unwrap();
|
||||
assert_eq!(
|
||||
checkpoint_progress_binding_alignment(¤t, 1, &id, &digest, 1).unwrap(),
|
||||
CheckpointProgressAlignment::Current
|
||||
);
|
||||
assert_eq!(
|
||||
checkpoint_progress_binding_alignment(¤t, 1, &id, &digest, 1).unwrap();
|
||||
assert!(
|
||||
checkpoint_progress_binding_alignment(¤t, 2, "next-checkpoint", &digest, 2)
|
||||
.unwrap(),
|
||||
CheckpointProgressAlignment::NeedsReconciliation
|
||||
.is_err()
|
||||
);
|
||||
let mut skipped = current.clone();
|
||||
skipped.sequence = 3;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,34 +1,23 @@
|
|||
use crate::repository_body_observer::RepositoryBodyReadSession;
|
||||
use crate::semantic_backend::{OllamaConfig, OllamaEmbedder, QdrantBackend, QdrantConfig};
|
||||
use crate::workspace_coverage_process_documents::publish_workspace_coverage_terminal_sight;
|
||||
use crate::workspace_coverage_projector::{
|
||||
WorkspaceCoverageAcquireResult, WorkspaceCoverageCurrentState,
|
||||
WorkspaceCoverageProjectionExecutionAuthority, acquire_workspace_coverage_projection,
|
||||
classify_current_workspace_coverage, execute_workspace_coverage_projection,
|
||||
prepare_workspace_coverage_projection, retire_workspace_coverage_collections,
|
||||
classify_current_workspace_coverage, compact_workspace_coverage_history,
|
||||
execute_workspace_coverage_projection, prepare_workspace_coverage_projection,
|
||||
retire_workspace_coverage_collections,
|
||||
};
|
||||
use crate::{
|
||||
EPIPHANY_WORKSPACE_COVERAGE_PROJECTOR_DAEMON_ID, HostIncarnationIdentityEntry,
|
||||
load_current_runtime_repository_body_basis, runtime_repository_body_store_binding,
|
||||
WorkspaceCoverageAuthority, load_current_runtime_repository_body_basis,
|
||||
open_workspace_coverage_authority, runtime_repository_body_store_binding,
|
||||
};
|
||||
use anyhow::{Context, Result, anyhow, bail};
|
||||
use ed25519_dalek::SigningKey;
|
||||
use sha2::{Digest, Sha256};
|
||||
#[cfg(windows)]
|
||||
use std::ffi::OsStr;
|
||||
#[cfg(unix)]
|
||||
use std::fs::File;
|
||||
#[cfg(unix)]
|
||||
use std::os::fd::AsRawFd;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[cfg(windows)]
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, ERROR_ALREADY_EXISTS, GetLastError, HANDLE};
|
||||
#[cfg(windows)]
|
||||
use windows_sys::Win32::System::Threading::{CreateMutexW, ReleaseMutex};
|
||||
|
||||
const EMBEDDING_PROVIDER_ID: &str = "gamecult-ollama-embedding";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
|
@ -89,85 +78,8 @@ pub struct WorkspaceCoverageProjectorServicePulse {
|
|||
pub fault: Option<String>,
|
||||
}
|
||||
|
||||
struct WorkspaceCoverageProjectorSingletonGuard {
|
||||
#[cfg(windows)]
|
||||
handle: HANDLE,
|
||||
#[cfg(unix)]
|
||||
file: File,
|
||||
}
|
||||
|
||||
impl Drop for WorkspaceCoverageProjectorSingletonGuard {
|
||||
fn drop(&mut self) {
|
||||
#[cfg(windows)]
|
||||
unsafe {
|
||||
let _ = ReleaseMutex(self.handle);
|
||||
CloseHandle(self.handle);
|
||||
}
|
||||
#[cfg(unix)]
|
||||
unsafe {
|
||||
let _ = libc::flock(self.file.as_raw_fd(), libc::LOCK_UN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn acquire_workspace_coverage_projector_singleton(
|
||||
runtime_store: &Path,
|
||||
body_store: &Path,
|
||||
) -> Result<WorkspaceCoverageProjectorSingletonGuard> {
|
||||
let identity = format!(
|
||||
"{:x}",
|
||||
Sha256::digest(
|
||||
format!(
|
||||
"{}|{}",
|
||||
runtime_store.to_string_lossy().to_lowercase(),
|
||||
body_store.to_string_lossy().to_lowercase()
|
||||
)
|
||||
.as_bytes()
|
||||
)
|
||||
);
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let name = OsStr::new(&format!(
|
||||
"Global\\EpiphanyWorkspaceCoverageProjector-{identity}"
|
||||
))
|
||||
.encode_wide()
|
||||
.chain(std::iter::once(0))
|
||||
.collect::<Vec<_>>();
|
||||
let handle = unsafe { CreateMutexW(std::ptr::null_mut(), 1, name.as_ptr()) };
|
||||
if handle.is_null() {
|
||||
return Err(anyhow!(
|
||||
"workspace coverage projector singleton mutex creation failed: {}",
|
||||
unsafe { GetLastError() }
|
||||
));
|
||||
}
|
||||
if unsafe { GetLastError() } == ERROR_ALREADY_EXISTS {
|
||||
unsafe { CloseHandle(handle) };
|
||||
bail!("workspace coverage projector owner already exists for this runtime Body route");
|
||||
}
|
||||
return Ok(WorkspaceCoverageProjectorSingletonGuard { handle });
|
||||
}
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let path =
|
||||
std::env::temp_dir().join(format!("epiphany-workspace-coverage-{identity}.lock"));
|
||||
let file = File::options()
|
||||
.create(true)
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(path)?;
|
||||
if unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) } != 0 {
|
||||
bail!("workspace coverage projector owner already exists for this runtime Body route");
|
||||
}
|
||||
return Ok(WorkspaceCoverageProjectorSingletonGuard { file });
|
||||
}
|
||||
#[allow(unreachable_code)]
|
||||
Err(anyhow!(
|
||||
"workspace coverage projector singleton is unsupported on this platform"
|
||||
))
|
||||
}
|
||||
|
||||
pub struct WorkspaceCoverageProjectorServiceBody {
|
||||
_singleton: WorkspaceCoverageProjectorSingletonGuard,
|
||||
coverage_authority: WorkspaceCoverageAuthority,
|
||||
runtime_store: PathBuf,
|
||||
executor_incarnation: String,
|
||||
managed_process_launch_id: String,
|
||||
|
|
@ -220,9 +132,7 @@ impl WorkspaceCoverageProjectorServiceBody {
|
|||
"workspace coverage projector runtime Body route disagrees with authenticated runtime id"
|
||||
);
|
||||
}
|
||||
let body_store = PathBuf::from(route.body_store_path);
|
||||
let singleton =
|
||||
acquire_workspace_coverage_projector_singleton(&runtime_store, &body_store)?;
|
||||
let coverage_authority = open_workspace_coverage_authority(&runtime_store)?;
|
||||
let operation_timeout_ms = config.qdrant_timeout_ms;
|
||||
let qdrant = QdrantBackend::new(QdrantConfig {
|
||||
url: config.qdrant_url,
|
||||
|
|
@ -236,7 +146,7 @@ impl WorkspaceCoverageProjectorServiceBody {
|
|||
query_instruction: String::new(),
|
||||
})?;
|
||||
Ok(Self {
|
||||
_singleton: singleton,
|
||||
coverage_authority,
|
||||
runtime_store,
|
||||
executor_incarnation,
|
||||
managed_process_launch_id,
|
||||
|
|
@ -304,12 +214,11 @@ impl WorkspaceCoverageProjectorServiceBody {
|
|||
}
|
||||
|
||||
fn pulse_inner(&mut self) -> Result<WorkspaceCoverageProjectorServicePulse> {
|
||||
let route = runtime_repository_body_store_binding(&self.runtime_store)?
|
||||
.ok_or_else(|| anyhow!("runtime has no repository Body-store binding"))?;
|
||||
// Retirement is derived from typed Body history and is deliberately
|
||||
// performed before the idle fast path. Qdrant never nominates its own
|
||||
// garbage and incompatible same-name collections stop the pulse.
|
||||
retire_workspace_coverage_collections(&route.body_store_path, &mut self.qdrant)?;
|
||||
retire_workspace_coverage_collections(&self.coverage_authority, &mut self.qdrant)?;
|
||||
let _ = compact_workspace_coverage_history(&self.runtime_store, &self.coverage_authority)?;
|
||||
let basis = load_current_runtime_repository_body_basis(&self.runtime_store)?;
|
||||
// Tags are mutable. Re-resolve the installed artifact every pulse so a
|
||||
// same-dimensional model replacement cannot reuse an older index.
|
||||
|
|
@ -318,12 +227,26 @@ impl WorkspaceCoverageProjectorServiceBody {
|
|||
if let WorkspaceCoverageCurrentState::Current(receipt) =
|
||||
classify_current_workspace_coverage(
|
||||
&self.runtime_store,
|
||||
&self.coverage_authority.store,
|
||||
&basis,
|
||||
EMBEDDING_PROVIDER_ID,
|
||||
&embedding_model_identity,
|
||||
dimensions,
|
||||
)?
|
||||
{
|
||||
let authority = self.execution_authority.as_ref().ok_or_else(|| {
|
||||
anyhow!("workspace coverage projector has no installed execution authority")
|
||||
})?;
|
||||
publish_workspace_coverage_terminal_sight(
|
||||
&authority.local_verse_store,
|
||||
&self.runtime_store,
|
||||
&self.coverage_authority,
|
||||
&authority.runtime_id,
|
||||
&self.managed_process_launch_id,
|
||||
&authority.trusted_host,
|
||||
&authority.provider_signing_key,
|
||||
chrono::Utc::now(),
|
||||
)?;
|
||||
return Ok(WorkspaceCoverageProjectorServicePulse {
|
||||
status: WorkspaceCoverageProjectorPulseStatus::Idle,
|
||||
body_observation_id: Some(basis.observation_id),
|
||||
|
|
@ -343,6 +266,7 @@ impl WorkspaceCoverageProjectorServiceBody {
|
|||
let plan_id = prepared.plan.plan_id.clone();
|
||||
match acquire_workspace_coverage_projection(
|
||||
&prepared,
|
||||
&self.coverage_authority.store,
|
||||
EPIPHANY_WORKSPACE_COVERAGE_PROJECTOR_DAEMON_ID,
|
||||
&self.executor_incarnation,
|
||||
&self.managed_process_launch_id,
|
||||
|
|
@ -358,6 +282,19 @@ impl WorkspaceCoverageProjectorServiceBody {
|
|||
})
|
||||
}
|
||||
WorkspaceCoverageAcquireResult::Current(receipt) => {
|
||||
let authority = self.execution_authority.as_ref().ok_or_else(|| {
|
||||
anyhow!("workspace coverage projector has no installed execution authority")
|
||||
})?;
|
||||
publish_workspace_coverage_terminal_sight(
|
||||
&authority.local_verse_store,
|
||||
&self.runtime_store,
|
||||
&self.coverage_authority,
|
||||
&authority.runtime_id,
|
||||
&self.managed_process_launch_id,
|
||||
&authority.trusted_host,
|
||||
&authority.provider_signing_key,
|
||||
chrono::Utc::now(),
|
||||
)?;
|
||||
Ok(WorkspaceCoverageProjectorServicePulse {
|
||||
status: WorkspaceCoverageProjectorPulseStatus::Idle,
|
||||
body_observation_id: Some(basis.observation_id),
|
||||
|
|
@ -377,6 +314,8 @@ impl WorkspaceCoverageProjectorServiceBody {
|
|||
&self.embedder,
|
||||
&mut self.qdrant,
|
||||
&WorkspaceCoverageProjectionExecutionAuthority {
|
||||
coverage_authority: &self.coverage_authority,
|
||||
runtime_store: &self.runtime_store,
|
||||
local_verse_store: &authority.local_verse_store,
|
||||
runtime_id: &authority.runtime_id,
|
||||
trusted_host: &authority.trusted_host,
|
||||
|
|
@ -447,18 +386,59 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn singleton_is_host_wide_for_one_canonical_runtime_body_pair() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let runtime = temp.path().join("runtime.ccmp");
|
||||
let body = temp.path().join("body.ccmp");
|
||||
std::fs::write(&runtime, [])?;
|
||||
std::fs::write(&body, [])?;
|
||||
let runtime = runtime.canonicalize()?;
|
||||
let body = body.canonicalize()?;
|
||||
let first = acquire_workspace_coverage_projector_singleton(&runtime, &body)?;
|
||||
assert!(acquire_workspace_coverage_projector_singleton(&runtime, &body).is_err());
|
||||
fn live_service_exclusively_owns_the_bound_coverage_store() -> Result<()> {
|
||||
let state = tempfile::tempdir()?;
|
||||
let repo = tempfile::tempdir()?;
|
||||
let initialized = std::process::Command::new("git")
|
||||
.arg("init")
|
||||
.current_dir(repo.path())
|
||||
.output()?;
|
||||
if !initialized.status.success() {
|
||||
bail!("singleton fixture failed to initialize repository");
|
||||
}
|
||||
let runtime = state.path().join("runtime.cc");
|
||||
let agents = state.path().join("agents.cc");
|
||||
let body = state.path().join("body.cc");
|
||||
let coverage = std::fs::canonicalize(state.path())?.join("workspace-coverage.cc");
|
||||
crate::initialize_runtime_spine(
|
||||
&runtime,
|
||||
crate::RuntimeSpineInitOptions {
|
||||
runtime_id: "singleton-runtime".into(),
|
||||
display_name: "singleton test".into(),
|
||||
created_at: "2026-07-17T00:00:00Z".into(),
|
||||
},
|
||||
)?;
|
||||
crate::ensure_agent_memory_swarm_identity(&agents, "singleton-swarm")?;
|
||||
crate::bind_runtime_to_agent_memory_swarm(&runtime, &agents, "2026-07-17T00:00:01Z")?;
|
||||
crate::bind_repository_body(repo.path(), &body, &runtime, "singleton-workspace")?;
|
||||
crate::bind_runtime_workspace_coverage_store(&runtime, &coverage, "2026-07-17T00:00:02Z")?;
|
||||
let launch_id = "019bff10-7426-7a1c-9ce4-33f91660a3a7";
|
||||
let first = WorkspaceCoverageProjectorServiceBody::new(
|
||||
&runtime,
|
||||
"singleton-runtime",
|
||||
config(),
|
||||
"first-incarnation",
|
||||
launch_id,
|
||||
)?;
|
||||
assert!(
|
||||
WorkspaceCoverageProjectorServiceBody::new(
|
||||
&runtime,
|
||||
"singleton-runtime",
|
||||
config(),
|
||||
"second-incarnation",
|
||||
launch_id,
|
||||
)
|
||||
.is_err(),
|
||||
"a second live projector must not acquire the same owned store"
|
||||
);
|
||||
drop(first);
|
||||
assert!(acquire_workspace_coverage_projector_singleton(&runtime, &body).is_ok());
|
||||
WorkspaceCoverageProjectorServiceBody::new(
|
||||
&runtime,
|
||||
"singleton-runtime",
|
||||
config(),
|
||||
"replacement-incarnation",
|
||||
launch_id,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
vendor/cultcache-rs
vendored
2
vendor/cultcache-rs
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit d10471e6994c72a0bb6e8a6b2d60a578ccd1bde5
|
||||
Subproject commit 24ea41e569eca67373fe3ebd96cf3e4d524bd98d
|
||||
Reference in a new issue