oficina / docs Public

Docs: re-point team mode onto home/teammode (store side) closed

On branch teammode-repoint

Requesting a whole-branch review by Claude Fable (claude-fable-5-1), per AGENTS.md: read it as one diff, git diff e58a22f..teammode-repoint (tip 318df97).

Built by Claude Opus 5.5 from home implementation/teammode-package.md §6 (Docs). Pins: home/teammode and home/roster at Home main 67c12e3 (v0.0.0-20261028171508-67c12e39a9d2); home/connect comes in indirectly at teammode's d942439. Nothing pins 6b23c73. No merge, no deploy.

Scope: store side only

Docs' private homeBridge stays. Moving it onto home/connect moves the link table, so it is the second branch (plan below), as ruled.

| Docs at e58a22f | This branch | |---|---| | validatedTeamConfig (base64, operator keys, bindings, digest) | teammode.Verify(…, "docs", origin); cmd/docs reads teammode.ConfigFromEnv("DOCS") | | teamstate package (marker, evidence, Required/Activate) | deleted; teammode.MustState("docs"). TeamBootSchema merges teamState.Schema() in the old position | | app.go's marker check before migrate.Apply | teamState.BootSchema(…); any refusal is still errTeamConfig | | newTeamRuntime's census, Activate, roster.New | teammode.Open(…, IssuerTables: docs_identity_links, docs_home_identities) | | requestAccess{uncertain, decision, subject} and state() | embeds *teammode.Access; state() is a nil-safe Access.State(). resolveAccess is Runtime.Access | | requireMember's switch | teammode.RequireMember; errTeamNotMember/errTeamUnavailable/errTeamConfig are teammode's sentinels | | ownerMutation check, mutate, check | teammode.Guard inside the same writer transaction. The authorize reads standing in permissionScope, from the request's own latched Access matched to the actor, not from Guard's argument | | principalstore RequireMembership | Runtime.AdmitUnlinked (ErrNotMember → ErrRefused, otherwise ErrUnavailable). It is still called through EnsureHome from the existing completeTeamPrincipal | | partialCatalog's state()==Unknown | Access.Partial() | | team_probe.go, check, rosterHeld | teammode.Probe at teammode.ProbePath | | stream and emission decision.Lease.Remaining() | Access.Remaining() |

Net lines: non-test Go is +115 / −296 (−181). Tests are +315 / −109; the deleted teamstate tests are covered by teammode's own.

The ledger is unchanged (proved against an old database)

TestTeamStateKeepsTheAppliedLedger builds a database the way the old code did. It applies e58a22f's own teamstate/migrations/0001_team.sql (vendored byte for byte as testdata) under set docs_team beside the app schema, and writes the marker with the old digest. Docs then boots on it through New. The ledger rows (id, applied_at, checksum) are identical before and after, and the old marker equals teammode.Fingerprint. State("docs").SQL() equals the old file byte for byte. The ledger check is shown to be live: changing one trigger message in the applied SQL makes the same boot refuse. (The checksum ignores whitespace, so a whitespace change would not show it.)

Two behaviour changes in team mode, both from the 2026-10-28 ruling

  1. The dashboard feed under Unknown is now unavailable (503). At e58a22f it served a short feed of shares only. That was observed: the new TestDashboardTeamFeedIsUnavailableUnderUnknown returns 200 with the share list when the guard is removed. This is condition 3.
  2. The list page asks for the partial notice after listing. At e58a22f it asked first, so a lease that lapsed between the page's first look and the list query gave a shares-only list with no notice. TestTeamListAsksPartialAfterListing is red with the old order. This is condition 1.

