Glean's client_id appears to be regenerating more frequently than Legacy's client_id
Categories
(Toolkit :: Telemetry, defect, P1)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox163 | --- | affected |
People
(Reporter: chutten|PTO, Assigned: janerik, NeedInfo)
References
Details
Attachments
(6 external files)
We see 0.05% of Glean clients associated with 2 Legacy client_ids over the course of October 2026 (by "baseline" ping record of clients running versions of Fx148+). Which isn't nothing, but isn't a lot. We know the Legacy client_id isn't infallible, and we accept that. (It used to be much worse before bug 1697045 in Fx88.)
Looking the other way around, however, we see 0.6% of Legacy clients with just 2 corresponding Glean client_ids. (Just 2 to weed out any automated cases where we'd expect to see a single Legacy client_id with dozens to hundreds-of-thousands of clients. The figure for Legacy clients with any number of Glean client_ids > 1 is 0.72%.) This is an order of magnitude higher.
Recently, (bug 2039807, Fx160) we introduced code to match Legacy's behaviour of restoring the client_id across a Profile Refresh (aka Profile Reset). If we try to take that into account in the data (because the code hasn't yet reached release) we see the proportion of Legacy clients with just 2 corresponding Glean client_ids come to 0.28%.
This is quite a bit better and well below the 1% "give a damn threshold" for most analyses.
...if you count profiles. But if you define a "new profile" as "the first time you see a "baseline" ping with a given client_id", then the figure is rather higher. In a population of interest, Ben Saunders found this figure to be ~2% corresponding to a 4.5% increase in new profiles if you measure by Glean vs measuring by Legacy. This is higher than the 1% "give a damn threshold" even if you allow for ~40% of that being attributed to profile resets.
This bug is about investigating the size, scope, and possible origins of this data.
| Reporter | ||
Comment 1•16 days ago
|
||
First, some things this likely is NOT:
- OS - Each OS is affected and they even appear to be affected proportionally to their use in Firefox Desktop's user population. Even if they weren't, the numbers are high enough for each OS to be inconsistent with the idea that the problem is tied to running a particular one.
- Time-bounded or unique to a Version or Season - This effect easily goes back to June and shows the same seasonality as DAU. (NOTE: the supporting query uses
sample_id = 42to speed things up which will undercount any profiles that regenerate to a client_id that doesn't havesample_id = 42.) - Geo - We see this effect reported from countries around the world. Similar to OS, even if the data weren't roughly proportional to our userbase, it would be in enough areas to be inconsistent with the idea that this is some regional-specific configuration.
- Also rules out images being reused in datacentres, it being uniquely tied to high-spec or low-spec hardware, or configurations limited to specific usecases like internet cafes or university computer labs.
- Architecture - We see this across CPU architecture. Doesn't appear to be a quirk of a particular implementation of a standard library or filesystem.
- rkv-specific - The Glean SDK uses
rkvfor its db. It was found to be unreliable in odd ways that resulted in client_id regeneration discovered last year. This was addressed in code that made it to Firefox Desktop in bug 2004922 (Fx148 and some Fx147). The Glean SDK intends to switch to a sqlite-based storage backend and did switch Nightly over for about one week in September between bug 2047566 and bug 2074141. Counting Nightly regenerations are noisy, but there's no evidence that sqlite fixed the problem.
That's all the relevant pieces, plus a few more, from the things to check guide. This appears to be widespread across time and space, though infrequent (don't forget this is 0.28% of profiles over a month).
| Reporter | ||
Comment 2•16 days ago
|
||
Some background on how client IDs work in Legacy and Glean.
How client_id works in Legacy
Implemented in ClientID.sys.mjs, the Legacy Telemetry client_id is a longitudinally-stable identifier stored in a Firefox Desktop profile in two places: state.json in the datareporting directory within the profile data directory (e.g. <ProfD>/<some hash>.default/datareporting/state.json) and (since bug 1697045 in Fx88 circa 2021) the preferences store (e.g. <PrefF> aka <PrefD>/user.js which appears to be <ProfD>/user.js in most cases) as toolkit.telemetry.cachedClientID.
On startup, ClientID.sys.mjs looks for state.json and, if it finds it and it's valid, uses its value for the Legacy client_id. If that fails, it checks for a value in prefs and, if it finds it and it's valid, uses its value for the Legacy client_id. If both of those fail, a fresh value is constructed. (The used value is saved to both prefs and state.json.)
How client_id works in Glean
The Glean client_id is a uuid metric containing a longitudinally-stable identifier stored in the Glean SDK's database (<datadir>/db/data.safe.bin under rkv) and, since v66.2.0 (Fx148 circa Jan 2026), in client_id.txt (<datadir>/client_id.txt). Firefox Desktop puts <datadir> in <ProfD>/datareporting (which is next to state.json)).
How Glean attempts to maintain a stable value for client_id is documented in full in the docs but boils down to: prefer the value in the database if there, in client_id.txt if not, and generate a new one if it's in neither. It reports on its operation, including error cases, in metrics in the glean.health.* metric category.
| Reporter | ||
Comment 3•15 days ago
|
||
If we limit ourselves to a conservative subset of the likely affected population (find all Legacy clients with more than one Glean client, discount all whose first profile startup reason was "profile-reset", choose only the Legacy clients with exactly 2 Glean clients (to avoid weird, infrequent, automated cases), and then excluding the Glean clients that were firstrun (pre-regen)) we find that all of them show an error when attempting to read Glean's client_id.txt. Most of it file-not-found.
It wouldn't be unreasonable to assume that the db is having trouble, too, since the Glean SDK needs to fail to retrieve from both locations before it will regen. However, this is only the case for a small proportion of the affected clients in this subset. Less than 10% of the affected population shows a db in an exceptional state.
The overwhelming majority report a non-exceptional case: there is no data in the data dir at all.
So of course the Glean SDK is treating this like a new profile: to its ability to tell, it is. There is no client_id.txt, there is no db/ or events/ or anything anywhere in its datadir.
Next lines of investigation:
- We ought to be able to see if more than just Glean's datadir is missing by checking the Legacy record. The profile subsession counter is stored in
datareporting/times.jsonand so if the entiredatareporting/dir (or more) was removed, we'd see it reset. - Check to see if the affected population reports errors when attempting to write
client_id.txt. This may help us distinguish between something wiping the dir between runs and something preventing us from writing to the dir at all.
| Reporter | ||
Comment 4•15 days ago
|
||
At most 60% of affected clients (Legacy) show a number of "main" pings with profileSubsessionCounter = 0 that would be consistent with a theory that the whole datareporting/ dir was wiped between runs. So if Glean's data is being wiped by something, it isn't always wiping all of datareporting/ as it goes.
As for whether those same likely-affected clients are experiencing difficulties writing client_id.txt, broadly not.
As far as the Glean SDK is concerned, it's able to write the client ID successfully, and then the next time it starts it's being started in an empty, and thus new, directory. There's some evidence consistent with something wiping files from the datareporting/ dir between runs more broadly than just Glean's dir, but it's not as conclusive (though some of that may be due to my choice of a test that was easy to write and explain).
Current Theories
- Storage in Glean's data dir specifically, and
datareporting/broadly, is sometimes unreliable between runs of Firefox Desktop.- Supporting evidence ranges as far back as bug 1697045, with the queries presented in this bug also in support.
- Legacy's ability to restore its client ID from prefs is the reason for the difference in client ID stability between the two systems.
PrefFis either more durable thanProfD/datareporting/or its susceptibility to this storage failure is at least independent and serves as a second attempt.- This follows from Theory 1 and code inspection (summarized in comment#2): If
datareporting/is unreliable, but the Legacy client ID is stable, the only other place it lives is within prefs.
- This follows from Theory 1 and code inspection (summarized in comment#2): If
| Reporter | ||
Comment 5•12 days ago
|
||
I think we're going to have to break (or at least bend) one of the original design decisions for the Glean SDK and allow the value of the Glean client_id to leave the SDK core. If Firefox Desktop can't provide a directory that Glean can rely on to persist files between runs every single time, then in order to keep the client_id stable across runs we'll need to expose its value so it can be stored elsewhere.
( Once again: client_id is stable across runs in the overwhelming majority of cases. Glean's "health" pings from Firefox Desktop report successful initializations outweighing these cases by 4-5 orders of magnitude )
The time might be right for this, as the environment in which we made this decision was very different from today. We have better systems, tools, and processes to make this less likely to be misused like the Legacy client ID was in the past.
And once the Glean SDK provides a mechanism for reporting and accepting an external backup value for the client_id, FOG can do what Legacy does and stuff it in the prefs. If my theories are correct, this should take care of these cases directly. Like the bug 1994757 and bug 1996862 two-step, we can instrument the solution before actually enabling mitigation of the issue by it, making sure we fully understand the solution's effect on the important business Metrics before we commit to it.
Comment 6•12 days ago
|
||
Just chiming in becuase I had also been looking at this in the context of validating Glean for Nimbus, I did a bunch of digging and found some hints but nothing super concrete but here's what I found in case it's helpful:
- There's more than one cohort of 'mixing' going on, I think. Roughly a quarter to a third are long-lived concurrent ids: both Glean ids were first seen 6+ months earlier and are active on the same days, usually on different Firefox and OS versions, so most likely two machines sharing one Legacy id. They aren't regenerations in the window. Most of the rest are rotations, where the newer Glean id is first seen in the window. (query)
- Rotations start with an empty Glean directory: on the newer id's first health ping,
client_id.txtis file-not-found andinit_countis 1 nearly every time. (query) Whether the rest ofdatareporting/went too depends on timing. When the newer id first appears on a later day than the older id's last ping, Legacy's lifetimeprofileSubsessionCountergoes backward that day about half the time, against 4% for single-id clients. When the switch happens within one day, it's about 20%, so there it's mostly Glean's directory alone. Overall that fits your "at most 60%". (query) Small note: the counter lives indatareporting/session-state.json;times.jsonis in the profile root. - Up to the switch the old Glean id looks healthy (populated db, init_count in the hundreds), and its last Legacy session usually ends in a normal
shutdown. No crash pattern. - On comment 5: a prefs backup should cover the rotations, since prefs survive. It would also carry the Glean
client_idinto copied profiles, the waycachedClientIDdoes for Legacy, so the first cohort would collapse to one Glean id per Legacy id. Worth deciding whether that's wanted.
Also checked and ruled out: the one-time uploadEnabled read at FOG init (the at_init deletion-request is rare), selectable profiles, background tasks, the updater restart, dedicated profiles per install and downgrade protection.
| Reporter | ||
Comment 7•12 days ago
|
||
(In reply to Jared Lockhart [:jlockhart] from comment #6)
- Rotations start with an empty Glean directory: on the newer id's first health ping,
client_id.txtis file-not-found andinit_countis 1 nearly every time. (query) Whether the rest ofdatareporting/went too depends on timing. When the newer id first appears on a later day than the older id's last ping, Legacy's lifetimeprofileSubsessionCountergoes backward that day about half the time, against 4% for single-id clients. When the switch happens within one day, it's about 20%, so there it's mostly Glean's directory alone. Overall that fits your "at most 60%". (query) Small note: the counter lives indatareporting/session-state.json;times.jsonis in the profile root.
Thanks for that clarification. Got those two mixed up in my brain for no reason.
- On comment 5: a prefs backup should cover the rotations, since prefs survive. It would also carry the Glean
client_idinto copied profiles, the waycachedClientIDdoes for Legacy, so the first cohort would collapse to one Glean id per Legacy id. Worth deciding whether that's wanted.
Copied profiles'd carry the Glean client_id already, though, unless a profile copy doesn't take the whole ProfD?
Comment 8•10 days ago
|
||
Oh sorry no you're right, both carry through so if a copied profile has diverging ids they probably rotated before the copy.
| Reporter | ||
Comment 9•4 days ago
|
||
WIP
TODO: More Tests!
| Reporter | ||
Comment 10•3 days ago
|
||
| Reporter | ||
Comment 11•3 days ago
|
||
Updated•3 days ago
|
Comment 12•3 days ago
|
||
| Reporter | ||
Comment 13•3 days ago
|
||
Supposing this lands in m-c as smoothly as it has in autoland, the next steps that I foresee are these:
- Thursday: Use
firefox_desktop_live.health_v1to see what volumes of the variousglean.health.backup_client_id_statusare for pings whoseapp_build >= '<first buildid with>':- I expect this'll be of the form
SELECT DATE(submission_timestamp) AS received_day, status.key AS label, SUM(status.value) AS total FROM moz-fx-data-shared-prod.firefox_desktop_live.health_v1 CROSS JOIN UNNEST(metrics.labeled_counter.glean_health_backup_client_id_status) AS status WHERE submission_timestamp > '2026-11-25'though maybeTIMESTAMP_TRUNC(submission_timestamp, HOUR)would look more interesting - Expect 100%
noneto begin as we only begin storing the backups after the updates start the first time - Expect them to start giving way to
matchas folks restart their browsers over the course of the day and the code confirms that, most frequently, the backup is just the same as the value we successfully read from db andclient_id.txt - There should be minimal
parseandmismatchand basically zeroc0ffee. Instances of these should be investigated and explained as we should only ever store and load valid values, should only ever store and load values that match the one in the SDK (if the SDK has one), and should never get a hint ofc0ffee. - Just about every day we get reports from Nightly of potential instances of client_id regen of the type we expect to be able to fix with this change. How many depends of course in how you estimate it, with the low end being between 1-5 (if you limit first to Legacy clients with exactly two Glean clients) and the high end being ~30 (if you look at Legacy clients reporting exactly two Glean clients on a given submission date).
- If the number of
backup_onlyexceeds the number of estimated regens, this will need investigating and explaining.
- If the number of
- I expect this'll be of the form
- Friday: Repeat some of Step 1 to see whether things are still going as expected. If things appear to be going well, request uplift to Beta of these fixes. We'll probably also need to uplift bug 2089635 and bug 2095526 to make this happen.
- I'm reasonably confident this will be a safe uplift because v71.1.0 will have been in Nightly a week by then, and this fix is broadly just instrumentation.
- If this slips to Monday, that's not the end of the world, it'll just mean landing in Beta 4. But I'd like this code to reach the larger Beta population sooner so we can get more data on the rare phenomenon this intends to detect (and eventually fix) before we decide when to turn on mitigation.
- Next Week: Step 1 again: look at the data and validate that we're getting the numbers of the various cases that we expect. If everything looks good, create a rollout targetting Nightly to turn mitigation on. Establish that the mitigation works from Nightly-only data. Consider expanding (with DS' knowledge and consent) to Beta.
- December (but later than just "next week"): Step 1 but for Release. Then apply the mitigation rollout according to DS' wishes.
- Consider when to schedule the follow-up work to make the Glean SDK API tidier and apply the mitigation in code, allowing it to ride the trains.
ni?Jan-Erik who has very kindly volunteered to run this plan while I'm out the until next week.
Comment 14•2 days ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/d40a5d7e70cc
https://hg.mozilla.org/mozilla-central/rev/cd47fcc28d88
https://hg.mozilla.org/mozilla-central/rev/57fbfbe3c608
| Assignee | ||
Comment 15•2 days ago
|
||
Gonna keep this bug open to use for tracking and analysis.
Hasn't made it into a Nightly just yet I guess, but we got 3 data points (lol).
Query: https://sql.telemetry.mozilla.org/queries/132240/source
2x match, 1x none.
Will add the app_build filter once nightly is out.
| Assignee | ||
Updated•2 days ago
|
Updated•2 days ago
|
| Assignee | ||
Comment 16•2 days ago
|
||
first app build with the fix: 20261126095627
| Assignee | ||
Comment 17•2 days ago
|
||
I put together a yardstick dashboard for a live view: https://yardstick.mozilla.org/d/jrhxqrr/backup-client-id-status-live
I also updated my own client and checked in about:config: telemetry.fog.backup.client_id has the same client ID that pings that are going out have (checked by triggering a baseline ping in about:glean).
| Assignee | ||
Comment 18•2 days ago
|
||
We're getting a steady amount of none and match counts.
A single backup_only so far. I will check in tomorrow on this again.
| Assignee | ||
Comment 19•2 days ago
|
||
Oh and I went ahead and documented the cases so that people other than :chutten and I who wrote/read the code know what each label means: https://github.com/mozilla/glean/commit/8eb3a97f6fedbe770a6b8feab1f9f258ee473c1d
| Assignee | ||
Comment 20•1 day ago
|
||
Looking at the data again today, by hour and more finely (split by this instead of a full day because we barely have 24 h of data, so on a "by day" view there's one dot):
- Curve looks like a rollout does
- Started with mostly
none, then quickly followed up bymatch - By now
matchovertook thenonecases, as expected: we getnoneonce after the update, recurring clients then keep sendingmatch - There's a handful of
backup_onlycases reported. That would be the case where we apply that backupped ID again (once enabled). This is in line with what :chutten wrote above about the number of regen'd client IDs (I haven't rerun the earlier queries we had to estimate the numbers)
Data is now also available in the moz-fx-data-shared-prod.firefox_desktop.health dataset, though of course only one day worth of data.
In line with the plan above I will request uplift to beta.
| Assignee | ||
Comment 21•1 day ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D346163
Updated•1 day ago
|
| Assignee | ||
Comment 22•1 day ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D346164
Updated•1 day ago
|
Comment 23•1 day ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: Little direct impact to the end user, but unnecessary and undetected regeneration of the Glean client_id, which impacts our visibility into new users and retention
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: no
- Steps to reproduce for manual QE testing: -
- Risk associated with taking this patch: low
- Explanation of risk level: All code has been on Nightly, the bigger Glean update has been there for a week already. No new bugs in these new versions have been detected.
The client_id regen fix/mitigation has been verified using telemetry data in Nightly. - String changes made/needed?: -
- Is Android affected?: unknown
| Assignee | ||
Comment 24•1 day ago
|
||
The central idea is to afford Glean the same advantages Legacy enjoys
when internal recordkeeping of the client ID fails: the option of
reading it from the prefs store.
Original Revision: https://phabricator.services.mozilla.com/D345902
Comment 25•1 day ago
|
||
@janerik could you look at the cargo failures in the try run on the uplift
https://phabricator.services.mozilla.com/D346824
https://treeherder.mozilla.org/jobs?repo=try&revision=f6cbdc70d662102ae743385e43913c45e1b745ec&selectedTaskRun=D1XPUqzcReqeHNf6NTL2tA.0
Comment 26•1 day ago
|
||
Also, the bug is still open re: comment 15
Description
•