@mark1russell7/algebra 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/build/clock.d.ts +50 -0
- package/build/clock.js +89 -0
- package/build/clock.js.map +1 -0
- package/build/index.d.ts +25 -0
- package/build/index.js +85 -4
- package/build/index.js.map +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -61,6 +61,25 @@ const problems = replay(CONNECTION_MACHINE, recorded, { machine: CONNECTION_MACH
|
|
|
61
61
|
// for example ["c1: app.machine.connection has no transition from OPEN on open to OPEN"]
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
## The clock
|
|
65
|
+
|
|
66
|
+
`@mark1russell7/algebra/clock` gives the clock of a runtime and a fake clock for tests. The entry imports nothing: no `node:` module, no zod and no other package. Thus a client in a browser can use it. The service and collections read time through it.
|
|
67
|
+
|
|
68
|
+
| Export | What it does |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `Clock` | `now()` gives the monotonic time in milliseconds. `after(ms, run)` starts `run` after `ms` and gives its `Cancel`. |
|
|
71
|
+
| `platformClock({ unref })` | A clock on `performance.now()` and `setTimeout`. With `unref: true`, its timers do not keep a Node process alive. |
|
|
72
|
+
| `realClock` | The clock of the platform with `unref: true`. |
|
|
73
|
+
| `fakeClock(start)` | A clock that moves only on `advance(ms)`. `block(ms)` moves it and starts no timer, as a blocked event loop does. `pending` counts the live timers. |
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { fakeClock } from "@mark1russell7/algebra/clock";
|
|
77
|
+
|
|
78
|
+
const clock = fakeClock();
|
|
79
|
+
clock.after(30_000, () => cache.sweep());
|
|
80
|
+
await clock.advance(30_000); // the sweep runs, at 30 s exactly
|
|
81
|
+
```
|
|
82
|
+
|
|
64
83
|
## Installation
|
|
65
84
|
|
|
66
85
|
```sh
|
package/build/clock.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/clock.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* This function stops a timer that `Clock.after` started. A second use does nothing. A clock of
|
|
4
|
+
* the platform also gives `unref`: after it, the timer does not keep a Node process alive.
|
|
5
|
+
*/
|
|
6
|
+
export type Cancel = (() => void) & {
|
|
7
|
+
readonly unref?: (() => void) | undefined;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A clock gives the monotonic time in milliseconds, and it starts a function after a delay. The
|
|
11
|
+
* runtime reads time only through a clock. Thus a test can give a fake clock, and the timing of
|
|
12
|
+
* the runtime is then exact and repeatable.
|
|
13
|
+
*/
|
|
14
|
+
export interface Clock {
|
|
15
|
+
/** This method gives the monotonic time, in milliseconds. A step of the wall clock does not move it. */
|
|
16
|
+
now(): number;
|
|
17
|
+
/** This method starts `run` after `ms` milliseconds, and gives the function that stops it. */
|
|
18
|
+
after(ms: number, run: () => void): Cancel;
|
|
19
|
+
}
|
|
20
|
+
/** These options make a clock of the platform. */
|
|
21
|
+
export interface PlatformClockOptions {
|
|
22
|
+
/** True makes each timer not keep a Node process alive. The default is false, as with `setTimeout`. */
|
|
23
|
+
readonly unref?: boolean | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* This function makes a clock of the platform: `performance.now()` and `setTimeout`. Each cancel
|
|
27
|
+
* that it gives also has `unref`. A delay longer than `setTimeout` takes waits in steps.
|
|
28
|
+
*/
|
|
29
|
+
export declare const platformClock: (options?: PlatformClockOptions) => Clock;
|
|
30
|
+
/**
|
|
31
|
+
* This clock reads `performance.now()` and uses `setTimeout`. Its timers do not keep a Node
|
|
32
|
+
* process alive, thus a timer that is not stopped cannot stop the exit of the process.
|
|
33
|
+
*/
|
|
34
|
+
export declare const realClock: Clock;
|
|
35
|
+
/** A fake clock moves only when a test tells it to. */
|
|
36
|
+
export interface FakeClock extends Clock {
|
|
37
|
+
/** This method moves the clock forward by `ms`, and it starts each timer that comes due, in sequence. */
|
|
38
|
+
advance(ms: number): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* This method moves the clock forward by `ms` and starts no timer, as a blocked event loop does.
|
|
41
|
+
* The next `advance` then starts each timer that came due during the block, late.
|
|
42
|
+
*/
|
|
43
|
+
block(ms: number): void;
|
|
44
|
+
/** This count is the number of timers that are not stopped and not called. */
|
|
45
|
+
readonly pending: number;
|
|
46
|
+
}
|
|
47
|
+
/** This function makes a fake clock. Its time starts at `start` milliseconds. */
|
|
48
|
+
export declare const fakeClock: (start?: number) => FakeClock;
|
|
49
|
+
//#endregion
|
|
50
|
+
//# sourceMappingURL=clock.d.ts.map
|
package/build/clock.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region src/clock.ts
|
|
2
|
+
/** This function gives the monotonic time: `performance.now()`, or `Date.now()` on a platform without `performance`. */
|
|
3
|
+
const monotonic = () => {
|
|
4
|
+
const performance = globalThis.performance;
|
|
5
|
+
return performance === void 0 ? Date.now() : performance.now();
|
|
6
|
+
};
|
|
7
|
+
/** This delay is the longest that `setTimeout` takes, in milliseconds. A longer delay starts the function after 1 ms. */
|
|
8
|
+
const LONGEST_DELAY = 2147483647;
|
|
9
|
+
/**
|
|
10
|
+
* This function makes a clock of the platform: `performance.now()` and `setTimeout`. Each cancel
|
|
11
|
+
* that it gives also has `unref`. A delay longer than `setTimeout` takes waits in steps.
|
|
12
|
+
*/
|
|
13
|
+
const platformClock = (options = {}) => ({
|
|
14
|
+
now: monotonic,
|
|
15
|
+
after(ms, run) {
|
|
16
|
+
let unrefed = options.unref === true;
|
|
17
|
+
const arm = (left) => {
|
|
18
|
+
const step = left > LONGEST_DELAY ? setTimeout(() => timer = arm(left - LONGEST_DELAY), LONGEST_DELAY) : setTimeout(run, Math.max(0, left));
|
|
19
|
+
if (unrefed) step.unref?.();
|
|
20
|
+
return step;
|
|
21
|
+
};
|
|
22
|
+
let timer = arm(ms);
|
|
23
|
+
const unref = () => {
|
|
24
|
+
unrefed = true;
|
|
25
|
+
timer.unref?.();
|
|
26
|
+
};
|
|
27
|
+
return Object.assign(() => clearTimeout(timer), { unref });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* This clock reads `performance.now()` and uses `setTimeout`. Its timers do not keep a Node
|
|
32
|
+
* process alive, thus a timer that is not stopped cannot stop the exit of the process.
|
|
33
|
+
*/
|
|
34
|
+
const realClock = /* @__PURE__ */ platformClock({ unref: true });
|
|
35
|
+
/** This function lets the promises that are ready continue, before the clock moves again. */
|
|
36
|
+
const settle = async () => {
|
|
37
|
+
for (let turn = 0; turn < 64; turn += 1) await Promise.resolve();
|
|
38
|
+
};
|
|
39
|
+
/** This function makes a fake clock. Its time starts at `start` milliseconds. */
|
|
40
|
+
const fakeClock = (start = 0) => {
|
|
41
|
+
let now = start;
|
|
42
|
+
let sequence = 0;
|
|
43
|
+
const timers = [];
|
|
44
|
+
const due = (end) => {
|
|
45
|
+
let best;
|
|
46
|
+
for (const timer of timers) if (timer.live && timer.at <= end && (best === void 0 || timer.at < best.at || timer.at === best.at && timer.order < best.order)) best = timer;
|
|
47
|
+
return best;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
now: () => now,
|
|
51
|
+
after(ms, run) {
|
|
52
|
+
const timer = {
|
|
53
|
+
at: now + Math.max(0, ms),
|
|
54
|
+
order: sequence++,
|
|
55
|
+
run,
|
|
56
|
+
live: true
|
|
57
|
+
};
|
|
58
|
+
timers.push(timer);
|
|
59
|
+
return () => {
|
|
60
|
+
timer.live = false;
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
async advance(ms) {
|
|
64
|
+
const end = now + Math.max(0, ms);
|
|
65
|
+
await settle();
|
|
66
|
+
for (;;) {
|
|
67
|
+
const timer = due(end);
|
|
68
|
+
if (timer === void 0) break;
|
|
69
|
+
timer.live = false;
|
|
70
|
+
now = Math.max(now, timer.at);
|
|
71
|
+
timer.run();
|
|
72
|
+
await settle();
|
|
73
|
+
}
|
|
74
|
+
now = Math.max(now, end);
|
|
75
|
+
for (let at = timers.length - 1; at >= 0; at -= 1) if (!timers[at].live) timers.splice(at, 1);
|
|
76
|
+
await settle();
|
|
77
|
+
},
|
|
78
|
+
block(ms) {
|
|
79
|
+
now += Math.max(0, ms);
|
|
80
|
+
},
|
|
81
|
+
get pending() {
|
|
82
|
+
return timers.filter((timer) => timer.live).length;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { fakeClock, platformClock, realClock };
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","names":[],"sources":["../src/clock.ts"],"sourcesContent":["// @mark1russell7/algebra/clock: the clock of a runtime, and a fake clock for tests. It imports\n// nothing: no `node:` module, no zod and no other package. Thus a client in a browser can use it.\n// The service gives this clock again as @mark1russell7/service/clock.\n\n/**\n * This function stops a timer that `Clock.after` started. A second use does nothing. A clock of\n * the platform also gives `unref`: after it, the timer does not keep a Node process alive.\n */\nexport type Cancel = (() => void) & { readonly unref?: (() => void) | undefined };\n\n/**\n * A clock gives the monotonic time in milliseconds, and it starts a function after a delay. The\n * runtime reads time only through a clock. Thus a test can give a fake clock, and the timing of\n * the runtime is then exact and repeatable.\n */\nexport interface Clock {\n /** This method gives the monotonic time, in milliseconds. A step of the wall clock does not move it. */\n now(): number;\n /** This method starts `run` after `ms` milliseconds, and gives the function that stops it. */\n after(ms: number, run: () => void): Cancel;\n}\n\n/** These options make a clock of the platform. */\nexport interface PlatformClockOptions {\n /** True makes each timer not keep a Node process alive. The default is false, as with `setTimeout`. */\n readonly unref?: boolean | undefined;\n}\n\n/** This function gives the monotonic time: `performance.now()`, or `Date.now()` on a platform without `performance`. */\nconst monotonic = (): number => {\n const performance = (globalThis as { performance?: { now(): number } }).performance;\n return performance === undefined ? Date.now() : performance.now();\n};\n\n/** This delay is the longest that `setTimeout` takes, in milliseconds. A longer delay starts the function after 1 ms. */\nconst LONGEST_DELAY = 0x7fffffff;\n\n/**\n * This function makes a clock of the platform: `performance.now()` and `setTimeout`. Each cancel\n * that it gives also has `unref`. A delay longer than `setTimeout` takes waits in steps.\n */\nexport const platformClock = (options: PlatformClockOptions = {}): Clock => ({\n now: monotonic,\n after(ms, run) {\n let unrefed = options.unref === true;\n const arm = (left: number): ReturnType<typeof setTimeout> => {\n const step =\n left > LONGEST_DELAY ? setTimeout(() => (timer = arm(left - LONGEST_DELAY)), LONGEST_DELAY) : setTimeout(run, Math.max(0, left));\n if (unrefed) (step as { unref?: () => void }).unref?.();\n return step;\n };\n let timer = arm(ms);\n const unref = (): void => {\n unrefed = true;\n (timer as { unref?: () => void }).unref?.();\n };\n return Object.assign(() => clearTimeout(timer), { unref });\n },\n});\n\n/**\n * This clock reads `performance.now()` and uses `setTimeout`. Its timers do not keep a Node\n * process alive, thus a timer that is not stopped cannot stop the exit of the process.\n */\nexport const realClock: Clock = /* @__PURE__ */ platformClock({ unref: true });\n\n/** A fake clock moves only when a test tells it to. */\nexport interface FakeClock extends Clock {\n /** This method moves the clock forward by `ms`, and it starts each timer that comes due, in sequence. */\n advance(ms: number): Promise<void>;\n /**\n * This method moves the clock forward by `ms` and starts no timer, as a blocked event loop does.\n * The next `advance` then starts each timer that came due during the block, late.\n */\n block(ms: number): void;\n /** This count is the number of timers that are not stopped and not called. */\n readonly pending: number;\n}\n\n/** This function lets the promises that are ready continue, before the clock moves again. */\nconst settle = async (): Promise<void> => {\n for (let turn = 0; turn < 64; turn += 1) await Promise.resolve();\n};\n\n/** This function makes a fake clock. Its time starts at `start` milliseconds. */\nexport const fakeClock = (start = 0): FakeClock => {\n let now = start;\n let sequence = 0;\n const timers: Array<{ at: number; order: number; run: () => void; live: boolean }> = [];\n const due = (end: number) => {\n let best: (typeof timers)[number] | undefined;\n for (const timer of timers)\n if (timer.live && timer.at <= end && (best === undefined || timer.at < best.at || (timer.at === best.at && timer.order < best.order)))\n best = timer;\n return best;\n };\n return {\n now: () => now,\n after(ms, run): Cancel {\n const timer = { at: now + Math.max(0, ms), order: sequence++, run, live: true };\n timers.push(timer);\n return () => {\n timer.live = false;\n };\n },\n async advance(ms) {\n // a monotonic clock does not go back\n const end = now + Math.max(0, ms);\n await settle();\n for (;;) {\n const timer = due(end);\n if (timer === undefined) break;\n timer.live = false;\n // a timer that came due during a block runs late, at the time of the clock\n now = Math.max(now, timer.at);\n timer.run();\n await settle();\n }\n now = Math.max(now, end);\n for (let at = timers.length - 1; at >= 0; at -= 1) if (!timers[at]!.live) timers.splice(at, 1);\n await settle();\n },\n block(ms) {\n now += Math.max(0, ms);\n },\n get pending() {\n return timers.filter((timer) => timer.live).length;\n },\n };\n};\n"],"mappings":";;AA6BA,MAAM,kBAA0B;CAC9B,MAAM,cAAe,WAAmD;CACxE,OAAO,gBAAgB,KAAA,IAAY,KAAK,IAAI,IAAI,YAAY,IAAI;AAClE;;AAGA,MAAM,gBAAgB;;;;;AAMtB,MAAa,iBAAiB,UAAgC,CAAC,OAAc;CAC3E,KAAK;CACL,MAAM,IAAI,KAAK;EACb,IAAI,UAAU,QAAQ,UAAU;EAChC,MAAM,OAAO,SAAgD;GAC3D,MAAM,OACJ,OAAO,gBAAgB,iBAAkB,QAAQ,IAAI,OAAO,aAAa,GAAI,aAAa,IAAI,WAAW,KAAK,KAAK,IAAI,GAAG,IAAI,CAAC;GACjI,IAAI,SAAS,KAAiC,QAAQ;GACtD,OAAO;EACT;EACA,IAAI,QAAQ,IAAI,EAAE;EAClB,MAAM,cAAoB;GACxB,UAAU;GACV,MAAkC,QAAQ;EAC5C;EACA,OAAO,OAAO,aAAa,aAAa,KAAK,GAAG,EAAE,MAAM,CAAC;CAC3D;AACF;;;;;AAMA,MAAa,YAAmC,8BAAc,EAAE,OAAO,KAAK,CAAC;;AAgB7E,MAAM,SAAS,YAA2B;CACxC,KAAK,IAAI,OAAO,GAAG,OAAO,IAAI,QAAQ,GAAG,MAAM,QAAQ,QAAQ;AACjE;;AAGA,MAAa,aAAa,QAAQ,MAAiB;CACjD,IAAI,MAAM;CACV,IAAI,WAAW;CACf,MAAM,SAA+E,CAAC;CACtF,MAAM,OAAO,QAAgB;EAC3B,IAAI;EACJ,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,QAAQ,MAAM,MAAM,QAAQ,SAAS,KAAA,KAAa,MAAM,KAAK,KAAK,MAAO,MAAM,OAAO,KAAK,MAAM,MAAM,QAAQ,KAAK,QAC5H,OAAO;EACX,OAAO;CACT;CACA,OAAO;EACL,WAAW;EACX,MAAM,IAAI,KAAa;GACrB,MAAM,QAAQ;IAAE,IAAI,MAAM,KAAK,IAAI,GAAG,EAAE;IAAG,OAAO;IAAY;IAAK,MAAM;GAAK;GAC9E,OAAO,KAAK,KAAK;GACjB,aAAa;IACX,MAAM,OAAO;GACf;EACF;EACA,MAAM,QAAQ,IAAI;GAEhB,MAAM,MAAM,MAAM,KAAK,IAAI,GAAG,EAAE;GAChC,MAAM,OAAO;GACb,SAAS;IACP,MAAM,QAAQ,IAAI,GAAG;IACrB,IAAI,UAAU,KAAA,GAAW;IACzB,MAAM,OAAO;IAEb,MAAM,KAAK,IAAI,KAAK,MAAM,EAAE;IAC5B,MAAM,IAAI;IACV,MAAM,OAAO;GACf;GACA,MAAM,KAAK,IAAI,KAAK,GAAG;GACvB,KAAK,IAAI,KAAK,OAAO,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,OAAO,GAAG,CAAE,MAAM,OAAO,OAAO,IAAI,CAAC;GAC7F,MAAM,OAAO;EACf;EACA,MAAM,IAAI;GACR,OAAO,KAAK,IAAI,GAAG,EAAE;EACvB;EACA,IAAI,UAAU;GACZ,OAAO,OAAO,QAAQ,UAAU,MAAM,IAAI,CAAC,CAAC;EAC9C;CACF;AACF"}
|
package/build/index.d.ts
CHANGED
|
@@ -7,6 +7,25 @@ export declare const arr: <T>(value: T | readonly T[]) => readonly T[];
|
|
|
7
7
|
/** This function gives the states that a transition leaves. The state "*" is each state that is not final. */
|
|
8
8
|
export declare const fromStates: (m: Pick<Machine, "states">, from: string | readonly string[]) => string[];
|
|
9
9
|
//#endregion
|
|
10
|
+
//#region src/conntrack.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* This function gives the lowest count of one network namespace after one scan of the conntrack
|
|
13
|
+
* collector under pressure. Each entry of the table can go at that scan. The sources are Linux v7.0,
|
|
14
|
+
* `net/netfilter/nf_conntrack_core.c`.
|
|
15
|
+
*
|
|
16
|
+
* - The scan starts to drop at `nf_conntrack_max / 100 * 95`, in integer arithmetic (lines 1526-1527).
|
|
17
|
+
* It drops an entry while the count is at that value or above it (lines 1605-1608). Thus this limit
|
|
18
|
+
* stops the scan one entry below the value.
|
|
19
|
+
* - A scan ends when its count of entries is more than `64000 / HZ` (line 97, lines 1561-1572). That end
|
|
20
|
+
* clears the pressure (lines 1645-1646). Thus this limit stops the scan after `64000 / HZ + 1` entries.
|
|
21
|
+
* - That count also holds each entry that expired by its own timeout, in any namespace (lines
|
|
22
|
+
* 1575-1578). Thus `expired` such entries before the end take `expired` drops from the namespace.
|
|
23
|
+
*
|
|
24
|
+
* The limit that stops the scan first gives the floor. `expired` is 0 by default, which gives the
|
|
25
|
+
* lowest floor. On a host with other flows, a scan can find some, and the floor is higher.
|
|
26
|
+
*/
|
|
27
|
+
export declare const conntrackFloor: (max: number, hz: number, expired?: number) => number;
|
|
28
|
+
//#endregion
|
|
10
29
|
//#region src/algebra.d.ts
|
|
11
30
|
/**
|
|
12
31
|
* This module has the closed forms of the algebra. They give the duration of a timer of a
|
|
@@ -50,6 +69,12 @@ type Node = {
|
|
|
50
69
|
};
|
|
51
70
|
/** This function parses the arithmetic of a document, or it throws an error that tells where the text stops making sense. */
|
|
52
71
|
export declare const parseExpr: (text: string) => Node;
|
|
72
|
+
/**
|
|
73
|
+
* This function gives the SYNs that a connect sends before it gives up: the first SYN and each
|
|
74
|
+
* retransmission (`synGiveUpWaits`). A connect whose SYN does not leave adds each of them to the field
|
|
75
|
+
* `drop` of conntrack, and each retransmission to `TCPRetransFail`.
|
|
76
|
+
*/
|
|
77
|
+
export declare const synGiveUpSends: (retries: number, linear: number) => number;
|
|
53
78
|
/**
|
|
54
79
|
* This function evaluates one duration of a timer of a machine, in the unit that its document
|
|
55
80
|
* gives it. The waits of a backoff timer read `fired`, which tells which wait.
|
package/build/index.js
CHANGED
|
@@ -87,6 +87,28 @@ const machineProblems = (m) => {
|
|
|
87
87
|
return problems;
|
|
88
88
|
};
|
|
89
89
|
//#endregion
|
|
90
|
+
//#region src/conntrack.ts
|
|
91
|
+
/**
|
|
92
|
+
* This function gives the lowest count of one network namespace after one scan of the conntrack
|
|
93
|
+
* collector under pressure. Each entry of the table can go at that scan. The sources are Linux v7.0,
|
|
94
|
+
* `net/netfilter/nf_conntrack_core.c`.
|
|
95
|
+
*
|
|
96
|
+
* - The scan starts to drop at `nf_conntrack_max / 100 * 95`, in integer arithmetic (lines 1526-1527).
|
|
97
|
+
* It drops an entry while the count is at that value or above it (lines 1605-1608). Thus this limit
|
|
98
|
+
* stops the scan one entry below the value.
|
|
99
|
+
* - A scan ends when its count of entries is more than `64000 / HZ` (line 97, lines 1561-1572). That end
|
|
100
|
+
* clears the pressure (lines 1645-1646). Thus this limit stops the scan after `64000 / HZ + 1` entries.
|
|
101
|
+
* - That count also holds each entry that expired by its own timeout, in any namespace (lines
|
|
102
|
+
* 1575-1578). Thus `expired` such entries before the end take `expired` drops from the namespace.
|
|
103
|
+
*
|
|
104
|
+
* The limit that stops the scan first gives the floor. `expired` is 0 by default, which gives the
|
|
105
|
+
* lowest floor. On a host with other flows, a scan can find some, and the floor is higher.
|
|
106
|
+
*/
|
|
107
|
+
const conntrackFloor = (max, hz, expired = 0) => {
|
|
108
|
+
const drops = Math.max(0, Math.floor(64e3 / hz) + 1 - expired);
|
|
109
|
+
return Math.max(Math.floor(max / 100) * 95 - 1, max - drops);
|
|
110
|
+
};
|
|
111
|
+
//#endregion
|
|
90
112
|
//#region src/algebra.ts
|
|
91
113
|
const exact = (n) => ({
|
|
92
114
|
kind: "exact",
|
|
@@ -297,6 +319,56 @@ const synWait = (fired, linear) => fired <= linear ? TCP_TIMEOUT_INIT : capped(T
|
|
|
297
319
|
* `tcp_syn_retries` + `tcp_syn_linear_timeouts` (`synWait`). The connect gives up at the end of the last wait.
|
|
298
320
|
*/
|
|
299
321
|
const synWaits = (retries, linear) => Array.from({ length: Number(linear + 1n + retries) }, (_, fired) => synWait(BigInt(fired), linear));
|
|
322
|
+
/**
|
|
323
|
+
* This function gives the waits of the SYN of a connect up to the firing that gives up, from 6.5
|
|
324
|
+
* (`tcp_write_timeout` in `net/ipv4/tcp_timer.c` at v7.0, lines 242-284). A firing applies two tests.
|
|
325
|
+
*
|
|
326
|
+
* - The count test: the retransmissions before it are `tcp_syn_retries` + `tcp_syn_linear_timeouts`.
|
|
327
|
+
* - The time test: `retransmits_timed_out` with the boundary `tcp_syn_retries` and no linear term. Its
|
|
328
|
+
* budget is `tcp_model_timeout` from an RTO of 1 s, (2^(retries + 1) - 1) s, from the first SYN
|
|
329
|
+
* (`tcp_connect` sets `retrans_stamp`, `tcp_output.c` line 4370). It needs one retransmission.
|
|
330
|
+
*
|
|
331
|
+
* The first firing that passes one test gives up. At the defaults both tests give 131 s. At
|
|
332
|
+
* `tcp_syn_retries` 2 and 4 linear waits, the time test gives 7 s and the count test gives 11 s.
|
|
333
|
+
*/
|
|
334
|
+
const synGiveUpWaits = (retries, linear) => {
|
|
335
|
+
const budget = retransBudget(retries, TCP_TIMEOUT_INIT, TCP_RTO_MAX);
|
|
336
|
+
const waits = synWaits(retries, linear);
|
|
337
|
+
let at = whole(0n);
|
|
338
|
+
for (let fired = 0; fired < waits.length; fired += 1) {
|
|
339
|
+
at = rationals.add(at, waits[fired]);
|
|
340
|
+
if (fired >= 1 && rationals.cmp(at, budget) >= 0) return waits.slice(0, fired + 1);
|
|
341
|
+
}
|
|
342
|
+
return waits;
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* This function gives how early the connect can give up, in seconds. The time test reads the real
|
|
346
|
+
* time of a firing, and the wheel makes that time late. A firing before the nominal one can pass it when its
|
|
347
|
+
* lateness takes it past the budget. With `tcp_usec_ts`, the test adds one jiffy (line 233).
|
|
348
|
+
*/
|
|
349
|
+
const synGiveUpEarly = (retries, linear, hz) => {
|
|
350
|
+
const budget = retransBudget(retries, TCP_TIMEOUT_INIT, TCP_RTO_MAX);
|
|
351
|
+
const waits = synGiveUpWaits(retries, linear);
|
|
352
|
+
const end = waits.reduce((total, wait) => rationals.add(total, wait), whole(0n));
|
|
353
|
+
const jiffy = rationals.div(whole(1n), hz);
|
|
354
|
+
let at = whole(0n);
|
|
355
|
+
let late = whole(0n);
|
|
356
|
+
for (let fired = 0; fired < waits.length - 1; fired += 1) {
|
|
357
|
+
at = rationals.add(at, waits[fired]);
|
|
358
|
+
late = rationals.add(late, rationals.div(whole(granularity(jiffiesOf(waits[fired], hz))), hz));
|
|
359
|
+
if (fired >= 1 && rationals.cmp(rationals.add(rationals.add(at, late), jiffy), budget) >= 0) {
|
|
360
|
+
const low = rationals.sub(budget, jiffy);
|
|
361
|
+
return rationals.sub(end, rationals.cmp(low, at) >= 0 ? low : at);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return whole(0n);
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* This function gives the SYNs that a connect sends before it gives up: the first SYN and each
|
|
368
|
+
* retransmission (`synGiveUpWaits`). A connect whose SYN does not leave adds each of them to the field
|
|
369
|
+
* `drop` of conntrack, and each retransmission to `TCPRetransFail`.
|
|
370
|
+
*/
|
|
371
|
+
const synGiveUpSends = (retries, linear) => synGiveUpWaits(BigInt(retries), BigInt(linear)).length;
|
|
300
372
|
/** This function gives the whole jiffies of a time at HZ, rounded up, as `msecs_to_jiffies` and `usecs_to_jiffies` round. */
|
|
301
373
|
const jiffiesOf = (seconds, hz) => rationals.ceil(rationals.mul(seconds, hz)).n;
|
|
302
374
|
/**
|
|
@@ -483,8 +555,8 @@ const MODELS = {
|
|
|
483
555
|
},
|
|
484
556
|
"linux.syn-giveup": {
|
|
485
557
|
knobs: [null, null],
|
|
486
|
-
seconds: ([retries, linear]) =>
|
|
487
|
-
source: "net/ipv4/tcp_timer.c tcp_write_timeout and
|
|
558
|
+
seconds: ([retries, linear]) => synGiveUpWaits(integer(retries, "tcp_syn_retries"), integer(linear, "tcp_syn_linear_timeouts")).reduce((total, wait) => rationals.add(total, wait), whole(0n)),
|
|
559
|
+
source: "net/ipv4/tcp_timer.c tcp_write_timeout, retransmits_timed_out and tcp_model_timeout at v7.0 (lines 187-284)"
|
|
488
560
|
},
|
|
489
561
|
"linux.syn-giveup-lateness": {
|
|
490
562
|
knobs: [
|
|
@@ -492,9 +564,18 @@ const MODELS = {
|
|
|
492
564
|
null,
|
|
493
565
|
"Hz"
|
|
494
566
|
],
|
|
495
|
-
seconds: ([retries, linear, hz]) => rationals.div(whole(
|
|
567
|
+
seconds: ([retries, linear, hz]) => rationals.div(whole(synGiveUpWaits(integer(retries, "tcp_syn_retries"), integer(linear, "tcp_syn_linear_timeouts")).reduce((total, wait) => total + granularity(jiffiesOf(wait, hz)), 0n)), hz),
|
|
496
568
|
source: "net/ipv4/tcp_timer.c tcp_retransmit_timer and kernel/time/timer.c calc_wheel_index at v6.6"
|
|
497
569
|
},
|
|
570
|
+
"linux.syn-giveup-early": {
|
|
571
|
+
knobs: [
|
|
572
|
+
null,
|
|
573
|
+
null,
|
|
574
|
+
"Hz"
|
|
575
|
+
],
|
|
576
|
+
seconds: ([retries, linear, hz]) => synGiveUpEarly(integer(retries, "tcp_syn_retries"), integer(linear, "tcp_syn_linear_timeouts"), hz),
|
|
577
|
+
source: "net/ipv4/tcp_timer.c retransmits_timed_out at v7.0 (lines 214-239) and kernel/time/timer.c calc_wheel_index"
|
|
578
|
+
},
|
|
498
579
|
"linux.syn-wait": {
|
|
499
580
|
knobs: [null, null],
|
|
500
581
|
seconds: ([fired, linear]) => synWait(integer(fired, FIRED), integer(linear, "tcp_syn_linear_timeouts")),
|
|
@@ -949,6 +1030,6 @@ const stackedDetection = (upper, lower, situation, manifestation, upperValues, l
|
|
|
949
1030
|
};
|
|
950
1031
|
};
|
|
951
1032
|
//#endregion
|
|
952
|
-
export { FIRED, algebraProblems, arr, detection, errnoOf, evaluate, exprKnobs, firings, fromStates, machineProblems, modelSource, overValues, parseExpr, probeTrain, readsFired, realizationKnobs, realizationOf, recovery, replay, stackedDetection, timerBand, timerOf, timerUnder, transitionOn };
|
|
1033
|
+
export { FIRED, algebraProblems, arr, conntrackFloor, detection, errnoOf, evaluate, exprKnobs, firings, fromStates, machineProblems, modelSource, overValues, parseExpr, probeTrain, readsFired, realizationKnobs, realizationOf, recovery, replay, stackedDetection, synGiveUpSends, timerBand, timerOf, timerUnder, transitionOn };
|
|
953
1034
|
|
|
954
1035
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["r"],"sources":["../src/machine.ts","../src/algebra.ts"],"sourcesContent":["import { arr } from \"./states.ts\";\n\nexport { arr, fromStates } from \"./states.ts\";\n\n/**\n * `mark1russell7.machine/1` is a state machine as data.\n *\n * One document describes one machine, and three readers share it: the conformance checker\n * (states, transitions, observer mappings), the algebra (the closed forms of timers over knobs)\n * and the simulator (the arm, cancel and fire events of timers). The format is small on purpose:\n * no hierarchy, no actions other than `emits`, and guards as documented text.\n */\n\n/** A unit is a unit that @mark1russell7/quantity stores: a time or a count, which is all that the timers of a machine read. */\nexport type Unit = string;\n\n/** An expression is a duration: a constant, a knob, arithmetic over knobs, or a named model of them. */\nexport type Expr =\n | { readonly const: number; readonly unit: Unit }\n | { readonly knob: string; readonly unit: Unit }\n /** This text is arithmetic over knob names: + - * / min max floor ceil pow ( ) */\n | { readonly expr: string; readonly unit: Unit }\n /** This name is a named model of the algebra over these knobs, for example the retransmission ladder. */\n | { readonly model: string; readonly knobs: readonly string[]; readonly unit: Unit };\n\n/** A timer has a duration, the events that arm and cancel it, and the event that it fires. */\nexport interface Timer {\n readonly duration: Expr;\n readonly lateness?: Expr | undefined;\n readonly early?: Expr | undefined;\n readonly arms: readonly string[];\n readonly cancels?: readonly string[] | undefined;\n readonly fires: string;\n /**\n * A backoff timer starts again after it fires, and no wait is shorter than the wait before it.\n * Examples are the retransmission timer of the kernel, its SYN timer and the reconnect of a driver. Its duration, lateness and\n * early bound are those of one wait. They can read `fired`: the number of times that it fired\n * after the last of its `resets`.\n */\n readonly backoff?: { readonly resets: readonly string[] } | undefined;\n readonly note?: string | undefined;\n}\n\n/**\n * This name is what the waits of a backoff timer read for the number of times that it fired after\n * a reset, from 0. It is not a knob, because nothing sets it. It is the count of the timer itself.\n */\nexport const FIRED = \"fired\";\n\n/**\n * A realization tells how long a mechanism takes where the machine operates. It is one of the\n * timers of the machine, whole, or a time of its own over the knobs of the machine. It has a\n * lateness and an early bound, as a timer has. The idle refresh of the Redis server is the idle\n * time of its keepalive, rounded on the timer wheel of the kernel. That is the first firing of its\n * keepalive timer, not the whole timer.\n */\nexport type Realization =\n | { readonly timer: string }\n | {\n readonly duration: Expr;\n readonly lateness?: Expr | undefined;\n readonly early?: Expr | undefined;\n readonly note?: string | undefined;\n };\n\n/**\n * An over tells the machine that this machine operates on, and how: a driver on its kernel socket.\n * Each state of this machine is on a state of the lower machine. Some knobs of this machine set\n * knobs of the lower machine. The end of the lower machine arrives as an event of this machine.\n *\n * The driver ioredis 6 sets the keepalive idle time of the kernel from its keepAlive option,\n * through setKeepAlive of Node. That function also sets the probe interval and count. The driver\n * learns of the end of the socket as stream.close.\n */\nexport interface Over {\n /** This identifier is the machine below, as a graph identifies its document. */\n readonly machine: string;\n /** This map gives the state of the lower machine that each state of this machine is on. */\n readonly states: Readonly<Record<string, string>>;\n /** These are the knobs of the lower machine that this machine sets, by their lower names, over its own knobs. */\n readonly sets: Readonly<Record<string, Expr>>;\n /** This event is the event of this machine that the end of the lower machine arrives as. */\n readonly ends: string;\n readonly note?: string | undefined;\n}\n\n/** A transition goes from one or more states to a state, on one or more events. */\nexport interface TransitionDef {\n readonly id: string;\n readonly from: string | readonly string[];\n readonly to: string;\n readonly on: string | readonly string[];\n readonly guard?: string | undefined;\n readonly timer?: string | undefined;\n readonly emits?: readonly string[] | undefined;\n readonly errno?: string | undefined;\n readonly note?: string | undefined;\n readonly source?: string | undefined;\n}\n\n/** A vantage is the layer that a machine is seen from. */\nexport type Vantage =\n \"wire\" | \"kernel\" | \"middlebox\" | \"proxy\" | \"driver\" | \"server\" | \"canary\" | \"injector\" | \"self\";\n\n/** A machine is one state machine document. */\nexport interface Machine {\n readonly format: \"mark1russell7.machine/1\";\n readonly id: string;\n readonly title: string;\n readonly layer: Vantage;\n readonly version: string;\n readonly conditions?: Readonly<Record<string, string>> | undefined;\n readonly sources: ReadonlyArray<{\n readonly ref: string;\n readonly rung: \"normative\" | \"implemented\" | \"documented\" | \"observed\" | \"derived\";\n readonly note?: string | undefined;\n }>;\n readonly states: Readonly<\n Record<\n string,\n {\n readonly initial?: boolean | undefined;\n readonly final?: boolean | undefined;\n readonly pseudo?: boolean | undefined;\n readonly note?: string | undefined;\n }\n >\n >;\n readonly events: Readonly<\n Record<\n string,\n {\n readonly kind: \"rx\" | \"tx\" | \"app\" | \"timer\" | \"local\" | \"packet\" | \"peer\";\n readonly note?: string | undefined;\n }\n >\n >;\n readonly knobs: Readonly<\n Record<\n string,\n {\n readonly key: string;\n readonly scope: string;\n readonly unit: Unit | null;\n readonly default: number | null;\n /** This value turns the knob's timers off: a time that reads the knob at it has no bound. */\n readonly off?: number | undefined;\n readonly note?: string | undefined;\n }\n >\n >;\n readonly timers: Readonly<Record<string, Timer>>;\n /** These are the mechanisms whose time this machine gives, by the identifier of each mechanism. */\n readonly realizes?: Readonly<Record<string, Realization>> | undefined;\n /** This is the machine that this machine operates on, for a machine on another machine. */\n readonly over?: Over | undefined;\n readonly transitions: readonly TransitionDef[];\n readonly observe?:\n | Readonly<\n Record<\n string,\n {\n readonly states: Readonly<Record<string, string>>;\n readonly hides?: readonly string[] | undefined;\n readonly fidelity: \"complete\" | \"sampled\" | \"lossy\" | \"derived\";\n readonly note?: string | undefined;\n }\n >\n >\n | undefined;\n readonly generated?: { readonly from: string; readonly by: string } | undefined;\n}\n\n/** This function gives the names that a duration reads: its knobs, by the names of the machine, and `fired`. */\nconst exprNames = (e: Expr): string[] => {\n if (\"knob\" in e) return [e.knob];\n if (\"model\" in e) return [...e.knobs];\n if (\"expr\" in e) {\n return (e.expr.match(/[A-Za-z_][A-Za-z0-9_.]*/g) ?? []).filter(\n (word) => ![\"min\", \"max\", \"floor\", \"ceil\", \"pow\"].includes(word),\n );\n }\n return [];\n};\n\n/** This function gives the knobs that a duration reads, by the names of the machine for them. */\nexport const exprKnobs = (e: Expr): string[] => exprNames(e).filter((name) => name !== FIRED);\n\n/** This function tells if a duration reads the number of times that its timer fired, as the waits of a backoff do. */\nexport const readsFired = (e: Expr): boolean => exprNames(e).includes(FIRED);\n\n/**\n * This function gives the problems in the consistency of a document. Each state, event, timer and\n * knob that it refers to must exist, and it must have an initial state. A reader refuses a\n * machine with problems, and does not draw half of it.\n */\nexport const machineProblems = (m: Machine): string[] => {\n const problems: string[] = [];\n const states = new Set(Object.keys(m.states));\n if (!Object.values(m.states).some((state) => state.initial === true)) {\n problems.push(\"no initial state\");\n }\n for (const t of m.transitions) {\n for (const from of arr(t.from)) {\n if (from !== \"*\" && !states.has(from)) problems.push(`${t.id}: from ${from}`);\n }\n if (!states.has(t.to)) problems.push(`${t.id}: to ${t.to}`);\n for (const event of arr(t.on))\n if (m.events[event] === undefined) problems.push(`${t.id}: event ${event}`);\n if (t.timer !== undefined && m.timers[t.timer] === undefined) {\n problems.push(`${t.id}: timer ${t.timer}`);\n }\n }\n if (m.knobs[FIRED] !== undefined)\n problems.push(`knob ${FIRED}: the name is a backoff timer's count of its firings`);\n for (const [id, tm] of Object.entries(m.timers)) {\n if (m.events[tm.fires] === undefined) problems.push(`timer ${id}: fires ${tm.fires}`);\n for (const knob of exprKnobs(tm.duration)) {\n const def = m.knobs[knob];\n if (def === undefined) problems.push(`timer ${id}: knob ${knob}`);\n // a duration is an amount, thus a switch or a choice cannot give it\n else if (def.unit === null) problems.push(`timer ${id}: knob ${knob} is not an amount`);\n }\n // only a timer that starts again has a count of its firings to read\n const reads = [tm.duration, tm.lateness, tm.early].some(\n (e) => e !== undefined && readsFired(e),\n );\n if (reads && tm.backoff === undefined)\n problems.push(`timer ${id}: reads ${FIRED}, but has no backoff`);\n for (const event of tm.backoff?.resets ?? [])\n if (!event.startsWith(\"enter:\") && m.events[event] === undefined)\n problems.push(`timer ${id}: backoff resets on ${event}`);\n }\n for (const [mechanism, how] of Object.entries(m.realizes ?? {})) {\n if (\"timer\" in how) {\n // a machine on another machine can realize a timer of the machine below. Only a reader of\n // the two documents can examine that\n if (m.timers[how.timer] === undefined && m.over === undefined)\n problems.push(`realizes ${mechanism}: timer ${how.timer}`);\n continue;\n }\n if ([how.duration, how.lateness, how.early].some((e) => e !== undefined && readsFired(e)))\n problems.push(`realizes ${mechanism}: reads ${FIRED}, which only a backoff timer counts`);\n for (const knob of exprKnobs(how.duration)) {\n const def = m.knobs[knob];\n if (def === undefined) problems.push(`realizes ${mechanism}: knob ${knob}`);\n else if (def.unit === null)\n problems.push(`realizes ${mechanism}: knob ${knob} is not an amount`);\n }\n }\n if (m.over !== undefined) {\n for (const state of Object.keys(m.over.states)) {\n if (!states.has(state)) problems.push(`over: state ${state}`);\n }\n if (m.events[m.over.ends] === undefined) problems.push(`over: ends ${m.over.ends}`);\n for (const [lower, set] of Object.entries(m.over.sets)) {\n if (readsFired(set)) problems.push(`over: sets ${lower} from ${FIRED}, which is no knob`);\n for (const knob of exprKnobs(set)) {\n const def = m.knobs[knob];\n if (def === undefined) problems.push(`over: sets ${lower} from knob ${knob}`);\n else if (def.unit === null) problems.push(`over: sets ${lower} from ${knob}, no amount`);\n }\n }\n }\n for (const [source, view] of Object.entries(m.observe ?? {})) {\n for (const state of Object.values(view.states)) {\n if (!states.has(state)) problems.push(`observe ${source}: ${state}`);\n }\n }\n const ids = m.transitions.map((t) => t.id);\n for (const id of new Set(ids)) {\n if (ids.filter((other) => other === id).length > 1) problems.push(`transition ${id} twice`);\n }\n return problems;\n};\n","import type { Extent, Quantity, Rational, Unknown } from \"@mark1russell7/quantity\";\nimport {\n convertExact,\n isUnbounded,\n quantity,\n rationals as r,\n unbounded,\n} from \"@mark1russell7/quantity\";\nimport type { Expr, Machine, TransitionDef } from \"./machine.ts\";\nimport { FIRED, arr, exprKnobs, fromStates } from \"./machine.ts\";\n\n/**\n * This module has the closed forms of the algebra. They give the duration of a timer of a\n * machine, and how late and how early it can fire, from the values of its knobs.\n *\n * A machine document writes each duration in one of four forms (`machine.ts`): a constant, a knob,\n * arithmetic over its knobs, or a named model. The arithmetic uses the value of each knob in the\n * unit that the document gives to that knob. Thus `tcp_keepalive / 3` of Redis divides whole\n * seconds, as Redis does. A model is the formula of the implementation itself, for example the\n * retransmission budget of the kernel. The values are exact rationals, not floats: 0.2 s × 1023\n * is 204.6 s, not 204.60000000000002.\n *\n * A knob without a value makes the result unknown, and the result names the knob. A knob that\n * nothing sets (no bound) makes a duration without an end.\n */\n\n/** This function gives the value of each knob, by the name of the machine for it: an amount, no bound, or unknown and the reason. */\nexport type KnobValues = (name: string) => Extent | Unknown | undefined;\n\n/** Timer bounds tell how long a timer operates, how late it can fire and how early, each in the unit of its document. */\nexport interface TimerBounds {\n readonly duration: Extent | Unknown;\n readonly lateness?: Extent | Unknown | undefined;\n readonly early?: Extent | Unknown | undefined;\n}\n\n/**\n * A value is an exact rational, no bound, or unknown with its reason. No bound has a sign. A\n * duration is not negative, but a step of the arithmetic can be: cap − ∞ is −∞, and\n * max(cap − ∞, cap / 2) is cap / 2.\n */\ntype Value =\n | { readonly kind: \"exact\"; readonly n: Rational }\n | { readonly kind: \"infinite\"; readonly negative?: true }\n | { readonly kind: \"unknown\"; readonly why: string };\n\nconst exact = (n: Rational): Value => ({ kind: \"exact\", n });\nconst INFINITE: Value = { kind: \"infinite\" };\nconst NEGATIVE_INFINITE: Value = { kind: \"infinite\", negative: true };\n/** This function gives the sign of a value that is not unknown: −1, 0 or 1. */\nconst signOf = (value: Value): number =>\n value.kind === \"infinite\"\n ? value.negative === true\n ? -1\n : 1\n : value.kind === \"exact\"\n ? r.cmp(value.n, r.ZERO)\n : 0;\n/** This function gives no bound with a sign. */\nconst unboundedOf = (sign: number): Value => (sign < 0 ? NEGATIVE_INFINITE : INFINITE);\nconst unknown = (why: string): Value => ({ kind: \"unknown\", why });\nconst whole = (n: bigint): Rational => r.rational(n);\n\n/** This function gives the first unknown among some values. An operation over them gets it. */\nconst unknownOf = (values: readonly Value[]): Value | undefined =>\n values.find((value) => value.kind === \"unknown\");\n\n// ---------------------------------------------------------------------------------------------\n// the arithmetic of the documents: + - * /, min, max, floor, ceil, parentheses, numbers, knob names\n// ---------------------------------------------------------------------------------------------\n\n/** A node is the arithmetic of a document, after the parse. */\nexport type Node =\n | { readonly op: \"num\"; readonly n: Rational }\n | { readonly op: \"knob\"; readonly name: string }\n | { readonly op: \"+\" | \"-\" | \"*\" | \"/\"; readonly a: Node; readonly b: Node }\n | { readonly op: \"neg\"; readonly a: Node }\n | { readonly op: \"min\" | \"max\" | \"floor\" | \"ceil\" | \"pow\"; readonly args: readonly Node[] };\n\nconst FUNCTIONS = { min: 2, max: 2, floor: 1, ceil: 1, pow: 2 } as const;\n\n/** This count is the largest exponent that `pow` takes. A larger one is a mistake in a document, not a timer. */\nconst POW_LIMIT = 4096n;\n\n/**\n * This function gives a value to a whole power: `pow(a, n)`. The exponent must be an exact whole\n * number, for example the `fired` of a backoff. A negative exponent gives the reciprocal. No bound\n * to the power 0 is 1, and to a positive power it keeps its sign when the power is odd.\n */\nconst power = (a: Value, b: Value): Value => {\n if (b.kind !== \"exact\" || !r.isInteger(b.n)) return unknown(\"pow takes a whole exponent\");\n const k = b.n.n;\n if (k > POW_LIMIT || k < -POW_LIMIT) return unknown(`pow takes an exponent of ${POW_LIMIT} or less`);\n if (a.kind === \"infinite\") {\n if (k === 0n) return exact(r.ONE);\n if (k < 0n) return exact(r.ZERO);\n return k % 2n === 0n ? INFINITE : a;\n }\n if (a.kind !== \"exact\") return unknown(\"not an amount\");\n if (k < 0n && a.n.n === 0n) return unknown(\"a division by zero\");\n return exact(r.pow(a.n, Number(k)));\n};\n\n/** This function parses the arithmetic of a document, or it throws an error that tells where the text stops making sense. */\nexport const parseExpr = (text: string): Node => {\n const tokens = text.match(/\\d+(?:\\.\\d+)?|[A-Za-z_][A-Za-z0-9_.]*|[-+*/(),]|\\S/g) ?? [];\n let at = 0;\n const peek = (): string | undefined => tokens[at];\n const take = (expected?: string): string => {\n const token = tokens[at];\n if (token === undefined || (expected !== undefined && token !== expected)) {\n throw new Error(`\"${text}\": expected ${expected ?? \"more\"} at ${token ?? \"the end\"}`);\n }\n at += 1;\n return token;\n };\n const expr = (): Node => {\n let node = term();\n while (peek() === \"+\" || peek() === \"-\") {\n const op = take() as \"+\" | \"-\";\n node = { op, a: node, b: term() };\n }\n return node;\n };\n const term = (): Node => {\n let node = factor();\n while (peek() === \"*\" || peek() === \"/\") {\n const op = take() as \"*\" | \"/\";\n node = { op, a: node, b: factor() };\n }\n return node;\n };\n const factor = (): Node => {\n const token = take();\n if (token === \"(\") {\n const inner = expr();\n take(\")\");\n return inner;\n }\n if (token === \"-\") return { op: \"neg\", a: factor() };\n if (/^\\d/.test(token)) return { op: \"num\", n: r.fromDecimal(token) };\n if (!/^[A-Za-z_]/.test(token)) throw new Error(`\"${text}\": ${token} is not a term`);\n // Only an own key is a function: `toString` is a knob, as each other name.\n if (Object.hasOwn(FUNCTIONS, token)) {\n const name = token as keyof typeof FUNCTIONS;\n take(\"(\");\n const args = [expr()];\n while (peek() === \",\") {\n take(\",\");\n args.push(expr());\n }\n take(\")\");\n if (args.length !== FUNCTIONS[name]) {\n throw new Error(`\"${text}\": ${name} takes ${FUNCTIONS[name]}, not ${args.length}`);\n }\n return { op: name, args };\n }\n return { op: \"knob\", name: token };\n };\n const node = expr();\n if (at < tokens.length) throw new Error(`\"${text}\": ${tokens[at]} after the end`);\n return node;\n};\n\nconst run = (node: Node, valueOf: (name: string) => Value): Value => {\n if (node.op === \"num\") return exact(node.n);\n if (node.op === \"knob\") return valueOf(node.name);\n if (node.op === \"neg\") {\n const a = run(node.a, valueOf);\n return a.kind === \"exact\" ? exact(r.neg(a.n)) : a.kind === \"infinite\" ? unboundedOf(-signOf(a)) : a;\n }\n if (\"args\" in node) {\n const args = node.args.map((arg) => run(arg, valueOf));\n const lost = unknownOf(args);\n if (lost !== undefined) return lost;\n if (node.op === \"floor\" || node.op === \"ceil\") {\n const [a] = args as [Value];\n return a.kind === \"exact\" ? exact(node.op === \"floor\" ? r.floor(a.n) : r.ceil(a.n)) : a;\n }\n const [a, b] = args as [Value, Value];\n if (node.op === \"pow\") return power(a, b);\n if (a.kind === \"infinite\" || b.kind === \"infinite\") {\n // +∞ wins a max and loses a min, and −∞ loses a max and wins a min\n const above = (x: Value, y: Value): boolean =>\n x.kind === \"infinite\" ? signOf(x) > 0 || (y.kind === \"infinite\" && signOf(y) < 0) : signOf(y) < 0;\n const larger = above(a, b) ? a : b;\n const smaller = larger === a ? b : a;\n return node.op === \"max\" ? larger : smaller;\n }\n if (a.kind !== \"exact\" || b.kind !== \"exact\") return unknown(\"not an amount\");\n const aFirst = r.cmp(a.n, b.n) <= 0;\n if (node.op === \"min\") return aFirst ? a : b;\n return aFirst ? b : a;\n }\n const a = run(node.a, valueOf);\n const b = run(node.b, valueOf);\n const lost = unknownOf([a, b]);\n if (lost !== undefined) return lost;\n if (a.kind === \"exact\" && b.kind === \"exact\") {\n if (node.op === \"/\" && b.n.n === 0n) return unknown(\"a division by zero\");\n const op = { \"+\": r.add, \"-\": r.sub, \"*\": r.mul, \"/\": r.div }[node.op];\n return exact(op(a.n, b.n));\n }\n // a timer that nothing sets is longer than each sum, and each positive multiple. Its sign\n // follows the arithmetic: cap − ∞ is −∞, which a max then discards\n if (node.op === \"+\" || node.op === \"-\") {\n const sa = signOf(a);\n const sb = node.op === \"-\" ? -signOf(b) : signOf(b);\n if (a.kind === \"infinite\" && b.kind === \"infinite\" && sa !== sb)\n return unknown(\"no bound less no bound\");\n return unboundedOf(a.kind === \"infinite\" ? sa : sb);\n }\n if (node.op === \"*\") {\n const sign = signOf(a) * signOf(b);\n return sign === 0 ? unknown(\"zero times no bound\") : unboundedOf(sign);\n }\n if (a.kind === \"infinite\" && b.kind === \"infinite\") return unknown(\"no bound over no bound\");\n if (b.kind === \"infinite\") return exact(r.ZERO);\n const sign = signOf(a) * signOf(b);\n return sign === 0 ? unknown(\"no bound over zero\") : unboundedOf(sign);\n};\n\n// ---------------------------------------------------------------------------------------------\n// the named models: the formula of an implementation over its knobs, in seconds\n// ---------------------------------------------------------------------------------------------\n\nconst integer = (value: Rational, what: string): bigint => {\n if (!r.isInteger(value) || value.n < 0n)\n throw new Error(`${what} is not a whole count: ${r.toNumber(value)}`);\n return value.n;\n};\n/** This function gives min(base × 2^k, cap), exactly. */\nconst capped = (base: Rational, k: bigint, cap: Rational): Rational => {\n const doubled = r.mul(base, whole(2n ** k));\n return r.cmp(doubled, cap) <= 0 ? doubled : cap;\n};\n/**\n * This function gives the hypothetical retransmission timeout of the kernel, `tcp_model_timeout`\n * in `net/ipv4/tcp_timer.c`. The waits double from the minimum RTO until a step is more than the\n * maximum, and then the waits are capped. For `tcp_retries2` = 15, it is 0.2 s × (2^10 − 1) +\n * 6 × 120 s = 924.6 s.\n */\nconst retransBudget = (retries: bigint, min: Rational, max: Rational): Rational => {\n let thresh = 0n;\n while (r.cmp(r.mul(min, whole(2n ** (thresh + 1n))), max) <= 0) thresh += 1n;\n if (retries <= thresh) return r.mul(min, whole(2n ** (retries + 1n) - 1n));\n return r.add(r.mul(min, whole(2n ** (thresh + 1n) - 1n)), r.mul(whole(retries - thresh), max));\n};\n\n/** These are `TCP_TIMEOUT_INIT` and `TCP_RTO_MAX` in `include/net/tcp.h` at v6.6: the first SYN RTO and the cap. */\nconst TCP_TIMEOUT_INIT = whole(1n);\nconst TCP_RTO_MAX = whole(120n);\n\n/**\n * This function gives the wait of the SYN of a connect after `fired` firings, from 6.5\n * (`tcp_retransmit_timer` in `net/ipv4/tcp_timer.c`). Each firing sends the SYN again. The first\n * `tcp_syn_linear_timeouts` firings keep the initial RTO, thus the waits 0 to\n * `tcp_syn_linear_timeouts` are 1 s each. Then each firing doubles the wait, up to `TCP_RTO_MAX`.\n */\nconst synWait = (fired: bigint, linear: bigint): Rational =>\n fired <= linear ? TCP_TIMEOUT_INIT : capped(TCP_TIMEOUT_INIT, fired - linear, TCP_RTO_MAX);\n\n/**\n * This function gives each wait of the SYN of a connect, from 6.5: the waits 0 to\n * `tcp_syn_retries` + `tcp_syn_linear_timeouts` (`synWait`). The connect gives up at the end of the last wait.\n */\nconst synWaits = (retries: bigint, linear: bigint): Rational[] =>\n Array.from({ length: Number(linear + 1n + retries) }, (_, fired) => synWait(BigInt(fired), linear));\n\n/** This function gives the whole jiffies of a time at HZ, rounded up, as `msecs_to_jiffies` and `usecs_to_jiffies` round. */\nconst jiffiesOf = (seconds: Rational, hz: Rational): bigint => r.ceil(r.mul(seconds, hz)).n;\n\n/**\n * This function gives the longest wait of the delayed ACK, in jiffies (`tcp_send_delayed_ack` in\n * `net/ipv4/tcp_output.c:4004-4054` at v6.6). The wait is the ACK timeout, `ato`. It is at least\n * `TCP_DELACK_MIN`, HZ/25. Above that, the smoothed round trip in whole jiffies bounds it, but not\n * below `TCP_DELACK_MIN`. The cap is `icsk_delack_max`, `TCP_DELACK_MAX` by default, HZ/5\n * (`include/net/tcp.h:133-136`, `net/ipv4/tcp.c:425`). Thus it is 40 ms on a fast path at each HZ, and\n * 200 ms at most.\n */\nconst delackWait = (rtt: Rational, hz: Rational): bigint => {\n const ticks = integer(hz, \"hz\");\n const least = ticks / 25n;\n const most = ticks / 5n;\n const srtt = jiffiesOf(rtt, hz);\n const bound = srtt > least ? srtt : least;\n return bound < most ? bound : most;\n};\n\n/**\n * This function gives how late the timer wheel can fire a timer that is due in `jiffies`\n * (`calc_wheel_index` in `kernel/time/timer.c` at v6.6). Level 0 holds the timers due in 63 jiffies\n * or less. Each level above holds eight times as long, at eight times the granularity. The wheel\n * rounds a timer up to the next boundary of its level, thus it fires up to one granularity late.\n * At HZ 250, a 2 h timer can be up to 131 s late.\n */\nconst granularity = (jiffies: bigint): bigint => {\n let level = 0n;\n while (level < 8n && jiffies >= 63n << (3n * level)) level += 1n;\n return 8n ** level;\n};\n\n/**\n * This function gives the lateness of the retransmission give-up after its budget. The first\n * retransmission sets the RTO to the round trip plus the minimum, rounded up to a jiffy\n * (`tcp_set_rto`). On a Docker network at HZ 250, that is 204 ms, not 200.\n *\n * Each firing doubles the RTO, up to the cap. The budget ends in the firing after the last one\n * that is short of it. Thus the give-up comes one step late at most, plus the rounding of each\n * firing on the wheel. The model assumes a steady path, whose variance stays below the minimum RTO.\n */\nconst retransLateness = (\n retries: bigint,\n min: Rational,\n max: Rational,\n rtt: Rational,\n hz: Rational,\n): Rational => {\n const base = jiffiesOf(r.add(min, rtt), hz);\n const cap = jiffiesOf(max, hz);\n let step = base;\n let wheel = 0n;\n for (let k = 1n; k <= retries + 1n; k += 1n) {\n step = base * 2n ** k < cap ? base * 2n ** k : cap;\n wheel += granularity(step);\n }\n return r.div(whole(step + wheel), hz);\n};\n\n/**\n * This function gives one wait of the retransmission timer with one segment in flight, in jiffies\n * (`net/ipv4/tcp_timer.c`, and `tcp_schedule_loss_probe` in `tcp_output.c`, at v6.6). Its first\n * firing is the tail loss probe. For one segment, the probe waits two round trips plus\n * `TCP_RTO_MIN`, but not longer than the RTO. Thus it waits the RTO itself: the round trip plus\n * the minimum, in whole jiffies.\n *\n * The probe arms the RTO again, and each RTO firing doubles it, up to the cap. Thus the\n * firing k comes 2^k RTOs after the send: 0.204, 0.408, 0.816 s on a Docker network at HZ 250.\n * With more than one segment in flight, the probe waits two round trips plus 2 jiffies.\n */\nconst rtoWait = (fired: bigint, min: Rational, max: Rational, rtt: Rational, hz: Rational) => {\n const base = jiffiesOf(r.add(min, rtt), hz);\n const cap = jiffiesOf(max, hz);\n if (fired === 0n) return base;\n const doubled = base * 2n ** (fired - 1n);\n return doubled < cap ? doubled : cap;\n};\n\n/**\n * This function gives the lateness of keepalive. It adds the idle timer and the interval of each\n * probe, each rounded up on the wheel at its own level. Linux arms the idle timer, then one probe\n * interval for each probe without an answer.\n */\n/**\n * This function gives the lateness of the retransmission give-up after its budget, under an ICMP\n * host or net unreachable for each RTO retransmission. Each ICMP reverts one doubling of the backoff\n * (`tcp_ld_RTO_revert` in `net/ipv4/tcp_ipv4.c` at v6.6, RFC 6069). Then each wait after the first RTO\n * firing is one RTO again, thus the give-up comes at most one RTO after the budget. Each firing up\n * to it can fire up to the granularity of its level of the wheel late.\n */\nconst retransLatenessReverted = (\n retries: bigint,\n min: Rational,\n max: Rational,\n rtt: Rational,\n hz: Rational,\n): Rational => {\n const base = jiffiesOf(r.add(min, rtt), hz);\n const budget = jiffiesOf(retransBudget(retries, min, max), hz);\n const firings = (budget + base - 1n) / base + 1n;\n return r.div(whole(base + firings * granularity(base)), hz);\n};\n\nconst keepaliveLateness = (\n idle: Rational,\n interval: Rational,\n probes: bigint,\n hz: Rational,\n): Rational => {\n const late = (time: Rational) => whole(granularity(jiffiesOf(time, hz)));\n return r.div(r.add(late(idle), r.mul(whole(probes), late(interval))), hz);\n};\n\ninterface Model {\n /** These are the knobs that it reads, in sequence, and the unit to read each in (null for a count). */\n readonly knobs: readonly (string | null)[];\n /** This function gives the result in seconds. */\n readonly seconds: (args: readonly Rational[]) => Rational;\n readonly source: string;\n}\n\nconst MODELS: Readonly<Record<string, Model>> = {\n \"linux.retrans-budget\": {\n knobs: [null, \"s\", \"s\"],\n seconds: ([retries, min, max]) => retransBudget(integer(retries!, \"tcp_retries2\"), min!, max!),\n source: \"net/ipv4/tcp_timer.c tcp_model_timeout at v6.6\",\n },\n // the give-up comes at the first RTO firing at the budget or after it: one step later at most,\n // at the real RTO of the path, plus the rounding of each firing on the wheel\n \"linux.retrans-step\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([retries, min, max, rtt, hz]) =>\n retransLateness(integer(retries!, \"tcp_retries2\"), min!, max!, rtt!, hz!),\n source:\n \"net/ipv4/tcp_timer.c, tcp_input.c tcp_set_rto and kernel/time/timer.c at v6.6 (measured by @mark1russell7/harness, 2026-10-08)\",\n },\n // one wait of the retransmission timer, the first of the loss probe: 2^(fired − 1) RTOs after it\n \"linux.rto-wait\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([fired, min, max, rtt, hz]) =>\n r.div(whole(rtoWait(integer(fired!, FIRED), min!, max!, rtt!, hz!)), hz!),\n source:\n \"net/ipv4/tcp_timer.c tcp_retransmit_timer and tcp_output.c tcp_schedule_loss_probe at v6.6 (measured by @mark1russell7/harness, 2026-10-12)\",\n },\n // one wait of the retransmission timer when each RTO retransmission draws an ICMP host or net\n // unreachable: the revert of RFC 6069 takes back the doubling, thus each wait is one RTO\n \"linux.rto-wait-reverted\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([, min, , rtt, hz]) => r.div(whole(jiffiesOf(r.add(min!, rtt!), hz!)), hz!),\n source: \"net/ipv4/tcp_ipv4.c tcp_v4_err and tcp_ld_RTO_revert at v6.6 (RFC 6069)\",\n },\n // the give-up under that revert: at most one RTO after its budget, plus the rounding of each firing\n \"linux.retrans-step-reverted\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([retries, min, max, rtt, hz]) =>\n retransLatenessReverted(integer(retries!, \"tcp_retries2\"), min!, max!, rtt!, hz!),\n source:\n \"net/ipv4/tcp_ipv4.c tcp_ld_RTO_revert and net/ipv4/tcp_timer.c retransmits_timed_out at v6.6 (RFC 6069)\",\n },\n // the rounding of that wait on the timer wheel, at the level that its length puts it in\n \"linux.rto-wait-lateness\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([fired, min, max, rtt, hz]) =>\n r.div(whole(granularity(rtoWait(integer(fired!, FIRED), min!, max!, rtt!, hz!))), hz!),\n source: \"kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // the idle timer of keepalive and the interval of each probe, each rounded on the wheel\n \"linux.keepalive-lateness\": {\n knobs: [\"s\", \"s\", null, \"Hz\"],\n seconds: ([idle, interval, probes, hz]) =>\n keepaliveLateness(idle!, interval!, integer(probes!, \"keepcnt\"), hz!),\n source: \"net/ipv4/tcp_timer.c tcp_keepalive_timer and kernel/time/timer.c at v6.6\",\n },\n // the rounding of one firing on the wheel: how late one timer due after this time can fire\n \"linux.wheel\": {\n knobs: [\"s\", \"Hz\"],\n seconds: ([time, hz]) => r.div(whole(granularity(jiffiesOf(time!, hz!))), hz!),\n source: \"kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // the longest wait of the delayed ACK: min(max(srtt, TCP_DELACK_MIN), TCP_DELACK_MAX), in jiffies\n \"linux.delack\": {\n knobs: [\"s\", \"Hz\"],\n seconds: ([rtt, hz]) => r.div(whole(delackWait(rtt!, hz!)), hz!),\n source:\n \"net/ipv4/tcp_output.c tcp_send_delayed_ack, include/net/tcp.h TCP_DELACK_MIN and TCP_DELACK_MAX at v6.6\",\n },\n // the rounding of that wait on the timer wheel: 1 jiffy at 40 ms, 8 at 200 ms at HZ 1000\n \"linux.delack-lateness\": {\n knobs: [\"s\", \"Hz\"],\n seconds: ([rtt, hz]) => r.div(whole(granularity(delackWait(rtt!, hz!))), hz!),\n source: \"net/ipv4/tcp_output.c tcp_send_delayed_ack and kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // one jiffy: a timer counts from the tick before the event that arms it\n \"linux.jiffy\": {\n knobs: [\"Hz\"],\n seconds: ([hz]) => r.div(whole(1n), hz!),\n source: \"include/linux/jiffies.h\",\n },\n // 6.5 and later: the first tcp_syn_linear_timeouts retransmissions wait the initial RTO, the\n // others double it, and the SYN gives up after syn_retries + linear_timeouts retransmissions\n \"linux.syn-giveup\": {\n knobs: [null, null],\n seconds: ([retries, linear]) =>\n synWaits(integer(retries!, \"tcp_syn_retries\"), integer(linear!, \"tcp_syn_linear_timeouts\")).reduce(\n (total, wait) => r.add(total, wait),\n whole(0n),\n ),\n source:\n \"net/ipv4/tcp_timer.c tcp_write_timeout and Documentation/networking/ip-sysctl.rst at v6.6\",\n },\n // the rounding of each of those waits on the timer wheel, at the level that its length puts it in:\n // 6.08 s at the defaults and HZ 1000, because the last wait of 64 s can be 4.096 s late\n \"linux.syn-giveup-lateness\": {\n knobs: [null, null, \"Hz\"],\n seconds: ([retries, linear, hz]) =>\n r.div(\n whole(\n synWaits(integer(retries!, \"tcp_syn_retries\"), integer(linear!, \"tcp_syn_linear_timeouts\")).reduce(\n (total, wait) => total + granularity(jiffiesOf(wait, hz!)),\n 0n,\n ),\n ),\n hz!,\n ),\n source: \"net/ipv4/tcp_timer.c tcp_retransmit_timer and kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // one wait of the SYN of a connect, after `fired` firings: 1 s for the waits 0 to\n // tcp_syn_linear_timeouts, then doubled at each firing, up to TCP_RTO_MAX\n \"linux.syn-wait\": {\n knobs: [null, null],\n seconds: ([fired, linear]) => synWait(integer(fired!, FIRED), integer(linear!, \"tcp_syn_linear_timeouts\")),\n source:\n \"net/ipv4/tcp_timer.c tcp_retransmit_timer at v6.6 (lines 604 and 624-631) and at v6.17 (lines 448 and 671-678)\",\n },\n // the rounding of that wait on the timer wheel: 64 jiffies for a wait of 1 s at HZ 1000, 8 at HZ 250\n \"linux.syn-wait-lateness\": {\n knobs: [null, null, \"Hz\"],\n seconds: ([fired, linear, hz]) =>\n r.div(\n whole(granularity(jiffiesOf(synWait(integer(fired!, FIRED), integer(linear!, \"tcp_syn_linear_timeouts\")), hz!))),\n hz!,\n ),\n source: \"net/ipv4/tcp_timer.c tcp_retransmit_timer and kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // the default retryStrategy of ioredis 6: min(2^(times - 1) × 50, 5000) ms, plus a jitter of up\n // to 199 ms, which the lateness of the timer carries. Its times counts attempts from 1 after the\n // last ready, thus it is one more than the number of firings of the timer. 5.x waited\n // min(times × 50, 2000) ms\n \"ioredis.retry-base\": {\n knobs: [null],\n seconds: ([fired]) => capped(r.fromDecimal(\"0.05\"), integer(fired!, FIRED), whole(5n)),\n source:\n \"ioredis 6.0.0 built/redis/RedisOptions.js retryStrategy and built/redis/event_handler.js\",\n },\n};\n\n/** This function gives the model of a name, or undefined. Only an own key is a model: `toString` is not one. */\nconst modelOf = (name: string): Model | undefined => (Object.hasOwn(MODELS, name) ? MODELS[name] : undefined);\n\n// ---------------------------------------------------------------------------------------------\n// the evaluation of a duration and a timer\n// ---------------------------------------------------------------------------------------------\n\n/**\n * This function gives the value of a knob in the unit that the document gives it (or as a count\n * when it is a count). For `fired`, it gives which wait of a backoff timer it is.\n */\nconst knobIn = (\n doc: Machine,\n name: string,\n unit: string | null,\n values: KnobValues,\n fired: number | undefined,\n): Value => {\n if (name === FIRED)\n return fired === undefined\n ? unknown(\"one wait of a timer with a backoff: say which, by how many times it has fired\")\n : exact(r.fromNumber(fired));\n if (!Object.hasOwn(doc.knobs, name)) return unknown(`the machine names no knob ${name}`);\n const given = values(name);\n if (given === undefined) return unknown(`nothing gives ${name}'s value`);\n if (\"unknown\" in given) return unknown(`${name}: ${given.unknown}`);\n if (given.value === \"infinite\") return INFINITE;\n const value = r.fromNumber(given.value);\n // a knob at its off value turns its timers off: a time that reads it has no bound\n const { off, unit: own } = doc.knobs[name]!;\n if (off !== undefined && own !== null && r.toNumber(convertExact(value, given.unit, own)) === off)\n return INFINITE;\n return exact(\n unit === null\n ? convertExact(value, given.unit, given.unit)\n : convertExact(value, given.unit, unit),\n );\n};\n\nconst out = (value: Value, unit: string): Extent | Unknown =>\n value.kind === \"exact\"\n ? quantity(r.toNumber(value.n), unit)\n : value.kind === \"infinite\"\n ? value.negative === true\n ? { unknown: \"a negative unbounded time\", unit }\n : unbounded(unit)\n : { unknown: value.why, unit };\n\n/**\n * This function evaluates one duration of a timer of a machine, in the unit that its document\n * gives it. The waits of a backoff timer read `fired`, which tells which wait.\n */\nexport const evaluate = (\n doc: Machine,\n expr: Expr,\n values: KnobValues,\n fired?: number,\n): Extent | Unknown => {\n if (\"const\" in expr) return quantity(expr.const, expr.unit);\n if (\"knob\" in expr) {\n return out(knobIn(doc, expr.knob, expr.unit, values, fired), expr.unit);\n }\n if (\"expr\" in expr) {\n const tree = parseExpr(expr.expr);\n const value = run(tree, (name) =>\n knobIn(doc, name, doc.knobs[name]?.unit ?? null, values, fired),\n );\n return out(value, expr.unit);\n }\n const model = modelOf(expr.model);\n if (model === undefined) return { unknown: `no model ${expr.model}`, unit: expr.unit };\n if (model.knobs.length !== expr.knobs.length) {\n return {\n unknown: `${expr.model} reads ${model.knobs.length} knobs, not ${expr.knobs.length}`,\n unit: expr.unit,\n };\n }\n const args = expr.knobs.map((name, index) =>\n knobIn(doc, name, model.knobs[index] ?? null, values, fired),\n );\n const lost = unknownOf(args);\n if (lost !== undefined) return out(lost, expr.unit);\n if (args.some((arg) => arg.kind === \"infinite\")) return unbounded(expr.unit);\n const seconds = model.seconds(args.map((arg) => (arg as { n: Rational }).n));\n return quantity(r.toNumber(convertExact(seconds, \"s\", expr.unit)), expr.unit);\n};\n\n/**\n * This function gives the bounds of a timer of a machine: how long it operates, how late it can\n * fire, how early. For a backoff timer, it gives one of its waits: the wait after `fired` firings.\n */\nexport const timerOf = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n fired?: number,\n): TimerBounds => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n return {\n duration: evaluate(doc, def.duration, values, fired),\n ...(def.lateness !== undefined ? { lateness: evaluate(doc, def.lateness, values, fired) } : {}),\n ...(def.early !== undefined ? { early: evaluate(doc, def.early, values, fired) } : {}),\n };\n};\n\n/** A firing is one firing of a backoff timer, after `fired` firings: its time from the arming. */\nexport interface Firing {\n readonly fired: number;\n /** This time is the sum of the waits to this firing, each less how early it can fire. */\n readonly low: Quantity;\n /** This time is the sum of the waits to this firing, each plus how late it can fire. */\n readonly high: Quantity;\n}\n\n/** A recovery tells when the firings of a backoff timer move a connection again after a stall. */\nexport interface Recovery {\n /** These are its firings from its arming, up to the first one that surely comes after the end of the stall. */\n readonly firings: readonly Firing[];\n /**\n * These are the firings that can be the first after the end of the stall. There is more than one\n * when the end falls in the bounds of a firing: that firing can come before the end or after it.\n */\n readonly first: readonly number[];\n /** This time is the earliest time of the first firing after the end of the stall, from the arming. */\n readonly low: Quantity;\n /** This time is the latest time of that firing, from the arming. */\n readonly high: Quantity;\n}\n\n/** This count is the most firings that `recovery` examines before it tells that the stall is longer than them. */\nconst FIRINGS = 4096;\n\n/**\n * This function gives the recovery from a stall. A backoff timer continues to fire through a\n * stall, and what each firing sends gets through only after the stall ends. Thus the connection\n * moves again at the first firing at the end or after it. That firing can be most of a wait after\n * the end. A stall that stops immediately after one firing costs almost all of the next, longer\n * wait.\n *\n * The stall counts from the arming of the timer, which is the send that the stall first lost. The\n * waits add, and so do how early and how late each can fire.\n */\nexport const recovery = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n stall: Extent,\n): Recovery | Unknown => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n if (def.backoff === undefined) throw new Error(`${doc.title}'s ${timer} has no backoff`);\n if (isUnbounded(stall))\n return { unknown: \"a stall that never ends: nothing recovers from it\", unit: \"s\" };\n const end = convertExact(r.fromNumber(stall.value), stall.unit, \"s\");\n const inSeconds = (extent: Extent | Unknown | undefined, what: string): Rational | string => {\n if (extent === undefined) return r.ZERO;\n if (\"unknown\" in extent) return `${what}: ${extent.unknown}`;\n if (isUnbounded(extent)) return `${what} has no bound, so the timer never fires again`;\n return convertExact(r.fromNumber(extent.value), extent.unit, \"s\");\n };\n const s = (value: Rational): Quantity => quantity(r.toNumber(value), \"s\");\n const sums: Array<{ fired: number; low: Rational; high: Rational }> = [];\n let low = r.ZERO;\n let high = r.ZERO;\n for (let fired = 0; fired < FIRINGS; fired += 1) {\n const bounds = timerOf(doc, timer, values, fired);\n const wait = inSeconds(bounds.duration, `wait ${fired}`);\n const early = inSeconds(bounds.early, `wait ${fired}'s early bound`);\n const late = inSeconds(bounds.lateness, `wait ${fired}'s lateness`);\n if (typeof wait === \"string\") return { unknown: wait, unit: \"s\" };\n if (typeof early === \"string\") return { unknown: early, unit: \"s\" };\n if (typeof late === \"string\") return { unknown: late, unit: \"s\" };\n low = r.add(low, r.sub(wait, early));\n high = r.add(high, r.add(wait, late));\n sums.push({ fired, low, high });\n if (r.cmp(low, end) < 0) continue;\n // a firing whose latest time is at the end or after it can be the first after the end\n const first = sums.filter((f) => r.cmp(f.high, end) >= 0);\n const earliest = first[0]!.low;\n return {\n firings: sums.map((f) => ({ fired: f.fired, low: s(f.low), high: s(f.high) })),\n first: first.map((f) => f.fired),\n low: s(r.cmp(earliest, end) >= 0 ? earliest : end),\n high: s(first.at(-1)!.high),\n };\n }\n return { unknown: `${FIRINGS} firings do not outlast the stall`, unit: \"s\" };\n};\n\n// ---------------------------------------------------------------------------------------------\n// the times on a timeline: the band of a timer, the firings of a backoff timer, a train of probes\n// ---------------------------------------------------------------------------------------------\n\n/** A band is the range of times in which a timer fires, from its arming. */\nexport interface Band {\n /** This time is the duration less how early the timer can fire. */\n readonly low: Extent;\n /** This time is the duration plus how late the timer can fire. */\n readonly high: Extent;\n}\n\n/** This function gives an amount as an exact value in seconds. Without an amount, it gives zero. */\nconst secondsOf = (extent: Extent | Unknown | undefined): Value => {\n if (extent === undefined) return exact(r.ZERO);\n if (\"unknown\" in extent) return unknown(extent.unknown);\n if (isUnbounded(extent)) return INFINITE;\n return exact(convertExact(r.fromNumber(extent.value), extent.unit, \"s\"));\n};\n\n/**\n * This function gives the band of a timer from its bounds, exactly, in `unit`. The band goes from\n * its duration less its early bound to its duration plus its lateness. A bound that the document\n * does not give is zero. A duration without an end gives a band without an end. A keepalive of 11 s, 4 ms early and 352 ms\n * late, gives 10.996 s to 11.352 s.\n */\nexport const timerBand = (bounds: TimerBounds, unit = \"s\"): Band | Unknown => {\n const duration = secondsOf(bounds.duration);\n const early = secondsOf(bounds.early);\n const late = secondsOf(bounds.lateness);\n const lost = unknownOf([duration, early, late]);\n if (lost !== undefined) return out(lost, unit) as Unknown;\n if (duration.kind !== \"exact\") return { low: unbounded(unit), high: unbounded(unit) };\n if (early.kind !== \"exact\") return { unknown: \"an early bound without an end\", unit };\n const low = r.sub(duration.n, early.n);\n const at = (n: Rational): Quantity => quantity(r.toNumber(convertExact(n, \"s\", unit)), unit);\n return { low: at(low), high: late.kind === \"exact\" ? at(r.add(duration.n, late.n)) : unbounded(unit) };\n};\n\n/** A scheduled firing is one firing of a backoff timer, and its time on the timeline. */\nexport interface Scheduled {\n /** This count is the wait that ends in this firing: the wait after `fired` firings. */\n readonly fired: number;\n /** This time is the sum of the waits to this firing, from the first wait of the schedule, in seconds. */\n readonly at: Quantity;\n}\n\n/** These options tell where the firings of a schedule start and stop. Each stop that they give applies. */\nexport interface ScheduleOptions {\n /** This count is the first wait of the schedule. The default is 0, the wait from the arming. */\n readonly from?: number | undefined;\n /** This count is the most firings to give. */\n readonly count?: number | undefined;\n /** This time stops the schedule: the schedule keeps no firing after it. */\n readonly until?: Extent | undefined;\n /** This time stops the schedule after the first firing at it or after it. That firing is in the schedule. */\n readonly reach?: Extent | undefined;\n}\n\n/**\n * This function gives the firings of a backoff timer on a timeline: the sum of its waits, exactly,\n * from the wait `from`. It stops at the first wait that is not a known amount, or at a stop of the\n * options, or after 4096 firings. Each time is the duration of the waits, without how early or\n * late each can fire.\n *\n * Two examples: the retransmission timer of Linux gives the send of each retransmission. The\n * retry of a call with a deadline gives the start of each try.\n */\nexport const firings = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n options: ScheduleOptions,\n): Scheduled[] => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n if (def.backoff === undefined) throw new Error(`${doc.title}'s ${timer} has no backoff`);\n if (options.count === undefined && options.until === undefined && options.reach === undefined) {\n throw new Error(`the firings of ${timer} need a stop: a count, until or reach`);\n }\n const limit = (extent: Extent | undefined): Value | undefined => (extent === undefined ? undefined : secondsOf(extent));\n const until = limit(options.until);\n const reach = limit(options.reach);\n const from = options.from ?? 0;\n const count = Math.min(options.count ?? FIRINGS, FIRINGS);\n const result: Scheduled[] = [];\n let at = r.ZERO;\n for (let fired = from; result.length < count; fired += 1) {\n const wait = secondsOf(timerOf(doc, timer, values, fired).duration);\n if (wait.kind !== \"exact\") break;\n at = r.add(at, wait.n);\n if (until?.kind === \"exact\" && r.cmp(at, until.n) > 0) break;\n result.push({ fired, at: quantity(r.toNumber(at), \"s\") });\n if (reach?.kind === \"exact\" && r.cmp(at, reach.n) >= 0) break;\n }\n return result;\n};\n\n/**\n * This function gives the times of a train of probes, exactly, in seconds. The first probe is at\n * `first`, and each next probe is one `interval` later, `count` probes in all. A first time without\n * an end gives no probe. An interval without an end gives only the first probe. Keepalive at its\n * defaults sends its probes at 7200 s, 7275 s, and so on to 7800 s.\n */\nexport const probeTrain = (first: Extent, interval: Extent, count: number): Quantity[] => {\n const start = secondsOf(first);\n const step = secondsOf(interval);\n if (start.kind !== \"exact\" || count < 1) return [];\n const times = [quantity(r.toNumber(start.n), \"s\")];\n if (step.kind !== \"exact\") return times;\n for (let k = 1; k < count; k += 1) times.push(quantity(r.toNumber(r.add(start.n, r.mul(step.n, whole(BigInt(k))))), \"s\"));\n return times;\n};\n\n/**\n * This function gives how long a mechanism takes where a machine operates, from the realization\n * of its document. The realization is one of its timers, whole, or its own duration, lateness and\n * early bound over the knobs of the machine. It gives undefined when the document does not realize the mechanism.\n */\nexport const realizationOf = (\n doc: Machine,\n mechanism: string,\n values: KnobValues,\n): TimerBounds | undefined => {\n const how = doc.realizes?.[mechanism];\n if (how === undefined) return undefined;\n if (\"timer\" in how) return timerOf(doc, how.timer, values);\n return {\n duration: evaluate(doc, how.duration, values),\n ...(how.lateness !== undefined ? { lateness: evaluate(doc, how.lateness, values) } : {}),\n ...(how.early !== undefined ? { early: evaluate(doc, how.early, values) } : {}),\n };\n};\n\n/** This function gives the knobs that a realization reads, by the names of the machine for them. */\nexport const realizationKnobs = (doc: Machine, mechanism: string): string[] => {\n const how = doc.realizes?.[mechanism];\n if (how === undefined) return [];\n const def = \"timer\" in how ? doc.timers[how.timer] : how;\n if (def === undefined) return [];\n return [\n ...new Set(\n [def.duration, def.lateness, def.early].flatMap((e) => (e === undefined ? [] : exprKnobs(e))),\n ),\n ];\n};\n\n/** This function gives what in a document the algebra cannot read: arithmetic that does not parse, or a model that it does not have. */\nexport const algebraProblems = (doc: Machine): string[] => {\n const problems: string[] = [];\n const read = (where: string, exprs: ReadonlyArray<Expr | undefined>) => {\n for (const expr of exprs) {\n if (expr === undefined) continue;\n if (\"expr\" in expr) {\n try {\n parseExpr(expr.expr);\n } catch (error) {\n problems.push(`${where}: ${(error as Error).message}`);\n }\n }\n if (\"model\" in expr && modelOf(expr.model) === undefined)\n problems.push(`${where}: no model ${expr.model}`);\n }\n };\n for (const [id, def] of Object.entries(doc.timers)) {\n read(`timer ${id}`, [def.duration, def.lateness, def.early]);\n }\n for (const [mechanism, how] of Object.entries(doc.realizes ?? {})) {\n if (!(\"timer\" in how)) read(`realizes ${mechanism}`, [how.duration, how.lateness, how.early]);\n }\n for (const [lower, set] of Object.entries(doc.over?.sets ?? {}))\n read(`over sets ${lower}`, [set]);\n return problems;\n};\n\n/** This function gives the source of the formula of a named model, for a reader of a result. */\nexport const modelSource = (name: string): string | undefined => modelOf(name)?.source;\n\n// ---------------------------------------------------------------------------------------------\n// detection: the minimum over the detectors that are live in what the connection was doing\n// ---------------------------------------------------------------------------------------------\n\n/**\n * A manifestation is what a failure lets back to the machine: the incoming events that continue\n * to arrive while it lasts. A black hole lets nothing back. The kernel of a frozen process\n * continues to acknowledge what it gets and to answer keepalive probes, thus its ACKs continue to\n * arrive.\n */\nexport interface Manifestation {\n readonly name: string;\n readonly passes: readonly string[];\n /**\n * These are the events that the failure itself sends one time, for example the FIN of a process\n * that stopped with SIGKILL. A delivered event that a transition takes from the state of the connection detects the\n * failure at once.\n */\n readonly delivers?: readonly string[] | undefined;\n /**\n * This errno replaces ETIMEDOUT when one of these timers gives up. Linux keeps an ICMP error on\n * an established socket as a soft error, and the timeout reports it (`tcp_write_err`). An ICMP\n * counts only when it quotes a segment in the window (`tcp_v4_err`). A retransmission is in the\n * window. A keepalive probe uses the sequence number before `snd_una`, thus its ICMP does not count.\n */\n readonly errno?: { readonly errno: string; readonly timers: readonly string[] } | undefined;\n /**\n * These are the durations that the failure changes, by timer. For example, an ICMP host\n * unreachable for each retransmission reverts the backoff of the retransmission timer.\n */\n readonly replaces?:\n | Readonly<\n Record<string, { readonly duration?: Expr; readonly lateness?: Expr; readonly early?: Expr }>\n >\n | undefined;\n}\n\n/** A situation is the activity of the connection when the failure started. */\nexport interface Situation {\n /** This name is the state of the machine, for example ESTABLISHED. */\n readonly state: string;\n /** This flag tells if it had sent data that the peer had not acknowledged. */\n readonly inFlight: boolean;\n}\n\n/** A detector is a timer that can still fire, how long it operates, and the event that it fires. */\nexport interface Detector {\n readonly timer: string;\n readonly fires: string;\n readonly duration: Extent | Unknown;\n /** This identifier is the machine below whose timer it is, when the timer is not of the machine itself (`over`). */\n readonly beneath?: string | undefined;\n}\n\n/** A detection is the result of the minimum over the live detectors. */\nexport interface Detection {\n /** These are the timers that can still fire, the soonest first. */\n readonly detectors: readonly Detector[];\n /** This detector is the first to fire, or null when none can fire in a known time: a silent failure. */\n readonly first: Detector | null;\n /** These are the live detectors whose time nothing gives. Then `first` is only an upper bound. */\n readonly unsettled: readonly string[];\n /** These are the timers that are armed but cannot fire, and the reason for each. */\n readonly held: ReadonlyArray<{ readonly timer: string; readonly why: string }>;\n /**\n * These are the events that the failure delivers and that a transition takes from the state:\n * each detects the failure at once, before any timer. The errno is the errno of the transition,\n * or null for an end of file.\n */\n readonly delivered: ReadonlyArray<{\n readonly event: string;\n readonly to: string;\n readonly errno: string | null;\n }>;\n}\n\nconst soonest = (a: Detector, b: Detector): number => {\n const rank = (d: Detector): number =>\n \"unknown\" in d.duration ? 2 : d.duration.value === \"infinite\" ? 1 : 0;\n if (rank(a) !== rank(b)) return rank(a) - rank(b);\n if (rank(a) !== 0) return a.timer.localeCompare(b.timer);\n const seconds = (d: Detector) => {\n const value = d.duration as Extent & { value: number };\n return r.toNumber(convertExact(r.fromNumber(value.value), value.unit, \"s\"));\n };\n return seconds(a) - seconds(b) || a.timer.localeCompare(b.timer);\n};\n\n/**\n * This function gives the detection: the minimum over the detectors that are live in the\n * situation. The entry to the state arms a timer, and so does what the failure causes: data in\n * flight without an acknowledgment gets a retransmission. An event that occurs cancels a timer.\n *\n * An event that arms the timer again, and that the failure continues to let through, stops it\n * before it fires. For example, the kernel of a frozen process answers each keepalive probe.\n * Without a live detector, the failure is silent at the level of this machine. Only something\n * above it, the timeout of an application or a heartbeat, can find it. The result is only as good\n * as the events that the document names.\n */\nexport const detection = (\n doc: Machine,\n situation: Situation,\n manifestation: Manifestation,\n values: KnobValues,\n): Detection => {\n const passes = new Set(manifestation.passes);\n const happened = new Set([`enter:${situation.state}`]);\n if (situation.inFlight && !passes.has(\"rx.ack\")) happened.add(\"tx.retransmit.first\");\n const occurs = (event: string): boolean => happened.has(event) || passes.has(event);\n const detectors: Detector[] = [];\n const held: Array<{ timer: string; why: string }> = [];\n for (const [timer, def] of Object.entries(doc.timers)) {\n // a backoff timer starts again when it fires: its firing is a new try of the machine, and\n // another timer gives up on it, as the retransmission give-up does\n if (def.backoff !== undefined) continue;\n if (!def.arms.some(occurs)) continue;\n const cancelled = (def.cancels ?? []).find(occurs);\n if (cancelled !== undefined) {\n held.push({ timer, why: `${cancelled} cancels it` });\n continue;\n }\n const rearmed = def.arms.find((event) => passes.has(event));\n if (rearmed !== undefined) {\n held.push({ timer, why: `${rearmed} keeps arriving and re-arms it` });\n continue;\n }\n const duration = manifestation.replaces?.[timer]?.duration ?? def.duration;\n detectors.push({ timer, fires: def.fires, duration: evaluate(doc, duration, values) });\n }\n detectors.sort(soonest);\n const [earliest] = detectors;\n const finite =\n earliest !== undefined &&\n !(\"unknown\" in earliest.duration) &&\n earliest.duration.value !== \"infinite\";\n const delivered = (manifestation.delivers ?? []).flatMap((event) => {\n const taken = transitionOn(doc, situation.state, event);\n return taken === undefined ? [] : [{ event, to: taken.to, errno: taken.errno ?? null }];\n });\n return {\n detectors,\n first: finite ? earliest : null,\n unsettled: detectors.filter((d) => \"unknown\" in d.duration).map((d) => d.timer),\n held,\n delivered,\n };\n};\n\n/**\n * This function gives the bounds of a timer of a machine under a failure: its own bounds, with each\n * duration that the manifestation replaces.\n */\nexport const timerUnder = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n manifestation: Manifestation,\n fired?: number,\n): TimerBounds => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n const replaced = manifestation.replaces?.[timer];\n const duration = replaced?.duration ?? def.duration;\n const lateness = replaced?.lateness ?? def.lateness;\n const early = replaced?.early ?? def.early;\n return {\n duration: evaluate(doc, duration, values, fired),\n ...(lateness !== undefined ? { lateness: evaluate(doc, lateness, values, fired) } : {}),\n ...(early !== undefined ? { early: evaluate(doc, early, values, fired) } : {}),\n };\n};\n\n/**\n * This function gives the errno of a detection by a timer: the errno of the transition that its\n * event takes from the state. A soft error of the manifestation replaces ETIMEDOUT, but only for\n * the timers whose segments its ICMP quotes in the window.\n */\nexport const errnoOf = (\n doc: Machine,\n state: string,\n detector: { readonly timer: string; readonly fires: string },\n manifestation: Manifestation,\n): string | null => {\n const errno = transitionOn(doc, state, detector.fires)?.errno ?? null;\n const soft = manifestation.errno;\n return errno === \"ETIMEDOUT\" && soft !== undefined && soft.timers.includes(detector.timer)\n ? soft.errno\n : errno;\n};\n\n// ---------------------------------------------------------------------------------------------\n// a machine on another machine: a driver on its kernel socket\n// ---------------------------------------------------------------------------------------------\n\n/** This function gives the transition that a machine takes from a state on an event, by its document. */\nexport const transitionOn = (\n doc: Machine,\n state: string,\n event: string,\n): TransitionDef | undefined =>\n doc.transitions.find((t) => fromStates(doc, t.from).includes(state) && arr(t.on).includes(event));\n\n/**\n * This function gives the values of a machine for the machine that it operates on. These are the\n * knobs that it sets, evaluated over its own knobs, and the other knobs of the lower machine. The\n * keepAlive of ioredis at 5000 ms is the keepidle of the kernel at 5 s.\n */\nexport const overValues =\n (upper: Machine, upperValues: KnobValues, lowerValues: KnobValues): KnobValues =>\n (name) => {\n const set = upper.over?.sets[name];\n return set === undefined ? lowerValues(name) : evaluate(upper, set, upperValues);\n };\n\n/**\n * This function gives the detection through the machine that a machine operates on. The detectors\n * of the lower machine are live in the state below the state of this machine. They use the knobs\n * that this machine sets.\n *\n * Each one reaches this machine as the event that the end of the lower\n * machine gives. They are beside the timers of this machine, and the first of all of them is the\n * first detection. A failure lets nothing new through to a machine above the socket, only the end\n * of the socket. Thus the timers of this machine see only what its state arms.\n */\nexport const stackedDetection = (\n upper: Machine,\n lower: Machine,\n situation: Situation,\n manifestation: Manifestation,\n upperValues: KnobValues,\n lowerValues: KnobValues,\n): Detection => {\n const over = upper.over;\n if (over === undefined) throw new Error(`${upper.title} runs on no other machine`);\n const sitsOn = over.states[situation.state];\n if (sitsOn === undefined) {\n throw new Error(`${upper.title}'s ${situation.state} sits on no state of ${lower.title}`);\n }\n const own = detection(upper, situation, { name: manifestation.name, passes: [] }, upperValues);\n const below = detection(\n lower,\n { ...situation, state: sitsOn },\n manifestation,\n overValues(upper, upperValues, lowerValues),\n );\n const detectors = [\n ...own.detectors,\n ...below.detectors.map((d) => ({ ...d, beneath: over.machine })),\n ].sort(soonest);\n const [earliest] = detectors;\n const finite =\n earliest !== undefined &&\n !(\"unknown\" in earliest.duration) &&\n earliest.duration.value !== \"infinite\";\n return {\n detectors,\n first: finite ? earliest : null,\n unsettled: detectors.filter((d) => \"unknown\" in d.duration).map((d) => d.timer),\n held: [...own.held, ...below.held.map((h) => ({ ...h, why: `${h.why}, beneath` }))],\n // what the failure delivers reaches the socket below: its end is the end of this machine\n delivered: below.delivered,\n };\n};\n"],"mappings":";;;;;;;AA+CA,MAAa,QAAQ;;AA+HrB,MAAM,aAAa,MAAsB;CACvC,IAAI,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI;CAC/B,IAAI,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,KAAK;CACpC,IAAI,UAAU,GACZ,QAAQ,EAAE,KAAK,MAAM,0BAA0B,KAAK,CAAC,EAAA,CAAG,QACrD,SAAS,CAAC;EAAC;EAAO;EAAO;EAAS;EAAQ;CAAK,CAAC,CAAC,SAAS,IAAI,CACjE;CAEF,OAAO,CAAC;AACV;;AAGA,MAAa,aAAa,MAAsB,UAAU,CAAC,CAAC,CAAC,QAAQ,SAAS,SAAS,KAAK;;AAG5F,MAAa,cAAc,MAAqB,UAAU,CAAC,CAAC,CAAC,SAAS,KAAK;;;;;;AAO3E,MAAa,mBAAmB,MAAyB;CACvD,MAAM,WAAqB,CAAC;CAC5B,MAAM,SAAS,IAAI,IAAI,OAAO,KAAK,EAAE,MAAM,CAAC;CAC5C,IAAI,CAAC,OAAO,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,UAAU,MAAM,YAAY,IAAI,GACjE,SAAS,KAAK,kBAAkB;CAElC,KAAK,MAAM,KAAK,EAAE,aAAa;EAC7B,KAAK,MAAM,QAAQ,IAAI,EAAE,IAAI,GAC3B,IAAI,SAAS,OAAO,CAAC,OAAO,IAAI,IAAI,GAAG,SAAS,KAAK,GAAG,EAAE,GAAG,SAAS,MAAM;EAE9E,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,GAAG,SAAS,KAAK,G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AAM,SAAS,KAAK,OAAO,UAAU;CACrC,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,GAAG,MAAM,MAAM,KAAK,UAAU,MAAM,uBAAuB,MAAM,OAAO;CAE1F,MAAM,MAAM,UAAU,OAAO,WAAW;EAAE,MAAM,cAAc;EAAM,QAAQ,CAAC;CAAE,GAAG,WAAW;CAC7F,MAAM,QAAQ,UACZ,OACA;EAAE,GAAG;EAAW,OAAO;CAAO,GAC9B,eACA,WAAW,OAAO,aAAa,WAAW,CAC5C;CACA,MAAM,YAAY,CAChB,GAAG,IAAI,WACP,GAAG,MAAM,UAAU,KAAK,OAAO;EAAE,GAAG;EAAG,SAAS,KAAK;CAAQ,EAAE,CACjE,CAAC,CAAC,KAAK,OAAO;CACd,MAAM,CAAC,YAAY;CAKnB,OAAO;EACL;EACA,OALA,aAAa,KAAA,KACb,EAAE,aAAa,SAAS,aACxB,SAAS,SAAS,UAAU,aAGZ,WAAW;EAC3B,WAAW,UAAU,QAAQ,MAAM,aAAa,EAAE,QAAQ,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK;EAC9E,MAAM,CAAC,GAAG,IAAI,MAAM,GAAG,MAAM,KAAK,KAAK,OAAO;GAAE,GAAG;GAAG,KAAK,GAAG,EAAE,IAAI;EAAW,EAAE,CAAC;EAElF,WAAW,MAAM;CACnB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["r"],"sources":["../src/machine.ts","../src/conntrack.ts","../src/algebra.ts"],"sourcesContent":["import { arr } from \"./states.ts\";\n\nexport { arr, fromStates } from \"./states.ts\";\n\n/**\n * `mark1russell7.machine/1` is a state machine as data.\n *\n * One document describes one machine, and three readers share it: the conformance checker\n * (states, transitions, observer mappings), the algebra (the closed forms of timers over knobs)\n * and the simulator (the arm, cancel and fire events of timers). The format is small on purpose:\n * no hierarchy, no actions other than `emits`, and guards as documented text.\n */\n\n/** A unit is a unit that @mark1russell7/quantity stores: a time or a count, which is all that the timers of a machine read. */\nexport type Unit = string;\n\n/** An expression is a duration: a constant, a knob, arithmetic over knobs, or a named model of them. */\nexport type Expr =\n | { readonly const: number; readonly unit: Unit }\n | { readonly knob: string; readonly unit: Unit }\n /** This text is arithmetic over knob names: + - * / min max floor ceil pow ( ) */\n | { readonly expr: string; readonly unit: Unit }\n /** This name is a named model of the algebra over these knobs, for example the retransmission ladder. */\n | { readonly model: string; readonly knobs: readonly string[]; readonly unit: Unit };\n\n/** A timer has a duration, the events that arm and cancel it, and the event that it fires. */\nexport interface Timer {\n readonly duration: Expr;\n readonly lateness?: Expr | undefined;\n readonly early?: Expr | undefined;\n readonly arms: readonly string[];\n readonly cancels?: readonly string[] | undefined;\n readonly fires: string;\n /**\n * A backoff timer starts again after it fires, and no wait is shorter than the wait before it.\n * Examples are the retransmission timer of the kernel, its SYN timer and the reconnect of a driver. Its duration, lateness and\n * early bound are those of one wait. They can read `fired`: the number of times that it fired\n * after the last of its `resets`.\n */\n readonly backoff?: { readonly resets: readonly string[] } | undefined;\n readonly note?: string | undefined;\n}\n\n/**\n * This name is what the waits of a backoff timer read for the number of times that it fired after\n * a reset, from 0. It is not a knob, because nothing sets it. It is the count of the timer itself.\n */\nexport const FIRED = \"fired\";\n\n/**\n * A realization tells how long a mechanism takes where the machine operates. It is one of the\n * timers of the machine, whole, or a time of its own over the knobs of the machine. It has a\n * lateness and an early bound, as a timer has. The idle refresh of the Redis server is the idle\n * time of its keepalive, rounded on the timer wheel of the kernel. That is the first firing of its\n * keepalive timer, not the whole timer.\n */\nexport type Realization =\n | { readonly timer: string }\n | {\n readonly duration: Expr;\n readonly lateness?: Expr | undefined;\n readonly early?: Expr | undefined;\n readonly note?: string | undefined;\n };\n\n/**\n * An over tells the machine that this machine operates on, and how: a driver on its kernel socket.\n * Each state of this machine is on a state of the lower machine. Some knobs of this machine set\n * knobs of the lower machine. The end of the lower machine arrives as an event of this machine.\n *\n * The driver ioredis 6 sets the keepalive idle time of the kernel from its keepAlive option,\n * through setKeepAlive of Node. That function also sets the probe interval and count. The driver\n * learns of the end of the socket as stream.close.\n */\nexport interface Over {\n /** This identifier is the machine below, as a graph identifies its document. */\n readonly machine: string;\n /** This map gives the state of the lower machine that each state of this machine is on. */\n readonly states: Readonly<Record<string, string>>;\n /** These are the knobs of the lower machine that this machine sets, by their lower names, over its own knobs. */\n readonly sets: Readonly<Record<string, Expr>>;\n /** This event is the event of this machine that the end of the lower machine arrives as. */\n readonly ends: string;\n readonly note?: string | undefined;\n}\n\n/** A transition goes from one or more states to a state, on one or more events. */\nexport interface TransitionDef {\n readonly id: string;\n readonly from: string | readonly string[];\n readonly to: string;\n readonly on: string | readonly string[];\n readonly guard?: string | undefined;\n readonly timer?: string | undefined;\n readonly emits?: readonly string[] | undefined;\n readonly errno?: string | undefined;\n readonly note?: string | undefined;\n readonly source?: string | undefined;\n}\n\n/** A vantage is the layer that a machine is seen from. */\nexport type Vantage =\n \"wire\" | \"kernel\" | \"middlebox\" | \"proxy\" | \"driver\" | \"server\" | \"canary\" | \"injector\" | \"self\";\n\n/** A machine is one state machine document. */\nexport interface Machine {\n readonly format: \"mark1russell7.machine/1\";\n readonly id: string;\n readonly title: string;\n readonly layer: Vantage;\n readonly version: string;\n readonly conditions?: Readonly<Record<string, string>> | undefined;\n readonly sources: ReadonlyArray<{\n readonly ref: string;\n readonly rung: \"normative\" | \"implemented\" | \"documented\" | \"observed\" | \"derived\";\n readonly note?: string | undefined;\n }>;\n readonly states: Readonly<\n Record<\n string,\n {\n readonly initial?: boolean | undefined;\n readonly final?: boolean | undefined;\n readonly pseudo?: boolean | undefined;\n readonly note?: string | undefined;\n }\n >\n >;\n readonly events: Readonly<\n Record<\n string,\n {\n readonly kind: \"rx\" | \"tx\" | \"app\" | \"timer\" | \"local\" | \"packet\" | \"peer\";\n readonly note?: string | undefined;\n }\n >\n >;\n readonly knobs: Readonly<\n Record<\n string,\n {\n readonly key: string;\n readonly scope: string;\n readonly unit: Unit | null;\n readonly default: number | null;\n /** This value turns the knob's timers off: a time that reads the knob at it has no bound. */\n readonly off?: number | undefined;\n readonly note?: string | undefined;\n }\n >\n >;\n readonly timers: Readonly<Record<string, Timer>>;\n /** These are the mechanisms whose time this machine gives, by the identifier of each mechanism. */\n readonly realizes?: Readonly<Record<string, Realization>> | undefined;\n /** This is the machine that this machine operates on, for a machine on another machine. */\n readonly over?: Over | undefined;\n readonly transitions: readonly TransitionDef[];\n readonly observe?:\n | Readonly<\n Record<\n string,\n {\n readonly states: Readonly<Record<string, string>>;\n readonly hides?: readonly string[] | undefined;\n readonly fidelity: \"complete\" | \"sampled\" | \"lossy\" | \"derived\";\n readonly note?: string | undefined;\n }\n >\n >\n | undefined;\n readonly generated?: { readonly from: string; readonly by: string } | undefined;\n}\n\n/** This function gives the names that a duration reads: its knobs, by the names of the machine, and `fired`. */\nconst exprNames = (e: Expr): string[] => {\n if (\"knob\" in e) return [e.knob];\n if (\"model\" in e) return [...e.knobs];\n if (\"expr\" in e) {\n return (e.expr.match(/[A-Za-z_][A-Za-z0-9_.]*/g) ?? []).filter(\n (word) => ![\"min\", \"max\", \"floor\", \"ceil\", \"pow\"].includes(word),\n );\n }\n return [];\n};\n\n/** This function gives the knobs that a duration reads, by the names of the machine for them. */\nexport const exprKnobs = (e: Expr): string[] => exprNames(e).filter((name) => name !== FIRED);\n\n/** This function tells if a duration reads the number of times that its timer fired, as the waits of a backoff do. */\nexport const readsFired = (e: Expr): boolean => exprNames(e).includes(FIRED);\n\n/**\n * This function gives the problems in the consistency of a document. Each state, event, timer and\n * knob that it refers to must exist, and it must have an initial state. A reader refuses a\n * machine with problems, and does not draw half of it.\n */\nexport const machineProblems = (m: Machine): string[] => {\n const problems: string[] = [];\n const states = new Set(Object.keys(m.states));\n if (!Object.values(m.states).some((state) => state.initial === true)) {\n problems.push(\"no initial state\");\n }\n for (const t of m.transitions) {\n for (const from of arr(t.from)) {\n if (from !== \"*\" && !states.has(from)) problems.push(`${t.id}: from ${from}`);\n }\n if (!states.has(t.to)) problems.push(`${t.id}: to ${t.to}`);\n for (const event of arr(t.on))\n if (m.events[event] === undefined) problems.push(`${t.id}: event ${event}`);\n if (t.timer !== undefined && m.timers[t.timer] === undefined) {\n problems.push(`${t.id}: timer ${t.timer}`);\n }\n }\n if (m.knobs[FIRED] !== undefined)\n problems.push(`knob ${FIRED}: the name is a backoff timer's count of its firings`);\n for (const [id, tm] of Object.entries(m.timers)) {\n if (m.events[tm.fires] === undefined) problems.push(`timer ${id}: fires ${tm.fires}`);\n for (const knob of exprKnobs(tm.duration)) {\n const def = m.knobs[knob];\n if (def === undefined) problems.push(`timer ${id}: knob ${knob}`);\n // a duration is an amount, thus a switch or a choice cannot give it\n else if (def.unit === null) problems.push(`timer ${id}: knob ${knob} is not an amount`);\n }\n // only a timer that starts again has a count of its firings to read\n const reads = [tm.duration, tm.lateness, tm.early].some(\n (e) => e !== undefined && readsFired(e),\n );\n if (reads && tm.backoff === undefined)\n problems.push(`timer ${id}: reads ${FIRED}, but has no backoff`);\n for (const event of tm.backoff?.resets ?? [])\n if (!event.startsWith(\"enter:\") && m.events[event] === undefined)\n problems.push(`timer ${id}: backoff resets on ${event}`);\n }\n for (const [mechanism, how] of Object.entries(m.realizes ?? {})) {\n if (\"timer\" in how) {\n // a machine on another machine can realize a timer of the machine below. Only a reader of\n // the two documents can examine that\n if (m.timers[how.timer] === undefined && m.over === undefined)\n problems.push(`realizes ${mechanism}: timer ${how.timer}`);\n continue;\n }\n if ([how.duration, how.lateness, how.early].some((e) => e !== undefined && readsFired(e)))\n problems.push(`realizes ${mechanism}: reads ${FIRED}, which only a backoff timer counts`);\n for (const knob of exprKnobs(how.duration)) {\n const def = m.knobs[knob];\n if (def === undefined) problems.push(`realizes ${mechanism}: knob ${knob}`);\n else if (def.unit === null)\n problems.push(`realizes ${mechanism}: knob ${knob} is not an amount`);\n }\n }\n if (m.over !== undefined) {\n for (const state of Object.keys(m.over.states)) {\n if (!states.has(state)) problems.push(`over: state ${state}`);\n }\n if (m.events[m.over.ends] === undefined) problems.push(`over: ends ${m.over.ends}`);\n for (const [lower, set] of Object.entries(m.over.sets)) {\n if (readsFired(set)) problems.push(`over: sets ${lower} from ${FIRED}, which is no knob`);\n for (const knob of exprKnobs(set)) {\n const def = m.knobs[knob];\n if (def === undefined) problems.push(`over: sets ${lower} from knob ${knob}`);\n else if (def.unit === null) problems.push(`over: sets ${lower} from ${knob}, no amount`);\n }\n }\n }\n for (const [source, view] of Object.entries(m.observe ?? {})) {\n for (const state of Object.values(view.states)) {\n if (!states.has(state)) problems.push(`observe ${source}: ${state}`);\n }\n }\n const ids = m.transitions.map((t) => t.id);\n for (const id of new Set(ids)) {\n if (ids.filter((other) => other === id).length > 1) problems.push(`transition ${id} twice`);\n }\n return problems;\n};\n","/**\n * This function gives the lowest count of one network namespace after one scan of the conntrack\n * collector under pressure. Each entry of the table can go at that scan. The sources are Linux v7.0,\n * `net/netfilter/nf_conntrack_core.c`.\n *\n * - The scan starts to drop at `nf_conntrack_max / 100 * 95`, in integer arithmetic (lines 1526-1527).\n * It drops an entry while the count is at that value or above it (lines 1605-1608). Thus this limit\n * stops the scan one entry below the value.\n * - A scan ends when its count of entries is more than `64000 / HZ` (line 97, lines 1561-1572). That end\n * clears the pressure (lines 1645-1646). Thus this limit stops the scan after `64000 / HZ + 1` entries.\n * - That count also holds each entry that expired by its own timeout, in any namespace (lines\n * 1575-1578). Thus `expired` such entries before the end take `expired` drops from the namespace.\n *\n * The limit that stops the scan first gives the floor. `expired` is 0 by default, which gives the\n * lowest floor. On a host with other flows, a scan can find some, and the floor is higher.\n */\nexport const conntrackFloor = (max: number, hz: number, expired = 0): number => {\n const drops = Math.max(0, Math.floor(64000 / hz) + 1 - expired);\n return Math.max(Math.floor(max / 100) * 95 - 1, max - drops);\n};\n","import type { Extent, Quantity, Rational, Unknown } from \"@mark1russell7/quantity\";\nimport {\n convertExact,\n isUnbounded,\n quantity,\n rationals as r,\n unbounded,\n} from \"@mark1russell7/quantity\";\nimport type { Expr, Machine, TransitionDef } from \"./machine.ts\";\nimport { FIRED, arr, exprKnobs, fromStates } from \"./machine.ts\";\n\n/**\n * This module has the closed forms of the algebra. They give the duration of a timer of a\n * machine, and how late and how early it can fire, from the values of its knobs.\n *\n * A machine document writes each duration in one of four forms (`machine.ts`): a constant, a knob,\n * arithmetic over its knobs, or a named model. The arithmetic uses the value of each knob in the\n * unit that the document gives to that knob. Thus `tcp_keepalive / 3` of Redis divides whole\n * seconds, as Redis does. A model is the formula of the implementation itself, for example the\n * retransmission budget of the kernel. The values are exact rationals, not floats: 0.2 s × 1023\n * is 204.6 s, not 204.60000000000002.\n *\n * A knob without a value makes the result unknown, and the result names the knob. A knob that\n * nothing sets (no bound) makes a duration without an end.\n */\n\n/** This function gives the value of each knob, by the name of the machine for it: an amount, no bound, or unknown and the reason. */\nexport type KnobValues = (name: string) => Extent | Unknown | undefined;\n\n/** Timer bounds tell how long a timer operates, how late it can fire and how early, each in the unit of its document. */\nexport interface TimerBounds {\n readonly duration: Extent | Unknown;\n readonly lateness?: Extent | Unknown | undefined;\n readonly early?: Extent | Unknown | undefined;\n}\n\n/**\n * A value is an exact rational, no bound, or unknown with its reason. No bound has a sign. A\n * duration is not negative, but a step of the arithmetic can be: cap − ∞ is −∞, and\n * max(cap − ∞, cap / 2) is cap / 2.\n */\ntype Value =\n | { readonly kind: \"exact\"; readonly n: Rational }\n | { readonly kind: \"infinite\"; readonly negative?: true }\n | { readonly kind: \"unknown\"; readonly why: string };\n\nconst exact = (n: Rational): Value => ({ kind: \"exact\", n });\nconst INFINITE: Value = { kind: \"infinite\" };\nconst NEGATIVE_INFINITE: Value = { kind: \"infinite\", negative: true };\n/** This function gives the sign of a value that is not unknown: −1, 0 or 1. */\nconst signOf = (value: Value): number =>\n value.kind === \"infinite\"\n ? value.negative === true\n ? -1\n : 1\n : value.kind === \"exact\"\n ? r.cmp(value.n, r.ZERO)\n : 0;\n/** This function gives no bound with a sign. */\nconst unboundedOf = (sign: number): Value => (sign < 0 ? NEGATIVE_INFINITE : INFINITE);\nconst unknown = (why: string): Value => ({ kind: \"unknown\", why });\nconst whole = (n: bigint): Rational => r.rational(n);\n\n/** This function gives the first unknown among some values. An operation over them gets it. */\nconst unknownOf = (values: readonly Value[]): Value | undefined =>\n values.find((value) => value.kind === \"unknown\");\n\n// ---------------------------------------------------------------------------------------------\n// the arithmetic of the documents: + - * /, min, max, floor, ceil, parentheses, numbers, knob names\n// ---------------------------------------------------------------------------------------------\n\n/** A node is the arithmetic of a document, after the parse. */\nexport type Node =\n | { readonly op: \"num\"; readonly n: Rational }\n | { readonly op: \"knob\"; readonly name: string }\n | { readonly op: \"+\" | \"-\" | \"*\" | \"/\"; readonly a: Node; readonly b: Node }\n | { readonly op: \"neg\"; readonly a: Node }\n | { readonly op: \"min\" | \"max\" | \"floor\" | \"ceil\" | \"pow\"; readonly args: readonly Node[] };\n\nconst FUNCTIONS = { min: 2, max: 2, floor: 1, ceil: 1, pow: 2 } as const;\n\n/** This count is the largest exponent that `pow` takes. A larger one is a mistake in a document, not a timer. */\nconst POW_LIMIT = 4096n;\n\n/**\n * This function gives a value to a whole power: `pow(a, n)`. The exponent must be an exact whole\n * number, for example the `fired` of a backoff. A negative exponent gives the reciprocal. No bound\n * to the power 0 is 1, and to a positive power it keeps its sign when the power is odd.\n */\nconst power = (a: Value, b: Value): Value => {\n if (b.kind !== \"exact\" || !r.isInteger(b.n)) return unknown(\"pow takes a whole exponent\");\n const k = b.n.n;\n if (k > POW_LIMIT || k < -POW_LIMIT) return unknown(`pow takes an exponent of ${POW_LIMIT} or less`);\n if (a.kind === \"infinite\") {\n if (k === 0n) return exact(r.ONE);\n if (k < 0n) return exact(r.ZERO);\n return k % 2n === 0n ? INFINITE : a;\n }\n if (a.kind !== \"exact\") return unknown(\"not an amount\");\n if (k < 0n && a.n.n === 0n) return unknown(\"a division by zero\");\n return exact(r.pow(a.n, Number(k)));\n};\n\n/** This function parses the arithmetic of a document, or it throws an error that tells where the text stops making sense. */\nexport const parseExpr = (text: string): Node => {\n const tokens = text.match(/\\d+(?:\\.\\d+)?|[A-Za-z_][A-Za-z0-9_.]*|[-+*/(),]|\\S/g) ?? [];\n let at = 0;\n const peek = (): string | undefined => tokens[at];\n const take = (expected?: string): string => {\n const token = tokens[at];\n if (token === undefined || (expected !== undefined && token !== expected)) {\n throw new Error(`\"${text}\": expected ${expected ?? \"more\"} at ${token ?? \"the end\"}`);\n }\n at += 1;\n return token;\n };\n const expr = (): Node => {\n let node = term();\n while (peek() === \"+\" || peek() === \"-\") {\n const op = take() as \"+\" | \"-\";\n node = { op, a: node, b: term() };\n }\n return node;\n };\n const term = (): Node => {\n let node = factor();\n while (peek() === \"*\" || peek() === \"/\") {\n const op = take() as \"*\" | \"/\";\n node = { op, a: node, b: factor() };\n }\n return node;\n };\n const factor = (): Node => {\n const token = take();\n if (token === \"(\") {\n const inner = expr();\n take(\")\");\n return inner;\n }\n if (token === \"-\") return { op: \"neg\", a: factor() };\n if (/^\\d/.test(token)) return { op: \"num\", n: r.fromDecimal(token) };\n if (!/^[A-Za-z_]/.test(token)) throw new Error(`\"${text}\": ${token} is not a term`);\n // Only an own key is a function: `toString` is a knob, as each other name.\n if (Object.hasOwn(FUNCTIONS, token)) {\n const name = token as keyof typeof FUNCTIONS;\n take(\"(\");\n const args = [expr()];\n while (peek() === \",\") {\n take(\",\");\n args.push(expr());\n }\n take(\")\");\n if (args.length !== FUNCTIONS[name]) {\n throw new Error(`\"${text}\": ${name} takes ${FUNCTIONS[name]}, not ${args.length}`);\n }\n return { op: name, args };\n }\n return { op: \"knob\", name: token };\n };\n const node = expr();\n if (at < tokens.length) throw new Error(`\"${text}\": ${tokens[at]} after the end`);\n return node;\n};\n\nconst run = (node: Node, valueOf: (name: string) => Value): Value => {\n if (node.op === \"num\") return exact(node.n);\n if (node.op === \"knob\") return valueOf(node.name);\n if (node.op === \"neg\") {\n const a = run(node.a, valueOf);\n return a.kind === \"exact\" ? exact(r.neg(a.n)) : a.kind === \"infinite\" ? unboundedOf(-signOf(a)) : a;\n }\n if (\"args\" in node) {\n const args = node.args.map((arg) => run(arg, valueOf));\n const lost = unknownOf(args);\n if (lost !== undefined) return lost;\n if (node.op === \"floor\" || node.op === \"ceil\") {\n const [a] = args as [Value];\n return a.kind === \"exact\" ? exact(node.op === \"floor\" ? r.floor(a.n) : r.ceil(a.n)) : a;\n }\n const [a, b] = args as [Value, Value];\n if (node.op === \"pow\") return power(a, b);\n if (a.kind === \"infinite\" || b.kind === \"infinite\") {\n // +∞ wins a max and loses a min, and −∞ loses a max and wins a min\n const above = (x: Value, y: Value): boolean =>\n x.kind === \"infinite\" ? signOf(x) > 0 || (y.kind === \"infinite\" && signOf(y) < 0) : signOf(y) < 0;\n const larger = above(a, b) ? a : b;\n const smaller = larger === a ? b : a;\n return node.op === \"max\" ? larger : smaller;\n }\n if (a.kind !== \"exact\" || b.kind !== \"exact\") return unknown(\"not an amount\");\n const aFirst = r.cmp(a.n, b.n) <= 0;\n if (node.op === \"min\") return aFirst ? a : b;\n return aFirst ? b : a;\n }\n const a = run(node.a, valueOf);\n const b = run(node.b, valueOf);\n const lost = unknownOf([a, b]);\n if (lost !== undefined) return lost;\n if (a.kind === \"exact\" && b.kind === \"exact\") {\n if (node.op === \"/\" && b.n.n === 0n) return unknown(\"a division by zero\");\n const op = { \"+\": r.add, \"-\": r.sub, \"*\": r.mul, \"/\": r.div }[node.op];\n return exact(op(a.n, b.n));\n }\n // a timer that nothing sets is longer than each sum, and each positive multiple. Its sign\n // follows the arithmetic: cap − ∞ is −∞, which a max then discards\n if (node.op === \"+\" || node.op === \"-\") {\n const sa = signOf(a);\n const sb = node.op === \"-\" ? -signOf(b) : signOf(b);\n if (a.kind === \"infinite\" && b.kind === \"infinite\" && sa !== sb)\n return unknown(\"no bound less no bound\");\n return unboundedOf(a.kind === \"infinite\" ? sa : sb);\n }\n if (node.op === \"*\") {\n const sign = signOf(a) * signOf(b);\n return sign === 0 ? unknown(\"zero times no bound\") : unboundedOf(sign);\n }\n if (a.kind === \"infinite\" && b.kind === \"infinite\") return unknown(\"no bound over no bound\");\n if (b.kind === \"infinite\") return exact(r.ZERO);\n const sign = signOf(a) * signOf(b);\n return sign === 0 ? unknown(\"no bound over zero\") : unboundedOf(sign);\n};\n\n// ---------------------------------------------------------------------------------------------\n// the named models: the formula of an implementation over its knobs, in seconds\n// ---------------------------------------------------------------------------------------------\n\nconst integer = (value: Rational, what: string): bigint => {\n if (!r.isInteger(value) || value.n < 0n)\n throw new Error(`${what} is not a whole count: ${r.toNumber(value)}`);\n return value.n;\n};\n/** This function gives min(base × 2^k, cap), exactly. */\nconst capped = (base: Rational, k: bigint, cap: Rational): Rational => {\n const doubled = r.mul(base, whole(2n ** k));\n return r.cmp(doubled, cap) <= 0 ? doubled : cap;\n};\n/**\n * This function gives the hypothetical retransmission timeout of the kernel, `tcp_model_timeout`\n * in `net/ipv4/tcp_timer.c`. The waits double from the minimum RTO until a step is more than the\n * maximum, and then the waits are capped. For `tcp_retries2` = 15, it is 0.2 s × (2^10 − 1) +\n * 6 × 120 s = 924.6 s.\n */\nconst retransBudget = (retries: bigint, min: Rational, max: Rational): Rational => {\n let thresh = 0n;\n while (r.cmp(r.mul(min, whole(2n ** (thresh + 1n))), max) <= 0) thresh += 1n;\n if (retries <= thresh) return r.mul(min, whole(2n ** (retries + 1n) - 1n));\n return r.add(r.mul(min, whole(2n ** (thresh + 1n) - 1n)), r.mul(whole(retries - thresh), max));\n};\n\n/** These are `TCP_TIMEOUT_INIT` and `TCP_RTO_MAX` in `include/net/tcp.h` at v6.6: the first SYN RTO and the cap. */\nconst TCP_TIMEOUT_INIT = whole(1n);\nconst TCP_RTO_MAX = whole(120n);\n\n/**\n * This function gives the wait of the SYN of a connect after `fired` firings, from 6.5\n * (`tcp_retransmit_timer` in `net/ipv4/tcp_timer.c`). Each firing sends the SYN again. The first\n * `tcp_syn_linear_timeouts` firings keep the initial RTO, thus the waits 0 to\n * `tcp_syn_linear_timeouts` are 1 s each. Then each firing doubles the wait, up to `TCP_RTO_MAX`.\n */\nconst synWait = (fired: bigint, linear: bigint): Rational =>\n fired <= linear ? TCP_TIMEOUT_INIT : capped(TCP_TIMEOUT_INIT, fired - linear, TCP_RTO_MAX);\n\n/**\n * This function gives each wait of the SYN of a connect, from 6.5: the waits 0 to\n * `tcp_syn_retries` + `tcp_syn_linear_timeouts` (`synWait`). The connect gives up at the end of the last wait.\n */\nconst synWaits = (retries: bigint, linear: bigint): Rational[] =>\n Array.from({ length: Number(linear + 1n + retries) }, (_, fired) => synWait(BigInt(fired), linear));\n\n/**\n * This function gives the waits of the SYN of a connect up to the firing that gives up, from 6.5\n * (`tcp_write_timeout` in `net/ipv4/tcp_timer.c` at v7.0, lines 242-284). A firing applies two tests.\n *\n * - The count test: the retransmissions before it are `tcp_syn_retries` + `tcp_syn_linear_timeouts`.\n * - The time test: `retransmits_timed_out` with the boundary `tcp_syn_retries` and no linear term. Its\n * budget is `tcp_model_timeout` from an RTO of 1 s, (2^(retries + 1) - 1) s, from the first SYN\n * (`tcp_connect` sets `retrans_stamp`, `tcp_output.c` line 4370). It needs one retransmission.\n *\n * The first firing that passes one test gives up. At the defaults both tests give 131 s. At\n * `tcp_syn_retries` 2 and 4 linear waits, the time test gives 7 s and the count test gives 11 s.\n */\nconst synGiveUpWaits = (retries: bigint, linear: bigint): Rational[] => {\n const budget = retransBudget(retries, TCP_TIMEOUT_INIT, TCP_RTO_MAX);\n const waits = synWaits(retries, linear);\n let at = whole(0n);\n for (let fired = 0; fired < waits.length; fired += 1) {\n at = r.add(at, waits[fired]!);\n // the firing after this wait has `fired` retransmissions before it, and the time test needs one\n if (fired >= 1 && r.cmp(at, budget) >= 0) return waits.slice(0, fired + 1);\n }\n return waits;\n};\n\n/**\n * This function gives how early the connect can give up, in seconds. The time test reads the real\n * time of a firing, and the wheel makes that time late. A firing before the nominal one can pass it when its\n * lateness takes it past the budget. With `tcp_usec_ts`, the test adds one jiffy (line 233).\n */\nconst synGiveUpEarly = (retries: bigint, linear: bigint, hz: Rational): Rational => {\n const budget = retransBudget(retries, TCP_TIMEOUT_INIT, TCP_RTO_MAX);\n const waits = synGiveUpWaits(retries, linear);\n const end = waits.reduce((total, wait) => r.add(total, wait), whole(0n));\n const jiffy = r.div(whole(1n), hz);\n let at = whole(0n);\n let late = whole(0n);\n for (let fired = 0; fired < waits.length - 1; fired += 1) {\n at = r.add(at, waits[fired]!);\n late = r.add(late, r.div(whole(granularity(jiffiesOf(waits[fired]!, hz))), hz));\n if (fired >= 1 && r.cmp(r.add(r.add(at, late), jiffy), budget) >= 0) {\n const low = r.sub(budget, jiffy);\n return r.sub(end, r.cmp(low, at) >= 0 ? low : at);\n }\n }\n return whole(0n);\n};\n\n/**\n * This function gives the SYNs that a connect sends before it gives up: the first SYN and each\n * retransmission (`synGiveUpWaits`). A connect whose SYN does not leave adds each of them to the field\n * `drop` of conntrack, and each retransmission to `TCPRetransFail`.\n */\nexport const synGiveUpSends = (retries: number, linear: number): number =>\n synGiveUpWaits(BigInt(retries), BigInt(linear)).length;\n\n/** This function gives the whole jiffies of a time at HZ, rounded up, as `msecs_to_jiffies` and `usecs_to_jiffies` round. */\nconst jiffiesOf = (seconds: Rational, hz: Rational): bigint => r.ceil(r.mul(seconds, hz)).n;\n\n/**\n * This function gives the longest wait of the delayed ACK, in jiffies (`tcp_send_delayed_ack` in\n * `net/ipv4/tcp_output.c:4004-4054` at v6.6). The wait is the ACK timeout, `ato`. It is at least\n * `TCP_DELACK_MIN`, HZ/25. Above that, the smoothed round trip in whole jiffies bounds it, but not\n * below `TCP_DELACK_MIN`. The cap is `icsk_delack_max`, `TCP_DELACK_MAX` by default, HZ/5\n * (`include/net/tcp.h:133-136`, `net/ipv4/tcp.c:425`). Thus it is 40 ms on a fast path at each HZ, and\n * 200 ms at most.\n */\nconst delackWait = (rtt: Rational, hz: Rational): bigint => {\n const ticks = integer(hz, \"hz\");\n const least = ticks / 25n;\n const most = ticks / 5n;\n const srtt = jiffiesOf(rtt, hz);\n const bound = srtt > least ? srtt : least;\n return bound < most ? bound : most;\n};\n\n/**\n * This function gives how late the timer wheel can fire a timer that is due in `jiffies`\n * (`calc_wheel_index` in `kernel/time/timer.c` at v6.6). Level 0 holds the timers due in 63 jiffies\n * or less. Each level above holds eight times as long, at eight times the granularity. The wheel\n * rounds a timer up to the next boundary of its level, thus it fires up to one granularity late.\n * At HZ 250, a 2 h timer can be up to 131 s late.\n */\nconst granularity = (jiffies: bigint): bigint => {\n let level = 0n;\n while (level < 8n && jiffies >= 63n << (3n * level)) level += 1n;\n return 8n ** level;\n};\n\n/**\n * This function gives the lateness of the retransmission give-up after its budget. The first\n * retransmission sets the RTO to the round trip plus the minimum, rounded up to a jiffy\n * (`tcp_set_rto`). On a Docker network at HZ 250, that is 204 ms, not 200.\n *\n * Each firing doubles the RTO, up to the cap. The budget ends in the firing after the last one\n * that is short of it. Thus the give-up comes one step late at most, plus the rounding of each\n * firing on the wheel. The model assumes a steady path, whose variance stays below the minimum RTO.\n */\nconst retransLateness = (\n retries: bigint,\n min: Rational,\n max: Rational,\n rtt: Rational,\n hz: Rational,\n): Rational => {\n const base = jiffiesOf(r.add(min, rtt), hz);\n const cap = jiffiesOf(max, hz);\n let step = base;\n let wheel = 0n;\n for (let k = 1n; k <= retries + 1n; k += 1n) {\n step = base * 2n ** k < cap ? base * 2n ** k : cap;\n wheel += granularity(step);\n }\n return r.div(whole(step + wheel), hz);\n};\n\n/**\n * This function gives one wait of the retransmission timer with one segment in flight, in jiffies\n * (`net/ipv4/tcp_timer.c`, and `tcp_schedule_loss_probe` in `tcp_output.c`, at v6.6). Its first\n * firing is the tail loss probe. For one segment, the probe waits two round trips plus\n * `TCP_RTO_MIN`, but not longer than the RTO. Thus it waits the RTO itself: the round trip plus\n * the minimum, in whole jiffies.\n *\n * The probe arms the RTO again, and each RTO firing doubles it, up to the cap. Thus the\n * firing k comes 2^k RTOs after the send: 0.204, 0.408, 0.816 s on a Docker network at HZ 250.\n * With more than one segment in flight, the probe waits two round trips plus 2 jiffies.\n */\nconst rtoWait = (fired: bigint, min: Rational, max: Rational, rtt: Rational, hz: Rational) => {\n const base = jiffiesOf(r.add(min, rtt), hz);\n const cap = jiffiesOf(max, hz);\n if (fired === 0n) return base;\n const doubled = base * 2n ** (fired - 1n);\n return doubled < cap ? doubled : cap;\n};\n\n/**\n * This function gives the lateness of keepalive. It adds the idle timer and the interval of each\n * probe, each rounded up on the wheel at its own level. Linux arms the idle timer, then one probe\n * interval for each probe without an answer.\n */\n/**\n * This function gives the lateness of the retransmission give-up after its budget, under an ICMP\n * host or net unreachable for each RTO retransmission. Each ICMP reverts one doubling of the backoff\n * (`tcp_ld_RTO_revert` in `net/ipv4/tcp_ipv4.c` at v6.6, RFC 6069). Then each wait after the first RTO\n * firing is one RTO again, thus the give-up comes at most one RTO after the budget. Each firing up\n * to it can fire up to the granularity of its level of the wheel late.\n */\nconst retransLatenessReverted = (\n retries: bigint,\n min: Rational,\n max: Rational,\n rtt: Rational,\n hz: Rational,\n): Rational => {\n const base = jiffiesOf(r.add(min, rtt), hz);\n const budget = jiffiesOf(retransBudget(retries, min, max), hz);\n const firings = (budget + base - 1n) / base + 1n;\n return r.div(whole(base + firings * granularity(base)), hz);\n};\n\nconst keepaliveLateness = (\n idle: Rational,\n interval: Rational,\n probes: bigint,\n hz: Rational,\n): Rational => {\n const late = (time: Rational) => whole(granularity(jiffiesOf(time, hz)));\n return r.div(r.add(late(idle), r.mul(whole(probes), late(interval))), hz);\n};\n\ninterface Model {\n /** These are the knobs that it reads, in sequence, and the unit to read each in (null for a count). */\n readonly knobs: readonly (string | null)[];\n /** This function gives the result in seconds. */\n readonly seconds: (args: readonly Rational[]) => Rational;\n readonly source: string;\n}\n\nconst MODELS: Readonly<Record<string, Model>> = {\n \"linux.retrans-budget\": {\n knobs: [null, \"s\", \"s\"],\n seconds: ([retries, min, max]) => retransBudget(integer(retries!, \"tcp_retries2\"), min!, max!),\n source: \"net/ipv4/tcp_timer.c tcp_model_timeout at v6.6\",\n },\n // the give-up comes at the first RTO firing at the budget or after it: one step later at most,\n // at the real RTO of the path, plus the rounding of each firing on the wheel\n \"linux.retrans-step\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([retries, min, max, rtt, hz]) =>\n retransLateness(integer(retries!, \"tcp_retries2\"), min!, max!, rtt!, hz!),\n source:\n \"net/ipv4/tcp_timer.c, tcp_input.c tcp_set_rto and kernel/time/timer.c at v6.6 (measured by @mark1russell7/harness, 2026-10-08)\",\n },\n // one wait of the retransmission timer, the first of the loss probe: 2^(fired − 1) RTOs after it\n \"linux.rto-wait\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([fired, min, max, rtt, hz]) =>\n r.div(whole(rtoWait(integer(fired!, FIRED), min!, max!, rtt!, hz!)), hz!),\n source:\n \"net/ipv4/tcp_timer.c tcp_retransmit_timer and tcp_output.c tcp_schedule_loss_probe at v6.6 (measured by @mark1russell7/harness, 2026-10-12)\",\n },\n // one wait of the retransmission timer when each RTO retransmission draws an ICMP host or net\n // unreachable: the revert of RFC 6069 takes back the doubling, thus each wait is one RTO\n \"linux.rto-wait-reverted\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([, min, , rtt, hz]) => r.div(whole(jiffiesOf(r.add(min!, rtt!), hz!)), hz!),\n source: \"net/ipv4/tcp_ipv4.c tcp_v4_err and tcp_ld_RTO_revert at v6.6 (RFC 6069)\",\n },\n // the give-up under that revert: at most one RTO after its budget, plus the rounding of each firing\n \"linux.retrans-step-reverted\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([retries, min, max, rtt, hz]) =>\n retransLatenessReverted(integer(retries!, \"tcp_retries2\"), min!, max!, rtt!, hz!),\n source:\n \"net/ipv4/tcp_ipv4.c tcp_ld_RTO_revert and net/ipv4/tcp_timer.c retransmits_timed_out at v6.6 (RFC 6069)\",\n },\n // the rounding of that wait on the timer wheel, at the level that its length puts it in\n \"linux.rto-wait-lateness\": {\n knobs: [null, \"s\", \"s\", \"s\", \"Hz\"],\n seconds: ([fired, min, max, rtt, hz]) =>\n r.div(whole(granularity(rtoWait(integer(fired!, FIRED), min!, max!, rtt!, hz!))), hz!),\n source: \"kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // the idle timer of keepalive and the interval of each probe, each rounded on the wheel\n \"linux.keepalive-lateness\": {\n knobs: [\"s\", \"s\", null, \"Hz\"],\n seconds: ([idle, interval, probes, hz]) =>\n keepaliveLateness(idle!, interval!, integer(probes!, \"keepcnt\"), hz!),\n source: \"net/ipv4/tcp_timer.c tcp_keepalive_timer and kernel/time/timer.c at v6.6\",\n },\n // the rounding of one firing on the wheel: how late one timer due after this time can fire\n \"linux.wheel\": {\n knobs: [\"s\", \"Hz\"],\n seconds: ([time, hz]) => r.div(whole(granularity(jiffiesOf(time!, hz!))), hz!),\n source: \"kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // the longest wait of the delayed ACK: min(max(srtt, TCP_DELACK_MIN), TCP_DELACK_MAX), in jiffies\n \"linux.delack\": {\n knobs: [\"s\", \"Hz\"],\n seconds: ([rtt, hz]) => r.div(whole(delackWait(rtt!, hz!)), hz!),\n source:\n \"net/ipv4/tcp_output.c tcp_send_delayed_ack, include/net/tcp.h TCP_DELACK_MIN and TCP_DELACK_MAX at v6.6\",\n },\n // the rounding of that wait on the timer wheel: 1 jiffy at 40 ms, 8 at 200 ms at HZ 1000\n \"linux.delack-lateness\": {\n knobs: [\"s\", \"Hz\"],\n seconds: ([rtt, hz]) => r.div(whole(granularity(delackWait(rtt!, hz!))), hz!),\n source: \"net/ipv4/tcp_output.c tcp_send_delayed_ack and kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // one jiffy: a timer counts from the tick before the event that arms it\n \"linux.jiffy\": {\n knobs: [\"Hz\"],\n seconds: ([hz]) => r.div(whole(1n), hz!),\n source: \"include/linux/jiffies.h\",\n },\n // 6.5 and later: the first tcp_syn_linear_timeouts retransmissions wait the initial RTO, the\n // others double it. The SYN gives up at the first firing after syn_retries + linear_timeouts\n // retransmissions, or after the budget of tcp_model_timeout for syn_retries, which comes first\n \"linux.syn-giveup\": {\n knobs: [null, null],\n seconds: ([retries, linear]) =>\n synGiveUpWaits(integer(retries!, \"tcp_syn_retries\"), integer(linear!, \"tcp_syn_linear_timeouts\")).reduce(\n (total, wait) => r.add(total, wait),\n whole(0n),\n ),\n source:\n \"net/ipv4/tcp_timer.c tcp_write_timeout, retransmits_timed_out and tcp_model_timeout at v7.0 (lines 187-284)\",\n },\n // the rounding of each of those waits on the timer wheel, at the level that its length puts it in:\n // 6.08 s at the defaults and HZ 1000, because the last wait of 64 s can be 4.096 s late\n \"linux.syn-giveup-lateness\": {\n knobs: [null, null, \"Hz\"],\n seconds: ([retries, linear, hz]) =>\n r.div(\n whole(\n synGiveUpWaits(integer(retries!, \"tcp_syn_retries\"), integer(linear!, \"tcp_syn_linear_timeouts\")).reduce(\n (total, wait) => total + granularity(jiffiesOf(wait, hz!)),\n 0n,\n ),\n ),\n hz!,\n ),\n source: \"net/ipv4/tcp_timer.c tcp_retransmit_timer and kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // how early the SYN can give up: a late firing before the nominal one can pass the time test.\n // 0 at the defaults and at syn_retries 2, because no such firing comes near the budget\n \"linux.syn-giveup-early\": {\n knobs: [null, null, \"Hz\"],\n seconds: ([retries, linear, hz]) =>\n synGiveUpEarly(integer(retries!, \"tcp_syn_retries\"), integer(linear!, \"tcp_syn_linear_timeouts\"), hz!),\n source: \"net/ipv4/tcp_timer.c retransmits_timed_out at v7.0 (lines 214-239) and kernel/time/timer.c calc_wheel_index\",\n },\n // one wait of the SYN of a connect, after `fired` firings: 1 s for the waits 0 to\n // tcp_syn_linear_timeouts, then doubled at each firing, up to TCP_RTO_MAX\n \"linux.syn-wait\": {\n knobs: [null, null],\n seconds: ([fired, linear]) => synWait(integer(fired!, FIRED), integer(linear!, \"tcp_syn_linear_timeouts\")),\n source:\n \"net/ipv4/tcp_timer.c tcp_retransmit_timer at v6.6 (lines 604 and 624-631) and at v6.17 (lines 448 and 671-678)\",\n },\n // the rounding of that wait on the timer wheel: 64 jiffies for a wait of 1 s at HZ 1000, 8 at HZ 250\n \"linux.syn-wait-lateness\": {\n knobs: [null, null, \"Hz\"],\n seconds: ([fired, linear, hz]) =>\n r.div(\n whole(granularity(jiffiesOf(synWait(integer(fired!, FIRED), integer(linear!, \"tcp_syn_linear_timeouts\")), hz!))),\n hz!,\n ),\n source: \"net/ipv4/tcp_timer.c tcp_retransmit_timer and kernel/time/timer.c calc_wheel_index at v6.6\",\n },\n // the default retryStrategy of ioredis 6: min(2^(times - 1) × 50, 5000) ms, plus a jitter of up\n // to 199 ms, which the lateness of the timer carries. Its times counts attempts from 1 after the\n // last ready, thus it is one more than the number of firings of the timer. 5.x waited\n // min(times × 50, 2000) ms\n \"ioredis.retry-base\": {\n knobs: [null],\n seconds: ([fired]) => capped(r.fromDecimal(\"0.05\"), integer(fired!, FIRED), whole(5n)),\n source:\n \"ioredis 6.0.0 built/redis/RedisOptions.js retryStrategy and built/redis/event_handler.js\",\n },\n};\n\n/** This function gives the model of a name, or undefined. Only an own key is a model: `toString` is not one. */\nconst modelOf = (name: string): Model | undefined => (Object.hasOwn(MODELS, name) ? MODELS[name] : undefined);\n\n// ---------------------------------------------------------------------------------------------\n// the evaluation of a duration and a timer\n// ---------------------------------------------------------------------------------------------\n\n/**\n * This function gives the value of a knob in the unit that the document gives it (or as a count\n * when it is a count). For `fired`, it gives which wait of a backoff timer it is.\n */\nconst knobIn = (\n doc: Machine,\n name: string,\n unit: string | null,\n values: KnobValues,\n fired: number | undefined,\n): Value => {\n if (name === FIRED)\n return fired === undefined\n ? unknown(\"one wait of a timer with a backoff: say which, by how many times it has fired\")\n : exact(r.fromNumber(fired));\n if (!Object.hasOwn(doc.knobs, name)) return unknown(`the machine names no knob ${name}`);\n const given = values(name);\n if (given === undefined) return unknown(`nothing gives ${name}'s value`);\n if (\"unknown\" in given) return unknown(`${name}: ${given.unknown}`);\n if (given.value === \"infinite\") return INFINITE;\n const value = r.fromNumber(given.value);\n // a knob at its off value turns its timers off: a time that reads it has no bound\n const { off, unit: own } = doc.knobs[name]!;\n if (off !== undefined && own !== null && r.toNumber(convertExact(value, given.unit, own)) === off)\n return INFINITE;\n return exact(\n unit === null\n ? convertExact(value, given.unit, given.unit)\n : convertExact(value, given.unit, unit),\n );\n};\n\nconst out = (value: Value, unit: string): Extent | Unknown =>\n value.kind === \"exact\"\n ? quantity(r.toNumber(value.n), unit)\n : value.kind === \"infinite\"\n ? value.negative === true\n ? { unknown: \"a negative unbounded time\", unit }\n : unbounded(unit)\n : { unknown: value.why, unit };\n\n/**\n * This function evaluates one duration of a timer of a machine, in the unit that its document\n * gives it. The waits of a backoff timer read `fired`, which tells which wait.\n */\nexport const evaluate = (\n doc: Machine,\n expr: Expr,\n values: KnobValues,\n fired?: number,\n): Extent | Unknown => {\n if (\"const\" in expr) return quantity(expr.const, expr.unit);\n if (\"knob\" in expr) {\n return out(knobIn(doc, expr.knob, expr.unit, values, fired), expr.unit);\n }\n if (\"expr\" in expr) {\n const tree = parseExpr(expr.expr);\n const value = run(tree, (name) =>\n knobIn(doc, name, doc.knobs[name]?.unit ?? null, values, fired),\n );\n return out(value, expr.unit);\n }\n const model = modelOf(expr.model);\n if (model === undefined) return { unknown: `no model ${expr.model}`, unit: expr.unit };\n if (model.knobs.length !== expr.knobs.length) {\n return {\n unknown: `${expr.model} reads ${model.knobs.length} knobs, not ${expr.knobs.length}`,\n unit: expr.unit,\n };\n }\n const args = expr.knobs.map((name, index) =>\n knobIn(doc, name, model.knobs[index] ?? null, values, fired),\n );\n const lost = unknownOf(args);\n if (lost !== undefined) return out(lost, expr.unit);\n if (args.some((arg) => arg.kind === \"infinite\")) return unbounded(expr.unit);\n const seconds = model.seconds(args.map((arg) => (arg as { n: Rational }).n));\n return quantity(r.toNumber(convertExact(seconds, \"s\", expr.unit)), expr.unit);\n};\n\n/**\n * This function gives the bounds of a timer of a machine: how long it operates, how late it can\n * fire, how early. For a backoff timer, it gives one of its waits: the wait after `fired` firings.\n */\nexport const timerOf = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n fired?: number,\n): TimerBounds => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n return {\n duration: evaluate(doc, def.duration, values, fired),\n ...(def.lateness !== undefined ? { lateness: evaluate(doc, def.lateness, values, fired) } : {}),\n ...(def.early !== undefined ? { early: evaluate(doc, def.early, values, fired) } : {}),\n };\n};\n\n/** A firing is one firing of a backoff timer, after `fired` firings: its time from the arming. */\nexport interface Firing {\n readonly fired: number;\n /** This time is the sum of the waits to this firing, each less how early it can fire. */\n readonly low: Quantity;\n /** This time is the sum of the waits to this firing, each plus how late it can fire. */\n readonly high: Quantity;\n}\n\n/** A recovery tells when the firings of a backoff timer move a connection again after a stall. */\nexport interface Recovery {\n /** These are its firings from its arming, up to the first one that surely comes after the end of the stall. */\n readonly firings: readonly Firing[];\n /**\n * These are the firings that can be the first after the end of the stall. There is more than one\n * when the end falls in the bounds of a firing: that firing can come before the end or after it.\n */\n readonly first: readonly number[];\n /** This time is the earliest time of the first firing after the end of the stall, from the arming. */\n readonly low: Quantity;\n /** This time is the latest time of that firing, from the arming. */\n readonly high: Quantity;\n}\n\n/** This count is the most firings that `recovery` examines before it tells that the stall is longer than them. */\nconst FIRINGS = 4096;\n\n/**\n * This function gives the recovery from a stall. A backoff timer continues to fire through a\n * stall, and what each firing sends gets through only after the stall ends. Thus the connection\n * moves again at the first firing at the end or after it. That firing can be most of a wait after\n * the end. A stall that stops immediately after one firing costs almost all of the next, longer\n * wait.\n *\n * The stall counts from the arming of the timer, which is the send that the stall first lost. The\n * waits add, and so do how early and how late each can fire.\n */\nexport const recovery = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n stall: Extent,\n): Recovery | Unknown => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n if (def.backoff === undefined) throw new Error(`${doc.title}'s ${timer} has no backoff`);\n if (isUnbounded(stall))\n return { unknown: \"a stall that never ends: nothing recovers from it\", unit: \"s\" };\n const end = convertExact(r.fromNumber(stall.value), stall.unit, \"s\");\n const inSeconds = (extent: Extent | Unknown | undefined, what: string): Rational | string => {\n if (extent === undefined) return r.ZERO;\n if (\"unknown\" in extent) return `${what}: ${extent.unknown}`;\n if (isUnbounded(extent)) return `${what} has no bound, so the timer never fires again`;\n return convertExact(r.fromNumber(extent.value), extent.unit, \"s\");\n };\n const s = (value: Rational): Quantity => quantity(r.toNumber(value), \"s\");\n const sums: Array<{ fired: number; low: Rational; high: Rational }> = [];\n let low = r.ZERO;\n let high = r.ZERO;\n for (let fired = 0; fired < FIRINGS; fired += 1) {\n const bounds = timerOf(doc, timer, values, fired);\n const wait = inSeconds(bounds.duration, `wait ${fired}`);\n const early = inSeconds(bounds.early, `wait ${fired}'s early bound`);\n const late = inSeconds(bounds.lateness, `wait ${fired}'s lateness`);\n if (typeof wait === \"string\") return { unknown: wait, unit: \"s\" };\n if (typeof early === \"string\") return { unknown: early, unit: \"s\" };\n if (typeof late === \"string\") return { unknown: late, unit: \"s\" };\n low = r.add(low, r.sub(wait, early));\n high = r.add(high, r.add(wait, late));\n sums.push({ fired, low, high });\n if (r.cmp(low, end) < 0) continue;\n // a firing whose latest time is at the end or after it can be the first after the end\n const first = sums.filter((f) => r.cmp(f.high, end) >= 0);\n const earliest = first[0]!.low;\n return {\n firings: sums.map((f) => ({ fired: f.fired, low: s(f.low), high: s(f.high) })),\n first: first.map((f) => f.fired),\n low: s(r.cmp(earliest, end) >= 0 ? earliest : end),\n high: s(first.at(-1)!.high),\n };\n }\n return { unknown: `${FIRINGS} firings do not outlast the stall`, unit: \"s\" };\n};\n\n// ---------------------------------------------------------------------------------------------\n// the times on a timeline: the band of a timer, the firings of a backoff timer, a train of probes\n// ---------------------------------------------------------------------------------------------\n\n/** A band is the range of times in which a timer fires, from its arming. */\nexport interface Band {\n /** This time is the duration less how early the timer can fire. */\n readonly low: Extent;\n /** This time is the duration plus how late the timer can fire. */\n readonly high: Extent;\n}\n\n/** This function gives an amount as an exact value in seconds. Without an amount, it gives zero. */\nconst secondsOf = (extent: Extent | Unknown | undefined): Value => {\n if (extent === undefined) return exact(r.ZERO);\n if (\"unknown\" in extent) return unknown(extent.unknown);\n if (isUnbounded(extent)) return INFINITE;\n return exact(convertExact(r.fromNumber(extent.value), extent.unit, \"s\"));\n};\n\n/**\n * This function gives the band of a timer from its bounds, exactly, in `unit`. The band goes from\n * its duration less its early bound to its duration plus its lateness. A bound that the document\n * does not give is zero. A duration without an end gives a band without an end. A keepalive of 11 s, 4 ms early and 352 ms\n * late, gives 10.996 s to 11.352 s.\n */\nexport const timerBand = (bounds: TimerBounds, unit = \"s\"): Band | Unknown => {\n const duration = secondsOf(bounds.duration);\n const early = secondsOf(bounds.early);\n const late = secondsOf(bounds.lateness);\n const lost = unknownOf([duration, early, late]);\n if (lost !== undefined) return out(lost, unit) as Unknown;\n if (duration.kind !== \"exact\") return { low: unbounded(unit), high: unbounded(unit) };\n if (early.kind !== \"exact\") return { unknown: \"an early bound without an end\", unit };\n const low = r.sub(duration.n, early.n);\n const at = (n: Rational): Quantity => quantity(r.toNumber(convertExact(n, \"s\", unit)), unit);\n return { low: at(low), high: late.kind === \"exact\" ? at(r.add(duration.n, late.n)) : unbounded(unit) };\n};\n\n/** A scheduled firing is one firing of a backoff timer, and its time on the timeline. */\nexport interface Scheduled {\n /** This count is the wait that ends in this firing: the wait after `fired` firings. */\n readonly fired: number;\n /** This time is the sum of the waits to this firing, from the first wait of the schedule, in seconds. */\n readonly at: Quantity;\n}\n\n/** These options tell where the firings of a schedule start and stop. Each stop that they give applies. */\nexport interface ScheduleOptions {\n /** This count is the first wait of the schedule. The default is 0, the wait from the arming. */\n readonly from?: number | undefined;\n /** This count is the most firings to give. */\n readonly count?: number | undefined;\n /** This time stops the schedule: the schedule keeps no firing after it. */\n readonly until?: Extent | undefined;\n /** This time stops the schedule after the first firing at it or after it. That firing is in the schedule. */\n readonly reach?: Extent | undefined;\n}\n\n/**\n * This function gives the firings of a backoff timer on a timeline: the sum of its waits, exactly,\n * from the wait `from`. It stops at the first wait that is not a known amount, or at a stop of the\n * options, or after 4096 firings. Each time is the duration of the waits, without how early or\n * late each can fire.\n *\n * Two examples: the retransmission timer of Linux gives the send of each retransmission. The\n * retry of a call with a deadline gives the start of each try.\n */\nexport const firings = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n options: ScheduleOptions,\n): Scheduled[] => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n if (def.backoff === undefined) throw new Error(`${doc.title}'s ${timer} has no backoff`);\n if (options.count === undefined && options.until === undefined && options.reach === undefined) {\n throw new Error(`the firings of ${timer} need a stop: a count, until or reach`);\n }\n const limit = (extent: Extent | undefined): Value | undefined => (extent === undefined ? undefined : secondsOf(extent));\n const until = limit(options.until);\n const reach = limit(options.reach);\n const from = options.from ?? 0;\n const count = Math.min(options.count ?? FIRINGS, FIRINGS);\n const result: Scheduled[] = [];\n let at = r.ZERO;\n for (let fired = from; result.length < count; fired += 1) {\n const wait = secondsOf(timerOf(doc, timer, values, fired).duration);\n if (wait.kind !== \"exact\") break;\n at = r.add(at, wait.n);\n if (until?.kind === \"exact\" && r.cmp(at, until.n) > 0) break;\n result.push({ fired, at: quantity(r.toNumber(at), \"s\") });\n if (reach?.kind === \"exact\" && r.cmp(at, reach.n) >= 0) break;\n }\n return result;\n};\n\n/**\n * This function gives the times of a train of probes, exactly, in seconds. The first probe is at\n * `first`, and each next probe is one `interval` later, `count` probes in all. A first time without\n * an end gives no probe. An interval without an end gives only the first probe. Keepalive at its\n * defaults sends its probes at 7200 s, 7275 s, and so on to 7800 s.\n */\nexport const probeTrain = (first: Extent, interval: Extent, count: number): Quantity[] => {\n const start = secondsOf(first);\n const step = secondsOf(interval);\n if (start.kind !== \"exact\" || count < 1) return [];\n const times = [quantity(r.toNumber(start.n), \"s\")];\n if (step.kind !== \"exact\") return times;\n for (let k = 1; k < count; k += 1) times.push(quantity(r.toNumber(r.add(start.n, r.mul(step.n, whole(BigInt(k))))), \"s\"));\n return times;\n};\n\n/**\n * This function gives how long a mechanism takes where a machine operates, from the realization\n * of its document. The realization is one of its timers, whole, or its own duration, lateness and\n * early bound over the knobs of the machine. It gives undefined when the document does not realize the mechanism.\n */\nexport const realizationOf = (\n doc: Machine,\n mechanism: string,\n values: KnobValues,\n): TimerBounds | undefined => {\n const how = doc.realizes?.[mechanism];\n if (how === undefined) return undefined;\n if (\"timer\" in how) return timerOf(doc, how.timer, values);\n return {\n duration: evaluate(doc, how.duration, values),\n ...(how.lateness !== undefined ? { lateness: evaluate(doc, how.lateness, values) } : {}),\n ...(how.early !== undefined ? { early: evaluate(doc, how.early, values) } : {}),\n };\n};\n\n/** This function gives the knobs that a realization reads, by the names of the machine for them. */\nexport const realizationKnobs = (doc: Machine, mechanism: string): string[] => {\n const how = doc.realizes?.[mechanism];\n if (how === undefined) return [];\n const def = \"timer\" in how ? doc.timers[how.timer] : how;\n if (def === undefined) return [];\n return [\n ...new Set(\n [def.duration, def.lateness, def.early].flatMap((e) => (e === undefined ? [] : exprKnobs(e))),\n ),\n ];\n};\n\n/** This function gives what in a document the algebra cannot read: arithmetic that does not parse, or a model that it does not have. */\nexport const algebraProblems = (doc: Machine): string[] => {\n const problems: string[] = [];\n const read = (where: string, exprs: ReadonlyArray<Expr | undefined>) => {\n for (const expr of exprs) {\n if (expr === undefined) continue;\n if (\"expr\" in expr) {\n try {\n parseExpr(expr.expr);\n } catch (error) {\n problems.push(`${where}: ${(error as Error).message}`);\n }\n }\n if (\"model\" in expr && modelOf(expr.model) === undefined)\n problems.push(`${where}: no model ${expr.model}`);\n }\n };\n for (const [id, def] of Object.entries(doc.timers)) {\n read(`timer ${id}`, [def.duration, def.lateness, def.early]);\n }\n for (const [mechanism, how] of Object.entries(doc.realizes ?? {})) {\n if (!(\"timer\" in how)) read(`realizes ${mechanism}`, [how.duration, how.lateness, how.early]);\n }\n for (const [lower, set] of Object.entries(doc.over?.sets ?? {}))\n read(`over sets ${lower}`, [set]);\n return problems;\n};\n\n/** This function gives the source of the formula of a named model, for a reader of a result. */\nexport const modelSource = (name: string): string | undefined => modelOf(name)?.source;\n\n// ---------------------------------------------------------------------------------------------\n// detection: the minimum over the detectors that are live in what the connection was doing\n// ---------------------------------------------------------------------------------------------\n\n/**\n * A manifestation is what a failure lets back to the machine: the incoming events that continue\n * to arrive while it lasts. A black hole lets nothing back. The kernel of a frozen process\n * continues to acknowledge what it gets and to answer keepalive probes, thus its ACKs continue to\n * arrive.\n */\nexport interface Manifestation {\n readonly name: string;\n readonly passes: readonly string[];\n /**\n * These are the events that the failure itself sends one time, for example the FIN of a process\n * that stopped with SIGKILL. A delivered event that a transition takes from the state of the connection detects the\n * failure at once.\n */\n readonly delivers?: readonly string[] | undefined;\n /**\n * This errno replaces ETIMEDOUT when one of these timers gives up. Linux keeps an ICMP error on\n * an established socket as a soft error, and the timeout reports it (`tcp_write_err`). An ICMP\n * counts only when it quotes a segment in the window (`tcp_v4_err`). A retransmission is in the\n * window. A keepalive probe uses the sequence number before `snd_una`, thus its ICMP does not count.\n */\n readonly errno?: { readonly errno: string; readonly timers: readonly string[] } | undefined;\n /**\n * These are the durations that the failure changes, by timer. For example, an ICMP host\n * unreachable for each retransmission reverts the backoff of the retransmission timer.\n */\n readonly replaces?:\n | Readonly<\n Record<string, { readonly duration?: Expr; readonly lateness?: Expr; readonly early?: Expr }>\n >\n | undefined;\n}\n\n/** A situation is the activity of the connection when the failure started. */\nexport interface Situation {\n /** This name is the state of the machine, for example ESTABLISHED. */\n readonly state: string;\n /** This flag tells if it had sent data that the peer had not acknowledged. */\n readonly inFlight: boolean;\n}\n\n/** A detector is a timer that can still fire, how long it operates, and the event that it fires. */\nexport interface Detector {\n readonly timer: string;\n readonly fires: string;\n readonly duration: Extent | Unknown;\n /** This identifier is the machine below whose timer it is, when the timer is not of the machine itself (`over`). */\n readonly beneath?: string | undefined;\n}\n\n/** A detection is the result of the minimum over the live detectors. */\nexport interface Detection {\n /** These are the timers that can still fire, the soonest first. */\n readonly detectors: readonly Detector[];\n /** This detector is the first to fire, or null when none can fire in a known time: a silent failure. */\n readonly first: Detector | null;\n /** These are the live detectors whose time nothing gives. Then `first` is only an upper bound. */\n readonly unsettled: readonly string[];\n /** These are the timers that are armed but cannot fire, and the reason for each. */\n readonly held: ReadonlyArray<{ readonly timer: string; readonly why: string }>;\n /**\n * These are the events that the failure delivers and that a transition takes from the state:\n * each detects the failure at once, before any timer. The errno is the errno of the transition,\n * or null for an end of file.\n */\n readonly delivered: ReadonlyArray<{\n readonly event: string;\n readonly to: string;\n readonly errno: string | null;\n }>;\n}\n\nconst soonest = (a: Detector, b: Detector): number => {\n const rank = (d: Detector): number =>\n \"unknown\" in d.duration ? 2 : d.duration.value === \"infinite\" ? 1 : 0;\n if (rank(a) !== rank(b)) return rank(a) - rank(b);\n if (rank(a) !== 0) return a.timer.localeCompare(b.timer);\n const seconds = (d: Detector) => {\n const value = d.duration as Extent & { value: number };\n return r.toNumber(convertExact(r.fromNumber(value.value), value.unit, \"s\"));\n };\n return seconds(a) - seconds(b) || a.timer.localeCompare(b.timer);\n};\n\n/**\n * This function gives the detection: the minimum over the detectors that are live in the\n * situation. The entry to the state arms a timer, and so does what the failure causes: data in\n * flight without an acknowledgment gets a retransmission. An event that occurs cancels a timer.\n *\n * An event that arms the timer again, and that the failure continues to let through, stops it\n * before it fires. For example, the kernel of a frozen process answers each keepalive probe.\n * Without a live detector, the failure is silent at the level of this machine. Only something\n * above it, the timeout of an application or a heartbeat, can find it. The result is only as good\n * as the events that the document names.\n */\nexport const detection = (\n doc: Machine,\n situation: Situation,\n manifestation: Manifestation,\n values: KnobValues,\n): Detection => {\n const passes = new Set(manifestation.passes);\n const happened = new Set([`enter:${situation.state}`]);\n if (situation.inFlight && !passes.has(\"rx.ack\")) happened.add(\"tx.retransmit.first\");\n const occurs = (event: string): boolean => happened.has(event) || passes.has(event);\n const detectors: Detector[] = [];\n const held: Array<{ timer: string; why: string }> = [];\n for (const [timer, def] of Object.entries(doc.timers)) {\n // a backoff timer starts again when it fires: its firing is a new try of the machine, and\n // another timer gives up on it, as the retransmission give-up does\n if (def.backoff !== undefined) continue;\n if (!def.arms.some(occurs)) continue;\n const cancelled = (def.cancels ?? []).find(occurs);\n if (cancelled !== undefined) {\n held.push({ timer, why: `${cancelled} cancels it` });\n continue;\n }\n const rearmed = def.arms.find((event) => passes.has(event));\n if (rearmed !== undefined) {\n held.push({ timer, why: `${rearmed} keeps arriving and re-arms it` });\n continue;\n }\n const duration = manifestation.replaces?.[timer]?.duration ?? def.duration;\n detectors.push({ timer, fires: def.fires, duration: evaluate(doc, duration, values) });\n }\n detectors.sort(soonest);\n const [earliest] = detectors;\n const finite =\n earliest !== undefined &&\n !(\"unknown\" in earliest.duration) &&\n earliest.duration.value !== \"infinite\";\n const delivered = (manifestation.delivers ?? []).flatMap((event) => {\n const taken = transitionOn(doc, situation.state, event);\n return taken === undefined ? [] : [{ event, to: taken.to, errno: taken.errno ?? null }];\n });\n return {\n detectors,\n first: finite ? earliest : null,\n unsettled: detectors.filter((d) => \"unknown\" in d.duration).map((d) => d.timer),\n held,\n delivered,\n };\n};\n\n/**\n * This function gives the bounds of a timer of a machine under a failure: its own bounds, with each\n * duration that the manifestation replaces.\n */\nexport const timerUnder = (\n doc: Machine,\n timer: string,\n values: KnobValues,\n manifestation: Manifestation,\n fired?: number,\n): TimerBounds => {\n const def = doc.timers[timer];\n if (def === undefined) throw new Error(`${doc.title} has no timer ${timer}`);\n const replaced = manifestation.replaces?.[timer];\n const duration = replaced?.duration ?? def.duration;\n const lateness = replaced?.lateness ?? def.lateness;\n const early = replaced?.early ?? def.early;\n return {\n duration: evaluate(doc, duration, values, fired),\n ...(lateness !== undefined ? { lateness: evaluate(doc, lateness, values, fired) } : {}),\n ...(early !== undefined ? { early: evaluate(doc, early, values, fired) } : {}),\n };\n};\n\n/**\n * This function gives the errno of a detection by a timer: the errno of the transition that its\n * event takes from the state. A soft error of the manifestation replaces ETIMEDOUT, but only for\n * the timers whose segments its ICMP quotes in the window.\n */\nexport const errnoOf = (\n doc: Machine,\n state: string,\n detector: { readonly timer: string; readonly fires: string },\n manifestation: Manifestation,\n): string | null => {\n const errno = transitionOn(doc, state, detector.fires)?.errno ?? null;\n const soft = manifestation.errno;\n return errno === \"ETIMEDOUT\" && soft !== undefined && soft.timers.includes(detector.timer)\n ? soft.errno\n : errno;\n};\n\n// ---------------------------------------------------------------------------------------------\n// a machine on another machine: a driver on its kernel socket\n// ---------------------------------------------------------------------------------------------\n\n/** This function gives the transition that a machine takes from a state on an event, by its document. */\nexport const transitionOn = (\n doc: Machine,\n state: string,\n event: string,\n): TransitionDef | undefined =>\n doc.transitions.find((t) => fromStates(doc, t.from).includes(state) && arr(t.on).includes(event));\n\n/**\n * This function gives the values of a machine for the machine that it operates on. These are the\n * knobs that it sets, evaluated over its own knobs, and the other knobs of the lower machine. The\n * keepAlive of ioredis at 5000 ms is the keepidle of the kernel at 5 s.\n */\nexport const overValues =\n (upper: Machine, upperValues: KnobValues, lowerValues: KnobValues): KnobValues =>\n (name) => {\n const set = upper.over?.sets[name];\n return set === undefined ? lowerValues(name) : evaluate(upper, set, upperValues);\n };\n\n/**\n * This function gives the detection through the machine that a machine operates on. The detectors\n * of the lower machine are live in the state below the state of this machine. They use the knobs\n * that this machine sets.\n *\n * Each one reaches this machine as the event that the end of the lower\n * machine gives. They are beside the timers of this machine, and the first of all of them is the\n * first detection. A failure lets nothing new through to a machine above the socket, only the end\n * of the socket. Thus the timers of this machine see only what its state arms.\n */\nexport const stackedDetection = (\n upper: Machine,\n lower: Machine,\n situation: Situation,\n manifestation: Manifestation,\n upperValues: KnobValues,\n lowerValues: KnobValues,\n): Detection => {\n const over = upper.over;\n if (over === undefined) throw new Error(`${upper.title} runs on no other machine`);\n const sitsOn = over.states[situation.state];\n if (sitsOn === undefined) {\n throw new Error(`${upper.title}'s ${situation.state} sits on no state of ${lower.title}`);\n }\n const own = detection(upper, situation, { name: manifestation.name, passes: [] }, upperValues);\n const below = detection(\n lower,\n { ...situation, state: sitsOn },\n manifestation,\n overValues(upper, upperValues, lowerValues),\n );\n const detectors = [\n ...own.detectors,\n ...below.detectors.map((d) => ({ ...d, beneath: over.machine })),\n ].sort(soonest);\n const [earliest] = detectors;\n const finite =\n earliest !== undefined &&\n !(\"unknown\" in earliest.duration) &&\n earliest.duration.value !== \"infinite\";\n return {\n detectors,\n first: finite ? earliest : null,\n unsettled: detectors.filter((d) => \"unknown\" in d.duration).map((d) => d.timer),\n held: [...own.held, ...below.held.map((h) => ({ ...h, why: `${h.why}, beneath` }))],\n // what the failure delivers reaches the socket below: its end is the end of this machine\n delivered: below.delivered,\n };\n};\n"],"mappings":";;;;;;;AA+CA,MAAa,QAAQ;;AA+HrB,MAAM,aAAa,MAAsB;CACvC,IAAI,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI;CAC/B,IAAI,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,KAAK;CACpC,IAAI,UAAU,GACZ,QAAQ,EAAE,KAAK,MAAM,0BAA0B,KAAK,CAAC,EAAA,CAAG,QACrD,SAAS,CAAC;EAAC;EAAO;EAAO;EAAS;EAAQ;CAAK,CAAC,CAAC,SAAS,IAAI,CACjE;CAEF,OAAO,CAAC;AACV;;AAGA,MAAa,aAAa,MAAsB,UAAU,CAAC,CAAC,CAAC,QAAQ,SAAS,SAAS,KAAK;;AAG5F,MAAa,cAAc,MAAqB,UAAU,CAAC,CAAC,CAAC,SAAS,KAAK;;;;;;AAO3E,MAAa,mBAAmB,MAAyB;CACvD,MAAM,WAAqB,CAAC;CAC5B,MAAM,SAAS,IAAI,IAAI,OAAO,KAAK,EAAE,MAAM,CAAC;CAC5C,IAAI,CAAC,OAAO,OAAO,EAAE,MAAM,CAAC,CAAC,MAA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AAQ,EAAE,CACjE,CAAC,CAAC,KAAK,OAAO;CACd,MAAM,CAAC,YAAY;CAKnB,OAAO;EACL;EACA,OALA,aAAa,KAAA,KACb,EAAE,aAAa,SAAS,aACxB,SAAS,SAAS,UAAU,aAGZ,WAAW;EAC3B,WAAW,UAAU,QAAQ,MAAM,aAAa,EAAE,QAAQ,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK;EAC9E,MAAM,CAAC,GAAG,IAAI,MAAM,GAAG,MAAM,KAAK,KAAK,OAAO;GAAE,GAAG;GAAG,KAAK,GAAG,EAAE,IAAI;EAAW,EAAE,CAAC;EAElF,WAAW,MAAM;CACnB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/algebra",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.3",
|
|
5
5
|
"description": "State machines as data, and the timer algebra over them: closed forms for a machine's timers in exact rationals, detection as the first live timer, recovery after a stall, and the replay of a trace.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"state-machine",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./build/index.d.ts",
|
|
34
34
|
"default": "./build/index.js"
|
|
35
35
|
},
|
|
36
|
+
"./clock": {
|
|
37
|
+
"types": "./build/clock.d.ts",
|
|
38
|
+
"default": "./build/clock.js"
|
|
39
|
+
},
|
|
36
40
|
"./replay": {
|
|
37
41
|
"types": "./build/replay.d.ts",
|
|
38
42
|
"default": "./build/replay.js"
|
|
@@ -63,7 +67,7 @@
|
|
|
63
67
|
}
|
|
64
68
|
},
|
|
65
69
|
"devDependencies": {
|
|
66
|
-
"@mark1russell7/cue": "github:mark1russell7/cue",
|
|
70
|
+
"@mark1russell7/cue": "github:mark1russell7/cue#da04dd56699a2ae806ab64da5b1d677476afe69e",
|
|
67
71
|
"@types/node": "^26.6.4",
|
|
68
72
|
"tsdown": "^0.23.1",
|
|
69
73
|
"typescript": "^7.0.2",
|