Repository navigation
feat(rust): add metaobjects-render prompt render and reply parser - #630
Merged
Merged
Conversation
…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
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
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.
What Changed
server/rust/metaobjects-rendercrate (not published to any registry). It renderstemplate.*bodies withmustache-ngunderneath, escaping each value for its format, expanding partials ahead of time, and derivinghas<Field>and-lastaccessors. 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 --forcecompares 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.scripts/check-extract-field-kinds.mjsandexpected-field-kinds.json. Updatesdocs/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.cargo-meta meta eject entity [--force]Evidence: eject --force over identical copy: [unchanged] keeps mtime, edited copy [replaced]
Evidence: XML reply depth guard: fixed survives 50k-deep reply, pre-fix aborts with stack overflow
Evidence: Render escaping vs fixtures and refusals (marker, cycle, set-delimiter, maxChars)
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.combinecallsparse_children, which callscombine. Trace for a reply of<r>followed by about 50k<a>: the first<a>has no close, its content is the rest of the text, the rest contains<, so it recurses, and this repeats once per<a>. The reply parser is documented as never failing (extract"never fails",xml_reader"Never fails"), but a Rust stack overflow is a hard abort thatcatch_unwindcannot 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 injson_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.rsparse_childrenandcombine(the recursion pair), andfind_stray_closeandhas_named_open(each rescans the span at every level, which makes the cost quadratic). Fix: thread a depth counter throughparse_childrenandcombine; 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 ✅
cargo-meta meta eject entity --force, output[unchanged], mtime unchanged on rerun--forceprinted[replaced]; non-force eject over an edited copy exited 1 with 'already owned' messagecargo test --workspacein server/rust (exit 0). It is a regression test run, not a live product drive, so it does not count as a live pass.scripts/ci-local.sh --affected --strict-toolchainsscripts/ci-local.sh --affected --strict-toolchainscargo test -p metaobjects-render(26 unit + render/extract/output-prompt conformance corpora, 58 and 17 case counts asserted) under CARGO_TARGET_DIR on DEV_SCRATCHcargo test -p metaobjects-cli --test cli eject(4 eject tests incl. the --force [unchanged] mtime test)Live:cargo-meta meta initthencargo-meta meta eject entityin a disposable project, then--forceover an identical copy (mtime pinned to 2001-09-09 kept),--forceover an edited copy ([replaced]), a second--forceover 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<a>XML reply underulimit -s 2048and on a normal<r><a>hello</a></r>replycargo test --workspacein server/rust (full Rust regression suite, exit 0)🔧 Fix applied.
✅ Re-checked - no issues remain.
cargo-meta meta eject entity [--force]scripts/ci-local.sh --affected --strict-toolchainsBaseline (not re-run):scripts/ci-local.sh --affected --strict-toolchainspassed at target commit 9cf3be260c.cargo test -p metaobjects-renderin 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-clithen livecargo-meta meta eject entity/--forceon 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<r><a><b>x</b></a><c>2</c></r>-> {"a":{"b":"x"},"c":2}; 50k-deep<a>reply returns exit 0 with fixed crate.Same probe built against git archive of 1ed7e77230^ (pre-fix xml_reader): deep reply aborts withthread ... has overflowed its stack, exit 134; nested reply still parses.Probe render calls (InMemoryProvider, RenderRequest): html escape of<b class="warn">A&B</b>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.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.