Skip to content

fix: cancel error explanations when closed - #324

Merged
CNSeniorious000 merged 1 commit into
mainfrom
fix/error-explainer-cancellation
Oct 30, 2026
Merged

CNSeniorious000 merged 1 commit into
mainfrom
fix/error-explainer-cancellation

Conversation

@CNSeniorious000

Copy link
Copy Markdown
Member

Abort error explanation startup and streaming when the dialog unmounts. Reuse the OpenAI client factory configured by the Python runtime, and pass its request an AbortSignal; prompt rendering stays unchanged. Ignore cancellation and report other failures.

Verified real-component cleanup before/after. A local slow SSE fixture with real Pyodide and OpenAI SDK confirms no request after cancellation during startup and a disconnected HTTP stream after the first token. Build and lint pass; remaining type errors are covered by #317.

Closes #323.

@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 9:31am UTC

@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-29T09:33:29.431916Z a821021 PR opened
ℹ️ 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/examples/explain.ts" line_range="8-9" />
<code_context>

-export async function* explain(traceback: string, code: string) {
-  const { AsyncChatGenerate } = await initPromplate();
+export async function* explain(traceback: string, code: string, signal: AbortSignal) {
+  if (signal.aborted)
+    return;
+  const { parse_chat_markup } = await initPromplate();
</code_context>
<issue_to_address>
**Existing explanation callers fail**

When an existing consumer invokes the exported function with its former two-argument call, the generator reads `signal.aborted` before doing any work, so a caller that still passes only `traceback` and `code` gets a TypeError instead of an explanation.

Make `signal` optional and create a non-aborted default signal for callers that do not provide one.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/lib/examples/explain.ts:9


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

Comment thread src/lib/examples/explain.ts Resolved
@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: 570029c8-b15a-4d60-831c-fd582dcde6cb
Commits

Reviewing files that changed from the base of the PR and between eb6ba3a and a821021.

Files selected for processing: 2
  • src/lib/components/ErrorExplain.svelte
  • src/lib/examples/explain.ts

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
  • ErrorExplain aborts generation when the component unmounts. It avoids updating rendered HTML after cancellation and shows a toast only for other errors.
  • explain accepts an AbortSignal, checks for cancellation during startup, and passes the signal to the OpenAI streaming request. It destroys the Python-side client factory after creating the client.

The explanation function now accepts an AbortSignal and uses it for a streamed gpt-4o-mini completion. The component passes the signal, stops processing after cancellation, and aborts the request during cleanup. Non-cancellation errors are displayed with toast.error.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

Merge Risk: Minimal · up to a8210

The explanation flow propagates cancellation and aborts on component cleanup without reporting cancellation errors. No actionable merge-blocking issue remains after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes canceling error explanations when the dialog closes. This matches the main change.
Description check Passed The description directly explains cancellation during startup and streaming, client reuse, error handling, validation, and the linked issue. It is related to the changeset.
Linked Issues check Passed [#323] The only active direct target is #323. Its requirement: leaving the error explainer must abort startup or the active HTTP stream, and cancellation must not show an error toast.

Implementation …
Out of Scope Changes check Passed All changes in the diff connect to #323. The change set has two files:
- ErrorExplain.svelte: adds the AbortController lifecycle, abort guards, and the toast import for non-abort errors. Each is nee…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

[#323] The only active direct target is #323. Its requirement: leaving the error explainer must abort startup or the active HTTP stream, and cancellation must not show an error toast.

Implementation at head:

  • ErrorExplain.svelte: onMount creates an AbortController and returns () =&gt; controller.abort(), so unmount aborts the signal.
  • explain.ts: checks signal.aborted after initPromplate(), after prompt rendering, and returns early if aborted. Startup is covered.
  • explain.ts: passes { signal } as the request option to client.chat.completions.create, so the OpenAI SDK aborts the HTTP stream.
  • ErrorExplain.svelte: the loop breaks when aborted, and html is set only while the signal is active.
  • ErrorExplain.svelte: the catch block calls toast.error only when !signal.aborted. Cancellation shows no toast. Other failures are reported.

The prompt is still rendered with context.ExplainError.arender, as before.

No automated test is added in the diff. The issue does not explicitly require one. The PR reports manual verification with a slow SSE fixture.

Residual uncertainty: py.pyimport("openai.AsyncClient") and parse_chat_markup come from the promplate packages installed by src/lib/pyodide/init.py. Their source is not in this repository, so their exact behavior cannot be checked here. The PR reports real-runtime verification.

Full details: Out of Scope Changes check

Explanation

All changes in the diff connect to #323. The change set has two files:

  • ErrorExplain.svelte: adds the AbortController lifecycle, abort guards, and the toast import for non-abort errors. Each is needed for the cancellation and error-reporting behavior.
  • explain.ts: adds the signal parameter and replaces AsyncChatGenerate with a direct stream. Passing the signal to the request requires this replacement. The getPy import and the client-factory call support the reuse of the Python-side client. The model, temperature, and prompt render match the earlier call.

No unrelated refactoring, documentation, or feature changes appear in the reviewed diff.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. 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 0 functions across 1 files. (1 skipped: 1 unsupported.)

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

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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.

@CNSeniorious000
CNSeniorious000 merged commit 89c4164 into main Oct 30, 2026
13 checks passed

This branch was successfully deployed

1 active deployment
Preview — a8210219 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.

Closing the error explainer leaves generation running

1 participant