@@ -1034,6 +1034,22 @@ const FAST_MODE_BETA = "fast-mode-2026-02-01";
10341034
10351035export { modelSupportsFastMode } from "../model/pi-models.ts" ;
10361036
1037+ /**
1038+ * Whether a turn should run in fast mode.
1039+ *
1040+ * Fast mode is OPT-IN: only an explicit `true` selects it. An unset `fastMode` means the
1041+ * caller expressed no preference, and treating that as "yes" bills the turn against a tier
1042+ * it never asked for — or fails it outright on an organization with no fast-mode quota,
1043+ * where the provider answers `rate_limit_error: … 0 fast mode input tokens per minute`.
1044+ *
1045+ * Only the web UI ever sets the field today, so every other entry point (CLI, API clients,
1046+ * integrations) leaves it undefined. `claude-harness` already reads it as opt-in
1047+ * (`turn.fastMode && …`); this keeps both harnesses agreeing on the same default.
1048+ */
1049+ export function wantsFastMode ( fastMode : boolean | undefined , modelId : string | undefined ) : boolean {
1050+ return fastMode === true && modelSupportsFastMode ( modelId ) ;
1051+ }
1052+
10371053export const TURN_PROVIDER_EFFORT_ALIASES : Record < string , string | null > = {
10381054 max : "max" ,
10391055 ultracode : "max" ,
@@ -1447,7 +1463,7 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {
14471463 entry . ref . toolApprovalGate = turn . toolApprovalGate ;
14481464
14491465 const desiredModelId = turn . model ?? resolveModelId ( turn . scopeLabel ) ;
1450- const wantFast = turn . fastMode !== false && modelSupportsFastMode ( desiredModelId ) ;
1466+ const wantFast = wantsFastMode ( turn . fastMode , desiredModelId ) ;
14511467 const current = entry . agentSession . model as { id ?: string ; headers ?: Record < string , string > } | undefined ;
14521468 const currentFast = Boolean ( current ?. headers ?. [ "anthropic-beta" ] ?. includes ( FAST_MODE_BETA ) ) ;
14531469 if ( current ?. id !== desiredModelId || currentFast !== wantFast ) {
@@ -1707,7 +1723,7 @@ export function createPiHarness(opts?: PiHarnessOptions): Harness {
17071723 console . error (
17081724 `[pi] provider refusal — retrying on fallback model ${ fromId } -> ${ fallbackId } session=${ turn . session . id } : ${ refusal } ` ,
17091725 ) ;
1710- const wantFast = turn . fastMode !== false && modelSupportsFastMode ( fallbackId ) ;
1726+ const wantFast = wantsFastMode ( turn . fastMode , fallbackId ) ;
17111727 await entry . agentSession . setModel ( wantFast ? withFastModeHeaders ( fallback ) : fallback ) ;
17121728 const active = entry . agentSession . model as { headers ?: Record < string , string > } | undefined ;
17131729 entry . ref . fast = Boolean ( active ?. headers ?. [ "anthropic-beta" ] ?. includes ( FAST_MODE_BETA ) ) ;
0 commit comments