@cohortapp/agent-sdk 2.18.23 → 2.18.25
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/bin/maestro.mjs +39 -4
- package/lib/assurance/first-reply.mjs +61 -0
- package/lib/assurance/notice-voice.mjs +23 -0
- package/lib/rate-guard.mjs +80 -4
- package/package.json +1 -1
- package/scripts/daemon/assurance.mjs +97 -1
package/bin/maestro.mjs
CHANGED
|
@@ -932,13 +932,31 @@ function isGitRepo(cwd) {
|
|
|
932
932
|
|
|
933
933
|
// Build a Set of repo-relative paths that are dirty (modified, added, untracked).
|
|
934
934
|
// Single git invocation is much faster than per-file checks.
|
|
935
|
+
//
|
|
936
|
+
// RETURNS null WHEN IT CANNOT TELL — never an empty Set.
|
|
937
|
+
//
|
|
938
|
+
// This used to `catch { }` and return the empty Set it had built, with a
|
|
939
|
+
// comment claiming "caller will fall back to caution mode". There was no such
|
|
940
|
+
// fallback: an empty Set is precisely the shape of "I checked, and nothing is
|
|
941
|
+
// dirty", so every local edit classified as pristine-and-overwritable. The
|
|
942
|
+
// caller's real caution signal is `null` — the value it already uses for "not
|
|
943
|
+
// a git repo", which preserves everything.
|
|
944
|
+
//
|
|
945
|
+
// It was reachable, and it was reached. `execFileSync` defaults to a 1 MiB
|
|
946
|
+
// maxBuffer; a repo with a large untracked tree (a node_modules, a build dir,
|
|
947
|
+
// a log directory) overflows it, git is killed with ENOBUFS, and the upgrade
|
|
948
|
+
// then overwrote hand-applied patches on a seat while reporting every stage
|
|
949
|
+
// ok, with empty backup and incoming directories. maxBuffer is raised to the
|
|
950
|
+
// same 256 MB `scripts/fleet/rollout.mjs` uses for exactly this reason — but
|
|
951
|
+
// the size is the mitigation and the null is the fix, because any git failure
|
|
952
|
+
// at all (a lock, a corrupt index, git missing from PATH) had the same effect.
|
|
935
953
|
function dirtyPathSet(cwd) {
|
|
936
954
|
const set = new Set();
|
|
937
955
|
try {
|
|
938
956
|
const out = execFileSync(
|
|
939
957
|
"git",
|
|
940
958
|
["status", "--porcelain=v1", "-z", "--untracked-files=all"],
|
|
941
|
-
{ cwd, encoding: "utf-8" }
|
|
959
|
+
{ cwd, encoding: "utf-8", maxBuffer: 256 * 1024 * 1024 }
|
|
942
960
|
);
|
|
943
961
|
// -z separates records with NUL; each record is "XY path" (no quoting).
|
|
944
962
|
// For renames (R/C) the format is "R newpath\0oldpath\0" — we only care
|
|
@@ -950,9 +968,12 @@ function dirtyPathSet(cwd) {
|
|
|
950
968
|
// Anything in porcelain output is non-clean by definition.
|
|
951
969
|
if (status !== " ") set.add(path);
|
|
952
970
|
}
|
|
953
|
-
} catch {
|
|
954
|
-
//
|
|
971
|
+
} catch (e) {
|
|
972
|
+
// CANNOT TELL. Say so; do not answer "nothing is dirty".
|
|
973
|
+
dirtyPathSet.lastError = (e && (e.code || e.message)) || "unknown";
|
|
974
|
+
return null;
|
|
955
975
|
}
|
|
976
|
+
dirtyPathSet.lastError = null;
|
|
956
977
|
return set;
|
|
957
978
|
}
|
|
958
979
|
|
|
@@ -1240,6 +1261,13 @@ Per-file behaviour:
|
|
|
1240
1261
|
}
|
|
1241
1262
|
|
|
1242
1263
|
const dirty = inGit ? dirtyPathSet(cwd) : null;
|
|
1264
|
+
if (inGit && dirty === null) {
|
|
1265
|
+
// Same posture as "not a git repo", and said just as loudly. Silence here
|
|
1266
|
+
// is what made the data loss invisible: every stage reported ok.
|
|
1267
|
+
warn(`Could not read local modifications from git (${dirtyPathSet.lastError}).`);
|
|
1268
|
+
warn("All existing files will be treated as locally modified and preserved.");
|
|
1269
|
+
warn("Prune is disabled for this run. Use --force-overwrite to override.");
|
|
1270
|
+
}
|
|
1243
1271
|
const ignorePatterns = loadMaestroignore(cwd);
|
|
1244
1272
|
if (ignorePatterns) {
|
|
1245
1273
|
log(`.maestroignore loaded (${ignorePatterns.length} pattern${ignorePatterns.length === 1 ? "" : "s"})`);
|
|
@@ -1313,7 +1341,9 @@ Per-file behaviour:
|
|
|
1313
1341
|
}
|
|
1314
1342
|
|
|
1315
1343
|
// Case 4: locally modified? Determine via git dirty set.
|
|
1316
|
-
|
|
1344
|
+
// `dirty` is null both outside a repo and when git could not be read.
|
|
1345
|
+
// Both mean "unprovable", and unprovable must preserve.
|
|
1346
|
+
const locallyModified = dirty ? dirty.has(repoRel) : true;
|
|
1317
1347
|
|
|
1318
1348
|
if (locallyModified && !flags.forceOverwrite) {
|
|
1319
1349
|
counts.preserved++;
|
|
@@ -1382,6 +1412,11 @@ Per-file behaviour:
|
|
|
1382
1412
|
log("Prune skipped (--no-prune): upstream-deleted files left in place.");
|
|
1383
1413
|
} else if (!inGit) {
|
|
1384
1414
|
warn("Prune skipped: not a git repo, so pristine framework files can't be told from yours.");
|
|
1415
|
+
} else if (!dirty) {
|
|
1416
|
+
// Prune deletes files on the strength of "git says this is tracked and
|
|
1417
|
+
// clean". With no readable git status there is no such strength, and the
|
|
1418
|
+
// failure mode is deleting an operator's work.
|
|
1419
|
+
warn(`Prune skipped: could not read git status (${dirtyPathSet.lastError}), so pristine files can't be told from yours.`);
|
|
1385
1420
|
} else if (!priorManifest) {
|
|
1386
1421
|
log("Prune skipped: no shipped-manifest yet, so framework files can't be told from your own.");
|
|
1387
1422
|
log(`Recording one now (${SHIPPED_MANIFEST_REL}); prune takes effect from the next upgrade.`);
|
|
@@ -483,3 +483,64 @@ export function isAgentStatusNotice(body) {
|
|
|
483
483
|
}
|
|
484
484
|
return false;
|
|
485
485
|
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* A SESSION SAYING IT HAS ALREADY ANSWERED THIS ONE.
|
|
489
|
+
*
|
|
490
|
+
* The silent-success rescue (`assurance.settleSession`) exists to hand a waiting
|
|
491
|
+
* requester the result their session produced but failed to send. It reads
|
|
492
|
+
* "exited 0 having sent nothing" as exactly one state — the answer got stuck on
|
|
493
|
+
* the way out — when there are two. The second is a session that read the item,
|
|
494
|
+
* recognised it as something it had ALREADY replied to, and declined to reply
|
|
495
|
+
* twice.
|
|
496
|
+
*
|
|
497
|
+
* Published, that second state is nonsense in the room. Measured, 2026-09-30
|
|
498
|
+
* 18:21:49Z, one seat into a shared engineering channel:
|
|
499
|
+
*
|
|
500
|
+
* Here's where I got to:
|
|
501
|
+
* Archived — this is a duplicate delivery of the same audit I already
|
|
502
|
+
* responded to in-channel this session. Logged to
|
|
503
|
+
* `logs/audit/2026-09-30-actions.jsonl`, no second response sent.
|
|
504
|
+
*
|
|
505
|
+
* Every word was true. The seat HAD answered, and declining to answer twice is
|
|
506
|
+
* the owner's standing instruction ("sometimes a reply isn't needed"). The
|
|
507
|
+
* rescue overrode that judgement and posted the reasoning, addressed to nobody,
|
|
508
|
+
* citing a path no colleague can open.
|
|
509
|
+
*
|
|
510
|
+
* WHY NOT SIMPLY "THE SESSION SAID IT SENT NOTHING". That was this function's
|
|
511
|
+
* first cut and it was wrong — three existing tests caught it, which is what
|
|
512
|
+
* they are for. "Nothing was sent." is the marker for BOTH states: the live
|
|
513
|
+
* sighting that created the rescue in the first place is a session whose final
|
|
514
|
+
* text read "I reviewed the three failing checks and pushed fixes for two. The
|
|
515
|
+
* third needs a decision from you. Nothing was sent." There the human is owed
|
|
516
|
+
* the result and suppressing it loses a decision they must make. The sentence
|
|
517
|
+
* does not separate the states; ALREADY-ANSWERED does, because it is the only
|
|
518
|
+
* one of the two in which the ask is genuinely discharged.
|
|
519
|
+
*
|
|
520
|
+
* Deliberately NOT matched: "no action needed", "nothing to do", "already
|
|
521
|
+
* handled". Those describe the WORK, not the REPLY — a session that says the
|
|
522
|
+
* work needs nothing may still owe the asker that sentence.
|
|
523
|
+
*/
|
|
524
|
+
const ALREADY_ANSWERED_PATTERNS = Object.freeze([
|
|
525
|
+
/\balready (?:responded|replied|answered)\b/i,
|
|
526
|
+
/\bduplicate (?:delivery|copy|of the same|of an?)\b/i,
|
|
527
|
+
/\b(?:responded|replied|answered) to (?:this|it|the same) (?:already|earlier|in[- ]channel)\b/i,
|
|
528
|
+
/\bsame (?:item|message|request|ask) (?:i|we) (?:already |have already )?(?:answered|replied to|responded to)\b/i,
|
|
529
|
+
]);
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Does this session's final text state that it had ALREADY replied to this
|
|
533
|
+
* item, so the ask is discharged and a rescue would be a second voice?
|
|
534
|
+
*
|
|
535
|
+
* Judged over the WHOLE text, not per paragraph: the statement is routinely a
|
|
536
|
+
* mid-sentence clause ("…duplicate delivery of the same audit I already
|
|
537
|
+
* responded to in-channel this session.").
|
|
538
|
+
*
|
|
539
|
+
* @param {unknown} finalText the session's own end-of-turn text
|
|
540
|
+
* @returns {boolean}
|
|
541
|
+
*/
|
|
542
|
+
export function isAlreadyAnsweredElsewhere(finalText) {
|
|
543
|
+
const t = String(finalText == null ? "" : finalText);
|
|
544
|
+
if (!t.trim()) return false;
|
|
545
|
+
return ALREADY_ANSWERED_PATTERNS.some((re) => re.test(t));
|
|
546
|
+
}
|
|
@@ -345,6 +345,29 @@ export function fallbackNotice(o = {}) {
|
|
|
345
345
|
// colleague tells them, so a notice may only assert what it saw.
|
|
346
346
|
return `${about} was cut off part-way — the session running it stopped and a new one took over. I've picked it back up from where it stopped.`;
|
|
347
347
|
}
|
|
348
|
+
// Gated on a retry actually being pending, not on the flag alone. A closed
|
|
349
|
+
// obligation really HAS stopped, so the final notice's "I've stopped trying"
|
|
350
|
+
// is true and must survive a caller that passes `paused` through both paths —
|
|
351
|
+
// the composer already narrows it, but this template is exported and is not
|
|
352
|
+
// entitled to assume its callers do.
|
|
353
|
+
if (o.paused && (o.willRetry || o.kind === "failure:retrying")) {
|
|
354
|
+
// A SPENT USAGE WINDOW IS NOT A BREAKAGE AND THE RETRY IS NOT RUNNING.
|
|
355
|
+
//
|
|
356
|
+
// The retrying line below asserts two things that are both false of a
|
|
357
|
+
// capped seat: that something "broke" (nothing did — a quota ran out on
|
|
358
|
+
// schedule) and that the work is running "now" (the rate-guard breaker is
|
|
359
|
+
// holding the spawn until the window resets). This branch exists because
|
|
360
|
+
// that fallback is not a rare path for THIS cause: the written notice is
|
|
361
|
+
// produced by spawning the same CLI that is capped, so when a seat is out
|
|
362
|
+
// of allowance the generator fails and this template is what the room
|
|
363
|
+
// actually reads. Every one of the ten notices measured on seat A028 on
|
|
364
|
+
// 2026-09-30 came through here.
|
|
365
|
+
//
|
|
366
|
+
// It promises only what the machinery does: one more attempt (RETRY_MAX),
|
|
367
|
+
// then a final notice either way. It does not promise to keep trying until
|
|
368
|
+
// the window reopens, because `sweepObligations` does not.
|
|
369
|
+
return `${about} hasn't gone through yet — ${cause}. I'll try again shortly and come back to you either way.`;
|
|
370
|
+
}
|
|
348
371
|
if (o.willRetry || o.kind === "failure:retrying") {
|
|
349
372
|
return `${about} broke before it finished: ${cause}. I'm running it again now.`;
|
|
350
373
|
}
|
package/lib/rate-guard.mjs
CHANGED
|
@@ -275,17 +275,93 @@ export const RATE_USAGE_LIMIT_HOLD_MS = num(process.env.RATE_USAGE_LIMIT_HOLD_MS
|
|
|
275
275
|
*/
|
|
276
276
|
export function parseResetAt(text, deps) {
|
|
277
277
|
if (!text || typeof text !== "string") return null;
|
|
278
|
-
|
|
278
|
+
// Lead-ins the providers actually use. "reset at" was missing and is the
|
|
279
|
+
// canonical Claude Code phrasing ("Your limit will reset at 3pm (UTC)") —
|
|
280
|
+
// the old alternation had `reset` and `resets at` but not `reset at`, so the
|
|
281
|
+
// one message this parser exists to read was the one it could not.
|
|
282
|
+
const m =
|
|
283
|
+
/(?:reset|resets|try again|available again|back)(?:\s+(?:at|in))?\s+(\d{1,2})(?::(\d{2}))?\s*([ap])\.?\s?m\.?/i.exec(text);
|
|
279
284
|
if (!m) return null;
|
|
280
285
|
const nowMs = clock(deps)();
|
|
281
286
|
let hr = parseInt(m[1], 10) % 12;
|
|
282
287
|
if (/p/i.test(m[3])) hr += 12;
|
|
283
288
|
const min = m[2] ? parseInt(m[2], 10) : 0;
|
|
289
|
+
|
|
290
|
+
// THE STATED ZONE WINS OVER THE SEAT'S OWN.
|
|
291
|
+
//
|
|
292
|
+
// This used to resolve the wall clock in the daemon's local zone always, on
|
|
293
|
+
// the reasoning that a seat reads a message written for its own timezone.
|
|
294
|
+
// That is not true of either real message: Claude Code stamps "(UTC)", and
|
|
295
|
+
// this file's OWN test corpus carries "resets 9:40pm (Australia/Sydney)".
|
|
296
|
+
// Against a Gulf seat those are 4 and 6 hours of error, and the error is not
|
|
297
|
+
// cosmetic — `recordUsageLimit` holds the breaker until this instant, so
|
|
298
|
+
// reading it too early reopens into a still-spent window (a storm) and too
|
|
299
|
+
// late leaves the seat dark for hours after its quota returned. Both were
|
|
300
|
+
// observed shapes on this fleet.
|
|
301
|
+
const zone = statedZone(text);
|
|
302
|
+
const t = zone ? epochInZone(nowMs, hr, min, zone) : epochLocal(nowMs, hr, min);
|
|
303
|
+
if (t == null) return null;
|
|
304
|
+
return t <= nowMs ? t + 24 * 60 * 60 * 1000 : t;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** The wall clock `hr:min` today, in the daemon's own zone. */
|
|
308
|
+
function epochLocal(nowMs, hr, min) {
|
|
284
309
|
const cand = new Date(nowMs);
|
|
285
310
|
cand.setHours(hr, min, 0, 0);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
311
|
+
return cand.getTime();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* A timezone named in the message — "(UTC)", "(GMT)", a trailing "UTC", or an
|
|
316
|
+
* IANA "Area/City" in parentheses. null when the message names none, which is
|
|
317
|
+
* the case that keeps the old local-zone behaviour exactly as it was.
|
|
318
|
+
*/
|
|
319
|
+
function statedZone(text) {
|
|
320
|
+
const paren = /\(([A-Za-z]+(?:\/[A-Za-z_+-]+)+)\)/.exec(text);
|
|
321
|
+
if (paren) return paren[1];
|
|
322
|
+
if (/\b(?:UTC|GMT)\b/i.test(text)) return "UTC";
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The epoch ms of `hr:min` on the zone's CURRENT day, for an arbitrary IANA
|
|
328
|
+
* zone. Two passes because a zone's offset depends on the instant being
|
|
329
|
+
* resolved: the first guess picks an offset, the second re-resolves with it,
|
|
330
|
+
* which converges across a DST boundary where a single pass lands an hour out.
|
|
331
|
+
* Returns null for an unusable zone name rather than throwing — a malformed
|
|
332
|
+
* zone must degrade to "no reset time known", never take the daemon down.
|
|
333
|
+
*/
|
|
334
|
+
function epochInZone(nowMs, hr, min, zone) {
|
|
335
|
+
try {
|
|
336
|
+
const parts = zoneParts(nowMs, zone);
|
|
337
|
+
let guess = Date.UTC(parts.year, parts.month - 1, parts.day, hr, min, 0, 0);
|
|
338
|
+
for (let i = 0; i < 2; i += 1) {
|
|
339
|
+
guess = Date.UTC(parts.year, parts.month - 1, parts.day, hr, min, 0, 0) - zoneOffsetMs(guess, zone);
|
|
340
|
+
}
|
|
341
|
+
return guess;
|
|
342
|
+
} catch {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The calendar date it currently is in `zone`. Throws on a bad zone name. */
|
|
348
|
+
function zoneParts(epochMs, zone) {
|
|
349
|
+
const f = new Intl.DateTimeFormat("en-US", {
|
|
350
|
+
timeZone: zone, hour12: false,
|
|
351
|
+
year: "numeric", month: "2-digit", day: "2-digit",
|
|
352
|
+
hour: "2-digit", minute: "2-digit", second: "2-digit",
|
|
353
|
+
});
|
|
354
|
+
const got = {};
|
|
355
|
+
for (const p of f.formatToParts(new Date(epochMs))) {
|
|
356
|
+
if (p.type !== "literal") got[p.type] = parseInt(p.value, 10);
|
|
357
|
+
}
|
|
358
|
+
return { year: got.year, month: got.month, day: got.day, hour: got.hour % 24, minute: got.minute, second: got.second };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** `zone`'s UTC offset in ms at a given instant. */
|
|
362
|
+
function zoneOffsetMs(epochMs, zone) {
|
|
363
|
+
const p = zoneParts(epochMs, zone);
|
|
364
|
+
return Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) - epochMs;
|
|
289
365
|
}
|
|
290
366
|
|
|
291
367
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cohortapp/agent-sdk",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.25",
|
|
4
4
|
"description": "Cohort Agent SDK — autonomous AI colleague runtime. Deploy senior AI colleagues on dedicated Mac minis, wired to the Cohort operating surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -98,7 +98,7 @@ import {
|
|
|
98
98
|
noticeRejection,
|
|
99
99
|
fallbackNotice,
|
|
100
100
|
} from "../../lib/assurance/notice-voice.mjs";
|
|
101
|
-
import { isRetiredFirstReply, firstReplyShape, REACTIONS } from "../../lib/assurance/first-reply.mjs";
|
|
101
|
+
import { isRetiredFirstReply, firstReplyShape, REACTIONS, isAlreadyAnsweredElsewhere } from "../../lib/assurance/first-reply.mjs";
|
|
102
102
|
// The unit of acknowledgement is the CONVERSATION, not the message: four
|
|
103
103
|
// messages in a row earn ONE first response that was written with all four in
|
|
104
104
|
// front of it. `groupIntoBatches` + `batchVerdict` decide WHEN and WHICH;
|
|
@@ -110,6 +110,7 @@ import {
|
|
|
110
110
|
batchQuietMs,
|
|
111
111
|
batchMaxSpanMs,
|
|
112
112
|
} from "../../lib/assurance/batch.mjs";
|
|
113
|
+
import { classifyUsageLimit } from "../../lib/rate-guard.mjs";
|
|
113
114
|
|
|
114
115
|
// ── Board mirror seams ───────────────────────────────────────────────────────
|
|
115
116
|
// Imported lazily so a board module problem can never stop the daemon booting,
|
|
@@ -1118,6 +1119,11 @@ export function composeFailure(rec, o = {}) {
|
|
|
1118
1119
|
cause: f.human || "the working session ended unexpectedly",
|
|
1119
1120
|
topic: o.topic != null ? o.topic : noticeTopic(rec),
|
|
1120
1121
|
willRetry: !!o.willRetry,
|
|
1122
|
+
// `paused` is set by the CLASSIFIER, not matched on a label here. The
|
|
1123
|
+
// composer has no business knowing which causes mean "held, not broken" —
|
|
1124
|
+
// classifyFailure already decided, and keeping that judgement in one place
|
|
1125
|
+
// is why a new held cause needs no edit to this file.
|
|
1126
|
+
paused: !!f.paused && !!o.willRetry,
|
|
1121
1127
|
});
|
|
1122
1128
|
}
|
|
1123
1129
|
|
|
@@ -1351,6 +1357,32 @@ export function composeInterrupted() {
|
|
|
1351
1357
|
* @param {string} [o.stage]
|
|
1352
1358
|
* @returns {{transient:boolean, label:string, human:string}}
|
|
1353
1359
|
*/
|
|
1360
|
+
/**
|
|
1361
|
+
* The cause clause for a spent usage window.
|
|
1362
|
+
*
|
|
1363
|
+
* Names the reset when `rate-guard` could parse one out of the provider's own
|
|
1364
|
+
* message, and says only "when the window resets" when it could not — the same
|
|
1365
|
+
* rule the rest of this file follows: assert what was observed, never a guess.
|
|
1366
|
+
* A wrong clock time is worse than no clock time, because a colleague plans
|
|
1367
|
+
* around it.
|
|
1368
|
+
*
|
|
1369
|
+
* @param {number|null} resetAt epoch ms, or null when unparseable
|
|
1370
|
+
*/
|
|
1371
|
+
function usageCapHuman(resetAt) {
|
|
1372
|
+
if (typeof resetAt === "number" && Number.isFinite(resetAt)) {
|
|
1373
|
+
// "7:00pm", not "7:00 PM" — this lands mid-sentence in a message to a
|
|
1374
|
+
// colleague, and the locale default's caps read like a log line.
|
|
1375
|
+
const when = new Date(resetAt)
|
|
1376
|
+
.toLocaleTimeString("en-GB", { hour: "numeric", minute: "2-digit", hour12: true })
|
|
1377
|
+
.replace(/\s*([ap])\.?m\.?/i, (_, ap) => `${ap.toLowerCase()}m`);
|
|
1378
|
+
// Comma, not an em-dash: this clause is interpolated INTO a sentence that
|
|
1379
|
+
// already carries one ("… hasn't gone through yet — <cause>."), and two
|
|
1380
|
+
// dashes in one line read like a transcript rather than a colleague.
|
|
1381
|
+
return `I've used up my usage allowance for now, and it resets at ${when}`;
|
|
1382
|
+
}
|
|
1383
|
+
return "I've used up my usage allowance for now, and it comes back when the window resets";
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1354
1386
|
export function classifyFailure(o = {}) {
|
|
1355
1387
|
const err = String(o.error || "");
|
|
1356
1388
|
const code = o.code;
|
|
@@ -1365,6 +1397,42 @@ export function classifyFailure(o = {}) {
|
|
|
1365
1397
|
if (/budget|spend cap|daily budget|essential-only/i.test(err)) {
|
|
1366
1398
|
return { transient: false, label: "budget_refused", human: "I've hit my spend cap for today, so I can't run the work that would answer this" };
|
|
1367
1399
|
}
|
|
1400
|
+
// A SPENT USAGE WINDOW IS NOT "AN ERROR", AND THE LAYER ALREADY KNOWS IT.
|
|
1401
|
+
//
|
|
1402
|
+
// `lib/rate-guard.mjs` recognises a spent usage window and the dispatcher
|
|
1403
|
+
// holds the breaker until it resets (dispatcher.mjs, two call sites). That
|
|
1404
|
+
// half worked. What did not is that THIS function — the one that decides what
|
|
1405
|
+
// a room is told — never asked. So a capped seat fell through to the generic
|
|
1406
|
+
// `exit_${code}` branch and told ten separate askers "the working session
|
|
1407
|
+
// ended with an error. I'm running it again now", ten times on 2026-09-30,
|
|
1408
|
+
// while the truth was a single fact with a known end time.
|
|
1409
|
+
//
|
|
1410
|
+
// Measured on seat A028 that day: ten asks, each one capped, each one told a
|
|
1411
|
+
// bare error. The owner read the room and diagnosed the cap by eye
|
|
1412
|
+
// ("looks like that seat has hit its limit") — which is the tell that the
|
|
1413
|
+
// notice was withholding what the machine already had.
|
|
1414
|
+
//
|
|
1415
|
+
// PRECEDENCE, both directions, because USAGE_LIMIT_RE matches the bare words
|
|
1416
|
+
// "limit reached" and would otherwise steal two neighbours:
|
|
1417
|
+
// - AFTER the 429 branch: "rate limit reached" carries both signatures, and
|
|
1418
|
+
// a 429 is a recoverable provider blip that SHOULD be retried with
|
|
1419
|
+
// backoff, whereas a spent window must not be hammered.
|
|
1420
|
+
// - AFTER budget_refused: a local spend cap phrased "daily budget limit
|
|
1421
|
+
// reached" would land here and become transient — turning a refusal that
|
|
1422
|
+
// holds for the rest of the day into a retry. Those messages are ours and
|
|
1423
|
+
// their wording is known, so the narrow check goes first.
|
|
1424
|
+
// First match wins, so both neighbours keep precedence over this one.
|
|
1425
|
+
//
|
|
1426
|
+
// `transient` stays TRUE, and that is not an oversight. `sweepObligations`
|
|
1427
|
+
// reads it as "retry once more" (RETRY_MAX=1); false would send the ask
|
|
1428
|
+
// straight to `closeObligation({outcome:"failed"})` and the work would be
|
|
1429
|
+
// abandoned rather than picked up when the window reopens. The retry itself
|
|
1430
|
+
// is already cheap — the breaker refuses the spawn while the hold stands.
|
|
1431
|
+
// The defect being fixed here is the sentence, not the retry policy.
|
|
1432
|
+
const cap = classifyUsageLimit(err, o.deps);
|
|
1433
|
+
if (cap.isLimit) {
|
|
1434
|
+
return { transient: true, label: "usage_capped", paused: true, human: usageCapHuman(cap.resetAt) };
|
|
1435
|
+
}
|
|
1368
1436
|
if (/out of memory|ENOMEM|low free memory/i.test(err)) {
|
|
1369
1437
|
return { transient: true, label: "resource_starved", human: "my machine ran out of memory partway through" };
|
|
1370
1438
|
}
|
|
@@ -1910,6 +1978,34 @@ export async function settleSession(a = {}) {
|
|
|
1910
1978
|
return { spoke: false, text: null, verdict: "silent-success", willRetry: false };
|
|
1911
1979
|
}
|
|
1912
1980
|
const finalText = safeResultText(a.stdout);
|
|
1981
|
+
|
|
1982
|
+
// A SESSION THAT CHOSE SILENCE HAS NOT FAILED TO SPEAK.
|
|
1983
|
+
//
|
|
1984
|
+
// This rescue reads "exited 0 having sent nothing" as one state — the
|
|
1985
|
+
// answer got stuck on the way out. There are two, and the second is a
|
|
1986
|
+
// session that recognised the item as one it had ALREADY replied to.
|
|
1987
|
+
// Publishing that one posts the seat's own reasoning into a room, addressed
|
|
1988
|
+
// to nobody. Measured on 2026-09-30 18:21:49Z, one seat into a shared
|
|
1989
|
+
// engineering channel: "Archived — this is a duplicate delivery of the same
|
|
1990
|
+
// audit I already responded to in-channel this session. Logged to
|
|
1991
|
+
// logs/audit/…jsonl, no second response sent." Every word of that was true,
|
|
1992
|
+
// the seat HAD already answered, and declining to answer twice is the
|
|
1993
|
+
// owner's standing instruction — which this rescue then overrode.
|
|
1994
|
+
//
|
|
1995
|
+
// The debt still closes. Silence was the session's answer, so the ask is
|
|
1996
|
+
// discharged, not abandoned; only the narration is withheld. Same shape as
|
|
1997
|
+
// the ambient-surface branch above, and a distinct note + counter so the
|
|
1998
|
+
// difference stays visible to an operator sweeping outcomes.
|
|
1999
|
+
if (isAlreadyAnsweredElsewhere(finalText)) {
|
|
2000
|
+
closeObligation(a.key, {
|
|
2001
|
+
outcome: "answered",
|
|
2002
|
+
now,
|
|
2003
|
+
note: "session exited 0 stating it had already answered this item; second narration withheld",
|
|
2004
|
+
});
|
|
2005
|
+
counters.bump("assurance.silent_success_already_answered", { service: rec.service });
|
|
2006
|
+
return { spoke: false, text: null, verdict: "silent-success", willRetry: false };
|
|
2007
|
+
}
|
|
2008
|
+
|
|
1913
2009
|
const text = composeSilentSuccess(rec, { finalText });
|
|
1914
2010
|
const res = await send(item, text, { kind: "reply", idempotencySuffix: `rescue-${rec.attempts || 0}` });
|
|
1915
2011
|
closeObligation(a.key, {
|