Skip to content

Give the S3 sync plan a domain model with named rules - #4902

Merged
Mpdreamz merged 5 commits into
mainfrom
split/15-sync-plan
Nov 27, 2026
Merged

Mpdreamz merged 5 commits into
mainfrom
split/15-sync-plan

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

The S3 sync plan's validity checks become named rules on a domain record, and the planner's file classification becomes a pure function. The deploy verdict, its log lines and the plan JSON stay the same.

Affects: Internals only

Stack: 15 of 16 in the split of #4530, on top of the foundation #4888.

Why

DocsSyncPlanValidator holds the deploy safety rules (complete listing, non-empty build, delete ratio against a size-dependent threshold) as nested if statements next to the logging. AwsS3SyncPlanStrategy mixes the S3 and file system calls with the add, update, skip and delete decision. Neither can be tested without the other.

What

Rules in the domain

SyncPlanCounts (in Elastic.Documentation.Sync) holds what the checks read: the listing flag, source and remote file counts and the delete count. It owns the threshold logic (the user value or 0.2, at least 0.8 up to 100 remote files, at least 0.5 up to 1,000, 0 for an empty bucket). SyncPlanCountsConstraints declares the three error rules.

Validator

DocsSyncPlanValidator.Validate(SyncPlan) reads the findings of the rules through Check. It keeps the old order: an incomplete listing or an empty build stops at its own message, otherwise the threshold reason is logged and a delete ratio over the threshold is an error. Messages, results and log calls are unchanged: each finding keeps its old message template and, for the delete ratio, the Ratio and Threshold arguments. SyncPlan.Counts is the new [JsonIgnore] view; the wire format is untouched. Deploying now references Configuration, which opens its internals to Deploying for Check.

Planner

SyncPlanner.Compute classifies local files and remote keys into add, update, skip and delete. AwsS3SyncPlanStrategy lists, hashes and calls it. ETags are still computed only for files that are also remote, and a remote ETag is read (and its quotes trimmed) only when an included local file is compared with it; the listing is used as it is. The add, update and skip lists now follow file order. They used to follow the order a concurrent bag returned, which was nondeterministic, so no stable behaviour changes. No exception is turned into a finding: the rules run through Check, which does not catch.

Tests

Rule and threshold tests, and CsCheck laws for the planner (the four lists partition the inputs, planning after applying is empty, deletes are remote-only and not excluded, listing order does not matter) and for the threshold and verdict.

Deferred behaviour changes

  • Rule total_sync_requests must be add + update + delete (P36 in Model the domain as typed records with named, tested rules #4530, a warning that fires for every plan that has skipped files).
  • SyncPlanLoader: reading a plan file through a loader that reports a malformed plan as a diagnostic. Apply still throws on malformed JSON, as before.
  • The raw reader (SyncPlan.Deserialize) staying internal, and RetainedPaths having an internal setter.
  • The validator reporting every error of a bad plan instead of the first.
  • Rejecting a persisted plan with a negative total_source_files: main rejects only zero, so a negative count still passes the file check (the rule is != 0). A stricter rule is a later change.

Verify

mise run test
dotnet test --project tests/Elastic.Documentation.Deploying.Tests
mise run snap:status

No verified snapshot changed. Golden site build compare skipped: deploy tooling only, no site build path changes.

🤖 Generated with Claude Code

Found by generated data

Nothing: no rule, ratio or threshold throws on hostile counts. One observation, identical to main: a NaN threshold never rejects a plan (pinned by ANanThreshold_NeverRejectsADeletion).

@Mpdreamz
Mpdreamz requested a review from a team as a code owner November 17, 2026 17:29
@Mpdreamz Mpdreamz added the chore label Nov 17, 2026
@Mpdreamz
Mpdreamz requested a review from akira28 November 17, 2026 17:29
@Mpdreamz Mpdreamz added the chore label Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4902/

Mpdreamz and others added 2 commits November 27, 2026 12:24
The plan's numbers become a SyncPlanCounts record whose three rules replace the checks inside DocsSyncPlanValidator, and the planner's classification of files moves into the pure SyncPlanner.Compute. The verdict, the log lines and the plan file stay the same.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
AutoTest runs every rule over generated legal plans and proves each rule can fire. A second generator adds partial listings, empty builds, negative, zero and huge counts and NaN or infinite thresholds, and checks that no rule, ratio or threshold throws. It found no defect: the rules behave as main's validator does, including a NaN threshold that never rejects a plan.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A negative source file count passes as on main, where only zero is rejected. The validator logs each finding with its old template and its Ratio and Threshold arguments. The planner reads a remote ETag only when it compares an included local file, with no second index of the bucket.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The scenario headings used the platform line ending, so the transcript test failed on Windows.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Mpdreamz
Mpdreamz merged commit 6245776 into main Nov 27, 2026
45 checks passed
@Mpdreamz
Mpdreamz deleted the split/15-sync-plan branch November 27, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant