fix(edge-worker): suppress Finished activity when turn ends on tool call (CYPACK-1177)#1201
Open
cyrusagent wants to merge 1 commit into
Open
fix(edge-worker): suppress Finished activity when turn ends on tool call (CYPACK-1177)#1201cyrusagent wants to merge 1 commit into
cyrusagent wants to merge 1 commit into
Conversation
…all (CYPACK-1177) When an SDK turn ended on a backgrounded tool call (ScheduleWakeup, background Bash) with no trailing assistant text, the "Finished" response activity was posted with the raw tool-input JSON as its body. Two fixes: 1. Don't buffer tool-use content into lastAssistantBodyBySession — its `content` is JSON.stringify(tool input), not real assistant text. 2. Skip the response activity entirely in addResultEntry when there is no buffered assistant text to post (and the result is not an error).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Assignee: @pauravhp (paurav)
Summary
Fixes CYPACK-1177.
When an SDK turn ended on a backgrounded tool call (
ScheduleWakeup,Bashwithrun_in_background) and there was no trailing assistant text, Cyrus posted a "Finished" response activity to Linear whose body was the raw tool-input JSON.Root cause: in
AgentSessionManager.handleClaudeMessage, every assistant message — including tool-use messages — wrote itscontentintolastAssistantBodyBySession. But for a tool-use message,extractContentserializes the tool input viaJSON.stringify(block.input, null, 2). When the result arrived without any trailing text message to overwrite the buffer,addResultEntryposted that JSON string as the response body.Changes
AgentSessionManager.ts— Only buffer text-only, non-empty assistant content intolastAssistantBodyBySession. Tool-use messages no longer poison the response fallback.AgentSessionManager.ts— InaddResultEntry, skip emitting the response activity entirely when there is no real content to post (and the result is not an error). The session status is still set to Complete bycompleteSession, but no spurious "Finished" entry is created.AgentSessionManager.result-no-trailing-text.test.tscovers theScheduleWakeupand background-Bashturn-ending cases, plus the happy path where trailing assistant text is still posted as a response.Test plan
pnpm vitest run test/AgentSessionManager.result-no-trailing-text.test.ts)pnpm typecheckcleanpnpm lintclean (no new errors)