Repository navigation
fix(canvas): upload media replaced on an existing node - #570
Open
Zhangbo-cn wants to merge 7 commits into
Open
Zhangbo-cn wants to merge 7 commits into
Zhangbo-cn wants to merge 7 commits into
Conversation
Zhangbo-cn
requested review from
hsliuustc0106 and
princepride
as code owners
November 29, 2026 03:28
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
force-pushed
the
fix/replace-node-upload
branch
from
November 29, 2026 03:54
401ee80 to
9bade54
Compare
# Conflicts: # scripts/run-browser-suite.mjs
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 /uploadswas ever sent, and the saved project keptbinding.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.tspushedupdate-nodewith the resource returned bycreationProjection.importFile. For ordinary images that resource is a page-local data URL with noassetId; the save-timeimportResource → importBlobstep 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
importBloband 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 onePUT /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 whilePUT /uploadsanswers 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 workspacenode_modulessymlink was committed by accident; that entry is removed and the wider pattern keeps anynode_modulessymlink out.maintracks nonode_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, currentmain): zeroPUT /uploadsrequests; the project showsbinding.role = "empty",objectRef = null, no assets; after a reload the node is back to the upload placeholder.After (
90f80f2e; the reviewed headee6b2dd8adds only browser-test coverage on top, the application code is identical): onePUT /uploads;binding.role = "material"withassetId, asset namereplace-probe.png, fingerprintsha256:9aa950b1…; after a reload the image is still rendered and no upload placeholder exists.Failure path (
90f80f2e): the same flow withPUT /uploadsanswered 500 shows the error toast instead of silently writing an empty binding; project state keeps no asset.Failing before, passing after: the browser test was copied onto
728b4077and run there: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— passednpm test— 1111 passed, 0 failednpm run check:i18n— 3839 keys, 0 problems, 170 Chinese source lines (baseline 170)npm run check:browser-locale— 105 pages, 0 problemsnpm run check:browser-manifest— 110 entries, gate=38node tests/browser/node_media_upload.mjsagainst the isolated fixture API and Vite at this head — passed both scenarios, including the populated replacement and the exact one-upload count728b4077— failed at line 79 (output above)Release checks on the pushed head
ee6b2dd8(run 47326254508) passed every lane:checks / static,checks / python,checks / frontend,checks / browser (isolated)(thegatelane that now runs this test),checks / browser (voice),checks / browser (assistant),checks / desktop / macos,checks / desktop / windows, and the aggregatechecks / checks; CodeQL andtestsare 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 onlychecks / pythonand the aggregate attests/test_agent_visual_gate.py::test_real_opencode_native_input[image-model]withAssertionError: 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 reported3330 passed, 121 skipped. The branch now carries currentmain(728b4077) and a fresh run starts on the pushed head.The run on the pushed head
ee6b2dd8(run 47326254508) completedsuccessacross all lanes listed above.origin/mainhas since advanced to42c5dc39(#692, a CI test-sharding change only); the PR diff against42c5dc39is the same five files, +206/−2, and the merge state is clean.Review
728b40774628307f315a2b29c466237a8c434a11(origin/mainat review time;mainhas since advanced to42c5dc39with [ci] python: parallelize suite across three shards and isolate native CLI regressions #692, a CI test-sharding change only, and the PR diff against42c5dc39is the same five files, +206/−2)ee6b2dd8c6522aba80a099135ce4a14412ea8f6cFixes #569opendirector-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.importFilecontinuing 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.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 on90f80f2ealso scored 93/100 with the same WITHHOLD reason; it asked for the populated replacement and exact-one-upload assertions, which were added inee6b2dd8. The re-review re-ran the head and base test (head passes both scenarios; base fails at line 79 with0 !== 1),tsc,npm test1111,check:i18n3839/170,check:browser-locale105,check:browser-manifest110/gate=38, verified the project states (two assets with the binding onreplace-probe-2.png; failure project still zero assets), matched the evidence URLs, and confirmed the delta90f80f2e..ee6b2dd8is test-only.ee6b2dd8completedsuccessacross every lane, including thegatebrowser 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.npm run build, and the desktop packages were not run locally; Release checks on this head are green.🤖 Generated with Claude Code