@cohortapp/agent-sdk 2.18.30 → 2.18.32
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cohortapp/agent-sdk",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.32",
|
|
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": {
|
|
@@ -1652,6 +1652,38 @@ export function markNoticeSaid(rec, notice, now) {
|
|
|
1652
1652
|
*/
|
|
1653
1653
|
async function sayOutcomeNotice(o) {
|
|
1654
1654
|
const { rec, notice, text, item, kind, now } = o;
|
|
1655
|
+
|
|
1656
|
+
// ── NO OUTCOME NOTICE REACHES A DOCUMENT, AT THE CHOKEPOINT ───────────────
|
|
1657
|
+
//
|
|
1658
|
+
// 2.18.30 put this test in `settleSession`, which covered the failed,
|
|
1659
|
+
// timed-out and silently-exited branches and MISSED the sweep's own. A seat
|
|
1660
|
+
// running 2.18.30 then posted the INTERRUPTED variant onto a plan document at
|
|
1661
|
+
// 11:49:10Z — "was cut off part-way — the session running it stopped and a new
|
|
1662
|
+
// one took over" — because `sweepObligations` branch (d) emits through here
|
|
1663
|
+
// without passing through `settleSession` at all. Branch (c), the
|
|
1664
|
+
// past-every-timeout case, had the same hole.
|
|
1665
|
+
//
|
|
1666
|
+
// So the guard belongs HERE rather than at each branch. This function is the
|
|
1667
|
+
// single chokepoint every outcome notice passes through — three callers today
|
|
1668
|
+
// — and a fourth branch added later is covered by construction instead of
|
|
1669
|
+
// reintroducing the defect. Patching three sites and trusting the next author
|
|
1670
|
+
// to remember is how 2.18.30 shipped incomplete.
|
|
1671
|
+
//
|
|
1672
|
+
// WHY THE INTERRUPTED VARIANT IS THE WORST ONE TO LEAVE UNGUARDED. Its trigger
|
|
1673
|
+
// is `rec.daemonPid !== process.pid && !alive(rec.daemonPid)` — a daemon that
|
|
1674
|
+
// was replaced. An AUTOUPDATE RELAUNCH is exactly that, so every seat taking a
|
|
1675
|
+
// release posts one of these for whatever obligation was in flight when it
|
|
1676
|
+
// restarted. On a document surface that makes a release itself the trigger for
|
|
1677
|
+
// a comment nobody asked for, fleet-wide, once per upgrade.
|
|
1678
|
+
//
|
|
1679
|
+
// A reply is unaffected: replies go out through `deliver` directly. Only
|
|
1680
|
+
// OUTCOME notices pass through here, and a document never asked for one.
|
|
1681
|
+
if (isDocumentSurface(rec)) {
|
|
1682
|
+
counters.bump("assurance.notice_withheld_document", { notice, service: rec && rec.service });
|
|
1683
|
+
markNoticeSaid(rec, notice, now);
|
|
1684
|
+
return { sent: false, reason: "document-surface" };
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1655
1687
|
if (noticeAlreadySaid(rec, notice)) {
|
|
1656
1688
|
console.log(`[assurance] ${notice} notice for ${rec.key} already delivered to ${rec.channel} — not repeating it`);
|
|
1657
1689
|
counters.bump("assurance.notice_deduped", { notice, scope: "obligation" });
|
|
@@ -170,11 +170,60 @@ function isEmergencyStop(paths) {
|
|
|
170
170
|
return existsSync(paths.emergencyStop);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Normalise a log call into the one shape every writer downstream expects.
|
|
175
|
+
*
|
|
176
|
+
* PURE, and exported, because this is the whole of the defect and a defect that
|
|
177
|
+
* cost 28,924 lost lines on one seat deserves a test that does not have to
|
|
178
|
+
* start a consumer to reach it.
|
|
179
|
+
*
|
|
180
|
+
* Two conventions were live against a one-parameter `log(entry)`: the
|
|
181
|
+
* consumer's own `log({level, stage, …})`, and the handlers' `log("warn", msg)`
|
|
182
|
+
* — their documented contract, used at 14 sites. Spreading a STRING yields its
|
|
183
|
+
* characters, so the written line became `{"0":"w","1":"a","2":"r","3":"n"}` and
|
|
184
|
+
* the message was dropped by the missing second parameter.
|
|
185
|
+
*
|
|
186
|
+
* Both are accepted rather than one being declared correct. Rejecting either
|
|
187
|
+
* would turn a silent loss into a throw inside a logger, which is worse than
|
|
188
|
+
* the bug.
|
|
189
|
+
*
|
|
190
|
+
* @param {unknown} entry an object, or a level string
|
|
191
|
+
* @param {unknown} [msg] the message, when `entry` is a level string
|
|
192
|
+
* @returns {object} always a plain object, never a spread string
|
|
193
|
+
*/
|
|
194
|
+
export function normaliseLogEntry(entry, msg) {
|
|
195
|
+
if (typeof entry === "string") {
|
|
196
|
+
return msg === undefined ? { level: entry } : { level: entry, msg: String(msg) };
|
|
197
|
+
}
|
|
198
|
+
if (entry && typeof entry === "object" && !Array.isArray(entry)) return entry;
|
|
199
|
+
// Not a string and not a plain object. Spreading it is what shredded the
|
|
200
|
+
// lines, so wrap it and make it loud instead.
|
|
201
|
+
return { level: "error", stage: "log_bad_entry", value: String(entry) };
|
|
202
|
+
}
|
|
203
|
+
|
|
173
204
|
function defaultLogger(entry) {
|
|
174
205
|
// The default logger ALSO writes to logs/cadence-bus/<date>.jsonl via
|
|
175
206
|
// logBusEvent, but mirrors important events to stderr so launchd's
|
|
176
207
|
// StandardErrorPath captures them.
|
|
177
|
-
|
|
208
|
+
//
|
|
209
|
+
// A MISSING LEVEL IS ITSELF AN ALARM. This used to test `entry.level` and
|
|
210
|
+
// nothing else, which made the mirror blind to exactly the failure that
|
|
211
|
+
// destroys the level: a shredded entry has no `.level`, so 28,924 lost lines
|
|
212
|
+
// on one seat produced not one stderr line, and the alarm that would have
|
|
213
|
+
// reported the loss was disabled by the loss. That is the general shape worth
|
|
214
|
+
// naming — a monitor whose firing condition reads a field the failure can
|
|
215
|
+
// damage — and it is the same defect as a pin asserting /restarted/i, which
|
|
216
|
+
// both the truth and the false claim satisfied.
|
|
217
|
+
//
|
|
218
|
+
// So: mirror an unknown level too. The cost of a spurious stderr line is
|
|
219
|
+
// nothing; the cost of a silent one is eleven days.
|
|
220
|
+
const level = entry && typeof entry === "object" ? entry.level : undefined;
|
|
221
|
+
if (level === undefined || level === null || level === "") {
|
|
222
|
+
try { process.stderr.write(`[cadence-consumer] LOG ENTRY WITH NO LEVEL — ${JSON.stringify(entry)}\n`); }
|
|
223
|
+
catch { /* ignore */ }
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (level === "error" || level === "warn") {
|
|
178
227
|
try { process.stderr.write(`[cadence-consumer] ${JSON.stringify(entry)}\n`); }
|
|
179
228
|
catch { /* ignore */ }
|
|
180
229
|
}
|
|
@@ -1224,8 +1273,37 @@ export function startConsumer(opts = {}) {
|
|
|
1224
1273
|
return { allowed: true };
|
|
1225
1274
|
}
|
|
1226
1275
|
|
|
1227
|
-
|
|
1228
|
-
|
|
1276
|
+
/**
|
|
1277
|
+
* TWO CONVENTIONS, ONE FUNCTION, AND THE LOSS WAS SILENT.
|
|
1278
|
+
*
|
|
1279
|
+
* This took a single object. The handlers it is handed to call it as
|
|
1280
|
+
* `log("warn", msg)` — their own contract, documented at the head of
|
|
1281
|
+
* cadence-handlers.mjs ("Handlers / guards receive ({ event, agentRoot, log })")
|
|
1282
|
+
* and used at 14 sites. Spreading a STRING yields its characters, so the
|
|
1283
|
+
* written line became `{"0":"w","1":"a","2":"r","3":"n","ts":…}` and the
|
|
1284
|
+
* message — the second argument — was discarded entirely by a one-parameter
|
|
1285
|
+
* signature.
|
|
1286
|
+
*
|
|
1287
|
+
* Measured: 28,924 shredded lines in eleven days on one seat (reconstructed as
|
|
1288
|
+
* 23,738 error, 3,287 warn, 1,899 info) against 323 findable well-formed error
|
|
1289
|
+
* lines; and 17,057 on a second seat over thirteen days with a different mix
|
|
1290
|
+
* (12,093 info, 3,919 warn, 19 error), which is the same defect meeting a
|
|
1291
|
+
* different handler population. On the charitable test — is the lost line
|
|
1292
|
+
* merely a duplicate of a good one? — 3 of 23,739 on the first seat and 0 of
|
|
1293
|
+
* 295 on the second had a well-formed error or warn line in the same second.
|
|
1294
|
+
* Nothing was redundant.
|
|
1295
|
+
*
|
|
1296
|
+
* NO RECOVERY IS POSSIBLE for what has already been written. Only the
|
|
1297
|
+
* timestamp and the level's first letters survive; the message is gone. The
|
|
1298
|
+
* affected windows are unrecoverable and should be recorded as such rather
|
|
1299
|
+
* than reconstructed.
|
|
1300
|
+
*/
|
|
1301
|
+
function log(entry, msg) {
|
|
1302
|
+
// Accept both conventions rather than picking a winner: 14 live call sites
|
|
1303
|
+
// use (level, msg) and the consumer's own calls use ({level, stage, …}).
|
|
1304
|
+
// Rejecting either would convert a silent loss into a crash in a logger,
|
|
1305
|
+
// which is worse.
|
|
1306
|
+
const enriched = { ts: new Date().toISOString(), ...normaliseLogEntry(entry, msg) };
|
|
1229
1307
|
logBusEvent(agentRoot, enriched);
|
|
1230
1308
|
if (userLogger) {
|
|
1231
1309
|
try { userLogger(enriched); } catch { /* never crash on logging */ }
|