Skip to content

fix(ollama): end the span when a chat call is interrupted or cancelled - #4029

Open
mayuriphad wants to merge 1 commit into
Arize-ai:mainfrom
mayuriphad:fix/ollama-end-span-on-base-exception
Open

mayuriphad wants to merge 1 commit into
Arize-ai:mainfrom
mayuriphad:fix/ollama-end-span-on-base-exception

Conversation

@mayuriphad

Copy link
Copy Markdown

Fixes #4022

Problem

The Ollama chat wrappers end the span only in except Exception and after a successful response. KeyboardInterrupt and asyncio.CancelledError derive from BaseException, so when either interrupts an in-flight chat() call (Ctrl-C, a cancelled task, asyncio.wait_for timeout, a client disconnect) the span is never ended or exported. Same pattern as #3968, fixed for OpenAI in #3971.

Fix

Catch BaseException around the wrapped call in both _ChatWrapper and _AsyncChatWrapper. _record_exception already accepts BaseException, so the span gets status ERROR and the exception event, and the exception is re-raised unchanged.

Tests

Added test_chat_keyboard_interrupt_ends_span and test_async_chat_cancelled_ends_span. Both fail on main (no finished span) and pass with this change. The other tests that don't need a recorded Ollama cassette still pass.

KeyboardInterrupt and asyncio.CancelledError derive from BaseException, so
the except Exception around the wrapped call never ran and the span was
never ended or exported. Catch BaseException and record it on the span.

Fixes Arize-ai#4022

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 04:15
@mayuriphad
mayuriphad requested a review from a team as a code owner October 12, 2026 04:15

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@mayuriphad

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Oct 12, 2026

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

Status: No status

Development

Successfully merging this pull request may close these issues.

[bug] ollama: a chat call interrupted by KeyboardInterrupt or asyncio cancellation never ends its span

2 participants