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
147 changes: 143 additions & 4 deletions docs/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,17 @@
"format": "double",
"type": "number"
},
"covered_by": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/components/schemas/RunCoveredBy",
"description": "For a `covered_by_pr` run: the open pull request that already does the\nwork, and why."
}
]
},
"created_at": {
"description": "When the run started (RFC 3339).",
"examples": [
Expand Down Expand Up @@ -3244,7 +3255,7 @@
"type": "array"
},
"status": {
"description": "Where the run is: `pending`, `running`, `awaiting_ci`, `completed`,\n`failed`, `needs_input`, `needs_outside_change`, `cancelled`,\n`retried` or `closed`. Treat a value you don't know as in progress.",
"description": "Where the run is: `pending`, `running`, `awaiting_ci`, `completed`,\n`failed`, `needs_input`, `needs_outside_change`, `covered_by_pr`, `cancelled`,\n`retried` or `closed`. Treat a value you don't know as in progress.",
"examples": [
"completed"
],
Expand All @@ -3253,6 +3264,16 @@
"null"
]
},
"stop_kind": {
"description": "Why the run stopped, when it was its own environment rather than a\nquestion: `tooling` (a command the run ran failed for want of a\ndependency or tool; see `tooling_failure`).",
"examples": [
null
],
"type": [
"string",
"null"
]
},
"ticket_id": {
"description": "The ticket's key or issue number in its source.",
"examples": [
Expand Down Expand Up @@ -3301,6 +3322,17 @@
"minimum": 0,
"type": "integer"
},
"tooling_failure": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/components/schemas/RunToolingFailure",
"description": "For a tooling failure: the exact command, the error it printed and\nwhat the run tried first."
}
]
},
"trigger": {
"$ref": "#/components/schemas/RunTrigger",
"description": "How the run was started and by whom (as in the runs list)."
Expand Down Expand Up @@ -3396,6 +3428,60 @@
],
"type": "object"
},
"RunCoveredBy": {
"description": "The open pull request that already does a run's work.",
"properties": {
"author": {
"description": "Who opened it.",
"examples": [
"octocat"
],
"type": "string"
},
"number": {
"description": "Its number.",
"examples": [
41
],
"format": "int64",
"minimum": 0,
"type": "integer"
},
"reason": {
"description": "Why it does the run's work, in one sentence.",
"examples": [
"It selects the card by its name, which is the ticket's fix."
],
"type": "string"
},
"repo": {
"description": "Its repository, `owner/name`.",
"examples": [
"acme/web"
],
"type": "string"
},
"title": {
"description": "Its title.",
"examples": [
"Fix the cards list spec"
],
"type": "string"
},
"url": {
"description": "Its address on GitHub.",
"examples": [
"https://github.com/acme/web/pull/41"
],
"type": "string"
}
},
"required": [
"repo",
"number"
],
"type": "object"
},
"RunNote": {
"description": "A note the run wrote while it worked.",
"properties": {
Expand Down Expand Up @@ -3461,6 +3547,18 @@
"null"
]
},
"evidence": {
"description": "The evidence the question cites: a `path:line` in the code or a\nlookup the run made. A ticket that states its own root cause and fix\nplan is only questioned with evidence that contradicts it.",
"examples": [
[
"config/limits.yml:12"
]
],
"items": {
"type": "string"
},
"type": "array"
},
"id": {
"description": "The question's id within the run (`q1`, `q2`, ...).",
"examples": [
Expand Down Expand Up @@ -3502,7 +3600,8 @@
"required": [
"id",
"question",
"suggestions"
"suggestions",
"evidence"
],
"type": "object"
},
Expand Down Expand Up @@ -3595,7 +3694,7 @@
]
},
"status": {
"description": "Where the run is: `pending`, `running`, `awaiting_ci`, `completed`,\n`failed`, `needs_input`, `needs_outside_change`, `cancelled`,\n`retried` or `closed`. Treat a value you don't know as in progress.",
"description": "Where the run is: `pending`, `running`, `awaiting_ci`, `completed`,\n`failed`, `needs_input`, `needs_outside_change`, `covered_by_pr`, `cancelled`,\n`retried` or `closed`. Treat a value you don't know as in progress.",
"examples": [
"completed"
],
Expand Down Expand Up @@ -3668,6 +3767,42 @@
],
"type": "object"
},
"RunToolingFailure": {
"description": "A command the run itself ran that failed for want of a dependency or a\ntool: the run's own environment, never a question for the ticket.",
"properties": {
"command": {
"description": "The exact command.",
"examples": [
"cd 'e2e' && pnpm exec tsc --noEmit -p tsconfig.json"
],
"type": "string"
},
"error": {
"description": "The error it printed.",
"examples": [
"sh: 1: tsc: not found"
],
"type": "string"
},
"tried": {
"description": "What the run tried first (installing the package's dependencies with\nits own manager, then the command again), with how each ended.",
"examples": [
[
"`cd 'e2e' && (pnpm install --ignore-workspace --frozen-lockfile || pnpm install --ignore-workspace)` failed (exit 1)"
]
],
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"command",
"error"
],
"type": "object"
},
"RunTrigger": {
"description": "How a run was started, in words, with a link to what started it.",
"properties": {
Expand Down Expand Up @@ -6624,7 +6759,7 @@
},
"/api/runs/{run_id}/retry": {
"post": {
"description": "Starts the run's ticket again as a new run. Only a run that is `failed`, `needs_input`, `needs_outside_change`, `cancelled` or `closed` can be retried; the old run becomes `retried`, so retrying it twice is refused with `400`. Find the new run with `GET /api/runs?q=<ticket id>`.\n\nA `completed` run whose `round_incomplete` is set (its pull request is open but the last fix round on it didn't finish) is resumed instead: the same run picks the round up again on the same pull request, with a fresh time budget, and the answer's status is `resuming`.",
"description": "Starts the run's ticket again as a new run. Only a run that is `failed`, `needs_input`, `needs_outside_change`, `covered_by_pr`, `cancelled` or `closed` can be retried; the old run becomes `retried`, so retrying it twice is refused with `400`. Find the new run with `GET /api/runs?q=<ticket id>`.\n\nA `completed` run whose `round_incomplete` is set (its pull request is open but the last fix round on it didn't finish) is resumed instead: the same run picks the round up again on the same pull request, with a fresh time budget, and the answer's status is `resuming`.",
"operationId": "retryRun",
"parameters": [
{
Expand Down Expand Up @@ -10877,6 +11012,7 @@
"awaiting_ci",
"needs_input",
"needs_outside_change",
"covered_by_pr",
"completed",
"merged",
"failed",
Expand Down Expand Up @@ -11099,6 +11235,7 @@
"awaiting_ci",
"needs_input",
"needs_outside_change",
"covered_by_pr",
"completed",
"merged",
"failed",
Expand Down Expand Up @@ -11321,6 +11458,7 @@
"awaiting_ci",
"needs_input",
"needs_outside_change",
"covered_by_pr",
"completed",
"merged",
"failed",
Expand Down Expand Up @@ -11543,6 +11681,7 @@
"awaiting_ci",
"needs_input",
"needs_outside_change",
"covered_by_pr",
"completed",
"merged",
"failed",
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 @@ -123,6 +123,7 @@ pub mod skill_compat;
pub mod skills;
/// Who may ask CoderHelm for work from a GitHub comment or review.
pub mod standing;
pub mod stop_rules;
/// A ticket's comments as CoderHelm read them, and whether its work is done.
pub mod ticket_state;
/// A team's monthly token limits: new tokens, cache read, cache write.
Expand Down
31 changes: 31 additions & 0 deletions services/common/src/run_questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub struct Question {
/// `suggestions` are then the choices.
#[serde(default, skip_serializing_if = "String::is_empty")]
pub decision: String,
/// The evidence the question cites (`path:line`, a lookup id): what in
/// the code or the data makes it a question (see `stop_rules::screen`).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub evidence: Vec<String>,
}

/// What a run asked when it stopped, and where it asked it.
Expand Down Expand Up @@ -178,6 +182,13 @@ pub fn parse(detail: &str) -> Vec<Question> {
});
} else if let (Some(why), Some(last)) = (field(item, "why"), out.last_mut()) {
last.why = why.to_string();
} else if let (Some(ev), Some(last)) = (field(item, "evidence"), out.last_mut()) {
last.evidence = ev
.split('|')
.map(str::trim)
.filter(|s| !s.is_empty())
.map(str::to_string)
.collect();
} else if let (Some(opts), Some(last)) = (
field(item, "options").or_else(|| field(item, "suggestions")),
out.last_mut(),
Expand Down Expand Up @@ -250,6 +261,13 @@ fn tidy(questions: Vec<Question>) -> Vec<Question> {
.take(MAX_SUGGESTIONS)
.collect(),
decision: q.decision,
evidence: q
.evidence
.iter()
.map(|s| clip(s.trim(), MAX_SUGGESTION_CHARS))
.filter(|s| !s.is_empty())
.take(MAX_SUGGESTIONS)
.collect(),
})
.collect()
}
Expand All @@ -272,6 +290,16 @@ pub fn markdown(questions: &[Question]) -> String {
.join(", ")
));
}
if !q.evidence.is_empty() {
out.push_str(&format!(
" Evidence: {}\n",
q.evidence
.iter()
.map(|s| format!("`{s}`"))
.collect::<Vec<_>>()
.join(", ")
));
}
}
out.trim_end().to_string()
}
Expand All @@ -289,6 +317,9 @@ pub fn plain(questions: &[Question]) -> String {
if !q.suggestions.is_empty() {
s.push_str(&format!(" Possible answers: {}.", q.suggestions.join("; ")));
}
if !q.evidence.is_empty() {
s.push_str(&format!(" Evidence: {}.", q.evidence.join("; ")));
}
s
})
.collect::<Vec<_>>()
Expand Down
8 changes: 7 additions & 1 deletion services/common/src/run_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub const RUNNING: &str = "running";
pub const AWAITING_CI: &str = "awaiting_ci";
pub const NEEDS_INPUT: &str = "needs_input";
pub const NEEDS_OUTSIDE_CHANGE: &str = "needs_outside_change";
/// An open pull request (anyone's) already does the work: the run linked it
/// and built no second fix (see `stop_rules::existing_work`).
pub const COVERED_BY_PR: &str = "covered_by_pr";
pub const COMPLETED: &str = "completed";
/// Older runs finished with this word before `completed`.
pub const SUCCESS: &str = "success";
Expand All @@ -36,13 +39,14 @@ pub const RETRIED: &str = "retried";
pub const ARCHIVED: &str = "archived";

