Skip to content

feat(codegen-ts): keep the hash manifest as one file per model package - #617

Merged
dmealing merged 4 commits into
mainfrom
fm/mo-per-package-hashes
Nov 20, 2026
Merged

dmealing merged 4 commits into
mainfrom
fm/mo-per-package-hashes

Conversation

@dmealing

@dmealing dmealing commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Replaces the single committed .metaobjects/.gen-state/.hashes.json with a .hashes/ directory holding one JSON file per model package (<package>.json, with .root.json for paths in no package). Parallel branches that regenerate different packages no longer conflict on one file. Applied in every port that keeps hash state: TypeScript (codegen-ts hash-manifest-store.ts), C#, Java and Kotlin (codegen-base HashManifest), Python, and Rust (preview). Placement is a pure function of each entry's recorded source node or owning object name, and readers merge all package files with the legacy file underneath.
  • On the first gen after upgrade, the legacy .hashes.json is read, the package files are written, the legacy file is removed, and !.gen-state/.hashes/ is added to .metaobjects/.gitignore when the old negation is present. Writes touch only files whose bytes change. The TypeScript skip decision refuses to skip while a legacy manifest is still present, so the migration run always writes. verify reads the manifest without migrating it.
  • Shared conformance vectors (fixtures/codegen-skip-conformance/manifests.json, plus a legacy-manifest case) hold each port to the same placement and migration behavior. Adds a TypeScript branch-merge test that merges two git branches changing different packages without conflict. Documents the change in ADR-0064 Amendment 1, docs/features/migrations/per-package-hash-manifest.md, and updates the existing hash-manifest migration guides and CHANGELOG (metamodelVersion is unchanged).
Validation

Risk Assessment

✅ Low: Per-package manifest placement is a pure function with a union reader, so misplacement costs only a merge conflict. Legacy migration, skip bypass, gitignore rewrite and dry-run handling hold in the ports I traced, and the migrated example manifests keep identical entries. I did not read every test, doc or fixture file in the diff, and I ran no tests. Only a stale test helper was found.

Testing

Three live scenarios passed against the real TypeScript meta CLI in disposable projects: fresh per-package layout, parallel two-branch merge with a clean post-merge gen and verify, and migration of a legacy single .hashes.json written by the base-commit CLI. The adversarial fresh-clone hand-edit refusal also passed inside the parallel-branch run. The old-layout conflict control was not reproduced: the two-entry harness merged clean on base too, so the before/after conflict claim rests on reasoning and the adopter report. Broad regression came from the configured scripts/ci-local.sh --affected --strict-toolchains run, which passed at this commit. Evidence transcript:

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Fresh project: meta gen writes one manifest file per model package (acme::commerce -> acme.commerce.json, acme::users -> acme.users.json) and no legacy .hashes.json ✅ pass live (Scenario 1 block): bun server/typescript/packages/cli/bin/meta.ts gen in a disposable meta-init p…
Parallel branches: branch A edits package commerce and branch B edits package users from the same baseline; both merge into main with no conflict, the merged tree regenerates unchanged, and verify --c… ✅ pass live Scenario 2 block in the evidence transcript: git merge branch-a and git merge branch-b both exit 0, no unmerged paths and no conflict markers; B's merge touched only .hashes/acme.users.json, meta.user…
Adversarial: fresh clone (no .gen-state snapshot bodies) with a hand-edited generated file; meta gen refuses by name using the committed per-package manifest and leaves the edit on disk ✅ pass live Scenario 2 block, fresh clone, hand edit, gen: gen exit=1, src/generated/acme/commerce/Program.ts,refused, the unedited Subscriber.ts unchanged, warning text 'this file has been edited since it was ge…
Legacy upgrade: a project written by the base commit 333ccc6 CLI (single .hashes.json) is migrated by the new CLI on its next gen with no output change ✅ pass live Scenario 3 block: base CLI gen produced .gen-state/.hashes.json; new meta gen exit 0, both files unchanged; afterwards .hashes.json is absent and .hashes/acme.commerce.json and .hashes/acme.users.json…
Negative control: prove the old single-file layout conflicts in the same two-branch flow ⏸️ untested no Attempted with the base-commit CLI in the same two-branch flow. Both branches changed non-adjacent lines of the two-entry .hashes.json, so git merged it clean and no conflict reproduced. Reproducing t…
Evidence: Per-package hash manifest scenario transcript (fresh layout, parallel merge with adversarial fresh-clone refusal, legacy migration)
\### Scenario 1: fresh project writes one manifest file per package
gen[2]{file,status}:
  src/generated/acme/commerce/Program.ts,new
  src/generated/acme/users/Subscriber.ts,new
summary: 2 written
help[1]: typecheck the generated code with `npx tsc`
antiPatterns:
  status: ran
  total: 0
  rows: []
exit=0
-- .gen-state/.hashes:
acme.commerce.json
acme.users.json
-- legacy .hashes.json present:
ls: cannot access '.metaobjects/.gen-state/.hashes.json': No such file or directory
-- .metaobjects/.gen-state/.hashes/acme.commerce.json
{
  "src/generated/acme/commerce/Program.ts": {
    "hash": "db97ea10d5c9f482ddcb57781ffa1ffdfa1bbbee11e9b4e57e5ea679cc3b3394",
    "generatedBy": "entity-file",
    "sourceNode": "acme::commerce::Program"
  }
}
-- .metaobjects/.gen-state/.hashes/acme.users.json
{
  "src/generated/acme/users/Subscriber.ts": {
    "hash": "325c4078e99d85c7872d9b1a5e4bc022a3abd4d51e0ddf2ee1f237125e73f9f3",
    "generatedBy": "entity-file",
    "sourceNode": "acme::users::Subscriber"
  }
}

\### Scenario 2: parallel branches, each edits one package, merged
merge branch-a exit=0
Merge made by the 'ort' strategy.
 .metaobjects/.gen-state/.hashes/acme.users.json |  2 +-
 metaobjects/meta.users.json                     | 27 ++++++++++++++++++++++---
 src/generated/acme/users/Subscriber.ts          |  2 ++
 3 files changed, 27 insertions(+), 4 deletions(-)
merge branch-b exit=0
-- unmerged paths:
-- conflict markers:
(none)
-- gen on merged tree:
gen[2]{file,status}:
  src/generated/acme/commerce/Program.ts,unchanged
  src/generated/acme/users/Subscriber.ts,unchanged
summary: 2 unchanged
-- verify --codegen on merged tree:
verify exit=0
-- fresh clone, hand edit, gen (adversarial):
ln: failed to create symbolic link 'node_modules/node_modules': File exists
gen exit=1
gen[2]{file,status}:
  src/generated/acme/commerce/Program.ts,refused
  src/generated/acme/users/Subscriber.ts,unchanged
summary: "1 unchanged, 1 refused"

-- control: same two-branch flow with the base commit CLI (333ccc60d):
meta: .metaobjects/.gen-state/.hashes.json is git-ignored, so it never reaches another machine — on a fresh clone or CI runner 'meta gen' cannot tell your hand edits from its own stale output, and will refuse to overwrite rather than guess. The rule is '.gen-state/*' at .metaobjects/.gitignore:11 — replace it there with a '/*' form plus a '!' negation for the manifest (e.g. '.gen-state/*/*' and '!.gen-state/*/.hashes.json') (the glob matters — git will not descend into an excluded directory, so a negation INSIDE an excluded directory can never apply), then commit the manifest. If you deliberately do not commit generated output, ignore this.
meta: .metaobjects/.gen-state/.hashes.json is git-ignored, so it never reaches another machine — on a fresh clone or CI runner 'meta gen' cannot tell your hand edits from its own stale output, and will refuse to overwrite rather than guess. The rule is '.gen-state/*' at .metaobjects/.gitignore:11 — replace it there with a '/*' form plus a '!' negation for the manifest (e.g. '.gen-state/*/*' and '!.gen-state/*/.hashes.json') (the glob matters — git will not descend into an excluded directory, so a negation INSIDE an excluded directory can never apply), then commit the manifest. If you deliberately do not commit generated output, ignore this.
merge branch-a exit=0
Merge made by the 'ort' strategy.
 metaobjects/meta.users.json            | 27 ++++++++++++++++++++++++---
 src/generated/acme/users/Subscriber.ts |  2 ++
 2 files changed, 26 insertions(+), 3 deletions(-)
