Skip to content

Workers land themselves: thread_merge commits worker branches onto main with no user say #614

Closed

Description

@currentbits

Symptom

Threads with workers merge their worktrees themselves. The user is never asked whether to merge, open a PR, or leave the branch alone.

Root cause

`thread_merge` (electron/orchServer.js) passed `intoPath: self.worktreePath || undefined`. A lead thread only has a worktree when it was created with the opt-in toggle, so the fallback target is the project checkout — and `mergeWorktree` squashes and commits there, on the default branch (electron/worktrees.js).

The orchestrator instructions actively drove it: "when one finishes, check its result and call thread_merge", repeated verbatim in the machine-delivered worker-finished notice (electron/runner.js).

Measured on the live machine (2026-08-20)

  • 200 of 207 worker threads in `coder-store.json` have a lead with no `worktreePath`.
  • 13 commits on `main` in one day of the form `Merge worktree coder/fork-…: Fork: …` — worker branches landed by an agent, no user gate, no PR option.

Fix

Workers build; the lead asks.

  • `assertUserApproved` in orchServer: refuses unless the caller passes `approved:true` and is running a turn a human started. The turn check is the real lock — `runner.isAutoTurn` reads the existing `autoTurns` map, so a worker-finished notice (machine-delivered, nobody has answered yet) can never approve. `approved` alone is an agent claim.
  • Gate fires only when the lead has no worktree, i.e. when the target is the default branch. A lead working in its own worktree keeps merging workers onto its own branch unasked — that is staging, and the user still gates that branch from the thread header.
  • New `thread_pr` tool: pushes the worker's branch and opens a PR via the existing `createPr`, behind the same gate. Leaves the worktree and branch in place so `thread_send` can put the worker back on review comments.
  • Instructions + finish notice rewritten to report-and-ask.

Tests: electron/test/orch-merge.test.js (refusal, approved, auto-turn, lead-worktree staging, thread_pr gate + guards).

Activity

  1. currentbits commented on Aug 21, 2026

    @currentbits
    OwnerAuthor

    Follow-up from a fresh report of the same symptom (2026-08-21): the 862812a gate works — live leads this morning were refused on machine-delivered turns and asked the user — but it had one residual gap.

    Gap: the lead asks via the AskUserQuestion card, the user picks "merge", and the gate still refuses: answering a question card never reset the runner's autoTurns counter, so isAutoTurn stayed true for the whole notice-delivered turn. Live thread 11cb8e39 told the user the card reply "doesn't count for this guard" and made them type a second message.

    Fix (branch coder/when-we-run-tasks-with-the-orhcestration-89b55b, commit 5057b1a): respondPermission zeroes autoTurns on an answered question (allow + answers only — a plain permission click or a deny does not count), and the refusal message now tells the lead the card answer counts. Test added in electron/test/claude.test.js.

    Also confirmed while investigating: the "no worktree is created" half of the report is a post-hoc illusion — workers do get worktrees; thread_merge cleanup deletes the worktree and clears worktreePath/branch, so merged workers look like they never had one.

  2. currentbits commented on Aug 22, 2026

    @currentbits
    OwnerAuthor

    Verified shipped on main (audit 2026-08-22): implementation present in the working tree, not just on a worker branch. Closing — the planboard never auto-closed these (#632).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions