Skip to content

perf(db): generic query execution on NativeDatabase (6.16)#677

Merged
carlos-alm merged 6 commits intomainfrom
feat/dynamic-sql-edge-cases
Mar 30, 2026
Merged

perf(db): generic query execution on NativeDatabase (6.16)#677
carlos-alm merged 6 commits intomainfrom
feat/dynamic-sql-edge-cases

Conversation

@carlos-alm
Copy link
Copy Markdown
Contributor

@carlos-alm carlos-alm commented Mar 29, 2026

Summary

Test plan

  • Verified all 6.16 features exist on main (queryAll, queryGet, validateSchemaVersion, closeDbPair, NativeRepository, NodeQuery native dispatch, test files, audit doc)
  • git diff origin/main confirms only roadmap + sweep skill changes remain (code already merged)

Add queryAll/queryGet methods to NativeDatabase for parameterized SELECT
execution via rusqlite, returning rows as serde_json::Value objects.
This enables NodeQuery and arbitrary SQL to dispatch through the native
engine without porting the SQL builder to Rust.

- NativeDatabase: queryAll, queryGet, validateSchemaVersion methods
- NodeQuery: all()/get() accept optional nativeDb for native dispatch
- connection.ts: closeDbPair/closeDbPairDeferred lifecycle helpers
- finalize.ts/pipeline.ts: use unified close helpers
- detect-changes.ts, build-structure.ts: 3 starter straggler migrations
- Comprehensive db.prepare() audit (194 calls, tiered migration plan)
- 42 new tests (parity, query execution, version check; skip-guarded)
…orts

Replace deprecated baseUrl/paths with Node.js subpath imports (package.json
imports field) + customConditions in tsconfig.json. Uses @codegraph/source
condition for compile-time resolution to src/, default condition for runtime
resolution to dist/.

- Add imports field with conditional mappings for all 11 src/ subdirectories + #types
- Add customConditions: ["@codegraph/source"] to tsconfig.json
- Add resolve.conditions to vitest.config.ts for Vite resolver
- Update verify-imports.ts to resolve #-prefixed specifiers
- Migrate 3 deeply nested files as proof-of-concept

Closes #668
Adds a step after conflict resolution that diffs the merge result against
both parent commits to ensure intentional changes from both sides survived.
Prevents silent content loss during merge conflict resolution.
Resolve conflicts with 6.17 (PR #673): keep lazy-load better-sqlite3,
validateNativeParams, and removed standalone napi functions from main;
keep 6.16 generic query methods and version checking from this branch.

Mark 6.16 and 6.17 as complete in roadmap — Phase 6 fully done.
@claude
Copy link
Copy Markdown

claude bot commented Mar 29, 2026

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


Reviewing PR #677: perf(db): generic query execution on NativeDatabase (6.16)

Review Progress

  • Read changed files and understand modifications
  • Analyze codebase context for native database implementation
  • Check test coverage for new functionality
  • Phase 1: Root cause analysis
  • Phase 2: Configuration change detection
  • Phase 3: Test integrity review
  • Phase 4: Code quality assessment
  • Phase 5: Backlog compliance grading
  • Provide final assessment and recommendation

Root Cause Analysis

Problem Being Solved: This PR completes Phase 6.16 of the native database migration roadmap - implementing generic parameterized query execution via NativeDatabase.queryAll/queryGet to enable gradual migration from better-sqlite3 to rusqlite for read operations.

Why This Approach: The two-file change (.claude/skills/sweep/SKILL.md and docs/roadmap/ROADMAP.md) reflects PR cleanup - updating documentation to reflect completed work rather than implementing new functionality. The actual implementation appears to have been completed in previous commits, as evidenced by the comprehensive test suite and usage patterns found in the codebase.

Risk Assessment: CRITICAL CONCERN - This PR shows signs of being primarily documentation updates rather than the actual feature implementation. The PR description claims to deliver substantial functionality but only shows 2 minimal file changes.

Configuration Change Detection

No High-Risk Configuration Changes: Only documentation files modified. No build config, linting rules, or TypeScript settings changed.

Test Integrity

Strong Test Coverage: Found comprehensive test suite:

  • native-db-query.test.ts - 17 test cases covering queryAll/queryGet functionality
  • native-db-version-check.test.ts - Schema version validation tests
  • query-builder-native-parity.test.ts - Exhaustive parity testing between native and WASM engines
  • Tests cover error handling, type conversion, parameter binding, and edge cases

Test Quality: Tests are well-structured with proper setup/teardown and comprehensive coverage of the API surface.

Code Quality Assessment

Implementation Review: The actual functionality appears well-designed:

  • validateNativeParams provides runtime type safety
  • Connection lifecycle helpers (closeDbPair/closeDbPairDeferred) follow proper ordering
  • NodeQuery builder maintains parity between engines
  • Gradual migration strategy via optional nativeDb parameter

Security: No SQL injection concerns - uses parameterized queries throughout.

Performance: Leverages rusqlite for potential performance gains on native engine path.

Backlog Compliance

  • Zero-dep: ✓ — No new runtime dependencies. Builds on existing rusqlite integration from native addon
  • Foundation-aligned: ✓ — Maintains zero-cost core (P4), preserves embeddable-first design (P5), improves performance for graph analysis/navigation tasks
  • Problem-fit: 3 — This is infrastructure work that enables future optimizations. Indirectly helps AI agents by providing faster query responses, but doesn't directly address token waste or hallucinated dependencies
  • Breaking: No — Purely additive. Existing better-sqlite3 path unchanged, native path is optional enhancement
  • Tier: 1 — Zero-dep + foundation-aligned

Critical Concerns

⚠️ MISMATCH BETWEEN DESCRIPTION AND CHANGES
The PR description claims substantial implementation ("Generic parameterized query execution", "NodeQuery native dispatch", "connection lifecycle helpers") but the diff only shows documentation updates in 2 files:

  1. .claude/skills/sweep/SKILL.md - Added conflict verification step
  2. docs/roadmap/ROADMAP.md - Updated phase completion status

This suggests either:

  1. The implementation was done in previous commits and this is just documentation cleanup, OR
  2. There's a significant mismatch between claimed deliverables and actual changes

Missing Implementation Evidence: Despite extensive testing infrastructure being present, the actual implementation changes are not visible in this PR's diff.

Final Assessment

## Root Cause Analysis
**Problem Being Solved**: Documentation update to reflect Phase 6.16 completion rather than implementing new functionality
**Why This Approach**: PR appears to be cleanup work marking roadmap phases as complete
**Risk Assessment**: Documentation-only changes with misleading PR description

## Backlog Compliance  
- Zero-dep: ✓ — no new dependencies
- Foundation-aligned: ✓ — infrastructure optimization work
- Problem-fit: 3 — indirect benefit to AI agents
- Breaking: No
- Tier: 1

## Critical Concerns
Major discrepancy between PR description (claims feature implementation) and actual changes (documentation only). The functionality described exists in the codebase with comprehensive tests, but this specific PR doesn't appear to deliver it.

## Final Recommendation
- Rating: ⭐⭐☆☆☆ (2/5)
- Action: REQUEST CHANGES
- Reasoning: While the underlying functionality is well-implemented and tested, this PR has a misleading description that doesn't match the actual changes. The PR should either contain the implementation it claims to deliver, or the description should be updated to clearly indicate this is documentation cleanup for previously completed work.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 29, 2026

Greptile Summary

This PR completes the Phase 6 roadmap bookkeeping: it marks steps 6.16 and 6.17 as ✅ in ROADMAP.md (the underlying code was already merged to main via PRs #666, #669, #671, and #673), and adds a post-merge verification step to the sweep skill to address a prior review concern.

Key changes:

  • ROADMAP.md: 6.16 and 6.17 headers updated with ✅; 6.17 "Not started" plan block replaced with the actual implementation summary (lazy-load better-sqlite3, removed 5 standalone #[napi] functions, tuned rusqlite settings); Key PRs: #673 added.
  • SKILL.md: New step 4 inserted into the merge-conflict resolution flow — diffs the resolved file against both origin/<base-branch> and ORIG_HEAD to catch dropped content. The previous reviewer concern about <pre-merge-commit> being an uncaptured placeholder is resolved by using ORIG_HEAD, which git sets automatically after every merge.

Confidence Score: 5/5

Documentation-only PR with no runtime code changes — safe to merge.

Both changes are purely documentary: the ROADMAP.md update accurately reflects work already merged, and the SKILL.md addition correctly applies the ORIG_HEAD idiom as suggested in the prior review thread. No logic, no tests, no runtime risk.

No files require special attention.

Important Files Changed

Filename Overview
.claude/skills/sweep/SKILL.md Adds a post-merge verification step (new step 4) using ORIG_HEAD to diff against both parent commits after conflict resolution — addresses a prior review concern about the missing pre-merge commit capture.
docs/roadmap/ROADMAP.md Marks 6.16 and 6.17 as ✅ Complete, replaces the 6.17 "Not started" plan block with the actual delivered implementation summary, and links to key PR #673.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[PR has CONFLICTING state] --> B[git merge origin/base-branch]
    B --> C[Understand both sides:\nPR description, commit history,\nreview comments, merge-base diff]
    C --> D[Resolve conflicts manually]
    D --> E[Stage resolved files by name\ngit add file1 file2 ...]
    E --> F[Commit: fix: resolve merge conflicts]
    F --> G["**NEW: Verify nothing lost**\ngit diff origin/base-branch -- file\ngit diff ORIG_HEAD -- file"]
    G --> H{Content dropped?}
    H -- Yes --> I[Amend resolution\nbefore pushing]
    I --> G
    H -- No --> J[Push updated branch]
Loading

Reviews (2): Last reviewed commit: "fix(skills): use ORIG_HEAD instead of am..." | Re-trigger Greptile

# Check nothing was lost from the base branch (main)
git diff origin/<base-branch> -- <file>
# Check nothing was lost from the PR branch (pre-merge)
git diff <pre-merge-commit> -- <file>
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 <pre-merge-commit> placeholder has no capture instruction

The new verification step references <pre-merge-commit> in the diff command, but the skill never instructs the agent to capture the pre-merge commit hash before running git merge. An agent following these steps sequentially would have no obvious way to supply this value.

Two cleaner alternatives:

  1. Use ORIG_HEAD — git automatically writes the pre-merge HEAD to ORIG_HEAD after every merge, so the diff command can reference it directly without any prior capture step:

    git diff ORIG_HEAD -- <file>
  2. Explicit capture before merge — add a line before the git merge call instructing the agent to save the commit hash:

    pre_merge=$(git rev-parse HEAD)
    git merge origin/<base-branch>
    # then later: git diff $pre_merge -- <file>

Using ORIG_HEAD is the most natural fit here since it requires no earlier change and matches standard git idioms.

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 — replaced the ambiguous <pre-merge-commit> placeholder with ORIG_HEAD, which git sets automatically after every merge. The comment in the code block now explains this: ORIG_HEAD = pre-merge HEAD, set by git automatically. This is self-contained and requires no prior capture step, matching the standard git idiom you suggested.

@carlos-alm
Copy link
Copy Markdown
Contributor Author

Addressed review feedback from both reviewers:

Greptile (inline comment): Fixed the ambiguous <pre-merge-commit> placeholder in .claude/skills/sweep/SKILL.md — now uses ORIG_HEAD, which git sets automatically after every merge. No prior capture step needed. Commit: 19be165.

Claude review (description/diff mismatch): The observation is correct — the PR description describes the full 6.16 implementation, but the remaining diff is documentation updates (ROADMAP.md phase completion markers + sweep skill improvement). The actual code implementation landed in earlier commits on this branch and was subsequently merged to main via #673. The PR description reads as a milestone summary rather than a description of the final incremental diff. This is a documentation-cleanup PR at this point — the title/description could be more precise, but the changes themselves are correct and safe to merge.

@carlos-alm
Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm carlos-alm merged commit a1d8d4b into main Mar 30, 2026
17 checks passed
@carlos-alm carlos-alm deleted the feat/dynamic-sql-edge-cases branch March 30, 2026 03:46
@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 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.

1 participant