Skip to content

perf: defer AI chat tool handler imports#35

Merged
charlesrhoward merged 1 commit intomainfrom
codex/feat-23-defer-tool-handler-imports
Feb 21, 2026
Merged

perf: defer AI chat tool handler imports#35
charlesrhoward merged 1 commit intomainfrom
codex/feat-23-defer-tool-handler-imports

Conversation

@charlesrhoward
Copy link
Contributor

@charlesrhoward charlesrhoward commented Feb 21, 2026

Summary

  • defer loading @/lib/ai-chat/tool-handlers until first tool call
  • cache the loaded module and reuse it for subsequent calls
  • preserve existing tool execution behavior

Validation

  • pnpm build

Closes #23


Note

Low Risk
Change is isolated to import timing/caching in the chat UI; functional behavior should remain the same aside from potential first-call load latency or dynamic import failures.

Overview
Defers loading of @/lib/ai-chat/tool-handlers in AIChatPanel by removing static imports and dynamically importing the module on the first tool call.

Caches the imported handlers in a ref (getToolHandlers) and routes all tool executions through the cached module, preserving the existing tool-call switch behavior (including async placeImage).

Written by Cursor Bugbot for commit 3211550. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drawit Ready Ready Preview, Comment Feb 21, 2026 9:38pm

Request Review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4388b2e9f0

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


try {
let result: unknown
const handlers = await getToolHandlers()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid gating all tool calls on lazy handler chunk load

The new unconditional await getToolHandlers() runs before the switch, so even runBackgroundDiagram (which does not use @/lib/ai-chat/tool-handlers) now fails if the lazy chunk cannot be fetched (e.g., stale client after deploy or transient chunk-load/network error). In that scenario, execution jumps to the outer catch and returns an error instead of running the background-diagram path, which is a behavior regression introduced by this commit.

Useful? React with 👍 / 👎.

@charlesrhoward charlesrhoward force-pushed the codex/feat-23-defer-tool-handler-imports branch from 4388b2e to 3211550 Compare February 21, 2026 21:37
@charlesrhoward charlesrhoward merged commit d3931db into main Feb 21, 2026
4 checks passed
@charlesrhoward charlesrhoward deleted the codex/feat-23-defer-tool-handler-imports branch February 21, 2026 21:38
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.

Performance: Defer AI tool handler imports in chat panel

1 participant