Skip to content

fix(builder): purge function_complexity on full rebuild#239

Merged
carlos-alm merged 1 commit intomainfrom
fix/purge-function-complexity-on-full-rebuild
Mar 2, 2026
Merged

fix(builder): purge function_complexity on full rebuild#239
carlos-alm merged 1 commit intomainfrom
fix/purge-function-complexity-on-full-rebuild

Conversation

@carlos-alm
Copy link
Contributor

Summary

  • Fixes fix(ci): use commit-count versioning for dev builds and benchmarks #173--no-incremental full rebuilds now clear the function_complexity table before inserting new data
  • Without this fix, old complexity rows became orphaned on each full rebuild (node IDs are reassigned), causing unbounded table growth (2160→2879→3599 rows observed across 3 rebuilds, while only ~720 are valid)
  • One-line addition of DELETE FROM function_complexity; to the full-rebuild purge sequence in builder.js

Test plan

  • npm test — all integration/unit tests pass (no regressions)
  • npm run lint — clean
  • Manual: node src/cli.js build . --no-incremental twice, verify SELECT COUNT(*) FROM function_complexity stays constant

`--no-incremental` full rebuilds didn't clear the `function_complexity`
table, causing orphaned rows to accumulate across rebuilds as node IDs
get reassigned. Add `DELETE FROM function_complexity` to the full-rebuild
purge sequence alongside the existing node_metrics/edges/nodes deletions.

Fixes #173

Impact: 1 functions changed, 11 affected
@claude
Copy link

claude bot commented Mar 2, 2026

Claude finished @carlos-alm's task —— View job


PR Review - Analysis Complete

Reviewing PR #239: fix(builder): purge function_complexity on full rebuild

Todo List:

  • Phase 1: Root cause analysis - understand the problem and solution approach
  • Phase 2: Configuration change detection - check for high-risk changes
  • Phase 3: Test integrity - look for red flags in testing approach
  • Phase 4: Code quality review - analyze implementation details
  • Final Assessment: Provide rating and recommendation

Phase 1 Analysis ✅

Problem Being Solved: During --no-incremental full rebuilds, the function_complexity table is not purged before new data is inserted. Since node IDs are reassigned on full rebuilds, old complexity rows become orphaned and accumulate indefinitely, causing unbounded table growth.

Evidence: Author reports table growth from 2160→2879→3599 rows across 3 rebuilds while only ~720 should be valid.

Solution Approach: Add DELETE FROM function_complexity; to the existing purge sequence on line 438 in builder.js.

Phase 2 Analysis ✅

Configuration Changes: ✅ NONE - No configuration, linting, test thresholds, or build settings modified.

Phase 3 Analysis ✅

Test Integrity: ✅ GOOD

  • No test expectations lowered or assertions weakened
  • Author claims tests pass (npm test, npm run lint)
  • Manual test plan provided for verification
  • Existing tests should continue to pass as the change only affects full rebuild cleanup

Phase 4 Analysis ✅

Code Quality: ✅ EXCELLENT

  • Perfect consistency: Incremental builds already clean up function_complexity per-file via deleteComplexityForFile?.run(relPath) (lines 512, 520). This PR simply ensures full rebuilds do the same globally.
  • Foreign key safety: Correctly placed in deletion sequence before DELETE FROM nodes since function_complexity.node_id has a foreign key constraint to nodes.id.
  • Minimal risk: One-line addition to existing proven purge pattern used for node_metrics and edges.
  • Schema alignment: function_complexity table exists since migration v8 (lines 116-125 in db.js) with proper foreign key constraints.
  • Error handling: Uses same try/catch pattern as incremental builds for missing table scenarios.

Technical Verification:

  • ✅ Change is in correct location (full rebuild purge sequence at line 438)
  • ✅ Maintains deletion order: node_metricsedgesfunction_complexitynodes
  • ✅ Consistent with incremental cleanup pattern already implemented
  • ✅ No performance impact (full rebuilds already do multiple table deletions)

Root Cause Analysis

Problem Being Solved: Legitimate data consistency bug - orphaned complexity rows accumulate on full rebuilds due to node ID reassignment.

Why This Approach: Correctly follows existing architectural pattern. Incremental builds already handle this per-file; full builds simply needed the same global cleanup.

Risk Assessment: MINIMAL - Single line addition to proven deletion pattern, maintains referential integrity order.

Critical Concerns

None. This is a clean, minimal fix addressing a real data consistency issue.

Final Recommendation

  • Rating: ⭐⭐⭐⭐⭐ (5/5)
  • Action: APPROVE - Excellent fix with perfect execution
  • Reasoning: Fixes legitimate bug with minimal, well-placed change that follows existing patterns. Change is technically sound, properly positioned, and maintains referential integrity. Author provided clear evidence of the problem and appropriate testing approach.

@carlos-alm carlos-alm merged commit 8ced104 into main Mar 2, 2026
15 checks passed
@carlos-alm carlos-alm deleted the fix/purge-function-complexity-on-full-rebuild branch March 2, 2026 11:01
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

Fixes unbounded function_complexity table growth during full rebuilds by adding DELETE FROM function_complexity; to the purge sequence in buildGraph().

Changes:

  • Added single deletion statement to the full-rebuild purge sequence (line 438)
  • Placed correctly between DELETE FROM edges; and DELETE FROM nodes; to maintain proper deletion order for foreign key constraints
  • Follows existing pattern for other child tables (node_metrics, edges, embeddings)

Why this was needed:
When --no-incremental full rebuilds run, all nodes are deleted and recreated with new auto-incremented IDs. Without purging function_complexity, old rows become orphaned (referencing deleted node IDs), causing unbounded growth (2160→2879→3599 rows observed across rebuilds when only ~720 are valid).

Safety:
The fix is safe because:

  • Foreign keys are temporarily disabled during the deletion sequence
  • Complexity data is recomputed and reinserted after rebuild using INSERT OR REPLACE pattern
  • No data loss—complexity metrics are recalculated from source code during each build
  • Consistent with how node_metrics, edges, and embeddings are already handled

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • Single-line fix that correctly addresses a well-documented bug by adding the missing table deletion to match the existing pattern for other foreign-key-constrained tables. The change is minimal, follows established conventions, and has no side effects.
  • No files require special attention

Important Files Changed

Filename Overview
src/builder.js Added DELETE FROM function_complexity; to full-rebuild purge sequence to prevent orphaned rows and unbounded table growth

Last reviewed commit: 453e81a

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

carlos-alm added a commit that referenced this pull request Mar 2, 2026
* docs: add dogfood report for v2.5.35-dev.26434e2

* docs: move dogfood report to correct path

* docs: remove report from incorrect worktree path

* docs: move v2.5.0 dogfood report to generated/dogfood/

* fix: incremental build verification, complexity warnings, and dev build docs

- Add node/edge count drift detection after incremental builds (>20% warns
  to use --no-incremental), persisting counts in build_meta
- Improve complexity command: when data is missing but graph exists, suggest
  --no-incremental instead of implying no graph exists
- Add @huggingface/transformers as devDependency so embedding benchmarks
  work out of the box
- Document dev build tarball installation in README (npm install <url> fails
  for optional platform deps)

Impact: 3 functions changed, 5 affected

* fix: configurable drift threshold, drift logging, and lock file sync

- Add build.driftThreshold to config defaults (0.2) so the 20%
  incremental build drift threshold is user-configurable
- Include actual drift percentages and threshold in warning message
  for easier debugging
- Regenerate package-lock.json to include @huggingface/transformers
  devDependency (fixes License Compliance Scan CI failure)

Impact: 1 functions changed, 1 affected

* fix(builder): incremental rebuild EISDIR, edge parity, dev tarball, native version

- filter directory nodes from reverse-deps query to prevent EISDIR (#235)
- load unchanged barrel files into reexportMap so barrel-resolved edges
  aren't dropped during incremental rebuilds (#236)
- add --strip flag to sync-native-versions.js removing platform
  optionalDependencies in dev builds, fixing npm install failures (#237)
- sync Cargo.toml version with package.json and automate via version script
- add barrel-project fixture and incremental-parity test

Impact: 4 functions changed, 1 affected

* docs: update 2.6.0 changelog with merged PRs #233 #239 #240 #241
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