Skip to content

fix(gaia-wiki): wait for merge and clean up locally when finishing the chain#514

Merged
stevensacks merged 2 commits into
mainfrom
fix/wiki-chain-finish-wait-merge
Jul 2, 2026
Merged

fix(gaia-wiki): wait for merge and clean up locally when finishing the chain#514
stevensacks merged 2 commits into
mainfrom
fix/wiki-chain-finish-wait-merge

Conversation

@stevensacks

Copy link
Copy Markdown
Contributor

Problem

/gaia-wiki's finish (gaia wiki chain finish, and sync land's protected-branch path) fired gh pr merge --squash --auto --delete-branch then immediately git checkout main and returned. --auto only queues the merge, so the CLI never waited for it: local main was never pulled to reflect the merged content, and the local wiki-sync/* branch was never deleted. The remote branch got auto-deleted on merge later, but the local one lingered until the session-start janitor eventually swept it.

Fix

Finish now lands like any other PR, following the "safe pattern" in wiki/concepts/PR Merge Workflow.md:

  1. Enable auto-merge (--auto waits for the gate to go green server-side).
  2. Poll gh pr view <branch> --json state until MERGED.
  3. Clean up locally: git checkout maingit pull --ff-only origin maingit branch -D <branch>git fetch --prune origin.
  4. Graceful degradation: if the merge doesn't land within the bounded wait, auto-merge stays queued (GitHub completes it once checks pass) and local cleanup is deferred to the session-start janitor — the CLI never hard-fails here.

The chain determinism contract forbids the router from inlining git/gh, so the wait+cleanup lives in a shared finalizeMerge helper in .gaia/cli/src/wiki/util/land.ts. Both chain finish and sync land's protected-branch landing route through it (the latter had the identical non-waiting bug), removing the duplicated finish tail.

Notes

  • Diff is entirely under .gaia/ + .claude/ + root markdown, so it's out of code-review-audit scope — the merge gate's out-of-scope bypass clears it with no marker.
  • Bundled binaries (.gaia/cli/gaia, gaia-maintainer) rebuilt.
  • Poll budget defaults to 10 × 30s; wiki-only PRs typically have no required checks so it returns on the first poll.

Testing

  • .gaia/cli typecheck clean; full CLI suite 1477 passed / 1 skipped.
  • Added merged-path and timeout-path tests for both chain finish and sync land.

🤖 Generated with Claude Code

`gaia wiki chain finish` (and `sync land`'s protected-branch path) fired
`gh pr merge --auto` then immediately checked out the base branch and
returned. `--auto` only queues the merge, so the base was never pulled and
the local `wiki-sync/*` branch was never deleted; the remote branch got
auto-deleted on merge while the local one lingered until the janitor swept it.

Finish now lands like any other PR: after enabling auto-merge it polls
`gh pr view --json state` until MERGED, then cleans up locally (checkout base,
pull --ff-only, delete the local branch, prune). If the merge does not land
within the bounded wait, auto-merge stays queued and cleanup is deferred to the
session-start janitor (unchanged fallback), so the CLI never hard-fails here.

The wait+cleanup lives in a shared `finalizeMerge` helper in `util/land.ts`
because the chain determinism contract forbids the router from inlining git/gh;
both surfaces route through it, removing the duplicated finish tail.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

code-review-audit skipped: no audit-relevant files changed in the un-audited delta (since the last clean audit); GAIA-Audit commit status stamped on HEAD so the merge gate is satisfied with no local audit run

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

code-review-audit skipped: no audit-relevant files changed in the un-audited delta (since the last clean audit); GAIA-Audit commit status stamped on HEAD so the merge gate is satisfied with no local audit run

@stevensacks stevensacks merged commit 9d17720 into main Jul 2, 2026
7 checks passed
@stevensacks stevensacks deleted the fix/wiki-chain-finish-wait-merge branch July 2, 2026 10:58
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.

1 participant