Skip to content

feat(rust): add metaobjects-render prompt render and reply parser - #630

Merged
dmealing merged 5 commits into
mainfrom
fm/mo-130-lane-rust-2
Nov 21, 2026
Merged

dmealing merged 5 commits into
mainfrom
fm/mo-130-lane-rust-2

Conversation

@dmealing

Copy link
Copy Markdown
Member

What Changed

  • Adds the publishable server/rust/metaobjects-render crate (not published to any registry). It renders template.* bodies with mustache-ng underneath, escaping each value for its format, expanding partials ahead of time, and deriving has<Field> and -last accessors. It also includes the tolerant reply parser (extract, FR-010/011) and the output-format prompt fragment (prompt). Hand-written patterns keep its dependencies small.
  • eject --force compares the existing copy with the shipped generator first. An identical copy reports [unchanged] and is not rewritten, so its mtime is kept. A CLI test covers this.
  • Registers Rust in scripts/check-extract-field-kinds.mjs and expected-field-kinds.json. Updates docs/ports/rust.md, docs/CONFORMANCE.md, the ADR-0065 amendment and the docs index to list the render, extract and output-prompt corpora as run and payload-type codegen, reply-parser codegen and the template verify gate as still missing.
Validation

Risk Assessment

✅ Low: The fix round's only change is a MAX_DEPTH=100 counter threaded through parse_children/combine in xml_reader.rs, which closes the stack-overflow path with a behavioural test. The eject compare-before-write, the field-kind registration and the workspace wiring are small and consistent with the intent.

Testing

Broad regression came from the configured test command scripts/ci-local.sh --affected --strict-toolchains, which passed at 9cf3be2 and was not re-run. Driven live against the real product built from this commit: (1) cargo-meta eject --force over an identical copy reports [unchanged] and keeps its mtime, while an edited copy is still replaced; (2) the XML reply reader survives a 50k-deep reply on a 2 MiB stack, where the pre-fix commit aborts with a stack overflow, and normal nested replies still parse; (3) render escaping matches the shared render-conformance fixtures and the marker, cycle, set-delimiter and maxChars refusals hold. Overall all three pass. One observation, not a finding: the deep reply yields {} for an optional String field instead of carrying the text, which is not a crash and the depth-guard intent is met.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
eject --force over a copy byte-identical to the shipped generator reports [unchanged] and keeps its mtime; an edited copy is still replaced (live cargo-meta binary, scratch project with synthetic Orde… ✅ pass live ~/.no-mistakes/evidence/01M7ZH2N214XAEYW3S6HZPXS91/eject-force-unchanged.txt; cargo build -p metaobjects-cli then cargo-meta meta eject entity [--force]
Adversarial: a 50k-deep unclosed <a> XML reply does not abort the process; normal nested XML still parses (probe on a 2 MiB thread, fixed vs pre-fix 1ed7e77^) ✅ pass live ~/.no-mistakes/evidence/01M7ZH2N214XAEYW3S6HZPXS91/xml-reply-depth-guard.txt; scratch probe crate with path dep on metaobjects-render
Render: html and csv per-format escaping match the shared fixtures; marker characters, partial cycles, set-delimiter tags and maxChars overflow are refused (synthetic inline templates via public rende… ✅ pass live ~/.no-mistakes/evidence/01M7ZH2N214XAEYW3S6HZPXS91/render-escape-and-refusals.txt; scratch probe calling metaobjects_render::render::render
Evidence: eject --force over identical copy: [unchanged] keeps mtime, edited copy [replaced]
# cargo-meta eject --force over an identical copy (live, scratch project)
ejected entity -> codegen/generators/entity.rs [created]
  wrote codegen/Cargo.toml (the engine is crates.io, exactly 0.1.0)
  wrote codegen/main.rs (the generator list)
The copies are yours: edit them freely. `cargo meta gen` and `cargo meta verify` now build and run the codegen/ crate; `cargo meta gen --list` reports how far an owned copy has drifted from the reference.
--- forced over identical copy
ejected entity -> codegen/generators/entity.rs [unchanged]
  kept codegen/Cargo.toml (already yours)
codegen/main.rs already exists and is yours: eject never edits it. In it:
  add `pub mod entity;` inside `mod generators`
  replace `Box::new(metaobjects_codegen::EntityGenerator)` with `Box::new(generators::entity::EntityGenerator)`
The copies are yours: edit them freely. `cargo meta gen` and `cargo meta verify` now build and run the codegen/ crate; `cargo meta gen --list` reports how far an owned copy has drifted from the reference.
exit 0
mtime after forced identical eject: 2001-09-09 01:46:40.000000000 -0400 codegen/generators/entity.rs
--- forced over edited copy
ejected entity -> codegen/generators/entity.rs [replaced]
  kept codegen/Cargo.toml (already yours)
codegen/main.rs already exists and is yours: eject never edits it. In it:
  add `pub mod entity;` inside `mod generators`
  replace `Box::new(metaobjects_codegen::EntityGenerator)` with `Box::new(generators::entity::EntityGenerator)`
The copies are yours: edit them freely. `cargo meta gen` and `cargo meta verify` now build and run the codegen/ crate; `cargo meta gen --list` reports how far an owned copy has drifted from the reference.
exit 0
mtime after edited forced eject: 2026-11-21 14:34:50.765378861 -0500 codegen/generators/entity.rs
Evidence: XML reply depth guard: fixed survives 50k-deep reply, pre-fix aborts with stack overflow
# extract on 2 MiB thread: nested (fixed) vs deep 50k <a> reply, fixed vs pre-fix (1ed7e77230^)
## fixed nested
{"a":{"b":"x"},"c":2}
exit 0
## fixed deep
{}
exit 0
## pre-fix deep

thread '<unknown>' (4086401) has overflowed its stack
fatal runtime error: stack overflow, aborting
/bin/bash: line 7: 4086400 Aborted                 (core dumped) /mnt/scratch/mo-probe-pre-target/debug/mo-probe deep 2>&1
exit 134
Evidence: Render escaping vs fixtures and refusals (marker, cycle, set-delimiter, maxChars)
# render probe (fixed crate): html/csv escaping vs fixtures/render-conformance, and refusals
html-escape: OK "&lt;b class=&quot;warn&quot;&gt;A&amp;B&lt;/b&gt;"
csv-injection: OK "name,value\nAlice,100\n'=cmd(),\"a,b\"\n"
marker-in-template: ERR template contains a reserved character (U+FDD0 or U+FDD1)
marker-in-payload: ERR payload contains a reserved character (U+FDD0 or U+FDD1)
partial-cycle: ERR partial cycle: loop -> loop
set-delimiter: ERR set-delimiter tags ({{=<% %>=}}) are not supported by the Rust renderer
max-chars: ERR render exceeded maxChars budget: 23 > 5
  • Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (1h30m12s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ server/rust/metaobjects-render/src/extract/xml_reader.rs:340 - The XML reader recurses once per nesting level with no depth bound, so a hostile or runaway model reply aborts the whole process. combine calls parse_children, which calls combine. Trace for a reply of &lt;r&gt; followed by about 50k &lt;a&gt;: the first &lt;a&gt; has no close, its content is the rest of the text, the rest contains &lt;, so it recurses, and this repeats once per &lt;a&gt;. The reply parser is documented as never failing (extract "never fails", xml_reader "Never fails"), but a Rust stack overflow is a hard abort that catch_unwind cannot catch. A tokio worker stack is 2 MB, so a few thousand levels is enough. The JSON reader already has the guard (MAX_DEPTH = 100 in json_reader.rs, copied from the Python reference); the XML reader lacks the equivalent. The Python reference's XML reader has no guard either, so this port should not inherit that gap. Siblings that must hold the same invariant: xml_reader.rs parse_children and combine (the recursion pair), and find_stray_close and has_named_open (each rescans the span at every level, which makes the cost quadratic). Fix: thread a depth counter through parse_children and combine; past roughly 100 levels, stop recursing and treat the remaining content as text (the JSON reader's behaviour).

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • 🚨 configured test command failed with exit code 1
  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
eject --force over a copy byte-identical to the shipped generator reports [unchanged] and keeps its mtime (cargo-meta, disposable project) ✅ pass live rust-lane-bundle1-live.txt; touched mtime to 2001-09-09, ran cargo-meta meta eject entity --force, output [unchanged], mtime unchanged on rerun
eject --force over an edited copy replaces it, and a non-force eject refuses to overwrite it (cargo-meta, disposable project) ✅ pass live rust-lane-bundle1-live.txt; --force printed [replaced]; non-force eject over an edited copy exited 1 with 'already owned' message
Prompt render engine: format escaping, csv injection neutralization, whole-float, empty-string section, marker and set-delimiter refusal, maxChars fail-closed (probe crate depending on metaobjects-ren… ✅ pass live rust-lane-bundle1-live.txt render section; csv output matches fixtures/render-conformance/render-csv-injection/expected.txt
Hostile deeply nested XML reply does not overflow the stack: 50,000 nested <a> under a 2 MiB stack returns an outcome (XML reader depth bound, review-1 fix) ✅ pass live rust-lane-bundle1-live.txt xml hostile section; exit=0 under ulimit -s 2048; normal reply still extracts a='hello'
Full Rust regression suite (server/rust) passes with the new crate and the eject change ⏸️ untested no Prior run was cargo test --workspace in server/rust (exit 0). It is a regression test run, not a live product drive, so it does not count as a live pass.
Configured command scripts/ci-local.sh --affected --strict-toolchains ⏸️ untested no Not re-run here: it is the outer configured test lane and the runbook says not to re-run lanes the change does not touch. Its failure on base is not attributable to this change.
  • scripts/ci-local.sh --affected --strict-toolchains
  • cargo test -p metaobjects-render (26 unit + render/extract/output-prompt conformance corpora, 58 and 17 case counts asserted) under CARGO_TARGET_DIR on DEV_SCRATCH
  • cargo test -p metaobjects-cli --test cli eject (4 eject tests incl. the --force [unchanged] mtime test)
  • Live: cargo-meta meta init then cargo-meta meta eject entity in a disposable project, then --force over an identical copy (mtime pinned to 2001-09-09 kept), --force over an edited copy ([replaced]), a second --force over the identical copy ([unchanged]), and a non-force eject over an edited copy (exit 1, refusal message)
  • Live: probe crate depending on the path crate metaobjects-render, rendering eight cases (html escape, csv injection, whole float, empty-string section, payload marker, template marker, set-delimiter, maxChars budget)
  • Live: probe crate running extract() on a 50,000-level &lt;a&gt; XML reply under ulimit -s 2048 and on a normal &lt;r&gt;&lt;a&gt;hello&lt;/a&gt;&lt;/r&gt; reply
  • cargo test --workspace in server/rust (full Rust regression suite, exit 0)

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
eject --force over a copy byte-identical to the shipped generator reports [unchanged] and keeps its mtime; an edited copy is still replaced (live cargo-meta binary, scratch project with synthetic Orde… ✅ pass live ~/.no-mistakes/evidence/01M7ZH2N214XAEYW3S6HZPXS91/eject-force-unchanged.txt; cargo build -p metaobjects-cli then cargo-meta meta eject entity [--force]
Adversarial: a 50k-deep unclosed <a> XML reply does not abort the process; normal nested XML still parses (probe on a 2 MiB thread, fixed vs pre-fix 1ed7e77^) ✅ pass live ~/.no-mistakes/evidence/01M7ZH2N214XAEYW3S6HZPXS91/xml-reply-depth-guard.txt; scratch probe crate with path dep on metaobjects-render
Render: html and csv per-format escaping match the shared fixtures; marker characters, partial cycles, set-delimiter tags and maxChars overflow are refused (synthetic inline templates via public rende… ✅ pass live ~/.no-mistakes/evidence/01M7ZH2N214XAEYW3S6HZPXS91/render-escape-and-refusals.txt; scratch probe calling metaobjects_render::render::render
  • scripts/ci-local.sh --affected --strict-toolchains
  • Baseline (not re-run): scripts/ci-local.sh --affected --strict-toolchains passed at target commit 9cf3be260c.
  • cargo test -p metaobjects-render in server/rust (scratch target dir): 26 unit tests incl. deep_nesting_returns_without_overflow, plus extract_conformance (58 cases), output_prompt_conformance (17 cases), render_conformance corpora; all pass.
  • cargo build -p metaobjects-cli then live cargo-meta meta eject entity / --force on a scratch project: first eject [created]; forced over identical copy [unchanged] with mtime preserved (2001 stamp kept); forced over edited copy [replaced].
  • Probe crate (scratch, path dep on the worktree metaobjects-render) run on a 2 MiB thread: XML nested reply &lt;r&gt;&lt;a&gt;&lt;b&gt;x&lt;/b&gt;&lt;/a&gt;&lt;c&gt;2&lt;/c&gt;&lt;/r&gt; -> {"a":{"b":"x"},"c":2}; 50k-deep &lt;a&gt; reply returns exit 0 with fixed crate.
  • Same probe built against git archive of 1ed7e77230^ (pre-fix xml_reader): deep reply aborts with thread ... has overflowed its stack, exit 134; nested reply still parses.
  • Probe render calls (InMemoryProvider, RenderRequest): html escape of &lt;b class=&#34;warn&#34;&gt;A&amp;B&lt;/b&gt; matches fixtures/render-conformance/render-raw-html-bypass expected; csv injection output matches render-csv-injection expected; marker U+FDD0 in template and in payload refused; self-including partial refused as cycle; set-delimiter tag refused; maxChars=5 refused fail-closed.
  • Evidence written to ~/.no-mistakes/evidence/01M7ZH2N214XAEYW3S6HZPXS91/: eject-force-unchanged.txt, xml-reply-depth-guard.txt, render-escape-and-refusals.txt. Scratch dirs created by this turn removed; no background processes left.
⚠️ **Document** - 1 info
  • ℹ️ Stale 'five ports' wording predates this change but is now wrong with Rust as a sixth port: fixtures/registry-conformance/README.md (lines ~130, 278, 321, 489, 538), docs/features/templates-and-payloads.md (lines ~489, ~718) and others. Out of scope here: a follow-up sweep should decide the port-count wording once and point to docs/CONFORMANCE.md rather than repeat it.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…rser and output-format fragment

The Rust port's prompt pillar, as a fourth publishable crate:

- render: a template.* body rendered over a JSON payload on mustache-ng, with
  partials expanded ahead of time, per-format escaping, derived has<Field> and
  -last accessors and a fail-closed maxChars budget. Passes render-conformance
  byte-identically.
- extract: the FR-010/011 tolerant reply parser (strip, locate, forgiving JSON
  and XML readers, coercion, classification). Passes all 58 extract-conformance
  cases.
- prompt: the output-format fragment in guide, inline and exampleOnly styles.
  Passes all 17 output-prompt-conformance cases, with the extract round trip.

Rust joins the extract FieldKind parity gate. The port and conformance docs say
what runs, and what prompt codegen is still to come.
A forced eject over a copy that already matches the shipped generator byte for
byte no longer rewrites it: it reports [unchanged] and the file keeps its bytes
and modified time, as every other write path in the port does. A copy that
differs is still replaced.
@dmealing
dmealing merged commit d4f94bc into main Nov 21, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-130-lane-rust-2 branch November 21, 2026 19:50
dmealing added a commit that referenced this pull request Nov 25, 2026
The rebase onto main brought in the metaobjects-render crate (#630), whose
corpus runner read expected.txt for every render case. This branch adds two
render-conformance cases that expect a missing-variable error instead, so the
Rust renderer now refuses an interpolated name the payload lacks, with the
same message and the same rules as the reference (sections over an absent
name stay legal, null is present, only rendered bodies are checked), and the
runner learns the expected-error.txt convention.
dmealing added a commit that referenced this pull request Nov 25, 2026
…#632)

* feat: move reporting and requirements into their own provider packs; raise on missing template variables; refuse permission-name collisions

- Reporting (object.report, dimension.*, measure.* incl. measure.derived/@expr,
  segment.filter, the entity's dimension/measure/segment children and @segment on
  origin.aggregate/origin.first) is registered by metaobjects-reporting; requirements
  (requirement.* and the root's requirement child) by metaobjects-requirements. Both
  are in the default bundle of every port (TS, C#, Java/Kotlin, Python, Rust), so
  existing models load and generate identically. A model that uses a left-out pack's
  vocabulary gets a loader error (new error-packs-left-out-*-used fixtures). The
  verify requirements gate reads through the pack.
- A pack subtype declared with extendsBase may fold a base another provider
  registered (object.report folds object.base); folded attributes keep the base's
  owner under ADR-0062.
- Core vocabulary pin, registry manifest (root requirement child gains min 0 /
  max null), metamodel docs, site reference and payload regenerated.
- GOVERNANCE.md: an attribute promoted from a pack into core keeps its name and
  meaning.
- B4: Mustache and Jinja raise ERR_VAR_NOT_ON_PAYLOAD for a variable or dotted path
  absent from the payload, in every port that renders; render runners learn
  expected-error.txt.
- B5: rules rule P3 refuses two permission points whose names resolve equal when at
  least one name is derived (ERR_TRANSITION_NAME_COLLISION), in every port.
- C3: Python checks @union shape and @Grain views at load; both must-fail fixtures
  leave its expected-failures ledger.

* fix(rules): compare P3 permission names exactly, so '::' and '.' are not one name

The P3 collision check rewrote '::' to '.' before comparing, so a derived
p::Order.open counted as a collision with the transition's p.Order.open. They
are different names in the metadata and the policy receives them as written.
Removed the rewrite in TS, C#, Java, Python and Rust. The former
error-rules-permission-name-op-package fixture becomes
rules-permission-name-package-separator-distinct, which every port's
conformance runner now loads clean.

* docs(changelog): drop a leftover rebase marker

* no-mistakes(review): apply reviewer inline fixes

* no-mistakes(test): Wrap two rustfmt-flagged lines in Rust registry and rules

* no-mistakes(document): sync docs with packs, render errors, P3

* no-mistakes(document): point pack docs at vocabulary owner

* feat: move reporting and requirements into their own provider packs; raise on missing template variables; refuse permission-name collisions

- Reporting (object.report, dimension.*, measure.* incl. measure.derived/@expr,
  segment.filter, the entity's dimension/measure/segment children and @segment on
  origin.aggregate/origin.first) is registered by metaobjects-reporting; requirements
  (requirement.* and the root's requirement child) by metaobjects-requirements. Both
  are in the default bundle of every port (TS, C#, Java/Kotlin, Python, Rust), so
  existing models load and generate identically. A model that uses a left-out pack's
  vocabulary gets a loader error (new error-packs-left-out-*-used fixtures). The
  verify requirements gate reads through the pack.
- A pack subtype declared with extendsBase may fold a base another provider
  registered (object.report folds object.base); folded attributes keep the base's
  owner under ADR-0062.
- Core vocabulary pin, registry manifest (root requirement child gains min 0 /
  max null), metamodel docs, site reference and payload regenerated.
- GOVERNANCE.md: an attribute promoted from a pack into core keeps its name and
  meaning.
- B4: Mustache and Jinja raise ERR_VAR_NOT_ON_PAYLOAD for a variable or dotted path
  absent from the payload, in every port that renders; render runners learn
  expected-error.txt.
- B5: rules rule P3 refuses two permission points whose names resolve equal when at
  least one name is derived (ERR_TRANSITION_NAME_COLLISION), in every port.
- C3: Python checks @union shape and @Grain views at load; both must-fail fixtures
  leave its expected-failures ledger.

* fix(rules): compare P3 permission names exactly, so '::' and '.' are not one name

The P3 collision check rewrote '::' to '.' before comparing, so a derived
p::Order.open counted as a collision with the transition's p.Order.open. They
are different names in the metadata and the policy receives them as written.
Removed the rewrite in TS, C#, Java, Python and Rust. The former
error-rules-permission-name-op-package fixture becomes
rules-permission-name-package-separator-distinct, which every port's
conformance runner now loads clean.

* no-mistakes(review): apply reviewer inline fixes

* no-mistakes(test): Wrap two rustfmt-flagged lines in Rust registry and rules

* no-mistakes(document): sync docs with packs, render errors, P3

* no-mistakes(document): point pack docs at vocabulary owner

* feat(rust): raise ERR_VAR_NOT_ON_PAYLOAD in the Rust renderer

The rebase onto main brought in the metaobjects-render crate (#630), whose
corpus runner read expected.txt for every render case. This branch adds two
render-conformance cases that expect a missing-variable error instead, so the
Rust renderer now refuses an interpolated name the payload lacks, with the
same message and the same rules as the reference (sections over an absent
name stay legal, null is present, only rendered bodies are checked), and the
runner learns the expected-error.txt convention.

* docs(conformance): recount render and Jinja cases after rebasing onto #634

Main's #634 added render-conformance cases and two corpora while this branch
added two render error cases and a Jinja error case; the counts and the
showcase payload are recomputed from the fixtures on disk.

* fix(render): check missing variables with the reference's whole-path lookup in every port

The B4 missing-variable check follows TypeScript on mustache.js: a dotted
name is tried whole against each context from the innermost outward, and a
list's length is a property. Python and C# now resolve that way; the Java
check pass falls back to a whole-path lookup before raising; the Rust check
pass counts a list's length as present. So no port raises
ERR_VAR_NOT_ON_PAYLOAD on a name TypeScript renders. What the C#, Java and
Rust engines then print for those names is a separate parity question.

* fix(render): treat 0 as falsy in Python sections and the C# check pass, as mustache.js does

An empty list's length now resolves, so {{#items.length}} on an empty list
rendered its body in Python. mustache.js tests sections with JavaScript
falsiness, where 0 and NaN are falsy; Python's section test and the C#
check pass now do the same. Adds a Python test pinning the shadowed-prefix,
length, zero and null-mid-path cases against the TypeScript output.

Also tidies the Java whole-path fallback (imports, a named length constant,
loop-invariant work hoisted) and the C# lookup (using, a redundant assignment).

* no-mistakes(review): Pin render parity with shared fixtures

* no-mistakes(review): apply reviewer inline fixes

* no-mistakes(test): apply changes made during test validation

* no-mistakes(review): apply reviewer inline fixes

* no-mistakes(review): Exempt only folded base attrs from Rust ownership check

* no-mistakes(document): Docs: Rust ledger, render parity, pack counts
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