Fix #4888: Finalize pending api_req_started messages on task completion #5017
+214
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4888 by ensuring all pending api_req_started messages are properly finalized when a task completes, preventing UI spinners from persisting in task history.
Changes
Core Implementation
finish()method toTask.ts: Finds allapi_req_startedmessages withoutcostorcancelReasonand sets theircostto0attemptCompletionTool.ts: Callsfinish()before emittingtaskCompletedto ensure all API requests are finalizedTesting
Task.spec.ts:api_req_startedmessages get finalized withcost: 0api_req_startedmessagesapi_req_startedmessages have eithercostorcancelReasonafter completionProblem Solved
The issue occurred because when tasks completed, some
api_req_startedmessages in the conversation history lacked bothcostandcancelReasonvalues. The UI component (ChatRow.tsx) shows a spinner for ANYapi_req_startedmessage missing these values, causing spinners to persist in completed task history.Solution Approach
While operations run sequentially and theoretically only the last
api_req_startedcould be unfinished, the UI checks ALL messages for the spinner condition. Rather than modifying the UI logic (which would require additional complexity), this solution ensures backend compatibility by finalizing all unfinished messages.Testing
✅ All existing tests pass
✅ New unit tests cover the
finish()method functionality✅ Linting and type checking pass
Verification
After this fix:
api_req_startedmessages properly finalizedImportant
Adds
finish()method toTaskto finalize pendingapi_req_startedmessages, ensuring UI spinners do not persist.finish()method toTaskclass inTask.tsto finalizeapi_req_startedmessages with nocostorcancelReasonby settingcostto0.attemptCompletionToolinattemptCompletionTool.tsto callfinish()before emittingtaskCompleted.Task.spec.tsto verifyfinish()method finalizes messages correctly, handles cases with no updates, and processes scenarios with noapi_req_startedmessages.This description was created by
for 5233f61. You can customize this summary. It will automatically update as commits are pushed.