Skip to content

fix: address Codex review comments (preview flags, fresh kill-switch)#30

Merged
kilbot merged 1 commit into
mainfrom
fix/review-followups
Jun 15, 2026
Merged

fix: address Codex review comments (preview flags, fresh kill-switch)#30
kilbot merged 1 commit into
mainfrom
fix/review-followups

Conversation

@kilbot

@kilbot kilbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Addresses the two open Codex P2 comments from the rapid landing-page PR series (the P1 cached-exposure one was already fixed in #29; the plugin #1146 P2s were fixed in 3c6bde58).

wp-admin-landing#27 thread (P2) — fresh kill-switch on cache hits. My #29 fix made the kill-switch read synchronous-only, so a switch flipped after the visitor's last load wouldn't clear the cache. Adds watchKillSwitch(ph): a background onFeatureFlags watch that re-reads the kill-switch with send_event:false (non-exposure → safe post-identify, the ops flag is bucket-agnostic) and clears the assignment cache so the kill takes effect next load. The experiment-flag exposure read stays synchronous + pre-identify (#29 invariant intact).

wp-admin-landing#23 thread (P2) — preview must not touch production flags. Adds advanced_disable_flags: preview so the Pages harness never resolves landing-variant (a live flag could otherwise override the seeded preview assignment) and preview iframe loads don't hit the production flag endpoint. Verified both seeded variants render deterministically.

Tests extended in tests/exposure-ordering.test.mjs.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added background monitoring for experiment variant kill-switches with faster cache clearing
  • Bug Fixes

    • Fixed production feature flags being resolved in preview environments
  • Tests

    • Added tests validating kill-switch monitoring and preview environment configuration

#29 — restore fresh kill-switch on cache hits. The synchronous exposure read
only sees the persisted kill-switch value; a switch flipped after the last load
wouldn't clear the cache. Add watchKillSwitch(ph): a background onFeatureFlags
watch that re-reads the kill-switch with send_event:false (non-exposure, so no
post-identify bucket concern — the ops flag is bucket-agnostic) and clears the
assignment cache so the kill takes effect next load (spec §3.1.4). The
experiment-flag exposure read stays synchronous + pre-identify.

#23 — preview must not resolve production flags. Add advanced_disable_flags in
preview so the Pages harness never fetches landing-variant (a live flag could
otherwise win over the seeded assignment) and preview iframe loads don't hit the
production flag endpoint. Verified both seeded variants render deterministically.

Extends tests/exposure-ordering.test.mjs.
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: wcpos/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bc270587-5aad-4aaf-993f-97bf4555868d

📥 Commits

Reviewing files that changed from the base of the PR and between 423bcfa and 35a9e24.

📒 Files selected for processing (4)
  • assets/js/welcome.js
  • src/bootstrap/variant-loader.ts
  • src/shared/analytics.ts
  • tests/exposure-ordering.test.mjs

📝 Walkthrough

Walkthrough

Adds a watchKillSwitch helper in variant-loader.ts that subscribes to PostHog flag updates and clears the assignment cache when the kill-switch fires, then wires it into prepareVariant's cache fast-path. Sets advanced_disable_flags: preview in initAnalytics to prevent production flag resolution in preview environments. Two tests cover both behaviors.

Changes

Kill-switch watcher and preview flag isolation

Layer / File(s) Summary
watchKillSwitch helper and cache-path wiring
src/bootstrap/variant-loader.ts
Defines watchKillSwitch(ph) which subscribes to PostHog flag updates, reads the kill-switch flag with send_event: false, clears the assignment cache when ON, and unsubscribes after first fire. Calls it from the prepareVariant cache fast-path after recordCachedExposure.
Preview flag isolation and tests
src/shared/analytics.ts, tests/exposure-ordering.test.mjs
Sets advanced_disable_flags: preview in initAnalytics PostHog config to block production flag resolution in preview environments. Tests assert that watchKillSwitch does not read FLAG_KEY during the cache render path, and that advanced_disable_flags is sourced correctly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • wcpos/wp-admin-landing#27: Directly modifies the same variant-loader.ts kill-switch and prepareVariant cache/fast-path logic this PR extends.
  • wcpos/wp-admin-landing#23: Introduces window.__WCPOS_PREVIEW in the preview harness HTML, which is the flag the new advanced_disable_flags: preview assignment in analytics.ts depends on.

Poem

🔪 The kill-switch lurks in async night,
A watcher armed but staying light —
No flag re-read, no bucket swayed,
Just cache cleared clean when switch is flayed.
And preview lands, production blind,
A tidy guard for peace of mind. 🏳️

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/review-followups

Comment @coderabbitai help to get the list of available commands and usage tips.

@kilbot kilbot merged commit 253abc4 into main Jun 15, 2026
7 of 8 checks passed
@kilbot kilbot deleted the fix/review-followups branch June 15, 2026 10:36

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35a9e24eb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (killValue === true || killValue === 'on') clearCache();
unsub?.();
});
if (fired) unsub();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the kill-switch watch through cached callbacks

On cache-served repeat visits, persisted PostHog flags exist, and the nearby resolveFlag comment already notes that onFeatureFlags can fire inline in that state. This guard immediately unsubscribes the new watcher after that stale cached callback, so it observes only the same value recordCachedExposure already read and is gone before the post-identify flag reload that should contain a freshly flipped kill-switch. In that scenario, a kill-switch enabled after the prior visit will not clear wcpos_landing_assignment for the next load.

Useful? React with 👍 / 👎.

kilbot added a commit that referenced this pull request Jun 15, 2026
)

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.
kilbot added a commit that referenced this pull request Jun 15, 2026
…Codex on #30) (#32)

* fix: kill-switch watch must survive the stale inline callback (Codex #30)

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.

* test: assert the documented 8s kill-switch watch timeout (CodeRabbit #32)

* docs: align watchKillSwitch docblock with persistent-subscription design (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.
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