Skip to content

feat(data): host-configured default and maximum page size for list, report and analytics reads, and a per-query row budget, refused with a code naming the limit - #29796

Merged
objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/project-thread-27ujkv
Nov 3, 2026
Merged

objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/project-thread-27ujkv

Conversation

@os-zhuang

@os-zhuang os-zhuang commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Sam · project thread

Part of #29783

This PR is the whole of that card. It says Part of rather than a closing keyword because the card's claim names no claude/issue-* branch and this PR's head branch cannot take that shape, so check:closing-target-claim could never pass with a closing keyword. The seat closes the card when this lands.

What changes

A deployment can now bound how many rows one data API read returns and walks, through three host variables. Each is a positive integer; all three unset is today's behaviour exactly.

Variable Meaning Unset
OS_DATA_DEFAULT_PAGE_SIZE the page a read gets when it names no limit the maximum when one is set, else no default
OS_DATA_MAX_PAGE_SIZE the largest limit a read may name no maximum
OS_DATA_QUERY_ROW_BUDGET the most rows one query may walk: offset plus the rows it returns no budget

The documented rule for a request over a limit is refuse, never clamp. A clamp answers a different page from the one asked for: a caller paging by its own limit would skip the rows in between, and an analytics answer has no hasMore to say a chart was cut. So:

  • a limit over the maximum → 400 MAX_RECORDS_EXCEEDED, the existing standard code for a caller-side limit (the request asked for more rows than a request may carry), naming the spelling the caller wrote ($top / top / limit) and the maximum;
  • offset + limit over the budget → 400 QUERY_ROW_BUDGET_EXCEEDED, naming the budget. This is a new code because the budget bounds how deep a query walks, not how big a page is: a page well within the maximum is refused at a deep enough offset.

Both are refused before the driver is asked (a budget probe, below, runs first and refuses on its answer). Each refusal writes one warn line: [data] read refused: code=… surface=list|analytics object=… rows=… limit=…. The line carries the object and counts, never a row value.

A read that names no limit:

  • List reads (GET /data/:object, POST /data/:object/query, grouped or flat, through findData) run with the default page size as their limit. The answer already says when more rows exist (hasMore, total), so this is an ordinary first page.
  • Analytics reads (AnalyticsService.query() behind /analytics/query, and queryDataset(), the dataset door reports and dashboards read through) run with one row more than the default page. An answer with more rows than the default is refused with MAX_RECORDS_EXCEEDED, telling the caller to name a limit and page with offset. The analytics doors judge the caller's own window; the dataset executor's internal passes (totals, measure-scoped queries) are not judged separately.
  • A budget with no page size probes one row more than the budget leaves after the offset. An answer over the budget is refused, and one that fits is served whole (the probe limit is taken back off, so hasMore / total read as an unpaged answer).

Where it lives:

  • @objectstack/types query-read-limits.ts holds the rule: resolveQueryReadLimits (strict: a value that is not a positive integer, or a default above the maximum, throws naming the variable), planQueryReadWindow, assertQueryReadRows, and the abstract QueryReadLimitError (limit) with one subclass per code, QueryPageSizeExceededError (MAX_RECORDS_EXCEEDED) and QueryRowBudgetExceededError (QUERY_ROW_BUDGET_EXCEEDED), each declaring its own code and status 400 so check:error-status-conformance pins the catalog's status. MAX_RECORDS_EXCEEDED gains its first producer, so it leaves scripts/error-status-unpinned-baseline.json (the shrink-only direction).
  • metadata-protocol findData plans every list read after the shape gates and before the engine.
  • service-analytics query() and queryDataset() plan the caller's window at the public doors.
  • Both constructors resolve the limits once, so a misconfigured variable fails the boot instead of 500-ing every read.
  • QUERY_ROW_BUDGET_EXCEEDED is registered in the error-code ledger under @objectstack/types, with a line on why it is not MAX_RECORDS_EXCEEDED; the references pages are regenerated; content/docs/api/data-api.mdx documents the three variables and the refusal rule; content/docs/api/error-catalog.mdx gains a QUERY_ROW_BUDGET_EXCEEDED entry, names the page-size cause under MAX_RECORDS_EXCEEDED, and counts 57 wire codes.

What the budget does not count: rows a database scans inside an aggregate or behind an unindexed filter. The data API cannot see those, so the budget counts the rows a query walks through its window. The expand sub-reads, the export route and internal engine reads (backfills, sweeps) are not data API list reads and are untouched.

Why

