Skip to content

mcp: check floor procedural-item footprints in collision checks - #1303

Open
kruschdev wants to merge 11 commits into
pascalorg:mainfrom
kruschdev:fix/procedural-item-collisions
Open

kruschdev wants to merge 11 commits into
pascalorg:mainfrom
kruschdev:fix/procedural-item-collisions

Conversation

@kruschdev

@kruschdev kruschdev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #1255

check_collisions and layout-clearance (collectOccupiedFootprints and findItemItemCollisions, used by verify_scene, furnish_room, and place_in_room) previously filtered strictly on node.type === 'item'. As a result, overlapping floor-standing procedural-item nodes returned status: "checked" with empty checkedItems, skippedItems, and collisions, while verify_scene reported hasIssues: false.

I updated @pascal-app/core and @pascal-app/mcp so floor-standing procedural-item nodes participate in plan footprint and vertical-interval collision checks under the same contract as item nodes:

  • Plan footprint and inspection (door-clearance.ts, item-space.ts): Added proceduralNodePlanCorners, proceduralNodePlanAabb, inspectProceduralItemPlanFootprint, and proceduralItemLevelPose using @pascal-app/core/procedural-items directly so standalone MCP bridges without @pascal-app/nodes loaded still evaluate recipe bounds accurately, including off-center recipe datums under yaw, named surface attachment host chains, and consistent unsupported_attachment skipping for wall-side and ceiling mounting designs parented to a level.
  • Layout clearance, stacking, and pair roles (layout-clearance.ts, furniture-kind.ts): Included procedural-item in collectOccupiedFootprints and findItemItemCollisions, extended designedTogether to ProceduralItemNode so procedural dining/bedside pairs within the 0.08 m clearance band are not false-positived as item_too_close, added proceduralHeightsInLevel and shared floor-lift election (electFloorPlacedLift) so items hosted on or resting atop procedural surfaces still honor STACK_TOLERANCE, filtered flat procedural rug underlays, and guarded ItemNode-only helpers (isWallDressing, itemSolidsInLevel, boxSolid).
  • MCP check_collisions (check-collisions.ts): Scoped, inspected, and gated procedural-item alongside item with catalog: "procedural" source metadata, recording unsupported_attachment, parent_local_coordinates, and non_planar_rotation in skippedItems (insufficient_evidence or partial) and excluding skipped procedural nodes from findItemItemCollisions.

How to test

  1. Run bunx biome check on the modified files in packages/core and packages/mcp (0 errors, 0 warnings).
  2. Run bunx turbo run build check-types test --filter=@pascal-app/core --filter=@pascal-app/mcp and verify the new #1255 regression cases pass in packages/core/src/agent-operations/layout-clearance.test.ts and packages/mcp/src/tools/check-collisions.test.ts.
  3. In a sandbox scene on level_0, place two floor-standing 2 m x 2 m x 0.9 m procedural-item nodes at [0, 0, 0] and call check_collisions({ levelId, minimumClearance: 0, floorOnly: true }) and verify_scene({}): check_collisions now reports checkedItems length 2 (catalog: "procedural") and 1 overlap collision, and verify_scene reports hasIssues: true with item_overlap.

Screenshots / screen recording

N/A (MCP and core layout-clearance logic; verified locally in both bun dev and production build).

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

Note

Medium Risk
Touches shared collision and verify_scene logic with substantial new geometry paths (recipe evaluation, host chains, attachment surfaces); regressions could false-positive or miss overlaps in agent layouts.

Overview
Floor-standing procedural-item nodes are now part of the same layout contract as catalog item nodes for check_collisions, verify_scene, and related MCP placement flows—fixing silent “no collisions” when two procedural blocks overlapped.

Core layout adds recipe-driven plan footprints (proceduralNodePlanCorners / inspectProceduralItemPlanFootprint), level poses via nodeLevelFrame, vertical intervals (including ceiling mounts and motion reach from recipe evaluation), and inclusion in collectOccupiedFootprints / findItemItemCollisions. Stacking, designedTogether clearance waivers, and procedural rug underlays mirror item behavior; children on named procedural surfaces can rest on the surface while still flagging penetration into shelves or panels above. itemLevelPose is centralized through the frame resolver instead of manual parent chaining.

