Skip to content

fix(canvas): upload media replaced on an existing node - #570

Open
Zhangbo-cn wants to merge 7 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:fix/replace-node-upload
Open

Zhangbo-cn wants to merge 7 commits into
ThinkFlowLab:mainfrom
Zhangbo-cn:fix/replace-node-upload

Conversation

@Zhangbo-cn

@Zhangbo-cn Zhangbo-cn commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replacing the media of an existing canvas node from the node itself (hover → Upload image) showed the picture for a moment and then dropped it: no PUT /uploads was ever sent, and the saved project kept binding.role = "empty" with no asset. Pressing the same upload again behaved the same way, so the node could not be filled.

Root cause: the replace-target branch in useWorkspaceTransfer.ts pushed update-node with the resource returned by creationProjection.importFile. For ordinary images that resource is a page-local data URL with no assetId; the save-time importResource → importBlob step that normally uploads bytes had already been skipped because the upload was addressed to an existing node. New nodes and toolbar uploads take the save path, so only node replacement lost the bytes.

The replace branch now uploads the file's bytes through importBlob and binds the resulting asset whenever the imported resource has no asset and is not text. Text replacements remain inline text; video, audio, HEIC and subject targets already came back asset-backed, so they keep their current path and do not upload twice. No user-facing copy changes: a failed upload still raises through the existing path, which shows the localized error toast.

Changes

  • src/canvas/workspace/useWorkspaceTransfer.ts: on a replacement target, import an unregistered non-text resource's bytes and bind that asset instead of the page-local preview.
  • tests/browser/node_media_upload.mjs: new gate-lane browser test. Scenario 1 replaces an empty image node's media and asserts exactly one PUT /uploads, binding.role = "material" with an asset named after the file, then reloads and asserts the image renders with no upload placeholder and no page errors. It then selects the now-filled node, uses the context menu's Replace asset, and asserts a second, single upload binds a different asset under the new file's name, which still survives a reload. Scenario 2 uploads while PUT /uploads answers 500 and asserts the error toast is visible and no asset is bound.
  • tests/browser/manifest.json, scripts/run-browser-suite.mjs: register the test in the gate lane.
  • .gitignore: node_modules/ → node_modules. Earlier on this branch a workspace node_modules symlink was committed by accident; that entry is removed and the wider pattern keeps any node_modules symlink out. main tracks no node_modules.

Evidence

Steps: an isolated fixture API and Vite served an empty image node seeded through the canvas model. The cursor hovered the node and clicked its Upload image, then chose a 64×64 PNG. Project state was read from the API after the upload and again after a reload.

Before (728b4077, current main): zero PUT /uploads requests; the project shows binding.role = "empty", objectRef = null, no assets; after a reload the node is back to the upload placeholder.

Before, after replace: the title changed but the node is empty and no asset exists (728b4077)

Before, after reload: the node is still empty (728b4077)

After (90f80f2e; the reviewed head ee6b2dd8 adds only browser-test coverage on top, the application code is identical): one PUT /uploads; binding.role = "material" with assetId, asset name replace-probe.png, fingerprint sha256:9aa950b1…; after a reload the image is still rendered and no upload placeholder exists.

After, after replace: the asset is registered and bound (90f80f2e)

After, after reload: the image persists with no placeholder (90f80f2e)

Failure path (90f80f2e): the same flow with PUT /uploads answered 500 shows the error toast instead of silently writing an empty binding; project state keeps no asset.

Failure: the upload error is visible and nothing is bound (90f80f2e)

Failing before, passing after: the browser test was copied onto 728b4077 and run there:

BASE SHA: 728b40774628307f315a2b29c466237a8c434a11
$ node tests/browser/node_media_upload.mjs
AssertionError [ERR_ASSERTION]: replacing node media must upload its bytes exactly once, not keep a page-local preview
0 !== 1
    at file:///tmp/od570-base/tests/browser/node_media_upload.mjs:79:10

On the head the same file passes both scenarios (Replacing node media uploads and keeps the saved asset), including the second, populated replacement and the exact one-upload count.

Test plan

Local, on the head (ee6b2dd8c6522aba80a099135ce4a14412ea8f6c):

  • node_modules/.bin/tsc --noEmit — passed
  • npm test — 1111 passed, 0 failed
  • npm run check:i18n — 3839 keys, 0 problems, 170 Chinese source lines (baseline 170)
  • npm run check:browser-locale — 105 pages, 0 problems
  • npm run check:browser-manifest — 110 entries, gate=38
  • node tests/browser/node_media_upload.mjs against the isolated fixture API and Vite at this head — passed both scenarios, including the populated replacement and the exact one-upload count
  • The same test file copied onto 728b4077 — failed at line 79 (output above)
  • The replacement and failure flows captured at both revisions (screenshots above)

Release checks on the pushed head ee6b2dd8 (run 47326254508) passed every lane: checks / static, checks / python, checks / frontend, checks / browser (isolated) (the gate lane that now runs this test), checks / browser (voice), checks / browser (assistant), checks / desktop / macos, checks / desktop / windows, and the aggregate checks / checks; CodeQL and tests are green too. An Electron-packaged run was not exercised locally.

