Collapse native coordinator store boundary
This commit is contained in:
parent
9da553090b
commit
c0b542f7ba
9 changed files with 83 additions and 93 deletions
|
|
@ -751,9 +751,7 @@ fn collect_coordinator_status(runtime_store: &Path, thread_id: &str) -> Result<V
|
|||
"--json",
|
||||
"--thread-id",
|
||||
thread_id,
|
||||
"--thread-state-store",
|
||||
&store,
|
||||
"--runtime-store",
|
||||
"--store",
|
||||
&store,
|
||||
],
|
||||
)
|
||||
|
|
@ -762,7 +760,7 @@ fn collect_coordinator_status(runtime_store: &Path, thread_id: &str) -> Result<V
|
|||
fn apply_bootstrap_patch(runtime_store: &Path, thread_id: &str, patch: Value) -> Result<Value> {
|
||||
let patch: epiphany_core::EpiphanyRoleStatePatchDocument =
|
||||
serde_json::from_value(patch).context("failed to decode typed bootstrap state patch")?;
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store, runtime_store);
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store);
|
||||
let applied = service.apply_state_update(
|
||||
thread_id,
|
||||
epiphany_core::state_update_from_role_patch(Some(0), patch),
|
||||
|
|
@ -771,7 +769,7 @@ fn apply_bootstrap_patch(runtime_store: &Path, thread_id: &str, patch: Value) ->
|
|||
Ok(json!({
|
||||
"revision": applied.revision,
|
||||
"changedFields": applied.changed_fields.iter().map(|field| format!("{field:?}")).collect::<Vec<_>>(),
|
||||
"epiphanyState": applied.state,
|
||||
"state": applied.state,
|
||||
}))
|
||||
}
|
||||
fn resolve_model_runtime_bin(root: &Path, configured: &Path) -> Result<PathBuf> {
|
||||
|
|
@ -971,7 +969,7 @@ fn launch_role(
|
|||
expected_revision: Option<i64>,
|
||||
max_runtime_seconds: u64,
|
||||
) -> Result<Value> {
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store, runtime_store);
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store);
|
||||
let state = service
|
||||
.state()?
|
||||
.ok_or_else(|| anyhow!("cannot launch role without native coordinator state"))?;
|
||||
|
|
@ -1020,7 +1018,7 @@ fn launch_role(
|
|||
"launcherJobId": launched.launcher_job_id,
|
||||
"backendJobId": launched.backend_job_id,
|
||||
"revision": launched.epiphany_state.revision,
|
||||
"epiphanyState": launched.epiphany_state,
|
||||
"state": launched.epiphany_state,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
@ -1030,7 +1028,7 @@ fn accept_role(
|
|||
role_id: &str,
|
||||
expected_revision: Option<u64>,
|
||||
) -> Result<Value> {
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store, runtime_store);
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store);
|
||||
let state = service
|
||||
.state()?
|
||||
.ok_or_else(|| anyhow!("cannot accept role without native coordinator state"))?;
|
||||
|
|
@ -1048,7 +1046,7 @@ fn accept_role(
|
|||
Ok(json!({
|
||||
"roleId": role,
|
||||
"revision": accepted.state.revision,
|
||||
"epiphanyState": accepted.state,
|
||||
"state": accepted.state,
|
||||
"acceptedReceiptId": accepted.update.accepted_receipt_id,
|
||||
"acceptedObservationId": accepted.update.accepted_observation_id,
|
||||
"acceptedEvidenceId": accepted.update.accepted_evidence_id,
|
||||
|
|
@ -1156,7 +1154,7 @@ fn supersede_role_result(
|
|||
accepted_evidence_id: None,
|
||||
summary: Some(summary),
|
||||
};
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store, runtime_store);
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store);
|
||||
let applied = service.apply_state_update(
|
||||
thread_id,
|
||||
epiphany_core::EpiphanyStateUpdate {
|
||||
|
|
@ -1169,7 +1167,7 @@ fn supersede_role_result(
|
|||
Ok(json!({
|
||||
"revision": applied.revision,
|
||||
"changedFields": applied.changed_fields.iter().map(|field| format!("{field:?}")).collect::<Vec<_>>(),
|
||||
"epiphanyState": applied.state,
|
||||
"state": applied.state,
|
||||
"receipt": receipt,
|
||||
}))
|
||||
}
|
||||
|
|
@ -1190,7 +1188,7 @@ fn launch_reorient(
|
|||
expected_revision: Option<i64>,
|
||||
max_runtime_seconds: u64,
|
||||
) -> Result<Value> {
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store, runtime_store);
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(runtime_store);
|
||||
let state = service
|
||||
.state()?
|
||||
.ok_or_else(|| anyhow!("cannot launch reorientation without native coordinator state"))?;
|
||||
|
|
@ -1231,7 +1229,7 @@ fn launch_reorient(
|
|||
"launcherJobId": launched.launcher_job_id,
|
||||
"backendJobId": launched.backend_job_id,
|
||||
"revision": launched.epiphany_state.revision,
|
||||
"epiphanyState": launched.epiphany_state,
|
||||
"state": launched.epiphany_state,
|
||||
"decision": decision,
|
||||
}))
|
||||
}
|
||||
|
|
@ -1784,6 +1782,9 @@ mod tests {
|
|||
"native coordinator regrew host dependency {forbidden:?}"
|
||||
);
|
||||
}
|
||||
let compatibility_field = ["epiphany", "State"].concat();
|
||||
assert!(!production.contains(&compatibility_field));
|
||||
assert!(!production.contains("--thread-state-store"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -51,8 +51,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::process::Command;
|
||||
|
||||
const DEFAULT_CARGO_TARGET_DIR: &str = r"C:\Users\Meta\.cargo-target-codex";
|
||||
const DEFAULT_THREAD_STATE_STORE: &str = "state/thread-state.msgpack";
|
||||
const DEFAULT_RUNTIME_STORE: &str = "state/runtime-spine.msgpack";
|
||||
const DEFAULT_COORDINATOR_STORE: &str = "state/runtime-spine.msgpack";
|
||||
const REORIENT_BINDING_ID: &str = "reorient-worker";
|
||||
const IMAGINATION_BINDING_ID: &str = "imagination-synthesis-worker";
|
||||
const RESEARCH_BINDING_ID: &str = "research-source-gather-worker";
|
||||
|
|
@ -94,8 +93,7 @@ fn main() -> Result<()> {
|
|||
struct Args {
|
||||
thread_id: Option<String>,
|
||||
cwd: PathBuf,
|
||||
thread_state_store: PathBuf,
|
||||
runtime_store: PathBuf,
|
||||
store: PathBuf,
|
||||
ephemeral: bool,
|
||||
json: bool,
|
||||
result: Option<PathBuf>,
|
||||
|
|
@ -112,8 +110,7 @@ impl Args {
|
|||
let mut parsed = Args {
|
||||
thread_id: None,
|
||||
cwd: root.clone(),
|
||||
thread_state_store: PathBuf::from(DEFAULT_THREAD_STATE_STORE),
|
||||
runtime_store: PathBuf::from(DEFAULT_RUNTIME_STORE),
|
||||
store: PathBuf::from(DEFAULT_COORDINATOR_STORE),
|
||||
ephemeral: true,
|
||||
json: false,
|
||||
result: None,
|
||||
|
|
@ -130,12 +127,7 @@ impl Args {
|
|||
match arg.as_str() {
|
||||
"--thread-id" => parsed.thread_id = Some(take_string(&mut args, "--thread-id")?),
|
||||
"--cwd" => parsed.cwd = take_path(&mut args, "--cwd")?,
|
||||
"--thread-state-store" => {
|
||||
parsed.thread_state_store = take_path(&mut args, "--thread-state-store")?
|
||||
}
|
||||
"--runtime-store" => {
|
||||
parsed.runtime_store = take_path(&mut args, "--runtime-store")?
|
||||
}
|
||||
"--store" => parsed.store = take_path(&mut args, "--store")?,
|
||||
"--ephemeral" => parsed.ephemeral = true,
|
||||
"--no-ephemeral" => parsed.ephemeral = false,
|
||||
"--json" => parsed.json = true,
|
||||
|
|
@ -171,14 +163,8 @@ fn run_native_interrupt(args: &Args) -> Result<Value> {
|
|||
.interrupt_binding
|
||||
.as_ref()
|
||||
.ok_or_else(|| anyhow!("--interrupt-binding requires a binding id"))?;
|
||||
let store = absolute_path(&args.thread_state_store)?;
|
||||
let runtime_store = absolute_path(&args.runtime_store)?;
|
||||
if store != runtime_store {
|
||||
return Err(anyhow!(
|
||||
"native interruption requires one unified thread/runtime store"
|
||||
));
|
||||
}
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(&store, &runtime_store);
|
||||
let store = absolute_path(&args.store)?;
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(&store);
|
||||
let state = service
|
||||
.state()?
|
||||
.ok_or_else(|| anyhow!("cannot interrupt without native coordinator state"))?;
|
||||
|
|
@ -198,14 +184,14 @@ fn run_native_interrupt(args: &Args) -> Result<Value> {
|
|||
"revision": result.epiphany_state.revision,
|
||||
"cancelRequested": result.cancel_requested,
|
||||
"interruptedThreadIds": result.interrupted_thread_ids,
|
||||
"epiphanyState": result.epiphany_state,
|
||||
"state": result.epiphany_state,
|
||||
}))
|
||||
}
|
||||
|
||||
fn run_native_status(args: &Args) -> Result<Value> {
|
||||
let cwd = absolute_path(&args.cwd)?;
|
||||
let store_path = absolute_path(&args.thread_state_store)?;
|
||||
let runtime_store_path = absolute_path(&args.runtime_store)?;
|
||||
let store_path = absolute_path(&args.store)?;
|
||||
let runtime_store_path = store_path.clone();
|
||||
let state = if store_path.exists() {
|
||||
read_accepted_coordinator_state(&store_path)
|
||||
.with_context(|| format!("failed to load {}", store_path.display()))?
|
||||
|
|
@ -1415,11 +1401,22 @@ mod native_interrupt_tests {
|
|||
use super::*;
|
||||
use epiphany_state_model::{EpiphanyJobBinding, EpiphanyJobKind};
|
||||
|
||||
#[test]
|
||||
fn native_operator_contract_has_one_store_and_no_codex_state_field() {
|
||||
let source = include_str!("epiphany-mvp-status.rs");
|
||||
let production = source.split("#[cfg(test)]").next().unwrap_or(source);
|
||||
let compatibility_field = ["epiphany", "State"].concat();
|
||||
assert!(!production.contains(&compatibility_field));
|
||||
assert!(!production.contains("--thread-state-store"));
|
||||
assert!(!production.contains("--runtime-store"));
|
||||
assert!(production.contains("--store"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_status_interrupt_uses_native_coordinator_state() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
let store = temp.path().join("status-interrupt.cc");
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(&store, &store);
|
||||
let service = epiphany_core::EpiphanyCoordinatorService::new(&store);
|
||||
service.apply_state_update(
|
||||
"thread-1",
|
||||
epiphany_core::EpiphanyStateUpdate {
|
||||
|
|
@ -1441,8 +1438,7 @@ mod native_interrupt_tests {
|
|||
let args = Args {
|
||||
thread_id: Some("thread-1".to_string()),
|
||||
cwd: temp.path().to_path_buf(),
|
||||
thread_state_store: store.clone(),
|
||||
runtime_store: store,
|
||||
store,
|
||||
ephemeral: true,
|
||||
json: true,
|
||||
result: None,
|
||||
|
|
@ -1455,7 +1451,7 @@ mod native_interrupt_tests {
|
|||
assert_eq!(result["source"], "native");
|
||||
assert_eq!(result["cancelRequested"], false);
|
||||
assert_eq!(
|
||||
result["epiphanyState"]["job_bindings"][0]["blocking_reason"],
|
||||
result["state"]["job_bindings"][0]["blocking_reason"],
|
||||
"native status proof"
|
||||
);
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -25,29 +25,21 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpiphanyCoordinatorService {
|
||||
thread_state_store: PathBuf,
|
||||
runtime_spine_store: PathBuf,
|
||||
store: PathBuf,
|
||||
}
|
||||
|
||||
impl EpiphanyCoordinatorService {
|
||||
pub fn new(
|
||||
thread_state_store: impl Into<PathBuf>,
|
||||
runtime_spine_store: impl Into<PathBuf>,
|
||||
) -> Self {
|
||||
pub fn new(store: impl Into<PathBuf>) -> Self {
|
||||
Self {
|
||||
thread_state_store: thread_state_store.into(),
|
||||
runtime_spine_store: runtime_spine_store.into(),
|
||||
store: store.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn thread_state_store(&self) -> &Path {
|
||||
&self.thread_state_store
|
||||
}
|
||||
pub fn runtime_spine_store(&self) -> &Path {
|
||||
&self.runtime_spine_store
|
||||
pub fn store(&self) -> &Path {
|
||||
&self.store
|
||||
}
|
||||
pub fn state(&self) -> Result<Option<EpiphanyThreadState>> {
|
||||
read_coordinator_state(&self.thread_state_store)
|
||||
read_coordinator_state(&self.store)
|
||||
}
|
||||
|
||||
pub fn role_result(
|
||||
|
|
@ -58,7 +50,7 @@ impl EpiphanyCoordinatorService {
|
|||
let state = self.state()?;
|
||||
Ok(read_role_result_snapshot(
|
||||
state.as_ref(),
|
||||
Some(&self.runtime_spine_store),
|
||||
Some(&self.store),
|
||||
role_id,
|
||||
binding_id,
|
||||
))
|
||||
|
|
@ -71,7 +63,7 @@ impl EpiphanyCoordinatorService {
|
|||
let state = self.state()?;
|
||||
Ok(read_reorient_result_snapshot(
|
||||
state.as_ref(),
|
||||
Some(&self.runtime_spine_store),
|
||||
Some(&self.store),
|
||||
binding_id,
|
||||
))
|
||||
}
|
||||
|
|
@ -82,12 +74,7 @@ impl EpiphanyCoordinatorService {
|
|||
update: EpiphanyStateUpdate,
|
||||
reference_turn_id: Option<String>,
|
||||
) -> Result<EpiphanyCoordinatorStateApplied> {
|
||||
apply_coordinator_state_update(
|
||||
&self.thread_state_store,
|
||||
thread_id,
|
||||
update,
|
||||
reference_turn_id,
|
||||
)
|
||||
apply_coordinator_state_update(&self.store, thread_id, update, reference_turn_id)
|
||||
}
|
||||
|
||||
pub fn apply_state_update_from(
|
||||
|
|
@ -98,7 +85,7 @@ impl EpiphanyCoordinatorService {
|
|||
reference_turn_id: Option<String>,
|
||||
) -> Result<EpiphanyCoordinatorStateApplied> {
|
||||
apply_coordinator_state_update_from_state(
|
||||
&self.thread_state_store,
|
||||
&self.store,
|
||||
thread_id,
|
||||
current_state,
|
||||
update,
|
||||
|
|
@ -118,18 +105,11 @@ impl EpiphanyCoordinatorService {
|
|||
let plan = plan_coordinator_job_launch(
|
||||
state,
|
||||
request,
|
||||
&self.runtime_spine_store,
|
||||
&self.store,
|
||||
launcher_job_id,
|
||||
backend_job_id,
|
||||
)?;
|
||||
commit_coordinator_job_launch(
|
||||
&self.runtime_spine_store,
|
||||
thread_id,
|
||||
state,
|
||||
request,
|
||||
&plan,
|
||||
created_at,
|
||||
)
|
||||
commit_coordinator_job_launch(&self.store, thread_id, state, request, &plan, created_at)
|
||||
}
|
||||
|
||||
pub fn accept_role(
|
||||
|
|
@ -144,7 +124,7 @@ impl EpiphanyCoordinatorService {
|
|||
nonce: &str,
|
||||
) -> Result<EpiphanyNativeRoleAcceptance> {
|
||||
accept_coordinator_role_finding(
|
||||
&self.runtime_spine_store,
|
||||
&self.store,
|
||||
thread_id,
|
||||
state,
|
||||
role_id,
|
||||
|
|
@ -169,7 +149,7 @@ impl EpiphanyCoordinatorService {
|
|||
update_investigation_checkpoint: bool,
|
||||
) -> Result<EpiphanyNativeReorientAcceptance> {
|
||||
accept_coordinator_reorient_finding(
|
||||
&self.runtime_spine_store,
|
||||
&self.store,
|
||||
thread_id,
|
||||
state,
|
||||
binding_id,
|
||||
|
|
@ -188,7 +168,7 @@ impl EpiphanyCoordinatorService {
|
|||
state: &EpiphanyThreadState,
|
||||
request: EpiphanyJobInterruptRequest,
|
||||
) -> Result<EpiphanyJobInterruptResult> {
|
||||
interrupt_coordinator_job(&self.thread_state_store, thread_id, state, request)
|
||||
interrupt_coordinator_job(&self.store, thread_id, state, request)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,6 +189,8 @@ mod tests {
|
|||
"build_role_acceptance_bundle",
|
||||
"serde_json",
|
||||
"thread/epiphany/",
|
||||
"thread_state_store",
|
||||
"runtime_spine_store",
|
||||
] {
|
||||
assert!(
|
||||
!production.contains(forbidden),
|
||||
|
|
|
|||
Reference in a new issue