





















@@ -17,6 +17,7 @@ const DEFAULT_HTTP_TIMEOUT_MS = 15_000;
1717const DEFAULT_LEASE_TTL_MS = 20 * 60 * 1_000;
1818const RETRY_BACKOFF_MS = [500, 1_000, 2_000, 4_000, 5_000] as const;
1919const RETRYABLE_ACQUIRE_CODES = new Set(["POOL_EXHAUSTED", "NO_CREDENTIAL_AVAILABLE"]);
20+const CHUNKED_PAYLOAD_MARKER = "__openclawQaCredentialPayloadChunksV1";
20212122const convexAcquireSuccessSchema = z.object({
2223status: z.literal("ok"),
@@ -38,6 +39,11 @@ const convexOkSchema = z.object({
3839status: z.literal("ok"),
3940});
404142+const convexPayloadChunkSuccessSchema = z.object({
43+status: z.literal("ok"),
44+data: z.string(),
45+});
46+4147type ConvexCredentialBrokerConfig = {
4248acquireTimeoutMs: number;
4349acquireUrl: string;
@@ -47,6 +53,7 @@ type ConvexCredentialBrokerConfig = {
4753httpTimeoutMs: number;
4854leaseTtlMs: number;
4955ownerId: string;
56+payloadChunkUrl: string;
5057releaseUrl: string;
5158role: QaCredentialRole;
5259};
@@ -196,10 +203,39 @@ function resolveConvexCredentialBrokerConfig(params: {
196203),
197204acquireUrl: joinQaCredentialEndpoint(baseUrl, endpointPrefix, "acquire"),
198205heartbeatUrl: joinQaCredentialEndpoint(baseUrl, endpointPrefix, "heartbeat"),
206+payloadChunkUrl: joinQaCredentialEndpoint(baseUrl, endpointPrefix, "payload-chunk"),
199207releaseUrl: joinQaCredentialEndpoint(baseUrl, endpointPrefix, "release"),
200208};
201209}
202210211+function parseChunkedPayloadMarker(payload: unknown) {
212+if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
213+return null;
214+}
215+const record = payload as Record<string, unknown>;
216+if (record[CHUNKED_PAYLOAD_MARKER] !== true) {
217+return null;
218+}
219+if (
220+typeof record.chunkCount !== "number" ||
221+!Number.isInteger(record.chunkCount) ||
222+record.chunkCount < 1
223+) {
224+throw new Error("Chunked credential payload marker has an invalid chunkCount.");
225+}
226+if (
227+typeof record.byteLength !== "number" ||
228+!Number.isInteger(record.byteLength) ||
229+record.byteLength < 0
230+) {
231+throw new Error("Chunked credential payload marker has an invalid byteLength.");
232+}
233+return {
234+chunkCount: record.chunkCount,
235+byteLength: record.byteLength,
236+};
237+}
238+203239function toBrokerError(params: {
204240payload: unknown;
205241fallback: string;
@@ -259,6 +295,42 @@ async function postConvexBroker(params: {
259295return payload;
260296}
261297298+async function resolveConvexCredentialPayload(params: {
299+acquired: z.infer<typeof convexAcquireSuccessSchema>;
300+config: ConvexCredentialBrokerConfig;
301+fetchImpl: typeof fetch;
302+kind: string;
303+}) {
304+const marker = parseChunkedPayloadMarker(params.acquired.payload);
305+if (!marker) {
306+return params.acquired.payload;
307+}
308+const chunks: string[] = [];
309+for (let index = 0; index < marker.chunkCount; index += 1) {
310+const payload = await postConvexBroker({
311+fetchImpl: params.fetchImpl,
312+timeoutMs: params.config.httpTimeoutMs,
313+authToken: params.config.authToken,
314+url: params.config.payloadChunkUrl,
315+body: {
316+kind: params.kind,
317+ownerId: params.config.ownerId,
318+actorRole: params.config.role,
319+credentialId: params.acquired.credentialId,
320+leaseToken: params.acquired.leaseToken,
321+ index,
322+},
323+});
324+const parsed = convexPayloadChunkSuccessSchema.parse(payload);
325+chunks.push(parsed.data);
326+}
327+const serialized = chunks.join("");
328+if (serialized.length !== marker.byteLength) {
329+throw new Error("Chunked credential payload length mismatch.");
330+}
331+return JSON.parse(serialized) as unknown;
332+}
333+262334function computeAcquireBackoffMs(params: {
263335attempt: number;
264336randomImpl: () => number;
@@ -355,7 +427,13 @@ export async function acquireQaCredentialLease<TPayload>(
355427};
356428let parsedPayload: TPayload;
357429try {
358-parsedPayload = opts.parsePayload(acquired.payload);
430+const resolvedPayload = await resolveConvexCredentialPayload({
431+ acquired,
432+ config,
433+ fetchImpl,
434+kind: opts.kind,
435+});
436+parsedPayload = opts.parsePayload(resolvedPayload);
359437} catch (error) {
360438try {
361439await releaseLease();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。