From 4df30a9b9bb7f2ba4cca7c6bab7d8d1fa6377093 Mon Sep 17 00:00:00 2001 From: Eyejoker Date: Mon, 23 Mar 2026 05:40:31 +0900 Subject: [PATCH] fix: keep ci watchers off the chat queue --- src/task-scheduler.test.ts | 55 ++++++++++++++++++++++++++++++++++++++ src/task-scheduler.ts | 4 +-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/task-scheduler.test.ts b/src/task-scheduler.test.ts index 73f3a2a..b0871af 100644 --- a/src/task-scheduler.test.ts +++ b/src/task-scheduler.test.ts @@ -152,6 +152,61 @@ describe('task scheduler', () => { expect(enqueueTask.mock.calls[0][1]).toBe('task-group-context'); }); + it('keeps watch_ci tasks on a dedicated queue even in group context', async () => { + const dueAt = new Date(Date.now() - 60_000).toISOString(); + createTask({ + id: 'task-watch-group', + group_folder: 'shared-group', + chat_jid: 'shared@g.us', + agent_type: 'codex', + prompt: ` +[BACKGROUND CI WATCH] + +Watch target: +GitHub Actions run 123456 + +Task ID: +task-watch-group + +Check instructions: +Check the run. + `.trim(), + schedule_type: 'interval', + schedule_value: '60000', + context_mode: 'group', + next_run: dueAt, + status: 'active', + created_at: '2026-02-22T00:00:00.000Z', + }); + + const enqueueTask = vi.fn(); + + startSchedulerLoop({ + serviceAgentType: 'codex', + registeredGroups: () => ({ + 'shared@g.us': { + name: 'Shared', + folder: 'shared-group', + trigger: '@Codex', + added_at: '2026-02-22T00:00:00.000Z', + agentType: 'codex', + }, + }), + getSessions: () => ({}), + queue: { enqueueTask } as any, + onProcess: () => {}, + sendMessage: async () => {}, + }); + + await vi.advanceTimersByTimeAsync(10); + + expect(enqueueTask).toHaveBeenCalledTimes(1); + expect(enqueueTask.mock.calls[0][0]).toBe( + 'shared@g.us::task:task-watch-group', + ); + expect(enqueueTask.mock.calls[0][1]).toBe('task-watch-group'); + }); + it('renders watcher heartbeat messages with target and timing', () => { const prompt = ` [BACKGROUND CI WATCH] diff --git a/src/task-scheduler.ts b/src/task-scheduler.ts index 152ba5f..fb0a56d 100644 --- a/src/task-scheduler.ts +++ b/src/task-scheduler.ts @@ -203,9 +203,9 @@ export function renderWatchCiStatusMessage(args: { } function getTaskQueueJid( - task: Pick, + task: Pick, ): string { - return task.context_mode === 'isolated' + return task.context_mode === 'isolated' || isWatchCiTask(task) ? `${task.chat_jid}::task:${task.id}` : task.chat_jid; }