Skip to content

Multi-instance support: registry, cctrace ps, header switcher#10

Merged
lroolle merged 1 commit into
mainfrom
feat/multi-instance
Jul 12, 2026
Merged

Multi-instance support: registry, cctrace ps, header switcher#10
lroolle merged 1 commit into
mainfrom
feat/multi-instance

Conversation

@lroolle

@lroolle lroolle commented Jul 12, 2026

Copy link
Copy Markdown
Member

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 new onSession hook 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/instances on 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).
  • Predictable ports: allocation walks 9317, 9318, … 9326 before falling back to an OS-assigned port.

Verification

  • 184/184 tests (10 new in tests/instances.test.ts: register/list/update/unregister, dead-pid + unparseable-file GC, sort order)
  • Real e2e with two concurrent live runs (fake claude): port 9317 was genuinely occupied on this machine, both instances landed on 9318/9319 sequentially; ps listed both; /api/instances from one showed the other with self: false; both registry files gone after exit
  • Replay + cost smoke suites still pass

🤖 Generated with Claude Code

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>
@lroolle lroolle merged commit d359f6b into main Jul 12, 2026
1 check passed
@lroolle lroolle deleted the feat/multi-instance branch July 12, 2026 05:53
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.

1 participant