Skip to content

fix(labextension): don't block JupyterLab startup with async kernel init#810

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-build-kale-jupyter-labextension
Draft

fix(labextension): don't block JupyterLab startup with async kernel init#810
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-build-kale-jupyter-labextension

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

@lumino/application awaits all autoStart plugin activate() promises before calling shell.attach() (which creates #main). Kale's activate() was async and awaited kernel creation + backend checks (~2–100s), so #main never appeared within browser_check's 100s timeout.

Changes

  • Deferred kernel init: kernel work is launched as a background IIFE (initializationPromise) — activate() returns immediately without blocking shell.attach()
  • SettingsAwareLeftPanel is async-aware: subscribes to initializationPromise via useEffect/React state; renders null until the kernel is ready, then renders the full panel
  • Preserved layout-restoration timing: lab.started.then() is now synchronous — widget is created and restorer.add() is called before lab.restored fires, keeping layout persistence across page reloads intact
  • Resume-notebook logic: lab.restored.then() still awaits initializationPromise so nb.resume_notebook_path only runs once the kernel is available
  • Removed erroneous throw error in the log.setup_logging catch block that would have caused activate() to reject and crash JupyterLab startup
// Before: activate() is async — blocks shell.attach()
async function activate(...): Promise<IKubeflowKale> {
  const kernel = await NotebookUtils.createNewKernel(); // ← blocks for seconds
  const backend = await getBackend(kernel);             // ← blocks more
  ...
}

// After: activate() returns immediately
function activate(...): Promise<IKubeflowKale> {
  const initializationPromise = (async () => {
    const kernel = await NotebookUtils.createNewKernel(); // runs in background
    const backend = await getBackend(kernel);
    return { kernel, backend };
  })();

  // Widget created synchronously; renders null until initializationPromise resolves
  lab.started.then(() => {
    kalePanelWidget = ReactWidget.create(<SettingsAwareLeftPanel />);
    restorer.add(kalePanelWidget, kalePanelWidget.id); // correct timing preserved
  });
  ...
}

…cked

The activate() function was async and awaited heavy kernel operations
(createNewKernel, getBackend, log.setup_logging) before returning.
Because @lumino/application awaits all autoStart plugin activate()
Promises before calling shell.attach() (which creates the #main element),
this caused JupyterLab's browser_check to time out after 100 s waiting
for '#main'.

Fix:
- Make activate() return immediately (non-blocking) by launching kernel
  init as a background IIFE (initializationPromise).
- Move getBackend() to module scope.
- SettingsAwareLeftPanel component now subscribes to
  initializationPromise via React state, rendering null until the kernel
  is ready, then rendering the full panel.
- lab.started.then() is synchronous: creates the widget and calls
  restorer.add() at the correct time (before lab.restored), preserving
  layout-restoration behaviour across page reloads.
- lab.restored.then() awaits initializationPromise to run the resume-
  notebook-path logic once the kernel is available.
- Remove erroneous `throw error` in the log.setup_logging catch block
  which would have caused activate() to reject and crash JupyterLab
  startup.
@google-oss-prow
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from stefanofioravanzo. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow Bot added size/L and removed size/XS labels May 27, 2026
Copilot AI changed the title [WIP] Fix failing GitHub Actions job for Kale Jupyter Labextension fix(labextension): don't block JupyterLab startup with async kernel init May 27, 2026
Copilot AI requested a review from StefanoFioravanzo May 27, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants