7.3 KiB
7.3 KiB
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
ResponsesApiRequestis serialized to JSON for the OpenAI Responses HTTP body. - Real need: OpenAI wire protocol.
- Verdict: allowed edge JSON.
- Current mechanism: typed
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- Former mechanism:
EpiphanyJobLaunchRequest.input_jsonandoutput_schema_json. - Real need: launch role workers with structured instructions and expected response shape.
- What broke when deleted: app-server helper tests and the manual launch handler had to stop treating launch cargo as loose JSON.
- Essential or bad ownership: bad ownership. The core request now carries
EpiphanyWorkerLaunchDocumentplusoutput_contract_id. - Remaining contamination:
ThreadEpiphanyJobLaunchParamsstill acceptsinput_jsonat the legacy app-server protocol edge and immediately parses it as hostile ingress. Final shape should be CultNet typed launch intent, not app-server JSON-RPC. - Files:
epiphany-core/src/surfaces/worker_launch.rs,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.
- Former mechanism:
epiphany-core/src/surfaces/role_result.rs- Current mechanism:
state_patchandself_patchareserde_json::Value;selfPatchis 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.
selfPatchalready has a typedAgentSelfPatchdocument inagent_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.
- Current mechanism:
vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs- Current mechanism:
ThreadEpiphanyRoleFinding.self_patch: Option<serde_json::Value>remains for the legacy projection. Launch params now use typed worker launch documents andoutput_contract_id. - 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; keep app-server protocol only as a temporary compatibility reliquary.
- Current mechanism:
Quarantine JSON
epiphany-core/src/heartbeat_state.rs- Current mechanism: heartbeat cognition stores some
serde_json::Valuefields. - 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.
- Current mechanism: heartbeat cognition stores some
- 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: allowed MCP wire JSON, but not allowed as Epiphany durable state or internal authority.
- Simpler architecture: an Epiphany-owned boundary with typed intent/result/receipt documents on the Epiphany side and normal MCP JSON-RPC on the MCP side. Do not pretend MCP itself should stop being JSON.
- 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
- Done: purge
selfPatchas internal JSON. Role-result interpretation now stores the typedAgentSelfPatchdocument and shares the agent-memory contract; JSON remains only at the legacy app-server projection. - Partly done: core worker launch
input_jsonandoutput_schema_jsonare replaced by typed launch documents and output contract ids. Remaining cut is the protocol edge. - Done: replace role
statePatchJSON with typed map/planning/graph patch documents.EpiphanyRoleFindingInterpretationnow carriesEpiphanyRoleStatePatchDocument; app-server maps it to the legacy protocol patch without JSON round-tripping. - Done: replace runtime job result JSON projections. Runtime-spine results now project through typed role/reorient interpreters instead of
runtime_job_result_to_role_jsonandruntime_job_result_to_reorient_json. - Done: replace app-server launch protocol
input_json/output_schema_jsonwith typed launch documents andoutput_contract_id. - Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into
epiphany_launch.rs, role/reorient result projection intoepiphany_results.rs, scene projection intoepiphany_scene.rs, freshness/reorientation mapping intoepiphany_reorient.rs, context/planning/graph-query projection intoepiphany_context.rs, jobs projection intoepiphany_jobs.rs, retrieve projection intoepiphany_retrieve.rs, pressure/pre-compaction checkpoint projection intoepiphany_pressure.rs, CRRC/coordinator/role-board projection plus acceptance/evidence signal helpers intoepiphany_coordinator.rs, Epiphany JSON-RPC route handling undercodex_message_processor/split into read/proposal routes and mutation/launch/accept/index routes, mutation support helpers intoepiphany_mutation_routes.rs, runtime-spine result snapshot/adaptation helpers intoepiphany_runtime_results.rs, automation/pre-compaction orchestration intoepiphany_automation.rs, state hydration/patch helpers intoepiphany_state_helpers.rs, and the old processor test tail intoprocessor_tests.rs, reducingcodex_message_processor.rsfrom about 21,263 to 10,433 lines. Next replace child-module parent visibility with explicit typed service boundaries and move remaining Epiphany imports/dispatch out of the processor where they do not belong; success means the processor keeps shrinking and ownership gets clearer, not merely better typed. - Seal MCP payloads behind an Epiphany boundary that speaks typed Epiphany documents internally and MCP JSON externally.
- Audit heartbeat cognition values and either type them or explicitly expire them.