Skip to content

Commit 49f4240

Browse files
authored
fix: keep session catalog mirroring within isolated profiles (#129638)
* fix: bind catalog HOME policy in active facade * fix: report isolated catalog mirroring
1 parent 6a246f7 commit 49f4240

4 files changed

Lines changed: 90 additions & 2 deletions

File tree

‎extensions/beam/src/mirror.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function fakeCatalog(params: {
5555
hostKind?: string;
5656
onList?: () => unknown;
5757
onRead?: (threadId: string) => unknown;
58+
processHomeFallbackAllowed?: boolean;
5859
}): ActiveSessionCatalog {
5960
const host: SessionCatalogHost = {
6061
hostId: "gateway:local",
@@ -77,6 +78,7 @@ function fakeCatalog(params: {
7778
pluginId: params.id,
7879
id: params.id,
7980
label: params.id,
81+
processHomeFallbackAllowed: params.processHomeFallbackAllowed ?? true,
8082
list: async () => {
8183
await params.onList?.();
8284
return [host];
@@ -815,6 +817,28 @@ describe("createBeamMirrorRunner", () => {
815817
expect(sent).toHaveLength(0);
816818
});
817819

820+
it("warns once when profile isolation disables process-HOME fallback", async () => {
821+
const warnings: string[] = [];
822+
const catalog = fakeCatalog({
823+
id: "claude",
824+
sessions: [],
825+
processHomeFallbackAllowed: false,
826+
});
827+
const runner = createBeamMirrorRunner({
828+
runtime: fakeRuntime(mirrorConfig({ catalogs: ["claude"] })),
829+
logger: { warn: (message) => warnings.push(message), info: () => {} },
830+
now: () => NOW,
831+
listCatalogs: () => [catalog],
832+
});
833+
834+
await runner.tick();
835+
await runner.tick();
836+
837+
expect(warnings).toEqual([
838+
"beam mirror process-HOME fallback disabled: isolated state; only explicit catalog roots can be mirrored",
839+
]);
840+
});
841+
818842
it("sends one completed upload when a session leaves the active window", async () => {
819843
const sent: SentRequest[] = [];
820844
const recency = NOW - 60_000;

‎extensions/beam/src/mirror.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export function createBeamMirrorRunner(params: {
281281
const controller = new AbortController();
282282
const { signal } = controller;
283283
let lastWarnAt = 0;
284+
let warnedProcessHomeIsolation = false;
284285
let redirectBlockedEndpoint: string | undefined;
285286
let activeTick: Promise<void> | undefined;
286287
let stopPromise: Promise<void> | undefined;
@@ -458,6 +459,15 @@ export function createBeamMirrorRunner(params: {
458459
// would otherwise re-mirror each other's rows forever.
459460
catalog.id !== "beam" && mirror.catalogs.includes(catalog.id),
460461
);
462+
if (
463+
!warnedProcessHomeIsolation &&
464+
catalogs.some((catalog) => !catalog.processHomeFallbackAllowed)
465+
) {
466+
warnedProcessHomeIsolation = true;
467+
params.logger.warn(
468+
"beam mirror process-HOME fallback disabled: isolated state; only explicit catalog roots can be mirrored",
469+
);
470+
}
461471
const catalogById = new Map(catalogs.map((catalog) => [catalog.id, catalog]));
462472
const candidates: BeamMirrorCandidate[] = [];
463473
for (const catalog of catalogs) {

‎src/gateway/server-methods/session-catalog.home-isolation.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const hoisted = vi.hoisted(() => ({
1717

1818
vi.mock("../../plugins/runtime.js", () => ({
1919
getActivePluginRegistry: () => hoisted.activeRegistry,
20+
getActivePluginSessionExtensionRegistry: () => hoisted.activeRegistry,
2021
requireActivePluginRegistry: () => hoisted.activeRegistry,
2122
}));
2223
vi.mock("../../config/sessions/session-accessor.js", async (importOriginal) => ({
@@ -25,6 +26,7 @@ vi.mock("../../config/sessions/session-accessor.js", async (importOriginal) => (
2526
}));
2627

2728
const { sessionCatalogHandlers } = await import("./session-catalog.js");
29+
const { listActiveSessionCatalogs } = await import("../../plugins/session-catalog-active.js");
2830

2931
function provider(
3032
id: string,
@@ -121,6 +123,52 @@ describe("session catalog Gateway HOME isolation", () => {
121123
);
122124
});
123125

126+
it("binds HOME isolation into the internal read-only catalog facade", async () => {
127+
const localHost = {
128+
hostId: "gateway:local",
129+
label: "Local",
130+
kind: "gateway" as const,
131+
connected: true,
132+
sessions: [],
133+
};
134+
const list = vi.fn(async (request: { allowProcessHomeFallback?: boolean }) =>
135+
request.allowProcessHomeFallback === false ? [] : [localHost],
136+
);
137+
const read = vi.fn(async (request: Parameters<SessionCatalogProvider["read"]>[0]) => {
138+
if (request.allowProcessHomeFallback === false) {
139+
throw new Error("local Test sessions are unavailable in isolated state");
140+
}
141+
return { hostId: request.hostId, threadId: request.threadId, items: [] };
142+
});
143+
hoisted.activeRegistry.sessionCatalogs = [{ provider: provider("test", { list, read }) }];
144+
145+
await withProfile(undefined, async () => {
146+
const [catalog] = listActiveSessionCatalogs();
147+
expect(catalog?.processHomeFallbackAllowed).toBe(true);
148+
await expect(catalog?.list({})).resolves.toEqual([localHost]);
149+
await expect(
150+
catalog?.read({ hostId: "gateway:local", threadId: "known-thread" }),
151+
).resolves.toMatchObject({ threadId: "known-thread" });
152+
});
153+
await withProfile("dev", async () => {
154+
const [catalog] = listActiveSessionCatalogs();
155+
expect(catalog?.processHomeFallbackAllowed).toBe(false);
156+
await expect(catalog?.list({})).resolves.toEqual([]);
157+
await expect(
158+
catalog?.read({ hostId: "gateway:local", threadId: "known-thread" }),
159+
).rejects.toThrow("local Test sessions are unavailable in isolated state");
160+
});
161+
162+
expect(list.mock.calls.map(([request]) => request.allowProcessHomeFallback)).toEqual([
163+
true,
164+
false,
165+
]);
166+
expect(read.mock.calls.map(([request]) => request.allowProcessHomeFallback)).toEqual([
167+
true,
168+
false,
169+
]);
170+
});
171+
124172
it.each([
125173
["continue", "continueSession", {}],
126174
["archive", "archive", { confirmNoOtherRunner: true }],

‎src/plugins/session-catalog-active.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { allowsProcessHomeSessionScan } from "../config/paths.js";
12
import { getActivePluginSessionExtensionRegistry } from "./runtime.js";
23
import type { SessionCatalogProvider } from "./session-catalog.js";
34

45
export type ActiveSessionCatalog = {
56
pluginId: string;
67
id: string;
78
label: string;
9+
processHomeFallbackAllowed: boolean;
810
list: SessionCatalogProvider["list"];
911
read: SessionCatalogProvider["read"];
1012
};
@@ -16,13 +18,17 @@ export type ActiveSessionCatalog = {
1618
*/
1719
export function listActiveSessionCatalogs(): ActiveSessionCatalog[] {
1820
const registrations = getActivePluginSessionExtensionRegistry()?.sessionCatalogs ?? [];
21+
const allowProcessHomeFallback = allowsProcessHomeSessionScan();
1922
return registrations
2023
.map(({ pluginId, provider }) => ({
2124
pluginId,
2225
id: provider.id,
2326
label: provider.label,
24-
list: provider.list.bind(provider),
25-
read: provider.read.bind(provider),
27+
processHomeFallbackAllowed: allowProcessHomeFallback,
28+
list: (params: Parameters<SessionCatalogProvider["list"]>[0]) =>
29+
provider.list({ ...params, allowProcessHomeFallback }),
30+
read: (params: Parameters<SessionCatalogProvider["read"]>[0]) =>
31+
provider.read({ ...params, allowProcessHomeFallback }),
2632
}))
2733
.toSorted((left, right) => left.id.localeCompare(right.id));
2834
}

0 commit comments

Comments
 (0)