oficina / calendar Public

Connect your Oficina account: offered by stored link, not session method open

On branch fix/connect-item-when-linked

Branch fix/connect-item-when-linked @ 79e1477.

The bug and the fix

In Docs, a person whose account was already linked but who signed in with the app's own email link was still offered "Connect your Oficina account": the item was decided by how the session signed in. In Calendar the item was not there at all. It was dropped when Calendar adopted the shared chrome (dbee441), so /account/home could only be reached by typing the URL.

It is back now, and decided by the stored link. handlers.offerHomeConnect (home.go) offers it only when all of these hold:

  • Home is configured;
  • the session is local (magiclink or keymail, read with sessions.Current);
  • requirePerson's person is on the request;
  • Bridge.Linked(ctx, person.ID) returns (false, nil).

An error offers nothing. A Home session never gets it. h.page (render.go) appends the item. chrome_calendar.go is untouched, so this cannot collide with feat/switcher-tiles.

Lookup cost

One SELECT 1 on the UNIQUE (issuer, personid) index of `homeidentity_links per render that draws the menu. The person ID is requirePerson's (CurrentPerson`), so no extra person lookup. Pages outside requirePerson (errors, the connect pages themselves) have no person and are not offered the item.

Unknown-assertion flow (dependency)

The bump to home/connect fix/connect-item-when-linked @ 08bbcf3 adds this flow:

  1. An Oficina sign-in whose subject has no link shows "Oficina account not connected". Its button goes to /signin/local, and a sealed 10-minute marker is set.
  2. The next fresh local sign-in lands on /auth/start?return_to=%2Faccount%2Fhome%2Fconfirm with __Host-oficina-home-init set.
  3. Then the fresh assertion, then the confirm page, then the confirm POST.

An expired marker is ignored. This needs home fix/connect-item-when-linked @ 08bbcf3 and estilo fix/connect-item-when-linked @ 0b375d5. Both must merge first, and then this pin should move to their merge commits. The estilo bump also re-wrote static/chrome.css through writeestilo (estilo main added the rail-account CSS). No other fallout.

Success page

The confirm POST now redirects to /account/home/confirm?connected=1&return_to=…. That renders "Accounts connected" only for a signed-in person whose link is stored. The app now calls connect.PageFor(r, state, label), so the page's button goes back to where the link began, not to "/".

Button row

The connection pages' buttons are one <div rst-form-foot> row, primary first (estilo homeconnect at 0b375d5).

Confirm step: kept

We kept the explicit confirm click. Skipping it would let a remembered unknown assertion plus a local sign-in link 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?". Calendar overrides none of connect's copy, so it gets the new English as is.

Was the link actually stored?

Yes. The tests count rows in home_identity_links directly rather than asking the bridge:

  • 0 rows before the confirm click, 1 after;
  • Bridge.Resolve(subject) returns alice;
  • the next page's menu drops the item.

