fix(presence-sync): tick mutex so setInterval overlap can not spawn parallel ticks #8
Reference in New Issue
Block a user
Delete Branch "fix/presence-sync-tick-mutex"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
PresenceSync.tick()iterates accounts serially withawaiton each agent-login + PUT round-trip. A single tick can easily run 20+s when there are several accounts (each agent-login is a network round-trip to Center, each PUT is a round-trip to Guild).setInterval(intervalMs)does NOT wait for the previous callback — on a busy gateway the next tick fires on top of a still-running one, and two parallel iterations each PUT the sameagentIdwithin milliseconds.Caught in prod (2026-05-25 23:23:35Z)
t2 gateway log, single
presence-sync started for 5 account(s)(single instance), yet paired log lines 4-10 ms apart for the same agent:The 500 is a separate backend bug (race-prone
findOne+saveinagent-presence.service.ts, fixed in nav/Fabric.Backend.Guild#presence-upsert-race). This PR fixes the plugin-side amplifier.Fix
Dropping overlapping ticks is safe:
lastStatus !== bridge.getgating already means status changes catch the next tick anyway. Skipping a beat costs nothing the next beat won't fix.Sim test
Sim has only 1 fabric account (no second account to overlap on), so the prod symptom can't be reproduced locally — but the code change is mechanical (4-line mutex around the existing
tick()body, renamed totickInner). Will validate on prod after deploy: paired-log-lines-within-1s count should drop to 0.