Skip to content

A store-owned canvas redrawn from the store stacks items in their saved order - #1029

Open
SunkenInTime wants to merge 1 commit into
mainfrom
t3/store-retake-order
Open

SunkenInTime wants to merge 1 commit into
mainfrom
t3/store-retake-order

Conversation

@SunkenInTime

@SunkenInTime SunkenInTime commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

On a store-owned strategy, the canvas drew overlapping items in the order the store lists its rows, not in their saved stacking order (sortIndex). If you dragged an item that sat under another, it came to the top for a moment. Then the redraw from the store put it back underneath. The store and server kept the right order. Only the drawing was wrong, and it was wrong every time the page was drawn from the store: after a save, after a teammate's change, or when the strategy was reopened.

#1014 is where this turned into a wrong save. After a doubted save and a reopen, the redraw sometimes ran before the canvas's next commit. In that case the commit saw the misdrawn order as a restack and sent it (ElementPatchOp x, sortIndex 3). The extra await in the issue only decides which of the two ran first. _retakeBase is unchanged.

Cause

storePageOf (lib/collab/store_editor_snapshot.dart) passes content.elements and content.lineupGroups on in the store's row order. The canvas draws page items in that list's order. The Convex path sorts the same lists by sortIndex in RemotePageSnapshot.groupElementsByPage.

Fix

storePageOf sorts elements and lineups with sortBySortIndex, the same stable sort the Convex path uses, so ties keep the store's row order. Nothing downstream matches items between two snapshots by index:

  • normalizedRemoteEntities, drawnLivesOf and store_page_commit key items by publicId.
  • The hydration key sorts its own copy.
  • The driver's liveHandOffCost takes elements.first of one snapshot to stand in for "one row changed". It asserts one row decoded, and its figure is the whole page's conversion, so which item it picks doesn't change what it measures.

Tests (test/library_store/store_canvas_commit_test.dart)

  • New, redraw only, no doubt and no injected await: "an item brought to the top over one with a later id is drawn on top after the store redraws the canvas". On main it fails at the first look after the save:
    Expected: ['x', 'a1'] Actual: ['a1', 'x']
  • The issue's doubt-and-reopen test now also asserts that the canvas is [x, a1] and that the store's sortIndex order equals the canvas order. On main, default timing:
    Expected: ['x', 'a1'] Actual: ['a1', 'x']
    On main with the issue's extra await, it fails as the issue reported: Expected: {'x': 1, 'a1': 2, 'p1': 2} Actual: {'x': 2, 'a1': 2, 'p1': 2}. With this change it passes in both timings.
  • Lineups: "a lineup a teammate brought to the top while the store was closed is drawn on top once it reopens". A lineup group's sortIndex only changes when someone else writes it, so the test does that through a reopen. The harness's live page answer carries no lineups, so a teammate push in this harness can't show it. On main:
    Expected: ['bk', 'zk'] Actual: ['zk', 'bk']

The queue model and the store model don't read sortIndex through this path. Neither goes through storePageOf, the store draw source, mergeRemote or _retakeBase, so no sweep is needed.

Why the driver didn't catch it

expectCanvasIsTheStores compared agents as an id → position map, so order was never checked. It now also requires the canvas's agent order to equal the store's sortIndex order. With only that check added to main (881b72c), cloud-store-own-open, the cloud-store-own-teammate pair and cloud-store-own-pages (run through linux-cut-network.sh) all stay CLEAN, because none of them restacks. The new cloud-store-own-stacking.json fails:
the canvas stacks the agents [a1-…, a2-…], the store stacks them [a2-…, a1-…]

In the running app

Driver runs on storeruns (Linux, --library-store store --cloud-store own) of cloud-store-own-stacking.json: two overlapping agents; Jett, the lower one, is dragged to the top, then the strategy is left and opened again. This PR's run is CLEAN. Main's run is CLEAN too, because main still has the weaker check, but its shots show the wrong order:

main vs this PR

On main, Sova is drawn over Jett right after the drag and again after reopening. With this PR, Jett stays on top.

ci: analyze test web desktop

Fixes #1014

Confidence Score: 5/5 · This PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge; no actionable issues were found.

Summary

storePageOf now sorts elements and lineups by sortIndex before the canvas draws them.

  • Store redraws keep page items in their saved stacking order.
  • The store-canvas driver checks that agents stack in saved order.

Reviews (1) · Last reviewed commit: "A store-owned canvas redrawn from the st..." · Reviewed by Greptile

…ed order

The store lists a page's rows in the order it holds them, and the canvas drew
them in that order, so an item brought to the top went back under items with
later rows on the next redraw. Elements and lineup groups are now sorted by
sortIndex when the store's page is turned into a snapshot, as the Convex path
already does.

The driver's expectCanvasIsTheStores also checks the canvas's stacking order
against the store's, and cloud-store-own-stacking.json drags the lower of two
overlapping agents to the top and reopens the strategy.
@coderabbitai

coderabbitai Bot commented Nov 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e41c3196-0a8d-45a3-a911-4db182d5302f
Commits

Reviewing files that changed from the base of the PR and between 881b72c and 7b06eb4.

Files selected for processing: 5

  • lib/collab/store_editor_snapshot.dart
  • lib/dev/drive/drive_cloud_store.dart
  • test/library_store/store_canvas_commit_test.dart
  • tool/drive/README.md
  • tool/drive/scripts/cloud-store-own-stacking.json
  • 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

This branch has not been deployed

No deployments
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.

Store editor: after a doubted save, whether the canvas's item order is sent depends on timing

1 participant