@openagents-org/agent-launcher 0.2.227 → 0.2.228

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.227",
3
+ "version": "0.2.228",
4
4
  "description": "OpenAgents Launcher — install, configure, and run AI coding agents from your terminal",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -518,6 +518,18 @@ class CodexAdapter extends BaseAdapter {
518
518
  await this._sendRunFailure(msgChannel, result, { partial: true });
519
519
  }
520
520
  return;
521
+ } else if (threadId && attempt === 0 && CodexAdapter._threadTooLarge(result)) {
522
+ // The thread holds an item the API will no longer take, and codex
523
+ // sends the whole thread with every turn, so every later message in
524
+ // this channel failed the same way. Only a new thread runs again.
525
+ this._log(`Thread ${threadId} for ${msgChannel} exceeds an API limit; starting a new one`);
526
+ delete this._channelThreads[msgChannel];
527
+ this._saveSessions();
528
+ try {
529
+ await this.sendStatus(msgChannel, 'This Codex conversation grew past what the model API accepts, '
530
+ + 'so it continues in a new one. Earlier context in this thread is not carried over.');
531
+ } catch {}
532
+ continue;
521
533
  } else if (result.exitCode !== 0 && threadId && attempt === 0 && !result.turnStarted && !CodexAdapter._serviceRefused(result)) {
522
534
  // Stale thread — clear and retry fresh. Only when the turn never
523
535
  // started: a thread codex cannot resume fails at once with nothing
@@ -814,6 +826,19 @@ class CodexAdapter extends BaseAdapter {
814
826
  return Boolean(turnFailed) || (exitCode !== 0 && exitCode !== undefined);
815
827
  }
816
828
 
829
+ /**
830
+ * True when the API refused the thread itself as too big. Seen as
831
+ * `[ArrayParam] [input[77].content] [array_above_max_length] Invalid
832
+ * 'input[77].content': array too long` on every message of one channel: an
833
+ * item in the history has more content parts than the API allows, and codex
834
+ * resends it each turn. The run's error, else what its stderr gives as the
835
+ * reason (_stderrReason), never a line of its log further up.
836
+ */
837
+ static _threadTooLarge({ errorMessage, stderr } = {}) {
838
+ const reason = String(errorMessage || '').trim() || CodexAdapter._stderrReason(stderr);
839
+ return /array_above_max_length|context_length_exceeded/i.test(reason);
840
+ }
841
+
817
842
  /**
818
843
  * True when the model service turned the run away (rate limit, quota,
819
844
  * credentials, network) — nothing to do with the thread being resumed. Such
@@ -71,6 +71,19 @@ const VERSION_PROBE_TTL_MS = 60000;
71
71
  // provider keeps requests on `/chat/completions` and skips catalog validation.
72
72
  const CUSTOM_PROVIDER_ID = 'openagents-gateway';
73
73
 
74
+ // The database OpenCode is pointed at (OPENCODE_DB) once the shared one cannot
75
+ // be opened. OpenCode 1.x and 2.x both default to <data>/opencode/opencode.db;
76
+ // 2.x renames the `session` table to `session_v2` when it migrates it, and from
77
+ // then on the 1.x CLI this adapter runs dies at startup with "Database is not
78
+ // empty and has no session table" on every message (opencode-ai 1.17.11,
79
+ // packages/core/src/database/migration.ts). OPENCODE_DB takes an absolute path
80
+ // in that version (packages/core/src/database/database.ts). Once this file
81
+ // exists it is used from then on; auth.json stays shared, so sign-ins keep
82
+ // working, and the user's own database is never written.
83
+ // Resolved per call, so it follows HOME.
84
+ const ownDbPath = () => path.join(os.homedir(), '.openagents', 'opencode', 'opencode.db');
85
+ const SHARED_DB_MIGRATED_RE = /database is not empty and has no session table/i;
86
+
74
87
  // Short, de-identified, actionable user messages per failure category. These
75
88
  // must NEVER default to "run auth login": only credential_missing / auth_failed
76
89
  // mention authentication. Diagnostics (exit code, signal, redacted stdout/
@@ -97,6 +110,7 @@ const FAILURE_MESSAGES = {
97
110
  permission_denied: 'OpenCode could not get permission for a tool call. Check the agent’s explicit deny rules or file access settings; sending continue alone will not change them.',
98
111
  process_crashed: 'OpenCode exited unexpectedly. Open diagnostics or retry.',
99
112
  cwd_unavailable: "OpenCode's working directory is not accessible. Check the agent's configured path (or agent home) permissions.",
113
+ shared_db_migrated: "OpenCode could not open its session database: a newer OpenCode (2.x, or the OpenCode desktop app) on this device has converted it to a format the OpenCode CLI that OpenAgents runs cannot read, and running it on a database of its own did not help either. Reinstall OpenCode from the launcher, or set OPENCODE_DB in this agent's configuration to the full path of a new file, then retry.",
100
114
  config_invalid: 'OpenCode would not start because one of its config files is invalid — the file and what is wrong with it are below. OpenCode reads it on every run, so every message fails until it is fixed: correct or remove that entry, then retry.',
101
115
  unknown_error: 'OpenCode failed for an undetermined reason. Open diagnostics or retry.',
102
116
  };
@@ -257,6 +271,7 @@ class OpenCodeAdapter extends BaseAdapter {
257
271
  }
258
272
  _spawnEnv(channel) {
259
273
  const env = { ...(this.agentEnv || process.env) };
274
+ if (!env.OPENCODE_DB && fs.existsSync(ownDbPath())) env.OPENCODE_DB = ownDbPath();
260
275
  if (!this._wiresWorkspaceMcp()) return env;
261
276
  // Give OpenCode the workspace tools (publish, todos, browser, ...) through
262
277
  // our MCP server, as the Claude adapter does. Merged into any inline config
@@ -279,6 +294,33 @@ class OpenCodeAdapter extends BaseAdapter {
279
294
  return env;
280
295
  }
281
296
 
297
+ /**
298
+ * Whether a run that failed on the shared database can be retried on
299
+ * ownDbPath(), creating that file if need be. False when the failed run was
300
+ * not on the shared database to begin with: OPENCODE_DB set by the user, the
301
+ * file already there before the run (`ownBefore`), or a fork that builds its
302
+ * own environment. The sessions saved so far are ids in the old database
303
+ * and are dropped when the file is created here.
304
+ */
305
+ _moveToOwnDatabase(ownBefore) {
306
+ if (ownBefore || this._spawnEnv !== OpenCodeAdapter.prototype._spawnEnv) return false;
307
+ if ((this.agentEnv || process.env).OPENCODE_DB) return false;
308
+ const file = ownDbPath();
309
+ try {
310
+ fs.mkdirSync(path.dirname(file), { recursive: true });
311
+ fs.writeFileSync(file, '', { flag: 'wx' });
312
+ } catch (e) {
313
+ // Another channel's run got here first: the file is the one to use.
314
+ if (e && e.code === 'EEXIST') return true;
315
+ this._log(`Could not create ${file}: ${e && e.message}`, 'error');
316
+ return false;
317
+ }
318
+ this._log(`Shared OpenCode database was migrated by a newer OpenCode; using ${file}`);
319
+ this._channelSessions = {};
320
+ this._saveSessions();
321
+ return true;
322
+ }
323
+
282
324
  /**
283
325
  * Only plain OpenCode reads OPENCODE_CONFIG_CONTENT; the forks built on this
284
326
  * adapter (CodeArts, MiMo Code) replace _spawnEnv and keep the curl skill.
@@ -497,7 +539,16 @@ class OpenCodeAdapter extends BaseAdapter {
497
539
  await this.sendStatus(msgChannel, 'thinking...');
498
540
 
499
541
  try {
500
- const responseText = await this._runOpencode(content, msgChannel);
542
+ let responseText;
543
+ const ownBefore = fs.existsSync(ownDbPath());
544
+ try {
545
+ responseText = await this._runOpencode(content, msgChannel);
546
+ } catch (e) {
547
+ if (!(e && e.category === 'shared_db_migrated') || !this._moveToOwnDatabase(ownBefore)) throw e;
548
+ await this.sendStatus(msgChannel, "OpenCode's shared database was converted by a newer OpenCode on this "
549
+ + 'device, so this agent now uses one of its own. Earlier context in this thread is not carried over.');
550
+ responseText = await this._runOpencode(content, msgChannel);
551
+ }
501
552
 
502
553
  if (this._stoppingChannels.has(msgChannel)) {
503
554
  this._stoppingChannels.delete(msgChannel);
@@ -1466,6 +1517,8 @@ class OpenCodeAdapter extends BaseAdapter {
1466
1517
  let category;
1467
1518
  if (isPostinstallStubOutput(hay)) {
1468
1519
  category = 'install_incomplete';
1520
+ } else if (SHARED_DB_MIGRATED_RE.test(hay)) {
1521
+ category = 'shared_db_migrated';
1469
1522
  } else if (configError) {
1470
1523
  // Checked before the provider patterns: what is wrong with the file is
1471
1524
  // free text ("Unrecognized key: model", "got {…401…}") that would read