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): 修复禁用 Fast 时子 Agent 导致发送失败

yanc8885ab2c895
diff --git a/docs/subscription-fast-policy.md b/docs/subscription-fast-policy.md
index 76c5f59c91..39ad62ca40 100644
--- a/docs/subscription-fast-policy.md
+++ b/docs/subscription-fast-policy.md
@@ -39,12 +39,16 @@
同一轮中先禁止、再重新允许,出口仍保持普通档,直到用户明确再次启用 Fast。该状态按当前 owner、任务和实际订阅来源隔离,不会串到其他任务或自定义 API;执行侧的模式变化也同步到本机运行时偏好,避免 bridge 和用量记录继续使用旧档。
-原生设置更新失败时不能谎报成功:保留限制并重试;组页面显示部分电脑尚未确认设置。此时尚未确认的旧版或离线电脑不能作为已经受控的执行电脑使用。
+Codex 只向根线程同步原生设置,子 Agent 的服务档位由原生引擎继承;不向子线程直接发送 `thread/settings/update`,因为 Multi-Agent V2 会拒绝该操作。[官方子 Agent 配置说明](https://developers.openai.com/codex/subagents)也明确服务档位跟随根会话。HTTP 和 WebSocket 请求出口仍按任务所属的订阅策略强制使用普通档,覆盖原生引擎残留的旧档位。
+
+在已经启用可信 Codex 请求代理的执行电脑上,原生设置同步只做尽力更新;同步失败记录警告,不阻断普通发送,禁止 Fast 的最终保证在请求出口。没有该出口时仍要求原生禁用成功。Claude 等依赖原生设置的路径不改变失败处理。
+
+执行限制无法保证时不能谎报成功:保留限制并重试;组页面显示部分电脑尚未确认设置。此时尚未确认的旧版或离线电脑不能作为已经受控的执行电脑使用。
### 旧版与离线电脑
1. 执行电脑声明 `subscriptionFastPolicy` 能力。
-2. 组所在电脑发送带修订号的限制,实际执行电脑持久化并更新原生会话后确认。
+2. 组所在电脑发送带修订号的限制,实际执行电脑持久化并建立执行保护后确认;Codex 的可信请求出口与原生设置同步按上述边界处理。
3. 新分配必须先完成绑定;组禁止 Fast 时,不能把未确认的旧版执行电脑当成成功。
4. 开启自动换电脑时,按既有策略尝试其他可用成员。
5. 未确认设置每 5 秒重试,不重建共享的 device-link 连接。
@@ -125,6 +129,16 @@
### 单元与回归
+2026-10-26 的 V2 子 Agent 兼容修复验证:
+
+- `CodexAgent.startSession` + 真实 `withFastModePolicy` 经过 V2 子线程登记、完成、再次发送,验证普通消息成功且设置 RPC 只发根线程;另验证原生同步失败时,有代理继续普通发送、无代理仍拒绝。原实现的前两种情况先复现失败,修复后三项通过,未放宽已有断言。
+- Core 的完整 Codex 与策略套件 1050 项通过,墙钟 43.30 秒(含收集);复用已有 1042 项的大文件及其原生协议/生命周期夹具,新三项测试体共约 112 毫秒,未增加模块重置、真实等待或新测试文件。设置通道单独选测 11 项通过,墙钟 3.71 秒。
+- Desktop 请求出口与策略 15 项、真实 Windows Codex 0.159.2 + loopback 代理/模拟上游 1 项通过,墙钟合计 11.01 秒;原生用例实际执行而非跳过,只用临时 HOME 和合成凭证。V2 拒绝响应由进程内假上游复现,未宣称双机或真实付费子 Agent 已实测。
+- Desktop 全量 typecheck、test hygiene(原基线内 361 文件)、文档合同 10 项与 diff 检查通过。
+- 完成五轮独立复查,并由五个 Orca DS Worker 分别审查原生协议、HTTP/WS 出口与信任边界、并发和生命周期、范围兼容、测试有效性;五侧均未发现必须修缺陷。协议侧首次异常终止未计作通过,同一 Worker 重试后形成结论。没有用禁用子 Agent、跳过登记或弱化断言规避错误。
+- 最终 rebase 到上游 `8cc032d9`,无冲突且 range-diff 确认修复内容等价;随后 Core 三文件 1104 项通过(37.70 秒),Desktop 三文件 16 项通过(10.65 秒),包括真实二进制的 loopback 用例。原 Codex 测试文件单独运行 1045 项通过(30.31 秒)。未完成真实 V2 子 Agent、macOS、不同物理电脑或无代理旧 V1 继承实测;这些边界仍如实保留。
+- Core 独立 build 仍有三条上游 `TS2339`:`recipe-loader.ts:205,227` 的 `ImportMeta.glob` 与 `pi-native-auto-compact.test.ts:764` 的 `modelOverrides`。用编译器内存覆盖将两个改动文件还原为上游 `a7e1b800` 后重跑,诊断逐条相同;没有修改工作区文件或类型配置来绕过它们。ESLint 同样与上游逐诊断对照:生产文件 4 条、既有测试文件 33 条,均无新增。
+
以下为本次执行过的主要批次;批次有重叠,不应简单相加为独立用例数。
| 批次 | 结果 |
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index fe5ac7ffa8..642b285d3c 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -12,6 +12,7 @@ import {
} from './index.js';
import { CodexForkError } from './fork-error.js';
import { Session } from '../../session.js';
+import { withFastModePolicy } from '../shared/fast-mode-policy.js';
import { AUTO_REVIEW_CONTINUATION_POLICY } from '../shared/continuation-policy.js';
import { Method, type TurnStartParams } from './app-server/protocol.js';
import type { Effort } from '../../types/common.js';
@@ -7438,6 +7439,84 @@ describe('CodexAgent fast mode service tier', () => {
});
describe('CodexAgent thread/settings/update channel', () => {
+ // Unit regression for #6894: use the real adapter + send policy wrapper.
+ // Previous tests had no descendant when enforcing a prohibition. V2 rejects
+ // direct child settings; creating/completing one must not break the next send.
+ it('continues standard-mode sends after a V2 descendant completes without updating child settings', async () => {
+ const agent = new CodexAgent(createDeps());
+ let turns = 0;
+ const host = installFakeHost(agent, (method, params) => {
+ if (method === Method.ThreadSettingsUpdate) {
+ if ((params as { threadId: string }).threadId !== 'start-thread-id') {
+ throw new Error('codex app-server thread/settings/update error -32600: direct app-server input is not allowed for multi-agent v2 sub-agents');
+ }
+ return {};
+ }
+ if (method === Method.TurnStart) return { turn: { id: `turn-${++turns}` } };
+ return undefined;
+ }, { codexProxyActive: true });
+ const policy = { isAllowed: () => false, subscribe: () => () => {} };
+ const handle = withFastModePolicy(await agent.startSession({
+ sessionId: 's-policy-v2', model: 'gpt-5.4', workingDir: '/repo',
+ fastMode: true, fastModePolicy: policy,
+ }), policy);
+ try {
+ await handle.send({ type: 'user', content: 'spawn a child' }, { throwOnStartFailure: true });
+ const handlers = host.getThreadHandlers()!;
+ handlers.itemStarted!({
+ threadId: 'start-thread-id', turnId: 'turn-1',
+ item: { id: 'spawn-v2', type: 'subAgentActivity', kind: 'started', agentThreadId: 'child-v2' },
+ });
+ handlers.descendantNotification!('child-v2', 'turn/completed', {
+ threadId: 'child-v2', turn: { id: 'child-turn', status: 'completed' },
+ });
+ handlers.turnCompleted!({ threadId: 'start-thread-id', turn: { id: 'turn-1', status: 'completed' } });
+ await handle.send({ type: 'user', content: 'hello' }, { throwOnStartFailure: true });
+ await handle.setFastMode!('ultrafast');
+ expect(turns).toBe(2);
+ expect(handle.getFastMode!()).toBe(false);
+ expect(host.registerDescendantLineage).toHaveBeenCalledWith('child-v2', 'start-thread-id');
+ const updates = host.request.mock.calls.filter(([method]) => method === Method.ThreadSettingsUpdate);
+ expect(updates.length).toBeGreaterThan(0);
+ expect(updates.every(([, params]) =>
+ (params as { threadId: string; serviceTier: unknown }).threadId === 'start-thread-id' &&
+ (params as { serviceTier: unknown }).serviceTier === null)).toBe(true);
+ const turnCalls = host.request.mock.calls.filter(([method]) => method === Method.TurnStart);
+ expect(turnCalls.every(([, params]) => (params as { serviceTier: unknown }).serviceTier === null)).toBe(true);
+ } finally {
+ await handle.close();
+ }
+ });
+
+ // A proxy enforces the wire policy even if native settings are unavailable;
+ // without that exit, native enforcement must still fail closed.
+ it.each([true, false])('handles a failed root policy update with proxy=%s', async codexProxyActive => {
+ const agent = new CodexAgent(createDeps());
+ const host = installFakeHost(agent, method => {
+ if (method === Method.ThreadSettingsUpdate) throw new Error('native settings unavailable');
+ if (method === Method.TurnStart) return { turn: { id: 'turn-1' } };
+ return undefined;
+ }, { codexProxyActive });
+ const policy = { isAllowed: () => false, subscribe: () => () => {} };
+ const handle = withFastModePolicy(await agent.startSession({
+ sessionId: 's-policy-root', model: 'gpt-5.4', workingDir: '/repo', fastModePolicy: policy,
+ }), policy);
+ try {
+ const send = handle.send({ type: 'user', content: 'hello' }, { throwOnStartFailure: true });
+ if (codexProxyActive) {
+ await expect(send).resolves.toBeUndefined();
+ expect(host.request.mock.calls.find(([method]) => method === Method.TurnStart)?.[1])
+ .toMatchObject({ serviceTier: null });
+ expect(handle.getFastMode!()).toBe(false);
+ } else {
+ await expect(send).rejects.toThrow('native settings unavailable');
+ expect(host.request.mock.calls.some(([method]) => method === Method.TurnStart)).toBe(false);
+ }
+ } finally {
+ await handle.close();
+ }
+ });
+
it('forces standard native requests despite stale tier defaults, notifications and re-enables under a host prohibition', async () => {
const agent = new CodexAgent(createDeps());
const host = installFakeHost(agent, method => method === Method.ThreadSettingsUpdate ? {} : method === Method.ThreadStart ? {
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 22eb8aed23..f879abf74e 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -6088,10 +6088,8 @@ assertRouteCurrent();
if (descendantThreadId === threadId || descendantMcpThreadIds.has(descendantThreadId)) return;
descendantMcpThreadIds.add(descendantThreadId);
registerCodexMcpContext(descendantThreadId, 'descendant');
- if (opts.fastModePolicy?.isAllowed() === false) {
- void host.request(Method.ThreadSettingsUpdate, { threadId: descendantThreadId, serviceTier: null })
- .catch(error => log.warn('descendant standard-mode update failed', { error: String(error) }));
- }
+ // Native descendants inherit the root tier. V2 rejects direct child
+ // settings updates; the trusted request exit also clamps stale tiers.
};
const unregisterDescendantCodexMcpContexts = (): void => {
for (const descendantThreadId of descendantMcpThreadIds) {
@@ -7296,10 +7294,12 @@ assertRouteCurrent();
* 回带的 thread/settings/updated 通知会乱序到达, reconcile 出现中间态闪现 (实测过
* null→fast→default)。串行后 server 按序处理、通知按序回, 最终态一次到位。
* - serviceTier 双 Option: 调用方传 'fast' (开) / null (清空); 不传该 key = 不变。
- * - **失败吞错**: settings/update 失败绝不抛 — turn/start 携带仍是兜底, 会话不受
- * 影响。server 回 ack 后真正状态经 thread/settings/updated 通知回带 (见 handlers)。
+ * - 只更新根线程,子线程由原生继承;V2 禁止直接更新子线程。
+ * - settings/update 失败通常只记录警告,后续 turn/start 与可信请求出口继续兜底。
+ * 仅在必须禁止 Fast 且没有请求代理时抛错,避免把未受保护的发送当作成功。
+ * server 回 ack 后真正状态经 thread/settings/updated 通知回带 (见 handlers)。
*
- * 返回入队任务的 promise (链已 catch, 永不 reject), 调用方可 await 到本次发送完成。
+ * 返回本次入队任务的 promise;队列本身恢复后续任务,不吞必须执行的失败。
*/
let settingsUpdateChain: Promise<void> = Promise.resolve();
const pushThreadSettings = (patch: Omit<ThreadSettingsUpdateParams, 'threadId'>, requireApplied = false): Promise<void> => {
@@ -7309,15 +7309,16 @@ assertRouteCurrent();
if (skipIfStaleHost('thread/settings/update')) return;
try {
const effectivePatch = opts.fastModePolicy?.isAllowed() === false ? { ...patch, serviceTier: null } : patch;
- await Promise.all([threadId, ...(requireApplied ? descendantMcpThreadIds : [])].map(id =>
- host.request<ThreadSettingsUpdateResponse>(Method.ThreadSettingsUpdate, { threadId: id, ...effectivePatch })));
+ await host.request<ThreadSettingsUpdateResponse>(Method.ThreadSettingsUpdate, { threadId, ...effectivePatch });
} catch (e) {
- log.warn('thread/settings/update failed (turn/start carry remains fallback)', {
+ const mustApplyNative = requireApplied && !hostUsesCodexProxy;
+ log.warn('thread/settings/update failed', {
threadId,
patchKeys: Object.keys(patch),
+ mustApplyNative,
error: e instanceof Error ? e.message : String(e),
});
- if (requireApplied) throw e;
+ if (mustApplyNative) throw e;
}
});
settingsUpdateChain = run.catch(() => undefined);