Skip to content
Closed
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
39 changes: 34 additions & 5 deletions crates/engine/src/cmd/catalogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{CmdResult, CommandSpec as C, Session};
pub fn commands() -> Vec<C> {
vec![
C::new("overture.add", "Add Overture Maps Data", "Home › Add › Web Data", overture_add).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network)).params(
r#"{"theme": "buildings"|"places"|"transportation"|"divisions"|"base"|"addresses", "type"?: "the theme's type (building, building_part; place; segment, connector; division_area, division, division_boundary; land_use, land, land_cover, water, infrastructure, bathymetry; address)", "release"?: "such as 2026-09-23.1 (default: the latest)", "bbox"?: [west, south, east, north] | "view" (the map's extent, the default), "tiles"?: bool (the whole world as map tiles, from the theme's PMTiles archive, instead of the features in view), "files"?: [the files' GeoParquet addresses, when already found and opened (the app's background requests)]}"#,
r#"{"theme": "buildings"|"places"|"transportation"|"divisions"|"base"|"addresses", "type"?: "the theme's type (building, building_part; place; segment, connector; division_area, division, division_boundary; land_use, land, land_cover, water, infrastructure, bathymetry; address)", "release"?: "such as 2026-09-23.1 (default: the latest)", "bbox"?: [west, south, east, north] | "view" (the map's extent, the default), "tiles"?: bool (the whole world as map tiles, from the theme's PMTiles archive, instead of the features in view), "files"?: [the files' GeoParquet addresses, when already found and opened (the app's background requests)]} (in a plugin's command in the app the files are left to download: it answers pending, with the layers already in, and the command runs again once they are added; see docs/plugins.md)"#,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new parameter text is shown to the Assistant and MCP as the tool's description (AGENTS.md, "Reach every surface"). "In a plugin's command in the app, the files are left to download: it answers pending, with the layers already in..." describes plugin-author behaviour that an assistant calling overture.add directly can't act on, and it adds a long clause to every description of this command. Suggest keeping the plugin detail in docs/plugins.md (already there) and leaving the parameter text as it was, or shortening it to a few words.

Confidence: medium. This is a wording point, not a behaviour change.

Category: quality

),
C::new("sourcecoop.products", "List Source Cooperative Products", "Home › Add › Web Data", sourcecoop_products).roles(&[]).effects(crate::policy::Effects::NONE.with(crate::policy::Effect::Network))
.view()
Expand Down Expand Up @@ -110,23 +110,52 @@ fn overture_add(s: &mut Session, p: &Value) -> CmdResult {

/// Adds a theme type's files (read in place, the map's view kept), all or none: when one can't be
/// added, the ones added before it are taken out again, so trying again doesn't add them twice.
/// Files left to the app (a plugin's command in the app) make the answer `"pending": true`; the
/// ones that landed before a later file failed stay (each its own undo step), and the error says so.
pub(crate) fn add_files(s: &mut Session, ty: &str, urls: &[String]) -> CmdResult {
// What a failure puts back: the map's layers in their order and its layer ids (not a copy of
// their data), and the active layer.
let (n, active, before) = (urls.len(), s.active_layer, s.map().layer_mark());
let mut layers: Vec<u32> = Vec::new();
let mut pending = false;
for (i, url) in urls.iter().enumerate() {
match super::layer::add_url(s, &json!({"url": url, "name": overture::layer_name(ty, i, n), "zoom": false})) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A rerun can resolve a different release and leave the first run's layers behind. A plugin command runs again from the start (plugin_fetch.rs, poll_plugin_retries). For the area path, overture_add calls release(p) (line 88) and the catalog's item addresses again, and the answer's files come from that. If Overture publishes a release between the first run and the rerun, the rerun's addresses differ from the ones that already landed. Those layers stay in the project but are not in the rerun's answer, and the new release's files are added next to them: duplicated data, and not "added once" as the new test claims. The same happens if the catalog fetch fails on the rerun, which leaves the landed layers with no answer for them.

I have not reproduced this. The window is narrow, so confidence is low to medium. The new rerun test does not reach it: it passes files, so no catalog is read on the rerun. A fix would carry the resolved release (or the addresses) in the retry state and have the rerun reuse them, or check that the rerun's addresses match the landed ones before adding.

Category: bug

Ok(r) => layers
.extend(r["layers"].as_array().into_iter().flatten().filter_map(Value::as_u64).filter_map(|id| u32::try_from(id).ok())),
Ok(r) => {
// A plugin's command in the app leaves the file to the app (`layer.addUrl`'s pending
// answer): the layer comes when it lands, and the command runs again (#2677).
pending |= r.get("pending").and_then(Value::as_bool) == Some(true);
layers
.extend(r["layers"].as_array().into_iter().flatten().filter_map(Value::as_u64).filter_map(|id| u32::try_from(id).ok()));
}
Err(e) => {
s.map_mut().restore_layers(&before);
s.active_layer = active;
return Err(if n > 1 { format!("{e} (none of the {n} files was added)") } else { e });
// Layers a plugin's earlier run left to the app have landed before this run: they
// stay, each its own undo step, so say so rather than that none was added.
// Counted from the downloads that landed, whichever of the files they were: a file
// after the failed one may have landed too, and this loop never reached it.
let kept = s
.rerun_landed
.iter()
.filter(|(asked, _, added)| {
added.added_any()
&& !added.gone(s.map())
&& asked.get("url").and_then(Value::as_str).is_some_and(|u| urls.iter().any(|x| x == u))
})
.count();
return Err(match (n > 1, kept) {
(false, _) => e,
(true, 0) => format!("{e} (none of the {n} files was added)"),
(true, k) => format!("{e} ({k} of the {n} files landed earlier and stay, each its own undo step)"),
});
}
Comment on lines 130 to 151

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All-or-none no longer holds across the pending runs. before is taken at the start of each run. On the first run, file 1's download is queued and file 2's is queued too, so this branch isn't reached. When a download later fails, the command reruns: file 1 has landed and is answered from its landed result, so its layer is already in the map and is part of the new before. If file 2's answer is now an error, restore_layers(&before) keeps file 1's layer. The command then returns an error that says "none of the 2 files was added", and the docs (docs/plugins.md, "It adds all of an area's files or none") say the same. The result is a partial add, which is the case this function's doc comment promises to rule out.

I haven't traced the failed-download path all the way (confidence: medium). It would be settled by a test where file 2's download fails after file 1 has landed, then checking the layer count and the answer. A fix needs the first run's layers to be recorded and removed when a later run fails, or the docs need to say that landed files stay.

Category: bug

}
}
Ok(json!({"layers": layers, "files": n}))
let mut out = json!({"layers": layers, "files": n});
if pending {
out["pending"] = json!(true);
}
Ok(out)
}

fn sourcecoop_products(_s: &mut Session, p: &Value) -> CmdResult {
Expand Down
113 changes: 113 additions & 0 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37495,6 +37495,119 @@ fn overture_files_are_added_all_or_none() {
assert_eq!(r["files"], 2);
let names: Vec<&str> = s.map().layers.iter().map(|l| l.name.as_str()).collect();
assert!(names.contains(&"Overture building (1/2)") && names.contains(&"Overture building (2/2)"), "{names:?}");
assert!(r.get("pending").is_none(), "files added here are not pending: {r}");
}

/// A plugin's command in the app leaves each Overture file to the app (`layer.addUrl`'s pending
/// answer): `overture.add` says so, instead of answering an empty list of layers (#2677).
#[test]
fn overture_files_a_plugin_command_leaves_to_the_app_answer_pending() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name and doc say "a plugin command", but this calls overture.add directly through run_leaving_downloads. The only plugin test (a_plugin_command_adding_overture_files_runs_again_when_they_are_added) passes files, so no test runs the area path (catalog read, then address fetches) through a plugin's rerun. That is the path where the release drift in catalogs.rs would happen. Suggest renaming this test to say it covers the deferred-download path, and adding a rerun test that goes through the area path. Also, no test covers a first run where one file is pending and a later file fails synchronously.

Category: quality

let home = "https://overturemaps-us-west-2.s3.amazonaws.com/release/2026-11-18.0/theme=buildings/type=building";
let urls = [format!("{home}/part-0.parquet"), format!("{home}/part-1.parquet")];
let mut s = Session::new(Project::default());
let r = s.run_leaving_downloads("overture.add", &json!({"theme": "buildings", "files": urls})).unwrap();
assert_eq!(r["pending"], true, "{r}");
assert_eq!((&r["files"], &r["layers"]), (&json!(2), &json!([])), "{r}");
assert!(s.map().layers.is_empty());
// Both files are asked for, named as the synchronous add names them; nothing was fetched.
let asked = s.take_url_requests();
let named: Vec<(&str, &str)> =
asked.iter().map(|q| (q.params()["url"].as_str().unwrap_or_default(), q.params()["name"].as_str().unwrap_or_default())).collect();
assert_eq!(named, [(urls[0].as_str(), "Overture building (1/2)"), (urls[1].as_str(), "Overture building (2/2)")]);
}

/// A plugin command that adds an area's Overture files in the app waits for them, and runs again
/// once the app has added them: its `overture.add` then answers both layers, added once (#2677).
#[test]
fn a_plugin_command_adding_overture_files_runs_again_when_they_are_added() {
use rustgis_data::{Dataset, Feature, Field, FieldType, Geometry, GeometryType, Value};
let mut ds = Dataset::new("b", GeometryType::Point, vec![Field::new("n", FieldType::Integer)]);
for i in 0..5u32 {
let c = rustgis_geom::Coord::new(7.0 + 0.01 * f64::from(i), 46.0);
ds.features.push(Feature { id: u64::from(i) + 1, geometry: Some(Geometry::Point(c)), attrs: vec![Value::Int(i64::from(i))] });
}
let bytes = rustgis_data::source::parquet::write(&ds).unwrap();
let mut s = world();
plugin("eng-overture", &["edit", "network"]);
let layers = s.map().layers.len();
let home = "https://overturemaps-us-west-2.s3.amazonaws.com/release/2026-11-18.0/theme=buildings/type=building";
let urls = [format!("{home}/part-0.parquet"), format!("{home}/part-1.parquet")];
let p = json!({"op": "overture.add", "params": {"theme": "buildings", "files": urls}});
let first = s.run_leaving_downloads("plugin:eng-overture/f", &p).unwrap();
assert_eq!(first["pending"], true, "{first}");
assert_eq!(s.map().layers.len(), layers, "the call's own run is undone");
let asked = s.take_url_requests();
assert_eq!(asked.len(), 2);
assert!(s.poll_plugin_retries().is_empty(), "nothing landed yet");
// The app downloads and adds both, each with its request's number.
for q in &asked {
let id = s.download_started_for(q).unwrap();
assert!(s.download_landed(id, bytes.clone()));
let mut add = q.params().clone();
add["id"] = json!(id);
s.complete_download(id, &add).unwrap();
}
assert_eq!(s.map().layers.len(), layers + 2);
let undo = s.undo.len();
let ran = s.poll_plugin_retries();
assert_eq!(ran.len(), 1, "{ran:?}");
let answer = ran[0].1.as_ref().unwrap();
assert_eq!(answer["layers"].as_array().map(Vec::len), Some(2), "{answer}");
assert!(answer.get("pending").is_none(), "{answer}");
let names: Vec<&str> = s.map().layers.iter().map(|l| l.name.as_str()).collect();
assert!(names.contains(&"Overture building (1/2)") && names.contains(&"Overture building (2/2)"), "{names:?}");
assert_eq!((s.map().layers.len(), s.undo.len()), (layers + 2, undo), "added once");
assert!(s.take_url_requests().is_empty() && !s.plugin_retries_waiting());
rustgis_plugins::unload("eng-overture");
}

/// When one of a plugin command's Overture files fails and the other landed (before or after it),
/// the command's error says that one stays (its own undo step), not that none was added.
#[test]
fn a_failed_pending_overture_add_says_which_files_stay() {
// The failed file comes second (the loop has added the first) or first (it never reaches the
// one that landed after it).
for bad_first in [false, true] {
a_failed_pending_overture_add_says_which_files_stay_in(bad_first);
}
}

fn a_failed_pending_overture_add_says_which_files_stay_in(bad_first: bool) {
use rustgis_data::{Dataset, Feature, Field, FieldType, Geometry, GeometryType, Value};
let mut ds = Dataset::new("b", GeometryType::Point, vec![Field::new("n", FieldType::Integer)]);
for i in 0..5u32 {
let c = rustgis_geom::Coord::new(7.0 + 0.01 * f64::from(i), 46.0);
ds.features.push(Feature { id: u64::from(i) + 1, geometry: Some(Geometry::Point(c)), attrs: vec![Value::Int(i64::from(i))] });
}
let good = rustgis_data::source::parquet::write(&ds).unwrap();
fn bad_bytes() -> Vec<u8> {
b"not a parquet file".to_vec()
}
let mut s = world();
plugin("eng-overture-fail", &["edit", "network"]);
let layers = s.map().layers.len();
let home = "https://overturemaps-us-west-2.s3.amazonaws.com/release/2026-11-18.0/theme=buildings/type=building";
let urls = [format!("{home}/part-0.parquet"), format!("{home}/part-1.parquet")];
let p = json!({"op": "overture.add", "params": {"theme": "buildings", "files": urls}});
s.run_leaving_downloads("plugin:eng-overture-fail/f", &p).unwrap();
let asked = s.take_url_requests();
assert_eq!(asked.len(), 2);
assert_eq!(asked[0].params()["url"], json!(urls[0]), "asked in the files' order");
// One lands and is added; the other's download fails.
for (q, bytes) in asked.iter().zip(if bad_first { [bad_bytes(), good.clone()] } else { [good.clone(), bad_bytes()] }) {
let id = s.download_started_for(q).unwrap();
assert!(s.download_landed(id, bytes));
let mut add = q.params().clone();
add["id"] = json!(id);
let _ = s.complete_download(id, &add);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of each complete_download is discarded, so the test doesn't check that the file which should land did land, or that the failing one failed. The layer-count assertion below catches a wrong total, but not which file was lost. Checking each result against bad_first would make the test say what it means, for example assert_eq!(s.complete_download(id, &add).is_err(), bad) with bad taken from the bytes pairing.

Confidence: medium. The test passes as written, so this is about clarity and a stronger check.

Category: quality

}
let ran = s.poll_plugin_retries();
let e = ran.first().and_then(|r| r.1.as_ref().err()).cloned().unwrap_or_default();
assert_eq!(s.map().layers.len(), layers + 1, "the file that landed stays: {ran:?}");
assert!(e.contains("1 of the 2 files landed earlier and stay"), "{e}");
assert!(e.contains(if bad_first { "part-0.parquet" } else { "part-1.parquet" }), "the failed file's own error: {e}");
assert!(!e.contains("none of the"), "{e}");
rustgis_plugins::unload("eng-overture-fail");
}

/// A multi-file add that fails puts the map back exactly: the same layers in the same order, and
Expand Down
9 changes: 9 additions & 0 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,15 @@ the way, once for each document at most, and a map layer is added by the run tha
16 documents are read at a time, and asking for more fails. In the web app
`service.add` still refuses to download.

`overture.add` does the same on the desktop when it adds an area's files: each GeoParquet file is
left to download as `layer.addUrl` does, and while any is under way it answers `{"pending": true,
"files": n, "layers": [...]}` (the layers already in; none on the first run), so the command can
return and runs again once they are added, when `overture.add` answers the ids of the layers it
added. Where it adds the files in the same run (the command line, the assistant) it adds all of an
area's files or none. When they are left to download, a file that fails stops the command with an
error that says how many landed before it. Those stay, each its own undo step.
It also fetches the catalog on each run, which waits with the window held.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This understates the window hold. Each run also fetches every chosen file's address (catalogs.rs, fetch(&f.item), up to MAX_FILES = 6) on the UI thread, not only the catalog. That path predates this PR, and "Never hold the window" applies to it, so the doc should at least name it.

Suggested change
It also fetches the catalog on each run, which waits with the window held.
It also fetches the catalog, and each chosen file's address (up to 6), on each run; both wait with the window held.

Category: quality


While a command waits the window answers, so the user can work and the project can change. The
status bar says the command is running, and asking for it again with the same parameters does
nothing. A run again sees the view the command first ran with, and the window's size then, unless
Expand Down
Loading