Runtime and event flow
September 19, 2026 · View on GitHub
Components
Codex App Server ─events─► FactoryRuntime ─snapshot─► ObservationBuilder
▲ │ │
│ │ ▼
└── steer / interrupt ◄── FactoryPolicy ◄─scores─ JevForemanModel
│
▼
RunStore
state.json + events.jsonl
CodexAppServerWorkerowns one App Server subprocess, thread, and active turn.FactoryRuntimeowns lifecycle state, the event queue, and active worker tasks.ObservationBuildergathers bounded worker, event, and Git evidence concurrently.JevForemanModelis the only module that imports the TypeSafe SDK.FactoryPolicyis pure deterministic decision logic.RunStoreatomically replaces state and appends immutable events.
Simulation classes implement the same model and worker protocols. They exist for the demo and offline tests; real runs default to Jev and Codex.
One assessment cycle
- A worker event enters the
asyncio.Queue. - The watcher drains adjacent events and applies the minimum assessment interval.
- Completion, failure, and stop events force an immediate cycle.
- Git status/diff and current state become one bounded
FactoryObservation. - The model returns ten probabilities, including repository
AGENTS.mddrift. - Pydantic validates and normalizes the assessment.
- Policy returns one legal
Intervention. - Runtime may steer the active turn, interrupt it, or apply another lifecycle action.
- The action and any steering message are persisted before observation continues.
Foreman-generated events do not feed back into the queue, preventing the observer from triggering itself recursively.
Shutdown
Worker timeout, overall timeout, escalation, and cancellation first request turn/interrupt.
If App Server does not complete the turn during the grace period, Foreman terminates the subprocess
group. Final state and the terminal event are persisted before the runtime closes the model client.
Reading the code
Start with these modules:
src/foreman/runtime.py— concurrency and lifecycle.src/foreman/policy.py— allowed decisions and ordering.src/foreman/observation.py— evidence boundaries.src/foreman/foreman/jev.py— SDK isolation.src/foreman/workers/codex_app_server.py— steerable App Server integration.src/foreman/workers/codex.py— non-steerablecodex execfallback.