Conversation
Log events are now timestamped and numbered at log time, queued, and uploaded in batches that leave the queue only on server ack. Unsent events survive unloads via localStorage (written on hide/pagehide only) and are uploaded by the next page load. Page transitions go through redirect(), which drains the queue first. /api/log accepts batches and skips invalid entries rather than rejecting the batch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018SvPCoGPWdKzNdUZVCoW29
redirect() now waits indefinitely for the log queue to drain instead of timing out after 5s. A single LogStatusBanner on the study page explains the wait when uploads are failing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018SvPCoGPWdKzNdUZVCoW29
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018SvPCoGPWdKzNdUZVCoW29
Works in non-secure contexts too, so no Math.random fallback is needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018SvPCoGPWdKzNdUZVCoW29
Contributor
Author
|
@neh8 can you test that this addresses the too-fast-to-log issue that you were seeing? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Before this change, each experiment log event was a separate POST that stopped retrying about 300ms after the first try. A Wi‑Fi blip or a redeploy during the writing task could silently lose chat messages and AI events, and those can't be recovered from anything else.
What
lib/logging.ts:log()now timestamps each event and assigns it asessionId(new per page load) and aseqnumber, then adds it to a queue. The queue uploads in batches about once per second, one request at a time. Events leave the queue only after the server confirms them; failed uploads retry with backoff for as long as the page is open.visibilitychange/pagehide), the queue is saved tolocalStorage, and the next page load uploads it. It is not written on every event.pagehidealso tries akeepaliveupload of up to 60KB.beforeunloadshows a prompt if events are still queued.redirect(url)/logThenRedirect()wait, retrying indefinitely, until the queue is empty. All study page transitions now go through them, replacing the duplicated log-then-window.locationcode. While a transition is blocked and uploads are failing, a singleLogStatusBanneron the study page explains the wait. The page moves on by itself once the upload succeeds. Batches the server rejected (4xx) don't block, since waiting can't recover them./api/log: takes an array of entries and groups them by username, since a queue recovered fromlocalStorageon a shared machine can hold another participant's events. It skips invalid entries instead of rejecting the batch, so one bad entry can't block the queue. The client drops a batch on a 4xx rather than retrying it.docs/logging.mdrecommends compressing the log files on disk.Analysis impact
Deduplicate on
(sessionId, seq), since duplicates are expected. Sort bytimestamp. A gap inseqwithin a session means lost events. Seeexperiment/docs/logging.md.Testing
__tests__/lib/logging.test.ts: batching and seq numbering, retry after a 5xx, dropping a batch on a 4xx, hand-off to the next page load vialocalStorage, flushing before a redirect, and a redirect that stays blocked while uploads fail and reports its status.tscpasses. ESLint reports no new issues; the existing error inScreenSizeCheck.tsxis unchanged.keepaliveupload duringpagehide, banner appearance).🤖 Generated with Claude Code
https://claude.ai/code/session_018SvPCoGPWdKzNdUZVCoW29