create-principles-disciple 1.156.2 → 1.157.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_release/product-identity.json +2 -2
- package/codex-adapter/dist/worker/workspace-worker.d.ts +11 -3
- package/codex-adapter/dist/worker/workspace-worker.js +30 -16
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/models/OwnerDecisionConsoleModel.js +33 -1
- package/console/dist/web/assets/app.js +3 -3
- package/core/dist/runtime/adversarial-loop.d.ts +8 -0
- package/core/dist/runtime/adversarial-loop.d.ts.map +1 -1
- package/core/dist/runtime/adversarial-loop.js +420 -45
- package/core/dist/runtime/adversarial-loop.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +3 -3
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
- package/core/dist/runtime/feature-flags/plugin-surface-registry.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/plugin-surface-registry.js +0 -16
- package/core/dist/runtime/feature-flags/plugin-surface-registry.js.map +1 -1
- package/core/dist/runtime/index.d.ts +4 -0
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +10 -0
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/internalization/artificer-runner.d.ts +9 -0
- package/core/dist/runtime/internalization/artificer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/artificer-runner.js +52 -0
- package/core/dist/runtime/internalization/artificer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/correlation-lineage.d.ts +16 -3
- package/core/dist/runtime/internalization/correlation-lineage.d.ts.map +1 -1
- package/core/dist/runtime/internalization/correlation-lineage.js +4 -4
- package/core/dist/runtime/internalization/correlation-lineage.js.map +1 -1
- package/core/dist/runtime/internalization/evaluator-runner.d.ts +35 -0
- package/core/dist/runtime/internalization/evaluator-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/evaluator-runner.js +390 -91
- package/core/dist/runtime/internalization/evaluator-runner.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +40 -13
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.js +520 -199
- package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-transition-decision.js +1 -1
- package/core/dist/runtime/internalization/internalization-transition-decision.js.map +1 -1
- package/core/dist/runtime/internalization/owner-resolution-service.d.ts.map +1 -1
- package/core/dist/runtime/internalization/owner-resolution-service.js +10 -8
- package/core/dist/runtime/internalization/owner-resolution-service.js.map +1 -1
- package/core/dist/runtime/internalization/owner-review.d.ts +2 -0
- package/core/dist/runtime/internalization/owner-review.d.ts.map +1 -1
- package/core/dist/runtime/internalization/owner-review.js +17 -11
- package/core/dist/runtime/internalization/owner-review.js.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +2 -0
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.js.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts +36 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.js +23 -2
- package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime/internalization/repair-create.d.ts +73 -0
- package/core/dist/runtime/internalization/repair-create.d.ts.map +1 -0
- package/core/dist/runtime/internalization/repair-create.js +200 -0
- package/core/dist/runtime/internalization/repair-create.js.map +1 -0
- package/core/dist/runtime/internalization/repair-lineage-backfill.d.ts +94 -0
- package/core/dist/runtime/internalization/repair-lineage-backfill.d.ts.map +1 -0
- package/core/dist/runtime/internalization/repair-lineage-backfill.js +123 -0
- package/core/dist/runtime/internalization/repair-lineage-backfill.js.map +1 -0
- package/core/dist/runtime/internalization/repair-task-identity.d.ts +99 -4
- package/core/dist/runtime/internalization/repair-task-identity.d.ts.map +1 -1
- package/core/dist/runtime/internalization/repair-task-identity.js +225 -7
- package/core/dist/runtime/internalization/repair-task-identity.js.map +1 -1
- package/core/dist/runtime/internalization/revision-reopen.d.ts +56 -1
- package/core/dist/runtime/internalization/revision-reopen.d.ts.map +1 -1
- package/core/dist/runtime/internalization/revision-reopen.js +82 -39
- package/core/dist/runtime/internalization/revision-reopen.js.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +0 -7
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +13 -68
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/successor-create.d.ts +69 -0
- package/core/dist/runtime/internalization/successor-create.d.ts.map +1 -0
- package/core/dist/runtime/internalization/successor-create.js +173 -0
- package/core/dist/runtime/internalization/successor-create.js.map +1 -0
- package/core/dist/runtime/internalization/successor-lookup.d.ts +50 -0
- package/core/dist/runtime/internalization/successor-lookup.d.ts.map +1 -0
- package/core/dist/runtime/internalization/successor-lookup.js +213 -0
- package/core/dist/runtime/internalization/successor-lookup.js.map +1 -0
- package/core/dist/runtime/runner/succeeded-result-recovery.d.ts +58 -0
- package/core/dist/runtime/runner/succeeded-result-recovery.d.ts.map +1 -0
- package/core/dist/runtime/runner/succeeded-result-recovery.js +117 -0
- package/core/dist/runtime/runner/succeeded-result-recovery.js.map +1 -0
- package/core/dist/runtime/store/runtime-state-manager.d.ts +1 -0
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js +4 -0
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.d.ts +3 -3
- package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.js +52 -0
- package/core/dist/runtime/store/task/memory-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.d.ts +3 -0
- package/core/dist/runtime/store/task/sqlite-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.js +204 -135
- package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/task-store.d.ts +17 -0
- package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
- package/core/dist/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +4 -0
- package/core/dist/telemetry-event.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +69 -11
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +432 -120
- package/dist/installer.js.map +1 -1
- package/dist/service-host-bridge.d.ts +0 -5
- package/dist/service-host-bridge.d.ts.map +1 -1
- package/dist/service-host-bridge.js.map +1 -1
- package/dist/service-host-provisioning.d.ts +123 -18
- package/dist/service-host-provisioning.d.ts.map +1 -1
- package/dist/service-host-provisioning.js +645 -77
- package/dist/service-host-provisioning.js.map +1 -1
- package/dist/utils/env.d.ts +9 -0
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +269 -49
- package/dist/utils/env.js.map +1 -1
- package/host-runtime/dist/codex-worker-status.d.ts +6 -4
- package/host-runtime/dist/codex-worker-status.js +7 -5
- package/host-runtime/dist/diagnostician-auto-run.js +2 -2
- package/host-runtime/dist/governance-signal-admission.d.ts +2 -1
- package/host-runtime/dist/governance-signal-admission.js +2 -1
- package/host-runtime/dist/index.d.ts +4 -2
- package/host-runtime/dist/index.js +6 -2
- package/host-runtime/dist/internalization-consumer-cycle.d.ts +13 -106
- package/host-runtime/dist/internalization-consumer-cycle.js +21 -99
- package/host-runtime/dist/internalization-consumer-governance.d.ts +3 -3
- package/host-runtime/dist/internalization-consumer-governance.js +17 -96
- package/host-runtime/dist/internalization-task-executor.d.ts +127 -0
- package/host-runtime/dist/internalization-task-executor.js +121 -0
- package/host-runtime/dist/workbuddy-worker-status.d.ts +6 -3
- package/host-runtime/dist/workbuddy-worker-status.js +7 -4
- package/host-runtime/dist/workspace-telemetry-emitter.js +1 -1
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/background-execution-transition.d.ts +25 -29
- package/install-layout/dist/background-execution-transition.js +90 -138
- package/install-layout/dist/index.d.ts +45 -33
- package/install-layout/dist/index.js +24 -18
- package/install-layout/package.json +1 -1
- package/package.json +5 -4
- package/pd-cli/dist/commands/codex-worker.d.ts +7 -3
- package/pd-cli/dist/commands/codex-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/codex-worker.js +125 -101
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js +148 -130
- package/pd-cli/dist/commands/runtime-internalization-enqueue-successors.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js +4 -0
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
- package/pd-cli/dist/commands/service-run-once.d.ts +12 -27
- package/pd-cli/dist/commands/service-run-once.d.ts.map +1 -1
- package/pd-cli/dist/commands/service-run-once.js +15 -206
- package/pd-cli/dist/commands/service-run-once.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.d.ts +7 -2
- package/pd-cli/dist/commands/workbuddy-worker.d.ts.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.js +133 -99
- package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
- package/pd-cli/dist/commands/worker-service-host-gate.d.ts +38 -0
- package/pd-cli/dist/commands/worker-service-host-gate.d.ts.map +1 -0
- package/pd-cli/dist/commands/worker-service-host-gate.js +110 -0
- package/pd-cli/dist/commands/worker-service-host-gate.js.map +1 -0
- package/pd-cli/dist/program.d.ts.map +1 -1
- package/pd-cli/dist/program.js +20 -84
- package/pd-cli/dist/program.js.map +1 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/rulehost-pipeline-runner.js +198 -142
- package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/pd-cli/dist/services/service-host/coordinator-common.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/coordinator-common.js +4 -5
- package/pd-cli/dist/services/service-host/coordinator-common.js.map +1 -1
- package/pd-cli/dist/services/service-host/index.d.ts +7 -10
- package/pd-cli/dist/services/service-host/index.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/index.js +8 -11
- package/pd-cli/dist/services/service-host/index.js.map +1 -1
- package/pd-cli/dist/services/service-host/install-identity.d.ts +5 -5
- package/pd-cli/dist/services/service-host/managed-run.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/managed-run.js +19 -22
- package/pd-cli/dist/services/service-host/managed-run.js.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/linux.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/linux.js +21 -2
- package/pd-cli/dist/services/service-host/scheduler/linux.js.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts +1 -1
- package/pd-cli/dist/services/service-host/scheduler/service-status.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/scheduler/service-status.js +0 -2
- package/pd-cli/dist/services/service-host/scheduler/service-status.js.map +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts +7 -51
- package/pd-cli/dist/services/service-host/status/service-run-status.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/status/service-run-status.js.map +1 -1
- package/pd-cli/dist/services/service-host/worker-adapter-openclaw.js +3 -3
- package/pd-cli/dist/services/service-host/worker-adapter.d.ts +0 -10
- package/pd-cli/dist/services/service-host/worker-adapter.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/worker-adapter.js +4 -12
- package/pd-cli/dist/services/service-host/worker-adapter.js.map +1 -1
- package/pd-cli/dist/services/service-host/worker-env.d.ts +1 -1
- package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts +5 -7
- package/pd-cli/dist/services/service-host/workspace-dispatch.d.ts.map +1 -1
- package/pd-cli/dist/services/service-host/workspace-dispatch.js +1 -3
- package/pd-cli/dist/services/service-host/workspace-dispatch.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +616 -1319
- package/plugin/dist/core/openclaw-tool-declaration.d.ts +13 -0
- package/plugin/dist/index.d.ts +0 -9
- package/plugin/dist/openclaw-worker.d.ts +21 -8
- package/plugin/dist/openclaw-worker.js +267 -267
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installer.js +432 -120
- package/release-manager/dist/service-host-provisioning.js +645 -77
- package/release-manager/dist/utils/env.js +269 -49
- package/release-manager/package.json +3 -2
- package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +9 -1
- package/workbuddy-adapter/dist/worker/workspace-worker.js +21 -9
- package/workbuddy-adapter/package.json +1 -1
- package/pd-cli/dist/commands/service-handover.d.ts +0 -12
- package/pd-cli/dist/commands/service-handover.d.ts.map +0 -1
- package/pd-cli/dist/commands/service-handover.js +0 -117
- package/pd-cli/dist/commands/service-handover.js.map +0 -1
- package/pd-cli/dist/commands/worker-drain.d.ts +0 -7
- package/pd-cli/dist/commands/worker-drain.d.ts.map +0 -1
- package/pd-cli/dist/commands/worker-drain.js +0 -51
- package/pd-cli/dist/commands/worker-drain.js.map +0 -1
- package/pd-cli/dist/services/service-host/handover-claims.d.ts +0 -14
- package/pd-cli/dist/services/service-host/handover-claims.d.ts.map +0 -1
- package/pd-cli/dist/services/service-host/handover-claims.js +0 -50
- package/pd-cli/dist/services/service-host/handover-claims.js.map +0 -1
- package/pd-cli/dist/services/service-host/shadow-run.d.ts +0 -87
- package/pd-cli/dist/services/service-host/shadow-run.d.ts.map +0 -1
- package/pd-cli/dist/services/service-host/shadow-run.js +0 -549
- package/pd-cli/dist/services/service-host/shadow-run.js.map +0 -1
- package/pd-cli/dist/services/service-host/workspace-handover.d.ts +0 -190
- package/pd-cli/dist/services/service-host/workspace-handover.d.ts.map +0 -1
- package/pd-cli/dist/services/service-host/workspace-handover.js +0 -1393
- package/pd-cli/dist/services/service-host/workspace-handover.js.map +0 -1
- package/plugin/dist/service/gateway-consumer-lease.d.ts +0 -142
- package/plugin/dist/service/gateway-quiesce-ack.d.ts +0 -40
- package/plugin/dist/service/internalization-auto-consumer-service.d.ts +0 -100
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atomic logical-successor creation authority (PRI-1299 review round 2).
|
|
3
|
+
*
|
|
4
|
+
* Producers may choose their own preferred task-id shape (deterministic,
|
|
5
|
+
* timestamp, or fallback), but lookup, malformed-candidate adjudication,
|
|
6
|
+
* id-occupancy classification, and insert happen in one write transaction.
|
|
7
|
+
*/
|
|
8
|
+
import { createPITaskDiagnosticJson, hydratePITaskRecord } from './pitask-metadata.js';
|
|
9
|
+
import { lookupSuccessorByParent } from './successor-lookup.js';
|
|
10
|
+
async function classifyOccupant(taskId, stateManager) {
|
|
11
|
+
const occupant = await stateManager.getTask(taskId);
|
|
12
|
+
if (occupant === null)
|
|
13
|
+
return 'free';
|
|
14
|
+
return hydratePITaskRecord(occupant) === null ? 'malformed' : 'foreign';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Shared dry-run/confirm allocation classifier. It is read-only; atomic
|
|
18
|
+
* creation invokes it inside the write transaction while previews invoke the
|
|
19
|
+
* same function outside it.
|
|
20
|
+
*/
|
|
21
|
+
export async function planSuccessorIdAllocation(stateManager, input) {
|
|
22
|
+
const primary = await classifyOccupant(input.preferredTaskId, stateManager);
|
|
23
|
+
if (primary === 'free')
|
|
24
|
+
return { outcome: 'use_id', taskId: input.preferredTaskId, usedFallback: false };
|
|
25
|
+
if (primary === 'malformed') {
|
|
26
|
+
return {
|
|
27
|
+
outcome: 'id_conflict',
|
|
28
|
+
reason: 'occupant_metadata_unparseable',
|
|
29
|
+
detail: 'task ' + input.preferredTaskId + ' occupies the successor id with unparseable or non-PI diagnosticJson — repair corruption before creating',
|
|
30
|
+
conflictingTaskIds: [input.preferredTaskId],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (input.fallbackTaskId === undefined) {
|
|
34
|
+
return {
|
|
35
|
+
outcome: 'id_conflict',
|
|
36
|
+
reason: 'derived_and_fallback_ids_occupied_by_foreign_chain',
|
|
37
|
+
detail: 'primary=' + input.preferredTaskId + ' occupied and no fallback id is available',
|
|
38
|
+
conflictingTaskIds: [input.preferredTaskId],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const fallback = await classifyOccupant(input.fallbackTaskId, stateManager);
|
|
42
|
+
if (fallback === 'free')
|
|
43
|
+
return { outcome: 'use_id', taskId: input.fallbackTaskId, usedFallback: true };
|
|
44
|
+
if (fallback === 'malformed') {
|
|
45
|
+
return {
|
|
46
|
+
outcome: 'id_conflict',
|
|
47
|
+
reason: 'occupant_metadata_unparseable',
|
|
48
|
+
detail: 'task ' + input.fallbackTaskId + ' occupies the fallback successor id with unparseable or non-PI diagnosticJson — repair corruption before creating',
|
|
49
|
+
conflictingTaskIds: [input.fallbackTaskId],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
outcome: 'id_conflict',
|
|
54
|
+
reason: 'derived_and_fallback_ids_occupied_by_foreign_chain',
|
|
55
|
+
detail: 'primary=' + input.preferredTaskId + ' fallback=' + input.fallbackTaskId + ' both occupied; no successor for parent ' + input.parentTaskId,
|
|
56
|
+
conflictingTaskIds: [input.preferredTaskId, input.fallbackTaskId],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function isUniqueViolation(error) {
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
return message.includes('UNIQUE constraint') || message.includes('PRIMARY KEY') || message.includes('already exists');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create or reuse the unique successor for (parentTaskId, successorKind,
|
|
65
|
+
* channel). All read-check-write steps share the TaskStore write transaction,
|
|
66
|
+
* so independent SQLite connections serialize at BEGIN IMMEDIATE rather than
|
|
67
|
+
* racing a read-release-write window.
|
|
68
|
+
*/
|
|
69
|
+
export async function createLogicalSuccessorTask(input) {
|
|
70
|
+
return input.stateManager.withWriteTransaction(async () => {
|
|
71
|
+
const lookup = await lookupSuccessorByParent(input.stateManager, {
|
|
72
|
+
parentTaskId: input.parentTaskId,
|
|
73
|
+
successorKind: input.successorKind,
|
|
74
|
+
channel: input.channel,
|
|
75
|
+
});
|
|
76
|
+
if (lookup.outcome === 'conflict' || lookup.outcome === 'malformed') {
|
|
77
|
+
return { outcome: 'lookup', lookup };
|
|
78
|
+
}
|
|
79
|
+
if (lookup.outcome === 'unique')
|
|
80
|
+
return { outcome: 'existing', task: lookup.successor };
|
|
81
|
+
const allocation = await planSuccessorIdAllocation(input.stateManager, {
|
|
82
|
+
preferredTaskId: input.preferredTaskId,
|
|
83
|
+
...(input.fallbackTaskId !== undefined ? { fallbackTaskId: input.fallbackTaskId } : {}),
|
|
84
|
+
parentTaskId: input.parentTaskId,
|
|
85
|
+
successorKind: input.successorKind,
|
|
86
|
+
channel: input.channel,
|
|
87
|
+
});
|
|
88
|
+
if (allocation.outcome === 'id_conflict')
|
|
89
|
+
return { outcome: 'id_conflict', allocation };
|
|
90
|
+
try {
|
|
91
|
+
const task = await input.stateManager.createTask({
|
|
92
|
+
taskId: allocation.taskId,
|
|
93
|
+
taskKind: input.successorKind,
|
|
94
|
+
status: 'pending',
|
|
95
|
+
attemptCount: 0,
|
|
96
|
+
maxAttempts: 3,
|
|
97
|
+
diagnosticJson: createPITaskDiagnosticJson({
|
|
98
|
+
...input.metadata,
|
|
99
|
+
parentTaskId: input.parentTaskId,
|
|
100
|
+
channel: input.channel,
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
return { outcome: 'created', task, usedFallback: allocation.usedFallback };
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (!isUniqueViolation(error))
|
|
107
|
+
throw error;
|
|
108
|
+
// Defensive convergence for non-participating writers or alternate store
|
|
109
|
+
// implementations: re-arbitrate in the same transaction rather than
|
|
110
|
+
// treating the id collision as permission to duplicate the logical row.
|
|
111
|
+
const rescanned = await lookupSuccessorByParent(input.stateManager, {
|
|
112
|
+
parentTaskId: input.parentTaskId,
|
|
113
|
+
successorKind: input.successorKind,
|
|
114
|
+
channel: input.channel,
|
|
115
|
+
});
|
|
116
|
+
if (rescanned.outcome === 'unique')
|
|
117
|
+
return { outcome: 'existing', task: rescanned.successor };
|
|
118
|
+
if (rescanned.outcome === 'conflict' || rescanned.outcome === 'malformed') {
|
|
119
|
+
return { outcome: 'lookup', lookup: rescanned };
|
|
120
|
+
}
|
|
121
|
+
if (!allocation.usedFallback && input.fallbackTaskId !== undefined && input.fallbackTaskId !== allocation.taskId) {
|
|
122
|
+
try {
|
|
123
|
+
const fallbackTask = await input.stateManager.createTask({
|
|
124
|
+
taskId: input.fallbackTaskId,
|
|
125
|
+
taskKind: input.successorKind,
|
|
126
|
+
status: 'pending',
|
|
127
|
+
attemptCount: 0,
|
|
128
|
+
maxAttempts: 3,
|
|
129
|
+
diagnosticJson: createPITaskDiagnosticJson({
|
|
130
|
+
...input.metadata,
|
|
131
|
+
parentTaskId: input.parentTaskId,
|
|
132
|
+
channel: input.channel,
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
return { outcome: 'created', task: fallbackTask, usedFallback: true };
|
|
136
|
+
}
|
|
137
|
+
catch (fallbackError) {
|
|
138
|
+
if (!isUniqueViolation(fallbackError))
|
|
139
|
+
throw fallbackError;
|
|
140
|
+
const fallbackRescan = await lookupSuccessorByParent(input.stateManager, {
|
|
141
|
+
parentTaskId: input.parentTaskId,
|
|
142
|
+
successorKind: input.successorKind,
|
|
143
|
+
channel: input.channel,
|
|
144
|
+
});
|
|
145
|
+
if (fallbackRescan.outcome === 'unique')
|
|
146
|
+
return { outcome: 'existing', task: fallbackRescan.successor };
|
|
147
|
+
if (fallbackRescan.outcome === 'conflict' || fallbackRescan.outcome === 'malformed') {
|
|
148
|
+
return { outcome: 'lookup', lookup: fallbackRescan };
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
outcome: 'id_conflict',
|
|
152
|
+
allocation: {
|
|
153
|
+
outcome: 'id_conflict',
|
|
154
|
+
reason: 'derived_and_fallback_ids_occupied_by_foreign_chain',
|
|
155
|
+
detail: 'unique_violation_without_logical_successor:' + allocation.taskId + ',' + input.fallbackTaskId,
|
|
156
|
+
conflictingTaskIds: [allocation.taskId, input.fallbackTaskId],
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
outcome: 'id_conflict',
|
|
163
|
+
allocation: {
|
|
164
|
+
outcome: 'id_conflict',
|
|
165
|
+
reason: 'derived_and_fallback_ids_occupied_by_foreign_chain',
|
|
166
|
+
detail: 'unique_violation_without_logical_successor:' + allocation.taskId,
|
|
167
|
+
conflictingTaskIds: [allocation.taskId],
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=successor-create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"successor-create.js","sourceRoot":"","sources":["../../../src/runtime/internalization/successor-create.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAuB,MAAM,sBAAsB,CAAC;AAE5G,OAAO,EAAE,uBAAuB,EAA8B,MAAM,uBAAuB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,UAAU,CAAC,MAAM;oBACzE,kBAAkB,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;iBACxC;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-1299: single successor-identification and integrity-adjudication seam.
|
|
3
|
+
*
|
|
4
|
+
* Identity is exactly (parentTaskId, successorKind, channel). Persisted task
|
|
5
|
+
* id shape, insertion order, and lexical ordering are never identity evidence.
|
|
6
|
+
* TaskStore narrows exact candidates in its WHERE/filter layer; this module
|
|
7
|
+
* still reads identity itself because identity is a domain judgment, not a
|
|
8
|
+
* storage-row coincidence. Historical rows whose optional parent edge is
|
|
9
|
+
* absent remain eligible for the existing producer-specific lineage proof
|
|
10
|
+
* (inferLegacyParentTaskId). A row whose identity is provably relevant but
|
|
11
|
+
* whose PI metadata cannot be fully hydrated is fail-closed malformed input,
|
|
12
|
+
* never an invisible "none".
|
|
13
|
+
*/
|
|
14
|
+
import { type TaskRecord } from '../task-status.js';
|
|
15
|
+
import type { RuntimeStateManager } from '../store/runtime-state-manager.js';
|
|
16
|
+
import { type InternalizationChannel, type RunnerKind } from './peer-runner-contracts.js';
|
|
17
|
+
export interface SuccessorLookupQuery {
|
|
18
|
+
readonly parentTaskId: string;
|
|
19
|
+
readonly successorKind: RunnerKind;
|
|
20
|
+
readonly channel: InternalizationChannel;
|
|
21
|
+
}
|
|
22
|
+
export type SuccessorLookupResult = {
|
|
23
|
+
readonly outcome: 'none';
|
|
24
|
+
} | {
|
|
25
|
+
readonly outcome: 'unique';
|
|
26
|
+
readonly successor: TaskRecord;
|
|
27
|
+
} | {
|
|
28
|
+
readonly outcome: 'conflict';
|
|
29
|
+
readonly decision: 'successor_integrity_conflict';
|
|
30
|
+
readonly reason: 'multiple_successors_for_parent';
|
|
31
|
+
readonly detail: string;
|
|
32
|
+
readonly parentTaskId: string;
|
|
33
|
+
readonly successorKind: RunnerKind;
|
|
34
|
+
readonly channel: InternalizationChannel;
|
|
35
|
+
readonly conflictingSuccessors: readonly TaskRecord[];
|
|
36
|
+
readonly conflictingSuccessorTaskIds: readonly string[];
|
|
37
|
+
} | {
|
|
38
|
+
readonly outcome: 'malformed';
|
|
39
|
+
readonly decision: 'successor_metadata_malformed';
|
|
40
|
+
readonly reason: 'successor_metadata_malformed';
|
|
41
|
+
readonly detail: string;
|
|
42
|
+
readonly parentTaskId: string;
|
|
43
|
+
readonly successorKind: RunnerKind;
|
|
44
|
+
readonly channel: InternalizationChannel;
|
|
45
|
+
readonly malformedCandidates: readonly TaskRecord[];
|
|
46
|
+
readonly malformedCandidateTaskIds: readonly string[];
|
|
47
|
+
readonly nextAction: 'repair_malformed_successor_metadata_before_retry';
|
|
48
|
+
};
|
|
49
|
+
export declare function lookupSuccessorByParent(stateManager: RuntimeStateManager, query: SuccessorLookupQuery): Promise<SuccessorLookupResult>;
|
|
50
|
+
//# sourceMappingURL=successor-lookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"successor-lookup.d.ts","sourceRoot":"","sources":["../../../src/runtime/internalization/successor-lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAG7E,OAAO,EAA4B,KAAK,sBAAsB,EAAE,KAAK,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAEpH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;CAC1C;AAED,MAAM,MAAM,qBAAqB,GAC7B;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,QAAQ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|
+
*
|
|
4
|
+
* Identity is exactly (parentTaskId, successorKind, channel). Persisted task
|
|
5
|
+
* id shape, insertion order, and lexical ordering are never identity evidence.
|
|
6
|
+
* TaskStore narrows exact candidates in its WHERE/filter layer; this module
|
|
7
|
+
* still reads identity itself because identity is a domain judgment, not a
|
|
8
|
+
* storage-row coincidence. Historical rows whose optional parent edge is
|
|
9
|
+
* absent remain eligible for the existing producer-specific lineage proof
|
|
10
|
+
* (inferLegacyParentTaskId). A row whose identity is provably relevant but
|
|
11
|
+
* whose PI metadata cannot be fully hydrated is fail-closed malformed input,
|
|
12
|
+
* never an invisible "none".
|
|
13
|
+
*/
|
|
14
|
+
import { PD_TASK_STATUSES } from '../task-status.js';
|
|
15
|
+
import { hydratePITaskRecord } from './pitask-metadata.js';
|
|
16
|
+
import { inferLegacyParentTaskId } from './correlation-lineage.js';
|
|
17
|
+
import { isInternalizationChannel } from './peer-runner-contracts.js';
|
|
18
|
+
function byTaskId(a, b) {
|
|
19
|
+
return a.taskId < b.taskId ? -1 : a.taskId > b.taskId ? 1 : 0;
|
|
20
|
+
}
|
|
21
|
+
function isRecord(value) {
|
|
22
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read only the successor identity triple. This deliberately does not require
|
|
26
|
+
* the complete PI schema: corruption in non-identity fields must not erase the
|
|
27
|
+
* fact that this row claims the logical successor identity.
|
|
28
|
+
*/
|
|
29
|
+
function readSuccessorIdentity(task) {
|
|
30
|
+
const fullHydrationValid = hydratePITaskRecord(task) !== null;
|
|
31
|
+
const raw = task.diagnosticJson;
|
|
32
|
+
if (typeof raw !== 'string' || raw.trim() === '') {
|
|
33
|
+
return { available: false, malformed: false, parentTaskId: null, channel: null, fullHydrationValid, detail: 'pi_metadata_absent' };
|
|
34
|
+
}
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = JSON.parse(raw);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return { available: false, malformed: true, parentTaskId: null, channel: null, fullHydrationValid, detail: 'diagnostic_json_unparseable' };
|
|
41
|
+
}
|
|
42
|
+
if (!isRecord(parsed) || !Object.hasOwn(parsed, 'pi_metadata')) {
|
|
43
|
+
return { available: false, malformed: false, parentTaskId: null, channel: null, fullHydrationValid, detail: 'pi_metadata_absent' };
|
|
44
|
+
}
|
|
45
|
+
const piMetadata = parsed.pi_metadata;
|
|
46
|
+
if (!isRecord(piMetadata)) {
|
|
47
|
+
return { available: false, malformed: true, parentTaskId: null, channel: null, fullHydrationValid, detail: 'pi_metadata_not_object' };
|
|
48
|
+
}
|
|
49
|
+
const parentValue = piMetadata.parentTaskId;
|
|
50
|
+
const channelValue = piMetadata.channel;
|
|
51
|
+
const parentTaskId = typeof parentValue === 'string' && parentValue.length > 0 ? parentValue : null;
|
|
52
|
+
const channel = typeof channelValue === 'string' && channelValue.length > 0 ? channelValue : null;
|
|
53
|
+
if (parentValue !== undefined && parentValue !== null && parentTaskId === null) {
|
|
54
|
+
return { available: true, malformed: true, parentTaskId, channel, fullHydrationValid, detail: 'pi_parent_task_id_not_string' };
|
|
55
|
+
}
|
|
56
|
+
if (channel === null) {
|
|
57
|
+
return { available: true, malformed: true, parentTaskId, channel, fullHydrationValid, detail: 'pi_channel_missing_or_not_string' };
|
|
58
|
+
}
|
|
59
|
+
if (!fullHydrationValid) {
|
|
60
|
+
return { available: true, malformed: true, parentTaskId, channel, fullHydrationValid, detail: 'pi_metadata_full_hydration_failed' };
|
|
61
|
+
}
|
|
62
|
+
return { available: true, malformed: false, parentTaskId, channel, fullHydrationValid, detail: 'identity_valid' };
|
|
63
|
+
}
|
|
64
|
+
function identityMatches(identity, query) {
|
|
65
|
+
return identity.parentTaskId === query.parentTaskId && identity.channel === query.channel;
|
|
66
|
+
}
|
|
67
|
+
function exactClassification(task, query) {
|
|
68
|
+
if (task.taskKind !== query.successorKind)
|
|
69
|
+
return 'no';
|
|
70
|
+
const identity = readSuccessorIdentity(task);
|
|
71
|
+
if (!identityMatches(identity, query))
|
|
72
|
+
return 'no';
|
|
73
|
+
return identity.malformed ? 'malformed' : 'valid';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A malformed row is relevant when the identity evidence it still exposes can
|
|
77
|
+
* plausibly claim this logical successor: either the same persisted parent, or
|
|
78
|
+
* the same channel with no parent edge (the shape legacy rows use before
|
|
79
|
+
* producer-specific inference). Completely unattributable rows cannot prove a
|
|
80
|
+
* relation to this parent and are not allowed to block unrelated chains.
|
|
81
|
+
*/
|
|
82
|
+
function malformedCandidateIsRelevant(task, query) {
|
|
83
|
+
if (task.taskKind !== query.successorKind)
|
|
84
|
+
return false;
|
|
85
|
+
const identity = readSuccessorIdentity(task);
|
|
86
|
+
if (!identity.malformed)
|
|
87
|
+
return false;
|
|
88
|
+
if (identity.channel !== null && isInternalizationChannel(identity.channel) && identity.channel !== query.channel) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (identity.parentTaskId === query.parentTaskId)
|
|
92
|
+
return true;
|
|
93
|
+
return identity.channel === query.channel && identity.parentTaskId === null;
|
|
94
|
+
}
|
|
95
|
+
function malformedResult(query, malformedCandidates) {
|
|
96
|
+
const sorted = [...malformedCandidates].sort(byTaskId);
|
|
97
|
+
const malformedCandidateTaskIds = sorted.map((task) => task.taskId);
|
|
98
|
+
return {
|
|
99
|
+
outcome: 'malformed',
|
|
100
|
+
decision: 'successor_metadata_malformed',
|
|
101
|
+
reason: 'successor_metadata_malformed',
|
|
102
|
+
detail: 'parentTaskId=' + query.parentTaskId + ';successorKind=' + query.successorKind + ';channel=' + query.channel + ';malformedTaskIds=[' + malformedCandidateTaskIds.join(',') + ']',
|
|
103
|
+
parentTaskId: query.parentTaskId,
|
|
104
|
+
successorKind: query.successorKind,
|
|
105
|
+
channel: query.channel,
|
|
106
|
+
malformedCandidates: sorted,
|
|
107
|
+
malformedCandidateTaskIds,
|
|
108
|
+
nextAction: 'repair_malformed_successor_metadata_before_retry',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export async function lookupSuccessorByParent(stateManager, query) {
|
|
112
|
+
// Exact parentage rows are pushed down into TaskStore. The identity re-check
|
|
113
|
+
// above is deliberate: mocked/alternate stores must not widen identity by
|
|
114
|
+
// ignoring part of the storage filter.
|
|
115
|
+
const exactCandidates = await stateManager.listTasks({
|
|
116
|
+
statuses: [...PD_TASK_STATUSES],
|
|
117
|
+
taskKind: query.successorKind,
|
|
118
|
+
piParentTaskId: query.parentTaskId,
|
|
119
|
+
piChannel: query.channel,
|
|
120
|
+
});
|
|
121
|
+
const matches = [];
|
|
122
|
+
const malformedCandidates = [];
|
|
123
|
+
for (const task of exactCandidates) {
|
|
124
|
+
const classification = exactClassification(task, query);
|
|
125
|
+
if (classification === 'valid')
|
|
126
|
+
matches.push(task);
|
|
127
|
+
if (classification === 'malformed')
|
|
128
|
+
malformedCandidates.push(task);
|
|
129
|
+
}
|
|
130
|
+
// The broad second read intentionally does not push down piChannel: rows
|
|
131
|
+
// whose channel key is missing/corrupt would otherwise be invisible before
|
|
132
|
+
// the malformed-metadata fail-closed judgment can run. It must run even
|
|
133
|
+
// when the exact read already found a valid successor: a same-parent row
|
|
134
|
+
// with a missing channel (or same-channel row with a missing parent edge)
|
|
135
|
+
// is still evidence of a potentially duplicated logical successor and must
|
|
136
|
+
// not be hidden merely because one well-formed row exists.
|
|
137
|
+
const legacyCandidates = await stateManager.listTasks({
|
|
138
|
+
statuses: [...PD_TASK_STATUSES],
|
|
139
|
+
taskKind: query.successorKind,
|
|
140
|
+
});
|
|
141
|
+
// A reconciliation/backfill writer can persist a missing parent edge
|
|
142
|
+
// between the exact first read and this broader second read. Re-judge
|
|
143
|
+
// exact identity on this second snapshot first; otherwise that row would
|
|
144
|
+
// be skipped as "already parented" and neither exact nor inferred.
|
|
145
|
+
const seenExact = new Set(matches.concat(malformedCandidates).map((task) => task.taskId));
|
|
146
|
+
for (const task of legacyCandidates) {
|
|
147
|
+
if (seenExact.has(task.taskId))
|
|
148
|
+
continue;
|
|
149
|
+
const classification = exactClassification(task, query);
|
|
150
|
+
if (classification === 'valid')
|
|
151
|
+
matches.push(task);
|
|
152
|
+
if (classification === 'malformed')
|
|
153
|
+
malformedCandidates.push(task);
|
|
154
|
+
}
|
|
155
|
+
const dedupMalformed = new Set(malformedCandidates.map((task) => task.taskId));
|
|
156
|
+
for (const task of legacyCandidates) {
|
|
157
|
+
if (task.taskKind !== query.successorKind)
|
|
158
|
+
continue;
|
|
159
|
+
if (malformedCandidateIsRelevant(task, query) && !dedupMalformed.has(task.taskId)) {
|
|
160
|
+
malformedCandidates.push(task);
|
|
161
|
+
dedupMalformed.add(task.taskId);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Legacy inference is unconditional: an exact valid successor must never
|
|
165
|
+
// hide a second legacy successor whose parent edge was never persisted but
|
|
166
|
+
// whose producer-specific lineage proof resolves to the same parent — that
|
|
167
|
+
// pair is one logical successor duplicated, i.e. an integrity conflict, not
|
|
168
|
+
// a clean chain. The proof standard is unchanged: only
|
|
169
|
+
// inferLegacyParentTaskId evidence counts (dependencyTaskIds alone are
|
|
170
|
+
// never generic parentage proof), a persisted parent edge is never
|
|
171
|
+
// second-guessed, and malformed rows cannot fully hydrate so they never
|
|
172
|
+
// reach inference. Rows already exact-matched — by the first read or by the
|
|
173
|
+
// second-read race reclassification — are skipped, and the taskId set keeps
|
|
174
|
+
// one entry per row no matter how many scan paths can reach it, so the
|
|
175
|
+
// final uniqueness/conflict adjudication below sees the complete,
|
|
176
|
+
// duplicate-free match set.
|
|
177
|
+
const matchedTaskIds = new Set(matches.map((task) => task.taskId));
|
|
178
|
+
for (const task of legacyCandidates) {
|
|
179
|
+
if (task.taskKind !== query.successorKind)
|
|
180
|
+
continue;
|
|
181
|
+
if (matchedTaskIds.has(task.taskId))
|
|
182
|
+
continue;
|
|
183
|
+
const piTask = hydratePITaskRecord(task);
|
|
184
|
+
if (!piTask || piTask.parentTaskId || piTask.channel !== query.channel)
|
|
185
|
+
continue;
|
|
186
|
+
const inferred = await inferLegacyParentTaskId(task, piTask, stateManager);
|
|
187
|
+
if (inferred.ok && inferred.parentTaskId === query.parentTaskId) {
|
|
188
|
+
matches.push(task);
|
|
189
|
+
matchedTaskIds.add(task.taskId);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (malformedCandidates.length > 0)
|
|
193
|
+
return malformedResult(query, malformedCandidates);
|
|
194
|
+
matches.sort(byTaskId);
|
|
195
|
+
if (matches.length === 0)
|
|
196
|
+
return { outcome: 'none' };
|
|
197
|
+
const [first] = matches;
|
|
198
|
+
if (matches.length === 1 && first !== undefined)
|
|
199
|
+
return { outcome: 'unique', successor: first };
|
|
200
|
+
const conflictingSuccessorTaskIds = matches.map((task) => task.taskId);
|
|
201
|
+
return {
|
|
202
|
+
outcome: 'conflict',
|
|
203
|
+
decision: 'successor_integrity_conflict',
|
|
204
|
+
reason: 'multiple_successors_for_parent',
|
|
205
|
+
detail: 'parentTaskId=' + query.parentTaskId + ';successorKind=' + query.successorKind + ';channel=' + query.channel + ';taskIds=[' + conflictingSuccessorTaskIds.join(',') + ']',
|
|
206
|
+
parentTaskId: query.parentTaskId,
|
|
207
|
+
successorKind: query.successorKind,
|
|
208
|
+
channel: query.channel,
|
|
209
|
+
conflictingSuccessors: matches,
|
|
210
|
+
conflictingSuccessorTaskIds,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=successor-lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"successor-lookup.js","sourceRoot":"","sources":["../../../src/runtime/internalization/successor-lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,gBAAgB,EAAmB,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE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,GAAG,KAAK,CAAC,OAAO,GAAG,YAAY,GAAG,2BAA2B,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG;QACjL,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,qBAAqB,EAAE,OAAO;QAC9B,2BAA2B;KAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable recovery of an already-succeeded peer runner result.
|
|
3
|
+
*
|
|
4
|
+
* Recovery is evidence-based, never a synthetic success: the terminal task's
|
|
5
|
+
* resultRef selects the authoritative run, the run must be the fenced
|
|
6
|
+
* task_completed row, its output must re-pass the runner validator, and the
|
|
7
|
+
* deterministic principle artifact must exist in the current artifact view.
|
|
8
|
+
*/
|
|
9
|
+
import type { TaskRecord } from '../task-status.js';
|
|
10
|
+
import type { RuntimeStateManager } from '../store/runtime-state-manager.js';
|
|
11
|
+
import type { PIArtifactStore } from '../internalization/pi-artifact.js';
|
|
12
|
+
import type { PeerRunnerResult } from './peer-runner-types.js';
|
|
13
|
+
import type { RunRecord } from '../runtime-protocol.js';
|
|
14
|
+
export type SucceededRunnerRecovery<TOutput> = {
|
|
15
|
+
readonly outcome: 'recovered';
|
|
16
|
+
readonly result: PeerRunnerResult<TOutput>;
|
|
17
|
+
} | {
|
|
18
|
+
readonly outcome: 'invalid';
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
};
|
|
21
|
+
export interface RecoverSucceededResultInput<TOutput> {
|
|
22
|
+
readonly task: TaskRecord;
|
|
23
|
+
readonly expectedTaskKind: string;
|
|
24
|
+
readonly resultRefPrefix: string;
|
|
25
|
+
readonly stateManager: Pick<RuntimeStateManager, 'getRunsByTask'> & Partial<Pick<RuntimeStateManager, 'getValidRunsByTaskTolerant'>>;
|
|
26
|
+
readonly artifactStore: Pick<PIArtifactStore, 'getArtifactById' | 'listBySourceTaskId'>;
|
|
27
|
+
readonly validateOutput: (output: unknown, taskId: string) => Promise<{
|
|
28
|
+
valid: boolean;
|
|
29
|
+
errors: readonly string[];
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Runner-specific validation for an authoritative output run that is not
|
|
33
|
+
* itself the clean terminal row. Evaluator completion-intent recovery can
|
|
34
|
+
* legitimately persist output on run N and write terminal success on a later
|
|
35
|
+
* resume run N+1 while resultRef still selects run N. This hook must verify
|
|
36
|
+
* that separate completion evidence; returning null means valid. When absent,
|
|
37
|
+
* an incomplete authoritative run is always invalid.
|
|
38
|
+
*/
|
|
39
|
+
readonly validateIncompleteAuthoritativeRun?: (input: {
|
|
40
|
+
readonly task: TaskRecord;
|
|
41
|
+
readonly authoritativeRun: RunRecord;
|
|
42
|
+
readonly runs: readonly RunRecord[];
|
|
43
|
+
}) => string | null;
|
|
44
|
+
/** Additional persisted-evidence consistency rule. Return null when valid. */
|
|
45
|
+
readonly verifyRecoveredEvidence?: (input: {
|
|
46
|
+
readonly task: TaskRecord;
|
|
47
|
+
readonly output: TOutput;
|
|
48
|
+
readonly artifactOutput: TOutput;
|
|
49
|
+
readonly runId: string;
|
|
50
|
+
}) => string | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Recover the exact successful execution result bound to a terminal task.
|
|
54
|
+
* Any absent or inconsistent evidence is fail-closed; callers must not treat
|
|
55
|
+
* recovery failure as permission to execute the terminal task again.
|
|
56
|
+
*/
|
|
57
|
+
export declare function recoverSucceededPeerRunnerResult<TOutput>(input: RecoverSucceededResultInput<TOutput>): Promise<SucceededRunnerRecovery<TOutput>>;
|
|
58
|
+
//# sourceMappingURL=succeeded-result-recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"succeeded-result-recovery.d.ts","sourceRoot":"","sources":["../../../src/runtime/runner/succeeded-result-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KA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EAAE,UAAU,CAAC;QAC1B,QAAQ,CAAC,gBAAgB,EAAE,SAAS,CAAC;QACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;KACrC,KAAK,MAAM,GAAG,IAAI,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;QAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;QACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,KAAK,MAAM,GAAG,IAAI,CAAC;CACrB;AAsBD;;;;GAIG;AACH,wBAAsB,gCAAgC,CAAC,OAAO,EAC5D,KAAK,EAAE,2BAA2B,CAAC,OAAO,CAAC,GAC1C,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAmF3C"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
function invalid(reason) {
|
|
2
|
+
return { outcome: 'invalid', reason };
|
|
3
|
+
}
|
|
4
|
+
function parseJsonObject(raw) {
|
|
5
|
+
try {
|
|
6
|
+
const parsed = JSON.parse(raw);
|
|
7
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : null;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function terminalRunError(run) {
|
|
14
|
+
if (run.executionStatus !== 'succeeded')
|
|
15
|
+
return `authoritative_run_not_succeeded:${run.executionStatus}`;
|
|
16
|
+
if (run.reason !== 'task_completed')
|
|
17
|
+
return `authoritative_run_not_terminal:${run.reason ?? 'missing_reason'}`;
|
|
18
|
+
if (run.errorCategory !== undefined)
|
|
19
|
+
return `authoritative_run_has_error:${run.errorCategory}`;
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Recover the exact successful execution result bound to a terminal task.
|
|
24
|
+
* Any absent or inconsistent evidence is fail-closed; callers must not treat
|
|
25
|
+
* recovery failure as permission to execute the terminal task again.
|
|
26
|
+
*/
|
|
27
|
+
export async function recoverSucceededPeerRunnerResult(input) {
|
|
28
|
+
const { task } = input;
|
|
29
|
+
if (task.taskKind !== input.expectedTaskKind) {
|
|
30
|
+
return invalid(`task_kind_mismatch:${task.taskKind}`);
|
|
31
|
+
}
|
|
32
|
+
if (task.status !== 'succeeded') {
|
|
33
|
+
return invalid(`task_not_succeeded:${task.status}`);
|
|
34
|
+
}
|
|
35
|
+
if (task.leaseOwner !== null && task.leaseOwner !== undefined) {
|
|
36
|
+
return invalid('terminal_task_still_leased');
|
|
37
|
+
}
|
|
38
|
+
const { resultRef } = task;
|
|
39
|
+
if (typeof resultRef !== 'string' || !resultRef.startsWith(`${input.resultRefPrefix}://`)) {
|
|
40
|
+
return invalid('result_ref_missing_or_prefix_mismatch');
|
|
41
|
+
}
|
|
42
|
+
const runId = resultRef.slice(input.resultRefPrefix.length + 3);
|
|
43
|
+
if (runId.length === 0)
|
|
44
|
+
return invalid('result_ref_run_id_empty');
|
|
45
|
+
const runs = input.stateManager.getValidRunsByTaskTolerant === undefined
|
|
46
|
+
? await input.stateManager.getRunsByTask(task.taskId)
|
|
47
|
+
: (await input.stateManager.getValidRunsByTaskTolerant(task.taskId)).runs;
|
|
48
|
+
const run = runs.find((candidate) => candidate.runId === runId);
|
|
49
|
+
if (!run)
|
|
50
|
+
return invalid(`authoritative_run_missing:${runId}`);
|
|
51
|
+
if (run.taskId !== task.taskId)
|
|
52
|
+
return invalid('authoritative_run_task_mismatch');
|
|
53
|
+
const authoritativeTerminalError = terminalRunError(run);
|
|
54
|
+
if (authoritativeTerminalError !== null) {
|
|
55
|
+
const completionEvidenceError = input.validateIncompleteAuthoritativeRun === undefined
|
|
56
|
+
? authoritativeTerminalError
|
|
57
|
+
: input.validateIncompleteAuthoritativeRun({
|
|
58
|
+
task,
|
|
59
|
+
authoritativeRun: run,
|
|
60
|
+
runs,
|
|
61
|
+
});
|
|
62
|
+
if (completionEvidenceError !== null)
|
|
63
|
+
return invalid(completionEvidenceError);
|
|
64
|
+
}
|
|
65
|
+
if (typeof run.outputPayload !== 'string' || run.outputPayload.length === 0) {
|
|
66
|
+
return invalid('successor_result_unavailable:output_payload_missing');
|
|
67
|
+
}
|
|
68
|
+
const parsedOutput = parseJsonObject(run.outputPayload);
|
|
69
|
+
if (parsedOutput === null)
|
|
70
|
+
return invalid('successor_result_unavailable:output_payload_unparseable');
|
|
71
|
+
const outputValidation = await input.validateOutput(parsedOutput, task.taskId);
|
|
72
|
+
if (!outputValidation.valid) {
|
|
73
|
+
return invalid(`output_payload_validation_failed:${outputValidation.errors.join(';')}`);
|
|
74
|
+
}
|
|
75
|
+
const output = parsedOutput;
|
|
76
|
+
const artifactId = `pi-art-${task.taskId}-${runId}`;
|
|
77
|
+
const artifact = await input.artifactStore.getArtifactById(artifactId);
|
|
78
|
+
if (!artifact)
|
|
79
|
+
return invalid(`principle_artifact_missing:${artifactId}`);
|
|
80
|
+
if (artifact.artifactKind !== 'principle')
|
|
81
|
+
return invalid(`artifact_kind_mismatch:${artifact.artifactKind}`);
|
|
82
|
+
if (artifact.sourceTaskId !== task.taskId)
|
|
83
|
+
return invalid('artifact_source_task_mismatch');
|
|
84
|
+
const currentArtifacts = await input.artifactStore.listBySourceTaskId(task.taskId);
|
|
85
|
+
if (!currentArtifacts.some((candidate) => candidate.artifactId === artifactId)) {
|
|
86
|
+
return invalid('principle_artifact_not_in_current_revision_view');
|
|
87
|
+
}
|
|
88
|
+
const parsedArtifactOutput = parseJsonObject(artifact.contentJson);
|
|
89
|
+
if (parsedArtifactOutput === null)
|
|
90
|
+
return invalid('artifact_content_unparseable');
|
|
91
|
+
const artifactValidation = await input.validateOutput(parsedArtifactOutput, task.taskId);
|
|
92
|
+
if (!artifactValidation.valid) {
|
|
93
|
+
return invalid(`artifact_content_validation_failed:${artifactValidation.errors.join(';')}`);
|
|
94
|
+
}
|
|
95
|
+
const artifactOutput = parsedArtifactOutput;
|
|
96
|
+
const consistencyError = input.verifyRecoveredEvidence?.({
|
|
97
|
+
task,
|
|
98
|
+
output,
|
|
99
|
+
artifactOutput,
|
|
100
|
+
runId,
|
|
101
|
+
}) ?? null;
|
|
102
|
+
if (consistencyError !== null)
|
|
103
|
+
return invalid(consistencyError);
|
|
104
|
+
return {
|
|
105
|
+
outcome: 'recovered',
|
|
106
|
+
result: {
|
|
107
|
+
status: 'succeeded',
|
|
108
|
+
taskId: task.taskId,
|
|
109
|
+
runId,
|
|
110
|
+
artifactId,
|
|
111
|
+
resultRef,
|
|
112
|
+
output,
|
|
113
|
+
attemptCount: task.attemptCount,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=succeeded-result-recovery.js.map
|