Skip to content

fix: retract markdown docs that become oversized - #319

Merged
xDarkicex merged 3 commits into
xDarkicex:mainfrom
compoodment:fix/markdown-oversized-stale
Aug 1, 2026
Merged

fix: retract markdown docs that become oversized#319
xDarkicex merged 3 commits into
xDarkicex:mainfrom
compoodment:fix/markdown-oversized-stale

Conversation

@compoodment

@compoodment compoodment commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Retracts previously ingested markdown documents when a later scan finds the source file has grown beyond markdownIngestionMaxTokensPerFile.
  • Handles both the pre-read estimate skip path and the streamed too_large path.
  • Adds an integration regression that ingests a small markdown file, grows it oversized, and verifies delete_authored_document removes stale authored content.

Fixes #315.

Verification

  • pnpm exec tsc --noEmit — PASS
  • pnpm run clean:test && pnpm exec tsc -p tsconfig.tests.json && node --test .ts-build/test/integration/markdown-ingest.test.js — PASS

Note: this branch is stacked on #318 so the test suite can compile. Full pnpm check and npm run test:integration are still blocked by unrelated upstream unit/integration failures after #318's compile fix.

– Vale

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced handling of markdown files exceeding configured token limits. Files that grow beyond the size threshold are now properly removed and retracted from the cache, instead of simply being skipped during future processing.
  • Tests

    • Added integration test validating that oversized markdown files are properly retracted from the cache when they exceed the configured token size limits.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Linter diff in the way? Review this PR in Change Stack to focus on meaningful changes and expand context only when needed.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4266ccce-7347-44d3-86d8-6ca426d5ded6

📥 Commits

Reviewing files that changed from the base of the PR and between 6d47279 and 324e4ce.

📒 Files selected for processing (2)
  • src/markdown-ingest.ts
  • test/integration/markdown-ingest.test.ts

📝 Walkthrough

Walkthrough

When a previously ingested markdown file exceeds markdownIngestionMaxTokensPerFile, the scanner now deletes its cached document instead of deferring silently. A new helper function deleteCachedSourceDocument is integrated into both token-check and streaming-detection paths. An integration test validates the retraction flow.

Changes

Oversized file document retraction

Layer / File(s) Summary
Deletion helper and oversized-file detection integration
src/markdown-ingest.ts
New deleteCachedSourceDocument(sourceDoc) helper that enqueues a delete operation and marks the snapshot dirty when a cached document exists. Integrated into syncMarkdownFile to delete cached documents when streamed content is too_large, and into syncCandidates to delete cached documents when estimated token count exceeds the limit.
Integration test for oversized retraction
test/integration/markdown-ingest.test.ts
FsDirentLike type is imported from markdown-ingest.js for reuse. New test case ingests a file under the token cap, rewrites it to exceed the cap, triggers the watcher, and asserts the previously cached authored document is retracted via delete_authored_document RPC call.

Sequence Diagram

sequenceDiagram
  participant Scanner as Markdown Scanner
  participant syncCandidates as syncCandidates
  participant syncMarkdownFile as syncMarkdownFile
  participant deleteCached as deleteCachedSourceDocument
  participant RPCClient as RPC Client
  
  Note over Scanner,RPCClient: File was previously ingested, now exceeds token limit
  Scanner->>syncCandidates: Scan oversized candidate
  syncCandidates->>syncCandidates: Check estimated tokens
  alt Tokens exceed limit
    syncCandidates->>deleteCached: Delete cached document
    deleteCached->>RPCClient: enqueue delete_authored_document
    deleteCached->>syncCandidates: filesDeleted++
  else Proceed to streaming check
    syncCandidates->>syncMarkdownFile: Stream file content
    syncMarkdownFile->>syncMarkdownFile: too_large detected
    syncMarkdownFile->>deleteCached: Delete cached document
    deleteCached->>RPCClient: enqueue delete_authored_document
    syncMarkdownFile->>syncMarkdownFile: Return "deleted"
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug, testing

Suggested reviewers

  • xDarkicex

Poem

🐰 A file grows fat, too large to chew,
The scanner said "skip it," but that won't do,
Now delete we must, no ghosts remain,
Fresh memory, clean—no stale refrain!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: retracting markdown documents that become oversized, which directly addresses the primary objective.
Linked Issues check ✅ Passed All objectives from issue #315 are met: the PR handles oversized files by deleting cached documents, covers both skip paths (pre-read estimate and streamed too_large), includes a regression test, and avoids deleting never-ingested files.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the oversized markdown document retraction issue. The helper function, conditional logic in syncMarkdownFile, and integration test are all necessary to address the linked issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@compoodment
compoodment marked this pull request as ready for review June 5, 2026 20:33
@xDarkicex xDarkicex added the release:patch Bump patch version on merge label Aug 1, 2026
@xDarkicex
xDarkicex merged commit 7f84ac8 into xDarkicex:main Aug 1, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:patch Bump patch version on merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: oversized markdown files leave stale authored documents behind

2 participants