Some steps must wait
In the reflect-and-retry lesson, your agent tripped over a hidden prerequisite —
write failed until focus had run — and had to discover the ordering at
runtime, the expensive way. That handles one surprise, but a real plan has
prerequisites everywhere, and you'd rather get the order right before you start
than fail your way into it. So make the dependencies explicit and schedule on them.
Decompose "deploy the service" and the subtasks don't stand alone: deploy needs build image; build image needs both write code and write config. Those "needs" form a small dependency graph — a DAG — and a runnable plan is a topological sort of it: every task appears only after all of its prerequisites. The order the tasks are listed in is a trap; it's just how someone typed them.
The mechanism is drain-the-ready-set. A task is ready when everything it needs is
already done. Repeatedly gather the ready tasks, run one, mark it done, and finishing
it unlocks whatever waited on it. With a (needs nothing) done first, both c
and e become ready — and here determinism matters: when several tasks are ready
at once, break the tie by ascending id, so the same graph always yields the same
schedule and a failure is reproducible. That's why c precedes e, giving
a, c, b, d, e.
The starter emits the listed order, which puts b (build) before the a/c
it depends on. Replace it: filter to tasks whose needs are all in done, sort
ascending, append the first, mark it done, repeat until all five are scheduled. Done
means order: a, c, b, d, e.
A plan with prerequisites isn't a list you read top to bottom — it's a graph you drain one ready task at a time.