Skip to content

fix: preserve scene material document state - #560

Open
ShiroKSH wants to merge 1 commit into
pascalorg:mainfrom
ShiroKSH:fix/preserve-scene-materials
Open

fix: preserve scene material document state#560
ShiroKSH wants to merge 1 commit into
pascalorg:mainfrom
ShiroKSH:fix/preserve-scene-materials

Conversation

@ShiroKSH

@ShiroKSH ShiroKSH commented Jul 29, 2026

Copy link
Copy Markdown

Summary

  • Preserve custom materials across API saves, clone/fork, SQLite, MCP import/export, and live sync.
  • Preserve collections and installed plugins at the bridge and storage boundaries.
  • Suppress only an exact live-event echo, so a following local edit is saved.

Checks

  • bun test packages/core/src/utils/clone-scene-graph.test.ts packages/mcp/src/storage/sqlite-scene-store.test.ts packages/mcp/src/bridge/scene-bridge.test.ts apps/editor/lib/graph-schema.test.ts apps/editor/lib/scene-sync.test.ts — 83 passed.
  • bun run --cwd packages/core build
  • bun run --cwd packages/mcp build
  • Targeted app TypeScript check for scene-sync.ts and scene-loader.tsx.

Note

Medium Risk
Touches untrusted graph validation and multi-session save/sync behavior; changes are bounded by schema checks and targeted tests but affect how scene payloads are accepted and written.

Overview
Fixes loss of custom scene document state (materials, collections, installed plugins) when scenes are saved, cloned, imported/exported, or synced live.

Persistence & validation: materials are now part of the core SceneGraph clone/fork path (deep-cloned on duplicate), validated on API (apiGraphSchema with SceneMaterial, including unsafe texture URL rejection) and SQLite graph parsing. MCP SceneBridge exportJSON / loadJSON and setScene extras round-trip collections, materials, and explicit plugin installs in one load.

Live sync: Shared scene-sync helpers build a signature that includes materials (and other persisted fields). The editor skips autosave only when the outgoing graph exactly matches the last applied remote event—replacing a broad time-based suppress—so a local edit right after a live update still saves.

Reviewed by Cursor Bugbot for commit 9970b0c. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9970b0c. Configure here.

nodes: state.nodes,
rootNodeIds: state.rootNodeIds,
collections: state.collections ?? {},
materials: state.materials,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MCP save drops materials

High Severity

SceneBridge.exportJSON now includes materials, but SceneOperations.exportSceneGraph still returns only nodes, roots, collections, and plugins. MCP save_scene and live sync publish through exportSceneGraph, so custom scene materials are dropped on persist even though import/export round-trips them in tests.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9970b0c. Configure here.


versionRef.current = payload.version
lastRemoteGraphJsonRef.current = sceneGraphSignature(payload.graph)
suppressRemoteSaveUntilRef.current = Date.now() + 2500

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remote echo uses pre-apply graph

Medium Severity

Live sync stores the echo signature from the SSE payload.graph before applySceneGraphToEditor, while autosave signs the store graph after setScene migration and cleanup. Those graphs often differ, so exact echo fails and the removed 2.5s save suppress no longer blocks redundant PUTs after remote updates.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9970b0c. Configure here.

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.

1 participant