Skip to content

fix(sync): restore UI state and task sync after reconnect or sleep (#107) - #111

Merged
Lexus2016 merged 1 commit into
mainfrom
fix/reconnect-state-sync
Sep 20, 2026
Merged

Lexus2016 merged 1 commit into
mainfrom
fix/reconnect-state-sync

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Closes #107

Summary

Addresses session and task state divergence when closing the browser tab, computer sleeps/hibernates, or network disconnects.

Root Cause

  1. In public/kanban.html, polling relied solely on setTimeout, which is paused by the browser when a tab is throttled or computer sleeps, with no visibilitychange, focus, or online events to trigger self-healing.
  2. In public/index.html, when WebSocket reconnected while currentSessionId was already populated, loadSess was skipped. If a background task finished while away, the final response saved in the database was not loaded into the chat DOM.
  3. In server.js, the 60s watchdog skipped any task present in taskRunning, even if its subprocess had already died (worker_pid no longer running), leaving stale tasks stuck in in_progress.

Changes

  • public/kanban.html: Added visibilitychange, focus, and online event listeners to immediately refresh the board and restart auto-refresh upon wake-up.
  • public/index.html: Added online event listener for immediate reconnection; updated reconnect and refocus handlers to call loadSess(activeTabId) so completed results, summaries, and checkmarks are rendered.
  • server.js: Added isPidAlive(pid) helper and updated watchdog to evict dead worker_pid processes from taskRunning and recover stuck tasks.
  • test/interrupted-recovery.test.js: Added test suite verifying watchdog isPidAlive checks, task recovery, and UI self-healing event bindings.

@Lexus2016
Lexus2016 merged commit c44ff27 into main Sep 20, 2026
2 checks passed
@Lexus2016
Lexus2016 deleted the fix/reconnect-state-sync branch September 20, 2026 19:26
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.

Bug: UI State Is Not Correctly Restored After Browser Close, Refresh, Sleep, or Disconnect

1 participant