Skip to content

feat(feature-flags): add weighted variants and evaluation hook - #353

Merged
olliethedev merged 2 commits into
mainfrom
feat/issue-342-after-v6
Nov 6, 2026
Merged

olliethedev merged 2 commits into
mainfrom
feat/issue-342-after-v6

Conversation

@olliethedev

@olliethedev olliethedev commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #342. Add optional weighted variants to existing flag types, validate JSON payloads and 100% totals, and preserve boolean evaluation responses.

flag eligibility → deterministic variant bucket → key + optional payload
                          ├─ useFeatureFlagVariant / evaluateVariant
                          └─ FlagEvaluation.variant / onEvaluate context.variant

Dashboard controls author variants, preview saved assignments, and show variant history. Docs cover the API, public payloads, additive database migration, cache behavior, and reassignment after weight edits. Registry output is regenerated.

Evidence

  • Packed consumer correction: the existing typed fixture now supplies variants: []; the focused npm packed-consumer check passes typechecking, runtime and browser behavior. CI runs both package managers.

  • Before: definitions and evaluations supported boolean eligibility only; no weighted authoring, assignment hook, or variant history.
    After: weighted authoring and deterministic key/payload assignment work through the dashboard and public operations; existing boolean browser flow still passes.

  • 21 unit tests passed; plugin typecheck/build and Biome passed. Targeted tests cover distribution, repeatability, identity precedence, zero weights, JSON validation, authorization, history/hooks, and server/client cache invalidation.

  • Both smoke.feature-flags.spec.ts browser tests passed against an isolated generated Next.js app on port 3504, including a 390px long-payload regression. Full local suite and full registry install matrix were not run; CI owns those checks.

  • Docs production build passed. Ejected Feature Flags registry files compile in the generated app; repeated registry generation matches committed output.

  • Captioned demo (MP4) · All screenshots and verification. All five demo frames inspected; mobile light/dark and keyboard focus verified with no page errors.

These evidence URLs require the owner's website login and LAN/private Tailscale access.

Weighted variant authoring

Assignment changes after a weight edit

Merge Danger

Door: two-way

Adds the serialized flag.variants string field, default []; SQL adapters need an additive migration. Existing rows without variants deserialize as empty lists. Code rollback can leave the added column in place.

Blast Radius: FeatureFlags

Payloads are public to evaluation clients. Editing variant keys, order, or weights can reassign subjects. Logs remain bounded and instance-local; other processes observe definition changes after their existing cache TTL.

@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
better-stack-docs Ready Ready Preview Nov 6, 2026 3:52am UTC
better-stack-playground Ready Ready Preview Nov 6, 2026 3:52am UTC

Request Review

@olliethedev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T03:54:14.273178Z 8625494 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 059eadcd0e

ℹ️ 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".

@olliethedev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 862549428c

ℹ️ 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".

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Bundle size

7 of 194 bundles changed.

Module Gzip base → PR Gzip change Minified change
@btst/plugin-feature-flags/client/components 122664 → 124191 B +1527 B (+1.2%) +5185 B (+0.9%)
@btst/plugin-feature-flags/client 123677 → 125184 B +1507 B (+1.2%) +5185 B (+0.9%)
@btst/plugin-feature-flags/api 102472 → 102796 B +324 B (+0.3%) +1528 B (+0.3%)
@btst/plugin-feature-flags/evaluate 424 → 550 B +126 B (+29.7%) +297 B (+40.9%)
@btst/plugin-feature-flags/client/hooks 20060 → 20092 B +32 B (+0.2%) +281 B (+0.4%)
@btst/plugin-feature-flags/css 1806 → 1822 B +16 B (+0.9%) +69 B (+1.1%)
@btst/plugin-feature-flags/query-keys 2450 → 2462 B +12 B (+0.5%) +103 B (+1.9%)

10ef1f7 → 8625494. Standalone costs; rows overlap. Moved paths appear as new/removed entries, not application savings.

Measured 22 packed archives separately; full report includes their compressed bytes without installed dependencies.

Full report and measurements

@olliethedev
olliethedev merged commit 6473edb into main Nov 6, 2026
62 checks passed

This branch was successfully deployed

2 active deployments
Preview – better-stack-docs — 86254942 Deployed Nov 6, 2026 by vercel[bot]
Preview – better-stack-playground — 86254942 Deployed Nov 6, 2026 by vercel[bot]
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.

Feature Flags: weighted multivariate variants and useFeatureFlagVariant hook

1 participant