@volter/supercode-orchestrator 0.4.83 → 0.4.84

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 (2) hide show
  1. package/board/ztrack.mjs +21 -6
  2. package/package.json +1 -1
package/board/ztrack.mjs CHANGED
@@ -50,8 +50,8 @@ class ZtrackBoard {
50
50
  };
51
51
  this.tx(() => {});
52
52
  }
53
- get(key, fallback = null) { return json(this.runtime.prepare('SELECT value FROM state WHERE key = ?').get(key)?.value, fallback); }
54
- put(key, value) { this.runtime.prepare('INSERT INTO state VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value').run(key, JSON.stringify(value)); }
53
+ get(key, fallback = null) { return this.computing && this.pendingValues.has(key) ? this.pendingValues.get(key) : json(this.runtime.prepare('SELECT value FROM state WHERE key = ?').get(key)?.value, fallback); }
54
+ put(key, value) { if (this.computing) { this.pendingValues.set(key, value); return; } this.runtime.prepare('INSERT INTO state VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value').run(key, JSON.stringify(value)); }
55
55
  stamp() {
56
56
  const fileStamp = (path) => { try { const s = statSync(path); return `${s.ino}:${s.size}:${s.mtimeMs}`; } catch { return 'missing'; } };
57
57
  return [fileStamp(this.path), fileStamp(this.archive), fileStamp(this.compatPath), this.get('version', '')].join('|');
@@ -71,6 +71,8 @@ class ZtrackBoard {
71
71
  if (current === file.before) atomic(file.path, file.text);
72
72
  }
73
73
  this.put('snapshot', pending.snapshot);
74
+ if (pending.intent) this.put(`applied:${pending.intent}`, true);
75
+ this.put('version', randomBytes(8).toString('hex'));
74
76
  this.runtime.prepare("DELETE FROM state WHERE key = 'pending'").run();
75
77
  }
76
78
  tx(fn) {
@@ -86,14 +88,22 @@ class ZtrackBoard {
86
88
  let committed = false;
87
89
  try {
88
90
  this.recover();
91
+ const version = this.get('version');
92
+ this.runtime.exec('COMMIT');
93
+ // Parsing, rules and rendering run against a snapshot, without a runtime writer transaction.
94
+ this.pendingValues = new Map(); this.computing = true;
89
95
  this.load();
90
96
  if (this.seed) this.seedIntoMemory();
91
97
  else this.lift();
92
98
  const result = fn(this.db);
93
99
  const documents = this.documents();
94
100
  const files = [{ path: this.path, before: hash(this.text), text: documents.open }, { path: this.archive, before: hash(this.archiveText), text: documents.archived }];
95
- if (files.some((f) => hash(read(f.path)) !== f.before)) { this.runtime.exec('ROLLBACK'); continue; }
96
101
  const snapshot = this.snapshot();
102
+ this.computing = false;
103
+ this.runtime.exec('BEGIN IMMEDIATE');
104
+ this.recover();
105
+ if (this.get('version') !== version || files.some((f) => hash(read(f.path)) !== f.before)) { this.runtime.exec('ROLLBACK'); continue; }
106
+ for (const [key, value] of this.pendingValues) this.put(key, value);
97
107
  // A durable intent precedes filesystem writes; recovery completes exactly this version.
98
108
  const intent = randomBytes(16).toString('hex');
99
109
  this.put('pending', { intent, files, snapshot });
@@ -101,14 +111,19 @@ class ZtrackBoard {
101
111
  // A concurrent writer may recover this intent and advance the runtime. Re-read
102
112
  // its identity before touching documents, retrying from any newer version.
103
113
  this.runtime.exec('BEGIN IMMEDIATE');
104
- if (this.get('pending')?.intent !== intent) { this.runtime.exec('ROLLBACK'); continue; }
114
+ if (this.get('pending')?.intent !== intent) {
115
+ const applied = this.get(`applied:${intent}`, false);
116
+ this.runtime.exec('ROLLBACK');
117
+ if (applied) { this.loadedStamp = null; this.seed = null; return result; }
118
+ continue;
119
+ }
105
120
  // Detect an editor racing the journal commit before replacing either document.
106
121
  if (files.some((f) => hash(read(f.path)) !== f.before)) {
107
122
  this.runtime.prepare("DELETE FROM state WHERE key = 'pending'").run(); this.runtime.exec('COMMIT');
108
123
  continue;
109
124
  }
110
125
  for (const f of files) if (hash(f.text) !== f.before) atomic(f.path, f.text);
111
- this.put('snapshot', snapshot); this.runtime.prepare("DELETE FROM state WHERE key = 'pending'").run();
126
+ this.put('snapshot', snapshot); this.put(`applied:${intent}`, true); this.runtime.prepare("DELETE FROM state WHERE key = 'pending'").run();
112
127
  this.export();
113
128
  this.put('version', randomBytes(8).toString('hex'));
114
129
  this.runtime.exec('COMMIT');
@@ -120,7 +135,7 @@ class ZtrackBoard {
120
135
  if (/busy|locked|Hermes wrote/i.test(error.message)) continue;
121
136
  if (committed) error.message += ' (the runtime journal retains any unfinished document write)';
122
137
  throw error;
123
- } finally { this.active = false; }
138
+ } finally { this.active = false; this.computing = false; this.pendingValues = null; }
124
139
  }
125
140
  }
126
141
  seedIntoMemory() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/supercode-orchestrator",
3
- "version": "0.4.83",
3
+ "version": "0.4.84",
4
4
  "type": "module",
5
5
  "description": "The orchestrator runtime over the Volter Harness ontology: one typed operational model whose folder is its serialization, read and written through the harness orchestration doors (docs/ORCHESTRATOR-IR.md)",
6
6
  "exports": {