Skip to content

The agent that grows with you

docs: document local crash recovery contract and replay limits

Teknium375fce5548f4
diff --git a/docs/gateway-local-sessions.md b/docs/gateway-local-sessions.md
index 64dc6af1b05..2247a3e053e 100644
--- a/docs/gateway-local-sessions.md
+++ b/docs/gateway-local-sessions.md
@@ -13,9 +13,11 @@ A server-authenticated identity with `session:create` can call:
The result preserves `session_id`, `stored_session_id`, `messages`, `message_count`, and
`info`, and includes the authority's normal resume snapshot fields. Both session IDs are
the same persisted ID. Creation is lazy with respect to the agent, but reserves the real
-SessionDB/SessionStore identity before returning. Repeating the request ID for the same
-principal and profile reuses its persisted routing entry. Omit the ID for a new session;
-clients that need lost-ACK retry protection must retain it.
+SessionDB/SessionStore identity before returning. One canonical SQLite transaction commits
+the session row, route, and private `gateway.local_policy.v1:<stored-id>` creation receipt.
+Repeating the request ID for the same principal and profile reuses that identity and frozen
+policy, including after daemon death. Omit the ID for a new session; clients that need
+lost-ACK retry protection must retain it. A failed transaction publishes no live session.
Attach another authenticated viewer with `session.resume({session_id})`, and submit
through `prompt.submit({session_id, submission_id, text})`. The accepted receipt is durable
@@ -53,10 +55,17 @@ pending approval alive. A new viewer can resume the same identity and answer thr
- `ping({})` returns `{pong: true}`. `runtime.describe({})` exposes only authority identity,
epoch, and the narrow implemented creation contract. It does not claim full runtime
protocol readiness, reveal credentials/paths, start an agent, or renew a turn lease.
-- Reconnect while the owner remains alive is covered. Cold gateway restart attachment,
- reset/compression identity migration, crash recovery of local queued work, and atomic
- general creation-policy receipts remain separate integration work. Stable routing is
- not a claim of the plan's complete transactional mutation/create API.
+- Cold restart restores valid private local policies and server-owned routes before execution.
+ Local sessions are scoped to their authenticated creating principal and profile. Caller
+ source/native context cannot reconstruct or authorize a local route. Missing, malformed,
+ foreign-profile or mismatched policy/identity fails closed, including preclaim checks;
+ historical pre-extension sessions without a receipt are not silently treated as CLI.
+- Never-started queued local inputs resume through the same authority FIFO after bootstrap
+ readiness. Interrupted started inputs become `unknown`, are never replayed, and pause
+ their followers. Reattachment can inspect the unknown snapshot without running it.
+- Reset/compression identity migration remains separate integration work. A creation receipt
+ cannot authorize a different compression successor; recovery currently pauses that route
+ instead of silently selecting a different stored session or inheriting a default policy.
## Verification
@@ -78,5 +87,11 @@ calls write separate files in three owned working directories. The next requests
the correct cwd results, distinct requested models and surface-specific tool schemas.
Reconnect preserves each agent; launcher environment carriers and config bytes do not
change. This is loopback integration evidence, not native launcher or vendor evidence.
-The frozen policy is currently adapter-owned memory; restart integration must persist and
-restore it before execution. A registered local source missing its policy fails closed.
+`tests/gateway/test_local_session_recovery.py` proves rollback-before-publication and cold
+receipt reuse, then starts separate ordinary daemons on the same temporary database using
+real control-socket tickets and authenticated WebSockets. A fixture-only scheduler barrier
+kills the first daemon after an input commits but before claim; another model request is
+held after its real claim. Fresh daemons execute only the authorized queued input, preserve
+history/source/model/toolsets despite changed defaults, and refuse unknown, foreign,
+missing and corrupt policy cases. A further restart executes nothing twice. All inference
+is loopback-only; this is not native launcher or compression-transfer evidence.
diff --git a/tests/gateway/fixtures/local_recovery_probe.py b/tests/gateway/fixtures/local_recovery_probe.py
index bcbcb8d9d57..46439f07fa5 100644
--- a/tests/gateway/fixtures/local_recovery_probe.py
+++ b/tests/gateway/fixtures/local_recovery_probe.py
@@ -172,6 +172,9 @@ def probe(tmp_path):
pids.append(proc.pid); epochs.append(desc['authority_epoch'])
asyncio.run(second(desc))
assert rows() == {'warm': 'terminal', 'started': 'unknown', 'follower': 'queued', 'foreign': 'queued', 'missing': 'queued', 'corrupt': 'queued', 'safe': 'terminal'}, rows()
+ with daemon(root, home, env, barrier=False) as (proc, desc):
+ pids.append(proc.pid); epochs.append(desc['authority_epoch'])
+ asyncio.run(second(desc))
texts = [next((m.get('content') for m in reversed(r['messages']) if m['role'] == 'user'), '') for r in peer.requests]
assert texts.count('BLOCK_STARTED') == 1 and texts.count('RECOVER_QUEUED') == 1, texts
assert not any(t in texts for t in ('NEVER_REPLAY', 'FOREIGN_QUEUE', 'MISSING_QUEUE', 'CORRUPT_QUEUE')), texts