From 14aa85e638cfbaf14cb020b2bc32e0578a18b891 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Tue, 17 Nov 2026 15:45:49 -0800 Subject: [PATCH 1/2] fix(vessels): the layer turns on even when its feed fails Turning vessels on returned what the first live poll answered, so a failing feed (such as a missing AIS key) made enable() resolve false and the layer reported it could not be turned on. loadLivePositions again resolves with nothing once the poll is done; going back to live reads the poll's answer through its own path. --- src/data/aisLiveVessels.test.mjs | 30 ++++++++++++++++++++++++++++++ src/layers/vessels/ingestion.js | 19 +++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/data/aisLiveVessels.test.mjs b/src/data/aisLiveVessels.test.mjs index 1b091ec4f7..0f94b7b86f 100644 --- a/src/data/aisLiveVessels.test.mjs +++ b/src/data/aisLiveVessels.test.mjs @@ -1461,6 +1461,36 @@ test('enable owns one grace timer and disable/re-enable starts a new session', a } }); +test('the layer turns on and off when its feed fails', async () => { + const harness = installWireHarness(undefined, { enabled: false }); + const priorFetch = globalThis.fetch; + const priorWarn = console.warn; + const clock = makeFakeAisRuntime(); + _setAisRuntimeForTest(clock.runtime); + globalThis.fetch = async () => ({ + ok: false, + status: 503, + json: async () => ({ + status: 'missing-key', + error: 'AISSTREAM_API_KEY is not set', + }), + }); + console.warn = () => {}; + try { + // Turning it on succeeds; the failure is shown on the layer. + assert.notEqual(await aisLiveVesselsLayer.enable(harness.viewer), false); + const feed = _getVesselFeedStateForTest(); + assert.equal(feed.status, 'unavailable'); + assert.equal(feed.error, 'AISSTREAM_API_KEY not set'); + assert.notEqual(aisLiveVesselsLayer.disable(), false); + } finally { + globalThis.fetch = priorFetch; + console.warn = priorWarn; + harness.cleanup(); + _setAisRuntimeForTest(); + } +}); + test('vessel trail lifecycle: deselect clears the selected-vessel trail', () => { const harness = installWireHarness(undefined); try { diff --git a/src/layers/vessels/ingestion.js b/src/layers/vessels/ingestion.js index 79eb347675..ebc898d656 100644 --- a/src/layers/vessels/ingestion.js +++ b/src/layers/vessels/ingestion.js @@ -32,7 +32,22 @@ export function createIngestion({ // may still be set while it loads (see resumeLive). let liveLoad = null; - async function loadLivePositions(viewer, { handover = false } = {}) { + /** + * Poll the live vessels (or take the live poll already out). Resolves + * when it is done, with nothing: a feed that fails is shown on the layer, + * and turning the layer on still succeeds. + * @param {object} viewer + * @returns {Promise} + */ + async function loadLivePositions(viewer) { + await pollLive(viewer); + } + + /** + * The live poll: resolves what loadPositions answers (false when it could + * not be had), or that of the live poll already out. + */ + async function pollLive(viewer, { handover = false } = {}) { // Following the world clock, the layer shows the snapshots loadAt applies. if (followsClock()) return false; // Back at live, a snapshot at a time still loading no longer applies: @@ -63,7 +78,7 @@ export function createIngestion({ * @returns {Promise} */ async function resumeLive(viewer) { - const applied = await loadLivePositions(viewer || readViewer(), { + const applied = await pollLive(viewer || readViewer(), { handover: true, }); return applied === true; From ca0aec4d668e1fc6bd00362af14f183e5525d0d6 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Tue, 17 Nov 2026 15:46:06 -0800 Subject: [PATCH 2/2] Add the changelog entry for the vessel toggle fix --- changelog.d/1790-vessels-toggle-without-feed.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog.d/1790-vessels-toggle-without-feed.md diff --git a/changelog.d/1790-vessels-toggle-without-feed.md b/changelog.d/1790-vessels-toggle-without-feed.md new file mode 100644 index 0000000000..a92d08d73c --- /dev/null +++ b/changelog.d/1790-vessels-toggle-without-feed.md @@ -0,0 +1,3 @@ +- Let AIS vessels turn on and off again when their feed fails; the live + position load no longer passes the poll's answer to `enable()` + (samehkhamis, #1790).