Skip to content

[Gastown] Manual Merge Flow — Container /merge Endpoint + Review Queue Processing (P0) #214

@jrf0110

Description

@jrf0110

Parent: #204 | Phase 1

⚠️ Critical gap: The Rig DO's startMergeInContainer() calls container.fetch('http://container/merge', ...) but the container control server has no /merge endpoint. This request 404s. The entire polecat→done→merge→closed loop is broken — beads submitted to the review queue sit there permanently.

Goal

When a polecat calls gt_done, process the review queue entry with a simple deterministic merge. No AI reasoning in Phase 1.

Current State

  • agentDone() in Rig DO works: unhooks bead, submits to review queue, arms alarm ✅
  • processReviewQueue() in alarm handler pops pending entries ✅
  • startMergeInContainer() builds request and calls container ✅
  • Container has no /merge or /git/merge endpoint ❌ — this is the gap
  • Merge always fails → entry marked 'failed' → stuck

Implementation

1. Container: POST /git/merge endpoint

Add to control-server.ts:

// POST /git/merge
// Deterministic merge of a polecat branch into the target branch
{
  rigId: string,
  branch: string,        // polecat's branch (e.g., "gt/toast")
  targetBranch: string,  // e.g., "main"
  gitUrl: string         // for fetch if needed
}
 { status: 'merged' | 'conflict', message: string, commitSha?: string }

Implementation:

  1. Ensure repo is cloned/fetched for the rig
  2. Create a temporary worktree on the target branch
  3. git merge --no-ff <branch> in the worktree
  4. If success: push to remote, clean up worktree, return merged
  5. If conflict: abort merge, clean up worktree, return conflict with details
  6. No AI — purely mechanical

2. Rig DO: Update startMergeInContainer()

Ensure the URL matches the container endpoint (/git/merge not /merge). Pass gitUrl from rig config.

3. Rig DO: Handle merge result

  • On merged: mark review queue entry as 'merged', close the bead
  • On conflict: mark entry as 'failed', create escalation bead with conflict details

Flow

  1. Polecat pushes branch, calls gt_done
  2. agentDone() → unhook, submit to review queue, arm alarm
  3. Alarm fires → processReviewQueue() pops entry
  4. startMergeInContainer()POST /git/merge to container
  5. Container merges and pushes (or reports conflict)
  6. DO updates review queue entry status

Acceptance Criteria

  • Container POST /git/merge endpoint implemented
  • Deterministic merge (no AI) with proper git commands
  • Merge success: entry marked 'merged', bead closed, branch pushed
  • Merge conflict: entry marked 'failed', escalation bead created
  • Rig DO startMergeInContainer() URL matches container endpoint
  • End-to-end: polecat calls gt_done → review queue → merge → bead closed
  • Git worktree cleanup after merge (success or failure)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions