GeezerVison is showing github.com — id(web): prosemirror_to_markdown panics on misplaced nodes — json_to_ast never validates block/inline placement · Issue #1043 · developing-today/code
id(web): prosemirror_to_markdown panics on misplaced nodes — json_to_ast never validates block/inline placement #1043DescriptionBug
prosemirror_to_markdown (pkgs/id/src/web/markdown.rs:908) does not validate the placement of nodes in the incoming ProseMirror document. json_to_ast (markdown.rs:963) recursively appends children without checking that inline nodes only appear in inline contexts and block nodes only in block contexts, so a structurally misplaced node produces an ill-formed comrak AST:
- In debug builds, comrak's
format_commonmark validation panics: The document to format is ill-formed: InvalidChildType { parent: Document, child: Text("orphan") } (comrak 0.56 cm.rs:29).
- In release builds the validation is compiled out (
#[cfg(debug_assertions)]), so the same input silently emits invalid markdown instead of returning an error.
The function's contract is Result<String, ConversionError> — an unknown node type already returns ConversionError::UnknownType (markdown.rs:1186). A known node in an impossible position should be an error (or a documented coercion), never a panic / silent corruption. The save path is convert_doc_to_bytes in pkgs/id/src/web/routes.rs:1986, so a malformed stored/imported/collab document hits this on save or export.
Evidence (verified 2026-10-26 on main cf60812)
Standalone probe crate carrying a verbatim copy of src/web/markdown.rs (comrak 0.56.0 locked) — logs in goal hidden_files probe-2026-10-26-2145/out3.log + out4.log. Each of these prosemirror_to_markdown inputs panics at comrak cm.rs:29:
- doc with a top-level
text node: {"type":"doc","content":[{"type":"text","text":"orphan"}]} → InvalidChildType { parent: Document, child: Text("orphan") }
- doc with a top-level
image node (inline node at block level)
- doc with a top-level
hard_break node
- a
paragraph whose content contains a paragraph
Controls that behave correctly today: unknown node type → Err(UnknownType("mention")); heading level 9 → clamped to 6; empty doc → Ok("").
Related precedent: #1017 (table-cell special case built an ill-formed AST that panicked in the same comrak validation) — fixed by making the conversion produce a well-formed AST. This issue is the general case: no placement validation anywhere in json_to_ast.
Why it matters
Stored ProseMirror documents are not exclusively editor-produced: they arrive via import, the collab layer, older clients, and direct API writes. Any of those can carry a misplaced node; today that means a panicked handler in debug builds and silently invalid .md output in release builds, on a function whose signature promises a ConversionError.
Acceptance criteria
prosemirror_to_markdown never panics and never emits an ill-formed AST for the four shapes above; each returns Err(ConversionError::…) (new variant if needed) or a documented, tested coercion (e.g. wrapping stray inline nodes in a paragraph).
- Regression tests in
web::markdown covering: inline node at doc level (text/image/hard_break), block node inside a paragraph, and at least one misplaced-node case inside a list item / blockquote / table cell.
- Existing
web::markdown tests still pass; well-formed documents render byte-identically to before.
Activitydeveloping-today commented on Oct 27, 2026 added kind/bugSomething isn't working (prefixed form of the classic bug label) task/triageQueue packet kind: verify, reproduce, and route this item app/idPackage/app: id (pkgs/ or apps/ in this repo) on Oct 27, 2026dezren39 commented on Oct 27, 2026 🤖 Agent note · filed
- Agent: new-issue-creator job
- Session / ID: new-issue-creator cron run 2026-10-26 21:45 CDT
- Found via: filed this run
- Task: Verified with a standalone probe crate carrying a verbatim copy of src/web/markdown.rs (comrak 0.56.0) on main cf60812 (logs hidden_files/probe-2026-10-26-2145/out3.log + out4.log): prosemirror_to_markdown panics at comrak cm.rs:29 (ill-formed AST, InvalidChildType) for a doc with a top-level text/image/hard_break node and for a paragraph containing a paragraph; json_to_ast (markdown.rs:963) does no block/inline placement validation, while unknown node types already return ConversionError::UnknownType (:1186). Release builds skip comrak's debug-only validation and silently emit invalid markdown. Enqueued as a triage packet to repo-health-code-pilot — error-vs-coerce is a design choice for triage (cf. id(web): saving a table cell with a hard break or a list panics in the markdown codec — ill-formed comrak AST #1017, the table-cell special case of the same class).
- Expectation: triage decides error vs coercion; done when the four shapes return a ConversionError (or documented coercion) with regression tests and no panic.
- Links: probe evidence in goal hidden_files (see issue body)
dezren39 commented on Oct 27, 2026 Parked — PR #1089 opened @ f6594ee (placement validation + MisplacedNode; rustfmt fix included after the first CI run flagged formatting). Probe suite 71/71, all five panic shapes now return Err.
{"v":1,"kind":"note","state":"parked","task_id":1232,"summary":"PR 1089: validate_placement walk + ConversionError::MisplacedNode; verified in verbatim-codec probe (71/71, five shapes Err, controls unchanged). Parked 20m on CI per the 5-minute rule.","artifacts":["https://github.com/developing-today/code/pull/1089"],"next":"merge PR 1089 when CI green, then complete task 1232"}
dezren39 commented on Oct 27, 2026 Done — queue worker (Lane A), task 1232: PR #1089 merged (merge commit a2e7bfc), issue auto-closed. CI on f6594ee: every functional check green (test-unit, all shards, cargo-check, fmt, treefmt, web suites); the only failures were clippy-lint and its aggregate, both Magic Nix Cache HTTP 418 / GitHub Actions Cache rate-limit infra (no clippy findings in the log) — merged under the standing rule for verified changes with unrelated infra failures, with the local probe suite at 71/71 from the previous shift.
{"v":1,"kind":"note","state":"done","task_id":1232,"summary":"PR 1089 merged a2e7bfc9; #1043 auto-closed. CI green except clippy/aggregate failing on Magic Nix Cache 418 infra (no lint findings). Probe suite 71/71 (prior shift).","artifacts":["https://github.com/developing-today/code/pull/1089"],"next":"none — task 1232 complete"}
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|