Skip to content

fix(cli): prevent EADDRINUSE when server already running (#3346)#3388

Merged
aegis-gh-agent[bot] merged 3 commits into
developfrom
fix/3346-eaddrinuse
May 14, 2026
Merged

fix(cli): prevent EADDRINUSE when server already running (#3346)#3388
aegis-gh-agent[bot] merged 3 commits into
developfrom
fix/3346-eaddrinuse

Conversation

@OneStepAt4time

Copy link
Copy Markdown
Owner

Summary

Fixes #3346 — ag run fails with EADDRINUSE when server already running.

Changes

  1. CLI health check fallback (src/commands/run.ts): When the health endpoint times out or returns a non-OK status, falls back to checking the Aegis PID file. If a live process exists, assumes the server is running and skips bootstrap/start.

  2. Server EADDRINUSE message (src/startup.ts): When a peer Aegis is detected on the port (already fixed by Hermes in a prior commit on this branch), exits with a clear message instead of a raw stack trace.

Verification

  • tsc --noEmit: clean
  • PID file check uses process.kill(pid, 0) for zero-cost liveness check
  • Graceful fallback: if PID file doesn't exist or process is dead, returns false (existing behavior)

ag run now checks the Aegis PID file as a fallback when the health
endpoint times out. If a PID file exists with a live process, the CLI
assumes the server is running and skips the bootstrap/start phase.

Also improved the server's EADDRINUSE error message: when a peer Aegis
is detected on the port, exits with a clear message telling the user to
either connect to the existing server or stop it first.

Fixes: #3346
When the health endpoint times out (server under load or transient issue),
isServerHealthy() now falls back to checking the Aegis PID file. If a
PID file exists with a live process, the CLI assumes the server is running
and skips bootstrap/start — preventing EADDRINUSE.

@aegis-gh-agent aegis-gh-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Two-part EADDRINUSE fix:

  1. isServerHealthy() falls back to PID file check when /v1/health times out — prevents CLI from thinking server is down when it's just slow.
  2. startup.ts gives clear message + ag stop suggestion instead of raw stack trace.

Clean implementation, standard POSIX PID check via process.kill(pid, 0). CI green. All gates pass.

@aegis-gh-agent aegis-gh-agent Bot merged commit 2a3630f into develop May 14, 2026
17 checks passed
@aegis-gh-agent aegis-gh-agent Bot deleted the fix/3346-eaddrinuse branch May 14, 2026 10:46
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