Skip to content

fix(engine): a full link chart skips what it can't draw, and a self-link is one end (#1947) - #2223

Merged
giswqs merged 2 commits into
opengeos:mainfrom
bearinmindcat:fix/1947-link-chart-full
Nov 16, 2026
Merged

giswqs merged 2 commits into
opengeos:mainfrom
bearinmindcat:fix/1947-link-chart-full

Conversation

@bearinmindcat

@bearinmindcat bearinmindcat commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2146 (#1947). Its review came in after it was merged; this does what it found.

Since this was opened, #2201 on main has made two of the three changes below: the self-link count, and skipping a feature the chart has no room for. With main merged in (69e03c4), this PR still changes only the third: once a destination has no room, a feature already in the chart goes straight to the destinations it can still link to.

  • A feature related to itself was counted as two new ends (now on main too, from fix(engine): address release sweep correctness findings #2201). When a relationship joins a layer to itself on the same key, a feature can be its own destination. With the feature not yet in the chart, share.linkChart counted its link as needing room for two, the origin and the destination, though they are one feature. At 2,999 features that link was left out with one place free. It now counts once. The notice already counted the link, so nothing was hidden, but the chart was one link short.

  • A full chart still went through every destination of every feature. A feature the chart had no room for tried each of its destinations and drew none, and the 20,000-link limit never stopped it, since no links were added. After 1,500 pairs fill the chart, a relationship of 10,000 features sharing one key with 10,000 others made 100 million tries. Now:

    • a feature the chart has no room for is skipped whole, since none of its links can be drawn (now on main too, from fix(engine): address release sweep correctness findings #2201);
    • once a destination has no room, a feature already in the chart goes straight to the next destination the chart holds (or to itself), the only ones it can still link to. Those destinations are found once per key and chart size, not once per feature. (This is what this PR still adds.)

    This doesn't change what's drawn or what the notice says; it only stops the tries that can't draw anything.

Testing

  • Engine a_link_chart_says_what_its_limits_leave_out adds a Self case on its own session. First and Fill, as in the First, Fill and Last case, bring the chart to 2,999 features; then comes a relationship of a layer to itself on one key. The page draws that feature's link to itself: 1,501 links and 3,000 features.

    Reproduced first, with sharing.rs as on main at 803a014, before fix(engine): address release sweep correctness findings #2201: the feature's link to itself was left out, with one place free.

    thread 'tests::a_link_chart_says_what_its_limits_leave_out' panicked at crates/engine/src/tests.rs:12648:5:
    assertion `left == right` failed
      left: (1500, 2999)
     right: (1501, 3000)
    

    Since fix(engine): address release sweep correctness findings #2201 it passes on main too, so it stays only as a check of that case.

  • The full chart, timed with a test not committed (1,500 pairs, then 10,000 features each related to the same 10,000): share.linkChart took 5,980 ms with only the self-link fix and 16 ms with this PR (the workspace's test profile, optimised with debug info). That case is now fast on main as well, through fix(engine): address release sweep correctness findings #2201's skip of a feature with no room. The case only this PR speeds up is features already in the chart that relate to many with no room; I'm timing it against main and will add the numbers here.

  • On Windows 11 x64, based on main 803a014: cargo fmt --all --check, the engine's 23 tests matching a_link_chart_says, share or link, cargo clippy -p rustgis-engine --all-targets -- -D warnings and, with CI's toolchain, cargo +1.100.0 clippy -p rustgis-engine --all-targets -- -D warnings -A clippy::needless_bool pass (the -A is Windows-only, for main's cfg(unix) block in source/shp/cache.rs). CI passes on the merge of main (69e03c4).

  • Not run: the whole of cargo xtask ci (the engine's other tests and hostile_params_never_panic among them), the browser build, and Linux or macOS.

UI evidence

No visible change in the app. On main a full chart is already made without the wait in the timed case above. With this PR it is also made without the wait when features already in the chart relate to many that have no room.

Related issue

Follows #2146, for #1947.

Summary by CodeRabbit

  • Bug Fixes
    • Link charts now handle crowded charts more reliably, including self-relations and destinations already represented in the chart.
    • Charts continue to respect per-feature and overall link limits.
    • Large charts now retain links across many feature relationships while keeping the displayed feature count consistent.

…ink is one end (opengeos#1947)

From opengeos#2146's review, after it was merged:

- A feature related to itself was counted as two new ends. With the
  chart at 2,999 and the feature not in it yet, its link to itself was
  left out although it needs only one place. It's now counted once.
- A full chart still went through every destination of every feature:
  one with no room left tried each and drew none. With 1,500 pairs
  filling the chart, a later relationship of 10,000 features sharing one
  key with 10,000 others made 100 million tries. A feature the chart
  has no room for is now skipped whole, and one already in it goes
  straight to the destinations the chart holds (or to itself), which
  are the only ones it can still link to.

What's drawn and what the notice says are unchanged by the second; the
first draws the one link it left out.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The link-chart builder now caches destinations already represented in the chart and uses the cache when node limits prevent adding a destination. A test checks link and feature counts for a large set of pairs and a self-relation.

Changes: Link-chart destination selection

Layer / File(s) Summary
Destination tracking and selection
crates/engine/src/cmd/sharing.rs, crates/engine/src/tests.rs
The builder caches positions of destinations already in the chart. When a destination cannot fit, it selects a later cached destination or an eligible later row for the same feature. The test checks link and feature counts for 1,499 additional pairs and a self-relation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: giswqs, elpidioassinaturas

Merge Risk: Minimal · up to 69e03

The change makes full link charts skip destinations that cannot be drawn and counts a self-link as one feature slot. No concrete merge-blocking risk was found in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two changes in the PR: a full link chart skips links it cannot draw, and a self-link counts as one end. Both match the raw summary and the objectives. The title is specific, but it…
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. It explains the two changes (self-link counted once, and skipping of features and destinations that ca…
Full details: Title check

Explanation

The title names the two changes in the PR: a full link chart skips links it cannot draw, and a self-link counts as one end. Both match the raw summary and the objectives. The title is specific, but it is long at 91 characters and uses a conventional-commit prefix with an issue number.

Full details: Description check

Explanation

The description follows the template's Summary, Testing, UI evidence, and Related issue sections. It explains the two changes (self-link counted once, and skipping of features and destinations that cannot fit) and states that the self-link change is already on main via #2201, so this PR adds only the destination-skipping change. Testing lists the reproduced failure, a timing test that was not committed, Windows checks, and the checks not run. The UI evidence section says no visible change, which matches the template's no-UI-change line. The Related issue section cites #2146 and #1947. The main gap is that the timing for the one case this PR speeds up is not yet filled in, and the author says they will add it.

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 chart by moonlit light
Destinations wait in rows, tucked out of sight
When space runs short, the cached paths appear
Links find their place, and counts stay clear
A self-link joins the quiet evening cheer

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: d7da9090-1566-4693-b57a-10c0e04fa904
Commits

Reviewing files that changed from the base of the PR and between 2ec51cb and 69e03c4.

Files selected for processing: 2

  • crates/engine/src/cmd/sharing.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; 7 remain after this review.

// Where a key's destinations already in the chart sit among its destinations, found when
// the chart has no room for another one and kept while it stays that size: a full chart
// then looks at these only, not at every destination of every feature.
let mut in_chart: HashMap<String, (usize, Vec<usize>)> = HashMap::new();

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.

Grouped minor nits on the new full-chart path (no change needed for correctness; I traced the skip, jump and self-link branches and they hold):

  • The (usize::MAX, Vec::new()) sentinel in in_chart could be an Option<(usize, Vec<usize>)> or a small struct, so the cache's "not yet computed" state is explicit rather than relying on no chart ever reaching usize::MAX nodes.
  • rows.partition_point and drows.binary_search both rely on drows being sorted ascending. That holds because by_key is filled by iterating rows in order, but nothing says so. A one-line comment at the by_key push would keep it true under later edits.
  • drows[i] (line ~1415) and drows[j] (line ~1425) index rather than use get(). Both are guarded by the loop and range, so this is style, not a crash path, and it can wait for the release quality pass.
  • Coverage gap: no committed test reaches next_self, i.e. a new origin at MAX_NODES - 1 whose earlier destinations don't fit and whose own row comes later in drows. The Last case covers the held-destination jump, and the Self case covers a self-link that fits directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for tracing the branches. All four points are left for the release quality pass:

  • The usize::MAX sentinel: the chart is capped at 3,000 nodes, so it can't be confused with a real count. An Option or a struct would make that explicit, but nothing behaves differently.
  • drows sorted: this holds because by_key is filled in row order. A comment there would only document it.
  • Indexing rather than get(): both indexes are bounded by the loop and the range, as you say.
  • A test reaching next_self: I traced it the same way. With a new origin at 2,999 nodes, earlier new destinations need two places and are skipped. The jump lands on the feature's own row, which needs one, and the link is drawn. Once that origin is in the chart, next_self is None and the held-row list is rebuilt for 3,000. An extra test for code that works can wait for the pass.

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.

Claude autofix (declined): Left for the release quality pass. The comment says no change is needed for correctness, and the points are style or extra coverage: the sentinel's form, a comment on the sorted drows invariant, indexing vs get(), and a test for next_self. The drows ordering does hold, since by_key is filled in row order.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • None found. I traced the three new paths in link_chart (crates/engine/src/cmd/sharing.rs:1404-1447) and they hold:
    • The early skip of an origin with no room is equivalent to the old behaviour, where every destination failed the same check.
    • When the chart has room for an origin but no destination, the jump lands only on destinations that fit (held destinations, or self when the origin is new).
    • The self-link count is right: dest_new is false when the origin is new and the destination is the same feature, so one slot is needed. The Self case in the test exercises this. Confidence: high.
  • Complexity is bounded. Each jump is followed by a draw or a break, so the full-chart case no longer makes the 100M tries described in the PR. Confidence: high.

Security

  • None. No new input parsing, and the new code uses no unwrap, expect or unsafe.

Performance

  • The fix is effective: the PR's own measurement drops from 5,980 ms to 16 ms. No committed test guards this, so a regression would go unnoticed. Confidence: medium.
  • Pre-existing, outside this diff: share.linkChart is not in exports::IN_BACKGROUND, so it still runs on the UI thread even though its work grows with features. AGENTS.md's "Never hold the window" rule applies. Confidence: medium.

Quality (grouped inline comment posted at sharing.rs:1386)

  • The usize::MAX sentinel in in_chart could be an Option.
  • partition_point and binary_search rely on drows being sorted, which is not documented.
  • drows[i] and drows[j] index rather than get(). The indexes are guarded, so this is style only.
  • No committed test reaches the next_self branch.

AGENTS.md

  • The PR body does not say which surfaces it reaches (CLI, Python, Assistant/MCP, undo). The "Reach every surface" section asks for that. Confidence: medium.
  • Nothing else found against the rules. The notice wording is unchanged, the new test covers the self-link with a separate session, and the test list needs no update.

Prior reviews: no existing threads, so nothing was left alone.

Note on testing: the PR says the engine tests were run only on Windows, and Linux was not run. CI should cover this.

Change size

Compared: the whole PR against main (merge base 803a014 to PR head 2ec51cb).

Measure Value
Files changed 2 (0 added, 2 modified, 0 removed, 0 renamed)
Size before 2.96 MB
Size after 2.96 MB
Total size change +2.9 KB
Path Before After Change
crates/engine/src/tests.rs 2.87 MB 2.87 MB +1.1 KB
crates/engine/src/cmd/sharing.rs 88.2 KB 89.9 KB +1.8 KB

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2223/
Web app https://preview.rustgis.app/pr-2223/app/
Commit 69e03c4

GitHub Pages takes a minute or two to publish a new commit.

@giswqs giswqs added the claude-autofix Apply to have Claude merge the base, resolve conflicts and fix review comments (re-add to run again) label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Claude autofix

  • Merged main and resolved conflicts in 1 file(s).
  • Review threads: 1 declined.
  • No fix commit was pushed.

@github-actions github-actions Bot removed the claude-autofix Apply to have Claude merge the base, resolve conflicts and fix review comments (re-add to run again) label Nov 16, 2026
let drow = drows[i];
// A feature related to itself is one end, not two.
let origin_new = a.is_none();
let dest_new = !index.contains_key(&(dm, d.id, drow)) && !(origin_new && (om, o.id, orow) == (dm, d.id, drow));

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.

Possible bug in the PR description: the self-link "fix" doesn't change behaviour. On main the count was usize::from(a.is_none()) + usize::from(destination != origin && !index.contains_key(&destination)). For a self-related feature, destination == origin, so the destination term was already 0 and the feature counted as one end. The new dest_new is logically identical in every case: when origin == destination, a is None exactly when the origin is not in index, so the new expression is also false. I could not find a case where main counts a self-link as two.

That means the new Self case in a_link_chart_says_what_its_limits_leave_out should pass on main too, which conflicts with the "Reproduced first … left: (1500, 2999)" output in the PR description. Could you run that test against main and confirm it fails there? If it passes, the self-link part is not a fix. The description and test should then say so, or a different reproduction should be found. Confidence: about 80%, from reading the diff; I have not run it.

The full-chart skip/jump logic (the in_chart cache and next_self) does look equivalent to the old behaviour to me, with no change in what's drawn.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes: against today's main it isn't a fix. #2201 started counting a feature related to itself as one end (the destination != origin you quote) after this PR was opened. The (1500, 2999) in the description came from this branch's first base, 803a014, which is before #2201. With main merged in, dest_new gives the same result as main's line and the Self block passes on main too. It stays only as a check of that case at 2,999 features.

#2201 also skips a feature the chart has no room for, which was the other half of this PR. The one part main doesn't have is this: once a destination has no room, a feature already in the chart goes straight to the next destination the chart holds (or to itself), not through each one in turn. I've corrected the description to say so. I'm also timing that case against main and will add the numbers there.

}
u.run("share.linkChart", &json!({})).unwrap();
// First draws 1 link (2 features), Fill 1,499 (2,997), and Self its feature's link to itself (1 more).
assert_eq!((drawn("Relationships").0, drawn("Relationships").1), (1501, 3000));

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 both sides of a limit to be tested: lossy input gives the notice, clean input gives none. This new block checks the drawn counts only, not the notice. At 1,501 links and 3,000 features, left should be None, so please assert that share.linkChart's notice for this session is empty (the notice_mark / said pattern used earlier in this test works here). Confidence: high that the assertion is missing; the rule applies because this is a clean case.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • Self-link "fix" appears to be a no-op, so the PR's stated reproduction doesn't match the code. On main, a self-related feature already counted as one end, because destination != origin was false. The new dest_new expression is logically identical. The Self case in a_link_chart_says_what_its_limits_leave_out should therefore pass on main too, which contradicts the "Reproduced first" output in the description. Confidence: ~80% (from reading the diff, not run). Posted inline at crates/engine/src/cmd/sharing.rs:1428.
  • The full-chart skip/jump logic looks correct. I traced the in_chart cache (recomputed only when nodes.len() changes), the next_held/next_self jump (always moves i forward, so no infinite loop), and the origin-new versus origin-in-chart cases. Output matches the old behaviour, and the notice is unchanged. Confidence: ~85%.

Security

  • None found. The change is internal index arithmetic with no new input parsing.

Performance

  • The per-key in_chart cache bounds the full-chart cost. It is rebuilt only when the chart size changes, which can happen only near 3,000 nodes, so the rebuild cost is bounded. Confidence: ~85%. No new finding.
  • Minor: key.clone() now runs per origin and per skip. This is a trivial allocation cost, not worth raising.

Quality

  • The dest_new expression could be the simpler original form, (om, o.id, orow) != (dm, d.id, drow) && !index.contains_key(...). This is a readability point, so it is left for the release quality pass.
  • Prior-thread points on the usize::MAX sentinel, the sorted-drows comment, indexing versus get(), and the untested next_self branch are already raised and answered by the author. I left them alone (4 points in 1 thread).

AGENTS.md

  • Test both ways. The new self test at crates/engine/src/tests.rs:12842 asserts drawn counts but not the absence of a notice for this clean case. Posted inline. Confidence: high.
  • The other AGENTS rules are satisfied: no unwrap in non-test code, no unsafe, the notice text is unchanged, nothing is saved, and no wasm or layering impact.
  • Not raised as a finding: share.linkChart runs synchronously in link_chart_item, not through a background path. This is pre-existing and not changed by this PR.

I did not run the tests. My conclusions come from reading the diff and the surrounding code.

Change size

Compared: the whole PR against main (merge base 230cd1e to PR head 69e03c4).

Measure Value
Files changed 2 (0 added, 2 modified, 0 removed, 0 renamed)
Size before 3.02 MB
Size after 3.04 MB
Total size change +2.7 KB
Path Before After Change
crates/engine/src/tests.rs 2.94 MB 2.94 MB +1.2 KB
crates/engine/src/cmd/sharing.rs 88.8 KB 90.4 KB +1.6 KB

@giswqs
giswqs merged commit d1e32c2 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.

2 participants