Metadata
| Status | done |
|---|---|
| Assigned | agent-154 |
| Agent identity | f51439356729d112a6c404803d88015d5b44832c6c584c62b96732b63c2b0c7e |
| Created | 2026-04-26T20:49:10.591536062+00:00 |
| Started | 2026-04-26T22:44:12.916483827+00:00 |
| Completed | 2026-04-26T23:05:46.992762669+00:00 |
| Tags | eval-scheduled |
| Tokens | 1748966 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):
git push origin main(FF-only). If non-FF, attemptgit fetch origin main && git merge --ff-only origin/main && retry-push. If still failing, log a warning and continue.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 fromorigin/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" viagit init --bare, sets origin, runs the merge path, assertsorigin/mainadvances andrefs/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 doneexits 0. - cargo build + cargo test pass with no new regressions.
-
Reference the audit document
docs/audit-unmerged-branches-2026-04-26.mdin 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
- (none)
Log
- 2026-04-26T21:04:34.449975940+00:00 Lightweight assignment: agent=Careful Programmer (f5143935), exec_mode=full, context_scope=task, reason=Careful Programmer role with edge-case focus is ideal for this correctness-critical, TDD-driven implementation requiring graceful error handling and non-fatal remote-operation fallbacks.
- 2026-04-26T21:05:45.647213787+00:00 Spawned by coordinator --executor claude --model opus
- 2026-04-26T21:05:58.383227402+00:00 Starting implementation: read task, will inspect attempt_worktree_merge in done.rs and write failing tests first
- 2026-04-26T21:09:51.766325717+00:00 Task marked as failed: Agent exited with code 1
- 2026-04-26T22:44:09.495531668+00:00 Task reset for retry from failed (attempt #2)
- 2026-04-26T22:44:12.916487674+00:00 Spawned by coordinator --executor claude --model opus
- 2026-04-26T22:44:24.927647380+00:00 Starting fresh attempt: examining src/commands/done.rs::attempt_worktree_merge to understand current squash-merge flow
- 2026-04-26T22:47:27.153512599+00:00 Plan: 1) Add PushOutcome enum + extend WorktreeMergeResult::Merged. 2) Add push_main_and_delete_branch helper (FF push + branch delete). 3) Wire into attempt_worktree_merge. 4) Update call site to format pushed/local-only messages. 5) Add tests using bare repo as origin in src/commands/done.rs::tests.
- 2026-04-26T23:05:01.515008272+00:00 Implementation complete: PushOutcome enum + push_main_and_delete_branch helper + integration. 3 new tests pass (PushedAndDeleted, LocalOnly, NoRemote). All 63 commands::done tests pass. Pre-existing failure in provenance_coverage_tests::provenance_full_lifecycle_all_ops_recorded confirmed unrelated (reproduces on stash).
- 2026-04-26T23:05:36.942148891+00:00 Committed: fc5bc0138 — pushed to remote
- 2026-04-26T23:05:46.992778690+00:00 Task marked as done