Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/code-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,43 @@ Two run attributes, served by `GET /api/runs/{run_id}` under `exploration`:
and without a `map_commit` shows how much exploration the map saves.

The replay case is `services/worker/src/passes/incidents/dg_code_map_kept_current.rs`.

## The installation's contract index

Beside each repository's map, CoderHelm keeps one index for the whole
installation: per repository, the contracts it exposes and the ones it uses
(HTTP endpoints, GraphQL root fields, events and queue messages, packages and
the symbols imported from them, environment variables). It is what tells a
run which other repositories a change reaches before it plans, codes or
reviews.

Code: `services/common/src/contracts.rs` (extraction, the record, the index,
pure) and `services/worker/src/passes/xrepo.rs` (what each step of a run reads
from it).

- **Built with the code graph.** The code graph's index pass extracts each
file's contracts with plain patterns, no model. A first build reads every
file; a push replaces only the changed files' entries. A repository with
no record yet (whatever its graph's state) is queued for a
contracts-only read when work in the installation starts, a few per
step, each at most once an hour.
- **One query per team.** Every record sits in one partition
(`pk = XC#{team}`, `sk = REPO#{owner/name}`, gzipped JSON), read in one
paginated query and kept in memory for ten minutes. What a change reaches
is worked out in memory, never by searching every repository.
- **Bounded.** A file over 256 KB is skipped, a pass reads at most 6,000
files, a file adds at most 80 entries and a repository holds at most 4,000
(environment reads, then imported symbols, go first). A stored record
stays under 300 KB. Imported symbols are kept only for packages some
repository of the installation exposes.
- **Read by every pass.** The planner's first message lists what its likely
files reach, and a plan that changes a contract another repository uses
either changes that repository too or says how it stays compatible under
`## Compatibility`. The coder's first message carries the consumers' own
lines (at most six excerpts). The reviewer raises a removed contract a
consumer still uses as a required finding. A pull request that touches
contracts others use carries a compatibility section. Every loop has
`find_consumers`.
- **Private stays private.** Reading is never limited. In a public
repository, nothing CoderHelm writes names a private repository or copies
its code; the incident page `xt` has the details.
18 changes: 18 additions & 0 deletions docs/incidents/xt_contract_change_reaches_every_consumer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# xt. `xt_contract_change_reaches_every_consumer`

**What happened:** PR work knew one repository at a time. A ticket asked a bookstore's orders service to return a book's price in cents and to retire an old route. The plan named the route and its test, the coder changed them, and the reviewer passed the pull request. Another repository's book page fetched that route, a reading app subscribed to an order event the same change renamed, and a shared types package described the old shape. Nothing in planning, coding, review or the pull request named any of them. The agents could have searched every repository; none did, and nothing made them.

**Why:** Knowing the rest of the installation was left to the model. The app map covers HTTP calls when a team has built it, and the read tools can search anything, but no step was given the other repositories a change reaches before it acted, and nothing checked the plan, the review or the pull request against them.

**The guarantee (invariants, enforced in code):**

- **An installation index, cheap and current.** For every repository of the installation, the contracts it exposes and the ones it uses: HTTP endpoints, GraphQL root fields, events and queue messages, packages and the symbols other repositories import from them, and environment variables (`common::contracts`). It is extracted with plain patterns by the code graph's index pass, which already reads the repository: a first build reads every file, a push replaces only the changed files' entries. All of a team's records sit in one partition and are read in one query, kept in memory for ten minutes. Every bound is a constant: file size, files per pass, entries per file and per repository, the stored record's size, links per answer, excerpts and characters per prompt. A repository with no record yet, whatever its graph's state, is queued for a contracts-only read (its graph and build status untouched), a few per step, each at most once an hour; so are the dependents of a package a pass newly exposes.
- **Planning.** The planner's first message lists what the ticket's likely files expose to other repositories and use from them. A plan whose files carry a contract another repository uses goes back once unless it changes every such repository (a group per repository, the multi-repository plan the run builds and links in merge order) or says how it stays compatible under `## Compatibility`.
- **Coding, fix rounds and CI rounds.** The coder's first message carries the consumers' own lines, read from each repository's default branch, so every round through the coder starts knowing its callers. A round a person asks for loads the same index.
- **Review.** The reviewer is shown each contract the change touches that another repository uses, and every contract the change removes or renames while a consumer still uses it is a required, blocking finding citing that consumer, whatever the model said. A removal is found by the patch's text, not by line numbers: a route moved to another method, a package renamed, a field or topic gone are each one. A rewrite that keeps the contract is not one. The reviewer's code graph covers the installation's other repositories too.
- **Shipping.** A pull request whose change touches contracts other repositories use, with neither those repositories in the run nor a compatibility section in its description, gets one, with every removed contract marked breaking.
- **Every loop can ask.** Every worker loop with tools has `find_consumers` over the index, and its prompt says to ask it before changing or explaining a contract.
- **No limit to one repository.** A source scan fails on a prompt that limits PR work to one repository, and on any graph registry PR work opens without the team's other repositories.
- **Privacy on every surface.** Reading stays unrestricted. Work posting to a public repository keeps every private read, from the tools and from what the index showed it, in memory and in a short-lived store item per installation, public repository and run; every loop waits for it to be stored, and the GitHub client reads it back before each write, so a write in a later invocation is held to an earlier read. A write tool whose input copies a private line, or names a private repository or a path read in one, is refused with the reason, and every text the GitHub client writes into that repository (pull request titles and bodies, commit messages, comments, reviews, release notes) has what came from a private repository taken out by the same leak check. The reviewer and the compatibility section say "a private repository of the installation" instead of a name. Visibility fails closed: when the installation's listing can't be read, or doesn't name a repository, that repository counts as private when it was read and as public when it is written to; only a target the listing names, and not as public, is private. A private repository's work may reference freely.

**Where it's enforced:** `common::contracts::{extract, Record, Index::links, Index::breaks, compat_section, team_index, answer}`, `common::repo_reach::{note_private, guard_public, code_refused}`, the worker's `passes::xrepo::RunContracts::{load, planner_section, plan_gaps, coder_context, review_section, break_findings, compat_note}` and `with_compat`, `passes::code_graph::{refresh_contracts, RepoGraphs::load_map, offer}`, `agent::reach::{offer, prompt, Exec}`, `agent::provider::converse_as` and `clients::github::public_payload`.
1 change: 1 addition & 0 deletions services/common/src/agent_policy/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub const BUILTIN: &[(&str, Risk)] = &[
("list_repos", Risk::Read),
("read_repo_file", Risk::Read),
("search_repo", Risk::Read),
("find_consumers", Risk::Read),
("github__read_file", Risk::Read),
("github__search_code", Risk::Read),
("github__list_directory", Risk::Read),
Expand Down
Loading