| @@ -18,14 +18,14 @@ export function createAuthorityKernel<Output, Frame>(options: { sessionId: bigin |
| 18 | 18 | let lastNow: number | null = null, lastGatedAt: number | null = null, leaseUntilMs: number | null = null, target: PositionTarget | null = null, reference: string | null = null |
| 19 | 19 | let reason = 'startup', commandAccepted = false |
| 20 | 20 | const events: { atMs: number | null, from: AuthorityState, to: AuthorityState, reason: string, epoch: number }[] = [] |
| 21 | | - function transition(to: AuthorityState, why: string) { |
| 21 | + function transition(to: AuthorityState, why: string, eventAtMs: number | null = lastNow) { |
| 22 | 22 | reason = why |
| 23 | 23 | if (to === state) return |
| 24 | 24 | const from = state |
| 25 | 25 | state = to |
| 26 | 26 | epoch = Math.min(0xFFFFFFFF, epoch + 1) |
| 27 | 27 | leaseUntilMs = null; target = null |
| 28 | | - events.push({ atMs: lastNow, from, to, reason: why, epoch }) |
| 28 | + events.push({ atMs: eventAtMs, from, to, reason: why, epoch }) |
| 29 | 29 | if (events.length > 64) events.shift() |
| 30 | 30 | } |
| 31 | 31 | function fault(why: string) { if (state !== 'killed') transition('failsafe', why) } |
| @@ -54,9 +54,10 @@ export function createAuthorityKernel<Output, Frame>(options: { sessionId: bigin |
| 54 | 54 | update(o: AuthorityObservation, command?: AuthorityCommand) { |
| 55 | 55 | commandAccepted = false |
| 56 | 56 | const observedEpoch = epoch |
| 57 | + const validNow = Number.isFinite(o.nowMs) && o.nowMs >= 0 && (lastNow === null || o.nowMs >= lastNow) |
| 57 | 58 | |
| 58 | | - if (o.interlocks.killActive === true) transition('killed', 'kill-input') |
| 59 | | - if (!Number.isFinite(o.nowMs) || o.nowMs < 0 || (lastNow !== null && o.nowMs < lastNow)) { if (active(state)) fault('clock-discontinuity'); reason = state === 'killed' ? reason : 'clock-discontinuity'; return snapshot() } |
| 59 | + if (o.interlocks.killActive === true) transition('killed', 'kill-input', validNow ? o.nowMs : lastNow) |
| 60 | + if (!validNow) { if (active(state)) fault('clock-discontinuity'); reason = state === 'killed' ? reason : 'clock-discontinuity'; return snapshot() } |
| 60 | 61 | const gap = lastNow !== null && o.nowMs - lastNow > authorityPolicy.schedulerGapMs |
| 61 | 62 | lastNow = o.nowMs |
| 62 | 63 | if (active(state) && gap) fault('supervisor-schedule-gap') |