{
  "schema_version": "1.3.0",
  "slug": "when-does-cursor-pagination-over-a-mutating-sort-key-skip-or-duplicate-rows",
  "title": "When does cursor pagination over a mutating sort key skip or duplicate rows?",
  "date_of_record": "2026 November 1",
  "scope": "Applies to keyset (cursor) pagination where the cursor encodes a sort key that can change between page requests. Excludes offset pagination and append-only tables with immutable sort keys.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-does-cursor-pagination-over-a-mutating-sort-key-skip-or-duplicate-rows.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-does-cursor-pagination-over-a-mutating-sort-key-skip-or-duplicate-rows.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-does-cursor-pagination-over-a-mutating-sort-key-skip-or-duplicate-rows.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 865,
    "python_slice_tokens": 118,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "**Predicate.** Keyset pagination is stable if and only if the sort key is immutable and unique. Given a cursor on key k, the next page is all rows with sort > k. If a row's sort value moves from below k to above k between pages, it is returned twice; if it moves from above to below, it is skipped entirely. **Failure.** A row updated between page fetches chan...",
    "what_was_observed": "**Signature.** Export counts that differ from table counts by a few rows, varying per run. Rows updated during the export are the missing or doubled ones. The defect rate tracks write rate during pagination. **Trace.** Sort key is updated_at. Export begins at t0 with cursor (updated_at=t0). A row updated at t1 > t0 was already read on page 1 and now sorts after the current cursor, so it appears again on page 3. A row...",
    "condition_of_validity": "Pagination returns an exact partition only while at least one holds: 1. **Immutable sort key.** The key is assigned at insert and never updated, and is unique (monotonic id, ULID, sequence). 2. **Snapshot.** All pages are read from a single snapshot or point-in-time view with a stable visibility boundary. 3. **Deduplication.** The client deduplicates by prim...",
    "decision_boundary": "- Immutable unique sort key: exact partition. - Mutable sort key with snapshot reads: exact for the snapshot; the export reflects the state at snapshot time, not at completion. - Mutable sort key, no snapshot: skips and duplicates are guaranteed whenever writes overlap pagination. - Mutable sort key plus client dedup: duplicates removed, gaps remain. Treat a...",
    "operational_effect": "The invariant couples read correctness to write concurrency, which no pagination API surfaces. Remediation is a key change or a snapshot read, not a client fix. The trap is to switch to offset pagination to get a total count. That trades silent skips for the well-known offset drift, which at least shifts consistently, and it does not fix anything for a mutat..."
  },
  "matched_failure_symptoms": [
    "PAGINATION_DRIFT_OR_INCOMPLETE_SCAN"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "fd134ccf12ac80af41f7dbb946f9a6f3fda0f12e1f99d9813198a1d34801fdd2",
    "verified_classes": [
      "CursorStabilityError",
      "CursorGate"
    ],
    "verified_functions": [
      "dispatch_pagination",
      "verify"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "CursorStabilityError"
    ],
    "sample_fail_closed_invariants": [
      "sort key is not unique: ties split across pages",
      "mutable sort key without snapshot read: rows may skip or repeat"
    ],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
