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

**What happened:** A fix run's own review asked for one proof: run the fixed end-to-end test twenty times. The fix round couldn't, because CoderHelm's own sandbox couldn't reach the sites the test runs against. It ended with "NEEDS A PERSON ... outside_reach", asking someone to widen CoderHelm's own network allowlist or run the command themselves. It called a repeat run in CI "outside this ticket". CoderHelm doesn't merge over its own review, so the pull request sat with nothing moving it. The same shape came back from other limits CoderHelm owns: its time budget, its tools, a workflow's triggers it hadn't read, and a proof its review asked for that none of its routes could run.

**The guarantee:** A hand-off to a person is a typed value (`common::person_only::PersonOnly`) from a closed set: a named permission an owner or admin grants, a product decision, an approval the repository's or team's rules require, a credential only the person holds, work someone else holds, or a real-world action. Its text is private to the module, and no variant covers CoderHelm's sandbox, network allowlist, budgets, tools, CI use, labels, tests or reads. Every written hand-off goes through one parser (`person_only::parse`, `of_reason`, `of_human_only`): the person gate's items, a fix round's `NEEDS A PERSON` line, and hand-backs. A limit CoderHelm owns comes back as an `OwnProblem`. That becomes an internal alert for CoderHelm's maintainers and one plain line on the run page, and the work goes on by another route. On its own pull request, CoderHelm's reviewer blocks only on what one of its routes can satisfy: an edit, a sandbox run, CI, or a page check. Anything else becomes one question or CoderHelm's own note (`review_feasible`). A pull request with no progress for a day gets a self-diagnosis, a retry along its next route and an internal alert (`own_problems::check`, on the 15-minute sweep). The team's hand-offs are counted by reason, its own problems by subject, along with the time each pull request spent blocked.
38 changes: 38 additions & 0 deletions services/common/src/handback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ pub struct HandBack {

impl HandBack {
/// `None` without a need: a hand-back says exactly what is needed.
/// `None` too when the need names a limit CoderHelm owns (its sandbox,
/// allowlist, budgets, tools, CI usage, labels, tests or reads,
/// `person_only::own_subject`): that is never a person's.
pub fn new(why: HumanOnly, need: &str) -> Option<HandBack> {
let n = need.split_whitespace().collect::<Vec<_>>().join(" ");
if !n.is_empty() && typed(why) && crate::person_only::of_human_only(why, &n).is_err() {
return None;
}
(!n.is_empty()).then(|| HandBack {
why,
need: crate::truncate_str(&n, 600).to_string(),
Expand Down Expand Up @@ -170,6 +176,21 @@ impl HandBack {
}
}

/// Reasons whose need is something a person is asked for (and so goes
/// through `person_only`). The others record what already happened (a
/// person's action, the usage limit, another holder) or are the recovery
/// ladder's own end (`Unrepaired`).
fn typed(why: HumanOnly) -> bool {
matches!(
why,
HumanOnly::Credential
| HumanOnly::MissingAccess
| HumanOnly::ProductDecision
| HumanOnly::AmbiguousTicket
| HumanOnly::Approval
)
}

/// Reads a reason on the list from words a run, a check or the judge wrote.
/// `None` when they name none, which is the case for every stall, red
/// check, tool error, time limit or budget, and for a read the team's
Expand All @@ -179,6 +200,11 @@ pub fn human_only_in(text: &str) -> Option<HumanOnly> {
if crate::aws_role_reads::is_install_grant(text) {
return None;
}
// Words about CoderHelm's own limits name no reason, whatever else they
Comment thread
coderhelm[bot] marked this conversation as resolved.
Resolved
// say ("grant access ... to CoderHelm's sandbox allowlist").
if crate::person_only::own_subject(text).is_some() {
return None;
}
let t = text.to_lowercase();
let any = |marks: &[&str]| marks.iter().any(|m| t.contains(m));
if any(&[
Expand Down Expand Up @@ -273,6 +299,18 @@ mod tests {
);
}

#[test]
fn coderhelms_own_limits_are_never_a_hand_back() {
for t in [
"Grant access: add staging.acme-books.example to CoderHelm's sandbox network allowlist",
"No access to the preview from the sandbox: net::ERR_TUNNEL_CONNECTION_FAILED",
"The e2e workflow has no repeat input; run the test 20 times yourself",
] {
assert_eq!(human_only_in(t), None, "{t}");
assert!(HandBack::new(HumanOnly::MissingAccess, t).is_none(), "{t}");
}
}

#[test]
fn a_read_the_aws_role_lacks_is_the_install_item_never_a_wait() {
let asked = "Grant access: the team's read-only role was denied wafv2:ListWebACLs and \
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 @@ -323,6 +323,7 @@ pub mod person_gate;
/// A person's lines on a CoderHelm branch stay theirs: writes that would undo them are
/// kept out.
pub mod person_lines;
pub mod person_only;
/// Plugins: packages of skills, agents, tools, triggers and outputs a team installs.
pub mod plugins;
/// One shape for "something is wrong": set by a check, cleared by the same
Expand Down
136 changes: 99 additions & 37 deletions services/common/src/person_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ pub enum Work {
Command(String),
/// Its own step, as written (a query to run, a list to post).
Own(String),
/// A limit CoderHelm owns that a writer tried to hand a person
/// (`person_only`): CoderHelm takes another route, its maintainers get
/// an internal alert, and the run page says so in one line.
Problem(crate::person_only::OwnProblem),
}

impl Work {
Expand All @@ -251,6 +255,7 @@ impl Work {
),
Work::Command(c) => format!("ran `{c}` in its sandbox"),
Work::Own(w) => w.clone(),
Work::Problem(p) => p.line(),
}
}
}
Expand Down Expand Up @@ -287,6 +292,9 @@ impl Decision {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HumanItem {
reason: Reason,
/// The typed hand-off it stands for (`person_only`): a `HumanItem`
/// exists only for one.
person: crate::person_only::PersonOnly,
action: String,
who: String,
why_not: String,
Expand All @@ -298,6 +306,9 @@ impl HumanItem {
pub fn reason(&self) -> Reason {
self.reason
}
pub fn person(&self) -> &crate::person_only::PersonOnly {
&self.person
}
pub fn action(&self) -> &str {
&self.action
}
Expand Down Expand Up @@ -823,7 +834,7 @@ fn reason_named(t: &str) -> Option<Reason> {
/// A step that spends real money: "paid" before an action a customer
/// takes (a paid checkout, registration, booking, order), or a purchase
/// made for real. No sandbox or test card stands in for one.
fn paid_action(t: &str) -> bool {
pub(crate) fn paid_action(t: &str) -> bool {
const ACTIONS: &[&str] = &[
"checkout",
"registration",
Expand Down Expand Up @@ -1010,16 +1021,14 @@ pub fn decide(a: &Ask, ctx: &Context) -> Outcome {
return deploy_item(a, &t, ctx);
}
return match reason_in(&cause) {
Some(reason @ (Reason::Grant | Reason::Credential | Reason::Approval)) => {
Outcome::Human(HumanItem {
reason,
action: first_nonempty(&a.how, &a.text),
who: who_for(reason, &a.owner),
why_not: first_nonempty(&a.why_not, reason.label()),
options: Vec::new(),
recommendation: String::new(),
})
}
Some(reason @ (Reason::Grant | Reason::Credential | Reason::Approval)) => human(
reason,
first_nonempty(&a.how, &a.text),
who_for(reason, &a.owner),
first_nonempty(&a.why_not, reason.label()),
Vec::new(),
String::new(),
),
_ => Outcome::Do(Work::Own(one_line(&a.text))),
};
}
Expand All @@ -1043,14 +1052,14 @@ pub fn decide(a: &Ask, ctx: &Context) -> Outcome {
}
// 2. A listed reason the item itself names.
if let Some(reason) = reason_in(&t) {
return Outcome::Human(HumanItem {
return human(
reason,
action: first_nonempty(&a.how, &a.text),
who: who_for(reason, &a.owner),
why_not: first_nonempty(&a.why_not, reason.label()),
options: Vec::new(),
recommendation: String::new(),
});
first_nonempty(&a.how, &a.text),
who_for(reason, &a.owner),
first_nonempty(&a.why_not, reason.label()),
Vec::new(),
String::new(),
);
}
// 3. A choice: settled by a source, else decided, else (hard to
// reverse, nothing settles it) one yes/no on the recommendation.
Expand Down Expand Up @@ -1085,14 +1094,14 @@ pub fn decide(a: &Ask, ctx: &Context) -> Outcome {
if options.is_empty() {
options = vec![rec.clone(), "leaving it out".to_string()];
}
return Outcome::Human(HumanItem {
reason: Reason::Irreversible,
action: format!("Yes or no: {}", trim_end(&strip_question_marks(&a.text))),
who: who_for(Reason::Irreversible, &a.owner),
why_not: Reason::Irreversible.label().to_string(),
return human(
Reason::Irreversible,
format!("Yes or no: {}", trim_end(&strip_question_marks(&a.text))),
who_for(Reason::Irreversible, &a.owner),
Reason::Irreversible.label().to_string(),
options,
recommendation: rec,
});
rec,
);
}
let chose = first_nonempty(&recommendation_of(a), &a.text);
return Outcome::Decided(Decision {
Expand Down Expand Up @@ -1143,14 +1152,14 @@ fn deploy_item(a: &Ask, t: &str, ctx: &Context) -> Outcome {
}
(m, _) => sentence_start(m),
};
Outcome::Human(HumanItem {
human(
reason,
action,
who: who_for(reason, &a.owner),
why_not: first_nonempty(&a.why_not, reason.label()),
options: Vec::new(),
recommendation: String::new(),
})
who_for(reason, &a.owner),
first_nonempty(&a.why_not, reason.label()),
Vec::new(),
String::new(),
)
}

impl Ask {
Expand Down Expand Up @@ -1197,16 +1206,57 @@ pub fn for_reason(why: HumanOnly, a: &Ask) -> Option<HumanItem> {
HumanOnly::Approval => Reason::Approval,
_ => return None,
};
Some(HumanItem {
human_item(
reason,
first_nonempty(&a.how, &a.text),
who_for(reason, &a.owner),
first_nonempty(&a.why_not, reason.label()),
Vec::new(),
String::new(),
)
.ok()
Comment thread
coderhelm[bot] marked this conversation as resolved.
Resolved
}

/// The one way a [`HumanItem`] is made: from a typed hand-off
/// (`person_only::of_reason`) for its reason and words. Words about
/// CoderHelm's own limits (its sandbox, allowlist, budgets, tools, CI
/// usage, labels, tests, reads) make no hand-off: they are its own problem.
fn human_item(
reason: Reason,
action: String,
who: String,
why_not: String,
options: Vec<String>,
recommendation: String,
) -> Result<HumanItem, crate::person_only::OwnProblem> {
let person = crate::person_only::of_reason(reason, &format!("{action}. {why_not}"))?;
Ok(HumanItem {
reason,
action: first_nonempty(&a.how, &a.text),
who: who_for(reason, &a.owner),
why_not: first_nonempty(&a.why_not, reason.label()),
options: Vec::new(),
recommendation: String::new(),
person,
action,
who,
why_not,
options,
recommendation,
})
}

/// [`human_item`] as the gate's outcome: an item for a person, or
/// CoderHelm's own problem ([`Work::Problem`]).
fn human(
reason: Reason,
action: String,
who: String,
why_not: String,
options: Vec<String>,
recommendation: String,
) -> Outcome {
match human_item(reason, action, who, why_not, options, recommendation) {
Ok(h) => Outcome::Human(h),
Err(p) => Outcome::Do(Work::Problem(p)),
}
}

/// The stable key of an item's decision: its kind and topic, or its
/// content words when it has no topic.
pub fn key(a: &Ask) -> String {
Expand Down Expand Up @@ -1259,6 +1309,18 @@ impl Gated {
.collect()
}

/// CoderHelm's own problems a writer tried to hand a person
/// (`person_only`): each is an internal alert and one run-page line.
pub fn problems(&self) -> Vec<&crate::person_only::OwnProblem> {
self.items
.iter()
.filter_map(|(_, o)| match o {
Outcome::Do(Work::Problem(p)) => Some(p),
_ => None,
})
.collect()
}

/// What CoderHelm does itself.
pub fn work(&self) -> Vec<&Work> {
self.items
Expand Down
Loading