Commit 7df3a08
committed
fix: align heartbeat to settled spec PR #148 HEARTBEAT GUIDANCE
Spec PR #148 settled at head dd60c27 with a hardened primary algorithm;
the yaml's HEARTBEAT GUIDANCE on extendReservation is the authority.
Rework of the interim round-5 implementation, both heartbeats
(lifecycle + streaming), version stays 0.4.1:
- SUCCESS PREDICATE: only a schema-valid HTTP 200
ReservationExtendResponse (status ACTIVE, integer expires_at_ms >= 0,
optional integer remaining_ttl_ms >= 0) is an observed success on the
primary path. Any other/malformed 2xx is AMBIGUOUS -> same-key
recovery, never scheduled from. Fieldless fallback keeps lenient
2xx-as-applied.
- SCHEDULING: per-attempt monotonic rtt (max tracked);
lead_floor = max(0, remaining_ttl_ms - rtt);
request_timeout_budget = enforced connectTimeout + readTimeout (the
client applies AbortSignal.timeout on every request);
attempt_budget = max(timeout, 1s, 2*maxRtt);
safety_margin = max(1s, 2*maxRtt);
next_delay = max(0, lead_floor - (2*attempt_budget + safety_margin))
from response receipt, recomputed from every schema-valid response.
Budgets/margins round up, leads/delays round down; saturating
arithmetic (unbounded timeout -> infinite budget -> next_delay 0).
- ZERO-DELAY GUARD: one immediate fresh attempt (new key) per
zero-delay success; two consecutive zeros stop + surface (lease
shorter than the retry-safety budget). Unreliable timing forces
lead_floor = 0 into the same guard; never a silent fallback
downgrade.
- RECOVERY: retry_window = current_lead - attempt_budget -
safety_margin, UNclamped; negative -> stop + surface; non-429 same-key
retry after min(30s, lead/4, window); 429 honors Retry-After
(delta-seconds * 1000, overflow-safe) exactly and only within the
window, else stop; repeated recovery recomputes from the same last
schema-valid response each failure; zero window -> one immediate
retry; progress guard stops zero-time loops; any other 4xx stops
without rotating the key. Permanent stops unchanged.
- CREATE: first beat from the create response's remaining_ttl_ms with
the create call's own measured rtt (no first-attempt-rtt widening —
replays recompute remaining_ttl_ms server-side).
- FALLBACK path (fieldless servers) unchanged.
Tests reworked to the settled formulas (T=7000 test config -> reserve
15000: 45000ms cadence at remaining 60000; 15000ms under a 30000 lead
cap) and extended: ambiguous-2xx same-key recovery; zero-delay guard
(1s lease -> one immediate fresh attempt -> stop + surfaced warning);
recovery loop 3750/2812/438/0 then stop when no retry+margin fits, all
same key; 429 honored at exactly 2000ms within window / stop at 8000ms
exceeding it; 4xx stop without key rotation; unbounded-timeout stop
(no silent fallback). All legacy fieldless tests pass unchanged.
456 tests pass; line coverage 97.65%, branch 91.96% (gates 95/85);
eslint, tsc, build clean. CHANGELOG/AUDIT/README aligned in place.1 parent 504c48b commit 7df3a08
5 files changed
Lines changed: 1092 additions & 237 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
64 | 82 | | |
65 | 83 | | |
66 | 84 | | |
| |||
81 | 99 | | |
82 | 100 | | |
83 | 101 | | |
84 | | - | |
| 102 | + | |
85 | 103 | | |
86 | 104 | | |
87 | 105 | | |
88 | 106 | | |
89 | 107 | | |
90 | 108 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
101 | 130 | | |
102 | | - | |
| 131 | + | |
103 | 132 | | |
104 | 133 | | |
105 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | | - | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
0 commit comments