@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
28 lines • 1.46 kB
JavaScript
import { nextKeyBackoffMs } from "./device-proxy-waits.js";
const MAX_AUTOMATIC_REISSUES = 2;
export function lostCallPacer(pacing) {
const { stepId, waits, conditions, clock, signal } = pacing;
/** Per device: automatic reissues since the last user choice, and the delay of the last paced one. */
const paced = new Map();
return {
async beforeReissue(deviceId, attempt) {
const { reissues, backoff } = paced.get(deviceId) ?? { reissues: 0 };
if (pacing.askUser && reissues >= MAX_AUTOMATIC_REISSUES) {
paced.delete(deviceId);
const waitFor = [{ kind: "user-choice", choiceId: `${stepId}:${attempt}` }];
const steer = `${deviceId} lost this step ${reissues + 1} times: re-run it or select another device`;
await waits.hold({ reason: "result-pending", steer, waitFor }, conditions.until(waitFor, signal));
return;
}
if (reissues === 0) {
paced.set(deviceId, { reissues: 1 });
return;
}
const delay = nextKeyBackoffMs(backoff);
paced.set(deviceId, { reissues: reissues + 1, backoff: delay });
const steer = `${deviceId} lost this step; reissuing it`;
await waits.hold({ reason: "result-pending", steer, waitFor: [] }, clock.sleep(delay, signal));
},
};
}
//# sourceMappingURL=device-proxy-lost-calls.js.map