-
Notifications
You must be signed in to change notification settings - Fork 38
feat(session-sync): phased SW resync with experiment-ready config #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Just-Insane
wants to merge
7
commits into
SableClient:dev
Choose a base branch
from
Just-Insane:feat/sw-session-resync-flags
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be1465d
feat(flags): inject client config from GH environment variables at build
Just-Insane 30d0529
feat(flags): add typed experiment bucketing helper with rollout perceβ¦
Just-Insane d1fda1d
feat(devtools): add Experiments panel to developer tools settings
Just-Insane 49a3586
test(flags): cover experiment bucketing and add changeset
Just-Insane b4a7fd5
feat(session-sync): phased SW session resync with experiment variant
Just-Insane 09e1a89
Add phased service-worker session re-sync controls
Just-Insane 39b1c99
fix(session-sync): add sessionSync to ClientConfig type
Just-Insane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| default: minor | ||
| --- | ||
|
|
||
| Add build-time client config overrides via environment variables, with typed deterministic experiment bucketing helpers for progressive feature rollout and A/B testing. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| default: minor | ||
| --- | ||
|
|
||
| Add phased service-worker session re-sync controls (foreground resync, visible heartbeat, adaptive backoff/jitter). |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { readFile, writeFile } from 'node:fs/promises'; | ||
| import process from 'node:process'; | ||
| import { PrefixedLogger } from './utils/console-style.js'; | ||
|
|
||
| const CONFIG_PATH = 'config.json'; | ||
| const OVERRIDES_ENV = 'CLIENT_CONFIG_OVERRIDES_JSON'; | ||
| const STRICT_ENV = 'CLIENT_CONFIG_OVERRIDES_STRICT'; | ||
| const logger = new PrefixedLogger('[config-inject]'); | ||
|
|
||
| const formatError = (error) => { | ||
| if (error instanceof Error) return error.stack ?? error.message; | ||
| return String(error); | ||
| }; | ||
|
|
||
| const isPlainObject = (value) => | ||
| typeof value === 'object' && value !== null && !Array.isArray(value); | ||
|
|
||
| const deepMerge = (target, source) => { | ||
| if (!isPlainObject(target) || !isPlainObject(source)) return source; | ||
|
|
||
| const merged = { ...target }; | ||
| Object.entries(source).forEach(([key, value]) => { | ||
| const targetValue = merged[key]; | ||
| merged[key] = | ||
| isPlainObject(targetValue) && isPlainObject(value) ? deepMerge(targetValue, value) : value; | ||
| }); | ||
| return merged; | ||
| }; | ||
|
|
||
| const failOnError = process.env[STRICT_ENV] === 'true'; | ||
| const overridesRaw = process.env[OVERRIDES_ENV]; | ||
|
|
||
| if (!overridesRaw) { | ||
| logger.info(`No ${OVERRIDES_ENV} provided; leaving ${CONFIG_PATH} unchanged.`); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| let fileConfig; | ||
| let overrides; | ||
|
|
||
| try { | ||
| const file = await readFile(CONFIG_PATH, 'utf8'); | ||
| fileConfig = JSON.parse(file); | ||
| } catch (error) { | ||
| logger.error(`Failed reading ${CONFIG_PATH}: ${formatError(error)}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| try { | ||
| overrides = JSON.parse(overridesRaw); | ||
| if (!isPlainObject(overrides)) { | ||
| throw new Error(`${OVERRIDES_ENV} must be a JSON object.`); | ||
| } | ||
| } catch (error) { | ||
| const message = `[config-inject] Invalid ${OVERRIDES_ENV}; ${ | ||
| failOnError ? 'failing build' : 'skipping overrides' | ||
| }.`; | ||
| if (failOnError) { | ||
| logger.error(`${message} ${formatError(error)}`); | ||
| process.exit(1); | ||
| } | ||
| logger.info(`[warning] ${message} ${formatError(error)}`); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| const mergedConfig = deepMerge(fileConfig, overrides); | ||
|
|
||
| await writeFile(CONFIG_PATH, `${JSON.stringify(mergedConfig, null, 2)}\n`, 'utf8'); | ||
| logger.info( | ||
| `Applied overrides to ${CONFIG_PATH}. Top-level keys: ${Object.keys(overrides).join(', ')}` | ||
| ); | ||
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
102 changes: 102 additions & 0 deletions
102
src/app/features/settings/developer-tools/ExperimentsPanel.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { useMemo } from 'react'; | ||
| import { Box, Text, color } from 'folds'; | ||
| import { useMatrixClient } from '$hooks/useMatrixClient'; | ||
| import { useClientConfig, selectExperimentVariant } from '$hooks/useClientConfig'; | ||
| import { SequenceCard } from '$components/sequence-card'; | ||
| import { SettingTile } from '$components/setting-tile'; | ||
| import { SequenceCardStyle } from '$features/settings/styles.css'; | ||
|
|
||
| export function ExperimentsPanel() { | ||
| const mx = useMatrixClient(); | ||
| const config = useClientConfig(); | ||
| const userId = mx.getUserId() ?? undefined; | ||
|
|
||
| const experiments = useMemo(() => { | ||
| if (!config.experiments) return []; | ||
| return Object.entries(config.experiments).map(([key, experimentConfig]) => ({ | ||
| key, | ||
| config: experimentConfig, | ||
| selection: selectExperimentVariant(key, experimentConfig, userId), | ||
| })); | ||
| }, [config.experiments, userId]); | ||
|
|
||
| if (experiments.length === 0) { | ||
| return ( | ||
| <Box direction="Column" gap="100"> | ||
| <Text size="L400">Features & Experiments</Text> | ||
| <Text size="T200" style={{ color: color.Secondary.Main }}> | ||
| No experiments configured | ||
| </Text> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Box direction="Column" gap="100"> | ||
| <Text size="L400">Features & Experiments</Text> | ||
| <SequenceCard | ||
| className={SequenceCardStyle} | ||
| variant="SurfaceVariant" | ||
| direction="Column" | ||
| gap="400" | ||
| > | ||
| {experiments.map(({ key, config: experimentConfig, selection }) => ( | ||
| <SettingTile key={key} title={key}> | ||
| <Box direction="Column" gap="200"> | ||
| <Box direction="Row" gap="300"> | ||
| <Text size="T200"> | ||
| <strong>Enabled:</strong> | ||
| </Text> | ||
| <Text | ||
| size="T200" | ||
| style={{ | ||
| color: selection.enabled ? color.Success.Main : color.Secondary.Main, | ||
| }} | ||
| > | ||
| {selection.enabled ? 'Yes' : 'No'} | ||
| </Text> | ||
| </Box> | ||
| {selection.enabled && ( | ||
| <> | ||
| <Box direction="Row" gap="300"> | ||
| <Text size="T200"> | ||
| <strong>Rollout:</strong> | ||
| </Text> | ||
| <Text size="T200">{selection.rolloutPercentage}%</Text> | ||
| </Box> | ||
| <Box direction="Row" gap="300"> | ||
| <Text size="T200"> | ||
| <strong>Your Variant:</strong> | ||
| </Text> | ||
| <Text | ||
| size="T200" | ||
| style={{ | ||
| color: selection.inExperiment ? color.Success.Main : color.Secondary.Main, | ||
| }} | ||
| > | ||
| {selection.variant} | ||
| {selection.inExperiment && ' (in experiment)'} | ||
| {!selection.inExperiment && ' (control)'} | ||
| </Text> | ||
| </Box> | ||
| {experimentConfig.variants && experimentConfig.variants.length > 0 && ( | ||
| <Box direction="Row" gap="300"> | ||
| <Text size="T200"> | ||
| <strong>Treatment Variants:</strong> | ||
| </Text> | ||
| <Text size="T200"> | ||
| {experimentConfig.variants | ||
| .filter((v) => v !== experimentConfig.controlVariant) | ||
| .join(', ')} | ||
| </Text> | ||
| </Box> | ||
| )} | ||
| </> | ||
| )} | ||
| </Box> | ||
| </SettingTile> | ||
| ))} | ||
| </SequenceCard> | ||
| </Box> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.