omni-notify-mcp 1.3.455 → 1.3.457
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.
- package/dist/shared/agentSession.js +255 -59
- package/dist/shared/conversation/conversations.js +109 -34
- package/dist/shared/conversation/copilotProvider.js +24 -10
- package/dist/shared/conversation/sessionDriver.js +79 -79
- package/dist/shared/webhost/autoSwitch.cjs +56 -6
- package/dist/shared/webhost/webviewShim.js +1015 -998
- package/package.json +2 -1
|
@@ -584,7 +584,9 @@ export class CodexControl {
|
|
|
584
584
|
const terminal = (status === "idle" || status === "notLoaded") && ["completed", "interrupted", "failed"].includes(after.status);
|
|
585
585
|
if (!active && !terminal)
|
|
586
586
|
return unread(`native thread status ${status} and turn status ${after.status} do not establish a coherent active or terminal generation`);
|
|
587
|
-
|
|
587
|
+
const transcript = typeof thread.path === "string" && path.isAbsolute(thread.path) ? thread.path : undefined;
|
|
588
|
+
const cwd = typeof thread.cwd === "string" && path.isAbsolute(thread.cwd) ? thread.cwd : undefined;
|
|
589
|
+
return { threadId, checkedAt: Date.now(), parent, turn: { kind: "known", ...after }, state: active ? "active" : "terminal", boardBinding, transcript, cwd };
|
|
588
590
|
}
|
|
589
591
|
catch (error) {
|
|
590
592
|
if (!(error instanceof CodexControlFailed))
|
|
@@ -603,7 +605,8 @@ export class CodexControl {
|
|
|
603
605
|
const turn = codexObservationObject(response.data[0]);
|
|
604
606
|
if (typeof turn?.id !== "string" || turn.id.length === 0 || typeof turn.status !== "string" || turn.status.length === 0)
|
|
605
607
|
throw new CodexControlFailed("native latest-turn identity or status is malformed");
|
|
606
|
-
|
|
608
|
+
const error = codexObservationObject(turn.error)?.message;
|
|
609
|
+
return { id: turn.id, status: turn.status, ...(typeof error === "string" ? { error } : {}) };
|
|
607
610
|
}
|
|
608
611
|
/** A new Codex main opened in `cwd` under `name`, idle until a press is posted into it. */
|
|
609
612
|
async startMain(cwd, name, held, model, created) {
|
|
@@ -664,7 +667,7 @@ export class CodexControl {
|
|
|
664
667
|
}
|
|
665
668
|
return working;
|
|
666
669
|
}
|
|
667
|
-
async resumeStory(threadId, message, beforeSend, name) {
|
|
670
|
+
async resumeStory(threadId, message, beforeSend, name, model) {
|
|
668
671
|
await this.daemonUp();
|
|
669
672
|
await this.open();
|
|
670
673
|
const thread = (await this.request("thread/read", { threadId, includeTurns: false })).thread;
|
|
@@ -674,7 +677,7 @@ export class CodexControl {
|
|
|
674
677
|
await this.request("thread/resume", { threadId, excludeTurns: true });
|
|
675
678
|
if (name !== undefined)
|
|
676
679
|
await this.request("thread/name/set", { threadId, name });
|
|
677
|
-
await this.post(threadId, message, beforeSend);
|
|
680
|
+
await this.post(threadId, message, beforeSend, model);
|
|
678
681
|
}
|
|
679
682
|
async archiveStory(threadId) {
|
|
680
683
|
await this.daemonUp();
|
|
@@ -841,13 +844,13 @@ export class CodexControl {
|
|
|
841
844
|
return { state: "pending", ownerThreadId: threadId, turnId: expectedTurnId, why: "graceful Stop requested for the selected Codex root and its children; native completion is still pending" };
|
|
842
845
|
}
|
|
843
846
|
/** The installed provider's advertised native model IDs, including all pages. */
|
|
844
|
-
async availableModels() {
|
|
847
|
+
async availableModels(includeHidden = true) {
|
|
845
848
|
await this.open();
|
|
846
849
|
const models = new Set();
|
|
847
850
|
const cursors = new Set();
|
|
848
851
|
let cursor;
|
|
849
852
|
do {
|
|
850
|
-
const response = await this.request("model/list", { includeHidden
|
|
853
|
+
const response = await this.request("model/list", { includeHidden, ...(cursor === undefined ? {} : { cursor }) });
|
|
851
854
|
if (!Array.isArray(response.data) || response.data.some(row => typeof row.model !== "string" || row.model.length === 0))
|
|
852
855
|
throw new CodexRefused("the native Codex model catalog has an invalid model ID; no explicit model was selected");
|
|
853
856
|
for (const row of response.data)
|
|
@@ -889,6 +892,9 @@ export class CodexControl {
|
|
|
889
892
|
const marker = `FleetView native message ${nonce}`;
|
|
890
893
|
const dir = path.join(this.project, ".fleetview", "codex-posts");
|
|
891
894
|
fs.mkdirSync(dir, { recursive: true });
|
|
895
|
+
const ignore = path.join(dir, ".gitignore");
|
|
896
|
+
if (!fs.existsSync(ignore))
|
|
897
|
+
fs.writeFileSync(ignore, "*\n");
|
|
892
898
|
const priorFiles = fs.readdirSync(dir).filter(name => name.startsWith(nonce + "-") && name.endsWith(".json")).sort((a, b) => Number(a.slice(nonce.length + 1, -5)) - Number(b.slice(nonce.length + 1, -5)));
|
|
893
899
|
let file = priorFiles.length === 0 ? "" : path.join(dir, priorFiles[priorFiles.length - 1]);
|
|
894
900
|
let receipt = file === "" ? undefined : JSON.parse(fs.readFileSync(file, "utf8"));
|
|
@@ -1017,7 +1023,7 @@ export class CodexControl {
|
|
|
1017
1023
|
}
|
|
1018
1024
|
}
|
|
1019
1025
|
/** `message` posted into the main's thread as his next turn: steered into the turn it is running, else started as a new one; `beforeSend` runs right before it goes and may refuse it by throwing. */
|
|
1020
|
-
async post(threadId, message, beforeSend = () => { }) {
|
|
1026
|
+
async post(threadId, message, beforeSend = () => { }, model) {
|
|
1021
1027
|
await this.open();
|
|
1022
1028
|
const input = [{ type: "text", text: message }];
|
|
1023
1029
|
const active = await this.activeTurn(threadId);
|
|
@@ -1025,7 +1031,7 @@ export class CodexControl {
|
|
|
1025
1031
|
if (active !== undefined)
|
|
1026
1032
|
await this.request("turn/steer", { threadId, expectedTurnId: active.id, input });
|
|
1027
1033
|
else
|
|
1028
|
-
await this.request("turn/start", { threadId, input });
|
|
1034
|
+
await this.request("turn/start", { threadId, input, ...(model === undefined ? {} : { model }) });
|
|
1029
1035
|
}
|
|
1030
1036
|
/** #4240: one native owner request per child turn, shared by the queue and the bound sweep. */
|
|
1031
1037
|
async endChild(childThreadId, laneStartTs, stateDir, expectedTurnId) {
|
|
@@ -1180,7 +1186,7 @@ export class CodexControl {
|
|
|
1180
1186
|
const connection = Object.assign(stream, { connecting: false, setTimeout: () => stream, setNoDelay: () => stream, setKeepAlive: () => stream });
|
|
1181
1187
|
const agent = new Agent();
|
|
1182
1188
|
agent.createConnection = () => connection;
|
|
1183
|
-
const socket = (this.socket = new Socket("ws://localhost/", { agent
|
|
1189
|
+
const socket = (this.socket = new Socket("ws://localhost/", { agent }));
|
|
1184
1190
|
let said = "";
|
|
1185
1191
|
let proxyEnded = false;
|
|
1186
1192
|
proxy.stderr.on("data", (chunk) => (said += chunk.toString("utf8")));
|
|
@@ -1189,7 +1195,14 @@ export class CodexControl {
|
|
|
1189
1195
|
proxy.once("error", (cause) => done(`the native Codex control proxy could not be started: ${cause.message}`));
|
|
1190
1196
|
});
|
|
1191
1197
|
let initialized = false;
|
|
1198
|
+
// The HTTP upgrade runs over the proxy's pipes. Its socket shim has no idle timeout.
|
|
1199
|
+
const handshake = setTimeout(() => {
|
|
1200
|
+
const cause = new CodexControlFailed(`the native Codex control handshake did not answer within ${CODEX_REQUEST_MS / 1000} seconds`);
|
|
1201
|
+
reject(cause);
|
|
1202
|
+
failed(cause);
|
|
1203
|
+
}, CODEX_REQUEST_MS);
|
|
1192
1204
|
const failed = (cause) => {
|
|
1205
|
+
clearTimeout(handshake);
|
|
1193
1206
|
if (!initialized)
|
|
1194
1207
|
void ended.then((why) => reject(new CodexControlFailed(`${cause.message}; ${why}`)));
|
|
1195
1208
|
if (this.generation === generation) {
|
|
@@ -1236,6 +1249,7 @@ export class CodexControl {
|
|
|
1236
1249
|
pending.resolve(message.result);
|
|
1237
1250
|
});
|
|
1238
1251
|
socket.once("open", () => {
|
|
1252
|
+
clearTimeout(handshake);
|
|
1239
1253
|
void this.request("initialize", { clientInfo: { name: NATIVE_OWNER_CLIENT_ID, version: "1.0.0" }, capabilities: { experimentalApi: true } }).then(() => {
|
|
1240
1254
|
socket.send(JSON.stringify({ method: "initialized", params: {} }));
|
|
1241
1255
|
initialized = true;
|
|
@@ -2756,9 +2770,9 @@ function writeStore(board, store) {
|
|
|
2756
2770
|
}
|
|
2757
2771
|
/** The id of a request: the hash of the facts that decide its entry, so the same facts are one request however often they are sent — its `why` rides beside them and never makes a new one. */
|
|
2758
2772
|
export function requestIdOf(fields) {
|
|
2759
|
-
const { storyId, title, pri, effort,
|
|
2773
|
+
const { storyId, title, pri, effort, name, brief, eligible, origin, place, pressedAt, forced, ruling } = fields;
|
|
2760
2774
|
// NULL-OK: field forced is OPTIONAL and therefore it is ok to check for NULL
|
|
2761
|
-
const facts = [STORY_QUEUE_WIRE, storyId, title, pri, effort,
|
|
2775
|
+
const facts = [STORY_QUEUE_WIRE, storyId, title, pri, effort, name, brief, eligible, origin, place ?? null, pressedAt ?? null, ...(forced === undefined ? [] : [forced]), ...(ruling === undefined ? [] : [ruling])];
|
|
2762
2776
|
return createHash("sha256").update(JSON.stringify(facts)).digest("hex").slice(0, 16);
|
|
2763
2777
|
}
|
|
2764
2778
|
const sleepSync = (ms) => {
|
|
@@ -2930,7 +2944,8 @@ export function submitStory(board, given, now) {
|
|
|
2930
2944
|
return { request: standing, written: false, acked: ack };
|
|
2931
2945
|
if (standing?.requestId === requestId && sameWhy && now - standing.submittedAt < ACK_LATE_MS)
|
|
2932
2946
|
return { request: standing, written: false, unackedMs: now - standing.submittedAt };
|
|
2933
|
-
const
|
|
2947
|
+
const { provider: _previousProvider, model: _previousModel, ...work } = fields;
|
|
2948
|
+
const request = { v: STORY_QUEUE_WIRE, requestId, submittedAt: now, ...work };
|
|
2934
2949
|
writeWhole(board, requestFile(board, given.storyId), request);
|
|
2935
2950
|
if (ack?.requestId === requestId)
|
|
2936
2951
|
return { request, written: true, acked: ack };
|
|
@@ -2975,8 +2990,14 @@ function clearRefusal(e, reading) {
|
|
|
2975
2990
|
}
|
|
2976
2991
|
/** 🔴 #4318 — whether the lane `held` names is this entry's own worker whose job record reads dead: a dead worker holds nothing, so the story is not kept from a fresh worker by it. */
|
|
2977
2992
|
function holdIsItsDeadWorker(e, held, reading) {
|
|
2993
|
+
const worker = e.worker;
|
|
2978
2994
|
// NULL-OK: field worker is OPTIONAL and therefore it is ok to check for NULL
|
|
2979
|
-
|
|
2995
|
+
if (worker === undefined)
|
|
2996
|
+
return false;
|
|
2997
|
+
// A job resumed by Claude can have a different ID from the session the roster reports.
|
|
2998
|
+
// NULL-OK: field lostSessionId is OPTIONAL and therefore it is ok to check for NULL
|
|
2999
|
+
const own = held.includes(worker.jobId) || (worker.lostSessionId !== undefined && held.includes(worker.lostSessionId));
|
|
3000
|
+
return own && !reading().alive;
|
|
2980
3001
|
}
|
|
2981
3002
|
/** A board pass failed before it could select: each queued entry it held back gets one `held-back` trace step naming why, written again only when the reason changes, so a stalled entry's own trace says why it waits. */
|
|
2982
3003
|
export async function traceHeldBack(board, why, now) {
|
|
@@ -3426,8 +3447,6 @@ function refusalOf(r) {
|
|
|
3426
3447
|
return `priority "${r.pri}" is none of ${PRI_ORDER.join(" ")}`;
|
|
3427
3448
|
if (rankIn(EFFORT_ORDER, r.effort) === -1)
|
|
3428
3449
|
return `size "${r.effort}" is none of ${EFFORT_ORDER.join(" ")}`;
|
|
3429
|
-
if (r.eligible && !QUEUE_PROVIDER_CHOICES.includes(r.provider))
|
|
3430
|
-
return `provider "${r.provider}" is not started by this queue — choose Claude, Copilot, Codex, OpenCode or AUTO`;
|
|
3431
3450
|
return undefined;
|
|
3432
3451
|
}
|
|
3433
3452
|
const priorAuthorityOf = (e) => Math.max(e?.startPressedAt ?? 0, e?.handStop?.at ?? 0, e?.worker?.startedAt ?? 0, e?.forceStartedAt ?? 0, e?.forceEventAt ?? 0);
|
|
@@ -3449,7 +3468,7 @@ function applyRequest(store, r, now) {
|
|
|
3449
3468
|
const intentAt = r.forced ?? r.pressedAt;
|
|
3450
3469
|
const priorAuthority = priorAuthorityOf(e);
|
|
3451
3470
|
const freshForce = r.forced !== undefined && r.forced > priorAuthority;
|
|
3452
|
-
const fields = { title: r.title, pri: r.pri, effort: r.effort,
|
|
3471
|
+
const fields = { title: r.title, pri: r.pri, effort: r.effort, name: r.name, brief: r.brief, eligible: r.eligible, why: r.why, ruling: r.ruling };
|
|
3453
3472
|
// NULL-OK: field e is OPTIONAL and therefore it is ok to check for NULL
|
|
3454
3473
|
if (e === undefined) {
|
|
3455
3474
|
if (!r.eligible)
|
|
@@ -3580,6 +3599,8 @@ function forceEntry(e, now, by, eventAt = now) {
|
|
|
3580
3599
|
}
|
|
3581
3600
|
/** The provider refused to start a story's worker: its own words, which the entry carries and the queue starts again on its backoff. */
|
|
3582
3601
|
export class WorkerNotStarted extends Error {
|
|
3602
|
+
/** The exact launch-time model a refused native turn attempted. */
|
|
3603
|
+
attemptedModel;
|
|
3583
3604
|
/** A new input was unsent; retain the previously owned native identity rather than silently replacing its context. */
|
|
3584
3605
|
retained;
|
|
3585
3606
|
/** Whether the queue starts it again on its backoff. */
|
|
@@ -3634,6 +3655,10 @@ export function fenceStart(provider, what) {
|
|
|
3634
3655
|
if ((owner === CLUSTER_OWNER) !== startsAsCluster)
|
|
3635
3656
|
throw new WorkerRefused(`${what} was not started: ${provider} agents are started by ${owner === CLUSTER_OWNER ? "the agent cluster (handed over under #4230)" : "the fleet (FleetView and BullseyeNotif)"} now, not by this process`);
|
|
3636
3657
|
}
|
|
3658
|
+
/** No currently usable route can start the worker. No input was sent. */
|
|
3659
|
+
export class QueueRouteUnavailable extends WorkerNotStarted {
|
|
3660
|
+
constructor(message) { super(message, true); }
|
|
3661
|
+
}
|
|
3637
3662
|
// GATE: the first wait before a parked worker is woken in its own session; doubled for each earlier wake up to WAKE_DOUBLINGS, so a worker that keeps stopping is woken less often but is never given up on
|
|
3638
3663
|
export const WAKE_BASE_MS = 60_000;
|
|
3639
3664
|
// GATE: how many times the wait doubles — past it a parked worker is woken every WAKE_BASE_MS * 2^WAKE_DOUBLINGS (32 min)
|
|
@@ -3764,8 +3789,8 @@ const pastQuestion = (worker, now) => {
|
|
|
3764
3789
|
delete worker.question;
|
|
3765
3790
|
worker.pastAt = now;
|
|
3766
3791
|
};
|
|
3767
|
-
/**
|
|
3768
|
-
export const asksMeni = (q) =>
|
|
3792
|
+
/** #4571 — only an actual prompt may be a decision; worker stops and guesses remain queue state. */
|
|
3793
|
+
export const asksMeni = (q) => q.prompt === true && q.act !== true && !USAGE_LIMIT.test(q.text.trim());
|
|
3769
3794
|
/** 🔴 #4544/#4545 — a usage-limit stop an earlier pass recorded as his question is no question of his: it leaves the worker whatever state its entry is in, so the board never puts it to him again, and an entry withdrawn on the decision the board made of it says what holds it instead. */
|
|
3770
3795
|
function dropUsageLimitQuestion(e, now) {
|
|
3771
3796
|
const asked = e.worker?.question;
|
|
@@ -3783,7 +3808,7 @@ function takeRuling(store, e, now) {
|
|
|
3783
3808
|
const asked = e.worker?.question;
|
|
3784
3809
|
const ruling = e.ruling;
|
|
3785
3810
|
// NULL-OK: field question is OPTIONAL and therefore it is ok to check for NULL
|
|
3786
|
-
if (asked === undefined || ruling === undefined || asked.answer !== undefined)
|
|
3811
|
+
if (asked === undefined || ruling === undefined || asked.answer !== undefined || !asksMeni(asked))
|
|
3787
3812
|
return;
|
|
3788
3813
|
if (!answersQuestion(ruling, asked))
|
|
3789
3814
|
return;
|
|
@@ -3823,6 +3848,29 @@ export const REARM_DOUBLINGS = 2;
|
|
|
3823
3848
|
export const ARCHIVE_KEPT_DAYS = 7;
|
|
3824
3849
|
/** 🔴 #4418 — a provider's HTTP 402 refusal, in the words its CLI reports it: the account the worker billed has no money or quota left, which no re-send to that account changes. */
|
|
3825
3850
|
const ACCOUNT_REFUSAL = /API Error: 402\b|\b402 (?:Payment Required|Insufficient Balance|You need positive balance|You have exceeded your monthly quota)|hit your (?:weekly|5-hour|five-hour|session|usage|monthly)? ?limit|Credit balance is too low|issue with the selected model \(claude-|account (?:has been |is )?(?:suspended|disabled)/i;
|
|
3851
|
+
const ROUTE_REFUSAL = /(?:rate[ _-]?limit|usage limit reached|insufficient[_ ]quota|too many requests|quota exceeded|model(?:_not_found|.{0,60}(?:unavailable|not available|not supported|not found|does not exist|access denied))|does not advertise.{0,50}model|HTTP (?:401|403|429|5[0-9]{2})\b|ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENETUNREACH)/i;
|
|
3852
|
+
const MODEL_REFUSAL = /model(?:_not_found|.{0,80}(?:unavailable|not available|not supported|not found|does not exist|access denied|not have access))|(?:cannot|does not|not permitted to) (?:use|serve|access).{0,30}\bmodel\b/i;
|
|
3853
|
+
export function providerRouteFailure(why) {
|
|
3854
|
+
return ACCOUNT_REFUSAL.test(why) || ROUTE_REFUSAL.test(why) || MODEL_REFUSAL.test(why);
|
|
3855
|
+
}
|
|
3856
|
+
function coolRoute(e, provider, now, why, nativeModel) {
|
|
3857
|
+
const attempts = Math.max(e.attempts, 1);
|
|
3858
|
+
const delay = attempts >= WORKER_ATTEMPTS ? rearmDelayMs(attempts) : RETRY_BASE_MS * 2 ** Math.min(attempts, REARM_DOUBLINGS);
|
|
3859
|
+
const model = nativeModel ?? (e.selectedRoute?.provider === provider ? e.selectedRoute.model : undefined);
|
|
3860
|
+
if (model !== undefined && MODEL_REFUSAL.test(why)) {
|
|
3861
|
+
e.modelRefusals = { ...e.modelRefusals, [provider]: { ...e.modelRefusals?.[provider], [model]: now + delay } };
|
|
3862
|
+
}
|
|
3863
|
+
else
|
|
3864
|
+
e.routeRefusals = { ...e.routeRefusals, [provider]: now + delay };
|
|
3865
|
+
}
|
|
3866
|
+
function retryProviderRoute(e, provider, now, why, nativeModel) {
|
|
3867
|
+
coolRoute(e, provider, now, why, nativeModel);
|
|
3868
|
+
delete e.accountRefused;
|
|
3869
|
+
e.state = "retrying";
|
|
3870
|
+
e.nextTryAt = now + RETRY_BASE_MS;
|
|
3871
|
+
e.why = `${why}; the next attempt reads available providers and models again`;
|
|
3872
|
+
step(e, now, "retry", e.why);
|
|
3873
|
+
}
|
|
3826
3874
|
/** 🔴 #4123 — how long after the queue gave up on a story it is offered to the line again. */
|
|
3827
3875
|
export const rearmDelayMs = (attempts) => REARM_BASE_MS * 2 ** Math.min(Math.max(attempts - WORKER_ATTEMPTS, 0), REARM_DOUBLINGS);
|
|
3828
3876
|
// GATE: how long one stretch of a queue pass may hold the resident service's thread before it lets a waiting request through
|
|
@@ -3910,7 +3958,7 @@ function noteCarried(e, reading, now) {
|
|
|
3910
3958
|
return true;
|
|
3911
3959
|
}
|
|
3912
3960
|
/** A worker that ended with its story still open: started again after its backoff, stopped in `failed` past {@link WORKER_ATTEMPTS}, or at once when its provider refused it as the box stands (`retried` false), read again after the first backoff. */
|
|
3913
|
-
function afterWorker(e, now, why, retried = true, refund = false) {
|
|
3961
|
+
function afterWorker(e, now, why, retried = true, { refund = false, lostJob = false } = {}) {
|
|
3914
3962
|
if (!ACCOUNT_REFUSAL.test(why))
|
|
3915
3963
|
delete e.accountRefusals;
|
|
3916
3964
|
if (!e.eligible) {
|
|
@@ -3941,7 +3989,9 @@ function afterWorker(e, now, why, retried = true, refund = false) {
|
|
|
3941
3989
|
e.attempts -= 1;
|
|
3942
3990
|
e.neverHeldRefusals = (e.neverHeldRefusals ?? 0) + 1;
|
|
3943
3991
|
}
|
|
3944
|
-
|
|
3992
|
+
// A missing Claude job gets one replacement even at the ordinary limit. Its attempt still counts.
|
|
3993
|
+
const limit = lostJob ? WORKER_ATTEMPTS + 1 : WORKER_ATTEMPTS;
|
|
3994
|
+
if (e.attempts >= limit) {
|
|
3945
3995
|
e.state = "failed";
|
|
3946
3996
|
delete e.nextTryAt;
|
|
3947
3997
|
e.why = `its worker was started ${e.attempts} times and the story is still open — the last: ${why}`;
|
|
@@ -4296,7 +4346,7 @@ async function passHeld(board, world, now) {
|
|
|
4296
4346
|
if (e.state === "failed") {
|
|
4297
4347
|
const gaveUp = e.trace.filter((t) => t.stage === "failed").pop();
|
|
4298
4348
|
// 🔴 #4485 — a story reported for a worker that never recorded itself, after its one restart, waits for his press or ↻ Retry: no re-arm starts it a third time on the same cause
|
|
4299
|
-
if (!e.eligible || gaveUp === undefined || neverRecordedSpent(e))
|
|
4349
|
+
if (!e.eligible || gaveUp === undefined || (world.resolveRoute === undefined && neverRecordedSpent(e)))
|
|
4300
4350
|
continue;
|
|
4301
4351
|
delete e.worker?.killedAt;
|
|
4302
4352
|
// NULL-OK: field accountRefused is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -4494,12 +4544,46 @@ async function passHeld(board, world, now) {
|
|
|
4494
4544
|
if (!watching)
|
|
4495
4545
|
continue;
|
|
4496
4546
|
const w = workerNow();
|
|
4547
|
+
const prompted = w.prompted === true && w.approval !== true && w.guessed !== true;
|
|
4497
4548
|
// NULL-OK: field found is OPTIONAL and therefore it is ok to check for NULL
|
|
4498
4549
|
if (e.worker === undefined && w.found !== undefined)
|
|
4499
4550
|
e.worker = w.found;
|
|
4500
4551
|
if (noteCarried(e, w, now))
|
|
4501
4552
|
continue;
|
|
4502
4553
|
delete e.worker?.carried;
|
|
4554
|
+
const failedWorker = e.worker;
|
|
4555
|
+
if (w.nativeModel !== undefined && failedWorker !== undefined)
|
|
4556
|
+
failedWorker.nativeModel = w.nativeModel;
|
|
4557
|
+
const routeError = w.refused ?? w.needs ?? w.why;
|
|
4558
|
+
if (!prompted && world.resolveRoute !== undefined && e.eligible && failedWorker !== undefined && w.parked?.limit === undefined && providerRouteFailure(routeError) && (!w.alive || w.parked !== undefined)) {
|
|
4559
|
+
if (w.session !== undefined)
|
|
4560
|
+
failedWorker.session = w.session;
|
|
4561
|
+
if (failedWorker.question?.prompt === true || providerRouteFailure(failedWorker.question?.text ?? ""))
|
|
4562
|
+
pastQuestion(failedWorker, now);
|
|
4563
|
+
const provider = failedWorker.provider;
|
|
4564
|
+
if (w.parked === undefined) {
|
|
4565
|
+
dropWorker(e);
|
|
4566
|
+
retryProviderRoute(e, provider, now, routeError, failedWorker.nativeModel);
|
|
4567
|
+
continue;
|
|
4568
|
+
}
|
|
4569
|
+
if (failedWorker.parkedAt === undefined) {
|
|
4570
|
+
coolRoute(e, provider, now, routeError, failedWorker.nativeModel);
|
|
4571
|
+
step(e, now, "retry", `${routeError}; the next attempt reads available providers and models again`);
|
|
4572
|
+
}
|
|
4573
|
+
delete failedWorker.blocked;
|
|
4574
|
+
delete failedWorker.needs;
|
|
4575
|
+
failedWorker.parkedAt ??= now;
|
|
4576
|
+
e.why = `${routeError}; its session and work are kept for the next available route`;
|
|
4577
|
+
if (w.parked.live) {
|
|
4578
|
+
if (w.parked.tasks === undefined)
|
|
4579
|
+
idle = idleWorker(failedWorker, () => w, now);
|
|
4580
|
+
break judge;
|
|
4581
|
+
}
|
|
4582
|
+
e.state = "queued";
|
|
4583
|
+
if (e.forced === true || now >= failedWorker.parkedAt + RETRY_BASE_MS)
|
|
4584
|
+
wakeable.set(e, w.parked.sessionId);
|
|
4585
|
+
continue;
|
|
4586
|
+
}
|
|
4503
4587
|
if (w.refused !== undefined) {
|
|
4504
4588
|
delete e.worker?.killedAt;
|
|
4505
4589
|
e.state = "failed";
|
|
@@ -4523,6 +4607,12 @@ async function passHeld(board, world, now) {
|
|
|
4523
4607
|
delete e.neverHeldRefusals;
|
|
4524
4608
|
if (w.neverRecorded === true) {
|
|
4525
4609
|
e.neverRecorded = (e.neverRecorded ?? 0) + 1;
|
|
4610
|
+
const provider = e.worker?.provider ?? e.selectedRoute?.provider;
|
|
4611
|
+
if (world.resolveRoute !== undefined && e.eligible && provider !== undefined) {
|
|
4612
|
+
dropWorker(e);
|
|
4613
|
+
retryProviderRoute(e, provider, now, w.why);
|
|
4614
|
+
continue;
|
|
4615
|
+
}
|
|
4526
4616
|
if (e.neverRecorded > NEVER_RECORDED_RESTARTS) {
|
|
4527
4617
|
// 🔴 #4485 — the restart for this cause was spent and its worker never recorded itself either: reported with the cause, never started again on it until his press or ↻ Retry (a story the board no longer asks for rests withdrawn with the same words, and a later ask puts it back to failed)
|
|
4528
4618
|
e.state = e.eligible ? "failed" : "withdrawn";
|
|
@@ -4535,8 +4625,17 @@ async function passHeld(board, world, now) {
|
|
|
4535
4625
|
continue;
|
|
4536
4626
|
}
|
|
4537
4627
|
delete e.neverRecorded;
|
|
4628
|
+
if (w.lostJob === true) {
|
|
4629
|
+
// Keep the job and session IDs until selection can recognize our stale roster claim. The missing transcript cannot replace an earlier checkpoint.
|
|
4630
|
+
if (e.worker?.session !== undefined) {
|
|
4631
|
+
e.worker.lostSessionId = e.worker.session.id;
|
|
4632
|
+
delete e.worker.session;
|
|
4633
|
+
}
|
|
4634
|
+
afterWorker(e, now, w.why, true, { lostJob: true });
|
|
4635
|
+
continue;
|
|
4636
|
+
}
|
|
4538
4637
|
// A post the owning native main accepted and no lane ever took is not a start the story spent: its charge is given back, its recorded main is kept, and the trace keeps what happened.
|
|
4539
|
-
afterWorker(e, now, w.neverHeld === undefined ? w.why : `${w.why}; that post never held a lane, so it spends none of the story's starts`, true, w.neverHeld !== undefined);
|
|
4638
|
+
afterWorker(e, now, w.neverHeld === undefined ? w.why : `${w.why}; that post never held a lane, so it spends none of the story's starts`, true, { refund: w.neverHeld !== undefined });
|
|
4540
4639
|
continue;
|
|
4541
4640
|
}
|
|
4542
4641
|
if (e.state === "starting") {
|
|
@@ -4565,8 +4664,6 @@ async function passHeld(board, world, now) {
|
|
|
4565
4664
|
step(e, now, "progress", `its worker ${e.worker.jobId} works again — ${w.why}`);
|
|
4566
4665
|
}
|
|
4567
4666
|
}
|
|
4568
|
-
if (w.nativeModel !== undefined && e.worker !== undefined)
|
|
4569
|
-
e.worker.nativeModel = w.nativeModel;
|
|
4570
4667
|
if (w.progressAt !== undefined && e.worker !== undefined && w.progressAt !== e.worker.progressAt) {
|
|
4571
4668
|
if (e.worker.progressAt === undefined)
|
|
4572
4669
|
step(e, now, "progress", `its work first moved at ${new Date(w.progressAt).toISOString()}`);
|
|
@@ -4577,16 +4674,19 @@ async function passHeld(board, world, now) {
|
|
|
4577
4674
|
e.worker.session = w.session;
|
|
4578
4675
|
delete e.neverRecorded;
|
|
4579
4676
|
}
|
|
4677
|
+
const previousQuestion = e.worker.question;
|
|
4678
|
+
const act = !prompted && w.approval !== true && w.guessed !== true;
|
|
4580
4679
|
// NULL-OK: field question is OPTIONAL and therefore it is ok to check for NULL
|
|
4581
|
-
if (w.blocked === true && w.question !== undefined &&
|
|
4680
|
+
if (w.blocked === true && w.question !== undefined && (previousQuestion === undefined || ((w.guessed !== true || previousQuestion.prompt === true) && (previousQuestion.text !== w.question || (previousQuestion.prompt === true) !== prompted || (previousQuestion.act === true) !== act || previousQuestion.approval !== w.approval)))) {
|
|
4582
4681
|
const from = Math.max(e.worker.startedAt, e.worker.pastAt ?? 0);
|
|
4583
4682
|
if (w.approval === true) {
|
|
4584
4683
|
e.worker.question = { text: w.question, at: now, from, approval: true, answer: APPROVAL_ANSWER };
|
|
4585
4684
|
step(e, now, "answered", `its worker ${e.worker.jobId} stopped on Claude Code's approval of a tool call, which is never Meni's question: the queue answers it itself, stops its process and wakes its own session with the answer — ${w.question}`);
|
|
4586
4685
|
}
|
|
4587
4686
|
else {
|
|
4588
|
-
e.worker.question = { text: w.question, at: now, from, ...(
|
|
4589
|
-
|
|
4687
|
+
e.worker.question = { text: w.question, at: now, from, ...(prompted ? { prompt: true } : act ? { act: true } : {}) };
|
|
4688
|
+
if (prompted)
|
|
4689
|
+
step(e, now, "asking", `its worker ${e.worker.jobId} waits on Meni's answer to: ${w.question}`);
|
|
4590
4690
|
takeRuling(store, e, now);
|
|
4591
4691
|
}
|
|
4592
4692
|
}
|
|
@@ -4787,7 +4887,9 @@ async function passHeld(board, world, now) {
|
|
|
4787
4887
|
const unscheduled = autoStartHeld(board);
|
|
4788
4888
|
const heldWhy = (e) => {
|
|
4789
4889
|
// 🔴 #4499 — his answer to the question its worker waits on is his own word on that story, so AUTO START off never holds the wake that carries it; his ⏸ Stop still does
|
|
4790
|
-
const
|
|
4890
|
+
const answer = e.worker?.question;
|
|
4891
|
+
const humanAnswer = (unhanded(answer) !== undefined && answer?.approval !== true) || (e.lastWorkerAnswer !== undefined && e.lastWorkerAnswer.approval !== true);
|
|
4892
|
+
const manual = unscheduled !== undefined && !hisOwn(e) && !humanAnswer ? unscheduled : undefined;
|
|
4791
4893
|
// NULL-OK: field halted is OPTIONAL and therefore it is ok to check for NULL
|
|
4792
4894
|
return e.forced === true ? manual : halted ?? manual;
|
|
4793
4895
|
};
|
|
@@ -4858,6 +4960,8 @@ async function passHeld(board, world, now) {
|
|
|
4858
4960
|
const sessionId = wakeable.get(e);
|
|
4859
4961
|
// NULL-OK: field sessionId is OPTIONAL and therefore it is ok to check for NULL
|
|
4860
4962
|
if (sessionId !== undefined) {
|
|
4963
|
+
if (e.nextTryAt !== undefined && e.nextTryAt > now)
|
|
4964
|
+
continue;
|
|
4861
4965
|
const reading = clearRefusal(e, world.worker(e, board));
|
|
4862
4966
|
if (!pressedAfterCarrierStarted(e, e.worker) && noteCarried(e, reading, now)) {
|
|
4863
4967
|
save();
|
|
@@ -4880,14 +4984,27 @@ async function passHeld(board, world, now) {
|
|
|
4880
4984
|
unwoken(`its worker ${parked.jobId} is parked, and ${wakeHeld}`);
|
|
4881
4985
|
continue;
|
|
4882
4986
|
}
|
|
4883
|
-
|
|
4987
|
+
let roomless;
|
|
4988
|
+
try {
|
|
4989
|
+
roomless = await world.noRoomFor?.(e);
|
|
4990
|
+
}
|
|
4991
|
+
catch (err) {
|
|
4992
|
+
if (!(err instanceof QueueRouteUnavailable))
|
|
4993
|
+
throw err;
|
|
4994
|
+
// OWNER: ITER/LOOP — retain this exact session until an eligible route exists. No wake was submitted.
|
|
4995
|
+
unwoken(err.message);
|
|
4996
|
+
e.nextTryAt = now + RETRY_BASE_MS;
|
|
4997
|
+
continue;
|
|
4998
|
+
}
|
|
4884
4999
|
if (roomless !== undefined) {
|
|
4885
5000
|
const moved = `its ${parked.provider} worker ${parked.jobId} is not woken: ${roomless}`;
|
|
4886
5001
|
dropWorker(e);
|
|
4887
5002
|
delete e.forced;
|
|
4888
5003
|
delete e.forcedBy;
|
|
4889
5004
|
step(e, now, "worker-ended", moved);
|
|
4890
|
-
|
|
5005
|
+
e.state = "queued";
|
|
5006
|
+
delete e.nextTryAt;
|
|
5007
|
+
e.why = moved;
|
|
4891
5008
|
save();
|
|
4892
5009
|
continue;
|
|
4893
5010
|
}
|
|
@@ -4915,10 +5032,13 @@ async function passHeld(board, world, now) {
|
|
|
4915
5032
|
const answered = parked.question?.answer === undefined ? undefined : { question: parked.question.text, answer: parked.question.answer, ...(parked.question.approval === true ? { approval: true } : {}) };
|
|
4916
5033
|
const woken = await world.wake(e, board, sessionId, wakeMessage(e.storyId, answered), worker => { e.worker = worker; save(); });
|
|
4917
5034
|
workerMade();
|
|
5035
|
+
delete e.nextTryAt;
|
|
4918
5036
|
e.landedAt = now;
|
|
4919
5037
|
// NULL-OK: field cwd is OPTIONAL and therefore it is ok to check for NULL
|
|
4920
5038
|
// 🔴 #4485 — a wake that resumed the very session it was handed keeps that session even under a new job id, so its worker is never read as one that never recorded itself
|
|
4921
5039
|
e.worker = { ...woken, wakes, ...(woken.provider === parked.provider && (woken.jobId === parked.jobId || parked.session?.id === sessionId) ? keptSession(parked) : {}), ...(parked.cwd === undefined ? {} : { cwd: parked.cwd }) };
|
|
5040
|
+
if (woken.nativeModel !== undefined && e.selectedRoute?.provider === woken.provider)
|
|
5041
|
+
e.selectedRoute = { ...e.selectedRoute, model: woken.nativeModel };
|
|
4922
5042
|
delete e.forced;
|
|
4923
5043
|
delete e.forcedBy;
|
|
4924
5044
|
if (noteCarried(e, { alive: true, why: "", carried: e.worker.carried }, now)) {
|
|
@@ -4933,10 +5053,21 @@ async function passHeld(board, world, now) {
|
|
|
4933
5053
|
catch (err) {
|
|
4934
5054
|
if (!(err instanceof WorkerNotStarted))
|
|
4935
5055
|
throw err;
|
|
5056
|
+
if (err instanceof QueueRouteUnavailable) {
|
|
5057
|
+
e.worker = parked;
|
|
5058
|
+
unwoken(err.message);
|
|
5059
|
+
e.nextTryAt = now + RETRY_BASE_MS;
|
|
5060
|
+
save();
|
|
5061
|
+
continue;
|
|
5062
|
+
}
|
|
4936
5063
|
if (err.retained !== undefined) {
|
|
4937
5064
|
e.worker = { ...(pressedAfterCarrierStarted(e, parked) ? parked : err.retained), wakes };
|
|
4938
5065
|
e.state = "queued";
|
|
4939
5066
|
e.why = `its existing native context is retained; the new follow-up was not sent: ${err.message}`;
|
|
5067
|
+
if (world.resolveRoute !== undefined && providerRouteFailure(err.message)) {
|
|
5068
|
+
coolRoute(e, parked.provider, now, err.message, err.attemptedModel ?? parked.nativeModel);
|
|
5069
|
+
e.nextTryAt = now + RETRY_BASE_MS;
|
|
5070
|
+
}
|
|
4940
5071
|
save();
|
|
4941
5072
|
continue;
|
|
4942
5073
|
}
|
|
@@ -5004,7 +5135,10 @@ async function passHeld(board, world, now) {
|
|
|
5004
5135
|
delete e.forced;
|
|
5005
5136
|
delete e.forcedBy;
|
|
5006
5137
|
step(e, now, "worker-ended", why);
|
|
5007
|
-
|
|
5138
|
+
if (providerRouteFailure(err.message))
|
|
5139
|
+
retryProviderRoute(e, parked.provider, now, why, err.attemptedModel ?? parked.nativeModel);
|
|
5140
|
+
else
|
|
5141
|
+
afterWorker(e, now, why);
|
|
5008
5142
|
}
|
|
5009
5143
|
}
|
|
5010
5144
|
save();
|
|
@@ -5020,6 +5154,20 @@ async function passHeld(board, world, now) {
|
|
|
5020
5154
|
}
|
|
5021
5155
|
if (!e.eligible || !(e.state === "queued" || ((e.state === "retrying" || e.state === "failed") && e.nextTryAt !== undefined && e.nextTryAt <= now)))
|
|
5022
5156
|
continue;
|
|
5157
|
+
if (e.worker === undefined) {
|
|
5158
|
+
const adopted = world.adoptRunning?.(e);
|
|
5159
|
+
if (adopted !== undefined) {
|
|
5160
|
+
e.worker = adopted;
|
|
5161
|
+
e.state = "running";
|
|
5162
|
+
e.landedAt = now;
|
|
5163
|
+
delete e.nextTryAt;
|
|
5164
|
+
workerMade(adopted.box !== undefined);
|
|
5165
|
+
e.why = `its existing ${adopted.provider} worker ${adopted.jobId} was adopted`;
|
|
5166
|
+
step(e, now, "started", e.why);
|
|
5167
|
+
save();
|
|
5168
|
+
continue;
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5023
5171
|
if (inArchive(e.worker)) {
|
|
5024
5172
|
// NULL-OK: field archiveRefused is OPTIONAL and therefore it is ok to check for NULL
|
|
5025
5173
|
if (e.worker.archiveRefused === undefined)
|
|
@@ -5110,6 +5258,24 @@ async function passHeld(board, world, now) {
|
|
|
5110
5258
|
const box = spillTo === undefined ? undefined : spillTo.box;
|
|
5111
5259
|
// NULL-OK: field box is OPTIONAL and therefore it is ok to check for NULL
|
|
5112
5260
|
const released = box === undefined ? memoryReleased(e, now) : ` — on ${box}, because ${lowMemory.why}`;
|
|
5261
|
+
if (world.resolveRoute !== undefined) {
|
|
5262
|
+
try {
|
|
5263
|
+
const route = await world.resolveRoute(e, box);
|
|
5264
|
+
if ((e.selectedRoute?.provider ?? e.worker?.provider) !== route.provider || (e.selectedRoute?.model !== undefined && e.selectedRoute.model !== route.model))
|
|
5265
|
+
e.attempts = 0;
|
|
5266
|
+
e.selectedRoute = route;
|
|
5267
|
+
}
|
|
5268
|
+
catch (error) {
|
|
5269
|
+
if (!(error instanceof QueueRouteUnavailable))
|
|
5270
|
+
throw error;
|
|
5271
|
+
// OWNER: ITER/LOOP — no usable route. Keep the checkpoint and retry the reading without spending a start.
|
|
5272
|
+
e.state = "retrying";
|
|
5273
|
+
e.nextTryAt = now + RETRY_BASE_MS;
|
|
5274
|
+
holdBack(e, now, "held-back", error.message);
|
|
5275
|
+
save();
|
|
5276
|
+
continue;
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5113
5279
|
if (e.forced === true) {
|
|
5114
5280
|
delete e.accountRefusals;
|
|
5115
5281
|
e.cutPending = forcer;
|
|
@@ -5131,7 +5297,9 @@ async function passHeld(board, world, now) {
|
|
|
5131
5297
|
e.worker = box === undefined ? await world.launch(e, board, record) : await world.spill(e, board, box, record);
|
|
5132
5298
|
// NULL-OK: field box is OPTIONAL and therefore it is ok to check for NULL
|
|
5133
5299
|
workerMade(e.worker.box !== undefined);
|
|
5134
|
-
e.provider
|
|
5300
|
+
delete e.provider;
|
|
5301
|
+
delete e.model;
|
|
5302
|
+
delete e.lastWorkerAnswer;
|
|
5135
5303
|
e.landedAt = now;
|
|
5136
5304
|
if (noteCarried(e, { alive: true, why: "", carried: e.worker.carried }, now)) {
|
|
5137
5305
|
save();
|
|
@@ -5171,8 +5339,22 @@ async function passHeld(board, world, now) {
|
|
|
5171
5339
|
continue;
|
|
5172
5340
|
}
|
|
5173
5341
|
// OWNER: ITER/LOOP — the provider refused this story's start, so its entry carries the provider's words and is started again on its backoff like a worker that ended, or stops failed when the provider refused it for good; the next entry in line is started.
|
|
5174
|
-
|
|
5175
|
-
|
|
5342
|
+
const provider = e.selectedRoute?.provider;
|
|
5343
|
+
const why = `its ${provider ?? "agent"} worker could not be started: ${err.message}`;
|
|
5344
|
+
step(e, Date.now(), "worker-ended", why);
|
|
5345
|
+
if (err instanceof QueueRouteUnavailable) {
|
|
5346
|
+
e.attempts = Math.max(0, e.attempts - 1);
|
|
5347
|
+
e.state = "retrying";
|
|
5348
|
+
e.nextTryAt = now + RETRY_BASE_MS;
|
|
5349
|
+
e.why = why;
|
|
5350
|
+
}
|
|
5351
|
+
else if (provider !== undefined && (err instanceof WorkerRefused || providerRouteFailure(err.message) || err.retried)) {
|
|
5352
|
+
if (err instanceof WorkerRefused && e.worker === undefined)
|
|
5353
|
+
e.attempts = Math.max(0, e.attempts - 1);
|
|
5354
|
+
retryProviderRoute(e, provider, now, why);
|
|
5355
|
+
}
|
|
5356
|
+
else
|
|
5357
|
+
afterWorker(e, now, why, err.retried);
|
|
5176
5358
|
}
|
|
5177
5359
|
save();
|
|
5178
5360
|
}
|
|
@@ -5863,8 +6045,13 @@ const mtimeOf = (file) => {
|
|
|
5863
6045
|
/** 🔴 #4337 — drops the entry's worker, keeping the conversation it recorded as the story's last one, so the story's next worker reads that agent's own transcript first. */
|
|
5864
6046
|
function dropWorker(e) {
|
|
5865
6047
|
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
5866
|
-
if (e.worker?.session !== undefined)
|
|
6048
|
+
if (e.worker?.session !== undefined && e.worker.session.transcript !== "")
|
|
5867
6049
|
e.lastSession = e.worker.session;
|
|
6050
|
+
if (e.worker?.cwd !== undefined)
|
|
6051
|
+
e.lastWorkerCwd = e.worker.cwd;
|
|
6052
|
+
const asked = e.worker?.question;
|
|
6053
|
+
if (asked?.answer !== undefined && asked.handed !== true)
|
|
6054
|
+
e.lastWorkerAnswer = { question: asked.text, answer: asked.answer, ...(asked.approval === true ? { approval: true } : {}) };
|
|
5868
6055
|
delete e.worker;
|
|
5869
6056
|
}
|
|
5870
6057
|
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
@@ -5872,19 +6059,21 @@ const keptSession = (worker) => ({ ...(worker.session === undefined ? {} : { ses
|
|
|
5872
6059
|
/** 🔴 #4123 — a worker whose job record Claude Code no longer keeps: still the story's worker while a process runs its session or that process is inside its start grace, woken in its own session once none does and its transcript is on disk, ended when there is no session to wake. */
|
|
5873
6060
|
function goneWorker(worker, now, home) {
|
|
5874
6061
|
const gone = `its job ${worker.jobId} is no longer on Claude Code's record`;
|
|
6062
|
+
const sessionId = worker.session?.id ?? worker.lostSessionId;
|
|
5875
6063
|
// 🔴 #4485 — a worker that never recorded itself: no job record, no session and no work ever read of it. Inside its start grace it may still be writing its record; past it the start is named as never recorded, so the queue restarts it once for that cause and then reports it.
|
|
5876
|
-
// NULL-OK: field
|
|
5877
|
-
if (
|
|
6064
|
+
// NULL-OK: field sessionId is OPTIONAL and therefore it is ok to check for NULL
|
|
6065
|
+
if (sessionId === undefined && worker.progressAt === undefined) {
|
|
5878
6066
|
const age = Math.round((now - worker.startedAt) / 1000);
|
|
5879
6067
|
if (now - worker.startedAt < WORKER_START_GRACE_MS)
|
|
5880
6068
|
return { alive: true, why: `its job ${worker.jobId} was started ${age}s ago and its process has not recorded itself yet` };
|
|
5881
6069
|
return { alive: false, neverRecorded: true, why: `its job ${worker.jobId} never recorded itself — ${age}s after its start Claude Code holds no record and no session of it, past its ${WORKER_START_GRACE_MS / 60_000}-minute start grace` };
|
|
5882
6070
|
}
|
|
5883
6071
|
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
6072
|
+
if (sessionId !== undefined && liveClaudeSessions(home).has(sessionId))
|
|
6073
|
+
return { alive: true, why: `${gone}, and a process runs its session ${sessionId}, so it is still this story's worker` };
|
|
6074
|
+
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
5884
6075
|
if (worker.session === undefined || readingTranscript(worker.session.transcript, () => mtimeOf(worker.session.transcript)) === undefined)
|
|
5885
|
-
return { alive: false, why: gone };
|
|
5886
|
-
if (liveClaudeSessions(home).has(worker.session.id))
|
|
5887
|
-
return { alive: true, why: `${gone}, and a process runs its session ${worker.session.id}, so it is still this story's worker` };
|
|
6076
|
+
return { alive: false, lostJob: true, why: gone };
|
|
5888
6077
|
if (now - worker.startedAt < WORKER_START_GRACE_MS)
|
|
5889
6078
|
return { alive: true, why: `${gone}, and it was started ${Math.round((now - worker.startedAt) / 1000)}s ago, so its process may not have recorded its session ${worker.session.id} yet` };
|
|
5890
6079
|
const cut = readingTranscript(worker.session.transcript, () => turnCutOff(worker.session.transcript));
|
|
@@ -6096,19 +6285,23 @@ const worksNow = (job) => {
|
|
|
6096
6285
|
};
|
|
6097
6286
|
/** 🔴 #4499 — a job stopped on Meni: its turn ended on an act it cannot do itself, or it sits mid-turn on a prompt (a question, a permission) that nobody at a background session's terminal answers; a message queued to it waits behind that stop and is no work. */
|
|
6098
6287
|
const waitsOnMeni = (job) => job.state === "blocked" || job.tempo === "blocked";
|
|
6099
|
-
/**
|
|
6288
|
+
/** #4499/#4571 — the recorded mid-turn question is a prompt. Needs and detail describe the stop for the queue. */
|
|
6100
6289
|
// NULL-OK: field block is OPTIONAL and therefore it is ok to check for NULL
|
|
6101
6290
|
const questionOf = (job) => {
|
|
6102
|
-
const
|
|
6103
|
-
|
|
6104
|
-
|
|
6291
|
+
const prompt = job.state === "blocked" ? undefined : job.block?.questions?.[0]?.question;
|
|
6292
|
+
// NULL-OK: field question is OPTIONAL and therefore it is ok to check for NULL
|
|
6293
|
+
if (prompt !== undefined && prompt.trim() !== "")
|
|
6294
|
+
return { question: prompt, prompted: true };
|
|
6295
|
+
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
6296
|
+
if (job.needs !== undefined && job.needs.trim() !== "")
|
|
6297
|
+
return { question: job.needs };
|
|
6105
6298
|
// NULL-OK: field detail is OPTIONAL and therefore it is ok to check for NULL
|
|
6106
6299
|
if (job.detail !== undefined && job.detail.trim() !== "")
|
|
6107
6300
|
return { question: job.detail, guessed: true };
|
|
6108
6301
|
return job.state === "blocked" ? {} : { question: `its prompt names no question (job ${job.sessionId})`, guessed: true };
|
|
6109
6302
|
};
|
|
6110
6303
|
/** 🔴 #4544 — the act Claude Code's job record names when its account's usage limit stopped the turn: `rate limited — wait and retry · You've hit your weekly limit · resets Nov 26, 10pm (America/Los_Angeles)`. */
|
|
6111
|
-
export const USAGE_LIMIT = /^rate limited —
|
|
6304
|
+
export const USAGE_LIMIT = /^(?:rate limited — |usage limit reached(?:\s*[—-]|$))/i;
|
|
6112
6305
|
/** 🔴 #4544 — the reset a usage-limit stop names: `resets 2am`, `resets 12:30pm`, `resets Nov 26, 10pm`, each with an optional `(<IANA zone>)`. */
|
|
6113
6306
|
const LIMIT_RESET = /resets (?:([A-Z][a-z]{2}) (\d{1,2}),? (?:at )?)?(\d{1,2})(?::(\d{2}))? ?(am|pm)(?: \(([^)]+)\))?/i;
|
|
6114
6307
|
const MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
@@ -6225,7 +6418,7 @@ const parkedWakeAt = (worker, parkedAt, parked) => Math.max(parkedAt + parkedWai
|
|
|
6225
6418
|
export function storyWorkerLiveness(worker, now, home = claudeHome()) {
|
|
6226
6419
|
const job = jobRecordOf(worker.jobId, home);
|
|
6227
6420
|
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
6228
|
-
const asLastRead = worker.blocked === true ? { blocked: true, ...(worker.needs === undefined ? {} : { needs: worker.needs })
|
|
6421
|
+
const asLastRead = worker.blocked === true ? { blocked: true, ...(worker.needs === undefined ? {} : { needs: worker.needs }) } : {};
|
|
6229
6422
|
if (job === "torn")
|
|
6230
6423
|
return { alive: true, ...asLastRead, why: `its job ${worker.jobId}'s record was caught mid-rewrite, so it is read again on the next pass` };
|
|
6231
6424
|
if (job === "gone")
|
|
@@ -6260,10 +6453,10 @@ export function storyWorkerLiveness(worker, now, home = claudeHome()) {
|
|
|
6260
6453
|
return { alive: true, ...progress, parked: { sessionId: job.sessionId, live, limit, ...(live && waitsOnTasks(job) ? { tasks: true } : {}) }, why: `its job ${worker.jobId} stopped on its account's usage limit, which is never Meni's question, so it is parked and woken in its own session ${when} — ${limit.said}` };
|
|
6261
6454
|
}
|
|
6262
6455
|
const asked = questionOf(job);
|
|
6263
|
-
// NULL-OK: field block is OPTIONAL and therefore it is ok to check for NULL
|
|
6264
|
-
const approval = job.state !== "blocked" && job.block?.questions?.[0] === undefined && job.needs !== undefined && TOOL_APPROVAL.test(job.needs);
|
|
6265
6456
|
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
6266
|
-
const
|
|
6457
|
+
const approval = job.state !== "blocked" && asked.prompted !== true && job.needs !== undefined && TOOL_APPROVAL.test(job.needs);
|
|
6458
|
+
// NULL-OK: field needs is OPTIONAL and therefore it is ok to check for NULL
|
|
6459
|
+
const blocked = waitsOnMeni(job) ? { blocked: true, ...(job.needs === undefined ? {} : { needs: job.needs }), ...asked, ...(approval ? { approval: true } : {}) } : {};
|
|
6267
6460
|
if (live && worksNow(job))
|
|
6268
6461
|
return { alive: true, ...progress, ...blocked, why: waitsOnMeni(job) ? `its job ${worker.jobId} waits on Meni while a background task of its own still runs, so it keeps its lane` : `its job ${worker.jobId} runs as session ${job.sessionId} (${job.state})` };
|
|
6269
6462
|
const how = live ? (job.state !== "blocked" && job.tempo === "blocked" ? `its process sits on a prompt waiting on Meni` : `its turn ended ${job.state} and its process waits at the prompt`) : `it reads ${job.state} and no process on this machine runs session ${job.sessionId}`;
|
|
@@ -6273,12 +6466,12 @@ export function storyWorkerLiveness(worker, now, home = claudeHome()) {
|
|
|
6273
6466
|
const BACKGROUNDED = /^backgrounded · (\S+)/m;
|
|
6274
6467
|
/** What `claude --bg --resume` adds when the session it was handed still runs, having started a second process on that session: `note: session <id> is already running in the background, so this started a copy as <copy>.` */
|
|
6275
6468
|
const STARTED_A_COPY = /session (\S+) is already running in the background, so this started a copy as ([^\s.]+)/;
|
|
6276
|
-
/** 🔴 #4123 — wakes a parked `claude --bg` session in place
|
|
6277
|
-
export async function wakeStoryWorker(sessionId, message, cwd, cli, now) {
|
|
6469
|
+
/** 🔴 #4123 — wakes a parked `claude --bg` session in place, in the folder it was started in. */
|
|
6470
|
+
export async function wakeStoryWorker(sessionId, message, cwd, cli, now, model) {
|
|
6278
6471
|
fenceStart("claude", `claude --bg --resume ${sessionId}`);
|
|
6279
6472
|
const start = await trustLaunchFolder(cwd);
|
|
6280
6473
|
return new Promise((resolve, reject) => {
|
|
6281
|
-
execFile(cli.cmd, [...cli.args, "--bg", "--resume", sessionId, message], { cwd: start, windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
6474
|
+
execFile(cli.cmd, [...cli.args, "--bg", "--resume", sessionId, ...(model === undefined ? [] : ["--model", model]), message], { cwd: start, windowsHide: true, timeout: LAUNCH_TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
6282
6475
|
const said = `${stdout}${stderr}`;
|
|
6283
6476
|
const copy = STARTED_A_COPY.exec(said);
|
|
6284
6477
|
if (copy !== null) {
|
|
@@ -6288,7 +6481,7 @@ export async function wakeStoryWorker(sessionId, message, cwd, cli, now) {
|
|
|
6288
6481
|
}
|
|
6289
6482
|
const job = BACKGROUNDED.exec(said);
|
|
6290
6483
|
if (job !== null)
|
|
6291
|
-
return resolve({ provider: "claude", startedAt: now, jobId: job[1] });
|
|
6484
|
+
return resolve({ provider: "claude", startedAt: now, jobId: job[1], ...(model === undefined ? {} : { nativeModel: model }) });
|
|
6292
6485
|
reject(new WorkerNotStarted(`claude --bg --resume ${err === null ? "printed no job id" : `failed (${err.message.split("\n")[0]})`} — ${said.replace(/\s+/g, " ").trim().slice(-300) || "it printed nothing"}`, err !== null && err.killed !== true));
|
|
6293
6486
|
});
|
|
6294
6487
|
});
|
|
@@ -6459,12 +6652,13 @@ export async function retireStoryWorker(worker, cli, record, home = claudeHome()
|
|
|
6459
6652
|
await stopStoryWorker(worker.jobId, cli, home);
|
|
6460
6653
|
// NULL-OK: field linkScanPath is OPTIONAL and therefore it is ok to check for NULL
|
|
6461
6654
|
const session = worker.session ?? (job === "gone" || job.linkScanPath === undefined ? undefined : { id: job.sessionId, transcript: job.linkScanPath });
|
|
6655
|
+
const sessionId = session?.id ?? worker.lostSessionId;
|
|
6656
|
+
// NULL-OK: field sessionId is OPTIONAL and therefore it is ok to check for NULL
|
|
6657
|
+
if (sessionId !== undefined && liveClaudeSessions(home).has(sessionId))
|
|
6658
|
+
throw new WorkerNotStarted(`a process still runs its session ${sessionId}, so it is archived once that process has gone`);
|
|
6462
6659
|
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
6463
|
-
if (session !== undefined)
|
|
6464
|
-
if (liveClaudeSessions(home).has(session.id))
|
|
6465
|
-
throw new WorkerNotStarted(`a process still runs its session ${session.id}, so it is archived once that process has gone`);
|
|
6660
|
+
if (session !== undefined)
|
|
6466
6661
|
record(session);
|
|
6467
|
-
}
|
|
6468
6662
|
// NULL-OK: field session is OPTIONAL and therefore it is ok to check for NULL
|
|
6469
6663
|
const moved = session === undefined ? "unknown" : moveConversation(session.transcript, archivedTranscriptOf(session.transcript, home));
|
|
6470
6664
|
if (job !== "gone") {
|
|
@@ -6610,6 +6804,8 @@ export function purgeStoryWorker(sessions, home = claudeHome(), temp = tmpdir())
|
|
|
6610
6804
|
const LAUNCH_TIMEOUT_MS = 60_000;
|
|
6611
6805
|
/** A story's worker, started windowless in `dir` (the story's own worktree when it has one, else the board) as a `claude --bg` session whose lifetime is the story's; `cli` is Claude Code's program as this machine runs it. */
|
|
6612
6806
|
export function launchStoryWorker(entry, dir, cli, now, env) {
|
|
6807
|
+
if (entry.model === undefined)
|
|
6808
|
+
throw new WorkerRefused("the launch did not resolve a Claude model");
|
|
6613
6809
|
return launchClaudeJob(entry.name, entry.model, workerBrief(entry), dir, cli, now, env);
|
|
6614
6810
|
}
|
|
6615
6811
|
const CLAUDE_MODEL = /^(default|best|inherit|opus|sonnet|haiku|fable|opusplan)(\[1m\])?$|^claude-/i;
|
|
@@ -6768,7 +6964,7 @@ export async function launchClaudeJob(name, model, brief, cwd, cli, now, env = l
|
|
|
6768
6964
|
const said = `${stdout}${stderr}`;
|
|
6769
6965
|
const job = BACKGROUNDED.exec(said);
|
|
6770
6966
|
if (job !== null)
|
|
6771
|
-
return resolve({ provider: "claude", startedAt: now, jobId: job[1] });
|
|
6967
|
+
return resolve({ provider: "claude", startedAt: now, jobId: job[1], nativeModel: model });
|
|
6772
6968
|
reject(new WorkerNotStarted(`claude --bg ${err === null ? "printed no job id" : `failed (${err.message.split("\n")[0]})`} — ${said.replace(/\s+/g, " ").trim().slice(-300) || "it printed nothing"}`));
|
|
6773
6969
|
});
|
|
6774
6970
|
});
|