Revision: 1 Last modified: 2026-12-04T17:48:16Z
The operator's one-shot: pull, refresh the CodeGraph index, commit, push.
Run it when: you want the whole local cycle in one command — bring the work tree up to date, re-index, commit what changed, and push.
The important design fact: the index refresh goes only through the single writer entry
scripts/codegraph/codegraph_safe.sh (§11.4.78(7), §11.4.80(5)), always with --wait. Stock codegraph is never
used as a fallback.
Why --wait matters (review 2026-11-04 F-CG1): a BULK run is detached. Without --wait,
codegraph_safe.sh returns 0 as soon as the indexer starts, so this script would commit, push and exit 0 before
the index exists — and would never see the indexer's failure. With --wait the exit status is the run's final
result.
How this differs from its siblings:
| Script | Does |
|---|---|
codegraph_update.sh |
updates the global npm package only; no index, no git |
codegraph_sync.sh |
status → sync . → status → validate, for one project; calls stock codegraph; no git |
codegraph_update_and_resync.sh (this) |
pull → index (via the writer entry, --wait) → commit → push |
The original version of this cycle (commit 00d4d50) was a one-liner calling stock codegraph init/sync/index and
masking every failure with || true — the pattern CM-CODEGRAPH-SAFE-INDEX-PATH forbids. A writer failure is now
reported and becomes this script's exit status.
bash,git, and a project root (git rev-parse --show-toplevel, falling back topwd).scripts/codegraph/codegraph_safe.shpresent and executable — orCG_UPDATE_SAFE_BINpointing at an equivalent. Missing → exit127withwriter entry not found: <path> (stock codegraph is never used).pull_all,commitandpush_allonPATHor as shell functions in the calling environment. These are the operator's own helper commands; they are UNKNOWN to this repository and not defined by it. If they are absent the parenthesised(... || true)subshells fail silently and the script proceeds to the index step regardless — which is a real footgun, documented rather than papered over.- No env vars are required;
CG_UPDATE_SAFE_BINis the only one read.
# From the project you want to update (the helpers must be available)
bash scripts/codegraph_update_and_resync.sh
# Point at a different writer entry (the tests do this)
CG_UPDATE_SAFE_BIN=/path/to/codegraph_safe.sh bash scripts/codegraph_update_and_resync.shWhat you should see: the output of pull_all, then codegraph_safe.sh's output for init or sync, then the output
of commit and push_all. On a writer failure:
codegraph_update_and_resync: codegraph_safe.sh sync FAILED (rc=1)
There is no --help and no flags.
| Code | Meaning |
|---|---|
0 |
The index run finished and verified |
| (writer's status) | Anything else is codegraph_safe.sh's own final exit status, passed through unchanged |
127 |
The writer entry was not found at CG_UPDATE_SAFE_BIN / scripts/codegraph/codegraph_safe.sh |
Note the asymmetry: pull_all / commit / push_all failures are swallowed (|| true, unchanged from the
operator's helpers) and do not affect the exit code. Only the index run decides it. A 0 from this script therefore
means "the index is current", not "the push succeeded" — check the helper output for that.
- No
.codegraph/codegraph.db→OP=init; otherwiseOP=sync. The choice is made once, before the writer runs. - The writer entry is missing. Prints the path it looked for, states that stock
codegraphis never used, and sets the exit status to127. It does not fall back — that is the point. - A BULK run blocks until it ends, which can be hours. This is why
--waitis mandatory here: the alternative is a silent early return. pull_allfails → the failure is printed by the helper but|| trueswallows the status; the index step still runs andcommit/push_allstill run. If that sequencing is not what you want, run the steps yourself.commitandpush_allare chained with&&, so a failingcommitskipspush_all— but, again, neither affects the exit status.- Inherited git environment. The script first unsets the repository-locating
GIT_*variables (git-env-hermetic), sogit rev-parse --show-toplevelcannot be redirected at another repository by your environment. - Run from a subdirectory.
git rev-parse --show-toplevelfinds the project root, so the writer entry operates on the right project;pull_all/commit/push_allrun from wherever you are.
- Unset the inherited repository-locating
GIT_*variables. - Resolve
HERE;SAFE=CG_UPDATE_SAFE_BIN, else$HERE/codegraph/codegraph_safe.sh. (pull_all || true).PROJECT=git rev-parse --show-toplevel, elsepwd.OP=syncwhen$PROJECT/.codegraph/codegraph.dbexists, elseinit.- If the writer entry exists →
bash "$SAFE" --wait "$OP"and captureCG_RC. Else print the refusal and setCG_RC=127. - On non-zero, print
codegraph_update_and_resync: codegraph_safe.sh $OP FAILED (rc=$CG_RC)to stderr. (commit || true) && (push_all || true).exit "$CG_RC".
scripts/codegraph/codegraph_safe.sh— the single writer entry this script uses; it classifies the run BULK or INCREMENTAL by pending backlog and supports--wait.docs/scripts/codegraph_safe.md.scripts/codegraph/codegraph_guard.sh— the companion guard (docs/scripts/codegraph_guard.md).scripts/codegraph_update.sh— updates the npm package.docs/scripts/codegraph_update.md.scripts/codegraph_sync.sh— the older per-project sync that still calls stockcodegraph(docs/scripts/codegraph_sync.md— see the defect note there).scripts/codegraph/tests/test_update_and_resync.sh,scripts/codegraph/tests/test_guard.sh(caseG9).- §11.4.78(7), §11.4.80(5) (single writer entry),
CM-CODEGRAPH-SAFE-INDEX-PATH.
2026-12-04 — bash -n clean; the script was not executed in this pass, because a run pulls, commits, pushes and
rewrites a CodeGraph index:
$ bash -n scripts/codegraph_update_and_resync.sh && echo PARSE-OK
PARSE-OK
$ grep -n 'CG_UPDATE_SAFE_BIN\|--wait' scripts/codegraph_update_and_resync.shA reader can verify the refusal path safely: point CG_UPDATE_SAFE_BIN at a path that does not exist and inspect the
127 behaviour — the writer is never reached, so no index and no git state is touched:
CG_UPDATE_SAFE_BIN=/nonexistent bash scripts/codegraph_update_and_resync.sh; echo "RC=$?"
# codegraph_update_and_resync: writer entry not found: /nonexistent (stock codegraph is never used)
# RC=127Beware: this still runs your pull_all / commit / push_all helpers, so only do it in a scratch clone.