Run the merge queue on a state-driven coordinator

This commit is contained in:
Ian Gulliver
2026-10-21 11:28:07 -07:00
parent a971cce9d6
commit 7fbdf1669a
13 changed files with 509 additions and 561 deletions
+12 -7
View File
@@ -81,17 +81,14 @@ func (m *Manager) mergeToMain(ctx context.Context, l *live, raw json.RawMessage)
return "", err
}
pm := m.projectMerge(project.Id)
pm.mu.Lock()
holder := pm.holder
if holder == "" {
pm.holder = task.Id
holder, err := m.store.ClaimMainPush(ctx, task.Id)
if err != nil {
return "", err
}
pm.mu.Unlock()
if holder != "" {
return "", fmt.Errorf("%w: task %s is merging into %s; call again once it is done", ErrConflict, holder, project.DefaultBranch)
}
defer m.releaseMerge(project.Id, task.Id)
defer m.endMainPush(task.Id)
commit, err := m.pushToMain(ctx, l, task, project, user, title)
if err != nil {
@@ -170,6 +167,14 @@ func (m *Manager) pushToMain(ctx context.Context, l *live, task api.Task, projec
return commit, nil
}
func (m *Manager) endMainPush(taskID string) {
err := m.store.EndMainPush(context.Background(), taskID)
if err != nil {
slog.Error("end push to main", "task", taskID, "err", err)
}
m.poke()
}
func landPrompt(target, title string) string {
return fmt.Sprintf("The human asked to merge this task's work so far into %[1]s and keep the task open (Merge & continue); byre holds the task's other agents until this turn ends. "+
"First merge %[1]s in with `git merge --no-ff --no-commit %[1]s`, resolve any conflicts keeping both sides' intent, regenerate generated files instead of hand-merging them, and check that the build and tests pass. "+