Skip to content

fix(engine): Import QGIS Style reads its file and images on a thread, with Cancel (#2620) - #2676

Merged
giswqs merged 2 commits into
opengeos:mainfrom
choupeanut:fix/2620-qgis-style-read-thread
Nov 22, 2026
Merged

giswqs merged 2 commits into
opengeos:mainfrom
choupeanut:fix/2620-qgis-style-read-thread

Conversation

@choupeanut

@choupeanut choupeanut commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

style.importQgis read its .qml (up to 256 MiB), parsed it (up to 64 MiB of XML) and read and decoded each raster image marker's image on the window's thread, with no Cancel (raised in review of #2612).

In the desktop app it is now a read made ahead (in reads::IN_BACKGROUND), as Size by Field and Column Statistics are: reads::prepare reads and parses the style on a thread of its own, and the command takes the result when it lands. The read looks at Cancel after the file read, before each image and once the parse is done, so a Cancel during the images is the cancelled error, not a style with skipped images. The style is applied only on landing, so a cancelled import leaves the layer as it was, and the landing is one Undo step. A layer renamed while its style was read is refused ("the layer was renamed while its style was read: import it again"), as the read used the old name.

Every other caller (the command line, Python, scripts and models, the Assistant and MCP, the browser, which has no read thread) reads where the command runs, as before. The single file read and the XML parse don't look at Cancel inside them (bounded by the 256 MiB and 64 MiB limits), and there is no progress count, only the background-read bar's busy indicator.

project.importQgis still runs on the window's thread (#2476). It shares the image reader, and a script or model runs it under Cancel, so it gains the same look once its parse is done: a Cancel during its images adds no layers, rather than an import with skipped images. No test drives that project path's Cancel.

Memory: one copy of the command's own text or data (at most 64 MiB, or its base64) while the read runs; no layer or raster data is copied. docs/user-guide/workspace.md names it among the reads made on a thread.

Testing

  • New: qgis_style_import_reads_its_files_ahead (engine): the style is read ahead; it still lands after the .qml and image are deleted; the notes and marker match the inline route for a clean PNG and a lossy GIF; Undo; a Cancel at every check, on the read thread and run inline under a probe, ends as the cancelled error with the project unchanged; a rename between the read and the landing is refused. Before the change it failed (the command wasn't among those that prepare background work); without the look after the parse it fails (the file, the image and the parse's end look: 2).
  • style.importQgis is registered in reads::IN_BACKGROUND, and cancellation.rs reads it with a raster marker image, so long_commands runs it in both Cancel sweeps.
  • a_qgis_style_is_read_on_a_thread_before_it_lands (ui-egui readjob): the job starts as "Import QGIS Style", the layer is styled only on landing, a lossy GIF is noted once on landing, a clean style says nothing, and Undo.
  • cargo test -p rustgis-engine --lib with the qgis/style import, cancel, similar, hostile_params_never_panic and permission_policy filters; cargo test -p rustgis-ui-egui --lib readjob; clippy with -D warnings on engine and ui-egui.
  • Local gate on origin/main (8265123) with this branch and one other of mine (fix/2447-terrain-block-keys) merged: pre-commit on every file, cargo fmt --check, clippy with -D warnings, cargo test --workspace (8721 passed, 0 failed), cargo xtask layers, cargo xtask schema --check with the fixtures checked against the schema and test hygiene, cargo xtask rows, and the Python package's tests (maturin + pytest, 44 passed). Not run here: the wasm32 build (no clang on this machine; CI's Web app job checks it), macOS and Windows.

UI evidence

No new UI: the existing background-read bar (busy indicator and Cancel) shows while a QGIS style imports. No screenshot taken.

Related issue

Closes #2620. #2476 (project.importQgis off the window) is a separate change and stays open.

Summary by CodeRabbit

  • New Features
    • QGIS style imports in the desktop app now read style and raster image-marker files in the background. You can continue working while files are read, and cancel the import without changing the layer.
    • Style changes are applied only after the files are read successfully.
  • Documentation
    • Updated the workspace guide with details about background reading and cancellation behavior for QGIS style imports.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

QGIS style imports can read the style file and raster marker images in the background on desktop. The import checks for cancellation and applies the style after the read completes. The change also adds cancellation checks to QGIS project imports and tests for read-ahead, landing, and undo behavior.

Changes: QGIS Style Import

Layer / File(s) Summary
Style reading and cancellation
crates/engine/src/cmd/qgis.rs, crates/engine/src/tests.rs, crates/engine/src/tests/cancellation.rs
Style reads check for cancellation before parsing and after marker-image reads. Read-ahead results are associated with a layer name, and landing fails if that layer was renamed. Project import checks cancellation before adding layers. Engine tests cover read-ahead, cancellation, file removal, and undo behavior.
Background read wiring and landing
crates/engine/src/cmd/reads.rs, crates/engine/src/policy/dispatch.rs, crates/ui-egui/src/lib.rs, crates/ui-egui/src/readjob.rs, docs/user-guide/workspace.md
The read system registers style.importQgis as a background read and captures its layer selector. Desktop dispatch sends it through the read-job system. Tests cover style application on landing, undo, and notices for unsupported images. The user guide describes the background read and cancellation behavior.

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

Change: Feature · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DesktopDispatch
  participant ReadJob
  participant ReadsPrepare
  participant QgisStyleAhead
  participant ReadStyleFile
  DesktopDispatch->>ReadJob: Queue style.importQgis
  ReadJob->>ReadsPrepare: Prepare background read
  ReadsPrepare->>QgisStyleAhead: Resolve target layer and schedule read
  QgisStyleAhead->>ReadStyleFile: Read style and marker images
  ReadStyleFile-->>QgisStyleAhead: Return style and report or error
  ReadJob->>QgisStyleAhead: Provide prefetched result at landing
Loading

Possibly related issues

  • Issue 2476 concerns project imports running on the window thread without cancellation. This change adds cancellation checks to project import but does not move it to a background thread.
  • Issue 2641 concerns UI-thread reads and cancellation tests. This change adds a reads::prepare path for QGIS style imports and adds cancellation coverage.

Possibly related PRs

  • opengeos/RustGIS#825: This PR introduces the QGIS style import command that this change routes through background reads.

Suggested reviewers: jgregoriorincon, giswqs, mavrick-f

Merge Risk: Minimal · up to 0d44e

Desktop QGIS style imports now read the style file and marker images in the background, with Cancel and a single Undo step. No concrete merge-blocking risk remains. The reported validation covers the engine and UI tests on the author's local workspace gate.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: desktop style.importQgis (QGIS style) file and image reads move to a background thread with Cancel support, tied to issue #2620. The changeset matches this (reads.rs I…
Description check Passed The description covers the Summary (what changed, why, the Cancel checkpoints, the rename refusal, memory notes and scope limits), Testing (new test, filters, local gate results, untested platforms), …
Linked Issues check Passed Direct issue #2620 asks for a style.importQgis arm in reads::prepare that reads the .qml and raster-marker images on a thread, then hands them to the command, with Cancel. The summary shows `IN_…
Out of Scope Changes check Passed Changes are: qgis.rs (style read split into read_style_file, Cancel checks, prefetch use, rename refusal), reads.rs (registration), policy/dispatch.rs (layer selector resolution for `style.imp…
Full details: Title check

Explanation

The title names the main change: desktop style.importQgis (QGIS style) file and image reads move to a background thread with Cancel support, tied to issue #2620. The changeset matches this (reads.rs IN_BACKGROUND, qgis.rs read_style_file/style_ahead, cancellation, readjob tests, docs). Minor issue: the title's 'Import QGIS Style' is the UI name of the command, and the PR objectives cite a different PR number (#2676) than the title's (#2620), but the title itself is accurate to the change.

Full details: Description check

Explanation

The description covers the Summary (what changed, why, the Cancel checkpoints, the rename refusal, memory notes and scope limits), Testing (new test, filters, local gate results, untested platforms), UI evidence (states no visible UI change, which matches the template's 'No visible UI change.' line), and Related issue (Closes #2620). The template's 'No visible UI change.' line is kept. The description is detailed and complete, and it follows the template's section headings.

Full details: Linked Issues check

Explanation

Direct issue #2620 asks for a style.importQgis arm in reads::prepare that reads the .qml and raster-marker images on a thread, then hands them to the command, with Cancel. The summary shows IN_BACKGROUND now includes style.importQgis, prepare dispatches it to qgis::style_ahead, and import_style uses the prefetched result. Cancel is checked after the file read, before each image, and after parsing. The style is applied only on landing, as one Undo step. The ui-egui dispatch routes the command through the background read job. Tests cover read-ahead matching inline notes and markers, Cancel at each check, Undo, and rename refusal. The issue's wording "progress like those commands" is met by the shared background-read bar's busy indicator, which the PR says these commands also use. No count-based progress exists. This is a minor gap in the wording, not a missing requirement. project.importQgis is a separate issue (#2476) and is correctly not required here.

Full details: Out of Scope Changes check

Explanation

Changes are: qgis.rs (style read split into read_style_file, Cancel checks, prefetch use, rename refusal), reads.rs (registration), policy/dispatch.rs (layer selector resolution for style.importQgis), lib.rs and readjob.rs (background job dispatch and tests), tests.rs and tests/cancellation.rs (new tests; contents visibility raised to pub(super)), and docs/user-guide/workspace.md (documents the background read). All serve #2620. One behavior change reaches beyond the issue: project.importQgis now checks Cancel after its parse, so a Cancel during image reads adds no layers. This follows from the shared image reader and is disclosed in the PR. The PR also states no test covers that path, which is a test gap and not an out-of-scope change. The project-path change is related but not requested, so a reviewer may want it confirmed. No unrelated change is shown.

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 reads the style file first
Then checks each marker image too
If Cancel comes, the work stops there
The layer waits until reads are through
A landed style can hop back out
And carrots cheer the queue anew

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: 289b6c7b-7349-4f60-930f-dc56ec69c5da
Commits

Reviewing files that changed from the base of the PR and between 8265123 and 0d44e06.

Files selected for processing: 8

  • crates/engine/src/cmd/qgis.rs
  • crates/engine/src/cmd/reads.rs
  • crates/engine/src/policy/dispatch.rs
  • crates/engine/src/tests.rs
  • crates/engine/src/tests/cancellation.rs
  • crates/ui-egui/src/lib.rs
  • crates/ui-egui/src/readjob.rs
  • docs/user-guide/workspace.md

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

}

/// The read `style.importQgis` makes before it runs in the desktop app: on a thread of its own, with
/// Cancel. A request that is wrong gives nothing, or its error: the command says why. It holds a

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 doc overstates what style_ahead does with a wrong request. It returns None for a request with no usable layer, and no read is placed; the command then gives its error when it runs. A read that fails (a missing or unparseable file) is not returned here at all: it is carried inside StyleAhead and given to the command on landing. Suggested wording:

Suggested change
/// Cancel. A request that is wrong gives nothing, or its error: the command says why. It holds a
/// Cancel. A request that is wrong gives nothing: no read is placed, and the command gives its error when it runs. A read that fails lands with its error. It holds a

Category: quality

@github-actions

Copy link
Copy Markdown
Contributor

Code review

No bugs, crash paths, silent data loss or security issues found. I checked the new background read against the existing layer.sizeBy and table.statistics pattern, the dispatch and landing plumbing, the wasm build (reads::prepare is not cfg-gated, so style_ahead is not dead code there), the test fixtures and dev-dependencies, and the picker path (it passes path directly, so nothing reads before the file is chosen). Scripts and models never reach read_ahead, and scoped Assistant/MCP ingress does not admit this command, so those callers still read inline as the PR says.

Prior reviews: none on this PR, so no concerns were left alone.

Bugs

  • None found. Confidence: medium-high. I could not compile or run the tests here.

Security

  • None found.

Performance

  • None found.

Quality

  • crates/engine/src/cmd/qgis.rs:2030: the style_ahead doc says a wrong request gives "nothing, or its error". The function itself only returns None. Read failures are carried in StyleAhead and returned on landing. Inline comment posted with a suggested wording. Confidence: high.
  • The project-import path gains a Cancel look (qgis.rs around line 171) with no test. The PR says so itself. An extra cancel test for project.importQgis would cover it. Confidence: medium. Deferrable as a quality point.

AGENTS.md

  • "Reach every surface": the PR body covers the desktop, browser, CLI, Python, scripts, models, Assistant, MCP and Undo. It does not say whether the phone interface (ui-touch) or plugins are reached, or why not. Confidence: medium. This is a PR-description gap, not a code defect.

Everything else in the AGENTS.md checklist I could verify holds: the reads::IN_BACKGROUND entry, the long_commands entry, tl_raw! for the readjob label, no unwrap in non-test code, and the test cases for both clean and lossy input.

Change size

Compared: the whole PR against main (merge base 4bbe5be to PR head 0d44e06).

Measure Value
Files changed 8 (0 added, 8 modified, 0 removed, 0 renamed)
Size before 4.26 MB
Size after 4.28 MB
Total size change +12.3 KB
Path Before After Change
crates/engine/src/tests.rs 3.36 MB 3.36 MB +5.6 KB
crates/ui-egui/src/readjob.rs 145.3 KB 148.1 KB +2.9 KB
crates/engine/src/cmd/qgis.rs 102.9 KB 105.6 KB +2.7 KB
crates/engine/src/tests/cancellation.rs 37.1 KB 37.8 KB +733 B
crates/ui-egui/src/lib.rs 505.5 KB 505.7 KB +225 B
docs/user-guide/workspace.md 54.1 KB 54.3 KB +201 B
crates/engine/src/cmd/reads.rs 18.7 KB 18.8 KB +159 B
crates/engine/src/policy/dispatch.rs 66.0 KB 66.1 KB +37 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Commit 0d44e06 from a fork built, but isn't published until a maintainer adds the preview label (once per commit).

@giswqs
giswqs added this pull request to the merge queue Nov 22, 2026
Merged via the queue into opengeos:main with commit 2872ad0 Nov 22, 2026
26 checks passed
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.

Import a QGIS style with its reads made on a thread

2 participants