Skip to content

VAPI-4167 feat: flush diagnostics when the page is hidden or unloaded - #27

Open
smoghe-bw wants to merge 4 commits into
mainfrom
VAPI-4167_flush-diagnostics-on-pagehide
Open

smoghe-bw wants to merge 4 commits into
mainfrom
VAPI-4167_flush-diagnostics-on-pagehide

Conversation

@smoghe-bw

@smoghe-bw smoghe-bw commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Jira: VAPI-4167

Summary

  • Flushes the DiagnosticsBatcher on window pagehide and on document visibilitychange to hidden, sending the batch as deviceDiagnostics over the open websocket. Without this, a tab close, navigation, or mobile backgrounding loses up to 5 minutes of buffered logs (including the 10-second in-call stats).
  • Best effort: the browser may tear down the socket before the bytes leave, more likely on Safari and mobile.
  • Skips the flush while the socket is closed, because a flush clears the buffer; the logs go out with the next flush instead.
  • Listeners are registered once per session on socket open (reconnect opens do not stack them) and removed in _disconnect. No-op when window/document do not exist (Node, e.g. the synthetic monitor).
  • On desktop refresh the existing beforeunload → disconnect() path usually sends the final batch first; this mainly covers mobile backgrounding and browsers that skip beforeunload.

Test plan

  • npm test: 172 passed, 6 new (pagehide flushes; hidden flushes; visible does not; no duplicate listeners across opens; nothing after disconnect; logs kept while the socket is closed and sent once it reopens)

🤖 Generated with Claude Code

Send the buffered diagnostics batch on window pagehide and on
visibilitychange to hidden, so a tab close, navigation, or mobile
backgrounding does not lose up to 5 minutes of logs. Best effort over the
existing websocket. A flush is skipped while the socket is closed so the
buffer is kept for a later flush. No-op outside a browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@smoghe-bw
smoghe-bw requested review from a team as code owners October 14, 2026 19:50
@bwappsec

bwappsec commented Oct 14, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

smoghe-bw and others added 3 commits October 14, 2026 15:59
- Guard on addEventListener/removeEventListener, not just window/document
- Skip page-exit flushes when the buffer is empty
- Make the disconnect test fail if the listeners are not removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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