Repository navigation
feat(server): calibrate the stats policy thresholds from the phase-0 measurements (rows-first p31b) - #1023
Draft
paddymul wants to merge 6 commits into
Draft
feat(server): calibrate the stats policy thresholds from the phase-0 measurements (rows-first p31b)#1023paddymul wants to merge 6 commits into
paddymul wants to merge 6 commits into
Conversation
…(rows-first p31) New tests/unit/server/test_stats_policy.py for buckaroo/server/stats_policy.py, which does not exist yet: - resolve_stats_policy: a table of (backend, source_kind, rows, cols, host_tier) against (tier_target, auto_request, requestable, reason), including the boundaries of each threshold and the three tallyman entries over 70 s. - The ceiling holds for host_tier="full", for a reload that re-resolves against a larger row count, and for a force request, and every tier a result lists as requestable is one a force would be granted. - Probes add no data query: the parquet footer probe reads a small share of a counting file object and decodes no row group, the dtype probe never collects a LazyFrame or executes a xorq expression, and a known xorq count is an input. - route_polars_entry returns "xorq" above R and "eager" at or below it. - Threshold overrides from BUCKAROO_* environment variables. Nothing imports the module yet. The tests error at fixture setup on the missing module until the implementation lands. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… p31) New buckaroo/server/stats_policy.py, pure and imported by nothing yet: - resolve_stats_policy(backend, source_kind, rows, cols, bytes, host_tier, limits) returns tier_target, auto_request, requestable, reason and estimate over the tiers schema < scalar < full. A ceiling is computed inside the function, so every caller gets the lower of the requested and ceiling tiers with reason "ceiling". A host tier lowers freely and raises only to the ceiling. Eager pandas and polars resolve to full. - route_polars_entry(rows, cols) returns "xorq" above R rows and "eager" at or below it. - probe_dtypes reads a schema without collecting or executing anything, and probe_parquet_rows reads a parquet footer's num_rows without decoding data. A xorq count is an input to the policy, never computed by it. - The thresholds are provisional constants gathered in StatsLimits, each with a BUCKAROO_* environment override read on every call. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…esolve_stats_policy (rows-first p31) bytes and source_kind were documented as validated but are not: bytes=-1, 'lots', 1.5 and object() are accepted, a np.int64 is echoed unchanged so json.dumps of the result fails, a host tier passed positionally lands in the bytes slot, and source_kind=None or 5 is accepted. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rows-first p31) bytes goes through the same integer check as rows and cols, so a negative, float or non-numeric value raises, a numpy integer is echoed as a plain int and the result stays JSON-serialisable, and a host tier passed positionally into the bytes slot raises instead of being echoed. source_kind must be a str; its vocabulary stays open for the callers that will read it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…s (rows-first p31b) The boundary tables now run on the module defaults and are written against the phase-0 proposals: full auto up to 12M rows and 520M cells, scalar auto up to 1.0B cells, full refused above 25M rows or 1.0B cells (force included), a scalar ceiling of 4.0B cells, and polars routed to xorq above 8M rows. Each threshold has an equal, a one-below and a one-above row, in rows and in cells. New tests pin each default to its literal value and cover the two new environment overrides, BUCKAROO_STATS_FULL_AUTO_CELLS and BUCKAROO_STATS_CEILING_FULL_CELLS. They fail on the current constants (10M rows, 500M cells, 50M-row ceiling, no scalar ceiling, R of 10M) and on the missing full_auto_cells and ceiling_full_cells fields. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
📦 TestPyPI package publishedpip install --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo==0.15.9.dev37180060370or with uv: uv pip install --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo==0.15.9.dev37180060370MCP server for Claude Codeclaude mcp add buckaroo-table -- uvx --from "buckaroo[mcp]==0.15.9.dev37180060370" --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo-table📖 Docs preview🎨 Storybook preview |
…measurements (rows-first p31b) Full auto now needs at most 12M rows and 520M cells (was 10M rows), scalar auto goes to a 1.0B cell budget (was 500M), `full` is refused above 25M rows or 1.0B cells including for a forced request (was 50M rows), scalar gets a 4.0B cell ceiling by default (was unset; an extrapolation with no measurement behind it), and polars routes to xorq above 8M rows (was 10M; the figure assumes pre_limit False). Each DEFAULT_* constant carries the measurement it comes from. The two new bounds are full_auto_cells and ceiling_full_cells, appended to StatsLimits, with BUCKAROO_STATS_FULL_AUTO_CELLS and BUCKAROO_STATS_CEILING_FULL_CELLS as overrides under the same parsing rules. _size_tier and _ceiling_tier read them; signatures and the result shape are unchanged. Three existing tests that hard-coded the old boundaries are updated: the numpy-integer case (11M rows is now full), the reload case (a 40M-row entry is now refused full) and the empty-environment case for the scalar ceiling (an empty value now means the 4.0B default, not no ceiling). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This was referenced Oct 4, 2026
Closed
Draft
paddymul
changed the base branch from
main
to
adr-003-stats-tiers-and-size-policy
October 6, 2026 14:40
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The thresholds in
buckaroo/server/stats_policy.py(PR #1019) are placeholders taken from repo constants: full stats up to 10M rows, scalar stats up to 500M cells, a 50M-row ceiling onfull, no ceiling onscalar, and polars routed to xorq above 10M rows. The phase-0 measurement run has since produced proposed values from 115 tallyman loads, xorq stats timings on parquet and CSV, and the RSS of eager polars frames. Against those measurements the placeholders are off in four ways: five 10.8-11.8M-row entries that took 2.7-6.5 s would go to the scalar tier, the 50M-row ceiling sits inside a gap where the telemetry has no entries (11.8M to 42.3M rows) and lets a forcedfullrun on the 42.3M-row entry that took 75 s, rows alone cannot see a wide entry, and 10M rows of eager polars does not fit the memory budget once windows copy the frame.This PR replaces the placeholders with the proposals. It changes constants and adds two cell bounds, nothing else.
Phase and plan references
Follow-up to plan 3 (
03-no-summary-stats-for-large-files.md) section 6 "Phase 1" and section 3.1, usingmeasurements-phase0.md("Proposed values", the telemetry join, the eager polars RSS section and the "not measured" list). Plan 1 sections 3 and 4.0 and plan 2 sections 3 and 4.1 are the vocabulary. The plans and the measurements are inbuckaroo2-reports/plans/, outside this repo.Approach
Each
DEFAULT_*constant takes the proposed value and carries a comment with the measurement behind it. Two newStatsLimitsfields and constants add the cell bounds the proposals need, and each has an environment override with the same parsing rules as the others (read on every call; a value that is not a non-negative integer is ignored with a warning).full_auto_rowsBUCKAROO_STATS_FULL_AUTO_ROWSfull_auto_cells(new)BUCKAROO_STATS_FULL_AUTO_CELLSscalar_auto_cellsBUCKAROO_STATS_SCALAR_AUTO_CELLSceiling_full_rowsBUCKAROO_STATS_CEILING_FULL_ROWSceiling_full_cells(new)BUCKAROO_STATS_CEILING_FULL_CELLSceiling_scalar_cellsBUCKAROO_STATS_CEILING_SCALAR_CELLSpolars_route_rowsBUCKAROO_POLARS_ROUTE_ROWSThe two rules that read the new fields:
fullwhenrows <= full_auto_rowsandcells <= full_auto_cells; otherwisescalarwhencells <= scalar_auto_cells; otherwiseschema. A 12M-row entry isfullat 43 columns (516M cells) andscalarat 44 (528M).schemawhencells > ceiling_scalar_cells; otherwisefullwhenrows <= ceiling_full_rowsandcells <= ceiling_full_cells; otherwisescalar. This refusesfullabove 25M rows or 1.0B cells, whichever is lower, for every caller including a forced request.Where the numbers come from:
pre_limitis False. With a 32 GB budget, four files resident and one window in flight, 8M rows is 27 GB and 10M is 33.5 GB. The figure assumespre_limitFalse, as the docstring says. With main's 1Mpre_limit, windows do not copy the frame and the resident-only bound is about 14M rows for four files.What changes
buckaroo/server/stats_policy.py: theDEFAULT_*constants and their comments,DEFAULT_FULL_AUTO_CELLSandDEFAULT_CEILING_FULL_CELLS, the twoStatsLimitsfields (appended afterpolars_route_rows, so positional construction is unchanged), two entries in_ENV_FIELDS, one added condition each in_size_tierand_ceiling_tier, and the module androute_polars_entrydocstrings.tests/unit/server/test_stats_policy.py.Function signatures and the result shape are unchanged.
Tests
All in
tests/unit/server/test_stats_policy.py.RESOLVE_TABLEis rewritten to the new values, with an equal, a one-below and a one-above row for every threshold, in rows and in cells (a row count or a column count moves the product). It also covers the 11.7M-row CSV entries, the three slow telemetry entries and the new ceilings with and without a host tier.TestCalibratedDefaultspinsStatsLimits(),StatsLimits.from_env()on a clean environment and the module constants to literal values, and asserts every limit has an environment variable.TestCeilinggains three property checks over all host tiers:fullnever resolves above 1.0B cells, above 25M rows with few cells, or pastschemaabove 4.0B cells.TestLimitsFromEnvruns its two parametrized checks over the new variables, and checks that each new bound is read from the environment on each call.TestRoutePolarsEntrychecks 7,999,999, 8,000,000 and 8,000,001 rows on the defaults.The
limfixture now returns the module defaults (it used to pin the plan's starting values explicitly). This is what makes the tables fail on the old constants, and it means a change to aDEFAULT_*constant fails them until the table is updated with it.The tests are committed alone first (
3fd6b5fa). CI on that commit failed: the ninePython / Testmatrix jobs (3.11 to 3.14, Max Versions 3.11 to 3.14, Windows) were red, and every other check completed (deployskipped). Locally, 115 of the 321 tests in the file fail on the old constants, mostly on assertions; the rest fail withAttributeErrorforfull_auto_cellsandceiling_full_cells, which the oldStatsLimitsdoes not have. The implementation is3eef7097, and every check on it completed green: 26 check runs succeeded (all ninePython / Testjobs, lint, JS, wheel, docs and the Playwright jobs),deploywas skipped, and the Read the Docs status passed.Three existing tests changed, because they hard-coded the old boundaries and fail on the new constants:
test_numpy_integer_counts_are_acceptedused 11M rows and expectedscalar; 11M rows x 43 columns is nowfull, so it uses 13M rows.test_reload_re_resolves_against_the_new_row_countused a 40M-row entry that keptfullunder the old 50M-row ceiling; that entry is now refused, so the "before" entry is 20M rows x 44 columns (880M cells, inside both ceilings).test_empty_value_means_unsetasserted that an emptyBUCKAROO_STATS_CEILING_SCALAR_CELLSgivesNone. The scalar ceiling now defaults to 4.0B cells, so an empty value means the default.Two tests were added in the implementation commit because they also pass on the old constants: the scalar ceiling's environment override, and a check that
requestablematches what a force request is granted at the new row and cell boundaries.The local unit suite (
pytest ./tests/unit -m "not slow") passes: 1519 passed, 5 skipped.Stack
This PR's base is main, and it is cumulative: it contains the four commits of draft PR #1019 (
feat/rowsfirst-p31-stats-policy:c1391701,8895d26c,f03532ca,a2cc7ce5) until that merges. This phase's commits are3fd6b5fa(failing tests) and3eef7097(implementation).git diff origin/feat/rowsfirst-p31-stats-policy...HEADshows only these.Why default behaviour is unchanged
No handler, session or dataflow imports
stats_policy, so no request, load or stats run reads these values. The module is still not wired in.Deviations from the plan
full_auto_cells,ceiling_full_cells), soStatsLimitshas two fields and there are two environment variables beyond the p31 set.StatsLimits, not placed next to the field they extend.Not in this PR
🤖 Generated with Claude Code