Skip to content

Conversation

@lucbrinkman
Copy link
Owner

Summary

Fixed two critical probability slider bugs:

Bug 1: Setting a slider to 0% displayed correctly on arrows but calculated as 50% downstream

  • Cause: || operator treated 0 as falsy, falling back to 50
  • Fix: Changed to ?? (nullish coalescing) to only fall back on null/undefined

Bug 2: Upgrading intermediate nodes to question nodes - slider affected arrows but not downstream calculations

  • Cause: Array-based indexing used questionNodeIndices.indexOf() which found wrong position when node indices didn't align with slider indices
  • Fix: Replaced with Map<string, number> keyed by node ID for direct O(1) lookups

Changes

  • Replace sliderProbs array with Map<string, number> keyed by node ID
  • Remove buggy questionNodeIndices.indexOf() lookup
  • Use direct map lookup: nodeIdToProb.get(sourceNode.id)
  • Fix falsy value bug: ||??
  • Keep sliderIndex field for sidebar visual sorting only (no longer used in calculations)

Test Plan

  • Set slider to 0% - downstream nodes correctly show 0% (not 50%)
  • Set slider to 100% - downstream nodes correctly show 100%
  • Upgrade intermediate node to question - slider immediately affects downstream
  • Dev server compiles without errors

🤖 Generated with Claude Code

Fixed two related bugs:
1. Setting slider to 0% displayed correctly on arrows but calculated as 50% downstream
2. Upgrading intermediate nodes to question nodes didn't affect downstream calculations

Root cause: Array-based slider indexing was using questionNodeIndices.indexOf()
which found the wrong position when node indices didn't align with slider indices.

Changes:
- Replace sliderProbs array with Map<string, number> keyed by node ID
- Remove buggy questionNodeIndices.indexOf() lookup
- Use direct map lookup: nodeIdToProb.get(sourceNode.id)
- Fix falsy value bug: change || to ?? so 0 is treated as valid value
- Keep sliderIndex field for sidebar visual sorting only

Both bugs now resolved and tested.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@vercel
Copy link

vercel bot commented Nov 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
ai-world-model Ready Ready Preview Comment Nov 21, 2025 8:07pm

Resolved conflict in lib/probability.ts:
- Keep renamed EdgeType.ALWAYS from main
- Keep new Map-based lookup logic from bug fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@lucbrinkman lucbrinkman merged commit d29d949 into main Nov 21, 2025
4 checks passed
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.

2 participants