Skip to content

feat: surface merge conflicts as PR review-fix items with priority ordering#356

Merged
itsmiso-ai merged 1 commit into
mainfrom
feat/355-merge-conflict-queue
Jun 11, 2026
Merged

feat: surface merge conflicts as PR review-fix items with priority ordering#356
itsmiso-ai merged 1 commit into
mainfrom
feat/355-merge-conflict-queue

Conversation

@itsmiso-ai

Copy link
Copy Markdown
Contributor

Fixes #355

Summary

Merge-conflicting PRs are invisible to the current worker system. This PR adds a sync/ingestion step that detects open PRs with merge conflicts and creates pr-review-fix items with priority ordering.

Changes

  • PrFixType enum: Added MERGE_CONFLICT, CI_FAILURE, REVIEW_FEEDBACK, OTHER types
  • PrFixQueueItem.type field: New field to categorize fix items
  • Priority ordering: Queue now returns items in priority order: conflicts > CI failures > review feedback
  • Merge conflict detection: ingestMergeConflict() function for detecting CONFLICTING PRs
  • Idempotent cleanup: clearResolvedConflictItems() clears items when PR becomes mergeable or closed
  • Sync route updates: Detects conflicts and clears resolved items during periodic sync
  • Queue endpoint: Supports prioritize_by_type parameter (default: true)

Acceptance Criteria

  • Dispatch detects open PRs where mergeable=CONFLICTING and creates pr-review-fix items with type: "MERGE_CONFLICT"
  • The review-fix queue returns items in priority order: conflicts > CI fails > requested changes
  • Workers can distinguish conflict items from review-feedback items via fixType field
  • Already-existing conflict items are not re-created on every sync pass (idempotent)
  • Conflict items are cleared/marked resolved when the PR becomes mergeable or is closed

Migration

Added migration 20260611000000_add_pr_fix_type to add the PrFixType enum and type field to PrFixQueueItem.

@its-saffron its-saffron Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Automated Review

Full PR review.

Analysis engine: MiniMax-M2.7@https://litellm.jory.dev/v1 (anthropic) — routed smart (risk match: db_or_migration_changes)

Review: PR PR 356 — Surface merge conflicts as PR review-fix items with priority ordering

Recommendation

Approve. The migration is safe, the implementation satisfies all linked issue acceptance criteria, and the code follows repository conventions.


Change-by-Change Findings

