fix(perception): require joint clock readiness before source activation

This commit is contained in:
DCCONSTRUCTIONS
2026-09-02 21:03:33 +03:00
parent 93ae1edbb4
commit 48835a0499
11 changed files with 558 additions and 112 deletions
+31
View File
@@ -18,6 +18,37 @@ from k1link.perception.streaming_queue import StreamMailbox
from k1link.perception.streaming_source_clock import SourceAnchor, SourceClockMonitor
def test_responder_warms_without_source_admission_and_rejects_wide_start():
monitor = SourceClockMonitor("worker", 10**12)
wide = sample(outbound=20_000_000, inbound=20_000_000)
now = wide.local_receive_ns + 10**12 + 1_000_000
anchor = SourceAnchor(10**12, wide.local_receive_ns + 1_000_000_000)
response = monitor.observe(wide, now, anchor, False)
assert response.anchor is monitor.anchor is None and response.bounds.samples == 1
with pytest.raises(StreamSuspended):
monitor.observed(now)
narrow = sample(2)
now = narrow.local_receive_ns + 10**12 + 1_000_000
response = monitor.observe(narrow, now, None, False)
assert response.anchor is None and response.bounds.samples == 2
response.bounds.require(now)
with pytest.raises(StreamSuspended):
monitor.observed(now) # Valid clock is not permission to start without an anchor.
third = sample(3)
now = third.local_receive_ns + 10**12 + 1_000_000
assert monitor.observe(third, now, anchor, False).anchor == anchor
assert monitor.observed(now)[1] < 5_000_000
def test_end_before_start_is_terminal_without_inventing_a_source_timeline():
monitor = SourceClockMonitor("worker", 10**12)
first = sample()
state = monitor.observe(first, first.local_receive_ns + 10**12 + 1_000_000, None, True)
assert state.ended and state.anchor is None
with pytest.raises(StreamSuspended):
monitor.observed(state.bounds.measured_at_ns)
def sample(number=1, outbound=1_000_000, inbound=2_000_000, offset=10**12):
t1 = 10**16 + number * 100_000_000
return ClockProbe(