@vllnt/convex-experiments 0.2.0-canary.38e0a3a → 0.2.0-canary.6def607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,61 +4,87 @@ All notable changes to this project are documented here. The format is based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [0.2.0] - Unreleased
7
+ ## [0.2.0] - 2026-11-28
8
8
 
9
9
  ### Added
10
10
 
11
11
  - Ship `docs/API.md`, `CHANGELOG.md` and `llms.txt` in the npm package, so coding agents can read
12
12
  docs that match the installed version from `node_modules/@vllnt/convex-experiments/`. `llms.txt`
13
- links shipped files relatively and has a "For coding agents" note and an Ecosystem line; the README
14
- gains a "For coding agents" note and a "Related packages" section.
15
- - `pnpm test:package` (run in CI) fails when a required file is missing from the tarball, when a
16
- contributor or internal file would ship, or when an `llms.txt` link does not resolve inside it.
17
- - `docs/API.md` documents the `./react`, `./test` and `./convex.config` entry points and the exported types.
13
+ links the shipped files relatively.
14
+ - `docs/API.md` documents the `./react`, `./test` and `./convex.config` entry points and the
15
+ exported types, and every public export has TSDoc.
16
+ - Document that `listExperiments` returns rows in creation order, and that `convex-test` 0.0.72 and
17
+ later need `convex ^1.46.0` (use 0.0.71 or older on `convex` 1.45).
18
+
19
+ ### Changed
20
+
21
+ - **Breaking:** Assignment now mixes the hash: FNV-1a over the UTF-16 code units of
22
+ `"<scope>:<salt>:<subjectRef>"` is followed by a 32-bit finalizer (murmur3 `fmix32`), so weights
23
+ hold for similar or sequential `subjectRef`s. Stored assignments are kept. A subject not yet
24
+ assigned in an experiment that runs across the upgrade, `peek` for such a subject, and a subject
25
+ re-enrolled after `forgetSubject` can land in a different variant than 0.1.0 picked. What to do:
26
+ finish such experiments before upgrading, or stop them and do not restart them after the upgrade
27
+ (a restarted experiment mixes the two hashes), or define a new experiment key.
28
+ - **Breaking:** `define`, `setStatus`, `assign`, `logExposure`, `forgetSubject` and
29
+ `deleteExperiment` reject an empty `scope`, `key` or `subjectRef` with
30
+ `ConvexError({ code: "INVALID_ARGUMENT" })`, and `define` rejects an empty variant key with
31
+ `INVALID_VARIANTS` (`reason: "empty_key"`); 0.1.0 accepted them. What to do: pass non-empty
32
+ identifiers (including `defaultScope`), or validate them before calling. Before upgrading, erase
33
+ or delete with 0.1.0 any data stored under an empty identifier; after the upgrade, `forgetSubject`
34
+ and `deleteExperiment` reject it too.
35
+ - **Breaking:** New data is capped. `scope`, `key`, `salt`, `subjectRef` and each variant key may be
36
+ at most 512 UTF-16 code units (JavaScript `string.length`: an emoji counts as 2; neither
37
+ characters nor UTF-8 bytes), and an experiment at most 100 variants; 0.1.0 accepted any length
38
+ and count. Over the cap, `define` (new experiment, or a changed `variants` or `salt`), and
39
+ `assign` and `logExposure` (a new subject) throw `ConvexError({ code: "INVALID_ARGUMENT" })`, or
40
+ `INVALID_VARIANTS` with `reason: "key_too_long"` for a variant key and `reason: "too_many"` for
41
+ the count. Data stored by 0.1.0 over a cap stays readable, and `setStatus`, `forgetSubject`,
42
+ `deleteExperiment`, a `define` that changes only `status`, and `assign` or `logExposure` for a
43
+ subject already stored all keep working. A `define` that changes `variants` or `salt` is checked
44
+ as new data, even if it keeps the old over-long value, and an experiment with assignments stays
45
+ locked. What to do: keep identifiers within 512 and use at most 100 variants; for an existing
46
+ experiment with a longer key or more variants, define a new shorter key.
47
+ - `define` and `setStatus` skip the write when nothing changed, so an idempotent re-define or a
48
+ repeated `setStatus` no longer invalidates subscriptions that read the definition (`getExperiment`,
49
+ `listExperiments`, `peek`, `results`). Return values are unchanged.
50
+ - `deleteExperiment` deletes the definition in the same pass once every child table returns fewer
51
+ rows than `batch`, so a small experiment is gone after one call instead of after a scheduled
52
+ follow-up pass. It still returns the child rows removed by that pass.
53
+ - A `logExposure` that enrolls a subject updates its variant tally once instead of twice (same
54
+ counts, one write fewer).
55
+ - `engines.node` moved from `>=18` to `>=20`, because the oldest supported `convex` peer (1.45) needs
56
+ Node >=20. The `convex` peer range stays `^1.45.0` and `react >=18` stays an optional peer
57
+ (both unchanged).
58
+ - Rework the README for coding agents (fixed section order, type-checked examples, an errors table,
59
+ a limits list, "For coding agents" and "Related packages" sections) and rewrite `docs/API.md` with
60
+ one heading per export. `llms.txt` is the single LLM index; the generated `llms-full.txt` is gone.
61
+ - Package metadata: `description` and `keywords` match the code, and `homepage` points at
62
+ `https://oss.vllnt.com/packages/convex-experiments`.
63
+ - Internal: CI, publishing, tests and dev tooling hardened and upgraded; the CI and publish
64
+ workflows install pnpm with Corepack instead of an outside action, the privacy guard pins its
65
+ GitHub actions to commit SHAs, the Renovate config is gone (dependency updates are a manual pass
66
+ under the 7-day rule), and `jsdom` and `@testing-library/react` are no longer dev dependencies (the
67
+ React hook tests render with `react-dom/server`); every push to `main` now publishes a canary,
68
+ whichever files it changes; no effect on the published API.
69
+
70
+ ### Removed
71
+
72
+ - Test files (`src/**/*.test.*`, `src/**/*.spec.*`) are no longer in the published package.
18
73
 
19
74
  ### Fixed
20
75
 
76
+ - Weighted splits now hold for similar or sequential `subjectRef`s. The bucket hash had no final
77
+ mixing, so refs such as `u0..u199` landed next to each other: on a real backend a 90:10 split gave
78
+ 200/0 and a 1:1 split over `u0..u19` gave 20/0. Random UUIDs were not skewed.
21
79
  - Correct shipped doc comments: `results` returns a zeroed row per defined variant (not `[]`) for an
22
- experiment with no enrollment, `weight` is never `0`, and `setStatus` returns `true` whenever the
23
- experiment exists.
24
- - **Breaking:** Reject empty `scope`, `key`, and `subjectRef` identifiers in `define`, `setStatus`,
25
- `assign`, `logExposure`, `forgetSubject`, and `deleteExperiment` with
26
- `ConvexError({ code: "INVALID_ARGUMENT" })`, and an empty variant key in `define` with
27
- `INVALID_VARIANTS` (`reason: "empty_key"`). Callers passing an empty `scope`, `key`, `subjectRef`
28
- or variant key now get a `ConvexError` instead of success.
80
+ experiment with no enrollment, `weight` is never `0`, `setStatus` returns `true` whenever the
81
+ experiment exists, and `define` sets `status` on every call (omitting it on a re-define resets it
82
+ to the client `defaultStatus`).
29
83
  - Make the `/test` entry type-check for consumers using `moduleResolution: nodenext`: relative imports
30
84
  in `src/` use explicit `.js` extensions and `src/test.ts` references `vite/client` types.
31
85
  - `register()` from `/test` accepts a host app's `convexTest(hostSchema, modules)` instance. It was
32
86
  typed against the component's own schema, so any host schema with other tables failed with TS2345.
33
87
 
34
- ### Changed
35
-
36
- - `engines.node` is now `>=20`, matching the oldest supported `convex` peer (1.45 requires Node
37
- >=20; 1.51 requires >=22).
38
- - Rework the README for coding agents (fixed section order, type-checked examples, an errors table
39
- and a limits list), rewrite `docs/API.md` with one heading per export, refresh `llms.txt`, add
40
- TSDoc to every public export, and set the `description` and `keywords` to match the code.
41
- `pnpm test:package` now also runs `scripts/check-docs.mjs`, which enforces these docs.
42
- `pnpm typecheck:ci` now also type-checks `example/` and the tests.
43
- - `deleteExperiment` deletes the definition in the same pass once every child table returns fewer rows
44
- than `batch`, which can save the final scheduled mutation of a delete.
45
- - `define` and `setStatus` skip the write when nothing changed, so idempotent re-defines no longer
46
- invalidate `peek`/`getExperiment`/`results` subscriptions.
47
- - The first `logExposure` for a subject updates its variant tally once instead of twice.
48
- - Clarify installation and usage documentation; retain `llms.txt` as the single
49
- maintained LLM index and remove the generated `llms-full.txt` bundle.
50
- - Adopt pnpm 10 with a seven-day release-age gate and blocked dependency install scripts; drop
51
- dependency overrides that no longer change the lockfile.
52
- - Develop and test against `convex` 1.51 and `convex-test` 0.0.73, and move the development
53
- toolchain to ESLint 10, jsdom 31, `@vllnt/typescript` 3 and Vitest 5.1.1. The `convex` peer range
54
- (`^1.45.0`) is unchanged.
55
- - Publish `@latest` only from a `vX.Y.Z` tag on `main` (npm trusted publishing with provenance); pin all
56
- workflow actions and scope their permissions. No local publish scripts remain.
57
- - Exclude test files from the published package.
58
- - Publish a canary on every push to `main` that touches the package or its shipped docs, and remove the
59
- repository-variable gate. The canary job still publishes under the `canary` dist-tag
60
- only and never moves `latest`; the `homepage` now points at `https://oss.vllnt.com/packages/convex-experiments`.
61
-
62
88
  ## [0.1.0] - 2026-09-01
63
89
 
64
90
  ### Added
package/README.md CHANGED
@@ -336,7 +336,10 @@ host with `error instanceof ConvexError` and read `error.data.code`.
336
336
  | ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
337
337
  | `INVALID_ARGUMENT` | `scope must be non-empty` (or `key`, `subjectRef`) | A mutation got an empty `scope`, `key` or `subjectRef` string. Queries do not check this. | Pass non-empty strings; check the client `defaultScope` is not `""` |
338
338
  | `INVALID_VARIANTS` with `reason: "empty"` | `an experiment needs at least one variant` | `define` got `variants: []` | Pass at least one variant |
339
+ | `INVALID_ARGUMENT` | `scope must be at most 512 UTF-16 code units` (or `key`, `salt`, `subjectRef`) | New data over the limit: `define` with a new `scope` or `key`, or a new or changed `salt`; `assign` or `logExposure` with a new `subjectRef` | Keep identifiers within 512 UTF-16 code units (`string.length`; an emoji counts as 2) |
340
+ | `INVALID_VARIANTS` with `reason: "too_many"` | `an experiment has at most 100 variants` | `define` got more than 100 variants in a new or changed set | Pass at most 100 variants |
339
341
  | `INVALID_VARIANTS` with `reason: "empty_key"` | `variant keys must be non-empty` | A variant has `key: ""` | Give every variant a non-empty key |
342
+ | `INVALID_VARIANTS` with `reason: "key_too_long"` | `variant keys must be at most 512 UTF-16 code units` | A variant key is over 512 UTF-16 code units in a new or changed set | Shorten the variant key to at most 512 |
340
343
  | `INVALID_VARIANTS` with `reason: "non_positive_weight"` | `variant "<key>" weight must be a positive finite number` | A weight is `0`, negative, `NaN` or `Infinity` | Use positive finite weights (fractions are allowed) |
341
344
  | `INVALID_VARIANTS` with `reason: "duplicate_key"` | `duplicate variant key "<key>"` | Two variants share a key | Make variant keys unique |
342
345
  | `INVALID_BATCH` | `batch must be an integer between 1 and 500` | `deleteExperiment` got a `batch` that is not an integer in 1..500 | Omit `batch` (default 200) or pass an integer in 1..500 |
@@ -367,8 +370,10 @@ other errors of its own: absent experiments and wrong scopes return `null`,
367
370
  - The variant is computed from `scope`, `salt` (default: the experiment key),
368
371
  `subjectRef` and the ordered variants and weights, with a 32-bit FNV-1a hash
369
372
  over the UTF-16 code units (`charCodeAt`) of `"<scope>:<salt>:<subjectRef>"`,
370
- not its UTF-8 bytes. It is deterministic bucketing, not randomness or a
371
- secret: anyone who knows those inputs can compute a subject's variant.
373
+ not its UTF-8 bytes, followed by a 32-bit finalizer (murmur3 `fmix32`), so
374
+ similar or sequential refs such as `u1`, `u2` still split by the weights. It
375
+ is deterministic bucketing, not randomness or a secret: anyone who knows those
376
+ inputs can compute a subject's variant.
372
377
  - Every `logExposure` call adds 1 to `exposures`; there is no idempotency key, so
373
378
  a retried call counts again. `subjects` counts each subject once. `assign`
374
379
  alone adds to `assigned`, not to `subjects` or `exposures`.
@@ -380,13 +385,28 @@ other errors of its own: absent experiments and wrong scopes return `null`,
380
385
  the last pass, so a `running` experiment keeps enrolling meanwhile: stop it first.
381
386
  - `listExperiments` and `results` are not paginated. `listExperiments` reads
382
387
  every experiment in the scope; calls that omit `scope` use the client
383
- `defaultScope` (`"global"`), never all scopes.
388
+ `defaultScope` (`"global"`), never all scopes. Rows come back in creation
389
+ order within the scope (oldest first), not sorted by key.
384
390
  - `results` returns `[]` for an absent experiment and one zeroed row per defined
385
391
  variant before anyone enrolls.
386
392
  - Only mutations reject empty `scope`, `key` and `subjectRef` (`INVALID_ARGUMENT`).
387
393
  Queries do not validate them: `peek(ctx, key, "")` on a `running` experiment
388
394
  returns a real variant, the deterministic pick for the empty string.
