Skip to content

fix(cli): reject sync for stale extraction indexes - #1842

Closed
bompus wants to merge 4 commits into
colbymchenry:mainfrom
bompus:fix/upstream-cli-stale-sync
Closed

bompus wants to merge 4 commits into
colbymchenry:mainfrom
bompus:fix/upstream-cli-stale-sync

Conversation

@bompus

@bompus bompus commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

An index built with an older extraction version can make codegraph sync print “Already up to date” and exit 0 even though status recommends a rebuild. With source edits, sync updates only those files and still leaves the index stale.

The CLI now checks the existing extraction-staleness signal before incremental work, closes the graph, and exits 1 with a codegraph index recovery instruction. --quiet also exits 1 and prints the reason as a single stderr line, so a git hook that fails on a non-zero exit still shows the user why. Current indexes continue syncing normally; a full index restores successful sync. The guard is confined to the explicit CLI command, preserving library and watcher incremental behavior.

Related to #1798: this addresses the misleading CLI success signal, not the proposed automatic background rebuild. It complements #1256's status/upgrade guidance changes.

Validation on Node 24.21.0, Linux/WSL2, based on upstream 3ed73bc:

  • TypeScript compilation and asset copying passed.
  • Nine focused CLI tests passed: seven new cases plus two existing explicit-index-path tests.
  • New coverage includes old and missing extraction stamps, unchanged and added files, normal and quiet modes, current indexes, and recovery after a full rebuild.

The equivalent fork integration also passed full native (4,742) and WASM (4,740) suites and five deployment probes. Those full-suite results are from the consolidated fork; the focused tests above were rerun on this upstream-only branch. Windows and the viewer build were not rerun for this change.

A quiet sync is the git-hook path. The stale-index refusal still exits 1,
but now writes one line to stderr so a hook that fails the commit on a
non-zero exit does not block it for an invisible reason. (colbymchenry#1798)
@bompus
bompus force-pushed the fix/upstream-cli-stale-sync branch from d3a8cc3 to 8ac04d4 Compare September 16, 2026 13:26
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Sep 26, 2026
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Sep 26, 2026
colbymchenry#1842's quiet-sync test skips the relaunch (CODEGRAPH_WASM_RELAUNCHED=1)
that adds --disable-warning=ExperimentalWarning. With colbymchenry#1913 merged the
directory probe loads node:sqlite on that path, so the SQLite warning
reached stderr and broke the one-line assertion. Pass the same flags.
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Sep 29, 2026
colbymchenry#1842's quiet-sync test skips the relaunch (CODEGRAPH_WASM_RELAUNCHED=1)
that adds --disable-warning=ExperimentalWarning. With colbymchenry#1913 merged the
directory probe loads node:sqlite on that path, so the SQLite warning
reached stderr and broke the one-line assertion. Pass the same flags.
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Sep 29, 2026
Tree = upstream main + the open PRs that still merge cleanly: colbymchenry#1925, colbymchenry#1957,
colbymchenry#1962, colbymchenry#1955, colbymchenry#1965 and the current heads of colbymchenry#1842 and colbymchenry#1913. Upstream has
already carried colbymchenry#1969-colbymchenry#1971, colbymchenry#1082 and colbymchenry#1791.

Dropped until they are rebased onto upstream's resolver rewrite: colbymchenry#1704,
colbymchenry#1921, colbymchenry#1926 and colbymchenry#1935.
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Oct 15, 2026
colbymchenry#1842's quiet-sync test skips the relaunch (CODEGRAPH_WASM_RELAUNCHED=1)
that adds --disable-warning=ExperimentalWarning. With colbymchenry#1913 merged the
directory probe loads node:sqlite on that path, so the SQLite warning
reached stderr and broke the one-line assertion. Pass the same flags.

(cherry picked from commit 77e16eb)
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Oct 21, 2026
Upstream merged 17 of the fork's carried PRs on 2026-10-20 (several
squashed, some with maintainer edits; colbymchenry#1704's content landed inside
colbymchenry#1926). Every conflict was our pre-merge copy of one of them, so the
upstream side was taken throughout. After the merge the tree differs
from upstream only by colbymchenry#1842, its test-flag fix, .gitignore, the
untracked .pyc and the README banner.

Dropped __tests__/sync-synthesis-input-package.test.ts: colbymchenry#2574 was
superseded by upstream colbymchenry#2688, which does not normalize spellings like
`@/widgets/Chart/`. That gap is colbymchenry#2577; it is carried separately via colbymchenry#2610.
inth3shadows added a commit to inth3shadows/codegraph that referenced this pull request Oct 25, 2026
Fork fixes colbymchenry#2588, colbymchenry#2766, colbymchenry#2807 superseded/merged upstream (maintainer
colbymchenry#2802, colbymchenry#2811, colbymchenry#2802). Removed from fork README carried-fixes list.

Fork-only items retained:
- sync stale-index check (colbymchenry#1842)
- sync-synthesis-input-package test
- ts-outer-declared-receiver test
- cli-sync-stale-index test
colbymchenry pushed a commit that referenced this pull request Oct 31, 2026
An index built by an older extraction version made `codegraph sync` print
"Already up to date" while `codegraph status` said to re-index. Sync
re-reads changed files only and never advances the extraction stamp, so
that message was false however little had changed.

Sync now says "No files changed" in that case and ends with a warning
that names `codegraph index`, after syncing changed files as before. It
exits 0. Refusing, as the PR first did, would have stopped the installed
git hooks: they run sync in the background with its output discarded, so
every index behind a hook would quietly stop following commits on the
next upgrade. `--quiet` stays silent, as cli-sync.test.ts already pins.

Validation: the new cli-sync-stale-index.test.ts has 6 cases for an old
stamp and a missing one, unchanged and changed files, quiet and not, a
current index, and the rebuild clearing the warning. 3 fail on main, 6
pass here. A real commit through the installed post-commit hook on a
stale index put the new file in the index in about a second.

Original PR #1842 by @bompus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@colbymchenry

Copy link
Copy Markdown
Owner

Thanks @bompus! This landed as #3121 with your authorship. One change: codegraph sync now warns and still runs instead of refusing, because the git hooks we install discard its output, so a refusal would silently stop those indexes after every upgrade. Your detection and test matrix are in, and automatic rebuilding stays with #1798.

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.

2 participants