Skip to content

Align CSG result naming with variable-based IDs and collision-safe blockKey handling#506

Merged
tracygardner merged 3 commits intomainfrom
codex/update-csg-naming-to-use-variable-based-ids
Apr 5, 2026
Merged

Align CSG result naming with variable-based IDs and collision-safe blockKey handling#506
tracygardner merged 3 commits intomainfrom
codex/update-csg-naming-to-use-variable-based-ids

Conversation

@tracygardner
Copy link
Copy Markdown
Contributor

@tracygardner tracygardner commented Apr 5, 2026

Motivation

  • Make CSG result meshes follow the same variable-based naming pattern used by other mesh-creation blocks (name__blockId) so scene names are readable and predictable.
  • Ensure block ownership metadata (blockKey) is derived from the variable-based ID rather than a hardcoded runtime prefix.
  • Avoid indiscriminate unique suffixing and only append a uniqueness suffix when a name collision actually occurs, matching shape-creator behavior.

Description

  • Generator changes: updated the CSG-producing blocks in generators/generators-transform.js (merge_meshes, subtract_meshes, intersection_meshes) to emit IDs as ${resultVar}__${block.id} and preserved meshMap / meshBlockIdMap wiring and generated call shapes (e.g. `await mergeMeshes(

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Prevented naming collisions for mesh operations, reducing duplicate/overwritten meshes and more reliable results.
  • Refactor

    • Mesh merge, subtract, intersect, and hull operations now use resolved, deterministic identities for created meshes, yielding consistent naming and behavior across transformations.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 5, 2026

Deploying flockdev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 151a054
Status: ✅  Deploy successful!
Preview URL: https://46d8fe0c.flockdev.pages.dev
Branch Preview URL: https://codex-update-csg-naming-to-u.flockdev.pages.dev

View logs

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

Warning

Rate limit exceeded

@tracygardner has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 19 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 12 minutes and 19 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 93557207-b934-46a6-b396-1e8117e20843

📥 Commits

Reviewing files that changed from the base of the PR and between c656170 and 151a054.

📒 Files selected for processing (1)
  • api/csg.js
📝 Walkthrough

Walkthrough

Adds deterministic mesh identity handling for CSG: generators emit ${resultVar}__${block.id} IDs; api/csg.js gains resolveCsgModelIdentity() to split that into a stable blockKey and a resolved unique modelId, and threads blockKey into mesh preparation and metadata.

Changes

Cohort / File(s) Summary
CSG Identity Resolution
api/csg.js
Adds resolveCsgModelIdentity(requestedModelId) to parse __-suffixed identifiers into blockKey and a resolved unique modelId; updates CSG ops (mergeMeshes, subtractMeshesMerge, subtractMeshesIndividual, intersectMeshes, createHull) to use the resolved identities and pass blockKey into prepareMeshes and metadata. Replaces prior blockId/mutation logic.
Deterministic Mesh ID Generation
generators/generators-transform.js
Replaces generated unique suffixes with deterministic IDs of the form ${resultVar}__${block.id} for CSG transform generators (merge_meshes, subtract_meshes, intersection_meshes, hull_meshes), and updates meshMap/meshBlockIdMap assignments and helper-call strings accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant Generator
  participant CSG_API
  participant Scene
  Generator->>CSG_API: call CSG op with meshId `${resultVar}__${block.id}`
  CSG_API->>CSG_API: resolveCsgModelIdentity(requestedModelId) -> {modelId, blockKey}
  CSG_API->>Scene: prepareMeshes(..., modelId, blockKey)
  Scene-->>CSG_API: prepared meshes
  CSG_API->>CSG_API: perform CSG operation -> result mesh
  CSG_API->>Scene: add mesh with unique modelId (append uid if collision)
  CSG_API->>Scene: flock.applyResultMeshProperties(result, blockKey)
  Scene-->>Generator: result reference
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I stitched two names with a tiny __,

one for the block and one for the mesh to bless.
No collisions now hop in my sight—
deterministic IDs, snug and right.
Hooray for clean names in the rabbit's light!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: aligning CSG result naming with variable-based IDs and implementing collision-safe blockKey handling, which matches the core objectives of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/update-csg-naming-to-use-variable-based-ids

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
generators/generators-transform.js (1)

575-580: ⚠️ Potential issue | 🟡 Minor

Align hull_meshes ID pattern with other CSG blocks.

The merge_meshes, subtract_meshes, and intersection_meshes blocks all use ${resultVar}__${block.id}, but hull_meshes uses "hull" + "_" + generateUniqueId(). This inconsistency means resolveCsgModelIdentity will parse blockKey differently for hull IDs—the entire ID becomes blockKey instead of extracting the block ID from the __ separator.

Change hull_meshes to use the same pattern:

-    const meshId = "hull" + "_" + generateUniqueId();
+    const meshId = `${resultVar}__${block.id}`;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@generators/generators-transform.js` around lines 575 - 580, The hull_meshes
case is creating meshId with "hull_"+generateUniqueId(), which breaks
resolveCsgModelIdentity's expected `${resultVar}__${block.id}` pattern; update
the code where meshId is set (and where meshMap and meshBlockIdMap are assigned)
to use the same pattern as other CSG blocks (e.g., meshId =
`${resultVar}__${block.id}`), leaving the subsequent createHull call
(createHull("${meshId}", ${meshList})) and the meshMap/meshBlockIdMap
assignments intact so identity parsing via resolveCsgModelIdentity works
consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/csg.js`:
- Around line 919-924: createHull is calling resolveCsgModelIdentity but the
hull generator ("hull" + "_" + generateUniqueId()) uses a single underscore so
resolveCsgModelIdentity sets blockKey to the whole string (e.g., "hull_abc123")
instead of the raw block ID like other CSG ops; update the hull_meshes generator
to emit IDs using the same split pattern as other CSG items (e.g.,
"hull__<blockId>" or whatever delimiter resolveCsgModelIdentity expects) so
blockKey becomes the block ID, or alternatively change createHull to
normalize/extract the block ID before calling flock.prepareMeshes (referencing
createHull, resolveCsgModelIdentity, hull_meshes generator, and
flock.prepareMeshes).

---

Outside diff comments:
In `@generators/generators-transform.js`:
- Around line 575-580: The hull_meshes case is creating meshId with
"hull_"+generateUniqueId(), which breaks resolveCsgModelIdentity's expected
`${resultVar}__${block.id}` pattern; update the code where meshId is set (and
where meshMap and meshBlockIdMap are assigned) to use the same pattern as other
CSG blocks (e.g., meshId = `${resultVar}__${block.id}`), leaving the subsequent
createHull call (createHull("${meshId}", ${meshList})) and the
meshMap/meshBlockIdMap assignments intact so identity parsing via
resolveCsgModelIdentity works consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f8041ab-5ef2-4664-bf8f-5e840198bc3c

📥 Commits

Reviewing files that changed from the base of the PR and between 24a9e32 and 80e0e24.

📒 Files selected for processing (2)
  • api/csg.js
  • generators/generators-transform.js

Comment on lines +919 to +924
const { modelId: resolvedModelId, blockKey } =
resolveCsgModelIdentity(modelId);
modelId = resolvedModelId;

return flock
.prepareMeshes(modelId, meshList, blockId)
.prepareMeshes(modelId, meshList, blockKey)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

createHull uses resolveCsgModelIdentity but generator still uses old pattern.

This function will parse an ID like hull_abc123 (from the generator's "hull" + "_" + generateUniqueId()). Since there's no __ in that pattern, resolveCsgModelIdentity will set blockKey = requestedModelId (the full string), which differs from the other CSG operations where blockKey is just the block ID.

This asymmetry may cause issues with block ownership metadata. Either update hull_meshes generator to use the new pattern, or document why hull is intentionally different.

Also applies to: 1003-1004

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/csg.js` around lines 919 - 924, createHull is calling
resolveCsgModelIdentity but the hull generator ("hull" + "_" +
generateUniqueId()) uses a single underscore so resolveCsgModelIdentity sets
blockKey to the whole string (e.g., "hull_abc123") instead of the raw block ID
like other CSG ops; update the hull_meshes generator to emit IDs using the same
split pattern as other CSG items (e.g., "hull__<blockId>" or whatever delimiter
resolveCsgModelIdentity expects) so blockKey becomes the block ID, or
alternatively change createHull to normalize/extract the block ID before calling
flock.prepareMeshes (referencing createHull, resolveCsgModelIdentity,
hull_meshes generator, and flock.prepareMeshes).

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
generators/generators-transform.js (1)

505-510: ⚠️ Potential issue | 🟠 Major

Use lastIndexOf("__") instead of indexOf("__") to correctly parse meshIds when variable names contain double underscores.

The meshId format ${resultVar}__${block.id} creates a parsing ambiguity in resolveCsgModelIdentity() at line 264 of api/csg.js. Since Blockly allows any valid JavaScript identifier (including those with __), a variable named my__mesh would create meshId my__mesh__abc123. The current code using indexOf("__") finds the first occurrence and incorrectly parses it as modelId = "my" and blockKey = "mesh__abc123", when it should parse the last __ separator to get modelId = "my__mesh" and blockKey = "abc123".

Fix line 264 in api/csg.js:

-    const separatorIndex = requestedModelId.indexOf("__");
+    const separatorIndex = requestedModelId.lastIndexOf("__");

This affects all four CSG transform blocks: merge_meshes (line 505), subtract_meshes (line 531), intersection_meshes (line 553), and hull_meshes (line 575) in generators-transform.js.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@generators/generators-transform.js` around lines 505 - 510, The meshId
generation uses `${resultVar}__${block.id}` (symbols: meshId, meshMap,
meshBlockIdMap, mergeMeshes) but parsing in resolveCsgModelIdentity()
(api/csg.js) uses indexOf("__") which breaks when resultVar contains "__";
change the parser to use lastIndexOf("__") instead of indexOf("__") so the
separator is taken as the final "__" and modelId and blockKey are split
correctly; ensure the same fix is applied conceptually to any CSG transform
parsing logic associated with merge_meshes, subtract_meshes,
intersection_meshes, and hull_meshes so generated ids like `my__mesh__abc123`
yield modelId="my__mesh" and blockKey="abc123".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@generators/generators-transform.js`:
- Around line 505-510: The meshId generation uses `${resultVar}__${block.id}`
(symbols: meshId, meshMap, meshBlockIdMap, mergeMeshes) but parsing in
resolveCsgModelIdentity() (api/csg.js) uses indexOf("__") which breaks when
resultVar contains "__"; change the parser to use lastIndexOf("__") instead of
indexOf("__") so the separator is taken as the final "__" and modelId and
blockKey are split correctly; ensure the same fix is applied conceptually to any
CSG transform parsing logic associated with merge_meshes, subtract_meshes,
intersection_meshes, and hull_meshes so generated ids like `my__mesh__abc123`
yield modelId="my__mesh" and blockKey="abc123".

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5df57c07-df37-4f9c-950c-b79b0df1ea70

📥 Commits

Reviewing files that changed from the base of the PR and between 80e0e24 and c656170.

📒 Files selected for processing (1)
  • generators/generators-transform.js

@tracygardner tracygardner merged commit a2095dd into main Apr 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant