Skip to content

fix(usage-retention): fail the retention gate on readers whose bound cannot be parsed - #449

Merged
argszero merged 1 commit into
mainfrom
fix/usage-retention-gate-unpaired-readers
Nov 26, 2026
Merged

argszero merged 1 commit into
mainfrom
fix/usage-retention-gate-unpaired-readers

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

usage_retention_gate.rs is the static gate that keeps the usage_records deletion threshold no later than every reader's own window lower bound. It resolved a reader's bound with

let Some(expr) = reader_bound(prod, at) else { continue; };

so a site that matched the reader shape but whose bound could not be parsed was dropped from the roster — and R1/R2 only quantify over the roster, so the invariant silently degraded to "the threshold is not later than every reader I could parse". The module doc already said an unparseable bound means that reader has no criterion; the code meant "that reader has no constraint".

This change makes that case fail the verdict: an unpaired site is recorded in Reading.unpaired, and the new rule R5 (roster complete) requires that list to be empty.

Related Issue

Closes #448

Changes

  • Reading gains unpaired: Vec<String> (file@masked-offset), filled by the reader scan where the silent continue used to be.
  • New rule R5 (r5() = unpaired.is_empty()); Reading::all() includes it and blame() prints the list.
  • Positive control the_scanner_sees_both_sides now also asserts the roster was not silently pruned.
  • every_usage_retention_rule_has_a_tooth gains a sixth tooth that mutates unpaired.
  • Module doc: R5 is stated; the rules heading said "三条规则" while listing four, and now says five.
  • Test-only: the module is declared #[cfg(test)] mod usage_retention_gate; in src/main.rs, so production behaviour is unchanged. No config or data-structure change, so config/config.example.toml is untouched.

Tests

  • cargo test — 614 passed, 0 failed, 0 ignored
  • cargo fmt --check — clean
  • cargo clippy — clean

Proof that the new rule has teeth (run against the tree of this patch, and against the same tree with this patch reverted): I injected an unpaired reader into src/routes/ops.rs — FROM usage_records WHERE time > with a strict > instead of >= — and ran cargo test usage_retention_gate.

  • before this patch: 6 passed — the unpaired reader was invisible to the gate
  • after this patch: 2 failed, naming routes/ops.rs@3587 and printing r5=false

The probe was then removed; the committed diff touches only src/usage_retention_gate.rs.

Checklist

  • Branch name follows the convention (fix/<description>)
  • Commit message uses Conventional Commits
  • Single purpose, minimal change

The gate resolved each reader's time bound with an early continue, so a
reader site whose bound could not be parsed vanished from the roster and
R1/R2 kept quantifying over what was left. The module doc already promised
that an unparseable bound means that reader has no criterion; it now does.

R5 records such sites in Reading.unpaired and fails the verdict, the
positive control asserts the unpaired list is empty, and the tooth test
mutates that list. Test-only module (#[cfg(test)]); no production change.
Also corrects the rule-count sentence in the module doc itself.

Refs #448
@argszero
argszero merged commit 278dbbd into main Nov 26, 2026
2 checks passed
argszero added a commit that referenced this pull request Nov 27, 2026
…le boundary (#451)

The gate cut a file's production code at the first `#[cfg(test)]`. That marker
is an attribute, not a module: when it attributes a single test-only helper,
every reader below it leaves the scanned region — and it leaves before the
roster is built, so R5 (#449), which judges the roster, cannot see it. The
verdict stays green on a roster that is a strict prefix of the file.

The boundary is now one the code checks: the region ends at the first
`#[cfg(test)]` that introduces a module (`mod … {` / `mod …;`), and a marker
that does not is recorded in `Reading.bare_markers` and fails the new rule R6
in the two files the gate takes facts from (`src/routes/` for the roster,
`src/usage_retention.rs` for the threshold and the delete helper).

Test-only module: no production behaviour change, no config or data-structure
change.

Closes #450
@argszero argszero mentioned this pull request Dec 3, 2026
argszero added a commit that referenced this pull request Dec 3, 2026
Five commits since v0.7.35 (#449, #451, #452, #453, #454). No schema change
(18 either side). The version string moves in the five carriers the deploy
gate guards: Cargo.toml, Cargo.lock, Dockerfile, docker-compose.yml and the
new CHANGELOG heading.

Co-authored-by: argszero <argszero@users.noreply.github.com>
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.

usage retention gate silently drops any reader it cannot parse, and its positive control cannot see the drop

1 participant