Skip to content

fix(git): stop leaking fsmonitor daemons e.g. 60GB+ of commited memory after running tests#16249

Merged
Hona merged 4 commits intoanomalyco:devfrom
Hona:fix/git-fsmonitor-cleanup
Mar 6, 2026
Merged

fix(git): stop leaking fsmonitor daemons e.g. 60GB+ of commited memory after running tests#16249
Hona merged 4 commits intoanomalyco:devfrom
Hona:fix/git-fsmonitor-cleanup

Conversation

@Hona
Copy link
Member

@Hona Hona commented Mar 6, 2026

Summary

  • disable fsmonitor in opencode-owned temp git repos and stop any daemon before test, e2e, and worktree cleanup removes those directories
  • make opencode's readonly git status and diff checks opt out of fsmonitor so dirty-state reads do not start detached background daemons in user repos
  • add regression coverage for fixture cleanup, readonly git checks, and worktree removal on Windows

Testing

  • bun test test/fixture/fixture.test.ts test/file/fsmonitor.test.ts test/file/index.test.ts test/project/worktree-remove.test.ts

@Hona Hona requested a review from adamdotdevin as a code owner March 6, 2026 01:09
Copilot AI review requested due to automatic review settings March 6, 2026 01:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents Git fsmonitor daemons from being spawned/leaked by opencode’s temporary repos, readonly git checks, and worktree cleanup—especially on Windows.

Changes:

  • Disable core.fsmonitor in opencode-owned temp git repos and stop any running daemon before removing git directories.
  • Force readonly git operations (status, diff, ls-files, show) to opt out of fsmonitor via git -c core.fsmonitor=false ....
  • Add Windows-focused regression tests covering fixture cleanup, readonly git checks, and worktree removal behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/opencode/src/file/index.ts Opt out of fsmonitor for readonly git diff/status-related commands.
packages/opencode/src/worktree/index.ts Stop fsmonitor daemon before worktree removal; opt out during reset dirty-check.
packages/opencode/test/fixture/fixture.ts Disable fsmonitor in git fixtures; ensure daemon stop + retrying cleanup on dispose.
packages/opencode/test/fixture/fixture.test.ts Regression tests for fsmonitor-disabled fixtures and disposal cleanup.
packages/opencode/test/file/fsmonitor.test.ts Windows-only tests asserting readonly git checks don’t start fsmonitor.
packages/opencode/test/project/worktree-remove.test.ts Adds Windows-only test for stopping fsmonitor before worktree removal.
packages/app/e2e/actions.ts Disable fsmonitor in e2e git repo creation; stop daemon + retrying rm on cleanup.
Comments suppressed due to low confidence (1)

packages/opencode/test/project/worktree-remove.test.ts:24

  • The first test in this file uses Unix-specific tooling (which git, a #!/bin/bash shim, and chmod) but it is not skipped on Windows. Since this PR adds Windows-specific coverage in the same suite (wintest), running the whole file on Windows will likely fail. Either skip that regression test on win32, or make the shim cross-platform (e.g., where git + a git.cmd wrapper on Windows).
const wintest = process.platform === "win32" ? test : test.skip

describe("Worktree.remove", () => {
  test("continues when git remove exits non-zero after detaching", async () => {
    await using tmp = await tmpdir({ git: true })
    const root = tmp.path
    const name = `remove-regression-${Date.now().toString(36)}`
    const branch = `opencode/${name}`
    const dir = path.join(root, "..", name)

    await $`git worktree add --no-checkout -b ${branch} ${dir}`.cwd(root).quiet()
    await $`git reset --hard`.cwd(dir).quiet()

    const real = (await $`which git`.quiet().text()).trim()
    expect(real).toBeTruthy()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Hona Hona marked this pull request as draft March 6, 2026 01:14
@Hona Hona changed the title fix(git): stop leaking fsmonitor daemons fix(git): stop leaking fsmonitor daemons e.g. 60GB+ of commited memory Mar 6, 2026
@Hona Hona changed the title fix(git): stop leaking fsmonitor daemons e.g. 60GB+ of commited memory fix(git): stop leaking fsmonitor daemons e.g. 60GB+ of commited memory after running tests Mar 6, 2026
@Hona Hona marked this pull request as ready for review March 6, 2026 05:41
@Hona Hona merged commit aec6ca7 into anomalyco:dev Mar 6, 2026
11 checks passed
jerome-benoit pushed a commit to jerome-benoit/opencode that referenced this pull request Mar 6, 2026
qdddddd pushed a commit to qdddddd/opencode that referenced this pull request Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants