Repository navigation
fix(memory): read and write front matter as data, never as code - #265
Conversation
|
Warning Review limit reached
This review includes 13 billable files and costs up to $3.25.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 1 minute for your next included review. View limit details
Comment |
Reviewer's GuideThe PR removes gray-matter's code-execution and body-reparsing hazards by funneling all front-matter access through a data-only utility, migrates every affected memory/document path to it, adds regression coverage and an import lint guard, and updates isolated-loader documentation to accurately describe its resource-limit and worker semantics. Sequence diagram for isolated document loading limitssequenceDiagram
participant Caller
participant Loader as loadIsolated
participant Worker as Isolated worker
participant DocumentLoader as Markdown/PDF/DOCX/Text loader
Caller->>Loader: loadIsolated(kind, bytes, options)
Loader->>Loader: copy bytes
Loader->>Worker: start with resourceLimits and empty execArgv
Worker->>DocumentLoader: read document
DocumentLoader-->>Worker: content, metadata, format
loop caller event loop timer
Loader->>Worker: getHeapStatistics()
Loader-->>Worker: end if timeout or sampled external memory exceeds bound
end
Worker-->>Loader: answer or worker error
Loader-->>Caller: copied result or rejection
Flow diagram for front matter parsing behaviorflowchart TD
Start[Read document text] --> Delimiter{Front matter delimiter?}
Delimiter -->|YAML or JSON| Parse[Parse as data]
Delimiter -->|JavaScript| Drop[Remove block without evaluating]
Delimiter -->|None| Body[Keep full text as body]
Parse --> Result[Return data and remaining body]
Drop --> Result
Body --> Result
Write[Write front matter] --> Unparsed[Pass body as content without reparsing]
Unparsed --> Serialized[Return YAML block plus unchanged body]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
PR Summary by QodoRead and write front matter without evaluating JavaScript
AI Description
Diagram
High-Level Assessment
Files changed (13)
|
Code Review by Qodo
1. Trace file safety lacks integration tests
|
## [0.13.36](v0.13.35...v0.13.36) (2026-10-10) ### fix * **memory:** read and write front matter as data, never as code (#265) ([af3801b](af3801b))
Summary
Front matter is read and written as data. gray-matter reads a front-matter block in the language named after its opening line of dashes, and its own engine for
jsandjavascriptevaluates the block. Given a string to write front matter onto, it parses that string first. The library handed it Markdown files, persona files, wiki pages, and the bodies of memory traces and wiki pages, with those engines in place.src/core/utils/frontMatter.tsis now the one module that calls gray-matter.readFrontMatterparses a YAML or JSON block into data. A block marked as JavaScript is not evaluated: it is taken off the content like any front matter and gives no data.writeFrontMatterwrites a YAML block in front of a body it never reads, so a body that opens with a line of dashes is kept whole. Before, its first lines were read as a block of its own and lost from the content.MarkdownLoader,MarkdownImporter,MarkdownExporter,ObsidianExporter,SoulLoader(loadSoul,loadSoulSync,parseSoul,renderSoulMarkdown) and the wiki'sparsePageandserializePagego through it. A lint rule refuses an import of gray-matter anywhere else undersrc.loadIsolated's TSDoc say what the isolated read leaves. A--max-old-space-sizethe process was started with overridesmaxHeapMbwhether it came from the command line or fromNODE_OPTIONS: V8's options are the whole process's, whatever the worker'sexecArgv(the page said the worker starts with none of the caller's command-line options). The check behindmaxExternalMbsamples on a timer on the caller's event loop and does not cap. The answer is copied into the caller's heap. The page also says how a read ends when the worker fails in another way, that the package ships ES modules only, and that the worker is a thread of the caller's process and not a sandbox for code.Linked issues
None.
Type of change
How this was verified
CI on this branch: Test & Lint (build, lint with the new rule, type check and the whole suite), Batch-1 gated tests and the release dry run. New tests:
src/core/utils/__tests__/frontMatter.test.ts: YAML and JSON blocks read into data; a block markedjs,javascript,JSorjsgives no data and is not evaluated; a body that opens with a line of dashes, or with a block marked as JavaScript, is written whole, read back whole and not evaluated. Each case that must not evaluate also hands the same text to gray-matter with its own engines, which does evaluate it, so the case fails without this change.loaders.test.ts:MarkdownLoaderon a buffer whose front matter is marked as JavaScript.WikiPageCodec.test.ts: a page whose body opens with such a block, throughserializePageandparsePage.Migration notes
None for YAML or JSON front matter. A block marked as JavaScript now gives no data, so write such front matter as YAML or JSON.
Checklist
!before the colon for a change that breaks users (feat!:orfeat(api)!:).Summary by Sourcery
Read and write front matter strictly as data while preserving document bodies and documenting isolated-loader behavior accurately.
Bug Fixes:
Enhancements:
Documentation:
Tests: