Seal immutable frontier planning results
This commit is contained in:
parent
6cbe47313c
commit
05300c8add
12 changed files with 645 additions and 14 deletions
|
|
@ -412,6 +412,61 @@ pub fn epiphany_role_launch_output_schema(role_id: EpiphanyRoleResultRoleId) ->
|
|||
schema
|
||||
}
|
||||
|
||||
pub fn epiphany_frontier_planning_output_schema() -> serde_json::Value {
|
||||
let mut schema = epiphany_role_launch_output_schema(EpiphanyRoleResultRoleId::Imagination);
|
||||
let properties = schema["properties"]
|
||||
.as_object_mut()
|
||||
.expect("role output schema properties");
|
||||
properties.remove("statePatch");
|
||||
properties.remove("selfPatch");
|
||||
properties.insert(
|
||||
"frontierPlanningRequestId".to_string(),
|
||||
serde_json::json!({
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"description": "Exact echo of the coordinator-bound repo frontier planning request."
|
||||
}),
|
||||
);
|
||||
properties.insert(
|
||||
"frontierPlanCandidate".to_string(),
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"required": [
|
||||
"planning_request_id", "model_revision", "model_hash",
|
||||
"frontier_item_id", "frontier_item_hash", "safe_paths", "action", "command",
|
||||
"checks", "stop_conditions", "rollback_steps", "commit_message", "proposed_at"
|
||||
],
|
||||
"properties": {
|
||||
"planning_request_id": {"type": "string", "minLength": 1},
|
||||
"model_revision": {"type": "integer", "minimum": 0},
|
||||
"model_hash": {"type": "string", "minLength": 1},
|
||||
"frontier_item_id": {"type": "string", "minLength": 1},
|
||||
"frontier_item_hash": {"type": "string", "minLength": 1},
|
||||
"safe_paths": {"type": "array", "minItems": 1, "items": {"type": "string", "minLength": 1}},
|
||||
"action": {"type": "string", "minLength": 1},
|
||||
"command": {"type": "string", "minLength": 1},
|
||||
"checks": {"type": "array", "minItems": 1, "items": {"type": "string", "minLength": 1}},
|
||||
"stop_conditions": {"type": "array", "minItems": 1, "items": {"type": "string", "minLength": 1}},
|
||||
"rollback_steps": {"type": "array", "minItems": 1, "items": {"type": "string", "minLength": 1}},
|
||||
"commit_message": {"type": "string", "minLength": 1},
|
||||
"proposed_at": {"type": "string", "minLength": 1}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}),
|
||||
);
|
||||
schema["required"] = serde_json::json!([
|
||||
"roleId",
|
||||
"verdict",
|
||||
"summary",
|
||||
"nextSafeMove",
|
||||
"filesInspected",
|
||||
"frontierPlanningRequestId",
|
||||
"frontierPlanCandidate"
|
||||
]);
|
||||
schema["additionalProperties"] = serde_json::Value::Bool(false);
|
||||
schema
|
||||
}
|
||||
|
||||
pub fn epiphany_reorient_launch_output_schema() -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
|
|
@ -956,6 +1011,21 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frontier_planning_schema_exposes_candidate_without_generic_patch_mouths() {
|
||||
let schema = epiphany_frontier_planning_output_schema();
|
||||
assert!(
|
||||
schema["properties"]
|
||||
.get("frontierPlanningRequestId")
|
||||
.is_some()
|
||||
);
|
||||
assert!(schema["properties"].get("frontierPlanCandidate").is_some());
|
||||
assert!(schema["properties"].get("statePatch").is_none());
|
||||
assert!(schema["properties"].get("selfPatch").is_none());
|
||||
assert!(schema["properties"].get("repoModelPatch").is_none());
|
||||
assert_eq!(schema["additionalProperties"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reorient_worker_prompt_is_bounded_not_full_persistent_memory() {
|
||||
let prompt = build_epiphany_reorient_launch_instruction(CoreEpiphanyReorientAction::Resume);
|
||||
|
|
|
|||
|
|
@ -838,6 +838,62 @@ pub(crate) mod tests {
|
|||
Ok((store, state, launch, planning))
|
||||
}
|
||||
|
||||
fn frontier_planning_result(
|
||||
planning: &RepoFrontierPlanningRequest,
|
||||
job_id: &str,
|
||||
proposed_at: &str,
|
||||
) -> Result<EpiphanyRuntimeRoleWorkerResult> {
|
||||
let mut candidate = RepoFrontierPlanCandidate {
|
||||
schema_version: REPO_FRONTIER_PLAN_CANDIDATE_SCHEMA_VERSION.into(),
|
||||
candidate_id: String::new(),
|
||||
planning_request_id: planning.request_id.clone(),
|
||||
model_revision: planning.model_revision,
|
||||
model_hash: planning.model_hash.clone(),
|
||||
frontier_item_id: planning.frontier_item_id.clone(),
|
||||
frontier_item_hash: planning.frontier_item_hash.clone(),
|
||||
safe_paths: vec![planning.source_scope[0].clone()],
|
||||
action: "Implement the bounded frontier plan.".into(),
|
||||
command: "cargo test --lib".into(),
|
||||
checks: vec!["Focused tests pass.".into()],
|
||||
stop_conditions: vec!["Authority scope changes.".into()],
|
||||
rollback_steps: vec!["Revert the bounded commit.".into()],
|
||||
commit_message: "Implement bounded frontier plan".into(),
|
||||
proposed_at: proposed_at.into(),
|
||||
contract: REPO_FRONTIER_PLANNING_CONTRACT.into(),
|
||||
};
|
||||
candidate.candidate_id = canonical_repo_frontier_plan_candidate_id(&candidate)?;
|
||||
Ok(EpiphanyRuntimeRoleWorkerResult {
|
||||
schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.into(),
|
||||
result_id: format!("frontier-planning-result-{job_id}"),
|
||||
job_id: job_id.into(),
|
||||
role_id: "imagination".into(),
|
||||
verdict: "draft-ready".into(),
|
||||
summary: "Produced one bounded candidate.".into(),
|
||||
next_safe_move: "Mind admission.".into(),
|
||||
checkpoint_summary: None,
|
||||
scratch_summary: None,
|
||||
files_inspected: planning.source_scope.clone(),
|
||||
frontier_node_ids: vec![planning.frontier_item_id.clone()],
|
||||
evidence_ids: vec![planning.admission_receipt_id.clone()],
|
||||
artifact_refs: Vec::new(),
|
||||
open_questions: Vec::new(),
|
||||
evidence_gaps: Vec::new(),
|
||||
risks: Vec::new(),
|
||||
state_patch_msgpack: None,
|
||||
self_patch_msgpack: None,
|
||||
item_error: None,
|
||||
metadata: std::collections::BTreeMap::new(),
|
||||
repo_model_patch_msgpack: None,
|
||||
verification_request_id: None,
|
||||
frontier_route_id: None,
|
||||
repo_frontier_modeling_request_id: None,
|
||||
proposal_modeling_request_id: None,
|
||||
claim_repair_request_id: None,
|
||||
frontier_planning_request_id: Some(planning.request_id.clone()),
|
||||
frontier_plan_candidate_msgpack: Some(rmp_serde::to_vec_named(&candidate)?),
|
||||
})
|
||||
}
|
||||
|
||||
fn research_launch(state: &EpiphanyThreadState) -> EpiphanyJobLaunchRequest {
|
||||
build_epiphany_role_launch_request(
|
||||
"thread-1",
|
||||
|
|
@ -1321,6 +1377,107 @@ pub(crate) mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frontier_planning_result_is_exact_immutable_and_patch_sealed() -> Result<()> {
|
||||
let root = tempfile::tempdir()?;
|
||||
let (store, state, launch, planning) =
|
||||
frontier_planning_launch_fixture(root.path(), "result-exact")?;
|
||||
let plan = plan_coordinator_job_launch(
|
||||
&state,
|
||||
&launch,
|
||||
&store,
|
||||
"launcher-result".into(),
|
||||
"backend-result".into(),
|
||||
)?;
|
||||
commit_coordinator_job_launch(
|
||||
&store,
|
||||
&planning.thread_id,
|
||||
&state,
|
||||
&launch,
|
||||
&plan,
|
||||
"2026-07-15T09:00:03Z".into(),
|
||||
)?;
|
||||
let result = frontier_planning_result(&planning, "backend-result", "2026-07-15T09:00:04Z")?;
|
||||
put_runtime_role_worker_result(&store, &result)?;
|
||||
put_runtime_role_worker_result(&store, &result)?;
|
||||
let stored = runtime_role_worker_result(&store, "backend-result")?
|
||||
.expect("immutable planning result");
|
||||
assert_eq!(stored, result);
|
||||
let candidate = stored
|
||||
.frontier_plan_candidate()?
|
||||
.expect("typed candidate payload");
|
||||
assert_eq!(candidate.planning_request_id, planning.request_id);
|
||||
assert_eq!(
|
||||
candidate.candidate_id,
|
||||
canonical_repo_frontier_plan_candidate_id(&candidate)?
|
||||
);
|
||||
assert!(
|
||||
coordinator_acceptance_cache(&store)?
|
||||
.get_all::<RepoFrontierPlanCandidate>()?
|
||||
.is_empty(),
|
||||
"candidate must remain inside immutable result until Mind admission"
|
||||
);
|
||||
let mut counterfeit = result;
|
||||
counterfeit.summary = "different result bytes".into();
|
||||
let before = std::fs::read(&store)?;
|
||||
assert!(put_runtime_role_worker_result(&store, &counterfeit).is_err());
|
||||
assert_eq!(std::fs::read(&store)?, before);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn frontier_planning_result_refuses_hostile_substitution_before_persistence() -> Result<()> {
|
||||
let root = tempfile::tempdir()?;
|
||||
for mutation in 0..9 {
|
||||
let (store, state, launch, planning) =
|
||||
frontier_planning_launch_fixture(root.path(), &format!("result-{mutation}"))?;
|
||||
let job_id = format!("backend-result-{mutation}");
|
||||
let plan = plan_coordinator_job_launch(
|
||||
&state,
|
||||
&launch,
|
||||
&store,
|
||||
format!("launcher-result-{mutation}"),
|
||||
job_id.clone(),
|
||||
)?;
|
||||
commit_coordinator_job_launch(
|
||||
&store,
|
||||
&planning.thread_id,
|
||||
&state,
|
||||
&launch,
|
||||
&plan,
|
||||
"2026-07-15T09:00:03Z".into(),
|
||||
)?;
|
||||
let mut result = frontier_planning_result(&planning, &job_id, "2026-07-15T09:00:04Z")?;
|
||||
match mutation {
|
||||
0 => result.frontier_planning_request_id = Some("swapped-request".into()),
|
||||
1 => result.frontier_planning_request_id = None,
|
||||
2 => result.frontier_plan_candidate_msgpack = None,
|
||||
3 => result.role_id = "modeling".into(),
|
||||
4 => result.state_patch_msgpack = Some(vec![0]),
|
||||
5 => result.self_patch_msgpack = Some(vec![0]),
|
||||
6 => result.repo_model_patch_msgpack = Some(vec![0]),
|
||||
_ => {
|
||||
let mut candidate = result.frontier_plan_candidate()?.unwrap();
|
||||
if mutation == 7 {
|
||||
candidate.frontier_item_hash = "adjacent-frontier".into();
|
||||
} else {
|
||||
candidate.safe_paths = vec!["outside/authority".into()];
|
||||
}
|
||||
result.frontier_plan_candidate_msgpack =
|
||||
Some(rmp_serde::to_vec_named(&candidate)?);
|
||||
}
|
||||
}
|
||||
let before = std::fs::read(&store)?;
|
||||
assert!(
|
||||
put_runtime_role_worker_result(&store, &result).is_err(),
|
||||
"hostile planning result mutation {mutation} must fail"
|
||||
);
|
||||
assert_eq!(std::fs::read(&store)?, before);
|
||||
assert!(runtime_role_worker_result(&store, &job_id)?.is_none());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concurrent_frontier_planning_launches_leave_only_winner_artifacts() -> Result<()> {
|
||||
let root = tempfile::tempdir()?;
|
||||
|
|
|
|||
|
|
@ -938,6 +938,8 @@ mod tests {
|
|||
repo_frontier_modeling_request_id: None,
|
||||
proposal_modeling_request_id: Some(selection.request_id),
|
||||
claim_repair_request_id: None,
|
||||
frontier_planning_request_id: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
};
|
||||
crate::put_runtime_role_worker_result(store, &result)?;
|
||||
crate::commit_repo_model_admission(
|
||||
|
|
@ -1419,6 +1421,8 @@ mod tests {
|
|||
repo_frontier_modeling_request_id: None,
|
||||
proposal_modeling_request_id: None,
|
||||
claim_repair_request_id: None,
|
||||
frontier_planning_request_id: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
};
|
||||
crate::put_runtime_role_worker_result(&runtime_store, &verification_result)?;
|
||||
crate::put_soul_verdict_receipt(
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ pub use agent_launch::build_epiphany_reorient_launch_request_with_dynamic_contex
|
|||
pub use agent_launch::build_epiphany_role_launch_request;
|
||||
pub use agent_launch::build_epiphany_role_launch_request_with_dynamic_context;
|
||||
pub use agent_launch::epiphany_agent_prompt_with_memory;
|
||||
pub use agent_launch::epiphany_frontier_planning_output_schema;
|
||||
pub use agent_launch::epiphany_reorient_launch_output_schema;
|
||||
pub use agent_launch::epiphany_role_binding_id;
|
||||
pub use agent_launch::epiphany_role_label;
|
||||
|
|
@ -776,6 +777,7 @@ pub use runtime_spine::RuntimeSpineJobOptions;
|
|||
pub use runtime_spine::RuntimeSpineJobResultOptions;
|
||||
pub use runtime_spine::RuntimeSpineSessionOptions;
|
||||
pub use runtime_spine::append_runtime_event;
|
||||
pub use runtime_spine::canonical_repo_frontier_plan_candidate_id;
|
||||
pub use runtime_spine::clear_epiphany_job_binding_backend;
|
||||
pub use runtime_spine::commit_repo_frontier_modeling_request;
|
||||
pub use runtime_spine::commit_repo_frontier_verification_request_for_chain;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,9 @@ use crate::repo_model_gateway::{
|
|||
REPO_FRONTIER_HANDS_AUTHORITY_CONTRACT, REPO_FRONTIER_HANDS_AUTHORITY_SCHEMA_VERSION,
|
||||
REPO_FRONTIER_MODELING_REQUEST_CONTRACT, REPO_FRONTIER_MODELING_REQUEST_SCHEMA_VERSION,
|
||||
REPO_FRONTIER_PLAN_ADOPTION_SCHEMA_VERSION, REPO_FRONTIER_PLAN_CANDIDATE_SCHEMA_VERSION,
|
||||
REPO_FRONTIER_PLANNING_CONTRACT, REPO_FRONTIER_PLANNING_REQUEST_SCHEMA_VERSION,
|
||||
REPO_FRONTIER_PLANNING_CONTRACT, REPO_FRONTIER_PLANNING_LAUNCH_BINDING_CONTRACT,
|
||||
REPO_FRONTIER_PLANNING_LAUNCH_BINDING_SCHEMA_VERSION,
|
||||
REPO_FRONTIER_PLANNING_REQUEST_SCHEMA_VERSION,
|
||||
REPO_FRONTIER_PROPOSAL_MODELING_LAUNCH_BINDING_CONTRACT,
|
||||
REPO_FRONTIER_PROPOSAL_MODELING_LAUNCH_BINDING_SCHEMA_VERSION,
|
||||
REPO_FRONTIER_PROPOSAL_MODELING_REQUEST_CONTRACT,
|
||||
|
|
@ -174,7 +176,7 @@ pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v0";
|
|||
pub const RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION: &str =
|
||||
"epiphany.runtime.worker_launch_request.v1";
|
||||
pub const RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION: &str =
|
||||
"epiphany.runtime.role_worker_result.v1";
|
||||
"epiphany.runtime.role_worker_result.v2";
|
||||
pub const RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION: &str =
|
||||
"epiphany.runtime.reorient_worker_result.v0";
|
||||
pub const COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION: &str = "epiphany.coordinator_run_receipt.v0";
|
||||
|
|
@ -410,6 +412,10 @@ pub struct EpiphanyRuntimeRoleWorkerResult {
|
|||
pub proposal_modeling_request_id: Option<String>,
|
||||
#[cultcache(key = 25, default)]
|
||||
pub claim_repair_request_id: Option<String>,
|
||||
#[cultcache(key = 26, default)]
|
||||
pub frontier_planning_request_id: Option<String>,
|
||||
#[cultcache(key = 27, default)]
|
||||
pub frontier_plan_candidate_msgpack: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl EpiphanyRuntimeRoleWorkerResult {
|
||||
|
|
@ -430,6 +436,13 @@ impl EpiphanyRuntimeRoleWorkerResult {
|
|||
"role worker repoModelPatch",
|
||||
)
|
||||
}
|
||||
|
||||
pub fn frontier_plan_candidate(&self) -> Result<Option<RepoFrontierPlanCandidate>> {
|
||||
decode_optional_msgpack(
|
||||
self.frontier_plan_candidate_msgpack.as_deref(),
|
||||
"role worker frontierPlanCandidate",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
|
|
@ -1457,6 +1470,11 @@ pub fn put_runtime_role_worker_result(
|
|||
validate_non_empty(&result.job_id, "role worker result job id")?;
|
||||
validate_non_empty(&result.result_id, "role worker result id")?;
|
||||
validate_non_empty(&result.role_id, "role worker result role id")?;
|
||||
if result.schema_version != RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION {
|
||||
return Err(anyhow!("role worker result schema version mismatch"));
|
||||
}
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
let is_verification = result.role_id == "verification";
|
||||
if is_verification
|
||||
!= (result
|
||||
|
|
@ -1553,8 +1571,94 @@ pub fn put_runtime_role_worker_result(
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
let has_planning_echo = result.frontier_planning_request_id.is_some();
|
||||
let has_planning_candidate = result.frontier_plan_candidate_msgpack.is_some();
|
||||
if has_planning_echo != has_planning_candidate {
|
||||
return Err(anyhow!(
|
||||
"frontier planning result requires both its request echo and typed candidate"
|
||||
));
|
||||
}
|
||||
if has_planning_echo {
|
||||
if !result.role_id.eq_ignore_ascii_case("imagination") {
|
||||
return Err(anyhow!(
|
||||
"only Imagination results may echo a frontier planning request"
|
||||
));
|
||||
}
|
||||
if result.state_patch_msgpack.is_some()
|
||||
|| result.self_patch_msgpack.is_some()
|
||||
|| result.repo_model_patch_msgpack.is_some()
|
||||
|| result.verification_request_id.is_some()
|
||||
|| result.frontier_route_id.is_some()
|
||||
|| result.repo_frontier_modeling_request_id.is_some()
|
||||
|| result.proposal_modeling_request_id.is_some()
|
||||
|| result.claim_repair_request_id.is_some()
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"frontier planning result may carry only its request echo and typed candidate authority"
|
||||
));
|
||||
}
|
||||
let request_id = result
|
||||
.frontier_planning_request_id
|
||||
.as_deref()
|
||||
.ok_or_else(|| anyhow!("frontier planning request echo disappeared"))?;
|
||||
let request = cache
|
||||
.get::<RepoFrontierPlanningRequest>(request_id)?
|
||||
.ok_or_else(|| anyhow!("frontier planning result requires persisted request"))?;
|
||||
validate_current_repo_frontier_planning_request(&cache, &request)?;
|
||||
let candidate = result
|
||||
.frontier_plan_candidate()?
|
||||
.ok_or_else(|| anyhow!("frontier planning candidate disappeared"))?;
|
||||
validate_repo_frontier_plan_candidate_against_request(&cache, &candidate, &request)?;
|
||||
let bindings = cache
|
||||
.get_all::<RepoFrontierPlanningLaunchBinding>()?
|
||||
.into_iter()
|
||||
.filter(|binding| binding.planning_request_id == request.request_id)
|
||||
.collect::<Vec<_>>();
|
||||
if bindings.len() != 1 {
|
||||
return Err(anyhow!(
|
||||
"frontier planning result requires exactly one coordinator launch binding"
|
||||
));
|
||||
}
|
||||
let binding = &bindings[0];
|
||||
let worker_launch = cache
|
||||
.get::<EpiphanyRuntimeWorkerLaunchRequest>(&result.job_id)?
|
||||
.ok_or_else(|| anyhow!("frontier planning result requires its worker launch"))?;
|
||||
let launch_document = worker_launch.launch_document()?;
|
||||
let projection = match &launch_document {
|
||||
EpiphanyWorkerLaunchDocument::Role(document) => {
|
||||
document.frontier_planning_context.as_ref()
|
||||
}
|
||||
EpiphanyWorkerLaunchDocument::Reorient(_) => None,
|
||||
};
|
||||
let expected_projection =
|
||||
crate::RepoFrontierPlanningContextProjection::from_request(&request);
|
||||
let launch_hash = format!(
|
||||
"{:x}",
|
||||
Sha256::digest(&worker_launch.launch_document_msgpack)
|
||||
);
|
||||
if binding.schema_version != REPO_FRONTIER_PLANNING_LAUNCH_BINDING_SCHEMA_VERSION
|
||||
|| binding.contract != REPO_FRONTIER_PLANNING_LAUNCH_BINDING_CONTRACT
|
||||
|| binding.binding_record_id
|
||||
!= format!("repo-frontier-planning-launch-{}", request.request_id)
|
||||
|| binding.job_id != result.job_id
|
||||
|| binding.binding_id != EPIPHANY_IMAGINATION_ROLE_BINDING_ID
|
||||
|| binding.runtime_id != request.runtime_id
|
||||
|| binding.thread_id != request.thread_id
|
||||
|| binding.worker_launch_document_sha256 != launch_hash
|
||||
|| worker_launch.job_id != result.job_id
|
||||
|| worker_launch.role != EPIPHANY_IMAGINATION_OWNER_ROLE
|
||||
|| worker_launch.binding_id != EPIPHANY_IMAGINATION_ROLE_BINDING_ID
|
||||
|| worker_launch.frontier_planning_request_id.as_deref()
|
||||
!= Some(request.request_id.as_str())
|
||||
|| worker_launch.proposal_modeling_request_id.is_some()
|
||||
|| worker_launch.claim_repair_request_id.is_some()
|
||||
|| projection != Some(&expected_projection)
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"frontier planning result does not exactly bind request, launch, runtime, thread, and candidate"
|
||||
));
|
||||
}
|
||||
}
|
||||
if let Some(existing) = cache.get::<EpiphanyRuntimeRoleWorkerResult>(&result.job_id)? {
|
||||
return if existing == *result {
|
||||
Ok(())
|
||||
|
|
@ -3540,6 +3644,94 @@ pub(crate) fn put_repo_frontier_plan_candidate(
|
|||
put_immutable_planning_entry(store_path, &candidate.candidate_id, candidate)
|
||||
}
|
||||
|
||||
fn validate_repo_frontier_plan_candidate_against_request(
|
||||
cache: &CultCache,
|
||||
candidate: &RepoFrontierPlanCandidate,
|
||||
request: &RepoFrontierPlanningRequest,
|
||||
) -> Result<()> {
|
||||
if candidate.schema_version != REPO_FRONTIER_PLAN_CANDIDATE_SCHEMA_VERSION
|
||||
|| candidate.contract != REPO_FRONTIER_PLANNING_CONTRACT
|
||||
|| candidate.selected_fields_invalid()
|
||||
|| candidate.planning_request_id != request.request_id
|
||||
|| candidate.model_revision != request.model_revision
|
||||
|| candidate.model_hash != request.model_hash
|
||||
|| candidate.frontier_item_id != request.frontier_item_id
|
||||
|| candidate.frontier_item_hash != request.frontier_item_hash
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"frontier planning candidate substituted request identity or required cargo"
|
||||
));
|
||||
}
|
||||
let expected_candidate_id = canonical_repo_frontier_plan_candidate_id(candidate)?;
|
||||
if candidate.candidate_id != expected_candidate_id {
|
||||
return Err(anyhow!("frontier planning candidate id is not canonical"));
|
||||
}
|
||||
let admission = cache
|
||||
.get::<RepoModelAdmissionReceipt>(&request.admission_receipt_id)?
|
||||
.ok_or_else(|| anyhow!("frontier planning candidate requires exact admission receipt"))?;
|
||||
if admission.schema_version != REPO_MODEL_ADMISSION_RECEIPT_SCHEMA_VERSION
|
||||
|| admission.contract != REPO_MODEL_ADMISSION_CONTRACT
|
||||
|| admission.admitted_revision != request.model_revision
|
||||
|| admission.admitted_hash != request.model_hash
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"frontier planning candidate admission binding mismatch"
|
||||
));
|
||||
}
|
||||
let entry = cache
|
||||
.get::<crate::EpiphanyMemoryGraphEntry>(crate::MEMORY_GRAPH_KEY)?
|
||||
.ok_or_else(|| anyhow!("frontier planning candidate requires canonical model"))?;
|
||||
let model = entry.snapshot()?;
|
||||
if model.model_revision != request.model_revision
|
||||
|| crate::memory_graph_model_hash(&model)? != request.model_hash
|
||||
{
|
||||
return Err(anyhow!("frontier planning candidate model is stale"));
|
||||
}
|
||||
let item = model
|
||||
.frontier
|
||||
.iter()
|
||||
.find(|item| item.id == request.frontier_item_id)
|
||||
.ok_or_else(|| anyhow!("frontier planning candidate frontier disappeared"))?;
|
||||
if format!("{:x}", Sha256::digest(rmp_serde::to_vec_named(item)?)) != request.frontier_item_hash
|
||||
|| item.source_scope != request.source_scope
|
||||
|| !candidate.safe_paths.iter().all(|path| {
|
||||
request.source_scope.iter().any(|scope| {
|
||||
path == scope
|
||||
|| path.starts_with(&format!("{}/", scope.trim_end_matches(['/', '\\'])))
|
||||
})
|
||||
})
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"frontier planning candidate exceeds exact frontier authority"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn canonical_repo_frontier_plan_candidate_id(
|
||||
candidate: &RepoFrontierPlanCandidate,
|
||||
) -> Result<String> {
|
||||
let semantic_bytes = rmp_serde::to_vec_named(&(
|
||||
&candidate.planning_request_id,
|
||||
candidate.model_revision,
|
||||
&candidate.model_hash,
|
||||
&candidate.frontier_item_id,
|
||||
&candidate.frontier_item_hash,
|
||||
&candidate.safe_paths,
|
||||
&candidate.action,
|
||||
&candidate.command,
|
||||
&candidate.checks,
|
||||
&candidate.stop_conditions,
|
||||
&candidate.rollback_steps,
|
||||
&candidate.commit_message,
|
||||
&candidate.proposed_at,
|
||||
))?;
|
||||
Ok(format!(
|
||||
"repo-frontier-plan-candidate-{:x}",
|
||||
Sha256::digest(semantic_bytes)
|
||||
))
|
||||
}
|
||||
|
||||
impl RepoFrontierPlanCandidate {
|
||||
fn selected_fields_invalid(&self) -> bool {
|
||||
self.candidate_id.trim().is_empty()
|
||||
|
|
@ -6980,6 +7172,8 @@ pub(crate) mod tests {
|
|||
repo_frontier_modeling_request_id: None,
|
||||
proposal_modeling_request_id: Some(selection.request_id),
|
||||
claim_repair_request_id: None,
|
||||
frontier_planning_request_id: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
};
|
||||
let review = RepoModelAdmissionReview {
|
||||
schema_version: REPO_MODEL_ADMISSION_REVIEW_SCHEMA_VERSION.to_string(),
|
||||
|
|
@ -7109,6 +7303,8 @@ pub(crate) mod tests {
|
|||
repo_frontier_modeling_request_id: None,
|
||||
proposal_modeling_request_id: None,
|
||||
claim_repair_request_id: Some(repair.request_id.clone()),
|
||||
frontier_planning_request_id: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
};
|
||||
let review = RepoModelAdmissionReview {
|
||||
schema_version: REPO_MODEL_ADMISSION_REVIEW_SCHEMA_VERSION.into(),
|
||||
|
|
@ -8382,6 +8578,8 @@ pub(crate) mod tests {
|
|||
repo_frontier_modeling_request_id: None,
|
||||
proposal_modeling_request_id: None,
|
||||
claim_repair_request_id: None,
|
||||
frontier_planning_request_id: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
};
|
||||
put_runtime_role_worker_result(&store, &verification_result)?;
|
||||
let verdict = SoulVerdictReceipt {
|
||||
|
|
@ -8501,6 +8699,8 @@ pub(crate) mod tests {
|
|||
repo_frontier_modeling_request_id: Some(fixture.modeling_request.request_id.clone()),
|
||||
proposal_modeling_request_id: None,
|
||||
claim_repair_request_id: None,
|
||||
frontier_planning_request_id: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
};
|
||||
let review = RepoModelAdmissionReview {
|
||||
schema_version: REPO_MODEL_ADMISSION_REVIEW_SCHEMA_VERSION.to_string(),
|
||||
|
|
@ -8777,6 +8977,8 @@ pub(crate) mod tests {
|
|||
repo_frontier_modeling_request_id: None,
|
||||
proposal_modeling_request_id: None,
|
||||
claim_repair_request_id: None,
|
||||
frontier_planning_request_id: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
};
|
||||
put_runtime_role_worker_result(&fixture.store, &adjacent)?;
|
||||
put_soul_verdict_receipt(
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use crate::EpiphanyReorientFreshnessStatus;
|
|||
use crate::EpiphanyReorientPressureLevel;
|
||||
use crate::EpiphanyReorientReason;
|
||||
|
||||
pub const ROLE_WORKER_OUTPUT_CONTRACT_ID: &str = "epiphany.worker.role_result.v1";
|
||||
pub const ROLE_WORKER_OUTPUT_CONTRACT_ID: &str = "epiphany.worker.role_result.v2";
|
||||
pub const REORIENT_WORKER_OUTPUT_CONTRACT_ID: &str = "epiphany.worker.reorient_result.v0";
|
||||
pub const REPO_FRONTIER_PROPOSAL_MODELING_CONTEXT_SCHEMA_VERSION: &str =
|
||||
"epiphany.worker.repo_frontier_proposal_modeling_context.v0";
|
||||
|
|
|
|||
Reference in a new issue