Skip to content

Reduce MCP review latency via shared changed-file resolution + bounded auto-detection#457

Open
Bakul2006 wants to merge 1 commit into
tirth8205:mainfrom
Bakul2006:bakul/MCPSpeedUp
Open

Reduce MCP review latency via shared changed-file resolution + bounded auto-detection#457
Bakul2006 wants to merge 1 commit into
tirth8205:mainfrom
Bakul2006:bakul/MCPSpeedUp

Conversation

@Bakul2006
Copy link
Copy Markdown
Contributor

Issue #262

What Changed

New shared resolver

Added:

resolve_changed_files()

in:

_common.py

This centralizes changed-file resolution for all review-oriented tools.

Resolution order:

  1. Explicit changed_files
  2. Short-lived cache reuse
  3. Fast auto-detection fallback
  4. Graceful timeout handling

The resolver returns both resolved files and metadata:

{
"files": [...],
"source": "...",
"cache_hit": bool,
"auto_detect_timed_out": bool,
"timeout_seconds": float,
}

Bounded auto-detection

Auto-detection is now intentionally bounded.

Default timeout:

5 seconds

(configurable)

Instead of allowing long-running internal detection paths to stall MCP workflows, the resolver now fails fast and returns structured guidance.

This prevents multi-minute hangs during agent execution.


Short-lived shared cache

Added a thread-safe changed-file cache with configurable TTL.

Default TTL:

3 seconds

(configurable)

This allows consecutive MCP tool calls in the same review workflow to reuse resolved changed files instead of repeatedly invoking git detection logic.

This is especially beneficial for agent orchestration patterns where multiple tools are called back-to-back.


Wired Into Review Tools

The shared resolver is now used by:

  • detect_changes_func()
  • get_review_context()
  • get_affected_flows_func()
  • get_impact_radius()
  • get_minimal_context()

This keeps behavior consistent across review flows.


User-Facing Behavior

When automatic changed-file detection exceeds the configured timeout and no files are resolved, tools now return explicit guidance indicating that callers should provide changed_files directly for fast execution.

This replaces previous silent stalls / timeout-heavy behavior.


Configuration

New environment variables:

Variable | Default | Purpose -- | -- | -- CRG_FAST_DIFF_TIMEOUT | 5.0 | Maximum auto-detection time CRG_CHANGED_FILES_CACHE_TTL | 3.0 | Cache reuse window

These can be tuned per environment / deployment.


Performance Impact

Expected improvements:

  • Small-diff MCP review workflows drop from minutes to seconds
  • Multi-call agent workflows avoid repeated git scans
  • Faster behavior on Windows repositories
  • Faster recovery on slow repos / CI environments
  • Better interoperability with agent clients using aggressive tool timeouts

@Bakul2006
Copy link
Copy Markdown
Contributor Author

Hey @tirth8205 Just tried adding the Cache memory In the MCP Calls To improve the latency please review if the approach is correct or I should think of another way . Core idea is to make the MCP calls Stateful in some way.

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