codeant-ai-for-open-source[bot] commented on code in PR #41491:
URL: https://github.com/apache/superset/pull/41491#discussion_r3485759231


##########
superset-frontend/src/embedded/index.tsx:
##########
@@ -190,34 +190,42 @@ function start() {
     method: 'GET',
     endpoint: '/api/v1/me/roles/',
   });
-  return pluginsReady.then(() =>
-    getMeWithRole().then(
-      ({ result }) => {
-        // fill in some missing bootstrap data
-        // (because at pageload, we don't have any auth yet)
-        // this allows the frontend's permissions checks to work.
-        bootstrapData.user = result;
-        store.dispatch({
-          type: USER_LOADED,
-          user: result,
-        });
-        if (!root) {
-          root = createRoot(appMountPoint);
-        }
-        root.render(<EmbeddedApp />);
-      },
-      err => {
-        // something is most likely wrong with the guest token; reset the guard
-        // so a rehandshake with a valid token can retry.
-        logging.error(err);
-        showFailureMessage(
-          t(
-            'Something went wrong with embedded authentication. Check the dev 
console for details.',
-          ),
-        );
-        started = false;
-      },
-    ),
+  return pluginsReady.then(
+    () =>
+      getMeWithRole().then(
+        ({ result }) => {
+          // fill in some missing bootstrap data
+          // (because at pageload, we don't have any auth yet)
+          // this allows the frontend's permissions checks to work.
+          bootstrapData.user = result;
+          store.dispatch({
+            type: USER_LOADED,
+            user: result,
+          });
+          if (!root) {
+            root = createRoot(appMountPoint);
+          }
+          root.render(<EmbeddedApp />);
+        },
+        err => {
+          // something is most likely wrong with the guest token; reset the 
guard
+          // so a rehandshake with a valid token can retry.
+          logging.error(err);
+          showFailureMessage(
+            t(
+              'Something went wrong with embedded authentication. Check the 
dev console for details.',
+            ),
+          );
+          started = false;
+        },
+      ),
+    err => {
+      // setupPlugins() or setupCodeOverrides() threw while preparing plugins;
+      // reset the guard so a retry can re-run start() instead of leaving the
+      // dashboard stuck in a failed state.
+      logging.error(err);
+      started = false;
+    },
   );

Review Comment:
   **Suggestion:** The retry path is still broken because `start()` always 
chains to the module-level `pluginsReady` promise, and that promise is created 
only once. If plugin setup rejects once, `pluginsReady` stays permanently 
rejected, so later retries immediately hit the rejection handler and can never 
proceed to user bootstrap/render. Recreate the plugin-setup promise after a 
failure (or lazily initialize it per attempt) so a retry actually reruns plugin 
initialization. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Embedded dashboard cannot recover after plugin setup failure.
   - ⚠️ Rehandshakes via guestToken never reach user bootstrap.
   - ⚠️ Embedded Switchboard client remains unusable after first failure.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Load the embedded dashboard page so that 
`superset-frontend/src/embedded/index.tsx` is
   evaluated; this creates the module-level `pluginsReady` promise at lines 
57-72, which
   calls `initPreamble().catch(...).then(async () => { await
   Promise.all([import("src/setup/setupPlugins"), 
import("src/setup/setupCodeOverrides")]);
   setupPlugins(); setupCodeOverrides({ embedded: true }); })`.
   
   2. Trigger the normal embedded handshake from the parent app so
   `window.addEventListener('message', ...)` in `embedded/index.tsx:244-332` 
runs and the
   `Switchboard.defineMethod('guestToken', ...)` handler at lines 260-266 calls
   `setupGuestClient(guestToken)` and then `start()`.
   
   3. While the first `start()` call is waiting on `pluginsReady`, cause the 
plugin-setup
   path to throw (for example by forcing an error in the dynamic import or in
   `setupPlugins()`/`setupCodeOverrides()` invoked from the async callback at 
lines 64-72);
   this rejection flows into the `pluginsReady.then(...)` call in `start()` at 
lines 193-229,
   invoking the rejection handler at lines 222-228, which logs the error and 
sets `started =
   false` but leaves `pluginsReady` as a permanently rejected promise.
   
   4. Have the parent app resend the embedded handshake and `guestToken` 
(calling the same
   `Switchboard.defineMethod('guestToken', ...)` at 260-266 again); `start()` 
at lines
   186-230 sees `started === false`, sets it to `true`, and calls 
`pluginsReady.then(...)`
   again, but because `pluginsReady` is already rejected and never recreated, 
the rejection
   handler runs immediately, `setupPlugins()`/`setupCodeOverrides()` are never 
re-invoked,
   and the embedded dashboard can never progress to the user bootstrap/render 
path at lines
   195-209, leaving the app in a permanently non-starting state despite retries.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1cded4a9ad3d4010997e118207bab9ef&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=1cded4a9ad3d4010997e118207bab9ef&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/embedded/index.tsx
   **Line:** 193:229
   **Comment:**
        *Logic Error: The retry path is still broken because `start()` always 
chains to the module-level `pluginsReady` promise, and that promise is created 
only once. If plugin setup rejects once, `pluginsReady` stays permanently 
rejected, so later retries immediately hit the rejection handler and can never 
proceed to user bootstrap/render. Recreate the plugin-setup promise after a 
failure (or lazily initialize it per attempt) so a retry actually reruns plugin 
initialization.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41491&comment_hash=acac9c9ba24a45a45d6e0daa56d70ddf28f8a53afb4e0f4a1d3aee776bf8967a&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41491&comment_hash=acac9c9ba24a45a45d6e0daa56d70ddf28f8a53afb4e0f4a1d3aee776bf8967a&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to