create-principles-disciple 1.156.0 → 1.156.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 +1 -1
- package/codex-adapter/dist/ingestion/pain-receipt-fallback.js +3 -2
- package/codex-adapter/dist/worker/workspace-worker.js +52 -17
- package/codex-adapter/package.json +1 -1
- package/core/dist/runtime/adversarial-loop.d.ts.map +1 -1
- package/core/dist/runtime/adversarial-loop.js +12 -0
- package/core/dist/runtime/adversarial-loop.js.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.js +6 -4
- package/core/dist/runtime/diagnostician-candidate.js.map +1 -1
- package/core/dist/runtime/index.d.ts +9 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +10 -2
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/intent/intent-doc.d.ts +30 -0
- package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-doc.js +47 -0
- package/core/dist/runtime/intent/intent-doc.js.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.d.ts +12 -0
- package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.js +20 -0
- package/core/dist/runtime/intent/intent-snapshot.js.map +1 -1
- package/core/dist/runtime/internalization/correlation-lineage.d.ts +113 -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/diag-rootcause-runner.d.ts +18 -0
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.js +53 -15
- package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts +58 -5
- package/core/dist/runtime/internalization/internalization-orchestrator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/internalization-orchestrator.js +370 -100
- 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/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 +31 -0
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.js +54 -1
- package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime/internalization/repair-task-identity.d.ts +43 -0
- package/core/dist/runtime/internalization/repair-task-identity.d.ts.map +1 -0
- package/core/dist/runtime/internalization/repair-task-identity.js +102 -0
- package/core/dist/runtime/internalization/repair-task-identity.js.map +1 -0
- package/core/dist/runtime/internalization/revision-reopen.d.ts +37 -0
- package/core/dist/runtime/internalization/revision-reopen.d.ts.map +1 -1
- package/core/dist/runtime/internalization/revision-reopen.js +144 -7
- package/core/dist/runtime/internalization/revision-reopen.js.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +8 -2
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +2 -2
- 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/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +4 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/pain-admission-disposition.d.ts +8 -4
- package/core/dist/runtime/pain-admission-disposition.d.ts.map +1 -1
- package/core/dist/runtime/pain-admission-disposition.js +8 -4
- package/core/dist/runtime/pain-admission-disposition.js.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.d.ts +38 -10
- package/core/dist/runtime/pain-receipt-recovery.d.ts.map +1 -1
- package/core/dist/runtime/pain-receipt-recovery.js +266 -30
- package/core/dist/runtime/pain-receipt-recovery.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts +60 -12
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +200 -142
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +14 -3
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +21 -9
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts +48 -13
- package/core/dist/runtime/pain-target-evidence-reconcile.d.ts.map +1 -1
- package/core/dist/runtime/pain-target-evidence-reconcile.js +267 -81
- package/core/dist/runtime/pain-target-evidence-reconcile.js.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.d.ts +2 -5
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts +2 -0
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js +18 -0
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.d.ts.map +1 -1
- package/core/dist/runtime/store/task/memory-task-store.js +20 -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.map +1 -1
- package/core/dist/runtime/store/task/sqlite-task-store.js +9 -0
- package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime/store/task/task-store.d.ts +10 -0
- package/core/dist/runtime/store/task/task-store.d.ts.map +1 -1
- package/core/package.json +1 -1
- package/host-runtime/dist/diagnostician-auto-run.js +20 -14
- package/host-runtime/dist/index.d.ts +3 -1
- package/host-runtime/dist/index.js +15 -1
- package/host-runtime/dist/intent-doc-reader.js +1 -1
- package/host-runtime/dist/internalization-consumer-cycle.d.ts +102 -1
- package/host-runtime/dist/internalization-consumer-cycle.js +177 -95
- package/host-runtime/dist/internalization-consumer-governance.d.ts +2 -1
- package/host-runtime/dist/internalization-consumer-governance.js +57 -2
- package/host-runtime/dist/workspace-pipeline-host-deps.d.ts +65 -0
- package/host-runtime/dist/workspace-pipeline-host-deps.js +94 -0
- package/host-runtime/dist/workspace-telemetry-emitter.js +14 -0
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/index.d.ts +1 -0
- package/install-layout/dist/index.js +1 -0
- package/install-layout/dist/openclaw-config-path.d.ts +9 -0
- package/install-layout/dist/openclaw-config-path.js +64 -0
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/codex-worker.js +2 -2
- package/pd-cli/dist/commands/codex-worker.js.map +1 -1
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +49 -75
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +18 -26
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +50 -66
- package/pd-cli/dist/commands/pain-retry.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 +184 -17
- 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 +209 -127
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/workbuddy-worker.js +2 -2
- package/pd-cli/dist/commands/workbuddy-worker.js.map +1 -1
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
- package/pd-cli/dist/services/config-doctor.js +7 -4
- package/pd-cli/dist/services/config-doctor.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 +53 -4
- package/pd-cli/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/server.d.ts +7 -0
- package/pd-mcp-server/dist/server.js +12 -1
- package/pd-mcp-server/dist/submit-assembly.js +2 -1
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +532 -496
- package/plugin/dist/core/config-health.d.ts +6 -0
- package/plugin/dist/core/openclaw-config-loader.d.ts +14 -0
- package/plugin/dist/core/pain-service.d.ts +26 -0
- package/plugin/dist/hooks/openclaw-run-turn-correlation.d.ts +30 -0
- package/plugin/dist/hooks/openclaw-target-turn-capture.d.ts +13 -0
- package/plugin/dist/hooks/pain-receipt-fallback.d.ts +107 -0
- package/plugin/dist/openclaw-sdk.d.ts +15 -0
- package/plugin/dist/openclaw-worker.d.ts +3 -0
- package/plugin/dist/openclaw-worker.js +288 -287
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/dist/ingestion/pain-receipt-fallback.js +3 -2
- package/workbuddy-adapter/dist/worker/workspace-worker.d.ts +3 -0
- package/workbuddy-adapter/dist/worker/workspace-worker.js +48 -15
- package/workbuddy-adapter/package.json +1 -1
|
@@ -13,8 +13,15 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @see docs/adr/0003-peer-agent-state-machine-orchestration.md
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { PD_TASK_STATUSES } from '../task-status.js';
|
|
17
|
+
import { deriveSuccessorTaskId } from './internalization-state-machine.js';
|
|
18
|
+
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 { inferLegacyParentTaskId } from './correlation-lineage.js';
|
|
22
|
+
// PRI-1293 Phase 3: 唯一 PeerRunnerKind 血缘权威解析器 (core 内部模块,
|
|
23
|
+
// 不入 barrel — 跨包消费方经 InternalizationOrchestrator 静态只读包装访问)。
|
|
24
|
+
import { resolveAuthoritativeCorrelationId, resolveAuthoritativeCorrelationIdWithLegacyBackfill, CORRELATION_LINEAGE_MAX_PARENT_EDGES, } from './correlation-lineage.js';
|
|
18
25
|
import { isPeerRunnerKind, isDiagnosticianStageKind, isRunnerKind } from './peer-runner-contracts.js';
|
|
19
26
|
import { validateInternalizationTaskReady, createNextTaskProposal, } from './internalization-state-machine.js';
|
|
20
27
|
import { getDiagSuccessors } from './internalization-job-graph.js';
|
|
@@ -25,24 +32,6 @@ import { evaluateAndPersistAdmissionFromStore } from '../pain-signal-bridge.js';
|
|
|
25
32
|
import { denyAllSourceMaterialAuthorization } from '../source-material-authorization.js';
|
|
26
33
|
import { decideInternalizationTransition, transitionInputFromTask, } from './internalization-transition-decision.js';
|
|
27
34
|
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
35
|
/**
|
|
47
36
|
* Runtime decision labels for WakeOnceResult — used by host layers for
|
|
48
37
|
* logging, metrics bucketing, and switch-statement exhaustiveness checks.
|
|
@@ -78,6 +67,17 @@ export class InternalizationOrchestrator {
|
|
|
78
67
|
this.runtimeKind = options.runtimeKind;
|
|
79
68
|
this.dryRun = options.dryRun ?? false;
|
|
80
69
|
}
|
|
70
|
+
// ── PRI-1293 Phase 3: 跨包血缘解析通道 (静态只读) ─────────────────────────
|
|
71
|
+
//
|
|
72
|
+
// resolveAuthoritativeCorrelationId 是 core 内部模块 correlation-lineage.ts
|
|
73
|
+
// 的唯一实现; host-runtime (Evaluator Repair Seeder) 与 pd-cli
|
|
74
|
+
// (rulehost seeder) 需要同一判定结果, 但 resolver 不得成为新的 barrel 公开
|
|
75
|
+
// 符号 (PRI-775 冻结面), 也不得复制第二套父链遍历。既有公开类上的静态只读
|
|
76
|
+
// 薄包装是 SPEC §5.4 授权的共享通道: 零状态、零写入, 仅委托。
|
|
77
|
+
/** PeerRunnerKind 父链 correlationId 权威解析 — 只读, 详见 correlation-lineage.ts。 */
|
|
78
|
+
static resolveAuthoritativeCorrelationId(leafTaskRecord, getTask) {
|
|
79
|
+
return resolveAuthoritativeCorrelationId(leafTaskRecord, getTask);
|
|
80
|
+
}
|
|
81
81
|
// ── wakeOnce ──────────────────────────────────────────────────────────────
|
|
82
82
|
/**
|
|
83
83
|
* Find the first leasable PI task, validate dependencies, and acquire lease
|
|
@@ -475,6 +475,44 @@ export class InternalizationOrchestrator {
|
|
|
475
475
|
};
|
|
476
476
|
}
|
|
477
477
|
if (transition.kind === 'REOPEN_SOURCE_EVALUATOR' && piTask.repairPayload) {
|
|
478
|
+
// PRI-1293 R7 (P1-1): Repair 完成路径的身份前置验证 — 本分支早于通用
|
|
479
|
+
// PeerRunner 血缘门禁, 不能依赖后续检查兜底。修改来源 Evaluator 之前
|
|
480
|
+
// 必须证明 Repair 自身: payload 身份与 taskId 互证、来源 Evaluator 真实、
|
|
481
|
+
// parent/correlation/channel 一致。验证失败 = 零写入 + 结构化拒绝
|
|
482
|
+
// (不得修改 dependencyTaskIds/清空 inputArtifactRefs/递增 revisionCount)。
|
|
483
|
+
const repairIdentity = await verifyRepairTaskIdentity(rawTask, piTask.repairPayload.sourceEvaluatorTaskId, piTask.repairPayload.repairIteration, this.stateManager);
|
|
484
|
+
if (!repairIdentity.ok) {
|
|
485
|
+
return {
|
|
486
|
+
decision: 'lineage_refused',
|
|
487
|
+
sourceTaskId: taskId,
|
|
488
|
+
reason: repairIdentity.reason,
|
|
489
|
+
detail: `repair_identity_verification_failed:${repairIdentity.detail} — source evaluator NOT reopened, zero writes`,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
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
|
+
}
|
|
478
516
|
// PRI-629 P0 (SPEC §12): epoch-aware causal identity — Owner 额外修订轮
|
|
479
517
|
// (revise_once reopen 该 artificer,其 revisionCount+1) 再次完成时,
|
|
480
518
|
// 重开来源 evaluator 必须使用新 causeId 才是真 reopen;同 epoch 重放
|
|
@@ -486,7 +524,7 @@ export class InternalizationOrchestrator {
|
|
|
486
524
|
// 情况重放都不得再次 reopen(后者会丢弃已完成的修订轮 verdict)。
|
|
487
525
|
const srcRaw = await this.stateManager.getTask(piTask.repairPayload.sourceEvaluatorTaskId);
|
|
488
526
|
const srcPi = srcRaw ? hydratePITaskRecord(srcRaw) : null;
|
|
489
|
-
if (srcPi && srcPi
|
|
527
|
+
if (srcPi && hasConsumedRevisionCause(srcPi, causeId)) {
|
|
490
528
|
return {
|
|
491
529
|
decision: 'revision_reopen_noop',
|
|
492
530
|
sourceTaskId: taskId,
|
|
@@ -529,9 +567,23 @@ export class InternalizationOrchestrator {
|
|
|
529
567
|
revisionCauseId: causeId,
|
|
530
568
|
});
|
|
531
569
|
if (!reopened.ok) {
|
|
532
|
-
//
|
|
533
|
-
|
|
534
|
-
|
|
570
|
+
// Repair 已成功但来源 Evaluator reopen 失败不是正常终点;保留真实拒绝类别。
|
|
571
|
+
if (reopened.reason.startsWith('lineage_refused:')) {
|
|
572
|
+
return { decision: 'lineage_refused', sourceTaskId: taskId,
|
|
573
|
+
reason: reopened.reason.slice('lineage_refused:'.length), detail: reopened.detail ?? reopened.reason };
|
|
574
|
+
}
|
|
575
|
+
if (reopened.reason === 'concurrent_modification') {
|
|
576
|
+
return { decision: 'concurrent_modification', sourceTaskId: taskId,
|
|
577
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
578
|
+
detail: reopened.detail ?? 'repair_evaluator_reopen_cas_conflict:' + piTask.repairPayload.sourceEvaluatorTaskId };
|
|
579
|
+
}
|
|
580
|
+
if (reopened.reason === 'invalid_task_metadata') {
|
|
581
|
+
return { decision: 'invalid_task_metadata', taskId: piTask.repairPayload.sourceEvaluatorTaskId,
|
|
582
|
+
reason: 'repair_evaluator_reopen_invalid_task_metadata' };
|
|
583
|
+
}
|
|
584
|
+
return { decision: 'revision_reopen_failed', sourceTaskId: taskId,
|
|
585
|
+
reopenedTaskId: piTask.repairPayload.sourceEvaluatorTaskId, reason: reopened.reason,
|
|
586
|
+
...(reopened.detail !== undefined ? { detail: reopened.detail } : {}) };
|
|
535
587
|
}
|
|
536
588
|
// A (crash window): 同 causeId 重放 = 真 no-op — 单独 decision 使
|
|
537
589
|
// reconciliation 不把它计为"恢复" (already materialized)。
|
|
@@ -584,20 +636,34 @@ export class InternalizationOrchestrator {
|
|
|
584
636
|
}
|
|
585
637
|
return this.reopenArtificerForSourceCorrection(taskId, piTask);
|
|
586
638
|
}
|
|
639
|
+
// ── PRI-1293 Phase 3: PeerRunnerKind 血缘门禁 (ADVANCE 路径唯一写前关口) ──
|
|
640
|
+
// 严格作用域: 仅 PeerRunnerKind 源任务。DiagnosticianStageKind 子任务
|
|
641
|
+
// 继续走 proposeNextTask 的 getDiagSuccessors 分支 (parentTaskId +
|
|
642
|
+
// dependencyTaskIds 语义), 绝不套用 correlationId 门禁。
|
|
643
|
+
// 校验发生在任何后继创建之前: 拒绝 = 零 createTask、零状态写入、零
|
|
644
|
+
// reopen; 结构化 lineage_refused 让 host 层 (consumer cycle / run-once /
|
|
645
|
+
// enqueue-successors / reconciliation) 可观测, 不折叠成 no_successor。
|
|
646
|
+
// 校验同时负责历史无 id 链的根侧恢复 — 成功结果 (含 recoveredFromLegacyRoot)
|
|
647
|
+
// 写入新后继 metadata.correlationId; 后继 taskId 派生保持原样 (proposal.
|
|
648
|
+
// correlationId ?? stripTrailingChannel), 不漂移在途历史链的确定性去重。
|
|
649
|
+
let authoritativeCorrelation = null;
|
|
650
|
+
if (isPeerRunnerKind(piTask.taskKind)) {
|
|
651
|
+
const lineage = await resolveAuthoritativeCorrelationIdWithLegacyBackfill(rawTask, this.stateManager);
|
|
652
|
+
if (!lineage.ok) {
|
|
653
|
+
return {
|
|
654
|
+
decision: 'lineage_refused',
|
|
655
|
+
sourceTaskId: taskId,
|
|
656
|
+
reason: lineage.reason,
|
|
657
|
+
detail: lineage.detail,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
authoritativeCorrelation = lineage;
|
|
661
|
+
}
|
|
587
662
|
const proposalResult = await this.proposeNextTask(taskId);
|
|
588
663
|
if (!proposalResult) {
|
|
589
664
|
return { decision: 'no_successor', sourceTaskId: taskId, reason: 'No valid successor in job graph for this task kind and channel' };
|
|
590
665
|
}
|
|
591
666
|
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
667
|
// Successor taskId must be STABLE across the whole peer-runner chain so that
|
|
602
668
|
// every layer (dreamer/philosopher/scribe/artificer/evaluator) derives its id
|
|
603
669
|
// from the SAME root, not from the predecessor's full id (which already
|
|
@@ -614,35 +680,62 @@ export class InternalizationOrchestrator {
|
|
|
614
680
|
// Fallback: when correlationId is absent (diagnostician chain seeds it as
|
|
615
681
|
// undefined), use the source taskId but strip a trailing `-<channel>` so we
|
|
616
682
|
// 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}`;
|
|
683
|
+
// PRI-1293 R5: 派生经共享单一来源 (internalization-state-machine) —
|
|
684
|
+
// dry-run 预览消费同一函数, 两条路径不再有各自的派生实现。
|
|
685
|
+
const successorTaskId = deriveSuccessorTaskId(proposal, taskId);
|
|
627
686
|
// ── 级联 reopen (revision wave) ──
|
|
628
687
|
// 稳定 id 后继已存在且为 succeeded: 仅当源任务经历过 revision
|
|
629
688
|
// (revisionCount > 0, 即上游被 reopen 后重新完成)时, 下游才必须重跑
|
|
630
689
|
// (而非 successor_exists 停摆)。普通幂等重扫 (revisionCount=0) 不级联,
|
|
631
690
|
// 保持既有 successor_exists 语义。pending/retry_wait 的存在后继仍走
|
|
632
691
|
// findExistingSuccessor 的 successor_exists 分支。
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
692
|
+
// ── 统一后继识别 (PRI-1293 review round 3) ──
|
|
693
|
+
// 后继身份是 (parentTaskId, successorKind, channel) 父子关系, 不是派生 id:
|
|
694
|
+
// - 修订重开把恢复的 correlationId 回填进源任务, 派生根漂移 (R2);
|
|
695
|
+
// - RuleHost 同步链持久化时间戳 id, 确定性派生永不复现 (R3)。
|
|
696
|
+
// 因此直查与父子扫描都不再受 revisionCount 门限制 — 此前 rc=0 仅靠
|
|
697
|
+
// createTask 的 UNIQUE 撞约束兜底, 对时间戳链等于毫无保护: dry-run
|
|
698
|
+
// (全状态索引) 能看到的终态后继, confirm 却再创建一条逻辑相同的链。
|
|
699
|
+
// 现在任何状态的已存在后继 (在途/终态/failed) 都先命中 successor_exists;
|
|
700
|
+
// 仅当命中可重开终态且源经历过 revision (rc>0) 时才进入级联重开。
|
|
701
|
+
// PRI-1293 R5 (跨链派生 id 碰撞): 父子扫描是唯一权威, 直查快路径废除——
|
|
702
|
+
// 旧实现在确定性 id 命中时跳过扫描, 且不校验 occupant 的 parentTaskId:
|
|
703
|
+
// 候选身份经修订回填进**另一条链** (如 RuleHost 时间戳链) 后, 其派生 id
|
|
704
|
+
// 与本队列链相同, 直查命中异链任务, 级联重开错链的后继并替换其依赖。
|
|
705
|
+
// 扫描按 (parentTaskId, kind, channel) 匹配, 异链 occupant 自然不命中;
|
|
706
|
+
// id 占用冲突在创建路径处理 (fallback 父派生 id + UNIQUE 竞态重扫)。
|
|
707
|
+
const scannedSuccessors = await this.findSuccessorByParent(taskId, proposal.taskKind, proposal.channel);
|
|
708
|
+
if (scannedSuccessors.length > 1) {
|
|
709
|
+
const conflictingSuccessorTaskIds = scannedSuccessors.map((candidate) => candidate.taskId);
|
|
710
|
+
return { decision: 'successor_integrity_conflict', sourceTaskId: taskId,
|
|
711
|
+
reason: 'multiple_successors_for_parent',
|
|
712
|
+
detail: 'parentTaskId=' + taskId + ';successorKind=' + proposal.taskKind + ';channel=' + proposal.channel + ';taskIds=[' + conflictingSuccessorTaskIds.join(',') + ']',
|
|
713
|
+
conflictingSuccessorTaskIds };
|
|
714
|
+
}
|
|
715
|
+
const existingSuccessorCandidate = scannedSuccessors[0] ?? null;
|
|
716
|
+
// PRI-1293 R5: 级联判定经共享只读 planner (revision-reopen.ts) — commit
|
|
717
|
+
// 与 dry-run 预览消费同一判定, 预览不再把"将重开"误报为 successor_exists。
|
|
718
|
+
const scannedSuccPi = existingSuccessorCandidate !== null ? hydratePITaskRecord(existingSuccessorCandidate) : null;
|
|
719
|
+
const successorTransitionPlan = existingSuccessorCandidate !== null
|
|
720
|
+
? planExistingSuccessorTransition({
|
|
721
|
+
sourceTaskId: taskId,
|
|
722
|
+
sourceRevisionCount: piTask.revisionCount ?? 0,
|
|
723
|
+
successorTaskId: existingSuccessorCandidate.taskId,
|
|
724
|
+
successorStatus: existingSuccessorCandidate.status,
|
|
725
|
+
successorRevisionCauseId: scannedSuccPi?.revisionCauseId,
|
|
726
|
+
successorConsumedRevisionCauseIds: scannedSuccPi?.consumedRevisionCauseIds,
|
|
727
|
+
})
|
|
728
|
+
: { plan: 'exists_plain' };
|
|
729
|
+
if (existingSuccessorCandidate !== null && successorTransitionPlan.plan !== 'exists_plain') {
|
|
730
|
+
const cascadeTargetTaskId = existingSuccessorCandidate.taskId;
|
|
731
|
+
const { cascadeCauseId } = successorTransitionPlan;
|
|
638
732
|
// B: 对称的 cause 前置 — 该 wave 的 cascade reopen 已 materialize
|
|
639
733
|
// (successor 可能 pending 或已重跑完成),重放不得再 reopen。
|
|
640
|
-
|
|
641
|
-
if (succPi && succPi.revisionCauseId === cascadeCauseId) {
|
|
734
|
+
if (successorTransitionPlan.plan === 'cascade_already_materialized') {
|
|
642
735
|
return {
|
|
643
736
|
decision: 'revision_reopen_noop',
|
|
644
737
|
sourceTaskId: taskId,
|
|
645
|
-
reopenedTaskId:
|
|
738
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
646
739
|
reason: 'revision_cause_already_materialized',
|
|
647
740
|
};
|
|
648
741
|
}
|
|
@@ -655,8 +748,8 @@ export class InternalizationOrchestrator {
|
|
|
655
748
|
// 的 replaceArtificerDependencyWith 过滤同源——不用 id 前缀约定) 不是
|
|
656
749
|
// 刚完成的 taskId 时,镜像 REOPEN_SOURCE_EVALUATOR 的换依赖语义。
|
|
657
750
|
let cascadeReplaceArtificerDependencyWith;
|
|
658
|
-
if (
|
|
659
|
-
for (const depId of
|
|
751
|
+
if (scannedSuccPi && proposal.taskKind === 'evaluator') {
|
|
752
|
+
for (const depId of scannedSuccPi.dependencyTaskIds) {
|
|
660
753
|
if (depId === taskId)
|
|
661
754
|
continue;
|
|
662
755
|
const dep = await this.stateManager.getTask(depId);
|
|
@@ -666,7 +759,7 @@ export class InternalizationOrchestrator {
|
|
|
666
759
|
}
|
|
667
760
|
}
|
|
668
761
|
}
|
|
669
|
-
const reopened = await this.reopenTaskForRevision(
|
|
762
|
+
const reopened = await this.reopenTaskForRevision(cascadeTargetTaskId, {
|
|
670
763
|
reason: 'upstream_revision_cascade',
|
|
671
764
|
// B (外部复核): causal idempotency — 同一 upstream revision wave 的
|
|
672
765
|
// reconciliation/commit 重放不得再次 reopen 或递增 revisionCount。
|
|
@@ -680,33 +773,82 @@ export class InternalizationOrchestrator {
|
|
|
680
773
|
return {
|
|
681
774
|
decision: 'revision_reopen_noop',
|
|
682
775
|
sourceTaskId: taskId,
|
|
683
|
-
reopenedTaskId:
|
|
776
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
684
777
|
reason: reopened.reason,
|
|
685
778
|
};
|
|
686
779
|
}
|
|
687
780
|
return {
|
|
688
781
|
decision: 'successor_reopened',
|
|
689
782
|
sourceTaskId: taskId,
|
|
690
|
-
reopenedTaskId:
|
|
783
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
691
784
|
successorKind: proposal.taskKind,
|
|
692
785
|
};
|
|
693
786
|
}
|
|
787
|
+
// 级联重开被拒绝不折叠为 successor_exists — 修订波未能向下游传播,
|
|
788
|
+
// 链停在旧 epoch; 结构化透出真实拒绝原因 (rc-9), 让 consumer cycle /
|
|
789
|
+
// run-once / enqueue-successors 可观测, 而非呈现为正常幂等态。
|
|
790
|
+
if (reopened.reason.startsWith('lineage_refused:')) {
|
|
791
|
+
return {
|
|
792
|
+
decision: 'lineage_refused',
|
|
793
|
+
sourceTaskId: taskId,
|
|
794
|
+
reason: reopened.reason.slice('lineage_refused:'.length),
|
|
795
|
+
detail: `cascade_reopen_refused:${cascadeTargetTaskId}${reopened.detail !== undefined ? `:${reopened.detail}` : ''}`,
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
if (reopened.reason === 'invalid_task_metadata') {
|
|
799
|
+
return {
|
|
800
|
+
decision: 'invalid_task_metadata',
|
|
801
|
+
taskId: cascadeTargetTaskId,
|
|
802
|
+
reason: `cascade_reopen_invalid_task_metadata: successor of ${taskId}`,
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
// PRI-1293 review round 3: CAS 并发落败是独立的结构化结果 — 级联未能
|
|
806
|
+
// 传播修订波, 链停在旧 epoch, 绝不折叠为 successor_exists (那会把未
|
|
807
|
+
// 完成的级联伪装成正常幂等态)。reopen 内部已在 CAS 落败后重读: 同一
|
|
808
|
+
// revisionCauseId 已 materialize 的重放在上面按 idempotent no-op 返回,
|
|
809
|
+
// 到达这里 = 真实的并发冲突, 可安全重试 (reopen 幂等)。
|
|
810
|
+
if (reopened.reason === 'concurrent_modification') {
|
|
811
|
+
return {
|
|
812
|
+
decision: 'concurrent_modification',
|
|
813
|
+
sourceTaskId: taskId,
|
|
814
|
+
reopenedTaskId: cascadeTargetTaskId,
|
|
815
|
+
detail: reopened.detail ?? `cascade_cas_conflict:${cascadeTargetTaskId}`,
|
|
816
|
+
};
|
|
817
|
+
}
|
|
694
818
|
return {
|
|
695
819
|
decision: 'successor_exists',
|
|
696
820
|
sourceTaskId: taskId,
|
|
697
|
-
successorTaskId,
|
|
821
|
+
successorTaskId: cascadeTargetTaskId,
|
|
698
822
|
successorKind: proposal.taskKind,
|
|
699
823
|
};
|
|
700
824
|
}
|
|
701
|
-
if (
|
|
702
|
-
//
|
|
825
|
+
if (existingSuccessorCandidate) {
|
|
826
|
+
// 统一识别的剩余命中: rc=0 的终态后继 (幂等重扫不级联 — 保留原任务
|
|
827
|
+
// id, 零创建零重复执行), 以及 leased/retry_wait/pending/failed 在途
|
|
828
|
+
// 或待重试后继 — 与任务状态机语义一致, 不重复处理。
|
|
703
829
|
return {
|
|
704
830
|
decision: 'successor_exists',
|
|
705
831
|
sourceTaskId: taskId,
|
|
706
|
-
successorTaskId,
|
|
832
|
+
successorTaskId: existingSuccessorCandidate.taskId,
|
|
707
833
|
successorKind: proposal.taskKind,
|
|
708
834
|
};
|
|
709
835
|
}
|
|
836
|
+
// PRI-1293 review fix: 创建前校验"再加一条边是否越限"。resolver 只校验
|
|
837
|
+
// 源任务自身链 (读取侧 — 深度 10 的在途任务保持可读), 但深度 10 的源
|
|
838
|
+
// 若创建后继, 新任务即刻成为第 11 条边, 之后它自身的每次 commit/reopen
|
|
839
|
+
// 都被同一 resolver 拒绝 — 产出"已创建但永远无法推进"的任务。因此在
|
|
840
|
+
// 持久化前 fail-closed: 源深度 9 → 后继 10 放行; 源深度 10 → 结构化拒绝,
|
|
841
|
+
// 零 createTask 零写入。注意此检查只在创建路径 — 上方在途/终态后继的
|
|
842
|
+
// successor_exists 与级联 reopen 不受影响 (reopen 有自身的血缘校验)。
|
|
843
|
+
if (authoritativeCorrelation !== null
|
|
844
|
+
&& authoritativeCorrelation.parentEdgeCount + 1 > CORRELATION_LINEAGE_MAX_PARENT_EDGES) {
|
|
845
|
+
return {
|
|
846
|
+
decision: 'lineage_refused',
|
|
847
|
+
sourceTaskId: taskId,
|
|
848
|
+
reason: 'parent_chain_cycle_or_depth_exceeded',
|
|
849
|
+
detail: `successor_would_exceed_depth_limit:${authoritativeCorrelation.parentEdgeCount + 1}_edges_max_${CORRELATION_LINEAGE_MAX_PARENT_EDGES}`,
|
|
850
|
+
};
|
|
851
|
+
}
|
|
710
852
|
const successorMetadata = {
|
|
711
853
|
dependencyTaskIds: proposal.dependencyTaskIds,
|
|
712
854
|
channel: proposal.channel,
|
|
@@ -715,35 +857,89 @@ export class InternalizationOrchestrator {
|
|
|
715
857
|
inputArtifactRefs: proposal.inputArtifactRefs,
|
|
716
858
|
outputArtifactRefs: [],
|
|
717
859
|
parentTaskId: proposal.parentTaskId,
|
|
718
|
-
|
|
860
|
+
// PRI-1293 Phase 3: 写入的是经过权威校验/恢复的 correlationId —
|
|
861
|
+
// 历史无 id 链在此补入根侧恢复值 (§3.6.3 历史恢复), 正常链上与
|
|
862
|
+
// proposal.correlationId 相同 (校验保证链内一致 + 根佐证)。
|
|
863
|
+
correlationId: authoritativeCorrelation?.correlationId ?? proposal.correlationId,
|
|
719
864
|
};
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
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;
|
|
898
|
+
}
|
|
899
|
+
// UNIQUE 落败: 重扫真实后继。并发创建者物化的新行一律 pending,
|
|
900
|
+
// successor_exists 收敛语义正确; 既有终态后继早在首个扫描即命中,
|
|
901
|
+
// 不会到达此处。
|
|
902
|
+
const rescanned = await this.findSuccessorByParent(taskId, proposal.taskKind, proposal.channel);
|
|
903
|
+
if (rescanned.length > 1) {
|
|
904
|
+
const conflictingSuccessorTaskIds = rescanned.map((candidate) => candidate.taskId);
|
|
905
|
+
return { decision: 'successor_integrity_conflict', sourceTaskId: taskId,
|
|
906
|
+
reason: 'multiple_successors_for_parent_after_unique_conflict',
|
|
907
|
+
detail: 'parentTaskId=' + taskId + ';successorKind=' + proposal.taskKind + ';channel=' + proposal.channel + ';taskIds=[' + conflictingSuccessorTaskIds.join(',') + ']',
|
|
908
|
+
conflictingSuccessorTaskIds };
|
|
909
|
+
}
|
|
910
|
+
if (rescanned.length === 1) {
|
|
911
|
+
return { decision: 'successor_exists', sourceTaskId: taskId,
|
|
912
|
+
successorTaskId: rescanned.at(0)?.taskId ?? "", successorKind: proposal.taskKind };
|
|
913
|
+
}
|
|
914
|
+
// occupant 不可解析 = 损坏行 — 它可能是本链被腐蚀的后继也可能是异链
|
|
915
|
+
// 残骸, 无法证明任一归属。fallback 创建会复制一条逻辑后继而腐蚀行
|
|
916
|
+
// 原地留存 (完整性恶化), fail-closed 要求先修复腐蚀 (rc-9 诚实)。
|
|
917
|
+
const occupantRaw = await this.stateManager.getTask(idForCreate);
|
|
918
|
+
if (occupantRaw !== null && hydratePITaskRecord(occupantRaw) === null) {
|
|
919
|
+
return {
|
|
920
|
+
decision: 'successor_id_conflict',
|
|
921
|
+
sourceTaskId: taskId,
|
|
922
|
+
reason: 'occupant_metadata_unparseable',
|
|
923
|
+
detail: 'task ' + idForCreate + ' occupies the derived id with unparseable diagnosticJson — repair corruption before creating (no fallback duplication of a corrupt row)',
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
if (createAttempt === 1) {
|
|
927
|
+
return {
|
|
928
|
+
decision: 'successor_id_conflict',
|
|
929
|
+
sourceTaskId: taskId,
|
|
930
|
+
reason: 'derived_and_fallback_ids_occupied_by_foreign_chain',
|
|
931
|
+
detail: 'primary=' + successorTaskId + ' fallback=' + successorTaskId + '-p-' + taskId + ' both occupied; scan found no successor for parent ' + taskId,
|
|
932
|
+
};
|
|
933
|
+
}
|
|
745
934
|
}
|
|
746
|
-
|
|
935
|
+
}
|
|
936
|
+
if (successorRecord === null) {
|
|
937
|
+
// 循环不变式保证不可达 (attempt 1 落败已返回), 防御性 fail-closed。
|
|
938
|
+
return {
|
|
939
|
+
decision: 'successor_id_conflict',
|
|
940
|
+
sourceTaskId: taskId,
|
|
941
|
+
reason: 'create_loop_exhausted_without_row',
|
|
942
|
+
};
|
|
747
943
|
}
|
|
748
944
|
return {
|
|
749
945
|
decision: 'successor_created',
|
|
@@ -890,7 +1086,25 @@ export class InternalizationOrchestrator {
|
|
|
890
1086
|
continue;
|
|
891
1087
|
try {
|
|
892
1088
|
const result = await this.commitNextTaskProposal(task.taskId);
|
|
893
|
-
|
|
1089
|
+
// PRI-1293 R7 (P2-2): 完整结构化投影 — repair reopen 失败后 Owner 必须
|
|
1090
|
+
// 能直接从 reconciliation 结果定位原本要重开的 Evaluator (reopenedTaskId),
|
|
1091
|
+
// 不得在中间层丢失证据字段。
|
|
1092
|
+
const outcome = {
|
|
1093
|
+
taskId: task.taskId, decision: result.decision,
|
|
1094
|
+
};
|
|
1095
|
+
if ('reason' in result)
|
|
1096
|
+
outcome.reason = result.reason;
|
|
1097
|
+
if ('detail' in result && result.detail !== undefined)
|
|
1098
|
+
outcome.detail = result.detail;
|
|
1099
|
+
if ('reopenedTaskId' in result && typeof result.reopenedTaskId === 'string')
|
|
1100
|
+
outcome.reopenedTaskId = result.reopenedTaskId;
|
|
1101
|
+
if ('successorTaskId' in result && typeof result.successorTaskId === 'string')
|
|
1102
|
+
outcome.successorTaskId = result.successorTaskId;
|
|
1103
|
+
if ('successorKind' in result && typeof result.successorKind === 'string')
|
|
1104
|
+
outcome.successorKind = result.successorKind;
|
|
1105
|
+
if ('conflictingSuccessorTaskIds' in result)
|
|
1106
|
+
outcome.conflictingSuccessorTaskIds = [...result.conflictingSuccessorTaskIds];
|
|
1107
|
+
outcomes.push(outcome);
|
|
894
1108
|
if (result.decision === 'successor_created' || result.decision === 'revision_reopened' || result.decision === 'successor_reopened'
|
|
895
1109
|
|| result.decision === 'source_correction_reopened') {
|
|
896
1110
|
recovered += 1;
|
|
@@ -989,7 +1203,7 @@ export class InternalizationOrchestrator {
|
|
|
989
1203
|
return { decision: 'source_correction_reopen_conflict', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'artificer_metadata_invalid' };
|
|
990
1204
|
}
|
|
991
1205
|
// 崩溃重放:Artificer 已带本 cause(上次续接已 materialize)→ 幂等 no-op。
|
|
992
|
-
if (artificerPi
|
|
1206
|
+
if (hasConsumedRevisionCause(artificerPi, causeId)) {
|
|
993
1207
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'reopened_earlier', recordedAt: new Date().toISOString() });
|
|
994
1208
|
return { decision: 'source_correction_reopen_noop', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'source_correction_cause_already_materialized' };
|
|
995
1209
|
}
|
|
@@ -1010,11 +1224,32 @@ export class InternalizationOrchestrator {
|
|
|
1010
1224
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'conflict', recordedAt: new Date().toISOString(), detail });
|
|
1011
1225
|
return { decision: 'source_correction_reopen_conflict', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: detail };
|
|
1012
1226
|
}
|
|
1227
|
+
// PRI-1293 Phase 3: 定点续接是生产 reopen 路径 — 与 commit/reopen 核心
|
|
1228
|
+
// 共享同一血缘权威。守卫通过后、CAS 写之前校验; 拒绝 = conflict 终态
|
|
1229
|
+
// 可观测 (receipt outcome 落库), 零写入。
|
|
1230
|
+
const artificerLineage = await resolveAuthoritativeCorrelationIdWithLegacyBackfill(artificerTask, this.stateManager);
|
|
1231
|
+
if (!artificerLineage.ok) {
|
|
1232
|
+
await this.recordSourceCorrectionOutcome(scribeTaskId, {
|
|
1233
|
+
kind: 'conflict',
|
|
1234
|
+
recordedAt: new Date().toISOString(),
|
|
1235
|
+
detail: `lineage_refused:${artificerLineage.reason}`,
|
|
1236
|
+
});
|
|
1237
|
+
return {
|
|
1238
|
+
decision: 'source_correction_reopen_conflict',
|
|
1239
|
+
sourceTaskId: scribeTaskId,
|
|
1240
|
+
reopenedTaskId: artificerTaskId,
|
|
1241
|
+
reason: `lineage_refused:${artificerLineage.reason}`,
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1013
1244
|
const merged = mergePITaskMetadata(artificerPi, {
|
|
1014
1245
|
runnerDecision: undefined,
|
|
1015
1246
|
completionIntent: undefined,
|
|
1016
1247
|
revisionCount: (artificerPi.revisionCount ?? 0) + 1,
|
|
1017
1248
|
revisionCauseId: causeId,
|
|
1249
|
+
// §5.3.7: 可恢复历史链在续接写中补入已验证的 correlationId。
|
|
1250
|
+
...(artificerLineage.correlationId !== (artificerPi.correlationId?.trim() ?? '')
|
|
1251
|
+
? { correlationId: artificerLineage.correlationId }
|
|
1252
|
+
: {}),
|
|
1018
1253
|
});
|
|
1019
1254
|
const updated = await this.stateManager.updateTaskIfDiagnosticJsonUnchanged(artificerTaskId, artificerTask.diagnosticJson ?? null, {
|
|
1020
1255
|
diagnosticJson: createPITaskDiagnosticJson(merged),
|
|
@@ -1027,6 +1262,9 @@ export class InternalizationOrchestrator {
|
|
|
1027
1262
|
expectedMaxAttempts: artificerTask.maxAttempts,
|
|
1028
1263
|
expectedLeaseOwner: artificerTask.leaseOwner ?? null,
|
|
1029
1264
|
expectedLeaseExpiresAt: artificerTask.leaseExpiresAt ?? null,
|
|
1265
|
+
// PRI-1293 R7 (P2-3): leaseOwner/leaseExpiresAt 相同的重租场景只有
|
|
1266
|
+
// leaseGeneration 单调递增可区分 — 缺失此前提则旧 CAS 会覆盖新租约。
|
|
1267
|
+
expectedLeaseGeneration: artificerTask.leaseGeneration ?? 0,
|
|
1030
1268
|
});
|
|
1031
1269
|
if (updated) {
|
|
1032
1270
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'reopened', recordedAt: new Date().toISOString() });
|
|
@@ -1037,7 +1275,7 @@ export class InternalizationOrchestrator {
|
|
|
1037
1275
|
// 真实漂移被守卫重新分类,不再误记终态 conflict。
|
|
1038
1276
|
const current = await this.stateManager.getTask(artificerTaskId);
|
|
1039
1277
|
const currentPi = current ? hydratePITaskRecord(current) : null;
|
|
1040
|
-
if (currentPi && currentPi
|
|
1278
|
+
if (currentPi && hasConsumedRevisionCause(currentPi, causeId)) {
|
|
1041
1279
|
await this.recordSourceCorrectionOutcome(scribeTaskId, { kind: 'reopened_earlier', recordedAt: new Date().toISOString() });
|
|
1042
1280
|
return { decision: 'source_correction_reopen_noop', sourceTaskId: scribeTaskId, reopenedTaskId: artificerTaskId, reason: 'concurrent_writer_materialized_same_cause' };
|
|
1043
1281
|
}
|
|
@@ -1074,25 +1312,57 @@ export class InternalizationOrchestrator {
|
|
|
1074
1312
|
}
|
|
1075
1313
|
}
|
|
1076
1314
|
/**
|
|
1077
|
-
* Find
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1315
|
+
* Find the logical successor by (parentTaskId, successorKind, channel) across
|
|
1316
|
+
* ALL task statuses — the lineage-truth counterpart of the derived-id lookup.
|
|
1317
|
+
*
|
|
1318
|
+
* Successor identity is the parentage relation, not the derived id:
|
|
1319
|
+
* - revision reopen backfills the recovered correlationId into the source,
|
|
1320
|
+
* shifting the derivation root away from the persisted id (PRI-1293 R2);
|
|
1321
|
+
* - the RuleHost synchronous chain persists timestamp-suffixed ids that the
|
|
1322
|
+
* deterministic derivation never reproduces (PRI-1293 R3).
|
|
1323
|
+
* ANY persisted row — in-flight (pending/leased/retry_wait), terminal
|
|
1324
|
+
* (succeeded/needs_human_review) or failed — proves the logical successor
|
|
1325
|
+
* already exists. This mirrors the semantics the deterministic-id UNIQUE
|
|
1326
|
+
* constraint catch used to provide as a last resort, extended to chains
|
|
1327
|
+
* whose ids are not derivable. Deterministic: ties break by taskId.
|
|
1080
1328
|
*/
|
|
1081
|
-
async
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1329
|
+
async findSuccessorByParent(parentTaskId, successorKind, channel) {
|
|
1330
|
+
// PRI-1293 R5 (F4 部分缓解): taskKind 过滤下推至 SQL WHERE task_kind = ?
|
|
1331
|
+
// (sqlite-task-store 既有能力), 扫描行数从全表收敛到单一 kind。
|
|
1332
|
+
// parentTaskId 的 json_extract 下推与批量复合索引属 PRI-1299 范围
|
|
1333
|
+
// (统一 Successor Lookup) — 本处是有界缓解而非完整修复。
|
|
1334
|
+
const allTasks = await this.stateManager.listTasks({ statuses: [...PD_TASK_STATUSES], taskKind: successorKind });
|
|
1335
|
+
const matches = [];
|
|
1336
|
+
for (const task of allTasks) {
|
|
1086
1337
|
if (task.taskKind !== successorKind)
|
|
1087
1338
|
continue;
|
|
1088
1339
|
const piTask = hydratePITaskRecord(task);
|
|
1089
1340
|
if (!piTask)
|
|
1090
1341
|
continue;
|
|
1091
1342
|
if (piTask.parentTaskId === parentTaskId && piTask.channel === channel) {
|
|
1092
|
-
|
|
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
|
+
}
|
|
1093
1362
|
}
|
|
1094
1363
|
}
|
|
1095
|
-
|
|
1364
|
+
matches.sort((a, b) => (a.taskId < b.taskId ? -1 : a.taskId > b.taskId ? 1 : 0));
|
|
1365
|
+
return matches;
|
|
1096
1366
|
}
|
|
1097
1367
|
/**
|
|
1098
1368
|
* Find candidate PI tasks by querying pending and retry_wait statuses.
|