run the agent as a pm2 peer instead of a child of officer
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 <noreply@anthropic.com>
This commit is contained in:
@@ -101,6 +101,31 @@ export async function flushAndSave(): Promise<void> {
|
||||
await saveState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the Anthropic proxy secret out of the *proxy* sidecar's state file.
|
||||
*
|
||||
* The proxy (`officer-anthropic-proxy`) and the agent (`officer-agent`) keep separate state — see
|
||||
* `initPaths`: `DATA_PATH/sidecar/` versus `DATA_PATH/<email>/sidecar/` — so the agent cannot reach
|
||||
* the secret through `getState()`. It used to be handed the secret in env by the main server, and
|
||||
* needing that handoff is precisely why the agent had to be spawned by `officer` (and therefore died
|
||||
* with it). Reading it off disk keeps the two processes independent, with the proxy still the only
|
||||
* writer.
|
||||
*
|
||||
* Returns '' when the secret is not on disk yet: `ensureProxySecret` persists through a 30s debounce,
|
||||
* so a brand-new install has a window where the file exists without it. Callers should treat '' as
|
||||
* "retry later" rather than fatal.
|
||||
*/
|
||||
export function readProxySecretFromDisk(): string {
|
||||
try {
|
||||
const proxyStateFile = join(DATA_PATH, 'sidecar', 'claude-state.json');
|
||||
if (!existsSync(proxyStateFile)) return '';
|
||||
const parsed = JSON.parse(readFileSync(proxyStateFile, 'utf-8')) as Partial<PersistedState>;
|
||||
return parsed.proxySecret ?? '';
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// ── Lockfile ──
|
||||
|
||||
export function acquireLock(): boolean {
|
||||
|
||||
Reference in New Issue
Block a user