389
- - The component sets no maximum length for keys, scopes or `subjectRef`.
395
+ - New data is capped: `scope`, `key`, `salt`, `subjectRef` and each variant key are
396
+ at most 512 UTF-16 code units, and an experiment has at most 100 variants. The
397
+ length is JavaScript `string.length`, not characters and not UTF-8 bytes: an
398
+ emoji counts as 2, so 256 emoji pass and 256 emoji plus one letter do not.
399
+ Exactly 512 passes; 513 throws `INVALID_ARGUMENT` (or `INVALID_VARIANTS` with
400
+ `reason: "key_too_long"` or `"too_many"`). The caps apply to `define` (a new
401
+ experiment, or a changed `variants` or `salt`) and to `assign` and `logExposure`
402
+ for a subject with no stored assignment. Queries (including `peek`) do not
403
+ check length.
404
+ - Data stored by 0.1.0 with a longer value stays readable. `setStatus`,
405
+ `forgetSubject`, `deleteExperiment`, a `define` that changes only `status`, and
406
+ `assign` or `logExposure` for a subject already stored keep working. A `define`
407
+ that changes `variants` or `salt` is checked as new data, even if it keeps the
408
+ old over-long value. For an existing experiment with a longer key or more than
409
+ 100 variants, define a new shorter key.
390
410
  - Scopes are namespaces, not authorization. The component reads no auth.
391
411
  - Timestamps (`createdAt`, `assignedAt`) are server time in ms; no method accepts
392
412
  a caller timestamp.
@@ -406,7 +426,9 @@ other errors of its own: absent experiments and wrong scopes return `null`,
406
426
  `>=22`. Check with `npm view convex@1.51.0 engines`. ES modules only.
407
427
  - `@vllnt/convex-experiments/test` ships as TypeScript source (`src/test.ts`) and
408
428
  needs `convex-test` and Vite's `import.meta.glob`, for example through
409
- `vitest`, with `vite/client` types.
429
+ `vitest`, with `vite/client` types. `convex-test` 0.0.72 and later require
430
+ `convex ^1.46.0`, so on `convex` 1.45 use `convex-test` 0.0.71 or older. Check
431
+ with `npm view convex-test@0.0.72 peerDependencies`.
410
432
 
411
433
  ## Testing
412
434
 
@@ -111,7 +111,10 @@ export declare class Experiments {
111
111
  * evenly). `salt` defaults to `key`; `status` to the client default (`running`).
112
112
  * Returns `{ created }` — `false` when an existing definition was updated. Status
113
113
  * transitions are always allowed; `variants`/`salt` are immutable once a subject
114
- * is assigned (throws `EXPERIMENT_LOCKED`).
114
+ * is assigned (throws `EXPERIMENT_LOCKED`). A new experiment needs `scope`, `key`
115
+ * and `salt` of at most 512 UTF-16 code units (`INVALID_ARGUMENT`); a new or
116
+ * changed variant set needs at most 100 variants (`INVALID_VARIANTS`, reason
117
+ * `too_many`) with keys of at most 512 (`key_too_long`).
115
118
  */
