Relationships
#3738 Source glob expansion crashes when a directory under the glob parent disappears mid-walk
Opened by stack72 · 10/21/2026· Shipped 10/21/2026
What happens
expandSourcePaths (src/infrastructure/persistence/swamp_sources_repository.ts) expands glob sources such as ~/code/* with @std/fs expandGlob. The std walk lists the parent with readDir, then calls Deno.stat on each directory entry it recurses into. If another process removes that directory between the listing and the stat, expandGlob throws NotFound and the whole command fails.
Home directories regularly hold short-lived lock directories (Claude Code's .claude.json.lock is one), so a user whose source glob sits directly under ~ can hit this at random.
Where it is reachable
expandSourcePaths is called from src/cli/repo_context.ts, src/cli/mod.ts, src/libswamp/extensions/reconcile_from_disk_service.ts and src/libswamp/sources/add.ts, list.ts and remove.ts, so it runs during repo-context setup as well as in the source commands.
Reproduction
Point a source glob at a directory where a script keeps creating and removing directories (mkdir/rmdir of a few thousand lock dirs in a loop). Found while triaging swamp-club#3694, where the same race made extension_source_add_test fail 10 of 10 runs under that churn.
Expected
An entry that disappears during expansion is skipped (it no longer exists, so it cannot be a source), and expansion keeps going instead of failing the command.
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.