Refactor the finalize/execute/review artifact model so that the execution-tracking layer (task checklist, watch items, sense-checks) is structured JSON rather than prose markdown. The finalize step produces a rich finalize.json with a tasks[] array (each task has id, description, depends_on, status, executor_notes, reviewer_verdict). The execute handler programmatically updates finalize.json after the worker runs - checking off tasks, populating executor_notes from execution.json data. The review handler programmatically fills in reviewer_verdict fields after the worker runs. A render_final_md() utility generates a human-readable markdown view from finalize.json on demand (for status/audit commands). The plan narrative stays as markdown (plan_v*.md), but the tracking layer is pure structured data that flows through the pipeline mechanically. Remove the LLM-edits-markdown-checklist approach entirely.
code
Plan:
# Implementation Plan: Structured JSON Tracking Layer for Finalize/Execute/Review
Overview
Replace the LLM-edits-markdown-checklist approach with a structured JSON artifact that flows mechanically through finalize → execute → review. The plan narrative stays markdown; the tracking layer becomes pure data.
Current State
Finalize produces final.md (prose markdown with - [ ] checklist + > _notes:_ lines) and a minimal finalize.json (task_count, watch_items, meta_commentary).
Execute tells the LLM to edit final.md in-place — checking off - [ ] → - [x] and filling > _notes:_. Also produces execution.json (output, files_changed, commands_run, deviations).
Review tells the LLM to read the edited final.md, verify checked-off items, fill in > _verdict:_ lines, and produce review.json.
Problems: Brittle markdown parsing, no machine-readable task state, no structured link between tasks and executor/reviewer feedback.
Step 1: Define the new finalize.json schema
File:megaplan/schemas.py
Replace the current schema with:
Assistant
{"flags":[{"id":"FLAG-001","concern":"The plan omits , but this repo's mock finalize/execute/review workers still emit the old artifact shapes. Without updating them, mock mode and the end-to-end tests will break as soon as , , and change shape.","category":"completeness","severity_hint":"likely-significant","evidence":" still returns , no , and no review verdict arrays. The mock-path tests assert that old shape in and , and the workflow test drives finalize->execute->review through mock workers in ."},{"id":"FLAG-002","concern":"The plan assumes the new JSON schemas will protect the structured tracking layer, but that is not true on the Codex resume path. Persistent Codex sessions skip , and runtime validation only checks top-level required keys, so malformed nested , , or verdict arrays could still be accepted and merged into .","category":"correctness","severity_hint":"likely-significant","evidence":" shows only checks for missing top-level keys. explicitly notes that does not support and relies on that shallow validation."},{"id":"FLAG-003","concern":"The plan adds source-of-truth mutations to during execute and review, but leaves the repository's audit trail model unchanged. Today those steps only record hashes for or , so the updated state would not be versioned in history or surfaced by audit as a distinct artifact revision.","category":"completeness","severity_hint":"likely-significant","evidence":" records only in execute history, and records only in review history. shows returns state only, not artifact contents or hashes for the mutated tracking file."}],"verified_flag_ids":[],"disputed_flag_ids":[]}
User
Assistant
{"flags":[{"id":"FLAG-002","concern":"The Codex-resume validation gap is still open. The proposed only checks that required keys exist, so bad nested values can still be merged into , and malformed entries are silently dropped instead of failing the step. That means the source-of-truth artifact can still become invalid or incomplete on the resume path.","category":"correctness","severity_hint":"likely-significant","evidence":"In the actual repo, resumed Codex runs still bypass and rely on shallow at and . The plan's pseudocode only does a required-key check; it does not validate types, enum values like , or surface a hard failure when merge data is bad."},{"id":"FLAG-003","concern":"The audit-trail concern is not actually resolved as written. The plan says accepts , but in this repository it has a fixed signature, and has no field. Implemented literally, the proposed addition will fail or require extra handler/type changes that the plan currently says are unnecessary.","category":"correctness","severity_hint":"likely-significant","evidence":" shows has explicit parameters only, with no . defines without a key. The revised plan metadata also explicitly assumes , which is false against the current code."},{"id":"FLAG-004","concern":"Scope creep: the plan keeps eagerly regenerated in finalize/execute/review, but still does not wire into the actual or commands, which are the only consumers named in the idea. That adds maintained artifact surface without implementing the stated on-demand status/audit path.","category":"maintainability","severity_hint":"likely-minor","evidence":"The current CLI commands at only list artifact filenames or dump ; they do not render or . The revised plan's Step 5 still describes handler-side regeneration of , not status/audit integration."}],"verified_flag_ids":["FLAG-001"],"disputed_flag_ids":[]}
Feed the executor finalize.json content (the tasks array) instead of final.md prose.
Remove the instruction to edit final.md checkboxes.
New instruction: "After completing each task, report your work in the execution.json output. Include a task_updates array: each entry has {task_id, status, executor_notes} describing what you did."
Feed the reviewer the updated finalize.json (with executor_notes populated) instead of the edited final.md.
Include sense_checks from finalize.json explicitly.
New instruction: "For each sense-check, provide a verdict. Return a task_verdicts array: [{task_id, reviewer_verdict}] and a sense_check_verdicts array: [{sense_check_id, verdict}]."
Remove all instructions about editing final.md checkboxes or > _verdict:_ lines.
Update schema tests for the new finalize.json, execution.json, and review.json shapes.
Update handler tests to verify the programmatic merge logic (task_updates → finalize.json, verdicts → finalize.json).
Add unit tests for render_final_md().
Test edge cases: executor skips a task, executor adds notes for a task_id not in finalize.json (should warn/ignore), reviewer provides verdict for unknown task_id.
Step 7: Remove dead code
Remove final_plan field from finalize schema (the LLM no longer returns this).
Remove all > _notes:_ / > _verdict:_ references from prompts.
Remove any markdown checkbox parsing logic if it exists outside prompts.
"version": 1,
"timestamp": "2026-03-23T05:25:10Z",
"hash": "sha256:3b82f7af058fbf49e81766c7234f4381d77087687664bc604a403168b3326a8f",
"questions": [
"Should final.md continue to exist as a derived artifact, or should it be dropped entirely in favor of finalize.json? The plan assumes it stays as a human-readable view, but if nothing reads it programmatically, it could be removed to reduce surface area.",
"The execute step currently tells the LLM to edit final.md in-place via file writes. With the new model, the executor no longer edits any tracking artifact \u2014 it just reports task_updates in its JSON output. Is that the intended boundary? Or should the executor still be able to add/modify tasks (e.g., split a task that turned out to be two things)?",
"Should the sense_checks array live inside finalize.json alongside tasks, or should it be a separate section of review.json (since only the reviewer fills it in)? The plan puts it in finalize.json so it's defined at finalize time and filled at review time, paralleling how tasks work.",
"The current review.json criteria array (name, pass, evidence) maps to success_criteria from the plan \u2014 these are separate from per-task verdicts. Should criteria remain as-is (reviewer evaluates success_criteria independently), or should they be merged into the task/sense-check model?"
],
"success_criteria": [
"finalize.json contains a tasks[] array with id, description, depends_on, status, executor_notes, reviewer_verdict fields \u2014 validated by JSON schema",
"The execute handler programmatically merges task_updates from execution.json into finalize.json without LLM involvement",
"The review handler programmatically merges reviewer verdicts from review.json into finalize.json without LLM involvement",
"render_final_md() produces correct markdown from any finalize.json state (pending, partially executed, fully reviewed)",
"No prompt instructs the LLM to edit markdown checkboxes, write > _notes:_ lines, or modify final.md in-place",
"All existing tests pass after adaptation, plus new tests cover the merge logic and render function",
"final.md is always a derived view regenerated from finalize.json \u2014 never the source of truth"
],
"assumptions": [
"final.md continues to exist as a human-readable derived view (not dropped), since status/audit commands and human operators benefit from it",
"sense_checks are defined at finalize time (one per task) and filled at review time, living in finalize.json alongside tasks",
"The existing review.json criteria array (success criteria evaluation) remains unchanged \u2014 it's orthogonal to per-task tracking",
"task IDs are simple strings like 'T1', 'T2' generated by the finalize LLM \u2014 no need for UUIDs or complex ID schemes",
"The executor cannot add new tasks \u2014 only update status/notes for tasks defined at finalize time. Deviations are captured in the existing execution.json deviations field",
"The plan narrative (plan_v*.md) is unchanged \u2014 this refactor only touches the finalize/execute/review tracking layer"
]
}
code
Existing flags:
[]
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.
Refactor the finalize/execute/review artifact model so that the execution-tracking layer (task checklist, watch items, sense-checks) is structured JSON rather than prose markdown. The finalize step produces a rich finalize.json with a tasks[] array (each task has id, description, depends_on, status, executor_notes, reviewer_verdict). The execute handler programmatically updates finalize.json after the worker runs - checking off tasks, populating executor_notes from execution.json data. The review handler programmatically fills in reviewer_verdict fields after the worker runs. A render_final_md() utility generates a human-readable markdown view from finalize.json on demand (for status/audit commands). The plan narrative stays as markdown (plan_v*.md), but the tracking layer is pure structured data that flows through the pipeline mechanically. Remove the LLM-edits-markdown-checklist approach entirely.
User notes and answers:
The critique and revise steps should cross-reference the actual existing artifacts (plan_v*.md structure, execution.json format, review.json format, finalize.json format) to ensure the new structured model captures everything that's already working well. Don't lose information that high-quality plans already contain.
code
Plan:
# Implementation Plan: Structured JSON Tracking Layer for Finalize/Execute/Review
Overview
Replace the LLM-edits-markdown-checklist approach with a structured JSON artifact that flows mechanically through finalize → execute → review. The plan narrative stays markdown; the tracking layer becomes pure data.
Current State
Finalize produces final.md (prose markdown with - [ ] checklist + > _notes:_ lines) and a minimal finalize.json (task_count, watch_items, meta_commentary).
Execute tells the LLM to edit final.md in-place — checking off - [ ] → - [x] and filling > _notes:_. Also produces execution.json (output, files_changed, commands_run, deviations).
Review tells the LLM to read the edited final.md, verify checked-off items, fill in > _verdict:_ lines, and produce review.json.
Problems: Brittle markdown parsing, no machine-readable task state, no structured link between tasks and executor/reviewer feedback.
Feed the executor finalize.json content (the tasks array) instead of final.md prose.
Remove the instruction to edit final.md checkboxes.
New instruction: "After completing each task, report your work in the execution.json output. Include a task_updates array: each entry has {task_id, status, executor_notes} describing what you did."
After writing execution.json, programmatically merge task_updates into finalize.json:
Load finalize.json.
For each entry in task_updates, find the matching task by task_id and update status and executor_notes.
Re-write finalize.json.
Re-generate final.md via render_final_md().
Record the updated finalize.json hash in history (see Step 3d).
3d. Audit trail for finalize.json mutations
After the merge in handle_execute, record the updated finalize.json as an additional artifact in the history entry:
Add "finalize_hash": sha256_file(plan_dir / "finalize.json") to the history entry dict passed to append_history().
Add "finalize.json" to the artifacts list in the StepResponse.
This is a lightweight extension — make_history_entry accepts **kwargs, so adding a field requires no signature change. The audit command already returns the full state (including history), so these hashes are surfaced automatically.
Step 4: Update the review prompt, schema, and handler
Feed the reviewer the updated finalize.json (with executor_notes populated) instead of the edited final.md.
Include sense_checks from finalize.json explicitly.
New instruction: "For each task, provide a reviewer verdict. Return a task_verdicts array: [{task_id, reviewer_verdict}]. For each sense-check, provide a verdict. Return a sense_check_verdicts array: [{sense_check_id, verdict}]."
Remove all instructions about editing final.md checkboxes or > _verdict:_ lines.
Note: The mock review hard-codes task IDs that match the mock finalize output. This is fine — mock workers are a closed system. In real runs, the review LLM reads the actual finalize.json task IDs.
Step 7: Add deep validation for merge inputs
File:megaplan/handlers.py (new helper, used by execute and review handlers)
Address the Codex resume path gap: validate_payload() only checks top-level required keys, so malformed nested arrays could slip through on the Codex resume path (which skips --output-schema).
Add a _validate_merge_inputs() helper called in the execute and review handlers before merging into finalize.json:
python
def _validate_merge_inputs(items: list, required_keys: set[str], label: str) -> list:
"""Validate and filter merge input arrays. Skip malformed entries with a warning."""
valid = []
for item in items:
if not isinstance(item, dict):
continue
missing = required_keys - item.keys()
if missing:
continue # skip malformed entry — logged in deviations or issues
valid.append(item)
return valid
This is defensive filtering at the merge boundary — if the Codex resume path delivers garbage in nested arrays, we skip those entries rather than corrupting finalize.json. The merge itself already tolerates unknown task_ids (no match → no update), so the combination is robust.
test_schemas.py: Update for new finalize.json, execution.json, and review.json shapes.
test_workers.py (lines 48-58, 213-235): Update mock payload assertions to match new structured shapes (tasks array, task_updates, task_verdicts/sense_check_verdicts).
test_megaplan.py (lines 145-177): Update the full workflow test that drives finalize→execute→review through mock workers. Verify that after execute, finalize.json tasks have status "done" and populated executor_notes. Verify that after review, finalize.json tasks have populated reviewer_verdicts and sense_checks have verdicts.
test_prompts.py: Update prompt content assertions — no more _notes:_ or _verdict:_ references.
Add unit tests for render_final_md() covering: all-pending, partially-done, fully-reviewed states.
Add unit tests for _validate_merge_inputs() covering: valid input, malformed entries skipped, empty list.
Step 9: Remove dead code
Remove final_plan field from finalize schema (the LLM no longer returns this).
Remove all > _notes:_ / > _verdict:_ references from prompts.
Remove any markdown checkbox parsing logic if it exists outside prompts.
Update _mock_finalize, _mock_execute, _mock_review to emit new artifact shapes
tests/test_schemas.py
Update for new schemas
tests/test_workers.py
Update mock payload assertions
tests/test_megaplan.py
Update full workflow test, verify programmatic merge results
tests/test_prompts.py
Update prompt content assertions
code
Plan metadata:
{
"version": 2,
"timestamp": "2026-03-23T05:30:46Z",
"hash": "sha256:57154a89e2298e347a32c2d96e81e117cd97bfa87cbdd39da71536adddb04182",
"changes_summary": "Revised plan to address all three significant flags from critique:\n\nFLAG-001 (workers.py omission): Added Step 6 covering _mock_finalize, _mock_execute, and _mock_review updates with exact new payload shapes. Added tests/test_workers.py to the test update scope.\n\nFLAG-002 (shallow validation on Codex resume path): Added Step 7 introducing _validate_merge_inputs() \u2014 a defensive filter applied at the merge boundary in execute and review handlers. Skips malformed nested entries rather than corrupting finalize.json. This addresses the gap where Codex resume bypasses --output-schema and validate_payload() only checks top-level keys.\n\nFLAG-003 (audit trail for finalize.json mutations): Extended Steps 3c/3d and 4c to record finalize_hash in the history entries for both execute and review steps, and include finalize.json in their StepResponse artifacts lists. Uses the existing make_history_entry(**kwargs) pattern \u2014 no signature changes needed. The audit command already surfaces full state including history, so these hashes appear automatically.",
"flags_addressed": [
"FLAG-001",
"FLAG-002",
"FLAG-003"
],
"questions": [
"Should final.md continue to exist as a derived artifact, or should it be dropped entirely in favor of finalize.json? The plan assumes it stays as a human-readable view, but if nothing reads it programmatically, it could be removed to reduce surface area.",
"The execute step currently tells the LLM to edit final.md in-place via file writes. With the new model, the executor no longer edits any tracking artifact \u2014 it just reports task_updates in its JSON output. Is that the intended boundary? Or should the executor still be able to add/modify tasks (e.g., split a task that turned out to be two things)?",
"Should the sense_checks array live inside finalize.json alongside tasks, or should it be a separate section of review.json (since only the reviewer fills it in)? The plan puts it in finalize.json so it's defined at finalize time and filled at review time, paralleling how tasks work.",
"The current review.json criteria array (name, pass, evidence) maps to success_criteria from the plan \u2014 these are separate from per-task verdicts. Should criteria remain as-is (reviewer evaluates success_criteria independently), or should they be merged into the task/sense-check model?"
],
"success_criteria": [
"finalize.json contains a tasks[] array with id, description, depends_on, status, executor_notes, reviewer_verdict fields \u2014 validated by JSON schema",
"The execute handler programmatically merges task_updates from execution.json into finalize.json without LLM involvement",
"The review handler programmatically merges reviewer verdicts from review.json into finalize.json without LLM involvement",
"render_final_md() produces correct markdown from any finalize.json state (pending, partially executed, fully reviewed)",
"No prompt instructs the LLM to edit markdown checkboxes, write lines, or modify final.md in-place",
"All existing tests pass after adaptation, plus new tests cover the merge logic, render function, and validation helper",
"final.md is always a derived view regenerated from finalize.json \u2014 never the source of truth",
"Mock workers in workers.py emit the new artifact shapes and pass validation",
"Execute and review history entries include finalize_hash for audit trail of finalize.json mutations",
"Malformed nested arrays from Codex resume path are filtered before merge \u2014 no corruption of finalize.json"
],
"assumptions": [
"final.md continues to exist as a human-readable derived view (not dropped), since status/audit commands and human operators benefit from it",
"sense_checks are defined at finalize time (one per task) and filled at review time, living in finalize.json alongside tasks",
"The existing review.json criteria array (success criteria evaluation) remains unchanged \u2014 it's orthogonal to per-task tracking",
"task IDs are simple strings like 'T1', 'T2' generated by the finalize LLM \u2014 no need for UUIDs or complex ID schemes",
"The executor cannot add new tasks \u2014 only update status/notes for tasks defined at finalize time. Deviations are captured in the existing execution.json deviations field",
"The plan narrative (plan_v*.md) is unchanged \u2014 this refactor only touches the finalize/execute/review tracking layer",
"make_history_entry accepts **kwargs so finalize_hash can be added without signature changes",
"_validate_merge_inputs silently skips malformed entries rather than raising errors \u2014 this is the right trade-off for robustness since the primary validation path (--output-schema on fresh sessions) still catches errors, and the Codex resume path is the fallback"
],
"delta_from_previous_percent": 30.35
}
code
Existing flags:
[
{
"id": "FLAG-001",
"concern": "The plan omits megaplan/workers.py, but this repo's mock finalize/execute/review workers still emit the old artifact shapes. Without updating them, mock mode and the end-to-end tests will break as soon as finalize.json, execution.json, and review.json change shape.",
"status": "addressed",
"severity": "significant"
},
{
"id": "FLAG-002",
"concern": "The plan assumes the new JSON schemas will protect the structured tracking layer, but that is not true on the Codex resume path. Persistent Codex sessions skip --output-schema, and runtime validation only checks top-level required keys, so malformed nested tasks, task_updates, or verdict arrays could still be accepted and merged into finalize.json.",
"status": "addressed",
"severity": "significant"
},
{
"id": "FLAG-003",
"concern": "The plan adds source-of-truth mutations to finalize.json during execute and review, but leaves the repository's audit trail model unchanged. Today those steps only record hashes for execution.json or review.json, so the updated finalize.json state would not be versioned in history or surfaced by audit as a distinct artifact revision.",
"status": "addressed",
"severity": "significant"
}
]
code
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.
“You are an independent reviewer. Critique the plan against the actual repository.….” Conversation with gpt-5.4, from the Peter O’Mallet DataClaw Conversations dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m80epwn5fbxwfbzq72q6y80g