An open-source, faster Devin alternative
TypeScript
docs: apply §12 pre-freeze hardening to agent-sessions
Igor Zalutskibb2f9620d3cc
diff --git a/docs/agent-sessions/agents.mdx b/docs/agent-sessions/agents.mdxindex 75e31d63..fff01ed9 100644--- a/docs/agent-sessions/agents.mdx+++ b/docs/agent-sessions/agents.mdx@@ -20,6 +20,6 @@ When a session is created it **freezes** the agent's `prompt`, `model`, and `run## Model-`model` is a `provider/model` id (e.g. `anthropic/claude-opus-4-8`); the chosen [runtime](/agent-sessions/runtimes) determines which models are valid. Usage is billed to your OpenComputer account, or to [your own provider key](/agent-sessions/authentication#model-credentials-byo-key).+`model` is a `provider/model` id (e.g. `anthropic/claude-opus-4-8`); the chosen [runtime](/agent-sessions/runtimes) determines which models are valid. Usage is billed to your OpenComputer account, or to [your own provider key](/agent-sessions/authentication#model-credentials-byo-key). Today the only callable runtime is `claude`.<Note>Additional model providers, and switching a session's model mid-session, are coming soon.</Note>diff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdxindex 63f514c9..e8105dae 100644--- a/docs/agent-sessions/api-reference.mdx+++ b/docs/agent-sessions/api-reference.mdx@@ -15,12 +15,13 @@ Base URL `https://api.opencomputer.dev/v3`. Management calls authenticate with y| `POST /sessions/:id/archive` | Archive (close) a session. || `POST /sessions/:id/client-tokens` | Mint a client token. Body: `scopes?`, `ttl?`. |-Provide `agent` (a saved agent id) **or** inline `prompt` + `model` + `runtime`. `key` gives get-or-create (one session per key). `input` is the task — a string or a full [envelope](/agent-sessions/messaging#the-envelope).+Provide `agent` (a saved agent id) **or** inline `prompt` + `model` + `runtime`. `key` gives get-or-create (one session per key); a request-level `Idempotency-Key` header makes a keyless create retry-safe. `input` is the task — a string or a full [envelope](/agent-sessions/messaging#the-envelope).```Session = { id, status, head, cursor,agent_snapshot: { prompt_hash, model, runtime },- last_turn: { state, result_event_id?, error? }, key?, created_at }+ last_turn: { state, turn_id, started_at, completed_at?, result_event_id?, error?, budget_exceeded? },+ usage: { active_seconds, usd, cap_usd?, tokens? }, key?, created_at }```## Eventsdiff --git a/docs/agent-sessions/durability.mdx b/docs/agent-sessions/durability.mdxindex 5097d35e..7bdadba3 100644--- a/docs/agent-sessions/durability.mdx+++ b/docs/agent-sessions/durability.mdx@@ -34,7 +34,7 @@ What's guaranteed today, and what isn't:| --- | --- || Client disconnects | Reconnect from your cursor; nothing lost. || Session idles | Sandbox hibernates; resumes on the next message. |-| Runtime crashes mid-turn | Auto re-wakes and continues from the hibernated sandbox state. |+| Runtime crashes mid-turn | Auto re-wakes and continues; in-flight work since the last logged event may repeat (make side effects idempotent). || Sandbox is **lost** (not hibernated) | The session may re-run / re-clone. Only **logged or delivered** outputs are durable. |<Warning>diff --git a/docs/agent-sessions/events.mdx b/docs/agent-sessions/events.mdxindex d1c3df5e..1befaba0 100644--- a/docs/agent-sessions/events.mdx+++ b/docs/agent-sessions/events.mdx@@ -12,7 +12,7 @@ Every step a session takes is an **event**, appended to the log in order. The lo"body": { "text": "3 tests fail in auth.spec.ts" }, "refs": {} }```-- **`id`** — unique; the idempotency key for appends.+- **`id`** — the event's own unique id (`evt_…`). The client idempotency key for steering is separate (deduped per session — see [steering](/agent-sessions/messaging)).- **`kind`** — `message` (content), `status` (lifecycle), or `error`.- **`actor`** — who produced it: `{ id, display?, type: "human" | "agent" | "system" }`.- **`level`** — visibility; see below.@@ -28,7 +28,7 @@ Every event carries a `level` saying **who it's for**. You filter the stream (an| --- | --- | --- || `user` | What a person is meant to read — the answer, results, a question back to them. The default for webhook delivery. | a chat bubble, the final result, a notification || `progress` | Plain-language step updates: "cloning the repo", "running tests", "found 3 failures". | a live "what's it doing right now" feed or status line |-| `internal` | The agent's raw reasoning and tool calls — verbose, not meant for end users. | debugging, an audit trail, your own internal console |+| `internal` | Tool calls and runtime detail — verbose, not meant for end users (the model's private reasoning is never surfaced). | debugging, an audit trail, your own internal console |Filtering is **cumulative** — `user` is the narrowest, `internal` is everything:diff --git a/docs/agent-sessions/messaging.mdx b/docs/agent-sessions/messaging.mdxindex 85176e4d..972208ac 100644--- a/docs/agent-sessions/messaging.mdx+++ b/docs/agent-sessions/messaging.mdx@@ -7,7 +7,7 @@ description: "Steer a session, and the shared message envelope"## Steer (inbound)-Send a message to a running or idle session; it wakes and continues with full context. Minimal form is just text:+Send a message to a running or idle session; it wakes and continues with its prior context. Minimal form is just text:```bashcurl https://api.opencomputer.dev/v3/sessions/$ID/messages \@@ -15,7 +15,7 @@ curl https://api.opencomputer.dev/v3/sessions/$ID/messages \-d '{ "text": "also check the CI config", "idempotency_key": "nudge-1" }'```-Pass `idempotency_key` so retries (flaky network, double-click) are de-duplicated — the same key is applied at most once.+Pass `idempotency_key` so retries (flaky network, double-click) are de-duplicated — applied at most once **per session**, so the same key is safe to reuse across different sessions.## The envelope@@ -35,7 +35,7 @@ Every inbound and outbound message normalizes to this shape. The core fields are}```-- **`id`** — unique; the idempotency key.+- **`id`** — the idempotency key, deduped **per session** (not global).- **`actor`** — who sent it (`human` | `agent` | `system`), namespaced.- **`conversation`** — an opaque reply/routing anchor.- **`text`** — the content the agent reads (or that you receive).diff --git a/docs/agent-sessions/overview.mdx b/docs/agent-sessions/overview.mdxindex dc4af94f..9ce6b80d 100644--- a/docs/agent-sessions/overview.mdx+++ b/docs/agent-sessions/overview.mdx@@ -25,10 +25,10 @@ The non-trivial parts you'd otherwise build — and get subtly wrong — handled<CardGroup cols={2}><Card title="Reliable delivery" icon="paper-plane">- Outbound messages are delivered at-least-once, idempotent per destination, retried with backoff, and dead-lettered — no lost or duplicated webhooks.+ Outbound messages are delivered at-least-once, retried with backoff, and dead-lettered — nothing silently dropped. Dedupe on `X-OC-Event-ID`.</Card><Card title="Managed sandbox lifecycle" icon="box">- Provision, hibernate on idle (storage-only ≈ free), wake in milliseconds, recover a dead sandbox, tear down — none of it your problem.+ Provision, hibernate on idle (storage-only ≈ free), wake in milliseconds, replace an unresponsive sandbox, tear down — none of it your problem.</Card><Card title="Isolated execution" icon="shield-halved">The agent's loop runs separately from the sandbox where its file changes and commands execute — the untrusted work is contained, apart from the loop and your model credentials.diff --git a/docs/agent-sessions/quickstart.mdx b/docs/agent-sessions/quickstart.mdxindex 34507c46..23652bdc 100644--- a/docs/agent-sessions/quickstart.mdx+++ b/docs/agent-sessions/quickstart.mdx@@ -13,14 +13,15 @@ export OPENCOMPUTER_API_KEY=your-api-key## 1. Start a session-One call starts a session. Pass a `model`, a `prompt` (the instructions), and `input` (the task).+One call starts a session. Pass a `model`, a `prompt` (the instructions), and `input` (the task) — plus an optional `webhook` to receive every event from the start.```bashcurl https://api.opencomputer.dev/v3/sessions \-H "Authorization: Bearer $OPENCOMPUTER_API_KEY" \-d '{ "model": "anthropic/claude-opus-4-8", "runtime": "claude","prompt": "You are a coding assistant.",- "input": "Clone github.com/acme/widget, run its tests, and summarize what fails." }'+ "input": "Write a Python script that prints the first 20 primes, run it, and report the output.",+ "webhook": "https://your.app/oc-webhook" }'``````json@@ -47,7 +48,7 @@ es.onmessage = (e) => render(JSON.parse(e.data)); // each event: { seq, actor, k## 3. Steer it-Send a follow-up at any time. The session wakes and continues with full prior context.+Send a follow-up at any time. The session wakes and continues with its prior context.```bashcurl https://api.opencomputer.dev/v3/sessions/$ID/messages \@@ -55,9 +56,9 @@ curl https://api.opencomputer.dev/v3/sessions/$ID/messages \-d '{ "text": "also check the CI config", "idempotency_key": "nudge-1" }'```-## 4. Get notified (optional)+## 4. Manage destinations (optional)-Register a webhook and the agent's user-facing messages are delivered to it — signed, retried, and de-duplicated.+You already passed a `webhook` at create. Add or manage more destinations later — each receives events from when it's created (earlier events aren't backfilled yet).```bashcurl https://api.opencomputer.dev/v3/sessions/$ID/destinations \@@ -65,7 +66,7 @@ curl https://api.opencomputer.dev/v3/sessions/$ID/destinations \-d '{ "url": "https://your.app/oc-webhook", "secret": "whsec_…", "level": "user" }'```-See [Webhooks](/agent-sessions/webhooks#verify-a-webhook) to verify the signature.+Deliveries are signed and retried; dedupe by `X-OC-Event-ID`. See [Webhooks](/agent-sessions/webhooks) to verify the signature and inspect deliveries.## Next stepsdiff --git a/docs/agent-sessions/sessions.mdx b/docs/agent-sessions/sessions.mdxindex 9835a7b8..089362d5 100644--- a/docs/agent-sessions/sessions.mdx+++ b/docs/agent-sessions/sessions.mdx@@ -10,7 +10,9 @@ A **session** is the durable unit of an [agent](/agent-sessions/agents) at work:1. You create a session from an agent (or an inline prompt + model). The session starts immediately.2. The [runtime](/agent-sessions/runtimes) executes the agent in a sandbox, appending [events](/agent-sessions/events) to the log as it works.3. With nothing left to do, the session goes **idle** and the sandbox **hibernates** (see [durability](/agent-sessions/durability)).-4. A [steer](/agent-sessions/messaging) message wakes it; it resumes with full prior context. Repeat.+4. A [steer](/agent-sessions/messaging) message wakes it; it resumes with its prior context. Repeat.++<Note>If the runtime crashes mid-turn it auto re-wakes and continues — but in-flight work since the last logged event may repeat, so make side effects idempotent. Details: [durability](/agent-sessions/durability).</Note>## Lifecycle@@ -21,6 +23,6 @@ A **session** is the durable unit of an [agent](/agent-sessions/agents) at work:| `failed` | The session errored out. || `archived` | Closed; read-only. |-A session also carries `last_turn = { state: "ok" | "error", result_event_id?, error? }`, so a one-off session tells you whether it finished and what it produced. By convention the **final result is a `user`-level [`message`](/agent-sessions/events) event**.+A session also carries `last_turn = { state: "running" | "ok" | "error", turn_id, started_at, completed_at?, result_event_id?, error?, budget_exceeded? }` and a `usage` summary (`active_seconds`, `usd`). Together with the status, these tell you whether a one-shot **finished**, is **waiting for steer**, or **stopped** on an error or budget cap — and what it produced. By convention the **final result is a `user`-level [`message`](/agent-sessions/events) event**.<Note>Blocking on input mid-turn (`ask` / awaiting-input) is coming soon. Today, steer is fire-and-continue: send a message and the session incorporates it on its next turn.</Note>diff --git a/docs/agent-sessions/webhooks.mdx b/docs/agent-sessions/webhooks.mdxindex 5672abf2..31cf8764 100644--- a/docs/agent-sessions/webhooks.mdx+++ b/docs/agent-sessions/webhooks.mdx@@ -24,6 +24,8 @@ curl https://api.opencomputer.dev/v3/sessions/$ID/destinations \| `PATCH /sessions/:id/destinations/:did` | Pause or resume (`enabled`), retune `level`/`kinds`, or rotate `secret`. || `DELETE /sessions/:id/destinations/:did` | Remove. |+A destination receives events appended **after** it's created. To capture a whole session, pass `webhook` in `POST /v3/sessions` so it's registered before the agent produces output. (Replaying earlier events with `backfill_from_seq` is coming soon.)+## DeliveriesEvery send and its outcome — the data behind a deliveries dashboard.@@ -45,8 +47,9 @@ Delivery = { id, destination_id, event_id, status, attempts, last_attempt_at, re## Delivery contract- **HTTPS only.** Private, loopback, link-local, and cloud-metadata addresses are refused.-- **At-least-once, idempotent per (event × destination)**, with exponential backoff; after the max attempts a delivery is **dead-lettered** (inspect and redeliver it above).-- **Signed.** Each request carries `X-OC-Signature` (HMAC-SHA256 over `timestamp + "." + body`, keyed by your `secret`) and `X-OC-Timestamp`. The `secret` is write-only — set once, never returned.+- **At-least-once.** Retried with exponential backoff; after the max attempts a delivery is **dead-lettered** (inspect and redeliver it above). A duplicate can still arrive — a send that succeeds as the worker dies, or a replayed turn — so **dedupe on `X-OC-Event-ID`**.+- **Correlation headers.** Every request carries `X-OC-Event-ID`, `X-OC-Delivery-ID`, and `X-OC-Session-ID` (for dedupe and correlation), plus the signature headers below.+- **Signed.** `X-OC-Signature` = HMAC-SHA256 over `X-OC-Timestamp + "." + rawBody`, keyed by your `secret`. Verify against the **raw request body, before parsing it**. `X-OC-Timestamp` guards replay; the `secret` is write-only — set once, never returned.- A delivery succeeds on HTTP `2xx`.### Verify a webhook@@ -54,7 +57,7 @@ Delivery = { id, destination_id, event_id, status, attempts, last_attempt_at, re```jsimport { createHmac, timingSafeEqual } from "node:crypto";-function verify(req, secret, body) {+function verify(req, secret, body) { // body = the RAW request body string, read before JSON.parseconst ts = req.headers["x-oc-timestamp"];if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // reject stale → replay guardconst expected = createHmac("sha256", secret).update(`${ts}.${body}`).digest("hex");