Skip to content

fix(git): stop git process overflow#2223

Merged
jonathanlab merged 2 commits into
mainfrom
posthog-code/fix-git-status-leak
May 19, 2026
Merged

fix(git): stop git process overflow#2223
jonathanlab merged 2 commits into
mainfrom
posthog-code/fix-git-status-leak

Conversation

@jonathanlab
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab commented May 19, 2026

lets batch incoming untracked changes instead of spawning a new git process for each one

…her invalidations

Forward AbortSignal through the tRPC read procedures and GitService methods
into the underlying queries package, so TanStack Query refetches and unmounts
actually kill the spawned `git status --untracked-files=all` child process
(streamGitStatus already wires SIGTERM on abort, but never received the
signal). Debounce git working-tree invalidations from useFileWatcher at
500ms so a burst of file events (worktree setup, node_modules churn, large
merges) collapses into one refetch instead of stacking dozens of concurrent
git processes.

Generated-By: PostHog Code
Task-Id: 8b1baf87-a02c-4bbc-bf41-c6267dac1846
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/hooks/useFileWatcher.ts:36-43
The timer cleanup effect has an empty dependency array, so it only runs on unmount. If `repoPath` changes while a 500 ms timer is pending, the old-path timer is not cancelled and will fire ~500 ms later calling `invalidateGitWorkingTreeQueries` with the stale path. Because there are no active query observers for that old path, TanStack Query won't refetch, so no git process is spawned — but adding `repoPath` to the deps array gives cleaner semantics and avoids the unnecessary invalidation entirely.

```suggestion
  useEffect(() => {
    return () => {
      if (gitInvalidateTimerRef.current) {
        clearTimeout(gitInvalidateTimerRef.current);
        gitInvalidateTimerRef.current = null;
      }
    };
  }, [repoPath]);
```

Reviews (1): Last reviewed commit: "fix(git): cancel superseded git status q..." | Re-trigger Greptile

Comment thread apps/code/src/renderer/hooks/useFileWatcher.ts Outdated
…vent

Move the debounce from the renderer into the file-watcher service. The
service already debounces events at 500ms; emit a single
WorkingTreeChanged event per flush so the renderer invalidates git
queries once per burst instead of once per file event.

Generated-By: PostHog Code
Task-Id: 8b1baf87-a02c-4bbc-bf41-c6267dac1846
@jonathanlab jonathanlab changed the title fix(git): stop git process pile-up from un-cancellable status queries fix(git): stop git process overflow May 19, 2026
@jonathanlab jonathanlab added the Create Release This will trigger a new release label May 19, 2026
@jonathanlab jonathanlab merged commit 2c4a54d into main May 19, 2026
15 checks passed
@jonathanlab jonathanlab deleted the posthog-code/fix-git-status-leak branch May 19, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Create Release This will trigger a new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants