create-principles-disciple 1.152.2 → 1.152.4
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/pd-hook.js +34 -4
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/config/pd-config-store.d.ts +48 -0
- package/console/dist/server/config/pd-config-store.js +273 -93
- package/console/dist/server/index.js +16 -1
- package/console/dist/server/models/ActivationsConsoleModel.d.ts +72 -1
- package/console/dist/server/models/ActivationsConsoleModel.js +92 -14
- package/console/dist/server/models/AdaptiveActivationConsoleModel.d.ts +79 -0
- package/console/dist/server/models/AdaptiveActivationConsoleModel.js +151 -0
- package/console/dist/server/models/ApprovalsConsoleModel.d.ts +28 -0
- package/console/dist/server/models/ApprovalsConsoleModel.js +118 -3
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.d.ts +38 -0
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +158 -26
- package/console/dist/server/models/IntentDecisionModel.d.ts +6 -1
- package/console/dist/server/models/IntentDecisionModel.js +17 -9
- package/console/dist/server/models/pipeline-health-metrics.d.ts +128 -0
- package/console/dist/server/models/pipeline-health-metrics.js +225 -0
- package/console/dist/server/routes/approvals.js +14 -0
- package/console/dist/server/routes/config.js +212 -1
- package/console/dist/server/routes/diagnostician.js +13 -2
- package/console/dist/server/routes/intent-decisions.js +19 -1
- package/console/dist/server/routes/pipeline-health.d.ts +9 -0
- package/console/dist/server/routes/pipeline-health.js +124 -0
- package/console/dist/web/assets/app.css +484 -67
- package/console/dist/web/assets/app.js +36 -31
- package/console/dist/web/assets/evidence-art-1.webp +0 -0
- package/console/dist/web/assets/evidence-art-2.webp +0 -0
- package/console/dist/web/assets/evidence-art-3.webp +0 -0
- package/console/dist/web/assets/evidence-art-4.webp +0 -0
- package/console/dist/web/assets/principle-grove.jpg +0 -0
- package/console/dist/web/assets/principle-stone-steps.jpg +0 -0
- package/console/dist/web/assets/principles-art-1.webp +0 -0
- package/console/dist/web/assets/principles-art-2.webp +0 -0
- package/console/dist/web/assets/principles-art-3.webp +0 -0
- package/console/dist/web/assets/principles-art-4.webp +0 -0
- package/console/dist/web/assets/today-art-1.webp +0 -0
- package/console/dist/web/assets/today-art-2.webp +0 -0
- package/console/dist/web/assets/today-art-3.webp +0 -0
- package/console/dist/web/assets/today-art-4.webp +0 -0
- package/core/dist/runtime/activation/activation-types.d.ts +6 -0
- package/core/dist/runtime/activation/activation-types.d.ts.map +1 -1
- package/core/dist/runtime/activation/activation-types.js.map +1 -1
- package/core/dist/runtime/activation/index.d.ts +2 -1
- package/core/dist/runtime/activation/index.d.ts.map +1 -1
- package/core/dist/runtime/activation/index.js +1 -1
- package/core/dist/runtime/activation/index.js.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.d.ts +8 -0
- package/core/dist/runtime/activation/ledger-identity.d.ts.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.js +20 -1
- package/core/dist/runtime/activation/ledger-identity.js.map +1 -1
- package/core/dist/runtime/activation/sqlite-approval-store.d.ts +18 -0
- package/core/dist/runtime/activation/sqlite-approval-store.d.ts.map +1 -1
- package/core/dist/runtime/activation/sqlite-approval-store.js +146 -20
- package/core/dist/runtime/activation/sqlite-approval-store.js.map +1 -1
- package/core/dist/runtime/adapter/artificer-l2-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/artificer-l2-adapter.js +11 -4
- package/core/dist/runtime/adapter/artificer-l2-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.js +11 -4
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/output-repair-contract.d.ts +21 -1
- package/core/dist/runtime/adapter/output-repair-contract.d.ts.map +1 -1
- package/core/dist/runtime/adapter/output-repair-contract.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-catalog.d.ts +42 -0
- package/core/dist/runtime/adapter/pi-ai-catalog.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-catalog.js +68 -0
- package/core/dist/runtime/adapter/pi-ai-catalog.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts +45 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts.map +1 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.js +321 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.js.map +1 -0
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +27 -2
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +71 -10
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/schema-prompt-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/schema-prompt-adapter.js +39 -6
- package/core/dist/runtime/adapter/schema-prompt-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/structured-output-repair.d.ts +26 -0
- package/core/dist/runtime/adapter/structured-output-repair.d.ts.map +1 -1
- package/core/dist/runtime/adapter/structured-output-repair.js +140 -2
- package/core/dist/runtime/adapter/structured-output-repair.js.map +1 -1
- package/core/dist/runtime/config/execution-timing.d.ts +56 -0
- package/core/dist/runtime/config/execution-timing.d.ts.map +1 -0
- package/core/dist/runtime/config/execution-timing.js +76 -0
- package/core/dist/runtime/config/execution-timing.js.map +1 -0
- package/core/dist/runtime/config/index.d.ts +4 -0
- package/core/dist/runtime/config/index.d.ts.map +1 -1
- package/core/dist/runtime/config/index.js +2 -0
- package/core/dist/runtime/config/index.js.map +1 -1
- package/core/dist/runtime/config/pd-config-redaction.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-redaction.js +4 -0
- package/core/dist/runtime/config/pd-config-redaction.js.map +1 -1
- package/core/dist/runtime/config/pd-config-types.d.ts +5 -0
- package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-types.js.map +1 -1
- package/core/dist/runtime/config/pd-credentials.d.ts +105 -0
- package/core/dist/runtime/config/pd-credentials.d.ts.map +1 -0
- package/core/dist/runtime/config/pd-credentials.js +409 -0
- package/core/dist/runtime/config/pd-credentials.js.map +1 -0
- package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts +13 -2
- package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician/diag-rootcause-output.js.map +1 -1
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.d.ts +45 -0
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.d.ts.map +1 -0
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.js +74 -0
- package/core/dist/runtime/diagnostician/diagnostic-context-budget.js.map +1 -0
- package/core/dist/runtime/diagnostician/prompt-projection.d.ts +51 -0
- package/core/dist/runtime/diagnostician/prompt-projection.d.ts.map +1 -0
- package/core/dist/runtime/diagnostician/prompt-projection.js +192 -0
- package/core/dist/runtime/diagnostician/prompt-projection.js.map +1 -0
- package/core/dist/runtime/diagnostician-output.d.ts +1 -1
- package/core/dist/runtime/diagnostician-output.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician-output.js +2 -2
- package/core/dist/runtime/diagnostician-output.js.map +1 -1
- package/core/dist/runtime/index.d.ts +5 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +11 -1
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/intent/index.d.ts +2 -0
- package/core/dist/runtime/intent/index.d.ts.map +1 -1
- package/core/dist/runtime/intent/index.js +2 -0
- package/core/dist/runtime/intent/index.js.map +1 -1
- package/core/dist/runtime/intent/intent-decision-record.d.ts +51 -3
- package/core/dist/runtime/intent/intent-decision-record.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.d.ts +104 -0
- package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -0
- package/core/dist/runtime/intent/intent-snapshot.js +164 -0
- package/core/dist/runtime/intent/intent-snapshot.js.map +1 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.d.ts +70 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.d.ts.map +1 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.js +148 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.js.map +1 -0
- package/core/dist/runtime/internalization/artificer-runner.js +1 -1
- package/core/dist/runtime/internalization/artificer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-distiller-runner.d.ts +6 -0
- package/core/dist/runtime/internalization/diag-distiller-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-distiller-runner.js +62 -5
- package/core/dist/runtime/internalization/diag-distiller-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +41 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.js +190 -43
- package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.d.ts +6 -0
- package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.js +114 -69
- package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
- package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/dreamer-prompt-builder.js +3 -0
- package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/dreamer-runner.js +1 -1
- package/core/dist/runtime/internalization/dreamer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/evaluator-runner.js +4 -4
- package/core/dist/runtime/internalization/evaluator-runner.js.map +1 -1
- package/core/dist/runtime/internalization/formation-context.d.ts +54 -0
- package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
- package/core/dist/runtime/internalization/formation-context.js +135 -3
- package/core/dist/runtime/internalization/formation-context.js.map +1 -1
- package/core/dist/runtime/internalization/index.d.ts +2 -2
- package/core/dist/runtime/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime/internalization/index.js +1 -1
- package/core/dist/runtime/internalization/index.js.map +1 -1
- package/core/dist/runtime/internalization/intent-contract.d.ts +107 -0
- package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
- package/core/dist/runtime/internalization/intent-contract.js +315 -4
- package/core/dist/runtime/internalization/intent-contract.js.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +8 -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/philosopher-prompt-builder.d.ts +22 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.js +22 -3
- package/core/dist/runtime/internalization/philosopher-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/philosopher-runner.d.ts +15 -0
- package/core/dist/runtime/internalization/philosopher-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/philosopher-runner.js +74 -2
- package/core/dist/runtime/internalization/philosopher-runner.js.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts +32 -0
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.js +44 -0
- package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +6 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +31 -15
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-output.d.ts +21 -0
- package/core/dist/runtime/internalization/scribe-output.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-output.js +125 -2
- package/core/dist/runtime/internalization/scribe-output.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +26 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.js +33 -3
- package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.d.ts +32 -2
- package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.js +106 -8
- package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts +46 -0
- package/core/dist/runtime/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/split-diagnostician-runner.js +220 -20
- package/core/dist/runtime/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime/internalization-integrity-remediation.d.ts +7 -0
- package/core/dist/runtime/internalization-integrity-remediation.d.ts.map +1 -1
- package/core/dist/runtime/internalization-integrity-remediation.js +44 -12
- package/core/dist/runtime/internalization-integrity-remediation.js.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-runtime-factory.js +25 -4
- package/core/dist/runtime/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.js +5 -5
- package/core/dist/runtime/pain-submit-capability.js.map +1 -1
- package/core/dist/runtime/runner/base-peer-runner.d.ts +90 -2
- package/core/dist/runtime/runner/base-peer-runner.d.ts.map +1 -1
- package/core/dist/runtime/runner/base-peer-runner.js +463 -170
- package/core/dist/runtime/runner/base-peer-runner.js.map +1 -1
- package/core/dist/runtime/runner/peer-runner-types.d.ts +19 -0
- package/core/dist/runtime/runner/peer-runner-types.d.ts.map +1 -1
- package/core/dist/runtime/runtime-protocol.d.ts +19 -0
- package/core/dist/runtime/runtime-protocol.d.ts.map +1 -1
- package/core/dist/runtime/signal-collector/llm-stage.d.ts +5 -0
- package/core/dist/runtime/signal-collector/llm-stage.d.ts.map +1 -1
- package/core/dist/runtime/signal-collector/llm-stage.js.map +1 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts +14 -0
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts.map +1 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js +16 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js.map +1 -1
- package/core/dist/runtime/store/commit/diagnostician-committer.d.ts +19 -0
- package/core/dist/runtime/store/commit/diagnostician-committer.d.ts.map +1 -1
- package/core/dist/runtime/store/commit/diagnostician-committer.js +11 -0
- package/core/dist/runtime/store/commit/diagnostician-committer.js.map +1 -1
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts +2 -2
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js +285 -35
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js.map +1 -1
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.d.ts +64 -0
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.d.ts.map +1 -0
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.js +231 -0
- package/core/dist/runtime/store/lifecycle/fenced-task-writer.js.map +1 -0
- package/core/dist/runtime/store/lifecycle/index.d.ts +2 -0
- package/core/dist/runtime/store/lifecycle/index.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/index.js +1 -0
- package/core/dist/runtime/store/lifecycle/index.js.map +1 -1
- package/core/dist/runtime/store/lifecycle/lease-fence.d.ts +80 -0
- package/core/dist/runtime/store/lifecycle/lease-fence.d.ts.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-fence.js +79 -0
- package/core/dist/runtime/store/lifecycle/lease-fence.js.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.d.ts +118 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.d.ts.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.js +187 -0
- package/core/dist/runtime/store/lifecycle/lease-heartbeat.js.map +1 -0
- package/core/dist/runtime/store/lifecycle/lease-manager.d.ts +30 -20
- package/core/dist/runtime/store/lifecycle/lease-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/lease-manager.js +94 -53
- package/core/dist/runtime/store/lifecycle/lease-manager.js.map +1 -1
- package/core/dist/runtime/store/lifecycle/recovery-sweep.d.ts.map +1 -1
- package/core/dist/runtime/store/lifecycle/recovery-sweep.js +32 -15
- package/core/dist/runtime/store/lifecycle/recovery-sweep.js.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts +29 -0
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.js +40 -0
- package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.d.ts +64 -10
- package/core/dist/runtime/store/runtime-state-manager.d.ts.map +1 -1
- package/core/dist/runtime/store/runtime-state-manager.js +154 -89
- package/core/dist/runtime/store/runtime-state-manager.js.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.js +73 -4
- package/core/dist/runtime/store/sqlite-connection.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 +6 -3
- package/core/dist/runtime/store/task/sqlite-task-store.js.map +1 -1
- package/core/dist/runtime/task-status.d.ts +16 -0
- package/core/dist/runtime/task-status.d.ts.map +1 -1
- package/core/dist/runtime/task-status.js +8 -0
- package/core/dist/runtime/task-status.js.map +1 -1
- package/core/dist/runtime/trajectory-schema.d.ts.map +1 -1
- package/core/dist/runtime/trajectory-schema.js +20 -1
- package/core/dist/runtime/trajectory-schema.js.map +1 -1
- package/core/dist/runtime/types/event-types.d.ts +20 -0
- package/core/dist/runtime/types/event-types.d.ts.map +1 -1
- package/core/dist/runtime/types/event-types.js +7 -0
- package/core/dist/runtime/types/event-types.js.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 +27 -2
- package/core/dist/telemetry-event.js.map +1 -1
- package/core/dist/trajectory-types.d.ts +33 -0
- package/core/dist/trajectory-types.d.ts.map +1 -1
- package/core/package.json +1 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +12 -5
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +9 -12
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/host-runtime/dist/adaptive-consumer-schedule.d.ts +103 -0
- package/host-runtime/dist/adaptive-consumer-schedule.js +145 -0
- package/host-runtime/dist/adaptive-priority-provider.d.ts +7 -1
- package/host-runtime/dist/adaptive-priority-provider.js +6 -3
- package/host-runtime/dist/adaptive-selection.d.ts +1 -1
- package/host-runtime/dist/adaptive-selection.js +2 -1
- package/host-runtime/dist/degraded-enforcement-marker.d.ts +35 -0
- package/host-runtime/dist/degraded-enforcement-marker.js +79 -0
- package/host-runtime/dist/index.d.ts +2 -0
- package/host-runtime/dist/index.js +8 -0
- package/host-runtime/dist/internalization-consumer-cycle.d.ts +35 -0
- package/host-runtime/dist/internalization-consumer-cycle.js +51 -17
- package/host-runtime/dist/prompt-activation-deliverability.d.ts +10 -0
- package/host-runtime/dist/prompt-activation-deliverability.js +5 -2
- package/host-runtime/dist/prompt-injection-event-evidence.d.ts +34 -0
- package/host-runtime/dist/prompt-injection-event-evidence.js +96 -0
- package/host-runtime/dist/signal-classifier.js +4 -4
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/mcp-binding-contract.js +4 -15
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/health-codex.d.ts.map +1 -1
- package/pd-cli/dist/commands/health-codex.js +26 -1
- package/pd-cli/dist/commands/health-codex.js.map +1 -1
- package/pd-cli/dist/commands/health.d.ts.map +1 -1
- package/pd-cli/dist/commands/health.js +32 -2
- package/pd-cli/dist/commands/health.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +6 -4
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-init.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-init.js +29 -1
- package/pd-cli/dist/commands/runtime-init.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 +9 -14
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +5 -5
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
- package/pd-cli/dist/commands/runtime-usage.d.ts +62 -0
- package/pd-cli/dist/commands/runtime-usage.d.ts.map +1 -0
- package/pd-cli/dist/commands/runtime-usage.js +315 -0
- package/pd-cli/dist/commands/runtime-usage.js.map +1 -0
- package/pd-cli/dist/commands/runtime.js +6 -6
- package/pd-cli/dist/commands/runtime.js.map +1 -1
- package/pd-cli/dist/index.d.ts.map +1 -1
- package/pd-cli/dist/index.js +51 -17
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/program.d.ts.map +1 -1
- package/pd-cli/dist/program.js +4 -0
- package/pd-cli/dist/program.js.map +1 -1
- package/pd-cli/dist/services/cli-invocation-log.d.ts +66 -0
- package/pd-cli/dist/services/cli-invocation-log.d.ts.map +1 -0
- package/pd-cli/dist/services/cli-invocation-log.js +139 -0
- package/pd-cli/dist/services/cli-invocation-log.js.map +1 -0
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
- package/pd-cli/dist/services/config-doctor.js +5 -4
- package/pd-cli/dist/services/config-doctor.js.map +1 -1
- package/pd-cli/dist/services/demo-story-a-runner.d.ts.map +1 -1
- package/pd-cli/dist/services/demo-story-a-runner.js +6 -2
- package/pd-cli/dist/services/demo-story-a-runner.js.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.d.ts +3 -1
- package/pd-cli/dist/services/pd-config-loader.d.ts.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.js +20 -8
- package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.js +5 -5
- package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +632 -536
- package/plugin/dist/core/signal-collector-host.d.ts +5 -0
- package/plugin/dist/governance-audit.js +2 -2
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +13 -10
- package/plugin/dist/service/internalization-auto-consumer-service.d.ts +2 -1
- package/plugin/dist/templates/langs/en/skills/pd-pain-signal/SKILL.md +1 -1
- package/plugin/dist/templates/langs/zh/skills/pd-pain-signal/SKILL.md +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/plugin/templates/langs/en/skills/pd-pain-signal/SKILL.md +1 -1
- package/plugin/templates/langs/zh/skills/pd-pain-signal/SKILL.md +1 -1
- package/release-manager/dist/installer.js +12 -5
- package/release-manager/dist/installers/codex-host-installer.js +9 -12
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +1 -1
- package/dist/installers/mcp-binding-shape-mirror.d.ts +0 -27
- package/dist/installers/mcp-binding-shape-mirror.d.ts.map +0 -1
- package/dist/installers/mcp-binding-shape-mirror.js +0 -105
- package/dist/installers/mcp-binding-shape-mirror.js.map +0 -1
- package/release-manager/dist/installers/mcp-binding-shape-mirror.js +0 -105
|
@@ -25,6 +25,9 @@ import { RunnerPhase } from './runner-phase.js';
|
|
|
25
25
|
import { computeFeatureFlagsFromConfig, isFeatureEnabled } from '../config/pd-config-feature-flags.js';
|
|
26
26
|
import { redactAbsolutePaths, redactTokenLikeValues, redactEnvLikeValues, redactSensitiveFields, redactTelemetryString, } from '../feedback/redact-sensitive.js';
|
|
27
27
|
import { safeStringifyPreview } from '../adapter/output-repair-contract.js';
|
|
28
|
+
import { DEFAULT_EXECUTION_TIMING, resolveExecutionTiming, } from '../config/execution-timing.js';
|
|
29
|
+
import { LeaseHeartbeat } from '../store/lifecycle/lease-heartbeat.js';
|
|
30
|
+
import { leaseFenceOf } from '../store/lifecycle/lease-fence.js';
|
|
28
31
|
// ── Defaults ─────────────────────────────────────────────────────────────────
|
|
29
32
|
/**
|
|
30
33
|
* P1-3: bounded per-attempt validator-error history. Kept small because it is
|
|
@@ -68,23 +71,39 @@ function readValidatorErrorHistory(raw) {
|
|
|
68
71
|
return [];
|
|
69
72
|
return history.filter((entry) => typeof entry === 'object' && entry !== null && !Array.isArray(entry));
|
|
70
73
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
/** Monotonic-by-contract clock used for budget accounting (never wall time). */
|
|
75
|
+
function defaultMonotonicClock() {
|
|
76
|
+
const perf = globalThis.performance;
|
|
77
|
+
return typeof perf?.now === 'function' ? perf.now() : Date.now();
|
|
78
|
+
}
|
|
79
|
+
const DEFAULT_PEER_RUNNER_OPTIONS = { pollIntervalMs: 5_000,
|
|
80
|
+
timeoutMs: DEFAULT_EXECUTION_TIMING.stageTimeoutMs,
|
|
74
81
|
defaultMaxAttempts: 3,
|
|
75
82
|
agentId: 'peer-runner',
|
|
76
83
|
coreGrounding: true,
|
|
84
|
+
leaseTtlMs: DEFAULT_EXECUTION_TIMING.leaseTtlMs,
|
|
85
|
+
heartbeatIntervalMs: DEFAULT_EXECUTION_TIMING.heartbeatIntervalMs,
|
|
77
86
|
};
|
|
78
87
|
function resolvePeerRunnerOptions(options, defaultAgentId) {
|
|
88
|
+
// SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §5.1: one resolver owns the
|
|
89
|
+
// relationship between stage timeout, lease TTL and renewal cadence. The
|
|
90
|
+
// stage timeout can no longer silently equal the lease TTL.
|
|
91
|
+
const timing = resolveExecutionTiming({
|
|
92
|
+
stageTimeoutMs: options.timeoutMs,
|
|
93
|
+
leaseTtlMs: options.leaseTtlMs,
|
|
94
|
+
heartbeatIntervalMs: options.heartbeatIntervalMs,
|
|
95
|
+
});
|
|
79
96
|
return {
|
|
80
97
|
pollIntervalMs: options.pollIntervalMs ?? DEFAULT_PEER_RUNNER_OPTIONS.pollIntervalMs,
|
|
81
|
-
timeoutMs:
|
|
98
|
+
timeoutMs: timing.stageTimeoutMs,
|
|
82
99
|
defaultMaxAttempts: options.defaultMaxAttempts ?? DEFAULT_PEER_RUNNER_OPTIONS.defaultMaxAttempts,
|
|
83
100
|
owner: options.owner,
|
|
84
101
|
runtimeKind: options.runtimeKind,
|
|
85
102
|
agentId: options.agentId ?? defaultAgentId,
|
|
86
103
|
outputLanguage: options.outputLanguage,
|
|
87
104
|
coreGrounding: options.coreGrounding ?? true,
|
|
105
|
+
leaseTtlMs: timing.leaseTtlMs,
|
|
106
|
+
heartbeatIntervalMs: timing.heartbeatIntervalMs,
|
|
88
107
|
};
|
|
89
108
|
}
|
|
90
109
|
// ── BasePeerRunner ───────────────────────────────────────────────────────────
|
|
@@ -101,6 +120,12 @@ export class BasePeerRunner {
|
|
|
101
120
|
eventEmitter;
|
|
102
121
|
artifactStore;
|
|
103
122
|
resolvedOptions;
|
|
123
|
+
/**
|
|
124
|
+
* Effective execution timing for this runner (SPEC-PD-PIPELINE-RELIABILITY-
|
|
125
|
+
* AND-EFFICIENCY-001 §5.1). Exposed so subclasses (e.g. the split
|
|
126
|
+
* diagnostician orchestrator) share the exact same budgets.
|
|
127
|
+
*/
|
|
128
|
+
executionTiming;
|
|
104
129
|
config;
|
|
105
130
|
/**
|
|
106
131
|
* Optional store for agent-authored draft context (Task 12).
|
|
@@ -116,6 +141,22 @@ export class BasePeerRunner {
|
|
|
116
141
|
* 覆盖 lastValidatorErrors,rc-7)。
|
|
117
142
|
*/
|
|
118
143
|
currentLeasedAttempt;
|
|
144
|
+
/**
|
|
145
|
+
* The identity of the acquisition this execution holds
|
|
146
|
+
* (SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §5.3). Every terminal /
|
|
147
|
+
* failure / diagnostic write carries it; a subclass that writes without it
|
|
148
|
+
* cannot compile against the fenced manager API.
|
|
149
|
+
*/
|
|
150
|
+
leaseFence = null;
|
|
151
|
+
/** The run created by THIS acquisition — never "the latest run". */
|
|
152
|
+
executionRunId = null;
|
|
153
|
+
/**
|
|
154
|
+
* Absolute monotonic deadline for a parent-budgeted execution
|
|
155
|
+
* (SPEC §5.1). Set by `runWithDeadline`; `undefined` means "stage budget
|
|
156
|
+
* only".
|
|
157
|
+
*/
|
|
158
|
+
parentDeadlineMonotonic;
|
|
159
|
+
monotonicClock;
|
|
119
160
|
constructor(deps, options, config) {
|
|
120
161
|
this.stateManager = deps.stateManager;
|
|
121
162
|
this.runtimeAdapter = deps.runtimeAdapter;
|
|
@@ -123,7 +164,14 @@ export class BasePeerRunner {
|
|
|
123
164
|
this.artifactStore = deps.artifactStore;
|
|
124
165
|
this.pendingAgentDraftStore = deps.pendingAgentDraftStore;
|
|
125
166
|
this.config = config;
|
|
167
|
+
this.monotonicClock = deps.monotonicClock ?? defaultMonotonicClock;
|
|
126
168
|
this.resolvedOptions = resolvePeerRunnerOptions(options, config.defaultAgentId);
|
|
169
|
+
this.executionTiming = {
|
|
170
|
+
stageTimeoutMs: this.resolvedOptions.timeoutMs,
|
|
171
|
+
parentBudgetMs: resolveExecutionTiming({ stageTimeoutMs: this.resolvedOptions.timeoutMs }).parentBudgetMs,
|
|
172
|
+
leaseTtlMs: this.resolvedOptions.leaseTtlMs,
|
|
173
|
+
heartbeatIntervalMs: this.resolvedOptions.heartbeatIntervalMs,
|
|
174
|
+
};
|
|
127
175
|
}
|
|
128
176
|
// ── Observability ──────────────────────────────────────────────────────────
|
|
129
177
|
/** Current internal phase. For testing/observability only. */
|
|
@@ -221,53 +269,93 @@ export class BasePeerRunner {
|
|
|
221
269
|
* Each invocation is independent — no mutable state between run() calls.
|
|
222
270
|
*/
|
|
223
271
|
async run(taskId) {
|
|
272
|
+
return this.runInternal(taskId, undefined);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Execute with a PARENT budget (SPEC §5.1). The deadline is created once by
|
|
276
|
+
* the orchestrator and passed down unchanged: a stage never re-earns a full
|
|
277
|
+
* parent budget, and the remaining time is recomputed before every expensive
|
|
278
|
+
* step (invoke, poll bound, commit). A deadline that has already passed
|
|
279
|
+
* refuses to start.
|
|
280
|
+
*/
|
|
281
|
+
async runWithDeadline(taskId, parentDeadlineMonotonic) {
|
|
282
|
+
return this.runInternal(taskId, parentDeadlineMonotonic);
|
|
283
|
+
}
|
|
284
|
+
async runInternal(taskId, parentDeadlineMonotonic) {
|
|
224
285
|
this.phase = RunnerPhase.Idle;
|
|
286
|
+
this.leaseFence = null;
|
|
287
|
+
this.executionRunId = null;
|
|
288
|
+
this.parentDeadlineMonotonic = parentDeadlineMonotonic;
|
|
225
289
|
const runtimeKind = this.getRuntimeKind();
|
|
290
|
+
if (this.parentDeadlineMonotonic !== undefined && this.remainingParentBudgetMs() <= 0) {
|
|
291
|
+
return {
|
|
292
|
+
status: 'failed',
|
|
293
|
+
taskId,
|
|
294
|
+
errorCategory: 'timeout',
|
|
295
|
+
failureReason: 'Parent execution budget exhausted before the stage started',
|
|
296
|
+
attemptCount: 1,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
226
299
|
// 1. Acquire lease — isolated try/catch so lease_conflict never uses synthetic TaskRecord
|
|
227
|
-
let
|
|
300
|
+
let acquisition;
|
|
228
301
|
try {
|
|
229
|
-
|
|
302
|
+
acquisition = await this.stateManager.acquireLeaseDetailed({
|
|
230
303
|
taskId,
|
|
231
304
|
owner: this.resolvedOptions.owner,
|
|
232
305
|
runtimeKind,
|
|
306
|
+
// SPEC-PD-PIPELINE-RELIABILITY-AND-EFFICIENCY-001 §5.2: the lease is a
|
|
307
|
+
// heartbeat-sustained window, not the stage's maximum duration.
|
|
308
|
+
durationMs: this.executionTiming.leaseTtlMs,
|
|
233
309
|
});
|
|
234
310
|
}
|
|
235
311
|
catch (error) {
|
|
236
312
|
return await this.handleLeaseOrPhaseError(taskId, error);
|
|
237
313
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
status: 'failed',
|
|
247
|
-
taskId,
|
|
248
|
-
errorCategory: 'input_invalid',
|
|
249
|
-
failureReason: `Task kind must be '${this.config.expectedTaskKind}', got '${leasedTask.taskKind}'`,
|
|
250
|
-
attemptCount: leasedTask.attemptCount,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
this.emitEvent('task_leased', taskId, {
|
|
254
|
-
taskKind: this.config.expectedTaskKind,
|
|
255
|
-
attemptCount: leasedTask.attemptCount,
|
|
256
|
-
});
|
|
257
|
-
// 1c. P0 (verdict drift) — completion-intent resume gate. A pending durable
|
|
258
|
-
// completion intent from the SAME revision epoch is the recovery authority:
|
|
259
|
-
// its effects are resumed idempotently; the LLM is NOT re-invoked, so a
|
|
260
|
-
// non-deterministic re-run can never drift the verdict against side
|
|
261
|
-
// effects that already happened (activation / repair seed / validation).
|
|
262
|
-
const resumed = await this.maybeResumePendingIntent(taskId, leasedTask);
|
|
263
|
-
if (resumed) {
|
|
264
|
-
this.phase = RunnerPhase.Completed;
|
|
265
|
-
return resumed;
|
|
266
|
-
}
|
|
267
|
-
// All subsequent errors use the real leasedTask — no synthetic TaskRecord allowed
|
|
314
|
+
const leasedTask = acquisition.task;
|
|
315
|
+
this.bindExecutionIdentity(leasedTask, acquisition.runId);
|
|
316
|
+
// SPEC §5.2: renewal starts as soon as THIS execution owns the lease.
|
|
317
|
+
// The task-kind validation and the completion-intent resume are already
|
|
318
|
+
// part of the execution window: starting renewal only afterwards left
|
|
319
|
+
// those steps running on a lease that could silently expire (and their
|
|
320
|
+
// writes outside the renewal window).
|
|
321
|
+
const heartbeat = this.startLeaseHeartbeat(taskId, this.leaseFence);
|
|
268
322
|
try {
|
|
269
|
-
//
|
|
270
|
-
|
|
323
|
+
// 1b. Validate task kind
|
|
324
|
+
if (leasedTask.taskKind !== this.config.expectedTaskKind) {
|
|
325
|
+
this.emitEvent('wrong_task_kind', taskId, {
|
|
326
|
+
expectedKind: this.config.expectedTaskKind,
|
|
327
|
+
actualKind: leasedTask.taskKind,
|
|
328
|
+
});
|
|
329
|
+
await this.markFailedFenced({ taskId, errorCategory: 'input_invalid' });
|
|
330
|
+
return {
|
|
331
|
+
status: 'failed',
|
|
332
|
+
taskId,
|
|
333
|
+
errorCategory: 'input_invalid',
|
|
334
|
+
failureReason: `Task kind must be '${this.config.expectedTaskKind}', got '${leasedTask.taskKind}'`,
|
|
335
|
+
attemptCount: leasedTask.attemptCount,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
this.emitEvent('task_leased', taskId, {
|
|
339
|
+
taskKind: this.config.expectedTaskKind,
|
|
340
|
+
attemptCount: leasedTask.attemptCount,
|
|
341
|
+
});
|
|
342
|
+
// 1c. P0 (verdict drift) — completion-intent resume gate. A pending durable
|
|
343
|
+
// completion intent from the SAME revision epoch is the recovery authority:
|
|
344
|
+
// its effects are resumed idempotently; the LLM is NOT re-invoked, so a
|
|
345
|
+
// non-deterministic re-run can never drift the verdict against side
|
|
346
|
+
// effects that already happened (activation / repair seed / validation).
|
|
347
|
+
// SPEC §5.2: the heartbeat is already running while this gate replays
|
|
348
|
+
// durable effects, so a slow resume can no longer consume the lease
|
|
349
|
+
// unreserved. Every terminal/effect write the resume performs goes
|
|
350
|
+
// through the fenced writer (§5.3), which is what actually prevents a
|
|
351
|
+
// superseded worker from stamping its result onto the new execution.
|
|
352
|
+
const resumed = await this.maybeResumePendingIntent(taskId, leasedTask);
|
|
353
|
+
if (resumed) {
|
|
354
|
+
this.phase = RunnerPhase.Completed;
|
|
355
|
+
return resumed;
|
|
356
|
+
}
|
|
357
|
+
// 2. Resolve store runId — the one created by THIS acquisition.
|
|
358
|
+
const storeRunId = this.requireExecutionRunId();
|
|
271
359
|
// 3. Build context
|
|
272
360
|
this.phase = RunnerPhase.BuildingContext;
|
|
273
361
|
this.currentLeasedAttempt = leasedTask.attemptCount;
|
|
@@ -275,6 +363,7 @@ export class BasePeerRunner {
|
|
|
275
363
|
this.emitEvent('context_built', taskId, { contextHash: context.contextHash });
|
|
276
364
|
// 4. Invoke runtime
|
|
277
365
|
this.phase = RunnerPhase.Invoking;
|
|
366
|
+
this.assertParentBudget('before runtime invocation');
|
|
278
367
|
const runHandle = await this.invokeRuntime(taskId, context);
|
|
279
368
|
const invocationInputPayload = this.getInvocationInputPayload(context);
|
|
280
369
|
if (invocationInputPayload !== undefined) {
|
|
@@ -331,6 +420,22 @@ export class BasePeerRunner {
|
|
|
331
420
|
this.checkLineageIntegrity(taskId, output, context);
|
|
332
421
|
// 8c. Emit success telemetry (receives validated output)
|
|
333
422
|
this.emitSuccessTelemetry(taskId, output, context);
|
|
423
|
+
// 8d. Ownership fence (SPEC §5.3). A worker whose lease was reclaimed
|
|
424
|
+
// between the last renewal and this commit must not write a terminal
|
|
425
|
+
// success: the result belongs to an execution nobody owns any more.
|
|
426
|
+
// The parent budget is re-checked here too — a result that arrived after
|
|
427
|
+
// the deadline must never be published (SPEC §5.1).
|
|
428
|
+
this.assertParentBudget('before success commit');
|
|
429
|
+
if (!(await heartbeat.assertOwned())) {
|
|
430
|
+
this.emitStaleCommitRejected(taskId, 'before_success_commit');
|
|
431
|
+
return {
|
|
432
|
+
status: 'failed',
|
|
433
|
+
taskId,
|
|
434
|
+
errorCategory: 'lease_conflict',
|
|
435
|
+
failureReason: 'Lease lost before commit; stale success write rejected',
|
|
436
|
+
attemptCount: leasedTask.attemptCount,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
334
439
|
// 9. Succeed task (abstract — subclass implements commit strategy)
|
|
335
440
|
const result = await this.succeedTask(taskId, storeRunId, output, leasedTask, context.contextHash, context);
|
|
336
441
|
if (result.status === 'succeeded') {
|
|
@@ -342,6 +447,220 @@ export class BasePeerRunner {
|
|
|
342
447
|
// Post-lease errors use retryOrFail with the real leasedTask
|
|
343
448
|
return await this.handlePostLeaseError(taskId, leasedTask, error);
|
|
344
449
|
}
|
|
450
|
+
finally {
|
|
451
|
+
await heartbeat.stop();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
// ── Lease heartbeat ────────────────────────────────────────────────────────
|
|
455
|
+
/**
|
|
456
|
+
* Start renewal for the lease this run holds.
|
|
457
|
+
*
|
|
458
|
+
* The heartbeat renews with the SAME owner identity used for acquisition and
|
|
459
|
+
* probes the persisted row at commit time. Its failures are emitted, never
|
|
460
|
+
* swallowed (rc-9): a renewal that cannot prove ownership is a reliability
|
|
461
|
+
* incident, not a background detail.
|
|
462
|
+
*/
|
|
463
|
+
startLeaseHeartbeat(taskId, fence) {
|
|
464
|
+
const timing = this.executionTiming;
|
|
465
|
+
this.eventEmitter.emitTelemetry({
|
|
466
|
+
eventType: 'execution_timing_resolved',
|
|
467
|
+
traceId: taskId,
|
|
468
|
+
timestamp: new Date().toISOString(),
|
|
469
|
+
sessionId: this.resolvedOptions.owner,
|
|
470
|
+
agentId: this.resolvedOptions.agentId,
|
|
471
|
+
payload: {
|
|
472
|
+
stageTimeoutMs: timing.stageTimeoutMs,
|
|
473
|
+
parentBudgetMs: timing.parentBudgetMs,
|
|
474
|
+
leaseTtlMs: timing.leaseTtlMs,
|
|
475
|
+
heartbeatIntervalMs: timing.heartbeatIntervalMs,
|
|
476
|
+
leaseFenceMode: fence ? 'fenced' : 'unfenced_test',
|
|
477
|
+
...(fence ? { leaseGeneration: fence.leaseGeneration } : {}),
|
|
478
|
+
},
|
|
479
|
+
});
|
|
480
|
+
const heartbeat = new LeaseHeartbeat({
|
|
481
|
+
taskId,
|
|
482
|
+
owner: this.resolvedOptions.owner,
|
|
483
|
+
// Production always has a fence. A test double that does not model
|
|
484
|
+
// leases must opt in explicitly — this is the ONLY unfenced path.
|
|
485
|
+
leaseGeneration: fence?.leaseGeneration ?? 0,
|
|
486
|
+
leaseTtlMs: timing.leaseTtlMs,
|
|
487
|
+
intervalMs: timing.heartbeatIntervalMs,
|
|
488
|
+
renewLease: (leaseFence, durationMs) => this.stateManager.renewLease(leaseFence, durationMs),
|
|
489
|
+
...(fence
|
|
490
|
+
? {
|
|
491
|
+
readOwnership: async (id) => {
|
|
492
|
+
const task = await this.stateManager.getTask(id);
|
|
493
|
+
return task
|
|
494
|
+
? {
|
|
495
|
+
status: task.status,
|
|
496
|
+
leaseOwner: task.leaseOwner ?? null,
|
|
497
|
+
leaseGeneration: task.leaseGeneration ?? 0,
|
|
498
|
+
leaseExpiresAt: task.leaseExpiresAt ?? null,
|
|
499
|
+
}
|
|
500
|
+
: null;
|
|
501
|
+
},
|
|
502
|
+
}
|
|
503
|
+
: { unfencedTestMode: true }),
|
|
504
|
+
emit: (event) => this.emitLeaseHeartbeatEvent(taskId, event),
|
|
505
|
+
});
|
|
506
|
+
heartbeat.start();
|
|
507
|
+
return heartbeat;
|
|
508
|
+
}
|
|
509
|
+
/** Bind the acquisition identity this execution writes under (SPEC §5.3). */
|
|
510
|
+
bindExecutionIdentity(task, runId) {
|
|
511
|
+
this.executionRunId = runId;
|
|
512
|
+
this.leaseFence = leaseFenceOf(task);
|
|
513
|
+
}
|
|
514
|
+
/** The runId created by this acquisition; a runner without one cannot commit. */
|
|
515
|
+
requireExecutionRunId() {
|
|
516
|
+
if (!this.executionRunId) {
|
|
517
|
+
throw new PDRuntimeError('execution_failed', 'No execution runId is bound to this runner invocation; refusing to resolve one by "latest run"');
|
|
518
|
+
}
|
|
519
|
+
return this.executionRunId;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* The fence this execution must present on every write.
|
|
523
|
+
*
|
|
524
|
+
* @throws PDRuntimeError{lease_conflict} when the acquisition produced no
|
|
525
|
+
* fence — an unfenced production write is exactly the defect the
|
|
526
|
+
* SPEC remediation removes, and a test double should not be
|
|
527
|
+
* committing artifacts.
|
|
528
|
+
*/
|
|
529
|
+
requireLeaseFence() {
|
|
530
|
+
if (!this.leaseFence) {
|
|
531
|
+
throw new PDRuntimeError('lease_conflict', 'No lease fence is bound to this runner invocation; refusing an unfenced write');
|
|
532
|
+
}
|
|
533
|
+
return this.leaseFence;
|
|
534
|
+
}
|
|
535
|
+
/** Remaining parent budget in ms (Infinity when no parent deadline applies). */
|
|
536
|
+
remainingParentBudgetMs() {
|
|
537
|
+
if (this.parentDeadlineMonotonic === undefined)
|
|
538
|
+
return Number.POSITIVE_INFINITY;
|
|
539
|
+
return this.parentDeadlineMonotonic - this.monotonicClock();
|
|
540
|
+
}
|
|
541
|
+
/** Fail loud when the parent budget is exhausted (SPEC §5.1). */
|
|
542
|
+
assertParentBudget(stage) {
|
|
543
|
+
const remaining = this.remainingParentBudgetMs();
|
|
544
|
+
if (remaining <= 0) {
|
|
545
|
+
throw new PDRuntimeError('timeout', `Parent execution budget exhausted ${stage}; the stage must not continue or commit`, { stage });
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/** Fenced success owned by this execution (subclasses use this, never the raw manager method). */
|
|
549
|
+
async markSucceededFenced(taskId, resultRef, runId = this.requireExecutionRunId()) {
|
|
550
|
+
return this.stateManager.markTaskSucceeded(taskId, resultRef, this.requireLeaseFence(), runId);
|
|
551
|
+
}
|
|
552
|
+
/** Fenced failure owned by this execution. */
|
|
553
|
+
async markFailedFenced(input) {
|
|
554
|
+
const { taskId, errorCategory, failureReason, runId } = input;
|
|
555
|
+
return this.stateManager.markTaskFailed(taskId, errorCategory, failureReason, this.requireLeaseFence(), runId ?? this.requireExecutionRunId());
|
|
556
|
+
}
|
|
557
|
+
emitLeaseHeartbeatEvent(taskId, event) {
|
|
558
|
+
const payload = {
|
|
559
|
+
owner: event.owner,
|
|
560
|
+
renewalCount: event.renewalCount,
|
|
561
|
+
...(event.detail ? { detail: event.detail } : {}),
|
|
562
|
+
};
|
|
563
|
+
// Literal per branch so the telemetry registry can see each name
|
|
564
|
+
// (scripts/check-telemetry-events.cjs cannot resolve a computed ternary).
|
|
565
|
+
if (event.type === 'renewed') {
|
|
566
|
+
this.eventEmitter.emitTelemetry({
|
|
567
|
+
eventType: 'lease_renewed',
|
|
568
|
+
traceId: taskId,
|
|
569
|
+
timestamp: event.occurredAt,
|
|
570
|
+
sessionId: this.resolvedOptions.owner,
|
|
571
|
+
agentId: this.resolvedOptions.agentId,
|
|
572
|
+
payload,
|
|
573
|
+
});
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if (event.type === 'renewal_failed') {
|
|
577
|
+
this.eventEmitter.emitTelemetry({
|
|
578
|
+
eventType: 'lease_renewal_failed',
|
|
579
|
+
traceId: taskId,
|
|
580
|
+
timestamp: event.occurredAt,
|
|
581
|
+
sessionId: this.resolvedOptions.owner,
|
|
582
|
+
agentId: this.resolvedOptions.agentId,
|
|
583
|
+
payload,
|
|
584
|
+
});
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
this.eventEmitter.emitTelemetry({
|
|
588
|
+
eventType: 'lease_ownership_lost',
|
|
589
|
+
traceId: taskId,
|
|
590
|
+
timestamp: event.occurredAt,
|
|
591
|
+
sessionId: this.resolvedOptions.owner,
|
|
592
|
+
agentId: this.resolvedOptions.agentId,
|
|
593
|
+
payload,
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Record that a stale worker tried to write a terminal state after losing its
|
|
598
|
+
* lease. This is the observable proof that fencing worked — without it the
|
|
599
|
+
* guard would silently discard work.
|
|
600
|
+
*/
|
|
601
|
+
emitStaleCommitRejected(taskId, phase) {
|
|
602
|
+
this.eventEmitter.emitTelemetry({
|
|
603
|
+
eventType: 'stale_commit_rejected',
|
|
604
|
+
traceId: taskId,
|
|
605
|
+
timestamp: new Date().toISOString(),
|
|
606
|
+
sessionId: this.resolvedOptions.owner,
|
|
607
|
+
agentId: this.resolvedOptions.agentId,
|
|
608
|
+
payload: { taskId, phase, owner: this.resolvedOptions.owner },
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
/** True when a fenced write was refused because another execution owns the task. */
|
|
612
|
+
// eslint-disable-next-line @typescript-eslint/class-methods-use-this
|
|
613
|
+
isLeaseConflictError(error) {
|
|
614
|
+
return error instanceof PDRuntimeError && error.category === 'lease_conflict';
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* The fenced write was refused: the row now belongs to another execution.
|
|
618
|
+
* Report the loss as a lease conflict instead of claiming this worker's own
|
|
619
|
+
* failure was persisted, and keep the refusal observable (rc-9).
|
|
620
|
+
*/
|
|
621
|
+
staleTerminalWriteResult(ctx, phase) {
|
|
622
|
+
this.emitStaleCommitRejected(ctx.taskId, phase);
|
|
623
|
+
return {
|
|
624
|
+
status: 'failed',
|
|
625
|
+
taskId: ctx.taskId,
|
|
626
|
+
errorCategory: 'lease_conflict',
|
|
627
|
+
failureReason: `Lease lost before ${phase}; the current owner's task state was left untouched. Original failure: ${ctx.failureReason}`,
|
|
628
|
+
attemptCount: ctx.task.attemptCount,
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Classify a refused task/run write. A storage fault and a lost lease are
|
|
633
|
+
* different outcomes: only the former means the task may still expect this
|
|
634
|
+
* worker's transition (SPEC §5.3).
|
|
635
|
+
*/
|
|
636
|
+
terminalWriteFailureResult(ctx, error, write) {
|
|
637
|
+
if (this.isLeaseConflictError(error)) {
|
|
638
|
+
return this.staleTerminalWriteResult(ctx, write.phase);
|
|
639
|
+
}
|
|
640
|
+
// Keep the literal `this.emitEvent('<suffix>'` shape: the telemetry union
|
|
641
|
+
// guard composes `<runnerName>_<suffix>` from it, and a dynamic name here
|
|
642
|
+
// would silently drop both events (ERR-060).
|
|
643
|
+
if (write.isRetryWrite === true) {
|
|
644
|
+
this.emitEvent('mark_retry_error', ctx.taskId, {
|
|
645
|
+
errorCategory: 'storage_unavailable',
|
|
646
|
+
attemptCount: ctx.task.attemptCount,
|
|
647
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
this.emitEvent('mark_failed_error', ctx.taskId, {
|
|
652
|
+
errorCategory: 'storage_unavailable',
|
|
653
|
+
attemptCount: ctx.task.attemptCount,
|
|
654
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
return {
|
|
658
|
+
status: 'failed',
|
|
659
|
+
taskId: ctx.taskId,
|
|
660
|
+
errorCategory: 'storage_unavailable',
|
|
661
|
+
failureReason: `State manager error: ${ctx.failureReason}`,
|
|
662
|
+
attemptCount: ctx.task.attemptCount,
|
|
663
|
+
};
|
|
345
664
|
}
|
|
346
665
|
// ── Telemetry ──────────────────────────────────────────────────────────────
|
|
347
666
|
/**
|
|
@@ -360,9 +679,11 @@ export class BasePeerRunner {
|
|
|
360
679
|
}
|
|
361
680
|
// ── Polling ────────────────────────────────────────────────────────────────
|
|
362
681
|
async pollUntilTerminal(runHandle) {
|
|
363
|
-
|
|
682
|
+
// SPEC §5.1: the stage timeout may never outlive the parent budget.
|
|
683
|
+
const effectiveTimeoutMs = Math.min(this.resolvedOptions.timeoutMs, this.remainingParentBudgetMs());
|
|
684
|
+
const deadline = this.monotonicClock() + effectiveTimeoutMs;
|
|
364
685
|
const terminalStatuses = ['succeeded', 'failed', 'timed_out', 'cancelled'];
|
|
365
|
-
while (
|
|
686
|
+
while (this.monotonicClock() < deadline) {
|
|
366
687
|
const status = await this.runtimeAdapter.pollRun(runHandle.runId);
|
|
367
688
|
if (terminalStatuses.includes(status.status)) {
|
|
368
689
|
return status;
|
|
@@ -377,7 +698,8 @@ export class BasePeerRunner {
|
|
|
377
698
|
}
|
|
378
699
|
}
|
|
379
700
|
catch { /* fall through to cancel/timeout */ }
|
|
380
|
-
// Timeout — cancel gracefully
|
|
701
|
+
// Timeout — cancel gracefully; a provider that cannot cancel is still
|
|
702
|
+
// isolated by the fence (a late result cannot be committed).
|
|
381
703
|
let cancelFailed = false;
|
|
382
704
|
try {
|
|
383
705
|
await this.runtimeAdapter.cancelRun(runHandle.runId);
|
|
@@ -390,7 +712,7 @@ export class BasePeerRunner {
|
|
|
390
712
|
});
|
|
391
713
|
}
|
|
392
714
|
const cancelNote = cancelFailed ? ' (cancelRun also failed)' : '';
|
|
393
|
-
throw new PDRuntimeError('timeout', `Run ${runHandle.runId} timed out after ${
|
|
715
|
+
throw new PDRuntimeError('timeout', `Run ${runHandle.runId} timed out after ${Math.round(effectiveTimeoutMs)}ms${cancelNote}`);
|
|
394
716
|
}
|
|
395
717
|
// ── Output fetching ────────────────────────────────────────────────────────
|
|
396
718
|
/**
|
|
@@ -459,39 +781,6 @@ export class BasePeerRunner {
|
|
|
459
781
|
}
|
|
460
782
|
return { ids: lineageIds, hasRejected };
|
|
461
783
|
}
|
|
462
|
-
// ── Store helpers ──────────────────────────────────────────────────────────
|
|
463
|
-
async resolveStoreRunId(taskId) {
|
|
464
|
-
// Tolerant read: a malformed HISTORICAL run row must not block recovery of
|
|
465
|
-
// a task whose lease just created a fresh valid run. acquireLease always
|
|
466
|
-
// inserts a valid 'running' run in the same transaction, so `runs` is
|
|
467
|
-
// guaranteed non-empty here under normal operation. We observe any
|
|
468
|
-
// degraded rows via telemetry (ERR-002) without throwing.
|
|
469
|
-
const { runs, degradedRuns } = await this.stateManager.getValidRunsByTaskTolerant(taskId);
|
|
470
|
-
if (degradedRuns.length > 0) {
|
|
471
|
-
this.eventEmitter.emitTelemetry({
|
|
472
|
-
eventType: 'degradation_triggered',
|
|
473
|
-
traceId: taskId,
|
|
474
|
-
timestamp: new Date().toISOString(),
|
|
475
|
-
sessionId: this.resolvedOptions.owner,
|
|
476
|
-
agentId: this.resolvedOptions.agentId,
|
|
477
|
-
payload: {
|
|
478
|
-
component: 'BasePeerRunner',
|
|
479
|
-
runnerName: this.config.runnerName,
|
|
480
|
-
trigger: 'malformed_historical_run_rows',
|
|
481
|
-
degradedCount: degradedRuns.length,
|
|
482
|
-
runIds: degradedRuns.map((r) => r.runId),
|
|
483
|
-
errors: degradedRuns.map((r) => r.error),
|
|
484
|
-
nextAction: 'Quarantine malformed run rows: pd runtime internalization integrity-repair --confirm',
|
|
485
|
-
},
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
const latestRun = runs[runs.length - 1];
|
|
489
|
-
if (!latestRun) {
|
|
490
|
-
throw new PDRuntimeError('execution_failed', `No valid run records found for task ${taskId} after lease acquisition. ` +
|
|
491
|
-
`If historical runs are malformed, quarantine them first: pd runtime internalization integrity-repair --confirm`);
|
|
492
|
-
}
|
|
493
|
-
return latestRun.runId;
|
|
494
|
-
}
|
|
495
784
|
/**
|
|
496
785
|
* Compute a deterministic hash from context references (observability only).
|
|
497
786
|
* Public so post-restart evidence reconstruction re-derives the exact same
|
|
@@ -519,30 +808,21 @@ export class BasePeerRunner {
|
|
|
519
808
|
attemptCount: 1,
|
|
520
809
|
};
|
|
521
810
|
}
|
|
522
|
-
//
|
|
523
|
-
//
|
|
811
|
+
// No lease was acquired, so this worker has NO authority to write task
|
|
812
|
+
// state (SPEC §5.3). Leaving the row untouched is the safe outcome: the
|
|
813
|
+
// lease/timeout machinery owns the transition from here.
|
|
524
814
|
this.emitEvent('run_failed', taskId, {
|
|
525
815
|
errorCategory: classified.category,
|
|
526
816
|
errorMessage: classified.message,
|
|
817
|
+
nextAction: 'No lease was held; task state was left unchanged. Recovery will reclaim it after the lease window.',
|
|
527
818
|
});
|
|
528
|
-
|
|
819
|
+
return {
|
|
820
|
+
status: 'failed',
|
|
529
821
|
taskId,
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
createdAt: new Date().toISOString(),
|
|
533
|
-
updatedAt: new Date().toISOString(),
|
|
822
|
+
errorCategory: classified.category,
|
|
823
|
+
failureReason: `${classified.message} (no lease held; task state not mutated)`,
|
|
534
824
|
attemptCount: 1,
|
|
535
|
-
maxAttempts: this.resolvedOptions.defaultMaxAttempts,
|
|
536
825
|
};
|
|
537
|
-
// PRI-559 P0-2: 同步持久化失败详情(若 PDRuntimeError 携带 details)。
|
|
538
|
-
if (classified.details && Object.keys(classified.details).length > 0) {
|
|
539
|
-
await this.persistOutputFailureDetails(taskId, undefined, {
|
|
540
|
-
errorCategory: classified.category,
|
|
541
|
-
errorMessage: classified.message,
|
|
542
|
-
...classified.details,
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
return this.retryOrFail({ taskId, task, errorCategory: classified.category, failureReason: classified.message });
|
|
546
826
|
}
|
|
547
827
|
async handlePostLeaseError(taskId, task, error) {
|
|
548
828
|
const classified = this.classifyError(error);
|
|
@@ -655,21 +935,14 @@ export class BasePeerRunner {
|
|
|
655
935
|
// Permanent errors — never retry
|
|
656
936
|
if (this.permanentErrorCategories.has(ctx.errorCategory)) {
|
|
657
937
|
try {
|
|
658
|
-
await this.
|
|
938
|
+
await this.markFailedFenced({
|
|
939
|
+
taskId: ctx.taskId,
|
|
940
|
+
errorCategory: ctx.errorCategory,
|
|
941
|
+
failureReason: ctx.failureReason,
|
|
942
|
+
});
|
|
659
943
|
}
|
|
660
944
|
catch (stateErr) {
|
|
661
|
-
this.
|
|
662
|
-
errorCategory: 'storage_unavailable',
|
|
663
|
-
attemptCount: ctx.task.attemptCount,
|
|
664
|
-
errorMessage: stateErr instanceof Error ? stateErr.message : String(stateErr),
|
|
665
|
-
});
|
|
666
|
-
return {
|
|
667
|
-
status: 'failed',
|
|
668
|
-
taskId: ctx.taskId,
|
|
669
|
-
errorCategory: 'storage_unavailable',
|
|
670
|
-
failureReason: `State manager error: ${ctx.failureReason}`,
|
|
671
|
-
attemptCount: ctx.task.attemptCount,
|
|
672
|
-
};
|
|
945
|
+
return this.terminalWriteFailureResult(ctx, stateErr, { phase: 'terminal failure write' });
|
|
673
946
|
}
|
|
674
947
|
this.emitEvent('task_failed', ctx.taskId, {
|
|
675
948
|
errorCategory: ctx.errorCategory,
|
|
@@ -697,21 +970,14 @@ export class BasePeerRunner {
|
|
|
697
970
|
// rc-9 (no silent fallback): telemetry event carries nextAction.
|
|
698
971
|
if (ctx.errorCategory === 'rate_limit' && this.isDegradationEnabled()) {
|
|
699
972
|
try {
|
|
700
|
-
await this.
|
|
973
|
+
await this.markFailedFenced({
|
|
974
|
+
taskId: ctx.taskId,
|
|
975
|
+
errorCategory: 'rate_limit',
|
|
976
|
+
failureReason: `LLM rate limit degraded: ${ctx.failureReason}`,
|
|
977
|
+
});
|
|
701
978
|
}
|
|
702
979
|
catch (stateErr) {
|
|
703
|
-
this.
|
|
704
|
-
errorCategory: 'storage_unavailable',
|
|
705
|
-
attemptCount: ctx.task.attemptCount,
|
|
706
|
-
errorMessage: stateErr instanceof Error ? stateErr.message : String(stateErr),
|
|
707
|
-
});
|
|
708
|
-
return {
|
|
709
|
-
status: 'failed',
|
|
710
|
-
taskId: ctx.taskId,
|
|
711
|
-
errorCategory: 'storage_unavailable',
|
|
712
|
-
failureReason: `State manager error: ${ctx.failureReason}`,
|
|
713
|
-
attemptCount: ctx.task.attemptCount,
|
|
714
|
-
};
|
|
980
|
+
return this.terminalWriteFailureResult(ctx, stateErr, { phase: 'terminal failure write' });
|
|
715
981
|
}
|
|
716
982
|
this.emitEvent('diag_llm_rate_limit_degraded', ctx.taskId, {
|
|
717
983
|
errorCategory: 'rate_limit',
|
|
@@ -732,21 +998,10 @@ export class BasePeerRunner {
|
|
|
732
998
|
const shouldRetry = this.stateManager.getRetryPolicy().shouldRetry(ctx.task);
|
|
733
999
|
if (shouldRetry) {
|
|
734
1000
|
try {
|
|
735
|
-
await this.stateManager.markTaskRetryWait(ctx.taskId, ctx.errorCategory, ctx.failureReason);
|
|
1001
|
+
await this.stateManager.markTaskRetryWait(ctx.taskId, ctx.errorCategory, ctx.failureReason, this.requireLeaseFence(), this.requireExecutionRunId());
|
|
736
1002
|
}
|
|
737
1003
|
catch (stateErr) {
|
|
738
|
-
this.
|
|
739
|
-
errorCategory: 'storage_unavailable',
|
|
740
|
-
attemptCount: ctx.task.attemptCount,
|
|
741
|
-
errorMessage: stateErr instanceof Error ? stateErr.message : String(stateErr),
|
|
742
|
-
});
|
|
743
|
-
return {
|
|
744
|
-
status: 'failed',
|
|
745
|
-
taskId: ctx.taskId,
|
|
746
|
-
errorCategory: 'storage_unavailable',
|
|
747
|
-
failureReason: `State manager error: ${ctx.failureReason}`,
|
|
748
|
-
attemptCount: ctx.task.attemptCount,
|
|
749
|
-
};
|
|
1004
|
+
return this.terminalWriteFailureResult(ctx, stateErr, { phase: 'retry_wait write', isRetryWrite: true });
|
|
750
1005
|
}
|
|
751
1006
|
this.emitEvent('task_retried', ctx.taskId, {
|
|
752
1007
|
errorCategory: ctx.errorCategory,
|
|
@@ -780,21 +1035,10 @@ export class BasePeerRunner {
|
|
|
780
1035
|
await this.persistTerminalFailure(ctx);
|
|
781
1036
|
const maxAttemptsReason = `Max attempts exceeded: ${ctx.failureReason}`;
|
|
782
1037
|
try {
|
|
783
|
-
await this.
|
|
1038
|
+
await this.markFailedFenced({ taskId: ctx.taskId, errorCategory: ctx.errorCategory, failureReason: maxAttemptsReason });
|
|
784
1039
|
}
|
|
785
1040
|
catch (stateErr) {
|
|
786
|
-
this.
|
|
787
|
-
errorCategory: 'storage_unavailable',
|
|
788
|
-
attemptCount: ctx.task.attemptCount,
|
|
789
|
-
errorMessage: stateErr instanceof Error ? stateErr.message : String(stateErr),
|
|
790
|
-
});
|
|
791
|
-
return {
|
|
792
|
-
status: 'failed',
|
|
793
|
-
taskId: ctx.taskId,
|
|
794
|
-
errorCategory: 'storage_unavailable',
|
|
795
|
-
failureReason: `State manager error: ${ctx.failureReason}`,
|
|
796
|
-
attemptCount: ctx.task.attemptCount,
|
|
797
|
-
};
|
|
1041
|
+
return this.terminalWriteFailureResult(ctx, stateErr, { phase: 'terminal failure write' });
|
|
798
1042
|
}
|
|
799
1043
|
this.emitEvent('task_failed', ctx.taskId, {
|
|
800
1044
|
errorCategory: ctx.errorCategory,
|
|
@@ -827,21 +1071,64 @@ export class BasePeerRunner {
|
|
|
827
1071
|
*/
|
|
828
1072
|
async persistTerminalFailure(ctx) {
|
|
829
1073
|
try {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
1074
|
+
// Fenced read-modify-write in ONE transaction: the merge source is the
|
|
1075
|
+
// CURRENT persisted JSON (rc-7), and a worker whose lease was reclaimed
|
|
1076
|
+
// cannot stamp this execution's terminal facts onto the new one.
|
|
1077
|
+
await this.stateManager.applyFencedDiagnosticJson(this.requireLeaseFence(), (current) => {
|
|
1078
|
+
const parsed = parseDiagnosticJsonRecord(current ?? ctx.task.diagnosticJson);
|
|
1079
|
+
// D-01 / rc-9: a pain whose diagnosis exhausted its attempts must not
|
|
1080
|
+
// disappear from the queue without a recovery pointer. This record is the
|
|
1081
|
+
// operator-facing statement that the pain was NOT internalized, plus the
|
|
1082
|
+
// command that can retry it.
|
|
1083
|
+
const sourcePainId = typeof parsed.sourcePainId === 'string' && parsed.sourcePainId.length > 0
|
|
1084
|
+
? parsed.sourcePainId
|
|
1085
|
+
: undefined;
|
|
1086
|
+
// D-01 review: `pd pain retry --pain-id … --confirm` alone fails — the
|
|
1087
|
+
// command needs the workspace and a resolvable runtime, and `--confirm`
|
|
1088
|
+
// is only for statement-based recovery of a *succeeded* task. Print the
|
|
1089
|
+
// workspace explicitly and state the remaining precondition instead of
|
|
1090
|
+
// handing the operator a command that errors when copied.
|
|
1091
|
+
const { workspaceDir } = this.stateManager;
|
|
1092
|
+
const workspaceArg = typeof workspaceDir === 'string' && workspaceDir.length > 0
|
|
1093
|
+
? ` --workspace "${workspaceDir}"`
|
|
1094
|
+
: ' --workspace <path-to-the-workspace>';
|
|
1095
|
+
parsed.terminal_failure = {
|
|
1096
|
+
recordedAt: new Date().toISOString(),
|
|
1097
|
+
reason: 'max_attempts_exceeded',
|
|
1098
|
+
errorCategory: ctx.errorCategory,
|
|
1099
|
+
failureReason: ctx.failureReason,
|
|
1100
|
+
attemptCount: ctx.task.attemptCount,
|
|
1101
|
+
maxAttempts: ctx.task.maxAttempts,
|
|
1102
|
+
painInternalized: false,
|
|
1103
|
+
retryable: true,
|
|
1104
|
+
...(sourcePainId !== undefined ? { sourcePainId } : {}),
|
|
1105
|
+
nextAction: sourcePainId !== undefined
|
|
1106
|
+
? `pd pain retry --pain-id ${sourcePainId}${workspaceArg}`
|
|
1107
|
+
: `pd runtime recovery failed-tasks${workspaceArg} --confirm --force`,
|
|
1108
|
+
// rc-9: the command above is runnable only under these conditions; if
|
|
1109
|
+
// they are omitted the CLI fails with its own nextAction, but the
|
|
1110
|
+
// operator should not have to discover that by trial.
|
|
1111
|
+
...(sourcePainId !== undefined
|
|
1112
|
+
? {
|
|
1113
|
+
nextActionRequires: [
|
|
1114
|
+
'the workspace above still contains .pd/state.db',
|
|
1115
|
+
'a runtime binding exists: pass --runtime <kind> --provider <p> --model <m> --apiKeyEnv <ENV> unless .pd/config.yaml already binds one',
|
|
1116
|
+
],
|
|
1117
|
+
}
|
|
1118
|
+
: {}),
|
|
1119
|
+
};
|
|
1120
|
+
return JSON.stringify(parsed);
|
|
1121
|
+
});
|
|
841
1122
|
}
|
|
842
1123
|
catch (err) {
|
|
1124
|
+
// A reclaimed lease and a storage fault are different facts. Both are
|
|
1125
|
+
// best-effort here (the terminal mark is the authority), but losing the
|
|
1126
|
+
// lease must be observable as such (SPEC §5.3).
|
|
1127
|
+
const leaseLost = this.isLeaseConflictError(err);
|
|
1128
|
+
if (leaseLost)
|
|
1129
|
+
this.emitStaleCommitRejected(ctx.taskId, 'terminal diagnostic write');
|
|
843
1130
|
this.emitEvent('mark_failed_error', ctx.taskId, {
|
|
844
|
-
errorCategory: 'storage_unavailable',
|
|
1131
|
+
errorCategory: leaseLost ? 'lease_conflict' : 'storage_unavailable',
|
|
845
1132
|
attemptCount: ctx.task.attemptCount,
|
|
846
1133
|
errorMessage: `persistTerminalFailure failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
847
1134
|
});
|
|
@@ -874,24 +1161,30 @@ export class BasePeerRunner {
|
|
|
874
1161
|
* 持久化失败不影响主流程(best-effort,记录事件即可)。
|
|
875
1162
|
*/
|
|
876
1163
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
877
|
-
async persistOutputFailureDetails(taskId,
|
|
1164
|
+
async persistOutputFailureDetails(taskId, _existingDiagnosticJson, details, extraTopLevelKeys) {
|
|
878
1165
|
try {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1166
|
+
// SPEC §5.3: the write is fenced and the merge source is read INSIDE the
|
|
1167
|
+
// same transaction. The second parameter is kept for call-site
|
|
1168
|
+
// compatibility but is intentionally unused: trusting a caller's stale
|
|
1169
|
+
// snapshot was the cross-attempt overwrite bug.
|
|
1170
|
+
await this.stateManager.applyFencedDiagnosticJson(this.requireLeaseFence(), (current) => {
|
|
1171
|
+
const parsed = parseDiagnosticJsonRecord(current);
|
|
1172
|
+
parsed.output_failure_details = {
|
|
1173
|
+
recordedAt: new Date().toISOString(),
|
|
1174
|
+
...details,
|
|
1175
|
+
};
|
|
1176
|
+
if (extraTopLevelKeys !== undefined) {
|
|
1177
|
+
Object.assign(parsed, extraTopLevelKeys);
|
|
1178
|
+
}
|
|
1179
|
+
return JSON.stringify(parsed);
|
|
1180
|
+
});
|
|
891
1181
|
}
|
|
892
1182
|
catch (err) {
|
|
1183
|
+
const leaseLost = this.isLeaseConflictError(err);
|
|
1184
|
+
if (leaseLost)
|
|
1185
|
+
this.emitStaleCommitRejected(taskId, 'output failure diagnostic write');
|
|
893
1186
|
this.emitEvent('mark_failed_error', taskId, {
|
|
894
|
-
errorCategory: 'storage_unavailable',
|
|
1187
|
+
errorCategory: leaseLost ? 'lease_conflict' : 'storage_unavailable',
|
|
895
1188
|
errorMessage: `persistOutputFailureDetails failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
896
1189
|
});
|
|
897
1190
|
}
|