Commit 5f1f7ba
committed
fix: heartbeat v2.3 — immediate first beat + lead-clamp regime
Spec review round 4 (two confirmed findings, both fixed):
1. Any bounded first-beat delay can outlive a small tenant-capped lease
(a 30 s cap is still 28 s too late for a 2 s grant). The first extend
now fires IMMEDIATELY: it costs one extension but provably beats an
arbitrarily small lease, and its response primes the grant ledger
with a real grant sample. All Date-derived effective-TTL/hint
scheduling is removed from the heartbeat path (start_heartbeat drops
the hint parameter; reserve() no longer threads date_ms).
ApiResponse::date_ms + httpdate parsing remain as general response
utilities with unit and e2e tests.
2. Under a server-side maximum-LEAD clamp (extend re-stamps
expires_at ~ now + L), successive expires_at_ms differences measure
elapsed time, not lease — grant-derived cadence is self-referential
and collapses to the 500 ms floor, burning max_extensions in
seconds. Each success is now classified (is_lead_clamp_grant): a
grant that is non-positive, or < 0.9*requested while within
[0.75, 1.25]x elapsed-since-last-success (a clock reading, not a
lease), holds the cadence at min(requested/2, 30 s), never
tightened, with a tracing::warn once per heartbeat. The lower band
arm lets a real-but-small per-extend grant re-tighten after a skip
doubles the gap. The same held cadence paces retries before any
grant sample exists, so a failed immediate first beat can never
hot-loop at zero delay.
Everything else unchanged: skip rule (lead_min >= 1.5*last_grant),
requested-amount wire extends, same-key transient retry, permanent stop
set, 2xx-as-applied, intended-instant scheduling, cancellation.
Also folds in the uncommitted v2.2 grant-ledger baseline this refines
(rounds 2-3: Date rejected as a correctness input, grant ledger with
same-frame arithmetic, per-beat delays, TENANT_CLOSED/NOT_FOUND stops).
Tests: wiremock suite reworked — immediate-first-beat cadence
(extend@0/1000/2000, skip@3000, extend@4000), capped-grant discovery via
the immediate beat, 503-on-first-beat single held-cadence retry with
same idempotency key, lead-clamp echo responder holding cadence (no
floor collapse), zero-grant immediate prime holding cadence, per-extend
grant clamp (+ttl/4) still tightening to 500 ms, small-ttl liveness,
permanent stops, unknown-status 2xx as applied. Pure cadence/regime
functions unit-tested (held-cadence pins incl. 30 s cap, lead-clamp
band boundaries, skip threshold, trace). Obsolete effective-TTL/date-
hint tests removed; Date parsing tests kept; date_ms asserted e2e in
response_test.
CHANGELOG and AUDIT amended in place (same 0.3.1 release, PR #75).1 parent 2346011 commit 5f1f7ba
9 files changed
Lines changed: 556 additions & 336 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
58 | 73 | | |
59 | 74 | | |
60 | 75 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 172 | + | |
182 | 173 | | |
183 | 174 | | |
184 | 175 | | |
| |||
238 | 229 | | |
239 | 230 | | |
240 | 231 | | |
241 | | - | |
242 | 232 | | |
243 | 233 | | |
244 | 234 | | |
| |||
| 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 | | - | |
93 | | - | |
94 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
| |||
0 commit comments