Repository navigation
feat: record every forgetting in the forget ledger before it commits - #261
Merged
Merged
Conversation
A forgetting committed and then appended to the ledger was lost to a restore when the process stopped between the two steps. Every forgetting now writes its intention first, with its event's id and time set before the transaction, and a reconciliation commits again, under the same id, time and reason, each one the database does not hold while the person still holds a key it names by fingerprint. A strict ledger forgets nobody it has not recorded, every ledger call is bounded by forgetLedger.timeout, bounda forgotten reads the event store without starting the app, and bounda forget-ledger expire gives KV entries written before keepFor their expiration.
…ation testing Pass the ledger to the intentions with its strictness and open it only when configured, so nothing guards a ledger that cannot be missing. A whole entry is committed again without reading its event and key a third time, a bare id given a key meanwhile takes a new intention, and the retention checks the person's row is current before it writes an intention it would leave. The CLI opens a project's storage through isAdapter, now public, and a ledger of your own is told to keep every field of an entry.
… says where it happened
Closing the client under a statement or transaction still running frees what libSQL's native code is using; a ledger call given up for its timeout and then closed with the app did just that. The connection now waits for everything it started before it closes. The two tests that opened a file from six worker threads and terminated them crashed the test process on Windows now and then (0xC0000005): libSQL's native code does not survive a thread that ends under it. They open the file from processes instead, as instances do.
…ledger-first # Conflicts: # docs/src/content/docs/guides/personal-data.md # docs/src/content/docs/reference/configuration.md # packages/cli/src/run.test.ts # packages/cli/src/run.ts # packages/cloudflare/src/forget-ledger.ts # packages/core/src/adapter/sql/forget-ledger.ts # packages/core/src/adapter/sql/index.ts # packages/core/src/adapter/sqlite/migrations.ts # packages/core/src/index.ts # packages/core/src/kernel/personal-data/ledger-append.test.ts # packages/core/src/kernel/personal-data/reconciliation-app.test.ts # packages/core/src/kernel/personal-data/retention.test.ts # packages/core/src/kernel/personal-data/retention.ts # packages/postgresql/src/migrations.ts
…ledger-first # Conflicts: # packages/cloudflare/src/index.ts
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.
With a forget ledger configured, every forgetting is now in the ledger before it commits, so a process that stops between the two, or a transaction that fails, never loses one.
What changes
forget,forgetAgain/bounda forget, a policy's or process'sforget(a newbeforeCommitstep of the unit of work, run once the attempt has decided, just before its transaction opens) and the retention write the forgetting's intention to the ledger first. The event's id and time are set before the transaction, which appends the event with them: the ledger and the database name one forgetting by one id.forgetthat rejects after its intention was written still forgets the person then; calling it again is safe.PersonalDataForgottencarry the fingerprints of the keys a forgetting destroys. A reconciliation commits an entry only while the person still holds a key it names: a key given after (they came back) is kept. This also settles the order between several intentions of one person, whatever order they are read in.retentionDueOf), so an intention its transaction backed out of (restricted, active again) never forgets.FORGET_LEDGER_GRACE_MS(one minute) to a later one, due once they come of age, so it never races a forgetting still committing.strictnow also means nothing is forgotten that the ledger has not recorded:ForgetLedgerUnavailableError(FORGET_LEDGER_UNAVAILABLE), nothing forgotten, retry is safe. Policies fail and retry; the retention holds the person.forgetLedger.timeout(DEFAULT_FORGET_LEDGER_TIMEOUT_MS, ten seconds) bounds every ledger call, the outbox and prune included, withForgetLedgerTimeoutError(FORGET_LEDGER_TIMEOUT, withoperationandtimeoutMs), and how long a non-strict start waits. A strict start no longer waits forever on a hung read."restored"is gone (never released): a forgetting committed again keeps its own. The after-commit append (withLedgerAppend) is replaced by the intention; the stream outbox stays for what a non-strict ledger did not take.reasonandfingerprintsin version 2 of theforget-ledgerscope (SQLite, PostgreSQL); KV keeps them in each key's metadata; memory keeps them. Earlier entries read as a request naming no keys.bounda forgottenreads the event store without starting the app (no ports, read models or ledger), so a strict ledger that is down does not stop it; its lines carryreasonandfingerprints.bounda forget --fromcommits each whole line again under its own id, time and reason. Newbounda forget-ledger expire --binding <name> --keep-for <duration>gives every key of a Workers KV ledger the expirationkeepForsets, those written before it was set included, through the project's wrangler (--local,--env,--wrangler-config,--persist-to).planKvForgetLedgerExpiryandexpireKvForgetLedger, also from a new Node-safe subpath@bounda-dev/cloudflare/forget-ledger.parseDurationis exported from core, andisAdapterfrom@bounda-dev/core/adapter(what the CLI opens a storage with).Tests for each edge
strict(commits, warns, the outbox copies it) and withstrict(FORGET_LEDGER_UNAVAILABLE, nothing forgotten, retry works), forforget,forgetAgain, the retention and the Durable Object.FORGET_LEDGER_TIMEOUTas cause; a non-strict one commits and stops waiting while the call hangs; a strict start fails past the timeout; a non-strict start goes on after it.reasonandfingerprints; the storage schema contract pinsforget-ledgerversion 2;wrangler kvagainst its local state forforget-ledger expire.Checked
pnpm checkwith Docker green (3422 tests) but for two local-only failures:astro checkcrashes on macOS with Node 25 (below), and the Vite plugin test ofreact-router, untouched, timed out once under a machine load of 170 and passes alone./code-reviewhigh: 7 findings, 5 fixed (retention checks the row before writing an intention, no third read when committing an entry again,isAdapterreused, own-ledger docs, no JSDoc on CLI internals), 2 not reachable (the Worker serves no forget; key reads and removal are serialized in the transaction).Left out
astro checkof the docs crashes locally on macOS with Node 25 in@emnapi/runtime2.0.0-beta.2, onmaintoo; CI runs it on Linux.