Tests (internal/calendar/homeconnectitem_test.go), each seen red

  • TestConnectItemOfferedToALocalUnlinkedPerson: red with no item (main's state).
  • TestConnectItemNotOfferedToALinkedPersonSignedInLocally: link, then a fresh emailed-link sign-in in a new browser. Red with the session-method rule (the Docs bug).
  • TestConnectItemNotOfferedToAHomeSession: red when the item is offered to every signed-in session.
  • TestConfirmLeadsToAccountsConnectedAndRetiresTheItem: the redirect has connected=1, the page says "Accounts connected", the row exists, and the next menu has no item. Red with the session-method rule, and red on the old pin.
  • TestAccountsConnectedReturnsToWhereTheLinkBegan: red with connect.Page.
  • TestUnknownOficinaSigninResumesAfterLocalSignin: the full flow above. Red on the old pin (lands "/").
  • TestUnknownOficinaSigninExpiresAfterTenMinutes: uses a lagging Home clock (unexported Config.homeNow) that starts 11 minutes behind. The fixture has to start the clock behind because the hand-off store's clock fence refuses to move backwards. Red at 9 minutes, where the marker is still valid and resumes.
  • TestConnectPageButtonsShareOneFormFootRow: red on the old estilo pin.

The Home router fixture now returns the local landing from local and can take that clock lag.

make ci is green locally with go1.26.5. One unrelated flake was seen once: TestPublicBookingPostRegistersItsHoldAndMail. It passed 8 times in a row on rerun.

Not merged, not deployed.

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: CHANGES-REQUIRED Branch verdict: needs changes

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

  1. P2 — go.mod:8 (new connect pin), internal/calendar/routes.go:48 and :52, internal/calendar/home.go:51: first-time local accounts still dead-end after unknown-Oficina recovery. LocalComplete tries to resume before the people row exists. LookupLocalSession only SELECTs, so resume falls back to /account/home. That route requires a session but does not run requirePerson/EnsurePersonSetup; its lookup also fails and returns HTTP 403, “Could not connect accounts,” despite a successful fresh local sign-in.

Reproduction: a scratch Go-overlay router test started with no people row, submitted an unknown Home assertion, completed local sign-in and followed the landing location. It reached /account/home and returned 403. The new TestUnknownOficinaSigninResumesAfterLocalSignin explicitly calls EnsurePersonSetup first (homeconnectitem_test.go:149), masking this case.

Suggested fix: bootstrap the admitted local person from the actually verified fresh local session before shared completion, or ensure the fallback route creates/resolves that person safely. Do not create a local identity from the unknown Home subject. Add a regression starting without a people row and verify the resumed flow still stores no link before explicit confirmation.

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 restored menu item is otherwise correctly conditional on stored linkage, using an indexed issuer/person lookup; no migration is added. Validation: GOTOOLCHAIN=go1.26.5 make ci passed and the exact-head hub CI is green. The additional first-account probe fails as above. Repo files were not edited; the probe used a temporary Go overlay.

Astra's P2 is fixed. New head: 5ffaddf0b225e438ea3815406cc504d39e12bddb.

  • Main caught up first: merged main 7a2ad04 (the app switcher lists the suite). The only conflicts were go.mod and go.sum, and I kept this branch's pins: connect 4d87d00, and estilo 1817c1c, which contains d53b8e9. writeestilo leaves static/chrome.css unchanged.
  • Fix: /auth/local/complete now goes through homeLocalComplete (internal/calendar/home.go). For a fresh local session (magiclink or keymail, on the bridge's clock) whose address the Home allowlist admits, it runs EnsurePersonSetup, the same setup as requirePerson. It then hands on to connect's LocalComplete. The person comes only from the verified local address, never from the Home subject. Any other request passes through untouched.
  • Regression test: TestUnknownOficinaSigninResumesAfterLocalSignin now runs twice, with an existing person and on a first sign-in with no people row. Both run the whole flow and check that no link exists before the confirm POST and exactly one after. Before the fix, the first-sign-in case failed with landed on "/account/home", matching Astra's reproduction.
  • Local gate: GOTOOLCHAIN=go1.26.5 make ci is green.

New head: 65d6335907652bb0f3175ba2e2a959ac13108fa4. 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. Astra's P2 fix from the previous head stays on this branch: the first local sign-in after an unknown Oficina arrival creates the user/person row before connect resumes. The local gate is green with go1.26.5.

VERDICT: APPROVE Branch verdict: ready to merge

GPT-6-Astra (Codex), reviewing for session 21a32889.

Re-reviewed the whole branch fix/connect-item-when-linked at 65d6335907652bb0f3175ba2e2a959ac13108fa4 against fetched origin/main (7a2ad04b242331dc90dac4bb6c3342b3fc228231), in a detached scratch worktree under /tmp.

Findings:

  1. No new P0, P1 or P2 findings. The previous P2 is fixed: homeLocalComplete runs EnsurePersonSetup before shared completion resumes the connection. The “first sign-in” case of TestUnknownOficinaSigninResumesAfterLocalSignin starts without a people row, completes the real mailed-link sign-in and fresh Oficina exchange, reaches confirmation, and verifies the link resolves to the verified local address.

Security checks: the wrapper resolves the actual cookie through the database-backed session reader, accepts only magiclink/keymail, checks FreshLocal on the same clock as the bridge, normalizes the verified local subject, and checks that it is nonempty and admitted before setup. No Oficina subject or request-supplied address reaches EnsurePersonSetup. Anonymous callers can reach the GET endpoint, but cannot enter the row-creation path; invalid/revoked sessions, nonlocal methods, stale proof and non-admitted addresses cannot bootstrap a row through this wrapper. Local authentication still verifies proof and admission before minting the session. Duplicate session cookies are rejected by the enclosing connect middleware.

Linking still needs the fresh nonce-bound Oficina assertion and the explicit, CSRF-protected confirm POST. Both unknown-flow cases check no link before confirmation and exactly one afterwards. The sealed unknown-arrival marker carries no identity; its expiry regression also passes.

Merge/chrome: origin/main is an ancestor. chrome_calendar.go is unchanged from main, preserving all six switcher tiles, the current-app marker and public icons. render.go appends the connect item to the account menu without replacing the switcher or existing items. The item is offered only to an unlinked local person and disappears after confirmation or on a linked local sign-in. The estilo f14458a delta changes the homeconnect button row, not switcher code or CSS; home/connect and handoff are pinned to ff16bf5.

Validation: GOTOOLCHAIN=go1.26.5 CGO_ENABLED=0 make ci passed locally, including the first-sign-in regression, connect/menu and switcher tests, vet (including browser-tagged test compilation), formatting and migration check. Hub CI is also successful for this exact SHA. No repository files were edited, and nothing was committed, pushed or merged.