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
18 changes: 18 additions & 0 deletions docs/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3171,6 +3171,23 @@
"null"
]
},
"prs": {
"description": "Every pull request the run opened, each with its own repository\n(`repo`, `pr_number`, `branch`, `url`, and `outcome` once it ended).\nBuild links and labels from these: in a run across several\nrepositories, `repo` and `pr_numbers` don't pair up.",
"examples": [
[
{
"branch": "coderhelm/web-42-login-rate-limit",
"pr_number": 318,
"repo": "acme/web",
"url": "https://github.com/acme/web/pull/318"
}
]
],
"items": {
"type": "object"
},
"type": "array"
},
"questions": {
"description": "What the run asked when it stopped as `needs_input`, one question\neach. Answer them with `POST /api/runs/{run_id}/answer`. Empty when\nit asked nothing it can take answers for here.",
"items": {
Expand Down Expand Up @@ -3301,6 +3318,7 @@
},
"required": [
"run_id",
"prs",
"tokens_in",
"tokens_out",
"cache_read_tokens",
Expand Down
3 changes: 3 additions & 0 deletions lambda/stuck-run-cleanup/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"ci_fix": "CI fix round",
"review_fix": "review fix round",
"feedback": "feedback round",
"security_fix": "security fix round",
}

_dynamodb = None
Expand Down Expand Up @@ -142,6 +143,8 @@ def round_kind(run, pass_name):
return "ci_fix"
if p == "feedback":
return "feedback"
if p == "security_fix":
return "security_fix"
return "review_fix"


Expand Down
1 change: 1 addition & 0 deletions lambda/tests/test_stuck_run_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def test_the_round_kind_falls_back_to_the_pass(self):
self.assertEqual(sweep.round_kind({}, "ci_fix:2"), "ci_fix")
self.assertEqual(sweep.round_kind({}, "feedback"), "feedback")
self.assertEqual(sweep.round_kind({}, "implement"), "review_fix")
self.assertEqual(sweep.round_kind({}, "security_fix:1"), "security_fix")

def test_no_pr_means_no_pr(self):
self.assertFalse(sweep.has_pull_request({}))
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 @@ -83,6 +83,7 @@ mod model_call_sites;
pub mod paged;
/// What happened to a PR Coderhelm opened, read from GitHub.
pub mod pr_outcome;
pub mod run_prs;
// review_stats: time-ordered review records for analytics
pub mod jira_text;
/// Anthropic API or Amazon Bedrock, and Bedrock's model ids.
Expand Down
35 changes: 34 additions & 1 deletion services/common/src/run_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ pub struct RunFailure<'a> {
/// Fail the run only while it is still in this status: a sweep that finds
/// a stuck run must not overwrite one that finished meanwhile.
pub only_from: Option<&'a str>,
/// More fields to set in the same write (tokens, cost, duration).
/// More fields to set in the same write (duration).
pub extra: Vec<(&'static str, AttributeValue)>,
/// Numbers added to fields in the same write (tokens, cost): what this
/// invocation used, on top of what earlier ones recorded.
pub add: Vec<(&'static str, AttributeValue)>,
}

/// The status-index sort key of a failed run.
Expand Down Expand Up @@ -117,6 +120,15 @@ pub fn update(run_id: &str, f: &RunFailure<'_>, now: &str) -> Update {
names.insert(n, (*field).to_string());
values.insert(v, value.clone());
}
if !f.add.is_empty() {
values.insert(":zero".into(), AttributeValue::N("0".into()));
}
for (i, (field, value)) in f.add.iter().enumerate() {
let (n, v) = (format!("#a{i}"), format!(":a{i}"));
expression.push_str(&format!(", {n} = if_not_exists({n}, :zero) + {v}"));
names.insert(n, (*field).to_string());
values.insert(v, value.clone());
}
expression.push_str(" REMOVE #legacy");
let condition = match f.only_from {
Some(from) => {
Expand Down Expand Up @@ -298,6 +310,27 @@ mod tests {
}
}

/// Tokens and cost are added to what the record holds, never set: a
/// later invocation's failure must not wipe the earlier cost.
#[test]
fn a_failure_adds_its_usage_to_the_record() {
let u = update(
"R1",
&RunFailure {
reason: "x",
add: vec![("cost_usd", AttributeValue::N("0.25".into()))],
..Default::default()
},
"now",
);
assert!(u
.expression
.contains("#a0 = if_not_exists(#a0, :zero) + :a0"));
assert_eq!(u.names["#a0"], "cost_usd");
assert_eq!(u.values[":a0"], AttributeValue::N("0.25".into()));
assert_eq!(u.values[":zero"], AttributeValue::N("0".into()));
}

#[test]
fn error_text_names_the_cause_not_just_service_error() {
assert_eq!(
Expand Down
Loading
Loading