Skip to content

fix: keep AI command running when the popup is closed - #1739

Merged
jasoncoffman merged 3 commits into
pinterest:masterfrom
chrismoradi:fix/ai-command-popup-close-while-running
Oct 29, 2026
Merged

jasoncoffman merged 3 commits into
pinterest:masterfrom
chrismoradi:fix/ai-command-popup-close-while-running

Conversation

@chrismoradi

@chrismoradi chrismoradi commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Closing the AI command popup while text-to-SQL is running now leaves the request running in the background. When it finishes, a toast offers to reopen the result.

Each AI socket request now carries a client-generated request_id that the server echoes on every event. useAISocket ignores events tagged with a different request_id, so late responses from cancelled or superseded requests no longer show up in a reopened or re-run command. Events with no request_id are handled as before, so custom AIWebSocket plugins and servers still on the old version during a rolling deploy keep working. Command errors are sent on the command's own channel, tagged with the request_id.

useAISocket also keeps a stable handler identity, clears existing listeners before emitting, and removes its listeners on unmount. Before, callers that passed an inline onData could leak a listener or handle each event twice.

Testing

  • New useAISocket tests cover: stale events ignored, events without a request_id still handled, each event handled once when emitting over an in-flight request, no leaked listeners after re-render or unmount.
  • New backend tests check that sql_title events are tagged with the request_id, and that a failure sends error then close on the command's channel.
  • make test passes (pytest, tsc, Jest, ESLint, webpack).
  • Manual: start a generate command, close the popup while it runs, edit the input; the toast shows the original question and "View" reopens the result.

Closing the AI command popup while text-to-SQL is running now leaves the
request running in the background. When it finishes, a toast offers to
reopen the result.

Each AI socket request now carries a client-generated request_id that the
server echoes on every event. useAISocket drops events for any other id,
so late responses from cancelled or superseded requests are ignored.
Command errors are sent on the command's own channel, tagged with the
request_id.

useAISocket also keeps a stable handler identity and clears existing
listeners before emitting. Before, callers that passed an inline onData
could leak a listener or handle each event twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasoncoffman
jasoncoffman self-requested a review October 26, 2026 21:49
jasoncoffman
jasoncoffman previously approved these changes Oct 28, 2026
Comment thread querybook/webapp/hooks/useAISocket.ts Resolved
Comment thread querybook/webapp/hooks/useAISocket.ts Resolved
Chris Moradi and others added 2 commits October 29, 2026 14:06
A data doc can now hold many AI command hooks, so clear each hook's
listeners when its component unmounts instead of leaving them on the
shared socket.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Custom AIWebSocket plugins, and servers still on the old version during
a rolling deploy, send events without a request_id. Handle those events
as before instead of dropping them; only events tagged with a different
request_id are ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasoncoffman
jasoncoffman merged commit ebd3e63 into pinterest:master Oct 29, 2026
4 checks passed
@chrismoradi
chrismoradi deleted the fix/ai-command-popup-close-while-running branch October 29, 2026 16:49
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.

2 participants