Release Dependent Tasks Only after Their Prerequisites Finish

Release dependent tasks only after prerequisites finish, distinguish ready work from completed work, and inspect blocked cycles with a controlled dependency graph.

How can an orchestrator distinguish a task that is ready to be handed out from a predecessor actually completed before releasing dependent work?

Substantively revised October 21, 2026. Author interpretation, documented cases and hypothetical examples are distinguished below.

An empty ready queue can describe unfinished work. Two predecessor tasks have already been handed out, neither has reported completion, and the dependent task remains blocked. Treating that temporary emptiness as completion would end the workflow precisely when the dependency information is still doing useful work.

Direct answer

For a fixed dependency graph, distinguish nodes ready to be handed out from nodes the caller has acknowledged as processed. In Python graphlib, obtain ready nodes, process them under the application's own rules, and call done only when the corresponding completion condition is satisfied. Recheck newly ready nodes afterward. Track unresolved nodes and cycle errors separately from an empty ready batch or inactive sorter. The experiment below checks state transitions only; it executes no jobs and does not verify that an external worker really completed its task.

Key takeaways

Readiness is permission to begin under the declared graph. It is not proof of completion. A downstream node must wait for the relevant predecessor acknowledgments rather than merely for those predecessors to appear in an earlier ready batch.

A temporary absence of newly ready work can coexist with outstanding work. The caller may need to wait for an already issued task rather than terminate the process. Distinguishing these states avoids making the ready queue carry a completion meaning it does not contain.

A cycle changes the interpretation of stopping. An inactive sorter with a reported cycle can leave nodes unprocessed after independent work has finished. A successful exit condition therefore needs to account for unresolved nodes and errors, not merely observe that no more progress is currently available.

Definitions and relationships

A predecessor is a node that must be processed before a dependent node can be released under the declared dependency relation. A directed acyclic graph permits a complete topological ordering. A directed cycle contains mutually blocking dependency paths that prevent a complete ordering of the affected nodes.

A ready batch contains nodes whose declared predecessor conditions permit them to be handed out. An issued node is a node already returned to the caller for processing. A completion acknowledgment is the caller's statement that an issued node should now count as processed for dependency release.

These are separate roles in the orchestration state. A graph describes precedence constraints; an executor performs actual work. The sorter does not inspect a generated file, a worker's exit status or the quality of a result merely because the caller marks a node done.

The problem: one queue is asked to describe three states

Consider a hypothetical local workflow that prepares an input, transforms it in two different ways, and combines the transformed outputs. An independent housekeeping task can run without those prerequisites. The program wants to hand out every currently eligible node without starting the combine step too early.

A single list called pending is insufficiently precise if it mixes tasks not yet eligible, tasks eligible but not issued, and tasks already running. Removing the preparation task from that list does not establish that its output exists. An empty eligible list also says nothing by itself about whether issued work is still in flight.

The practical question is which state transition releases dependent work. If the transition is task dispatch rather than acknowledged processing, downstream work can observe missing or partial results. If the transition is never recorded, downstream work can remain blocked despite completed predecessors. The implementation must make that boundary explicit.

Root cause: a precedence relation is confused with an execution trace

A topological order can show a legal ordering of nodes in a fixed graph. It does not itself run the tasks or confirm their results. Listing preparation before transformation is a statement about precedence; it is not evidence that preparation completed successfully before transformation began in a separate execution system.

The confusion becomes more consequential when several nodes can be ready together. After both transformation tasks are handed out, the ready batch may be empty while the system waits for either task to finish. An implementation that treats the empty batch as a complete traversal erases the distinction between waiting and finishing.

The repair is to preserve both the graph and the lifecycle information required by the caller. Record which nodes were issued, which were acknowledged and which remain unresolved. Use the sorter to enforce declared prerequisites, while keeping the application's success condition and failure handling outside that narrow data structure contract.

Framework: the Ready-to-Done Boundary

The Ready-to-Done Boundary is the author's proposed inspection method for a fixed dependency workflow. Its components are Predecessor Meaning, Issued Set, Acknowledgment Rule and Unresolved Exit. It makes the release decision inspectable without pretending to implement a complete scheduler, retry system or resource optimizer.

Predecessor Meaning states which nodes must precede another node and why. In the experiment, the graph maps each node to its predecessors. Do not reverse that direction accidentally: a list of prerequisites for a node is different from a list of tasks that should follow it.

Issued Set distinguishes nodes handed out from nodes merely present in the graph. The experiment verifies that getting a ready batch does not return the same batch again on the next call. That absence is a handoff state, not an acknowledgment that those nodes have finished.

Acknowledgment Rule defines when the caller can mark an issued node processed. The graph library checks aspects of the call sequence, but the application remains responsible for the substantive condition. For a real transformation, that might involve validating a result before acknowledging completion; no such transformation is executed in this study.

Unresolved Exit compares stopping conditions with the nodes actually accounted for. A graph with a cycle can stop making progress while leaving nodes unresolved. Preserve the error and the unresolved set so that the caller does not present blocked work as a successful complete run.

Framework example and application

For a diamond graph, let A precede both B and C, and let D depend on both B and C. Let E be independent. The first ready set can contain A and E. Acknowledging E does not release B or C because their prerequisite is A, not any completed node.

Apply the method by tracing acknowledgments separately from ready batches. After A is acknowledged, B and C become available. After only B is acknowledged, D remains blocked. This trace explains which transition matters and prevents a vague rule such as proceed when something finishes from replacing the actual predecessor relation.

Three documented mechanisms

Example 1: graphlib exposes readiness and acknowledgment separately

The Python graphlib documentation defines a predecessor mapping and separate prepare, get_ready and done operations. It also describes a CycleError while allowing retrieval of work that remains unblocked. These API distinctions support an explicit readiness-and-acknowledgment protocol rather than equating a ready node with a completed job. [S1]

The operational implication is to inspect the caller's use of that protocol. A node can have satisfied graph prerequisites while still awaiting its own execution. Conversely, a caller can misreport completion. The API's graph bookkeeping does not evaluate the work product that an application associates with the node.

Example 2: CPython tracks handed-out and finished nodes distinctly

The inspected CPython 3.11 branch implementation maintains separate bookkeeping for nodes handed out and nodes marked finished. Its done validation distinguishes unknown nodes, nodes not yet handed out and nodes already marked done. That implementation helps explain the state differences tested below. The linked branch is mutable and is not presented as an exact source snapshot of the installed Python 3.11.9 runtime. [S2]

This source inspection is evidence about implementation structure, while the local script supplies evidence about the installed runtime's observed behavior. Keep those roles distinct. Reading a branch file does not replace executing the pinned environment, and using its public API does not require treating private counters as an application interface.

Example 3: the release history limits older recipe assumptions

Python's historical 3.9 release notes identify graphlib and TopologicalSorter as additions in that release. The historical record establishes when the standard-library facility appeared; it is not advice to deploy unsupported Python 3.9. The executed experiment uses Python 3.11.9, and the versioned documentation currently identifies its own later patch version. [S3]

This matters when choosing supporting material. A programming book published before graphlib existed can offer useful design background but cannot document that later API as a contemporary recipe. Keep the source of current operation behavior separate from older general software design recommendations.

Case study: a diamond and an independent task

This is an executed local study using invented node labels. No task bodies, worker threads, build processes or external services ran. Python 3.11.9 processed a fixed five-node graph: A had no predecessors; B and C each depended on A; D depended on B and C; E was independent.

After prepare, the initial ready set contained A and E. A second get_ready call returned an empty tuple because those nodes had already been handed out. The sorter remained active. That combination is the first useful observation: empty newly ready work did not mean every issued node had been acknowledged.

The script acknowledged E first. No diamond successor became ready, and A remained outstanding. It then acknowledged A, after which the next ready set contained B and C. The experiment compares these batches as sets where sibling order is irrelevant, rather than inventing a general alphabetical or performance priority for independent nodes.

Completing one branch is insufficient

The script acknowledged B while C remained outstanding. The next ready batch was empty and the sorter remained active. D was still blocked, which matched the declared requirement that both B and C precede it. Counting one completed branch would have supplied the wrong release rule for this graph.

After C was acknowledged, the next batch contained D. Handing out D did not immediately make the sorter inactive because D itself had not yet been acknowledged. Once the script marked D done, the finite acyclic graph became inactive and no additional ready nodes remained.

This sequence separates three questions that can otherwise collapse into one. Was a node eligible to be issued? Has it already been issued? Has the caller acknowledged it? The script's results demonstrate their separate bookkeeping roles without claiming that any corresponding data processing operation actually succeeded.

Invalid call controls

The study tested ready retrieval and done before prepare, adding a node after prepare, and marking dependent D done before it had been handed out. Each invalid call was rejected with ValueError. After the finite graph completed, duplicate acknowledgment of D and acknowledgment of an unknown node were also rejected.

These checks establish specific lifecycle protections in the demonstrated runtime. They do not make a caller's valid done call truthful about external work. A program can call done at a procedurally valid moment while its real task has failed; detecting that situation belongs to the application and its completion rule.

The negative controls are useful because a happy-path topological list would not exercise those distinctions. A graph can produce a legal static ordering even when the surrounding executor misunderstands readiness. The tests need to challenge the handoff boundary directly when that boundary is the subject of the claim.

Cycle control: inactive but unresolved

