pi-better-goal 0.14.1 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-goal",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "description": "Pi extension for goal tracking with background-aware continuation.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,6 +47,7 @@ export function readAssignmentWaits(path, owner, connection) {
47
47
  export function createAssignmentReader(path) {
48
48
  let db;
49
49
  let identity;
50
+ let snapshot = false;
50
51
  const statements = new Map();
51
52
  return {
52
53
  revision() {
@@ -54,6 +55,7 @@ export function createAssignmentReader(path) {
54
55
  const stat = statSync(path, { bigint: true });
55
56
  const next = `${stat.dev}:${stat.ino}`;
56
57
  if (identity !== next) {
58
+ if (snapshot) throw new Error("Coordinator identity changed during observation");
57
59
  db?.close();
58
60
  db = undefined;
59
61
  statements.clear();
@@ -63,6 +65,21 @@ export function createAssignmentReader(path) {
63
65
  db ??= new DatabaseSync(path, { readOnly: true });
64
66
  return `${identity}:${db.prepare("PRAGMA data_version").get().data_version}`;
65
67
  },
68
+ beginSnapshot() {
69
+ this.revision();
70
+ if (snapshot) throw new Error("Coordinator snapshot already open");
71
+ db.exec("BEGIN");
72
+ snapshot = true;
73
+ const release = () => {
74
+ if (!snapshot) return;
75
+ try { db.exec("ROLLBACK"); } finally { snapshot = false; }
76
+ };
77
+ try {
78
+ // Pin the WAL read view before recording its revision; other writers keep advancing.
79
+ db.prepare("SELECT count(*) FROM sqlite_schema").get();
80
+ return { revision: this.revision(), release };
81
+ } catch (error) { release(); throw error; }
82
+ },
66
83
  read(owner) {
67
84
  try {
68
85
  this.revision();
@@ -98,6 +115,6 @@ export function createAssignmentReader(path) {
98
115
  return new Map([...hashes].map(([key, hash]) => [key, hash.digest("hex")]));
99
116
  } catch { return undefined; }
100
117
  },
101
- close() { db?.close(); db = undefined; statements.clear(); identity = undefined; },
118
+ close() { if (snapshot) { db.exec("ROLLBACK"); snapshot = false; } db?.close(); db = undefined; statements.clear(); identity = undefined; },
102
119
  };
103
120
  }