Skip to content

Bug: Stale AST line coordinates in get_code_snippet / search_code after file modification #1750

Description

@0xkhalz

Version

v0.10.7

Platform

Linux (x64)

Install channel

Built from source

Binary variant

standard

What happened, and what did you expect?

Files with parse_partial ranges (and modified files generally) can have stale AST line coordinates after the file is edited on disk without re-indexing.

  • get_code_snippet reads and slices source lines from the live file on disk using the coordinates stored at index time. When the file has shifted due to edits, it returns shifted/corrupted source text or an entirely different function's body for the requested symbol.
  • search_code runs grep against the live file on disk (obtaining current line numbers) but maps matches to symbols using stored (stale) [start_line, end_line] node ranges, causing grep hits to be misattributed to adjacent functions, and in MODE_FULL returning drifted source lines.

Expected behavior:
When file metadata changes on disk (freshness != "metadata_match"), tools should detect drift and avoid returning corrupted source slices or misattributed symbols.

Reproduction

  1. Initial indexed state:
    check_index_coverage on src/mcp/mcp.c before edit:
{
  "path": "src/mcp/mcp.c",
  "status": "partial",
  "freshness": "metadata_match"
}

Indexed coordinates for maybe_auto_index: 11769–11819.

  1. Modification on disk:
    Insert 50 comment lines immediately above maybe_auto_index in src/mcp/mcp.c. The function's true location on disk moves from 11769–11819 to 11819–11869. No index_repository or re-index is performed.

  2. Query:
    Call get_code_snippet for maybe_auto_index.

  3. Actual result:
    Returned:

start_line: 11769
end_line:   11819

The returned source field contained the 50 newly inserted comment lines plus the function signature, rather than the function's actual body at its live location. In other queries, it returned the body of dispatch_tool instead.

Confirmations

  • I searched existing issues and this is not a duplicate.
  • My reproduction uses shareable code (a dummy snippet or a public OSS repository), not proprietary code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions