Skip to content

Clean first-run message when the repo isn't codegraph-indexed yet - #21

Merged
inth3shadows merged 3 commits into
masterfrom
claude-missing-index-message
Jul 19, 2026
Merged

Clean first-run message when the repo isn't codegraph-indexed yet#21
inth3shadows merged 3 commits into
masterfrom
claude-missing-index-message

Conversation

@inth3shadows

Copy link
Copy Markdown
Owner

What

The sharpest new-user papercut: point codeshot at a repo that codegraph has never indexed, and you got a confusing raw wrapper —

codeshot: Command failed: codegraph query --path /repo --json --limit 1 -- hello
✗ CodeGraph not initialized in /repo

Now codeshot recognizes that state and hands back the exact fix:

codeshot: codegraph has no index for '/repo' yet — build one first with
'codegraph init /repo', then rerun. (codeshot reads codegraph's index; it doesn't create it.)

This is the sibling of the existing matchSymbolNotFound clean-message handling, and it closes the #1 adoption-friction gap vs rivals that parse source directly (madge/pyan/go-callvis need no index).

The subtlety (found by running it, not reasoning)

The naive fix — check the message in parseCodegraphOutputdoesn't work: an unindexed repo makes codegraph query exit non-zero, so execFile throws before any stdout is parsed. The clean message has to be caught at the throw path in runCodegraph, which recognizes the not-initialized text (matchNotInitialized) and re-throws anything else so a genuine codegraph failure isn't misreported as a missing index. Covers both symbol and --architecture mode via the shared choke point.

Explicitly not doing

No auto-install of codegraph, no auto-codegraph init. Installing software / building a heavy persistent index is codegraph's call, not a diagram tool's — same detect-and-instruct stance as the existing requireOnPath. (An opt-in --init flag is a possible future candidate, never implicit.)

Verified

  • Live end-to-end against a real unindexed tmp repo → clean message, exit 1, both modes.
  • Connected symbols on codeshot's own indexed repo → no false trigger.
  • 88 tests pass (was 85): unit tests for matchNotInitialized / argRepoPath, plus a guarded CLI test that runs the real binary against a fresh unindexed tmp dir and asserts the clean message (not the raw error).

…boarding)

On an unindexed repo, `codegraph query` exits NON-ZERO with "CodeGraph not
initialized" on stderr, so execFile threw before parseCodegraphOutput could see
the text — a first-time user got the confusing wrapper:
  codeshot: Command failed: codegraph query ... CodeGraph not initialized ...

runCodegraph now catches that non-zero exit, recognizes the message via
matchNotInitialized, and prints the exact fix (naming the repo path):
  codeshot: codegraph has no index for '<path>' yet — build one first with
  'codegraph init <path>', then rerun. ...
It re-throws any other codegraph failure so a genuine error isn't misreported as
a missing index. Sibling of the existing matchSymbolNotFound handling; covers
both symbol and --architecture mode via the shared runCodegraph choke point.

Deliberately does NOT auto-install codegraph or auto-run 'codegraph init':
installing software or building a heavy, persistent index is codegraph's call,
not a diagram tool's — the same detect-and-instruct stance as requireOnPath.

- render/callgraph.js: matchNotInitialized, argRepoPath, exitNotInitialized;
  runCodegraph handles the non-zero-exit path
- test/run.js: unit tests + a guarded CLI test against a real unindexed tmp repo
- USAGE.md: troubleshooting entry
- .runechoguardignore: add MAX_CODEGRAPH_BUFFER (const reference misread as a
  bare call by the guard once the refactor touched its line)
…t initialized' race)

Splitting 'codegraph init' and 'codegraph query' across two GitHub Actions steps
intermittently failed the diagrams job with 'not initialized': the step boundary
kills codegraph's process group before the freshly built on-disk db is finalized,
so a later step's fresh query process sees no index (while the same-step status
does). Root-caused by reading codegraph's isInitialized() — it checks for a
finalized .codegraph/codegraph.db, absent when the build process is killed early.

Fix: run init + readiness-probe + --check in one shell step, retrying a real
query until the index answers, with CODEGRAPH_NO_WATCHDOG=1 so a throttled runner
doesn't trip the liveness watchdog mid-index. Not caused by this branch's code
change (master hits the same race; my error-handling change only made the failure
message clean instead of a raw 'Command failed').
…"not initialized"

The prior commit checked for codegraph's "CodeGraph not initialized" message in
parseCodegraphOutput's STDOUT. But codeshot's --architecture enumerate query
(`codegraph query -- ''`) returns every indexed node's content — and this file's
own source contains that exact phrase in a comment describing the message. So
codeshot read its own indexed source back and falsely reported a well-indexed
repo as uninitialized. It only surfaced in CI, which indexes the branch's real
code; master lacked the phrase, and local runs used a symlinked master index.

Fix: match "not initialized" ONLY on stderr with a non-zero exit (runCodegraph's
catch) — never on successful stdout. Removed the stdout scan; narrowed the catch
to err.stderr. Added a regression test (a JSON response mentioning the phrase must
parse, not error). Reverted the CI-hardening commit — it chased a wrong "cross-
step race" hypothesis; ci.yml is back to master's version.
@inth3shadows
inth3shadows merged commit c9e4889 into master Jul 19, 2026
5 checks passed
@inth3shadows
inth3shadows deleted the claude-missing-index-message branch July 19, 2026 15:00
@inth3shadows
inth3shadows restored the claude-missing-index-message branch July 19, 2026 15:01
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