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
15 changes: 15 additions & 0 deletions docs/incidents/xp_answers_read_the_other_repo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# xp. `xp_answers_read_the_other_repo`

**What happened:** A person asked on an API repository's pull request why a card read "Ages 1 - 4 years" when the data said 3 months to 4 years. CoderHelm's reply named the website's age formatter as the cause and said it couldn't open that formatter from this repository, so it hadn't confirmed the rounding. The website was another repository of the same team, and CoderHelm's GitHub app could read it.

**Why:** The round that answered had only the tools of the repository it worked in. Nothing told the model the installation's other repositories were readable, and nothing checked an answer that said it couldn't see something it never tried to read.

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

- Every worker model loop that is offered tools (the coder, every fix round, the reviewer, ticket replies, triage, skills) is also offered `list_repos`, `read_repo_file` and `search_repo`, read only, over every repository of the team's GitHub installation. They are added in the one place every worker loop starts, and a source scan fails on a worker loop that goes around it. Chat and team agents read the same repositories through their code tools.
- Every such system prompt says the team's whole installation is readable, and to look before answering.
- Text a person reads in which CoderHelm says, in the first person, that it can't see, open, access, read or confirm something is rejected before it is posted, unless a tool call in that same turn returned a refusal; then the line must name the repository or path and the refusal. Sentences about the code or the product are never read as such a claim. A loop's answer that fails is sent back once to look with the tools; a retry that fails or runs out of time never replaces the answer, and what still fails is taken out of the prose only. Code, data and structured output are never edited. The person-text check and the reply composer hold the same rule.
- A source scan fails on any prompt that tells the model it is limited to one repository.
- Content from a private repository never appears in text posted where people outside the installation can read it: a public repository's pull request, issue or comment. Reading stays allowed everywhere, so answers stay right. Repository visibility comes from the installation's repository list, and one it doesn't name as public counts as private. When a reply goes to a public repository, every read of a private repository in that turn is kept, and the reply is checked before it is sent: no line or code from those reads verbatim, and no private repository's name or path. A reply that trips the check is asked to state its conclusion in plain words; what still trips it is taken out, in prose and in structured replies alike. It never turns into "I can't see it". A reply in a private repository may quote what it read, and so may a reply in a public repository quoting another public one; a comment asking to paste a private file gets the conclusion only.

**Where it's enforced:** `common::repo_reach::{defs, call, prompt_for, claim, allowed, strip, look_first, refusal_in, leak, redact, conclusion_only}`, `common::repo_read::GitHubHost::{installation_repos, installation_listing}`, `common::rendered::person_text`, `common::reply_compose::finish`, the worker's `agent::reach::{offer, prompt, Exec, access, kept_answer, public_answer, is_public}` in `agent::provider::converse_as`, Chat's `brain::system_prompt` and `chat_agent::run`, and `tool_registry::BUILTIN`.
9 changes: 9 additions & 0 deletions docs/incidents/xq_own_modes_never_red_ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# xq. `xq_own_modes_never_red_ci`

**What happened:** A front-end fix's pull request also listed three shell scripts of the repository's CI as files it changed: a cleanup script, a stub command its tests put on the path, and the test that runs it. Merging the base into the branch had dropped their executable bit (before `xl`). The pull request's script tests failed while the base stayed green on them. The fix rounds ran `chmod +x` in the sandbox, called `restore_file` on the scripts several times, and deleted and wrote them again in a batch write. None of it reached the mode. After five rounds the run ended failed on red CI and was handed to a person, for a cause CoderHelm made itself.

**Why:** `restore_file` took the bytes from the ref and the mode from the branch, which had already lost it. No tool set a mode. Nothing compared the pull request's modes with the base when its checks were red and the base's green. The repair sweep of `xl` compared each CoderHelm commit with its parent only, where a delete followed by a write shows no drop. It took its runs from the description catch-up's picks, which skip runs in flight and every run whose description was already rebuilt, and it never set a failed run going again.

**The guarantee:** A check red on the pull request and green on the base first gets the mode diagnosis. Every file the pull request changes is compared with the merge base, and an executable, symbolic link or submodule that CoderHelm's commits turned into a plain file is put back in one commit, with no model round, and CI decides again. A mode CoderHelm dropped that it can't put back yet is its own problem: an internal alert, the run page's line, and a retry while the tries make progress. After three tries in a row that put nothing more back it stops retrying, records why once, and the run waits on CI. It is never `failed` on red CI and never a person's to-do. A sweep whose branch moved during the repair gives its claim back, so the pull request is read again. A path a person's commit changed is theirs and is left. `restore_file` restores the mode from the same ref as the bytes. `set_mode` sets a file's executable bit as a commit, or puts back the base's mode, and refuses symbolic links and submodules. A `chmod` in the sandbox says it never reaches the commit and names `set_mode`. The repair sweep compares each pull request with its base too, reads runs of every status a pull request can still be open under (failed runs first, runs in flight included), and resumes a run that ended on red CI once its modes are back.

**Where it's enforced:** `clients::git_mode::{mode_move, against_base}`, `GitHubClient::{set_mode, merge_base_and_files}`, `mode_repair::{stuck_step, base_plan, against_base, on_red, write_restore, picks, reads, set_mode_tool, set_mode_call, restore_mode, sweep, repair_one}`, `resume::{mode_cause, hand_off_red_ci, resume_after_mode_repair}`, the `restore_file` and `set_mode` arms of the coder's and the feedback round's executors, and `common::coder_shell::CHMOD`.
15 changes: 15 additions & 0 deletions services/common/src/agent_policy/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ pub const BUILTIN: &[(&str, Risk)] = &[
("get_diff", Risk::Read),
("github_history", Risk::Read),
("search_org", Risk::Read),
// Every repository of the team's installation, offered to every agent
// (`repo_reach`).
("list_repos", Risk::Read),
("read_repo_file", Risk::Read),
("search_repo", Risk::Read),
("github__read_file", Risk::Read),
("github__search_code", Risk::Read),
("github__list_directory", Risk::Read),
Expand Down Expand Up @@ -262,6 +267,7 @@ pub const BUILTIN: &[(&str, Risk)] = &[
("edit_file", Risk::Write),
("batch_write", Risk::Write),
("restore_file", Risk::Write),
("set_mode", Risk::Write),
("run_codegen", Risk::Write),
("run_checks", Risk::Write),
("reproduce_on_base", Risk::Write),
Expand Down Expand Up @@ -448,6 +454,15 @@ mod tests {
assert_eq!(kind_of("confluence_append").0, CallKind::Outbound);
}

/// The cross-repository tools every agent is offered are reads the
/// engine knows (their names are constants, out of the scan below).
#[test]
fn cross_repo_tools_are_reads() {
for t in crate::repo_reach::TOOLS {
assert_eq!(Builtin.risk(t), Some(Risk::Read), "{t}");
}
}

#[test]
fn builtins_are_listed_once() {
let mut seen = BTreeSet::new();
Expand Down
10 changes: 10 additions & 0 deletions services/common/src/coder_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ pub const WRITES: &str = "Commands don't change files here: the sandbox works on
a file, write_file to create or replace one, batch_write to write several or delete one \
(`action: delete`), restore_file to put one back as it was.";

/// The message for `chmod`: a mode set in the sandbox's copy never reaches
/// the branch.
pub const CHMOD: &str = "chmod doesn't reach the commit: the sandbox works on a copy and \
nothing it changes is kept, modes included. Set a file's mode on the branch with set_mode \
(`executable: true`), or put back the mode it has on the base branch with set_mode and no \
`executable`; restore_file brings a file's mode back with its content.";

/// The message for git commands that change the branch or reach the remote.
pub const GIT: &str = "git doesn't run here: every write_file, edit_file and batch_write is \
committed to the branch, and CoderHelm pushes and opens the pull request itself. See the \
Expand Down Expand Up @@ -401,6 +408,9 @@ fn refusal(prog: &str, args: &[String], redirects: bool) -> Option<&'static str>
if SECRET_READERS.contains(&prog) {
return Some(SECRETS);
}
if prog == "chmod" {
return Some(CHMOD);
}
if FILE_WRITERS.contains(&prog) {
return Some(WRITES);
}
Expand Down
1 change: 1 addition & 0 deletions services/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub mod embed;
/// brain chat and the team's agents search.
pub mod knowledge;
// Reading the team's repositories for Chat (overview, files, search).
pub mod repo_reach;
pub mod repo_read;
// The test that every model call site is a metered helper
pub mod ci_cover;
Expand Down
17 changes: 14 additions & 3 deletions services/common/src/rendered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ static RUN_ON: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"[^:\n]{1,80}: [^:\n]{1,200}: [^:\n]{1,200}: ").expect("regex"));

/// What in `text` a person shouldn't be shown, or `None`: an empty slot
/// ([`empty_slot`]), a hand-off of work CoderHelm does itself, a template
/// plural ("file(s)"), a bracketed internal key, or clauses run together
/// with colons. Code spans are taken out first, so a command or a name in
/// ([`empty_slot`]), a claim that CoderHelm can't see, open, access or
/// confirm something (`repo_reach::claim`: every repository of the team's
/// installation is readable, so with no refusal from a tool the claim is a
/// guess), a hand-off of work CoderHelm does itself, a template plural
/// ("file(s)"), a bracketed internal key, or clauses run together with
/// colons. Code spans are taken out first, so a command or a name in
/// backticks never trips it.
pub fn person_text(text: &str) -> Option<String> {
if let Some(gap) = empty_slot(text) {
Expand All @@ -199,6 +202,14 @@ pub fn person_text(text: &str) -> Option<String> {
return Some(format!("words for the model (\"{p}\": {why}): {body}"));
}
}
// Every repository of the team's installation is readable, and a
// text CoderHelm writes for a person carries no refusal from a
// tool, so a first-person claim it can't see something is a guess.
if let Some(c) = crate::repo_reach::claim(body) {
return Some(format!(
"a claim CoderHelm can't see or confirm something: {c}"
));
}
if body.contains("(s)") {
return Some(format!("a template plural: {body}"));
}
Expand Down
4 changes: 4 additions & 0 deletions services/common/src/reply_compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ pub fn finish(
markdown: bool,
) -> Option<(String, Vec<(String, String)>)> {
let text = cv::no_arrows(&without_greeting(raw, to));
// A sentence saying CoderHelm can't see or confirm something is never
// posted: the composer has no refusal from a tool to show for it
// (`repo_reach`).
let text = crate::repo_reach::strip(&text, &[]);
Comment thread
coderhelm[bot] marked this conversation as resolved.
Resolved
let (kept, dropped) = check(&text, g);
let kept = with_commit_link(&kept, g.facts, markdown);
let kept = cv::cut_words(&kept, MAX_REPLY_CHARS);
Expand Down
Loading