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): keep yield claims across ask_user and plan follow-ups

Dashb9094f989c4b
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index adc771d899..e4c0c98896 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -17726,6 +17726,76 @@ describe('CodexAgent yield continuation', () => {
await handle.close();
});
+ it('does not cancel a yield claim when ask_user continuation starts', 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}` } };
+ }
+ return undefined;
+ });
+ const handle = await agent.startSession({
+ sessionId: 'session-yield-ask-user-internal',
+ model: 'gpt-5.4',
+ workingDir: '/repo',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.itemCompleted || !handlers.turnCompleted || !handlers.requestUserInput) {
+ throw new Error('expected item, turn, and user-input handlers');
+ }
+ const ownerDecision = deferred<InteractionDecision>();
+ handle.setInteractionResolver(async () => ownerDecision.promise);
+ const events = await collectYieldEvents(handle);
+ await handle.send({ type: 'user', content: 'run typecheck' });
+ void handlers.requestUserInput({
+ threadId: 'start-thread-id',
+ turnId: 'turn-1',
+ itemId: 'item-ask',
+ questions: [{
+ id: 'native-q1',
+ header: 'Question',
+ question: 'Pick one',
+ isOther: false,
+ isSecret: false,
+ options: [{ label: 'A', description: null }],
+ }],
+ }, { requestId: 'req-ask' });
+ handlers.itemCompleted({
+ threadId: 'start-thread-id',
+ turnId: 'turn-1',
+ item: {
+ id: 'item-exec-ask',
+ 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 waitForExpectation(() => {
+ expect(events.some((event) => event.type === 'done' && event.turnContinuationId != null)).toBe(true);
+ });
+ await vi.waitFor(() => {
+ expect(yieldTurnStartCalls(host)).toHaveLength(1);
+ });
+ ownerDecision.resolve({
+ kind: 'ask_user_question',
+ answers: { 'Pick one': 'A' },
+ });
+ await vi.waitFor(() => {
+ expect(host.request.mock.calls.filter(([method]) => method === Method.TurnStart)).toHaveLength(3);
+ });
+ const claimedDone = events.find((event) => event.type === 'done' && event.turnContinuationId != null);
+ expect(handle.beginTurnContinuationWait?.(claimedDone?.turnContinuationId)).toBe('active');
+ expect(handle.isTurnRunning?.()).toBe(true);
+ await handle.close();
+ });
+
it('emits a terminal error when the yield continuation cannot start', async () => {
const agent = new CodexAgent(createDeps());
let turnStarts = 0;
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 952f85cb2e..144339a2f9 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -1164,11 +1164,13 @@ const CODEX_INHERITED_CAPABILITY_SELECTION = Symbol('codexInheritedCapabilitySel
// 直接拿它当 review intent 会让灰区 reviewer 完全看不到用户原始请求与获批计划(codex 报)。
const CODEX_AUTO_REVIEW_INTENT = Symbol('codexAutoReviewIntent');
const CODEX_YIELD_CONTINUATION = Symbol('codexYieldContinuation');
+const CODEX_INTERNAL_CONTINUATION = Symbol('codexInternalContinuation');
const YIELD_CONTINUATION_MAX_ATTEMPTS = 2;
type CodexInternalSendOptions = SendOptions & {
[CODEX_INHERITED_CAPABILITY_SELECTION]?: string;
[CODEX_AUTO_REVIEW_INTENT]?: string;
[CODEX_YIELD_CONTINUATION]?: number;
+ [CODEX_INTERNAL_CONTINUATION]?: true;
};
type YieldContinuationClaim = {
id: number;
@@ -3335,6 +3337,7 @@ export class CodexAgent extends BaseAgent {
yieldContinuationAbort = abort;
const sendOptions: CodexInternalSendOptions = {
[CODEX_YIELD_CONTINUATION]: claim.retryCount + 1,
+ [CODEX_INTERNAL_CONTINUATION]: true,
throwOnStartFailure: true,
signal: abort.signal,
};
@@ -5898,6 +5901,7 @@ export class CodexAgent extends BaseAgent {
.filter(Boolean)
.join('\n'),
...(autoReviewIntent ? { [CODEX_AUTO_REVIEW_INTENT]: autoReviewIntent } : {}),
+ [CODEX_INTERNAL_CONTINUATION]: true,
});
const emitPlanFollowUpStartFailure = (kind: 'implementation' | 'revision', error: unknown): void => {
log.warn(`plan ${kind} turn failed to start`, { error: String(error) });
@@ -6287,6 +6291,7 @@ export class CodexAgent extends BaseAgent {
? { [CODEX_INHERITED_CAPABILITY_SELECTION]: live.capabilitySelectionText }
: {}),
...(autoReviewIntent ? { [CODEX_AUTO_REVIEW_INTENT]: autoReviewIntent } : {}),
+ [CODEX_INTERNAL_CONTINUATION]: true,
};
try {
await handle.send({ type: 'user', content: message }, sendOptions);
@@ -10841,8 +10846,9 @@ export class CodexAgent extends BaseAgent {
if (rejectClosedOrCancelledSend(sendOpts, 'before start')) {
return;
}
- const yieldAttempt = (sendOpts as CodexInternalSendOptions | undefined)?.[CODEX_YIELD_CONTINUATION];
- if (yieldAttempt == null) {
+ const internalOpts = sendOpts as CodexInternalSendOptions | undefined;
+ const yieldAttempt = internalOpts?.[CODEX_YIELD_CONTINUATION];
+ if (yieldAttempt == null && internalOpts?.[CODEX_INTERNAL_CONTINUATION] !== true) {
cancelActiveYieldContinuation('new send');
}
// 用户开启新 turn = 旧重连序列作废;deadline 不得跨 turn 误伤新请求。