From 3b3bf29f9bab49f009f7578532e4d9e534f31c85 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:38:31 -0500 Subject: [PATCH 01/16] perf: cancel superseded imagery thumbnail refinement --- src/layers/recentImagery/thumbnails.js | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/layers/recentImagery/thumbnails.js b/src/layers/recentImagery/thumbnails.js index 47c383f139..cd4c8fed7e 100644 --- a/src/layers/recentImagery/thumbnails.js +++ b/src/layers/recentImagery/thumbnails.js @@ -35,6 +35,8 @@ export function createThumbnailLoader({ const queue = []; let inFlight = 0; let touchCounter = 0; + let supersededQueued = 0; + let supersededInFlight = 0; let destroyed = false; function notify(key) { @@ -212,9 +214,39 @@ export function createThumbnailLoader({ candidates.length, extra, ); + const keys = []; order.forEach((index, priority) => { - this.request(candidates[index], box, priority); + const candidate = candidates[index]; + if (!candidate?.key) return; + keys.push(candidate.key); + this.request(candidate, box, priority); }); + return keys; + }, + + /** + * Keep only refinement work still wanted by the current UI intent. + * + * Known decoded/probed entries may remain warm under the LRU residency + * policy, but queued or in-flight acquisition for no-longer-wanted keys is + * cancelled. A cancelled known-present re-fetch keeps its proven metadata. + * @param {Iterable} keys + */ + retain(keys) { + const wanted = new Set(keys || []); + for (let index = queue.length - 1; index >= 0; index -= 1) { + const entry = queue[index]; + if (wanted.has(entry.key)) continue; + queue.splice(index, 1); + supersededQueued += 1; + if (entry.status === 'unknown') entries.delete(entry.key); + } + for (const entry of [...entries.values()]) { + if (!entry.loading || wanted.has(entry.key)) continue; + entry.controller?.abort(); + supersededInFlight += 1; + if (entry.status === 'unknown') entries.delete(entry.key); + } }, /** @@ -259,6 +291,13 @@ export function createThumbnailLoader({ return () => listeners.delete(listener); }, + refinementStats() { + return { + supersededQueued, + supersededInFlight, + }; + }, + stats() { return { inFlight, From 60bf311f90c6de6ee5d8841ecb8c377fca806606 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:38:36 -0500 Subject: [PATCH 02/16] perf: retain only current imagery thumbnail intent --- src/layers/recentImagery/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index 23b12f44c1..8187872c21 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -568,12 +568,14 @@ export function createRecentImageryLayer({ const list = stripList(); if (!list.length) return; reconcileFocus(); - thumbnails.requestOrdered(list, _box, { - focusIndex: Math.max(0, focusIndexIn(list)), - firstVisible: _visible.first, - lastVisible: _visible.last, - extra: 2, - }); + const wanted = new Set( + thumbnails.requestOrdered(list, _box, { + focusIndex: Math.max(0, focusIndexIn(list)), + firstVisible: _visible.first, + lastVisible: _visible.last, + extra: 2, + }) || [], + ); for (const key of new Set([ _assigned.a, _assigned.b, @@ -581,8 +583,11 @@ export function createRecentImageryLayer({ _followKey, ])) { const candidate = candidateFor(key); - if (sourceOn(candidate)) thumbnails.request(candidate, _box, 0); + if (!sourceOn(candidate)) continue; + thumbnails.request(candidate, _box, 0); + wanted.add(candidate.key); } + thumbnails.retain?.(wanted); } function resetCatalog() { From ee8848e81f09fed30d7e89de9a618d88ea4d9099 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:38:39 -0500 Subject: [PATCH 03/16] test: track retained imagery thumbnail intent --- src/layers/recentImagery/testDoubles.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/layers/recentImagery/testDoubles.mjs b/src/layers/recentImagery/testDoubles.mjs index 2b00e5b019..e6932a166a 100644 --- a/src/layers/recentImagery/testDoubles.mjs +++ b/src/layers/recentImagery/testDoubles.mjs @@ -275,6 +275,7 @@ export function fakeThumbnails() { const requested = []; /** Direct `request` calls: `[key, priority]`. */ const requests = []; + const retained = []; const ask = (key) => { if (!requested.includes(key)) requested.push(key); }; @@ -282,6 +283,7 @@ export function fakeThumbnails() { calls, requested, requests, + retained, requestOrdered(candidates, box, window) { calls.push(['ordered', candidates.map((c) => c.key), window]); const { focusIndex, firstVisible, lastVisible, extra } = window; @@ -291,12 +293,18 @@ export function fakeThumbnails() { lastVisible, candidates.length, extra, - ).forEach((index) => ask(candidates[index].key)); + ); + const keys = order.map((index) => candidates[index].key); + keys.forEach(ask); + return keys; }, request(candidate, box, priority) { ask(candidate.key); requests.push([candidate.key, priority]); }, + retain(keys) { + retained.push([...keys]); + }, /** Settle every requested key still unknown, as the loader would. */ probeRequested(status = 'present') { for (const key of requested) From c3fd6eaf24a302628baca6d571cbd1c3f8683960 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:38:43 -0500 Subject: [PATCH 04/16] test: cover stale thumbnail cancellation --- src/layers/recentImagery/thumbnails.test.mjs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/layers/recentImagery/thumbnails.test.mjs b/src/layers/recentImagery/thumbnails.test.mjs index 891b2e8dd2..f88b05c5f7 100644 --- a/src/layers/recentImagery/thumbnails.test.mjs +++ b/src/layers/recentImagery/thumbnails.test.mjs @@ -315,3 +315,27 @@ test('a request queued behind an aborted fetch still starts once the abort settl tracked: 1, }); }); + + +test('retain aborts stale acquisition while allowing the current intent to start', async () => { + const { loader, fetch } = fixture({ maxInFlight: 1 }); + const stale = candidate('S30', '2026-09-10'); + const current = candidate('S30', '2026-09-11'); + + loader.request(stale, BOX, 0); + loader.request(current, BOX, 1); + assert.equal(fetch.calls.length, 1); + assert.match(fetch.calls[0].url, /TIME=2026-09-10/); + + loader.retain([current.key]); + assert.equal(fetch.calls[0].signal.aborted, true); + await settle(); + + assert.equal(fetch.calls.length, 2, 'current intent starts after stale abort'); + assert.match(fetch.calls[1].url, /TIME=2026-09-11/); + assert.deepEqual(loader.refinementStats(), { + supersededQueued: 0, + supersededInFlight: 1, + }); + assert.equal(loader.get(stale.key).status, 'unknown'); +}); From ab0754623e51c5134ff277ae46361f7e86adeeac Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:38:46 -0500 Subject: [PATCH 05/16] test: prove imagery layer retains current thumbnail intent --- src/layers/recentImagery/index.test.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/layers/recentImagery/index.test.mjs b/src/layers/recentImagery/index.test.mjs index 7675d0f3a9..ce90f7ad57 100644 --- a/src/layers/recentImagery/index.test.mjs +++ b/src/layers/recentImagery/index.test.mjs @@ -1061,6 +1061,10 @@ test('alpha, split and visible range notify without re-rendering the row', async f.layer.setSplit(0.25); f.layer.setVisibleRange(1, 3); assert.equal(f.thumbnails.calls.at(-1)[2].firstVisible, 1); + assert.ok( + f.thumbnails.retained.at(-1).includes(f.snap().focus.key), + 'the current focus remains in the retained refinement intent', + ); assert.equal(rowRenders, rows); assert.deepEqual(f.reasons.slice(-2), ['alpha', 'split']); f.layer.setAlpha('bad'); From 61d65aa2d872d15fdcea37ff83ea8c808daf973f Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:38:49 -0500 Subject: [PATCH 06/16] docs: record stale imagery thumbnail cancellation --- docs/CURRENT-STATE.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 22ce1eb3b2..4808b64197 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1,3 +1,12 @@ +## Generation-style stale thumbnail cancellation — September 29, 2026 + +Recent Imagery thumbnail acquisition now retains only the current refinement +intent. When focus, visible strip range, pins or preview intent changes, queued +thumbnail work for no-longer-wanted days is removed and in-flight acquisition is +aborted. Already-probed/decoded entries may remain warm under the existing LRU +residency policy, and cancelling a re-fetch never forgets proven availability or +acquisition metadata. Diagnostics count superseded queued and in-flight work. + # God's Eye View Current State ## Cyber HUD — September 23, 2026 From 5e28b5a72c3ba4b42271aff29e09ae606aa405f0 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:38:54 -0500 Subject: [PATCH 07/16] docs: note stale imagery thumbnail cancellation --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58103d04da..1ffa66d1db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +- Cancel Recent Imagery thumbnail acquisition that no longer belongs to the current focus/visible/pin/preview intent. Stale queued work is removed and stale in-flight fetches are aborted while known-good decoded/probed entries may remain warm under the existing cache policy; cancellation counters are exposed for diagnostics. + - Public Overpass instances are no longer used by default. Street Traffic roads come from TomTom flow tiles, OpenFreeMap vector tiles, or both, chosen on the layer row (TomTom / OSM / Hybrid) or with `?trafficRoads=`. With a From 455d36fe9233cfbfe2fff527689b6fe9f389a12b Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:39:27 -0500 Subject: [PATCH 08/16] test: fix retained thumbnail order fake --- src/layers/recentImagery/testDoubles.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layers/recentImagery/testDoubles.mjs b/src/layers/recentImagery/testDoubles.mjs index e6932a166a..d96acada0e 100644 --- a/src/layers/recentImagery/testDoubles.mjs +++ b/src/layers/recentImagery/testDoubles.mjs @@ -287,7 +287,7 @@ export function fakeThumbnails() { requestOrdered(candidates, box, window) { calls.push(['ordered', candidates.map((c) => c.key), window]); const { focusIndex, firstVisible, lastVisible, extra } = window; - thumbnailOrder( + const order = thumbnailOrder( focusIndex, firstVisible, lastVisible, From 8b4952415e9396b13e5424244d3f6708d7fec883 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:39:31 -0500 Subject: [PATCH 09/16] test: format stale thumbnail cancellation proof --- src/layers/recentImagery/thumbnails.test.mjs | 46 +++++++++++--------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/layers/recentImagery/thumbnails.test.mjs b/src/layers/recentImagery/thumbnails.test.mjs index f88b05c5f7..d57d764726 100644 --- a/src/layers/recentImagery/thumbnails.test.mjs +++ b/src/layers/recentImagery/thumbnails.test.mjs @@ -316,26 +316,32 @@ test('a request queued behind an aborted fetch still starts once the abort settl }); }); +test( + 'retain aborts stale acquisition while allowing the current intent to start', + async () => { + const { loader, fetch } = fixture({ maxInFlight: 1 }); + const stale = candidate('S30', '2026-09-10'); + const current = candidate('S30', '2026-09-11'); -test('retain aborts stale acquisition while allowing the current intent to start', async () => { - const { loader, fetch } = fixture({ maxInFlight: 1 }); - const stale = candidate('S30', '2026-09-10'); - const current = candidate('S30', '2026-09-11'); + loader.request(stale, BOX, 0); + loader.request(current, BOX, 1); + assert.equal(fetch.calls.length, 1); + assert.match(fetch.calls[0].url, /TIME=2026-09-10/); - loader.request(stale, BOX, 0); - loader.request(current, BOX, 1); - assert.equal(fetch.calls.length, 1); - assert.match(fetch.calls[0].url, /TIME=2026-09-10/); + loader.retain([current.key]); + assert.equal(fetch.calls[0].signal.aborted, true); + await settle(); - loader.retain([current.key]); - assert.equal(fetch.calls[0].signal.aborted, true); - await settle(); - - assert.equal(fetch.calls.length, 2, 'current intent starts after stale abort'); - assert.match(fetch.calls[1].url, /TIME=2026-09-11/); - assert.deepEqual(loader.refinementStats(), { - supersededQueued: 0, - supersededInFlight: 1, - }); - assert.equal(loader.get(stale.key).status, 'unknown'); -}); + assert.equal( + fetch.calls.length, + 2, + 'current intent starts after stale abort', + ); + assert.match(fetch.calls[1].url, /TIME=2026-09-11/); + assert.deepEqual(loader.refinementStats(), { + supersededQueued: 0, + supersededInFlight: 1, + }); + assert.equal(loader.get(stale.key).status, 'unknown'); + }, +); From d38303fcd4af0938e2c48f784a8b0778b1cfcf8b Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 30 Sep 2026 20:51:50 -0500 Subject: [PATCH 10/16] chore: add one-shot branch formatter --- .github/workflows/tmp-format-fix.yml | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/tmp-format-fix.yml diff --git a/.github/workflows/tmp-format-fix.yml b/.github/workflows/tmp-format-fix.yml new file mode 100644 index 0000000000..40dce117ed --- /dev/null +++ b/.github/workflows/tmp-format-fix.yml @@ -0,0 +1,37 @@ +name: Temporary branch formatter + +on: + push: + branches: + - perf/imagery-stale-thumbnail-cancellation-20260929 + +permissions: + contents: write + +jobs: + format: + if: github.actor != 'github-actions[bot]' + runs-on: ubuntu-latest + env: + PUPPETEER_SKIP_DOWNLOAD: 1 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + ref: perf/imagery-stale-thumbnail-cancellation-20260929 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 + with: + node-version: 24.14.0 + cache: npm + - run: npm ci + - run: npm run format + - name: Commit formatting + shell: bash + run: | + if git diff --quiet; then + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add -u + git commit -m "style: apply adopted formatting" + git push origin HEAD:perf/imagery-stale-thumbnail-cancellation-20260929 From 0de14670ed3559198627354a7f3f84c69629a4df Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 1 Oct 2026 01:52:24 +0000 Subject: [PATCH 11/16] style: apply adopted formatting --- src/layers/recentImagery/thumbnails.test.mjs | 49 +++++++++----------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/layers/recentImagery/thumbnails.test.mjs b/src/layers/recentImagery/thumbnails.test.mjs index d57d764726..087430cf33 100644 --- a/src/layers/recentImagery/thumbnails.test.mjs +++ b/src/layers/recentImagery/thumbnails.test.mjs @@ -316,32 +316,29 @@ test('a request queued behind an aborted fetch still starts once the abort settl }); }); -test( - 'retain aborts stale acquisition while allowing the current intent to start', - async () => { - const { loader, fetch } = fixture({ maxInFlight: 1 }); - const stale = candidate('S30', '2026-09-10'); - const current = candidate('S30', '2026-09-11'); +test('retain aborts stale acquisition while allowing the current intent to start', async () => { + const { loader, fetch } = fixture({ maxInFlight: 1 }); + const stale = candidate('S30', '2026-09-10'); + const current = candidate('S30', '2026-09-11'); - loader.request(stale, BOX, 0); - loader.request(current, BOX, 1); - assert.equal(fetch.calls.length, 1); - assert.match(fetch.calls[0].url, /TIME=2026-09-10/); + loader.request(stale, BOX, 0); + loader.request(current, BOX, 1); + assert.equal(fetch.calls.length, 1); + assert.match(fetch.calls[0].url, /TIME=2026-09-10/); - loader.retain([current.key]); - assert.equal(fetch.calls[0].signal.aborted, true); - await settle(); + loader.retain([current.key]); + assert.equal(fetch.calls[0].signal.aborted, true); + await settle(); - assert.equal( - fetch.calls.length, - 2, - 'current intent starts after stale abort', - ); - assert.match(fetch.calls[1].url, /TIME=2026-09-11/); - assert.deepEqual(loader.refinementStats(), { - supersededQueued: 0, - supersededInFlight: 1, - }); - assert.equal(loader.get(stale.key).status, 'unknown'); - }, -); + assert.equal( + fetch.calls.length, + 2, + 'current intent starts after stale abort', + ); + assert.match(fetch.calls[1].url, /TIME=2026-09-11/); + assert.deepEqual(loader.refinementStats(), { + supersededQueued: 0, + supersededInFlight: 1, + }); + assert.equal(loader.get(stale.key).status, 'unknown'); +}); From 683fbe32eff70aa93566e3e8c3da521636f8d4dc Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 30 Sep 2026 20:52:56 -0500 Subject: [PATCH 12/16] chore: remove one-shot branch formatter --- .github/workflows/tmp-format-fix.yml | 37 ---------------------------- 1 file changed, 37 deletions(-) delete mode 100644 .github/workflows/tmp-format-fix.yml diff --git a/.github/workflows/tmp-format-fix.yml b/.github/workflows/tmp-format-fix.yml deleted file mode 100644 index 40dce117ed..0000000000 --- a/.github/workflows/tmp-format-fix.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Temporary branch formatter - -on: - push: - branches: - - perf/imagery-stale-thumbnail-cancellation-20260929 - -permissions: - contents: write - -jobs: - format: - if: github.actor != 'github-actions[bot]' - runs-on: ubuntu-latest - env: - PUPPETEER_SKIP_DOWNLOAD: 1 - steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - with: - ref: perf/imagery-stale-thumbnail-cancellation-20260929 - - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 - with: - node-version: 24.14.0 - cache: npm - - run: npm ci - - run: npm run format - - name: Commit formatting - shell: bash - run: | - if git diff --quiet; then - exit 0 - fi - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -u - git commit -m "style: apply adopted formatting" - git push origin HEAD:perf/imagery-stale-thumbnail-cancellation-20260929 From 82f7355837e9dae5f72003224448427f05934ec4 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Thu, 1 Oct 2026 00:52:10 -0500 Subject: [PATCH 13/16] chore: add one-shot downstream format fixer --- .github/workflows/downstream-format-fix.yml | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/downstream-format-fix.yml diff --git a/.github/workflows/downstream-format-fix.yml b/.github/workflows/downstream-format-fix.yml new file mode 100644 index 0000000000..38b856350e --- /dev/null +++ b/.github/workflows/downstream-format-fix.yml @@ -0,0 +1,37 @@ +name: Downstream format fix + +on: + push: + branches: + - perf/imagery-stale-thumbnail-cancellation-20260929 + +permissions: + contents: write + +jobs: + format: + if: ${{ github.actor != 'github-actions[bot]' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + with: + ref: perf/imagery-stale-thumbnail-cancellation-20260929 + - uses: actions/setup-node@v5 + with: + node-version: 24.14.0 + cache: npm + - run: npm ci + env: + PUPPETEER_SKIP_DOWNLOAD: 1 + - run: npm run format + - name: Commit formatting if needed + shell: bash + run: | + if git diff --quiet; then + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m "chore: apply adopted formatting" + git push From 85227cca9dc0fa74055c5f4e9490fea932f86875 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Thu, 1 Oct 2026 00:52:52 -0500 Subject: [PATCH 14/16] chore: remove one-shot downstream format fixer --- .github/workflows/downstream-format-fix.yml | 37 --------------------- 1 file changed, 37 deletions(-) delete mode 100644 .github/workflows/downstream-format-fix.yml diff --git a/.github/workflows/downstream-format-fix.yml b/.github/workflows/downstream-format-fix.yml deleted file mode 100644 index 38b856350e..0000000000 --- a/.github/workflows/downstream-format-fix.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Downstream format fix - -on: - push: - branches: - - perf/imagery-stale-thumbnail-cancellation-20260929 - -permissions: - contents: write - -jobs: - format: - if: ${{ github.actor != 'github-actions[bot]' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - with: - ref: perf/imagery-stale-thumbnail-cancellation-20260929 - - uses: actions/setup-node@v5 - with: - node-version: 24.14.0 - cache: npm - - run: npm ci - env: - PUPPETEER_SKIP_DOWNLOAD: 1 - - run: npm run format - - name: Commit formatting if needed - shell: bash - run: | - if git diff --quiet; then - exit 0 - fi - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -A - git commit -m "chore: apply adopted formatting" - git push From a0db300d5473d812690aafda52b85bb9a0fa54d6 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Wed, 18 Nov 2026 16:39:56 +0400 Subject: [PATCH 15/16] docs(imagery): tighten cancellation notes and match them to the code --- changelog.d/881-imagery-cancellation.md | 6 +++++- docs/CURRENT-STATE.md | 2 +- src/layers/recentImagery/index.js | 3 +-- src/layers/recentImagery/thumbnails.js | 13 +++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/changelog.d/881-imagery-cancellation.md b/changelog.d/881-imagery-cancellation.md index 4c17c854f6..dd67a9ba48 100644 --- a/changelog.d/881-imagery-cancellation.md +++ b/changelog.d/881-imagery-cancellation.md @@ -1 +1,5 @@ -- Cancel superseded Recent Imagery thumbnail fetches when focus, visible range, pins or preview change; retain known-good availability metadata and count each aborted in-flight request once. When the followed automatic day resolves empty, re-request its successor even if scrolling previously cancelled that probe (kvnloo, #881; independent reviews: quanticsoul4772, gekh). +- Cancel Recent Imagery thumbnail fetches that are no longer wanted when focus, + the visible strip, pins or sources change; a day already known to have + imagery stays known. When the automatic day turns out empty, fetch the next + day again even if scrolling had cancelled it (kvnloo, #881; reviews: + quanticsoul4772, gekh). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 9f7bdf68c6..e03f5fd243 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8062,7 +8062,7 @@ pins and share links already supply complete boxes. - DATA ▸ **Recent Imagery** (`recent-imagery`, `src/layers/recentImagery/`) lists the last 30 UTC days of imagery for a selected box and drapes the days you pick: HLS S30 (Sentinel-2) and L30 (Landsat 8/9) at 30 m, and the VIIRS NOAA-21 daily overview at 250 m. Keyless and browser-direct: NASA CMR for which days have HLS granules in the box (`catalog.js`, both collections concurrently, paged with `CMR-Search-After` up to 2,000 records each, `truncated` against CMR `hits`), GIBS WMTS for tiles, Worldview Snapshots for thumbnails and exports. Worldview's `Data-Present` header is the only availability signal: GIBS answers an empty tile with HTTP 200, and the JPEG overview would drape black, so a day confirmed empty never drapes. - **Box.** SELECT BOX (`src/ui/imageryBoxTool.js`) claims the pointer like Draw, borrows the stock click actions and freezes the camera only mid-drag; USE VIEW takes the camera rectangle; `boxFromPinAt` grows a 10 km box. Boxes must be ≤ 1,000 km a side, on one side of the dateline and inside the Web-Mercator limit (`validateBox`). A refusal (`boxError`, including the tool's own via `reportBoxRefusal`) stays at the top of the panel until a box succeeds; a view over the cap is refused with its size, never shrunk. An oversized box or view (`Box is … km wide · limit 1,000 km`, `View is … wide · …`) sets the hint to `Zoom in or draw a smaller box` and enables ZOOM IN: `zoomToFit()` flies top-down (1.2 s) to the refused box's centre, or the ground under the canvas centre for a view, at the height whose view is about 400 km wide for the canvas aspect and the camera's vertical FOV (`fitViewHeightM`, clamped 5–400 km), and returns that height. - **Modes, pins and the preview.** The mode is explicit: `image` (one pinned day, slot `a`), `basemap` (that day on the left of a swipe, the basemap on the right: slot `a` splits LEFT and there is no second layer) and `ab` (day `a` left, day `b` right). `setAssignment(slot, key | null)` / `toggleAssignment(slot, key)` pin and unpin; a day is in one slot at most (pinning it in the other slot moves it) and an empty day cannot be pinned. `setMode()` keeps both pins; `b` only drapes in `ab`. While the mode's first empty slot exists the focused day previews in it: a click at once, arrow keys after 250 ms of quiet (`FOCUS_DEBOUNCE_MS`, one timer, last day wins); an unprobed day is followed and previews when its probe says present, an empty or unknown day never drapes and the previous preview stays. A pin change drops the preview until focus moves again, and unpinning takes that layer off at once. `rankLatest` picks START HERE coverage first (a present HLS day whose footprints cover the box, or have none, beats a newer sliver), then newest with all granules ≤ 20% known cloud, then newest; slivers only as `partial`; else the newest non-empty VIIRS day; it is focused and previewed after each search when nothing is pinned. Escape clears the preview (`clearPreview()`), then cancels the box tool, then blurs — with SELECT BOX armed too, through the tool's `onEscape` interceptor wired in `createApplicationTools`. Pins, mode, box and split changes made in the panel are published with `adoptLayerParams`, never while a share link is being applied. -- **Rendering.** `rendering.js` owns at most two GIBS layers on the host `src/maps/imageryHost.js` resolves: the globe port's imagery while the globe shows, the shown photoreal tileset while it is hidden, or none (the panel says so). Layers are rebuilt on a new host, never re-parented. `MapSourceController.subscribe()` fires after every settled stack switch (silent switches and fallbacks included) and the layer rebinds on it. Tile requests pass a six-slot semaphore of our own (Cesium's global limits are untouched). Under `requestRenderMode` a deferred tile needs a later frame, but a deferral must never request one itself or a stalled tile keeps the scene rendering every frame: a request that finds the semaphore full asks for nothing (the settling request asks for one frame), and a tile Cesium itself deferred goes through one coalesced 250 ms retry. Thumbnails: three fetches at once, sixteen decoded images, least-recently-used where a `get` read is never a use; eviction keeps the probe result. The strip's visible window is probed around the focused card; the pinned and previewed days are probed wherever they sit, at the focused card's priority, so a pin restored or assigned off-screen still drapes. Superseded thumbnail work is cancelled when focus, visible range, pins or preview change; known-good availability metadata remains cached, and each aborted in-flight request is counted once. If the followed automatic day proves empty, the next ranked day's probe is re-requested even if an earlier request was cancelled. +- **Rendering.** `rendering.js` owns at most two GIBS layers on the host `src/maps/imageryHost.js` resolves: the globe port's imagery while the globe shows, the shown photoreal tileset while it is hidden, or none (the panel says so). Layers are rebuilt on a new host, never re-parented. `MapSourceController.subscribe()` fires after every settled stack switch (silent switches and fallbacks included) and the layer rebinds on it. Tile requests pass a six-slot semaphore of our own (Cesium's global limits are untouched). Under `requestRenderMode` a deferred tile needs a later frame, but a deferral must never request one itself or a stalled tile keeps the scene rendering every frame: a request that finds the semaphore full asks for nothing (the settling request asks for one frame), and a tile Cesium itself deferred goes through one coalesced 250 ms retry. Thumbnails: three fetches at once, sixteen decoded images, least-recently-used where a `get` read is never a use; eviction keeps the probe result. The strip's visible window is probed around the focused card; the pinned and previewed days are probed wherever they sit, at the focused card's priority, so a pin restored or assigned off-screen still drapes. A thumbnail request pass over a non-empty strip ends with `retain()`, which cancels queued and in-flight work for days it no longer wants (focus, visible range, pins, sources, the empty-day filter, a share link); a cancelled day already probed present keeps its status. When an automatic day probes empty, its successor is requested again, since scrolling may have cancelled that probe. - **Esri surface and the swipe.** While any image is on the map (a preview included) the layer holds the map lease (`acquireImageryComparison`, owner `recent-imagery`, `esri-if-photoreal`): on Google 3D the map switches to Esri, because 30 m pixels over 3D buildings do not read, and Cesium's split only works on the globe. The lease is handed back, and Google 3D restored unless the operator changed maps meanwhile, when the last image leaves the map or the layer is disabled; the notice line says so while it holds. While a day is shown the imagery keeps Esri: a manual switch that lands on Google 3D is answered at once with a new lease under the same policy (`keepEsri`), the notice reads `Imagery stays on Esri · CLEAR to use Google 3D`, and the divider never suspends because of a map switch. It re-leases once per switch generation and only for a manual one (`MapSourceController#getSwitchOrigin()` is `manual` for an outside `setStack`, `automatic` for the controller's own fallback or recovery), never for the lease's own switch and never while releasing, so CLEAR and disable still return to Google 3D; a lease another owner holds stays refused. When Esri fails and the controller falls back to Google 3D on its own, the layer lets the lease go without restoring anything, both days drape on the tileset without a swipe and the guidance reads `Esri map unavailable · no swipe`; only the next manual switch to Google 3D takes Esri again, so a failing Esri map is never retried in a loop. Switching between globe stacks (Esri, OSM, Bing) only rebinds. On a tileset host both images drape without a swipe. The split control (`createImagerySplit`, labels A / B, or IMAGE / BASEMAP) exists only while a swipe is live, recentres on every new comparison (not while scrubbing the second day), except once for a split restored from a link. There is no keyboard shortcut (Space is the app's push-to-talk): SWAP (`#ri-swap`, in the controls row, its slot reserved and the button disabled while no swipe is live) trades the two sides, A to the right and B to the left, or the image to the right of the basemap, and a second click restores; the hint reads `Drag the divider · SWAP trades sides`. The swap is not in the share link, and every new comparison starts unswapped. One opacity applies to both drapes. Another owner holding the lease is reported and the images still drape. - **Panel.** `#recent-imagery-panel` is rail markup in the Context view (`src/ui/views/ContextView.vue`) beside `#weather-panel`, registered in `PanelLayoutController`, `PanelChrome` and the share panel state (`ui` token `i`), hidden while the layer is off and opened on first appearance unless a stored or shared collapse choice exists (`dataset.collapsedPreference`). `LayerPanel.attachRecentImagery(factory)` mounts the readout (`createRecentImageryPanel` in `src/ui/recentImagery.js`) into its `data-rail-scroller` body, as the weather readout is mounted. The body is a fixed stack in which no block changes height and no control moves in any state: `#ri-actions` (SELECT BOX · USE VIEW · CLEAR, rail-card actions), `#ri-notice` (one line: `#ri-notice-text` with the refusal, error, CLEAR notice or the Esri note, and `#ri-zoom-in` in a fixed slot at its right end, reserved unless an oversized box or view can be fitted), `#ri-strip` (day cards newest first: thumbnail, date, sensor, cloud, START HERE, PREVIEW, and a SHOW chip or A and B chips; ← → Home End move, S / A / B pin, Enter previews), `#ri-hint` (one line: the next step), `#ri-selection` (`#ri-mode` IMAGE · VS BASEMAP · A / B, then `#ri-slot-a` and `#ri-slot-b` with `#ri-unpin-a` / `#ri-unpin-b` kept in place when empty), `#ri-controls` (`#ri-opacity`, EXPORT / EXPORT A and EXPORT B) and `#ri-details`, a collapsed rail card holding the focused day's acquisition, coverage and granules, catalog notes, the empty-days toggle and the imagery credit. Absent controls are reserved (invisible), never removed. Every render preserves the body's `scrollTop`; opening DETAILS then scrolls its card into view once. - **Share links.** Layer options (token `1`): box edges as integers at degrees × 100000, pins `a` and `b` as compact days (`S20260918`), `m` mode (0 image, 1 basemap, 2 A / B), `p` split percent (share-link only: never stored locally) and `v` for the daily overview. Row chips: `MORE DETAIL · 30 m` (on) and `DAILY OVERVIEW · 250 m` (off). diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index 6ed8f036d8..6cd41f19f3 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -833,8 +833,7 @@ export function createRecentImageryLayer({ pruned && (_followKey !== previousFollow || _previewKey !== previousPreview) ) { - // A new automatic day can have had its probe cancelled while offscreen. - // Re-request it even when the visible window has not moved. + // The new automatic day's probe may have been cancelled off-screen. requestThumbnails(); } if (pruned) syncRender(); diff --git a/src/layers/recentImagery/thumbnails.js b/src/layers/recentImagery/thumbnails.js index 48d20a6c0a..47e0f1491f 100644 --- a/src/layers/recentImagery/thumbnails.js +++ b/src/layers/recentImagery/thumbnails.js @@ -169,9 +169,8 @@ export function createThumbnailLoader({ if (existing) { touch(existing); if (existing.loading && existing.controller?.signal.aborted) { - // A known-present re-fetch keeps its metadata when cancelled. If - // that day is wanted again before cancellation settles, give the - // new request its own entry so the old run cannot discard it. + // Wanted again before the abort settles: a fresh entry, so the old + // run cannot discard it. const renewed = { ...existing, priority, @@ -237,11 +236,9 @@ export function createThumbnailLoader({ }, /** - * Keep only refinement work still wanted by the current UI intent. - * - * Known decoded/probed entries may remain warm under the LRU residency - * policy, but queued or in-flight acquisition for no-longer-wanted keys is - * cancelled. A cancelled known-present re-fetch keeps its proven metadata. + * Cancel queued and in-flight work for every key not in `keys`. Settled + * entries stay under the LRU; a cancelled re-fetch of a present day keeps + * its status. * @param {Iterable} keys */ retain(keys) { From bd84fab552b9bc5794d321c070f42a1b30a67bae Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Wed, 18 Nov 2026 16:41:04 +0400 Subject: [PATCH 16/16] refactor(imagery): drop unused cancellation counters and impossible-case guards --- src/layers/recentImagery/index.js | 4 +-- src/layers/recentImagery/thumbnails.js | 26 ++++---------------- src/layers/recentImagery/thumbnails.test.mjs | 11 +-------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/layers/recentImagery/index.js b/src/layers/recentImagery/index.js index 6cd41f19f3..ce3c97610d 100644 --- a/src/layers/recentImagery/index.js +++ b/src/layers/recentImagery/index.js @@ -580,7 +580,7 @@ export function createRecentImageryLayer({ firstVisible: _visible.first, lastVisible: _visible.last, extra: 2, - }) || [], + }), ); for (const key of new Set([ _assigned.a, @@ -593,7 +593,7 @@ export function createRecentImageryLayer({ thumbnails.request(candidate, _box, 0); wanted.add(candidate.key); } - thumbnails.retain?.(wanted); + thumbnails.retain(wanted); } function resetCatalog() { diff --git a/src/layers/recentImagery/thumbnails.js b/src/layers/recentImagery/thumbnails.js index 47e0f1491f..190836fefd 100644 --- a/src/layers/recentImagery/thumbnails.js +++ b/src/layers/recentImagery/thumbnails.js @@ -37,8 +37,6 @@ export function createThumbnailLoader({ const queue = []; let inFlight = 0; let touchCounter = 0; - let supersededQueued = 0; - let supersededInFlight = 0; let destroyed = false; function notify(key) { @@ -225,14 +223,10 @@ export function createThumbnailLoader({ candidates.length, extra, ); - const keys = []; - order.forEach((index, priority) => { - const candidate = candidates[index]; - if (!candidate?.key) return; - keys.push(candidate.key); - this.request(candidate, box, priority); + return order.map((index, priority) => { + this.request(candidates[index], box, priority); + return candidates[index].key; }); - return keys; }, /** @@ -242,19 +236,16 @@ export function createThumbnailLoader({ * @param {Iterable} keys */ retain(keys) { - const wanted = new Set(keys || []); + const wanted = new Set(keys); for (let index = queue.length - 1; index >= 0; index -= 1) { const entry = queue[index]; if (wanted.has(entry.key)) continue; queue.splice(index, 1); - supersededQueued += 1; if (entry.status === 'unknown') entries.delete(entry.key); } for (const entry of [...entries.values()]) { if (!entry.loading || wanted.has(entry.key)) continue; - if (!entry.controller || entry.controller.signal.aborted) continue; - entry.controller.abort(); - supersededInFlight += 1; + entry.controller?.abort(); if (entry.status === 'unknown') entries.delete(entry.key); } }, @@ -301,13 +292,6 @@ export function createThumbnailLoader({ return () => listeners.delete(listener); }, - refinementStats() { - return { - supersededQueued, - supersededInFlight, - }; - }, - stats() { return { inFlight, diff --git a/src/layers/recentImagery/thumbnails.test.mjs b/src/layers/recentImagery/thumbnails.test.mjs index b7b0fe4403..a9df5e0861 100644 --- a/src/layers/recentImagery/thumbnails.test.mjs +++ b/src/layers/recentImagery/thumbnails.test.mjs @@ -357,14 +357,10 @@ test('retain aborts stale acquisition while allowing the current intent to start 'current intent starts after stale abort', ); assert.match(fetch.calls[1].url, /TIME=2026-09-11/); - assert.deepEqual(loader.refinementStats(), { - supersededQueued: 0, - supersededInFlight: 1, - }); assert.equal(loader.get(stale.key).status, 'unknown'); }); -test('repeat retain counts an aborted known-present re-fetch once', async () => { +test('a cancelled re-fetch of a known-present day keeps its status and is retryable', async () => { const { loader, fetch } = fixture({ maxInFlight: 1, maxDecoded: 1 }); const stale = candidate('S30', '2026-09-10'); const newer = candidate('S30', '2026-09-11'); @@ -383,12 +379,7 @@ test('repeat retain counts an aborted known-present re-fetch once', async () => loader.request(stale, BOX, 0); assert.equal(fetch.calls.length, 3, 'an evicted known day re-fetches'); loader.retain([]); - loader.retain([]); assert.equal(fetch.calls[2].signal.aborted, true); - assert.deepEqual(loader.refinementStats(), { - supersededQueued: 0, - supersededInFlight: 1, - }); await settle(); assert.equal(loader.get(stale.key).status, 'present');