Skip to content

fix: distinct error message when a CouchDB database is missing - #554

Merged
DhavalRepo18 merged 3 commits into
mainfrom
feat/couchdb-error-classification
Sep 25, 2026
Merged

DhavalRepo18 merged 3 commits into
mainfrom
feat/couchdb-error-classification

Conversation

@ShuxinLin

@ShuxinLin ShuxinLin commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When a CouchDB-backed tool returns nothing, there are two different causes:

  1. Wrong key: the agent passed an asset, sensor, site or work order that doesn't match. It should correct the arguments.
  2. Missing database: the database was never loaded in this environment, or CouchDB is unreachable. No argument change will help.

Before this PR, both cases produced the same message ("unknown asset_id …", "no records …", "work order not found", "no failure_mode record …"). Agents would keep guessing IDs against a database that doesn't exist.

This PR keeps every wrong-key message as it is. In the missing-database case the tools now return:

the data source does not exist or is unreachable in this environment; the data is unavailable, do not retry with other arguments

The message never contains the database name. Response shapes are unchanged: ErrorResult still has just error.

How each server detects a missing database

Server Detection
iot _missing_db_error(db) runs db.check() (a HEAD request) only on the not-found and failure paths, before reporting an unknown key. It covers asset_detail, installed_sensors, measured_sensors, history, latest_reading, stream_extent, sensor_coverage, sensor_stats, asset_ids, assets and find_assets_by_sensors.
fmsr A 404 whose reason is "Database does not exist" is no longer treated as a missing failure-mode record.
wo CouchClient (get/put/delete/find/view) raises CouchError with the message above when the 404 reason is "Database does not exist.", instead of get returning None, which meant "not found".
vibration On "no data" and "no sensors", database_available() checks that the database exists before reporting missing data.

Notes for reviewers

  • The existence check runs only after a lookup has already failed or come back empty, so successful calls pay no extra cost.
  • wo: the missing-database CouchError surfaces as an MCP tool error (Error executing tool …: the data source does not exist …), not as an ErrorResult. get_failure_codes keeps its existing catalog-unavailable message.
  • fmsr only detects a missing database. Connection errors keep the existing database lookup failed … message.
  • iot sites() still falls back to ["MAIN"] when the asset registry is unavailable, so the telemetry tools keep working without it.

Type of Change

  • Infrastructure / Tooling Improvement

Testing & Validation

  • uv run pytest src/ -k "not integration": adds 9 tests, each asserting the wrong-key message and the missing-database message, and that the database name is not in the message. The same 19 tests fail on main and on this branch (they need a live CouchDB, or are unrelated evaluation/observability tests), so there are no new failures.
  • Not yet run against a live CouchDB.

A missing or unreachable database was reported the same way as a wrong key
(e.g. 'unknown asset_id', 'work order not found'). On not-found/failure paths
the iot, fmsr, wo and vibration servers now report that the database does not
exist in this environment and that retrying with other arguments won't help.

Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
@ShuxinLin
ShuxinLin force-pushed the feat/couchdb-error-classification branch from 5d9b8f2 to 6bbaba3 Compare September 25, 2026 20:12
@ShuxinLin ShuxinLin changed the title feat: separate wrong-key vs missing-DB errors in MCP servers fix: distinct error message when a CouchDB database is missing Sep 25, 2026
Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
…heck

Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
@DhavalRepo18
DhavalRepo18 merged commit 81265cb into main Sep 25, 2026
5 checks passed
Sagar-CK pushed a commit to Rohith-Kanathur/AssetOpsBench that referenced this pull request Oct 2, 2026
couchdb3.Database is falsy when its database does not exist (__bool__ sends
a HEAD request), so the `if not iot_db` / `if not fm_db` guards fired before
the missing-database message from IBM#554 and returned "IoT records database
not connected" / "database not connected". With CouchDB unreachable,
__bool__ raised instead.

Tool guards now go through _missing_db_error (FMSR: check()), helpers test
`is None`, and an unknown site is checked against a missing asset registry
first, since the registry falls back to ["MAIN"] when it cannot be read.

Signed-off-by: Shuxin Lin <linshuhsin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants