From 744f0f8e445d122f5c049b48060fff54787c6cca Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:14:15 +0800 Subject: [PATCH] fix(sftp): publish repaired hierarchy before ignoring progress --- .../state/sftpTransferCenterStore.test.ts | 26 +++++++++++++++++++ application/state/sftpTransferCenterStore.ts | 9 +++++++ ...ansferCenter.children-performance.test.tsx | 22 ++++++++++++++++ docs/research/sftp-folder-list-performance.md | 17 ++++++++++++ 4 files changed, 74 insertions(+) diff --git a/application/state/sftpTransferCenterStore.test.ts b/application/state/sftpTransferCenterStore.test.ts index 94844d89a..88aedc9c2 100644 --- a/application/state/sftpTransferCenterStore.test.ts +++ b/application/state/sftpTransferCenterStore.test.ts @@ -4051,3 +4051,29 @@ test("admission updates hierarchy state without forcing full owner lifecycle wor assert.equal(store.getLifecycleSnapshot().tasks[0].status, "transferring"); assert.equal(lifecycleNotifications, 0, "dispatch admission keeps its existing lightweight fanout"); }); + + +test("same-byte and ignored terminal events publish repaired background hierarchy immediately", () => { + for (const { status, type } of [ + { status: "transferring", type: "progress" }, + { status: "completed", type: "progress" }, + { status: "completed", type: "completed" }, + { status: "failed", type: "failed" }, + ] as const) { + const store = createSftpTransferCenterStore(); + store.publishOwner("panel", [{ ...makeTask("folder"), isDirectory: true }]); + store.publishOwner("background-agent", [{ ...makeTask("orphan", status), background: true }]); + const beforeRepair = store.getLifecycleSnapshot(); + let lifecycleNotifications = 0; + store.subscribe(() => { lifecycleNotifications += 1; }); + store.ingestBackgroundEvent({ type, transferId: "orphan", parentTaskId: "folder", transferred: 2 }); + const repaired = store.getLifecycleSnapshot(); + assert.notEqual(repaired, beforeRepair, status); + assert.equal(repaired.tasks.find((task) => task.id === "orphan")?.parentTaskId, "folder", status); + assert.equal(repaired.tasks.find((task) => task.id === "orphan")?.background, false, status); + assert.equal(lifecycleNotifications, 0, "hierarchy repair keeps lightweight owner fanout"); + store.ingestBackgroundEvent({ type: "progress", transferId: "orphan", parentTaskId: "folder", transferred: 3 }); + assert.equal(store.getLifecycleSnapshot(), repaired, "subsequent byte ticks preserve the repaired hierarchy without rebuilding it"); + assert.equal(store.getTask("orphan")?.parentTaskId, "folder"); + } +}); diff --git a/application/state/sftpTransferCenterStore.ts b/application/state/sftpTransferCenterStore.ts index 769db9688..49d97fbc9 100644 --- a/application/state/sftpTransferCenterStore.ts +++ b/application/state/sftpTransferCenterStore.ts @@ -2218,6 +2218,12 @@ export function createSftpTransferCenterStore(persistence?: StorePersistence): S existing = tasks[existingIndex]; captureObservedTask(existing); } + // Hierarchy repair has already changed the live row. Even an otherwise + // ignored event must publish that change; ordinary progress still emits + // only once at the end, without a second directory-sized snapshot build. + const publishRepairedHierarchy = () => { + if (existing !== beforeEvent) emitProgress(false, true); + }; // A delayed child progress event can arrive after the renderer compacted // that completed child into its parent checkpoint. Never resurrect it as // a live row, especially after the parent itself has finished. @@ -2243,9 +2249,11 @@ export function createSftpTransferCenterStore(persistence?: StorePersistence): S // Allow a late explicit cancel to stick; ignore everything else. if (event.type === "completed" || event.type === "failed") { // Keep existing terminal state (prefer cancelled over late completed). + publishRepairedHierarchy(); return; } if (event.type === "queued" || event.type === "started" || event.type === "progress" || event.type === "pausing" || event.type === "resumed" || event.type === "paused") { + publishRepairedHierarchy(); return; } } @@ -2290,6 +2298,7 @@ export function createSftpTransferCenterStore(persistence?: StorePersistence): S && sameOptional(event.resumable, existing.resumable) && sameOptional(event.pauseUnavailableReason, existing.pauseUnavailableReason) ) { + publishRepairedHierarchy(); return; } } diff --git a/components/GlobalSftpTransferCenter.children-performance.test.tsx b/components/GlobalSftpTransferCenter.children-performance.test.tsx index 8aecbe693..44776e6f8 100644 --- a/components/GlobalSftpTransferCenter.children-performance.test.tsx +++ b/components/GlobalSftpTransferCenter.children-performance.test.tsx @@ -130,5 +130,27 @@ test("expanded folder history bounds mounted files, isolates progress, and reach await click('button[aria-label="Show files"]'); assert.ok(childRows().length > 0 && childRows().length < 40); assert.equal(store.getSnapshot().tasks.filter((task) => task.parentTaskId === "folder").length, childCount - 1, "virtualization never drops queued files"); + await runWithAct(() => { + store.publishOwner("repair-folder", [{ ...base, id: "repair-folder", fileName: "repaired folder", status: "transferring", isDirectory: true }]); + store.publishOwner("repair-background", [{ ...base, id: "repair-child", fileName: "repaired-child.bin", status: "transferring", isDirectory: false, background: true, transferredBytes: 10 }]); + }); + const repairedFolderRow = () => [...env.document.querySelectorAll('[data-section=global-sftp-transfer-row]')].find((row) => row.textContent?.includes("repaired folder"))!; + assert.equal(repairedFolderRow().querySelector('button[aria-label="Show files"]'), null); + await runWithAct(async () => { + store.ingestBackgroundEvent({ type: "progress", transferId: "repair-child", parentTaskId: "repair-folder", transferred: 10 }); + await new Promise((resolve) => setTimeout(resolve, 20)); + }); + const repairedExpand = repairedFolderRow().querySelector('button[aria-label="Show files"]'); + assert.ok(repairedExpand, "same-byte hierarchy repair immediately exposes the folder's child"); + await dispatchDomEvent(repairedExpand, new env.window.MouseEvent("click", { bubbles: true })); + await flushEffects(); + assert.match(repairedFolderRow().textContent ?? "", /repaired-child.bin/); + const repairedHierarchy = store.getLifecycleSnapshot(); + await runWithAct(async () => { + store.ingestBackgroundEvent({ type: "progress", transferId: "repair-child", parentTaskId: "repair-folder", transferred: 11 }); + await new Promise((resolve) => setTimeout(resolve, 20)); + }); + assert.equal(store.getLifecycleSnapshot(), repairedHierarchy); + assert.match(repairedFolderRow().textContent ?? "", /repaired-child.bin/); await click("[data-section=global-sftp-transfer-toggle]"); }); diff --git a/docs/research/sftp-folder-list-performance.md b/docs/research/sftp-folder-list-performance.md index b881ce4d3..07f600b83 100644 --- a/docs/research/sftp-folder-list-performance.md +++ b/docs/research/sftp-folder-list-performance.md @@ -64,3 +64,20 @@ An Electron comparison against initial repair 1b96e27b0 confirmed stale batch buttons before and correct disabled/enabled states afterward. The final 1,000 / 5,000 file runs still mounted 12 rows and reached the final file: expand-to-frame 12.6 / 12.86 ms, child progress 1.32–15.42 / 1.06–17.90 ms. + + +## Hierarchy repair follow-up + +A same-byte background event can repair a formerly top-level child before the +progress de-duplication guard returns. The repaired hierarchy must be published +even when the remaining event is ignored, including late events for terminal +rows. Those early exits now publish only when repair actually replaced the row; +normal progress still builds at most one hierarchy snapshot and ordinary byte +ticks keep its reference stable. + +Both the store and actual-center regressions failed before this repair. The +Electron comparison against e894c9cb confirmed the old folder had no Show files +action after the same-byte event or its next byte tick. The repaired folder +immediately exposes its child, and the next byte tick keeps that grouping +without rebuilding it. A fresh 5,000-file run mounted 12 rows, reached the final +file and retained all 5,000 records: expansion 14.12 ms, progress 1.28-18.58 ms.