You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Orchestrator worker threads are never deleted, only archived #213
Spun out of #134 (audit of every programmatic thread-minting path).
Problem
thread_fork (electron/orchServer.js:245 → services.forkWorkerThread, services.js:731 → createThread) mints a thread plus empty messagesByThread / workLogByThread keys on every fork. The coder-threads server is folded into every provider (orchServer.js:571), so any in-app agent can fork.
Finished workers are only archived (runner.js:685), never deleted. thread_send can unarchive and reuse one (orchServer.js:274) but nothing requires reuse, and listThreads / threadSummaries return archived threads too (services.js:1093).
Same shape at runner.js:3434 (pendingFork): a thread created with orchestrate: true mints one worker on first run; failed setup deletes the orphan (runner.js:3460), success leaves it forever.
Impact
An 8-worker fan-out is an expected pattern (runner.js:313). One orchestrated session per weekday x 4-8 forks is roughly 1,000-2,000 leftover worker threads a year, each with its own transcript. Same store-blob pressure as #134 and #124, just slower.
Fix direction
Retention for settled worker threads, in the spirit of the per-automation cap landed for #134 (automationId tag + keep newest N, skipping working / worktree'd / pinned threads). Worker threads already carry handoffFrom provenance, so they are identifiable without a new field.
Fixed in 752f647 on branch coder/orchestrator-worker-threads-are-never-de-539a7e (not yet on main).
Retention lives in sweepCrew (electron/runner.js) — the one function both worker-minting paths already settle through, so thread_fork and the runner's pendingFork shape are covered by the same 22 lines. MAX_WORKERS_PER_ORCHESTRATOR = 20, newest-first with insertion-index tie-break, mirroring pruneAutomationThreads from #134. A worker is deleted (services.purgeThread, which drops the transcript and work log too) only when its status is done/failed/stopped, it has no live run, no worktreePath, and no pinnedAt; skipped threads still occupy a keep slot.
No new field was needed — orchWorker + handoffFrom already identify workers, as the issue predicted. The worktreePath guard is not a permanent exemption: worktrees.js clears it on merge/remove, so an integrated worker becomes prunable on the next sweep.
Tests: 3 cases in electron/test/orchestrator-threads.test.js, driven through createRunner's boot sweep so they exercise the shipped sweepCrew rather than a copy. npm run test:electron: 901/902 pass, the 1 failure being the pre-existing web-integration reconnect baseline.
Left out deliberately: filtering archived workers from listThreads/threadSummaries. Capping the crew at 20 caps what those return; worth its own issue if the list still feels noisy.
Known ceiling: purging a worker that is itself an orchestrator of a nested crew orphans that crew's handoffFrom (the sidebar already tolerates an absent source, and the nested crew has its own cap), so those transcripts survive until their own orchestrator sweeps.
Activity
currentbits commentedon Aug 17, 2026
Fixed in
752f647on branchcoder/orchestrator-worker-threads-are-never-de-539a7e(not yet on main).Retention lives in
sweepCrew(electron/runner.js) — the one function both worker-minting paths already settle through, sothread_forkand the runner'spendingForkshape are covered by the same 22 lines.MAX_WORKERS_PER_ORCHESTRATOR = 20, newest-first with insertion-index tie-break, mirroringpruneAutomationThreadsfrom #134. A worker is deleted (services.purgeThread, which drops the transcript and work log too) only when its status is done/failed/stopped, it has no live run, noworktreePath, and nopinnedAt; skipped threads still occupy a keep slot.No new field was needed —
orchWorker+handoffFromalready identify workers, as the issue predicted. TheworktreePathguard is not a permanent exemption:worktrees.jsclears it on merge/remove, so an integrated worker becomes prunable on the next sweep.Tests: 3 cases in electron/test/orchestrator-threads.test.js, driven through
createRunner's boot sweep so they exercise the shippedsweepCrewrather than a copy.npm run test:electron: 901/902 pass, the 1 failure being the pre-existing web-integration reconnect baseline.Left out deliberately: filtering archived workers from
listThreads/threadSummaries. Capping the crew at 20 caps what those return; worth its own issue if the list still feels noisy.Known ceiling: purging a worker that is itself an orchestrator of a nested crew orphans that crew's
handoffFrom(the sidebar already tolerates an absent source, and the nested crew has its own cap), so those transcripts survive until their own orchestrator sweeps.Merge pull request #328 from currentbits/coder/orchestrator-worker-th…