@aibyzero/cm-workflow 0.16.7 → 0.16.9
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 +37 -0
- package/README.md +39 -3
- package/VERSION +1 -1
- package/assets/readme/workflow-recovery-detailed.png +0 -0
- package/assets/readme/workflow-stages-detailed.png +0 -0
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +61 -4
- package/docs/next-steps.md +8 -2
- package/docs/user-guide.md +204 -0
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-admission.mjs +3 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +138 -26
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +142 -21
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-core.mjs +26 -4
- package/runtime/js/cm-ai/durable-runner-state.mjs +951 -43
- 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/execution-store.mjs +4 -2
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -4
- 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 +86 -17
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +44 -9
- package/runtime/js/cm-ai/host-session.mjs +47 -7
- package/runtime/js/cm-ai/host-tool-bridge.mjs +55 -6
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +112 -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-dispatch-limits.mjs +18 -0
- package/runtime/js/cm-ai/review-package.mjs +10 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
- 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 +636 -65
- 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/cause-package.mjs +37 -8
- package/runtime/js/cm-fix/diagnosis.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +356 -187
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/investigation.mjs +25 -9
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +15 -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-prd/review-correction.mjs +10 -4
- 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 +79 -9
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-run.mjs +26 -0
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +312 -0
- package/runtime/js/notify.mjs +492 -0
- package/runtime/js/policy-binding-compat.mjs +54 -0
- package/runtime/model-efficiency.md +17 -0
- 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 +70 -2
- 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 +96 -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 +55 -10
- package/scripts/cm-ai-batch-drive.test.mjs +65 -0
- package/scripts/cm-ai-batch-host.mjs +132 -13
- package/scripts/cm-ai-batch-host.test.mjs +255 -7
- package/scripts/cm-ai-batch-run-fixture.mjs +499 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +38 -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 +189 -22
- package/scripts/cm-ai-batch-run.test.mjs +22 -334
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +104 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +153 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +4 -3
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive.mjs +68 -23
- package/scripts/cm-ai-drive.test.mjs +37 -2
- package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
- package/scripts/cm-ai-host-cli-workflow.test.mjs +271 -0
- package/scripts/cm-ai-host-fixture.mjs +268 -0
- package/scripts/cm-ai-host-protected.test.mjs +251 -0
- package/scripts/cm-ai-host.mjs +28 -16
- package/scripts/cm-ai-host.test.mjs +17 -759
- package/scripts/cm-ai-light-modules.test.mjs +57 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
- package/scripts/cm-ai-protected-scope.test.mjs +7 -3
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +78 -11
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +127 -8
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +475 -0
- package/scripts/cm-ai-review-failure.test.mjs +124 -13
- package/scripts/cm-ai-review-timeout.test.mjs +188 -10
- package/scripts/cm-ai-run.mjs +15 -6
- package/scripts/cm-ai-supersede.test.mjs +486 -41
- 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 +18 -2
- package/scripts/cm-external-model-recovery.test.mjs +29 -3
- package/scripts/cm-fix-abandon.test.mjs +249 -10
- package/scripts/cm-fix-cause-package.test.mjs +33 -0
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +34 -8
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +35 -0
- 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 +143 -10
- 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-log-event.mjs +49 -12
- package/scripts/cm-notify-command.test.mjs +900 -0
- package/scripts/cm-notify-read-drift.test.mjs +205 -0
- package/scripts/cm-notify.mjs +469 -0
- package/scripts/cm-notify.test.mjs +685 -0
- package/scripts/cm-patrol.mjs +83 -0
- package/scripts/cm-patrol.test.mjs +161 -0
- 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-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/cm-token-report.mjs +497 -0
- package/scripts/cm-token-report.test.mjs +346 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/policy-binding-compat.test.mjs +99 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +7 -3
- package/skills/cm-ai/references/N6-qa-eval.md +2 -2
- package/skills/cm-ai/references/js-host-modes.md +90 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +136 -0
- package/skills/cm-ai/references/js-host-recovery.md +311 -0
- package/skills/cm-ai/references/js-host.md +76 -331
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +2 -0
- package/skills/cm-fix/references/js-host.md +56 -10
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +16 -3
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/SKILL.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -38,7 +38,8 @@ import {readProjectInstructionContext} from '../cm-ai/cm-ai-context-refresh.mjs'
|
|
|
38
38
|
import {publishFixDossier,publishFixObservationDossier,publishFixEscalationDossier,readFixObservationArchive} from './dossier.mjs';
|
|
39
39
|
import {readFixWalkthrough,fixWalkthroughBinding,createFixWalkthrough,inspectFixWalkthrough,verifyFixWalkthroughEvidence,walkthroughCoversDiagnosis} from './walkthrough.mjs';
|
|
40
40
|
import {logFixEvent} from './start.mjs';
|
|
41
|
-
import {
|
|
41
|
+
import {fixInvestigationRequest} from './investigation.mjs';
|
|
42
|
+
import {inspectFixDiagnosis,fixDiagnosisAnswer,isInvalidFixDiagnosis} from './diagnosis.mjs';
|
|
42
43
|
import {finishFix,fixCompletionProjection,eventsAt,isFixObservationExit} from './finish.mjs';
|
|
43
44
|
import {specsPermissionArgs} from '../cm-ai/codex-config.mjs';
|
|
44
45
|
import {protectedFixBridge} from './protected-edits.mjs';
|
|
@@ -65,19 +66,47 @@ function stepRecord(id){
|
|
|
65
66
|
return abandonable.has(pending)?{base:match[1],suffix:match[2],pending}:null;
|
|
66
67
|
}
|
|
67
68
|
const retryBase=id=>id.replace(/-retry-[1-8]-(intent|result)$/,'-$1');
|
|
69
|
+
// V2 (F09/F13/F14/F28): a redone write step keeps the review baseline its first
|
|
70
|
+
// intent captured. The abandon (or blocked-rerun) record says so with
|
|
71
|
+
// baselinePinned; the redo's intent must carry exactly that baseline, so the
|
|
72
|
+
// abandoned attempt's residue is part of the reviewed diff, never of the
|
|
73
|
+
// "before" image. Older journals without the marker replay unchanged.
|
|
74
|
+
const PINNED_STEPS=new Set(['test_author','repair','revision_test_author','revision_repair']);
|
|
75
|
+
// V10 (F15/F18/F20): a legitimate blocked verdict of a local step may be rerun
|
|
76
|
+
// with a reason, at most twice per step kind; the blocked result stays history.
|
|
77
|
+
const RERUNNABLE=Object.freeze({test_author_blocked:'test_author',repair_blocked:'repair',regression_blocked:'regression',
|
|
78
|
+
post_review_regression_blocked:'post_review_regression',walkthrough_blocked:'walkthrough',
|
|
79
|
+
revision_test_author_blocked:'revision_test_author',revision_repair_blocked:'revision_repair',
|
|
80
|
+
revision_regression_blocked:'revision_regression',revision_post_review_regression_blocked:'revision_post_review_regression',
|
|
81
|
+
revision_walkthrough_blocked:'revision_walkthrough'});
|
|
82
|
+
export const MAX_FIX_BLOCKED_RERUNS=2;
|
|
83
|
+
// Record numbers cover every legal rerun: two per step kind across all kinds.
|
|
84
|
+
const MAX_FIX_BLOCKED_RERUN_RECORDS=Object.keys(RERUNNABLE).length*MAX_FIX_BLOCKED_RERUNS;
|
|
85
|
+
const BLOCKED_RERUN_ID=/^fix-blocked-rerun-([1-9]\d?)$/;
|
|
86
|
+
const blockedRerunNumber=id=>{const match=BLOCKED_RERUN_ID.exec(id);
|
|
87
|
+
const n=match?Number(match[1]):0;return n>=1&&n<=MAX_FIX_BLOCKED_RERUN_RECORDS?n:0;};
|
|
68
88
|
const latestStepRecord=(records,id)=>[...records].reverse().find(row=>retryBase(row.id)===id);
|
|
69
89
|
// A cause or second-round final review that produced no review result may be
|
|
70
90
|
// abandoned once, audited, and dispatched again under its own record prefix.
|
|
91
|
+
// Each cause review round has its own one-time abandonment: round 1 under
|
|
92
|
+
// fix-cause-*, the post-rediagnosis round 2 under fix-cause-rediagnosis-*.
|
|
71
93
|
const REVIEW_ABANDON={cause_review:'fix-cause',revision_final_review:'fix-revision-final'};
|
|
94
|
+
// V5 (F23/F26): a second no-result abandonment per round (MAX_FIX_REVIEW_ABANDONS)
|
|
95
|
+
// is recorded as <prefix>-abandoned-2 and redispatched under <prefix>-retry-2-*.
|
|
96
|
+
export const MAX_FIX_REVIEW_ABANDONS=2;
|
|
97
|
+
export const FIX_REVIEW_RECOVERY_LIMIT_REASON=`fix_review_recovery_limit: 首轮最终审查的 worker 连续没有打开审查线程就丢失,无线程恢复已用满 ${MAX_FIX_REVIEW_ABANDONS} 次,不再续审。`
|
|
98
|
+
+'先查清审查 CLI 为何起不来(登录、额度、网络或本机环境),原运行记录保留不改写;修好后发 cancel 结束本运行,用新的 runId 重新发起修复。';
|
|
99
|
+
const cycleId=(prefix,rows,suffix)=>rows.some(row=>row.id===`${prefix}-abandoned-2`)?`${prefix}-retry-2-${suffix}`
|
|
100
|
+
:rows.some(row=>row.id===`${prefix}-abandoned`)?`${prefix}-retry-${suffix}`:`${prefix}-${suffix}`;
|
|
72
101
|
const causeRecord=(records,suffix)=>{
|
|
73
102
|
const marker=records.findIndex(row=>row.id==='fix-rediagnosis-intent');
|
|
103
|
+
const tail=marker<0?null:records.slice(marker+1);
|
|
74
104
|
const row=marker<0?reviewCycleRecord(records,'fix-cause',suffix)
|
|
75
|
-
:
|
|
105
|
+
:tail.find(row=>row.id===cycleId('fix-cause-rediagnosis',tail,suffix));
|
|
76
106
|
return suffix==='result'?reconciledFixResultRecord(records,row):row;
|
|
77
107
|
};
|
|
78
108
|
const reviewCycleRecord=(records,prefix,suffix)=>{
|
|
79
|
-
const row=records.
|
|
80
|
-
?records.find(row=>row.id===`${prefix}-retry-${suffix}`):records.find(row=>row.id===`${prefix}-${suffix}`);
|
|
109
|
+
const row=records.find(row=>row.id===cycleId(prefix,records,suffix));
|
|
81
110
|
return suffix==='result'?reconciledFixResultRecord(records,row):row;
|
|
82
111
|
};
|
|
83
112
|
// Reviews wait for their own budget (host review configuration), never for the
|
|
@@ -88,27 +117,21 @@ function reviewTimeout(adapter,fallback){
|
|
|
88
117
|
return adapter.timeoutMs;
|
|
89
118
|
}
|
|
90
119
|
|
|
91
|
-
|
|
92
|
-
const value=json(raw,32*1024);
|
|
93
|
-
shape(value,['status','rootCause','affectedPaths','plan','crossLayer','affectedModules',...(Object.hasOwn(value,'investigation')?['investigation']:[])]);
|
|
94
|
-
need(['diagnosed','needs_evidence','design_change'].includes(value.status),'invalid_diagnosis');
|
|
95
|
-
for(const key of ['rootCause','plan'])text(value[key]);
|
|
96
|
-
need(typeof value.crossLayer==='boolean','invalid_diagnosis');
|
|
97
|
-
if(Object.hasOwn(value,'investigation'))inspectFixInvestigation(value.investigation,value.crossLayer);
|
|
98
|
-
for(const key of ['affectedPaths','affectedModules']){
|
|
99
|
-
need(Array.isArray(value[key])&&value[key].length>0&&value[key].length<=32,'invalid_diagnosis');
|
|
100
|
-
for(const item of value[key]){
|
|
101
|
-
text(item);need(!path.isAbsolute(item)&&item===path.posix.normalize(item)
|
|
102
|
-
&&item!=='.'&&!item.startsWith('../')&&!/[\\\0]/.test(item),'invalid_diagnosis');
|
|
103
|
-
}
|
|
104
|
-
need(new Set(value[key]).size===value[key].length,'invalid_diagnosis');
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
120
|
+
const diagnosis=inspectFixDiagnosis;
|
|
108
121
|
|
|
109
|
-
const HISTORY_INSPECTION=Symbol('fix-history-inspection');
|
|
122
|
+
const HISTORY_INSPECTION=Symbol('fix-history-inspection'),DURABLE_HISTORY=Symbol('fix-durable-history');
|
|
110
123
|
// Same owner projection, backed by a read-only journal and no writer/dispatch.
|
|
111
124
|
export function inspectFixExecutionHistory({specsRoot,identity}){
|
|
125
|
+
return readFixHistory({specsRoot,identity},owner=>owner.status());
|
|
126
|
+
}
|
|
127
|
+
// The same read-only owner's completion evidence: present only for a run that
|
|
128
|
+
// reached its normal completed closeout (approved final review of the exact
|
|
129
|
+
// package, task_done and run_done bound), else it throws. Grants nothing.
|
|
130
|
+
export function inspectFixCompletionHistory({specsRoot,identity}){
|
|
131
|
+
return readFixHistory({specsRoot,identity,durable:true},(owner,initial)=>({identity:initial.identity,
|
|
132
|
+
configuration:initial.configuration,evidence:owner.completionEvidence()}));
|
|
133
|
+
}
|
|
134
|
+
function readFixHistory({specsRoot,identity,durable=false},read){
|
|
112
135
|
const snapshot=readExecutionSnapshot({specsRoot,identity});
|
|
113
136
|
const initial=snapshot.records[0]?.payload;need(initial?.workflow==='cm-fix-stages-v1','fix_history_invalid');
|
|
114
137
|
validIdentity(initial.identity);
|
|
@@ -117,11 +140,12 @@ export function inspectFixExecutionHistory({specsRoot,identity}){
|
|
|
117
140
|
need(digest(snapshot.fingerprints)===digest({workflow:digest('cm-fix-stages-v1'),config:digest(initial.configuration),inputs:digest(initial.identity)}),'fingerprint_mismatch');
|
|
118
141
|
const {archiveMode,...configuration}=initial.configuration;
|
|
119
142
|
need(archiveMode===undefined||archiveMode==='bare','fix_history_invalid');
|
|
120
|
-
const owner=openFixExecution({specsRoot:archiveMode==='bare'?null:specsRoot,identity:initial.identity,configuration,create:false},{[HISTORY_INSPECTION]:snapshot});
|
|
121
|
-
try{return owner
|
|
143
|
+
const owner=openFixExecution({specsRoot:archiveMode==='bare'?null:specsRoot,identity:initial.identity,configuration,create:false},{[HISTORY_INSPECTION]:snapshot,[DURABLE_HISTORY]:durable});
|
|
144
|
+
try{return read(owner,initial);}finally{owner.close();}
|
|
122
145
|
}
|
|
123
146
|
|
|
124
|
-
export function openFixExecution(options,{bridge=null,prepare=null,causeReview=null,finalReview=null,assertReviewReady=null,[HISTORY_INSPECTION]:inspectionSnapshot=null}={}){
|
|
147
|
+
export function openFixExecution(options,{bridge=null,prepare=null,causeReview=null,finalReview=null,assertReviewReady=null,[HISTORY_INSPECTION]:inspectionSnapshot=null,[DURABLE_HISTORY]:durableHistory=false}={}){
|
|
148
|
+
need(!durableHistory||inspectionSnapshot,'fix_read_only');
|
|
125
149
|
shape(options,['identity','configuration','create',...(Object.hasOwn(options,'hostContextId')?['hostContextId']:[]),
|
|
126
150
|
...(Object.hasOwn(options,'specsRoot')?['specsRoot']:[])]);
|
|
127
151
|
const {identity,configuration:originalConfiguration,create}=json(options,64*1024);validIdentity(identity);
|
|
@@ -200,12 +224,15 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
200
224
|
try{store=inspectionSnapshot?{snapshot:()=>inspectionSnapshot,close(){},append(){need(false,'fix_read_only');}}:openExecutionStore({specsRoot,identity:{repositoryId:identity.repositoryId,runId:identity.runId},create,
|
|
201
225
|
fingerprints:{workflow:digest('cm-fix-stages-v1'),config:digest(configuration),inputs:digest(identity)}});}catch(error){guard?.close();throw error;}
|
|
202
226
|
const closeStore=()=>{try{store.close();}finally{guard?.close();}};
|
|
203
|
-
let active=null,closed=false;
|
|
227
|
+
let active=null,closed=false,lastPinned={};
|
|
204
228
|
const retryCount=base=>{
|
|
205
229
|
const records=store.snapshot().records;
|
|
206
230
|
return records.filter(row=>/^fix-abandoned-[1-8]$/.test(row.id)).filter(row=>{
|
|
207
231
|
const intent=records.find(item=>digest(item)===row.payload.intentDigest);
|
|
208
232
|
return intent&&stepRecord(retryBase(intent.id))?.base===base;
|
|
233
|
+
}).length+records.filter(row=>blockedRerunNumber(row.id)>0).filter(row=>{
|
|
234
|
+
const intent=records.find(item=>digest(item)===row.payload.intentDigest);
|
|
235
|
+
return intent&&stepRecord(retryBase(intent.id))?.base===base;
|
|
209
236
|
}).length;
|
|
210
237
|
};
|
|
211
238
|
const append=(recordId,kind,payload)=>{
|
|
@@ -392,8 +419,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
392
419
|
append(recordId,'result',payload);
|
|
393
420
|
}catch{/* Missing, conflicting or unbound receipts never change the original unknown. */}
|
|
394
421
|
}
|
|
395
|
-
|
|
396
|
-
|
|
422
|
+
// snapshot: the store's, or a candidate one a writer validates before appending.
|
|
423
|
+
function project(snapshot=store.snapshot()){
|
|
397
424
|
need(snapshot.records.length>0,'fix_history_invalid');
|
|
398
425
|
const [first,...records]=snapshot.records;
|
|
399
426
|
// Older runs could advance a recovered single-layer diagnosis without cause review.
|
|
@@ -418,7 +445,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
418
445
|
need(first.id==='fix-configuration'&&first.kind==='intent'&&digest(first.payload)===digest(initial),'fix_history_invalid');
|
|
419
446
|
let stage='reproduce',pending=null,reproduction=null,diagnosed=null,learning=null,cause=null,started=null,causeResult=null,red=null,redFiles=null,baseline=null,baselineFiles=null;
|
|
420
447
|
let pendingOrigin=null,pendingIntent=null;
|
|
421
|
-
const abandoned=[],retryCounts=new Map();
|
|
448
|
+
const abandoned=[],retryCounts=new Map(),pinned={},blockedReruns={};let lastStepResult=null;
|
|
422
449
|
let authorBaseline=null,authored=null,escalationIntent=null,escalation=null;
|
|
423
450
|
const redStage=()=>diagnosed?.status==='design_change'?'design_change_required':'red_test_required';
|
|
424
451
|
let repairBaseline=null,repaired=null;
|
|
@@ -426,6 +453,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
426
453
|
let finalRegistration=null,finalStarted=null,finalResult=null,finalRecovery=null,finalRecoveryCount=0;
|
|
427
454
|
let rediagnosis=null,rediagnosisThread=null;
|
|
428
455
|
let causeOrigin=null,causeResultPayload=null,causeAbandonment=null,revisionFinalResultPayload=null,revisionAbandonment=null;
|
|
456
|
+
let causeAbandonment2=null,revisionAbandonment2=null;
|
|
429
457
|
const finalInvocations=new Set(),finalThreads=new Set();
|
|
430
458
|
let joinedCount=0;const seenJoined=new Set();
|
|
431
459
|
let n5=null,postReviewRegression=null,walkthrough=null,revision=null,revisionBaseline=null,revisionRepair=null,revisionRegression=null;
|
|
@@ -444,6 +472,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
444
472
|
}
|
|
445
473
|
need(digest(inventory([...reviewedFiles.values()]))===digest(inventory(next.files)),'fix_revision_source_mismatch');
|
|
446
474
|
}
|
|
475
|
+
const pendingBaseline=kind=>({test_author:authorBaseline,repair:repairBaseline,revision_test_author:revisionAuthorBaseline,revision_repair:revisionBaseline})[kind];
|
|
476
|
+
const assertPinned=(kind,value)=>{if(pinned[kind])need(digest(value)===digest(pinned[kind]),'fix_history_invalid');};
|
|
447
477
|
const reviewLedger=fixReviewLedger(snapshot.records,configuration);
|
|
448
478
|
for(const storedRecord of records){
|
|
449
479
|
if(/^fix-review-(receipt|reconciled)-/.test(storedRecord.id))continue;
|
|
@@ -452,8 +482,12 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
452
482
|
if(abandonedMatch){
|
|
453
483
|
need(Number(abandonedMatch[1])===abandoned.length+1&&record.kind==='result'
|
|
454
484
|
&&stage==='unknown'&&abandonable.has(pending)&&pendingIntent&&pendingOrigin,'fix_history_invalid');
|
|
455
|
-
shape(record.payload,['pending','reason','abandonedAt','intentDigest']);
|
|
485
|
+
shape(record.payload,['pending','reason','abandonedAt','intentDigest',...(Object.hasOwn(record.payload,'baselinePinned')?['baselinePinned']:[])]);
|
|
456
486
|
need(record.payload.pending===pending&&record.payload.intentDigest===digest(pendingIntent),'fix_history_invalid');
|
|
487
|
+
if(Object.hasOwn(record.payload,'baselinePinned')){
|
|
488
|
+
need(record.payload.baselinePinned===true&&PINNED_STEPS.has(pending),'fix_history_invalid');
|
|
489
|
+
pinned[pending]??=pendingBaseline(pending);
|
|
490
|
+
}
|
|
457
491
|
need(typeof record.payload.reason==='string'&&record.payload.reason.trim().length>0
|
|
458
492
|
&&Buffer.byteLength(record.payload.reason,'utf8')<=1000
|
|
459
493
|
&&!/[\r\n\0\u0085\u2028\u2029]/.test(record.payload.reason)&&Number.isSafeInteger(record.payload.abandonedAt)
|
|
@@ -471,8 +505,39 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
471
505
|
if(pending==='revision_retrospective')revisionRetrospectivePackage=null;
|
|
472
506
|
stage=pendingOrigin;pending=null;pendingOrigin=null;pendingIntent=null;continue;
|
|
473
507
|
}
|
|
508
|
+
const blockedRerun=blockedRerunNumber(record.id)?[record.id,String(blockedRerunNumber(record.id))]:null;
|
|
509
|
+
if(blockedRerun){
|
|
510
|
+
const kind=RERUNNABLE[stage];
|
|
511
|
+
need(Number(blockedRerun[1])===Object.values(blockedReruns).reduce((a,b)=>a+b,0)+1&&record.kind==='result'
|
|
512
|
+
&&kind&&pending===null&&revision===null===!kind.startsWith('revision_')&&pendingIntent&&pendingOrigin&&lastStepResult
|
|
513
|
+
&&stepRecord(retryBase(pendingIntent.id))?.pending===kind&&stepRecord(retryBase(lastStepResult.id))?.pending===kind
|
|
514
|
+
&&(blockedReruns[kind]??0)<MAX_FIX_BLOCKED_RERUNS,'fix_history_invalid');
|
|
515
|
+
shape(record.payload,['stage','pending','reason','rerunAt','intentDigest','resultDigest',...(Object.hasOwn(record.payload,'baselinePinned')?['baselinePinned']:[])]);
|
|
516
|
+
need(record.payload.stage===stage&&record.payload.pending===kind&&record.payload.intentDigest===digest(pendingIntent)
|
|
517
|
+
&&record.payload.resultDigest===digest(lastStepResult)&&typeof record.payload.reason==='string'&&record.payload.reason.trim().length>0
|
|
518
|
+
&&Buffer.byteLength(record.payload.reason,'utf8')<=1000&&!/[\r\n\0\u0085\u2028\u2029]/.test(record.payload.reason)
|
|
519
|
+
&&Number.isSafeInteger(record.payload.rerunAt)&&record.payload.rerunAt>0,'fix_history_invalid');
|
|
520
|
+
if(Object.hasOwn(record.payload,'baselinePinned')){
|
|
521
|
+
need(record.payload.baselinePinned===true&&PINNED_STEPS.has(kind),'fix_history_invalid');pinned[kind]??=pendingBaseline(kind);
|
|
522
|
+
}
|
|
523
|
+
const base=stepRecord(retryBase(pendingIntent.id)).base;
|
|
524
|
+
need((retryCounts.get(base)??0)<8,'fix_history_invalid');retryCounts.set(base,(retryCounts.get(base)??0)+1);
|
|
525
|
+
blockedReruns[kind]=(blockedReruns[kind]??0)+1;
|
|
526
|
+
if(kind==='test_author'){authored=null;authorBaseline=null;}
|
|
527
|
+
if(kind==='repair'){repaired=null;repairBaseline=null;}
|
|
528
|
+
if(kind==='regression')regression=null;
|
|
529
|
+
if(kind==='post_review_regression')postReviewRegression=null;
|
|
530
|
+
if(kind==='walkthrough')walkthrough=null;
|
|
531
|
+
if(kind==='revision_test_author'){revisionAuthored=null;revisionAuthorBaseline=null;}
|
|
532
|
+
if(kind==='revision_repair'){revisionRepair=null;revisionBaseline=null;}
|
|
533
|
+
if(kind==='revision_regression')revisionRegression=null;
|
|
534
|
+
if(kind==='revision_post_review_regression')revisionPostRegression=null;
|
|
535
|
+
if(kind==='revision_walkthrough')revisionWalkthrough=null;
|
|
536
|
+
stage=pendingOrigin;pendingOrigin=null;pendingIntent=null;lastStepResult=null;continue;
|
|
537
|
+
}
|
|
474
538
|
const retried=/^(.*)-retry-([1-8])-(intent|result)$/.exec(record.id);
|
|
475
|
-
|
|
539
|
+
// A review cycle's second retry (fix-cause-retry-2-result) is not a step retry.
|
|
540
|
+
if(retried&&!/^fix-(?:cause(?:-rediagnosis)?|revision-final)$/.test(retried[1])){
|
|
476
541
|
const baseId=`${retried[1]}-${retried[3]}`,step=stepRecord(baseId);
|
|
477
542
|
need(step&&Number(retried[2])===retryCounts.get(step.base)
|
|
478
543
|
&&record.kind===retried[3],'fix_history_invalid');
|
|
@@ -481,7 +546,10 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
481
546
|
if(/^fix-final-recovery-(?:[1-9]\d*-)?authorized$/.test(record.id)){
|
|
482
547
|
need(!(configuration.externalModels||configuration.executionPolicy),'external_review_reconciliation_required');
|
|
483
548
|
need(record.id===`${recoveryPrefix(finalRecoveryCount+1)}-authorized`,'fix_history_invalid');
|
|
484
|
-
|
|
549
|
+
// V5 (F24): a first final review whose worker never opened a thread may
|
|
550
|
+
// also be recovered, bound to providerThreadId null, while fewer than
|
|
551
|
+
// MAX_FIX_REVIEW_ABANDONS recoveries were made (threaded ones keep their rule).
|
|
552
|
+
need(identity.attempt===1&&stage==='unknown'&&finalRegistration&&(finalStarted||finalRecoveryCount<MAX_FIX_REVIEW_ABANDONS)&&!revision
|
|
485
553
|
&&(!finalResult||finalResult.observationStatus==='unknown')&&record.kind==='result','fix_review_recovery_unavailable');
|
|
486
554
|
const value=record.payload;
|
|
487
555
|
shape(value,['invocationId','packageDigest','registrationDigest','providerThreadId','previousInvocationStopped','reason']);
|
|
@@ -511,7 +579,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
511
579
|
&&digest(value.reviewFeedback)===digest(causeResult.review),'fix_history_invalid');
|
|
512
580
|
if(value.learning!==null)inspectFixLearning(value.learning);
|
|
513
581
|
rediagnosis=value;rediagnosisThread=started;learning=value.learning;
|
|
514
|
-
cause=null;causeResult=null;causeResultPayload=null;started=null;causeAbandonment=null;
|
|
582
|
+
cause=null;causeResult=null;causeResultPayload=null;started=null;causeAbandonment=null;causeAbandonment2=null;
|
|
515
583
|
stage='unknown';pending='rediagnosis';continue;
|
|
516
584
|
}
|
|
517
585
|
if(record.id==='fix-rediagnosis-result'){
|
|
@@ -519,14 +587,18 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
519
587
|
diagnosed=diagnosis(record.payload);pending=null;
|
|
520
588
|
stage=diagnosed.status==='needs_evidence'?'rediagnosis_blocked':'cause_review_required';continue;
|
|
521
589
|
}
|
|
522
|
-
|
|
590
|
+
// Round 2 (after rediagnosis) replays as the cause review cycle, including its own one-time abandonment and retry.
|
|
591
|
+
const causeRevised=/^fix-cause-rediagnosis-((?:retry-(?:2-)?)?(?:registered|started|result)|abandoned(?:-2)?)$/.exec(record.id);
|
|
523
592
|
if(causeRevised){need(rediagnosis!==null,'fix_history_invalid');record={...record,id:`fix-cause-${causeRevised[1]}`};}
|
|
524
|
-
else if(rediagnosis!==null&&/^fix-cause-(?:retry-)?(?:registered|started|result)$/.test(record.id))need(false,'fix_history_invalid');
|
|
525
|
-
// After
|
|
526
|
-
|
|
593
|
+
else if(rediagnosis!==null&&/^fix-cause-(?:(?:retry-(?:2-)?)?(?:registered|started|result)|abandoned(?:-2)?)$/.test(record.id))need(false,'fix_history_invalid');
|
|
594
|
+
// After an abandonment only the next cycle's records are valid: retry-*
|
|
595
|
+
// after the first, retry-2-* after the second (V5, at most two per round).
|
|
596
|
+
const reviewRetry=/^(fix-cause|fix-revision-final)-retry-(2-)?(registered|started|result)$/.exec(record.id);
|
|
527
597
|
if(reviewRetry){
|
|
528
|
-
|
|
529
|
-
|
|
598
|
+
const first=reviewRetry[1]==='fix-cause'?causeAbandonment:revisionAbandonment;
|
|
599
|
+
const second=reviewRetry[1]==='fix-cause'?causeAbandonment2:revisionAbandonment2;
|
|
600
|
+
need(reviewRetry[2]?second!==null:first!==null&&second===null,'fix_history_invalid');
|
|
601
|
+
record={...record,id:`${reviewRetry[1]}-${reviewRetry[3]}`};
|
|
530
602
|
}else if(/^fix-cause-(registered|started|result)$/.test(record.id))need(causeAbandonment===null,'fix_history_invalid');
|
|
531
603
|
else if(/^fix-revision-final-(registered|started|result)$/.test(record.id))need(revisionAbandonment===null,'fix_history_invalid');
|
|
532
604
|
const observed=/^fix-observation-(?:(\d+)-)?(resume-prepared|reproduce-intent|reproduce-result|diagnose-intent|diagnose-result)$/.exec(record.id);
|
|
@@ -540,6 +612,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
540
612
|
need(pending===null,'fix_history_invalid');
|
|
541
613
|
pendingOrigin=stage;pendingIntent=storedRecord;
|
|
542
614
|
}
|
|
615
|
+
if(localStep&&record.kind==='result')lastStepResult=storedRecord;
|
|
543
616
|
need(stage!=='cancelled'&&stage!=='escalated','fix_history_invalid');
|
|
544
617
|
const joined=joinedRecord.exec(record.id);
|
|
545
618
|
if(joined){
|
|
@@ -636,7 +709,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
636
709
|
if(record.id==='fix-revision-test-author-intent'){
|
|
637
710
|
need(revision?.tests&&stage==='revision_test_author_required'&&record.kind==='intent','fix_history_invalid');
|
|
638
711
|
shape(record.payload,['baseline','revisionDigest']);
|
|
639
|
-
revisionAuthorBaseline=readReviewBaseline(record.payload.baseline);
|
|
712
|
+
revisionAuthorBaseline=readReviewBaseline(record.payload.baseline);assertPinned('revision_test_author',revisionAuthorBaseline);
|
|
640
713
|
need(record.payload.revisionDigest===digest(revision)&&digest(revisionAuthorBaseline.identity)===digest(revision.nextIdentity)
|
|
641
714
|
&&digest(revisionAuthorBaseline.scope)===digest([...revision.tests.testFiles].sort())
|
|
642
715
|
&&digest(revisionAuthorBaseline.requirements)===digest([...configuration.repair.requirements].sort())
|
|
@@ -663,7 +736,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
663
736
|
if(record.id==='fix-revision-repair-intent'){
|
|
664
737
|
need(revision&&revisionBaseline===null&&['final_review_changes_requested','walkthrough_blocked','post_review_regression_blocked',...(revision.tests?['revision_prepared']:[])].includes(stage)&&record.kind==='intent','fix_history_invalid');
|
|
665
738
|
shape(record.payload,['baseline','revisionDigest','redDigest','testBaselineDigest']);
|
|
666
|
-
revisionBaseline=readReviewBaseline(record.payload.baseline);
|
|
739
|
+
revisionBaseline=readReviewBaseline(record.payload.baseline);assertPinned('revision_repair',revisionBaseline);
|
|
667
740
|
need(digest(revisionBaseline.identity)===digest(revision.nextIdentity)
|
|
668
741
|
&&revisionBaseline.rootDigest===repairBaseline.rootDigest&&(revisionBaseline.specsPath??null)===(repairBaseline.specsPath??null)
|
|
669
742
|
&&digest(revisionBaseline.scope)===digest(repairBaseline.scope)&&digest(revisionBaseline.requirements)===digest(repairBaseline.requirements)
|
|
@@ -740,11 +813,12 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
740
813
|
need(record.payload.outcome==='created'&&record.payload.status==='ready_for_review'&&/^[a-f0-9]{64}$/.test(record.payload.handoffSha256),'invalid_handoff_result');
|
|
741
814
|
revisionHandoff=record.payload;pending=null;stage='revision_final_review_required';continue;
|
|
742
815
|
}
|
|
743
|
-
if(
|
|
816
|
+
if(/^(fix-cause|fix-revision-final)-abandoned(-2)?$/.test(record.id)){
|
|
744
817
|
need(!(configuration.externalModels||configuration.executionPolicy),'external_review_reconciliation_required');
|
|
745
|
-
const causeKind=record.id
|
|
818
|
+
const causeKind=record.id.startsWith('fix-cause-'),secondAbandon=record.id.endsWith('-2');
|
|
746
819
|
const registration=causeKind?cause:revisionFinalRegistration,result=causeKind?causeResult:revisionFinalResult;
|
|
747
|
-
|
|
820
|
+
const prior=causeKind?[causeAbandonment,causeAbandonment2]:[revisionAbandonment,revisionAbandonment2];
|
|
821
|
+
need(record.kind==='result'&&(secondAbandon?prior[0]!==null&&prior[1]===null:prior[0]===null)&®istration&&stage==='unknown'
|
|
748
822
|
&&(pending===(causeKind?'cause_review':'revision_final_review')&&!result
|
|
749
823
|
||pending===null&&result&&result.observationStatus!=='completed'),'fix_history_invalid');
|
|
750
824
|
const value=record.payload,resultPayload=causeKind?causeResultPayload:revisionFinalResultPayload;
|
|
@@ -755,9 +829,11 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
755
829
|
need(typeof value.reason==='string'&&value.reason.trim().length>0&&Buffer.byteLength(value.reason,'utf8')<=1000
|
|
756
830
|
&&!/[\r\n\0\u0085\u2028\u2029]/.test(value.reason)&&Number.isSafeInteger(value.abandonedAt)&&value.abandonedAt>0,'fix_history_invalid');
|
|
757
831
|
if(causeKind){
|
|
758
|
-
|
|
832
|
+
if(secondAbandon)causeAbandonment2=value;else causeAbandonment=value;
|
|
833
|
+
stage=causeOrigin;cause=null;started=null;causeResult=null;causeResultPayload=null;causeResumeStage=null;
|
|
759
834
|
}else{
|
|
760
|
-
|
|
835
|
+
if(secondAbandon)revisionAbandonment2=value;else revisionAbandonment=value;
|
|
836
|
+
stage='revision_final_review_required';
|
|
761
837
|
revisionFinalRegistration=null;revisionFinalStarted=null;revisionFinalResult=null;revisionFinalResultPayload=null;
|
|
762
838
|
}
|
|
763
839
|
pending=null;continue;
|
|
@@ -774,7 +850,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
774
850
|
need(revision&&pending==='revision_final_review'&&revisionFinalStarted===null&&record.kind==='result','fix_history_invalid');
|
|
775
851
|
need(record.payload.providerThreadId!==finalRecovery?.providerThreadId,'final_context_mismatch');
|
|
776
852
|
shape(record.payload,['providerThreadId']);id(record.payload.providerThreadId);
|
|
777
|
-
need(record.payload.providerThreadId
|
|
853
|
+
need(![revisionAbandonment?.providerThreadId,revisionAbandonment2?.providerThreadId].includes(record.payload.providerThreadId),'final_context_mismatch');
|
|
778
854
|
const config=fixRevisionReviewConfiguration(revisionFeedback(),revision.nextIdentity,hostContextIds);
|
|
779
855
|
need(![...fixHostContexts(config),config.reviewer.contextId,...config.reviewer.excludedThreadIds].includes(record.payload.providerThreadId),'final_context_mismatch');
|
|
780
856
|
revisionFinalStarted=record.payload.providerThreadId;continue;
|
|
@@ -937,7 +1013,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
937
1013
|
if(record.id==='fix-repair-intent'){
|
|
938
1014
|
need(configuration.repair&&stage==='repair_required'&&repairBaseline===null&&record.kind==='intent','fix_history_invalid');
|
|
939
1015
|
shape(record.payload,['baseline','redDigest','testBaselineDigest']);
|
|
940
|
-
repairBaseline=readReviewBaseline(record.payload.baseline);
|
|
1016
|
+
repairBaseline=readReviewBaseline(record.payload.baseline);assertPinned('repair',repairBaseline);
|
|
941
1017
|
const codeRoot=fs.realpathSync(configuration.reproduction.cwd);
|
|
942
1018
|
need(digest(repairBaseline.identity)===digest(identity)&&repairBaseline.rootDigest===createHash('sha256').update(codeRoot).digest('hex')
|
|
943
1019
|
&&(repairBaseline.specsPath??null)===reviewSpecsPath(codeRoot,evidenceSpecsRoot)
|
|
@@ -955,7 +1031,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
955
1031
|
}
|
|
956
1032
|
if(record.id==='fix-test-author-intent'){
|
|
957
1033
|
need(configuration.testAuthor&&stage===redStage()&&authorBaseline===null&&record.kind==='intent','fix_history_invalid');
|
|
958
|
-
authorBaseline=readReviewBaseline(record.payload);
|
|
1034
|
+
authorBaseline=readReviewBaseline(record.payload);assertPinned('test_author',authorBaseline);
|
|
959
1035
|
const codeRoot=fs.realpathSync(configuration.reproduction.cwd);
|
|
960
1036
|
need(authorBaseline.rootDigest===createHash('sha256').update(codeRoot).digest('hex')
|
|
961
1037
|
&&(authorBaseline.specsPath??null)===reviewSpecsPath(codeRoot,evidenceSpecsRoot),'test_author_binding_mismatch');
|
|
@@ -1039,7 +1115,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1039
1115
|
need(pending==='cause_review'&&started===null&&record.kind==='result','fix_history_invalid');
|
|
1040
1116
|
shape(record.payload,['providerThreadId']);id(record.payload.providerThreadId);started=record.payload.providerThreadId;
|
|
1041
1117
|
need(![...hostContextIds,configuration.causeReview.contextId,finalStarted,rediagnosisThread,...configuration.causeReview.excludedThreadIds,
|
|
1042
|
-
causeAbandonment?.providerThreadId].includes(started),'cause_registration_mismatch');continue;
|
|
1118
|
+
causeAbandonment?.providerThreadId,causeAbandonment2?.providerThreadId].filter(Boolean).includes(started),'cause_registration_mismatch');continue;
|
|
1043
1119
|
}
|
|
1044
1120
|
if(record.id==='fix-cause-result'){
|
|
1045
1121
|
need(pending==='cause_review'&&record.kind==='result','fix_history_invalid');
|
|
@@ -1090,102 +1166,113 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1090
1166
|
if(configuration.walkthrough&&diagnosed?.status==='diagnosed'
|
|
1091
1167
|
&&['red_test_required','cause_review_required'].includes(stage)
|
|
1092
1168
|
&&!walkthroughCoversDiagnosis(configuration.walkthrough,diagnosed))stage='walkthrough_configuration_mismatch';
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1169
|
+
// Live re-verification of the run's evidence against the current tree. A
|
|
1170
|
+
// durable history read (a completed run as a later delivery of its root) asks
|
|
1171
|
+
// only what the journal and its closeout settled: later reviewed changes may
|
|
1172
|
+
// legitimately move these files, and the caller checks the tree itself.
|
|
1173
|
+
if(!durableHistory){
|
|
1174
|
+
// F14 exemption: once a repair (or, while it is being redone, a test
|
|
1175
|
+
// authoring) pinned its baseline, that intent already passed this check;
|
|
1176
|
+
// the residue in its scope is the redo's input and is reviewed against
|
|
1177
|
+
// the pinned baseline, so it is not cause-review drift.
|
|
1178
|
+
if(causeResult?.review?.verdict==='approved'&&stage!=='cancelled'&&repairBaseline===null&&!pinned.repair
|
|
1179
|
+
&&!(pinned.test_author&&authored===null)){
|
|
1180
|
+
try{
|
|
1181
|
+
const current=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,
|
|
1182
|
+
context:Object.hasOwn(cause.request.payload.reviewPackage,'contextFiles'),status:{identity,stage:'cause_review_required',reproduction,diagnosis:diagnosed,learning,
|
|
1183
|
+
...(rediagnosis?{rediagnosis}:{}),
|
|
1184
|
+
...(cause.request.payload.reviewPackage.correction?{causeReviewCorrection:cause.request.payload.reviewPackage.correction}:{})}});
|
|
1185
|
+
verifyFixCauseTransition(cause.request.payload.reviewPackage,current,authorBaseline,authored);
|
|
1186
|
+
}catch{stage='cause_review_drift';}
|
|
1187
|
+
}
|
|
1188
|
+
if(causeResult?.observationStatus==='completed'&&!['cancelled','cause_review_drift'].includes(stage)){
|
|
1189
|
+
try{publishCause(true);}catch{stage='cause_review_evidence_required';}
|
|
1190
|
+
}
|
|
1191
|
+
if(red&&!(revisionAuthorBaseline&&stage==='unknown')&&!['cancelled','cause_review_drift','cause_review_evidence_required'].includes(stage)){
|
|
1192
|
+
try{verifyFixRedEvidence(red,configuration.redTest,evidenceSpecsRoot,currentTestFiles(red.testFiles,revisionAuthored?.outcome==='authored'?{files:revisionAuthored.testFiles}:null));}catch{stage='red_test_evidence_required';}
|
|
1193
|
+
}
|
|
1194
|
+
if(baseline&&['repair_required','baseline_blocked'].includes(stage)){
|
|
1195
|
+
try{need(digest(fixBaselineFiles(configuration.baseline))===digest(baseline.testFiles),'baseline_files_changed');}
|
|
1196
|
+
catch{stage='baseline_evidence_required';}
|
|
1197
|
+
}
|
|
1198
|
+
if(stage===redStage()&&configuration.testAuthor&&!authored)stage='test_author_required';
|
|
1199
|
+
if(stage===redStage()&&authored){
|
|
1200
|
+
try{need(digest(redTestFiles(configuration.redTest))===digest(authored.testFiles),'test_author_drift');}
|
|
1201
|
+
catch{stage='test_author_evidence_required';}
|
|
1202
|
+
}
|
|
1203
|
+
if(!revisionAuthorBaseline&&repaired&&!learningPackage&&['regression_required','repair_blocked','handoff_required','regression_blocked','handoff_ready','learning_writeback_required','learning_writeback_blocked',...finalStages].includes(stage)){
|
|
1204
|
+
try{verifyFixRepair({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,baseline:repairBaseline,result:repaired});}
|
|
1205
|
+
catch{stage='repair_evidence_required';}
|
|
1206
|
+
}
|
|
1207
|
+
if(!revisionAuthorBaseline&&retrospective&&!learningPackage&&['handoff_ready','learning_writeback_required',...finalStages].includes(stage)){
|
|
1208
|
+
try{need(implementationPackage(regression).packageDigest===retrospective.packageDigest,'retrospective_drift');}
|
|
1209
|
+
catch{stage='retrospective_evidence_required';}
|
|
1210
|
+
}
|
|
1211
|
+
if(!revisionAuthorBaseline&&learningPackage&&['handoff_ready',...finalStages].includes(stage)){
|
|
1212
|
+
try{need(implementationPackage(regression,true).packageDigest===learningPackage.packageDigest,'writeback_drift');}
|
|
1213
|
+
catch{stage='learning_writeback_evidence_required';}
|
|
1214
|
+
}
|
|
1215
|
+
if(!revisionAuthorBaseline&&handoff&&finalStages.includes(stage)){
|
|
1216
|
+
try{
|
|
1217
|
+
const checked=verifyHostHandoff({root:configuration.reproduction.cwd,baseline:learningPackage?fixLearningReviewBaseline(reviewBaseline()):reviewBaseline(),
|
|
1218
|
+
checks:reviewChecks(regression),handoffPath:handoffPath(),evidence:store.snapshot().records.find(record=>record.id==='fix-handoff-intent').payload.evidence});
|
|
1219
|
+
need(checked.handoffSha256===handoff.handoffSha256,'handoff_drift');
|
|
1220
|
+
}catch{stage='handoff_evidence_required';}
|
|
1221
|
+
}
|
|
1222
|
+
if(finalResult?.observationStatus==='completed'&&finalStages.includes(stage)){
|
|
1223
|
+
try{publishFinal(true);if(finalResult.review.verdict==='approved'&&!n5)stage='completion_gate_required';}
|
|
1224
|
+
catch{stage='final_review_evidence_required';}
|
|
1225
|
+
}
|
|
1226
|
+
if(n5&&['post_review_regression_required','post_review_regression_blocked','closeout_required','walkthrough_blocked'].includes(stage)){
|
|
1227
|
+
try{need(digest(checkN5(n5Options()))===digest(n5.gate),'n5_binding_mismatch');}
|
|
1228
|
+
catch{stage='completion_gate_required';}
|
|
1229
|
+
}
|
|
1230
|
+
if(walkthrough&&['closeout_required','walkthrough_blocked'].includes(stage)){
|
|
1231
|
+
try{verifyFixWalkthroughEvidence(walkthrough,evidenceSpecsRoot);}catch{stage='walkthrough_evidence_required';}
|
|
1232
|
+
}
|
|
1233
|
+
if(revision&&['final_review_changes_requested','walkthrough_blocked','post_review_regression_blocked'].includes(stage))stage='revision_prepared';
|
|
1234
|
+
if(stage==='revision_test_author_required'&&!pinned.revision_test_author){
|
|
1235
|
+
try{verifyRevisionStart(captureReviewBaseline({root:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,
|
|
1236
|
+
identity:revision.nextIdentity,scope:revision.tests.testFiles,requirements:configuration.repair.requirements}));}
|
|
1237
|
+
catch{stage='revision_test_evidence_required';}
|
|
1238
|
+
}
|
|
1239
|
+
if(revisionAuthored?.outcome==='authored'&&!['unknown','cancelled'].includes(stage)&&!(pinned.revision_repair&&!revisionBaseline)){
|
|
1240
|
+
try{
|
|
1241
|
+
verifyExtensionFiles(configuration.reproduction.cwd,{plan:revision.tests,files:revisionAuthored.testFiles});
|
|
1242
|
+
if(!revisionBaseline)verifyFixRepair({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,
|
|
1243
|
+
baseline:revisionAuthorBaseline,result:{outcome:'repaired',baselineDigest:revisionAuthored.baselineDigest,changedFiles:revisionAuthored.changedFiles,files:revisionAuthored.testFiles,completionEligible:false}});
|
|
1244
|
+
}catch{stage='revision_test_evidence_required';}
|
|
1245
|
+
}
|
|
1246
|
+
if(revisionRepair&&!revisionLearningPackage&&['revision_regression_required','revision_repair_blocked','revision_handoff_required','revision_regression_blocked','revision_handoff_ready','revision_learning_writeback_required','revision_learning_writeback_blocked',...revisionFinalStages].includes(stage)){
|
|
1247
|
+
try{verifyFixRepair({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,baseline:revisionBaseline,result:revisionRepair,allowUnchanged:Boolean(revision.tests)});}
|
|
1248
|
+
catch{stage='revision_repair_evidence_required';}
|
|
1249
|
+
}
|
|
1250
|
+
if(revisionRetrospective&&!revisionLearningPackage&&['revision_handoff_ready','revision_learning_writeback_required',...revisionFinalStages].includes(stage)){
|
|
1251
|
+
try{need(revisionImplementationPackage(revisionRegression).packageDigest===revisionRetrospective.packageDigest,'retrospective_drift');}
|
|
1252
|
+
catch{stage='revision_retrospective_evidence_required';}
|
|
1253
|
+
}
|
|
1254
|
+
if(revisionLearningPackage&&['revision_handoff_ready',...revisionFinalStages].includes(stage)){
|
|
1255
|
+
try{need(revisionImplementationPackage(revisionRegression).packageDigest===revisionLearningPackage.packageDigest,'writeback_drift');}
|
|
1256
|
+
catch{stage='revision_learning_writeback_evidence_required';}
|
|
1257
|
+
}
|
|
1258
|
+
if(revisionHandoff&&revisionFinalStages.includes(stage)){
|
|
1259
|
+
try{
|
|
1260
|
+
const checked=verifyHostHandoff({root:configuration.reproduction.cwd,baseline:revisionReviewBaseline(),checks:reviewChecks(revisionRegression),
|
|
1261
|
+
handoffPath:revisionHandoffPath(),evidence:store.snapshot().records.find(row=>row.id==='fix-revision-handoff-intent').payload.evidence});
|
|
1262
|
+
need(checked.handoffSha256===revisionHandoff.handoffSha256,'handoff_drift');
|
|
1263
|
+
}catch{stage='revision_handoff_evidence_required';}
|
|
1264
|
+
}
|
|
1265
|
+
if(revisionFinalResult?.observationStatus==='completed'&&revisionFinalStages.includes(stage)){
|
|
1266
|
+
try{publishRevisionFinal(true);if(revisionFinalResult.review.verdict==='approved'&&!revisionN5)stage='revision_completion_gate_required';}
|
|
1267
|
+
catch{stage='revision_final_review_evidence_required';}
|
|
1268
|
+
}
|
|
1269
|
+
if(revisionN5&&['revision_post_review_regression_required','revision_post_review_regression_blocked','revision_closeout_required','revision_walkthrough_blocked'].includes(stage)){
|
|
1270
|
+
try{need(digest(checkN5(revisionN5Options()))===digest(revisionN5.gate),'n5_binding_mismatch');}
|
|
1271
|
+
catch{stage='revision_completion_gate_required';}
|
|
1272
|
+
}
|
|
1273
|
+
if(revisionWalkthrough&&['revision_closeout_required','revision_walkthrough_blocked'].includes(stage)){
|
|
1274
|
+
try{verifyFixWalkthroughEvidence(revisionWalkthrough,evidenceSpecsRoot);}catch{stage='revision_walkthrough_evidence_required';}
|
|
1275
|
+
}
|
|
1189
1276
|
}
|
|
1190
1277
|
if(observationResume&&!['unknown','cancelled'].includes(stage)){
|
|
1191
1278
|
try{verifyObservationResume(observationResume);}catch{stage='observation_resume_evidence_required';}
|
|
@@ -1217,16 +1304,23 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1217
1304
|
// disconnect or cancellation observation. Each kind may be abandoned once.
|
|
1218
1305
|
const noReviewResult=(registration,result,kind)=>stage==='unknown'&®istration!==null
|
|
1219
1306
|
&&(pending===kind&&!result||pending===null&&result!==null&&result.observationStatus!=='completed');
|
|
1220
|
-
const causeNoResult=
|
|
1307
|
+
const causeNoResult=noReviewResult(cause,causeResult,'cause_review');
|
|
1221
1308
|
const revisionNoResult=noReviewResult(revisionFinalRegistration,revisionFinalResult,'revision_final_review');
|
|
1222
1309
|
if(stage==='unknown'&&[...reviewLedger.receipts.values()].some(p=>reviewLedger.applied.has(p.invocationId)&&p.inspection.kind==='cm-provider-review-failure')){stage='review_provider_failed';pending=null;}
|
|
1223
|
-
const reviewAbandonable=!(configuration.externalModels||configuration.executionPolicy)&&causeNoResult&&!
|
|
1310
|
+
const reviewAbandonable=!(configuration.externalModels||configuration.executionPolicy)&&causeNoResult&&!causeAbandonment2?'cause_review':!(configuration.externalModels||configuration.executionPolicy)&&revisionNoResult&&!revisionAbandonment2?'revision_final_review':null;
|
|
1311
|
+
lastPinned=pinned;
|
|
1312
|
+
const rerunKind=RERUNNABLE[stage]&&(revision===null)!==RERUNNABLE[stage].startsWith('revision_')?RERUNNABLE[stage]:null;
|
|
1224
1313
|
const status=json({identity,stage,pending,abandoned,executionActive:active!==null,reproduction,diagnosis:diagnosed,learning,causeReview:causeResult,
|
|
1225
1314
|
...(reviewAbandonable?{reviewAbandonable}:{}),
|
|
1315
|
+
...(Object.keys(pinned).length?{pinnedBaselines:Object.fromEntries(Object.entries(pinned).map(([kind,value])=>[kind,value.baselineDigest]))}:{}),
|
|
1316
|
+
...(Object.keys(blockedReruns).length?{blockedReruns}:{}),
|
|
1317
|
+
...(rerunKind?{blockedRerun:{pending:rerunKind,used:blockedReruns[rerunKind]??0,limit:MAX_FIX_BLOCKED_RERUNS}}:{}),
|
|
1226
1318
|
...((configuration.externalModels||configuration.executionPolicy)&&stage==='unknown'?{reviewReconciliation:{available:reviewLedger.pending.length===1,invocationId:reviewLedger.pending[0]?.invocationId??null}}:{}),
|
|
1227
|
-
...(causeNoResult&&
|
|
1319
|
+
...(causeNoResult&&causeAbandonment2||revisionNoResult&&revisionAbandonment2?{reviewAbandonBudgetExhausted:true}:{}),
|
|
1228
1320
|
...(causeAbandonment?{causeReviewAbandonment:causeAbandonment}:{}),
|
|
1321
|
+
...(causeAbandonment2?{causeReviewAbandonment2:causeAbandonment2}:{}),
|
|
1229
1322
|
...(revisionAbandonment?{revisionFinalReviewAbandonment:revisionAbandonment}:{}),
|
|
1323
|
+
...(revisionAbandonment2?{revisionFinalReviewAbandonment2:revisionAbandonment2}:{}),
|
|
1230
1324
|
...(causeReviewCorrection?{causeReviewCorrection}:{}),...(rediagnosis?{rediagnosis}:{}),
|
|
1231
1325
|
...(observationResume?{observationResume,observationCycle}:{}),
|
|
1232
1326
|
...(observationReproduction?{observationReproduction}:{}),
|
|
@@ -1294,11 +1388,39 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1294
1388
|
&&stepRecord(retryBase(row.id))?.pending===current.pending);
|
|
1295
1389
|
need(intent,'fix_abandon_unavailable');
|
|
1296
1390
|
append(`fix-abandoned-${current.abandoned.length+1}`,'result',
|
|
1297
|
-
{pending:current.pending,reason,abandonedAt:Date.now(),intentDigest:digest(intent)
|
|
1391
|
+
{pending:current.pending,reason,abandonedAt:Date.now(),intentDigest:digest(intent),
|
|
1392
|
+
...(PINNED_STEPS.has(current.pending)?{baselinePinned:true}:{})});
|
|
1298
1393
|
logFixEvent({specsRoot:evidenceSpecsRoot,identity,configuration,event:'abandon',phase:current.pending,
|
|
1299
1394
|
detail:`显式放弃 unknown 步骤:${current.pending}`,data:{pending:current.pending,reason}});
|
|
1300
1395
|
return project();
|
|
1301
1396
|
},
|
|
1397
|
+
// V10: rerun a step whose legitimate verdict was blocked (test author or
|
|
1398
|
+
// repair answered blocked, regression or walkthrough inconclusive/blocked).
|
|
1399
|
+
// The blocked result stays in the journal; a write step keeps its baseline.
|
|
1400
|
+
rerunBlockedStep({reason,authorized=false}={}){
|
|
1401
|
+
need(!closed&&active===null,'fix_busy');need(authorized===true,'fix_blocked_rerun_authorization_required');
|
|
1402
|
+
need(typeof reason==='string'&&reason.trim().length>0&&Buffer.byteLength(reason,'utf8')<=1000
|
|
1403
|
+
&&!/[\r\n\0\u0085\u2028\u2029]/.test(reason),'fix_blocked_rerun_reason_required');
|
|
1404
|
+
const current=project();
|
|
1405
|
+
need(current.blockedRerun,'fix_blocked_rerun_unavailable');
|
|
1406
|
+
need(current.blockedRerun.used<MAX_FIX_BLOCKED_RERUNS,'fix_blocked_rerun_limit');
|
|
1407
|
+
const kind=current.blockedRerun.pending,records=store.snapshot().records;
|
|
1408
|
+
const intent=[...records].reverse().find(row=>row.kind==='intent'&&stepRecord(retryBase(row.id))?.pending===kind);
|
|
1409
|
+
const result=[...records].reverse().find(row=>row.kind==='result'&&stepRecord(retryBase(row.id))?.pending===kind);
|
|
1410
|
+
need(intent&&result,'fix_blocked_rerun_unavailable');
|
|
1411
|
+
const used=records.filter(row=>blockedRerunNumber(row.id)>0).length;
|
|
1412
|
+
const recordId=`fix-blocked-rerun-${used+1}`,payload={stage:current.stage,pending:kind,reason,rerunAt:Date.now(),
|
|
1413
|
+
intentDigest:digest(intent),resultDigest:digest(result),...(PINNED_STEPS.has(kind)?{baselinePinned:true}:{})};
|
|
1414
|
+
// The exact record must replay before it is appended (never a poisoned journal).
|
|
1415
|
+
const snapshot=store.snapshot(),candidate={version:1,seq:snapshot.records.length+1,id:recordId,kind:'result',payload,
|
|
1416
|
+
previousDigest:snapshot.records.at(-1)?.digest??null};
|
|
1417
|
+
try{project({...snapshot,records:[...snapshot.records,{...candidate,digest:digest(candidate)}]});}
|
|
1418
|
+
catch{need(false,'fix_blocked_rerun_unavailable');}
|
|
1419
|
+
append(recordId,'result',payload);
|
|
1420
|
+
logFixEvent({specsRoot:evidenceSpecsRoot,identity,configuration,event:'rerun',phase:kind,
|
|
1421
|
+
detail:`带理由重跑合法阻断的步骤:${kind}`,data:{pending:kind,stage:current.stage,reason}});
|
|
1422
|
+
return project();
|
|
1423
|
+
},
|
|
1302
1424
|
// One audited abandonment per review kind, mirroring cm-ai abandon_review. The
|
|
1303
1425
|
// host confirms the old reviewer process stopped; the record binds the exact
|
|
1304
1426
|
// registration, thread and any no-result observation. The retry needs the
|
|
@@ -1311,10 +1433,14 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1311
1433
|
const current=project();
|
|
1312
1434
|
need(current.reviewAbandonBudgetExhausted!==true,'fix_review_abandon_budget_exhausted');
|
|
1313
1435
|
need(current.reviewAbandonable,'fix_review_abandon_unavailable');
|
|
1314
|
-
const records=store.snapshot().records,
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1436
|
+
const records=store.snapshot().records,base=current.reviewAbandonable==='cause_review'&¤t.rediagnosis
|
|
1437
|
+
?'fix-cause-rediagnosis':REVIEW_ABANDON[current.reviewAbandonable];
|
|
1438
|
+
// V5: the first abandonment ends the round's first cycle; the second ends the retry cycle.
|
|
1439
|
+
const again=Boolean(current.reviewAbandonable==='cause_review'?current.causeReviewAbandonment:current.revisionFinalReviewAbandonment);
|
|
1440
|
+
const prefix=again?`${base}-retry`:base;
|
|
1441
|
+
const registration=records.findLast(row=>row.id===`${prefix}-registered`),result=records.findLast(row=>row.id===`${prefix}-result`)??null;
|
|
1442
|
+
append(`${base}-abandoned${again?'-2':''}`,'result',{invocationId:registration.payload.request.invocationId,registrationDigest:digest(registration.payload),
|
|
1443
|
+
providerThreadId:records.findLast(row=>row.id===`${prefix}-started`)?.payload.providerThreadId??null,
|
|
1318
1444
|
resultDigest:result===null?null:digest(result.payload),reason,abandonedAt:Date.now()});
|
|
1319
1445
|
logFixEvent({specsRoot:evidenceSpecsRoot,identity,configuration,event:'abandon',phase:current.reviewAbandonable,
|
|
1320
1446
|
detail:`显式放弃无结果的审查:${current.reviewAbandonable}`,data:{pending:current.reviewAbandonable,reason}});
|
|
@@ -1326,8 +1452,11 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1326
1452
|
const current=project(),records=store.snapshot().records;
|
|
1327
1453
|
need(identity.attempt===1&¤t.stage==='unknown'&&!current.revision
|
|
1328
1454
|
&&(!current.finalReview||current.finalReview.observationStatus==='unknown'),'fix_review_recovery_unavailable');
|
|
1329
|
-
const prior=finalRecord(records,'registered')?.payload,thread=finalRecord(records,'started')?.payload.providerThreadId;
|
|
1330
|
-
need(prior
|
|
1455
|
+
const prior=finalRecord(records,'registered')?.payload,thread=finalRecord(records,'started')?.payload.providerThreadId??null;
|
|
1456
|
+
need(prior,'fix_review_recovery_unavailable');
|
|
1457
|
+
// V5 (F24): the thread-less recoveries are spent: an explicit limit, not a generic refusal.
|
|
1458
|
+
if(!thread&¤t.finalReviewRecoveryCount>=MAX_FIX_REVIEW_ABANDONS)throw Object.assign(new Error('fix_review_recovery_limit'),
|
|
1459
|
+
{code:'fix_review_recovery_limit',reason:FIX_REVIEW_RECOVERY_LIMIT_REASON});
|
|
1331
1460
|
if(current.finalReviewRecoveryCount>0||recoveryInvocationId!==null)
|
|
1332
1461
|
need(recoveryInvocationId===prior.request.invocationId,'fix_review_recovery_authorization_required');
|
|
1333
1462
|
need(invocationId===prior.request.invocationId&&packageDigest===prior.request.payload.reviewPackage.packageDigest
|
|
@@ -1551,7 +1680,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1551
1680
|
async reviewFinal(){
|
|
1552
1681
|
need(!closed&&active===null,'fix_busy');const start=project();if(!['final_review_required','revision_final_review_required'].includes(start.stage))return start;
|
|
1553
1682
|
const revising=start.stage==='revision_final_review_required';
|
|
1554
|
-
const prefix=revising?(start.revisionFinalReviewAbandonment?'fix-revision-final-retry':'fix-revision-final'):recoveryPrefix(start.finalReviewRecoveryCount);
|
|
1683
|
+
const prefix=revising?(start.revisionFinalReviewAbandonment2?'fix-revision-final-retry-2':start.revisionFinalReviewAbandonment?'fix-revision-final-retry':'fix-revision-final'):recoveryPrefix(start.finalReviewRecoveryCount);
|
|
1555
1684
|
need(finalReview&&typeof assertReviewReady==='function','final_review_unavailable');
|
|
1556
1685
|
const ready=assertReviewReady();if(types.isPromise(ready))Promise.prototype.then.call(ready,()=>{},()=>{});
|
|
1557
1686
|
need(ready===undefined,'final_sync_registration_required');
|
|
@@ -1572,7 +1701,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1572
1701
|
joinLiveHost();append(`${prefix}-registered`,'intent',value);registered=true;
|
|
1573
1702
|
},onStarted(providerThreadId){
|
|
1574
1703
|
need(providerThreadId!==start.finalReviewRecovery?.providerThreadId
|
|
1575
|
-
|
|
1704
|
+
&&!(revising&&[start.revisionFinalReviewAbandonment?.providerThreadId,start.revisionFinalReviewAbandonment2?.providerThreadId].filter(Boolean).includes(providerThreadId)),'final_context_mismatch');
|
|
1576
1705
|
if(!revising)need(!store.snapshot().records.some(row=>finalCycleRecord(row,'started')
|
|
1577
1706
|
&&row.payload.providerThreadId===providerThreadId),'final_context_mismatch');
|
|
1578
1707
|
append(`${prefix}-started`,'result',{providerThreadId});
|
|
@@ -1738,7 +1867,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1738
1867
|
const repair=prepareFixRepair({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,identity:executionIdentity,
|
|
1739
1868
|
...configuration.repair,defect:configuration.defect,diagnosis:start.diagnosis,
|
|
1740
1869
|
...(revising?{reviewFeedback:revisionFeedback(),...(testExtension()?{testExtension:testExtension()}:{})}:{}),
|
|
1741
|
-
redTest:configuration.redTest,baseline:configuration.baseline,redEvidence:start.redTest,beforeBaseline:start.baseline},{bridge,assertReviewReady
|
|
1870
|
+
redTest:configuration.redTest,baseline:configuration.baseline,redEvidence:start.redTest,beforeBaseline:start.baseline},{bridge,assertReviewReady,
|
|
1871
|
+
pinnedBaseline:lastPinned[revising?'revision_repair':'repair']??null,protectedMode:protectedSpecsRoot!==null});
|
|
1742
1872
|
const result=await repair.execute({authorized:true,signal:controller.signal,register(baseline){
|
|
1743
1873
|
append(`${prefix}-intent`,'intent',{baseline,redDigest:digest(start.redTest),testBaselineDigest:digest(start.baseline),...(revising?{revisionDigest:digest(start.revision)}:{})});registered=true;
|
|
1744
1874
|
}});
|
|
@@ -1746,6 +1876,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1746
1876
|
inspectFixRepair(result,repair.baseline,{allowUnchanged:revising&&Boolean(start.revision.tests)});append(`${prefix}-result`,'result',result);return project();
|
|
1747
1877
|
}catch(error){
|
|
1748
1878
|
if(preparing&&timedOut)need(false,'fix_learning_interrupted');
|
|
1879
|
+
// A pinned redo names the residue paths the operator must restore first.
|
|
1880
|
+
if(!registered&&!controller.signal.aborted&&['fix_pinned_residue','fix_protected_residue','fix_pinned_baseline_mismatch'].includes(error?.code))throw error;
|
|
1749
1881
|
if(!registered&&!controller.signal.aborted)need(false,error?.code==='fix_learning_context_changed'?'fix_learning_context_changed':'repair_preparation_failed');
|
|
1750
1882
|
return project();
|
|
1751
1883
|
}finally{clearTimeout(timer);active=null;}
|
|
@@ -1781,7 +1913,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1781
1913
|
need(project().stage===start.stage,'fix_evidence_changed');
|
|
1782
1914
|
const author=prepareFixTestAuthor({codeProject:configuration.reproduction.cwd,specsRoot:evidenceSpecsRoot,identity:executionIdentity,
|
|
1783
1915
|
testFiles:revising?start.revision.tests.testFiles:configuration.redTest.testFiles,requirements:revising?configuration.repair.requirements:configuration.testAuthor.requirements,
|
|
1784
|
-
defect:configuration.defect,diagnosis:start.diagnosis,reproduction:start.reproduction,...(revising?{reviewFeedback:inspectFixRepairReview(revisionFeedback(),executionIdentity),testPlan:start.revision.tests}:{})},{bridge,assertReviewReady
|
|
1916
|
+
defect:configuration.defect,diagnosis:start.diagnosis,reproduction:start.reproduction,...(revising?{reviewFeedback:inspectFixRepairReview(revisionFeedback(),executionIdentity),testPlan:start.revision.tests}:{})},{bridge,assertReviewReady,
|
|
1917
|
+
pinnedBaseline:lastPinned[revising?'revision_test_author':'test_author']??null,protectedMode:protectedSpecsRoot!==null});
|
|
1785
1918
|
const result=await author.execute({authorized:true,signal:controller.signal,register(baseline){
|
|
1786
1919
|
append(`${prefix}-intent`,'intent',revising?{baseline,revisionDigest:digest(start.revision)}:baseline);registered=true;
|
|
1787
1920
|
}});
|
|
@@ -1789,6 +1922,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1789
1922
|
inspectFixTestAuthor(result,author.baseline);append(`${prefix}-result`,'result',result);return project();
|
|
1790
1923
|
}catch(error){
|
|
1791
1924
|
if(preparing&&timedOut)need(false,'fix_learning_interrupted');
|
|
1925
|
+
// A pinned redo names the residue paths the operator must restore first.
|
|
1926
|
+
if(!registered&&!controller.signal.aborted&&['fix_pinned_residue','fix_protected_residue','fix_pinned_baseline_mismatch'].includes(error?.code))throw error;
|
|
1792
1927
|
if(!registered&&!controller.signal.aborted)need(false,error?.code==='fix_learning_context_changed'
|
|
1793
1928
|
?'fix_learning_context_changed':'test_author_preparation_failed');
|
|
1794
1929
|
return project();
|
|
@@ -1864,8 +1999,8 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1864
1999
|
need(configuration.causeReview&&causeReview&&typeof causeReview.authorize==='function'&&typeof causeReview.run==='function','cause_review_unavailable');
|
|
1865
2000
|
const reviewer=configuration.causeReview;
|
|
1866
2001
|
const budget=reviewTimeout(causeReview,configuration.reproduction.timeoutMs);
|
|
1867
|
-
const prefix
|
|
1868
|
-
const
|
|
2002
|
+
const prefix=`${status.rediagnosis?'fix-cause-rediagnosis':'fix-cause'}${status.causeReviewAbandonment2?'-retry-2':status.causeReviewAbandonment?'-retry':''}`;
|
|
2003
|
+
const abandonedThreads=[status.causeReviewAbandonment?.providerThreadId,status.causeReviewAbandonment2?.providerThreadId].filter(Boolean);
|
|
1869
2004
|
const pkg=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,status});
|
|
1870
2005
|
const request=requestFor({invocationId:`fix-cause.${randomUUID()}`,identity,role:'reviewer',provider:reviewer.provider,
|
|
1871
2006
|
requestedModel:reviewer.requestedModel,contextId:reviewer.contextId,payload:{reviewPackage:pkg,priorReview:null}});
|
|
@@ -1889,7 +2024,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1889
2024
|
JSON.stringify(causeExpectation(request,reviewConfiguration)));
|
|
1890
2025
|
if(event.event==='thread.started'){
|
|
1891
2026
|
// A retry is a fresh reviewer thread, never the abandoned one.
|
|
1892
|
-
need(event.provider_thread
|
|
2027
|
+
need(!abandonedThreads.includes(event.provider_thread)&&event.provider_thread!==status.rediagnosis?.priorProviderThreadId,'observation_context');
|
|
1893
2028
|
append(`${prefix}-started`,'result',{providerThreadId:event.provider_thread});started=event.provider_thread;
|
|
1894
2029
|
}
|
|
1895
2030
|
events.push(event);return true;
|
|
@@ -1911,8 +2046,17 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1911
2046
|
// The review budget expiring is a recorded no-result observation, not an
|
|
1912
2047
|
// unrecorded interruption; a cancellation or invalid stream stays unknown.
|
|
1913
2048
|
if(invalid||controller.signal.aborted&&!timedOut||project().stage==='cancelled')return project();
|
|
1914
|
-
|
|
1915
|
-
inspectCauseResult(value,registration,reviewConfiguration,started);
|
|
2049
|
+
let value={dispatchAt,observation:observation(timedOut?{status:'failed',code:'timeout'}:result)};
|
|
2050
|
+
try{inspectCauseResult(value,registration,reviewConfiguration,started);}
|
|
2051
|
+
catch(error){
|
|
2052
|
+
// A reviewer that finished but whose answer breaks the verdict contract
|
|
2053
|
+
// (e.g. invalid_finding_path, missing_material) is a recorded failed
|
|
2054
|
+
// observation with that code, never a silently dropped result. The same
|
|
2055
|
+
// events must still bind; otherwise it stays unrecorded as before.
|
|
2056
|
+
if(timedOut||result?.status!=='succeeded'||configuration.externalModels||configuration.executionPolicy)throw error;
|
|
2057
|
+
value={dispatchAt,observation:observation({status:'failed',code:typeof error?.code==='string'&&/^[a-z_]{1,64}$/.test(error.code)?error.code:'observation_invalid'})};
|
|
2058
|
+
inspectCauseResult(value,registration,reviewConfiguration,started);
|
|
2059
|
+
}
|
|
1916
2060
|
append(`${prefix}-result`,'result',value);
|
|
1917
2061
|
if(!receiptConflict)saveReviewReceipt(prefix,capturedReceipt);
|
|
1918
2062
|
if(project().causeReview?.observationStatus==='completed')publishCause();
|
|
@@ -1925,14 +2069,29 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1925
2069
|
},
|
|
1926
2070
|
async rediagnose({authorized=false,reason}={}){
|
|
1927
2071
|
need(!closed&&active===null,'fix_busy');need(authorized===true,'fix_rediagnosis_authorization_required');
|
|
1928
|
-
const start=project();
|
|
2072
|
+
const start=project();
|
|
2073
|
+
// The one continuation is the intent. It binds the request (prior review,
|
|
2074
|
+
// its feedback, Learning), never an answer, so an intent left without a
|
|
2075
|
+
// result (rejected answer or lost reply) is answered again under itself.
|
|
2076
|
+
const reasking=start.stage==='unknown'&&start.pending==='rediagnosis'&&Boolean(start.rediagnosis);
|
|
2077
|
+
need(reasking||start.stage==='rediagnosis_required'&&!start.rediagnosis,'fix_rediagnosis_unavailable');
|
|
1929
2078
|
text(reason);need(Buffer.byteLength(reason,'utf8')<=1000&&!/[\r\n\0\u0085\u2028\u2029]/.test(reason),'fix_rediagnosis_reason_invalid');
|
|
1930
|
-
need(bridge!==null,'fix_rediagnosis_unavailable');
|
|
1931
|
-
const
|
|
2079
|
+
need(bridge!==null,'fix_rediagnosis_unavailable');
|
|
2080
|
+
const records=store.snapshot().records,marker=records.findIndex(row=>row.id==='fix-rediagnosis-intent');
|
|
2081
|
+
const before=marker<0?records:records.slice(0,marker);
|
|
2082
|
+
const prior=reviewCycleRecord(before,'fix-cause','registered').payload;
|
|
2083
|
+
if(reasking){
|
|
2084
|
+
need(digest(prior)===start.rediagnosis.priorRegistrationDigest,'fix_rediagnosis_unavailable');
|
|
2085
|
+
publishCauseEvidence({specsRoot:evidenceSpecsRoot,configuration:reviewConfiguration,inspectOnly:true,round:1,registration:prior,
|
|
2086
|
+
started:reviewCycleRecord(before,'fix-cause','started')?.payload.providerThreadId??null,
|
|
2087
|
+
result:reviewCycleRecord(before,'fix-cause','result')?.payload});
|
|
2088
|
+
}else publishCause(true);
|
|
2089
|
+
const priorPackage=prior.request.payload.reviewPackage;
|
|
1932
2090
|
const assertBasis=()=>{
|
|
1933
2091
|
const pkg=createFixCausePackage({codeProject:configuration.reproduction.cwd,defect:configuration.defect,
|
|
1934
|
-
status:{...start,stage:'cause_review_required'}
|
|
1935
|
-
|
|
2092
|
+
status:reasking?{...start,stage:'cause_review_required',rediagnosis:null,learning:priorPackage.learning}
|
|
2093
|
+
:{...start,stage:'cause_review_required'}});
|
|
2094
|
+
need(pkg.packageDigest===priorPackage.packageDigest,'fix_rediagnosis_source_changed');
|
|
1936
2095
|
const slug=identity.taskId.slice(6);
|
|
1937
2096
|
const slot=path.join(evidenceSpecsRoot,'.reviews',`fix-${slug}-cause-r2.md`);
|
|
1938
2097
|
let occupied=false;
|
|
@@ -1941,27 +2100,34 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1941
2100
|
return pkg;
|
|
1942
2101
|
};
|
|
1943
2102
|
const pkg=assertBasis();
|
|
1944
|
-
const
|
|
2103
|
+
const reviewFeedback=reasking?start.rediagnosis.reviewFeedback:start.causeReview.review;
|
|
2104
|
+
const controller=new AbortController();active=controller;let registered=reasking,timer;
|
|
1945
2105
|
try{
|
|
1946
2106
|
timer=setTimeout(()=>controller.abort(),configuration.reproduction.timeoutMs);
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
2107
|
+
if(!reasking){
|
|
2108
|
+
const learning=prepare===null?start.learning:inspectFixLearning(await prepare({identity,defect:configuration.defect},controller.signal));
|
|
2109
|
+
need(!controller.signal.aborted,'fix_learning_interrupted');
|
|
2110
|
+
need(project().stage===start.stage,'fix_evidence_changed');
|
|
2111
|
+
// Preparation awaits current-session work; recheck its original evidence before the single continuation is registered.
|
|
2112
|
+
assertBasis();
|
|
2113
|
+
const history=store.snapshot().records;
|
|
2114
|
+
append('fix-rediagnosis-intent','intent',{reason,historyDigest:digest(history),priorRegistrationDigest:digest(prior),
|
|
2115
|
+
priorObservationDigest:start.causeReview.observationDigest,priorPackageDigest:pkg.packageDigest,
|
|
2116
|
+
priorProviderThreadId:start.causeReview.providerThreadId,
|
|
2117
|
+
reviewFeedback,learning});registered=true;
|
|
2118
|
+
}
|
|
2119
|
+
const value=fixDiagnosisAnswer(await bridge.call('fix_diagnose',{identity,defect:configuration.defect,
|
|
1958
2120
|
codeProject:configuration.reproduction.cwd,reproduction:start.reproduction,previousDiagnosis:start.diagnosis,
|
|
1959
|
-
reviewFeedback
|
|
2121
|
+
reviewFeedback,diagnosticRecord:fixInvestigationRequest,
|
|
1960
2122
|
...fixQaDiagnosisEvidence({specsRoot,identity,configuration})},controller.signal));
|
|
1961
2123
|
if(controller.signal.aborted)return project();
|
|
1962
2124
|
if(configuration.qaSource)inspectFixQaSource({specsRoot,identity,configuration});
|
|
1963
2125
|
append('fix-rediagnosis-result','result',value);return project();
|
|
1964
|
-
}catch(error){
|
|
2126
|
+
}catch(error){
|
|
2127
|
+
// A rejected answer is reported, not hidden as an interruption; rediagnosis stays pending.
|
|
2128
|
+
if(!registered||isInvalidFixDiagnosis(error))throw error;
|
|
2129
|
+
return project();
|
|
2130
|
+
}
|
|
1965
2131
|
finally{clearTimeout(timer);active=null;}
|
|
1966
2132
|
},
|
|
1967
2133
|
async advance({authorized=false}={}){
|
|
@@ -1997,7 +2163,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
1997
2163
|
let value;
|
|
1998
2164
|
if(diagnosing){
|
|
1999
2165
|
timer=setTimeout(()=>controller.abort(),configuration.reproduction.timeoutMs);
|
|
2000
|
-
value=
|
|
2166
|
+
value=fixDiagnosisAnswer(await Promise.race([interrupted,Promise.resolve().then(()=>bridge.call('fix_diagnose',{
|
|
2001
2167
|
identity,defect:configuration.defect,codeProject:configuration.reproduction.cwd,
|
|
2002
2168
|
reproduction:current.observationReproduction,diagnosticRecord:fixInvestigationRequest,
|
|
2003
2169
|
...fixQaDiagnosisEvidence({specsRoot,identity,configuration}),
|
|
@@ -2009,7 +2175,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
2009
2175
|
append(`${prefix}-result`,'result',value);current=project();
|
|
2010
2176
|
}
|
|
2011
2177
|
return current;
|
|
2012
|
-
}catch(error){if(!registered)throw error;return project();}
|
|
2178
|
+
}catch(error){if(!registered||isInvalidFixDiagnosis(error))throw error;return project();}
|
|
2013
2179
|
finally{clearTimeout(timer);controller.signal.removeEventListener('abort',rejectAbort);active=null;}
|
|
2014
2180
|
}
|
|
2015
2181
|
if(!['reproduce','diagnose'].includes(start.stage))return start;
|
|
@@ -2040,7 +2206,7 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
2040
2206
|
?createFixReproduction(configuration.reproduction,{specsRoot:protectedSpecsRoot}):reproduce)({identity},{signal:controller.signal,authorized:true});
|
|
2041
2207
|
else{
|
|
2042
2208
|
timer=setTimeout(()=>controller.abort(),configuration.reproduction.timeoutMs);
|
|
2043
|
-
value=
|
|
2209
|
+
value=fixDiagnosisAnswer(await bridge.call('fix_diagnose',{identity,defect:configuration.defect,
|
|
2044
2210
|
...fixQaDiagnosisEvidence({specsRoot,identity,configuration}),
|
|
2045
2211
|
codeProject:configuration.reproduction.cwd,reproduction:current.reproduction,diagnosticRecord:fixInvestigationRequest},controller.signal));
|
|
2046
2212
|
}
|
|
@@ -2057,6 +2223,9 @@ export function openFixExecution(options,{bridge=null,prepare=null,causeReview=n
|
|
|
2057
2223
|
'fix_learning_interrupted','cancelled','host_disconnected'].includes(error?.code)?error.code:'fix_preparation_failed';
|
|
2058
2224
|
need(false,code);
|
|
2059
2225
|
}
|
|
2226
|
+
// A rejected answer is reported as such; the intent stays without a result
|
|
2227
|
+
// (abandon_step remains the recovery). Transport loss stays unknown and is never redispatched.
|
|
2228
|
+
if(isInvalidFixDiagnosis(error))throw error;
|
|
2060
2229
|
// Intent without a valid result is unknown, including transport loss; never redispatch it.
|
|
2061
2230
|
return project();
|
|
2062
2231
|
}finally{active=null;}
|