Skip to content

feat(engine): a linked layer says when its source's feature count has changed - #3272

Closed
Mavrick-F wants to merge 2 commits into
opengeos:mainfrom
Mavrick-F:feat/linked-source-feature-count
Closed

Mavrick-F wants to merge 2 commits into
opengeos:mainfrom
Mavrick-F:feat/linked-source-feature-count

Conversation

@Mavrick-F

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

Copy link
Copy Markdown
Member

Summary

Linked layers now report how many features their source gained or lost since the project was saved. The check uses the reopened source header. Sources that finish opening later compare it alongside the saved fields on their first view.

Not for merging yet: the compatibility cost below is undecided. This adds an optional field to format 2 together with a linked-source-feature-count requirement. A project, map or layer file that has a layer read in place from a file with a known count lists it, so 0.8.0 and earlier refuse to open that file; they open such a project when it is saved without this change. Saves use a whole-source count the reader already knows. A definition query or view window can show fewer rows while the saved count still covers the source. Subset and estimated counts leave the field absent. The linked-source-feature-count requirement protects files with a baseline from older readers that would discard it on save.

The shared project and map paths cover desktop, browser, and mobile. Local links report changes during project open, including from the CLI and Python. Assistant, MCP, and plugins retain their existing command interfaces. The notice records a net change on reopen and creates no Undo step. The comparison adds two optional counts per link and holds 0× the layer's feature storage.

Testing

  • The baseline CLI saved a two-feature link without a count and reopened the one-feature replacement without a notice. The changed CLI saves the baseline and reports one fewer on reopen.
  • Focused engine and map regressions passed. They cover a partial window, increased and decreased counts, equal counts, older projects, one notice per layer, and serialization of known and unknown totals.
  • Regenerated the project schema and added a fixture. All 76 fixtures opened, the new fixture validated against the schema, and formatting and Clippy passed.
  • The released v0.8.0 CLI discarded an unguarded count on resave. With the capability it refused by name and left the file byte-for-byte unchanged.
  • Linked reopens in Twin Cities, Portland, and Utrecht reported the added field and one fewer feature at 17,678, 79,867, and 205,924 respectively. The Portland replay uses a field that sorts after the saved columns to exercise the additive schema case.

The full Linux fork gate passed, including the wasm build and browser smoke test.

UI evidence

Portland parcel layer reopened with an added field and one fewer feature

Related issue

Part of #1998

Related to #1853

Summary by CodeRabbit

  • New Features
    • Projects now report when the feature count in a linked source differs from its saved count, indicating whether the count increased or decreased.
    • Count-change notices appear once when the source is checked, and no notice appears when the count is unchanged.
    • Existing projects without saved feature-count information continue to open without a count-change notice.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Projects now save feature counts for eligible linked sources and compare those counts when streamed sources open. When a count changes, the session publishes a notice with the saved and current counts.

Changes: Linked source feature-count tracking

Layer / File(s) Summary
Save and compare source feature counts
crates/map/src/source.rs, crates/map/src/lib.rs, crates/engine/src/project.rs
Source layers save counts for eligible linked files and check them during synchronization and project opening. Changed saved/current counts can be retrieved for notices.
Declare saved-count capability
crates/engine/src/project.rs, crates/engine/src/project_capabilities.rs, schema/project.schema.json, schema/fixtures/linked_source_feature_count.rgis
Project and map capability detection includes linked-source feature-count support. The schema and fixture include the capability and saved-count field.
Publish count-change notices
crates/engine/src/notice_text.rs, crates/engine/src/lib.rs, crates/engine/src/tests.rs
Session notices report changed source counts. Tests cover increases, decreases, unchanged counts, repeated synchronization, and legacy metadata.

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant LayerSync as Layer::sync_source_with
  participant SourceLayer
  participant SessionNotice as Session::notice_landed_pixels
  LayerSync->>SourceLayer: check_feature_count()
  SessionNotice->>SourceLayer: take_feature_count_change()
  SourceLayer-->>SessionNotice: saved/current pair when counts differ
  SessionNotice->>SessionNotice: publish non-error notice
Loading

Possibly related issues

  • opengeos/RustGIS#1853: Adds a changed-source notice on reopen and records linked-source count support in format 2 project metadata.
  • opengeos/RustGIS#1405: Adds a required capability marker for the saved-count field in the project schema.

Suggested reviewers: elpidioassinaturas, giswqs

Merge Risk: Minimal · up to d74e0

This adds a notice when a linked source's feature count has changed since the project was saved. It is additive and guarded by a capability, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(engine): a linked layer says when its source's feature count has changed" matches the main change. The PR adds a notice when a linked layer's source gains or loses features since the p…
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.
Description check Passed The description follows the template's Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change: linked layers report a feature-count change since the project was sav…
Full details: Title check

Explanation

The title "feat(engine): a linked layer says when its source's feature count has changed" matches the main change. The PR adds a notice when a linked layer's source gains or loses features since the project was saved. The changeset adds the saved_feature_count tracking in map/source.rs, the notice text in notice_text.rs, the engine notice publishing in lib.rs, the capability and schema updates, and tests. The title is specific and follows a conventional commit prefix. It is one sentence and stays under 80 characters.

Full details: Description check

Explanation

The description follows the template's Summary, Testing, UI evidence, and Related issue sections. The Summary explains the change: linked layers report a feature-count change since the project was saved, using the reopened source header. The Testing section lists the CLI baseline and changed-run checks, focused engine and map regressions, fixture and schema checks, the v0.8.0 compatibility check, and reopen results for three datasets. The UI evidence section includes a screenshot of the reopened Portland layer and its notice. The Related issue section links Part of #1998 and Related to #1853. The author marks the PR as not ready to merge because the compatibility cost is undecided. That is a stated status, not a missing template section. The Testing section cites the full gate passing, but the description does not give the exact command, such as cargo xtask ci. The template does not require that command, so it does not block a pass.

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 checks the counts at dawn,
Two saved, then one has hopped along.
The source reports the changed amount,
A notice marks the new account.
The burrow’s fields are counted right,
Then carrots crunch through quiet night.

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: 324e2145-df65-4d1c-ac8b-2b310df9edeb
Commits

Reviewing files that changed from the base of the PR and between 14c3c20 and d74e0b5.

Files selected for processing: 9

  • crates/engine/src/lib.rs
  • crates/engine/src/notice_text.rs
  • crates/engine/src/project.rs
  • crates/engine/src/project_capabilities.rs
  • crates/engine/src/tests.rs
  • crates/map/src/lib.rs
  • crates/map/src/source.rs
  • schema/fixtures/linked_source_feature_count.rgis
  • schema/project.schema.json

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

Comment thread crates/map/src/source.rs
Comment on lines +1119 to +1121
pub fn feature_count_for_save(&self) -> Option<u64> {
if self.is_open() { self.linked_feature_count() } else { self.checked_feature_count.or(self.saved_feature_count) }
}

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.

When a source is open, this returns the live header count and ignores the saved baseline. The baseline is only compared at check_feature_count, and take_feature_count_change only clears it later, in notice_landed_pixels. Any save that runs before that point overwrites the baseline with the current count, so the change is never reported. Two paths reach that state:

  • repair(false, …) (normalize_after, used when a map is imported) opens linked sources and never calls check_feature_count, because the check is gated on opened.
  • A source that opens with skipped rows returns None here, so the baseline and the linked-source-feature-count requirement are dropped with no notice.

A save of a project that was just opened, with no frame between, does the same. Keeping an uncompared or unsaid baseline until it is taken fixes all three. Please also add a regression test that saves before any view sync and one that imports a linked layer, since the current test only saves after a sync.

Suggested change
pub fn feature_count_for_save(&self) -> Option<u64> {
if self.is_open() { self.linked_feature_count() } else { self.checked_feature_count.or(self.saved_feature_count) }
}
pub fn feature_count_for_save(&self) -> Option<u64> {
// A baseline not yet compared or reported stays the count written: the header read now may differ from it.
if let Some(saved) = self.saved_feature_count {
return Some(saved);
}
if self.is_open() { self.linked_feature_count() } else { self.checked_feature_count }
}

Category: bug

Comment thread crates/engine/src/lib.rs
Comment on lines +3066 to +3067
if let Some((saved, current)) = layer.source.as_mut().and_then(|source| source.take_feature_count_change()) {
source_counts.push(notice_text::NoticeText::source_count_changed(&layer.name, saved, current));

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.

AGENTS.md asks for one notice per kind with a count. This pushes one notice per linked layer, so a project with several changed links gives several notices of the same kind. The existing source_errors path already aggregates this way, with a count. The same pattern would fit here: collect (name, saved, current) and emit one source_count_changed-style notice with a count, or name the layers in a list. The test that checks one notice per layer would then need updating.

Category: agents-md

Comment thread crates/map/src/source.rs

/// A streamed layer's source.
#[derive(Clone, Default, Serialize, Deserialize)]
#[serde(remote = "Self")]

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.

#[serde(remote = "Self")] is needed here only so that getter works on a private field. With a remote derive, the derive emits inherent serialize/deserialize functions and not trait impls, which is why the manual impl Serialize/Deserialize below call Self::serialize. Inherent methods win path resolution, so this is correct, but it reads like infinite recursion. A one-line comment saying so, and why a getter is needed, would save the next reader time.

Category: quality

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Reviewed the 9-file diff against pr-context/AGENTS.md, the SourceLayer save and check paths, and the project-open and notice paths. No prior review threads exist on this PR, so none were skipped. I could not build or run the tests (no shell in this session), so the findings below come from reading the code.

Bugs

  • Baseline overwritten before comparison (crates/map/src/source.rs:1119). When a source is open, feature_count_for_save returns the live header count and ignores the saved baseline. Any save before check_feature_count and take_feature_count_change run overwrites the baseline and the change is never reported. This happens on the import path (repair(false) opens sources without checking), on a save with no frame in between, and when a source opens with skipped rows (the field and the requirement are then dropped silently). The suggested fix keeps an uncompared or unreported baseline. Confidence: about 70%.
  • relinked drops the baseline (crates/map/src/source.rs:1194). A relinked layer loses saved_feature_count. On save, the field and the linked-source-feature-count requirement disappear with no notice. Confidence: about 60%.

Security

  • None found.

Performance

  • None significant. The new per-frame check_feature_count short-circuits once the baseline is compared, and the new fields add no layer-sized storage.

Quality

  • #[serde(remote = "Self")] (crates/map/src/source.rs:122) plus the manual trait impls is correct because inherent methods win path resolution. It needs a comment, since it reads like recursion. Confidence: high.

AGENTS.md

  • One notice per layer (crates/engine/src/lib.rs:3066). AGENTS.md asks for one notice per kind with a count. The source-count notices are pushed per layer, while the existing source_errors path aggregates. Confidence: about 60%.

Twins checked

  • Linked read routes: addData by path and linked are covered by linked_file() and is_remote_name. GDAL and DuckDB are excluded explicitly. addDataBytes, addDataText and addDownload do not set a linked path. PostGIS, MySQL and SQL Server are excluded through linked_file(). I did not verify the zip member count.
  • Project open: project.open is covered. project.import (repair(false)) is not, which is bug 1.
  • Overlay tools and wasm branches: not touched by the diff.

Change size

Compared with the base branch (merge base d364137 to PR head d74e0b5), 9 files changed: 1 added, 8 modified, 0 removed, 0 renamed.

Measure Value
Files changed 9 (added 1, modified 8, removed 0, renamed 0)
Size before 4.74 MB
Size after 4.75 MB
Total size change +10.3 KB
Path Before After Change
crates/engine/src/tests.rs 3.73 MB 3.73 MB +3.4 KB
crates/map/src/source.rs 134.7 KB 137.3 KB +2.6 KB
schema/fixtures/linked_source_feature_count.rgis 0 B 2.0 KB +2.0 KB
crates/engine/src/notice_text.rs 5.7 KB 6.7 KB +1.0 KB
crates/engine/src/lib.rs 224.0 KB 224.4 KB +393 B
crates/engine/src/project_capabilities.rs 198.0 KB 198.4 KB +371 B
crates/engine/src/project.rs 154.3 KB 154.6 KB +295 B
crates/map/src/lib.rs 281.9 KB 282.1 KB +204 B
schema/project.schema.json 37.7 KB 37.8 KB +76 B

@Mavrick-F
Mavrick-F marked this pull request as draft November 28, 2026 21:10
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Findings are grouped by category. I read the full diff, the base AGENTS.md, and the three prior threads, and checked the code they point at. I did not build or run the tests; findings come from reading the code.

Bugs

  • FlatGeobuf with zero features loses the count change (confidence about 60%, inline comment posted at crates/map/src/source.rs:1114). fgb.rs:282 maps a header count of 0 to None, and None here means "unknown". A linked FlatGeobuf that now holds no features gets no notice, and while it is open the saved count and the linked-source-feature-count requirement are dropped on the next save. I did not confirm how the FlatGeobuf header encodes an unknown count, so the fix depends on that.
  • Earlier thread still holds, not re-posted (source.rs:1121). Saving before the first check, or after an import or a skipped-row open, still overwrites the baseline. The code is unchanged, so I left it alone.

Security

  • None found.

Performance

  • None found. check_feature_count does one header read per layer and then returns. The PR adds two Option<u64> per source.

Quality

  • Earlier thread still holds, not re-posted (source.rs:122). The remote-derive comment is still missing.
  • Nit, not posted: the test's translated(...).contains("{change}") only checks that a placeholder is present. A fixed expected rendered string would be stronger.
  • Lower confidence, not posted: the GDAL and DuckDB exclusion in linked_feature_count is deliberate, but the PR text does not say that those linked layers never get a count notice.

AGENTS.md

  • Earlier thread still holds, not re-posted (engine/src/lib.rs:3068). One notice is still pushed per changed layer, not one per kind with a count.

Other points (lower confidence, not posted)

  • In-session changes may go unreported (about 40%). While a source is open, feature_count_for_save writes the live count rather than the last checked count. A file that changes between open and save is therefore never reported on a later open.
  • Compatibility. The PR text already flags it: any project with a local link now needs linked-source-feature-count, so 0.8.0 refuses those files. Maintainers need to decide that.
  • Twins checked:
    • addDataBytes and addDataText are embedded, so linked_file excludes them.
    • GDAL and DuckDB are excluded explicitly.
    • FlatGeobuf is the bug above.
    • addDownload and zip routes are not verified.
  • Test gaps. The tests do not cover save before the first view sync or an imported linked layer. Prior threads already raise both.

Change size

Compared with the base branch: merge base 14c3c20 to PR head 110f565 (whole PR against main).

Measure Value
Files changed 9 (1 added, 8 modified, 0 removed, 0 renamed)
Size before 4.76 MB
Size after 4.77 MB
Total size change +10.3 KB
Path Before After Change
crates/engine/src/tests.rs 3.74 MB 3.74 MB +3.4 KB
crates/map/src/source.rs 134.7 KB 137.3 KB +2.6 KB
schema/fixtures/linked_source_feature_count.rgis 0 B 2.0 KB +2.0 KB
crates/engine/src/notice_text.rs 5.7 KB 6.7 KB +1.0 KB
crates/engine/src/lib.rs 224.0 KB 224.4 KB +393 B
crates/engine/src/project_capabilities.rs 205.6 KB 205.9 KB +371 B
crates/engine/src/project.rs 154.8 KB 155.1 KB +295 B
crates/map/src/lib.rs 283.3 KB 283.5 KB +204 B
schema/project.schema.json 37.9 KB 37.9 KB +76 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3272/
Web app https://preview.rustgis.app/pr-3272/app/
Commit 110f565

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

Closing this. Once written, the saved count needs a capability that older releases refuse, so ordinary projects with a layer read in place would stop opening in them, for the sake of one notice. Reading the count first and writing it a release later would soften that, but not enough to be worth it. #3208 already says when a linked source's fields change.

@Mavrick-F Mavrick-F closed this Nov 29, 2026
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