@openagents-org/agent-launcher 0.2.214 → 0.2.215

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": "@openagents-org/agent-launcher",
3
- "version": "0.2.214",
3
+ "version": "0.2.215",
4
4
  "description": "OpenAgents Launcher — install, configure, and run AI coding agents from your terminal",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -198,6 +198,9 @@ class BaseAdapter {
198
198
  this._cursorFile = this._cursorFilePath();
199
199
  this._lastPersistedCursor = null;
200
200
  this._resumedFromCursor = false;
201
+ // No cursor and no head: polls read from the start of history until they
202
+ // come back empty (see _skipExistingEvents).
203
+ this._unanchored = false;
201
204
  this._running = false;
202
205
  this._sessionId = null; // issued by server on /v1/join; used to prove liveness
203
206
  this._processedIds = new Set();
@@ -550,7 +553,15 @@ class BaseAdapter {
550
553
  this._lastEventId = head;
551
554
  this._persistCursor(head);
552
555
  this._log(`Skipped existing events, cursor at ${head}`);
556
+ return;
553
557
  }
558
+ // The head lookup failed (network not up yet, a 5xx) or the workspace is
559
+ // empty. Polling with no cursor reads from the start of history, and a
560
+ // fresh start is not a replay, so every old message that named this agent
561
+ // was run again, one after another — a Codex hitting 429 posted an error
562
+ // every ~20s for an hour. Age-filter until the backlog is drained.
563
+ this._unanchored = true;
564
+ this._log('Could not find the head of the event stream — skipping stale messages until caught up', 'warn');
554
565
  }
555
566
 
556
567
  // ------------------------------------------------------------------
@@ -1286,6 +1297,10 @@ class BaseAdapter {
1286
1297
  continue;
1287
1298
  }
1288
1299
 
