Skip to content

Commit fa24347

Browse files
t3dotggclaude
andcommitted
refactor: gate prompt suggestions behind one Labs setting
Suggestions spend plan usage, so replace the default-on per-provider switches with a server-scoped Labs flag (off by default) that the session manager passes to adapters when a provider session opens. Codex now also samples after background work and after a held goal completes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cdcf07a commit fa24347

14 files changed

Lines changed: 77 additions & 76 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
28812881
readonly freshQueueOnReopen?: boolean;
28822882
readonly forkSession?: ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerShape["forkSession"];
28832883
readonly allocateSessionId?: Effect.Effect<string>;
2884+
readonly promptSuggestions?: boolean;
28842885
}) =>
28852886
Effect.gen(function* () {
28862887
const fileSystem = yield* FileSystem.FileSystem;
@@ -3039,6 +3040,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
30393040
providerSessionId: ProviderSessionId.make("provider-session-claude-wake"),
30403041
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
30413042
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
3043+
promptSuggestions: options?.promptSuggestions === true,
30423044
});
30433045
const providerThread = yield* runtime.ensureThread({
30443046
threadId,
@@ -6568,7 +6570,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
65686570

65696571
it.effect("offers the prompt suggestion Claude sends after a completed turn", () =>
65706572
Effect.gen(function* () {
6571-
const harness = yield* makeWakeHarness;
6573+
const harness = yield* makeWakeHarnessWithOptions({ promptSuggestions: true });
65726574
const input = makeClaudeTestTurnInput({
65736575
threadId: harness.threadId,
65746576
providerThread: harness.providerThread,

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,7 @@ export function makeClaudeQueryOptions(input: {
14661466
readonly cwd: string | null;
14671467
readonly attachmentsDir?: string;
14681468
readonly settings?: ClaudeSettings;
1469+
readonly promptSuggestions?: boolean;
14691470
readonly sdkSettings?: string | ClaudeSdkSettings;
14701471
readonly environment?: NodeJS.ProcessEnv;
14711472
readonly mcpServers?: ClaudeQueryOptions["mcpServers"];
@@ -1548,7 +1549,7 @@ export function makeClaudeQueryOptions(input: {
15481549
? "bypassPermissions"
15491550
: (input.permissionMode ?? "default")),
15501551
includePartialMessages: true,
1551-
promptSuggestions: input.settings?.promptSuggestions ?? true,
1552+
promptSuggestions: input.promptSuggestions === true,
15521553
...(compiledSelection.effort === undefined
15531554
? {}
15541555
: {
@@ -4677,6 +4678,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
46774678
}),
46784679
openSession: Effect.fn("ClaudeAdapterV2.openSession")(
46794680
function* (input: ProviderAdapter.ProviderAdapterV2OpenSessionInput) {
4681+
const promptSuggestionsEnabled = input.promptSuggestions === true;
46804682
const sessionScope = yield* Effect.scope;
46814683
const now = yield* DateTime.now;
46824684
const session = providerSession({
@@ -10235,6 +10237,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1023510237
cwd: turnInput.runtimePolicy.cwd,
1023610238
attachmentsDir,
1023710239
settings: adapterOptions.settings,
10240+
promptSuggestions: promptSuggestionsEnabled,
1023810241
...(launchArgSettings === undefined
1023910242
? {}
1024010243
: { sdkSettings: claudeSdkLaunchArgSettings(launchArgSettings) }),

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,7 @@ describe("CodexAdapterV2 fork boundary", () => {
476476
);
477477
});
478478

479-
// Replays fail on unscripted frames; tests that cover suggestions opt back in.
480-
const DEFAULT_CODEX_SETTINGS = Schema.decodeSync(CodexSettings)({ promptSuggestions: false });
481-
const PROMPT_SUGGESTION_CODEX_SETTINGS = Schema.decodeSync(CodexSettings)({});
479+
const DEFAULT_CODEX_SETTINGS = Schema.decodeSync(CodexSettings)({});
482480
const CODEX_TEST_MODEL_SELECTION = {
483481
instanceId: CodexAdapterV2.CODEX_DEFAULT_INSTANCE_ID,
484482
model: "gpt-5.4",
@@ -1144,7 +1142,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
11441142
onRequest: (method: string, params: unknown) => Effect.Effect<void> = () => Effect.void,
11451143
readChildMetadata?: Parameters<typeof withCodexReplayChildMetadata>[2],
11461144
beforeEmitInbound?: CodexReplay.CodexAppServerReplayDriver["beforeEmitInbound"],
1147-
settings: CodexSettings = DEFAULT_CODEX_SETTINGS,
1145+
promptSuggestions = false,
11481146
) =>
11491147
Effect.gen(function* () {
11501148
const fileSystem = yield* FileSystem.FileSystem;
@@ -1192,7 +1190,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
11921190
};
11931191
const adapter = yield* CodexAdapterV2.makeCodexAdapterV2({
11941192
instanceId: CodexAdapterV2.CODEX_DEFAULT_INSTANCE_ID,
1195-
settings,
1193+
settings: DEFAULT_CODEX_SETTINGS,
11961194
environment: {},
11971195
clientFactory,
11981196
crypto: yield* Crypto.Crypto,
@@ -1212,6 +1210,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
12121210
providerSessionId: ProviderSessionId.make(`provider-session-${transcript.scenario}`),
12131211
modelSelection: CODEX_TEST_MODEL_SELECTION,
12141212
runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
1213+
promptSuggestions,
12151214
});
12161215
const providerThread = yield* runtime.ensureThread({
12171216
threadId,
@@ -1755,7 +1754,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
17551754
undefined,
17561755
undefined,
17571756
undefined,
1758-
PROMPT_SUGGESTION_CODEX_SETTINGS,
1757+
true,
17591758
);
17601759
const turnInput = makeCodexTestTurnInput({
17611760
threadId: harness.threadId,

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.testkit.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import {
2020
import type { ProviderReplayGate } from "@t3tools/provider-testing/replayGate";
2121
import * as CodexAdapterV2 from "./CodexAdapterV2.ts";
2222

23-
// Replays fail on unscripted frames; tests that cover suggestions opt back in.
24-
const DEFAULT_CODEX_SETTINGS = Schema.decodeSync(CodexSettings)({ promptSuggestions: false });
23+
const DEFAULT_CODEX_SETTINGS = Schema.decodeSync(CodexSettings)({});
2524

2625
export class CodexReplayTranscriptDecodeError extends Schema.TaggedError<CodexReplayTranscriptDecodeError>()(
2726
"CodexReplayTranscriptDecodeError",

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
19241924
const emitProviderEvent = (event: ProviderAdapter.ProviderAdapterV2Event) =>
19251925
Queue.offer(events, event).pipe(Effect.asVoid);
19261926

1927-
const promptSuggestionsEnabled = (resolvedRuntime?.config ?? adapterOptions.settings)
1928-
.promptSuggestions;
1927+
const promptSuggestionsEnabled = input.promptSuggestions === true;
19291928
// Best effort: older Codex lacks thread/sample, and a sample fails once the user sends again.
19301929
const samplePromptSuggestion = (
19311930
context: ActiveCodexTurnContext,
@@ -5955,6 +5954,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
59555954
});
59565955
yield* emitRootTerminal(hold.context, { ...hold.event, status });
59575956
yield* Deferred.succeed(hold.next, undefined);
5957+
const nativeThreadId = hold.context.providerThread.nativeThreadRef?.nativeId;
5958+
if (promptSuggestionsEnabled && status === "completed" && nativeThreadId != null) {
5959+
yield* samplePromptSuggestion(hold.context, nativeThreadId, hold.context.nativeTurnId);
5960+
}
59585961
});
59595962

59605963
const releaseGoalHold = Effect.fnUntraced(function* (
@@ -6282,14 +6285,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
62826285
const retainSettledContext =
62836286
input.status === "completed" &&
62846287
(yield* turnHasRetainedBackgroundWork(input.nativeTurnId));
6285-
// Predict only once the run is done: not mid-goal and not while background work runs.
6288+
// A held goal predicts when settleGoalHold completes it.
62866289
if (
62876290
promptSuggestionsEnabled &&
62886291
input.status === "completed" &&
62896292
input.context.subagent === null &&
62906293
!input.continueRun &&
62916294
!holdsForGoal &&
6292-
!retainSettledContext &&
62936295
nativeThreadId != null
62946296
) {
62956297
yield* samplePromptSuggestion(input.context, nativeThreadId, input.nativeTurnId);

‎apps/server/src/orchestration-v2/ProviderSessionManager.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,20 @@ export const layerWithOptions = (
350350
const projectService = yield* Effect.serviceOption(ProjectService.ProjectService);
351351
const eventSink = yield* EventSink.EventSinkV2;
352352
const commandOutput = yield* CommandOutputHub.CommandOutputHub;
353-
const promptSuggestions = yield* SubscriptionRef.make<
353+
const promptSuggestionStore = yield* SubscriptionRef.make<
354354
ReadonlyMap<ThreadId, NonNullable<OrchestrationV2PromptSuggestion>>
355355
>(new Map());
356356
const idAllocator = yield* IdAllocator.IdAllocatorV2;
357357
const providerEventIngestor = yield* ProviderEventIngestor.ProviderEventIngestorV2;
358358
const projectionStore = yield* ProjectionStore.ProjectionStoreV2;
359359
const agentScope = yield* AgentScope;
360+
// Labs flag, read once per provider session; unreadable settings keep it off.
361+
const promptSuggestionsEnabled = Option.isNone(serverSettings)
362+
? Effect.succeed(false)
363+
: serverSettings.value.getSettings.pipe(
364+
Effect.map((settings) => settings.promptSuggestionsEnabled),
365+
Effect.orElseSucceed(() => false),
366+
);
360367
const agentAccessSettings = Effect.fn("ProviderSessionManagerV2.agentAccessSettings")(
361368
function* (threadId: ThreadId) {
362369
if (Option.isNone(serverSettings)) return { browser: true, device: false };
@@ -1961,7 +1968,7 @@ export const layerWithOptions = (
19611968
return commandOutput.append(event);
19621969
}
19631970
if (event.type === "prompt_suggestion.updated") {
1964-
return SubscriptionRef.update(promptSuggestions, (current) => {
1971+
return SubscriptionRef.update(promptSuggestionStore, (current) => {
19651972
const next = new Map(current);
19661973
next.delete(event.threadId);
19671974
next.set(event.threadId, { runId: event.runId, text: event.text });
@@ -2202,12 +2209,14 @@ export const layerWithOptions = (
22022209
});
22032210
const sessionScope = yield* Scope.fork(sessionScopes);
22042211
yield* agentScope.clear(input.threadId);
2212+
const promptSuggestions = yield* promptSuggestionsEnabled;
22052213
const runtime = yield* adapter
22062214
.openSession({
22072215
threadId: input.threadId,
22082216
providerSessionId: input.providerSessionId,
22092217
modelSelection: input.modelSelection,
22102218
runtimePolicy: input.runtimePolicy,
2219+
promptSuggestions,
22112220
...(input.resumeFromSession === undefined
22122221
? {}
22132222
: { resumeFromSession: input.resumeFromSession }),
@@ -2581,7 +2590,7 @@ export const layerWithOptions = (
25812590
),
25822591
),
25832592
subscribePromptSuggestion: (threadId) =>
2584-
SubscriptionRef.changes(promptSuggestions).pipe(
2593+
SubscriptionRef.changes(promptSuggestionStore).pipe(
25852594
Stream.map((suggestions) => suggestions.get(threadId) ?? null),
25862595
Stream.changes,
25872596
),

‎apps/server/src/provider/ProviderInstanceRegistry.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const makeCodexConfig = (overrides: Partial<CodexSettings>): CodexSettings => ({
9898
shadowHomePath: "",
9999
launchArgs: "",
100100
customModels: [],
101-
promptSuggestions: true,
102101
...overrides,
103102
});
104103

@@ -110,7 +109,6 @@ const makeClaudeConfig = (overrides: Partial<ClaudeSettings>): ClaudeSettings =>
110109
launchArgs: "",
111110
autoCompactWindow: "",
112111
idleCompaction: "default",
113-
promptSuggestions: true,
114112
...overrides,
115113
});
116114

‎apps/web/src/components/settings/LabsSettingsPanel.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function LabsSettingsPanel() {
2121
{/* Clerk is only mounted when this build has T3 Connect. */}
2222
{hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
2323
<LinkedEnvironmentsRow />
24+
<PromptSuggestionsRow />
2425
<SimlockHostsRow />
2526
</SettingsSection>
2627
<LegacyFeaturesSection />
@@ -150,6 +151,29 @@ function LinkedEnvironmentsRow() {
150151
);
151152
}
152153

154+
function PromptSuggestionsRow() {
155+
const settings = useScopedSettings();
156+
const updateSettings = useUpdateScopedSettings();
157+
return (
158+
<SettingsRow
159+
serverScoped
160+
{...searchableSetting("prompt-suggestions-beta")}
161+
settingKeys={["promptSuggestionsEnabled"]}
162+
description="After a Claude or Codex turn, show a predicted next message in the empty composer. Press Tab to use it. Each suggestion is one extra cached request, so it uses some of your plan. Applies to new sessions."
163+
control={
164+
<ScopedSwitch
165+
settingKeys={["promptSuggestionsEnabled"]}
166+
checked={settings.promptSuggestionsEnabled}
167+
onCheckedChange={(checked) =>
168+
updateSettings({ promptSuggestionsEnabled: Boolean(checked) })
169+
}
170+
aria-label="Suggest next prompt"
171+
/>
172+
}
173+
/>
174+
);
175+
}
176+
153177
function SimlockHostsRow() {
154178
const settings = useScopedSettings();
155179
const updateSettings = useUpdateScopedSettings();

‎apps/web/src/components/settings/ProviderInstanceCard.tsx‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,25 +1283,7 @@ export function ProviderInstanceCard({
12831283
title="Runtime"
12841284
headerPlacement="outside"
12851285
>
1286-
{runtime === undefined ? (
1287-
runtimeFields
1288-
) : (
1289-
<>
1290-
{runtime}
1291-
{driverOption ? (
1292-
// Managed Codex owns its paths; its behavior switches stay editable.
1293-
<ProviderSettingsForm
1294-
definition={driverOption}
1295-
value={instance.config}
1296-
idPrefix={`provider-instance-${instanceId}`}
1297-
variant="settings"
1298-
onChange={updateConfig}
1299-
environmentId={environmentId}
1300-
fieldKeys={["promptSuggestions"]}
1301-
/>
1302-
) : null}
1303-
</>
1304-
)}
1286+
{runtime ?? runtimeFields}
13051287
</FoldedSettingsSection>
13061288
</div>
13071289
) : !driverOption || deriveProviderSettingsFields(driverOption).length > 0 ? (

‎apps/web/src/components/settings/ProviderSettingsForm.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ interface ProviderSettingsFormProps {
326326
readonly onChange: (nextConfig: Record<string, unknown> | undefined) => void;
327327
/** Where the secret providers offered for `SettingsSecretValue` fields are configured. */
328328
readonly environmentId?: EnvironmentId | undefined;
329-
/** Render only these fields; omit to render every visible field. */
330-
readonly fieldKeys?: ReadonlyArray<string>;
331329
}
332330

333331
function SecretSettingsControl({
@@ -663,11 +661,8 @@ export function ProviderSettingsForm({
663661
variant,
664662
onChange,
665663
environmentId,
666-
fieldKeys,
667664
}: ProviderSettingsFormProps) {
668-
const fields = deriveProviderSettingsFields(definition, value).filter(
669-
(field) => fieldKeys === undefined || fieldKeys.includes(field.key),
670-
);
665+
const fields = deriveProviderSettingsFields(definition, value);
671666
const isLocalAcp =
672667
definition.driverKind === "acpRegistry" &&
673668
readProviderConfigString(value, "source") === "local";

0 commit comments

Comments
 (0)