feat(coder): v2.6 Phase 3 — lifecycle hardening (idle evict, crash recovery, worktree reaper)
Idle TTL eviction per (chat,agent) + LRU cap (never a busy backend); pure lifecycle-decisions.ts (TDD). Crash recovery lifts openchamber's health-monitor + busy-aware-restart + stale-grace state machine into opencode-server.ts (+ port reclaim) and warm-acp.ts; opencode crash -> fresh sessions, ACP -> re-session/new. F.1 turn-guard + U.6 usage preserved (their tests pass). Orphan worktree reaper (1h grace, superset-style dirty/unpushed preflight, Paseo soft-delete) + close hooks + diff re-baseline after apply_pending. 35 new tests + DB-opt-in reconnect test; 215 coder tests pass; tsc + build clean. Completes v2.6. Follow-ups out of scope: apps/server close-hook caller, 3.7 DiffPanel staging hint, live smokes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ import { clearTaskCommands, setTaskCommands } from './agent-commands-cache.js';
|
||||
import { getManifestCommands } from './provider-commands.js';
|
||||
import { persistExternalAgentTurn } from './agent-turn-persist.js';
|
||||
import { snapshotToWireToolCall, type AcpToolSnapshot } from './acp-tool-snapshot.js';
|
||||
import { agentPool } from './agent-pool.js';
|
||||
import { agentPool, OPENCODE_POOL_KEY } from './agent-pool.js';
|
||||
import { OpenCodeServerBackend } from './backends/opencode-server.js';
|
||||
import { WarmAcpBackend } from './backends/warm-acp.js';
|
||||
import { shouldUseWarmBackend } from './backends/warm-acp-routing.js';
|
||||
@@ -499,9 +499,8 @@ export function createDispatcher(deps: Deps): { start(): void; stop(): Promise<v
|
||||
|
||||
// OpenCode runs ONE server per BooCoder process, shared across all sessions
|
||||
// (the backend multiplexes sessions internally), so it's pooled under a fixed
|
||||
// key rather than per-session. Warm ACP backends (Phase 2) will be per-session.
|
||||
const OPENCODE_POOL_KEY = '__opencode_server__';
|
||||
|
||||
// key (OPENCODE_POOL_KEY, shared with the lifecycle close-hook) rather than
|
||||
// per-session. Warm ACP backends (Phase 2) are per (chat, agent).
|
||||
function getOpenCodeBackend(installPath: string | null): AgentBackend {
|
||||
let backend = agentPool.get(OPENCODE_POOL_KEY, 'opencode');
|
||||
if (!backend) {
|
||||
@@ -710,6 +709,9 @@ export function createDispatcher(deps: Deps): { start(): void; stop(): Promise<v
|
||||
signal: ac.signal,
|
||||
onEvent,
|
||||
});
|
||||
// Phase 3: keep the pooled backend's slot warm across this (possibly long)
|
||||
// turn so the idle sweep measures from turn END, not start.
|
||||
agentPool.touch(OPENCODE_POOL_KEY, agent);
|
||||
|
||||
// Flush any text held back mid-tag at stream end (complete tags stripped).
|
||||
const dcpTail = dcp.flush();
|
||||
@@ -962,6 +964,8 @@ export function createDispatcher(deps: Deps): { start(): void; stop(): Promise<v
|
||||
taskId,
|
||||
modeId: task.mode_id ?? undefined,
|
||||
});
|
||||
// Phase 3: keep the pooled (chat,agent) backend warm across the turn.
|
||||
agentPool.touch(chatId, agent);
|
||||
|
||||
const assistantContent = textChunks.join('').slice(0, 50_000);
|
||||
const reasoningText = reasoningChunks.join('').slice(0, 200_000);
|
||||
|
||||
Reference in New Issue
Block a user