TokenCap uses Tree-sitter, compiled to WASM, to find real function boundaries in your code. When a large file has to be shown in part, the parser tells it where a function starts and ends, so a matching function is shown whole instead of cut in the middle.
For a while, on Node 20, that only worked for Rust.
What it looked like
Nothing. That was the problem.
The parse layer is built to degrade gracefully. If a grammar is missing or fails, parse() returns null and the caller falls back to text heuristics. It never throws. The error is only printed when TOKENCAP_DEBUG is set.
So on Node 20, JavaScript, TypeScript, Python, Go and Java files all went through the heuristic path for function boundaries, spans and outlines. Builds succeeded. Packs were produced. They were just less precise, and nothing said so.
The cause
TokenCap pins web-tree-sitter 0.24 and vendors its grammars under src/parse/grammars/. A warm-up step loaded all of them in parallel.
On Node 20, that runtime linked the symbols of grammars loaded concurrently into each other. Loading JavaScript would fail with an error naming a Python symbol:
bad export type for 'tree_sitter_python_external_scanner_create'
One grammar survived the race. Every other language fell back. Node 24 happened to tolerate the same parallel load, so on Node 24 everything looked fine.
The fix
Load grammars one at a time. The warm-up can still ask for every grammar at once with Promise.all, but each actual load waits on the previous one through a promise queue (trimmed from src/parse/engine.js):
let loadQueue = Promise.resolve();
function loadLanguageFromPath(wasmPath, langId) {
const load = loadQueue.then(() => Parser.Language.load(wasmPath));
loadQueue = load.catch(() => {});
return load;
}
The real function also wraps a failure in a message that names the grammar and the likely cause, a grammar that does not match the runtime it is loaded into. Concurrent callers asking for the same language share one in-flight load, so the queue does not load a grammar twice.
After the fix, packs are identical across Node 18 and 20.
The test that would have caught it
A test that only checks that parsing does not crash passes the whole time this bug exists. The new test checks the good path (trimmed; samples holds one small snippet per language):
await test("warming every grammar at once loads all of them (Node 20 linking race)", async () => {
disposeEngine();
await warmGrammars();
assert.equal(parserCount(), vendoredLanguages().length);
for (const lang of vendoredLanguages()) {
const tree = parseSync(samples[lang], lang);
assert.ok(tree, `${lang} parses after warmGrammars on ${process.version}`);
assert.ok(!tree.rootNode.hasError);
deleteTree(tree);
}
});
CI now runs the suite on Node 20 on Ubuntu and Windows, and on Node 24 on Ubuntu, with a comment in the workflow saying why: behaviour has differed by Node version before.
A second quiet failure: WASM memory
A second bug had the same shape. Every tree the parser returns lives on the WASM heap until it is freed with deleteTree(). In a long-lived process, like the MCP server or the bridge, the heap could run out. When it does, the runtime aborts with WebAssembly.RuntimeError: Aborted() and stays unusable. Every later parse failed, and fell back, silently.
Now parse() recognises the abort, drops the dead runtime, loads a fresh one and retries once. Long sessions keep parsing.
The lesson
Graceful degradation is the right default for a tool that has to work on any repository. But every fallback branch is a place where a bug can live without a symptom.
Three takeaways:
- For every fallback, write a test that asserts the primary path ran, not just that some output exists.
- Run CI on more than one runtime version when the code depends on a native or WASM layer.
- Make fallbacks visible. A fallback rate that jumps from zero to most of your files should show up somewhere other than a debug flag. TokenCap went part of the way here:
tokencap makenow writes a build record (.tokencap/build.json) listing the layers that built or failed, andask,analyze healthand the MCP status report whether the index is fresh, behind, incomplete or missing, with the command that fixes it.
Install and docs: tokencap.vansharora.app
Top comments (0)