mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 20:54:30 +00:00
fix(acp): wait for gateway connection before processing ACP messages
- Move gateway.start() before AgentSideConnection creation - Wait for hello message to confirm connection is established - This fixes issues where messages were processed before gateway was ready Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
59807efa31
commit
7499e0f619
@@ -12,7 +12,7 @@ import { readSecretFromFile } from "./secret-file.js";
|
|||||||
import { AcpGatewayAgent } from "./translator.js";
|
import { AcpGatewayAgent } from "./translator.js";
|
||||||
import type { AcpServerOptions } from "./types.js";
|
import type { AcpServerOptions } from "./types.js";
|
||||||
|
|
||||||
export function serveAcpGateway(opts: AcpServerOptions = {}): Promise<void> {
|
export async function serveAcpGateway(opts: AcpServerOptions = {}): Promise<void> {
|
||||||
const cfg = loadConfig();
|
const cfg = loadConfig();
|
||||||
const connection = buildGatewayConnectionDetails({
|
const connection = buildGatewayConnectionDetails({
|
||||||
config: cfg,
|
config: cfg,
|
||||||
@@ -80,6 +80,21 @@ export function serveAcpGateway(opts: AcpServerOptions = {}): Promise<void> {
|
|||||||
process.once("SIGINT", shutdown);
|
process.once("SIGINT", shutdown);
|
||||||
process.once("SIGTERM", shutdown);
|
process.once("SIGTERM", shutdown);
|
||||||
|
|
||||||
|
// Start gateway first and wait for connection before processing ACP messages
|
||||||
|
gateway.start();
|
||||||
|
|
||||||
|
// Use a promise to wait for hello (connection established)
|
||||||
|
const helloReceived = new Promise<void>((resolve) => {
|
||||||
|
const originalOnHelloOk = gateway.opts.onHelloOk;
|
||||||
|
gateway.opts.onHelloOk = (hello) => {
|
||||||
|
originalOnHelloOk?.(hello);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for gateway connection before creating AgentSideConnection
|
||||||
|
await helloReceived;
|
||||||
|
|
||||||
const input = Writable.toWeb(process.stdout);
|
const input = Writable.toWeb(process.stdout);
|
||||||
const output = Readable.toWeb(process.stdin) as unknown as ReadableStream<Uint8Array>;
|
const output = Readable.toWeb(process.stdin) as unknown as ReadableStream<Uint8Array>;
|
||||||
const stream = ndJsonStream(input, output);
|
const stream = ndJsonStream(input, output);
|
||||||
@@ -90,7 +105,6 @@ export function serveAcpGateway(opts: AcpServerOptions = {}): Promise<void> {
|
|||||||
return agent;
|
return agent;
|
||||||
}, stream);
|
}, stream);
|
||||||
|
|
||||||
gateway.start();
|
|
||||||
return closed;
|
return closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user