Skip to content

[feat] canvas: show project structure first and load node media by priority - #485

Merged
kunkunblueberry merged 2 commits into
ThinkFlowLab:mainfrom
Redivesue:feat/446-stage-2-node-media
Nov 24, 2026
Merged

kunkunblueberry merged 2 commits into
ThinkFlowLab:mainfrom
Redivesue:feat/446-stage-2-node-media

Conversation

@Redivesue

@Redivesue Redivesue commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Progressive canvas loading for #446, in two commits that can be reviewed one at a time. It replaces #484, which carried only the first commit. Opening or switching a canvas no longer waits for every node's media.

[feat] canvas: show project structure before node media

  • The workspace becomes interactive from the opened project snapshot. Media then fills in per node, with loading, failed and retry states.
  • Node media fields keep a stable asset source (opendirector-asset://<projectId>/<assetId>). Object URLs are resolved only where media is displayed or read, so they stay out of the document, undo history and save baseline.
  • open-canvas returns text bodies, so hidden text, copy and export do not depend on a later read.
  • reference-catalog checks files against its one snapshot instead of replaying history for each asset.

[feat] canvas: load node media independently by priority

  • Media reads share one bounded priority queue with 3 concurrent reads. Explicit actions run ahead of display reads.
  • On-screen nodes start reading when they reach the viewport, through one shared IntersectionObserver. There is no off-screen preload.
  • A display read is cancelled once no on-screen consumer needs it. Actions are never cancelled by a display consumer leaving.
  • Repeated media reads reuse the validated project head instead of replaying history under the catalog lock for each asset.

Media reads and the cached project head

main already serves the cached head on hot read paths: snapshot() returns _current_record(...)[0] without checking validated, and open() and caught-up change polling use it too, to avoid replaying the chain under the catalog lock. This PR extends it to open_media with a stricter rule. The cached head is used only after its chain has been validated; otherwise the read still runs the full _load, so a damaged ancestor is still rejected. The served bytes are still checked against the asset's fingerprint and size, so a rewritten media file is rejected as before.

What changes: an ancestor commit rewritten on disk while the server runs is no longer caught by a media read until the server restarts. Saves and history reads still replay and validate the chain. The storage owner should confirm this trade-off for the media read path.

Linked issue

Labels

  • Labels applied by the repository's labeling workflow: type:feat, area:canvas, area:performance.

Test plan

Local, on this branch (both commits, rebased onto aff774a8):

  • tsc --noEmit, check:i18n, check:browser-locale, check:browser-manifest, generate_contracts.py --check and pre-commit run --from-ref main pass.
  • Frontend: 978 passed. Python (-m cpu): 2922 passed, 118 skipped (Windows-only).
  • Browser gate (scripts/run-browser-suite.mjs, Vite dev server and isolated API as in CI): 30 of 30, including canvas_progressive_load in both languages. capability discovery is flaky on main too: run alone, it failed 1 of 3 times on 3c151e15, waiting for "Service paused".
  • Packaged desktop app (Electron 45, ad-hoc signed), rebuilt from this branch:
    • apps/desktop/scripts/smoke.mjs passes: first run, canvas, media drag-and-drop, authenticated API, isolation, both locales, hidden-window Host, reopen and sidebar preferences. The earlier A dialog obscures the canvas failure, which 52102ed0 also had, no longer occurs on this base.
    • On an isolated copy of the benchmark data: image preview, video playback, audio, original download, image editor, timeline editor and same-asset paste pass.

Not run:

  • Desktop archive export and MP4 export were not exercised in the packaged app. The browser gate's timeline_workflow exports and checks a real MP4.

Left to CI: the repository's pull request checks.

Evidence that it works

  • Media attached.

Recording, browser runtime on a warm server, the same fixtures: left main (8258d4b0), right this branch (stage 1 and 2). The overlay, injected by the recording script, shows the time since the project click and when the canvas became usable: 9.26 s on main, 0.27 s here, with media filling in afterwards.

pr485-switch-main-vs-this-branch.mp4

Node states in English and Chinese: one media read held open, one failing with Retry, one loaded, and a text node that arrived with the canvas.

pr485-node-states-en-US pr485-node-states-zh-CN

Six-direction switch benchmark on three heavy fixtures: A image-heavy (180 nodes, 0.67 GiB), B video-heavy (89 nodes, 2.05 GiB), C mixed with editors (116 nodes, 0.97 GiB). Apple M2, 16 GiB, macOS 26.5; Chrome 158 headless against the source server, and the packaged Electron 45 app. Per direction: 4 warm-up switches excluded, then 10 measured switches; median / P90 in ms, nearest-rank. "Usable" means the target title is shown, the workspace is not busy or inert, and every visible node is mounted. "Content" means every in-viewport image is decoded, video has readyState >= 2, audio >= 1, and text is rendered. The driver uses CDP without the Network domain.

Measured on 52102ed0 (base), the stage 1 commit (9b50c442) and the stage 2 commit (417582ca), before rebasing onto aff774a8. The upstream commits added since then (lease renewal, upload through request(), a mask-composite edge, agent job-state queries, macOS DMG guidance) do not touch canvas open or media reads.

Browser Usable, base Usable, stage 1 Usable, stage 2 Content, base Content, stage 1 Content, stage 2
A→B 18652 / 21725 238 / 295 246 / 256 18764 / 21841 5976 / 8143 5272 / 5989
B→A 9714 / 12286 298 / 336 292 / 308 11264 / 15870 6770 / 7160 4918 / 5351
C→B 19870 / 21496 249 / 265 236 / 254 20002 / 21620 10826 / 13078 6733 / 11040
B→C 8915 / 9912 306 / 365 277 / 297 9510 / 10375 5920 / 6713 3448 / 4974
A→C 7658 / 7839 285 / 1898 300 / 365 7979 / 8193 2878 / 4657 4330 / 5823
C→A 5034 / 5420 312 / 411 304 / 373 6342 / 6697 7554 / 8111 6384 / 7524
Desktop Usable, base Usable, stage 1 Usable, stage 2 Content, base Content, stage 1 Content, stage 2
A→B 5866 / 8623 266 / 277 282 / 304 6065 / 8805 2904 / 3138 4713 / 4975
B→A 8140 / 9365 376 / 498 386 / 508 9995 / 10909 8052 / 8308 7104 / 7257
C→B 3404 / 4507 239 / 257 ¹ 214 / 243 3566 / 4743 3024 / 5308 ¹ 3726 / 4539
B→C 3459 / 3688 256 / 261 ¹ 282 / 286 3863 / 4176 3510 / 3543 ¹ 2908 / 3039
A→C 5369 / 7974 622 / 1792 294 / 298 5790 / 8390 3280 / 4355 3033 / 3258
C→A 7863 / 8674 300 / 436 296 / 389 9324 / 10129 6565 / 7838 7018 / 7191

¹ The stage 1 desktop C↔B run stopped at switch 9 of 24 on a storage_busy lock timeout, so these rows have 3 and 2 samples. Stage 2 completed 24 of 24 in every run.

With stage 2, usable median is within 500 ms and usable P90 within 1000 ms in every direction (worst P90: 508 ms, desktop B→A). Click feedback P90 is at most 32 ms. Stage 2 logged no failed requests in any run; base logged 409s on assistant/draft and timed-out tool-tasks reads in every run.

Stage 2 is not uniformly faster than stage 1 to full content. Content median improves in 5 of 6 browser directions and 3 of 6 desktop directions. It regresses most on desktop A→B (2904 → 4713 ms), where B's large in-view videos now share 3 read slots, and on browser A→C (2878 → 4330 ms). This benchmark uses the fit-all view, which puts every node in the viewport, so it does not exercise viewport gating.

Cold open after a server restart, usable median, stage 1 → stage 2: browser A 2066 → 1812, B 1269 → 1363, C 1481 → 1753 ms; desktop A 1418 → 1384, B 719 → 701, C 878 → 900 ms (base: browser 15339 / 7289 / 4033, desktop 8250 / 3630 / 3487 ms).

Time to all in-view content after a cold open, base → stage 1 → stage 2: browser A 15535 → 12475 → 10916, B 7507 → 5546 → 5573, C 4033 → 3499 → 4506 ms; desktop A 8250 → 10473 → 9191, B 3801 → 3728 → 5335, C 3487 → 3576 → 3698 ms. On desktop, full content after a cold open is slower than on base for all three canvases, because the canvas becomes usable first and media then loads through 3 read slots.

Peak Blob storage per run: base 1.0–2.8 GiB, stage 1 0.7–1.4 GiB, stage 2 0.5–1.3 GiB.

Known limitations

  • Media reads do not retry a storage_busy lock timeout. storageRequest and CreationClient.open retry it, but transientReadFailure does not, so main has the same gap; there the read error is swallowed and the node shows no media. Here the node shows "Could not load media" with Retry. It happened in the stage 1 desktop C↔B run (six reads about 15 s after C opened, matching the catalog lock timeout) and once on a freshly restarted server with stage 2 (see the next item). Stage 2 shortens catalog lock holds, and its benchmark runs had no lock timeout.
  • Switching away while the current canvas is still loading media is not covered by the benchmark above. Measured separately, A→B 2 s after A became usable, with 47–94 of its 133 visible nodes still loading (browser runtime, 3 runs each, click to B usable): 0.75–0.98 s with both commits and 4.7–5.0 s with stage 1 alone, on a warm server. The first such switch after a server restart took 42.4 s with both commits and 48.8 s with stage 1 alone, because the first history replay of A (301 commits) holds the catalog lock for longer than its 15 s timeout and other requests queue behind it. That lock contention exists on main too, where the workspace stays inert until every node's media has loaded.
  • While a canvas is open, its loaded media is held as Blobs, one copy per asset (about 177 MiB for A and 1.2 GiB for B in the packaged app). The copy is released when the canvas is closed or switched.
  • Video is still read as a whole file. Streaming and posters are outside this change.

Provider verification

  • No real-provider calls were made.

Bilingual UI

  • zh-CN and en-US are updated together: canvasNodes.media.loading, .failed and .retry. canvas_progressive_load runs in both languages.

@github-actions github-actions Bot added area:canvas Canvas, nodes and direct manipulation area:performance Performance and responsiveness / 性能与响应速度 type:feat New capability or behaviour labels Nov 24, 2026
@Redivesue
Redivesue force-pushed the feat/446-stage-2-node-media branch from 3c95a2d to 3a9ee03 Compare November 24, 2026 05:01
},
{ timeoutMs: 120_000, attempts: 3, ...options },
),
{

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.

These are the two existing js/file-access-to-http findings on main, for the media content and thumbnail fetches in CreationClient. They are reported again because this PR wraps both calls in the read limiter. The URLs and their sources are unchanged: same-origin /api paths built from the project and asset IDs. The CodeQL check passes.

},
{ timeoutMs: 120_000, attempts: 3 },
),
{ priority: MEDIA_PRIORITY.visible },
@kunkunblueberry

