feat: keep typing during scheduled tasks and tell waiting users

A group-context scheduled task occupies the room queue, so a human message
sent meanwhile waited silently (up to the whole task run) with no typing
indicator; the room looked unresponsive.

- Scheduled tasks (not CI watchers) hold the room's typing indicator for
  their whole run (DiscordChannel.setTypingHold: typing stays on while any
  hold is active, independent of message-turn setTyping(false)).
- A human message that has to wait behind a running scheduled task gets a
  one-time notice per wait: "지금 예약 작업을 진행하고 있습니다. 이 작업을
  마친 뒤 바로 답변드리겠습니다." (GroupQueue.claimScheduledTaskWaitNotice,
  reset when the waiting messages run).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-27 23:12:00 +09:00
parent fdfdd384bf
commit fdd98e9eb8
14 changed files with 323 additions and 1 deletions

View File

@@ -565,6 +565,78 @@ describe('task scheduler', () => {
expect(task?.last_result).toBe('done');
});
it('holds the room typing indicator for the whole scheduled task run', async () => {
const dueAt = new Date(Date.now() - 60_000).toISOString();
const watchPrompt =
'[BACKGROUND CI WATCH]\n\nWatch target:\nrun 1\n\nCheck instructions:\nCheck.';
for (const [id, prompt] of [
['task-typing', 'continue the work'],
['task-typing-watch', watchPrompt],
]) {
createTask({
id,
group_folder: 'shared-group',
chat_jid: 'shared@g.us',
agent_type: 'codex',
prompt,
schedule_type: 'once',
schedule_value: dueAt,
context_mode: 'group',
next_run: dueAt,
status: 'active',
created_at: '2026-02-22T00:00:00.000Z',
});
}
const events: string[] = [];
runAgentProcessMock.mockImplementationOnce(async () => {
events.push('agent');
return { status: 'success' as const, result: 'done' };
});
const executions: Promise<void>[] = [];
const enqueueTask = vi.fn(
(_groupJid: string, _taskId: string, fn: () => Promise<void>) => {
executions.push(fn());
},
);
const setTypingHold = vi.fn(
async (jid: string, holdId: string, active: boolean) => {
events.push(`${active ? 'on' : 'off'}:${jid}:${holdId}`);
},
);
await runSchedulerTickOnce({
serviceAgentType: 'codex',
roomBindings: () => ({
'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 () => {},
setTypingHold,
});
await Promise.all(executions);
// Only the real task holds typing; the CI watcher stays silent.
expect(setTypingHold).toHaveBeenCalledTimes(2);
expect(events.indexOf('on:shared@g.us:scheduled-task:task-typing')).toBe(
events.indexOf('agent') - 1,
);
expect(events).toContain('off:shared@g.us:scheduled-task:task-typing');
expect(
events.indexOf('off:shared@g.us:scheduled-task:task-typing'),
).toBeGreaterThan(
events.indexOf('on:shared@g.us:scheduled-task:task-typing'),
);
});
it('keeps interval tasks active and reschedules them after an execution error', async () => {
const dueAt = new Date(Date.now() - 60_000).toISOString();
createTask({