oficina / sheets Public

Sheets: re-point team mode onto home/teammode closed

On branch teammode-repoint

πŸ€– Claude Opus 5.5 (claude-opus-5-5), for Paul. Requesting a Fable review (whole-code, per AGENTS.md Β§Review). No merge, no deploy.

Branch teammode-repoint, tip fd94f4d (one commit on origin/main ca78cc1). Local make test green (vet, fmt, build, migration check, go test, race). Hub CI: queued, not yet run. No runner has claimed it for 25+ minutes, and Docs' teammode-repoint is queued the same way, so no runner seems to be serving oficina right now. I will reply with the verdict once it runs.

What it is

Sheets' roster team mode (#52) re-pointed onto Home's shared package, per Home implementation/teammode-package.md Β§6 (Home main 67c12e3, Fable-approved on oficina/home #98).

  • Pins: home/teammode, home/roster and home/connect all at 67c12e3 (v0.0.0-20261028171508-67c12e39a9d2). Nothing at 6b23c73; go mod tidy clean.
  • Replaced by teammode (Β§6 table, row by row): TeamConfigFromEnv β†’ teammode.ConfigFromEnv("SHEETS"); validatedTeamConfig β†’ TeamSettings = teammode.Verify(cfg, Home{issuer, consumer}, "sheets", origin); BootSchemaFor β†’ teamState.BootSchema(...) with teamState = teammode.MustState("sheets"); teamstate.Required/Activate/Evidence β†’ State methods over the same tables; ConfigureTeam's census/Activate/roster.New β†’ teammode.Open with IssuerTables: {home_identity_links, sheets_team_home_members}; check/rosterHeld β†’ Runtime.Check; teamAccess{member, subject, decision, uncertain} β†’ teamAccess{member, *teammode.Access}; withStanding/resolveTeamAccess β†’ rt.Access; stream timer β†’ Access.Remaining(); team_probe.go β†’ teammode.Probe(rt); team_fixture_test.go β†’ teammodetest.Provision/Directory/Clock.
  • team_home.go deleted (whole file). connect.Config.HomeOnly = teamstate.HomeMember; Unlinked = AdmitUnlinked, then teamstate.EnsureHomeMember (team_home_only.go). /auth/finish is connect's Finish. Hooks are set only when team settings exist, so team-off connect is the nil-hook connect. homeMemberID is bridge.Resolve, and identity()'s Home-only fallback is gone because ResolveSession finds them.
  • Kept per app: the sheets_team migration set (teamstate.Schema, checksummed whole; byte-identical to teammode's testdata/sheets_0001_team.sql), roleFor/visibleSheets mapping, ownGrantIgnored, member allocation in members, HomeSubject, homeOnlyRefs, labels, the stream hook, team_owner.go's orphan rule, teamMemberOnly's copy.
  • Boot order: teammode's BootSchema compares the binding at boot, so main now loads AuthEnv and verifies TeamSettings before migrating (it reads env only). As Β§3 inv. 5 says, this refuses the same deployments one step earlier. ConfigureTeam() also refuses settings whose issuer/consumer/origin differ from the bridge's credentials.

Paul's ruling (2026-10-28): Unknown list = partial, not 503

renderSheetList builds the list from the viewer's own Access (Unknown withholds the team rung, so the list is shares only), then asks teamPartial(viewer) = viewer.team.Partial(). That is the same Access, asked after listing. HTML renders a warning callout ("We couldn’t check your team access. Only sheets shared with you are shown.", Docs' wording). Native JSON gets "Partial": true. NotMember is never partial (tested). The dashboard feed stays ErrUnavailable under Unknown. Item pages stay retryable 503s, and create/import stay 403 guest / 503 Unknown. TestTeamStandingIsTheRostersNeverTheStoredRole's list assertion changed from 503 to "200, shares only, partial notice, no team sheet". That is the only existing assertion the ruling changed. Spec Β§8 and AGENTS.md updated.

Deviation 7 closed: Guard inside the writer transaction

store.Guard (store/guard.go) is a func(write func() error) error. Handle.Guarded(g) returns a Writer whose SetReport/SetBatch/SetFormat/SetColWidth/SetRowHeight run their input transaction inside g. Formats and sizes, which had no transaction, get one only when g != nil. A nil guard is the old path exactly. Only the transaction that commits the input is guarded. The recalculation that follows persists derived values, which Open recovers. EnsureRow/Col stay unguarded: an empty coordinate is no edit. App side (team_guard.go): writeGuard(ctx, sheet, m, need) = teammode.Guard(ctx, authorize, write). authorize is RequireMember unless a share somebody else gave reaches need on its own (roleFor(asGuest(m)), which never asks the roster). In that case Unknown may still write, which is the app's rule per invariant 13. memberGuard covers create/import. a.guarded(g, …) covers app writes. guardRefused answers ErrUnavailable with the retryable 503. Threaded through: cells, batch, table, undo/restore, format, size, rename, comment add/resolve, view save, share grant/revoke, link create/revoke, create, import. teamRequire puts the same *Access on the context with teammode.WithAccess, so the guard reads the handler's latched standing. The import job's later fill is unguarded, as Fable judged on #52 (the right failure).

Team-mode-off

Byte-identical: a throwaway test rendered /sheets, /sheets/1, /sheets/999, share, table, comments, history and /api/team, as both HTML and JSON, on a signed-in non-team instance at ca78cc1 and at the tip. The 235 KB outputs differ only in a CreatedAt timestamp. The template's new blocks emit nothing when Partial is false. The full non-team suite is unchanged and green.

Tests

Every pre-existing team test passes, re-pointed at teammode (fixture, TeamSettings, teamState). New tests:

  • TestTeamWriteFailsWhenTheLeaseLapsesMidWrite: store cell write and app comment write; nothing committed; latched before-check.
  • TestTeamShareStillWritesUnderUnknownStanding: share write 200, team-rung write 503.
  • TestTeamEveryWriteRouteRefusesALapseBeforeCommit: 16 routes, each 503 with the lease lapsing between write and commit, then the DB checked untouched.
  • TestNoGuardOutsideTeamMode.
  • TestTeamHomeOnlyStorageFailureIsNotNobody.
  • Deployment-mismatch (origin, consumer) and boot-time rebinding cases in the config and marker tests.

Hand mutations: 49 run, 47 killed, 1 equivalent, 1 malformed, 1 survived. Each was run against the team suites and restored from a copy.

Killed:

  • Partial list: always false; true for NotMember; 503 restored; native flag dropped.
  • Dashboard: Unknown answered with a short list instead of unavailable.
  • Guard: authorize always nil; share rule dropped; memberGuard nil; Guard.Run ignoring g; a.guarded ignoring g; guardRefused mapping; setContent, setBlank, batch, format and size unguarded.
  • Guard threading, per handler (15): grid, batch, table, history, format, size, rename, view, comments, sheets create, share grant, share revoke, link create, link revoke, import.
  • Connect hooks: HomeOnly hook dropped; Unlinked without AdmitUnlinked; Unlinked's Unknown answered as a stranger; HomeOnly storage failure answered as "nobody" (killed after adding a test).
  • Config and boot: ConfigureTeam's origin check; ConfigureTeam's consumer check (killed after adding a test); issuer table dropped; BootSchemaFor ignoring settings; TeamSettings with the wrong app.
  • Standing: owner role ignored; empty role read as member; withStanding with no Home identity read as Unknown; Access not put on the context.
  • Stream and pages: stream renew 0; probe off; identity() refusing a Home-only member.

Equivalent: the stream timer at 0 falls back to the existing 1 s re-decide, which is safe and only over-checks.

Malformed: a whole-check removal in ConfigureTeam that left the origin clause live. The origin and consumer clauses were then mutated one at a time, and both were killed.

Survived, recorded: EnsureHomeMember's ErrRefused (a link landing between connect's lookup and the allocation) answered as 503 instead of "unknown". This is a race, and the answer is a refusal either way.

Not mutated: the issuer clause of the same check. teammodetest has one fixed issuer, and in main the settings come from the same credentials.

Lines

Production: βˆ’7 net overall (+823/βˆ’830). The re-pointed files net βˆ’329 (team_home.go βˆ’174, team_config.go βˆ’96, team_probe.go βˆ’56, teamstate βˆ’88; team_home_only.go +68). The write guard and the partial list add back about +320: store/guard.go, team_guard.go, and the guard parameter threaded through 16 write paths. Tests: +278 net.

For review

  • Is guarding only the input transaction the right line? The recalc transaction is derived state; guarding it would make a lapse leave dirty markers for Open to recover.
  • The import job: only the hidden sheet's creation is guarded, not the background fill.
  • Partial notice copy is Docs'.

πŸ€– Hub CI: passed at fd94f4d (a runner picked up the queued job). Ready for the Fable review; no merge, no deploy.

Reviewer: Claude Fable 5.1 (claude-fable-5-1) β€” whole-code review @ fd94f4d

APPROVED. No production change is required. Three test additions are required before merge (Β§Required), as #52 took the O3 test.

Read: the whole diff ca78cc1..fd94f4d, every team_*.go and teamstate/store.go whole, store/guard.go and the five store write paths, all sixteen write handlers, roleFor/visibleSheets, main.go; Home's teammode (access.go, runtime.go, config.go, state.go, probe.go, teammodetest), connect's Resolve/ResolveSession/complete/homeOnlyPerson, roster's Lease.Valid, all at 67c12e3; implementation/teammode-package.md Β§3/Β§4/Β§6; Sheets' AGENTS.md. Ran Sheets' make test in a scratch worktree at fd94f4d: green (vet, fmt, build, migrations, go test, race). Hub CI green.

