oficina / suite Public

Revision 11: restore-safe revisions, CURSOR_RESET (one per re-read), no-store, strict S2, RunProducer; removed-owner case pending Paul

Answers Fable 5.1's review of c38e3ad; Fable 5.1 re-reviewed and APPROVED at 640d058.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from feat/revision-11 into main.
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 91affa14eae4c3c699a49dc9ff291cf772607954 parent c38e3ad
16 files changed, +1,447 −188
  • README.md +11 −7
  • conformance/conformance.go +202 −48
  • conformance/conformance_test.go +127 −33
  • docs/superpowers/specs/2026-09-05-suite-sharing-doctrine.md +486 −32
  • fixtures.go +70 −15
  • fixtures/custody.json +43 −6
  • fixtures_test.go +69 −0
  • mutations.py +12 −0
  • s1.go +29 −0
  • s1_test.go +61 −1
  • s2.go +11 −2
  • s2_test.go +22 −0
  • server/consumers.go +5 −2
  • server/server.go +113 −23
  • server/server_test.go +180 −18
  • strictjson.go +6 −1

CI passed — run details

CI log
=== gate ===
ok  	amadan.net/oficina/suite	0.008s
ok  	amadan.net/oficina/suite/conformance	0.030s
ok  	amadan.net/oficina/suite/server	0.009s
diff --git a/README.md b/README.md
index c80cff8..11fa282 100644
--- a/README.md
+++ b/README.md
@@ -21,9 +21,9 @@ owns the rule that binds the others.
client must refuse. Both are shared so every app runs the same gate
rather than inventing its own.
- `conformance/`: the harness an app points at its own server half.
-- `server/`: the producer half — the bearer check, the three routes and
- their wire shapes — that an app mounts by implementing `Producer`
- (doctrine §6.5, revision 10).
+- `server/`: the producer half — the bearer check, the three routes, their
+ wire shapes and cache headers, and the cursor reset — that an app mounts
+ as `server.Handler` by implementing `Producer` (doctrine §6.5, §6.6).
## How an app uses it
@@ -37,7 +37,9 @@ cannot get one.** The shape it will take:
```go
func TestSuiteConformance(t *testing.T) {
- conformance.Run(t, myapp.SuiteRoutes())
+ // The producer, mounted through server.Handler as the app mounts it,
+ // behind a token the harness mints. Never server.Routes (deprecated).
+ conformance.RunProducer(t, myapp.SuiteProducer(), suite.SubjectPersonRef)
}
```
@@ -57,9 +59,11 @@ step 4,
after memoria's slice 1 and before its slice 2; it is specified and has no
fixture yet.
-Not built, deliberately: the server half — that arrives with the first app
-that serves one, and the fixtures get corrected by the second, which is the
-point of §10. Nor call 7, call 8, the roster or anything needing an
+The server half, `server/`, was built in revision 10 with the first two
+apps that serve it, Docs and Fichas, and corrected by them in revision 11
+(§6.6) — which is the point of §10.
+
+Not built, deliberately: call 7, call 8, the roster or anything needing an
assertion; those are §12 steps 4 and 5 and they wait on the home's identity
layer.
diff --git a/conformance/conformance.go b/conformance/conformance.go
index 87dadf6..74b81ce 100644
--- a/conformance/conformance.go
+++ b/conformance/conformance.go
@@ -1,16 +1,22 @@
// Package conformance drives an app's server half against the doctrine's
// golden fixtures.
//
-// An app mounts its suite routes on a handler and hands that handler here.
-// The harness fires the fixture's requests at it and reports what the contract
-// says should have happened and did not. Doctrine §10: two specs are guesses,
-// two implementations are facts — this is where the second implementation
-// corrects the first.
+// An app built on suite/server hands its Producer to RunProducer, which
+// mounts it exactly as the app does — server.Handler, behind a bearer token
+// the harness mints for itself — so what is tested is what is served, and
+// no unauthenticated handler ever needs to exist. An app with its own server
+// half hands that handler to Run or RunAs. The harness fires the fixture's
+// requests and reports what the contract says should have happened and did
+// not. Doctrine §10: two specs are guesses, two implementations are facts —
+// this is where the second implementation corrects the first.
package conformance
import (
"bytes"
+ "crypto/rand"
+ "encoding/hex"
"encoding/json"
+ "errors"
"fmt"
"net/http"
"net/http/httptest"
@@ -21,6 +27,7 @@ import (
"testing"
"amadan.net/oficina/suite"
+ "amadan.net/oficina/suite/server"
)
// Report is what a run found. An empty Failures is a pass.
@@ -62,6 +69,64 @@ func RunAs(t *testing.T, h http.Handler, kind suite.SubjectKind) {
}
}
+// RunProducer is how an app built on suite/server runs gate 3: the
+// producer mounted through server.Handler, exactly as the app mounts it, and
+// driven with a token the harness mints (revision 11). kind is the asker
+// kind the app keys on.
+//
+// It tests Handler and the Producer behind it, nothing else: middleware an
+// app puts in front of Handler — its own router, a proxy, a cache, a CSRF
+// or session layer — is not in the request path here and is not covered.
+// Nor can it see how the app seeded its world from the fixture's owner,
+// asker_grant and rung; a case seeded wrongly can pass.
+func RunProducer(t *testing.T, p server.Producer, kind suite.SubjectKind) {
+ t.Helper()
+ report := CheckProducer(p, kind)
+ for _, f := range report.Failures {
+ t.Error(f)
+ }
+ if report.Checked == 0 {
+ t.Error("conformance ran no checks; a gate that asserts nothing passes everything")
+ }
+}
+
+// CheckProducer is RunProducer without a *testing.T. Beyond CheckAs it
+// asks once with no token, which must be the 401 — Handler, not routes
+// served to anybody — and that 401 is held to the same Cache-Control and
+// Vary as every other response (Fable's review of 0a59e7d, L6).
+func CheckProducer(p server.Producer, kind suite.SubjectKind) Report {
+ var r Report
+ raw := make([]byte, 32)
+ if _, err := rand.Read(raw); err != nil {
+ r.fail("minting the harness's token: %v", err)
+ return r
+ }
+ token := hex.EncodeToString(raw)
+ h := server.Handler(p, []server.Consumer{{
+ ID: "suite-conformance",
+ Tokens: []server.Token{{Epoch: 1, SHA256: server.TokenHash(token)}},
+ }}, nil)
+
+ // Through the header audit, as every request in CheckAs is: the 401 is
+ // a response like any other, and a cache keeping it keyed without
+ // Authorization would serve it to the next caller.
+ audit := &storeAudit{next: h, r: &r, seen: map[string]bool{}}
+ anon := do(audit, "GET", suite.RouteS3+"/"+suite.NonexistentItemID+"?revision=1", nil)
+ r.Checked++
+ if anon.Code != http.StatusUnauthorized {
+ r.fail("a request with no token: got %d, want 401", anon.Code)
+ }
+
+ report := CheckAs(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+ req = req.Clone(req.Context())
+ req.Header.Set("Authorization", "Bearer "+token)
+ h.ServeHTTP(w, req)
+ }), kind)
+ r.Checked += report.Checked
+ r.Failures = append(r.Failures, report.Failures...)
+ return r
+}
+
// Check drives the handler and returns what it found, without touching a
// *testing.T. It exists so the harness itself can be tested: a harness that
// passes every server is worse than no harness, and the only way to know is to
@@ -86,13 +151,49 @@ func CheckAs(h http.Handler, kind suite.SubjectKind) Report {
}
fixture.Asker.Kind, fixture.Stranger.Kind = kind, kind
- checkS3(h, fixture, &r)
- checkS2(h, fixture, &r)
- checkWrongKind(h, fixture, kind, &r)
- checkS1(h, fixture, &r)
+ audit := &storeAudit{next: h, r: &r, seen: map[string]bool{}}
+ checkS3(audit, fixture, &r)
+ checkS2(audit, fixture, &r)
+ checkWrongKind(audit, fixture, kind, &r)
+ checkS1(audit, fixture, &r)
return r
}
+// storeAudit holds every response the harness receives to the headers the
+// doctrine requires on all of them (§6.5, revision 11): Cache-Control:
+// no-store, so no cache between two apps keeps one person's S2 answer or a
+// private item's S3 body for the next request, and Vary: Authorization. One
+// failure per route, method and status, not one per request.
+type storeAudit struct {
+ next http.Handler
+ r *Report
+ seen map[string]bool
+}
+
+func (a *storeAudit) ServeHTTP(w http.ResponseWriter, req *http.Request) {
+ rec := httptest.NewRecorder()
+ a.next.ServeHTTP(rec, req)
+ res := rec.Result()
+ route := req.URL.Path
+ if strings.HasPrefix(route, suite.RouteS3+"/") {
+ route = suite.RouteS3
+ }
+ key := fmt.Sprintf("%s %s %d", req.Method, route, res.StatusCode)
+ if !a.seen[key] {
+ a.seen[key] = true
+ a.r.Checked++
+ if res.Header.Get("Cache-Control") != "no-store" || res.Header.Get("Vary") != "Authorization" {
+ a.r.fail("%s: Cache-Control %q and Vary %q, want no-store and Authorization on every response",
+ key, res.Header.Get("Cache-Control"), res.Header.Get("Vary"))
+ }
+ }
+ for k, v := range res.Header {
+ w.Header()[k] = v
+ }
+ w.WriteHeader(res.StatusCode)
+ w.Write(rec.Body.Bytes())
+}
+
// Gate 2's kind rule: an asker of a kind the app does not key on is UNKNOWN
// for the whole call, never NOT_VISIBLE and never an answer read off the
// value alone (Astra, 2026-11-01: the reference server compared values only
@@ -104,11 +205,12 @@ func checkWrongKind(h http.Handler, f suite.CustodyFixture, kind suite.SubjectKi
}
wrong := suite.Subject{Kind: other, Value: f.Asker.Value}
pairs := make([]suite.ItemRevision, 0, len(f.Cases))
+ want := make([]suite.Authorization, 0, len(f.Cases))
for _, c := range f.Cases {
pairs = append(pairs, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision})
+ want = append(want, suite.UNKNOWN)
}
- askS2(h, f, r, "the asker's value under the kind this app does not key on", wrong, pairs,
- func(suite.CustodyCase) suite.Authorization { return suite.UNKNOWN })
+ ask(h, r, "the asker's value under the kind this app does not key on", wrong, pairs, want)
}
// Gate 3, the content half. Since revision 10 (Paul, 2026-11-01) every live
@@ -125,12 +227,14 @@ func checkS3(h http.Handler, f suite.CustodyFixture, r *Report) {
r.fail("S3 for an item that does not exist: got %d, want 404", baseline.Code)
}
- // Only the current revision is ever served: a consumer asking for
- // revision 6 or 8 of an item now at 7 gets the refusal, not today's
- // bytes under another number (Astra, 2026-11-01: the reference server
- // served the older one; a mutant serving the newer one passed).
+ // Only the current revision is ever served: a consumer asking for a
+ // revision the log holds but has moved past, or one it never issued,
+ // gets the refusal, not today's bytes under another name (Astra,
+ // 2026-11-01: the reference server served the older one; a mutant
+ // serving the newer one passed). Since revision 11 the fixture names
+ // both revisions; the harness computes neither.
for _, c := range f.Cases {
- for _, rev := range []int64{c.Revision - 1, c.Revision + 1} {
+ for _, rev := range []int64{c.PriorRevision, c.UnknownRevision} {
rec := do(h, "GET", suite.RouteS3+"/"+c.ItemID+"?revision="+strconv.FormatInt(rev, 10), nil)
r.Checked++
if refusal(rec) != refusal(baseline) {
@@ -138,6 +242,26 @@ func checkS3(h http.Handler, f suite.CustodyFixture, r *Report) {
c.ItemID, rev, c.Revision, refusal(rec), refusal(baseline))
}
}
+ // No revision, a malformed one and one under 1 are the same refusal
+ // (Fable, review of c38e3ad, M5): a server that read a missing
+ // revision as "the current one" serves bytes nobody named, and one
+ // that answered 400 tells the caller the item exists.
+ for what, query := range map[string]string{"no revision": "", "a malformed revision": "?revision=seven", "revision 0": "?revision=0"} {
+ rec := do(h, "GET", suite.RouteS3+"/"+c.ItemID+query, nil)
+ r.Checked++
+ if refusal(rec) != refusal(baseline) {
+ r.fail("S3 %s with %s: %s, want the refusal for an item that does not exist (%s)",
+ c.ItemID, what, refusal(rec), refusal(baseline))
+ }
+ }
+ // S3 is a GET. A POST is not served, whatever it is answered with.
+ if c.S3Status == 200 {
+ rec := do(h, "POST", suite.RouteS3+"/"+c.ItemID+"?revision="+strconv.FormatInt(c.Revision, 10), nil)
+ r.Checked++
+ if rec.Code >= 200 && rec.Code <= 299 || strings.Contains(rec.Body.String(), c.S3Body) {
+ r.fail("S3 %s on POST: %d, and S3 serves a GET only", c.ItemID, rec.Code)
+ }
+ }
}
for _, c := range f.Cases {
@@ -180,43 +304,58 @@ func checkS3(h http.Handler, f suite.CustodyFixture, r *Report) {
// grant, and never a link. The fixture's asker owns one private item, holds a
// grant on another and a former grant on a deleted one, and does not own the
// link-shared and moved-to-private items, so each part of the check shows.
+//
+// Since revision 11 the revisions asked about are the fixture's own: its
+// prior_revision (one the log holds, not current) and its unknown_revision
+// (one the log never issued). The harness computes no "one behind": a
+// revision is a name, and a producer comparing numbers is the one a restore
+// turns into a leak (doctrine §6.6).
func checkS2(h http.Handler, f suite.CustodyFixture, r *Report) {
- // Three questions, not one. A single question at the current revision for
- // a single person lets a server answer from the rung alone and read
+ // Several questions, not one. A single question at the current revision
+ // for a single person lets a server answer from the rung alone and read
// neither the asker nor the revision it was sent.
- current := make([]suite.ItemRevision, 0, len(f.Cases))
- behind := make([]suite.ItemRevision, 0, len(f.Cases))
- for _, c := range f.Cases {
- current = append(current, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision})
- behind = append(behind, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision - 1})
+ at := func(rev func(suite.CustodyCase) int64, want func(suite.CustodyCase) suite.Authorization) ([]suite.ItemRevision, []suite.Authorization) {
+ pairs := make([]suite.ItemRevision, 0, len(f.Cases))
+ wants := make([]suite.Authorization, 0, len(f.Cases))
+ for _, c := range f.Cases {
+ pairs = append(pairs, suite.ItemRevision{ItemID: c.ItemID, Revision: rev(c)})
+ wants = append(wants, want(c))
+ }
+ return pairs, wants
}
+ current := func(c suite.CustodyCase) int64 { return c.Revision }
+ prior := func(c suite.CustodyCase) int64 { return c.PriorRevision }
+ unknown := func(c suite.CustodyCase) int64 { return c.UnknownRevision }
+ stranger := func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger }
- askS2(h, f, r, "the fixture's asker, at the current revision", f.Asker, current,
- func(c suite.CustodyCase) suite.Authorization { return c.S2Result })
+ pairs, want := at(current, func(c suite.CustodyCase) suite.Authorization { return c.S2Result })
+ ask(h, r, "the fixture's asker, at the current revision", f.Asker, pairs, want)
+ pairs, want = at(prior, func(c suite.CustodyCase) suite.Authorization { return c.S2ResultSuperseded })
+ ask(h, r, "the fixture's asker, at a prior revision the log holds", f.Asker, pairs, want)
+ pairs, want = at(unknown, func(c suite.CustodyCase) suite.Authorization { return c.S2ResultAhead })
+ ask(h, r, "the fixture's asker, at a revision the log never issued", f.Asker, pairs, want)
- askS2(h, f, r, "the fixture's asker, one revision behind", f.Asker, behind,
- func(c suite.CustodyCase) suite.Authorization { return c.S2ResultSuperseded })
+ // The stranger at every revision: a server that checks the revision
+ // before the person tells a stranger STALE or UNKNOWN where it owes
+ // them NOT_VISIBLE (Astra, 2026-11-01).
+ pairs, want = at(current, stranger)
+ ask(h, r, "a person with no team standing", f.Stranger, pairs, want)
+ pairs, want = at(prior, stranger)
+ ask(h, r, "a person with no team standing, at a prior revision", f.Stranger, pairs, want)
+ pairs, want = at(unknown, stranger)
+ ask(h, r, "a person with no team standing, at a revision never issued", f.Stranger, pairs, want)
- ahead := make([]suite.ItemRevision, 0, len(f.Cases))
- for _, c := range f.Cases {
- ahead = append(ahead, suite.ItemRevision{ItemID: c.ItemID, Revision: c.Revision + 1})
- }
- askS2(h, f, r, "the fixture's asker, one revision ahead", f.Asker, ahead,
- func(c suite.CustodyCase) suite.Authorization { return c.S2ResultAhead })
-
- askS2(h, f, r, "a person with no team standing", f.Stranger, current,
- func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger })
-
- // The stranger at the other revisions too: a server that checks the
- // revision before the person tells a stranger STALE where it owes them
- // NOT_VISIBLE (Astra, 2026-11-01).
- askS2(h, f, r, "a person with no team standing, one revision behind", f.Stranger, behind,
- func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger })
- askS2(h, f, r, "a person with no team standing, one revision ahead", f.Stranger, ahead,
- func(c suite.CustodyCase) suite.Authorization { return c.S2ResultStranger })
+ // An id the producer does not know is NOT_VISIBLE for everybody. A
+ // server that fails open — VISIBLE for whatever it cannot find — passes
+ // every fixture case, because every fixture case exists (Fable, review
+ // of c38e3ad, H2).
+ none := []suite.ItemRevision{{ItemID: suite.NonexistentItemID, Revision: 1}}
+ ask(h, r, "the fixture's asker, about an id the app does not know", f.Asker, none, []suite.Authorization{suite.NOT_VISIBLE})
+ ask(h, r, "a person with no team standing, about an id the app does not know", f.Stranger, none, []suite.Authorization{suite.NOT_VISIBLE})
}
-func askS2(h http.Handler, f suite.CustodyFixture, r *Report, what string, asker suite.Subject, pairs []suite.ItemRevision, want func(suite.CustodyCase) suite.Authorization) {
+// ask puts one S2 question and holds each answer to want, pair by pair.
+func ask(h http.Handler, r *Report, what string, asker suite.Subject, pairs []suite.ItemRevision, want []suite.Authorization) {
if err := suite.CheckS2Batch(pairs); err != nil {
r.fail("custody fixture is over the S2 cap: %v", err)
return
@@ -229,12 +368,14 @@ func askS2(h http.Handler, f suite.CustodyFixture, r *Report, what string, asker
}
rec := do(h, "POST", suite.RouteS2, body)
+ // DecodeS2 is strict: a row carrying anything beyond item_id, revision
+ // and result makes the whole call UNKNOWN, and fails here.
got := suite.DecodeS2(pairs, rec.Code, rec.Body.Bytes())
- for i, c := range f.Cases {
+ for i, p := range pairs {
r.Checked++
- if got[i] != want(c) {
- r.fail("S2 %s asked for %s: got %s, want %s", c.ItemID, what, got[i], want(c))
+ if got[i] != want[i] {
+ r.fail("S2 %s asked for %s: got %s, want %s", p.ItemID, what, got[i], want[i])
}
}
}
@@ -280,6 +421,19 @@ func checkS1(h http.Handler, f suite.CustodyFixture, r *Report) {
}
cursor = feed.Cursor
}
+
+ // A cursor the log does not recognise — restored from a backup, or
+ // issued by another log — is the fixed 409, which tells the consumer to
+ // drop what it holds and read from the beginning. Answered as the tip,
+ // it leaves a consumer holding a dead log's items for ever; answered as
+ // a failure, it stalls the consumer for ever (Fable, review of c38e3ad,
+ // H1; doctrine §6.6).
+ rec := do(h, "GET", suite.RouteS1+"?cursor="+url.QueryEscape(suite.NeverIssuedCursor), nil)
+ r.Checked++
+ if _, err := suite.DecodeS1(rec.Code, rec.Body.Bytes()); !errors.Is(err, suite.ErrCursorReset) {
+ r.fail("S1 with a cursor the log never issued: %d %q, want %d %s", rec.Code, rec.Body.String(), suite.CursorResetStatus, suite.CursorResetBody)
+ }
+
for _, c := range f.Cases {
r.Checked++
row, ok := last[c.ItemID]
diff --git a/conformance/conformance_test.go b/conformance/conformance_test.go
index d3882ea..a0de44f 100644
--- a/conformance/conformance_test.go
+++ b/conformance/conformance_test.go
@@ -39,6 +39,18 @@ type referenceServer struct {
stuckWithRows bool // the same cursor back, with rows
reservedCursor bool // cursors that need query escaping (correct)
repeatEarlierRow bool // an item's last row older than its current revision
+
+ // Revision 11 (Fable's review of c38e3ad).
+ numericRevisions bool // STALE for any revision below current, held in the log or not
+ failOpen bool // VISIBLE for an id it does not know
+ titleInS2Row bool // an S2 row carrying the item's title
+ missingRevisionIsNow bool // S3 with no ?revision serves the current bytes
+ malformedRevision400 bool // S3 answers 400 for a malformed revision
+ s3ServesPost bool // S3 serves a POST
+ foreignCursorIsTip bool // a cursor the log never issued answered as the tip
+ foreignCursorFails bool // a cursor the log never issued answered 503
+ cacheable bool // no Cache-Control: no-store
+ noVary bool // no-store, and no Vary: Authorization
}
func (s *referenceServer) find(itemID string) (suite.CustodyCase, bool) {
@@ -51,15 +63,21 @@ func (s *referenceServer) find(itemID string) (suite.CustodyCase, bool) {
}
func (s *referenceServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ if !s.cacheable {
+ w.Header().Set("Cache-Control", "no-store")
+ if !s.noVary {
+ w.Header().Set("Vary", "Authorization")
+ }
+ }
switch {
- case strings.HasPrefix(r.URL.Path, suite.RouteS3+"/"):
+ case strings.HasPrefix(r.URL.Path, suite.RouteS3+"/") && (r.Method == "GET" || s.s3ServesPost):
s.serveS3(w, r)
- case r.URL.Path == suite.RouteS2:
+ case r.URL.Path == suite.RouteS2 && r.Method == "POST":
s.serveS2(w, r)
- case r.URL.Path == suite.RouteS1:
+ case r.URL.Path == suite.RouteS1 && r.Method == "GET":
s.serveS1(w, r)
default:
- http.NotFound(w, r)
+ w.WriteHeader(http.StatusMethodNotAllowed)
}
}
@@ -78,7 +96,15 @@ func (s *referenceServer) serveS3(w http.ResponseWriter, r *http.Request) {
}
// Revision 10: every live item is held, so every live item is served —
// at its current revision only.
- rev, _ := strconv.ParseInt(r.URL.Query().Get("revision"), 10, 64)
+ raw := r.URL.Query().Get("revision")
+ rev, err := strconv.ParseInt(raw, 10, 64)
+ if raw == "" && s.missingRevisionIsNow {
+ rev = c.Revision
+ }
+ if raw != "" && err != nil && s.malformedRevision400 {
+ w.WriteHeader(400)
+ return
+ }
if c.Rung != suite.RungDeleted && (rev == c.Revision || (s.serveSuperseded && rev < c.Revision) || (s.serveFuture && rev > c.Revision)) {
w.WriteHeader(200)
if s.wrongBodyForTeamItem {
@@ -113,6 +139,7 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) {
ItemID string `json:"item_id"`
Revision int64 `json:"revision"`
Result suite.Authorization `json:"result"`
+ Title string `json:"title,omitempty"`
}
out := struct {
Results []result `json:"results"`
@@ -137,6 +164,12 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) {
if c.Rung == suite.RungDeleted {
return false
}
+ if stranger {
+ // The fixture's stranger owns nothing and holds no grant, so
+ // nothing opens for them. Whether a removed member keeps what
+ // they own is not ruled (doctrine §14) and not in the fixture.
+ return false
+ }
if s.linkCountsAsGrant && c.Link != "" {
return true
}
@@ -152,6 +185,9 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) {
switch {
case !ok:
answer = suite.NOT_VISIBLE
+ if s.failOpen {
+ answer = suite.VISIBLE
+ }
case s.ignoreAskerAndRevision:
// Answers from the rung alone: any asker, any revision. This is
@@ -163,24 +199,32 @@ func (s *referenceServer) serveS2(w http.ResponseWriter, r *http.Request) {
case stranger && s.revisionBeforePerson && p.Revision < c.Revision:
answer = suite.STALE
- case stranger:
- // No team standing reaches nothing, the team rung included.
+ case !mayOpen(c):
answer = suite.NOT_VISIBLE
- case mayOpen(c) && p.Revision < c.Revision:
+ case p.Revision == c.Revision:
+ answer = suite.VISIBLE
+
+ case p.Revision == c.PriorRevision:
+ // In the log, and not current (§6.6): decided from the log.
answer = suite.STALE
- case mayOpen(c) && p.Revision > c.Revision:
- // A revision the log does not recognise (§4.3).
- answer = suite.UNKNOWN
- if s.staleWhenAhead {
- answer = suite.STALE
- }
+ case s.numericRevisions && p.Revision < c.Revision:
+ // The counter's habit: below current reads as "older".
+ answer = suite.STALE
- case mayOpen(c):
- answer = suite.VISIBLE
+ case s.staleWhenAhead && p.Revision > c.Revision:
+ answer = suite.STALE
+
+ default:
+ // A revision the log does not hold (§4.3, §6.6).
+ answer = suite.UNKNOWN
}
- out.Results = append(out.Results, result{ItemID: p.ItemID, Revision: p.Revision, Result: answer})
+ row := result{ItemID: p.ItemID, Revision: p.Revision, Result: answer}
+ if s.titleInS2Row && ok {
+ row.Title = c.Name
+ }
+ out.Results = append(out.Results, row)
}
w.Header().Set("Content-Type", "application/json")
@@ -211,27 +255,35 @@ func (s *referenceServer) serveS1(w http.ResponseWriter, r *http.Request) {
half := len(rows) / 2
var page []map[string]any
next := cursor
- switch cursor {
- case "":
- page, next = rows[:half], "c-1"
- case "c-1":
- page, next = rows[half:], "c-2"
- default:
- page = []map[string]any{}
- }
+ issued := []string{"", "c-1", "c-2"}
if s.reservedCursor {
// A cursor with characters a query string must escape. A harness
// that sent it unescaped would read "c 1&x=y" as "c 1".
- switch cursor {
- case "":
- page, next = rows[:half], "c 1&x=y"
- case "c 1&x=y":
- page, next = rows[half:], "c+2#end"
- default:
+ issued = []string{"", "c 1&x=y", "c+2#end"}
+ }
+ switch cursor {
+ case issued[0]:
+ page, next = rows[:half], issued[1]
+ case issued[1]:
+ page, next = rows[half:], issued[2]
+ case issued[2]:
+ page = []map[string]any{}
+ default:
+ // A cursor this log never issued (§6.6, revision 11).
+ switch {
+ case s.foreignCursorIsTip:
page = []map[string]any{}
+ case s.foreignCursorFails:
+ w.WriteHeader(503)
+ return
+ default:
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(suite.CursorResetStatus)
+ w.Write([]byte(suite.CursorResetBody))
+ return
}
}
- if s.repeatEarlierRow && cursor == "c-1" {
+ if s.repeatEarlierRow && cursor == issued[1] {
// The second page repeats an item from the first at an older
// revision: the item's state is its LAST row, and it is stale.
stale := map[string]any{}
@@ -244,7 +296,7 @@ func (s *referenceServer) serveS1(w http.ResponseWriter, r *http.Request) {
if s.neverEnds {
next = cursor + "x"
}
- if s.stuckWithRows && cursor == "c-1" {
+ if s.stuckWithRows && cursor == issued[1] {
next = cursor
}
w.Header().Set("Content-Type", "application/json")
@@ -438,3 +490,45 @@ func TestHarnessRound3(t *testing.T) {
t.Error("an address-keyed server ignoring the kind passed")
}
}
+
+// Fable's review of c38e3ad (revision 11): each a broken server the harness
+// must refuse. The reference server above passes; each bend breaks one rule.
+//
+// MUTATION-TESTED 2026-11-01 on the harness, each reverted, by the bend that
+// then passed: the S2 questions at the fixture's unknown_revision replaced
+// by Revision+1 → "revisions compared as numbers"; the NonexistentItemID
+// questions removed → "an unknown id answered VISIBLE"; DecodeS2's
+// DisallowUnknownFields removed → "a title in an S2 row"; the
+// missing/malformed S3 loop removed → "no revision serves today's bytes"
+// and "a malformed revision answered 400"; the POST probe removed → "S3
+// served on POST"; the foreign-cursor probe removed → both foreign-cursor
+// bends; storeAudit's header check removed → "a cacheable response", and
+// its Vary half alone → "no Vary: Authorization". (The stranger questions at
+// prior and unknown revisions removed → "STALE for a stranger", in the test
+// above.)
+//
+// 2026-11-02 (Fable's review of 0a59e7d, H1): the bend "an owner without
+// standing" is withdrawn with the fixture case doc-owner-left it needed.
+// That case was revision 11's proposal, unruled by Paul and contrary to
+// gate 5's reading; with no stranger-owned case the bend breaks nothing
+// the harness asks about, so keeping it would only fail this test.
+func TestHarnessCatchesWhatRevision10Missed(t *testing.T) {
+ for name, bend := range map[string]func(*referenceServer){
+ "revisions compared as numbers": func(s *referenceServer) { s.numericRevisions = true },
+ "an unknown id answered VISIBLE": func(s *referenceServer) { s.failOpen = true },
+ "a title in an S2 row": func(s *referenceServer) { s.titleInS2Row = true },
+ "no revision serves today's bytes": func(s *referenceServer) { s.missingRevisionIsNow = true },
+ "a malformed revision answered 400": func(s *referenceServer) { s.malformedRevision400 = true },
+ "S3 served on POST": func(s *referenceServer) { s.s3ServesPost = true },
+ "a foreign cursor answered as the tip": func(s *referenceServer) { s.foreignCursorIsTip = true },
+ "a foreign cursor answered 503": func(s *referenceServer) { s.foreignCursorFails = true },
+ "a cacheable response": func(s *referenceServer) { s.cacheable = true },
+ "no Vary: Authorization": func(s *referenceServer) { s.noVary = true },
+ } {
+ s := newReference(t)
+ bend(s)
+ if report := conformance.Check(s); len(report.Failures) == 0 {
+ t.Errorf("%s: the harness passed it", name)
+ }
+ }
+}
diff --git a/docs/superpowers/specs/2026-09-05-suite-sharing-doctrine.md b/docs/superpowers/specs/2026-09-05-suite-sharing-doctrine.md
index 1935b18..779ec1a 100644
--- a/docs/superpowers/specs/2026-09-05-suite-sharing-doctrine.md
+++ b/docs/superpowers/specs/2026-09-05-suite-sharing-doctrine.md
@@ -3,10 +3,100 @@
How the apps of the suite share identity, membership and content with
each other, and where the line is that nothing crosses.
-**Status:** design, **revision 10**, 2026-11-01. Revision 10 carries
-Paul's ruling and was reviewed by GPT-6 (Codex, "Astra") in three passes:
-REQUEST CHANGES on 12848f8 and 53b79d5, **APPROVE** on 983114a, its polish
-items applied after.
+**Status:** design, **revision 11**, 2026-11-02. Revision 11 is this
+session's answer to a review of revision 10 (at c38e3ad) by Fable
+(claude-fable-5-1). Fable 5.1 then reviewed revision 11 at **0a59e7d** and
+returned **REQUEST CHANGES** (one high, three medium, seven low findings);
+this round answers that review, and **Fable 5.1 (claude-fable-5-1, as
+dispatched and as reported) re-reviewed it at 640d058: APPROVE**, every
+finding verified answered, its own mutations run, no new contradiction.
+Revision 10 carries Paul's ruling and was reviewed by GPT-6 (Codex,
+"Astra") in three passes: REQUEST CHANGES on 12848f8 and 53b79d5,
+**APPROVE** on 983114a, its polish items applied after.
+
+**This round (2026-11-02, this session, answering Fable 5.1's review of
+0a59e7d).** Revision 11 is not on `main` (`origin/main` is c38e3ad,
+revision 10), so this round amends it in place rather than minting revision
+12; a citation of revision 11 names this round's commit or a later one,
+never 0a59e7d, and a session that read 0a59e7d reads again. Nothing in it
+is Paul's. What changes:
+
+- **H1 — the removed-owner case is withdrawn, and asked.** §4.3's "no team
+ standing reaches nothing, ownership included" contradicted gate 5 and §6's
+ S2 row, and Paul has not ruled. It is now marked an **unruled proposal**;
+ gate 5's reading binds until he does; the fixture case `doc-owner-left` is
+ out of `custody.json` (the format has no pending list) and recorded in
+ §14 as a **NEEDS PAUL** item; `server.Producer`'s doc says only what is
+ ruled. The harness's matching broken variant is withdrawn with it.
+- **M1** — at most **one `CURSOR_RESET` per re-read**: a second before the
+ tip is a producer failure that keeps its items withheld, and re-reads
+ back off (§6.6, A.4); §9 gains item 13, the cost a resetting producer
+ can still impose.
+- **M2** — an expired or compacted cursor is answered `CURSOR_RESET` too;
+ the S1 row's "full re-announce" is struck, and S5's paragraph is marked.
+- **M3** — where revision 11 said the fixture "holds every app" to the
+ owner rule, it now says the harness sees answers and not seeding, and
+ cannot (§4.3, §6.5, gate 3).
+- **L1** — §6.6's step 1 is a soft drop (hidden, pending); step 3 is the
+ hard retire. **L2** — the cursor stamp rule is normative: per event, or
+ minted at restore and never restored; a generation id in the restorable
+ database is not enough. **L3** — "most unknown revisions sit below" was
+ false (four of ten) and is corrected, and the module now tests that the
+ fixture has openable cases on both sides. **L4** — a revision is redrawn
+ on a collision with any revision the log holds for the item. **L5** —
+ gate 3's revision-10 "one behind / one ahead" is marked superseded.
+ **L6** — `conformance.CheckProducer`'s unauthenticated probe goes
+ through the header audit, and `RunProducer`'s doc says it tests `Handler`
+ only. L7 needed no change.
+
+**Revision 11 makes a restore safe, and makes S2 and S3 fail closed where
+the harness could not see them fail open.** Who: this session, answering
+Fable's findings on c38e3ad; nothing in it is Paul's except where quoted,
+and the one question it raises is his (below). Why: the two producers that
+implemented revision 10 — Fichas (`main` c837d28) and Docs (branch
+`feat/suite-producer`) — both found that a counted or clock-based revision
+is **reissued after a database restore**: an `(item, revision)` memoria
+already held then matched different bytes, and S2 said `VISIBLE` over stale
+private text. Both moved to random revisions and stamped cursors, and both
+were left answering an unrecognised cursor with a 503 and a manual reset.
+What changes, each where it lives:
+
+- **§6.6 is new and normative**: a revision names one byte sequence for
+ ever; a producer that can reissue one is not conformant; `STALE` is
+ decided from the producer's own log, and a revision the log does not hold
+ is `UNKNOWN` on S2 and the refusal on S3. A cursor the log does not
+ recognise is answered with one fixed `409 {"code":"CURSOR_RESET"}`, and
+ the consumer hides everything it holds from that producer and reads it
+ again from the beginning, at most once per re-read (Fable H1; bounded
+ 2026-11-02, M1).
+- **The fixture** names each case's `prior_revision` and
+ `unknown_revision`; the harness computes no "one behind" any more. It
+ asks S2 about an id the producer does not know (`NOT_VISIBLE`, never a
+ fail-open `VISIBLE`), refuses S3 with no, a malformed or a zero revision
+ and on POST, refuses S2 rows carrying any field beyond the three, and
+ requires `Cache-Control: no-store` and `Vary: Authorization` on every
+ response (Fable H1, H2, M3, M5). A new case, `doc-owner-left`, is a
+ private item whose owner has lost team standing: `NOT_VISIBLE` to them
+ too — this session's proposal (§4.3), not a ruling. *(Withdrawn
+ 2026-11-02, answering Fable's review of 0a59e7d, H1: see above and §14.)*
+- **Gate 3c** gains a flip case: an answer is never cached, so the next
+ request on every surface follows the sibling's new answer (Fable H3).
+- **`suite/server`**: `Handler` is the only thing an app mounts, and
+ `conformance.RunProducer` tests it through a token it mints; the
+ unauthenticated `Routes` is deprecated, kept because the module is
+ additive and Docs' and Fichas' tests call it (Fable M4).
+- **§9 item 2** says plainly that a sibling token reads the grant graph
+ (Fable M6); revision-9 text left unmarked in §6 and §6.4 is marked
+ (Fable M1, low items).
+
+**Paul's questions (§14, NEEDS PAUL).** First, does a person removed from
+the team keep S2 access to items they own or were individually granted
+(gate 5's reading, Docs today), or reach nothing (revision 11's proposal)?
+Until he rules, gate 5's reading holds. Second: may a consumer send
+private items to its model provider to embed them? Revision 10 put private documents in the
+corpus that §8 compares to "whole-corpus egress", and nobody ruled on that
+egress. Until he does, a consumer embeds nothing private and sends a model
+only passages already ruled `VISIBLE` for the person asking (§8).
**Revision 10 widens custody to every live item, by Paul's ruling, and
builds the producer half.** Asked *"Is it possible for everyone's Memoria to
@@ -39,7 +129,9 @@ stays where it is. What changes, each where it lives:
what every teammate could read, so a bug in its per-person gate could at
worst show a teammate something they could already open in the app. Under
revision 10 a consumer holds everyone's private and individually shared
-items, sealed at rest like everything else it holds, and the same bug shows
+items, sealed at rest — which bounds a disk and not a process *(wording
+corrected in revision 11; it read "like everything else it holds")* — and
+the same bug shows
a teammate somebody else's private document. S2 — asked per person, per
request, never cached, with every non-`VISIBLE` answer withholding — is now
the only thing between those documents and a teammate's search, and every
@@ -415,6 +507,47 @@ revision the app of record does not recognise is **`UNKNOWN`**: withheld
loudly, the app named, the consumer free to re-ingest. memoria records
this defect open in its §13; A.4 closes it. *(GPT-6 review, finding 11.)*
+> **Revision 11 (this session, 2026-11-01, answering Fable's review of
+> c38e3ad): "behind" is not a number.** The paragraph above reasons in
+> counts — "holds 7, the app now has 5" — and a count is exactly what a
+> restore reissues: after it, the app reaches 7 again with different bytes,
+> and a consumer holding the old 7 is told `VISIBLE`. So a revision names
+> **one byte sequence for ever**; a producer whose revisions can be
+> reissued is not conformant; `STALE` means "a revision my log holds that
+> is not current", decided from the log and never by comparing numbers;
+> and a revision the log does not hold is `UNKNOWN` for a person who may
+> open the item (and `NOT_VISIBLE` for one who may not — the person is
+> checked first). §6.6 states it as the contract.
+
+> **UNRULED PROPOSAL — not the contract.** *(This session, 2026-11-01, in
+> revision 11; demoted 2026-11-02, answering Fable's review of 0a59e7d, H1,
+> because it contradicts gate 5 and §6's S2 row and Paul has not ruled.)*
+> The proposal: **no team standing reaches nothing, ownership included** —
+> a member who owns private items and is then removed from the team gets
+> `NOT_VISIBLE` on S2 for their own items, as every stranger does for
+> every item, on the reasoning that a consumer serves the team's members,
+> a person off the roster is not one, and "they own it" is a fact inside
+> the app of record, where its own rules can still serve them.
+>
+> **What binds until Paul rules is gate 5's reading** (§11): a member
+> removed at the home **holding no other grant** gets `NOT_VISIBLE`, and
+> losing team standing does not by itself revoke an instance-side grant —
+> asserting otherwise would implement a complete-offboarding policy §5.2
+> has not agreed to. Docs answers that way today, as Fable's review of
+> 0a59e7d records. The question is §14's
+> NEEDS PAUL item. Revision 11 also put a fixture case, `doc-owner-left`,
+> behind the proposal; it is **withdrawn from `custody.json`** and no
+> binding case asks about a removed owner either way.
+>
+> **Whichever way Paul rules, the harness cannot hold an app to it alone.**
+> An app seeds its own world from the fixture's `owner`, `asker_grant` and
+> `rung`, and the harness sees only the answers, not the seeding: an app
+> could map a "removed owner" to an ownerless item, or to a person who was
+> never a member, and pass without implementing either reading. Revision
+> 11 said the fixture case "holds every app to it"; it did not. The rule,
+> once ruled, needs an app-side test that removes a real member from a
+> real roster and asks again.
+
**Never cached, at any scope.** Not per session, not per page, not for
the life of a warm process. Caching authorization is what makes a stale
answer a leak (memoria §6.5), and the usability pressure to cache within
@@ -749,8 +882,8 @@ spec, which owns them, and are cited here for completeness of direction.
| 1–6 | person → home, instance → home | session; consumer token | — | Home §9. Unchanged. |
| 7 activity | home → instance | **assertion** for the person, `aud` = instance | who the front door is for | `design-activity-pull` §4–5 owns the wire shape. The home renders and holds rendered output only, under two ages (§4.3). Not in the contract module yet — §12 step 2 is S1, S2 and S3. When it arrives, the fixtures **cite** that spec's gates 10–20 rather than restate them, or this contract rebuilds §2's drift one layer down. |
| 8 roster | instance → home | consumer token | which instance asks | §5.3. Scoped to the caller's team. Paged; the copy has a TTL. |
-| S1 change feed | sibling → sibling | consumer token | same-team sibling | `(item_id, revision, gone, touched_at)`. No title, no content, no visibility flag. Per-consumer TTL; past it, full re-announce. |
-| S2 authorization | sibling → sibling | consumer token **+ named asker** | same-team sibling, asking for a person | Four values, total decoder, cap 256 pairs. **Never cached**: a passage crosses no request boundary without an S2 `VISIBLE` in the request that carried it (memoria §8.4, gate 26). Asker is a typed subject (§3); the answer is the app's own read check for that person — team rung, ownership, a live grant, never a link — with no custody intersection since revision 10 (§4.3). |
+| S1 change feed | sibling → sibling | consumer token | same-team sibling | `(item_id, revision, gone, touched_at)`. No title, no content, no visibility flag. Per-consumer TTL; past it, ~~full re-announce~~ the cursor is reset *(revision 11, answering Fable's review of 0a59e7d, M2: one start-over mechanism, not two)*. A cursor the producer's log does not recognise — restored, foreign, or expired or compacted past the TTL — is `409 {"code":"CURSOR_RESET"}` and nothing else; the consumer hides what it holds from that producer and reads from the beginning, at most one reset per re-read (§6.6, revision 11). |
+| S2 authorization | sibling → sibling | consumer token **+ named asker** | same-team sibling, asking for a person | Four values, total decoder, cap 256 pairs. **Never cached**: a passage crosses no request boundary without an S2 `VISIBLE` in the request that carried it (memoria §8.4, gate 26). Asker is a typed subject (§3); the answer is the app's own read check for that person — team rung, ownership, a live grant, never a link — with no custody intersection since revision 10 (§4.3). For a person removed from the team, gate 5's reading (§11) stands until Paul rules (§14): holding no other grant, `NOT_VISIBLE`; whether ownership or an individual grant survives removal is open, and revision 11's "reaches nothing" is a proposal, not this row. An id the app does not know is `NOT_VISIBLE`; a revision its log does not hold is `UNKNOWN` (§6.6). |
| S3 content | sibling → sibling | consumer token | same-team sibling | `(id, revision)`, **no person**. Every live item at its current revision since revision 10 (team-visible only before it); one identical 404 for deleted, unknown or superseded. Never 403. |
| S6 aggregate | sibling → Sheets | consumer token + named asker | as S2 | Enumerated function over cell refs, never expression text. Cap 64. Typed subject and the app's own read check, as S2 (no custody intersection since revision 10). |
| S8 write-as-self | sibling → sibling | consumer token | same-team sibling | §7.2. Into the caller's designated area only; only items the caller authored. |
@@ -788,20 +921,33 @@ implying one exists.
**S4 and S5 are not calls, and no number is reserved for them.** memoria
§6.1 resolved S4, the tombstone, into a feed row — `gone` covers deletion
-and departure from team-visibility indistinguishably — and S5, consumer
-expiry, into the per-consumer TTL, since expiry is the decommission verb.
+and departure from team-visibility indistinguishably *(superseded by
+revision 10, Paul, 2026-11-01: `gone` means deleted and nothing else; a
+move down the ladder is not a departure from custody, and S2 rules on it.
+Marked in revision 11, which found it unmarked)* — and S5, consumer
+expiry, into the per-consumer TTL, since expiry is the decommission verb
+*(what follows expiry changed in revision 11, answering Fable's review of
+0a59e7d, M2: a consumer coming back past its TTL is answered §6.6's
+`CURSOR_RESET`, not a "full re-announce", which was a second start-over
+mechanism nobody specified)*.
Both are settled; they are recorded here because a table that runs S1, S2,
S3, S6, S8 leaves two holes, and a hole in a numbered contract is somewhere
a later call falls. *(Review pass, 2026-09-05.)*
### 6.5 The producer half (revision 10)
+*Decisions in this section: this session, 2026-11-01, reviewed by GPT-6
+("Astra", APPROVE on 983114a); the revision-11 additions are this session's,
+answering Fable's review of c38e3ad, reviewed by Fable 5.1 (APPROVE on
+640d058).*
+
`amadan.net/oficina/suite/server` is the server half §6 names, built with
the first two apps that serve it (Docs and Fichas). An app implements one
interface, `Producer` — `Feed(cursor, limit)`, `Rule(asker, pairs)`,
`Content(item, revision)` — and mounts `server.Handler` beside its router.
-The package owns everything an app could get subtly wrong and must not get
-differently from its neighbour:
+**`Handler` is the only thing an app mounts.** The package owns everything
+an app could get subtly wrong and must not get differently from its
+neighbour:
- **The bearer check.** `<APP>_SUITE_CONSUMERS` is strict JSON,
`[{"consumer_id":"memoria","tokens":[{"epoch":1,"sha256":"<hex>"}]}]`,
@@ -812,21 +958,171 @@ differently from its neighbour:
- **S1.** `rows` is never null; a producer's empty cursor is a 500, and a
failed read a 503, never an empty page. At the tip the producer returns
the cursor it was given and no rows, which is what stops memoria's poll.
- 256 rows a page.
+ 256 rows a page. A row at revision under 1 is a 500 (revision 11). A
+ producer returns `server.ErrCursorReset` for a cursor its log does not
+ recognise and the package writes §6.6's fixed 409; a reset of the
+ beginning, `""`, is a 500, because it would loop a consumer for ever.
- **S2.** The request is decoded strictly (no unknown fields, no trailing
document), the asker through `NewSubject`, the batch through
- `CheckS2Batch`; anything else is a 400. A producer error is a 503, which
- the consumer reads as `UNKNOWN` for the whole call; an answer count that
- differs from the pair count is a 500. Every pair is echoed.
+ `CheckS2Batch`, and a pair at revision under 1 is refused as S3 refuses
+ one (revision 11); anything else is a 400. A producer error is a 503,
+ which the consumer reads as `UNKNOWN` for the whole call; an answer count
+ that differs from the pair count is a 500. Every pair is echoed, and a
+ row is `(item_id, revision, result)` and nothing else — the consumer's
+ decoder refuses the whole answer otherwise (revision 11).
- **S3.** One refusal — an empty 404 — for a deleted item, an id that
never existed, a revision that is not current, missing or malformed, and
a body over 2 MiB (memoria refuses more than 2 MiB + 64 KiB and would
otherwise retry the same feed page for ever). Never 403. A 200 is
- `text/plain`.
-
-`server.Routes` is the same routes without the bearer check, for the
-conformance harness, which drives a handler with no token. An app never
-mounts it. The package keeps the module's rule: standard library only.
+ `text/plain`. S3 is a GET; any other method is not served.
+- **Every response** — each 200, each refusal, the 401 and the router's own
+ 404 and 405 — carries `Cache-Control: no-store` and `Vary:
+ Authorization` (revision 11). An S2 answer is one person's and an S3 body
+ may be a private item's; a cache between two apps that kept either would
+ serve it to the next request, which is leak-list item 11's failure on a
+ sibling call. Refusals stay byte-identical to each other with the headers
+ on, because every one carries the same two.
+
+**Testing it: `conformance.RunProducer(t, producer, kind)`** (revision 11).
+It mounts the producer through `Handler` exactly as the app does, mints a
+token for itself, requires the 401 without it, and runs the whole harness
+through it — so what is tested is what is served. `server.Routes`, the
+routes with no bearer check, existed for the harness to drive and is
+**deprecated**: mounted, it serves every live item, private ones included,
+to anybody who can reach the app. It stays because the module is additive
+(AGENTS.md) and Docs' and Fichas' tests call it; both move to
+`RunProducer`, and nothing new may call `Routes`. Rejected: removing it
+(a removed exported name is a new major version, and two branches use it
+today); renaming it to something that sounds dangerous (a new exported
+footgun with a scarier name is still a footgun, and the harness no longer
+needs one at all). The package keeps the module's rule: standard library
+only.
+
+**Its reach, said plainly** *(answering Fable's review of 0a59e7d, L6 and
+M3)*: it tests `Handler` and the `Producer` behind it and nothing in front
+— an app's own router, proxy, cache or session middleware is not in the
+request path and is not covered. And it tests the answers of a world the
+app seeded from the fixture, not the seeding: an app that maps a case's
+`owner` or `asker_grant` wrongly can pass. Its unauthenticated probe goes
+through the same header audit as every other request.
+
+### 6.6 Revisions and cursors survive a restore (revision 11)
+
+*This session, 2026-11-01, answering Fable's review of c38e3ad (H1). Found
+by both producers: Fichas `main` c837d28 and Docs `feat/suite-producer`.
+Amended 2026-11-02 by this session, answering Fable's review of 0a59e7d (M1,
+M2, L1 to L4); reviewed by Fable 5.1, APPROVE on 640d058.*
+
+**A revision names one byte sequence for ever.** Once a producer has
+issued `(item, revision)`, that pair names those bytes and no others, for
+the life of the item — across a restart, a migration and a restore from a
+backup. A producer whose revisions can be reissued is **not conformant**:
+a counter, or a clock, rolls back with a restored database and hands the
+same numbers out again to different text. The consumer then holds an old
+`(item, 7)` that the app's log also calls 7, S2 answers `VISIBLE`, and a
+passage the item no longer contains — a private one, since revision 10 —
+is shown as current. That is the leak both producers found in themselves.
+
+So, normatively:
+
+- A revision is **unique per item for ever**. The recommended shape is the
+ one both producers chose: a random positive int63 drawn per change, and
+ drawn again on a collision with **any revision the log holds for that
+ item**, not only the current one — a draw equal to a prior revision gives
+ an old name to new bytes, which is the reissue this section forbids
+ *(revision 11 said "the current one"; corrected answering Fable's review
+ of 0a59e7d, L4)*. It has no order, and nothing may compare two revisions
+ by size.
+- **`STALE` comes from the producer's own log**: the asked revision is one
+ the log holds for that item, and it is not the current one.
+- **A revision the log does not hold is `UNKNOWN` on S2** for a person who
+ may open the item (`NOT_VISIBLE` for one who may not — the person is
+ checked before the revision), **and the refusal on S3**: the same
+ byte-identical 404 as a deleted item. After a restore, everything the
+ consumer holds that the restored log never issued is therefore withheld
+ loudly and re-fetched, never shown.
+- The fixture names, per case, a `prior_revision` (held, not current) and
+ an `unknown_revision` (never issued), and the harness asks about both
+ rather than computing "one behind". Some cases put the unknown revision
+ *below* the current one and the rest above it, among the cases the asker
+ may open, so a producer still comparing numbers fails and so does one
+ answering `STALE` for anything not current; the module's own tests hold
+ the fixture to having both *(revision 11 said "most" sat below; it was
+ four of ten, and is three of nine since `doc-owner-left` was withdrawn —
+ Fable's review of 0a59e7d, L3)*.
+
+**A cursor carries the identity of the log that issued it.** A cursor that
+is only a position is reissued by a restore exactly as a counted revision
+is: the restored log reaches the same position with different events, and
+the consumer continues silently from the wrong place. Both producers stamp
+each cursor with a random value written alongside the event it names, and
+check it on every request.
+
+**The stamp rule is normative** *(answering Fable's review of 0a59e7d,
+L2)*. A cursor's stamp is either **drawn at random per event and written
+with that event**, so a restored log holds only the stamps of the events it
+actually has; or **minted when the log is restored and never itself
+restored from a backup**, so a restore always changes it. A generation id
+kept in the same restorable database as the log is **not sufficient**: the
+restore brings the old generation back with the old events, and the
+cursors it issued before still match a log that has since diverged.
+
+**A cursor the log does not recognise** — the log was restored, or the
+cursor was issued by some other log, or it does not parse, or it names a
+position the producer has expired or compacted away (a consumer back past
+its per-consumer TTL, §6) — is answered
+with **status 409 and exactly the body `{"code":"CURSOR_RESET"}`**: no
+other field, no position, no count, no reason. It is never answered as the
+tip (which leaves a consumer holding a dead log's items for ever) and never
+as a generic 5xx (which stalls it for ever, as Docs' and Fichas' 503 and
+manual reset did). It means: *your cursor names no position in my log;
+set aside everything you hold from me and read from the beginning.* It is the
+**one** way a producer tells a consumer to start over: an expired cursor is
+answered with it too, and there is no separate "full re-announce" *(§6's S1
+row said there was; answering Fable's review of 0a59e7d, M2)*. The
+beginning, `""`, is never reset. The module carries it as
+`suite.CursorResetStatus`, `suite.CursorResetBody`, `suite.ErrCursorReset`
+(what `DecodeS1` returns for exactly that answer, and for nothing else —
+any other 409 is a plain failure, because a reset destroys a consumer's
+whole copy), and `server.ErrCursorReset` (what a producer's `Feed` returns
+for the package to write it).
+
+**The consumer's half, binding.** On `ErrCursorReset` a consumer:
+
+1. **soft-drops** every item it holds from that producer — the text,
+ every passage, embedding and derived artefact built from it: each is
+ hidden from **every** surface and marked *pending*, and its cursor for
+ that producer is discarded — before it reads anything else from it;
+2. reads S1 again from `""` to the tip, ingesting as it would a new
+ producer; an item the re-read lists is re-fetched, and a pending copy
+ may be replaced or reused only where the re-read names the same
+ `(item, revision)` (the first rule of this section makes that the same
+ bytes);
+3. when the re-read reaches the tip, **hard-retires** every item still
+ pending — every item absent from that complete re-read — and deletes
+ it, so an item the restored log no longer has cannot survive in the
+ consumer because nothing told it to leave.
+
+*(Revision 11's step 1 "dropped every item", which left step 3 nothing to
+retire; corrected answering Fable's review of 0a59e7d, L1.)* Step 1 comes
+first because steps 2 and 3 can fail part-way; a consumer that re-read
+before hiding could be left serving a mix of two logs. Until the re-read
+reaches the tip, the consumer names that producer's items nowhere and says
+the app is being re-read — the loud withholding §4.3 requires, not a
+silently shorter answer.
+
+**At most one reset per re-read** *(answering Fable's review of 0a59e7d,
+M1)*. A second `CURSOR_RESET` from the same producer **before the re-read
+reaches the tip** is a **failure** of that producer, not another reset: the
+consumer abandons that re-read rather than starting over at once, treats
+the producer as unavailable (§6.3) and says so to people by naming the app,
+and keeps everything it held from that producer **pending and withheld
+from every answer** until a later re-read completes — fail closed, never
+back to showing the pre-reset copy. Every re-read, the first after a reset
+and any after such a failure, waits on the consumer's ordinary backoff for
+that producer, so a producer that resets every request costs one read per
+backoff interval and not a loop.
+Leak list item 13 (§9) records what such a producer can still cost.
### 6.1 Why two credentials
@@ -864,8 +1160,14 @@ caching authorization.**
Any hop across a `<team>` label. Any sibling presenting an assertion it
did not receive from the home for its own `aud`. Any write except §7. Any
-item outside the custody predicate. The home in the loop of a sibling
-call. Content leaving the team's hosts except under ruling 6.
+item outside custody — which since revision 10 is every live item, so the
+clause now forbids holding a deleted item, an id the app does not know,
+and any revision but the current one *(reworded in revision 11; it said
+"outside the custody predicate", which revision 10 left meaning nothing)*.
+Any passage shown to a person without an S2 `VISIBLE` for that person in
+the same request. The home in the loop of a sibling call. Content leaving
+the team's hosts except under ruling 6, and private content leaving them
+at all until §14's egress question is answered.
---
@@ -1073,6 +1375,22 @@ Docs rejected, differing only in the three properties the second clause
names (discussion 33). Both specs cite this section and delete their own
wording (Appendix A).
+> **Revision 11 (this session, 2026-11-01; Fable's review of c38e3ad, M2):
+> the comparison above was made when the corpus was team-visible items
+> only.** Since revision 10 a consumer holds private and individually
+> granted items too, so "whole-corpus egress" now includes documents only
+> their owner may open. Nobody has ruled on sending those to a model
+> provider. Paul ruled on 2026-09-19 that TensorX is zero-data-retention
+> and is treated as local — that ruling is context, and it answers a
+> retention question, not whether private documents may leave the team's
+> hosts for embedding. **Until Paul rules (§14), a consumer embeds no
+> private or individually granted item, and sends a model provider only
+> passages already ruled `VISIBLE` by S2 for the person asking in the same
+> request** — which memoria's AI answer already does. A private item is
+> then held and searchable by its own words, and absent from semantic
+> recall, and the consumer says so rather than pretending the recall is
+> complete.
+
---
## 9. The suite leak list
@@ -1096,13 +1414,17 @@ apps are a suite, and every one is a consequence of ruling 1 or 4.
granted, or link-only (§4.2) — and an honest consumer retires what
leaves; a compromised one retires nothing, and no revocation reaches a
copy it already holds (ruling 14).
-2. **A compromised sibling can name any asker on S2**, and so learn which
- items a given member may open — private ones included, since revision
- 10 removed the intersection (Paul, 2026-11-01). Bounded by item 1 as
- revision 10 states it: it already holds every live item, so what S2
- adds is who may open each, which a compromised holder of the items and
- the roster could largely infer anyway. *Revision 9 bounded this by the
- custody intersection; that bound no longer exists.*
+2. **A sibling's consumer token reads the team's grant graph.** It can
+ name any asker on S2, so whoever holds the token — a compromised
+ sibling, or anybody who lifts the token from its config — learns, for
+ every member and every live item, who may open what: who owns which
+ private document, who was granted which, and who was not. Since
+ revision 10 (Paul, 2026-11-01) that includes every private item. It is
+ not bounded by item 1 and not "largely inferable" from the items
+ *(revision 10 said "could largely infer anyway"; revision 11, answering
+ Fable's review of c38e3ad, M6, says it plainly)*: the text of a document
+ rarely says who it was shared with, and S2 does. *Revision 9 bounded
+ this by the custody intersection; that bound no longer exists.*
3. **A compromised sibling can write into its own designated area** as
itself (S8). It cannot write as a person or touch a person-authored
item.
@@ -1156,6 +1478,20 @@ apps are a suite, and every one is a consequence of ruling 1 or 4.
URL reads or writes the item, the app cannot name them, and a
forwarded link is a grant nobody recorded. This is what "anyone with
the link" means and there is no version of it that is not this.
+13. **A buggy or hostile producer can force a consumer to drop and re-read
+ it** (§6.6). `CURSOR_RESET` needs no proof that a restore happened, so a
+ sibling that answers it — wrongly, or on purpose, or on every request —
+ makes the consumer hide everything it held from that sibling, read its
+ whole feed again, re-fetch every item and re-embed whatever it embeds
+ (§8). That is an **availability and embedding cost**, not a leak:
+ nothing is shown that
+ was not shown before, a second reset inside one re-read is a failure
+ that keeps the sibling's items withheld rather than another reset, and
+ re-reads are subject to backoff, so the cost is bounded by the backoff
+ and the size of that sibling's own feed. A compromised sibling can
+ already do worse to its own items (item 1); this records that it can
+ also make a consumer pay for them repeatedly. *(Answering Fable's review
+ of 0a59e7d, M1.)*
---
@@ -1214,11 +1550,42 @@ that cannot be written as stated is a spec bug.
`VISIBLE` for the team rung, the owner and a live grantee; `NOT_VISIBLE`
for a link-only, guest-only or moved-to-private item the asker neither
owns nor holds a grant on, for a deleted one, and for a stranger at any
- revision; `STALE` one revision behind and `UNKNOWN` one ahead for a
- person who may open it. S1 carries every live item at its current
+ revision; ~~`STALE` one revision behind and `UNKNOWN` one ahead~~ for a
+ person who may open it *(superseded by the revision-11 paragraph below:
+ `STALE` at the case's `prior_revision` and `UNKNOWN` at its
+ `unknown_revision`, never a computed ±1 — marked answering Fable's
+ review of 0a59e7d, L5)*. S1 carries every live item at its current
revision, and `gone` only for deletion. The paragraph below is revision
9's gate 3, superseded.
+ **Revision 11** (this session, 2026-11-01, answering Fable's review of
+ c38e3ad) adds, all in the harness: S2 is asked at each case's
+ `prior_revision` (`STALE` for who may open it) and `unknown_revision`
+ (`UNKNOWN` for who may open it, `NOT_VISIBLE` for who may not), never at
+ a computed ±1 (§6.6); S3 refuses both with the baseline 404. S2 about
+ `NonexistentItemID`, for the asker and for the stranger, is
+ `NOT_VISIBLE` — a producer that fails open, `VISIBLE` for an id it
+ cannot find, passes every case that exists and fails here. S3 with no
+ revision, a malformed one or revision 0 is the baseline refusal, and S3
+ does not serve a POST. An S2 row with any field beyond `item_id`,
+ `revision` and `result` fails the whole call. S1 at a cursor the log
+ never issued (`NeverIssuedCursor`) is `409 {"code":"CURSOR_RESET"}`.
+ Every response carries `Cache-Control: no-store` and `Vary:
+ Authorization`, the unauthenticated 401 included. An app on
+ `suite/server` runs it as `conformance.RunProducer` (§6.5).
+
+ *Withdrawn 2026-11-02 (answering Fable's review of 0a59e7d, H1):*
+ revision 11 also added a case, `doc-owner-left` — private, owned by the
+ stranger, `NOT_VISIBLE` to everybody — on §4.3's proposal that no team
+ standing reaches nothing, ownership included. Paul has not ruled, and
+ the case contradicted gate 5's reading below. It is out of the fixture
+ until he rules (§14). **What the harness does not hold an app to,**
+ said plainly: it sees the answers of a world the app seeded from the
+ fixture's `owner`, `asker_grant` and `rung`, and not the seeding, so
+ whatever Paul rules about a removed owner needs a test in the app that
+ removes a real member and asks again; and it drives `Handler` alone, so
+ middleware in front of it is the app's to test (§6.5).
+
*Revision 9:* **Custody, one fixture per rung.** S3 answers 200 for a `team` item and
404 for `private`, `granted`, guest-only, **link-shared-but-not-team**
(ruling 15) and deleted. The status and body are identical for "not
@@ -1237,6 +1604,21 @@ that cannot be written as stated is a spec bug.
citations, the document page, every list, a delete or report path —
shows the first and never the second, and withholds loudly when the
sibling does not answer. memoria's is `TestEverySurfaceAsksTheAppOfRecord`.
+
+ **Never cached, tested (revision 11; Fable's review of c38e3ad, H3).**
+ Seeding two documents shows a surface asks; it does not show the
+ surface asks *again*. So the gate also: seeds a document the sibling
+ answers `VISIBLE`, renders every surface above for that person and
+ asserts it shows; **flips the sibling's answer for that item to
+ `NOT_VISIBLE`** with nothing else changed — no feed row, no restart, no
+ cache cleared — and asserts that the **next request on every surface**
+ hides it, the AI answer and its citations included; then flips it to
+ `UNKNOWN` and asserts every surface **withholds loudly and names the
+ app** rather than hiding silently or showing the earlier answer. A
+ surface that still shows the item after the flip has cached an
+ authorization answer, which §4.3 forbids at any scope. Writing it is
+ memoria's; the doctrine makes it binding, and a consumer may not ingest
+ a private item until it passes.
4. **No cross-team dial.** Zero connections to a host whose `<team>` label
differs — `acme-evil`, `acme.docs.oficina.works.evil` — and zero
*follow-up* connections when an allowed host answers with a redirect to
@@ -1251,7 +1633,11 @@ that cannot be written as stated is a spec bug.
that admits nobody. A **guest fixture** keeps exactly the activity its
own grant reaches: losing team standing does not revoke an
instance-side grant, and asserting an empty list for that person would
- implement a complete-offboarding policy §5.2 has not agreed to. A
+ implement a complete-offboarding policy §5.2 has not agreed to. *(This
+ reading also governs a removed member who owns items or holds an
+ individual grant, until Paul answers §14's question; revision 11's
+ contrary proposal in §4.3 is not ruled. Noted 2026-11-02, answering
+ Fable's review of 0a59e7d, H1.)* A
**failed refresh** past the TTL yields `UNKNOWN`, not `NOT_VISIBLE`,
admits nobody new **and stops serving team standing to an existing
session**. A **home rewound** — both to a lower epoch, and to the same
@@ -1391,6 +1777,40 @@ change to where the list comes from.
## 14. Open
+- **NEEDS PAUL — may private items be sent to the model provider for
+ embeddings?** *(Raised by this session in revision 11, from Fable's
+ review of c38e3ad, M2; not decided here.)* Revision 10 (*"Hold private
+ too, check per person"*) put every private and individually granted item
+ in a consumer's corpus, and §8 compares memoria's embedding ingest to
+ "whole-corpus egress" — a comparison made when the corpus was team items
+ only. Context, not an answer: Paul ruled on 2026-09-19 that TensorX is
+ zero-data-retention and treated as local, which settles what the
+ provider keeps and not whether a person's private document may leave the
+ team's hosts to be embedded. The choices: embed private items too (full
+ semantic recall over one's own private documents; private text leaves
+ the hosts); embed team items only (private items found by their words
+ alone, and the consumer says so); or embed nothing until a local model
+ exists. **Until he rules, §8's interim rule holds**: nothing private is
+ embedded, and only passages S2 has ruled `VISIBLE` for the asker in the
+ same request reach a model.
+- **NEEDS PAUL — does a person removed from the team keep S2 access to
+ items they own or were individually granted (gate 5's reading, Docs
+ today), or reach nothing (the revision-11 proposal)?** *(Raised by this
+ session, 2026-11-02, answering Fable's review of 0a59e7d, H1; not decided
+ here.)* Gate 5 (§11) reads that losing team standing does not revoke an
+ instance-side grant, because the opposite is a complete-offboarding
+ policy §5.2 has not agreed to; §6's S2 row says the answer is the app's
+ own read check — team rung, ownership, a live grant. Revision 11's §4.3
+ proposed instead that a person off the roster reaches nothing through a
+ consumer, ownership included, since a consumer serves the team's members
+ and the app of record can still serve the person by its own rules. The
+ two disagree only for a removed member who owns items or holds an
+ individual grant. **Until he rules, gate 5's reading holds**, and the
+ fixture asks nothing about the case: `doc-owner-left` (private, owner
+ `"stranger"`, revisions 12 / 11 / 10, `NOT_VISIBLE` to everybody) is
+ withdrawn from `custody.json` and goes back, with whichever answers he
+ rules, together with an app-side test that removes a real member, since
+ the harness cannot see how an app seeds an owner (§4.3).
- **A third review pass, on revision 3.** Two models have read this and
the second returned *request changes*; revision 3 answers all sixteen of
its findings and adds four rulings, so what needs reading now is
@@ -1527,6 +1947,21 @@ S1 to S3 and S8 **wherever sibling consumer tokens are configured**."*
> a `team` rung for documents, the default for new ones and not for
> existing ones (*"New docs Team, old private"*). Docs implements the
> producer through `suite/server` (§6.5).
+>
+> **Revision 11 (this session, 2026-11-01)**: Docs' random revisions and
+> stamped cursors are §6.6's recommended shape, now normative. An
+> unrecognised cursor returns `server.ErrCursorReset` (the 409), not the
+> 503 and manual reset; the conformance tests move from `server.Routes` to
+> `conformance.RunProducer`; ~~the seeding adds `doc-owner-left`, owned by
+> the stranger, and~~ the seeding reads `prior_revision` from the fixture.
+> Fichas, which has no appendix here, adopts the same. *(`doc-owner-left`
+> was withdrawn 2026-11-02, answering Fable's review of 0a59e7d, H1: Paul
+> has not ruled what a removed owner keeps, §14. Docs answers today by
+> gate 5's reading — a removed member keeps what they own or were granted
+> — as that review records, and that stands until he rules. A Docs branch
+> that seeded the case drops it. And §6.6's stamp rule is now normative:
+> a cursor stamp drawn per event, or minted at restore and never restored;
+> a generation id in the restorable database is not enough.)*
The sibling switch is independent of shape (suite §3): §12 steps 2 and 3
have Docs and Sheets serving lone peers before the home exists, so "in
suite shape" would forbid the sequencing this document depends on.
@@ -1615,6 +2050,25 @@ removed the asker rather than adding one.
> document page, so they are ruled there). A surface that names a document
> without asking is the leak revision 10 moved the risk into. memoria
> §8.13 records the surfaces and their gate.
+>
+> **Revision 11 (this session, 2026-11-01) adds three.** On
+> `suite.ErrCursorReset` from a sibling's S1, memoria follows §6.6's three
+> steps — hide everything held from that app on every surface and mark it
+> pending, drop its cursor, re-read from `""`, hard-retire whatever the
+> complete re-read did not list — and withholds that app's items loudly
+> until the re-read reaches the tip; today any S1 error, this one
+> included, leaves the cursor where it is, which is safe but never
+> recovers. **At most one reset per re-read**: a second `CURSOR_RESET`
+> from that app before the re-read reaches the tip is a failure, not
+> another reset — memoria names the app as unavailable and keeps its
+> pending items withheld from every answer until a later re-read completes
+> — and each re-read waits on memoria's backoff for that app (§6.6, §9 item
+> 13; amended 2026-11-02, answering Fable's review of 0a59e7d, M1 and L1).
+> Gate 3c's flip case (§11) is memoria's to write.
+> And until Paul answers §14's egress question, memoria embeds no private
+> or individually granted item. `DecodeS2` now refuses a result row with
+> any field beyond the three; memoria's own fakes emit exactly the three,
+> so nothing in memoria changes for it.
§4.1: intersect S2's answer with the custody predicate (suite §4.3), and
type the asker subject (suite §3). The grants join as §4.1 states it —
diff --git a/fixtures.go b/fixtures.go
index 82b4bca..8df22a3 100644
--- a/fixtures.go
+++ b/fixtures.go
@@ -28,7 +28,9 @@ type S2Request struct {
// Rung is where an item sits on the sharing ladder (§4.2, ruling 15). A link
// is not a rung; it is a read-only capability that any rung may carry, and
-// custody keys on the rung alone.
+// who may open an item keys on the rung (with ownership and grants), never
+// on the link. Since revision 10 the rung no longer bounds what a consumer
+// holds; it decides S2.
type Rung string
const (
@@ -49,9 +51,18 @@ type CustodyCase struct {
Rung Rung `json:"rung"`
Link string `json:"link"`
// Owner is "asker" when the fixture's asker owns the item and "other"
- // when somebody else does; AskerGrant is whether the asker holds a live
+ // when another member does. AskerGrant is whether the asker holds a live
// individual grant on it. Together with Rung they are what an app seeds
- // so its own read check produces the S2 answers below (revision 10).
+ // so its own read check produces the S2 answers below (revision 10). The
+ // harness cannot see how an app mapped them while seeding, so a case
+ // seeded wrongly can pass; what an owner keeps is held to the app's own
+ // tests as much as to this fixture.
+ //
+ // Revision 11 added a third value, "stranger" (an owner who has since
+ // lost team standing, case doc-owner-left). That case was withdrawn on
+ // 2026-11-02, answering Fable's review of 0a59e7d (H1): Paul has not
+ // ruled whether such a person keeps their own items, and gate 5 reads
+ // that they do (doctrine §14). No binding case uses "stranger".
Owner string `json:"owner"`
AskerGrant bool `json:"asker_grant"`
S3Status int `json:"s3_status"`
@@ -61,13 +72,33 @@ type CustodyCase struct {
// body, or return a 200 carrying a different item entirely.
S3Body string `json:"s3_body"`
S2Result Authorization `json:"s2_result"`
- // S2ResultSuperseded is the answer when the same item is asked about one
- // revision behind. A team item is STALE — readable, but the app of record
- // has moved on — and anything custody already refuses stays refused.
+ // PriorRevision is a revision the item's log holds that is not its
+ // current one: an app seeds its log with it before Revision. It is
+ // Revision - 1 in every case, so an app that seeded "one behind" before
+ // revision 11 seeds the same log, but the harness reads it from here and
+ // never computes it — a revision is a name, and a producer whose
+ // revisions are random has no "one behind" (doctrine §6.6, revision 11).
+ PriorRevision int64 `json:"prior_revision"`
+ // UnknownRevision is a revision the item's log never issued. Some cases
+ // put it BELOW Revision and away from PriorRevision, so a producer that
+ // decides STALE by comparing numbers — the counter's habit, which is
+ // what a restore turns into a leak — answers STALE where it owes
+ // UNKNOWN; the rest put it above, so one that says STALE for anything
+ // not current fails too. (Revision 11 said "most" are below; it was
+ // four of ten, and is three of nine since doc-owner-left was withdrawn.
+ // TestCustodyFixtureUnknownRevisionsBothSides holds the fixture to
+ // having both among the cases the asker may open.) An app must never
+ // issue it while seeding.
+ UnknownRevision int64 `json:"unknown_revision"`
+ // S2ResultSuperseded is the answer at PriorRevision: STALE for a person
+ // who may open the item — readable, but the app of record has moved on —
+ // and NOT_VISIBLE for one who may not. (The name is revision 9's; the
+ // module is additive.)
S2ResultSuperseded Authorization `json:"s2_result_superseded"`
- // S2ResultAhead is the answer one revision ahead of the app's own: a
- // revision its log does not recognise. UNKNOWN for a person who may open
- // the item (§4.3), NOT_VISIBLE for one who may not.
+ // S2ResultAhead is the answer at UnknownRevision, a revision the log
+ // does not hold: UNKNOWN for a person who may open the item (§4.3),
+ // NOT_VISIBLE for one who may not. (Named when the harness asked one
+ // revision ahead; since revision 11 it asks at UnknownRevision.)
S2ResultAhead Authorization `json:"s2_result_ahead"`
// S2ResultStranger is the answer for a person with no team standing.
S2ResultStranger Authorization `json:"s2_result_stranger"`
@@ -75,17 +106,28 @@ type CustodyCase struct {
// NonexistentItemID is never in the fixture. A refusal for an item that does
// not exist has to be byte-for-byte the refusal for one that was deleted, so
-// a consumer cannot tell a deletion from an id it made up. (Before revision
-// 10 the same held for every item that was not team-visible.)
+// a consumer cannot tell a deletion from an id it made up, and S2 answers it
+// NOT_VISIBLE for everybody — never VISIBLE, which is a producer failing
+// open (revision 11). (Before revision 10 the S3 rule held for every item
+// that was not team-visible.)
const NonexistentItemID = "doc-no-such-item-ever"
-// CustodyFixture is gate 3's world: one case per rung, plus team-plus-link and
-// the after-ingest transitions the reviews asked for.
+// NeverIssuedCursor is a cursor no producer issued. S1 answers it with the
+// cursor reset (CursorResetStatus, CursorResetBody), never as the tip and
+// never as a failure (doctrine §6.6, revision 11). A producer must not issue
+// it.
+const NeverIssuedCursor = "suite-conformance-cursor-never-issued"
+
+// CustodyFixture is gate 3's world: one case per rung, plus team-plus-link
+// and the after-ingest transitions the reviews asked for.
type CustodyFixture struct {
Team string `json:"team"`
Asker Subject `json:"asker"`
- // Stranger has no team standing. Every case refuses them, the team-visible
- // ones included: team standing is what makes a team item readable.
+ // Stranger has no team standing, owns nothing in the fixture and holds
+ // no grant on any of it, so every case refuses them, the team rung
+ // included. Whether a person removed from the team keeps items they own
+ // or were individually granted is NOT ruled (doctrine §14, NEEDS PAUL);
+ // the fixture asks nothing about it.
Stranger Subject `json:"stranger"`
Cases []CustodyCase `json:"cases"`
}
@@ -96,6 +138,10 @@ func LoadCustodyFixture() (CustodyFixture, error) {
if err != nil {
return CustodyFixture{}, fmt.Errorf("suite: reading custody fixture: %w", err)
}
+ return parseCustodyFixture(raw)
+}
+
+func parseCustodyFixture(raw []byte) (CustodyFixture, error) {
var f CustodyFixture
if err := json.Unmarshal(raw, &f); err != nil {
return CustodyFixture{}, fmt.Errorf("suite: parsing custody fixture: %w", err)
@@ -103,5 +149,14 @@ func LoadCustodyFixture() (CustodyFixture, error) {
if len(f.Cases) == 0 {
return CustodyFixture{}, fmt.Errorf("suite: custody fixture has no cases")
}
+ for _, c := range f.Cases {
+ // Three distinct names, each one S2 and S3 would accept: a fixture
+ // whose prior or unknown revision is the current one, or under 1,
+ // asks nothing it claims to ask.
+ if c.Revision < 1 || c.PriorRevision < 1 || c.UnknownRevision < 1 ||
+ c.PriorRevision == c.Revision || c.UnknownRevision == c.Revision || c.UnknownRevision == c.PriorRevision {
+ return CustodyFixture{}, fmt.Errorf("suite: custody case %s: revisions %d, %d, %d are not three distinct revisions of 1 or more", c.ItemID, c.Revision, c.PriorRevision, c.UnknownRevision)
+ }
+ }
return f, nil
}
diff --git a/fixtures/custody.json b/fixtures/custody.json
index 1ec285e..71fe641 100644
--- a/fixtures/custody.json
+++ b/fixtures/custody.json
@@ -9,8 +9,8 @@
"team-visible ones. A consumer holds private and granted items too, and",
"S2 decides per person, from the app's own read check, with no",
"intersection with custody. So every live item answers S3 200 with its",
- "own bytes; only a deleted item, and one that never existed, answer the",
- "identical 404.",
+ "own bytes at its current revision; a deleted item, one that never",
+ "existed, and any revision that is not current answer the identical 404.",
"",
"The asker is the same person for every case, and the item id is quoted",
"in every case, so a server cannot pass by answering differently for",
@@ -20,10 +20,29 @@
"asker may open the item today; the rung decides that only through the",
"app's own read check.",
"",
- "s2_result_ahead is the answer one revision AHEAD of the app's own: a",
- "revision its log does not recognise is UNKNOWN for a person who may",
- "open the item (§4.3), and NOT_VISIBLE for one who may not — a person",
- "with no right to the item learns nothing about its revisions."
+ "REVISION 11 (this session, 2026-11-01, answering Fable's review of",
+ "c38e3ad): revisions are names, not counts (doctrine §6.6). Each case",
+ "carries prior_revision — a revision its log holds that is not current —",
+ "and unknown_revision — one its log never issued. An app seeds its log",
+ "with prior_revision then revision, and never issues unknown_revision.",
+ "s2_result_superseded is the answer at prior_revision: STALE for a person",
+ "who may open the item, NOT_VISIBLE for one who may not.",
+ "s2_result_ahead is the answer at unknown_revision: UNKNOWN for a person",
+ "who may open the item (§4.3), NOT_VISIBLE for one who may not — a person",
+ "with no right to the item learns nothing about its revisions. Some",
+ "cases put unknown_revision BELOW the current one (doc-team, doc-private",
+ "and doc-team-link among those the asker may open) and the rest above,",
+ "so a producer comparing numbers (the counter's habit) says STALE where",
+ "it owes UNKNOWN, and one saying STALE for anything not current fails",
+ "too. Both S3 revisions are refused with the identical 404.",
+ "",
+ "WITHDRAWN 2026-11-02 (answering Fable's review of 0a59e7d, H1): the",
+ "case doc-owner-left — private, owned by a member who has since lost",
+ "team standing, NOT_VISIBLE to everybody — was revision 11's proposal",
+ "and Paul has not ruled on it. It contradicted gate 5's reading (a",
+ "removed member keeps what their own grant reaches). It is out of the",
+ "binding cases until he rules (doctrine §14, NEEDS PAUL). The stranger",
+ "below owns nothing in this fixture and holds no grant on any of it."
],
"team": "acme",
"asker": {
@@ -40,6 +59,8 @@
"item_id": "doc-team",
"s3_body": "the Q3 plan, shared with the whole team",
"revision": 7,
+ "prior_revision": 6,
+ "unknown_revision": 5,
"rung": "team",
"link": null,
"owner": "other",
@@ -55,6 +76,8 @@
"item_id": "doc-private",
"s3_body": "my own notes, private to me",
"revision": 4,
+ "prior_revision": 3,
+ "unknown_revision": 2,
"rung": "private",
"link": null,
"owner": "asker",
@@ -70,6 +93,8 @@
"item_id": "doc-granted",
"s3_body": "the board pack, shared with me by name",
"revision": 9,
+ "prior_revision": 8,
+ "unknown_revision": 10,
"rung": "granted",
"link": null,
"owner": "other",
@@ -85,6 +110,8 @@
"item_id": "doc-guest",
"s3_body": "the contractor brief, shared with a guest only",
"revision": 2,
+ "prior_revision": 1,
+ "unknown_revision": 3,
"rung": "granted",
"link": null,
"owner": "other",
@@ -100,6 +127,8 @@
"item_id": "doc-link",
"s3_body": "the press draft, private with a read link",
"revision": 5,
+ "prior_revision": 4,
+ "unknown_revision": 6,
"rung": "private",
"link": "read",
"owner": "other",
@@ -115,6 +144,8 @@
"item_id": "doc-team-link",
"s3_body": "the launch checklist, team-shared and link-shared",
"revision": 3,
+ "prior_revision": 2,
+ "unknown_revision": 1,
"rung": "team",
"link": "read",
"owner": "other",
@@ -130,6 +161,8 @@
"item_id": "doc-deleted",
"s3_body": "",
"revision": 6,
+ "prior_revision": 5,
+ "unknown_revision": 7,
"rung": "deleted",
"link": null,
"owner": "other",
@@ -145,6 +178,8 @@
"item_id": "doc-was-team",
"s3_body": "the old roadmap, moved back to private",
"revision": 8,
+ "prior_revision": 7,
+ "unknown_revision": 9,
"rung": "private",
"link": null,
"owner": "other",
@@ -160,6 +195,8 @@
"item_id": "doc-link-added-late",
"s3_body": "the hiring plan, private, link added later",
"revision": 11,
+ "prior_revision": 10,
+ "unknown_revision": 12,
"rung": "private",
"link": "read",
"owner": "other",
diff --git a/fixtures_test.go b/fixtures_test.go
index 1af7858..a15d9d5 100644
--- a/fixtures_test.go
+++ b/fixtures_test.go
@@ -61,3 +61,72 @@ func TestHostileHostFixture(t *testing.T) {
}
}
}
+
+// The custody fixture names three distinct revisions per case, each one S2
+// and S3 would accept (revision 11). A case whose prior or unknown revision
+// is its current one would ask the harness's questions of nothing.
+//
+// MUTATION-TESTED 2026-11-01, reverted: the loader's revision check removed
+// → every bad case below accepted.
+func TestCustodyFixtureRevisionsAreDistinct(t *testing.T) {
+ f, err := LoadCustodyFixture()
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, c := range f.Cases {
+ if c.PriorRevision != c.Revision-1 {
+ // Docs and Fichas seed "one behind" before revision 11; keeping
+ // prior at Revision - 1 keeps their seeding correct.
+ t.Errorf("%s: prior_revision %d, want %d", c.ItemID, c.PriorRevision, c.Revision-1)
+ }
+ }
+ for name, rv := range map[string]string{
+ "prior is current": `"revision":7,"prior_revision":7,"unknown_revision":5`,
+ "unknown is current": `"revision":7,"prior_revision":6,"unknown_revision":7`,
+ "unknown is prior": `"revision":7,"prior_revision":6,"unknown_revision":6`,
+ "prior missing": `"revision":7,"unknown_revision":5`,
+ "unknown under 1": `"revision":7,"prior_revision":6,"unknown_revision":0`,
+ } {
+ raw := `{"cases":[{"item_id":"doc-x",` + rv + `}]}`
+ if _, err := parseCustodyFixture([]byte(raw)); err == nil {
+ t.Errorf("%s: accepted", name)
+ }
+ }
+}
+
+// The fixture puts some unknown revisions below the current one and some
+// above, among the cases the asker may open (where the answer is UNKNOWN
+// and a wrong STALE shows). Without a case below, a producer comparing
+// numbers passes; without one above, a producer answering STALE for
+// anything not current passes. Revision 11 claimed "most" sat below, which
+// was never checked and was false (four of ten); this holds the claim the
+// harness actually depends on (Fable's review of 0a59e7d, L3).
+//
+// MUTATION-TESTED 2026-11-02, reverted: doc-granted's unknown_revision moved
+// from 10 to 7 (below its current 9, leaving no openable case above) → "no
+// case the asker may open puts unknown_revision above". doc-team's,
+// doc-private's and doc-team-link's moved above their current revisions
+// (8, 5, 4) → "no case the asker may open puts unknown_revision below".
+func TestCustodyFixtureUnknownRevisionsBothSides(t *testing.T) {
+ f, err := LoadCustodyFixture()
+ if err != nil {
+ t.Fatal(err)
+ }
+ below, above := 0, 0
+ for _, c := range f.Cases {
+ if c.S2ResultAhead != UNKNOWN {
+ continue
+ }
+ if c.UnknownRevision < c.Revision {
+ below++
+ } else {
+ above++
+ }
+ }
+ if below == 0 {
+ t.Error("no case the asker may open puts unknown_revision below the current revision; a producer comparing numbers passes")
+ }
+ if above == 0 {
+ t.Error("no case the asker may open puts unknown_revision above the current revision; a producer answering STALE for anything not current passes")
+ }
+}
diff --git a/mutations.py b/mutations.py
index c9993f2..3b1dbbc 100644
--- a/mutations.py
+++ b/mutations.py
@@ -41,6 +41,18 @@ MUTATIONS = [
"\tif err := rejectAmbiguousJSON(body); err != nil {\n\t\treturn allUnknown(len(asked))\n\t}",
"\tif false {\n\t\treturn allUnknown(len(asked))\n\t}"),
+ ("r11 L6: Decoder.More back as the end-of-input check", "strictjson.go",
+ "\tif _, err := dec.Token(); err != io.EOF {",
+ "\tif _ = io.EOF; dec.More() {"),
+
+ ("r11 M5: S2 result rows may carry fields outside the contract", "s2.go",
+ "\tdec.DisallowUnknownFields()\n\tvar parsed s2Body",
+ "\tvar parsed s2Body"),
+
+ ("r11 H1b: any status carrying the reset body is a reset", "s1.go",
+ "status == CursorResetStatus && bytes.Equal",
+ "true && bytes.Equal"),
+
("9: hostname labels are not validated", "transport.go",
"\t\tif err := validLabel(label); err != nil {",
"\t\tif false {\n\t\t\t_ = label\n\t\tif err := error(nil); err != nil {"),
diff --git a/s1.go b/s1.go
index ba5c3d2..7300b6a 100644
--- a/s1.go
+++ b/s1.go
@@ -3,6 +3,7 @@ package suite
import (
"bytes"
"encoding/json"
+ "errors"
"fmt"
"time"
)
@@ -30,9 +31,37 @@ type Feed struct {
Rows []FeedRow `json:"rows"`
}
+// CursorResetStatus and CursorResetBody are S1's one answer for a cursor the
+// producer's log does not recognise — a log restored from a backup, or a
+// cursor some other log issued (doctrine §6.6, revision 11). 409 because the
+// request conflicts with the producer's state and is not the consumer's
+// syntax error; the body is fixed, with no other field, so it carries no
+// position, no count and nothing about the log.
+const (
+ CursorResetStatus = 409
+ CursorResetBody = `{"code":"CURSOR_RESET"}`
+)
+
+// ErrCursorReset is DecodeS1's answer to exactly CursorResetStatus with
+// exactly CursorResetBody: "your cursor names no position in my log". The
+// consumer hides every item it holds from that producer on every surface
+// and marks it pending, drops its cursor, reads from "" again, and retires
+// as gone whatever that complete re-read does not list (doctrine §6.6). One
+// reset per re-read: a second before the re-read reaches the tip is a
+// failure of that producer, not another reset, and its items stay withheld.
+// Any other 409 is a plain failure,
+// because a reset destroys a consumer's whole copy and must not be read into
+// a body that merely resembles one.
+var ErrCursorReset = errors.New("suite: S1 cursor reset: the producer's log holds no such position")
+
// DecodeS1 reads a change-feed page, refusing anything the contract does not
// allow on the wire.
func DecodeS1(status int, body []byte) (Feed, error) {
+ if status == CursorResetStatus && bytes.Equal(bytes.TrimSpace(body), []byte(CursorResetBody)) {
+ // Whitespace around the object is the only latitude: a trailing
+ // newline is what json.Encoder writes, and it changes no meaning.
+ return Feed{}, ErrCursorReset
+ }
if status < 200 || status > 299 {
// Not an empty feed. An empty feed means "nothing changed", and
// returning that for a failed call advances a consumer's cursor past
diff --git a/s1_test.go b/s1_test.go
index 075b573..8560d65 100644
--- a/s1_test.go
+++ b/s1_test.go
@@ -1,6 +1,9 @@
package suite
-import "testing"
+import (
+ "errors"
+ "testing"
+)
// S1 rows are (item_id, revision, gone, touched_at) and nothing else
// (doctrine §6). Draft 1 of memoria's feed carried a visible-to-team field and
@@ -128,3 +131,60 @@ func TestS1NonSuccessIsAnError(t *testing.T) {
t.Fatal("got nil error for a 503, want a refusal")
}
}
+
+// A cursor the producer's log does not recognise is answered with one fixed
+// 409, and only that exact answer is a reset (doctrine §6.6, revision 11).
+// A reset makes a consumer drop its whole copy of the producer, so a body
+// that merely resembles one — a field more, another code, a second document,
+// the right body under another status — is a plain failure, never a reset.
+//
+// MUTATION-TESTED 2026-11-01, each reverted: the status check removed (any
+// status with the body is a reset) → "the body under 200" and "under 503";
+// the body compared with bytes.Contains instead of equality → "a field
+// more"; the reset check disabled, so a 409 falls to the non-2xx failure →
+// "exact".
+func TestS1CursorReset(t *testing.T) {
+ for name, body := range map[string]string{
+ "exact": `{"code":"CURSOR_RESET"}`,
+ "with json.Encoder's newline": `{"code":"CURSOR_RESET"}` + "\n",
+ } {
+ if _, err := DecodeS1(409, []byte(body)); !errors.Is(err, ErrCursorReset) {
+ t.Errorf("%s: %v, want ErrCursorReset", name, err)
+ }
+ }
+ for name, c := range map[string]struct {
+ status int
+ body string
+ }{
+ "a field more": {409, `{"code":"CURSOR_RESET","at":"c-3"}`},
+ "another code": {409, `{"code":"CURSOR_STALE"}`},
+ "an empty 409": {409, ``},
+ "two documents": {409, `{"code":"CURSOR_RESET"}{}`},
+ "a stray bracket": {409, `{"code":"CURSOR_RESET"}]`},
+ "the body under 200": {200, `{"code":"CURSOR_RESET"}`},
+ "under 503": {503, `{"code":"CURSOR_RESET"}`},
+ } {
+ _, err := DecodeS1(c.status, []byte(c.body))
+ if err == nil || errors.Is(err, ErrCursorReset) {
+ t.Errorf("%s: %v, want a plain failure", name, err)
+ }
+ }
+}
+
+// Trailing content is a real end-of-input check. Decoder.More answers false
+// in front of a stray ']' or '}', so a complete page followed by either was
+// accepted as one document (Fable, review of c38e3ad, L6).
+//
+// MUTATION-TESTED 2026-11-01, reverted: dec.More() restored as the end check
+// in rejectAmbiguousJSON → "]" and "}" accepted.
+func TestS1TrailingDelimiterIsRefused(t *testing.T) {
+ for _, junk := range []string{"]", "}", " ]", "[]", "0"} {
+ body := `{"cursor":"c-1","rows":[]}` + junk
+ if _, err := DecodeS1(200, []byte(body)); err == nil {
+ t.Errorf("accepted %q after a page", junk)
+ }
+ }
+ if _, err := DecodeS1(200, []byte(`{"cursor":"c-1","rows":[]}`+" \n\t")); err != nil {
+ t.Errorf("trailing whitespace is not content: %v", err)
+ }
+}
diff --git a/s2.go b/s2.go
index 0ad865c..fcb24d5 100644
--- a/s2.go
+++ b/s2.go
@@ -1,6 +1,9 @@
package suite
-import "encoding/json"
+import (
+ "bytes"
+ "encoding/json"
+)
// Authorization is what S2 answers for one item, for one named asker.
//
@@ -53,8 +56,14 @@ func DecodeS2(asked []ItemRevision, status int, body []byte) []Authorization {
if err := rejectAmbiguousJSON(body); err != nil {
return allUnknown(len(asked))
}
+ // Strict, as S1 is: a result row is (item_id, revision, result) and
+ // nothing else. A row carrying a title or a passage is a sibling leaking
+ // into a decoder that would otherwise drop the field unseen; it is not an
+ // answer (Fable, review of c38e3ad, M5).
+ dec := json.NewDecoder(bytes.NewReader(body))
+ dec.DisallowUnknownFields()
var parsed s2Body
- if err := json.Unmarshal(body, &parsed); err != nil {
+ if err := dec.Decode(&parsed); err != nil {
return allUnknown(len(asked))
}
diff --git a/s2_test.go b/s2_test.go
index f7c7e04..7ac3ded 100644
--- a/s2_test.go
+++ b/s2_test.go
@@ -223,3 +223,25 @@ func TestS2DecodesAFullBatch(t *testing.T) {
assertResults(t, got, want)
}
+
+// A result row is (item_id, revision, result) and nothing more. A row
+// carrying a title is a sibling leaking an item's name into a decoder that
+// would have dropped the field unseen; it is not an answer, and the whole
+// call is UNKNOWN (Fable, review of c38e3ad, M5).
+//
+// MUTATION-TESTED 2026-11-01, each reverted: DisallowUnknownFields removed
+// → "a title in a row" and "a field beside results"; dec.More() restored
+// as rejectAmbiguousJSON's end check → "a stray brace".
+func TestS2RefusesFieldsOutsideTheContract(t *testing.T) {
+ asked := []ItemRevision{{ItemID: "doc-1", Revision: 7}}
+ for name, body := range map[string]string{
+ "a title in a row": `{"results":[{"item_id":"doc-1","revision":7,"result":"VISIBLE","title":"Q3 plan"}]}`,
+ "a field beside results": `{"results":[{"item_id":"doc-1","revision":7,"result":"VISIBLE"}],"note":"x"}`,
+ "a stray brace": `{"results":[{"item_id":"doc-1","revision":7,"result":"VISIBLE"}]}}`,
+ "a stray bracket": `{"results":[{"item_id":"doc-1","revision":7,"result":"VISIBLE"}]}]`,
+ } {
+ t.Run(name, func(t *testing.T) {
+ assertResults(t, DecodeS2(asked, 200, []byte(body)), []Authorization{UNKNOWN})
+ })
+ }
+}
diff --git a/server/consumers.go b/server/consumers.go
index b4d0899..1dc77ca 100644
--- a/server/consumers.go
+++ b/server/consumers.go
@@ -91,8 +91,11 @@ func TokenHash(token string) string {
// answers every other one with the same empty 401: no token, a malformed
// header, an unknown token and a retired one are indistinguishable. Every
// configured hash is compared, in constant time, whatever matched first.
+//
+// Its 401 carries the same Cache-Control and Vary as every other response
+// of this package (noStore).
func Authenticate(consumers []Consumer, next http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ return noStore(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
tok, ok := bearer(r)
if !ok || tok == "" {
w.WriteHeader(http.StatusUnauthorized)
@@ -115,5 +118,5 @@ func Authenticate(consumers []Consumer, next http.Handler) http.Handler {
return
}
next.ServeHTTP(w, r.WithContext(contextWithConsumer(r.Context(), match)))
- })
+ }))
}
diff --git a/server/server.go b/server/server.go
index 037e8b4..fc5099d 100644
--- a/server/server.go
+++ b/server/server.go
@@ -4,10 +4,13 @@
// is held.
//
// An app implements Producer — its feed, its own per-person read check, and
-// an item's text — and mounts Handler beside its router. Everything the
+// an item's text — and mounts Handler beside its router. Handler is the only
+// thing an app mounts; its conformance test is conformance.RunProducer, which
+// drives Handler through a bearer token it mints for itself. Everything the
// contract fixes and an app could get subtly wrong lives here instead: the
-// bearer check, the strict S2 decode and cap, the wire shapes, and the one
-// byte-identical refusal S3 gives for anything it will not serve.
+// bearer check, the strict S2 decode and cap, the wire shapes, the cache
+// headers on every response, the cursor reset, and the one byte-identical
+// refusal S3 gives for anything it will not serve.
//
// Like the rest of the module it has no dependencies beyond the standard
// library, so an app's pin chain stays one deep (AGENTS.md).
@@ -27,13 +30,39 @@ import (
)
// Producer is an app's half of the contract.
+//
+// Revisions name bytes for ever (doctrine §6.6, revision 11). An (item,
+// revision) a producer has once issued names one byte sequence, and no
+// revision is ever issued twice — not after a restore from a backup either.
+// A counter or a clock is reissued by a restore: an old revision a consumer
+// holds then matches different bytes, and Rule says VISIBLE over text the
+// item no longer has. A producer whose revisions can be reissued is not
+// conformant. Draw them at random (Docs and Fichas use a random positive
+// int63) and redraw on a collision with ANY revision the log holds for the
+// item, not only the current one — a draw equal to a prior revision would
+// give an old name to new bytes. Decide STALE from the producer's own log,
+// never by comparing numbers.
type Producer interface {
// Feed returns the rows after cursor — "" is the beginning — at most
// limit of them, in the app's own log order, and the cursor to ask from
// next. At the tip it returns rows: [] and the SAME cursor it was given
// (a consumer stops polling only when the cursor comes back unchanged
// with no rows; a fresh cursor at the tip makes it page forever). The
- // cursor is opaque and never empty.
+ // cursor is opaque and never empty, and every row's revision is 1 or
+ // more.
+ //
+ // A cursor the producer's log does not recognise — the log was restored
+ // from a backup, another log issued it, or it names a position the log
+ // has since expired or compacted away — is ErrCursorReset, never the tip
+ // and never a failure: this package answers it with S1's one fixed 409,
+ // the one way a consumer is told to start over, and the consumer hides
+ // everything it holds from this producer and reads from "" (§6.6). So a
+ // cursor must carry enough to be recognised: a position alone is
+ // reissued by a restore. Its stamp is normative: either drawn at random
+ // per event and written with that event, or minted when the log is
+ // restored and never itself restored from a backup. A generation id kept
+ // in the same restorable database is not enough — the restore brings the
+ // old generation back with it. "" is never reset.
//
// Since revision 10 the feed carries every live item, private and
// granted ones included; gone means deleted, and nothing else.
@@ -41,18 +70,26 @@ type Producer interface {
// Rule answers, for each pair in order, whether asker may open that item
// now: the app's own read check (team rung, ownership, a live grant;
- // never a link). VISIBLE at the current revision; STALE when the asker
- // may open it and the asked revision is older than current; NOT_VISIBLE
- // when the asker may not, or the item is deleted or unknown; UNKNOWN when
- // the app cannot say (an asker of a kind it does not key on, a revision
- // its log does not recognise, a roster it cannot reach). Never cached.
- // It returns exactly len(pairs) answers.
+ // never a link). For a person removed from the team, doctrine gate 5's
+ // reading stands: one holding no other grant gets NOT_VISIBLE, and losing
+ // team standing does not by itself revoke what they own or were granted
+ // individually. Revision 11 proposed that such a person reach nothing,
+ // ownership included; Paul has not ruled, so that is not the contract
+ // (doctrine §4.3, §14). VISIBLE at the current revision; STALE when
+ // the asker may open it and the asked revision is one the log holds that
+ // is not current; NOT_VISIBLE when the asker may not, or the item is
+ // deleted or an id the app does not know; UNKNOWN when the app cannot
+ // say (an asker of a kind it does not key on, a revision its log does not
+ // hold, a roster it cannot reach). The person is checked before the
+ // revision: a person who may not open the item learns nothing about its
+ // revisions. Never cached. It returns exactly len(pairs) answers.
Rule(ctx context.Context, asker suite.Subject, pairs []suite.ItemRevision) ([]suite.Authorization, error)
// Content returns the item's text at revision, as the plain text a
// consumer indexes. suite.ErrNotAvailable for a deleted item, an unknown
- // id, or a revision that is not the current one; this package turns it
- // into the one refusal every such case shares.
+ // id, or a revision that is not the current one (one the log holds, or
+ // one it never issued); this package turns it into the one refusal every
+ // such case shares.
Content(ctx context.Context, itemID string, revision int64) ([]byte, error)
}
@@ -72,20 +109,35 @@ const MaxContentBytes = 2 << 20
// and an asker, are far under it.
const maxS2Body = 256 << 10
+// ErrCursorReset is what Feed returns for a cursor its log does not
+// recognise. It is suite.ErrCursorReset itself, so either name matches with
+// errors.Is; this package answers it with suite.CursorResetStatus and
+// suite.CursorResetBody (doctrine §6.6).
+var ErrCursorReset = suite.ErrCursorReset
+
// Handler returns the authenticated routes, or nil when no consumer is
// configured: an app with no consumers serves no suite routes at all
-// (doctrine §3, A.2 — the routes exist wherever consumer tokens do).
+// (doctrine §3, A.2 — the routes exist wherever consumer tokens do). It is
+// the only thing an app mounts.
func Handler(p Producer, consumers []Consumer, logger *slog.Logger) http.Handler {
if len(consumers) == 0 {
return nil
}
- return Authenticate(consumers, Routes(p, logger))
+ return Authenticate(consumers, routes(p, logger))
}
-// Routes is the three routes with no authentication. An app never mounts it
-// directly; it exists for Handler and for the conformance harness, which
-// drives a handler without a bearer token.
+// Routes is the three routes with NO bearer check: mounted, it serves every
+// live item — private ones included — to anybody who can reach the app.
+//
+// Deprecated: never mount it. Mount Handler, and test with
+// conformance.RunProducer or conformance.CheckProducer, which drive Handler
+// through a token they mint (revision 11). Routes stays only because the
+// module is additive (AGENTS.md) and Docs' and Fichas' tests call it.
func Routes(p Producer, logger *slog.Logger) http.Handler {
+ return routes(p, logger)
+}
+
+func routes(p Producer, logger *slog.Logger) http.Handler {
if logger == nil {
logger = slog.New(slog.NewTextHandler(io.Discard, nil))
}
@@ -93,12 +145,42 @@ func Routes(p Producer, logger *slog.Logger) http.Handler {
mux.HandleFunc("GET "+suite.RouteS1, func(w http.ResponseWriter, r *http.Request) { serveS1(p, logger, w, r) })
mux.HandleFunc("POST "+suite.RouteS2, func(w http.ResponseWriter, r *http.Request) { serveS2(p, logger, w, r) })
mux.HandleFunc("GET "+suite.RouteS3+"/{item}", func(w http.ResponseWriter, r *http.Request) { serveS3(p, logger, w, r) })
- return mux
+ return noStore(mux)
+}
+
+// noStore marks every response this package writes, the mux's own 404 and
+// 405 included, as one nobody may keep: an S2 answer is one person's, and
+// an S3 body may be a private item's. no-store keeps a cache at the platform
+// edge from serving it to the next request (leak list item 11's shape);
+// Vary: Authorization says, to any cache that ignores no-store, that a
+// response belongs to the credential that fetched it. Set before anything
+// else is written, so a refusal carries exactly the headers every other
+// refusal does (Fable, review of c38e3ad, M3).
+func noStore(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Cache-Control", "no-store")
+ w.Header().Set("Vary", "Authorization")
+ next.ServeHTTP(w, r)
+ })
}
func serveS1(p Producer, logger *slog.Logger, w http.ResponseWriter, r *http.Request) {
cursor := r.URL.Query().Get("cursor")
feed, err := p.Feed(r.Context(), cursor, FeedPageLimit)
+ if errors.Is(err, ErrCursorReset) {
+ if cursor == "" {
+ // The beginning names no position, so it cannot be one the log
+ // lost; a reset here would send a consumer back to "" for ever.
+ logger.Error("suite S1: the producer reset the beginning")
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ // The fixed body and nothing else: no position, no count, no reason.
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(suite.CursorResetStatus)
+ io.WriteString(w, suite.CursorResetBody)
+ return
+ }
if err != nil {
// Never an empty feed: an empty page for a failed read would move a
// consumer's cursor past changes it never saw.
@@ -119,10 +201,10 @@ func serveS1(p Producer, logger *slog.Logger, w http.ResponseWriter, r *http.Req
writeJSON(w, feed)
}
-// checkFeed holds the producer to what DecodeS1 will demand. Its errors are
-// fixed strings of this package's own, never the producer's, so they may be
-// logged., so a mistake
-// is a 500 here rather than a consumer stalling on a page it refuses.
+// checkFeed holds the producer to what DecodeS1 will demand, so a mistake is
+// a 500 here rather than a consumer stalling on a page it refuses. Its errors
+// are fixed strings of this package's own, never the producer's, so they may
+// be logged.
func checkFeed(f suite.Feed) error {
if f.Cursor == "" {
return errors.New("empty cursor")
@@ -134,6 +216,11 @@ func checkFeed(f suite.Feed) error {
if row.ItemID == "" || row.TouchedAt.IsZero() {
return errors.New("row without an item id or a time")
}
+ if row.Revision < 1 {
+ // S2 and S3 refuse a revision under 1, so a row carrying one
+ // could never be asked about or fetched.
+ return errors.New("row with a revision under 1")
+ }
}
return nil
}
@@ -158,7 +245,10 @@ func serveS2(p Producer, logger *slog.Logger, w http.ResponseWriter, r *http.Req
return
}
for _, pr := range req.Pairs {
- if pr.ItemID == "" {
+ // No revision under 1, as S3 refuses one: no producer issues it, so
+ // a pair carrying one is a consumer bug, refused rather than ruled
+ // (Fable, review of c38e3ad, L5).
+ if pr.ItemID == "" || pr.Revision < 1 {
w.WriteHeader(http.StatusBadRequest)
return
}
diff --git a/server/server_test.go b/server/server_test.go
index 81595d4..5d82a51 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
+ "fmt"
"log/slog"
"net/http"
"net/http/httptest"
@@ -30,6 +31,9 @@ type fixtureProducer struct {
cursor string // overrides the feed's cursor when set
content []byte // overrides S3 bytes when set
lastAsker suite.Subject
+ zeroTime bool // the first row carries no touched_at
+ zeroRev bool // the first row carries revision 0
+ resetStart bool // Feed resets even the beginning
}
func (p *fixtureProducer) find(id string) (suite.CustodyCase, bool) {
@@ -48,10 +52,23 @@ func (p *fixtureProducer) Feed(_ context.Context, cursor string, limit int) (sui
if cursor == "end" {
return suite.Feed{Cursor: "end"}, nil
}
+ if cursor != "" || p.resetStart {
+ // The only cursors this log issues are "end" and the override, and
+ // a test's own; anything else names no position in it (§6.6).
+ if p.cursor == "" || cursor != p.cursor {
+ return suite.Feed{}, fmt.Errorf("fichas-like: cursor %q: %w", cursor, server.ErrCursorReset)
+ }
+ }
var rows []suite.FeedRow
for _, c := range p.f.Cases {
rows = append(rows, suite.FeedRow{ItemID: c.ItemID, Revision: c.Revision, Gone: c.Rung == suite.RungDeleted, TouchedAt: time.Date(2026, 11, 1, 9, 0, 0, 0, time.UTC)})
}
+ if p.zeroTime {
+ rows[0].TouchedAt = time.Time{}
+ }
+ if p.zeroRev {
+ rows[0].Revision = 0
+ }
for i := 0; i < p.extraRows; i++ {
rows = append(rows, suite.FeedRow{ItemID: "extra-" + strconv.Itoa(i), Revision: 1, TouchedAt: time.Date(2026, 11, 1, 9, 0, 0, 0, time.UTC)})
}
@@ -80,15 +97,17 @@ func (p *fixtureProducer) Rule(_ context.Context, asker suite.Subject, pairs []s
for _, pr := range pairs {
c, ok := p.find(pr.ItemID)
may := ok && asker == p.f.Asker && c.Rung != suite.RungDeleted && (c.Rung == suite.RungTeam || c.Owner == "asker" || c.AskerGrant)
+ // STALE from the log, never by comparing numbers (§6.6): this log
+ // holds the current revision and the one before it.
switch {
case !may:
out = append(out, suite.NOT_VISIBLE)
- case pr.Revision < c.Revision:
+ case pr.Revision == c.Revision:
+ out = append(out, suite.VISIBLE)
+ case pr.Revision == c.PriorRevision:
out = append(out, suite.STALE)
- case pr.Revision > c.Revision:
- out = append(out, suite.UNKNOWN)
default:
- out = append(out, suite.VISIBLE)
+ out = append(out, suite.UNKNOWN)
}
}
if p.short {
@@ -142,10 +161,25 @@ func do(h http.Handler, method, url, tok string, body []byte) *httptest.Response
}
// The routes this package serves pass the doctrine's own harness, driven
-// through a producer that only knows the fixture. The harness never sends a
-// malformed revision or an unauthenticated request, which is why the tests
-// below exist beside it.
+// through a producer that only knows the fixture, mounted as an app mounts
+// it: Handler, behind a token (conformance.RunProducer, revision 11). The
+// tests below cover what the harness does not send.
+//
+// MUTATION-TESTED 2026-11-01, reverted: CheckProducer driving the deprecated
+// Routes in place of Handler → "a request with no token: got 404".
+//
+// MUTATION-TESTED 2026-11-02 (Fable's review of 0a59e7d, L6), reverted:
+// Authenticate's no-token 401 stripped of Cache-Control and Vary → "GET
+// /suite/s3 401: Cache-Control "" and Vary """ here; with CheckProducer's
+// anonymous probe sent around the header audit instead of through it (as
+// before), the same mutant passed this test.
func TestRoutesPassConformance(t *testing.T) {
+ conformance.RunProducer(t, producer(t), suite.SubjectPersonRef)
+}
+
+// The deprecated Routes still serves what it served, for the apps whose
+// tests call it (the module is additive).
+func TestDeprecatedRoutesStillConform(t *testing.T) {
conformance.Run(t, server.Routes(producer(t), nil))
}
@@ -162,7 +196,8 @@ func TestNoConsumersServesNothing(t *testing.T) {
// MUTATION-TESTED 2026-11-01, each reverted: the hash comparison skipped
// (any bearer admitted) → "an unknown token"; only the first token of a
// consumer compared → "the second token"; a reason written in the 401 body
-// → "alike".
+// → "alike". Revision 11: the scheme check removed (any seven bytes taken
+// as "Bearer ") → "not a bearer", which "Basic " never caught.
func TestAuthentication(t *testing.T) {
h := server.Handler(producer(t), consumers(t, token, "the-next-token"), nil)
ok := do(h, "GET", suite.RouteS1, token, nil)
@@ -180,9 +215,12 @@ func TestAuthentication(t *testing.T) {
r.Header.Set("Authorization", "Bearer not-the-token")
return r
},
+ // Seven bytes, as "Bearer " is: with "Basic " (six) the token was
+ // cut one byte short and refused whether or not the scheme was
+ // checked (Fable, review of c38e3ad, L5).
"not a bearer": func() *http.Request {
r := httptest.NewRequest("GET", suite.RouteS1, nil)
- r.Header.Set("Authorization", "Basic "+token)
+ r.Header.Set("Authorization", "Digest "+token)
return r
},
"an empty bearer": func() *http.Request {
@@ -196,7 +234,7 @@ func TestAuthentication(t *testing.T) {
if rec.Code != 401 {
t.Errorf("%s: %d, want 401", name, rec.Code)
}
- got := strconv.Itoa(rec.Code) + "|" + rec.Body.String()
+ got := signature(rec)
if first == "" {
first = got
} else if got != first {
@@ -205,6 +243,9 @@ func TestAuthentication(t *testing.T) {
}
}
+// MUTATION-TESTED 2026-11-01, reverted: the SHA-256 length check reduced to
+// "not empty" → "31 bytes of hex" and "33 bytes of hex" (Fable, review of
+// c38e3ad, L5: nothing tested it).
func TestParseConsumers(t *testing.T) {
good := `[{"consumer_id":"memoria","tokens":[{"epoch":1,"sha256":"` + server.TokenHash("x") + `"}]}]`
if cs, err := server.ParseConsumers(good); err != nil || len(cs) != 1 || cs[0].ID != "memoria" {
@@ -219,6 +260,10 @@ func TestParseConsumers(t *testing.T) {
"three tokens": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `"},{"epoch":2,"sha256":"` + h + `"},{"epoch":3,"sha256":"` + h + `"}]}]`,
"no tokens": `[{"consumer_id":"m","tokens":[]}]`,
"not hex": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"plaintext-token"}]}]`,
+ // Hex, and a byte short of a SHA-256: no token can ever match it, so
+ // it is a typo that would serve nobody (Fable, review of c38e3ad, L5).
+ "31 bytes of hex": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h[:62] + `"}]}]`,
+ "33 bytes of hex": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `00"}]}]`,
"a repeated id": `[{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `"}]},{"consumer_id":"m","tokens":[{"epoch":1,"sha256":"` + h + `"}]}]`,
"trailing content": good + `[]`,
"not a list": `{"consumer_id":"m"}`,
@@ -325,14 +370,7 @@ func TestS3RefusesAlike(t *testing.T) {
if base.Code != 404 {
t.Fatalf("baseline: %d", base.Code)
}
- sig := func(r *httptest.ResponseRecorder) string {
- var hs []string
- for k, v := range r.Header() {
- hs = append(hs, k+"="+strings.Join(v, ","))
- }
- sort.Strings(hs)
- return strconv.Itoa(r.Code) + "|" + strings.Join(hs, "|") + "|" + r.Body.String()
- }
+ sig := signature
for name, url := range map[string]string{
"deleted": suite.RouteS3 + "/doc-deleted?revision=6",
"superseded": suite.RouteS3 + "/doc-team?revision=6",
@@ -448,3 +486,127 @@ func (p *emptyIDProducer) Feed(ctx context.Context, cursor string, limit int) (s
}
return f, err
}
+
+// signature is a response as a client could compare it: status, every
+// header, body.
+func signature(r *httptest.ResponseRecorder) string {
+ var hs []string
+ for k, v := range r.Header() {
+ hs = append(hs, k+"="+strings.Join(v, ","))
+ }
+ sort.Strings(hs)
+ return strconv.Itoa(r.Code) + "|" + strings.Join(hs, "|") + "|" + r.Body.String()
+}
+
+// A cursor the producer's log does not recognise is S1's one fixed 409, and
+// the consumer's decoder reads it as a reset (doctrine §6.6, revision 11).
+// The beginning is never reset: a producer that resets "" would send a
+// consumer back to "" for ever, so that is a 500.
+//
+// MUTATION-TESTED 2026-11-01, each reverted: the ErrCursorReset branch
+// removed (a reset answered as a failed feed) → "a foreign cursor"; the ""
+// guard removed → "the beginning reset"; the body written through
+// json.Encoder as an object with a second field → "a foreign cursor".
+func TestS1CursorReset(t *testing.T) {
+ p := producer(t)
+ h := server.Handler(p, consumers(t, token), nil)
+ rec := do(h, "GET", suite.RouteS1+"?cursor=17.4421", token, nil)
+ if _, err := suite.DecodeS1(rec.Code, rec.Body.Bytes()); !errors.Is(err, suite.ErrCursorReset) {
+ t.Errorf("a foreign cursor: %d %q, %v; want the reset", rec.Code, rec.Body.String(), err)
+ }
+ if rec.Code != 409 || rec.Body.String() != suite.CursorResetBody || rec.Header().Get("Content-Type") != "application/json" {
+ t.Errorf("a foreign cursor: %d %q %q, want exactly 409 %s as JSON", rec.Code, rec.Body.String(), rec.Header().Get("Content-Type"), suite.CursorResetBody)
+ }
+ // The cursors the log did issue still read.
+ if rec := do(h, "GET", suite.RouteS1+"?cursor=end", token, nil); rec.Code != 200 {
+ t.Errorf("the log's own cursor: %d", rec.Code)
+ }
+ p.resetStart = true
+ if rec := do(h, "GET", suite.RouteS1+"?cursor=", token, nil); rec.Code != 500 {
+ t.Errorf("the beginning reset: %d, want 500", rec.Code)
+ }
+}
+
+// Every response the package writes is one nobody may keep, and refusals of
+// a kind stay byte-identical with the headers on (Fable, review of c38e3ad,
+// M3). Through Handler, so the 401 is covered, and including the mux's own
+// 404 and 405, which no route of ours writes.
+//
+// MUTATION-TESTED 2026-11-01, each reverted: noStore dropped from routes →
+// "Routes" (through Handler, Authenticate's own noStore still covers it);
+// noStore dropped from Authenticate → "no token"; Vary not set → every
+// response.
+func TestEveryResponseIsNoStore(t *testing.T) {
+ p := producer(t)
+ h := server.Handler(p, consumers(t, token), nil)
+ ask := `{"asker":{"kind":"person_ref","value":"pers_ana"},"pairs":[{"item_id":"doc-team","revision":7}]}`
+ cases := map[string]func() *httptest.ResponseRecorder{
+ "S1 200": func() *httptest.ResponseRecorder { return do(h, "GET", suite.RouteS1, token, nil) },
+ "S1 409": func() *httptest.ResponseRecorder { return do(h, "GET", suite.RouteS1+"?cursor=x", token, nil) },
+ "S2 200": func() *httptest.ResponseRecorder { return do(h, "POST", suite.RouteS2, token, []byte(ask)) },
+ "S2 400": func() *httptest.ResponseRecorder { return do(h, "POST", suite.RouteS2, token, []byte("nope")) },
+ "S3 200": func() *httptest.ResponseRecorder {
+ return do(h, "GET", suite.RouteS3+"/doc-team?revision=7", token, nil)
+ },
+ "S3 404": func() *httptest.ResponseRecorder {
+ return do(h, "GET", suite.RouteS3+"/doc-deleted?revision=6", token, nil)
+ },
+ "S3 POST": func() *httptest.ResponseRecorder {
+ return do(h, "POST", suite.RouteS3+"/doc-team?revision=7", token, nil)
+ },
+ "no such route": func() *httptest.ResponseRecorder { return do(h, "GET", "/suite/s9", token, nil) },
+ "no token": func() *httptest.ResponseRecorder { return do(h, "GET", suite.RouteS1, "", nil) },
+ "a wrong token": func() *httptest.ResponseRecorder {
+ return do(h, "GET", suite.RouteS3+"/doc-team?revision=7", "nope", nil)
+ },
+ }
+ for name, run := range cases {
+ rec := run()
+ if rec.Header().Get("Cache-Control") != "no-store" || rec.Header().Get("Vary") != "Authorization" {
+ t.Errorf("%s (%d): Cache-Control %q, Vary %q; want no-store and Authorization", name, rec.Code, rec.Header().Get("Cache-Control"), rec.Header().Get("Vary"))
+ }
+ }
+ // The deprecated Routes too, which apps' own tests still call.
+ if rec := do(server.Routes(p, nil), "GET", suite.RouteS3+"/doc-team?revision=7", "", nil); rec.Header().Get("Cache-Control") != "no-store" || rec.Header().Get("Vary") != "Authorization" {
+ t.Errorf("Routes: Cache-Control %q, Vary %q", rec.Header().Get("Cache-Control"), rec.Header().Get("Vary"))
+ }
+ if cases["S3 POST"]().Code == 200 {
+ t.Error("S3 served a POST")
+ }
+ p.feedErr, p.ruleErr, p.contentErr = errors.New("down"), errors.New("down"), errors.New("down")
+ for name, rec := range map[string]*httptest.ResponseRecorder{
+ "S1 503": do(h, "GET", suite.RouteS1, token, nil),
+ "S2 503": do(h, "POST", suite.RouteS2, token, []byte(ask)),
+ "S3 503": do(h, "GET", suite.RouteS3+"/doc-team?revision=7", token, nil),
+ } {
+ if rec.Code != 503 || rec.Header().Get("Cache-Control") != "no-store" || rec.Header().Get("Vary") != "Authorization" {
+ t.Errorf("%s: %d, Cache-Control %q, Vary %q", name, rec.Code, rec.Header().Get("Cache-Control"), rec.Header().Get("Vary"))
+ }
+ }
+}
+
+// Revision 11's edges (Fable, review of c38e3ad, L5): S2 refuses a revision
+// under 1 in a pair, as S3 does; a feed row with no touched_at or a revision
+// under 1 is the producer's mistake, a 500, never a page.
+//
+// MUTATION-TESTED 2026-11-01, each reverted: S2's revision check removed →
+// "revision 0" and "revision -1"; checkFeed's TouchedAt check removed → "no
+// touched_at"; checkFeed's revision check removed → "revision 0 in the feed".
+func TestRevision11Edges(t *testing.T) {
+ p := producer(t)
+ h := server.Handler(p, consumers(t, token), nil)
+ for name, rev := range map[string]string{"revision 0": "0", "revision -1": "-1"} {
+ body := `{"asker":{"kind":"person_ref","value":"pers_ana"},"pairs":[{"item_id":"doc-team","revision":` + rev + `}]}`
+ if rec := do(h, "POST", suite.RouteS2, token, []byte(body)); rec.Code != 400 {
+ t.Errorf("%s in an S2 pair: %d, want 400", name, rec.Code)
+ }
+ }
+ p.zeroTime = true
+ if rec := do(h, "GET", suite.RouteS1, token, nil); rec.Code != 500 {
+ t.Errorf("no touched_at: %d, want 500", rec.Code)
+ }
+ p.zeroTime, p.zeroRev = false, true
+ if rec := do(h, "GET", suite.RouteS1, token, nil); rec.Code != 500 {
+ t.Errorf("revision 0 in the feed: %d, want 500", rec.Code)
+ }
+}
diff --git a/strictjson.go b/strictjson.go
index a14cbdd..ed1db42 100644
--- a/strictjson.go
+++ b/strictjson.go
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
+ "io"
"strings"
)
@@ -28,7 +29,11 @@ func rejectAmbiguousJSON(data []byte) error {
}
// Anything after the first complete value means the body is two documents
// wearing one Content-Length, and which one is "the" answer is a guess.
- if dec.More() {
+ // The end is io.EOF from one more Token, never Decoder.More: More answers
+ // false in front of a stray ']' or '}', so `{...}]` passed as one
+ // document (Fable, review of c38e3ad, L6; the server package had already
+ // learned this from Astra, 2026-11-01).
+ if _, err := dec.Token(); err != io.EOF {
return fmt.Errorf("suite: trailing content after the JSON document")
}
return nil