Fix auto-merge failure in fork mode with permission pre-check (issue #1226)#1227
Fix auto-merge failure in fork mode with permission pre-check (issue #1226)#1227
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #1226
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>
--auto-merge option didn't result in actual mergeThis reverts commit 1ac97c4.
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
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. |
|
🤖 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. |
- 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>
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Summary
Fixes #1226 — Pull requests with
--auto-mergeoption didn't result in actual merge.Root Cause
The
--auto-mergefeature 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 becausegh pr mergerequires write/push access to the target repository.Evidence from two affected PRs:
ideavnetkeep80Both had
--auto-mergeflag but the solver user only had read access (push: false).Changes
src/github-merge.lib.mjs— AddedcheckMergePermissions()function that verifies write/push/admin/maintain access before attempting mergesrc/solve.auto-merge.lib.mjs— Added three guards:argv.fork) instartAutoRestartUntilMergable()checkMergePermissions()instartAutoRestartUntilMergable()attemptAutoMerge()docs/case-studies/issue-1226/— Comprehensive case study with timeline reconstruction, root cause analysis, and proposed solutionstests/test-auto-merge-permissions.mjs— 14 unit tests covering permission checks and fork-mode guard logicBehavior Change
--auto-mergein fork mode: silent failure, potentially infinite restart loop--auto-mergein fork mode: graceful exit with "Ready to merge" PR commentTest plan
node tests/test-auto-merge-permissions.mjs)node tests/test-merge-queue.mjs)solve-queue.test.mjs(CLAUDE_5_HOUR_SESSION_THRESHOLD) is not caused by this PRFixes #1226
🤖 Generated with Claude Code