CMDB Relationships Read Backwards - edmozley/freeitsm GitHub Wiki
CMDB relationships read backwards in the AI summary and Network Mapper
Found by the 5.0.0 help audit · Module: CMDB, Network Mapper · Fixed in: 5.1.0 (changelog #2822) · Follows PR #297
What you saw
A relationship in the CMDB is stored one way round - VM-A runs on HOST-A - with an inverse verb for reading it backwards (HOST-A hosts VM-A). Two places put that into words the wrong way:
- The AI summary of an object (CMDB → an object → Generate). On a host, the AI was told "VM-A - hosts this", under the heading "What depends on this object". So it could write that a VM hosts its host, and it treated every incoming link as a dependency, whatever the relationship type meant.
- Network Mapper → Add related objects. In the Others → this object group the VM was labelled hosts, and the connector it then drew went VM-A → HOST-A with the label hosts - an arrow reading "VM-A hosts HOST-A".
The object page itself had the same mistake until PR #297 fixed it in 5.0.0. These were the two places it had not reached.
Why it happened
Both used the inverse verb for an incoming link, with the other object as the subject. The inverse only reads correctly with the current object as the subject ("this hosts VM-A"). Put after the other object's name, or on an arrow drawn from the other object, it says the opposite of what is stored.
The summary had a second fault of its own: it listed every incoming relationship under "What depends on this object". Whether a link carries a failure is a setting on the relationship type (When something fails), not a consequence of its direction - managed by or located in is not a dependency.
The fix
Every relationship is told as a sentence naming both ends, with the forward verb, source first - the same reading the object page has used since #297.
-
AI summary. The prompt-building moved out of
api/cmdb/generate_object_summary.phpintoincludes/cmdb_summary_prompt.php(cmdbObjectSummaryMessage()), so a test can read exactly what the AI is told. Incoming links are selected withrt.verb, notrt.inverse_verb, and listed with outgoing ones under Relationships (each reads source - verb - target):foreach ($outgoing as $r) $msg .= "- " . $obj['name'] . " " . $r['verb'] . " " . $r['name'] . " (" . $r['class_name'] . ")\n"; foreach ($incoming as $r) $msg .= "- " . $r['name'] . " (" . $r['class_name'] . ") " . $r['verb'] . " " . $obj['name'] . "\n";Property references get their own heading (Objects that point at this one through a property), and the system prompt's rule changed from "what depends on it ... count incoming relationships" to "Each relationship is given as a sentence - source, verb, target - so keep that direction exactly and never reverse it."
-
Network Mapper.
api/network-mapper/get_related_objects.phplabels an incoming row withrt.verb. The connectorcommitRelatedSelections()draws for it goes other → this, so VM-A → HOST-A now reads runs on.
Deliberately unchanged: the REST API's diagram suggestions (api/v1/resources/network_mapper.php) keep the inverse for incoming links, because each suggestion reads from the object being expanded (HOST-A hosts VM-A) - correct as it is.
Files
| File | Change |
|---|---|
includes/cmdb_summary_prompt.php |
New: cmdbObjectSummaryMessage(), the user message for an object's AI summary |
api/cmdb/generate_object_summary.php |
Calls it; the system prompt's direction rule |
api/network-mapper/get_related_objects.php |
Incoming rows labelled with the forward verb |
tests/cmdb-relationship-direction.php |
New, 8 checks |
How it was proved
tests/cmdb-relationship-direction.php on the test install makes a host, a VM and an app with runs on / hosts links, then checks:
- what the AI is told for the host (ZZ-VM (Server) runs on ZZ-HOST), never hosts this, and no "What depends on this object" heading;
- for the VM, both its own link and the link into it, each read source first;
- that the system prompt tells the AI never to reverse a sentence;
- the real
get_related_objects.phpendpoint, with a signed-in session: the VM is under incoming and labelled runs on.
Worth knowing
- 🔴 TRAP: anywhere a relationship is put into words or drawn as an arrow, use the forward verb with the source first. The inverse is only right with the current object as the subject - and a configured verb cannot be bent round "this" in every language anyway.
- The relationship-type settings now describe the inverse as how the link reads the other way round, used when you add it from the other end (changelog #2823).
Related: CMDB - Developer Guide · Network Mapper - Developer Guide · CMDB relationship wording - PR review · Bugs resolved