Skip to content
Open
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
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ Changes are recorded here before a release version is assigned.

### Changed

- Version 0.94.0: a review that cannot reach its pull request says why, and
the review host form shows how to create a token (ADR-0146). Before, a
start with no review host recorded said only that the address was "not a
pull request address of a recorded review host", a private repository the
token cannot see said "the review host answered with status 404", and a
token refused during the file fetch said "the host keeps refusing or
failing requests".
- With no review host recorded, the start says so, that nothing was sent,
and to add the host and a token under **Settings > Reviews > Review
hosts**. An address no recorded host owns says to check it or add its
host.
- A 401 says the token was refused and should be replaced, a 403 that it
lacks a scope or the organization has not approved or authorized it, and
a 404 that the pull request does not exist or the token cannot see its
repository, which is how GitHub, GitLab, and Bitbucket answer a private
repository. Other statuses keep their number.
- `review_host_failing` names its cause: a refused token, a rate limit, or
ten failed requests in a row. `review_fetch_file` tells the model what a
401, 403, or 404 means in the same way.
- The **Add host** form shows numbered steps for creating a token on the
chosen kind's host under **Kind** and changes them with the kind; each
host's **Set token…** shows its kind's steps. For GitHub they cover the
repository's owner (the operator's own account or the organization) as
resource owner, selected repositories, Pull requests and Contents read,
an organization's approval, and a classic `repo` token for an outside
collaborator. They are plain text,
dated 2026-12-05; the GitHub and Bitbucket Cloud addresses in them were
not confirmed on the documentation pages read.
- No error code changes, no host text reaches a message, and no host was
contacted: the statuses are tested against loopback fixtures.

- The `settings` window is redesigned as six pages of cards (ADR-0136). The
sidebar groups **Connections** and **Chat defaults** under **Chat**, each
workspace and **All workspaces** under **Workspaces**, and **Toolchains**,
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/omgcode-core", "crates/omgcode-cli", "crates/omgcode-platform", "crates/omgcode-app", "crates/omgcode-desktop"]

