All work
/ 02

Cross-Repository Code Intelligence

Core knowledge retrieval system for DD Cortex.

Engineering question

How can engineers discover and reuse existing implementations across dozens of repositories without relying on tribal knowledge?

Shipped
Cross-Repository Code Intelligence
Sole owner
read engine, discovery, guardrails
Internal platform
one capability inside DD Cortex
Shipped
hardened against live agent sessions
Zero clones
reads never touch developer disk

Overview

DD Cortex is an internal engineering assistant that helps developers work inside the organization's codebase. It is a larger product with multiple contributors. My work was one of its core capabilities: making the assistant able to read and reason across other repositories, not just the one the developer has open.

Before this, a developer working in repo A could ask the assistant anything about repo A. If the answer lived in repo B, a service another team owned, the assistant was blind to it, and the developer fell back on the organizational workflow: find out which team owns it, find the engineer who wrote it, schedule a knowledge transfer, read unfamiliar code, then start building.

I built the system that removed that dependency, so an engineer can reference another internal repository directly in conversation and get answers from its actual source.

My role

  • ·Designed the cross-repository read architecture, using server side git mirrors instead of local clones
  • ·Built repository discovery so the picker surfaces every repository the service can legitimately read
  • ·Built the mention and prompt layer that makes the capability visible to the model
  • ·Built the deterministic guardrail layer that corrects agent misbehaviour in code rather than in prose
  • ·Designed the error taxonomy that turns git failures into actions a model can take
  • ·Wrote the test coverage for the new subsystem

The challenge

The organizational problem came first. As the engineering organization grew, similar problems got solved repeatedly in different repositories. Discovering prior work depended on knowing who to ask. Knowledge lived in repositories and in people's heads, and neither was reachable without already knowing where to look.

The constraints ruled out the obvious solution. The natural instinct is to index everything locally. That was not available.

  • ·Repositories live in the organization's git server, and access differs by team. Not every engineer can read every repository.
  • ·Cloning every repository onto every developer machine is expensive to maintain, and would quietly bypass the access model.
  • ·The system had to read code through a bot token with read only scope, respecting the organization's existing permissions rather than inventing a parallel one.
  • ·Some repositories are large. One internal repository is 1.1 GB on its own.

So the requirement became. read repository B in place, from a central service, with the same access boundary the organization already enforces, and without ever putting repo B on the developer's disk.

A third constraint shaped more of the design than either of the above. The assistant runs on a self hosted model that follows instructions less reliably than frontier models. A capability that works when the model behaves correctly is not a shipped capability. Most of the engineering below exists to make wrong behaviour either impossible or self correcting.

System design

Organization git server
        │  read only bot token, allowlist gated
        ▼
Repository discovery ─────────────▶ @ mention picker in the editor
        │
        ▼
Server side bare mirrors, no working files on disk
        │
        ├── cheap path: git ls-tree and git show, for listing and reading
        └── expensive path: a materialized worktree for the one
        │                   directory scanning tool, bounded LRU
        │                   with disk eviction
        ▼
Tool layer (MCP) ─────────────────▶ semantic search over indexed repos
        │
        ▼
Extension host guardrails: reroute, dedup, search budget
        │
        ▼
Model answers about repo B. All edits stay in repo A.

The system was not designed in one pass. It moved through four stages, each forced by what the previous stage got wrong.

Stage 1: make cross-repository reads possible at all. Read tools gained an optional target repository parameter. When present, the backend created a mirror, checked out a full worktree, and read from that directory. It worked, and review found it unshippable: a full disk checkout to read a single file, an unbounded in memory cache, a network fetch on every call, and no timeouts anywhere. One hung clone could stall the agent indefinitely.

Stage 2: make it efficient and production safe. File reads and directory listings moved to reading directly from the bare mirror via git show and git ls-tree, with no checkout at all. Only the one tool that genuinely scans a directory still materializes a worktree, behind a bounded LRU that evicts from disk as well as memory. Fetches became TTL gated instead of per call. Every git operation got a timeout.

Stage 3: make it discoverable by humans and by the model. Typing @ already meant reference a local file, so referencing an external repository needed a distinct affordance. Following the typed prefix and picker pattern used by other tools engineers already know, a Repos section was added to the @ menu, populated live from the git server. Selecting one inserts a repository mention, which expands into an instruction block, and the system prompt gained cross-repository rules so the model knows the capability exists before any mention appears.

Stage 4: survive contact with a real agent. Live sessions produced a parade of failures that no amount of design review would have predicted. That stage produced most of the interesting engineering.

What live testing changed

