Skip to content

fix: preserve flag evaluations tracked during analytics flush - #284

Open
pcbeingused333 wants to merge 3 commits into
Flagsmith:mainfrom
pcbeingused333:fix/c3477-analytics-flush
Open

pcbeingused333 wants to merge 3 commits into
Flagsmith:mainfrom
pcbeingused333:fix/c3477-analytics-flush

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 15, 2026 •

Copy link
Copy Markdown

Flag evaluations can be lost when they are recorded during an analytics submission, or when the submission raises synchronously after the pending batch has been detached.

Detach the current batch under a lock and submit it outside the lock so evaluations can continue while the request is being scheduled. If submission raises synchronously, add the detached counts back into the pending batch under the lock and propagate the exception. The next flush submits both the restored counts and the evaluations recorded during submission.

Testing and validation

  • python -m pytest -q tests/test_analytics.py on the previous PR head with the new regression produced one failure and seven passes. All eight pass with the fix.
  • The full local suite had 374 passes and six failures in the Accept-Encoding header assertions. The same six failures reproduce on upstream main in the local Python 3.15 environment, which also advertises zstd.

This change and its regression test were prepared with assistance from OpenAI Codex.

@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 15, 2026 19:21
@pcbeingused333
pcbeingused333 requested review from emyller and removed request for a team November 15, 2026 19:21
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

AnalyticsProcessor now locks updates to buffered analytics data. flush captures and clears the pending batch before posting it, and updates the flush timestamp during that operation. track_feature checks the timer while holding the lock and calls flush after releasing it. A concurrent test blocks a POST and verifies that evaluations recorded during the submission remain available for a later flush.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to b4387

This change keeps flag evaluations recorded during an analytics submission from being lost. No merge-blocking risk was found, and a regression test covers the behavior.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 9e00888a-3ad3-439c-9840-bb231f17424e
Commits

Reviewing files that changed from the base of the PR and between b480743 and b438740.

Files selected for processing: 2

  • flagsmith/analytics.py
  • tests/test_analytics.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread flagsmith/analytics.py Resolved
@pcbeingused333

Copy link
Copy Markdown
Author

Thanks for pointing out the synchronous submission failure. The follow-up restores the detached counts under the lock and merges them with evaluations recorded during submission before re-raising the exception. A regression test verifies that the next flush sends both sets of counts. Could you take another look at the updated behavior?

This comment was drafted with Claude Code.

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.

1 participant