Skip to content

fix: stop console initialization after unmount - #320

Merged
CNSeniorious000 merged 3 commits into
mainfrom
fix/console-initialization
Oct 29, 2026
Merged

CNSeniorious000 merged 3 commits into
mainfrom
fix/console-initialization

Conversation

@CNSeniorious000

@CNSeniorious000 CNSeniorious000 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Skip console setup when navigation finishes before Pyodide or the console module loads. Check cancellation before changing Python globals, detach output callbacks on unmount and ignore late updates. Report console initialization failures with a Reload action.

Verified deferred initialization and cleanup with the real Svelte component in Chromium. Production-preview failure injection also confirms the error appears and Reload restores a working console. Combined build, lint and type checks pass (24 existing warnings).

Closes #319.

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Project Deployment Actions Updated
promplate-docs Ready Ready Preview Oct 29, 2026 7:34pm UTC

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 551bbcf5-d022-4d97-9cc8-d007e6ed6347
Commits

Reviewing files that changed from the base of the PR and between 8901957 and afc8b53.

Files selected for processing: 1
  • src/lib/components/console/HeadlessConsole.svelte

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Summary
  • Stop console setup after unmount by checking the abort signal before and after initConsole.
  • Detach stdout and stderr callbacks on unmount, and ignore later log updates.
  • Add optional AbortSignal support to initConsole so it skips Python setup when aborted.
  • The PR description reports Chromium checks with deferred runtime stubs, and passing build and lint.

HeadlessConsole now aborts pending initialization when it is destroyed, clears the Python console’s stdout and stderr callbacks when ready, and ignores log updates after cancellation. It passes an optional AbortSignal to initConsole, which skips its initialization code when the signal is aborted. If initialization fails while the component remains active, HeadlessConsole displays an error toast with a reload action.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to afc8b

The change prevents canceled console setup from proceeding after navigation and detaches existing output callbacks. No actionable merge-blocking issue was identified.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Out of Scope Changes check Warning The cancellation and cleanup changes stay within #319. The new toast.error("Unable to initialize console", ...) behavior and its Reload action add independent failure-reporting UI. Issue #319 does… Remove the initialization-failure toast and Reload action from this pull request, or link the behavior to an active issue that requires it.
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes stopping console initialization after component unmount.
Description check Passed The description directly explains cancellation, cleanup, error handling, verification, and the linked issue for the console initialization changes.
Linked Issues check Passed Issue #319 requires cancellation after unmount, no post-unmount console setup or callback assignment, and callback detachment. HeadlessConsole.svelte aborts on destroy, checks the signal after `getP…
Full details: Linked Issues check

Explanation

Issue #319 requires cancellation after unmount, no post-unmount console setup or callback assignment, and callback detachment. HeadlessConsole.svelte aborts on destroy, checks the signal after getPy() and initConsole(signal), and assigns globals and callbacks only after those checks. onDestroy clears existing stdout_callback and stderr_callback, and pushLog ignores late updates. init.ts also checks the signal before running the console initialization code.

Full details: Out of Scope Changes check

Explanation

The cancellation and cleanup changes stay within #319. The new toast.error("Unable to initialize console", ...) behavior and its Reload action add independent failure-reporting UI. Issue #319 does not request this behavior, and the linked issue provides no requirement that supports it.

Resolution

Remove the initialization-failure toast and Reload action from this pull request, or link the behavior to an active issue that requires it.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T08:29:30.109904Z 8901957 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/lib/components/console/HeadlessConsole.svelte" line_range="43" />
<code_context>
+
   onMount(async () => {
     const py = await getPy();
+    if (disposed)
+      return;
     await initConsole();
</code_context>
<issue_to_address>
**Abandoned mounts overwrite console state**

When the component is destroyed while `initConsole()` is pending, `initConsole()` continues into `py.runPythonAsync(...)` and redefines the shared console and helper globals after navigation, so a later mount can observe state overwritten by the abandoned mount.

Prevent `initConsole()` from running Python initialization or changing shared globals after the component is disposed.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/lib/components/console/HeadlessConsole.svelte:43


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@sourcery-ai sourcery-ai 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.

Sourcery assessment

Approved.

@CNSeniorious000
CNSeniorious000 merged commit a198f2d into main Oct 29, 2026
13 checks passed

This branch was successfully deployed

1 active deployment
Preview — afc8b539 Deployed Oct 29, 2026 by vercel[bot]
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.

Console initialization continues after navigation

1 participant