Skip to content

broker: fix direct-run detection for symlinked release path#105

Merged
benvinegar merged 1 commit into
mainfrom
bentlegen/fix-broker-register-symlink
Feb 21, 2026
Merged

broker: fix direct-run detection for symlinked release path#105
benvinegar merged 1 commit into
mainfrom
bentlegen/fix-broker-register-symlink

Conversation

@benvinegar
Copy link
Copy Markdown
Member

@benvinegar benvinegar commented Feb 21, 2026

Summary

  • fix bin/broker-register.mjs main-module detection when invoked via symlinked release path (/opt/baudbot/current/...)
  • add isMainModule() helper that compares resolved and realpath URLs
  • add test coverage for symlink argv path handling

Why

sudo baudbot broker register could exit silently with code 0 because module URL and argv path differed across /opt/baudbot/current symlink boundaries.

Validation

  • node --check bin/broker-register.mjs
  • node --test bin/broker-register.test.mjs

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 21, 2026

Greptile Summary

Fixed silent exit bug when broker-register.mjs is invoked via symlinked release path (e.g., /opt/baudbot/current/bin/broker-register.mjs/opt/baudbot/releases/<sha>/bin/broker-register.mjs).

Changes:

  • Added isMainModule() helper that compares both resolved path and realpath to handle symlinks correctly
  • Replaced hardcoded main-module check with the new helper function
  • Added comprehensive test coverage for symlink argv path handling

Why this matters:
The deployment architecture uses symlinks (current → releases/<sha>) for atomic release switches. The old check (import.meta.url === file://${process.argv[1]}) would fail when the script was invoked via a symlink because import.meta.url resolves to the real file path while process.argv[1] stays as the symlink path, causing the script to exit silently without executing.

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • The fix is well-contained, solves a real production issue with symlinked paths, includes proper error handling with try-catch blocks, and has comprehensive test coverage validating the new behavior
  • No files require special attention

Important Files Changed

Filename Overview
bin/broker-register.mjs Added isMainModule() helper to handle symlinked paths by comparing both resolved and realpath URLs, fixing silent exit issue when script is invoked via symlink
bin/broker-register.test.mjs Added test coverage for isMainModule() symlink handling using temporary files and symlink creation

Last reviewed commit: 15a8c88

@benvinegar benvinegar merged commit eb80ed4 into main Feb 21, 2026
10 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.

1 participant