fix: keep usage resets on the slot grid when Claude hits 100%
Evidence (journal): 10/04 and 10/05 08:00 and 10/12 23:00 the primer failed (exit 1) because the account was at 100% in an off-slot window (resets 9am / 3am); the first request after that reset then opened the next window off the slot too, and the drift carried on. - Usage limit that resets off the slot grid (not ~04/08/13/18/23:00 KST): extend the alignment hold to the next window start (08/13/18/23), so nothing opens a window between the reset and the primer. The pause notice names both times. Rooms paused by the limit stay paused (silently, now alignment-only, @-mention bypass works) until the hold ends; an expired real limit no longer counts as a limit. - A real limit takes precedence over the hold in the pre-run gate. - Primer: when the current 5h window (cached usage) ends within 10 min after the slot, wait until 5 s after that reset before firing, so the primer is not counted in, or rejected by, the old window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,9 +22,12 @@ import {
|
||||
} from './claude-usage-pause.js';
|
||||
import { getPairedTaskById } from './db.js';
|
||||
import {
|
||||
extendUsageAlignmentHold,
|
||||
formatUsageAlignmentHoldMessage,
|
||||
formatUsageLimitAlignedPauseMessage,
|
||||
getUsageAlignmentHold,
|
||||
isUsageAlignmentBypassed,
|
||||
nextWindowStartAfterOffSlotReset,
|
||||
} from './usage-alignment-hold.js';
|
||||
import { completePairedTaskWithReason } from './paired-task-status.js';
|
||||
import { prepareMessageAgentExecutionTarget } from './message-agent-executor-target.js';
|
||||
@@ -114,12 +117,32 @@ async function pauseRunForClaudeUsage(args: {
|
||||
markRunPausedForClaudeUsage(args.runId);
|
||||
args.pairedExecutionLifecycle.updateSummary({ outputText: args.summary });
|
||||
args.pairedExecutionLifecycle.releaseForClaudeUsagePause();
|
||||
const notice = args.alignment
|
||||
? formatUsageAlignmentHoldMessage(formatResetTime(pause.until, Date.now()))
|
||||
: formatClaudeUsagePauseMessage({
|
||||
resumeAt: pause.until,
|
||||
resetKnown: pause.resetKnown,
|
||||
});
|
||||
const nowMs = Date.now();
|
||||
let notice: string;
|
||||
if (args.alignment) {
|
||||
notice = formatUsageAlignmentHoldMessage(
|
||||
formatResetTime(pause.until, nowMs),
|
||||
);
|
||||
} else {
|
||||
// A limit that resets off the slot grid would open an off-slot window
|
||||
// on the first request after the reset; hold until the next slot.
|
||||
if (pause.resetKnown) {
|
||||
const slot = nextWindowStartAfterOffSlotReset(pause.until);
|
||||
if (slot) extendUsageAlignmentHold(slot);
|
||||
}
|
||||
const holdAtReset = pause.resetKnown
|
||||
? getUsageAlignmentHold(pause.until.getTime())
|
||||
: null;
|
||||
notice = holdAtReset
|
||||
? formatUsageLimitAlignedPauseMessage(
|
||||
formatResetTime(pause.until, nowMs),
|
||||
formatResetTime(holdAtReset.until, nowMs),
|
||||
)
|
||||
: formatClaudeUsagePauseMessage({
|
||||
resumeAt: pause.until,
|
||||
resetKnown: pause.resetKnown,
|
||||
});
|
||||
}
|
||||
await args.onOutput?.({
|
||||
status: 'success',
|
||||
result: null,
|
||||
@@ -148,7 +171,8 @@ async function pauseWhileClaudeUsageLimited(args: {
|
||||
: getUsageAlignmentHold();
|
||||
if (!pause && !hold) return false;
|
||||
try {
|
||||
if (pause && (!hold || pause.until >= hold.until)) {
|
||||
// A real limit wins; its notice names any hold that follows the reset.
|
||||
if (pause) {
|
||||
args.log.warn(
|
||||
{ until: pause.until.toISOString(), role: args.activeRole },
|
||||
'Claude usage limit still in effect; pausing the room without starting a run',
|
||||
|
||||
Reference in New Issue
Block a user