MCP check_collisions inspects procedural nodes with catalog: "procedural" metadata and records skip reasons (unsupported_attachment, non_planar_rotation, etc.). Recipe evaluation now builds swept reach for ceiling-mounted designs with motion so spinning fans and similar fixtures collide in plan/height checks.

Reviewed by Cursor Bugbot for commit 5fdc85c. 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.

Stale Bugbot comment from a previous run.

@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.

Stale Bugbot comment from a previous run.

@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.

Stale Bugbot comment from a previous run.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @kruschdev, this closes a real false-negative (#1255): floor-standing procedural-items now go through the same footprint and vertical-interval checks as items, and the bridge path no longer needs @pascal-app/nodes loaded. I ran the new suites locally on this branch: layout-clearance.test.ts 51/51 and check-collisions.test.ts 16/16.

A few small things before merge:

  1. Optional chaining on recipe (check-collisions.ts): the name uses node.recipe?.name, but source.assetId uses node.recipe.name. If recipe is always present by schema, drop the ?.. If it isn't, guard both.
  2. Skip reason for wall-hosted procedural items: a procedural item with wallId is skipped as parent_local_coordinates when floorOnly is false. It isn't in parent-local coordinates, it's wall-attached, so unsupported_attachment seems more accurate in both modes. An agent reading the result will act on that reason.
  3. Scope: furniture-kind.ts (+81) isn't mentioned in the description. If it's needed for procedural footprints, a sentence on why would help. Otherwise it could be a separate PR.

CI for this fork is waiting on maintainer approval to run.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks @Aymericr! I addressed all three points in e40f704:

  1. Consistent recipe access (check-collisions.ts): Dropped the redundant ?. on node.recipe.name since ProceduralItemNode always validates a required recipe, matching node.recipe.name in source.assetId and node.asset.name for catalog items.
  2. Wall-hosted procedural skip reason: Split out the node.type === 'procedural-item' && node.wallId check ahead of the generic non-level parent check so wall-hosted procedural items report unsupported_attachment in both floorOnly: true and floorOnly: false modes, and added a regression assertion for both modes in check-collisions.test.ts.
  3. Why furniture-kind.ts is included: Once floor-standing procedural-item nodes enter collectOccupiedFootprints and findItemItemCollisions, layoutIssuesFromScene needs isFloorUnderlay and designedTogether / pairRole to recognize ProceduralItemNode as well; otherwise procedural rugs and intentionally paired procedural furniture (like dining chairs near tables) trigger false-positive item_overlap or item_too_close findings in verify_scene. (I noted this in the second bullet of the PR description as well.)

@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.

Stale Bugbot comment from a previous run.

@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.

Stale Bugbot comment from a previous run.

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Maintainer] Thanks @kruschdev. Checking procedural-item footprints in check_collisions / verify_scene is the right fix for #1255 and the scope (floor-hosted first) is sensible. Bugbot has several Medium findings at bd0c21d that I think are valid and that would turn into false positives in verify_scene (which sets hasIssues), so please address or answer each before this lands:

  1. door-clearance.ts: wall-side items are marked as checked but proceduralItemLevelPose returns null for them, so they are reported as checked yet never paired. Either exclude them from checkedItems or pose them.
  2. layout-clearance.ts: designedTogether is still applied only when both nodes are item; procedural chairs, stools and tables now go through findItemItemCollisions with the default 0.08 m gap, so valid dining and bedside layouts get item_too_close. Apply the designed-pair rule to procedural items too.
  3. layout-clearance.ts: isProceduralFloorUnderlay runs the rug check on the raw folded category, so snake_case ids like floor_mat are missed (the neighbouring pairRole normalises [-_]+).
  4. furniture-kind.ts: pairing ignores specific procedural categories.
  5. Ceiling-hosted items: three findings (mounting origin omitted in item-space.ts, ceiling items false-colliding without heights, ceiling-hosted children counted in floor packing). If the intent is floor-only, filter ceiling hosts out up front.

