Fix/scenarios list refresh - #8
Conversation
13546c4 to
9f11e5f
Compare
There was a problem hiding this comment.
92Infinitus92 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
| if (index === -1) return current; | ||
|
|
||
| const restored = [...current]; | ||
| restored[index] = previous; |
There was a problem hiding this comment.
Overlapping Rollbacks Restore Failed Edits
If two edits to the same scenario overlap and both PATCH requests fail, the second request captures the first optimistic object as its previous state and restores it during rollback, leaving an unpersisted edit visible even though neither request succeeded.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/studio/src/lib/scenarios-list-ops.ts
Line: 8
Comment:
**Overlapping Rollbacks Restore Failed Edits**
If two edits to the same scenario overlap and both PATCH requests fail, the second request captures the first optimistic object as its previous state and restores it during rollback, leaving an unpersisted edit visible even though neither request succeeded.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.b1e2049 to
8046055
Compare
Dispatch scenarioUpdated only after the PATCH resolves, defer the list refresh while the editor pane is open, and flush it once on close. Show the full-screen loader only on the first load so create and post-edit refreshes update the list in the background instead of blanking the page.
Optimistically remove a scenario card on delete and restore it on failure, and surface a small notice when a background refresh fails so the list is not silently stale. Adds tests for the refresh state machine.
…olls back Roll back optimistic delete and update against the current list via functional state updates, so a create or delete that lands mid-request survives the rollback instead of being clobbered by a stale snapshot. Adds unit tests for the reinsert helper.
a53dc6c to
bfeb90e
Compare
| }) | ||
| ); | ||
| } | ||
| onRefresh?.(); |
There was a problem hiding this comment.
Failed Refresh Restores Deleted Card
When a scenario is deleted while its metadata update is queued, this refresh runs before the DELETE request is sent and can reinsert the still-existing server copy. If DELETE then succeeds but its post-delete refresh fails, the page preserves that reinserted list, leaving the successfully deleted scenario visible until another refresh succeeds.
Knowledge Base Used: Studio scenarios and AI workflows
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/studio/src/components/svm/scenarios-bento.tsx
Line: 237
Comment:
**Failed Refresh Restores Deleted Card**
When a scenario is deleted while its metadata update is queued, this refresh runs before the DELETE request is sent and can reinsert the still-existing server copy. If DELETE then succeeds but its post-delete refresh fails, the page preserves that reinserted list, leaving the successfully deleted scenario visible until another refresh succeeds.
**Knowledge Base Used:** [Studio scenarios and AI workflows](https://app.greptile.com/limechain/-/custom-context/knowledge-base/limechain/surfpool-web-ui/-/docs/studio-scenarios-ai.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Greptile Summary
The PR introduces background scenario-list refreshes, optimistic delete/update reconciliation, and actionable refresh errors. One queued-update/delete race can still leave a successfully deleted card visible when the corrective refresh fails.
Confidence Score: 4/5
The PR is not yet safe to merge because a successfully deleted scenario can remain visible when an intermediate update refresh reinserts it and the post-delete refresh fails.
Queue reconciliation refreshes before a waiting DELETE starts, and the page preserves the resulting list if the corrective post-delete refresh fails.
Files Needing Attention: apps/studio/src/components/svm/scenarios-bento.tsx and apps/studio/src/app/scenarios/page.tsx
Important Files Changed
Sequence Diagram
Prompt To Fix All With AI
Reviews (10): Last reviewed commit: "fix(studio): preserve refreshed scenario..." | Re-trigger Greptile
Context used: