feat(migrate,metadata-protocol): os migrate meta --stored rewrites sys_metadata rows in place (#4327) - #4464
Merged
Conversation
…s_metadata rows in place (#4327) #4317 closed the correctness gap from the read side: every stored-row rehydration seam replays the full ADR-0087 conversion chain, retired entries included, so a row written under any past protocol is served canonical forever. The rows themselves stayed legacy — the chain re-lowers them on every load and each logs a conversion notice per process. Until now the only things that rewrote such a row were a Studio re-save and duplicatePackage. `os migrate meta --stored` walks sys_metadata (active + draft, all orgs), replays the same applyConversionsToStoredItem pass, and re-saves each changed body through saveMetaItem — so a rewritten row gets a sys_metadata_history entry, a fresh checksum and the mutation projectors, exactly like an author's save. The history row's source is `migrate-stored`, distinguishing an upgrade from an edit. parentVersion is the row's own checksum, so a concurrent writer produces a 409 the report names rather than a clobber. Preview is the default and --apply the only writing mode, matching its two siblings and #3617's "a dry run changes nothing"; an apply run refuses to start while another process holds the SQLite database. Nothing gates on this having run (#3855) and no sys_migration flag is recorded — a flag would advertise enforcement that does not exist. What a run buys is hygiene plus an assertable verdict: nothing left to do exits 0, work remaining exits 1. Three carve-outs are reported rather than counted as done: flow rows (their seam is AutomationEngine.registerFlow, which holds the executor registry the node-type conflict guard needs), types with no repository write path (agent), and rows that still fail the current schema after conversion. An empty scan says it attests nothing rather than reading as a pass. Also: protocol.migrateStoredMetadata() returns the same structured report an admin route would render, and saveMetaItem takes an optional `source` for its history/audit rows — server-stated, never request-derived. Closes #4327 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WoZPKPDqJ7WB7z84xk9y3f
…sh line (#4454) The addendum said flows were "tracked separately" without saying where. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WoZPKPDqJ7WB7z84xk9y3f
…tion-stored-rewrite-jxlz2k # Conflicts: # packages/metadata-protocol/src/protocol.ts
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 23 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
The v17 entry for #3903 described the read-path guarantee and stopped there, and the upgrade checklist listed the two per-deployment migrations without this one. Both now point at `os migrate meta --stored`, marked optional — it opens no gate, unlike its two neighbours in that list. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WoZPKPDqJ7WB7z84xk9y3f
…tion-stored-rewrite-jxlz2k
…tion-stored-rewrite-jxlz2k
This was referenced Aug 1, 2026
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.
Closes #4327.
Why
#4317 answered #3903 from the read side: every stored-row rehydration seam replays the full ADR-0087 conversion chain, retired entries included, so a row written under any past protocol is served canonical forever. What it deliberately did not do is make the rows themselves canonical — a pre-17 row keeps its legacy bytes, the chain re-lowers it on every load, and each affected row logs one conversion notice per process. Until now the only things that ever rewrote such a row were a Studio re-save and
duplicatePackage.What
protocol.migrateStoredMetadata()walkssys_metadata—active+draft, every org — replays the sameapplyConversionsToStoredItempass, and re-saves each changed body throughsaveMetaItem. So a rewritten row gets everything an author's save gets: the schema gate, asys_metadata_historyrow, a fresh checksum, the mutation projectors and the watch event Studio's HMR consumes. Three deliberate arguments:parentVersion: row.checksum— a true optimistic lock. A concurrent writer that moved the row gets a 409, reported asfailed, never a clobber.force: true— the destructive diff compares the stored body (whichgetMetaItemalready serves converted) against the same conversion. Empty by construction, and there is no author here for a prompt to reach.source: 'migrate-stored'— a later history diff distinguishes an upgrade from somebody's edit.os migrate meta --storedis the operator surface. Archived/deprecated rows are never read (they are a record of what was), andsys_metadata_historyis appended to, never rewritten — converting a version body would break the checksum↔body pairing the contract depends on.Two deliberate deviations from the issue text
Preview is the default;
--applyis the only writing mode. The issue sketched "optionally--dry-run", i.e. writing by default. Both siblings (os migrate value-shapes,os migrate files-to-references) and #3617's "a dry run changes nothing" establish the opposite, and the reason applies with more force here because what moves is metadata: every affected row's checksum and one history entry per row. An apply run also refuses to start while another process holds the SQLite database, for the same reason the file migration does (--forceoverrides).No
sys_migrationflag row. The issue is explicit that this is not load-bearing, and #3855's conclusion stands — an operator-run migration cannot be relied upon, so the read path remains the guarantee. A flag row would advertise a gate that does not exist. The "explicit, verifiable my data is on protocol N" the issue asks for is delivered by the re-run instead: nothing left to do exits0, work remaining exits1, so the claim becomes a CI check rather than a belief.What it declines, and names
Reported, never counted as done:
flowrowsreservedNodeTypes). Flows canonicalize atregisterFlow. Filed as #4454agent)saveMetaItemroutes those down the legacy raw-engine branch: no history row, and a forcedstate: 'active'that would promote a draft. A historyless half-write is worse than leaving the row to the read pathAn empty scan says it attests nothing rather than reading as a pass — same lesson as the value-shape scan: "nothing to convert" and "nothing was looked at" are different claims, and a run from the wrong project root produces the second.
No speculative API was added for the flow case: a
canonicalizeFlowhook nothing can pass would advertise a capability the runtime does not deliver (PD #10). #4454 sketches the automation-engine entry point it needs.One bug fixed on the way
oclif's
dependsOncannot express "stored-only": a boolean withdefault: falseand anenv-backed string both read as provided, sodependsOn: ['stored']on--database-urlwould make a merely-exportedOS_DATABASE_URLbreakos migrate meta --from N. The guard reads raw argv instead (storedOnlyFlagsIn), which also closes adeclared ≠ enforcedgap:--applyon the authored-source chain is now refused rather than silently ignored.Verification
protocol.stored-migration.test.ts(preview writes nothing; apply rewrites in place; history row + fresh checksum +migrate-storedsource; re-run is a no-op; drafts stay drafts; all orgs; archived untouched; type filter; each carve-out; unparseable body; schema refusal; optimistic-lock conflict does not clobber), 8 inmeta.stored-flags.test.ts(the argv guard incl. the env-var trap, and the flag declarations).metadata-protocol·cli·objectql·rest·metadata·runtime·specall green after mergingmain(which carried three commits touching these packages; one import conflict inprotocol.ts, resolved keeping both sides).pnpm lint,tsc --noEmit, and thedoc-authoring/type-check-coverage/published-files/changeset-fixedgates pass.conditionalRequiredrow intoexamples/app-todo's SQLite → preview exits 1 and names the conversion →--applyrewrites → DB shows the same row id with a canonical body, a new checksum, and asys_metadata_historyrow{source: 'migrate-stored', previous_checksum: <the legacy checksum>}→ re-run reports canonical and exits 0.Docs
content/docs/deployment/cli.mdxgains anos migrate meta --storedsection (including the occupancy-gate row and the "hygiene, not a gate" framing), and ADR-0087 gains a 2026-08-01 addendum recording the decision — why no flag, why the write gate is not bypassed, why history stays verbatim, and what the pass does not cover.🤖 Generated with Claude Code
https://claude.ai/code/session_01WoZPKPDqJ7WB7z84xk9y3f
Generated by Claude Code