diff --git a/packages/dsh-loopx-plugin/README.md b/packages/dsh-loopx-plugin/README.md index fa051dc690..20d219cfbc 100644 --- a/packages/dsh-loopx-plugin/README.md +++ b/packages/dsh-loopx-plugin/README.md @@ -549,9 +549,21 @@ pre-step revalidation order remains authoritative. DSH's LLM retry plugin owns provider-request retries. For CLI calls, this Driver retries only safe fixed-argv LoopX reads and an idempotent `quota should-run` receipt, at most twice beyond the first attempt. Every retry uses the same -`--turn-instance-id`. Typed authority denials, incompatible schemas, -cancellation, and human input are never retried. There is no cumulative -eight-failure breaker or plugin-owned durable activation state. The small +`--turn-instance-id`. If a saved quota page loses its CLI response, retry +only that page with the same reference, selection and offset. This also +applies during pre-step revalidation. Typed authority denials, incompatible schemas, +cancellation, and human input are never retried. + +On macOS and Linux, the plugin cancels commands in the process group it started +and waits for that group and its output pipes before retrying a timed-out read. +If cleanup cannot be confirmed, it stops the attempt. This does not guarantee +cleanup of a process that starts its own session, or of descendants on Windows. + +GoalBar never retries a lifecycle write. If no result can be verified, refresh +to read the Goal's current state before trying the action again. + +There is no cumulative eight-failure breaker or plugin-owned durable activation +state. The small process-local activation projection is bound to one exact Session and is reconstructed only from its typed event history. Exhausting the three attempts stops that evaluation; it does not create a periodic error-retry loop. Only a @@ -635,7 +647,6 @@ cd packages/dsh-loopx-plugin DSH_BIN="$(command -v dsh)" ./install.sh dsh --profile web --dump-config ``` - The installer rejects an incompatible host before changing its profile. A successful profile contains `loopx-goalbar`, `loopx-init-command`, `loopx-driver`, and the passive `loopx-shadow-observer` in that order. The installer also reads diff --git a/packages/dsh-loopx-plugin/src/cli.ts b/packages/dsh-loopx-plugin/src/cli.ts index 506a36a9d9..e99090a874 100644 --- a/packages/dsh-loopx-plugin/src/cli.ts +++ b/packages/dsh-loopx-plugin/src/cli.ts @@ -1,5 +1,6 @@ -import { spawn } from 'node:child_process' +import { execFile, spawn } from 'node:child_process' import { statSync } from 'node:fs' +import { setTimeout as delay } from 'node:timers/promises' // 1.2.4 includes the released Windows peer-file fix. Bootstrap and every // runtime consumer must use the same floor, including an existing global CLI. @@ -116,12 +117,64 @@ export interface ResolveLoopXCommandOptions { const DEFAULT_TIMEOUT_MS = 20_000 const DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024 const FORCE_KILL_GRACE_MS = 250 +const CLEANUP_CONFIRM_MS = 1_000 +const PS = process.platform === 'darwin' ? '/bin/ps' : '/usr/bin/ps' -function transportKind(error: NodeJS.ErrnoException): LoopXCliError { +// Match the managed Host's local process-group boundary. This npm package +// also runs standalone with older Core CLIs and cannot load their TS internals. +function signalOwnedGroup(pgid: number, signal: NodeJS.Signals | 0): boolean { + try { + process.kill(-pgid, signal) + return true + } catch (error) { + if ((error as NodeJS.ErrnoException).code === 'ESRCH') return false + throw error + } +} + +async function confirmGroupStopped(pgid: number): Promise { + const deadline = performance.now() + CLEANUP_CONFIRM_MS + for (;;) { + const remaining = Math.ceil(deadline - performance.now()) + if (remaining <= 0) throw new Error('CLI group did not exit') + try { + if (!signalOwnedGroup(pgid, 0)) return + } catch (error) { + // Darwin may return EPERM for an unreaped, dead group. Check process + // state; lack of permission to signal is not proof of termination. + if ((error as NodeJS.ErrnoException).code !== 'EPERM') throw error + } + const rows = await new Promise((resolve, reject) => { + execFile(PS, ['-A', '-o', 'pgid=', '-o', 'stat='], { + encoding: 'utf8', timeout: remaining, killSignal: 'SIGKILL', maxBuffer: 1024 * 1024, + env: { LC_ALL: 'C', PATH: '/usr/bin:/bin' }, + }, (error, stdout) => { if (error) reject(error); else resolve(stdout) }) + }) + if (performance.now() >= deadline || !rows.trim()) throw new Error('CLI group observation unavailable') + let live = false + for (const row of rows.trim().split('\n')) { + const [, group, state] = /^\s*(\d+)\s+(\S+)\s*$/u.exec(row) ?? [] + if (group === undefined || state === undefined) throw new Error('Invalid CLI group observation') + if (Number(group) === pgid && !state.startsWith('Z')) live = true + } + if (!live) return + await delay(10) + } +} + +function transportKind(error: NodeJS.ErrnoException, spawned: boolean): LoopXCliError { if (error.code === 'ENOENT') { return new LoopXCliError('missing', 'required executable is unavailable', false, undefined, { osCode: error.code }) } - return new LoopXCliError('transport', 'could not start the LoopX command', true, undefined, { osCode: error.code }) + return new LoopXCliError('transport', spawned ? 'LoopX command I/O failed' : 'could not start the LoopX command', + true, undefined, { osCode: error.code }) +} + +// A non-retryable transport means the adapter could not safely continue to a +// second child. Keep launch/probe fallbacks from interpreting it as "missing." +export function isUnsafeToContinue(error: unknown): boolean { + return error instanceof LoopXCliError + && (error.kind === 'aborted' || (error.kind === 'transport' && !error.retryable)) } export const runFile: FileRunner = (file, args, options) => new Promise((resolve, reject) => { @@ -130,10 +183,12 @@ export const runFile: FileRunner = (file, args, options) => new Promise((resolve return } + const posix = process.platform !== 'win32' const child = spawn(file, [...args], { cwd: options.cwd, env: options.env ?? process.env, shell: false, + detached: posix, stdio: ['ignore', 'pipe', 'pipe'], }) const stdout: Buffer[] = [] @@ -143,17 +198,59 @@ export const runFile: FileRunner = (file, args, options) => new Promise((resolve let settled = false let terminalError: LoopXCliError | undefined let forceKillTimer: ReturnType | undefined + const closed = Promise.withResolvers() + const group = posix && child.pid !== undefined && child.pid > 1 ? child.pid : undefined const cleanup = (): void => { clearTimeout(timer) if (forceKillTimer !== undefined) clearTimeout(forceKillTimer) options.signal?.removeEventListener('abort', abort) } + const rejectOnce = (error: LoopXCliError): void => { + if (settled) return + settled = true + cleanup() + reject(error) + } const fail = (error: LoopXCliError): void => { if (settled || terminalError !== undefined) return terminalError = error clearTimeout(timer) options.signal?.removeEventListener('abort', abort) + if (child.pid === undefined) { + rejectOnce(error) + return + } + if (group !== undefined) { + void (async () => { + try { + if (signalOwnedGroup(group, 'SIGTERM')) { + await delay(FORCE_KILL_GRACE_MS) + signalOwnedGroup(group, 'SIGKILL') + } + await confirmGroupStopped(group) + // If a descendant escaped the group with these pipes, cleanup of + // the owned group does not make this operation safe to retry. + await Promise.race([ + closed.promise, + delay(CLEANUP_CONFIRM_MS, undefined, { ref: false }).then(() => { + throw new Error('CLI output pipes did not close') + }), + ]) + rejectOnce(error) + } catch { + child.stdout.destroy() + child.stderr.destroy() + rejectOnce(new LoopXCliError( + 'transport', 'LoopX CLI process cleanup was not confirmed', false, undefined, + { causeKind: error.kind }, + )) + } + })() + return + } + // Keep the direct-child/reap path on Windows. Node does not give this + // adapter a Job Object that it owns after the command leader has exited. child.kill('SIGTERM') forceKillTimer = setTimeout(() => { if (!settled) child.kill('SIGKILL') @@ -178,15 +275,19 @@ export const runFile: FileRunner = (file, args, options) => new Promise((resolve options.signal?.addEventListener('abort', abort, { once: true }) child.stdout.on('data', (chunk: Buffer) => collect(stdout, chunk)) child.stderr.on('data', (chunk: Buffer) => collect(stderr, chunk)) - child.on('error', (error: NodeJS.ErrnoException) => fail(transportKind(error))) + const onTransportError = (error: NodeJS.ErrnoException) => fail(transportKind(error, child.pid !== undefined)) + child.stdout.on('error', onTransportError) + child.stderr.on('error', onTransportError) + child.on('error', onTransportError) child.on('close', code => { + closed.resolve() if (settled) return - settled = true - cleanup() if (terminalError !== undefined) { - reject(terminalError) + if (group === undefined) rejectOnce(terminalError) return } + settled = true + cleanup() resolve({ exitCode: code ?? 1, stdout: Buffer.concat(stdout).toString('utf8'), @@ -266,13 +367,12 @@ export async function runJsonMutationCommand( }, ) } catch (error: unknown) { - throw error instanceof LoopXCliError - ? error - : new LoopXCliError( - 'transport', - 'LoopX mutation command failed to execute', - false, - ) + if (error instanceof LoopXCliError) { + throw error.retryable + ? new LoopXCliError(error.kind, error.message, false, error.exitCode, error.diagnostics) + : error + } + throw new LoopXCliError('transport', 'LoopX mutation command failed to execute', false) } const payload = parsePayload(result.stdout) @@ -447,7 +547,7 @@ export async function resolveLoopXCommand( if (options.signal?.aborted) { throw new LoopXCliError('aborted', 'operation was cancelled', false) } - if (error instanceof LoopXCliError && error.kind === 'aborted') throw error + if (isUnsafeToContinue(error)) throw error const failure = error instanceof LoopXCliError ? error : new LoopXCliError('transport', 'LoopX version probe failed to execute', false) probes.push(new LoopXCliError(failure.kind, 'version probe failed', false, failure.exitCode, { diff --git a/packages/dsh-loopx-plugin/src/driver.ts b/packages/dsh-loopx-plugin/src/driver.ts index 5f144538cf..131f0c595f 100644 --- a/packages/dsh-loopx-plugin/src/driver.ts +++ b/packages/dsh-loopx-plugin/src/driver.ts @@ -356,7 +356,7 @@ const QUOTA_REQUIRED_POINTERS = ['/ok', '/mode', '/goal_id', '/should_run', '/ag const QUOTA_RECEIPT_POINTER = '/heartbeat_receipt' const QUOTA_OPTIONAL_POINTERS = [QUOTA_RECEIPT_POINTER, '/scheduler_hint', '/reward_memory_recall'] -type QuotaReadOptions = Pick +type QuotaReadOptions = Pick function quotaNavigationReference(payload: Record): string | undefined { if (payload.schema_version !== QUOTA_NAVIGATION_SCHEMA || payload.ok !== true) return undefined @@ -1278,7 +1278,13 @@ export class LoopXContinuationDriver { // The 2.3 CLI supplies immutable navigation and its bounded reader. Older // supported CLIs continue to answer this Host-only call with raw JSON. const progressive = supportedLoopXVersion(command.version, '2.3.0') !== undefined - const options = { runner: this.runner, cwd: agent.session.header.cwd, signal } + const options = { + runner: this.runner, + cwd: agent.session.header.cwd, + signal, + attempts: 3, + retryDelaysMs: this.retryDelaysMs, + } const rawAdmission = (payload: Record) => payload.goal_id === binding.goalId && typeof payload.ok === 'boolean' && typeof payload.should_run === 'boolean' const quota = await runJsonCommand( @@ -1295,15 +1301,13 @@ export class LoopXContinuationDriver { ], { ...options, - attempts: 3, - retryDelaysMs: this.retryDelaysMs, ...(progressive ? {} : { env: { ...process.env, LOOPX_CONTEXT_DELIVERY: 'off' } }), validate: payload => rawAdmission(payload) || (progressive && quotaNavigationReference(payload) !== undefined), }, ) const reference = progressive ? quotaNavigationReference(quota) : undefined if (reference === undefined) return quota - // Reading a saved capture is outside the guard's transport retry. + // Retry the exact saved page on transport loss, outside the guard retry. const decision = await readQuotaCapture(command, reference, options, revalidateOnly) if (!rawAdmission(decision)) { throw new LoopXCliError('invalid_schema', 'LoopX quota capture did not match the bound Goal', false) diff --git a/packages/dsh-loopx-plugin/src/goalbar/service.ts b/packages/dsh-loopx-plugin/src/goalbar/service.ts index f6f44b8dcd..d09445114f 100644 --- a/packages/dsh-loopx-plugin/src/goalbar/service.ts +++ b/packages/dsh-loopx-plugin/src/goalbar/service.ts @@ -697,7 +697,8 @@ export class GoalBarService implements GoalBarServiceHandle { } catch { return { kind: 'unknown', code: 'operation_result_unknown' } } finally { - // The runner promise settles only after child close, including forced kill. + // Release the local operation after the runner has verified the result + // or reported it unknown. Never replay a lifecycle mutation here. admission.resolveMutation() } if (!verified) return { kind: 'unknown', code: 'operation_result_unknown' } diff --git a/packages/dsh-loopx-plugin/src/init-command.ts b/packages/dsh-loopx-plugin/src/init-command.ts index 0aacf700eb..6ab416538f 100644 --- a/packages/dsh-loopx-plugin/src/init-command.ts +++ b/packages/dsh-loopx-plugin/src/init-command.ts @@ -7,6 +7,7 @@ import type { UserMessage } from '@deepseek-ai/dsh-session' import { LoopXCliError, MINIMUM_LOOPX_VERSION, + isUnsafeToContinue, resolveLoopXCommand, runFile, runJsonCommand, @@ -183,7 +184,7 @@ async function compatible( && payload.host_surface === HOST_SURFACE && typeof payload.install_required === 'boolean' } catch (error: unknown) { - if (error instanceof LoopXCliError && error.kind === 'aborted') throw error + if (isUnsafeToContinue(error)) throw error return false } } @@ -236,7 +237,7 @@ async function resolveInstallPython(options: LoopXInitOptions): Promise ) if (pipResult.exitCode === 0) return python } catch (error: unknown) { - if (error instanceof LoopXCliError && error.kind === 'aborted') throw error + if (isUnsafeToContinue(error)) throw error } } throw new LoopXInitError( @@ -324,7 +325,7 @@ export async function initializeLoopX(options: LoopXInitOptions = {}): Promise { readOnlyFromGuard: 1 }, { route: 'read-only paged revalidation', version: 'loopx 2.3.0', setting: 'on', readerCalls: 4, readOnlyFromGuard: 3, readOnlyPageBytes: '256' }, + { route: 'lost response on a later page', version: 'loopx 2.3.0', setting: 'on', readerCalls: 4, + readOnlyFromGuard: 3, readOnlyPageBytes: '256', loseReaderResponse: true }, ])('settles the queued exact receipt once through $route admission', async ({ - route, version, setting, readerCalls, readOnlyFromGuard, readOnlyPageBytes, + route, version, setting, readerCalls, readOnlyFromGuard, readOnlyPageBytes, loseReaderResponse, }) => { const testFixture = await fixture() const warnings: string[] = [] @@ -312,6 +314,8 @@ describe('DSH admission-to-closeout integration', () => { let reads = 0 let inlinePages = 0 let inlineContinuations = 0 + let lostPage: { argv: readonly string[]; stdout: string } | undefined + let recoveredPage = false const runner: FileRunner = async (file, args, options) => { if (args.includes('context-read')) reads += 1 if (args.includes('should-run')) { @@ -332,6 +336,17 @@ describe('DSH admission-to-closeout integration', () => { if (page.offset !== 0) { inlineContinuations += 1 expect(readerArgs).toContain('--selection-sha256') + if (loseReaderResponse && lostPage === undefined) { + lostPage = { argv: readerArgs, stdout: response.stdout } + // The original Core read succeeded, but its output was lost + // before the Driver could observe it. + throw new LoopXCliError('transport', 'synthetic reader response loss', true) + } + if (lostPage !== undefined && !recoveredPage) { + expect(readerArgs).toEqual(lostPage.argv) + expect(response.stdout).toEqual(lostPage.stdout) + recoveredPage = true + } } return response } @@ -379,6 +394,11 @@ describe('DSH admission-to-closeout integration', () => { async () => ({ kind: 'enter', messages: [queued] }), ) expect(admission.kind).toBe('enter') + if (loseReaderResponse) { + expect(recoveredPage).toBe(true) + expect(warnings).toEqual([]) + expect(testFixture.queued).toHaveLength(0) + } // The Driver intentionally revalidates before and after the next pre-step hook. expect(guardCalls).toBe(3) if (readOnlyPageBytes) { @@ -565,7 +585,7 @@ describe('DSH admission-to-closeout integration', () => { } }, 45_000) - it.each(['held', 'digest mismatch', 'inline digest mismatch', 'paged'] as const)( + it.each(['held', 'digest mismatch', 'inline digest mismatch', 'paged', 'transport exhausted'] as const)( 'keeps one guard when the progressive capture is %s', async scenario => { const testFixture = await fixture() @@ -575,6 +595,7 @@ describe('DSH admission-to-closeout integration', () => { const warnings: string[] = [] let guards = 0 let reads = 0 + const lostReads: string[][] = [] const runner: FileRunner = async (file, args, options) => { const child = { ...options, env: { ...options.env, LOOPX_CONTEXT_DELIVERY: 'on' } } if (args.includes('context-read')) { @@ -591,7 +612,13 @@ describe('DSH admission-to-closeout integration', () => { expect(page.schema_version).toBe('context_capture_page_v1') return { ...response, stdout: JSON.stringify({ ...page, selection_sha256: '0'.repeat(64) }) } } - return realLoopXRunner(file, readerArgs, child) + const response = await realLoopXRunner(file, readerArgs, child) + if (scenario === 'transport exhausted') { + expect(record(JSON.parse(response.stdout)).ok).toBe(true) + lostReads.push(readerArgs) + throw new LoopXCliError('transport', 'synthetic reader response loss', true) + } + return response } if (!args.includes('should-run')) return realLoopXRunner(file, args, child) guards += 1 @@ -625,7 +652,13 @@ describe('DSH admission-to-closeout integration', () => { driver.observeAgent(testFixture.agent) await evaluated expect(guards).toBe(1) - if (scenario === 'digest mismatch' || scenario === 'inline digest mismatch') { + if (scenario === 'transport exhausted') { + expect(reads).toBe(3) + expect(lostReads).toEqual([lostReads[0], lostReads[0], lostReads[0]]) + expect(testFixture.queued).toHaveLength(0) + expect(warnings).toHaveLength(1) + expect(warnings[0]).toContain('admission_failed stage=quota kind=transport') + } else if (scenario === 'digest mismatch' || scenario === 'inline digest mismatch') { expect(reads).toBe(1) expect(testFixture.queued).toHaveLength(0) expect(warnings).toHaveLength(1) diff --git a/packages/dsh-loopx-plugin/tests/cli.spec.ts b/packages/dsh-loopx-plugin/tests/cli.spec.ts index d6442da47c..bec28b8140 100644 --- a/packages/dsh-loopx-plugin/tests/cli.spec.ts +++ b/packages/dsh-loopx-plugin/tests/cli.spec.ts @@ -1,3 +1,7 @@ +import { execFileSync } from 'node:child_process' +import { mkdtempSync, readFileSync, rmSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' import { describe, expect, it } from 'vitest' import { LoopXCliError, @@ -313,3 +317,89 @@ describe('reap-aware mutation execution', () => { }]) }) }) + +describe.skipIf(process.platform === 'win32')('owned CLI process group', () => { + it.each(['timeout', 'abort', 'mutation', 'escaped pipe'] as const)( + 'retires a descendant holding an inherited pipe on %s before returning or retrying', + async mode => { + const dir = mkdtempSync(join(tmpdir(), 'loopx-cli-child-')) + const childPidFile = join(dir, 'child-pid') + const signal = new AbortController() + const cli = { ...command, file: process.execPath } + const child = [ + "process.on('SIGTERM', () => {})", + 'setTimeout(() => {}, 5000)', + ].join(';') + const fixture = [ + 'const {spawn} = require("node:child_process")', + 'const {writeFileSync} = require("node:fs")', + 'const [code, path, mode] = process.argv.slice(1)', + 'const child = spawn(process.execPath, ["-e", code], {stdio: "inherit", detached: mode === "escaped pipe"})', + 'writeFileSync(path, String(child.pid))', + // The grandchild keeps the pipe open after the CLI leader is gone. + 'process.exit(0)', + ].join(';') + const live = (pid: number): boolean => { + try { + const state = execFileSync('ps', ['-p', String(pid), '-o', 'stat='], { + encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], + }).trim() + return !state.startsWith('Z') + } catch (error) { + if ((error as { status?: number }).status === 1) return false + throw error + } + } + let attempts = 0 + let descendantAliveAfterFirst: boolean | undefined + const pid = () => Number(readFileSync(childPidFile, 'utf8')) + const runner: FileRunner = (_file, _args, options) => { + attempts += 1 + if (attempts === 1) { + return runFile(process.execPath, ['-e', fixture, child, childPidFile, mode], options) + } + descendantAliveAfterFirst = live(pid()) + return runFile(process.execPath, ['-e', 'console.log(JSON.stringify({ok:true}))'], options) + } + const options = { runner, timeoutMs: 750 } + const operation = mode === 'mutation' + ? runJsonMutationCommand(cli, [], options) + : runJsonCommand(cli, [], { + ...options, signal: signal.signal, attempts: 2, retryDelaysMs: [0], + }) + // Attach the failure observer before scheduling abort or a bounded test + // deadline so neither test path leaves an unhandled rejection. + const observed = operation.catch((error: unknown) => error) + try { + if (mode === 'abort') { + await expect.poll(pid, { timeout: 600 }).toBeGreaterThan(1) + signal.abort() + } + const pending = Symbol('pending after cleanup') + let timer: ReturnType | undefined + const outcome = await Promise.race([ + observed, + new Promise(resolve => { timer = setTimeout(() => resolve(pending), 3200) }), + ]).finally(() => { clearTimeout(timer) }) + expect(outcome).not.toBe(pending) + expect(live(pid())).toBe(mode === 'escaped pipe') + if (mode === 'timeout') { + expect(outcome).toEqual({ ok: true }) + expect(attempts).toBe(2) + expect(descendantAliveAfterFirst).toBe(false) + } else { + expect(outcome).toMatchObject({ + kind: mode === 'mutation' ? 'timeout' : mode === 'escaped pipe' ? 'transport' : 'aborted', + retryable: false, + }) + expect(attempts).toBe(1) + } + } finally { + try { const childPid = pid(); if (live(childPid)) process.kill(childPid, 'SIGKILL') } catch {} + await observed + rmSync(dir, { recursive: true, force: true }) + } + }, + 10_000, + ) +}) diff --git a/packages/dsh-loopx-plugin/tests/init-command.spec.ts b/packages/dsh-loopx-plugin/tests/init-command.spec.ts index 6937e150f5..90d22649a1 100644 --- a/packages/dsh-loopx-plugin/tests/init-command.spec.ts +++ b/packages/dsh-loopx-plugin/tests/init-command.spec.ts @@ -234,6 +234,24 @@ describe('automatic DSH bootstrap', () => { }) describe('/loopx-init implementation', () => { + it.each(['version', 'inspect'] as const)( + 'does not replace a runtime whose %s probe could not be cleaned up safely', + async stage => { + const calls: string[][] = [] + const runner: FileRunner = async (_file, args) => { + calls.push([...args]) + if (stage === 'inspect' && args.includes('--version')) { + return { exitCode: 0, stdout: 'loopx 2.3.0\n', stderr: '' } + } + throw new LoopXCliError('transport', 'CLI cleanup not confirmed', false) + } + await expect(initializeLoopX({ runner, skillsDir: '/fixture/skills' })) + .rejects.toMatchObject({ kind: 'transport', retryable: false }) + expect(calls).toHaveLength(stage === 'version' ? 1 : 2) + expect(calls.flat()).not.toContain('--install') + }, + ) + it('keeps a compatible CLI and installs plus verifies the DSH skills', async () => { const calls: string[][] = [] let inspectCount = 0 diff --git a/skills/loopx-self-repair/references/repair-patterns.md b/skills/loopx-self-repair/references/repair-patterns.md index 5753a1733b..7c907d7583 100644 --- a/skills/loopx-self-repair/references/repair-patterns.md +++ b/skills/loopx-self-repair/references/repair-patterns.md @@ -159,6 +159,8 @@ teaches a reusable control-plane lesson. | `future_monitor_heartbeat_liveness_overreach` | A valid future-scheduled monitor repeatedly enters `frontier_exhausted_monitor_lane` or `dead_monitor_repeat` even though it is not due and no real monitor execution occurred. | generated heartbeat guard command, trigger `current_time_iso`, quota `heartbeat_receipt`, monitor Todo `next_due_at`, run-history `quota_monitor_poll` rows, concrete Todo/target identity, and monitor mode. | Future wait state was collapsed into empty-frontier exhaustion, while distinct heartbeat turn ids were treated as monitor executions and lowered the dead-monitor threshold. | Add typed `future_monitor_wait` and `due_monitor_execution` frontier rules. Keep future monitors quiet/no-spend until due; count `dead_monitor_repeat` only from unchanged due/external executions carrying a concrete Todo or target identity. Heartbeat turn ids remain idempotency/liveness evidence and never reduce the real execution threshold. | | `replan_context_delivery_gap` | A replan obligation is visible, but a weak protocol-following model ignores or mis-executes a manual evidence-log read ritual, then spends turns debugging ACK/read order instead of choosing a new direction. | current obligation id, host-projected `replan_context_v0`, compact coverage ledger, delivery receipt, typed action packet, selected model tool action, semantic writeback receipt, and successor turn boundary. | Evidence access was modeled as an agent CLI obligation even though the control plane already owned the ledger; read execution and semantic use were conflated. A separate Todo-add then refresh ACK also let the model execute the successor in the replan turn. | Have the host prefetch and project bounded evidence coverage into quota. Treat the delivery receipt as context delivery only; require the model's real next action to produce an accepted typed semantic delta bound to the current obligation. When the delta is a runnable successor, bind the exact obligation on the Todo write itself and return `end_current_heartbeat`; do not require a second ACK or run the successor in that turn. Remove the standalone evidence command and generated read rituals. Reuse the typed replan context for the core Goal, dense scoped decision evidence, repetition reduction and exact history-reference reads. Keep replan selection independent of the routine display window, and validate novelty against complete available history even when the readable context is truncated; reject malformed schemas and unavailable references instead of treating them as empty evidence. Preserve the durable history and historical receipt decoder, not a compatibility command. Cover real quota→model action→Todo/refresh CLI behavior plus missing/wrong obligation identity. | | `machine_cli_capture_projection_gap` | A native hook or non-model JSON consumer treats context navigation as the effective decision and denies ready work because a top-level admission field is absent. | Original child argv/runtime profile; outer schema versus the same immutable captured Core decision; parent/child context settings; real Core ready, user-gate and zero-quota cases. | Model-facing context transport wrapped the formerly inline machine payload. A locator is not a policy decision; a locale/codec repair alone cannot restore this path. | Use the existing machine-output contract only for the non-model child process, retaining Core gates, identity, UTF-8 and environment isolation. Reuse the established per-child `LOOPX_CONTEXT_DELIVERY=off`; do not disable model context globally or interpret navigation `ok` as admission. Actual model consumers must follow the original readers and retain current bytes/digests. Validate ready, user-gate and zero-quota behavior with parent context on/off unchanged; distinguish source, installed-host and live-model qualification. | +| `dsh_quota_capture_read_transport_loss` | DSH abandons a continuation after LoopX has saved its admission and a quota reader subprocess fails to return a page. | Compare the original Turn receipt, recorded reader arguments and page cursor with the subsequent reservation and settlement records. Separate lost transport from a typed denial or changed digest. | Guard transport retry did not apply to the separate read of its saved capture. | Retry the same verified page with the existing bounded CLI retry. Preserve the reference, offset, selection digest, cancellation, identity revalidation and queue ownership. Verify with a lost response on a later page, an unrecoverable read and the complete original-Turn settlement. | +| `cli_descendant_holds_timeout_pipe` | A CLI deadline has elapsed and the leader exited, but the host still waits for output held open by a descendant. | Compare the leader and owned group state, stdout/stderr closure, and the retry or mutation readback. Reproduce in an isolated process group. | Killing the direct child does not retire its inherited pipe writers. A closed pipe is not proof that a writer stopped. | Confirm cleanup of the command's owned group and drain its pipes before retrying a safe read. An escaped writer or unverifiable cleanup must not authorize replay or a fallback install. A mutation keeps its unknown-result and authoritative readback path; do not kill unrelated process trees. Keep POSIX group, detached-session and Windows evidence separate. | | `native_policy_test_consumer_navigation` | A source-owned policy smoke intentionally exercises native output but raises `KeyError` on an admission field, or mistakes navigation `ok` for decision readiness. | Original CLI result and the same current immutable recovery, unchanged semantic assertions, and full connection/own-Todo readback. | The test helper decoded only outer JSON and treated the model-facing navigation envelope as the policy. This differs from the machine-output host adapter in `machine_cli_capture_projection_gap`. | Reuse the existing test-only `read_cli_policy_payload` oracle to verify the current complete recovery; preserve inline results, nonzero exits, physical-file/digest checks and all original semantic assertions. Keep native output enabled for this qualification. Test generic/domain connection and the caller's own first Todo through the real CLI, plus failed/inline/native and damaged-reference cases. Isolate temporary runtimes and telemetry before child invocation and retire only authenticated test-owned runtimes before removing their directory. The oracle proves test observations, not model retention, execution authority or whole-Goal benefit. | | `replan_settlement_binding_projection_gap` | A replan packet and selected Todo are both visible, so an agent combines `--todo-id` with `--replan-obligation-id`, alternates between them after rejection, or performs the Todo-bound refresh but omits the matching spend. | Original quota receipt identity, selected Todo, semantic obligation id, interaction settlement plan, projected refresh/spend commands, and accepted semantic ACK. | The semantic obligation target and causal settlement identity were adjacent but unlabeled, while one boolean conflated direct obligation binding with whether a full settlement chain was required. | Keep exactly one causal settlement binding. For a turn-scoped executable plan, project a domain-local typed replan settlement contract that labels the selected Todo or Todo-less obligation as the binding and keeps the replan id as a separate semantic target when necessary. Todo-bound and directly bound replan writes both project material refresh followed by spend; never combine their CLI flags. Keep unscoped diagnostic reads compact and non-executable. Cover TS projection, hot-path envelope, real Todo-bound/Todo-less CLI chains, output budget, and in-flight delivery continuity. | | `native_goal_todoless_replan_reentry_gap` | A native visible Goal completes all advancement Todos, semantic closeout derives a Todo-less autonomous replan obligation, and the next unbound quota read projects a bare refresh with no Turn identity or spend chain. | Native Goal runtime profile, selected Todo absence, replan obligation id, interaction CLI actions before and after Turn creation, and settlement identity. | Native-Goal Turn re-entry recognized only selected Todos as actionable settlement bindings and ignored a valid Todo-less replan obligation. | Treat either a selected Todo or a valid replan obligation as a native-Goal settlement binding. When no Turn or settlement plan exists, project only the exact `quota should-run ... --begin-turn` re-entry. After execution, require the obligation-bound refresh and spend chain; keep generic unscoped diagnostic behavior unchanged. |