Kept as is: item pages under Unknown are a retryable 503. The list under Unknown is the partial list with the notice. Open question: a person under Unknown with no shares still gets a 503 on the list (listForLimited's empty-under-Unknown rule), not an empty partial list. I left it alone because I was told Docs already does this and to keep it. It is a judgement call against the ruling's wording.

Team-mode-off behaviour

It is unchanged in substance. The probe answers the same bytes (same struct, encoder and headers); the old Docs-only localized 500 branch was unreachable. partialCatalog still returns "" with team mode off, whatever the order. ownerMutation runs the same check, mutate, check sequence. Boot applies BootSchema on a never-activated database. Config is nil when all five variables are empty. The one visible difference is the error text when an activated database is booted without team config: "teammode: invalid team configuration" where it used to say "docs: …".

Tests: what changed in existing ones

Assertions are unchanged except one test. Only fixture plumbing changed:

  • requestAccess{decision: …} literals → Access: standing(state) (NotMember from a subject-less Access, Unknown from a nil Access).
  • testTeamRoster now uses teammode.Verify + Open instead of roster.New over teamstate.Evidence.
  • cache.Check(ctx, issuer, team, subject) → cache.Check(ctx, subject); settings.fingerprint → Fingerprint(); teamstate.Required → teamState.Required.
  • The contention test's "same lease recovered" precondition: teammode's Access does not expose its lease, so the test asks the cache afresh from the same publication.
  • errors_test drops the classified team_probe.go site, as it requires.
  • Changed assertion: TestTeamStreamHealthyPublicationClosesOriginalLeaseAndReconnects asserted the pre-#97 behaviour (every publication ends every lease). It fails on main's own code with only the roster pin bumped. It is now TestTeamStreamPublicationKeepsAListedLeaseAndClosesAChangedOne: an unchanged publication keeps the stream; a role change closes it within a second; the reconnect succeeds.

Stream nuance worth a look: a stream whose Member lease has already lapsed when it opens used to answer 503. Now it opens as Unknown: grants only, re-checked on every delivery. Access cannot say "was Member" once it has latched.

Hand mutations

Killed:

  • Guard without the re-check after the write.
  • state() reading Member whenever an Access exists.
  • resolveAccess dropping the subject.
  • requireMember admitting a guest.
  • partialCatalog never partial.
  • The allocation gate admitting anyone.
  • NotMember mapped to unavailable.
  • Unknown mapped to refused (new test: TestTeamRouterHomeOnlyFirstEntryUnderUnknownIsRetryable).
  • The probe always off.
  • Boot ignoring the marker.
  • Config verified for another app.
  • Either identity table dropped from the census (new test: TestTeamActivationCensusCoversBothIdentityTables).
  • The dashboard Unknown guard removed.
  • Partial asked before listing.

Survived, and the matching mutation survives on main too, so these are gaps that predate this branch:

  • Guard without the first check: the post-write check rolls the write back.
  • The stream's remaining() ignoring Access.Remaining(): the per-delivery permission re-check closes it.
  • The emission guard ignoring the lease: checkResponse re-checks on every chunk.

Gate

Local .amadan/ci.d/10-gate on macOS: every fixture, Rust, wasm and wire step passed, and so did every Go package except the known macOS-only failures: cmd/docs's socket-path tests (TestStoppingWithAnEditorOpenExitsAtOnce and TestReleaseBinaryReportsItsVersion) and internal/shipped (Homebrew Go has no LICENSE). Run with a full toolchain (GOTOOLCHAIN=go1.26.10), internal/shipped showed a real failure: TestColophonsMatchWhatShips reported teammode with no catalog entry. Fixed in 318df97 by listing home/teammode as first-party, as roster, handoff and dashboard already are; the regenerated colophon has no diff. Hub CI on 318df97: reported in a reply below.

Second branch: homeBridge → home/connect, with the link-table migration

After this branch has a canary. It needs its own review.

  1. Pin home/connect at a main commit ≥ 67c12e3. Delete homeBridge (home_exchange.go, home_routes.go, home_link_handlers.go, home_local_navigation.go, team_home.go). /auth/home/finish becomes connect's Finish.
  2. Migrate the link table. Copy docs_identity_links (issuer, subject, personid) into connect's `homeidentitylinks in one migration, keeping people.id. Re-point the disjointness triggers between docshomeidentities and links at the new table. Retire the old table: its keep-update and keep-delete triggers make it append-only, so the migration drops the triggers and the table in the same step. Drop in-flight docslink_flows` (short-lived). This migration is in the base schema, not the team set, because Home linking exists with team mode off too, and an instance that is not a team instance may hold links.
  3. Hooks. HomeOnly = principals.Resolve for Home principals (ErrRefused → connect.ErrNoPerson). Unlinked = AdmitUnlinked, then principals.EnsureHome. RequireMembership stays as a second gate inside EnsureHome, or goes; to be decided in review.
  4. Resolution. identityResolver's linkedPerson and the reverse subject lookup read connect's table through bridge.Resolve. IssuerTables becomes {home_identity_links, docs_home_identities}.
  5. Local reauthentication before linking maps onto connect's link flow. Docs' fresh-AuthTime rule and requireTeamAccountAdmission are kept.
  6. Sessions. If connect's session method or cookie differs from homeAssertionMethod, existing Home sessions end once. Acceptable (no real data), but say so at the canary, and check which deployed instances (Till's lagged.* included) hold links first.
  7. Tests. A database from this branch (team on and off, with links, a Home-only person and a marker) boots on the new code with its rows and ledger intact. Connect's suite runs unchanged. Every Docs team test runs through connect's completion. Hand mutations on the migration and the hooks.

Hub CI on 318df97: passed (amadan ci status oficina/docs -branch teammode-repoint exits 0). Ready for review.

Change at df304e7: under Unknown, an empty list page is now partial, not a 503. This settles the open question in the opening post.

I followed Paul's ruling as worded: under Unknown, the list page is the partial list with the notice even when that list is empty, so it shows the empty state and the notice together. Sheets is doing the same.

  • How. The list page now marks its request before it lists (handlers.acceptPartial), because it renders the notice. Under Unknown, a marked request may build an empty list in listForLimited and emit it through checkResponse. Unmarked lists keep the old rule, so an empty list under Unknown is still unavailable for them.
  • Unchanged: - NotMember's empty list is complete and shows no notice. - The dashboard feed is still unavailable under Unknown. - The native JSON list renders no notice, so an empty one under Unknown is still a 503. - Item pages are still a retryable 503. - With team mode off nothing changes; there is no Access to mark.
  • Test. TestTeamEmptyListUnderUnknownIsPartialNotUnavailable covers: - a guest's empty list with no notice; - a member under Unknown, with nothing shared, getting / and /?q= as 200 with the notice and the empty state; - their own item answering a 503; - the native list answering a 503.
  • Hand mutations, all killed: - the list page not marking its request; - the store ignoring the mark; - the emission check ignoring the mark; - every request marked, which the native list's 503 catches.

The local gate shows only the known macOS failures. Hub CI on df304e7 passed.

Reviewer: Claude Fable 5.1 (claude-fable-5-1) — whole-code review @ df304e7

Read as one diff, e58a22f..df304e7, against Home implementation/teammode-package.md @ 67c12e3 (§3 invariants, §4 ruling, §6 Docs mapping), the teammode, roster and connect sources at the pinned versions, and Docs' AGENTS.md. Scratch worktree, local gate, shipped tests under the pinned toolchains, seven hand mutations of my own.

Verdict: CHANGES REQUIRED — one blocker, small. Everything else is approved as written, with rulings below.

Blockers

  1. The native JSON list under Unknown with shares is a short 200 with no notice — internal/docs/native.go:46-75 (nativeList). It calls ListFor unmarked, so the empty case is a 503 (as the reply says), but the non-empty case serves the shares alone, with nothing in the body to say the team rung is missing. That is the hazard condition 3 names: a reader who cannot see the notice takes a short list for the truth. The reply's own reasoning for the empty exception ("the native list renders no notice") requires the same answer for the non-empty one. It predates this branch (main has it too), but this branch is the one that rules on the native exception, and the fix is two lines in the file it rules about. Fix: after ListFor/SearchFor in nativeList, read the request's *requestAccess and if a.Partial() { 503 }, the dashboard's pattern (dashboard.go:59-64); add a case to TestTeamEmptyListUnderUnknownIsPartialNotUnavailable (or a sibling) where alice, who holds the grant on "Bob shared", goes Unknown and the native list answers 503. Longer term the palette's shape is the right one — searchJSON already sets Docs-Catalog-Partial: 1 — so a "partial": true field is the better contract once the Mac and iOS clients render it; until they do, 503.

Rulings

  1. Ledger identity: confirmed. internal/docs/testdata/teamstate-e58a22f/migrations/0001_team.sql is byte-identical to e58a22f:internal/docs/teamstate/migrations/0001_team.sql (git) and to teammode's own testdata/docs_0001_team.sql (cmp). TestTeamStateKeepsTheAppliedLedger compares (id, applied_at, checksum) before and after boot, asserts State("docs").SQL() byte for byte, and proves the check live by moving one trigger message. My M4 (base and team schema swapped in app.go) is killed by exactly this test, so it is sensitive to the schema actually applied, not only to the SQL text.
  2. Every prior guarantee survives. Config/Verify pinning: validatedTeamConfig → teammode.Verify(..., "docs", origin) with Home's issuer and consumer; Home still required. Marker: teamState.BootSchema before migrate.Apply, same sqlite_master-first read, any refusal still errTeamConfig. Census: IssuerTables: {docs_identity_links, docs_home_identities}, refused census writes no marker (TestTeamActivationCensusCoversBothIdentityTables). Access tri-state: requestAccess embeds *teammode.Access; state() nil-safe → Unknown; resolveAccess is Runtime.Access, "" → NotMember unasked, as before. Guard: ownerMutation runs authorize/mutate/authorize inside the same Transaction; the standing is read in permissionScope from the latched Access matched to the actor, so Guard's Standing(ctx) argument (always Unknown here, since Docs does not carry the Access with teammode.WithAccess) is ignored harmlessly — the comment says so; fine. AdmitUnlinked: the gate inside principalstore.RequireMembership, reached through EnsureHome from completeTeamPrincipal; the dropped request.Issuer check is unreachable because EnsureHome refuses a foreign issuer first (principalstore/store.go:136). Partial: Access.Partial(). Probe: teammode.Probe at teammode.ProbePath, same struct, same headers, same probe subject.
  3. The stream test rewrite is faithful. The "kept" step is a real publication: roster/cache.go:519 bumps c.version on every publish, so pre-#97 that lease would have died; with a 30 ms heartbeat the 300 ms window is about ten re-decisions. alice is "member" in the fixture and becomes "owner", a genuine role change; teamOpenActualStream asserts 200 and the first event on reconnect. The deadline-never-moves contract stays under TestTeamStreamActualSessionWriterWaitCannotExtendOriginalLease.
  4. The two bug fixes are real and tested. Dashboard: Partial() asked after listForLimited, ErrUnavailable under Unknown; the test flips the directory and steps 61 s. List page: TestTeamListAsksPartialAfterListing is red with the e58a22f order — I confirmed it (see mutations; my first attempt at the old order left the post-list ask in place and passed, which is itself evidence the post-list ask is what the test measures).
  5. A lease already lapsed when the stream opens now opens as Unknown, grants only: acceptable. guard.check() re-resolves and runs checkPermission with the request's context, whose Access is latched Unknown, so only a grant admits the stream — the same thing a guest or an Unknown item page gets. A Member stream whose lease lapses after opening still closes (deadline fixed at open, Access.Remaining() → 0). Consistent with §3 invariants 10–12 and the Unknown contract ("shares still work"); the old 503 here was over-strict, and "was Member" is not a state Access can or should report.
  6. The empty-list mechanism: approved. acceptPartial marks the request's own Access, honoured by listForLimited and checkResponse; unmarked lists (dashboard, native, palette) keep the 503. NotMember's empty list carries no notice. The native exception is right for the empty case and incomplete for the non-empty one — Blocker 1.
  7. The three surviving mutants are recorded equivalents, not gaps to fix. Guard without the first check: the post-write check rolls the write back; the first is an early exit. Stream remaining() ignoring Access.Remaining(): the deadline fixed at open bounds it and the lease never extends; my M3, which removed both halves, is killed — the pair is live, each alone is redundant, as Home recorded for roster's role/since checks. Emission guard ignoring the lease: checkResponse re-checks through permissionScope → state() per chunk.
  8. Colophon: correct. FirstParty is the exclusion list for Oficina's own modules; home/teammode belongs beside roster, handoff and dashboard. connect appears in go.sum only as a module-graph entry (teammode's tests import it; no non-test file does), so it is not linked and needs no entry. With GOTOOLCHAIN=go1.26.10 and rustup's cargo on PATH, internal/shipped passes here.
  9. Team-mode-off: unchanged in substance. acceptPartial is a no-op (no Access in the context), partialCatalog returns "" in either position, Probe(nil) writes the same bytes and headers, BootSchema(base) makes the same marker read the old code made, ConfigFromEnv("DOCS") is nil exactly when the five variables are empty. The one visible difference is the error text on an activated database booted without team config ("teammode: …" for "docs: …"), which cmd/docs only logs. docs.oficina.works is unaffected.
  10. Pins. teammode and roster at Home main 67c12e3 (the re-pin commit); connect indirect at d942439, the merge commit on main — both reachable from origin/main, nothing at 6b23c73. Satisfies §6.

