Skip to content

fix: scope endpoint identity by project and honour the URL host when linking - #883

Merged
vitali87 merged 16 commits into
mainfrom
fix/host-aware-endpoint-identity
Jul 22, 2026
Merged

fix: scope endpoint identity by project and honour the URL host when linking#883
vitali87 merged 16 commits into
mainfrom
fix/host-aware-endpoint-identity

Conversation

@vitali87

@vitali87 vitali87 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Fixes #879.

ENDPOINT resources were keyed by METHOD /template alone, so two services exposing GET /health collapsed into one shared node with EXPOSES edges from both handlers, and any matching URL's trace fanned out to every service, including ones the call can never reach. The URL names its target service in the host (compose and cluster DNS use the service name) and that evidence was discarded.

Endpoint qns are now scoped by owning project (resource::ENDPOINT::<project>::METHOD /template, with a project property; EXPOSES always comes from within one project, so the owner is known at emission). The linker became host-aware: when the URL's hostname stem matches an indexed project's name stem (hash suffix stripped, underscores and dashes interchangeable), only that project's endpoints are candidates; a host matching no project keeps the full permissive fan-out, and legacy endpoint rows without a project stay linkable. This also stops unknown-lead (/**) templates in one project from tail-matching another service's URLs.

Verified live on a five-project graph (three fixture services plus fastapi/full-stack-fastapi-template and paurakhsharma/python-microservice-fastapi): the health-check trace now reaches only the addressed service, and every one of the seven caller-to-handler traces is exact, with zero cross-project fabrication.

RED then GREEN in commit history; combined with the direction gate from #881 in one linker pass.

Summary by CodeRabbit

  • New Features
    • Endpoint resources now include project ownership metadata and use project-scoped qualified names.
    • Host-aware endpoint linking now matches endpoints using a normalized project “stem,” while preserving legacy/unscoped fallback behavior.
  • Bug Fixes
    • Improved endpoint resolution and linking across differing host/project naming formats (including underscore vs. dash) and partially migrated graphs.
  • Tests
    • Updated and expanded endpoint extraction, endpoint identity/prefix resolution, and host-aware linking tests, including exclusion of other-project template tail matches.

@vitali87

Copy link
Copy Markdown
Owner Author

@greptile review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e92329f9-55ff-4fb3-9a72-88685235b306

📥 Commits

Reviewing files that changed from the base of the PR and between f59f213 and 5d60423.

📒 Files selected for processing (1)
  • codebase_rag/tests/test_endpoint_extraction.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • codebase_rag/tests/test_endpoint_extraction.py

📝 Walkthrough

Walkthrough

Endpoint resources now use project-scoped qualified names and project metadata. Live endpoint linking narrows candidates by normalized host and project stems while preserving legacy fallback behavior. Tests cover the updated identity and linking semantics.

Changes

Project-scoped endpoint resolution

Layer / File(s) Summary
Project-scoped endpoint identity
codebase_rag/parsers/endpoints.py, codebase_rag/tests/test_endpoint_extraction.py, codebase_rag/tests/test_endpoint_prefix_resolution.py
Endpoint qualified names, resource properties, live-resource aggregation, and relationship assertions now include project-scoped identity data.
Host-aware endpoint linking
codebase_rag/parsers/endpoints.py, codebase_rag/tests/test_endpoint_extraction.py
Network URLs select endpoints by normalized host and project stems, with fallback behavior and legacy metadata handling covered by tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EndpointResources
  participant link_endpoints
  participant NetworkURL
  EndpointResources->>link_endpoints: provide endpoint identity and project
  NetworkURL->>link_endpoints: provide hostname and URL template
  link_endpoints->>link_endpoints: compare normalized host and project stems
  link_endpoints->>NetworkURL: create matching RESOLVES_TO edges
Loading

Possibly related issues

  • Issue 879: Adds the per-project endpoint identity and host-aware linking described by the issue.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, but it omits the required Summary, Type of Change, Test Plan, and Checklist sections. Reformat the PR description to match the template, adding the missing sections with bullets, checkboxes, and brief test details.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: project-scoped endpoint identity and host-aware linking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/host-aware-endpoint-identity

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR scopes endpoint linking to the service named by each URL host. The main changes are:

  • Project-scoped endpoint qualified names and ownership properties.
  • Host-aware endpoint candidate selection with normalized project names.
  • Compatibility for project-less endpoint rows in partially migrated graphs.
  • Tests for project isolation, fallback behavior, and project-name edge cases.

Confidence Score: 5/5

This looks safe to merge.

The legacy-row fix keeps project-less endpoints linkable when a host matches a scoped project. The project-name fix removes only the final generated suffix. No blocking issues were found in the changed code.

T-Rex T-Rex Logs

What T-Rex did

  • Ran the contract-validation harness to compare the pre-change and post-change route-scoping and cross-project filtering, establishing apples-to-apples comparison.
  • Verified that after-state outcomes passed across all categories: scoped QN/project metadata, host match, unmatched fan-out, legacy-only, mixed legacy/scoped, unknown-lead exclusion, and double-underscore project match.
  • Confirmed the comparison harness executed at the same runtime scope and listed the exact emitted relationship targets in both runs.
  • Collected and inspected artifacts, including logs and the Python validation script, to support the validation findings.
  • Documented that the artifacts collectively enable review of the remaining before/after differences and the invariants observed by the harness.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/parsers/endpoints.py Adds project-owned endpoint identities, host-aware linking, and compatibility for legacy endpoint rows.
