[codex] Refactor control-plane server lifecycle#153
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8371bd91f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| heartbeat = setInterval(() => { | ||
| try { | ||
| registerServer(); |
There was a problem hiding this comment.
Avoid stealing newer live-server ownership
When two lifecycle handles coexist (for example an embedded-chat server starts after a daemon, or a daemon is started with the owner guard bypassed), this heartbeat keeps calling registerServer() unconditionally. That lets the older server overwrite the global live-server record after a newer server has registered, so clients can attach to the wrong endpoint until another heartbeat or shutdown changes it; the close path only protects clearLiveServer and does not prevent this refresh from stealing ownership. Check the current serverId before refreshing, or stop the heartbeat once this handle no longer owns the live-server record.
Useful? React with 👍 / 👎.
Summary
Splits reusable control-plane server startup from daemon command behavior.
startHeddleControlPlaneServeras the realsrc/serverlifecycle owner for app creation, asset validation, HTTP listen/close, global live-server registration/heartbeat, known-workspace registration, and heartbeat scheduler coordination.heddle daemoninto a CLI adapter that detects a fresh live server, prints its address, and exits successfully instead of throwing or starting another daemon.process.exit()in CLI/dev entrypoints rather than the reusable server lifecycle.Expected behavior change
After this slice, starting
heddle daemonwhile a fresh control-plane server is already registered no longer fails with a second-daemon conflict. It reports the existing server endpoint and exits successfully.A standalone daemon still starts the same control-plane server path when no fresh server exists, registers itself globally, refreshes its live-server heartbeat, and clears only its own live-server record on shutdown.
Embedded
chat-v2is not wired yet, but it can now use the same lifecycle API later without introducing a TUI-only server path or inheriting daemon-specific process-exit behavior.Validation
yarn typecheckyarn testvitestfor daemon/lifecycle/registry/runtime-host tests