fix-wg-done

Fix wg done auto-push origin main + delete origin agent branch on clean merge

Metadata

Statusdone
Assignedagent-154
Agent identityf51439356729d112a6c404803d88015d5b44832c6c584c62b96732b63c2b0c7e
Created2026-04-26T20:49:10.591536062+00:00
Started2026-04-26T22:44:12.916483827+00:00
Completed2026-04-26T23:05:46.992762669+00:00
Tagseval-scheduled
Tokens1748966 in / 17294 out

Description

Description

Closes the structural gap identified in docs/audit-unmerged-branches-2026-04-26.md: today the stigmergic merge-back in wg done runs git merge --squash <branch> into the worktree-local main, but never pushes main to origin and never deletes the agent branch on origin. As a result, every clean wg done leaves a leftover origin/wg/agent-N/<task> branch and the squash commit accumulates only on the local main of whoever ran the worktree.

File scope

  • src/commands/done.rs (primary — attempt_worktree_merge, around lines 119–246, and the call site around lines 1739–1792)
  • src/commands/done.rs::tests (new tests for the push/delete behavior with a stub remote)

Do not touch other files unless absolutely required.

Implementation guidance

In attempt_worktree_merge, after the Merged { commit_sha } arm successfully creates the squash commit on local main, perform two best-effort follow-ups (both must be non-fatal — wg done must still succeed if the remote is unavailable):

  1. git push origin main (FF-only). If non-FF, attempt git fetch origin main && git merge --ff-only origin/main && retry-push. If still failing, log a warning and continue.
  2. git push origin :refs/heads/<branch> to delete the remote agent branch. Only do this AFTER step 1 succeeds AND the squash commit is reachable from origin/main.

Surface both outcomes via the [merge] log line:

  • success: [merge] Squash-merged X to main (sha) — pushed origin/main, deleted origin/<branch>
  • partial: [merge] Squash-merged X to main (sha) — local-only (push failed: <reason>)

Validation

  • Failing test written first: tests/done_merge_push_test.rs::test_done_pushes_main_and_deletes_branch_on_clean_merge — uses a local bare-repo "remote" via git init --bare, sets origin, runs the merge path, asserts origin/main advances and refs/heads/<branch> is gone on origin.
  • Implementation makes the test pass.
  • Negative test: test_done_succeeds_when_remote_unavailable — push targets an unreachable URL; assert local merge still happens, error is logged, wg done exits 0.
  • cargo build + cargo test pass with no new regressions.
  • Reference the audit document docs/audit-unmerged-branches-2026-04-26.md in the commit message.

Why this matters

Without this fix, every audit cycle reproduces the same shape: tens of wg/agent-* branches on origin whose work is technically on local-main but invisible to anyone else. The fix is the load-bearing one — without it, the next audit will look identical.

Depends on

Required by

Log