Skip to content

FLT-399 I3a contract v3: sessions lease/handoff + Theia open (for sprint lane A)

Status: v3 (2026-11-06). This is the single batched revision agreed with lane A. It folds in every change from the I3a council gate (PR #34, rounds 663ccd5, 2b9e430 and a669e3d). It supersedes v2 (LF hash 8f4d91db...). Server: usage-governor docs/contracts/FLT-399-I3a-sessions-theia-v3.md. Client: fleet-harness contract/i3a.v3.md. Hash rule (agreed): strip one leading UTF-8 BOM, convert CRLF to LF, change nothing else, then SHA-256 in lowercase hex.

Changes from v2

  1. Every error status and body is listed below. Each body comes from the server source, which is cited.
  2. The list path /v1/sessions (no wt) is read-only. POST, PUT and DELETE on it return 405.
  3. Malformed JSON (a non-object root, duplicate keys, a flattened PUT body) returns 400.
  4. A sessions file that is unreadable or the wrong shape returns 500 sessions_corrupt, and nothing is overwritten.
  5. Lock contention gets a single 2 s deadline, then 503 busy.
  6. Theia launches directly with an argument array (no scheduled task). A failed start returns 502 launch_failed. The success wire shape is unchanged.

Credentials

  • Read routes use the per-install read credential, ~/.fleet-secrets/forge-gateway.token.
  • Mutating routes use a SEPARATE mutate credential, ~/.fleet-secrets/forge-gateway-mutate.token: 64 lowercase hex characters, owner-only ACL. It is written only into Theia/dsh client configs, never into the MCP adapter or claude-mem.
  • Both go in the standard HTTP authorization header with the bearer scheme. Read them at runtime.
  • Known limit. Same-user ACLs do not enforce the read/mutate split. Any process running as the same Windows user can read both files. Enforcement needs the dedicated worker account (FLT-355).
  • A wrong or missing credential returns 401 {"error":"unauthorized"} (ForgeLocalGateway.cs:473). A read credential on a mutate route returns 403 {"error":{"type":"route_disabled","ticket":"FLT-399 I3"}} (ForgeGatewayRoutePolicy.cs:28).

Common rules

  • {wt} must match ^WT-[0-9a-z]{4}$; otherwise 400 {"error":"bad_wt"} (ForgeLocalGateway.I3a.cs:63).
  • ETag/If-Match. A strong ETag is the decimal version in double quotes, e.g. ETag: "7". If-Match must carry exactly one strong quoted value. Weak (W/), * or lists get 400.
  • Every write is CAS. A mutating request carries both a lease and the expected version.
  • Concurrency. All session state lives in ONE shared sessions file. Every request (read or write) takes one process-wide lock and one OS file lock under a single 2 s deadline. A write reads the file, applies the per-wt CAS change, then writes temp and replaces. A write to one wt never rolls back a sibling wt.
  • Contention. When the 2 s deadline passes, the response is 503 {"error":{"type":"busy"}} (ForgeLocalGateway.I3a.cs:466). It is retryable.
  • Corrupt file. If the shared file is unreadable, or parses but has the wrong shape (for example "sessions" is not an object, or a per-wt record has the wrong type), every request returns 500 {"error":{"type":"sessions_corrupt"}} (ForgeLocalGateway.I3a.cs:484). The file is never overwritten. It is not retryable.
  • Malformed request. A non-object JSON root, duplicate keys, unknown fields or a wrong shape returns 400 {"error":"bad_request"} (ForgeLocalGateway.I3a.cs:74).

Session object

{ "wt": "WT-xxxx",
  "owner": "<sessionId>|null",
  "version": <int>,
  "lease": { "leaseId": "<opaque>", "owner": "<sessionId>", "expiresAt": "<ISO-8601 UTC>" } | null,
  "ticketPanel": { ... } }
The field is leaseId everywhere.

ticketPanel allowlist. Unknown fields get 400.

Field Type / limit
ticketKey string, ^[A-Z]{2,10}-[0-9]{1,6}$
status enum todo, in_progress, review, blocked, done
checklist array, max 50, of { "id": "<^[a-z0-9-]{1,40}$>", "done": bool } (ids only, no text)
activeFile repo-relative path, max 260, no ..
updatedAt ISO-8601 UTC

Bootstrap and 404

  • GET on an unknown wt returns 404 { "wt", "version": 0 }.
  • The first lease on an unknown wt passes expectedVersion: 0 and creates the record at version 1.

Endpoints

Method + path Request Success Failure
GET /v1/sessions (read credential) — 200 list (pure read, never writes) 500 / 503 as in Common rules
POST/PUT/DELETE /v1/sessions — — 405 {"error":{"type":"method_not_allowed","use":"/v1/sessions/{wt}"}} (ForgeLocalGateway.cs:1627)
GET /v1/sessions/{wt} (read credential) — 200 object + ETag 404 as above
POST /v1/sessions/{wt}/lease {owner, ttlSeconds: 30..600, expectedVersion} 200 {leaseId, version, expiresAt} 409 {currentOwner, version, expiresAt}: lease held by another owner and unexpired. 412 {version}: stale version.
PUT /v1/sessions/{wt} If-Match, X-Forge-Lease: <leaseId>, body exactly {"ticketPanel":{...}} (max 64 KB; a flattened body gets 400) 200 {version} + ETag 409: wrong or expired lease. 412: stale version. 400: shape.
POST /v1/sessions/{wt}/handoff {toOwner, leaseId, expectedVersion, idempotencyKey: <uuid>} 200 {leaseId: <new, for toOwner>, version, elapsedMs} 409: wrong or expired lease. 412: stale version.
DELETE /v1/sessions/{wt}/lease X-Forge-Lease, If-Match 204 409: wrong or expired lease. 412: stale version.

Every row can also return 400, 401, 403, 500 or 503 as described in Common rules. The 409 and 412 bodies are built per request and will be captured verbatim from the live server at deploy.

Handoff details: - Idempotency. A repeat with the same idempotencyKey within 10 minutes returns the SAME response and does not rotate the lease again. - It is atomic: the old lease is invalidated, so the old owner's next write gets 409. - Timing target: under 2 s, measured server-side.

Theia

POST /v1/theia/open with the mutate credential, body { worktreePath }. - Server-side canonicalisation by FINAL HANDLE PATH. Open without following reparse points, read the final path, and reject junctions, symlinks, UNC, \\?\ and alternate data streams. No string-prefix checks. - Allowlist. The final path must equal a registered worktree: listed by git worktree list --porcelain of a repo directly under ~/source/repos, or the repo root itself. - Launch. The gateway starts Theia directly with an argument array: UseShellExecute=false, with the worktree path as one argument. There is no scheduled task, no launcher script and no command string. - Responses: - 202 { launchId } (ForgeLocalGateway.I3a.cs:390), only after the process has started. - 400 {"error":"path_refused"} (ForgeLocalGateway.I3a.cs:368) - 401: missing or invalid credential - 403: read credential used - 502 {"error":{"type":"launch_failed"}} (ForgeLocalGateway.I3a.cs:385). Not retryable.