Skip to content

[ZC: ⁠ ⁠ ⁠WW.3.S] UM-1689: let the plan look the keeper up instead of scanning for it - #2131

Merged
swu-zc[bot] merged 3 commits into
mainfrom
zc/um1689-planner-keepers-table
Dec 3, 2026
Merged

swu-zc[bot] merged 3 commits into
mainfrom
zc/um1689-planner-keepers-table

Conversation

@jaywedgeworth22

@jaywedgeworth22 jaywedgeworth22 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

[ZC: ⁠ ⁠ ⁠WW.3.S] UM-1689: let the plan look the keeper up instead of scanning for it
Fixes UM-1689 (follow-up to #2125).

Summary

The duplicate-cleanup planning script now materializes each group’s keeper in a temporary SQLite table and indexes the group keys. Candidate rows look up their keeper through that index instead of joining against a window-function result, avoiding the repeated full scans that made the plan impractical on large ledgers. The ledger remains open read-only, and the documented intent is to preserve the plan’s results.

A test checks SQLite’s query plan to ensure the keeper is searched through an index rather than scanned. The planning script now derives manifest labels from the materialized keepers; an automated review flagged that this may include labels whose keepers fall outside the requested time window.


Summary

  • Replace the regular space after “throughout.” with a nonbreaking space in the rollout document.

No functional or query-planning changes are included in the provided patch.


Summary

The duplicate-cleanup planner now materializes rows within the requested time window and uses that set to determine which labels to report and which candidate rows to plan. Keeper selection remains based on the newest row for each group across the ledger, including rows outside the window. This prevents unrelated labels elsewhere in the ledger from creating empty manifests or causing a narrow plan to exceed the cleanup CLI’s label limit.

Tests

Added coverage confirming that the query looks up keepers through an index and that labels absent from the requested window are not reported or given manifests. Test execution is not reported.


Summary

The cleanup planner now stages rows within the requested time window and uses that window as the source for both candidate grouping and manifest labels. It still determines each group’s keeper from the ledger as a whole, so the newest row can be selected even when it falls outside the requested window. This prevents labels found only outside the window from producing empty manifests or causing a narrow run to exceed the cleanup CLI’s label limit.

Tests

Added coverage for planning a window when the ledger contains more labels than the cleanup CLI supports, verifying that only labels present in the window are reported and written to manifests. Updated the query-plan test to create the temporary tables and indexes required by the planner’s revised query.

…canning for it

The plan joined each candidate row to its group's keeper against a query that computes ROW_NUMBER() over the whole eligible set, and SQLite cannot look a group up inside such a query: there is no index on its result, so the join scanned the set once for every row.  On the production ledger that read 142 GB and never finished; with the keepers materialized into an indexed table the same plan reads 3.5 GB and finishes in minutes.

The plan's results are the same: the same 448,977 candidates, the same four manifests, the same keeper for each group, and the same rows left alone.  A test reads the query plan and asserts that the keeper is looked up through an index rather than scanned, so the shape cannot quietly go back to a scan.
@linear-code

linear-code Bot commented Dec 3, 2026

Copy link
Copy Markdown

UM-1689

@kody-ai

This comment has been minimized.

@kody-ai

kody-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Automatic approval held

Kody's assessment:

Risk rules: Stored data and migrations, Shared contracts and public interfaces.

@swu-zc

swu-zc Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@kody start-review
[ZC: ⁠ ⁠ ⁠WW.3.S]
Head: a451b7f
UM-1689 follow-up.  The plan joined each candidate row to its group's keeper against a query that computes ROW_NUMBER() over the whole eligible set, and SQLite cannot look a group up inside such a query, so it scanned the set once for every row: 142 GB on the production ledger, and it never finished.  The keepers are now materialized into an indexed table, and a test reads the query plan and asserts the lookup is a search rather than a scan.  The plan's results are unchanged.

A double space where the note means a sentence break, corrected to the real gap.
@kody-ai

This comment has been minimized.

@swu-zc
swu-zc Bot enabled auto-merge (squash) December 3, 2026 17:25
…was given

The keepers table made the label query cheap by reading the labels from the keepers, and the keepers are every group's newest row in the whole ledger.  A run bounded to a window therefore reported a label and wrote a manifest for every label the ledger holds, not only the labels the window holds, and a ledger with more than eight labels could stop a narrow run from being planned at all.  The window's rows now live in a table of their own, the same way the keepers do, and the labels are read from there.  The labels the plan reports are the labels of the rows it may touch, by construction rather than by a second query that has to be kept in step with the first.

Both plans were run over the same window of the production ledger and agree: the same 5,275 groups, the same 5,275 keepers, the same candidates, and the same manifest digests.  A test writes nine labels outside the window and one cross-host pair inside it, and asserts that the run is planned, that only the label the window holds is reported, and that no manifest is left for a label the run never touched.  The test fails on the old query with "this plan needs 10 manifests".
@kody-ai

This comment has been minimized.

@github-actions
github-actions Bot disabled auto-merge December 3, 2026 17:47
@swu-zc

swu-zc Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@kody start-review
[ZC: ⁠ ⁠ ⁠WW.3.S]
Head: 1050071
UM-1689 follow-up, second request on this head: the run that started on the push stopped at a provider rate limit.

The plan joins each candidate row to its group's keeper.  The keeper is materialized into an indexed table, and the window's rows into a table of their own, so the labels the plan reports are read from the rows it may touch rather than from the whole ledger.  The first run of the review found that regression, and it is fixed: a test writes nine labels outside the window and one cross-host pair inside it, and asserts that only the label the window holds is reported and that no manifest is left for a label the run never touched.

Both plans were run over the same window of the production ledger and agree on every group, keeper and manifest digest.

@kody-ai

kody-ai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

​

@swu-zc
swu-zc Bot merged commit a998cc8 into main Dec 3, 2026
19 checks passed
@swu-zc
swu-zc Bot deleted the zc/um1689-planner-keepers-table branch December 3, 2026 17:57
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