Event-sourced sessions
A session is an append-only log in PostgreSQL. Streams resume exactly, the hub fans events out, and nothing is replayed twice.
On this page
The headline promise of Argus is that a session keeps going when every client disconnects, that any device can attach and see the whole history plus the live stream, and that a client which reconnects gets exactly the events it missed. The design that keeps that promise is simple: the event log is the state.
The log is the state
Every session has an append-only list of events. An event has the session, a gapless sequence number seq, the run it belongs to, a type, a time, an actor (user, app, agent or system), a JSON payload, and the trace identifiers of the work that produced it. Nothing else holds the progress of a run. A run's working state is rebuilt from its events, so there is no separate checkpoint format and no determinism rule for model or tool code.
| Family | Event types (examples) |
|---|---|
| Conversation | session.created, session.status, message.user, message.agent |
| Model | model.started, model.completed, context.summarized, usage.snapshot |
| Tools | tool.requested, tool.policy, tool.completed, tool.failed, tool.outcome_unknown |
| Runs | run.started, run.status, run.completed |
| Workflows | judge.verdict, loop.iteration, artifact.written |
| People | human.requested, human.answered |
| Money and trouble | budget.warning, budget.exhausted, error |
| Live only | delta.text, never stored |
The set is a public contract. The schemas live with the API contract and are checked against recorded fixtures in tests, and they are extended only additively.
Appending, and why the numbers have no gaps
An append is one database transaction. It reserves the next block of numbers by updating the session's last_seq counter, then inserts the events. Concurrent appends to one session therefore serialise on that row, so seq is gapless within a session. Callers can also state the number they expect the log to end at, and the append is refused if another writer got there first.
The database enforces the append-only rule itself. A trigger, events_append_only, refuses any update or delete of an event row, so the log cannot be edited by a bug or by the application's own role. That is what lets the log double as the audit trail.
When the transaction commits, the store sends a PostgreSQL notification carrying the session and the new seq.
Streams that resume
GET /v1/projects/{project}/sessions/{session}/events returns the log as Server-Sent Events:
- Each event is sent with
id: <seq>, so a browser's built-inLast-Event-IDreconnect, and the SDK's, work unchanged. - A reconnect with the last number seen receives exactly the events after it, then the live tail. There are no duplicates and no holes.
- An idle stream gets a comment line about every 15 seconds so proxies keep it open.
- The same route pages history with
?after=<seq>&limit=, so history and live follow are one mechanism.
The app server passes streams through unbuffered, so a person in the app sees the same stream a CLI does.
The hub and deltas
<figure class="diagram" data-diagram="hub"> <div class="diagram-scroll" role="region" aria-label="Figure 2, scrolls sideways" tabindex="0"> <svg class="d-w780" viewBox="0 0 780 250" role="img" aria-labelledby="dg-hub-t dg-hub-d" focusable="false"> <title id="dg-hub-t">How an event reaches a client</title> <desc id="dg-hub-d">The runner appends an event to PostgreSQL. The commit notifies the hub in each API process, which reads the session log after its own cursor and sends the new events to its clients over Server-Sent Events, each event carrying its sequence number as the id. Text deltas go from the runner to the hub directly and are never stored.</desc> <defs><marker id="dg-hub-head" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="d-headfill" d="M0 0L10 5L0 10z"/></marker></defs> <rect class="d-box d-argus" x="16" y="110" width="110" height="56" rx="6"/> <text class="d-t" x="71" y="133" text-anchor="middle">Runner</text> <text class="d-s" x="71" y="149" text-anchor="middle">appends events</text> <rect class="d-box d-store" x="200" y="40" width="130" height="190" rx="6"/> <text class="d-t" x="265" y="130" text-anchor="middle">PostgreSQL</text> <text class="d-s" x="265" y="146" text-anchor="middle">events, gapless seq</text> <rect class="d-box d-argus" x="430" y="40" width="150" height="70" rx="6"/> <text class="d-t" x="505" y="70" text-anchor="middle">API process</text> <text class="d-s" x="505" y="86" text-anchor="middle">stream hub</text> <rect class="d-box d-argus" x="430" y="160" width="150" height="70" rx="6"/> <text class="d-t" x="505" y="190" text-anchor="middle">API process</text> <text class="d-s" x="505" y="206" text-anchor="middle">stream hub</text> <rect class="d-box d-client" x="640" y="40" width="124" height="70" rx="6"/> <text class="d-t" x="702" y="70" text-anchor="middle">Client</text> <text class="d-s" x="702" y="86" text-anchor="middle">browser</text> <rect class="d-box d-client" x="640" y="160" width="124" height="70" rx="6"/> <text class="d-t" x="702" y="190" text-anchor="middle">Client</text> <text class="d-s" x="702" y="206" text-anchor="middle">CLI or SDK</text> <line class="d-line" x1="126" y1="138" x2="200" y2="138" marker-end="url(#dg-hub-head)"/> <text class="d-m" x="163" y="130" text-anchor="middle">1. append</text> <path class="d-line d-dash" d="M71 110 V18 H505 V40" marker-end="url(#dg-hub-head)"/> <text class="d-s" x="300" y="12" text-anchor="middle">deltas: live only, never stored</text> <line class="d-line d-dash" x1="330" y1="62" x2="430" y2="62" marker-end="url(#dg-hub-head)"/> <text class="d-m" x="380" y="54" text-anchor="middle">2. notify</text> <line class="d-line" x1="430" y1="94" x2="330" y2="94" marker-end="url(#dg-hub-head)"/> <text class="d-m" x="380" y="110" text-anchor="middle">3. read</text> <line class="d-line d-dash" x1="330" y1="182" x2="430" y2="182" marker-end="url(#dg-hub-head)"/> <text class="d-m" x="380" y="174" text-anchor="middle">2. notify</text> <line class="d-line" x1="430" y1="214" x2="330" y2="214" marker-end="url(#dg-hub-head)"/> <text class="d-m" x="380" y="230" text-anchor="middle">3. read</text> <line class="d-line" x1="580" y1="75" x2="640" y2="75" marker-end="url(#dg-hub-head)"/> <line class="d-line" x1="580" y1="195" x2="640" y2="195" marker-end="url(#dg-hub-head)"/> <text class="d-s" x="610" y="66" text-anchor="middle">4. SSE</text> <text class="d-s" x="610" y="186" text-anchor="middle">4. SSE</text> </svg> </div> <figcaption>Figure 2. How an event reaches a client. The runner writes to PostgreSQL; the commit notifies every API process; each process's hub wakes the subscribers of that session, which read the log after their own cursor. Dashed boxes are outside Argus (people and their tools).</figcaption> </figure>In words: the runner appends an event, PostgreSQL commits it and notifies, and the hub in each API process wakes the subscribers of that session. A subscriber then reads the log after its own cursor and writes what it finds to its client.
The stream hub is the part that fans events out to every open stream, on every device, across processes:
- Each subscriber has its own goroutine and cursor. It reads the log after its cursor whenever its session is notified, in that subscriber's own project context. Delivery is therefore in order, exactly once, and a slow client slows only itself.
- A notification can come from the same process or, through
LISTEN, from another one. A missed notification only delays delivery: every subscriber also re-reads the log on a short poll, and when the listening connection is lost the listener reconnects with backoff and wakes everyone. - Deltas are the text a model is typing. They are streamed as live-only
delta.textevents that are never stored and never move the resume point. The runner coalesces them over a short window. A delta crosses processes by notification only when it fits PostgreSQL's payload limit; otherwise remote subscribers simply get the persistedmessage.agentwhen the step ends. - The hub keeps the in-flight text of each model call, so a client that joins mid-step first receives the text so far and then the live deltas.
Because the persisted events and the live deltas are separate, the log stays small and exact, and a late joiner never needs the deltas to be correct.
Replay
"Replay" in Argus means three things, all reading the same log:
- Reconnect. A client resumes from its last
seq, as above. - History. Opening a session on another device reads the log from the start and then follows it. The run map is drawn from the log, so it is the same picture everywhere.
- Resuming a run. When a runner claims a run, including one whose previous runner died, it rebuilds the run's state by reading its events. A completed model call or tool call is never repeated. A tool call that was in flight at the crash is retried only if the tool is declared idempotent; otherwise the run records
tool.outcome_unknownand asks a person. See The runner.
Costs of the design
- The log grows. At this scale it is one table per database. Partitioning by month and a retention policy are planned, not built.
- Postgres carries the notification load. That is comfortable to hundreds of concurrent streams and would need a change at tens of thousands; the design notes name the scale path (replicas, splitting roles, partitioning by project).
- Event shapes are permanent once published, which is why they change only by addition.
Read next
The runner shows how a run is claimed and stepped, and the same page has the sequence of a whole run.