Skip to content

Commit e103386

Browse files
committed
fix: retain accepted plan across implementation handoffs
1 parent 4f8872f commit e103386

3 files changed

Lines changed: 112 additions & 5 deletions

File tree

‎examples/adversarial-implementation/components/Ticket/Advance.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ returns: {type: object}
1616
A decision or contract conflict holds the ticket for its existing approval gate.
1717
A correction clears prior verdicts. Readiness requires every selected reviewer to
1818
PASS the same signed implementation SHA; it does not authorize delivery or merge.
19+
Selected feedback documents remain available across reviews and corrections.
1920

2021
<Let as="state" value={props.pending.checkpoint} />
2122
<Let as="result" value={props.result} />
@@ -48,6 +49,6 @@ PASS the same signed implementation SHA; it does not authorize delivery or merge
4849
<Let as="gate" value={held || result.outcome === "escalate" ? state.gate : correction ? "implementation" : ready ? "feedback-ready" : remaining[0] + "-review"} />
4950
<Let as="status" value={held ? "hold" : ready ? "feedback_ready" : props.pending.execution.status === "failed" ? "paused" : "running"} />
5051
<Let as="assignment" value={{...props.pending.manifest.assignment,phase:gate === "implementation" ? "implementation" : "review",assessment:reviewPolicy.assessment,reviewKind:reviewPolicy.kind,revision,priorRevision:props.pending.manifest.assignment.revision,request:result.handoff,handoffInputs:result.handoffInputs ?? [],changedPaths:props.observation.changedPaths,artifacts:[...result.artifacts,props.observation.path],evidence:result.evidence,findings:result.findings,contract:result.contract ?? state.assignment.contract ?? null}} />
51-
<Return value={{...state,status,dispatchable:!held && !ready && props.pending.execution.status !== "failed",round,gate,revision,reviews,reviewPolicy,exactApproval,exactReview,assignment,feedbackInputs:result.outcome === "complete" && call.role === "implementor" ? result.handoffInputs ?? state.assignment.handoffInputs ?? [] : state.feedbackInputs ?? [],discovery:[...(state.discovery ?? []),...((result.discoveryRequests?.length ?? 0) + (result.discoveryGaps?.length ?? 0) > 0 ? [{role:call.role,revision:result.revision,result:props.pending.resultPath,requests:result.discoveryRequests ?? [],gaps:result.discoveryGaps ?? []}] : [])],feedback:result.outcome === "complete" && call.role === "implementor" ? [props.pending.resultPath,props.observation.path] : state.feedback,hold:held ? {kind:correction ? "correction_bound" : result.outcome,reason:result.handoff} : null}} />
52+
<Return value={{...state,status,dispatchable:!held && !ready && props.pending.execution.status !== "failed",round,gate,revision,reviews,reviewPolicy,exactApproval,exactReview,assignment,feedbackInputs:result.outcome === "complete" && call.role === "implementor" ? [...new Set([...(state.feedbackInputs ?? []),...(state.assignment.handoffInputs ?? []),...(result.handoffInputs ?? [])])] : state.feedbackInputs ?? [],discovery:[...(state.discovery ?? []),...((result.discoveryRequests?.length ?? 0) + (result.discoveryGaps?.length ?? 0) > 0 ? [{role:call.role,revision:result.revision,result:props.pending.resultPath,requests:result.discoveryRequests ?? [],gaps:result.discoveryGaps ?? []}] : [])],feedback:result.outcome === "complete" && call.role === "implementor" ? [props.pending.resultPath,props.observation.path] : state.feedback,hold:held ? {kind:correction ? "correction_bound" : result.outcome,reason:result.handoff} : null}} />
5253

5354
</If>

‎examples/adversarial-implementation/tests/Friction.test.md‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,89 @@ git rev-parse HEAD
369369
<AssertEquals actual={continued.calls.every(call => call.sourceValue.clean && call.sourceValue.head === manifest.assignment.revision)} expected={true} />
370370
</TempDir>
371371
</Test>
372+
373+
<Test name="accepted plan survives distinct implementation handoffs and retained correction" timeout="90s">
374+
<TempDir>
375+
<Fixture.Repository as="fixture" />
376+
<Dir path={fixture.repository}>
377+
<File path="api.sh">format() { printf '%s' "$1"; }
378+
</File>
379+
```bash exec as="base"
380+
git add api.sh
381+
git commit -qm 'existing API'
382+
git rev-parse HEAD
383+
```
384+
<If condition={base.exitCode !== 0}><Fail message={base.stderr} /></If>
385+
</Dir>
386+
<Let as="reference" value={fixture.root + "/accepted.md"} />
387+
<Dir path={fixture.root}><File path="accepted.md">Accepted plan retention contract.</File></Dir>
388+
<Let as="impact" value={{...assessment,architecture:true,evidence:[reference]}} />
389+
<Let as="manifest" value={{schema:"ticket-workflow.v2",work:"handoff",directory:fixture.directory,maxCorrections:3,maxApiRepairs:3,maxResponseCorrections:0,roles:{architect:{session:"original-architect",provider:"codex",initialized:false},planner:{session:"original-planner",provider:"codex",initialized:false},implementor:{session:"original-implementor",provider:"codex",initialized:false}},acceptedInputs:[{path:reference,content:"Accepted plan retention contract."}],assignment:{phase:"discovery",work:"handoff",repository:fixture.repository,revision:base.stdout.trim(),priorRevision:null,request:"handoff-retention",assessment:impact,changedPaths:[],artifacts:[],evidence:[],findings:[],recipient:"planner",continuation:{phase:"implementation",role:"implementor"}}}} />
390+
<Fixture.Entry entry="planning-case" value={manifest} repository={fixture.repository} command={runner} root={root} as="child" />
391+
<If condition={child.exitCode !== 0}><Fail message={child.stderr || child.stdout} /></If>
392+
<Parse schema={{type:"object"}} as="planned">{child.stdout}</Parse>
393+
<AssertEquals actual={planned.calls[0].status} expected="accepted" />
394+
<Let as="planPath" value={planned.calls[0].resultValue.handoffInputs[0]} />
395+
<Let as="plan" value={planned.documents[planPath]} />
396+
<AssertEquals actual={plan.content} expected="Use the existing format API for the remaining consumer. Remove legacy.fixture, run bash consumer.sh, and return its signed feedback commit." />
397+
<Fixture.Entry entry="continue" value={planned} repository={fixture.repository} steps={3} command={runner} root={root} as="child" />
398+
<If condition={child.exitCode !== 0}><Fail message={child.stderr || child.stdout} /></If>
399+
<Parse schema={{type:"object"}} as="correcting">{child.stdout}</Parse>
400+
<AssertEquals actual={correcting.calls.slice(0,1)} expected={planned.calls} />
401+
<If condition={correcting.calls.length !== 4 || correcting.calls.some(call => call.resultValue === undefined)}><Fail message={JSON.stringify(correcting)} /></If>
402+
<AssertEquals actual={correcting.calls.map(call => [call.role,call.resultValue?.outcome])} expected={[["planner","complete"],["implementor","complete"],["architect","pass"],["planner","changes_required"]]} />
403+
<Let as="implementationPath" value={correcting.calls[1].resultValue.handoffInputs[0]} />
404+
<Let as="implementation" value={correcting.documents[implementationPath]} />
405+
<AssertEquals actual={implementation.content} expected="Initial implementation evidence: bash consumer.sh passed." />
406+
<AssertEquals actual={correcting.calls[1].resultValue.handoffInputs} expected={[implementationPath]} />
407+
<AssertEquals actual={implementationPath === planPath} expected={false} />
408+
<Each in={correcting.calls.slice(2)} let="review">
409+
<Ticket.Text path={review.attempt + "/called.json"} as="text" />
410+
<Parse schema={{type:"object"}} as="invoked">{text}</Parse>
411+
<AssertEquals actual={invoked.inputs} expected={review.inputs} />
412+
<AssertEquals actual={invoked.inputs.filter(input => input.path === planPath)} expected={[plan]} />
413+
<AssertEquals actual={invoked.inputs.filter(input => input.path === implementationPath)} expected={[implementation]} />
414+
</Each>
415+
<AssertEquals actual={{status:correcting.status,gate:correcting.gate,round:correcting.round,dispatchable:correcting.dispatchable,hold:correcting.hold}} expected={{status:"paused",gate:"implementation",round:3,dispatchable:true,hold:null}} />
416+
<Let as="correctionPath" value={correcting.calls[3].resultValue.handoffInputs[0]} />
417+
<AssertEquals actual={correcting.assignment.handoffInputs} expected={[correctionPath]} />
418+
<Let as="quotedPlan" value={"'" + planPath.replaceAll("'","'\"'\"'") + "'"} />
419+
```bash exec as="mutated"
420+
printf '%s' 'Mutable plan file changed after capture.' > {quotedPlan}
421+
```
422+
<If condition={mutated.exitCode !== 0}><Fail message={mutated.stderr} /></If>
423+
<Fixture.Entry entry="continue" value={correcting} repository={fixture.repository} steps={1} command={runner} root={root} as="child" />
424+
<If condition={child.exitCode !== 0}><Fail message={child.stderr || child.stdout} /></If>
425+
<Parse schema={{type:"object"}} as="corrected">{child.stdout}</Parse>
426+
<AssertEquals actual={corrected.calls.slice(0,4)} expected={correcting.calls} />
427+
<Let as="correctedPath" value={corrected.calls[4].resultValue.handoffInputs[0]} />
428+
<AssertEquals actual={corrected.calls[4].resultValue.handoffInputs} expected={[correctedPath,correctionPath]} />
429+
<AssertEquals actual={corrected.documents[correctedPath].content} expected="Corrected implementation evidence: bash consumer.sh passed." />
430+
<AssertEquals actual={corrected.feedbackInputs} expected={[planPath,implementationPath,correctionPath,correctedPath]} />
431+
<Fixture.Entry entry="continue" value={corrected} repository={fixture.repository} steps={2} command={runner} root={root} as="child" />
432+
<If condition={child.exitCode !== 0}><Fail message={child.stderr || child.stdout} /></If>
433+
<Parse schema={{type:"object"}} as="finished">{child.stdout}</Parse>
434+
<AssertEquals actual={finished.calls.slice(0,5)} expected={corrected.calls} />
435+
<AssertEquals actual={finished.status} expected="feedback_ready" />
436+
<AssertEquals actual={finished.round} expected={3} />
437+
<AssertEquals actual={finished.manifest} expected={manifest} />
438+
<AssertEquals actual={finished.calls.map(call => call.initialize)} expected={[true,true,true,false,false,false,false]} />
439+
<AssertEquals actual={finished.calls.map(call => call.session)} expected={["original-planner","original-implementor","original-architect","original-planner","original-implementor","original-architect","original-planner"]} />
440+
<AssertEquals actual={finished.reviews} expected={{architect:finished.revision,planner:finished.revision}} />
441+
<AssertEquals actual={finished.documents[planPath]} expected={plan} />
442+
<Each in={["architect","planner"]} let="role">
443+
<Let as="received" value={finished.calls.filter(call => call.role === role).flatMap(call => call.inputs)} />
444+
<AssertEquals actual={received.filter(input => input.path === planPath)} expected={[plan]} />
445+
<AssertEquals actual={received.filter(input => input.path === implementationPath)} expected={[implementation]} />
446+
<AssertEquals actual={received.filter(input => input.path === correctedPath)} expected={[finished.documents[correctedPath]]} />
447+
</Each>
448+
<Each in={finished.calls.slice(5)} let="review">
449+
<Ticket.Text path={review.attempt + "/called.json"} as="text" />
450+
<Parse schema={{type:"object"}} as="invoked">{text}</Parse>
451+
<AssertEquals actual={invoked.inputs} expected={review.inputs} />
452+
<AssertEquals actual={review.assignment.handoffInputs.includes(planPath)} expected={true} />
453+
<AssertEquals actual={new Set(review.assignment.handoffInputs).size} expected={review.assignment.handoffInputs.length} />
454+
<AssertEquals actual={invoked.inputs.filter(input => input.path === planPath)} expected={[]} />
455+
</Each>
456+
</TempDir>
457+
</Test>

‎examples/adversarial-implementation/tests/components/Phase/Role.md‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ props:
1414
---
1515

1616
<Let as="assignment" value={props.assignment} />
17+
<Let as="handoffCase" value={assignment.request.startsWith("handoff-retention")} />
1718
<If condition={props.correction !== null}>
1819
<Dir path={props.assignment.artifactDirectory + "/response-corrections/" + String(props.correction.ordinal).padStart(4,"0")}><File path="called.json"><Json value={{session:props.session,plannerProvider:props.plannerProvider,implementationProvider:props.implementationProvider,initialize:props.initialize,ordinal:props.correction.ordinal,remaining:props.correction.remaining}} /></File></Dir>
1920
<Phase.Extract text={props.correction.rejectedText} as="original" />
@@ -53,7 +54,7 @@ git rev-parse HEAD^
5354
<Let as="request" value={{key:"ordinary-contract",role:scenario === "wrong-request" ? "architect" : props.role,question:"Which existing owner retains initial planning?",neededFor:"Prepare the ordinary plan.",evidenceNeeded:"The accepted Ticket boundary.",origin:assignment.artifactDirectory}} />
5455
<Let as="gap" value={{request:{...request,role:scenario === "wrong-gap" ? "architect" : props.role},searched:[planPath],status:"resolved",evidence:[planPath],toolCalls:null,elapsedMs:null}} />
5556
<Let as="contract" value={{work:assignment.work,sourceRevision:revision,scope:"Retain original sessions and exact source.",sections:[]}} />
56-
<Json value={{schema:"phase-result.v2",phase:assignment.phase,work:assignment.work,outcome,revision,summary:assignment.request.includes("oversized-summary") ? "x".repeat(1201) : "The ordinary plan and focused evidence are saved.",handoff:decision ? "ROOT: resolve the newly discovered material choice." : ordinary ? "#1084:" + scenario + " Implement the selected plan using the accepted format API; retire legacy.fixture." : "Implement the selected ordinary plan using the accepted format API; retire legacy.fixture.",handoffInputs:[...new Set([planPath,...(ordinary ? assignment.handoffInputs ?? [] : [])])],artifacts:[planPath],evidence:[],findings:[],assessment:assignment.assessment,discoveryRequests:discovery ? [request] : [],discoveryGaps:discovery ? [gap] : [],...(props.role === "architect" ? {contract} : {}),...(blocked ? {blocker:{kind:"permission",reason:"Source permission is unavailable.",unblockCondition:"Restore the existing source permission.",evidence:[planPath]}} : {}),next:decision || blocked ? {phase:"hold",role:null} : discovery ? {phase:"discovery",role:"architect"} : assignment.continuation}} />
57+
<Json value={{schema:"phase-result.v2",phase:assignment.phase,work:assignment.work,outcome,revision,summary:assignment.request.includes("oversized-summary") ? "x".repeat(1201) : "The ordinary plan and focused evidence are saved.",handoff:handoffCase ? "handoff-retention implement" : decision ? "ROOT: resolve the newly discovered material choice." : ordinary ? "#1084:" + scenario + " Implement the selected plan using the accepted format API; retire legacy.fixture." : "Implement the selected ordinary plan using the accepted format API; retire legacy.fixture.",handoffInputs:[...new Set([planPath,...(ordinary ? assignment.handoffInputs ?? [] : [])])],artifacts:[planPath],evidence:[],findings:[],assessment:assignment.assessment,discoveryRequests:discovery ? [request] : [],discoveryGaps:discovery ? [gap] : [],...(props.role === "architect" ? {contract} : {}),...(blocked ? {blocker:{kind:"permission",reason:"Source permission is unavailable.",unblockCondition:"Restore the existing source permission.",evidence:[planPath]}} : {}),next:decision || blocked ? {phase:"hold",role:null} : discovery ? {phase:"discovery",role:"architect"} : assignment.continuation}} />
5758
<Else>
5859
<If condition={props.role === "implementor"}>
5960
<If condition={conflict}>
@@ -66,14 +67,20 @@ resize narrow
6667
<File path="consumer.sh">. ./api.sh
6768
test "$(format consumer)" = consumer
6869
</File>
70+
<If condition={handoffCase && assignment.request === "handoff-retention correct"}>
71+
<File path="consumer.sh">. ./api.sh
72+
test "$(format consumer)" = consumer
73+
printf '%s' ''
74+
</File>
75+
</If>
6976
```bash exec as="check"
7077
bash consumer.sh
7178
```
7279
<If condition={check.exitCode !== 0}><Fail message={check.stderr} /></If>
7380
<If condition={assignment.request === "change-api"}><File path="api.sh">format() { printf '%s' "$1"; }
7481
unvalidated() { printf '%s' changed; }
7582
</File></If>
76-
<If condition={assignment.request !== "keep-fixture"}>
83+
<If condition={assignment.request !== "keep-fixture" && assignment.request !== "handoff-retention correct"}>
7784
```bash exec as="retired"
7885
git rm -q legacy.fixture
7986
```
@@ -91,8 +98,21 @@ git rev-parse HEAD
9198
<Else><Let as="check" value={{exitCode:0,stdout:"Independent review inspected the migration.",stderr:""}} /></Else>
9299
</If>
93100
<Dir path={assignment.artifactDirectory}><File path="focused.json"><Json value={{revision,...check}} /></File></Dir>
94-
<Let as="outcome" value={conflict ? "needs_discovery" : props.role === "implementor" ? "complete" : props.role === "architect" && assignment.request.endsWith("structural-rejected") ? "changes_required" : "pass"} />
95-
<Json value={{schema:"phase-result.v2",...(assignment.request === "omitted-metadata" ? {} : {phase:assignment.phase,work:assignment.work,revision}),outcome,summary:["oversized-summary","uncorrectable-summary"].includes(assignment.request) ? "x".repeat(1201) : "The fake role ran the assigned consumer.",handoff:conflict ? "Planner: add and validate resize for the remaining consumer." : "Original owner: inspect the completed consumer migration.",artifacts:[receipt],evidence:[{revision:assignment.request === "short-revision" ? revision.slice(0,8) : revision,command:conflict ? "resize narrow" : "inspect the assigned commit",outcome:conflict ? "failed" : "passed",artifact:receipt}],findings:[],assessment:assignment.assessment,...(assignment.request.includes("#1084:") ? {handoffInputs:assignment.handoffInputs ?? []} : {}),discoveryRequests:[],discoveryGaps:[],...(assignment.request === "omitted-metadata" ? {} : {next:conflict ? {phase:"discovery",role:"planner"} : outcome === "changes_required" ? {phase:"implementation",role:"implementor"} : assignment.continuation}),...(conflict ? {apiConflict:{expected:"The API can resize a remaining consumer.",observed:"resize is unavailable.",reproducer:"Source api.sh and run resize narrow.",artifact:receipt}} : {})}} />
101+
<Let as="outcome" value={conflict ? "needs_discovery" : props.role === "implementor" ? "complete" : (props.role === "architect" && assignment.request.endsWith("structural-rejected") || handoffCase && props.role === "planner" && assignment.request === "handoff-retention review") ? "changes_required" : "pass"} />
102+
<Let as="selectedHandoff" value={handoffCase && (props.role === "implementor" || outcome === "changes_required")} />
103+
<Let as="handoffPath" value={assignment.artifactDirectory + "/handoff.md"} />
104+
<If condition={selectedHandoff}>
105+
<Dir path={assignment.artifactDirectory}>
106+
<If condition={props.role === "implementor"}>
107+
<If condition={assignment.request === "handoff-retention correct"}>
108+
<File path="handoff.md">Corrected implementation evidence: bash consumer.sh passed.</File>
109+
<Else><File path="handoff.md">Initial implementation evidence: bash consumer.sh passed.</File></Else>
110+
</If>
111+
<Else><File path="handoff.md">Correct the implementation while retaining its accepted plan.</File></Else>
112+
</If>
113+
</Dir>
114+
</If>
115+
<Json value={{schema:"phase-result.v2",...(assignment.request === "omitted-metadata" ? {} : {phase:assignment.phase,work:assignment.work,revision}),outcome,summary:["oversized-summary","uncorrectable-summary"].includes(assignment.request) ? "x".repeat(1201) : "The fake role ran the assigned consumer.",handoff:handoffCase ? props.role === "implementor" ? assignment.request === "handoff-retention correct" ? "handoff-retention corrected-review" : "handoff-retention review" : outcome === "changes_required" ? "handoff-retention correct" : assignment.request : conflict ? "Planner: add and validate resize for the remaining consumer." : "Original owner: inspect the completed consumer migration.",artifacts:selectedHandoff ? [receipt,handoffPath] : [receipt],evidence:[{revision:assignment.request === "short-revision" ? revision.slice(0,8) : revision,command:conflict ? "resize narrow" : "inspect the assigned commit",outcome:conflict ? "failed" : "passed",artifact:receipt}],findings:[],assessment:assignment.assessment,...(selectedHandoff ? {handoffInputs:[handoffPath,...(assignment.request === "handoff-retention correct" ? assignment.handoffInputs ?? [] : [])]} : assignment.request.includes("#1084:") ? {handoffInputs:assignment.handoffInputs ?? []} : {}),discoveryRequests:[],discoveryGaps:[],...(assignment.request === "omitted-metadata" ? {} : {next:conflict ? {phase:"discovery",role:"planner"} : outcome === "changes_required" ? {phase:"implementation",role:"implementor"} : assignment.continuation}),...(conflict ? {apiConflict:{expected:"The API can resize a remaining consumer.",observed:"resize is unavailable.",reproducer:"Source api.sh and run resize narrow.",artifact:receipt}} : {})}} />
96116
</Else>
97117
</If>
98118
</Else>

0 commit comments

Comments
 (0)