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(maker-core): emit cancelled yield Done only when tombstone swallows it

Dasha109227c8dc9
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index de5ed75d1b..965812268e 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -99,9 +99,10 @@ timeout 不得触发自动换窗或 replay。Codex 当前没有与 Claude `AutoC
`waitForYieldContinuationIdle()`,同时收掉未完成的 ask_user/plan 卡,不得在用户
已看到失败后再开 ask_user/plan turn。续段启动失败的产品终态只由续段层
发送一次(`yield-continuation-start-failed`),`handle.send` 不得再发一组
- 通用终态。continuation 的 `turn/start` 已被服务端接受后若本地 Stop,即使
- `turnStarted` 已激活、随后 `interrupted` 被墓碑吞掉,也必须发出一条未认领的
- cancelled `done`,避免 Session 仍握着 `currentTurnAttemptToken`。
+ 通用终态。continuation 的 `turn/start` 已被服务端接受、但 RPC 仍 pending 时若
+ 本地 Stop,墓碑会吞掉随后的 `interrupted`,必须补一条未认领 cancelled `done`,
+ 避免 Session 仍握着 `currentTurnAttemptToken`。RPC 已返回后由 provider
+ `interrupted` 发唯一产品 Done,abort 不得再合成一条。
续段必须继承铸造 claim 时的 origin 上下文:`turnPermissionPolicy`、
capability selection 与 auto-review intent。不得把无人值守只读边界重置成普通
Auto,也不得用固定 wait 提示覆盖原请求的能力选择或审查意图。
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index f4dd11e462..c7b0c713cb 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -18375,6 +18375,78 @@ describe('CodexAgent yield continuation', () => {
await handle.close();
});
+ it('lets provider interrupted emit the only unclaimed cancelled done after TurnStart returns', async () => {
+ const agent = new CodexAgent(createDeps());
+ let turnSeq = 0;
+ const host = installFakeHost(agent, (method) => {
+ if (method === Method.TurnStart) {
+ turnSeq += 1;
+ return { turn: { id: `turn-${turnSeq}` } };
+ }
+ if (method === Method.TurnInterrupt) return {};
+ return undefined;
+ });
+ const handle = await agent.startSession({
+ sessionId: 'session-yield-stop-after-start-resp',
+ model: 'gpt-5.4',
+ workingDir: '/repo',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.itemCompleted || !handlers.turnCompleted || !handlers.turnStarted) {
+ throw new Error('expected item, turn, and started handlers');
+ }
+ const events = await collectYieldEvents(handle);
+ await handle.send({ type: 'user', content: 'run typecheck' });
+ handlers.itemCompleted({
+ threadId: 'start-thread-id',
+ turnId: 'turn-1',
+ item: {
+ id: 'item-exec-stop-after-resp',
+ type: 'commandExecution',
+ command: 'pnpm --filter desktop run typecheck',
+ status: 'completed',
+ aggregatedOutput: 'Script running with cell ID 226',
+ },
+ });
+ handlers.turnCompleted({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-1', status: 'completed' },
+ });
+ await vi.waitFor(() => {
+ expect(yieldTurnStartCalls(host)).toHaveLength(1);
+ });
+ handlers.turnStarted({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-2', status: 'inProgress' },
+ });
+ expect(handle.getCurrentTurnId?.()).toBe('turn-2');
+ await handle.abort();
+ await waitForExpectation(() => {
+ expect(host.request).toHaveBeenCalledWith(Method.TurnInterrupt, {
+ threadId: 'start-thread-id',
+ turnId: 'turn-2',
+ });
+ });
+ expect(events.filter((event) => (
+ event.type === 'done'
+ && event.turnContinuationId == null
+ && (event.data as { cancelled?: boolean }).cancelled === true
+ ))).toHaveLength(0);
+ handlers.turnCompleted({
+ threadId: 'start-thread-id',
+ turn: { id: 'turn-2', status: 'interrupted' },
+ });
+ await waitForExpectation(() => {
+ expect(events.filter((event) => (
+ event.type === 'done'
+ && event.turnContinuationId == null
+ && (event.data as { cancelled?: boolean }).cancelled === true
+ ))).toHaveLength(1);
+ });
+ expect(handle.isTurnRunning?.()).toBe(false);
+ await handle.close();
+ });
+
it('does not mint a claim from an agentMessage quoting a yield marker', async () => {
const agent = new CodexAgent(createDeps());
const host = installFakeHost(agent, (method) => {
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 88aaabc1ef..be0f9b7f19 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -12019,11 +12019,13 @@ export class CodexAgent extends BaseAgent {
async abort() {
const cancelledYield = cancelActiveYieldContinuation('aborted');
- // isolateCancelledTurnStart tombstones the accepted turn and swallows
- // interrupted turn/completed. Emit the unclaimed cancelled done here so
- // Session releases currentTurnAttemptToken even if turnStarted already
- // activated the continuation and the RPC is still pending.
- if (cancelledYield) {
+ // isolateCancelledTurnStart tombstones an accepted turn whose TurnStart
+ // RPC is still pending, and that tombstone swallows interrupted
+ // turn/completed. Only then emit an unclaimed cancelled done so Session
+ // releases currentTurnAttemptToken. After the RPC has returned,
+ // provider interrupted already emits one product Done — synthesizing
+ // another here would settle the next attempt.
+ if (cancelledYield && isTurnStartPending) {
emitCancelledYieldProductDone();
}
clearReconnectStall();