mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-05 06:59:42 +02:00
fix(review): breaker reset semantics, trip observability, push template (PR #147)
- Breaker reset is now explicit-only: POST /api/sessions/:id/interactive no
longer unconditionally resets the PTY-exit breaker (that endpoint IS the
frontend's automatic re-attach path, so the breaker could never trip on the
COD-115 crash loop and any tab click silently re-armed it). The route accepts
a schema-validated optional body flag {clearBreaker:true}
(InteractiveStartSchema) and resets only when it is sent.
- Frontend restart control: app.js selectSession keeps the bare auto-attach
(no body, never clears); when the selected session has respawnBlocked it asks
for explicit user confirmation and only then re-POSTs with clearBreaker:true.
respawnBlocked is surfaced via SessionState/toState() (runtime-only, not
restored on boot so recovery can re-attach).
- Trip observability: WebServer.setupSessionListeners() is now idempotent
(skips while refs are attached) and the re-attach routes (/interactive,
/interactive-respawn, /shell) re-run it, restoring the wiring that the exit
handler detaches on every PTY exit — without this the 5th-exit trip had
guaranteed zero listeners (no SSE, no push, no persist, no run-summary).
- Push notification: added SessionRespawnBreakerTripped to PUSH_EVENT_MAP
('Session crash loop stopped', urgency critical) with an exit-count body
branch; previously sendPushNotifications silently no-oped.
- Minor: buildMuxAttachEnv() truecolor param is now actually passed
(codex/gemini, mirrors buildEnvExports); buildClaudeEnv() uses delete for
COLORTERM/CLAUDECODE (same node-pty "KEY=undefined" quirk as COD-115).
- Tests: route tests assert auto-reattach does NOT reset, clearBreaker resets,
invalid flag rejected, and listener re-wiring on /interactive + /shell;
real-wiring lifecycle tests (createSessionListeners/attach/detach) prove the
exit-detach gap and that re-setup keeps the 5th-exit trip observable;
PUSH_EVENT_MAP regression guard.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -246,6 +246,10 @@ export function registerRespawnRoutes(
|
||||
}
|
||||
}
|
||||
|
||||
// Re-attach listener wiring if a prior PTY exit detached it (the wiring exit
|
||||
// handler removes ALL session listeners; idempotent — no-op while still attached).
|
||||
await ctx.setupSessionListeners(session);
|
||||
|
||||
// Start interactive session
|
||||
await session.startInteractive();
|
||||
getLifecycleLog().log({
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
FlickerFilterSchema,
|
||||
QuickRunSchema,
|
||||
QuickStartSchema,
|
||||
InteractiveStartSchema,
|
||||
} from '../schemas.js';
|
||||
import {
|
||||
autoConfigureRalph,
|
||||
@@ -611,6 +612,14 @@ export function registerSessionRoutes(
|
||||
|
||||
app.post('/api/sessions/:id/interactive', async (req) => {
|
||||
const { id } = req.params as { id: string };
|
||||
// Body is optional (auto-reattach callers send none) — same idiom as /interactive-respawn.
|
||||
const bodyResult = req.body
|
||||
? InteractiveStartSchema.safeParse(req.body)
|
||||
: { success: true as const, data: {} as { clearBreaker?: boolean } };
|
||||
if (!bodyResult.success) {
|
||||
return createErrorResponse(ApiErrorCode.INVALID_INPUT, 'Invalid request body');
|
||||
}
|
||||
const { clearBreaker } = bodyResult.data;
|
||||
const session = findSessionOrFail(ctx, id);
|
||||
|
||||
if (session.isBusy()) {
|
||||
@@ -633,9 +642,20 @@ export function registerSessionRoutes(
|
||||
}
|
||||
}
|
||||
|
||||
// COD-118: an explicit user-initiated start clears any tripped PTY-exit
|
||||
// circuit breaker so an intentional restart is never blocked by a prior crash-loop.
|
||||
session.resetRespawnBreaker();
|
||||
// COD-118: ONLY an explicit user-initiated restart (body {clearBreaker:true})
|
||||
// clears a tripped PTY-exit circuit breaker. This endpoint is ALSO the frontend's
|
||||
// automatic re-attach path (selectSession auto-POSTs it for any pid===null
|
||||
// session), so an unconditional reset here would re-arm the exact crash loop
|
||||
// the breaker exists to stop — auto-reattach sends no body and must not clear.
|
||||
if (clearBreaker) {
|
||||
session.resetRespawnBreaker();
|
||||
}
|
||||
// Re-attach listener wiring if a prior PTY exit detached it: the wiring exit
|
||||
// handler removes ALL session listeners (incl. respawnBreakerTripped), and only
|
||||
// session-create/boot-recovery paths ran setupSessionListeners before this fix —
|
||||
// without this, a re-attached session's SSE/terminal/trip events go unobserved.
|
||||
// setupSessionListeners is idempotent (no-op while refs are still attached).
|
||||
await ctx.setupSessionListeners(session);
|
||||
await session.startInteractive();
|
||||
getLifecycleLog().log({
|
||||
event: 'started',
|
||||
@@ -663,6 +683,8 @@ export function registerSessionRoutes(
|
||||
}
|
||||
|
||||
try {
|
||||
// Re-attach listener wiring if a prior PTY exit detached it (see /interactive).
|
||||
await ctx.setupSessionListeners(session);
|
||||
await session.startShell();
|
||||
getLifecycleLog().log({
|
||||
event: 'started',
|
||||
|
||||
Reference in New Issue
Block a user