release: test → main — POST /api/chat/{chatId}/stop (#590)
Merged
SW
4mo ago+2064+2064+0123456789012345678901234567890123456789-22-22-01234567890123456789
Promotes test to main (1 commit): adds POST /api/chat/{chatId}/stop to halt an in-flight chat workflow (#590) — cancels the run, waits for terminal status, releases active_stream_id via CAS. Verified end-to-end on preview (stop cancels the model mid-tool-call, slot released, sub-second response).
🤖 Generated with Claude Code
Summary by cubic
Adds POST /api/chat/{chatId}/stop to cancel an in-flight chat workflow. Stop now aborts the current step fast, waits for terminal status, closes SSE promptly, and frees the chat slot.
-
New Features
- New route to stop a chat: validates auth/ownership, calls
getRun().cancel(), waits viawaitForTerminalRunStatus, then clearsactive_stream_idwith CAS; handlespending-*placeholders; returns{ success, stopped }. - Preemption in
runAgentStep: pollsgetRun(runId).status, passes anabortSignaltostreamText, detects user-stop viapipeWorkflowStreamWithStopDetection, and re-persists closed tool parts on abort; returns anabortedflag. - Tool backstop:
wrapToolsWithAbortraces toolexecuteagainst the abort signal and rejects hung tools withToolAbortedError. - SSE watcher:
wrapWorkflowStreamWatchercloses the response on terminal status, synthesizestool-output-errorfor unclosed tool-calls, and forwards consumer cancel togetRun().cancel(); wired intohandleChatWorkflowStream. - Post-step behavior: credits are charged when a
responseMessageexists; auto-commit is skipped on user-stop.
- New route to stop a chat: validates auth/ownership, calls
-
Bug Fixes
- Stop no longer leaves the UI “streaming”; SSE closes quickly after cancellation.
- Natural completions aren’t misclassified as stops; avoids late
finishReasonrejections. - On cancel timeout, returns 504 and keeps
active_stream_idheld to avoid races. - Client disconnect now cancels the run to reduce drift and tool leaks.
Summary by CodeRabbit
Release Notes
-
New Features
- Users can now stop in-progress chat workflows through a new stop endpoint.
-
Bug Fixes
- Tool calls now properly finalize with error status when a workflow is stopped, preventing incomplete tool states from persisting across sessions.