A unit test for your production experiment.

On every pull request, a real, throwaway Flagsmith boots in CI, runs your app's own tests against the change, and becomes the merge oracle: if your experiment stops counting users, the pull request fails and names the line.

Your coding agent renamed checkout_completed. Your tests passed. Headcount didn't.

  • Every Flagsmith user

    headcount lint, about one second, no tests, no Docker, no Flagsmith, catches 9 of 13.

  • Teams with end-to-end tests

    The full check, real Flagsmith in CI, catches 13 of 13 and names the line.

- uses: ayushagarwalhere/headcount/action@v1
  with:
    experiment: .headcount/experiment.json
    test-command: npx playwright test

See all 14 planted faults, each a live pull request

Left: the Flagsmith dashboard shows the PayPal button experiment as Running, with the show-paypal arm at 0.0% conversion. Right: the pull request check is red, and Headcount's annotation points at sample-app/public/app.mjs line 68: the metric expects checkout_completed, the app sends checkoutCompleted.
Flagsmith says Running. Headcount says broken, at line 68.

What only Headcount does

  1. Names the broken line.

    Not just a red check: the file and line that stopped the count, such as public/app.mjs:68.

  2. Suggests the fix.

    A one-click suggestion on the pull request. The author clicks Commit suggestion and the experiment counts again.

  3. Catches dashboard drift.

    A rollout change made in Flagsmith becomes a pull request against the committed experiment file, which Headcount then checks. Experiments as code, both ways.

Watch it count

Banding wheel, plan view: control · exposures 29 of 29 counted; control · Checkout Completion 0 of 23 counted; show-paypal · exposures 23 of 23 counted; show-paypal · Checkout Completion 0 of 16 counted1234
Up and Down move between stripes, Left and Right move one tick, Home and End jump to the first tick and the pin, P toggles plan and elevation, R replays.

FAIL

control: 29 exposures counted of 29 sent, 0 of 23 Checkout Completion counted.

Cause The event name does not match the metric exactly public/lib/store.mjs:5

Stock pipeline
unit tests pass / dashboard running
Headcount
Fails the PR
Boot to verdict
45.2 s
Tracers
52

Lab run of the Kiln & Co. sample against Flagsmith 2.295.2 with synthetic tracer identities, recorded by node faults/bench.mjs.

Fault dial · planted pull requests

How it works

  1. 1

    Boot

    Pinned open-source Flagsmith 2.295.2 from one compose file.

    docker compose

  2. 2

    Recreate

    Your committed export, rebuilt through the Admin API and started.

    POST …/experiments/ · …/start/

  3. 3

    Drive tracers

    Your own tests, as hc-‹run›-‹n› identities, 15 per arm by default.

    POST /api/v1/identities/ · /api/v1/events

  4. 4

    Refresh

    Exposures refresh and results refresh, once.

    …/exposures/refresh/ · …/results/refresh/

  5. 5

    Judge

    Four checks, each a number Flagsmith returned against a number Headcount sent.

    GET …/exposures/ · …/results/

Proof · planted-fault benchmark

Each row is one small pull request against the Kiln & Co. sample, run through the stock pipeline and through Headcount. Rows come from node faults/bench.mjs; synthetic tracer identities against a throwaway Flagsmith.

