Skip to content

Drop empty paragraphs from canonical document projection - #212

Open
lavaman131 wants to merge 1 commit into
mainfrom
fix-trailing-empty-paragraph-description
Open

lavaman131 wants to merge 1 commit into
mainfrom
fix-trailing-empty-paragraph-description

Conversation

@lavaman131

Copy link
Copy Markdown
Collaborator

Closes #211

Problem

An empty Lexical paragraph was exported as an MDAST paragraph with no children. serialize writes that as an extra blank line, and parse discards it. Pressing Enter at the end of a document, or inserting a /research card, was enough to make the room persist source that fails its own round trip. The document-summary job then failed with "Document source is not canonical." under every harness.

Change

  • packages/dialect/src/convert.ts: $exportPlanTree drops empty paragraphs at every depth, so projection is canonical. Block addressing already ignored them: addressable() skips root-level empty paragraphs and digests() goes through parse. The Lexical tree and browser editing are unchanged; only the server projection differs. Table cells and a container left with only an empty paragraph export exactly as before.
  • apps/server/src/plan/room.ts: existing checkpoints still store the old blank lines, and restore() required the stored source to match the projection exactly. Without a change, those channels would fail to open with "stored plan source does not match its Yjs checkpoint". restore() now also accepts a stored source whose canonical form, serialize(parse(source)), matches the projection. An unrelated source is still rejected. The next checkpoint rewrites the source in canonical form.

Existing documents keep failing description jobs until their next edit re-projects them.

Verification

New regression tests cover export at the root, after a Research card, between blocks and inside a blockquote, plus restoring a legacy checkpoint. Both failed before the fix.

Live check with agent-browser against an AGENT=off server: I typed text and pressed Enter twice, then read the stored snapshot.

Checkout Stored source serialize(parse(s)) === s
main "The harp needs new strings.\n\n\n\n" false
this branch "The harp needs new strings.\n" true

A document written by main opened on this branch without errors, accepted an edit, and was saved in canonical form ("…strings.\n\nOrder a full set.\n"):

A main-written document edited on this branch

The first run of bun run e2e failed one test, responsive-decisions.e2e.ts "long independent decisions…", on a strict-mode locator. That failure also happens on main: cold-start runs of that test failed 2 of 3 times on main and 3 of 3 on this branch, so it is an existing flake. The rerun of the full suite passed.

Assistant-verification: bun test unit passed: 1659 pass, 2 skip, 0 fail; new convert and room regression tests failed before the fix
Assistant-verification: bun run test:postgres passed: 59 PostgreSQL contract tests
Assistant-verification: bun run types passed: all workspaces and E2E
Assistant-verification: bun run ci passed: dprint, oxlint, tokens, type scale, Impeccable
Assistant-verification: bun run e2e passed: 236 Chromium tests on rerun; the one earlier failure is an existing cold-start flake that also fails on main
Assistant-verification: agent-browser E2E passed: text plus two Enters stores canonical source on this branch versus non-canonical on main; a main-written document opens, edits, and re-persists canonically
Assistant-model: Claude Opus 5.5
Assistant-workflow: inline
Assistant-duration: 16m converged, estimated none given
Co-authored-by: Alex Lavaee lavaman131@github.com

@lavaman131 lavaman131 self-assigned this Sep 28, 2026
@coolify-githubnext-app

coolify-githubnext-app Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

The preview deployment for chopin is ready. 🟢

Open app | Open Build Logs | Open Application Logs

Last updated at: 2026-10-01 15:11:26 CET

@lavaman131
lavaman131 force-pushed the fix-trailing-empty-paragraph-description branch from d0e053e to 908f1b7 Compare September 28, 2026 22:42
MaggieAppleton added a commit that referenced this pull request Sep 30, 2026
An empty Lexical paragraph exported as an empty MDAST paragraph, which
serializes as an extra blank line that parsing discards. Rooms persisted
that non-canonical source, and document-summary jobs then failed with
"Document source is not canonical." Projection now drops empty paragraphs
at every depth, matching the blocks that addressable() and digests()
already count.

Checkpoints written before this change still store the former blank
lines, so restore accepts a stored source whose canonical form matches
the projection.

Closes #211

Assistant-model: Claude Opus 5.5
Assistant-workflow: inline
Assistant-duration: 15m converged, estimated none given
Assistant-verification: bun test unit passed: 1659 pass, 2 skip, 0 fail; new convert and room regression tests failed before the fix
Assistant-verification: bun run test:postgres passed: 59 pass
Assistant-verification: bun run types passed: all workspaces and E2E
Assistant-verification: bun run ci passed: dprint, oxlint, tokens, type scale, Impeccable
Assistant-verification: bun run e2e passed: 236 Chromium tests
Assistant-verification: agent-browser E2E passed: typing text and two Enters stores canonical "…strings.\n" on this branch versus non-canonical "…strings.\n\n\n\n" on main; a document written by main opens, edits, and re-persists canonically on this branch
Co-authored-by: Alex Lavaee <lavaman131@github.com>
@lavaman131
lavaman131 force-pushed the fix-trailing-empty-paragraph-description branch from 8c74c16 to e1fc8c3 Compare October 1, 2026 15:07
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.

Empty paragraphs make room projection non-canonical, failing document descriptions

2 participants