GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(ai): ignore late converse tool deltas (#45847) · jinhuang712/opencode@760cbf5

This repository was archived by the owner on Oct 29, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/ai
    • src/protocols
      • bedrock-converse.ts
    • test/provider
      • bedrock-converse.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/ai/src/protocols/bedrock-converse.ts‎

Copy file name to clipboardExpand all lines: packages/ai/src/protocols/bedrock-converse.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ const mapUsage = (usage: BedrockUsageSchema | undefined, providerMetadataKey: st
496496
interface ParserState {
497497
readonly providerMetadataKey: string
498498
readonly tools: ToolStream.State<number>
499+
readonly finishedTools: ReadonlySet<number>
499500
// Bedrock splits the finish into `messageStop` (carries `stopReason`) and
500501
// `metadata` (carries usage). Hold the terminal event in state so `onHalt`
501502
// can emit exactly one finish after both chunks have had a chance to arrive.
@@ -574,6 +575,7 @@ const step = (state: ParserState, event: BedrockEvent) =>
574575

575576
if (event.contentBlockDelta?.delta?.toolUse) {
576577
const index = event.contentBlockDelta.contentBlockIndex
578+
if (state.finishedTools.has(index)) return [state, []] as const
577579
const result = ToolStream.appendExisting(
578580
ADAPTER,
579581
state.tools,
@@ -612,6 +614,7 @@ const step = (state: ParserState, event: BedrockEvent) =>
612614
state.hasToolCalls,
613615
lifecycle,
614616
tools: result.tools,
617+
finishedTools: resultEvents.length > 0 ? new Set([...state.finishedTools, index]) : state.finishedTools,
615618
reasoningSignatures: Object.fromEntries(
616619
Object.entries(state.reasoningSignatures).filter(([key]) => key !== String(index)),
617620
),
@@ -703,6 +706,7 @@ export const protocol = Protocol.make({
703706
initial: (request) => ({
704707
providerMetadataKey: request.model.route.providerMetadataKey ?? String(request.model.provider),
705708
tools: ToolStream.empty<number>(),
709+
finishedTools: new Set<number>(),
706710
pendingFinish: undefined,
707711
hasToolCalls: false,
708712
lifecycle: Lifecycle.initial(),
Collapse file

‎packages/ai/test/provider/bedrock-converse.test.ts‎

Copy file name to clipboardExpand all lines: packages/ai/test/provider/bedrock-converse.test.ts
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,59 @@ describe("Bedrock Converse route", () => {
491491
}),
492492
)
493493

494+
it.effect("ignores late tool deltas after contentBlockStop", () =>
495+
Effect.gen(function* () {
496+
const body = eventStreamBody(
497+
[
498+
"contentBlockStart",
499+
{
500+
contentBlockIndex: 0,
501+
start: { toolUse: { toolUseId: "tool_1", name: "lookup" } },
502+
},
503+
],
504+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: '{"query":"weather"}' } } }],
505+
["contentBlockStop", { contentBlockIndex: 0 }],
506+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: '{"late":true}' } } }],
507+
["messageStop", { stopReason: "tool_use" }],
508+
)
509+
const response = yield* LLMClient.generate(baseRequest).pipe(Effect.provide(fixedBytes(body)))
510+
511+
expect(response.toolCalls).toEqual([
512+
{ type: "tool-call", id: "tool_1", name: "lookup", input: { query: "weather" } },
513+
])
514+
expect(response.events.filter((event) => event.type === "tool-input-delta")).toEqual([
515+
{
516+
type: "tool-input-delta",
517+
id: "tool_1",
518+
name: "lookup",
519+
text: '{"query":"weather"}',
520+
input: { query: "weather" },
521+
},
522+
])
523+
}),
524+
)
525+
526+
it.effect("rejects tool deltas without contentBlockStart", () =>
527+
Effect.gen(function* () {
528+
const error = yield* LLMClient.generate(baseRequest).pipe(
529+
Effect.provide(
530+
fixedBytes(
531+
eventStreamBody(
532+
["contentBlockDelta", { contentBlockIndex: 0, delta: { toolUse: { input: "{}" } } }],
533+
["messageStop", { stopReason: "tool_use" }],
534+
),
535+
),
536+
),
537+
Effect.flip,
538+
)
539+
540+
expect(error).toMatchObject({
541+
reason: { _tag: "InvalidProviderOutput" },
542+
message: "Bedrock Converse tool delta is missing its tool call",
543+
})
544+
}),
545+
)
546+
494547
it.effect("recovers incomplete tool input at finalization", () =>
495548
Effect.gen(function* () {
496549
const body = eventStreamBody(

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.