# Engine socket protocol v1
Transport is a local Unix stream socket, owned by the user with mode 0600. Each
connection carries one request and one response. Frames are a four-byte unsigned
big-endian JSON byte length followed by exactly that UTF-8 JSON. Length is positive
and at most 8 MiB; truncated/oversized/invalid JSON frames are rejected. Socket
read/write timeouts bound incomplete clients. There is no remote unauthenticated
TCP listener. A future web bridge must use this client contract and own its remote
authentication policy.
Request fields: version=1, id (nonempty, at most 128 bytes), command. Commands are
objects tagged by type: hello, status, events (after: exclusive u64 cursor), wait,
pause, resume, cancel. Unknown fields and protocol versions are rejected before
controls execute. Responses echo id and version, include error/message (null on
success), current status, and events. Error codes include unsupported_version,
invalid_request_id, safety_gate_closed and run_finished. Clients verify version
and request ID. Repeating a read is harmless; controls acknowledge their resulting
cooperative state and are durably journaled locally before acknowledgement.
Status records run_id, sequence, updated_at UTC, engine pid, outcome, control,
pause_reason, active study, bounded recent task facts, allocations, message,
wall_ms and active_ms. Outcomes are starting/running/completed/failed/cancelled.
Liveness is separate: a socket response proves reachability at that observation;
a persisted running status alone does not. Task snapshots retain up to 512 recent
entries within a 2 MiB status budget, favoring active entries; all task transitions remain in the event log.
ETA/throughput use active elapsed time, excluding pauses.
Events contain sequence, at, kind and structured data. Sequences increase within
the run. Replay pages hold at most 256 events and approximately 2 MiB of event
JSON; request after the last consumed sequence until caught up. Old locally evicted
pages are read from authoritative storage. No attached viewer is required for
journal/status publication. A healthy local acknowledgement is not a claim that
a remote terminal commit has completed: wait returns terminal only after final
authoritative records are committed. Durable offline status is the fallback after
engine exit. Stale running after process loss is not converted into success.
Pause/resume/cancel are cooperative. Storage and disk safety gates must recover
before explicit resume succeeds. Closing a client/dashboard never cancels work.
The independent dashboard uses these same requests; it owns no engine resources.