Skip to content

fs: fff live index misses new empty directories and directories without direct files #67316

Backlog

Description

@pewpil

Summary

In a Git project using the fff file search backend, directories created after the project has been indexed are missing from @ completion when they contain no direct files. Empty directories never appear. A directory that contains only subdirectories also stays missing even when a file is created deeper inside it: only the file's immediate parent directory is added.

A fresh server, or a location the server has not indexed before, returns all of these directories correctly. Restarting the server makes them appear. The TUI @ picker reads /api/fs/find directly, so it has no entry for these directories.

Environment

  • opencode version: 2.4.3 (latest; also reproduced on 2.4.2)
  • Client: TUI; verified against opencode serve and the running background service
  • Model and provider: Not relevant
  • OS: Linux 6.18.65-1-lts (x64)
  • Terminal: alacritty, TERM=alacritty, COLORTERM=truecolor
  • Shell: /usr/bin/bash
  • Install/channel: latest release (/usr/bin/opencode, v2.4.2; v2.4.3 release binary used for the latest verification)
  • Active plugins: None found

Reproduction

  1. Create a Git repository and start OpenCode with fff available:

    mkdir -p /tmp/oc-fff-repro && cd /tmp/oc-fff-repro
    git init
    mkdir -p deep/sub && touch deep/sub/file.txt
    opencode serve --port 4099

    opencode serve prints a local URL and password. Export the password before using the API commands below:

    export OPENCODE_PASSWORD=<password printed by opencode serve>
  2. Query the API once to initialize the location's fff picker:

    opencode api --server http://127.0.0.1:4099 GET '/api/fs/find?query=deep&limit=20'

    The result includes deep/, deep/sub/, and deep/sub/file.txt.

  3. While the server is still running, create a new empty directory and a new directory that contains only a subdirectory with a file:

    mkdir -p newempty newdeep/sub
    touch newdeep/sub/file.txt
  4. Query the new directories:

    opencode api --server http://127.0.0.1:4099 GET '/api/fs/find?query=newempty&limit=20'
    opencode api --server http://127.0.0.1:4099 GET '/api/fs/find?query=newdeep&limit=20'

    Actual results:

    {"data":[]}
    {"data":[{"path":"newdeep/sub/file.txt","type":"file"},{"path":"newdeep/sub/","type":"directory"}]}

    newempty/ is absent, and newdeep/ is absent even though its child directories and file were indexed.

  5. Stop and restart opencode serve on the same repository, then repeat the queries from step 4. Both newempty/ and newdeep/ are returned, the same way the initial deep/ query returned deep/.

  6. In the TUI, typing @newempty or @newdeep shows no matching directory, so neither directory can be selected.

Creating a file directly inside newempty/ makes newempty/ appear on the next query, and it stays indexed after that file is removed:

touch newempty/file.txt   # query now returns newempty/ and newempty/file.txt
rm newempty/file.txt      # newempty/ remains

Expected Behavior

Every directory that exists in the location should be available in @ completion, regardless of whether it contains files or only subdirectories. Creating a directory while the server is running should make it mentionable without restarting the server.

Actual Behavior

  • A newly created empty directory is never added to the live fff index.
  • A newly created directory that contains only subdirectories is not added; only the immediate parent of a newly indexed file is added (newdeep/sub/), not all of its ancestors (newdeep/).
  • The TUI @ picker consumes /api/fs/find directly, so these directories cannot be mentioned.
  • Restarting the server, or using a fresh location, returns the missing directories, which shows the initial scan handles them correctly and the incremental update is the failing part.

Additional Context

Activity

  1. added
    area/core
    type/bug
    version/v2
    on Nov 30, 2026
  2. opencodejr commented on Nov 30, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced this on the released 2.4.3 CLI through opencode serve, following your steps:

    1. In a git repo containing deep/sub/file.txt, I queried /api/fs/find?query=deep, which returned deep/, deep/sub/ and the file.
    2. With the server still running, I ran mkdir -p newempty newdeep/sub && touch newdeep/sub/file.txt.
    3. Querying newempty did not return newempty/. Querying newdeep returned only newdeep/sub/ and newdeep/sub/file.txt, without newdeep/.
    4. After restarting the server, both directories were returned.

    It still happens on the latest dev (88b03b9), run from source. The script below reproduces it against the API.

    Related: #60293 (empty directories missing from the ripgrep backend, open PR #60450) and #61640 (the project root missing from @/, open PR #61758).

    Reproduction script (repro.sh)
    #!/bin/sh
    # Reproduces #67316: fff live index misses new empty dirs and dirs without direct files.
    # Usage: sh repro.sh            (uses `opencode` from PATH)
    #        OC="bun ... /path/to/packages/cli/src/index.ts" sh repro.sh  (from source)
    set -u
    OC=${OC:-opencode}
    PORT=${PORT:-4099}
    DIR=$(mktemp -d /tmp/oc-fff-repro.XXXX)
    export HOME=$(mktemp -d /tmp/oc-home.XXXX)
    export OPENCODE_PASSWORD=repro-secret
    cd "$DIR" && git init -q && mkdir -p deep/sub && touch deep/sub/file.txt
    $OC --version
    $OC serve --port $PORT > "$DIR.log" 2>&1 &
    PID=$!
    for i in $(seq 1 60); do grep -qi listening "$DIR.log" && break; sleep 1; done
    cat "$DIR.log"
    q() { echo "--- query=$1"; $OC api --server http://127.0.0.1:$PORT GET "/api/fs/find?query=$1&limit=20"; echo; }
    q deep; sleep 3; q deep
    mkdir -p newempty newdeep/sub && touch newdeep/sub/file.txt
    sleep 5
    q newempty; q newdeep
    kill $PID; wait $PID 2>/dev/null
    echo "=== restart"
    $OC serve --port $PORT > "$DIR.log" 2>&1 &
    PID=$!
    for i in $(seq 1 60); do grep -qi listening "$DIR.log" && break; sleep 1; done
    q newempty; sleep 3; q newempty; q newdeep
    kill $PID

    Run it: sh repro.sh

  3. archit15singh commented on Nov 30, 2026

    @archit15singh

    I reproduced this on macOS arm64 with OpenCode v2.4.3 and narrowed it to the fff dependency. In a standalone Git fixture, FileFinder.directorySearch() on fff 0.10.5 (OpenCode’s pin) and 0.11.0 included the immediate parent of a new file, but omitted both its ancestor and a new empty directory after 7 seconds. A fresh picker found both directories.

    Would you prefer an upstream fff fix followed by an OpenCode dependency update, or an OpenCode-side workaround? I can help with whichever route fits. Codex assisted with the reproductions and this comment.

  4. pewpil commented on Nov 30, 2026

    @pewpil
    Author

    Source-level follow-up on current dev (20c6a0a) with the pinned fff 0.10.5.

    The gap is in fff's live directory table, not in OpenCode's /api/fs/find call path:

    • fff's watcher queues a created directory only for watching (crates/fff-core/src/watcher/background_watcher.rs:478-481). index_new_directory then indexes files (:709-783) and returns early when the new subtree has no files (:764-766), without inserting the directory or its walked subdirectories into sync_data.dirs.
    • The only live path that adds a directory is FilePicker::add_new_file, which registers the new file's immediate parent (crates/fff-core/src/file_picker.rs:1693-1701), not its ancestors.
    • The initial scan builds the directory table from every walked directory (file_picker.rs:2180-2242), including empty subtrees and pure ancestors. That is why a restart or a fresh picker returns the missing directories.

    I reproduced this directly against clean fff v0.10.5:

    • new empty directory -> []
    • new directory whose only child is sub/file.txt -> ["sub/"] (the parent newdeep/ is absent)

    A minimal upstream patch that registers the new directory and its walked subdirectories/ancestors in index_new_directory makes both cases pass, and the existing 7 directory-index tests still pass in a temporary clone. An optional hardening is to have add_new_file register all ancestors, so a file event alone repairs a missed directory event. The fix then needs an fff release and a bump of both @ff-labs/fff-bun and @ff-labs/fff-node in OpenCode; the existing fff patch only changes ESM import specifiers and cannot carry the native fix.

    v0.10.6 and v0.11.0 retain the same watcher path, and main still has the early return. None of the related OpenCode PRs cover it: #60450 adds empty directories to the ripgrep layer, #61758 adds the root for the literal / query, #67279 changes fff selection for ignored locations, #65571 adds an exact-path probe, #62065 normalizes separators, and #65623 bounds cold ripgrep indexing. #33751 is the same symptom from v1 and was closed for inactivity, not fixed.

    Workaround remains: create a file directly in the missing directory, or restart the server so the initial scan rebuilds the directory table.

    I have not opened an upstream fff issue for this yet; the reproduction and patch above are from a temporary v0.10.5 clone and have not been reviewed by the fff maintainers.

  5. dkovalenko-oai commented on Dec 1, 2026

    @dkovalenko-oai

    looking

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

    area/coreplatform/linuxreproducedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions