Separate resident directives from Mind objectives
This commit is contained in:
parent
8ebe56f1a2
commit
b4b46d50c0
6 changed files with 167 additions and 36 deletions
|
|
@ -260,10 +260,10 @@ impl Args {
|
|||
|
||||
fn run_coordinator(args: &Args) -> Result<Value> {
|
||||
let root = env::current_dir().context("failed to resolve current dir")?;
|
||||
match (&args.resident_state_store, &args.resident_preparation_id) {
|
||||
let resident_claim = match (&args.resident_state_store, &args.resident_preparation_id) {
|
||||
(Some(store), Some(preparation_id)) => {
|
||||
let identity = capture_process_instance(std::process::id())?;
|
||||
claim_resident_self_preparation_as_child(
|
||||
Some(claim_resident_self_preparation_as_child(
|
||||
store,
|
||||
preparation_id,
|
||||
&LaunchedCoordinator {
|
||||
|
|
@ -272,15 +272,15 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
process_executable_path: identity.executable_path,
|
||||
},
|
||||
chrono::Utc::now().timestamp_millis().max(0) as u64,
|
||||
)?;
|
||||
)?)
|
||||
}
|
||||
(None, None) => {}
|
||||
(None, None) => None,
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"resident coordinator bootstrap requires both state store and preparation id"
|
||||
));
|
||||
}
|
||||
}
|
||||
};
|
||||
let local_verse_store = status_cli::absolute_path(&args.local_verse_store)?;
|
||||
assert_local_verse_brake_released(
|
||||
&local_verse_store,
|
||||
|
|
@ -355,13 +355,33 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
}));
|
||||
let run_result = (|| -> Result<Value> {
|
||||
if let Some(objective) = args.objective.as_deref() {
|
||||
let intake = intake_operator_objective(&runtime_store, &thread_id, objective)?;
|
||||
startup_events.push(json!({
|
||||
"type": "operatorObjectiveIntake",
|
||||
"threadId": thread_id,
|
||||
"revision": intake.state.revision,
|
||||
"changed": intake.changed,
|
||||
}));
|
||||
if let (Some(store), Some(preparation_id), Some(claim)) = (
|
||||
args.resident_state_store.as_deref(),
|
||||
args.resident_preparation_id.as_deref(),
|
||||
resident_claim.as_ref(),
|
||||
) {
|
||||
epiphany_core::validate_resident_self_prepared_objective(
|
||||
store,
|
||||
preparation_id,
|
||||
claim,
|
||||
objective,
|
||||
)?;
|
||||
startup_events.push(json!({
|
||||
"type": "residentObjectiveBinding",
|
||||
"threadId": thread_id,
|
||||
"grantId": claim.grant_id,
|
||||
"preparationId": preparation_id,
|
||||
"canonicalObjectiveChanged": false,
|
||||
}));
|
||||
} else {
|
||||
let intake = intake_operator_objective(&runtime_store, &thread_id, objective)?;
|
||||
startup_events.push(json!({
|
||||
"type": "operatorObjectiveIntake",
|
||||
"threadId": thread_id,
|
||||
"revision": intake.state.revision,
|
||||
"changed": intake.changed,
|
||||
}));
|
||||
}
|
||||
}
|
||||
if let Some(request_id) = args.imagination_consideration_request_id.as_deref() {
|
||||
if args.objective.is_some() {
|
||||
|
|
|
|||
|
|
@ -2678,6 +2678,38 @@ pub fn resident_self_child_claim(
|
|||
.get::<ResidentSelfChildClaim>(&format!("resident-self-child-claim-{preparation_id}"))
|
||||
}
|
||||
|
||||
/// Authenticates the per-turn objective carried by a resident coordinator
|
||||
/// launch. The canonical coordinator thread objective remains Mind-owned; this
|
||||
/// validates only the directive already persisted in the exact prepared grant.
|
||||
pub fn validate_resident_self_prepared_objective(
|
||||
path: &Path,
|
||||
preparation_id: &str,
|
||||
claim: &ResidentSelfChildClaim,
|
||||
objective: &str,
|
||||
) -> Result<()> {
|
||||
let cache = state_cache(path)?;
|
||||
let state = cache
|
||||
.get::<ResidentSelfState>(RESIDENT_SELF_STATE_KEY)?
|
||||
.ok_or_else(|| anyhow!("resident Self state is absent at objective bootstrap"))?;
|
||||
let prepared = state
|
||||
.prepared_launch
|
||||
.as_ref()
|
||||
.filter(|prepared| prepared.preparation_id == preparation_id)
|
||||
.ok_or_else(|| anyhow!("resident Self preparation is absent at objective bootstrap"))?;
|
||||
let objective_digest = digest_parts([objective.as_bytes()]);
|
||||
if prepared.grant.pressure_kind != "operator-objective"
|
||||
|| prepared.grant.grant_id != claim.grant_id
|
||||
|| prepared.launch_digest != claim.launch_digest
|
||||
|| prepared.grant.objective != objective
|
||||
|| prepared.objective_digest != objective_digest
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"resident coordinator objective disagrees with its exact prepared grant"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn complete_resident_self_turn(
|
||||
path: &Path,
|
||||
|
|
@ -4460,6 +4492,32 @@ mod tests {
|
|||
resident_prepared_launch_thread_id(&prepared)?,
|
||||
"resident-self-thread-cognitive-runtime"
|
||||
);
|
||||
let process = LaunchedCoordinator {
|
||||
process_id: u32::MAX - 20,
|
||||
process_creation_token: 81,
|
||||
process_executable_path: policy.coordinator_bin.clone(),
|
||||
};
|
||||
let claim = claim_resident_self_preparation_as_child(
|
||||
&store,
|
||||
&prepared.preparation_id,
|
||||
&process,
|
||||
4,
|
||||
)?;
|
||||
validate_resident_self_prepared_objective(
|
||||
&store,
|
||||
&prepared.preparation_id,
|
||||
&claim,
|
||||
"Run one bounded planning turn.",
|
||||
)?;
|
||||
assert!(
|
||||
validate_resident_self_prepared_objective(
|
||||
&store,
|
||||
&prepared.preparation_id,
|
||||
&claim,
|
||||
"Replace the canonical objective.",
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue