Skip to content

poc: add stop button to cancel in-flight chat stream - #131

Open
Penina-Levy wants to merge 32 commits into
mainfrom
poc/penina-stopbutton
Open

Penina-Levy wants to merge 32 commits into
mainfrom
poc/penina-stopbutton

Conversation

@Penina-Levy

Copy link
Copy Markdown
Collaborator

When isSending, replaces the send button with a red stop button. Clicking it aborts the fetch stream via AbortController and appends an assistant message "okay, I won't answer that" to the canvas.

When isSending, replaces the send button with a red stop button.
Clicking it aborts the fetch stream via AbortController and appends
an assistant message "okay, I won't answer that" to the canvas.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coolify-sefaria-github

coolify-sefaria-github Bot commented May 7, 2026 •

Copy link
Copy Markdown

The preview deployment for sefaria/ai-chatbot:server is ready. 🟢

Open app | Open Build Logs | Open Application Logs

Last updated at: 2026-06-25 11:33:10 CET

@gitvelocity-reviewer

Copy link
Copy Markdown

📊 Code Quality Score: 10/100

26 × 0.4 (Small ESF) = 10.4

Category Score Factors
🔭 Scope 5/20 2 files, single feature addition, no new endpoints or DB changes, contained within chatbot component and API layer
🏗️ Architecture 4/20 Signal threading through existing API call, follows existing patterns, no new abstractions or dependencies introduced
⚙️ Implementation 8/20 Proper AbortController usage, conditional UI toggle, error path differentiation (AbortError vs other), finally cleanup; minor inconsistency using string literal 'sent' instead of STATUS constant
⚠️ Risk 5/20 Easily reversible, no data migration or auth changes, minor UX risk from discarding partial streamed content, no feature flag needed given low blast radius
✅ Quality 3/15 No tests added for behavioral changes, no documentation, hardcoded informal abort message string, missing STATUS constant usage
🔒 Perf / Security 1/5 Proper AbortController cleanup in finally block, no security concerns introduced

Scored by GitVelocity · How are scores calculated?

Penina and others added 27 commits May 7, 2026 12:37
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44x44px, #c03522 background, #a02c1c on hover/active, 8px radius,
lucide square outline icon (16x16, white stroke).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Matches native title-attribute tooltip pattern used on header buttons.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add wasStopped flag to hide the thinking/progress block the moment
stop is clicked, so "okay, I won't answer that" cleanly replaces it
without a brief overlap.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously, aborting during stream reading fell through to the
recovery logic which could deliver a response anyway, making the
stop button appear to do nothing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add box-sizing: border-box and padding: 0 to prevent browser
default styles from inflating the button beyond 44px.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When the user clicks stop, the thinking block disappears and no
new message is added. Existing chat content remains unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
White bg (#ffffff) with lucide/circle-stop icon (#6f6f6f stroke),
hover state light gray (#eeeeee). Replaces red ButtonTest/stop design.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lt, cccccc hover

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ius-sm)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Default bg: --lc-disabled-button-hover (#cccccc)
Hover bg: new --lc-stop-btn-hover (#999999)
Icon: currentColor via --lc-bg (#ffffff)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…SS vars

- Remove wasStopped state flag (was ineffective due to Svelte batching)
- Replace setTimeout focus hack with await tick() in finally block
- Rename --lc-disabled-button-hover to --lc-stop-btn-bg for clarity
- Both stop button vars now follow --lc-stop-btn-* naming

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Removes redundant --lc-stop-btn-bg/hover variables. Stop button now
uses --lc-primary and --lc-primary-hover, matching Figma update and
the send button pattern.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- :focus-visible uses outline: 2px solid --lc-primary with offset,
  consistent with primary color focus pattern in codebase
- aria-hidden=true on SVG since button already has aria-label

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- streamAbortController: plain let, not $state (not used in template)
- stoppedByUser: moved below early-return guard
- saveMessagesToStorage: deduplicated, called once at end of catch
- STATUS_SENT constant added, replaces hardcoded 'sent' string
- sendMessageStream signal wrapped in options object (avoids 10th positional param)
- type=button added to stop button
- focus-visible: white outline + navy box-shadow, visible on any background

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
transition:all was including outline, causing focus ring to flash
and disappear. Now only background-color and transform transition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…uard tick() in finally

- Replace all status: 'sent' with STATUS_SENT constant
- Add JSDoc for options param in sendMessageStream
- Wrap await tick() in try/catch to prevent masking original errors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fires reportClientStreamEvent('stream_cancelled') on abort, including:
- elapsed_ms: time from request start to cancel
- last_progress_type: what the stream was doing when stopped
- last_tool_name: which tool was running if any

Uses a getProgress callback in options so api.js can read live
component state without coupling. metadata spread added to
reportClientStreamEvent for extensible extra fields.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Penina and others added 4 commits June 24, 2026 12:43
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44x44px, transparent bg with 1px navy border, rounded-square stop icon

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant