Skip to content

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

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

kruschdev wants to merge 14 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
Broad changes to shared layout-clearance and height resolution used by furnish, verify, and MCP; behavior is conservative but regressions could affect placement validation across mixed procedural/catalog scenes.

Overview
Floor-standing procedural-item nodes now participate in the same plan footprint, overlap, clearance, and door-blocking checks as catalog item nodes, fixing silent passes when two procedural blocks overlapped or when MCP check_collisions returned empty results.

Core adds recipe-evaluated plan corners/AABBs (proceduralNodePlanCorners, inspectProceduralItemPlanFootprint) and level poses via nodeLevelFrame, including off-center datums, ceiling mounts, and motion reach sweeps. collectOccupiedFootprints / findItemItemCollisions / verify_scene paths pick up procedural footprints, vertical intervals, rug underlays, designedTogether dining pairs, named attachment stacking (with host-part overlap above shelves), and stricter rules when script heights are unknown (e.g. animated items at doors).

MCP check_collisions inspects and reports procedural nodes (catalog: "procedural") and records skip reasons (unsupported_attachment, non_planar_rotation, etc.) instead of ignoring them.

Reviewed by Cursor Bugbot for commit e8b192b. 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).

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

Review at 5fdc85c6, run with Codex (gpt-6.2-astra) over two rounds: a full review, then each finding re-checked against the code. Only the verified blocker is requested below.

The two latest fixes check out:

  • a77b31bf: a child whose bottom clears the named support is no longer skipped against the whole host. The bookcase fixture covers a short 30 cm vase that fits the 40 cm bay, a 60 cm vase that hits the shelf above, a side-panel hit, and a vase that slices the upper board.
  • 5fdc85c6: planarRotation now uses the shared PLANAR_ROTATION_EPSILON (1e-6). Near-zero Euler tilt stays in the collision pass; a 0.2 rad tilt is still skipped.

P1 — packages/core/src/agent-operations/layout-clearance.ts (scriptItemBoundsInLevel / itemHeightsInLevel): A script-backed catalog item attached to a procedural host still cannot use the manifest-height resolver, which only accepts a level or ceiling parent. The fallback, itemLevelHeightRange, treats the node origin as the model bottom and uses catalog height. With identity asset corrections and manifest bounds from −0.20 m to +0.10 m, a lamp at local Y = 0 on the bookcase mid-shelf occupies Y = 0.22–0.52 m and passes through the 0.40–0.42 m board, but the fallback puts its bottom at 0.42 m, so the support check waives the board and reports no overlap. Transform the manifest corners through the corrective asset pose, attachment frame, and host floor lift before deciding that the child is resting on the surface (and before waiving that surface).

Non-blocking follow-ups: the new host-part check extrudes each part as a prism, so a diagonal brace can false-overlap a vase it only crosses above; MIN_OVERLAP_AREA (0.001 m²) can hide a complete hit on a 20×20 mm upright; only a direct attached child gets the shelf-part check (a small item sitting on the vase false-overlaps the whole bookcase box); catalog itemLevelHeightRange still requires exactly zero pitch/roll, so a 1e-7 tilt loses the height interval and falls back to the whole-host box; procedural ground sampling still uses the footprint center rather than the node origin.

Not merging at this head.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for re-running CI. I pushed 46ce24e to fix the P1 for hosted script-backed items:

  • Hosted manifest bounds resolution (packages/core/src/agent-operations/layout-clearance.ts): Extracted a shared scriptItemLevelFrame helper used by scriptItemBoundsInLevel, scriptItemToLevel, itemVerticalInterval, and itemSolidsInLevel (replacing the duplicate hostedToLevel path). For script-backed items hosted under an item or procedural-item chain, it walks the host chain with cycle, disallowed-mount, and finiteNumbers guards, composes the full pose through nodeLevelFrame(..., { planOnly: true }) (including named procedural attachment frames), adds resolveHostChainBaseElevation(root, nodes).baseY, and transforms the 8 manifest corners through asset.scale, asset.rotation, asset.offset, node.scale, and the composed level frame.
  • No catalog-height fallback for script items (itemHeightsInLevel): Script-backed items (node.source present) now rely solely on itemVerticalInterval so malformed or animated script manifests cannot fall back to itemLevelHeightRange and falsely waive host penetration. Also aligned itemLevelHeightRange in packages/core/src/agent-operations/item-space.ts to use PLANAR_ROTATION_EPSILON (1e-6).
  • Regression tests (packages/core/src/agent-operations/layout-clearance.test.ts): Added 5 bookcase + 5 cm floor-slab fixture cases covering the [-0.20, +0.10] mid-shelf lamp piercing the board (overlap), corrective asset.offset seating cleanly in the 40 cm bay (0 collisions), 2x vertical scale hitting the upper shelf board (overlap), animated script lamp refusing fallback waiver (overlap), and micro-tilted (1e-9) plain catalog item still fitting cleanly.

Verified locally with bun run check-types (14/14), bun test on door-clearance.test.ts, layout-clearance.test.ts, item-space.test.ts, and packages/mcp/src/tools/check-collisions.test.ts (98/98 pass, 312 assertions), and Biome.

@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] Re-reviewed at 46ce24eebdbd30927ed4d3d00b302879a3bb78b2 (the 5fdc85c6..46ce24ee delta, then the full PR) with Codex (gpt-6.2-astra) in two rounds. The second round re-traced every finding and reproduced it with in-memory probes on the merged tree. GitHub CI is green at this head (the viewer/ifc timing flake passed on rerun).

My earlier P1 is fixed. A script-backed item attached directly to a procedural shelf now takes its height from the manifest, composed through the host's named surface and frame, and no longer falls back to itemLevelHeightRange. I found no yaw-sign error, no double floor lift and no cycle loop, and the near-zero rotation tolerance is right. Thanks for the fast turnaround.

Three P1s remain on valid scenes. I reproduced each one.

  1. packages/core/src/agent-operations/layout-clearance.ts:985 (classification falls to :1075) — a nested item that fits inside a shelf bay is reported as colliding with the bookcase. The host-part check only recognizes a direct child. With a 4 cm tray on the middle shelf and a 20 cm script lamp on the tray, both fit below the next board, but gap: 0 returns a bookcase ↔ lamp collision, and verifyScene reports it too. Fix: walk from the descendant up to the child attached directly to this host, use that child's named surface, and test the descendant's bounds against the host parts above that surface. Don't blanket-exempt ancestors: a taller lamp must still hit the upper board. Add a tall-lamp control.
  2. layout-clearance.ts:323 and :295 — floor support disagrees with the renderer. :323 returns the bare slab elevation, but the renderer uses the finish top at the footprint point (hooks/spatial-grid/floor-placed-elevation.ts:112). With a 0.050 m slab and a 0.100 m finish the renderer's support is 0.151 m, but clearance used 0.050 m. The nested lamp was measured at [0.510, 0.710] instead of [0.611, 0.811], which hides 61 mm of overlap with a ceiling-hosted obstruction at 0.750 m. The ground fallback at :295 also samples the footprint center, where the renderer samples the node origin (floor-placed-elevation.ts:105). For an off-center recipe on sloping terrain I got 0.750 m instead of 0.500 m. Fix: keep the snapshot slab election, apply floorFinishTopAt at the elected point, and sample ground at the node origin. Add a test with a slab plus finish (the existing shelf test uses a bare slab).
  3. layout-clearance.ts:860 and :1031 — the named-attachment check ignores moving host parts. Each shape is tested at rest and the pair is then waived. A ceiling-mounted host with a panel that slides 0.28 m into its attached item passed relation validation, and verifyScene returned valid: true with no overlap. Placing the same panel at its travel endpoint reports the overlap. Fix: use per-part swept bounds for moving parts, or fall back conservatively to the host's swept bounds when rest geometry can't prove separation.

P2

  • door-clearance.ts:731 — a supplied height resolver that returns null (unknown) is turned back into itemLevelHeightRange, so an animated script can dodge a blocked-door finding. Use the catalog range only when no resolver was supplied.
  • door-clearance.ts:223 and furniture-kind.ts:106 — node.source?.manifest.bounds throws if source exists without manifest. verifyScene rejects that scene first (schema_invalid), so it only hits raw callers, but please guard both accesses.
  • layout-clearance.ts:952 — boxSolid calls itemLevelPose without the built record or frame cache, which copies the whole node map per lookup (item-space.ts:82). Pass { nodes, frameCache } and memoize box solids by ID.

P3: the cycle test at layout-clearance.test.ts:1898 only calls itemHosts; assert on the collision and script-bounds entry points as well, and add a rotated two-hop fixture with nonzero X/Z offsets. MCP check_collisions still skips non-level parents (mcp/src/tools/check-collisions.ts:262), so the hosted fix only helps scene verification.

Once these three are fixed with tests I'll re-review quickly. I'm not pushing to your fork.

@kruschdev

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough re-review and the concrete probes. I pushed b8c98ce and e8b192b addressing all three P1s, all three P2s, the P3 test coverage, and a full-PR audit sweep:

  • P1 Feat/builder modes #1 (nested descendants on procedural hosts, packages/core/src/agent-operations/layout-clearance.ts): Replaced the direct-child-only check with attachedSurfaceOnHost, which walks up item and procedural-item ancestors (with cycle and Object.hasOwn guards) to find the child attached directly to the procedural host and tests the descendant's own bounds against host parts above that surface. Added a rotated two-hop fixture (bookcase -> 4 cm tray -> 20 cm script lamp with nonzero X/Z offsets) confirming findItemItemCollisions and verifyScene stay clear, plus a 45 cm tall-lamp control that still reports overlap against the upper shelf board.
  • P1 Feat/import and manipulate image scans #2 (floor finish top & node-origin ground sampling, electFloorPlacedLift): Applied floorFinishTopAt(nodes, levelId, support.id, footprint.position[0], footprint.position[2]) ?? support.elevation on elected slabs and switched the ground fallback to sample levelBaseElevationAt at node.position[0], node.position[2] to match floor-placed-elevation.ts. Added tests with a 0.050 m slab + 0.100 m floor finish script (0.151 m support catching a ceiling obstruction at 0.750 m) and an off-center recipe on sloping terrain verifying origin sampling.
  • P1 Feat/cc and levels #3 (moving host parts in hostPartsAboveSurfaceSolids): Shapes carrying a motionGroup now compute per-shape swept bounds through jointReach(evaluated.motions, [shape], shapeBounds) (failing closed to null if motion bounds cannot be resolved) and project the swept bounds through the host's level pose. Added a ceiling-mounted host test with a panel sliding +0.28 m into its attached item (overlap in both findItemItemCollisions and verifyScene) and a -0.28 m away control (0 collisions).
  • P2s, P3s & full-PR hardening: Preserved explicit null returns from args.heightsOf in packages/core/src/agent-operations/door-clearance.ts (falling back to itemLevelHeightRange only when no resolver was supplied), guarded node.source?.manifest?.bounds in door-clearance.ts and furniture-kind.ts, enforced 3-tuple rotation + PLANAR_ROTATION_EPSILON + finite swept effectiveDimensions in inspectProceduralItemPlanFootprint, rejected self-tilted procedural items in resolvePlanLevelPose, passed { nodes, frameCache } to itemLevelPose and memoized boxSolid by ID in layout-clearance.ts, hardened prototype-chain lookups and roof/block floorOnly guards, and expanded the parent-cycle test across itemHosts, findItemItemCollisions, itemHeightsInLevel, and scriptItemBoundsInLevel.

Verified locally with bun run check-types (14/14), bun test across door-clearance.test.ts, layout-clearance.test.ts, item-space.test.ts, and packages/mcp/src/tools/check-collisions.test.ts (102/102 pass, 338 assertions), and Biome.

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

Re-review at e8b192b4 (previous review was at 46ce24ee). Thanks @kruschdev: all three original P1s are fixed, and so are the P2s. One new P1 remains, and it comes from the nested-attachment fix. I'd like that closed before merge.

What I checked. I ran two Codex rounds on the 46ce24ee..e8b192b4 diff and the full PR. The second round verified every finding against the code with in-memory probes. I also ran the full local CI: install, lint, i18n, skills, types, test, build, render-bundle, smoke, mcp and viewer-live all pass. GitHub CI is green at this head (9/9), so the only blocker is the one below.

Original P1s: fixed

  • Nested shelf item: the 20 cm lamp on the 4 cm tray is now clear in both findItemItemCollisions and verifyScene. The 45 cm control still hits the upper board. The old code reported bookcase↔lamp at gap 0.
  • Floor support: the nested lamp now sits at [0.611, 0.811] m, not [0.510, 0.710] m, so it hits the 0.750 m obstruction. The off-centre sloping-terrain probe is 0.500 m, sampled at the node origin, as the renderer does.
  • Moving host part: the +0.28 m sliding panel now reports the same overlap as its frozen endpoint, including item_overlap in verifyScene. The −0.28 m control stays clear.

P2s: fixed

  • A null height resolver no longer falls back to the catalog range.
  • source: {} without a manifest no longer throws (door-clearance.ts, furniture-kind.ts).
  • boxSolid no longer copies the node map per lookup.

P3: satisfied. Production-entry cycle tests and the rotated two-hop fixture are in. Note that they also pass on the old code, so they pin existing behaviour rather than a fixed defect.

Blocker (P1, new regression): a moving descendant of a named-attachment surface passes through the host

Repro, reproduced at e8b192b4 and confirmed by the second round:

  • Fixture: bookcase → 4 cm tray on the middle shelf, with a procedural riser child that slides 0.31 m upward through the board above.
  • At e8b192b4, findItemItemCollisions(gap: 0) returns [] and verifyScene returns valid: true, issues: [].
  • With the riser frozen at its +0.31 m endpoint, the same code reports bookcase↔riser, a 0.006 m² overlap.
  • 46ce24ee reported the pair in both cases. That was only because the coarse host box covered the whole thing, not because it detected the motion. So the pair was flagged, and now it is silently cleared.

Why: the new above-the-surface test sweeps the host's parts but uses the child's rest height. childY comes from the rest evaluation (layout-clearance.ts ~738), the upper board is then dropped by the childY.max <= y0 + 1e-3 skip (~902), and the pair is waived when aboveSolids.length === 0 (~1093). The named shelf permits contact with the support surface, not penetration of the board above it. It is agent-reachable too: three place_design-accepted v1 designs with a procedural tray with a named top reproduce it, and verifyScene misses the overlap.

Fix: before waiving the pair, take the descendant's swept bounds (Y and X/Z, the same sweep you already apply to host parts) and use them for childY and the solids test. If separation can't be proved, keep the conservative collision. Add a regression next to the short-lamp fit control: a riser sliding +0.31 m must report the collision, and a riser sliding −0.31 m or one that stays under the board must stay clear. Please check that the new test fails on e8b192b4.

Non-blocking follow-ups (P2/P3, fine as a follow-up PR)

  • P2, MCP floorOnly disagrees with core. A level-parented item with roofSegmentId is checked by check_collisions({floorOnly:true}) and reports an overlap with floor furniture. Core excludes it. MCP uses the narrower guard at packages/mcp/src/tools/check-collisions.ts ~263–275, compared with layout-clearance.ts:184 and door-clearance.ts ~250. Share the host guard and report unsupported_attachment.
  • P2, perf. The ancestry helper runs before spatial rejection (layout-clearance.ts ~1049, with a Set allocated per call at ~1019). For 1,000 disjoint procedural items it is called 999,000 times. findItemItemCollisions median is 70 → 134 ms at 1,000 all-procedural items and 16 → 19 ms at 200. Precompute named ancestors per footprint, or reject on bounds first.
  • P2, pre-existing and also present at 46ce24ee. A spinning ceiling-fan blade is sampled in 16 steps (recipe.ts ~1315, door-clearance.ts ~349). With initial yaw π/16 the swept maxX is 1.7674 m against a true 1.800 m, so a cabinet starting at 1.780 m is missed at gap 0. Use analytic extrema or a conservative envelope. This is not a blocker for this PR.
  • P3. The rotation tolerance differs between item-space.ts:58 and door-clearance.ts:243. At 5e-6 rad, proceduralItemLevelPose returns a pose but collection rejects the item. I found no production collision disagreement.

Once the swept-descendant fix and its regression test land, this is an approve from me.

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