← Back to Pull requests

fix(render-core): harden template deserialization for floats and isolate scene inheritance #53

Closed
unknown closed this pull request without merging on Oct 16, 2026 15:21 UTC
View on GitHub
unknown unknown commented on Oct 13, 2026 21:03 UTC
Author

## Summary
Hardens template deserialization for coordinates and dimensions across all element types so floating-point numbers parse cleanly (rounded to the nearest integer) with range and finiteness checks, adds load-time migration for legacy box elements omitting explicit width and height, and isolates scene inheritance to styling attributes.

Note on TODOS.md P0: The pre-existing test render::frame::tests::layer_order_honors_explicit_ids_then_array_order was verified passing on main. This PR addresses the broader schema vulnerability by ensuring that floating-point numbers produced by hand-editing or AI prompt generators do not cause serde deserialization failures.

Key Changes


1. Visitor-based flexible numeric deserialization: Replaced untagged enum deserialization with zero-buffering Visitor implementations (FlexibleI32Visitor and FlexibleU32Visitor) and typed newtype wrappers (FlexibleI32, FlexibleU32). Out-of-range floats and invalid types produce clean, precise deserialization errors.
2. Backward-compatible dimension migration: Added load-time migration migrate_legacy_element_dimensions in Template::from_value_scaled. Any legacy box element (rect, plot, meter, gauge, image) lacking explicit width or height inherits them from the scene canvas, ensuring older saved and AI-generated templates (like full-canvas background rects) load without error.
3. Targeted scene inheritance: Restricted merge_scene_into_item to inheritable styling attributes (font, color, opacity, font_size, decimal_rounding). Prevents leaking scene-only metadata (start, end, layers, groups, vars, fps, lap_gate) into element configs.
4. Comprehensive test coverage:
- template_parses_with_float_dimensions_and_coordinates: Expanded to assert on all element types (label, value, plot, meter, rect, gauge, image).
- scene_inheritance_does_not_leak_scene_metadata: Hardened to assert directly on raw JSON values, proving that scene metadata does not leak into child elements.
- legacy_element_without_dimensions_migrates_scene_dimensions: Verifies that box elements without explicit dimensions inherit scene canvas dimensions.
- lap_gate_flexible_total_laps_deserializes: Verifies flexible float parsing for LapGateConfig.total_laps.
- out_of_range_float_fails_deserialization: Verifies that out-of-range floats fail deserialization with descriptive errors.

Verification


  • Prettier check: passed.

  • ESLint: passed cleanly with 0 errors.

  • Vite build: passed in 7.41s.
  • Diff: 320 lines (+240 / -80) across 4 files Reviewer: walkersutton Review duration: 3977m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 320 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.345
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #53"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 41.9% (MEDIUM) · Higher = larger blast radius
    41.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.6% · Safe to merge
    16.6%