A separate three-node graph contained X depending on Y, Y depending on X and independent Z. Prepare raised CycleError. The script retained that failure and still obtained Z as ready work, then acknowledged Z. The remaining ready batch was empty, and the sorter was inactive.

X and Y remained unprocessed. The stopping state therefore differed from the completed five-node acyclic example even though both ended inactive with no ready nodes. The retained cycle error and unresolved set supplied the missing interpretation: no more progress was available under the fixed graph, rather than every intended node having completed.

All 25 assertions passed. A separate static-order check included all five acyclic nodes once and confirmed that every predecessor preceded its dependent. That check establishes the precedence property of the returned order; it does not prove one universal sibling order, execution success or minimum elapsed completion time.

Failure example: an empty batch is treated as a finish signal

After B was acknowledged and C remained outstanding, no new node could be issued. A loop that terminated simply because get_ready returned an empty tuple would abandon the workflow before D could be released. It would confuse waiting for a valid predecessor acknowledgment with having nothing left to do.

The cycle example shows why replacing that rule with stop when inactive is still incomplete as a success condition. Inactivity can describe blocked progress after the available acyclic work has been processed. The program must preserve the earlier cycle error and account for unresolved nodes instead of interpreting a lack of activity as universal completion.

The repair is to make the exit claim match the observed state. Completed, waiting and blocked are different outcomes. A product can expose them differently, but it should not erase the distinction merely because all three can involve an empty ready list at some moment.

Common mistakes in dependency orchestration

One mistake is reversing predecessor and successor relationships. If a node's configured list means work that must happen first, entering tasks that should happen afterward creates a different graph. Write one concrete relation in words and check it against a small trace before importing a large workflow.

Another mistake is marking a node done immediately after dispatch. That may be correct only if dispatch itself is the entire declared task. When the node represents a longer operation, acknowledging it at dispatch releases its dependents before the intended completion condition has occurred.

A third mistake is interpreting sibling order as a priority policy. Two nodes can satisfy their predecessor conditions at the same stage without the graph specifying which deserves a worker first. If resources are limited, selection among eligible tasks is an additional decision requiring its own explicit rule.

Finally, avoid assuming the graph can be edited freely after preparation in this tested API version. The script checks that an attempted addition is rejected. A product needing dynamic dependency changes must implement and evaluate an appropriate process rather than smuggling that capability into a fixed-graph example.

Counterargument: is a static order enough?

For a small sequence run synchronously, a static topological order can be sufficient to determine a legal precedence sequence. The application can execute one task, validate its result and then move to the next. There is no need to pretend every workflow requires concurrent scheduling or a complex state monitor.

The tradeoff changes when several tasks are issued before they finish or when a process must distinguish waiting from blocked progress. A single list does not describe those in-flight transitions. The ready-and-done protocol supplies a narrower interface for handling them, while the application remains responsible for actual execution and its success condition.

Choose the simpler approach that fits the real task, and state what it proves. A static ordering is not a throughput optimization study. A ready-batch trace is not a guarantee of worker fairness. A useful design keeps those claims separate rather than borrowing authority from the mathematical language of graphs.

Action plan: trace a dependent release

Choose a small authorized workflow and write each node's actual prerequisites. Include a node with two predecessors and an independent node. Use meaningful task descriptions in your working notes, but retain short labels in the trace so that each release decision can be inspected without rereading an operational narrative.

Record the initial ready set and the issued nodes. Acknowledge an independent node first and check that unrelated dependent work stays blocked. Then acknowledge only one branch of a two-predecessor dependency and verify that the downstream node does not become ready until the other required acknowledgment occurs.

Test an invalid early acknowledgment, a duplicate acknowledgment and a small separate cycle. Preserve the observed error and unresolved nodes. These controls distinguish correct precedence bookkeeping from a program that merely happens to list the right labels under one unchallenging successful run.

Before connecting real workers, define what allows the caller to report done. Decide how it will handle an operation that fails, produces an invalid result or never reports back. Those behaviors were not executed here. Treat them as additional implementation work instead of claiming that a passing graph fixture already solves them.

FAQ: ready, issued and finished work

Does a ready node mean its task has finished?

No. It means the node can be handed out under the declared predecessor conditions. The experiment executes no task bodies. A caller must apply its own processing and completion rule before treating the issued node as processed for dependent release.

Why can get_ready return nothing while work remains?

The caller may already hold nodes that have been handed out but not acknowledged. In the diamond fixture, C remains outstanding after B is marked done, so D cannot yet be issued. The empty new batch does not erase the outstanding node.

Does marking B done release D immediately?

Not in the demonstrated graph because D also depends on C. The study checks that D remains blocked after B alone and becomes ready after C is acknowledged too. The release decision follows the complete declared predecessor relation, not merely the fact that something finished.

