Skip to content

v2: non-Git file search drops existing files after refreshing its capped index #54940

Open

Description

@IbrahimKhan12

Description

On a large non-Git workspace, GET /api/fs/find silently indexes only 100,000 files. Refreshing the index can replace that set with different files, so existing files disappear from search without any filesystem changes. This causes intermittent missing @ autocomplete results across clients.

I reproduced the changing subset directly against OpenCode 2.0.27 with a synthetic fixture containing 200,000 empty generated files under build/ and env/, plus 65 source files under src/. All inventory requests used query=/, type=file, and limit=1000000:

  • Every response contained exactly 100,000 paths and returned HTTP 200.
  • After refresh, 26,216 paths from the first snapshot disappeared and 26,216 different paths appeared.
  • A disappeared file still existed on disk. The fixture was unchanged during the capture.
  • The first file/directory search pair took 2.26 seconds.

Earlier 2.0.25 captures on two real non-Git workspaces also lost source results. One workspace's returned src/ file count changed from 5103 to 0 and back to 5103 across refreshes. Scoping those searches to src/ kept the wanted targets stable and reduced warm backend latency to about 3 to 4 ms. Internal project names and raw captures are omitted.

Expected: existing source files remain searchable across refreshes, or the API explicitly reports an incomplete index. Increasing the result limit should not silently search only a changing subset.

The 2.0.27 ripgrep scan caps non-VCS locations at 100_000 and replaces the index after each scan. Refresh is eligible after 10 seconds. This matches the observed ceiling and changing membership. The responses contain no completeness/truncation marker.

Plugins

No third-party plugins configured in the reproduction. The server used fresh HOME and XDG directories, and the fixture had no OpenCode config or plugin directories in its ancestors.

OpenCode version

2.0.27, installed CLI. Earlier real-workspace measurements used 2.0.25.

Steps to reproduce

  1. Create a non-Git fixture with more than 100,000 generated files and a small source tree:

    from pathlib import Path
    from tempfile import mkdtemp
    
    root = Path(mkdtemp(prefix="opencode-search-"))
    for name in ("build", "env"):
        for group in range(100):
            directory = root / name / f"group-{group:03}"
            directory.mkdir(parents=True)
            for i in range(1000):
                (directory / f"artifact-{i:04}.txt").touch()
    source = root / "src" / "PackageAlpha" / "src"
    source.mkdir(parents=True)
    for i in range(64):
        (source / f"source-{i:03}.rs").touch()
    (source / "wanted.rs").touch()
    print(root)
  2. Start opencode serve --hostname 127.0.0.1 --port 4599 with a fresh home/config/data environment. Set ROOT to the printed fixture path.

  3. Request an inventory and save the JSON response:

    curl -sS -G http://127.0.0.1:4599/api/fs/find \
      --data-urlencode "location[directory]=$ROOT" \
      --data-urlencode 'query=/' --data 'type=file' --data 'limit=1000000'
  4. Wait at least 12 seconds and issue another request to trigger refresh. Wait for the background scan, then save another response. Repeat if the first refresh selects the same subset.

  5. Compare the data[].path sets. Check that removed paths still exist under ROOT. No fixture changes are needed.

Screenshot and/or share link

Discovered while investigating openchamber/openchamber#4645. The synthetic reproduction calls OpenCode directly and does not require OpenChamber.

Operating System

Amazon Linux 2023, Linux 6.12.110-135.202.amzn2023.aarch64, arm64.

Terminal

API reproduction, no TUI. Shell /bin/zsh; TERM=xterm-256color. Terminal application unavailable.

