Skip to content

Fix/scenarios list refresh - #8

Open
92Infinitus92 wants to merge 9 commits into
feat/studio-override-outcomes-uifrom
fix/scenarios-list-refresh
Open

Fix/scenarios list refresh#8
92Infinitus92 wants to merge 9 commits into
feat/studio-override-outcomes-uifrom
fix/scenarios-list-refresh

Conversation

@92Infinitus92

@92Infinitus92 92Infinitus92 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator
  • Refresh scenarios without showing a full-page loading state.
  • Remove deleted scenarios immediately.
  • Preserve concurrent list changes when an optimistic delete or update fails.
  • Surface background refresh failures with retry and dismiss actions.

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.

  • Keeps the existing catalog visible during background refreshes and rejects stale load responses.
  • Serializes optimistic metadata updates and preserves concurrently refreshed fields.
  • Removes scenarios immediately and restores failed deletions against the current list.
  • Defers editor-triggered refreshes until the detail pane closes.

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

Filename Overview
apps/studio/src/app/scenarios/page.tsx Adds guarded background loading, deferred pane refreshes, and retryable refresh errors; preserving the current list on failure exposes the delete race.
apps/studio/src/components/svm/scenarios-bento.tsx Adds serialized optimistic updates and functional delete rollback, but an update completion can refresh and restore a card before its pending DELETE begins.
apps/studio/src/components/svm/scenario-editor.tsx Moves the scenario-updated event after successful persistence so subsequent refreshes read saved editor state.
apps/studio/src/lib/scenarios-list-ops.ts Reinserts failed optimistic deletions without replacing a newer same-ID item or discarding unrelated list changes.
apps/studio/src/app/scenarios/page.test.tsx Covers background loading, deferred refreshes, errors, retries, and stale-request rejection.
apps/studio/src/components/svm/scenarios-bento.test.tsx Covers queued update reconciliation and refreshed-field preservation but not the queued-update/delete interaction.
apps/studio/src/lib/scenarios-list-ops.test.ts Covers insertion ordering, concurrent list changes, and preservation of newer same-ID values.

Sequence Diagram

sequenceDiagram
  participant U as User
  participant B as ScenariosBento
  participant P as Scenario Page
  participant S as Scenario Service
  U->>B: Delete scenario with queued update
  B->>B: Remove card optimistically
  B->>B: Await queued PATCH
  B->>P: Refresh after PATCH
  P->>S: GET scenarios
  S-->>P: Scenario still exists
  P-->>B: Reinsert server list
  B->>S: DELETE scenario
  S-->>B: Success
  B->>P: Post-delete refresh
  P->>S: GET scenarios
  S--xP: Refresh failure
  P-->>B: Preserve current list
Loading

Fix all with Greploop Fix All in Claude Code Fix All in Codex Fix All in Cursor

Prompt To Fix All With AI
### Issue 1
apps/studio/src/components/svm/scenarios-bento.tsx:237
**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.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (10): Last reviewed commit: "fix(studio): preserve refreshed scenario..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used:

@92Infinitus92 92Infinitus92 self-assigned this Aug 14, 2026
Comment thread apps/studio/src/components/svm/scenarios-bento.tsx Outdated
@92Infinitus92
92Infinitus92 force-pushed the fix/scenarios-list-refresh branch from 13546c4 to 9f11e5f Compare August 14, 2026 21:52
@92Infinitus92

Copy link
Copy Markdown
Collaborator Author

@greptileai

@greptile-apps greptile-apps 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.

92Infinitus92 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@failfmi

failfmi commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

@greptileai

Comment thread apps/studio/src/components/svm/scenarios-bento.tsx Outdated
if (index === -1) return current;

const restored = [...current];
restored[index] = previous;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread apps/studio/src/components/svm/scenarios-bento.tsx Outdated
Comment thread apps/studio/src/components/svm/scenarios-bento.tsx Outdated
Comment thread apps/studio/src/components/svm/scenarios-bento.tsx
@92Infinitus92

Copy link
Copy Markdown
Collaborator Author

@greptileai

Comment thread apps/studio/src/components/svm/scenarios-bento.tsx
@92Infinitus92
92Infinitus92 force-pushed the feat/studio-override-outcomes-ui branch from b1e2049 to 8046055 Compare September 3, 2026 07:19
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.
@92Infinitus92
92Infinitus92 force-pushed the fix/scenarios-list-refresh branch from a53dc6c to bfeb90e Compare September 3, 2026 08:23
})
);
}
onRefresh?.();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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.

Fix in Claude Code Fix in Codex Fix in Cursor

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