Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions core/config/ConfigHandler.hubCache.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";

import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";

describe("ConfigHandler hub assistant cache fallback", () => {
let tempDir: string;

beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "continue-hub-cache-"));
process.env.CONTINUE_GLOBAL_DIR = path.join(tempDir, ".continue-global");
vi.resetModules();
});

afterEach(() => {
delete process.env.CONTINUE_GLOBAL_DIR;
fs.rmSync(tempDir, { force: true, recursive: true });
});

test("uses cached hub assistants when the hub becomes unavailable", async () => {
const [{ ConfigHandler }, { LLMLogger }, { default: FileSystemIde }] =
await Promise.all([
import("./ConfigHandler"),
import("../llm/logger"),
import("../util/filesystem"),
]);

class TestIde extends FileSystemIde {
override async fileExists(fileUri: string): Promise<boolean> {
const filepath = fileUri.startsWith("file://")
? fileURLToPath(fileUri)
: fileUri;
return fs.existsSync(filepath);
}
}

const ide = new TestIde(tempDir);
const handler = new ConfigHandler(
ide,
new LLMLogger(),
Promise.resolve(undefined),
);
await handler.isInitialized;

const personalAssistant = {
configResult: {
config: {
name: "Local LlamaCpp",
version: "1.0.0",
},
configLoadInterrupted: false,
errors: [],
},
iconUrl: "https://example.com/personal.png",
ownerSlug: "lemonade",
packageSlug: "llamacpp",
rawYaml: "name: Local LlamaCpp",
};
const orgAssistant = {
configResult: {
config: {
name: "Org Assistant",
version: "2.0.0",
},
configLoadInterrupted: false,
errors: [],
},
iconUrl: "https://example.com/org.png",
ownerSlug: "continuedev",
packageSlug: "team-assistant",
rawYaml: "name: Org Assistant",
};

let outage = false;
(handler as any).controlPlaneClient = {
getPolicy: vi.fn().mockResolvedValue(null),
isSignedIn: vi.fn().mockResolvedValue(true),
listOrganizations: vi.fn().mockImplementation(async () => {
if (outage) {
return null;
}

return [
{
iconUrl: "https://example.com/org.png",
id: "org-1",
name: "Org One",
slug: "org-one",
},
];
}),
listAssistants: vi
.fn()
.mockImplementation(async (orgId: string | null) => {
if (outage) {
return null;
}

return orgId === null ? [personalAssistant] : [orgAssistant];
}),
};

const warm = await (handler as any).getOrgs();
expect(warm.errors ?? []).toHaveLength(0);

outage = true;

const fallback = await (handler as any).getOrgs();
expect(fallback.errors?.map((error: any) => error.message)).toContain(
"Continue Hub is unavailable. Using cached Hub assistants until the service recovers.",
);

const personalOrg = fallback.orgs.find((org: any) => org.id === "personal");
expect(
personalOrg?.profiles.some(
(profile: any) =>
profile.profileDescription.id === "lemonade/llamacpp" &&
profile.profileDescription.title === "Local LlamaCpp",
),
).toBe(true);

const org = fallback.orgs.find((entry: any) => entry.id === "org-1");
expect(
org?.profiles.some(
(profile: any) =>
profile.profileDescription.id === "continuedev/team-assistant" &&
profile.profileDescription.title === "Org Assistant",
),
).toBe(true);
});
});
141 changes: 121 additions & 20 deletions core/config/ConfigHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
IdeSettings,
ILLMLogger,
} from "../index.js";
import { GlobalContext } from "../util/GlobalContext.js";
import {
CachedHubAssistant,
CachedHubOrganization,
GlobalContext,
} from "../util/GlobalContext.js";
import { getConfigYamlPath } from "../util/paths.js";

