@cohortapp/agent-sdk 2.18.32 → 2.18.34

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.
@@ -181,16 +181,38 @@ function baseHeaders(token, orgId) {
181
181
  */
182
182
  async function httpRequest(fetchImpl, url, init, timeoutMs = DEFAULT_TIMEOUT_MS) {
183
183
  const f = pickFetch(fetchImpl);
184
- if (!f) return { ok: false, status: 0, body: null };
184
+ if (!f) return { ok: false, status: 0, body: null, failure: "no-fetch" };
185
185
  const ctrl = typeof AbortController === "function" ? new AbortController() : null;
186
- const timer = ctrl ? setTimeout(() => ctrl.abort(), timeoutMs) : null;
186
+ let timedOut = false;
187
+ const timer = ctrl ? setTimeout(() => { timedOut = true; ctrl.abort(); }, timeoutMs) : null;
187
188
  try {
188
189
  const res = await f(url, { ...init, signal: ctrl ? ctrl.signal : undefined });
189
190
  let body = null;
190
191
  try { body = await res.json(); } catch { body = null; }
191
192
  return { ok: !!res.ok, status: typeof res.status === "number" ? res.status : 0, body };
192
- } catch {
193
- return { ok: false, status: 0, body: null };
193
+ } catch (err) {
194
+ // A TIMEOUT AND A BROKEN SOCKET ARE NOT THE SAME FACT, AND THIS DISCARDED BOTH.
195
+ //
196
+ // `catch { }` returned a bare `status: 0`, which `asResFrame` renders as
197
+ // "http 0". A seat then sees "http 0" and cannot tell an abort from a DNS
198
+ // failure, a reset, or a missing origin — so the one piece of information
199
+ // that names the cause was thrown away at the only place that had it.
200
+ //
201
+ // Measured consequence: a seat's `messaging.history` returned at `limit: 3`
202
+ // and failed with "http 0" at normal page sizes, which reads as a transport
203
+ // or payload fault. It is neither — it is this 8s abort firing on a slower
204
+ // query, and the seat missed two hours of inbound while diagnosing the wrong
205
+ // layer. Its sends were landing the whole time, so it looked healthy.
206
+ return {
207
+ ok: false,
208
+ status: 0,
209
+ body: null,
210
+ failure: timedOut ? "timeout" : "transport",
211
+ timeoutMs: timedOut ? timeoutMs : undefined,
212
+ // `code` before `name`: ENOTFOUND/ECONNRESET identify the fault, while
213
+ // `name` is almost always the useless "Error".
214
+ cause: (err && (err.code || err.name)) || "unknown",
215
+ };
194
216
  } finally {
195
217
  if (timer) clearTimeout(timer);
196
218
  }
@@ -220,6 +242,19 @@ function asResFrame(r) {
220
242
  const b = r.body;
221
243
  if (b && typeof b === "object" && typeof b.ok === "boolean") return b; // already a frame
222
244
  if (r.ok) return okFrame(b);
245
+ if (r && r.status === 0 && r.failure === "timeout") {
246
+ // Named, with the budget, so the reader knows what to change.
247
+ // INTERNAL, not a new "TIMEOUT" code, deliberately. ERROR_CODES is the
248
+ // SHARED wire vocabulary (each entry carries an http mapping, so hq reads it
249
+ // too) and errFrame silently degrades an unknown code to INTERNAL — so
250
+ // writing "TIMEOUT" here would have looked like a new code and quietly been
251
+ // INTERNAL anyway, which is the same class of lie this whole change removes.
252
+ // The cause goes in the MESSAGE, which is what a person actually reads.
253
+ return errFrame("INTERNAL", `request timed out after ${r.timeoutMs}ms before any HTTP status — raise timeoutMs for this call, or ask for fewer rows`);
254
+ }
255
+ if (r && r.status === 0 && r.failure) {
256
+ return errFrame("INTERNAL", `transport failed before any HTTP status (${r.cause}) — not an HTTP error`);
257
+ }
223
258
  return errFrame(httpStatusToCode(r.status), `http ${r.status}`);
224
259
  }
225
260
 
@@ -333,11 +368,19 @@ export async function call(method, params, o = {}) {
333
368
  : "");
334
369
  if (key) headers["x-idempotency-key"] = String(key);
335
370
  }
371
+ // THE POST PATH HAD NO TUNABLE TIMEOUT WHILE THE GET PATH DID.
372
+ //
373
+ // This called httpRequest with no fourth argument, so every RPC — including a
374
+ // history read over a busy channel — sat under the same hard 8s ceiling with no
375
+ // way for a caller to ask for more, even though the read helper below already
376
+ // honours `o.timeoutMs`. That asymmetry is the defect; the default is unchanged
377
+ // so nothing moves for callers that do not ask.
378
+ const callTimeoutMs = Number.isFinite(o.timeoutMs) && o.timeoutMs > 0 ? o.timeoutMs : DEFAULT_TIMEOUT_MS;
336
379
  const r = await httpRequest(o.fetchImpl, v1Url(base, method), {
337
380
  method: "POST",
338
381
  headers,
339
382
  body: JSON.stringify(wire),
340
- });
383
+ }, callTimeoutMs);
341
384
  return asResFrame(r);
