Skip to content

fix(remote): start herdr when its leftover socket refuses the connection - #405

Merged
devswha merged 1 commit into
mainfrom
fix/bridge-stale-socket
Oct 3, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/bridge-stale-socket

Conversation

@devswha

@devswha devswha commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Change

A Linux or macOS PC whose herdr was lost to a restart (or a kill) could not be connected again: Update ended in "Bridge did not start. Check ~/.config/herdr-web-ui/bridges/bridge.log on the PC." every time, until someone started herdr on that PC by hand.

herdr leaves its socket file behind when it dies that way. server/remote-entry.ts starts herdr only when the socket is absent; a socket that exists and does not answer was treated as an operator problem and rethrown, so the bridge exited before it wrote its descriptor:

HerdrError: cannot reach herdr at /Users/…/.config/herdr/herdr.sock: Failed to connect

Windows already tells a leftover marker from a live daemon (staleMarker). This adds the same for Unix sockets: refusedSocket(path) connects and returns true only on ECONNREFUSED, the kernel's answer for a socket file nobody listens on. Then the bridge starts herdr as it does for an absent socket. Any other failure (a daemon that is slow, a file that may not be read) still rethrows and leaves the daemon alone.

Found on a MacBook that restarted by itself: its bridge registry held a descriptor of a dead v13 bridge, herdr was not running, and herdr.sock dated from before the restart.

Validation

  • server/herdr-marker.test.ts: a child process listens on a socket and is killed with SIGKILL; refusedSocket is false for a missing file and for the live listener, true for the file left behind.
  • herdr itself starts over such a file: checked with herdr --session … server in a temporary XDG_CONFIG_HOME, killed with SIGKILL and started again, on Linux (herdr 0.9.3) and macOS arm64 (herdr 0.9.0). Both give ECONNREFUSED for the leftover socket with the bundle's Bun 1.4.2.
  • Linux, temporary HOME: with a leftover socket in place, bun server/remote-entry.ts started herdr and wrote its descriptor (bundle_version 14). Before the change it exits with the error above.
  • bun run typecheck: pass. bun run test:unit: 1128 pass, 3 skip, 0 fail.

Not checked

  • The full path over SSH from the PC list (bun run test:ssh), and a built remote bundle.
  • Windows is untouched: it keeps staleWindowsMarker.
  • No REMOTE_BUNDLE_VERSION bump here; PCs get this with the next bundle release.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
CONTRIBUTING.md — configured

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e03bb3a9-4f4f-49ee-9bf5-1cceb93ae766
📥 Commits

Reviewing files that changed from the base of the PR and between a5ccf28 and 27e70c6.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • server/herdr-marker.test.ts
  • server/herdr-marker.ts
  • server/remote-entry.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • On Linux and macOS, herdr now starts when a leftover socket file has no active listener, instead of being blocked by the stale file. Existing active sockets continue to prevent startup.
    • The fix will reach PCs with their next bridge update.

Walkthrough

The bridge now checks whether an existing socket is stale after bridgeIdentity() fails. On non-Windows systems, it continues startup when a connection to the socket is refused. Tests cover missing, live, and stale socket paths.

Changes

Stale Socket Startup Recovery

Layer / File(s) Summary
Detect refused socket connections
server/herdr-marker.ts, server/herdr-marker.test.ts
refusedSocket returns true only for ECONNREFUSED. The test checks missing and live sockets, then checks the socket path after its listener stops.
Apply stale-socket check during startup
server/remote-entry.ts, CHANGELOG.md
When bridgeIdentity() fails and a socket exists, startup proceeds on Windows only if its marker is stale. On other platforms, startup proceeds only if the socket connection is refused. Otherwise, the original error is rethrown. The changelog records the fix.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 27e70

This change lets the bridge start herdr when a leftover socket file has no listener. No merge-blocking risk was identified.

Architecture Summary

Architecture risk: 🔵 Low · up to 27e70

The change affects 2 systems.

Changed systems: server, CHANGELOG.md

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — server (service) was modified; 3 changed files map to changed impact.
  • observed — CHANGELOG.md (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in CHANGELOG.md: Adds an Unreleased changelog entry stating that the bridge starts herdr when its leftover socket file has no listener, with the fix delivered in the next bridge update.
  • observed — Modified behavior in server/herdr-marker.test.ts: Added imports for temporary-directory and socket-path handling, filesystem cleanup and existence checks, and refusedSocket.
  • observed — Modified behavior in server/herdr-marker.test.ts: Added a test skipped on Windows that checks refusedSocket returns false for a missing path and a live listener, then true after the listener is killed while its socket file remains. The test kills and awaits the listener and removes the temporary directory in cleanup.
  • observed — Modified behavior in server/herdr-marker.ts: Adds the refusedSocket export and documents that Linux and macOS may retain socket files after a daemon is killed or a reboot. The function returns false after a successful connection, and on failure returns true only for ECONNREFUSED; other errors return false.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the fix: start herdr when its leftover socket refuses the connection.
Description check ✅ Passed The description includes the required Change and Validation sections. It explains the failure, resulting behavior, and test results, and it states which checks were not run.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@devswha
devswha merged commit eefa437 into main Oct 3, 2026
12 checks passed
@devswha
devswha deleted the fix/bridge-stale-socket branch October 3, 2026 17:38
devswha added a commit that referenced this pull request Oct 3, 2026
Bumps package.json and herdr-plugin.toml to 0.3.48, moves the Unreleased
notes under [0.3.48] - 2026-10-04 (with the PR links #403, #405 and #406
lacked), and adds the compare link. Raises the remote PC bundle to 15
(the bridge starts herdr on a stale socket, #405; `/api/worktree/create`
takes `agent`, #401): push the `remote-v15` tag and let the bundle
workflow publish before running release.yml.

Carries #393, #376, #403, #405, #402, #400, #397, #406, #401, #407,
#408.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5.1 <[email protected]>
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