Skip to content

Cap automation threads at the newest 20 per automation (#134) - #216

Merged
currentbits merged 2 commits into
mainfrom
coder/automations-mint-a-new-thread-on-every-f-9a04e0
Aug 17, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/automations-mint-a-new-thread-on-every-f-9a04e0

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #134.

Why

runAutomation called services.createThread() on every fire and nothing ever removed those threads. One hourly automation mints ~24 threads/day, ~8,700/year, each with its own transcript in the single-JSON store — and every debounced save re-stringifies the whole blob. Nothing here needs user action, so the store grew monotonically for a user who deletes nothing. store.js had per-thread caps (MAX_MESSAGES_PER_THREAD, MAX_WORKLOG_ITEMS_PER_THREAD) but no cap on the number of threads.

What changed

  • electron/services.js — createThread accepts an optional automationId and stamps it on the thread (null on hand-made threads). No store migration: migrateThread spreads ...t, so the field survives load and is simply absent on old rows.
  • electron/automations.js — runAutomation tags the thread it mints with auto.id and, after startRun settles, prunes that automation's threads down to the newest MAX_THREADS_PER_AUTOMATION (20) via services.purgeThread, which also drops the thread's messagesByThread / workLogByThread / usage entries.
    • Never purges a thread that is working, worktree-backed, or pinned. Skipped threads still occupy a keep slot, so the cap is not silently exceeded to compensate.
    • The prune runs after the run in its own try/catch: a retention failure cannot stamp lastError or fail the fire.
    • threads:changed is broadcast at thread creation as before (a long run should not leave its thread invisible in the sidebar) and again after the prune so deleted rows disappear.

Tests

Four cases added to electron/test/automations.test.js: the cap holds and keeps the newest threads, purged transcripts are gone from messagesByThread, live/pinned/worktree threads survive, and other automations plus hand-made threads are untouched.

npm run test:electron 805/806, npm run test:renderer 716/716, npm run typecheck clean. The single electron failure (wireClient x webBridge over a real socket) fails on main too and is unrelated.

Deliberately not done

No settings knob for the retention number and no global thread-count cap. An audit of every other programmatic thread-minting path found one more unbounded case — orchestrator fork threads are archived but never deleted — tracked separately in #213.

🤖 Generated with Claude Code

  • PR created by the Claude Code agent

Willem and others added 2 commits August 17, 2026 08:47
Automation fires mint a new thread each time with no cleanup.
Stamp automationId on createThread and purge older ones after
each run, skipping live, pinned, and worktree threads.
The retention commit moved the only threads:changed broadcast past
startRun, so a long automation run left its thread invisible in the
sidebar until it finished. Broadcast at creation as before, and again
after the prune so deleted rows disappear.

Co-Authored-By: Claude Opus 5 <[email protected]>
@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 ca75470 into main Aug 17, 2026
1 check failed
@currentbits
currentbits deleted the coder/automations-mint-a-new-thread-on-every-f-9a04e0 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.

Automations mint a new thread on every fire; the store grows without bound

1 participant