Skip to content

Feat: run the demo in the background on uncommon ports, with a preflight - #719

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:feat/demo-ux
Jul 30, 2026
Merged

Feat: run the demo in the background on uncommon ports, with a preflight#719
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:feat/demo-ux

Conversation

@huang195

@huang195 huang195 commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

Three UX improvements to the local --demo quickstart, following on from #718:

  1. Background start — the installer no longer holds your terminal.
  2. Uncommon loopback ports — far less likely to collide.
  3. Port preflight — a clear message instead of a raw bind error.

Plus a leaner root-README quickstart.

Changes

install-demo.sh starts the demo in the background. Instead of exec authbridge-proxy --demo (foreground, Ctrl-C to stop), it now nohups the proxy with redirected output and a pidfile, waits until the forward proxy is actually listening — or surfaces the log tail if it died — then returns to the prompt. It prints the viewer/agent commands and a kill stop command. Because it regains control, the agent command now carries the absolute CA path, so the old "run from the same directory" caveat is gone.

Preflight. Before downloading, a best-effort check (lsof, then nc; skipped if neither exists) tests the three demo ports and aborts with a clear message if one is taken — e.g. "port 47600 is already in use. Is the demo already running…?"

Uncommon loopback ports. 8081 / 9094 / 9093 overlap with common dev + observability tools (alt-http, Alertmanager, pushgateway). Moved to:

Listener Was Now
forward proxy 127.0.0.1:8081 127.0.0.1:47600
session API 127.0.0.1:9094 127.0.0.1:47601
stats :9093 (wildcard) 127.0.0.1:47602
health :9091 unchanged (hardcoded, non-fatal on conflict)

Pinning stats also de-wildcards it (it had defaulted to all interfaces). Port constants live in both demo.go and install-demo.sh, with a sync comment in each.

Leaner README quickstart. One command that installs, starts the demo in the background, and prints the next steps. The CA, NODE_EXTRA_CA_CERTS, port numbers, and the multi-env-var agent command are all shown by the tool at runtime, so the README no longer repeats them.

Testing

  • shellcheck clean (via koalaman/shellcheck container); go build/test/vet green — the demo test asserts the new loopback ports (incl. stats).
  • Branch binary --demo: binds 47600/47601/47602 on loopback, no transparent listener.
  • install-demo.sh end-to-end on darwin/arm64: preflight aborts cleanly on an occupied port; otherwise it backgrounds the proxy, writes cortex-ca/demo.pid, detects readiness (Cortex demo is running (pid N)), prints the instructions with the absolute CA path, and returns to the shell with the proxy still running (killable via the pidfile). (The released v0.7.0-alpha.1 binary predates the port change, so the ports become fully consistent once this PR ships in a release; mechanics verified against it, ports verified against the branch binary.)

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

Summary by CodeRabbit

  • New Features

    • Demo installation now checks whether required local ports are available before starting.
    • The demo runs in the background, waits for readiness, and provides log and process information.
    • Updated terminal guidance makes it easier to watch and send agent traffic, then stop the demo.
  • Documentation

    • Simplified the local quick-start experience to use a single installation command.
    • Clarified demo behavior, local endpoints, and options for reviewing or building the installer.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@huang195, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f5a17c57-5360-4ae4-b0ae-2bf3e555185b

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd5790 and 12f0dd9.

📒 Files selected for processing (4)
  • README.md
  • authbridge/cmd/authbridge-proxy/demo.go
  • authbridge/cmd/authbridge-proxy/demo_test.go
  • authbridge/install-demo.sh
📝 Walkthrough

Walkthrough

The demo now uses fixed loopback ports, validates those bindings, checks port availability before installation, starts the proxy in the background with readiness logging, and updates the README quick start for watching agent traffic.

Changes

Demo flow

Layer / File(s) Summary
Demo ports and configuration
authbridge/cmd/authbridge-proxy/demo.go, authbridge/cmd/authbridge-proxy/demo_test.go
The demo uses loopback ports 47600, 47601, and 47602 for the forward proxy, session API, and stats listener, with matching test assertions.
Installer preflight and startup
authbridge/install-demo.sh
The installer checks port availability, supports install-only mode, launches the demo with nohup, writes log and PID files, waits for readiness, and prints updated commands.
Quick-start instructions
README.md
The README now documents the one-line installer flow for watching live agent traffic and provides source-build guidance.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant install-demo.sh
  participant authbridge-proxy
  participant demo.log
  install-demo.sh->>install-demo.sh: Check required loopback ports
  install-demo.sh->>authbridge-proxy: Start --demo with nohup
  authbridge-proxy->>demo.log: Write binding status
  install-demo.sh->>demo.log: Poll for forward-proxy readiness
  install-demo.sh-->>install-demo.sh: Print viewer, proxy, and stop commands
Loading

Possibly related PRs