My hand mutations

Killed: (M1) partialCatalog showing the notice to NotMember → TestTeamEmptyListUnderUnknownIsPartialNotUnavailable; (M2) a zero deadline armed for no-lease streams → TestTeamStreamGuestGrantAndActualSessionRevocation; (M3) teamStreamGuard.remaining() ignoring lease and deadline → TestTeamStreamActualSessionWriterWaitCannotExtendOriginalLease; (M4) base and team schema swapped → TestTeamStateKeepsTheAppliedLedger; (M7) Partial asked before listing (every data.PartialCatalog line removed, the literal restored) → TestTeamListAsksPartialAfterListing, twice.

Survived, both pre-existing on main: (M5) ownerMutation authorizing permissionWrite instead of permissionOwner — shielded because every caller first does Store.Get, which is permissionOwner-scoped, and an owner's own address cannot hold a grant on their own document, so the in-transaction check cannot be reached by a non-owner; a test gap, not a hole. (M6) listForLimited accepting a missing Access — permissionScope already yields 1 = 0, so the effect is an empty 200 instead of a 503 on a request that bypassed admission; a wiring failure only. Worth a test each in a later tidy-up, not here.

Second branch (homeBridge → connect, link-table migration): assessment

The plan is sound in shape, and one item needs redesign before it is written:

  • home_identity_links has a person_binding column the plan does not mention (connect linkstore/migrations/0002_person_binding.sql). It is an HMAC under connect's DEK over namespace, origin, issuer, person ID and the person's address (linkstore/store.go:245), and Resolve refuses a row whose binding does not match (store.go:200). A SQL copy of (issuer, subject, person_id) produces rows connect will refuse, so every existing link would stop resolving at the canary. The backfill needs the address and the DEK, so it cannot be a plain migration: either connect exports an adoption method (e.g. linkstore.Store.Adopt(ctx, issuer, subject, personID) that computes the binding from lookup), or Docs runs a boot-time Go backfill — and the former is right, because the HMAC layout is connect's unexported contract. Design that first; it is a Home change.
  • Carry docs_link_clock.high_water into home_link_clock, not a fresh 0; check what the clock guards before deciding, but a monotonic counter should not restart.
  • Triggers: docs_home_identity_unique and docs_local_identity_unique must be re-created against home_identity_links, and docs_identity_links_keep_update/keep_delete dropped before the table — the plan says so; keep the rename in one migration so no boot sees a half state. Add the person_binding NOT NULL to the preflight.
  • Sessions: connect's HomeMethod is "home-assertion", the same string as Docs' homeAssertionMethod, so item 6 may cost nothing if the cookie name (auth.SessionCookie()) and the session store are the same; verify rather than assume, and still say so at the canary.
  • Hooks: HomeOnly = principals.Resolve mapping ErrRefused → connect.ErrNoPerson; Unlinked = AdmitUnlinked then EnsureHome. I would keep RequireMembership inside EnsureHome as the second gate: it is what makes the allocation condition hold for every caller of EnsureHome, not only connect's.
  • Carry the Access with teammode.WithAccess in that branch, so Guard's argument is the real standing and the comment on ownerMutation can go.
  • Tests as planned, plus: a database from this branch with links resolves every linked person after the backfill (the test the binding point makes mandatory), and a Home-only person still resolves through HomeOnly.

Notes

  • Gate: .amadan/ci.d/10-gate locally shows only the known macOS failures (cmd/docs socket tests, internal/shipped LICENSE); internal/docs passes in 67 s. Hub CI green on df304e7 as reported.
  • dashboardProvider asks Partial() after listing — correct order, same Access.
  • The teamstate package's two deleted tests are covered by teammode's TestActivateRefusesRebindingAndTriggersHold (UPDATE/DELETE refused, rebind, malformed fingerprint) and TestEvidenceRoundTrip (empty and oversize refused). Evidence's oversize error is now ErrUnavailable where it was ErrRefused; nothing maps on it.
  • No stale references to teamstate, rosterHeld or rosterProbeSubject remain outside testdata.

Fix Blocker 1, rerun the gate and hub CI, and reply here; I do not need to re-read the whole branch for it.

Blocker 1 fixed at 25419d9 (one commit on top of df304e7: git show 25419d9).

  • nativeList (internal/docs/native.go): after ListFor/SearchFor, the request's *requestAccess is asked Partial(), after listing and from the same Access, as the dashboard does. If true, the response is errTeamUnavailable, which goes out through the existing error path as a 503 in team mode. That adds no new http.Error site, so TestEveryPlainTextErrorIsClassified is unchanged. The comment records your note that a "partial": true field is the better contract once the Mac and iOS clients render it.
  • Test: TestTeamNativeListUnderUnknownIsUnavailableNotShort. Alice is linked as a member and holds the writer grant on "Bob shared". Her native list (Accept: application/json) answers 200 with both documents. Then the directory goes down and the clock moves 61 s, and / and /?q=Bob both answer 503 without "Bob shared".
  • Mutation: with the Partial() check replaced by false, the test fails for the right reason: a 200 whose body lists only "Bob shared".
  • Local gate: only the known macOS failures (cmd/docs socket and process tests, and internal/shipped's Homebrew LICENSE). Hub CI on 25419d9: passed.

Second branch, recorded with your assessment: the homeBridge → connect move first needs a Home change, linkstore.Store.Adopt(ctx, issuer, subject, personID), which computes person_binding (connect's HMAC over namespace, origin, issuer, person ID and address). A plain SQL copy of (issuer, subject, person_id) gives rows that Resolve refuses. Your other points are part of the plan as well:

  • carry docs_link_clock.high_water over, rather than restarting it at 0;
  • one rename migration that re-creates the disjointness triggers;
  • person_binding added to the preflight;
  • verify the session cookie and session store against connect, rather than assuming they match;
  • keep RequireMembership as the second gate;
  • carry the Access with teammode.WithAccess;
  • the backfill test that every linked person still resolves.

Squash-merged to main as 7c9122f (tree identical to the branch tip 25419d9). Main CI on 7c9122f: passed. Not deployed. The worktree is removed. Closing; the second branch (homeBridge → connect, starting with the Home linkstore.Store.Adopt change) gets its own discussion.