[workspace.package]
version = "0.93.0"
version = "0.94.0"
edition = "2024"
rust-version = "1.99.1"
license = "Apache-2.0"
Expand Down
15 changes: 13 additions & 2 deletions crates/omgcode-app/src/desktop/reviews/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,13 @@ fn a_start_for_an_address_no_host_recognises_fails_with_a_fixed_text() {
assert_eq!(view.state, ReviewOperationState::Failed);
let error = view.error.expect("an error");
assert_eq!(error.code, "review_address_unrecognised");
assert_eq!(error.message, UrlRefusal::Unrecognised.reason());
// Core's fixed text says nothing was sent and where a host is added (ADR-0146).
assert!(
error.message.contains("nothing was sent")
&& error.message.contains("Settings > Reviews > Review hosts"),
"{}",
error.message
);
for text in [&error.code, &error.message] {
assert!(!text.contains("example.invalid") && !text.contains("secret-value"));
}
Expand Down Expand Up @@ -1837,7 +1843,12 @@ fn a_failed_start_reports_core_s_fixed_code_and_text_only() {
(
StartError::Status(404),
"review_host_not_found",
"the review host answered with status 404",
"the review host answered 404: the pull request does not exist, or the token cannot see its repository (a private repository the token has no access to answers 404)",
),
(
StartError::Status(502),
"review_host_server_error",
"the review host answered with status 502",
),
(
StartError::Malformed,
Expand Down
52 changes: 50 additions & 2 deletions crates/omgcode-core/src/review/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Why a review step failed. Each reason has a stable code, and none carries
//! text from a host, a path, a URL, or the token.

use std::borrow::Cow;

use thiserror::Error;

use crate::review_host::ReviewHostError;
Expand All @@ -11,8 +13,10 @@ pub enum ReviewError {
/// The client failed before a status arrived.
#[error("the review host request failed: {}", .0.code())]
Host(ReviewHostError),
/// The host answered with a status the step cannot use.
#[error("the review host answered with status {0}")]
/// The host answered with a status the step cannot use. A 401, 403, or 404
/// says what it usually means for a token, because a host answers a
/// private repository that the token cannot see with 404, not 401.
#[error("{}", status_text(*.0))]
Status(u16),
/// The host kept asking the client to wait, or asked for too long a wait.
#[error("the review host rate limit was reached")]
Expand Down Expand Up @@ -62,3 +66,47 @@ impl From<ReviewHostError> for ReviewError {
}
}
}

/// What the operator is told about a 401.
pub(crate) const UNAUTHORIZED_TEXT: &str = "the review host refused the token (status 401): it is wrong, expired, or revoked; set a new token for the host in Settings > Reviews > Review hosts";
/// What the operator is told about a 403.
pub(crate) const FORBIDDEN_TEXT: &str = "the review host refused access (status 403): the token lacks a scope the review needs, or the repository's organization has not approved or authorized it";
/// What the operator is told about a 404. GitHub, GitLab, and Bitbucket answer
/// a private repository that the token cannot see as if it did not exist.
pub(crate) const NOT_FOUND_TEXT: &str = "the review host answered 404: the pull request does not exist, or the token cannot see its repository (a private repository the token has no access to answers 404)";

/// The text of a status. It holds no text from the host.
fn status_text(status: u16) -> Cow<'static, str> {
match status {
401 => Cow::Borrowed(UNAUTHORIZED_TEXT),
403 => Cow::Borrowed(FORBIDDEN_TEXT),
404 => Cow::Borrowed(NOT_FOUND_TEXT),
other => Cow::Owned(format!("the review host answered with status {other}")),
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn an_access_status_says_it_is_about_the_token_and_others_give_the_number() {
let unauthorized = ReviewError::Status(401).to_string();
assert!(unauthorized.contains("status 401"), "{unauthorized}");
assert!(unauthorized.contains("refused the token"), "{unauthorized}");
let forbidden = ReviewError::Status(403).to_string();
assert!(forbidden.contains("status 403"), "{forbidden}");
assert!(forbidden.contains("lacks a scope"), "{forbidden}");
let missing = ReviewError::Status(404).to_string();
assert!(missing.contains("404"), "{missing}");
assert!(missing.contains("cannot see its repository"), "{missing}");
assert_eq!(
ReviewError::Status(418).to_string(),
"the review host answered with status 418"
);
// The codes are unchanged.
assert_eq!(ReviewError::Status(401).code(), "review_host_unauthorized");
assert_eq!(ReviewError::Status(403).code(), "review_host_forbidden");
assert_eq!(ReviewError::Status(404).code(), "review_host_not_found");
}
}
25 changes: 16 additions & 9 deletions crates/omgcode-core/src/review/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,22 @@ pub fn fetch_review(
continue;
}
failures += 1;
if matches!(
record.code.as_deref(),
Some("review_host_unauthorized" | "review_host_rate_limited")
) || failures >= MAX_CONSECUTIVE_FAILURES
{
return Err(ReviewError::Refused(
"review_host_failing",
"the host keeps refusing or failing requests",
));
// The code stays `review_host_failing`; the text keeps the cause,
// so a refused token is not reported as a failing host.
let stop = match record.code.as_deref() {
Some("review_host_unauthorized") => Some(
"the review host refused the token while the files were fetched (status 401); set a new token for the host in Settings > Reviews > Review hosts",
),
Some("review_host_rate_limited") => Some(
"the review host's rate limit stopped the file fetch; start the review again later",
),
_ if failures >= MAX_CONSECUTIVE_FAILURES => Some(
"ten file requests in a row failed; the host keeps refusing or failing requests",
),
_ => None,
};
if let Some(text) = stop {
return Err(ReviewError::Refused("review_host_failing", text));
}
} else {
failures = 0;
Expand Down
4 changes: 4 additions & 0 deletions crates/omgcode-core/src/review/fetch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ fn an_unauthorised_blob_ends_the_fetch_instead_of_recording_every_file_as_failed
);
let error = run.output.as_ref().unwrap_err();
assert_eq!(error.code(), "review_host_failing");
// The operator is told that the token was refused, not that the host fails.
let text = error.to_string();
assert!(text.contains("refused the token"), "{text}");
assert!(text.contains("status 401"), "{text}");
assert!(!run.folder.join("review.json").exists());
}

Expand Down
28 changes: 19 additions & 9 deletions crates/omgcode-core/src/review/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ use crate::session::{ReviewStarted, SessionError, SessionJournal};
use crate::skills::SkillName;
use crate::turn::CancelToken;

/// The refusal when no review host is recorded at all: nothing was sent.
pub(crate) const NO_HOST_TEXT: &str = "no review host is recorded, so nothing was sent; add the code host and a token for it in Settings > Reviews > Review hosts, then start the review again";
/// The refusal when hosts are recorded but none owns the address.
pub(crate) const UNMATCHED_TEXT: &str = "the address is not a pull request address of a recorded review host, so nothing was sent; check the address, or add its host in Settings > Reviews > Review hosts";

/// How old an unrecorded review folder must be before a start deletes it.
const ORPHAN_AGE: Duration = Duration::from_secs(24 * 60 * 60);
/// The most entries of the reviews folder one sweep looks at.
Expand Down Expand Up @@ -152,15 +157,20 @@ fn plan(request: &StartRequest<'_>, make_client: MakeClient<'_>) -> Result<Plan,
endpoint: status.endpoint(),
})
.collect();
let parsed = parse_pull_request_url(request.address, &hosts).map_err(|refusal| {
ReviewError::Refused(
match refusal {
super::url::UrlRefusal::Unrecognised => "review_address_unrecognised",
super::url::UrlRefusal::Ambiguous => "review_address_ambiguous",
},
refusal.reason(),
)
})?;
let parsed =
parse_pull_request_url(request.address, &hosts).map_err(|refusal| match refusal {
// Nothing has been sent, so the text says what to record, not what a
// host answered.
super::url::UrlRefusal::Unrecognised if hosts.is_empty() => {
ReviewError::Refused("review_address_unrecognised", NO_HOST_TEXT)
}
super::url::UrlRefusal::Unrecognised => {
ReviewError::Refused("review_address_unrecognised", UNMATCHED_TEXT)
}
super::url::UrlRefusal::Ambiguous => {
ReviewError::Refused("review_address_ambiguous", refusal.reason())
}
})?;
let status = store
.review_hosts()
.iter()
Expand Down
28 changes: 28 additions & 0 deletions crates/omgcode-core/src/review/start_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,39 @@ fn an_address_no_recorded_host_matches_is_refused() {
] {
let error = start(&fixture, address, &CancelToken::new(), |_| Ok(())).expect_err("refused");
assert_eq!(error.code(), "review_address_unrecognised", "{address}");
let text = error.to_string();
assert!(text.contains("nothing was sent"), "{text}");
assert!(text.contains("Review hosts"), "{text}");
}
assert!(entries(&root(&fixture)).is_empty());
assert!(fixture.host.targets().is_empty());
}

#[test]
fn with_no_recorded_host_the_refusal_says_to_add_one() {
let fixture = github_fixture();
let mut store = ControlStore::open(&fixture.data).expect("control store");
let revision = store.revision();
// The removal's report is not needed: only the missing record matters here.
let _removal = store
.unbind_review_host("work", revision)
.expect("removal recorded")
.finish(&fixture.credentials);
drop(store);
let error = start(
&fixture,
"https://github.com/o/r/pull/7",
&CancelToken::new(),
|_| Ok(()),
)
.expect_err("refused");
assert_eq!(error.code(), "review_address_unrecognised");
let text = error.to_string();
assert!(text.starts_with("no review host is recorded"), "{text}");
assert!(text.contains("add the code host and a token"), "{text}");
assert!(fixture.host.targets().is_empty(), "nothing was sent");
}

#[test]
fn a_cancel_during_the_fetch_leaves_no_folder_record_or_ledger() {
let cancel = CancelToken::new();
Expand Down
14 changes: 14 additions & 0 deletions crates/omgcode-core/src/review/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,20 @@ fn refuse_for(error: ReviewError) -> ToolRefusal {
"the host's rate limit was reached; try again later",
),
ReviewError::Refused(code, text) => refuse(code, text),
// The model is told what an access status means, so it can tell the
// operator that the token, not the file, is the problem.
ReviewError::Status(401) => refuse(
"review_host_unauthorized",
"the host refused the review host's token (status 401); the operator must set a new token for the host",
),
ReviewError::Status(403) => refuse(
"review_host_forbidden",
"the host refused access to the file (status 403); the token may lack a scope the review needs",
),
ReviewError::Status(404) => refuse(
"review_host_not_found",
"the host answered 404: the file is not at that commit, or the token cannot see the repository",
),
other => refuse(other.code(), "the host did not return the file"),
}
}
26 changes: 26 additions & 0 deletions crates/omgcode-core/src/review/tools_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,32 @@ fn a_path_over_the_recorded_limit_is_refused_before_the_host_or_the_ledger_is_to
assert_eq!(fetch(&mut fixture, &exact), Err("path_not_in_tree"));
}

#[test]
fn a_404_tells_the_model_the_token_may_not_see_the_repository() {
let mut fixture = fixture(Vec::new());
let client = fixture.host.client(ReviewHostKind::GitHub);
let manifest = manifest();
let cancel = CancelToken::new();
let ledger = ledger_path(&fixture.root, fixture.id);
let refusal = fetch_on_demand(
OnDemand {
folder: &mut fixture.folder,
manifest: &manifest,
client: &client,
ledger_path: &ledger,
cancel: &cancel,
},
"big.bin",
)
.expect_err("the host answers 404");
assert_eq!(refusal.code, "review_host_not_found");
assert!(
refusal.text.contains("token cannot see the repository"),
"{}",
refusal.text
);
}

#[test]
fn the_call_and_byte_budgets_stop_fetches_and_failed_calls_count() {
let mut fixture = fixture(Vec::new());
Expand Down
Loading