Project current work from one Mind snapshot

This commit is contained in:
Meta Vens 2026-08-25 00:31:24 +02:00
commit 7374be5ece
6 changed files with 67 additions and 68 deletions

View file

@ -478,9 +478,9 @@ pub(crate) fn body_modeling_decision_envelope(
pub fn project_current_work(store_path: impl AsRef<Path>) -> Result<EpiphanyCurrentWorkProjection> {
let store_path = store_path.as_ref();
let mind = crate::assemble_mind_view(store_path)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let mind = crate::mind_documents::assemble_mind_view_from_cache(&cache)?;
let body_modeling = match (
mind.repository_body_observation.clone(),
mind.repo_model.as_ref(),
@ -522,15 +522,15 @@ pub fn project_current_work(store_path: impl AsRef<Path>) -> Result<EpiphanyCurr
Ok(EpiphanyCurrentWorkProjection {
mind_projection_digest: mind.projection_digest,
body_modeling,
research: crate::runtime_repo_frontier_research_lifecycle(store_path)?,
frontier_planning: crate::runtime_repo_frontier_planning_lifecycle(store_path)?,
research: crate::runtime_spine::repo_frontier_research_lifecycle(&cache)?,
frontier_planning: crate::runtime_spine::repo_frontier_planning_lifecycle(&cache)?,
proposal_modeling: current_proposal_modeling_work(&cache)?,
frontier_verdict_modeling: current_frontier_verdict_modeling_work(&cache)?,
verification: current_verification_work(&cache)?,
reorientation: crate::reorientation_work::current_reorientation_work(&cache)?,
imagination_considerations,
admitted_model_direction_consideration,
hands_frontier_ready: crate::runtime_has_actionable_hands_frontier(store_path)?,
hands_frontier_ready: crate::runtime_spine::has_actionable_hands_frontier(&cache)?,
})
}
@ -1071,7 +1071,9 @@ pub fn current_frontier_verdict_modeling_review_job_id(
pub fn current_frontier_research_review_job_id(
store_path: impl AsRef<Path>,
) -> Result<Option<String>> {
let lifecycle = crate::runtime_repo_frontier_research_lifecycle(store_path)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let lifecycle = crate::runtime_spine::repo_frontier_research_lifecycle(&cache)?;
Ok(
(lifecycle.stage == crate::RepoFrontierResearchLifecycleStage::ResultReady)
.then_some(lifecycle.worker_job_id)
@ -1113,15 +1115,15 @@ pub fn launch_current_frontier_planning_work(
let store_path = store_path.as_ref();
chrono::DateTime::parse_from_rfc3339(created_at)
.map_err(|_| anyhow!("frontier Planning launch time is invalid"))?;
let lifecycle = crate::runtime_repo_frontier_planning_lifecycle(store_path)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let lifecycle = crate::runtime_spine::repo_frontier_planning_lifecycle(&cache)?;
if lifecycle.stage != RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady {
return Err(anyhow!("Mind has no launchable frontier Planning work"));
}
let request_id = lifecycle
.planning_request_id
.ok_or_else(|| anyhow!("frontier Planning work lost its request"))?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let request = cache
.get::<crate::RepoFrontierPlanningRequest>(&request_id)?
.ok_or_else(|| anyhow!("frontier Planning request disappeared"))?;
@ -1261,7 +1263,9 @@ pub fn launch_current_frontier_plan_mind_work(
let store_path = store_path.as_ref();
chrono::DateTime::parse_from_rfc3339(created_at)
.map_err(|_| anyhow!("frontier plan Mind launch time is invalid"))?;
let lifecycle = crate::runtime_repo_frontier_planning_lifecycle(store_path)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let lifecycle = crate::runtime_spine::repo_frontier_planning_lifecycle(&cache)?;
if lifecycle.stage != RepoFrontierPlanningLifecycleStage::MindLaunchReady {
return Err(anyhow!("Mind has no launchable frontier plan review"));
}
@ -1271,8 +1275,6 @@ pub fn launch_current_frontier_plan_mind_work(
let request_id = lifecycle
.mind_request_id
.ok_or_else(|| anyhow!("frontier plan Mind launch lost its request"))?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let request = cache
.get::<crate::RepoFrontierPlanMindRequest>(&request_id)?
.ok_or_else(|| anyhow!("frontier plan Mind request disappeared"))?;
@ -1576,7 +1578,9 @@ pub fn launch_current_frontier_research_work(
let store_path = store_path.as_ref();
chrono::DateTime::parse_from_rfc3339(created_at)
.map_err(|_| anyhow!("frontier Research launch time is invalid"))?;
if crate::runtime_repo_frontier_research_lifecycle(store_path)?.stage
let mut current = crate::runtime_spine_cache(store_path)?;
current.pull_all_backing_stores()?;
if crate::runtime_spine::repo_frontier_research_lifecycle(&current)?.stage
!= crate::RepoFrontierResearchLifecycleStage::LaunchReady
{
return Err(anyhow!("Mind has no launchable frontier Research work"));
@ -1728,7 +1732,10 @@ pub fn accept_frontier_research_result(
return Ok(receipt);
}
}
if current_frontier_research_review_job_id(store_path)?.as_deref() != Some(job_id) {
let research_lifecycle = crate::runtime_spine::repo_frontier_research_lifecycle(&cache)?;
if research_lifecycle.stage != crate::RepoFrontierResearchLifecycleStage::ResultReady
|| research_lifecycle.worker_job_id.as_deref() != Some(job_id)
{
return Err(anyhow!(
"frontier Research result is not current review work"
));
@ -1764,8 +1771,9 @@ pub fn accept_frontier_research_result(
.research_decision()?
.ok_or_else(|| anyhow!("frontier Research result has no typed decision"))?;
decision.validate()?;
let lookups =
crate::runtime_authenticated_public_source_lookups_for_worker(store_path, job_id)?;
let lookups = crate::runtime_spine::authenticated_requested_public_source_lookups_for_worker(
&cache, job_id,
)?;
for lookup in &lookups {
if !result.evidence_ids.contains(&lookup.receipt_id)
|| !result.files_inspected.contains(&lookup.source_ref)
@ -1923,7 +1931,13 @@ pub fn accept_frontier_verification_result(
return Ok(EpiphanyAgentPassAdmissionOutcome::Committed(receipt));
}
}
if current_frontier_verification_review_job_id(store_path)?.as_deref() != Some(job_id) {
let verification = current_verification_work(&cache)?;
if verification
.filter(|work| work.attempt.action == EpiphanyAgentPassContinuationAction::Review)
.and_then(|work| work.attempt.job_id)
.as_deref()
!= Some(job_id)
{
return Err(anyhow!(
"frontier Verification result is not current review work"
));
@ -2840,7 +2854,9 @@ pub fn launch_current_body_modeling_work(
let store_path = store_path.as_ref();
chrono::DateTime::parse_from_rfc3339(created_at)
.map_err(|_| anyhow!("Body Modeling launch time is invalid"))?;
let mind = crate::assemble_mind_view(store_path)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let mind = crate::mind_documents::assemble_mind_view_from_cache(&cache)?;
let body_basis = mind
.repository_body_observation
.clone()
@ -2854,8 +2870,6 @@ pub fn launch_current_body_modeling_work(
body_basis,
repo_model.reasoning_basis(),
)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
if resolve_body_modeling_work(
work.clone(),
cache.get::<EpiphanyBodyModelingDecisionReceipt>(&work.work_id)?,
@ -3013,7 +3027,7 @@ pub fn launch_current_proposal_modeling_work(
{
return Err(anyhow!("proposal Modeling launch provenance mismatch"));
}
let mind = crate::assemble_mind_view(store_path)?;
let mind = crate::mind_documents::assemble_mind_view_from_cache(&cache)?;
let body_basis = mind
.repository_body_observation
.clone()
@ -3146,7 +3160,7 @@ pub fn launch_current_frontier_verdict_modeling_work(
.get::<crate::EpiphanyRepoModelFrontierDocument>(&request.frontier_item_id)?
.ok_or_else(|| anyhow!("frontier verdict Modeling launch lost its frontier document"))?;
let frontier_item = frontier_document.value()?;
let mind = crate::assemble_mind_view(store_path)?;
let mind = crate::mind_documents::assemble_mind_view_from_cache(&cache)?;
let body_basis = mind
.repository_body_observation
.clone()

View file

@ -262,13 +262,10 @@ pub use runtime_spine::retain_completed_runtime_sessions;
pub use runtime_spine::retain_failed_runtime_worker_attempts;
pub use runtime_spine::retain_fulfilled_runtime_worker_attempts;
pub use runtime_spine::review_repo_frontier_planning_failure;
pub(crate) use runtime_spine::runtime_authenticated_public_source_lookups_for_worker;
pub(crate) use runtime_spine::runtime_has_actionable_hands_frontier;
pub use runtime_spine::runtime_identity;
pub use runtime_spine::runtime_job;
pub use runtime_spine::runtime_reorient_worker_result;
pub use runtime_spine::runtime_repo_frontier_planning_lifecycle;
pub(crate) use runtime_spine::runtime_repo_frontier_research_lifecycle;
pub use runtime_spine::runtime_requested_public_source_refs_for_worker;
pub use runtime_spine::runtime_role_worker_result;
pub use runtime_spine::runtime_spine_cache;

View file

@ -495,6 +495,10 @@ pub(crate) fn validate_mind_write_envelope(envelope: &CultCacheEnvelope) -> Resu
pub fn assemble_mind_view(store_path: impl AsRef<Path>) -> Result<EpiphanyMindView> {
let mut cache = runtime_spine_cache(store_path.as_ref())?;
cache.pull_all_backing_stores()?;
assemble_mind_view_from_cache(&cache)
}
pub(crate) fn assemble_mind_view_from_cache(cache: &CultCache) -> Result<EpiphanyMindView> {
let identity = cache
.get::<EpiphanyMindIdentity>(MIND_SCHEMA_EPOCH)?
.ok_or_else(|| anyhow!("writable Mind store has no v1 identity"))?;
@ -554,7 +558,7 @@ pub fn assemble_mind_view(store_path: impl AsRef<Path>) -> Result<EpiphanyMindVi
.get::<crate::EpiphanyRepoModelIdentityDocument>(crate::REPO_MODEL_IDENTITY_KEY)?
.is_some()
{
Some(crate::assemble_repo_model_view(store_path.as_ref())?)
Some(crate::repo_model_documents::assemble_repo_model_view_from_cache(cache)?)
} else {
None
};

View file

@ -1041,7 +1041,7 @@ pub fn worker_reasoning_basis(
let launch_document = launch.launch_document()?;
let (source_documents, projection) = match launch_document {
EpiphanyWorkerLaunchDocument::Role(document) => {
let mind = crate::assemble_mind_view(store_path)?;
let mind = crate::mind_documents::assemble_mind_view_from_cache(&cache)?;
let source_documents = mind.source_documents.clone();
let authority: EpiphanyRolePassAuthorityProjection = document.into();
let modeling_body = if authority.role_id.eq_ignore_ascii_case("modeling") {
@ -1149,7 +1149,7 @@ pub fn put_reasoning_basis(
let EpiphanyWorkerLaunchDocument::Role(document) = launch.launch_document()? else {
return Err(anyhow!("role reasoning basis cites a non-role launch"));
};
let current_mind = crate::assemble_mind_view(store_path)?;
let current_mind = crate::mind_documents::assemble_mind_view_from_cache(&cache)?;
let current_modeling_body = if projection
.authority
.role_id

View file

@ -114,7 +114,9 @@ pub fn request_current_reorientation(
chrono::DateTime::parse_from_rfc3339(requested_at)
.map_err(|_| anyhow!("reorientation request time is invalid"))?;
let store_path = store_path.as_ref();
let mind = crate::assemble_mind_view(store_path)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let mind = crate::mind_documents::assemble_mind_view_from_cache(&cache)?;
let mut source_documents = mind
.source_documents
.iter()
@ -168,8 +170,6 @@ pub fn request_current_reorientation(
requested_at: requested_at.into(),
};
validate_reorientation_request_intrinsic(&request)?;
let mut cache = crate::runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
if let Some(existing) = cache.get::<EpiphanyReorientationRequest>(&request_id)? {
validate_reorientation_request_current(&cache, &existing)?;
return Ok(existing);

View file

@ -2627,17 +2627,6 @@ pub(crate) struct AuthenticatedPublicSourceLookup {
pub source_ref: String,
}
pub(crate) fn runtime_authenticated_public_source_lookups_for_worker(
store_path: impl AsRef<Path>,
worker_job_id: &str,
) -> Result<Vec<AuthenticatedPublicSourceLookup>> {
validate_non_empty(worker_job_id, "public source worker job id")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
authenticated_requested_public_source_lookups_for_worker(&cache, worker_job_id)
}
fn authenticated_public_source_lookup_receipts_for_worker(
cache: &CultCache,
worker_job_id: &str,
@ -5546,10 +5535,8 @@ fn frontier_item_is_actionable_for_organ(
/// admitted exactly once and contains an item the route committer can hand to
/// Hands. Status projection must use this instead of assuming that a clear
/// CRRC lane implies implementation authority.
pub(crate) fn runtime_has_actionable_hands_frontier(
runtime_store: impl AsRef<Path>,
) -> Result<bool> {
runtime_has_actionable_frontier_for_organ(runtime_store, "Hands")
pub(crate) fn has_actionable_hands_frontier(cache: &CultCache) -> Result<bool> {
has_actionable_frontier_for_organ(cache, "Hands")
}
fn frontier_authority_documents(
@ -5942,20 +5929,17 @@ impl RepoFrontierResearchLifecycle {
/// review, and accepted Mind-commit lifecycle. This is the launch-currency owner:
/// an uncovered frontier is not launchable while its current attempt is still
/// running or awaiting review.
pub(crate) fn runtime_repo_frontier_research_lifecycle(
runtime_store: impl AsRef<Path>,
pub(crate) fn repo_frontier_research_lifecycle(
cache: &CultCache,
) -> Result<RepoFrontierResearchLifecycle> {
let runtime_store = runtime_store.as_ref();
let mut cache = runtime_spine_cache(runtime_store)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
require_identity(cache)?;
let launches = cache.get_all::<EpiphanyRuntimeWorkerLaunchRequest>()?;
let jobs = cache.get_all::<EpiphanyRuntimeJob>()?;
let role_results = cache.get_all::<EpiphanyRuntimeRoleWorkerResult>()?;
let (view, _basis) = current_keyed_repo_model(&cache)?;
let (view, _basis) = current_keyed_repo_model(cache)?;
let model = view.memory_context_projection();
let work = next_repo_frontier_research_work(&cache, &model, &launches)?;
let work = next_repo_frontier_research_work(cache, &model, &launches)?;
let request = match work {
Some(NextRepoFrontierResearchWork::Unrequested(item)) => {
return Ok(RepoFrontierResearchLifecycle {
@ -5988,7 +5972,7 @@ pub(crate) fn runtime_repo_frontier_research_lifecycle(
.collect::<Result<Vec<_>>>()?
.into_iter()
.map(|launch| {
let carried_request = frontier_research_request_for_launch(&cache, launch)?
let carried_request = frontier_research_request_for_launch(cache, launch)?
.ok_or_else(|| anyhow!("frontier Research launch lost its typed request"))?;
if carried_request != request {
return Err(anyhow!(
@ -6246,7 +6230,9 @@ pub fn review_repo_frontier_planning_failure(
chrono::DateTime::parse_from_rfc3339(reviewed_at)
.map_err(|_| anyhow!("planning failure review time must be RFC3339"))?;
let runtime_store = runtime_store.as_ref();
let lifecycle = runtime_repo_frontier_planning_lifecycle(runtime_store)?;
let mut cache = runtime_spine_cache(runtime_store)?;
cache.pull_all_backing_stores()?;
let lifecycle = repo_frontier_planning_lifecycle(&cache)?;
let (pass_kind, expected_job_id) = match lifecycle.stage {
RepoFrontierPlanningLifecycleStage::ImaginationFailed => {
("imagination", lifecycle.imagination_job_id.as_deref())
@ -6262,8 +6248,6 @@ pub fn review_repo_frontier_planning_failure(
let planning_request_id = lifecycle
.planning_request_id
.ok_or_else(|| anyhow!("planning failure review lost its request"))?;
let mut cache = runtime_spine_cache(runtime_store)?;
cache.pull_all_backing_stores()?;
let result = cache
.get::<EpiphanyRuntimeRoleWorkerResult>(job_id)?
.ok_or_else(|| anyhow!("planning failure review lost its typed result"))?;
@ -6338,7 +6322,13 @@ pub fn runtime_repo_frontier_planning_lifecycle(
let runtime_store = runtime_store.as_ref();
let mut cache = runtime_spine_cache(runtime_store)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
repo_frontier_planning_lifecycle(&cache)
}
pub(crate) fn repo_frontier_planning_lifecycle(
cache: &CultCache,
) -> Result<RepoFrontierPlanningLifecycle> {
require_identity(cache)?;
let empty = |stage| RepoFrontierPlanningLifecycle {
stage,
planning_request_id: None,
@ -6387,7 +6377,7 @@ pub fn runtime_repo_frontier_planning_lifecycle(
..empty(RepoFrontierPlanningLifecycleStage::Terminal)
});
}
if runtime_has_actionable_frontier_for_organ(runtime_store, "Imagination")? {
if has_actionable_frontier_for_organ(cache, "Imagination")? {
return Ok(empty(RepoFrontierPlanningLifecycleStage::Ready));
}
let latest_terminal = decisions.iter().max_by(|a, b| {
@ -6607,15 +6597,9 @@ pub fn runtime_repo_frontier_planning_lifecycle(
Ok(lifecycle)
}
fn runtime_has_actionable_frontier_for_organ(
runtime_store: impl AsRef<Path>,
organ: &str,
) -> Result<bool> {
let runtime_store = runtime_store.as_ref();
let mut cache = runtime_spine_cache(runtime_store)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
let Ok((view, _basis)) = current_keyed_repo_model(&cache) else {
fn has_actionable_frontier_for_organ(cache: &CultCache, organ: &str) -> Result<bool> {
require_identity(cache)?;
let Ok((view, _basis)) = current_keyed_repo_model(cache) else {
return Ok(false);
};
let model = view.memory_context_projection();