From 62dc4c1a5c6dab4b2b9f30a55a10054b9cc18cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Thu, 30 Jul 2026 04:34:01 +0000 Subject: [PATCH] run the agent as a pm2 peer instead of a child of officer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the process that runs claude (sidecar/claude/user-instance.ts) had no pm2 entry and was spawned on demand by the main server, with stdout/stderr inherited. that made every agent session a grandchild of officer, so pm2's tree-kill took the session down on every `pm2 restart officer` — the single thing that makes it impossible to work on the platform while an agent is running. give it its own entry (officer-agent) and delete the spawn machinery: ensureClaudeSidecar, spawnAndWaitForRegistration, the 50ms registration poll and the per-email claudeProcs/claudeSpawnWaiters maps, ~77 lines. officer now spawns no sidecar at all. for that to work the sidecar had to stop needing officer to start: - it resolves the owner from the database (getOwnerUser) instead of reading CLAUDE_USER_EMAIL out of the env officer built. single-user is a hard invariant, so there is nothing to fan out over. CLAUDE_USER_EMAIL still wins when set, for manual runs, and a fresh install waits for bootstrap rather than exiting into a restart loop. - it reads the anthropic proxy secret from the proxy sidecar's own state file rather than being handed it in env. lazily, because ensureProxySecret persists on a 30s debounce and pm2 starts both processes together. it registers as 'agent' with capability 'claude', so the registry finds it the way it finds every other sidecar. that removes the email argument from killClaude, interruptClaude and clearClaudeSession, which only ever existed to locate a per-email sidecar by name. what officer keeps is a short wait-for-capability, because pm2 brings peers up together and the first request after a boot can beat the sidecar's registration. also align the two officer port fallbacks in the sidecar (5000 for the socket, 9010 for the rest base) — same instance, so they cannot disagree. this fixes R1 and R2 from CLAUDE_SIDECAR_ISOLATION.md. events produced while officer is down are still lost; that is stage 2. Co-Authored-By: Claude Opus 4.8 --- docs/navigation-audit.md | 207 +++++++++++++++++++ ecosystem.config.cjs | 10 + src/databases/officer_db/src/index.ts | 1 + src/databases/officer_db/src/queries/auth.ts | 8 + src/servers/api/chat/websocket.ts | 2 +- src/servers/channels/send-claude-code.ts | 6 +- src/servers/sidecar-registry.ts | 130 +++--------- src/servers/sidecar/claude/state.ts | 25 +++ src/servers/sidecar/claude/user-instance.ts | 73 +++++-- 9 files changed, 340 insertions(+), 122 deletions(-) create mode 100644 docs/navigation-audit.md diff --git a/docs/navigation-audit.md b/docs/navigation-audit.md new file mode 100644 index 00000000..6207f530 --- /dev/null +++ b/docs/navigation-audit.md @@ -0,0 +1,207 @@ +# Frontend Navigation Audit — the "opaque click" anti-pattern + +**Date:** 2026-07-30 · **Branch:** `sidecars-claude` · **Status:** exploration + documentation only (no code changed) + +Prep work for the upcoming **full navigation refactor**. This catalogues every place the frontend +navigates to / selects an **addressable entity** using a `