fix: alignment hold also covers scheduled-task limits and the primer
- A scheduled Claude task that hits the usage limit now extends the alignment hold to the next slot when the reset is off the grid, like a room turn (it called runAgentProcess directly and skipped that path). - The Claude primer is skipped while a hold outlasts its slot (e.g. the 08:00 primer during a realignment hold until 13:00). A hold ending at the slot itself does not count: the slot timer fired at 07:59:59.999 for 08:00 on 2026-10-16. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,7 @@ import {
|
||||
_initTestDatabase,
|
||||
createPairedTask,
|
||||
createTask,
|
||||
getRouterState,
|
||||
getTaskById,
|
||||
setRouterState,
|
||||
} from './db.js';
|
||||
@@ -136,6 +137,7 @@ import {
|
||||
} from './claude-usage-pause.js';
|
||||
import { TIMEZONE } from './config.js';
|
||||
import * as usageAlignmentHold from './usage-alignment-hold.js';
|
||||
import { USAGE_ALIGNMENT_HOLD_UNTIL_KEY } from './usage-alignment-hold.js';
|
||||
import * as serviceRouting from './service-routing.js';
|
||||
import * as tokenRefresh from './token-refresh.js';
|
||||
import { createTaskStatusTracker } from './task-status-tracker.js';
|
||||
@@ -862,6 +864,67 @@ Check the run.
|
||||
);
|
||||
});
|
||||
|
||||
it('holds until the next slot when a scheduled Claude task hits a limit that resets off the grid', async () => {
|
||||
vi.setSystemTime(new Date('2026-10-16T08:30:00+09:00'));
|
||||
const dueAt = new Date(Date.now() - 60_000).toISOString();
|
||||
createTask({
|
||||
id: 'task-off-slot-limit',
|
||||
group_folder: 'shared-group',
|
||||
chat_jid: 'shared@g.us',
|
||||
agent_type: 'claude-code',
|
||||
prompt: 'claude task',
|
||||
schedule_type: 'once',
|
||||
schedule_value: dueAt,
|
||||
context_mode: 'isolated',
|
||||
next_run: dueAt,
|
||||
status: 'active',
|
||||
created_at: '2026-02-22T00:00:00.000Z',
|
||||
});
|
||||
(runAgentProcessMock as any).mockImplementationOnce(
|
||||
async (
|
||||
_group: unknown,
|
||||
_input: unknown,
|
||||
_onProcess: unknown,
|
||||
onOutput?: (output: Record<string, unknown>) => Promise<void>,
|
||||
) => {
|
||||
await onOutput?.({
|
||||
status: 'success',
|
||||
result: "You're out of extra usage · resets 9:20am (Asia/Seoul)",
|
||||
});
|
||||
return { status: 'success', result: null };
|
||||
},
|
||||
);
|
||||
const enqueueTask = vi.fn(
|
||||
(_groupJid: string, _taskId: string, fn: () => Promise<void>) => {
|
||||
void fn();
|
||||
},
|
||||
);
|
||||
|
||||
startSchedulerLoop({
|
||||
serviceAgentType: 'claude-code',
|
||||
roomBindings: () => ({
|
||||
'shared@g.us': {
|
||||
name: 'Shared',
|
||||
folder: 'shared-group',
|
||||
trigger: '@Claude',
|
||||
added_at: '2026-02-22T00:00:00.000Z',
|
||||
agentType: 'claude-code',
|
||||
},
|
||||
}),
|
||||
getSessions: () => ({}),
|
||||
queue: { enqueueTask } as any,
|
||||
onProcess: () => {},
|
||||
sendMessage: vi.fn(async () => {}),
|
||||
});
|
||||
await vi.advanceTimersByTimeAsync(10);
|
||||
|
||||
expect(runAgentProcessMock).toHaveBeenCalledTimes(1);
|
||||
// 09:20 KST reset -> no Claude until the 13:00 KST slot.
|
||||
expect(getRouterState(USAGE_ALIGNMENT_HOLD_UNTIL_KEY)).toBe(
|
||||
'2026-10-16T04:00:00.000Z',
|
||||
);
|
||||
});
|
||||
|
||||
it('suppresses Claude OAuth expiry banners for scheduled tasks and retries after a token refresh', async () => {
|
||||
const dueAt = new Date(Date.now() - 60_000).toISOString();
|
||||
createTask({
|
||||
|
||||
Reference in New Issue
Block a user