@@ -301,6 +301,14 @@ export function useCodexAccountPool(apiBase: string, enabled = true): CodexAccou |
301 | 301 | pendingActiveIdRef.current = { id: nextActiveId }; |
302 | 302 | setActiveId(nextActiveId); |
303 | 303 | } |
| 304 | + // Deliberately NOT cross-gated against the switch and order writes, even though |
| 305 | + // pausing the pinned account also releases the pin. This edge is conditional on |
| 306 | + // the pin still naming `id`, which makes it order-robust: whichever response |
| 307 | + // lands last, the client agrees with the server. An unconditional edge is what |
| 308 | + // forced the gate between those two -- each states a pin outright, so the later |
| 309 | + // response wins regardless of which write the server applied last. Sharing a |
| 310 | + // mutation ref here would instead make a pause and an order change on two |
| 311 | + // unrelated accounts reject each other for no reason. |
304 | 312 | if (paused) setActivePinnedId(current => current === id ? null : current); |
305 | 313 | void load(); |
306 | 314 | return { ok: true } as const; |
@@ -375,6 +383,9 @@ export function useCodexAccountPool(apiBase: string, enabled = true): CodexAccou |
375 | 383 | pendingActiveIdRef.current = { id: nextActiveId }; |
376 | 384 | setActiveId(nextActiveId); |
377 | 385 | } |
| 386 | + // Conditional for the same reason as the single-account pause above: clearing |
| 387 | + // outright would race the switch and order writes, which is why those two are |
| 388 | + // gated against each other and these two do not need to be. |
378 | 389 | setActivePinnedId(current => current !== null && pausedIds.has(current) ? null : current); |
379 | 390 | void load(); |
380 | 391 | return { ok: true, pausedCount: result.pausedCount ?? pausedIds.size } as const; |
|