From f5a4bbcb1c34e7e666a21ff3a603fdd09bc88cb3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Mar 2026 19:23:15 +0000 Subject: [PATCH] Fix empty content_block_stop handler to finalize tool input and emit item.updated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The content_block_stop handler retrieved the in-flight tool but did nothing with it — no event emission, no state update. This was dead code. content_block_stop signals that a content block's streaming is complete. For tool_use blocks, this means the input JSON is fully streamed. The handler now: 1. Finalizes the accumulated partial JSON input 2. Updates the tool in inFlightTools with the parsed input 3. Emits an item.updated event with the complete tool state This ensures the UI always receives the final, complete tool input even if the last input_json_delta didn't trigger an update due to fingerprint deduplication. Co-authored-by: Julius Marminge --- .../src/provider/Layers/ClaudeCodeAdapter.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/apps/server/src/provider/Layers/ClaudeCodeAdapter.ts b/apps/server/src/provider/Layers/ClaudeCodeAdapter.ts index dea48d07bb..086b67f92f 100644 --- a/apps/server/src/provider/Layers/ClaudeCodeAdapter.ts +++ b/apps/server/src/provider/Layers/ClaudeCodeAdapter.ts @@ -1148,6 +1148,52 @@ function makeClaudeCodeAdapter(options?: ClaudeCodeAdapterLiveOptions) { if (!tool) { return; } + + let finalTool = tool; + if (tool.partialInputJson.length > 0) { + const parsedInput = tryParseJsonRecord(tool.partialInputJson); + if (parsedInput) { + const detail = summarizeToolRequest(tool.toolName, parsedInput); + finalTool = { + ...tool, + input: parsedInput, + ...(detail ? { detail } : {}), + }; + context.inFlightTools.set(index, finalTool); + } + } + + const stamp = yield* makeEventStamp(); + yield* offerRuntimeEvent({ + type: "item.updated", + eventId: stamp.eventId, + provider: PROVIDER, + createdAt: stamp.createdAt, + threadId: context.session.threadId, + ...(context.turnState ? { turnId: asCanonicalTurnId(context.turnState.turnId) } : {}), + itemId: asRuntimeItemId(finalTool.itemId), + payload: { + itemType: finalTool.itemType, + status: "inProgress", + title: finalTool.title, + ...(finalTool.detail ? { detail: finalTool.detail } : {}), + data: { + toolName: finalTool.toolName, + input: finalTool.input, + }, + }, + providerRefs: { + ...providerThreadRef(context), + ...(context.turnState ? { providerTurnId: String(context.turnState.turnId) } : {}), + providerItemId: ProviderItemId.makeUnsafe(finalTool.itemId), + }, + raw: { + source: "claude.sdk.message", + method: "claude/stream_event/content_block_stop", + payload: message, + }, + }); + return; } });