FLT-399 I3a, DRAFT v2 contract: sessions lease/handoff + Theia open (for sprint lane A)¶
Status: DRAFT v2 (2026-11-05). It folds in lane A's council v1 points 1-10. The I3a council gate can still change it, and WT-98c2 will tell lane A if it does. Target: I3a lands after I1, with :4319 deployed by end of day 2026-11-06, in parallel with I2.
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 (point 10). Same-user ACLs do not enforce the read/mutate split. Any process running as the same Windows user can read both files. The split stops credential spread through generated configs; it does NOT stop a same-user process. Enforcement needs the dedicated low-privilege worker account (plan council revision 1, FLT-355, on Andrew's list). Until that exists, treat a same-user process as able to mutate.
- A wrong or missing credential returns 401. A valid read credential on a mutate route returns 403.
Common rules¶
{wt}must match^WT-[0-9a-z]{4}$; otherwise 400.- ETag/If-Match (point 9). The ETag is a strong ETag: the decimal version in double quotes, e.g.
ETag: "7".If-Matchmust carry exactly one strong quoted value. Weak (W/),*or lists get 400. - Every write is CAS (point 4). Each mutating request carries both a lease and the expected version.
- Concurrency (point 8). All session state lives in ONE shared sessions file. Every mutation happens under one process-wide lock plus an OS file lock: read the file, apply the per-wt CAS change, then write temp and replace. A write to one wt therefore never rolls back a sibling wt.
Session object¶
{ "wt": "WT-xxxx",
"owner": "<sessionId>|null",
"version": <int>,
"lease": { "leaseId": "<opaque>", "owner": "<sessionId>", "expiresAt": "<ISO-8601 UTC>" } | null,
"ticketPanel": { ... } }
leaseId everywhere (point 2).
ticketPanel allowlist (point 1). 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, per the council ruling) |
activeFile |
repo-relative path, max 260, no .. |
updatedAt |
ISO-8601 UTC |
Bootstrap and 404 (point 5)¶
GETon an unknown wt returns 404{ "wt", "version": 0 }.- The first lease on an unknown wt passes
expectedVersion: 0and creates the record at version 1.
Endpoints¶
| Method + path | Request | Success | Failure |
|---|---|---|---|
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 {ticketPanel} (max 64 KB) |
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. |
Handoff details:
- Idempotency (point 6). 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 (point 7)¶
POST /v1/theia/open with the mutate credential, body { worktreePath }.
- Server-side canonicalisation by FINAL HANDLE PATH. Open the directory without following reparse points, read its 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. An argument array, no interpolated launcher script, and a per-launch scheduled-task name ForgeTheiaOpen-<launchId> that is deleted after start.
- Responses:
- 202 { launchId }
- 400: path refused
- 401: missing or invalid credential
- 403: read credential used