Copy link
Copy Markdown
Collaborator

WITHHOLD 3a9ee03 Refs #446

  • Required CI is green on this SHA: checks / python (13m15s), static, frontend, browser (assistant|isolated|voice), checks, tests, route, CodeQL — all 13 pass. The required checks had not started when I opened this review (all action_required); I approved those runs and the numbers above are from that attempt.
  • Still blocking: this is a user-visible change with no attached media. switch-main-vs-stage2.mp4 and the node-state images are named only inside HTML comments, and the checklist box is unchecked; the body contains no user-attachments URL. Attach them or mark N/A with a reason.
  • This tip contains [feat] canvas: show project structure before node media #484's commit d369be56, so the GitHub diff is 56 files = stage 1 + stage 2, and mergeStateStatus is CLEAN only because both trees are self-consistent. Merge [feat] canvas: show project structure before node media #484 first (or rebase after it lands) so the squash does not carry stage 1 twice. I reviewed the stage-2 delta separately as pr484...pr485 (11 files) as you asked.
  • One semantics point I verified rather than took from the description. creation_assets.py now uses _find + _current_record instead of _load, and an unproven chain still falls back to the full replay, so a damaged ancestor is still rejected. What it does extend is the cached-head exposure to a new call site: _current_record keys its cache on the head file signature plus the manifest, so an ancestor rewritten on disk while the server runs is served from cache until restart. open_media did a full _load before this change. Your body discloses this; I am recording it so the storage owner confirms the media read path is the right place to accept it.
  • Same packaged-desktop gap as stage 1: the smoke test failed with "A dialog obscures the canvas" before the rebase and was not rerun, and archive/MP4 export were not exercised.

Checked with no finding:

  • PriorityLimiter ordering, the retained/waiting bookkeeping in holdMediaRead, and the abort paths: a display consumer that leaves only aborts the shared read once every display consumer has left, an action read is marked retained, and an aborted read does not mark the asset unavailable (markMedia is skipped when the shared controller aborted). The queue is FIFO within a priority and prioritize only moves a job earlier.
  • One shared IntersectionObserver with a 160px rootMargin, unobserved on unmount; useInViewport defaults to visible when IntersectionObserver is absent, so a non-browser test environment does not stall loading.
  • Off-viewport nodes show the loading state again when they re-enter, because the effect re-runs on the enabled flip; the abort is not reported as a failure.
  • AssistantMedia moved onto the same hook, so the chat surface and canvas share one read path rather than two.

Ran: gh pr checks 485 on 3a9ee03 (13/13 pass); approved the three action_required workflow runs; read priorityLimiter.ts, the creationClient.ts delta, the useAssetMedia.tsx and CanvasNodeView.tsx deltas, and the creation_assets.py change against _current_record/_load on main; compared the stage-2 delta as pr484...pr485.

Not run: local tsc --noEmit, frontend tests, the browser gate, the Python suite, or the packaged desktop app. This review used CI and source reading only.

Opening or switching a canvas waited for every node's media, including hidden
nodes, before the workspace became interactive.

