@wjarka/cezarion 0.17.0-pr2131.3281 → 0.17.0-pr2132.3284

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -82,6 +82,17 @@ export declare function createDelegationRoutes(service: DelegationService, crede
82
82
  "/discover": {
83
83
  $post: {
84
84
  output: {
85
+ runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
86
+ models: {
87
+ id: string;
88
+ label: string;
89
+ description: string;
90
+ effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
91
+ }[];
92
+ source: "cache" | "live" | "unavailable";
93
+ stale: boolean;
94
+ reason?: string | undefined;
95
+ } | {
85
96
  scope: "host-default-account";
86
97
  runners: {
87
98
  status: "connected" | "disconnected" | "not-installed" | "unknown";
@@ -102,17 +113,6 @@ export declare function createDelegationRoutes(service: DelegationService, crede
102
113
  reason?: string | undefined;
103
114
  }[];
104
115
  nextOffset?: number | undefined;
105
- } | {
106
- runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
107
- models: {
108
- id: string;
109
- label: string;
110
- description: string;
111
- effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
112
- }[];
113
- source: "cache" | "live" | "unavailable";
114
- stale: boolean;
115
- reason?: string | undefined;
116
116
  };
117
117
  outputFormat: "json";
118
118
  status: 200;
@@ -221,13 +221,13 @@ export declare function createDelegationRoutes(service: DelegationService, crede
221
221
  status: 200;
222
222
  input: {
223
223
  json: {
224
- requestIds: string[];
225
- mode?: "all" | "any" | "one" | undefined;
226
- timeoutSeconds?: number | undefined;
227
- } | {
228
224
  workerIds: string[];
229
225
  timeoutSeconds?: number | undefined;
230
226
  mode?: "all" | "any" | "one" | undefined;
227
+ } | {
228
+ requestIds: string[];
229
+ mode?: "all" | "any" | "one" | undefined;
230
+ timeoutSeconds?: number | undefined;
231
231
  } | {
232
232
  peerIds: string[];
233
233
  timeoutSeconds?: number | undefined;
@@ -57,17 +57,6 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
57
57
  "/discover": {
58
58
  $post: {
59
59
  output: {
60
- runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
61
- models: {
62
- id: string;
63
- label: string;
64
- description: string;
65
- effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
66
- }[];
67
- source: "cache" | "live" | "unavailable";
68
- stale: boolean;
69
- reason?: string | undefined;
70
- } | {
71
60
  scope: "host-default-account";
72
61
  runners: {
73
62
  status: "connected" | "disconnected" | "not-installed" | "unknown";
@@ -88,6 +77,17 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
88
77
  reason?: string | undefined;
89
78
  }[];
90
79
  nextOffset?: number | undefined;
80
+ } | {
81
+ runner: "claude" | "codex" | "cursor" | "omp" | "opencode" | "pi";
82
+ models: {
83
+ id: string;
84
+ label: string;
85
+ description: string;
86
+ effortLevels?: ("high" | "low" | "max" | "medium" | "xhigh")[] | undefined;
87
+ }[];
88
+ source: "cache" | "live" | "unavailable";
89
+ stale: boolean;
90
+ reason?: string | undefined;
91
91
  };
92
92
  outputFormat: "json";
93
93
  status: 200;
@@ -0,0 +1,91 @@
1
+ import type { RunRecord, RunStore } from '../../runs/store.ts';
2
+ import type { ContinueRunOptions } from '../continuation-admission.ts';
3
+ import { type RunExitId } from '../run-states.ts';
4
+ import type { RunModuleContext } from './types.ts';
5
+ interface AutoResumeHost {
6
+ move(runId: string, exit: RunExitId, patch: Omit<Parameters<RunStore['updateRun']>[1], 'status'>): RunRecord | undefined;
7
+ continueRun(runId: string, opts: ContinueRunOptions, deferForCapacity: boolean): {
8
+ ok: boolean;
9
+ error?: string;
10
+ };
11
+ pump(): Promise<void>;
12
+ }
13
+ /**
14
+ * Auto-resume after a provider usage limit (spec 2026-08-03-auto-resume-after-usage-limit).
15
+ *
16
+ * The wait is the provider's own reset instant plus this grace: resuming AT the boundary races the
17
+ * provider's clock (and its rounding), and one failed resume costs the whole window over again.
18
+ * Thirty seconds is cheap next to five hours and long enough to be past any sane skew.
19
+ */
20
+ export declare const AUTO_RESUME_GRACE_MS = 30000;
21
+ /**
22
+ * Consecutive automatic resumes allowed without a human turn. A resume can only fire after a real
23
+ * reset instant, so this is not a throttle — it is the backstop for the pathological case (a
24
+ * provider that answers "limit reached, retry now" in a loop), and it is deliberately generous
25
+ * enough to sit through a couple of days of five-hour windows.
26
+ */
27
+ export declare const MAX_AUTO_RESUMES = 12;
28
+ /**
29
+ * How long a missed deadline stays worth acting on. The promise is "we pick this up when the
30
+ * window reopens" — kept across a restart or an overnight close, which is the case the feature
31
+ * exists for. A day later it is no longer that promise: the user has moved on, and a task
32
+ * springing back to life is a surprise rather than a service. Such a deadline is retired with a
33
+ * note instead of fired, so the only tasks a sweep can revive are ones someone is still waiting on.
34
+ */
35
+ export declare const AUTO_RESUME_MISSED_WINDOW_MS: number;
36
+ export declare class AutoResumeScheduler {
37
+ private readonly context;
38
+ private readonly host;
39
+ /** Armed usage-limit resumes, keyed by run id (spec
40
+ * 2026-08-03-auto-resume-after-usage-limit). The DEADLINE itself lives on the record
41
+ * (`autoResumeAt`) — this map holds only the process-local timer, so a restart rebuilds it
42
+ * from the record rather than losing the wait. Runs here are `failed` and therefore NOT in
43
+ * `active`, which is why the timer cannot live on an `ActiveRun` like the monitoring one. */
44
+ readonly autoResumeTimers: Map<string, NodeJS.Timeout>;
45
+ constructor(context: RunModuleContext, host: AutoResumeHost);
46
+ dispose(): void;
47
+ /**
48
+ * A run just failed: if the provider said "usage limit, back at T", promise to resume it at
49
+ * `T + AUTO_RESUME_GRACE_MS` instead of leaving the task dead until someone notices.
50
+ *
51
+ * Every refusal below is silent-but-honest — the run stays `failed` with its Continue button,
52
+ * which is exactly the pre-feature behavior — except the safety cap, which says so on the
53
+ * transcript, because a run that stops resuming itself needs to explain why.
54
+ */
55
+ scheduleAutoResumeIfLimited(runId: string): void;
56
+ /** Publish the deadline on the record (the cockpit's only source) and arm the timer for it. The
57
+ * run waits for it (hearsay-tools/cezarion#1236): `waiting`, its error kept for a withdrawal. */
58
+ private armAutoResume;
59
+ /**
60
+ * The window has reopened. Re-check the record synchronously — hours may have passed, and the
61
+ * user may have continued, deleted or cancelled the run in them — then hand the resume to the
62
+ * ordinary queued-continuation path so it obeys both concurrency caps like any other work.
63
+ */
64
+ private fireAutoResume;
65
+ /**
66
+ * Reconcile process-local resume timers from durable records on pump and recovery. Retire
67
+ * appointments when disabled or invalid; do not leave a deadline with no wake source.
68
+ */
69
+ reconcileAutoResumes(): void;
70
+ /**
71
+ * The PER-TASK off switch (`DELETE /api/v1/runs/:id/auto-resume`, and the archive route):
72
+ * stop resuming THIS task, without touching the workspace setting or any other task.
73
+ *
74
+ * Idempotent — a run with nothing pending answers the same way, because "this task will not
75
+ * resume itself" is equally true either way. Returns false only when the run does not exist,
76
+ * which is the route's 404.
77
+ */
78
+ cancelAutoResume(runId: string): boolean;
79
+ /** Retire a pending resume — timer, deadline and counter. The counter goes too because every
80
+ * caller is a fresh epoch: a human Continue, or a resume that re-stamps its own count. */
81
+ clearAutoResume(runId: string): void;
82
+ /**
83
+ * Withdraw a pending resume without continuing the run: a per-task cancel, the setting switched
84
+ * off, a missed window, the cap, or a resume that could not start. A run on hold settles
85
+ * `failed` with the error it kept, the state it was in before it waited (owner,
86
+ * 2026-10-21). Its waits stay as a failed run's do: open ones armed, resolved ones owed to the
87
+ * next Continue.
88
+ */
89
+ private withdrawAutoResume;
90
+ }
91
+ export {};
@@ -0,0 +1,248 @@
1
+ import { isUsageLimitHold } from '../../contract/index.js';
2
+ import { parseUsageLimit } from '../../core/usage-limit.js';
3
+ import { formatWakeInstant } from '../run-scheduling.js';
4
+ import { transitionVia } from '../run-states.js';
5
+ /**
6
+ * Auto-resume after a provider usage limit (spec 2026-08-03-auto-resume-after-usage-limit).
7
+ *
8
+ * The wait is the provider's own reset instant plus this grace: resuming AT the boundary races the
9
+ * provider's clock (and its rounding), and one failed resume costs the whole window over again.
10
+ * Thirty seconds is cheap next to five hours and long enough to be past any sane skew.
11
+ */
12
+ export const AUTO_RESUME_GRACE_MS = 30_000;
13
+ /**
14
+ * Consecutive automatic resumes allowed without a human turn. A resume can only fire after a real
15
+ * reset instant, so this is not a throttle — it is the backstop for the pathological case (a
16
+ * provider that answers "limit reached, retry now" in a loop), and it is deliberately generous
17
+ * enough to sit through a couple of days of five-hour windows.
18
+ */
19
+ export const MAX_AUTO_RESUMES = 12;
20
+ /**
21
+ * How long a missed deadline stays worth acting on. The promise is "we pick this up when the
22
+ * window reopens" — kept across a restart or an overnight close, which is the case the feature
23
+ * exists for. A day later it is no longer that promise: the user has moved on, and a task
24
+ * springing back to life is a surprise rather than a service. Such a deadline is retired with a
25
+ * note instead of fired, so the only tasks a sweep can revive are ones someone is still waiting on.
26
+ */
27
+ export const AUTO_RESUME_MISSED_WINDOW_MS = 24 * 60 * 60_000;
28
+ const AUTO_RESUME_PROMPT = 'The provider usage limit that interrupted this task has reset. Read the handoff file (CEZ_HANDOFF_FILE) to recover context, then continue the task from where you left off.';
29
+ export class AutoResumeScheduler {
30
+ context;
31
+ host;
32
+ /** Armed usage-limit resumes, keyed by run id (spec
33
+ * 2026-08-03-auto-resume-after-usage-limit). The DEADLINE itself lives on the record
34
+ * (`autoResumeAt`) — this map holds only the process-local timer, so a restart rebuilds it
35
+ * from the record rather than losing the wait. Runs here are `failed` and therefore NOT in
36
+ * `active`, which is why the timer cannot live on an `ActiveRun` like the monitoring one. */
37
+ autoResumeTimers = new Map();
38
+ constructor(context, host) {
39
+ this.context = context;
40
+ this.host = host;
41
+ }
42
+ dispose() {
43
+ for (const timer of this.autoResumeTimers.values())
44
+ clearTimeout(timer);
45
+ this.autoResumeTimers.clear();
46
+ }
47
+ /**
48
+ * A run just failed: if the provider said "usage limit, back at T", promise to resume it at
49
+ * `T + AUTO_RESUME_GRACE_MS` instead of leaving the task dead until someone notices.
50
+ *
51
+ * Every refusal below is silent-but-honest — the run stays `failed` with its Continue button,
52
+ * which is exactly the pre-feature behavior — except the safety cap, which says so on the
53
+ * transcript, because a run that stops resuming itself needs to explain why.
54
+ */
55
+ scheduleAutoResumeIfLimited(runId) {
56
+ if (this.autoResumeTimers.has(runId))
57
+ return; // already promised
58
+ const run = this.context.store.getRun(runId);
59
+ if (!run || run.status !== 'failed')
60
+ return;
61
+ // Archiving IS resigning from a task. Reviving one because a window happened to reopen would
62
+ // be the feature working against the clearest signal the user can give it.
63
+ if (run.archived)
64
+ return;
65
+ const limit = parseUsageLimit(run.error);
66
+ if (!limit)
67
+ return;
68
+ if (!this.context.semaphore.autoResumeOnUsageLimit())
69
+ return;
70
+ // No session to resume = nothing this feature can do; `continueRun` would refuse anyway.
71
+ if (!run.steps.some((step) => step.sessionId))
72
+ return;
73
+ const attempts = run.autoResumeAttempts ?? 0;
74
+ if (attempts >= MAX_AUTO_RESUMES) {
75
+ this.context.store.appendEvent(runId, {
76
+ type: 'note',
77
+ message: `automatic resume cap reached (${MAX_AUTO_RESUMES}) — continue this task manually`,
78
+ });
79
+ return;
80
+ }
81
+ const wakeAt = new Date(limit.resetAt.getTime() + AUTO_RESUME_GRACE_MS);
82
+ this.armAutoResume(runId, wakeAt.getTime());
83
+ this.context.store.appendEvent(runId, {
84
+ type: 'lifecycle',
85
+ message: `usage limit reached — resuming automatically at ${formatWakeInstant(wakeAt)}`,
86
+ });
87
+ }
88
+ /** Publish the deadline on the record (the cockpit's only source) and arm the timer for it. The
89
+ * run waits for it (hearsay-tools/cezarion#1236): `waiting`, its error kept for a withdrawal. */
90
+ armAutoResume(runId, deadline) {
91
+ this.host.move(runId, 'hold', { finishedAt: undefined, autoResumeAt: new Date(deadline).toISOString() });
92
+ const timer = setTimeout(() => this.fireAutoResume(runId), Math.max(0, deadline - Date.now()));
93
+ timer.unref?.();
94
+ this.autoResumeTimers.set(runId, timer);
95
+ }
96
+ /**
97
+ * The window has reopened. Re-check the record synchronously — hours may have passed, and the
98
+ * user may have continued, deleted or cancelled the run in them — then hand the resume to the
99
+ * ordinary queued-continuation path so it obeys both concurrency caps like any other work.
100
+ */
101
+ fireAutoResume(runId) {
102
+ this.autoResumeTimers.delete(runId);
103
+ const run = this.context.store.getRun(runId);
104
+ if (!run || !isUsageLimitHold(run))
105
+ return;
106
+ // Belt and braces against the one gap `reconcileAutoResumes` cannot close: the setting going
107
+ // off in the window between the last pump and this tick.
108
+ if (!this.context.semaphore.autoResumeOnUsageLimit()) {
109
+ this.withdrawAutoResume(runId, 'automatic resume cancelled — auto-resume is switched off');
110
+ return;
111
+ }
112
+ const attempts = (run.autoResumeAttempts ?? 0) + 1;
113
+ // `continueRun` retires the pending resume (timer + record fields) on the way in — this is a
114
+ // resume, not a user turn, so the counter is put back straight after.
115
+ const resumed = this.host.continueRun(runId, { text: AUTO_RESUME_PROMPT }, true);
116
+ if (!resumed.ok) {
117
+ // Refusals happen before `continueRun` retires anything, so the deadline is still on the
118
+ // record — and a deadline in the past is a promise the cockpit keeps displaying and the
119
+ // engine will never keep. Retire it here instead, and say why.
120
+ this.withdrawAutoResume(runId, `automatic resume could not start — ${resumed.error ?? 'unknown'}`);
121
+ return;
122
+ }
123
+ this.context.store.updateRun(runId, { autoResumeAttempts: attempts });
124
+ this.context.store.appendEvent(runId, {
125
+ type: 'lifecycle',
126
+ message: `usage limit reset — resuming automatically (${attempts}/${MAX_AUTO_RESUMES})`,
127
+ });
128
+ // A deferred continuation only ENQUEUES itself; the queue moves when something pumps it, and
129
+ // `recover()` — the other deferring caller — pumps once after its whole bulk sweep. A timer
130
+ // firing on its own has no such follow-up, so without this the resumed run sits at `queued`
131
+ // until some unrelated run happens to finish. This is the pump for it.
132
+ void this.host.pump();
133
+ }
134
+ /**
135
+ * Reconcile process-local resume timers from durable records on pump and recovery. Retire
136
+ * appointments when disabled or invalid; do not leave a deadline with no wake source.
137
+ */
138
+ reconcileAutoResumes() {
139
+ if (!this.context.semaphore.autoResumeOnUsageLimit()) {
140
+ // Sweep the RECORDS, not the timer map. A record promising a resume that no timer is
141
+ // holding is the exact population this method exists for, and it is also the one the
142
+ // setting can be switched off in front of: cezar restarted while it was off, the config
143
+ // was hand-edited, or the project context was disposed mid-wait. Retiring only the armed
144
+ // timers leaves such a record with a live `autoResumeAt`, which `accountHolds()` reads as
145
+ // a deadline hold — so nothing new starts on that account, `rescueStalledQueue` treats the
146
+ // phantom appointment as a legitimate reason to sit still, and the cockpit shows a
147
+ // `scheduled` row for a resume that will never come. `clearAutoResume` covers the armed
148
+ // ones too, so this one loop is the whole cancellation. It reads any resume time, not
149
+ // `isUsageLimitHold`, so a stale one is retired too.
150
+ const pending = new Set([
151
+ ...this.autoResumeTimers.keys(),
152
+ ...this.context.store.listRuns().filter((run) => run.autoResumeAt !== undefined).map((run) => run.id),
153
+ ]);
154
+ for (const runId of pending)
155
+ this.withdrawAutoResume(runId, 'automatic resume cancelled — auto-resume is switched off');
156
+ return;
157
+ }
158
+ for (const run of this.context.store.listRuns()) {
159
+ if (!isUsageLimitHold(run))
160
+ continue;
161
+ if (this.autoResumeTimers.has(run.id))
162
+ continue;
163
+ const deadline = Date.parse(run.autoResumeAt);
164
+ // A deadline that is unreadable, belongs to a run that has spent its cap, or belongs to a
165
+ // task the user has archived is retired rather than re-armed: it can only mislead. One
166
+ // that has just passed arms at zero — the window is open, which is the point.
167
+ if (run.archived
168
+ || !Number.isFinite(deadline)
169
+ || (run.autoResumeAttempts ?? 0) >= MAX_AUTO_RESUMES) {
170
+ this.withdrawAutoResume(run.id);
171
+ continue;
172
+ }
173
+ // …and one missed by more than a day is retired loudly: reviving a task from another era
174
+ // is a surprise, not a service, and this is what keeps a sweep from resurrecting every
175
+ // limit-stopped task a user has long since walked away from.
176
+ if (Date.now() - deadline > AUTO_RESUME_MISSED_WINDOW_MS) {
177
+ this.withdrawAutoResume(run.id, 'automatic resume expired — its window reopened over a day ago; continue this task manually');
178
+ continue;
179
+ }
180
+ this.armAutoResume(run.id, deadline);
181
+ }
182
+ }
183
+ /**
184
+ * The PER-TASK off switch (`DELETE /api/v1/runs/:id/auto-resume`, and the archive route):
185
+ * stop resuming THIS task, without touching the workspace setting or any other task.
186
+ *
187
+ * Idempotent — a run with nothing pending answers the same way, because "this task will not
188
+ * resume itself" is equally true either way. Returns false only when the run does not exist,
189
+ * which is the route's 404.
190
+ */
191
+ cancelAutoResume(runId) {
192
+ const run = this.context.store.getRun(runId);
193
+ if (!run)
194
+ return false;
195
+ // Any resume time, not `isUsageLimitHold`: a withdrawal also retires one a record kept by mistake.
196
+ const pending = run.autoResumeAt !== undefined || this.autoResumeTimers.has(runId);
197
+ this.withdrawAutoResume(runId, pending ? 'automatic resume cancelled for this task' : undefined);
198
+ if (pending) {
199
+ // This run may have been the last thing holding its account's queue — nothing else will
200
+ // notice, since the hold is derived and its release is not an event.
201
+ void this.host.pump();
202
+ }
203
+ return true;
204
+ }
205
+ /** Retire a pending resume — timer, deadline and counter. The counter goes too because every
206
+ * caller is a fresh epoch: a human Continue, or a resume that re-stamps its own count. */
207
+ clearAutoResume(runId) {
208
+ const timer = this.autoResumeTimers.get(runId);
209
+ if (timer)
210
+ clearTimeout(timer);
211
+ this.autoResumeTimers.delete(runId);
212
+ const run = this.context.store.getRun(runId);
213
+ if (!run)
214
+ return;
215
+ // A continuation's own status write retires the appointment of a run on hold
216
+ // (hearsay-tools/cezarion#1236): clearing it first would show a waiting run with no
217
+ // appointment, which reads as Needs you, for the moment between the two writes.
218
+ if (isUsageLimitHold(run)) {
219
+ if (run.autoResumeAttempts !== undefined)
220
+ this.context.store.updateRun(runId, { autoResumeAttempts: undefined });
221
+ return;
222
+ }
223
+ // Any resume time, not `isUsageLimitHold`: it retires a stale one too.
224
+ if (run.autoResumeAt !== undefined || run.autoResumeAttempts !== undefined) {
225
+ this.context.store.updateRun(runId, { autoResumeAt: undefined, autoResumeAttempts: undefined });
226
+ }
227
+ }
228
+ /**
229
+ * Withdraw a pending resume without continuing the run: a per-task cancel, the setting switched
230
+ * off, a missed window, the cap, or a resume that could not start. A run on hold settles
231
+ * `failed` with the error it kept, the state it was in before it waited (owner,
232
+ * 2026-10-21). Its waits stay as a failed run's do: open ones armed, resolved ones owed to the
233
+ * next Continue.
234
+ */
235
+ withdrawAutoResume(runId, note) {
236
+ // Committed first: a store that cannot write throws here with the timer still armed, and the
237
+ // note is written only once the withdrawal is on disk (hearsay-tools/cezarion#1236).
238
+ if (this.context.store.getRun(runId))
239
+ transitionVia('withdraw-hold', () => this.context.store.getRun(runId), () => this.context.store.commitAutoResumeWithdrawal(runId));
240
+ const timer = this.autoResumeTimers.get(runId);
241
+ if (timer)
242
+ clearTimeout(timer);
243
+ this.autoResumeTimers.delete(runId);
244
+ if (note && this.context.store.getRun(runId))
245
+ this.context.store.appendEvent(runId, { type: 'note', message: note });
246
+ }
247
+ }
248
+ //# sourceMappingURL=auto-resume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-resume.js","sourceRoot":"","sources":["../../../src/workflows/run/auto-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AASjE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;AAE7D,MAAM,kBAAkB,GACtB,6KAA6K,CAAC;AAEhL,MAAM,OAAO,mBAAmB;IAQD,OAAO;IAAqC,IAAI;IAP7E;;;;kGAI8F;IACrF,gBAAgB,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE9D,YAA6B,OAAyB,EAAmB,IAAoB;uBAAhE,OA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: RunRecord): StartRunInput;
33
33
  * local-first: the process and the browser reading it are the same machine.
34
34
  */
35
35
  export declare function formatWakeInstant(at: Date): string;
36
+ /**
37
+ * Derive this project’s future-deadline and in-flight account holds from records for the shared
38
+ * semaphore. Past deadlines do not block the queue.
39
+ */
40
+ export declare function deriveAccountHolds(records: RunRecord[], withExecutionAccount: <T extends RunRecord>(run: T) => T, now?: number): AccountHolds;
@@ -1,3 +1,4 @@
1
+ import { isUsageLimitHold } from '../contract/index.js';
1
2
  /**
2
3
  * A deadline hold blocks all work on its account. An in-flight resume holds fresh work only;
3
4
  * other resumes must remain eligible.
@@ -58,4 +59,26 @@ export function queuedRecoveryInput(run) {
58
59
  export function formatWakeInstant(at) {
59
60
  return new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'long' }).format(at);
60
61
  }
62
+ /**
63
+ * Derive this project’s future-deadline and in-flight account holds from records for the shared
64
+ * semaphore. Past deadlines do not block the queue.
65
+ */
66
+ export function deriveAccountHolds(records, withExecutionAccount, now = Date.now()) {
67
+ const deadline = new Set();
68
+ const inFlight = new Set();
69
+ for (const run of records) {
70
+ // A holding run always carries the runner it actually ran on, so the fallback is unused
71
+ // here — it is spelled out rather than `!` so a future record shape degrades, not throws.
72
+ const key = () => runAccountKey(withExecutionAccount(run), run.runner ?? 'claude');
73
+ if (isUsageLimitHold(run)) {
74
+ const at = Date.parse(run.autoResumeAt);
75
+ if (Number.isFinite(at) && at > now)
76
+ deadline.add(key());
77
+ }
78
+ else if (resumeInFlight(run)) {
79
+ inFlight.add(key());
80
+ }
81
+ }
82
+ return { deadline, inFlight };
83
+ }
61
84
  //# sourceMappingURL=run-scheduling.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-scheduling.js","sourceRoot":"","sources":["../../src/workflows/run-scheduling.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAiF,EACjF,KAAmB,EACnB,cAAwB;IAExB,MAAM,GAAG,GAAG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CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
@@ -5,6 +5,7 @@ import { type CezarAskRequest, type CezarDoneAnswer, type CezarDoneRequest, type
5
5
  import { type PreviewStopRequest, type PreviewStopResult, type PreviewServeRequest, type PreviewServeResult } from '../contract/index.js';
6
6
  import { NO_WAIT_NUDGE_NOTE, NO_WAIT_NOTE, NO_WAIT_NO_REPLY_NOTE, COMPLETION_NO_REPLY_NOTE, WORKER_FALLBACK_NOTE, WORKER_FALLBACK_REPLY_NOTE, COMPLETION_NUDGE_NOTE, AUTONOMOUS_ASK_NOTE, AUTONOMOUS_NUDGE } from './turn-end.ts';
7
7
  export { claudeScheduleWakeupDelay, appendTurnText, trackTurnTail, classifyTurnEnd } from './run/turn-markers.ts';
8
+ export { AUTO_RESUME_GRACE_MS, MAX_AUTO_RESUMES, AUTO_RESUME_MISSED_WINDOW_MS } from './run/auto-resume.ts';
8
9
  export { agentDirectories, composeSystemPrompt, expandRegistrySlashSkill, expandRegistrySlashSkillText, leadingSlashSkillName, resolveExtraSystemPrompt, skillSystemPrompt } from './run/prompts.ts';
9
10
  export { stepLabel } from './run/steps.ts';
10
11
  export { makeRunTitle } from '../runs/run-title.ts';
@@ -54,21 +55,6 @@ export declare const COMPLETION_WILL_WAIT = "If you end your turn with done agai
54
55
  /** Bound one unattended session; an explicit Continue starts a new budget. */
55
56
  export declare const MAX_AUTO_CONTINUES = 40;
56
57
  export { AUTONOMOUS_NUDGE, NO_WAIT_NUDGE_NOTE, NO_WAIT_NOTE, NO_WAIT_NO_REPLY_NOTE, COMPLETION_NO_REPLY_NOTE, WORKER_FALLBACK_NOTE, WORKER_FALLBACK_REPLY_NOTE, COMPLETION_NUDGE_NOTE, AUTONOMOUS_ASK_NOTE };
57
- /**
58
- * Auto-resume after a provider usage limit (spec 2026-08-03-auto-resume-after-usage-limit).
59
- *
60
- * The wait is the provider's own reset instant plus this grace: resuming AT the boundary races the
61
- * provider's clock (and its rounding), and one failed resume costs the whole window over again.
62
- * Thirty seconds is cheap next to five hours and long enough to be past any sane skew.
63
- */
64
- export declare const AUTO_RESUME_GRACE_MS = 30000;
65
- /**
66
- * Consecutive automatic resumes allowed without a human turn. A resume can only fire after a real
67
- * reset instant, so this is not a throttle — it is the backstop for the pathological case (a
68
- * provider that answers "limit reached, retry now" in a loop), and it is deliberately generous
69
- * enough to sit through a couple of days of five-hour windows.
70
- */
71
- export declare const MAX_AUTO_RESUMES = 12;
72
58
  /**
73
59
  * Consecutive failed automatic attempts to deliver a run's wait results (hearsay-tools/cezarion#1233):
74
60
  * each is a session that failed, or closed cleanly, while the results were still owed, counted across
@@ -86,14 +72,6 @@ export declare const WAKE_SESSION_CLOSED_ERROR = "the session closed before the
86
72
  export declare const WAITS_DISCARDED_NOTE = "Stop discarded the waits this task held and their results; the task stays failed";
87
73
  /** Stop on a failed run that only owed a completion refusal (hearsay-tools/cezarion#1301). */
88
74
  export declare const REFUSAL_DISCARDED_NOTE = "Stop discarded the completion refusal this task still owed; the task stays failed";
89
- /**
90
- * How long a missed deadline stays worth acting on. The promise is "we pick this up when the
91
- * window reopens" — kept across a restart or an overnight close, which is the case the feature
92
- * exists for. A day later it is no longer that promise: the user has moved on, and a task
93
- * springing back to life is a surprise rather than a service. Such a deadline is retired with a
94
- * note instead of fired, so the only tasks a sweep can revive are ones someone is still waiting on.
95
- */
96
- export declare const AUTO_RESUME_MISSED_WINDOW_MS: number;
97
75
  /**
98
76
  * How often the queue checks that it is not wedged.
99
77
  *
@@ -249,12 +227,8 @@ export declare class RunManager {
249
227
  * Wait-withdrawing entries also retain a durable queue ID until delivered. */
250
228
  private readonly queuedInput;
251
229
  private get deferredMessages();
252
- /** Armed usage-limit resumes, keyed by run id (spec
253
- * 2026-08-03-auto-resume-after-usage-limit). The DEADLINE itself lives on the record
254
- * (`autoResumeAt`) — this map holds only the process-local timer, so a restart rebuilds it
255
- * from the record rather than losing the wait. Runs here are `failed` and therefore NOT in
256
- * `active`, which is why the timer cannot live on an `ActiveRun` like the monitoring one. */
257
- private readonly autoResumeTimers;
230
+ private readonly autoResumeScheduler;
231
+ private get autoResumeTimers();
258
232
  private pumping;
259
233
  /** The scheduler only needs repo presence, stable for this manager's lifetime.
260
234
  * Cache the promise (including null) so every sweep doesn't spawn Git (#364).
@@ -761,28 +735,7 @@ export declare class RunManager {
761
735
  * Terminal status alone is not process-exit proof: an active session or an
762
736
  * unfinished private worker generation must retain its files until exit. */
763
737
  private reapTerminalScratch;
764
- /**
765
- * A run just failed: if the provider said "usage limit, back at T", promise to resume it at
766
- * `T + AUTO_RESUME_GRACE_MS` instead of leaving the task dead until someone notices.
767
- *
768
- * Every refusal below is silent-but-honest — the run stays `failed` with its Continue button,
769
- * which is exactly the pre-feature behavior — except the safety cap, which says so on the
770
- * transcript, because a run that stops resuming itself needs to explain why.
771
- */
772
738
  private scheduleAutoResumeIfLimited;
773
- /** Publish the deadline on the record (the cockpit's only source) and arm the timer for it. The
774
- * run waits for it (hearsay-tools/cezarion#1236): `waiting`, its error kept for a withdrawal. */
775
- private armAutoResume;
776
- /**
777
- * The window has reopened. Re-check the record synchronously — hours may have passed, and the
778
- * user may have continued, deleted or cancelled the run in them — then hand the resume to the
779
- * ordinary queued-continuation path so it obeys both concurrency caps like any other work.
780
- */
781
- private fireAutoResume;
782
- /**
783
- * Reconcile process-local resume timers from durable records on pump and recovery. Retire
784
- * appointments when disabled or invalid; do not leave a deadline with no wake source.
785
- */
786
739
  private reconcileAutoResumes;
787
740
  /**
788
741
  * Hand a run that has not spawned anything back to the queue, when the account it would run on
@@ -803,31 +756,9 @@ export declare class RunManager {
803
756
  * or future appointment explains it; start through ordinary caps. Public for direct tests.
804
757
  */
805
758
  rescueStalledQueue(now?: number): Promise<void>;
806
- /**
807
- * Derive this project’s future-deadline and in-flight account holds from records for the shared
808
- * semaphore. Past deadlines do not block the queue.
809
- */
810
759
  accountHolds(now?: number): AccountHolds;
811
- /**
812
- * The PER-TASK off switch (`DELETE /api/v1/runs/:id/auto-resume`, and the archive route):
813
- * stop resuming THIS task, without touching the workspace setting or any other task.
814
- *
815
- * Idempotent — a run with nothing pending answers the same way, because "this task will not
816
- * resume itself" is equally true either way. Returns false only when the run does not exist,
817
- * which is the route's 404.
818
- */
819
760
  cancelAutoResume(runId: string): boolean;
820
- /** Retire a pending resume — timer, deadline and counter. The counter goes too because every
821
- * caller is a fresh epoch: a human Continue, or a resume that re-stamps its own count. */
822
761
  private clearAutoResume;
823
- /**
824
- * Withdraw a pending resume without continuing the run: a per-task cancel, the setting switched
825
- * off, a missed window, the cap, or a resume that could not start. A run on hold settles
826
- * `failed` with the error it kept, the state it was in before it waited (owner,
827
- * 2026-10-21). Its waits stay as a failed run's do: open ones armed, resolved ones owed to the
828
- * next Continue.
829
- */
830
- private withdrawAutoResume;
831
762
  /** Reclaim finished worktrees beyond the keep-limit (#483) — directory only,
832
763
  * `cez/<id8>` branch kept. Best-effort; a failure never affects run
833
764
  * lifecycle. `review`/live runs are excluded by the selector. */