Skip to content

Commit ccb847e

Browse files
authored
fix(gateway): make startup control-plane retries explicit
* fix(gateway): make startup control-plane retries explicit * docs(changelog): note startup control-plane retry fix
1 parent ebc26a0 commit ccb847e

4 files changed

Lines changed: 49 additions & 29 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Docs: https://docs.openclaw.ai
231231
- Diagnostics: reset stuck-session timers on reply, tool, status, block, and ACP progress events, and back off repeated `session.stuck` diagnostics while a session remains unchanged. Supersedes #72010. Thanks @rubencu.
232232
- Gateway/agents: avoid rebuilding core tools for plugin-only allowlists and keep the full plugin registry cache warm across scoped plugin loads, reducing per-turn latency spikes. Fixes #75882, #75907, #75906, #75887, and #75851. (#75922) Thanks @obviyus.
233233
- Agents/failover: classify bare `status: internal server error` provider messages as retryable server errors so model fallback can rotate instead of stopping. (#73844) Thanks @thesomewhatyou.
234+
- Gateway/startup: return the shared retryable startup-sidecars error for startup-gated control-plane RPCs such as sessions.create, sessions.send, sessions.abort, agent.wait, and tools.effective, so clients can retry early sidecar races. (#76012) Thanks @scoootscooob.
234235

235236
## 2026.4.30
236237

‎src/gateway/server-methods.control-plane-rate-limit.test.ts‎

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {
33
__testing as controlPlaneRateLimitTesting,
44
resolveControlPlaneRateLimitKey,
55
} from "./control-plane-rate-limit.js";
6+
import { isRetryableGatewayStartupUnavailableError } from "./protocol/startup-unavailable.js";
67
import { handleGatewayRequest } from "./server-methods.js";
78
import type { GatewayRequestHandler } from "./server-methods/types.js";
9+
import { STARTUP_UNAVAILABLE_GATEWAY_METHODS } from "./server-startup-unavailable-methods.js";
810

911
const noWebchat = () => false;
1012

@@ -131,32 +133,37 @@ describe("gateway control-plane write rate limit", () => {
131133
expect(handlerCalls).toHaveBeenCalledTimes(4);
132134
});
133135

134-
it("blocks startup-gated methods before dispatch", async () => {
135-
const handlerCalls = vi.fn();
136-
const handler: GatewayRequestHandler = (opts) => {
137-
handlerCalls(opts);
138-
opts.respond(true, undefined, undefined);
139-
};
140-
const context = {
141-
...buildContext(),
142-
unavailableGatewayMethods: new Set(["chat.history", "models.list"]),
143-
} as Parameters<typeof handleGatewayRequest>[0]["context"];
144-
const client = buildClient();
145-
146-
const blocked = await runRequest({ method: "models.list", context, client, handler });
147-
148-
expect(handlerCalls).not.toHaveBeenCalled();
149-
expect(blocked).toHaveBeenCalledWith(
150-
false,
151-
undefined,
152-
expect.objectContaining({
153-
code: "UNAVAILABLE",
154-
retryable: true,
155-
retryAfterMs: 500,
156-
details: { method: "models.list" },
157-
}),
158-
);
159-
});
136+
it.each(STARTUP_UNAVAILABLE_GATEWAY_METHODS)(
137+
"blocks startup-gated method %s before dispatch with a retryable startup error",
138+
async (method) => {
139+
const handlerCalls = vi.fn();
140+
const handler: GatewayRequestHandler = (opts) => {
141+
handlerCalls(opts);
142+
opts.respond(true, undefined, undefined);
143+
};
144+
const context = {
145+
...buildContext(),
146+
unavailableGatewayMethods: new Set(STARTUP_UNAVAILABLE_GATEWAY_METHODS),
147+
} as Parameters<typeof handleGatewayRequest>[0]["context"];
148+
const client = buildClient();
149+
150+
const blocked = await runRequest({ method, context, client, handler });
151+
152+
expect(handlerCalls).not.toHaveBeenCalled();
153+
expect(blocked).toHaveBeenCalledWith(
154+
false,
155+
undefined,
156+
expect.objectContaining({
157+
code: "UNAVAILABLE",
158+
retryable: true,
159+
retryAfterMs: 500,
160+
details: { reason: "startup-sidecars", method },
161+
}),
162+
);
163+
const error = blocked.mock.calls[0]?.[2];
164+
expect(isRetryableGatewayStartupUnavailableError(error)).toBe(true);
165+
},
166+
);
160167

161168
it("uses connId fallback when both device and client IP are unknown", () => {
162169
const key = resolveControlPlaneRateLimitKey({

‎src/gateway/server-methods.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { formatControlPlaneActor, resolveControlPlaneActor } from "./control-pla
33
import { consumeControlPlaneWriteBudget } from "./control-plane-rate-limit.js";
44
import { ADMIN_SCOPE, authorizeOperatorScopesForMethod } from "./method-scopes.js";
55
import { ErrorCodes, errorShape } from "./protocol/index.js";
6+
import {
7+
gatewayStartupUnavailableDetails,
8+
GATEWAY_STARTUP_RETRY_AFTER_MS,
9+
} from "./protocol/startup-unavailable.js";
610
import { isRoleAuthorizedForMethod, parseGatewayRole } from "./role-policy.js";
711
import { agentHandlers } from "./server-methods/agent.js";
812
import { agentsHandlers } from "./server-methods/agents.js";
@@ -128,8 +132,8 @@ export async function handleGatewayRequest(
128132
undefined,
129133
errorShape(ErrorCodes.UNAVAILABLE, `${req.method} unavailable during gateway startup`, {
130134
retryable: true,
131-
retryAfterMs: 500,
132-
details: { method: req.method },
135+
retryAfterMs: GATEWAY_STARTUP_RETRY_AFTER_MS,
136+
details: { ...gatewayStartupUnavailableDetails(), method: req.method },
133137
}),
134138
);
135139
return;
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
export const STARTUP_UNAVAILABLE_GATEWAY_METHODS = ["chat.history", "models.list"] as const;
1+
export const STARTUP_UNAVAILABLE_GATEWAY_METHODS = [
2+
"agent.wait",
3+
"chat.history",
4+
"models.list",
5+
"sessions.abort",
6+
"sessions.create",
7+
"sessions.send",
8+
"tools.effective",
9+
] as const;

0 commit comments

Comments
 (0)