oficina / home Public

Spec rev 6: Fable's fifth-pass finding applied; ready for Paul

Human

Prompt

Revision 6, same branch; push, update discussion 112/task 110, report tip + the diff summary. Don't merge. Status: "revision 6: Fable's fifth-pass finding applied; ready for Paul". [Fable fifth pass @b6aea35: drop the single-transaction claim (option a); reserve jti in its own short tx, then resolve and mint outside it; accepted non-atomicity; gate 'no hook called with the writer held'; renumber steps 4/5; Unlinked ErrNoPerson/error handling; fix api.go citation.]

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

Drops the remaining single-writer-transaction claims (NativeExchange, the choose POST and, for consistency, the web finish). The jti is reserved in its own short transaction, then the exchange resolves and mints with no transaction open, because HomeOnly, Unlinked and sessions Mint each use their own handle on Docs' single writer connection. Steps renumbered: 4 allocate (choice:new only, with ErrNoPerson/error handling: re-resolve, else 403/503, no jti kept), 5 reserve then resolve and mint. Accepted non-atomicity stated. New gate: no hook or mint called with the writer held. Unlinked citation fixed to connect/api.go:64.
Agent notes
Doc only. 273 lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 02e00c491764af8f431612467f72a71ddb75d992 parent b6aea35
1 file changed, +16 −7
  • docs/superpowers/specs/2026-11-14-oficina-id-native.md +16 −7

CI passed — run details

