create-principles-disciple 1.156.1 → 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 +432 -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 +11 -1
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +18 -1
- 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 +126 -0
- package/core/dist/runtime/internalization/correlation-lineage.d.ts.map +1 -0
- package/core/dist/runtime/internalization/correlation-lineage.js +431 -0
- package/core/dist/runtime/internalization/correlation-lineage.js.map +1 -0
- 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 +97 -17
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.js +730 -139
- package/core/dist/runtime/internalization/internalization-orchestrator.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-state-machine.d.ts +14 -0
- package/core/dist/runtime/internalization/internalization-state-machine.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-state-machine.js +22 -0
- package/core/dist/runtime/internalization/internalization-state-machine.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 +4 -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 +67 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.js +77 -3
- 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 +138 -0
- package/core/dist/runtime/internalization/repair-task-identity.d.ts.map +1 -0
- package/core/dist/runtime/internalization/repair-task-identity.js +320 -0
- package/core/dist/runtime/internalization/repair-task-identity.js.map +1 -0
- package/core/dist/runtime/internalization/revision-reopen.d.ts +93 -1
- package/core/dist/runtime/internalization/revision-reopen.d.ts.map +1 -1
- package/core/dist/runtime/internalization/revision-reopen.js +215 -35
- package/core/dist/runtime/internalization/revision-reopen.js.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +8 -9
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +15 -70
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/rule-binding-revision.js +3 -3
- package/core/dist/runtime/internalization/rule-binding-revision.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 -1
- package/host-runtime/dist/index.js +16 -2
- package/host-runtime/dist/internalization-consumer-cycle.d.ts +12 -4
- package/host-runtime/dist/internalization-consumer-cycle.js +103 -99
- package/host-runtime/dist/internalization-consumer-governance.d.ts +4 -3
- package/host-runtime/dist/internalization-consumer-governance.js +17 -41
- 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 +263 -78
- 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 +213 -127
- 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 +202 -97
- 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 +271 -271
- 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
|
@@ -13,8 +13,16 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @see docs/adr/0003-peer-agent-state-machine-orchestration.md
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { deriveSuccessorTaskId } from './internalization-state-machine.js';
|
|
17
|
+
import { hydratePITaskRecord, createPITaskDiagnosticJson, mergePITaskMetadata, hasConsumedRevisionCause } from './pitask-metadata.js';
|
|
18
|
+
import { reopenTaskForRevision, buildRepairRevisionCauseId, planExistingSuccessorTransition, planRevisionReopenInitialState } from './revision-reopen.js';
|
|
19
|
+
import { planStaleRepairTransitionFromDependencyScan, scanEvaluatorArtificerDependencyIdentity, verifyRepairTaskIdentity } from './repair-task-identity.js';
|
|
20
|
+
import { lookupSuccessorByParent } from './successor-lookup.js';
|
|
21
|
+
import { createLogicalSuccessorTask } from './successor-create.js';
|
|
22
|
+
import { validateAndBackfillRepairLineage } from './repair-lineage-backfill.js';
|
|
23
|
+
// PRI-1293 Phase 3: 唯一 PeerRunnerKind 血缘权威解析器 (core 内部模块,
|
|
24
|
+
// 不入 barrel — 跨包消费方经 InternalizationOrchestrator 静态只读包装访问)。
|
|
25
|
+
import { resolveAuthoritativeCorrelationId, resolveAuthoritativeCorrelationIdWithLegacyBackfill, planLegacyLineageResolution, CORRELATION_LINEAGE_MAX_PARENT_EDGES, } from './correlation-lineage.js';
|
|
18
26
|
import { isPeerRunnerKind, isDiagnosticianStageKind, isRunnerKind } from './peer-runner-contracts.js';
|
|
19
27
|
import { validateInternalizationTaskReady, createNextTaskProposal, } from './internalization-state-machine.js';
|
|
20
28
|
import { getDiagSuccessors } from './internalization-job-graph.js';
|
|
@@ -25,24 +33,6 @@ import { evaluateAndPersistAdmissionFromStore } from '../pain-signal-bridge.js';
|
|
|
25
33
|
import { denyAllSourceMaterialAuthorization } from '../source-material-authorization.js';
|
|
26
34
|
import { decideInternalizationTransition, transitionInputFromTask, } from './internalization-transition-decision.js';
|
|
27
35
|
import { PDRuntimeError } from '../error-categories.js';
|
|
28
|
-
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
29
|
-
/**
|
|
30
|
-
* Strip a trailing `-<channel>` segment from a task id so that re-appending
|
|
31
|
-
* `-${channel}` does not accumulate duplicates.
|
|
32
|
-
*
|
|
33
|
-
* Used as a fallback when proposal.correlationId is unavailable (e.g. legacy
|
|
34
|
-
* diagnostician-chain seeds). Example: `dreamer-cand-1-prompt` + channel
|
|
35
|
-
* `prompt` → `dreamer-cand-1`.
|
|
36
|
-
*
|
|
37
|
-
* Guarded: only strips when the suffix EXACTLY matches the channel, so task ids
|
|
38
|
-
* that merely contain the channel substring elsewhere are left intact.
|
|
39
|
-
*/
|
|
40
|
-
function stripTrailingChannel(taskId, channel) {
|
|
41
|
-
if (!channel)
|
|
42
|
-
return taskId;
|
|
43
|
-
const suffix = `-${channel}`;
|
|
44
|
-
return taskId.endsWith(suffix) ? taskId.slice(0, taskId.length - suffix.length) : taskId;
|
|
45
|
-
}
|
|
46
36
|
/**
|
|
47
37
|
* Runtime decision labels for WakeOnceResult — used by host layers for
|
|
48
38
|
* logging, metrics bucketing, and switch-statement exhaustiveness checks.
|
|
@@ -58,6 +48,14 @@ export const WAKE_ONCE_DECISIONS = [
|
|
|
58
48
|
'lease_conflict',
|
|
59
49
|
'invalid_task_metadata',
|
|
60
50
|
];
|
|
51
|
+
/** Private transaction-rollback signal; caught at the transaction boundary and translated back to the structured public result. */
|
|
52
|
+
class CommitDecisionRollback extends Error {
|
|
53
|
+
result;
|
|
54
|
+
constructor(result) {
|
|
55
|
+
super('rollback commit decision');
|
|
56
|
+
this.result = result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
61
59
|
/** PRI-1047 Owner review R6 #3: source-correction 定点续接「读取→守卫→CAS」
|
|
62
60
|
* 的有界重试上限——瞬时并发写者(只改无关信息)重试而非误记终态冲突。 */
|
|
63
61
|
const SOURCE_CORRECTION_REOPEN_CAS_ATTEMPTS = 3;
|
|
@@ -78,6 +76,17 @@ export class InternalizationOrchestrator {
|
|
|
78
76
|
this.runtimeKind = options.runtimeKind;
|
|
79
77
|
this.dryRun = options.dryRun ?? false;
|
|
80
78
|
}
|
|
79
|
+
// ── PRI-1293 Phase 3: 跨包血缘解析通道 (静态只读) ─────────────────────────
|
|
80
|
+
//
|
|
81
|
+
// resolveAuthoritativeCorrelationId 是 core 内部模块 correlation-lineage.ts
|
|
82
|
+
// 的唯一实现; host-runtime (Evaluator Repair Seeder) 与 pd-cli
|
|
83
|
+
// (rulehost seeder) 需要同一判定结果, 但 resolver 不得成为新的 barrel 公开
|
|
84
|
+
// 符号 (PRI-775 冻结面), 也不得复制第二套父链遍历。既有公开类上的静态只读
|
|
85
|
+
// 薄包装是 SPEC §5.4 授权的共享通道: 零状态、零写入, 仅委托。
|
|
86
|
+
/** PeerRunnerKind 父链 correlationId 权威解析 — 只读, 详见 correlation-lineage.ts。 */
|
|
87
|
+
static resolveAuthoritativeCorrelationId(leafTaskRecord, getTask) {
|
|
88
|
+
return resolveAuthoritativeCorrelationId(leafTaskRecord, getTask);
|
|
89
|
+
}
|
|
81
90
|
// ── wakeOnce ──────────────────────────────────────────────────────────────
|
|
82
91
|
/**
|
|
83
92
|
* Find the first leasable PI task, validate dependencies, and acquire lease
|
|
@@ -409,6 +418,248 @@ export class InternalizationOrchestrator {
|
|
|
409
418
|
proposal,
|
|
410
419
|
};
|
|
411
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* Read-only preview of the same state-machine gate used by commit. It never
|
|
423
|
+
* writes lineage, tasks, cascade state, or metadata. null means the source is
|
|
424
|
+
* eligible to continue to proposal/successor arbitration.
|
|
425
|
+
*/
|
|
426
|
+
async previewNextTaskTransitionGate(taskId) {
|
|
427
|
+
const rawTask = await this.stateManager.getTask(taskId);
|
|
428
|
+
if (!rawTask)
|
|
429
|
+
return { decision: 'task_not_found', taskId };
|
|
430
|
+
const piTask = hydratePITaskRecord(rawTask);
|
|
431
|
+
if (!piTask)
|
|
432
|
+
return { decision: 'invalid_task_metadata', taskId, reason: 'Failed to hydrate PITaskRecord from diagnosticJson' };
|
|
433
|
+
const legacyVerdict = await this.resolveLegacyRunnerVerdict(taskId, rawTask.taskKind);
|
|
434
|
+
const adversarialReplayFailed = rawTask.taskKind === 'evaluator'
|
|
435
|
+
? await this.resolveAdversarialReplayFailed(taskId)
|
|
436
|
+
: false;
|
|
437
|
+
const transition = decideInternalizationTransition(transitionInputFromTask(piTask, legacyVerdict, { adversarialReplayFailed }));
|
|
438
|
+
if (transition.kind === 'HUMAN_REVIEW_REQUIRED' || transition.kind === 'NOT_ADVANCEABLE') {
|
|
439
|
+
return { decision: 'source_not_succeeded', taskId, status: piTask.status };
|
|
440
|
+
}
|
|
441
|
+
if (transition.kind === 'BLOCKED_MISSING_VERDICT') {
|
|
442
|
+
return { decision: 'blocked_missing_verdict', taskId, reason: transition.reason };
|
|
443
|
+
}
|
|
444
|
+
if (transition.kind === 'REVISION_REQUIRED') {
|
|
445
|
+
return { decision: 'blocked_by_revision', sourceTaskId: taskId, reason: transition.reason, runnerDecision: piTask.runnerDecision ?? 'unknown' };
|
|
446
|
+
}
|
|
447
|
+
if (transition.kind === 'TERMINAL_REJECT') {
|
|
448
|
+
return { decision: 'blocked_by_rejection', sourceTaskId: taskId, reason: transition.reason, runnerDecision: piTask.runnerDecision ?? 'unknown' };
|
|
449
|
+
}
|
|
450
|
+
if (transition.kind === 'REOPEN_SOURCE_EVALUATOR') {
|
|
451
|
+
return this.previewRepairReopenTransition(rawTask, piTask, transition.reason);
|
|
452
|
+
}
|
|
453
|
+
if (piTask.status !== 'succeeded') {
|
|
454
|
+
return { decision: 'source_not_succeeded', taskId, status: piTask.status };
|
|
455
|
+
}
|
|
456
|
+
if (rawTask.taskKind === 'scribe' && piTask.sourceCorrectionReceipt !== undefined
|
|
457
|
+
&& piTask.sourceCorrectionCauseId !== undefined
|
|
458
|
+
&& piTask.revisionCauseId === piTask.sourceCorrectionCauseId) {
|
|
459
|
+
if (piTask.sourceCorrectionReceipt.reopenOutcome !== undefined) {
|
|
460
|
+
return {
|
|
461
|
+
decision: 'source_correction_reopen_noop',
|
|
462
|
+
sourceTaskId: taskId,
|
|
463
|
+
reopenedTaskId: piTask.sourceCorrectionReceipt.artificerTaskId,
|
|
464
|
+
reason: `source_correction_outcome_recorded:${piTask.sourceCorrectionReceipt.reopenOutcome.kind}`,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
return this.previewSourceCorrectionReopen(taskId, piTask);
|
|
468
|
+
}
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Shared stale-repair guard for preview and commit. The evaluator dependency
|
|
473
|
+
* chain is scanned through the single Core repair dependency resolver — an
|
|
474
|
+
* ordinary artificer never terminates the scan early, malformed/unprovable
|
|
475
|
+
* repair candidates fail closed, and only another valid same-evaluator repair
|
|
476
|
+
* at an equal/newer round supersedes this completion.
|
|
477
|
+
*/
|
|
478
|
+
async resolveStaleRepairTransitionGuard(input) {
|
|
479
|
+
const scan = await scanEvaluatorArtificerDependencyIdentity({
|
|
480
|
+
evaluatorTask: input.sourceEvaluatorTask,
|
|
481
|
+
store: this.stateManager,
|
|
482
|
+
});
|
|
483
|
+
return planStaleRepairTransitionFromDependencyScan({
|
|
484
|
+
scan,
|
|
485
|
+
completingRepairTaskId: input.completingRepairTaskId,
|
|
486
|
+
completingRepairIteration: input.completingRepairIteration,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Read-only projection of the repair-completion branch. It performs the
|
|
491
|
+
* same identity, causal-idempotency, superseded-repair, target-state and
|
|
492
|
+
* lineage judgments as commit, but never backfills lineage metadata and
|
|
493
|
+
* never reopens the source evaluator.
|
|
494
|
+
*/
|
|
495
|
+
async previewRepairReopenTransition(rawTask, piTask, transitionReason) {
|
|
496
|
+
const { taskId } = rawTask;
|
|
497
|
+
const payload = piTask.repairPayload;
|
|
498
|
+
if (!payload) {
|
|
499
|
+
return {
|
|
500
|
+
decision: 'lineage_refused',
|
|
501
|
+
sourceTaskId: taskId,
|
|
502
|
+
reason: 'repair_role_payload_missing',
|
|
503
|
+
detail: `repair task ${taskId} carries repairTaskRole but no valid repairPayload — source evaluator NOT reopened, zero writes`,
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
const repairIdentity = await verifyRepairTaskIdentity(rawTask, payload.sourceEvaluatorTaskId, payload.repairIteration, this.stateManager);
|
|
507
|
+
if (!repairIdentity.ok) {
|
|
508
|
+
return {
|
|
509
|
+
decision: 'lineage_refused',
|
|
510
|
+
sourceTaskId: taskId,
|
|
511
|
+
reason: repairIdentity.reason,
|
|
512
|
+
detail: `repair_identity_verification_failed:${repairIdentity.detail} — source evaluator NOT reopened, zero writes`,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
const causeId = buildRepairRevisionCauseId(piTask);
|
|
516
|
+
const srcRaw = await this.stateManager.getTask(payload.sourceEvaluatorTaskId);
|
|
517
|
+
const srcPi = srcRaw ? hydratePITaskRecord(srcRaw) : null;
|
|
518
|
+
if (srcPi && hasConsumedRevisionCause(srcPi, causeId)) {
|
|
519
|
+
return {
|
|
520
|
+
decision: 'revision_reopen_noop',
|
|
521
|
+
sourceTaskId: taskId,
|
|
522
|
+
reopenedTaskId: payload.sourceEvaluatorTaskId,
|
|
523
|
+
reason: 'revision_cause_already_materialized',
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
if (srcPi && srcRaw) {
|
|
527
|
+
const staleGuard = await this.resolveStaleRepairTransitionGuard({
|
|
528
|
+
sourceEvaluatorTask: srcRaw,
|
|
529
|
+
completingRepairTaskId: taskId,
|
|
530
|
+
completingRepairIteration: payload.repairIteration,
|
|
531
|
+
});
|
|
532
|
+
if (staleGuard.kind === 'invalid') {
|
|
533
|
+
return {
|
|
534
|
+
decision: 'lineage_refused',
|
|
535
|
+
sourceTaskId: taskId,
|
|
536
|
+
reason: staleGuard.reason,
|
|
537
|
+
detail: `stale_repair_guard_unprovable:${staleGuard.detail} — source evaluator NOT reopened, zero writes`,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
if (staleGuard.kind === 'superseded') {
|
|
541
|
+
return {
|
|
542
|
+
decision: 'revision_reopen_noop',
|
|
543
|
+
sourceTaskId: taskId,
|
|
544
|
+
reopenedTaskId: payload.sourceEvaluatorTaskId,
|
|
545
|
+
reason: 'stale_repair_transition_superseded',
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
// PRI-1299 P2 (preview/confirm parity): 初始状态分类必须经共享纯规划器 —
|
|
550
|
+
// confirm (reopenTaskForRevision 第一快照门) 对初始 leased 的业务拒绝是
|
|
551
|
+
// task_in_flight_leased (映射 revision_reopen_failed); 预览此前误报
|
|
552
|
+
// concurrent_modification, 但单次快照的只读预览不存在竞争窗口 —
|
|
553
|
+
// concurrent_modification 只属于 confirm 的血缘校验漂移/CAS 并发落败。
|
|
554
|
+
const initialPlan = planRevisionReopenInitialState(srcRaw, causeId);
|
|
555
|
+
switch (initialPlan.plan) {
|
|
556
|
+
case 'task_not_found':
|
|
557
|
+
return {
|
|
558
|
+
decision: 'revision_reopen_failed',
|
|
559
|
+
sourceTaskId: taskId,
|
|
560
|
+
reopenedTaskId: payload.sourceEvaluatorTaskId,
|
|
561
|
+
reason: 'task_not_found',
|
|
562
|
+
};
|
|
563
|
+
case 'invalid_task_metadata':
|
|
564
|
+
return {
|
|
565
|
+
decision: 'invalid_task_metadata',
|
|
566
|
+
taskId: payload.sourceEvaluatorTaskId,
|
|
567
|
+
reason: 'repair_evaluator_reopen_invalid_task_metadata',
|
|
568
|
+
};
|
|
569
|
+
case 'idempotent_replay_same_revision':
|
|
570
|
+
// 前置 consumed 检查 (上方) 通常先命中; 此处兜底保持同一业务类别
|
|
571
|
+
// (valid metadata 时不可达 — 顺序与 confirm 一致所需)。
|
|
572
|
+
return {
|
|
573
|
+
decision: 'revision_reopen_noop',
|
|
574
|
+
sourceTaskId: taskId,
|
|
575
|
+
reopenedTaskId: payload.sourceEvaluatorTaskId,
|
|
576
|
+
reason: 'revision_cause_already_materialized',
|
|
577
|
+
};
|
|
578
|
+
case 'refused_in_flight':
|
|
579
|
+
return {
|
|
580
|
+
decision: 'revision_reopen_failed',
|
|
581
|
+
sourceTaskId: taskId,
|
|
582
|
+
reopenedTaskId: payload.sourceEvaluatorTaskId,
|
|
583
|
+
reason: initialPlan.reason,
|
|
584
|
+
};
|
|
585
|
+
case 'proceed':
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
// proceed 蕴含行存在且 metadata 可解析 — 经规划器携带的窄化快照继续。
|
|
589
|
+
const proceedRaw = initialPlan.rawTask;
|
|
590
|
+
if (isPeerRunnerKind(proceedRaw.taskKind)) {
|
|
591
|
+
const lineage = await planLegacyLineageResolution(proceedRaw, this.stateManager);
|
|
592
|
+
if (!lineage.ok) {
|
|
593
|
+
return {
|
|
594
|
+
decision: 'lineage_refused',
|
|
595
|
+
sourceTaskId: taskId,
|
|
596
|
+
reason: lineage.reason,
|
|
597
|
+
detail: lineage.detail,
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return {
|
|
602
|
+
decision: 'revision_reopened',
|
|
603
|
+
sourceTaskId: taskId,
|
|
604
|
+
reopenedTaskId: payload.sourceEvaluatorTaskId,
|
|
605
|
+
reason: transitionReason,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Read-only projection of source-correction targeted reopen. The confirm
|
|
610
|
+
* path additionally records receipt.reopenOutcome and performs the CAS;
|
|
611
|
+
* every business guard classification is mirrored here without either write.
|
|
612
|
+
*/
|
|
613
|
+
async previewSourceCorrectionReopen(scribeTaskId, scribePi) {
|
|
614
|
+
const receipt = scribePi.sourceCorrectionReceipt;
|
|
615
|
+
if (receipt === undefined) {
|
|
616
|
+
return { decision: 'invalid_task_metadata', taskId: scribeTaskId, reason: 'source_correction_receipt_missing' };
|
|
617
|
+
}
|
|
618
|
+
const causeId = scribePi.sourceCorrectionCauseId
|
|
619
|
+
?? `rule-source-correction:${receipt.candidateId}:${receipt.bindingRevision}`;
|
|
620
|
+
const { artificerTaskId } = receipt;
|
|
621
|
+
const artificerTask = await this.stateManager.getTask(artificerTaskId);
|
|
622
|
+
if (!artificerTask) {
|
|
623
|
+
return { decision: 'source_correction_reopen_failed', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'artificer_task_missing' };
|
|
624
|
+
}
|
|
625
|
+
const artificerPi = hydratePITaskRecord(artificerTask);
|
|
626
|
+
if (!artificerPi) {
|
|
627
|
+
return { decision: 'source_correction_reopen_conflict', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'artificer_metadata_invalid' };
|
|
628
|
+
}
|
|
629
|
+
if (hasConsumedRevisionCause(artificerPi, causeId)) {
|
|
630
|
+
return { decision: 'source_correction_reopen_noop', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'source_correction_cause_already_materialized' };
|
|
631
|
+
}
|
|
632
|
+
if (artificerTask.status === 'pending' || artificerTask.status === 'retry_wait') {
|
|
633
|
+
return { decision: 'source_correction_reopen_noop', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: `artificer_in_flight_${artificerTask.status}` };
|
|
634
|
+
}
|
|
635
|
+
if (artificerTask.status !== 'needs_human_review') {
|
|
636
|
+
return { decision: 'source_correction_reopen_conflict', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: `artificer_status_${artificerTask.status}` };
|
|
637
|
+
}
|
|
638
|
+
const stopReasonCode = artificerPi.humanReviewContext?.reasonCode ?? '';
|
|
639
|
+
if (stopReasonCode !== receipt.expectedStopReasonCode) {
|
|
640
|
+
return {
|
|
641
|
+
decision: 'source_correction_reopen_conflict',
|
|
642
|
+
sourceTaskId: scribeTaskId,
|
|
643
|
+
reopenedTaskId: artificerTaskId,
|
|
644
|
+
reason: `stop_reason_drifted:${stopReasonCode || 'none'}!=${receipt.expectedStopReasonCode}`,
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
const lineage = await planLegacyLineageResolution(artificerTask, this.stateManager);
|
|
648
|
+
if (!lineage.ok) {
|
|
649
|
+
return {
|
|
650
|
+
decision: 'source_correction_reopen_conflict',
|
|
651
|
+
sourceTaskId: scribeTaskId,
|
|
652
|
+
reopenedTaskId: artificerTaskId,
|
|
653
|
+
reason: `lineage_refused:${lineage.reason}`,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
return {
|
|
657
|
+
decision: 'source_correction_reopened',
|
|
658
|
+
sourceTaskId: scribeTaskId,
|
|
659
|
+
reopenedTaskId: artificerTaskId,
|
|
660
|
+
reason: 'original_artificer_reopened_on_new_scribe_epoch',
|
|
661
|
+
};
|
|
662
|
+
}
|
|
412
663
|
// ── commitNextTaskProposal ──────────────────────────────────────────────
|
|
413
664
|
/**
|
|
414
665
|
* Commit a successor task proposal for a succeeded source task.
|
|
@@ -474,11 +725,33 @@ export class InternalizationOrchestrator {
|
|
|
474
725
|
runnerDecision: piTask.runnerDecision ?? 'unknown',
|
|
475
726
|
};
|
|
476
727
|
}
|
|
477
|
-
if (transition.kind === 'REOPEN_SOURCE_EVALUATOR'
|
|
728
|
+
if (transition.kind === 'REOPEN_SOURCE_EVALUATOR') {
|
|
729
|
+
if (!piTask.repairPayload) {
|
|
730
|
+
return {
|
|
731
|
+
decision: 'lineage_refused',
|
|
732
|
+
sourceTaskId: taskId,
|
|
733
|
+
reason: 'repair_role_payload_missing',
|
|
734
|
+
detail: `repair task ${taskId} carries repairTaskRole but no valid repairPayload — source evaluator NOT reopened, zero writes`,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
// PRI-1293 R7 (P1-1) + PRI-1300: Repair 完成路径的身份前置验证保持只读;
|
|
738
|
+
// 缺失亲缘字段/OD-8 repair role 的 CAS 回填延后到初始状态分类确认会
|
|
739
|
+
// 实际 reopen 之后。否则 leased / same-cause no-op 会先写 repair row,
|
|
740
|
+
// 破坏 preview/confirm 的零写 parity。
|
|
741
|
+
const repairIdentity = await verifyRepairTaskIdentity(rawTask, piTask.repairPayload.sourceEvaluatorTaskId, piTask.repairPayload.repairIteration, this.stateManager);
|
|
742
|
+
if (!repairIdentity.ok) {
|
|
743
|
+
return {
|
|
744
|
+
decision: 'lineage_refused',
|
|
745
|
+
sourceTaskId: taskId,
|
|
746
|
+
reason: repairIdentity.reason,
|
|
747
|
+
detail: `repair_identity_verification_failed:${repairIdentity.detail} — source evaluator NOT reopened, zero writes`,
|
|
748
|
+
};
|
|
749
|
+
}
|
|
478
750
|
// PRI-629 P0 (SPEC §12): epoch-aware causal identity — Owner 额外修订轮
|
|
479
751
|
// (revise_once reopen 该 artificer,其 revisionCount+1) 再次完成时,
|
|
480
752
|
// 重开来源 evaluator 必须使用新 causeId 才是真 reopen;同 epoch 重放
|
|
481
753
|
// (crash/reconciliation) 使用相同 causeId → no-op。
|
|
754
|
+
const completingRepairPayload = piTask.repairPayload;
|
|
482
755
|
const causeId = buildRepairRevisionCauseId(piTask);
|
|
483
756
|
// A/B: cause 已 materialize 的判定前移 — 目标(任意状态)的 revisionCauseId
|
|
484
757
|
// 与本 repair 的 causeId 相同,说明这轮 reopen 已发生过: 目标可能仍在
|
|
@@ -486,7 +759,7 @@ export class InternalizationOrchestrator {
|
|
|
486
759
|
// 情况重放都不得再次 reopen(后者会丢弃已完成的修订轮 verdict)。
|
|
487
760
|
const srcRaw = await this.stateManager.getTask(piTask.repairPayload.sourceEvaluatorTaskId);
|
|
488
761
|
const srcPi = srcRaw ? hydratePITaskRecord(srcRaw) : null;
|
|
489
|
-
if (srcPi && srcPi
|
|
762
|
+
if (srcPi && hasConsumedRevisionCause(srcPi, causeId)) {
|
|
490
763
|
return {
|
|
491
764
|
decision: 'revision_reopen_noop',
|
|
492
765
|
sourceTaskId: taskId,
|
|
@@ -502,36 +775,121 @@ export class InternalizationOrchestrator {
|
|
|
502
775
|
// completing repair IS the evaluator's current repair dep, or is a
|
|
503
776
|
// NEWER round of the same source evaluator.
|
|
504
777
|
if (srcPi && srcRaw) {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
778
|
+
const staleGuard = await this.resolveStaleRepairTransitionGuard({
|
|
779
|
+
sourceEvaluatorTask: srcRaw,
|
|
780
|
+
completingRepairTaskId: taskId,
|
|
781
|
+
completingRepairIteration: piTask.repairPayload.repairIteration,
|
|
782
|
+
});
|
|
783
|
+
if (staleGuard.kind === 'invalid') {
|
|
784
|
+
return {
|
|
785
|
+
decision: 'lineage_refused',
|
|
786
|
+
sourceTaskId: taskId,
|
|
787
|
+
reason: staleGuard.reason,
|
|
788
|
+
detail: `stale_repair_guard_unprovable:${staleGuard.detail} — source evaluator NOT reopened, zero writes`,
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
if (staleGuard.kind === 'superseded') {
|
|
792
|
+
return {
|
|
793
|
+
decision: 'revision_reopen_noop',
|
|
794
|
+
sourceTaskId: taskId,
|
|
795
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
796
|
+
reason: 'stale_repair_transition_superseded',
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
// 与只读 preview 使用同一初始状态分类器: missing / invalid / same-cause
|
|
801
|
+
// replay / in-flight 都是零写分支。只有确认当前快照允许 reopen 后,才
|
|
802
|
+
// 执行 repair 血缘 + OD-8 role CAS 回填;随后 reopenTaskForRevision 对
|
|
803
|
+
// 状态漂移再次裁决,仍保留并发安全。
|
|
804
|
+
const initialPlan = planRevisionReopenInitialState(srcRaw, causeId);
|
|
805
|
+
switch (initialPlan.plan) {
|
|
806
|
+
case 'task_not_found':
|
|
807
|
+
return { decision: 'revision_reopen_failed', sourceTaskId: taskId,
|
|
808
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId, reason: 'task_not_found' };
|
|
809
|
+
case 'invalid_task_metadata':
|
|
810
|
+
return { decision: 'invalid_task_metadata', taskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
811
|
+
reason: 'repair_evaluator_reopen_invalid_task_metadata' };
|
|
812
|
+
case 'idempotent_replay_same_revision':
|
|
813
|
+
return { decision: 'revision_reopen_noop', sourceTaskId: taskId,
|
|
814
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
815
|
+
reason: 'idempotent_replay_same_revision' };
|
|
816
|
+
case 'refused_in_flight':
|
|
817
|
+
return { decision: 'revision_reopen_failed', sourceTaskId: taskId,
|
|
818
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId, reason: initialPlan.reason };
|
|
819
|
+
case 'proceed':
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
const repairLineage = await validateAndBackfillRepairLineage({
|
|
823
|
+
repairTaskId: taskId,
|
|
824
|
+
existing: rawTask,
|
|
825
|
+
sourceEvaluatorTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
826
|
+
repairIteration: piTask.repairPayload.repairIteration,
|
|
827
|
+
}, this.stateManager);
|
|
828
|
+
if (!repairLineage.ok) {
|
|
829
|
+
if (repairLineage.reason === 'concurrent_modification') {
|
|
830
|
+
return {
|
|
831
|
+
decision: 'concurrent_modification',
|
|
832
|
+
sourceTaskId: taskId,
|
|
833
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
834
|
+
detail: `repair_identity_backfill_cas_conflict:${taskId} — evaluator NOT reopened, safe to retry`,
|
|
835
|
+
};
|
|
524
836
|
}
|
|
837
|
+
return {
|
|
838
|
+
decision: 'lineage_refused',
|
|
839
|
+
sourceTaskId: taskId,
|
|
840
|
+
reason: repairLineage.reason,
|
|
841
|
+
detail: `repair_identity_verification_failed:${repairLineage.detail} — source evaluator NOT reopened, zero writes`,
|
|
842
|
+
};
|
|
525
843
|
}
|
|
526
844
|
const reopened = await this.reopenTaskForRevision(piTask.repairPayload.sourceEvaluatorTaskId, {
|
|
527
845
|
replaceArtificerDependencyWith: taskId,
|
|
528
846
|
reason: 'artificer_repair_complete',
|
|
529
847
|
revisionCauseId: causeId,
|
|
848
|
+
validateTargetSnapshot: async ({ rawTask: targetSnapshot }) => {
|
|
849
|
+
const writeCriticalGuard = await this.resolveStaleRepairTransitionGuard({
|
|
850
|
+
sourceEvaluatorTask: targetSnapshot,
|
|
851
|
+
completingRepairTaskId: taskId,
|
|
852
|
+
completingRepairIteration: completingRepairPayload.repairIteration,
|
|
853
|
+
});
|
|
854
|
+
if (writeCriticalGuard.kind === 'invalid') {
|
|
855
|
+
return {
|
|
856
|
+
ok: false,
|
|
857
|
+
reason: `lineage_refused:${writeCriticalGuard.reason}`,
|
|
858
|
+
detail: `stale_repair_guard_unprovable_at_write:${writeCriticalGuard.detail} — source evaluator NOT reopened, zero writes`,
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
if (writeCriticalGuard.kind === 'superseded') {
|
|
862
|
+
return { ok: false, reason: 'stale_repair_transition_superseded' };
|
|
863
|
+
}
|
|
864
|
+
return { ok: true };
|
|
865
|
+
},
|
|
530
866
|
});
|
|
531
867
|
if (!reopened.ok) {
|
|
532
|
-
//
|
|
533
|
-
|
|
534
|
-
|
|
868
|
+
// Repair 已成功但来源 Evaluator reopen 失败不是正常终点;保留真实拒绝类别。
|
|
869
|
+
if (reopened.reason === 'stale_repair_transition_superseded') {
|
|
870
|
+
return {
|
|
871
|
+
decision: 'revision_reopen_noop',
|
|
872
|
+
sourceTaskId: taskId,
|
|
873
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
874
|
+
reason: 'stale_repair_transition_superseded',
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
if (reopened.reason.startsWith('lineage_refused:')) {
|
|
878
|
+
return { decision: 'lineage_refused', sourceTaskId: taskId,
|
|
879
|
+
reason: reopened.reason.slice('lineage_refused:'.length), detail: reopened.detail ?? reopened.reason };
|
|
880
|
+
}
|
|
881
|
+
if (reopened.reason === 'concurrent_modification') {
|
|
882
|
+
return { decision: 'concurrent_modification', sourceTaskId: taskId,
|
|
883
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
884
|
+
detail: reopened.detail ?? 'repair_evaluator_reopen_cas_conflict:' + piTask.repairPayload.sourceEvaluatorTaskId };
|
|
885
|
+
}
|
|
886
|
+
if (reopened.reason === 'invalid_task_metadata') {
|
|
887
|
+
return { decision: 'invalid_task_metadata', taskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
888
|
+
reason: 'repair_evaluator_reopen_invalid_task_metadata' };
|
|
889
|
+
}
|
|
890
|
+
return { decision: 'revision_reopen_failed', sourceTaskId: taskId,
|
|
891
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId, reason: reopened.reason,
|
|
892
|
+
...(reopened.detail !== undefined ? { detail: reopened.detail } : {}) };
|
|
535
893
|
}
|
|
536
894
|
// A (crash window): 同 causeId 重放 = 真 no-op — 单独 decision 使
|
|
537
895
|
// reconciliation 不把它计为"恢复" (already materialized)。
|
|
@@ -584,20 +942,39 @@ export class InternalizationOrchestrator {
|
|
|
584
942
|
}
|
|
585
943
|
return this.reopenArtificerForSourceCorrection(taskId, piTask);
|
|
586
944
|
}
|
|
945
|
+
// ── PRI-1293 Phase 3: PeerRunnerKind 血缘门禁 (ADVANCE 路径唯一写前关口) ──
|
|
946
|
+
// 严格作用域: 仅 PeerRunnerKind 源任务。DiagnosticianStageKind 子任务
|
|
947
|
+
// 继续走 proposeNextTask 的 getDiagSuccessors 分支 (parentTaskId +
|
|
948
|
+
// dependencyTaskIds 语义), 绝不套用 correlationId 门禁。
|
|
949
|
+
// 校验发生在任何后继创建之前: 拒绝 = 零 createTask、零状态写入、零
|
|
950
|
+
// reopen; 结构化 lineage_refused 让 host 层 (consumer cycle / run-once /
|
|
951
|
+
// enqueue-successors / reconciliation) 可观测, 不折叠成 no_successor。
|
|
952
|
+
// 校验同时负责历史无 id 链的根侧恢复 — 成功结果 (含 recoveredFromLegacyRoot)
|
|
953
|
+
// 写入新后继 metadata.correlationId; 后继 taskId 派生保持原样 (proposal.
|
|
954
|
+
// correlationId ?? stripTrailingChannel), 不漂移在途历史链的确定性去重。
|
|
955
|
+
// PRI-1299 review: first prove the lineage with the read-only planner.
|
|
956
|
+
// The writing backfill must not run before the successor integrity gate:
|
|
957
|
+
// otherwise a confirm that ends in successor_integrity_conflict would still
|
|
958
|
+
// have mutated historical parent edges. If the planner refuses, preserve the
|
|
959
|
+
// existing lineage_refused precedence with zero writes.
|
|
960
|
+
let authoritativeLineagePlan = null;
|
|
961
|
+
if (isPeerRunnerKind(piTask.taskKind)) {
|
|
962
|
+
const lineagePlan = await planLegacyLineageResolution(rawTask, this.stateManager);
|
|
963
|
+
if (!lineagePlan.ok) {
|
|
964
|
+
return {
|
|
965
|
+
decision: 'lineage_refused',
|
|
966
|
+
sourceTaskId: taskId,
|
|
967
|
+
reason: lineagePlan.reason,
|
|
968
|
+
detail: lineagePlan.detail,
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
authoritativeLineagePlan = lineagePlan;
|
|
972
|
+
}
|
|
587
973
|
const proposalResult = await this.proposeNextTask(taskId);
|
|
588
974
|
if (!proposalResult) {
|
|
589
975
|
return { decision: 'no_successor', sourceTaskId: taskId, reason: 'No valid successor in job graph for this task kind and channel' };
|
|
590
976
|
}
|
|
591
977
|
const { proposal } = proposalResult;
|
|
592
|
-
const existingSuccessor = await this.findExistingSuccessor(taskId, proposal.taskKind, proposal.channel);
|
|
593
|
-
if (existingSuccessor) {
|
|
594
|
-
return {
|
|
595
|
-
decision: 'successor_exists',
|
|
596
|
-
sourceTaskId: taskId,
|
|
597
|
-
successorTaskId: existingSuccessor.taskId,
|
|
598
|
-
successorKind: proposal.taskKind,
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
978
|
// Successor taskId must be STABLE across the whole peer-runner chain so that
|
|
602
979
|
// every layer (dreamer/philosopher/scribe/artificer/evaluator) derives its id
|
|
603
980
|
// from the SAME root, not from the predecessor's full id (which already
|
|
@@ -614,35 +991,86 @@ export class InternalizationOrchestrator {
|
|
|
614
991
|
// Fallback: when correlationId is absent (diagnostician chain seeds it as
|
|
615
992
|
// undefined), use the source taskId but strip a trailing `-<channel>` so we
|
|
616
993
|
// don't re-append the channel we are about to add back.
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
// ends with a literal "-undefined". (No current code path reaches here
|
|
621
|
-
// with channel=undefined — the diagnostician chain terminates at
|
|
622
|
-
// diag_router which has no successor — but this keeps the invariant
|
|
623
|
-
// defensive rather than relying on that fact staying true.)
|
|
624
|
-
const successorTaskId = proposal.channel
|
|
625
|
-
? `${proposal.taskKind}-${successorRoot}-${proposal.channel}`
|
|
626
|
-
: `${proposal.taskKind}-${successorRoot}`;
|
|
994
|
+
// PRI-1293 R5: 派生经共享单一来源 (internalization-state-machine) —
|
|
995
|
+
// dry-run 预览消费同一函数, 两条路径不再有各自的派生实现。
|
|
996
|
+
const successorTaskId = deriveSuccessorTaskId(proposal, taskId);
|
|
627
997
|
// ── 级联 reopen (revision wave) ──
|
|
628
998
|
// 稳定 id 后继已存在且为 succeeded: 仅当源任务经历过 revision
|
|
629
999
|
// (revisionCount > 0, 即上游被 reopen 后重新完成)时, 下游才必须重跑
|
|
630
1000
|
// (而非 successor_exists 停摆)。普通幂等重扫 (revisionCount=0) 不级联,
|
|
631
1001
|
// 保持既有 successor_exists 语义。pending/retry_wait 的存在后继仍走
|
|
632
1002
|
// findExistingSuccessor 的 successor_exists 分支。
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
1003
|
+
// ── 统一后继识别 (PRI-1293 review round 3) ──
|
|
1004
|
+
// 后继身份是 (parentTaskId, successorKind, channel) 父子关系, 不是派生 id:
|
|
1005
|
+
// - 修订重开把恢复的 correlationId 回填进源任务, 派生根漂移 (R2);
|
|
1006
|
+
// - RuleHost 同步链持久化时间戳 id, 确定性派生永不复现 (R3)。
|
|
1007
|
+
// 因此直查与父子扫描都不再受 revisionCount 门限制 — 此前 rc=0 仅靠
|
|
1008
|
+
// createTask 的 UNIQUE 撞约束兜底, 对时间戳链等于毫无保护: dry-run
|
|
1009
|
+
// (全状态索引) 能看到的终态后继, confirm 却再创建一条逻辑相同的链。
|
|
1010
|
+
// 现在任何状态的已存在后继 (在途/终态/failed) 都先命中 successor_exists;
|
|
1011
|
+
// 仅当命中可重开终态且源经历过 revision (rc>0) 时才进入级联重开。
|
|
1012
|
+
// PRI-1293 R5 (跨链派生 id 碰撞): 父子扫描是唯一权威, 直查快路径废除——
|
|
1013
|
+
// 旧实现在确定性 id 命中时跳过扫描, 且不校验 occupant 的 parentTaskId:
|
|
1014
|
+
// 候选身份经修订回填进**另一条链** (如 RuleHost 时间戳链) 后, 其派生 id
|
|
1015
|
+
// 与本队列链相同, 直查命中异链任务, 级联重开错链的后继并替换其依赖。
|
|
1016
|
+
// 扫描按 (parentTaskId, kind, channel) 匹配, 异链 occupant 自然不命中;
|
|
1017
|
+
// id 占用冲突在创建路径处理 (fallback 父派生 id + UNIQUE 竞态重扫)。
|
|
1018
|
+
const successorLookup = await this.findSuccessorByParent(taskId, proposal.taskKind, proposal.channel);
|
|
1019
|
+
if (successorLookup.outcome === 'conflict') {
|
|
1020
|
+
return { decision: successorLookup.decision, sourceTaskId: taskId,
|
|
1021
|
+
reason: successorLookup.reason,
|
|
1022
|
+
detail: successorLookup.detail,
|
|
1023
|
+
conflictingSuccessorTaskIds: [...successorLookup.conflictingSuccessorTaskIds] };
|
|
1024
|
+
}
|
|
1025
|
+
if (successorLookup.outcome === 'malformed') {
|
|
1026
|
+
return {
|
|
1027
|
+
decision: successorLookup.decision,
|
|
1028
|
+
sourceTaskId: taskId,
|
|
1029
|
+
reason: successorLookup.reason,
|
|
1030
|
+
detail: successorLookup.detail,
|
|
1031
|
+
malformedCandidateTaskIds: [...successorLookup.malformedCandidateTaskIds],
|
|
1032
|
+
nextAction: successorLookup.nextAction,
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
// The conflict gate above is now the first write-sensitive decision. Only
|
|
1036
|
+
// after it passes may the legacy lineage resolver persist proven parent edges.
|
|
1037
|
+
// This keeps successor_integrity_conflict truly zero-write while preserving
|
|
1038
|
+
// the pre-existing backfill behavior for paths that can proceed.
|
|
1039
|
+
if (isPeerRunnerKind(piTask.taskKind) && successorLookup.outcome === 'unique') {
|
|
1040
|
+
const lineage = await resolveAuthoritativeCorrelationIdWithLegacyBackfill(rawTask, this.stateManager);
|
|
1041
|
+
if (!lineage.ok) {
|
|
1042
|
+
return {
|
|
1043
|
+
decision: 'lineage_refused',
|
|
1044
|
+
sourceTaskId: taskId,
|
|
1045
|
+
reason: lineage.reason,
|
|
1046
|
+
detail: lineage.detail,
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
const existingSuccessorCandidate = successorLookup.outcome === 'unique' ? successorLookup.successor : null;
|
|
1051
|
+
// PRI-1293 R5: 级联判定经共享只读 planner (revision-reopen.ts) — commit
|
|
1052
|
+
// 与 dry-run 预览消费同一判定, 预览不再把"将重开"误报为 successor_exists。
|
|
1053
|
+
const scannedSuccPi = existingSuccessorCandidate !== null ? hydratePITaskRecord(existingSuccessorCandidate) : null;
|
|
1054
|
+
const successorTransitionPlan = existingSuccessorCandidate !== null
|
|
1055
|
+
? planExistingSuccessorTransition({
|
|
1056
|
+
sourceTaskId: taskId,
|
|
1057
|
+
sourceRevisionCount: piTask.revisionCount ?? 0,
|
|
1058
|
+
successorTaskId: existingSuccessorCandidate.taskId,
|
|
1059
|
+
successorStatus: existingSuccessorCandidate.status,
|
|
1060
|
+
successorRevisionCauseId: scannedSuccPi?.revisionCauseId,
|
|
1061
|
+
successorConsumedRevisionCauseIds: scannedSuccPi?.consumedRevisionCauseIds,
|
|
1062
|
+
})
|
|
1063
|
+
: { plan: 'exists_plain' };
|
|
1064
|
+
if (existingSuccessorCandidate !== null && successorTransitionPlan.plan !== 'exists_plain') {
|
|
1065
|
+
const cascadeTargetTaskId = existingSuccessorCandidate.taskId;
|
|
1066
|
+
const { cascadeCauseId } = successorTransitionPlan;
|
|
638
1067
|
// B: 对称的 cause 前置 — 该 wave 的 cascade reopen 已 materialize
|
|
639
1068
|
// (successor 可能 pending 或已重跑完成),重放不得再 reopen。
|
|
640
|
-
|
|
641
|
-
if (succPi && succPi.revisionCauseId === cascadeCauseId) {
|
|
1069
|
+
if (successorTransitionPlan.plan === 'cascade_already_materialized') {
|
|
642
1070
|
return {
|
|
643
1071
|
decision: 'revision_reopen_noop',
|
|
644
1072
|
sourceTaskId: taskId,
|
|
645
|
-
reopenedTaskId:
|
|
1073
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
646
1074
|
reason: 'revision_cause_already_materialized',
|
|
647
1075
|
};
|
|
648
1076
|
}
|
|
@@ -655,8 +1083,8 @@ export class InternalizationOrchestrator {
|
|
|
655
1083
|
// 的 replaceArtificerDependencyWith 过滤同源——不用 id 前缀约定) 不是
|
|
656
1084
|
// 刚完成的 taskId 时,镜像 REOPEN_SOURCE_EVALUATOR 的换依赖语义。
|
|
657
1085
|
let cascadeReplaceArtificerDependencyWith;
|
|
658
|
-
if (
|
|
659
|
-
for (const depId of
|
|
1086
|
+
if (scannedSuccPi && proposal.taskKind === 'evaluator') {
|
|
1087
|
+
for (const depId of scannedSuccPi.dependencyTaskIds) {
|
|
660
1088
|
if (depId === taskId)
|
|
661
1089
|
continue;
|
|
662
1090
|
const dep = await this.stateManager.getTask(depId);
|
|
@@ -666,7 +1094,7 @@ export class InternalizationOrchestrator {
|
|
|
666
1094
|
}
|
|
667
1095
|
}
|
|
668
1096
|
}
|
|
669
|
-
const reopened = await this.reopenTaskForRevision(
|
|
1097
|
+
const reopened = await this.reopenTaskForRevision(cascadeTargetTaskId, {
|
|
670
1098
|
reason: 'upstream_revision_cascade',
|
|
671
1099
|
// B (外部复核): causal idempotency — 同一 upstream revision wave 的
|
|
672
1100
|
// reconciliation/commit 重放不得再次 reopen 或递增 revisionCount。
|
|
@@ -680,77 +1108,193 @@ export class InternalizationOrchestrator {
|
|
|
680
1108
|
return {
|
|
681
1109
|
decision: 'revision_reopen_noop',
|
|
682
1110
|
sourceTaskId: taskId,
|
|
683
|
-
reopenedTaskId:
|
|
1111
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
684
1112
|
reason: reopened.reason,
|
|
685
1113
|
};
|
|
686
1114
|
}
|
|
687
1115
|
return {
|
|
688
1116
|
decision: 'successor_reopened',
|
|
689
1117
|
sourceTaskId: taskId,
|
|
690
|
-
reopenedTaskId:
|
|
1118
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
691
1119
|
successorKind: proposal.taskKind,
|
|
692
1120
|
};
|
|
693
1121
|
}
|
|
1122
|
+
// 级联重开被拒绝不折叠为 successor_exists — 修订波未能向下游传播,
|
|
1123
|
+
// 链停在旧 epoch; 结构化透出真实拒绝原因 (rc-9), 让 consumer cycle /
|
|
1124
|
+
// run-once / enqueue-successors 可观测, 而非呈现为正常幂等态。
|
|
1125
|
+
if (reopened.reason.startsWith('lineage_refused:')) {
|
|
1126
|
+
return {
|
|
1127
|
+
decision: 'lineage_refused',
|
|
1128
|
+
sourceTaskId: taskId,
|
|
1129
|
+
reason: reopened.reason.slice('lineage_refused:'.length),
|
|
1130
|
+
detail: `cascade_reopen_refused:${cascadeTargetTaskId}${reopened.detail !== undefined ? `:${reopened.detail}` : ''}`,
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
if (reopened.reason === 'invalid_task_metadata') {
|
|
1134
|
+
return {
|
|
1135
|
+
decision: 'invalid_task_metadata',
|
|
1136
|
+
taskId: cascadeTargetTaskId,
|
|
1137
|
+
reason: `cascade_reopen_invalid_task_metadata: successor of ${taskId}`,
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
// PRI-1293 review round 3: CAS 并发落败是独立的结构化结果 — 级联未能
|
|
1141
|
+
// 传播修订波, 链停在旧 epoch, 绝不折叠为 successor_exists (那会把未
|
|
1142
|
+
// 完成的级联伪装成正常幂等态)。reopen 内部已在 CAS 落败后重读: 同一
|
|
1143
|
+
// revisionCauseId 已 materialize 的重放在上面按 idempotent no-op 返回,
|
|
1144
|
+
// 到达这里 = 真实的并发冲突, 可安全重试 (reopen 幂等)。
|
|
1145
|
+
if (reopened.reason === 'concurrent_modification') {
|
|
1146
|
+
return {
|
|
1147
|
+
decision: 'concurrent_modification',
|
|
1148
|
+
sourceTaskId: taskId,
|
|
1149
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
1150
|
+
detail: reopened.detail ?? `cascade_cas_conflict:${cascadeTargetTaskId}`,
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
694
1153
|
return {
|
|
695
1154
|
decision: 'successor_exists',
|
|
696
1155
|
sourceTaskId: taskId,
|
|
697
|
-
successorTaskId,
|
|
1156
|
+
successorTaskId: cascadeTargetTaskId,
|
|
698
1157
|
successorKind: proposal.taskKind,
|
|
699
1158
|
};
|
|
700
1159
|
}
|
|
701
|
-
if (
|
|
702
|
-
//
|
|
1160
|
+
if (existingSuccessorCandidate) {
|
|
1161
|
+
// 统一识别的剩余命中: rc=0 的终态后继 (幂等重扫不级联 — 保留原任务
|
|
1162
|
+
// id, 零创建零重复执行), 以及 leased/retry_wait/pending/failed 在途
|
|
1163
|
+
// 或待重试后继 — 与任务状态机语义一致, 不重复处理。
|
|
703
1164
|
return {
|
|
704
1165
|
decision: 'successor_exists',
|
|
705
1166
|
sourceTaskId: taskId,
|
|
706
|
-
successorTaskId,
|
|
1167
|
+
successorTaskId: existingSuccessorCandidate.taskId,
|
|
707
1168
|
successorKind: proposal.taskKind,
|
|
708
1169
|
};
|
|
709
1170
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
1171
|
+
// PRI-1293 review fix: 创建前校验"再加一条边是否越限"。resolver 只校验
|
|
1172
|
+
// 源任务自身链 (读取侧 — 深度 10 的在途任务保持可读), 但深度 10 的源
|
|
1173
|
+
// 若创建后继, 新任务即刻成为第 11 条边, 之后它自身的每次 commit/reopen
|
|
1174
|
+
// 都被同一 resolver 拒绝 — 产出"已创建但永远无法推进"的任务。因此在
|
|
1175
|
+
// 持久化前 fail-closed: 源深度 9 → 后继 10 放行; 源深度 10 → 结构化拒绝,
|
|
1176
|
+
// 零 createTask 零写入。注意此检查只在创建路径 — 上方在途/终态后继的
|
|
1177
|
+
// successor_exists 与级联 reopen 不受影响 (reopen 有自身的血缘校验)。
|
|
1178
|
+
//
|
|
1179
|
+
// PRI-1299 round 8: successor lookup 的非事务预检不能保护后续写入。
|
|
1180
|
+
// 创建路径把 transaction-time lineage plan、最终 successor 仲裁、successor
|
|
1181
|
+
// insert 和 legacy parent-edge backfill 放进同一个写事务。conflict/malformed/
|
|
1182
|
+
// id_conflict 在任何 backfill 前返回;backfill 失败则抛出私有 sentinel,
|
|
1183
|
+
// 让 SQLite rollback 已创建 successor 和部分回填,再在事务外翻译回结构化结果。
|
|
721
1184
|
try {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
1185
|
+
return await this.stateManager.withWriteTransaction(async () => {
|
|
1186
|
+
let creationLineagePlan = authoritativeLineagePlan;
|
|
1187
|
+
if (isPeerRunnerKind(piTask.taskKind)) {
|
|
1188
|
+
const transactionPlan = await planLegacyLineageResolution(rawTask, this.stateManager);
|
|
1189
|
+
if (!transactionPlan.ok) {
|
|
1190
|
+
throw new CommitDecisionRollback({
|
|
1191
|
+
decision: 'lineage_refused',
|
|
1192
|
+
sourceTaskId: taskId,
|
|
1193
|
+
reason: transactionPlan.reason,
|
|
1194
|
+
detail: transactionPlan.detail,
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
creationLineagePlan = transactionPlan;
|
|
1198
|
+
}
|
|
1199
|
+
if (creationLineagePlan !== null
|
|
1200
|
+
&& creationLineagePlan.parentEdgeCount + 1 > CORRELATION_LINEAGE_MAX_PARENT_EDGES) {
|
|
1201
|
+
throw new CommitDecisionRollback({
|
|
1202
|
+
decision: 'lineage_refused',
|
|
1203
|
+
sourceTaskId: taskId,
|
|
1204
|
+
reason: 'parent_chain_cycle_or_depth_exceeded',
|
|
1205
|
+
detail: 'successor_would_exceed_depth_limit:' + (creationLineagePlan.parentEdgeCount + 1) + '_edges_max_' + CORRELATION_LINEAGE_MAX_PARENT_EDGES,
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
const successorMetadata = {
|
|
1209
|
+
dependencyTaskIds: proposal.dependencyTaskIds,
|
|
1210
|
+
channel: proposal.channel,
|
|
1211
|
+
pipelineMode: proposal.pipelineMode,
|
|
1212
|
+
timeoutMs: 300_000,
|
|
1213
|
+
inputArtifactRefs: proposal.inputArtifactRefs,
|
|
1214
|
+
outputArtifactRefs: [],
|
|
1215
|
+
parentTaskId: proposal.parentTaskId,
|
|
1216
|
+
// PRI-1293 Phase 3: 写入的是经过权威校验/恢复的 correlationId —
|
|
1217
|
+
// 历史无 id 链在此补入根侧恢复值 (§3.6.3 历史恢复), 正常链上与
|
|
1218
|
+
// proposal.correlationId 相同 (校验保证链内一致 + 根佐证)。
|
|
1219
|
+
correlationId: creationLineagePlan?.correlationId ?? proposal.correlationId,
|
|
1220
|
+
};
|
|
1221
|
+
// PRI-1293 R5: 创建是 bounded 收敛循环 (至多 2 次)。
|
|
1222
|
+
// attempt 0 用主派生 id; UNIQUE 落败先重扫——并发创建者若已物化真实
|
|
1223
|
+
// 后继 (同 parent/kind/channel) 按 successor_exists 收敛, 绝不重复创建;
|
|
1224
|
+
// 重扫为空 = occupant 属异链 (扫描为空已证明它非本父子后继), attempt 1
|
|
1225
|
+
// 改用父派生 fallback id。fallback id 对同一 (parent, kind, channel)
|
|
1226
|
+
// 确定性收敛: 两个并发创建者碰壁后落到**同一** fallback id, 胜负由
|
|
1227
|
+
// UNIQUE 裁决, 败者重扫收敛——不会双链并行。fallback 仍 UNIQUE 落败
|
|
1228
|
+
// 且重扫为空 = 持续占用冲突, fail-closed 结构化 successor_id_conflict
|
|
1229
|
+
// (绝不折叠为 successor_exists 伪装幂等)。
|
|
1230
|
+
const creation = await createLogicalSuccessorTask({
|
|
1231
|
+
stateManager: this.stateManager,
|
|
1232
|
+
parentTaskId: taskId,
|
|
1233
|
+
successorKind: proposal.taskKind,
|
|
1234
|
+
channel: proposal.channel,
|
|
1235
|
+
preferredTaskId: successorTaskId,
|
|
1236
|
+
fallbackTaskId: successorTaskId + '-p-' + taskId,
|
|
1237
|
+
metadata: successorMetadata,
|
|
1238
|
+
});
|
|
1239
|
+
if (creation.outcome === 'lookup') {
|
|
1240
|
+
if (creation.lookup.outcome === 'malformed') {
|
|
1241
|
+
return {
|
|
1242
|
+
decision: creation.lookup.decision,
|
|
1243
|
+
sourceTaskId: taskId,
|
|
1244
|
+
reason: creation.lookup.reason,
|
|
1245
|
+
detail: creation.lookup.detail,
|
|
1246
|
+
malformedCandidateTaskIds: [...creation.lookup.malformedCandidateTaskIds],
|
|
1247
|
+
nextAction: creation.lookup.nextAction,
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
return {
|
|
1251
|
+
decision: creation.lookup.decision,
|
|
1252
|
+
sourceTaskId: taskId,
|
|
1253
|
+
reason: creation.lookup.reason,
|
|
1254
|
+
detail: creation.lookup.detail,
|
|
1255
|
+
conflictingSuccessorTaskIds: [...creation.lookup.conflictingSuccessorTaskIds],
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
if (creation.outcome === 'id_conflict') {
|
|
1259
|
+
return {
|
|
1260
|
+
decision: 'successor_id_conflict',
|
|
1261
|
+
sourceTaskId: taskId,
|
|
1262
|
+
reason: creation.allocation.reason,
|
|
1263
|
+
detail: creation.allocation.detail,
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
if (isPeerRunnerKind(piTask.taskKind)) {
|
|
1267
|
+
const lineage = await resolveAuthoritativeCorrelationIdWithLegacyBackfill(rawTask, this.stateManager, creationLineagePlan ?? undefined);
|
|
1268
|
+
if (!lineage.ok) {
|
|
1269
|
+
throw new CommitDecisionRollback({
|
|
1270
|
+
decision: 'lineage_refused',
|
|
1271
|
+
sourceTaskId: taskId,
|
|
1272
|
+
reason: lineage.reason,
|
|
1273
|
+
detail: lineage.detail,
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
if (creation.outcome === 'existing') {
|
|
1278
|
+
return {
|
|
1279
|
+
decision: 'successor_exists',
|
|
1280
|
+
sourceTaskId: taskId,
|
|
1281
|
+
successorTaskId: creation.task.taskId,
|
|
1282
|
+
successorKind: proposal.taskKind,
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
739
1285
|
return {
|
|
740
|
-
decision: '
|
|
1286
|
+
decision: 'successor_created',
|
|
741
1287
|
sourceTaskId: taskId,
|
|
742
|
-
successorTaskId,
|
|
1288
|
+
successorTaskId: creation.task.taskId,
|
|
743
1289
|
successorKind: proposal.taskKind,
|
|
744
1290
|
};
|
|
745
|
-
}
|
|
746
|
-
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
catch (error) {
|
|
1294
|
+
if (error instanceof CommitDecisionRollback)
|
|
1295
|
+
return error.result;
|
|
1296
|
+
throw error;
|
|
747
1297
|
}
|
|
748
|
-
return {
|
|
749
|
-
decision: 'successor_created',
|
|
750
|
-
sourceTaskId: taskId,
|
|
751
|
-
successorTaskId: successorRecord.taskId,
|
|
752
|
-
successorKind: proposal.taskKind,
|
|
753
|
-
};
|
|
754
1298
|
}
|
|
755
1299
|
/**
|
|
756
1300
|
* P0-3 legacy 判据: 从该任务最近 succeeded run 的 output_payload **显式解析**
|
|
@@ -890,7 +1434,25 @@ export class InternalizationOrchestrator {
|
|
|
890
1434
|
continue;
|
|
891
1435
|
try {
|
|
892
1436
|
const result = await this.commitNextTaskProposal(task.taskId);
|
|
893
|
-
|
|
1437
|
+
// PRI-1293 R7 (P2-2): 完整结构化投影 — repair reopen 失败后 Owner 必须
|
|
1438
|
+
// 能直接从 reconciliation 结果定位原本要重开的 Evaluator (reopenedTaskId),
|
|
1439
|
+
// 不得在中间层丢失证据字段。
|
|
1440
|
+
const outcome = {
|
|
1441
|
+
taskId: task.taskId, decision: result.decision,
|
|
1442
|
+
};
|
|
1443
|
+
if ('reason' in result)
|
|
1444
|
+
outcome.reason = result.reason;
|
|
1445
|
+
if ('detail' in result && result.detail !== undefined)
|
|
1446
|
+
outcome.detail = result.detail;
|
|
1447
|
+
if ('reopenedTaskId' in result && typeof result.reopenedTaskId === 'string')
|
|
1448
|
+
outcome.reopenedTaskId = result.reopenedTaskId;
|
|
1449
|
+
if ('successorTaskId' in result && typeof result.successorTaskId === 'string')
|
|
1450
|
+
outcome.successorTaskId = result.successorTaskId;
|
|
1451
|
+
if ('successorKind' in result && typeof result.successorKind === 'string')
|
|
1452
|
+
outcome.successorKind = result.successorKind;
|
|
1453
|
+
if ('conflictingSuccessorTaskIds' in result)
|
|
1454
|
+
outcome.conflictingSuccessorTaskIds = [...result.conflictingSuccessorTaskIds];
|
|
1455
|
+
outcomes.push(outcome);
|
|
894
1456
|
if (result.decision === 'successor_created' || result.decision === 'revision_reopened' || result.decision === 'successor_reopened'
|
|
895
1457
|
|| result.decision === 'source_correction_reopened') {
|
|
896
1458
|
recovered += 1;
|
|
@@ -989,7 +1551,7 @@ export class InternalizationOrchestrator {
|
|
|
989
1551
|
return { decision: 'source_correction_reopen_conflict', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'artificer_metadata_invalid' };
|
|
990
1552
|
}
|
|
991
1553
|
// 崩溃重放:Artificer 已带本 cause(上次续接已 materialize)→ 幂等 no-op。
|
|
992
|
-
if (artificerPi
|
|
1554
|
+
if (hasConsumedRevisionCause(artificerPi, causeId)) {
|
|
993
1555
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'reopened_earlier', recordedAt: new Date().toISOString() });
|
|
994
1556
|
return { decision: 'source_correction_reopen_noop', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'source_correction_cause_already_materialized' };
|
|
995
1557
|
}
|
|
@@ -1010,11 +1572,32 @@ export class InternalizationOrchestrator {
|
|
|
1010
1572
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'conflict', recordedAt: new Date().toISOString(), detail });
|
|
1011
1573
|
return { decision: 'source_correction_reopen_conflict', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: detail };
|
|
1012
1574
|
}
|
|
1575
|
+
// PRI-1293 Phase 3: 定点续接是生产 reopen 路径 — 与 commit/reopen 核心
|
|
1576
|
+
// 共享同一血缘权威。守卫通过后、CAS 写之前校验; 拒绝 = conflict 终态
|
|
1577
|
+
// 可观测 (receipt outcome 落库), 零写入。
|
|
1578
|
+
const artificerLineage = await resolveAuthoritativeCorrelationIdWithLegacyBackfill(artificerTask, this.stateManager);
|
|
1579
|
+
if (!artificerLineage.ok) {
|
|
1580
|
+
await this.recordSourceCorrectionOutcome(scribeTaskId, {
|
|
1581
|
+
kind: 'conflict',
|
|
1582
|
+
recordedAt: new Date().toISOString(),
|
|
1583
|
+
detail: `lineage_refused:${artificerLineage.reason}`,
|
|
1584
|
+
});
|
|
1585
|
+
return {
|
|
1586
|
+
decision: 'source_correction_reopen_conflict',
|
|
1587
|
+
sourceTaskId: scribeTaskId,
|
|
1588
|
+
reopenedTaskId: artificerTaskId,
|
|
1589
|
+
reason: `lineage_refused:${artificerLineage.reason}`,
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1013
1592
|
const merged = mergePITaskMetadata(artificerPi, {
|
|
1014
1593
|
runnerDecision: undefined,
|
|
1015
1594
|
completionIntent: undefined,
|
|
1016
1595
|
revisionCount: (artificerPi.revisionCount ?? 0) + 1,
|
|
1017
1596
|
revisionCauseId: causeId,
|
|
1597
|
+
// §5.3.7: 可恢复历史链在续接写中补入已验证的 correlationId。
|
|
1598
|
+
...(artificerLineage.correlationId !== (artificerPi.correlationId?.trim() ?? '')
|
|
1599
|
+
? { correlationId: artificerLineage.correlationId }
|
|
1600
|
+
: {}),
|
|
1018
1601
|
});
|
|
1019
1602
|
const updated = await this.stateManager.updateTaskIfDiagnosticJsonUnchanged(artificerTaskId, artificerTask.diagnosticJson ?? null, {
|
|
1020
1603
|
diagnosticJson: createPITaskDiagnosticJson(merged),
|
|
@@ -1027,6 +1610,9 @@ export class InternalizationOrchestrator {
|
|
|
1027
1610
|
expectedMaxAttempts: artificerTask.maxAttempts,
|
|
1028
1611
|
expectedLeaseOwner: artificerTask.leaseOwner ?? null,
|
|
1029
1612
|
expectedLeaseExpiresAt: artificerTask.leaseExpiresAt ?? null,
|
|
1613
|
+
// PRI-1293 R7 (P2-3): leaseOwner/leaseExpiresAt 相同的重租场景只有
|
|
1614
|
+
// leaseGeneration 单调递增可区分 — 缺失此前提则旧 CAS 会覆盖新租约。
|
|
1615
|
+
expectedLeaseGeneration: artificerTask.leaseGeneration ?? 0,
|
|
1030
1616
|
});
|
|
1031
1617
|
if (updated) {
|
|
1032
1618
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'reopened', recordedAt: new Date().toISOString() });
|
|
@@ -1037,7 +1623,7 @@ export class InternalizationOrchestrator {
|
|
|
1037
1623
|
// 真实漂移被守卫重新分类,不再误记终态 conflict。
|
|
1038
1624
|
const current = await this.stateManager.getTask(artificerTaskId);
|
|
1039
1625
|
const currentPi = current ? hydratePITaskRecord(current) : null;
|
|
1040
|
-
if (currentPi && currentPi
|
|
1626
|
+
if (currentPi && hasConsumedRevisionCause(currentPi, causeId)) {
|
|
1041
1627
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'reopened_earlier', recordedAt: new Date().toISOString() });
|
|
1042
1628
|
return { decision: 'source_correction_reopen_noop', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'concurrent_writer_materialized_same_cause' };
|
|
1043
1629
|
}
|
|
@@ -1074,25 +1660,30 @@ export class InternalizationOrchestrator {
|
|
|
1074
1660
|
}
|
|
1075
1661
|
}
|
|
1076
1662
|
/**
|
|
1077
|
-
* Find
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1663
|
+
* Find the logical successor by (parentTaskId, successorKind, channel) across
|
|
1664
|
+
* ALL task statuses — the lineage-truth counterpart of the derived-id lookup.
|
|
1665
|
+
*
|
|
1666
|
+
* Successor identity is the parentage relation, not the derived id:
|
|
1667
|
+
* - revision reopen backfills the recovered correlationId into the source,
|
|
1668
|
+
* shifting the derivation root away from the persisted id (PRI-1293 R2);
|
|
1669
|
+
* - the RuleHost synchronous chain persists timestamp-suffixed ids that the
|
|
1670
|
+
* deterministic derivation never reproduces (PRI-1293 R3).
|
|
1671
|
+
* ANY persisted row — in-flight (pending/leased/retry_wait), terminal
|
|
1672
|
+
* (succeeded/needs_human_review) or failed — proves the logical successor
|
|
1673
|
+
* already exists. This mirrors the semantics the deterministic-id UNIQUE
|
|
1674
|
+
* constraint catch used to provide as a last resort, extended to chains
|
|
1675
|
+
* whose ids are not derivable. Multiple matches are an integrity conflict;
|
|
1676
|
+
* taskId ordering is used only for deterministic reporting, never selection.
|
|
1080
1677
|
*/
|
|
1081
|
-
async
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
continue;
|
|
1091
|
-
if (piTask.parentTaskId === parentTaskId && piTask.channel === channel) {
|
|
1092
|
-
return task;
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
return null;
|
|
1678
|
+
async findSuccessorByParent(parentTaskId, successorKind, channel) {
|
|
1679
|
+
// PRI-1299: thin delegate only. Candidate narrowing is pushed into
|
|
1680
|
+
// TaskStore; zero/unique/conflict adjudication and legacy-parent inference
|
|
1681
|
+
// live in the single core successor-lookup seam shared with pd-cli.
|
|
1682
|
+
return lookupSuccessorByParent(this.stateManager, {
|
|
1683
|
+
parentTaskId,
|
|
1684
|
+
successorKind,
|
|
1685
|
+
channel,
|
|
1686
|
+
});
|
|
1096
1687
|
}
|
|
1097
1688
|
/**
|
|
1098
1689
|
* Find candidate PI tasks by querying pending and retry_wait statuses.
|