Repository navigation
fix(fmsr): match failure-mode records on asset_class only - #553
Merged
ShuxinLin merged 2 commits intoSep 25, 2026
Merged
Conversation
- Look up records by comparing normalised asset_class values in Python instead of by _id. The loader keys docs as fm:<raw asset_class>, so classes like 'Hydraulic Pump' were unreachable by the lowercased key. - Normalise only case, punctuation and whitespace; stop stripping digits, which turned 'CO2 Compressor' into 'co compressor'. - Keep the stored asset_class name when updating a record. - Suggest close matches in the not-found error. Tests: FakeDatabase now returns copies from find() and enforces _rev conflicts like CouchDB; add coverage for write failures, concurrent updates, duplicate normalised classes and non-fm: _ids. Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
This was referenced Sep 25, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes two asset-class lookup bugs in the FMSR server.
1. Stored classes with capitals or punctuation could not be found. The CouchDB loader stores each record as
_id = "fm:" + asset_classusing the raw name (src/couchdb/loader.py:_make_id). The server lowercased the input and then matched exactly onfm:<key>and onasset_class == key. As a result, a record such as"asset_class": "Hydraulic Pump"was never found, andadd_failure_modescreated a duplicate record next to it. This stayed hidden because the only sample record is"pump".2. Digits were stripped from class names.
re.sub(r"\d+", "", ...)turnedCO2 Compressorintoco compressor,Type 2 Chillerintotype chillerand3-Phase Motorintophase motor.Fix Details
asset_classonly, never on_id. The server reads the records'asset_classvalues (a small collection, capped at 10,000) and compares the normalised names in Python._and whitespace, and leaves digits alone. The caller is expected to pass a real class name. Instance ids likePump-1are not rewritten.add_failure_modeskeeps the storedasset_classname when it updates a record. New records are still created asfm:<normalised name>._idwins, deterministically.asset_classdescription now tells the agent to pass a generic equipment type rather than an asset id (for "Chiller 6", use "chiller").get_failure_modessays to retry with a class suggested in the error.add_failure_modessays to reuse an existing class name where one fits, to avoid near-duplicate classes.Impact on Benchmarking
pump,Pumpandhydraulic_pumpbehave as before for the bundledpumpsample.Pump-1) no longer map topump. They now return a not-found error that suggestspump.Related Issues
Verification Steps
uv run pytest src/servers/fmsr -qpasses (32 tests).uv run pytest src/ -k "not integration": 19 failures, the same set that fails onmain(iottest_invalid_site,test_static_json_scorer,test_file_exporter). None are in fmsr.New tests cover:
_ids not in thefm:<class>form_idnever used for matchingaddupdating the matched record in placeTest gaps closed:
FakeDatabase.findreturned the stored dicts themselves, so write tests passed even ifsavewas never called. It now returns copies.FakeDatabasenow enforces_revconflicts the way CouchDB does.Checklist
ruff checkstill reports the file's existingList/Optionaltyping-style warnings (UP006/UP045).