Repository navigation
fix: flush analytics once a batch's worth of bytes is queued - #986
Merged
Merged
Conversation
The early flush at maxBatchBytes read the file queue's byteCount, which was only tracked when a disk byte cap (maxQueueBytes) was set. Analytics has a batch byte limit but no disk cap, so byteCount stayed 0 and large events waited for flushAt or the timer. Track file sizes whenever the endpoint has a batch byte limit, without adding eviction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dustinbyrne
approved these changes
Oct 28, 2026
dustinbyrne
left a comment
Contributor
There was a problem hiding this comment.
Byte tracking remains separate from eviction, and the added analytics-factory and accounting regression tests cover the intended behavior. No actionable findings.
AI-assisted review.
The base already landed the same byte-tracking fix (9c1565b), so take its PostHogFileBackedQueue/PostHogQueue versions and keep only this branch's extra tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
💡 Motivation and Context
Follow-up to #938, from the review bot's comment.
PostHogQueue.flushIfOverThreshold()flushes early oncefileQueue.byteCountreachesendpoint.maxBatchBytes(5 MiB for analytics). ButPostHogFileBackedQueueonly trackedbyteCountwhen it had a disk byte cap (maxBytes, frommaxQueueBytes), and only the AI endpoint sets one. For analyticsbyteCountstayed 0, so the early flush never fired, and large events waited forflushAtor the flush timer.What changed:
PostHogFileBackedQueuetakes a newtrackBytesflag. It tracks file sizes whentrackBytesormaxBytesis set. Eviction still happens only whenmaxBytesis set, as before.PostHogQueuepassestrackBytes: endpoint.maxBatchBytes != nil, so analytics counts bytes but still has no disk byte cap.No new changeset: this is an unreleased 4.0 fix, and the existing
.changeset/v4-capture-v1.mdon #938 already describes the 5 MiB analytics batches.💚 How did you test it?
flushesAtByteLimit(Capture V1 queue suite): three ~2 MiB analytics events,flushAt = 100, queue not started (no timer), no manual flush. With the fix the queue drains. Without the fix it fails:queue.depth → 3, no requests sent after 10 s.tracksBytesWithoutLimit(file-backed queue alignment suite):byteCountis tracked withtrackBytesand nomaxBytes, survives a reload from disk, decreases on pop, and nothing is evicted.swift test --no-parallel -Xswiftc -DTESTING --filter 'PostHogQueueTest|PostHogCaptureV1|PostHogFileBackedQueue': 109 tests in 9 suites passed twice in a row. A third run had failures inFileBackedQueue Concurrency Tests, but only while another local session was running the same test bundle against the shared Application Support directory. That suite doesn't use byte tracking.make lint: no new warnings. Didn't runmake buildSdkbecausexcprettyisn't installed locally.📝 Checklist
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Built with Claude Code. I used a separate
trackBytesflag instead of giving analytics amaxQueueBytescap, so analytics doesn't get byte-based eviction it never had.🤖 Generated with Claude Code