/// Every status a run record carries.
pub const ALL: [&str; 14] = [
pub const ALL: [&str; 15] = [
PENDING,
QUEUED,
RUNNING,
AWAITING_CI,
NEEDS_INPUT,
NEEDS_OUTSIDE_CHANGE,
COVERED_BY_PR,
COMPLETED,
SUCCESS,
MERGED,
Expand Down Expand Up @@ -198,6 +202,7 @@ mod tests {
AWAITING_CI,
NEEDS_INPUT,
NEEDS_OUTSIDE_CHANGE,
COVERED_BY_PR,
COMPLETED,
SUCCESS,
FAILED,
Expand Down Expand Up @@ -225,6 +230,7 @@ mod tests {
assert_eq!(reopen_status(COMPLETED), COMPLETED);
assert_eq!(reopen_status(FAILED), FAILED);
assert_eq!(reopen_status(NEEDS_OUTSIDE_CHANGE), NEEDS_OUTSIDE_CHANGE);
assert_eq!(reopen_status(COVERED_BY_PR), COVERED_BY_PR);
assert_eq!(reopen_status(NEEDS_INPUT), NEEDS_INPUT);
for s in IN_FLIGHT {
assert_eq!(reopen_status(s), NEEDS_INPUT, "{s}");
Expand Down
Loading
Loading