fix(satellites): forget ISS telemetry from dropped sockets

A new ISSLive connection must rebuild its own joint snapshot and station-clock
liveness. Without clearing the prior session, a fast reconnect can mark old
joint positions live before fresh angles arrive.

Add a node:test reconnect regression and update the runtime contract.
Follow-up to PR #1767 by ZloyS; original ISS model credit: IMBrandao (#1690).

Tests: node --test server/providers/space/issTelemetry.test.mjs (UNRUN)
This commit is contained in:
Kevin Rajan authored and Denis Groshev committed 2026-11-16 21:54:05 +01:00
1 parent f0d2906220
commit 79ab830824
4 files changed
+55 -1

No files matched your search

@@ -0,0 +1,4 @@
- Clear ISS joint samples and station-clock liveness when the opt-in
NASA telemetry socket drops. A reconnected feed must supply new joint data
rather than presenting the previous connection's angles as live
(follow-up to ZloyS's #1767 and IMBrandao's #1690).
+3 -1
View File
@@ -1953,7 +1953,9 @@ closes it after two minutes without one, retries on a 5 s to 5 min ladder and
recycles a socket that is silent for 30 s. The body is
`{ configured, status, generatedAt, items }`: `status` is `live` only while the
station clock ticked with signal in the last 20 s, and each item is
`[value, epoch ms it was true at]`. Unset, the route answers
`[value, epoch ms it was true at]`. On a socket loss the relay discards that
connection's joint samples and station-clock credit, so fresh signal after
reconnection cannot present old angles as live telemetry. Unset, the route answers
`{ configured: false }` without contacting the feed, and the browser asks once.
`issTelemetry.js` in the satellites layer polls it every 5 s while the model is
drawn and, in Automatic, replaces the computed targets with the feed's: each
+5
View File
@@ -179,6 +179,11 @@ export function createIssTelemetryRelay({ createSocket, now = Date.now }) {
const old = socket;
socket = null;
fields.clear();
// A replacement session must rebuild both its joint snapshot and signal
// credit; a new clock tick cannot make the old session's angles live.
values.clear();
signalAt = null;
signalClass = null;
try {
old?.terminate?.();
} catch {
@@ -219,6 +219,49 @@ test('a lost or silent connection is retried on a ladder, and stale events are i
assert.equal(third.terminated, true);
});
test('a reconnect cannot mark the previous socket\'s joint samples live', () => {
const { relay, sockets, clock } = relayAt(NOV_13);
relay.demand();
const first = sockets[0];
first.emit('open');
first.emit('message', 'CONOK,S1,50000,5000,*');
const stamp = stampOf(clock.ms);
first.emit(
'message',
`U,1,${index('S0000004')},${stamp}|17|24\r\n` +
`U,1,${index('TIME_000001')},${stamp}|1|24`,
);
assert.equal(relay.snapshot().status, 'live');
assert.deepEqual(relay.snapshot().items.S0000004, [17, clock.ms]);
first.emit('close');
assert.equal(relay.snapshot().status, 'reconnecting');
clock.ms += 5_000;
relay.demand();
assert.equal(sockets.length, 2);
assert.equal(relay.snapshot().status, 'connecting');
assert.deepEqual(relay.snapshot().items, {});
const second = sockets[1];
second.emit('open');
second.emit('message', 'CONOK,S2,50000,5000,*');
// The clock can return before any new joint snapshot is delivered.
second.emit(
'message',
`U,1,${index('TIME_000001')},${stampOf(clock.ms)}|1|24`,
);
assert.equal(relay.snapshot().status, 'live');
assert.deepEqual(
relay.snapshot().items,
{},
'the new clock must not revive old joint angles',
);
second.emit(
'message',
`U,1,${index('S0000004')},${stampOf(clock.ms)}|23|24`,
);
assert.deepEqual(relay.snapshot().items.S0000004, [23, clock.ms]);
});
test('a refused or ended session starts over', () => {
for (const line of ['CONERR,2,x', 'END,31,x', 'LOOP,0', 'REQERR,1,17,x']) {
const { relay, sockets } = relayAt(NOV_13);