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): WeCom/WeChat 投递失败改用稳定系统拒绝码

MagicLizid1fb9fa04cd4
diff --git a/apps/desktop/src/main/im/wechat/WechatIM.ts b/apps/desktop/src/main/im/wechat/WechatIM.ts
index 862a319865..806d92e76e 100644
--- a/apps/desktop/src/main/im/wechat/WechatIM.ts
+++ b/apps/desktop/src/main/im/wechat/WechatIM.ts
@@ -503,16 +503,15 @@ export class WechatIM extends BaseIM implements RichChannelIM {
this.#pendingInteractions.set(userId, { request, resolve: resolvePending, timer });
try {
await this.sendText(userId, formatWechatInteractionPrompt(request));
- } catch (error) {
+ } catch {
const pending = this.#pendingInteractions.get(userId);
if (pending?.request.requestId === request.requestId) {
clearTimeout(pending.timer);
this.#pendingInteractions.delete(userId);
}
- return defaultWechatInteractionDecision(
- request,
- error instanceof Error ? error.message : 'wechat_interaction_send_failed',
- );
+ // Denial reasons are classified by exact/prefix match. Raw Error.message
+ // is not a system code and would be presented as a user rejection.
+ return defaultWechatInteractionDecision(request, 'wechat_interaction_send_failed');
}
return result;
}
diff --git a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
index 08aa7bbc50..6fdd419a9d 100644
--- a/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
+++ b/apps/desktop/src/main/im/wechat/__tests__/WechatIM.test.ts
@@ -239,6 +239,22 @@ describe('WechatIM host boundary', () => {
});
});
+ it('投递失败时用稳定系统码收口,不把 Error.message 当成拒绝原因', async () => {
+ const im = new WechatIM(deps());
+ vi.spyOn(im, 'sendText').mockRejectedValue(new Error('socket hang up'));
+
+ await expect(im.handleTextInteraction('peer-1', {
+ kind: 'permission',
+ requestId: 'request-send-failed',
+ toolName: 'bash',
+ input: { command: 'pnpm test' },
+ })).resolves.toEqual({
+ kind: 'permission',
+ behavior: 'deny',
+ reason: 'wechat_interaction_send_failed',
+ });
+ });
+
it('fails closed before authorization when the signed compatibility policy disables it', async () => {
const createTransport = vi.fn();
const im = new WechatIM(
diff --git a/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts b/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts
index ca9796c4a8..ce5d9448f5 100644
--- a/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts
+++ b/apps/desktop/src/main/im/wecom/__tests__/textInteractions.test.ts
@@ -128,4 +128,24 @@ describe('formatWecomInteractionPrompt', () => {
});
expect(sendText).not.toHaveBeenCalled();
});
+
+ it('投递失败时用稳定系统码收口,不把 Error.message 当成拒绝原因', async () => {
+ const sendMarkdownText = vi.fn(async () => {
+ throw new Error('Request failed with status code 500');
+ });
+ const im = {
+ onTextMessageIntercept: vi.fn(() => () => undefined),
+ onStatusChange: vi.fn(() => () => undefined),
+ sendMarkdownText,
+ sendText: vi.fn(),
+ } as unknown as WecomIM;
+ const interactions = new WecomTextInteractions(im);
+
+ await expect(interactions.handle('owner', permissionRequest({ command: 'pnpm test' })))
+ .resolves.toEqual({
+ kind: 'permission',
+ behavior: 'deny',
+ reason: 'wecom_interaction_send_failed',
+ });
+ });
});
diff --git a/apps/desktop/src/main/im/wecom/textInteractions.ts b/apps/desktop/src/main/im/wecom/textInteractions.ts
index 94f79692f8..65068fcb3a 100644
--- a/apps/desktop/src/main/im/wecom/textInteractions.ts
+++ b/apps/desktop/src/main/im/wecom/textInteractions.ts
@@ -44,16 +44,15 @@ export class WecomTextInteractions {
try {
await this.im.sendMarkdownText(userId, formatWecomInteractionPrompt(request));
- } catch (error) {
+ } catch {
const current = this.pending.get(userId);
if (current?.request.requestId === request.requestId) {
clearTimeout(current.timer);
this.pending.delete(userId);
}
- return defaultDecision(
- request,
- error instanceof Error ? error.message : 'wecom_interaction_send_failed',
- );
+ // Denial reasons are classified by exact/prefix match. Raw Error.message
+ // is not a system code and would be presented as a user rejection.
+ return defaultDecision(request, 'wecom_interaction_send_failed');
}
return result;
}
diff --git a/packages/maker-core/src/agents/shared/auto-review-decision.test.ts b/packages/maker-core/src/agents/shared/auto-review-decision.test.ts
index 13027970fe..f2dda9a081 100644
--- a/packages/maker-core/src/agents/shared/auto-review-decision.test.ts
+++ b/packages/maker-core/src/agents/shared/auto-review-decision.test.ts
@@ -370,6 +370,8 @@ describe('isSystemPermissionDenialReason', () => {
expect(isSystemPermissionDenialReason('orca_disable')).toBe(true);
expect(isSystemPermissionDenialReason('session_running_race')).toBe(true);
expect(isSystemPermissionDenialReason('turn_not_dispatched')).toBe(true);
+ expect(isSystemPermissionDenialReason('Request failed with status code 500')).toBe(false);
+ expect(isSystemPermissionDenialReason('socket hang up')).toBe(false);
expect(isSystemPermissionDenialReason('User denied')).toBe(false);
expect(isSystemPermissionDenialReason('wechat_user_denied')).toBe(false);
expect(isSystemPermissionDenialReason('wecom_user_denied')).toBe(false);