342
385
  }
343
386
 
@@ -100,9 +100,25 @@ export function refreshGlobalInstall(o = {}) {
100
100
  return { ok: true, action: plan.action, detail: `${plan.action === "skip" ? "skipped" : "no change"} (${plan.reason})${plan.argv && plan.action === "skip" ? `: ${plan.argv.join(" ")}` : ""}`, argv: plan.argv };
101
101
  }
102
102
  const r = exec(plan.argv[0], plan.argv.slice(1), { timeout: 180_000 });
103
- if (r.status === 0) return { ok: true, action: "install", detail: `${plan.argv.join(" ")} (${plan.reason})`, argv: plan.argv };
103
+ const was = globalVersion ? `was ${globalVersion}` : "was not installed";
104
+ if (r.status === 0) {
105
+ // POST-STATE FIRST, AND THE PRE-STATE LABELLED AS PAST.
106
+ //
107
+ // This used to interpolate `plan.reason` verbatim, which is the PRE-install
108
+ // reading — "global install is 2.18.30, agent dir is 2.18.31". On a
109
+ // SUCCESSFUL install that detail string is indistinguishable from the
110
+ // mismatch an operator is hunting, so a row whose `ok` is true reads as the
111
+ // failure. Someone auditing upgrade-result.json across a fleet for exactly
112
+ // that mismatch would flag every healthy seat.
113
+ //
114
+ // The `ok` flag was always the signal; the detail actively argued against
115
+ // it. Now the detail agrees with the flag.
116
+ return { ok: true, action: "install", detail: `${plan.argv.join(" ")} — global now ${String(o.version || "").trim()} (${was})`, argv: plan.argv };
117
+ }
104
118
  const err = String(r.stderr || "").trim().split("\n").filter(Boolean).pop() || `exit ${r.status}`;
105
- return { ok: false, action: "install", detail: `${plan.argv.join(" ")} failed: ${err} — run it by hand`, argv: plan.argv };
119
+ // On failure the actionable fact is that the global copy did NOT move, which
120
+ // the old string left the reader to infer from the absence of good news.
121
+ return { ok: false, action: "install", detail: `${plan.argv.join(" ")} failed: ${err} — global still ${globalVersion || "not installed"}; run it by hand`, argv: plan.argv };
106
122
  }
107
123
 
108
124
  export default { planGlobalRefresh, parseGlobalVersion, readGlobalVersion, refreshGlobalInstall, SDK_PACKAGE, SKIP_ENV };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohortapp/agent-sdk",
3
- "version": "2.18.32",
3
+ "version": "2.18.34",
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": {