Skip to content

fix(cli): accurately display bound viewer port on splash screen#560

Merged
rohitg00 merged 2 commits into
rohitg00:mainfrom
Tanmay-008:fix/cli-viewer-port-discovery
May 20, 2026
Merged

fix(cli): accurately display bound viewer port on splash screen#560
rohitg00 merged 2 commits into
rohitg00:mainfrom
Tanmay-008:fix/cli-viewer-port-discovery

Conversation

@Tanmay-008
Copy link
Copy Markdown
Contributor

@Tanmay-008 Tanmay-008 commented May 20, 2026

  • Expose viewerPort and viewerSkipped state in /agentmemory/livez endpoint.
  • Update CLI readiness check to poll until the viewer port is bound or explicitly skipped.
  • Prevents misleading default port (3113) display on splash screen when the viewer falls back to another port.

Fixes #521

Summary by CodeRabbit

  • New Features
    • CLI now auto-discovers the viewer port from the running server and uses it to build viewer URLs.
    • Health and liveness endpoints include viewer server status, port, and a "viewer skipped" indicator.
    • Readiness and diagnostics now honor discovered viewer port and treat skipped-viewer signals as ready, improving reachability checks.

Review Change Stack

- Expose viewerPort and viewerSkipped state in /agentmemory/livez endpoint.
- Update CLI readiness check to poll until the viewer port is bound or explicitly skipped.
- Prevents misleading default port (3113) display on splash screen when the viewer falls back to another port.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

@Tanmay-008 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2b71ed3d-5016-49d1-9e26-0504d58c1990

📥 Commits

Reviewing files that changed from the base of the PR and between 04a1b3c and 7706506.

📒 Files selected for processing (1)
  • src/viewer/server.ts

📝 Walkthrough

Walkthrough

The PR exposes the viewer server's bound port and skip state, returns them in health/livez endpoints, and updates the CLI to discover and cache the actual viewer port for URL construction and reachability checks.

Changes

Dynamic Viewer Port Discovery

Layer / File(s) Summary
Viewer server state tracking and export
src/viewer/server.ts
Module-level boundViewerPort and viewerSkipped state added; exported getters (getBoundViewerPort(), getViewerSkipped()); state reset on start, set on listening, and updated on terminal error/EADDRINUSE cases.
Health and liveness endpoint updates
src/triggers/api.ts
Imports viewer state helpers and includes viewerPort and viewerSkipped fields in /agentmemory/livez and /agentmemory/health JSON responses.
CLI dynamic viewer port discovery and integration
src/cli.ts
Adds exported discoverViewerPort() to fetch /agentmemory/livez and cache viewerPort; isAgentmemoryReady() parses viewerPort/viewerSkipped; getViewerUrl() prefers env var, then discovered port, then config-derived; runStatus() copies health-provided port; doctor viewerReachable now calls discoverViewerPort() before probing.

Sequence Diagram

sequenceDiagram
  participant CLI
  participant HealthLivez as /agentmemory/livez
  participant Health as /agentmemory/health
  participant ViewerServer as ViewerServer

  ViewerServer->>ViewerServer: bind to port, set boundViewerPort or viewerSkipped
  CLI->>HealthLivez: GET /agentmemory/livez
  HealthLivez->>ViewerServer: read getBoundViewerPort / getViewerSkipped
  HealthLivez->>CLI: respond with viewerPort and viewerSkipped
  CLI->>CLI: discoverViewerPort() caches viewerPort
  CLI->>CLI: getViewerUrl() uses discovered port
  CLI->>ViewerServer: probe constructed viewer URL for reachability
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I dug a tunnel, found a port so true,

No more false splash that made you stew.
Now health tells me where the viewer hides,
CLI listens close and checks all sides.
Hooray — the port and I both know where to do!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the CLI to display the correct viewer port on the splash screen instead of a hardcoded/default port.
Linked Issues check ✅ Passed The PR fully addresses issue #521 by exposing viewer state in /agentmemory/livez, updating CLI readiness checks, and preventing misleading default port display.
Out of Scope Changes check ✅ Passed All changes are directly focused on discovering and displaying the actual bound viewer port, with no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 `@src/viewer/server.ts`:
- Around line 134-135: Reset exported viewer state at the top of
startViewerServer() by setting boundViewerPort = null and viewerSkipped = false,
and when binding succeeds assign boundViewerPort from the actual server socket
(e.g., use server.address().port or the equivalent actual bound port) instead of
currentPort; also ensure that on any bind failure or exception paths (the
branches that currently handle bind errors) you clear boundViewerPort (set it to
null) and leave viewerSkipped in the correct state so stale module-level state
cannot leak across in-process restarts.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 842ff891-efbd-4b84-b319-a2bb616fda44

📥 Commits

Reviewing files that changed from the base of the PR and between 1838f4d and 04a1b3c.

📒 Files selected for processing (3)
  • src/cli.ts
  • src/triggers/api.ts
  • src/viewer/server.ts

Comment thread src/viewer/server.ts
@rohitg00 rohitg00 merged commit edd1ceb into rohitg00:main May 20, 2026
3 of 4 checks passed
@rohitg00
Copy link
Copy Markdown
Owner

Thanks @Tanmay-008 — exposing viewerPort + viewerSkipped on /livez is a clean way to make the splash truthful. Merged. Closes #521.

rohitg00 added a commit that referenced this pull request May 21, 2026
…uard (#588)

Three concerns surfaced when auditing PRs merged since v0.9.21:

1) Graph parser regex from #494 was correct for self-closing tags ONLY
   when they're the only entity in the document. With a self-closing
   entity followed by an explicit-close entity, the greedy `[^>]*` ate
   the trailing `/` of the self-close, the alternation fell through to
   the explicit-close branch, and `[\s\S]*?` ran ahead to the *next*
   `</entity>` — merging two entity declarations into one match and
   silently dropping a node. Switch to lazy `[^>]*?` so the
   self-closing alternation gets first chance. Test from #494 (which
   was failing on main but I didn't notice) now passes.

2) #386 shipped `${AGENTMEMORY_URL}` / `${AGENTMEMORY_SECRET}`
   placeholders in plugin/.mcp.json. Claude Code and Cursor expand
   those at MCP launch time; some hosts pass the literal string
   through. A truthy literal `"${AGENTMEMORY_URL}"` defeats the
   existing `|| DEFAULT_URL` fallback and would have the shim POST to
   `${AGENTMEMORY_URL}/agentmemory/...` (DNS failure). Add a
   defensive guard in src/mcp/rest-proxy.ts that strips any value of
   the form `${...}` so the fallback engages. Mirror in
   src/mcp/standalone.ts's mode-announce log line.

3) CHANGELOG entries for all PRs landed since v0.9.21 (#321, #325,
   #386, #454, #494, #526, #542, #560, #561, #562, #564, #567) plus
   the regex + env-guard hardening here.

Validation:
- npm test → 98 files, 1091 tests pass
- npm pack → 142 files, fresh install clean, iii-sdk@0.11.2 pinned,
  plugin/ shipped with hooks/scripts/skills/opencode/
- New test file covers 8 placeholder cases (unset, empty,
  `${VAR}` literal, mismatched braces, real values with $,
  unclosed `${`, no-braces `$VAR`).
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.

CLI splash claims Viewer http://localhost:3113 before viewer is actually listening (v0.9.20)

2 participants