1300
+ // The cursor stops moving (or none comes back) only once the poll has
1301
+ // reached the end of the stream. An empty `messages` alone does not say
1302
+ // that: it is the page after events for other agents were dropped.
1303
+ const caughtUp = !rawCursor || rawCursor === this._lastEventId;
1289
1304
  if (rawCursor) {
1290
1305
  this._lastEventId = rawCursor;
1291
1306
  this._persistCursor(rawCursor);
@@ -1293,8 +1308,9 @@ class BaseAdapter {
1293
1308
  // Only the first poll after resuming from a persisted cursor is a
1294
1309
  // replay; later polls carry live traffic and are never age-filtered
1295
1310
  // (a skewed local clock must not make a live agent go deaf).
1296
- const isReplay = this._resumedFromCursor;
1311
+ const isReplay = this._resumedFromCursor || this._unanchored;
1297
1312
  this._resumedFromCursor = false;
1313
+ if (caughtUp) this._unanchored = false;
1298
1314
  const staleByChannel = {};
1299
1315
 
1300
1316
  // Deduplicate
@@ -465,7 +465,7 @@ class CodexAdapter extends BaseAdapter {
465
465
  await this._sendRunFailure(msgChannel, result, { partial: true });
466
466
  }
467
467
  return;
468
- } else if (result.exitCode !== 0 && threadId && attempt === 0) {
468
+ } else if (result.exitCode !== 0 && threadId && attempt === 0 && !CodexAdapter._serviceRefused(result)) {
469
469
  // Stale thread — clear and retry fresh
470
470
  this._log(`Stale thread detected for ${msgChannel}, clearing and retrying`);
471
471
  delete this._channelThreads[msgChannel];
@@ -743,6 +743,22 @@ class CodexAdapter extends BaseAdapter {
743
743
  return Boolean(turnFailed) || (exitCode !== 0 && exitCode !== undefined);
744
744
  }
745
745
 
746
+ /**
747
+ * True when the model service turned the run away (rate limit, quota,
748
+ * credentials, network) — nothing to do with the thread being resumed. Such
749
+ * a run was read as a stale thread: the thread was dropped, losing the
750
+ * conversation, and the same refused request was sent a second time.
751
+ */
752
+ static _serviceRefused({ errorMessage, stderr } = {}) {
753
+ const refused = /\b(401|402|403|429)\b|too many requests|rate.?limit|usage limit|quota|credits|unauthorized|forbidden|error sending request/i;
754
+ if (refused.test(String(errorMessage || ''))) return true;
755
+ // Only the end of stderr, where the reason the run died is: a stale
756
+ // thread whose earlier log mentioned a quota was kept, and every later
757
+ // message in that channel failed until restart.
758
+ const lastLines = String(stderr || '').split(/\r?\n/).filter((l) => l.trim()).slice(-5).join('\n');
759
+ return refused.test(lastLines);
760
+ }
761
+
746
762
  /**
747
763
  * Pick the most informative failure detail from a run result:
748
764
  * turn.failed / error event message → stderr tail → signal → exit code.
package/src/daemon.js CHANGED
@@ -39,6 +39,12 @@ const CLI_MODELS_RETRY_MS = 9 * 60 * 1000;
39
39
  // stopped. A few rather than one per type: each child loads the whole core.
40
40
  const RUNTIME_DETECT_GROUPS = 4;
41
41
  const RUNTIME_DETECT_TIMEOUT_MS = 90 * 1000;
42
+ // Probe results that mean the setup was never finished (no key, no sign-in,
43
+ // not installed). Time alone does not change them, and re-running them every
44
+ // hour re-reported the same failure all day; they are swept daily, and again
45
+ // as soon as detection sees the type installed or signed in.
46
+ const SETUP_INCOMPLETE = new Set(['not_ready', 'not_logged_in', 'missing_api_key', 'not_installed', 'install_failed']);
47
+ const SETUP_INCOMPLETE_MAX_AGE_MS = 24 * 3600 * 1000;
42
48
 
43
49
  /**
44
50
  * Mask an API key for display (same shape the workspace backend uses for
@@ -247,6 +253,29 @@ class Daemon {
247
253
  }
248
254
  }
249
255
 
256
+ /**
257
+ * A sign-in done in a terminal, or an install, changes no agent config, so
258
+ * nothing re-probes on its own and the daily sweep is far off. Re-probe the
259
+ * unfinished agents of a type as soon as detection sees it become installed
260
+ * or signed in.
261
+ */
262
+ _probeNewlyReady(previous) {
263
+ const became = new Set((this._runtimes || []).filter((rt) => {
264
+ const before = previous.get(rt.type);
265
+ return before && ((rt.installed && !before.installed) || (rt.ready && !before.ready));
266
+ }).map((rt) => rt.type));
267
+ if (!became.size) return;
268
+ const due = this.config.getAgents().filter((a) => became.has(a.type)
269
+ && this._probes[a.name] && SETUP_INCOMPLETE.has(this._probes[a.name].code));
270
+ if (!due.length) return;
271
+ (async () => {
272
+ for (const a of due) {
273
+ try { await this._probeAgent(a.name); } catch {}
274
+ }
275
+ this._nodeHeartbeat();
276
+ })();
277
+ }
278
+
250
279
  /** Report a runtime install that failed while creating `name`, as its probe result. */
251
280
  _recordInstallFailure(name, type, error) {
252
281
  let install = null;
@@ -275,7 +304,8 @@ class Daemon {
275
304
  for (const a of this.config.getAgents()) {
276
305
  const last = this._probes[a.name];
277
306
  const age = last && last.at ? Date.now() - Date.parse(last.at) : Infinity;
278
- if (age < maxAgeMs) continue;
307
+ const limit = last && SETUP_INCOMPLETE.has(last.code) ? Math.max(maxAgeMs, SETUP_INCOMPLETE_MAX_AGE_MS) : maxAgeMs;
308
+ if (age < limit) continue;
279
309
  try { await this._probeAgent(a.name); } catch {}
280
310
  }
281
311
  this._nodeHeartbeat();
@@ -994,6 +1024,7 @@ class Daemon {
994
1024
  const order = types.length ? types : [...found.keys()];
995
1025
  this._runtimes = order.map((type) => found.get(type) || previous.get(type)).filter(Boolean);
996
1026
  this._cliModelsAfterDetection(previous);
1027
+ this._probeNewlyReady(previous);
997
1028
  }
998
1029
 
999
1030
  /**
package/src/probe.js CHANGED
@@ -92,7 +92,8 @@ function scrub(text) {
92
92
  if (!text) return '';
93
93
  const masked = String(text)
94
94
  .replace(/sk-[A-Za-z0-9_-]{8,}/g, 'sk-****')
95
- .replace(/(api[-_ ]?key["':\s=]+)[A-Za-z0-9_-]{8,}/gi, '$1****')
95
+ // Not a plain word: "Incorrect API key provided: sk-…" lost "provided".
96
+ .replace(/(api[-_ ]?key["':\s=]+)([A-Za-z0-9_-]{8,})/gi, (m, p, v) => (/^[a-z]+$/.test(v) ? m : `${p}****`))
96
97
  .replace(/Bearer\s+[A-Za-z0-9._-]{8,}/gi, 'Bearer ****');
97
98
  // Then everything the adapters strip from quoted CLI text: a Codex probe
98
99
  // that failed after printing a token-shaped blob showed that blob as its
@@ -137,7 +138,11 @@ function classifyOutputText(text) {
137
138
  // — the one misreading that sends a user to re-authenticate a working key.
138
139
  if (/credit balance|insufficient[_ ]?(quota|credits|funds)|payment required|\b402\b|billing|quota[_ ]?exceeded|exceeded your current quota|额度|余额|欠费|余额不足/.test(text)) return CODE.OUT_OF_CREDIT;
139
140
  if (/rate[- ]?limit|too many requests|\b429\b|overloaded|\b529\b/.test(text)) return CODE.RATE_LIMITED;
140
- if (/enotfound|econnrefused|econnreset|etimedout|eai_again|fetch failed|socket hang up|network error|self[- ]signed certificate|unable to get local issuer/.test(text)) return CODE.NETWORK;
141
+ // "error sending request for url (…)" is how Codex (Rust) says the host
142
+ // was unreachable; a Codex that could not reach chatgpt.com ran out the
143
+ // probe clock and was reported as waiting for interactive input. "Request
144
+ // to <host> timed out" is the direct API test's own deadline (utils.js).
145
+ if (/enotfound|econnrefused|econnreset|etimedout|eai_again|fetch failed|socket hang up|network error|error sending request|request to \S+ timed out|self[- ]signed certificate|unable to get local issuer/.test(text)) return CODE.NETWORK;
141
146
  if (/api key.{0,24}(not set|not found|missing)|no api key|missing api key|environment variable.{0,40}(is )?(not set|required)/.test(text)) return CODE.MISSING_API_KEY;
142
147
  if (/invalid.{0,12}(api.?key|x-api-key|token)|incorrect api key|authentication[_ ]?error|invalid credentials|\b401\b|unauthorized|forbidden|\b403\b/.test(text)) return CODE.INVALID_API_KEY;
143
148
  // A sign-in that exists but has run out — Claude Code: "Failed to
@@ -350,6 +355,25 @@ function shellQuoted(binary, shell) {
350
355
  return shell && !/^".*"$/.test(binary) ? `"${binary}"` : binary;
351
356
  }
352
357
 
358
+ /**
359
+ * Whether a line is an encoded blob rather than words. A whole-line run of
360
+ * base64/base64url characters is one; so is a line where mixed-case
361
+ * alphanumeric runs (and already-redacted spans) make up half of it — a
362
+ * Codex timeout reported a fragment of a dumped object, `…849-1.0.1.
363
+ * [REDACTED]\",md: '3P2K.…`, as its reason. Hex ids, paths and URL paths
364
+ * have no mixed-case runs and are not counted.
365
+ */
366
+ function mostlyEncoded(line) {
367
+ if (/^[A-Za-z0-9+/=._-]{24,}$/.test(line)) return true;
368
+ const body = line.replace(/\s+/g, '');
369
+ const unredacted = line.replace(/\[REDACTED\]/g, '');
370
+ let encoded = line.length - unredacted.length;
371
+ for (const run of unredacted.match(/[A-Za-z0-9+/=_.-]{16,}/g) || []) {
372
+ if (/\d/.test(run) && /[a-z]/.test(run) && /[A-Z]/.test(run)) encoded += run.length;
373
+ }
374
+ return encoded * 2 >= body.length;
375
+ }
376
+
353
377
  /**
354
378
  * The one line worth reporting from a failed run.
355
379
  *
@@ -359,11 +383,15 @@ function shellQuoted(binary, shell) {
359
383
  * with the timeout named first.
360
384
  */
361
385
  function failureMessage(res, code, timeoutMs) {
362
- // A line that is one long run of base64/base64url characters is an encoded
363
- // blob (a token, encrypted reasoning), never a sentence that says why the
364
- // CLI failed. JSON and URLs have characters outside that set and stay.
365
- const lines = (s) => String(s || '').split(/\r?\n/).map((l) => l.trim())
366
- .filter((l) => l && !BENIGN_OUTPUT.test(l) && !/^[A-Za-z0-9+/=._-]{24,}$/.test(l));
386
+ // A line that is mostly encoded blob (a token, encrypted reasoning) never
387
+ // says why the CLI failed, and neither does a stack frame: a crashed Node
388
+ // shim showed only its last frames, `…(file:///C:/…/codex.js:108:9) at
389
+ // file:///…`, with the `Error:` line above them cut off. JSON and URLs stay.
390
+ // Each line is scrubbed before that test: a provider that echoes the whole
391
+ // key (`401 Incorrect API key provided: sk-proj-…`) had the one line that
392
+ // explains the failure dropped as encoded.
393
+ const lines = (s) => String(s || '').split(/\r?\n/).map((l) => scrub(l.trim()))
394
+ .filter((l) => l && !BENIGN_OUTPUT.test(l) && !mostlyEncoded(l) && !/^at\s+\S/.test(l));
367
395
  const all = [...lines(res.stderr), ...lines(res.stdout)];
368
396
  const telling = all.find((l) => classifyOutputText(l.toLowerCase()) === code);
369
397
  const detail = tail(telling || lines(res.stderr).join('\n') || lines(res.stdout).join('\n'), OUTPUT_CAP);
package/src/utils.js CHANGED
@@ -37,12 +37,28 @@ function request(url, { method = 'POST', headers = {}, body = null, timeout = 15
37
37
  res.on('end', () => resolve({ status: res.statusCode, data }));
38
38
  });
39
39
  req.on('error', (e) => resolve({ error: e.message }));
40
- req.on('timeout', () => { req.destroy(); resolve({ error: 'Request timed out' }); });
40
+ // Name the host and the deadline: a bare "Request timed out" on the
41
+ // device card did not say whether the provider or the network was slow.
42
+ req.on('timeout', () => { req.destroy(); resolve({ error: `Request to ${parsedUrl.host} timed out after ${Math.round(timeout / 1000)}s` }); });
41
43
  if (body) req.write(body);
42
44
  req.end();
43
45
  });
44
46
  }
45
47
 
48
+ /**
49
+ * The test completion. 15s read as broken a slow relay that answers in 20, and
50
+ * a dropped connection failed the whole test: give it 30s and one more try on
51
+ * a timeout or reset. A host that does not resolve is not retried.
52
+ */
53
+ const COMPLETION_TIMEOUT_MS = 30000;
54
+ const RETRYABLE = /timed out|econnreset|socket hang up|eai_again/i;
55
+
56
+ async function requestCompletion(url, opts) {
57
+ const res = await request(url, { ...opts, timeout: COMPLETION_TIMEOUT_MS });
58
+ if (!res.error || !RETRYABLE.test(res.error)) return res;
59
+ return request(url, { ...opts, timeout: COMPLETION_TIMEOUT_MS });
60
+ }
61
+
46
62
  /**
47
63
  * The chat models an OpenAI-compatible endpoint says it serves, or [] when it
48
64
  * publishes no readable list. A list we cannot read is not a test failure —
@@ -154,7 +170,7 @@ async function testLLMConnection(env, opts = {}) {
154
170
  max_tokens: 32,
155
171
  messages: [{ role: 'user', content: 'Say hi in 5 words.' }],
156
172
  });
157
- const res = await request(url, { headers, body });
173
+ const res = await requestCompletion(url, { headers, body });
158
174
  return completionResult(res, { isAnthropic: true, model });
159
175
  }
160
176
 
@@ -183,7 +199,7 @@ async function testLLMConnection(env, opts = {}) {
183
199
  };
184
200
  if (hasKimiConfig) requestBody.max_tokens = 32;
185
201
  else requestBody.max_completion_tokens = 32;
186
- const res = await request(`${baseUrl}/chat/completions`, { headers, body: JSON.stringify(requestBody) });
202
+ const res = await requestCompletion(`${baseUrl}/chat/completions`, { headers, body: JSON.stringify(requestBody) });
187
203
  last = completionResult(res, { isAnthropic: false, model: candidate });
188
204
  if (last.success) return last;
189
205
  // Only a model WE picked moves on to the next one. A configured model is