Commit 504c48b
committed
feat: adopt remaining_ttl_ms (spec PR #148) for normative heartbeat scheduling
Spec review round 5 (user-approved) proved regime detection from
(grant, elapsed) samples undecidable in general: any real per-extend
grant in the sticky window [0.75*min(ttl/2, 30s), 0.9*ttl) tracks the
held cadence closely enough to stay classified lead-clamp while the
lease erodes to a lapse (ttl 24s, +10s grants -> held 12s -> ratio
10/12 inside the [0.75, 1.25] band forever, -2s per cycle). The
protocol gained a server-authoritative field; this adopts it.
Models: optional `remaining_ttl_ms` on ReservationCreateResponse and
ExtendResponse (int64 >= 0, remaining lifetime at response evaluation,
same clock snapshot as expires_at_ms; absent on dry-run/DENY and on
older servers).
Heartbeat (src/heartbeat.rs), NORMATIVE when present on a response:
- lead_floor = max(0, remaining_ttl_ms - rtt), rtt = monotonic
send->receive elapsed (unknown -> 0); max observed rtt tracked.
- retry_reserve = min(lead_floor/2, max(1s, 2*max_observed_rtt))
- next beat = lead_floor - retry_reserve after response receipt,
recomputed from EVERY field-carrying response; expiry-difference
accumulation is never used for scheduling in this mode.
- First beat: a field-carrying create derives the first delay from the
same formula instead of the immediate prime (no wasted primed
extension under max-lead clamping; a capped 1s lease first-beats at
~500ms, inside the lease).
- The lead_min skip check is BYPASSED while the latest successful
response carried the field (exact schedule; a heuristic skip could
overshoot the real lease); the grant ledger keeps running so the
heuristic resumes seamlessly if the field disappears.
- Transient failure: same-key retry after clamp(lead_estimate/4, 1s,
30s), lead_estimate = last lead_floor - elapsed since that response.
- Extend-by-requested-ttl, permanent stops, 2xx-as-applied unchanged.
Fallback (no field): v2.3 grant-ledger behavior unchanged in code;
docs amended in place to mark the [0.75, 1.25] band as best-effort for
per-extend-delta clamping legacy servers only, with remaining_ttl_ms
as the normative path.
Tests: five new wiremock scenarios (responders optionally emitting
remaining_ttl_ms, constant or first-n-only) - normative steady state
with skip bypass and no immediate prime; capped-create first beat
inside the lease; field-carrying max-lead clamp at ~cap - reserve with
no collapse; field disappearing mid-flight with the heuristic resuming
(and skipping) on the maintained ledger; normative same-key transient
retry. Pure-function pins: 60s remaining -> 59s delay, rtt widening,
lead-floor saturation, retry clamp bounds. Wire-format serde tests for
the optional field on both responses. All 11 legacy fallback tests
unchanged and green.
CHANGELOG and AUDIT amended in place (same 0.3.1 release, PR #75).1 parent 5f1f7ba commit 504c48b
8 files changed
Lines changed: 708 additions & 72 deletions
File tree
- src
- models
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
43 | 65 | | |
44 | 66 | | |
45 | 67 | | |
| |||
59 | 81 | | |
60 | 82 | | |
61 | 83 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
73 | 103 | | |
74 | 104 | | |
75 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
| |||
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
27 | | - | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
172 | 176 | | |
| 177 | + | |
173 | 178 | | |
174 | 179 | | |
175 | 180 | | |
| |||
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
| 237 | + | |
| 238 | + | |
232 | 239 | | |
233 | 240 | | |
234 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
| 105 | + | |
| 106 | + | |
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
| |||
0 commit comments