From 1bc9cc4ab7e6b004268fe4022512ed210b32d5a8 Mon Sep 17 00:00:00 2001 From: Keaton Hoskins Date: Sun, 18 Oct 2026 14:40:21 -0700 Subject: [PATCH] fix(T13890): no warning when session end finds no session (exit 24/31) runBounded takes benign exit codes; the Stop dispatcher's session end passes SESSION_END_BENIGN_EXITS (ExitCode.SESSION_UNBOUND, ExitCode.SESSION_NOT_FOUND), so a Stop with no bound session prints nothing. Other non-zero exits still warn once. Follow-up to #2363 (review-hotfix LOW). Co-Authored-By: Claude Opus 5.5 --- .changeset/hook-stop-benign-session-end.md | 12 ++++++++++++ .../cli/__tests__/stop-dispatch-entry.test.ts | 19 +++++++++++++++++++ packages/cleo/src/cli/stop-dispatch-entry.ts | 15 ++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .changeset/hook-stop-benign-session-end.md diff --git a/.changeset/hook-stop-benign-session-end.md b/.changeset/hook-stop-benign-session-end.md new file mode 100644 index 0000000000..cf39355ea6 --- /dev/null +++ b/.changeset/hook-stop-benign-session-end.md @@ -0,0 +1,12 @@ +--- +id: hook-stop-benign-session-end +tasks: [T13890] +kind: fix +summary: cleo hook stop no longer warns when session end finds no session to end (exit 24 or 31) +--- + +A Stop with no bound session makes `cleo session end` exit with +`E_SESSION_UNBOUND` (24) or `E_SESSION_NOT_FOUND` (31). The Stop dispatcher +printed "session end failed … (exit 24)" for that expected case. Those two +exits are now benign (`SESSION_END_BENIGN_EXITS`). Every other non-zero exit +still prints one warning line. diff --git a/packages/cleo/src/cli/__tests__/stop-dispatch-entry.test.ts b/packages/cleo/src/cli/__tests__/stop-dispatch-entry.test.ts index 915cb7ea81..24d87929e3 100644 --- a/packages/cleo/src/cli/__tests__/stop-dispatch-entry.test.ts +++ b/packages/cleo/src/cli/__tests__/stop-dispatch-entry.test.ts @@ -7,6 +7,7 @@ * @task T13796 */ +import { ExitCode } from '@cleocode/contracts/exit-codes.js'; import { GOAL_TICK_PROVIDER_ENV } from '@cleocode/contracts/goal-runtime.js'; import { describe, expect, it, vi } from 'vitest'; import { @@ -19,6 +20,7 @@ import { processStopDispatchDeps, runBounded, runTickKillable, + SESSION_END_BENIGN_EXITS, type StopDispatchDeps, stopDispatch, type TickRun, @@ -286,6 +288,23 @@ describe('stopDispatch (T13796)', () => { const failed = vi.fn(); await runBounded(process.execPath, ['-e', 'process.exit(3)'], 5000, 'session end', failed); expect(failed.mock.calls[0]?.[0]).toMatch(/session end failed after \d+ ms \(exit 3\)/); + // A Stop with no bound session: session end's no-session exits are benign. + const quiet = vi.fn(); + for (const code of SESSION_END_BENIGN_EXITS) { + await runBounded( + process.execPath, + ['-e', `process.exit(${code})`], + 5000, + 'session end', + quiet, + SESSION_END_BENIGN_EXITS, + ); + } + expect(SESSION_END_BENIGN_EXITS).toEqual([ + ExitCode.SESSION_UNBOUND, + ExitCode.SESSION_NOT_FOUND, + ]); + expect(quiet).not.toHaveBeenCalled(); } finally { const { execFileSync } = await import('node:child_process'); try { diff --git a/packages/cleo/src/cli/stop-dispatch-entry.ts b/packages/cleo/src/cli/stop-dispatch-entry.ts index e25dcd72f8..13de1e2489 100644 --- a/packages/cleo/src/cli/stop-dispatch-entry.ts +++ b/packages/cleo/src/cli/stop-dispatch-entry.ts @@ -43,6 +43,7 @@ import { spawn } from 'node:child_process'; import { existsSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import type { HookJsonValue } from '@cleocode/contracts'; +import { ExitCode } from '@cleocode/contracts/exit-codes.js'; import { GOAL_TICK_PROVIDER_ENV } from '@cleocode/contracts/goal-runtime.js'; /** Harnesses `cleo hook stop` dispatches for. */ @@ -292,12 +293,22 @@ export function processStopDispatchDeps( SESSION_END_WAIT_MS, 'session end', warn, + SESSION_END_BENIGN_EXITS, ); }, warn, }; } +/** + * `cleo session end` exits that only mean there was no session to end (a Stop + * with no bound session): expected, so they print no warning. + */ +export const SESSION_END_BENIGN_EXITS: readonly number[] = [ + ExitCode.SESSION_UNBOUND, + ExitCode.SESSION_NOT_FOUND, +]; + /** * Run a detached process and wait for it at most `waitMs`. A non-zero exit or * a spawn error gets one `warn` line with the duration. Past the wait the @@ -308,6 +319,7 @@ export function processStopDispatchDeps( * @param waitMs - Longest wait. * @param label - Name used in the warning. * @param warn - Receives the diagnostic line. + * @param benignExits - Non-zero exit codes that are expected and get no warning. * @returns Resolves on exit or at the deadline, whichever comes first. */ export function runBounded( @@ -316,6 +328,7 @@ export function runBounded( waitMs: number, label: string, warn: (line: string) => void, + benignExits: readonly number[] = [], ): Promise { return new Promise((done) => { const started = Date.now(); @@ -340,7 +353,7 @@ export function runBounded( if (settled) return; settled = true; clearTimeout(timer); - if (code !== 0) { + if (code !== 0 && (code === null || !benignExits.includes(code))) { warn( `[cleo hook] ${label} failed after ${Date.now() - started} ms (${signal ?? `exit ${code}`})\n`, );