@principles/host-runtime 4.11.0 → 5.0.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/dist/codex-disclosure.d.ts +1 -1
- package/dist/codex-disclosure.js +1 -1
- package/dist/diagnostician-auto-run.d.ts +1 -1
- package/dist/diagnostician-auto-run.js +15 -1
- package/dist/forward-observation.d.ts +29 -0
- package/dist/forward-observation.js +279 -0
- package/dist/governance-signal-admission.js +52 -6
- package/dist/index.d.ts +6 -5
- package/dist/index.js +33 -8
- package/dist/pain-inbox.d.ts +8 -0
- package/dist/pain-inbox.js +115 -1
- package/dist/production-pain-evidence.d.ts +2 -2
- package/dist/production-pain-evidence.js +301 -55
- package/dist/production-rulehost-gate.js +0 -19
- package/package.json +3 -3
- package/dist/legacy-rule-contract-symbols.d.ts +0 -20
- package/dist/legacy-rule-contract-symbols.js +0 -124
package/dist/pain-inbox.js
CHANGED
|
@@ -31,9 +31,11 @@
|
|
|
31
31
|
import { createHash, randomUUID } from 'node:crypto';
|
|
32
32
|
import fs from 'node:fs';
|
|
33
33
|
import path from 'node:path';
|
|
34
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
34
35
|
import Database from 'better-sqlite3';
|
|
35
36
|
import { resolveTrajectoryDbPath } from '@principles/core/runtime/storage-paths';
|
|
36
|
-
import { evaluatePainIngress, } from '@principles/core/runtime';
|
|
37
|
+
import { checkIngressTopLevelConsistency, createDiagnosticianTaskId, evaluatePainIngress, parsePainIngressV1Payload, } from '@principles/core/runtime';
|
|
38
|
+
import { isAutomaticPainSubmissionAuthorized } from './auto-pain-authorization.js';
|
|
37
39
|
import { readSourceMaterialAuthorization } from './source-material-authorization.js';
|
|
38
40
|
import { ensureGovernanceDiagnosticianTask } from './governance-signal-admission.js';
|
|
39
41
|
export const PAIN_INBOX_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -246,6 +248,15 @@ function evaluateInboxCanonicalAdmission(args) {
|
|
|
246
248
|
}
|
|
247
249
|
return { ok: true, decision };
|
|
248
250
|
}
|
|
251
|
+
function automaticInboxSubmissionRefusal(workspaceDir, provenance) {
|
|
252
|
+
if (provenance !== 'automatic_hook' || isAutomaticPainSubmissionAuthorized(workspaceDir))
|
|
253
|
+
return null;
|
|
254
|
+
return {
|
|
255
|
+
ok: false,
|
|
256
|
+
reason: 'auto_pain_unauthorized',
|
|
257
|
+
nextAction: 'Enable automatic Pain submission in this workspace before approving this item, or dismiss it. No Pain was submitted.',
|
|
258
|
+
};
|
|
259
|
+
}
|
|
249
260
|
function openTrajectoryDb(workspaceDir, readonly, factory) {
|
|
250
261
|
const dbPath = resolveTrajectoryDbPath(workspaceDir);
|
|
251
262
|
if (!factory && !fs.existsSync(dbPath))
|
|
@@ -273,6 +284,103 @@ function deriveInboxCanonicalPainId(hostKind, key) {
|
|
|
273
284
|
.slice(0, 16);
|
|
274
285
|
return `pain_${hostKind}_inbox_${digest}`;
|
|
275
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Repair only the historical Inbox writer's contradictory mirror. The
|
|
289
|
+
* independent, Owner-approved marker must match the queued task; this is not
|
|
290
|
+
* a fallback in the general re-entry validator. It neither replays an
|
|
291
|
+
* approval nor reconstructs evidence from conversation material.
|
|
292
|
+
*/
|
|
293
|
+
async function repairQueuedLegacyInboxProvenance(input) {
|
|
294
|
+
const { workspaceDir, task, stateManager } = input;
|
|
295
|
+
const painId = task.inputRef;
|
|
296
|
+
if (task.taskKind !== 'diagnostician' || (task.status !== 'pending' && task.status !== 'retry_wait')
|
|
297
|
+
|| task.leaseOwner !== undefined
|
|
298
|
+
|| painId === undefined || !/^pain_(codex|workbuddy|openclaw)_inbox_[0-9a-f]{16}$/.test(painId)
|
|
299
|
+
|| task.taskId !== createDiagnosticianTaskId(painId) || task.diagnosticJson === undefined) {
|
|
300
|
+
return 'not_applicable';
|
|
301
|
+
}
|
|
302
|
+
const record = parseJsonSafe(task.diagnosticJson);
|
|
303
|
+
if (record?.provenance !== 'host_context_bound' || record.sourcePainId !== painId
|
|
304
|
+
|| !Array.isArray(record.evidence))
|
|
305
|
+
return 'not_applicable';
|
|
306
|
+
const ingress = parsePainIngressV1Payload(record.painIngress);
|
|
307
|
+
if (!ingress.ok)
|
|
308
|
+
return 'not_applicable';
|
|
309
|
+
const { correlation, origin } = ingress.payload;
|
|
310
|
+
if (correlation.status !== 'bound' || origin.kind !== 'automatic_hook')
|
|
311
|
+
return 'not_applicable';
|
|
312
|
+
const host = correlation.hostKind;
|
|
313
|
+
const sessionId = host === 'codex' ? correlation.rootSessionId : correlation.sessionId;
|
|
314
|
+
if (origin.source !== `${host}:pain_inbox` || record.hostKind !== host || record.sessionIdHint !== sessionId
|
|
315
|
+
|| checkIngressTopLevelConsistency({
|
|
316
|
+
payload: ingress.payload, topLevelProvenance: 'automatic_hook',
|
|
317
|
+
topLevelSessionIdHint: sessionId, topLevelEvidenceCount: record.evidence.length,
|
|
318
|
+
}) !== null)
|
|
319
|
+
return 'not_applicable';
|
|
320
|
+
const trajectory = openTrajectoryDb(workspaceDir, true);
|
|
321
|
+
if (trajectory === null)
|
|
322
|
+
return 'not_applicable';
|
|
323
|
+
try {
|
|
324
|
+
if (!tableExists(trajectory.db, 'governance_signal_admissions'))
|
|
325
|
+
return 'not_applicable';
|
|
326
|
+
const marker = trajectory.db.prepare(`SELECT * FROM governance_signal_admissions
|
|
327
|
+
WHERE canonical_pain_id = ? AND diagnostician_task_id = ? AND decision = 'inbox_approved'`).get(painId, task.taskId);
|
|
328
|
+
if (!isGsaAdmissionRow(marker) || marker.host_kind !== host || marker.root_session_id !== sessionId)
|
|
329
|
+
return 'not_applicable';
|
|
330
|
+
const payload = parseJsonSafe(marker.task_payload_json);
|
|
331
|
+
if (payload === null || payload.source !== record.source || payload.sessionId !== sessionId || payload.hostKind !== host
|
|
332
|
+
|| payload.reason !== record.reasonSummary
|
|
333
|
+
|| !isRecord(payload.ownerApproval) || typeof payload.ownerApproval.approvedAt !== 'string'
|
|
334
|
+
|| !isDeepStrictEqual(payload.painIngress, record.painIngress)
|
|
335
|
+
|| !Array.isArray(payload.evidence)
|
|
336
|
+
|| !isDeepStrictEqual(payload.evidence.map((entry) => (isRecord(entry) ? { kind: 'behavior_trace', sourceRef: entry.sourceRef, note: entry.note } : null)), record.evidence))
|
|
337
|
+
return 'not_applicable';
|
|
338
|
+
let inboxKey = marker.logical_observation_key;
|
|
339
|
+
if (host === 'openclaw' && inboxKey.startsWith('openclaw:confirmation:')) {
|
|
340
|
+
inboxKey = inboxKey.slice('openclaw:confirmation:'.length);
|
|
341
|
+
if (payload.source !== 'mid_confidence_correction' || payload.ownerApproval.confirmationId !== inboxKey)
|
|
342
|
+
return 'not_applicable';
|
|
343
|
+
}
|
|
344
|
+
else if (payload.source !== 'trajectory_stall' && payload.source !== 'idle_audit_deviation') {
|
|
345
|
+
// Governed-host correction tasks were written by another branch.
|
|
346
|
+
return 'not_applicable';
|
|
347
|
+
}
|
|
348
|
+
if (deriveInboxCanonicalPainId(host, inboxKey) !== painId)
|
|
349
|
+
return 'not_applicable';
|
|
350
|
+
const consent = readSourceMaterialAuthorization({ workspaceDir, hostKind: host });
|
|
351
|
+
if (consent.status !== 'authorized' && !(host === 'openclaw' && consent.reason === 'consent_missing')) {
|
|
352
|
+
return 'source_authorization_blocked';
|
|
353
|
+
}
|
|
354
|
+
if (!isAutomaticPainSubmissionAuthorized(workspaceDir))
|
|
355
|
+
return 'auto_pain_unauthorized';
|
|
356
|
+
const updated = await stateManager.updateTaskIfDiagnosticJsonUnchanged(task.taskId, task.diagnosticJson, {
|
|
357
|
+
diagnosticJson: JSON.stringify({
|
|
358
|
+
...record, provenance: 'automatic_hook', provenanceReason: 'Pain detected by automatic hook (after_tool_call)',
|
|
359
|
+
}),
|
|
360
|
+
}, {
|
|
361
|
+
expectedStatus: task.status, expectedAttemptCount: task.attemptCount,
|
|
362
|
+
expectedLeaseOwner: null, expectedLeaseExpiresAt: task.leaseExpiresAt ?? null, expectedLeaseGeneration: task.leaseGeneration ?? 0,
|
|
363
|
+
});
|
|
364
|
+
return updated === null ? 'conflict' : 'repaired';
|
|
365
|
+
}
|
|
366
|
+
finally {
|
|
367
|
+
trajectory.close();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/** All background diagnosis workers share this same narrow recovery boundary. */
|
|
371
|
+
export async function executeQueuedDiagnosisWithInboxRecovery(input) {
|
|
372
|
+
const repair = await repairQueuedLegacyInboxProvenance(input);
|
|
373
|
+
if (repair === 'not_applicable' || repair === 'repaired')
|
|
374
|
+
return input.execute();
|
|
375
|
+
return {
|
|
376
|
+
status: 'skipped',
|
|
377
|
+
taskId: input.task.taskId,
|
|
378
|
+
painId: input.task.inputRef ?? input.task.taskId,
|
|
379
|
+
candidateIds: [],
|
|
380
|
+
ledgerEntryIds: [],
|
|
381
|
+
message: repair === 'conflict' ? 'candidate_changed' : repair,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
276
384
|
function parseItemId(itemId) {
|
|
277
385
|
if (itemId.startsWith('gsa:') && itemId.length > 4) {
|
|
278
386
|
return { source: 'gsa', rawKey: itemId.slice(4) };
|
|
@@ -576,6 +684,9 @@ export async function admitOwnerApprovedInboxCandidate(input) {
|
|
|
576
684
|
};
|
|
577
685
|
}
|
|
578
686
|
const canonical = ingress.decision.legacy;
|
|
687
|
+
const refusal = automaticInboxSubmissionRefusal(workspaceDir, canonical.provenance);
|
|
688
|
+
if (refusal)
|
|
689
|
+
return refusal;
|
|
579
690
|
// W3 Step 1: CAS claim inbox_candidate -> inbox_approving
|
|
580
691
|
const approvingPayload = {
|
|
581
692
|
...payload,
|
|
@@ -797,6 +908,9 @@ export async function admitOwnerApprovedInboxCandidate(input) {
|
|
|
797
908
|
};
|
|
798
909
|
}
|
|
799
910
|
const canonical = ingress.decision.legacy;
|
|
911
|
+
const refusal = automaticInboxSubmissionRefusal(workspaceDir, canonical.provenance);
|
|
912
|
+
if (refusal)
|
|
913
|
+
return refusal;
|
|
800
914
|
const claimPayload = {
|
|
801
915
|
signalKind: 'mid_confidence_correction',
|
|
802
916
|
excerpt: (ocRow.excerpt ?? '').slice(0, 500),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Database from 'better-sqlite3';
|
|
2
|
-
import { recordEnvironmentSnapshot } from '@principles/core/runtime/trajectory-schema';
|
|
3
2
|
import type { GovernanceHostKind } from '@principles/core/runtime';
|
|
4
3
|
import type { HostEvent, HostEventEmitter, HostEventResult } from '@principles/core/host';
|
|
5
4
|
export interface ProductionPainEnrichment {
|
|
@@ -35,6 +34,8 @@ declare function hasCanonicalSchema(db: Database.Database): boolean;
|
|
|
35
34
|
export interface VerifiedToolOutcomeInput {
|
|
36
35
|
/** Host tool-call id — the join key written by the live PostToolUse path. */
|
|
37
36
|
readonly toolUseId: string;
|
|
37
|
+
/** Host turn/run identity required for exact v4 correlation; absent stays unlinked. */
|
|
38
|
+
readonly hostTurnId?: string;
|
|
38
39
|
readonly toolName: string;
|
|
39
40
|
readonly params?: unknown;
|
|
40
41
|
/** Verified process exit code from the host's authoritative tool-fact record. */
|
|
@@ -89,6 +90,5 @@ export declare function createProductionPainEvidenceHandler(options?: {
|
|
|
89
90
|
hostKind?: GovernanceHostKind;
|
|
90
91
|
projectDir?: string;
|
|
91
92
|
events?: HostEventEmitter;
|
|
92
|
-
environmentProvider?: (event: HostEvent) => Pick<NonNullable<Parameters<typeof recordEnvironmentSnapshot>[1]>, 'hostVersion' | 'runtimeVersion' | 'agentConfigDigest' | 'modelConfigDigest' | 'repoCommit' | 'workspaceStateDigest' | 'featureFlagsDigest'>;
|
|
93
93
|
}): (event: HostEvent) => Promise<HostEventResult>;
|
|
94
94
|
export { hasCanonicalSchema as hasProductionPainSchema };
|
|
@@ -3,10 +3,11 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import Database from 'better-sqlite3';
|
|
5
5
|
import { applyTrajectorySchemaBase, sanitizeToolParams, sanitizeValue, } from '@principles/core/runtime';
|
|
6
|
+
import { claimFirstWriterProvenance, jsonEvidenceTextEquivalent, linkToolCallToOpportunity, recordCoverageDiagnostic } from '@principles/core/runtime/forward-evidence';
|
|
7
|
+
import { forwardObservationScopeAuthorized } from '@principles/core/runtime/forward-observation-scope';
|
|
6
8
|
// PRI-1135: the canonical column declaration lives with the DDL owner. Import
|
|
7
9
|
// the subpath directly so the public runtime barrel surface stays unchanged.
|
|
8
10
|
import { TRAJECTORY_REQUIRED_COLUMNS, convergeTrajectorySchemaVersion } from '@principles/core/runtime/trajectory-schema';
|
|
9
|
-
import { recordEnvironmentSnapshot } from '@principles/core/runtime/trajectory-schema';
|
|
10
11
|
import { resolveTrajectoryDbPath } from '@principles/core/runtime/storage-paths';
|
|
11
12
|
const MAX_PREVIEW = 500;
|
|
12
13
|
function isRecord(value) {
|
|
@@ -276,49 +277,160 @@ export function recordVerifiedToolOutcomes(args) {
|
|
|
276
277
|
// Callers without a hostKind keep the historical match-any semantics
|
|
277
278
|
// (explicit compat contract, asserted by tests).
|
|
278
279
|
const findByToolUseId = args.hostKind !== undefined
|
|
279
|
-
? db.prepare('SELECT id, outcome FROM tool_calls WHERE session_id = ? AND tool_use_id = ? AND host_kind = ? ORDER BY id LIMIT 1')
|
|
280
|
-
: db.prepare('SELECT id, outcome FROM tool_calls WHERE session_id = ? AND tool_use_id = ? ORDER BY id LIMIT 1');
|
|
281
|
-
const
|
|
282
|
-
|
|
280
|
+
? db.prepare('SELECT id, outcome, turn_id, tool_name, params_json FROM tool_calls WHERE session_id = ? AND tool_use_id = ? AND host_kind = ? ORDER BY id LIMIT 1')
|
|
281
|
+
: db.prepare('SELECT id, outcome, turn_id, tool_name, params_json FROM tool_calls WHERE session_id = ? AND tool_use_id = ? ORDER BY id LIMIT 1');
|
|
282
|
+
const findFullKeyCandidates = args.hostKind !== undefined
|
|
283
|
+
? db.prepare(`SELECT id, outcome, turn_id, tool_name, params_json FROM tool_calls
|
|
284
|
+
WHERE session_id = ? AND tool_use_id = ? AND host_kind = ?
|
|
285
|
+
ORDER BY CASE WHEN turn_id = ? THEN 0 WHEN turn_id IS NULL THEN 1 ELSE 2 END, id LIMIT 4`)
|
|
286
|
+
: null;
|
|
287
|
+
const upgradeUnknown = db.prepare("UPDATE tool_calls SET outcome = ?, exit_code = ?, result_preview = COALESCE(?, result_preview), turn_id = COALESCE(turn_id, ?) WHERE id = ? AND outcome = 'unknown'");
|
|
288
|
+
const insertVerified = db.prepare('INSERT INTO tool_calls (session_id, tool_name, outcome, duration_ms, exit_code, error_type, error_message, params_json, result_preview, created_at, tool_use_id, host_kind, turn_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
|
|
283
289
|
const upsertSession = db.prepare('INSERT INTO sessions (session_id, started_at, updated_at) VALUES (?, ?, ?) ON CONFLICT(session_id) DO UPDATE SET updated_at = excluded.updated_at');
|
|
284
290
|
const createdAt = new Date().toISOString();
|
|
285
|
-
|
|
291
|
+
const database = db;
|
|
292
|
+
database.transaction(() => {
|
|
293
|
+
// Authorization is part of the durable write boundary. Checking it only
|
|
294
|
+
// before schema convergence would leave a revocation/expiry window while
|
|
295
|
+
// the database is opened and migrated.
|
|
296
|
+
const forwardAuthorizedAtWrite = forwardObservationScopeAuthorized(args.workspaceDir);
|
|
286
297
|
for (const input of args.outcomes) {
|
|
287
298
|
if (typeof input.exitCode !== 'number' || !Number.isInteger(input.exitCode))
|
|
288
299
|
continue;
|
|
289
300
|
const finalOutcome = input.exitCode === 0 ? 'success' : 'failure';
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
301
|
+
const sanitizedParams = sanitizeToolParams(input.params ?? {}, args.workspaceDir);
|
|
302
|
+
const inputParamsJson = stable(sanitizedParams);
|
|
303
|
+
let candidate;
|
|
304
|
+
if (args.hostKind !== undefined && input.hostTurnId !== undefined && findFullKeyCandidates !== null) {
|
|
305
|
+
const candidates = findFullKeyCandidates.all(args.sessionId, input.toolUseId, args.hostKind, input.hostTurnId);
|
|
306
|
+
const exactRow = candidates.find((row) => row.turn_id === input.hostTurnId);
|
|
307
|
+
// The host-native exact tuple (session+turn+call id) is the
|
|
308
|
+
// identity authority. Params are evidence content and may serialize
|
|
309
|
+
// differently between live hooks and transcript replay; canonical
|
|
310
|
+
// JSON equivalence therefore decides compatibility. When content is
|
|
311
|
+
// actually contradictory and a forward opportunity can consume the row,
|
|
312
|
+
// verified evidence is preserved separately so the linker quarantines
|
|
313
|
+
// the ambiguity instead of borrowing either projection. Tool-name mismatch remains
|
|
314
|
+
// incompatible.
|
|
315
|
+
const forwardOpportunityAtRisk = forwardAuthorizedAtWrite
|
|
316
|
+
? database.prepare('SELECT 1 AS ok FROM observation_opportunities WHERE host_kind = ? AND host_session_id = ? AND turn_id = ? AND native_tool_call_id = ? LIMIT 1').get(args.hostKind, args.sessionId, input.hostTurnId, input.toolUseId) !== undefined
|
|
317
|
+
: false;
|
|
318
|
+
const evidenceParamsCompatible = (storedParams) => {
|
|
319
|
+
// Outside a forward opportunity this preserves the legacy verified-outcome
|
|
320
|
+
// reconciliation contract. Once an exact forward opportunity can consume
|
|
321
|
+
// the row, contradictory partial evidence must not be silently merged.
|
|
322
|
+
if (!forwardOpportunityAtRisk)
|
|
323
|
+
return true;
|
|
324
|
+
if (storedParams === null || storedParams === undefined)
|
|
325
|
+
return true;
|
|
326
|
+
return typeof storedParams === 'string' && jsonEvidenceTextEquivalent(storedParams, inputParamsJson);
|
|
327
|
+
};
|
|
328
|
+
const exact = exactRow !== undefined && exactRow.tool_name === input.toolName && evidenceParamsCompatible(exactRow.params_json) ? exactRow : undefined;
|
|
329
|
+
const hasDifferentKnownTurn = candidates.some((row) => row.turn_id !== null && row.turn_id !== input.hostTurnId);
|
|
330
|
+
const nullTurnCandidates = candidates.filter((row) => row.turn_id === null);
|
|
331
|
+
// Exact full identity wins. A SINGLE NULL-turn partial may be
|
|
332
|
+
// upgraded only when no same-call-id reuse evidence exists in another
|
|
333
|
+
// known turn; otherwise the partial row is ambiguous and the verified
|
|
334
|
+
// full key must remain a separate write.
|
|
335
|
+
const solePartial = !hasDifferentKnownTurn && nullTurnCandidates.length === 1 && candidates.length === 1 ? nullTurnCandidates[0] : undefined;
|
|
336
|
+
candidate = exact ?? (solePartial !== undefined && solePartial.tool_name === input.toolName && evidenceParamsCompatible(solePartial.params_json) ? solePartial : undefined);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
candidate = (args.hostKind !== undefined
|
|
340
|
+
? findByToolUseId.get(args.sessionId, input.toolUseId, args.hostKind)
|
|
341
|
+
: findByToolUseId.get(args.sessionId, input.toolUseId));
|
|
342
|
+
}
|
|
343
|
+
// A verified full key must not consume a row from a reused call id in
|
|
344
|
+
// another known turn. Such rows stay unlinked evidence.
|
|
345
|
+
const existing = input.hostTurnId !== undefined && candidate !== undefined && candidate.turn_id !== null && candidate.turn_id !== input.hostTurnId
|
|
346
|
+
? undefined
|
|
347
|
+
: candidate;
|
|
293
348
|
const boundedPreview = typeof input.outputPreview === 'string' && input.outputPreview.length > 0
|
|
294
349
|
? input.outputPreview.slice(0, MAX_PREVIEW)
|
|
295
350
|
: null;
|
|
296
351
|
if (existing !== undefined) {
|
|
297
352
|
if (existing.outcome === 'unknown') {
|
|
298
|
-
upgradeUnknown.run(finalOutcome, input.exitCode, boundedPreview, existing.id);
|
|
353
|
+
upgradeUnknown.run(finalOutcome, input.exitCode, boundedPreview, input.hostTurnId ?? null, existing.id);
|
|
354
|
+
if (args.hostKind !== undefined && forwardAuthorizedAtWrite) {
|
|
355
|
+
linkToolCallToOpportunity(database, {
|
|
356
|
+
hostKind: args.hostKind,
|
|
357
|
+
sessionId: args.sessionId,
|
|
358
|
+
turnId: input.hostTurnId ?? null,
|
|
359
|
+
toolCallId: input.toolUseId,
|
|
360
|
+
toolCallRowid: existing.id,
|
|
361
|
+
outcome: finalOutcome,
|
|
362
|
+
toolName: input.toolName,
|
|
363
|
+
paramsJson: typeof existing.params_json === 'string' ? existing.params_json : inputParamsJson,
|
|
364
|
+
evidenceAt: createdAt,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
299
367
|
results.push({ status: 'updated', id: existing.id });
|
|
300
368
|
}
|
|
301
369
|
else {
|
|
370
|
+
if (args.hostKind !== undefined && forwardAuthorizedAtWrite) {
|
|
371
|
+
// A verified final outcome that contradicts an already-final
|
|
372
|
+
// same-key row must invalidate any derived exact link. Calling
|
|
373
|
+
// the linker lets it compare the durable row with the claimed
|
|
374
|
+
// verified outcome; identical redelivery remains idempotent.
|
|
375
|
+
linkToolCallToOpportunity(database, {
|
|
376
|
+
hostKind: args.hostKind,
|
|
377
|
+
sessionId: args.sessionId,
|
|
378
|
+
turnId: input.hostTurnId ?? null,
|
|
379
|
+
toolCallId: input.toolUseId,
|
|
380
|
+
toolCallRowid: existing.id,
|
|
381
|
+
outcome: finalOutcome,
|
|
382
|
+
toolName: input.toolName,
|
|
383
|
+
paramsJson: typeof existing.params_json === 'string' ? existing.params_json : inputParamsJson,
|
|
384
|
+
evidenceAt: createdAt,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
302
387
|
results.push({ status: 'skipped_final', id: existing.id, reason: 'outcome_already_final' });
|
|
303
388
|
}
|
|
304
389
|
continue;
|
|
305
390
|
}
|
|
306
391
|
upsertSession.run(args.sessionId, createdAt, createdAt);
|
|
307
|
-
const sanitizedParams = sanitizeToolParams(input.params ?? {}, args.workspaceDir);
|
|
308
392
|
// GFI-COMPLETE-REMOVAL-001 follow-up: commit 62e2cab15 dropped the two
|
|
309
393
|
// retired GFI columns from this INSERT but left their placeholder
|
|
310
394
|
// arguments behind, so every verified-outcome write threw
|
|
311
395
|
// "Too many parameter values were provided". Keep the values aligned
|
|
312
396
|
// with the 12 remaining columns.
|
|
313
|
-
const info = insertVerified.run(args.sessionId, input.toolName, finalOutcome, null, input.exitCode, null, null, stable(sanitizedParams), boundedPreview, createdAt, input.toolUseId, args.hostKind ?? null);
|
|
314
|
-
|
|
397
|
+
const info = insertVerified.run(args.sessionId, input.toolName, finalOutcome, null, input.exitCode, null, null, stable(sanitizedParams), boundedPreview, createdAt, input.toolUseId, args.hostKind ?? null, input.hostTurnId ?? null);
|
|
398
|
+
const rowid = Number(info.lastInsertRowid);
|
|
399
|
+
if (args.hostKind !== undefined && forwardAuthorizedAtWrite) {
|
|
400
|
+
claimFirstWriterProvenance(database, {
|
|
401
|
+
hostKind: args.hostKind,
|
|
402
|
+
sessionId: args.sessionId,
|
|
403
|
+
writerKind: 'verified_outcome_ingestion',
|
|
404
|
+
evidenceTable: 'tool_calls',
|
|
405
|
+
evidenceRowid: rowid,
|
|
406
|
+
sourceEventIdentity: { sessionId: args.sessionId, turnId: input.hostTurnId ?? null, toolCallId: input.toolUseId },
|
|
407
|
+
inceptionStatus: 'UNKNOWN',
|
|
408
|
+
identityCompleteness: input.hostTurnId !== undefined ? 'complete' : 'incomplete',
|
|
409
|
+
writeTime: createdAt,
|
|
410
|
+
});
|
|
411
|
+
linkToolCallToOpportunity(database, {
|
|
412
|
+
hostKind: args.hostKind,
|
|
413
|
+
sessionId: args.sessionId,
|
|
414
|
+
turnId: input.hostTurnId ?? null,
|
|
415
|
+
toolCallId: input.toolUseId,
|
|
416
|
+
toolCallRowid: rowid,
|
|
417
|
+
outcome: finalOutcome,
|
|
418
|
+
toolName: input.toolName,
|
|
419
|
+
paramsJson: inputParamsJson,
|
|
420
|
+
evidenceAt: createdAt,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
results.push({ status: 'inserted', id: rowid });
|
|
315
424
|
}
|
|
316
|
-
})();
|
|
425
|
+
}).immediate();
|
|
317
426
|
}
|
|
318
427
|
catch (error) {
|
|
319
428
|
const reason = `trajectory_write_failed:${error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200)}`;
|
|
320
|
-
|
|
321
|
-
|
|
429
|
+
// The transaction is all-or-nothing. Entries pushed inside the transaction
|
|
430
|
+
// are not durable once it throws, so retaining them would report rolled-back
|
|
431
|
+
// writes as verified successes.
|
|
432
|
+
results.length = 0;
|
|
433
|
+
for (let i = 0; i < args.outcomes.length; i += 1)
|
|
322
434
|
results.push({ status: 'unavailable', reason });
|
|
323
435
|
}
|
|
324
436
|
finally {
|
|
@@ -342,9 +454,6 @@ export function recordVerifiedToolOutcomes(args) {
|
|
|
342
454
|
* writer. Omitted -> NULL (unknown).
|
|
343
455
|
*/
|
|
344
456
|
export function createProductionPainEvidenceHandler(options = {}) {
|
|
345
|
-
// PD Phase 1.5: sessions whose environment evidence was already captured by
|
|
346
|
-
// THIS handler process — one row per session, not one per tool call.
|
|
347
|
-
const envCapturedSessions = new Set();
|
|
348
457
|
return async (event) => {
|
|
349
458
|
// PRI-750: shared-path tool event with the host's natural turn/tool ids
|
|
350
459
|
// (Codex turn_id → runId, tool_use_id → toolCallId) so receipt events
|
|
@@ -445,6 +554,13 @@ export function createProductionPainEvidenceHandler(options = {}) {
|
|
|
445
554
|
let identityConflict = false;
|
|
446
555
|
try {
|
|
447
556
|
db.transaction(() => {
|
|
557
|
+
// Re-read authorization inside the immediate write transaction. The
|
|
558
|
+
// enrichment provider is asynchronous host I/O; a marker valid before
|
|
559
|
+
// that await may have expired, been deleted, or been replaced by the
|
|
560
|
+
// time the durable write begins. Forward evidence must follow the
|
|
561
|
+
// authorization state at the write boundary, not the earlier hook
|
|
562
|
+
// entry point.
|
|
563
|
+
const forwardAuthorizedAtWrite = forwardObservationScopeAuthorized(event.context.workspaceDir);
|
|
448
564
|
// CR-01: the host tool-call id is the stable join key for the
|
|
449
565
|
// consent-gated transcript upgrade (recordVerifiedToolOutcomes);
|
|
450
566
|
// content-shape probing stays the fallback for hosts without ids.
|
|
@@ -453,12 +569,78 @@ export function createProductionPainEvidenceHandler(options = {}) {
|
|
|
453
569
|
// NOT this delivery's duplicate, so both hosts keep independent
|
|
454
570
|
// records instead of the second being swallowed.
|
|
455
571
|
if (event.context.toolCallId !== undefined) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
572
|
+
// Versioned exact correlation key: session + host-native turn +
|
|
573
|
+
// tool-use id when the host supplied a turn. Partial NULL-turn rows
|
|
574
|
+
// may be upgraded only when they are the SINGLE compatible candidate.
|
|
575
|
+
// Evidence that the host reused the same call id in another turn is
|
|
576
|
+
// ambiguity: never consume the partial row and never exact-link by
|
|
577
|
+
// proximity or content shape.
|
|
578
|
+
let existingRow;
|
|
579
|
+
let ambiguousIdentity = false;
|
|
580
|
+
if (options.hostKind !== undefined && event.context.turnId !== undefined) {
|
|
581
|
+
const candidates = db.prepare('SELECT id, tool_name, outcome, duration_ms, exit_code, error_message, params_json, result_preview, turn_id FROM tool_calls WHERE session_id = ? AND tool_use_id = ? AND host_kind = ? ORDER BY CASE WHEN turn_id = ? THEN 0 WHEN turn_id IS NULL THEN 1 ELSE 2 END, id LIMIT 5')
|
|
582
|
+
.all(event.context.sessionId, event.context.toolCallId, options.hostKind, event.context.turnId);
|
|
583
|
+
const exact = candidates.find((row) => isRecord(row) && row.turn_id === event.context.turnId);
|
|
584
|
+
if (exact !== undefined) {
|
|
585
|
+
existingRow = exact;
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
const nullTurn = candidates.filter((row) => isRecord(row) && (row.turn_id ?? null) === null);
|
|
589
|
+
const differentTurn = candidates.filter((row) => isRecord(row) && row.turn_id !== null && row.turn_id !== event.context.turnId);
|
|
590
|
+
const solePartial = differentTurn.length === 0 && nullTurn.length === 1 && candidates.length === 1 ? nullTurn[0] : undefined;
|
|
591
|
+
if (solePartial !== undefined && isRecord(solePartial) && solePartial.tool_name === toolName && jsonEvidenceTextEquivalent(String(solePartial.params_json), paramsJson)) {
|
|
592
|
+
existingRow = solePartial;
|
|
593
|
+
}
|
|
594
|
+
else if (candidates.length > 0) {
|
|
595
|
+
ambiguousIdentity = true;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
else if (options.hostKind !== undefined) {
|
|
600
|
+
const candidates = db.prepare('SELECT id, tool_name, outcome, duration_ms, exit_code, error_message, params_json, result_preview, turn_id FROM tool_calls WHERE session_id = ? AND tool_use_id = ? AND host_kind = ? ORDER BY id LIMIT 5')
|
|
601
|
+
.all(event.context.sessionId, event.context.toolCallId, options.hostKind);
|
|
602
|
+
existingRow = candidates.length === 1 ? candidates[0] : undefined;
|
|
603
|
+
ambiguousIdentity = candidates.length > 1;
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
existingRow = db.prepare('SELECT id, tool_name, outcome, duration_ms, exit_code, error_message, params_json, result_preview, turn_id FROM tool_calls WHERE session_id = ? AND tool_use_id = ?').get(event.context.sessionId, event.context.toolCallId);
|
|
607
|
+
}
|
|
608
|
+
if (ambiguousIdentity && forwardAuthorizedAtWrite) {
|
|
609
|
+
recordCoverageDiagnostic(db, {
|
|
610
|
+
hostKind: options.hostKind ?? null,
|
|
611
|
+
sessionId: event.context.sessionId,
|
|
612
|
+
eventKind: 'after_tool_call',
|
|
613
|
+
diagnosticKind: 'tool_call_identity_ambiguous',
|
|
614
|
+
reason: 'multiple same-call-id candidates exist; incomplete/reused identity is not consumed or exact-linked',
|
|
615
|
+
sourceEventIdentity: { sessionId: event.context.sessionId, turnId: event.context.turnId ?? null, toolCallId: event.context.toolCallId },
|
|
616
|
+
});
|
|
617
|
+
warnings.push('tool_call_identity_ambiguous:multiple same-call-id candidates; evidence preserved without exact reuse');
|
|
618
|
+
}
|
|
459
619
|
const existing = isRecord(existingRow) ? existingRow : undefined;
|
|
460
620
|
if (existing !== undefined) {
|
|
461
621
|
duplicate = true;
|
|
622
|
+
// partial-to-full upgrade: one compatible NULL-turn row receives
|
|
623
|
+
// the host turn key in place. Mutable outcome finalization is
|
|
624
|
+
// upgraded only while the stored outcome is still unknown; a final
|
|
625
|
+
// verified fact is never overwritten by lower-confidence live text.
|
|
626
|
+
if ((existing.turn_id ?? null) === null
|
|
627
|
+
&& event.context.turnId !== undefined
|
|
628
|
+
&& existing.tool_name === toolName
|
|
629
|
+
&& jsonEvidenceTextEquivalent(String(existing.params_json), paramsJson)) {
|
|
630
|
+
if (existing.outcome === 'unknown' && outcome.outcome !== 'unknown') {
|
|
631
|
+
db.prepare('UPDATE tool_calls SET turn_id = ?, outcome = ?, exit_code = ?, error_message = ?, result_preview = ? WHERE id = ?')
|
|
632
|
+
.run(event.context.turnId, outcome.outcome, outcome.exitCode ?? null, outcome.error ?? null, resultPreview, Number(existing.id));
|
|
633
|
+
existing.outcome = outcome.outcome;
|
|
634
|
+
existing.exit_code = outcome.exitCode ?? null;
|
|
635
|
+
existing.error_message = outcome.error ?? null;
|
|
636
|
+
existing.result_preview = resultPreview;
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
db.prepare('UPDATE tool_calls SET turn_id = ? WHERE id = ?')
|
|
640
|
+
.run(event.context.turnId, Number(existing.id));
|
|
641
|
+
}
|
|
642
|
+
existing.turn_id = event.context.turnId;
|
|
643
|
+
}
|
|
462
644
|
// Same physical host-call identity is idempotent only when the
|
|
463
645
|
// evidence content agrees. A same-id/different-content delivery is
|
|
464
646
|
// a conflict: preserve the first evidence and surface the anomaly
|
|
@@ -471,16 +653,43 @@ export function createProductionPainEvidenceHandler(options = {}) {
|
|
|
471
653
|
// direction ignores mutable outcome/exit/preview finalization
|
|
472
654
|
// facts while still comparing immutable call facts below.
|
|
473
655
|
const verifiedUpgradeReplay = outcome.outcome === 'unknown' && existing.outcome !== 'unknown';
|
|
656
|
+
const incompleteTurnEvidence = (existing.turn_id ?? null) === null || (event.context.turnId ?? null) === null;
|
|
474
657
|
identityConflict = existing.tool_name !== toolName
|
|
475
|
-
|| (existing.duration_ms ?? null) !== (outcome.durationMs ?? null)
|
|
476
|
-
|| existing.params_json
|
|
477
|
-
|| (existing.turn_id
|
|
478
|
-
|| (!verifiedUpgradeReplay && (existing.outcome !== outcome.outcome
|
|
658
|
+
|| ((existing.duration_ms ?? null) !== null && (outcome.durationMs ?? null) !== null && existing.duration_ms !== outcome.durationMs)
|
|
659
|
+
|| !jsonEvidenceTextEquivalent(String(existing.params_json), paramsJson)
|
|
660
|
+
|| (!incompleteTurnEvidence && existing.turn_id !== event.context.turnId)
|
|
661
|
+
|| (!incompleteTurnEvidence && !verifiedUpgradeReplay && (existing.outcome !== outcome.outcome
|
|
479
662
|
|| (existing.exit_code ?? null) !== (outcome.exitCode ?? null)
|
|
480
663
|
|| (existing.error_message ?? null) !== (outcome.error ?? null)
|
|
481
664
|
|| existing.result_preview !== resultPreview));
|
|
482
665
|
if (identityConflict) {
|
|
483
666
|
warnings.push('tool_call_identity_conflict:same host toolCallId delivered with different evidence content; original row preserved');
|
|
667
|
+
if (options.hostKind !== undefined && forwardAuthorizedAtWrite) {
|
|
668
|
+
linkToolCallToOpportunity(db, {
|
|
669
|
+
hostKind: options.hostKind,
|
|
670
|
+
sessionId: event.context.sessionId,
|
|
671
|
+
turnId: event.context.turnId ?? null,
|
|
672
|
+
toolCallId: event.context.toolCallId ?? null,
|
|
673
|
+
toolCallRowid: Number(existing.id),
|
|
674
|
+
outcome: outcome.outcome,
|
|
675
|
+
toolName,
|
|
676
|
+
paramsJson,
|
|
677
|
+
evidenceAt: createdAt,
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
else if (options.hostKind !== undefined && forwardAuthorizedAtWrite) {
|
|
682
|
+
linkToolCallToOpportunity(db, {
|
|
683
|
+
hostKind: options.hostKind,
|
|
684
|
+
sessionId: event.context.sessionId,
|
|
685
|
+
turnId: event.context.turnId ?? null,
|
|
686
|
+
toolCallId: event.context.toolCallId ?? null,
|
|
687
|
+
toolCallRowid: Number(existing.id),
|
|
688
|
+
outcome: String(existing.outcome),
|
|
689
|
+
toolName,
|
|
690
|
+
paramsJson,
|
|
691
|
+
evidenceAt: createdAt,
|
|
692
|
+
});
|
|
484
693
|
}
|
|
485
694
|
return;
|
|
486
695
|
}
|
|
@@ -498,38 +707,75 @@ export function createProductionPainEvidenceHandler(options = {}) {
|
|
|
498
707
|
return;
|
|
499
708
|
}
|
|
500
709
|
db.prepare(`INSERT INTO sessions (session_id, started_at, updated_at) VALUES (?, ?, ?) ON CONFLICT(session_id) DO UPDATE SET updated_at = excluded.updated_at`).run(event.context.sessionId, createdAt, createdAt);
|
|
501
|
-
db.prepare(`INSERT INTO tool_calls (session_id, tool_name, outcome, duration_ms, exit_code, error_type, error_message, params_json, result_preview, created_at, tool_use_id, project_dir, host_kind, turn_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
710
|
+
const insertedToolCall = db.prepare(`INSERT INTO tool_calls (session_id, tool_name, outcome, duration_ms, exit_code, error_type, error_message, params_json, result_preview, created_at, tool_use_id, project_dir, host_kind, turn_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
502
711
|
.run(event.context.sessionId, toolName, outcome.outcome, outcome.durationMs ?? null, outcome.exitCode, outcome.error ? outcome.error.split(/[\s:]/, 1)[0] : null, outcome.error ?? null, paramsJson, resultPreview, createdAt, event.context.toolCallId ?? null, path.resolve(options.projectDir ?? event.context.workspaceDir), options.hostKind ?? null, event.context.turnId ?? null);
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
712
|
+
const toolCallRowid = Number(insertedToolCall.lastInsertRowid);
|
|
713
|
+
if (options.hostKind !== undefined && forwardAuthorizedAtWrite && event.context.sessionId !== 'openclaw:session-unavailable') {
|
|
714
|
+
claimFirstWriterProvenance(db, {
|
|
715
|
+
hostKind: options.hostKind,
|
|
716
|
+
sessionId: event.context.sessionId,
|
|
717
|
+
writerKind: 'live_tool_call',
|
|
718
|
+
evidenceTable: 'tool_calls',
|
|
719
|
+
evidenceRowid: toolCallRowid,
|
|
720
|
+
sourceEventIdentity: { sessionId: event.context.sessionId, turnId: event.context.turnId ?? null, toolCallId: event.context.toolCallId ?? null },
|
|
721
|
+
inceptionStatus: 'UNKNOWN',
|
|
722
|
+
identityCompleteness: event.context.turnId !== undefined && event.context.toolCallId !== undefined ? 'complete' : 'incomplete',
|
|
723
|
+
writeTime: createdAt,
|
|
724
|
+
});
|
|
725
|
+
const correlation = linkToolCallToOpportunity(db, {
|
|
726
|
+
hostKind: options.hostKind,
|
|
727
|
+
sessionId: event.context.sessionId,
|
|
728
|
+
turnId: event.context.turnId ?? null,
|
|
729
|
+
toolCallId: event.context.toolCallId ?? null,
|
|
730
|
+
toolCallRowid,
|
|
731
|
+
outcome: outcome.outcome,
|
|
732
|
+
toolName,
|
|
733
|
+
paramsJson,
|
|
734
|
+
evidenceAt: createdAt,
|
|
735
|
+
});
|
|
736
|
+
let quarantinedExactAssociation = false;
|
|
737
|
+
if (event.context.turnId === undefined && event.context.toolCallId !== undefined) {
|
|
738
|
+
// A newly inserted turn-less row cannot be attributed to a host
|
|
739
|
+
// turn. If an exact association for the same host/session/call id
|
|
740
|
+
// already exists, that durable ambiguity affects the old exact
|
|
741
|
+
// link too. Re-run the exact linker inside this same transaction
|
|
742
|
+
// instead of leaving a stale linked_exact cache alive merely
|
|
743
|
+
// because the turn-less evidence arrived after the exact row.
|
|
744
|
+
const exactAssociations = db.prepare(`SELECT opportunity_id, turn_id, tool_call_rowid FROM observation_opportunities
|
|
745
|
+
WHERE host_kind = ? AND host_session_id = ? AND native_tool_call_id = ?
|
|
746
|
+
AND turn_id IS NOT NULL AND tool_call_rowid IS NOT NULL AND correlation_status = 'linked_exact'`)
|
|
747
|
+
.all(options.hostKind, event.context.sessionId, event.context.toolCallId);
|
|
748
|
+
for (const associationRow of exactAssociations) {
|
|
749
|
+
if (!isRecord(associationRow) || typeof associationRow.turn_id !== 'string' || typeof associationRow.tool_call_rowid !== 'number')
|
|
750
|
+
continue;
|
|
751
|
+
const evidenceRow = db.prepare('SELECT outcome, tool_name, params_json FROM tool_calls WHERE rowid = ?').get(associationRow.tool_call_rowid);
|
|
752
|
+
if (!isRecord(evidenceRow) || typeof evidenceRow.outcome !== 'string' || typeof evidenceRow.tool_name !== 'string')
|
|
753
|
+
continue;
|
|
754
|
+
const relink = linkToolCallToOpportunity(db, {
|
|
755
|
+
hostKind: options.hostKind,
|
|
756
|
+
sessionId: event.context.sessionId,
|
|
757
|
+
turnId: associationRow.turn_id,
|
|
758
|
+
toolCallId: event.context.toolCallId,
|
|
759
|
+
toolCallRowid: associationRow.tool_call_rowid,
|
|
760
|
+
outcome: evidenceRow.outcome,
|
|
761
|
+
toolName: evidenceRow.tool_name,
|
|
762
|
+
...(typeof evidenceRow.params_json === 'string' ? { paramsJson: evidenceRow.params_json } : {}),
|
|
763
|
+
evidenceAt: createdAt,
|
|
764
|
+
});
|
|
765
|
+
quarantinedExactAssociation ||= relink.status === 'conflict';
|
|
766
|
+
}
|
|
531
767
|
}
|
|
768
|
+
// Incomplete/orphan exact correlation is a normal coverage state for
|
|
769
|
+
// hosts whose Pre identity is unavailable and is already persisted in
|
|
770
|
+
// observation_coverage_diagnostics. Do not turn every otherwise
|
|
771
|
+
// successful Post write into a user-visible hook degradation; only a
|
|
772
|
+
// same-key evidence conflict is anomalous enough to surface here.
|
|
773
|
+
if (correlation.status === 'conflict' || quarantinedExactAssociation)
|
|
774
|
+
warnings.push('forward_post_correlation_conflict');
|
|
532
775
|
}
|
|
776
|
+
// PRI-1333 P0-2 cutover: PostToolUse must not mint legacy session-first
|
|
777
|
+
// research snapshots. Event-scoped before_tool_call captures are owned
|
|
778
|
+
// by forward-observation.ts; historical NULL-linked rows remain read-only.
|
|
533
779
|
// The dedupe probes above must hold the write lock before reading:
|
|
534
780
|
// otherwise two processes can both observe no row and both insert the
|
|
535
781
|
// same physical redelivery. `.immediate()` serializes that check-write
|