Skip to content

Fix auto-merge failure in fork mode with permission pre-check (issue #1226)#1227

Merged
konard merged 7 commits intomainfrom
issue-1226-964a0fd2fe61
Feb 13, 2026
Merged

Fix auto-merge failure in fork mode with permission pre-check (issue #1226)#1227
konard merged 7 commits intomainfrom
issue-1226-964a0fd2fe61

Conversation

@konard
Copy link
Contributor

@konard konard commented Feb 6, 2026

Summary

Fixes #1226 — Pull requests with --auto-merge option didn't result in actual merge.

Root Cause

The --auto-merge feature was fundamentally incompatible with fork mode. When hive-mind operates on repositories where it only has read (pull) access, it uses fork mode to create PRs from a fork to the upstream. However, the auto-merge code (solve.auto-merge.lib.mjs) had no check for fork mode or write access permissions, and would silently fail because gh pr merge requires write/push access to the target repository.

Evidence from two affected PRs:

Both had --auto-merge flag but the solver user only had read access (push: false).

Changes

  1. src/github-merge.lib.mjs — Added checkMergePermissions() function that verifies write/push/admin/maintain access before attempting merge
  2. src/solve.auto-merge.lib.mjs — Added three guards:
    • Fork-mode early detection (argv.fork) in startAutoRestartUntilMergable()
    • Permission pre-check via checkMergePermissions() in startAutoRestartUntilMergable()
    • Permission pre-check in attemptAutoMerge()
    • When merge is impossible, posts a "Ready to merge" comment to the PR to notify the maintainer
  3. docs/case-studies/issue-1226/ — Comprehensive case study with timeline reconstruction, root cause analysis, and proposed solutions
  4. tests/test-auto-merge-permissions.mjs — 14 unit tests covering permission checks and fork-mode guard logic

Behavior Change

Before After
--auto-merge in fork mode: silent failure, potentially infinite restart loop --auto-merge in fork mode: graceful exit with "Ready to merge" PR comment
No permission check before merge attempt Permission verified before entering merge loop

Test plan

  • 14 new tests pass (node tests/test-auto-merge-permissions.mjs)
  • Existing merge queue tests pass (node tests/test-merge-queue.mjs)
  • ESLint passes on changed files
  • Prettier formatting verified
  • Pre-existing test failure in solve-queue.test.mjs (CLAUDE_5_HOUR_SESSION_THRESHOLD) is not caused by this PR

Fixes #1226

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #1226
@konard konard self-assigned this Feb 6, 2026
konard and others added 3 commits February 6, 2026 12:00
Deep analysis of why --auto-merge didn't work for PRs ideav/crm#233
and netkeep80/isocubic#265. Root cause: the solver operates in fork
mode (read-only access) but gh pr merge requires write access to the
target repository.

Includes timeline reconstruction, evidence data, and proposed solutions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Issue #1226: Auto-merge was silently failing for fork-mode PRs because
the solver user doesn't have write access to upstream repositories.

Changes:
- Add checkMergePermissions() to github-merge.lib.mjs to verify
  write/push access before attempting merge
- Add fork-mode early detection in startAutoRestartUntilMergable() -
  if argv.fork is set, skip auto-merge and post "ready to merge"
  comment to PR instead
- Add permission pre-check in both startAutoRestartUntilMergable()
  and attemptAutoMerge() to fail gracefully with a helpful message
  when the user lacks write access

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
14 tests covering:
- checkMergePermissions() function behavior (API calls, return structure)
- Fork-mode guard logic (blocks auto-merge in fork mode)
- Permission pre-check logic (read/push/admin/maintain/triage access levels)

All tests pass against live GitHub API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Pull requests with --auto-merge option didn't result in actual merge Fix auto-merge failure in fork mode with permission pre-check (issue #1226) Feb 6, 2026
@konard konard marked this pull request as ready for review February 6, 2026 11:06
@konard
Copy link
Contributor Author

konard commented Feb 6, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $9.948678 USD
  • Calculated by Anthropic: $7.849145 USD
  • Difference: $-2.099533 (-21.10%)
    📎 Log file uploaded as Gist (1745KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Feb 13, 2026

Ensure all changes are correct, consistent, validated, tested and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass.

@konard konard marked this pull request as draft February 13, 2026 18:39
@konard
Copy link
Contributor Author

konard commented Feb 13, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-02-13T18:39:46.055Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

konard and others added 2 commits February 13, 2026 19:41
- Format case study documentation and evidence files with Prettier
- Add changeset for auto-merge fork-mode fix
- Update test to use torvalds/linux (public read-only repo) instead of ideav/crm

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review February 13, 2026 18:49
@konard
Copy link
Contributor Author

konard commented Feb 13, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $3.299324
  • Calculated by Anthropic: $1.917008 USD
  • Difference: $-1.382316 (-41.90%)
    📎 Log file uploaded as Gist (899KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 6be59ff into main Feb 13, 2026
21 checks passed
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.

Pull requests with --auto-merge option didn't result in actual merge

1 participant