Skip to content

fix: wire config.build.engine into pipeline and connection#1604

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-1596
Jun 18, 2026
Merged

fix: wire config.build.engine into pipeline and connection#1604
carlos-alm merged 2 commits into
mainfrom
fix/issue-1596

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • openRepo() and openReadonlyWithNative() in connection.ts previously read process.env.CODEGRAPH_ENGINE directly, silently ignoring any engine value set via .codegraphrc.json. They now read loadConfig().build.engine, which already incorporates both the env-var path (via applyEnvOverrides) and the config-file path.
  • initializeEngine() and setupPipeline() in pipeline.ts used ctx.opts.engine || 'auto', skipping config.build.engine. The priority chain is now ctx.opts.engine ?? ctx.config.build.engine ?? 'auto'. Config is loaded first in setupPipeline() so build.engine is available before the native-availability check.
  • Fix a pre-existing Biome format warning in fn-impact.ts (unnecessary parentheses, carried in from the fix/issue-1587 merge).

Test plan

  • TypeScript type check passes (npx tsc --noEmit)
  • Lint passes (npm run lint)
  • Graph classifier and role unit tests pass (npx vitest run tests/graph/classifiers tests/unit/roles.test.ts)
  • All non-WASM tests pass (WASM grammar files are not available in the worktree — this is a known limitation, not a regression)

Closes #1596

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent engine-override gap where connection.ts read process.env.CODEGRAPH_ENGINE directly and pipeline.ts used ctx.opts.engine || 'auto', both bypassing any engine value set in .codegraphrc.json. All three call sites now use the unified priority chain opts.engine ?? config.build.engine ?? 'auto', which already incorporates the env-var path via applyEnvOverrides.

  • connection.ts: openRepo() and openReadonlyWithNative() now call loadConfig().build.engine (cached, negligible overhead); openReadonlyWithNative gains an optional opts.engine escape hatch mirroring openRepo().
  • pipeline.ts: loadConfig() is moved above the enginePref computation in setupPipeline() so config.build.engine is populated before the native-availability check and initializeEngine() reads it; || is replaced with ?? throughout the engine chain.
  • fn-impact.ts: Parentheses lint fix only, no functional change.

Confidence Score: 5/5

Safe to merge — changes are narrowly scoped to wiring an existing config value into call sites that were previously ignoring it, with no new code paths or data mutations.

All three engine-selection sites now use the same priority chain; loadConfig() is cached so per-call overhead in connection.ts is negligible; moving loadConfig() earlier in setupPipeline() is safe because openDb/initSchema have no dependency on ctx.config; the ?? vs || change is type-safe given the TypeScript union type on engine.

No files require special attention.

Important Files Changed

Filename Overview
src/db/connection.ts Replaces direct process.env.CODEGRAPH_ENGINE reads with loadConfig().build.engine in both openRepo() and openReadonlyWithNative(); adds optional opts.engine to openReadonlyWithNative() for parity with openRepo().
src/domain/graph/builder/pipeline.ts Moves ctx.config = loadConfig() before enginePref computation so .codegraphrc.json build.engine is visible; changes
src/domain/analysis/fn-impact.ts Removes unnecessary parentheses around nullish-coalescing expression to fix Biome lint warning; no functional change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CLI / programmatic call] --> B{opts.engine set?}
    B -- yes --> E[use opts.engine]
    B -- no --> C[loadConfig / ctx.config]
    C --> D{config.build.engine set?}
    D -- yes --> E
    D -- no --> F[fallback: 'auto']
    E --> G{engine !== 'wasm'?}
    F --> G
    G -- yes --> H{isNativeAvailable?}
    H -- yes --> I[open NativeDatabase / rusqlite]
    H -- no --> J[open better-sqlite3]
    G -- no --> J
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[CLI / programmatic call] --> B{opts.engine set?}
    B -- yes --> E[use opts.engine]
    B -- no --> C[loadConfig / ctx.config]
    C --> D{config.build.engine set?}
    D -- yes --> E
    D -- no --> F[fallback: 'auto']
    E --> G{engine !== 'wasm'?}
    F --> G
    G -- yes --> H{isNativeAvailable?}
    H -- yes --> I[open NativeDatabase / rusqlite]
    H -- no --> J[open better-sqlite3]
    G -- no --> J
Loading

Reviews (4): Last reviewed commit: "fix: add engine override param to openRe..." | Re-trigger Greptile

Comment thread src/db/connection.ts Outdated
const engine = process.env.CODEGRAPH_ENGINE || 'auto';
// config.build.engine covers both CODEGRAPH_ENGINE env (via applyEnvOverrides)
// and the .codegraphrc.json config-file path.
const engine = loadConfig().build.engine ?? 'auto';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 openReadonlyWithNative cannot accept a per-call engine override

openRepo() accepts opts.engine so callers can force 'wasm' for a specific operation, but openReadonlyWithNative() has no such escape hatch and always reads loadConfig().build.engine. Any future caller that needs --engine wasm for a query path (e.g. a benchmark or test harness) has no way to opt out of the native path through this function. Since this is a query-only surface the risk is low today, but the asymmetry may cause confusion if callers expect parity with openRepo().

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f7606b6. Added an optional opts: { engine?: 'native' | 'wasm' | 'auto' } parameter to openReadonlyWithNative() (default {}), mirroring the openRepo() escape hatch. The priority chain is now opts.engine ?? loadConfig().build.engine ?? 'auto' — identical to openRepo(). All existing callers are unaffected (they pass no opts). TypeScript compiles cleanly; the change is purely additive.

Comment thread src/db/connection.ts
// so this covers both the env-var path and the .codegraphrc.json config-file path.
// This ensures --engine wasm and benchmark workers bypass the native path.
const engine = opts.engine || process.env.CODEGRAPH_ENGINE || 'auto';
const engine = opts.engine ?? loadConfig().build.engine ?? 'auto';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 loadConfig() uses process.cwd(), not the DB's directory

Both openRepo() and openReadonlyWithNative() call loadConfig() without a rootDir argument, so they resolve .codegraphrc.json from process.cwd(). When a caller passes a customDbPath pointing to a different repository (e.g. codegraph query --db /other/project/.codegraph/graph.db), the engine setting from that project's config file is never consulted — only the CWD config is used. This was equally true of the previous process.env.CODEGRAPH_ENGINE approach (a process-wide variable), so it is not a regression, but it is worth documenting as a known gap if multi-repo support is planned.

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fixed in this PR — this is a pre-existing limitation that predates this change (the previous process.env.CODEGRAPH_ENGINE approach was equally process-wide). Tracked as #1605 for follow-up when multi-repo / --db hardening is planned.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

4 functions changed42 callers affected across 32 files

  • openRepo in src/db/connection.ts:370 (28 transitive callers)
  • openReadonlyWithNative in src/db/connection.ts:427 (8 transitive callers)
  • initializeEngine in src/domain/graph/builder/pipeline.ts:63 (4 transitive callers)
  • setupPipeline in src/domain/graph/builder/pipeline.ts:173 (5 transitive callers)

@carlos-alm

Copy link
Copy Markdown
Contributor Author

Addressed Greptile P2 findings:

  • Finding 1 (line 433, openReadonlyWithNative engine override): Fixed in f7606b6. Added opts: { engine?: 'native' | 'wasm' | 'auto' } parameter (default {}), matching openRepo()'s escape hatch. Priority chain is now opts.engine ?? loadConfig().build.engine ?? 'auto' — identical to openRepo(). Backward-compatible; no callers updated. TypeScript compiles cleanly.

  • Finding 2 (line 387, loadConfig() uses process.cwd()): Pre-existing limitation, not a regression from this PR — the prior process.env.CODEGRAPH_ENGINE approach was equally process-wide. Tracked as connection: loadConfig() uses process.cwd() instead of DB root when customDbPath is set #1605 for follow-up when --db / multi-repo support is hardened.

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm carlos-alm merged commit 089f3ff into main Jun 18, 2026
31 checks passed
@carlos-alm carlos-alm deleted the fix/issue-1596 branch June 18, 2026 10:07
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: wire config.build.engine from .codegraphrc.json into pipeline and connection.ts

1 participant