Skip to content

fix(llm): stop a failed --deep round from erasing the concept layer - #111

Closed
christian-jorge wants to merge 6 commits into
trailhq:mainfrom
christian-jorge:fix/llm-build-robustness
Closed

christian-jorge wants to merge 6 commits into
trailhq:mainfrom
christian-jorge:fix/llm-build-robustness

Conversation

@christian-jorge

Copy link
Copy Markdown

A --deep round where every summary call failed erased the whole concept layer. With no successful summaries the node set is empty, and the reconcile step then pruned every existing concept node — including anything a human wrote below the generated block, which the file format explicitly promises to preserve. One expired key or one 429 storm was enough. Nothing is pruned now when synthesis produced nothing.

Also on the money path:

  • A 429 during synthesis discarded every per-file summary already paid for in phase one.
  • stopReason was never checked, so a reply truncated at max_tokens was cached as a valid empty summary — and the cache is keyed by content hash, so it stayed wrong until the file changed.
  • crux truncated the file at 18k chars but still asked about targets whose line numbers were past the cut.
  • -j/--concurrency never reached the concept pass, where a --deep build spends most of its calls; it sat fixed at 8 regardless of the flag.
  • Usage was normalized carefully across providers and then thrown away. A run now reports what it cost.
  • GRAFT_PROVIDER was cast, not validated, so a typo produced an undefined model and an error from deep inside an SDK.
  • Retries are configurable on every provider, and a workspace build no longer aborts the remaining children when one fails.

Part of a stack. This work started as an audit of main and is split by area so each piece is reviewable on its own. Order, each based on the one before it:

  1. feat/subscription-provider — --deep without an API key, + the locale bug
  2. fix/graph-extraction — Python imports, JSX edges, WASM leak
  3. fix/query-and-viz-security — ReDoS, DNS rebinding, XSS, --in
  4. fix/hosts-settings-safety — the settings.json wipe
  5. fix/llm-build-robustness — the concept-layer wipe, usage accounting
  6. fix/windows-and-cli-ux — the dead npm path on Windows
  7. chore/ci-and-packaging — type-check the tests, run the packaged artifact
  8. docs/config-reference — the config surface the above introduced

Cross-fork PRs can only target main, so GitHub shows the cumulative diff here. This PR own diff: fix/hosts-settings-safety...christian-jorge:Graft:fix/llm-build-robustness

Every link in the stack is green on its own: tsc clean and the full suite at 0 failures on Windows. Happy to reorder, rebase, drop any piece, or squash the lot back into one — just say which.

🤖 Generated with Claude Code

christian-jorge and others added 6 commits August 13, 2026 14:53
…ting

Adds a third transport, `claude-cli`, that drives the locally installed and
already-signed-in Claude Code binary in headless mode. `--deep` previously
required GRAFT_API_KEY, so a developer paying for a Claude subscription still
had to buy separate API credits for concept nodes and per-symbol summaries.

The CLI is a coding agent, not a completions endpoint, so the adapter narrows
it: every built-in tool is disabled, and the user's settings, hooks, MCP
servers and CLAUDE.md are kept out of the run — without that a personal
"always answer in Portuguese" memory silently rewrites every summary in the
graph. Structured output is emulated (no tool_choice on this wire) and
transient failures are retried with backoff.

Provider selection is explicit-first: an existing key-based setup resolves
exactly as it did before. The CLI is only inferred when no key is configured.

Also pins the savings/stats number formatting to en-US. Nine bare
toLocaleString() calls followed the machine locale, so a pt-BR host rendered
1990 as "1.990" — and graft explicitly asks the reading agent to SUM those
numbers across calls, making its headline metric ~1000x low. This was already
failing three tests upstream.

681 tests, 0 failures.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Windows only *marks* a file deleted and keeps it in its directory until the
last handle closes, so an rmdir racing a just-closed parse or an exiting child
throws ENOTEMPTY. Bare rmSync teardowns made a DIFFERENT test fail on each full
run while every one passed in isolation. Callers move over in later changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…king a WASM parser per file

A Python repo's graph had no cross-file edges at all: resolveImport treated
'.utils' as a JS-relative path, producing candidates like src/.utils that never
exist. Relative dots now walk directories and __init__.py is a candidate.

JSX component usage produced no edge either — <Button/> is the field 'name' of
a JSX element, which isDeclarationName counted as a declaration, so in a React
app most real dependencies were invisible.

Also: the breadth tier allocated a Parser and a Tree per file and freed neither
(both live in the WASM heap, out of reach of the GC); git ls-files during a
merge conflict emitted every conflicted path three times, tripling its nodes;
C/C++ header prototypes shadowed their definitions; and the extraction cache
stamp ignored queries/*.scm, so editing a grammar query invalidated nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…d honor --in across a workspace

A pattern from a user or an LLM ran unbounded against every file, so one
catastrophic backtrack hung the whole MCP server. grep now runs under a time
budget and reports when it stopped early, in the CLI as well as over MCP.

The viz server accepted any Host header, so any page a developer visited could
rebind DNS and read the repo graph off localhost; and the viewer's esc() left
quotes unescaped, letting a symbol name break out into an attribute. Both are
closed and covered.

Also: graft_trace_calls silently degraded depth 'all' to 1 in a workspace, the
--in filter was dropped entirely for grep and find_all across child repos, and
$ anchors never matched in a CRLF checkout.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ited refresh inside the repo

runInit treated a settings.json it could not parse — a BOM, a comment, a
trailing comma — as absent and overwrote it, taking permissions, env, model,
hooks and statusLine with it, without a backup. It is now refused and reported,
including through the automatic refresh path so hook-only users see it.

An unsolicited refresh no longer creates machine-wide config it was never asked
for: the --no-global opt-out is memoized outside the repo, so deleting graft/
or cloning fresh no longer loses it. The committed shims carry no developer's
home directory, re-init rewrites nothing when nothing changed (a fresh clone
stops going dirty), and the unscoped `npx graft` grant is revoked rather than
carried forward.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…and account for what it cost

A round where every summary call failed produced an empty node set, and the
reconcile step then pruned every existing concept node — including the human
notes written below the generated block. Nothing is pruned now when synthesis
produced nothing. A 429 during synthesis no longer discards the per-file
summaries already paid for in phase one, a truncated reply is no longer cached
as an empty summary (stopReason is checked), and crux targets outside the
truncation window are no longer asked about.

`-j/--concurrency` now reaches the concept pass, where a --deep build spends
most of its calls; it used to stop at the wiring tier and sit fixed at 8.
Per-run token usage is collected and printed instead of being normalized
carefully and thrown away, retries are configurable on every provider, and
GRAFT_PROVIDER is validated instead of cast.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant