Add decision-auditable OpenRouter transport
This commit is contained in:
parent
7ea40ae7e5
commit
ab321b3434
14 changed files with 1061 additions and 103 deletions
|
|
@ -71,6 +71,8 @@ struct Args {
|
|||
model_runtime_bin: PathBuf,
|
||||
tool_adapter_bin: PathBuf,
|
||||
model_provider: String,
|
||||
model: String,
|
||||
provider_credential_path: Option<PathBuf>,
|
||||
thread_id: Option<String>,
|
||||
objective: Option<String>,
|
||||
cwd: PathBuf,
|
||||
|
|
@ -107,6 +109,8 @@ impl Args {
|
|||
model_runtime_bin: PathBuf::from(DEFAULT_MODEL_RUNTIME_BIN),
|
||||
tool_adapter_bin: PathBuf::from(DEFAULT_TOOL_ADAPTER_BIN),
|
||||
model_provider: "openai-codex".to_string(),
|
||||
model: "gpt-5.4".to_string(),
|
||||
provider_credential_path: None,
|
||||
thread_id: None,
|
||||
objective: None,
|
||||
cwd: root.clone(),
|
||||
|
|
@ -153,6 +157,11 @@ impl Args {
|
|||
"--model-provider" => {
|
||||
parsed.model_provider = take_string(&mut args, "--model-provider")?;
|
||||
}
|
||||
"--model" => parsed.model = take_string(&mut args, "--model")?,
|
||||
"--provider-credential" => {
|
||||
parsed.provider_credential_path =
|
||||
Some(take_path(&mut args, "--provider-credential")?)
|
||||
}
|
||||
"--thread-id" => parsed.thread_id = Some(take_string(&mut args, "--thread-id")?),
|
||||
"--objective" => parsed.objective = Some(take_string(&mut args, "--objective")?),
|
||||
"--proposal-modeling-request-id" => {
|
||||
|
|
@ -393,6 +402,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -434,6 +445,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -487,6 +500,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -639,6 +654,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -688,6 +705,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -1009,6 +1028,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -1051,6 +1072,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -1171,6 +1194,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -1240,6 +1265,8 @@ fn run_coordinator(args: &Args) -> Result<Value> {
|
|||
&model_runtime_bin,
|
||||
&tool_adapter_bin,
|
||||
&args.model_provider,
|
||||
&args.model,
|
||||
args.provider_credential_path.as_deref(),
|
||||
&runtime_store,
|
||||
&codex_home,
|
||||
&mcp_config,
|
||||
|
|
@ -1816,6 +1843,8 @@ fn launch_worker_runtime_detached(
|
|||
model_runtime_bin: &Path,
|
||||
tool_adapter_bin: &Path,
|
||||
model_provider: &str,
|
||||
model: &str,
|
||||
provider_credential_path: Option<&Path>,
|
||||
runtime_store: &Path,
|
||||
codex_home: &Path,
|
||||
mcp_config: &Path,
|
||||
|
|
@ -1843,6 +1872,8 @@ fn launch_worker_runtime_detached(
|
|||
.arg("run-worker")
|
||||
.arg("--provider")
|
||||
.arg(model_provider)
|
||||
.arg("--model")
|
||||
.arg(model)
|
||||
.arg("--store")
|
||||
.arg(runtime_store)
|
||||
.arg("--codex-home")
|
||||
|
|
@ -1855,6 +1886,9 @@ fn launch_worker_runtime_detached(
|
|||
.arg(&activation_token_sha256)
|
||||
.arg("--max-runtime-seconds")
|
||||
.arg(max_runtime_seconds.to_string());
|
||||
if let Some(path) = provider_credential_path {
|
||||
command.arg("--provider-credential").arg(path);
|
||||
}
|
||||
if auto_tools {
|
||||
command
|
||||
.arg("--auto-tools")
|
||||
|
|
@ -2223,6 +2257,8 @@ mod tests {
|
|||
model_runtime_bin: current_exe.clone(),
|
||||
tool_adapter_bin: current_exe,
|
||||
model_provider: "test".to_string(),
|
||||
model: "test-model".to_string(),
|
||||
provider_credential_path: None,
|
||||
thread_id: Some("error-terminalization".to_string()),
|
||||
objective: Some("Exercise the coordinator error boundary.".to_string()),
|
||||
cwd: cwd.clone(),
|
||||
|
|
|
|||
|
|
@ -563,6 +563,11 @@ impl Args {
|
|||
.get("--model-provider")
|
||||
.cloned()
|
||||
.ok_or_else(|| anyhow!("missing --model-provider"))?,
|
||||
model: value
|
||||
.get("--model")
|
||||
.cloned()
|
||||
.ok_or_else(|| anyhow!("missing --model"))?,
|
||||
provider_credential_path: value.get("--provider-credential").map(PathBuf::from),
|
||||
max_steps: u64v("--max-steps", 4)?,
|
||||
turn_timeout_seconds: u64v("--turn-timeout-seconds", 600)?,
|
||||
cooldown_seconds: u64v("--cooldown-seconds", 60)?,
|
||||
|
|
@ -831,6 +836,8 @@ mod brake_tests {
|
|||
codex_home: shared.join("codex-home"),
|
||||
mcp_config: shared.join("mcp.toml"),
|
||||
model_provider: "test".into(),
|
||||
model: "test-model".into(),
|
||||
provider_credential_path: None,
|
||||
max_steps: 1,
|
||||
turn_timeout_seconds: 1,
|
||||
cooldown_seconds: 1,
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ use std::collections::BTreeSet;
|
|||
use std::path::Path;
|
||||
|
||||
pub const REASONING_BASIS_SCHEMA_VERSION: &str = "epiphany.reasoning_basis.v1";
|
||||
pub const DECISION_CONTEXT_SCHEMA_VERSION: &str = "epiphany.decision_context.v1";
|
||||
pub const DECISION_CONTEXT_SCHEMA_VERSION: &str = "epiphany.decision_context.v2";
|
||||
pub const MODEL_PASS_FAILURE_SCHEMA_VERSION: &str = "epiphany.model_pass_failure.v1";
|
||||
pub const MIND_COMMIT_RECEIPT_SCHEMA_VERSION: &str = "epiphany.mind_commit_receipt.v1";
|
||||
pub const REASONING_BASIS_TYPE: &str = "epiphany.reasoning_basis.v1";
|
||||
pub const DECISION_CONTEXT_TYPE: &str = "epiphany.decision_context.v1";
|
||||
pub const DECISION_CONTEXT_TYPE: &str = "epiphany.decision_context.v2";
|
||||
pub const MODEL_PASS_FAILURE_TYPE: &str = "epiphany.model_pass_failure.v1";
|
||||
pub const MIND_COMMIT_RECEIPT_TYPE: &str = "epiphany.mind_commit_receipt.v1";
|
||||
pub const DECISION_AUDIT_PROJECTION_SCHEMA_VERSION: &str = "epiphany.decision_audit_projection.v1";
|
||||
|
|
@ -349,7 +349,7 @@ pub struct EpiphanyDecisionToolObservation {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.decision_context.v1",
|
||||
type = "epiphany.decision_context.v2",
|
||||
schema = "EpiphanyDecisionContext"
|
||||
)]
|
||||
pub struct EpiphanyDecisionContext {
|
||||
|
|
@ -1970,6 +1970,8 @@ mod tests {
|
|||
previous_response_id: None,
|
||||
tools: Vec::new(),
|
||||
output_schema_json: None,
|
||||
provider_id: native.provider.clone(),
|
||||
wire_dialect: epiphany_openai_adapter::EpiphanyOpenAiWireDialect::Responses,
|
||||
};
|
||||
(native, provider)
|
||||
}
|
||||
|
|
@ -2088,6 +2090,42 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decision_context_seals_openrouter_identity_and_terminal_tool_dialect() -> Result<()> {
|
||||
let reasoning_basis = basis()?;
|
||||
let mut native = EpiphanyModelRequest::new(
|
||||
"request-openrouter",
|
||||
"conversation-openrouter",
|
||||
"openrouter",
|
||||
"stealth/ox-alpha",
|
||||
"decide",
|
||||
);
|
||||
native.reasoning_basis_id = Some(reasoning_basis.basis_id.clone());
|
||||
native.output_contract_id = Some("epiphany.test.output.v0".into());
|
||||
native.output_schema_json = Some(
|
||||
serde_json::json!({
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {"status": {"type": "string"}},
|
||||
"required": ["status"]
|
||||
})
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
let context = EpiphanyDecisionContext::new(&reasoning_basis, native.clone(), Vec::new())?;
|
||||
let provider = context.provider_request()?;
|
||||
assert_eq!(provider.provider_id, "openrouter");
|
||||
assert_eq!(
|
||||
provider.wire_dialect,
|
||||
epiphany_openai_adapter::EpiphanyOpenAiWireDialect::ChatCompletionsTerminalTool
|
||||
);
|
||||
assert_eq!(
|
||||
provider,
|
||||
epiphany_openai_adapter::request_from_native(&native)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decision_context_reuses_runtime_binding_owner_and_survives_transcript_deletion() -> Result<()>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ pub fn resident_self_local_provider_status(
|
|||
) -> &'static str {
|
||||
if validate_resident_self_store_separation(resident_store, policy).is_err()
|
||||
|| !directory_ready(&policy.workspace)
|
||||
|| !codex_credentials_ready(&policy.codex_home)
|
||||
|| !model_provider_credential_ready(policy)
|
||||
{
|
||||
return "warming";
|
||||
}
|
||||
|
|
@ -482,9 +482,12 @@ pub fn derive_resident_cognition_readiness(
|
|||
if !workspace_ready {
|
||||
reasons.push("workspace is absent, inaccessible, or read-only".into());
|
||||
}
|
||||
let credential_ready = codex_credentials_ready(&request.policy.codex_home);
|
||||
let credential_ready = model_provider_credential_ready(&request.policy);
|
||||
if !credential_ready {
|
||||
reasons.push("Codex credential material is unavailable".into());
|
||||
reasons.push(format!(
|
||||
"model-provider credential material is unavailable for {}",
|
||||
request.policy.model_provider
|
||||
));
|
||||
}
|
||||
let ready = release_authenticated
|
||||
&& physical_stores_separate
|
||||
|
|
@ -794,6 +797,20 @@ 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
|
||||
.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()
|
||||
}),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(unix, test))]
|
||||
fn unix_credential_mode_ready(mode: u32) -> bool {
|
||||
mode & 0o600 == 0o600 && mode & 0o077 == 0
|
||||
|
|
@ -1129,6 +1146,8 @@ mod tests {
|
|||
codex_home: shared.join("codex-home"),
|
||||
mcp_config: shared.join("mcp.toml"),
|
||||
model_provider: "test".into(),
|
||||
model: "test-model".into(),
|
||||
provider_credential_path: None,
|
||||
max_steps: 1,
|
||||
turn_timeout_seconds: 1,
|
||||
cooldown_seconds: 1,
|
||||
|
|
|
|||
|
|
@ -295,6 +295,8 @@ pub struct ResidentSelfPolicy {
|
|||
pub codex_home: PathBuf,
|
||||
pub mcp_config: PathBuf,
|
||||
pub model_provider: String,
|
||||
pub model: String,
|
||||
pub provider_credential_path: Option<PathBuf>,
|
||||
pub max_steps: u64,
|
||||
pub turn_timeout_seconds: u64,
|
||||
pub cooldown_seconds: u64,
|
||||
|
|
@ -330,7 +332,16 @@ impl ResidentSelfPolicy {
|
|||
));
|
||||
}
|
||||
}
|
||||
if let Some(path) = self.provider_credential_path.as_ref()
|
||||
&& !path.is_absolute()
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"resident Self provider credential path must be absolute: {}",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
if self.model_provider.trim().is_empty()
|
||||
|| self.model.trim().is_empty()
|
||||
|| self.max_steps == 0
|
||||
|| self.turn_timeout_seconds == 0
|
||||
{
|
||||
|
|
@ -645,6 +656,8 @@ pub fn coordinator_argv(
|
|||
policy.tool_adapter_bin.display().to_string(),
|
||||
"--model-provider".into(),
|
||||
policy.model_provider.clone(),
|
||||
"--model".into(),
|
||||
policy.model.clone(),
|
||||
"--runtime-id".into(),
|
||||
runtime_id.into(),
|
||||
"--thread-id".into(),
|
||||
|
|
@ -670,6 +683,9 @@ pub fn coordinator_argv(
|
|||
"--max-runtime-seconds".into(),
|
||||
policy.turn_timeout_seconds.to_string(),
|
||||
];
|
||||
if let Some(path) = policy.provider_credential_path.as_ref() {
|
||||
argv.extend(["--provider-credential".into(), path.display().to_string()]);
|
||||
}
|
||||
let ResidentSelfWake::Explicit { objective } = wake;
|
||||
argv.extend(["--objective".into(), objective.clone()]);
|
||||
argv
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ pub const COORDINATOR_RUN_RECEIPT_RETENTION_HEAD_SCHEMA_VERSION: &str =
|
|||
"epiphany.coordinator_run_receipt_retention_head.v0";
|
||||
pub const COORDINATOR_RUN_RECEIPT_RETENTION_HEAD_KEY: &str = "coordinator-run-receipt-retention";
|
||||
pub const OPENAI_ADAPTER_STATUS_TYPE: &str = "epiphany.openai_adapter_status.v0";
|
||||
pub const OPENAI_MODEL_REQUEST_TYPE: &str = "epiphany.openai_model_request.v0";
|
||||
pub const OPENAI_MODEL_REQUEST_TYPE: &str = "epiphany.openai_model_request.v1";
|
||||
pub const OPENAI_MODEL_STREAM_EVENT_TYPE: &str = "epiphany.openai_model_stream_event.v0";
|
||||
pub const OPENAI_MODEL_RECEIPT_TYPE: &str = "epiphany.openai_model_receipt.v0";
|
||||
pub const MODEL_ADAPTER_STATUS_TYPE: &str = "epiphany.model_adapter_status.v0";
|
||||
|
|
@ -170,7 +170,7 @@ pub const TOOL_INVOCATION_RECEIPT_TYPE: &str = "epiphany.tool_invocation_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.v0";
|
||||
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v2";
|
||||
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v3";
|
||||
pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main";
|
||||
pub const RUNTIME_MODEL_EXECUTION_BINDING_SCHEMA_VERSION: &str =
|
||||
"epiphany.runtime.model_execution_binding.v0";
|
||||
|
|
@ -189,7 +189,7 @@ 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";
|
||||
pub const OPENAI_ADAPTER_STATUS_SCHEMA_VERSION: &str = "epiphany.openai_adapter_status.v0";
|
||||
pub const OPENAI_MODEL_REQUEST_SCHEMA_VERSION: &str = "epiphany.openai_model_request.v0";
|
||||
pub const OPENAI_MODEL_REQUEST_SCHEMA_VERSION: &str = "epiphany.openai_model_request.v1";
|
||||
pub const OPENAI_MODEL_STREAM_EVENT_SCHEMA_VERSION: &str = "epiphany.openai_model_stream_event.v0";
|
||||
pub const OPENAI_MODEL_RECEIPT_SCHEMA_VERSION: &str = "epiphany.openai_model_receipt.v0";
|
||||
pub const MODEL_ADAPTER_STATUS_SCHEMA_VERSION: &str = "epiphany.model_adapter_status.v0";
|
||||
|
|
@ -2751,8 +2751,7 @@ where
|
|||
.ok_or_else(|| anyhow!("archived model execution lost provider request"))?;
|
||||
if native_request.request_id != *request_id
|
||||
|| provider_request.request_id != *request_id
|
||||
|| native_request.conversation_id != provider_request.conversation_id
|
||||
|| native_request.model != provider_request.model
|
||||
|| provider_request != epiphany_openai_adapter::request_from_native(&native_request)
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"archived model execution request family is inconsistent"
|
||||
|
|
@ -13986,6 +13985,40 @@ pub(crate) mod tests {
|
|||
runtime_spine_backing_store(&archive_v0_store)?.pull_all()?,
|
||||
archive_v0_before
|
||||
);
|
||||
|
||||
let responses_only_store = temp.path().join("responses-only-runtime.cc");
|
||||
let mut responses_only = CultCache::new();
|
||||
responses_only.register_entry_type::<crate::EpiphanyMindIdentity>()?;
|
||||
responses_only.register_entry_type::<EpiphanyRuntimeIdentity>()?;
|
||||
responses_only
|
||||
.add_generic_backing_store(runtime_spine_backing_store(&responses_only_store)?);
|
||||
responses_only.put(
|
||||
crate::MIND_SCHEMA_EPOCH,
|
||||
&crate::EpiphanyMindIdentity {
|
||||
schema_epoch: crate::MIND_SCHEMA_EPOCH.into(),
|
||||
runtime_id: "responses-only-runtime".into(),
|
||||
},
|
||||
)?;
|
||||
responses_only.put(
|
||||
RUNTIME_IDENTITY_KEY,
|
||||
&EpiphanyRuntimeIdentity {
|
||||
schema_version: "epiphany.runtime_spine.v2".into(),
|
||||
runtime_id: "responses-only-runtime".into(),
|
||||
display_name: "Responses-only runtime".into(),
|
||||
runtime_kind: "epiphany.native".into(),
|
||||
created_at: "2026-08-22T00:00:00Z".into(),
|
||||
updated_at: "2026-08-22T00:00:00Z".into(),
|
||||
supported_document_types: Vec::new(),
|
||||
metadata: BTreeMap::new(),
|
||||
},
|
||||
)?;
|
||||
let responses_only_before =
|
||||
runtime_spine_backing_store(&responses_only_store)?.pull_all()?;
|
||||
assert!(runtime_spine_cache(&responses_only_store).is_err());
|
||||
assert_eq!(
|
||||
runtime_spine_backing_store(&responses_only_store)?.pull_all()?,
|
||||
responses_only_before
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue