AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Tracing Cross-Service Dependencies with Sourcegraph Cody: A Multi-Repo Engineering Guide

王偉翔 · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Microservice sprawl is often where developer AI tools quietly fall apart. Most AI coding assistants perform admirably inside a self-contained repository, but the moment a breaking change occurs in an upstream authentication library or an asynchronous event payload changes in an order service, their context window hits a hard wall. They cannot see beyond the root of the active local IDE workspace. Developers are left manually grep-searching across dozens of cloned repositories or relying on outdated architectural diagrams.

Sourcegraph Cody takes a fundamentally different route. Because it sits directly on top of Sourcegraph’s enterprise code graph and universal code search, Cody can pull contextual awareness from multiple repositories simultaneously. At 365Finds, we evaluate developer tools based on how they survive real-world distributed architectures, not clean toy projects.

This guide breaks down how to configure, query, and verify cross-service dependencies across multiple repositories using Sourcegraph Cody, while outlining the architectural guardrails necessary to avoid context noise and hallucinations.


1. Architectural Foundation: How Cody Queries Across Repositories

Standard AI coding assistants rely primarily on local text chunking and vector embeddings generated from whatever project directory you opened in VS Code or JetBrains. If service-b consumes a protobuf definition housed in proto-contracts, a local assistant simply guesses or hallucinates the contract.

Sourcegraph Cody solves this through two distinct backend capabilities:

  1. SCIP (Sourcegraph Code Intelligence Protocol): Sourcegraph indexes codebases using SCIP—an open, language-agnostic standard that replaces older LSIF implementations. Language-specific indexers (scip-go, scip-typescript, scip-java, scip-python) analyze source trees at compile-time precision, emitting symbol identifiers for definitions, references, and implementations across package and repository boundaries.
  2. Server-Side Universal Code Search: When Cody queries a codebase, it does not merely pass your question to a large language model. It executes targeted queries against Sourcegraph’s centralized search index, combining keyword search, structural AST search, and the SCIP symbol graph into the retrieval pipeline before synthesizing the LLM prompt.
+-----------------------------------------------------------+
|                     Cody Chat / IDE                       |
|   Prompt: "@repo:org/orders @repo:org/billing trace RPC"   |
+-----------------------------+-----------------------------+
                              |
                              v
+-----------------------------------------------------------+
|                 Sourcegraph Backend Server                |
|  - SCIP Cross-Repo Code Intelligence                      |
|  - Universal Code Search Engine (Regex / AST / Symbols)   |
|  - Cody Context Filter (RE2 Access Policies)              |
+-----------------------------+-----------------------------+
                              |
                              v
+-----------------------------------------------------------+
|                   External / Local LLM                    |
|           (Claude 3.5 Sonnet / GPT-4o / Gateway)          |
|      Grounded Cross-Service Dependency Architecture       |
+-----------------------------------------------------------+

This structural awareness means Cody understands when a TypeScript client in one repository calls a Go gRPC service in another, provided both repositories are indexed on your Sourcegraph instance.


2. Prerequisites and Repository Indexing Setup

Before asking Cody to trace cross-service interactions, verify that your Sourcegraph instance and local editor extensions meet these baseline requirements:

To upload SCIP indexes in CI/CD pipelines (e.g., GitHub Actions or GitLab CI):

# Example for a Go microservice
scip-go
src code-intel upload -f index.scip

# Example for a TypeScript service
scip-typescript index
src code-intel upload -f index.scip

3. Step-by-Step Workflow: Tracing Cross-Service Dependencies

Step 1: Scope Multi-Repository Context in Cody Chat

Do not ask general cross-service questions without specifying context. Cody allows you to explicitly anchor remote repositories using @-mentions in the chat window.

  1. Open the Cody Chat panel in VS Code or JetBrains.
  2. Type @ in the prompt input field.
  3. Select Remote Repositories from the context dropdown menu.
  4. Search for and select the upstream producer repository (e.g., github.com/org/checkout-service).
  5. Type @ again and select the shared schema or consumer repository (e.g., github.com/org/payment-service and github.com/org/shared-proto).

Operational Note: Cody Enterprise currently allows up to 10 remote repositories to be linked simultaneously in a single chat context. In a microservices architecture with hundreds of services, you must strategically select the immediate blast-radius cluster (consumer, producer, shared contracts) rather than attempting to attach the entire fleet.


Step 2: Formulate Structured Dependency Queries

Vague queries like "how do these talk?" generate speculative prose. Instead, structure prompts around concrete integration mechanisms: contract schemas, RPC endpoints, and asynchronous event topics.

Scenario A: Tracing a gRPC / Protobuf Breaking Change

When modifying a field in a shared protocol definition:

@repo:github.com/org/shared-proto @repo:github.com/org/order-service @repo:github.com/org/fulfillment-service

We are planning to deprecate the `user_tier` field in `proto/order/v1/order.proto` and replace it with `membership_details.tier_code`.
1. Which RPC handlers in `order-service` populate this field?
2. Which client calls in `fulfillment-service` deserialize and depend on `user_tier`?
3. Provide the file paths and line numbers where breaking changes will occur if `user_tier` is removed.

Scenario B: Tracing REST API and HTTP Gateway Routing

When an API Gateway forwards traffic downstream to an internal service:

@repo:github.com/org/api-gateway @repo:github.com/org/user-profile-service

Trace the request path for `POST /v2/users/{id}/preferences`.
1. How does the gateway middleware authenticate and transform headers before forwarding to `user-profile-service`?
2. Where is the matching route handled in `user-profile-service`?
3. List any environment variables or service discovery URLs that bind these two services together.

Scenario C: Tracing Event Bus Topics (Kafka / RabbitMQ)

When services communicate asynchronously through message brokers:

@repo:github.com/org/billing-service @repo:github.com/org/notification-worker

Find the message schema published to the `billing.invoices.settled` topic in `billing-service`.
1. Show the publisher code and payload construction.
2. In `notification-worker`, locate the consumer group subscription for this topic.
3. Confirm if all fields emitted by the publisher are accounted for in the worker's deserializer struct.

Step 3: Verify Synthesis Against the Compiler Graph

Never trust LLM output blindly when auditing microservice blast radiuses. An AI assistant can easily confuse two endpoints with similar naming conventions.

Use Sourcegraph’s dual-interface verification:

  1. Check Cody’s Context Chips: In the Cody chat response, click on the Context pills displayed at the top of the message. Review which exact files and lines were retrieved. If Cody did not pull the client SDK or contract file, supply it manually using @filename.
  2. Jump to Definition / Find References: Right-click the symbol identified by Cody in your editor and choose Sourcegraph’s Find References. Verify that the cross-repository reference exists in the SCIP index. If SCIP confirms the link, Cody’s architectural narrative is grounded in real AST evidence.

4. Managing Noise and Compliance: Cody Context Filters

Allowing an AI model to query across all repositories creates two risks: leaking sensitive credentials or proprietary modules to external LLM providers, and polluting chat context with archived or deprecated microservices.

Sourcegraph Enterprise administrators should enforce Cody Context Filters (cody.contextFilters) in the site configuration using RE2 regular expressions:

{
  "cody.contextFilters": {
    "include": [
      {
        "repoNamePattern": "^github\\.com\\/acmecorp\\/(core-.*|shared-schemas|api-gateway)$"
      }
    ],
    "exclude": [
      {
        "repoNamePattern": ".*-deprecated$"
      },
      {
        "repoNamePattern": "^github\\.com\\/acmecorp\\/(secrets-vault|pci-compliance)$"
      }
    ]
  }
}

5. Architectural Trade-offs: The 365Finds Verdict

At 365Finds, our assessment is straightforward: Sourcegraph Cody is one of the very few developer AI assistants capable of meaningful cross-repository reasoning. For microservice refactoring, cross-team API handoffs, and onboarding into polyglot architectures, its SCIP-backed code graph provides a substantial productivity advantage over single-repo competitors.

DimensionSourcegraph Cody Multi-RepoSingle-Repo AI Assistants
Context ScopeUp to 10 indexed remote repositoriesActive IDE workspace folder only
Code IntelligenceSCIP compiler-accurate symbol graphFuzzy text embeddings / heuristic search
Microservice Dependency MappingNative across contracts, SDKs, and callsRequires manual copy-pasting or monorepo hacks
Enterprise GovernanceGranular RE2 context inclusion/exclusion filtersWorkspace-level ignore files (.cursorignore, etc.)
Licensing RequirementFull remote multi-repo requires EnterpriseStandard Pro / Free tiers often support full local features

Where Cody Has Blind Spots

Engineers must recognize Cody’s hard boundaries:

  1. Static vs. Runtime Telemetry: Cody analyzes static code topology. It cannot know if an endpoint is blocked by an ingress firewall, disabled by a LaunchDarkly feature flag, or routed dynamically via a service mesh (e.g., Istio Envoy filters) unless those configurations live directly in the indexed code repositories.
  2. Untyped Dynamic Payloads: If your microservices communicate via loosely typed JSON payloads across message queues without explicit schemas or TypeScript/Protobuf interfaces, Cody must fall back on keyword search heuristics rather than SCIP symbol maps.
  3. The 10-Repository Ceiling: In large enterprises running 300+ microservices, developers cannot ask Cody to "analyze the whole company." You must know enough about your target architecture to pick the relevant 5 to 10 repositories.

For static cross-service dependency tracing and contract audits, Sourcegraph Cody is a premier enterprise tool. Pair it with runtime distributed tracing (such as OpenTelemetry or Jaeger) to validate that what Cody traces in the code graph matches what actually executes in production.


References