@hearsay-tools/squawk 0.18.0-dev.7820 → 0.18.0-dev.7830

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 (129) hide show
  1. package/dist/activity/read-model.d.ts +3 -1
  2. package/dist/activity/read-model.js +17 -15
  3. package/dist/activity/read-model.js.map +1 -1
  4. package/dist/activity/requests.d.ts +3 -1
  5. package/dist/activity/requests.js +1 -1
  6. package/dist/activity/requests.js.map +1 -1
  7. package/dist/artifacts/reports-index.d.ts +3 -7
  8. package/dist/artifacts/reports-index.js +6 -6
  9. package/dist/artifacts/reports-index.js.map +1 -1
  10. package/dist/automations/service.js +1 -1
  11. package/dist/automations/service.js.map +1 -1
  12. package/dist/automations/task-template.js +3 -3
  13. package/dist/automations/task-template.js.map +1 -1
  14. package/dist/ci-wait/controller.d.ts +42 -42
  15. package/dist/delegation/conversations.d.ts +6 -2
  16. package/dist/delegation/conversations.js +1 -1
  17. package/dist/delegation/conversations.js.map +1 -1
  18. package/dist/delegation/family-end.d.ts +4 -2
  19. package/dist/delegation/family-end.js +1 -1
  20. package/dist/delegation/family-end.js.map +1 -1
  21. package/dist/delegation/scratch-cleanup.js +2 -2
  22. package/dist/delegation/scratch-cleanup.js.map +1 -1
  23. package/dist/delegation/task-discovery.js +1 -1
  24. package/dist/delegation/task-discovery.js.map +1 -1
  25. package/dist/delegation/worker-cleanup.js +4 -4
  26. package/dist/delegation/worker-cleanup.js.map +1 -1
  27. package/dist/project-commands.js +1 -1
  28. package/dist/project-commands.js.map +1 -1
  29. package/dist/project-migration/live.js +1 -1
  30. package/dist/project-migration/live.js.map +1 -1
  31. package/dist/runs/branch-owners.d.ts +2 -2
  32. package/dist/runs/cold-reads.d.ts +1 -1
  33. package/dist/runs/cold-reads.js +1 -1
  34. package/dist/runs/lifecycle.d.ts +2 -1
  35. package/dist/runs/lifecycle.js.map +1 -1
  36. package/dist/runs/live-tasks.js +1 -1
  37. package/dist/runs/live-tasks.js.map +1 -1
  38. package/dist/runs/ports.d.ts +63 -31
  39. package/dist/runs/retention.d.ts +4 -3
  40. package/dist/runs/retention.js +2 -2
  41. package/dist/runs/retention.js.map +1 -1
  42. package/dist/runs/run-cold-reads.d.ts +98 -0
  43. package/dist/runs/run-cold-reads.js +194 -0
  44. package/dist/runs/run-cold-reads.js.map +1 -0
  45. package/dist/runs/run-persistence.d.ts +150 -0
  46. package/dist/runs/run-persistence.js +396 -0
  47. package/dist/runs/run-persistence.js.map +1 -0
  48. package/dist/runs/run-queries.d.ts +190 -0
  49. package/dist/runs/run-queries.js +480 -0
  50. package/dist/runs/run-queries.js.map +1 -0
  51. package/dist/runs/run-repo-scope.d.ts +38 -0
  52. package/dist/runs/run-repo-scope.js +78 -0
  53. package/dist/runs/run-repo-scope.js.map +1 -0
  54. package/dist/runs/run-retention.d.ts +6 -2
  55. package/dist/runs/run-retention.js +11 -2
  56. package/dist/runs/run-retention.js.map +1 -1
  57. package/dist/runs/store.d.ts +12 -292
  58. package/dist/runs/store.js +122 -1119
  59. package/dist/runs/store.js.map +1 -1
  60. package/dist/serve-boot.d.ts +3 -1
  61. package/dist/serve-boot.js +2 -2
  62. package/dist/serve-boot.js.map +1 -1
  63. package/dist/server/models-routes.d.ts +13 -13
  64. package/dist/server/project-context.js +3 -3
  65. package/dist/server/project-context.js.map +1 -1
  66. package/dist/server/repo-branches.d.ts +5 -3
  67. package/dist/server/repo-branches.js +1 -1
  68. package/dist/server/repo-branches.js.map +1 -1
  69. package/dist/server/reports-api.d.ts +2 -2
  70. package/dist/server/run-checkout.d.ts +3 -1
  71. package/dist/server/run-checkout.js +2 -2
  72. package/dist/server/run-checkout.js.map +1 -1
  73. package/dist/server/run-relationships.d.ts +3 -1
  74. package/dist/server/run-relationships.js +1 -1
  75. package/dist/server/run-relationships.js.map +1 -1
  76. package/dist/server/server.d.ts +58 -58
  77. package/dist/server/server.js +12 -12
  78. package/dist/server/server.js.map +1 -1
  79. package/dist/server/start-server.js +1 -1
  80. package/dist/server/start-server.js.map +1 -1
  81. package/dist/workflows/run/auto-resume.js +2 -2
  82. package/dist/workflows/run/auto-resume.js.map +1 -1
  83. package/dist/workflows/run/completion-gate.js +1 -1
  84. package/dist/workflows/run/completion-gate.js.map +1 -1
  85. package/dist/workflows/run/continuation-acceptance.js +2 -2
  86. package/dist/workflows/run/continuation-acceptance.js.map +1 -1
  87. package/dist/workflows/run/family-reconciler.d.ts +2 -1
  88. package/dist/workflows/run/family-reconciler.js +8 -8
  89. package/dist/workflows/run/family-reconciler.js.map +1 -1
  90. package/dist/workflows/run/maintenance-claims.js +2 -2
  91. package/dist/workflows/run/maintenance-claims.js.map +1 -1
  92. package/dist/workflows/run/native-skill-input-queue.js +1 -1
  93. package/dist/workflows/run/native-skill-input-queue.js.map +1 -1
  94. package/dist/workflows/run/queued-revival.js +3 -3
  95. package/dist/workflows/run/queued-revival.js.map +1 -1
  96. package/dist/workflows/run/run-cancel.js +5 -5
  97. package/dist/workflows/run/run-cancel.js.map +1 -1
  98. package/dist/workflows/run/run-finish.js +1 -1
  99. package/dist/workflows/run/run-finish.js.map +1 -1
  100. package/dist/workflows/run/run-line.js +2 -2
  101. package/dist/workflows/run/run-line.js.map +1 -1
  102. package/dist/workflows/run/run-recovery.js +6 -6
  103. package/dist/workflows/run/run-recovery.js.map +1 -1
  104. package/dist/workflows/run/run-settlement.js +4 -4
  105. package/dist/workflows/run/run-settlement.js.map +1 -1
  106. package/dist/workflows/run/run-start.js +1 -1
  107. package/dist/workflows/run/run-start.js.map +1 -1
  108. package/dist/workflows/run/step-loop.js +4 -4
  109. package/dist/workflows/run/step-loop.js.map +1 -1
  110. package/dist/workflows/run/turn-nudges.js +1 -1
  111. package/dist/workflows/run/turn-nudges.js.map +1 -1
  112. package/dist/workflows/run/turn-settler.js +1 -1
  113. package/dist/workflows/run/turn-settler.js.map +1 -1
  114. package/dist/workflows/run/usage-accounting.js +1 -1
  115. package/dist/workflows/run/usage-accounting.js.map +1 -1
  116. package/dist/workflows/run/wake-admission.js +1 -1
  117. package/dist/workflows/run/wake-admission.js.map +1 -1
  118. package/dist/workflows/run/worker-questions.js +3 -3
  119. package/dist/workflows/run/worker-questions.js.map +1 -1
  120. package/dist/workflows/run.js +1 -1
  121. package/dist/workflows/run.js.map +1 -1
  122. package/package.json +4 -4
  123. package/scripts/benchmark-automation-lookups.ts +2 -2
  124. package/scripts/benchmark-conversation-lookup.ts +2 -2
  125. package/scripts/benchmark-family-reconcile.ts +2 -2
  126. package/scripts/benchmark-run-store.ts +3 -3
  127. package/scripts/benchmark-workspace-events.ts +2 -2
  128. package/scripts/benchmark-worktree-retention.ts +1 -1
  129. package/scripts/seed-archive-profile.ts +2 -2
@@ -0,0 +1,396 @@
1
+ /**
2
+ * How the store's writes reach `runs.db` (hearsay-tools/squawk#4043): the durable commit, the
3
+ * debounced save and its timer, the fenced transaction, conflict handling and the pending
4
+ * deletions. `RunStore` keeps one of these as `store.persistence`; `close` stays on the store.
5
+ */
6
+ import { existsSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { isDeepStrictEqual } from 'node:util';
9
+ import { assertProjectWritable, projectWriteRefused } from '../server/cockpit-ownership.js';
10
+ import { storedRow } from './cold-reads.js';
11
+ import { publishRunWrite, snapshotRun } from './lifecycle.js';
12
+ import { reconcileLoadedRun } from './loaded-run-exits.js';
13
+ import { encodeRawRecord } from './raw-record.js';
14
+ import { stageCommit } from './record-write-rules.js';
15
+ import { familyKey } from './run-claims.js';
16
+ import { RunWriteRefusedError } from './run-claims-topic.js';
17
+ import { RUNS_DB_FILE, RunConflictError, } from './run-database.js';
18
+ import { rescopeRun, restoreOriginatingIssue } from './run-references.js';
19
+ import { encodeRunRow } from './run-row.js';
20
+ /** Make `target` hold exactly `source`'s fields, keeping the object every holder references. */
21
+ export function replaceRecord(target, source) {
22
+ for (const key of Object.keys(target))
23
+ if (!(key in source))
24
+ delete target[key];
25
+ Object.assign(target, source);
26
+ }
27
+ export class RunPersistenceTopic {
28
+ dataDir;
29
+ persistence;
30
+ state;
31
+ saveTimer = null;
32
+ /** The family of each pending deletion, whose claim the deleting write is fenced against. */
33
+ deletedFamilies = new Map();
34
+ constructor(dataDir, persistence, state) {
35
+ this.dataDir = dataDir;
36
+ this.persistence = persistence;
37
+ this.state = state;
38
+ }
39
+ get db() { return this.state.db(); }
40
+ get owner() { return this.state.owner(); }
41
+ get openFailure() { return this.state.openFailure(); }
42
+ get repoHandle() { return this.state.repoHandle(); }
43
+ get held() { return this.state.held; }
44
+ get committing() { return this.state.committing; }
45
+ get dirty() { return this.state.dirty; }
46
+ get deleted() { return this.state.deleted; }
47
+ get historyOwed() { return this.state.historyOwed; }
48
+ get quarantined() { return this.state.quarantined; }
49
+ get claimed() { return this.state.claimed; }
50
+ get pendingClaims() { return this.state.pendingClaims; }
51
+ get base() { return this.state.base; }
52
+ get coldBase() { return this.state.coldBase; }
53
+ get coldReads() { return this.state.coldReads; }
54
+ get liveItems() { return this.state.liveItems; }
55
+ get published() { return this.state.published; }
56
+ get archive() { return this.state.archive; }
57
+ get claims() { return this.state.claims; }
58
+ get retention() { return this.state.retention; }
59
+ peek(id) { return this.state.peek(id); }
60
+ isAnchor(id, run) { return this.state.isAnchor(id, run); }
61
+ evictSettled() { this.state.evictSettled(); }
62
+ /** Persistence source for consumers that build the reports index. No index is created here. */
63
+ reportSource() { return { db: this.db, dataDir: this.dataDir, openFailure: this.openFailure }; }
64
+ /**
65
+ * Durably replace or delete staged rows together with pending dirty rows. Persist before
66
+ * changing held objects or notifying subscribers. On failure retain all pending state; flush()
67
+ * remains best-effort.
68
+ */
69
+ commitIndex(input, source, write = {}) {
70
+ const exits = new Map(write.exits);
71
+ const staged = stageCommit(input, {
72
+ peek: id => this.peek(id),
73
+ completionArchiveBlocker: run => this.archive.completionArchiveBlocker(run),
74
+ stageArchive: (staged, run, archived) => this.archive.stageArchive(staged, run, archived, exits),
75
+ });
76
+ const before = new Map([...staged].map(([id, next]) => [id, next ? write.before?.get(id) ?? snapshotRun(this.peek(id)) : undefined])), committed = new Map([...staged].map(([id, next]) => [id, snapshotRun(next ?? undefined)]));
77
+ if (!this.db)
78
+ throw this.openFailure ?? new Error('runs database unavailable: nothing can be saved');
79
+ this.assertWritable(staged);
80
+ this.persist(staged);
81
+ // Preserve existing record references, but expose the entire transaction before its first event, which
82
+ // carries the record this commit wrote (`committed`). A finished run is held until the next sweep.
83
+ for (const [id, next] of staged) {
84
+ this.coldReads.forget(id);
85
+ if (!next) {
86
+ this.held.delete(id);
87
+ continue;
88
+ }
89
+ this.committing.add(id);
90
+ const current = this.held.get(id);
91
+ if (current)
92
+ replaceRecord(current, next);
93
+ else
94
+ this.held.set(id, next);
95
+ }
96
+ try {
97
+ for (const id of staged.keys()) {
98
+ const run = this.held.get(id);
99
+ if (run)
100
+ publishRunWrite(this.published, committed.get(id) ?? run, before.get(id), source, exits.get(id));
101
+ else
102
+ this.published.publish('run.deleted', { runId: id });
103
+ }
104
+ }
105
+ finally {
106
+ for (const id of staged.keys())
107
+ this.committing.delete(id);
108
+ this.sweepIfSettled(staged.keys());
109
+ }
110
+ for (const [id, next] of staged)
111
+ if (next?.archived)
112
+ this.archive.compressor.enqueue(id);
113
+ }
114
+ /**
115
+ * Refuse (throwing, with nothing changed) a commit that stages a quarantined run, or a run whose
116
+ * family this store does not claim and cannot take: another process owns it, or a dead process
117
+ * left it live and it has not been adopted.
118
+ */
119
+ assertWritable(staged) {
120
+ const families = new Map();
121
+ const held = new Set();
122
+ for (const [id, next] of staged) {
123
+ if (this.quarantined.has(id))
124
+ throw new RunWriteRefusedError(id, 'quarantined');
125
+ const family = next ? familyKey(next) : this.familyOf(id);
126
+ families.set(id, family);
127
+ if (this.held.has(id))
128
+ held.add(family);
129
+ }
130
+ // A run this store holds may move to a new family; any other row is claimed as a plain write.
131
+ const owned = new Set([...this.claims.claimFamilies(held, { allowLive: true }),
132
+ ...this.claims.claimFamilies([...families.values()].filter((family) => !held.has(family)))]);
133
+ for (const [id, family] of families) {
134
+ if (!owned.has(family))
135
+ throw this.claims.runOwnership(id) === 'fallback' ? this.claims.fallbackRefusal(id) : new RunWriteRefusedError(id, this.claims.runOwnership(id) === 'orphaned' ? 'orphaned' : 'foreign');
136
+ }
137
+ }
138
+ /** The family of a run this store knows: held, else its row; a run nowhere is its own. */
139
+ familyOf(id) {
140
+ const held = this.held.get(id);
141
+ return held ? familyKey(held) : this.deletedFamilies.get(id) ?? this.db?.familyOf(id) ?? id;
142
+ }
143
+ /** Schedule the sweep that lets any of `ids` leave memory, when one of them now can. */
144
+ sweepIfSettled(ids) {
145
+ for (const id of ids) {
146
+ const run = this.held.get(id);
147
+ if (run && !this.isAnchor(id, run)) {
148
+ this.scheduleSave();
149
+ return;
150
+ }
151
+ }
152
+ }
153
+ /** Write the pending rows out now (used on shutdown). */
154
+ flush() {
155
+ if (this.saveTimer) {
156
+ clearTimeout(this.saveTimer);
157
+ this.saveTimer = null;
158
+ }
159
+ this.saveNow();
160
+ }
161
+ /** `RunStore.close`'s final save: what is pending goes out, and nothing leaves memory. */
162
+ closeSave() {
163
+ if (this.saveTimer) {
164
+ clearTimeout(this.saveTimer);
165
+ this.saveTimer = null;
166
+ }
167
+ this.saveNow(false);
168
+ }
169
+ /** Save `run` debounced and publish it; `before` is the record at the write's entry (none: created). */
170
+ touch(run, before, exit) {
171
+ this.dirty.add(run.id);
172
+ this.scheduleSave();
173
+ publishRunWrite(this.published, run, before, undefined, exit);
174
+ this.archive.maybeEnqueueHistoryCompress(run);
175
+ }
176
+ /** The held record is gone; the next save or commit deletes its row, fenced by `family`'s claim
177
+ * and by the revision this store last saw (kept in `base` until the delete is written). */
178
+ markDeleted(id, family) {
179
+ this.liveItems.forget(id);
180
+ this.coldReads.forget(id);
181
+ const read = this.coldBase.get(id);
182
+ if (!this.base.has(id) && read)
183
+ this.base.set(id, storedRow(read));
184
+ this.dirty.delete(id);
185
+ this.deleted.add(id);
186
+ this.deletedFamilies.set(id, family);
187
+ this.historyOwed.add(id);
188
+ }
189
+ /** Debounced so token-usage updates don't rewrite a row per event. Nothing to schedule without
190
+ * a database: a `RunStore.unavailable` store, or a closed one, writes nothing. */
191
+ scheduleSave() {
192
+ if (this.saveTimer || !this.db)
193
+ return;
194
+ this.saveTimer = setTimeout(() => {
195
+ this.saveTimer = null;
196
+ this.saveNow();
197
+ }, 300);
198
+ this.saveTimer.unref?.();
199
+ }
200
+ /** The single database write, so a test can fail it the way a full disk would. */
201
+ writeIndex(changes) {
202
+ const transaction = (changes) => { assertProjectWritable(this.dataDir); return this.db.transaction(changes); };
203
+ return this.persistence ? this.persistence(changes, transaction) : transaction(changes);
204
+ }
205
+ /**
206
+ * Write `staged` plus everything still pending — dirty rows from memory, deletions — in one
207
+ * transaction, then clear the pending marks. Throws with nothing cleared when it fails.
208
+ * Never copies or sorts the whole store: the cost is the rows that changed.
209
+ *
210
+ * Fenced (#779, plan step 3): the transaction commits only if every family it writes still
211
+ * carries this store's claim and every row is at the revision this store last saw. Otherwise
212
+ * nothing is written and `handleConflicts` deals with the rows that changed under it.
213
+ */
214
+ persist(staged) {
215
+ const upserts = [];
216
+ const deletes = [];
217
+ const families = new Map();
218
+ const extras = new Map();
219
+ const encode = (run) => {
220
+ const encoded = encodeRawRecord(run, (this.base.get(run.id) ?? this.coldBase.get(run.id))?.extras);
221
+ extras.set(run.id, encoded.extras);
222
+ const projected = { ...run };
223
+ restoreOriginatingIssue(projected);
224
+ upserts.push({ ...encodeRunRow(run, encoded.data),
225
+ issueAttributionCurrent: isDeepStrictEqual(projected, run) });
226
+ };
227
+ for (const [id, next] of staged) {
228
+ if (next)
229
+ encode(next);
230
+ else
231
+ deletes.push(id);
232
+ families.set(id, next ? familyKey(next) : this.familyOf(id));
233
+ }
234
+ for (const id of this.dirty) {
235
+ const run = this.held.get(id);
236
+ if (!run || staged.has(id))
237
+ continue;
238
+ encode(run);
239
+ families.set(id, familyKey(run));
240
+ }
241
+ for (const id of this.deleted) {
242
+ if (staged.has(id))
243
+ continue;
244
+ deletes.push(id);
245
+ families.set(id, this.familyOf(id));
246
+ }
247
+ // A row's insertion order (`seq`) is the order this write inserts it in, and it is where the
248
+ // run lists among runs created in the same millisecond. Insert new runs in creation order (the
249
+ // held set's, then staged runs not held yet), whether staged or dirty brought them here.
250
+ if (upserts.filter((row) => !this.base.has(row.id)).length > 1) {
251
+ const created = new Map();
252
+ for (const id of [...this.held.keys(), ...staged.keys()])
253
+ if (!created.has(id))
254
+ created.set(id, created.size);
255
+ upserts.sort((a, b) => created.get(a.id) - created.get(b.id));
256
+ }
257
+ // A held run whose write moved it into a new family (a worker quarantined to `invalid`) takes
258
+ // that family's claim first; one it cannot take fails the fence below as claim-lost.
259
+ const moved = [...new Set(families.values())].filter((family) => !this.claimed.has(family) && !this.pendingClaims.has(family));
260
+ if (moved.length > 0)
261
+ this.claims.claimFamilies(moved, { allowLive: true });
262
+ let commit;
263
+ try {
264
+ commit = this.writeIndex({ upserts, deletes, ...(this.owner ? { fence: this.fence(families) } : {}) });
265
+ }
266
+ catch (error) {
267
+ if (error instanceof RunConflictError)
268
+ this.handleConflicts(error, staged);
269
+ throw error;
270
+ }
271
+ for (const [family, generation] of commit.claims) {
272
+ this.claimed.set(family, generation);
273
+ this.pendingClaims.delete(family);
274
+ }
275
+ for (const row of upserts) {
276
+ this.base.set(row.id, { revision: commit.revisions.get(row.id), seq: commit.seqs.get(row.id), data: row.data, extras: extras.get(row.id) });
277
+ }
278
+ for (const id of deletes) {
279
+ this.liveItems.forget(id);
280
+ this.base.delete(id);
281
+ this.deletedFamilies.delete(id);
282
+ this.retention.removeOwedHistory(id);
283
+ }
284
+ this.dirty.clear();
285
+ this.deleted.clear();
286
+ if (this.saveTimer) {
287
+ clearTimeout(this.saveTimer);
288
+ this.saveTimer = null;
289
+ }
290
+ }
291
+ /** What a write of these rows (id → family) must still find: this store's claims, at the
292
+ * generations it took them, and each row at the revision it last saw (none for a new row). */
293
+ fence(families) {
294
+ const claims = new Map();
295
+ const rows = new Map();
296
+ for (const [id, family] of families) {
297
+ const pending = this.pendingClaims.get(family);
298
+ // Generations start at 1, so an unclaimed family's 0 fails the fence as claim-lost.
299
+ claims.set(family, pending !== undefined ? { take: pending } : { generation: this.claimed.get(family) ?? 0 });
300
+ rows.set(id, { revision: (this.base.get(id) ?? this.coldBase.get(id))?.revision ?? null, family });
301
+ }
302
+ return { owner: this.owner, claims, rows };
303
+ }
304
+ /**
305
+ * Handle a fenced-write conflict. Save unexpected conflict evidence before clearing pending
306
+ * state or quarantining the row. If evidence persistence fails, retain pending writes. Other
307
+ * rows remain writable; stale unclaimed reads only fail their write.
308
+ */
309
+ handleConflicts(error, staged) {
310
+ const unexpected = error.conflicts.filter((conflict) => this.held.has(conflict.id) || this.deleted.has(conflict.id) || this.coldBase.get(conflict.id)?.owned === true);
311
+ if (unexpected.length === 0 || !this.db || !this.owner)
312
+ return;
313
+ const evidence = unexpected.map((conflict) => {
314
+ const seen = this.base.get(conflict.id) ?? this.coldBase.get(conflict.id);
315
+ const local = staged.has(conflict.id) ? staged.get(conflict.id) : this.deleted.has(conflict.id) ? null : this.held.get(conflict.id) ?? null;
316
+ return {
317
+ runId: conflict.id, reason: conflict.reason,
318
+ baseRevision: seen?.revision ?? null, baseData: seen?.data ?? null,
319
+ localData: local === null ? null : JSON.stringify(local), localDeleted: local === null,
320
+ currentRevision: conflict.current?.revision ?? null, currentData: conflict.current?.data ?? null,
321
+ };
322
+ });
323
+ let seqs;
324
+ try {
325
+ seqs = this.db.recordConflicts(this.owner.session, evidence);
326
+ }
327
+ catch (evidenceError) {
328
+ const message = evidenceError instanceof Error ? evidenceError.message : String(evidenceError);
329
+ console.error(`[hsq] ${RUNS_DB_FILE}: could not record the conflicting write on ${unexpected.map((c) => c.id).join(', ')}; it stays pending: ${message}`);
330
+ return;
331
+ }
332
+ unexpected.forEach((conflict, index) => {
333
+ const family = this.familyOf(conflict.id);
334
+ this.liveItems.forget(conflict.id);
335
+ this.quarantined.add(conflict.id);
336
+ this.coldReads.forget(conflict.id);
337
+ this.dirty.delete(conflict.id);
338
+ this.deleted.delete(conflict.id);
339
+ this.deletedFamilies.delete(conflict.id);
340
+ // The delete did not happen, so the history stays with the row.
341
+ this.historyOwed.delete(conflict.id);
342
+ if (conflict.reason === 'claim-lost') {
343
+ this.claimed.delete(family);
344
+ this.pendingClaims.delete(family);
345
+ }
346
+ const decoded = conflict.current ? this.state.decodeRunRow(conflict.current.data) : undefined;
347
+ const current = decoded?.run;
348
+ if (this.claims.isFallbackRun(conflict.id))
349
+ this.held.delete(conflict.id);
350
+ const held = this.held.get(conflict.id);
351
+ const before = snapshotRun(held ?? staged.get(conflict.id) ?? undefined);
352
+ if (current && conflict.current) {
353
+ // The other writer's record as it stands, normalized only as a live owner's run would be.
354
+ reconcileLoadedRun(current, { keepLive: true });
355
+ rescopeRun(current, this.repoHandle);
356
+ if (held)
357
+ replaceRecord(held, current);
358
+ this.base.set(conflict.id, { revision: conflict.current.revision, seq: conflict.current.seq, data: conflict.current.data, extras: decoded.extras });
359
+ publishRunWrite(this.published, held ?? current, before ?? snapshotRun(current), 'conflict');
360
+ }
361
+ else {
362
+ this.held.delete(conflict.id);
363
+ this.base.delete(conflict.id);
364
+ this.published.publish('run.deleted', { runId: conflict.id });
365
+ }
366
+ console.error(`[hsq] run ${conflict.id} was changed by another writer (${conflict.reason}); this process will not write it again until Squawk restarts. Evidence: ${join(this.dataDir, RUNS_DB_FILE)}, table run_conflicts, seq ${seqs[index]}.`);
367
+ });
368
+ this.scheduleSave();
369
+ }
370
+ /** Write what is pending, then (unless closing) let every run whose write settled leave memory. */
371
+ saveNow(evict = true) {
372
+ if (!this.db || projectWriteRefused(this.dataDir))
373
+ return;
374
+ // A second attempt only after a conflict excluded its rows: the unrelated rest goes out at once.
375
+ for (let attempt = 0; attempt < 2 && (this.dirty.size > 0 || this.deleted.size > 0); attempt++) {
376
+ const quarantined = this.quarantined.size;
377
+ try {
378
+ this.persist(new Map());
379
+ }
380
+ catch (err) {
381
+ if (err instanceof RunConflictError && this.quarantined.size > quarantined)
382
+ continue;
383
+ // A pending save may outlive its directory; never recreate it or hide live-directory
384
+ // failures. The rows stay pending (and held), so the next save or commit retries them.
385
+ if (existsSync(this.dataDir)) {
386
+ const message = err instanceof Error ? err.message : String(err);
387
+ console.error(`[hsq] failed to save ${RUNS_DB_FILE}: ${message}`);
388
+ }
389
+ break;
390
+ }
391
+ }
392
+ if (evict)
393
+ this.evictSettled();
394
+ }
395
+ }
396
+ //# sourceMappingURL=run-persistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-persistence.js","sourceRoot":"","sources":["../../src/runs/run-persistence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAsC,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAkB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAuB,MAAM,uBAAuB,CAAC;AAClF,OAAO,EACL,YAAY,EAAE,gBAAgB,GAE/B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAW5C,gGAAgG;AAChG,MAAM,UAA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AC;gBACpE,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,KAAK;YAAE,IAAI,CAAC,YAAY,EAAE,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,190 @@
1
+ import type { ArchivedRunsResponse, RunSummary } from '../contract/index.js';
2
+ import { type AutomationNames } from '../contract/index.js';
3
+ import { type BranchOwner } from './branch-owners.ts';
4
+ import type { ColdReadCache, StoredRow } from './cold-reads.ts';
5
+ import type { RunFamilyReads, RunQueries } from './ports.ts';
6
+ import type { RunColdReadsTopic } from './run-cold-reads.ts';
7
+ import { type RunDatabase } from './run-database.ts';
8
+ import type { RunPinHolder } from './run-pins.ts';
9
+ import { type ListOrder } from './run-row.ts';
10
+ import { type PeerTaskPageOptions } from './run-summary-page.ts';
11
+ import type { RunRecord } from './store.ts';
12
+ /** The items newest first, each by the order beside it. Stable: ties keep their input order. */
13
+ export declare function sortNewestFirst<T>(entries: Iterable<readonly [T, ListOrder]>): T[];
14
+ /** What the topic asks of the store; no import of `store.ts` values. */
15
+ export interface QueriesState {
16
+ /** The open database; null for an unavailable or closed store. */
17
+ db(): RunDatabase | null;
18
+ readonly held: Map<string, RunRecord>;
19
+ readonly pins: Map<string, Set<RunPinHolder>>;
20
+ readonly deleted: Set<string>;
21
+ readonly unreadable: Set<string>;
22
+ readonly base: Map<string, StoredRow>;
23
+ readonly coldReads: Pick<ColdReadCache, 'scope'>;
24
+ readonly rows: Pick<RunColdReadsTopic, 'loadCold' | 'decodeCold' | 'fromRow'>;
25
+ /** The store's `getRun`, so a spy on it sees the queries' reads. */
26
+ getRun(id: string): RunRecord | undefined;
27
+ }
28
+ export declare class RunQueriesTopic implements RunQueries, RunFamilyReads {
29
+ private readonly state;
30
+ constructor(state: QueriesState);
31
+ private get db();
32
+ private get held();
33
+ private get pins();
34
+ private get deleted();
35
+ private get unreadable();
36
+ private get base();
37
+ private get coldReads();
38
+ private loadCold;
39
+ private decodeCold;
40
+ private fromRow;
41
+ private getRun;
42
+ /**
43
+ * The live set, newest first: runs whose record is live (`isLiveRecord`) or that a RunManager
44
+ * pins. Finished runs are not here — read one by id (`getRun`), by an indexed query
45
+ * (`listWorkersOf`, `findRunByClientRequestId`, `listRunsWithWorktree`,
46
+ * `listBranchOwners`), or as list rows (`listRunSummaries`).
47
+ */
48
+ listRuns(): RunRecord[];
49
+ /** Where a held run lists: its row's insertion order, or after every row while this store has
50
+ * not written it yet. The held set keeps such runs in creation order, and so does every list
51
+ * that sorts them in held-set order (`sortNewestFirst` is stable). */
52
+ listOrder(run: RunRecord): ListOrder;
53
+ /**
54
+ * EVERY run as a full record, newest first — decoded row by row. Only the legacy `GET /runs`
55
+ * (older clients; the cockpit reads `GET /run-summaries`) may call this: it is exactly the
56
+ * whole-history parse #779 exists to remove from everything else.
57
+ */
58
+ listAllRunsForLegacyRoute(): RunRecord[];
59
+ /** A bounded page of discoverable peer roots, including the current held overlay. */
60
+ listPeerTaskSummaries(options: PeerTaskPageOptions): {
61
+ runs: RunSummary[];
62
+ nextOffset?: number;
63
+ };
64
+ /**
65
+ * Every run as its list row, newest first: the stored `summary` column, with each held run's
66
+ * own projection laid over it — a debounced save keeps memory up to 300 ms ahead of the row,
67
+ * and a run created since the last save has no row yet. `usage` is the caller's to attach.
68
+ *
69
+ * With `archivedWindow` (#864), the window the cockpit's lists read: every unarchived run, plus
70
+ * the newest `archivedWindow` archived ROOT runs, and whether older archived roots were left
71
+ * out. Archived workers are never in it (see `RunDatabase.listWindowSummaries`); with `roots`,
72
+ * no worker is — the runs index, whose readers list no workers. A held run
73
+ * lists by its record, so one archived or unarchived since the last save is ranked as it is now.
74
+ *
75
+ * A row this store found unreadable is left out, as the cold reader leaves out a row it had to
76
+ * decode and could not. A finished row nobody has decoded is served from its summary by both,
77
+ * which decodes nothing; reading it is what finds out (`isUnreadable`).
78
+ */
79
+ listRunSummaries(options?: {
80
+ archivedWindow?: number | undefined;
81
+ roots?: boolean;
82
+ }): {
83
+ runs: RunSummary[];
84
+ truncated: boolean;
85
+ };
86
+ /**
87
+ * One page of archived ROOT runs, newest first (#864): `GET /run-summaries/archived`, the
88
+ * archived runs past the window. Held runs list by their record, as in `listRunSummaries`.
89
+ * `before` is the previous page's `nextCursor`; with `q`, only runs `matchesRunSearch` keeps, and
90
+ * `total` counts those. `automationNames` lets `q` match a task by its automation's name, as the
91
+ * list's origin line shows it (hearsay-tools/cezarion#1616). A cursor this store did not write
92
+ * answers `{ error }`.
93
+ *
94
+ * Ranking reads every archived root's key (id, created_at, seq: no record, no summary), so the
95
+ * page and `total` agree with the held overlay; only the page's own rows are read in full.
96
+ */
97
+ listArchivedRuns(options: {
98
+ before?: string;
99
+ limit: number;
100
+ q?: string;
101
+ automationNames?: AutomationNames;
102
+ }): ArchivedRunsResponse | {
103
+ error: string;
104
+ };
105
+ /** The archived roots in `runs.db`, each by its key: every one without `q` (no record, no
106
+ * summary read), and with `q` the searched rows `matchesRunSearch` keeps, which carry the summary
107
+ * the search read. A deleted, held or unreadable run's row is left out; a held run joins in
108
+ * `overlayHeldArchived`. */
109
+ private rankArchivedRows;
110
+ /** Lay the held archived roots over `ranked`, each by its record: it replaces its stored row
111
+ * (already left out of `ranked`), and with `q` it must match. A held worker never lists. */
112
+ private overlayHeldArchived;
113
+ /** The page of `ordered` after the cursor `after`: its summaries, the cursor of the next page,
114
+ * and `total`, the count of all of `ordered`. */
115
+ private archivedPage;
116
+ /** The page's summaries: a ranked key's own, else its stored one, read for the rows that have
117
+ * none in a single query. A row whose stored summary does not fit the contract is projected from
118
+ * its record; a row that cannot be read at all is left out. */
119
+ private hydrateArchivedPage;
120
+ /**
121
+ * The ROOT runs, archived or not, that match `query` (`matchesRunSearch`), newest first: at most
122
+ * `limit`, and whether more matched. The owned half of the workspace search (#864); held runs
123
+ * match by their record.
124
+ */
125
+ searchRunSummaries(query: string, limit: number): {
126
+ runs: RunSummary[];
127
+ truncated: boolean;
128
+ };
129
+ /** A row whose stored summary does not fit the contract any more, projected from its record. */
130
+ private coldSummary;
131
+ /** Run `fn` reading each run that is not held at most once (`ColdReadCache`, hearsay-tools/cezarion#2378). */
132
+ withReadCache<T>(fn: () => T): T;
133
+ /** The ids in memory right now: the held set, for diagnostics and the benchmark's heap pass. */
134
+ heldIds(): string[];
135
+ /**
136
+ * The workers a root run owns, newest first, read off its own `receipts` (#659). Every
137
+ * `createOwnedRun` writes the receipt and the worker record in one transaction, and the
138
+ * receipt list is capped at 1,024 creations (#816), so this is a bounded lookup rather than a walk of the whole
139
+ * project index. An ordinary or worker run owns nothing and costs one map read; a receipt
140
+ * whose record has been deleted is skipped, never invented. A parent quarantined to
141
+ * `invalid` has no readable receipts and reports none, which is also what the cockpit
142
+ * assumes for that role.
143
+ */
144
+ listOwnedWorkers(parentId: string): RunRecord[];
145
+ /** Every worker filed under `parentId` (the `parent_run_id` index plus memory), newest first:
146
+ * receipts or not, which is what the reconcile and deletion checks ask. */
147
+ listWorkersOf(parentId: string): RunRecord[];
148
+ /** The id of every worker, held or stored, without decoding any (recovery's worker passes). */
149
+ listWorkerIds(): string[];
150
+ /** The id of every run whose delegation is quarantined (`invalid`), held or stored: its stored
151
+ * summary says so, so nothing is decoded (scratch cleanup). */
152
+ listQuarantinedRunIds(): string[];
153
+ /** All retained tasks this automation started, including variants, finished and archived runs.
154
+ * Logs and receipts may compact independently. Read only matching keys in SQLite and overlay
155
+ * held records so a debounced provenance update or deletion is reflected immediately. */
156
+ countAutomationRuns(automationId: string): number;
157
+ /** First non-archived task referencing a project issue, including secondary references. */
158
+ findNonArchivedRunByIssue(repo: string, number: number): string | undefined;
159
+ /**
160
+ * The runs automation receipts launched, by receipt id (`automation.receiptId` or
161
+ * `automationTrigger.receiptId`). Memory answers first; a receipt it does not know costs one
162
+ * pass over `runs.db` that reads the records' JSON in SQLite — only a crash leftover (a
163
+ * receipt still `reserved` at startup) ever asks.
164
+ */
165
+ findRunIdsByAutomationReceipt(receiptIds: readonly string[]): Map<string, string>;
166
+ /** The id of every root whose delegation carries a conversation, held or stored: recovery's full
167
+ * reconcile pass (#661). `naming` keeps the ledgers whose messages name that run id as sender or
168
+ * recipient. Stored roots come from the `conversation_members` index, so no record is read. */
169
+ listConversationRootIds(naming?: string): string[];
170
+ /** The id of every run, held or stored, without decoding any (orphan-worktree sweeps). */
171
+ listRunIds(): string[];
172
+ /** Runs with a materialized worktree directory (`worktreePath`, not reclaimed), most recently
173
+ * finished first, then newest first: worktree retention and the worktrees panel. */
174
+ listRunsWithWorktree(): RunRecord[];
175
+ /**
176
+ * Every run that owns a branch or names the PR it created, as the few fields branch cleanup and
177
+ * git-log attribution read (issue 08 §B3, §B5; a squash commit is attributed by its PR number):
178
+ * the stored summary plus the `branch` and `base_branch` columns, so a Git-tab request decodes
179
+ * no record. Held runs answer from memory.
180
+ */
181
+ listBranchOwners(): BranchOwner[];
182
+ /** The rows a column query returned, as records, with memory laid over them: a held run
183
+ * answers from memory (matching `matches` there, not on its maybe-older row). */
184
+ private queryRuns;
185
+ /** The run an idempotent start already created (#504), archived or not. A deleted run is gone
186
+ * with its record, so a retry after deletion honestly creates a fresh one. */
187
+ findRunByClientRequestId(clientRequestId: string): RunRecord | undefined;
188
+ /** Indexed family enumeration, including members not yet flushed to SQLite. */
189
+ listFamilyRunIds(rootId: string): string[];
190
+ }