Skip to content

fix(edge-worker): suppress Finished activity when turn ends on tool call (CYPACK-1177)#1201

Open
cyrusagent wants to merge 1 commit into
mainfrom
cypack-1177
Open

fix(edge-worker): suppress Finished activity when turn ends on tool call (CYPACK-1177)#1201
cyrusagent wants to merge 1 commit into
mainfrom
cypack-1177

Conversation

@cyrusagent
Copy link
Copy Markdown
Contributor

Assignee: @pauravhp (paurav)

Summary

Fixes CYPACK-1177.

When an SDK turn ended on a backgrounded tool call (ScheduleWakeup, Bash with run_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 its content into lastAssistantBodyBySession. But for a tool-use message, extractContent serializes the tool input via JSON.stringify(block.input, null, 2). When the result arrived without any trailing text message to overwrite the buffer, addResultEntry posted that JSON string as the response body.

Changes

  1. AgentSessionManager.ts — Only buffer text-only, non-empty assistant content into lastAssistantBodyBySession. Tool-use messages no longer poison the response fallback.
  2. AgentSessionManager.ts — In addResultEntry, 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 by completeSession, but no spurious "Finished" entry is created.
  3. New regression testAgentSessionManager.result-no-trailing-text.test.ts covers the ScheduleWakeup and background-Bash turn-ending cases, plus the happy path where trailing assistant text is still posted as a response.

Test plan

  • New tests pass (pnpm vitest run test/AgentSessionManager.result-no-trailing-text.test.ts)
  • Full edge-worker test suite passes (614 tests)
  • pnpm typecheck clean
  • pnpm lint clean (no new errors)

Tip: I will respond to comments that @ mention @cyrusagent on this PR. You can also submit a review with all your feedback at once, and I will automatically wake up to address each comment.

…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).
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