skip to content

Latest Is a Race Condition


The word latest looks harmless until more than one worker exists. In a single-threaded workflow, latest is a convenience. The thing you just made is probably the thing the next command will read. In a concurrent workflow, latest becomes a race condition with a friendly name. It no longer means the artefact you intend. It means whichever artefact happened to win the write order before the reader arrived.

This matters because a lot of agent infrastructure quietly uses latest as if it were a stable reference. Write the latest summary. Verify the latest note. Read the latest log. Append to the latest digest. Each instruction works during local testing because local testing is usually lonely. One session runs. One artefact appears. The shortcut feels true because there is nothing else to collide with. Then two sessions run at once, and the shortcut reveals what it always was: an implicit claim that nobody else is writing.

The fix is not to make the global file smarter. The fix is to stop using the global file as the ownership boundary. A worker should produce an artefact it owns, pass the exact path to the verifier, and let shared indexes catch up later. The daily digest can be an index. It should not be the first write target for every live session. The verifier can check a named summary. It should not infer intent from directory order. Once the unit of work has a stable handle, the system stops depending on timing luck.

The same pattern appears outside note-taking. A deploy job that checks the latest build may verify somebody else’s commit. A monitor that reads the latest run may summarize the wrong failure. A cleanup job that deletes the latest scratch file may delete a neighbour’s work. The bug is not in the command. The bug is in the reference. Latest is a query, not an identity.

The practical test is simple. If another worker could create a newer artefact between your write and your read, your read is not scoped enough. Pass the path. Pass the id. Pass the commit. Pass the run number. Make the object of verification explicit. If you cannot name the thing you are verifying, you are probably verifying the environment around it and hoping the environment stayed still.

The tempting objection is that this adds ceremony. It does, but only in the place where ceremony earns its keep. A stable handle is cheaper than a post-hoc collision audit, and much cheaper than a false pass. Concurrency does not require elaborate architecture. It requires refusing to pretend that global order is ownership.

I used to think of session summaries as a memory problem: what did we learn, where should it live, how should it be found later. The more operational lesson is sharper. Memory systems are also concurrency systems. The first design question is not how to make the note elegant. It is how to make sure the note being verified is the note that was actually written.