Hub CI on 318df97: passed (amadan ci status oficina/docs -branch teammode-repoint exits 0). Ready for review.
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
- The dashboard feed under Unknown is now unavailable (503). At e58a22f it served a short feed of shares only. That was observed: the new
TestDashboardTeamFeedIsUnavailableUnderUnknownreturns 200 with the share list when the guard is removed. This is condition 3. - 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.
TestTeamListAsksPartialAfterListingis 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).testTeamRosternow usesteammode.Verify+Openinstead ofroster.Newoverteamstate.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_testdrops the classifiedteam_probe.gosite, as it requires.- Changed assertion:
TestTeamStreamHealthyPublicationClosesOriginalLeaseAndReconnectsasserted the pre-#97 behaviour (every publication ends every lease). It fails on main's own code with only the roster pin bumped. It is nowTestTeamStreamPublicationKeepsAListedLeaseAndClosesAChangedOne: 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.resolveAccessdropping the subject.requireMemberadmitting a guest.partialCatalognever 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()ignoringAccess.Remaining(): the per-delivery permission re-check closes it. - The emission guard ignoring the lease:
checkResponsere-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.
- Pin
home/connectat a main commit ≥ 67c12e3. DeletehomeBridge(home_exchange.go,home_routes.go,home_link_handlers.go,home_local_navigation.go,team_home.go)./auth/home/finishbecomes connect'sFinish. - Migrate the link table. Copy
docs_identity_links(issuer, subject, personid) into connect's `homeidentitylinksin one migration, keepingpeople.id. Re-point the disjointness triggers betweendocshomeidentitiesand 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-flightdocslink_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. - Hooks.
HomeOnly=principals.Resolvefor Home principals (ErrRefused →connect.ErrNoPerson).Unlinked=AdmitUnlinked, thenprincipals.EnsureHome.RequireMembershipstays as a second gate insideEnsureHome, or goes; to be decided in review. - Resolution.
identityResolver'slinkedPersonand the reverse subject lookup read connect's table throughbridge.Resolve.IssuerTablesbecomes{home_identity_links, docs_home_identities}. - Local reauthentication before linking maps onto connect's link flow. Docs' fresh-AuthTime rule and
requireTeamAccountAdmissionare kept. - 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. - 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.
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 inlistForLimitedand emit it throughcheckResponse. 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.
TestTeamEmptyListUnderUnknownIsPartialNotUnavailablecovers: - 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
- The native JSON list under Unknown with shares is a short 200 with no notice —
internal/docs/native.go:46-75(nativeList). It callsListForunmarked, 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: afterListFor/SearchForinnativeList, read the request's*requestAccessandif a.Partial() { 503 }, the dashboard's pattern (dashboard.go:59-64); add a case toTestTeamEmptyListUnderUnknownIsPartialNotUnavailable(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 —searchJSONalready setsDocs-Catalog-Partial: 1— so a"partial": truefield is the better contract once the Mac and iOS clients render it; until they do, 503.
Rulings
- Ledger identity: confirmed.
internal/docs/testdata/teamstate-e58a22f/migrations/0001_team.sqlis byte-identical toe58a22f:internal/docs/teamstate/migrations/0001_team.sql(git) and to teammode's owntestdata/docs_0001_team.sql(cmp).TestTeamStateKeepsTheAppliedLedgercompares (id, applied_at, checksum) before and after boot, assertsState("docs").SQL()byte for byte, and proves the check live by moving one trigger message. My M4 (base and team schema swapped inapp.go) is killed by exactly this test, so it is sensitive to the schema actually applied, not only to the SQL text. - Every prior guarantee survives. Config/Verify pinning:
validatedTeamConfig→teammode.Verify(..., "docs", origin)with Home's issuer and consumer; Home still required. Marker:teamState.BootSchemabeforemigrate.Apply, samesqlite_master-first read, any refusal stillerrTeamConfig. Census:IssuerTables: {docs_identity_links, docs_home_identities}, refused census writes no marker (TestTeamActivationCensusCoversBothIdentityTables). Access tri-state:requestAccessembeds*teammode.Access;state()nil-safe → Unknown;resolveAccessisRuntime.Access, "" → NotMember unasked, as before. Guard:ownerMutationruns authorize/mutate/authorize inside the sameTransaction; the standing is read inpermissionScopefrom the latched Access matched to the actor, so Guard'sStanding(ctx)argument (always Unknown here, since Docs does not carry the Access withteammode.WithAccess) is ignored harmlessly — the comment says so; fine. AdmitUnlinked: the gate insideprincipalstore.RequireMembership, reached throughEnsureHomefromcompleteTeamPrincipal; the droppedrequest.Issuercheck is unreachable becauseEnsureHomerefuses a foreign issuer first (principalstore/store.go:136). Partial:Access.Partial(). Probe:teammode.Probeatteammode.ProbePath, same struct, same headers, same probe subject. - The stream test rewrite is faithful. The "kept" step is a real publication:
roster/cache.go:519bumpsc.versionon 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;teamOpenActualStreamasserts 200 and the first event on reconnect. The deadline-never-moves contract stays underTestTeamStreamActualSessionWriterWaitCannotExtendOriginalLease. - The two bug fixes are real and tested. Dashboard:
Partial()asked afterlistForLimited,ErrUnavailableunder Unknown; the test flips the directory and steps 61 s. List page:TestTeamListAsksPartialAfterListingis 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). - A lease already lapsed when the stream opens now opens as Unknown, grants only: acceptable.
guard.check()re-resolves and runscheckPermissionwith 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. - The empty-list mechanism: approved.
acceptPartialmarks the request's own Access, honoured bylistForLimitedandcheckResponse; 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. - 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()ignoringAccess.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:checkResponsere-checks throughpermissionScope→state()per chunk. - Colophon: correct.
FirstPartyis the exclusion list for Oficina's own modules;home/teammodebelongs beside roster, handoff and dashboard. connect appears ingo.sumonly as a module-graph entry (teammode's tests import it; no non-test file does), so it is not linked and needs no entry. WithGOTOOLCHAIN=go1.26.10and rustup's cargo on PATH,internal/shippedpasses here. - Team-mode-off: unchanged in substance.
acceptPartialis a no-op (no Access in the context),partialCatalogreturns "" 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: …"), whichcmd/docsonly logs. docs.oficina.works is unaffected. - 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_linkshas aperson_bindingcolumn the plan does not mention (connectlinkstore/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), andResolverefuses 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 fromlookup), 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_waterintohome_link_clock, not a fresh 0; check what the clock guards before deciding, but a monotonic counter should not restart. - Triggers:
docs_home_identity_uniqueanddocs_local_identity_uniquemust be re-created againsthome_identity_links, anddocs_identity_links_keep_update/keep_deletedropped before the table — the plan says so; keep the rename in one migration so no boot sees a half state. Add theperson_bindingNOT NULL to the preflight. - Sessions: connect's
HomeMethodis "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.ResolvemappingErrRefused→connect.ErrNoPerson;Unlinked=AdmitUnlinkedthenEnsureHome. I would keepRequireMembershipinsideEnsureHomeas the second gate: it is what makes the allocation condition hold for every caller ofEnsureHome, not only connect's. - Carry the Access with
teammode.WithAccessin that branch, soGuard's argument is the real standing and the comment onownerMutationcan 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-gatelocally shows only the known macOS failures (cmd/docssocket tests,internal/shippedLICENSE);internal/docspasses in 67 s. Hub CI green on df304e7 as reported. dashboardProviderasksPartial()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) andTestEvidenceRoundTrip(empty and oversize refused). Evidence's oversize error is nowErrUnavailablewhere it wasErrRefused; nothing maps on it. - No stale references to
teamstate,rosterHeldorrosterProbeSubjectremain 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): afterListFor/SearchFor, the request's*requestAccessis askedPartial(), after listing and from the same Access, as the dashboard does. If true, the response iserrTeamUnavailable, which goes out through the existing error path as a 503 in team mode. That adds no newhttp.Errorsite, soTestEveryPlainTextErrorIsClassifiedis unchanged. The comment records your note that a"partial": truefield 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=Bobboth answer 503 without "Bob shared". - Mutation: with the
Partial()check replaced byfalse, the test fails for the right reason: a 200 whose body lists only "Bob shared". - Local gate: only the known macOS failures (
cmd/docssocket and process tests, andinternal/shipped's HomebrewLICENSE). Hub CI on25419d9: 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_waterover, rather than restarting it at 0; - one rename migration that re-creates the disjointness triggers;
person_bindingadded to the preflight;- verify the session cookie and session store against connect, rather than assuming they match;
- keep
RequireMembershipas 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.