merge branch-b exit=0
-- unmerged paths:
-- conflict markers:
(none)

\### Scenario 3: legacy .hashes.json (base commit 333ccc60d CLI) migrated by new CLI
base gen exit=0
-- before (base layout):
src
.metaobjects/.gen-state/.hashes.json
gen[2]{file,status}:
  src/generated/acme/commerce/Program.ts,unchanged
  src/generated/acme/users/Subscriber.ts,unchanged
summary: 2 unchanged
help[1]: typecheck the generated code with `npx tsc`
antiPatterns:
  status: ran
  total: 0
  rows: []
new gen exit=0
-- after:
acme.commerce.json
acme.users.json
ls: cannot access '.metaobjects/.gen-state/.hashes.json': No such file or directory
-- .metaobjects/.gen-state/.hashes/acme.commerce.json
{
  "src/generated/acme/commerce/Program.ts": {
    "hash": "db97ea10d5c9f482ddcb57781ffa1ffdfa1bbbee11e9b4e57e5ea679cc3b3394",
    "generatedBy": "entity-file",
    "sourceNode": "acme::commerce::Program"
  }
}
-- .metaobjects/.gen-state/.hashes/acme.users.json
{
  "src/generated/acme/users/Subscriber.ts": {
    "hash": "325c4078e99d85c7872d9b1a5e4bc022a3abd4d51e0ddf2ee1f237125e73f9f3",
    "generatedBy": "entity-file",
    "sourceNode": "acme::users::Subscriber"
  }
}
  • Outcome: ⚠️ 1 info across 1 run (9m3s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ server/python/tests/codegen/test_cli_config_verify.py:133 - The _record_as_written helper still writes the legacy single-file .gen-state/.hashes.json. The test passes only because readers still merge the legacy file underneath the package files. So test_verify_codegen_shared_outdir_detects_stale_extra and its siblings never exercise the new .hashes/&lt;package&gt;.json layout for the verify path. server/python/tests/codegen/manifest_helpers.py was added in this change for this purpose, so the helper should write through it. (The Java ConfiguredGeneratorsTest legacy fixture at line 516 is deliberate, since it models a pre-release manifest.)
⚠️ **Test** - 1 info
  • ℹ️ .metaobjects/.gen-state/.fingerprint-typescript.json - The .metaobjects/.gen-state/.fingerprint-typescript.json file is still one shared file per project and is rewritten whenever the model changes. Init's .metaobjects/.gitignore ignores it, so projects scaffolded by meta init are unaffected. Projects without that .gitignore that track gen-state will still conflict on it when branches change the model. That behaviour predates this change, and the intent names only .hashes.json. No change requested.
  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Fresh project: meta gen writes one manifest file per model package (acme::commerce -> acme.commerce.json, acme::users -> acme.users.json) and no legacy .hashes.json ✅ pass live (Scenario 1 block): bun server/typescript/packages/cli/bin/meta.ts gen in a disposable meta-init p…
Parallel branches: branch A edits package commerce and branch B edits package users from the same baseline; both merge into main with no conflict, the merged tree regenerates unchanged, and verify --c… ✅ pass live Scenario 2 block in the evidence transcript: git merge branch-a and git merge branch-b both exit 0, no unmerged paths and no conflict markers; B's merge touched only .hashes/acme.users.json, meta.user…
Adversarial: fresh clone (no .gen-state snapshot bodies) with a hand-edited generated file; meta gen refuses by name using the committed per-package manifest and leaves the edit on disk ✅ pass live Scenario 2 block, fresh clone, hand edit, gen: gen exit=1, src/generated/acme/commerce/Program.ts,refused, the unedited Subscriber.ts unchanged, warning text 'this file has been edited since it was ge…
Legacy upgrade: a project written by the base commit 333ccc6 CLI (single .hashes.json) is migrated by the new CLI on its next gen with no output change ✅ pass live Scenario 3 block: base CLI gen produced .gen-state/.hashes.json; new meta gen exit 0, both files unchanged; afterwards .hashes.json is absent and .hashes/acme.commerce.json and .hashes/acme.users.json…
Negative control: prove the old single-file layout conflicts in the same two-branch flow ⏸️ untested no Attempted with the base-commit CLI in the same two-branch flow. Both branches changed non-adjacent lines of the two-entry .hashes.json, so git merged it clean and no conflict reproduced. Reproducing t…
  • scripts/ci-local.sh --affected --strict-toolchains
  • bun server/typescript/packages/cli/bin/meta.ts init in a disposable scratch project (synthetic two-package model, entityFile generator)
  • bun server/typescript/packages/cli/bin/meta.ts gen on a fresh project: exit 0, per-package manifest files written, no .hashes.json
  • Two-branch parallel edit (branch-a in acme::commerce, branch-b in acme::users) merged with git merge in a disposable repo: both exit 0, no unmerged paths
  • Post-merge meta gen (both files unchanged) and meta verify --codegen (exit 0)
  • Fresh git clone of the disposable repo, hand edit to a generated file, meta gen: exit 1, file refused by name, unedited file unchanged
  • Legacy upgrade: base-commit 333ccc60d CLI extracted with git archive wrote a .hashes.json; new CLI meta gen exit 0, outputs unchanged, legacy file removed, per-package files written
  • Driver script ran end-to-end; transcript saved to evidence; scratch projects removed afterwards; no background processes started
  • Broad regression came from the configured test command scripts/ci-local.sh --affected --strict-toolchains, which passed at this target commit. Not re-run here because no source or test files were changed in this turn.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Parallel branches that regenerate files in different packages no longer
conflict on a single .gen-state/.hashes.json. The manifest is now
.gen-state/.hashes/<package>.json, with .root.json for a path in no
package, in every port that keeps hash state (TypeScript, C#, Java,
Kotlin, Python, Rust).

- ADR-0064 Amendment 1 records the layout, the file naming, the
  placement rules (sourceNode, then the model object a file name starts
  with by words, then the file it was read from, then root), the
  write-only-what-changed rule and the migration.
- fixtures/codegen-skip-conformance/manifests.json holds the shared
  vectors, and a legacy-manifest case in cases.json holds every port to
  the migration: a run that finds the legacy file splits it, deletes it
  and adds the gitignore negation; verify never migrates.
- Placement only decides which file holds an entry. Readers merge every
  file, so a wrong placement costs a merge conflict and nothing else.
- A test merges two real git branches that change different packages
  with no conflict.
- CHANGELOG lists it under "Upgrading from 1.2.0" for 1.3.0, with a
  migration guide.
- Rust keeps .root.json only when the manifest holds no entry at all
  (ADR-0064 Amendment 1 section 4), matching the other ports.
- Java feeds only root-level objects into the stem index, as the other
  ports do, and touches .metaobjects/.gitignore only when it migrates a
  legacy manifest.
- Migration replaces the dead `!.gen-state/.hashes.json` negation with
  `!.gen-state/.hashes/` in every port (shared vector updated), instead
  of leaving both.
- The JVM, TypeScript and 1.0-to-1.1 migration guides name the
  directory in their commands and ignore rules, so following them no
  longer git-ignores `.hashes/`.
- The four example projects carry their migrated `.hashes/` manifest.
- The Python no-op save test now re-records identical content and checks
  no file changes, instead of setting its own flag.
@dmealing
dmealing merged commit 7fa4695 into main Nov 20, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-per-package-hashes branch November 20, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant