





















@@ -242,6 +242,11 @@ import {
242242shouldRotateCompactionTranscript,
243243} from "../compaction-successor-transcript.js";
244244import { configureEmbeddedAttemptHttpRuntime } from "./attempt-http-runtime.js";
245+import {
246+createEmbeddedRunStageTracker,
247+formatEmbeddedRunStageSummary,
248+shouldEmitEmbeddedRunStageSummary,
249+} from "./attempt-stage-timing.js";
245250import {
246251assembleAttemptContextEngine,
247252buildLoopPromptCacheInfo,
@@ -589,6 +594,19 @@ export async function runEmbeddedAttempt(
589594log.debug(
590595`embedded run start: runId=${params.runId} sessionId=${params.sessionId} provider=${params.provider} model=${params.modelId} thinking=${params.thinkLevel} messageChannel=${params.messageChannel ?? params.messageProvider ?? "unknown"}`,
591596);
597+const prepStages = createEmbeddedRunStageTracker();
598+const emitPrepStageSummary = (phase: string) => {
599+const summary = prepStages.snapshot();
600+const message = formatEmbeddedRunStageSummary(
601+`embedded run prep stages: runId=${params.runId} sessionId=${params.sessionId} phase=${phase}`,
602+summary,
603+);
604+if (shouldEmitEmbeddedRunStageSummary(summary)) {
605+log.warn(message);
606+} else if (log.isEnabled("debug")) {
607+log.debug(message);
608+}
609+};
592610593611await fs.mkdir(resolvedWorkspace, { recursive: true });
594612@@ -610,6 +628,7 @@ export async function runEmbeddedAttempt(
610628config: params.config,
611629agentId: params.agentId,
612630});
631+prepStages.mark("workspace-sandbox");
613632614633let restoreSkillEnv: (() => void) | undefined;
615634let aborted = Boolean(params.abortSignal?.aborted);
@@ -645,6 +664,7 @@ export async function runEmbeddedAttempt(
645664workspaceDir: effectiveWorkspace,
646665agentId: sessionAgentId,
647666});
667+prepStages.mark("skills");
648668649669const sessionLabel = params.sessionKey ?? params.sessionId;
650670const contextInjectionMode = resolveContextInjectionMode(params.config);
@@ -760,6 +780,7 @@ export async function runEmbeddedAttempt(
760780});
761781return applyEmbeddedAttemptToolsAllow(allTools, params.toolsAllow);
762782})();
783+prepStages.mark("core-plugin-tools");
763784const toolsEnabled = supportsModelTools(params.model);
764785const bootstrapHasFileAccess = toolsEnabled && toolsRaw.some((tool) => tool.name === "read");
765786const bootstrapRouting = await resolveAttemptWorkspaceBootstrapRouting({
@@ -803,6 +824,7 @@ export async function runEmbeddedAttempt(
803824runKind: params.bootstrapContextRunKind,
804825}),
805826});
827+prepStages.mark("bootstrap-context");
806828const remappedContextFiles = remapInjectedContextFilesToWorkspace({
807829files: resolvedContextFiles,
808830sourceWorkspaceDir: resolvedWorkspace,
@@ -935,6 +957,7 @@ export async function runEmbeddedAttempt(
935957warn: (message) => log.warn(message),
936958});
937959const effectiveTools = [...tools, ...filteredBundledTools];
960+prepStages.mark("bundle-tools");
938961const allowedToolNames = collectAllowedToolNames({
939962tools: effectiveTools,
940963 clientTools,
@@ -1221,6 +1244,7 @@ export async function runEmbeddedAttempt(
12211244 bootstrapMode,
12221245contextFiles: remappedContextFiles,
12231246});
1247+prepStages.mark("system-prompt");
1224124812251249// Keep the session lock scoped to transcript/session mutations. Cold plugin
12261250// and tool setup can be slow, and holding the lock there blocks CLI fallback
@@ -1345,6 +1369,7 @@ export async function runEmbeddedAttempt(
13451369cfg: params.config,
13461370contextTokenBudget: params.contextTokenBudget,
13471371});
1372+prepStages.mark("session-resource-loader");
1348137313491374// Get hook runner early so it's available when creating tools
13501375const hookRunner = getGlobalHookRunner();
@@ -1441,6 +1466,7 @@ export async function runEmbeddedAttempt(
14411466}
14421467session.setActiveToolsByName(sessionToolAllowlist);
14431468const activeSession = session;
1469+prepStages.mark("agent-session");
14441470if (isRawModelRun) {
14451471// Raw model probes should measure exactly the requested prompt against
14461472// the selected provider/model. Reset clears restored transcript state
@@ -1692,6 +1718,8 @@ export async function runEmbeddedAttempt(
16921718`(${params.provider}/${params.modelId})`,
16931719);
16941720}
1721+prepStages.mark("stream-setup");
1722+emitPrepStageSummary("stream-ready");
1695172316961724const cacheObservabilityEnabled = Boolean(cacheTrace) || log.isEnabled("debug");
16971725const promptCacheToolNames = collectPromptCacheToolNames(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。