@sentropic/cluster-mesh 0.19.1 → 0.20.0

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.
Files changed (36) hide show
  1. package/dist/modules/catalog.js +1 -1
  2. package/dist/storage/instance-ownership.d.ts +30 -0
  3. package/dist/storage/instance-ownership.d.ts.map +1 -0
  4. package/dist/storage/instance-ownership.js +90 -0
  5. package/dist/storage/instance-ownership.js.map +1 -0
  6. package/dist/storage/postgres/ordinary-transactions.d.ts.map +1 -1
  7. package/dist/storage/postgres/ordinary-transactions.js +2 -0
  8. package/dist/storage/postgres/ordinary-transactions.js.map +1 -1
  9. package/dist/storage/postgres/protocol.d.ts +7 -0
  10. package/dist/storage/postgres/protocol.d.ts.map +1 -1
  11. package/dist/storage/postgres/protocol.js.map +1 -1
  12. package/dist/storage/sqlite/backend.d.ts +38 -0
  13. package/dist/storage/sqlite/backend.d.ts.map +1 -0
  14. package/dist/storage/sqlite/backend.js +159 -0
  15. package/dist/storage/sqlite/backend.js.map +1 -0
  16. package/dist/storage/sqlite/connection.d.ts +11 -0
  17. package/dist/storage/sqlite/connection.d.ts.map +1 -0
  18. package/dist/storage/sqlite/connection.js +108 -0
  19. package/dist/storage/sqlite/connection.js.map +1 -0
  20. package/dist/storage/sqlite/engine.d.ts +44 -0
  21. package/dist/storage/sqlite/engine.d.ts.map +1 -0
  22. package/dist/storage/sqlite/engine.js +262 -0
  23. package/dist/storage/sqlite/engine.js.map +1 -0
  24. package/dist/storage/sqlite/index.d.ts +28 -0
  25. package/dist/storage/sqlite/index.d.ts.map +1 -0
  26. package/dist/storage/sqlite/index.js +161 -0
  27. package/dist/storage/sqlite/index.js.map +1 -0
  28. package/dist/storage/sqlite/owner-source.d.ts +2 -0
  29. package/dist/storage/sqlite/owner-source.d.ts.map +1 -0
  30. package/dist/storage/sqlite/owner-source.js +52 -0
  31. package/dist/storage/sqlite/owner-source.js.map +1 -0
  32. package/dist/storage/sqlite/transaction-port.d.ts +6 -0
  33. package/dist/storage/sqlite/transaction-port.d.ts.map +1 -0
  34. package/dist/storage/sqlite/transaction-port.js +27 -0
  35. package/dist/storage/sqlite/transaction-port.js.map +1 -0
  36. package/package.json +5 -1
@@ -0,0 +1,44 @@
1
+ import { type SqliteConnection } from './connection.js';
2
+ import { CanonicalInstanceRegistry, type CanonicalInstanceHandle } from '../instance-ownership.js';
3
+ export declare const SQLITE_MIN_ENGINE = "3.51.3";
4
+ export declare const SQLITE_SCHEMA_VERSION = "1";
5
+ export interface SqliteBackportQualification {
6
+ readonly version: string;
7
+ readonly imageDigest: string;
8
+ readonly note: string;
9
+ }
10
+ export interface SqliteOpenOptions {
11
+ readonly path: string;
12
+ readonly storeKey?: string;
13
+ readonly instanceId?: string;
14
+ readonly registry?: CanonicalInstanceRegistry;
15
+ readonly qualifiedBackport?: SqliteBackportQualification;
16
+ /** Owning module: persisted at creation and validated on every reopen so
17
+ * an existing file is never reinterpreted under another module. */
18
+ readonly moduleId?: string;
19
+ }
20
+ export interface SqliteOpenReceipt {
21
+ readonly ownerPid: number;
22
+ readonly isolation: 'process';
23
+ readonly nodeVersion: string;
24
+ readonly engineVersion: string;
25
+ readonly realPath: string;
26
+ readonly journalMode: string;
27
+ readonly synchronous: string;
28
+ readonly lockingMode: string;
29
+ readonly instanceId: string;
30
+ readonly storageEpoch: string;
31
+ readonly schemaVersion: string;
32
+ readonly openedAt: string;
33
+ /** The qualified Linux tuple verifies the isolated owner's kernel lock. */
34
+ readonly lockLiveness: 'procfs';
35
+ }
36
+ export interface SqliteEngine {
37
+ readonly db: SqliteConnection;
38
+ readonly handle: CanonicalInstanceHandle;
39
+ readonly receipt: SqliteOpenReceipt;
40
+ assertOwnership(): void;
41
+ close(): void;
42
+ }
43
+ export declare const openSqliteEngine: (options: SqliteOpenOptions) => SqliteEngine;
44
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/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IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC;CACjC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,gBAAgB,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,eAAe,IAAI,IAAI,CAAC;IACxB,KAAK,IAAI,IAAI,CAAC;CACf;AAqFD,eAAO,MAAM,gBAAgB,YAAa,iBAAiB,KAAG,YAiI7D,CAAC"}
@@ -0,0 +1,262 @@
1
+ // SQLite open guard and G3 ownership engine (lot 1). node:sqlite only.
2
+ // The engine check runs before WAL; effective parameters are read back,
3
+ // never assumed from the requested setting.
4
+ import { randomUUID } from 'node:crypto';
5
+ import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
6
+ import { basename, dirname, resolve } from 'node:path';
7
+ import { openIsolatedConnection } from './connection.js';
8
+ import { CanonicalInstanceRegistry, CanonicalOwnershipError } from '../instance-ownership.js';
9
+ export const SQLITE_MIN_ENGINE = '3.51.3';
10
+ export const SQLITE_SCHEMA_VERSION = '1';
11
+ const parseEngine = (version) => {
12
+ const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
13
+ if (!match)
14
+ throw new CanonicalOwnershipError('open-refused', `unreadable SQLite engine version: ${version}`);
15
+ return [Number(match[1]), Number(match[2]), Number(match[3])];
16
+ };
17
+ const engineAtLeast = (version, floor) => {
18
+ const [a, b, c] = parseEngine(version);
19
+ const [x, y, z] = parseEngine(floor);
20
+ return a !== x ? a > x : b !== y ? b > y : c >= z;
21
+ };
22
+ // Process-wide open registry, keyed by canonical path. POSIX locks do not
23
+ // exclude two opens from the same process, so SQLite alone cannot refuse a
24
+ // second live holder here; cross-process exclusion stays with EXCLUSIVE.
25
+ // Entries from another pid are fork copies and are superseded.
26
+ const OPEN_ENGINES = new Map();
27
+ const canonicalPathOf = (path) => {
28
+ const resolved = resolve(path);
29
+ try {
30
+ return realpathSync(resolved);
31
+ }
32
+ catch {
33
+ try {
34
+ return `${realpathSync(dirname(resolved))}/${basename(resolved)}`;
35
+ }
36
+ catch {
37
+ throw new CanonicalOwnershipError('open-refused', `SQLite parent directory is not usable: ${path}`);
38
+ }
39
+ }
40
+ };
41
+ const isBusyError = (error) => /busy|locked/i.test(error?.message ?? '');
42
+ const storeFileIdentityOf = (path) => {
43
+ try {
44
+ const identity = statSync(path);
45
+ return { dev: identity.dev, ino: identity.ino, nlink: identity.nlink };
46
+ }
47
+ catch {
48
+ throw new CanonicalOwnershipError('terminal-loss', `SQLite store file is not usable: ${path}`);
49
+ }
50
+ };
51
+ // Kernel lock liveness without touching the database file: reading
52
+ // /proc/locks opens procfs only, never the store, so the probe cannot
53
+ // disturb the POSIX locks it verifies. SQLite keeps a WRITE lock on the
54
+ // store inode while EXCLUSIVE is held; a foreign close of another fd on
55
+ // the same inode drops every POSIX lock of this process, and the
56
+ // connection would otherwise keep serving cached state.
57
+ const lockLineFor = (line, pid, ino) => {
58
+ const fields = line.trim().split(/\s+/);
59
+ if (fields.length < 7 || fields[4] !== String(pid))
60
+ return false;
61
+ const target = (fields[5] ?? '').split(':');
62
+ if (target.length !== 3 || target[2] !== String(ino))
63
+ return false;
64
+ return fields[3] === 'WRITE' || fields[3] === 'RW';
65
+ };
66
+ const holdsPosixWriteLock = (locks, pid, ino) => locks.split('\n').some((line) => lockLineFor(line, pid, ino));
67
+ const readPragma = (db, name) => {
68
+ const row = db.prepare(`PRAGMA ${name}`).get();
69
+ const value = row === undefined ? undefined : row[name.toLowerCase()] ?? Object.values(row)[0];
70
+ return String(value);
71
+ };
72
+ const SQLITE_MODULE_KEY = 'sqlite_module_id';
73
+ const gateModuleIdentity = (db, moduleId) => {
74
+ if (moduleId === undefined)
75
+ return;
76
+ if (moduleId.length === 0)
77
+ throw new CanonicalOwnershipError('open-refused', 'sqlite open requires a non-empty moduleId');
78
+ const row = db.prepare('SELECT value FROM cm_meta WHERE key = ?').get(SQLITE_MODULE_KEY);
79
+ if (row !== undefined) {
80
+ if (row.value !== moduleId) {
81
+ throw new CanonicalOwnershipError('open-refused', `SQLite store owned by module ${row.value}: refused for ${moduleId}`);
82
+ }
83
+ return;
84
+ }
85
+ const scopesTable = db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'cm_scopes'").get();
86
+ const populated = scopesTable !== undefined &&
87
+ db.prepare('SELECT COUNT(*) AS count FROM cm_scopes').get().count > 0;
88
+ if (populated)
89
+ throw new CanonicalOwnershipError('open-refused', 'SQLite store has state without a recorded owning module');
90
+ db.prepare('INSERT INTO cm_meta(key, value) VALUES(?, ?)').run(SQLITE_MODULE_KEY, moduleId);
91
+ };
92
+ export const openSqliteEngine = (options) => {
93
+ if (process.platform !== 'linux') {
94
+ throw new CanonicalOwnershipError('open-refused', 'SQLite ownership requires the qualified Linux process-isolation tuple');
95
+ }
96
+ if (typeof options.path !== 'string' || options.path.length === 0 || options.path === ':memory:') {
97
+ throw new CanonicalOwnershipError('open-refused', 'durable SQLite storage requires a file path');
98
+ }
99
+ const registry = options.registry ?? new CanonicalInstanceRegistry();
100
+ const storeKey = options.storeKey ?? `sqlite:${options.path}`;
101
+ const canonicalPath = canonicalPathOf(options.path);
102
+ if (existsSync(canonicalPath) && statSync(canonicalPath).nlink !== 1) {
103
+ throw new CanonicalOwnershipError('open-refused', 'SQLite hard-link aliases are not qualified');
104
+ }
105
+ if (OPEN_ENGINES.get(canonicalPath) === process.pid) {
106
+ throw new CanonicalOwnershipError('instance-busy', `SQLite store already open in this process: ${canonicalPath}`);
107
+ }
108
+ OPEN_ENGINES.set(canonicalPath, process.pid);
109
+ let db;
110
+ try {
111
+ db = openIsolatedConnection(canonicalPath);
112
+ }
113
+ catch (error) {
114
+ OPEN_ENGINES.delete(canonicalPath);
115
+ throw error;
116
+ }
117
+ try {
118
+ let engineVersion;
119
+ let journalMode;
120
+ let lockingMode;
121
+ try {
122
+ db.exec('PRAGMA busy_timeout = 0');
123
+ engineVersion = String(db.prepare('SELECT sqlite_version() AS version').get().version);
124
+ const qualified = engineAtLeast(engineVersion, SQLITE_MIN_ENGINE) ||
125
+ (options.qualifiedBackport !== undefined &&
126
+ options.qualifiedBackport.version === engineVersion &&
127
+ options.qualifiedBackport.imageDigest.length > 0 &&
128
+ options.qualifiedBackport.note.length > 0);
129
+ if (!qualified)
130
+ throw new CanonicalOwnershipError('open-refused', `refused engine ${engineVersion}: minimum is ${SQLITE_MIN_ENGINE}`);
131
+ db.exec('PRAGMA locking_mode = EXCLUSIVE');
132
+ db.exec('PRAGMA journal_mode = WAL');
133
+ db.exec('PRAGMA synchronous = FULL');
134
+ journalMode = readPragma(db, 'journal_mode');
135
+ const synchronous = readPragma(db, 'synchronous');
136
+ lockingMode = readPragma(db, 'locking_mode');
137
+ if (journalMode.toLowerCase() !== 'wal')
138
+ throw new CanonicalOwnershipError('open-refused', `WAL not effective: ${journalMode}`);
139
+ if (synchronous !== '2')
140
+ throw new CanonicalOwnershipError('open-refused', `FULL not effective: ${synchronous}`);
141
+ if (lockingMode.toLowerCase() !== 'exclusive')
142
+ throw new CanonicalOwnershipError('open-refused', `EXCLUSIVE not effective: ${lockingMode}`);
143
+ db.exec('CREATE TABLE IF NOT EXISTS cm_meta(key TEXT PRIMARY KEY, value TEXT NOT NULL)');
144
+ db.exec('CREATE TABLE IF NOT EXISTS cm_ownership(id INTEGER PRIMARY KEY CHECK(id = 1), instance_id TEXT NOT NULL, epoch TEXT NOT NULL)');
145
+ gateModuleIdentity(db, options.moduleId);
146
+ }
147
+ catch (error) {
148
+ if (error instanceof CanonicalOwnershipError)
149
+ throw error;
150
+ if (isBusyError(error))
151
+ throw new CanonicalOwnershipError('instance-busy', `live holder present: ${error.message}`);
152
+ throw error;
153
+ }
154
+ let won;
155
+ try {
156
+ db.exec('BEGIN IMMEDIATE');
157
+ }
158
+ catch (error) {
159
+ if (isBusyError(error))
160
+ throw new CanonicalOwnershipError('instance-busy', `live holder present: ${error.message}`);
161
+ throw error;
162
+ }
163
+ try {
164
+ const row = db.prepare('SELECT instance_id AS instanceId, epoch FROM cm_ownership WHERE id = 1').get();
165
+ won = row === undefined
166
+ ? { instanceId: options.instanceId ?? `instance-${randomUUID()}`, epoch: 1 }
167
+ : { instanceId: options.instanceId ?? String(row.instanceId), epoch: Number(row.epoch) + 1 };
168
+ db.prepare('INSERT INTO cm_ownership(id, instance_id, epoch) VALUES(1, ?, ?) ON CONFLICT(id) DO UPDATE SET instance_id = excluded.instance_id, epoch = excluded.epoch').run(won.instanceId, String(won.epoch));
169
+ db.prepare("INSERT INTO cm_meta(key, value) VALUES('schema_version', ?) ON CONFLICT(key) DO NOTHING").run(SQLITE_SCHEMA_VERSION);
170
+ db.exec('COMMIT');
171
+ }
172
+ catch (error) {
173
+ try {
174
+ db.exec('ROLLBACK');
175
+ }
176
+ catch { /* already rolled back */ }
177
+ throw error;
178
+ }
179
+ let handle;
180
+ try {
181
+ handle = registry.acquire(storeKey, String(won.epoch));
182
+ }
183
+ catch (error) {
184
+ db.close();
185
+ throw error;
186
+ }
187
+ if (handle.instanceId !== won.instanceId) {
188
+ db.prepare('UPDATE cm_ownership SET instance_id = ? WHERE id = 1').run(handle.instanceId);
189
+ won = { instanceId: handle.instanceId, epoch: won.epoch };
190
+ }
191
+ const lockLiveness = 'procfs';
192
+ const fileId = storeFileIdentityOf(canonicalPath);
193
+ const receipt = Object.freeze({ ownerPid: db.ownerPid, isolation: 'process', nodeVersion: process.version, engineVersion,
194
+ realPath: canonicalPath, journalMode: journalMode.toLowerCase(), synchronous: 'FULL',
195
+ lockingMode: lockingMode.toLowerCase(), instanceId: won.instanceId, storageEpoch: String(won.epoch),
196
+ schemaVersion: SQLITE_SCHEMA_VERSION, openedAt: new Date().toISOString(), lockLiveness });
197
+ let closed = false;
198
+ const assertOwnership = () => {
199
+ if (closed)
200
+ throw new CanonicalOwnershipError('terminal-loss', 'sqlite engine is closed');
201
+ // File identity first: a replace/rename invalidates every cached read.
202
+ let identity;
203
+ try {
204
+ identity = storeFileIdentityOf(canonicalPath);
205
+ }
206
+ catch (error) {
207
+ registry.markTerminal(handle);
208
+ throw error;
209
+ }
210
+ if (identity.dev !== fileId.dev || identity.ino !== fileId.ino || identity.nlink !== 1) {
211
+ registry.markTerminal(handle);
212
+ throw new CanonicalOwnershipError('terminal-loss', 'ownership lost: store file was replaced');
213
+ }
214
+ // Kernel lock liveness before trusting the connection's cached state:
215
+ // a foreign close drops the POSIX lock while SQLite still believes it
216
+ // holds EXCLUSIVE. stat/procs reads never open the store file.
217
+ if (lockLiveness === 'procfs') {
218
+ let locks = null;
219
+ try {
220
+ locks = readFileSync('/proc/locks', 'utf8');
221
+ }
222
+ catch {
223
+ locks = null;
224
+ }
225
+ if (locks === null || !holdsPosixWriteLock(locks, db.ownerPid, fileId.ino)) {
226
+ registry.markTerminal(handle);
227
+ throw new CanonicalOwnershipError('terminal-loss', 'ownership lost: POSIX lock is no longer held');
228
+ }
229
+ }
230
+ const current = db.prepare('SELECT instance_id AS instanceId, epoch FROM cm_ownership WHERE id = 1').get();
231
+ if (current?.instanceId !== won.instanceId || current?.epoch !== String(won.epoch)) {
232
+ registry.markTerminal(handle);
233
+ throw new CanonicalOwnershipError('terminal-loss', 'ownership lost: epoch superseded');
234
+ }
235
+ registry.verify(handle);
236
+ };
237
+ return {
238
+ db,
239
+ handle,
240
+ receipt,
241
+ assertOwnership,
242
+ close: () => {
243
+ if (closed)
244
+ return;
245
+ closed = true;
246
+ registry.release(handle);
247
+ OPEN_ENGINES.delete(canonicalPath);
248
+ db.close();
249
+ },
250
+ };
251
+ }
252
+ catch (error) {
253
+ if (OPEN_ENGINES.get(canonicalPath) === process.pid)
254
+ OPEN_ENGINES.delete(canonicalPath);
255
+ try {
256
+ db.close();
257
+ }
258
+ catch { /* close best effort */ }
259
+ thro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AE,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,OAAO,CAAC,GAAG;YAAE,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACxF,IAAI,CAAC;YAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC;QACrD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { ScopeGrant } from '../authority.js';
2
+ import type { ProfileClaim } from '../profiles.js';
3
+ import { type StagedKernelOptions, type StagedKernelRoot } from '../staged-factory.js';
4
+ import { CANONICAL_INSTANCE_OWNERSHIP_CONTRACT, CanonicalInstanceRegistry } from '../instance-ownership.js';
5
+ import { type SqliteEngine, type SqliteOpenOptions } from './engine.js';
6
+ import { SqliteStateBackend } from './backend.js';
7
+ export declare const sqliteProfileClaims: (module: string, resync: boolean) => readonly ProfileClaim[];
8
+ export interface SqliteKernelOptions extends Omit<StagedKernelOptions, 'backend' | 'coordinator' | 'moduleId'> {
9
+ readonly path: string;
10
+ readonly moduleId: string;
11
+ readonly open?: Omit<SqliteOpenOptions, 'path'>;
12
+ }
13
+ export interface SqliteKernel {
14
+ readonly engine: SqliteEngine;
15
+ readonly backend: SqliteStateBackend;
16
+ readonly moduleId: string;
17
+ readonly incarnation: string;
18
+ readonly ownershipContract: typeof CANONICAL_INSTANCE_OWNERSHIP_CONTRACT;
19
+ bind(grant: ScopeGrant<unknown>): unknown;
20
+ bindNew(grant: ScopeGrant<unknown>): unknown;
21
+ revoke(token: string): void | Promise<void>;
22
+ provisionFence(...args: Parameters<StagedKernelRoot['provisionFence']>): unknown;
23
+ profiles(resync: boolean): readonly ProfileClaim[];
24
+ close(): void;
25
+ }
26
+ export declare const createSqliteKernel: (options: SqliteKernelOptions) => SqliteKernel;
27
+ export { CanonicalInstanceRegistry };
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKlD,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,gBAAgB,CAAC;AAG9D,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qCAAqC,EACrC,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAoB,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AA+ClD,eAAO,MAAM,mBAAmB,WAAY,MAAM,UAAU,OAAO,KAAG,SAAS,YAAY,EAQxF,CAAC;AAuEJ,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,aAAa,GAAG,UAAU,CAAC;IAC5G,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,OAAO,qCAAqC,CAAC;IACzE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC1C,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC7C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,cAAc,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,GAAG,OAAO,CAAC;IACjF,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,YAAY,EAAE,CAAC;IACnD,KAAK,IAAI,IAAI,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,YAAa,mBAAmB,KAAG,YAsCjE,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -0,0 +1,161 @@
1
+ // @sentropic/cluster-mesh/storage/sqlite — durable node:sqlite backend.
2
+ // Lot 1 boundary: committed ordinary state persists per mutation in one
3
+ // SQLite transaction that re-verifies ownership before COMMIT. Staged
4
+ // attachment, boundary manifests, journal lanes, consumers and grant
5
+ // issuance stay session-local: reopening replays ordinary reads and commits, while
6
+ // staged-family calls on a reloaded populated scope refuse loudly until
7
+ // restart recovery lands. No Python, no addon, no helper binary.
8
+ import { createHash } from 'node:crypto';
9
+ import { StorageInvalidCommandError, UnsupportedProfileError } from '../errors.js';
10
+ import { CanonicalOwnershipError } from '../instance-ownership.js';
11
+ import { createKernel } from '../kernel.js';
12
+ import { rootCapability } from '../root-profiles.js';
13
+ import { createRootStagedKernel, } from '../staged-factory.js';
14
+ import { CANONICAL_INSTANCE_OWNERSHIP_CONTRACT, CanonicalInstanceRegistry, } from '../instance-ownership.js';
15
+ import { openSqliteEngine } from './engine.js';
16
+ import { SqliteStateBackend } from './backend.js';
17
+ import { withSqliteTransaction } from './transaction-port.js';
18
+ const SQLITE_MEANINGS = {
19
+ 'atomic-units-v1': 'owned bounded plans;single-writer sequential transactions;one root CAS;durable complete receipts;immutable flush retries only',
20
+ 'immutable-chains-v1': 'canonical byte payloads;per-chain allocation;ordered head CAS;retained identities',
21
+ 'immutable-boundaries-v1': 'exact head sequence allocation HMAC;owner scope incarnation root manifests;current coverage;no TTL;full page envelopes',
22
+ 'scope-outbox-v1': 'one committed segment in selected log;same-session append replay;contiguous fenced checkpoints;registered snapshot resync;poison retained',
23
+ 'visibility-barriers-v1': 'persistent ancestry;atomic barrier and content publication;current getter/page denial;covered reparenting refused',
24
+ 'staged-units-v1': 'comments framed SHA256 v1;owned ordinals and authenticated owner capabilities;portable bounded preparation;frozen root CAS;terminal recovery',
25
+ 'fenced-writers-v1': 'durable owner epoch incarnation lanes;host-clock leases;post-wait gate checks;explicit recovery and rotation',
26
+ 'purge-jobs-v1': 'durable bounded jobs;holds and shared references;canonical bytes and staged-item erasure;one verified outcome and notification;no archive restore claim',
27
+ };
28
+ // Lot 1 restart-durable subset: only state inside the persisted scope
29
+ // snapshot (records, chains/heads, index, aggregates, idempotency commits)
30
+ // survives close/reopen. Staged attachment, journal lanes, consumers,
31
+ // barriers, fences, purge jobs and boundary manifests stay session-local,
32
+ // so their profiles remain disabled until S2-S4 deliver and qualify them.
33
+ // immutable-boundaries-v1 is withheld in particular: its manifest registry
34
+ // and staged attachment are not persisted, so advertised manifests would
35
+ // disappear on reopen.
36
+ const LOT1_DURABLE_PROFILES = new Set([
37
+ 'atomic-units-v1',
38
+ 'immutable-chains-v1',
39
+ ]);
40
+ const SQLITE_CLAIMS = Object.freeze(Object.entries(SQLITE_MEANINGS).map(([profile, meaning]) => Object.freeze({
41
+ profile: profile,
42
+ version: '1',
43
+ digest: createHash('sha256').update(JSON.stringify(['storage-profile', 'v1', profile, meaning])).digest('hex'),
44
+ })));
45
+ export const sqliteProfileClaims = (module, resync) => Object.freeze(SQLITE_CLAIMS.filter((claim) => LOT1_DURABLE_PROFILES.has(claim.profile) &&
46
+ (module === 'comments' || claim.profile !== 'staged-units-v1') &&
47
+ (resync || claim.profile !== 'scope-outbox-v1')));
48
+ const READONLY_METHODS = new Set([
49
+ 'capability', 'requireOperation', 'readHead', 'readChain', 'readRecord', 'readAggregate', 'readPage',
50
+ 'indexGet', 'inspectStaged', 'journalFence', 'journalRead', 'journalInspect', 'externalRead', 'snapshotRead',
51
+ 'auditRead', 'purgeProgress', 'purgeJobIds', 'purgeEvidence', 'recoveryEvidence', 'verifyManifest',
52
+ 'manifestReadPage', 'readBlob', 'query',
53
+ ]);
54
+ const SYNC_METHODS = new Set(['requireOperation', 'capability']);
55
+ const persistAfter = (bound, backend, engine, scope) => new Proxy(bound, {
56
+ get(target, property, receiver) {
57
+ const claims = sqliteProfileClaims(target.moduleId, true);
58
+ if (property === 'profiles')
59
+ return claims;
60
+ if (property === 'capability')
61
+ return (profile) => {
62
+ engine.assertOwnership();
63
+ const claim = claims.find(entry => entry.profile === profile);
64
+ if (!claim)
65
+ throw new UnsupportedProfileError(profile);
66
+ const original = target.capability(profile);
67
+ // Bind ports to the guarded facade, including previously issued
68
+ // ports. Never return methods bound to the memory runtime.
69
+ return Object.freeze({ ...('port' in original ? rootCapability(receiver, profile) : {}), ...claim });
70
+ };
71
+ const value = Reflect.get(target, property, target);
72
+ if (typeof value !== 'function')
73
+ return value;
74
+ // Possession is verified before every call, reads included: loss is
75
+ // terminal and revokes dependent readers. Only mutations persist.
76
+ // Sync ports keep their sync contract; async refusals reject.
77
+ if (SYNC_METHODS.has(String(property))) {
78
+ return (...args) => {
79
+ engine.assertOwnership();
80
+ return value.apply(target, args);
81
+ };
82
+ }
83
+ return async (...args) => {
84
+ const joined = property === 'transact' && backend.joinsTransaction(scope);
85
+ const release = joined ? () => { } : backend.admit();
86
+ try {
87
+ engine.assertOwnership();
88
+ if (property === 'transact' && typeof args[1] === 'function') {
89
+ const callback = args[1];
90
+ args[1] = (tx) => withSqliteTransaction(engine, tx, callback);
91
+ }
92
+ if (READONLY_METHODS.has(String(property)) || joined) {
93
+ const outcome = await value.apply(target, args);
94
+ engine.assertOwnership();
95
+ return outcome;
96
+ }
97
+ // Admission excludes readers and other mutations until rollback
98
+ // or durable publication has completed. Inner-op atomicity stays
99
+ // with the coordinator and its captured root identity.
100
+ const snapshot = backend.snapshotScope(scope);
101
+ const invoke = async () => value.apply(target, args);
102
+ const outcome = property === 'transact' ? await backend.withTransaction(scope, invoke) : await invoke();
103
+ try {
104
+ engine.assertOwnership();
105
+ backend.flushScope(scope);
106
+ }
107
+ catch (error) {
108
+ backend.restoreScope(scope, snapshot);
109
+ throw error;
110
+ }
111
+ return outcome;
112
+ }
113
+ finally {
114
+ release();
115
+ }
116
+ };
117
+ },
118
+ });
119
+ export const createSqliteKernel = (options) => {
120
+ const { path, moduleId, open, ...neutral } = options;
121
+ if (typeof moduleId !== 'string' || moduleId.length === 0) {
122
+ throw new StorageInvalidCommandError('sqlite kernel requires a moduleId');
123
+ }
124
+ const engine = openSqliteEngine({ ...(open ?? {}), path, moduleId });
125
+ const backend = new SqliteStateBackend(engine);
126
+ const staged = moduleId === 'comments';
127
+ const inner = staged
128
+ ? createRootStagedKernel({ ...neutral, backend, moduleId })
129
+ : createKernel({ ...neutral, backend, moduleId });
130
+ const wrapScope = (bound, grant) => persistAfter(bound, backend, engine, { tenantId: grant.scope.tenantId, workspaceId: grant.scope.workspaceId });
131
+ const kernel = {
132
+ engine,
133
+ backend,
134
+ moduleId: inner.moduleId,
135
+ incarnation: inner.incarnation,
136
+ ownershipContract: CANONICAL_INSTANCE_OWNERSHIP_CONTRACT,
137
+ bind: (grant) => wrapScope(inner.bind(grant), grant),
138
+ bindNew: (grant) => wrapScope(inner.bindNew(grant), grant),
139
+ revoke: (token) => inner.revoke(token),
140
+ provisionFence: (...args) => {
141
+ if (!('provisionFence' in inner))
142
+ throw new UnsupportedProfileError('staged-units-v1');
143
+ return inner.provisionFence(...args);
144
+ },
145
+ profiles: (resync) => sqliteProfileClaims(moduleId, resync),
146
+ close: () => {
147
+ backend.assertIdle();
148
+ try {
149
+ backend.flushAll();
150
+ }
151
+ catch (error) {
152
+ if (!(error instanceof CanonicalOwnershipError))
153
+ throw error;
154
+ }
155
+ engine.close();
156
+ },
157
+ };
158
+ return Object.freeze(kernel);
159
+ };
160
+ export { CanonicalInstanceRegistry };
161
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/storage/sqlite/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,wEAAwE;AACxE,sEAAsE;AACtE,qEAAqE;AACrE,mFAAmF;AACnF,wEAAwE;AACxE,iEAAiE;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,YAAY,EAAmB,MAAM,cAAc,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,sBAAsB,GAGvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qCAAqC,EACrC,yBAAyB,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAA6C,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,eAAe,GAAG;IACtB,iBAAiB,EACf,+HAA+H;IACjI,qBAAqB,EAAE,mFAAmF;IAC1G,yBAAyB,EACvB,wHAAwH;IAC1H,iBAAiB,EACf,2IAA2I;IAC7I,wBAAwB,EACtB,mHAAmH;IACrH,iBAAiB,EACf,8IAA8I;IAChJ,mBAAmB,EACjB,8GAA8G;IAChH,eAAe,EACb,yJAAyJ;CACnJ,CAAC;AAIX,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,0EAA0E;AAC1E,0EAA0E;AAC1E,2EAA2E;AAC3E,yE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,CAAC;QAC3D,KAAK,EAAE,GAAS,EAAE;YAChB,OAAO,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC;gBACH,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,CAAC,KAAK,YAAY,uBAAuB,CAAC;oBAAE,MAAM,KAAK,CAAC;YAC/D,CAAC;YACD,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const SQLITE_OWNER_SOURCE: string;
2
+ //# sourceMappingURL=owner-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner-source.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/owner-source.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,QAgD/B,CAAC"}
@@ -0,0 +1,52 @@
1
+ // Only this fixed program runs in the writer process. Caller callbacks
2
+ // execute across IPC in the caller, never alongside SQLite's POSIX locks.
3
+ export const SQLITE_OWNER_SOURCE = String.raw `
4
+ import { readSync, writeSync } from 'node:fs';
5
+ import { DatabaseSync } from 'node:sqlite';
6
+ import { StringDecoder } from 'node:string_decoder';
7
+ const decoder = new StringDecoder('utf8');
8
+ let buffered = '';
9
+ const send = value => {
10
+ const data = Buffer.from(JSON.stringify(value) + '\n');
11
+ for (let offset = 0; offset < data.length;) offset += writeSync(1, data, offset);
12
+ };
13
+ const receive = () => {
14
+ while (!buffered.includes('\n')) {
15
+ const data = Buffer.alloc(65536);
16
+ const size = readSync(0, data);
17
+ if (!size) process.exit(0);
18
+ buffered += decoder.write(data.subarray(0, size));
19
+ }
20
+ const end = buffered.indexOf('\n');
21
+ const line = buffered.slice(0, end);
22
+ buffered = buffered.slice(end + 1);
23
+ return JSON.parse(line);
24
+ };
25
+ const fail = error => send({ error: { name: error.name, message: error.message,
26
+ code: error.code, errcode: error.errcode, errstr: error.errstr } });
27
+ let db;
28
+ try { db = new DatabaseSync(process.argv[1]); send({ result: process.pid }); }
29
+ catch (error) { fail(error); process.exit(1); }
30
+ const dispatch = request => {
31
+ try {
32
+ let result;
33
+ if (request.op === 'close') { db.close(); send({ result: null }); process.exit(0); }
34
+ if (request.op === 'exec') db.exec(request.sql);
35
+ else if (request.op === 'function') db.function(request.sql, request.options, (...args) => {
36
+ send({ callback: request.sql, args });
37
+ for (;;) {
38
+ const reply = receive();
39
+ if (reply.op !== 'callback-result') { dispatch(reply); continue; }
40
+ if (reply.error) throw Object.assign(new Error(reply.error.message), reply.error);
41
+ return reply.result;
42
+ }
43
+ });
44
+ else if (['get', 'all', 'run'].includes(request.op)) {
45
+ result = db.prepare(request.sql)[request.op](...request.args);
46
+ } else if (request.op !== 'exec') throw new Error('Unsupported SQLite owner request');
47
+ send({ result });
48
+ } catch (error) { fail(error); }
49
+ };
50
+ for (;;) dispatch(receive());
51
+ `;
52
+ //# sourceMappingURL=owner-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner-source.js","sourceRoot":"","sources":["../../../src/storage/sqlite/owner-source.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgD5C,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { KernelTransaction } from '../scope-runtime.js';
2
+ import type { SqliteEngine } from './engine.js';
3
+ /** The callback owns this port only until it returns. Results are released
4
+ * after revalidation, including reads prepared before ownership loss. */
5
+ export declare const withSqliteTransaction: <T>(engine: SqliteEngine, tx: KernelTransaction, callback: (port: KernelTransaction) => Promise<T>) => Promise<T>;
6
+ //# sourceMappingURL=transaction-port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-port.d.ts","sourceRoot":"","sources":["../../../src/storage/sqlite/transaction-port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;yEACyE;AACzE,eAAO,MAAM,qBAAqB,cAAqB,YAAY,MAAM,iBAAiB,YAC9E,CAAC,IAAI,EAAE,iBAAiB,KAAK,QAAQ,CAAC,CAAC,KAAG,QAAQ,CAAC,CAoB9D,CAAC"}