No real provider was called; this path is a local file upload and needs no model. The fixture asset is a generated PNG.

Checks note

The previous Release run on the pre-merge head (2f662eb9) failed only checks / python and the aggregate at tests/test_agent_visual_gate.py::test_real_opencode_native_input[image-model] with AssertionError: Real OpenCode integration timed out (tests/test_native_runtime.py:370). That is a real-OpenCode integration timeout in the harness, unrelated to canvas upload code; the suite otherwise reported 3330 passed, 121 skipped. The branch now carries current main (728b4077) and a fresh run starts on the pushed head.

The run on the pushed head ee6b2dd8 (run 47326254508) completed success across all lanes listed above. origin/main has since advanced to 42c5dc39 (#692, a CI test-sharding change only); the PR diff against 42c5dc39 is the same five files, +206/−2, and the merge state is clean.

Review

  • Reviewed base: 728b40774628307f315a2b29c466237a8c434a11 (origin/main at review time; main has since advanced to 42c5dc39 with [ci] python: parallelize suite across three shards and isolate native CLI regressions #692, a CI test-sharding change only, and the PR diff against 42c5dc39 is the same five files, +206/−2)
  • Reviewed head: ee6b2dd8c6522aba80a099135ce4a14412ea8f6c
  • Fixes #569
  • Self-review (opendirector-review, candidate mode): 93/100. Ratings: scope 3/3, correctness 3/3, validation 2/3 (Release checks have not run on the unpushed head; the text/new-node/subject paths are reasoned from the guard and delegated to existing extended lanes rather than re-run locally), claim evidence 3/3 (before/after captures at the pinned base and head with project state, the failure toast, and the failing-before run), simplicity 3/3 (no comments added; the upload reuses the existing client and projection). Verdict: WITHHOLD only because Release checks have not run on the unpushed head; no blocking code finding.
  • Self-review findings, all non-blocking: the guard on the replacement resource is a four-part condition that relies on importFile continuing to return an asset-backed resource for video, audio, HEIC and subject targets; if that changes, the condition silently stops uploading instead of failing, and only the browser test would catch it. The failure-path toast is asserted with fixture text injected by the test route, so the test proves visibility and no binding, not the production error wording.
  • Independent candidate review (non-contributing subagent, same skill and pinned base/head): 93/100 on ee6b2dd8, WITHHOLD only because Release checks have not run on this unpushed head; no blocking findings. Ratings: scope 3/3, correctness 3/3, validation 2/3 (CI and the unchanged-path extended lanes unrun; the requested populated-replacement and exact-one-upload gaps are now closed), claim evidence 3/3, simplicity 3/3. The first pass on 90f80f2e also scored 93/100 with the same WITHHOLD reason; it asked for the populated replacement and exact-one-upload assertions, which were added in ee6b2dd8. The re-review re-ran the head and base test (head passes both scenarios; base fails at line 79 with 0 !== 1), tsc, npm test 1111, check:i18n 3839/170, check:browser-locale 105, check:browser-manifest 110/gate=38, verified the project states (two assets with the binding on replace-probe-2.png; failure project still zero assets), matched the evidence URLs, and confirmed the delta 90f80f2e..ee6b2dd8 is test-only.
  • Status after review: run 47326254508 on ee6b2dd8 completed success across every lane, including the gate browser lane that runs the new test and the extended lanes covering the untouched paths. That satisfies the condition both reviews withheld on; their scores and findings above are unchanged.
  • Material validation gaps: the extended browser lanes covering the unchanged new-node, subject, and text paths, npm run build, and the desktop packages were not run locally; Release checks on this head are green.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:canvas Canvas, nodes and direct manipulation type:bug Something is broken labels Nov 29, 2026
Uploading a file into an existing node kept the editor's page-local blob
URL: the replace branch of the import path only patched node data, while the
byte upload happened later when a projection imported the resource. The item
was saved with an empty binding, so the picture disappeared on the next
refresh and the node fell back to its placeholder.

Upload the file before the node change and patch the asset-backed resource, so
a replaced picture is registered like any other upload. Subject targets use the
same resolved resource instead of uploading twice.

Refs ThinkFlowLab#569
@Zhangbo-cn
Zhangbo-cn force-pushed the fix/replace-node-upload branch from 401ee80 to 9bade54 Compare November 29, 2026 03:54
Zhangbo-cn and others added 4 commits December 2, 2026 22:11
The real-OpenCode worker timed out under load; the same case passes locally.
The merge commit staged the worktree's node_modules symlink because the
.gitignore entry ended with a slash, which matches directories only.
Ignore the name itself so a symlink is excluded too, and remove the entry
that was committed by the merge.

Drop the explanatory code comment and the unused test cleanup so the
change is described by the tests and the commit message alone.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhangbo-cn pushed a commit to Zhangbo-cn/OpenDirector that referenced this pull request Dec 4, 2026
…ures

Co-Authored-By: Claude Code <noreply@anthropic.com>
A failed byte upload must surface the backend error and leave the node
without an asset instead of silently binding nothing.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhangbo-cn pushed a commit to Zhangbo-cn/OpenDirector that referenced this pull request Dec 4, 2026
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>

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

area:canvas Canvas, nodes and direct manipulation type:bug Something is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant