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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

**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.
- **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. Each write is conditioned on the record's version: a pass that loses the race to another reads the newer record and merges its own files onto it, a few times at most, so overlapping passes never drop each other's entries. The branch's current head is the authority: before it writes, a pass reads the head again, and a pass whose commit isn't it never writes its view; it reads the files that changed between the two, either way, and writes at the head, whether the branch moved forward or was reset back. Each file's entries record the head they were read at. Turning the graph off empties the record with no commit, so turning it on reads every file again; one that keeps losing writes nothing, leaves the other's record intact and says so. 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.
Expand Down
42 changes: 38 additions & 4 deletions services/common/src/app_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,50 @@ where
P: Fn(Status, Option<i64>) -> PF,
PF: std::future::Future<Output = Result<bool, String>>,
{
for _ in 0..5 {
match write_versioned(5, read, put, change).await? {
Some(Versioned::Written(next)) => Ok(Updated::Written(next)),
Some(Versioned::Kept(cur)) => Ok(Updated::Kept(cur)),
None => Err("the map's build status kept changing; try again".into()),
}
}

/// What a versioned write came to.
pub(crate) enum Versioned<T> {
/// The new value was written.
Written(T),
/// The change didn't apply to the value as it is, which is kept.
Kept(Option<T>),
}

/// The one versioned-write loop in `common`: `read` gives the value and
/// its version, `change` the next value (or `None` to keep it), and `put`
/// writes it conditioned on the version read (`Ok(false)` when another
/// write came first, which reads again and asks `change` again). `Ok(None)`
/// when every one of `tries` lost the race: nothing was written, and the
/// stored value is the other writer's.
pub(crate) async fn write_versioned<T, R, RF, P, PF>(
tries: usize,
read: R,
put: P,
change: impl Fn(Option<&T>) -> Option<T>,
) -> Result<Option<Versioned<T>>, String>
where
T: Clone,
R: Fn() -> RF,
RF: std::future::Future<Output = Result<(Option<T>, Option<i64>), String>>,
P: Fn(T, Option<i64>) -> PF,
PF: std::future::Future<Output = Result<bool, String>>,
{
for _ in 0..tries {
let (cur, version) = read().await?;
let Some(next) = change(cur.as_ref()) else {
return Ok(Updated::Kept(cur));
return Ok(Some(Versioned::Kept(cur)));
};
if put(next.clone(), version).await? {
return Ok(Updated::Written(next));
return Ok(Some(Versioned::Written(next)));
}
}
Err("the map's build status kept changing; try again".into())
Ok(None)
}

/// Writes `next` if the status is still at `version` (`Ok(false)` if not).
Expand Down
Loading