Skip to content

fix(core): share fff engine per directory - #52964

Closed
Shalin-Shah-2002 wants to merge 1 commit into
anomalyco:devfrom
Shalin-Shah-2002:share-fff-engine
Closed

Shalin-Shah-2002 wants to merge 1 commit into
anomalyco:devfrom
Shalin-Shah-2002:share-fff-engine

Conversation

@Shalin-Shah-2002

@Shalin-Shah-2002 Shalin-Shah-2002 commented Oct 3, 2026 •

Copy link
Copy Markdown

Issue for this PR

Fixes #50966

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Each fffLayer build calls Fff.create({ basePath }), and every engine owns its own file index and inotify watcher. LocationServiceMap.reload() boots the replacement graph while running sessions still borrow the old one, so for the same directory the old and new graph each hold an engine. The kernel doesn't dedupe watches across inotify instances, so the watch count and the in-memory index double.

fffLayer now keeps a module-level map of engines by directory. A build reuses the engine for its directory and bumps a user count, and the finalizer only destroys the engine when the last user closes. Engine options are constants, so sharing doesn't change behavior. I did not touch LocationServiceMap.canonical; refs that resolve to the same directory through a symlink would still get separate engines.

How did you verify your code works?

Added packages/core/test/location-search.test.ts:

  • Holds a borrowed graph for a git directory, calls LocationServiceMap.reload(), and asserts one live engine for that directory. Before the change it fails with 2 live engines; after, it passes.
  • Builds fffLayer twice for one directory and asserts the engine survives closing the first scope and is destroyed when the second closes.

bun test for test/filesystem/search.test.ts, test/location-layer.test.ts, test/location-filesystem.test.ts and the new file: 41 pass. The full packages/core suite has the same 41 failures with and without this change (Ripgrep and ShellTool tests; no rg binary and no native tree-sitter build in my environment). bun run typecheck in packages/core is clean. (An earlier run showed 3 errors in src/plugin/command.ts; they came from stale dependencies in my checkout and are gone after bun install.)

I could only measure this on macOS, not by counting inotify watches on Linux as the issue does.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_01HfXsWoKF5h7tmdmyUEw1rD

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@connor-grady

Copy link
Copy Markdown

#50966 was closed as a v1 issue; the v2 report is #54631, where the duplicate engine was reproduced. On dev at 707de58 a second engine exists while a session step is still running after /reload (case 1 there), which is what this PR collapses. The permanent leak on v2 releases (case 2) is already gone on dev, since [email protected] compares RcMap entries by identity. Changing Fixes #50966 to Fixes #54631 would close the open report on merge.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple fff engines per process watch the same base path, multiplying inotify watches 2-3x

2 participants