Skip to content

fix(xl-ai): reject invokeAI when the menu is closed and the request fails - #3348

Open
itisrmk wants to merge 1 commit into
TypeCellOS:mainfrom
itisrmk:fix/invoke-ai-closed-menu-errors
Open

itisrmk wants to merge 1 commit into
TypeCellOS:mainfrom
itisrmk:fix/invoke-ai-closed-menu-errors

Conversation

@itisrmk

@itisrmk itisrmk commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Programmatic invokeAI calls that fail while the AI menu is closed now reject with the same error the menu would have stored. Calls that start with the menu open still resolve and show that error in the menu.

Rationale

invokeAI caught transport failures, tool-execution failures (result.ok === false), and thrown errors, then only called setAIResponseStatus({ status: "error" }). That method returns immediately when aiMenuState === "closed", so the error was logged and discarded. The promise resolved, the menu stayed "closed", and a caller could not tell an HTTP 500 or a failed tool call from success.

The reporter asked for a result the caller can observe: reject, or return { ok: false, error }. Rejecting keeps the return type Promise<void> and makes the failure visible to existing await / try/catch callers.

Changes

  • packages/xl-ai/src/AIExtension.ts: if invokeAI starts with the menu closed, both failure paths reject with the error that would have been stored (chat.error, result.error, or the thrown value). The menu-open path still calls setAIResponseStatus and resolves.
  • packages/xl-ai/src/AIExtension.test.ts: covers a transport error, a tool-execution error, and a thrown request, plus both failure paths while the menu is open.

Impact

Callers that invoke AI without opening the menu can catch the failure and close the forked review themselves. Menu-driven calls start with the menu open, so they still resolve and render the error state.

Testing

  • With the old invokeAI, the three closed-menu tests resolved instead of rejecting.
  • vp test --run src/AIExtension.test.ts: 5 passed.
  • vp lint --type-aware --type-check and vp fmt on the touched files: passed.

Closes #3275

Summary by CodeRabbit

  • Bug Fixes
    • AI request failures are now handled consistently: when the AI menu is closed, the original error is returned to the caller; when the menu is open, the error is recorded in the menu’s status instead.

…ails

setAIResponseStatus ignores updates while the AI menu is closed, so a
programmatic invokeAI that failed resolved like success. Reject with that
error when the call starts with the menu closed. Calls that start with the
menu open still resolve and store the error for the menu.

Co-authored-by: Rahul Kashyap <itisrmk@users.noreply.github.com>
@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

@cursoragent is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

invokeAI now rejects with the original error when a request fails and the AI menu was closed at invocation. When the menu was open, failures remain represented in menu error state. Regression tests cover transport errors, tool-execution errors, and thrown request errors.

Changes: AI invocation error reporting

Layer / File(s) Summary
Menu-aware error handling
packages/xl-ai/src/AIExtension.ts
invokeAI records the menu state at invocation and uses a shared error handler. Failed results and caught exceptions reject when the menu started closed; when it started open, the error is recorded in menu state.
Error handling regression tests
packages/xl-ai/src/AIExtension.test.ts
Tests cover closed-menu rejection for transport, tool-execution, and thrown request errors. Open-menu tests verify that returned failures and thrown requests resolve to undefined and record error details and the active block ID.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: yousefed, matthewlipski

Merge Risk: Minimal · up to 2021d

Programmatic invokeAI callers can now detect failures when the AI menu is closed, and the menu-open behavior is unchanged. The regression tests cover both cases, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: invokeAI now rejects when the AI menu is closed and the request fails. It matches the raw summary and the PR objectives, and it follows the conventional fix(scope) for…
Description check Passed The description follows the repository template. It has Summary, Rationale, Changes, Impact, and Testing sections, and it explains the closed-menu and menu-open behavior. It links the issue with Close…
Linked Issues check Passed Issue #3275 is the only active direct target. Its requirement: a programmatic invokeAI caller must learn the outcome of a failed call made while the AI menu is closed. The diff at `packages/xl-ai/sr…
Out of Scope Changes check Passed All production changes in AIExtension.ts relate directly to the closed-menu failure reporting in #3275. The reportError helper replaces three duplicated setAIResponseStatus calls. The rejection …
Full details: Title check

Explanation

The title names the main change: invokeAI now rejects when the AI menu is closed and the request fails. It matches the raw summary and the PR objectives, and it follows the conventional fix(scope) format. It is 73 characters, which is within a reasonable length for a title.

Full details: Description check

Explanation

The description follows the repository template. It has Summary, Rationale, Changes, Impact, and Testing sections, and it explains the closed-menu and menu-open behavior. It links the issue with Closes #3275. Two template sections are missing: Screenshots/Video, which is optional for this non-UI change, and Checklist, which is not ticked. Additional Notes is also absent. The description does not state whether the docs were updated, which the checklist asks for.

Full details: Linked Issues check

Explanation

Issue #3275 is the only active direct target. Its requirement: a programmatic invokeAI caller must learn the outcome of a failed call made while the AI menu is closed. The diff at packages/xl-ai/src/AIExtension.ts records invokedWhileMenuClosed at call start. The reportError helper stores the error for the menu and, when the menu was closed, saves the error. After the try/catch, the function throws that error. This covers the chat.error path (includes errors inside a 200 stream), the result.ok === false path, and thrown exceptions. The issue lists rejecting as an acceptable outcome ("e.g. ... returns { ok: false, error } (or rejects)"). The test file covers the three closed-menu failure modes and both failure paths with the menu open. Menu-open calls keep the prior behavior: they store the error and resolve. No unmet coding requirement was found.

Full details: Out of Scope Changes check

Explanation

All production changes in AIExtension.ts relate directly to the closed-menu failure reporting in #3275. The reportError helper replaces three duplicated setAIResponseStatus calls. The rejection is gated on the menu state captured at call start. The test additions in AIExtension.test.ts cover this behavior. No unrelated changes were identified in the diff. One minor point, not a scope issue: if result.ok is true and chat.error is undefined, the helper would throw undefined. This depends on the existing branch condition and was not changed by this PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

A rabbit checks the menu’s state,
Then sends a prompt and waits to see.
If errors come while menus close,
The caller learns what failed to be.
Open menus keep the error close,
While tests watch both paths carefully.

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: 6bc16f6d-639d-4ad9-a0f7-1e09756ec22b
Commits

Reviewing files that changed from the base of the PR and between 58a40d2 and 2021d81.

Files selected for processing: 2

  • packages/xl-ai/src/AIExtension.test.ts
  • packages/xl-ai/src/AIExtension.ts

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@3348

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@3348

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@3348

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3348

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@3348

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3348

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@3348

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@3348

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@3348

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@3348

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@3348

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@3348

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@3348

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@3348

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@3348

@blocknote/xl-typst-exporter

npm i https://pkg.pr.new/@blocknote/xl-typst-exporter@3348

commit: 2021d81

This branch has not been deployed

No deployments
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.

xl-ai: invokeAI with the AI menu closed never reports errors

2 participants