Migration (prisma/migrations/20260611000000_add_pr_fix_type/migration.sql)

  • New enum PrFixType with values MERGE_CONFLICT, CI_FAILURE, REVIEW_FEEDBACK, OTHER — standard Prisma pattern, no data loss risk.
  • **ADD COLUMN type NOT NULL DEFAULT 'OTHER'** — populates existing rows with the catch-all OTHER` value, which is correct since pre-existing queue items had no explicit type.
  • Two composite indexes on (type) and (status, type) for efficient priority-ordered queue queries.

Schema (prisma/schema.prisma)

  • Enum PrFixType added; type field on PrFixQueueItem defaults to OTHER.
  • Two new indexes mirror the migration SQL.

Code changes (src/lib/pr-followup-ingestion.ts)

  • ingestMergeConflict(): detects mergeable=CONFLICTING PRs, enqueues with type: "MERGE_CONFLICT". Correctly checks bot author and repo owner eligibility before enqueueing.
  • clearResolvedConflictItems(): marks FIXED when PR becomes mergeable or closed. Guarded by type === "MERGE_CONFLICT" and status === "QUEUED" — idempotent.
  • ingestMergeStateEvent(): now sets type based on mergeStateStatus ("dirty"/"conflicting" → MERGE_CONFLICT).
  • All existing ingestors (ingestCommentEvent, ingestReviewEvent, ingestCheckRunEvent) now set type explicitly (REVIEW_FEEDBACK, CI_FAILURE).

Queue logic (src/lib/pr-fix-queue.ts)

  • normalizePrFixType(): proper normalization with hyphens stripped, uppercase comparison.
  • listQueuedPrFixItems(): sorts in-memory by PR_FIX_TYPE_PRIORITY then queuedAt when prioritizeByType !== false.
  • toAgentQueueItem(): includes fixType in the returned item — workers can distinguish conflict from feedback items.

API route (src/app/api/pr-fix-queue/queued/route.ts)

  • Added prioritize_by_type query param (default true) — mirrors the prioritizeByType option in the library.

Types (src/types/index.ts)

  • PrFixType type, normalizePrFixType(), VALID_PR_FIX_TYPES, and PR_FIX_TYPE_PRIORITY constant — consistent with the existing PrFixLane/PrFixStatus pattern in the codebase.

Required Check Responses

✅ review migration for data loss risk

The migration adds a new enum type and a non-null column with a default value. No existing rows are deleted or modified destructively. PostgreSQL handles ADD COLUMN ... DEFAULT 'OTHER' without a table rewrite in modern versions (11+), so this is a low-risk online migration. Existing PrFixQueueItem rows will receive type = 'OTHER' by default, which is semantically correct.

⚠️ test migration on a copy of production schema

Cannot verify from the PR corpus. There is no evidence of testing on a production-schema copy in the provided diff, PR body, or linked issue. This is a best-practice recommendation for production deployments: run prisma migrate deploy on a staging snapshot before applying to production. The migration itself is straightforward, but schema size and concurrent write patterns during deployment could reveal edge cases not visible in a clean diff.


Standards Compliance

  • ✅ Enum and type patterns follow existing PrFixLane/PrFixStatus conventions
  • ✅ Error handling uses error instanceof Error pattern in routes
  • ✅ No agent-specific names in generic code (isAllowedBotAuthor uses env-configurable allowlist)
  • ✅ HTTP status codes used appropriately in API routes
  • ✅ Audit trail entries written via prFixHistory on status changes
  • ✅ No hardcoded agent names or repo names — PR_FOLLOWUP_BOT_IDENTITIES and PR_FOLLOWUP_BRANCH_OWNERS are configurable

Linked Issue Fit (PR 355)

Acceptance Criterion Status
Dispatch detects mergeable=CONFLICTING and creates pr-review-fix items with type: "MERGE_CONFLICT" ingestMergeConflict() in sync route
Queue returns items in priority order: conflicts > CI fails > requested changes PR_FIX_TYPE_PRIORITY + in-memory sort
Workers can distinguish conflict items via fixType field toAgentQueueItem() surfaces fixType
Already-existing conflict items are not re-created (idempotent) ✅ Evidence-key deduplication + existence check
Conflict items are cleared when PR becomes mergeable or is closed clearResolvedConflictItems() sets status: "FIXED"

Unknowns / Needs Verification

  1. Production migration testing — recommend verifying the ADD COLUMN NOT NULL DEFAULT step on a production-schema snapshot before deployment, especially if the PrFixQueueItem table is large or sees high write volume.
  2. In-memory sort at scalelistQueuedPrFixItems() loads all queued items into memory and sorts in-process. This is acceptable for typical queue sizes but would need pagination or a database-side ORDER BY if the queue grows to thousands of items. No evidence of queue-size stress testing in the corpus.

…dering

Refs #355

- Add PrFixType enum (MERGE_CONFLICT, CI_FAILURE, REVIEW_FEEDBACK, OTHER)
- Add type field to PrFixQueueItem for categorizing fix items
- Implement priority ordering: conflicts > CI failures > review feedback
- Add ingestMergeConflict() for detecting CONFLICTING PRs
- Add clearResolvedConflictItems() for idempotent cleanup
- Update sync route to detect conflicts and clear resolved items
- Update queue endpoint to support prioritize_by_type parameter
- Workers can distinguish conflict items via fixType field
@itsmiso-ai itsmiso-ai force-pushed the feat/355-merge-conflict-queue branch from bc8698a to 89827ff Compare June 11, 2026 21:34
@itsmiso-ai itsmiso-ai merged commit c2e5077 into main Jun 11, 2026
3 checks passed
@itsmiso-ai itsmiso-ai deleted the feat/355-merge-conflict-queue branch June 11, 2026 21:51
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.

feat: surface merge conflicts as PR review-fix items with priority ordering

1 participant