Suggested reviewers: esnible, evaline-ju, mrsabath

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: background demo startup, uncommon ports, and a preflight check.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@authbridge/install-demo.sh`:
- Around line 75-82: Update the preflight port-check loop in install-demo.sh to
include the health listener port 9091 alongside DEMO_FORWARD_PORT,
DEMO_SESSION_PORT, and DEMO_STATS_PORT, while preserving the existing
AUTHBRIDGE_INSTALL_ONLY guard and failure handling.
- Around line 170-190: Update the startup readiness loop around demo_pid and the
forward-proxy log check so it only succeeds after the proxy has actually bound
its socket, using a real endpoint probe or a post-bind readiness signal rather
than the pre-bind name=forward-proxy entry. On timeout or bind failure, retain
the diagnostic warning/log-tail behavior and do not print the “Cortex demo is
running” message; emit that success message only when readiness is confirmed.
🪄 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 Plus

Run ID: 2bcfff0b-5bbd-4fec-9418-4cda01559fd7

📥 Commits

Reviewing files that changed from the base of the PR and between 4e01283 and 9cd5790.

📒 Files selected for processing (4)
  • README.md
  • authbridge/cmd/authbridge-proxy/demo.go
  • authbridge/cmd/authbridge-proxy/demo_test.go
  • authbridge/install-demo.sh

Comment on lines +75 to +82
# --- preflight: fail early (before downloading) if a demo port is taken ---
if [ "${AUTHBRIDGE_INSTALL_ONLY:-}" != "1" ]; then
for p in "$DEMO_FORWARD_PORT" "$DEMO_SESSION_PORT" "$DEMO_STATS_PORT"; do
if port_in_use "$p"; then
die "port ${p} is already in use. Is the demo already running (see ./cortex-ca/demo.pid)? Otherwise free the port, or change the ports in ./cortex-ca/demo.yaml, then re-run."
fi
done
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Preflight the health listener port too.

The demo still binds health on 9091, but this loop only checks the three new ports. A collision on 9091 downloads and launches the demo only for it to fail during startup. Add 9091 to the preflight set.

🤖 Prompt for 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.

In `@authbridge/install-demo.sh` around lines 75 - 82, Update the preflight
port-check loop in install-demo.sh to include the health listener port 9091
alongside DEMO_FORWARD_PORT, DEMO_SESSION_PORT, and DEMO_STATS_PORT, while
preserving the existing AUTHBRIDGE_INSTALL_ONLY guard and failure handling.

Comment thread authbridge/install-demo.sh Outdated
Improve the local demo UX from three angles.

install-demo.sh now starts the proxy in the background instead of foreground:
nohup + redirected output + a pidfile, then it waits for readiness — the forward
proxy's port actually accepting (a post-bind probe, not the pre-bind "listening"
log line), or the process exiting (log tail + hard fail) — before returning to
the prompt. It prints the viewer / agent commands and a stop command, and — because
it now regains control — the agent command carries the absolute CA path, so the
old "run from the same directory" caveat is gone. It also runs a best-effort
preflight (lsof, then nc) on the demo ports before downloading, aborting with a
clear message if one is taken (e.g. the demo is already running).

Move the demo listeners to uncommon loopback ports to cut collision odds: the
old 8081 / 9094 / 9093 overlap with common dev and observability tools. Forward
proxy -> 127.0.0.1:47600, session API -> 127.0.0.1:47601, stats ->
127.0.0.1:47602. Pinning stats also de-wildcards it (it defaulted to :9093 on
all interfaces). Health stays on :9091 (hardcoded, non-fatal on conflict). The
port constants live in both demo.go and install-demo.sh; a comment in each notes
the coupling.

Rework the root README quickstart into three tight steps on the new ports:
install + start (one backgrounded command), open the viewer (abctl), and send an
agent's traffic through it (Claude Code). No CA prose — the env var just appears
in the command — and no build-from-source fallback line.

Test: shellcheck clean; go build/test/vet green (the demo test asserts the new
loopback ports). Ran the branch binary --demo — binds 47600/47601/47602 on
loopback, no transparent listener. Ran install-demo.sh end to end on darwin/arm64:
preflight aborts on an occupied port; otherwise it backgrounds the proxy, writes
the pidfile, detects readiness, prints the instructions, and returns to the shell
with the proxy still running (killable via the pidfile).

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>

@esnible esnible left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clean, well-scoped UX improvement to the local --demo quickstart: backgrounds the proxy with a pidfile + readiness probe, moves listeners to uncommon loopback ports (47600–47602), adds a best-effort port preflight, and de-wildcards the stats endpoint (previously defaulted to :9093 on all interfaces — a genuine security tightening).

Verified the new stats:/address YAML maps correctly to cfg.Stats.StatsAddress (authbridge/authlib/config/config.go) and matches the new test assertion; the demo's explicit value also overrides the old :9093 wildcard default. Port constants are kept in sync between demo.go and install-demo.sh with cross-reference comments in both. Shell logic is sound: port_in_use semantics (lsof -sTCP:LISTEN, then nc -z, else assume-free) are consistent across preflight and readiness, the preflight is correctly skipped in AUTHBRIDGE_INSTALL_ONLY=1 mode, and startup detects early exit (bind failure) before probing the port.

Only a trivial nit (see inline). All CI green.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Shell, Go, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing (all checks green; Spellcheck skipped)

Assisted-By: Claude Code

Comment thread README.md

3. **Run your agent through it** — e.g. Claude Code (from the same directory, so `./cortex-ca` resolves — or use the absolute path the proxy logged):
3. **Send an agent's traffic through it** — e.g. Claude Code, from the directory where you started the demo:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Step 3 still frames it as "from the directory where you started the demo" and uses $PWD/cortex-ca/ca.crt, while the installer now prints an absolute CA path (${ca_dir}/ca.crt) so it can be pasted from anywhere. The PR body notes the "run from the same directory" caveat is gone — worth aligning the README wording/path to match, though it's fine as-is for a simplified quickstart.

@huang195
huang195 merged commit 249de04 into rossoctl:main Jul 30, 2026
19 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Jul 30, 2026
@huang195
huang195 deleted the feat/demo-ux branch July 30, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants