

























@@ -114,6 +114,7 @@ import { createEmbeddedRunReplayState, observeReplayMetadata } from "./replay-st
114114import { handleAssistantFailover } from "./run/assistant-failover.js";
115115import {
116116createEmbeddedRunStageTracker,
117+EMBEDDED_RUN_ATTEMPT_DISPATCH_STAGE,
117118formatEmbeddedRunStageSummary,
118119shouldWarnEmbeddedRunStageSummary,
119120} from "./run/attempt-stage-timing.js";
@@ -194,6 +195,16 @@ const COMPACTION_CONTINUATION_RETRY_INSTRUCTION =
194195"The previous attempt compacted the conversation context before producing a final user-visible answer. Continue from the compacted transcript and produce the final answer now. Do not restart from scratch, do not repeat completed work, and do not rerun tools unless the transcript clearly lacks required evidence.";
195196type EmbeddedRunAttemptForRunner = Awaited<ReturnType<typeof runEmbeddedAttemptWithBackend>>;
196197198+function resolveAttemptDispatchApiKey(params: {
199+apiKeyInfo: ApiKeyInfo | null;
200+runtimeAuthState: RuntimeAuthState | null;
201+}): string | undefined {
202+if (params.runtimeAuthState) {
203+return undefined;
204+}
205+return params.apiKeyInfo?.apiKey;
206+}
207+197208function resolveEmbeddedRunLaneTimeoutMs(timeoutMs: number): number | undefined {
198209if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
199210return undefined;
@@ -1271,6 +1282,9 @@ export async function runEmbeddedPiAgent(
12711282authRetryPending = false;
12721283attemptedThinking.add(thinkLevel);
12731284await fs.mkdir(resolvedWorkspace, { recursive: true });
1285+if (!startupStagesEmitted) {
1286+startupStages.mark(EMBEDDED_RUN_ATTEMPT_DISPATCH_STAGE.workspace);
1287+}
1274128812751289const basePrompt =
12761290nextAttemptPromptOverride ??
@@ -1289,9 +1303,12 @@ export async function runEmbeddedPiAgent(
12891303promptAdditions.length > 0
12901304 ? `${basePrompt}\n\n${promptAdditions.join("\n\n")}`
12911305 : basePrompt;
1292-let resolvedStreamApiKey: string | undefined;
1293-if (!runtimeAuthState && apiKeyInfo) {
1294-resolvedStreamApiKey = (apiKeyInfo as ApiKeyInfo).apiKey;
1306+const resolvedStreamApiKey = resolveAttemptDispatchApiKey({
1307+ apiKeyInfo,
1308+ runtimeAuthState,
1309+});
1310+if (!startupStagesEmitted) {
1311+startupStages.mark(EMBEDDED_RUN_ATTEMPT_DISPATCH_STAGE.prompt);
12951312}
12961313const runtimePlan = buildAgentRuntimePlan({
12971314 provider,
@@ -1323,9 +1340,10 @@ export async function runEmbeddedPiAgent(
13231340},
13241341});
13251342if (!startupStagesEmitted) {
1326-startupStages.mark("attempt-dispatch");
1343+startupStages.mark(EMBEDDED_RUN_ATTEMPT_DISPATCH_STAGE.runtimePlan);
1344+startupStages.mark(EMBEDDED_RUN_ATTEMPT_DISPATCH_STAGE.dispatch);
13271345notifyExecutionPhase("attempt_dispatch", { provider, model: modelId });
1328-emitStartupStageSummary("attempt-dispatch");
1346+emitStartupStageSummary(EMBEDDED_RUN_ATTEMPT_DISPATCH_STAGE.dispatch);
13291347startupStagesEmitted = true;
13301348}
13311349此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。