Sub topic 7
Keeping a Progress File
This chapter assumes you can read Python, JSON, and Markdown, and that you know how an agent calls tools in a loop. It also assumes you have seen the idea of a checkpoint from the previous chapters: a machine-readable snapshot of task state that is written after each step.
A checkpoint tells a program where to restart. It does not tell a person, or a fresh agent, why the work looks the way it does. A progress file fills that gap. It is a short, human-readable document that records the goal, the plan, the status, the decisions made, and the next action.
What a progress file is for
A checkpoint is optimized for code. It holds data such as a list of completed step names, and a script reads it without any interpretation. A progress file is optimized for a reader who has lost context. That reader might be you tomorrow, a new agent session after the context window filled up, or a colleague taking over.
The two files answer different questions.
| Question | Checkpoint | Progress file |
|---|---|---|
| Which steps has the program finished? | Yes, exact | Yes, summarized |
| Why was this approach chosen? | No | Yes |
| What should happen next? | Implied by the step list | Stated in words |
| What is blocked or unclear? | No | Yes |
| Who reads it? | Code | People and agents |
Keep both. The checkpoint is the source of truth for what the program has done. The progress file is the source of truth for intent and reasoning.
The five parts of a progress file
A useful progress file has five parts. Each one prevents a specific kind of confusion on resume.
- Goal. One or two sentences that say what "done" means. State it in a form that can be checked, for example "All pages under docs/ build without warnings."
- Status. A checklist of the plan, with finished items marked. Add counts for partial items, such as "18 of 42 done."
- Decisions. Choices that were made and the reason. Without the reason, a later reader may undo the choice.
- Next action. A single concrete step, specific enough to start without further thought.
- Open problems. Questions that need an answer, and anything that is blocked.
Here is a complete example.
# 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.Notice what the example leaves out. It has no log of every command that was run and no transcript of the conversation. Those belong in a separate log if you need them. A progress file that grows without limit stops being read.
Why the next action must be a single step
The "Next action" section is the part most often written badly. A vague entry such as "continue the migration" forces the reader to rediscover the state of the work, which is exactly the cost the file exists to remove.
A good next action has three properties:
- It names a specific place to start, such as a file or a record.
- It is one action, or a very short sequence with an obvious end.
- It says what to do afterward to confirm success, such as "then run the build."
Compare these two entries.
| Weak | Strong |
|---|---|
| Keep converting pages. | Convert shortcodes in docs/guides/ starting at setup.md, then run the build. |
| Check the export. | Compare the 2023-08 row count with the source database, then export 2023-09. |
Recording decisions with reasons
A decision without a reason is a trap. Suppose the file says "Use redirects." Three sessions later, an agent sees 42 pages with old names and decides to rename them for tidiness. The reason ("keep the old URLs") would have prevented that.
Write each decision in the form choice, then reason. If you rejected an alternative that a reader might reasonably try, record that too:
## Decisions
- Keep the old URLs; add redirects instead of renaming pages. External sites link to them.
- Do not use the bulk-convert tool. It rewrites front matter and loses custom fields.The second entry is valuable because it records a failed attempt. A new reader would otherwise try the same tool and repeat the loss.
When to update the file
Update the progress file at the same moments you save a checkpoint: after each completed step, and before anything risky. If the file is updated only at the end, a crash leaves it describing a state that no longer exists.
A good rule is to update it in this order:
- Finish the step.
- Save the checkpoint.
- Update the progress file.
The checkpoint comes first because it is the record the program trusts. If the process dies between steps 2 and 3, the progress file is slightly behind. That is a recoverable error, and the resume routine can detect it by comparing the two.
The reverse order is worse. If the progress file says a step is done but the checkpoint does not, a reader will trust the document and skip work that never finished.
Generating the file from code
You can keep the progress file in sync by writing it from the same state the checkpoint holds. This removes the risk of the two disagreeing about what is finished. The program writes the status lines and the agent supplies the free-text parts: decisions, next action, and open problems.
The example below renders a progress file from a state dictionary and writes it with the same temporary-file-and-replace pattern used for checkpoints.
import os
import tempfile
PLAN = ["fetch", "transform", "validate", "publish"]
def render_progress(goal, state):
done = set(state.get("completed", []))
lines = ["# Task progress", "", "## Goal", goal, "", "## Status"]
for name in PLAN:
mark = "x" if name in done else " "
lines.append(f"- [{mark}] {name}")
lines += ["", "## Decisions"]
lines += [f"- {d}" for d in state.get("decisions", [])] or ["- None yet."]
lines += ["", "## Next action", state.get("next_action", "Not set."), ""]
lines += ["## Open problems"]
lines += [f"- {p}" for p in state.get("open_problems", [])] or ["- None."]
return "\n".join(lines) + "\n"
def write_progress(path, text):
directory = os.path.dirname(os.path.abspath(path))
fd, tmp_path = tempfile.mkstemp(dir=directory, suffix=".tmp")
try:
with os.fdopen(fd, "w") as f:
f.write(text)
f.flush()
os.fsync(f.fileno())
os.replace(tmp_path, path)
except BaseException:
if os.path.exists(tmp_path):
os.unlink(tmp_path)
raise
if __name__ == "__main__":
state = {
"completed": ["fetch", "transform"],
"decisions": ["Keep source files unchanged; write results to out/."],
"next_action": "Run validate on out/, then publish.",
"open_problems": [],
}
write_progress("progress.md", render_progress("Publish the cleaned dataset.", state))
print(open("progress.md").read())Generating the status section means it cannot drift from the checkpoint. Do not generate the decisions and next action blindly, though. Those need judgment, and a stale value there is worse than an empty one.
Common mistakes
- Writing a diary instead of a state. A progress file describes where things stand now, not everything that happened. Replace old status lines instead of appending to them.
- Leaving the next action stale. After finishing a step, update the next action in the same edit. A next action that points to completed work sends the next reader in a circle.
- Marking unverified work as done. If you did not confirm a result, say so. Add a line such as "Not yet verified: row count for 2023-08."
- Recording facts that can be looked up cheaply. Do not copy file contents into the progress file. Point to the file instead. Copies go out of date.
- Storing secrets. Progress files are plain text and often shared. Never put tokens or passwords in them.
- Letting it grow. If the file passes a page or two, move old detail into an archive file and keep only the current picture.
Where the progress file fits
The progress file is the main input to the resume routine in the next chapters. On restart, the routine loads the checkpoint to decide what to skip, and reads the progress file to recover the goal, the decisions, and the next action. When work moves to another agent or person, the progress file becomes the core of the handoff note, which adds warnings and unverified items on top.
Exercise
A task crashes right after a step finishes. The checkpoint lists the step as completed, but the progress file still shows it as unchecked and the next action points to that same step. What should the resume routine do, and why is the opposite situation (progress file says done, checkpoint does not) more dangerous?
Show answer
The routine should treat the checkpoint as the source of truth for what the program finished, skip the step, and then update the progress file so the status and next action match. The progress file is only slightly behind, which is safe and detectable. In the opposite case, a reader trusting the progress file would skip a step that never completed, so work would be silently lost. This is why the checkpoint is saved before the progress file is updated.
Exercise
Rewrite this progress entry so it is useful to a reader with no context: "Next action: keep going with the export." Assume months 2023-01 to 2023-08 are exported and the 2023-08 row count has not been checked.
Show answer
"Next action: Compare the row count of the 2023-08 export in out/ with the source database. If they match, export 2023-09." This names a specific place to start, is a single action, and says what to do after it succeeds. It also surfaces the unverified item instead of hiding it.