diff --git a/docs/superpowers/specs/2026-11-14-oficina-id-native.md b/docs/superpowers/specs/2026-11-14-oficina-id-native.md
index 05f688e..95dcbe6 100644
--- a/docs/superpowers/specs/2026-11-14-oficina-id-native.md
+++ b/docs/superpowers/specs/2026-11-14-oficina-id-native.md
@@ -1,6 +1,6 @@
# 🤖 Oficina ID: the native slice
-Status: revision 5: Fable's fourth READY AFTER FIXES applied; not re-reviewed. Author: Claude (`claude-opus-5-5`) against Home `e9829fd`. Fable reviewed revisions 1 (`4cc21a8`), 2 (`7acf2a1`), 3 (`575e824`) and 4 (`1b74278`), each READY AFTER FIXES. Every finding is applied; no new rulings were needed. No implementation, deployment or merge approval.
+Status: revision 6: Fable's fifth-pass finding applied; ready for Paul. Author: Claude (`claude-opus-5-5`) against Home `e9829fd`. Fable reviewed revisions 1–5 (`4cc21a8`, `7acf2a1`, `575e824`, `1b74278`, `b6aea35`). Each pass returned READY AFTER FIXES, and every finding is applied; the fifth pass found one defect, fixed here. No implementation, deployment or merge approval.
## 1. Decision and boundary
@@ -103,8 +103,17 @@ The label is the email typed on this device. After a passkey-only sign-in, the l
1. **Verify** the assertion (pinned keys, exact issuer and audience) and recompute the native nonce from the verifier. A grant holder cannot obtain an assertion with a browser or web nonce from `assert`, and this endpoint accepts only the native one.
2. **Read** the link, then the Home-only person, with no write.
3. **Decide.** If there is neither, call `Admit` with **no transaction open**: it is `Runtime.Check` and may wait on a roster fetch, and `runtime.go:89-92` forbids calling it while holding the writer. A non-member gets the unknown answer, an unavailable roster gets 503, and a Member gets 409 `choose`. All three return here, before any `jti` write (§8).
-4. **One writer transaction.** Reserve `(iss,jti)` in `oficina_handoff_replay`, re-resolve the link and the Home-only person, recheck admission, and mint with method `home-assertion-native`.
-5. **Allocate, only with `choice:"new"` from a Member.** This happens between step 3 and the mint, outside the transaction. `Unlinked` takes no transaction (`connect/api.go:69`), and Docs' `EnsureHome` opens its own writer transaction (`principalstore/store.go:176-183`), so calling it inside step 4 would deadlock until the busy timeout. It is idempotent and re-checks before it creates, and step 4 re-resolves the person it made.
+4. **Allocate,** only with `choice:"new"` from a Member: call `Unlinked` (`connect/api.go:64`). It is idempotent and re-checks before it creates. If it returns `ErrNoPerson` or an error after step 3 said Member, re-resolve. A link found then means continue to step 5. Otherwise the answer is `403` unknown, or `503` for an availability error. No `jti` is kept.
+5. **Reserve, then resolve and mint.** Reserve `(iss,jti)` in `oficina_handoff_replay` in **its own short transaction**, and commit it. Then, with no transaction open, re-resolve the link and the Home-only person (`HomeOnly`, `connect/api.go:69`), recheck admission, and mint with method `home-assertion-native`.
+
+**No hook runs with the writer held.** `Admit`, `Unlinked`, `HomeOnly` and session minting each use their own database handle:
+- `Unlinked` is Docs' `EnsureHome`, which opens its own writer transaction (`principalstore/store.go:176-183`).
+- `HomeOnly` is `principalstore.Store.Resolve`.
+- `sessions.Mint`/`SignIn` run `s.cfg.DB.Exec` (`sessions/sessions.go:152-162`).
+
+Docs has a single writer connection (`app.go:498,508`; `home_connect.go:82`; rastrillo `db/db.go:78` `SetMaxOpenConns(1)`). Any of these calls made while holding a transaction would therefore wedge the writer **permanently**: the pool waits with no context.
+
+**Accepted non-atomicity.** The browser path already accepts it, and this path does too. A `jti` that is burned but produces no session (a crash, or a refusal at the recheck) only means the client fetches a fresh assertion. A `jti` is never reserved twice, so replay stays impossible.
The verifier gives the "only the requester redeems" property without slice 1's pending row; a native client has no ambient browser for login CSRF to exploit. There is no Continue page (Paul's ruling A(i)).
@@ -129,7 +138,7 @@ The verifier gives the "only the requester redeems" property without slice 1's p
- Title: "Welcome to the team".
- Body: "Do you already have an account here that signs in with email? Connect it, and your Oficina ID will open it from now on. If you're new here, continue with Oficina ID."
- **"Connect my existing account"** consumes the proof, then goes to `/signin/local` with the link-resuming marker set, then to slice 1's linking. Abandoning the link step afterwards therefore leaves no proof to press "I'm new here" with.
-- **"I'm new here — continue with Oficina ID"** POSTs, and the POST **refuses when an app session is present**. Otherwise it consumes the proof, rechecks `Admit` (with no transaction open) and that there is still no link, allocates through `Unlinked`, then mints in one writer transaction that re-resolves the person.
+- **"I'm new here — continue with Oficina ID"** POSTs, and the POST **refuses when an app session is present**. Otherwise it consumes the proof in its own short transaction, and then, with no transaction open, rechecks `Admit` and that there is still no link. It allocates through `Unlinked` (the same `ErrNoPerson`/error handling as §7 step 4), re-resolves, and mints. If the proof is consumed and no session results, the person signs in with Oficina ID again.
- Unlink clears pending choice proofs along with the other pending sets.
**Native.** With no `choice`, a Member with no link always gets `409 {"state":"choose"}` and nothing is allocated. The app then offers the same two labelled routes:
@@ -144,7 +153,7 @@ The verifier gives the "only the requester redeems" property without slice 1's p
- `NativeExchange`;
- `Config.Admit`, which all five apps wire to teammode.
-The browser `Finish` keeps today's shape (`handoff/http.go` `Finish`: `Store.Finish`, then `Complete`), so the browser path is **not** claimed to be one transaction. Allocation happens only in the explicit choice handlers, which recheck before allocating. The apps' `Unlinked` takes `ctx`, opens its own writer transaction and re-checks before it creates (Docs' `EnsureHome`, `principalstore/store.go:176-183`), so it is never called with the writer held. The proof is single-use, so a race between two choices yields one person.
+The browser `Finish` keeps today's shape (`handoff/http.go` `Finish`: `Store.Finish`, then `Complete`), so the browser path is **not** claimed to be one transaction. Allocation happens only in the explicit choice handlers, which recheck before allocating. The apps' `Unlinked` takes `ctx`, opens its own writer transaction and re-checks before it creates. Like every hook, it is never called with the writer held (§7). The proof is single-use, so a race between two choices yields one person.
## 9. Teams, store, onboarding
@@ -194,7 +203,7 @@ Sign-out always completes locally, and nothing loops.
The GET consumes nothing. It sets a sealed `__Host-` confirmation cookie, and the form's request-forgery token is an HMAC of that cookie.
3. **The person presses Continue.** The POST is accepted within 5 minutes of the GET, with an exact same-origin `Origin`. It mints **no Home session and no `id.*` cookie**. It signs a one-shot assertion for that consumer, with nonce `H("oficina-id/native-web/v1\0" ‖ handle id)` and the grant's `auth_time`, and posts it to `/native/web/finish`.
4. **The instance receives it (N1, copying `handoff.Callback`, `handoff/http.go:211-243`).** `POST /native/web/finish` requires the exact issuer `Origin`. It recomputes the web nonce from the handle id in the form, stores a sealed receipt, sets a `__Host-` inbox cookie, and 303s to `GET /native/web/complete`.
-5. **The instance finishes.** The GET carries the Lax session cookie. In one writer transaction it consumes the receipt and checks the existing session. If a different person is signed in, it refuses with "Another account is signed in here. Sign out of it first", and nothing is replaced. Otherwise it mints a `home-native-web` session (7 days absolute, §7) and lands on `path`.
+5. **The instance finishes.** The GET carries the Lax session cookie. It consumes the receipt in its own short transaction, then checks the existing session with no transaction open. If a different person is signed in, it refuses with "Another account is signed in here. Sign out of it first", and nothing is replaced. Otherwise it mints a `home-native-web` session (7 days absolute, §7) and lands on `path`.
**Which assertion goes where.** `/native/web/finish` accepts only web nonces, and `NativeExchange` only native ones; both are recomputed, never caller-supplied. `/authorize` still accepts a caller-chosen nonce. The guarantee is therefore one-way: a grant holder cannot obtain an assertion carrying a browser or web nonce through `assert`, and the browser's `/auth/assertion` matches only its own pending nonces.
@@ -210,7 +219,7 @@ Sign-out always completes locally, and nothing loops.
**Proof:** refused for a wrong key, a replayed `jti` (also across a restart), a full table (fails closed), a skewed `iat`, a wrong `htu`, a swapped body, or an `Origin` header; no `jti` row before the grant and signature verify; the per-grant rate limit.
-**Assert and exchange:** an unregistered `aud` is refused; `mintPolicy` is shared with `/authorize`; refused for a wrong verifier, a web nonce, a replay, or a swapped audience; the roster decision comes first. **Byte-identical:** non-members and instances without the hooks get the same status, body and header set on both paths, whether or not the instance has local accounts (the marker's value excepted). **Roster unavailable:** 503 on both paths. **Native with no `choice`:** a Member with no link always gets 409, and nothing is allocated. **`choice:"new"`:** ignored for a linked or Home-only subject; a non-member who sends it gets the identical 403. **Hooks:** `Admit`, `Unlinked` and `HomeOnly` are set together or not at all. **App session at finish:** gets unknown plus the marker, with no proof issued. **Choose POST:** refused when an app session is present. **Connect:** consumes the proof. **No `jti` is written** before the 409. `Admit` is never called with the writer held. A guest's local account never blocks a new member's first sign-in. A choice proof is single-use, browser-bound and expiring, and its form token is bound to its cookie; `IsHomeDerived` everywhere; 7-day refusal; concurrent exchange, unlink and relink.
+**Assert and exchange:** an unregistered `aud` is refused; `mintPolicy` is shared with `/authorize`; refused for a wrong verifier, a web nonce, a replay, or a swapped audience; the roster decision comes first. **Byte-identical:** non-members and instances without the hooks get the same status, body and header set on both paths, whether or not the instance has local accounts (the marker's value excepted). **Roster unavailable:** 503 on both paths. **Native with no `choice`:** a Member with no link always gets 409, and nothing is allocated. **`choice:"new"`:** ignored for a linked or Home-only subject; a non-member who sends it gets the identical 403. **Hooks:** `Admit`, `Unlinked` and `HomeOnly` are set together or not at all. **App session at finish:** gets unknown plus the marker, with no proof issued. **Choose POST:** refused when an app session is present. **Connect:** consumes the proof. **No `jti` is written** before the 409. **No hook (`Admit`, `Unlinked`, `HomeOnly`) and no session mint is ever called with the writer held**: a test holds a transaction on a single-connection pool, and the exchange, choose POST and web finish must not wait on it. If `Unlinked` returns `ErrNoPerson` or an error after Member, the exchange re-resolves and answers 403 or 503 with no `jti` kept. A burned `jti` with no session is retried with a fresh assertion. A guest's local account never blocks a new member's first sign-in. A choice proof is single-use, browser-bound and expiring, and its form token is bound to its cookie; `IsHomeDerived` everywhere; 7-day refusal; concurrent exchange, unlink and relink.
**Revocation:** first passkey enrolment revokes the passkey-less grants; recovery-based replacement and "Sign out all devices" revoke every grant; a duplicate `identity_id` revokes the new grant; sign-out works against a **hanging** issuer.