From 0ec3b79c07973e746328a1d6e1be5057096029af Mon Sep 17 00:00:00 2001 From: Neerav Makwana <261249544+neeravmakwana@users.noreply.github.com> Date: Fri, 24 Apr 2026 22:47:35 -0400 Subject: [PATCH] refactor: reuse model-id prefix helper for Gemini guard --- src/agents/execution-contract.ts | 2 +- .../pi-embedded-runner/run/incomplete-turn.ts | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/agents/execution-contract.ts b/src/agents/execution-contract.ts index bb3d72b822d..ab9c9bea273 100644 --- a/src/agents/execution-contract.ts +++ b/src/agents/execution-contract.ts @@ -14,7 +14,7 @@ import { resolveAgentExecutionContract, resolveSessionAgentIds } from "./agent-s * bare names. The adversarial review in #64227 flagged this as a quality * gap on completion-gate criterion 1. */ -function stripProviderPrefix(modelId: string): string { +export function stripProviderPrefix(modelId: string): string { const normalizedModelId = modelId.trim(); const match = /^([^/:]+)[/:](.+)$/.exec(normalizedModelId); return (match?.[2] ?? normalizedModelId).toLowerCase(); diff --git a/src/agents/pi-embedded-runner/run/incomplete-turn.ts b/src/agents/pi-embedded-runner/run/incomplete-turn.ts index 1b9429eb23a..0e8dba07f82 100644 --- a/src/agents/pi-embedded-runner/run/incomplete-turn.ts +++ b/src/agents/pi-embedded-runner/run/incomplete-turn.ts @@ -2,7 +2,10 @@ import type { AgentMessage } from "@mariozechner/pi-agent-core"; import { isSilentReplyPayloadText, SILENT_REPLY_TOKEN } from "../../../auto-reply/tokens.js"; import type { EmbeddedPiExecutionContract } from "../../../config/types.agent-defaults.js"; import { normalizeLowercaseStringOrEmpty } from "../../../shared/string-coerce.js"; -import { isStrictAgenticSupportedProviderModel } from "../../execution-contract.js"; +import { + isStrictAgenticSupportedProviderModel, + stripProviderPrefix, +} from "../../execution-contract.js"; import { isLikelyMutatingToolName } from "../../tool-mutation.js"; import { assessLastAssistantMessage } from "../thinking.js"; import type { EmbeddedRunLivenessState } from "../types.js"; @@ -83,7 +86,7 @@ const GEMINI_INCOMPLETE_TURN_PROVIDER_IDS = new Set([ "google-antigravity", "google-gemini-cli", ]); -const GEMINI_INCOMPLETE_TURN_MODEL_ID_PATTERN = /^gemini(?:[.-]|$)/i; +const GEMINI_INCOMPLETE_TURN_MODEL_ID_PATTERN = /^gemini(?:[.-]|$)/; const DEFAULT_PLANNING_ONLY_RETRY_LIMIT = 1; const STRICT_AGENTIC_PLANNING_ONLY_RETRY_LIMIT = 2; // Allow one immediate continuation plus one follow-up continuation before @@ -407,12 +410,6 @@ function shouldApplyPlanningOnlyRetryGuard(params: { }); } -function stripProviderPrefix(modelId: string): string { - const normalizedModelId = modelId.trim(); - const match = /^([^/:]+)[/:](.+)$/.exec(normalizedModelId); - return (match?.[2] ?? normalizedModelId).toLowerCase(); -} - function isIncompleteTurnRecoverySupportedProviderModel(params: { provider?: string; modelId?: string;