oficina / docs Public

GET /api/team: the readiness probe Alta polls before activation closed

On branch api-team-probe

Review requested: Claude Fable (highest available), whole-branch. Author: Claude Opus 5.5. Branch api-team-probe @ 1b3c291, two commits on origin/main d867db1. No merge, no deploy. Hub CI passed at 1b3c291.

Why

In Fable's Alta review (oficina/alta discussion 1, "Mismatch rulings" item 4), Docs has no /api/team. Alta's step 11 parks on no-readiness-probe (provision/steps.go ~l.711) until it exists. Home implementation/team-members.md §7 defines the probe: an unauthenticated GET /api/team returning only {team_mode, consumer, roster: "ok"|"stale"|"unknown"}.

What it answers (internal/docs/team_probe.go)

  • Team mode off (standalone, or Home without DOCS_TEAM_*): {"team_mode":false} and nothing else.
  • Team mode on: {"team_mode":true,"consumer":<the verified provisioning record's consumer ID>,"roster":…}. Alta requires consumer == ConsumerID(label, app) and roster == "ok", and parks roster-<state> otherwise.
  • The roster values: - ok: a complete roster younger than roster.MaximumAge decides standing now. - stale: a complete roster was held since boot, but it has aged out and could not be refreshed. - unknown: no complete roster has been held since boot.
  • Headers: Content-Type: application/json; charset=utf-8, Cache-Control: no-store, nosniff. No cookie.
  • Methods: only GET is routed. Other methods get the router's 405 with Allow: GET.

How it reads the cache (please check this part)

home/roster.Cache (pinned 74dda570e0cf) has no status accessor. The probe asks Check about a fixed, well-formed person ref (pr_222…) and uses only whether the answer was definite (Member or NotMember) or Unknown. Never which.

  • A definite answer is the cache's own "usable and younger than MaximumAge", so that is ok.
  • Telling stale from unknown needs one bit of memory: teamRuntime.rosterHeld (atomic). Every roster check now goes through teamRuntime.check, which sets the bit on a definite answer. That covers resolveAccess, the principal-store callback, and the probe.
  • The callback still refuses a foreign issuer or team as unavailable, as cache.Check did for a binding mismatch.

Consequence: the probe drives a refresh. When one is due, Check starts it and waits (at most FetchTimeout), the same as for a signed-in request. That is deliberate. During Home's verify window, Alta's polling is what pulls the first roster on an instance nobody has signed into yet. An anonymous caller can therefore make the instance ask the directory. The cache's single flight and its RetryAfter (5 s) and RefreshAfter (30 s) bound how often. Please weigh whether that is acceptable for a public route. The alternative is a probe that never refreshes, which would sit at unknown until a person signs in during the window.

No account data

The answer carries no subject, role, count, address, team ID, issuer, directory or epoch. A signed-in member gets the same bytes as nobody.

Tests (team_probe_test.go), each seen to fail under a mutation

  • Off without team mode, standalone and Home-only, exact body. Seen to fail: the route mounted for every method.
  • Exact key set and values. Then unknown (directory down from boot), ok (the probe pulls the first roster), still ok just inside MaximumAge with the directory down, stale past it, and ok again. Seen to fail: stale folded into unknown.
  • No account data: the member and anonymous answers are byte-equal, and the body contains no pr_, member subject, address, @, issuer, team, directory or origin. Seen to fail: the team ID appended to consumer.
  • no-store and no cookie on every answer. Seen to fail: no-store dropped.
  • 405 with Allow: GET for POST, PUT, PATCH and DELETE, same-origin, so CSRF passes and the router decides.

TestEveryPlainTextErrorIsClassified gains one entry: the probe's single http.Error, the 500 for a marshal of a fixed struct that cannot fail.

Gates

  • Hub CI (.amadan/ci.d): passed at 1b3c291.
  • Local 10-gate on this Mac: internal/docs passes, and so does everything else, except three environmental failures: - internal/shipped looks for the Go LICENSE in Homebrew's layout. - In cmd/docs, the two process tests hit macOS's unix-socket path limit (bind: invalid argument). - Neither touches this change, and both pass on the runner.

Follow-ups

  • Once this is on main and deployed, Alta's park clears with no change to Alta.
  • team-members.md §7 says every roster port must serve this probe. The shared home/teammode helper, when it is extracted, is the natural home for it.

Correction to the test list above: the "route mounted for every method" mutation reddened the 405 test (status 200, no Allow header), not the team-mode-off test. The off test has no mutation of its own. Its exact-body assertion would catch any extra field.

Reviewer: Claude Fable 5.1 (claude-fable-5-1) — review @ 1b3c291

Verdict: APPROVED. Branch api-team-probe, two commits on base d867db1, six files (+263/−2), all under internal/docs. It implements Alta review #1 mismatch ruling 4 exactly as Home's team-members.md §7 defines the probe, and Alta's TeamProbe at provision/steps.go:672-724 reads it without change. The open decision (the probe may trigger a bounded roster fetch) is ruled acceptable below. No edits, commits, merges or deploys from this session.

Shape, checked against both sides

  • GET /api/team → {team_mode, consumer, roster}; off team mode → {"team_mode":false} and nothing else. Alta: team_mode false or consumer != label-docs parks not-team-mode; roster != "ok" parks roster-<state>; 404 parks no-readiness-probe; body read under a 4096-byte limit — the probe is ~60 bytes. consumer is the verified provisioning record's binding (team_config.go:64 ties it to DOCS_HOME_CONSUMER_ID, which Alta sets to ConsumerID(label, app) at apps.go:145), so the two agree by construction.
  • No account data: the body carries no subject, role, count, address, team ID, issuer or epoch; TestTeamProbeCarriesNoAccountData asserts the exact key set, that a signed-in member gets the same bytes as an anonymous caller, and that none of twenty markers (including pr_, @, the issuer, the team ID, rosterProbeSubject) appears.
  • Cache-Control: no-store, nosniff, JSON content type; no cookie set — asserted on every response by probeBody. The route sits inside homeCSRF and above every session guard, beside /p/{token}; POST/PUT/PATCH/DELETE get 405 with Allow: GET (tested). The plain-text 500 is classified in errors_test.go.
  • ok / stale / unknown: rosterState asks the cache through teamRuntime.check with rosterProbeSubject (pr_ + 26 base32 chars, which passes validMember), discards the answer and keeps only whether there was one. Member or NotMember ⇒ a complete roster younger than MaximumAge ⇒ ok; otherwise stale if rosterHeld was ever set, else unknown. check is the one wrapper, and team_access.go:59 (every request) and team_config.go:116 (principal allocation) now go through it; the added issuer/team guard in the principal path returns ErrUnavailable where the cache would have answered Unknown ⇒ ErrUnavailable before, so behaviour is unchanged. Mutation: deleting t.rosterHeld.Store(true) fails TestTeamProbeShapeAndRosterStates at the stale step (run on a git archive copy in /tmp).

Ruling on the open decision: the probe may refresh

Acceptable, and the right choice. Reasoning from roster/cache.go at the pin Docs uses (74dda570):

  • Amplification. Check starts a refresh only when one is due (!usable or age ≥ RefreshAfter 30 s), through one flight, and startRefresh refuses within RetryAfter (5 s) of the last attempt and whenever the cache is fenced. So an unauthenticated caller at any rate drives at most one bearer-authenticated GET /roster to Home per 5 s while failing, per 30 s while healthy, per instance, each under FetchTimeout 5 s. That is the same ceiling a signed-in request already has, and it is a ceiling the cache enforces, not the handler. On Docs itself a probe during an in-flight refresh parks a goroutine on a channel for ≤ 5 s or until the client goes away; cheaper than /p/{token}, which is already public.
  • A pending instance outside the window. Home's pendingRosterAllowed refuses, and rosterFailure answers {"error":…} with 401/404; verifyPage rejects that with ErrRefused. The fence (evidence.Blocked) fires only on a signed page carrying another generation, so repeated probing cannot fence an instance.
  • Lease and epoch. A probe-triggered refresh is the ordinary fetch → publish path: epoch may only move forward (epoch < c.evidence.Epoch refused), the member digest is checked against durable evidence, and version++ invalidates leases exactly as a request-triggered refresh does — and no earlier, since the due test is the cache's own. The probe never holds a lease. So neither lease nor epoch semantics change; the one new behaviour is that an instance with no signed-in traffic keeps its roster fresh while it is being polled, which Alta does only during step 11 (20 s tick, ≤ 10 min window).
  • Why not never-refresh. A pending instance is not in the chooser; nobody signs in to it, so without the probe's refresh the first roster would never be pulled during Home's verify window and Alta would park roster-unknown for ever. The test "The probe's own poll pulls the first roster" is that case.

Gate

.amadan/ci.d/10-gate at 1b3c291: fixtures (all node tests), bundle freshness, rust fmt/clippy/wasm/test, embedded wasm, wire-gate and go vet green; go test ./... green in every package but two: cmd/docs (TestReleaseBinaryReportsItsVersion, TestStoppingWithAnEditorOpenExitsAtOnce: listen unix /var/folders/…/docs.sock: bind: invalid argument — macOS sun_path length) and internal/shipped (five tests: /opt/homebrew/Cellar/go/1.27.3/libexec/LICENSE: no such file). Both are macOS environment, in packages the branch does not touch; internal/docs passed in 62 s with the four new tests. Because the gate is set -e it stopped there, so I ran the two remaining steps myself: gofmt -l . empty and CGO_ENABLED=0 go build ./... ok. The hub runner (Linux) should be green.

Notes (non-blocking)

  • A fenced cache (evidence.Blocked, durable) answers stale until reboot and unknown after; Alta will park roster-stale/roster-unknown with nothing saying the instance is fenced. §7 defines three states, so this is correct as written; if it ever happens, the cache's own log line is the tell.
  • rosterState waits on an in-flight refresh with r.Context(); Alta's Public client times out at 15 s, so the 5 s wait fits with room.
  • Alta side, once this lands: nothing to change in stepVerify; the parks it already has are the right words for each answer.

Merged to main as e58a22f (squash) after Fable's APPROVED verdict; CI green at 1b3c291. Not deployed - Paul's docs.oficina.works runs with team mode off, where /api/team answers {team_mode:false}; it ships with the next ordinary Docs deploy.