fix: stop the scratch-name match from pruning user directories

Open Beginner friendly
#385 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
tooling

Research direction

Start at internal/indexdir/filter.go (besideStore, around lines 109-114), where the name-only strings.HasPrefix match lives, and check scratchdir.LockName for the content check to use instead. Then follow pruning in internal/indexer/discover/discoverexclusion.go:162-172 to see where the exclusion record is made. Reproduce with the mkdir/symlink steps in the issue; done means the user directory is indexed (or recorded with a reason) while real scratch dirs holding a .lock are still pruned, with a test under internal/indexdir.

Written by the indexing model from the issue text.

Description

area:indexer bug needs-triage
What happens

The index skips any directory whose name starts with the store name followed by .scratch-. A user directory with such a name is skipped too. Discovery prunes it with no exclusion record, so its files are missing from the index and no reason is reported. This follows PR #384, which introduces the name match in internal/indexdir/filter.go.

Reproduced on commit 375d8be6 of branch fix/index-path-links, built from source:

$ codegraph index --force repo
files=1 nodes=2 edges=1 duration=82ms

Only repo/main.go is indexed. repo/store-real.scratch-notes/a.go is absent.

The cause is besideStore in internal/indexdir/filter.go:109-114. It matches a scratch directory by strings.HasPrefix on the name alone. DiscoverAll then prunes the matching directory before it makes any record (internal/indexer/discover/discoverexclusion.go:162-172).

What you expected instead

A directory that codegraph did not create is indexed as source, or it gets an exclusion record with a reason. Only a real scratch directory is pruned.

The match must check the content of the directory, such as its lock file .lock (scratchdir.LockName), and not the name alone. A scratch name ends in a random suffix, so the name cannot tell a scratch directory from a user directory.

Steps to reproduce
  1. Run mkdir -p repo/.codegraph repo/store-real repo/store-real.scratch-notes.
  2. Run ln -s ../store-real repo/.codegraph/store.
  3. Write package a to repo/store-real.scratch-notes/a.go, and package main to repo/main.go.
  4. Run codegraph index --force repo. Only one file is indexed.
Version

codegraph dev (commit unknown, built unknown) go1.26.11 darwin/arm64, built from 375d8be6.

Platform

macOS 27.2.1 arm64

How did you install it?

Built from source

Languages in the affected repository

Go. The bug depends on directory names, not on the language.

Before submitting
  • I searched existing issues and this is not a duplicate
  • I checked the capability matrix and this is not a documented limitation
  • This is not a security vulnerability
Dominant language
Go
Stars
0
Forks
0
Avg merge
5h 16m
Merged PRs (30d)
107

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from seanb4t/codegraph-go

All issues in seanb4t/codegraph-go

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.