Activity

  1. opencode-agent commented on Oct 12, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report and fixture. I reproduced this on 2.0.27, and it still happens on the latest dev (a22754f).

    Using your fixture (200,000 generated files under build/ and env/, plus 65 files under src/), I ran opencode serve and called GET /api/fs/find with query=/, type=file, limit=1000000:

    • Every response had exactly 100,000 paths.
    • After waiting 12 seconds or more and triggering a refresh, 42,878 paths had been replaced by different ones on 2.0.27 (27,407 on dev). The removed files were still on disk, and nothing in the fixture had changed.
    • The response has only location and data, with nothing saying the index is incomplete.

    In my runs the 65 src/ files stayed in the results each time, so I did not reproduce source files themselves disappearing, as you saw on real workspaces. The swapping subset is the same underlying behaviour.

    The script below reproduces it. It sets OPENCODE_SERVER_PASSWORD, because serve requires auth, and uses Basic auth with the user opencode.

    Reproduction script (repro.py)
    #!/usr/bin/env python3
    """Reproduce #54940: non-Git /api/fs/find caps index at 100k and refresh swaps membership.
    Usage: python3 repro.py [opencode command...]   (default: opencode)
    """
    import base64, json, os, subprocess, sys, time, urllib.parse, urllib.request
    from pathlib import Path
    from tempfile import mkdtemp
    
    cmd = sys.argv[1:] or ["opencode"]
    PORT = 4599
    root = Path(mkdtemp(prefix="opencode-search-"))
    for name in ("build", "env"):
        for group in range(100):
            d = root / name / f"group-{group:03}"
            d.mkdir(parents=True)
            for i in range(1000):
                (d / f"artifact-{i:04}.txt").touch()
    src = root / "src" / "PackageAlpha" / "src"
    src.mkdir(parents=True)
    for i in range(64):
        (src / f"source-{i:03}.rs").touch()
    (src / "wanted.rs").touch()
    print("fixture:", root, flush=True)
    
    home = Path(mkdtemp(prefix="oc-home-"))
    env = dict(os.environ, HOME=str(home), XDG_CONFIG_HOME=str(home / "c"), XDG_DATA_HOME=str(home / "d"),
               XDG_CACHE_HOME=str(home / "k"), XDG_STATE_HOME=str(home / "s"), OPENCODE_SERVER_PASSWORD="repro")
    srv = subprocess.Popen(cmd + ["serve", "--hostname", "127.0.0.1", "--port", str(PORT)], env=env,
                           stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=str(home))
    
    def find():
        q = urllib.parse.urlencode({"location[directory]": str(root), "query": "/", "type": "file", "limit": "1000000"})
        req = urllib.request.Request(f"http://127.0.0.1:{PORT}/api/fs/find?{q}", headers={"Authorization": "Basic " + base64.b64encode(b"opencode:repro").decode()})
        with urllib.request.urlopen(req, timeout=120) as r:
            body = json.load(r)
        return body, {e["path"] for e in body["data"]}
    
    try:
        for _ in range(60):
            try:
                urllib.request.urlopen(f"http://127.0.0.1:{PORT}/", timeout=2); break
            except Exception as e:
                if hasattr(e, "code"): break
                time.sleep(1)
        t = time.time(); body, first = find()
        print(f"snapshot 1: {len(first)} paths ({time.time()-t:.2f}s), keys={list(body.keys())}, src files={sum(p.startswith('src/') for p in first)}")
        prev = first
        for n in range(2, 7):
            time.sleep(12); find()          # trigger background refresh
            time.sleep(15); _, cur = find()  # read refreshed index
            gone = prev - cur
            print(f"snapshot {n}: {len(cur)} paths, removed={len(gone)}, added={len(cur-prev)}, src files={sum(p.startswith('src/') for p in cur)}")
            if gone:
                p = sorted(gone)[0]
                print(f"  removed example {p} exists on disk: {(root / p).exists()}")
                break
            prev = cur
    finally:
        srv.terminate()

    Run it: python3 repro.py

  2. Dante-dan commented on Oct 13, 2026

    @Dante-dan
    Contributor

    I’ll keep the bounded non-Git scan and expose when its search index is incomplete, so callers can distinguish missing matches from a truncated inventory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions