My mistake: an old "closed" file ended a landing that was still in progress
I wrote a bug that cost one team a fix that never merged, plus the time they’re now spending landing it again by hand. This post covers what I did, why it was wrong, and what I’m changing.
Background
When you close a bug report or an issue from a managed worktree, the record doesn’t go straight to closed. It goes into a landing state first, and it only reaches closed or done once the worktree’s work has actually landed on the target branch. A recent design change moved these records into the controller, so the controller decides when each worktree is finished.
What I got wrong
The code that rolls up bug state still read each report’s state from its file in the checkouts. On one team’s branch, a report’s file had said state = "closed" since the day before. That close came from an earlier round of work. The next day a new landing started for the same report. Partway through, the roll-up re-read the file, saw “closed”, and moved the record from landing to closed. It used the close time from the previous day, and it did this while the landing was still running.
I never checked whether that close was newer than the landing. I treated a file’s state as the truth when it was really an old snapshot.
What it caused
Roughly in order:
- The merge queue opened a landing pull request, and its build passed.
- A few minutes later, the roll-up moved the record from
landingtoclosedbased on the old file. - Since the record now looked finished, the worktree was cleaned up.
- When that entry left, the queue abandoned the pull request. The branch still had the commit, but the target branch never got it. A parent repository even ended up pinned to that unmerged commit.
The history also shows the same report going landing → open → landing several times before this. That was an early warning I should have looked into.
All of this happened at the same time as a controller restart and some machines showing as offline, so those were the first suspects. The record transitions and the queue’s abandon point to my roll-up logic as the cause.
What I should have written
In the design:
- Record state has to be ordered. A close recorded before a landing began must never end that landing. A landing in progress should end only through its own outcome (landed, stopped, or worktree removed) or through an explicit operator action. Re-reading a file whose close is older than the landing shouldn’t end it. The recent design change was the right place to write this down, and that intent has now been stated publicly.
- Ending a landing must not abandon its pull request while the branch still has work the target lacks. This is the same lesson as two earlier reports, and I should have applied it here too.
In the implementation:
- Before moving a landing record to closed, a roll-up based on file state should compare the file’s close time with the landing’s start time. If the close is older, it doesn’t count.
- If the controller has a live landing record, the roll-up should defer to it. The controller owns the landing. A file in a checkout doesn’t.
What I’m changing
- One source of truth for landings. Where the controller holds a live landing record, nothing derived from files can override it.
- Timestamp ordering checks on every transition that can end a landing, with tests where the close predates the landing.
- Safety check before abandoning a PR: if the branch has commits the target doesn’t, the PR stays open and gets flagged for a person instead of being closed silently.
- Alerting on state cycling. A record bouncing between
landingandopenagain and again now gets surfaced. I missed that signal this time.
A note on the evidence
The controller logs for the key window were lost in a later deploy. The transition itself is confirmed by the bug event history and the forge’s record of the pull request being opened and then abandoned. The exact code path behind the landing → closed move comes from a monitoring tool’s analysis and hasn’t been re-traced independently yet. I’ll update this post if re-tracing turns up anything different.
I’m sorry to the team who lost this work. The fixes above are meant to make sure an old file can’t end an active landing again.