Skip to content

Auto-discover server host/port for test/env/status commands#17

Merged
adambalogh merged 1 commit into
mainfrom
claude/og-veil-test-port-rvxw8s
Jul 9, 2026
Merged

Auto-discover server host/port for test/env/status commands#17
adambalogh merged 1 commit into
mainfrom
claude/og-veil-test-port-rvxw8s

Conversation

@adambalogh

Copy link
Copy Markdown
Contributor

Summary

When the background server is started on a non-default port, client commands (test, env, status) now automatically discover and connect to it without requiring the user to re-specify the port. This is achieved by persisting the server's configuration when it starts and loading it when client commands run.

Key Changes

  • Runtime config persistence: Added save_runtime() and load_runtime() functions in daemon.py to persist the server's configuration to a JSON file when it starts and retrieve it when needed
  • New _client_config() helper: Introduced a helper function that prefers the running server's actual configuration but falls back to environment/defaults when no server is running
  • Updated client commands: Modified test and env commands to use _client_config() instead of hardcoded defaults
  • Enhanced test command: Added --host and --port flags to allow explicit overrides when needed
  • Improved status output: Now displays the running server's actual base URL
  • Config serialization: Added to_dict() and from_dict() methods to ServerConfig for JSON persistence
  • Cleanup on stop: The recorded runtime config is cleared when the server stops or a stale pidfile is detected

Implementation Details

  • Runtime configuration is stored in ~/.og-veil/server.json and only exists while the server is running
  • The load_runtime() function checks if a server is actually running (via pidfile) before returning the saved config, ensuring stale configs don't mislead clients
  • Client commands gracefully fall back to environment variables and defaults when no server is running
  • The test command's explicit --host/--port flags take precedence over the discovered configuration

https://claude.ai/code/session_01U1jJ45sjA3o5KtBR4b2TM7

The local server could be started on a non-default port (`serve --port`,
`OG_VEIL_PORT`), but `test`, `env`, and `status` always fell back to
`ServerConfig.from_env()` and assumed 11434 — so `og-veil test` hit the
wrong port and 404'd unless the caller re-exported OG_VEIL_PORT in the same
shell and restarted everything.

Persist the config the background server actually started with to
`server.json` (mirroring the pidfile lifecycle), and have the client
commands read it back:

- config: `runtime_path()` + `ServerConfig.to_dict()`/`from_dict()`.
- daemon: `save_runtime`/`load_runtime`/`clear_runtime`; `load_runtime`
  returns the recorded config only while a server is actually running, and
  the recorded config is cleared on stop and when a stale pidfile is reaped
  (so a server that died on a port conflict can't mislead later commands).
- cli: save the runtime config on a successful background start; `test`,
  `env`, and `status` resolve the host/port from the running server. `status`
  now also prints the live Base URL.
- cli: add `--host`/`--port` overrides to `test` for pointing at a specific
  server, and clarify the help text.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U1jJ45sjA3o5KtBR4b2TM7
@adambalogh adambalogh marked this pull request as ready for review July 9, 2026 14:13
@adambalogh adambalogh merged commit 9adf140 into main Jul 9, 2026
4 checks passed
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.

2 participants