Skip to content

feat: add batch querying for multi-agent dispatch#223

Merged
carlos-alm merged 2 commits into
mainfrom
feat/batch-query
Mar 2, 2026
Merged

feat: add batch querying for multi-agent dispatch#223
carlos-alm merged 2 commits into
mainfrom
feat/batch-query

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • Add codegraph batch <command> [targets...] CLI command that runs the same query against multiple targets in one call, returning all results in a single JSON payload
  • Add batchData() programmatic API and batch_query MCP tool for AI agent consumption
  • Supports 10 commands: fn-impact, context, explain, where, query, fn, impact, deps, flow, complexity
  • Per-target error isolation — one failing target doesn't abort the batch
  • Target input via positional args, --from-file (JSON array or newline-delimited), or --stdin

Closes #28 (Backlog)

Test plan

  • 14 integration tests covering success, partial failure, error capture, empty targets, unknown commands, complexity, and CLI JSON output
  • MCP unit tests updated — batch_query in tool list, all 36 MCP tests pass
  • 151 total tests pass across batch, queries, audit, context, flow, and MCP suites
  • Biome lint clean on all changed files

Add `codegraph batch <command> [targets...]` CLI command, `batchData()`
programmatic API, and `batch_query` MCP tool. Runs the same query
against multiple targets in one call, returning all results in a single
JSON payload with per-target error isolation.

Supports 10 commands: fn-impact, context, explain, where, query, fn,
impact, deps, flow, complexity. Accepts targets via positional args,
--from-file (JSON array or newline-delimited), or --stdin.

Impact: 3 functions changed, 3 affected
@claude

claude Bot commented Mar 2, 2026

Copy link
Copy Markdown

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


PR Review: Batch Querying Feature

Review Tasks:

  • Read and analyze all changed files
  • Phase 1: Root cause analysis
  • Phase 2: Configuration change detection
  • Phase 3: Test integrity assessment
  • Phase 4: Code quality review
  • Provide final rating and recommendation

Phase 1: Root Cause Analysis ✅

Problem Being Solved: The PR addresses issue #28 requesting batch querying capability for multi-agent swarms that need to execute 20+ queries efficiently in a single call rather than individual API calls.

Why This Approach: The implementation is well-justified:

  • Adds a dedicated batch.js module with clean separation of concerns
  • Leverages existing query functions rather than reimplementing logic
  • Provides both CLI and programmatic APIs plus MCP tool integration
  • Error isolation prevents one failing target from aborting the entire batch

Risk Assessment: LOW RISK - This is a pure additive feature that doesn't modify existing functionality.

Phase 2: Configuration Change Detection ✅

No high-risk configuration changes detected:

  • No biome/linting rule modifications
  • No test timeout increases or coverage threshold changes
  • No build configuration changes
  • No TypeScript strictness relaxation

Phase 3: Test Integrity Assessment ✅

Test coverage is comprehensive:

  • 14 integration tests in batch.test.js covering success cases, partial failures, error handling, empty targets, unknown commands, complexity command, and CLI JSON output
  • MCP unit tests updated to include batch_query in expected tool list
  • All tests use proper assertions without weakening
  • No removed or relaxed assertions found
  • Tests validate both happy path and error conditions properly

Phase 4: Code Quality Assessment ✅

Strengths:

  • Clean architecture: BATCH_COMMANDS registry maps commands to functions with signature metadata
  • Proper error handling: Per-target try/catch with error isolation
  • Security: No shell execution, SQL injection, or eval usage detected
  • Input validation: CLI validates commands against allowed list and symbol kinds
  • Consistent patterns: Follows existing codebase conventions for CLI options and JSON output
  • Memory safe: No unbounded operations or resource leaks

Minor observations:

  • Input parsing uses parseInt() without validation, but this follows existing patterns throughout the codebase (src/cli.js:1196)
  • JSON parsing in CLI for file/stdin input has basic error handling via try/catch in calling context
  • MCP integration uses dynamic import properly for lazy loading

No security or performance issues identified

Root Cause Analysis

Problem Being Solved: Multi-agent systems need efficient batch querying to avoid N+1 API call patterns when analyzing multiple targets simultaneously.
Why This Approach: Leverages existing, proven query functions with minimal duplication and proper error isolation.
Risk Assessment: Very low risk - pure additive feature with comprehensive test coverage.

Critical Concerns

None identified. This is a well-implemented feature addition.

Final Recommendation

  • Rating: ⭐⭐⭐⭐☆ (4/5)
  • Action: APPROVE
  • Reasoning: High-quality implementation with excellent test coverage, clean architecture, proper error handling, and no security concerns. Addresses a real need for multi-agent systems with a well-designed solution that maintains consistency with the existing codebase.

@greptile-apps

greptile-apps Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds batch querying functionality that enables running the same query command against multiple targets in a single call, returning consolidated JSON output. The implementation spans batch orchestration (batch.js), CLI integration (cli.js), programmatic API exports (index.js), and MCP tool exposure (mcp.js).

Key implementation details:

  • 10 supported commands: fn-impact, context, explain, where, query, fn, impact, deps, flow, complexity
  • Error isolation: Individual target failures don't abort the batch; each result includes ok status and either data or error
  • Flexible input: Targets via positional args, --from-file (JSON/newline), or --stdin
  • Special handling: complexity command uses dbOnly signature, passing target in opts rather than as first arg
  • 14 integration tests covering success, partial failure, edge cases, and CLI output

The code is clean, well-documented, and follows project conventions. All query function signatures are correctly mapped to their respective call patterns.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • Clean implementation with comprehensive test coverage (14 integration tests), proper error handling, correct function signature mappings, and no logical or security issues found. The previous comment issue about spread order was already addressed.
  • No files require special attention

Important Files Changed

Filename Overview
src/batch.js New batch orchestration module with proper error isolation and command mapping
src/cli.js Added batch command with flexible input methods (args, file, stdin) and proper validation
src/index.js Exported batch functions for programmatic API access
src/mcp.js Added batch_query tool with proper schema and handler for MCP agent consumption

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant Batch
    participant QueryFns
    participant DB

    User->>CLI: batch <command> [targets...] --db path
    CLI->>CLI: Parse input (args/file/stdin)
    CLI->>CLI: Validate command & options
    CLI->>Batch: batch(command, targets, dbPath, opts)
    Batch->>Batch: batchData(command, targets, dbPath, opts)
    
    loop For each target
        alt sig === 'dbOnly' (complexity)
            Batch->>QueryFns: fn(dbPath, {...opts, target})
        else sig === 'name'/'target'/'file'
            Batch->>QueryFns: fn(target, dbPath, opts)
        end
        QueryFns->>DB: Query graph.db
        DB-->>QueryFns: Return data
        alt Success
            QueryFns-->>Batch: data
            Batch->>Batch: results.push({target, ok:true, data})
        else Error
            QueryFns-->>Batch: throw error
            Batch->>Batch: results.push({target, ok:false, error})
        end
    end
    
    Batch-->>CLI: {command, total, succeeded, failed, results}
    CLI->>User: JSON output
Loading

Last reviewed commit: 2355b43

@greptile-apps greptile-apps Bot left a comment

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.

6 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread src/batch.js Outdated
* - 'name' → dataFn(target, dbPath, opts)
* - 'target' → dataFn(target, dbPath, opts)
* - 'file' → dataFn(target, dbPath, opts)
* - 'dbOnly' → dataFn(dbPath, { target, ...opts }) (target goes into opts)

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.

Comment shows spread order backwards from implementation on line 68

Suggested change
* - 'dbOnly' dataFn(dbPath, { target, ...opts }) (target goes into opts)
* - 'dbOnly' dataFn(dbPath, { ...opts, target }) (target goes into opts)

Comment thread src/batch.js Outdated
try {
let data;
if (entry.sig === 'dbOnly') {
// complexityData(dbPath, { target, ...opts })

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.

Comment shows spread order backwards from implementation

Suggested change
// complexityData(dbPath, { target, ...opts })
// complexityData(dbPath, { ...opts, target })

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@claude

claude Bot commented Mar 2, 2026

Copy link
Copy Markdown

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


PR Review: Batch Querying Feature

Review Tasks:

  • Read and analyze all changed files
  • Phase 1: Root cause analysis
  • Phase 2: Configuration change detection
  • Phase 3: Test integrity assessment
  • Phase 4: Code quality review
  • Provide final rating and recommendation

Phase 1: Root Cause Analysis ✅

Problem Being Solved: The PR addresses issue #28 requesting batch querying capability for multi-agent swarms that need to execute 20+ queries efficiently in a single call rather than individual API calls.

Why This Approach: The implementation is well-justified:

  • Adds a dedicated batch.js module with clean separation of concerns
  • Leverages existing query functions rather than reimplementing logic
  • Provides both CLI and programmatic APIs plus MCP tool integration
  • Error isolation prevents one failing target from aborting the entire batch

Risk Assessment: LOW RISK - This is a pure additive feature that doesn't modify existing functionality.

Phase 2: Configuration Change Detection ✅

No high-risk configuration changes detected:

  • No biome/linting rule modifications
  • No test timeout increases or coverage threshold changes
  • No build configuration changes
  • No TypeScript strictness relaxation

Phase 3: Test Integrity Assessment ✅

Test coverage is comprehensive:

  • 14 integration tests in batch.test.js covering success cases, partial failures, error handling, empty targets, unknown commands, complexity command, and CLI JSON output
  • MCP unit tests updated to include batch_query in expected tool list
  • All tests use proper assertions without weakening
  • No removed or relaxed assertions found
  • Tests validate both happy path and error conditions properly

Phase 4: Code Quality Assessment ✅

Strengths:

  • Clean architecture: BATCH_COMMANDS registry maps commands to functions with signature metadata
  • Proper error handling: Per-target try/catch with error isolation
  • Security: No shell execution, SQL injection, or eval usage detected
  • Input validation: CLI validates commands against allowed list and symbol kinds
  • Consistent patterns: Follows existing codebase conventions for CLI options and JSON output
  • Memory safe: No unbounded operations or resource leaks

Minor observations:

  • Input parsing uses parseInt() without validation, but this follows existing patterns throughout the codebase (src/cli.js:1196)
  • JSON parsing in CLI for file/stdin input has basic error handling via try/catch in calling context
  • MCP integration uses dynamic import properly for lazy loading

No security or performance issues identified

Root Cause Analysis

Problem Being Solved: Multi-agent systems need efficient batch querying to avoid N+1 API call patterns when analyzing multiple targets simultaneously.
Why This Approach: Leverages existing, proven query functions with minimal duplication and proper error isolation.
Risk Assessment: Very low risk - pure additive feature with comprehensive test coverage.

Critical Concerns

None identified. This is a well-implemented feature addition.

Final Recommendation

  • Rating: ⭐⭐⭐⭐☆ (4/5)
  • Action: APPROVE
  • Reasoning: High-quality implementation with excellent test coverage, clean architecture, proper error handling, and no security concerns. Addresses a real need for multi-agent systems with a well-designed solution that maintains consistency with the existing codebase.

@carlos-alm carlos-alm merged commit 850ef3e into main Mar 2, 2026
15 checks passed
@carlos-alm carlos-alm deleted the feat/batch-query branch March 2, 2026 07:19
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