Repository navigation
docs(adrs): extend M5 close-out across the related ADR set - #419
Conversation
📝 WalkthroughWalkthroughThis PR updates ADRs to add invariant-aware migration routing: a persistent ChangesInvariant-Aware Migration Routing System
Sequence DiagramsequenceDiagram
participant CLI
participant Planner
participant Graph
participant Runner
participant DB
CLI->>Planner: migration status/apply (--ref?)
Planner->>Graph: findPathWithInvariants(from,to,required)
Graph-->>Planner: path / unreachable / unsatisfiable
Planner->>Runner: execute plan (includes providedInvariants)
Runner->>DB: apply edge, atomically update core_hash/profile_hash + union(invariants)
DB-->>Runner: ack
Runner-->>CLI: success / MIGRATION.INVARIANTS_PENDING / error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-telemetry
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-telemetry
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
Builds on the ADR 208 + ADR 001 amendment already on this branch. Re-applies the durable contributions from the closeout-backup branch on the new base, dropping anything that the post-closeout work has made obsolete. ADR 208: add the marker-vs-ledger framing as a principle, not a pragmatic trade-off. The marker is what Prisma Next has signed the database with (a framework-issued guarantee record); the ledger is an audit artifact (user-owned lifecycle, truncatable). Structural framework behaviour must never depend on the audit log. Plus the explicit alternatives-considered (rejected ledger-side, rejected graph-derived) for completeness. Skipped from the backup branch: - The "Known soundness gap: pre-check vs squash" subsection — the CLI now defers UNKNOWN_INVARIANT until after marker subtraction (52ab770), which is the option-(a) fix the gap discussion called for. The gap is closed. - The "runner derives invariants from plan.operations" §D7 framing — the runner now reads options.plan.providedInvariants (ec06cc5), which is what the existing §"Plan envelope carries providedInvariants" section already documents. ADR 021: invariants column in the marker DDL example, server-side merge note in §Ownership and lifecycle, Mongo schemaless behaviour on absent field, SQLite BEGIN EXCLUSIVE merge. ADR 042: superseded-for-prerelease banner. The auto-migration v1->v2 story isn't how the marker schema evolved in practice; the invariants column lives in CREATE TABLE IF NOT EXISTS from the start with no in-place upgrade. ADR 039: from == to rejection narrowed to ops-free self-edges. findPathWithInvariants documented (state-level dedup, int32-bitmask state encoding capped at k=30, byte-identical fallback to findPath when required = empty). Neighbour ordering owned by neighbour generation. Covering-edges-first as primary tie-break key when required is non-empty. Terminology blockquote for edgeId/migrationHash. ADR 176: reconciliation banner mapping the v1 implementation back to the conceptual model (named identity, applied-at-least-once marker, Model A co-located, fail-closed routing). Open questions closed item-by-item with cross-references to ADR 208. ADR 169: refs now {hash, invariants}, per-file layout, drives invariant-aware routing via effectiveRequired. migrationHash covers providedInvariants (and invariantId on data ops via ops.json). ADR 192: new §"Op schema includes routing-layer fields" — invariantId round-trips through MigrationOpSchema. Cross-ref to ADR 208 added.
Self-review pass from a new-reader perspective. Three classes of fix.
Terminology consistency in ADR 208 §"Why marker, not ledger or
graph-derived":
- "data-transform guarantees" --> "data-transform invariants" so the
whole subsection uses the same term as the rest of the ADR.
- "Structural framework behaviour" --> "Framework decisions about
applicability and routing". The word "structural" is overloaded
elsewhere in the ADR (it contrasts with "invariant-aware" routing),
so reusing it here for "core / load-bearing framework behaviour"
was confusing.
- "what Prisma Next has signed the database with" --> "the database's
own statement of what the framework has confirmed about it". The
"signed" metaphor reads as cryptographic signing on first encounter.
Code-internal jargon softened in §"Why marker..." alternatives:
- "readLedger SPI on ControlFamilyInstance" --> "ledger-read SPI
surface across both storage families". The named identifier was
load-bearing for an insider but opaque to a fresh reader; the
paraphrase preserves the rationale.
- "Mongo ledger parity (TML-2283)" --> "Mongo's ledger up to parity
with the SQL ledger, which is its own workstream". The Linear
ticket reference doesn't survive outside the org.
- "db update" gets a one-clause gloss inline ("which advances the
marker without going through migrations") so the reader doesn't
have to chase the term.
- "anyone vacuumed the ledger lately" --> "ledger retention policy".
Clearer about the category-error claim.
ADR 021 server-side merge bullet:
- Replaced unicode "double bar" character with the actual SQL `||`
array-concat operator. Previously matched neither Postgres nor
ADR 208's main body, where the operator is correctly `||`.
- Spelled out why server-side merge eliminates the race instead of
just naming the race.
Reviewing my own banners against the established pattern (ADR 044, 167, 174, 193): supersession banners are one paragraph stating what's superseded and where the new content lives, not a recap of the new ADR. ADR 174's pattern for resolved open questions is strikethrough on the original question + a one-line "Resolved" annotation, not rewritten bullets. ADR 176: replace the seven-bullet "ADR 208 records..." banner with a one-sentence "Refined by ADR 208" banner. In §Open questions, keep each original question (struck through) and add a one-line resolution pointing to ADR 208 / ADR 039. Matches ADR 174 §Open questions. ADR 042: trim the three-paragraph banner to one paragraph. The rationale and "future-revisit" notes were duplicating each other and ADR 208's content.
…acts Before deleting the bench doc, lift its conclusions into ADR 208 as a new §"Performance and the absence of a hard guard". Captures: the Set<string> covered-set encoding (with the bitmask history the encoding choice records), production-typical wall times (sub-ms at k=0 or 1), the 2^k worst case (~80 ms at k=8, ~8.7 s at k=16 on synthetic branchy inputs), why a hard guard isn't warranted for v1, and the soft heads-up option. Fix ADR 039 §Path computation: my earlier amendment described the covered-subset encoding as an "int32 bitmask capped at k=30", which was correct at the time of M3 but obsolete after a0bfe17 refactored to Set<string>. Rewritten to match current code; defers performance discussion to ADR 208. Retire the now-superseded transient artefacts under projects/graph-based-migrations/: - specs/chat.md (40K of pure scratch) - specs/april-milestone.md (past milestone planning) - specs/data-migration-scenarios.md (exploratory) - specs/data-migrations.md (theory; superseded by ADR 176 + spec) - specs/data-migrations-solutions.md (exploratory) - specs/planner-replacement-proposal.md (proposal) - invariant-aware-routing-bench.md (conclusions now in ADR 208) Retained for reasons noted previously: data-migrations-spec.md, data-migrations-plan.md, disk-sizing-investigation.md, walkthrough.md. issue-triage.md retained pending Linear filing of its one substantive entry.
The one substantive entry (marker SQL duplicated across families) is known and being addressed separately. The triage file's suggested fix of a shared sql-marker package is also not the right shape — marker SQL can't really be shared across targets given dialect differences. Delete the scratch.
walkthrough.md belonged to the graph-status-rendering workstream — its companion spec / plan (migration-status-graph-rendering.spec.md / -plan.md) were retired earlier; the doc has been an orphan for a while, with several dangling cross-references (the spec and plan files don't exist; one bullet linked to issue-triage.md, which we also just retired). Delete the doc.
The two benchmark baselines and the disk-sizing investigation were working artefacts from the April migration-perf characterisation. Their conclusions are settled (no perf guards, sub-ms typical, no disk sizing concerns at expected migration counts) and the docs are not referenced from anywhere except each other. Deleted: - docs/planning/benchmarks/migration-graph-baseline.md - docs/planning/benchmarks/migration-planner-baseline.md - projects/graph-based-migrations/disk-sizing-investigation.md
The data-migrations parent spec and its plan were the last remaining files in projects/graph-based-migrations/. With TML-2283 closing on PR #404 merge, neither has an open workstream consuming them: the routing slice is owned by ADR 208, the conceptual model lives in ADR 176, and the data-transform authoring + planner-positioning theory text has no live consumer. The umbrella folder retires entirely.
6ff43b0 to
364f383
Compare
… references Self-review pass per the "long-lived documentation" lens — ADRs shouldn't reference Linear tickets, project milestones, or transient states the system passed through. ADR 208 substantial rewrite: - Lead with §"At a glance" worked example (phone-backfill scenario) so a reader without context anchors on something concrete before hitting the decision content. - Restructure §Decision into the natural narrative arc — identity, manifest aggregate, edge-level invariants, routing primitive + outcome, marker semantics, server-side merge, CLI subtraction, status diagnostic, plan-envelope threading. Replaces the feature-checklist ordering. - Drop §Verification entirely. The AC-IDs (AC-A01..AC-Z06) referenced acceptance criteria from a now-deleted spec; "M1-M4" and "this PR" are project-state markers. The whole section was anchored to a state that no longer exists. - Drop "D4 -- Split identity" / "D5" / etc. numbering. The D-numbers were anchored to a now-deleted spec where D1-D3 lived. - Drop "obsolete-by-design" and "earlier spec text" framing -- describe the current rule directly. - Drop "(an earlier 30-bit-mask version was simpler-per-state...)" parenthetical from §Performance -- describe the current Set<string> encoding directly. The bitmask trade-off lives in §Alternatives now. - Move alternatives discussion (ledger-side / graph-derived / parallel runner channel / bitmask) to a §Alternatives considered at the end. - §"Why the marker, not the ledger" stays as a standalone principle section between §Decision and §Performance. ADR 042: replace the 3-paragraph "Superseded for prerelease" banner with a one-sentence cross-reference note. The pattern in this ADR isn't actually superseded -- ADR 208 just didn't use it for one specific column. The pattern remains the design of record for future schema changes that need to migrate live deployments via ALTER. ADR 176: drop "v1 implementation" -> "the implementation" in the banner; drop "edited manually for v1" -> "edited manually" in the resolved open-questions list. ADR 039: rephrase "the rejection is narrowed to ops-free self-edges" as a direct description of the current rule.
The bitmask covered-subset encoding wasn't a design alternative considered at decision time — it was an implementation we shipped and refactored away. That kind of implementation history doesn't belong in long-lived documentation. §Performance still describes the current Set<string> encoding directly; nothing else needs to change.
The word betrayed implementation history (the option channel was tried and removed). The argument against re-adding it stands without the prefix: a parallel option is a second source of truth for a property verify already enforces.
wmadden
left a comment
There was a problem hiding this comment.
The ADR is great, nice work, but it has a couple of outdated claims 👍🏻
pre-emptively approving
Will flagged three places in his review where I claimed `migration verify`
was the integrity gate. The command doesn't exist — manifest integrity
runs at load time in readMigrationPackage (re-derive providedInvariants
from ops.json + recompute migrationHash). Self-review of all our edits
turned up additional issues, mostly clustered in ADR 208's §"At a glance"
example.
ADR 208 §"At a glance" example:
- this.dataTransform(endContract, name, options) — was 2-arg
dataTransform(name, options), which doesn't exist on Postgres.
- check / run closures take no parameters and return SqlQueryPlan |
Buildable. Was check: db => ... / run: db => ..., neither shape exists.
- addColumn requires defaultSql in ColumnSpec — was missing.
- Made the example explicitly schematic ("query bodies elided") since the
full SQL DSL surface isn't relevant to the routing story.
- Migration class needs describe() and the bottom MigrationCLI.run(...)
to be a complete authored migration; both added.
ADR 208 §"At a glance" prose:
- "MIGRATION.UNKNOWN_INVARIANT before any database activity" was wrong;
the check now runs after client.connect + readMarker (per the post-#404
fix that defers the check until marker.invariants is available).
- "no migration provides" was incomplete; the actual rule checks
declared ∪ marker.invariants, so an id from a retired migration that
the marker still has does not fail UNKNOWN_INVARIANT.
- Replaced the fictitious "→ prod / required / applied / missing /
route" output box with prose; the box doesn't match real apply output.
ADR 208 §"Manifest aggregate" / §"Plan envelope" / §"Alternatives":
- All three referenced `migration verify`. Replaced with "load-time
integrity check" or equivalent.
ADR 169 §3 (Will's #1): "The migration `verify` step ..." → "When a
migration is loaded from disk, the loader ..."
ADR 192 (Will's #2): "at verify time" → "at load time"
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/architecture` docs/adrs/ADR 208 - Invariant-aware migration routing.md:
- Around line 117-119: The fenced code block containing the expression
"effectiveRequired = ref.invariants − marker.invariants" is unlabeled and
triggers MD040; update that triple-backtick fence to include a language tag
(e.g., use "text") so it becomes ```text, ensuring the block remains otherwise
unchanged and Markdown linter rules pass; locate the fenced block by searching
for the exact expression "effectiveRequired = ref.invariants −
marker.invariants" in the ADR content.
🪄 Autofix (Beta)
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: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 8b29d28a-043f-4cc7-998b-8187986043dc
📒 Files selected for processing (6)
docs/architecture docs/adrs/ADR 039 - Migration graph path resolution & integrity.mddocs/architecture docs/adrs/ADR 042 - Contract Marker Evolution.mddocs/architecture docs/adrs/ADR 169 - On-disk migration persistence.mddocs/architecture docs/adrs/ADR 176 - Data migrations as invariant-guarded transitions.mddocs/architecture docs/adrs/ADR 192 - ops.json is the migration contract.mddocs/architecture docs/adrs/ADR 208 - Invariant-aware migration routing.md
✅ Files skipped from review due to trivial changes (4)
- docs/architecture docs/adrs/ADR 192 - ops.json is the migration contract.md
- docs/architecture docs/adrs/ADR 176 - Data migrations as invariant-guarded transitions.md
- docs/architecture docs/adrs/ADR 042 - Contract Marker Evolution.md
- docs/architecture docs/adrs/ADR 169 - On-disk migration persistence.md
| ``` | ||
| effectiveRequired = ref.invariants − marker.invariants | ||
| ``` |
There was a problem hiding this comment.
Add a language tag to the fenced block on Line 117.
This block is currently unlabeled and triggers Markdown lint rule MD040. Use text (or another explicit language) to keep docs lint-clean.
Suggested patch
-```
+```text
effectiveRequired = ref.invariants − marker.invariants</details>
As per coding guidelines, “Keep docs current (READMEs, rules, links) as defined in `.cursor/rules/doc-maintenance.mdc`.”
<!-- suggestion_start -->
<details>
<summary>📝 Committable suggestion</summary>
> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
```suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 117-117: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for 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.
In `@docs/architecture` docs/adrs/ADR 208 - Invariant-aware migration routing.md
around lines 117 - 119, The fenced code block containing the expression
"effectiveRequired = ref.invariants − marker.invariants" is unlabeled and
triggers MD040; update that triple-backtick fence to include a language tag
(e.g., use "text") so it becomes ```text, ensuring the block remains otherwise
unchanged and Markdown linter rules pass; locate the fenced block by searching
for the exact expression "effectiveRequired = ref.invariants −
marker.invariants" in the ADR content.
docs(adrs): extend M5 close-out across the related ADR set
Base:
invariant-routing-cli(stacked on top of #404)Branch:
invarant-routing-closeoutSummary
Stacks on #404. Extends the M5 close-out — which today touches ADR 001 (self-edge relaxation) and the new ADR 208 (invariant-aware migration routing) — across the rest of the ADR set the work materially affected: 021, 039, 042, 169, 176, 192.
The goal: a reader landing on any of those ADRs sees the v1 decisions inline rather than having to chase ADR 208 to find out what changed underneath them. Most of the amendments are short cross-reference updates; the substantive additions to ADR 208 are:
#### Why marker, not ledger or graph-derived— promotes the marker-vs-ledger distinction from a pragmatic trade-off to a principle: marker = framework-issued guarantee record, ledger = audit artifact, structural framework behaviour must never depend on the audit log. The framing was inline in the spec and would have been lost when the spec was retired.### Performance and the absence of a hard guard— lifts the conclusions from the now-retiredinvariant-aware-routing-bench.md: production-typical inputs stay sub-millisecond, the2^kcurve only materialises on synthetic worst case, no hard guard warranted for v1, optional--verboseheads-up at largekif we want it later.Plus a final cleanup pass:
projects/graph-based-migrations/is retired in full (its remaining transient artefacts had no live consumers — the routing slice is in ADR 208, the conceptual model is in ADR 176, and TML-2283 closes on #404 merge), as are the orphaned April migration-perf baselines underdocs/planning/benchmarks/.What's deliberately not in this PR
Two sections from an earlier draft of this work were dropped after rebasing onto the current
invariant-routing-cli, because the post-#404 polish trail made them obsolete:UNKNOWN_INVARIANTcould fire even whenmarker.invariantsalready had the id. Closed by52ab770c8 fix(cli): defer UNKNOWN_INVARIANT pre-check until marker.invariants— the CLI now subtracts before the pre-check.plan.operations" framing in ADR 208 §D7. Replaced byec06cc550 feat(migrations): thread providedInvariants through plan envelope— runners now readoptions.plan.providedInvariants, and ADR 208's existing §"Plan envelope carriesprovidedInvariants" already documents the new shape correctly.No code, tests, or behavioural changes — this is documentation + transient-artefact cleanup only.
Test plan
findPathWithInvariantsfor ADR 039,MigrationOpSchemafor ADR 192, runners for ADR 208) and confirm the prose matches what's actually inmain + #404.data-migrations-spec.mdthat's been left dangling on purpose (different workstream's content).ADR 208 - Higher-order codecs for parameterized types.md(codec work) andADR 208 - Invariant-aware migration routing.md(this work) coexist. Out of scope here; the team will need to renumber one.Related
feat(migration,cli): invariant-aware ref routing (M4) + self-edge support)projects/graph-based-migrations/umbrella folder in full following feat(migration,cli): invariant-aware ref routing (M4) + self-edge support #404's spec/plan retirement (2f5c24869)Summary by CodeRabbit