Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): gate bedrock provider routing behind a flag (#84774)

Chris Volzera789efb8c9d5
diff --git a/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts b/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts
index 30b0a172e40b..1da08ccbf69a 100644
--- a/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/claude-agent.ts
@@ -80,7 +80,11 @@ import { BaseAcpAgent } from "../base-acp-agent";
import { isLocalSkillCommandChunk } from "../local-skill";
import { LOCAL_TOOLS_MCP_NAME, type LocalToolCtx } from "../local-tools";
import { visiblePromptBlocks } from "../prompt-blocks";
-import { resolveSpokenNarration, resolveTaskId } from "../session-meta";
+import {
+ resolveBedrockGatewayVariant,
+ resolveSpokenNarration,
+ resolveTaskId,
+} from "../session-meta";
import {
buildBreakdown,
emptyBaseline,
@@ -2396,6 +2400,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
const environment = meta?.environment;
const channelMode = meta?.channelMode;
const spokenNarration = resolveSpokenNarration(meta);
+ const bedrockGatewayVariant = resolveBedrockGatewayVariant(meta);
const requestFinish = this.buildRequestFinish(taskId, meta?.taskRunId);
const buildInProcessMcpServers = (): Record<
string,
@@ -2506,6 +2511,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
taskState,
getCurrentModelId: () => this.session?.modelId,
gatewayEnv: this.options?.gatewayEnv,
+ bedrockGatewayVariant,
onTaskStateChange: async () => {
await this.client.sessionUpdate({
sessionId,
diff --git a/products/desktop/packages/agent/src/adapters/claude/session/options.test.ts b/products/desktop/packages/agent/src/adapters/claude/session/options.test.ts
index de17f5fdf484..a1313cef10ba 100644
--- a/products/desktop/packages/agent/src/adapters/claude/session/options.test.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/session/options.test.ts
@@ -376,6 +376,7 @@ describe("buildSessionOptions", () => {
name: "omits the project-scope header when POSTHOG_PROJECT_ID is unset",
projectId: undefined,
existingHeaders: undefined,
+ bedrockGatewayVariant: undefined,
expected: [
"x-posthog-property-$ai_session_id: test-session",
"x-posthog-use-bedrock-fallback: true",
@@ -385,6 +386,7 @@ describe("buildSessionOptions", () => {
name: "forwards POSTHOG_PROJECT_ID as the gateway project scope",
projectId: "42",
existingHeaders: undefined,
+ bedrockGatewayVariant: undefined,
expected: [
"X-PostHog-Project-Id: 42",
"x-posthog-property-$ai_session_id: test-session",
@@ -395,6 +397,7 @@ describe("buildSessionOptions", () => {
name: "preserves pre-existing custom headers ahead of the project-scope header",
projectId: "42",
existingHeaders: "x-posthog-property-task_id: task-abc",
+ bedrockGatewayVariant: undefined,
expected: [
"x-posthog-property-task_id: task-abc",
"X-PostHog-Project-Id: 42",
@@ -402,19 +405,46 @@ describe("buildSessionOptions", () => {
"x-posthog-use-bedrock-fallback: true",
].join("\n"),
},
- ])("$name", ({ projectId, existingHeaders, expected }) => {
- if (projectId !== undefined) {
- process.env.POSTHOG_PROJECT_ID = projectId;
- }
- if (existingHeaders !== undefined) {
- process.env.ANTHROPIC_CUSTOM_HEADERS = existingHeaders;
- }
+ {
+ name: "serves the session from Bedrock on the test variant, without the unreachable fallback header",
+ projectId: undefined,
+ existingHeaders: undefined,
+ bedrockGatewayVariant: "test" as const,
+ expected: [
+ "x-posthog-property-$ai_session_id: test-session",
+ "x-posthog-provider: bedrock",
+ "x-posthog-flag-bedrock-llm-gateway: test",
+ ].join("\n"),
+ },
+ {
+ name: "keeps the Bedrock failover and sends no provider header on the control variant",
+ projectId: undefined,
+ existingHeaders: undefined,
+ bedrockGatewayVariant: "control" as const,
+ expected: [
+ "x-posthog-property-$ai_session_id: test-session",
+ "x-posthog-use-bedrock-fallback: true",
+ "x-posthog-flag-bedrock-llm-gateway: control",
+ ].join("\n"),
+ },
+ ])(
+ "$name",
+ ({ projectId, existingHeaders, bedrockGatewayVariant, expected }) => {
+ if (projectId !== undefined) {
+ process.env.POSTHOG_PROJECT_ID = projectId;
+ }
+ if (existingHeaders !== undefined) {
+ process.env.ANTHROPIC_CUSTOM_HEADERS = existingHeaders;
+ }
- const headers = buildSessionOptions(makeParams()).env
- ?.ANTHROPIC_CUSTOM_HEADERS;
+ const headers = buildSessionOptions({
+ ...makeParams(),
+ bedrockGatewayVariant,
+ }).env?.ANTHROPIC_CUSTOM_HEADERS;
- expect(headers).toBe(expected);
- });
+ expect(headers).toBe(expected);
+ },
+ );
});
describe("gateway turn tracing env", () => {
diff --git a/products/desktop/packages/agent/src/adapters/claude/session/options.ts b/products/desktop/packages/agent/src/adapters/claude/session/options.ts
index 62f8587d5d72..d966630defc5 100644
--- a/products/desktop/packages/agent/src/adapters/claude/session/options.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/session/options.ts
@@ -12,6 +12,10 @@ import type {
SpawnedProcess,
SpawnOptions,
} from "@anthropic-ai/claude-agent-sdk";
+import {
+ BEDROCK_LLM_GATEWAY_FLAG,
+ type BedrockGatewayVariant,
+} from "@posthog/shared";
import {
buildPosthogProjectHeaderLines,
buildPosthogPropertyHeaderLines,
@@ -106,6 +110,8 @@ export interface BuildOptionsParams {
getCurrentModelId?: () => string | undefined;
/** Explicit gateway config — prevents global process.env mutation. */
gatewayEnv?: GatewayEnv;
+ /** Matched `bedrock-llm-gateway` variant; `test` serves this session from Bedrock. */
+ bedrockGatewayVariant?: BedrockGatewayVariant;
}
export function buildSystemPrompt(
@@ -159,6 +165,7 @@ function buildMcpServers(
function buildEnvironment(
gateway?: GatewayEnv,
sessionId?: string,
+ bedrockGatewayVariant?: BedrockGatewayVariant,
): Record<string, string> {
// Custom HTTP headers reach the model only through the Claude CLI subprocess,
// which reads them from this env var (newline-delimited `name: value` lines)
@@ -183,8 +190,25 @@ function buildEnvironment(
buildPosthogPropertyHeaderLines({ $ai_session_id: sessionId }),
);
}
- // Route to AWS Bedrock as a fallback when Anthropic returns 5xx
- headerLines.push("x-posthog-use-bedrock-fallback: true");
+ // The two Bedrock headers are mutually exclusive at the gateway: it dispatches
+ // on `x-posthog-provider: bedrock` and returns before it ever reads the
+ // fallback header, so sending both would imply a failover that cannot happen.
+ if (bedrockGatewayVariant === "test") {
+ // Serve the session from Bedrock outright. This path has no reverse
+ // fallback, so a Bedrock outage surfaces as an error instead of retrying
+ // against Anthropic.
+ headerLines.push("x-posthog-provider: bedrock");
+ } else {
+ // Fail over to Bedrock when Anthropic returns 5xx/429 or blocks on billing.
+ headerLines.push("x-posthog-use-bedrock-fallback: true");
+ }
+ if (bedrockGatewayVariant) {
+ // Stamps `$feature/bedrock-llm-gateway` onto the $ai_generation event the
+ // gateway captures, so test and control are comparable in analytics.
+ headerLines.push(
+ `x-posthog-flag-${BEDROCK_LLM_GATEWAY_FLAG}: ${bedrockGatewayVariant}`,
+ );
+ }
const customHeaders = headerLines.join("\n");
// SDK 0.3.142 made MCP servers connect in the background by default. That
@@ -513,7 +537,11 @@ export function buildSessionOptions(params: BuildOptionsParams): Options {
params.mcpServers,
loadUserClaudeJsonMcpServers(params.cwd, params.logger),
),
- env: buildEnvironment(params.gatewayEnv, params.sessionId),
+ env: buildEnvironment(
+ params.gatewayEnv,
+ params.sessionId,
+ params.bedrockGatewayVariant,
+ ),
hooks: buildHooks(
params.userProvidedOptions?.hooks,
params.onModeChange,
diff --git a/products/desktop/packages/agent/src/adapters/claude/types.ts b/products/desktop/packages/agent/src/adapters/claude/types.ts
index b95cfaacdfef..7053955835bf 100644
--- a/products/desktop/packages/agent/src/adapters/claude/types.ts
+++ b/products/desktop/packages/agent/src/adapters/claude/types.ts
@@ -10,6 +10,7 @@ import type {
Query,
SDKUserMessage,
} from "@anthropic-ai/claude-agent-sdk";
+import type { BedrockGatewayVariant } from "@posthog/shared";
import type { EffortLevel } from "@posthog/shared/domain-types";
import type { PostHogProductId } from "../../posthog-products";
import type { AgentMode } from "../../types";
@@ -233,6 +234,12 @@ export type NewSessionMeta = {
* emits always (consumers gate playback), local stays silent.
*/
spokenNarration?: boolean;
+ /**
+ * Matched `bedrock-llm-gateway` variant at session start. `test` serves the
+ * session from Bedrock through the gateway. Only the desktop resolves this,
+ * so headless runs leave it unset and keep the gateway's default provider.
+ */
+ bedrockGatewayVariant?: BedrockGatewayVariant;
jsonSchema?: Record<string, unknown> | null;
mcpToolApprovals?: McpToolApprovals;
posthogExecPermissionRegex?: string;
diff --git a/products/desktop/packages/agent/src/adapters/session-meta.ts b/products/desktop/packages/agent/src/adapters/session-meta.ts
index a4ccf9fdde35..9b0abffc34d0 100644
--- a/products/desktop/packages/agent/src/adapters/session-meta.ts
+++ b/products/desktop/packages/agent/src/adapters/session-meta.ts
@@ -1,3 +1,5 @@
+import type { BedrockGatewayVariant } from "@posthog/shared";
+
/** Minimal shape needed to resolve the effective task id from session meta. */
interface TaskIdSource {
taskId?: string;
@@ -35,3 +37,20 @@ export function resolveSpokenNarration(
): boolean {
return meta?.spokenNarration === true;
}
+
+/** Minimal shape needed to resolve the Bedrock gateway variant from meta. */
+interface BedrockGatewayVariantSource {
+ bedrockGatewayVariant?: BedrockGatewayVariant;
+}
+
+/**
+ * The desktop is the only client that evaluates the `bedrock-llm-gateway` flag,
+ * so every other caller (headless cloud runs, sandboxes) leaves this unset and
+ * keeps whatever provider the gateway defaults to. Shared by the Claude and
+ * Codex adapters.
+ */
+export function resolveBedrockGatewayVariant(
+ meta: BedrockGatewayVariantSource | undefined,
+): BedrockGatewayVariant | undefined {
+ return meta?.bedrockGatewayVariant;
+}
diff --git a/products/desktop/packages/core/src/sessions/sessionService.ts b/products/desktop/packages/core/src/sessions/sessionService.ts
index 9136c03979b7..0aee3b7e1218 100644
--- a/products/desktop/packages/core/src/sessions/sessionService.ts
+++ b/products/desktop/packages/core/src/sessions/sessionService.ts
@@ -21,6 +21,7 @@ import {
type AcpMessage,
type Adapter,
type AgentSession,
+ type BedrockGatewayVariant,
type CloudRegion,
classifyGatewayLimitError,
type ExecutionMode,
@@ -502,6 +503,7 @@ export interface SessionServiceDeps {
rtkEnabledCloud?: boolean;
spokenNotifications?: boolean;
spokenNarrationEnabled?: boolean;
+ bedrockGatewayVariant?: BedrockGatewayVariant;
};
usageLimit: { show: (...args: any[]) => any };
readonly addDirectoryDialog: { open: boolean };
@@ -2228,14 +2230,19 @@ export class SessionService {
this.d.log.warn("Failed to verify workspace", { taskId, err });
});
- const { customInstructions, rtkEnabledLocal, spokenNarrationEnabled } =
- this.d.settings;
+ const {
+ customInstructions,
+ rtkEnabledLocal,
+ spokenNarrationEnabled,
+ bedrockGatewayVariant,
+ } = this.d.settings;
const result = await this.d.trpc.agent.reconnect.mutate({
taskId,
taskRunId,
repoPath,
rtkEnabled: rtkEnabledLocal,
spokenNarration: spokenNarrationEnabled === true,
+ bedrockGatewayVariant,
apiHost: auth.apiHost,
projectId: auth.projectId,
logUrl,
@@ -2580,6 +2587,7 @@ export class SessionService {
customInstructions: startCustomInstructions,
rtkEnabledLocal,
spokenNarrationEnabled,
+ bedrockGatewayVariant,
} = this.d.settings;
const preferredModel = model ?? this.d.DEFAULT_GATEWAY_MODEL;
const result = await this.d.trpc.agent.start.mutate({
@@ -2593,6 +2601,7 @@ export class SessionService {
customInstructions: startCustomInstructions || undefined,
rtkEnabled: rtkEnabledLocal,
spokenNarration: spokenNarrationEnabled === true,
+ bedrockGatewayVariant,
effort: effortLevelSchema.safeParse(reasoningLevel).success
? (reasoningLevel as EffortLevel)
: undefined,
diff --git a/products/desktop/packages/shared/src/flags.ts b/products/desktop/packages/shared/src/flags.ts
index efa9d90ae88e..9b836c79ba96 100644
--- a/products/desktop/packages/shared/src/flags.ts
+++ b/products/desktop/packages/shared/src/flags.ts
@@ -54,3 +54,23 @@ export const ANNOUNCEMENTS_FLAG = "posthog-desktop-announcements";
export const SIGNALS_PR_REFUNDS_FLAG = "signals-pr-refunds";
/** Gates replacing Inbox report navigation with generated report canvases. */
export const REPORT_CANVAS_INBOX_FLAG = "posthog-desktop-report-canvases";
+
+/**
+ * Serves a session's Claude traffic from Bedrock instead of Anthropic. The
+ * `test` variant sends `x-posthog-provider: bedrock`, which the gateway routes
+ * to its Bedrock backend; `control` sends nothing and the gateway keeps its
+ * `anthropic` default.
+ *
+ * The variants differ in resilience, not just in provider. `control` keeps the
+ * gateway's Bedrock *failover* (`x-posthog-use-bedrock-fallback`), which retries
+ * against Bedrock when Anthropic returns 5xx/429 or blocks on billing. `test`
+ * cannot use it: the gateway dispatches on the provider header and returns
+ * before reading the fallback one, and its direct-Bedrock path has no reverse
+ * fallback to Anthropic. So a Bedrock outage fails a `test` session outright.
+ */
+export const BEDROCK_LLM_GATEWAY_FLAG = "bedrock-llm-gateway";
+
+/** Variants of {@link BEDROCK_LLM_GATEWAY_FLAG}. */
+export const BEDROCK_GATEWAY_VARIANTS = ["test", "control"] as const;
+
+export type BedrockGatewayVariant = (typeof BEDROCK_GATEWAY_VARIANTS)[number];
diff --git a/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts b/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts
index a5aedd4154d4..ad773d7c5e3a 100644
--- a/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts
+++ b/products/desktop/packages/ui/src/features/feature-flags/identifiers.ts
@@ -11,6 +11,13 @@ export interface FeatureFlags {
* consumption boundary — the shape is whatever was typed into PostHog.
*/
getPayload(flagKey: string): unknown;
+ /**
+ * Matched variant of a multivariate flag, or undefined when the flag is
+ * unmatched or flags haven't loaded. `isEnabled` cannot distinguish variants
+ * — every non-empty variant string is truthy, so a `control` user reads as
+ * enabled. Callers comparing against a specific variant must use this.
+ */
+ getVariant(flagKey: string): string | undefined;
onFlagsLoaded(handler: () => void): () => void;
}
diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx
index e1667248a761..abb7fb4837e4 100644
--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx
+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/UserMessage.test.tsx
@@ -14,6 +14,7 @@ function renderWithFlags(node: ReactNode, bluebirdEnabled: boolean) {
const flags: FeatureFlags = {
isEnabled: () => bluebirdEnabled,
getPayload: () => undefined,
+ getVariant: () => undefined,
onFlagsLoaded: () => () => {},
};
const container = new Container();
diff --git a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.recovery.integration.test.ts b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.recovery.integration.test.ts
index b7611bf8cc42..4d762672bbc9 100644
--- a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.recovery.integration.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.recovery.integration.test.ts
@@ -245,6 +245,7 @@ vi.mock("@posthog/ui/shell/posthogAnalyticsImpl", () => ({
buildPermissionToolMetadata: vi.fn(() => ({})),
posthogFeatureFlags: {
isEnabled: vi.fn(() => undefined),
+ getVariant: vi.fn(() => undefined),
onFlagsLoaded: vi.fn(),
},
}));
diff --git a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts
index 6bc4913c17d7..3b08ab6cd71a 100644
--- a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts
+++ b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.test.ts
@@ -272,6 +272,7 @@ const mockAgentSessionNotifier = vi.hoisted(() => ({
const mockFeatureFlags = vi.hoisted(() => ({
isEnabled: vi.fn(() => false),
+ getVariant: vi.fn((): string | undefined => undefined),
onFlagsLoaded: vi.fn(() => vi.fn()),
}));
@@ -311,6 +312,7 @@ vi.mock("@posthog/ui/shell/posthogAnalyticsImpl", () => ({
buildPermissionToolMetadata: vi.fn(() => ({})),
posthogFeatureFlags: {
isEnabled: vi.fn(() => undefined),
+ getVariant: vi.fn(() => undefined),
onFlagsLoaded: vi.fn(),
},
}));
diff --git a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.ts b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.ts
index 54b8b334a2b6..5395ebddb434 100644
--- a/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.ts
+++ b/products/desktop/packages/ui/src/features/sessions/sessionServiceHost.ts
@@ -19,7 +19,12 @@ import {
HOST_TRPC_CLIENT,
type HostTrpcClient,
} from "@posthog/host-router/client";
-import { SPOKEN_NARRATION_FLAG } from "@posthog/shared";
+import {
+ BEDROCK_GATEWAY_VARIANTS,
+ BEDROCK_LLM_GATEWAY_FLAG,
+ type BedrockGatewayVariant,
+ SPOKEN_NARRATION_FLAG,
+} from "@posthog/shared";
import {
createAuthenticatedClient,
getAuthenticatedClient,
@@ -69,6 +74,30 @@ export function shouldEnableSpokenNarration(
return userOptedIn && (flagEnabled || isDevelopment);
}
+/**
+ * Narrow the raw flag value to a known variant. An unmatched flag, an
+ * unresolved one, or a variant added in PostHog that this build does not know
+ * about all yield undefined, which leaves the session on the gateway's default
+ * provider rather than guessing.
+ *
+ * posthog-js resolves flags asynchronously, so a session started before the
+ * first load finishes reads undefined and runs on Anthropic. That window is
+ * effectively the first launch after install, because posthog-js restores
+ * cached flags from its persistence layer on init, and this flag matches on
+ * `email`, which only exists once `identify` runs.
+ *
+ * An unresolved variant is deliberately not treated as `control`: the session
+ * sends no `$feature/` property at all, so it drops out of both arms instead of
+ * inflating control. That keeps the comparison honest at the cost of losing a
+ * few early sessions. Waiting for flags here would put a network round trip in
+ * front of every session start and reconnect, which is a worse trade.
+ */
+export function resolveBedrockGatewayVariant(
+ rawVariant: string | undefined,
+): BedrockGatewayVariant | undefined {
+ return BEDROCK_GATEWAY_VARIANTS.find((variant) => variant === rawVariant);
+}
+
function hostClient(): HostTrpcClient {
return resolveService<HostTrpcClient>(HOST_TRPC_CLIENT);
}
@@ -132,6 +161,11 @@ function buildSessionServiceDeps(): SessionServiceDeps {
),
import.meta.env.DEV,
),
+ bedrockGatewayVariant: resolveBedrockGatewayVariant(
+ resolveService<FeatureFlags>(FEATURE_FLAGS).getVariant(
+ BEDROCK_LLM_GATEWAY_FLAG,
+ ),
+ ),
};
},
usageLimit: {
diff --git a/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts b/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
index eb353fefb3bb..2927e3fba1b8 100644
--- a/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
+++ b/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
@@ -409,6 +409,20 @@ export function getFeatureFlagPayload(flagKey: string): unknown {
return posthog.getFeatureFlagPayload(flagKey);
}
+/**
+ * Matched variant of a multivariate flag; undefined when uninitialized or
+ * unmatched. posthog-js returns `true` for a boolean flag rather than a variant
+ * name, so only string values pass through.
+ */
+export function getFeatureFlagVariant(flagKey: string): string | undefined {
+ if (!isInitialized) {
+ return undefined;
+ }
+
+ const value = posthog.getFeatureFlag(flagKey);
+ return typeof value === "string" ? value : undefined;
+}
+
/**
* Reload feature flags from the server.
* Useful after a person property change (e.g., invite code redemption).
@@ -441,6 +455,7 @@ export const posthogAnalyticsTracker: AnalyticsTracker = {
export const posthogFeatureFlags: FeatureFlags = {
isEnabled: isFeatureFlagEnabled,
getPayload: getFeatureFlagPayload,
+ getVariant: getFeatureFlagVariant,
onFlagsLoaded: onFeatureFlagsLoaded,
};
diff --git a/products/desktop/packages/workspace-server/src/services/agent/agent.ts b/products/desktop/packages/workspace-server/src/services/agent/agent.ts
index 5f375b217685..c6f7bfdf2f57 100644
--- a/products/desktop/packages/workspace-server/src/services/agent/agent.ts
+++ b/products/desktop/packages/workspace-server/src/services/agent/agent.ts
@@ -65,6 +65,7 @@ import {
import {
type AcpMessage,
type Adapter,
+ type BedrockGatewayVariant,
buildCloudTaskConfigOptions,
type CloudRegion,
type ExecutionMode,
@@ -296,6 +297,8 @@ interface SessionConfig {
rtkEnabled?: boolean;
/** The user's spoken-narration setting at session start. */
spokenNarration?: boolean;
+ /** Matched `bedrock-llm-gateway` variant at session start. */
+ bedrockGatewayVariant?: BedrockGatewayVariant;
}
/** Pull the adapter's `agentCapabilities._meta.posthog.steering` from initialize. */
@@ -1035,6 +1038,9 @@ If a repository is required, call \`list_repos\` to find it, then use \`clone_re
...(config.spokenNarration !== undefined && {
spokenNarration: config.spokenNarration,
}),
+ ...(config.bedrockGatewayVariant !== undefined && {
+ bedrockGatewayVariant: config.bedrockGatewayVariant,
+ }),
mcpToolApprovals: toolApprovals,
...(permissionMode && { permissionMode }),
...(model != null && { model }),
@@ -1120,6 +1126,9 @@ If a repository is required, call \`list_repos\` to find it, then use \`clone_re
...(config.spokenNarration !== undefined && {
spokenNarration: config.spokenNarration,
}),
+ ...(config.bedrockGatewayVariant !== undefined && {
+ bedrockGatewayVariant: config.bedrockGatewayVariant,
+ }),
mcpToolApprovals: toolApprovals,
...(permissionMode && { permissionMode }),
...(model != null && { model }),
@@ -1151,6 +1160,9 @@ If a repository is required, call \`list_repos\` to find it, then use \`clone_re
...(config.spokenNarration !== undefined && {
spokenNarration: config.spokenNarration,
}),
+ ...(config.bedrockGatewayVariant !== undefined && {
+ bedrockGatewayVariant: config.bedrockGatewayVariant,
+ }),
mcpToolApprovals: toolApprovals,
...(permissionMode && { permissionMode }),
...(model != null && { model }),
@@ -2195,6 +2207,10 @@ For git operations while detached:
rtkEnabled: "rtkEnabled" in params ? params.rtkEnabled : undefined,
spokenNarration:
"spokenNarration" in params ? params.spokenNarration : undefined,
+ bedrockGatewayVariant:
+ "bedrockGatewayVariant" in params
+ ? params.bedrockGatewayVariant
+ : undefined,
};
}
diff --git a/products/desktop/packages/workspace-server/src/services/agent/schemas.ts b/products/desktop/packages/workspace-server/src/services/agent/schemas.ts
index 977d384bdcac..14d1cd3ba438 100644
--- a/products/desktop/packages/workspace-server/src/services/agent/schemas.ts
+++ b/products/desktop/packages/workspace-server/src/services/agent/schemas.ts
@@ -2,6 +2,7 @@ import type {
RequestPermissionRequest,
PermissionOption as SdkPermissionOption,
} from "@agentclientprotocol/sdk";
+import { BEDROCK_GATEWAY_VARIANTS } from "@posthog/shared";
import { effortLevelSchema } from "@posthog/shared/domain-types";
import { z } from "zod";
import { USER_AGENT_INSTRUCTIONS_MAX_LENGTH } from "../os/schemas";
@@ -101,6 +102,12 @@ export const startSessionInput = z.object({
* narration off, so headless runs never load the tool.
*/
spokenNarration: z.boolean().optional(),
+ /**
+ * Matched variant of the `bedrock-llm-gateway` flag. `test` serves this
+ * session from Bedrock via the gateway; `control` keeps Anthropic. Absent
+ * (headless runs, unresolved flags) leaves the gateway on its default.
+ */
+ bedrockGatewayVariant: z.enum(BEDROCK_GATEWAY_VARIANTS).optional(),
});
export type StartSessionInput = z.infer<typeof startSessionInput>;
@@ -242,6 +249,8 @@ export const reconnectSessionInput = z.object({
rtkEnabled: z.boolean().optional(),
/** See startSessionInput.spokenNarration. */
spokenNarration: z.boolean().optional(),
+ /** See startSessionInput.bedrockGatewayVariant. */
+ bedrockGatewayVariant: z.enum(BEDROCK_GATEWAY_VARIANTS).optional(),
});
export type ReconnectSessionInput = z.infer<typeof reconnectSessionInput>;