fix(wechat): fallback manage LLM providers when chat balance is exhausted
Memind CI / Test, build, and release guards (push) Failing after 4m34s

When DeepSeek returns 402, try other chat providers before giving up, and cancel the sole active task only during LLM outages so user 123 can cancel without Goose.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-29 14:02:48 +08:00
parent 5de58af9ed
commit 6db460eb89
4 changed files with 218 additions and 29 deletions
+14
View File
@@ -91,6 +91,20 @@ export async function handleWechatScheduledTaskIntent({
if (decision.action === 'clarify') {
return decision.message;
}
if (decision.llmUnavailable) {
if (tasks.length === 1) {
logger.warn?.(
'[wechat-scheduled-task] outage fallback cancel for single active task',
{ userId: user.userId, taskId: tasks[0].id },
);
const cancelled = await scheduledTaskService.cancelTask({
userId: user.userId,
taskId: tasks[0].id,
});
return formatScheduledTaskCancelReply(cancelled);
}
return '暂时无法连接模型来识别要取消的任务,请稍后再试,或明确说出任务名称。';
}
}
return null;
+50
View File
@@ -131,6 +131,56 @@ test('handleWechatScheduledTaskIntent passes cancel to goose when manage llm is
assert.equal(reply, null);
});
test('handleWechatScheduledTaskIntent outage-fallback cancels sole active task when manage llm is unavailable', async () => {
const calls = [];
const reply = await handleWechatScheduledTaskIntent({
intent: {
msgType: 'text',
agentText: '取消定时推送苏州天气任务',
msgId: 'msg-123-outage',
},
user: { userId: 'user-123' },
scheduledTaskService: {
async listTasks() {
return [{
id: 'task-suzhou',
title: '每天早上6:30推送苏州市天气预报',
recurrence: 'daily',
hour: 6,
minute: 30,
timezone: 'Asia/Shanghai',
}];
},
async cancelTask(payload) {
calls.push(payload);
return {
id: 'task-suzhou',
title: '每天早上6:30推送苏州市天气预报',
status: 'cancelled',
};
},
},
wechatScheduledTaskManageLlmConfigService: {
async isManageLlmEnabled() {
return true;
},
async getConfig() {
return { modelProviderKeyId: 'deepseek-key', model: 'deepseek-chat' };
},
},
llmProviderService: {
async listKeys() {
return [{ id: 'deepseek-key', name: 'DeepSeek', status: 'active', defaultModel: 'deepseek-chat', models: ['deepseek-chat'] }];
},
async createChatCompletion() {
return { ok: false, status: 402, message: '{"error":{"message":"Insufficient Balance"}}' };
},
},
});
assert.match(reply, /已取消定时任务/u);
assert.deepEqual(calls, [{ userId: 'user-123', taskId: 'task-suzhou' }]);
});
test('handleWechatScheduledTaskIntent returns clarify message when manage llm is ambiguous', async () => {
const reply = await handleWechatScheduledTaskIntent({
intent: {