Skip to content

FLT-399 I3b mobile routes v4.1

Additive contract for the mobile session list, the session SSE stream, the existing handoff used as the approve action, and the optional read-route origin allowlist. This document does not change the pinned I3a v2, v3, or v4 contracts or their vectors. Field rules R1 to R27 still apply. A body that this document does not name stays default-deny.

Author: Gronktayvius (Grok), lane WT-1d5b. Date: 2026-11-07.

1. Auth, Host, and Origin

Every route below uses the same default-deny credential check as the other session routes.

  • GET /v1/sessions and GET /v1/sessions/{wt}/stream are read routes. The read credential is accepted. A missing or unknown credential is 401 {"error":"unauthorized"}. The mutate credential on the stream is 403 {"error":{"type":"route_disabled","ticket":"FLT-399 I3"}}. The list stays reachable with the mutate credential, matching the I3a list (it is not a single-session GET).
  • Any method other than GET on the list or on the stream is 405 {"error":{"type":"method_not_allowed","use":"/v1/sessions/{wt}"}} once a credential is accepted. No credential is still 401.
  • Host stays exact: 127.0.0.1:4319 or [::1]:4319. Cloudflare rewrites Host, so an allowlisted Origin never relaxes Host. A rejected Host is 403 {"error":"Forbidden Host header (DNS rebinding guard)"}.
  • Origin, when present, must be the loopback origin, or, on a read route only, an exact entry from the allowlist in section 5. No Origin header is allowed (same-site, CORS-free). A rejected Origin is 403 {"error":"Forbidden cross-origin or file/null-origin browser request (EMBRACE guard)"}. The check runs before auth.

2. GET /v1/sessions

Read-only. The handler renders each wtRecords entry with the same snapshot function as GET /v1/sessions/{wt}, with ticketPanel omitted. An expired or absent lease is owner: null and lease: null, the same as the single-session GET. A lease id is never rendered.

Success is 200, Content-Type: application/json, no extra headers:

{"sessions":[{"wt":"WT-a001","owner":"bob","version":1,"lease":{"owner":"bob","expiresAt":"2026-11-07T00:00:30Z"}}]}
  • Members of the root are exactly sessions, or sessions then truncated when the file has more than 256 records.
  • sessions is an array sorted by wt ordinal ascending, unique wt values.
  • Each item's members, in order, are wt, owner, version, lease.
  • lease, when not null, is exactly {owner, expiresAt}. lease.owner equals owner. There is no leaseId and no ticketPanel.
  • At most 256 items. When the file has more, the response is the first 256 and "truncated":true. truncated is absent otherwise.
  • A missing sessions file is {"sessions":[]}. The file is not created.
  • A corrupt sessions file is 500 {"error":{"type":"sessions_corrupt"}}, the same body as the single-session GET. The file is not overwritten.
  • Lock order is unchanged: the session gate, then shared-sessions.json.lock. The lock is not held across the response write. Contention is 503 {"error":{"type":"busy"}}.
  • {wt} that fails R1 inside the file, or a non-object record, is the corrupt-file error.

The emitted body is checked by the list validator (R28) before it is written: no whitespace, no ticketPanel, no leaseId, version a non-negative integer within the safe integer range, owners and timestamps under R2 and R8.

3. GET /v1/sessions/{wt}/stream

Read credential. Server-Sent Events.

Headers on success:

  • Content-Type: text/event-stream
  • Cache-Control: no-store

Framing, each event one line of JSON and no newline inside data:

event: snapshot
data: {"wt":"WT-bb01","owner":"alice","version":1,"lease":{"owner":"alice","expiresAt":"2026-11-07T00:00:30Z"},"ticketPanel":{}}
  • On connect the server sends event: snapshot whose data is byte-for-byte the single-session GET body, from the same snapshot function (including ticketPanel, still without leaseId).
  • The server polls the sessions file at most once per second, under the same per-worktree lock order as other readers, and sends another event: snapshot only when that record's version changes. The lock is released before the sleep.
  • A : keepalive comment is sent every 15 seconds.
  • The server closes the stream after 10 minutes. The client reconnects.
  • At most 8 streams are open gateway-wide. The 9th is 503 {"error":{"type":"stream_capacity"}} with Retry-After: 5 and Content-Type: application/json. No event bytes are sent.
  • {wt} is validated with R1 before any stream starts. A bad wt is 400 {"error":"bad_wt"}.
  • An unknown wt is 404 {"wt":"...","version":0}, the same body as the single-session GET. The server does not stream a bootstrap snapshot.
  • A client disconnect stops the stream immediately. The slot and the per-stream buffers are released. The server does not buffer an unbounded event queue.
  • Token values are never logged.

4. Approve handoff

There is no new approve route. POST /v1/sessions/{wt}/handoff is the mobile approve action. It requires the mutate credential. Origin stays loopback-or-absent. An allowlisted read origin is rejected on this route.

Request (R2, R3, R6, R4):

{"toOwner":"bob","leaseId":"<32 lowercase hex>","expectedVersion":1,"idempotencyKey":"<canonical uuid>"}

Success is 200:

{"wt":"WT-cc01","leaseId":"<new 32 lowercase hex>","version":2,"expiresAt":"<R8 timestamp>","elapsedMs":0}

Idempotency (R17): the same key and the same fingerprint (toOwner, leaseId, expectedVersion) within 10 minutes replays the stored response byte for byte, including a later replay after the lease clock would no longer accept a fresh handoff. The same key with a different fingerprint is 409 {"error":{"type":"idempotency_conflict"}}. A confirming GET /v1/sessions/{wt} shows owner equal to toOwner and still has no leaseId in the snapshot.

5. Origin allowlist

Optional file gateway-allowed-origins.json in the gateway user-home config directory, next to the traffic log: {userHome}/.fleet/forge-gateway/gateway-allowed-origins.json.

  • A missing file means the strict default. Nothing is logged and the directory is not created for the allowlist.
  • The file is a JSON array of at most 8 strings, at most 4096 bytes. Each entry is an exact origin: https:// only, host (letters, digits, ., -) plus an optional port 1 to 65535, no userinfo, no path, no query, no fragment, no wildcard, no space.
  • The extra origins are accepted only as the Origin header on the read routes: GET /v1/sessions, GET /sessions, GET /v1/sessions/{wt}, and GET /v1/sessions/{wt}/stream. Match is exact and ordinal after trimming the header.
  • Mutate routes (POST lease, PUT, DELETE lease, POST handoff, POST /v1/theia/open) still require no Origin or the loopback origin.
  • One invalid entry, a ninth entry, a non-array, a comment, a trailing comma, or a file over the byte cap rejects the whole file. The gateway logs a token-free reason code (not-json, not-array, too-many, bad-entry, too-large, unreadable) to origin-allowlist.log in the same directory and uses the strict default.
  • https://evil.example is rejected unless that exact string is a valid entry.