Please add a test per fix: a dining set of procedural chairs around a procedural table that must not report item_too_close, a floor_mat under furniture, and a ceiling light above a table.

CI: GitHub Actions have not run on this head (fork workflows are waiting for maintainer approval), so I cannot call it green yet. Fixes #1255 looks right once the above is in.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks @Aymericr! All five Bugbot items you listed were already fixed and covered by tests before bd0c21d:

  • door-clearance.ts (wall-side items marked checked): fixed in 7055180b (inspectProceduralItemPlanFootprint skips wall-side mounting regardless of floorOnly).
  • layout-clearance.ts (designedTogether on procedural items): fixed in 7055180b, tested in layout-clearance.test.ts (waives clearance (but not overlap) for designedTogether procedural dining pairs with procedural dining chairs next to a procedural dining table).
  • layout-clearance.ts (isProceduralFloorUnderlay snake_case): fixed in 1db9bd79 (normalizing [-_]+), tested in layout-clearance.test.ts with a floor_mat procedural underlay.
  • furniture-kind.ts (specific procedural categories): fixed in 1db9bd79 (gating name matching on generic categories, with a lighting "Table lamp" regression test in layout-clearance.test.ts).
  • Ceiling-hosted items (all three findings): fixed in 543813a3 (mounting origin across host chains), 7989f5f1 (swept reach heights for non-recessed ceiling motions, tested with a ceiling fan above a dining table in layout-clearance.test.ts), and bd0c21de (hasNonFloorHost ancestor walk excluding ceiling/wall-hosted descendants from floorOnly packing).

The branch merges cleanly with main and is ready for CI approval whenever you have a moment.

@Aymericr Aymericr added the bot:bugs label Dec 2, 2026 — with Cursor

Aymericr commented Dec 3, 2026

Copy link
Copy Markdown
Member

Review at bd0c21de, run with Codex (gpt-6.2-astra) over two rounds: a full review, then each finding re-checked against the diff. Only findings that survived are listed.

  • P1 — packages/core/src/agent-operations/layout-clearance.ts:739: A named attachment triggers continue before the pair’s footprints or heights are compared. In the tabletop fixture, changing the lamp’s local Y from 0 to -0.20 moves its base from 0.90 m to 0.70 m, but the pair is still skipped. Fix: compare the resolved child bottom with the named support surface using STACK_TOLERANCE; test both resting contact and penetration.
  • P1 — packages/core/src/agent-operations/door-clearance.ts:355: Plan corners use evaluated.min/max, while proceduralHeightsInLevel uses evaluated.reach ?? evaluated. The test fan’s 1.2 × 0.14 m blade extends only 0.07 m along Z at rest but reaches 0.60 m after a quarter turn. A tall, narrow cabinet at Z 0.50 m can therefore be rejected by the plan check despite intersecting the sweep. Fix: project swept X/Z bounds for collision checks and add that cabinet case.
  • P2 — packages/core/src/agent-operations/layout-clearance.ts:191: collectOccupiedFootprints accepts the yaw-only projection from proceduralPlanAabbInLevel. For the MCP test’s rotation [0.2, 0, 0], core retains that footprint even though its height helper rejects the tilt and MCP reports non_planar_rotation. Fix: apply the same planar-rotation guard before core accepts the footprint; cover packing and verification with the tilted fixture.
  • P2 — packages/core/src/agent-operations/item-space.ts:198: itemHosts adds parent.id to hosts but never checks membership before following parentId. For procedural parents A → B → A, neither the loop condition nor the repeated Set.add stops traversal. Fix: break on an already-visited ID and test a two-node cycle.
  • P2 — packages/core/src/agent-operations/furniture-kind.ts:173: Catalog role matching previously used read(item.asset); it now uses the asset ID with node.name ?? node.asset.name. For a generic-category chair with an opaque asset ID, renaming the instance from “Dining chair” to “A” removes the seat match and its dining-table clearance exemption. Fix: pass node.asset to read for catalog items and test that an instance rename preserves the result.
  • P3 — packages/core/src/agent-operations/door-clearance.ts:419: Inspection already has evaluated, but calls proceduralNodePlanAabb(node), whose corner helper calls evaluateRecipe again. The collision pass also evaluates the recipe separately for the footprint and height interval. Fix: pass evaluated bounds into projection and reuse each node’s evaluation within the check.

P0/P1: 2. Those need fixing before this can land. CI hasn't run on this fork PR yet because it needs a maintainer to approve the workflow run; it merges once that's green.

@kruschdev
kruschdev force-pushed the fix/procedural-item-collisions branch from bd0c21d to 71a9220 Compare December 3, 2026 04:39
@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the architectural guidance from #1350. I rebased onto main (3b31a48) and pushed ee7b870 + 71a9220 addressing every finding:

  • Canonical nodeLevelFrame pose resolution + cycle safety: Replaced the hand-rolled stepThroughHostChain in packages/core/src/agent-operations/item-space.ts with nodeLevelFrame(..., { planOnly: true, cache }) from ../procedural-items/world-pose (handling orphan roots and NaN Y conservatively), added a seen cycle guard to itemHosts, and replaced the bounded depth < 16 host walks in layout-clearance.ts with cycle-safe seen sets tracking both map keys and node IDs.
  • Named-attachment overlap check (P1): Replaced the unconditional named-attachment continue in layout-clearance.ts with namedAttachmentSurfaceLevelY + STACK_TOLERANCE so penetrating attached items still report collisions.
  • Swept reach plan bounds + perimeter corner winding (P1): Updated proceduralNodePlanCorners in door-clearance.ts to project evaluated.reach ?? evaluated X/Z bounds and emit corners in non-self-intersecting perimeter winding order (instead of bowtie order) for boxSolid / polygon boolean intersection.
  • Tilted guard, renamed catalog assets, wallId inspection, and per-pass caching (P2/P3): Added the planarRotation guard for procedural-item in collectOccupiedFootprints, passed node.asset directly in furniture-kind.ts so instance renames preserve designedTogether, aligned inspectProceduralItemPlanFootprint to reject wallId and non-floor mounting.attachTo, guarded node.recipe?.name in packages/mcp/src/tools/check-collisions.ts, and threaded per-pass evalCache + frameCache across collision checks.

Added 7 regression tests covering named-attachment penetration, spinning ceiling fan swept X/Z bounds, tilted procedural items, host cycles, renamed catalog chairs, non-bowtie corner winding, and wallId inspection. Verified green with bun run check-types (14/14) and bun test packages/core/src/agent-operations/layout-clearance.test.ts packages/mcp/src/tools/check-collisions.test.ts (75/75 pass).

@Aymericr Aymericr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[Maintainer] Thanks @kruschdev — I re-reviewed 71a92208. The earlier findings at bd0c21de are fixed: named-attachment penetration now uses STACK_TOLERANCE, plan corners project evaluated.reach, tilted items are dropped from footprints, itemHosts is cycle-safe, catalog role matching reads node.asset, and evaluations are reused through evalCache / preEvaluated. GitHub Actions and a local CI run (install, lint, i18n, types, test, build, smoke, mcp, viewer-live) are green at this head. Cursor Bugbot also reported no issues.

One remaining P1 is blocking:

  • P1 — packages/core/src/agent-operations/layout-clearance.ts:857-861: After the child’s bottom clears the named support surface, the pair is skipped entirely. That is correct for a lamp on a tabletop (the surface is the host’s top, so the ordinary stack check would also waive it). It is wrong for a mid-height surface: a 60 cm vase attached to a bookcase shelf with only a 40 cm opening still produces no collision, even though it intersects the next board. Please waive contact with the supporting surface only, and still test the child against host parts that extend above it. Add a fixture with a short vase that fits and a too-tall vase that must report overlap.

