Skip to content

Poll archived worker PRs and wake their lead; never reclaim a running worktree (#1431) - #1607

Merged
currentbits merged 1 commit into
mainfrom
coder/pr-refresh-archived-workers-1431
Oct 12, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/pr-refresh-archived-workers-1431

Conversation

@currentbits

@currentbits currentbits commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1431.

Why

sweepCrew archives finished workers while their PRs are still open, and the background PR refresher skipped archived threads (if (t.archived) return false). Worker PRs therefore stayed OPEN in the store forever, their worktrees were never reclaimed, and the PR watch never saw them. In the live store, 23 archived rows with a PR number are still non-terminal, and every Solenta PR I checked among them is actually merged on GitHub.

Separately, maybeCleanupMergedWorktree checked for a dirty tree but not for a live run. A worker with a clean tree could lose its checkout mid-run when its PR merged.

What

Most of the issue's design had already shipped as electron/prWatch.js (#1493 D), so this PR is small.

  • Poll archived threads. isPrRefreshCandidate keeps archived threads. Terminal states still drop out, so each one costs polls only until it merges or closes.

  • Wake the lead, not the archived worker. New prWatch.wakeTarget() decides who a PR alert goes to:

    • a thread that isn't archived: itself, as before;
    • an archived worker: its live lead;
    • an archived non-worker, or a worker whose lead is archived or trashed: nobody (state refresh only).

    The relayed line names the worker and ends with "Send it the fix with thread_send (threadId …); merging stays with the user." Wake state and the 3-wake cap stay on the worker.

  • Never reclaim a running worktree. maybeCleanupMergedWorktree refuses while the thread is working or quota-wait and queues it. The next refresher pass retries it without calling gh, because a MERGED thread has already left the candidate set. The guard covers the refresher and the in-app merge path alike.

Checked

  • A merge settles a thread from its PR state alone (src/threadSettle.ts), not from a message timestamp. [pr watch] turns can't block settling.
  • Upgrade burst, from a read-only scan of the live store:
    • none of the 23 archived rows has prWatchState, so on first sight they record a baseline and wake nobody;
    • none has a verify command;
    • all 11 Solenta planboard issues they would auto-complete on merge are already closed.

Left out

  • No alert to the lead when a PR merges or closes. PR state already drives settling, and the wake would buy no action.
  • Retry queue is in memory only. After a restart, a postponed cleanup falls to the retention sweep or manual cleanup.

Tests

  • pr-refresh: an archived row refreshes to MERGED with plain fields and no wake.
  • pr-watch: unit coverage of the relay wording and targets, plus an end-to-end refresher test that wakes the lead.
  • worktree-cleanup: a running thread defers, the retry needs no gh, and the worktree is reclaimed once the run ends.

Each new test fails when the old behaviour is restored. The three suites pass 69/69 on this branch. The full electron suite in a CI-like env (all CODER_* vars unset) gives 4660 pass / 2 fail, and both failures (automation-create-mcp GitHub trigger shape, store round-trip) reproduce on clean main.

🤖 Generated with Claude Code

… worktree (#1431)

sweepCrew archives finished workers while their PRs are still open, and
the PR refresher skipped archived threads, so worker PRs stayed OPEN in
the store forever and their worktrees were never reclaimed.

- isPrRefreshCandidate keeps archived threads; terminal states still drop out.
- prWatch.wakeTarget: an archived worker never wakes itself. Its live lead
  gets the [pr watch] line naming the worker, with a thread_send hint and
  merging left to the user. Archived non-workers, or workers whose lead is
  archived/trashed, refresh state only.
- maybeCleanupMergedWorktree refuses while the thread is working or
  quota-wait and queues the id; the next refresher pass retries it without
  gh. Covers both the refresher and the in-app merge path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T13:27:10.197079Z b5de8ff PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@currentbits
currentbits merged commit 0545d27 into main Oct 12, 2026
3 of 6 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5de8ff284

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread electron/prWatch.js
* @returns {string | null}
*/
function wakeTarget(store, thread) {
if (!isWatched(thread)) return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip deleted workers when choosing a wake target

When an auto-archived worker is subsequently moved to Recently deleted, trashThread preserves its archived, orchWorker, and handoffFrom fields, so this still returns the live lead because only the lead's trashedAt is checked. A later PR failure can therefore start an unsolicited turn on the lead instructing it to contact a worker that thread_send will reject as deleted (electron/crossThread.js:95). Treat a trashed source worker as having no wake target.

Useful? React with 👍 / 👎.

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.

P2: PR refresher can't see archived worker PRs (34 of 35 stuck OPEN); merged-worktree cleanup ignores running threads

1 participant