The maintainer's 2026-11-03 04:26Z instruction on the cloud plan decision, verbatim: 「同意:在代码里补两个保护再谈放宽:查询扫描行预算和强制分页;每周看板加「每个 Team 组织的数据库大小与行读量」。第 3 个月闸门前有这两组数,再决定存储包价格和数据边界的数字。」

The hosted data plane runs this data API, and on main there was no general page-size cap in it or in the SQL / libSQL drivers (re-checked at 946a173f: driver-odata's pageSize is only for its own upstream, and MCP's maxQueryLimit only for its own tool). Cloud sets the numbers in its own card (cloud#3510) once a pin carries this.

Verification

  • packages/types/src/query-read-limits.test.ts (18): configuration (unset, all three, strict refusal of 0 / -5 / 1.5 / abc / 10k / 1e3, default above maximum), no limits leave every read untouched, refusal shape (status, code, limit, message, the one log line with no row value), the default page, the analytics probe, the budget (including the default page counting against it, and the budget-only probe), and both codes resolving verbatim at 400 through resolveThrownHttpError.
  • packages/rest/src/data-query-read-limits.test.ts (6, real SqlDriver over SQLite, both list doors): defaults unchanged with nothing set (every row, a 100,000 limit, a grouped read), the default page with hasMore: true / total: 5, a limit within the maximum, MAX_RECORDS_EXCEEDED on $top, top, limit and a grouped read with the driver never called, QUERY_ROW_BUDGET_EXCEEDED with the driver never called, and a budget-only read refused when it overruns and served whole (hasMore: false, total: 5) when it fits.
  • packages/services/service-analytics/src/__tests__/query-read-limits.test.ts (8): both analytics doors unchanged with nothing set (no LIMIT, 500 rows served), the probe reaching the query (limit: 4) and the SQL (LIMIT 4), an answer past the default refused with the log line, a caller's own limit run as asked, over-maximum and over-budget refused with nothing run, and the budget-only probe.
  • data-page-window-door.test.ts (the existing window pins) still passes. Full local suites: types 860 tests, metadata-protocol 310 files, service-analytics 4,958 tests, rest 7,139 tests, all passing.
  • pnpm typecheck for types, metadata-protocol, service-analytics and rest (with its test layer); eslint on every touched file; node scripts/check-error-status-conformance.mjs green; spec error-code-ledger.test.ts green; pnpm --filter @objectstack/spec check:generated named content/docs/references/** stale, regenerated with gen:docs; check-doc-anchors resolves the new catalog links; check-error-status-conformance (and its self-test) green.
  • node scripts/pm/dispatch-gates.mjs --tier: no path-derived tier mandate. Its Clause ② hint fires on packages/spec/src/api/error-code-ledger.zod.ts: the new code widens the published ErrorCode vocabulary, so a contract-tier review is owed before the queue.

Clause-②: yes (widening)
Metadata-protocol: none

What Clause-② widens: the published error-code vocabulary. ErrorCode (the union ApiErrorSchema.code parses against) gains one registered member, QUERY_ROW_BUDGET_EXCEEDED. A page size over the maximum answers the existing standard MAX_RECORDS_EXCEEDED (400), which gains its first producer. No metadata an author writes changes, and no existing code, status or response shape moves.

Keep one value on each of the two lines above, each line starting with its key.
Human Minimum
item 5 says what they mean.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QUs3BtTosRanM94rtudkMk


Generated by Claude Code

@os-zhuang os-zhuang self-assigned this Nov 3, 2026
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 4 package(s): @objectstack/metadata-protocol, @objectstack/service-analytics, @objectstack/spec, @objectstack/types, touching 33 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/types/src/index.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

14 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/api/client-sdk.mdx (via ERROR_CODE_LEDGER (symbol, a top-level const object))
  • content/docs/api/data-api.mdx (via MAX_RECORDS_EXCEEDED (symbol, a top-level const object), QUERY_ROW_BUDGET_EXCEEDED (symbol, a top-level const object), MAX_RECORDS_EXCEEDED (literal, a string literal in MAX_RECORDS_EXCEEDED), OS_DATA_DEFAULT_PAGE_SIZE (literal, a string literal in DATA_DEFAULT_PAGE_SIZE_ENV), OS_DATA_MAX_PAGE_SIZE (literal, a string literal in DATA_MAX_PAGE_SIZE_ENV), OS_DATA_QUERY_ROW_BUDGET (literal, a string literal in DATA_QUERY_ROW_BUDGET_ENV), QUERY_ROW_BUDGET_EXCEEDED (literal, a string literal in ERROR_CODE_LEDGER; a string literal in QUERY_ROW_BUDGET_EXCEEDED), /:object/export (route, bridged from symbol limitParam — its route source's handler names it))
  • content/docs/api/error-catalog.mdx (via ERROR_CODE_LEDGER (symbol, a top-level const object), MAX_RECORDS_EXCEEDED (symbol, a top-level const object), QUERY_ROW_BUDGET_EXCEEDED (symbol, a top-level const object), MAX_RECORDS_EXCEEDED (literal, a string literal in MAX_RECORDS_EXCEEDED), OS_DATA_DEFAULT_PAGE_SIZE (literal, a string literal in DATA_DEFAULT_PAGE_SIZE_ENV), OS_DATA_MAX_PAGE_SIZE (literal, a string literal in DATA_MAX_PAGE_SIZE_ENV), OS_DATA_QUERY_ROW_BUDGET (literal, a string literal in DATA_QUERY_ROW_BUDGET_ENV), QUERY_ROW_BUDGET_EXCEEDED (literal, a string literal in ERROR_CODE_LEDGER; a string literal in QUERY_ROW_BUDGET_EXCEEDED))
  • content/docs/api/error-handling-server.mdx (via ERROR_CODE_LEDGER (symbol, a top-level const object))
  • content/docs/concepts/metadata-lifecycle.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it))
  • content/docs/data-modeling/queries.mdx (via findData (symbol, a method of class ObjectStackProtocolImplementation))
  • content/docs/data-modeling/schema-design.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it))
  • content/docs/deployment/cli.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it))
  • content/docs/kernel/contracts/data-engine.mdx (via ERROR_CODE_LEDGER (symbol, a top-level const object))
  • content/docs/kernel/services-checklist.mdx (via findData (symbol, a method of class ObjectStackProtocolImplementation))
  • content/docs/permissions/permission-sets.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it))
  • content/docs/protocol/objectql/query-syntax.mdx (via findData (symbol, a method of class ObjectStackProtocolImplementation))
  • content/docs/protocol/objectui/actions.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it))
  • content/docs/ui/actions.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it))

⛔ 8 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v15.mdx (via findData (symbol, a method of class ObjectStackProtocolImplementation))
  • content/docs/releases/v16.mdx (via queryDataset (symbol, a method of class AnalyticsService))
  • content/docs/releases/v17/17-0.mdx (via ERROR_CODE_LEDGER (symbol, a top-level const object))
  • content/docs/releases/v17/17-1.mdx (via ERROR_CODE_LEDGER (symbol, a top-level const object))
  • content/docs/releases/v17/17-4.mdx (via ERROR_CODE_LEDGER (symbol, a top-level const object))
  • content/docs/releases/v17/17-5.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it))
  • content/docs/releases/v17/17-6.mdx (via /:object/export (route, bridged from symbol limitParam — its route source's handler names it), /api/v1/analytics/dataset/query (route, the route ledger binds it to client method analytics.queryDataset))
  • content/docs/releases/v9.mdx (via queryDataset (symbol, a method of class AnalyticsService))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/types/src/index.ts) — pages documenting those are invisible to this run
  • 1 cross-cutting symbol(s) contributed no route anchor: findData (4 routes)
  • 7 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 61 of 219 client-bound route-ledger rows — the other 158 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 158: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 55 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 103 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 171 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 99c069652e82e4417fd4cd2f46ee83176f9bab98 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 012cd7e535f9291023fc6a48538bbf6f3d066662 — the merge of head cbe0f85dd699d3116ea791b8b671fae1da81c294 into base 99c069652e82e4417fd4cd2f46ee83176f9bab98, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 012cd7e535f9291023fc6a48538bbf6f3d066662 && git checkout 012cd7e535f9291023fc6a48538bbf6f3d066662
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 99c069652e82e4417fd4cd2f46ee83176f9bab98 cbe0f85dd699d3116ea791b8b671fae1da81c294 && git checkout -B drift-repro 99c069652e82e4417fd4cd2f46ee83176f9bab98 && git merge --no-ff cbe0f85dd699d3116ea791b8b671fae1da81c294

node scripts/docs-audit/affected-docs.mjs --json 99c069652e82e4417fd4cd2f46ee83176f9bab98

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 99c069652e82e4417fd4cd2f46ee83176f9bab98 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@github-actions github-actions Bot added size/xl and removed size/l labels Nov 3, 2026
…ate reads a producer

check:error-status-conformance reads a class declaring both its code and its
status; the shared class took its code as a constructor argument, so the
catalog's 400 for QUERY_PAGE_SIZE_EXCEEDED and QUERY_ROW_BUDGET_EXCEEDED had no
producer it could pin. QueryPageSizeExceededError and QueryRowBudgetExceededError
each declare their own pair under the abstract QueryReadLimitError.

Claude-Session: https://claude.ai/code/session_01QUs3BtTosRanM94rtudkMk
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor

repo:cloud#2 · os-zhuang · session_0123kRqqdpAJWYMgsgdAJX4G

Contract-review record · 2026-11-03T07:12Z · CONTRACT_REVIEW_TIER (fable, by an at-tier reviewer) on a69e1db4 · Clause-② yes · REQUEST-CHANGES (one blocking item)

Blocking. QUERY_PAGE_SIZE_EXCEEDED is a synonym of the standard MAX_RECORDS_EXCEEDED.

Holds as is.

  • (a) The widening is otherwise exact: nothing existing moved, and the changeset levels follow the rule.
  • (b) Registration is consistent: the ledger, the catalog under 400, the count, and the status-conformance producers.
  • (c) With no host configuration nothing clamps. Today's self-hosted behaviour is unchanged on every door, and tests pin it.
  • (d) There is one rule, refuse and never clamp, and REST and both analytics doors share the planner.
  • (e) The log line carries code, surface, object, rows and limit only.
  • (f) Tests cover the refusal shape, the defaults, the probes and configuration faults.

Non-blocking. You can carry these in the same push:

  • The limit reaches the wire only inside message. Lifting it into details.limit (thread-http-error mapping) would be the structured form.
  • data-api.mdx says "neither request reaches the database". For a budget-only grouped read, the probe runs the aggregate and refuses afterwards, so tighten that sentence.

The seat re-reads on the next head. When it lands, the seat closes #29783 (the body says "Part of").

…_RECORDS_EXCEEDED

The contract review found QUERY_PAGE_SIZE_EXCEEDED a synonym of the standard
MAX_RECORDS_EXCEEDED (400, a caller-side limit: the request asked for more than
a request may carry). The page-size refusals now answer that code, which gains
its first producer, and QUERY_PAGE_SIZE_EXCEEDED is gone from the ledger, so
the widening is QUERY_ROW_BUDGET_EXCEEDED alone. Its ledger row says why it is
not MAX_RECORDS_EXCEEDED. The catalog folds the page-size cause into the
MAX_RECORDS_EXCEEDED entry, the wire count is 57, the unpinned baseline drops
MAX_RECORDS_EXCEEDED, and data-api.mdx no longer says a budget probe's read
never runs.

Claude-Session: https://claude.ai/code/session_01QUs3BtTosRanM94rtudkMk
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor

repo:cloud#2 · os-zhuang · session_0123kRqqdpAJWYMgsgdAJX4G

Contract re-read · 2026-11-03T07:47Z · head 23b7c161 · Clause-② yes · ACCEPT

  • The blocking item is resolved. Page-size refusals now answer the standard MAX_RECORDS_EXCEEDED (400), which gets its first producer here and leaves the unpinned baseline (shrink-only). QUERY_PAGE_SIZE_EXCEEDED is gone from the ledger, the catalog, the docs, the changeset and the tests. The widening is now one member, QUERY_ROW_BUDGET_EXCEEDED. Its ledger row says why it is not MAX_RECORDS_EXCEEDED: the budget bounds how deep a query walks (offset plus page), so a page within the maximum can still be refused at a deep offset. The wire count is 57.
  • Non-blocking. data-api.mdx now states that the budget probe read runs before refusing. Declining details.limit is accepted: nestedRefusalEnvelope forwards only the code, the message and the user message by rule, and changing that envelope is a separate shape decision outside this card.
  • Everything that held at a69e1db4 still holds: no default clamp, one refuse-never-clamp rule, logs carry counts only, tests cover it.

The merge state is dirty, so the dev thread will merge main into the branch. Automerge is armed, and the seat closes #29783 at landing.

@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 3, 2026 07:49
Resolves the one conflict in metadata-protocol findData: main now hands the
engine typed bags (aggregateQuery, findQuery). The read-limit plan runs before
findQuery is built, so the bag carries the planned limit, and the grouped
branch plans before aggregateQuery as before. Reference docs regenerated.

Claude-Session: https://claude.ai/code/session_01QUs3BtTosRanM94rtudkMk
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants