Commit 900cfcd
authored
Measure position-reconciliation grace on the monotonic clock (#4366)
The continuous position-consistency check has a grace window: when the node
recently observed local activity on a position, check_position_discrepancy
suppresses a cache-vs-venue discrepancy for position_check_threshold_ns,
giving the local execution pipeline a moment to settle before synthesizing
an EXTERNAL reconciliation position.
That window is inherently a real-time duration — you want N real seconds of
cover. But it was measured on self.clock: last_activity was stamped from
self.clock (and before that carried from the venue event's ts_event), and
the threshold was compared against a self.clock delta. self.clock is not
guaranteed to advance at wall rate — a live node can be given a non-wall
clock through a clock factory (e.g. a simulated or replay venue driving the
node clock). When that clock runs fast or is anchored to a different epoch,
the delta is not real elapsed time and the threshold no longer means real
cover: an accelerated clock shrinks the window by its speed and the grace
can collapse before the first reconciliation poll.
Measure the grace on the monotonic dst::time clock instead: stamp
last_activity from dst::time::Instant and compare via elapsed() against the
threshold as a Duration. The window is now real elapsed time at any clock
speed or epoch. This also aligns the grace with the reconciliation loop
itself, which already schedules its polls on dst::time (LiveNode::run) — the
grace was the only part measuring durations on self.clock. The continuous
position check is a live-only feature and never runs under backtest, so a
monotonic grace clock has no effect on backtest determinism.
record_position_activity no longer takes a ts_event parameter and no longer
reads self.clock; position_local_activity now holds monotonic instants.
Add a regression test that records activity, races self.clock ~954 days
ahead in a single step, and asserts the grace still holds; it fails against
a self.clock-based grace and passes with the monotonic grace.
Coded by an LLM.1 parent fe7c00b commit 900cfcd
3 files changed
Lines changed: 110 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
274 | | - | |
| 275 | + | |
| 276 | + | |
275 | 277 | | |
276 | 278 | | |
277 | 279 | | |
| |||
305 | 307 | | |
306 | 308 | | |
307 | 309 | | |
308 | | - | |
| 310 | + | |
309 | 311 | | |
310 | 312 | | |
311 | 313 | | |
| |||
1439 | 1441 | | |
1440 | 1442 | | |
1441 | 1443 | | |
1442 | | - | |
1443 | | - | |
1444 | | - | |
1445 | | - | |
1446 | | - | |
1447 | | - | |
1448 | | - | |
1449 | | - | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
1450 | 1459 | | |
1451 | 1460 | | |
1452 | 1461 | | |
| |||
1498 | 1507 | | |
1499 | 1508 | | |
1500 | 1509 | | |
1501 | | - | |
1502 | | - | |
1503 | | - | |
1504 | | - | |
1505 | | - | |
| 1510 | + | |
1506 | 1511 | | |
1507 | 1512 | | |
1508 | 1513 | | |
| |||
1522 | 1527 | | |
1523 | 1528 | | |
1524 | 1529 | | |
1525 | | - | |
1526 | 1530 | | |
1527 | 1531 | | |
1528 | 1532 | | |
1529 | 1533 | | |
1530 | 1534 | | |
1531 | 1535 | | |
1532 | 1536 | | |
1533 | | - | |
1534 | 1537 | | |
1535 | 1538 | | |
1536 | 1539 | | |
| |||
1737 | 1740 | | |
1738 | 1741 | | |
1739 | 1742 | | |
1740 | | - | |
1741 | | - | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
1742 | 1747 | | |
1743 | 1748 | | |
1744 | 1749 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1166 | 1166 | | |
1167 | 1167 | | |
1168 | 1168 | | |
1169 | | - | |
1170 | 1169 | | |
1171 | 1170 | | |
1172 | 1171 | | |
| |||
1406 | 1405 | | |
1407 | 1406 | | |
1408 | 1407 | | |
1409 | | - | |
1410 | | - | |
1411 | | - | |
1412 | | - | |
1413 | | - | |
| 1408 | + | |
| 1409 | + | |
1414 | 1410 | | |
1415 | 1411 | | |
1416 | 1412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8110 | 8110 | | |
8111 | 8111 | | |
8112 | 8112 | | |
8113 | | - | |
| 8113 | + | |
| 8114 | + | |
8114 | 8115 | | |
8115 | | - | |
| 8116 | + | |
8116 | 8117 | | |
8117 | 8118 | | |
8118 | 8119 | | |
| |||
8134 | 8135 | | |
8135 | 8136 | | |
8136 | 8137 | | |
| 8138 | + | |
| 8139 | + | |
| 8140 | + | |
| 8141 | + | |
| 8142 | + | |
| 8143 | + | |
| 8144 | + | |
| 8145 | + | |
| 8146 | + | |
| 8147 | + | |
| 8148 | + | |
| 8149 | + | |
| 8150 | + | |
| 8151 | + | |
| 8152 | + | |
| 8153 | + | |
| 8154 | + | |
| 8155 | + | |
| 8156 | + | |
| 8157 | + | |
| 8158 | + | |
| 8159 | + | |
| 8160 | + | |
| 8161 | + | |
| 8162 | + | |
| 8163 | + | |
| 8164 | + | |
| 8165 | + | |
| 8166 | + | |
| 8167 | + | |
| 8168 | + | |
| 8169 | + | |
| 8170 | + | |
| 8171 | + | |
| 8172 | + | |
| 8173 | + | |
| 8174 | + | |
| 8175 | + | |
| 8176 | + | |
| 8177 | + | |
| 8178 | + | |
| 8179 | + | |
| 8180 | + | |
| 8181 | + | |
| 8182 | + | |
| 8183 | + | |
| 8184 | + | |
| 8185 | + | |
| 8186 | + | |
| 8187 | + | |
| 8188 | + | |
| 8189 | + | |
| 8190 | + | |
| 8191 | + | |
| 8192 | + | |
| 8193 | + | |
| 8194 | + | |
| 8195 | + | |
| 8196 | + | |
| 8197 | + | |
| 8198 | + | |
| 8199 | + | |
| 8200 | + | |
| 8201 | + | |
| 8202 | + | |
| 8203 | + | |
| 8204 | + | |
| 8205 | + | |
| 8206 | + | |
| 8207 | + | |
| 8208 | + | |
| 8209 | + | |
| 8210 | + | |
| 8211 | + | |
| 8212 | + | |
| 8213 | + | |
| 8214 | + | |
| 8215 | + | |
| 8216 | + | |
| 8217 | + | |
8137 | 8218 | | |
8138 | 8219 | | |
8139 | 8220 | | |
| |||
0 commit comments