Skip to content

[repo-health] Low: observer.mjs crashes silently if OBSERVER_PORT env is non-numeric #17

Description

@Liohtml

Summary

assets/observer.mjs converts OBSERVER_PORT with a bare Number() call. If the environment variable is set to a non-numeric value, PORT becomes NaN and server.listen(NaN, ...) silently binds to a random ephemeral port rather than throwing — the Observer appears to start but is unreachable on the expected port.

Category

Bug

Severity

Low

Details

// assets/observer.mjs:9
const PORT = Number(process.env.OBSERVER_PORT || 4317);

Number('bad-value') returns NaN. Node's server.listen(NaN) does not throw; it picks an OS-assigned port, so the dashboard is no longer at the printed URL. The entry script sets OBSERVER_PORT from config.observerPort which is already validated by the CLI, but direct invocations (e.g. running observer.mjs outside of agentbox) are unprotected.

Suggested Fix

Add a guard after the Number() call:

const PORT = Number(process.env.OBSERVER_PORT || 4317);
if (!Number.isInteger(PORT) || PORT < 1 || PORT > 65535) {
  console.error(`[observer] Invalid OBSERVER_PORT: ${process.env.OBSERVER_PORT}`);
  process.exit(1);
}

Effort Estimate

5 min


Automated finding by repo-health-agent v1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions