@bastani/atomic-storage-libsql 0.9.54 → 0.9.55-alpha.1

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
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.9.55] - 2026-10-30
6
+
7
+ ### Fixed
8
+
9
+ - A `file:` database opened through the adapter now waits up to 5 seconds for a lock another connection holds, and uses the write-ahead log like Atomic's own SQLite stores. Several processes can write one file, for example a workflow root, its coordinator and its workers; before, they lost statements to each other at once with `SQLITE_BUSY: database is locked`. The first open changes an existing file to WAL mode.
10
+
11
+ ## [0.9.55-alpha.1] - 2026-10-30
12
+
13
+ ### Fixed
14
+
15
+ - A `file:` database opened through the adapter now waits up to 5 seconds for a lock another connection holds, and uses the write-ahead log like Atomic's own SQLite stores. Several processes can write one file, for example a workflow root, its coordinator and its workers; before, they lost statements to each other at once with `SQLITE_BUSY: database is locked`. The first open changes an existing file to WAL mode.
16
+
5
17
  ## [0.9.49] - 2026-10-27
6
18
 
7
19
  Self-hosted sqld namespaces and faster remote workflow journals.
package/README.md CHANGED
@@ -35,6 +35,8 @@ chmod 600 ~/.atomic/turso-token
35
35
  | `authToken` | for remote databases | The database token. Pass it through `secrets` (`{ "file": ... }` or `{ "env": ... }`) so it stays out of settings. |
36
36
  | `namespace` | no | A self-hosted sqld namespace (`sqld --enable-namespaces`), sent as the `x-namespace` header. Needs a `libsql:`, `https:`, or `http:` URL. |
37
37
 
38
+ A `file:` database is opened in write-ahead-log mode with a 5000 ms busy timeout, the way Atomic's own SQLite stores are, so several processes can read and write one file at once: a statement waits up to 5 seconds for a lock another process holds instead of failing with `SQLITE_BUSY`, and the wait blocks the calling thread. The first open changes the file to WAL mode, which is kept in the file and adds `-wal` and `-shm` files beside it. Open a file only through this adapter at a time: another SQLite library with the same file open in WAL mode was seen to read stale data.
39
+
38
40
  The token is redacted from error messages and diagnostics. Add a `prefix` to the `storage` block to keep projects or teams apart in one database. See [Storage](../coding-agent/docs/storage.md) for selection precedence, per-process overrides, and the other storage options.
39
41
 
40
42
  ## Use from the SDK
package/libsql.js CHANGED
@@ -95,6 +95,13 @@ function driverResult(result) {
95
95
  return { columns: result.columns, rows: result.rows, changes: result.rowsAffected };
96
96
  }
97
97
 
98
+ /**
99
+ * How long a connection to a local `file:` database waits for a lock another connection holds before failing with
100
+ * `SQLITE_BUSY`, as Atomic's own SQLite stores wait. Without it the driver fails at once, so two processes writing
101
+ * one file, such as a workflow root, its coordinator and its workers, lose statements to each other.
102
+ */
103
+ const FILE_BUSY_TIMEOUT_MS = 5000;
104
+
98
105
  /**
99
106
  * @param {LibsqlDatabaseOptions} options
100
107
  * @returns {Promise<import("@bastani/atomic/storage").SqliteDatabase>}
@@ -108,11 +115,20 @@ export async function openLibsqlDatabase({ url, authToken, namespace, headers })
108
115
  } catch (cause) {
109
116
  throw new StorageAdapterLoadError("@libsql/client", /** @type {import("@bastani/atomic/storage").StorageFailureCause} */ (cause));
110
117
  }
118
+ const local = /^file:/i.test(url);
111
119
  /** @type {import("@libsql/client").Client | undefined} */
112
120
  let client;
113
- // Create the client inside a driver call, so the facade redacts credentials from its failures.
121
+ // Create the client inside a driver call, so the facade redacts credentials from its failures. The busy timeout is a
122
+ // client option, not a PRAGMA, because the client opens more connections than the one that ran the PRAGMA, and
123
+ // each needs it; a connection waits for a lock on the calling thread.
114
124
  const connection = () =>
115
- (client ??= createClient({ url, authToken, intMode: "bigint", ...(added.length > 0 ? { fetch: fetchWith(added) } : {}) }));
125
+ (client ??= createClient({
126
+ url,
127
+ authToken,
128
+ intMode: "bigint",
129
+ ...(local ? { timeout: FILE_BUSY_TIMEOUT_MS } : {}),
130
+ ...(added.length > 0 ? { fetch: fetchWith(added) } : {}),
131
+ }));
116
132
  const database = createSqliteDatabase({
117
133
  descriptor: { adapter: "libsql", location: url },
118
134
  redact: redactSecrets([authToken ?? "", ...urlCredentials(url), ...Object.values(headers ?? {})]),
@@ -138,6 +154,10 @@ export async function openLibsqlDatabase({ url, authToken, namespace, headers })
138
154
  });
139
155
  try {
140
156
  await database.exec("PRAGMA foreign_keys = ON");
157
+ // Readers and the one writer of a file share it through the write-ahead log, as in Atomic's own SQLite stores;
158
+ // in the default rollback journal a read refuses a writer's commit and the other way round. The mode is stored
159
+ // in the file, so this changes it once and costs nothing afterwards.
160
+ if (local) await database.exec("PRAGMA journal_mode = WAL");
141
161
  return database;
142
162
  } catch (error) {
143
163
  await database.close().catch(() => {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/atomic-storage-libsql",
3
- "version": "0.9.54",
3
+ "version": "0.9.55-alpha.1",
4
4
  "description": "libSQL / Turso storage adapter for Atomic sessions, workflow journals, and Intercom.",
5
5
  "contributors": [
6
6
  "Norin Lavaee",