UAT: UKOQueryInterface.get_resources_by_layer() always returns empty list — extracts resource IDs from wrong SPARQL binding key #5835

Open
opened 2026-04-09 10:25:38 +00:00 by HAL9000 · 2 comments
Owner

Bug Report

What Was Tested

UKOQueryInterface.get_resources_by_layer() in src/cleveragents/application/services/uko_query_interface.py — the method that returns resource IDs classified at a given UKO ontology layer.

Expected Behavior (from spec)

Per docs/specification.md §45519, UKOQueryInterface provides classify_resource(uri) returning a ClassificationResult with layer (0–3), primary_type, source_resource_id, and relationships. The get_resources_by_layer() method should return a list of resource ULIDs that have been indexed at the given layer.

Actual Behavior

get_resources_by_layer() always returns an empty list due to a bug in the binding key extraction.

Code location: src/cleveragents/application/services/uko_query_interface.py, lines 244–261:

bindings = self._graph_backend.query(
    self._project,
    f'SELECT ?s ?o WHERE {{ ?s {_LAYER_PREDICATE} "{layer}" }}',
)

resource_ids: list[str] = []
for binding in bindings:
    obj = binding.get("o", "")  # BUG: extracts from "o" key
    # Extract resource ID from uko://resource/<id> URI.
    if obj.startswith("uko://resource/"):
        resource_ids.append(obj[len("uko://resource/") :])

The bug: The SPARQL query selects ?s ?o where ?s is the subject (the UKO node URI) and ?o is the object (the layer number string). The code then tries to extract a uko://resource/ URI from binding.get("o", "") — but "o" contains the layer number (e.g., "2"), not the resource URI.

The resource URI is stored as a provenance triple: <uko_node_uri> uko:sourceResource <uko://resource/<id>>. To get the resource ID, the method should either:

  1. Query for ?s uko:sourceResource ?resource WHERE { ?s uko:layer "N" } and extract from the resource binding, OR
  2. Extract from the subject ?s binding and look up the uko:sourceResource predicate.

Reproduction: Index any resource, then call get_resources_by_layer(layer) — it always returns [] regardless of what was indexed.

Steps to Reproduce

from cleveragents.domain.models.acms.index_stubs import InMemoryGraphIndexBackend
from cleveragents.application.services.uko_query_interface import UKOQueryInterface

backend = InMemoryGraphIndexBackend()
backend.add_triple("local/proj", "uko://code/module/foo", "uko:layer", "1")
backend.add_triple("local/proj", "uko://code/module/foo", "uko:sourceResource", "uko://resource/01HQ8ZDRX50000000000000001")

qi = UKOQueryInterface(backend, "local/proj")
result = qi.get_resources_by_layer(1)
# Expected: ["01HQ8ZDRX50000000000000001"]
# Actual: []

Code Location

  • src/cleveragents/application/services/uko_query_interface.py, lines 244–261 (get_resources_by_layer)

Impact

Any ACMS context strategy that uses get_resources_by_layer() to discover resources by UKO layer will receive empty results, breaking layer-based context selection. This is a functional correctness bug in the UKO query interface.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report ### What Was Tested `UKOQueryInterface.get_resources_by_layer()` in `src/cleveragents/application/services/uko_query_interface.py` — the method that returns resource IDs classified at a given UKO ontology layer. ### Expected Behavior (from spec) Per `docs/specification.md` §45519, `UKOQueryInterface` provides `classify_resource(uri)` returning a `ClassificationResult` with `layer` (0–3), `primary_type`, `source_resource_id`, and `relationships`. The `get_resources_by_layer()` method should return a list of resource ULIDs that have been indexed at the given layer. ### Actual Behavior `get_resources_by_layer()` **always returns an empty list** due to a bug in the binding key extraction. **Code location**: `src/cleveragents/application/services/uko_query_interface.py`, lines 244–261: ```python bindings = self._graph_backend.query( self._project, f'SELECT ?s ?o WHERE {{ ?s {_LAYER_PREDICATE} "{layer}" }}', ) resource_ids: list[str] = [] for binding in bindings: obj = binding.get("o", "") # BUG: extracts from "o" key # Extract resource ID from uko://resource/<id> URI. if obj.startswith("uko://resource/"): resource_ids.append(obj[len("uko://resource/") :]) ``` **The bug**: The SPARQL query selects `?s ?o` where `?s` is the subject (the UKO node URI) and `?o` is the object (the layer number string). The code then tries to extract a `uko://resource/` URI from `binding.get("o", "")` — but `"o"` contains the layer number (e.g., `"2"`), not the resource URI. The resource URI is stored as a provenance triple: `<uko_node_uri> uko:sourceResource <uko://resource/<id>>`. To get the resource ID, the method should either: 1. Query for `?s uko:sourceResource ?resource WHERE { ?s uko:layer "N" }` and extract from the `resource` binding, OR 2. Extract from the subject `?s` binding and look up the `uko:sourceResource` predicate. **Reproduction**: Index any resource, then call `get_resources_by_layer(layer)` — it always returns `[]` regardless of what was indexed. ### Steps to Reproduce ```python from cleveragents.domain.models.acms.index_stubs import InMemoryGraphIndexBackend from cleveragents.application.services.uko_query_interface import UKOQueryInterface backend = InMemoryGraphIndexBackend() backend.add_triple("local/proj", "uko://code/module/foo", "uko:layer", "1") backend.add_triple("local/proj", "uko://code/module/foo", "uko:sourceResource", "uko://resource/01HQ8ZDRX50000000000000001") qi = UKOQueryInterface(backend, "local/proj") result = qi.get_resources_by_layer(1) # Expected: ["01HQ8ZDRX50000000000000001"] # Actual: [] ``` ### Code Location - `src/cleveragents/application/services/uko_query_interface.py`, lines 244–261 (`get_resources_by_layer`) ### Impact Any ACMS context strategy that uses `get_resources_by_layer()` to discover resources by UKO layer will receive empty results, breaking layer-based context selection. This is a functional correctness bug in the UKO query interface. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
Author
Owner

MoSCoW classification: Must Have

Rationale: This is a Priority/Critical bug — UKOQueryInterface.get_resources_by_layer() always returns empty list. The UKO (Unified Knowledge Ontology) query interface is a core component of the ACMS. A method that always returns empty results makes the entire layer-based resource querying non-functional. This blocks context assembly and knowledge graph features that are core to the v3.5.0 milestone.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner

MoSCoW classification: **Must Have** Rationale: This is a `Priority/Critical` bug — `UKOQueryInterface.get_resources_by_layer()` always returns empty list. The UKO (Unified Knowledge Ontology) query interface is a core component of the ACMS. A method that always returns empty results makes the entire layer-based resource querying non-functional. This blocks context assembly and knowledge graph features that are core to the v3.5.0 milestone. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 added this to the v3.4.0 milestone 2026-04-09 13:53:47 +00:00
Author
Owner

Milestone compliance fix applied:

  • Assigned to milestone: v3.4.0 (ACMS v1 + Context Scaling)
  • Reason: Issue is State/Verified but had no milestone. UKOQueryInterface is part of the ACMS/UKO system which belongs to v3.4.0 scope.

Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: backlog-groomer

Milestone compliance fix applied: - Assigned to milestone: **v3.4.0** (ACMS v1 + Context Scaling) - Reason: Issue is `State/Verified` but had no milestone. `UKOQueryInterface` is part of the ACMS/UKO system which belongs to v3.4.0 scope. --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: backlog-groomer
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#5835
No description provided.