From fc4aec4f56f0bc150c6da1ff83a717f980b0c486 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Sun, 23 Aug 2026 20:38:45 -0700 Subject: [PATCH] fix(desktop): keep archive sync in main window Co-authored-by: Rizz <302abe414ca6e3134763d2539bfcf145aea2a63fe5f8455204ed602fd40cf381@buzz.block.builderlab.xyz> Signed-off-by: Taylor Ho --- .../local-archive/useArchiveSync.test.mjs | 41 ++++++++++--------- .../features/local-archive/useArchiveSync.ts | 4 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/desktop/src/features/local-archive/useArchiveSync.test.mjs b/desktop/src/features/local-archive/useArchiveSync.test.mjs index 672c197582..057f7c8c0b 100644 --- a/desktop/src/features/local-archive/useArchiveSync.test.mjs +++ b/desktop/src/features/local-archive/useArchiveSync.test.mjs @@ -75,7 +75,7 @@ function mountGate({ }, // `getCurrentWindow()` reads exactly this path (api/window.js:85), and // `isTauri()` reads `globalThis.isTauri` (api/core.js:280). Both are what - // `huddleWindowChannelId` uses to tell a companion realm from the main one. + // `isCompanionWindow` uses to tell a companion realm from the main one. metadata: { currentWindow: { label: windowLabel } }, transformCallback: () => Math.random(), }; @@ -265,25 +265,28 @@ describe("archive sync lifecycle leases", () => { // commands at all. describe("archive sync realm ownership", () => { - it("issues no archive lifecycle commands from a companion window", async () => { - const gate = mountGate({ - windowLabel: "huddle-11111111-2222-3333-4444-555555555555", - }); - await gate.mount(); - await gate.settleGate(); - await gate.unmount(); + for (const windowLabel of [ + "huddle-test-channel-do-not-use", + "agent-activity-test-agent-do-not-use-test-channel-do-not-use", + ]) { + it(`issues no archive lifecycle commands from ${windowLabel}`, async () => { + const gate = mountGate({ windowLabel }); + await gate.mount(); + await gate.settleGate(); + await gate.unmount(); - assert.deepEqual( - gate.invoked.filter( - (cmd) => - cmd.endsWith("_archive_sync") || - cmd === "announce_archive_sync_epoch", - ), - [], - "a companion realm must not announce or run lifecycle commands — its " + - "cleanup would cancel the main window's live sync task", - ); - }); + assert.deepEqual( + gate.invoked.filter( + (cmd) => + cmd.endsWith("_archive_sync") || + cmd === "announce_archive_sync_epoch", + ), + [], + "a companion realm must not announce or run lifecycle commands — its " + + "cleanup would cancel the main window's live sync task", + ); + }); + } it("still runs the lifecycle in the main window", async () => { const gate = mountGate({ windowLabel: "main" }); diff --git a/desktop/src/features/local-archive/useArchiveSync.ts b/desktop/src/features/local-archive/useArchiveSync.ts index 666b1aac72..0aabff5a0a 100644 --- a/desktop/src/features/local-archive/useArchiveSync.ts +++ b/desktop/src/features/local-archive/useArchiveSync.ts @@ -1,6 +1,6 @@ import * as React from "react"; -import { huddleWindowChannelId } from "@/features/huddle/lib/huddleWindow"; +import { isCompanionWindow } from "@/app/companionWindow"; import { announceArchiveSyncEpoch, nextArchiveSyncLease, @@ -60,7 +60,7 @@ export function useArchiveSync(ready: boolean): void { React.useEffect(() => { if (!ready) return; // Companion realms do not participate; see the ownership rule above. - if (huddleWindowChannelId() !== null) return; + if (isCompanionWindow()) return; const lease = nextArchiveSyncLease(); let stopped = false;