@effect-agent/storage-sqlite 0.1.0-beta.114 → 0.1.0-beta.115

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.
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { a as initializeSqliteJournal } from "./sqlite-journal-BCyBc87Y.mjs";
2
+ import { a as initializeSqliteJournal } from "./sqlite-journal-DE4MN8uP.mjs";
3
3
  import { Effect, Layer, Schema } from "effect";
4
4
  import * as SqlClientService from "effect/unstable/sql/SqlClient";
5
5
  import { SourcePartition, SubscriptionError, SubscriptionStore } from "effect-agent/subscription";
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { SqliteStorageConfig, SqliteStorageConfigValue } from "./SqliteStorageConfig.mjs";
3
3
  import { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteStorageCorruptionError, SqliteStorageError } from "./SqliteStorageError.mjs";
4
4
  import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
5
- import { a as initializeSqliteJournal, n as RawCheckpoint, r as RawReadRequest, t as RawAppendRequest } from "./sqlite-journal-BCyBc87Y.mjs";
5
+ import { a as initializeSqliteJournal, n as RawCheckpoint, r as RawReadRequest, t as RawAppendRequest } from "./sqlite-journal-DE4MN8uP.mjs";
6
6
  import { Clock, Context, Crypto, Duration, Effect, Layer, Option, Ref, Schema, Stream } from "effect";
7
7
  import { NodeCrypto } from "@effect/platform-node";
8
8
  import { SqliteClient } from "@effect/sql-sqlite-node";
package/dist/index.d.mts CHANGED
@@ -5,7 +5,7 @@ import { t as SqliteStorageFailpoint_d_exports } from "./SqliteStorageFailpoint.
5
5
  import { t as SqliteMessageDeliveryStore_d_exports } from "./SqliteMessageDeliveryStore.mjs";
6
6
  import { t as SqliteThreadStore_d_exports } from "./SqliteThreadStore.mjs";
7
7
  import { t as SqliteScheduleStore_d_exports } from "./SqliteScheduleStore.mjs";
8
- import { t as SqliteStorageVersion_d_exports } from "./SqliteStorageVersion-BO6U_VHq.mjs";
8
+ import { t as SqliteStorageVersion_d_exports } from "./SqliteStorageVersion-BBmy73KE.mjs";
9
9
  import { t as SqliteSubmissionLedger_d_exports } from "./SqliteSubmissionLedger.mjs";
10
10
  import { t as SqliteSubscriptionStore_d_exports } from "./SqliteSubscriptionStore.mjs";
11
11
  export { SqliteActivityStore_d_exports as SqliteActivityStore, SqliteMessageDeliveryStore_d_exports as SqliteMessageDeliveryStore, SqliteScheduleStore_d_exports as SqliteScheduleStore, SqliteStorageConfig_d_exports as SqliteStorageConfig, SqliteStorageError_d_exports as SqliteStorageError, SqliteStorageFailpoint_d_exports as SqliteStorageFailpoint, SqliteStorageVersion_d_exports as SqliteStorageVersion, SqliteSubmissionLedger_d_exports as SqliteSubmissionLedger, SqliteSubscriptionStore_d_exports as SqliteSubscriptionStore, SqliteThreadStore_d_exports as SqliteThreadStore };
@@ -40,7 +40,21 @@ const createRecoveryCheckpointTable = Effect.gen(function* () {
40
40
  });
41
41
  //#endregion
42
42
  //#region src/internal/migrations.ts
43
- const CurrentSqliteStorageVersion = 12;
43
+ const CurrentSqliteStorageVersion = 14;
44
+ /** One permanent destination inbox fence, including workers stopped before admission. */
45
+ const createWorkerStops = Effect.gen(function* () {
46
+ const sql = yield* SqlClient.SqlClient;
47
+ yield* sql`CREATE TABLE effect_agent_worker_stops (thread_id TEXT PRIMARY KEY NOT NULL, terminal TEXT)`;
48
+ yield* sql`CREATE INDEX effect_agent_worker_starts ON effect_agent_message_deliveries(owner_thread_id,
49
+ json_extract(record_json, '$.envelope.workerAdmission.origin.worker.delegationId'),
50
+ json_extract(record_json, '$.envelope.workerAdmission.origin.worker.targetAgentId'), message_id)
51
+ WHERE message_id = json_extract(record_json, '$.envelope.workerAdmission.origin.firstMessageId')`;
52
+ yield* sql`CREATE INDEX effect_agent_worker_pending ON effect_agent_message_deliveries(owner_thread_id,
53
+ json_extract(record_json, '$.envelope.workerAdmission.origin.worker.threadId'), message_id)
54
+ WHERE state IN ('pending', 'parked') AND json_extract(record_json, '$.receipt') IS NULL`;
55
+ yield* sql`CREATE INDEX effect_agent_worker_execution ON effect_agent_canonical_records(thread_id,
56
+ json_extract(record_json, '$.payload._tag'), sequence) WHERE json_extract(record_json, '$.payload.runId') IS NOT NULL`;
57
+ });
44
58
  /** Index only outstanding obligations, ordered by the recovery scan's stable cursor. */
45
59
  const createNonterminalIndex = Effect.gen(function* () {
46
60
  yield* (yield* SqlClient.SqlClient)`CREATE INDEX effect_agent_submissions_nonterminal ON effect_agent_submissions (thread_id, queue_sequence) WHERE state <> 'settled'`.withoutTransform;
@@ -342,9 +356,10 @@ const sqliteMigrations = SqliteMigrator.fromRecord({ "1_current_thread_storage":
342
356
  yield* createMessageDeliveryTables;
343
357
  yield* createMessageDeliveryPendingIndex;
344
358
  yield* createRecoveryCheckpointTable;
345
- yield* sql`PRAGMA user_version = 12`.withoutTransform;
359
+ yield* createWorkerStops;
360
+ yield* sql`PRAGMA user_version = 14`.withoutTransform;
346
361
  }) });
347
362
  //#endregion
348
- export { createMessageDeliveryTables as a, createRecoveryCheckpointTable as i, createNonterminalIndex as n, sqliteMigrations as r, CurrentSqliteStorageVersion as t };
363
+ export { createRecoveryCheckpointTable as a, sqliteMigrations as i, createNonterminalIndex as n, createMessageDeliveryTables as o, createWorkerStops as r, CurrentSqliteStorageVersion as t };
349
364
 
350
- //# sourceMappingURL=migrations-BZ89iaTY.mjs.map
365
+ //# sourceMappingURL=migrations-BmgwzT68.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations-BmgwzT68.mjs","names":[],"sources":["../src/internal/message-delivery-schema.ts","../src/internal/recovery-checkpoint-schema.ts","../src/internal/migrations.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\n/** Additive storage owned by this adapter; creation participates in its version transaction. */\nexport const createMessageDeliveryTables = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_message_deliveries (\n owner_thread_id TEXT NOT NULL,\n message_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n state TEXT NOT NULL,\n deadline_at_millis INTEGER,\n record_json TEXT NOT NULL,\n PRIMARY KEY (owner_thread_id, message_id)\n )\n `.withoutTransform;\n yield* sql`\n CREATE INDEX effect_agent_message_deliveries_due\n ON effect_agent_message_deliveries (deadline_at_millis, owner_thread_id, message_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n});\n","import { Effect } from \"effect\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\n/** One disposable recovery snapshot per Thread, independent of generic projections. */\nexport const createRecoveryCheckpointTable = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_recovery_checkpoints (\n thread_id TEXT PRIMARY KEY NOT NULL,\n through_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n checkpoint_json TEXT NOT NULL,\n FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT\n )\n `.withoutTransform;\n});\n","import { SqliteMigrator } from \"@effect/sql-sqlite-node\";\nimport { Effect } from \"effect\";\nimport { createMessageDeliveryPendingIndex } from \"effect-agent/sql-message-delivery-store\";\nimport { createNativeReadIndexes } from \"effect-agent/sql-thread-native-reads\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\nimport { createMessageDeliveryTables } from \"./message-delivery-schema.ts\";\nimport { createRecoveryCheckpointTable } from \"./recovery-checkpoint-schema.ts\";\n\nexport const CurrentSqliteStorageVersion = 14;\n\n/** One permanent destination inbox fence, including workers stopped before admission. */\nexport const createWorkerStops = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`CREATE TABLE effect_agent_worker_stops (thread_id TEXT PRIMARY KEY NOT NULL, terminal TEXT)`;\n yield* sql`CREATE INDEX effect_agent_worker_starts ON effect_agent_message_deliveries(owner_thread_id,\n json_extract(record_json, '$.envelope.workerAdmission.origin.worker.delegationId'),\n json_extract(record_json, '$.envelope.workerAdmission.origin.worker.targetAgentId'), message_id)\n WHERE message_id = json_extract(record_json, '$.envelope.workerAdmission.origin.firstMessageId')`;\n yield* sql`CREATE INDEX effect_agent_worker_pending ON effect_agent_message_deliveries(owner_thread_id,\n json_extract(record_json, '$.envelope.workerAdmission.origin.worker.threadId'), message_id)\n WHERE state IN ('pending', 'parked') AND json_extract(record_json, '$.receipt') IS NULL`;\n yield* sql`CREATE INDEX effect_agent_worker_execution ON effect_agent_canonical_records(thread_id,\n json_extract(record_json, '$.payload._tag'), sequence) WHERE json_extract(record_json, '$.payload.runId') IS NOT NULL`;\n});\n\n/** Index only outstanding obligations, ordered by the recovery scan's stable cursor. */\nexport const createNonterminalIndex = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`CREATE INDEX effect_agent_submissions_nonterminal ON effect_agent_submissions (thread_id, queue_sequence) WHERE state <> 'settled'`\n .withoutTransform;\n});\n\n/** Initialize empty storage with the complete current schema. */\nexport const sqliteMigrations = SqliteMigrator.fromRecord({\n \"1_current_thread_storage\": Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_threads (\n thread_id TEXT PRIMARY KEY NOT NULL,\n created_at TEXT NOT NULL,\n tail_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_canonical_batches (\n thread_id TEXT NOT NULL,\n batch_id TEXT NOT NULL,\n first_sequence INTEGER NOT NULL,\n last_sequence INTEGER NOT NULL,\n batch_digest TEXT NOT NULL,\n tail_digest TEXT NOT NULL,\n batch_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, batch_id),\n FOREIGN KEY (thread_id)\n REFERENCES effect_agent_threads(thread_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_canonical_records (\n thread_id TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n record_id TEXT NOT NULL,\n batch_id TEXT NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, sequence),\n UNIQUE (thread_id, record_id),\n FOREIGN KEY (thread_id, batch_id)\n REFERENCES effect_agent_canonical_batches(thread_id, batch_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_canonical_records_batch\n ON effect_agent_canonical_records (thread_id, batch_id, sequence)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_checkpoints (\n thread_id TEXT NOT NULL,\n through_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n checkpoint_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, through_sequence),\n FOREIGN KEY (thread_id)\n REFERENCES effect_agent_threads(thread_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // Admission rows exist before Thread materialization (durability §4), so\n // thread_id intentionally carries no foreign key into effect_agent_threads.\n yield* sql`\n CREATE TABLE effect_agent_submissions (\n submission_id TEXT PRIMARY KEY NOT NULL,\n thread_id TEXT NOT NULL,\n queue_sequence INTEGER NOT NULL,\n principal TEXT NOT NULL,\n idempotency_key TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n agent_digests_json TEXT NOT NULL,\n deployment_id TEXT NOT NULL,\n input_json TEXT NOT NULL,\n input_digest TEXT NOT NULL,\n receipt_id TEXT NOT NULL,\n state TEXT NOT NULL,\n settled_outcome TEXT,\n created_at TEXT NOT NULL,\n ready_at TEXT,\n input_applied_record_id TEXT,\n input_applied_sequence INTEGER,\n joined_host_submission_id TEXT,\n suspended_reason_json TEXT,\n suspended_at TEXT,\n unknown_reason TEXT,\n unknown_tool_call_ids_json TEXT,\n parent_submission_id TEXT,\n parent_tool_call_id TEXT,\n admission_group TEXT,\n admission_fence_json TEXT,\n worker_admission_json TEXT,\n message_admission_json TEXT,\n UNIQUE (thread_id, principal, idempotency_key),\n UNIQUE (thread_id, queue_sequence)\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_submissions_group\n ON effect_agent_submissions (thread_id, admission_group, state)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_submission_ownership (\n submission_id TEXT PRIMARY KEY NOT NULL,\n attempt_id TEXT NOT NULL,\n ownership_token TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL,\n owner_producer_id TEXT NOT NULL,\n lease_expires_at TEXT NOT NULL,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_attempts (\n attempt_id TEXT PRIMARY KEY NOT NULL,\n submission_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n owner_producer_id TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL,\n claimed_at TEXT NOT NULL,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_settlement_reservations (\n submission_id TEXT PRIMARY KEY NOT NULL,\n settlement_id TEXT NOT NULL,\n outcome TEXT NOT NULL,\n record_id TEXT NOT NULL,\n record_json TEXT NOT NULL,\n record_digest TEXT NOT NULL,\n reserved_at TEXT NOT NULL,\n finalized_at TEXT,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_abort_intents (\n submission_id TEXT PRIMARY KEY NOT NULL,\n author TEXT NOT NULL,\n reason TEXT NOT NULL,\n requested_at TEXT NOT NULL,\n canonical_record_id TEXT,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_submissions_joined_host\n ON effect_agent_submissions (joined_host_submission_id)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_approval_decisions (\n submission_id TEXT NOT NULL,\n tool_call_id TEXT NOT NULL,\n decision TEXT NOT NULL,\n resolver TEXT NOT NULL,\n reason TEXT NOT NULL,\n decided_at TEXT NOT NULL,\n PRIMARY KEY (submission_id, tool_call_id),\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_unknown_resolutions (\n submission_id TEXT NOT NULL,\n tool_call_id TEXT NOT NULL,\n author TEXT NOT NULL,\n reason TEXT NOT NULL,\n resolution_json TEXT NOT NULL,\n resolved_at TEXT NOT NULL,\n PRIMARY KEY (submission_id, tool_call_id),\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // Durable attached children (spec §12, SUB-004): a child Submission records its immutable\n // parent linkage at admission; the parent-side index serves the recovery attachment view.\n yield* sql`\n CREATE INDEX effect_agent_submissions_parent\n ON effect_agent_submissions (parent_submission_id)\n `.withoutTransform;\n\n // Parent-owned child budget reservations (spec §12 steps 2 and 6, SUB-010): generic\n // opaque-payload state-machine rows (D8) — allocation and accounting are Schema-encoded\n // JSON documents the adapter never interprets; status moves\n // reserved → releasePending → released, applied exactly once.\n yield* sql`\n CREATE TABLE effect_agent_child_reservations (\n reservation_id TEXT PRIMARY KEY NOT NULL,\n parent_submission_id TEXT NOT NULL,\n parent_tool_call_id TEXT NOT NULL,\n child_submission_id TEXT,\n status TEXT NOT NULL,\n allocation_json TEXT NOT NULL,\n allocation_digest TEXT NOT NULL,\n accounting_json TEXT,\n reserved_at TEXT NOT NULL,\n release_began_at TEXT,\n released_at TEXT,\n UNIQUE (parent_submission_id, parent_tool_call_id),\n FOREIGN KEY (parent_submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // record_json is authoritative. The remaining columns support owner keyset paging and\n // deadline queries without decoding unrelated future schedules.\n yield* sql`\n CREATE TABLE effect_agent_schedules (\n tenant_id TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n schedule_id TEXT NOT NULL,\n deadline_at_millis INTEGER,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, owner_id, schedule_id)\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_schedules_deadline\n ON effect_agent_schedules (deadline_at_millis, tenant_id, owner_id, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_schedules_owner_deadline\n ON effect_agent_schedules (tenant_id, owner_id, deadline_at_millis, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_subscription_sequences (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n event_scan_cursor TEXT NOT NULL,\n delivery_scan_cursor TEXT NOT NULL,\n recovery_scan_cursor INTEGER NOT NULL,\n PRIMARY KEY (tenant_id, source_address)\n )\n `.withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscriptions (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n subscription_id TEXT NOT NULL,\n ordinal INTEGER NOT NULL,\n source_name TEXT NOT NULL,\n source_version TEXT NOT NULL,\n matching_key TEXT NOT NULL,\n state TEXT NOT NULL,\n expires_at_millis INTEGER,\n recovery_at_millis INTEGER,\n recovery_present INTEGER NOT NULL DEFAULT 0,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id),\n UNIQUE (tenant_id, source_address, ordinal)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_owner ON effect_agent_subscriptions (tenant_id, source_address, owner_id, ordinal)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_candidates ON effect_agent_subscriptions (tenant_id, source_address, source_name, source_version, matching_key, ordinal)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_recovery ON effect_agent_subscriptions (tenant_id, source_address, recovery_at_millis, ordinal) WHERE recovery_at_millis IS NOT NULL`\n .withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscription_events (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n event_id TEXT NOT NULL,\n source_name TEXT NOT NULL,\n source_version TEXT NOT NULL,\n matching_key TEXT NOT NULL,\n payload_digest TEXT NOT NULL,\n cutoff INTEGER NOT NULL,\n cursor INTEGER NOT NULL,\n routing_complete INTEGER NOT NULL,\n tombstone INTEGER NOT NULL DEFAULT 0,\n next_attempt_at_millis INTEGER NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, event_id)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_events_pending ON effect_agent_subscription_events (tenant_id, source_address, routing_complete, next_attempt_at_millis, event_id)`\n .withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscription_deliveries (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n subscription_id TEXT NOT NULL,\n event_id TEXT NOT NULL,\n delivery_key TEXT NOT NULL,\n state TEXT NOT NULL,\n next_attempt_at_millis INTEGER NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id, event_id),\n UNIQUE (tenant_id, source_address, delivery_key)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_deliveries_pending ON effect_agent_subscription_deliveries (tenant_id, source_address, state, next_attempt_at_millis, delivery_key)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_deliveries_registration ON effect_agent_subscription_deliveries (tenant_id, source_address, owner_id, subscription_id, delivery_key)`\n .withoutTransform;\n yield* createNativeReadIndexes;\n yield* createNonterminalIndex;\n yield* createMessageDeliveryTables;\n yield* createMessageDeliveryPendingIndex;\n yield* createRecoveryCheckpointTable;\n yield* createWorkerStops;\n yield* sql`PRAGMA user_version = 14`.withoutTransform;\n }),\n});\n"],"mappings":";;;;;;;AAIA,MAAa,8BAA8B,OAAO,IAAI,aAAa;CACjE,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,GAAG;;;;;;;;;;IAUR;CACF,OAAO,GAAG;;;;IAIR;AACJ,CAAC;;;;ACnBD,MAAa,gCAAgC,OAAO,IAAI,aAAa;CAGnE,OAAO,CAAA,OAFY,UAAU,UAAA,AAEnB;;;;;;;;IAQR;AACJ,CAAC;;;ACPD,MAAa,8BAA8B;;AAG3C,MAAa,oBAAoB,OAAO,IAAI,aAAa;CACvD,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,GAAG;CACV,OAAO,GAAG;;;;CAIV,OAAO,GAAG;;;CAGV,OAAO,GAAG;;AAEZ,CAAC;;AAGD,MAAa,yBAAyB,OAAO,IAAI,aAAa;CAG5D,OAAO,CAAA,OAFY,UAAU,UAAA,AAEnB,qIACP;AACL,CAAC;;AAGD,MAAa,mBAAmB,eAAe,WAAW,EACxD,4BAA4B,OAAO,IAAI,aAAa;CAClD,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,GAAG;;;;;;;;MAQR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;MAWR;CAIF,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiCR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CAEF,OAAO,GAAG;;;;;;;;;;;MAWR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAIF,OAAO,GAAG;;;MAGR;CAMF,OAAO,GAAG;;;;;;;;;;;;;;;;;;MAkBR;CAIF,OAAO,GAAG;;;;;;;;;MASR;CAEF,OAAO,GAAG;;;;MAIR;CAEF,OAAO,GAAG;;;;MAIR;CAEF,OAAO,GAAG;;;;;;;;;;MAUR;CACF,OAAO,GAAG;;;;;;;;;;;;;;;;;;MAkBR;CACF,OAAO,GAAG,6HACP;CACH,OAAO,GAAG,mKACP;CACH,OAAO,GAAG,+KACP;CACH,OAAO,GAAG;;;;;;;;;;;;;;;;;MAiBR;CACF,OAAO,GAAG,4KACP;CACH,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CACF,OAAO,GAAG,6KACP;CACH,OAAO,GAAG,8KACP;CACH,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO,GAAG,2BAA2B;AACvC,CAAC,EACH,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { SqliteStorageConfig } from "./SqliteStorageConfig.mjs";
2
2
  import { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointLocation, SqliteWriteContention } from "./SqliteStorageError.mjs";
3
3
  import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
4
- import { a as createMessageDeliveryTables, i as createRecoveryCheckpointTable, n as createNonterminalIndex, r as sqliteMigrations } from "./migrations-BZ89iaTY.mjs";
4
+ import { a as createRecoveryCheckpointTable, i as sqliteMigrations, n as createNonterminalIndex, o as createMessageDeliveryTables, r as createWorkerStops } from "./migrations-BmgwzT68.mjs";
5
5
  import { Effect, Exit, Schema } from "effect";
6
6
  import { createMessageDeliveryPendingIndex } from "effect-agent/sql-message-delivery-store";
7
7
  import * as SqlClient from "effect/unstable/sql/SqlClient";
@@ -305,7 +305,8 @@ const checkPredecessorLayout = Effect.fn("SqliteJournal.checkPredecessorLayout")
305
305
  "record_json"
306
306
  ]
307
307
  },
308
- ...version === 10 ? { effect_agent_recovery_checkpoints: [
308
+ ...version === 12 ? { effect_agent_canonical_records: [...predecessorColumns.effect_agent_canonical_records, "outstanding"] } : {},
309
+ ...version >= 10 ? { effect_agent_recovery_checkpoints: [
309
310
  "thread_id",
310
311
  "through_sequence",
311
312
  "tail_digest",
@@ -317,7 +318,7 @@ const checkPredecessorLayout = Effect.fn("SqliteJournal.checkPredecessorLayout")
317
318
  const names = new Set(expected);
318
319
  if (columns.length !== names.size || columns.some((column) => !names.has(column.name))) return yield* SqliteStorageCompatibilityError.make({
319
320
  actualVersion: version,
320
- supportedVersion: 12,
321
+ supportedVersion: 14,
321
322
  message: `The v${version} ${table} columns do not match the supported predecessor; no upgrade was committed.`
322
323
  });
323
324
  }
@@ -332,22 +333,52 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
332
333
  const journalMode = yield* decodeSingleRow(Schema.Array(SqliteJournalModeRow), "pragma_journal_mode", "singleton", journalModeRows);
333
334
  if (journalMode.journal_mode.toLowerCase() !== "wal") return yield* SqliteStorageCompatibilityError.make({
334
335
  actualVersion: 0,
335
- supportedVersion: 12,
336
+ supportedVersion: 14,
336
337
  message: `SQLite WAL mode is required; the database reported ${journalMode.journal_mode}.`
337
338
  });
338
339
  const versionRows = yield* sql`PRAGMA user_version`.pipe(Effect.mapError(storageError("read storage version")));
339
340
  const version = yield* decodeSingleRow(Schema.Array(SqliteVersionRow), "pragma_user_version", "singleton", versionRows);
340
- if (version.user_version !== 0 && version.user_version !== 7 && version.user_version !== 8 && version.user_version !== 9 && version.user_version !== 10 && version.user_version !== 11 && version.user_version !== 12) return yield* SqliteStorageCompatibilityError.make({
341
+ const verifyWorkerPredecessor = Effect.fnUntraced(function* (workerContract) {
342
+ const requiredRows = yield* sql`
343
+ SELECT name
344
+ FROM sqlite_master
345
+ WHERE (type = 'table'
346
+ AND name IN (
347
+ 'effect_agent_threads',
348
+ 'effect_agent_canonical_batches',
349
+ 'effect_agent_canonical_records',
350
+ 'effect_agent_checkpoints',
351
+ 'effect_agent_submissions',
352
+ 'effect_agent_submission_ownership',
353
+ 'effect_agent_attempts',
354
+ 'effect_agent_settlement_reservations',
355
+ 'effect_agent_abort_intents',
356
+ 'effect_agent_approval_decisions',
357
+ 'effect_agent_unknown_resolutions',
358
+ 'effect_agent_schedules',
359
+ 'effect_agent_message_deliveries',
360
+ 'effect_agent_recovery_checkpoints'
361
+ )) OR (type = 'index' AND name IN ('effect_agent_submissions_nonterminal', 'effect_agent_records_subtree', 'effect_agent_message_deliveries_pending', 'effect_agent_records_outstanding', 'effect_agent_records_call', 'effect_agent_records_run_input', 'effect_agent_records_worker_input'))
362
+ OR (${workerContract ? 1 : 0} = 1 AND name IN ('effect_agent_worker_stops', 'effect_agent_worker_starts', 'effect_agent_worker_pending', 'effect_agent_worker_execution'))
363
+ ORDER BY name
364
+ `.pipe(Effect.mapError(storageError("verify storage tables")));
365
+ if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "required_tables", requiredRows)).length !== 21 + (workerContract ? 4 : 0)) return yield* SqliteStorageCompatibilityError.make({
366
+ actualVersion: 14,
367
+ supportedVersion: 14,
368
+ message: "The SQLite file claims the current format but is missing required tables or its nonterminal index. Retain the original store for inspection."
369
+ });
370
+ });
371
+ if (version.user_version !== 0 && version.user_version !== 7 && version.user_version !== 8 && version.user_version !== 9 && version.user_version !== 10 && version.user_version !== 11 && version.user_version !== 12 && version.user_version !== 13 && version.user_version !== 14) return yield* SqliteStorageCompatibilityError.make({
341
372
  actualVersion: version.user_version,
342
- supportedVersion: 12,
343
- message: `The SQLite file uses unsupported storage version ${version.user_version}; this build supports exactly version 12. Only supported v7, v8, v9, v10 and v11 can be upgraded automatically. Keep the original file and use a compatible library version.`
373
+ supportedVersion: 14,
374
+ message: `The SQLite file uses unsupported storage version ${version.user_version}; this build supports exactly version 14. Only supported v7, v8, v9, v10, v11, v12 and v13 can be upgraded automatically. Keep the original file and use a compatible library version.`
344
375
  });
345
376
  if (version.user_version === 7 || version.user_version === 8 || version.user_version === 9 || version.user_version === 10) yield* sql.withTransaction(Effect.gen(function* () {
346
377
  const current = yield* sql`PRAGMA user_version`;
347
- if (current.length === 1 && current[0].user_version === 12) return;
378
+ if (current.length === 1 && current[0].user_version === 14) return;
348
379
  if (current.length !== 1 || current[0].user_version !== 7 && current[0].user_version !== 8 && current[0].user_version !== 9 && current[0].user_version !== 10) return yield* SqliteStorageCompatibilityError.make({
349
380
  actualVersion: -1,
350
- supportedVersion: 12,
381
+ supportedVersion: 14,
351
382
  message: "Storage version changed while acquiring the upgrade transaction."
352
383
  });
353
384
  if ((yield* sql`SELECT name FROM sqlite_master WHERE type='table' AND name IN (
@@ -357,17 +388,17 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
357
388
  'effect_agent_approval_decisions', 'effect_agent_unknown_resolutions', 'effect_agent_schedules'
358
389
  )`).length !== 12) return yield* SqliteStorageCompatibilityError.make({
359
390
  actualVersion: current[0].user_version,
360
- supportedVersion: 12,
391
+ supportedVersion: 14,
361
392
  message: "The predecessor store is missing required tables; no upgrade was committed."
362
393
  });
363
394
  if ((yield* sql`SELECT name FROM sqlite_master WHERE type='table' AND name='effect_agent_recovery_checkpoints'`).length !== (current[0].user_version === 10 ? 1 : 0)) return yield* SqliteStorageCompatibilityError.make({
364
395
  actualVersion: current[0].user_version,
365
- supportedVersion: 12,
396
+ supportedVersion: 14,
366
397
  message: "The predecessor recovery checkpoint storage does not match its version; refusing ambiguous data without mutation."
367
398
  });
368
399
  if ((yield* sql`SELECT name FROM sqlite_master WHERE name='effect_agent_submissions_nonterminal'`).length !== 0) return yield* SqliteStorageCompatibilityError.make({
369
400
  actualVersion: current[0].user_version,
370
- supportedVersion: 12,
401
+ supportedVersion: 14,
371
402
  message: "The predecessor already contains the nonterminal index; refusing ambiguous storage without mutation."
372
403
  });
373
404
  if (current[0].user_version === 7) {
@@ -412,7 +443,8 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
412
443
  rowKey: "upgrade",
413
444
  message: error.message
414
445
  })));
415
- yield* sql`PRAGMA user_version = 12`;
446
+ yield* createWorkerStops;
447
+ yield* sql`PRAGMA user_version = 14`;
416
448
  yield* failpoint("upgrade:after-version");
417
449
  })).pipe(Effect.provide(NodeCrypto.layer), Effect.catchTag("SqliteStorageFailpointError", (error) => SqliteStorageError.make({
418
450
  cause: error,
@@ -441,7 +473,7 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
441
473
  `.pipe(Effect.mapError(storageError("inspect unversioned storage")));
442
474
  if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "effect_agent_%", existingRows)).length > 0) return yield* SqliteStorageCompatibilityError.make({
443
475
  actualVersion: 0,
444
- supportedVersion: 12,
476
+ supportedVersion: 14,
445
477
  message: "The SQLite file contains unversioned Effect Agent tables. Refusing to mutate ambiguous stored data; retain it for inspection with its original writer."
446
478
  });
447
479
  yield* SqliteMigrator.run({ loader: sqliteMigrations }).pipe(Effect.mapError((error) => SqliteStorageError.make({
@@ -452,16 +484,16 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
452
484
  }
453
485
  if (version.user_version === 11) yield* sql.withTransaction(Effect.gen(function* () {
454
486
  const current = yield* sql`PRAGMA user_version`;
455
- if (current[0]?.user_version === 12) return;
487
+ if (current[0]?.user_version === 14) return;
456
488
  if (current[0]?.user_version !== 11) return yield* SqliteStorageCompatibilityError.make({
457
489
  actualVersion: current[0]?.user_version ?? -1,
458
- supportedVersion: 12,
490
+ supportedVersion: 14,
459
491
  message: "Storage version changed during native index upgrade"
460
492
  });
461
493
  yield* checkPredecessorLayout(10);
462
494
  if ((yield* sql`SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'effect_agent_submissions_nonterminal'`).length !== 1) return yield* SqliteStorageCompatibilityError.make({
463
495
  actualVersion: 11,
464
- supportedVersion: 12,
496
+ supportedVersion: 14,
465
497
  message: "Predecessor storage is missing its required nonterminal index"
466
498
  });
467
499
  yield* failpoint("upgrade:before-mutation");
@@ -474,40 +506,70 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
474
506
  })));
475
507
  yield* failpoint("upgrade:after-mutation");
476
508
  yield* failpoint("upgrade:before-version");
477
- yield* sql`PRAGMA user_version = 12`;
509
+ yield* createWorkerStops;
510
+ yield* sql`PRAGMA user_version = 14`;
478
511
  yield* failpoint("upgrade:after-version");
479
512
  })).pipe(Effect.mapError((error) => SqliteStorageError.make({
480
513
  operation: "upgrade native indexes",
481
514
  message: error.message,
482
515
  cause: error
483
516
  })));
484
- const requiredRows = yield* sql`
485
- SELECT name
486
- FROM sqlite_master
487
- WHERE (type = 'table'
488
- AND name IN (
489
- 'effect_agent_threads',
490
- 'effect_agent_canonical_batches',
491
- 'effect_agent_canonical_records',
492
- 'effect_agent_checkpoints',
493
- 'effect_agent_submissions',
494
- 'effect_agent_submission_ownership',
495
- 'effect_agent_attempts',
496
- 'effect_agent_settlement_reservations',
497
- 'effect_agent_abort_intents',
498
- 'effect_agent_approval_decisions',
499
- 'effect_agent_unknown_resolutions',
500
- 'effect_agent_schedules',
501
- 'effect_agent_message_deliveries',
502
- 'effect_agent_recovery_checkpoints'
503
- )) OR (type = 'index' AND name IN ('effect_agent_submissions_nonterminal', 'effect_agent_records_subtree', 'effect_agent_message_deliveries_pending', 'effect_agent_records_outstanding', 'effect_agent_records_call', 'effect_agent_records_run_input', 'effect_agent_records_worker_input'))
504
- ORDER BY name
505
- `.pipe(Effect.mapError(storageError("verify storage tables")));
506
- if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "required_tables", requiredRows)).length !== 21) return yield* SqliteStorageCompatibilityError.make({
507
- actualVersion: 12,
508
- supportedVersion: 12,
509
- message: "The SQLite file claims the current format but is missing required tables or its nonterminal index. Retain the original store for inspection."
510
- });
517
+ if (version.user_version === 12) yield* sql.withTransaction(Effect.gen(function* () {
518
+ const current = yield* sql`PRAGMA user_version`;
519
+ if (current[0]?.user_version === 14) return;
520
+ if (current[0]?.user_version !== 12) return yield* SqliteStorageCompatibilityError.make({
521
+ actualVersion: current[0]?.user_version ?? -1,
522
+ supportedVersion: 14,
523
+ message: "Storage version changed during worker stop upgrade"
524
+ });
525
+ yield* checkPredecessorLayout(12);
526
+ yield* verifyWorkerPredecessor(false);
527
+ yield* failpoint("upgrade:before-mutation");
528
+ yield* createWorkerStops;
529
+ yield* failpoint("upgrade:after-mutation");
530
+ yield* failpoint("upgrade:before-version");
531
+ yield* sql`PRAGMA user_version = 14`;
532
+ yield* failpoint("upgrade:after-version");
533
+ })).pipe(Effect.mapError((cause) => SqliteStorageError.make({
534
+ operation: "upgrade worker stop",
535
+ message: "Worker stop upgrade failed",
536
+ cause
537
+ })));
538
+ if (version.user_version === 13) yield* sql.withTransaction(Effect.gen(function* () {
539
+ const current = yield* sql`PRAGMA user_version`;
540
+ if (current[0]?.user_version === 14) return;
541
+ if (current[0]?.user_version !== 13) return yield* SqliteStorageCompatibilityError.make({
542
+ actualVersion: current[0]?.user_version ?? -1,
543
+ supportedVersion: 14,
544
+ message: "Storage version changed during assignment seal upgrade"
545
+ });
546
+ yield* checkPredecessorLayout(12);
547
+ yield* verifyWorkerPredecessor(true);
548
+ const columns = yield* sql`PRAGMA table_info(effect_agent_worker_stops)`;
549
+ yield* Schema.decodeUnknownEffect(Schema.Tuple([Schema.Struct({
550
+ cid: Schema.Literal(0),
551
+ name: Schema.Literal("thread_id"),
552
+ type: Schema.Literal("TEXT"),
553
+ notnull: Schema.Literal(1),
554
+ dflt_value: Schema.Null,
555
+ pk: Schema.Literal(1)
556
+ })]))(columns).pipe(Effect.mapError(() => SqliteStorageCompatibilityError.make({
557
+ actualVersion: 13,
558
+ supportedVersion: 14,
559
+ message: "Unsupported worker seal layout; no upgrade was committed"
560
+ })));
561
+ yield* failpoint("upgrade:before-mutation");
562
+ yield* sql`ALTER TABLE effect_agent_worker_stops ADD COLUMN terminal TEXT`;
563
+ yield* failpoint("upgrade:after-mutation");
564
+ yield* failpoint("upgrade:before-version");
565
+ yield* sql`PRAGMA user_version = 14`;
566
+ yield* failpoint("upgrade:after-version");
567
+ })).pipe(Effect.mapError((cause) => SqliteStorageError.make({
568
+ operation: "upgrade assignment seals",
569
+ message: "Assignment seal upgrade failed",
570
+ cause
571
+ })));
572
+ yield* verifyWorkerPredecessor(true);
511
573
  const classifyWriteFailure = (operation) => (error) => error.reason._tag === "LockTimeoutError" ? SqliteWriteContention.make({
512
574
  cause: error,
513
575
  operation,
@@ -1041,4 +1103,4 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
1041
1103
  //#endregion
1042
1104
  export { initializeSqliteJournal as a, decodeRows as i, RawCheckpoint as n, RawReadRequest as r, RawAppendRequest as t };
1043
1105
 
1044
- //# sourceMappingURL=sqlite-journal-BCyBc87Y.mjs.map
1106
+ //# sourceMappingURL=sqlite-journal-DE4MN8uP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-journal-DE4MN8uP.mjs","names":[],"sources":["../src/internal/sqlite-journal.ts"],"sourcesContent":["import { NodeCrypto } from \"@effect/platform-node\";\nimport { SqliteMigrator } from \"@effect/sql-sqlite-node\";\nimport { Effect, Exit, Schema } from \"effect\";\nimport { EMPTY_TAIL_DIGEST } from \"effect-agent/digest\";\nimport { CanonicalRecord, CanonicalSequence, ProducerEpoch } from \"effect-agent/records\";\nimport { ScheduleFailpoint, ScheduleFailpointError } from \"effect-agent/schedule\";\nimport { createMessageDeliveryPendingIndex } from \"effect-agent/sql-message-delivery-store\";\nimport {\n checkV2ThreadLayout,\n upgradeV2Schedules,\n upgradeV2Subscriptions,\n} from \"effect-agent/sql-storage-v2-upgrade\";\nimport {\n createNativeReadIndexes,\n seedNativeReadIndexes,\n indexCanonicalRecord,\n} from \"effect-agent/sql-thread-native-reads\";\nimport { SubscriptionFailpoint, SubscriptionFailpointError } from \"effect-agent/subscription\";\nimport {\n MAX_THREAD_EXPORT_RECORDS,\n CheckpointRejected,\n FenceRejected,\n ThreadNotMaterialized,\n type SaveRecoveryCheckpointRequest,\n} from \"effect-agent/thread-store\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\nimport type { SqlError } from \"effect/unstable/sql/SqlError\";\n\nimport { SqliteStorageConfig } from \"../SqliteStorageConfig.ts\";\nimport type { SqliteStorageFailpointError } from \"../SqliteStorageError.ts\";\nimport {\n SqliteAppendConflict,\n SqliteCheckpointConflict,\n SqliteFenceRejected,\n SqliteStorageCompatibilityError,\n SqliteStorageFailpointLocation,\n SqliteStorageCorruptionError,\n SqliteStorageError,\n SqliteWriteContention,\n} from \"../SqliteStorageError.ts\";\nimport { SqliteStorageFailpoint } from \"../SqliteStorageFailpoint.ts\";\nimport { createMessageDeliveryTables } from \"./message-delivery-schema.ts\";\nimport {\n CurrentSqliteStorageVersion,\n createWorkerStops,\n createNonterminalIndex,\n sqliteMigrations,\n} from \"./migrations.ts\";\nimport { createRecoveryCheckpointTable } from \"./recovery-checkpoint-schema.ts\";\n\nconst BoundedStoredText = Schema.String.check(Schema.isMaxLength(16 * 1024 * 1024));\nconst BoundedIdentifier = Schema.NonEmptyString.check(Schema.isMaxLength(1024));\nconst NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));\nconst MAX_RECORDS_PER_THREAD = MAX_THREAD_EXPORT_RECORDS;\nconst ZERO_SEQUENCE = Schema.decodeSync(CanonicalSequence)(0);\nconst MAX_STORED_TEXT_BYTES = 16 * 1024 * 1024;\nconst MAX_IDENTIFIER_LENGTH = 1_024;\n\nconst storedTextBytes = (value: string): number => new TextEncoder().encode(value).byteLength;\n\nclass SqliteVersionRow extends Schema.Class<SqliteVersionRow>(\"SqliteVersionRow\")({\n user_version: NonNegativeInt,\n}) {}\n\nclass SqliteJournalModeRow extends Schema.Class<SqliteJournalModeRow>(\"SqliteJournalModeRow\")({\n journal_mode: Schema.NonEmptyString.check(Schema.isMaxLength(32)),\n}) {}\n\nclass SqliteNameRow extends Schema.Class<SqliteNameRow>(\"SqliteNameRow\")({\n name: BoundedIdentifier,\n}) {}\n\nclass ThreadRow extends Schema.Class<ThreadRow>(\"ThreadRow\")({\n thread_id: BoundedIdentifier,\n created_at: Schema.NonEmptyString.check(Schema.isMaxLength(128)),\n producer_epoch: ProducerEpoch,\n tail_digest: BoundedStoredText,\n tail_sequence: CanonicalSequence,\n}) {}\n\nclass BatchRow extends Schema.Class<BatchRow>(\"BatchRow\")({\n batch_digest: BoundedStoredText,\n batch_id: BoundedIdentifier,\n batch_json: BoundedStoredText,\n thread_id: BoundedIdentifier,\n first_sequence: CanonicalSequence,\n last_sequence: CanonicalSequence,\n tail_digest: BoundedStoredText,\n}) {}\n\nclass RecordRow extends Schema.Class<RecordRow>(\"RecordRow\")({\n batch_id: BoundedIdentifier,\n thread_id: BoundedIdentifier,\n record_id: BoundedIdentifier,\n record_json: BoundedStoredText,\n sequence: CanonicalSequence,\n}) {}\n\nclass CheckpointRow extends Schema.Class<CheckpointRow>(\"CheckpointRow\")({\n checkpoint_json: BoundedStoredText,\n thread_id: BoundedIdentifier,\n tail_digest: BoundedStoredText,\n through_sequence: CanonicalSequence,\n}) {}\n\nexport class RawRecord extends Schema.Class<RawRecord>(\"@effect-agent/storage-sqlite/RawRecord\")({\n recordId: BoundedIdentifier,\n recordJson: BoundedStoredText,\n}) {}\n\nexport class RawAppendRequest extends Schema.Class<RawAppendRequest>(\n \"@effect-agent/storage-sqlite/RawAppendRequest\",\n)({\n batchDigest: BoundedStoredText,\n batchId: BoundedIdentifier,\n batchJson: BoundedStoredText,\n threadId: BoundedIdentifier,\n expectedTailDigest: BoundedStoredText,\n expectedTailSequence: CanonicalSequence,\n producerEpoch: ProducerEpoch,\n records: Schema.NonEmptyArray(RawRecord).check(Schema.isMaxLength(256)),\n tailDigest: BoundedStoredText,\n}) {}\n\nexport class RawAppendResult extends Schema.Class<RawAppendResult>(\n \"@effect-agent/storage-sqlite/RawAppendResult\",\n)({\n firstSequence: CanonicalSequence,\n lastSequence: CanonicalSequence,\n replayed: Schema.Boolean,\n tailDigest: BoundedStoredText,\n}) {}\n\nexport class RawReadRequest extends Schema.Class<RawReadRequest>(\n \"@effect-agent/storage-sqlite/RawReadRequest\",\n)({\n threadId: BoundedIdentifier,\n fromSequenceExclusive: CanonicalSequence,\n limit: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(1_024)),\n}) {}\n\nexport class RawCheckpoint extends Schema.Class<RawCheckpoint>(\n \"@effect-agent/storage-sqlite/RawCheckpoint\",\n)({\n checkpointJson: BoundedStoredText,\n threadId: BoundedIdentifier,\n tailDigest: BoundedStoredText,\n throughSequence: CanonicalSequence,\n}) {}\n\nexport class RawThreadExport extends Schema.Class<RawThreadExport>(\n \"@effect-agent/storage-sqlite/RawThreadExport\",\n)({\n thread: ThreadRow,\n records: Schema.Array(RecordRow),\n}) {}\n\ntype AppendError =\n | SqliteAppendConflict\n | SqliteFenceRejected\n | SqliteStorageCorruptionError\n | SqliteStorageError\n | SqliteStorageFailpointError\n | SqliteWriteContention;\n\ntype CheckpointError =\n | SqliteCheckpointConflict\n | SqliteStorageCorruptionError\n | SqliteStorageError\n | SqliteWriteContention;\n\nconst storageError =\n (operation: string) =>\n (error: SqlError): SqliteStorageError =>\n SqliteStorageError.make({\n cause: error,\n operation,\n message: error.message,\n });\n\n/** Decode raw SQLite rows against a Schema, reporting failures as typed corruption. */\nexport const decodeRows = Effect.fn(\"SqliteJournal.decodeRows\")(\n <A, I>(\n schema: Schema.Codec<ReadonlyArray<A>, ReadonlyArray<I>>,\n table: string,\n rowKey: string,\n rows: unknown,\n ): Effect.Effect<ReadonlyArray<A>, SqliteStorageCorruptionError> =>\n Schema.decodeUnknownEffect(schema)(rows).pipe(\n Effect.mapError((error) =>\n SqliteStorageCorruptionError.make({\n table,\n rowKey,\n message: String(error),\n }),\n ),\n ),\n);\n\n/** Decode exactly one raw SQLite row against a Schema, reporting failures as typed corruption. */\nexport const decodeSingleRow = Effect.fn(\"SqliteJournal.decodeSingleRow\")(\n <A, I>(\n schema: Schema.Codec<ReadonlyArray<A>, ReadonlyArray<I>>,\n table: string,\n rowKey: string,\n rows: unknown,\n ): Effect.Effect<A, SqliteStorageCorruptionError> =>\n decodeRows(schema, table, rowKey, rows).pipe(\n Effect.flatMap((decoded) =>\n decoded.length === 1\n ? Effect.succeed(decoded[0])\n : Effect.fail(\n SqliteStorageCorruptionError.make({\n table,\n rowKey,\n message: `Expected exactly one row but found ${decoded.length}.`,\n }),\n ),\n ),\n ),\n);\n\n/** Column inventory of the supported v8 predecessor, independent of physical column order. */\nconst predecessorColumns = {\n effect_agent_threads: [\n \"thread_id\",\n \"created_at\",\n \"tail_sequence\",\n \"tail_digest\",\n \"producer_epoch\",\n ],\n effect_agent_canonical_batches: [\n \"thread_id\",\n \"batch_id\",\n \"first_sequence\",\n \"last_sequence\",\n \"batch_digest\",\n \"tail_digest\",\n \"batch_json\",\n ],\n effect_agent_canonical_records: [\"thread_id\", \"sequence\", \"record_id\", \"batch_id\", \"record_json\"],\n effect_agent_checkpoints: [\"thread_id\", \"through_sequence\", \"tail_digest\", \"checkpoint_json\"],\n effect_agent_submissions: [\n \"submission_id\",\n \"thread_id\",\n \"queue_sequence\",\n \"principal\",\n \"idempotency_key\",\n \"agent_id\",\n \"agent_digests_json\",\n \"deployment_id\",\n \"input_json\",\n \"input_digest\",\n \"receipt_id\",\n \"state\",\n \"settled_outcome\",\n \"created_at\",\n \"ready_at\",\n \"input_applied_record_id\",\n \"input_applied_sequence\",\n \"joined_host_submission_id\",\n \"suspended_reason_json\",\n \"suspended_at\",\n \"unknown_reason\",\n \"unknown_tool_call_ids_json\",\n \"parent_submission_id\",\n \"parent_tool_call_id\",\n \"admission_group\",\n \"admission_fence_json\",\n ],\n effect_agent_submission_ownership: [\n \"submission_id\",\n \"attempt_id\",\n \"ownership_token\",\n \"producer_epoch\",\n \"owner_producer_id\",\n \"lease_expires_at\",\n ],\n effect_agent_attempts: [\n \"attempt_id\",\n \"submission_id\",\n \"thread_id\",\n \"owner_producer_id\",\n \"producer_epoch\",\n \"claimed_at\",\n ],\n effect_agent_settlement_reservations: [\n \"submission_id\",\n \"settlement_id\",\n \"outcome\",\n \"record_id\",\n \"record_json\",\n \"record_digest\",\n \"reserved_at\",\n \"finalized_at\",\n ],\n effect_agent_abort_intents: [\n \"submission_id\",\n \"author\",\n \"reason\",\n \"requested_at\",\n \"canonical_record_id\",\n ],\n effect_agent_approval_decisions: [\n \"submission_id\",\n \"tool_call_id\",\n \"decision\",\n \"resolver\",\n \"reason\",\n \"decided_at\",\n ],\n effect_agent_unknown_resolutions: [\n \"submission_id\",\n \"tool_call_id\",\n \"author\",\n \"reason\",\n \"resolution_json\",\n \"resolved_at\",\n ],\n effect_agent_child_reservations: [\n \"reservation_id\",\n \"parent_submission_id\",\n \"parent_tool_call_id\",\n \"child_submission_id\",\n \"status\",\n \"allocation_json\",\n \"allocation_digest\",\n \"accounting_json\",\n \"reserved_at\",\n \"release_began_at\",\n \"released_at\",\n ],\n effect_agent_schedules: [\n \"tenant_id\",\n \"owner_id\",\n \"schedule_id\",\n \"deadline_at_millis\",\n \"record_json\",\n ],\n effect_agent_subscription_sequences: [\n \"tenant_id\",\n \"source_address\",\n \"sequence\",\n \"event_scan_cursor\",\n \"delivery_scan_cursor\",\n \"recovery_scan_cursor\",\n ],\n effect_agent_subscriptions: [\n \"tenant_id\",\n \"source_address\",\n \"owner_id\",\n \"subscription_id\",\n \"ordinal\",\n \"source_name\",\n \"source_version\",\n \"matching_key\",\n \"state\",\n \"expires_at_millis\",\n \"recovery_at_millis\",\n \"recovery_present\",\n \"record_json\",\n ],\n effect_agent_subscription_events: [\n \"tenant_id\",\n \"source_address\",\n \"event_id\",\n \"source_name\",\n \"source_version\",\n \"matching_key\",\n \"payload_digest\",\n \"cutoff\",\n \"cursor\",\n \"routing_complete\",\n \"next_attempt_at_millis\",\n \"record_json\",\n \"tombstone\",\n ],\n effect_agent_subscription_deliveries: [\n \"tenant_id\",\n \"source_address\",\n \"owner_id\",\n \"subscription_id\",\n \"event_id\",\n \"delivery_key\",\n \"state\",\n \"next_attempt_at_millis\",\n \"record_json\",\n ],\n} as const;\n\nconst checkPredecessorLayout = Effect.fn(\"SqliteJournal.checkPredecessorLayout\")(function* (\n version: 8 | 9 | 10 | 12,\n) {\n const sql = yield* SqlClient.SqlClient;\n\n const messageColumns =\n version === 8\n ? predecessorColumns\n : {\n ...predecessorColumns,\n effect_agent_submissions: [\n ...predecessorColumns.effect_agent_submissions,\n \"worker_admission_json\",\n \"message_admission_json\",\n ],\n effect_agent_message_deliveries: [\n \"owner_thread_id\",\n \"message_id\",\n \"version\",\n \"state\",\n \"deadline_at_millis\",\n \"record_json\",\n ],\n };\n\n const expectedColumns = {\n ...messageColumns,\n ...(version === 12\n ? {\n effect_agent_canonical_records: [\n ...predecessorColumns.effect_agent_canonical_records,\n \"outstanding\",\n ],\n }\n : {}),\n ...(version >= 10\n ? {\n effect_agent_recovery_checkpoints: [\n \"thread_id\",\n \"through_sequence\",\n \"tail_digest\",\n \"checkpoint_json\",\n ],\n }\n : {}),\n };\n\n for (const [table, expected] of Object.entries(expectedColumns)) {\n const columns = yield* decodeRows(\n Schema.Array(Schema.Struct({ name: BoundedIdentifier })),\n table,\n \"schema\",\n yield* sql.unsafe(`PRAGMA table_info(${table})`),\n );\n\n const names = new Set<string>(expected);\n\n if (columns.length !== names.size || columns.some((column) => !names.has(column.name)))\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: version,\n supportedVersion: CurrentSqliteStorageVersion,\n message: `The v${version} ${table} columns do not match the supported predecessor; no upgrade was committed.`,\n });\n }\n});\n\nexport const initializeSqliteJournal = Effect.fn(\"SqliteJournal.initialize\")(function* () {\n const sql = yield* SqlClient.SqlClient;\n const { hit: failpoint } = yield* SqliteStorageFailpoint;\n const { busyTimeout } = yield* SqliteStorageConfig;\n\n yield* sql`PRAGMA foreign_keys = ON`.pipe(Effect.mapError(storageError(\"enable foreign keys\")));\n // PRAGMA statements do not accept bound parameters; the value is a schema-validated\n // non-negative integer, never caller-controlled text.\n yield* sql\n .unsafe(`PRAGMA busy_timeout = ${busyTimeout}`)\n .pipe(Effect.mapError(storageError(\"configure busy timeout\")));\n\n const journalModeRows = yield* sql<Record<string, unknown>>`PRAGMA journal_mode`.pipe(\n Effect.mapError(storageError(\"read journal mode\")),\n );\n\n const journalMode = yield* decodeSingleRow(\n Schema.Array(SqliteJournalModeRow),\n \"pragma_journal_mode\",\n \"singleton\",\n journalModeRows,\n );\n\n if (journalMode.journal_mode.toLowerCase() !== \"wal\") {\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: 0,\n supportedVersion: CurrentSqliteStorageVersion,\n message: `SQLite WAL mode is required; the database reported ${journalMode.journal_mode}.`,\n });\n }\n\n const versionRows = yield* sql<Record<string, unknown>>`PRAGMA user_version`.pipe(\n Effect.mapError(storageError(\"read storage version\")),\n );\n\n const version = yield* decodeSingleRow(\n Schema.Array(SqliteVersionRow),\n \"pragma_user_version\",\n \"singleton\",\n versionRows,\n );\n\n const verifyWorkerPredecessor = Effect.fnUntraced(function* (workerContract: boolean) {\n const requiredRows = yield* sql<Record<string, unknown>>`\n SELECT name\n FROM sqlite_master\n WHERE (type = 'table'\n AND name IN (\n 'effect_agent_threads',\n 'effect_agent_canonical_batches',\n 'effect_agent_canonical_records',\n 'effect_agent_checkpoints',\n 'effect_agent_submissions',\n 'effect_agent_submission_ownership',\n 'effect_agent_attempts',\n 'effect_agent_settlement_reservations',\n 'effect_agent_abort_intents',\n 'effect_agent_approval_decisions',\n 'effect_agent_unknown_resolutions',\n 'effect_agent_schedules',\n 'effect_agent_message_deliveries',\n 'effect_agent_recovery_checkpoints'\n )) OR (type = 'index' AND name IN ('effect_agent_submissions_nonterminal', 'effect_agent_records_subtree', 'effect_agent_message_deliveries_pending', 'effect_agent_records_outstanding', 'effect_agent_records_call', 'effect_agent_records_run_input', 'effect_agent_records_worker_input'))\n OR (${workerContract ? 1 : 0} = 1 AND name IN ('effect_agent_worker_stops', 'effect_agent_worker_starts', 'effect_agent_worker_pending', 'effect_agent_worker_execution'))\n ORDER BY name\n `.pipe(Effect.mapError(storageError(\"verify storage tables\")));\n\n const required = yield* decodeRows(\n Schema.Array(SqliteNameRow),\n \"sqlite_master\",\n \"required_tables\",\n requiredRows,\n );\n\n if (required.length !== 21 + (workerContract ? 4 : 0)) {\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: CurrentSqliteStorageVersion,\n supportedVersion: CurrentSqliteStorageVersion,\n message:\n \"The SQLite file claims the current format but is missing required tables or its nonterminal index. Retain the original store for inspection.\",\n });\n }\n });\n\n // Support the known beta49/beta50 and immediate predecessor formats atomically.\n if (\n version.user_version !== 0 &&\n version.user_version !== 7 &&\n version.user_version !== 8 &&\n version.user_version !== 9 &&\n version.user_version !== 10 &&\n version.user_version !== 11 &&\n version.user_version !== 12 &&\n version.user_version !== 13 &&\n version.user_version !== CurrentSqliteStorageVersion\n ) {\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: version.user_version,\n supportedVersion: CurrentSqliteStorageVersion,\n message:\n `The SQLite file uses unsupported storage version ${version.user_version}; ` +\n `this build supports exactly version ${CurrentSqliteStorageVersion}. ` +\n \"Only supported v7, v8, v9, v10, v11, v12 and v13 can be upgraded automatically. Keep the original file and use a compatible library version.\",\n });\n }\n\n if (\n version.user_version === 7 ||\n version.user_version === 8 ||\n version.user_version === 9 ||\n version.user_version === 10\n ) {\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* sql<{ user_version: number }>`PRAGMA user_version`;\n\n if (current.length === 1 && current[0].user_version === CurrentSqliteStorageVersion)\n return;\n if (\n current.length !== 1 ||\n (current[0].user_version !== 7 &&\n current[0].user_version !== 8 &&\n current[0].user_version !== 9 &&\n current[0].user_version !== 10)\n )\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: -1,\n supportedVersion: CurrentSqliteStorageVersion,\n message: \"Storage version changed while acquiring the upgrade transaction.\",\n });\n\n const required = yield* sql<{\n name: string;\n }>`SELECT name FROM sqlite_master WHERE type='table' AND name IN (\n 'effect_agent_threads', 'effect_agent_canonical_batches', 'effect_agent_canonical_records',\n 'effect_agent_checkpoints', 'effect_agent_submissions', 'effect_agent_submission_ownership',\n 'effect_agent_attempts', 'effect_agent_settlement_reservations', 'effect_agent_abort_intents',\n 'effect_agent_approval_decisions', 'effect_agent_unknown_resolutions', 'effect_agent_schedules'\n )`;\n\n if (required.length !== 12)\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: current[0].user_version,\n supportedVersion: CurrentSqliteStorageVersion,\n message:\n \"The predecessor store is missing required tables; no upgrade was committed.\",\n });\n\n const recoveryTables =\n yield* sql`SELECT name FROM sqlite_master WHERE type='table' AND name='effect_agent_recovery_checkpoints'`;\n\n if (recoveryTables.length !== (current[0].user_version === 10 ? 1 : 0))\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: current[0].user_version,\n supportedVersion: CurrentSqliteStorageVersion,\n message:\n \"The predecessor recovery checkpoint storage does not match its version; refusing ambiguous data without mutation.\",\n });\n\n const indexes =\n yield* sql`SELECT name FROM sqlite_master WHERE name='effect_agent_submissions_nonterminal'`;\n\n if (indexes.length !== 0)\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: current[0].user_version,\n supportedVersion: CurrentSqliteStorageVersion,\n message:\n \"The predecessor already contains the nonterminal index; refusing ambiguous storage without mutation.\",\n });\n if (current[0].user_version === 7) {\n yield* checkV2ThreadLayout();\n for (const statement of [\n sql`ALTER TABLE effect_agent_submissions ADD COLUMN admission_group TEXT`,\n sql`ALTER TABLE effect_agent_submissions ADD COLUMN admission_fence_json TEXT`,\n sql`CREATE INDEX effect_agent_submissions_group ON effect_agent_submissions (thread_id, admission_group, state)`,\n ]) {\n yield* failpoint(\"upgrade:before-mutation\");\n yield* statement;\n yield* failpoint(\"upgrade:after-mutation\");\n }\n yield* upgradeV2Schedules(16 * 1024 * 1024).pipe(\n Effect.provideService(ScheduleFailpoint, {\n hit: (point) =>\n Schema.decodeUnknownEffect(SqliteStorageFailpointLocation)(point).pipe(\n Effect.flatMap(failpoint),\n Effect.mapError(() => ScheduleFailpointError.make({ point })),\n ),\n }),\n );\n yield* upgradeV2Subscriptions(16 * 1024 * 1024).pipe(\n Effect.provideService(SubscriptionFailpoint, {\n hit: (point) =>\n Schema.decodeUnknownEffect(SqliteStorageFailpointLocation)(point).pipe(\n Effect.flatMap(failpoint),\n Effect.mapError(() => SubscriptionFailpointError.make({ point })),\n ),\n }),\n );\n }\n if (\n current[0].user_version === 8 ||\n current[0].user_version === 9 ||\n current[0].user_version === 10\n )\n yield* checkPredecessorLayout(current[0].user_version);\n if (current[0].user_version === 7 || current[0].user_version === 8) {\n yield* failpoint(\"upgrade:before-mutation\");\n yield* sql`ALTER TABLE effect_agent_submissions ADD COLUMN worker_admission_json TEXT`;\n yield* failpoint(\"upgrade:after-mutation\");\n yield* failpoint(\"upgrade:before-mutation\");\n yield* sql`ALTER TABLE effect_agent_submissions ADD COLUMN message_admission_json TEXT`;\n yield* failpoint(\"upgrade:after-mutation\");\n yield* failpoint(\"upgrade:before-mutation\");\n yield* createMessageDeliveryTables;\n yield* failpoint(\"upgrade:after-mutation\");\n }\n if (current[0].user_version !== 10) {\n yield* failpoint(\"upgrade:before-mutation\");\n yield* createRecoveryCheckpointTable;\n yield* failpoint(\"upgrade:after-mutation\");\n }\n yield* failpoint(\"upgrade:before-mutation\");\n yield* createNonterminalIndex;\n yield* failpoint(\"upgrade:after-mutation\");\n yield* failpoint(\"upgrade:before-version\");\n yield* createNativeReadIndexes;\n yield* createMessageDeliveryPendingIndex;\n yield* seedNativeReadIndexes.pipe(\n Effect.catchTag(\"ThreadStoreError\", (error) =>\n SqliteStorageCorruptionError.make({\n table: \"effect_agent_canonical_records\",\n rowKey: \"upgrade\",\n message: error.message,\n }),\n ),\n );\n yield* createWorkerStops;\n yield* sql`PRAGMA user_version = 14`;\n yield* failpoint(\"upgrade:after-version\");\n }),\n )\n .pipe(\n Effect.provide(NodeCrypto.layer),\n Effect.catchTag(\"SqliteStorageFailpointError\", (error) =>\n SqliteStorageError.make({\n cause: error,\n operation: \"upgrade storage\",\n message: error.message,\n }),\n ),\n Effect.catchTag([\"ScheduleFailpointError\", \"SubscriptionFailpointError\"], (error) =>\n SqliteStorageError.make({\n cause: error,\n operation: \"upgrade storage\",\n message: \"Injected storage upgrade failure\",\n }),\n ),\n Effect.catchTag(\"StorageUpgradeError\", (error) =>\n SqliteStorageCorruptionError.make({\n table: error.table,\n rowKey: error.rowKey,\n message: error.message,\n }),\n ),\n Effect.catchTag(\"SqlError\", storageError(\"upgrade supported storage\")),\n Effect.catchTag(\"SchemaError\", (error) =>\n SqliteStorageCorruptionError.make({\n table: \"upgrade\",\n rowKey: \"v7\",\n message: error.message,\n }),\n ),\n );\n }\n\n if (version.user_version === 0) {\n const existingRows = yield* sql<Record<string, unknown>>`\n SELECT name\n FROM sqlite_master\n WHERE type = 'table'\n AND name LIKE 'effect_agent_%'\n ORDER BY name\n `.pipe(Effect.mapError(storageError(\"inspect unversioned storage\")));\n\n const existing = yield* decodeRows(\n Schema.Array(SqliteNameRow),\n \"sqlite_master\",\n \"effect_agent_%\",\n existingRows,\n );\n\n if (existing.length > 0) {\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: 0,\n supportedVersion: CurrentSqliteStorageVersion,\n message:\n \"The SQLite file contains unversioned Effect Agent tables. Refusing to mutate ambiguous stored data; retain it for inspection with its original writer.\",\n });\n }\n\n yield* SqliteMigrator.run({ loader: sqliteMigrations }).pipe(\n Effect.mapError((error) =>\n SqliteStorageError.make({\n cause: error,\n operation: \"initialize current storage\",\n message: error.message,\n }),\n ),\n );\n }\n\n if (version.user_version === 11) {\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* sql<{ user_version: number }>`PRAGMA user_version`;\n\n if (current[0]?.user_version === 14) return;\n if (current[0]?.user_version !== 11)\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: current[0]?.user_version ?? -1,\n supportedVersion: 14,\n message: \"Storage version changed during native index upgrade\",\n });\n yield* checkPredecessorLayout(10);\n\n const requiredIndex =\n yield* sql`SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'effect_agent_submissions_nonterminal'`;\n\n if (requiredIndex.length !== 1)\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: 11,\n supportedVersion: 14,\n message: \"Predecessor storage is missing its required nonterminal index\",\n });\n yield* failpoint(\"upgrade:before-mutation\");\n yield* createNativeReadIndexes;\n yield* createMessageDeliveryPendingIndex;\n yield* seedNativeReadIndexes.pipe(\n Effect.catchTag(\"ThreadStoreError\", (error) =>\n SqliteStorageCorruptionError.make({\n table: \"effect_agent_canonical_records\",\n rowKey: \"upgrade\",\n message: error.message,\n }),\n ),\n );\n yield* failpoint(\"upgrade:after-mutation\");\n yield* failpoint(\"upgrade:before-version\");\n yield* createWorkerStops;\n yield* sql`PRAGMA user_version = 14`;\n yield* failpoint(\"upgrade:after-version\");\n }),\n )\n .pipe(\n Effect.mapError((error) =>\n SqliteStorageError.make({\n operation: \"upgrade native indexes\",\n message: error.message,\n cause: error,\n }),\n ),\n );\n }\n\n if (version.user_version === 12) {\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* sql<{ user_version: number }>`PRAGMA user_version`;\n\n if (current[0]?.user_version === 14) return;\n if (current[0]?.user_version !== 12)\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: current[0]?.user_version ?? -1,\n supportedVersion: 14,\n message: \"Storage version changed during worker stop upgrade\",\n });\n yield* checkPredecessorLayout(12);\n yield* verifyWorkerPredecessor(false);\n yield* failpoint(\"upgrade:before-mutation\");\n yield* createWorkerStops;\n yield* failpoint(\"upgrade:after-mutation\");\n yield* failpoint(\"upgrade:before-version\");\n yield* sql`PRAGMA user_version = 14`;\n yield* failpoint(\"upgrade:after-version\");\n }),\n )\n .pipe(\n Effect.mapError((cause) =>\n SqliteStorageError.make({\n operation: \"upgrade worker stop\",\n message: \"Worker stop upgrade failed\",\n cause,\n }),\n ),\n );\n }\n\n if (version.user_version === 13) {\n yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const current = yield* sql<{ user_version: number }>`PRAGMA user_version`;\n\n if (current[0]?.user_version === 14) return;\n if (current[0]?.user_version !== 13)\n return yield* SqliteStorageCompatibilityError.make({\n actualVersion: current[0]?.user_version ?? -1,\n supportedVersion: 14,\n message: \"Storage version changed during assignment seal upgrade\",\n });\n yield* checkPredecessorLayout(12);\n yield* verifyWorkerPredecessor(true);\n const columns = yield* sql`PRAGMA table_info(effect_agent_worker_stops)`;\n\n yield* Schema.decodeUnknownEffect(\n Schema.Tuple([\n Schema.Struct({\n cid: Schema.Literal(0),\n name: Schema.Literal(\"thread_id\"),\n type: Schema.Literal(\"TEXT\"),\n notnull: Schema.Literal(1),\n dflt_value: Schema.Null,\n pk: Schema.Literal(1),\n }),\n ]),\n )(columns).pipe(\n Effect.mapError(() =>\n SqliteStorageCompatibilityError.make({\n actualVersion: 13,\n supportedVersion: 14,\n message: \"Unsupported worker seal layout; no upgrade was committed\",\n }),\n ),\n );\n yield* failpoint(\"upgrade:before-mutation\");\n yield* sql`ALTER TABLE effect_agent_worker_stops ADD COLUMN terminal TEXT`;\n yield* failpoint(\"upgrade:after-mutation\");\n yield* failpoint(\"upgrade:before-version\");\n yield* sql`PRAGMA user_version = 14`;\n yield* failpoint(\"upgrade:after-version\");\n }),\n )\n .pipe(\n Effect.mapError((cause) =>\n SqliteStorageError.make({\n operation: \"upgrade assignment seals\",\n message: \"Assignment seal upgrade failed\",\n cause,\n }),\n ),\n );\n }\n\n yield* verifyWorkerPredecessor(true);\n\n const classifyWriteFailure =\n (operation: string) =>\n (error: SqlError): SqliteStorageError | SqliteWriteContention =>\n error.reason._tag === \"LockTimeoutError\"\n ? SqliteWriteContention.make({\n cause: error,\n operation,\n message: `Another producer holds the SQLite write lock; ${operation} is safe to retry.`,\n })\n : storageError(operation)(error);\n\n /**\n * Runs one journal write transaction under `BEGIN IMMEDIATE`. SQLite's deferred `BEGIN`\n * would let a read-then-write transaction start as a reader and fail with\n * SQLITE_BUSY_SNAPSHOT on upgrade, which `busy_timeout` never retries. Taking the write\n * lock up front keeps cross-owner contention inside the bounded busy retry; a lock\n * timeout is classified as the retryable SqliteWriteContention. A failed `BEGIN` leaves\n * no transaction, so no rollback is attempted for it.\n *\n * Journal write transactions are always top level. Nesting one inside another would\n * deadlock the single-connection client, so new journal operations must not wrap this\n * helper inside another transaction.\n */\n const withWriteTransaction =\n (operation: string) =>\n <A, E>(\n effect: Effect.Effect<A, E>,\n ): Effect.Effect<A, E | SqliteStorageError | SqliteWriteContention> =>\n Effect.uninterruptibleMask((restore) =>\n Effect.scoped(\n Effect.gen(function* () {\n const connection = yield* sql.reserve.pipe(\n Effect.mapError(classifyWriteFailure(operation)),\n );\n\n yield* connection\n .executeUnprepared(\"BEGIN IMMEDIATE\", [], undefined)\n .pipe(Effect.mapError(classifyWriteFailure(operation)));\n\n const exit = yield* restore(\n Effect.provideService(effect, sql.transactionService, [connection, 0] as const),\n ).pipe(Effect.exit);\n\n if (Exit.isSuccess(exit)) {\n yield* connection\n .executeUnprepared(\"COMMIT\", [], undefined)\n .pipe(Effect.mapError(classifyWriteFailure(operation)));\n\n return exit.value;\n }\n yield* Effect.orDie(connection.executeUnprepared(\"ROLLBACK\", [], undefined));\n\n return yield* exit;\n }),\n ).pipe(\n Effect.withSpan(\"SqliteJournal.withWriteTransaction\", { attributes: { operation } }),\n ),\n );\n\n /**\n * Runs a read-only snapshot under a deferred transaction. Effect's SQLite client now\n * starts every writable-client `withTransaction` with `BEGIN IMMEDIATE`, which is the\n * right default for mutations but would make exports take the write lock and block a\n * concurrent append. Reserving the connection and beginning explicitly preserves the\n * adapter's snapshot-with-concurrent-writer contract. As with the write helper, a failed\n * `BEGIN` is reported directly because there is no transaction to roll back.\n */\n const withReadTransaction =\n (operation: string) =>\n <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E | SqliteStorageError> =>\n Effect.uninterruptibleMask((restore) =>\n Effect.scoped(\n Effect.gen(function* () {\n const connection = yield* sql.reserve.pipe(Effect.mapError(storageError(operation)));\n\n yield* connection\n .executeUnprepared(\"BEGIN\", [], undefined)\n .pipe(Effect.mapError(storageError(operation)));\n\n const exit = yield* restore(\n Effect.provideService(effect, sql.transactionService, [connection, 0] as const),\n ).pipe(Effect.exit);\n\n if (Exit.isSuccess(exit)) {\n yield* connection\n .executeUnprepared(\"COMMIT\", [], undefined)\n .pipe(Effect.mapError(storageError(operation)));\n\n return exit.value;\n }\n yield* Effect.orDie(connection.executeUnprepared(\"ROLLBACK\", [], undefined));\n\n return yield* exit;\n }),\n ).pipe(Effect.withSpan(\"SqliteJournal.withReadTransaction\", { attributes: { operation } })),\n );\n\n const materialize = Effect.fn(\"SqliteJournal.materialize\")(function* (\n threadId: string,\n createdAt: string,\n emptyTailDigest: string,\n producerEpoch: ProducerEpoch,\n ): Effect.fn.Return<\n void,\n SqliteFenceRejected | SqliteStorageCorruptionError | SqliteStorageError | SqliteWriteContention\n > {\n if (\n threadId.length > MAX_IDENTIFIER_LENGTH ||\n storedTextBytes(emptyTailDigest) > MAX_STORED_TEXT_BYTES\n ) {\n return yield* SqliteStorageError.make({\n operation: \"materialize thread\",\n message: \"Thread identity or initial digest exceeds the SQLite storage bounds.\",\n });\n }\n yield* withWriteTransaction(\"materialize transaction\")(\n Effect.gen(function* () {\n const existingRows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n created_at,\n tail_sequence,\n tail_digest,\n producer_epoch\n FROM effect_agent_threads\n WHERE thread_id = ${threadId}\n `.pipe(Effect.mapError(storageError(\"read materialized thread\")));\n\n const existing = yield* decodeRows(\n Schema.Array(ThreadRow),\n \"effect_agent_threads\",\n threadId,\n existingRows,\n );\n\n if (existing.length > 1) {\n return yield* SqliteStorageCorruptionError.make({\n table: \"effect_agent_threads\",\n rowKey: threadId,\n message: \"A thread primary key returned more than one row.\",\n });\n }\n if (existing.length === 0) {\n yield* sql`\n INSERT INTO effect_agent_threads (\n thread_id,\n created_at,\n tail_sequence,\n tail_digest,\n producer_epoch\n ) VALUES (\n ${threadId},\n ${createdAt},\n 0,\n ${emptyTailDigest},\n ${producerEpoch}\n )\n `.pipe(Effect.mapError(storageError(\"materialize thread\")));\n\n return;\n }\n if (producerEpoch < existing[0].producer_epoch) {\n return yield* SqliteFenceRejected.make({\n producerEpoch,\n actualEpoch: existing[0].producer_epoch,\n message: `Producer epoch ${producerEpoch} is stale; current epoch is ${existing[0].producer_epoch}.`,\n });\n }\n if (producerEpoch > existing[0].producer_epoch) {\n yield* sql`\n UPDATE effect_agent_threads\n SET producer_epoch = ${producerEpoch}\n WHERE thread_id = ${threadId}\n `.pipe(Effect.mapError(storageError(\"advance materialization epoch\")));\n }\n }),\n );\n });\n\n const getThread = Effect.fn(\"SqliteJournal.getThread\")(function* (threadId: string) {\n const rows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n created_at,\n tail_sequence,\n tail_digest,\n producer_epoch\n FROM effect_agent_threads\n WHERE thread_id = ${threadId}\n `.pipe(Effect.mapError(storageError(\"read thread\")));\n\n return yield* decodeRows(Schema.Array(ThreadRow), \"effect_agent_threads\", threadId, rows);\n });\n\n const append = Effect.fn(\"SqliteJournal.append\")(function* (\n request: RawAppendRequest,\n ): Effect.fn.Return<RawAppendResult, AppendError> {\n if (\n request.threadId.length > MAX_IDENTIFIER_LENGTH ||\n request.batchId.length > MAX_IDENTIFIER_LENGTH ||\n storedTextBytes(request.batchJson) > MAX_STORED_TEXT_BYTES ||\n storedTextBytes(request.batchDigest) > MAX_STORED_TEXT_BYTES ||\n storedTextBytes(request.tailDigest) > MAX_STORED_TEXT_BYTES ||\n request.records.some(\n (record) =>\n record.recordId.length > MAX_IDENTIFIER_LENGTH ||\n storedTextBytes(record.recordJson) > MAX_STORED_TEXT_BYTES,\n )\n ) {\n return yield* SqliteStorageError.make({\n operation: \"append canonical batch\",\n message: \"Canonical identifiers or encoded JSON exceed the SQLite storage bounds.\",\n });\n }\n\n return yield* withWriteTransaction(\"append transaction\")(\n Effect.gen(function* () {\n const recordIds = request.records.map((record) => record.recordId);\n\n if (new Set(recordIds).size !== recordIds.length) {\n return yield* SqliteAppendConflict.make({\n message: `Batch ${request.batchId} contains duplicate canonical record IDs.`,\n reason: \"record-identity\",\n });\n }\n\n const threadRows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n created_at,\n tail_sequence,\n tail_digest,\n producer_epoch\n FROM effect_agent_threads\n WHERE thread_id = ${request.threadId}\n `.pipe(Effect.mapError(storageError(\"read append tail\")));\n\n const thread = yield* decodeSingleRow(\n Schema.Array(ThreadRow),\n \"effect_agent_threads\",\n request.threadId,\n threadRows,\n );\n\n if (request.producerEpoch !== thread.producer_epoch) {\n return yield* SqliteFenceRejected.make({\n producerEpoch: request.producerEpoch,\n actualEpoch: thread.producer_epoch,\n message: `Producer epoch ${request.producerEpoch} is not the current epoch ${thread.producer_epoch}.`,\n });\n }\n\n const batchRows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n batch_id,\n first_sequence,\n last_sequence,\n batch_digest,\n tail_digest,\n batch_json\n FROM effect_agent_canonical_batches\n WHERE thread_id = ${request.threadId}\n AND batch_id = ${request.batchId}\n `.pipe(Effect.mapError(storageError(\"read idempotent batch\")));\n\n const batches = yield* decodeRows(\n Schema.Array(BatchRow),\n \"effect_agent_canonical_batches\",\n `${request.threadId}/${request.batchId}`,\n batchRows,\n );\n\n if (batches.length > 1) {\n return yield* SqliteStorageCorruptionError.make({\n table: \"effect_agent_canonical_batches\",\n rowKey: `${request.threadId}/${request.batchId}`,\n message: \"A canonical batch primary key returned more than one row.\",\n });\n }\n if (batches.length === 1) {\n const existing = batches[0];\n\n if (existing.batch_digest !== request.batchDigest) {\n return yield* SqliteAppendConflict.make({\n message: `Batch ${request.batchId} already exists with different canonical content.`,\n reason: \"batch-digest\",\n });\n }\n\n return RawAppendResult.make({\n firstSequence: existing.first_sequence,\n lastSequence: existing.last_sequence,\n replayed: true,\n tailDigest: existing.tail_digest,\n });\n }\n\n if (\n request.expectedTailSequence !== thread.tail_sequence ||\n request.expectedTailDigest !== thread.tail_digest\n ) {\n return yield* SqliteAppendConflict.make({\n message:\n `Expected tail ${request.expectedTailSequence}/${request.expectedTailDigest} ` +\n `but found ${thread.tail_sequence}/${thread.tail_digest}.`,\n reason: \"tail\",\n actualTailSequence: thread.tail_sequence,\n actualTailDigest: thread.tail_digest,\n });\n }\n if (thread.tail_sequence + request.records.length > MAX_RECORDS_PER_THREAD) {\n return yield* SqliteStorageError.make({\n operation: \"append canonical batch\",\n message: `Thread record limit ${MAX_RECORDS_PER_THREAD} would be exceeded.`,\n });\n }\n\n const existingRecordRows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n sequence,\n record_id,\n batch_id,\n record_json\n FROM effect_agent_canonical_records\n WHERE thread_id = ${request.threadId}\n AND record_id IN ${sql.in(recordIds)}\n ORDER BY sequence\n `.pipe(Effect.mapError(storageError(\"check canonical record identities\")));\n\n const existingRecords = yield* decodeRows(\n Schema.Array(RecordRow),\n \"effect_agent_canonical_records\",\n `${request.threadId}/record_ids`,\n existingRecordRows,\n );\n\n if (existingRecords.length > 0) {\n return yield* SqliteAppendConflict.make({\n message: `Canonical record ID ${existingRecords[0].record_id} already exists.`,\n reason: \"record-identity\",\n });\n }\n\n const firstSequence = yield* Schema.decodeEffect(CanonicalSequence)(\n thread.tail_sequence + 1,\n ).pipe(\n Effect.mapError((error) =>\n SqliteStorageError.make({\n cause: error,\n operation: \"append canonical batch\",\n message: error.message,\n }),\n ),\n );\n\n const lastSequence = yield* Schema.decodeEffect(CanonicalSequence)(\n firstSequence + request.records.length - 1,\n ).pipe(\n Effect.mapError((error) =>\n SqliteStorageError.make({\n cause: error,\n operation: \"append canonical batch\",\n message: error.message,\n }),\n ),\n );\n\n yield* sql`\n INSERT INTO effect_agent_canonical_batches (\n thread_id,\n batch_id,\n first_sequence,\n last_sequence,\n batch_digest,\n tail_digest,\n batch_json\n ) VALUES (\n ${request.threadId},\n ${request.batchId},\n ${firstSequence},\n ${lastSequence},\n ${request.batchDigest},\n ${request.tailDigest},\n ${request.batchJson}\n )\n `.pipe(Effect.mapError(storageError(\"insert canonical batch\")));\n yield* failpoint(\"append:after-batch-insert\");\n\n yield* Effect.forEach(\n request.records,\n (record, index) =>\n Effect.gen(function* () {\n yield* sql`\n INSERT INTO effect_agent_canonical_records (\n thread_id,\n sequence,\n record_id,\n batch_id,\n record_json\n ) VALUES (\n ${request.threadId},\n ${firstSequence + index},\n ${record.recordId},\n ${request.batchId},\n ${record.recordJson}\n )\n `.pipe(Effect.mapError(storageError(\"insert canonical record\")));\n\n const canonical = yield* Schema.decodeEffect(Schema.fromJsonString(CanonicalRecord))(\n record.recordJson,\n ).pipe(\n Effect.mapError((error) =>\n SqliteStorageCorruptionError.make({\n table: \"effect_agent_canonical_records\",\n rowKey: record.recordId,\n message: error.message,\n }),\n ),\n );\n\n yield* indexCanonicalRecord(request.threadId, canonical).pipe(\n Effect.provideService(SqlClient.SqlClient, sql),\n Effect.mapError(storageError(\"index canonical record\")),\n );\n yield* failpoint(\"append:after-record-insert\");\n }),\n { discard: true },\n );\n\n yield* sql`\n UPDATE effect_agent_threads\n SET\n tail_sequence = ${lastSequence},\n tail_digest = ${request.tailDigest},\n producer_epoch = ${request.producerEpoch}\n WHERE thread_id = ${request.threadId}\n `.pipe(Effect.mapError(storageError(\"advance thread tail\")));\n yield* failpoint(\"append:after-tail-update\");\n\n return RawAppendResult.make({\n firstSequence,\n lastSequence,\n replayed: false,\n tailDigest: request.tailDigest,\n });\n }),\n );\n });\n\n const read = Effect.fn(\"SqliteJournal.read\")(function* (request: RawReadRequest) {\n const rows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n sequence,\n record_id,\n batch_id,\n record_json\n FROM effect_agent_canonical_records\n WHERE thread_id = ${request.threadId}\n AND sequence > ${request.fromSequenceExclusive}\n ORDER BY sequence\n LIMIT ${request.limit}\n `.pipe(Effect.mapError(storageError(\"read canonical records\")));\n\n return yield* decodeRows(\n Schema.Array(RecordRow),\n \"effect_agent_canonical_records\",\n `${request.threadId}>${request.fromSequenceExclusive}`,\n rows,\n );\n });\n\n const exportThread = Effect.fn(\"SqliteJournal.exportThread\")(function* (threadId: string) {\n return yield* withReadTransaction(\"export transaction\")(\n Effect.gen(function* () {\n const threadRows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n created_at,\n tail_sequence,\n tail_digest,\n producer_epoch\n FROM effect_agent_threads\n WHERE thread_id = ${threadId}\n `.pipe(Effect.mapError(storageError(\"export thread\")));\n\n const thread = yield* decodeSingleRow(\n Schema.Array(ThreadRow),\n \"effect_agent_threads\",\n threadId,\n threadRows,\n );\n\n yield* failpoint(\"export:after-thread-read\");\n\n if (thread.tail_sequence > MAX_RECORDS_PER_THREAD)\n return yield* SqliteStorageError.make({\n operation: \"export thread\",\n message: \"The thread exceeds the current export record limit.\",\n });\n const records: Array<RecordRow> = [];\n let afterSequence = ZERO_SEQUENCE;\n\n while (afterSequence < thread.tail_sequence) {\n const limit = Math.min(1_024, thread.tail_sequence - afterSequence);\n\n const request = RawReadRequest.make({\n threadId,\n fromSequenceExclusive: afterSequence,\n limit,\n });\n\n const page = yield* read(request);\n\n if (\n page.length !== limit ||\n page.some((record, index) => record.sequence !== afterSequence + index + 1)\n ) {\n return yield* SqliteStorageCorruptionError.make({\n table: \"effect_agent_canonical_records\",\n rowKey: threadId,\n message: \"The exported canonical prefix is not contiguous through its captured tail.\",\n });\n }\n records.push(...page);\n afterSequence = page[page.length - 1].sequence;\n }\n\n const beyondTail =\n yield* sql`SELECT sequence FROM effect_agent_canonical_records WHERE thread_id=${threadId} AND sequence > ${thread.tail_sequence} LIMIT 1`.pipe(\n Effect.mapError(storageError(\"verify export tail\")),\n );\n\n if (beyondTail.length !== 0)\n return yield* SqliteStorageCorruptionError.make({\n table: \"effect_agent_canonical_records\",\n rowKey: threadId,\n message: \"Canonical records exist beyond the captured thread tail.\",\n });\n\n return RawThreadExport.make({ thread, records });\n }),\n );\n });\n\n const saveCheckpoint = Effect.fn(\"SqliteJournal.saveCheckpoint\")(function* (\n checkpoint: RawCheckpoint,\n ): Effect.fn.Return<void, CheckpointError> {\n if (\n checkpoint.threadId.length > MAX_IDENTIFIER_LENGTH ||\n storedTextBytes(checkpoint.checkpointJson) > MAX_STORED_TEXT_BYTES\n ) {\n return yield* SqliteStorageError.make({\n operation: \"save checkpoint\",\n message: \"Checkpoint identity or encoded JSON exceeds the SQLite storage bounds.\",\n });\n }\n yield* withWriteTransaction(\"checkpoint transaction\")(\n Effect.gen(function* () {\n const threadRows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n created_at,\n tail_sequence,\n tail_digest,\n producer_epoch\n FROM effect_agent_threads\n WHERE thread_id = ${checkpoint.threadId}\n `.pipe(Effect.mapError(storageError(\"read checkpoint tail\")));\n\n const thread = yield* decodeSingleRow(\n Schema.Array(ThreadRow),\n \"effect_agent_threads\",\n checkpoint.threadId,\n threadRows,\n );\n\n if (checkpoint.throughSequence > thread.tail_sequence) {\n return yield* SqliteCheckpointConflict.make({\n message:\n `Checkpoint sequence ${checkpoint.throughSequence} is after canonical tail ` +\n `${thread.tail_sequence}.`,\n });\n }\n\n const checkpointRows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n through_sequence,\n tail_digest,\n checkpoint_json\n FROM effect_agent_checkpoints\n WHERE thread_id = ${checkpoint.threadId}\n AND through_sequence = ${checkpoint.throughSequence}\n `.pipe(Effect.mapError(storageError(\"read idempotent checkpoint\")));\n\n const existing = yield* decodeRows(\n Schema.Array(CheckpointRow),\n \"effect_agent_checkpoints\",\n `${checkpoint.threadId}/${checkpoint.throughSequence}`,\n checkpointRows,\n );\n\n if (existing.length > 1) {\n return yield* SqliteStorageCorruptionError.make({\n table: \"effect_agent_checkpoints\",\n rowKey: `${checkpoint.threadId}/${checkpoint.throughSequence}`,\n message: \"A checkpoint primary key returned more than one row.\",\n });\n }\n if (existing.length === 1) {\n if (\n existing[0].tail_digest !== checkpoint.tailDigest ||\n existing[0].checkpoint_json !== checkpoint.checkpointJson\n ) {\n return yield* SqliteCheckpointConflict.make({\n message: \"A different checkpoint already exists at this canonical sequence.\",\n });\n }\n\n return;\n }\n\n yield* sql`\n INSERT INTO effect_agent_checkpoints (\n thread_id,\n through_sequence,\n tail_digest,\n checkpoint_json\n ) VALUES (\n ${checkpoint.threadId},\n ${checkpoint.throughSequence},\n ${checkpoint.tailDigest},\n ${checkpoint.checkpointJson}\n )\n `.pipe(Effect.mapError(storageError(\"insert checkpoint\")));\n }),\n );\n });\n\n const saveRecoveryCheckpoint = Effect.fn(\"SqliteJournal.saveRecoveryCheckpoint\")(function* (\n request: SaveRecoveryCheckpointRequest,\n checkpointJson: string,\n ) {\n const { checkpoint } = request;\n\n if (\n checkpoint.threadId.length > MAX_IDENTIFIER_LENGTH ||\n storedTextBytes(checkpointJson) > MAX_STORED_TEXT_BYTES\n ) {\n return yield* SqliteStorageError.make({\n operation: \"save recovery checkpoint\",\n message: \"Checkpoint identity or encoded JSON exceeds the SQLite storage bounds.\",\n });\n }\n yield* withWriteTransaction(\"recovery checkpoint transaction\")(\n Effect.gen(function* () {\n const threads = yield* getThread(checkpoint.threadId);\n const thread = threads[0];\n\n if (thread === undefined)\n return yield* ThreadNotMaterialized.make({ threadId: checkpoint.threadId });\n if (request.producerEpoch !== thread.producer_epoch)\n return yield* FenceRejected.make({\n threadId: checkpoint.threadId,\n actualEpoch: thread.producer_epoch,\n attemptedEpoch: request.producerEpoch,\n });\n if (checkpoint.throughSequence > thread.tail_sequence)\n return yield* CheckpointRejected.make({\n threadId: checkpoint.threadId,\n reason: \"ahead-of-tail\",\n });\n\n const digests =\n checkpoint.throughSequence === 0\n ? [EMPTY_TAIL_DIGEST]\n : yield* getTailDigestAt(checkpoint.threadId, checkpoint.throughSequence);\n\n if (digests.length !== 1 || digests[0] !== checkpoint.tailDigest)\n return yield* CheckpointRejected.make({\n threadId: checkpoint.threadId,\n reason: \"digest-mismatch\",\n });\n\n yield* failpoint(\"save-recovery-checkpoint:before\");\n yield* sql`\n INSERT INTO effect_agent_recovery_checkpoints (thread_id, through_sequence, tail_digest, checkpoint_json)\n VALUES (${checkpoint.threadId}, ${checkpoint.throughSequence}, ${checkpoint.tailDigest}, ${checkpointJson})\n ON CONFLICT (thread_id) DO UPDATE SET\n through_sequence = excluded.through_sequence,\n tail_digest = excluded.tail_digest,\n checkpoint_json = excluded.checkpoint_json\n WHERE excluded.through_sequence >= effect_agent_recovery_checkpoints.through_sequence\n `.pipe(Effect.mapError(storageError(\"save recovery checkpoint\")));\n }),\n );\n yield* failpoint(\"save-recovery-checkpoint:after\");\n });\n\n const loadRecoveryCheckpoint = Effect.fn(\"SqliteJournal.loadRecoveryCheckpoint\")(function* (\n threadId: string,\n ) {\n const rows = yield* sql<Record<string, unknown>>`\n SELECT thread_id, through_sequence, tail_digest, checkpoint_json\n FROM effect_agent_recovery_checkpoints\n WHERE thread_id = ${threadId}\n `.pipe(Effect.mapError(storageError(\"load recovery checkpoint\")));\n\n return yield* decodeRows(\n Schema.Array(CheckpointRow),\n \"effect_agent_recovery_checkpoints\",\n threadId,\n rows,\n );\n });\n\n const loadCheckpoint = Effect.fn(\"SqliteJournal.loadCheckpoint\")(function* (\n threadId: string,\n atOrBeforeSequence: CanonicalSequence,\n ) {\n const rows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n through_sequence,\n tail_digest,\n checkpoint_json\n FROM effect_agent_checkpoints\n WHERE thread_id = ${threadId}\n AND through_sequence <= ${atOrBeforeSequence}\n ORDER BY through_sequence DESC\n LIMIT 1\n `.pipe(Effect.mapError(storageError(\"load checkpoint\")));\n\n return yield* decodeRows(\n Schema.Array(CheckpointRow),\n \"effect_agent_checkpoints\",\n `${threadId}<=${atOrBeforeSequence}`,\n rows,\n );\n });\n\n const getTailDigestAt = Effect.fn(\"SqliteJournal.getTailDigestAt\")(function* (\n threadId: string,\n sequence: CanonicalSequence,\n ) {\n if (sequence === 0) {\n const threads = yield* getThread(threadId);\n\n return threads.length === 0\n ? []\n : [threads[0].tail_sequence === 0 ? threads[0].tail_digest : undefined].filter(\n (value): value is string => value !== undefined,\n );\n }\n\n const rows = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n batch_id,\n first_sequence,\n last_sequence,\n batch_digest,\n tail_digest,\n batch_json\n FROM effect_agent_canonical_batches\n WHERE thread_id = ${threadId}\n AND last_sequence = ${sequence}\n `.pipe(Effect.mapError(storageError(\"read canonical digest at sequence\")));\n\n const batches = yield* decodeRows(\n Schema.Array(BatchRow),\n \"effect_agent_canonical_batches\",\n `${threadId}/${sequence}`,\n rows,\n );\n\n return batches.map((batch) => batch.tail_digest);\n });\n\n const scanStoredPayloads = Effect.fn(\"SqliteJournal.scanStoredPayloads\")(function* () {\n return yield* withReadTransaction(\"startup scan transaction\")(\n Effect.gen(function* () {\n const threads = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n created_at,\n tail_sequence,\n tail_digest,\n producer_epoch\n FROM effect_agent_threads\n ORDER BY thread_id\n `.pipe(Effect.mapError(storageError(\"scan threads\")));\n\n const batches = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n batch_id,\n first_sequence,\n last_sequence,\n batch_digest,\n tail_digest,\n batch_json\n FROM effect_agent_canonical_batches\n ORDER BY thread_id, first_sequence\n `.pipe(Effect.mapError(storageError(\"scan canonical batches\")));\n\n const records = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n sequence,\n record_id,\n batch_id,\n record_json\n FROM effect_agent_canonical_records\n ORDER BY thread_id, sequence\n `.pipe(Effect.mapError(storageError(\"scan canonical records\")));\n\n const checkpoints = yield* sql<Record<string, unknown>>`\n SELECT\n thread_id,\n through_sequence,\n tail_digest,\n checkpoint_json\n FROM effect_agent_checkpoints\n ORDER BY thread_id, through_sequence\n `.pipe(Effect.mapError(storageError(\"scan checkpoints\")));\n\n return {\n threads: yield* decodeRows(\n Schema.Array(ThreadRow),\n \"effect_agent_threads\",\n \"startup_scan\",\n threads,\n ),\n batches: yield* decodeRows(\n Schema.Array(BatchRow),\n \"effect_agent_canonical_batches\",\n \"startup_scan\",\n batches,\n ),\n records: yield* decodeRows(\n Schema.Array(RecordRow),\n \"effect_agent_canonical_records\",\n \"startup_scan\",\n records,\n ),\n checkpoints: yield* decodeRows(\n Schema.Array(CheckpointRow),\n \"effect_agent_checkpoints\",\n \"startup_scan\",\n checkpoints,\n ),\n };\n }),\n );\n });\n\n return {\n append,\n exportThread,\n getThread,\n getTailDigestAt,\n loadCheckpoint,\n loadRecoveryCheckpoint,\n saveRecoveryCheckpoint,\n materialize,\n read,\n saveCheckpoint,\n scanStoredPayloads,\n withWriteTransaction,\n withReadTransaction,\n } as const;\n});\n\nexport type SqliteJournal = Effect.Success<ReturnType<typeof initializeSqliteJournal>>;\n"],"mappings":";;;;;;;;;;;;;;;;;AAkDA,MAAM,oBAAoB,OAAO,OAAO,MAAM,OAAO,YAAY,QAAgB,CAAC;AAClF,MAAM,oBAAoB,OAAO,eAAe,MAAM,OAAO,YAAY,IAAI,CAAC;AAC9E,MAAM,iBAAiB,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,yBAAyB;AAC/B,MAAM,gBAAgB,OAAO,WAAW,iBAAiB,CAAC,CAAC,CAAC;AAC5D,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAE9B,MAAM,mBAAmB,UAA0B,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,CAAC,CA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,IACzB,OAAO,KACL,6BAA6B,KAAK;CAChC;CACA;CACA,SAAS,sCAAsC,QAAQ,OAAO;AAChE,CAAC,CACH,CACN,CACF,CACJ;;AAGA,MAAM,qBAAqB;CACzB,sBAAsB;EACpB;EACA;EACA;EACA;EACA;CACF;CACA,gCAAgC;EAC9B;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,gCAAgC;EAAC;EAAa;EAAY;EAAa;EAAY;CAAa;CAChG,0BAA0B;EAAC;EAAa;EAAoB;EAAe;CAAiB;CAC5F,0BAA0B;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,mCAAmC;EACjC;EACA;EACA;EACA;EACA;EACA;CACF;CACA,uBAAuB;EACrB;EACA;EACA;EACA;EACA;EACA;CACF;CACA,sCAAsC;EACpC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,4BAA4B;EAC1B;EACA;EACA;EACA;EACA;CACF;CACA,iCAAiC;EAC/B;EACA;EACA;EACA;EACA;EACA;CACF;CACA,kCAAkC;EAChC;EACA;EACA;EACA;EACA;EACA;CACF;CACA,iCAAiC;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,wBAAwB;EACtB;EACA;EACA;EACA;EACA;CACF;CACA,qCAAqC;EACnC;EACA;EACA;EACA;EACA;EACA;CACF;CACA,4BAA4B;EAC1B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,kCAAkC;EAChC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,sCAAsC;EACpC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAEA,MAAM,yBAAyB,OAAO,GAAG,sCAAsC,CAAC,CAAC,WAC/E,SACA;CAC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E1D,OAAO;KACL,SAAS,OAAO,WACd,OAAO,MAAM,SAAS,GACtB,wBACA,gBACA,OACF;KACA,SAAS,OAAO,WACd,OAAO,MAAM,QAAQ,GACrB,kCACA,gBACA,OACF;KACA,SAAS,OAAO,WACd,OAAO,MAAM,SAAS,GACtB,kCACA,gBACA,OACF;KACA,aAAa,OAAO,WAClB,OAAO,MAAM,aAAa,GAC1B,4BACA,gBACA,WACF;IACF;GACF,CAAC,CACH;EACF,CAamB;EACjB;EACA;CACF;AACF,CAAC"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@effect-agent/storage-sqlite","version":"0.1.0-beta.114","dependencies":{"@effect/platform-node":"4.0.0-rc.116","@effect/sql-sqlite-node":"4.0.0-rc.116","effect-agent":"0.1.0-beta.114"},"devDependencies":{"@effect/vitest":"4.0.0-rc.116","effect":"4.0.0-rc.116","typescript":"7.0.2","vite-plus":"0.3.2"},"peerDependencies":{"effect":"^4.0.0-rc.116"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./sqlite-activity-store":{"types":"./dist/SqliteActivityStore.d.mts","default":"./dist/SqliteActivityStore.mjs"},"./sqlite-schedule-store":{"types":"./dist/SqliteScheduleStore.d.mts","default":"./dist/SqliteScheduleStore.mjs"},"./sqlite-storage-config":{"types":"./dist/SqliteStorageConfig.d.mts","default":"./dist/SqliteStorageConfig.mjs"},"./sqlite-storage-error":{"types":"./dist/SqliteStorageError.d.mts","default":"./dist/SqliteStorageError.mjs"},"./sqlite-storage-failpoint":{"types":"./dist/SqliteStorageFailpoint.d.mts","default":"./dist/SqliteStorageFailpoint.mjs"},"./sqlite-storage-version":{"types":"./dist/SqliteStorageVersion.d.mts","default":"./dist/SqliteStorageVersion.mjs"},"./sqlite-submission-ledger":{"types":"./dist/SqliteSubmissionLedger.d.mts","default":"./dist/SqliteSubmissionLedger.mjs"},"./sqlite-subscription-store":{"types":"./dist/SqliteSubscriptionStore.d.mts","default":"./dist/SqliteSubscriptionStore.mjs"},"./sqlite-thread-store":{"types":"./dist/SqliteThreadStore.d.mts","default":"./dist/SqliteThreadStore.mjs"},"./testing/sqlite-storage-failpoint-testing":{"types":"./dist/SqliteStorageFailpointTesting.d.mts","default":"./dist/SqliteStorageFailpointTesting.mjs"},"./sqlite-message-delivery-store":{"types":"./dist/SqliteMessageDeliveryStore.d.mts","default":"./dist/SqliteMessageDeliveryStore.mjs"}},"description":"Node SQLite persistence adapters for the Effect Agent durable runtime and optional memory lifecycle.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/storage-sqlite"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
1
+ {"name":"@effect-agent/storage-sqlite","version":"0.1.0-beta.115","dependencies":{"@effect/platform-node":"4.0.0-rc.116","@effect/sql-sqlite-node":"4.0.0-rc.116","effect-agent":"0.1.0-beta.115"},"devDependencies":{"@effect/vitest":"4.0.0-rc.116","effect":"4.0.0-rc.116","typescript":"7.0.2","vite-plus":"0.3.2"},"peerDependencies":{"effect":"^4.0.0-rc.116"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./sqlite-activity-store":{"types":"./dist/SqliteActivityStore.d.mts","default":"./dist/SqliteActivityStore.mjs"},"./sqlite-schedule-store":{"types":"./dist/SqliteScheduleStore.d.mts","default":"./dist/SqliteScheduleStore.mjs"},"./sqlite-storage-config":{"types":"./dist/SqliteStorageConfig.d.mts","default":"./dist/SqliteStorageConfig.mjs"},"./sqlite-storage-error":{"types":"./dist/SqliteStorageError.d.mts","default":"./dist/SqliteStorageError.mjs"},"./sqlite-storage-failpoint":{"types":"./dist/SqliteStorageFailpoint.d.mts","default":"./dist/SqliteStorageFailpoint.mjs"},"./sqlite-storage-version":{"types":"./dist/SqliteStorageVersion.d.mts","default":"./dist/SqliteStorageVersion.mjs"},"./sqlite-submission-ledger":{"types":"./dist/SqliteSubmissionLedger.d.mts","default":"./dist/SqliteSubmissionLedger.mjs"},"./sqlite-subscription-store":{"types":"./dist/SqliteSubscriptionStore.d.mts","default":"./dist/SqliteSubscriptionStore.mjs"},"./sqlite-thread-store":{"types":"./dist/SqliteThreadStore.d.mts","default":"./dist/SqliteThreadStore.mjs"},"./testing/sqlite-storage-failpoint-testing":{"types":"./dist/SqliteStorageFailpointTesting.d.mts","default":"./dist/SqliteStorageFailpointTesting.mjs"},"./sqlite-message-delivery-store":{"types":"./dist/SqliteMessageDeliveryStore.d.mts","default":"./dist/SqliteMessageDeliveryStore.mjs"}},"description":"Node SQLite persistence adapters for the Effect Agent durable runtime and optional memory lifecycle.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/storage-sqlite"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}