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
|
@@ -13,15 +13,16 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @see docs/adr/0003-peer-agent-state-machine-orchestration.md
|
|
15
15
|
*/
|
|
16
|
-
import { PD_TASK_STATUSES } from '../task-status.js';
|
|
17
16
|
import { deriveSuccessorTaskId } from './internalization-state-machine.js';
|
|
18
17
|
import { hydratePITaskRecord, createPITaskDiagnosticJson, mergePITaskMetadata, hasConsumedRevisionCause } from './pitask-metadata.js';
|
|
19
|
-
import { reopenTaskForRevision, buildRepairRevisionCauseId, planExistingSuccessorTransition } from './revision-reopen.js';
|
|
20
|
-
import { verifyRepairTaskIdentity } from './repair-task-identity.js';
|
|
21
|
-
import {
|
|
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';
|
|
22
23
|
// PRI-1293 Phase 3: 唯一 PeerRunnerKind 血缘权威解析器 (core 内部模块,
|
|
23
24
|
// 不入 barrel — 跨包消费方经 InternalizationOrchestrator 静态只读包装访问)。
|
|
24
|
-
import { resolveAuthoritativeCorrelationId, resolveAuthoritativeCorrelationIdWithLegacyBackfill, CORRELATION_LINEAGE_MAX_PARENT_EDGES, } from './correlation-lineage.js';
|
|
25
|
+
import { resolveAuthoritativeCorrelationId, resolveAuthoritativeCorrelationIdWithLegacyBackfill, planLegacyLineageResolution, CORRELATION_LINEAGE_MAX_PARENT_EDGES, } from './correlation-lineage.js';
|
|
25
26
|
import { isPeerRunnerKind, isDiagnosticianStageKind, isRunnerKind } from './peer-runner-contracts.js';
|
|
26
27
|
import { validateInternalizationTaskReady, createNextTaskProposal, } from './internalization-state-machine.js';
|
|
27
28
|
import { getDiagSuccessors } from './internalization-job-graph.js';
|
|
@@ -47,6 +48,14 @@ export const WAKE_ONCE_DECISIONS = [
|
|
|
47
48
|
'lease_conflict',
|
|
48
49
|
'invalid_task_metadata',
|
|
49
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
|
+
}
|
|
50
59
|
/** PRI-1047 Owner review R6 #3: source-correction 定点续接「读取→守卫→CAS」
|
|
51
60
|
* 的有界重试上限——瞬时并发写者(只改无关信息)重试而非误记终态冲突。 */
|
|
52
61
|
const SOURCE_CORRECTION_REOPEN_CAS_ATTEMPTS = 3;
|
|
@@ -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,12 +725,19 @@ export class InternalizationOrchestrator {
|
|
|
474
725
|
runnerDecision: piTask.runnerDecision ?? 'unknown',
|
|
475
726
|
};
|
|
476
727
|
}
|
|
477
|
-
if (transition.kind === 'REOPEN_SOURCE_EVALUATOR'
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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。
|
|
483
741
|
const repairIdentity = await verifyRepairTaskIdentity(rawTask, piTask.repairPayload.sourceEvaluatorTaskId, piTask.repairPayload.repairIteration, this.stateManager);
|
|
484
742
|
if (!repairIdentity.ok) {
|
|
485
743
|
return {
|
|
@@ -489,34 +747,11 @@ export class InternalizationOrchestrator {
|
|
|
489
747
|
detail: `repair_identity_verification_failed:${repairIdentity.detail} — source evaluator NOT reopened, zero writes`,
|
|
490
748
|
};
|
|
491
749
|
}
|
|
492
|
-
if (repairIdentity.needsLineageBackfill) {
|
|
493
|
-
// 历史缺失 parent/correlation — 来源已证明, 经全快照 CAS 安全补齐
|
|
494
|
-
// (不覆盖并发 lease); CAS 落败 = 并发冲突, 本轮不写 evaluator。
|
|
495
|
-
const backfillMerged = mergePITaskMetadata(piTask, {
|
|
496
|
-
parentTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
497
|
-
correlationId: repairIdentity.authoritativeCorrelationId,
|
|
498
|
-
});
|
|
499
|
-
const backfillCas = await this.stateManager.updateTaskIfDiagnosticJsonUnchanged(taskId, rawTask.diagnosticJson ?? null, { diagnosticJson: createPITaskDiagnosticJson(backfillMerged) }, {
|
|
500
|
-
expectedStatus: rawTask.status,
|
|
501
|
-
expectedAttemptCount: rawTask.attemptCount,
|
|
502
|
-
expectedMaxAttempts: rawTask.maxAttempts,
|
|
503
|
-
expectedLeaseOwner: rawTask.leaseOwner ?? null,
|
|
504
|
-
expectedLeaseExpiresAt: rawTask.leaseExpiresAt ?? null,
|
|
505
|
-
expectedLeaseGeneration: rawTask.leaseGeneration ?? 0,
|
|
506
|
-
});
|
|
507
|
-
if (backfillCas === null) {
|
|
508
|
-
return {
|
|
509
|
-
decision: 'concurrent_modification',
|
|
510
|
-
sourceTaskId: taskId,
|
|
511
|
-
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
512
|
-
detail: `repair_identity_backfill_cas_conflict:${taskId} — evaluator NOT reopened, safe to retry`,
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
750
|
// PRI-629 P0 (SPEC §12): epoch-aware causal identity — Owner 额外修订轮
|
|
517
751
|
// (revise_once reopen 该 artificer,其 revisionCount+1) 再次完成时,
|
|
518
752
|
// 重开来源 evaluator 必须使用新 causeId 才是真 reopen;同 epoch 重放
|
|
519
753
|
// (crash/reconciliation) 使用相同 causeId → no-op。
|
|
754
|
+
const completingRepairPayload = piTask.repairPayload;
|
|
520
755
|
const causeId = buildRepairRevisionCauseId(piTask);
|
|
521
756
|
// A/B: cause 已 materialize 的判定前移 — 目标(任意状态)的 revisionCauseId
|
|
522
757
|
// 与本 repair 的 causeId 相同,说明这轮 reopen 已发生过: 目标可能仍在
|
|
@@ -540,34 +775,105 @@ export class InternalizationOrchestrator {
|
|
|
540
775
|
// completing repair IS the evaluator's current repair dep, or is a
|
|
541
776
|
// NEWER round of the same source evaluator.
|
|
542
777
|
if (srcPi && srcRaw) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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
|
+
};
|
|
562
798
|
}
|
|
563
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
|
+
};
|
|
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
|
+
};
|
|
843
|
+
}
|
|
564
844
|
const reopened = await this.reopenTaskForRevision(piTask.repairPayload.sourceEvaluatorTaskId, {
|
|
565
845
|
replaceArtificerDependencyWith: taskId,
|
|
566
846
|
reason: 'artificer_repair_complete',
|
|
567
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
|
+
},
|
|
568
866
|
});
|
|
569
867
|
if (!reopened.ok) {
|
|
570
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
|
+
}
|
|
571
877
|
if (reopened.reason.startsWith('lineage_refused:')) {
|
|
572
878
|
return { decision: 'lineage_refused', sourceTaskId: taskId,
|
|
573
879
|
reason: reopened.reason.slice('lineage_refused:'.length), detail: reopened.detail ?? reopened.reason };
|
|
@@ -646,18 +952,23 @@ export class InternalizationOrchestrator {
|
|
|
646
952
|
// 校验同时负责历史无 id 链的根侧恢复 — 成功结果 (含 recoveredFromLegacyRoot)
|
|
647
953
|
// 写入新后继 metadata.correlationId; 后继 taskId 派生保持原样 (proposal.
|
|
648
954
|
// correlationId ?? stripTrailingChannel), 不漂移在途历史链的确定性去重。
|
|
649
|
-
|
|
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;
|
|
650
961
|
if (isPeerRunnerKind(piTask.taskKind)) {
|
|
651
|
-
const
|
|
652
|
-
if (!
|
|
962
|
+
const lineagePlan = await planLegacyLineageResolution(rawTask, this.stateManager);
|
|
963
|
+
if (!lineagePlan.ok) {
|
|
653
964
|
return {
|
|
654
965
|
decision: 'lineage_refused',
|
|
655
966
|
sourceTaskId: taskId,
|
|
656
|
-
reason:
|
|
657
|
-
detail:
|
|
967
|
+
reason: lineagePlan.reason,
|
|
968
|
+
detail: lineagePlan.detail,
|
|
658
969
|
};
|
|
659
970
|
}
|
|
660
|
-
|
|
971
|
+
authoritativeLineagePlan = lineagePlan;
|
|
661
972
|
}
|
|
662
973
|
const proposalResult = await this.proposeNextTask(taskId);
|
|
663
974
|
if (!proposalResult) {
|
|
@@ -704,15 +1015,39 @@ export class InternalizationOrchestrator {
|
|
|
704
1015
|
// 与本队列链相同, 直查命中异链任务, 级联重开错链的后继并替换其依赖。
|
|
705
1016
|
// 扫描按 (parentTaskId, kind, channel) 匹配, 异链 occupant 自然不命中;
|
|
706
1017
|
// id 占用冲突在创建路径处理 (fallback 父派生 id + UNIQUE 竞态重扫)。
|
|
707
|
-
const
|
|
708
|
-
if (
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
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;
|
|
716
1051
|
// PRI-1293 R5: 级联判定经共享只读 planner (revision-reopen.ts) — commit
|
|
717
1052
|
// 与 dry-run 预览消费同一判定, 预览不再把"将重开"误报为 successor_exists。
|
|
718
1053
|
const scannedSuccPi = existingSuccessorCandidate !== null ? hydratePITaskRecord(existingSuccessorCandidate) : null;
|
|
@@ -840,113 +1175,126 @@ export class InternalizationOrchestrator {
|
|
|
840
1175
|
// 持久化前 fail-closed: 源深度 9 → 后继 10 放行; 源深度 10 → 结构化拒绝,
|
|
841
1176
|
// 零 createTask 零写入。注意此检查只在创建路径 — 上方在途/终态后继的
|
|
842
1177
|
// successor_exists 与级联 reopen 不受影响 (reopen 有自身的血缘校验)。
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
correlationId: authoritativeCorrelation?.correlationId ?? proposal.correlationId,
|
|
864
|
-
};
|
|
865
|
-
// PRI-1293 R5: 创建是 bounded 收敛循环 (至多 2 次)。
|
|
866
|
-
// attempt 0 用主派生 id; UNIQUE 落败先重扫——并发创建者若已物化真实
|
|
867
|
-
// 后继 (同 parent/kind/channel) 按 successor_exists 收敛, 绝不重复创建;
|
|
868
|
-
// 重扫为空 = occupant 属异链 (扫描为空已证明它非本父子后继), attempt 1
|
|
869
|
-
// 改用父派生 fallback id。fallback id 对同一 (parent, kind, channel)
|
|
870
|
-
// 确定性收敛: 两个并发创建者碰壁后落到**同一** fallback id, 胜负由
|
|
871
|
-
// UNIQUE 裁决, 败者重扫收敛——不会双链并行。fallback 仍 UNIQUE 落败
|
|
872
|
-
// 且重扫为空 = 持续占用冲突, fail-closed 结构化 successor_id_conflict
|
|
873
|
-
// (绝不折叠为 successor_exists 伪装幂等)。
|
|
874
|
-
let successorRecord = null;
|
|
875
|
-
for (let createAttempt = 0; createAttempt < 2 && successorRecord === null; createAttempt++) {
|
|
876
|
-
const idForCreate = createAttempt === 0
|
|
877
|
-
? successorTaskId
|
|
878
|
-
: successorTaskId + '-p-' + taskId;
|
|
879
|
-
try {
|
|
880
|
-
successorRecord = await this.stateManager.createTask({
|
|
881
|
-
taskId: idForCreate,
|
|
882
|
-
taskKind: proposal.taskKind,
|
|
883
|
-
status: 'pending',
|
|
884
|
-
attemptCount: 0,
|
|
885
|
-
maxAttempts: 3,
|
|
886
|
-
inputRef: undefined,
|
|
887
|
-
resultRef: undefined,
|
|
888
|
-
lastError: undefined,
|
|
889
|
-
leaseOwner: undefined,
|
|
890
|
-
leaseExpiresAt: undefined,
|
|
891
|
-
diagnosticJson: createPITaskDiagnosticJson(successorMetadata),
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
catch (createErr) {
|
|
895
|
-
const errMsg = createErr instanceof Error ? createErr.message : String(createErr);
|
|
896
|
-
if (!(errMsg.includes('UNIQUE constraint') || errMsg.includes('PRIMARY KEY') || errMsg.includes('already exists'))) {
|
|
897
|
-
throw createErr;
|
|
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 和部分回填,再在事务外翻译回结构化结果。
|
|
1184
|
+
try {
|
|
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;
|
|
898
1198
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
detail: 'parentTaskId=' + taskId + ';successorKind=' + proposal.taskKind + ';channel=' + proposal.channel + ';taskIds=[' + conflictingSuccessorTaskIds.join(',') + ']',
|
|
908
|
-
conflictingSuccessorTaskIds };
|
|
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
|
+
});
|
|
909
1207
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
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
|
+
};
|
|
913
1257
|
}
|
|
914
|
-
|
|
915
|
-
// 残骸, 无法证明任一归属。fallback 创建会复制一条逻辑后继而腐蚀行
|
|
916
|
-
// 原地留存 (完整性恶化), fail-closed 要求先修复腐蚀 (rc-9 诚实)。
|
|
917
|
-
const occupantRaw = await this.stateManager.getTask(idForCreate);
|
|
918
|
-
if (occupantRaw !== null && hydratePITaskRecord(occupantRaw) === null) {
|
|
1258
|
+
if (creation.outcome === 'id_conflict') {
|
|
919
1259
|
return {
|
|
920
1260
|
decision: 'successor_id_conflict',
|
|
921
1261
|
sourceTaskId: taskId,
|
|
922
|
-
reason:
|
|
923
|
-
detail:
|
|
1262
|
+
reason: creation.allocation.reason,
|
|
1263
|
+
detail: creation.allocation.detail,
|
|
924
1264
|
};
|
|
925
1265
|
}
|
|
926
|
-
if (
|
|
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') {
|
|
927
1278
|
return {
|
|
928
|
-
decision: '
|
|
1279
|
+
decision: 'successor_exists',
|
|
929
1280
|
sourceTaskId: taskId,
|
|
930
|
-
|
|
931
|
-
|
|
1281
|
+
successorTaskId: creation.task.taskId,
|
|
1282
|
+
successorKind: proposal.taskKind,
|
|
932
1283
|
};
|
|
933
1284
|
}
|
|
934
|
-
|
|
1285
|
+
return {
|
|
1286
|
+
decision: 'successor_created',
|
|
1287
|
+
sourceTaskId: taskId,
|
|
1288
|
+
successorTaskId: creation.task.taskId,
|
|
1289
|
+
successorKind: proposal.taskKind,
|
|
1290
|
+
};
|
|
1291
|
+
});
|
|
935
1292
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
sourceTaskId: taskId,
|
|
941
|
-
reason: 'create_loop_exhausted_without_row',
|
|
942
|
-
};
|
|
1293
|
+
catch (error) {
|
|
1294
|
+
if (error instanceof CommitDecisionRollback)
|
|
1295
|
+
return error.result;
|
|
1296
|
+
throw error;
|
|
943
1297
|
}
|
|
944
|
-
return {
|
|
945
|
-
decision: 'successor_created',
|
|
946
|
-
sourceTaskId: taskId,
|
|
947
|
-
successorTaskId: successorRecord.taskId,
|
|
948
|
-
successorKind: proposal.taskKind,
|
|
949
|
-
};
|
|
950
1298
|
}
|
|
951
1299
|
/**
|
|
952
1300
|
* P0-3 legacy 判据: 从该任务最近 succeeded run 的 output_payload **显式解析**
|
|
@@ -1324,45 +1672,18 @@ export class InternalizationOrchestrator {
|
|
|
1324
1672
|
* (succeeded/needs_human_review) or failed — proves the logical successor
|
|
1325
1673
|
* already exists. This mirrors the semantics the deterministic-id UNIQUE
|
|
1326
1674
|
* constraint catch used to provide as a last resort, extended to chains
|
|
1327
|
-
* whose ids are not derivable.
|
|
1675
|
+
* whose ids are not derivable. Multiple matches are an integrity conflict;
|
|
1676
|
+
* taskId ordering is used only for deterministic reporting, never selection.
|
|
1328
1677
|
*/
|
|
1329
1678
|
async findSuccessorByParent(parentTaskId, successorKind, channel) {
|
|
1330
|
-
// PRI-
|
|
1331
|
-
//
|
|
1332
|
-
//
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
continue;
|
|
1339
|
-
const piTask = hydratePITaskRecord(task);
|
|
1340
|
-
if (!piTask)
|
|
1341
|
-
continue;
|
|
1342
|
-
if (piTask.parentTaskId === parentTaskId && piTask.channel === channel) {
|
|
1343
|
-
matches.push(task);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
if (matches.length === 0) {
|
|
1347
|
-
// PRI-1293 R8 (review #3): 历史未回填后继对持久化 parent 扫描不可见 —
|
|
1348
|
-
// 协调扫描先处理旧父节点时会重复创建后继, 事后才被判完整性冲突。
|
|
1349
|
-
// 创建前用**同一历史推断规则** (单边 inferLegacyParentTaskId, 非通用
|
|
1350
|
-
// dependency 回退) 识别可证明的未回填后继纳入查重; 推断不出或证据
|
|
1351
|
-
// 不足者不算后继 — 与回填门禁同一证明标准, 不放宽。
|
|
1352
|
-
for (const task of allTasks) {
|
|
1353
|
-
if (task.taskKind !== successorKind)
|
|
1354
|
-
continue;
|
|
1355
|
-
const piTask = hydratePITaskRecord(task);
|
|
1356
|
-
if (!piTask || piTask.parentTaskId || piTask.channel !== channel)
|
|
1357
|
-
continue;
|
|
1358
|
-
const inferred = await inferLegacyParentTaskId(task, piTask, this.stateManager);
|
|
1359
|
-
if (inferred.ok && inferred.parentTaskId === parentTaskId) {
|
|
1360
|
-
matches.push(task);
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
matches.sort((a, b) => (a.taskId < b.taskId ? -1 : a.taskId > b.taskId ? 1 : 0));
|
|
1365
|
-
return matches;
|
|
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
|
+
});
|
|
1366
1687
|
}
|
|
1367
1688
|
/**
|
|
1368
1689
|
* Find candidate PI tasks by querying pending and retry_wait statuses.
|