WheelPlanted pull requestCause it plantsPathStock pipelineLint (static)HeadcountCause namedBoot to verdict
No change (baseline)nonebrowserunit tests pass / dashboard runningcleanPASSESnone55.9 s
No change (baseline), checkout APInoneserver, local evalunit tests pass / dashboard runningcleanPASSESnone40.4 s
Use camelCase for analytics event names #1Event names match your metrics exactly, including case.browserunit tests pass / dashboard runningerror: event-nameFAILS THE PRThe event name does not match the metric exactly45.2 s
Report PayPal orders with their own completion event #2Event names match your metrics exactly, including case (here in one arm only).browserunit tests pass / dashboard runningerror: event-nameFAILS THE PRThe event name does not match the metric exactly49.5 s
Forget the shopper as soon as the order is placed #3The user is identified.browserunit tests pass / dashboard runningerror: unidentifiedFAILS THE PRThe user is not identified45.3 s
Identify the shopper lazily, at checkout #4The user is identified (before the experiment flag is read).browserunit tests pass / dashboard runningerror: identified-lateFAILS THE PRThe user is identified after the flag lookup44.9 s
Re-export the experiment after the variation was recreated through the API #5Every variation of the flag has a label.browserunit tests pass / dashboard runningerror: unkeyed-variationFAILS THE PRA variation has no key48.2 s
Rename the country trait to shipping_country #6The identity is inside the experiment's rollout (and its audience).browserunit tests pass / dashboard runningerror: outside-rolloutFAILS THE PRThe identity is outside the rollout or the audience59.3 s
Let the SDK batch events on its own timer #7Buffered events were sent before your application exited.browserunit tests pass / dashboard runningerror: not-flushedFAILS THE PREvents were still buffered when the app exited1 min 30 s
Record the conversion on the server, where ad blockers cannot drop it #8Event timestamps are within the accepted window.browserunit tests pass / dashboard runningerror: timestampFAILS THE PREvent timestamps are outside the accepted window1 min 11 s
Attach the receipt image to checkout_completed for the analytics team #9A batch over 2 MiB is rejected whole.browserunit tests pass / dashboard runningerror: batch-sizeFAILS THE PRAn event batch is over 2 MiB2 min 02 s
Read server-side analytics event names from the tracking plan file #10Event names match your metrics exactly, including case (the name is read from a JSON file at run time).server, local evalunit tests pass / dashboard runningcleanFAILS THE PRThe event name does not match the metric exactly39.3 s
Batch server events every five minutes and flush them in one exit hook #11Buffered events were sent before your application exited (close() is called, on a path the process never takes).server, local evalunit tests pass / dashboard runningcleanFAILS THE PREvents were still buffered when the app exited29.9 s
Quote shipping on the checkout options, with country codes in lower case #12The identity is inside the experiment's rollout (and its audience): the trait is set, with a value the segment does not match.server, local evalunit tests pass / dashboard runningcleanFAILS THE PRThe identity is outside the rollout or the audience38.9 s
Create Flagsmith identities only for shoppers who place an order #13The user is identified (before the experiment flag is read; here identify() moved to another module).browserunit tests pass / dashboard runningcleanFAILS THE PRThe user is identified after the flag lookup44.3 s
Wait for consent before identifying shoppers in Germany #14Not catchable here: the tests only ship to GB, so the broken path never runs in CI.browserunit tests pass / dashboard runningwarning only: unidentifiedPASSESnone57.5 s
No change (baseline)
Cause it plants
none
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
clean
Headcount
PASSES
Cause named
none
Boot to verdict
55.9 s
No change (baseline), checkout API
Cause it plants
none
Path
server, local eval
Stock pipeline
unit tests pass / dashboard running
Lint (static)
clean
Headcount
PASSES
Cause named
none
Boot to verdict
40.4 s
Cause it plants
Event names match your metrics exactly, including case.
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: event-name
Headcount
FAILS THE PR
Cause named
The event name does not match the metric exactly
Boot to verdict
45.2 s
Cause it plants
Event names match your metrics exactly, including case (here in one arm only).
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: event-name
Headcount
FAILS THE PR
Cause named
The event name does not match the metric exactly
Boot to verdict
49.5 s
Cause it plants
The user is identified.
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: unidentified
Headcount
FAILS THE PR
Cause named
The user is not identified
Boot to verdict
45.3 s
Cause it plants
The user is identified (before the experiment flag is read).
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: identified-late
Headcount
FAILS THE PR
Cause named
The user is identified after the flag lookup
Boot to verdict
44.9 s
Cause it plants
Every variation of the flag has a label.
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: unkeyed-variation
Headcount
FAILS THE PR
Cause named
A variation has no key
Boot to verdict
48.2 s
Cause it plants
The identity is inside the experiment's rollout (and its audience).
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: outside-rollout
Headcount
FAILS THE PR
Cause named
The identity is outside the rollout or the audience
Boot to verdict
59.3 s
Cause it plants
Buffered events were sent before your application exited.
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: not-flushed
Headcount
FAILS THE PR
Cause named
Events were still buffered when the app exited
Boot to verdict
1 min 30 s
Cause it plants
Event timestamps are within the accepted window.
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: timestamp
Headcount
FAILS THE PR
Cause named
Event timestamps are outside the accepted window
Boot to verdict
1 min 11 s
Cause it plants
A batch over 2 MiB is rejected whole.
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
error: batch-size
Headcount
FAILS THE PR
Cause named
An event batch is over 2 MiB
Boot to verdict
2 min 02 s
Cause it plants
Event names match your metrics exactly, including case (the name is read from a JSON file at run time).
Path
server, local eval
Stock pipeline
unit tests pass / dashboard running
Lint (static)
clean
Headcount
FAILS THE PR
Cause named
The event name does not match the metric exactly
Boot to verdict
39.3 s
Cause it plants
Buffered events were sent before your application exited (close() is called, on a path the process never takes).
Path
server, local eval
Stock pipeline
unit tests pass / dashboard running
Lint (static)
clean
Headcount
FAILS THE PR
Cause named
Events were still buffered when the app exited
Boot to verdict
29.9 s
Cause it plants
The identity is inside the experiment's rollout (and its audience): the trait is set, with a value the segment does not match.
Path
server, local eval
Stock pipeline
unit tests pass / dashboard running
Lint (static)
clean
Headcount
FAILS THE PR
Cause named
The identity is outside the rollout or the audience
Boot to verdict
38.9 s
Cause it plants
The user is identified (before the experiment flag is read; here identify() moved to another module).
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
clean
Headcount
FAILS THE PR
Cause named
The user is identified after the flag lookup
Boot to verdict
44.3 s
Cause it plants
Not catchable here: the tests only ship to GB, so the broken path never runs in CI.
Path
browser
Stock pipeline
unit tests pass / dashboard running
Lint (static)
warning only: unidentified
Headcount
PASSES
Cause named
none
Boot to verdict
57.5 s

Planted faults with a cause from the list: 13.

Stock pipeline caught before merge: 0 of 13.

Lint (static, no Flagsmith) failed the pull request: 9 of 13.

Headcount failed the pull request: 13 of 13; named the planted cause: 13 of 13.

Reading the wheel

Incised ticks
One per tracer Headcount sent into that arm. Cut into the clay: Headcount's own record.
Glaze
One stroke per ring, as long as the count Flagsmith returned for that arm. Flagsmith reports counts per arm, not per tracer.
Brass pin
Where the glaze should stop: what was sent. A green cap means that check passed.
Red hatch and flag
Sent, but not counted. The check failed for that arm.
Grey hatch
Unfinished journeys, accepted either way, or a value Flagsmith did not return: no reading, never a zero.
Tray
Chips for tracers Flagsmith quarantined because they saw more than one arm.

Limits

  • Sample ratio is reported, never asserted. Flagsmith leaves srm_p_value empty for experiments with a rollout (upstream Flagsmith/flagsmith#8798), so the row is informational.
  • Only what your tests reach. A fault on a path the tests never take cannot fail the check. The consent-gate case shows it: the tests ship to GB only, so Germany's broken path never runs in CI, and Headcount passes it.
  • Causes that only show in production, such as an ad blocker or a real traffic mix, are outside a CI check.

Set it up

Export the experiment once with headcount export; the admin credential stays on your machine. headcount export --check exits 1 when the live experiment has drifted from the committed file. Locally, the same check runs with node bin/headcount.mjs run --test-command "npx playwright test". GitLab: include gitlab/headcount.gitlab-ci.yml.

headcount lint is a static pre-flight that reads the source and the experiment file, with no Docker and no Flagsmith, and annotates the pull request before the full check has booted. It is a first opinion; the full run is the verdict. Measured by node faults/lint-bench.mjs: Lint flagged 9 of 13 (at error level, failing the lint step: 9 of 13); named the planted cause: 9 of 13. Findings on the unchanged baseline (false positives): 0.

InputDefaultWhat it does
test-commandnoneCommand that runs the tracer journey spec (for example npx playwright test tests/e2e/checkout.spec.mjs). Not needed with the http driver.
experiment.headcount/experiment.jsonPath to the committed experiment export.
working-directory.Directory of the app under test.
driverteststests (default) runs test-command; http repeats .headcount/journey.json against a service.
min-per-arm15Tracer identities per arm. 15 is enough for the verdict, which reads Flagsmith's per-arm counts.
full-resultsfalsetrue sends 60 tracers per arm (above Flagsmith's 50-identity floor) so the summary also shows lift and chance to win.
workers2Parallel test workers.
port8300Host port for the throwaway Flagsmith (the recording proxy uses port + 1).
cache-imagetrueCache the pre-migrated Flagsmith database image between runs.
artifact-namenoneName for the uploaded run record. Set it per matrix leg if the Action runs more than once in one job name.
basenoneGit ref the pull request is compared with, for file and line in causes. Defaults to the PR base branch.
linttruetrue (default) runs headcount lint first, a static pre-flight that annotates the PR in seconds while the full check runs; its findings do not decide the job. only runs lint alone (no Docker; the job fails on lint errors). false skips it.
lint-srcnoneComma-separated folders or files lint reads (default everything except node_modules, tests and build output).
lint-sarifnoneA path (for example headcount-lint.sarif) where lint also writes its findings as SARIF 2.1.0, for github/codeql-action/upload-sarif. Empty (default) writes none. See docs/lint-quickstart.md.
dashboard-screenshottruetrue (default) screenshots Flagsmith's own results page for the experiment before teardown (flagsmith-results.png in the report artifact), using the app's Playwright; skipped with a note when Playwright is not installed. Never changes the verdict. false skips it.
flagsmith-patchesnonesrm boots the pinned Flagsmith with one patched file mounted (a draft upstream fix), so Flagsmith returns srm_p_value and the sample-ratio row becomes a fifth check that fails below 0.001. Runs at least 120 tracers. Empty (default) runs stock Flagsmith, where that row is informational.
weekly-trafficnoneUsers a week who reach the code that reads the experiment's flag in production and match its audience segment, if it has one (for example 4000). On a red check the summary then says about how many users a week in each failing arm would go uncounted: this number x the committed rollout x the arm's split x the share the tracer run lost. Empty (default) adds no line. A value that is not a positive number adds a note and no line; it never fails the job. See docs/impact.md.
suggestionstruetrue (default) posts a one-click fix (a review comment with a suggestion block) when a cause sits on a line the pull request added and the fix is an exact edit of that line; pull_request events only. Needs permissions: pull-requests: write; without it the fix is still shown in the job summary. false turns it off.
pr-commenttruetrue (default) keeps one comment in the pull request conversation with the verdict (headline, cause with a link to the line, impact, per-variant counts, a link to the run), edited in place on every run; one comment per job leg, keyed on artifact-name. pull_request events only. Needs permissions: pull-requests: write; without it a note goes in the job summary and the job is unaffected. false turns it off.
github-token${{ github.token }}Token for posting suggestion review comments and the pull request comment.

How this differs from Flagsmith's sdk-spec

Flagsmith's sdk-spec also boots Flagsmith in CI and seeds it through the Admin API, to test that the SDKs behave. Headcount tests that your app, after this pull request, still produces events the engine counts for your experiment, and it reads the exposures and results endpoints to say so.