Skip to content

Fix auto-ping timer firing 8s early due to setInterval/countdown desync#25

Merged
MrAlders0n merged 2 commits into
mainfrom
copilot/fix-auto-ping-timer-issue
Dec 17, 2025
Merged

Fix auto-ping timer firing 8s early due to setInterval/countdown desync#25
MrAlders0n merged 2 commits into
mainfrom
copilot/fix-auto-ping-timer-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 17, 2025

Auto-ping countdown showed ~8s remaining when the ping fired because setInterval started at T=0 but countdown display only started after the ~7s API delay completed.

Changes

Replaced interval-based timing with sequential scheduling:

  • setIntervalsetTimeout chain where each ping schedules the next after completion
  • New scheduleNextAutoPing() atomically starts countdown and schedules next ping
  • sendPing() calls scheduleNextAutoPing() after API POST + map refresh complete
  • startAutoPing() simplified to only trigger first ping

Timing flow:

// Before: setInterval from T=0, countdown from T=7 → 8s desync
startAutoPing()  setInterval(15s) | sendPing()  [7s delay]  countdown starts

// After: setTimeout from completion time → perfect sync  
startAutoPing()  sendPing()  [7s delay]  scheduleNextAutoPing()  countdown + setTimeout(15s)

Cleanup:

  • clearIntervalclearTimeout in stopAutoPing()
  • Existing state.running guard prevents race conditions
Original prompt

Since the last merge things seem to be working better, heres a new issue we need fixed.

When Start Auto Ping is enabled with a 15-second interval (the same issue occurs at 30 seconds), the countdown initially behaves correctly (15, 14, 13, 12, etc.). However, at approximately 8 seconds remaining, the status briefly switches to “ping sent / waiting for API” and then immediately returns to the countdown.

Expected auto-ping behavior:

A ping must be sent only when the countdown reaches 0.

After the ping is sent, the app should stay in “waiting for API” until the API POST completes.

Once the API response is received and the iframe has refreshed, a new full interval countdown (for example, 15 seconds) should begin.

Current behavior indicates the auto-ping send logic is firing early, rather than being strictly tied to the countdown reaching zero.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix early auto-ping send logic Fix auto-ping timer firing 8s early due to setInterval/countdown desync Dec 17, 2025
Copilot AI requested a review from MrAlders0n December 17, 2025 23:43
@MrAlders0n MrAlders0n marked this pull request as ready for review December 17, 2025 23:43
@MrAlders0n MrAlders0n merged commit ea81104 into main Dec 17, 2025
@MrAlders0n MrAlders0n deleted the copilot/fix-auto-ping-timer-issue branch December 18, 2025 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants