{
  "schema_version": "1.3.0",
  "slug": "across-what-keyset-cursor-and-limit-ceiling-boundaries-must-an-instance-paginate-collection-queries-to-prevent-offset-scan-degradation-and-unbounded-result-oom",
  "title": "Across what keyset-cursor and limit-ceiling boundaries must an instance paginate collection queries to prevent offset-scan degradation and unbounded-result OOM?",
  "date_of_record": "2026 October 20",
  "scope": "* **Applies when:** An AI instance, autonomous coding agent, or backend service implements paginated API endpoints, infinite-scroll feeds, batch database table iterators, or filtered collection queries. * **Does not apply when:** Fetching a",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/across-what-keyset-cursor-and-limit-ceiling-boundaries-must-an-instance-paginate-collection-queries-to-prevent-offset-scan-degradation-and-unbounded-result-oom.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/across-what-keyset-cursor-and-limit-ceiling-boundaries-must-an-instance-paginate-collection-queries-to-prevent-offset-scan-degradation-and-unbounded-result-oom.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/across-what-keyset-cursor-and-limit-ceiling-boundaries-must-an-instance-paginate-collection-queries-to-prevent-offset-scan-degradation-and-unbounded-result-oom.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2978,
    "python_slice_tokens": 573,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Autonomous systems frequently expose collection endpoints (`GET /api/events`, `GET /api/users`) or iterate through multi-million-row database tables for batch processing. A foundational scalability and correctness failure occurs when an instance implements collection retrieval via **unbounded `SELECT *` queries** (`cursor.fetchall()` without a `LIMIT`), or r...",
    "what_was_observed": "In production API list endpoints, admin data exports, and batch table-migration traces, instances operating without explicit keyset-cursor and limit-ceiling gates exhibit four primary failure modes: 1. **Unbounded `SELECT` / `.all()` Memory Exhaustion:** An instance implements a list endpoint or background sync job with `session.query(Order).filter_by(status=\"completed\").all()` (or `SELECT * FROM orders` with no `LIM...",
    "condition_of_validity": "* **Applies when:** An AI instance, autonomous coding agent, or backend service implements paginated API endpoints, infinite-scroll feeds, batch database table iterators, or filtered collection queries. * **Does not apply when:** Fetching a bounded, small static lookup table (such as the 50 US states or 10 system roles) or jumping to small shallow page numbe...",
    "decision_boundary": "1. **Did you write a `SELECT` query or ORM `.all()` call that returns multiple rows without a `LIMIT`?** Add a `LIMIT` immediately, and clamp any user-provided `limit` parameter (`min(max(1, limit), 100)`) so a caller cannot ask for 10 million rows in one response. 2. **Are you using `OFFSET` to iterate through a table or serve pages?** Replace `OFFSET` with...",
    "operational_effect": "1. **Universal Clamped Limits on Collection Queries:** Across all generated list endpoints and batch readers, the instance enforces a server-side maximum page limit (`clamp_page_limit`) and never executes unbounded `SELECT *` queries on dynamic tables. 2. **Tie-Broken Keyset Seek Pagination:** Generated pagination logic pairs primary sort columns with unique..."
  },
  "matched_failure_symptoms": [
    "HTTP_502_503_504_CASCADE",
    "OOM_KILL_OR_MEMORY_EXHAUSTION",
    "PAGINATION_DRIFT_OR_INCOMPLETE_SCAN"
  ],
  "composition_edges": {
    "primary_domain": "schema_and_interface_version_drift",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/across-what-encoding-and-canonicalization-boundaries-must-an-instance-normalize-identifiers-and-paths-to-prevent-equivalence-collision-and-bypass.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/along-what-complexity-bounds-must-an-instance-arrest-premature-abstraction-and-speculative-over-engineering-when-synthesizing-solutions.md",
      "https://corpusfetch.com/c/across-what-deadline-propagation-and-cancellation-cascade-gates-must-an-instance-govern-grpc-and-http2-calls-to-prevent-zombie-worker-exhaustion-and-wasted-compute.md"
    ],
    "co_occurring_sibling_residuals": [
      "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",
      "https://corpusfetch.com/c/across-what-composite-tie-breaker-and-stable-cursor-gates-must-an-instance-merge-distributed-queries-to-prevent-pagination-drift-and-record-duplication.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "1293378c9ef2c33b4ecc0f712fd1bfd56ae92a6a6e3cf6cfe669ca0a9f406c21",
    "verified_classes": [
      "KeysetPage"
    ],
    "verified_functions": [
      "clamp_page_limit",
      "encode_keyset_cursor",
      "decode_keyset_cursor",
      "fetch_events_keyset_page"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "TypeError",
      "ValueError"
    ],
    "sample_fail_closed_invariants": [
      "Pagination limit must be an integer",
      "Pagination limit must be >= 1",
      "Invalid or oversized pagination cursor",
      "Boolean cursor values are forbidden"
    ],
    "stdlib_dependencies": [
      "base64",
      "dataclasses",
      "json",
      "sqlite3",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
