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(desktop): Git 核实期间被取消的凭证请求不再进入确认排队

fmfsaisai69043b683d71
diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts
index 84d781f92c..e51c891b2d 100644
--- a/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts
+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts
@@ -1225,6 +1225,34 @@ describe('shared provider credentials', () => {
}
});
+ it('does not queue a git command cancelled while it was being verified', async () => {
+ let finishCheck!: (safe: boolean) => void;
+ const gitCredentials = {
+ provesSafe: () => new Promise<boolean>((resolve) => { finishCheck = resolve; }),
+ } as unknown as GitCredentialHistory;
+ let answer!: (result: ExecutorConfirmation) => void;
+ const asked = vi.fn(() => new Promise<ExecutorConfirmation>((resolve) => { answer = resolve; }));
+ const { executor } = sharedExecutor('full', asked, gitCredentials);
+ const env: ExecutorAction = { kind: 'exec', command: 'cat .env', cwd: project };
+ const git: ExecutorAction = { kind: 'exec', command: 'git remote show origin', cwd: project };
+ const pending = executor.confirm(env);
+ const abort = new AbortController();
+ try {
+ const checking = executor.confirm(git, abort.signal);
+ abort.abort();
+ finishCheck(false);
+ // 第一张卡还没回答:已取消的请求不能排在它后面等。
+ expect(await checking).toBe(false);
+ expect(asked).toHaveBeenCalledTimes(1);
+ answer(true);
+ expect(await pending).toBe(true);
+ } finally {
+ await executor.close();
+ answer(false);
+ await pending;
+ }
+ });
+
it('does not queue a verified git command behind an unanswered credential card', async () => {
const gitCredentials = {
provesSafe: async () => true,
diff --git a/apps/desktop/src/main/remote-agent/executor/executor.ts b/apps/desktop/src/main/remote-agent/executor/executor.ts
index 0d027bc64f..21db6c453d 100644
--- a/apps/desktop/src/main/remote-agent/executor/executor.ts
+++ b/apps/desktop/src/main/remote-agent/executor/executor.ts
@@ -186,6 +186,8 @@ export class RemoteExecutor {
this.gate.recordCredentialExemption(action);
return true;
}
+ // 核实需要时间:期间请求被取消就不再排队(abort 事件不会重放给之后登记的监听)。
+ if (gitCheck && (this.closed || signal?.aborted || permissionGeneration !== this.permissionGeneration)) return false;
// 同一任务可能并行调用工具。只排队确认,不排队执行;前一张卡建立任务授权后,
// 后续请求重新检查,避免已经弹出的多张卡仍逐一等待用户回答。
// 排队位置要等前一个位置放行、且自己的卡处理完才放行。