fix: kill-switch watch survives the stale inline callback (addresses Codex on #30)#32
Conversation
|
Warning Review limit reached
More reviews will be available in 29 minutes and 45 seconds. Learn how PR review limits work. To continue reviewing without waiting, enable usage-based billing in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository: wcpos/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesKill-switch subscription lifecycle
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/exposure-ordering.test.mjs (1)
55-55: ⚡ Quick winCould we assert the explicit 8-second timeout contract here?
Right now this only proves
setTimeoutexists; a wrong duration would still pass. Would you tighten this to assert8000as part of the watcher lifecycle guarantee?As per coding guidelines, "Respect documented author intent and check for companion PRs"—the PR intent explicitly defines a fixed 8-second bound.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/exposure-ordering.test.mjs` at line 55, The assertion on the assert.match call for the watch variable currently only verifies that setTimeout exists but does not validate the specific 8-second timeout duration. Update the regex pattern in the assert.match call to explicitly check for the 8000 millisecond timeout value within the setTimeout invocation, ensuring the test verifies the documented 8-second timeout contract as part of the watcher lifecycle guarantee.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/exposure-ordering.test.mjs`:
- Line 55: The assertion on the assert.match call for the watch variable
currently only verifies that setTimeout exists but does not validate the
specific 8-second timeout duration. Update the regex pattern in the assert.match
call to explicitly check for the 8000 millisecond timeout value within the
setTimeout invocation, ensuring the test verifies the documented 8-second
timeout contract as part of the watcher lifecycle guarantee.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: wcpos/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 5b118081-db26-45a1-9e5a-d0e890208753
📒 Files selected for processing (3)
assets/js/welcome.jssrc/bootstrap/variant-loader.tstests/exposure-ordering.test.mjs
Fix triage
Working through both now. |
) watchKillSwitch copied resolveFlag's unsubscribe-after-first-fire guard, but on a cached repeat visit posthog-js fires onFeatureFlags inline with the STALE persisted flags — so it read the same value recordCachedExposure already saw and unsubscribed before the fresh network reload, meaning a kill-switch flipped since the last visit never cleared the assignment cache (the exact case it was meant to handle). Removed the guard: stay subscribed, clear the cache on any observed ON value (fresh reload / post-identify reload), bounded by an 8s timeout so the listener never lingers. Pins the regression in tests/exposure-ordering.test.mjs.
7824566 to
27fdbf1
Compare
|
✅ Both items resolved:
@coderabbitai the 8s-timeout nitpick is addressed in 27fdbf1. CI green, no open threads. Ready for review/merge — not self-merging. |
|
🐇 ✅ ✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/bootstrap/variant-loader.ts`:
- Around line 106-113: The docblock at lines 95-96 describing the watcher
lifecycle is outdated and contradicts the new implementation shown at lines
106-113. Update the earlier docblock to reflect the persistent-subscription
design intent: explain that the watcher intentionally stays subscribed without
the synchronous-fire/unsubscribe-after-first guard, that it clears on observed
ON values from fresh network reloads, and that it is bounded by a timeout to
prevent the listener from lingering indefinitely. This aligns the documentation
with the actual persistent-subscription pattern implemented in the code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: wcpos/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a1b058c0-fcb1-480c-9f0b-b61c13e7ec14
📒 Files selected for processing (3)
assets/js/welcome.jssrc/bootstrap/variant-loader.tstests/exposure-ordering.test.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/exposure-ordering.test.mjs
…ign (CodeRabbit #32) The docblock at lines 95-96 still described the old synchronous-fire guard that unsubscribes after the first reload. The implementation deliberately dropped that guard so the watch survives the stale inline callback and picks up the fresh network reload. Update the wording to match.
Addresses the P2 Codex flagged on #30 (which I'd already merged — apologies; not self-merging this one).
Bug:
watchKillSwitchreusedresolveFlag's unsubscribe-after-first-fire guard. On a cached repeat visit posthog-js firesonFeatureFlagsinline with the stale persisted flags, so the watcher read the same valuerecordCachedExposurealready saw and unsubscribed before the fresh network reload — meaning a kill-switch flipped since the last visit never clearedwcpos_landing_assignment. The exact scenario #30 set out to fix, it didn't.Fix: drop the guard. Stay subscribed and clear the cache on any observed ON value (the fresh network reload, and the post-identify reload), then stop; bounded by an 8s timeout so the listener never lingers. The experiment-flag exposure read stays synchronous + pre-identify (unchanged). Regression pinned in
tests/exposure-ordering.test.mjs(asserts no first-fire unsubscribe, bounded by timeout).Please review before merge.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests