Extract Codex transport from Epiphany
This commit is contained in:
parent
ce22c3b11f
commit
ed7357a28b
17 changed files with 2627 additions and 8314 deletions
|
|
@ -11,6 +11,7 @@ use epiphany_core::HANDS_PATCH_RECEIPT_TYPE;
|
|||
use epiphany_core::HandsActionIntent;
|
||||
use epiphany_core::RepoFrontierHandsAuthority;
|
||||
use epiphany_core::RuntimeSpineInitOptions;
|
||||
use epiphany_core::coordinator_status as status_projection;
|
||||
use epiphany_core::finalize_coordinator_run;
|
||||
use epiphany_core::hands_action_review_for_intent;
|
||||
use epiphany_core::initialize_runtime_spine;
|
||||
|
|
@ -25,13 +26,13 @@ use epiphany_core::substrate_gate_coordinator_implementation_grant;
|
|||
use epiphany_core::{
|
||||
LaunchedCoordinator, capture_process_instance, claim_resident_self_preparation_as_child,
|
||||
};
|
||||
use epiphany_core::coordinator_status as status_projection;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::collections::BTreeMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread;
|
||||
|
|
@ -69,7 +70,7 @@ struct Args {
|
|||
thread_id: Option<String>,
|
||||
objective: Option<String>,
|
||||
cwd: PathBuf,
|
||||
codex_home: PathBuf,
|
||||
model_connector_endpoint: SocketAddr,
|
||||
mcp_config: PathBuf,
|
||||
artifact_dir: PathBuf,
|
||||
runtime_store: PathBuf,
|
||||
|
|
@ -106,9 +107,7 @@ impl Args {
|
|||
thread_id: None,
|
||||
objective: None,
|
||||
cwd: root.clone(),
|
||||
codex_home: env::var_os("CODEX_HOME")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| home_dir().join(".codex")),
|
||||
model_connector_endpoint: "127.0.0.1:17891".parse().unwrap(),
|
||||
mcp_config: root.join(".epiphany").join("mcp.toml"),
|
||||
artifact_dir: root.join(".epiphany-dogfood").join("coordinator"),
|
||||
runtime_store: root.join("state").join("runtime-spine.msgpack"),
|
||||
|
|
@ -197,7 +196,10 @@ impl Args {
|
|||
parsed.required_action = Some(take_string(&mut args, "--required-action")?)
|
||||
}
|
||||
"--cwd" => parsed.cwd = take_path(&mut args, "--cwd")?,
|
||||
"--codex-home" => parsed.codex_home = take_path(&mut args, "--codex-home")?,
|
||||
"--connector-endpoint" => {
|
||||
parsed.model_connector_endpoint =
|
||||
take_string(&mut args, "--connector-endpoint")?.parse()?
|
||||
}
|
||||
"--mcp-config" => parsed.mcp_config = take_path(&mut args, "--mcp-config")?,
|
||||
"--artifact-dir" => parsed.artifact_dir = take_path(&mut args, "--artifact-dir")?,
|
||||
"--runtime-store" => {
|
||||
|
|
@ -283,12 +285,10 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
let cwd = status_projection::absolute_path(&args.cwd)?;
|
||||
let model_runtime_bin = resolve_model_runtime_bin(&root, &args.model_runtime_bin)?;
|
||||
let tool_adapter_bin = resolve_model_runtime_bin(&root, &args.tool_adapter_bin)?;
|
||||
let codex_home = status_projection::absolute_path(&args.codex_home)?;
|
||||
let mcp_config = status_projection::absolute_path(&args.mcp_config)?;
|
||||
let artifact_dir = status_projection::absolute_path(&args.artifact_dir)?;
|
||||
let runtime_store = status_projection::absolute_path(&args.runtime_store)?;
|
||||
reset_artifact_dir(&artifact_dir)?;
|
||||
fs::create_dir_all(&codex_home)?;
|
||||
|
||||
let telemetry_path = artifact_dir.join("agent-function-telemetry.json");
|
||||
let steps_path = artifact_dir.join("coordinator-steps.jsonl");
|
||||
|
|
@ -408,7 +408,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -450,7 +450,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -504,7 +504,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -549,7 +549,9 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
let snapshot_name = format!("step-{index:02}-{action}.txt");
|
||||
fs::write(
|
||||
artifact_dir.join(&snapshot_name),
|
||||
status_projection::render_status(&status_projection::sanitize_for_operator(status.clone())),
|
||||
status_projection::render_status(&status_projection::sanitize_for_operator(
|
||||
status.clone(),
|
||||
)),
|
||||
)?;
|
||||
snapshots.push(snapshot_name);
|
||||
let mut step = json!({
|
||||
|
|
@ -656,7 +658,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -706,7 +708,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -1027,7 +1029,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -1070,7 +1072,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -1186,7 +1188,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -1256,7 +1258,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
args.model_connector_endpoint,
|
||||
&mcp_config,
|
||||
&cwd,
|
||||
args.resident_state_store.as_deref(),
|
||||
|
|
@ -1344,7 +1346,7 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
"modelRuntimeBin": model_runtime_bin,
|
||||
"toolAdapterBin": tool_adapter_bin,
|
||||
"modelProvider": args.model_provider,
|
||||
"codexHome": codex_home,
|
||||
"modelConnectorEndpoint": args.model_connector_endpoint,
|
||||
"mcpConfig": mcp_config,
|
||||
"runtimeStore": runtime_store,
|
||||
"workspace": cwd,
|
||||
|
|
@ -1738,7 +1740,7 @@ fn launch_worker_runtime_detached(
|
|||
model: &str,
|
||||
provider_credential_path: Option<&Path>,
|
||||
runtime_store: &Path,
|
||||
codex_home: &Path,
|
||||
model_connector_endpoint: SocketAddr,
|
||||
mcp_config: &Path,
|
||||
cwd: &Path,
|
||||
resident_store: Option<&Path>,
|
||||
|
|
@ -1767,8 +1769,8 @@ fn launch_worker_runtime_detached(
|
|||
.arg(model)
|
||||
.arg("--store")
|
||||
.arg(runtime_store)
|
||||
.arg("--codex-home")
|
||||
.arg(codex_home)
|
||||
.arg("--connector-endpoint")
|
||||
.arg(model_connector_endpoint.to_string())
|
||||
.arg("--mcp-config")
|
||||
.arg(mcp_config)
|
||||
.arg("--job-id")
|
||||
|
|
@ -2053,7 +2055,10 @@ fn append_jsonl(path: &Path, value: &Value) -> Result<()> {
|
|||
}
|
||||
|
||||
fn append_operator_step_jsonl(path: &Path, step: &Value) -> Result<()> {
|
||||
append_jsonl(path, &status_projection::sanitize_for_operator(step.clone()))
|
||||
append_jsonl(
|
||||
path,
|
||||
&status_projection::sanitize_for_operator(step.clone()),
|
||||
)
|
||||
}
|
||||
|
||||
fn take_string(args: &mut impl Iterator<Item = String>, name: &str) -> Result<String> {
|
||||
|
|
@ -2065,13 +2070,6 @@ fn take_path(args: &mut impl Iterator<Item = String>, name: &str) -> Result<Path
|
|||
Ok(PathBuf::from(take_string(args, name)?))
|
||||
}
|
||||
|
||||
fn home_dir() -> PathBuf {
|
||||
env::var_os("USERPROFILE")
|
||||
.or_else(|| env::var_os("HOME"))
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -2111,7 +2109,7 @@ mod tests {
|
|||
thread_id: Some("error-terminalization".to_string()),
|
||||
objective: Some("Exercise the coordinator error boundary.".to_string()),
|
||||
cwd: cwd.clone(),
|
||||
codex_home: temp.path().join("codex-home"),
|
||||
model_connector_endpoint: "127.0.0.1:17891".parse().unwrap(),
|
||||
mcp_config: cwd.join(".epiphany/mcp.toml"),
|
||||
artifact_dir: cwd.join(".epiphany-smoke/error-terminalization"),
|
||||
runtime_store: runtime_store.clone(),
|
||||
|
|
|
|||
|
|
@ -495,7 +495,11 @@ impl Args {
|
|||
runtime_store: path("--runtime-store")?,
|
||||
local_verse_store: path("--local-verse-store")?,
|
||||
artifact_root: path("--artifact-root")?,
|
||||
codex_home: path("--codex-home")?,
|
||||
model_connector_endpoint: value
|
||||
.get("--connector-endpoint")
|
||||
.ok_or_else(|| anyhow!("missing --connector-endpoint"))?
|
||||
.parse()
|
||||
.context("invalid --connector-endpoint")?,
|
||||
mcp_config: path("--mcp-config")?,
|
||||
model_provider: value
|
||||
.get("--model-provider")
|
||||
|
|
@ -776,7 +780,7 @@ mod brake_tests {
|
|||
runtime_store,
|
||||
local_verse_store: verse_store,
|
||||
artifact_root: shared.join("artifacts"),
|
||||
codex_home: shared.join("codex-home"),
|
||||
model_connector_endpoint: "127.0.0.1:17891".parse().unwrap(),
|
||||
mcp_config: shared.join("mcp.toml"),
|
||||
model_provider: "test".into(),
|
||||
model: "test-model".into(),
|
||||
|
|
|
|||
|
|
@ -3664,7 +3664,7 @@ mod tests {
|
|||
runtime_store: store.clone(),
|
||||
local_verse_store: temp.path().join("local-verse.cc"),
|
||||
artifact_root: temp.path().join("artifacts"),
|
||||
codex_home: temp.path().join("codex-home"),
|
||||
model_connector_endpoint: "127.0.0.1:17891".parse().unwrap(),
|
||||
mcp_config: temp.path().join("mcp.toml"),
|
||||
model_provider: "openrouter".into(),
|
||||
model: "stealth/ox-alpha".into(),
|
||||
|
|
|
|||
|
|
@ -728,20 +728,12 @@ fn directory_ready(path: &Path) -> bool {
|
|||
fs::metadata(path).is_ok_and(|value| value.is_dir() && !value.permissions().readonly())
|
||||
}
|
||||
|
||||
fn codex_credentials_ready(codex_home: &Path) -> bool {
|
||||
directory_ready(codex_home) && credential_file_ready(&codex_home.join("auth.json"))
|
||||
}
|
||||
|
||||
fn model_provider_credential_ready(policy: &ResidentSelfPolicy) -> bool {
|
||||
match policy.model_provider.as_str() {
|
||||
"openai-codex" | "openai" => codex_credentials_ready(&policy.codex_home),
|
||||
"openrouter" => policy
|
||||
"openai-codex" | "openai" | "openrouter" => policy
|
||||
.provider_credential_path
|
||||
.as_deref()
|
||||
.is_some_and(|path| {
|
||||
fs::metadata(path).is_ok_and(|metadata| metadata.is_file())
|
||||
&& fs::File::open(path).is_ok()
|
||||
}),
|
||||
.is_some_and(credential_file_ready),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -972,30 +964,6 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn unix_credentials_reject_group_or_other_access() -> Result<()> {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let temp = tempfile::tempdir()?;
|
||||
let auth = temp.path().join("auth.json");
|
||||
fs::write(&auth, b"{}")?;
|
||||
fs::set_permissions(&auth, fs::Permissions::from_mode(0o400))?;
|
||||
assert!(!codex_credentials_ready(temp.path()));
|
||||
fs::set_permissions(&auth, fs::Permissions::from_mode(0o644))?;
|
||||
assert!(!codex_credentials_ready(temp.path()));
|
||||
fs::set_permissions(&auth, fs::Permissions::from_mode(0o600))?;
|
||||
assert!(codex_credentials_ready(temp.path()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_credentials_file_cannot_impersonate_canonical_auth() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
fs::write(temp.path().join("credentials.json"), b"{}")?;
|
||||
assert!(!codex_credentials_ready(temp.path()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn readiness_uses_mounted_cognitive_identity_for_projection_and_brake() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
|
|
@ -1026,7 +994,7 @@ mod tests {
|
|||
runtime_store,
|
||||
local_verse_store,
|
||||
artifact_root: shared.join("artifacts"),
|
||||
codex_home: shared.join("codex-home"),
|
||||
model_connector_endpoint: "127.0.0.1:17891".parse().unwrap(),
|
||||
mcp_config: shared.join("mcp.toml"),
|
||||
model_provider: "test".into(),
|
||||
model: "test-model".into(),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use cultcache_rs::{
|
|||
use serde::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub const RESIDENT_SELF_STATE_KEY: &str = "resident-self";
|
||||
|
|
@ -273,7 +274,7 @@ pub struct ResidentSelfPolicy {
|
|||
pub runtime_store: PathBuf,
|
||||
pub local_verse_store: PathBuf,
|
||||
pub artifact_root: PathBuf,
|
||||
pub codex_home: PathBuf,
|
||||
pub model_connector_endpoint: SocketAddr,
|
||||
pub mcp_config: PathBuf,
|
||||
pub model_provider: String,
|
||||
pub model: String,
|
||||
|
|
@ -301,7 +302,6 @@ impl ResidentSelfPolicy {
|
|||
("runtime store", &self.runtime_store),
|
||||
("local Verse store", &self.local_verse_store),
|
||||
("artifact root", &self.artifact_root),
|
||||
("Codex home", &self.codex_home),
|
||||
("MCP config", &self.mcp_config),
|
||||
("release store", &self.release_store),
|
||||
] {
|
||||
|
|
@ -320,6 +320,13 @@ impl ResidentSelfPolicy {
|
|||
path.display()
|
||||
));
|
||||
}
|
||||
if !self.model_connector_endpoint.ip().is_loopback()
|
||||
|| self.model_connector_endpoint.port() == 0
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"resident Self model connector must use a nonzero loopback endpoint"
|
||||
));
|
||||
}
|
||||
if self.model_provider.trim().is_empty()
|
||||
|| self.model.trim().is_empty()
|
||||
|| self.max_steps == 0
|
||||
|
|
@ -617,8 +624,8 @@ pub fn coordinator_argv(
|
|||
turn_id.into(),
|
||||
"--cwd".into(),
|
||||
policy.workspace.display().to_string(),
|
||||
"--codex-home".into(),
|
||||
policy.codex_home.display().to_string(),
|
||||
"--connector-endpoint".into(),
|
||||
policy.model_connector_endpoint.to_string(),
|
||||
"--mcp-config".into(),
|
||||
policy.mcp_config.display().to_string(),
|
||||
"--artifact-dir".into(),
|
||||
|
|
@ -2762,7 +2769,7 @@ mod coordinator_launch_contract_tests {
|
|||
runtime_store,
|
||||
local_verse_store: root.join("local-verse.cc"),
|
||||
artifact_root: root.join("artifacts"),
|
||||
codex_home: root.join("codex-home"),
|
||||
model_connector_endpoint: "127.0.0.1:17891".parse().unwrap(),
|
||||
mcp_config: root.join("mcp.toml"),
|
||||
model_provider: "openrouter".into(),
|
||||
model: "stealth/ox-alpha".into(),
|
||||
|
|
@ -2791,7 +2798,7 @@ mod coordinator_launch_contract_tests {
|
|||
runtime_store: PathBuf::from("/epiphany/state/runtime.cc"),
|
||||
local_verse_store: PathBuf::from("/epiphany/state/local-verse.cc"),
|
||||
artifact_root: PathBuf::from("/epiphany/artifacts"),
|
||||
codex_home: PathBuf::from("/epiphany/codex-home"),
|
||||
model_connector_endpoint: "127.0.0.1:17891".parse().unwrap(),
|
||||
mcp_config: PathBuf::from("/epiphany/mcp.toml"),
|
||||
model_provider: "openrouter".into(),
|
||||
model: "stealth/ox-alpha".into(),
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ pub const COORDINATOR_RUN_RECEIPT_TYPE: &str = "epiphany.coordinator_run_receipt
|
|||
pub const RUNTIME_IDENTITY_KEY: &str = "self";
|
||||
pub const RUNTIME_SWARM_BINDING_KEY: &str = "runtime-swarm-binding";
|
||||
pub const RUNTIME_SWARM_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.swarm_binding.v1";
|
||||
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v37";
|
||||
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v38";
|
||||
pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main";
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(type = "epiphany.runtime.identity", schema = "EpiphanyRuntimeIdentity")]
|
||||
|
|
@ -1936,7 +1936,8 @@ fn archive_completed_model_session(
|
|||
}
|
||||
match &native_terminals[0].payload {
|
||||
EpiphanyModelStreamPayload::Completed { receipt } => {
|
||||
if cache.get::<EpiphanyModelReceipt>(request_id)?.as_ref() != Some(receipt) {
|
||||
if cache.get::<EpiphanyModelReceipt>(request_id)?.as_ref() != Some(receipt.as_ref())
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"runtime session archive found inconsistent native model receipt"
|
||||
));
|
||||
|
|
|
|||
Reference in a new issue