@aibyzero/cm-workflow 0.16.8 → 0.17.0
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/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +629 -121
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-prd/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +80 -10
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +124 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -84
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +54 -0
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +489 -51
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +23 -5
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +36 -1
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {readExecutionPolicy} from './execution-policy.mjs';
|
|
2
|
+
import {readControlPolicy} from './control-policy.mjs';
|
|
2
3
|
import {readExternalModels} from './external-models.mjs';
|
|
3
4
|
import {beforeFirstQaRound,qaRevisionFollows,readQaConfigRevision} from './qa-config-revision.mjs';
|
|
4
5
|
import {readCloseoutPolicy} from './knowledge-closeout.mjs';
|
|
@@ -9,17 +10,18 @@ import {reviewResult,reviewReceipt} from './review-runner.mjs';
|
|
|
9
10
|
import {checkCompletion} from './gate-bridge.mjs';
|
|
10
11
|
import path from 'node:path';
|
|
11
12
|
import {readCommitIntent,readCommitResult} from './task-commit-codec.mjs';
|
|
12
|
-
import {inspectProviderReview,hasProviderReviewResult,inspectProviderReviewFailure,inspectProviderReviewReconciliation,REVIEWER_PROVIDER_FAILURES} from './provider-review-observation.mjs';
|
|
13
|
+
import {inspectProviderReview,hasProviderReviewResult,inspectProviderReviewFailure,inspectProviderReviewReconciliation,REVIEWER_PROVIDER_FAILURES,abandonableReviewerExit,reviewerGoneWithoutResult} from './provider-review-observation.mjs';
|
|
13
14
|
import {readReconciliationReceipt} from './review-reconciliation.mjs';
|
|
14
15
|
import {readCmAiProjectLearningWriteback} from './cm-ai-learning-writer.mjs';
|
|
15
16
|
import {readCmAiTaskLearningApplication} from './cm-ai-context-refresh.mjs';
|
|
16
17
|
import {reviewExclusions} from './effect-contract.mjs';
|
|
17
18
|
import {validateAcceptedFix} from './accepted-fix.mjs';
|
|
18
19
|
import {readBootstrapEvidence,validateBootstrapReviewPackage} from './host-bootstrap.mjs';
|
|
19
|
-
import {validateCodeProjectPaths,assertCodeProjectSelections} from './code-projects.mjs';
|
|
20
|
+
import {validateCodeProjectPaths,assertCodeProjectSelections,MAX_CODE_PROJECTS} from './code-projects.mjs';
|
|
20
21
|
import {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
21
22
|
import {readSpecificationRebind} from './specification-material.mjs';
|
|
22
23
|
import {protectedScopePaths} from './developer-adapter.mjs';
|
|
24
|
+
import {validWorkerPid,validStartTime} from './worker-process-identity.mjs';
|
|
23
25
|
|
|
24
26
|
const LIMIT=16*1024*1024;
|
|
25
27
|
// The developer adapter refuses a protected scope on every dispatch, before any
|
|
@@ -35,9 +37,9 @@ const prefix=(a,b)=>{need(b.length>=a.length,'runner_history_mismatch');same(a,b
|
|
|
35
37
|
const uuid=s=>need(typeof s==='string' && /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(s),'runner_session');
|
|
36
38
|
const states=['ready','awaiting_review','approved','changes_requested','fixture_completed','blocked','unknown','cancelled','pending_review'];
|
|
37
39
|
export const stageAllowed=(kind,state,code=null,reviewVerdict=null)=>
|
|
38
|
-
kind==='develop'&&state==='blocked'&&['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large','bootstrap_verification_failed','bootstrap_instruction_conflict'].includes(code)
|
|
40
|
+
kind==='develop'&&state==='blocked'&&['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large','bootstrap_verification_failed','bootstrap_instruction_conflict','develop_call_timeout','develop_answer_invalid',...RECHECK_CODES,DEVELOP_REDO_CODE,DISPATCH_RETRY_CODE,DEVELOP_INTERRUPTED_CODE,...DOCUMENTATION_SYNC_CODES].includes(code)
|
|
39
41
|
||kind==='review'&&state==='pending_review'&&REVIEW_RETRY_CODES.includes(code)
|
|
40
|
-
||kind==='complete'&&state==='blocked'&&(['completion_checks_changed','completion_package_changed'].includes(code)
|
|
42
|
+
||kind==='complete'&&state==='blocked'&&(['completion_checks_changed','completion_package_changed',COMPLETE_RECHECK_CODE].includes(code)
|
|
41
43
|
||code==='review_package_changed'&&reviewVerdict==='approved')
|
|
42
44
|
||kind==='develop'&&state==='blocked'&&code==='review_package_changed'&&reviewVerdict==='changes_requested'
|
|
43
45
|
||({develop:['ready','changes_requested'],review:['awaiting_review'],complete:['approved']})[kind]?.includes(state)===true;
|
|
@@ -59,6 +61,41 @@ const timeoutEffect=entry=>entry.effect.kind==='review'&&reviewRetryCode(entry.r
|
|
|
59
61
|
&&entry.result.code===reviewRetryCode(entry.result.reviewInvocation.result);
|
|
60
62
|
export const reviewRetrySpent=(cache,calls,attempt,contextId)=>cache.some(entry=>entry.effect.identity.attempt===attempt&&timeoutEffect(entry))
|
|
61
63
|
||calls.some(call=>call.terminal==='abandoned'&&call.contextId===contextId);
|
|
64
|
+
// V5 (A34/A36): no-result redispatches of one review round (attempt), counted
|
|
65
|
+
// apart from the two review rounds: the automatic one (a retryable end that went
|
|
66
|
+
// back to pending_review), operator abandonments (abandoned calls), and the
|
|
67
|
+
// review-redispatch records an operator writes (abandon_review) from a spent
|
|
68
|
+
// retryable block. The automatic transition still grants only the first
|
|
69
|
+
// (reviewTimeoutTransition, unchanged so older journals replay as written); the
|
|
70
|
+
// second needs that record, which carries the operator's confirmation that the
|
|
71
|
+
// original call's reviewer process stopped: a timeout only aborted it and the
|
|
72
|
+
// host never waited for its exit, so nothing else proves it gone.
|
|
73
|
+
// Never a third verdict: a redispatch exists only because the round accepted none.
|
|
74
|
+
export const MAX_REVIEW_REDISPATCHES=2;
|
|
75
|
+
export const reviewRedispatchCount=(cache,calls,attempt,contextId,records=0)=>
|
|
76
|
+
cache.filter(entry=>entry.effect.identity.attempt===attempt&&timeoutEffect(entry)&&entry.result.state==='pending_review').length
|
|
77
|
+
+calls.filter(call=>call.terminal==='abandoned'&&call.contextId===contextId).length+records;
|
|
78
|
+
// The spent retryable block of this round (reviewTimeoutTransition gave blocked).
|
|
79
|
+
const spentRetryBlock=s=>{
|
|
80
|
+
const entry=s.cache.at(-1);
|
|
81
|
+
// An end whose worker could not confirm its process-group cleanup never qualifies.
|
|
82
|
+
return s.state==='blocked'&&REVIEW_RETRY_CODES.includes(s.code)&&entry?.effect.kind==='review'
|
|
83
|
+
&&s.reviewInvocation?.result?.observation?.result?.code!=='process_cleanup_unknown'
|
|
84
|
+
&&entry.effect.identity.attempt===s.attempt&&timeoutEffect(entry)&&entry.result.state==='blocked'&&entry.result.code===s.code
|
|
85
|
+
&&s.reviewInvocation?.registration?.binding?.invocationId!=null
|
|
86
|
+
&&entry.result.reviewInvocation?.registration?.binding?.invocationId===s.reviewInvocation.registration.binding.invocationId;
|
|
87
|
+
};
|
|
88
|
+
export const reviewRedispatchable=(s,contextId,records=0)=>spentRetryBlock(s)
|
|
89
|
+
&&reviewRedispatchCount(s.cache,s.calls,s.attempt,contextId,records)<MAX_REVIEW_REDISPATCHES;
|
|
90
|
+
export const reviewRedispatchExhausted=(s,contextId,records=0)=>spentRetryBlock(s)
|
|
91
|
+
&&reviewRedispatchCount(s.cache,s.calls,s.attempt,contextId,records)>=MAX_REVIEW_REDISPATCHES;
|
|
92
|
+
export const REVIEW_REDISPATCH_LIMIT_CODE='review_redispatch_limit';
|
|
93
|
+
export const reviewRedispatchLimitReason=code=>`${REVIEW_REDISPATCH_LIMIT_CODE}: 本轮独立审查已无结论重派 ${MAX_REVIEW_REDISPATCHES} 次(原记录 blocked/${code}),`
|
|
94
|
+
+'不再自动重派,也不计为审查轮次。先查清审查进程为何一直没有结论(登录、额度、网络或审查答复格式),'
|
|
95
|
+
+'修好后用 --supersede-reviewed-evidence 新建运行重做;本运行记录保留不改写。';
|
|
96
|
+
export const reviewRedispatchStopReason=code=>`review_redispatch_stop_required: 本轮独立审查第二次没有结论(blocked/${code}),本轮还剩 1 次无结论重派。`
|
|
97
|
+
+'宿主只中止了原调用、没有等到审查进程退出,不能证明它已停止:先确认原审查进程(含子进程)已退出,'
|
|
98
|
+
+'再用 --allow-abandon-review 发送 abandon_review(单行 reason)登记确认,之后 advance 重派;不算审查轮次。';
|
|
62
99
|
export const reviewTimeoutTransition=(result,cache,attempt,calls=[],contextId=null)=>{
|
|
63
100
|
const code=reviewRetryCode(result);
|
|
64
101
|
return code===null?null:{state:reviewRetrySpent(cache,calls,attempt,contextId)?'blocked':'pending_review',code};
|
|
@@ -66,12 +103,371 @@ export const reviewTimeoutTransition=(result,cache,attempt,calls=[],contextId=nu
|
|
|
66
103
|
// Six counted provider calls per run. Locally rejected developer values,
|
|
67
104
|
// automatic review retries and abandoned invocations hold no slot.
|
|
68
105
|
export const MAX_RUNNER_CALLS=6;
|
|
106
|
+
// A develop the host answer limit cut off (call_timeout, call terminal unknown).
|
|
107
|
+
// It produced nothing the runner accepted. Only while the code root still equals
|
|
108
|
+
// where it started (checked live, see developTimeoutBasis) can the run go on, so
|
|
109
|
+
// it holds no call or effect slot; MAX_DEVELOP_TIMEOUT_RETRIES bounds the redos.
|
|
110
|
+
export const developTimeoutEffect=entry=>entry.effect.kind==='develop'&&entry.result.state==='unknown'
|
|
111
|
+
&&entry.result.code==='call_timeout';
|
|
112
|
+
export const MAX_DEVELOP_TIMEOUT_RETRIES=2;
|
|
113
|
+
export const DEVELOP_CALL_TIMEOUT_REASON='develop_call_timeout: 开发应答超过宿主请求上限(默认 30 分钟),代码根仍与本轮开发开始时一致;'
|
|
114
|
+
+'在原运行 advance 重发本轮开发(新 effect id,审查轮次不变)。迟到的应答仍被拒绝。';
|
|
115
|
+
// The tree a timed-out develop started from, when the journal pins it: the
|
|
116
|
+
// reviewed attempt-1 package (attempt 2) or the original baseline (attempt 1,
|
|
117
|
+
// nothing delivered yet). A develop redone from a blocked delivery left
|
|
118
|
+
// unrecorded edits on disk, so its start cannot be proven: null, stays unknown.
|
|
119
|
+
// The binding outlives the develop-timeout-retry record (blocked/develop_call_timeout):
|
|
120
|
+
// the redo re-verifies the same start right before dispatch.
|
|
121
|
+
export const developTimeoutState=s=>s.state==='unknown'&&s.code==='call_timeout'
|
|
122
|
+
||s.state==='blocked'&&s.code==='develop_call_timeout';
|
|
123
|
+
export function developTimeoutBasis(s,configuration=null) {
|
|
124
|
+
if(configuration?.mode==='instructions')return null;
|
|
125
|
+
const last=s.cache.at(-1),call=s.calls.at(-1);
|
|
126
|
+
if(!(developTimeoutState(s)&&last&&developTimeoutEffect(last)
|
|
127
|
+
&&last.effect.identity.attempt===s.attempt&&call?.terminal==='unknown'&&call.channel==='fixture'))return null;
|
|
128
|
+
if(s.cache.filter(developTimeoutEffect).length>MAX_DEVELOP_TIMEOUT_RETRIES)return null;
|
|
129
|
+
return pinnedDevelopStart(s,developTimeoutEffect);
|
|
130
|
+
}
|
|
131
|
+
// The tree the round's develop effects all started from, when the journal pins
|
|
132
|
+
// it: the reviewed attempt-1 package (attempt 2) or the original baseline
|
|
133
|
+
// (attempt 1, nothing delivered yet). Earlier develops of this attempt that
|
|
134
|
+
// produced nothing the runner accepted (skip) are passed over; any other entry
|
|
135
|
+
// means unrecorded edits may exist, so the start cannot be proven (null). The
|
|
136
|
+
// caller still compares the live code root with it.
|
|
137
|
+
function pinnedDevelopStart(s,skip,from=s.cache.length-2){
|
|
138
|
+
for(let i=from;i>=0;i--){
|
|
139
|
+
const entry=s.cache[i];
|
|
140
|
+
if(skip(entry)&&entry.effect.identity.attempt===s.attempt)continue;
|
|
141
|
+
return s.attempt===2&&entry.effect.kind==='review'&&entry.result.state==='changes_requested'
|
|
142
|
+
&&s.reviewPackage?.identity.attempt===1&&s.priorReview?.verdict==='changes_requested'?'reviewed_package':null;
|
|
143
|
+
}
|
|
144
|
+
return s.attempt===1&&s.reviewPackage===null?'baseline':null;
|
|
145
|
+
}
|
|
146
|
+
// A current-session answer the host rejected locally (invalid_result without the
|
|
147
|
+
// protected retryable flag: e.g. application.note over 512 characters). It was
|
|
148
|
+
// journaled as blocked/failed. Like a protected invalid value it holds no call
|
|
149
|
+
// or effect slot; MAX_DEVELOP_ANSWER_RETRIES bounds the redos. Edits the session
|
|
150
|
+
// already wrote stay on disk and are part of the redone delivery, which is
|
|
151
|
+
// built from the round's start and reviewed like any other.
|
|
152
|
+
export const developAnswerInvalidEffect=entry=>{
|
|
153
|
+
const call=entry.result.calls?.at(-1);
|
|
154
|
+
return entry.effect.kind==='develop'&&entry.result.state==='blocked'&&entry.result.code==='failed'
|
|
155
|
+
&&call?.terminal==='failed'&&call.requestedModel==='current-session'&&call.failureResult?.code==='invalid_result'
|
|
156
|
+
&&!Object.hasOwn(call.failureResult,'retryable');
|
|
157
|
+
};
|
|
158
|
+
export const MAX_DEVELOP_ANSWER_RETRIES=2;
|
|
159
|
+
export const DEVELOP_ANSWER_LIMITS='application.note 为单行且不超过 512 个字符(no_relevant_lesson 时为 null);'
|
|
160
|
+
+'retrospective 的 reason 与每个候选的 trigger、action 为单行且不超过 240 个字符;候选 1–3 个,每个 1–8 条相对路径证据(单行、不超过 512 个字符)';
|
|
161
|
+
const answerReasons={application_note_limit:'application.note 超过 512 个字符或含换行'};
|
|
162
|
+
export const developAnswerInvalidReason=failure=>`develop_answer_invalid: 开发应答未通过交付合同校验(${answerReasons[failure?.reason]??failure?.reason??'invalid_input'});`
|
|
163
|
+
+`上限:${DEVELOP_ANSWER_LIMITS}。会话已写的代码保留,在原运行 advance 重发本轮开发(新 effect id,审查轮次不变),按上限重新应答。`;
|
|
164
|
+
// The journaled blocked/failed develop is the last effect and the cap is not spent.
|
|
165
|
+
export function developAnswerRetryable(s,configuration=null) {
|
|
166
|
+
if(configuration?.mode==='instructions')return false;
|
|
167
|
+
const last=s.cache.at(-1);
|
|
168
|
+
return s.state==='blocked'&&['failed','develop_answer_invalid'].includes(s.code)&&last!==undefined
|
|
169
|
+
&&developAnswerInvalidEffect(last)&&last.effect.identity.attempt===s.attempt
|
|
170
|
+
&&s.cache.filter(developAnswerInvalidEffect).length<=MAX_DEVELOP_ANSWER_RETRIES;
|
|
171
|
+
}
|
|
172
|
+
// V3 answer gaps: the delivery already reached the disk (the developer call
|
|
173
|
+
// succeeded and its Learning was written back), but a later step never got a
|
|
174
|
+
// usable answer: the task checks or the verification precheck (timed out,
|
|
175
|
+
// disconnected, late, or malformed), or the completion re-check before any
|
|
176
|
+
// task-commit-intent. The developer is never dispatched again: advance journals
|
|
177
|
+
// develop-recheck (or complete-recheck) and re-runs only those later steps.
|
|
178
|
+
// Neither the source effect nor its re-check holds a call or effect slot;
|
|
179
|
+
// MAX_ANSWER_GAP_RETRIES bounds each kind per run. Old journals are projected
|
|
180
|
+
// the same way on replay; their records are never rewritten.
|
|
181
|
+
export const MAX_ANSWER_GAP_RETRIES=2;
|
|
182
|
+
const CHECK_ANSWER_MISSING=['call_timeout','execution_error','host_disconnected','host_request_timeout','role_log_failed'];
|
|
183
|
+
// limit_exceeded is left out: it is also how older runtimes recorded package and
|
|
184
|
+
// journal size limits, which a re-check does not resolve. An oversized check
|
|
185
|
+
// answer is refused by the bridge and times out (check_answer_missing).
|
|
186
|
+
const CHECK_ANSWER_INVALID=['invalid_input','invalid_result','verification_precheck_invalid'];
|
|
187
|
+
// A53: the delivery touched paths outside the task scope (not only files the
|
|
188
|
+
// checks created). The paths are named; once the operator moved or restored
|
|
189
|
+
// them, a re-check rebuilds the handoff and package without a new develop.
|
|
190
|
+
export const OUT_OF_SCOPE_RECHECK_CODE='develop_out_of_scope';
|
|
191
|
+
export const RECHECK_CODES=Object.freeze(['check_answer_missing','check_answer_invalid',OUT_OF_SCOPE_RECHECK_CODE]);
|
|
192
|
+
export const COMPLETE_RECHECK_CODE='complete_recheck_failed';
|
|
193
|
+
// learningWriteback mirrors the checkpointed Learning result, which the journal
|
|
194
|
+
// grammar only accepts after this effect's own developer call succeeded (or on a
|
|
195
|
+
// re-check that kept it unchanged).
|
|
196
|
+
export const developRecheckSource=entry=>{
|
|
197
|
+
const result=entry.result,call=result.calls?.at(-1);
|
|
198
|
+
return entry.effect.kind==='develop'&&result.state==='unknown'
|
|
199
|
+
&&[...CHECK_ANSWER_MISSING,...CHECK_ANSWER_INVALID,'out_of_scope'].includes(result.code)
|
|
200
|
+
&&call?.terminal==='succeeded'&&call.channel==='fixture'
|
|
201
|
+
&&result.learningWriteback!=null&&result.learningWriteback.outcome!=='writeback_pending';
|
|
202
|
+
};
|
|
203
|
+
export function developRecheckCode(s,config,recorded=0){
|
|
204
|
+
if(config.bootstrap?.mode==='instructions'||config.taskLearning?.hostHandoff!==true)return null;
|
|
205
|
+
const last=s.cache.at(-1);
|
|
206
|
+
if(!last||last.effect.identity.attempt!==s.attempt||!developRecheckSource(last)
|
|
207
|
+
||s.learningResult==null||s.receipt!==null)return null;
|
|
208
|
+
if(s.state==='blocked'&&RECHECK_CODES.includes(s.code))return s.code;
|
|
209
|
+
if(!(s.state==='unknown'&&s.code===last.result.code)||recorded>=MAX_ANSWER_GAP_RETRIES)return null;
|
|
210
|
+
return last.result.code==='out_of_scope'?OUT_OF_SCOPE_RECHECK_CODE
|
|
211
|
+
:CHECK_ANSWER_INVALID.includes(last.result.code)?'check_answer_invalid':'check_answer_missing';
|
|
212
|
+
}
|
|
213
|
+
// detail: the source checkpoint's reason, which names the out-of-scope paths.
|
|
214
|
+
const outOfScopePaths=detail=>typeof detail==='string'&&/^out_of_scope:/.test(detail)
|
|
215
|
+
?detail.replace(/^out_of_scope:\s*/,'').split(/,\s*/).filter(Boolean).slice(0,20):[];
|
|
216
|
+
export const developRecheckReason=(code,source,detail=null)=>code===OUT_OF_SCOPE_RECHECK_CODE
|
|
217
|
+
?boundedReason(`${code}: 开发已交付并写回 Learning,但改动超出任务 scope(原记录 unknown/${source}):`,(paths=>paths.length?paths:['见原记录'])(outOfScopePaths(detail)),
|
|
218
|
+
'。这些路径可能是会话越界写的,也可能是你自己的改动:移走或还原它们(确需改动就先走规格变更扩大 scope)后,在原运行 advance 只重跑检查、验证预检、handoff 与审查包,不重发开发、不占名额(每运行最多 2 次)。')
|
|
219
|
+
:`${code}: 开发已交付并写回 Learning,但之后的检查或验证预检没有拿到可用应答(原记录 unknown/${source})。`
|
|
220
|
+
+'先确认上一次检查命令已经停止;在原运行 advance 只重跑检查、验证预检、handoff 与审查包,不重发开发,不占开发调用与 effect 名额(每运行最多 2 次)。';
|
|
221
|
+
export const completeRecheckSource=entry=>entry.effect.kind==='complete'&&entry.result.state==='unknown'
|
|
222
|
+
&&[...CHECK_ANSWER_MISSING,'invalid_input'].includes(entry.result.code)
|
|
223
|
+
&&entry.result.taskCommit===null;
|
|
224
|
+
export function completeRecheckable(s,recorded=0){
|
|
225
|
+
const last=s.cache.at(-1);
|
|
226
|
+
if(!last||last.effect.identity.attempt!==s.attempt||!completeRecheckSource(last)||s.taskCommit!=null)return false;
|
|
227
|
+
if(s.state==='blocked'&&s.code===COMPLETE_RECHECK_CODE)return true;
|
|
228
|
+
return s.state==='unknown'&&s.code===last.result.code&&recorded<MAX_ANSWER_GAP_RETRIES;
|
|
229
|
+
}
|
|
230
|
+
export const completeRecheckReason=source=>`${COMPLETE_RECHECK_CODE}: 完成前复查没有正常结束(检查应答缺失、断开,或宿主在写入提交意图前出错;原记录 unknown/${source}),task-commit-intent 尚未写入,tasks.md 未改动。`
|
|
231
|
+
+'先按宿主 stderr 的 diagnostic 修好原因(如缺失的 handoff 或检查环境);'
|
|
232
|
+
+'在原运行发送 complete 重新复查并完成,不重新开发或审查(每运行最多 2 次)。';
|
|
233
|
+
// V2 + R3: a current-session develop whose answer never arrived (timed out with
|
|
234
|
+
// the code root changed or its start not pinned, disconnected, late) or came back
|
|
235
|
+
// as a bare failure. The session may still be writing and the host cannot see
|
|
236
|
+
// it, so nothing is redispatched until the operator confirms it stopped:
|
|
237
|
+
// develop_redo with a reason, journaled as develop-answer-redo. The redo sends
|
|
238
|
+
// the same round under a new effect id. Edits already on disk stay and are part
|
|
239
|
+
// of the redone delivery, whose review package is built against the task
|
|
240
|
+
// baseline captured when the run was created (never re-captured), so no edit
|
|
241
|
+
// skips the checks and the independent review. Provider development and
|
|
242
|
+
// instruction bootstrap are excluded (their writers or half-writes need their
|
|
243
|
+
// own reconciliation); the host also excludes protected current-session mode,
|
|
244
|
+
// where a changed root can only be a partially applied proposal.
|
|
245
|
+
export const DEVELOP_REDO_CODE='develop_answer_missing';
|
|
246
|
+
export const MAX_DEVELOP_REDOS=2;
|
|
247
|
+
export const developAnswerMissingEffect=entry=>{
|
|
248
|
+
const result=entry.result,call=result.calls?.at(-1);
|
|
249
|
+
if(entry.effect.kind!=='develop'||call?.requestedModel!=='current-session'||call.channel!=='fixture')return false;
|
|
250
|
+
return result.state==='unknown'&&result.code==='unknown'&&call.terminal==='unknown'
|
|
251
|
+
||result.state==='blocked'&&result.code==='failed'&&call.terminal==='failed'
|
|
252
|
+
&&!Object.hasOwn(call,'failureResult')&&!Object.hasOwn(call,'blockedReason');
|
|
253
|
+
};
|
|
254
|
+
// V9: a provider develop (Codex writes in its sandbox, Claude proposes and the
|
|
255
|
+
// host applies) that ended without a usable result. Its worker may outlive the
|
|
256
|
+
// call, so a redo is offered only for an effect whose worker identity this
|
|
257
|
+
// runtime journaled (workerJournal intent marker): the host then proves the
|
|
258
|
+
// recorded process group gone before the redo record is written.
|
|
259
|
+
export const providerStuckCause=entry=>{
|
|
260
|
+
const result=entry.result,call=result.calls?.at(-1);
|
|
261
|
+
if(entry.effect.kind!=='develop'||!call||call.requestedModel==='current-session'||call.channel!=='fixture')return null;
|
|
262
|
+
if(result.state==='unknown'&&call.terminal==='unknown')return result.code==='call_timeout'?'provider_call_timeout':'provider_unknown';
|
|
263
|
+
// Only an explicit invalid proposal: a bare failure may be a legitimate
|
|
264
|
+
// blocked answer without a reason, which stays terminal (A11).
|
|
265
|
+
if(result.state==='blocked'&&result.code==='failed'&&call.terminal==='failed'&&!Object.hasOwn(call,'blockedReason')
|
|
266
|
+
&&call.failureResult?.code==='invalid_result'&&call.failureResult.retryable!==true)return 'provider_failed';
|
|
267
|
+
if(result.state==='blocked'&&result.code==='unavailable'&&call.terminal==='unavailable')return 'provider_unavailable';
|
|
268
|
+
return null;
|
|
269
|
+
};
|
|
270
|
+
// What the stuck develop was ('call_timeout', 'unknown', 'execution_error',
|
|
271
|
+
// 'failed' or a provider_* cause), or null when this exit does not apply.
|
|
272
|
+
// workers: the journaled worker records by effect id (readRunnerHistory).
|
|
273
|
+
export function developRedoCause(s,config,recorded=0,workers=null){
|
|
274
|
+
if(config.bootstrap?.mode==='instructions'||recorded>=MAX_DEVELOP_REDOS)return null;
|
|
275
|
+
if(config.developer.requestedModel!=='current-session'){
|
|
276
|
+
const last=s.cache.at(-1);
|
|
277
|
+
if(!last||last.effect.identity.attempt!==s.attempt||s.receipt!==null)return null;
|
|
278
|
+
const cause=providerStuckCause(last);
|
|
279
|
+
if(cause===null||s.state!==last.result.state||s.code!==last.result.code)return null;
|
|
280
|
+
return workers?.[last.effect.id]?.journal===true?cause:null;
|
|
281
|
+
}
|
|
282
|
+
const last=s.cache.at(-1);
|
|
283
|
+
if(!last||last.effect.identity.attempt!==s.attempt||s.receipt!==null)return null;
|
|
284
|
+
if(developTimeoutEffect(last)&&s.calls.at(-1)?.terminal==='unknown'
|
|
285
|
+
&&(s.state==='unknown'&&s.code==='call_timeout'||s.state==='blocked'&&s.code==='develop_call_timeout'))return 'call_timeout';
|
|
286
|
+
if(developAnswerMissingEffect(last)&&s.state===last.result.state&&s.code===last.result.code)return last.result.code;
|
|
287
|
+
// A dispatch failure whose round start cannot be proven unchanged (legacy
|
|
288
|
+
// execution_error, a start the journal does not pin, or a root that changed,
|
|
289
|
+
// also after its develop-dispatch-retry record) needs the same confirmation.
|
|
290
|
+
if(developDispatchFailedEffect(last)&&(s.state==='unknown'&&s.code===last.result.code
|
|
291
|
+
||s.state==='blocked'&&s.code===DISPATCH_RETRY_CODE))return last.result.code;
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
// V1/V3 (P1-3): the current-session developer run failed before the session was
|
|
295
|
+
// asked anything: the host's own role routing (its run-log write or the workflow
|
|
296
|
+
// role configuration) threw, the call never returned (terminal unknown, no
|
|
297
|
+
// result). Those codes are raised only before the bridge request, so nothing
|
|
298
|
+
// was dispatched and nothing written: develop_dispatch_failed, redone like any
|
|
299
|
+
// retryable develop block after a develop-dispatch-retry record. Older runtimes
|
|
300
|
+
// collapsed the same failure into execution_error, which a failure after the
|
|
301
|
+
// answer can also produce; such a journal gets this exit only while the code
|
|
302
|
+
// root still equals the round's pinned start (checked live, like #198), and
|
|
303
|
+
// otherwise the operator-confirmed develop_redo.
|
|
304
|
+
export const DISPATCH_RETRY_CODE='develop_dispatch_failed';
|
|
305
|
+
export const DISPATCH_FAILURE_CODES=Object.freeze(['role_log_failed','invalid_workflow_config']);
|
|
306
|
+
export const developDispatchFailedEffect=entry=>{
|
|
307
|
+
const result=entry.result,call=result.calls?.at(-1);
|
|
308
|
+
return entry.effect.kind==='develop'&&result.state==='unknown'
|
|
309
|
+
&&[...DISPATCH_FAILURE_CODES,'execution_error'].includes(result.code)
|
|
310
|
+
&&call?.terminal==='unknown'&&call.resultDigest===null&&call.requestedModel==='current-session'&&call.channel==='fixture';
|
|
311
|
+
};
|
|
312
|
+
// The round start the journal pins ('baseline' or 'reviewed_package'), or null.
|
|
313
|
+
// Like #198 the binding outlives the develop-dispatch-retry record
|
|
314
|
+
// (blocked/develop_dispatch_failed): the host compares the live code root with
|
|
315
|
+
// this start before every redispatch, the first one and any after a restart.
|
|
316
|
+
export function developDispatchBasis(s,config,recorded=0){
|
|
317
|
+
if(config.bootstrap?.mode==='instructions'||config.developer.requestedModel!=='current-session')return null;
|
|
318
|
+
const last=s.cache.at(-1);
|
|
319
|
+
if(!last||last.effect.identity.attempt!==s.attempt||s.receipt!==null||!developDispatchFailedEffect(last))return null;
|
|
320
|
+
if(!(s.state==='unknown'&&s.code===last.result.code&&recorded<MAX_DEVELOP_REDOS
|
|
321
|
+
||s.state==='blocked'&&s.code===DISPATCH_RETRY_CODE))return null;
|
|
322
|
+
return pinnedDevelopStart(s,entry=>developDispatchFailedEffect(entry)||developTimeoutEffect(entry));
|
|
323
|
+
}
|
|
324
|
+
// Q16/Q17 (V2): documentation_sync runs inside the final task's develop, after
|
|
325
|
+
// the session already answered the develop. This runtime journals that answer
|
|
326
|
+
// and the documentation start (documentation-sync-started) right before it asks
|
|
327
|
+
// the sync, and marks the developer call with that record's digest
|
|
328
|
+
// (call.documentationSync). A sync that then ends without a usable answer is
|
|
329
|
+
// checkpointed unknown with one of these codes; only documentation_sync is
|
|
330
|
+
// asked again, by a develop intent whose adapter reuses the journaled answer.
|
|
331
|
+
// The developer is never dispatched again, and the review package still
|
|
332
|
+
// compares with the task baseline captured at create. The source holds no call
|
|
333
|
+
// or effect slot; MAX_DOCUMENTATION_SYNC_RETRIES bounds the retries per run.
|
|
334
|
+
// Journals without the record keep their old projection.
|
|
335
|
+
//
|
|
336
|
+
// R3: nothing the host observes proves the documentation writer stopped. A
|
|
337
|
+
// lost answer may simply not have written yet, and an accepted answer only ends
|
|
338
|
+
// the host's wait, not the session's writes. So every retry first needs the
|
|
339
|
+
// operator's stop confirmation for that exact source call (develop_redo with a
|
|
340
|
+
// reason, journaled as documentation-sync-retry), or the effect-interrupted
|
|
341
|
+
// record of a host that died during the sync (the same confirmation, given
|
|
342
|
+
// through abandon_effect). The disk is a separate gate, checked right before
|
|
343
|
+
// every redispatch (also after a restart): the code root outside the
|
|
344
|
+
// documentation paths still equals the documentation start, and the
|
|
345
|
+
// documentation paths still equal what they were when the stop was confirmed.
|
|
346
|
+
export const DOCUMENTATION_SYNC_INTERRUPTED_CODE='documentation_sync_interrupted';
|
|
347
|
+
export const DOCUMENTATION_SYNC_CODES=Object.freeze(['documentation_sync_answer_missing','documentation_sync_answer_invalid',
|
|
348
|
+
'documentation_sync_answer_blocked','documentation_sync_out_of_scope',DOCUMENTATION_SYNC_INTERRUPTED_CODE]);
|
|
349
|
+
export const MAX_DOCUMENTATION_SYNC_RETRIES=2;
|
|
350
|
+
// The workflow configuration accepts up to 256 documentation paths
|
|
351
|
+
// (host-workflow-capabilities.mjs); the record accepts every one of them.
|
|
352
|
+
export const MAX_DOCUMENTATION_PATHS=256;
|
|
353
|
+
// The documentation paths and their sha256 (null: absent) a record names: in
|
|
354
|
+
// the task scope, distinct, 1..MAX_DOCUMENTATION_PATHS of them.
|
|
355
|
+
export function validDocumentationStates(documents,scope){
|
|
356
|
+
need(Array.isArray(documents)&&documents.length>0&&documents.length<=MAX_DOCUMENTATION_PATHS,'runner_documentation');
|
|
357
|
+
const seen=new Set();
|
|
358
|
+
for(const item of documents){
|
|
359
|
+
shape(item,['path','sha256']);
|
|
360
|
+
need(typeof item.path==='string'&&scope.includes(item.path)&&!seen.has(item.path),'runner_documentation');
|
|
361
|
+
seen.add(item.path);if(item.sha256!==null)hex(item.sha256);
|
|
362
|
+
}
|
|
363
|
+
return documents;
|
|
364
|
+
}
|
|
365
|
+
export const DOCUMENTATION_SYNC_LIMIT_CODE='documentation_sync_retry_limit';
|
|
366
|
+
export const documentationSyncSource=entry=>{
|
|
367
|
+
const result=entry.result,call=result.calls?.at(-1);
|
|
368
|
+
return entry.effect.kind==='develop'&&result.state==='unknown'&&DOCUMENTATION_SYNC_CODES.includes(result.code)
|
|
369
|
+
&&call?.terminal==='unknown'&&call.resultDigest===null&&typeof call.documentationSync==='string'
|
|
370
|
+
&&call.channel==='fixture'&&result.learningWriteback==null;
|
|
371
|
+
};
|
|
372
|
+
// The checkpointed failure (state unknown, last effect) still waiting for its
|
|
373
|
+
// stop confirmation, while the run has a retry left; its code, or null.
|
|
374
|
+
export function documentationSyncRetryCode(s,config,recorded=0){
|
|
375
|
+
if(config.bootstrap)return null;
|
|
376
|
+
const last=s.cache.at(-1);
|
|
377
|
+
if(!last||last.effect.identity.attempt!==s.attempt||!documentationSyncSource(last))return null;
|
|
378
|
+
return s.state==='unknown'&&s.code===last.result.code&&recorded<MAX_DOCUMENTATION_SYNC_RETRIES?s.code:null;
|
|
379
|
+
}
|
|
380
|
+
const documentationSyncCauses={
|
|
381
|
+
documentation_sync_answer_missing:'文档同步没有拿到应答(超时、断开、迟到被拒或宿主核对时出错)',
|
|
382
|
+
documentation_sync_answer_invalid:'文档同步的应答格式不合格(只接受 {"status":"completed"} 或 {"status":"blocked"})',
|
|
383
|
+
documentation_sync_answer_blocked:'文档同步答复 blocked,文档没有同步完',
|
|
384
|
+
documentation_sync_out_of_scope:'文档同步改了文档路径以外的文件',
|
|
385
|
+
documentation_sync_interrupted:'宿主在文档同步中途退出'};
|
|
386
|
+
const documentationDetail=(code,detail)=>{
|
|
387
|
+
if(typeof detail!=='string'||!detail)return '';
|
|
388
|
+
if(code==='documentation_sync_out_of_scope'){
|
|
389
|
+
const paths=detail.replace(/^out_of_scope:\s*/,'').split(/,\s*/).filter(Boolean).slice(0,20);
|
|
390
|
+
return paths.length?`:${paths.join(', ')}`:'';
|
|
391
|
+
}
|
|
392
|
+
return code==='documentation_sync_answer_missing'&&/^[a-z_]{1,64}$/.test(detail)?`(${detail})`:'';
|
|
393
|
+
};
|
|
394
|
+
const DOCUMENTATION_SYNC_TAIL='只重发文档同步,复用运行存档里已记录的开发应答,不重发开发;盘上的开发与文档改动保留,审查包仍对照本运行创建时的任务基线,经检查与独立审查;不占调用与 effect 名额(每运行最多 2 次)。';
|
|
395
|
+
const documentationSyncFixes={
|
|
396
|
+
documentation_sync_answer_blocked:'按会话说明补齐或修正文档、解决阻碍;',
|
|
397
|
+
documentation_sync_out_of_scope:'把这些文件还原到文档同步开始时的内容(宿主按运行存档里的摘要核对,没还原就拒绝;确需修改先走规格变更);'};
|
|
398
|
+
const documentationSyncGate='重发前宿主再核对:文档路径以外的文件与文档同步开始时一致,文档路径与确认停写时一致,任一不符就拒绝、不写记录。';
|
|
399
|
+
// Before the confirmation: shown as blocked with pendingAction develop_redo.
|
|
400
|
+
export const documentationSyncStopReason=(code,detail=null)=>`${code}: 开发已应答并写入运行存档,但${documentationSyncCauses[code]}${documentationDetail(code,detail)}。`
|
|
401
|
+
+'宿主无法证明会话已停止修改文档(没应答可能只是还没写,已应答也只结束了宿主的等待);'
|
|
402
|
+
+`先确认会话已停止修改文档,${documentationSyncFixes[code]??''}再以 --mode resume --allow-develop-redo 启动并发送 develop_redo(单行 reason,写入运行存档);之后 advance `
|
|
403
|
+
+DOCUMENTATION_SYNC_TAIL+documentationSyncGate;
|
|
404
|
+
// After the confirmation (documentation-sync-retry or effect-interrupted).
|
|
405
|
+
export const documentationSyncRetryReason=(code,detail=null)=>`${code}: ${documentationSyncCauses[code]}${documentationDetail(code,detail)};`
|
|
406
|
+
+(code===DOCUMENTATION_SYNC_INTERRUPTED_CODE?'操作员已确认旧宿主与会话停止写入(effect-interrupted)。':'操作员已确认会话停止修改文档(documentation-sync-retry)。')
|
|
407
|
+
+'在原运行 advance '+DOCUMENTATION_SYNC_TAIL+documentationSyncGate+'确认之后若你又改了文档,再发送一次 develop_redo 重新确认(不另占次数)。';
|
|
408
|
+
export const documentationSyncLimitReason=source=>`${DOCUMENTATION_SYNC_LIMIT_CODE}: 文档同步重发(原记录 ${source})已在本运行用满 ${MAX_DOCUMENTATION_SYNC_RETRIES} 次,不再重发。`
|
|
409
|
+
+'先查清会话为何一直不应答、答复 blocked 或越界写文件;修好后用 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做,'
|
|
410
|
+
+'本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift 作为已有代码记录。';
|
|
411
|
+
export const developDispatchReason=source=>`${DISPATCH_RETRY_CODE}: 开发请求在派发给会话之前失败(原记录 unknown/${source})`
|
|
412
|
+
+(DISPATCH_FAILURE_CODES.includes(source)?',宿主自己的角色路由出错,未派发':'')+',代码根仍与本轮开发起点一致(每次重发前再核对)'
|
|
413
|
+
+'。修好 reason 指出的宿主环境(运行日志写入、工作流角色配置)后在原运行 advance 用新 effect id 重发本轮开发;不占调用与 effect 名额(每运行最多 2 次)。';
|
|
414
|
+
const redoCauses={call_timeout:'开发应答超时且代码根已变化或本轮起点无法核对',
|
|
415
|
+
role_log_failed:'开发请求派发前宿主运行日志写入失败,但代码根已变化或本轮起点无法核对',
|
|
416
|
+
invalid_workflow_config:'开发请求派发前工作流角色配置无效,但代码根已变化或本轮起点无法核对',unknown:'开发应答中断(会话断开、应答形状错或结果不明)',
|
|
417
|
+
execution_error:'开发调用以 execution_error 结束、结果不明',failed:'开发应答只回了 failed、没有可用结果',
|
|
418
|
+
provider_call_timeout:'provider 开发进程超时、结果不明',provider_unknown:'provider 开发进程中断或输出无法解析、结果不明',
|
|
419
|
+
provider_failed:'provider 开发提案未通过本地校验',provider_unavailable:'provider 开发进程启动失败或报告失败'};
|
|
420
|
+
const providerCause=cause=>String(cause).startsWith('provider_');
|
|
421
|
+
export const developRedoRequiredReason=cause=>providerCause(cause)
|
|
422
|
+
?`${DEVELOP_REDO_CODE}: ${redoCauses[cause]??cause}。provider 进程组可能仍在写文件;以 --mode resume --allow-develop-redo 启动并发送 develop_redo(单行 reason),`
|
|
423
|
+
+'宿主先按运行存档里记下的进程身份(pid、启动时间)核对进程组已退出,核对不了(Windows、无权限、读不到启动时间)就拒绝。'
|
|
424
|
+
+'之后 advance 用新 effect id 重发本轮开发:盘上改动保留,审查包仍对照本运行创建时的任务基线,经检查与独立审查;不占调用与 effect 名额(每运行最多 2 次)。'
|
|
425
|
+
:`${DEVELOP_REDO_CODE}: ${redoCauses[cause]??cause}。会话可能仍在写文件,宿主看不到;`
|
|
426
|
+
+'先确认会话已停止修改代码,再以 --mode resume --allow-develop-redo 启动并发送 develop_redo(单行 reason,写入运行存档)。'
|
|
427
|
+
+'之后 advance 用新 effect id 重发本轮开发:盘上改动保留,审查包仍对照本运行创建时的任务基线,经检查与独立审查;不占调用与 effect 名额(每运行最多 2 次)。';
|
|
428
|
+
export const developRedoReason=cause=>`${DEVELOP_REDO_CODE}: ${redoCauses[cause]??cause};`
|
|
429
|
+
+(providerCause(cause)?'宿主已核对 provider 进程组退出(develop-answer-redo)。':'操作员已确认会话停写(develop-answer-redo)。')
|
|
430
|
+
+'在原运行 advance 用新 effect id 重发本轮开发;盘上改动保留并经检查与独立审查,审查轮次不变。';
|
|
431
|
+
// V8: the host died with an effect intent and no checkpoint. abandon_effect
|
|
432
|
+
// journals effect-interrupted instead of voiding the run: the pending effect is
|
|
433
|
+
// retired (it never got a slot) and the run continues from the step's own
|
|
434
|
+
// retryable block. A develop becomes blocked/develop_interrupted and is redone
|
|
435
|
+
// under a new effect id; edits already on disk stay and are reviewed against
|
|
436
|
+
// the task baseline captured at create (never re-captured). A review that was
|
|
437
|
+
// never registered returns to awaiting_review. A completion without a
|
|
438
|
+
// task-commit-intent returns to the state it started from. Old journals keep
|
|
439
|
+
// their records; their effect-abandoned records still end the run.
|
|
440
|
+
export const DEVELOP_INTERRUPTED_CODE='develop_interrupted';
|
|
441
|
+
export const developInterruptedReason=provider=>`${DEVELOP_INTERRUPTED_CODE}: 宿主在本轮开发中途退出,开发意图已登记但结果没写入;`
|
|
442
|
+
+(provider?'宿主已核对 provider 进程组退出(或进程从未启动)。':'操作员已确认会话停写。')
|
|
443
|
+
+'在原运行 advance 用新 effect id 重发本轮开发:盘上改动保留,审查包仍对照本运行创建时的任务基线,经检查与独立审查;不占调用与 effect 名额。';
|
|
444
|
+
// A45: the host died after task-commit-intent and before its result. Shown
|
|
445
|
+
// instead of unknown/reconciliation_required; complete then follows only the
|
|
446
|
+
// journaled commit plan (tasks.md before or after, never a redone completion).
|
|
447
|
+
export const COMMIT_INTERRUPTED_CODE='complete_commit_interrupted';
|
|
448
|
+
export const COMMIT_INTERRUPTED_REASON=`${COMMIT_INTERRUPTED_CODE}: 宿主在写入任务完成的提交意图之后、提交结果之前退出,tasks.md 可能已勾选也可能未勾选。`
|
|
449
|
+
+'发送 complete:宿主只按运行存档里的提交计划核对 tasks.md——已是提交后的内容就补记结果;仍是提交前的内容且证据文件未变、代码仍等于审查通过的交付,就按原计划写完;其余情况拒绝并保留现场。不重新复查、不重新开发。';
|
|
450
|
+
export const REVIEW_INTERRUPTED_REASON='review_interrupted: 宿主在审查登记前退出,审查没有派发;在原运行 advance 重新取得本轮审查授权并派发,不占重派次数。';
|
|
451
|
+
// A pending develop's round start as the journal pins it (see pinnedDevelopStart):
|
|
452
|
+
// nothing of this attempt may have been accepted or left unrecorded edits.
|
|
453
|
+
export const pendingDevelopStart=s=>pinnedDevelopStart(s,entry=>developDispatchFailedEffect(entry)||developTimeoutEffect(entry),s.cache.length-1);
|
|
454
|
+
// The same start for a checkpointed provider develop being redone (it is the
|
|
455
|
+
// last cache entry; earlier redo sources of this attempt produced nothing accepted).
|
|
456
|
+
export const redoDevelopStart=s=>pinnedDevelopStart(s,entry=>developDispatchFailedEffect(entry)||developTimeoutEffect(entry)||developRedoSource(entry));
|
|
457
|
+
// What may sit between a pending intent and an effect-interrupted record.
|
|
458
|
+
// documentation-sync-started (Q16) keeps a host death during the sync interruptible as before.
|
|
459
|
+
const INTERRUPTIBLE_TRAILERS={develop:['control','develop-worker','documentation-sync-started'],review:['control','host-joined'],complete:['control']};
|
|
460
|
+
// A provider develop that ended without a usable result is, like a current-session
|
|
461
|
+
// one, a redo source (developRedoCause): it holds no call or effect slot either.
|
|
462
|
+
export const developRedoSource=entry=>developAnswerMissingEffect(entry)||providerStuckCause(entry)!==null;
|
|
69
463
|
export const countedCalls=(calls,cache)=>calls.filter(call=>!invalidDeveloperCall(call)&&call.terminal!=='abandoned').length
|
|
70
|
-
-cache.filter(timeoutEffect).length
|
|
464
|
+
-cache.filter(timeoutEffect).length-cache.filter(developTimeoutEffect).length-cache.filter(developAnswerInvalidEffect).length
|
|
465
|
+
-cache.filter(developRedoSource).length-cache.filter(developDispatchFailedEffect).length
|
|
466
|
+
-cache.filter(documentationSyncSource).length;
|
|
71
467
|
// A review effect whose journaled result the operator abandoned (below) no
|
|
72
468
|
// longer holds one of the six effect slots; its retry does.
|
|
73
469
|
const abandonedResult=(entry,calls)=>entry.effect.kind==='review'&&entry.result.state==='unknown'
|
|
74
|
-
&&calls.some(call=>call.terminal==='abandoned'&&call.invocationId===entry.result.reviewInvocation?.registration?.
|
|
470
|
+
&&calls.some(call=>call.terminal==='abandoned'&&call.invocationId===entry.result.reviewInvocation?.registration?.binding?.invocationId);
|
|
75
471
|
// Completion holds no effect slot. It makes no provider call, it is admitted
|
|
76
472
|
// only from an approved review (stageAllowed), and every outcome but a
|
|
77
473
|
// completion re-check block ends the run; those blocks have their own bound,
|
|
@@ -83,7 +479,9 @@ const completionBlock=entry=>entry.effect.kind==='complete'&&entry.result.state=
|
|
|
83
479
|
export const completionBlockCount=cache=>cache.filter(completionBlock).length;
|
|
84
480
|
export const completedEffectCount=(cache,calls=[])=>cache.filter(entry=>!(entry.effect.kind==='develop'
|
|
85
481
|
&&entry.result.state==='blocked'&&['developer_result_invalid','check_output_out_of_scope'].includes(entry.result.code))
|
|
86
|
-
&&!timeoutEffect(entry)&&!
|
|
482
|
+
&&!timeoutEffect(entry)&&!developTimeoutEffect(entry)&&!developAnswerInvalidEffect(entry)&&!developRecheckSource(entry)
|
|
483
|
+
&&!developRedoSource(entry)&&!developDispatchFailedEffect(entry)&&!documentationSyncSource(entry)
|
|
484
|
+
&&!abandonedResult(entry,calls)&&entry.effect.kind!=='complete').length;
|
|
87
485
|
// The six-effect cap counts develop and review effects only; completion (above),
|
|
88
486
|
// QA, documentation and finalization hold no slot.
|
|
89
487
|
export const MAX_RUNNER_EFFECTS=6;
|
|
@@ -99,8 +497,9 @@ export const effectSlotFree=(kind,cache,calls)=>kind==='complete'||completedEffe
|
|
|
99
497
|
export const developBudget=s=>({calls:countedCalls(s.calls,s.cache),effects:completedEffectCount(s.cache,s.calls)});
|
|
100
498
|
export const developBudgetExhausted=s=>{
|
|
101
499
|
if(!stageAllowed('develop',s.state,s.code,s.priorReview?.verdict))return false;
|
|
102
|
-
|
|
103
|
-
|
|
500
|
+
// A re-check makes no developer call: only its review needs one.
|
|
501
|
+
const used=developBudget(s),calls=RECHECK_CODES.includes(s.code)?1:2;
|
|
502
|
+
return used.calls+calls>MAX_RUNNER_CALLS||used.effects+2>MAX_RUNNER_EFFECTS;
|
|
104
503
|
};
|
|
105
504
|
// At most this many re-checks after a blocked completion. Each re-runs only the
|
|
106
505
|
// local checks and the commit gate, so a small fixed bound keeps the journal
|
|
@@ -120,16 +519,40 @@ export const developRetryLimitReason=({countedCalls:calls,countedEffects:effects
|
|
|
120
519
|
// failure of a class that is now retried automatically but was recorded as
|
|
121
520
|
// unknown (older versions, or after a final message). Nothing ever accepted its
|
|
122
521
|
// verdict, so, exactly like an interrupted registered review, the operator may
|
|
123
|
-
// abandon it and spend the
|
|
124
|
-
//
|
|
125
|
-
|
|
522
|
+
// abandon it and spend one of the round's MAX_REVIEW_REDISPATCHES. A Claude reviewer stopped
|
|
523
|
+
// at its boundary (unexpected_tool_or_content) qualifies only under
|
|
524
|
+
// abandonableReviewerExit: process closed, nothing received, and a rejection
|
|
525
|
+
// that cannot have run a tool. Other tool, context and output limit breaks,
|
|
526
|
+
// observation_invalid and legacy timed_out without inspection stay out.
|
|
527
|
+
// A journaled review end with no accepted verdict that the operator may abandon:
|
|
528
|
+
// a timeout, a fixed provider failure, a Claude boundary exit that cannot have
|
|
529
|
+
// run a tool (abandonableReviewerExit), or (V5, A33) an end whose reviewer
|
|
530
|
+
// process the worker proved gone without a final message (reviewerGoneWithoutResult).
|
|
531
|
+
export const abandonableReviewOutcome=result=>result?.inspection!=null&&result.reconciliationRequired===true
|
|
532
|
+
&&(result.outcome==='timed_out'||result.outcome==='unknown'
|
|
533
|
+
&&(Object.hasOwn(REVIEWER_PROVIDER_FAILURES,result.observation?.result?.code)
|
|
534
|
+
||result.inspection.provider==='claude'&&abandonableReviewerExit(result.observation)
|
|
535
|
+
||reviewerGoneWithoutResult(result.observation)));
|
|
536
|
+
export function abandonableReviewResult(s,contextId,records=0){
|
|
126
537
|
const entry=s.cache.at(-1),result=s.reviewInvocation?.result;
|
|
127
538
|
return s.state==='unknown'&&entry?.effect.kind==='review'&&entry.effect.identity.attempt===s.attempt
|
|
128
|
-
&&entry.result.state==='unknown'&&result
|
|
129
|
-
&&
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
539
|
+
&&entry.result.state==='unknown'&&abandonableReviewOutcome(result)
|
|
540
|
+
&&entry.result.reviewInvocation?.registration?.binding?.invocationId===s.reviewInvocation.registration?.binding?.invocationId
|
|
541
|
+
&&reviewRedispatchCount(s.cache,s.calls,s.attempt,contextId,records)<MAX_REVIEW_REDISPATCHES;
|
|
542
|
+
}
|
|
543
|
+
// R4: why a no-verdict review end cannot be abandoned, with its real exit.
|
|
544
|
+
export function reviewAbandonRefusal(s,contextId,records=0){
|
|
545
|
+
const entry=s.cache.at(-1),result=s.reviewInvocation?.result;
|
|
546
|
+
if(s.state!=='unknown'||entry?.effect.kind!=='review'||entry.effect.identity.attempt!==s.attempt||!result||result.outcome==='observed')return null;
|
|
547
|
+
if(reviewRedispatchCount(s.cache,s.calls,s.attempt,contextId,records)>=MAX_REVIEW_REDISPATCHES)
|
|
548
|
+
return {code:'review_abandon_budget_exhausted',reason:`本轮独立审查已无结论重派 ${MAX_REVIEW_REDISPATCHES} 次,不能再放弃重派;查清原因后用 --supersede-reviewed-evidence 新建运行重做。`};
|
|
549
|
+
if(result.observation?.result?.code==='process_cleanup_unknown')
|
|
550
|
+
return {code:'review_process_unverified',reason:'审查 worker 报告进程组清理结果不明(process_cleanup_unknown),宿主无法证明旧审查进程已退出,不放行重派;手工确认该进程组已不存在后,用 --supersede-reviewed-evidence 新建运行重做。'};
|
|
551
|
+
if(result.inspection==null)
|
|
552
|
+
return {code:'review_observation_invalid',reason:'审查事件流本身不合法(observation_invalid),宿主无法判断审查进程是否给出过结论,不放行重派;核对原审查证据后用 --supersede-reviewed-evidence 新建运行重做。'};
|
|
553
|
+
if(!abandonableReviewOutcome(result))
|
|
554
|
+
return {code:'review_boundary_unverified',reason:'审查进程越界(工具或内容边界)后退出,或退出时可能已收到结论,宿主不能证明重派安全;核对原审查证据与磁盘后用 --supersede-reviewed-evidence 新建运行重做。'};
|
|
555
|
+
return null;
|
|
133
556
|
}
|
|
134
557
|
export function validateTaskLearningReviewPackage(rawPackage,writeback,learningInput,bootstrap=null,configuration=null) {
|
|
135
558
|
validTaskLearningInput(learningInput,learningInput.identity,learningInput.feature);
|
|
@@ -193,7 +616,7 @@ export function runnerStatus(s,config) {
|
|
|
193
616
|
export function controlledState(state,event,outstanding,version=1) {
|
|
194
617
|
const s=structuredClone(state);
|
|
195
618
|
const unresolvedReview=version===3&&s.reviewInvocation?.result?.reconciliationRequired===true
|
|
196
|
-
&&s.reviewInvocation.registration?.
|
|
619
|
+
&&s.reviewInvocation.registration?.binding?.identity?.attempt===s.attempt;
|
|
197
620
|
if(event==='workflow-error') {s.workflowError='workflow_error';if(!outstanding && s.state!=='fixture_completed'
|
|
198
621
|
&& !(s.state==='unknown'&&(version>=2&&s.taskCommit||unresolvedReview))){s.state='blocked';s.code='workflow_error';if(Object.hasOwn(s,'reason'))s.reason=null;}}
|
|
199
622
|
else if(event==='late-cancel'){s.cancelAfterCommit=true;s.cancellationRequested=true;}
|
|
@@ -224,7 +647,10 @@ function callRequest(call,adapter,contextId,role,payload,identity,session,index)
|
|
|
224
647
|
shape(call,['invocationId','contextId','provider','requestedModel','effectiveModel','channel','started','terminal','requestDigest','resultDigest',
|
|
225
648
|
...(Object.hasOwn(call,'providerThreadId')?['providerThreadId']:[]),
|
|
226
649
|
...(Object.hasOwn(call,'failureResult')?['failureResult']:[]),
|
|
227
|
-
...(Object.hasOwn(call,'blockedReason')?['blockedReason']:[])
|
|
650
|
+
...(Object.hasOwn(call,'blockedReason')?['blockedReason']:[]),
|
|
651
|
+
...(Object.hasOwn(call,'documentationSync')?['documentationSync']:[])]);
|
|
652
|
+
// Q16: the documentation-sync-started record this developer call journaled.
|
|
653
|
+
if(Object.hasOwn(call,'documentationSync')){need(role==='developer','runner_call');hex(call.documentationSync);}
|
|
228
654
|
if(Object.hasOwn(call,'blockedReason')){
|
|
229
655
|
need(role==='developer'&&call.terminal==='failed'&&!Object.hasOwn(call,'failureResult'),'runner_call');
|
|
230
656
|
validBlockedReason(call.blockedReason);
|
|
@@ -279,15 +705,19 @@ export function validateReviewDispatchGrant(raw,expected) {
|
|
|
279
705
|
need(digest(grantBody(grant))===grant.grantDigest,'runner_grant');return grant;
|
|
280
706
|
}
|
|
281
707
|
function readRegistration(p,before,effect,config,session,carried=null) {
|
|
282
|
-
|
|
708
|
+
need(!Object.hasOwn(p,'grant')&&!Object.hasOwn(p,'authorizationAt'),'runner_invocation');
|
|
709
|
+
shape(p,['version','protocol','type','effectId','reviewerId','adapterId','requestDigest','registeredAt','binding']);
|
|
283
710
|
need(p.effectId===effect.id,'runner_invocation');
|
|
284
|
-
const request=reviewRequest(before,config,session,carried),reviewer=config.reviewers[0];
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
711
|
+
const request=reviewRequest(before,config,session,carried),reviewer=config.reviewers[0],binding=json(p.binding);
|
|
712
|
+
shape(binding,['adapterId','invocationId','requestDigest','identity','reviewerId','logicalContextId','packageDigest','hostContextId']);
|
|
713
|
+
id(binding.hostContextId);need(Number.isSafeInteger(p.registeredAt),'runner_invocation');
|
|
714
|
+
need([config.reviewInvocation.developerThreadId,...config.reviewInvocation.excludedThreadIds].includes(binding.hostContextId),'runner_invocation');
|
|
715
|
+
same(binding,{adapterId:reviewer.adapterId,invocationId:request.invocationId,requestDigest:request.requestDigest,
|
|
716
|
+
identity:request.identity,reviewerId:reviewer.id,logicalContextId:request.contextId,
|
|
717
|
+
packageDigest:before.reviewPackage.packageDigest,hostContextId:binding.hostContextId});
|
|
718
|
+
need(p.reviewerId===reviewer.id&&p.adapterId===reviewer.adapterId&&p.requestDigest===request.requestDigest,'runner_invocation');
|
|
289
719
|
return {request,record:json({reviewerId:p.reviewerId,adapterId:p.adapterId,requestDigest:p.requestDigest,
|
|
290
|
-
|
|
720
|
+
registeredAt:p.registeredAt,binding})};
|
|
291
721
|
}
|
|
292
722
|
function readStarted(p,registration,effect,config) {
|
|
293
723
|
shape(p,['version','protocol','type','effectId','invocationId','providerThreadId']);
|
|
@@ -300,9 +730,7 @@ function readInvocationResult(p,registration,started,effect,config) {
|
|
|
300
730
|
const common=['version','protocol','type','effectId','invocationId','dispatchAt','outcome','observation','inspection','reconciliationRequired'];
|
|
301
731
|
need(p.effectId===effect.id&&p.invocationId===registration.request.invocationId,'runner_invocation');
|
|
302
732
|
need(typeof p.reconciliationRequired==='boolean','runner_invocation');
|
|
303
|
-
|
|
304
|
-
else need(Number.isSafeInteger(p.dispatchAt)&®istration.record.registeredAt<=p.dispatchAt
|
|
305
|
-
&&p.dispatchAt<registration.record.grant.expiresAt,'runner_invocation');
|
|
733
|
+
need(Number.isSafeInteger(p.dispatchAt)&®istration.record.registeredAt===p.dispatchAt,'runner_invocation');
|
|
306
734
|
const expectation={request:registration.request,developerThreadId:config.reviewInvocation.developerThreadId,
|
|
307
735
|
excludedThreadIds:config.reviewInvocation.excludedThreadIds};
|
|
308
736
|
let inspected=null;
|
|
@@ -337,11 +765,6 @@ function readInvocationResult(p,registration,started,effect,config) {
|
|
|
337
765
|
const failure=inspectProviderReviewFailure(JSON.stringify(observation),JSON.stringify(expectation));
|
|
338
766
|
need(failure!==null,'runner_invocation');same(p.inspection,failure);
|
|
339
767
|
need(failure.providerThreadId===started,'runner_invocation');
|
|
340
|
-
} else if(p.outcome==='not_dispatched') {
|
|
341
|
-
shape(p,[...common,'reason']);need(['grant_expired','clock_invalid'].includes(p.reason)
|
|
342
|
-
&&p.observation===null&&p.inspection===null&&p.reconciliationRequired===true&&started===null,'runner_invocation');
|
|
343
|
-
need(p.reason==='grant_expired'?Number.isSafeInteger(p.dispatchAt)&&p.dispatchAt>=registration.record.grant.expiresAt:
|
|
344
|
-
p.dispatchAt===null||p.dispatchAt<registration.record.registeredAt,'runner_invocation');
|
|
345
768
|
} else need(false,'runner_invocation');
|
|
346
769
|
return json(Object.fromEntries(Object.entries(p).filter(([key])=>!['version','protocol','type','effectId','invocationId'].includes(key))),512*1024);
|
|
347
770
|
}
|
|
@@ -349,15 +772,15 @@ function invocationCall(call,registration,started,result,before) {
|
|
|
349
772
|
shape(call,['invocationId','contextId','provider','requestedModel','effectiveModel','channel','started','terminal','requestDigest','resultDigest','providerThreadId']);
|
|
350
773
|
const request=registration.request;need(call.invocationId===request.invocationId&&call.contextId===request.contextId
|
|
351
774
|
&&call.provider===request.provider&&call.requestedModel===request.requestedModel&&call.effectiveModel==='unknown'
|
|
352
|
-
&&call.channel==='host-
|
|
775
|
+
&&call.channel==='host-review'&&call.requestDigest===request.requestDigest
|
|
353
776
|
&&call.providerThreadId===started,'runner_call');
|
|
354
777
|
const expectedTerminal=result.outcome==='observed'?'succeeded':result.outcome==='cancelled'?'cancelled':
|
|
355
|
-
|
|
356
|
-
need(call.started===
|
|
778
|
+
reviewTransportTimeout(result)||reviewerFailure(result)?'failed':'unknown';
|
|
779
|
+
need(call.started===true&&call.terminal===expectedTerminal
|
|
357
780
|
&&call.resultDigest===digest(result.outcome==='observed'?result.inspection.review:result)
|
|
358
781
|
&&before.sequence+1===Number(request.invocationId.split('.').at(-1)),'runner_call');
|
|
359
782
|
}
|
|
360
|
-
function checkpoint(before,raw,effect,config,original,session,controls,version=1,taskCommit=null,invocation=null,carried=null) {
|
|
783
|
+
function checkpoint(before,raw,effect,config,original,session,controls,version=1,taskCommit=null,invocation=null,carried=null,documentation=null) {
|
|
361
784
|
const s=json(raw,LIMIT);
|
|
362
785
|
shape(s,['state','code','attempt','session','sequence','reviewPackage','currentChecks','receipt','receipts','calls','cache',
|
|
363
786
|
...(Object.hasOwn(s,'reason')?['reason']:[]),
|
|
@@ -391,12 +814,28 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
391
814
|
if(effect.kind!=='develop'&&Object.hasOwn(config,'taskLearning'))same(s.learningResult,before.learningResult);
|
|
392
815
|
if(effect.kind==='develop') {
|
|
393
816
|
need(added.length<=1 && s.receipts.length===before.receipts.length,'runner_develop');same(s.receipt,null);same(s.priorReview,before.priorReview);
|
|
817
|
+
// A re-check (develop-recheck) dispatches no developer: it keeps the Learning
|
|
818
|
+
// result and stands on the developer call that already succeeded.
|
|
819
|
+
const recheck=before.state==='blocked'&&RECHECK_CODES.includes(before.code);
|
|
820
|
+
if(recheck){need(added.length===0&&before.learningResult!=null&&before.calls.at(-1)?.terminal==='succeeded','runner_develop');
|
|
821
|
+
same(s.learningResult,before.learningResult);}
|
|
822
|
+
const developerCall=recheck?before.calls.at(-1):added[0];
|
|
394
823
|
if(added.length)callRequest(added[0],config.developer,config.developer.contextId,'developer',{
|
|
395
824
|
scope:config.scope,requirements:original.files.filter(f=>config.requirements.includes(f.path)),priorReview:before.priorReview,
|
|
396
825
|
...supersededReviewPayload(carried,before.attempt),
|
|
397
826
|
...(Object.hasOwn(original,'specification')?{specification:original.specification}:{}),
|
|
398
827
|
...(Object.hasOwn(effect,'learningInput')?{learningInput:effect.learningInput}:{})
|
|
399
828
|
},identity,session,before.calls.length+1);
|
|
829
|
+
// Q16: a developer call carries the documentation-sync-started record it
|
|
830
|
+
// journaled (exactly that one), and a delivery is the answer it recorded.
|
|
831
|
+
need((added[0]?.documentationSync??null)===(documentation?.digest??null),'runner_documentation');
|
|
832
|
+
if(documentation&&added[0].terminal==='succeeded')
|
|
833
|
+
need(added[0].resultDigest===digest(documentation.payload.result),'runner_documentation');
|
|
834
|
+
if(s.state==='unknown'&&DOCUMENTATION_SYNC_CODES.includes(s.code))
|
|
835
|
+
need(documentation!==null&&added[0].terminal==='unknown'&&added[0].resultDigest===null,'runner_documentation');
|
|
836
|
+
// A documentation-only redo of the final task's develop journals a sync again.
|
|
837
|
+
if(before.state==='blocked'&&DOCUMENTATION_SYNC_CODES.includes(before.code)&&added[0]?.terminal==='succeeded')
|
|
838
|
+
need(documentation!==null,'runner_documentation');
|
|
400
839
|
// A live-session init_verify that did not pass: the host wrote nothing, and
|
|
401
840
|
// the develop keeps exactly the Learning/bootstrap evidence it started from.
|
|
402
841
|
const verificationFailed=added[0]?.terminal==='failed'&&added[0].failureResult?.code==='bootstrap_verification_failed';
|
|
@@ -431,8 +870,8 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
431
870
|
same(application.identity,effect.learningInput.identity);}
|
|
432
871
|
const writeback=readCmAiProjectLearningWriteback(s.learningResult.writeback,
|
|
433
872
|
{learningInput:effect.learningInput,retrospective:s.learningResult.retrospective});
|
|
434
|
-
need(added.length===1&&
|
|
435
|
-
same(
|
|
873
|
+
need((recheck||added.length===1)&&developerCall?.terminal==='succeeded','runner_learning');
|
|
874
|
+
same(developerCall.resultDigest,digest({outcome:'implemented',...(hasApplication?{application}:{}),
|
|
436
875
|
retrospective:s.learningResult.retrospective,...(hasBootstrap?{bootstrap:s.learningResult.bootstrap}:{})}));
|
|
437
876
|
if(writeback.outcome==='writeback_pending'){
|
|
438
877
|
expectedState='blocked';expectedCode='learning_writeback_pending';
|
|
@@ -450,7 +889,7 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
450
889
|
?{outcome:'implemented',...(s.learningResult&&Object.hasOwn(s.learningResult,'application')
|
|
451
890
|
?{application:s.learningResult.application}:{}),retrospective:s.learningResult?.retrospective,
|
|
452
891
|
...(s.learningResult?.bootstrap?{bootstrap:s.learningResult.bootstrap}:{})}:{outcome:'implemented'};
|
|
453
|
-
need(added.length===1 &&
|
|
892
|
+
need((recheck||added.length===1) && developerCall?.terminal==='succeeded' && developerCall.resultDigest===digest(developerResult),'runner_develop');
|
|
454
893
|
if(Object.hasOwn(config,'taskLearning'))need(s.learningResult!==null
|
|
455
894
|
&&s.learningResult.writeback.outcome!=='writeback_pending','runner_learning');
|
|
456
895
|
packageLink(s.reviewPackage,original,before.attempt,s.currentChecks);
|
|
@@ -462,7 +901,7 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
462
901
|
// between the checks and the review package. No package exists, so no review
|
|
463
902
|
// round was spent; the attempt counter does not move either.
|
|
464
903
|
// develop_unchanged_after_review: attempt 2 matched the rejected attempt-1 artifact.
|
|
465
|
-
if(
|
|
904
|
+
if(developerCall?.terminal==='succeeded'&&['verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large'].includes(s.code)) {
|
|
466
905
|
// s.receipt is null for every develop checkpoint (above); at attempt 2 the
|
|
467
906
|
// state before still holds the attempt-1 receipt, so only receipts compare.
|
|
468
907
|
need(digest(s.reviewPackage)===digest(before.reviewPackage),'runner_develop');
|
|
@@ -497,9 +936,8 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
497
936
|
need(!invocation?.result&&added.length===0&&s.sequence===before.sequence,'runner_invocation');
|
|
498
937
|
same(s.reviewInvocation,before.reviewInvocation);same(s.receipt,before.receipt);same(s.receipts,before.receipts);same(s.priorReview,before.priorReview);
|
|
499
938
|
if(controls.cancelled===true){expectedState='cancelled';expectedCode='cancelled';}
|
|
500
|
-
else if(s.code==='permission_denied')expectedState='pending_review';
|
|
501
939
|
else if(Object.hasOwn(original,'specification')&&s.code==='spec_drift')expectedState='blocked';
|
|
502
|
-
else {need(
|
|
940
|
+
else {need(s.code==='clock_invalid','runner_invocation');expectedState='unknown';}
|
|
503
941
|
expectedCode??=s.code;
|
|
504
942
|
} else {
|
|
505
943
|
need(invocation.result&&added.length===1,'runner_invocation');
|
|
@@ -524,7 +962,6 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
524
962
|
}
|
|
525
963
|
}
|
|
526
964
|
else if(invocation.result.outcome==='cancelled'){need(controls.cancelled===true,'runner_control');expectedState='cancelled';expectedCode='cancelled';}
|
|
527
|
-
else if(invocation.result.outcome==='not_dispatched'){expectedState='pending_review';expectedCode=invocation.result.reason;}
|
|
528
965
|
else {const retry=reviewTimeoutTransition(invocation.result,before.cache,before.attempt,before.calls,
|
|
529
966
|
config.reviewers[0].contexts[before.attempt-1]);
|
|
530
967
|
expectedState=retry?.state??'unknown';expectedCode=retry?.code??invocation.result.reason??invocation.result.inspection?.code??'reconciliation_required';}
|
|
@@ -570,7 +1007,7 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
570
1007
|
expectedState='blocked';
|
|
571
1008
|
if(['completion_checks_changed','completion_package_changed'].includes(s.code)){
|
|
572
1009
|
need(effect.kind==='complete'&&['approved','blocked'].includes(before.state)
|
|
573
|
-
&&(before.state==='approved'||['completion_checks_changed','completion_package_changed','review_package_changed'].includes(before.code)),'runner_transition');
|
|
1010
|
+
&&(before.state==='approved'||['completion_checks_changed','completion_package_changed','review_package_changed',COMPLETE_RECHECK_CODE].includes(before.code)),'runner_transition');
|
|
574
1011
|
expectedCode=s.code;
|
|
575
1012
|
if(s.code==='completion_package_changed')need(typeof s.reason==='string'&&s.reason.length>0,'runner_diagnostic');
|
|
576
1013
|
}
|
|
@@ -610,6 +1047,23 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
610
1047
|
recovered.cache.at(-1).result=runnerStatus(recovered,config);
|
|
611
1048
|
return recovered;
|
|
612
1049
|
}
|
|
1050
|
+
// A42: since #160 a completion re-check whose check list (ids or commands)
|
|
1051
|
+
// or visual carriers differed from the reviewed package ended in a terminal
|
|
1052
|
+
// package_mismatch whose reason is the bare code; nothing else produced that
|
|
1053
|
+
// reason, and the reviewed code had matched. A retried complete re-verifies
|
|
1054
|
+
// everything. A reason naming changed paths, and the older no-reason shape
|
|
1055
|
+
// (it also covered a Learning handoff mismatch and pre-#160 code drift, so
|
|
1056
|
+
// the journal cannot prove it was only checks), stay terminal.
|
|
1057
|
+
if(effect.kind==='complete'&&s.state==='blocked'&&s.code==='package_mismatch'
|
|
1058
|
+
&&s.reason==='package_mismatch'&&s.taskCommit==null
|
|
1059
|
+
&&(before.state==='approved'||before.state==='blocked'
|
|
1060
|
+
&&[...COMPLETION_RETRY_CODES,'review_package_changed',COMPLETE_RECHECK_CODE].includes(before.code))){
|
|
1061
|
+
const recovered=structuredClone(s);
|
|
1062
|
+
recovered.code='completion_checks_changed';
|
|
1063
|
+
recovered.reason='completion_checks_changed: 旧版本把完成复查与审查包的检查清单或检查证据差异记成了 package_mismatch(代码未变);发送 complete 按审查包的检查清单重新复查并完成。';
|
|
1064
|
+
recovered.cache.at(-1).result=runnerStatus(recovered,config);
|
|
1065
|
+
return recovered;
|
|
1066
|
+
}
|
|
613
1067
|
// Runners before the create-time scope gate dispatched a protected scope and
|
|
614
1068
|
// journaled the adapter's pre-dispatch refusal as unknown/execution_error,
|
|
615
1069
|
// with no exit. Reproject only that exact shape: one developer call that never
|
|
@@ -631,7 +1085,8 @@ function checkpoint(before,raw,effect,config,original,session,controls,version=1
|
|
|
631
1085
|
function completionConfig(config,version){
|
|
632
1086
|
shape(config,['root','identity','scope','requirements','excludedContexts','timeoutMs','developer','reviewers','completion',
|
|
633
1087
|
...(version===3?['reviewInvocation']:[]),...(Object.hasOwn(config,'taskLearning')?['taskLearning']:[]),
|
|
634
|
-
...['bootstrap','codeProjectPaths','knowledgeCloseout','externalModels','executionPolicy'].filter(key=>Object.hasOwn(config,key))]);
|
|
1088
|
+
...['bootstrap','codeProjectPaths','knowledgeCloseout','externalModels','executionPolicy','controlPolicy'].filter(key=>Object.hasOwn(config,key))]);
|
|
1089
|
+
if(Object.hasOwn(config,'controlPolicy')){same(config.controlPolicy,readControlPolicy(config.controlPolicy));need(version===3,'runner_version');}
|
|
635
1090
|
if(Object.hasOwn(config,'knowledgeCloseout'))readCloseoutPolicy(config.knowledgeCloseout);
|
|
636
1091
|
if(Object.hasOwn(config,'executionPolicy')){same(config.executionPolicy,readExecutionPolicy(config.executionPolicy));need(version===3,'execution_policy_runner_version');}
|
|
637
1092
|
if(Object.hasOwn(config,'externalModels')){same(config.externalModels,readExternalModels(config.externalModels));need(version===3,'external_model_runner_version');}
|
|
@@ -686,6 +1141,29 @@ function completionConfig(config,version){
|
|
|
686
1141
|
}
|
|
687
1142
|
return c;
|
|
688
1143
|
}
|
|
1144
|
+
const workerSummary=w=>({journal:w.journal===true,spawned:w.spawning!==null,started:w.started,
|
|
1145
|
+
applies:w.applies.map(item=>({started:item.started}))});
|
|
1146
|
+
// What a redo, interruption or void record names when the host proved every
|
|
1147
|
+
// started writer's process group gone: the provider worker and each sandbox
|
|
1148
|
+
// subprocess that applied a protected proposal (the exact develop-worker
|
|
1149
|
+
// records it checked). null: nothing was started, so there is nothing to prove.
|
|
1150
|
+
export const workerGoneBinding=summary=>{
|
|
1151
|
+
const worker=summary?.started??null,applies=(summary?.applies??[]).filter(item=>item.started).map(item=>item.started);
|
|
1152
|
+
if(worker===null&&!applies.length)return null;
|
|
1153
|
+
return {worker:worker&&{recordDigest:worker.digest,pid:worker.pid},
|
|
1154
|
+
applies:applies.map(item=>({recordDigest:item.digest,pid:item.pid})),verdict:'gone'};
|
|
1155
|
+
};
|
|
1156
|
+
// Every writer the journal shows as about to start also journaled its pid.
|
|
1157
|
+
// A pending effect with a spawning record and no pid is unprovable.
|
|
1158
|
+
const writersComplete=w=>(w.spawning===null||w.started!==null)&&w.applies.every(item=>item.started!==null);
|
|
1159
|
+
const bindingMatches=(p,expected)=>expected===null?!Object.hasOwn(p,'worker')
|
|
1160
|
+
:Object.hasOwn(p,'worker')&&digest(p.worker)===digest(expected);
|
|
1161
|
+
// R2: an interrupted step of the same kind is retired at most this many times
|
|
1162
|
+
// per run; afterwards abandon_effect only voids the run (effect-abandoned).
|
|
1163
|
+
export const MAX_EFFECT_INTERRUPTIONS=2;
|
|
1164
|
+
export const EFFECT_INTERRUPT_LIMIT_CODE='effect_interrupt_limit';
|
|
1165
|
+
export const effectInterruptLimitReason=kind=>`${EFFECT_INTERRUPT_LIMIT_CODE}: 宿主中途退出后在原运行内恢复 ${kind} 已用满 ${MAX_EFFECT_INTERRUPTIONS} 次。`
|
|
1166
|
+
+'先查清宿主为何反复中断;确认旧宿主与写入方已退出后,abandon_effect 只能作废本运行(effect-abandoned),再用 --supersede-reviewed-evidence 新建运行。';
|
|
689
1167
|
function fullEnvelope(r,index,previousDigest){
|
|
690
1168
|
shape(r,['version','seq','id','kind','payload','previousDigest','digest']);hex(r.digest);
|
|
691
1169
|
need(r.version===1&&r.seq===index+1&&r.previousDigest===previousDigest,'runner_chain');
|
|
@@ -700,12 +1178,57 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
700
1178
|
let original,session,state,pending=null,beforeIntent=null,controlCount=0,controls={},completeIntentDigest=null,transaction=null;
|
|
701
1179
|
let invocation={registration:null,started:null,result:null};let registrationRecord=null,startedRecord=null,resultRecord=null,lastReview=null;
|
|
702
1180
|
const acceptedFixes=[],joinedHosts=[],reviewerThreads=[];let qaAttachment=null,qaRevision=null,joinedForInvocation=false,supersession=null;
|
|
1181
|
+
const answerGaps={developRecheck:0,completeRecheck:0,developRedo:0,developDispatch:0,documentationSync:0,reviewRedispatch:{1:0,2:0}};
|
|
1182
|
+
// Q16: documentation-sync-started records by digest, and the pending develop's.
|
|
1183
|
+
const documentationRecords=new Map();let pendingDocumentation=null,documentationStop=null;
|
|
1184
|
+
// V8/V9: interrupted intents (their ids are never reused) and the provider
|
|
1185
|
+
// worker records of the pending develop and of every checkpointed develop.
|
|
1186
|
+
const interrupted=[],workers={};let pendingWorker=null;
|
|
703
1187
|
const reviewConfig=(calls=[])=>({...config,reviewInvocation:{...config.reviewInvocation,
|
|
704
1188
|
excludedThreadIds:reviewExclusions({excludedThreadIds:[...config.reviewInvocation.excludedThreadIds,...joinedHosts]},
|
|
705
1189
|
calls,config.developer.contextId)}});
|
|
706
1190
|
const reconciliationBinding=()=>({effectId:lastReview.effect.id,invocationId:lastReview.request.invocationId,
|
|
707
1191
|
registeredDigest:lastReview.registrationRecord.digest,startedDigest:lastReview.startedRecord?.digest??null,
|
|
708
1192
|
resultDigest:lastReview.resultRecord.digest});
|
|
1193
|
+
// A pending effect that effect-interrupted may retire: no task-commit-intent,
|
|
1194
|
+
// not cancelled, a review never registered, and after the intent only the
|
|
1195
|
+
// records its kind may leave behind (controls, a join, worker records).
|
|
1196
|
+
// Q16: the documentation start a pending develop belongs to. Its own once
|
|
1197
|
+
// documentation_sync was asked; before that (a documentation-only redo whose
|
|
1198
|
+
// host died between its intent and its new start record) the start of the
|
|
1199
|
+
// failure the redo was confirmed for, which the intent's prior state names.
|
|
1200
|
+
const documentationOrigin=()=>{
|
|
1201
|
+
if(pending?.kind!=='develop')return null;
|
|
1202
|
+
if(pendingDocumentation!==null)return pendingDocumentation;
|
|
1203
|
+
if(beforeIntent?.state!=='blocked'||!DOCUMENTATION_SYNC_CODES.includes(beforeIntent.code))return null;
|
|
1204
|
+
const digest=beforeIntent.calls.at(-1)?.documentationSync,payload=documentationRecords.get(digest);
|
|
1205
|
+
return payload===undefined?null:{digest,payload};
|
|
1206
|
+
};
|
|
1207
|
+
const pendingInterruptible=(effect,intentIndex,end)=>version===3&&!(config.externalModels||config.executionPolicy)
|
|
1208
|
+
&&effect!==null&&Object.hasOwn(INTERRUPTIBLE_TRAILERS,effect.kind)&&transaction===null&&state.taskCommit?.intentDigest==null
|
|
1209
|
+
&&!controls.cancelled&&!controls.workflowError&&(effect.kind!=='review'||!invocation.registration)
|
|
1210
|
+
&&interrupted.filter(item=>item.kind===effect.kind).length<MAX_EFFECT_INTERRUPTIONS
|
|
1211
|
+
// Q16: one that died during documentation_sync is a documentation retry and
|
|
1212
|
+
// shares that cap; once spent, abandon_effect only voids the run.
|
|
1213
|
+
&&(documentationOrigin()===null||answerGaps.documentationSync<MAX_DOCUMENTATION_SYNC_RETRIES)
|
|
1214
|
+
&&records.slice(intentIndex+1,end).every(row=>INTERRUPTIBLE_TRAILERS[effect.kind].includes(row.payload.type));
|
|
1215
|
+
// A pending develop whose only trailers are controls and worker records may
|
|
1216
|
+
// still be voided (effect-abandoned) once the interruption cap is spent.
|
|
1217
|
+
const pendingWorkerVoidable=(effect,intentIndex,end)=>version===3&&!(config.externalModels||config.executionPolicy)
|
|
1218
|
+
&&effect?.kind==='develop'&&transaction===null&&state.taskCommit?.intentDigest==null
|
|
1219
|
+
&&records.slice(intentIndex+1,end).some(row=>row.payload.type==='develop-worker')
|
|
1220
|
+
&&records.slice(intentIndex+1,end).every(row=>['control','develop-worker'].includes(row.payload.type));
|
|
1221
|
+
const roundRedispatches=()=>reviewRedispatchCount(state.cache,state.calls,state.attempt,
|
|
1222
|
+
config.reviewers[0].contexts[state.attempt-1],answerGaps.reviewRedispatch[state.attempt]);
|
|
1223
|
+
const pendingReviewExhausted=()=>pending?.kind==='review'&&invocation.registration!==null
|
|
1224
|
+
&&(invocation.result===null||invocation.result.outcome!=='observed')&&roundRedispatches()>=MAX_REVIEW_REDISPATCHES;
|
|
1225
|
+
// A38: a pending review whose result reached the journal but whose checkpoint
|
|
1226
|
+
// did not, and the result is a no-verdict end the operator could abandon.
|
|
1227
|
+
const pendingResultAbandonable=()=>!(config.externalModels||config.executionPolicy)&&version===3&&pending?.kind==='review'
|
|
1228
|
+
&&invocation.registration!==null&&invocation.result!==null&&invocation.result.outcome!=='observed'
|
|
1229
|
+
&&!controls.cancelled&&!controls.workflowError
|
|
1230
|
+
&&(abandonableReviewOutcome(invocation.result)||reviewRetryCode(invocation.result)!==null)
|
|
1231
|
+
&&roundRedispatches()<MAX_REVIEW_REDISPATCHES;
|
|
709
1232
|
for(const [index,r] of records.entries()) {
|
|
710
1233
|
if(index>0)need(records[index-1].payload.type!=='effect-abandoned','runner_abandon');
|
|
711
1234
|
boundRunnerRecord(r,index+1);
|
|
@@ -756,15 +1279,22 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
756
1279
|
state.reviewPackage=readReviewPackage(p.reviewPackage);
|
|
757
1280
|
state.state='awaiting_review';state.code=null;state.reason=null;
|
|
758
1281
|
} else if(p.type==='effect-intent') {
|
|
759
|
-
shape(p,[...common,'effect']);need(r.kind==='intent' && pending===null,'runner_intent');
|
|
1282
|
+
shape(p,[...common,'effect',...(Object.hasOwn(p,'workerJournal')?['workerJournal']:[])]);need(r.kind==='intent' && pending===null,'runner_intent');
|
|
760
1283
|
const e=p.effect;shape(e,['version','id','identity','kind',...(Object.hasOwn(e,'learningInput')?['learningInput']:[])]);
|
|
761
1284
|
validIdentity(e.identity);id(e.id);
|
|
1285
|
+
// The marker says this runtime journals the provider worker's identity
|
|
1286
|
+
// (develop-worker) for this effect; only provider development carries it.
|
|
1287
|
+
// Current-session development carries it when protected proposals are
|
|
1288
|
+
// applied by a sandbox subprocess (apply records only).
|
|
1289
|
+
if(Object.hasOwn(p,'workerJournal'))need(version===3&&p.workerJournal===true&&e.kind==='develop','runner_worker');
|
|
1290
|
+
need(!interrupted.some(item=>item.effectId===e.id),'runner_cache');
|
|
1291
|
+
pendingWorker={journal:p.workerJournal===true,spawning:null,started:null,applies:[]};
|
|
762
1292
|
if(e.kind==='develop'&&Object.hasOwn(config,'taskLearning'))need(Object.hasOwn(e,'learningInput'),'runner_learning');
|
|
763
1293
|
if(Object.hasOwn(e,'learningInput')){need(e.kind==='develop'&&Object.hasOwn(config,'taskLearning'),'runner_learning');
|
|
764
1294
|
validTaskLearningInput(e.learningInput,e.identity,config.taskLearning.feature);}
|
|
765
1295
|
same(e.identity,{...config.identity,attempt:state.attempt});need(e.version===1 && stageAllowed(e.kind,state.state,state.code,state.priorReview?.verdict),'runner_stage');
|
|
766
1296
|
need(effectSlotFree(e.kind,state.cache,state.calls) && !state.cache.some(c=>c.effect.id===e.id),'runner_cache');
|
|
767
|
-
pending=e;beforeIntent=structuredClone(state);controls={};completeIntentDigest=e.kind==='complete'?r.digest:null;
|
|
1297
|
+
pending=e;beforeIntent=structuredClone(state);controls={};completeIntentDigest=e.kind==='complete'?r.digest:null;pendingDocumentation=null;documentationStop=null;
|
|
768
1298
|
invocation={registration:null,started:null,result:null};registrationRecord=null;startedRecord=null;resultRecord=null;
|
|
769
1299
|
joinedForInvocation=false;lastReview=null;
|
|
770
1300
|
} else if(version===3&&p.type==='host-joined') {
|
|
@@ -830,6 +1360,126 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
830
1360
|
&&p.fromCode===state.code&&p.countedCalls===used.calls&&p.countedEffects===used.effects,'runner_retry_limit');
|
|
831
1361
|
state.state='blocked';state.code='develop_retry_limit';
|
|
832
1362
|
state.reason=developRetryLimitReason(p);lastReview=null;
|
|
1363
|
+
} else if(version===3&&p.type==='develop-answer-retry') {
|
|
1364
|
+
// Written by advance for a current-session answer the host rejected as
|
|
1365
|
+
// invalid; replay re-derives the whole condition from the journal.
|
|
1366
|
+
shape(p,[...common,'effectId','invocationId']);
|
|
1367
|
+
need(r.kind==='result'&&pending===null&&state.code==='failed'&&developAnswerRetryable(state,config.bootstrap)
|
|
1368
|
+
&&p.effectId===state.cache.at(-1).effect.id&&p.invocationId===state.calls.at(-1).invocationId,'runner_develop_answer');
|
|
1369
|
+
state.code='develop_answer_invalid';state.reason=developAnswerInvalidReason(state.calls.at(-1).failureResult);lastReview=null;
|
|
1370
|
+
} else if(version===3&&p.type==='develop-timeout-retry') {
|
|
1371
|
+
// Written by advance after it found the code root unchanged since the
|
|
1372
|
+
// timed-out develop started; replay re-derives everything but the disk.
|
|
1373
|
+
shape(p,[...common,'effectId','invocationId','basis']);
|
|
1374
|
+
const basis=developTimeoutBasis(state,config.bootstrap);
|
|
1375
|
+
need(r.kind==='result'&&pending===null&&state.state==='unknown'&&basis!==null&&p.basis===basis
|
|
1376
|
+
&&p.effectId===state.cache.at(-1).effect.id&&p.invocationId===state.calls.at(-1).invocationId,'runner_develop_timeout');
|
|
1377
|
+
state.state='blocked';state.code='develop_call_timeout';state.reason=DEVELOP_CALL_TIMEOUT_REASON;lastReview=null;
|
|
1378
|
+
} else if(version===3&&p.type==='develop-recheck') {
|
|
1379
|
+
// Written by advance for a delivered develop whose later checks never got
|
|
1380
|
+
// a usable answer; everything is re-derived from the replayed journal.
|
|
1381
|
+
shape(p,[...common,'effectId','invocationId','code']);
|
|
1382
|
+
const code=developRecheckCode(state,config,answerGaps.developRecheck);
|
|
1383
|
+
need(r.kind==='result'&&pending===null&&state.state==='unknown'&&code!==null&&p.code===code
|
|
1384
|
+
&&p.effectId===state.cache.at(-1).effect.id&&p.invocationId===state.calls.at(-1).invocationId,'runner_develop_recheck');
|
|
1385
|
+
answerGaps.developRecheck++;
|
|
1386
|
+
state.state='blocked';state.code=code;state.reason=developRecheckReason(code,state.cache.at(-1).result.code,state.cache.at(-1).result.reason);lastReview=null;
|
|
1387
|
+
} else if(version===3&&p.type==='develop-answer-redo') {
|
|
1388
|
+
// The operator confirmed the session stopped writing (R3); the redo itself
|
|
1389
|
+
// is the next develop intent. Re-derived from the journal, never the disk.
|
|
1390
|
+
const cause=developRedoCause(state,config,answerGaps.developRedo,workers);
|
|
1391
|
+
need(r.kind==='result'&&pending===null&&cause!==null&&p.cause===cause
|
|
1392
|
+
&&p.effectId===state.cache.at(-1).effect.id&&p.invocationId===state.calls.at(-1).invocationId,'runner_develop_redo');
|
|
1393
|
+
// Every started provider writer must have been proven gone by the host;
|
|
1394
|
+
// a Claude proposal also needs the live root at the round start (basis).
|
|
1395
|
+
const provider=cause.startsWith('provider_');
|
|
1396
|
+
shape(p,[...common,'effectId','invocationId','cause','reason','at',...['worker','basis'].filter(key=>Object.hasOwn(p,key))]);
|
|
1397
|
+
need(bindingMatches(p,provider?workerGoneBinding(workers[p.effectId]):null),'runner_develop_redo');
|
|
1398
|
+
if(provider&&config.developer.provider==='claude')need(p.basis!=null&&p.basis===redoDevelopStart(state),'runner_develop_redo');
|
|
1399
|
+
else need(!Object.hasOwn(p,'basis'),'runner_develop_redo');
|
|
1400
|
+
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
1401
|
+
&&!/[\r\n\0]/.test(p.reason),'runner_develop_redo');
|
|
1402
|
+
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_develop_redo');
|
|
1403
|
+
answerGaps.developRedo++;
|
|
1404
|
+
state.state='blocked';state.code=DEVELOP_REDO_CODE;state.reason=developRedoReason(cause);lastReview=null;
|
|
1405
|
+
} else if(version===3&&p.type==='develop-dispatch-retry') {
|
|
1406
|
+
// Written by advance when the develop failed before dispatch; a legacy
|
|
1407
|
+
// execution_error is admitted only on a journal-pinned start (the live
|
|
1408
|
+
// host compared the code root with it before writing this record).
|
|
1409
|
+
shape(p,[...common,'effectId','invocationId','basis']);
|
|
1410
|
+
const basis=developDispatchBasis(state,config,answerGaps.developDispatch);
|
|
1411
|
+
need(r.kind==='result'&&pending===null&&state.state==='unknown'&&basis!==null&&p.basis===basis
|
|
1412
|
+
&&p.effectId===state.cache.at(-1).effect.id&&p.invocationId===state.calls.at(-1).invocationId,'runner_develop_dispatch');
|
|
1413
|
+
answerGaps.developDispatch++;
|
|
1414
|
+
state.reason=developDispatchReason(state.code);
|
|
1415
|
+
state.state='blocked';state.code=DISPATCH_RETRY_CODE;lastReview=null;
|
|
1416
|
+
} else if(version===3&&p.type==='documentation-sync-started') {
|
|
1417
|
+
// Q16: written by the final task's develop right before it asks
|
|
1418
|
+
// documentation_sync: the developer answer it already accepted and the
|
|
1419
|
+
// documentation start. Bound to the pending develop's own developer call.
|
|
1420
|
+
shape(p,[...common,'effectId','invocationId','result','effectiveModel','documents','othersDigest']);
|
|
1421
|
+
need(r.kind==='result'&&pending?.kind==='develop'&&p.effectId===pending.id&&pendingDocumentation===null
|
|
1422
|
+
&&!config.bootstrap&&p.invocationId===`${session}.${beforeIntent.calls.length+1}`
|
|
1423
|
+
&&!controls.cancelled&&!controls.workflowError,'runner_documentation');
|
|
1424
|
+
text(p.effectiveModel);hex(p.othersDigest);json(p.result,256*1024);
|
|
1425
|
+
need(p.result!==null&&typeof p.result==='object'&&!Array.isArray(p.result),'runner_documentation');
|
|
1426
|
+
validDocumentationStates(p.documents,config.scope);
|
|
1427
|
+
// A documentation-only redo carries exactly the answer its source journaled.
|
|
1428
|
+
if(beforeIntent.state==='blocked'&&DOCUMENTATION_SYNC_CODES.includes(beforeIntent.code)){
|
|
1429
|
+
const source=documentationRecords.get(beforeIntent.calls.at(-1)?.documentationSync);
|
|
1430
|
+
need(source&&digest(source.result)===digest(p.result)&&source.effectiveModel===p.effectiveModel
|
|
1431
|
+
&&digest(source.documents.map(item=>item.path))===digest(p.documents.map(item=>item.path)),'runner_documentation');
|
|
1432
|
+
}
|
|
1433
|
+
pendingDocumentation={digest:r.digest,payload:p};documentationRecords.set(r.digest,p);
|
|
1434
|
+
} else if(version===3&&p.type==='documentation-sync-retry') {
|
|
1435
|
+
// Q16/Q17 (R3): develop_redo's stop confirmation for one failed
|
|
1436
|
+
// documentation_sync, bound to its developer call and start record, with
|
|
1437
|
+
// the documentation paths as they were at the confirmation. From the
|
|
1438
|
+
// checkpointed failure (unknown) it spends one of the run's retries; from
|
|
1439
|
+
// an already confirmed block (a re-confirmation after the operator's own
|
|
1440
|
+
// edits) it only replaces the confirmed documentation state.
|
|
1441
|
+
shape(p,[...common,'effectId','invocationId','startDigest','code','documents','reason','at']);
|
|
1442
|
+
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
1443
|
+
&&!/[\r\n\0]/.test(p.reason),'runner_documentation_retry');
|
|
1444
|
+
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_documentation_retry');
|
|
1445
|
+
need(r.kind==='result'&&pending===null,'runner_documentation_retry');
|
|
1446
|
+
const call=state.calls.at(-1),start=documentationRecords.get(call?.documentationSync);
|
|
1447
|
+
need(start!==undefined&&p.invocationId===call.invocationId&&p.startDigest===call.documentationSync,'runner_documentation_retry');
|
|
1448
|
+
validDocumentationStates(p.documents,config.scope);
|
|
1449
|
+
same(p.documents.map(item=>item.path),start.documents.map(item=>item.path));
|
|
1450
|
+
if(state.state==='unknown'){
|
|
1451
|
+
const code=documentationSyncRetryCode(state,config,answerGaps.documentationSync);
|
|
1452
|
+
need(code!==null&&p.code===code&&p.effectId===state.cache.at(-1).effect.id,'runner_documentation_retry');
|
|
1453
|
+
answerGaps.documentationSync++;
|
|
1454
|
+
documentationStop={effectId:p.effectId,invocationId:p.invocationId,startDigest:p.startDigest,
|
|
1455
|
+
detail:state.cache.at(-1).result.reason??null};
|
|
1456
|
+
}else need(state.state==='blocked'&&DOCUMENTATION_SYNC_CODES.includes(state.code)&&p.code===state.code
|
|
1457
|
+
&&documentationStop!==null&&p.effectId===documentationStop.effectId&&p.invocationId===documentationStop.invocationId
|
|
1458
|
+
&&p.startDigest===documentationStop.startDigest,'runner_documentation_retry');
|
|
1459
|
+
state.state='blocked';state.code=p.code;state.reason=documentationSyncRetryReason(p.code,documentationStop.detail);lastReview=null;
|
|
1460
|
+
} else if(version===3&&p.type==='complete-recheck') {
|
|
1461
|
+
shape(p,[...common,'effectId','source']);
|
|
1462
|
+
need(r.kind==='result'&&pending===null&&state.state==='unknown'&&completeRecheckable(state,answerGaps.completeRecheck)
|
|
1463
|
+
&&p.effectId===state.cache.at(-1).effect.id&&p.source===state.code,'runner_complete_recheck');
|
|
1464
|
+
answerGaps.completeRecheck++;
|
|
1465
|
+
state.state='blocked';state.code=COMPLETE_RECHECK_CODE;state.reason=completeRecheckReason(p.source);lastReview=null;
|
|
1466
|
+
} else if(version===3&&p.type==='review-redispatch') {
|
|
1467
|
+
// V5 (A34): written by abandon_review from this round's spent retryable
|
|
1468
|
+
// review block while the round has a no-result redispatch left: the
|
|
1469
|
+
// operator confirmed (reason) the original call's reviewer stopped. The
|
|
1470
|
+
// redispatch itself is the next review intent. Re-derived from the journal.
|
|
1471
|
+
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
1472
|
+
shape(p,[...common,'effectId','invocationId','attempt','code','reason','at']);
|
|
1473
|
+
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
1474
|
+
&&!/[\r\n\0]/.test(p.reason),'runner_review_redispatch');
|
|
1475
|
+
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_review_redispatch');
|
|
1476
|
+
const contextId=config.reviewers[0].contexts[state.attempt-1];
|
|
1477
|
+
need(r.kind==='result'&&pending===null&&p.attempt===state.attempt
|
|
1478
|
+
&&reviewRedispatchable(state,contextId,answerGaps.reviewRedispatch[state.attempt])
|
|
1479
|
+
&&p.code===state.code&&p.effectId===state.cache.at(-1).effect.id
|
|
1480
|
+
&&p.invocationId===state.reviewInvocation.registration.binding.invocationId,'runner_review_redispatch');
|
|
1481
|
+
answerGaps.reviewRedispatch[state.attempt]++;
|
|
1482
|
+
state.state='pending_review';lastReview=null;
|
|
833
1483
|
} else if(version===3&&p.type==='completion-retry-limit') {
|
|
834
1484
|
// Terminal: written instead of a complete intent once the re-check bound
|
|
835
1485
|
// is spent. Every field is recomputed from the replayed state.
|
|
@@ -837,12 +1487,12 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
837
1487
|
need(r.kind==='result'&&pending===null&&completionRetriesExhausted(state)&&p.fromCode===state.code
|
|
838
1488
|
&&p.completionBlocks===completionBlockCount(state.cache),'runner_retry_limit');
|
|
839
1489
|
state.state='blocked';state.code='completion_retry_limit';state.reason=completionRetryLimitReason(p);lastReview=null;
|
|
840
|
-
} else if(version===3&&p.type==='review-invocation-abandoned'&&Object.hasOwn(p,'resultDigest')) {
|
|
1490
|
+
} else if(version===3&&p.type==='review-invocation-abandoned'&&Object.hasOwn(p,'resultDigest')&&pending===null) {
|
|
841
1491
|
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
842
1492
|
// Abandoning a checkpointed review whose journaled result was never accepted.
|
|
843
1493
|
shape(p,[...common,'effectId','invocationId','registeredDigest','startedDigest','resultDigest','reason','at']);
|
|
844
1494
|
need(r.kind==='result'&&pending===null&&lastReview!==null
|
|
845
|
-
&&abandonableReviewResult(state,config.reviewers[0].contexts[state.attempt-1]),'runner_abandon');
|
|
1495
|
+
&&abandonableReviewResult(state,config.reviewers[0].contexts[state.attempt-1],answerGaps.reviewRedispatch[state.attempt]),'runner_abandon');
|
|
846
1496
|
need(p.effectId===lastReview.effect.id&&state.cache.at(-1).effect.id===lastReview.effect.id
|
|
847
1497
|
&&p.invocationId===lastReview.request.invocationId&&p.registeredDigest===lastReview.registrationRecord.digest
|
|
848
1498
|
&&p.startedDigest===(lastReview.startedRecord?.digest??null)&&p.resultDigest===lastReview.resultRecord.digest,'runner_abandon');
|
|
@@ -850,7 +1500,7 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
850
1500
|
&&!/[\r\n\0]/.test(p.reason),'runner_abandon');
|
|
851
1501
|
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_abandon');
|
|
852
1502
|
const call=state.calls.find(item=>item.invocationId===p.invocationId);
|
|
853
|
-
need(call?.terminal==='unknown'&&call.channel==='host-
|
|
1503
|
+
need(call?.terminal==='unknown'&&call.channel==='host-review','runner_abandon');
|
|
854
1504
|
// The invocation keeps its slot and its result digest; only its terminal
|
|
855
1505
|
// records the operator's exit, which also marks the attempt's retry spent.
|
|
856
1506
|
call.terminal='abandoned';
|
|
@@ -860,21 +1510,26 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
860
1510
|
lastReview=null;
|
|
861
1511
|
} else if(version===3&&p.type==='review-invocation-abandoned') {
|
|
862
1512
|
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1513
|
+
// A38: a pending review whose no-verdict result reached the journal right
|
|
1514
|
+
// before the host died (no checkpoint) is abandoned like a pending one,
|
|
1515
|
+
// bound to that result record, which must be the record just before.
|
|
1516
|
+
const withResult=Object.hasOwn(p,'resultDigest');
|
|
1517
|
+
shape(p,[...common,'effectId','invocationId','registeredDigest','startedDigest',...(withResult?['resultDigest']:[]),'reason','at']);
|
|
1518
|
+
need(r.kind==='result'&&pending?.kind==='review'&&invocation.registration
|
|
1519
|
+
&&(withResult?pendingResultAbandonable()&&records[index-1]===resultRecord&&p.resultDigest===resultRecord.digest:!invocation.result)
|
|
1520
|
+
&&!controls.cancelled&&!controls.workflowError
|
|
1521
|
+
// A redispatch's intent was issued from pending_review (V5: up to two per round).
|
|
1522
|
+
&&(state.state==='awaiting_review'||state.state==='pending_review'&&REVIEW_RETRY_CODES.includes(state.code)),'runner_abandon');
|
|
866
1523
|
need(p.effectId===pending.id&&p.invocationId===invocation.registration.request.invocationId
|
|
867
1524
|
&&p.registeredDigest===registrationRecord.digest
|
|
868
1525
|
&&p.startedDigest===(startedRecord?.digest??null),'runner_abandon');
|
|
869
1526
|
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
870
1527
|
&&!/[\r\n\0]/.test(p.reason),'runner_abandon');
|
|
871
1528
|
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_abandon');
|
|
872
|
-
need(
|
|
873
|
-
&&!state.calls.some(call=>call.terminal==='abandoned'
|
|
874
|
-
&&call.contextId===config.reviewers[0].contexts[state.attempt-1]),'runner_abandon_budget');
|
|
1529
|
+
need(roundRedispatches()<MAX_REVIEW_REDISPATCHES,'runner_abandon_budget');
|
|
875
1530
|
const request=invocation.registration.request;
|
|
876
1531
|
state.calls.push({invocationId:request.invocationId,contextId:request.contextId,provider:request.provider,
|
|
877
|
-
requestedModel:request.requestedModel,effectiveModel:'unknown',channel:'host-
|
|
1532
|
+
requestedModel:request.requestedModel,effectiveModel:'unknown',channel:'host-review',
|
|
878
1533
|
started:startedRecord!==null,terminal:'abandoned',requestDigest:request.requestDigest,
|
|
879
1534
|
resultDigest:r.digest,providerThreadId:invocation.started});
|
|
880
1535
|
state.sequence++;
|
|
@@ -882,12 +1537,103 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
882
1537
|
state.reviewInvocation={registration:invocation.registration.record,started:invocation.started,
|
|
883
1538
|
result:{outcome:'abandoned',reason:p.reason,at:p.at,recordDigest:r.digest}};
|
|
884
1539
|
pending=null;beforeIntent=null;invocation={registration:null,started:null,result:null};
|
|
1540
|
+
} else if(version===3&&p.type==='develop-worker') {
|
|
1541
|
+
// V9: the writers of the pending develop, journaled by the host right
|
|
1542
|
+
// before (…spawning) and right after (…started: pid = process group,
|
|
1543
|
+
// start time) each spawns: the provider worker once, and each sandbox
|
|
1544
|
+
// subprocess that applies a protected proposal (one per root, at most
|
|
1545
|
+
// MAX_CODE_PROJECTS). Bound to the
|
|
1546
|
+
// develop's invocation; never after a cancel or workflow error.
|
|
1547
|
+
const started=['started','apply_started'].includes(p.phase);
|
|
1548
|
+
shape(p,[...common,'effectId','invocationId','phase',...(started?['pid','startTime']:[])]);
|
|
1549
|
+
need(r.kind==='result'&&pending?.kind==='develop'&&p.effectId===pending.id&&pendingWorker?.journal===true
|
|
1550
|
+
&&p.invocationId===`${session}.${beforeIntent.calls.length+1}`&&!controls.cancelled&&!controls.workflowError,'runner_worker');
|
|
1551
|
+
if(started)need(validWorkerPid(p.pid)&&validStartTime(p.startTime),'runner_worker');
|
|
1552
|
+
const identity={digest:r.digest,pid:p.pid,startTime:p.startTime};
|
|
1553
|
+
const provider=config.developer.requestedModel!=='current-session',open=pendingWorker.applies.at(-1);
|
|
1554
|
+
if(p.phase==='spawning'){need(provider&&pendingWorker.spawning===null&&!pendingWorker.applies.length,'runner_worker');pendingWorker.spawning=r.digest;}
|
|
1555
|
+
else if(p.phase==='started'){need(provider&&pendingWorker.spawning!==null&&pendingWorker.started===null&&!pendingWorker.applies.length,'runner_worker');pendingWorker.started=identity;}
|
|
1556
|
+
else if(p.phase==='apply_spawning'){need((!open||open.started!==null)&&pendingWorker.applies.length<MAX_CODE_PROJECTS,'runner_worker');pendingWorker.applies.push({started:null});}
|
|
1557
|
+
else{need(p.phase==='apply_started'&&open&&open.started===null,'runner_worker');open.started=identity;}
|
|
1558
|
+
} else if(version===3&&p.type==='effect-interrupted') {
|
|
1559
|
+
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
1560
|
+
shape(p,[...common,'effectId','effectKind','intentDigest','lastRecordDigest','reason','at',
|
|
1561
|
+
...['basis','worker','startDigest','documents'].filter(key=>Object.hasOwn(p,key))]);
|
|
1562
|
+
const intentIndex=records.slice(0,index).findLastIndex(row=>row.payload.type==='effect-intent');
|
|
1563
|
+
// Q16: a develop that died during documentation_sync names its start record
|
|
1564
|
+
// and the documentation paths as they were when the operator confirmed
|
|
1565
|
+
// the old host and session stopped (this record); exactly then.
|
|
1566
|
+
const origin=documentationOrigin(),documentationInterrupted=origin!==null;
|
|
1567
|
+
need(documentationInterrupted===Object.hasOwn(p,'startDigest')&&documentationInterrupted===Object.hasOwn(p,'documents'),'runner_interrupt');
|
|
1568
|
+
if(documentationInterrupted){
|
|
1569
|
+
need(p.startDigest===origin.digest,'runner_interrupt');
|
|
1570
|
+
validDocumentationStates(p.documents,config.scope);
|
|
1571
|
+
same(p.documents.map(item=>item.path),origin.payload.documents.map(item=>item.path));
|
|
1572
|
+
}
|
|
1573
|
+
need(r.kind==='result'&&pending&&intentIndex>=0&&pendingInterruptible(pending,intentIndex,index),'runner_interrupt');
|
|
1574
|
+
need(p.effectId===pending.id&&p.effectKind===pending.kind&&p.intentDigest===records[intentIndex].digest
|
|
1575
|
+
&&p.lastRecordDigest===records[index-1].digest,'runner_interrupt');
|
|
1576
|
+
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
1577
|
+
&&!/[\r\n\0]/.test(p.reason),'runner_interrupt');
|
|
1578
|
+
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_interrupt');
|
|
1579
|
+
const provider=config.developer.requestedModel!=='current-session';
|
|
1580
|
+
if(pending.kind==='develop'){
|
|
1581
|
+
// A provider worker that may have started is retired only with the
|
|
1582
|
+
// host's proof that its process group is gone; no record, no proof.
|
|
1583
|
+
if(provider)need(pendingWorker.journal===true,'runner_interrupt');
|
|
1584
|
+
need(writersComplete(pendingWorker)&&bindingMatches(p,workerGoneBinding(pendingWorker)),'runner_interrupt');
|
|
1585
|
+
// basis: the live host proved the code root still equals the pinned round
|
|
1586
|
+
// start where every write is an applied proposal (protected current-session
|
|
1587
|
+
// development, Claude provider development): a partial apply is restored
|
|
1588
|
+
// by a person first, never sent to review as a new delivery (V6).
|
|
1589
|
+
const proposalApply=provider&&config.developer.provider==='claude';
|
|
1590
|
+
if(proposalApply)need(p.basis!=null&&p.basis===pendingDevelopStart(state),'runner_interrupt');
|
|
1591
|
+
else if(Object.hasOwn(p,'basis'))need(!provider&&p.basis===pendingDevelopStart(state),'runner_interrupt');
|
|
1592
|
+
const request=requestFor({invocationId:`${session}.${state.calls.length+1}`,identity:{...config.identity,attempt:state.attempt},
|
|
1593
|
+
role:'developer',provider:config.developer.provider,requestedModel:config.developer.requestedModel,
|
|
1594
|
+
contextId:config.developer.contextId,payload:{scope:config.scope,
|
|
1595
|
+
requirements:original.files.filter(f=>config.requirements.includes(f.path)),priorReview:state.priorReview,
|
|
1596
|
+
...supersededReviewPayload(supersession?.carriedReview??null,state.attempt),
|
|
1597
|
+
...(Object.hasOwn(original,'specification')?{specification:original.specification}:{}),
|
|
1598
|
+
...(Object.hasOwn(pending,'learningInput')?{learningInput:pending.learningInput}:{})}});
|
|
1599
|
+
state.calls.push({invocationId:request.invocationId,contextId:config.developer.contextId,provider:config.developer.provider,
|
|
1600
|
+
requestedModel:config.developer.requestedModel,effectiveModel:'unknown',channel:'fixture',started:true,
|
|
1601
|
+
terminal:'abandoned',requestDigest:request.requestDigest,resultDigest:r.digest,
|
|
1602
|
+
...(documentationInterrupted?{documentationSync:origin.digest}:{})});
|
|
1603
|
+
state.sequence++;
|
|
1604
|
+
if(documentationInterrupted){
|
|
1605
|
+
// The developer had answered (journaled): redo only documentation_sync.
|
|
1606
|
+
answerGaps.documentationSync++;
|
|
1607
|
+
documentationStop={effectId:pending.id,invocationId:request.invocationId,startDigest:p.startDigest,detail:null};
|
|
1608
|
+
state.state='blocked';state.code=DOCUMENTATION_SYNC_INTERRUPTED_CODE;
|
|
1609
|
+
state.reason=documentationSyncRetryReason(DOCUMENTATION_SYNC_INTERRUPTED_CODE);
|
|
1610
|
+
}else{state.state='blocked';state.code=DEVELOP_INTERRUPTED_CODE;state.reason=developInterruptedReason(provider);}
|
|
1611
|
+
}else{
|
|
1612
|
+
need(!Object.hasOwn(p,'basis')&&!Object.hasOwn(p,'worker'),'runner_interrupt');
|
|
1613
|
+
if(pending.kind==='review'){state.state='awaiting_review';state.code=null;state.reason=REVIEW_INTERRUPTED_REASON;}
|
|
1614
|
+
else {state.state=beforeIntent.state;state.code=beforeIntent.code;state.reason=beforeIntent.reason??null;}
|
|
1615
|
+
}
|
|
1616
|
+
interrupted.push({effectId:pending.id,kind:pending.kind});
|
|
1617
|
+
pending=null;beforeIntent=null;invocation={registration:null,started:null,result:null};pendingWorker=null;pendingDocumentation=null;
|
|
1618
|
+
joinedForInvocation=false;lastReview=null;
|
|
885
1619
|
} else if(version===3&&p.type==='effect-abandoned') {
|
|
886
1620
|
need(!(config.externalModels||config.executionPolicy),'external_review_reconciliation_required');
|
|
887
1621
|
shape(p,[...common,'effectId','effectKind','intentDigest','reason','at',
|
|
888
|
-
...(Object.hasOwn(p,
|
|
1622
|
+
...['lastRecordDigest','worker'].filter(key=>Object.hasOwn(p,key))]);
|
|
889
1623
|
let intentIndex=index-1;
|
|
890
|
-
while(intentIndex>=0&&records[intentIndex].payload.type==='control'
|
|
1624
|
+
while(intentIndex>=0&&(records[intentIndex].payload.type==='control'
|
|
1625
|
+
||pending?.kind==='develop'&&records[intentIndex].payload.type==='documentation-sync-started'))intentIndex--;
|
|
1626
|
+
// A36: a registered review whose no-result redispatches this round
|
|
1627
|
+
// (MAX_REVIEW_REDISPATCHES) are spent can no longer be abandoned with abandon_review. Voiding the run
|
|
1628
|
+
// (then superseding it) is its only exit; it must name the last record.
|
|
1629
|
+
const exhaustedReview=pendingReviewExhausted();
|
|
1630
|
+
const lastIntent=records.slice(0,index).findLastIndex(row=>row.payload.type==='effect-intent');
|
|
1631
|
+
// A develop with journaled writers is voided only with their gone-proof.
|
|
1632
|
+
const workerVoid=pendingWorkerVoidable(pending,lastIntent,index);
|
|
1633
|
+
if(exhaustedReview||workerVoid)intentIndex=lastIntent;
|
|
1634
|
+
if(workerVoid)need(writersComplete(pendingWorker)&&bindingMatches(p,workerGoneBinding(pendingWorker))
|
|
1635
|
+
&&Object.hasOwn(p,'lastRecordDigest'),'runner_abandon');
|
|
1636
|
+
else need(!Object.hasOwn(p,'worker'),'runner_abandon');
|
|
891
1637
|
const intent=records[intentIndex];
|
|
892
1638
|
need(r.kind==='result'&&pending&&['develop','complete','review'].includes(pending.kind)
|
|
893
1639
|
&&intent?.payload.type==='effect-intent'&&transaction===null
|
|
@@ -895,8 +1641,8 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
895
1641
|
need(p.effectId===pending.id&&p.effectKind===pending.kind
|
|
896
1642
|
&&p.intentDigest===intent.digest
|
|
897
1643
|
&&(Object.hasOwn(p,'lastRecordDigest')
|
|
898
|
-
?p.lastRecordDigest===records[index-1].digest:intentIndex===index-1)
|
|
899
|
-
&&(pending.kind!=='review'||!invocation.registration&&!joinedForInvocation),'runner_abandon');
|
|
1644
|
+
?p.lastRecordDigest===records[index-1].digest:intentIndex===index-1&&!exhaustedReview&&!workerVoid)
|
|
1645
|
+
&&(pending.kind!=='review'||!invocation.registration&&!joinedForInvocation||exhaustedReview),'runner_abandon');
|
|
900
1646
|
need(typeof p.reason==='string'&&p.reason.trim().length>0&&Buffer.byteLength(p.reason,'utf8')<=500
|
|
901
1647
|
&&!/[\r\n\0]/.test(p.reason),'runner_abandon');
|
|
902
1648
|
need(typeof p.at==='string'&&Number.isFinite(Date.parse(p.at))&&new Date(p.at).toISOString()===p.at,'runner_abandon');
|
|
@@ -905,17 +1651,18 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
905
1651
|
} else if(p.type==='effect-checkpoint') {
|
|
906
1652
|
shape(p,[...common,'effectId','checkpoint']);need(r.kind==='result' && pending && p.effectId===pending.id,'runner_checkpoint');
|
|
907
1653
|
state=checkpoint(beforeIntent,p.checkpoint,pending,config,original,session,controls,version,state.taskCommit??null,invocation,
|
|
908
|
-
supersession?.carriedReview??null);
|
|
1654
|
+
supersession?.carriedReview??null,pendingDocumentation);pendingDocumentation=null;
|
|
909
1655
|
lastReview=version===3&&pending.kind==='review'&&invocation.result?{effect:pending,request:invocation.registration.request,
|
|
910
1656
|
registrationRecord,startedRecord,resultRecord,before:beforeIntent,controls,invocation}:null;
|
|
911
|
-
pending=
|
|
1657
|
+
if(pending.kind==='develop'&&pendingWorker?.journal)workers[pending.id]=workerSummary(pendingWorker);
|
|
1658
|
+
pending=null;beforeIntent=null;invocation={registration:null,started:null,result:null};pendingWorker=null;
|
|
912
1659
|
} else if(version>=2 && ['task-commit-intent','task-commit-result'].includes(p.type)){
|
|
913
1660
|
shape(p,[...common,'effectId','completeIntentDigest','commit']);
|
|
914
1661
|
need(pending?.kind==='complete'&&p.effectId===pending.id&&p.completeIntentDigest===completeIntentDigest&&!controls.cancelled,'runner_commit');
|
|
915
1662
|
if(p.type==='task-commit-intent'){
|
|
916
1663
|
need(r.kind==='commit-intent'&&transaction===null
|
|
917
1664
|
&&(beforeIntent.state==='approved'||beforeIntent.state==='blocked'
|
|
918
|
-
&&['completion_checks_changed','completion_package_changed','review_package_changed'].includes(beforeIntent.code)),'runner_commit');
|
|
1665
|
+
&&['completion_checks_changed','completion_package_changed','review_package_changed',COMPLETE_RECHECK_CODE].includes(beforeIntent.code)),'runner_commit');
|
|
919
1666
|
const c=readCommitIntent(p.commit,{owner:completion.owner,identity:pending.identity,fingerprints:completion.fingerprints});
|
|
920
1667
|
const base=attemptBaseline(original,pending.identity.attempt),s=beforeIntent;
|
|
921
1668
|
checkCompletion({receipt:s.receipt,registered:s.receipts.find(x=>x.id===s.receipt?.id),
|
|
@@ -973,14 +1720,24 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
973
1720
|
&&!transaction&&state.taskCommit?.intentDigest==null
|
|
974
1721
|
&&(pending.kind!=='review'||!invocation.registration&&!joinedForInvocation)
|
|
975
1722
|
&&records.slice(records.findLastIndex(row=>row.payload.type==='effect-intent')+1)
|
|
976
|
-
.every(row=>row.payload.type==='control');
|
|
1723
|
+
.every(row=>row.payload.type==='control'||pending.kind==='develop'&&row.payload.type==='documentation-sync-started');
|
|
977
1724
|
const reviewResultAbandon=!(config.externalModels||config.executionPolicy)&&version===3&&pending===null&&lastReview!==null
|
|
978
|
-
&&abandonableReviewResult(state,config.reviewers[0].contexts[state.attempt-1])
|
|
1725
|
+
&&abandonableReviewResult(state,config.reviewers[0].contexts[state.attempt-1],answerGaps.reviewRedispatch[state.attempt])
|
|
979
1726
|
?{effectId:lastReview.effect.id,invocationId:lastReview.request.invocationId,
|
|
980
1727
|
registeredDigest:lastReview.registrationRecord.digest,startedDigest:lastReview.startedRecord?.digest??null,
|
|
981
1728
|
resultDigest:lastReview.resultRecord.digest}:null;
|
|
982
|
-
|
|
1729
|
+
const lastIntentIndex=records.findLastIndex(row=>row.payload.type==='effect-intent');
|
|
1730
|
+
const interruptible=pending!==null&&pendingInterruptible(pending,lastIntentIndex,records.length);
|
|
1731
|
+
const interruptLimit=pending!==null&&!interruptible
|
|
1732
|
+
&&interrupted.filter(item=>item.kind===pending.kind).length>=MAX_EFFECT_INTERRUPTIONS;
|
|
1733
|
+
const workerVoidable=pending!==null&&pendingWorkerVoidable(pending,lastIntentIndex,records.length);
|
|
1734
|
+
return {original,session,state,pending,acceptedFixes,qaAttachment,answerGaps,
|
|
983
1735
|
...(version===3?{joinedHosts,reviewerThreads,supersession,pendingAbandonable,reviewResultAbandon,
|
|
1736
|
+
interrupted,workers,pendingInterruptible:interruptible,pendingReviewExhausted:pendingReviewExhausted(),
|
|
1737
|
+
pendingResultAbandonable:pending!==null&&pendingResultAbandonable(),
|
|
1738
|
+
pendingInterruptLimit:interruptLimit,pendingWorkerVoidable:workerVoidable,
|
|
1739
|
+
pendingWorker:pending?.kind==='develop'&&pendingWorker?workerSummary(pendingWorker):null,
|
|
1740
|
+
pendingDocumentation:documentationOrigin(),
|
|
984
1741
|
reviewReconciliation:lastReview?.reconciliation&&['unknown','pending_review'].includes(state.state)?{...reconciliationBinding(),
|
|
985
1742
|
...lastReview.reconciliation,request:lastReview.request,effect:lastReview.effect,before:lastReview.before}:null,
|
|
986
1743
|
pendingObservedReview:pending?.kind==='review'&&invocation.result?.outcome==='observed'
|
|
@@ -988,6 +1745,63 @@ export function readRunnerHistory(raw,config,version=1) {
|
|
|
988
1745
|
started:invocation.started,result:invocation.result}:null}:{}),
|
|
989
1746
|
...(version>=2?{transaction}:{})};
|
|
990
1747
|
}
|
|
1748
|
+
// R2: each answer-gap exit has two uses per run. Once spent, the same stuck shape
|
|
1749
|
+
// is shown as an explicit limit block instead of falling back to an exit-less
|
|
1750
|
+
// unknown/reconcile: its code names the spent exit and its reason names what is
|
|
1751
|
+
// left (fix the root cause, then a superseding run). Derived from the journal
|
|
1752
|
+
// on every read, never journaled itself, so replay shows the same block.
|
|
1753
|
+
// A spent develop_dispatch_failed exit falls to the confirmed develop_redo, so it
|
|
1754
|
+
// has no limit code of its own.
|
|
1755
|
+
export const ANSWER_GAP_LIMIT_CODES=Object.freeze(['check_answer_retry_limit','complete_recheck_limit','develop_redo_limit',DOCUMENTATION_SYNC_LIMIT_CODE]);
|
|
1756
|
+
const gapLimitReason=(code,what,source)=>`${code}: ${what}(原记录 ${source})已在本运行用满 ${MAX_ANSWER_GAP_RETRIES} 次,不再自动重做。`
|
|
1757
|
+
+'先查清根因(会话为何一直不应答或答复不合格、宿主环境为何失败);修好后用 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做,'
|
|
1758
|
+
+'本运行留在盘上的改动需还原,或加 --accept-superseded-code-drift 作为已有代码记录。';
|
|
1759
|
+
export function answerGapLimit(s,config,gaps={}){
|
|
1760
|
+
if(!['unknown','blocked'].includes(s.state))return null;
|
|
1761
|
+
const source=`${s.state}/${s.code}`;
|
|
1762
|
+
if(s.state==='unknown'&&(gaps.developRecheck??0)>=MAX_ANSWER_GAP_RETRIES&&developRecheckCode(s,config,0)!==null)
|
|
1763
|
+
return {code:'check_answer_retry_limit',reason:gapLimitReason('check_answer_retry_limit','开发后的检查或验证预检重跑',source)};
|
|
1764
|
+
if(s.state==='unknown'&&(gaps.completeRecheck??0)>=MAX_ANSWER_GAP_RETRIES&&completeRecheckable(s,0))
|
|
1765
|
+
return {code:'complete_recheck_limit',reason:gapLimitReason('complete_recheck_limit','完成前复查重跑',source)};
|
|
1766
|
+
if(s.state==='unknown'&&(gaps.documentationSync??0)>=MAX_DOCUMENTATION_SYNC_RETRIES&&documentationSyncRetryCode(s,config,0)!==null)
|
|
1767
|
+
return {code:DOCUMENTATION_SYNC_LIMIT_CODE,reason:documentationSyncLimitReason(source)};
|
|
1768
|
+
if((gaps.developRedo??0)>=MAX_DEVELOP_REDOS&&developRedoCause(s,config,0,gaps.workers??null)!==null)
|
|
1769
|
+
return {code:'develop_redo_limit',reason:gapLimitReason('develop_redo_limit','确认停写后的开发重发',source)};
|
|
1770
|
+
return null;
|
|
1771
|
+
}
|
|
1772
|
+
// Q28: the status a host would show for a replayed journal, as far as the
|
|
1773
|
+
// journal alone decides it. Drivers prepare answers from this (never from the
|
|
1774
|
+
// raw replay state, which still reads unknown/call_timeout or blocked/failed
|
|
1775
|
+
// for the retryable answer-gap blocks). Exits that also need a live disk check
|
|
1776
|
+
// (#198 develop_call_timeout, a legacy pinned dispatch failure) are projected
|
|
1777
|
+
// as available: preparing an answer that ends up unused is harmless, while a
|
|
1778
|
+
// missing one ends a real redo in host_close. Exits that need an operator
|
|
1779
|
+
// confirmation first (develop_redo) are not projected as retryable.
|
|
1780
|
+
export function projectedRunnerStatus(history,config){
|
|
1781
|
+
const s=history.state,gaps=history.answerGaps??{};
|
|
1782
|
+
const project=code=>({...s,state:'blocked',code});
|
|
1783
|
+
if(s.state==='blocked'&&s.code==='failed'&&developAnswerRetryable(s,config.bootstrap))return project('develop_answer_invalid');
|
|
1784
|
+
if(s.state==='blocked'&&s.code==='failed'){const limit=answerGapLimit(s,config,gaps);
|
|
1785
|
+
return limit?{...s,state:'blocked',code:limit.code,reason:limit.reason}:s;}
|
|
1786
|
+
// V5: a spent retryable review block with a no-result redispatch left waits
|
|
1787
|
+
// for the operator's stop confirmation (abandon_review → review-redispatch);
|
|
1788
|
+
// a fully spent one is a limit.
|
|
1789
|
+
if(s.state==='blocked'&&!(config.externalModels||config.executionPolicy)&&Array.isArray(config.reviewers)){
|
|
1790
|
+
const contextId=config.reviewers[0].contexts[s.attempt-1],records=gaps.reviewRedispatch?.[s.attempt]??0;
|
|
1791
|
+
if(reviewRedispatchable(s,contextId,records))return {...s,reviewRedispatchStopRequired:true,reason:reviewRedispatchStopReason(s.code)};
|
|
1792
|
+
if(reviewRedispatchExhausted(s,contextId,records))return {...s,code:REVIEW_REDISPATCH_LIMIT_CODE,reason:reviewRedispatchLimitReason(s.code)};
|
|
1793
|
+
}
|
|
1794
|
+
if(s.state!=='unknown')return s;
|
|
1795
|
+
const recheck=developRecheckCode(s,config,gaps.developRecheck??0);
|
|
1796
|
+
if(recheck!==null)return project(recheck);
|
|
1797
|
+
if(completeRecheckable(s,gaps.completeRecheck??0))return project(COMPLETE_RECHECK_CODE);
|
|
1798
|
+
// Q16/Q17: a failed documentation_sync needs the operator's stop
|
|
1799
|
+
// confirmation (develop_redo) first, so it is not projected as retryable.
|
|
1800
|
+
if(s.code==='call_timeout'&&developTimeoutBasis(s,config.bootstrap)!==null)return project('develop_call_timeout');
|
|
1801
|
+
if(developDispatchBasis(s,config,gaps.developDispatch??0)!==null)return project(DISPATCH_RETRY_CODE);
|
|
1802
|
+
const limit=answerGapLimit(s,config,gaps);
|
|
1803
|
+
return limit?{...s,state:'blocked',code:limit.code,reason:limit.reason}:s;
|
|
1804
|
+
}
|
|
991
1805
|
// Baseline rootDigest uses bytes of the canonical root, not JSON string encoding.
|
|
992
1806
|
import {createHash} from 'node:crypto';
|
|
993
1807
|
import {readQaAttachment} from './qa-attachment.mjs';
|