import EventEmitter from "node:events";
Expand Down Expand Up @@ -176,30 +180,71 @@ export class ConfigHandler {
const isSignedIn = await this.controlPlaneClient.isSignedIn();
if (isSignedIn) {
try {
let usedCachedHubData = false;

// TODO use policy returned with org, not policy endpoint
const policyResponse = await this.controlPlaneClient.getPolicy();
PolicySingleton.getInstance().policy = policyResponse;

const cachedHubOrganizations = this.getCachedHubOrganizations();
const orgDescriptions =
await this.controlPlaneClient.listOrganizations();
const orgsWithPolicy = orgDescriptions.map((d) => ({
...d,
policy: policyResponse?.policy,
}));
const orgsWithPolicy = (orgDescriptions ?? cachedHubOrganizations)
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Hub fallback cache is not scoped or cleared per account, so unavailable Hub responses can expose stale orgs/assistants after account switch.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At core/config/ConfigHandler.ts, line 192:

<comment>Hub fallback cache is not scoped or cleared per account, so unavailable Hub responses can expose stale orgs/assistants after account switch.</comment>

<file context>
@@ -176,30 +180,71 @@ export class ConfigHandler {
-          ...d,
-          policy: policyResponse?.policy,
-        }));
+        const orgsWithPolicy = (orgDescriptions ?? cachedHubOrganizations)
+          .filter((org) => org.id !== this.PERSONAL_ORG_DESC.id)
+          .map((d) => ({
</file context>
Fix with Cubic

.filter((org) => org.id !== this.PERSONAL_ORG_DESC.id)
Comment on lines +189 to +193
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scope hub-assistant fallback cache to active account

When listOrganizations() fails, this path falls back to cachedHubOrganizations from global context, but the cached records are not keyed to the signed-in account and this change does not invalidate them on auth/org changes. In practice, if a user switches accounts (or loses org membership) and the Hub is unavailable, the app can resurrect assistants/orgs from the previous account, exposing stale/private profile metadata and selecting profiles the current user should not see. Please scope the cache by account identity (or clear it on session changes) before using it for offline fallback.

Useful? React with 👍 / 👎.

.map((d) => ({
iconUrl: d.iconUrl,
id: d.id,
name: d.name,
slug: d.slug,
policy: policyResponse?.policy,
}));

if (orgDescriptions === null && cachedHubOrganizations.length > 0) {
usedCachedHubData = true;
}

if (policyResponse?.policy?.allowOtherOrgs === false) {
if (orgsWithPolicy.length === 0) {
return { orgs: [] };
} else {
const firstOrg = await this.getNonPersonalHubOrg(orgsWithPolicy[0]);
return { orgs: [firstOrg] };
if (firstOrg.usedCache) {
usedCachedHubData = true;
}
if (usedCachedHubData) {
errors.push({
fatal: false,
message:
"Continue Hub is unavailable. Using cached Hub assistants until the service recovers.",
});
}
return { orgs: [firstOrg.org], errors };
}
}
const orgs = await Promise.all([
this.getPersonalHubOrg(),
...orgsWithPolicy.map((org) => this.getNonPersonalHubOrg(org)),
]);

const personalOrg = await this.getPersonalHubOrg();
const nonPersonalOrgs = await Promise.all(
orgsWithPolicy.map((org) => this.getNonPersonalHubOrg(org)),
);
if (
personalOrg.usedCache ||
nonPersonalOrgs.some((org) => org.usedCache)
) {
usedCachedHubData = true;
}
if (usedCachedHubData) {
errors.push({
fatal: false,
message:
"Continue Hub is unavailable. Using cached Hub assistants until the service recovers.",
});
}
const orgs = [
personalOrg.org,
...nonPersonalOrgs.map((org) => org.org),
];
// TODO make try/catch more granular here, to catch specific org errors
return { orgs };
return { orgs, errors };
} catch (e) {
errors.push({
fatal: false,
Expand Down Expand Up @@ -236,9 +281,21 @@ export class ConfigHandler {
}));
}

private async getHubProfiles(orgScopeId: string | null) {
const assistants = await this.controlPlaneClient.listAssistants(orgScopeId);
private getCachedHubOrganizations(): CachedHubOrganization[] {
return this.globalContext.get("cachedHubOrganizations") ?? [];
}

private updateCachedHubOrganization(org: CachedHubOrganization) {
const cached = this.getCachedHubOrganizations().filter(
(existing) => existing.id !== org.id,
);
this.globalContext.update("cachedHubOrganizations", [...cached, org]);
}

private async createPlatformProfiles(
assistants: CachedHubAssistant[],
orgScopeId: string | null,
) {
return await Promise.all(
assistants.map(async (assistant) => {
const profileLoader = await PlatformProfileLoader.create({
Expand All @@ -254,23 +311,58 @@ export class ConfigHandler {
ide: this.ide,
llmLogger: this.llmLogger,
rawYaml: assistant.rawYaml,
orgScopeId: orgScopeId,
orgScopeId,
});

return new ProfileLifecycleManager(profileLoader, this.ide);
}),
);
}

private async loadHubProfiles(
orgScopeId: string | null,
org: OrganizationDescription,
): Promise<{ profiles: ProfileLifecycleManager[]; usedCache: boolean }> {
const assistants = await this.controlPlaneClient.listAssistants(orgScopeId);
if (assistants !== null) {
this.updateCachedHubOrganization({
id: org.id,
iconUrl: org.iconUrl,
name: org.name,
slug: org.slug,
profiles: assistants,
});
return {
profiles: await this.createPlatformProfiles(assistants, orgScopeId),
usedCache: false,
};
}

const cachedProfiles =
this.getCachedHubOrganizations().find((entry) => entry.id === org.id)
?.profiles ?? [];
return {
profiles: await this.createPlatformProfiles(cachedProfiles, orgScopeId),
usedCache: cachedProfiles.length > 0,
};
}

private async getNonPersonalHubOrg(
org: OrganizationDescription,
): Promise<OrgWithProfiles> {
): Promise<{ org: OrgWithProfiles; usedCache: boolean }> {
const localProfiles = await this.getLocalProfiles({
includeGlobal: false,
includeWorkspace: true,
});
const profiles = [...(await this.getHubProfiles(org.id)), ...localProfiles];
return this.rectifyProfilesForOrg(org, profiles);
const { profiles: hubProfiles, usedCache } = await this.loadHubProfiles(
org.id,
org,
);
const profiles = [...hubProfiles, ...localProfiles];
return {
org: await this.rectifyProfilesForOrg(org, profiles),
usedCache,
};
}

private PERSONAL_ORG_DESC: OrganizationDescription = {
Expand All @@ -279,14 +371,23 @@ export class ConfigHandler {
name: "Personal",
slug: undefined,
};
private async getPersonalHubOrg() {
private async getPersonalHubOrg(): Promise<{
org: OrgWithProfiles;
usedCache: boolean;
}> {
const localProfiles = await this.getLocalProfiles({
includeGlobal: true,
includeWorkspace: true,
});
const hubProfiles = await this.getHubProfiles(null);
const { profiles: hubProfiles, usedCache } = await this.loadHubProfiles(
null,
this.PERSONAL_ORG_DESC,
);
const profiles = [...hubProfiles, ...localProfiles];
return this.rectifyProfilesForOrg(this.PERSONAL_ORG_DESC, profiles);
return {
org: await this.rectifyProfilesForOrg(this.PERSONAL_ORG_DESC, profiles),
usedCache,
};
}

private async getLocalOrg() {
Expand Down
Loading
Loading