diff --git a/epiphany-core/src/agent_memory.rs b/epiphany-core/src/agent_memory.rs index 1a859285..d14f4b30 100644 --- a/epiphany-core/src/agent_memory.rs +++ b/epiphany-core/src/agent_memory.rs @@ -366,15 +366,45 @@ pub fn review_agent_self_patch( } }; - if !patch_value.is_object() { - reasons.push("selfPatch must be a JSON object".to_string()); + match decode_agent_self_patch(patch_value) { + Ok(patch) => reasons.extend(review_agent_self_patch_contract(&target_agent_id, &patch)), + Err(reason) => reasons.push(reason), } - let patch: AgentSelfPatch = serde_json::from_value(patch_value.clone()).unwrap_or_default(); - if patch.agent_id.as_deref() != Some(target_agent_id.as_str()) { + AgentMemoryReview { + status: if reasons.is_empty() { + "accepted" + } else { + "rejected" + } + .to_string(), + target_agent_id, + target_role_id: role_id.to_string(), + target_store: store_path.display().to_string(), + reasons, + applied: None, + } +} + +pub(crate) fn decode_agent_self_patch( + patch_value: &Value, +) -> std::result::Result { + if !patch_value.is_object() { + return Err("selfPatch must be a JSON object".to_string()); + } + serde_json::from_value(patch_value.clone()) + .map_err(|err| format!("selfPatch is not a valid AgentSelfPatch document: {err}")) +} + +pub(crate) fn review_agent_self_patch_contract( + expected_agent_id: &str, + patch: &AgentSelfPatch, +) -> Vec { + let mut reasons = Vec::new(); + if patch.agent_id.as_deref() != Some(expected_agent_id) { reasons.push(format!( "selfPatch agentId {:?} does not match this lane; expected {:?}", - patch.agent_id, target_agent_id + patch.agent_id, expected_agent_id )); } match patch.reason.as_deref() { @@ -384,17 +414,15 @@ pub fn review_agent_self_patch( ), } - if let Some(object) = patch_value.as_object() { - for key in object.keys() { - if forbidden_patch_field(key) { - reasons.push(format!( - "selfPatch field {key:?} is project truth or authority; use the proper Epiphany control surface instead" - )); - } else if !allowed_patch_field(key) { - reasons.push(format!( - "selfPatch field {key:?} is not part of the bounded memory mutation contract" - )); - } + for key in patch.extra.keys() { + if forbidden_patch_field(key) { + reasons.push(format!( + "selfPatch field {key:?} is project truth or authority; use the proper Epiphany control surface instead" + )); + } else if !allowed_patch_field(key) { + reasons.push(format!( + "selfPatch field {key:?} is not part of the bounded memory mutation contract" + )); } } @@ -431,19 +459,7 @@ pub fn review_agent_self_patch( ); } - AgentMemoryReview { - status: if reasons.is_empty() { - "accepted" - } else { - "rejected" - } - .to_string(), - target_agent_id, - target_role_id: role_id.to_string(), - target_store: store_path.display().to_string(), - reasons, - applied: None, - } + reasons } pub fn apply_agent_self_patch( diff --git a/epiphany-core/src/surfaces/role_result.rs b/epiphany-core/src/surfaces/role_result.rs index a11d23d8..32bd61dc 100644 --- a/epiphany-core/src/surfaces/role_result.rs +++ b/epiphany-core/src/surfaces/role_result.rs @@ -39,7 +39,7 @@ pub struct EpiphanyRoleFindingInterpretation { pub evidence_gaps: Vec, pub risks: Vec, pub state_patch: Option, - pub self_patch: Option, + pub self_patch: Option, pub self_persistence: Option, pub job_error: Option, pub item_error: Option, @@ -114,10 +114,10 @@ pub fn interpret_role_finding( item_error: Option, ) -> EpiphanyRoleFindingInterpretation { let state_patch = raw_result.get("statePatch").cloned(); - let self_patch = raw_result.get("selfPatch").cloned(); - let self_persistence = self_patch - .as_ref() - .map(|patch| review_role_self_patch(role_id, patch)); + let (self_patch, self_persistence) = raw_result + .get("selfPatch") + .map(|patch| decode_role_self_patch(role_id, patch)) + .unwrap_or((None, None)); let item_error = match role_id { EpiphanyRoleResultRoleId::Imagination => merge_item_error( item_error, @@ -358,95 +358,11 @@ pub fn review_role_self_patch( patch: &serde_json::Value, ) -> EpiphanyRoleSelfPersistenceReview { let (expected_agent_id, target_path) = role_self_memory_target(role_id); - let mut reasons = Vec::new(); - let Some(object) = patch.as_object() else { - return EpiphanyRoleSelfPersistenceReview { - status: EpiphanyRoleSelfPersistenceStatus::Rejected, - target_agent_id: Some(expected_agent_id.to_string()), - target_path: Some(target_path.to_string()), - reasons: vec!["selfPatch must be a JSON object".to_string()], - }; + let reasons = match decode_agent_self_patch(patch) { + Ok(patch) => review_agent_self_patch_contract(expected_agent_id, &patch), + Err(reason) => vec![reason], }; - let agent_id = object.get("agentId").and_then(serde_json::Value::as_str); - match agent_id { - Some(id) if id == expected_agent_id => {} - Some(id) => reasons.push(format!( - "selfPatch agentId {id:?} does not match this lane; expected {expected_agent_id:?}" - )), - None => reasons.push(format!( - "selfPatch must include agentId {expected_agent_id:?}" - )), - } - match object.get("reason").and_then(serde_json::Value::as_str) { - Some(reason) if reason.trim().len() >= 16 && reason.len() <= 800 => {} - Some(_) => reasons.push( - "selfPatch reason must be a bounded explanation of at least 16 characters".to_string(), - ), - None => reasons.push( - "selfPatch must include a reason explaining why this improves the lane".to_string(), - ), - } - - let allowed = [ - "agentId", - "reason", - "evidenceIds", - "semanticMemories", - "episodicMemories", - "relationshipMemories", - "goals", - "values", - "privateNotes", - ]; - let forbidden = [ - "statePatch", - "objective", - "activeSubgoalId", - "subgoals", - "invariants", - "graphs", - "graphFrontier", - "graphCheckpoint", - "scratch", - "investigationCheckpoint", - "jobBindings", - "planning", - "churn", - "mode", - "codeEdits", - "files", - "authorityScope", - "backendJobId", - "rawResult", - ]; - for key in object.keys() { - if forbidden.contains(&key.as_str()) { - reasons.push(format!( - "selfPatch field {key:?} is project truth or authority; use statePatch, roleAccept, or another explicit control surface instead" - )); - } else if !allowed.contains(&key.as_str()) { - reasons.push(format!( - "selfPatch field {key:?} is not part of the bounded memory mutation contract" - )); - } - } - - let mut mutation_count = 0usize; - mutation_count += review_self_patch_memories(&mut reasons, object, "semanticMemories"); - mutation_count += review_self_patch_memories(&mut reasons, object, "episodicMemories"); - mutation_count += review_self_patch_memories(&mut reasons, object, "relationshipMemories"); - mutation_count += review_self_patch_goals(&mut reasons, object); - mutation_count += review_self_patch_values(&mut reasons, object); - mutation_count += review_self_patch_private_notes(&mut reasons, object); - review_self_patch_string_array(&mut reasons, object, "evidenceIds", 16, 160); - if mutation_count == 0 { - reasons.push( - "selfPatch must contain at least one semantic memory, episodic memory, relationship memory, goal, value, or private note" - .to_string(), - ); - } - EpiphanyRoleSelfPersistenceReview { status: if reasons.is_empty() { EpiphanyRoleSelfPersistenceStatus::Accepted @@ -459,6 +375,22 @@ pub fn review_role_self_patch( } } +fn decode_role_self_patch( + role_id: EpiphanyRoleResultRoleId, + patch: &serde_json::Value, +) -> ( + Option, + Option, +) { + let review = review_role_self_patch(role_id, patch); + let decoded = if review.status == EpiphanyRoleSelfPersistenceStatus::Accepted { + decode_agent_self_patch(patch).ok() + } else { + None + }; + (decoded, Some(review)) +} + pub fn modeling_role_state_patch_policy_errors(patch: &serde_json::Value) -> Vec { let mut errors = Vec::new(); if has_field(patch, "objective") { @@ -853,237 +785,6 @@ fn non_empty_array_field(value: &serde_json::Value, key: &str) -> bool { .is_some_and(|items| !items.is_empty()) } -fn review_self_patch_memories( - reasons: &mut Vec, - object: &serde_json::Map, - field: &str, -) -> usize { - let Some(value) = object.get(field) else { - return 0; - }; - let Some(items) = value.as_array() else { - reasons.push(format!("selfPatch {field} must be an array")); - return 0; - }; - if items.len() > 8 { - reasons.push(format!("selfPatch {field} may contain at most 8 records")); - } - let mut valid = 0usize; - for (index, item) in items.iter().enumerate() { - let Some(record) = item.as_object() else { - reasons.push(format!("selfPatch {field}[{index}] must be an object")); - continue; - }; - review_self_patch_id(reasons, record, field, index, "memoryId", "mem-"); - review_self_patch_summary(reasons, record, field, index, "summary", 600); - review_self_patch_unit(reasons, record, field, index, "salience"); - review_self_patch_unit(reasons, record, field, index, "confidence"); - valid += 1; - } - valid -} - -fn review_self_patch_goals( - reasons: &mut Vec, - object: &serde_json::Map, -) -> usize { - let Some(value) = object.get("goals") else { - return 0; - }; - let Some(items) = value.as_array() else { - reasons.push("selfPatch goals must be an array".to_string()); - return 0; - }; - if items.len() > 6 { - reasons.push("selfPatch goals may contain at most 6 records".to_string()); - } - let mut valid = 0usize; - for (index, item) in items.iter().enumerate() { - let Some(record) = item.as_object() else { - reasons.push(format!("selfPatch goals[{index}] must be an object")); - continue; - }; - review_self_patch_id(reasons, record, "goals", index, "goalId", "goal-"); - review_self_patch_summary(reasons, record, "goals", index, "description", 700); - review_self_patch_string(reasons, record, "goals", index, "scope", 80); - review_self_patch_unit(reasons, record, "goals", index, "priority"); - review_self_patch_string(reasons, record, "goals", index, "emotionalStake", 400); - review_self_patch_string(reasons, record, "goals", index, "status", 80); - valid += 1; - } - valid -} - -fn review_self_patch_values( - reasons: &mut Vec, - object: &serde_json::Map, -) -> usize { - let Some(value) = object.get("values") else { - return 0; - }; - let Some(items) = value.as_array() else { - reasons.push("selfPatch values must be an array".to_string()); - return 0; - }; - if items.len() > 6 { - reasons.push("selfPatch values may contain at most 6 records".to_string()); - } - let mut valid = 0usize; - for (index, item) in items.iter().enumerate() { - let Some(record) = item.as_object() else { - reasons.push(format!("selfPatch values[{index}] must be an object")); - continue; - }; - review_self_patch_id(reasons, record, "values", index, "valueId", "value-"); - review_self_patch_summary(reasons, record, "values", index, "label", 240); - review_self_patch_unit(reasons, record, "values", index, "priority"); - if !record - .get("unforgivableIfBetrayed") - .is_some_and(serde_json::Value::is_boolean) - { - reasons.push(format!( - "selfPatch values[{index}].unforgivableIfBetrayed must be a boolean" - )); - } - valid += 1; - } - valid -} - -fn review_self_patch_private_notes( - reasons: &mut Vec, - object: &serde_json::Map, -) -> usize { - let Some(value) = object.get("privateNotes") else { - return 0; - }; - let Some(items) = value.as_array() else { - reasons.push("selfPatch privateNotes must be an array".to_string()); - return 0; - }; - if items.len() > 6 { - reasons.push("selfPatch privateNotes may contain at most 6 records".to_string()); - } - for (index, item) in items.iter().enumerate() { - match item.as_str() { - Some(text) if !text.trim().is_empty() && text.len() <= 600 => {} - _ => reasons.push(format!( - "selfPatch privateNotes[{index}] must be non-empty text under 600 characters" - )), - } - } - items.len() -} - -fn review_self_patch_string_array( - reasons: &mut Vec, - object: &serde_json::Map, - field: &str, - max_items: usize, - max_len: usize, -) { - let Some(value) = object.get(field) else { - return; - }; - let Some(items) = value.as_array() else { - reasons.push(format!("selfPatch {field} must be an array")); - return; - }; - if items.len() > max_items { - reasons.push(format!( - "selfPatch {field} may contain at most {max_items} records" - )); - } - for (index, item) in items.iter().enumerate() { - match item.as_str() { - Some(text) if !text.trim().is_empty() && text.len() <= max_len => {} - _ => reasons.push(format!( - "selfPatch {field}[{index}] must be non-empty text under {max_len} characters" - )), - } - } -} - -fn review_self_patch_id( - reasons: &mut Vec, - record: &serde_json::Map, - collection: &str, - index: usize, - field: &str, - prefix: &str, -) { - match record.get(field).and_then(serde_json::Value::as_str) { - Some(id) - if id.starts_with(prefix) - && id.len() <= 120 - && id - .chars() - .all(|ch| ch.is_ascii_alphanumeric() || "-_.".contains(ch)) => {} - Some(_) => reasons.push(format!( - "selfPatch {collection}[{index}].{field} must start with {prefix:?}, avoid whitespace, and stay under 120 characters" - )), - None => reasons.push(format!( - "selfPatch {collection}[{index}].{field} is required" - )), - } -} - -fn review_self_patch_summary( - reasons: &mut Vec, - record: &serde_json::Map, - collection: &str, - index: usize, - field: &str, - max_len: usize, -) { - match record.get(field).and_then(serde_json::Value::as_str) { - Some(text) if !text.trim().is_empty() && text.len() <= max_len => {} - Some(_) => reasons.push(format!( - "selfPatch {collection}[{index}].{field} must be non-empty text under {max_len} characters" - )), - None => reasons.push(format!( - "selfPatch {collection}[{index}].{field} is required" - )), - } -} - -fn review_self_patch_string( - reasons: &mut Vec, - record: &serde_json::Map, - collection: &str, - index: usize, - field: &str, - max_len: usize, -) { - match record.get(field).and_then(serde_json::Value::as_str) { - Some(text) if !text.trim().is_empty() && text.len() <= max_len => {} - Some(_) => reasons.push(format!( - "selfPatch {collection}[{index}].{field} must be non-empty text under {max_len} characters" - )), - None => reasons.push(format!( - "selfPatch {collection}[{index}].{field} is required" - )), - } -} - -fn review_self_patch_unit( - reasons: &mut Vec, - record: &serde_json::Map, - collection: &str, - index: usize, - field: &str, -) { - match record.get(field).and_then(serde_json::Value::as_f64) { - Some(value) if (0.0..=1.0).contains(&value) => {} - Some(_) => reasons.push(format!( - "selfPatch {collection}[{index}].{field} must be between 0 and 1" - )), - None => reasons.push(format!( - "selfPatch {collection}[{index}].{field} is required" - )), - } -} - #[cfg(test)] mod tests { use super::*; @@ -1403,6 +1104,9 @@ mod tests { })); } } +use crate::agent_memory::AgentSelfPatch; +use crate::agent_memory::decode_agent_self_patch; +use crate::agent_memory::review_agent_self_patch_contract; use codex_protocol::protocol::EpiphanyAcceptanceReceipt; use codex_protocol::protocol::EpiphanyCodeRef; use codex_protocol::protocol::EpiphanyEvidenceRecord; diff --git a/notes/codex-auth-spine-inventory.md b/notes/codex-auth-spine-inventory.md new file mode 100644 index 00000000..c2ab65f8 --- /dev/null +++ b/notes/codex-auth-spine-inventory.md @@ -0,0 +1,72 @@ +# Codex Auth Spine Inventory + +Objective: keep only the Codex organ that proves OpenAI entitlement and moves typed model-call requests to the OpenAI edge. Everything else is suspect until it earns a live invariant. + +## Live Spine + +Plain path: + +1. Epiphany prepares a typed turn/request document. +2. A small auth spine resolves OpenAI credentials. +3. A small model transport spine serializes the typed request at the OpenAI wire edge. +4. The OpenAI stream is decoded into typed Epiphany runtime events/results. +5. Epiphany stores durable state as CultCache documents and exposes CultNet schemas at network edges. + +Current Codex mechanism: + +- `vendor/codex/codex-rs/login/src/auth/manager.rs` + - Owns `CodexAuth`, `AuthManager`, token refresh, API-key auth, ChatGPT subscription auth, agent identity auth, and unauthorized recovery. + - Real need: OpenAI subscription/API entitlement and refresh behavior. + - Smell: imports app-server protocol auth modes and wider Codex protocol types. The auth organ is not cleanly independent. +- `vendor/codex/codex-rs/codex-api/src/auth.rs` + - Owns `AuthProvider` and `SharedAuthProvider`. + - Real need: small async boundary that applies auth headers to transport requests. + - Keep candidate. This is close to the shape Epiphany wants. +- `vendor/codex/codex-rs/codex-api/src/provider.rs` + - Owns endpoint base URL, headers, retry policy, idle timeout, and request construction. + - Real need: OpenAI/Azure endpoint configuration. + - Keep candidate, but only as model transport configuration. +- `vendor/codex/codex-rs/codex-api/src/endpoint/session.rs` + - Owns request construction, auth application, retry telemetry, and HTTP/SSE execution. + - Real need: authenticated OpenAI HTTP/SSE execution. + - Keep candidate if carved away from telemetry and generic endpoint spread. +- `vendor/codex/codex-rs/codex-api/src/endpoint/responses.rs` + - Owns Responses API request serialization and SSE request launch. + - Real need: OpenAI wire adapter. + - Allowed JSON: `serde_json::to_value` at this exact external wire edge. +- `vendor/codex/codex-rs/codex-client/src/default_client.rs` + - Owns reqwest client setup and trace header injection. + - Real need: HTTP transport. + - Keep candidate, but it should become a small transport dependency, not a Codex identity. +- `vendor/codex/codex-rs/core/src/client.rs` + - Owns the current live request path from prompt/model info through `ApiResponsesClient`. + - Real need: some of this is model-call orchestration. + - Smell: currently embedded in a broad Codex session core with tools, session telemetry, prompt assembly, realtime/websocket alternatives, and unauthorized retry loops. + +## Not The Spine + +These may remain in the vendored tree during quarantine, but they are not Epiphany organs: + +- Apps, skills, plugins, marketplace, startup sync, connector inventory. +- TUI/CLI/chat UI/session lifecycle except a temporary login UX if needed. +- Multi-agent tool plumbing from Codex. Epiphany owns swarm physiology through CultNet/CultCache. +- App-server protocol surfaces that exist to mirror Codex product features. +- JSON-RPC shapes that expose internal accidents instead of CultNet contracts. +- Realtime/websocket, review, guardian, cloud task, backend task, and account UI surfaces unless a specific auth entitlement dependency proves otherwise. + +## Invariants + +- OpenAI auth is a sealed reliquary: it may authenticate and refresh, not own Epiphany runtime shape. +- The OpenAI API wire adapter may serialize JSON because OpenAI speaks JSON. That permission does not leak inward. +- CultNet schemas describe network edges. CultCache documents carry live state. +- A Codex type survives only if it protects one of these invariants: credential validity, authenticated request construction, streaming decode, or model capability/provider metadata. +- `codex_message_processor.rs` is not allowed to be the owner of Epiphany runtime truth. + +## Suspicious Load-Bearing Questions + +- Can `AuthManager` be extracted without `codex_app_server_protocol`, `codex_protocol::auth`, and app-server-specific auth modes? +- Does Epiphany need Codex websocket/realtime paths, or only Responses SSE? +- Which model-provider metadata is genuinely required to keep subscription compatibility? +- Can unauthorized recovery live entirely in the auth spine instead of the session/chat processor layer? +- Can model-call input/output become one typed Epiphany document pair before the OpenAI edge serialization? + diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 95c59261..3c4f977d 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -366,23 +366,29 @@ that change what the next agent should believe. Do not continue implementation automatically from a rehydrate-only request. -The next real move is Codex starvation, not outward bridge work. The first -bounded slice is: +The next real move remains Codex starvation, not outward bridge work. The +inventory and ledger now exist: -1. create `notes/codex-auth-spine-inventory.md` -2. inventory the minimum vendored Codex path required for OpenAI subscription - auth, account/session refresh, model provider config, model request - construction, streaming response handling, and rate/error handling -3. create `notes/json-contamination-ledger.md` -4. classify every Epiphany-relevant `serde_json::Value`, `json!`, - `from_value`, and `to_value` as schema/wire descriptor, hostile ingress, - sealed forensic artifact, quarantine experiment, or heretek internal blob -5. choose the first typed-document replacement target, preferably `selfPatch` - or worker launch/result cargo +- `notes/codex-auth-spine-inventory.md` maps the minimal Codex auth/model-call + reliquary: `login` auth/token refresh, `codex-api` auth/provider/session and + Responses edge, `codex-client` transport, and the suspect current + `core/src/client.rs` orchestration. +- `notes/json-contamination-ledger.md` classifies the major Epiphany JSON + contamination. Edge JSON is allowed only for schema/wire boundaries, + hostile ingress before typed parse, sealed forensic artifacts, or named + quarantine. +- First cut landed: role-result `selfPatch` is now an internal typed + `AgentSelfPatch` document reviewed by the same contract used by agent memory. + The legacy app-server protocol projection serializes it back to JSON only at + the quarantine wall. -Do not resume Rider, Unity, Aquarium, Face, dogfood, planning, app, skill, -marketplace, or bridge expansion until this liberation pass has an inventory, -ledger, and first cut. No fresh balcony on the contaminated cathedral. +Continue with worker launch/result cargo. Replace +`EpiphanyJobLaunchRequest.input_json` and `output_schema_json` with typed +launch/result documents plus schema ids in `epiphany-core`, then make +`codex_message_processor.rs` project those documents instead of assembling +loose JSON blobs. Do not resume Rider, Unity, Aquarium, Face, dogfood, +planning, app, skill, marketplace, or bridge expansion until this organ is +being cut cleanly. The Phase 6 freshness slice is landed. It exposes read-only `thread/epiphany/freshness` from live retrieval summaries plus graph diff --git a/notes/json-contamination-ledger.md b/notes/json-contamination-ledger.md new file mode 100644 index 00000000..27ea59af --- /dev/null +++ b/notes/json-contamination-ledger.md @@ -0,0 +1,64 @@ +# JSON Contamination Ledger + +Rule: JSON is allowed at external schema/wire boundaries. Inside Epiphany, live data should be typed CultCache documents or typed CultNet messages. A `serde_json::Value` inside core logic is guilty until it identifies its border checkpoint. + +## Allowed Wire Or Schema JSON + +- `vendor/codex/codex-rs/codex-api/src/endpoint/responses.rs` + - Current mechanism: typed `ResponsesApiRequest` is serialized to JSON for the OpenAI Responses HTTP body. + - Real need: OpenAI wire protocol. + - Verdict: allowed edge JSON. +- `vendor/codex/codex-rs/codex-api/src/requests/responses.rs` + - Current mechanism: mutates serialized request JSON to attach item ids for Azure. + - Real need: compatibility with upstream API quirks. + - Smell: typed request loses shape before a provider-specific patch is applied. + - Simpler architecture: provider-specific typed request rendering, then JSON emission once. +- Schema fixtures, schema catalogs, and protocol snapshot tests. + - Verdict: allowed if they test wire schema, not internal state. + +## Internal JSON To Purge + +- `vendor/codex/codex-rs/core/src/codex_thread.rs` + - Current mechanism: `EpiphanyJobLaunchRequest.input_json` and `output_schema_json`. + - Real need: launch role workers with structured instructions and expected response shape. + - What breaks if deleted: current job launch path cannot carry worker input/schema to Codex runtime. + - Essential or bad ownership: bad ownership. Worker launch intent should be a typed document plus schema id, not two loose blobs. + - Simpler architecture: `EpiphanyWorkerLaunchDocument` in CultCache/CultNet, with typed payload and `output_contract_id`. + - Files: `vendor/codex/codex-rs/core/src/codex_thread.rs`, `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`, `vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs`, `epiphany-core/src/runtime_spine.rs`. +- `epiphany-core/src/surfaces/role_result.rs` + - Current mechanism: `state_patch` and `self_patch` are `serde_json::Value`; `selfPatch` is manually revalidated here. + - Real need: interpret worker findings and review bounded lane-local memory petitions. + - What breaks if deleted: app-server mapping still expects JSON protocol fields. + - Essential or bad ownership: bad ownership. `selfPatch` already has a typed `AgentSelfPatch` document in `agent_memory.rs`; role-result review duplicated the contract. + - Simpler architecture: role interpretation stores `AgentSelfPatch`, and only the protocol projection serializes JSON for the existing app-server surface. + - Files: `epiphany-core/src/agent_memory.rs`, `epiphany-core/src/surfaces/role_result.rs`, `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`, `vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs`. +- `vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs` + - Current mechanism: `ThreadEpiphanyRoleFinding.self_patch: Option`, `ThreadEpiphanyJobLaunchRequest.input_json`, and `output_schema_json`. + - Real need: app-server compatibility while Epiphany is still hosted inside Codex. + - What breaks if deleted: frontend/server protocol compilation. + - Essential or bad ownership: temporary compatibility reliquary, not a final contract. + - Simpler architecture: CultNet schema messages generated from typed document structs. + +## Quarantine JSON + +- `epiphany-core/src/heartbeat_state.rs` + - Current mechanism: heartbeat cognition stores some `serde_json::Value` fields. + - Real need: experimental cognition payloads still changing shape. + - Verdict: quarantine only. It must either become typed heartbeat documents or remain clearly marked as volatile cognition scratch. +- MCP tool call arguments/results in `vendor/codex/codex-rs/core/src/mcp_tool_call.rs`. + - Current mechanism: arbitrary MCP payloads are raw JSON. + - Real need: MCP is an external protocol with schema-bearing tools. + - Verdict: edge adapter. It does not belong in the Codex auth organ. + - Simpler architecture: CultNet MCP adapter with typed request/result wrappers and raw JSON sealed at the MCP edge. +- Unity/Rider/void-memory CLI outputs. + - Current mechanism: JSON command output and ad hoc parsing. + - Real need: bridge external tools while native surfaces mature. + - Verdict: quarantine bridges; do not let them define internal contracts. + +## Ranking + +1. Done: purge `selfPatch` as internal JSON. Role-result interpretation now stores the typed `AgentSelfPatch` document and shares the agent-memory contract; JSON remains only at the legacy app-server projection. +2. Replace worker launch `input_json` and `output_schema_json` with typed launch documents and schema ids. +3. Replace role `statePatch` JSON with typed map/planning/graph patch documents. +4. Seal MCP JSON behind a CultNet MCP adapter. +5. Audit heartbeat cognition values and either type them or explicitly expire them. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index b5b66cc5..6155f680 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 198fcc0c..53503e26 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -278,5 +278,5 @@ rejected_paths: reason: making Epiphany cleaner inside Codex still preserves the wrong organ; Codex must be starved down to OpenAI subscription auth/model transport, while Epiphany data and subsystem communication move to typed CultCache/CultNet. current_status: - summary: The prior app-server control-plane rebuild is complete enough as a scar, not as the destination. The new active doctrine is Codex starvation and CultNet liberation: runtime data should be typed CultCache documents; Epiphany-controlled subsystems should communicate through CultNet typed contracts; generic JSON is contamination except at schema/wire, hostile ingress, sealed forensic, or named quarantine boundaries; and vendored Codex should shrink to OpenAI subscription auth/model transport only. `codex_message_processor.rs` remains a contaminated host organ until Epiphany operator surfaces, worker intents/results, runtime lifecycle, and tests are evacuated to native CultNet/CultCache surfaces. - next_action: Start the liberation pass, not outward bridge work: create `notes/codex-auth-spine-inventory.md` to inventory the minimum Codex auth/model-call path, create `notes/json-contamination-ledger.md` to classify Epiphany-relevant JSON uses, then choose the first typed-document replacement target such as `selfPatch` or worker launch/result cargo. + summary: The Codex starvation pass has its first receipts. `notes/codex-auth-spine-inventory.md` maps the minimal vendored OpenAI auth/model-call spine; `notes/json-contamination-ledger.md` classifies the major Epiphany JSON uses by allowed edge, quarantine, or internal contamination. The first cut moved role-result `selfPatch` handling from raw JSON plus duplicated validators to the typed `AgentSelfPatch` document contract, with JSON serialization retained only at the legacy app-server protocol projection. + next_action: Continue the liberation pass by replacing worker launch/result cargo: remove `EpiphanyJobLaunchRequest.input_json` and `output_schema_json` as internal authority, define typed launch/result documents plus schema ids in `epiphany-core`, and make `codex_message_processor.rs` project those documents instead of assembling loose JSON blobs. diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs index fe59dff7..17df20f6 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs @@ -13371,7 +13371,10 @@ fn map_protocol_role_finding( evidence_gaps: finding.evidence_gaps, risks: finding.risks, state_patch, - self_patch: finding.self_patch, + self_patch: finding.self_patch.map(|patch| { + serde_json::to_value(patch) + .expect("AgentSelfPatch is a serializable protocol projection") + }), self_persistence: finding .self_persistence .map(map_protocol_role_self_persistence_review),