codebase_rag/tests/test_endpoint_extraction.py Adds tests for endpoint ownership, host filtering, fallback behavior, and legacy compatibility.
codebase_rag/tests/test_endpoint_prefix_resolution.py Updates endpoint identity extraction to account for the project segment.

Reviews (3): Last reviewed commit: "style: apply ruff format" | Re-trigger Greptile

Comment thread codebase_rag/parsers/endpoints.py Outdated
Comment thread codebase_rag/parsers/endpoints.py Outdated
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR scopes endpoint resources by project and uses URL hosts to narrow endpoint linking. The main changes are:

  • Project-qualified endpoint resource names and properties.
  • Host and project stem normalization for candidate selection.
  • Direction-aware and host-aware linker tests.
  • Updated prefix-resolution expectations for scoped endpoint names.

Confidence Score: 4/5

The host-aware linking path can still drop valid legacy links or fail to narrow realistic service hosts.

  • Mixed old and new endpoint rows exclude matching legacy routes.

  • Project names containing __ are reduced to the wrong service stem.

  • Kubernetes fully qualified service names fall back to cross-project fan-out.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex attempted the focused mixed owned-and-legacy endpoint repro harness but hit environment blockers and could not complete pytest collection due to an unavailable CMake executable required by pymgclient.
  • T-Rex ran the project-stem truncation repro harness; the endpoint linker produced two RESOLVES_TO targets, including an unrelated project, and the focused harness failed its single-edge assertion.
  • T-Rex ran the cluster FQDN bypass repro harness; the linker emitted two RESOLVES_TO edge batches (one to the intended host, one to an impossible endpoint), causing the focused pytest reproduction to fail due to multiple targets.
  • T-Rex validated health-endpoint normalization and confirmed that after the adjustment five health endpoints had distinct project-qualified names; both executable harness runs exited 0, and the focused pytest run recorded the exact command and environment collection blocker for verification.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/parsers/endpoints.py Adds project-scoped endpoint identities and host-aware filtering, with bugs in legacy selection and hostname normalization.
codebase_rag/tests/test_endpoint_extraction.py Updates endpoint expectations and adds direction, identity, host-matching, and legacy compatibility tests.
codebase_rag/tests/test_endpoint_prefix_resolution.py Updates prefix-resolution tests to extract identities from project-scoped endpoint names.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Network URL] --> B[Parse and normalize host]
C[Live endpoint resources] --> D[Normalize project names]
B --> E{Matching project endpoints exist?}
D --> E
E -->|Yes| F[Use matching project endpoints]
E -->|No| G[Use all endpoints]
F --> H[Check direction and path template]
G --> H
H --> I[Create RESOLVES_TO edges]
Loading
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
codebase_rag/parsers/endpoints.py:347
**Mixed Graph Drops Legacy Endpoints**

When a hostname matches any project-owned endpoint, `owned` becomes non-empty and this branch excludes every legacy endpoint whose `project` is null. During a partial migration, matching legacy routes therefore lose their existing `RESOLVES_TO` edges even though legacy rows are meant to remain linkable.

### Issue 2 of 3
codebase_rag/parsers/endpoints.py:318
**Project Stem Truncates Valid Names**

A project base name can itself contain `__`, such as `billing__worker`; its generated name becomes `billing__worker__<hash>`, but splitting at the first separator reduces the stem to `billing`. Requests to the corresponding `billing__worker` service then miss host scoping and retain cross-project fan-out.

### Issue 3 of 3
codebase_rag/parsers/endpoints.py:310-311
**Cluster FQDN Bypasses Host Scoping**

A Kubernetes URL such as `http://user-service.default.svc.cluster.local/health` yields the full hostname, which cannot equal the `user-service` project stem. The linker therefore falls back to all endpoints and can recreate the cross-project traces this change is intended to remove.

Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

Comment thread codebase_rag/parsers/endpoints.py Outdated
Comment thread codebase_rag/parsers/endpoints.py Outdated
Comment thread codebase_rag/parsers/endpoints.py
@vitali87

Copy link
Copy Markdown
Owner Author

@greptile review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@codebase_rag/tests/test_endpoint_extraction.py`:
- Around line 551-562: Update
test_project_stem_keeps_double_underscore_base_names to assert that the single
created link targets the order__worker__2adc9027 endpoint, not merely that one
link was created. Use the returned link/edge data from helper._link and preserve
the existing cardinality assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 78133c30-e084-413d-b05c-801e1aa07b92

📥 Commits

Reviewing files that changed from the base of the PR and between cab2174 and f59f213.

📒 Files selected for processing (2)
  • codebase_rag/parsers/endpoints.py
  • codebase_rag/tests/test_endpoint_extraction.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • codebase_rag/parsers/endpoints.py

Comment thread codebase_rag/tests/test_endpoint_extraction.py
@sonarqubecloud

Copy link
Copy Markdown

@vitali87
vitali87 merged commit 91136a5 into main Jul 22, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Shared ENDPOINT identity ignores the URL host, collapsing same-template endpoints across services

1 participant