oficina / memoria Public

Connect item follows the stored link; unknown Oficina sign-in resumes the link open

On branch fix/connect-item-when-linked

🤖 Branch fix/connect-item-when-linked @ c5ff381. Not merged, not deployed.

The bug and the fix

The account menu offered "Connect your Oficina account" to every magic-link/Keymail session (offersHomeLink tested v.method). So a person whose account was already linked, but who signed in with Memoria's own email link, was still offered it (Paul hit this). Now the stored link decides: offersHomeLink(r, v) finds the viewer's local identity row (homeLocalID, by the keyed address fingerprint) and asks Bridge.Linked(ctx, id). No row means no link can name this person, so it offers. An error on either lookup means unknown and offers nothing. A Home session is the link, so it is never offered there. The chrome.go change is limited to offersHomeLink and its one caller.

Lookup cost

Per menu render: one indexed lookup on memoria_home_local_identities.address_lookup, plus one on home_identity_links' UNIQUE (issuer, person_id) once the person has a row. The person ID was not already in the request context (admissionOf resolves an ID only for Home sessions, and viewer carries none), so it is looked up here.

Unknown-assertion flow

When an Oficina assertion with no link arrives, home leaves a sealed 10-minute marker. The next fresh local sign-in, at /auth/local/complete, starts the link: /auth/start?return_to=%2Faccount%2Fhome%2Fconfirm, then a fresh Home assertion, then the confirm page, then the confirm POST. Memoria-specific fix needed for this: starting the link needs the person's local identity row, and only /account/home created it. So someone who had never opened that page could not resume, and ended up on the Connect page instead. The new localComplete creates the row first, but only for a fresh local sign-in that carries connect's navigation-marker cookie. Ordinary sign-ins still create nothing, as the existing tests require. It checks the cookie by name (it is unexported in connect); the resume test fails if that name changes.

Dependencies: this pins home fix/connect-item-when-linked @ 08bbcf3, which brings estilo fix/connect-item-when-linked @ 0b375d5. Both must merge first, and then this pin should move to their merge commits.

Success page

The confirm POST redirects to /account/home/confirm?connected=1&return_to=…, which shows "Accounts connected". renderHome now calls connect.PageFor(r, …), so the button goes back to the page the sign-in was heading for. The test checks /search?q=nebula, not /.

Button row

Estilo 0b375d5 puts the connect page's buttons in one <div rst-form-foot> row, primary first. static/chrome.css was regenerated (go run ./scripts/writeestilo); TestDoorStylesAreEstilos failed until that was done. That was the only fallout from the estilo bump.

Confirm step: kept

We kept the explicit confirm click. Skipping it would let a remembered unknown assertion plus a local sign-in link the two accounts with no deliberate gesture. Also, the Oficina assertion carries only an opaque subject, so the confirm page cannot name the Oficina address, only the local one. Instead the confirm page now has its own title and copy: "Connect these two accounts?" / "Your Oficina account is confirmed. Connect it to the Memoria account below, and you can sign in to Memoria with Oficina from now on." The unknown page now says "Sign in to your Memoria account once to connect it to your Oficina account." The hub is still not named.

Was the link actually stored?

Yes. The tests read home_identity_links directly. There is no row before the confirm click and exactly one row for the subject after the POST, both from the menu and in the unknown flow. After that, the same session's next page has no menu item, and a fresh Oficina sign-in with that subject signs in as alice.

Tests (internal/memoria/homelinkedtest.go), each seen red with the fix reverted

  • unlinked local session, with and without an identity row: offered. Red when offersHomeLink returned false for no row, and again for a row with no link.
  • linked, then a magic-link sign-in: no item. Red with the session-method check restored.
  • either lookup failing (each table dropped): no item. Red when an error offered the item, for each lookup.
  • Home session: no item. Red when every signed-in viewer was offered it.
  • confirm POST in the same session: "Accounts connected", the row exists, and the next page has no item. Red with the method check restored.
  • unknown flow end to end (unknown page button goes to /signin/local, then the freshness start, fresh assertion, Memoria confirm copy, POST, stored row, PageFor's way back). Red without localComplete (landed on /account/home), with connect.Page instead of PageFor, and without the copy overrides.
  • marker age: 9 minutes resumes, 11 minutes lands on / with nothing started. This uses the app clock, which WireHome now passes as Now: a.now (time.Now in production). The fixture starts on that clock because the link store refuses to go backwards. Red on the 9-minute case without localComplete. The expiry check itself is home's code and is tested there.
  • button row: one rst-form-foot, primary before ghost, on the start page and the confirm page. Red with estilo pinned back to 530cb93 (zero rows).

GOTOOLCHAIN=go1.26.5 make ci is green locally.

Re-pinned after the coordinator restart. home/connect is now 4d87d00, the connect branch caught up with home main 0ceb238, and estilo comes in at 1817c1c, the homeconnect row branch caught up with switcher tiles d53b8e9. static/chrome.css was regenerated with scripts/writeestilo for the switcher-tiles CSS. The local gate is green with go1.26.5. The pins should move to the merge commits once estilo and home land.

On "name both accounts" (item 4): the Oficina half cannot be named, by design. The assertion's subject is an opaque person ref, and Home's one rule is that it never stores a readable address, so no Oficina address exists anywhere to show. The confirm step names the local account and gets its own question for a title. The explicit click stays, because the resumed flow would otherwise link accounts with no deliberate gesture.

VERDICT: APPROVE-WITH-NITS Branch verdict: ready to merge

GPT-6-Astra (Codex), reviewing for session 21a32889. Reviewed the whole branch at 22f9ce2ffe80a3f63ca73768a01be7103f851c21 against fetched origin/main.

  1. No blocking P0/P1/P2 findings. Security review: I found no P0/P1 issue or demonstrated login-CSRF/account-link substitution in the changed flow. The sealed, ten-minute marker carries no identity; the resumed link still uses the actual fresh local session, a fresh nonce-bound Home assertion, and an explicit CSRF-protected confirmation POST. Success is checked against stored linkage. This is a code-review verdict, not a waiver of the required merge gate.

The wrapper closes the new-account gap: it allocates the local identity only from an actual fresh local session, with admission enforced by ensureHomeLocalIdentity. The row retains sealed-address/fingerprint binding and grants no content or membership access. The Home subject is not used to create it.

Hardening note — internal/memoria/home.go:107–124: the wrapper copies connect's private cookie name and checks presence, not the sealed marker's validity. An invalid, duplicate or expired marker can therefore trigger local-row allocation for an otherwise fresh admitted local user even though shared completion will ignore it. This does not confer authentication or create a link, so it is not a blocker. Prefer a public validated-marker/bootstrap hook in connect; retain an integration test covering name/API drift and add invalid/expired-marker allocation coverage.

Query-cost note: a fresh local identity lookup plus the link-existence lookup can mean two indexed reads per relevant render (one when no identity row exists), rather than exactly one.

Validation: GOTOOLCHAIN=go1.26.5 make ci hit the unchanged TestAModelResponseIsCheapToProcess timing failure (“no row with time to spare”). It repeated on the branch and reproduced on a separate origin/main worktree. Focused Connect/Unknown/HomeRouter tests through make test passed, as did make migration-check. The exact-head hub CI is green. Land the reviewed dependencies and refresh pins after squash as needed.

New head: 7fb47d980a219bac639cee1c8608c862cf38ebea. estilo #25 and home #84 have merged, so this branch now pins main: estilo f14458a, and home/connect and home/handoff ff16bf5. Current origin/main is merged in; only go.mod and go.sum conflicted, and those were resolved to the new pins. writeestilo, where this repo has it, leaves the vendored CSS unchanged. The local gate is green with go1.26.5.