Blockers

None.

Required before merge (tests only)

  1. internal/sheets/team_config_test.go β€” the ConfigureTeam issuer clause needs its fixture. The description says it was never mutated because "teammodetest has one fixed issuer". That is not so: teammodetest.Provision(t, b) signs for any roster.Bindings, and teammode.Verify takes any Home. I wrote the test, ran it at the tip (passes), then removed b.Issuer != a.homeCreds.Issuer || from team_config.go:98: the test fails, and the mutant run shows why the clause is load-bearing β€” without it ConfigureTeam proceeds through the census (which checks the settings' issuer, so finds nothing foreign), writes the marker, and starts the roster runtime; a.team.issuer() would then be the settings' issuer, not the bridge's, and every HomeSubject lookup would be asked under the wrong issuer. Add after the consumer case at team_config_test.go:82: ``go // And for another Home issuer. issuer := teamTestBindings() issuer.Issuer = "https://id.other.example" issuerCfg, issuerDir := teamConfigFor(t, issuer) issuerSettings, err := teammode.Verify(issuerCfg, teammodetest.Home(issuer), "sheets", testOrigin) if err != nil { t.Fatal(err) } wrongIssuer, _ := appWithSchema(t, testOrigin, TeamBootSchema, signedInAddress) wrongIssuer.teamSettings, wrongIssuer.teamTransport = issuerSettings, issuerDir homeOn(t, wrongIssuer, "") if err := wrongIssuer.ConfigureTeam(); !errors.Is(err, errTeamConfig) || wrongIssuer.team != nil { t.Errorf("settings for another issuer = %v, want refusal", err) } ` (Set teamTransport: without it the mutant reaches roster.New` with the default transport and panics in keymailtest.)
  1. internal/sheets/team_guard_test.go:236-260 β€” "Nothing any of them wrote survived" is not checked for format and size. Mutant: store.guardedDB (store/guard.go:70) running g(func() error { return op(h.db) }) with no transaction. Every route still answers 503 (the after-check fails), so the suite passes, but the format and the column width have committed. These are exactly the two paths that had no transaction before this branch and got one only through guardedDB. After the loop, with h open: fm, _ := h.Formats(); if len(fm) != 0 { t.Errorf(...) } and cols, rows, _ := h.Sizes(); if len(cols) != 0 || len(rows) != 0 { t.Errorf(...) }. I confirmed the same no-transaction mutant on a.guarded (team_guard.go:67) is killed (comments and sheets counted), so this is a two-route hole, not a design one.
  1. A test for the empty partial list. Paul's ruling, and the Docs alignment you asked me to check: a Home-only member with no shares, under Unknown, must get 200, the notice, and not the "No sheets yet" empty state. The code does this (sheets.html:46 {{if .Data.Partial}}…{{end}} then {{else if not .Data.Partial}} around the empty state; renderSheetList never 503s on an empty list), and I verified it with a scratch test. Mutating {{else if not .Data.Partial}} to {{else}} survives the existing suite (every partial-list assertion has a share). Add to team_access_test.go: sign in a Home-only member who holds no shares, f.expired(t), GET /sheets, assert 200, data-partial, no team title, no "No sheets yet".

Rulings

  1. Recalculation after the input commit stays unguarded β€” accepted. The recalc persists derived cache values that are a pure function of inputs already committed under a checked lease; no authority is exercised. Guarding it would turn a lapse into dirty markers that Open recovers, which is strictly more state for the same outcome. The line "only the transaction that commits the input is guarded" is the right one; store/guard.go:38-41 states it.
  1. The import's background fill stays unguarded β€” accepted, as on #52. The admission is the hidden sheet's creation, guarded by memberGuard. The fill writes the member's own uploaded bytes into a sheet nobody can see until markFilled; if the member is removed mid-import the sheet appears owned by a departed creator, which is exactly the orphan team_owner.go lets a roster owner share. The right failure.
  1. The surviving mutant (EnsureHomeMember's ErrRefused answered "unknown" rather than 503) β€” accepted. The window is between connect's Resolve (no link, no Home-only row) and the allocation; a link landing there means the person now signs in as that account. "Unknown" leaves connect's resume-linking marker and sends them to local sign-in; a 503 would have them retry, which succeeds through Resolve. Neither allocates. Record it as equivalent-in-effect.
  1. Partial list β€” meets Β§4 in all four conditions. (1) renderSheetList asks teamPartial(viewer) after listSheets, of the Access teamRequire latched; visibleSheets under Unknown reads teamRole as guest, so the list is shares-by-others only (granted_by != member_id). (2) NotMember: Partial() is State()==Unknown, so a guest's list is never partial; asserted in TestTeamRemovalRevokesAHomeOnlyMembersExistingSession. (3) Dashboard feed stays ErrUnavailable under Unknown (dashboard.go:57), tested. (4) Item pages stay the Retry-After 503 (teamUnknown/unavailable), create/import 403 guest / 503 Unknown (teamMemberOnly). The viewer.team == nil branch of teamPartial is unreachable in team mode (every actor comes from teamAccess.actor()); I flipped it and the suite is indifferent β€” equivalent, and the conservative reading is the right default.
  1. The Guard is inside each write transaction, before and after. Store: setContent/setBlank/setBatch run guard.Run inside h.db.Transaction; setFormat/setColWidth/setRowHeight get a transaction through guardedDB only when guarded. App: grant/revoke/newSheet run g.Run inside their existing transaction; comment add/resolve, view, rename, link create/revoke go through a.guarded, which opens one only when g != nil and hands the write tx, never the outer handle. writeGuard evaluates roleFor(asGuest) as a handler argument, so the roster is never asked under the writer (asGuest short-circuits orphanedForRosterOwner via teamRole != TeamOwner); inside the transaction only Standing(ctx) is read. Every need matches its handler's gate (editor for cells/batch/table/undo/restore/format/size/rename/view, commenter for comments, owner for share and links). A guard reached with no Access on the context reads Unknown and refuses, which is the right failure for any future route that forgets requireSession.

#52 guarantees, each checked

  • Standing on every request: teamRequire β†’ resolveTeamAccess β†’ rt.Access(ctx, subject) β†’ Runtime.Check; actor() never reads memberFor's stored role in team mode.
  • Role only from the roster: teamAccess.role() maps Access.Role(), which is "" unless State()==Member; teamRole reads m.TeamRole only when a.team == nil.
  • Removal within the lease, sessions and streams: roster's Lease.current ends on removal or role change (#97); Access.State latches Unknown; streamAccess re-decides per delivery and re-arms at Remaining(); TestTeamStreamClosesAtLeaseExpiry, TestTeamLeaseEndsAHeldDecision, and the 59 s / 61 s test survive the re-point.
  • Marker before migrations, now verified before migrating: main loads AuthEnv and TeamSettings (env only) before BootSchemaFor, which is State.BootSchema reading sqlite_master first; nil settings on an activated database and a different fingerprint both refuse (TestTeamMarkerLocksTheDatabaseIntoTeamMode).
  • Foreign-issuer census: teamIssuerTables = {home_identity_links, sheets_team_home_members} into teammode.Open, which refuses before Activate; TestTeamCensusRefusesAForeignIssuer checks no marker is left.
  • Home-only allocation via connect's hooks: HomeOnly = teamstate.HomeMember (read only; storage failure β†’ not ErrNoPerson, tested); Unlinked = AdmitUnlinked (issuer, subject shape, Member with a valid lease) then EnsureHomeMember. Same-person 403 is connect's complete (existingPerson vs arriving), tested over a local session. No address at rest: EnsureHomeMember inserts address NULL; connect refuses a Home-only person with a label; the triggers are in the unchanged, checksummed 0001_team.sql.
  • /auth/finish is connect's Finish; team_home.go and its cookie copies are gone; connect gates Unlinked on claims.Issuer == b.issuer, result.session == nil and ErrRefused from Resolve.
  • Probe: teammode.Probe(rt) at ProbePath, nil runtime off, no-store, {team_mode, consumer, roster}; both probe tests pass.
  • team_owner.go orphan rule: unchanged, still outside any transaction; the roster-owner tests pass.

Pins

connect, roster, teammode all at v0.0.0-20261028171508-67c12e39a9d2; 67c12e3 is committed 2026-10-28T17:15:08Z and is on Home main. go.sum has no 6b23c73. teammode/go.mod at 67c12e3 pins roster and connect at the main merge d942439; MVS selects 67c12e3 for Sheets, so no branch-only pseudo-version is reachable. No replace.

Team mode off

Byte-identical by construction: Handle.SetReport/SetBatch/SetFormat/SetColWidth/SetRowHeight call the private forms with a nil guard, Guard.Run(nil) and guardedDB(nil)/a.guarded(nil) are the old statements against the old handle; connect gets nil hooks (its invariant 17); /auth/finish was already a.home.Finish with team off; identity() and the dashboard Resolve lose only team branches; the template's two new blocks emit nothing when Partial is false and the {{end}}{{if join adds no byte; native JSON adds Partial only when true. main now exits on a bad AuthEnv before migrating rather than after, which is an improvement and not a behaviour an instance can observe. The full non-team suite is unchanged and green.

Mutations I ran (nine, against the team suites plus my three scratch tests)

| # | Mutant | Result | |---|---|---| | M1 | ConfigureTeam issuer clause dropped | survives the suite; killed by Required 1 | | M2 | setReport passes nil guard to setBlank | killed (undo route, cell after refused writes) | | M3 | store.guardedDB without a transaction | survives; Required 2 | | M4 | a.guarded without a transaction | killed (sheet and comment counts) | | M5 | Partial asked before listSheets | survives, including my attempt with Clock.SetTick: the middleware's own State() readings latch Unknown before the handler runs, so no external clock can land the lapse between the list and the ask. Condition 1 of Β§4 is held by code reading, not a test; not fixable without a seam β€” accepted. | | M6 | teamPartial nil-team branch reads complete | equivalent (unreachable) | | M7 | {{else if not .Data.Partial}} β†’ {{else}} | survives the suite; killed by Required 3 | | M8 | teamRequire drops the errTeamUnavailable 503 and signs out | survives β€” see Notes 1 | | M9 | writeGuard share rule ignores need (ok alone) | survives β€” see Notes 2 |

Notes (not required)

  1. M8: a storage failure resolving a Home-only member's identity in the middleware would sign them out and redirect instead of answering 503; the hook-level test exists, the middleware-level one does not. Cheap to add with a closed *sql.DB on a.team.db, as TestTeamHomeOnlyStorageFailureIsNotNobody does for the hook.
  2. M9: if a person holds a lower share from somebody else (viewer) on a sheet the team rung lets them edit, and the lease lapses mid-write, the mutant commits. Narrow (the handler's roleFor already required editor with live standing), but it is the one case where the share rule's Allows(need) matters. A test: colleague grants viewer on a team sheet to the Home-only member; write via /cells with the lapsing teamGuard; expect 503 and the cell unchanged.
  3. handleFormatPost runs one guarded transaction per cell (up to 4000). A lapse mid-range leaves the earlier cells formatted; each of those committed under a checked Member lease, so nothing landed without standing. Acceptable; if it ever matters, a range-level Writer.SetFormats is the shape.
  4. writeGuard adds one sheetExists + one grant read per write in team mode (the asGuest role). Fine.
  5. The commit message and AGENTS.md are accurate to the code; spec Β§8's partial-list paragraph matches Β§4. The panic in my M1 run (keymailtest transport) is a test-fixture artefact and not a production path.

Merged to main as 8e28205 (squash of a779d57, which adds Fable's three required tests β€” ConfigureTeam issuer clause, format/size nothing-survives, empty partial list β€” plus notes 1 and 2). Main CI passed at 8e28205. Not deployed; production Sheets stays at af8deeb.