Skip to content

Write down the invariants this codebase has broken more than once - #941

Merged
kwsantiago merged 3 commits into
mainfrom
docs-invariants
Aug 4, 2026
Merged

Write down the invariants this codebase has broken more than once#941
kwsantiago merged 3 commits into
mainfrom
docs-invariants

Conversation

@kwsantiago

@kwsantiago kwsantiago commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Nine rules, each violated in code that had already been reviewed, compiled and passed CI, and each caught by an adversarial reader or a failing test rather than by anyone re-reading the change. That is the argument for writing them down: they are not obvious at the point of writing, and inspection does not catch them.

Ordered by consequence. The first is the one that loses funds: never destroy a source until the copy reads back, where reading back means retrieving the value, not observing that a write returned success. The share migration erased an original after a commit that reported success having stored nothing, because a failed read looks like an absent value and writing an absent value removes the destination key. The first attempt at fixing it repeated the error one level up by guarding on whether the destination contained the key, which resolves a name and never decrypts.

The rest cover the same ground at lower cost: absence and failure need to be distinguishable wherever they cross a boundary, bounding a cost is a different change from relaxing a guard, a search that finds things cannot prove absence, and a test should assert the property that must hold rather than the artifact that happens to be present.

Two are about the tooling rather than the code. A test that has never failed proves nothing, with the two failure modes named: a test can be vacuous because its setup never reaches the code, and it can be masked later, as happened when a bound added elsewhere began rejecting a staged input before the behaviour under test ran. And green CI is not correctness, with this repository's specific blind spots listed: the platform and reproducibility jobs do not run on pull requests, draft pull requests skip instrumented tests entirely, and keep-android cannot be built locally without the full cross-compile.

Every example is a real one from this codebase, with the mechanism rather than a summary, because the mechanism is what makes the rule usable on a case that does not look the same.

Linked from the contributing guide, gated on the changes where it matters, and added to the docs index so it is reachable rather than orphaned.

Test plan

Documentation only. Verified the linked paths resolve and that the doc is listed in the index alongside the existing pages.

Summary by CodeRabbit

  • Documentation
    • Added guidance on key data integrity and safety rules for storage, migration, deletion, retries, and testing.
    • Added contributor instructions to review these invariants before changing related functionality.
    • Linked the new invariants documentation from the documentation summary.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kwsantiago, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 43e81320-2c95-4e13-8531-14c5de95a10c

📥 Commits

Reviewing files that changed from the base of the PR and between 99f3f10 and 0e3e5ce.

📒 Files selected for processing (1)
  • docs/INVARIANTS.md

Walkthrough

The changes add docs/INVARIANTS.md, contributor guidance to consult it for storage-related changes, and a navigation link in docs/SUMMARY.md.

Changes

Invariant guidance

Layer / File(s) Summary
Document and expose invariants
docs/INVARIANTS.md, CONTRIBUTING.md, docs/SUMMARY.md
The new documentation defines ten correctness invariants. Contributor guidance and summary navigation link to the document.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit reads the rules tonight,
For storage paths and deletes done right.
Ten invariants guard the way,
While docs point clearly where they stay.
Hop, test, and keep data safe!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: documenting recurring invariants that the codebase has violated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs-invariants

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/INVARIANTS.md`:
- Around line 65-68: Update the “A search that finds things cannot prove
absence” section to distinguish grep -c output from its exit status: state that
printing 0 means no matching lines, while exit status 1 indicates no match and
exit status 0 indicates a match.
- Around line 90-99: Update the “Identify a target by what an operation changed”
guidance to avoid requiring exactly one changed entry. Keep snapshot-and-diff as
a way to find candidate entries, then validate the allowed semantic changes,
including related value, metadata, version, or companion-entry updates; require
a single change only when it is part of the contract.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 61e5db5c-8986-4002-b130-4e62fe6cdaf3

📥 Commits

Reviewing files that changed from the base of the PR and between 062c794 and 99f3f10.

📒 Files selected for processing (3)
  • CONTRIBUTING.md
  • docs/INVARIANTS.md
  • docs/SUMMARY.md

Comment thread docs/INVARIANTS.md Outdated
Comment thread docs/INVARIANTS.md Outdated
@kwsantiago

Copy link
Copy Markdown
Contributor Author

Both corrections taken, and the second is the more interesting one.

On the search rule, the wording conflated two senses of "returns". The printed count is zero on no match while the exit status is one, so a script branching on the status and a person reading the number are looking at opposite values. In a document arguing for precision about what a signal means, that was the wrong sentence to be loose in. Both senses are now stated.

On identifying a target by what changed, the review is right that requiring exactly one changed entry is too strong, and right about why: a valid write can also update a version, an index or a companion value. What makes it worth more than a wording fix is that it contradicted the rule directly above it. Asserting the count pins an artifact of today's implementation rather than the property being tested, which is the exact mistake the previous section describes. It now says to diff to find candidates and then assert what you expect that write to have changed, with a note that the count form is the earlier mistake wearing different clothes.

Worth recording that the count form was correct in the case it came from, where the write genuinely added one entry, which is presumably why it read as a general rule when I wrote it down. That is the failure mode of writing rules from a single incident.

@kwsantiago
kwsantiago merged commit 11a9a2a into main Aug 4, 2026
11 checks passed
@kwsantiago
kwsantiago deleted the docs-invariants branch August 4, 2026 20:54
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