Skip to content

fix(context): prevent OOM crash on large llms-full.txt files#99

Open
wbisschoff13 wants to merge 1 commit into
neuledge:mainfrom
wbisschoff13:fix/oom-large-llms-txt
Open

fix(context): prevent OOM crash on large llms-full.txt files#99
wbisschoff13 wants to merge 1 commit into
neuledge:mainfrom
wbisschoff13:fix/oom-large-llms-txt

Conversation

@wbisschoff13

Copy link
Copy Markdown
Contributor

Large markdown files (>1MB) like Cloudflare's llms-full.txt previously caused Node.js heap OOM because remark-parse built a full AST of the entire document.

Now they are pre-split by ## headings before AST parsing, so each chunk stays small and is independently parseable.

Changes

  • packages/context/src/package-builder.ts: Added splitMarkdownByHeadings() function and pre-processing in buildPackage() that splits large .md/.mdx/.txt files by ## headings
  • packages/context/src/package-builder.test.ts: Added 7 tests covering splitting behavior

Verification

  • All 172 tests pass
  • TypeScript compiles cleanly

…s-full.txt files

Large markdown files (>1MB) like Cloudflare's llms-full.txt previously
caused Node.js heap OOM because remark-parse built a full AST of the
entire document. Now they are pre-split by ## headings so each chunk is
independently parseable with minimal memory.

Fixes: neuledge#99
@changeset-bot

changeset-bot Bot commented Jun 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 84864dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@neuledge/context Patch
@neuledge/registry Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@moshest moshest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix. This solves a real crash and the tests are easy to follow.

A few things before merge:

  • CI is red, but it's only a formatting nitpick in the test file. Run pnpm fix and it should go green.
  • Left one inline note about splitting on ## inside code blocks.
  • Heads up: a single huge section, or a file with no ## headings at all, would still crash. That's fine for now, but maybe add a quick comment in the code so it's clear this isn't a full fix.

Changeset is already included, so that's covered.


Generated by Claude Code

let current: string[] = [];

for (const line of file.content.split("\n")) {
if (line.startsWith("## ")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to watch here. If a line inside a code block starts with ## , it gets treated as a heading and the file is split in the wrong place. That could break code samples in exactly the big files this targets. Might be worth skipping lines inside fenced ``` blocks.


Generated by Claude Code

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.

2 participants