Skip to content

Retain only the last 20 worker threads per orchestrator (#213) - #328

Merged
currentbits merged 1 commit into
mainfrom
coder/orchestrator-worker-threads-are-never-de-539a7e
Aug 17, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/orchestrator-worker-threads-are-never-de-539a7e

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #213.

Why

services.forkWorkerThread mints a thread plus empty messagesByThread / workLogByThread keys on every fork, and finished workers were only ever archived (sweepCrew in electron/runner.js), never deleted. An 8-worker fan-out is a normal pattern here, so one orchestrated session per weekday works out to roughly 1,000-2,000 leftover worker threads a year, each carrying its own transcript. Same store-blob pressure as #134 and #124, just slower.

What changed

Retention now runs inside sweepCrew — the one function both worker-minting paths (orchServer's thread_fork tool and the runner's pendingFork dispatch) already settle through, since both go via services.forkWorkerThread and inherit orchWorker + handoffFrom. That provenance was enough to identify workers, so no new field was added.

MAX_WORKERS_PER_ORCHESTRATOR = 20, newest-first with an insertion-index tie-break for same-millisecond forks — the same shape as pruneAutomationThreads landed for #134. A worker is deleted via the existing services.purgeThread (which drops the thread with its messages, work log and usage) only when all of these hold:

  • status is done / failed / stopped — never an idle, queued or in-flight thread
  • no live run in the runner's active map
  • no worktreePath
  • no pinnedAt

Skipped threads still occupy a keep slot, matching #134. The worktreePath guard is not a permanent exemption: worktrees.js clears it on merge or remove, so an integrated worker becomes prunable on the next sweep.

Tests

Three cases in electron/test/orchestrator-threads.test.js, covering the cap (with the purged threads' messagesByThread entries verified gone), the working / worktree'd / pinned skips, and non-interference with hand-made threads and a second orchestrator's crew. They drive the prune through createRunner's boot sweep so they exercise the shipped sweepCrew rather than a copy of the logic.

npm run test:electron: 901 of 902 pass. The single failure is the pre-existing web-integration.test.js reconnect baseline on main, not this change.

Deliberately out of scope

  • Filtering archived workers out of listThreads / threadSummaries. Capping the crew at 20 caps what those return; worth its own issue if the list still reads as noisy.

  • Nested crews: purging a worker that itself orchestrated a crew orphans that crew's handoffFrom. sidebarGroups already tolerates an absent source and the nested crew carries its own cap, so those transcripts survive until their own orchestrator sweeps.

  • PR created by the Claude Code agent

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 95c3bff into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/orchestrator-worker-threads-are-never-de-539a7e branch October 3, 2026 16:07
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.

Orchestrator worker threads are never deleted, only archived

1 participant