Skip to content

The open-source app everyone uses to manage agents at work

fix(cloud): enable experimental toggles on staging (#16876)

Dottac5226daf7a37
diff --git a/docs/guides/board-operator/experimental-features.md b/docs/guides/board-operator/experimental-features.md
index 485f9eb94e..09f486e79c 100644
--- a/docs/guides/board-operator/experimental-features.md
+++ b/docs/guides/board-operator/experimental-features.md
@@ -22,6 +22,13 @@ Controls are listed alphabetically within each section. Hosting operators can hi
controls they manage; empty developer and legacy sections are omitted. Hidden
controls retain their configured values.
+On Paperclip Cloud staging (`*.staging.paperclip.app`), instance admins can
+view and change experimental settings. Cloud-managed feature values act as
+defaults until changed, and saved choices survive reloads. Production Cloud
+keeps its managed values and hosting restrictions. Staging only permits changes
+to an explicit list of feature controls. Cloud access and execution policies,
+including managed-sandbox-only execution, remain managed on staging.
+
The CLI exposes the same surface:
```sh
diff --git a/maps/agent-access-map/instance-operations.md b/maps/agent-access-map/instance-operations.md
index 9728d1085b..cc3dcb2221 100644
--- a/maps/agent-access-map/instance-operations.md
+++ b/maps/agent-access-map/instance-operations.md
@@ -81,6 +81,17 @@ own policy and access review.
Gaps: Settings APIs cover parts of configuration; pre-start database/binding/storage
configuration is local operator tooling.
+Cloud staging exposes experimental controls to instance admins and permits saved
+overrides of Cloud feature defaults. This exception requires a managed instance
+and a provisioner-supplied `*.staging.paperclip.app` primary hostname; request
+headers do not establish staging. Ordinary board members and agents still cannot
+mutate instance settings. Only an explicit feature allowlist is editable. Cloud
+owner-admin elevation and managed-sandbox execution policy remain managed, and
+production policy and other Cloud floors remain.
+Local [route tests](../../server/src/__tests__/instance-settings-routes.test.ts)
+cover staging admin access, non-admin denial and a spoofed request hostname;
+no live Cloud or agent-credential verification is claimed.
+
## `diagnostics`
Review: `baseline`.
diff --git a/maps/feature-map/instance-operations.md b/maps/feature-map/instance-operations.md
index 8812efe61e..f28d75d3e4 100644
--- a/maps/feature-map/instance-operations.md
+++ b/maps/feature-map/instance-operations.md
@@ -60,6 +60,14 @@ Automated: [experimental settings](../../ui/src/pages/InstanceExperimentalSettin
Manual: Change a harmless experimental setting, reload, and confirm the affected route honors it. Back up a disposable instance, inspect the reported file and metadata, and restore using the documented procedure into a second isolated target. Verify a known record after restoration.
+Cloud staging: On a managed `*.staging.paperclip.app` instance, verify experiments
+are visible and editable by an instance admin, and changes survive reload.
+Production keeps its hidden controls and managed feature values. Staging retains
+other Cloud restrictions. [Settings policy tests](../../server/src/__tests__/instance-settings-managed-overlay.test.ts),
+[route tests](../../server/src/__tests__/instance-settings-routes.test.ts), and
+[health tests](../../server/src/__tests__/health.test.ts) exercise simulated Cloud
+identities and persistence; they do not establish a deployed staging walkthrough.
+
## Gotchas
- Source-checkout update/check commands report manual update guidance; they do
diff --git a/server/src/__tests__/cloud-instance.test.ts b/server/src/__tests__/cloud-instance.test.ts
index dd5097bc69..fa00a56fbc 100644
--- a/server/src/__tests__/cloud-instance.test.ts
+++ b/server/src/__tests__/cloud-instance.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
getCloudStackContext,
isCloudManagedInstance,
+ isCloudStagingInstance,
type CloudInstanceEnv,
} from "../services/cloud-instance.js";
@@ -33,6 +34,31 @@ describe("isCloudManagedInstance", () => {
});
});
+describe("isCloudStagingInstance", () => {
+ it("requires both a managed instance and a provisioner-owned staging hostname", () => {
+ expect(isCloudStagingInstance({
+ PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN: "tenant-token",
+ PAPERCLIP_PRIMARY_HOST: " team.staging.paperclip.app ",
+ })).toBe(true);
+ expect(isCloudStagingInstance({
+ PAPERCLIP_MANAGED_CONFIG: "managed-document",
+ PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app",
+ })).toBe(true);
+ expect(isCloudStagingInstance({ PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app" })).toBe(false);
+ });
+
+ it.each([undefined, "", "team.paperclip.app", "localhost", "staging.example.com", "team.staging.paperclip.app.evil.com"])(
+ "keeps production restrictions with primary host %s",
+ (primaryHost) => {
+ expect(isCloudStagingInstance({
+ PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN: "tenant-token",
+ PAPERCLIP_PRIMARY_HOST: primaryHost,
+ NODE_ENV: "development",
+ })).toBe(false);
+ },
+ );
+});
+
describe("getCloudStackContext", () => {
it("returns null outside Paperclip Cloud even when stray stack metadata exists", () => {
expect(getCloudStackContext({ PAPERCLIP_STACK_SLUG: "stray-stack" })).toBeNull();
diff --git a/server/src/__tests__/health.test.ts b/server/src/__tests__/health.test.ts
index 1ff6587693..c04f448ab8 100644
--- a/server/src/__tests__/health.test.ts
+++ b/server/src/__tests__/health.test.ts
@@ -136,6 +136,29 @@ describe("GET /health", () => {
expect(Object.prototype.hasOwnProperty.call(res.body, "hiddenSettings")).toBe(false);
});
+ it("reveals staging experiments while retaining other Cloud settings restrictions", async () => {
+ const env = {
+ PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN: "tenant-token",
+ PAPERCLIP_PRIMARY_HOST: "team.paperclip.app",
+ PAPERCLIP_HIDDEN_SETTINGS: "instance.plugins,instance.experimental,instance.experimental.*",
+ };
+ const app = createApp(undefined, testServerInfo, undefined, env);
+ const production = await request(app).get("/health");
+ expect(production.body.hiddenSettings).toContain("instance.experimental");
+ expect(production.body.hiddenSettings).toContain("instance.experimental.enableChatConnectors");
+
+ env.PAPERCLIP_PRIMARY_HOST = "team.staging.paperclip.app";
+ const staging = await request(app).get("/health");
+ expect(staging.body.hiddenSettings).toContain("instance.plugins");
+ expect(staging.body.hiddenSettings).toContain("instance.experimental.enableManagedSandboxOnly");
+ expect(staging.body.hiddenSettings).toContain("instance.experimental.enableOwnerInstanceAdmin");
+ expect(staging.body.hiddenSettings).not.toContain("instance.experimental");
+ expect(staging.body.hiddenSettings).not.toContain("instance.experimental.enableChatConnectors");
+
+ env.PAPERCLIP_PRIMARY_HOST = "team.paperclip.app";
+ expect((await request(app).get("/health")).body.hiddenSettings).toEqual(production.body.hiddenSettings);
+ });
+
it("publishes concrete wildcard restrictions to the UI and refreshes changed exceptions", async () => {
const env = { PAPERCLIP_HIDDEN_SETTINGS: "instance.plugins,instance.experimental.*,!instance.experimental.enableEnvironments" };
const app = createApp(undefined, testServerInfo, undefined, env);
diff --git a/server/src/__tests__/instance-settings-managed-overlay.test.ts b/server/src/__tests__/instance-settings-managed-overlay.test.ts
index c6dfce4c64..60e7fbc824 100644
--- a/server/src/__tests__/instance-settings-managed-overlay.test.ts
+++ b/server/src/__tests__/instance-settings-managed-overlay.test.ts
@@ -6,6 +6,7 @@ import {
normalizeExperimentalSettings,
} from "../services/instance-settings.js";
import { parseManagedConfigEnv } from "../services/managed-config.js";
+import { evaluateExecutionAllowlist } from "../services/execution-allowlist.js";
const MANAGED_RAW = JSON.stringify({
v: 1,
@@ -82,6 +83,98 @@ describe("applyManagedExperimentalOverlay", () => {
});
describe("instanceSettingsService managed overlay", () => {
+ it("keeps sandbox policy enforced on staging after a tenant tries to disable it", async () => {
+ const row = settingsRow({ enableManagedSandboxOnly: false });
+ const { db, persistedSets } = stubDb(row);
+ const runtimeEnv = {
+ PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app",
+ ...managedEnv(JSON.stringify({
+ v: 1, mode: "cloud", catalogVersion: "test",
+ features: { enableManagedSandboxOnly: true }, plugins: { autoInstall: [] },
+ })),
+ };
+ const service = instanceSettingsService(db, { runtimeEnv });
+ const updated = await service.updateExperimental({ enableManagedSandboxOnly: false });
+ Object.assign(row, persistedSets.at(-1));
+ const restored = await instanceSettingsService(db, { runtimeEnv }).getExperimental();
+ for (const experimental of [updated.experimental, restored]) {
+ expect(experimental).toMatchObject({
+ enableManagedSandboxOnly: true,
+ managedKeys: { enableManagedSandboxOnly: { managed: true, managedBy: "paperclip-cloud" } },
+ });
+ expect(evaluateExecutionAllowlist(
+ { managedSandboxOnly: experimental.enableManagedSandboxOnly },
+ { driver: "local", provider: null },
+ )).toMatchObject({ allowed: false, deniedDriver: "local" });
+ }
+ });
+
+ it("lets staging override managed defaults, persists toggles, and preserves other defaults", async () => {
+ const row = settingsRow({});
+ const { db, persistedSets } = stubDb(row);
+ const runtimeEnv = {
+ ...managedEnv(JSON.stringify({
+ v: 1, mode: "cloud", catalogVersion: "test",
+ features: { enableStatusCards: true, enableChatConnectors: false, enableNativeRunner: true },
+ plugins: { autoInstall: [] },
+ })),
+ PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app",
+ };
+ const service = instanceSettingsService(db, { runtimeEnv });
+ expect(await service.getExperimental()).toMatchObject({
+ enableStatusCards: true, enableChatConnectors: false, enableNativeRunner: true, managedKeys: {},
+ });
+ expect(persistedSets).toHaveLength(0);
+
+ for (const enabled of [true, false]) {
+ const updated = await service.updateExperimental({ enableChatConnectors: enabled, enableNativeRunner: enabled });
+ Object.assign(row, persistedSets.at(-1));
+ const expected = {
+ enableStatusCards: true, enableChatConnectors: enabled, enableNativeRunner: enabled, managedKeys: {},
+ };
+ expect(updated.experimental).toMatchObject(expected);
+ const restored = instanceSettingsService(db, { runtimeEnv });
+ expect(await restored.getExperimental()).toMatchObject(expected);
+ expect((await restored.get()).experimental).toMatchObject(expected);
+ expect(row.experimental).not.toHaveProperty("managedKeys");
+ expect(row.experimental).not.toHaveProperty("enableStatusCards");
+ }
+
+ const changedDefaults = instanceSettingsService(db, { runtimeEnv: {
+ ...runtimeEnv,
+ PAPERCLIP_MANAGED_CONFIG: JSON.stringify({
+ v: 1, mode: "cloud", catalogVersion: "test",
+ features: { enableStatusCards: false, enableChatConnectors: true, enableNativeRunner: true },
+ plugins: { autoInstall: [] },
+ }),
+ } });
+ expect(await changedDefaults.getExperimental()).toMatchObject({
+ enableStatusCards: false, enableChatConnectors: false, enableNativeRunner: false,
+ });
+
+ const production = instanceSettingsService(db, { runtimeEnv: { ...runtimeEnv, PAPERCLIP_PRIMARY_HOST: "team.paperclip.app" } });
+ expect(await production.getExperimental()).toMatchObject({
+ enableChatConnectors: false, enableNativeRunner: true,
+ managedKeys: { enableChatConnectors: { managed: true }, enableNativeRunner: { managed: true } },
+ });
+ });
+
+ it("preserves Cloud owner access policy on staging", async () => {
+ const { db } = stubDb(settingsRow({ enableOwnerInstanceAdmin: false }));
+ const service = instanceSettingsService(db, { runtimeEnv: {
+ PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app",
+ ...managedEnv(JSON.stringify({
+ v: 1, mode: "cloud", catalogVersion: "test",
+ features: { enableOwnerInstanceAdmin: true }, plugins: { autoInstall: [] },
+ })),
+ } });
+ expect(await service.getExperimental()).toMatchObject({
+ enableOwnerInstanceAdmin: true,
+ managedKeys: { enableOwnerInstanceAdmin: { managed: true, managedBy: "paperclip-cloud" } },
+ });
+ expect((await service.updateExperimental({ enableOwnerInstanceAdmin: false })).experimental.enableOwnerInstanceAdmin).toBe(true);
+ });
+
it.each([{}, { enableMcpAggregators: false }])("keeps aggregators on with legacy stored and managed values: %j", async (stored) => {
const { db } = stubDb(settingsRow({ ...stored, enableChatConnectors: true }));
const service = instanceSettingsService(db, { runtimeEnv: managedEnv(JSON.stringify({
diff --git a/server/src/__tests__/instance-settings-routes.test.ts b/server/src/__tests__/instance-settings-routes.test.ts
index 14abf47810..033b74b724 100644
--- a/server/src/__tests__/instance-settings-routes.test.ts
+++ b/server/src/__tests__/instance-settings-routes.test.ts
@@ -857,6 +857,53 @@ describe("instance settings routes", () => {
});
});
+ describe("Cloud staging experiments", () => {
+ afterEach(() => vi.unstubAllEnvs());
+
+ it.each(["instance.experimental", "instance.experimental.*"])(
+ "keeps hidden Cloud sandbox policy protected when staging reveals %s",
+ async (hidden) => {
+ vi.stubEnv("PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN", "tenant-token");
+ vi.stubEnv("PAPERCLIP_PRIMARY_HOST", "team.staging.paperclip.app");
+ vi.stubEnv("PAPERCLIP_HIDDEN_SETTINGS", hidden);
+ mockInstanceSettingsService.getExperimental.mockResolvedValue({ enableManagedSandboxOnly: true });
+ const app = createApp(localAdminActor());
+ await request(app).patch("/api/instance/settings/experimental")
+ .send({ enableManagedSandboxOnly: false }).expect(403);
+ expect(mockInstanceSettingsService.updateExperimental).not.toHaveBeenCalled();
+ },
+ );
+
+ it("lets a staging admin change hidden experiments but keeps general settings locked", async () => {
+ vi.stubEnv("PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN", "tenant-token");
+ vi.stubEnv("PAPERCLIP_PRIMARY_HOST", "team.staging.paperclip.app");
+ vi.stubEnv("PAPERCLIP_HIDDEN_SETTINGS", "instance.experimental,instance.experimental.*,instance.general.censorUsernameInLogs");
+ const app = createApp({ type: "board", userId: "admin-1", source: "session", isInstanceAdmin: true });
+ await request(app).patch("/api/instance/settings/experimental").send({ enableChatConnectors: true }).expect(200);
+ expect(mockInstanceSettingsService.updateExperimental).toHaveBeenCalledWith({ enableChatConnectors: true });
+ await request(app).patch("/api/instance/settings/general").send({ censorUsernameInLogs: true }).expect(403);
+ expect(mockInstanceSettingsService.updateGeneral).not.toHaveBeenCalled();
+ });
+
+ it("keeps production locked even with a staging request hostname", async () => {
+ vi.stubEnv("PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN", "tenant-token");
+ vi.stubEnv("PAPERCLIP_PRIMARY_HOST", "team.paperclip.app");
+ vi.stubEnv("PAPERCLIP_HIDDEN_SETTINGS", "instance.experimental.*");
+ const app = createApp(localAdminActor());
+ await request(app).patch("/api/instance/settings/experimental")
+ .set("Host", "team.staging.paperclip.app").send({ enableChatConnectors: true }).expect(403);
+ expect(mockInstanceSettingsService.updateExperimental).not.toHaveBeenCalled();
+ });
+
+ it("still requires instance admin access on staging", async () => {
+ vi.stubEnv("PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN", "tenant-token");
+ vi.stubEnv("PAPERCLIP_PRIMARY_HOST", "team.staging.paperclip.app");
+ const app = createApp({ type: "board", userId: "member-1", source: "session", isInstanceAdmin: false });
+ await request(app).patch("/api/instance/settings/experimental").send({ enableChatConnectors: true }).expect(403);
+ expect(mockInstanceSettingsService.updateExperimental).not.toHaveBeenCalled();
+ });
+ });
+
describe("task drain", () => {
const adminActor = {
type: "board",
diff --git a/server/src/services/cloud-instance.ts b/server/src/services/cloud-instance.ts
index cdd3636969..5cde4dd8dd 100644
--- a/server/src/services/cloud-instance.ts
+++ b/server/src/services/cloud-instance.ts
@@ -1,4 +1,46 @@
import { createHash } from "node:crypto";
+import type { ManagedExperimentalFeatureKey } from "@paperclipai/shared";
+
+const CLOUD_STAGING_EXPERIMENTAL_KEYS: ReadonlySet<string> = new Set([
+ "autoRestartDevServerWhenIdle",
+ "enableAgentChat",
+ "enableBetaSkills",
+ "enableBuiltInAgents",
+ "enableCases",
+ "enableChatConnectors",
+ "enableClassicTaskInterface",
+ "enableCombinedInboxTasks",
+ "enableConferenceRoomChat",
+ "enableDecisions",
+ "enableEnvironments",
+ "enableExperimentalFileViewer",
+ "enableExternalObjects",
+ "enableFastResponses",
+ "enableFirstTaskPlanProposal",
+ "enableGitHubReviewBots",
+ "enableGoalsSidebarLink",
+ "enableGrokBot",
+ "enableIsolatedWorkspaces",
+ "enableIsolatedWorkspacesByDefault",
+ "enableIssuePlanDecompositions",
+ "enableMemoryConnectors",
+ "enableMuse",
+ "enableNativeRunner",
+ "enableOpenAiDot",
+ "enablePaperclipDeveloperMode",
+ "enablePublicMcp",
+ "enableServerInfoDebugView",
+ "enableSimplifiedEnglishInteractions",
+ "enableSmokeLab",
+ "enableStatusCards",
+ "enableStreamlinedUi",
+ "enableSummaries",
+ "enableWorktreeRunExecution",
+] satisfies ManagedExperimentalFeatureKey[]);
+
+export function isCloudStagingExperimentalSetting(key: string): boolean {
+ return CLOUD_STAGING_EXPERIMENTAL_KEYS.has(key);
+}
export type CloudInstanceEnv = Record<string, string | undefined>;
@@ -32,6 +74,11 @@ export function isCloudManagedInstance(
);
}
+export function isCloudStagingInstance(env: CloudInstanceEnv = process.env): boolean {
+ const host = normalizeOptionalEnvValue(env.PAPERCLIP_PRIMARY_HOST);
+ return isCloudManagedInstance(env) && host !== null && /^[a-z0-9-]+\.staging\.paperclip\.app$/i.test(host);
+}
+
/**
* Public stack metadata injected by the Paperclip Cloud provisioner.
*
diff --git a/server/src/services/instance-settings.ts b/server/src/services/instance-settings.ts
index 6b6a37a69c..642c67a31f 100644
--- a/server/src/services/instance-settings.ts
+++ b/server/src/services/instance-settings.ts
@@ -35,6 +35,7 @@ import {
import { eq } from "drizzle-orm";
import { getManagedInstanceConfig, type ManagedInstanceConfig } from "./managed-config.js";
import { getOperatorSettingDefaults } from "./setting-defaults.js";
+import { isCloudStagingExperimentalSetting, isCloudStagingInstance } from "./cloud-instance.js";
const DEFAULT_SINGLETON_KEY = "default";
const instanceGeneralSettingsStorageSchema = instanceGeneralSettingsSchema.strip();
@@ -435,6 +436,13 @@ export function instanceSettingsService(db: Db, options: InstanceSettingsService
// Fail closed: a malformed PAPERCLIP_MANAGED_CONFIG throws here (and at
// boot in index.ts) rather than silently running without the overlay.
const managedConfig = getManagedInstanceConfig(options.runtimeEnv ?? process.env);
+ const staging = isCloudStagingInstance(options.runtimeEnv ?? process.env);
+ const enforcedManagedConfig = staging && managedConfig
+ ? {
+ ...managedConfig,
+ features: Object.fromEntries(Object.entries(managedConfig.features).filter(([key]) => !isCloudStagingExperimentalSetting(key))),
+ }
+ : managedConfig;
// Same posture for PAPERCLIP_SETTING_DEFAULTS: parsed once, applied per
// read, never persisted (see applyOperatorGeneralDefaults) — including on
// the write path, where a full-GET echo of the overlaid value is stripped
@@ -446,9 +454,11 @@ export function instanceSettingsService(db: Db, options: InstanceSettingsService
}
function toExperimentalView(raw: unknown): InstanceExperimentalSettingsWithManaged {
+ const stored = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
+ const defaults = staging ? { ...managedConfig?.features, ...stored } : raw;
const { experimental, managedKeys } = applyManagedExperimentalOverlay(
- applyCloudCatalogDefaults(normalizeExperimentalSettings(raw), raw, managedConfig),
- managedConfig,
+ applyCloudCatalogDefaults(normalizeExperimentalSettings(defaults), defaults, managedConfig),
+ enforcedManagedConfig,
);
// Self-hosted responses stay byte-identical: no managedKeys field at all.
return managedConfig ? { ...experimental, managedKeys } : experimental;
@@ -568,12 +578,22 @@ export function instanceSettingsService(db: Db, options: InstanceSettingsService
const current = await getOrCreateRow();
// Guarded Cloud flags stay absent from the row unless chosen, so the
// read-time catalog default keeps applying (see stripCloudCatalogDefaultEchoes).
- const nextExperimental = stripCloudCatalogDefaultEchoes(
- current.experimental,
- patch,
- applyExperimentalSettingsPatch(current.experimental, patch, options),
- managedConfig,
- );
+ const nextExperimental = staging
+ ? applyExperimentalSettingsPatch(toExperimentalView(current.experimental), patch, options)
+ : stripCloudCatalogDefaultEchoes(
+ current.experimental,
+ patch,
+ applyExperimentalSettingsPatch(current.experimental, patch, options),
+ managedConfig,
+ );
+ if (staging) {
+ const stored = current.experimental as Record<string, unknown> | null;
+ for (const key of Object.keys(INSTANCE_FEATURE_CATALOG) as ManagedExperimentalFeatureKey[]) {
+ if (typeof stored?.[key] !== "boolean" && !Object.prototype.hasOwnProperty.call(patch, key)) {
+ delete nextExperimental[key];
+ }
+ }
+ }
const now = new Date();
const [updated] = await db
.update(instanceSettings)
diff --git a/server/src/services/settings-visibility.ts b/server/src/services/settings-visibility.ts
index 76ad0e83f4..561659776a 100644
--- a/server/src/services/settings-visibility.ts
+++ b/server/src/services/settings-visibility.ts
@@ -1,5 +1,6 @@
-import { parseHiddenSettingsList } from "@paperclipai/shared";
+import { experimentalSettingKey, INSTANCE_FEATURE_KEYS, parseHiddenSettingsList } from "@paperclipai/shared";
import { logger } from "../middleware/logger.js";
+import { isCloudStagingExperimentalSetting, isCloudStagingInstance } from "./cloud-instance.js";
/**
* Operator-hidden settings, from the `PAPERCLIP_HIDDEN_SETTINGS` env var
@@ -11,20 +12,14 @@ export const HIDDEN_SETTINGS_ENV_KEY = "PAPERCLIP_HIDDEN_SETTINGS";
export type HiddenSettingsEnv = Record<string, string | undefined>;
-let cache: { raw: string | undefined; hidden: ReadonlySet<string> } | null = null;
+let cache: { raw: string | undefined; staging: boolean; hidden: ReadonlySet<string> } | null = null;
-/**
- * Parse-once accessor keyed on the raw env value. Callers that pass a custom
- * env (tests) get a fresh parse whenever the raw value differs; process.env
- * callers share one parsed set for the process lifetime. Members are always
- * `HideableSettingKey`s; typed as strings so route code can probe with
- * computed `instance.*` keys.
- */
export function getHiddenSettings(
env: HiddenSettingsEnv = process.env,
): ReadonlySet<string> {
const raw = env[HIDDEN_SETTINGS_ENV_KEY];
- if (cache && cache.raw === raw) return cache.hidden;
+ const staging = isCloudStagingInstance(env);
+ if (cache && cache.raw === raw && cache.staging === staging) return cache.hidden;
const { hidden, unknown } = parseHiddenSettingsList(raw);
if (unknown.length > 0) {
logger.warn(
@@ -32,6 +27,12 @@ export function getHiddenSettings(
`${HIDDEN_SETTINGS_ENV_KEY} contains unknown keys; they are ignored`,
);
}
- cache = { raw, hidden: new Set(hidden) };
+ const visibleOnStaging = (key: string) =>
+ key === "instance.experimental"
+ || (key.startsWith("instance.experimental.") && isCloudStagingExperimentalSetting(key.slice("instance.experimental.".length)));
+ const expanded = staging && hidden.includes("instance.experimental")
+ ? [...hidden, ...INSTANCE_FEATURE_KEYS.map(experimentalSettingKey)]
+ : hidden;
+ cache = { raw, staging, hidden: new Set(staging ? expanded.filter((key) => !visibleOnStaging(key)) : hidden) };
return cache.hidden;
}