Repository navigation
Cut trail's peak memory on big repos - #737
Conversation
🌱 graft blast radius2 areas changed → 4 areas can be affected. 7 dependent symbols, depth 2. flowchart TB
A0(("CLI Graph Refresh<br/>3 symbols"))
A1(("MCP Server Integration<br/>2 symbols"))
A2(("Graph Building<br/>1 symbol"))
A3(("Pull Request Review<br/>1 symbol"))
classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
class A0,A1,A2,A3 reached;
Who knows this code — 3 people across 6 areas
Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no All 7 dependent symbols, grouped by areaCLI Graph Refresh — 3 symbols in 2 files
MCP Server Integration — 2 symbols in 2 files
Graph Building — 1 symbol in 1 file
Pull Request Review — 1 symbol in 1 file
Test signal per changed area — 1 ✓ · 1 ⚠Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.
42 test suites also reference this code45 symbols, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.
Open the interactive graph → — click an area to see its dependent symbols at file:line. |
trailhq#737's test parsed the extract cache as one JSON document and compared readExtractCache with strict prototype equality. The cache is now NDJSON (a header line, then one {rel, e} line per file) and its files map is prototype-less, so the test checks each line and compares by value.
…nferred blast dependents (#25) * fix(graph): keep a running build's lock, count a linked worktree once, and mark inferred blast dependents A lock past 5 minutes was taken as stale by age alone, so a slow first build lost it to the next query, which started a second build beside it. A lock is now taken over only once its owner has gone, or at 15 minutes whoever holds it. sync-run names itself in the lock it is handed, since whoever took the lock exits at once. Liveness only extends a lock, so a lock is never freed sooner than before. From Trail-Code #736, with the claim written through writeFileInside so it cannot follow a planted link. The low-priority builds and overlap telemetry in #736 and the memory work in #737 are left out. A workspace took every child with a .git as a repository, so a linked worktree beside its main checkout was indexed as a second one. workspaceRepos keeps one child per repository: the main checkout, or the first worktree when the main checkout is elsewhere. Requiring a .git folder instead would empty a folder of worktrees and drop submodules and --separate-git-dir clones. The parent still counts checkouts, so a repo beside its own worktree is a workspace of one and not a pooled graph of both. Running from inside a worktree is untouched: its root has a .git, so it never was a workspace. blast computed which dependents were inferred and then dropped the flag. They now carry the [inferred] mark callers prints, in the text, Markdown and JSON reports and in the blast radius after an edit. The summary counts them, and at each depth they follow the definite ones, so a list's cap drops leads first. Across changed files a definite path beats an inferred one of the same depth, as it does within one walk. * test: read the linked worktree's graph from its file
Issue: In a Claude Code session on assign, trail's processes used up to 4.2 GB at once, enough to make a laptop hang while trail syncs.
Why: The MCP server rebuilt the code map inside itself after edits and kept about 2 GB for the rest of the session. Every query also copied the whole search index, and one non-ASCII character made each map file twice as big in memory.
Fix: Rebuilds run in a short-lived process that gives its memory back when it ends, queries keep only the words they look up, and the map files are written as plain ASCII. One turn's peak drops to 2.9 GB, with the same answers.
Moves: active users, people with
session_summaryin the last 7 days (PostHog db 11,posthog_event_full_view): 7,214 on 2026-10-29, read 13:10 IST (996 of them from the trail CLI).Second PR for the reported hang, after #736 (lock takeover, which can't happen on the reporter's 0.26.0). This one is the memory, and every path it changes is also in 0.26.0.
Measured: one turn on assign, median of 3
The MCP server answers a query,
trail askruns as the prompt hook runs it, the agent edits a file and queries again, thentrail buildruns as the end-of-turn sync does. Copy of assign (88k symbols: 94 MB map, 70 MB search index, 255 MB extract cache), 12-core Mac, 24 GB. Before isorigin/main(19865ff4).trail ask(prompt hook's child)The three runs' totals: before 4,362 / 4,311 / 3,288 MB, after 2,957 / 3,111 / 2,859 MB. That is a 31% cut by median and 25% by mean. The total depends on how much the processes' peaks overlap in time, so it varies. Each process's own peak is lower in every run: the MCP server drops from 3,106–3,812 to 1,039–1,766 MB (median less than half), the build drops from 2,285–2,559 to 1,865–2,179 MB, and
askfrom 1,094–1,351 to 933–948 MB.Same answers:
trail ask --jsonis byte-identical on 8 queries,ask-index.jsonis byte-identical, andwiring.jsonand the extract cache read back the same values.What changed
src/graph/refresh.ts+ newsrc/graph/refresh-run.ts:ensureFreshGraph's drift rebuild runs in a child process when the compiled script ships next to it (from source, i.e. the tests, it still builds in process). The query waits for it as it waited for the in-process build. A signal that ends the query kills the child before releasing the lock.src/ask/ask.ts: a sidecar doc keeps only the query's terms and the plural formshasTermchecks, plus its body length.--inkeeps whole bags, since its idf comes from them.src/graph/write.ts(asciiJson),src/graph/extract-cache.ts: non-ASCII written as\uXXXX. One such character made V8 hold the whole file as a two-byte string: ~100 MB more per map read, ~300 MB per extract-cache read. The extract cache is also written one file's entry at a time instead of as one 255 MB string.src/ask/index-file.ts: the search index is written entry by entry, with the same bytes.Kept away from
src/cli.ts,src/telemetry/contract.ts,src/claude/format.ts,src/notes/notes.tsand #736's files.Tests
npm testwith a fresh scratch HOME: 4129 pass, 9 skipped, 1 fail. The one failure isupkeep-hooks"a repo graft set up, on a machine without trail", which fails on clean main the same way.trail checkflags 2 conflicts with the 27 Oct learning that ruled out "building synchronously inside the query". That learning is about the first build of a missing map, which is unchanged (still detached via sync-run). The drift rebuild was already awaited by the query before this PR; it now runs in a child, and a hook timeout still ends it and frees the lock, as before.Follow-ups
[word, count]pairs); a word-to-documents format would be about a tenth.build_completedandquery.🤖 Generated with Claude Code