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。

fix(codex): 修正 exec 续接误报与未完成结果提示 (#4327)

Dashc98b1fd45151
diff --git a/apps/desktop/src/renderer/components/chat/errorReasonI18n.ts b/apps/desktop/src/renderer/components/chat/errorReasonI18n.ts
index e5ce402f05..b90be3d3ce 100644
--- a/apps/desktop/src/renderer/components/chat/errorReasonI18n.ts
+++ b/apps/desktop/src/renderer/components/chat/errorReasonI18n.ts
@@ -18,6 +18,7 @@ export const ERROR_REASON_I18N_KEYS: Record<string, string> = {
'empty-response': 'logic.errors.emptyResponse',
'turn-failed': 'logic.errors.turnFailed',
'silent-stop-exhausted': 'logic.errors.silentStopExhausted',
+ 'yield-continuation-incomplete': 'logic.errors.executionResultUnavailable',
'output-limit': 'logic.errors.outputLimit',
tool_use_loop_detected: 'logic.errors.toolUseLoopDetected',
'permission-tighten-interrupt-failed': 'logic.errors.permissionTightenInterruptFailed',
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 090a88998c..9db6d27331 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -11540,6 +11540,7 @@
"qrExpired": "QR code expired, please start again",
"registrationFailed": "Creation failed, please retry later",
"silentStopExhausted": "The model returned empty responses repeatedly; auto-resume is paused. Click \"Continue\" to resume the task.",
+ "executionResultUnavailable": "Unable to retrieve the execution result. Automatic continuation has stopped. Ask the assistant to check the existing execution result.",
"outputLimit": "The model reached its output limit, so this response may be incomplete. Send the next message to continue.",
"permissionTightenInterruptFailed": "Failed to stop the running task while tightening permissions; it may keep running without approval prompts until it finishes. Stop it manually if needed.",
"codexAutoReviewUnavailable": "Auto-review is temporarily unavailable. The current action was blocked and permissions switched to Default. Retry the request; Cindy will ask when needed.",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 215f0044cf..c54c387f66 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -11524,6 +11524,7 @@
"qrExpired": "QR コードが期限切れです。最初からやり直してください",
"registrationFailed": "作成に失敗しました。後でもう一度お試しください",
"silentStopExhausted": "モデルが空の応答を繰り返し返したため、自動再開を一時停止しました。「続行」をクリックしてタスクを再開してください。",
+ "executionResultUnavailable": "実行結果を取得できなかったため、自動継続を停止しました。既存の実行結果を確認するようアシスタントに依頼してください。",
"outputLimit": "モデルが出力上限に達したため、この応答は不完全な可能性があります。次のメッセージを送信して続行できます。",
"permissionTightenInterruptFailed": "権限を厳格化する際に実行中のタスクを停止できませんでした。タスクは終了まで確認なしで実行され続ける可能性があります。必要に応じて手動で停止してください。",
"codexAutoReviewUnavailable": "自動レビューは一時的に利用できません。現在の操作をブロックし、デフォルト権限に切り替えました。もう一度実行してください。必要な場合は確認します。",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 6bc5d5c684..aea09b2f7d 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -11524,6 +11524,7 @@
"qrExpired": "QR 코드가 만료됨. 다시 시작하세요",
"registrationFailed": "생성 실패. 잠시 후 다시 시도하세요",
"silentStopExhausted": "모델이 빈 응답을 반복해서 반환하여 자동 재개가 일시 중지되었습니다. \"계속\"을 클릭하여 작업을 재개하세요.",
+ "executionResultUnavailable": "실행 결과를 가져오지 못해 자동 계속 진행을 중단했습니다. 어시스턴트에게 기존 실행 결과를 확인하도록 요청하세요.",
"outputLimit": "모델이 출력 한도에 도달하여 이번 응답은 불완전할 수 있습니다. 다음 메시지를 보내 계속할 수 있습니다.",
"permissionTightenInterruptFailed": "권한을 강화하는 동안 실행 중인 작업을 중지하지 못했습니다. 작업이 끝날 때까지 확인 없이 계속 실행될 수 있습니다. 필요하면 수동으로 중지하세요.",
"codexAutoReviewUnavailable": "자동 리뷰를 일시적으로 사용할 수 없습니다. 현재 작업을 차단하고 기본 권한으로 전환했습니다. 다시 시도하세요. 필요한 경우 확인을 요청합니다.",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 5d83d876eb..ed373c5ef6 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -11524,6 +11524,7 @@
"qrExpired": "二维码已过期,请重新开始",
"registrationFailed": "创建失败,请稍后重试",
"silentStopExhausted": "模型连续多次返回空响应,自动续跑已暂停。点击「继续」恢复任务。",
+ "executionResultUnavailable": "未能取回执行结果,已停止自动续接。可以让助手检查已有的执行结果。",
"outputLimit": "模型已达到输出长度上限,本轮回复可能不完整。可以直接发送下一条消息继续。",
"permissionTightenInterruptFailed": "收紧权限时未能停止正在运行的任务,它可能会继续免确认执行直到结束;如有需要请手动停止。",
"codexAutoReviewUnavailable": "自动审批暂时不可用,当前操作已阻止并切换为默认权限。请重试,需要时会询问你。",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index e7c3ce07b1..53dce5a032 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -11524,6 +11524,7 @@
"qrExpired": "二維碼已過期,請重新開始",
"registrationFailed": "建立失敗,請稍後重試",
"silentStopExhausted": "模型連續多次返回空響應,自動續跑已暫停。點選「繼續」恢復任務。",
+ "executionResultUnavailable": "未能取得執行結果,已停止自動接續。可以請助手檢查既有的執行結果。",
"outputLimit": "模型已達到輸出長度上限,本輪回覆可能不完整。可以直接傳送下一則訊息繼續。",
"permissionTightenInterruptFailed": "收緊權限時未能停止正在執行的任務,它可能會繼續免確認執行直到結束;如有需要請手動停止。",
"codexAutoReviewUnavailable": "自動審批暫時不可用,當前操作已阻止並切換為預設權限。請重試,需要時會詢問你。",
diff --git a/apps/mobile/src/__tests__/inputProjection.test.ts b/apps/mobile/src/__tests__/inputProjection.test.ts
index 2ae6425703..4d586ad754 100644
--- a/apps/mobile/src/__tests__/inputProjection.test.ts
+++ b/apps/mobile/src/__tests__/inputProjection.test.ts
@@ -405,6 +405,12 @@ describe('inputProjection', () => {
);
});
+ it('localizes incomplete execution without exposing the host cell diagnostic', () => {
+ expect(localizeAgentError('yield-continuation-incomplete', null)).toBe(
+ i18n.t('session.tail.executionResultUnavailable'),
+ );
+ });
+
it('localizes live tool-loop errors instead of rendering the host message', () => {
const localized = localizeAgentError(
'tool_use_loop_detected',
diff --git a/apps/mobile/src/i18n/locales/en/session.json b/apps/mobile/src/i18n/locales/en/session.json
index dbaace16ce..80c9764079 100644
--- a/apps/mobile/src/i18n/locales/en/session.json
+++ b/apps/mobile/src/i18n/locales/en/session.json
@@ -477,6 +477,7 @@
"continueTask": "Continue Task",
"retry": "Retry",
"ignore": "Ignore",
+ "executionResultUnavailable": "Unable to retrieve the execution result. Automatic continuation has stopped. Ask the assistant to check the existing execution result.",
"outputLimit": "The model reached its output limit, so this response may be incomplete. Send the next message to continue.",
"toolUseLoopDetected": "The model repeated a tool call too many times, so Cindy stopped this turn to prevent an infinite loop. Send a new message to continue.",
"toolUseLoopDetectedWithCount": "The model kept repeating invalid tool calls, so Cindy stopped this turn after {{count}} failures to prevent an infinite loop. Send a new message to continue.",
diff --git a/apps/mobile/src/i18n/locales/ja/session.json b/apps/mobile/src/i18n/locales/ja/session.json
index de1585f330..b5d83a959f 100644
--- a/apps/mobile/src/i18n/locales/ja/session.json
+++ b/apps/mobile/src/i18n/locales/ja/session.json
@@ -477,6 +477,7 @@
"continueTask": "タスクを続ける",
"retry": "再試行",
"ignore": "無視",
+ "executionResultUnavailable": "実行結果を取得できなかったため、自動継続を停止しました。既存の実行結果を確認するようアシスタントに依頼してください。",
"outputLimit": "モデルが出力上限に達したため、この応答は不完全な可能性があります。次のメッセージを送信して続行できます。",
"toolUseLoopDetected": "モデルがツール呼び出しを繰り返したため、無限ループを防ぐためこのターンを停止しました。新しいメッセージを送信して続行できます。",
"toolUseLoopDetectedWithCount": "モデルが無効なツール呼び出しを繰り返したため、無限ループを防ぐために {{count}} 回の失敗後にこのターンを停止しました。新しいメッセージを送信して続行できます。",
diff --git a/apps/mobile/src/i18n/locales/ko/session.json b/apps/mobile/src/i18n/locales/ko/session.json
index d6c0659352..de65ea4d24 100644
--- a/apps/mobile/src/i18n/locales/ko/session.json
+++ b/apps/mobile/src/i18n/locales/ko/session.json
@@ -473,6 +473,7 @@
"continueTask": "작업 계속",
"retry": "다시 시도",
"ignore": "무시",
+ "executionResultUnavailable": "실행 결과를 가져오지 못해 자동 계속 진행을 중단했습니다. 어시스턴트에게 기존 실행 결과를 확인하도록 요청하세요.",
"outputLimit": "모델이 출력 한도에 도달하여 이번 응답은 불완전할 수 있습니다. 다음 메시지를 보내 계속할 수 있습니다.",
"toolUseLoopDetected": "모델이 도구 호출을 너무 많이 반복하여 무한 루프를 방지하기 위해 이번 턴을 중지했습니다. 새 메시지를 보내 계속할 수 있습니다.",
"toolUseLoopDetectedWithCount": "모델이 잘못된 도구 호출을 반복하여 무한 루프를 방지하기 위해 {{count}}회 실패 후 이번 턴을 중지했습니다. 새 메시지를 보내 계속할 수 있습니다.",
diff --git a/apps/mobile/src/i18n/locales/zh-CN/session.json b/apps/mobile/src/i18n/locales/zh-CN/session.json
index ee1f8991db..b9f3972ab6 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/session.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/session.json
@@ -473,6 +473,7 @@
"continueTask": "继续任务",
"retry": "重试",
"ignore": "忽略",
+ "executionResultUnavailable": "未能取回执行结果,已停止自动续接。可以让助手检查已有的执行结果。",
"outputLimit": "模型已达到输出长度上限,本轮回复可能不完整。可以直接发送下一条消息继续。",
"toolUseLoopDetected": "模型重复调用工具次数过多,Cindy 已停止本轮以避免无限循环。可以发送新消息继续。",
"toolUseLoopDetectedWithCount": "模型连续触发了无效的工具调用,Cindy 已在 {{count}} 次失败后停止本轮,以避免无限循环。可以发送新消息继续。",
diff --git a/apps/mobile/src/i18n/locales/zh-TW/session.json b/apps/mobile/src/i18n/locales/zh-TW/session.json
index 779325f3ad..046ef14320 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/session.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/session.json
@@ -477,6 +477,7 @@
"continueTask": "繼續任務",
"retry": "重試",
"ignore": "忽略",
+ "executionResultUnavailable": "未能取得執行結果,已停止自動接續。可以請助手檢查既有的執行結果。",
"outputLimit": "模型已達到輸出長度上限,本輪回覆可能不完整。可以直接傳送下一則訊息繼續。",
"toolUseLoopDetected": "模型重複呼叫工具次數過多,Cindy 已停止這一輪以避免無限迴圈。可以傳送新訊息繼續。",
"toolUseLoopDetectedWithCount": "模型連續觸發無效的工具呼叫,Cindy 已在 {{count}} 次失敗後停止本輪,以避免無限迴圈。可以傳送新訊息繼續。",
diff --git a/apps/mobile/src/session/agentErrorI18n.ts b/apps/mobile/src/session/agentErrorI18n.ts
index 62238e358b..f9361cf384 100644
--- a/apps/mobile/src/session/agentErrorI18n.ts
+++ b/apps/mobile/src/session/agentErrorI18n.ts
@@ -50,6 +50,7 @@ export function localizeAgentError(
reason: unknown,
toolLoop: MobileToolLoopErrorDetails | null,
): string | null {
+ if (reason === 'yield-continuation-incomplete') return i18n.t('session.tail.executionResultUnavailable');
if (reason === 'output-limit') return i18n.t('session.tail.outputLimit');
if (reason !== 'tool_use_loop_detected') return null;
if (!toolLoop) return i18n.t('session.tail.toolUseLoopDetected');
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index ab219d8ed4..363ff7954f 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -146,7 +146,11 @@ Codex 的 120 秒 reconnect watchdog 只是 fallback 收口,不是根因诊断
结算 usage;只有原子挂在该终态边界上的显式 continuation claim 才能挡住产品结束。
Codex `functions.exec` yield 没有协议级 execution handle(cell / wait 活在
`codex-rs` daemon),近期检测只能是 adapter 内、用真实 rollout fixture 锁死的启发式,
- 用来铸造有界 claim,再由宿主确定性开续段让模型 wait 同一 cell。无 `id`/`call_id`
+ 用来铸造有界 claim,再由宿主确定性开续段让模型 wait 同一 cell。
+ `commandExecution` 带数字 `exitCode` 时,结构化退出结果优先于正文:即使 stdout
+ 完整复刻 running 状态头,也不得铸造 claim;不能仅凭 `status: completed` 排除
+ 没有退出码的旧版 yield 包装。实现与回归见 `agents/codex/yielded-exec-cell.ts`
+ 及其测试(均位于 `packages/maker-core/src/`)。无 `id`/`call_id`
的 item 只认 `itemCompleted` 快照:`itemUpdated` 不得入账,不得给匿名条目发明身份。
无 yield marker 的 nameless 完成不得清匿名桶;匿名 `wait` 若按 `cell_id` 结算了其中一个
cell,只从匿名桶拿掉该 cell,不得清空仍在跑的其它匿名 cell。同 turn 或续段里
@@ -154,8 +158,11 @@ Codex 的 120 秒 reconnect watchdog 只是 fallback 收口,不是根因诊断
再铸 claim,也不得报 lost-handle。Plan Mode 审批只在产品终态跑:存在 awaiting
yield claim 时不得把空计划当循环结束,也不得在 SDK `turn/completed` 上提前挂审批;
origin 已产出的计划挂在 claim 上,续段结算后再审。禁止把 `last_agent_message == null` 或开场白当结算
- 判据;cell 跨 turn 存活性未证实前,续段失败必须诚实报 lost-handle,不得 replay 原请求
- 或重跑已执行命令。续段 claim 一旦挡住产品结束,所有非重试终态错误路径(不限
+ 判据;空续段或重试耗尽只证明未取回结果,统一报 `yield-continuation-incomplete`,
+ 不得推断 cell 丢失或由跨 turn 导致。用户错误不带 cell 编号,原因和编号保留在诊断日志。
+ 真实 `not found` 也可能来自重复等待已消费的 cell,不等同于底层命令丢失;
+ 已结算 cell 不因后续重复等待失败而重新入账。不得 replay 原请求或重跑已执行命令。
+ 续段 claim 一旦挡住产品结束,所有非重试终态错误路径(不限
transport)都必须同步结算它,不能只推 Done 而让 `isTurnRunning()` 仍为 true。
续段 `turn/start` 已被服务端接受后若本地取消,必须先凭响应里的 turn id 落墓碑并
best-effort interrupt,再抛/返回取消;`wait` 仍输出 running marker 视为 cell
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index 8b36bacb80..f676c904c9 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -19952,7 +19952,7 @@ describe('CodexAgent yield continuation', () => {
return host.request.mock.calls.filter(([method, params]) => (
method === Method.TurnStart
&& String((params as { input?: Array<{ text?: string }> }).input?.[0]?.text ?? '')
- .includes('A foreground exec cell is still running')
+ .includes('Wait for every listed cell')
));
}
@@ -20598,12 +20598,59 @@ describe('CodexAgent yield continuation', () => {
});
expect(events.some((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-incomplete'
))).toBe(false);
expect(handle.isTurnRunning?.()).toBe(true);
await handle.close();
});
+ it.each([false, true])('does not continue after reading the cell 42 report example (updated=%s)', async (updated) => {
+ const agent = new CodexAgent(createDeps());
+ const host = installFakeHost(agent, (method) => {
+ if (method === Method.TurnStart) return { turn: { id: 'turn-1' } };
+ return undefined;
+ });
+ const handle = await agent.startSession({
+ sessionId: 'session-report-cell-example',
+ model: 'gpt-5.4',
+ workingDir: '/repo',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.itemCompleted || !handlers.itemUpdated || !handlers.turnCompleted) {
+ throw new Error('expected item and turn handlers');
+ }
+ const events = await collectYieldEvents(handle);
+ await handle.send({ type: 'user', content: 'Read the report' });
+ const item = {
+ id: 'report-read',
+ type: 'commandExecution',
+ command: 'cat REPORT.md',
+ aggregatedOutput: 'Example:\n```\nScript running with cell ID 42\nWall time 1 second\n```',
+ };
+ if (updated) {
+ handlers.itemUpdated({
+ threadId: 'start-thread-id', turnId: 'turn-1',
+ item: { ...item, status: 'inProgress', exitCode: null },
+ });
+ }
+ handlers.itemCompleted({
+ threadId: 'start-thread-id', turnId: 'turn-1',
+ item: { ...item, status: 'completed', exitCode: 0 },
+ });
+ handlers.turnCompleted({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-1', status: 'completed' },
+ });
+ await waitForExpectation(() => {
+ expect(events.some((event) => event.type === 'done')).toBe(true);
+ });
+ expect(events.find((event) => event.type === 'done')?.turnContinuationId).toBeUndefined();
+ expect(events.some((event) => event.type === 'error')).toBe(false);
+ expect(handle.isTurnRunning?.()).toBe(false);
+ expect(yieldTurnStartCalls(host)).toHaveLength(0);
+ await handle.close();
+ });
+
it('does not mint a claim for a finished command without a yield marker', async () => {
const agent = new CodexAgent(createDeps());
const host = installFakeHost(agent, (method) => {
@@ -21310,7 +21357,7 @@ describe('CodexAgent yield continuation', () => {
await handle.close();
});
- it('settles the product turn after the continuation waits the yielded cell', async () => {
+ it.each([false, true])('keeps a consumed cell settled even after duplicate wait failure: %s', async (duplicateWait) => {
const agent = new CodexAgent(createDeps());
let turnSeq = 0;
const host = installFakeHost(agent, (method) => {
@@ -21364,6 +21411,16 @@ describe('CodexAgent yield continuation', () => {
content: [{ type: 'output_text', text: 'Script completed\nWall time 4.2 seconds\nOutput:\n' }],
},
});
+ if (duplicateWait) {
+ handlers.itemCompleted({
+ threadId: 'start-thread-id', turnId: 'turn-2',
+ item: {
+ id: 'wait-consumed-cell', type: 'function_call', name: 'wait',
+ arguments: JSON.stringify({ cell_id: '226' }),
+ content: [{ type: 'output_text', text: 'Script failed\nScript error:\nexec cell 226 not found' }],
+ },
+ });
+ }
handlers.turnCompleted({
threadId: 'start-thread-id',
turn: { id: 'turn-2', status: 'completed' },
@@ -21373,7 +21430,7 @@ describe('CodexAgent yield continuation', () => {
});
expect(events.some((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-incomplete'
))).toBe(false);
const dones = events.filter((event) => event.type === 'done');
expect(dones[0]?.turnContinuationId).toEqual(expect.any(Number));
@@ -21382,7 +21439,7 @@ describe('CodexAgent yield continuation', () => {
await handle.close();
});
- it('emits lost-handle without a later successful done after an empty continuation', async () => {
+ it.each([undefined, 'Script failed\nWall time 0 seconds\nOutput:\nScript error:\nexec cell 226 not found', 'failed to parse function arguments'])('reports incomplete without claiming loss after wait output %s', async (waitOutput) => {
const agent = new CodexAgent(createDeps());
let turnSeq = 0;
const host = installFakeHost(agent, (method) => {
@@ -21425,6 +21482,17 @@ describe('CodexAgent yield continuation', () => {
threadId: 'start-thread-id',
turn: { id: 'turn-2', status: 'inProgress' },
});
+ if (waitOutput) {
+ handlers.itemCompleted({
+ threadId: 'start-thread-id',
+ turnId: 'turn-2',
+ item: {
+ id: 'wait-failed', type: 'function_call', name: 'wait',
+ arguments: JSON.stringify({ cell_id: '226' }),
+ content: [{ type: 'output_text', text: waitOutput }],
+ },
+ });
+ }
handlers.turnCompleted({
threadId: 'start-thread-id',
turn: { id: 'turn-2', status: 'completed' },
@@ -21432,9 +21500,14 @@ describe('CodexAgent yield continuation', () => {
await waitForExpectation(() => {
expect(events.filter((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-incomplete'
))).toHaveLength(1);
});
+ expect(events.find((event) => event.type === 'error')?.data).toMatchObject({
+ message: 'Unable to retrieve the execution result. Automatic continuation has stopped. Ask the assistant to check the existing execution result.',
+ isTerminal: true,
+ });
+ expect(yieldTurnStartCalls(host)).toHaveLength(1);
const claimedDone = events.find((event) => event.type === 'done' && event.turnContinuationId != null);
expect(claimedDone).toBeDefined();
expect(events.filter((event) => event.type === 'done' && event.turnContinuationId == null)).toHaveLength(0);
@@ -21489,9 +21562,10 @@ describe('CodexAgent yield continuation', () => {
threadId: 'start-thread-id',
turnId: 'turn-2',
item: {
- id: 'item-exec-retry-2',
- type: 'commandExecution',
- command: 'pnpm --filter desktop run typecheck',
+ id: 'item-wait-retry-2',
+ type: 'function_call',
+ name: 'wait',
+ arguments: JSON.stringify({ cell_id: '226' }),
status: 'completed',
aggregatedOutput: 'Script running with cell ID 226\nWall time 1.0 seconds\nOutput:\n',
},
@@ -21511,9 +21585,10 @@ describe('CodexAgent yield continuation', () => {
threadId: 'start-thread-id',
turnId: 'turn-3',
item: {
- id: 'item-exec-retry-3',
- type: 'commandExecution',
- command: 'pnpm --filter desktop run typecheck',
+ id: 'item-wait-retry-3',
+ type: 'function_call',
+ name: 'wait',
+ arguments: JSON.stringify({ cell_id: '226' }),
status: 'completed',
aggregatedOutput: 'Script running with cell ID 226\nWall time 1.0 seconds\nOutput:\n',
},
@@ -21525,10 +21600,14 @@ describe('CodexAgent yield continuation', () => {
await waitForExpectation(() => {
expect(events.filter((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-incomplete'
))).toHaveLength(1);
});
expect(events.filter((event) => event.type === 'done' && event.turnContinuationId == null)).toHaveLength(0);
+ expect(events.find((event) => event.type === 'error')?.data).toMatchObject({
+ message: 'Unable to retrieve the execution result. Automatic continuation has stopped. Ask the assistant to check the existing execution result.',
+ });
+ expect(yieldTurnStartCalls(host)).toHaveLength(2);
expect(handle.isTurnRunning?.()).toBe(false);
await handle.close();
});
@@ -21792,7 +21871,7 @@ describe('CodexAgent yield continuation', () => {
});
expect(events.some((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-incomplete'
))).toBe(false);
expect(events.filter((event) => event.type === 'done')).toHaveLength(1);
expect(events.find((event) => event.type === 'done' && event.turnContinuationId == null)).toBeUndefined();
@@ -21896,7 +21975,7 @@ describe('CodexAgent yield continuation', () => {
await handle.close();
});
- it('does not start a queued ask_user continuation after lost-handle', async () => {
+ it('does not start a queued ask_user continuation after incomplete continuation', async () => {
const agent = new CodexAgent(createDeps());
let turnSeq = 0;
const host = installFakeHost(agent, (method) => {
@@ -21967,7 +22046,7 @@ describe('CodexAgent yield continuation', () => {
await waitForExpectation(() => {
expect(events.some((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-incomplete'
))).toBe(true);
});
await new Promise((resolve) => setTimeout(resolve, 20));
@@ -21980,7 +22059,7 @@ describe('CodexAgent yield continuation', () => {
await handle.close();
});
- it('does not start ask_user after lost-handle if the user answers later', async () => {
+ it('does not start ask_user after incomplete continuation if the user answers later', async () => {
const agent = new CodexAgent(createDeps());
let turnSeq = 0;
const host = installFakeHost(agent, (method) => {
@@ -22045,7 +22124,7 @@ describe('CodexAgent yield continuation', () => {
await waitForExpectation(() => {
expect(events.some((event) => (
event.type === 'error'
- && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-lost-handle'
+ && String((event.data as { reason?: string }).reason ?? '') === 'yield-continuation-incomplete'
))).toBe(true);
});
expect(events.some((event) => (
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 840395187b..522b0b89e1 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -3599,7 +3599,7 @@ export class CodexAgent extends BaseAgent {
releaseSettledYieldContinuationClaim(claim);
};
const emitYieldContinuationFailure = (opts: {
- reason: 'yield-continuation-start-failed' | 'yield-continuation-lost-handle';
+ reason: 'yield-continuation-start-failed' | 'yield-continuation-incomplete';
message: string;
cells: YieldedExecCell[];
detail?: string;
@@ -3607,7 +3607,7 @@ export class CodexAgent extends BaseAgent {
log.warn(
opts.reason === 'yield-continuation-start-failed'
? 'yield continuation turn failed to start'
- : 'yield continuation lost exec cell',
+ : 'yield continuation did not retrieve execution results',
{
reason: opts.reason,
...(opts.detail ? { detail: opts.detail } : {}),
@@ -3646,10 +3646,12 @@ export class CodexAgent extends BaseAgent {
detail: String(error),
});
};
- const emitYieldContinuationLostHandle = (cells: YieldedExecCell[], reason: string): void => {
+ // Missing progress or exhausted retries do not prove a handle was lost.
+ // Even not-found can mean a completed cell was already consumed.
+ const emitYieldContinuationIncomplete = (cells: YieldedExecCell[], reason: string): void => {
emitYieldContinuationFailure({
- reason: 'yield-continuation-lost-handle',
- message: `Foreground exec cell ${cells.map((cell) => cell.cellId).join(', ')} was lost after the previous turn completed.`,
+ reason: 'yield-continuation-incomplete',
+ message: 'Unable to retrieve the execution result. Automatic continuation has stopped. Ask the assistant to check the existing execution result.',
cells,
detail: reason,
});
@@ -10197,7 +10199,7 @@ export class CodexAgent extends BaseAgent {
// product terminal, not a lost handle.
flushYieldContinuationIdleWaiters();
} else if (yieldedCells.length === 0 || retryCount >= YIELD_CONTINUATION_MAX_ATTEMPTS) {
- emitYieldContinuationLostHandle(
+ emitYieldContinuationIncomplete(
outstandingCells,
yieldedCells.length === 0 ? 'empty_completion' : 'retry_exhausted',
);
diff --git a/packages/maker-core/src/agents/codex/yielded-exec-cell.test.ts b/packages/maker-core/src/agents/codex/yielded-exec-cell.test.ts
index 6e5ea945a1..1e8dc98cf0 100644
--- a/packages/maker-core/src/agents/codex/yielded-exec-cell.test.ts
+++ b/packages/maker-core/src/agents/codex/yielded-exec-cell.test.ts
@@ -61,6 +61,34 @@ describe('extractYieldedExecCellIds', () => {
});
describe('extractYieldedExecCellsFromCodexItem', () => {
+ // 2026-09-11: reading a report printed this complete example at column 0.
+ // The shell had already exited; its stdout was mistaken for a live exec cell.
+ it.each([0, 1])('ignores report examples when the command has exit code %s', (exitCode) => {
+ for (const aggregatedOutput of [
+ 'Example:\n```\nScript running with cell ID 42\nWall time 1 second\n```',
+ 'Script running with cell ID 42\nWall time 1 second\n',
+ `${'x'.repeat(20_000)}\nScript running with cell ID 42\nWall time 1 second\n`,
+ ]) {
+ expect(extractYieldedExecCellsFromCodexItem({
+ type: 'commandExecution',
+ id: 'report-read',
+ command: 'cat REPORT.md',
+ status: exitCode === 0 ? 'completed' : 'failed',
+ exitCode,
+ aggregatedOutput,
+ })).toEqual([]);
+ }
+ });
+
+ it.each([undefined, null])('preserves legacy yield output with exitCode %s', (exitCode) => {
+ expect(extractYieldedExecCellsFromCodexItem({
+ type: 'commandExecution',
+ status: 'completed',
+ exitCode,
+ aggregatedOutput: 'Script running with cell ID 226\nWall time 1 second\n',
+ })).toEqual([{ cellId: '226' }]);
+ });
+
it('reads commandExecution.aggregatedOutput', () => {
expect(extractYieldedExecCellsFromCodexItem({
type: 'commandExecution',
@@ -203,7 +231,9 @@ describe('formatYieldContinuationPrompt', () => {
]);
expect(prompt).toContain('Wait for cell ID 226');
expect(prompt).toContain('Do not start a new task');
- expect(prompt).toContain('report that it was lost');
+ expect(prompt).toContain('report the actual error');
+ expect(prompt).toContain('Do not rerun the command');
+ expect(prompt).not.toContain('report that it was lost');
expect(prompt).not.toContain('pnpm --filter desktop run typecheck'.repeat(2));
});
});
diff --git a/packages/maker-core/src/agents/codex/yielded-exec-cell.ts b/packages/maker-core/src/agents/codex/yielded-exec-cell.ts
index a4aba1c909..5a1e2e8180 100644
--- a/packages/maker-core/src/agents/codex/yielded-exec-cell.ts
+++ b/packages/maker-core/src/agents/codex/yielded-exec-cell.ts
@@ -5,8 +5,8 @@
* (#3179 rollout: "Script running with cell ID 226")。本模块把那条文案降格为
* **检测启发式**:只用来铸造有界 continuation claim,不参与产品「是否交付完」判断。
*
- * 协议级 executionHandle 是跨仓长期项;在那之前,漏判等于今天的假完成,误判只是
- * 多跑一轮有界续段。
+ * 协议级 executionHandle 是跨仓长期项;在那之前,漏判会造成假完成,误判会
+ * 等待不存在的 cell 并把已完成的工作误报为失败。结构化退出码优先于正文启发式。
*/
export interface YieldedExecCell {
@@ -22,8 +22,8 @@ export interface YieldedExecCell {
* 文案(grep 的 `路径:行号:` 前缀、源码里的缩进+引号、字面 `\n` 转义)都不满足
* 这两条,不再被当成真实 cell 铸造 continuation claim —— 此前误判会让已成功的
* 命令等待不存在的 cell,升级成 yield-continuation-lost-handle 终态失败。
- * 残余盲区:纯文本恰好在列 0 完整复刻两行状态头 —— 与真实执行器输出无法区分,
- * 接受(协议级 executionHandle 落地前的启发式边界)。
+ * 单靠文本无法区分列 0 完整复刻的示例。item 层必须先排除有退出码的命令,
+ * 其 aggregatedOutput 是已退出进程的正文,不是 functions.exec 的状态头。
*/
export const YIELDED_EXEC_CELL_RE =
/(?:^|\r?\n)Script running with cell ID[ \t]+(\d+)(?:[ \t]+|\r?\n)Wall time[ \t]/gi;
@@ -48,6 +48,11 @@ export function extractYieldedExecCellIds(text: string | null | undefined): stri
export function extractYieldedExecCellsFromCodexItem(item: unknown): YieldedExecCell[] {
const record = asRecord(item);
if (!record || !isApprovedYieldItem(record)) return [];
+ // Native command output can contain verbatim executor examples (including
+ // complete status headers). A numeric exit code is stronger evidence than
+ // that text. Do not use status=completed alone: legacy yield wrappers also
+ // complete their item while the cell keeps running, without an exit code.
+ if (record.type === 'commandExecution' && typeof record.exitCode === 'number') return [];
const command = commandFromCodexItem(record);
const ids = extractYieldedExecCellIds(collectItemText(record));
return ids.map((cellId) => (
@@ -97,9 +102,9 @@ export function formatYieldContinuationPrompt(cells: readonly YieldedExecCell[])
: `- cell ID ${cell.cellId}`;
}).join('\n');
return [
- 'A foreground exec cell is still running after the previous turn completed.',
+ 'A foreground exec cell was reported running; its completion has not been confirmed.',
'Wait for every listed cell and finish the original user request. Do not start a new task.',
- 'If a cell is gone, report that it was lost instead of rerunning the command.',
+ 'If waiting fails, report the actual error without assuming the command was lost. Do not rerun the command.',
unique.length === 1 ? `Wait for cell ID ${unique[0]!.cellId}.` : 'Wait for:',
...(unique.length > 1 ? [cellList] : []),
].join('\n');