Module Contract Lab: INPUT → PROCESS → CHECKPOINT → RETURN
The third lab turns a group from a visual frame into an engineering module. We will build a small branch using only core ComfyUI nodes and explicitly define its input contract, responsibility, checkpoint and return point.
Learn to see responsibility boundaries
One of the main sources of chaos in a large workflow is not knowing where one responsibility ends and the next begins. LAB 03 forces that boundary to become explicit on the canvas.
After the exercise, you should be able to take any Hansen branch and state what it receives, what it does, where its result is verified, and what it officially returns to the Master Workflow.
A minimal IMAGE module without models
- Keep LoadImage outside MODULE_01_INVERT: it is the upstream / Master Input.
- Place ImageInvert inside the MODULE_01_INVERT group.
- Place the first PreviewImage inside the group and label it CHECKPOINT · MODULE RESULT.
- Keep the second PreviewImage outside and label it MASTER DOWNSTREAM / OUTPUT.
- Connect the single IMAGE output of ImageInvert to both the local checkpoint and downstream output.
Write the contract before you run the graph
Why this is a contract
The module must not hide dependencies on prompt, model, seed or mask. Its only external dependency in this lab is IMAGE.
| Field | LAB 03 |
|---|---|
| Required input | IMAGE |
| Source | MASTER INPUT · LoadImage |
| Dimensions | Inherited from the source image |
| Batch | Passed with the IMAGE tensor |
| Coordinate space | Same canvas as the input IMAGE |
| Optional inputs | None |
State the task in one line
MODULE_01_INVERT has one responsibility: receive IMAGE and return an inverted IMAGE. Nothing more. It does not load the file, save the delivery result, choose a route or control other groups.
If a module description requires a long sentence containing several independent tasks, the boundary is probably poorly drawn.
A checkpoint proves the module before downstream
Run the workflow and inspect only the LOCAL CHECKPOINT first. Do not judge MASTER OUTPUT until the local result is proven.
This simple rule saves hours later in PPL, masks and main FLUX: a local branch should be able to prove its own result independently of whatever happens after return.
Return is a boundary, not necessarily a dedicated node
In LAB 03, the return point is the IMAGE link that crosses the right boundary of MODULE_01_INVERT and continues to MASTER OUTPUT. A separate Return node is not required; what matters is an unambiguous interface.
In a large production graph, return points are worth marking with a reroute/label/note, especially if the module may later be extracted as a standalone JSON.
| Return field | LAB 03 |
|---|---|
| Type | IMAGE |
| Meaning | Processed module result |
| Canvas | Same logical image canvas as input |
| Downstream assumption | The consumer should not need to know the module’s internal implementation |
Replacement test: the module should be replaceable
Create a second group, MODULE_02_PASS_THROUGH. Its job is to return the original IMAGE unchanged. Then place a selector after the two module outputs and switch between MODULE_01_INVERT and MODULE_02_PASS_THROUGH.
If downstream continues to receive the same IMAGE contract, the modules are interface-compatible even though their internal behavior is completely different.
Use the same questions on any Hansen branch
| LAB 03 question | Production branch example |
|---|---|
| INPUT CONTRACT? | BASE IMAGE / MASK / MODEL / prompt / controls |
| ONE RESPONSIBILITY? | For example Generate Person or Segment Person |
| LOCAL CHECKPOINT? | raw generation / bbox / mask / clean cutout / composite |
| RETURN CONTRACT? | IMAGE / MASK / LATENT returned downstream |
| HIDDEN DEPENDENCIES? | shared seed, size, selector, loader, prompt fragment |
LAB 03 is complete when you can design a module before choosing nodes
- You write the responsibility and contracts before selecting nodes.
- You distinguish a local checkpoint from the final Master output.
- You can point to the exact return point on the canvas.
- You can identify incoming links that cross the module boundary.
- You understand why two very different modules can be interchangeable when they share the same contract.
- You can explain why a hidden dependency breaks standalone extraction.
After the first three labs
LAB 01 teaches route selection; LAB 02 teaches centralized group control; LAB 03 teaches module boundaries. Together they provide the minimum practical foundation for reading the Hansen production graph.