From 79ab830824f23b5faf440278c15b13de57a0fef8 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Mon, 16 Nov 2026 14:32:58 -0600 Subject: [PATCH] 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) --- changelog.d/1767-iss-telemetry-reconnect.md | 4 ++ docs/CURRENT-STATE.md | 4 +- server/providers/space/issTelemetry.js | 5 +++ server/providers/space/issTelemetry.test.mjs | 43 ++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 changelog.d/1767-iss-telemetry-reconnect.md diff --git a/changelog.d/1767-iss-telemetry-reconnect.md b/changelog.d/1767-iss-telemetry-reconnect.md new file mode 100644 index 0000000000..8fe3f4ad86 --- /dev/null +++ b/changelog.d/1767-iss-telemetry-reconnect.md @@ -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). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 920c7e234a..a148a5fff6 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -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 diff --git a/server/providers/space/issTelemetry.js b/server/providers/space/issTelemetry.js index 9b83e325c1..564b5edaa9 100644 --- a/server/providers/space/issTelemetry.js +++ b/server/providers/space/issTelemetry.js @@ -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 { diff --git a/server/providers/space/issTelemetry.test.mjs b/server/providers/space/issTelemetry.test.mjs index 647d07fa5f..9abc275f5b 100644 --- a/server/providers/space/issTelemetry.test.mjs +++ b/server/providers/space/issTelemetry.test.mjs @@ -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);