@volter/supercode-orchestrator 0.4.141 → 0.4.142

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.
@@ -21,7 +21,7 @@ import { spawn as spawnChild, spawnSync } from 'node:child_process';
21
21
  import { existsSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
22
22
  import { hostname, tmpdir } from 'node:os';
23
23
  import { basename, dirname, join } from 'node:path';
24
- import { randomUUID } from 'node:crypto';
24
+ import { createHash, randomUUID } from 'node:crypto';
25
25
  import { fileURLToPath } from 'node:url';
26
26
  import { view, boardPath, claimer, event, json, listBoards, logsDir, now, openBoard, setActor, tx } from './store.mjs';
27
27
  import { doors, fire, loadWorkflow, resumeOf, runSpec, requestSessionClose, retireSupersededRuns, refreshRelationAnswers, transitionsFor, scopeOf, statusOf, templateValue, workflowFor } from './workflow.mjs';
@@ -778,6 +778,12 @@ function observeIdle(board, fleet, settings, report, entry, effects) {
778
778
  }
779
779
  }
780
780
 
781
+ function effectMessageKey(effect) {
782
+ if (effect.messageKey) return effect.messageKey;
783
+ const identity = JSON.stringify([effect.kind, effect.id, effect.runId, effect.sourceEvent, effect.durableId, effect.verb, effect.text]);
784
+ return `board-effect-${createHash('sha256').update(identity).digest('hex')}`;
785
+ }
786
+
781
787
  /** The verb drains this durable notice immediately; the dispatcher retries after a failure. */
782
788
  export async function sessionNotice(board, e) {
783
789
  const prior = view(board, (db) => json(db.prepare('SELECT metadata FROM task_runs WHERE id=?').get(e.runId)?.metadata, {})?.supercode);
@@ -792,7 +798,7 @@ export async function sessionNotice(board, e) {
792
798
  let error = null, receipt = null;
793
799
  try {
794
800
  if (!e.address) throw new Error('lifecycle notice awaits the owned launch session identity');
795
- receipt = await send(boardAddress(board.label), board.label, e.address, e.text, e.messageKey ?? `board-run-notice-${e.id}-${e.durableId}`);
801
+ receipt = await send(boardAddress(board.label), board.label, e.address, e.text, effectMessageKey(e));
796
802
  if (!receipt.delivered) error = receipt.reason ?? 'notice queued; native transcript confirmation pending'; }
797
803
  catch (failure) { error = String(failure.message).slice(-500); }
798
804
  tx(board, (db) => {
@@ -813,7 +819,7 @@ export async function sessionEffect(board, e) {
813
819
  let receipt;
814
820
  try {
815
821
  if (!address) throw new Error('actor session identity unavailable');
816
- receipt = await send(boardAddress(board.label), board.label, address, e.text, `board-actor-${e.id}-${e.durableId}`);
822
+ receipt = await send(boardAddress(board.label), board.label, address, e.text, effectMessageKey(e));
817
823
  } catch (error) { receipt = { delivered: false, reason: error.message }; }
818
824
  const kind = receipt.delivered ? 'actor_notice_delivered' : receipt.queued ? 'actor_notice_queued' : 'actor_notice_failed';
819
825
  tx(board, db => {
package/board/rows.mjs CHANGED
@@ -5,7 +5,7 @@ const quote = s => `"${s.replaceAll('"', '""')}"`;
5
5
  const RUNTIME = new Set(['claim_lock','claim_expires','worker_pid','last_heartbeat_at','current_run_id','consecutive_failures','last_failure_error','block_recurrences','session_id','workspace_path']);
6
6
  const OMIT = new Set(['tasks','supercode_cards','task_links','sqlite_sequence']);
7
7
  export class RuntimeRows {
8
- constructor(db) { this.db=db; this.revision=null; this.tables=new Map(); this.runtime={}; this.clocks={}; this.cachedTasks={}; this.cachedCards={}; }
8
+ constructor(db) { this.db=db; this.revision=null; this.tables=new Map(); this.runtime={}; this.clocks={}; this.sequences={}; this.cachedTasks={}; this.cachedCards={}; }
9
9
  normalized() { return Boolean(this.db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='runtime_rows'").get()); }
10
10
  watch(mem) {
11
11
  mem.exec('CREATE TEMP TABLE IF NOT EXISTS _runtime_dirty (name TEXT, key TEXT)');
@@ -40,16 +40,24 @@ export class RuntimeRows {
40
40
  const value=json(row.value,null);
41
41
  if(row.name==='@runtime') { if(value)this.runtime[row.key]=value;else delete this.runtime[row.key]; }
42
42
  else if(row.name==='@clock') { if(value)this.clocks[row.key]=value;else delete this.clocks[row.key]; }
43
+ else if(row.name==='@sequence') { if(value)this.sequences[row.key]=value;else delete this.sequences[row.key]; }
43
44
  else if(row.name==='@task_cache') { if(value)this.cachedTasks[row.key]=value;else delete this.cachedTasks[row.key]; }
44
45
  else if(row.name==='@card_cache') { if(value)this.cachedCards[row.key]=value;else delete this.cachedCards[row.key]; }
45
46
  else this.insert(mem,row.name,value,row.key);
46
47
  }
48
+ if (mem.prepare("SELECT 1 FROM sqlite_master WHERE name='sqlite_sequence'").get()) {
49
+ for (const [name, value] of Object.entries(this.sequences)) {
50
+ const sequence = mem.prepare('SELECT seq FROM sqlite_sequence WHERE name=?').get(name);
51
+ if (sequence) mem.prepare('UPDATE sqlite_sequence SET seq=MAX(seq,?) WHERE name=?').run(value.seq,name);
52
+ else mem.prepare('INSERT INTO sqlite_sequence(name,seq) VALUES(?,?)').run(name,value.seq);
53
+ }
54
+ }
47
55
  this.revision=Number(this.db.prepare("SELECT value FROM state WHERE key='rows_revision'").get()?.value??0);
48
56
  return true;
49
57
  }
50
58
  changes(mem,{all=false}={}) {
51
59
  const dirty=all?[...this.tables.values()].flatMap(t=>mem.prepare(`SELECT ${t.keys.map(quote).join(',')} FROM ${quote(t.name)}`).all().map(row=>({name:t.name,key:JSON.stringify(t.keys.map(k=>row[k]))}))):mem.prepare('SELECT DISTINCT name,key FROM _runtime_dirty').all();
52
- return dirty.map(({name,key})=>{
60
+ const changes = dirty.map(({name,key})=>{
53
61
  const table=this.tables.get(name);
54
62
  const row=mem.prepare(`SELECT * FROM ${quote(name)} WHERE ${table.keys.map(k=>`${quote(k)} IS ?`).join(' AND ')}`).get(...JSON.parse(key))??null;
55
63
  if(name==='tasks')return {name:'@runtime',key:JSON.parse(key)[0],value:row&&Object.fromEntries(Object.entries(row).filter(([k])=>RUNTIME.has(k))),source:{name,key,row}};
@@ -72,6 +80,12 @@ export class RuntimeRows {
72
80
  if(name==='@clock')return JSON.stringify(source.row)!==JSON.stringify(this.cachedCards[key]??null);
73
81
  return false;
74
82
  });
83
+ if (mem.prepare("SELECT 1 FROM sqlite_master WHERE name='sqlite_sequence'").get()) {
84
+ for (const row of mem.prepare('SELECT name,seq FROM sqlite_sequence').all()) {
85
+ if (Number(this.sequences[row.name]?.seq) !== Number(row.seq)) changes.push({name:'@sequence',key:row.name,value:row,source:{name:'sqlite_sequence',key:JSON.stringify([row.name]),row}});
86
+ }
87
+ }
88
+ return changes;
75
89
  }
76
90
  mirror(changes, revision) {
77
91
  const previous=Number(this.db.prepare("SELECT value FROM state WHERE key='read_revision'").get()?.value??-1);
@@ -108,6 +122,7 @@ export class RuntimeRows {
108
122
  }
109
123
  if(name==='@runtime') { if(value)this.runtime[key]=value;else delete this.runtime[key]; }
110
124
  if(name==='@clock') { if(value)this.clocks[key]=value;else delete this.clocks[key]; }
125
+ if(name==='@sequence') { if(value)this.sequences[key]=value;else delete this.sequences[key]; }
111
126
  }
112
127
  for(const {name,sql} of this.tables.values())if(!OMIT.has(name))this.db.prepare('INSERT OR IGNORE INTO runtime_schema VALUES(?,?)').run(name,sql);
113
128
  this.db.prepare("INSERT INTO state VALUES('rows_revision',?) ON CONFLICT(key) DO UPDATE SET value=excluded.value").run(String(revision));
@@ -338,7 +338,7 @@ function queueTransitionNotice(db, board, entry, task, from, name, payload, befo
338
338
  const scope = scopeOf(db, board, after, { params: entry.params, event: { ...payload, verb: name, from, to }, extra: { run: { id: beforeRun.id } } });
339
339
  const text = render(entry.workflow.notify?.worker?.run_changed ?? '{{card.id}}: {{event.verb}} changed run {{run.id}} ({{event.from}} → {{event.to}}). Stop work under the previous run; follow the board’s current state. {{event.reason ?? ""}}', scope);
340
340
  const source = one(db, 'SELECT MAX(id) AS id FROM task_events WHERE task_id = ?', task.id)?.id;
341
- const effect = { kind: 'session_notice', id: task.id, runId: beforeRun.id, address, text, sourceEvent: source, verb: name };
341
+ const effect = { kind: 'session_notice', id: task.id, runId: beforeRun.id, address, text, sourceEvent: source, verb: name, messageKey: `board-run-notice-${randomBytes(16).toString('hex')}` };
342
342
  const inserted = run(db, 'INSERT INTO supercode_effects (effect) VALUES (?)', JSON.stringify(effect));
343
343
  effects.push({ ...effect, durableId: Number(inserted.lastInsertRowid) });
344
344
  const current = json(one(db, 'SELECT metadata FROM task_runs WHERE id = ?', beforeRun.id)?.metadata, {}) ?? {};
@@ -791,7 +791,7 @@ const ACTIONS = {
791
791
  ctx.effects.push({ kind: 'board_message', id: ctx.id });
792
792
  },
793
793
  send_to_actor(ctx, text) {
794
- const effect = { kind: 'send_to_actor', id: ctx.id, runId: ctx.runId, text };
794
+ const effect = { kind: 'send_to_actor', id: ctx.id, runId: ctx.runId, text, messageKey: `board-actor-${randomBytes(16).toString('hex')}` };
795
795
  const inserted = run(ctx.db, 'INSERT INTO supercode_effects (effect) VALUES (?)', JSON.stringify(effect));
796
796
  ctx.effects.push({ ...effect, durableId: Number(inserted.lastInsertRowid) });
797
797
  },
package/board/ztrack.mjs CHANGED
@@ -625,6 +625,7 @@ class ZtrackBoard {
625
625
  if (id) sources.set(`tasks:${JSON.stringify([id])}`, {name:'tasks',key:JSON.stringify([id]),row:this.mem.prepare('SELECT * FROM tasks WHERE id=?').get(id)});
626
626
  }
627
627
  for (const {name,key,row:source} of sources.values()) {
628
+ if (name === 'sqlite_sequence') continue;
628
629
  if (!compat.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(name)) continue;
629
630
  const table = this.rows.tables.get(name);
630
631
  if (name === 'task_events') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/supercode-orchestrator",
3
- "version": "0.4.141",
3
+ "version": "0.4.142",
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": {