Skip to content

feat(engine): carry loss codes through reader and tool results - #2479

Merged
Mavrick-F merged 3 commits into
opengeos:mainfrom
Mavrick-F:feat/loss-result-producers
Nov 19, 2026
Merged

Mavrick-F merged 3 commits into
opengeos:mainfrom
Mavrick-F:feat/loss-result-producers

Conversation

@Mavrick-F

@Mavrick-F Mavrick-F commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Carry typed loss messages from readers and geoprocessing tools into the engine. GeoRSS classifies unreadable polygon holes as dropped.ring. Repair Geometry classifies attribute values with no matching field as dropped.extra-attributes.

Batch messages retain their codes for warnings, and tool history and delivery results retain the text. The WMS regression now checks the legend warning text as well as its code and severity.

The shared engine supplies the notices on desktop, browser, mobile, CLI, Python, MCP and Assistant. Public code fields for the automation adapters and strict mode remain part of #2371.

Testing

  • Focused reader, analysis, engine and WMS regressions.
  • Fork CI on the submitted commit, including the browser build.
  • Headless before and after views of the same GeoRSS import.

UI evidence

Before — The GeoRSS import reported the unreadable hole under Info.

Before

After — The same message appears under Warnings.

After

Related issue

Part of #2371. Follow-up to #2467.

Summary by CodeRabbit

  • New Features
    • Import and geometry-repair operations now identify certain dropped data—such as unreadable polygon holes or extra attribute values—with classified loss notices.
    • Loss notices are carried through tool results, batch operations, and file exports, making them available alongside existing messages and in delivered-file history.
    • Read reports now provide access to both ordinary messages and loss notices.
  • Bug Fixes
    • Loss notices are distinguished from ordinary messages while retaining their readable text and classification.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds classified loss messages to data read reports and analysis tool results. The engine carries loss codes and text through tool execution, batch reporting, notices, file delivery, and history. Existing tool results without classified losses initialize an empty loss list.

Changes: Loss reporting

Layer / File(s) Summary
Loss contracts and read classification
crates/data/src/loss.rs, crates/data/src/lib.rs, crates/data/src/georss.rs, crates/data/src/source/mod.rs, crates/engine/tests/never_silent_reading.rs, crates/engine/src/cmd/stac_area.rs, ROADMAP.md
LossCode adds DroppedRing and DroppedExtraAttributes, and LossMessage stores a code and text. ReadReport gains a loss list and an into_messages method. GeoRSS unreadable holes are classified as DroppedRing.
Tool result loss records
crates/analysis/src/lib.rs, crates/analysis/src/dggs.rs, crates/analysis/src/merge.rs, crates/analysis/src/tissot.rs, crates/analysis/src/tools.rs, crates/analysis/src/tools/*, crates/geolibre/src/lib.rs, crates/plugins/src/tools.rs, crates/assistant/src/tests.rs, crates/analysis/tests/*, crates/engine/src/tests.rs
ToolResult gains a losses field. Existing producers initialize it as empty; geometry repair returns a DroppedExtraAttributes loss when it truncates extra attribute values. Tests cover the structured loss result.
Engine loss propagation
crates/engine/src/cmd/gp.rs, crates/engine/src/cmd/layer.rs, crates/engine/src/policy/dispatch.rs, crates/engine/src/tests.rs
The engine carries loss codes alongside message text through input handling and tool execution. It reports typed losses separately from ordinary messages and retains loss text in file-delivery history.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant FileReader
  participant inputs_of
  participant ToolExecution
  participant publish_tool_loss
  FileReader->>inputs_of: returns classified read losses
  inputs_of->>ToolExecution: passes input losses
  ToolExecution->>publish_tool_loss: publishes loss code and text
Loading

Possibly related issues

  • opengeos/RustGIS#2371: The change adds typed loss codes to read and tool results, matching the issue objective.
  • opengeos/RustGIS#2008: The change carries typed losses through geoprocessing messages, but the supplied summary describes the issue as a remaining follow-up for other notice gaps.

Possibly related PRs

  • opengeos/RustGIS#2467: This PR carries loss codes through reader and tool results, using the typed-notice concept introduced there.

Suggested reviewers: pawelkra, flight1973

Merge Risk: Minimal · up to fad00

The change carries classified loss messages from readers and geometry tools to users. No concrete defect was found, and the inspected paths still show the warnings, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(engine): carry loss codes through reader and tool results" matches the main change. The raw summary and objectives show typed LossMessage values added to ReadReport and ToolResult, Geo…
Description check Passed The description follows the repository template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the loss-code classification for GeoRSS and Repair Geometry. Tes…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(engine): carry loss codes through reader and tool results" matches the main change. The raw summary and objectives show typed LossMessage values added to ReadReport and ToolResult, GeoRSS holes classified as DroppedRing, and Repair Geometry attribute truncation classified as DroppedExtraAttributes. The title is specific and follows conventional commit style.

Full details: Description check

Explanation

The description follows the repository template. It has Summary, Testing, UI evidence, and Related issue sections. The Summary explains the loss-code classification for GeoRSS and Repair Geometry. Testing lists focused regressions and CI. UI evidence includes before and after images, which fits the template's requirement for a visible UI change. Related issue links #2371 and #2467. Testing lacks specific commands or test names, which is a minor gap.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit sorts the losses by their code,
Then sends each notice down its winding road.
A dropped ring gets a name to show,
Extra fields are marked before they go.
Through batches, files, and history,
The hare keeps every loss in view.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 514bbb8d-0c99-403c-9988-5e5a8bf5ab36
Commits

Reviewing files that changed from the base of the PR and between 3081dc3 and fad00b6.

Files selected for processing: 3

  • crates/analysis/src/lib.rs
  • crates/engine/src/cmd/gp.rs
  • crates/engine/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

Comment thread crates/engine/src/cmd/gp.rs Outdated
const NAMED: usize = 50;
let classified = distinct_tool_messages.iter().filter_map(|(text, code, count)| Some((text, (*code)?, count)));
let listed = classified.clone().take(NAMED);
for (text, code, count) in listed {

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.

Batch loss notices are no longer aggregated by kind. Before this change, every tool message in a batch went into one gp.batch: N item(s) reported messages (…) notice. Now each distinct loss text gets its own Warning notice, up to 50, and the text usually embeds a per-item count (for example the features(tally.extra) figure in Repair Geometry). A batch over many layers with varying counts can therefore produce dozens of notices.

AGENTS.md asks for "one notice per kind with a count". Consider aggregating by code, for example one gp.batch: N item(s) lost <kind>: … notice per LossCode, with the sample and the "and N more, in the result" tail as the plain-message notice already does. Confidence: medium. I have not run a batch with varying counts to confirm the notice count.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Batch runs now emit one warning per loss code with a count and up to three examples. Full messages remain in the result. The expanded regression exercises different counts for the same code in one batch. It passed locally, and fork CI passed. fad00b6

Comment thread crates/analysis/src/lib.rs Outdated
pub struct ToolResult {
pub output: Output,
pub messages: Vec<String>,
/// Losses identified by the producer. Text-only consumers also display their text.

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 doc comment says text-only consumers "also display their text", but the producers this PR changes don't follow that contract. Repair Geometry now puts its extra-attributes text only in losses, not in messages. The engine merges the two, so the desktop, CLI and Python paths are fine. Any direct analysis::run caller that reads only messages now silently loses that notice, which AGENTS.md's "Never silent" rule forbids.

Suggest stating the contract exactly, for example: "messages holds text only; a producer with a classified loss puts it in losses and not in messages, so a consumer reads both." Alternatively, keep the text in messages too and dedupe in the engine. Confidence: low to medium; it depends on whether any non-engine consumer reads messages alone today. My search found none outside tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The field docs now say that classified losses appear in the losses list only, and that consumers displaying plain text must read both lists. The engine still retains both in history and delivery results. Fork CI passed. fad00b6

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I read the full diff, the base-branch AGENTS.md, and the surrounding code. prior-reviews.json has no threads, so I left none of the earlier concerns alone. The change itself is sound. Its main path (gp.run, layer.addData, gp.batch, file delivery) carries the new losses through to notices, and the tests cover both the lossy and clean cases.

Bugs

  • Low confidence (about 0.35): ToolResult.losses is documented as "text-only consumers also display their text", but Repair Geometry now puts its text only in losses. The engine merges the two, so the desktop, CLI and Python paths are fine. A direct analysis::run caller that reads only messages would drop the notice silently. Inline comment on crates/analysis/src/lib.rs:168.
  • Low confidence (about 0.3): in file_delivered (crates/engine/src/cmd/gp.rs:2708), a loss on a failed delivery is reported as an uncoded error notice. The loss code is lost in that branch. The file was not written, so this may be acceptable.

Security

  • None found. The new text is produced by the tools and readers, and no new input path was added.

Performance

  • None found. The clones in inputs.losses.iter().cloned() are small, and distinct_tool_messages was already unbounded before this change.

Quality

  • The inputs_of rebinding (let losses = Vec::new(); followed by a cfg tuple rebind) is awkward. Left for the release quality pass.
  • Adding a pub field to ToolResult breaks external struct literals. Consider #[non_exhaustive] or a constructor. Left for the release quality pass.

AGENTS.md

  • Medium confidence (about 0.6): in batch runs, each distinct loss text now becomes its own Warning notice, up to 50 of them. Previously, tool messages in a batch were aggregated into one gp.batch: N item(s) reported messages notice. The texts embed per-item counts, so the new behaviour departs from "one notice per kind with a count". Inline comment on crates/engine/src/cmd/gp.rs:2305.
  • Checked and not raised: the Python binding, the streamed-layer path, add_reads, the service-group GeoJSON path, and the repair_geometry test at line 585 (its said is the no-area notice, not the extra-attributes text). None of these lose a classified loss.

Earlier concerns left alone: 0 (no prior threads).

I could not compile or run the tests in this environment, so the findings above rest on reading the code.

Change size

Compared with main (merge base 96da316 to PR head 3081dc3): the whole PR, not the latest push.

Measure Value
Files changed 26 (0 added, 26 modified, 0 removed, 0 renamed)
Size before 5.43 MB
Size after 5.44 MB
Total size change +8.3 KB
Path Before After Change
crates/engine/src/cmd/gp.rs 285.1 KB 288.4 KB +3.3 KB
crates/engine/src/tests.rs 3.12 MB 3.13 MB +1.8 KB
crates/engine/tests/never_silent_reading.rs 35.7 KB 36.3 KB +647 B
crates/data/src/loss.rs 2.0 KB 2.5 KB +539 B
crates/analysis/src/tools.rs 869.7 KB 870.2 KB +489 B
crates/data/src/lib.rs 50.3 KB 50.7 KB +380 B
crates/analysis/src/tools/repair_geometry.rs 19.3 KB 19.5 KB +202 B
crates/engine/src/cmd/layer.rs 359.2 KB 359.3 KB +146 B
crates/analysis/src/lib.rs 33.7 KB 33.8 KB +142 B
crates/analysis/tests/repair_geometry.rs 55.7 KB 55.8 KB +126 B
crates/data/src/georss.rs 16.7 KB 16.7 KB +76 B
crates/analysis/src/merge.rs 5.1 KB 5.2 KB +49 B
crates/analysis/tests/resolved_tools.rs 5.4 KB 5.5 KB +49 B
crates/analysis/src/dggs.rs 32.4 KB 32.4 KB +40 B
crates/analysis/src/tools/network_analysis.rs 36.9 KB 36.9 KB +40 B
crates/plugins/src/tools.rs 18.1 KB 18.2 KB +40 B
crates/data/src/source/mod.rs 57.6 KB 57.7 KB +28 B
crates/analysis/src/tissot.rs 18.7 KB 18.7 KB +20 B
crates/analysis/src/tools/check_geometry.rs 20.0 KB 20.0 KB +20 B
crates/analysis/src/tools/geometry.rs 14.7 KB 14.7 KB +20 B

The table lists the 20 largest changes. The other six files changed by under 20 bytes each.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2479/
Web app https://preview.rustgis.app/pr-2479/app/
Commit fad00b6

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@Mavrick-F

Copy link
Copy Markdown
Member Author

The two inline findings are addressed in the fix commit. On failed file delivery, the report retains the error and the loss text. A coded delivery loss describes a file that reached its destination. The constructor and cfg-binding suggestions are left for the release quality pass. fad00b6

Comment thread crates/data/src/georss.rs
assert!(lossy[0].0.features[0].geometry.is_some());
assert!(
lossy[0].1.messages.iter().any(|m| m.contains("1 hole in a polygon was unreadable and left out")),
lossy[0].1.losses.iter().any(|m| m.code == crate::loss::LossCode::DroppedRing && m.text.contains("1 hole in a polygon was unreadable and left out")),

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 line is 141+ characters, and the repo's rustfmt.toml sets max_width = 140, so cargo fmt --check (part of cargo xtask ci) will fail on it. Splitting the closure body keeps the same assertion:

Suggested change
lossy[0].1.losses.iter().any(|m| m.code == crate::loss::LossCode::DroppedRing && m.text.contains("1 hole in a polygon was unreadable and left out")),
lossy[0].1.losses.iter().any(|m| {
m.code == crate::loss::LossCode::DroppedRing && m.text.contains("1 hole in a polygon was unreadable and left out")
}),

Confidence: high (line length measured from the diff).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The formatting hook passed on this exact head in fork and upstream CI. Splitting the assertion for readability is left for the release quality pass.

return Err(format!("{path} has more than {} features: simplify it or use a bounding box", area::MAX_FEATURES));
}
let mut messages: Vec<String> = report.messages.into_iter().map(|m| format!("{path}: {m}")).collect();
let mut messages: Vec<String> = report.into_messages().map(|m| format!("{path}: {m}")).collect();

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.

into_messages() turns a classified dropped.ring loss from a GeoRSS hole back into plain text, and from_file then calls s.warn(m). The STAC search-area path therefore reports the loss without its code, so a scheduled job checking codes won't see it. The text is kept, so nothing is silent, but the classification this PR adds is lost on this path. The same gap applies to a file read as a tool input through inputs_of, which this PR also covers.

Suggest carrying Vec<LossMessage> (or (String, Option<LossCode>)) out of read_geometries and publishing coded losses through s.notify_loss in from_file, so the code survives. Confidence: medium. I did not find a test for the STAC path or for a file-input tool loss.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

STAC uses read_path, which does not accept GeoRSS. ZIP members use read_bytes, which also does not accept GeoRSS. The classified producer reaches Add Data via read_layers. The tool input adapter already transfers report.losses into the tool result. Carrying codes on the STAC path when it gains a classified producer is left for the release quality pass.

#[cfg(target_arch = "wasm32")]
{
let msgs = result.messages.clone();
let msgs = result.messages.iter().cloned().map(|m| (m, None)).collect();

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.

On the queued path (browser, and tests with queue_gp_files), the returned msgs drop result.losses and keep only the plain messages. A batch running a file-output tool therefore never sees those losses, so BatchLosses can't aggregate them. The losses are published one at a time later, in file_delivered, which is the per-item behaviour this PR removes for batches. The same thing happens at the test-only branch on line 2895.

No tool that produces losses today has a file output on this path, so this is latent. Still, the returned messages should be built the same way as the native path (plain messages plus coded losses, around line 3003), so the batch aggregator sees them. Confidence: medium on the fix, low on whether a user can hit it today.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A queued result has not reached its destination. Its typed losses are retained with the pending file and published on successful delivery. Returning them to the batch early would report them before delivery and can report them again at delivery. No file-output tool currently produces coded losses. Grouping successful queued deliveries can be revisited with the first such producer and is left for the release quality pass.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • Line over the rustfmt limit (posted inline, georss.rs:296). One test line is 141+ characters against max_width = 140, so cargo fmt --check fails. Confidence: high.
  • STAC search-area path drops the loss code (posted inline, stac_area.rs:47). into_messages() flattens a dropped.ring loss to plain text, and s.warn then emits it unclassified. The text is kept, so nothing is silent, but the code this PR adds is lost. Confidence: medium.
  • Queued file outputs hide losses from batch aggregation (posted inline, gp.rs:2929; test-only copy at gp.rs:2895). The returned messages omit coded losses, so BatchLosses never sees them. No producer reaches this path today, so it is latent. Confidence: medium on the fix, low on user impact.
  • Failed file delivery drops the code (gp.rs:2739). When delivery fails, losses go through s.notify(…, true) as plain errors instead of publish_tool_loss. Low impact, since the output was not delivered.

Security

  • None found in the changed code.

Performance

  • None new. The batch distinct_tool_messages linear search predates this change.

Quality

  • Breaking ToolResult change. The new public losses field is a required struct field, which forces losses: Vec::new() into about 35 sites and breaks any external struct-literal constructor (register_external authors). A Default derive or a constructor would avoid this. Confidence: high on the fact.
  • Nested prefix in the batch reader notice (gp.rs:2348). The sample reads gp.batch: N loss report(s) (gp.batch: N inputs (…): …). Cosmetic.
  • Awkward cfg split in inputs_of (gp.rs:1260). Works on both targets, but could be simpler with an allow attribute.
  • materialize_within hardcodes losses: Vec::new() (source/mod.rs:670). Correct today because no source produces losses, but it silently drops any future source losses. Low.
  • Test gaps. tool_result_reports_classified_attribute_loss covers only Layer outputs. Nothing exercises a file output with losses, a file-input tool loss (inputs_of), or the STAC path. Confidence: medium.

AGENTS.md

  • Checked and fine: no new unwrap/expect in non-test code, the one-notice-per-kind-with-count rule is met for batch losses, both-ways tests exist for GeoRSS, and the PR body covers the surfaces. The batch notice still uses format!, which matches the surrounding engine code.

Earlier concerns

  • Two earlier threads are on this PR. The batch per-text notices concern is addressed: losses now aggregate by code (gp.rs:2300 onward). The analysis::ToolResult doc-contract thread was partly addressed by the new doc comment, and I left it alone. Two concerns were not re-posted.

Change size

Compared with main (merge base 96da316 to PR head fad00b6). 26 files, all modified.

Measure Value
Files changed 26 (added 0, modified 26, removed 0, renamed 0)
Size before 5.43 MB
Size after 5.44 MB
Total size change +10.0 KB
Path Before After Change
crates/engine/src/cmd/gp.rs 285.1 KB 289.4 KB +4.3 KB
crates/engine/src/tests.rs 3.13 MB 3.13 MB +2.6 KB
crates/engine/tests/never_silent_reading.rs 35.7 KB 36.3 KB +647 B
crates/data/src/loss.rs 2.0 KB 2.5 KB +539 B
crates/analysis/src/tools.rs 869.7 KB 870.2 KB +489 B
crates/data/src/lib.rs 50.3 KB 50.7 KB +380 B
crates/analysis/src/lib.rs 33.7 KB 34.0 KB +260 B
crates/analysis/src/tools/repair_geometry.rs 19.3 KB 19.5 KB +202 B
crates/engine/src/cmd/layer.rs 359.2 KB 359.3 KB +146 B
crates/analysis/tests/repair_geometry.rs 55.7 KB 55.8 KB +126 B
crates/data/src/georss.rs 16.7 KB 16.7 KB +76 B
crates/analysis/src/merge.rs 5.1 KB 5.2 KB +49 B
crates/analysis/tests/resolved_tools.rs 5.4 KB 5.5 KB +49 B
crates/analysis/src/dggs.rs 32.4 KB 32.4 KB +40 B
crates/analysis/src/tools/network_analysis.rs 36.9 KB 36.9 KB +40 B
crates/plugins/src/tools.rs 18.1 KB 18.2 KB +40 B
crates/data/src/source/mod.rs 57.6 KB 57.7 KB +28 B
crates/analysis/src/tissot.rs 18.7 KB 18.7 KB +20 B
crates/analysis/src/tools/check_geometry.rs 20.0 KB 20.0 KB +20 B
crates/analysis/src/tools/geometry.rs 14.7 KB 14.7 KB +20 B

The table lists the 20 largest changes. The remaining 6 files changed by under 20 B each.

@Mavrick-F

Copy link
Copy Markdown
Member Author

The inline replies cover formatting, STAC and queued output. A failed delivery retains the diagnostic text and has no committed file loss to report. The constructor, batch prefix, cfg binding, and future source and file-output coverage suggestions are left for the release quality pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant