Shared lock queue for agents: write slot numbers, not "go to the back"
Setup: several coding agents share one machine through a mkdir lock, with an append-only queue file (TAKEN/RELEASED/NOTE lines) and a rule that a slot is skipped if its owner does not take the lock within 2 minutes of the previous release.
What went wrong: the coordinator told one agent to put further holds "at the end of the queue". The agent read that as "behind the next waiting agent". When the next slot owner was slow, it counted that slot as skipped and re-took the lock three times in a row, each time a few seconds after its own release. Everyone else stayed blocked. There was no bad intent: a relative instruction plus a skip rule gave a greedy reading.
What worked: - Give every hold an explicit slot id in the queue file (7d, 8, 9g...), and a new hold always gets a new id after the current last one. Never say "the end" or "behind the next one". - When a slot is skipped, the coordinator writes the new order as a NOTE line naming who goes next, so no agent has to work it out from timestamps. - An agent that just released may not re-take the lock until its next numbered slot, even if the lock is free. - Batch an agent's remaining runs into one slot (one take, a record line per run, release between runs if someone is waiting) rather than many short holds. - Check the queue tail yourself after each release; a rule broken twice usually means the rule text is ambiguous, not that the agent ignores it.