docs: Closing the Books pattern guide + runnable contrast (#139)#199
Merged
Conversation
Design spec for the Tier 1 #139 card: a doc-only kernel rustdoc module documenting the Closing the Books pattern as the preferred alternative to snapshots, plus a runnable examples/closing-the-books crate that builds the cash-register domain as a long-lived aggregate vs bounded CashierShift streams and prints the difference in events replayed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Five-task TDD plan: scaffold example crate, CashierShift bounded-stream aggregate + AggregateFixture tests, CashRegister anti-pattern with executable replay-count contrast, kernel closing_the_books rustdoc guide module, and the snapshot.rs cross-link + snapshot-design doc refresh. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…139) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…#139) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a prominent intra-doc pointer on the Snapshotting decorator to the nexus::closing_the_books guide module so readers land on the preferred alternative before adopting snapshots. Update the snapshot design doc to replace bare #139 issue references with concrete links to the now-shipped guide module and examples/closing-the-books example. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The CloseShift compare-then-subtract trips clippy's default implicit_saturating_sub, which suggests .saturating_sub() — the construct CLAUDE.md rule 2 bans. The flake gate misses it (clippy runs --lib, excluding examples), but a learner running cargo clippy --all-targets would be nudged toward the banned API in a teaching example. Add a reasoned allow. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #139 — the final card in the Tier 1: Table Stakes milestone. Documents the "Closing the Books" event-sourcing pattern as the preferred alternative to aggregate snapshots, with an executable contrast to back the prose.
crates/nexus/src/closing_the_books.rs) — a doc-only//!module shipped on docs.rs next toaggregate/events. Explains the pattern (bounded streams + a first-class summary event carrying minimum state forward), contrasts it with snapshots grounded in nexus's real behaviour (schema_versionis a cache key, not a migration engine — no upcasting path for snapshot bytes), and gives honest "when NOT to use it" caveats.examples/closing-the-books/) — builds the same cash-register domain two ways and prints the contrast:CashRegister: one stream, replays all 5001 events to read the current float;CashierShiftstreams: the current shift replays only 11 events, withfinal_float(110) carried forward into a brand-new shift stream.record/replay_streamhelpers; 4AggregateFixturetests cover theCloseShiftoverage/shortage/guard logic.nexus-store'sSnapshottingdecorator down tonexus::closing_the_books(the kernel can't link up to the store), and the older2026-04-10-snapshot-design.mdnow points at the shipped guide instead of the bare issue number.Design intent: nexus ships no "close stream"/"archive"/"delete" API — Closing the Books is a modeling discipline (a new stream is just
AggregateRoot::new(new_id); the summary is an ordinaryDomainEvent).Test Plan
nix flake checkgreen on every commit (pre-commit hook)cargo test -p nexus-example-closing-the-books— 4/4 fixture tests passcargo run -p nexus-example-closing-the-books— prints 5001-vs-11 event contrast; carried float 110 → recovered float 5100cargo docresolves thenexus::closing_the_booksintra-doc link from the snapshot decoratorcargo clippy --all-targetson the example is warning-clean (reasoned allow for the project-bannedsaturating_subnudge)nexus-storesource🤖 Generated with Claude Code