What does done prove about an external result?

By itself, it proves no substantive property of an external result. It is a caller acknowledgment used for graph bookkeeping. The experiment demonstrates valid and invalid call sequences, while actual task success, output validation and safe release conditions belong to the surrounding application.

Is inactive the same as successfully complete?

No. The cycle control becomes inactive after its independent node is processed while X and Y remain unresolved. Preserve the cycle error and account for all intended nodes before labeling the workflow complete. A lack of further progress can describe blockage rather than success.

Can useful work remain after CycleError?

The separate fixture permits independent Z to be obtained and acknowledged despite a cycle between X and Y. That demonstrates one unblocked portion of a graph. It does not repair the cycle or establish that every possible node outside a reported cycle will be available regardless of its own prerequisites.

Can the same ready batch be retrieved repeatedly?

The demonstrated immediate second call returns an empty tuple after the first batch has been handed out. Track issued nodes in the caller's workflow instead of expecting repeated retrieval to act as a list of running tasks. The next release depends on subsequent state transitions.

Are sibling tasks ranked by business importance?

The dependency relation does not define that business policy. Two nodes may become eligible together. A separate priority rule can choose among eligible work when resources are constrained, but the study does not implement such a resource scheduler or claim an optimal choice.

Why are some ready batches compared as sets?

The acceptance question is which nodes satisfy the prerequisites at that point. A and E are independent, as are B and C after A. Comparing those memberships avoids turning the particular insertion-dependent sibling order into an unsupported universal ordering requirement.

Can I add nodes after prepare?

The tested Python 3.11.9 behavior rejects that operation, and the study treats the graph as fixed. A system needing new dependencies during execution requires a deliberate design for that requirement. This fixture does not demonstrate dynamic graph mutation or migration between graph versions.

Does a static topological order execute the graph?

No. It supplies an ordering of nodes satisfying the tested precedence constraints. The study separately confirms every predecessor appears before its dependent. Running, validating and reporting the real work are additional operations that a list of labels cannot perform by itself.

Were concurrent workers tested?

No threads or worker processes were used. The script makes sequential API calls to inspect state transitions. Its results do not establish synchronization safety, worker fairness, resource allocation, retries or recovery from a worker that never acknowledges an issued task.

Why cite an old Python release note?

It establishes graphlib's historical introduction in Python 3.9 and helps distinguish older general recipes from documentation of the later facility. It is not a recommendation to deploy the unsupported 3.9 series. The actual experiment and its recorded runtime are separate evidence.

Does rejecting duplicate done prevent all orchestration bugs?

No. It catches the demonstrated invalid acknowledgment sequence. The caller can still misunderstand what its task means or acknowledge an invalid external result once. Procedural validation is useful but does not replace an application-specific completion definition and tests of actual execution failures.

What is the minimum useful exit record?

Record whether all intended nodes were accounted for, which issued work remains outstanding, whether a cycle or another error occurred and which nodes remain unresolved. The exact product format can vary. Preserve enough state to distinguish completion, waiting and blocked progress without inferring success from emptiness alone.

Recommended books

Python Cookbook, third edition, by David Beazley and Brian K. Jones, published by O'Reilly in May 2013, provides general Python implementation background. It predates graphlib's introduction and is not cited as an API guide to TopologicalSorter. Current operation claims come from versioned documentation, source inspection and the actual experiment.

A Philosophy of Software Design, second edition, by John Ousterhout, released in July 2021, is useful background for deciding which lifecycle details an interface should expose. The author's official metadata verifies the edition and date. That recommendation does not claim the book supplies this experiment or proves any scheduler property.

The Pragmatic Programmer, twentieth anniversary edition, by David Thomas and Andrew Hunt, published in September 2019, offers broader software engineering context. Use it to support deliberate implementation practice, while keeping the source of each current API claim explicit. The book recommendations rely on verified official records, not a full-book reading claim.

Further exploration

Compare this fixed dependency protocol with a priority queue. Dependencies establish which work can be released under prerequisites; a priority rule chooses among work already eligible. Combining those functions requires an intentional boundary so that a high priority cannot be mistaken for permission to bypass unfinished prerequisites.

Also compare task acknowledgment with artifact invalidation in a build system. Both use relationships, but they answer different questions. This study observes whether the caller has acknowledged fixed graph nodes; it does not inspect file timestamps, rebuild stale outputs or validate the content of generated artifacts.

The next useful experiment is the completion rule your real executor will apply. Introduce a task failure or invalid result and verify that dependents are handled according to an explicit policy. Keep that evaluation separate from the passing graph trace until the actual execution behavior has been implemented and observed.

Primary evidence sources

Related concepts: systems thinking, wealth structure, and the survival loop. Read the editorial policy and citation guide.