Repository navigation
Open
Labels
Description
When agents on one machine publish two different pages at about the same time, the second publish can pick up the first agent's attempt and send that instead, so its own page never goes up. It still reports success, with exit 0 and the other page's URL, so its agent tells the person their page is live when it isn't. This happens on any instance, production included, and in dev environments, where every agent session shares the environment's CLI state.
Why:
- One slot. Every page publish (
patchy publish <file>) records its attempt in one slot per instance in the CLI's state:<state>/publish/<instance hash>/attempt(packages/patchy/src/State.ts:227). A publish that finds an attempt there sends that one instead of its own; this is meant for recovering an interrupted publish (packages/patchy/src/commands.ts:555,State.ts:405). - Unlocked cache. The cache that records which page file belongs to which patch is read, changed and written without a lock (
State.ts:541). Two publishes finishing together can drop one entry. That page's next publish then makes a new patch at a new URL instead of updating its own. - Credentials too. Saved credentials and pending logins are written the same way, so concurrent sign-ins can lose one. This is rarer.
Publishes of different repos keep separate attempts in each repo's .patchy/; the credential races apply to them too.
The fix:
- Give each page its own publish slot, keyed by the file as well as the instance.
- Hold a lock that works across processes for each whole read, change and write of a state file, keeping today's atomic replacement. Atomic replacement already stops half-written files; it can't stop lost updates.
- An attempt left in the old single slot is recovered only by a publish of its own recorded file (
State.ts:70keepstarget.file). Any other publish leaves it alone, never sends it, and never reports its success.
Found by GPT 6.1 Sol while working out the builder pipeline for agent areas, and kept out of that map.
Done means
- Two agents publishing different pages at the same moment each put up their own page and report their own URL.
- Republishing either page afterwards updates its patch rather than creating a new one.
- An interrupted publish from before the fix is recovered by publishing its own file again, and never by publishing a different one.
Activity