H-5770, H-6115: Add PlaybackContext for real-time simulation playback and WebWorker#8295
Open
H-5770, H-6115: Add PlaybackContext for real-time simulation playback and WebWorker#8295
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Collaborator
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
a676139 to
2c55788
Compare
2c55788 to
558a7bb
Compare
558a7bb to
da55643
Compare
This was referenced Jan 27, 2026
da55643 to
1ea2c35
Compare
Remove Promise<void> union from play and setPlayMode function types, keeping only void returns for simpler synchronous API. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace async arrow functions with Promise.resolve for mock accessors - Use globalThis instead of self in web worker - Use underscore prefix for intentionally unused simulation variables - Fix dot notation for property access in tests - Remove unnecessary void operator and conditional - Remove constructor return statement in mock Worker class Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…mulationInstance definitions - Removed redundant SimulationInstance definitions from test cases. - Simplified tests by directly using SimulationFrame instances. - Improved readability and maintainability of the test suite. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Place instances are now accessed via SimulationInstance.places Map instead of being duplicated in each frame's place state. Functions that need Place data now look it up from simulation.places.get(placeId). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rewrite simulation/worker/README.md with worker states, messages, and hook docs - Add simulation/simulator/README.md explaining types and computation flow - Add simulation/README.md documenting SimulationProvider context - Add playback/README.md documenting PlaybackContext Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…igurable
- Move maxTime from worker state to SimulationInstance (immutable once set)
- Check maxTime in computeNextFrame instead of worker
- Add SimulationCompletionReason type ("maxTime" | "deadlock")
- Make backpressure configurable via InitMessage (maxFramesAhead, batchSize)
- Add setBackpressure message for runtime reconfiguration
- Remove setMaxTime message from worker protocol
- Update READMEs with new architecture documentation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Increase timeout duration from 0 to 50 milliseconds to allow for better simulation initialization. - Add comments to clarify the need for improvement in handling simulation initialization completion. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove computeBufferDuration from SimulationContext and derive it from playMode in PlaybackProvider: - viewOnly: 0s (no buffering needed) - computeBuffer: 0.5s ahead - computeMax: 10s ahead (large buffer for continuous computation) This simplifies the API by making buffer duration an internal implementation detail of PlaybackProvider. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Simplify play(), setPlayMode(), and tick() by removing manual maxTime management. The backpressure mechanism via ack now handles all computation flow control automatically. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Make PlaybackProvider.play() the single entry point for starting playback/simulation. This consolidates initialization logic and ensures backpressure params are always passed correctly. Key changes: - Remove console.log debug statements - Replace fragile setTimeout(50) with state-based coordination - Remove duplicate initialization logic from simulation-controls - Remove unused COMPUTE_BUFFER_THRESHOLD constant Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- SimulationContext.initialize() now returns Promise<void> that resolves when worker is ready or rejects on error - PlaybackProvider.play() awaits initialize() before calling runSimulation() - Worker tracks simulationStatus (ready/running/complete/error) for proper state validation - Moved run guard logic from Provider to worker where it has authoritative state - Updated tests to handle Promise-returning functions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update useLatest hook to set ref synchronously during render instead of in useEffect. This ensures the ref is immediately available to other effects in the same render cycle, fixing an issue where the last batch of simulation frames wasn't visible in the Timeline. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When playback speed is Infinity, skip time-based frame advancement (which produces Infinity math) and instead jump directly to the latest available frame. Pauses playback when simulation completes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sync documentation with current implementation: - Fix incorrect backpressure values (computeBuffer: 40/10) - Simplify and condense documentation - Add playback speed behavior details (including Max/Infinity) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address AI review feedback: - Pass current RNG state to computePossibleTransition() to ensure deterministic random sequencing across multiple transitions per frame - Fix off-by-one in ack() calls: use totalFrames - 1 since indices are 0-based - Remove unused runSimulation from effect dependency array Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add getFramesInRange(start, end?) method to SimulationContext for fetching frames in a range instead of all frames - Update useCompartmentData hook to use incremental frame fetching, only processing new frames instead of re-processing all frames - Cache place colors computation with useMemo - Track processed frame count to enable incremental updates Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix issues identified by AI reviewers and human feedback: - Add race condition guards after async getFrame() in animation loop - Make stop() pause simulation worker like pause() does - Fix stale frame count in play() and setCurrentViewedFrame() - Remove unnecessary exports (PlayModeBackpressure, PLAY_MODES) - Update changeset description to be user-facing - Optimize useCompartmentData from O(p*f) to O(p+f) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
cdb183a to
4c2b66c
Compare
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| const reset: WorkerActions["reset"] = () => { | ||
| postMessage({ type: "stop" }); | ||
| setState(initialState); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



🌟 What is the purpose of this PR?
Introduce a PlaybackContext that handles viewing simulation frames at controlled speeds, separate from simulation computation. Simulation computes frames as fast as possible (or buffered) while playback shows them at the configured speed.
🔗 Related links
🚫 Blocked by
Nothing
🔍 What does this change?
Architecture
requestAnimationFrameack()andsetBackpressure()Play Modes
viewOnlycomputeBuffercomputeMaxPlayback Speeds
Key Changes
initialize()returns Promise for proper async handlingviewOnlywhen simulation completesPre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
None
🐾 Next steps
None
🛡 What tests cover this?
src/playback/provider.test.tsx(28 tests)❓ How to test this?
yarn devdtand playback speed📹 Demo
N/A