docs(agents): require persisting state before publishing handoffs - #584
Merged
Conversation
## Summary ### Why? A queue message that hands work to a later stage races the write that backs it. Within a service boundary the payload is only the entity ID and the consumer reloads from storage, so a message published before its write lands lets the consumer read an entity that was never recorded — or a version older than the one the message describes — and then act on an assumption that was never true. The other ordering is self-correcting: a failed publish leaves the state durable and the retry re-publishes, where the reverse leaves a message describing a state nothing wrote. The repo already depends on this ordering but never wrote it down. Two sites deliberately publish *first* — the recovery nudge in `speculate/finalize.go` and the status log in `buildsignal.go` — each with a local comment explaining why. Stated as a blanket rule, it would read as something those two sites violate, and the next reader would "fix" them. ### What? Adds "Persist before you publish" as Key Concept #6, scoped to messages that hand off work. It carves out messages whose consumer depends on nothing the write does — a status log recording a transition, an idempotent nudge whose consumer re-derives from current state — and points at the two sites that document that reasoning in place. Cross-references the rule from the queue-payload guidance, since reloading from storage is what makes the ordering load-bearing there.
behinddwalls
marked this pull request as ready for review
August 12, 2026 22:57
mnoah1
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why?
A queue message that hands work to a later stage races the write that backs it. Within a service boundary the payload is only the entity ID and the consumer reloads from storage, so a message published before its write lands lets the consumer read an entity that was never recorded — or a version older than the one the message describes — and then act on an assumption that was never true. The other ordering is self-correcting: a failed publish leaves the state durable and the retry re-publishes, where the reverse leaves a message describing a state nothing wrote.
The repo already depends on this ordering but never wrote it down. Two sites deliberately publish first — the recovery nudge in
speculate/finalize.goand the status log inbuildsignal.go— each with a local comment explaining why. Stated as a blanket rule, it would read as something those two sites violate, and the next reader would "fix" them.What?
Adds "Persist before you publish" as Key Concept #6, scoped to messages that hand off work. It carves out messages whose consumer depends on nothing the write does — a status log recording a transition, an idempotent nudge whose consumer re-derives from current state — and points at the two sites that document that reasoning in place.
Cross-references the rule from the queue-payload guidance, since reloading from storage is what makes the ordering load-bearing there.