116
119
  define(ctx: RunMutationCtx, key: string, opts: DefineOptions & {
117
120
  variants: Variant[];
@@ -123,13 +126,16 @@ export declare class Experiments {
123
126
  /**
124
127
  * Enroll a subject and return the sticky variant. `{ variant: null }` when the
125
128
  * experiment is absent or not running; otherwise `{ variant, isNew }`, `isNew`
126
- * true only on the first persisting call.
129
+ * true only on the first persisting call. Throws `INVALID_ARGUMENT` for a new
130
+ * subject whose `subjectRef` is over 512 UTF-16 code units; a stored one replays.
127
131
  */
128
132
  assign(ctx: RunMutationCtx, key: string, subjectRef: string, scope?: string): Promise<AssignOutcome>;
129
133
  /**
130
134
  * Record an exposure (enrolling the subject if needed) and return their variant,
131
135
  * or `null` when the experiment is absent or not `running`. Repeated exposures
132
136
  * for one subject share one row; every call adds 1 to the variant's `exposures`.
137
+ * Throws `INVALID_ARGUMENT` when enrolling a new subject whose `subjectRef` is
138
+ * over 512 UTF-16 code units; a subject stored with a longer one still logs.
133
139
  */
134
140
  logExposure(ctx: RunMutationCtx, key: string, subjectRef: string, scope?: string): Promise<ExposureOutcome>;
135
141
  /** The experiment definition, or `null` if none exists. */
@@ -143,7 +149,7 @@ export declare class Experiments {
143
149
  * flicker-free first paint, then call `logExposure` to enroll + tally.
144
150
  */
145
151
  peek(ctx: RunQueryCtx, key: string, subjectRef: string, scope?: string): Promise<ExposureOutcome>;
146
- /** Every experiment in a scope, optionally filtered by `status`. */
152
+ /** Every experiment in a scope, optionally filtered by `status`, in creation order. */
147
153
  listExperiments(ctx: RunQueryCtx, opts?: {
148
154
  scope?: string;
149
155
  status?: ExperimentStatus;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,UAAU,EACV,aAAa,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GACd,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE;QACT,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YACE,KAAK,EAAE,MAAM,CAAC;YACd,GAAG,EAAE,MAAM,CAAC;YACZ,QAAQ,EAAE,OAAO,EAAE,CAAC;YACpB,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,gBAAgB,CAAC;SAC1B,EACD;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,CACrB,CAAC;QACF,SAAS,EAAE,iBAAiB,CAC1B,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,gBAAgB,CAAA;SAAE,EACxD,OAAO,CACR,CAAC;QACF,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE,EAClD,aAAa,CACd,CAAC;QACF,WAAW,EAAE,iBAAiB,CAC5B,UAAU,EACV,UAAU,EACV;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE,EAClD,eAAe,CAChB,CAAC;QACF,aAAa,EAAE,iBAAiB,CAC9B,UAAU,EACV,UAAU,EACV;YAAE,KAAK,E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AAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5C,OAAO,CAAC,MAAM,CAAC,CAMjB;CACF;AAED,YAAY,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,aAAa,GACd,CAAC"}
@@ -43,7 +43,10 @@ export class Experiments {
43
43
  * evenly). `salt` defaults to `key`; `status` to the client default (`running`).
44
44
  * Returns `{ created }` — `false` when an existing definition was updated. Status
45
45
  * transitions are always allowed; `variants`/`salt` are immutable once a subject
46
- * is assigned (throws `EXPERIMENT_LOCKED`).
46
+ * is assigned (throws `EXPERIMENT_LOCKED`). A new experiment needs `scope`, `key`
47
+ * and `salt` of at most 512 UTF-16 code units (`INVALID_ARGUMENT`); a new or
48
+ * changed variant set needs at most 100 variants (`INVALID_VARIANTS`, reason
49
+ * `too_many`) with keys of at most 512 (`key_too_long`).
47
50
  */
48
51
  define(ctx, key, opts) {
49
52
  return ctx.runMutation(this.component.mutations.define, {
@@ -65,7 +68,8 @@ export class Experiments {
65
68
  /**
66
69
  * Enroll a subject and return the sticky variant. `{ variant: null }` when the
67
70
  * experiment is absent or not running; otherwise `{ variant, isNew }`, `isNew`
68
- * true only on the first persisting call.
71
+ * true only on the first persisting call. Throws `INVALID_ARGUMENT` for a new
72
+ * subject whose `subjectRef` is over 512 UTF-16 code units; a stored one replays.
69
73
  */
70
74
  assign(ctx, key, subjectRef, scope) {
71
75
  return ctx.runMutation(this.component.mutations.assign, {
@@ -78,6 +82,8 @@ export class Experiments {
78
82
  * Record an exposure (enrolling the subject if needed) and return their variant,
79
83
  * or `null` when the experiment is absent or not `running`. Repeated exposures
80
84
  * for one subject share one row; every call adds 1 to the variant's `exposures`.
85
+ * Throws `INVALID_ARGUMENT` when enrolling a new subject whose `subjectRef` is
86
+ * over 512 UTF-16 code units; a subject stored with a longer one still logs.
81
87
  */
82
88
  logExposure(ctx, key, subjectRef, scope) {
83
89
  return ctx.runMutation(this.component.mutations.logExposure, {
@@ -114,7 +120,7 @@ export class Experiments {
114
120
  subjectRef,
115
121
  });
116
122
  }
117
- /** Every experiment in a scope, optionally filtered by `status`. */
123
+ /** Every experiment in a scope, optionally filtered by `status`, in creation order. */
118
124
  listExperiments(ctx, opts = {}) {
119
125
  return ctx.runQuery(this.component.queries.listExperiments, {
120
126
  scope: this.scopeOf(opts.scope),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAoGnF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,WAAW;IAWH,SAAS;IAVX,YAAY,CAAS;IACrB,aAAa,CAAmB;IAEjD;;;;;OAKG;IACH,YACmB,SAA+B,EAChD,OAAO,GAAuB,EAAE;yBADf,SAAS;QAG1B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC;QAC1D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,IAAK,cAA4B,CAAC;IAC9E,CAAC;IAEO,OAAO,CAAC,KAAyB;QACvC,OAAO,KAAK,IAAI,IAAI,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CACJ,GAAmB,EACnB,GAAW,EACX,IAA6C;QAE7C,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE;YACtD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAC/B,GAAG;YACH,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,GAAG;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa;SAC1C,CAAC,CAA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AO,CAAC,KAAK,CAAC;YAC1B,GAAG;YACH,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CACd,GAAmB,EACnB,GAAW,EACX,IAAI,GAAuC,EAAE;QAE7C,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,gBAAgB,EAAE;YAChE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAC/B,GAAG;YACH,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,oBAAoB;SAC1C,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,7 +1,10 @@
1
1
  /** Public TypeScript surface for the experiments client. */
2
2
  /** A weighted variant — an opaque variant key and its relative selection weight. */
3
3
  export interface Variant {
4
- /** The host's opaque variant key (e.g. `"control"`, `"treatment"`). */
4
+ /**
5
+ * The host's opaque variant key (e.g. `"control"`, `"treatment"`). At most 512
6
+ * UTF-16 code units (JavaScript `string.length`) in a new or changed variant set.
7
+ */
5
8
  key: string;
6
9
  /** Relative selection weight; the bucket width is `weight / sum(weights)`. */
7
10
  weight: number;
@@ -20,7 +23,8 @@ export interface DefineOptions {
20
23
  /** Namespace for this experiment. Defaults to the client `defaultScope`. */
21
24
  scope?: string;
22
25
  /**
23
- * Hash salt for deterministic assignment. Defaults to the experiment `key`.
26
+ * Hash salt for deterministic assignment. Defaults to the experiment `key`. At
27
+ * most 512 UTF-16 code units (JavaScript `string.length`) in a new or changed definition.
24
28
  * Fixed once any subject is assigned (changing it after enrollment throws
25
29
  * `EXPERIMENT_LOCKED`); to re-randomize, define a new experiment key.
26
30
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,oFAAoF;AACpF,MAAM,WAAW,OAAO;IACtB,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;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E,GACjB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEzD,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -9,8 +9,15 @@
9
9
  * tallies. Status transitions (start/stop) are always allowed. To re-randomize or
10
10
  * reweight after enrollment, define a new experiment key.
11
11
  *
12
- * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `scope` or `key` is empty.
13
- * @throws `ConvexError({ code: "INVALID_VARIANTS", reason })` for a bad variant set.
12
+ * **Size limits (new data only):** a new experiment needs `scope`, `key` and `salt`
13
+ * of at most 512 UTF-16 code units; a new or changed variant set needs at most 100
14
+ * variants whose keys are each at most 512. An update that changes neither
15
+ * `variants` nor `salt` is never rejected for the length of existing values.
16
+ *
17
+ * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `scope` or `key` is empty,
18
+ * or when `scope`, `key` or `salt` is over 512 UTF-16 code units (new data only).
19
+ * @throws `ConvexError({ code: "INVALID_VARIANTS", reason })` for a bad variant set;
20
+ * `reason` is `too_many` (over 100) or `key_too_long` (a key over 512) for the caps.
14
21
  * @throws `ConvexError({ code: "EXPERIMENT_LOCKED" })` when `variants`/`salt` change
15
22
  * after a subject has been assigned.
16
23
  */
@@ -30,7 +37,8 @@ export declare const define: import("convex/server").RegisteredMutation<"public"
30
37
  * Move an experiment to a new lifecycle `status`. Returns `false` when no
31
38
  * experiment exists for `(scope, key)`, `true` when it exists. Stopping an
32
39
  * experiment freezes enrollment (`assign` returns `{ variant: null }`) while
33
- * leaving recorded assignments and exposures intact.
40
+ * leaving recorded assignments and exposures intact. Applies no length limit, so
41
+ * an experiment stored with a longer `scope` or `key` can still change status.
34
42
  */
35
43
  export declare const setStatus: import("convex/server").RegisteredMutation<"public", {
36
44
  key: string;
@@ -42,6 +50,10 @@ export declare const setStatus: import("convex/server").RegisteredMutation<"publ
42
50
  * experiment is absent or not `running` (the host treats it as control). When
43
51
  * `running`, the first call deterministically picks and persists a variant
44
52
  * (`isNew: true`); later calls replay it (`isNew: false`). Time is server-sourced.
53
+ *
54
+ * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when an argument is empty, or
55
+ * when a new assignment's `subjectRef` is over 512 UTF-16 code units. A stored
56
+ * assignment with a longer `subjectRef` is still replayed.
45
57
  */
46
58
  export declare const assign: import("convex/server").RegisteredMutation<"public", {
47
59
  key: string;
@@ -61,6 +73,10 @@ export declare const assign: import("convex/server").RegisteredMutation<"public"
61
73
  * or `logExposure` created it. Later exposures bump the row's `count` and the
62
74
  * tally's `exposures` only (deduped per subject). `{ variant: null }`
63
75
  * when the experiment is absent or not `running`. Time is server-sourced.
76
+ *
77
+ * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when an argument is empty, or
78
+ * when enrolling a new subject whose `subjectRef` is over 512 UTF-16 code units.
79
+ * A subject already stored with a longer `subjectRef` can still log exposures.
64
80
  */
65
81
  export declare const logExposure: import("convex/server").RegisteredMutation<"public", {
66
82
  key: string;
@@ -76,6 +92,7 @@ export declare const logExposure: import("convex/server").RegisteredMutation<"pu
76
92
  * rows — decrementing the variant tallies accordingly. The GDPR right-to-erasure
77
93
  * primitive for a `subjectRef` that maps to a person. Returns `true` if anything
78
94
  * was deleted. Loop over `listExperiments` to erase a subject across a scope.
95
+ * Applies no length limit, so rows stored with a longer `subjectRef` can be erased.
79
96
  */
80
97
  export declare const forgetSubject: import("convex/server").RegisteredMutation<"public", {
81
98
  key: string;
@@ -87,7 +104,8 @@ export declare const forgetSubject: import("convex/server").RegisteredMutation<"
87
104
  * exposure, and tally row. Bounded: removes up to `batch` rows per table per pass
88
105
  * and self-reschedules until the children are drained, then deletes the definition.
89
106
  * Idempotent and safe to call on an absent experiment. Returns the rows removed
90
- * this pass.
107
+ * this pass. Applies no length limit, so an experiment stored with a longer `scope`
108
+ * or `key` can be deleted.
91
109
  */
92
110
  export declare const deleteExperiment: import("convex/server").RegisteredMutation<"public", {
93
111
  batch: number;
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAoJA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;GAyDjB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,SAAS;;;;oBAmBpB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,MAAM;;;;;aAzIG,MAAM;WAAS,OAAO;;;GA6J1C,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW;;;;;;;;GAyDtB,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;oBAyCxB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;;;;mBAiE3B,CAAC"}
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AA0LA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;GA4DjB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;;;;oBAmBpB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM;;;;;aAzJG,MAAM;WAAS,OAAO;;;GA6K1C,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW;;;;;;;;GAyDtB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,aAAa;;;;oBAyCxB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;;;;mBAiE3B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { ConvexError, v } from "convex/values";
2
2
  import { api } from "./_generated/api.js";
3
3
  import { mutation } from "./_generated/server.js";
4
- import { pickVariant } from "../shared.js";
4
+ import { MAX_ID_LENGTH, MAX_VARIANTS, pickVariant } from "../shared.js";
5
5
  import { assignResult, experimentStatus, exposureResult, variant } from "./validators.js";
6
6
  /** Reject empty identifiers: an empty scope/key/subjectRef would store a meaningless row. */
7
7
  function assertNonEmpty(fields) {
@@ -14,6 +14,41 @@ function assertNonEmpty(fields) {
14
14
  }
15
15
  }
16
16
  }
17
+ /**
18
+ * Reject an identifier longer than `MAX_ID_LENGTH` UTF-16 code units (JavaScript
19
+ * `string.length`). Called only where new data is written, never on a path that
20
+ * reads, updates the status of, erases or deletes rows that already exist.
21
+ */
22
+ function assertMaxLength(fields) {
23
+ for (const [name, value] of Object.entries(fields)) {
24
+ if (value.length > MAX_ID_LENGTH) {
25
+ throw new ConvexError({
26
+ code: "INVALID_ARGUMENT",
27
+ message: `${name} must be at most ${MAX_ID_LENGTH} UTF-16 code units`,
28
+ });
29
+ }
30
+ }
31
+ }
32
+ /** Reject a variant set over `MAX_VARIANTS`, or with a variant key over `MAX_ID_LENGTH`, and a salt over it. */
33
+ function assertDefinitionSize(variants, salt) {
34
+ assertMaxLength({ salt });
35
+ if (variants.length > MAX_VARIANTS) {
36
+ throw new ConvexError({
37
+ code: "INVALID_VARIANTS",
38
+ reason: "too_many",
39
+ message: `an experiment has at most ${MAX_VARIANTS} variants`,
40
+ });
41
+ }
42
+ for (const candidate of variants) {
43
+ if (candidate.key.length > MAX_ID_LENGTH) {
44
+ throw new ConvexError({
45
+ code: "INVALID_VARIANTS",
46
+ reason: "key_too_long",
47
+ message: `variant keys must be at most ${MAX_ID_LENGTH} UTF-16 code units`,
48
+ });
49
+ }
50
+ }
51
+ }
17
52
  /**
18
53
  * Reject a malformed variant set before any write: at least one variant, every
19
54
  * weight a positive finite number, and no duplicate variant keys. The thrown
@@ -109,6 +144,7 @@ async function ensureAssignment(ctx, experiment, subjectRef, now) {
109
144
  if (existing !== null) {
110
145
  return { variant: existing.variant, isNew: false };
111
146
  }
147
+ assertMaxLength({ subjectRef });
112
148
  const variantKey = pickVariant(experiment.variants, hashSalt(experiment), subjectRef);
113
149
  await ctx.db.insert("assignments", {
114
150
  scope: experiment.scope,
@@ -134,8 +170,15 @@ function variantsChanged(a, b) {
134
170
  * tallies. Status transitions (start/stop) are always allowed. To re-randomize or
135
171
  * reweight after enrollment, define a new experiment key.
136
172
  *
137
- * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `scope` or `key` is empty.
138
- * @throws `ConvexError({ code: "INVALID_VARIANTS", reason })` for a bad variant set.
173
+ * **Size limits (new data only):** a new experiment needs `scope`, `key` and `salt`
174
+ * of at most 512 UTF-16 code units; a new or changed variant set needs at most 100
175
+ * variants whose keys are each at most 512. An update that changes neither
176
+ * `variants` nor `salt` is never rejected for the length of existing values.
177
+ *
178
+ * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `scope` or `key` is empty,
179
+ * or when `scope`, `key` or `salt` is over 512 UTF-16 code units (new data only).
180
+ * @throws `ConvexError({ code: "INVALID_VARIANTS", reason })` for a bad variant set;
181
+ * `reason` is `too_many` (over 100) or `key_too_long` (a key over 512) for the caps.
139
182
  * @throws `ConvexError({ code: "EXPERIMENT_LOCKED" })` when `variants`/`salt` change
140
183
  * after a subject has been assigned.
141
184
  */
@@ -156,6 +199,8 @@ export const define = mutation({
156
199
  .withIndex("by_scope_key", (q) => q.eq("scope", args.scope).eq("key", args.key))
157
200
  .unique();
158
201
  if (existing === null) {
202
+ assertMaxLength({ scope: args.scope, key: args.key });
203
+ assertDefinitionSize(args.variants, args.salt);
159
204
  await ctx.db.insert("experiments", {
160
205
  key: args.key,
161
206
  scope: args.scope,
@@ -168,6 +213,7 @@ export const define = mutation({
168
213
  }
169
214
  const definitionChanged = variantsChanged(existing.variants, args.variants) || existing.salt !== args.salt;
170
215
  if (definitionChanged) {
216
+ assertDefinitionSize(args.variants, args.salt);
171
217
  const firstAssignment = await ctx.db
172
218
  .query("assignments")
173
219
  .withIndex("by_scope_experiment_subject", (q) => q.eq("scope", args.scope).eq("experimentKey", args.key))
@@ -196,7 +242,8 @@ export const define = mutation({
196
242
  * Move an experiment to a new lifecycle `status`. Returns `false` when no
197
243
  * experiment exists for `(scope, key)`, `true` when it exists. Stopping an
198
244
  * experiment freezes enrollment (`assign` returns `{ variant: null }`) while
199
- * leaving recorded assignments and exposures intact.
245
+ * leaving recorded assignments and exposures intact. Applies no length limit, so
246
+ * an experiment stored with a longer `scope` or `key` can still change status.
200
247
  */
201
248
  export const setStatus = mutation({
202
249
  args: { scope: v.string(), key: v.string(), status: experimentStatus },
@@ -221,6 +268,10 @@ export const setStatus = mutation({
221
268
  * experiment is absent or not `running` (the host treats it as control). When
222
269
  * `running`, the first call deterministically picks and persists a variant
223
270
  * (`isNew: true`); later calls replay it (`isNew: false`). Time is server-sourced.
271
+ *
272
+ * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when an argument is empty, or
273
+ * when a new assignment's `subjectRef` is over 512 UTF-16 code units. A stored
274
+ * assignment with a longer `subjectRef` is still replayed.
224
275
  */
225
276
  export const assign = mutation({
226
277
  args: { scope: v.string(), key: v.string(), subjectRef: v.string() },
@@ -249,6 +300,10 @@ export const assign = mutation({
249
300
  * or `logExposure` created it. Later exposures bump the row's `count` and the
250
301
  * tally's `exposures` only (deduped per subject). `{ variant: null }`
251
302
  * when the experiment is absent or not `running`. Time is server-sourced.
303
+ *
304
+ * @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when an argument is empty, or
305
+ * when enrolling a new subject whose `subjectRef` is over 512 UTF-16 code units.
306
+ * A subject already stored with a longer `subjectRef` can still log exposures.
252
307
  */
253
308
  export const logExposure = mutation({
254
309
  args: { scope: v.string(), key: v.string(), subjectRef: v.string() },
@@ -305,6 +360,7 @@ export const logExposure = mutation({
305
360
  * rows — decrementing the variant tallies accordingly. The GDPR right-to-erasure
306
361
  * primitive for a `subjectRef` that maps to a person. Returns `true` if anything
307
362
  * was deleted. Loop over `listExperiments` to erase a subject across a scope.
363
+ * Applies no length limit, so rows stored with a longer `subjectRef` can be erased.
308
364
  */
309
365
  export const forgetSubject = mutation({
310
366
  args: { scope: v.string(), key: v.string(), subjectRef: v.string() },
@@ -349,7 +405,8 @@ export const forgetSubject = mutation({
349
405
  * exposure, and tally row. Bounded: removes up to `batch` rows per table per pass
350
406
  * and self-reschedules until the children are drained, then deletes the definition.
351
407
  * Idempotent and safe to call on an absent experiment. Returns the rows removed
352
- * this pass.
408
+ * this pass. Applies no length limit, so an experiment stored with a longer `scope`
409
+ * or `key` can be deleted.
353
410
  */
354
411
  export const deleteExperiment = mutation({
355
412
  args: { scope: v.string(), key: v.string(), batch: v.number() },