fix(desktop): keep archive sync in main window

Co-authored-by: Rizz <302abe414ca6e3134763d2539bfcf145aea2a63fe5f8455204ed602fd40cf381@buzz.block.builderlab.xyz>
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
Taylor Ho
2026-08-23 20:38:45 -07:00
committed by Rizz
parent 22caeb7405
commit fc4aec4f56
2 changed files with 24 additions and 21 deletions

View File

@@ -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" });

View File

@@ -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;