Some of our library styles turned into HEXes

We’ve been using a list of DS styles for more than a year now
Nobody touched them recently (as can be seen in the version history).

Without any apparent reason some of them (like random 30% of them) stopped working with Themer.
I started debugging the code and found out the Figma API fails to fetch them anymore.
I had a style applied on a node and then ran:

const selectedStyleId = figma.getStyleById(figma.currentPage.selection[0]['fillStyleId'])['key'];
figma.importStyleByKeyAsync(selectedStyleId)

and it errored out with failed to fetch a style message.

the styleId in that case was

33d8ce3c082bb23d23e4256016944b2a293c074e

I also noticed that it ran an additional XHR to Figma (non-broken styles did not)
https://www.figma.com/api/design_systems/library/styles/33d8ce3c082bb23d23e4256016944b2a293c074e
which returned this (note how that styleId is nowhere in the response):

{"error":false,"status":200,"meta":{"style":{"id":"362083602","style_type":"FILL","key":"adcfd4d53d8c33a7793d682d5f2c3d3b27f0e688","file_key":"eYNUPCCrHM5t5YjTvl4LZE","node_id":"116:17","content_hash":"22785:6","checkpoint_id":"1135521611787006261","name":"Dark/BG Secondary","user_id":"849938892417828899","created_at":"2020-10-01T05:40:12.007Z","updated_at":"2022-07-31T10:37:29.774Z","unpublished_at":null,"description":"Gray8","sort_position":"!x}}}}}}}qO","file_checkpoint_id":"1135521185588039512","meta":"{\"style_thumbnail\":{\"type\":\"FILL\",\"fillPaints\":[{\"type\":\"SOLID\",\"color\":{\"r\":0.08627451211214066,\"g\":0.10196078568696976,\"b\":0.12156862765550613,\"a\":1},\"opacity\":1,\"visible\":true,\"blendMode\":\"NORMAL\"}]}}","full_hierarchy_path":null,"library_hierarchy_path_id":"9303373","destination_key":null,"description_rt":null,"moved_by_figma":null,"type":"style","canvas_url":"/style/adcfd4d53d8c33a7793d682d5f2c3d3b27f0e688/canvas?ver=QDwEIUC2UAqNFIZoOlVYJ7","thumbnail_url":"/style/adcfd4d53d8c33a7793d682d5f2c3d3b27f0e688/thumbnail?ver=QDwEIUC2UAqNFIZoOlVYJ7","user":{"id":"849938892417828899","handle":"Noa Rotstein","img_url":"https://www.gravatar.com/avatar/1b4dbf43be4bbfdd5f1c4cb86cd9da5c?size=240&default=https%3A%2F%2Fs3-alpha.figma.com%2Fstatic%2Fuser_n_v2.png"},"team_id":"927833951696866624"},"file":{"creator_id":"560072608586365833","updated_at":"2022-07-11T11:53:52.218Z","key":"eYNUPCCrHM5t5YjTvl4LZE","name":"DA Library","description":null,"folder_id":"21588185","scheme":null,"track_tags":{"source":"forked"},"team_id":"927833951696866624","link_access":"org_view","trashed_user_id":null,"license":null,"parent_org_id":"695364532893973687","org_browsable":false,"thumbnail_url_override":null,"thumbnail_guid":"10998:168367","proto_link_access":"view","org_audience":true,"file_repo_id":"1044540155628988702","source_file_key":null,"source_checkpoint_id":null,"editor_type":"design","branch_checkpoint_id":null,"workspace_id":null,"has_file_link_password":false,"has_proto_link_password":false,"url":"https://www.figma.com/file/eYNUPCCrHM5t5YjTvl4LZE/DA-Library","edit_url":"https://www.figma.com/file/eYNUPCCrHM5t5YjTvl4LZE/DA-Library","prototype_url":"https://www.figma.com/proto/eYNUPCCrHM5t5YjTvl4LZE/DA-Library","viewer_export_restricted":false,"realtime_token":"/file-eYNUPCCrHM5t5YjTvl4LZE:1669779484:0:056527677b2e32d0c6d7dae9daa0244b41a2bea9","is_try_file":false,"created_at":"2021-01-19T10:13:27Z","deleted_at":null,"trashed_at":null}},"i18n":null};

Also the linkage stopped working. Updating the color in the library didn’t update it in consumers.

In attempt to resurrect those styles we unpublished and then published the library (of course testing beforehand on a test library that the linkage to styles restores in consumers when you publish the library back).
But as a result those corrupted styles turned into HEXes in all of the consumers.

This is now a critical issue in our DS blocking us from any further work.
Worst of all we don’t understand why and how that happened.