oficina / memoria Public

Answer Fable's re-review of e1f6829: the owner sees a re-read; the front page never withholds silently

- Sources page: a Reconciling source reads "Being re-read after it was
  restored from a backup…" (alarming) instead of a pre-restore "Current
  as of"; a failed read of the state says so.
- Front page: Recently updated's notices stand without the list, so a
  pool that is all withheld still says which app did not answer.
- Pinned, each mutation seen red: a listed-then-404'd item is retired at
  the tip (R06); retirement goes through Store.Delete, the index holding
  exactly what the database does (R03); Reconciling is cleared only after
  the deletes, and PolledAt only after retirement (R04, R10, new
  TestAFailedRetirementStaysHidden); an unreadable re-read state
  withholds every sibling passage loudly (R01, reached by renaming the
  table).
- Gate 3c's flip test adds the scriptless AI answer and the search the
  native and agent APIs answer from.
- Stale comments on WithholdAndReannounce and SiblingFeed.Reconciling.
- Spec §8.14: the sources line, and the wake as the re-read's backoff.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev ff846dbd2bfb24c67859f6e583fa97ab4bb85c16 parent e1f6829
7 files changed, +265 −23
  • docs/superpowers/specs/2026-09-03-memoria-design.md +7 −1
  • internal/memoria/flip_test.go +86 −2
  • internal/memoria/handlers_sources.go +11 −0
  • internal/memoria/models.go +5 −4
  • internal/memoria/sibling/policy.go +5 −3
  • internal/memoria/siblingreset_test.go +143 −9
  • internal/memoria/templates/index.html +8 −4

CI passed — run details

diff --git a/docs/superpowers/specs/2026-09-03-memoria-design.md b/docs/superpowers/specs/2026-09-03-memoria-design.md
index e3f59e4..ffd4766 100644
--- a/docs/superpowers/specs/2026-09-03-memoria-design.md
+++ b/docs/superpowers/specs/2026-09-03-memoria-design.md
@@ -4708,7 +4708,13 @@ and its cursor discarded. The next wake reads from the start; a document
the re-read fetches is unpended; at the tip the rest are deleted and the
app is shown again. A second reset before the tip is a failure that
re-marks everything pending; a reset answered to the start is a broken
-producer and drops nothing (`siblingreset_test.go`).
+producer and drops nothing (`siblingreset_test.go`). The owner's sources
+page says "Being re-read after it was restored from a backup" in place of
+"Current as of" while it lasts. A re-read waits for the next wake, which
+is memoria's backoff: an instance that stays awake does not poll again
+until it hibernates and wakes, and until then the source stays hidden
+and says so — the fail-closed direction, said here so it is not mistaken
+for a stall.
## 9. Surfaces
diff --git a/internal/memoria/flip_test.go b/internal/memoria/flip_test.go
index 3dab8a9..8355d4e 100644
--- a/internal/memoria/flip_test.go
+++ b/internal/memoria/flip_test.go
@@ -27,8 +27,11 @@ import (
// Surfaces: the results page, the results fragment, the typeahead, the AI
// answer (whose own cache is keyed on the ruled passages, so a flip
// changes the key), the document page, the documents list and the front
-// page's Recently updated. TestEverySurfaceAsksTheAppOfRecord covers the
-// delete paths, which never show a sibling's document at all.
+// page's Recently updated, the scriptless AI answer, and the search the
+// native and agent APIs answer from. TestEverySurfaceAsksTheAppOfRecord
+// covers the delete paths, which never show a sibling's document at all;
+// the correction page lists only checked facts, and reports hold
+// coordinates only.
//
// Written, it found the typeahead hiding an unanswered app's documents
// silently; it now carries §4.1's line like every other surface.
@@ -114,6 +117,30 @@ func TestGate3cEverySurfaceFollowsAFlip(t *testing.T) {
func(r *httptest.ResponseRecorder) bool { return r.Code == 503 }},
{"the documents list", "/documents", names, says},
{"recently updated", "/", names, says},
+ // The scriptless AI answer, rendered into the results page.
+ {"the scriptless AI answer", "/?q=nebula+launch&ai=1",
+ func(r *httptest.ResponseRecorder) bool {
+ return strings.Contains(r.Body.String(), "FROM THE SPRING PLAN") || names(r)
+ }, says},
+ }
+ // The native and agent APIs both answer from SearchWithoutFacts
+ // (native.go, agent_access.go); asked of it directly, with the asker
+ // the page uses.
+ asker := suite.Subject{Kind: suite.SubjectAddress, Value: "paul@tito.io"}
+ if got, ok := a.asker(httptest.NewRequest("GET", "/", nil)); ok {
+ asker = got
+ }
+ apiSays := func() (shown bool, notices string) {
+ p, err := a.store.SearchWithoutFacts(ctx, asker, "nebula", 25)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, r := range p.Results {
+ if r.Title == title {
+ shown = true
+ }
+ }
+ return shown, strings.Join(p.Notices, " ")
}
for _, step := range []struct {
@@ -144,6 +171,21 @@ func TestGate3cEverySurfaceFollowsAFlip(t *testing.T) {
}
}
}
+ shown, notices := apiSays()
+ switch step.want {
+ case "shown":
+ if !shown {
+ t.Errorf("the native and agent search after %v: not shown", step.give)
+ }
+ case "hidden":
+ if shown {
+ t.Errorf("the native and agent search after NOT_VISIBLE: still shown")
+ }
+ case "withheld":
+ if shown || !strings.Contains(notices, notice) {
+ t.Errorf("the native and agent search after UNKNOWN: shown=%v, notices %q", shown, notices)
+ }
+ }
// The control stays on the list throughout.
if !strings.Contains(get("/documents").Body.String(), "Kitchen rota") {
t.Fatalf("after %v the control is gone, so an empty list proves nothing", step.give)
@@ -165,3 +207,45 @@ func (echoAnswerer) Answer(_ context.Context, _ string, ps []string) ([]provider
}
return []provider.Sentence{{Text: "ONLY THE CHECKLIST.", Cite: []int{0}}}, nil
}
+
+// The front page withholds out loud even when every recent document is
+// withheld: the notices stand without the list (Fable's review of
+// e1f6829, whose probe found the section, notices and all, missing).
+//
+// MUTATION-TESTED 2026-11-02: the notices back inside {{with .Recent}} →
+// "said nothing".
+func TestTheFrontPageSaysWhenEveryRecentDocumentIsWithheld(t *testing.T) {
+ logger := slog.New(slog.NewTextHandler(io.Discard, nil))
+ d, err := db.Open(filepath.Join(t.TempDir(), "app.db"), logger)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { d.Close() })
+ dek := make([]byte, 32)
+ for i := range dek {
+ dek[i] = byte(i*5 + 2)
+ }
+ sealer, err := seal.New(dek)
+ if err != nil {
+ t.Fatal(err)
+ }
+ mux, a, err := AppForTest(d, "http://127.0.0.1:8899", sealer, logger)
+ if err != nil {
+ t.Fatal(err)
+ }
+ a.store.custody = &perItemCustody{apps: docsRoster(), give: map[string]suite.Authorization{"only": suite.UNKNOWN}}
+ if _, err := a.store.Ingest(context.Background(), IngestSpec{Source: "Docs", Key: "only", Title: "The only document", Body: "Text.", ItemID: "only", SiblingRevision: 1}); err != nil {
+ t.Fatal(err)
+ }
+ req := httptest.NewRequest("GET", "/", nil)
+ req.Header.Set("Accept", "text/html")
+ rec := httptest.NewRecorder()
+ mux.ServeHTTP(rec, req)
+ b := rec.Body.String()
+ if strings.Contains(b, "The only document") {
+ t.Fatal("the withheld document is on the front page")
+ }
+ if !strings.Contains(b, "Docs did not answer") {
+ t.Errorf("the front page withheld everything recent and said nothing:\n%s", b)
+ }
+}
diff --git a/internal/memoria/handlers_sources.go b/internal/memoria/handlers_sources.go
index 0dd0e63..3fedf46 100644
--- a/internal/memoria/handlers_sources.go
+++ b/internal/memoria/handlers_sources.go
@@ -57,11 +57,22 @@ func (a *app) siblingRows(r *http.Request) []sourceRow {
}
var out []sourceRow
now := time.Now().UTC()
+ // Sources being re-read after a CURSOR_RESET (suite doctrine §6.6:
+ // "says the app is being re-read"). Readers see it on every page that
+ // withholds; the owner sees it here, in place of a "Current as of"
+ // that would date from before the restore.
+ rereading, rerr := a.store.reconcilingSources(r.Context())
for _, app := range roster.ordered() {
row := sourceRow{App: app.Name}
at, err := a.store.polledAt(r.Context(), app.Name)
switch {
+ case rerr != nil:
+ row.Current = "Could not read whether this source is being re-read."
+ row.CurrentAlarming = true
+ case rereading[app.Name]:
+ row.Current = "Being re-read after it was restored from a backup; its documents are hidden until the re-read finishes."
+ row.CurrentAlarming = true
case err != nil:
// **Not "never polled".** A read that failed says so; a count
// that fails is not a count of zero, and the same rule governs
diff --git a/internal/memoria/models.go b/internal/memoria/models.go
index fde19e9..d00acf3 100644
--- a/internal/memoria/models.go
+++ b/internal/memoria/models.go
@@ -183,10 +183,11 @@ type SiblingFeed struct {
// entirely until a re-announce completes, so the other sources fill
// the page to its full depth instead of it rendering nearly empty.
//
- // Not set by anything yet — AHEAD is not on the wire (§13) — and here
- // rather than added later because the column is what makes the
- // re-announce state durable across the hibernation that is certain to
- // happen in the middle of one.
+ // Set by a CURSOR_RESET (siblingsync.go cursorReset, suite doctrine
+ // §6.6) and cleared when the re-read reaches the tip; AHEAD, which this
+ // column was first added for, is still not on the wire (§13). Durable
+ // because the hibernation that is certain to happen in the middle of a
+ // re-read must not end it.
Reconciling bool `gorm:"not null;default:false"`
CreatedAt time.Time
UpdatedAt time.Time
diff --git a/internal/memoria/sibling/policy.go b/internal/memoria/sibling/policy.go
index f76d8ef..120f27c 100644
--- a/internal/memoria/sibling/policy.go
+++ b/internal/memoria/sibling/policy.go
@@ -47,9 +47,11 @@ const (
// readable and refetching fixes it. Not a denial.
WithholdAndRefetch
- // WithholdAndReannounce: AHEAD. **Nothing produces this yet**, and that
- // is recorded rather than hidden — see aheadNotYetOnTheWire below, which
- // is the tripwire that fails the day it becomes reachable.
+ // WithholdAndReannounce: a source being re-read. memoria's rule()
+ // produces it for every passage from a source whose feed is Reconciling
+ // after a CURSOR_RESET (suite doctrine §6.6). No S2 answer maps to it:
+ // AHEAD is still not on the wire, and aheadNotYetOnTheWire below is the
+ // tripwire for the day it is.
WithholdAndReannounce
// numDispositions is one past the last, so a test can iterate the
diff --git a/internal/memoria/siblingreset_test.go b/internal/memoria/siblingreset_test.go
index 86e745a..a95682c 100644
--- a/internal/memoria/siblingreset_test.go
+++ b/internal/memoria/siblingreset_test.go
@@ -3,10 +3,14 @@ package memoria
import (
"context"
"errors"
+ "net/http/httptest"
"strings"
"testing"
"amadan.net/oficina/suite"
+ "gorm.io/gorm"
+
+ "amadan.net/oficina/memoria/internal/memoria/sibling"
)
// CURSOR_RESET, memoria's half (suite doctrine §6.6, revision 11): a
@@ -33,6 +37,12 @@ import (
// -> "still withheld after the re-read"
// finishReread run on every page, not only at the tip
// -> "retired before the re-read reached the tip"
+// a listed row S3 refuses unpended (Fable's R06)
+// -> "survived the re-read"
+// retirement by deleting the document row, not Store.Delete (R03)
+// -> "passages outlived their retired documents"
+// the sources page not reading Reconciling
+// -> "does not say Docs is being re-read"
func TestACursorResetHidesThenReReadsThenRetires(t *testing.T) {
ctx := context.Background()
s := storeForTest(t)
@@ -42,24 +52,27 @@ func TestACursorResetHidesThenReReadsThenRetires(t *testing.T) {
f := &feedServer{
t: t,
pages: map[string]suite.Feed{
- "": {Cursor: "old-1", Rows: []suite.FeedRow{row("keep", 5, false), row("drop", 7, false)}},
+ "": {Cursor: "old-1", Rows: []suite.FeedRow{row("keep", 5, false), row("drop", 7, false), row("unserved", 9, false)}},
"old-1": {Cursor: "old-1", Rows: []suite.FeedRow{}},
},
- bodies: map[string]string{"keep": "The nebula plan is kept.", "drop": "The nebula budget was dropped."},
+ bodies: map[string]string{"keep": "The nebula plan is kept.", "drop": "The nebula budget was dropped.", "unserved": "The nebula draft."},
}
sib, client := f.start(t)
if _, err := s.Poll(ctx, client, sib); err != nil {
t.Fatalf("first poll: %v", err)
}
- if got := nebula(t, s, asker); got.n != 2 {
- t.Fatalf("before the reset the search found %d, want 2 (the presence half)", got.n)
+ if got := nebula(t, s, asker); got.n != 3 {
+ t.Fatalf("before the reset the search found %d, want 3 (the presence half)", got.n)
}
// The sibling is restored: memoria's cursor names nothing in its log.
// The restored log has "keep" and not "drop", and two pages, so the
- // tip is not reached on the first.
+ // tip is not reached on the first. It lists "unserved" and then will
+ // not serve it: memoria cannot show its copy is one the restored log
+ // still has, so the tip retires it too.
f.reset = map[string]bool{"old-1": true}
- f.pages[""] = suite.Feed{Cursor: "new-1", Rows: []suite.FeedRow{row("keep", 5, false)}}
+ f.failS3 = map[string]bool{"unserved": true}
+ f.pages[""] = suite.Feed{Cursor: "new-1", Rows: []suite.FeedRow{row("keep", 5, false), row("unserved", 9, false)}}
f.pages["new-1"] = suite.Feed{Cursor: "new-2", Rows: []suite.FeedRow{}}
f.pages["new-2"] = suite.Feed{Cursor: "new-2", Rows: []suite.FeedRow{}}
@@ -77,9 +90,12 @@ func TestACursorResetHidesThenReReadsThenRetires(t *testing.T) {
if !strings.Contains(got.notices, "Docs is being re-read") {
t.Errorf("withheld without saying so: notices %q", got.notices)
}
- if heldCount(t, s, "Docs") != 2 {
+ if heldCount(t, s, "Docs") != 3 {
t.Errorf("the reset deleted something; it may only hide (step 1 is a soft drop)")
}
+ if line := sourcesLine(t, s, sib); !strings.Contains(line, "Being re-read") {
+ t.Errorf("the owner's sources page does not say Docs is being re-read: %q", line)
+ }
// The re-read, stopped after its first page: nothing is retired yet,
// and the source stays hidden.
@@ -87,7 +103,7 @@ func TestACursorResetHidesThenReReadsThenRetires(t *testing.T) {
if _, err := s.Poll(ctx, client, sib); err == nil {
t.Fatal("the scripted failure did not fail")
}
- if heldCount(t, s, "Docs") != 2 {
+ if heldCount(t, s, "Docs") != 3 {
t.Fatal("retired before the re-read reached the tip")
}
if got := nebula(t, s, asker); got.n != 0 {
@@ -100,13 +116,131 @@ func TestACursorResetHidesThenReReadsThenRetires(t *testing.T) {
t.Fatalf("re-read: %v", err)
}
if heldCount(t, s, "Docs") != 1 {
- t.Errorf("%d Docs documents after the re-read, want 1: \"drop\" survived the re-read, or the re-listed document was retired", heldCount(t, s, "Docs"))
+ t.Errorf("%d Docs documents after the re-read, want 1: \"drop\" or \"unserved\" survived the re-read, or the re-listed document was retired", heldCount(t, s, "Docs"))
}
assertHeld(t, s, "Docs", "keep", 5)
got = nebula(t, s, asker)
if got.n != 1 || got.notices != "" {
t.Errorf("still withheld after the re-read: %d results, notices %q", got.n, got.notices)
}
+ // Retired through Store.Delete: the in-memory index holds exactly the
+ // passages the database does. (The chunk rows cascade with their
+ // document whatever deletes it; the index is what a raw delete leaves
+ // behind.)
+ var stored int64
+ if err := s.db.G.Model(&Chunk{}).Count(&stored).Error; err != nil {
+ t.Fatal(err)
+ }
+ indexed, err := s.ix.Count()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if int64(indexed) != stored {
+ t.Errorf("passages outlived their retired documents: %d indexed, %d stored", indexed, stored)
+ }
+ if line := sourcesLine(t, s, sib); !strings.HasPrefix(line, "Current as of") {
+ t.Errorf("the sources page after the re-read: %q", line)
+ }
+}
+
+// A retirement that fails leaves the source hidden and the feed not
+// called current: §6.6's step 1 exists so that a consumer is never left
+// showing a mix of two logs, and clearing Reconciling before the deletes
+// (or stamping PolledAt before them) is how a crash would leave one.
+//
+// MUTATION-TESTED 2026-11-02, each seen red and reverted: Reconciling
+// cleared before the deletes → "shown after a failed retirement";
+// markPolled before finishReread → "called current".
+func TestAFailedRetirementStaysHidden(t *testing.T) {
+ ctx := context.Background()
+ s := storeForTest(t)
+ s.custody = &fixedCustody{apps: docsRoster(), give: suite.VISIBLE}
+ asker := suite.Subject{Kind: suite.SubjectAddress, Value: "paul@tito.io"}
+ f := &feedServer{
+ t: t,
+ pages: map[string]suite.Feed{
+ "": {Cursor: "old-1", Rows: []suite.FeedRow{row("keep", 1, false), row("drop", 2, false)}},
+ "old-1": {Cursor: "old-1", Rows: []suite.FeedRow{}},
+ },
+ bodies: map[string]string{"keep": "nebula keep", "drop": "nebula drop"},
+ }
+ sib, client := f.start(t)
+ if _, err := s.Poll(ctx, client, sib); err != nil {
+ t.Fatal(err)
+ }
+ before := polledAt(t, s, "Docs")
+ f.reset = map[string]bool{"old-1": true}
+ if _, err := s.Poll(ctx, client, sib); err != nil {
+ t.Fatal(err)
+ }
+ f.pages[""] = suite.Feed{Cursor: "end", Rows: []suite.FeedRow{row("keep", 1, false)}}
+ f.pages["end"] = suite.Feed{Cursor: "end", Rows: []suite.FeedRow{}}
+
+ failing := true
+ if err := s.db.G.Callback().Delete().Before("gorm:delete").Register("test:fail_retire", func(tx *gorm.DB) {
+ if failing && tx.Statement.Table == "documents" {
+ tx.AddError(errors.New("the disk went away"))
+ }
+ }); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.Poll(ctx, client, sib); err == nil {
+ t.Fatal("the retirement did not fail, so nothing below is about a failed one")
+ }
+ if got := nebula(t, s, asker); got.n != 0 {
+ t.Fatalf("shown after a failed retirement: %d results", got.n)
+ }
+ if !polledAt(t, s, "Docs").Equal(before) {
+ t.Error("a re-read whose retirement failed was called current")
+ }
+ // Next wake, the disk is back: the tip finishes the job.
+ failing = false
+ if _, err := s.Poll(ctx, client, sib); err != nil {
+ t.Fatalf("the retry: %v", err)
+ }
+ if got := nebula(t, s, asker); got.n != 1 || heldCount(t, s, "Docs") != 1 {
+ t.Errorf("after the retry: %d results, %d held; want 1 and 1", got.n, heldCount(t, s, "Docs"))
+ }
+}
+
+// rule() withholds every sibling passage when it cannot read which
+// sources are being re-read, rather than guess that none is (Fable,
+// 2026-11-02: this branch was unreachable). MUTATION-TESTED 2026-11-02:
+// the read error ignored → "shown".
+func TestAnUnreadableReReadStateWithholds(t *testing.T) {
+ ctx := context.Background()
+ s := storeForTest(t)
+ s.custody = &fixedCustody{apps: docsRoster(), give: suite.VISIBLE}
+ asker := suite.Subject{Kind: suite.SubjectAddress, Value: "paul@tito.io"}
+ if _, err := s.Ingest(systemWrite(ctx), IngestSpec{Source: "Docs", Key: "a", Title: "A", Body: "nebula a", ItemID: "a", SiblingRevision: 1}); err != nil {
+ t.Fatal(err)
+ }
+ if got := nebula(t, s, asker); got.n != 1 {
+ t.Fatalf("presence: %d results", got.n)
+ }
+ if err := s.db.G.Exec("ALTER TABLE sibling_feeds RENAME TO sibling_feeds_away").Error; err != nil {
+ t.Fatal(err)
+ }
+ got := nebula(t, s, asker)
+ if got.n != 0 {
+ t.Fatalf("shown with the re-read state unreadable: %d results", got.n)
+ }
+ if !strings.Contains(got.notices, "Docs") {
+ t.Errorf("withheld silently: %q", got.notices)
+ }
+}
+
+// sourcesLine is the owner's sources-page freshness line for sib.
+func sourcesLine(t *testing.T, s *Store, sib sibling.Sibling) string {
+ t.Helper()
+ keep := s.custody
+ s.custody = &Siblings{client: sibling.NewForTest(), byName: map[string]sibling.Sibling{sib.Name: sib}}
+ defer func() { s.custody = keep }()
+ rows := (&app{store: s}).siblingRows(httptest.NewRequest("GET", "/connectors", nil))
+ if len(rows) != 1 {
+ t.Fatalf("%d sources rows, want 1", len(rows))
+ }
+ return rows[0].Current
}
// At most one reset per re-read (§6.6, Fable's M1): a second reset before
diff --git a/internal/memoria/templates/index.html b/internal/memoria/templates/index.html
index a196148..d275e21 100644
--- a/internal/memoria/templates/index.html
+++ b/internal/memoria/templates/index.html
@@ -48,15 +48,19 @@
<h2 rst-home-label>Recent searches <button type="button" rst-home-clear>Clear</button></h2>
<ul rst-home-list></ul>
</section>
- {{with .Recent}}
+ {{if or .Recent .RecentNotices}}
+ {{/* The notices stand without the list: when every recent document is
+ withheld, an empty section with "Docs did not answer" is the loud
+ withholding §4.1 asks for, and no section at all would be silent
+ (Fable's review of e1f6829). */}}
<section>
<h2 rst-home-label>Recently updated</h2>
- {{range $.RecentNotices}}<p rst-muted rst-home-notice>{{.}}</p>{{end}}
- <ul rst-home-list>
+ {{range .RecentNotices}}<p rst-muted rst-home-notice>{{.}}</p>{{end}}
+ {{with .Recent}}<ul rst-home-list>
{{/* The whole row opens it (Paul, 2026-10-31): rastrillo's list row,
whose one primary link covers the row. */}}
{{range .}}<li rst-row><span rst-row-main><a href="/documents/{{.ID}}">{{.Title}}</a><span rst-row-sub>{{if .Path}}{{.Path}} · {{end}}<time datetime="{{.UpdatedISO}}">{{.UpdatedDay}}</time></span></span></li>{{end}}
- </ul>
+ </ul>{{end}}
</section>
{{end}}
</div>