@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
41 lines • 1.86 kB
JavaScript
import { CHILD_STALLED_STOP_MAX_MS_ENV, childStalledStopMaxMs, clearStopProgress, hostLoopStalled, STOP_STALL_EVIDENCE_MAX_AGE_MS, writeStopProgress, } from "./host-stalled-evidence.js";
import { supervisorLog } from "./host-supervisor-log.js";
import { loopLagErrorMs } from "./loop-lag-threshold.js";
const STALL_WAIT_SLICE_MS = 5_000;
/**
* Waits past the ordinary stop window while the child stays stalled, in slices, up to the bound
* measured from `signalledAt`. Returns how long it waited beyond the ordinary window (0 when the child
* was not stalled at all, so the ordinary escalation is unchanged).
*/
export async function waitOutStalledChild(options) {
const { child, generation, signalledAt } = options;
const maxMs = childStalledStopMaxMs();
const untilAt = signalledAt + maxMs;
const stalled = () => hostLoopStalled(generation, {
now: Date.now(),
errorMs: loopLagErrorMs(),
windowMs: STOP_STALL_EVIDENCE_MAX_AGE_MS,
}).catch(() => false);
let waited = 0;
try {
while (Date.now() < untilAt && (await stalled())) {
if (waited === 0)
supervisorLog(`host child is stalled; waiting up to ${maxMs}ms (${CHILD_STALLED_STOP_MAX_MS_ENV})`);
await writeStopProgress(generation, {
at: new Date().toISOString(),
phase: "waiting_stalled_child",
untilAt: new Date(untilAt).toISOString(),
}).catch(() => undefined);
const slice = Math.min(STALL_WAIT_SLICE_MS, untilAt - Date.now());
const exited = await options.waitForExit(child, slice);
waited += slice;
if (exited)
break;
}
}
finally {
await clearStopProgress(generation);
}
return waited;
}
//# sourceMappingURL=host-lifecycle-stall-wait.js.map