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): avoid silent file-change rejection

david5d20ee28861e
diff --git a/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts b/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts
index 3fb466e78d..a223c3d999 100644
--- a/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts
+++ b/apps/desktop/src/main/__tests__/makerEventHotPathOrdering.test.ts
@@ -412,10 +412,9 @@ describe('maker:event hot path ordering', () => {
expect(epochCaptureIndex).toBeGreaterThanOrEqual(0);
expect(currentEpochCheckIndex).toBeGreaterThan(epochCaptureIndex);
expect(flushIndex).toBeGreaterThan(currentEpochCheckIndex);
- expect(broadcastIndex).toBeGreaterThan(flushIndex);
- expect(broadcastIndex).toBeGreaterThanOrEqual(0);
- expect(pendingIndex).toBeGreaterThan(broadcastIndex);
- expect(islandIndex).toBeGreaterThan(pendingIndex);
+ expect(pendingIndex).toBeGreaterThan(flushIndex);
+ expect(broadcastIndex).toBeGreaterThan(pendingIndex);
+ expect(islandIndex).toBeGreaterThan(broadcastIndex);
expect(interactionListenerSource.slice(0, broadcastIndex)).not.toContain('handleInteractionRequest(');
expect(source).toContain('Agent Island interaction update failed after maker interaction broadcast');
});
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index a14c088d07..138a5c4fa9 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -3248,11 +3248,6 @@ export function installDesktopInteractionListener(session: {
planFilePath?: unknown;
},
);
- broadcastToAllWindows(MAKER_PUSH.INTERACTION_REQUEST, {
- sessionId: session.id,
- request: req,
- persistId: interactionPersistId,
- });
return new Promise<InteractionDecision>((resolve) => {
const entry: PendingInteractionEntry = {
sessionId: session.id,
@@ -3270,7 +3265,14 @@ export function installDesktopInteractionListener(session: {
dismissRendererInteraction(pending, req.requestId, 'timeout', 'deny');
}, PERMISSION_INTERACTION_TIMEOUT_MS);
}
+ // Register before delivery so a fast renderer/device response cannot race
+ // the resolver and be discarded as an unknown request.
pendingInteractionResolvers.set(req.requestId, entry);
+ broadcastToAllWindows(MAKER_PUSH.INTERACTION_REQUEST, {
+ sessionId: session.id,
+ request: req,
+ persistId: interactionPersistId,
+ });
handleAgentIslandInteractionAfterBroadcast(
session as { id: string; agentKind?: unknown; workDir?: unknown; workspaceKind?: unknown },
req,
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index 700605f893..13bd7ba7f7 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -11664,6 +11664,67 @@ describe('CodexAgent MCP thread context hooks', () => {
await handle.close();
});
+ it('asks the user when a file-change approval omits grantRoot', async () => {
+ const reviewAutoPermissionAction = vi.fn<AutoReviewDelegate>(async () => ({
+ verdict: 'block' as const,
+ reason: 'The destination path is missing.',
+ }));
+ const agent = new CodexAgent(createDeps({}, { reviewAutoPermissionAction }));
+ const host = installFakeHost(agent);
+ const handle = await agent.startSession({
+ sessionId: 'session-auto-file-change-without-root',
+ model: 'gpt-5.5',
+ providerId: 'xd',
+ workingDir: '/repo',
+ permissionMode: 'auto',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.fileChangeApproval) throw new Error('expected fileChangeApproval handler');
+ const resolver = vi.fn(async (): Promise<InteractionDecision> => (
+ { kind: 'permission', behavior: 'allow' }
+ ));
+ handle.setInteractionResolver(resolver);
+
+ await expect(handlers.fileChangeApproval({
+ threadId: 'start-thread-id',
+ turnId: 'turn-file-change-without-root',
+ itemId: 'patch-without-root',
+ grantRoot: null,
+ })).resolves.toEqual({ decision: 'accept' });
+
+ expect(reviewAutoPermissionAction).not.toHaveBeenCalled();
+ expect(resolver).toHaveBeenCalledOnce();
+ expect(resolver.mock.calls[0]?.[0]).toMatchObject({
+ kind: 'permission',
+ toolName: 'file_change',
+ input: { grantRoot: null },
+ suggestions: undefined,
+ });
+ await handle.close();
+ });
+
+ it('keeps Full access non-interactive when a file-change approval omits grantRoot', async () => {
+ const agent = new CodexAgent(createDeps());
+ const host = installFakeHost(agent);
+ const handle = await agent.startSession({
+ sessionId: 'session-full-file-change-without-root',
+ model: 'gpt-5.5',
+ providerId: 'xd',
+ workingDir: '/repo',
+ permissionMode: 'bypassPermissions',
+ });
+ const handlers = host.getThreadHandlers();
+ if (!handlers?.fileChangeApproval) throw new Error('expected fileChangeApproval handler');
+
+ await expect(handlers.fileChangeApproval({
+ threadId: 'start-thread-id',
+ turnId: 'turn-full-file-change-without-root',
+ itemId: 'full-patch-without-root',
+ grantRoot: null,
+ })).resolves.toEqual({ decision: 'accept' });
+ await handle.close();
+ });
+
it('re-checks Ask and Full access after an in-flight Cindy auto-review', async () => {
const askReview = deferred<{ verdict: 'allow' }>();
const askReviewer = vi.fn(() => askReview.promise);
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 7145e0f53d..0aa6317ec5 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -6354,6 +6354,13 @@ export class CodexAgent extends BaseAgent {
suggestions: codexSessionApprovalSuggestions(),
metadata: params.reason ? { reason: params.reason } : undefined,
}, {
+ // Codex may omit grantRoot for ordinary apply_patch requests. Without a
+ // concrete target the lightweight reviewer cannot classify the write,
+ // but silently declining is surfaced by app-server as "rejected by user"
+ // even though no user interaction happened. Escalate that protocol gap
+ // to a real confirmation; unattended callers still fail closed when no
+ // interaction resolver is available.
+ forcePrompt: mutablePermissionMode === 'auto' && !params.grantRoot?.trim(),
autoReviewAction: { kind: 'file-write', path: params.grantRoot ?? undefined },
itemId: params.itemId,
});