Skip to content

feat(memory): Markdown documents with revisions and sections (format 10) - #124

Merged
venkat1701 merged 3 commits into
mainfrom
feature/memory-documents
Nov 25, 2026
Merged

venkat1701 merged 3 commits into
mainfrom
feature/memory-documents

Conversation

@venkat1701

@venkat1701 venkat1701 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

First part of the memory work. Any node can hold Markdown revisions, and each revision is split into sections that hyperedges can point at.

What it does

  • REVISE stores an immutable revision.
    • Revisions are numbered per node.
    • Each one has a valid time (when the content applies) and a recorded time (when the database learned it). It can name up to 16 sources, either evidence records or atoms.
    • The Markdown goes to the payload store, so revisions outlive the 64-generation history window.
  • Revisions are split into sections at their headings.
    • Both heading styles count: # and underlined. Fenced code, indented code and front matter are skipped.
    • Each section gets a stable anchor such as claimsbay/decisions and byte offsets into the revision.
  • Revisions and sections are atoms of two system types, $Revision and $Section.
    • A hyperedge can link a person, a decision and the section that records it.
    • They are visible exactly when their node is, so tenant and type grants carry over without anything new.
  • REVISION OF … VALID AT t RECORDED AT t2 answers "what did the document say about time t, as far as we knew at t2".
  • PURGE removes the node with its revisions and sections, and deletes hyperedges left with no members. It also zeroes the Markdown and the node's large values in the payload files.
    • The erasure is journaled in the purge commit and finished after it, or on the next open.
    • Purge runs only on main.
  • DELETE refuses a node that has revisions. Revisions and sections cannot be changed.
  • MERGE BRANCH copies revisions made on a branch. If both sides revised the same node, the merge is refused under every policy.

Storage format goes to 10 (slots 57-59 and 67). Format 9 directories are refused with the usual message.

Syntax

revise        = "REVISE" ref "MARKDOWN" string { revise_option } [ "AS" variable ] ;
revise_option = "VALID" "FROM" instant | "VALID" "TO" instant
              | "SOURCES" "(" ref { "," ref } ")" | "NOTE" string ;
revisions     = "REVISIONS" "OF" ref ;
revision_of   = "REVISION" "OF" ref [ "NUMBER" integer | [ "VALID" "AT" instant ] [ "RECORDED" "AT" instant ] ]
                [ "AS" variable ] ;
sections_of   = "SECTIONS" "OF" ref ;
section       = "SECTION" ref ;
purge         = "PURGE" ref ;

The names are open to change before merge.

Testing

  • Full build passes: engine 269, database 314, server 41.
  • MarkdownTest checks 400 random documents against a separate reference splitter, plus edge cases: setext headings, fences, front matter, CRLF, UTF-8 offsets and duplicate anchors.
  • DocumentTest covers:
    • revision chains;
    • sections as hyperedge members;
    • valid/recorded time against a scan over 40 random revisions;
    • 90 revisions read back after a restart;
    • immutability;
    • purge, with the payload files checked byte for byte;
    • a purge journal left behind by a crash, finished on open.
  • DocumentStatementTest covers the HQL, merging from a branch, and refused two-sided merges.
  • SecurityTest#documentsStayInsideTheTenant and PermissionsTest#revisionsAndSectionsFollowTheirDocumentsType cover tenants, grants and quotas.
  • Mutations: 8 of 8 deliberately broken rules were caught by a test.
  • Live over the wire, two tenants, 105 revisions:
    • sections agree with a Python splitter on every document;
    • 128 of 128 time-resolution probes agree with a scan;
    • after PURGE, the Markdown markers are gone from the payload files on disk;
    • 15 of 15 cross-tenant probes are refused;
    • everything is the same after SIGKILL, with 249 commits replayed;
    • a deliberately wrong reference fails.

Merge order for the memory stack: #128 (CI fix), #124, #125, #126, #127, #129 (online text index rebuild), #130 (starter kit). Retarget each to main once the one below it merges. A private preview image built from #129 merged with #128 is at ghcr.io/metacoglabs/hstore-memory:0.2.0-dec80f2.

…mat 10)

Any node can now hold Markdown revisions. Each revision is immutable,
numbered per node, and carries valid time, recorded time, an author, a
note and up to 16 sources. It is split into sections at its headings,
with stable anchors and byte offsets. Revisions and sections are atoms
of the system types $Revision and $Section, so hyperedges can point at
the exact text a fact came from. They are visible exactly when their
node is.

PURGE removes a node with its revisions and sections, drops hyperedges
left empty, and zeroes the Markdown and large values in the payload
files. The erasure goes through a journal that is finished after the
commit or on the next open. MERGE BRANCH carries revisions across and
refuses when both sides revised the same node.

New statements: REVISE, REVISIONS OF, REVISION OF, SECTIONS OF,
SECTION, PURGE. The storage format moves to 10 for slots 57 to 59 and 67.
- Check a revision fully before writing its Markdown: valid Unicode,
  section limit, valid interval, and whether every record fits a stored
  value at the database's page size. Markdown written by a transaction
  that rolls back, fails or retries is erased and its quota refunded.
- A first revision racing a delete of its node now conflicts, so
  revisions can no longer outlive their node.
- PURGE checks WRITE on every hyperedge type that holds the node, a
  revision or a section, removes edges left empty on revisions and the
  node too, and erases payloads of the node from every generation still
  in the history window.
- With ASYNC durability, erasures wait for a checkpoint that made the
  purge durable. Erase failures are logged and retried; they no longer
  surface from a committed purge.
- Heading titles are truncated in linear time, and anchors are capped
  at 160 bytes.
- Section extraction no longer treats list items, quotes, HTML
  comments, fences inside list items or tab-indented lines as headings,
  and reads front matter after a byte order mark.
- MATCH NODE and other whole-graph listings skip revisions and sections.
@venkat1701

Copy link
Copy Markdown
Collaborator Author

Pushed fa6ee4b with fixes from a review pass:

  • A revision is now checked in full before its Markdown is written: valid Unicode, section count, valid interval, and whether each record fits a stored value at the page size. Markdown from a transaction that rolls back, fails or retries is erased, and its quota is refunded.
  • A first revision racing a delete of its node now conflicts, so orphaned revisions can't happen.
  • PURGE:
    • It needs WRITE on every hyperedge type holding the node, a revision or a section.
    • It drops edges left empty on revisions and on the node.
    • It also erases the node's payloads from generations still in the history window.
  • With ASYNC durability, erasure waits for a checkpoint.
  • Title truncation is linear. Anchors are capped at 160 bytes, which fixes records that overflowed 1 KiB pages.
  • Section extraction no longer turns list items, quotes, HTML comments, fences inside list items or tab-indented lines into headings, and it handles front matter after a BOM.
  • MATCH NODE and other whole-graph listings skip revisions and sections.

Full build: engine 269, database 323, server 41. The live run is green again on this commit, before and after SIGKILL.

The payload files never shrink, so refunding the quota of a rolled-back
revision would let a writer fill the disk by writing and rolling back.
Abandoned Markdown is still zeroed, but its bytes keep counting, as every
other rolled-back payload already does.
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