Skip to content

fix(gateway): use entity cache for detail endpoints instead of DiscoveryManager#326

Merged
mfaferek93 merged 2 commits intomainfrom
fix/topic-source-component-404
Mar 30, 2026
Merged

fix(gateway): use entity cache for detail endpoints instead of DiscoveryManager#326
mfaferek93 merged 2 commits intomainfrom
fix/topic-source-component-404

Conversation

@mfaferek93
Copy link
Copy Markdown
Collaborator

@mfaferek93 mfaferek93 commented Mar 30, 2026

Summary

Detail handlers used DiscoveryManager::get_*() which re-discovers from ROS 2 graph on each call. This missed topic-source and synthetic components that are only present in the entity cache. List endpoints already used the cache, causing inconsistency: GET /components lists topic-source components but GET /components/{id} returns 404.

Switch all entity detail and relationship handlers to use ThreadSafeEntityCache.

Test plan

  • 58/58 integration tests pass (100%) locally
  • Test on M3 Pro robot: GET /components/imu should return 200 instead of 404

Fixes #319

Copilot AI review requested due to automatic review settings March 30, 2026 11:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Switches discovery detail/relationship handlers to use ThreadSafeEntityCache for entity lookups, fixing inconsistencies where entities listed from the cache could 404 on detail endpoints due to DiscoveryManager re-discovery.

Changes:

  • Replaced DiscoveryManager::get_area/get_component/get_app/get_function usage with ThreadSafeEntityCache lookups in multiple detail handlers.
  • Updated several relationship handlers to resolve related entity IDs via cache indexes and then fetch entity details from the cache.
  • Reduced reliance on per-request ROS graph re-discovery for affected endpoints.

@mfaferek93 mfaferek93 force-pushed the fix/topic-source-component-404 branch 2 times, most recently from c627a08 to f55921a Compare March 30, 2026 12:26
@mfaferek93 mfaferek93 self-assigned this Mar 30, 2026
…eryManager

Detail handlers (GET /areas/{id}, /components/{id}, /apps/{id},
/functions/{id}) used DiscoveryManager::get_*() which re-discovers
from ROS 2 graph on each call. This missed topic-source and synthetic
components that are only present in the cache (populated during
periodic discovery refresh).

Switch entity detail handlers to use ThreadSafeEntityCache which
already has the complete entity set including topic-source components.
List endpoints already used the cache, so this makes behavior consistent.

Relationship endpoints (contains, hosts, depends-on, subcomponents,
function-hosts) keep using DiscoveryManager for hierarchy resolution
and to return fresh discovery state (e.g., is_online status).

Fixes #319
@mfaferek93 mfaferek93 force-pushed the fix/topic-source-component-404 branch from f55921a to f79ccbb Compare March 30, 2026 13:36
@mfaferek93 mfaferek93 requested a review from bburda March 30, 2026 14:44
Copy link
Copy Markdown
Collaborator

@bburda bburda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues:

  1. handle_app_depends_on inner loop still uses discovery->get_app(dep_id) (see inline)
  2. No regression integration test - test_discovery_heuristic.test.py only tests list endpoints in runtime_only mode. A "list then detail" test for synthetic components would guard against this exact bug scenario.

handle_app_depends_on and handle_function_hosts used
discovery->get_app() for dependency/host lookups - same bug class
this PR fixes. Synthetic/topic-source apps would incorrectly show
as missing. Switch to cache.get_app() consistently.

Update test expectations: is_online now reflects cache state
(enriched during runtime linking) rather than discovery default.
@mfaferek93 mfaferek93 requested a review from bburda March 30, 2026 18:53
@mfaferek93 mfaferek93 merged commit d1e2234 into main Mar 30, 2026
17 of 18 checks passed
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.

Topic-source components return 404 on detail endpoint but appear in list

3 participants