mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-27 22:38:50 +00:00
* perf(core): add a tree releaser that lets tree-sitter finalizers run node-tree-sitter frees a Tree's native memory in an N-API finalizer that Node runs from a setImmediate after GC. A parse loop that never yields a macrotask never reaches that phase, so dropping each tree does not lower RSS. createTreeReleaser() yields one macrotask every PARSES_PER_RELEASE (16) calls; parse loops await it after each parse. No callers yet. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(group): split the HTTP project scan into per-file collect and cross-file resolve HttpLanguagePlugin.scanProject took every parsed tree of a project family at once. Replace it with a two-phase HttpProjectScan: collect() reduces one parsed file to plain data while its tree is alive, resolve() runs the cross-file pass over the collected facts in scan order. Java and Kotlin collect their SharedSpringType view; the JS/TS family collects the scope view and framework route facts per file and shares one scan object, which still pools the three grammars as one family. runProjectScan() is the one-shot form for callers that hold every tree. The orchestrator uses it over the inputs it already gathers, so behaviour is unchanged; a follow-up streams the two phases. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): do not keep tree-sitter trees alive across the HTTP source scan HttpRouteExtractor.extract cached every parsed tree until it returned, and the project-scan pass handed all trees of a family to one call. On a large Kotlin/Android monorepo that held gigabytes of native tree memory between two graph queries, which the query memory guard then blamed on the query. Each file is now parsed, scanned and reduced to its project-scan facts in one synchronous step, so its tree is unreachable once the file is done. Only detections and facts are cached. The facts go through structuredClone, which rejects a leaked tree or syntax node and copies strings sliced from the source. The extractor awaits a tree releaser after each parse so the native finalizers run every PARSES_PER_RELEASE parses. A family is marked complete even when none of its files parsed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): let HTTP prepareRepo passes free trees as they go The Java, Kotlin, Python and JS/TS prepareRepo pre-passes parse their gated files in one synchronous loop. They drop each tree, but its native memory is freed only by a finalizer that never runs until the loop ends, so the whole pass stays resident at once. Each pass now awaits a tree releaser before every parse, and prepareRepo may return a Promise (the orchestrator already awaits it; the JS/TS pass was already async). The direct test callers await it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): free tree-sitter trees in the topic, gRPC, Thrift and include scans These extractors parse one file after another in a loop that never yields a macrotask, so the native memory of every tree they drop stays resident until the loop ends (the same deferred-finalizer issue as the HTTP scan). Each loop now awaits a tree releaser before every parse. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(core): nudge V8 to collect dropped tree-sitter trees Yielding a macrotask lets tree finalizers run, but only for wrappers a GC has already found dead. node-tree-sitter never reports a tree's native memory to V8, so a wrapper that reaches the old generation waits for a major GC that JS heap growth alone rarely starts. Over 6,300 Java, Kotlin and TypeScript files the HTTP scan ran 3-4 major GCs, left about 6,700 of 7,200 dropped trees uncollected and reached 1.2-3.7 GB RSS. The tree releaser now also checks RSS every PARSES_PER_RELEASE parses. After 32 MB of growth since the last nudge it replaces one held, never-written 64 MB buffer. Dropping the old (old-generation) buffer leaves external memory that only a major GC releases, so V8 runs one. The buffer is not zero-filled and is above glibc's largest mmap threshold, so it adds no resident memory on Linux or macOS. The same scan then peaked at 0.47-0.92 GB. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): lease each repo's graph pool entry while its contracts are extracted Group sync opened each repo's LadybugDB pool entry without a lease, on the grounds that extraction finishes before anything could evict it. The source scan now yields to the event loop while it parses, so a long query-free parse phase lets the pool's idle sweep, or another caller opening more repos than the pool holds, close the repo between two of its queries. The extractors swallow the resulting errors, so the sync silently lost its graph enrichment. Pin the repo after initLbug and release the lease when the repo's extraction ends, as the manifest windows already do. Only one extraction lease is held at a time, so pool residency stays bounded. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(core): bound the tree releaser's nudge interval instead of ratcheting it The releaser nudged V8 once RSS had grown 32 MB above the RSS at the last nudge. Each nudge therefore raised the bar to that cycle's peak, so the dead trees allowed between nudges grew with the number of parsed files: one 6,300-file HTTP scan reached 2.3 GB, and four times the files 3.5 GB, of which 2.8 GB was outside the JS heap. Measure growth from the lowest RSS seen since the last nudge, re-read after the nudge, and nudge at least every 8 yields (128 parses), which also covers RSS that stays flat after glibc reuses freed memory. On the same scans this peaks at 0.45-0.52 GB and 1.03 GB, with 240-330 MB outside the JS heap at both sizes; the rest at four times the files is per-file facts in the JS heap. Wall time is unchanged. The nudge is now best effort: a failed allocation no longer rejects the caller's extraction, the old buffer is dropped before the new one is allocated, and under --zero-fill-buffers the buffer is a plain ArrayBuffer, whose failed allocation throws instead of aborting the process. nudgeV8 is exported, and a test checks in a child process that it makes V8 run a major GC. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * refactor(group): move the one-shot project scan helper to the tests runProjectScan was production code that only tests called. Move it to test/helpers/run-project-scan.ts; the orchestrator streams collect and resolve itself and never used it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(group): share the parse-turn helpers and cover the Java and Python prepare passes The two tree-release test files carried their own copies of the turn-counting helpers and the safe-parse spy; both now use test/helpers/event-loop-turns.ts, so the two contracts cannot drift. The tree-lifetime fixture never opened the Java or Python prepareRepo parse passes, so a pass that kept its trees went unnoticed. It now has a Java constants class and a FastAPI include_router module, neither of which yields a contract. A mutation that keeps every Java or Python prepare-pass tree now fails the reachability test (2 live trees, limit 1); with the old fixture it passed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(group): note the group sync memory fix and run the lease test on every OS Add an Unreleased "Fixed" entry for the group sync tree-memory fix, including the HTTP language plugin contract change (scanProject becomes projectScan with collect and resolve; prepareRepo may return a Promise). Register the new pool-lease integration test in the native LadybugDB list so it also runs on the Windows and macOS shards. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(core): detect both spellings of --zero-fill-buffers in the tree releaser Node accepts the flag as --zero_fill_buffers too, in its arguments and in NODE_OPTIONS, and keeps that spelling verbatim, so the nudge fell back to Buffer.allocUnsafeSlow, which aborts the process instead of throwing when the allocation fails under that flag. Normalise underscores before comparing. Tests: a child process per spelling (arguments and NODE_OPTIONS) checks which allocation nudgeV8 uses, and a unit case checks that the RSS floor is re-based after a nudge (without it, flat RSS nudged on every yield: 8 nudges instead of 1). The releaser test spawns Node, so it joins the cross-platform spawn list. Comment corrections: the old buffer stays allocated until the GC the new allocation starts (both are allocated until then); the nudge cap holds per scan, not across scans; and the extra major GCs cost about 8 % wall time on a single CPU, while a many-core host showed no change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(group): cover the extraction lease across extractors and failures, Windows-safe The lease test kept the helper's writable LadybugDB handle open while the pool opened the same file, which Windows file locks may refuse. It now closes that handle before each sync and reopens it afterwards, as the FTS empty-tables test does. New cases: - the concurrent-caller case also runs its query-free phase inside the gRPC extractor, so a lease ended after the HTTP extractor fails; - the idle-sweep case opens an unleased control entry and asserts the same sweep closes it, so the case cannot pass with a sweep that never ran; - in the sync spy harness, a repo whose extraction throws releases its lease before the next repo is leased (a lease released only on success leaves one held: [0, 0, 1]). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(core): decide --zero-fill-buffers the way Node parses it The tree releaser matched the flag by spelling and still missed forms Node accepts: a double-quoted token in NODE_OPTIONS, and --zero-fill-buffers= with any value (even =false turns it on). In those forms the nudge used Buffer.allocUnsafeSlow, which under the flag aborts the process when the allocation fails instead of throwing. Parse it as Node does instead: split NODE_OPTIONS on spaces outside double quotes, drop the quotes, honour backslash escapes inside them, read NODE_OPTIONS before the command line, treat dashes and underscores alike, accept any =value, and let the last of --zero-fill-buffers and --no-zero-fill-buffers win. A table of 16 forms is checked against the parser and against Node itself (internal getOptionValue). Always using new ArrayBuffer would avoid the parsing, but it does not pass the residency check: on macOS its zero-filled pages become resident when a freed buffer is reused (about 130 MB after repeated nudges, against 2 MB for allocUnsafeSlow); on Linux both stay at 2 MB. Under an address-space limit, new ArrayBuffer throws in both modes, and allocUnsafeSlow aborts under the flag (exit 134). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(group): check the extraction lease holds through the last extractor The real-pool lease cases covered the HTTP and gRPC extractors only, so a lease released after the gRPC block went unnoticed while the Thrift, topic and include extractors, which also yield, could lose the repo. Add stubs for those three and run the concurrent-caller case inside each. Releasing the lease after gRPC now fails the Thrift, topic and include cases; releasing it before include fails the include case. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(core): stop reading NODE_OPTIONS at the first non-option, as Node does Node stops reading NODE_OPTIONS at the first argument that is not an option (one that does not start with "-", or a bare "-") and ignores the rest, so "--zero-fill-buffers x --no-zero-fill-buffers" leaves zero-fill on. The parser kept reading and answered off, the direction in which the nudge would use the allocation that aborts under the flag. The table now holds that form, a bare "-", a stray token before the flag, an empty argument (which does not stop Node) and a leading tab (only spaces separate), all checked against Node itself. A child case passes the flag on the command line, so the module's use of process.execArgv is tested again. Comments no longer claim the nudge buffer is never touched: under --zero-fill-buffers it is zero-filled, which on macOS makes about 130 MB resident. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(core): treat any mention of --zero-fill-buffers as on The releaser picks its nudge allocation from whether Node runs with --zero-fill-buffers. A wrong "off" picks Buffer.allocUnsafeSlow, which aborts the process when the 64 MB allocation fails in that mode; a wrong "on" only costs macOS residency. The hand-written NODE_OPTIONS parser stopped at the separate value of --require, -r, --import, --title, --conditions or --disable-warning, missed a flag after it, and so answered "off" where Node says "on". It also missed a Node config file, which can turn the flag on. Replace the parser with a conservative scan: any mention of the flag in either spelling, on the command line or in NODE_OPTIONS (quotes and backslashes dropped), or of a config file, counts as on. The Node check now asserts the safe side: wherever Node turns zero-fill on, so does the releaser. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): keep no scope view in the JS/TS project-scan facts The JS/TS collect returned each file's ParsedFile next to its route facts, and the orchestrator cloned and held every one of them until the cross-file resolve. Its only consumer was the context argument of resolveImportTarget, which the JavaScript and TypeScript resolvers do not take. Keep the ParsedFile local to collect and return only the facts (null when a file has none); every file path still reaches the resolver's file set. On a TS-heavy Express fixture (tsconfig alias, three-level router chain) the heap retained at resolve falls from 93 MB to 19 MB at 150 files and from 183 MB to 36 MB at 300, with identical contracts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(group): sample live trees on a stride in the tree lifetime test Every sample forces a full GC, and sampling each of the 83 scan and collect calls made the test take most of a minute on a loaded host. Sample the first, every eighth and the last call instead; a first run counts the calls so the second knows which is last. A leak grows with the files scanned, and one held by a prepareRepo pass stays for the whole scan, so the stride still sees it: holding every tree, or one extra tree in the Java or Python prepareRepo, still fails the test. Locally the test drops from 8.1 s to 1.8 s. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): clone the cached scan detections so they keep no source alive node.text is a substring of the file's source, so a cached detection whose path or name was read from the tree kept the whole source string alive until extract() returned. The project-scan facts already went through structuredClone for this reason; run the scan() detections through it too. They are plain data, and the clone also rejects a leaked tree or syntax node. The new lifetime-test arm scans 16 files with one detection each, once with 1 KB and once with 1 MB of padding, and bounds the extra heap at resolve: it was 15 MB before and is -1.8 MB now. On 300 TS files the added clones cost a few milliseconds. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs: drop the CHANGELOG entry; the release process owns it DoD.md reserves gitnexus/CHANGELOG.md for the release process. The text stays in the pull request description for the release author. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): name the plugin and file when an HTTP scan fails A throw from a plugin's scan or collect, or a result that cannot be structured-cloned, fails the repo's extraction, and sync then reported only the bare cause (for a leaked syntax node: "function getTextFromString (node) ... could not be cloned"). Rethrow it as "HTTP plugin <name> failed on <file>: <cause>" with the original error as its cause. Document the project-scan contract that the orchestrator relies on: collect runs once per file after scan, a throw or a non-cloneable result fails the extraction, resolve is skipped when no family file was parsed, and resolve gets the first parsed family file's repoContext. The clone-error test now runs on the Java project scan, whose grammar is always built. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): share one tree releaser across prepareRepo and the HTTP scan Each prepareRepo pass made its own releaser and the orchestrator another, so their parse counts did not add up: a Java repo with 15 constant files and 15 controllers parsed 31 files in one event-loop turn, never reaching the 16-parse yield. A parse that failed or timed out returned before the orchestrator's release and did not count at all, so a run of failures never yielded (112 parses in one turn in the test). Pass the extraction's releaser to prepareRepo as an optional releaseTrees argument (standalone callers keep their own), and count every parse the orchestrator attempts, before it parses. The turn probe can now make parses fail, for a test of that case. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(core): drop the held nudge buffer when the last group sync ends The tree releasers replace one held 64 MB buffer to nudge V8, and nothing dropped it afterwards: a long-lived MCP or serve process that ran one nudging group sync kept 64 MB of external memory for good (resident on macOS under --zero-fill-buffers). Add holdNudgeBuffer(), a counted hold whose last end drops the buffer. syncGroup, the only caller of the contract extractors, holds it for the whole extraction and ends the hold in its outer finally, so the repos of one sync still share the buffer and concurrent syncs keep it until the last one ends. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(core): pin the held nudge buffer and the lowered RSS floor Two releaser mutants survived the suite: a nudge that does not keep its buffer (the major-GC test only asserted at least one major GC), and an RSS floor that is never lowered after the first reading. Check that the buffer stays allocated until the next nudge replaces it, and that growth from a lower RSS nudges although RSS stays below the first reading; each mutant now fails a test. The major-GC test now asserts more major GCs with the nudge than without, instead of none without it, which depends on the V8 version. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(group): run the tree lifetime test without Kotlin and on Windows paths The Kotlin grammar is optional, but the lifetime test counted Kotlin parses in its bulk fixture, expected Kotlin contracts and ran a Kotlin prepareRepo case, so six cases failed where the grammar is not built. Run the Kotlin cases only where its plugin is registered. The exact parse-count arm with graph routes named its controller with POSIX separators; on Windows the file scan lists backslashes, and the graph path would miss the scanned file and parse it once more. Name a Java controller in the platform's spelling there, and bound the other spelling to one extra parse in a separate case. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * docs(core): say the releaser's nudge cap holds per extraction Since the HTTP extraction shares its releaser with its prepareRepo passes, the yield count, and with it the nudge cap, spans the whole extraction, not one scan. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): copy the strings prepareRepo contexts keep from parsed files A prepareRepo context lives for the whole HTTP extraction, and the Java and Kotlin constant maps, the Python router prefixes and constants, and the JS/TS module facts held strings read from syntax nodes. Those are slices of the file's source, so the context kept the whole source of every file it recorded something from: 14 MB of a 14 MB padding in each family's test. Clone each file's extracted constants or facts where the pass stores them (the Python pass clones its finished context), and state the rule in the prepareRepo contract. The extractors shared with ingestion are unchanged. Their outputs compare deep-equal to their clones on 7,552 fixture files, and a new lifetime-test arm per family bounds the retained heap. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * test(group): check every prepareRepo pass awaits the releaser it is given Only the Java pass was covered by a mixed extraction test, so the Kotlin, Python or JS/TS pass could drop the shared releaser unnoticed. Hand each pass a counting releaser, make every third parse fail, and expect one await per attempted parse. A pass that ignores the releaser now fails (0 of 48), and so does one that awaits only after a successful parse (32 of 48). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): name the plugins when a project scan's resolve fails A throw from projectScan.resolve still reached sync with only its own message, unlike scan, collect and their clones. Rethrow it as "HTTP project scan of <plugins> failed: <cause>", naming the plugins whose files the family pass parsed, with the original error as its cause. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(group): release scan buffers and preserve reopened pool leases * test(group): skip project resolution for empty input --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Gergő Magyar <gergomagyar@icloud.com> Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> |
||
|---|---|---|
| .. | ||
| compat | ||
| fixtures | ||
| helpers | ||
| integration | ||
| unit | ||
| utils | ||