stdio (TypeScript): the ask's bound is the setting ask-bound; the pause has a seam (H-A-549)

Review round 1: the bound of asking again while the tool runner is stopping is the
setting ask-bound (default 60 s), and the pause and the clock are askPacing, which
the test replaces as the Go test does pause and askNow, so nothing sleeps. Rows
added: past the bound the fault is the caller's, a bare timeout stays a failure.

Builds: design 47 H2 H-A-542, H-A-544, H-A-549
This commit is contained in:
2026-11-23 12:05:15 +01:00
parent fdb85e8bd5
commit 07bfc71c33
3 changed files with 38 additions and 15 deletions
+17 -7
View File
@@ -31,8 +31,17 @@ export function isStopping(err: unknown): boolean {
return typeof err === "object" && err !== null && (err as { errorKind?: unknown }).errorKind === ERROR_KIND_STOPPING;
}
/** How long a call is asked again while the tool runner is stopping: the Go stdio Ask's bound (H-A-544). */
const STOPPING_BOUND_MS = 60_000;
/** The setting of how long a call is asked again while the tool runner is stopping, and its default: the Go stdio Ask's
* (H-A-544, H-A-549). */
export const ASK_BOUND_SETTING = "ask-bound";
const DEFAULT_ASK_BOUND_MS = 60_000;
/** How a call waits between two asks while the tool runner is stopping, and its clock: a test's to replace, as the Go
* stdio's pause and askNow are, so nothing sleeps. */
export const askPacing = {
pause: (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms)),
now: (): number => Date.now(),
};
/** A duration setting as the node-engine composes it (MESH_CONFIG_<KEY>, design 47 H2 H-A-370), in milliseconds: Go's
* duration text ("1s", "250ms", "1m30s"); an absent setting is its default, one that is no duration is an error naming it. */
@@ -53,23 +62,24 @@ function settingMs(key: string, fallback: number): number {
/** Asks once and again, while the answer is the typed fault stopping, after a pause at the kept-call pace (the settings
* kept-call-pace-first and kept-call-pace-max, 1 s doubling to 30 s by default, as the Go stdio's Ask), until the new
* runner answers or the bound ends; then the stopping fault is the caller's as such (H-A-542, H-A-544). A plain refusal
* runner answers or the bound (the setting ask-bound, 60 s by default) ends; then the stopping fault is the caller's as such (H-A-542, H-A-544). A plain refusal
* and a bare timeout are never asked again. */
async function askAgainWhileStopping(key: string, once: () => Promise<unknown>): Promise<unknown> {
const start = Date.now();
const start = askPacing.now();
const bound = settingMs(ASK_BOUND_SETTING, DEFAULT_ASK_BOUND_MS);
let wait = settingMs("kept-call-pace-first", 1000);
const most = settingMs("kept-call-pace-max", 30_000);
for (;;) {
try {
return await once();
} catch (err) {
const left = STOPPING_BOUND_MS - (Date.now() - start);
const left = bound - (askPacing.now() - start);
if (!isStopping(err) || wait >= left) {
if (isStopping(err)) (err as Error).message = `${key}: the tool runner was stopping, asked again until the bound of 60s: ${(err as Error).message}`;
if (isStopping(err)) (err as Error).message = `${key}: the tool runner was stopping, asked again until the bound of ${bound}ms: ${(err as Error).message}`;
throw err;
}
process.stderr.write(`[mesh-sdk] ${key}: the tool runner is stopping (${(err as Error).message}); asked again in ${wait}ms\n`);
await new Promise((r) => setTimeout(r, wait));
await askPacing.pause(wait);
wait = Math.min(wait * 2, most);
}
}