fix: parse self-closing graph entities
Summary
- Accept self-closing graph
<entity .../>tags inparseGraphXml. - Keep existing explicit closing-tag entity parsing and property parsing behavior.
- Add regression coverage for a self-closing entity that participates in a relationship.
Fixes #492.
Verification
npx tsdownpassed in isolated fork clone.npm run buildreached tsdown build completion but failed afterward on Windows shell-only copy fallback (trueis not recognized / shell syntax). No live AgentMemory service was started.- Tests not run locally per local environment constraint; full
npm testintentionally skipped to avoid any accidental interaction with the live AgentMemory setup.
Summary by CodeRabbit
-
Bug Fixes
- Improved XML entity parsing to support both self-closing and standard tag formats.
-
Tests
- Added test case for entity parsing with self-closing XML tags to ensure robust format handling.
@Rex57 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.
A member of the Team first needs to authorize it.
Updated the graph extraction entity parser to accept both self-closing Self-closing Entity Tag Support π― 2 (Simple) | β±οΈ ~8 minutes π° A rabbit's tale of tags made whole, βοΈ Tip: You can configure your own custom pre-merge checks in the settings.π Walkthrough
Walkthrough
<entity ... /> and standard <entity>...</entity> tag formats by making the properties block optional in the regex. Added a test case verifying self-closing entities parse correctly and produce expected node and edge counts.Changes
Layer / File(s)
Summary
Entity regex self-closing tag support and test
src/functions/graph.ts, test/graph.test.tsparseGraphXml's entityRegex now treats the inner properties content group as optional using ?, allowing empty propsBlock when tags are self-closing. A new test mocks self-closing file entities and verifies extraction produces correct node and edge counts.Estimated code review effort
Poem
Self-closing entities find their role,
With optionals in regex bright,
The graph now parses day and night!π₯ Pre-merge checks | β
4 | β 1
β Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Docstring Coverage
β οΈ Warning
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.
Write docstrings for the functions missing them to satisfy the coverage threshold.
β
Passed checks (4 passed)
Check name
Status
Explanation
Title check
β
Passed
The title accurately describes the main change: updating the parseGraphXml function to handle self-closing graph entity tags in addition to standard closing-tag forms.
Linked Issues check
β
Passed
The pull request fully addresses issue
#492 by modifying parseGraphXml's regex to support self-closing entity tags and adding test coverage for this scenario.
Out of Scope Changes check
β
Passed
All changes are scoped to the stated objective: updating entity parsing logic and adding regression test coverage for self-closing entities.
Description Check
β
Passed
Check skipped - CodeRabbitβs high-level summary is enabled.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Caught a regression on local test merge. The new self-closing test case fails because the regex still has a greedy quantifier:
// shipped in this PR:
/<entity\s+type="([^"]+)"\s+name="([^"]+)"[^>]*(?:\/>|>([\s\S]*?)<\/entity>)/g
// ^^^^^ greedy β eats across the next entity
Traced standalone with the test payload (<entity ... />\n<entity ... ><property/></entity>): match 1 captures the first entity's name correctly, then [^>]* greedily consumes the / of /> and tries the alternation. The first alternative \/> fails (no / left to match), so it falls through to the second alternative >(...)<\/entity> β which then matches >\n<entity ...><property/></entity>, swallowing entity #2 entirely. Result: 1 match instead of 2.
One-char fix: lazy quantifier instead of greedy.
- /<entity\s+type="([^"]+)"\s+name="([^"]+)"[^>]*(?:\/>|>([\s\S]*?)<\/entity>)/g
+ /<entity\s+type="([^"]+)"\s+name="([^"]+)"[^>]*?(?:\/>|>([\s\S]*?)<\/entity>)/g
Verified with the same node trace: lazy returns 2 matches.
Push that and the test suite should go green. Thanks for the catch + the regression test β that test is exactly the kind of payload that exposes the bug.
I hit this same parser failure while investigating #559 / graph rebuild behavior on a local v0.9.20-style store. This PR is the right fix direction, and I think the real provider output makes the case stronger.
A live graph extraction response that source parseGraphXml would parse as 0 nodes / 0 edges was not empty. It looked like this, sanitized:
<entities>
<entity type="agent" name="Agent"/>
<entity type="system" name="Memory System"/>
<entity type="component" name="MCP Server Agent Memory"/>
<entity type="concept" name="Chinese Input"/>
<entity type="concept" name="English Memories"/>
<entity type="tool" name="Glob"/>
<entity type="directory" name="<local-project-dir>"/>
<entity type="file_type" name="Markdown files"/>
</entities>
<relationships>
<relationship type="uses" source="Agent" target="Glob" weight="0.9"/>
<relationship type="searches_in" source="Glob" target="<local-project-dir>" weight="0.9"/>
<relationship type="searches_for" source="Glob" target="Markdown files" weight="0.9"/>
</relationships>
So self-closing entity support is not just a synthetic edge case: it is enough to turn real non-empty provider output into 0/0 today.
One follow-up this PR may or may not want to include: the same real response also contains out-of-schema entity/relationship types (agent, system, component, directory, file_type, searches_in, searches_for, etc.). Even after the self-closing regex fix, those need either normalization to the supported graph enums or explicit rejection/fallback, otherwise graph extraction may stay brittle. Happy to split that into a separate PR if you'd rather keep #494 narrowly scoped to self-closing tags.
This also cross-links to #559, because parser loss can present as an empty graph even when the provider returned usable graph-shaped XML.
Thanks @Rex57 β regex change is minimal (alternation between self-closing and explicit-close) and propsBlock ?? "" guard handles the missing capture group. Tests cover the new path. Merged. Closes #492; partial fix for #559.