@robhowley/pi-remembrancer 0.5.1 → 0.6.0
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/README.md +58 -17
- package/extensions/remembrancer/capture-artifacts.ts +211 -0
- package/extensions/remembrancer/capture-handoff.ts +712 -0
- package/extensions/remembrancer/capture-jobs.ts +111 -0
- package/extensions/remembrancer/capture-matches.ts +145 -0
- package/extensions/remembrancer/capture-notices.ts +51 -0
- package/extensions/remembrancer/capture-publication-lock.mjs +37 -0
- package/extensions/remembrancer/capture-review.ts +84 -12
- package/extensions/remembrancer/capture-sizing.ts +63 -0
- package/extensions/remembrancer/capture-submission.ts +289 -0
- package/extensions/remembrancer/capture-worker-bootstrap.mjs +53 -0
- package/extensions/remembrancer/capture-worker.ts +336 -0
- package/extensions/remembrancer/capture.ts +259 -135
- package/extensions/remembrancer/checkpoints.ts +603 -116
- package/extensions/remembrancer/config.ts +31 -1
- package/extensions/remembrancer/evidence.ts +318 -74
- package/extensions/remembrancer/index.ts +260 -14
- package/extensions/remembrancer/private-sqlite.mjs +17 -0
- package/extensions/remembrancer/proposal-read.ts +223 -9
- package/extensions/remembrancer/proposal-ui.ts +597 -191
- package/extensions/remembrancer/proposals.ts +44 -9
- package/extensions/remembrancer/review-findings.ts +178 -0
- package/extensions/remembrancer/review-pages.ts +58 -16
- package/extensions/remembrancer/review-plan.ts +27 -0
- package/extensions/remembrancer/reviewer-budget.ts +53 -0
- package/extensions/remembrancer/reviewer.ts +166 -30
- package/extensions/remembrancer/taskwarrior.ts +95 -14
- package/package.json +5 -4
- package/skills/remembrancer/SKILL.md +35 -19
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { dirname, isAbsolute, join } from 'node:path';
|
|
5
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
5
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
6
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
6
7
|
|
|
8
|
+
import { openPrivateSqlite } from './private-sqlite.mjs';
|
|
7
9
|
import { CaptureReview } from './capture-review.js';
|
|
10
|
+
import {
|
|
11
|
+
CAPTURE_MAX_ATTEMPTS,
|
|
12
|
+
CAPTURE_RETRY_DELAY_MS,
|
|
13
|
+
CapturePreparationError,
|
|
14
|
+
CaptureRetryableError,
|
|
15
|
+
CaptureWorkerOwnership,
|
|
16
|
+
type CaptureAttempt,
|
|
17
|
+
type CaptureJob,
|
|
18
|
+
type CaptureStatus,
|
|
19
|
+
} from './capture-jobs.js';
|
|
20
|
+
import { physicalInbox, validateReadyManifest, type ReadyManifest } from './capture-handoff.js';
|
|
21
|
+
import { prepareHistoricalReview } from './evidence.js';
|
|
8
22
|
import {
|
|
9
23
|
validateDraft,
|
|
10
24
|
validateSnapshot,
|
|
25
|
+
unionProposalSources,
|
|
11
26
|
type Proposal,
|
|
12
27
|
type ProposalDraft,
|
|
13
28
|
type ProposalSubmission,
|
|
@@ -25,7 +40,7 @@ export type FinishPlan = {
|
|
|
25
40
|
checkpoints?: readonly (Tip | Checkpoint)[];
|
|
26
41
|
};
|
|
27
42
|
|
|
28
|
-
function
|
|
43
|
+
export function defaultCheckpointFile(): string {
|
|
29
44
|
const state = process.env['XDG_STATE_HOME'];
|
|
30
45
|
return join(
|
|
31
46
|
state && isAbsolute(state) ? state : join(homedir(), '.local', 'state'),
|
|
@@ -35,18 +50,8 @@ function defaultFile(): string {
|
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
function openPrivate(filename: string): DatabaseSync {
|
|
38
|
-
if (filename !== ':memory:') {
|
|
39
|
-
|
|
40
|
-
// Closing a second descriptor for an existing SQLite file can drop this
|
|
41
|
-
// process's POSIX locks, even those held by another DatabaseSync instance.
|
|
42
|
-
try {
|
|
43
|
-
closeSync(openSync(filename, 'ax', 0o600));
|
|
44
|
-
} catch (error) {
|
|
45
|
-
if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;
|
|
46
|
-
chmodSync(filename, 0o600);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return new DatabaseSync(filename);
|
|
53
|
+
if (filename !== ':memory:') mkdirSync(dirname(filename), { recursive: true, mode: 0o700 });
|
|
54
|
+
return openPrivateSqlite(filename);
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
function absoluteTimestamp(value: string | null | undefined): string | null {
|
|
@@ -67,15 +72,36 @@ function checkpointFromTip(tip: Tip): Checkpoint {
|
|
|
67
72
|
return { ...tip, since: candidate.since ?? null };
|
|
68
73
|
}
|
|
69
74
|
|
|
75
|
+
// Unsupported rows fence their session even when their order cannot be interpreted.
|
|
76
|
+
const predecessor = `SELECT earlier.id FROM capture_jobs AS earlier
|
|
77
|
+
WHERE earlier.id <> job.id AND earlier.session_id = job.session_id
|
|
78
|
+
AND earlier.state <> 'completed'
|
|
79
|
+
AND (json_extract(earlier.body, '$.version') IS NOT 3
|
|
80
|
+
OR earlier.admission_order < job.admission_order)
|
|
81
|
+
ORDER BY earlier.admission_order LIMIT 1`;
|
|
82
|
+
|
|
70
83
|
export class CheckpointStore {
|
|
71
84
|
private db: DatabaseSync;
|
|
72
85
|
private filename: string;
|
|
73
86
|
private reviewLock: DatabaseSync | undefined;
|
|
74
|
-
private
|
|
87
|
+
private jobCapture:
|
|
88
|
+
| {
|
|
89
|
+
owner: CaptureWorkerOwnership;
|
|
90
|
+
attempt: CaptureAttempt;
|
|
91
|
+
review: CaptureReview;
|
|
92
|
+
generation: number;
|
|
93
|
+
body: string;
|
|
94
|
+
}
|
|
95
|
+
| undefined;
|
|
75
96
|
|
|
76
|
-
|
|
97
|
+
get file(): string {
|
|
98
|
+
return this.filename;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
constructor(filename = defaultCheckpointFile()) {
|
|
77
102
|
this.filename = filename;
|
|
78
103
|
this.db = openPrivate(filename);
|
|
104
|
+
if (filename !== ':memory:') this.filename = realpathSync(filename);
|
|
79
105
|
try {
|
|
80
106
|
this.db.exec('PRAGMA busy_timeout = 5000; BEGIN IMMEDIATE;');
|
|
81
107
|
this.db.exec(`
|
|
@@ -98,6 +124,72 @@ export class CheckpointStore {
|
|
|
98
124
|
id TEXT PRIMARY KEY, revision INTEGER NOT NULL, state TEXT NOT NULL,
|
|
99
125
|
body TEXT NOT NULL
|
|
100
126
|
)`);
|
|
127
|
+
this.db.exec(`
|
|
128
|
+
CREATE TABLE IF NOT EXISTS review_context (
|
|
129
|
+
singleton INTEGER PRIMARY KEY CHECK(singleton = 1),
|
|
130
|
+
generation INTEGER NOT NULL, notice_generation INTEGER NOT NULL
|
|
131
|
+
);
|
|
132
|
+
INSERT OR IGNORE INTO review_context VALUES (1, 0, 0);
|
|
133
|
+
CREATE TABLE IF NOT EXISTS capture_jobs (
|
|
134
|
+
id TEXT PRIMARY KEY, session_id TEXT NOT NULL, snapshot TEXT NOT NULL,
|
|
135
|
+
accepted_at TEXT NOT NULL, admission_order TEXT NOT NULL, body TEXT NOT NULL, state TEXT NOT NULL CHECK(state IN ('queued', 'completed', 'failed')),
|
|
136
|
+
retry_eligible INTEGER NOT NULL CHECK(retry_eligible IN (0, 1)), diagnostic TEXT,
|
|
137
|
+
CHECK ((state = 'queued' AND retry_eligible = 1 AND diagnostic IS NULL)
|
|
138
|
+
OR (state = 'completed' AND retry_eligible = 0 AND diagnostic IS NULL)
|
|
139
|
+
OR (state = 'failed' AND diagnostic IS NOT NULL AND length(trim(diagnostic)) > 0))
|
|
140
|
+
);
|
|
141
|
+
`);
|
|
142
|
+
// Triggers keep each mutation and its generation in the same transaction,
|
|
143
|
+
// including existing single-statement manual proposal/application writes.
|
|
144
|
+
for (const table of ['sources', 'reviewed_boundaries', 'proposals']) {
|
|
145
|
+
for (const operation of ['INSERT', 'UPDATE', 'DELETE']) {
|
|
146
|
+
this.db.exec(`DROP TRIGGER IF EXISTS context_${table}_${operation}`);
|
|
147
|
+
let condition = '';
|
|
148
|
+
if (table === 'sources' && operation === 'INSERT')
|
|
149
|
+
condition = 'WHEN NEW.seed_since IS NOT NULL';
|
|
150
|
+
if (table === 'sources' && operation === 'UPDATE')
|
|
151
|
+
condition = 'WHEN NEW.seed_since IS NOT OLD.seed_since';
|
|
152
|
+
this.db.exec(`CREATE TRIGGER context_${table}_${operation}
|
|
153
|
+
AFTER ${operation} ON ${table} ${condition} BEGIN
|
|
154
|
+
UPDATE review_context SET generation = generation + 1
|
|
155
|
+
${table === 'proposals' ? ', notice_generation = notice_generation + 1' : ''}
|
|
156
|
+
WHERE singleton = 1;
|
|
157
|
+
END`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (Number(this.db.prepare('PRAGMA user_version').get()!['user_version']) < 1) {
|
|
161
|
+
const update = this.db.prepare('UPDATE proposals SET revision = ?, body = ? WHERE id = ?');
|
|
162
|
+
for (const row of this.db.prepare('SELECT id, revision, body FROM proposals').iterate()) {
|
|
163
|
+
const proposal = JSON.parse(row['body'] as string) as Proposal & { history?: unknown };
|
|
164
|
+
const sources = unionProposalSources(proposal.sources);
|
|
165
|
+
if (!Object.hasOwn(proposal, 'history') && sources.length === proposal.sources.length)
|
|
166
|
+
continue;
|
|
167
|
+
delete proposal.history;
|
|
168
|
+
proposal.sources = sources;
|
|
169
|
+
proposal.revision = Number(row['revision']) + 1;
|
|
170
|
+
update.run(proposal.revision, JSON.stringify(proposal), row['id'] as string);
|
|
171
|
+
}
|
|
172
|
+
this.db.exec('PRAGMA user_version = 1');
|
|
173
|
+
}
|
|
174
|
+
if (Number(this.db.prepare('PRAGMA user_version').get()!['user_version']) < 2) {
|
|
175
|
+
this.db.exec(`
|
|
176
|
+
ALTER TABLE capture_jobs ADD COLUMN attempt_count INTEGER NOT NULL DEFAULT 0
|
|
177
|
+
CHECK(attempt_count >= 0 AND attempt_count <= ${CAPTURE_MAX_ATTEMPTS});
|
|
178
|
+
ALTER TABLE capture_jobs ADD COLUMN active_attempt_id TEXT;
|
|
179
|
+
ALTER TABLE capture_jobs ADD COLUMN next_attempt_at INTEGER;
|
|
180
|
+
ALTER TABLE capture_jobs ADD COLUMN revision INTEGER NOT NULL DEFAULT 1 CHECK(revision > 0);
|
|
181
|
+
CREATE TABLE capture_control (
|
|
182
|
+
singleton INTEGER PRIMARY KEY CHECK(singleton = 1),
|
|
183
|
+
paused INTEGER NOT NULL CHECK(paused IN (0, 1))
|
|
184
|
+
);
|
|
185
|
+
INSERT INTO capture_control (singleton, paused) VALUES (1, 0);
|
|
186
|
+
UPDATE capture_jobs SET state = 'failed', retry_eligible = 0,
|
|
187
|
+
diagnostic = CASE WHEN diagnostic IS NULL THEN '' ELSE diagnostic || '; ' END
|
|
188
|
+
|| 'Historical attempts unknown; explicit retry required'
|
|
189
|
+
WHERE state <> 'completed';
|
|
190
|
+
PRAGMA user_version = 2;
|
|
191
|
+
`);
|
|
192
|
+
}
|
|
101
193
|
this.db.exec('COMMIT');
|
|
102
194
|
} catch (error) {
|
|
103
195
|
try {
|
|
@@ -112,6 +204,16 @@ export class CheckpointStore {
|
|
|
112
204
|
// A separate lock file lets other Pi sessions enroll during an interactive review.
|
|
113
205
|
// SQLite releases this transaction's OS lock on close, including process death.
|
|
114
206
|
claimReview(): void {
|
|
207
|
+
this.claimReviewLock();
|
|
208
|
+
try {
|
|
209
|
+
this.db.exec('UPDATE review_context SET generation = generation + 1 WHERE singleton = 1');
|
|
210
|
+
} catch (error) {
|
|
211
|
+
this.releaseReview();
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private claimReviewLock(): void {
|
|
115
217
|
if (this.reviewLock) throw new Error('A remembrancer review is already open');
|
|
116
218
|
const lock = openPrivate(this.filename === ':memory:' ? ':memory:' : this.filename + '.lock');
|
|
117
219
|
try {
|
|
@@ -128,7 +230,6 @@ export class CheckpointStore {
|
|
|
128
230
|
releaseReview(): void {
|
|
129
231
|
this.reviewLock?.close();
|
|
130
232
|
this.reviewLock = undefined;
|
|
131
|
-
this.capture = undefined;
|
|
132
233
|
}
|
|
133
234
|
|
|
134
235
|
proposals(state?: ProposalState, offset = 0, limit = 50): Proposal[] {
|
|
@@ -164,9 +265,8 @@ export class CheckpointStore {
|
|
|
164
265
|
return row ? (JSON.parse(row['body'] as string) as Proposal) : undefined;
|
|
165
266
|
}
|
|
166
267
|
|
|
167
|
-
private saveProposal(proposal: Proposal, expectedRevision?: number):
|
|
168
|
-
// Draft decisions have no active application. Outcomes retain
|
|
169
|
-
// snapshot they describe; previous applications live only in history.
|
|
268
|
+
private saveProposal(proposal: Proposal, expectedRevision?: number): Proposal {
|
|
269
|
+
// Draft decisions have no active application. Outcomes retain their claim and snapshot.
|
|
170
270
|
const { state, claim, result, applicationBefore } = proposal;
|
|
171
271
|
const valid =
|
|
172
272
|
state === 'pending' || state === 'dismissed'
|
|
@@ -178,6 +278,17 @@ export class CheckpointStore {
|
|
|
178
278
|
: ['applied', 'already_satisfied', 'uncertain'].includes(state) &&
|
|
179
279
|
result?.state === state);
|
|
180
280
|
if (!valid) throw new Error('Invalid proposal application state');
|
|
281
|
+
if (expectedRevision !== undefined) {
|
|
282
|
+
const row = this.db
|
|
283
|
+
.prepare('SELECT revision, body FROM proposals WHERE id = ?')
|
|
284
|
+
.get(proposal.id);
|
|
285
|
+
if (!row || row['revision'] !== expectedRevision)
|
|
286
|
+
throw new Error('Proposal revision conflict');
|
|
287
|
+
const previous = JSON.parse(row['body'] as string) as Proposal;
|
|
288
|
+
if (isDeepStrictEqual(proposal, previous)) return previous;
|
|
289
|
+
proposal.revision = expectedRevision + 1;
|
|
290
|
+
proposal.updatedAt = new Date().toISOString();
|
|
291
|
+
}
|
|
181
292
|
if (expectedRevision === undefined) {
|
|
182
293
|
this.db
|
|
183
294
|
.prepare('INSERT INTO proposals VALUES (?, ?, ?, ?)')
|
|
@@ -197,39 +308,32 @@ export class CheckpointStore {
|
|
|
197
308
|
) {
|
|
198
309
|
throw new Error('Proposal revision conflict');
|
|
199
310
|
}
|
|
311
|
+
return proposal;
|
|
200
312
|
}
|
|
201
313
|
|
|
202
|
-
private
|
|
314
|
+
private checkedProposal(id: string, revision: number, states: ProposalState[]): Proposal {
|
|
203
315
|
const value = this.proposal(id);
|
|
204
316
|
if (!value || value.revision !== revision) throw new Error('Proposal revision conflict');
|
|
205
317
|
if (!states.includes(value.state)) throw new Error('Illegal proposal state transition');
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
...value,
|
|
209
|
-
history: [...history, previous],
|
|
210
|
-
revision: revision + 1,
|
|
211
|
-
updatedAt: new Date().toISOString(),
|
|
212
|
-
};
|
|
318
|
+
return value;
|
|
213
319
|
}
|
|
214
320
|
|
|
215
321
|
editProposal(id: string, revision: number, draft: ProposalDraft): Proposal {
|
|
216
322
|
validateDraft(draft);
|
|
217
|
-
const value = this.
|
|
323
|
+
const value = this.checkedProposal(id, revision, ['pending']);
|
|
218
324
|
value.draft = structuredClone(draft);
|
|
219
|
-
this.saveProposal(value, revision);
|
|
220
|
-
return value;
|
|
325
|
+
return this.saveProposal(value, revision);
|
|
221
326
|
}
|
|
222
327
|
|
|
223
328
|
dismissProposal(id: string, revision: number): Proposal {
|
|
224
|
-
const value = this.
|
|
329
|
+
const value = this.checkedProposal(id, revision, ['pending']);
|
|
225
330
|
value.state = 'dismissed';
|
|
226
|
-
this.saveProposal(value, revision);
|
|
227
|
-
return value;
|
|
331
|
+
return this.saveProposal(value, revision);
|
|
228
332
|
}
|
|
229
333
|
|
|
230
334
|
claimProposal(id: string, revision: number, before?: TaskSnapshot | null): Proposal {
|
|
231
335
|
if (before) validateSnapshot(before);
|
|
232
|
-
const value = this.
|
|
336
|
+
const value = this.checkedProposal(id, revision, ['pending']);
|
|
233
337
|
if ((value.draft ?? value).question !== null)
|
|
234
338
|
throw new Error('Resolve proposal question before applying');
|
|
235
339
|
const change = (value.draft ?? value).change;
|
|
@@ -241,8 +345,7 @@ export class CheckpointStore {
|
|
|
241
345
|
value.state = 'applying';
|
|
242
346
|
value.claim = randomUUID();
|
|
243
347
|
value.result = null;
|
|
244
|
-
this.saveProposal(value, revision);
|
|
245
|
-
return value;
|
|
348
|
+
return this.saveProposal(value, revision);
|
|
246
349
|
}
|
|
247
350
|
|
|
248
351
|
recordProposalResult(
|
|
@@ -251,7 +354,7 @@ export class CheckpointStore {
|
|
|
251
354
|
claim: string,
|
|
252
355
|
result: ApplicationResult,
|
|
253
356
|
): Proposal {
|
|
254
|
-
const value = this.
|
|
357
|
+
const value = this.checkedProposal(id, revision, ['applying', 'uncertain']);
|
|
255
358
|
if (!claim || value.claim !== claim) throw new Error('Application claim mismatch');
|
|
256
359
|
if (!['applied', 'already_satisfied', 'uncertain'].includes(result.state))
|
|
257
360
|
throw new Error('Invalid application result');
|
|
@@ -270,94 +373,470 @@ export class CheckpointStore {
|
|
|
270
373
|
throw new Error('Verified task does not match target');
|
|
271
374
|
value.state = result.state;
|
|
272
375
|
value.result = structuredClone(result);
|
|
273
|
-
this.saveProposal(value, revision);
|
|
274
|
-
return value;
|
|
376
|
+
return this.saveProposal(value, revision);
|
|
275
377
|
}
|
|
276
378
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
);
|
|
291
|
-
this.capture = review;
|
|
292
|
-
return review;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
private validatedCapture(id: string, submissions: readonly ProposalSubmission[]) {
|
|
296
|
-
if (!this.reviewLock || !this.capture || this.capture.id !== id)
|
|
297
|
-
throw new Error('No matching active capture');
|
|
298
|
-
const frozen = this.capture.completion(submissions);
|
|
379
|
+
private saveCapture(
|
|
380
|
+
capture: ReturnType<CaptureReview['completion']>,
|
|
381
|
+
submissions: readonly ProposalSubmission[],
|
|
382
|
+
): Proposal[] {
|
|
383
|
+
const enrolled = new Map(this.sources().map((source) => [source.sessionId, source.file]));
|
|
384
|
+
const plan = this.normalizePlan({
|
|
385
|
+
...capture.plan,
|
|
386
|
+
sources: (capture.plan.sources ?? []).map((source) => ({
|
|
387
|
+
...source,
|
|
388
|
+
file: enrolled.get(source.sessionId) ?? source.file,
|
|
389
|
+
})),
|
|
390
|
+
});
|
|
391
|
+
const saved: Proposal[] = [];
|
|
299
392
|
const ids = new Set<string>();
|
|
300
|
-
for (const submission of submissions) {
|
|
393
|
+
for (const [index, submission] of submissions.entries()) {
|
|
394
|
+
const references = capture.sources[index]!;
|
|
395
|
+
const now = new Date().toISOString();
|
|
396
|
+
let proposal: Proposal;
|
|
301
397
|
if (submission.id !== undefined) {
|
|
302
398
|
if (ids.has(submission.id)) throw new Error('Repeated proposal revision');
|
|
303
399
|
ids.add(submission.id);
|
|
304
|
-
this.
|
|
400
|
+
const previous = this.proposal(submission.id);
|
|
401
|
+
if (!previous || previous.revision !== submission.expectedRevision)
|
|
402
|
+
throw new CaptureRetryableError('Proposal revision conflict');
|
|
403
|
+
if (previous.state !== 'pending')
|
|
404
|
+
throw new CaptureRetryableError('Illegal proposal state transition');
|
|
405
|
+
const conflict =
|
|
406
|
+
'New evidence conflicts with an edited draft. Review both before applying.';
|
|
407
|
+
proposal = {
|
|
408
|
+
...previous,
|
|
409
|
+
change: submission.change,
|
|
410
|
+
expected: submission.expected,
|
|
411
|
+
question: submission.question,
|
|
412
|
+
explanation: submission.explanation,
|
|
413
|
+
sources: unionProposalSources(previous.sources, references),
|
|
414
|
+
};
|
|
415
|
+
if (
|
|
416
|
+
proposal.draft &&
|
|
417
|
+
!isDeepStrictEqual(proposal, {
|
|
418
|
+
...previous,
|
|
419
|
+
sources: unionProposalSources(previous.sources),
|
|
420
|
+
})
|
|
421
|
+
) {
|
|
422
|
+
proposal.draft = { ...proposal.draft, question: conflict };
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
proposal = {
|
|
426
|
+
id: randomUUID(),
|
|
427
|
+
revision: 1,
|
|
428
|
+
change: submission.change,
|
|
429
|
+
expected: submission.expected,
|
|
430
|
+
question: submission.question,
|
|
431
|
+
draft: null,
|
|
432
|
+
explanation: submission.explanation,
|
|
433
|
+
sources: references,
|
|
434
|
+
state: 'pending',
|
|
435
|
+
claim: null,
|
|
436
|
+
result: null,
|
|
437
|
+
createdAt: now,
|
|
438
|
+
updatedAt: now,
|
|
439
|
+
};
|
|
305
440
|
}
|
|
441
|
+
saved.push(this.saveProposal(proposal, submission.expectedRevision));
|
|
306
442
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
443
|
+
|
|
444
|
+
this.writeCoverage(plan);
|
|
445
|
+
return saved;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
contextGeneration(): number {
|
|
449
|
+
return Number(
|
|
450
|
+
this.db.prepare('SELECT generation FROM review_context WHERE singleton = 1').get()![
|
|
451
|
+
'generation'
|
|
452
|
+
],
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
proposalNotice(): { generation: number; pending: number } {
|
|
457
|
+
const row = this.db
|
|
458
|
+
.prepare(
|
|
459
|
+
`SELECT notice_generation AS generation,
|
|
460
|
+
(SELECT count(*) FROM proposals WHERE state = 'pending') AS pending
|
|
461
|
+
FROM review_context WHERE singleton = 1`,
|
|
462
|
+
)
|
|
463
|
+
.get()!;
|
|
464
|
+
return { generation: Number(row['generation']), pending: Number(row['pending']) };
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
claimCaptureWorker(): CaptureWorkerOwnership {
|
|
468
|
+
return CaptureWorkerOwnership.claim(this.filename);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
captureJob(id: string): CaptureJob | undefined {
|
|
472
|
+
const row = this.db.prepare('SELECT * FROM capture_jobs WHERE id = ?').get(id);
|
|
473
|
+
if (!row) return undefined;
|
|
474
|
+
return {
|
|
475
|
+
manifest: JSON.parse(row['body'] as string) as ReadyManifest,
|
|
476
|
+
state: row['state'] as CaptureJob['state'],
|
|
477
|
+
retryEligible: Boolean(row['retry_eligible']),
|
|
478
|
+
diagnostic: row['diagnostic'] as string | null,
|
|
479
|
+
attemptCount: Number(row['attempt_count']),
|
|
480
|
+
activeAttemptId: row['active_attempt_id'] as string | null,
|
|
481
|
+
nextAttemptAt: row['next_attempt_at'] as number | null,
|
|
482
|
+
revision: Number(row['revision']),
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
captureStatus(): CaptureStatus {
|
|
487
|
+
const jobs = this.db
|
|
488
|
+
.prepare(
|
|
489
|
+
`SELECT job.id, (${predecessor}) AS blocked_by FROM capture_jobs AS job
|
|
490
|
+
WHERE job.state <> 'completed' ORDER BY job.admission_order`,
|
|
491
|
+
)
|
|
492
|
+
.all()
|
|
493
|
+
.map((row) => ({
|
|
494
|
+
...this.captureJob(row['id'] as string)!,
|
|
495
|
+
blockedBy: row['blocked_by'] as string | null,
|
|
496
|
+
}));
|
|
497
|
+
return { paused: this.capturePaused(), jobs };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
private capturePaused(): boolean {
|
|
501
|
+
return Boolean(
|
|
502
|
+
this.db.prepare('SELECT paused FROM capture_control WHERE singleton = 1').get()!['paused'],
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
setCapturePaused(paused: boolean, nowMs = Date.now()): void {
|
|
507
|
+
this.transaction(() => {
|
|
508
|
+
this.db
|
|
509
|
+
.prepare('UPDATE capture_control SET paused = ? WHERE singleton = 1')
|
|
510
|
+
.run(Number(paused));
|
|
511
|
+
if (paused) this.interruptCaptureAttempts('Capture interrupted by pause', nowMs);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
retryCaptureJob(id: string, expectedRevision: number): CaptureJob {
|
|
516
|
+
return this.transaction(() => {
|
|
517
|
+
const job = this.captureJob(id);
|
|
518
|
+
if (
|
|
519
|
+
!job ||
|
|
520
|
+
job.state !== 'failed' ||
|
|
521
|
+
job.retryEligible ||
|
|
522
|
+
job.activeAttemptId !== null ||
|
|
523
|
+
job.revision !== expectedRevision
|
|
524
|
+
)
|
|
525
|
+
throw Error('Capture retry confirmation is stale or job is not stopped');
|
|
526
|
+
this.db
|
|
527
|
+
.prepare(
|
|
528
|
+
`UPDATE capture_jobs SET state = 'queued', retry_eligible = 1,
|
|
529
|
+
diagnostic = NULL, attempt_count = 0, next_attempt_at = NULL, revision = revision + 1
|
|
530
|
+
WHERE id = ?`,
|
|
531
|
+
)
|
|
532
|
+
.run(id);
|
|
533
|
+
return this.captureJob(id)!;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
completedCaptureJobIds(owner: CaptureWorkerOwnership): string[] {
|
|
538
|
+
owner.assertStore(this.filename);
|
|
539
|
+
return this.db
|
|
540
|
+
.prepare("SELECT id FROM capture_jobs WHERE state = 'completed' ORDER BY rowid")
|
|
541
|
+
.all()
|
|
542
|
+
.map((row) => row['id'] as string);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
unresolvedSnapshot(snapshot: string): boolean {
|
|
546
|
+
return !!this.db
|
|
547
|
+
.prepare("SELECT 1 FROM capture_jobs WHERE snapshot = ? AND state <> 'completed' LIMIT 1")
|
|
548
|
+
.get(snapshot);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
importCaptureJob(owner: CaptureWorkerOwnership, value: ReadyManifest): CaptureJob {
|
|
552
|
+
owner.assertStore(this.filename);
|
|
553
|
+
const manifest = validateReadyManifest(value, dirname(value.snapshot));
|
|
554
|
+
return this.transaction(() => {
|
|
555
|
+
owner.assertStore(this.filename);
|
|
556
|
+
const existing = this.captureJob(manifest.id);
|
|
557
|
+
if (!existing || existing.state !== 'completed') {
|
|
558
|
+
const snapshot = statSync(manifest.snapshot);
|
|
559
|
+
if (!snapshot.isFile() || snapshot.size !== manifest.source.bytes)
|
|
560
|
+
throw Error('Retained snapshot extent differs from handoff');
|
|
355
561
|
}
|
|
562
|
+
if (existing) {
|
|
563
|
+
if (JSON.stringify(existing.manifest) !== JSON.stringify(manifest))
|
|
564
|
+
throw Error('Handoff ID metadata conflict');
|
|
565
|
+
return existing;
|
|
566
|
+
}
|
|
567
|
+
// Publication sequences belong to one durable inbox, not the importer or
|
|
568
|
+
// the wall clock. Never compare counters from different inboxes.
|
|
569
|
+
const previous = this.db.prepare('SELECT snapshot FROM capture_jobs LIMIT 1').get();
|
|
570
|
+
if (
|
|
571
|
+
previous &&
|
|
572
|
+
physicalInbox(dirname(previous['snapshot'] as string)) !==
|
|
573
|
+
physicalInbox(dirname(manifest.snapshot))
|
|
574
|
+
)
|
|
575
|
+
throw Error('Capture publication order requires one inbox per database');
|
|
576
|
+
if (
|
|
577
|
+
this.db
|
|
578
|
+
.prepare('SELECT 1 FROM capture_jobs WHERE admission_order = ?')
|
|
579
|
+
.get(manifest.admissionOrder)
|
|
580
|
+
)
|
|
581
|
+
throw Error('Conflicting capture publication order');
|
|
582
|
+
this.db
|
|
583
|
+
.prepare(
|
|
584
|
+
`INSERT INTO capture_jobs
|
|
585
|
+
(id, session_id, snapshot, accepted_at, admission_order, body, state,
|
|
586
|
+
retry_eligible, diagnostic, attempt_count, active_attempt_id, next_attempt_at, revision)
|
|
587
|
+
VALUES (?, ?, ?, ?, ?, ?, 'queued', 1, NULL, 0, NULL, NULL, 1)`,
|
|
588
|
+
)
|
|
589
|
+
.run(
|
|
590
|
+
manifest.id,
|
|
591
|
+
manifest.source.sessionId,
|
|
592
|
+
manifest.snapshot,
|
|
593
|
+
manifest.acceptedAt,
|
|
594
|
+
manifest.admissionOrder,
|
|
595
|
+
JSON.stringify(manifest),
|
|
596
|
+
);
|
|
597
|
+
return this.captureJob(manifest.id)!;
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
runnableCaptureJobs(owner: CaptureWorkerOwnership, nowMs = Date.now()): CaptureJob[] {
|
|
602
|
+
owner.assertStore(this.filename);
|
|
603
|
+
return this.runnableCaptureJobIds(nowMs).map((id) => this.captureJob(id)!);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Read-only exit-race check. A subsequent claim still grants authority.
|
|
607
|
+
captureRecoveryPending(nowMs = Date.now()): boolean {
|
|
608
|
+
return this.runnableCaptureJobIds(nowMs).length > 0;
|
|
609
|
+
}
|
|
356
610
|
|
|
357
|
-
|
|
358
|
-
|
|
611
|
+
private runnableCaptureJobIds(nowMs: number): string[] {
|
|
612
|
+
// Drain every visible ready signal before selection, regardless of discovery order.
|
|
613
|
+
const first = this.db.prepare('SELECT snapshot FROM capture_jobs LIMIT 1').get();
|
|
614
|
+
if (
|
|
615
|
+
first &&
|
|
616
|
+
readdirSync(dirname(first['snapshot'] as string)).some(
|
|
617
|
+
(name) =>
|
|
618
|
+
name.endsWith('.ready.json') && !this.captureJob(name.slice(0, -'.ready.json'.length)),
|
|
619
|
+
)
|
|
620
|
+
)
|
|
621
|
+
return [];
|
|
622
|
+
return this.db
|
|
623
|
+
.prepare(
|
|
624
|
+
`SELECT job.id FROM capture_jobs AS job
|
|
625
|
+
WHERE (SELECT paused FROM capture_control WHERE singleton = 1) = 0
|
|
626
|
+
AND json_extract(job.body, '$.version') = 3
|
|
627
|
+
AND (job.state = 'queued' OR (job.state = 'failed' AND job.retry_eligible = 1))
|
|
628
|
+
AND job.active_attempt_id IS NULL AND job.attempt_count < ?
|
|
629
|
+
AND (job.next_attempt_at IS NULL OR job.next_attempt_at <= ?)
|
|
630
|
+
AND NOT EXISTS (${predecessor}) ORDER BY job.admission_order`,
|
|
631
|
+
)
|
|
632
|
+
.all(CAPTURE_MAX_ATTEMPTS, nowMs)
|
|
633
|
+
.map((row) => row['id'] as string);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
claimCaptureAttempt(
|
|
637
|
+
owner: CaptureWorkerOwnership,
|
|
638
|
+
jobId: string,
|
|
639
|
+
nowMs = Date.now(),
|
|
640
|
+
): CaptureAttempt | undefined {
|
|
641
|
+
let attempt: CaptureAttempt | undefined;
|
|
642
|
+
try {
|
|
643
|
+
return this.coordinateCapture(owner, () =>
|
|
644
|
+
this.transaction(() => {
|
|
645
|
+
if (!this.runnableCaptureJobIds(nowMs).includes(jobId)) return undefined;
|
|
646
|
+
attempt = owner.startAttempt(jobId);
|
|
647
|
+
this.db
|
|
648
|
+
.prepare(
|
|
649
|
+
`UPDATE capture_jobs SET attempt_count = attempt_count + 1,
|
|
650
|
+
active_attempt_id = ?, state = 'queued', retry_eligible = 1, diagnostic = NULL,
|
|
651
|
+
next_attempt_at = NULL, revision = revision + 1 WHERE id = ?`,
|
|
652
|
+
)
|
|
653
|
+
.run(attempt.id, jobId);
|
|
654
|
+
return attempt;
|
|
655
|
+
}),
|
|
656
|
+
);
|
|
657
|
+
} catch (error) {
|
|
658
|
+
// Never leave an executable in-memory identity after a failed durable commit.
|
|
659
|
+
if (attempt) owner.abandon(attempt);
|
|
660
|
+
throw error;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
assertCaptureAttempt(owner: CaptureWorkerOwnership, attempt: CaptureAttempt): void {
|
|
665
|
+
owner.assertStore(this.filename);
|
|
666
|
+
owner.assertAttempt(attempt);
|
|
667
|
+
// One statement observes identity and pause together, including quick pause/resume.
|
|
668
|
+
if (
|
|
669
|
+
!this.db
|
|
670
|
+
.prepare(
|
|
671
|
+
`SELECT 1 FROM capture_jobs
|
|
672
|
+
WHERE id = ? AND state = 'queued' AND active_attempt_id = ?
|
|
673
|
+
AND (SELECT paused FROM capture_control WHERE singleton = 1) = 0`,
|
|
674
|
+
)
|
|
675
|
+
.get(attempt.jobId, attempt.id)
|
|
676
|
+
)
|
|
677
|
+
throw Error('No matching durable capture attempt');
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
recoverInterruptedCaptureAttempts(owner: CaptureWorkerOwnership, nowMs = Date.now()): void {
|
|
681
|
+
owner.assertStore(this.filename);
|
|
682
|
+
this.transaction(() => this.interruptCaptureAttempts('Capture worker interrupted', nowMs));
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
private interruptCaptureAttempts(diagnostic: string, nowMs: number): void {
|
|
686
|
+
for (const row of this.db
|
|
687
|
+
.prepare('SELECT id FROM capture_jobs WHERE active_attempt_id IS NOT NULL')
|
|
688
|
+
.all()) {
|
|
689
|
+
const job = this.captureJob(row['id'] as string)!;
|
|
690
|
+
this.writeCaptureFailure(job, diagnostic, true, nowMs);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
private writeCaptureFailure(
|
|
695
|
+
job: CaptureJob,
|
|
696
|
+
diagnostic: string,
|
|
697
|
+
temporary: boolean,
|
|
698
|
+
nowMs: number,
|
|
699
|
+
): void {
|
|
700
|
+
const retry = temporary && job.attemptCount < CAPTURE_MAX_ATTEMPTS;
|
|
701
|
+
this.db
|
|
702
|
+
.prepare(
|
|
703
|
+
`UPDATE capture_jobs SET state = 'failed', retry_eligible = ?, diagnostic = ?,
|
|
704
|
+
active_attempt_id = NULL, next_attempt_at = ?, revision = revision + 1 WHERE id = ?`,
|
|
705
|
+
)
|
|
706
|
+
.run(
|
|
707
|
+
Number(retry),
|
|
708
|
+
temporary && !retry ? `Capture attempt allowance exhausted: ${diagnostic}` : diagnostic,
|
|
709
|
+
retry ? nowMs + CAPTURE_RETRY_DELAY_MS : null,
|
|
710
|
+
job.manifest.id,
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
private coordinateCapture<T>(owner: CaptureWorkerOwnership, operation: () => T): T {
|
|
715
|
+
owner.assertStore(this.filename);
|
|
716
|
+
try {
|
|
717
|
+
this.claimReviewLock();
|
|
718
|
+
} catch (error) {
|
|
719
|
+
if (
|
|
720
|
+
error instanceof Error &&
|
|
721
|
+
error.message.startsWith('A remembrancer review is already open')
|
|
722
|
+
)
|
|
723
|
+
throw new CaptureRetryableError(error.message);
|
|
724
|
+
throw error;
|
|
725
|
+
}
|
|
726
|
+
try {
|
|
727
|
+
return operation();
|
|
728
|
+
} finally {
|
|
729
|
+
this.releaseReview();
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
prepareCaptureJob(owner: CaptureWorkerOwnership, attempt: CaptureAttempt): CaptureReview {
|
|
734
|
+
if (this.jobCapture?.attempt === attempt) throw Error('Attempt already has a frozen capture');
|
|
735
|
+
const frozen = this.coordinateCapture(owner, () =>
|
|
736
|
+
this.transaction(() => {
|
|
737
|
+
this.assertCaptureAttempt(owner, attempt);
|
|
738
|
+
const job = this.captureJob(attempt.jobId)!;
|
|
739
|
+
const enrolled = this.sources().find(
|
|
740
|
+
(source) => source.sessionId === job.manifest.source.sessionId,
|
|
741
|
+
);
|
|
742
|
+
return {
|
|
743
|
+
job,
|
|
744
|
+
source: {
|
|
745
|
+
file: job.manifest.source.file,
|
|
746
|
+
sessionId: job.manifest.source.sessionId,
|
|
747
|
+
seedSince: enrolled?.seedSince ?? null,
|
|
748
|
+
},
|
|
749
|
+
liveSourceFile: enrolled?.file ?? job.manifest.source.file,
|
|
750
|
+
reviewed: this.reviewed(),
|
|
751
|
+
generation: this.contextGeneration(),
|
|
752
|
+
body: JSON.stringify(job.manifest),
|
|
753
|
+
};
|
|
754
|
+
}),
|
|
755
|
+
);
|
|
756
|
+
// Parsing and historical applicability are deliberately outside manual ownership.
|
|
757
|
+
const result = prepareHistoricalReview(
|
|
758
|
+
frozen.source,
|
|
759
|
+
frozen.job.manifest.snapshot,
|
|
760
|
+
frozen.reviewed,
|
|
761
|
+
undefined,
|
|
762
|
+
frozen.liveSourceFile,
|
|
763
|
+
);
|
|
764
|
+
this.assertCaptureAttempt(owner, attempt);
|
|
765
|
+
if ('retryEligible' in result) {
|
|
766
|
+
this.failCaptureJob(owner, attempt, result.diagnostic, result.retryEligible);
|
|
767
|
+
throw new CapturePreparationError(result.diagnostic, result.category, result.retryEligible);
|
|
768
|
+
}
|
|
769
|
+
const review = new CaptureReview(result.review, () => {
|
|
770
|
+
this.assertCaptureAttempt(owner, attempt);
|
|
771
|
+
if (this.jobCapture?.review !== review) throw Error('No matching frozen capture job');
|
|
772
|
+
});
|
|
773
|
+
this.jobCapture = { owner, attempt, review, generation: frozen.generation, body: frozen.body };
|
|
774
|
+
return review;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
failCaptureJob(
|
|
778
|
+
owner: CaptureWorkerOwnership,
|
|
779
|
+
attempt: CaptureAttempt,
|
|
780
|
+
diagnostic: string,
|
|
781
|
+
retryEligible: boolean,
|
|
782
|
+
nowMs = Date.now(),
|
|
783
|
+
): boolean {
|
|
784
|
+
owner.assertStore(this.filename);
|
|
785
|
+
if (!diagnostic.trim()) throw Error('Capture failure requires a diagnostic');
|
|
786
|
+
const failed = this.transaction(() => {
|
|
787
|
+
const job = this.captureJob(attempt.jobId);
|
|
788
|
+
if (!job || job.state !== 'queued' || job.activeAttemptId !== attempt.id) return false;
|
|
789
|
+
owner.assertAttempt(attempt);
|
|
790
|
+
this.writeCaptureFailure(job, diagnostic, retryEligible, nowMs);
|
|
791
|
+
return true;
|
|
359
792
|
});
|
|
360
|
-
|
|
793
|
+
if (failed) {
|
|
794
|
+
this.jobCapture = undefined;
|
|
795
|
+
owner.abandon(attempt);
|
|
796
|
+
}
|
|
797
|
+
return failed;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
finishCaptureJob(
|
|
801
|
+
owner: CaptureWorkerOwnership,
|
|
802
|
+
attempt: CaptureAttempt,
|
|
803
|
+
submissions: readonly ProposalSubmission[],
|
|
804
|
+
): Proposal[] {
|
|
805
|
+
const saved = this.coordinateCapture(owner, () =>
|
|
806
|
+
this.transaction(() => {
|
|
807
|
+
this.assertCaptureAttempt(owner, attempt);
|
|
808
|
+
const active = this.jobCapture;
|
|
809
|
+
const job = this.captureJob(attempt.jobId);
|
|
810
|
+
if (
|
|
811
|
+
!active ||
|
|
812
|
+
active.owner !== owner ||
|
|
813
|
+
active.attempt !== attempt ||
|
|
814
|
+
!job ||
|
|
815
|
+
job.state !== 'queued' ||
|
|
816
|
+
JSON.stringify(job.manifest) !== active.body ||
|
|
817
|
+
this.db
|
|
818
|
+
.prepare(
|
|
819
|
+
`SELECT (${predecessor}) AS blocked_by FROM capture_jobs AS job WHERE job.id = ?`,
|
|
820
|
+
)
|
|
821
|
+
.get(attempt.jobId)!['blocked_by'] !== null
|
|
822
|
+
)
|
|
823
|
+
throw Error('No matching durable capture job');
|
|
824
|
+
validateReadyManifest(job.manifest, dirname(job.manifest.snapshot));
|
|
825
|
+
if (this.contextGeneration() !== active.generation)
|
|
826
|
+
throw new CaptureRetryableError('Capture review context changed; reprepare');
|
|
827
|
+
const capture = active.review.completion(submissions);
|
|
828
|
+
const proposals = this.saveCapture(capture, submissions);
|
|
829
|
+
this.db
|
|
830
|
+
.prepare(
|
|
831
|
+
`UPDATE capture_jobs SET state = 'completed', retry_eligible = 0, diagnostic = NULL,
|
|
832
|
+
active_attempt_id = NULL, next_attempt_at = NULL, revision = revision + 1 WHERE id = ?`,
|
|
833
|
+
)
|
|
834
|
+
.run(attempt.jobId);
|
|
835
|
+
return proposals;
|
|
836
|
+
}),
|
|
837
|
+
);
|
|
838
|
+
this.jobCapture = undefined;
|
|
839
|
+
owner.abandon(attempt);
|
|
361
840
|
return saved;
|
|
362
841
|
}
|
|
363
842
|
|
|
@@ -493,6 +972,14 @@ export class CheckpointStore {
|
|
|
493
972
|
|
|
494
973
|
close(): void {
|
|
495
974
|
this.releaseReview();
|
|
975
|
+
if (this.jobCapture) {
|
|
976
|
+
try {
|
|
977
|
+
this.jobCapture.owner.abandon(this.jobCapture.attempt);
|
|
978
|
+
} catch {
|
|
979
|
+
/* Ownership release already invalidated the attempt. */
|
|
980
|
+
}
|
|
981
|
+
this.jobCapture = undefined;
|
|
982
|
+
}
|
|
496
983
|
this.db.close();
|
|
497
984
|
}
|
|
498
985
|
}
|