Observed behaviourRoot causeFix
The model retried the same semantic search for ten minutesSearching an unindexed repository returns zero results, and the model could not distinguish no match from not indexed, so it assumed its query was badCount indexed points for the repository. When zero, return an explicit not indexed flag telling the model to stop searching and read files instead
The model called tools on a server named after the repositoryA weak model conflated the repository name with a tool server nameDeterministic auto reroute: recognise the intent, send it to the right server, inject the repository name as the missing argument, and return a note teaching the correct form
The model tried to clone the repository from a public host, and web searched itThe instruction block described what to do but never forbade the alternativesExplicit prohibitions plus literal example calls, because weak models copy examples far more reliably than they follow abstract rules
Valid cross-repository calls failed with "No workspace bound"A pre flight gate required a bound workspace, and ran before the tool ever saw its target repository argumentRemoved the gate for these tools, and replaced the misleading error with one that names the missing argument and shows an example
A 1.1 GB clone crashed with a file lock errorA 60 second timeout killed the clone mid flight, leaving a partial mirror, and recovery deleted it while the just killed process still held Windows file locksA separate, much longer timeout for first time clones, plus delete with backoff so lock races heal instead of crashing
Fixes appeared not to work after restartPersisted settings still pointed at the production endpoint, so calls reached a server without the new codeThe expected endpoint is recomputed on startup. A mismatched registration is dropped and re added, so environment drift self heals
Six consecutive searches with paraphrased queries, never reading a fileExisting loop detection compares identical parameters, so varied query thrash is invisible to itA search budget: nudge, then hard block, then escalate to the human. Reset by any read or pivot

Key engineering decisions

Read from mirrors, not checkouts. git show and git ls-tree read straight from git's object database. A single file read costs milliseconds and zero disk, against gigabytes for a full checkout. Only the tool that genuinely scans a directory pays for a worktree.

Separate the cheap resolve from the expensive materialize. Resolving a repository to a commit is always needed. Putting files on disk almost never is. Splitting those into two layers means the common path never subsidizes the rare one. Both share in flight deduplication, so five simultaneous requests for the same repository produce one clone.

One security gate, reused rather than reimplemented. The allowlist check lives in exactly one function, the same one already guarding repository binding. A second, subtly different copy is how access control drifts.

Errors are product surface, not exhaust. Raw git stderr is mapped to a taxonomy where each case tells the caller the single correct next action. Busy means wait and retry the same tool. Not found means the repository may exist but the bot lacks read access. Ref not found names the default branch to fall back to. This matters more with an agent consumer than a human one, because the model's instinct on an ambiguous error is to change strategy, and changing strategy is precisely what produced the invented servers and the clone attempts.

Correct the model in code where prompting is unreliable. Every tool call passes through one handler, which makes it the place where wrong calls can be deterministically fixed. Three guards live there: reroute a misaddressed call rather than failing it, catch consecutive identical calls with an escalating response, and cap consecutive searches that make no progress. Only consecutive repeats are caught, any other tool running in between invalidates the cache, and failed calls are never cached. Otherwise the retry after failure path would be broken by the guard meant to protect it.

Layer the defenses, and let each layer catch what the one above missed. Each rung exists because a real transcript proved the one above it insufficient.

RungMechanismCatchesCost when it fires
0Prompt rules and mention blockwrong intent, before it happensfree
1Auto reroutemisaddressed callsnone, the call still succeeds
2Error taxonomy and not indexed hintsdead ends the model cannot perceiveone wasted call
3Duplicate note with cached resultverbatim retryno network
4Hard duplicate error and search nudgepersistence past the notenone
5Search budget blockparaphrase thrashnone
6Escalation to the humaneverything elsehuman attention

Bound every cache, time limit every network call. An unbounded cache is a leak with a delay on it, and an untimed git call is a hung agent. Freshness windows turn per call costs into per window costs.

Fail soft at the UI edge. If discovery fails, the picker returns an empty section. The chat box never breaks because the git server had a bad moment.

Architecture:The repository as a database, not a directory

Outcome

Engineers can reference another internal repository directly in conversation and get answers grounded in its real source, without identifying the owning team, scheduling a knowledge transfer, or cloning anything locally. Reads happen server side through a read only token constrained by a single allowlist, so the organization's existing access model still governs what is visible. Edits remain confined to the workspace the developer actually has open.

The practical effect is that reuse becomes cheaper than reinvention. Prior work stops being something you have to already know about in order to find.

Lessons

Engineering knowledge is harder to retrieve than to generate. The bottleneck in a growing organization is rarely writing the code. It is discovering that the code already exists, understanding why it was built that way, and making that reachable by the next engineer who needs it.

Designing for a weak model is a different discipline than designing for a strong one. Instructions are a starting point, not a mechanism. The pattern that worked was three layers. Teach it, with self describing tools and literal examples. Tell it precisely what failed and what to do next. When it still misbehaves, correct it in code. Each layer exists because a real transcript proved the one above it insufficient.

Error messages are an interface, and agents are the least forgiving consumer of that interface. A human reading "No workspace bound" eventually figures out the real problem. A model reads it, concludes the capability is broken, and invents a workaround. Every ambiguous error I left in place came back later as a bizarre agent behaviour.

The organizational constraint was the interesting part of the problem. Search across repositories is a weekend project. Search across repositories that cannot be cloned, whose access differs by team, through a token with a deliberately narrow scope, is an architecture. The constraints were what made the design worth writing down.

Repository names, internal hostnames, and configuration details are omitted. The architecture and engineering reasoning are described as built.

Next project
/ 03

MS Capital — Portfolio Management Platform

Full-stack portfolio analytics & in-browser Excel for institutional clients