Sub topic 7
Keeping a progress file
This chapter assumes you can read Markdown and write Python that handles files. It also assumes you know what a checkpoint is: machine state saved after each step.
Why a second file
A checkpoint tells code which steps finished. It does not say what the goal is, why you chose an approach, or what to do next. A progress file is a Markdown document that records those things. An agent that restarts with an empty context window can read it in seconds. A person can read it too.
| Row | Checkpoint | Progress file |
|---|---|---|
| Format | JSON | Markdown |
| Reader | Your code | Agent or person |
| Holds | Completed steps, data | Goal, decisions, next action |
| Trusted for | What ran | Why and what next |
What goes in it
Use the same five sections every time, so a reader always knows where to look.
# Task: Migrate docs to the new site generator
## Goal
All pages under docs/ build without warnings in the new generator.
## Status
- [x] Inventory existing pages (42 found)
- [x] Convert front matter
- [ ] Convert shortcodes (18 of 42 done)
- [ ] Fix broken links
## Decisions
- Keep the old URLs; add redirects instead of renaming pages.
## Next action
Convert shortcodes in docs/guides/ starting at setup.md, then run the build.
## Open problems
- The gallery page uses a shortcode with no equivalent. Needs a decision.Rules that keep it useful
- Update it after every step, not at the end. A file written only at the end is missing when a crash happens.
- Give exactly one next action. A list of options forces the next reader to choose again.
- Record each decision with its reason. Without the reason, a later agent may undo it.
- Write measurable facts ("18 of 42 done"), not impressions ("mostly done").
- Keep it short. Move old detail to an archive file so the live file stays readable.
Updating it from code
The function below ticks one checklist item and replaces the line under ## Next action. It writes through a temporary file so a crash cannot leave half a progress file.
import os
import tempfile
def mark_done(path, item, next_action):
with open(path) as f:
lines = f.read().splitlines()
out = []
found = False
in_next = False
for line in lines:
if line.strip() == f"- [ ] {item}":
line = f"- [x] {item}"
found = True
elif line.startswith("## "):
in_next = line.strip() == "## Next action"
elif in_next and line.strip():
line = next_action
in_next = False
out.append(line)
if not found:
raise ValueError(f"No open item named {item!r}")
directory = os.path.dirname(os.path.abspath(path))
fd, tmp_path = tempfile.mkstemp(dir=directory, suffix=".tmp")
with os.fdopen(fd, "w") as f:
f.write("\n".join(out) + "\n")
os.replace(tmp_path, path)Order of writes
Save the checkpoint first, then the progress file. A crash between the two leaves the progress file one step behind. That is safe, because the resume routine treats the checkpoint as the record of what ran. If you reversed the order, the progress file could claim a step finished that never did.
Common mistakes
- Treating the progress file as proof. It is a claim written by a past session, so check it against reality before acting (a later chapter covers this).
- Letting "Next action" go stale after a step finishes.
- Burying decisions in a long narrative where nobody finds them.
Exercise
A job crashes after saving its checkpoint but before updating progress.md. On restart, which file shows the true state of finished steps, and what is wrong with the other one?
Show answer
The checkpoint shows the true state. progress.md is one step behind: it lists the last step as unfinished and its Next action is stale. The resume routine should trust the checkpoint, then bring progress.md up to date.