Skip to content

fix(layout): the Layout view no longer waits for legend pictures, and an export's waits are complete and cancellable (#2008) - #2279

Merged
deniial00 merged 2 commits into
opengeos:mainfrom
deniial00:audit-layout-legend-waits
Nov 16, 2026
Merged

deniial00 merged 2 commits into
opengeos:mainfrom
deniial00:audit-layout-legend-waits

Conversation

@deniial00

@deniial00 deniial00 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

The Layout view slept on the interface's thread, up to 30 s, while a WMS or WMTS legend picture was on its way, so the window froze on a slow service. The same wait in an export had no way out: Cancel was not looked at, and a picture still missing when the wait ran out was drawn without, leaving a file that looked complete.

  • The Layout view never waits for legend pictures. It draws what has arrived and says it is waiting (PagePending { frames, legends }); the page is drawn again once its legend pictures have all landed, not on every fetch (the rule fix(layout): the browser's layout page is drawn again once its legend pictures land, not on every fetch #1177 added for the browser, now on the desktop as well).
  • An export waits as before and stops on Cancel. PNG, PDF and SVG exports of a layout, and a raster's PMTiles export, look at Cancel while they wait and return the cancelled error with nothing written.
  • An export that drew a legend whose picture was still on its way is refused, with a message, rather than written incomplete. That includes the browser, which cannot wait. The refusal holds even if the picture lands a moment later, because the file would still lack it. A picture that failed to load, or is too large, is left out as before; the user guide says so.
  • One 30 s budget per page's legend pictures, started by the first picture actually on its way (an SVG's elements and fallback pictures share it), not 30 s per legend. A map series gets one budget per page, not one for the whole series: a later page's pictures are only asked for when it is drawn.
  • A legend wholly off the page is neither waited for nor counted by the redraw. One test (on_page, in millimetres) decides it for the page's drawing and for the redraw, so no resolution makes them disagree.

Kind of change: any maintainer; no new command, parameter, saved field or dependency. docs/user-guide/layouts.md describes the wait and the Cancel behaviour.

Testing

On the head, run through a private build lane of my own (the shared one was held by another bundle's stopped build):

  • cargo xtask test-hygiene ok, cargo fmt --check ok, cargo clippy --workspace --all-targets -- -D warnings ok. cargo test --workspace is not green on my machine: 2 tests fail, and both fail identically on a clean origin/main (d30f427e), with no change of mine involved:

    • rustgis-data source::tests::geopackage_provenance_skips_a_replaced_path (3 of 3 runs on clean main)
    • rustgis-engine tests::session_log_export_inputs_exclude_output_reloads (2 of 2 runs on clean main)

    Both assert i.path == path.display().to_string() in the input fingerprints feat(engine): record the RustGIS version and input file fingerprints in the Session log (#1998) #2253 added to the Session log. I don't know the cause and haven't tried to fix it here. Everything else in cargo test --workspace --no-fail-fast passed, including all 84 of the render crate's layout::tests.

  • cargo xtask layers: ok. project_schema --check: schema matches, 12 fixture projects open. pre-commit run --all-files: all hooks passed. RUSTFLAGS="-D warnings" cargo build --locked --target wasm32-unknown-unknown -p rustgis-web: ok.

  • New tests (render): a page waits for its legends only until its deadline; an export shares one legend deadline across its calls; a legend whose picture is ready does not start the export's legend clock; an SVG export gives up on held legends at one deadline; an export drawn without a legend picture stays refused when the picture lands later; an off-page legend holds no export up; a legend says from the lookup that draws it whether a picture is missing; only an on-page legend is waited for by the redraw; the drawing and the redraw gate agree on a legend at the page's edge; cancelling a pending raster read returns no archive. UI: the desktop page waits for its legend, not for unrelated fetches.

  • Real ui_shot runs of the Layout view with a legend picture held back by a local test server (first paint after the legend was requested): 30.1 s on the base, 0.03 s with this change. See below.

  • CI on this head (9db7345): every check passes, including the full Linux cargo test job and the wasm build, so the two tests above pass on Linux.

Reviewed with review-loop: 5 rounds, 5 findings fixed, 1 declined.

UI evidence

The page after the legend picture has landed, from a real ui_shot of the Layout view (a WMS legend held back by a local server for the "Delayed legend" layer). The screenshots were taken on an earlier commit of this branch; the Layout view's behaviour they show is unchanged since.

Before (first paint after the legend was requested took 30.1 s; after the picture arrived the page never showed it, because the wait had already given up and nothing redrew it):

before-released.png

After (first paint 0.03 s; the page is drawn again once the picture lands, and shows it):

after-released.png

Related issue

Part of #2008 (section 3, its first finding only): claim. Not closing it: the rest of the audit stays open.

Reaches

  • Desktop app: the Layout view no longer blocks; exports wait and cancel (the export dialog's Cancel and the background export path).
  • Browser: the Layout view already redrew when legends landed (fix(layout): the browser's layout page is drawn again once its legend pictures land, not on every fetch #1177); an export now fails with a message when a legend picture is still on its way instead of writing a page without it.
  • CLI, Python, MCP and the Assistant: they call the same layout.export; they get the refusal message, and Cancel where they have it.
  • Ribbon, shortcuts, plugins, phone: no new control or command.
  • The way back: nothing is saved or changed in the project.

… an export's waits are complete and cancellable (opengeos#2008)

Part of opengeos#2008 (section 3, first finding).

The interactive page (render_pending) never waits for WMS/WMTS legend pictures: it reports which frames and legends were drawn without content still on its way (PagePending), and the Layout view redraws once those legend pictures have all landed, on the desktop as well as in the browser, not on every unrelated fetch.

Exports (render, render_drawing, layout_svg, the raster export) still wait: one legend budget per page, 30 s, stopping at once on Cancel with the established cancelled error. An export that drew a legend whose picture was still on its way is refused rather than written without it, even if the picture lands afterwards. A legend wholly off the page is neither waited for nor counted, decided by one test shared by the page's drawing and the redraw gate.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Layout rendering now reports pending frames and legend pictures separately. Interactive layouts redraw when pending legend pictures arrive. Supported export paths use bounded waits for on-page legend pictures, and raster export can stop waiting when cancellation is requested.

Changes: Legend rendering and export

Layer / File(s) Summary
Track pending content during page drawing
crates/render/src/layout.rs, crates/render/src/tiles.rs
render_pending returns separate frame and legend pending flags. Legend lookup tracks missing pictures, and the page-intersection test excludes legends that are off-page.
Apply legend completion checks to exports
crates/render/src/layout.rs, crates/render/src/svg.rs
Export rendering shares a 30-second wait budget for legend pictures. Exports report cancellation or missing on-page pictures; SVG export checks legend completion before the revision check.
Stop raster export waits on cancellation
crates/render/src/raster_export.rs, crates/render/src/tiles.rs
Raster export checks cancellation during tile processing and raster-data waits. Tests hold a fetch to verify that cancellation ends the wait.
Redraw pages when pending content arrives
crates/ui-egui/src/layoutview.rs, docs/user-guide/layouts.md
The Layout view schedules redraws for pending legends on desktop and browser. A desktop test checks redraw behavior, and the guide describes layout waits, export waits, and cancellation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Export
  participant render_page
  participant draw_page
  participant LegendLookup
  Export->>render_page: Start or reuse legend deadline
  render_page->>draw_page: Draw page with export legend checks
  draw_page->>LegendLookup: Read legend rows and picture status
  LegendLookup-->>draw_page: Return rows and missing-picture status
  render_page-->>Export: Return completion or error
Loading

Possibly related PRs

  • opengeos/RustGIS#1177: It changes browser redraw behavior for pending legend pictures, which this PR also revises.
  • opengeos/RustGIS#1535: It adds browser redraw triggers and retains the legend redraw behavior changed by this PR.
  • opengeos/RustGIS#1168: It introduced legend pictures in layouts and the export wait behavior modified here.

Suggested reviewers: elpidioassinaturas, jgregoriorincon, giswqs

Merge Risk: Minimal · up to 9db73

The Layout view now draws without waiting for legend pictures, and exports wait for them with a bounded, cancellable wait. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the Layout view no longer waits for legend pictures, and export waits are complete and cancellable. The changeset matches this (PagePending, render_pending, export can…
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 is thorough and follows the template's spirit. It has a Summary, a Testing section with commands and results, and UI evidence with before and after screenshots, which the template requ…
Full details: Title check

Explanation

The title names the main change: the Layout view no longer waits for legend pictures, and export waits are complete and cancellable. The changeset matches this (PagePending, render_pending, export cancellation in raster_export.rs, layoutview.rs redraw gating, and layouts.md). The title is specific, and the fix(layout) prefix is accurate. The title is 124 characters, which is long, but it is not vague and not off-topic.

Full details: Description check

Explanation

The description is thorough and follows the template's spirit. It has a Summary, a Testing section with commands and results, and UI evidence with before and after screenshots, which the template requires for visible UI changes. The Related issue section is present (Part of #2008). The template's 'No visible UI change' line is not applicable here, and the author supplied screenshots instead, which is correct. All required sections are filled in with substantive content, so the check passes.

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 watches legends bloom,
While frames arrive and shadows loom.
The page redraws when pictures land,
Exports wait with time in hand.
If canceled, the wait is through,
And every tile can rest 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: 67db9e62-8992-4812-a4dd-e2478ab75f84
Commits

Reviewing files that changed from the base of the PR and between 43605eb and 9db7345.

Files selected for processing: 2

  • crates/render/src/layout.rs
  • docs/user-guide/layouts.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.

// for) shows none of its pictures: nothing to wait for or to be missing.
let on_canvas = element.is_some() || on_page(layout, e);
if wait_legends && on_canvas {
wait_for_tile_legends(map, scale, exclude, legend_deadline())?;

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.

Bug (confidence: high on the behaviour, impact depends on timing): legend_deadline() runs for every on-canvas legend, even when none of its pictures is pending. So the export's 30 s clock starts at the first legend drawn, not at the first wait. The comment on legend_deadline says it is "started by the first legend that waits", so this contradicts the intent.

Failure scenario: legend A's picture is ready and starts the clock at t=0. Frame B then spends 30 s or more on its tiles. Legend B's WMS picture is only requested at t=35 s. wait_for_tile_legends checks now < deadline first, so it never requests or waits for B's picture. B is drawn without it and the export is refused, though a fresh 30 s budget would have covered it.

Suggested fix: only start the clock when a picture is actually pending.

Suggested change
wait_for_tile_legends(map, scale, exclude, legend_deadline())?;
if wait_legends && on_canvas && tile_legends_pending(map, scale, exclude) {
wait_for_tile_legends(map, scale, exclude, legend_deadline())?;
}

A regression test should assert that LEGEND_BUDGET stays Some(None) after a legend whose picture is ready has been drawn in an export.

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.

Fixed in 9db7345: the clock now starts only when a picture is actually pending, with a test that a legend whose picture is ready leaves it unstarted and that a later legend still gets the whole wait.

legend(&mut pm, r, map, (title, *columns), drawn, opts, ppp);
// Whether a picture was still on its way when the rows were made: the very lookup
// that drew the legend, not an earlier one a retry or an eviction could outdate.
let missing = legend_missing(&mut pm, r, map, (title, *columns), drawn, opts, ppp) && on_canvas;

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.

Silent omission (confidence: medium; pre-existing, but this PR states the opposite for exports): the refusal relies on legend_missing, which relies on tile_legend. That function (around line 2162, not in this diff) handles State::Failed (a 404 or a network error) and a picture larger than MAX_LEGEND_SIDE with _ => {}, the same as "not yet loaded". Only State::Pending sets missing. So an export whose WMS or WMTS legend fails is written without that picture, with no notice and no refusal.

This contradicts the PR description ("An export that drew a legend without one of its pictures is refused ... rather than written incomplete"). It also breaks the "Never silent" rule in AGENTS.md, which requires a notice wherever data is dropped.

Either refuse the export for a failed or oversized picture, as for a pending one, or report it through ToolResult::messages / Session::notify with a count. If the omission is intended, the PR description and docs/user-guide/layouts.md should say that a failed picture is dropped silently.

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.

Right that a failed or oversized picture is left out of an export without a notice, but that is the existing behaviour of tile_legend (#1168) and a different finding from the waits this PR fixes: it needs its own notice path, so it is out of scope here and a follow-up candidate. The user guide already says such a picture is left out; 9db7345 corrects this PR's wording (docs, comment and description) to say that only a picture still on its way stops an export. (reviewed at 43605eb)

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • Export's 30 s legend clock starts too early (crates/render/src/layout.rs:482, confidence high on the behaviour, impact depends on timing). legend_deadline() runs for every on-canvas legend, even when no picture is pending. A legend drawn early can start the clock, so a later legend whose picture is requested after 30 s is never waited for and the export is refused. The fix is to call legend_deadline() only when tile_legends_pending is true. The comment on legend_deadline says the clock starts with "the first legend that waits", so the code does not match its own intent.
  • Failed or oversized legend pictures are dropped silently in exports (crates/render/src/layout.rs:487, tile_legend near line 2162, not in the diff; confidence medium, pre-existing). tile_legend treats State::Failed and pictures over MAX_LEGEND_SIDE the same as "not loaded", so only Pending sets missing. An export with a failing legend server is written without the picture and with no notice. The PR description says such exports are refused, so the description is wrong, and the "Never silent" rule is broken.

Security

  • None found in the changed lines.

Performance

  • Nothing significant. The export wait polls every 15 ms, as before. The interactive redraw check runs at most every 250 ms while a legend is pending.

Quality

  • The new tests do not cover when the deadline starts. A regression test for the first bug should assert that LEGEND_BUDGET stays Some(None) after a legend whose picture is ready is drawn during an export.

AGENTS.md

  • Silent omission, covered under Bugs above (Never silent).
  • Checked and fine: no unwrap or expect in non-test code, cancellation checks are in the new loops, the wasm cfg gates look right, and legend is only used under #[cfg(test)].

Already raised: none. There were no earlier review threads on this PR.

Confidence: both findings were verified by reading the code. I did not run the tests or the wasm build, since I have no shell here.

Change size

Compared: the whole PR against main (merge base d30f427 to PR head 43605eb). No trees were truncated.

Measure Value
Files changed 6 (added 0, modified 6, removed 0, renamed 0)
Size before 666.8 KB
Size after 693.2 KB
Total size change +26.4 KB
Path Before After Change
crates/render/src/layout.rs 309.9 KB 329.4 KB +19.5 KB
crates/ui-egui/src/layoutview.rs 192.1 KB 195.0 KB +2.8 KB
crates/render/src/raster_export.rs 14.6 KB 17.4 KB +2.8 KB
crates/render/src/tiles.rs 74.9 KB 75.6 KB +701 B
docs/user-guide/layouts.md 47.4 KB 48.0 KB +559 B
crates/render/src/svg.rs 27.7 KB 27.8 KB +88 B

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2279/
Web app https://preview.rustgis.app/pr-2279/app/
Commit 9db7345

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).

…its way, and the docs say only that stops an export (opengeos#2008)

An export's 30 s legend budget started at the first on-canvas legend drawn, even one whose picture was ready, so a later legend whose picture was first asked for after 30 s was never waited for and the export was refused. The wait, and so the clock, now starts only when a picture is pending.

The docs and the finish_legends comment say that a legend picture still on its way stops an export; a picture that failed or is too large is left out, as the docs already said.
@github-actions

Copy link
Copy Markdown
Contributor

Code review

I reviewed the full diff against the base-branch AGENTS.md, both prior threads, and the code they touch. I did not run tests, clippy, or the wasm build, since I had no execution tool. CI and the author's test runs are the check for those.

Bugs: No new defects found at medium or higher confidence.

  • The earlier clock-start bug (legend deadline started by a ready legend) is fixed in 9db7345. I confirmed the new order at crates/render/src/layout.rs:483: tile_legends_pending is checked before legend_deadline().
  • Cancel works on every new wait. The legend wait polls Cancel every 15 ms. The raster loop's wait_for_news_unless polls its stop closure at the same rate, so a Cancel press is not held for the full timeout.
  • The per-page budget holds: render_drawing is called once per page in series exports (crates/engine/src/cmd/layout.rs:4985), so each page gets its own budget, as the docs say.
  • Low (about 30%), a note only: browser exports of a layout with a WMS or WMTS legend still loading now fail instead of writing an incomplete file. The docs say so, so I'm not raising it as a defect.

Security: None found. No new input paths. Legend addresses still go through address::check.

Performance: Low. wait_for_tile_legends re-runs tile_legends_pending on every 15 ms tick, as it did before. The PR doesn't change that cost.

Quality (nits, for the release quality pass, not posted inline):

  • legend at crates/render/src/layout.rs:~2368 is a #[cfg(test)] wrapper around legend_missing. The tests could call legend_missing directly.
  • draw_page takes a (pending, wait_legends) tuple. A small struct or a named field would read more clearly.
  • The LEGEND_BUDGET doc says it is open "while an export draws", but render_page opens it on the interactive path too. It is harmless, since wait_legends is false there, but the comment is wrong.
  • legend_deadline() computes fresh even when a deadline already exists.

AGENTS.md:

  • Already raised, not re-posted: failed or oversized legend pictures are still dropped from exports with no notice. The author declined this as a follow-up. AGENTS.md says "Existing silent losses are bugs" and "Never silent", so that deferral conflicts with the repo's rules. The maintainer should decide whether it belongs in this PR.
  • The PR meets the other rules I checked: no new command or saved field, so no schema or test-list update; web_time and cfg gating for wasm; the docs and the "Reach every surface" section are consistent with the code.

Earlier concerns left alone: 2. One (clock start) is fixed in 9db7345 and verified above. The other (silent omission) is covered in AGENTS.md above.

Change size

Compared: the whole PR against main (merge base d30f427 to PR head 9db7345).

Measure Value
Files changed 6 (0 added, 6 modified, 0 removed, 0 renamed)
Size before 666.8 KB
Size after 694.6 KB
Total size change +27.8 KB
Path Before After Change
crates/render/src/layout.rs 309.9 KB 330.8 KB +20.9 KB
crates/ui-egui/src/layoutview.rs 192.1 KB 195.0 KB +2.8 KB
crates/render/src/raster_export.rs 14.6 KB 17.4 KB +2.8 KB
crates/render/src/tiles.rs 74.9 KB 75.6 KB +701 B
docs/user-guide/layouts.md 47.4 KB 48.0 KB +566 B
crates/render/src/svg.rs 27.7 KB 27.8 KB +88 B

@deniial00
deniial00 merged commit e4252df into opengeos:main Nov 16, 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.

1 participant