Multi-instance support: registry, cctrace ps, header switcher#10
Merged
Conversation
Running several cctrace sessions at once used to be a port scavenger hunt: the second instance fell back to a random OS-assigned port and nothing pointed at it. Now: - src/instances.ts: every live run registers <data-dir>/instances/<pid>.json (port, project, session id once seen on the wire) and unregisters on exit; entries whose pid died are garbage-collected on every read, so crashes self-heal. - cctrace ps [--json]: list live instances with URL, project, session. - /api/instances on the live server; the web UI header grows a "N more" switcher when sibling instances exist (polled every 15s, live pages only). - Port allocation walks 9317, 9318, ... before resorting to an OS-assigned port, so concurrent runs land on predictable neighbors. Verified with two concurrent live runs against a fake claude: sequential ports (9317 was genuinely occupied), ps table, cross-instance /api/instances with self-marking, zero stale files after exit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running several cctrace sessions at once was a port scavenger hunt — the second instance landed on a random OS port and nothing pointed at it.
What
src/instances.ts(new): live-instance registry under<data-dir>/instances/<pid>.json— port, project, log file, and the Claude session id once it appears on the wire (via a newonSessionhook in the server). Unregisters on exit; dead-pid entries are GC'd on every read, so crashes self-heal.cctrace ps [--json]: table of live instances — URL, PID, project, session, started./api/instanceson the live server (self-marked); the web UI header shows a "⇄ N more" switcher when sibling instances exist (15s poll, live pages only — snapshots never fetch).Verification
tests/instances.test.ts: register/list/update/unregister, dead-pid + unparseable-file GC, sort order)pslisted both;/api/instancesfrom one showed the other withself: false; both registry files gone after exit🤖 Generated with Claude Code