Codex's Architecture: From a Single Model Call to a Recoverable Runtime System
Coding agent builders get a concrete map of where naive agents break down and the exact boundaries Codex adds, which separates a demo from a runtime that survives restarts and grows experience. The patterns, from context projection to privilege-limited background agents, transfer directly to any agent architecture.
Codex's source shows a chain that begins with a user's input and ends with a recoverable storage layer. The execution path goes through session admission, context projection, model request, tool execution, and result write-back, but a second lifecycle path feeds results into rollout files, background memory consolidation, and restart recovery. Each step exists because a naive agent would break at that point.
Key boundaries include thread/session/turn resource layering with explicit admission states, a ContextManager that projects canonical history into model input, a unified ToolInvocation for native/MCP/Code Mode tools, and a persistence split where JSONL is the source of truth and SQLite is just an index. A two-phase memory pipeline extracts from rollout, then runs a heavily restricted consolidation agent that cannot read or generate memory, access the network, or use plugins.
Codex's architecture is reactive, not feature-driven: every layer exists because a naive agent would collapse at that point, which gives the design a strong sense of necessity.
Separating the source of truth (JSONL) from the index (SQLite) protects audit correctness from performance pressure, a pattern worth copying for any system that must both record and query.
The memory consolidation agent is deliberately crippled to prevent recursive capability amplification, showing that self-improvement must be bounded by explicit privilege limits.
Treating conversations as resources with lifecycles, rather than message lists, is what makes concurrency, interruption, and shutdown manageable in a local coding agent.
The model never sees raw history; it sees a projection. That boundary prevents unsupported media and stale metadata from polluting the prompt, and it keeps the fact source clean.