Repository navigation
Get sync git and gh off the main-process event loop (fixes #124 beachballs) - #229
Merged
currentbits merged 12 commits intoAug 17, 2026
Merged
Conversation
JSON.stringify of the live store is ~58ms (53MB, 226 threads), so a
250ms debounce under concurrent streams spends a quarter of the event
loop just serializing. Double the delay on each dirty flush up to 2s
and reset when quiet. saveNow stays sync for process.on('exit').
CODER_LOOP_LAG=1 turns on perf_hooks.monitorEventLoopDelay and logs
mean/p50/p99/max every 5s. Off by default, no histogram created.
Concurrent agent threads beachballed because git status/fetch/pull and addProject ran execFileSync on the Electron main process. Add execCommandAsync next to the existing sync execCommand (worktrees.js still needs the sync export) and await it from the services git helpers.
…into coder/app-beachballs-when-multiple-threads-run-4e7132
…ball diff() and listFiles() were still calling execFileSync on the main process (bounded at 15s by #88). With several agent runs streaming at once those reads queued every other thread behind them. Convert only the hot read paths to execFile. Write actions (merge, push, PR, setup) stay sync. gitTryAsync now carries the sync error field and treats async SIGTERM kills as timeouts.
) git:syncInfo, git:repoInfo and git:pull document "never throws" and answer in-band. Once services.gitSyncInfo & co. became async, `return fn(root)` inside their try/catch settled the promise outside the try, so the catch could no longer see a rejection. Nothing fails today because those functions catch their own errors, which is exactly why this needed pinning before a future throw path makes it a live bug. Co-Authored-By: Claude Opus 5 <[email protected]>
… Stopping a run leaves agent grandchildren alive (no process-
…124) defaultWhich is execFileSync on the main-process event loop and runner.js calls it on every run start, uncached, so concurrent runs each paid a PATH walk. Cache hits only: a miss stays uncached so installing a provider CLI while the app is open still works without a restart. Memoised rather than made async — a cached lookup is both faster than an async spawn and a far smaller diff than the caller cascade. Co-Authored-By: Claude Opus 5 <[email protected]>
Planboard and PR status/list/checks were still calling execFileSync gh with a 30s timeout on the main process. Route those through the existing ghTryAsync helper so a hanging GitHub call cannot beachball every window.
…into coder/app-beachballs-when-multiple-threads-run-4e7132 # Conflicts: # electron/main.js
W4 converted the hot read paths but left createPr and mergePr on sync gh because write paths were scoped out. That left a 30s network call able to freeze every window and every streaming thread on a single click, which is the reported bug — so finish it. mergePr was already async (3 awaits). createPr becomes async; its local git (push/defaultBranch/gitTry) stays sync, still bounded at 15s by #88 — the 30s NETWORK calls were the point. With no callers left, sync ghTry is deleted rather than left as a landmine, and worktrees.js no longer imports execFileSync at all. Co-Authored-By: Claude Opus 5 <[email protected]>
Runs the issue's own repro against the real stack — real Electron main process, real Store/runner/registerIpc, real preload bridge in a real BrowserWindow — with N concurrent CODER_SIMULATE runs (free, no network) while hammering git:diff / git:status / files:list / git:syncInfo from the renderer. Main process measures its own loop lag with the same perf_hooks histogram CODER_LOOP_LAG uses. Measured across the branch point, 4 threads / 15s / ~596 git IPC calls: before: lag p99 63.4ms, max 149.3ms, STARVED 60.4% after: lag p99 2.0ms, max 33.6ms, STARVED 3.5% At 8 threads: 60.7% -> 5.0%. Sustained starvation is the beachball, and it is gone. Isolated ~60-90ms spikes remain, consistent with the whole-store JSON.stringify (#225). Co-Authored-By: Claude Opus 5 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…when-multiple-threads-run-4e7132 # Conflicts: # electron/main.js
currentbits
pushed a commit
that referenced
this pull request
Aug 17, 2026
…remainder origin/main (#229) finished the sync-gh work this branch had duplicated, so the overlapping half is dropped in favour of main's. What survives is exactly what #228 asked for and main still does not have: resolveThreadGit and the project default-branch lookup off sync git on the PR read paths.
currentbits
deleted the
coder/app-beachballs-when-multiple-threads-run-4e7132
branch
October 3, 2026 16:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #124. With several agent threads streaming at once, the whole app intermittently froze with a macOS beachball. Every synchronous
execFileSynccall in the Electron main process blocks all streaming and all windows for its full duration, so N concurrent runs plus IPC traffic queued behind whichever one was blocking.Measured, before and after
electron/beachball.js(added here,npm run beachball) runs the issue's own repro against the real stack — real Electron main process, realStore/createRunner/registerIpc, real preload bridge in a realBrowserWindow— with N concurrentCODER_SIMULATE=1runs (free, no network) while the renderer hammersgit:diff,git:status,files:listandgit:syncInfoover real IPC. The main process measures its own event-loop lag with the sameperf_hookshistogram the newCODER_LOOP_LAGprobe uses, against a 10ms heartbeat. Missed heartbeats are the beachball: while the loop is blocked nothing paints and no stream is serviced.Run on a worktree at this branch's merge-base (none of this work in it) and on this branch. Same machine, same workload, ~596 git IPC calls each.
4 concurrent runs, 15s
8 concurrent runs, 15s: 60.7% → 5.0% starved, p99 63.1ms → 2.0ms.
Before the fix the main process missed three of every five heartbeats for fifteen seconds straight. It also no longer degrades with thread count — sync lag scaled 18.7 → 31.3 → 53.7ms p99 at 2/4/8 threads, async stays flat at 1.1–3.8ms.
What changed
Async git (
ssh.js,services.js,worktrees.js). #88 bounded sync git at 15s but explicitly deferred the async conversion. AddedexecCommandAsyncalongside the existing syncexecCommand, and convertedgitStatus/gitSyncInfo/gitRepoInfo/gitFetch/gitPull/addProject/createProject, plus theworktrees.jshot reads: thediff HEADpath behindgit:diff, andlistFiles/lsFilesbehind the@-mention autocomplete — which fired a synchronousgit ls-fileson every keystroke.Async
gh— the biggest offender, and not in the original issue's list.worktrees.jshad a syncghTrycallingexecFileSync(ghBin(), ...)withGH_TIMEOUT_MS = 30_000.ghis a network call, so one slow GitHub request froze every window and every streaming thread for up to 30 seconds — three orders of magnitude worse than the local git this issue was opened about. It was reachable from six IPC handlers, including theissues.jsplanboard ones that agents hit while other threads stream. Everything now routes through the pre-existingghTryAsync, and syncghTryis deleted rather than left as a landmine;worktrees.jsno longer importsexecFileSyncat all.Store flush backoff + lag probe (
store.js,looplag.js). Measured first rather than assumed:JSON.stringifyof the live store is ~58ms, becausecoder-store.jsonon a real install is 54MB — 97% of itmessagesByThreadacross 227 threads. #89's per-thread caps work correctly; the store is simply linear in thread count, which no per-thread cap can bound. At a 250ms debounce under concurrent streams that spent a quarter of the event loop serializing. The debounce now backs off 250ms → 2s while dirty and resets when quiet.CODER_LOOP_LAG=1enablesperf_hooks.monitorEventLoopDelay()and logs mean/p50/p99/max every 5s, off by default with no histogram created when unset.whichmemoisation (providers.js).runner.jscalleddefaultWhichon every run start, uncached, so N concurrent runs paid NPATHwalks. Hits are cached; misses deliberately are not, so installing a provider CLI while the app is open still works without a restart. Memoised rather than made async — a cache hit beats an async spawn and avoids the caller cascade.A latent bug fixed and pinned (
ipc.js).git:syncInfo,git:repoInfoandgit:pulldocument "never throws" and answer in-band. They were written asreturn services.gitFoo(root)inside atry/catch; once those functions became async the returned promise settles outside the try, so the catch could no longer see a rejection. Nothing fails today only because those functions catch their own errors — which is exactly why it needed pinning before a future throw path makes it live. Fixed withreturn await, pluselectron/test/ipc-async-guard.test.js, verified to fail 3/3 with theawaits removed.Tradeoffs and deliberate remainders
saveNow()stays synchronous on purpose (process.on('exit')cannot await) with a comment saying so.setupWorktree,mergeWorktree,push,commit,revertFile,cleanupWorktree) — once per deliberate click, still bounded at 15s by Synchronous git on the main-process event loop with no default timeout #88. Marked in-file with aponytail:comment.createPr/mergePrhad their gh converted because 30s network calls were the actual risk; their local git is untouched.messagesByThread, Sync local git remains in resolveThreadGit / defaultBranch on the PR read paths #228 residual sync local git inresolveThreadGit/defaultBranchon the PR read paths.Testing
electron 859/860, renderer 723/723, core 38/38,
tsc --noEmitclean.The one electron failure is
wireClient × webBridge over a real socket, a pre-existing port-allocation flake under parallel runs that passes 18/18 when its file runs alone. Present on main before this work.New tests:
ipc-async-guard.test.js,which-cache.test.js,gh-async.test.js,looplag.test.js, plus additions to the store, services and worktrees suites. The two I wrote myself I verified fail without their fix.Note for anyone testing in a worktree: clone deps with
cp -Rcfrom the main checkout rather thannpm install, and runcd core && npm run buildfirst —npm run test:electronneeds a builtcore/distor ~140 tests fail on a missing module.PR created by the Claude Code agent