Non-blocking follow-ups, not required for this merge:

  • itemVerticalInterval still resolves script manifest bounds only for direct level or ceiling parents (layout-clearance.ts:407-413, fallback at :619). hostedToLevel already walks procedural hosts; wiring it into the height path would catch a script lamp whose model extends below its attachment origin. The same gap already exists for catalog-item hosts.
  • findBlockedDoors is still catalog-item only (door-clearance.ts:717), unchanged from main.
  • Floor-standing recipes still have no motion reach (this PR expands reach to ceiling designs only).
  • The 16-step spin sampler can miss about 4 mm between samples on the fan fixture.
  • Core planarRotation requires exact 0 pitch/roll; MCP inspection allows 1e-6.
  • Ground lift is sampled at the footprint center; the renderer uses the node origin.
  • Elected slab support uses bare elevation, not floorFinishTopAt (same catalog limitation).
  • The renamed-chair test filters on issue.code, but LayoutIssue exposes type, so the assertion would pass even if the exemption broke.

Please address the P1 and I will approve and merge.

Comment on lines +856 to +861
if (
supportY !== undefined &&
attachedChildToHost.childY !== undefined &&
attachedChildToHost.childY.min >= supportY - STACK_TOLERANCE
) {
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P1: this waives the child against the entire host once childY.min clears the named surface. That hides a too-tall object on a mid-height shelf (for example a 60 cm vase in a 40 cm opening) that still intersects boards above the support. Waive contact with the supporting surface only, and still test the child against host parts that extend above it. Please add a short-vase / too-tall-vase fixture.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for running CI. I pushed a77b31b to fix the blocking P1 (plus the issue.type assertion bug in the renamed-chair test):

  • Waive only the named supporting surface (packages/core/src/agent-operations/layout-clearance.ts): Once an attached child clears supportY - STACK_TOLERANCE, hostPartsAboveSurfaceSolids projects every host EvaluatedShape extending above supportY + 1e-3 (using oriented boxCorners + convexHull2D for non-ellipsoids) that vertically overlaps the child (1 mm grazing tolerance under upper boards), and runs relateSolids(..., { stack: 0, minArea: MIN_OVERLAP_AREA }) so thin upper shelf boards (18 to 20 mm) and side/back panels still report overlap while normal contact with the supporting shelf is waived. Also added convexHull2D in boxSolid (with a < 3 vertex guard) so catalog itemNodePlanCorners always builds a simple convex polygon for relateSolids.
  • Bookcase & renamed-chair tests (packages/core/src/agent-operations/layout-clearance.test.ts): Added a rotated bookcase fixture (40 cm opening, 2 cm upper shelf board, side and back panels) verifying that a short 30 cm vase fits cleanly while a 60 cm vase, a vase shifted into a side panel, and an elevated vase slicing the bottom 15 mm of the upper shelf board all report overlap. Updated hangingShelfRecipe to use an open deck with end suspension rods, and changed the renamed-chair filter from issue.code to issue.type.

Verified green locally with bun run check-types (14/14) and bun test packages/core/src/agent-operations/layout-clearance.test.ts packages/mcp/src/tools/check-collisions.test.ts (76/76 pass).

@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 1 potential issue.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit a77b31b. Configure here.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Pushed 5fdc85c to fix the Bugbot finding on planarRotation:

  • Exported a shared PLANAR_ROTATION_EPSILON = 1e-6 from packages/core/src/agent-operations/door-clearance.ts and reused it in packages/core/src/agent-operations/layout-clearance.ts so collectOccupiedFootprints, proceduralHeightsInLevel, and inspectProceduralItemPlanFootprint use the exact same 1e-6 tolerance and 3-tuple rotation validation.
  • Added a regression assertion in packages/core/src/agent-operations/layout-clearance.test.ts verifying that near-zero Euler round-trip tilt ([1e-9, 0, -1e-9]) remains included in collectOccupiedFootprints and findItemItemCollisions.

Verified green locally with bun run check-types (14/14) and bun test packages/core/src/agent-operations/layout-clearance.test.ts packages/mcp/src/tools/check-collisions.test.ts (76/76 pass).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] check_collisions and verify_scene silently ignore overlapping procedural-item nodes

2 participants