Skip to content

Watch mode on large repos schedules overlapping full refreshes and delays MCP visibility #792

Closed

Description

@DmytroTelish

Problem

On a large Kùzu-backed repository under cgc watch, single-file edits can take a long time to become queryable through MCP because the watcher refresh path does too much full-repo work and can schedule overlapping refreshes for the same repo.

Reproduction context

Observed on a large monorepo of roughly:

  • 2,190 files
  • 8,764 functions
  • 1,147 classes

Before

On that repo, a single watched source edit took about 20-26 seconds before the new symbol became queryable through MCP.

Instrumenting the refresh path also showed the relink phase scaling with the whole repo rather than the changed file set. In one run, the call relink was still at 100 / 1691 files after 103.7 seconds.

Expected

A watched single-file change should refresh incrementally:

  • avoid overlapping refresh storms for the same repo
  • avoid rebuilding imports for every file on each refresh
  • avoid opening one DB session per changed file
  • avoid relinking the entire repo when only a small file set changed

Candidate fix direction

  • serialize refreshes per repo and batch queued file paths
  • update imports incrementally for changed/deleted files
  • batch changed-file graph updates into one DB session
  • scope call/inheritance relinking to changed files plus affected callers/inheritors

Related work

PR #791 implements this approach and reduced the same large-repo single-file watch latency to <= 10 seconds for symbol visibility in local testing.

Activity

  1. github-actions commented on Apr 3, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  2. DmytroTelish commented on Apr 6, 2026

    @DmytroTelish
    Author

    Hello @Shashankss1205,

    I am writing to request an update to the attached PR. I am open to suggestions and criticism and would be happy to make any necessary edits.

    I appreciate the work you have done but it is not suitable for large projects with frequent changes. I have therefore decided to take action. I can update the changes in my spare time if you can advise how I can assist.

  3. Shashankss1205 commented on Apr 9, 2026

    @Shashankss1205
    Collaborator

    Hey @DmytroTelish, i have recently refactored a major portion of the indexing logic. if you are willing to add incremental indexing support for cgc watch, you can join our discord and communicate your plans regarding this.

    https://discord.gg/dR4QY32uYQ

  4. k282 commented on Apr 15, 2026

    @k282
    Collaborator

    @DmytroTelish I have implemented incremental watch indexing for neo4j. You can do the similar approach for KuzuDB too. Here's what it does:

    Incremental Update Algorithm (in watcher.py):

    Watchdog-based — uses [watchdog] library to detect file system events (modify, create, delete)
    Debounced — waits 2 seconds of quiet before processing (prevents IDE save storms)
    Truly incremental — O(k) not O(n):
    When a file changes, queries Neo4j for files that CALLS/INHERITS the changed file
    Only re-parses the changed file + its callers/inheritors (the affected subset)
    DETACH DELETEs stale edges, updates [imports_map] for just that file, re-links only the subset
    Initial scan — on first [watch], does a full parse to build baseline; subsequent changes are incremental

  5. k282 commented on Apr 15, 2026

    @k282
    Collaborator

    Refer this PR - #796

  6. moved this from Backlog to In progress in CGC Progress Boardon Apr 29, 2026
  7. Shashankss1205 commented on Jul 25, 2026

    @Shashankss1205
    Collaborator

    Resolved: watcher debounces per-path with scoped relink (watcher.py:183-264, commit e4ed17c). Closing.

  8. moved this from In progress to Done in CGC Progress Boardon Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions