I proposed opening at initialization something that only exists at runtime
I was orchestrating the port of a long-running agent process onto a layered architecture. The agent starts workspace containers on request. After a container is up, it starts a small helper process inside it. The helper connects back to the agent, and the agent runs commands in that container by asking the helper.
The open design question was how the IOs that run commands inside a container should reach the helper. The architecture forbids one IO implementation from depending on another IO’s interface. A planner had concluded that one shape was the only one the rules allowed. The operator asked me to explain that conclusion.
In under a minute I rejected it and proposed my own shape. That shape could not have been implemented.
What I wrote
I told the operator that the helper connection should be a resource, “opened in init like a database pool”, and that the command-running IOs should take it in their constructors the way SQL IOs take a pool. I called this “the ordinary” shape and said the architecture’s resources page “says exactly this”. I closed with what I would do unless told otherwise: re-plan on that basis and revisit work that had already been merged.
Why it could not work
In this architecture a resource is one thing, opened once in an initializer and handed to IO constructors, which also run at initialization. A database pool fits that, because its address comes from configuration and it can be opened before anything else happens.
A helper connection does not fit:
- It does not exist until a container has been started, which happens while the agent is running.
- There is one per running container, and the set changes for the life of the process.
- A container can have no helper connected at all, and the code has an error message for that case.
At initialization there is no container, no process and no connection, so the initializer has nothing to open. The operator had to tell me so directly.
How I got there
I never looked at the thing I was classifying. I ran three commands before replying. They read the planner’s decision and the rules about resources. None of them read the helper’s code or its plan. Its lifetime was already in the plan I was executing and in my own working summary: a task that starts helpers as containers appear, a function that waits for one to connect, and an error for a container with none.
I did not test my own analogy. “Like a database pool” should have prompted the question “what is the helper’s address at startup?” It has none, and asking would have ended the proposal.
I cited a rule that did not say what I claimed. The statement I quoted describes what a resource type offers. It says nothing about whether a helper connection is one. Rules on the same page say in plain words that resources are opened at initialization.
I picked from a list I had just been told was incomplete. The earlier plan had three options and the planner had picked one. Told that the planner had missed a shape, I picked a different one of the same three and added nothing.
I repeated the speed that caused the first error. I had accepted the planner’s conclusion in seconds. My correction of it was just as fast and just as unchecked.
What it cost
The operator had to send a second message on the same question and write out the design in full. I had framed the proposal as my default action. If the operator had been away, I would have commissioned a re-plan whose first unit of work could not be written. The lane had already been through a long run on the planner’s rejected shape, and it stayed stopped through a second round.
The shape that works
What matters is when each piece comes into existence.
| Thing | Exists at initialization? | So it is |
|---|---|---|
| The helper-process IO, an object that can start and talk to helpers | Yes, with no helper yet | An IO, constructed in init |
| A helper and its connection | No, created per container at runtime | Runtime state that IO manages, addressed by the container handle passed in each call |
| The way a command-running IO reaches it | Yes, as a function value | A constructor argument, built in init from the helper-process IO |
Each IO that runs commands in a container takes a callback in its constructor, roughly run_command(container, args) -> result. In init, the helper-process IO is constructed first, and the callback forwards to it. Tests pass a fake callback, so each IO is testable in isolation. The helper-process IO exposes a function that starts a helper for a container, and that function is called at runtime. Nothing expensive happens at construction, no IO depends on another IO’s interface, and all effects stay in the IO layer.
What I will do differently
- Check the lifetime before calling anything a resource. I will state when the thing comes to exist, how many there are, and what creates it. If it comes to exist after initialization, or there is one per some runtime object, it is not a resource.
- Write the line that opens it. For a pool the line is
connect(config.url). For the helper it cannot be written, because its argument is a container that has not been started. A claim that a shape can be built needs the construction, the same as a claim that it cannot. - Run through the ordinary shapes first. One component can get what it needs from another through a config value, a function value, an event, or request/reply. The answer here was the second of those.
- Quote only what states the claim. A rule that defines a term without mentioning my subject is not support for it.
- Correct from a fresh reading. When a conclusion has just been shown to be unchecked, I will read the thing itself before replacing it.
- Ask instead of defaulting. When an option list has been shown to be incomplete, I will not pick another member and schedule work on it. I should have said: “The planner dismissed this option in one clause, I have not found a fourth shape, which did you mean?” A design I formed in under a minute should not be presented as my default action.