antechamber 2.0.8 → 2.0.10

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/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ and this project uses [Semantic Versioning](https://semver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.10] - 2026-11-20
11
+
12
+ ### Fixed
13
+
14
+ - OpenChamber keeps subagent costs in the session total after a restart, even
15
+ when its live events arrive before the session list finishes loading.
16
+
17
+ ## [2.0.9] - 2026-11-19
18
+
19
+ ### Fixed
20
+
21
+ - Two antechamber adapters starting at once on a new registry, or right after upgrading from `sessions.json`, no
22
+ longer fail with `Failed to persist session registry ... database is locked` or
23
+ `ENOENT ... sessions.json`. Switching a new registry to WAL now backs off and retries within the 5 s busy timeout,
24
+ a `sessions.json` another process already imported and renamed is no longer an error, and a process that opens
25
+ the registry while another imports `sessions.json` no longer finds it empty.
26
+
10
27
  ## [2.0.8] - 2026-11-19
11
28
 
12
29
  - test(generation): watch for the release before logging the event a test waits on (#101)
@@ -533,6 +533,28 @@ function persistedEntry(entry) {
533
533
  function errorCode(error) {
534
534
  return error instanceof Error && "code" in error ? String(error.code) : undefined;
535
535
  }
536
+ const REGISTRY_BUSY_TIMEOUT_MS = 5_000;
537
+ /**
538
+ * Connections switching a new file to WAL at the same time can deadlock, and SQLite then answers SQLITE_BUSY at once
539
+ * instead of running its busy handler (https://sqlite.org/c3ref/busy_handler.html). Do what that handler would: back
540
+ * off and try again within the same `busy_timeout`. Once one connection has switched the file, the rest find it in WAL.
541
+ */
542
+ function enableWal(db) {
543
+ const deadline = Date.now() + REGISTRY_BUSY_TIMEOUT_MS;
544
+ const pause = new Int32Array(new SharedArrayBuffer(4));
545
+ for (;;) {
546
+ try {
547
+ db.exec("PRAGMA journal_mode = WAL;");
548
+ return;
549
+ }
550
+ catch (error) {
551
+ const busy = error instanceof Error && "errcode" in error && (Number(error.errcode) & 0xff) === 5;
552
+ if (!busy || Date.now() >= deadline)
553
+ throw error;
554
+ Atomics.wait(pause, 0, 0, 5 + Math.random() * 20);
555
+ }
556
+ }
557
+ }
536
558
  export class SessionStore {
537
559
  stateDir;
538
560
  file;
@@ -549,7 +571,9 @@ export class SessionStore {
549
571
  if (this.db !== undefined)
550
572
  return this.db;
551
573
  const legacy = join(this.stateDir, "sessions.json");
552
- if (!write && !existsSync(this.file) && !existsSync(legacy))
574
+ // Legacy first: another process renames sessions.json away only after it has created the database, so whichever
575
+ // moment the second check runs, one of the two is there. The other order can miss both.
576
+ if (!write && !existsSync(legacy) && !existsSync(this.file))
553
577
  return undefined;
554
578
  let db;
555
579
  try {
@@ -559,7 +583,8 @@ export class SessionStore {
559
583
  closeSync(openSync(this.file, "a", REGISTRY_FILE_MODE));
560
584
  chmodSync(this.file, REGISTRY_FILE_MODE);
561
585
  db = new DatabaseSync(this.file);
562
- db.exec("PRAGMA busy_timeout = 5000; PRAGMA journal_mode = WAL;");
586
+ db.exec(`PRAGMA busy_timeout = ${REGISTRY_BUSY_TIMEOUT_MS};`);
587
+ enableWal(db);
563
588
  db.exec(`CREATE TABLE IF NOT EXISTS sessions (
564
589
  id TEXT PRIMARY KEY, payload TEXT NOT NULL, pi_session_id TEXT NOT NULL,
565
590
  directory TEXT NOT NULL, parent_id TEXT, has_task INTEGER NOT NULL
@@ -601,6 +626,9 @@ export class SessionStore {
601
626
  return record(parsed) ? parsed : undefined;
602
627
  }
603
628
  catch (error) {
629
+ // Another process imported it and renamed it away after this one checked it was there.
630
+ if (errorCode(error) === "ENOENT")
631
+ return undefined;
604
632
  if (!(error instanceof SyntaxError))
605
633
  throw error;
606
634
  // Preserve malformed JSON untouched; a later repair can still be imported.
package/dist/v2.d.ts CHANGED
@@ -208,6 +208,7 @@ export declare class V2EventTranslator {
208
208
  private onTextPart;
209
209
  private onToolPart;
210
210
  private state;
211
+ private usageFrames;
211
212
  private frame;
212
213
  }
213
214
  export {};
package/dist/v2.js CHANGED
@@ -345,6 +345,7 @@ export class V2EventTranslator {
345
345
  ...(info.parentMessageID !== undefined ? { parentMessageID: info.parentMessageID } : {}),
346
346
  ...(info.metadata !== undefined ? { metadata: info.metadata } : {}),
347
347
  }),
348
+ ...this.usageFrames(directory, info),
348
349
  ];
349
350
  }
350
351
  case "session.updated": {
@@ -353,15 +354,7 @@ export class V2EventTranslator {
353
354
  ...(info.metadata !== undefined
354
355
  ? [this.frame(directory, "session.metadata.updated", { sessionID: info.id, metadata: info.metadata })]
355
356
  : []),
356
- ...(info.cost !== undefined
357
- ? [
358
- this.frame(directory, "session.usage.updated", {
359
- sessionID: info.id,
360
- cost: info.cost,
361
- tokens: info.tokens ?? zeroTokens(),
362
- }),
363
- ]
364
- : []),
357
+ ...this.usageFrames(directory, info),
365
358
  ];
366
359
  }
367
360
  case "session.diff":
@@ -726,6 +719,17 @@ export class V2EventTranslator {
726
719
  }
727
720
  return st;
728
721
  }
722
+ usageFrames(directory, info) {
723
+ if (info.cost === undefined)
724
+ return [];
725
+ return [
726
+ this.frame(directory, "session.usage.updated", {
727
+ sessionID: info.id,
728
+ cost: info.cost,
729
+ tokens: info.tokens ?? zeroTokens(),
730
+ }),
731
+ ];
732
+ }
729
733
  frame(directory, type, data, created = Date.now()) {
730
734
  const aggregateID = typeof data.sessionID === "string" ? data.sessionID : undefined;
731
735
  const seq = aggregateID === undefined ? undefined : (this.sequences.get(aggregateID) ?? 0) + 1;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antechamber-openchamber",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "OpenChamber extension for antechamber: installs and pins the antechamber server and OmO, draws the OmO Graph and the OmO Work section, and titles OmO tool cards",
5
5
  "private": true,
6
6
  "type": "module",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antechamber",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "OpenCode-compatible HTTP/SSE server that lets OpenChamber drive the pi coding agent (and OmO) over RPC",
5
5
  "type": "module",
6
6
  "license": "MIT",