My code stopped work and didn't say why, or gave the wrong reason
This post is about a mistake I made over and over in an orchestration system I work on. I wrote code that decided to stop work: keep a workspace around, halt a merge, refuse to start a task, put an item on hold, or settle an outcome. Then it either reported nothing or reported a reason that sent the operator the wrong way.
None of these decisions crashed anything. Each was a quiet early return. Because nothing failed loudly, the operators found the stalls by their effects, sometimes days later, by digging through command histories, agent logs and disk usage. When they did find a reason string, it often named a symptom, so the fix went after the symptom.
What I did wrong
Here are the cases, with internal details removed.
- A retry loop nobody could see. An operation that timed out was retried every few minutes. The task’s status, the project’s status and the alerts said nothing about it. The only record was in the machine’s shell history.
- “In progress” that wasn’t. Items sat in a “landing” state for two days with nothing actually running. Worse, the status page made them look busy.
- A true but useless message. A waiting item showed “no workspace holds it.” That was accurate, but it didn’t say why or what would change it. The real cause was a workspace kept elsewhere, and the message never pointed there.
- A decision logged only at debug level. When the system decided to keep a workspace, it logged the decision at debug level, reused the message from a different keep reason, and wrote nothing to the workspace’s own record. The workspace showed up in reports with no reason for being kept.
- One message for several causes. A single check could fail for different reasons, but I wrote one message for all of them. It told readers to compare commits when the real problem was a modified tracked file. That wrong message repeated in the logs for two days.
- Naming the symptom instead of the cause. An interrupted rebase was reported as “uncommitted changes.” That’s true at the file level but wrong as a diagnosis. People cleaned up changes that weren’t the problem.
- Skipping without a word. The settlement step quietly passed over a nested repository when it, or its parent, was off the expected branch.
- Every ending looked the same. A session that stopped because a dependency was open, one that stopped because it needed a human, one that finished successfully and one that failed partway through all ended without a cause. The only way to tell them apart was to inspect a file’s state afterwards.
- A hold that read as a failure. A deliberate hold, which waits on the operator by design, looked exactly like an error.
- Documentation that promised more than the code did. A comment promised a retry “at every scan until the reading settles,” and the code didn’t do it. A stale deadline reason was also shown as the first thing on the page.
Why it happened
Each time, I treated the decision to stop as the end of my job. I’d write the return, continue or “keep” branch and assume the log line, if there was one, counted as communication. It doesn’t. Operators read the object they care about: the workspace, the task or the event stream. A debug log isn’t on that list.
When I did write a reason, I usually described the step the code was on when it stopped (“no workspace”, “uncommitted changes”) and not what the code had actually found. Those are different things, and only the second one tells someone what to do.
What I should have done, and what I’m doing now
- Write the reason where the operator looks. If code stalls or throws away work, the reason goes on the workspace’s record, the task’s report or the scheduler’s events. Logs are extra, never a replacement.
- Name the cause and what clears it. “Kept because a rebase is in progress; finish or abort it to release” is a reason. “Uncommitted changes” isn’t. If one check can fail for several causes, each cause gets its own message.
- Give every lasting state a visible form. States like landing, held, kept and placing need their own representation for each step and each stop. Holds must look different from failures. I’m adding a check that every stop state the code can produce has a visual form, so nothing falls back to a generic “busy” look.
- Test what the comments promise. If a comment promises a retry, a limit or a resend, a test has to exercise it. If the test can’t be written, the comment is wrong and comes out.
- Make sessions end with a cause. Each way a session can end (blocked, needs a human, done, failed) carries its own explicit cause, so nobody has to guess from leftover state.
A checklist for reviewing my code (and yours)
For every new early return, continue, keep or refusal in a diff, ask: where does the operator read why this happened?
- If the answer is “a log line,” it isn’t reported.
- If the answer is “a reason string shared with another cause,” it isn’t reported.
- If the answer is “they’ll notice when it doesn’t finish,” it definitely isn’t reported.
Quietly stopping work is a feature with no user interface. I shipped several of those. From now on, every stop gets a clear reason with the right cause, shown where people actually look.