Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

Merge origin/main into cindy/witty-kepler

DavidShen693284db5237
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index c527446285,6e14fc960c..9b0091b229
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -16226,27 -16183,64 +16239,66 @@@ export function registerMakerIpc(maker
);
}
if (!liveSessionBeforeRouteChange) {
+ assertRuntimeOwnerCurrent();
+ assertSharedTaskCurrent.admit();
- try {
- await rehydrateColdPiRuntimeForWindowVerification(sessionId);
- } catch {
- throwIpcError(
- localModelWindowSwitchErrorCode('MODEL_WINDOW_CURRENT_CONTEXT_UNKNOWN'),
- 'Pi current runtime could not be verified; runtime selection was not changed',
- );
- }
- liveSessionBeforeRouteChange = maker.getSession(sessionId);
- if (!liveSessionBeforeRouteChange) {
- throwIpcError(
- localModelWindowSwitchErrorCode('MODEL_WINDOW_CURRENT_CONTEXT_UNKNOWN'),
- 'Pi current runtime could not be verified; runtime selection was not changed',
- );
+ // 冷启动核实(2~3s)只在它可能改变决策时才做:目标窗口对**已知占用**已到
+ // danger/overflow 才可能需要缩窗交接 / 二次确认;有余量时任何「当前窗口」
+ // 读数都不会触发交接(见 assessRuntimeModelSwitchGate 的 fail-open 矩阵),
+ // 让用户白等一次 Pi 冷启动就是纯卡顿(2026-09-21 实报)。
+ // 占用取 runtime **关闭时固化的 live 读数**(sessionLastLiveUsage),
+ // 不读 sessions.context_tokens:后者只在 turn 正常收尾时落库,中断 / 崩溃
+ // 后可能低报真实占用,拿它证明「目标还有余量」会绕过缩窗交接
+ // (Greptile P1,2026-09-21);进程重启 / 硬杀后没有缓存时自动回退到核实。
+ // 无原生会话的冷 Pi 也不在本预检范围内(维持既有 fail-closed 语义)。
+ const coldPiLastLiveUsage = getSessionLastLiveUsage(sessionId);
+ const coldPiTargetContextWindow = lookupVerifiedContextWindow(
+ (_agentKind, modelId, pid) =>
+ resolveConfiguredContextWindow(getActiveCatalog(), 'pi', pid, modelId),
+ model,
+ targetRouteProviderId,
+ 'pi',
+ );
+ const skipColdPiWindowVerification =
+ !!runtimeStatus.sdkSessionId &&
+ shouldSkipColdPiWindowRehydration({
+ contextTokens: coldPiLastLiveUsage?.contextTokens ?? null,
+ targetContextWindow: coldPiTargetContextWindow,
+ });
+ if (skipColdPiWindowVerification) {
+ coldPiRouteWithoutLiveWindowCheck = true;
+ log.info('set-model: skipped cold Pi window verification', {
+ sessionId,
+ reason: 'target-window-has-headroom',
+ contextTokens: coldPiLastLiveUsage?.contextTokens ?? null,
+ contextWindow: coldPiLastLiveUsage?.contextWindow ?? null,
+ capturedAtMs: coldPiLastLiveUsage?.capturedAtMs ?? null,
+ targetContextWindow: coldPiTargetContextWindow,
+ fromModel: currentRuntimeModel ?? null,
+ toModel: model,
+ currentProviderId,
+ nextProviderId: targetRouteProviderId,
+ });
+ } else {
+ try {
+ await rehydrateColdPiRuntimeForWindowVerification(sessionId);
+ } catch {
+ throwIpcError(
+ localModelWindowSwitchErrorCode('MODEL_WINDOW_CURRENT_CONTEXT_UNKNOWN'),
+ 'Pi current runtime could not be verified; runtime selection was not changed',
+ );
+ }
+ liveSessionBeforeRouteChange = maker.getSession(sessionId);
+ if (!liveSessionBeforeRouteChange) {
+ throwIpcError(
+ localModelWindowSwitchErrorCode('MODEL_WINDOW_CURRENT_CONTEXT_UNKNOWN'),
+ 'Pi current runtime could not be verified; runtime selection was not changed',
+ );
+ }
+ rehydratedColdPiRuntime = liveSessionBeforeRouteChange;
+ currentRuntimeModel = liveSessionBeforeRouteChange.model;
+ runtimeRouteChanged =
+ currentRuntimeModel !== model || currentProviderId !== targetRouteProviderId;
}
- rehydratedColdPiRuntime = liveSessionBeforeRouteChange;
- currentRuntimeModel = liveSessionBeforeRouteChange.model;
- runtimeRouteChanged =
- currentRuntimeModel !== model || currentProviderId !== targetRouteProviderId;
}
}
let targetContextWindow: number | undefined;