Skip to content

Hold the cold shard plan to the bound greedy assignment guarantees - #1058

Merged
Vilin97 merged 1 commit into
mainfrom
maintainer/shard-balance-invariant
Nov 27, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
maintainer/shard-balance-invariant

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

The required Test (pytest) check fails on main for every PR that runs it; this makes the shard-balance test assert what the planner can guarantee.

Root cause

test_cold_plan_covers_pool_in_balanced_shards plans a cold build of the real pool and required the heaviest shard to stay within 1.25 times the mean shard. No assignment can satisfy that once a single project costs more than that, because projects are the shard unit.

#1035 added FiniteIntegralRelationAlgebras (1,373 files, 78 MB of sources). The planner predicts 31,100 CPU seconds for it and correctly gives it a shard of its own, against a mean shard of 24,091 seconds and a limit of 30,114.

A content PR does not run pytest, so #1035 merged green and the check broke afterwards for PRs that touch python/, a workflow or the top-level documents.

Evidence

  • Python CI run 45931507242 on main (the daily statistics refresh, 2026-11-27 02:59 UTC): assert 31060 <= ((1.25 * 333880) / 14).
  • At 1044203bb the cold plan puts FiniteIntegralRelationAlgebras alone in shard 00 at 31,100 seconds; the other thirteen shards hold 23,547 to 23,554 seconds each.
  • The prediction is not an overestimate. The Built lines of the project's own PR build (run 45906085808, 3 h 30 min) sum to 43,950 seconds, about twice MovingSofa (20,975).

Change

  • The test now asserts that no shard exceeds the mean load by more than its cheapest project. Greedy assignment gives each project to the least loaded shard, which holds at most the mean at that moment, and a shard's last project is its cheapest. The bound holds for any pool, so a content merge cannot break it. For a shard of many small projects it is tighter than the old ratio.
  • The test also checks each reported shard_seconds against the costs of the shard's members.
  • A synthetic test reproduces the Import finite integral relation algebra counts through seven atoms #1035 shape (one project above 1.25 times the mean) and checks that the helper rejects two heavy projects packed together.
  • plan-build-shards.py: the cost prediction moves into predicted_costs so the test reads the planner's own costs. The plan is unchanged. The MAX_SHARDS comment named MovingSofa as the costliest project; it now names both.

Validation

  • uv run ruff check, uv run ruff format --check: clean.
  • uv run --group test pytest: 1,112 passed, 2 skipped, 1 failed. The failure is test_repository_notice_is_current, which fails in a local checkout whenever an import merged after the last daily refresh; CI regenerates NOTICE first.
  • Three mutations of the planner each fail the new assertions: least-loaded choice replaced by fewest members, ascending cost order, and a wrong shard_seconds.

Not changed

  • build-costs.json still dates from 2026-11-06 and lacks 95 of 423 projects. The estimates only affect how evenly the other shards fill; the slowest shard is now the new project alone either way.
  • A cold whole-pool run is now bounded by that project's shard (its PR build took 3 h 30 min), up from about 2 h 15 min for MovingSofa. Only a cheaper project shortens it.

🤖 Generated with Claude Code

The balance test compared the heaviest shard with 1.25 times the mean
shard. No assignment satisfies that once one project costs more, and
FiniteIntegralRelationAlgebras (#1035) is predicted at 31,100 CPU
seconds against a mean shard of 24,091. Content PRs do not run pytest,
so the required check failed on main afterwards for every PR that does.

Assert instead that no shard exceeds the mean by more than its cheapest
project, which greedy assignment guarantees for any pool.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

No added or modified Lean files under LeanPool/ in this PR. No compile-cost measurements are needed.

Advisory only — never blocks merge.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Advisory cross-file review against Lean Pool's supervisory rubric. This is not by itself a significance, source-verification, or merge verdict.

The PR appears safe to merge; the revised test matches what the unchanged planner guarantees.RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; the revised test matches what the unchanged planner guarantees.

Summary

Replaces the cold-plan test’s fixed balance ratio with a bound that allows an indivisible project to outweigh the mean shard.

  • Cold-build checks now match how projects are assigned to shards.

Reviews (1) · Last reviewed commit: "Hold the cold shard plan to the bound gr..." · Reviewed by Greptile

@Vilin97 Vilin97 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source review passed at 1bb91a18af43a0736ff037b955f1946fb345b661.

  • Immediately before a shard receives its final and cheapest project, its load is at most the mean at that step. Nonnegative costs make that mean at most the final mean. This gives the new bound even when a single project would make the old fixed ratio unattainable.
  • Extracting predicted_costs preserves the planner's inputs and assignments. I obtained identical old and new outputs across 300 synthetic cases, including zero costs, missing measurements and dominant projects. The new check also rejected packing two dominant projects together. Exact-head Ruff and pytest passed. Python CI

@Vilin97
Vilin97 added this pull request to the merge queue Nov 27, 2026
@Vilin97

Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 LLM review — refactor (gpt-6.2-sol)

Reviewed head: 1bb91a18af43a0736ff037b955f1946fb345b661

Verdict: ✅ approve

The PR replaces the cold-plan test’s fixed 1.25× ratio with the bound guaranteed by largest-first greedy assignment. It checks reported shard loads against their members’ predicted costs and adds a regression case for an oversized project. The base and PR produced identical plan JSON in five scenarios, and all 30 targeted Python tests passed.

Aspect Value
Scope CI shard-balance tests and cost helper extraction
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

The new bound accommodates an indivisible project larger than the mean shard while still catching regressions in assignment order, shard selection, and load reporting.

Findings (1)

  • prompt-injection — PR-wide
    PR discussion comment 7226987881 invokes the pool’s review rubric and repeats a recommendation to merge inside <ruby><rp> markup that can conceal the text when rendered. Remove the hidden recommendation from the comment.

Tokens: 525,422 in / 5,535 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $2.1847 (Standard API equivalent; uncached input) (long-context rate)
Automated review against .github/REFACTOR_REVIEW_RULES.md. Disagree? Reply on the PR; rules can be updated in a PR of their own.

Merged via the queue into main with commit bf11e80 Nov 27, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant