CURSOR_RESET: hide, re-read from the start, retire what was not re-listed (suite §6.6, revision 11)
On a 409 CURSOR_RESET from a sibling's S1: - every document held from it is marked pending, its feed is marked Reconciling and its cursor discarded, in one transaction (step 1); - rule() withholds a Reconciling source wholesale on every surface, with "<app> is being re-read after a restore; its results are not on this page." (the notice existed for AHEAD and was never reached); - the next poll reads from "" (the wake is the backoff); a re-fetched item is unpended (step 2); - at the tip, everything still pending is deleted through Store.Delete and the source is shown again (step 3); - a second reset before the tip is errResetTwice and re-marks everything pending, so only a completing re-read decides what survives; - a reset answered to "" is errResetAtStart and drops nothing. Migration 0010 adds documents.pending. Every guard mutated and seen red (siblingreset_test.go records them).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+385
−6
internal/memoria/migrations/0010_alter_documents.sql+2 −0internal/memoria/migrations/schema.sql+1 −1internal/memoria/models.go+6 −0internal/memoria/sibling/policy.go+1 −1internal/memoria/sibling/policy_test.go+1 −1internal/memoria/siblingreset_test.go+211 −0internal/memoria/siblingsync.go+128 −0internal/memoria/siblingsync_test.go+9 −2internal/memoria/store.go+26 −1
diff --git a/internal/memoria/migrations/0010_alter_documents.sql b/internal/memoria/migrations/0010_alter_documents.sql| new file mode 100644 |
| index 0000000..5705416 |
| --- /dev/null |
| +++ b/internal/memoria/migrations/0010_alter_documents.sql |
| @@ -0,0 +1,2 @@ |
| +ALTER TABLE `documents` ADD `pending` numeric NOT NULL DEFAULT false; |
| + |
diff --git a/internal/memoria/migrations/schema.sql b/internal/memoria/migrations/schema.sql| index f5624a5..b9db332 100644 |
| --- a/internal/memoria/migrations/schema.sql |
| +++ b/internal/memoria/migrations/schema.sql |
| @@ -7,7 +7,7 @@ CREATE TABLE `chunks` (`id` integer PRIMARY KEY AUTOINCREMENT,`document_id` inte |
| CREATE TABLE `connectors` (`id` integer PRIMARY KEY AUTOINCREMENT,`kind` text NOT NULL,`sealed_token` blob NOT NULL,`workspace_print` text,`last_verified` datetime,`created_at` datetime,`updated_at` datetime); |
| -CREATE TABLE `documents` (`id` integer PRIMARY KEY AUTOINCREMENT,`source` text NOT NULL,`external_id` text NOT NULL,`revision` integer NOT NULL DEFAULT 1,`sealed_title` blob NOT NULL,`sealed_body` blob NOT NULL,`bytes` integer,`created_at` datetime,`updated_at` datetime, `body_print` text NOT NULL DEFAULT "", `sealed_path` blob, `sibling_item_id` blob, `sibling_revision` integer NOT NULL DEFAULT 0); |
| +CREATE TABLE `documents` (`id` integer PRIMARY KEY AUTOINCREMENT,`source` text NOT NULL,`external_id` text NOT NULL,`revision` integer NOT NULL DEFAULT 1,`sealed_title` blob NOT NULL,`sealed_body` blob NOT NULL,`bytes` integer,`created_at` datetime,`updated_at` datetime, `body_print` text NOT NULL DEFAULT "", `sealed_path` blob, `sibling_item_id` blob, `sibling_revision` integer NOT NULL DEFAULT 0, `pending` numeric NOT NULL DEFAULT false); |
| CREATE TABLE `fact_reports` (`id` integer PRIMARY KEY AUTOINCREMENT,`reporter_print` text NOT NULL,`sealed_report` blob NOT NULL,`created_at` datetime); |
diff --git a/internal/memoria/models.go b/internal/memoria/models.go| index 060b2b5..fde19e9 100644 |
| --- a/internal/memoria/models.go |
| +++ b/internal/memoria/models.go |
| @@ -90,6 +90,12 @@ type Document struct { |
| // coordinate is not content, and the count of edits is already |
| // inferable from row history. |
| SiblingRevision int64 `gorm:"not null;default:0"` |
| + // Pending marks a sibling document held from before a CURSOR_RESET |
| + // (suite doctrine §6.6, revision 11): soft-dropped, and hard-retired |
| + // when the re-read reaches the tip unless the re-read lists it again. |
| + // Hiding is not this column's job — the whole source is withheld while |
| + // its SiblingFeed is Reconciling — so it is read only by retirement. |
| + Pending bool `gorm:"not null;default:false"` |
| // SealedTitle and SealedBody are sealed under distinct HKDF purposes. |
| SealedTitle []byte `gorm:"not null"` |
| SealedBody []byte `gorm:"not null"` |
diff --git a/internal/memoria/sibling/policy.go b/internal/memoria/sibling/policy.go| index 2a1a924..f76d8ef 100644 |
| --- a/internal/memoria/sibling/policy.go |
| +++ b/internal/memoria/sibling/policy.go |
| @@ -205,7 +205,7 @@ func (o *Outcome) Lines() []string { |
| // number of passages it would have contributed is not a number |
| // about this page. |
| out = append(out, fmt.Sprintf( |
| - "%s is reconciling after a restore; its results are not on this page.", |
| + "%s is being re-read after a restore; its results are not on this page.", |
| k.app)) |
| } |
| } |
diff --git a/internal/memoria/sibling/policy_test.go b/internal/memoria/sibling/policy_test.go| index bd95a8d..fb59ed2 100644 |
| --- a/internal/memoria/sibling/policy_test.go |
| +++ b/internal/memoria/sibling/policy_test.go |
| @@ -161,7 +161,7 @@ func TestTheNoticesNameTheAppAndTheShapeOfTheLoss(t *testing.T) { |
| want := []string{ |
| "Sheets did not answer; 2 results withheld.", |
| "Docs has moved on from 1 result; refetching.", |
| - "Calendar is reconciling after a restore; its results are not on this page.", |
| + "Calendar is being re-read after a restore; its results are not on this page.", |
| } |
| if !reflect.DeepEqual(got, want) { |
| t.Errorf("notices =\n %s\nwant\n %s", |
diff --git a/internal/memoria/siblingreset_test.go b/internal/memoria/siblingreset_test.go| new file mode 100644 |
| index 0000000..86e745a |
| --- /dev/null |
| +++ b/internal/memoria/siblingreset_test.go |
| @@ -0,0 +1,211 @@ |
| +package memoria |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/suite" |
| +) |
| + |
| +// CURSOR_RESET, memoria's half (suite doctrine §6.6, revision 11): a |
| +// sibling restored from a backup answers 409 to the cursor memoria holds, |
| +// and memoria hides everything it holds from that sibling on every |
| +// surface, reads the feed again from the start, and at the tip deletes |
| +// whatever the re-read did not list. |
| +// |
| +// The search is the surface asked here; every other surface goes through |
| +// the same rule() (TestEverySurfaceAsksTheAppOfRecord), which is where the |
| +// withholding is. |
| +// |
| +// MUTATION-TESTED 2026-11-02, each seen red and reverted: |
| +// |
| +// rule() not withholding a reconciling source |
| +// -> "shown while being re-read" |
| +// cursorReset not discarding the cursor |
| +// -> the sibling is asked for the disowned cursor again ("unscripted") |
| +// cursorReset not marking documents pending |
| +// -> "survived the re-read" |
| +// unpend removed from applyRow |
| +// -> "the re-listed document was retired" |
| +// finishReread not clearing Reconciling |
| +// -> "still withheld after the re-read" |
| +// finishReread run on every page, not only at the tip |
| +// -> "retired before the re-read reached the tip" |
| +func TestACursorResetHidesThenReReadsThenRetires(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", 5, false), row("drop", 7, 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."}, |
| + } |
| + 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) |
| + } |
| + |
| + // 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. |
| + f.reset = map[string]bool{"old-1": true} |
| + f.pages[""] = suite.Feed{Cursor: "new-1", Rows: []suite.FeedRow{row("keep", 5, 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{}} |
| + |
| + res, err := s.Poll(ctx, client, sib) |
| + if err != nil || !res.Reset { |
| + t.Fatalf("reset poll = %+v, %v; want Reset and no error", res, err) |
| + } |
| + if got := cursorOf(t, s, "Docs"); got != "" { |
| + t.Errorf("cursor after a reset = %q, want discarded", got) |
| + } |
| + got := nebula(t, s, asker) |
| + if got.n != 0 { |
| + t.Fatalf("shown while being re-read: %d results", got.n) |
| + } |
| + 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 { |
| + t.Errorf("the reset deleted something; it may only hide (step 1 is a soft drop)") |
| + } |
| + |
| + // The re-read, stopped after its first page: nothing is retired yet, |
| + // and the source stays hidden. |
| + f.failS1 = map[string]bool{"new-1": true} |
| + if _, err := s.Poll(ctx, client, sib); err == nil { |
| + t.Fatal("the scripted failure did not fail") |
| + } |
| + if heldCount(t, s, "Docs") != 2 { |
| + t.Fatal("retired before the re-read reached the tip") |
| + } |
| + if got := nebula(t, s, asker); got.n != 0 { |
| + t.Fatalf("shown while being re-read (after a partial re-read): %d", got.n) |
| + } |
| + |
| + // The re-read completes. |
| + f.failS1 = nil |
| + if _, err := s.Poll(ctx, client, sib); err != nil { |
| + 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")) |
| + } |
| + 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) |
| + } |
| +} |
| + |
| +// At most one reset per re-read (§6.6, Fable's M1): a second reset before |
| +// the tip is a failure, everything stays hidden, and only a later re-read |
| +// that completes decides what survives — including a document the |
| +// abandoned re-read had already fetched again. |
| +// |
| +// MUTATION-TESTED 2026-11-02, each seen red and reverted: cursorReset |
| +// returning nil on a second reset -> "a second reset was not a failure"; |
| +// the second reset not re-marking pending -> "survived". |
| +func TestASecondResetBeforeTheTipIsAFailure(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("a", 1, false), row("b", 2, false)}}, |
| + "old-1": {Cursor: "old-1", Rows: []suite.FeedRow{}}, |
| + }, |
| + bodies: map[string]string{"a": "nebula a", "b": "nebula b"}, |
| + } |
| + sib, client := f.start(t) |
| + if _, err := s.Poll(ctx, client, sib); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.reset = map[string]bool{"old-1": true} |
| + if res, err := s.Poll(ctx, client, sib); err != nil || !res.Reset { |
| + t.Fatalf("first reset = %+v, %v", res, err) |
| + } |
| + |
| + // The re-read lists "b", then resets again on its own cursor. |
| + f.pages[""] = suite.Feed{Cursor: "mid", Rows: []suite.FeedRow{row("b", 2, false)}} |
| + f.reset["mid"] = true |
| + _, err := s.Poll(ctx, client, sib) |
| + if !errors.Is(err, errResetTwice) { |
| + t.Fatalf("a second reset was not a failure: %v", err) |
| + } |
| + if got := nebula(t, s, asker); got.n != 0 { |
| + t.Fatalf("shown after a failed re-read: %d", got.n) |
| + } |
| + |
| + // A later re-read lists only "a" and completes: "b", fetched by the |
| + // abandoned re-read, must not survive on that re-read's word. |
| + f.reset = nil |
| + f.pages[""] = suite.Feed{Cursor: "end", Rows: []suite.FeedRow{row("a", 1, false)}} |
| + f.pages["end"] = suite.Feed{Cursor: "end", Rows: []suite.FeedRow{}} |
| + if _, err := s.Poll(ctx, client, sib); err != nil { |
| + t.Fatalf("later re-read: %v", err) |
| + } |
| + if heldCount(t, s, "Docs") != 1 { |
| + t.Fatalf("\"b\" survived: %d Docs documents, want 1", heldCount(t, s, "Docs")) |
| + } |
| + assertHeld(t, s, "Docs", "a", 1) |
| +} |
| + |
| +// A reset answered to the start of the feed is a broken producer, not an |
| +// instruction: nothing is hidden or dropped on its word. |
| +// |
| +// MUTATION-TESTED 2026-11-02: the cursor == "" check removed -> "hidden". |
| +func TestAResetAtTheStartDropsNothing(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: "c", Rows: []suite.FeedRow{row("a", 1, false)}}, "c": {Cursor: "c", Rows: []suite.FeedRow{}}}, |
| + bodies: map[string]string{"a": "nebula a"}, |
| + } |
| + sib, client := f.start(t) |
| + if _, err := s.Poll(ctx, client, sib); err != nil { |
| + t.Fatal(err) |
| + } |
| + // The stored cursor is lost (say, a fresh row), and the producer |
| + // answers reset to "". |
| + if err := s.db.G.Model(&SiblingFeed{}).Where("app = ?", "Docs").Update("sealed_cursor", nil).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + f.reset = map[string]bool{"": true} |
| + if _, err := s.Poll(ctx, client, sib); !errors.Is(err, errResetAtStart) { |
| + t.Fatalf("a reset to the start = %v, want errResetAtStart", err) |
| + } |
| + if got := nebula(t, s, asker); got.n != 1 { |
| + t.Fatalf("hidden on a broken producer's word: %d results", got.n) |
| + } |
| +} |
| + |
| +type found struct { |
| + n int |
| + notices string |
| +} |
| + |
| +func nebula(t *testing.T, s *Store, asker suite.Subject) found { |
| + t.Helper() |
| + page, err := s.Search(context.Background(), asker, "nebula", 10) |
| + if err != nil { |
| + t.Fatalf("search: %v", err) |
| + } |
| + return found{len(page.Results), strings.Join(page.Notices, " | ")} |
| +} |
diff --git a/internal/memoria/siblingsync.go b/internal/memoria/siblingsync.go| index 388fd00..b460900 100644 |
| --- a/internal/memoria/siblingsync.go |
| +++ b/internal/memoria/siblingsync.go |
| @@ -48,8 +48,26 @@ type PollResult struct { |
| // memoria holds is consistent; it is not current, and the sources |
| // page must not say it is. |
| More bool |
| + // Reset means the sibling answered CURSOR_RESET (suite doctrine §6.6, |
| + // revision 11) and this poll soft-dropped everything held from it. |
| + // The re-read starts on the next poll, never in this one: "every |
| + // re-read … waits on the consumer's ordinary backoff", and memoria's |
| + // is the wake. |
| + Reset bool |
| } |
| +// errResetTwice is §6.6's "at most one reset per re-read": a second |
| +// CURSOR_RESET before the re-read reached the tip is a failure of that |
| +// producer, not another reset. What was held stays pending and withheld |
| +// (the source stays Reconciling); the next poll starts a later re-read. |
| +var errResetTwice = errors.New("a second cursor reset before the re-read reached the tip") |
| + |
| +// errResetAtStart is a CURSOR_RESET answered to the empty cursor, which |
| +// §6.6 says is never reset (the module's server answers 500 rather than |
| +// write one). A producer doing it is broken; nothing is dropped on its |
| +// word, and the poll fails. |
| +var errResetAtStart = errors.New("a cursor reset answered to the start of the feed") |
| + |
| // Poll brings memoria's copy of one sibling's content up to date. |
| // |
| // **The cursor advances only after a page has been fully applied**, and |
| @@ -90,6 +108,16 @@ func (s *Store) Poll(ctx context.Context, c *sibling.Client, sib sibling.Sibling |
| return res, nil |
| } |
| feed, err := c.Feed(ctx, sib, cursor) |
| + if errors.Is(err, suite.ErrCursorReset) { |
| + // The rows already applied on earlier pages of this poll came |
| + // from the log the producer has just disowned; soft-dropping |
| + // marks them pending with everything else. |
| + if cursor == "" { |
| + return res, fmt.Errorf("poll %s: %w", sib.Name, errResetAtStart) |
| + } |
| + res.Reset = true |
| + return res, s.cursorReset(ctx, sib.Name) |
| + } |
| if err != nil { |
| return res, fmt.Errorf("poll %s: %w", sib.Name, err) |
| } |
| @@ -117,6 +145,11 @@ func (s *Store) Poll(ctx context.Context, c *sibling.Client, sib sibling.Sibling |
| // stop and say the poll did not conclude. |
| res.More = len(feed.Rows) > 0 |
| if !res.More { |
| + // The tip. A re-read after a reset ends here, and only here: |
| + // §6.6 step 3 retires what the complete re-read did not list. |
| + if err := s.finishReread(ctx, sib.Name, &res); err != nil { |
| + return res, err |
| + } |
| if err := s.markPolled(ctx, sib.Name); err != nil { |
| return res, err |
| } |
| @@ -195,10 +228,105 @@ func (s *Store) applyRow(ctx context.Context, c *sibling.Client, sib sibling.Sib |
| case err != nil: |
| return err |
| } |
| + // Listed by the re-read and fetched again, so it is no longer a |
| + // leftover of the disowned log (§6.6 step 2). A row that 404s or is |
| + // empty above returns before this and stays pending: memoria cannot |
| + // show that its copy is one the restored log still has, so the tip |
| + // retires it. |
| + if err := s.unpend(ctx, sib.Name, row.ItemID); err != nil { |
| + return err |
| + } |
| res.Stored++ |
| return nil |
| } |
| +// cursorReset is §6.6 step 1, on CURSOR_RESET: every document held from |
| +// app is marked pending, the source is marked Reconciling — which takes |
| +// it off every surface, because rule() withholds a reconciling source |
| +// wholesale — and the cursor is discarded, so the next poll reads from |
| +// "". One transaction: a crash between the three must not leave a source |
| +// shown with its cursor gone, or hidden with its cursor kept. |
| +// |
| +// A source already Reconciling is in a re-read that has not reached the |
| +// tip, and this is its second reset: errResetTwice. The marking is done |
| +// all the same — documents the abandoned re-read had fetched go back to |
| +// pending, so only a re-read that completes decides what survives. |
| +func (s *Store) cursorReset(ctx context.Context, app string) error { |
| + var again bool |
| + err := s.db.G.WithContext(ctx).Transaction(func(tx *gormTx) error { |
| + var row SiblingFeed |
| + err := tx.Where("app = ?", app).First(&row).Error |
| + switch { |
| + case errors.Is(err, errRecordNotFound): |
| + // A reset with no stored cursor cannot happen (Poll refuses a |
| + // reset on ""), but a feed row is what holds the state, so make |
| + // one rather than reason about it. |
| + row = SiblingFeed{App: app} |
| + if err := tx.Create(&row).Error; err != nil { |
| + return err |
| + } |
| + case err != nil: |
| + return err |
| + } |
| + again = row.Reconciling |
| + if err := tx.Model(&Document{}).Where("source = ?", app).Update("pending", true).Error; err != nil { |
| + return err |
| + } |
| + return tx.Model(&SiblingFeed{}).Where("id = ?", row.ID). |
| + Updates(map[string]any{"reconciling": true, "sealed_cursor": nil}).Error |
| + }) |
| + if err != nil { |
| + return err |
| + } |
| + if again { |
| + return fmt.Errorf("poll %s: %w", app, errResetTwice) |
| + } |
| + return nil |
| +} |
| + |
| +// unpend clears Pending on the document a re-read has just fetched again. |
| +func (s *Store) unpend(ctx context.Context, app, itemID string) error { |
| + external, err := s.externalID(itemID) |
| + if err != nil { |
| + return err |
| + } |
| + return s.db.G.WithContext(ctx).Model(&Document{}). |
| + Where("source = ? AND external_id = ? AND pending = ?", app, external, true). |
| + Update("pending", false).Error |
| +} |
| + |
| +// finishReread is §6.6 step 3, at the tip: if app is Reconciling, every |
| +// document still pending is deleted — through Store.Delete, so the index |
| +// goes first — and only then is the source shown again. A delete that |
| +// fails leaves it Reconciling, and the next poll, at the tip again, |
| +// finishes the job. |
| +func (s *Store) finishReread(ctx context.Context, app string, res *PollResult) error { |
| + var row SiblingFeed |
| + err := s.db.G.WithContext(ctx).Where("app = ?", app).First(&row).Error |
| + switch { |
| + case errors.Is(err, errRecordNotFound): |
| + return nil |
| + case err != nil: |
| + return err |
| + } |
| + if !row.Reconciling { |
| + return nil |
| + } |
| + var docs []Document |
| + if err := s.db.G.WithContext(ctx).Select("id"). |
| + Where("source = ? AND pending = ?", app, true).Find(&docs).Error; err != nil { |
| + return err |
| + } |
| + for _, d := range docs { |
| + if err := s.Delete(ctx, d.ID); err != nil { |
| + return err |
| + } |
| + res.Deleted++ |
| + } |
| + return s.db.G.WithContext(ctx).Model(&SiblingFeed{}).Where("id = ?", row.ID). |
| + Update("reconciling", false).Error |
| +} |
| + |
| // cursor reads memoria's position in one sibling's feed. |
| // |
| // **A cursor that will not open is an error, never an empty cursor.** An |
diff --git a/internal/memoria/siblingsync_test.go b/internal/memoria/siblingsync_test.go| index aa25abd..fcb2c3b 100644 |
| --- a/internal/memoria/siblingsync_test.go |
| +++ b/internal/memoria/siblingsync_test.go |
| @@ -32,8 +32,10 @@ type feedServer struct { |
| // forbidS3 answers 403, which is a CONTRACT BREACH and a third thing |
| // again: the sibling is telling callers which ids exist. |
| forbidS3 map[string]bool |
| - s1Calls int |
| - s3Calls int |
| + // reset answers CURSOR_RESET to these cursors (suite doctrine §6.6). |
| + reset map[string]bool |
| + s1Calls int |
| + s3Calls int |
| } |
| func (f *feedServer) start(t *testing.T) (sibling.Sibling, *sibling.Client) { |
| @@ -50,6 +52,11 @@ func (f *feedServer) start(t *testing.T) (sibling.Sibling, *sibling.Client) { |
| _, _ = w.Write([]byte(`{"cursor":"","rows":[]}`)) |
| return |
| } |
| + if f.reset[cur] { |
| + w.WriteHeader(suite.CursorResetStatus) |
| + _, _ = w.Write([]byte(suite.CursorResetBody)) |
| + return |
| + } |
| page, ok := f.pages[cur] |
| if !ok { |
| f.t.Errorf("sibling asked for an unscripted cursor %q", cur) |
diff --git a/internal/memoria/store.go b/internal/memoria/store.go| index 0534110..f27038d 100644 |
| --- a/internal/memoria/store.go |
| +++ b/internal/memoria/store.go |
| @@ -955,6 +955,12 @@ func (s *Store) rule(ctx context.Context, asker suite.Subject, all []Result) Pag |
| disp := make([]sibling.Disposition, len(all)) |
| var cands []sibling.Candidate |
| var at []int |
| + // Sources being re-read after a CURSOR_RESET (suite doctrine §6.6): |
| + // everything held from them is withheld, by app, with one line saying |
| + // so, and nobody is asked about it. A failed read of the set withholds |
| + // every sibling passage — the zero disposition — rather than guess that |
| + // none is being re-read. |
| + rereading, rerr := s.reconcilingSources(ctx) |
| for i, r := range all { |
| if r.item.Item.ItemID == "" { |
| // memoria-owned: §4.2 makes memoria the app of record, and |
| @@ -962,7 +968,11 @@ func (s *Store) rule(ctx context.Context, asker suite.Subject, all []Result) Pag |
| disp[i] = sibling.Render |
| continue |
| } |
| - if s.custody == nil { |
| + if s.custody == nil || rerr != nil { |
| + continue |
| + } |
| + if rereading[r.Source] { |
| + disp[i] = sibling.WithholdAndReannounce |
| continue |
| } |
| sib, ok := s.custody.Sibling(r.Source) |
| @@ -1033,6 +1043,21 @@ func (s *Store) rule(ctx context.Context, asker suite.Subject, all []Result) Pag |
| return page |
| } |
| +// reconcilingSources is the set of apps whose feed is Reconciling: soft- |
| +// dropped by a CURSOR_RESET and not yet re-read to the tip. |
| +func (s *Store) reconcilingSources(ctx context.Context) (map[string]bool, error) { |
| + var apps []string |
| + if err := s.db.G.WithContext(ctx).Model(&SiblingFeed{}). |
| + Where("reconciling = ?", true).Pluck("app", &apps).Error; err != nil { |
| + return nil, err |
| + } |
| + out := make(map[string]bool, len(apps)) |
| + for _, a := range apps { |
| + out[a] = true |
| + } |
| + return out, nil |
| +} |
| + |
| // Recent lists the n most recently updated documents, titles and paths |
| // opened, for the front page. One query and n opens, not Summaries' read |
| // of everything with a passage count each: the front page loads on every |