Skip to content

Commit 5cabd2b

Browse files
authored
Revert "fix(providers): report request acceptance consistently (#125807)" (#126021)
This reverts commit f5e9622.
1 parent 39b39ca commit 5cabd2b

44 files changed

Lines changed: 164 additions & 1261 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/plugins/sdk-provider-plugins.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,6 @@ catalog, API-key auth, and dynamic model resolution.
716716
| `validateReplayTurns` | Strict replay-turn validation before the embedded runner |
717717
| `onModelSelected` | Post-selection callback (e.g. telemetry) |
718718

719-
Custom `createStreamFn` transports must report provider acceptance before exposing the first stream event. Import the lifecycle helpers from `openclaw/plugin-sdk/provider-lifecycle`. Use `notifyProviderHttpResponse` when the transport owns a real `Response`, or `notifyProviderHttpMetadata` when an SDK exposes the real status and headers without the response body. Both helpers also run the compatibility `onResponse` callback. Use `notifyProviderStreamOpened` when an SDK returns an open stream but hides HTTP metadata; it never invents status or headers. Stream wrappers must forward `onProviderAccepted` and `onResponse` unchanged.
720-
721719
Runtime fallback notes:
722720

723721
- `normalizeConfig` resolves one owning plugin per provider id (bundled providers first, then the matched runtime plugin) and calls only that hook - there is no scan across other providers. Google's own `normalizeConfig` hook is what normalizes `google` / `google-vertex` / `google-antigravity` config entries; it is not a separate core fallback.

‎docs/plugins/sdk-subpaths.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ are private-local.
149149
| `plugin-sdk/provider-catalog-runtime` | Provider catalog augmentation runtime hook and plugin-provider registry seams for contract tests |
150150
| `plugin-sdk/provider-catalog-shared` | Private-local after July 2026; `findCatalogTemplate`, `buildSingleProviderApiKeyCatalog`, `buildManifestModelProviderConfig`, `supportsNativeStreamingUsageCompat`, `applyProviderNativeStreamingUsageCompat` |
151151
| `plugin-sdk/provider-http` | Private-local after July 2026; Generic provider HTTP/endpoint capability helpers, provider HTTP errors, and audio transcription multipart form helpers |
152-
| `plugin-sdk/provider-lifecycle` | Supported provider request-acceptance types and helpers for real HTTP metadata and metadata-free SDK or WebSocket streams |
153152
| `plugin-sdk/provider-binary-stream` | Direct-reader bounded binary streams with fitting-prefix delivery and explicit overflow/release errors |
154153
| `plugin-sdk/provider-web-fetch-contract` | Private-local after July 2026; Narrow web-fetch config/selection contract helpers such as `enablePluginInConfig` and `WebFetchProviderPlugin` |
155154
| `plugin-sdk/provider-web-fetch` | Private-local after July 2026; Web-fetch provider registration/cache helpers |

‎extensions/amazon-bedrock-mantle/mantle-anthropic.runtime.test.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ describe("createMantleAnthropicStreamFn", () => {
6060
const context = { messages: [] };
6161
const deps = createTestDeps();
6262
deps.stream.mockReturnValue(stream as never);
63-
const onProviderAccepted = vi.fn();
64-
const onResponse = vi.fn();
6563

6664
const result = createMantleAnthropicStreamFn(deps)(model, context, {
6765
apiKey: "bedrock-bearer-token",
68-
onProviderAccepted,
69-
onResponse,
7066
headers: {
7167
"X-Caller": "caller-header",
7268
},
@@ -91,8 +87,6 @@ describe("createMantleAnthropicStreamFn", () => {
9187
"bedrock-bearer-token",
9288
);
9389
expect(streamOptions.thinkingEnabled).toBe(false);
94-
expect(streamOptions.onProviderAccepted).toBe(onProviderAccepted);
95-
expect(streamOptions.onResponse).toBe(onResponse);
9690
});
9791

9892
it("omits unsupported Opus 4.7 sampling and reasoning overrides", () => {

‎extensions/amazon-bedrock-mantle/mantle-anthropic.runtime.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ function buildMantleAnthropicBaseOptions(
136136
cacheRetention: options?.cacheRetention,
137137
sessionId: options?.sessionId,
138138
onPayload: options?.onPayload,
139-
onProviderAccepted: options?.onProviderAccepted,
140-
onResponse: options?.onResponse,
141139
maxRetryDelayMs: options?.maxRetryDelayMs,
142140
metadata: options?.metadata,
143141
};

‎extensions/amazon-bedrock/stream.runtime.test.ts‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,36 +119,19 @@ describe("Bedrock stream client lifecycle", () => {
119119
yield { messageStop: { stopReason: BedrockStopReason.END_TURN } };
120120
}
121121
const send = vi.spyOn(BedrockRuntimeClient.prototype, "send").mockResolvedValue({
122-
$metadata: { httpStatusCode: 200, requestId: "bedrock-request-1" },
122+
$metadata: { httpStatusCode: 200 },
123123
stream: successfulStream(),
124124
} as never);
125125
const destroy = vi.spyOn(BedrockRuntimeClient.prototype, "destroy");
126-
const onProviderAccepted = vi.fn();
127-
const onResponse = vi.fn();
128126

129-
const resultPromise = streamBedrockForTest(bedrockModel({}), context, {
130-
onProviderAccepted,
131-
onResponse,
132-
}).result();
127+
const resultPromise = streamBedrockForTest(bedrockModel({}), context).result();
133128
await streamBlocked;
134129
expect(destroy).not.toHaveBeenCalled();
135130

136131
releaseStream();
137132
const result = await resultPromise;
138133

139134
expect(result.stopReason).toBe("stop");
140-
expect(onProviderAccepted).toHaveBeenCalledWith(
141-
{
142-
kind: "http_response",
143-
status: 200,
144-
headers: { "x-amzn-requestid": "bedrock-request-1" },
145-
},
146-
expect.objectContaining({ provider: "amazon-bedrock" }),
147-
);
148-
expect(onResponse).toHaveBeenCalledWith(
149-
{ status: 200, headers: { "x-amzn-requestid": "bedrock-request-1" } },
150-
expect.objectContaining({ provider: "amazon-bedrock" }),
151-
);
152135
expectDestroyedClient(send, destroy);
153136
});
154137

‎extensions/amazon-bedrock/stream.runtime.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import {
5555
type ToolResultMessage,
5656
} from "openclaw/plugin-sdk/llm";
5757
import { canonicalizeBase64 } from "openclaw/plugin-sdk/media-runtime";
58-
import { notifyProviderHttpMetadata } from "openclaw/plugin-sdk/provider-lifecycle";
5958
import {
6059
resolveClaudeFable5ModelIdentity,
6160
resolveClaudeModelIdentity,
@@ -284,11 +283,10 @@ const streamBedrock: StreamFunction<"bedrock-converse-stream", BedrockOptions> =
284283
if (response.$metadata.requestId) {
285284
responseHeaders["x-amzn-requestid"] = response.$metadata.requestId;
286285
}
287-
await notifyProviderHttpMetadata({
288-
options,
289-
response: { status: response.$metadata.httpStatusCode, headers: responseHeaders },
286+
await options?.onResponse?.(
287+
{ status: response.$metadata.httpStatusCode, headers: responseHeaders },
290288
model,
291-
});
289+
);
292290
}
293291

294292
let sawMessageStop = false;

‎extensions/anthropic-vertex/stream-runtime.test.ts‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -541,26 +541,6 @@ describe("createAnthropicVertexStreamFn", () => {
541541
expect(transportOptions).not.toHaveProperty("temperature");
542542
});
543543

544-
it("forwards provider acceptance hooks to the shared Anthropic transport", () => {
545-
const { deps, streamAnthropicMock } = createStreamDeps();
546-
const streamFn = createAnthropicVertexStreamFn("vertex-project", "us-east5", undefined, deps);
547-
const onProviderAccepted = vi.fn();
548-
const onResponse = vi.fn();
549-
550-
void streamFn(
551-
makeModel({ id: "claude-sonnet-4-6" }),
552-
{ messages: [] },
553-
{
554-
onProviderAccepted,
555-
onResponse,
556-
},
557-
);
558-
559-
const transportOptions = streamTransportOptions(streamAnthropicMock);
560-
expect(transportOptions.onProviderAccepted).toBe(onProviderAccepted);
561-
expect(transportOptions.onResponse).toBe(onResponse);
562-
});
563-
564544
it("keeps already-budgeted cache_control markers intact when forwarding payload hooks", async () => {
565545
const { deps, streamAnthropicMock } = createStreamDeps();
566546
const onPayload = vi.fn(async (payload: unknown) => payload);

‎extensions/anthropic-vertex/stream-runtime.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ export function createAnthropicVertexStreamFn(
231231
// cache boundary and budgets all cache_control markers; re-applying the
232232
// payload policy here marked the uncached suffix and breached the 4-marker cap.
233233
onPayload: options?.onPayload,
234-
onProviderAccepted: options?.onProviderAccepted,
235-
onResponse: options?.onResponse,
236234
maxRetryDelayMs: options?.maxRetryDelayMs,
237235
metadata: options?.metadata,
238236
};

‎extensions/google/transport-stream.test.ts‎

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -630,58 +630,6 @@ describe("google transport stream", () => {
630630
expect(guardedFetchMock).not.toHaveBeenCalled();
631631
});
632632

633-
it("reports the real HTTP response before consuming Gemini SSE output", async () => {
634-
mockGoogleTextResponse();
635-
const onProviderAccepted = vi.fn();
636-
const onResponse = vi.fn();
637-
638-
const result = await runGeminiStreamResult({
639-
options: { onProviderAccepted, onResponse },
640-
});
641-
642-
expect(result.stopReason).toBe("stop");
643-
expect(onProviderAccepted).toHaveBeenCalledWith(
644-
{
645-
kind: "http_response",
646-
status: 200,
647-
headers: { "content-type": "text/event-stream" },
648-
},
649-
expect.objectContaining({ provider: "google" }),
650-
);
651-
expect(onResponse).toHaveBeenCalledWith(
652-
{ status: 200, headers: { "content-type": "text/event-stream" } },
653-
expect.objectContaining({ provider: "google" }),
654-
);
655-
});
656-
657-
it("reports rejected HTTP responses without marking them accepted", async () => {
658-
guardedFetchMock.mockResolvedValueOnce(
659-
new Response('{"error":{"message":"rate limited"}}', {
660-
status: 429,
661-
headers: {
662-
"content-type": "application/json",
663-
"x-request-id": "req-rejected",
664-
},
665-
}),
666-
);
667-
const onProviderAccepted = vi.fn();
668-
const onResponse = vi.fn();
669-
670-
const result = await runGeminiStreamResult({
671-
options: { onProviderAccepted, onResponse },
672-
});
673-
674-
expect(result.stopReason).toBe("error");
675-
expect(onProviderAccepted).not.toHaveBeenCalled();
676-
expect(onResponse).toHaveBeenCalledWith(
677-
{
678-
status: 429,
679-
headers: expect.objectContaining({ "x-request-id": "req-rejected" }),
680-
},
681-
expect.objectContaining({ provider: "google" }),
682-
);
683-
});
684-
685633
it("uses the guarded fetch transport and parses Gemini SSE output", async () => {
686634
guardedFetchMock.mockResolvedValueOnce(
687635
buildSseResponse([
@@ -1471,106 +1419,6 @@ describe("google transport stream", () => {
14711419
},
14721420
);
14731421

1474-
it("does not retry when a slow provider acceptance callback rejects", async () => {
1475-
vi.stubEnv("OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS", "10");
1476-
let cancelCalled = false;
1477-
guardedFetchMock.mockResolvedValueOnce(
1478-
buildOpenRawSseResponse({
1479-
sse: 'data: {"candidates":[{"finishReason":"STOP"}]}\n\n',
1480-
onCancel: () => {
1481-
cancelCalled = true;
1482-
},
1483-
}),
1484-
);
1485-
1486-
const result = await runGeminiStreamResult({
1487-
model: buildGeminiModel({ id: "gemini-3.1-pro-preview" }),
1488-
options: {
1489-
reasoning: "high",
1490-
onProviderAccepted: async () => {
1491-
await new Promise((resolve) => {
1492-
setTimeout(resolve, 25);
1493-
});
1494-
throw new Error("acceptance callback failed");
1495-
},
1496-
},
1497-
});
1498-
1499-
expect(result).toMatchObject({
1500-
stopReason: "error",
1501-
errorMessage: "acceptance callback failed",
1502-
});
1503-
expect(guardedFetchMock).toHaveBeenCalledOnce();
1504-
expect(cancelCalled).toBe(true);
1505-
});
1506-
1507-
it.each(["onProviderAccepted", "onResponse"] as const)(
1508-
"aborts a pending %s callback without retrying",
1509-
async (hookName) => {
1510-
vi.stubEnv("OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS", "1000");
1511-
const controller = new AbortController();
1512-
const cancel = vi.fn();
1513-
guardedFetchMock.mockResolvedValueOnce(
1514-
buildOpenRawSseResponse({
1515-
sse: 'data: {"candidates":[{"finishReason":"STOP"}]}\n\n',
1516-
onCancel: cancel,
1517-
}),
1518-
);
1519-
let markHookStarted!: () => void;
1520-
const hookStarted = new Promise<void>((resolve) => {
1521-
markHookStarted = resolve;
1522-
});
1523-
const hook = vi.fn(() => {
1524-
markHookStarted();
1525-
return new Promise<void>(() => {});
1526-
});
1527-
1528-
const resultPromise = runGeminiStreamResult({
1529-
model: buildGeminiModel({ id: "gemini-3.1-pro-preview" }),
1530-
options: {
1531-
reasoning: "high",
1532-
signal: controller.signal,
1533-
[hookName]: hook,
1534-
},
1535-
});
1536-
await hookStarted;
1537-
controller.abort(
1538-
Object.assign(new Error("operator canceled the request"), {
1539-
code: "OPERATOR_CANCELLED",
1540-
}),
1541-
);
1542-
1543-
await expect(resultPromise).resolves.toMatchObject({
1544-
stopReason: "aborted",
1545-
errorCode: "OPERATOR_CANCELLED",
1546-
errorMessage: "operator canceled the request",
1547-
});
1548-
expect(hook).toHaveBeenCalledOnce();
1549-
expect(guardedFetchMock).toHaveBeenCalledOnce();
1550-
expect(cancel).toHaveBeenCalledOnce();
1551-
},
1552-
);
1553-
1554-
it("does not count provider acceptance callback time against the retry deadline", async () => {
1555-
vi.stubEnv("OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS", "10");
1556-
mockGoogleTextResponse("accepted");
1557-
1558-
const result = await runGeminiStreamResult({
1559-
model: buildGeminiModel({ id: "gemini-3.1-pro-preview" }),
1560-
options: {
1561-
reasoning: "high",
1562-
onProviderAccepted: async () => {
1563-
await new Promise((resolve) => {
1564-
setTimeout(resolve, 25);
1565-
});
1566-
},
1567-
},
1568-
});
1569-
1570-
expect(result.content).toEqual([{ type: "text", text: "accepted" }]);
1571-
expect(guardedFetchMock).toHaveBeenCalledOnce();
1572-
});
1573-
15741422
it("keeps oversized-video shedding in the Gemini 3 retry payload", async () => {
15751423
vi.stubEnv("OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS", "10");
15761424
guardedFetchMock

0 commit comments

Comments
 (0)