Project the canvas from the opened snapshot and keep a stable asset source in
node media fields. Object URLs are resolved only where media is displayed or
read, so they no longer enter the document, undo history or save baseline.
Saving compares asset identity, so a late media read cannot change a binding.

Return text with open-canvas, show loading and failed states per node, and
check reference-catalog files against its one snapshot.

Refs ThinkFlowLab#446
Once the structure is interactive, every mounted node still started its media
read at once and waited behind the catalog lock.

Share a bounded priority queue across media reads, start on-screen nodes only
when they reach the viewport, and cancel a display read once no on-screen
consumer needs it. Explicit actions keep priority and are never cancelled by a
display consumer leaving.

Reuse the validated head for repeated media reads. An unproven chain still runs
the full validation first, so a damaged ancestor keeps being rejected.

Refs ThinkFlowLab#446
@Redivesue
Redivesue force-pushed the feat/446-stage-2-node-media branch from 3a9ee03 to 7f70818 Compare November 24, 2026 09:34
@Redivesue Redivesue changed the title [feat] canvas: load node media independently by priority [feat] canvas: show project structure first and load node media by priority Nov 24, 2026
@Redivesue

Copy link
Copy Markdown
Contributor Author

Updated per the review: #484 is closed, so this PR now carries both commits, rebased onto aff774a8. The body has the media, a design note on the cached project head, and validation on this tip: Python 2922 passed, browser gate 30/30, packaged desktop smoke and acceptance pass. The new workflow runs need approval.

@kunkunblueberry

Copy link
Copy Markdown
Collaborator

PASS 7f70818 Refs #446

Supersedes my WITHHOLD. This PR now carries both stages (#484 is closed in its favour), the body has the media evidence, and the required checks are green on this SHA.

  • Required CI: 13/13 on 7f70818 — checks / python, static, frontend, browser (assistant|isolated|voice), checks, tests, route, CodeQL. mergeStateStatus CLEAN.
  • Evidence: attached recording (main 9.26 s vs 0.27 s to usable) and English/Chinese node-state screenshots, with - [x] Media attached and - [x] Refs #446.
  • The tip only moved by a rebase plus the body. I diffed my reviewed tip 3a9ee032 against 7f70818a over the pull request's own files (src/backend, src/canvas, creation_assets.py, priorityLimiter.test.ts, creationClient.test.ts) and the diff is empty, so the stage-1 and stage-2 code I read earlier is the code that ships.
  • No revert of merged work: job_states and unfinished_jobs are still in creation_canvas.py alongside the new text_contents, and the canvasNodes.media.* keys are still in both locales.

One correction to my earlier note, in the author's favour. I wrote that using the cached head in open_media newly exposes the media path. The design note pointed out something I had not checked: main's open() already calls _current_record and continues even when validated is false, while this change requires validated before reusing the head and otherwise falls back to a full _load. I verified both in creation_projects.py and creation_assets.py, so the new call site is stricter than the path already on main, and the served bytes are still checked against the asset fingerprint and size. The remaining gap — an ancestor rewritten on disk while the server runs is caught on the next restart, not by a media read — is narrower than what open() already accepts, and the note says so.

Accepted as disclosed, not fixed here: media reads still do not retry a storage_busy lock timeout (the same gap exists on main, where the read error is swallowed instead); switching away while a canvas is still loading is slower than a settled switch; loaded media is held as Blobs while a canvas is open; video is still read as a whole file. All four are stated in the body with measurements.

Ran: gh pr checks 485 on 7f70818 (13/13); approved the three action_required runs so required CI could execute; git diff 3a9ee032..7f70818a over the pull request's own files (empty); re-read creation_assets.py, priorityLimiter.ts, the creationClient.ts and useAssetMedia.tsx deltas, and the _current_record/_load/open() paths on main; verified the attachments and both locale keys.

Not run: the Python suite, browser gate, or packaged desktop app locally. This review used CI, source reading, and the recorded evidence in the body.

@kunkunblueberry
kunkunblueberry merged commit 8b831f2 into ThinkFlowLab:main Nov 24, 2026
13 checks passed
@Redivesue
Redivesue deleted the feat/446-stage-2-node-media branch November 24, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:canvas Canvas, nodes and direct manipulation area:performance Performance and responsiveness / 性能与响应速度 type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants