


































@@ -4,6 +4,7 @@ import {
44isAssistantCompletionReleaseNotification,
55isCodexTurnAbortMarkerNotification,
66isFileChangePatchUpdatedNotification,
7+isAssistantCommentaryCompletionNotification,
78isNativeToolProgressNotification,
89isNativeResponseStreamDeltaNotification,
910isPendingOpenClawDynamicToolCompletionNotification,
@@ -18,7 +19,7 @@ import {
1819shouldDisarmAssistantCompletionIdleWatch,
1920updateActiveTurnItemIds,
2021} from "./attempt-notifications.js";
21-import { CODEX_POST_REASONING_SOURCE_REPLY_IDLE_TIMEOUT_MS } from "./attempt-timeouts.js";
22+import { CODEX_POST_REASONING_REPLY_IDLE_TIMEOUT_MS } from "./attempt-timeouts.js";
2223import type { CodexAttemptTurnWatchController } from "./attempt-turn-watches.js";
2324import type { CodexServerNotification } from "./protocol.js";
2425@@ -79,7 +80,6 @@ export function applyCodexTurnNotificationState(params: {
7980threadId: string;
8081turnId: string;
8182currentPromptTexts: string[];
82-sourceReplyDeliveryMode: string | undefined;
8383turnWatches: CodexAttemptTurnWatchController;
8484activeTurnItemIds: Set<string>;
8585activeAppServerTurnRequests: number;
@@ -151,23 +151,45 @@ export function applyCodexTurnNotificationState(params: {
151151params.activeTurnItemIds.size === 0 &&
152152params.activeAppServerTurnRequests === 0 &&
153153!assistantCompletionCanRelease &&
154-!postToolRawAssistantCompletionNeedsTerminalGuard;
155-const shouldArmPostReasoningSourceReplyWatch =
154+!postToolRawAssistantCompletionNeedsTerminalGuard &&
155+!rawToolOutputCompletion;
156+const shouldArmNoToolPostProgressReplyWatch =
156157isCurrentTurnNotification &&
157-isReasoningItemCompletionNotification(notification) &&
158+!turnCrossedToolHandoff &&
158159params.activeTurnItemIds.size === 0 &&
159-params.sourceReplyDeliveryMode === "message_tool_only";
160-const shouldArmPostRawReasoningSourceReplyWatch =
160+(isReasoningItemCompletionNotification(notification) ||
161+isAssistantCommentaryCompletionNotification(notification));
162+const shouldArmNoToolPostRawProgressReplyWatch =
163+!turnCrossedToolHandoff &&
161164rawResponseItemCompletedWithNoActiveItems &&
162-isRawReasoningCompletionNotification(notification) &&
163-params.sourceReplyDeliveryMode === "message_tool_only";
165+(isRawReasoningCompletionNotification(notification) ||
166+ isRawAssistantProgressNotification(notification));
164167const shouldRearmCompletionIdleWatchAfterLastCurrentTurnItem =
165168isCurrentTurnNotification &&
166169notification.method === "item/completed" &&
167170params.activeTurnItemIds.size === 0 &&
168171!trackedDynamicToolCompletion &&
169172!assistantCompletionCanRelease &&
170-!shouldArmPostReasoningSourceReplyWatch;
173+!shouldArmNoToolPostProgressReplyWatch;
174+const shouldUsePostToolContinuationWatch =
175+turnCrossedToolHandoff &&
176+(postToolRawAssistantCompletionNeedsTerminalGuard ||
177+postToolPatchUpdateNeedsTerminalGuard ||
178+rawToolOutputCompletion ||
179+trackedDynamicToolCompletion ||
180+shouldRearmCompletionIdleWatchAfterLastCurrentTurnItem);
181+const armPostToolContinuationWatch = () => {
182+turnWatches.armCompletionIdleWatch({
183+timeoutMs: params.postToolRawAssistantCompletionIdleTimeoutMs,
184+});
185+turnWatches.extendAttemptIdleWatch(params.postToolRawAssistantCompletionIdleTimeoutMs);
186+};
187+const armPostProgressReplyWatch = () => {
188+turnWatches.armCompletionIdleWatch({
189+timeoutMs: CODEX_POST_REASONING_REPLY_IDLE_TIMEOUT_MS,
190+});
191+turnWatches.extendAttemptIdleWatch(CODEX_POST_REASONING_REPLY_IDLE_TIMEOUT_MS);
192+};
171193172194if (isCurrentTurnNotification && notification.method === "error") {
173195if (isRetryableErrorNotification(notification.params)) {
@@ -187,26 +209,28 @@ export function applyCodexTurnNotificationState(params: {
187209// Post-tool assistant status and patch snapshots can be followed by more
188210// native edit streaming. Keep the short guard alive until Codex reports a
189211// terminal turn state instead of falling back to the long terminal watch.
190-turnWatches.armCompletionIdleWatch({
191-timeoutMs: params.postToolRawAssistantCompletionIdleTimeoutMs,
192-});
193-} else if (shouldArmPostReasoningSourceReplyWatch || shouldArmPostRawReasoningSourceReplyWatch) {
194-turnWatches.armCompletionIdleWatch({
195-timeoutMs: CODEX_POST_REASONING_SOURCE_REPLY_IDLE_TIMEOUT_MS,
196-});
212+armPostToolContinuationWatch();
213+} else if (shouldArmNoToolPostProgressReplyWatch || shouldArmNoToolPostRawProgressReplyWatch) {
214+armPostProgressReplyWatch();
215+} else if (trackedDynamicToolCompletion) {
216+armPostToolContinuationWatch();
197217} else if (unblockedAssistantCompletionRelease) {
198218turnWatches.armAssistantCompletionIdleWatch(describeNotificationActivity(notification));
199219} else if (shouldRearmCompletionIdleWatchAfterLastCurrentTurnItem) {
200220// If a non-assistant current-turn item is the last active item and the
201221// bridge then goes quiet, reset the short completion-idle guard from that
202222// final completion so the remaining silent-turn gap fails fast.
203-turnWatches.armCompletionIdleWatch();
223+if (shouldUsePostToolContinuationWatch) {
224+armPostToolContinuationWatch();
225+} else {
226+turnWatches.armCompletionIdleWatch();
227+}
204228} else if (rawResponseItemCompletedWithNoActiveItems) {
205229turnWatches.armCompletionIdleWatch();
206230} else if (isCurrentTurnNotification && rawToolOutputCompletion) {
207231// Raw OpenAI response streams can report the tool-output handoff without
208232// a matching app-server `item/completed`; keep the post-tool guard alive.
209-turnWatches.armCompletionIdleWatch();
233+armPostToolContinuationWatch();
210234} else if (isCurrentTurnNotification && shouldDisarmAssistantCompletionIdleWatch(notification)) {
211235turnWatches.disarmAssistantCompletionIdleWatch();
212236}
@@ -222,8 +246,8 @@ export function applyCodexTurnNotificationState(params: {
222246!postToolRawAssistantCompletionNeedsTerminalGuard &&
223247!postToolPatchUpdateNeedsTerminalGuard &&
224248!rawResponseItemCompletedWithNoActiveItems &&
225-!shouldArmPostReasoningSourceReplyWatch &&
226-!shouldArmPostRawReasoningSourceReplyWatch &&
249+!shouldArmNoToolPostProgressReplyWatch &&
250+!shouldArmNoToolPostRawProgressReplyWatch &&
227251!shouldRearmCompletionIdleWatchAfterLastCurrentTurnItem
228252) {
229253// The short completion-idle watchdog guards blind gaps after Codex
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。