@hearsay-tools/squawk 0.18.0-dev.7816 → 0.18.0-dev.7825

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 (128) hide show
  1. package/dist/activity/publisher.js +2 -2
  2. package/dist/activity/publisher.js.map +1 -1
  3. package/dist/activity/read-model.js +1 -1
  4. package/dist/activity/read-model.js.map +1 -1
  5. package/dist/activity/requests.d.ts +4 -2
  6. package/dist/activity/requests.js +1 -1
  7. package/dist/activity/requests.js.map +1 -1
  8. package/dist/artifacts/reports-index.d.ts +4 -7
  9. package/dist/artifacts/reports-index.js +7 -7
  10. package/dist/artifacts/reports-index.js.map +1 -1
  11. package/dist/ci-wait/controller.d.ts +42 -42
  12. package/dist/delegation/conversations.d.ts +6 -2
  13. package/dist/delegation/conversations.js +3 -2
  14. package/dist/delegation/conversations.js.map +1 -1
  15. package/dist/delegation/family-end.d.ts +4 -2
  16. package/dist/delegation/results.js +2 -2
  17. package/dist/delegation/results.js.map +1 -1
  18. package/dist/delegation/routes.d.ts +65 -65
  19. package/dist/delegation/routes.js +1 -1
  20. package/dist/delegation/routes.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/service.js +2 -2
  24. package/dist/delegation/service.js.map +1 -1
  25. package/dist/delegation/transport.d.ts +65 -65
  26. package/dist/delegation/worker-cleanup.js +1 -1
  27. package/dist/delegation/worker-cleanup.js.map +1 -1
  28. package/dist/preview/host.d.ts +2 -1
  29. package/dist/preview/host.js +1 -1
  30. package/dist/preview/host.js.map +1 -1
  31. package/dist/project-migration/live.js +3 -3
  32. package/dist/project-migration/live.js.map +1 -1
  33. package/dist/runs/claim-families.d.ts +1 -1
  34. package/dist/runs/claim-families.js +1 -1
  35. package/dist/runs/lifecycle.d.ts +2 -1
  36. package/dist/runs/lifecycle.js.map +1 -1
  37. package/dist/runs/live-tasks.js +1 -1
  38. package/dist/runs/live-tasks.js.map +1 -1
  39. package/dist/runs/loaded-run-exits.d.ts +23 -0
  40. package/dist/runs/loaded-run-exits.js +46 -1
  41. package/dist/runs/loaded-run-exits.js.map +1 -1
  42. package/dist/runs/ports.d.ts +38 -14
  43. package/dist/runs/retention.d.ts +3 -1
  44. package/dist/runs/retention.js +5 -5
  45. package/dist/runs/retention.js.map +1 -1
  46. package/dist/runs/run-claims-topic.d.ts +130 -0
  47. package/dist/runs/run-claims-topic.js +258 -0
  48. package/dist/runs/run-claims-topic.js.map +1 -0
  49. package/dist/runs/run-claims.d.ts +1 -1
  50. package/dist/runs/run-claims.js +1 -1
  51. package/dist/runs/run-claims.js.map +1 -1
  52. package/dist/runs/run-database.d.ts +1 -1
  53. package/dist/runs/run-index.js +3 -1
  54. package/dist/runs/run-index.js.map +1 -1
  55. package/dist/runs/run-persistence.d.ts +150 -0
  56. package/dist/runs/run-persistence.js +396 -0
  57. package/dist/runs/run-persistence.js.map +1 -0
  58. package/dist/runs/run-pins.d.ts +38 -0
  59. package/dist/runs/run-pins.js +45 -0
  60. package/dist/runs/run-pins.js.map +1 -0
  61. package/dist/runs/run-references.d.ts +1 -1
  62. package/dist/runs/run-references.js +1 -1
  63. package/dist/runs/run-references.js.map +1 -1
  64. package/dist/runs/run-retention.d.ts +6 -2
  65. package/dist/runs/run-retention.js +11 -2
  66. package/dist/runs/run-retention.js.map +1 -1
  67. package/dist/runs/store-open.d.ts +45 -0
  68. package/dist/runs/store-open.js +89 -0
  69. package/dist/runs/store-open.js.map +1 -0
  70. package/dist/runs/store.d.ts +9 -209
  71. package/dist/runs/store.js +88 -802
  72. package/dist/runs/store.js.map +1 -1
  73. package/dist/runs/webhook.d.ts +3 -1
  74. package/dist/runs/webhook.js +2 -2
  75. package/dist/runs/webhook.js.map +1 -1
  76. package/dist/serve-boot.d.ts +2 -2
  77. package/dist/server/completion-actions.js +2 -2
  78. package/dist/server/completion-actions.js.map +1 -1
  79. package/dist/server/models-routes.d.ts +13 -13
  80. package/dist/server/project-run-files.d.ts +3 -1
  81. package/dist/server/project-run-files.js +3 -3
  82. package/dist/server/project-run-files.js.map +1 -1
  83. package/dist/server/provider-sign-in-routes.d.ts +2 -2
  84. package/dist/server/reports-api.d.ts +2 -2
  85. package/dist/server/run-checkout.d.ts +3 -1
  86. package/dist/server/run-checkout.js +3 -3
  87. package/dist/server/run-checkout.js.map +1 -1
  88. package/dist/server/run-event-feed.js +2 -2
  89. package/dist/server/run-event-feed.js.map +1 -1
  90. package/dist/server/runner-install-routes.d.ts +10 -10
  91. package/dist/server/server.d.ts +1593 -1593
  92. package/dist/server/server.js +9 -9
  93. package/dist/server/server.js.map +1 -1
  94. package/dist/server/start-server.js +1 -1
  95. package/dist/server/start-server.js.map +1 -1
  96. package/dist/workflows/run/continuation-acceptance.js +2 -2
  97. package/dist/workflows/run/continuation-acceptance.js.map +1 -1
  98. package/dist/workflows/run/family-reconciler.d.ts +2 -1
  99. package/dist/workflows/run/family-reconciler.js +2 -2
  100. package/dist/workflows/run/family-reconciler.js.map +1 -1
  101. package/dist/workflows/run/maintenance-claims.js +6 -6
  102. package/dist/workflows/run/maintenance-claims.js.map +1 -1
  103. package/dist/workflows/run/native-skill-input-queue.js +1 -1
  104. package/dist/workflows/run/native-skill-input-queue.js.map +1 -1
  105. package/dist/workflows/run/queued-revival.js +3 -3
  106. package/dist/workflows/run/queued-revival.js.map +1 -1
  107. package/dist/workflows/run/run-cancel.js +5 -5
  108. package/dist/workflows/run/run-cancel.js.map +1 -1
  109. package/dist/workflows/run/run-finish.js +1 -1
  110. package/dist/workflows/run/run-finish.js.map +1 -1
  111. package/dist/workflows/run/run-recovery.js +3 -3
  112. package/dist/workflows/run/run-recovery.js.map +1 -1
  113. package/dist/workflows/run/run-settlement.js +5 -5
  114. package/dist/workflows/run/run-settlement.js.map +1 -1
  115. package/dist/workflows/run/step-loop.js +4 -4
  116. package/dist/workflows/run/step-loop.js.map +1 -1
  117. package/dist/workflows/run/turn-nudges.js +1 -1
  118. package/dist/workflows/run/turn-nudges.js.map +1 -1
  119. package/dist/workflows/run/turn-settler.js +1 -1
  120. package/dist/workflows/run/turn-settler.js.map +1 -1
  121. package/dist/workflows/run/usage-accounting.js +1 -1
  122. package/dist/workflows/run/usage-accounting.js.map +1 -1
  123. package/dist/workflows/run.js +7 -7
  124. package/dist/workflows/run.js.map +1 -1
  125. package/package.json +4 -4
  126. package/scripts/benchmark-family-reconcile.ts +1 -1
  127. package/scripts/benchmark-run-store.ts +5 -5
  128. package/scripts/benchmark-workspace-events.ts +2 -2
@@ -0,0 +1,150 @@
1
+ import { type ColdReadCache, type StoredRow } from './cold-reads.ts';
2
+ import { type RunLifecycle } from './lifecycle.ts';
3
+ import type { LiveItemSnapshots } from './live-item-snapshots.ts';
4
+ import type { RunPersistence } from './ports.ts';
5
+ import type { RunArchiveTopic } from './run-archive.ts';
6
+ import { type ClaimOwner } from './run-claims.ts';
7
+ import { type RunClaimsTopic } from './run-claims-topic.ts';
8
+ import { type RunDatabase, type RunDatabaseChanges, type RunDatabaseCommit } from './run-database.ts';
9
+ import type { RunExitId } from './run-exits.ts';
10
+ import type { RunRetentionTopic } from './run-retention.ts';
11
+ import type { RunStoreOpenError } from './store-open-error.ts';
12
+ import type { DecodedRun, RepoHandle, RunRecord } from './store.ts';
13
+ /** Per-store persistence adapter; the second argument is the normal fenced transaction. */
14
+ export type RunStorePersistence = (changes: RunDatabaseChanges, transaction: RunDatabase['transaction']) => RunDatabaseCommit;
15
+ /** Why a `run` event fired, when a delegation checkpoint caused it or nothing durable changed
16
+ * (`republish`) (in-process only). */
17
+ export type CommitSource = 'delegation-checkpoint' | 'delegation-destroy-progress' | 'live-release';
18
+ /** Make `target` hold exactly `source`'s fields, keeping the object every holder references. */
19
+ export declare function replaceRecord(target: RunRecord, source: RunRecord): void;
20
+ /** What the topic asks of the store; no import of `store.ts` values. */
21
+ export interface PersistenceState {
22
+ /** The open database; null for an unavailable or closed store. */
23
+ db(): RunDatabase | null;
24
+ /** This store's identity in `run_claims`; undefined without a database. */
25
+ owner(): ClaimOwner | undefined;
26
+ /** Why `open` failed, in a `RunStore.unavailable` store. */
27
+ openFailure(): RunStoreOpenError | undefined;
28
+ /** The repository this project is, once `setRepoHandle` armed it. */
29
+ repoHandle(): RepoHandle | null | undefined;
30
+ readonly held: Map<string, RunRecord>;
31
+ readonly committing: Set<string>;
32
+ readonly dirty: Set<string>;
33
+ readonly deleted: Set<string>;
34
+ readonly historyOwed: Set<string>;
35
+ readonly quarantined: Set<string>;
36
+ readonly claimed: Map<string, number>;
37
+ readonly pendingClaims: Map<string, {
38
+ session: string;
39
+ generation: number;
40
+ } | null>;
41
+ readonly base: Map<string, StoredRow>;
42
+ readonly coldBase: Map<string, StoredRow & {
43
+ owned: boolean;
44
+ }>;
45
+ readonly coldReads: Pick<ColdReadCache, 'forget'>;
46
+ readonly liveItems: Pick<LiveItemSnapshots, 'forget'>;
47
+ readonly published: RunLifecycle;
48
+ readonly archive: Pick<RunArchiveTopic, 'completionArchiveBlocker' | 'stageArchive' | 'maybeEnqueueHistoryCompress' | 'compressor'>;
49
+ readonly claims: Pick<RunClaimsTopic, 'claimFamilies' | 'runOwnership' | 'fallbackRefusal' | 'isFallbackRun'>;
50
+ readonly retention: Pick<RunRetentionTopic, 'removeOwedHistory'>;
51
+ decodeRunRow(data: string): DecodedRun | undefined;
52
+ /** Read held legacy family members, or a detached cold record. */
53
+ peek(id: string): RunRecord | undefined;
54
+ /** Whether a held run anchors itself (and its family) in memory. */
55
+ isAnchor(id: string, run: RunRecord): boolean;
56
+ /** Drop every held run that is neither an anchor nor in an anchored family. */
57
+ evictSettled(): void;
58
+ }
59
+ export declare class RunPersistenceTopic implements RunPersistence {
60
+ private readonly dataDir;
61
+ private readonly persistence;
62
+ private readonly state;
63
+ private saveTimer;
64
+ /** The family of each pending deletion, whose claim the deleting write is fenced against. */
65
+ private readonly deletedFamilies;
66
+ constructor(dataDir: string, persistence: RunStorePersistence | undefined, state: PersistenceState);
67
+ private get db();
68
+ private get owner();
69
+ private get openFailure();
70
+ private get repoHandle();
71
+ private get held();
72
+ private get committing();
73
+ private get dirty();
74
+ private get deleted();
75
+ private get historyOwed();
76
+ private get quarantined();
77
+ private get claimed();
78
+ private get pendingClaims();
79
+ private get base();
80
+ private get coldBase();
81
+ private get coldReads();
82
+ private get liveItems();
83
+ private get published();
84
+ private get archive();
85
+ private get claims();
86
+ private get retention();
87
+ private peek;
88
+ private isAnchor;
89
+ private evictSettled;
90
+ /** Persistence source for consumers that build the reports index. No index is created here. */
91
+ reportSource(): {
92
+ db: RunDatabase | null;
93
+ dataDir: string;
94
+ openFailure: RunStoreOpenError | undefined;
95
+ };
96
+ /**
97
+ * Durably replace or delete staged rows together with pending dirty rows. Persist before
98
+ * changing held objects or notifying subscribers. On failure retain all pending state; flush()
99
+ * remains best-effort.
100
+ */
101
+ commitIndex(input: ReadonlyMap<string, RunRecord | null>, source?: CommitSource, write?: {
102
+ before?: ReadonlyMap<string, Readonly<RunRecord>>;
103
+ exits?: ReadonlyMap<string, RunExitId | undefined>;
104
+ }): void;
105
+ /**
106
+ * Refuse (throwing, with nothing changed) a commit that stages a quarantined run, or a run whose
107
+ * family this store does not claim and cannot take: another process owns it, or a dead process
108
+ * left it live and it has not been adopted.
109
+ */
110
+ assertWritable(staged: ReadonlyMap<string, RunRecord | null>): void;
111
+ /** The family of a run this store knows: held, else its row; a run nowhere is its own. */
112
+ familyOf(id: string): string;
113
+ /** Schedule the sweep that lets any of `ids` leave memory, when one of them now can. */
114
+ sweepIfSettled(ids: Iterable<string>): void;
115
+ /** Write the pending rows out now (used on shutdown). */
116
+ flush(): void;
117
+ /** `RunStore.close`'s final save: what is pending goes out, and nothing leaves memory. */
118
+ closeSave(): void;
119
+ /** Save `run` debounced and publish it; `before` is the record at the write's entry (none: created). */
120
+ touch(run: RunRecord, before: Readonly<RunRecord> | undefined, exit?: RunExitId): void;
121
+ /** The held record is gone; the next save or commit deletes its row, fenced by `family`'s claim
122
+ * and by the revision this store last saw (kept in `base` until the delete is written). */
123
+ markDeleted(id: string, family: string): void;
124
+ /** Debounced so token-usage updates don't rewrite a row per event. Nothing to schedule without
125
+ * a database: a `RunStore.unavailable` store, or a closed one, writes nothing. */
126
+ scheduleSave(): void;
127
+ /** The single database write, so a test can fail it the way a full disk would. */
128
+ private writeIndex;
129
+ /**
130
+ * Write `staged` plus everything still pending — dirty rows from memory, deletions — in one
131
+ * transaction, then clear the pending marks. Throws with nothing cleared when it fails.
132
+ * Never copies or sorts the whole store: the cost is the rows that changed.
133
+ *
134
+ * Fenced (#779, plan step 3): the transaction commits only if every family it writes still
135
+ * carries this store's claim and every row is at the revision this store last saw. Otherwise
136
+ * nothing is written and `handleConflicts` deals with the rows that changed under it.
137
+ */
138
+ private persist;
139
+ /** What a write of these rows (id → family) must still find: this store's claims, at the
140
+ * generations it took them, and each row at the revision it last saw (none for a new row). */
141
+ private fence;
142
+ /**
143
+ * Handle a fenced-write conflict. Save unexpected conflict evidence before clearing pending
144
+ * state or quarantining the row. If evidence persistence fails, retain pending writes. Other
145
+ * rows remain writable; stale unclaimed reads only fail their write.
146
+ */
147
+ private handleConflicts;
148
+ /** Write what is pending, then (unless closing) let every run whose write settled leave memory. */
149
+ private saveNow;
150
+ }
@@ -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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AAI,CAAC,WAAW,CAAC,IAAI,GAAG,WAAW;oBAAE,SAAS;gBACrF,qFAAqF;gBACrF,uFAAuF;gBACvF,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC7B,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBACjE,OAAO,CAAC,KAAK,CAAC,wBAAwB,YAAY,KAAK,OAAO,EAAE,CAAC,CAAC;gBACpE,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,KAAK;YAAE,IAAI,CAAC,YAAY,EAAE,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The holds that keep a run loaded while a process works on it (hearsay-tools/squawk#4042), and
3
+ * the publish of a held record without a write. `RunStore` keeps one of these as `store.runPins`.
4
+ * The user's pin (`setPinned`) is a read flag (`run-read-flags.ts`).
5
+ */
6
+ import { type RunLifecycle } from './lifecycle.ts';
7
+ import type { RunPins } from './ports.ts';
8
+ import type { RunRecord } from './store.ts';
9
+ /** Who may hold a run in memory besides its own record (see `RunPinsTopic.pin`). `maintenance` is the
10
+ * RunManager's publish, worktree-reclaim and branch-cleanup claims, held across their async work. */
11
+ export type RunPinHolder = 'active' | 'continue' | 'cleanup' | 'maintenance';
12
+ /** What the topic asks of the store; no import of `store.ts` values. */
13
+ export interface PinsState {
14
+ /** Who holds a run beyond its record, by holder, so one holder's unpin never releases another. */
15
+ readonly pins: Map<string, Set<RunPinHolder>>;
16
+ readonly published: Pick<RunLifecycle, 'publish'>;
17
+ /** The record a store write changes in place: held, or loaded to be. */
18
+ record(id: string): RunRecord | undefined;
19
+ /** Read held legacy family members, or a detached cold record. */
20
+ peek(id: string): RunRecord | undefined;
21
+ sweepIfSettled(ids: Iterable<string>): void;
22
+ }
23
+ export declare class RunPinsTopic implements RunPins {
24
+ private readonly state;
25
+ constructor(state: PinsState);
26
+ /**
27
+ * Keep a run in memory for `holder` until `unpin(id, holder)`: a RunManager pins the runs it is
28
+ * executing (`active`) and the run a Continue is admitting (`continue`). A finished run is
29
+ * loaded. Pins are per holder, so releasing one never releases another. Returns the held record.
30
+ */
31
+ pin(id: string, holder: RunPinHolder): RunRecord | undefined;
32
+ /** Publish a run's current record again without a write: something read beside the record
33
+ * changed, such as the run leaving the manager's live registries, which a detail's finish
34
+ * verdict reads (hearsay-tools/cezarion#1301). */
35
+ republish(id: string): void;
36
+ /** Release `holder`'s pin. The run leaves memory at the next sweep once nothing else holds it. */
37
+ unpin(id: string, holder: RunPinHolder): void;
38
+ }