Repository navigation
feat!: catalogue stored event types and wait for the code that reads them - #383
Merged
Merged
Conversation
…them Every append records the kinds of its events (aggregate type, type, schema version) in bounda_event_types, in its own transaction; a storage migration fills it from the events already stored. A start refuses a store holding an event newer code wrote, and every read refuses one written after the start with the transient SchemaAheadError (SCHEMA_AHEAD), never reading it in a shape it was not written in. Each subscriber reads up to the first event it cannot read and stops there on its own; reactions, recipient notices and scheduled commands wait with back-off and are never dead-lettered for it; a rebuild pauses; the hosts answer 503.
- Reactions and scheduled work that meet newer code wait the dispatcher's base delay, spend no attempt and release their claim (EV1-a). - A transaction records the kinds it writes once, sorted, before it commits, so two writers of new kinds never deadlock (EV1-b), and sees them in types() before it commits (EV1-e). - The catalogue tells the runtime's ScheduledCommandFailed apart by aggregate type, and an app event of that name is refused (EV1-c). - The store records every personal category a key was given in; a start reads it, and older code never forgets a category only newer code declares: forgets refuse with CategoryAheadError (SCHEMA_AHEAD), reactions and retention wait (EV1-f). - A commit whose writes meet newer code throws that as the work would, so a reaction's forget at commit waits instead of leaving its claim.
…vent newer code wrote
SQLite runs one write transaction at a time, so holding a transaction's kinds back until its end bought nothing there; PostgreSQL keeps it.
A reseal that takes no append lock deadlocked on PostgreSQL with a transaction recording its kinds as it appended; the new case fails without the buffer.
…the forget ledger The reconciliation refuses to forget such a category again with CategoryAheadError and waits, and the pruning keeps an intention that names one, since only the code that declares it can tell whether the forgetting holds.
…ansaction recorded
@bounda-dev/cli
@bounda-dev/cloudflare
@bounda-dev/core
create-bounda
@bounda-dev/postgresql
@bounda-dev/react-router
@bounda-dev/sqlite
commit: |
EventStore.reseal takes, for each event, what the caller read it as, writes it only while the store still holds that, and resolves to the positions it left. The backfill passes it on both its paths, the events naming nobody now in a transaction of their own, and reads an event it left again on its next pass instead of stamping an older shape with a newer version. PostgreSQL locks each row it checks; the memory store's own reseal waits for a transaction's commit.
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.
The store keeps a catalogue of the kinds of event it holds,
bounda_event_types (aggregate_type, type, schema_version), and every reader refuses an event newer code wrote with the transientSchemaAheadError(SCHEMA_AHEAD) instead of reading it in a shape it was not written in. A deploy that changes an event's schema rolls forward across instances: the older code waits for the newer one.Rows → tests
Paths under
packages/core/src/unless named. Contracts run on memory,node:sqlite, libSQL, PostgreSQL and the Durable Object.adapter/testing/event-store.contract.ts: empty store; one row per kind; more kinds than a statement carries; a failed append records none; a transaction's kinds on commit, none on rollback; "shows a transaction the kinds its appends and reseals write before it commits, and nobody once it rolls back"; "commits two transactions that first write the same new kinds in opposite orders, recording each once"; two writers of one new kind; a reseal records the version it gives;postgresql/src/postgresql.test.ts"records a transaction's new kinds once its work is done, so a reseal that takes no append lock never deadlocks with it".storage-schema.contract.ts(migration fills the catalogue),earlier-rows.ts(0.2.0 / 0.3.0 databases),restore.contract.ts,adapter/sqlite/restore-copy.test.ts,adapter/sql/event-types.test.ts.kernel/aggregate/stored-types.test.ts"refuses the start, naming in code-point order every kind newer code wrote…", "reads in no version a type of the runtime's aggregate or of a process's lifecycle this core does not know";kernel/schema-ahead-app.test.ts"refuses to start once the catalogue holds a kind of event newer code wrote".stored-types.test.ts"knows every event a module of the runtime's aggregate names…", "reads a scheduled command's failure, on any stream, in the runtime's version";kernel/system-events.test.ts;modules/validate.test.tsandcli/src/generate/discover.test.tsrefuse an app event namedScheduledCommandFailed.kernel/aggregate/upcasting.test.ts("rejects every read…", "…even when the start saw its kind", "…a kind this code has no module for, written after the start…", "rejects with a configuration error…");contracts/errors.test.ts.kernel/dispatch/delivery.test.ts;schema-ahead-app.test.ts"holds every subscriber…".upcasting.test.ts"rejects every read…", "reads the readable events before the first one it cannot read…".kernel/events/guarded-storage.test.ts;kernel/personal-data/schema-ahead-readers.test.ts;kernel/recipients/recipients-app.test.ts. Each of the ten readers inside a transaction is pinned at an event newer code wrote meanwhile, with aracedAdapterthat appends it between the read and the commit: forget ("refuses, writing nothing, a forget whose intention's id another instance committed meanwhile in a version a newer Bounda wrote"), tenant forget, redaction, reseal, restriction and lift, backfill, presumed recipients (forget, export, notices), lost disclosures and handing data out.kernel/personal-data/backfill-walk.test.ts, incl. "leaves an event newer code rewrote while this pass read it, walking no further than it" (two walkers interleaved: older code reads, newer code upcasts, the older write is left);schema-ahead-readers.test.ts"refuses, rewriting nothing, a reseal, a redaction and an export…".EventStore.resealwrites an event givenfromonly while the store still holds it:event-store.contract.ts"writes an event given what it was read as only while it still holds that, in that schema version…", "leaves, inside a transaction, an event written again since it was read", "leaves an event a transaction holds written again from what both read, once it commits";adapter/staged-event-store.test.ts;postgresql.test.ts"…once the reseal waiting on its row sees it commit" and "locks the events a reseal checks in position order…";reseal-batches.test.ts"leaves as it is now an event written again since the batch was read, named or not…".kernel/shared/reaction-attempt.test.ts"holds a reaction that met an event newer code wrote with the dispatcher's base delay, counting no attempt…", "gives the first failure of its own after an event newer code wrote every attempt its retry allows";adapter/testing/inbox-ledger.contract.ts(release);schema-ahead-app.test.ts;kernel/recipients/notices.test.ts;kernel/process/deadlines.test.ts"defer a deadline that meets an event newer code wrote by the dispatcher's base delay, counting no attempt…";kernel/policy/delayed.test.ts"defer a run whose event newer code wrote, or whose command meets such an event…";kernel/dead-letters/restricted.test.ts"defers the retry whose letter meets an event newer code wrote…";kernel/unit-of-work/unit-of-work.test.ts"throws what newer code wrote, met by a write at commit, as the work itself would have…".schema-ahead-app.test.ts"rejects a command on its stream with SCHEMA_AHEAD…";react-router/src/failure.test.ts;cloudflare/test/worker.test.ts;cloudflare/test/outcome.test.ts"throws an event newer code wrote again as the SchemaAheadError it was, with every field".schema-ahead-app.test.ts(rebuild pauses and resumes; a tenant's export hands out no end); person export inschema-ahead-readers.test.ts;cli/src/forgotten.test.ts.bounda_personal_categories), and a start reads it: older code never forgets a category only newer code declares.kernel/personal-data/category-ahead.test.ts(forget as a whole, a category the store held at start, a reaction that waits, retention that holds, a forgetting's kept keys, a tenant's forget);personal-key-store.contract.ts"records each category a key is added in once…";storage-transaction.contract.ts"records the category of the keys it adds with the rest, or not at all", "keeps the category a write outside it recorded meanwhile when it rolls back";kernel/personal-data/forget.test.ts"refuses a forget by category or as a whole that would take a key of a category only newer code declares…";retention.test.ts"holds a person whose forget meets newer code…", "never lists a kept key of a category only newer code declares…";reconciliation.test.ts"waits for newer code it met…", "refuses, writing nothing, to forget again a category only newer code declares";ledger-prune.test.ts"keeps a forgetting's intention that names a category only newer code declares…";storage-schema.contract.ts(migration fills it);cloudflare/test/outcome.test.ts"throws keys of a category newer code declares again as the CategoryAheadError it was".core/test-types/schema-evolution.test-d.ts.Checks
pnpm check,pnpm test:typesandpnpm docs:buildpass locally with Docker. Stryker on the changed lines of every touched package (core,cli,postgresql,react-router,cloudflare): every mutant killed but six equivalents:stored-types.ts:105(a versions list no case reads); the two halves ofupcasting.ts:93, a type guard only a kind below version 1 or an upcast with no steps reaches;sqlite/event-store.ts:211andpostgresql/src/event-store.ts:252, which would read or lock the row of an event given nofromtoo, as its write does anyway;reseal-batches.ts:318, aschemaVersion: undefinedevery store reads as none.Breaking
EventStoregainstypes(),InboxLedgergainsrelease()andPersonalKeyStoregainsrecordedCategories(): an adapter of your own implements all three.EventStore.resealtakesfromper event and resolves to the positions it left. An event namedScheduledCommandFailedis refused. New publicCategoryAheadError(SCHEMA_AHEAD).minorchangesets on every package changed.