Skip to content

feat: cinematic demo, adaptive gates, crash-map HNSW, training defaults#6

Merged
shaal merged 2 commits into
mainfrom
feat/demo-presentation-adaptive-gates-crash-hnsw
Jul 23, 2026
Merged

feat: cinematic demo, adaptive gates, crash-map HNSW, training defaults#6
shaal merged 2 commits into
mainfrom
feat/demo-presentation-adaptive-gates-crash-hnsw

Conversation

@shaal

@shaal shaal commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

Makes the VectorVroom demo more watchable and more effective at training: cinematic presentation, crash-aware adaptive checkpoints, crash-map HNSW memory, a cleaner Triangle track, and survival-oriented default knobs.

Cinematic presentation (demoPresentation.js)

  • On-canvas cinema HUD: gen, alive, best fitness, laps, sim speed + story line
  • Follow best camera (button / F)
  • Motion trails, rank-colored Top-K swarm, champion glow + sensors
  • Crash heat visualization (button / H) — death deposits over the track
  • Optional 3D orbital view (button / 3 / ?view=3d) of the same 2D sim (instanced-style projected cars + extruded walls)
  • Demo mode (button / D / ?demo=1) guided cinematic path
  • Road cache blit during training (perf) via roadEditor.paintTo()
  • Overlay controls + styles; wired from main.js animate / genEnd

Triangle track

  • Clean symmetric apex-left triangle (blunted inner tip, spacious right lobe)
  • Full-loop 9 ordered green gates (spawn → apex approach/exit → return)
  • Angled corner gates; hand-tuned apex cluster from editor sessions
  • Preset updated in trackPresets.js

Training defaults (survive + learn + archive)

Knob Before After
Batch size N 10 500
Round length 15s 20s
Variance 0.30 0.22
Conservative init 0 0.65
Sim speed (honest fitness)
  • Worker now receives simSpeed + pause on each begin() (defaults actually apply)
  • Presets Fresh / Grind / Polish retuned; also set conservative init
  • Ruvector dynamics key default ON (no-op until trajectories exist)
  • Demo mode aligns with Fresh + mild spectacle settings

Adaptive green gates (opt-in)

UI: 🧪 Experiments → Adaptive green gates · URL: ?adaptGates=1

  • Per-gen pass-rate bottleneck detection
  • Nudge hard gates toward previous success / spawn (capped drift)
  • Add intermediate gates on severe cliffs; remove near-redundant mids
  • Safety rails: min 4 gates, max baseline+2, protect first/last, topo cooldown, survival regression → restore baseline
  • Track-keyed layout memory + Reset gates

Crash heat → curriculum + HNSW

  • Worker records death (x,y) (popDeathXY on genEnd)
  • Adaptive gates aim nudges/inserts using crash centroids (same events as Heat)
  • Crash-map codec: 16×9 log1p grid → 144-d L2 vector (crashMapCodec.js)
  • Ruvector HNSW index for crash maps (IDB v4 crash_maps store):
    • encodeCrashMap / archiveCrashMap / recommendCrashLayouts
    • Retrieve similar crash problems and apply better-surviving gate layouts
  • Passive archive of crash maps even when adaptive is off (index fills while training)

Other fixes / wiring

  • roadEditor.paintTo / drawLinesOn for offscreen road cache
  • Phase-4 slider paint uses nextSeconds correctly; sim-speed select matches default 2×
  • Cinema + experiments CSS (HUD, control chips, adaptive status)

How to try

# from repo root
python3 -m http.server 8765
  • Demo: http://127.0.0.1:8765/AI-Car-Racer/index.html?demo=1
  • 3D: ?view=3d&follow=1
  • Adaptive + crash HNSW: enable 🧪 Adaptive green gates (or ?adaptGates=1), train a few gens, watch status for bottleneck / hnsw: applied layout…
  • Console: window.__rvBridge.info().crashMaps

Test plan

  • Hard-refresh; phase 4 shows N=500, 2×, 20s, cons-init ~0.65 (unless localStorage overrides cons-init)
  • Start training: swarm, champion, HUD update; worker runs at 2× without touching the dropdown
  • Toggle Follow / 3D / Trails / Heat / Demo; no console errors
  • Load preset Triangle: 9 gates, symmetric walls, spawn heading up
  • Enable Adaptive green gates; after 1–2 gens status shows bottleneck / nudge or crash heat
  • After several gens with deaths: info().crashMaps.count > 0; later gens may show HNSW layout apply
  • Reset gates restores baseline layout
  • ?rv=0 still trains (crash passive archive skipped when rv disabled path respected)
  • Smoke: open with ?adaptGates=1&view=3d — Experiments open, adaptive on

Summary by CodeRabbit

  • New Features

    • Added a cinematic presentation layer with 2D/3D rendering, camera follow, motion trails, crash heatmaps, HUD stats, and guided demo mode.
    • Introduced Adaptive Green Gates (performance- and crash-pattern–aware) with reset-to-baseline and per-track integration.
    • Added crash-map encoding, storage, and crash-layout recommendations.
  • Improvements

    • Updated the Triangle track to use a new 9-checkpoint gate sequence.
    • Enhanced training presets (including conservative initialization) and default simulation speed to 2×.
    • Improved road rendering/caching and track-edit refresh behavior; added crash-location reporting.

Improve the training demo so learning is more legible, cars survive more
often, and checkpoint curriculum can adapt from pass rates and crash heat.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e1cd569a-98b3-4cf8-a886-f5ad5b25ff61

📥 Commits

Reviewing files that changed from the base of the PR and between da6af78 and 1f606ae.

📒 Files selected for processing (4)
  • AI-Car-Racer/adaptiveGates.js
  • AI-Car-Racer/main.js
  • AI-Car-Racer/ruvectorBridge.js
  • AI-Car-Racer/trackPresets.js

📝 Walkthrough

Walkthrough

This PR adds adaptive checkpoint gates backed by crash-map retrieval and persistence, a cinematic 2D/3D presentation layer, expanded crash telemetry, revised training defaults and presets, new track geometry, and UI controls for adaptive gates and demo mode.

Changes

Adaptive training and presentation

Layer / File(s) Summary
Crash-map encoding and persistence
AI-Car-Racer/crashMapCodec.js, AI-Car-Racer/sim-worker.js, AI-Car-Racer/ruvectorBridge.js
Crash positions and causes are encoded into normalized vectors, transferred at generation end, indexed for similarity retrieval, and persisted in IndexedDB.
Generation-driven gate adaptation
AI-Car-Racer/adaptiveGates.js, AI-Car-Racer/main.js
AdaptiveGates analyzes reach rates and crash centroids, applies gate insertion, removal, nudging, retrieval, baseline restoration, and local best-layout persistence.
Cinematic rendering pipeline
AI-Car-Racer/demoPresentation.js, AI-Car-Racer/roadEditor.js, AI-Car-Racer/main.js, AI-Car-Racer/style.css
Rendering gains road caching, camera following, 3D projection, heatmaps, trails, swarm/champion visuals, HUD updates, and demo sequencing.
Training, track, and UI integration
AI-Car-Racer/index.html, AI-Car-Racer/buttonResponse.js, AI-Car-Racer/trackPresets.js, AI-Car-Racer/uiPanels.js, AI-Car-Racer/utils.js
New scripts, defaults, presets, Triangle checkpoints, adaptive-gate controls, demo controls, and track-cache invalidation are wired into the application.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Worker
  participant Main
  participant AdaptiveGates
  participant CrashMapBridge
  participant Canvas
  Worker->>Main: generation results and crash coordinates
  Main->>AdaptiveGates: onGenEnd(genData)
  AdaptiveGates->>CrashMapBridge: archive and query crash layouts
  CrashMapBridge-->>AdaptiveGates: recommended gate layout
  AdaptiveGates->>Main: apply updated checkpoints
  Main->>Canvas: render cached road, swarm, and champion
Loading

Possibly related PRs

  • shaal/VrumVector#2: Both changes restructure or extend the Experiments UI in uiPanels.js and its related styling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 additions: cinematic demo, adaptive gates, crash-map search, and training default updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/demo-presentation-adaptive-gates-crash-hnsw

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.

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
AI-Car-Racer/demoPresentation.js (1)

704-711: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Redundant drawHeatmap/drawTrail in the 3D branch.

Both branches are identical, and in the 3D path beginFrame already painted the heatmap and trail (Lines 870–871) before drawSwarm runs. Re-drawing them here double-blends the semi-transparent overlays in 3D (denser heat/brighter trails than 2D) and re-scans the full 160×90 heat grid an extra time each frame. Consider drawing heat/trail once per frame for both view modes.

♻️ Collapse identical branches
-    if (!state.view3d) {
-      drawHeatmap(ctx);
-      drawTrail(ctx);
-    } else {
-      // Refresh trail/heat under the latest poses (road already drawn).
-      drawHeatmap(ctx);
-      drawTrail(ctx);
-    }
+    // 2D: paint under the cars/camera. 3D already drew them in beginFrame.
+    if (!state.view3d) {
+      drawHeatmap(ctx);
+      drawTrail(ctx);
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@AI-Car-Racer/demoPresentation.js` around lines 704 - 711, Remove the
redundant conditional around drawHeatmap and drawTrail in the frame-rendering
flow, leaving a single invocation of each for both 2D and 3D modes. Preserve the
existing beginFrame behavior so 3D overlays are not drawn a second time, while
keeping the 2D rendering order unchanged.
AI-Car-Racer/uiPanels.js (1)

1813-1814: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Guard the adaptive-gate status poll interval from duplicates.

setInterval(refreshAdaptStatus, 1500) is never cleared, and the experiments details is appended from one build path that later survives re-parenting moves. If this path can run more than once, each run adds another 1500ms poller. Store/fall back to a single interval id, or move the poll to a true one-time registration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@AI-Car-Racer/uiPanels.js` around lines 1813 - 1814, Update the interval setup
near refreshAdaptStatus so repeated executions of the panel build path reuse a
single poller instead of creating additional 1500ms intervals. Store the
interval identifier in a persistent scope, guard registration when one already
exists, and preserve the existing status-refresh behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@AI-Car-Racer/ruvectorBridge.js`:
- Line 573: Update archiveCrashMap around the meta.cps assignment to deep-clone
the cps array before storing it in m.cps, rather than retaining the caller’s
array reference. Preserve the existing Array.isArray guard and ensure nested
checkpoint data is independently copied so later mutations cannot alter the
archived layout.

---

Nitpick comments:
In `@AI-Car-Racer/demoPresentation.js`:
- Around line 704-711: Remove the redundant conditional around drawHeatmap and
drawTrail in the frame-rendering flow, leaving a single invocation of each for
both 2D and 3D modes. Preserve the existing beginFrame behavior so 3D overlays
are not drawn a second time, while keeping the 2D rendering order unchanged.

In `@AI-Car-Racer/uiPanels.js`:
- Around line 1813-1814: Update the interval setup near refreshAdaptStatus so
repeated executions of the panel build path reuse a single poller instead of
creating additional 1500ms intervals. Store the interval identifier in a
persistent scope, guard registration when one already exists, and preserve the
existing status-refresh behavior.
🪄 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 Plus

Run ID: 163797eb-b743-4e49-bed2-4f202d25234b

📥 Commits

Reviewing files that changed from the base of the PR and between ea1a317 and da6af78.

📒 Files selected for processing (13)
  • AI-Car-Racer/adaptiveGates.js
  • AI-Car-Racer/buttonResponse.js
  • AI-Car-Racer/crashMapCodec.js
  • AI-Car-Racer/demoPresentation.js
  • AI-Car-Racer/index.html
  • AI-Car-Racer/main.js
  • AI-Car-Racer/roadEditor.js
  • AI-Car-Racer/ruvectorBridge.js
  • AI-Car-Racer/sim-worker.js
  • AI-Car-Racer/style.css
  • AI-Car-Racer/trackPresets.js
  • AI-Car-Racer/uiPanels.js
  • AI-Car-Racer/utils.js

nGates: (meta.nGates | 0),
timestamp: Date.now(),
};
if (Array.isArray(meta.cps)) m.cps = meta.cps;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Deep-clone meta.cps before storing to prevent later mutation corrupting the archived layout.

archiveCrashMap stores the caller's cps array by reference (the mirror only copies the vector via .slice()). main.js's passive archive path passes the live road.checkPointList (see main.js Lines 942), so any subsequent in-place edit/rebuild of that array before the debounced persist() fires would silently rewrite the crash-layout association. adaptiveGates.js sidesteps this by cloning at its call site; centralizing the copy here protects every caller.

🛡️ Proposed defensive copy
-  if (Array.isArray(meta.cps)) m.cps = meta.cps;
+  if (Array.isArray(meta.cps)) {
+    m.cps = meta.cps.map((seg) => [
+      { x: +seg[0].x, y: +seg[0].y },
+      { x: +seg[1].x, y: +seg[1].y },
+    ]);
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (Array.isArray(meta.cps)) m.cps = meta.cps;
if (Array.isArray(meta.cps)) {
m.cps = meta.cps.map((seg) => [
{ x: +seg[0].x, y: +seg[0].y },
{ x: +seg[1].x, y: +seg[1].y },
]);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@AI-Car-Racer/ruvectorBridge.js` at line 573, Update archiveCrashMap around
the meta.cps assignment to deep-clone the cps array before storing it in m.cps,
rather than retaining the caller’s array reference. Preserve the existing
Array.isArray guard and ensure nested checkpoint data is independently copied so
later mutations cannot alter the archived layout.

Stop Triangle green lines from sticking after loading Rectangle: notify
AdaptiveGates on preset load, key memory by wall geometry, and require
matching geometrySig before HNSW layout apply. Reset now recaptures the
current track when the baseline is stale.
@shaal
shaal merged commit 93da730 into main Jul 23, 2026
@shaal
shaal deleted the feat/demo-presentation-adaptive-gates-crash-hnsw branch July 23, 2026 21:40
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