Skip to content

Install the crq binary atomically to avoid macOS SIGKILL after in-place updates#15

Merged
kristofferR merged 2 commits into
mainfrom
fix-macos-inplace-build
Jul 4, 2026
Merged

Install the crq binary atomically to avoid macOS SIGKILL after in-place updates#15
kristofferR merged 2 commits into
mainfrom
fix-macos-inplace-build

Conversation

@kristofferR

@kristofferR kristofferR commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Problem

Today a live crq install got wedged: every invocation died instantly with Killed: 9 (SIGKILL), including crq doctor and crq help, while the already-running autoreview daemon kept working. Cause: the binary had been rebuilt directly onto the existing file (go build -o ~/.local/bin/crq, per the README's manual-install instructions). Overwriting an already-executed Mach-O in place reuses the inode, macOS's cached code-signature for that inode goes stale, and the kernel kills any later exec of it. Copying the same bytes to a fresh inode ran fine — confirming it's the in-place overwrite, not the signature content.

Fix

  • install.sh: new install_binary() helper — stage the binary next to the target (mktemp in the same directory), chmod 0755, then mv -f over the destination. Atomic on the same filesystem, always a fresh inode regardless of which install(1) implementation is first on PATH (BSD install unlinks first, but that behavior shouldn't be load-bearing — e.g. with GNU coreutils installed), and a running daemon keeps executing its old inode untouched. Both the release-asset and source-build paths now use it.
  • README: the manual source install builds to ~/.local/bin/crq.new and renames, with a comment explaining why go build -o onto an existing crq bricks it on macOS.

Verification

  • bash -n clean.
  • End-to-end: ran install.sh with CRQ_BIN_DIR pointing at a temp dir containing an existing crq, using CRQ_INSTALL_SOURCE_DIR (source-build path). The target's inode changed, no staged temp files were left behind, and the installed binary executes (crq doctor exits 0).

https://claude.ai/code/session_015QX1sVWhKaCAo6u76gFnvF

Summary by CodeRabbit

  • Bug Fixes
    • Improved installation reliability by avoiding in-place replacement of the running binary, which helps prevent subsequent launches from being killed on macOS.
    • Updated both source-build and release-asset install flows to replace the binary more safely.
  • Documentation
    • Clarified the manual build/install steps by staging the built binary and then moving it into ~/.local/bin/crq.

Overwriting an already-executed binary in place (same inode) leaves macOS's
cached code signature stale, after which every execution of the path dies
with SIGKILL ("Killed: 9") until the file is replaced with a fresh inode.
This wedged a live install today when the binary was rebuilt with
`go build -o ~/.local/bin/crq` straight over the old file, exactly as the
README suggested.

- install.sh: add install_binary() — stage next to the target, chmod, then
  rename over it. Atomic on the same filesystem, guarantees a new inode
  regardless of which install(1) implementation is on PATH (BSD unlinks
  first; that behavior shouldn't be load-bearing), and a running autoreview
  daemon keeps its old inode.
- README: the manual source install now builds to crq.new and renames, with
  a note explaining why in-place `go build -o` bricks the binary on macOS.

Verified: installer run against a temp BIN_DIR replaces an existing binary
with a new inode and the result executes cleanly.

Claude-Session: https://claude.ai/code/session_015QX1sVWhKaCAo6u76gFnvF
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5282c503-474c-4828-926e-7aeb687ce983

📥 Commits

Reviewing files that changed from the base of the PR and between e9f4c10 and 6002350.

📒 Files selected for processing (1)
  • install.sh
📜 Recent review details
🔇 Additional comments (2)
install.sh (2)

20-28: LGTM! Local-scoping issue from prior review has been addressed.


147-147: LGTM!

Also applies to: 165-165


📝 Walkthrough

Walkthrough

The install script now stages crq in a temporary file and replaces the installed binary with mv -f. The README manual install steps were updated to match that staged rename flow.

Changes

Atomic binary install

Layer / File(s) Summary
install_binary helper and call sites
install.sh
Adds install_binary(src, dest) that stages the binary, applies 0755 permissions, and atomically renames it into place; both the release-asset and source-build install paths now call this helper instead of install -m 0755.
README manual install instructions
README.md
Manual build steps now build to ~/.local/bin/crq.new and forcibly rename it to ~/.local/bin/crq, with comments explaining avoidance of macOS stale code-signature issues.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit hops, then pauses just right,
Staging the binary out of sight.
Rename, not overwrite, clean and neat—
No sleepy macOS code-signature feet. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: atomic crq installation to prevent macOS SIGKILL from in-place updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-macos-inplace-build

Comment @coderabbitai help to get the list of available commands.

@kristofferR

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kristofferR

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@install.sh`:
- Around line 20-27: The install_binary function is leaking src, dest, and
staged into the global shell namespace. Update install_binary to declare these
as function-local variables so they don’t collide with other script variables,
and keep the existing mktemp/cp/chmod/mv flow intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 37fb7cd3-0819-440e-8c7c-874068ea9e5a

📥 Commits

Reviewing files that changed from the base of the PR and between 823a260 and e9f4c10.

📒 Files selected for processing (2)
  • README.md
  • install.sh
📜 Review details
🔇 Additional comments (2)
install.sh (1)

146-146: LGTM!

Also applies to: 164-164

README.md (1)

124-128: LGTM!

Comment thread install.sh
@kristofferR

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kristofferR

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kristofferR
kristofferR merged commit a6550d5 into main Jul 4, 2026
1 check passed
@kristofferR
kristofferR deleted the fix-macos-inplace-build branch July 4, 2026 08:27
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.

1 participant