Harden the execute→review pipeline so that by the time a plan reaches DONE, every task has verifiable evidence of completion. During execution: require the executor to return structured per-task evidence (files_changed, commands_run) that can be cross-checked against the actual git diff; require preliminary sense-check acknowledgments from the executor (not just reviewer). Between execute and review: add a programmatic validation pass that audits executor claims against repo state — did the claimed files actually change? do executor_notes reference real artifacts? are sense checks acknowledged? During review: reviewer cross-references executor evidence with git diff and fills verdicts. The whole loop should be thorough but not cumbersome — no new CLI flags, no interactive prompts, enforcement is automatic and invisible on the happy path. The goal: when a plan hits DONE, you can read finalize.json and have complete auditable evidence of what was done, why, and whether it checks out.
User notes and answers:
Ease of agentic use is extremely important. The executor agent needs to understand what's expected without confusion. Enforcement should be robust but the interface (schema, prompts, error messages) must be simple and clear. Don't make the executor jump through hoops — make the right thing easy and the wrong thing impossible.
Two additional requirements before execution:
PROMPT QUALITY FOR AGENTS: The execute and review prompts must be example-driven, not prose-driven. Show the executor a concrete JSON example of the expected output shape (task_updates with files_changed, commands_run; sense_check_acknowledgments with notes). Show the reviewer how to work: trust executor evidence by default, add your own detail where things seem ambiguous or audit flags something, don't re-verify everything from scratch. The sense check experience should be: executor acknowledges each check with a brief note during execution, reviewer confirms or digs deeper only where needed.
REVIEW-TO-EXECUTE KICKBACK LOOP: If the reviewer finds that work itself is incomplete (not just paperwork — actual tasks that weren't done properly), they should be able to kick the plan back to execute. Add a review verdict that triggers STATE_EXECUTED -> STATE_FINALIZED transition with next_step='execute', preserving review findings as context for the re-execution. The executor on re-run sees what the reviewer flagged and addresses it. This creates a mini execute<->review loop that can run multiple times until the reviewer is satisfied. The review.json should carry forward so the executor knows what was flagged.
Goal: When a plan reaches DONE, finalize.json contains complete, auditable, programmatically-verified evidence of what was done and whether it checks out.
Current state: The pipeline has good structural bones — executor returns task_updates with executor_notes, reviewer fills reviewer_verdict and sense_check verdicts, coverage gaps block state transitions. Three gaps remain:
Evidence is flat, not per-task.files_changed and commands_run live at the top level of execution.json, not tied to individual tasks.
No programmatic validation. Executor claims are trusted at face value. Nobody checks whether claimed files actually appear in git status.
Sense-check acknowledgments are one-directional. The executor sees sense checks as "nudges" (prompts.py:380) but never formally acknowledges them.
Key design decision — required fields, not optional:strict_schema() (schemas.py:189-196) forces all declared properties to be required and sets additionalProperties: false on agent-facing schemas. Rather than fighting this, we embrace it: all new evidence fields are required in the schema. This is better for agentic clarity — the executor always knows exactly what to return, no ambiguity. Empty arrays ([]) are the valid value for skipped tasks.
DONE enforcement strategy: Three layers ensure the DONE guarantee:
Schema layer: Agent-facing schemas require all evidence fields — agent cannot return a valid payload without them.
Handler layer:handle_execute blocks if any "done" task has empty files_changed (not just missing task coverage). handle_review blocks if any task verdict has empty evidence_files. Sense-check acknowledgment coverage blocks execute.
Audit layer: Programmatic cross-check of executor claims vs git status surfaces advisory findings for the reviewer.
Merge helper extension:_validate_merge_inputs() (handlers.py:183-228) currently only handles string fields — it iterates required_fields, checks isinstance(value, str), and copies to a normalized dict. Array evidence fields (files_changed, commands_run, evidence_files) need a new array_fields parameter so the helper can validate and carry them through without breaking existing string-field behavior.
Constraints: No new CLI flags, no interactive prompts, enforcement is automatic. Happy path feels invisible.
Phase 1: Schema and Prompt Changes
Step 1: Add per-task evidence fields to execution.json schema (megaplan/schemas.py:129-143)
Scope: Small
Addfiles_changed (array of strings) and commands_run (array of strings) as properties inside task_updates items (schemas.py:133). Since strict_schema() will make them required, the agent must always include them. For skipped tasks, empty arrays [] are valid.
Addsense_check_acknowledgments as a new required top-level array in execution.json (schemas.py:128), with items:
Simple two-field structure — no boolean flag, just the ID and a note. If the executor has nothing to say, a brief note like "N/A — not applicable during execution" suffices. This keeps the interface minimal.
Keep the existing top-level files_changed and commands_run as summary fields.
Step 2: Add evidence fields to finalize.json schema (megaplan/schemas.py:79-121)
Scope: Small
Addfiles_changed (array of strings, default []) and commands_run (array of strings, default []) to task items (schemas.py:86-101). These start as [] when finalize creates the tasks.
Addexecutor_note (string, default "") to sense_check items (schemas.py:105-116). Starts empty, populated during execute merge.
Addevidence_files (array of strings, default []) to task items for the reviewer to populate during review.
Step 3: Add evidence_files to review.json schema (megaplan/schemas.py:144-184)
Scope: Small
Addevidence_files (array of strings) to task_verdicts items (schemas.py:164-169). The reviewer lists which files from the diff they verified for each task.
Step 4: Update the execute prompt for per-task evidence (megaplan/prompts.py:398-430)
Scope: Small
Replace the task_updates instruction (prompts.py:425-426) with:
code
Return `task_updates` with one object per completed or skipped task:
{"task_id": "...", "status": "done|skipped", "executor_notes": "...", "files_changed": ["relative/path", ...], "commands_run": ["...", ...]}.
For skipped tasks, use empty arrays for files_changed and commands_run.
Replace the sense-check nudge block (prompts.py:379-382) to also require formal acknowledgment:
code
Sense checks — acknowledge each one in `sense_check_acknowledgments`:
- SC1 (T1): Did implementation match the stated idea?
Return: [{"sense_check_id": "SC1", "executor_note": "Yes — implemented X as described"}]
Keep the instruction simple and example-driven. Show the executor exactly what the output looks like.
Step 5: Update the review prompts for evidence cross-referencing (megaplan/prompts.py:433-520)
Scope: Small
Add review requirement to both _review_claude_prompt and _review_codex_prompt: "Return evidence_files in each task verdict listing the files you verified from the diff."
Add review requirement: "Cross-reference executor per-task files_changed against the git diff. Flag any discrepancy."
Add review requirement: "Verify that sense-check acknowledgments are substantive, not perfunctory."
Readexecution_audit.json if it exists (added in Phase 2), and include its findings in the prompt. Gracefully skip if the file doesn't exist (handles first-time runs and non-git environments).
Phase 2: Handler Merge Logic and Validation
Step 6: Extend _validate_merge_inputs to support array fields (megaplan/handlers.py:183-228)
Scope: Medium — This is the prerequisite for Steps 7 and 10. Without it, array evidence fields silently disappear during merge.
The current function only handles string fields:
Line 206-217: iterates required_fields, checks isinstance(value, str), copies to normalized dict.
Line 249-250 in _merge_validated_entries: copies merge_fields from validated entry to target.
If files_changed: ["foo.py"] is in required_fields, it fails isinstance(value, str) and the entire entry is skipped as malformed.
Fix — add an array_fields parameter:
Addarray_fields: tuple[str, ...] = () parameter to _validate_merge_inputs() (handlers.py:183).
Update the validation loop (handlers.py:206-217) to handle array fields separately from required string fields:
python
# After the existing required_fields string loop (lines 208-217):
for field in array_fields:
value = entry.get(field)
if not isinstance(value, list):
malformed = True
break
normalized[field] = value
Also check that array fields are present in the entry (handlers.py:202): extend the missing-field check to include array_fields.
Update the return type annotation from list[dict[str, str]] to list[dict[str, Any]] (handlers.py:191) since normalized dicts now contain lists too.
Update_merge_validated_entries type annotation (handlers.py:231) from list[dict[str, str]] to list[dict[str, Any]] to match.
No changes to _merge_validated_entries logic itself — it already does target[field] = entry[field] which works for any type.
Step 7: Update handle_execute to merge per-task evidence and enforce completeness (megaplan/handlers.py:1110-1139)
Scope: Medium
Extend the _validate_merge_inputs call for task_updates (handlers.py:1113-1119) to include the new array fields:
Track coverage: unacked_checks = total_checks - ack_count. If unacked_checks > 0, add deviation and set blocked.
Add per-task evidence completeness enforcement (after merge, before writing finalize.json): iterate merged tasks, check each task with status == "done". If files_changed is empty (len(task.get("files_changed", [])) == 0), add deviation and set blocked = True. This enforces the DONE guarantee — a "done" task must claim at least one file changed. commands_run is allowed to be empty (some tasks are pure file edits with no commands). evidence_files is enforced on the review side (Step 10).
Step 8: Add validate_execution_evidence() to megaplan/evaluation.py
Git file detection: Use git status --short (matching collect_git_diff_summary at _core.py:402-419) to get changed/untracked files. Parse the two-character status prefix and extract file paths (column 3 onward, handling -> for renames). This catches modified, added, deleted, renamed, and untracked files.
Non-fatal fallback — all four paths explicitly:
If (project_dir / ".git").exists() is False: return {"findings": [], "skipped": True, "reason": "Not a git repository"}.
If FileNotFoundError (git not on PATH): return {"findings": [], "skipped": True, "reason": "git not found on PATH"}.
If subprocess.TimeoutExpired: return {"findings": [], "skipped": True, "reason": "git status timed out"}.
If process.returncode != 0: return {"findings": [], "skipped": True, "reason": f"git status failed: {process.stderr.strip() or process.stdout.strip()}"}.
This covers all four failure modes, including the non-zero returncode from empty .git directories used in test scaffolds at tests/test_prompts.py:54 and tests/test_megaplan.py:67.
Check 1 — files_changed vs git status: Collect union of all per-task files_changed from finalize.json tasks. Compare against actual files from git status. Flag:
Phantom claims: "executor says T2 changed foo.py but it is not in git status."
Unclaimed changes: "bar.py in git status but not claimed by any task."
Check 2 — executor_notes artifact references: For each task's executor_notes, extract path-like tokens (regex: word chars, slashes, dots, with a file extension). Check existence relative to project_dir. Flag non-existent paths. Keep regex simple — false positives are acceptable since findings are advisory.
Check 3 — sense-check acknowledgment quality: Flag any executor_note that is very short (< 10 chars) or matches a generic pattern ("done", "yes", "acknowledged") as "possibly perfunctory."
Step 9: Wire validation into handle_execute and write audit artifact (megaplan/handlers.py:1134)
Scope: Small
Callvalidate_execution_evidence(finalize_data, project_dir) after merging task_updates into finalize.json, before writing finalize.json to disk.
Write result to execution_audit.json in plan_dir.
Append each finding to the deviations list so it appears in the step response. Do not block based on audit findings — they are advisory for the reviewer. (Handler-level blocking in Step 7 already covers the structural guarantees.)
Addexecution_audit.json to the artifacts list.
Step 10: Update handle_review to merge evidence_files and enforce completeness (megaplan/handlers.py:1191-1280)
Scope: Small
Extend the _validate_merge_inputs call for task_verdicts (handlers.py:1202-1207) to include the new array field:
Add per-task evidence completeness enforcement in the blocked check (handlers.py:1245): after merging verdicts, check each task with status == "done". If evidence_files is empty, add issue and set blocked = True. This enforces the reviewer side of the DONE guarantee — the reviewer must cite at least one file they verified per done task.
Update_mock_execute (workers.py:379-388) to include per-task files_changed and commands_run in each task_update, and add sense_check_acknowledgments to the payload.
Update_mock_review (workers.py:398-410) to include evidence_files in each task_verdict.
Ensure mock finalize (workers.py:345-373) initializes files_changed: [], commands_run: [], evidence_files: [] on tasks and executor_note: "" on sense_checks.
Run existing tests after Steps 1-3 + Step 6 + Step 11 to verify schema changes, helper extension, and mocks stay in sync.
Run handler tests after Steps 7, 10 to confirm new fields merge and blocking works correctly.
Run validate_execution_evidence unit tests after Step 8.
Run full test suite after Step 12 to verify end-to-end pipeline.
Manual smoke test: run megaplan with mock workers end-to-end, inspect finalize.json at DONE to verify all evidence fields populated and non-empty for done tasks.
code
Execution tracking state (`finalize.json`):
{
"tasks": [
{
"id": "T1",
"description": "Add per-task evidence fields (files_changed, commands_run) to execution.json task_updates schema, add sense_check_acknowledgments top-level array to execution.json schema, and add evidence fields (files_changed, commands_run, evidence_files, executor_note) with empty defaults to finalize.json and review.json schemas in megaplan/schemas.py",
"depends_on": [],
"status": "done",
"executor_notes": "Extended strict schemas so finalize tasks now carry files_changed, commands_run, and evidence_files; finalize sense checks now carry executor_note; execution task_updates now require per-task files_changed and commands_run plus top-level sense_check_acknowledgments; review outputs now require evidence_files and a top-level review_verdict for the kickback loop.",
"reviewer_verdict": ""
},
{
"id": "T2",
"description": "Update execute prompt (megaplan/prompts.py:398-430) to instruct the executor to return per-task files_changed and commands_run in task_updates, and to return sense_check_acknowledgments with sense_check_id and executor_note for each sense check. Use example-driven format showing exact expected output shape.",
"depends_on": [
"T1"
],
"status": "done",
"executor_notes": "Rewrote the execute prompt to be example-driven with exact JSON output shape for task_updates and sense_check_acknowledgments, and to surface prior review.json findings on re-execution so the executor sees what must be fixed.",
"reviewer_verdict": ""
},
{
"id": "T3",
"description": "Update review prompts (_review_claude_prompt and _review_codex_prompt in megaplan/prompts.py:433-520) to require evidence_files in each task verdict, instruct cross-referencing executor per-task files_changed against git diff, verify sense-check acknowledgment quality, and include execution_audit.json findings if the file exists (graceful skip if absent).",
"depends_on": [
"T1"
],
"status": "done",
"executor_notes": "Reworked both review prompts to be example-driven, to trust executor evidence by default, to cross-check per-task files_changed and commands_run against git diff, and to include execution_audit.json with a graceful missing-file fallback.",
"reviewer_verdict": ""
},
{
"id": "T4",
"description": "Extend _validate_merge_inputs (megaplan/handlers.py:183-228) with array_fields: tuple[str, ...] = () parameter. Array fields validated with isinstance(value, list) instead of isinstance(value, str), copied to normalized dict. Update return type to list[dict[str, Any]]. Update _merge_validated_entries type annotation to list[dict[str, Any]] (logic unchanged \u2014 target[field] = entry[field] already works for any type).",
"depends_on": [],
"status": "done",
"executor_notes": "Extended _validate_merge_inputs with array_fields support and widened merge helper typing to carry list-valued evidence fields through execute/review merges without stripping them.",
"reviewer_verdict": ""
},
{
"id": "T5",
"description": "Update mock workers (megaplan/workers.py:340-411): mock finalize adds files_changed: [], commands_run: [], evidence_files: [] on tasks and executor_note: '' on sense_checks. Mock execute adds per-task files_changed and commands_run in task_updates and adds sense_check_acknowledgments. Mock review adds evidence_files in each task_verdict.",
"depends_on": [
"T1"
],
"status": "done",
"executor_notes": "Updated mock finalize/execute/review workers so every new required field is populated, including empty arrays for pending/skipped fields, per-task evidence arrays, sense_check_acknowledgments, and review verdict evidence_files.",
"reviewer_verdict": ""
},
{
"id": "T6",
"description": "Update handle_execute (megaplan/handlers.py:1110-1139): pass array_fields=('files_changed', 'commands_run') to _validate_merge_inputs for task_updates; extend merge_fields to include files_changed and commands_run; add sense_check_acknowledgments merge block (validate, merge executor_note into sense_checks, block if unacked_checks > 0); add per-task evidence enforcement \u2014 block if done task has empty files_changed AND empty commands_run (FLAG-006 softening: if commands_run is non-empty, downgrade to advisory deviation instead of blocking).",
"depends_on": [
"T4"
],
"status": "done",
"executor_notes": "Updated handle_execute to merge per-task files_changed and commands_run, merge sense_check_acknowledgments onto finalize sense_checks by id, block incomplete task/sense-check coverage, and enforce FLAG-006 by blocking only when a done task has both files_changed and commands_run empty while treating command-only tasks as advisory.",
"reviewer_verdict": ""
},
{
"id": "T7",
"description": "Implement validate_execution_evidence(finalize_data, project_dir) in megaplan/evaluation.py. Returns dict with findings, files_in_diff, files_claimed, skipped, reason. Uses git status --short (matching collect_git_diff_summary pattern). Four non-fatal fallback paths: no .git, FileNotFoundError, TimeoutExpired, non-zero returncode. Check 1: phantom claims vs unclaimed changes. Check 2: path-like tokens in executor_notes checked for existence. Check 3: perfunctory sense-check acknowledgments (<10 chars or generic patterns).",
"depends_on": [
"T6"
],
"status": "done",
"executor_notes": "Implemented validate_execution_evidence using git status --short with non-fatal fallback handling for missing .git, missing git binary, timeouts, and non-zero returncode; it audits phantom claims, unclaimed changes, missing note artifacts, and perfunctory sense-check acknowledgments.",
"reviewer_verdict": ""
},
{
"id": "T8",
"description": "Wire validate_execution_evidence into handle_execute (after task merge, before writing finalize.json). Write result to execution_audit.json in plan_dir. Append findings to deviations as advisory (non-blocking). Add execution_audit.json to artifacts list.",
"depends_on": [
"T7"
],
"status": "done",
"executor_notes": "Wired execution auditing into handle_execute so execution_audit.json is written before finalize.json and all audit findings or skips are appended to deviations as advisory, non-blocking signals.",
"reviewer_verdict": ""
},
{
"id": "T9",
"description": "Update handle_review (megaplan/handlers.py:1191-1280): pass array_fields=('evidence_files',) to _validate_merge_inputs for task_verdicts; extend merge_fields to include evidence_files; add per-task evidence enforcement \u2014 block if done task has empty evidence_files AND reviewer_verdict doesn't substantively reference command output (FLAG-006 softening: if reviewer_verdict is substantive, downgrade to advisory deviation).",
"depends_on": [
"T4"
],
"status": "done",
"executor_notes": "Updated handle_review to merge evidence_files, enforce reviewer evidence for done tasks, soften FLAG-006 when reviewer_verdict is substantive, and route review_verdict=needs_rework back to STATE_FINALIZED with next_step=execute so review findings carry into the next execution pass.",
"reviewer_verdict": ""
},
{
"id": "T10",
"description": "Update render_final_md (megaplan/_core.py:92-142) to render per-task files_changed (indented list under each task when non-empty), executor_note on sense checks, and evidence_files under reviewer verdict (when non-empty). Keep existing gap-detection logic intact.",
"depends_on": [
"T1"
],
"status": "done",
"executor_notes": "Extended render_final_md to show per-task files_changed, per-sense-check executor_note, and reviewer evidence_files while preserving the existing coverage-gap reporting behavior.",
"reviewer_verdict": ""
},
{
"id": "T11",
"description": "Write tests: unit test validate_execution_evidence with mocked git status (modified, untracked, renamed, deleted; graceful skip for all four fallback paths including non-zero returncode); unit test _validate_merge_inputs with array_fields; update existing schema/handler/render test fixtures to include new required fields; test blocking behavior for empty evidence on done tasks; test FLAG-006 softening (done task with empty files_changed but non-empty commands_run is not blocked). Run full test suite.",
"depends_on": [
"T7",
"T8",
"T6",
"T9",
"T10",
"T5"
],
"status": "done",
"executor_notes": "Added unit and flow tests for array-field validation, execution auditing across all git fallback modes, execute/review evidence enforcement, FLAG-006 softening, prompt/schema updates, and the new review-to-execute kickback loop; full pytest suite passes.",
"reviewer_verdict": ""
}
],
"watch_items": [
"FLAG-006: Do NOT block execute when a done task has empty files_changed but non-empty commands_run \u2014 treat as advisory deviation. Same principle for review: empty evidence_files with substantive reviewer_verdict is a deviation, not a blocker. This handles verification-only tasks.",
"strict_schema() (schemas.py:189-196) forces ALL declared properties to be required and sets additionalProperties: false. Every new field added to schemas will be required in agent-facing output. Empty arrays [] are the valid value for skipped tasks \u2014 not missing fields.",
"_validate_merge_inputs currently only handles string fields (isinstance check at line 210). T4 MUST land before T6/T9 or array evidence fields will be silently stripped during merge, causing data loss.",
"The sense_check_acknowledgments merge needs a targets_by_id built from finalize_data sense_checks (keyed by 'id'), not from tasks. Don't confuse the two ID spaces.",
"validate_execution_evidence must handle four failure modes from git status: (1) no .git directory, (2) git not on PATH (FileNotFoundError), (3) timeout, (4) non-zero returncode (empty .git dirs in test scaffolds at tests/test_prompts.py:54 and tests/test_megaplan.py:67). All return skipped=True, never raise.",
"Existing top-level files_changed and commands_run in execution.json are summary fields and must be preserved alongside the new per-task fields \u2014 they serve different purposes (summary vs attribution).",
"The review prompt must gracefully handle missing execution_audit.json (first-time runs, non-git environments). Use conditional read, not hard dependency.",
"Keep executor-facing schema and prompt changes minimal and example-driven. The executor should see exactly what shape to return, no ambiguity. This is the user's top priority.",
"commands_run is intentionally NOT enforced non-empty for done tasks \u2014 some tasks are pure file edits. Only files_changed non-emptiness is enforced (softened by FLAG-006 for verification-only tasks).",
"Return type annotations on _validate_merge_inputs and _merge_validated_entries must change from list[dict[str, str]] to list[dict[str, Any]] to accommodate array fields."
],
"sense_checks": [
{
"id": "SC1",
"task_id": "T1",
"question": "Do the new schema fields in execution.json, finalize.json, and review.json all survive strict_schema() \u2014 i.e., are they declared as properties (not just defaults) so they become required?",
"verdict": ""
},
{
"id": "SC2",
"task_id": "T2",
"question": "Does the execute prompt show the executor the exact expected JSON shape for task_updates (with files_changed, commands_run) and sense_check_acknowledgments, with a concrete example?",
"verdict": ""
},
{
"id": "SC3",
"task_id": "T3",
"question": "Do both review prompts (Claude and Codex) include the execution_audit.json read with a graceful fallback if the file doesn't exist?",
"verdict": ""
},
{
"id": "SC4",
"task_id": "T4",
"question": "Does _validate_merge_inputs correctly validate array fields with isinstance(value, list) and skip entries where an array field is not a list, without breaking existing string-field validation?",
"verdict": ""
},
{
"id": "SC5",
"task_id": "T5",
"question": "Do mock workers produce payloads that pass schema validation with all new required fields populated (including empty arrays for skipped tasks)?",
"verdict": ""
},
{
"id": "SC6",
"task_id": "T6",
"question": "Does handle_execute correctly implement FLAG-006 softening \u2014 blocking only when a done task has BOTH empty files_changed AND empty commands_run, treating empty files_changed with non-empty commands_run as advisory deviation?",
"verdict": ""
},
{
"id": "SC7",
"task_id": "T7",
"question": "Does validate_execution_evidence handle all four git failure modes (no .git, FileNotFoundError, TimeoutExpired, non-zero returncode) by returning skipped=True without raising?",
"verdict": ""
},
{
"id": "SC8",
"task_id": "T8",
"question": "Are audit findings appended to deviations as advisory (non-blocking) and is execution_audit.json written before finalize.json so the reviewer can reference it?",
"verdict": ""
},
{
"id": "SC9",
"task_id": "T9",
"question": "Does handle_review implement FLAG-006 softening for evidence_files \u2014 not blocking when a done task has empty evidence_files but a substantive reviewer_verdict?",
"verdict": ""
},
{
"id": "SC10",
"task_id": "T10",
"question": "Does render_final_md correctly render the new fields (files_changed list, executor_note, evidence_files) without breaking existing gap-detection logic?",
"verdict": ""
},
{
"id": "SC11",
"task_id": "T11",
"question": "Does the full test suite pass, including tests for FLAG-006 softening (done task with commands_run but no files_changed is not blocked)?",
"verdict": ""
}
],
"meta_commentary": "Execution order: T1 and T4 are independent and can run in parallel (schemas and helper extension). T2, T3, T5, T10 depend only on T1. T6 and T9 depend on T4. T7 depends on T6. T8 depends on T7. T11 depends on everything else.\n\nCritical judgment call \u2014 FLAG-006 softening: The plan's Step 7 says 'block if done task has empty files_changed.' The gate warning says to NOT block when commands_run is non-empty. Implement the softened version: block only when BOTH files_changed AND commands_run are empty for a done task. Same principle for Step 10 / evidence_files \u2014 if reviewer_verdict is substantive (>20 chars), treat empty evidence_files as advisory. This avoids forcing agents to invent file attribution for verification-only tasks.\n\nThe _validate_merge_inputs extension (T4) is the keystone \u2014 without it, array fields silently vanish during merge. Prioritize getting this right. The fix is surgical: add an array_fields parameter, validate with isinstance(value, list), copy to normalized dict. The existing _merge_validated_entries logic (target[field] = entry[field]) already works for any type \u2014 only the type annotation needs updating.\n\nFor the sense_check_acknowledgments merge in T6: build targets_by_id from finalize_data['sense_checks'] keyed by 'id' field (not 'sense_check_id'). The executor returns sense_check_id in its acknowledgments, but the finalize.json sense_checks use 'id'. The _merge_validated_entries id_field should be 'sense_check_id' and targets_by_id should be keyed by the sense_check 'id' values.\n\nThe execution_audit.json is advisory-only \u2014 findings go into deviations for visibility but never set blocked=True. The blocking guarantees come from the handler-level checks (empty evidence arrays) and schema-level enforcement (required fields). This separation keeps the audit from creating false-positive blocks while still surfacing useful cross-check information for the reviewer.\n\nRun existing tests after T1+T4+T5 to catch any fixture breakage early. The test fixtures in tests/ construct execution.json and review.json payloads that will need the new required fields added."
}
code
Plan metadata:
{
"version": 3,
"timestamp": "2026-03-25T02:35:04Z",
"hash": "sha256:af55ff5e059d3c0e617f36461a3abeede5f73aee14030fa79896597286d98282",
"changes_summary": "Surgical fixes for the three remaining flags \u2014 no structural changes to the plan, just closing the specific gaps:\n\nFLAG-003 (DONE enforcement): Added explicit blocking checks for empty evidence arrays. In Step 7: after merging task_updates, iterate done tasks \u2014 if any has empty files_changed, block execute. In Step 10: after merging task_verdicts, iterate done tasks \u2014 if any has empty evidence_files, block review. commands_run is intentionally not enforced (some tasks are pure file edits). This closes the gap between "required in schema" (agent must return the field) and "non-empty at DONE" (the field must have content for done tasks).\n\nFLAG-004 (non-zero returncode): Added the fourth fallback path explicitly in Step 8: if process.returncode != 0: return {\"findings\": [], \"skipped\": True, \"reason\": f\"git status failed: {stderr}\"}. This matches collect_git_diff_summary's handling at _core.py:417-418 and covers the empty .git directory case used in test scaffolds.\n\nFLAG-005 (merge helpers strip array fields): Added Step 6 as a dedicated step to extend _validate_merge_inputs. The fix adds an array_fields: tuple[str, ...] = () parameter. Array fields get validated with isinstance(value, list) instead of isinstance(value, str), and copied to the normalized dict alongside string fields. Return type annotation updated to dict[str, Any]. _merge_validated_entries already handles any type via target[field] = entry[field], so it only needs a type annotation update. Steps 7 and 10 now show the exact call signatures with array_fields= parameter.",
"flags_addressed": [
"FLAG-003",
"FLAG-004",
"FLAG-005"
],
"questions": [],
"success_criteria": [
"Every task in finalize.json at STATE_DONE has non-empty files_changed, executor_notes, and reviewer_verdict fields (enforced by handler blocking on empty arrays + required schema fields)",
"Every task in finalize.json at STATE_DONE has non-empty evidence_files from the reviewer (enforced by handle_review blocking)",
"Every sense_check in finalize.json at STATE_DONE has a non-empty executor_note and reviewer verdict (enforced by blocking on incomplete acknowledgment coverage)",
"execution_audit.json exists after every execute step and contains programmatic cross-check of claimed vs actual file changes",
"Phantom file claims (executor says file changed but git status disagrees) are detected and surfaced in audit findings",
"Unclaimed changes (file in git status but not claimed by any task) are detected and surfaced in audit findings",
"Review prompts include audit findings so the reviewer can act on discrepancies",
"New fields are required in agent-facing schemas \u2014 agents always return them, no ambiguity",
"No new CLI flags or interactive prompts are introduced",
"Audit validation degrades gracefully in all non-git scenarios: missing .git, missing git binary, timeout, AND non-zero returncode from empty .git directories",
"Existing test suite passes after updating test fixtures to include new required fields",
"render_final_md shows the enriched evidence when present",
"Mock workers produce valid payloads with all new fields",
"_validate_merge_inputs correctly carries array fields (files_changed, commands_run, evidence_files) through validation without stripping them"
],
"assumptions": [
"Per-task files_changed and commands_run are executor-reported claims, not system-captured. The audit validates claims against git state but doesn't independently log commands. Acceptable since the executor is an LLM agent that can only self-report.",
"The git status check uses git status --short (matching existing collect_git_diff_summary). This captures modified, added, deleted, renamed, and untracked files. Committed-then-amended changes that are no longer dirty won't appear \u2014 assumed acceptable.",
"Making all new fields required in the schema means plans created before this version will need megaplan init re-run to regenerate schema files. This is standard for schema-breaking changes and acceptable.",
"The execution_audit.json artifact is written alongside execution.json and finalize.json \u2014 no separate CLI step or state transition needed.",
"Sense-check acknowledgment coverage blocking uses the same pattern as task coverage: if executor doesn't acknowledge all sense checks, execute is blocked and must re-run.",
"The path-extraction regex for executor_notes validation is simple (tokens with / and file extensions). False positives are acceptable since findings are advisory for the reviewer.",
"commands_run is not enforced non-empty for done tasks \u2014 some tasks are pure file edits with no shell commands. Only files_changed is enforced non-empty since every done task must touch at least one file.",
"Reviewer evidence_files is enforced non-empty for done tasks \u2014 the reviewer must cite at least one file they verified. For skipped tasks, empty is valid."
],
"structure_warnings": [],
"delta_from_previous_percent": 30.3
}
code
Execution summary:
{
"output": "Implemented the execute\u2192review hardening end to end. Schemas now require per-task evidence and sense-check acknowledgments in schemas.py, execute/review prompts are example-driven and review-aware in prompts.py, execute now merges evidence, writes execution_audit.json, and enforces the FLAG-006 softening path while review can either approve, block on missing evidence, or route back to execute via review_verdict in handlers.py and handlers.py. The audit pass lives in evaluation.py, and final.md now renders files_changed, sense-check executor notes, and reviewer evidence_files in \fore.py. Mock workers and tests were updated across workers.py, test_megaplan.py, test_evaluation.py, test_prompts.py, test_schemas.py, and test_workers.py.\n\nCommands run: pytest tests/test_schemas.py tests/test_prompts.py tests/test_workers.py tests/test_evaluation.py tests/test_megaplan.py -q, pytest -q, git status --short, git diff --stat -- megaplan tests. Full test suite passed: 254 passed.\n\nFiles changed: megaplan/_core.py, megaplan/evaluation.py, megaplan/handlers.py, megaplan/prompts.py, megaplan/schemas.py, megaplan/workers.py, tests/test_evaluation.py, tests/test_megaplan.py, tests/test_prompts.py, tests/test_schemas.py, tests/test_workers.py. Deviation from the written task list: I added a required top-level review_verdict field and execute-side reuse of prior review.json so the approved review\u2192execute kickback loop is explicit and machine-enforceable. Existing unrelated worktree change left untouched: scorecard.png.",
"files_changed": [
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED],
[REDACTED]
],
"commands_run": [
"pytest tests/test_schemas.py tests/test_prompts.py tests/test_workers.py tests/test_evaluation.py tests/test_megaplan.py -q",
"pytest -q",
"git status --short",
"git diff --stat -- megaplan tests"
],
"deviations": [
"Added a required top-level review_verdict field to review.json and corresponding prompt/handler wiring so review can explicitly kick work back to execute, because the approved plan required that behavior but did not define a concrete schema field for it.",
"Included prior review.json in the execute prompt when present so re-execution sees preserved review findings directly.",
"Left the pre-existing unrelated scorecard.png modification untouched."
],
"task_updates": [
{
"task_id": "T1",
"status": "done",
"executor_notes": "Extended strict schemas so finalize tasks now carry files_changed, commands_run, and evidence_files; finalize sense checks now carry executor_note; execution task_updates now require per-task files_changed and commands_run plus top-level sense_check_acknowledgments; review outputs now require evidence_files and a top-level review_verdict for the kickback loop."
},
{
"task_id": "T2",
"status": "done",
"executor_notes": "Rewrote the execute prompt to be example-driven with exact JSON output shape for task_updates and sense_check_acknowledgments, and to surface prior review.json findings on re-execution so the executor sees what must be fixed."
},
{
"task_id": "T3",
"status": "done",
"executor_notes": "Reworked both review prompts to be example-driven, to trust executor evidence by default, to cross-check per-task files_changed and commands_run against git diff, and to include execution_audit.json with a graceful missing-file fallback."
},
{
"task_id": "T4",
"status": "done",
"executor_notes": "Extended _validate_merge_inputs with array_fields support and widened merge helper typing to carry list-valued evidence fields through execute/review merges without stripping them."
},
{
"task_id": "T5",
"status": "done",
"executor_notes": "Updated mock finalize/execute/review workers so every new required field is populated, including empty arrays for pending/skipped fields, per-task evidence arrays, sense_check_acknowledgments, and review verdict evidence_files."
},
{
"task_id": "T6",
"status": "done",
"executor_notes": "Updated handle_execute to merge per-task files_changed and commands_run, merge sense_check_acknowledgments onto finalize sense_checks by id, block incomplete task/sense-check coverage, and enforce FLAG-006 by blocking only when a done task has both files_changed and commands_run empty while treating command-only tasks as advisory."
},
{
"task_id": "T7",
"status": "done",
"executor_notes": "Implemented validate_execution_evidence using git status --short with non-fatal fallback handling for missing .git, missing git binary, timeouts, and non-zero returncode; it audits phantom claims, unclaimed changes, missing note artifacts, and perfunctory sense-check acknowledgments."
},
{
"task_id": "T8",
"status": "done",
"executor_notes": "Wired execution auditing into handle_execute so execution_audit.json is written before finalize.json and all audit findings or skips are appended to deviations as advisory, non-blocking signals."
},
{
"task_id": "T9",
"status": "done",
"executor_notes": "Updated handle_review to merge evidence_files, enforce reviewer evidence for done tasks, soften FLAG-006 when reviewer_verdict is substantive, and route review_verdict=needs_rework back to STATE_FINALIZED with next_step=execute so review findings carry into the next execution pass."
},
{
"task_id": "T10",
"status": "done",
"executor_notes": "Extended render_final_md to show per-task files_changed, per-sense-check executor_note, and reviewer evidence_files while preserving the existing coverage-gap reporting behavior."
},
{
"task_id": "T11",
"status": "done",
"executor_notes": "Added unit and flow tests for array-field validation, execution auditing across all git fallback modes, execute/review evidence enforcement, FLAG-006 softening, prompt/schema updates, and the new review-to-execute kickback loop; full pytest suite passes."
}
]
}
code
Execution audit (`execution_audit.json`): not present. Skip that artifact gracefully and rely on `finalize.json`, `execution.json`, and the git diff.
Git diff summary:
M megaplan/_core.py
M megaplan/evaluation.py
M megaplan/handlers.py
M megaplan/prompts.py
M megaplan/schemas.py
M megaplan/workers.py
M scorecard.png
M tests/test_evaluation.py
M tests/test_megaplan.py
M tests/test_prompts.py
M tests/test_schemas.py
M tests/test_workers.py
code
Requirements:
- Be critical.
- Verify each success criterion explicitly.
- Trust executor evidence by default. Only re-verify from scratch where the diff, the audit, or the notes leave a real ambiguity.
- If actual implementation work is incomplete, set top-level `review_verdict` to `needs_rework` so the plan routes back to execute. Use `approved` only when the work itself checks out.
- Cross-reference each task's `files_changed` and `commands_run` against the git diff and any audit findings.
- Review every `sense_check` explicitly and treat perfunctory acknowledgments as a reason to dig deeper.
- Follow this JSON shape exactly:
```json
{
"review_verdict": "approved",
"criteria": [
{
"name": "Review cross-check completed",
"pass": true,
"evidence": "Executor evidence in finalize.json matches the diff and the audit file."
}
],
"issues": [],
"summary": "Approved. The executor evidence is consistent and the remaining findings are advisory only.",
"task_verdicts": [
{
"task_id": "T3",
"reviewer_verdict": "Pass. Review prompt changes match the diff and reference the audit fallback correctly.",
"evidence_files": ["megaplan/prompts.py"]
}
],
"sense_check_verdicts": [
{
"sense_check_id": "SC3",
"verdict": "Confirmed. Both review prompts load execution_audit.json with a graceful fallback."
}
]
}
```
- When the work needs another execute pass, keep the same shape and change only `review_verdict` to `needs_rework`; put the actionable gaps in `issues`, `summary`, and per-task verdicts.
{
"review_verdict": "needs_rework",
"criteria": [
{
"name": "Every done task has non-empty files_changed, executor_notes, and reviewer_verdict",
"pass": false,
"evidence": "Failed on the files_changed part: [megaplan/handlers.py] only blocks execute when both files_changed and commands_run are empty, and [tests/test_megaplan.py] explicitly preserves that softened path in test_execute_softens_done_task_with_commands_only."
},
{
"name": "Every done task has non-empty evidence_files from the reviewer",
"pass": false,
"evidence": "Failed: [megaplan/handlers.py] allows review to finish with empty evidence_files when reviewer_verdict is deemed substantive, and [tests/test_megaplan.py] locks that in via test_review_softens_substantive_verdict_without_evidence_files_and_can_kick_back."
},
{
"name": "Every sense check at DONE has non-empty executor_note and reviewer verdict",
"pass": true,
"evidence": "[megaplan/handlers.py] blocks missing executor acknowledgments during execute and incomplete sense-check verdict coverage during review."
},
{
"name": "execution_audit.json exists after every execute step",
"pass": true,
"evidence": "[megaplan/handlers.py] writes execution_audit.json unconditionally before finalize.json, and [tests/test_megaplan.py] asserts the artifact exists after execute. The current review bundle omitted the artifact, but the implementation path is present."
},
{
"name": "Phantom file claims are detected and surfaced",
"pass": true,
"evidence": "[megaplan/evaluation.py] compares claimed files against git status --short and emits phantom-claim findings; [tests/test_evaluation.py] covers the ghost.py case."
},
{
"name": "Unclaimed changes are detected and surfaced",
"pass": true,
"evidence": "[megaplan/evaluation.py] reports changed files in git status that no task claimed; [tests/test_evaluation.py] covers deleted and untracked files."
},
{
"name": "Review prompts include audit findings",
"pass": true,
"evidence": "[megaplan/prompts.py] includes execution_audit.json in both review prompts and falls back cleanly when it is absent."
},
{
"name": "New fields are required in agent-facing schemas",
"pass": true,
"evidence": "[megaplan/schemas.py] adds the new evidence fields as declared properties, and strict_schema() makes them required."
},
{
"name": "No new CLI flags or interactive prompts were introduced",
"pass": true,
"evidence": "The diff is confined to schemas, prompts, handlers, evaluation, rendering, workers, and tests; no CLI surface change was introduced."
},
{
"name": "Audit validation degrades gracefully in all non-git scenarios",
"pass": true,
"evidence": "[megaplan/evaluation.py] returns skipped=true for missing .git, missing git binary, timeouts, and non-zero git status; [tests/test_evaluation.py] covers all four paths."
},
{
"name": "Existing test suite passes after fixture updates",
"pass": true,
"evidence": "The diff updates the affected schema/prompt/worker/handler tests, and the executor reported pytest -q passing. I could not rerun pytest here because the sandbox has no usable temporary directory."
},
{
"name": "render_final_md shows the enriched evidence",
"pass": true,
"evidence": "[megaplan/_core.py] renders per-task files_changed, sense-check executor_note, and reviewer evidence_files while keeping gap reporting intact."
},
{
"name": "Mock workers produce valid payloads with all new fields",
"pass": true,
"evidence": "[megaplan/workers.py] populates the new task arrays, sense-check acknowledgments, review_verdict, and reviewer evidence_files; [tests/test_workers.py] checks those fields."
},
{
"name": "_validate_merge_inputs carries array fields without stripping them",
"pass": true,
"evidence": "[megaplan/handlers.py] now accepts array_fields, validates lists, and returns dict[str, Any]; [tests/test_megaplan.py] covers valid and malformed array-field inputs."
}
],
"issues": [
"T6 needs rework: tighten handle_execute so every done task must carry non-empty files_changed, then update the execute-side tests and mocks to match. The current FLAG-006 softening leaves a DONE path without file-backed task evidence.",
"T9 needs rework: tighten handle_review so every done task must carry non-empty evidence_files, then update the review-side tests and mocks to match. The current substantive-verdict softening leaves a DONE path without reviewer-cited file evidence."
],
"summary": "Needs rework. The schema, prompt, audit, rendering, and review-kickback pieces are largely in place, but the core DONE guarantee is still softened in execute and review: a plan can finish with empty task files_changed or empty reviewer evidence_files. I also could not rerun pytest in this sandbox because no usable temp directory is available, so test-pass confirmation relies on the executor report and the updated test files.",
"task_verdicts": [
{
"task_id": "T1",
"reviewer_verdict": "Pass. The schema changes landed: finalize.json, execution.json, and review.json now declare the new evidence fields and survive strict_schema().",
"evidence_files": [
"megaplan/schemas.py"
]
},
{
"task_id": "T2",
"reviewer_verdict": "Pass. The execute prompt is example-driven, shows the exact JSON shape for task_updates and sense_check_acknowledgments, and includes prior review.json context for re-execution.",
"evidence_files": [
"megaplan/prompts.py"
]
},
{
"task_id": "T3",
"reviewer_verdict": "Pass. Both review prompts are example-driven, instruct trust-by-default cross-checking, and include the execution_audit.json fallback path.",
"evidence_files": [
"megaplan/prompts.py"
]
},
{
"task_id": "T4",
"reviewer_verdict": "Pass. _validate_merge_inputs now carries list-valued evidence fields through validation and merge without stripping them.",
"evidence_files": [
"megaplan/handlers.py"
]
},
{
"task_id": "T5",
"reviewer_verdict": "Pass. Mock finalize/execute/review payloads include the new required fields and sense-check acknowledgment structures.",
"evidence_files": [
"megaplan/workers.py",
"tests/test_workers.py"
]
},
{
"task_id": "T6",
"reviewer_verdict": "Needs rework. The merge and sense-check acknowledgment logic is correct, but the blocker is softer than the approved success criteria: done tasks may still proceed with files_changed=[] when commands_run is non-empty.",
"evidence_files": [
"megaplan/handlers.py",
"tests/test_megaplan.py"
]
},
{
"task_id": "T7",
"reviewer_verdict": "Pass. validate_execution_evidence() handles the four non-git fallback modes and audits phantom claims, unclaimed changes, missing note artifacts, and perfunctory acknowledgments.",
"evidence_files": [
"megaplan/evaluation.py",
"tests/test_evaluation.py"
]
},
{
"task_id": "T8",
"reviewer_verdict": "Pass. Execute writes execution_audit.json, appends advisory audit findings to deviations, and keeps those findings non-blocking.",
"evidence_files": [
"megaplan/handlers.py",
"tests/test_megaplan.py"
]
},
{
"task_id": "T9",
"reviewer_verdict": "Needs rework. The review-to-execute kickback loop is implemented, but review still allows evidence_files=[] for done tasks when the reviewer text is substantive, which misses the approved DONE evidence requirement.",
"evidence_files": [
"megaplan/handlers.py",
"tests/test_megaplan.py"
]
},
{
"task_id": "T10",
"reviewer_verdict": "Pass. render_final_md() now shows per-task files, sense-check executor notes, and reviewer evidence files without breaking the existing coverage-gap output.",
"evidence_files": [
"megaplan/_core.py"
]
},
{
"task_id": "T11",
"reviewer_verdict": "Needs rework. Coverage is broad, but the tests currently encode the T6/T9 softening instead of enforcing the approved non-empty evidence guarantees, so they will need to move with the handler fixes.",
"evidence_files": [
"tests/test_megaplan.py",
"tests/test_evaluation.py",
"tests/test_prompts.py",
"tests/test_schemas.py",
"tests/test_workers.py"
]
}
],
"sense_check_verdicts": [
{
"sense_check_id": "SC1",
"verdict": "Confirmed. The new schema fields are declared as properties in [megaplan/schemas.py], so strict_schema() makes them required."
},
{
"sense_check_id": "SC2",
"verdict": "Confirmed. The execute prompt includes a concrete JSON example with files_changed, commands_run, and sense_check_acknowledgments."
},
{
"sense_check_id": "SC3",
"verdict": "Confirmed. Both review prompts load execution_audit.json when present and fall back cleanly when it is absent."
},
{
"sense_check_id": "SC4",
"verdict": "Confirmed. Array fields are validated with isinstance(value, list) and preserved through merge validation."
},
{
"sense_check_id": "SC5",
"verdict": "Confirmed. The mock workers populate the new required fields, including empty arrays and default executor_note values."
},
{
"sense_check_id": "SC6",
"verdict": "Confirmed, and this is one of the two substantive gaps: execute intentionally softens the blocker and allows command-only done tasks."
},
{
"sense_check_id": "SC7",
"verdict": "Confirmed. validate_execution_evidence() returns skipped=true without raising for all four non-git failure modes."
},
{
"sense_check_id": "SC8",
"verdict": "Confirmed. Audit findings are appended as advisory deviations and execution_audit.json is written before finalize.json."
},
{
"sense_check_id": "SC9",
"verdict": "Confirmed, and this is the second substantive gap: review intentionally softens the blocker and allows substantive-verdict-only done tasks."
},
{
"sense_check_id": "SC10",
"verdict": "Confirmed. final.md renders the new evidence fields and still reports missing coverage where appropriate."
},
{
"sense_check_id": "SC11",
"verdict": "Provisionally confirmed from the diff: the new tests exist and target the right areas, and the executor reported full pytest success. I could not rerun pytest here because the sandbox has no usable temporary directory."
}
]
}
“Review the implementation against the success criteria. Project directory:….” Conversation with gpt-5.4, from the Peter O’Mallet DataClaw Conversations dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m80epy0rz5ng59taz784383p