fix: prevent false divergence when disabling second PVM#8
Conversation
The rAF-based flush in useOrchestratorState cleared pendingSnapshots after each flush, causing subsequent pvmStateChanged handlers to fall back to a stale `initial` closure captured before loadProgram completed. When two PVM workers responded across different animation frames, the second event reverted the first PVM's loaded state to pre-load defaults, producing a false gas/PC divergence. Add a lastFlushedSnapshots ref that tracks the most recently flushed snapshot map. Post-flush event handlers now use this as their fallback base instead of the stale initial state. Includes E2E tests for the enable→disable flow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for pvm-debugger ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR adds end-to-end tests validating correct behavior when disabling a secondary PVM debugger and modifies the orchestrator state hook's snapshot accumulation logic to retain post-flush state across event boundaries. Changes
Possibly related issues
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/web/e2e/sprint-25-disable-pvm-divergence.spec.ts (1)
25-40: Consider adding diagnostic logging in the catch block.The silent catch block makes it harder to diagnose why Ananas failed to enable if the test returns
false. This is a minor ergonomics improvement.🔧 Proposed improvement for better diagnostics
try { await expect(page.getByTestId("pvm-tab-ananas")).toHaveRole("tab", { timeout: 15000, }); return true; - } catch { + } catch (e) { + console.warn("Ananas PVM tab did not appear:", e); return false; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/e2e/sprint-25-disable-pvm-divergence.spec.ts` around lines 25 - 40, The tryEnableAnanas function currently swallows errors in its catch and returns false with no diagnostics; update the catch block in tryEnableAnanas to log diagnostic information (e.g., the caught error message and a snapshot of relevant page state like page.url() or page.locator('body').innerText()) via the test/logger so you can see why the tab didn't appear before returning false, while preserving the existing return false behavior; reference the ananasSwitch locator and pvm-tab-ananas expectation when assembling the log for context.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/e2e/sprint-25-disable-pvm-divergence.spec.ts`:
- Around line 25-40: The tryEnableAnanas function currently swallows errors in
its catch and returns false with no diagnostics; update the catch block in
tryEnableAnanas to log diagnostic information (e.g., the caught error message
and a snapshot of relevant page state like page.url() or
page.locator('body').innerText()) via the test/logger so you can see why the tab
didn't appear before returning false, while preserving the existing return false
behavior; reference the ananasSwitch locator and pvm-tab-ananas expectation when
assembling the log for context.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a6148e6f-5046-4baf-9395-5bdde37266d8
📒 Files selected for processing (2)
apps/web/e2e/sprint-25-disable-pvm-divergence.spec.tsapps/web/src/hooks/useOrchestratorState.ts
When enabling/disabling PVMs, loadProgram is async and workers respond at different times. This creates a brief window where one PVM has loaded state while the other still has defaults, producing a false divergence flash. Gate divergence display behind isReloadingRef which is already true for the duration of loadProgram. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Document the stale-closure rAF race fix (lastFlushedSnapshots ref) and the divergence flash suppression during PVM reload (isReloadingRef gate). Add the new E2E test file to required files and verification sections. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
useOrchestratorStatewhere post-flush event handlers fell back to a staleinitialclosure, reverting already-loaded PVM state to pre-loadProgramdefaultslastFlushedSnapshotsref so the fallback chain is: pending buffer → last flushed state → initial stateDetails
When two PVM workers responded to
loadProgramacross different animation frames, the secondpvmStateChangedevent would rebuild fromnew Map(initial)(captured beforeloadProgram), losing the first PVM's loaded state. This caused false gas divergence (0 vs 10000) immediately after enabling the second PVM.Test plan
🤖 Generated with Claude Code