fix(daemon): reconcile and merge tasks whose PR was merged on the forge (#1872)

ListOpenPRs dropped org_id, so the reconciler resolved the forge and
worktrees in the default org instead of the task's own and skipped the
task silently. Select the org, log a skipped task, and let the Merge
action succeed when the forge reports the PR already merged.
This commit is contained in:
sam committed 2026-11-14 04:01:31 +11:00
1 parent da1795c597
commit 5edf58fd68
7 files changed
+80 -5

No files matched your search

@@ -651,12 +651,13 @@ func (q *Queries) InsertTransition(ctx context.Context, arg InsertTransitionPara
}
const listOpenPRs = `-- name: ListOpenPRs :many
SELECT id, owner, repo, issue_number, pr_number, status, source, identity, attempt, review_cursor, watch_comment_id, outputs
SELECT id, org_id, owner, repo, issue_number, pr_number, status, source, identity, attempt, review_cursor, watch_comment_id, outputs
FROM tasks WHERE status = 'pr_open' AND ($1::text IS NULL OR org_id = $1)
`
type ListOpenPRsRow struct {
ID int64
OrgID string
Owner string
Repo string
IssueNumber int64
@@ -681,6 +682,7 @@ func (q *Queries) ListOpenPRs(ctx context.Context, scopeOrg pgtype.Text) ([]List
var i ListOpenPRsRow
if err := rows.Scan(
&i.ID,
&i.OrgID,
&i.Owner,
&i.Repo,
&i.IssueNumber,
@@ -308,7 +308,7 @@ WHERE id = @id AND status = @from_status
DELETE FROM tasks WHERE id = $1 AND status = $2;
-- name: ListOpenPRs :many
SELECT id, owner, repo, issue_number, pr_number, status, source, identity, attempt, review_cursor, watch_comment_id, outputs
SELECT id, org_id, owner, repo, issue_number, pr_number, status, source, identity, attempt, review_cursor, watch_comment_id, outputs
FROM tasks WHERE status = 'pr_open' AND (sqlc.narg(scope_org)::text IS NULL OR org_id = sqlc.narg(scope_org));
-- name: NextTaskID :one
+1 -1
View File
@@ -802,7 +802,7 @@ func (s *Store) OpenPRs(ctx context.Context) ([]workflow.Task, error) {
for _, r := range rows {
outputs, _ := task.DecodeOutputs(r.Outputs)
tasks = append(tasks, workflow.Task{
ID: r.ID, Owner: r.Owner, Repo: r.Repo, IssueNumber: int(r.IssueNumber),
ID: r.ID, Org: org.OrgID(r.OrgID), Owner: r.Owner, Repo: r.Repo, IssueNumber: int(r.IssueNumber),
PRNumber: int(r.PrNumber), Status: r.Status, Source: r.Source,
Identity: r.Identity, Attempt: int(r.Attempt),
ReviewCursor: r.ReviewCursor, WatchCommentID: r.WatchCommentID,