@agentchatme/openclaw 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/RUNBOOK.md +2 -2
- package/dist/index.cjs +140 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -14
- package/dist/index.d.ts +46 -14
- package/dist/index.js +140 -50
- package/dist/index.js.map +1 -1
- package/dist/setup-entry.cjs +140 -50
- package/dist/setup-entry.cjs.map +1 -1
- package/dist/setup-entry.js +140 -50
- package/dist/setup-entry.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,11 @@ this package adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
7
7
|
|
|
8
8
|
This package is in pre-1.0 development.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## 0.8.1 — 2026-11-04
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **The socket no longer dies for good.** Three paths in `ws-client.ts` ended the doorbell permanently with nothing able to restart it: the client's own hello-ack timeout closed with 1008 and was then read as an auth rejection, so one slow handshake killed the integration until a gateway restart; sixty failed reconnects (about 27 minutes of a deploy, a DNS outage or a closed laptop) were escalated to the same dead `AUTH_FAIL`; and `reconfigured()`, the only exit, has no caller. Now a close the client initiated is never evidence about the server (it is tracked and takes the normal backoff), the hard cap is gone (after 60 attempts one error line is logged and the backoff cap widens to 5 minutes, retrying for as long as it takes), and a genuine server rejection (close `1008 Invalid token`, or 4401/4403) enters `AUTH_FAIL` but retries a fresh HELLO every 10–15 minutes, so a reinstated account or a key rotated back reconnects on its own. A `1008` with any other reason — the server's own `HELLO frame required` after a stalled event loop or a slow network leg — is a slow handshake and takes the normal backoff. At the gateway a rejected key is one `AUTH_FAIL (…)` error line and one steady `blocked` / `not-linked` status until a HELLO is accepted again (`key accepted again — AUTH_FAIL cleared` at info); the retries themselves are debug lines, not a health flap. `stop()` remains the only way the client ends; it now also cancels a pending retry timer instead of letting it open a socket after `closed`.
|
|
11
15
|
|
|
12
16
|
## 0.8.0 — 2026-11-02
|
|
13
17
|
|
package/RUNBOOK.md
CHANGED
|
@@ -74,7 +74,7 @@ Two error lines mean the doorbell is not doing its job:
|
|
|
74
74
|
|
|
75
75
|
### `AUTH_FAIL`
|
|
76
76
|
|
|
77
|
-
The key
|
|
77
|
+
The server rejected the key during the handshake (close `1008 Invalid token`: invalid, rotated, account suspended or deleted). The socket is not dead: it retries a fresh HELLO every 10–15 minutes, so an account that is reinstated or a key rotated back reconnects on its own. The gateway logs one `AUTH_FAIL (…) — the server rejected the key; retrying every 10–15 min` error line when the run starts and `key accepted again — AUTH_FAIL cleared` at info when it ends; in between the account stays `blocked` / `not-linked` in `openclaw channels capabilities` and each retry is a debug line. A `1008` with any other reason (`HELLO frame required` after a stalled event loop or a slow network leg) is a slow handshake, not a rejection, and takes the normal backoff. A new key still needs the steps below: the running gateway holds the old one.
|
|
78
78
|
|
|
79
79
|
1. `curl -H "Authorization: Bearer $AGENTCHAT_API_KEY" https://api.agentchat.me/v1/agents/me`
|
|
80
80
|
2. Rotate or recover: `openclaw channels add agentchat` → **Replace the API key** → paste / register / **Recover a lost API key** (handle + email code). The wizard re-places the key in `.env` and the identity line.
|
|
@@ -82,7 +82,7 @@ The key was rejected (invalid, revoked, or the reconnect hard cap was hit). AUTH
|
|
|
82
82
|
|
|
83
83
|
### Reconnect storm
|
|
84
84
|
|
|
85
|
-
The socket reconnects with exponential backoff (`reconnect.*`). `close-1011` is the client's own ping timeout
|
|
85
|
+
The socket reconnects with exponential backoff (`reconnect.*`) and never gives up on its own; only a stop ends it. `close-1011` is the client's own ping timeout, `close-1001` its own hello-ack timeout (the log line carries `ours: true`) or the server going away, `close-1006` an abnormal network close. After 60 consecutive failed attempts one error line (`still reconnecting after 60 attempts`) is logged and the backoff cap widens to 5 minutes until a HELLO succeeds. Nothing to do client-side if the API is down.
|
|
86
86
|
|
|
87
87
|
### Duplicate or missing turns
|
|
88
88
|
|
package/dist/index.cjs
CHANGED
|
@@ -159,7 +159,7 @@ function classifyNetworkError(err) {
|
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
// src/version.ts
|
|
162
|
-
var PACKAGE_VERSION = "0.8.
|
|
162
|
+
var PACKAGE_VERSION = "0.8.1";
|
|
163
163
|
|
|
164
164
|
// src/client-identity.ts
|
|
165
165
|
var AGENTCHAT_CLIENT_NAME = "openclaw";
|
|
@@ -1805,7 +1805,6 @@ function transition(state, event) {
|
|
|
1805
1805
|
return { kind: "CONNECTING", attempt: event.attempt, startedAt: event.now };
|
|
1806
1806
|
}
|
|
1807
1807
|
if (event.type === "DRAIN_REQUESTED") return { kind: "CLOSED" };
|
|
1808
|
-
if (event.type === "AUTH_REJECTED") return { kind: "AUTH_FAIL", reason: event.reason };
|
|
1809
1808
|
return state;
|
|
1810
1809
|
}
|
|
1811
1810
|
case "CONNECTING": {
|
|
@@ -1851,6 +1850,9 @@ function transition(state, event) {
|
|
|
1851
1850
|
return state;
|
|
1852
1851
|
}
|
|
1853
1852
|
case "AUTH_FAIL": {
|
|
1853
|
+
if (event.type === "CONNECT") {
|
|
1854
|
+
return { kind: "CONNECTING", attempt: event.attempt, startedAt: event.now };
|
|
1855
|
+
}
|
|
1854
1856
|
if (event.type === "RECONFIGURED") return { kind: "DISCONNECTED" };
|
|
1855
1857
|
if (event.type === "DRAIN_REQUESTED") return { kind: "CLOSED" };
|
|
1856
1858
|
return state;
|
|
@@ -1861,15 +1863,25 @@ function transition(state, event) {
|
|
|
1861
1863
|
}
|
|
1862
1864
|
}
|
|
1863
1865
|
function isTerminal(state) {
|
|
1864
|
-
return state.kind === "CLOSED"
|
|
1866
|
+
return state.kind === "CLOSED";
|
|
1865
1867
|
}
|
|
1866
1868
|
|
|
1867
1869
|
// src/ws-client.ts
|
|
1868
1870
|
var HELLO_ACK_TIMEOUT_MS = 4e3;
|
|
1869
|
-
var
|
|
1871
|
+
var RECONNECT_LONG_OUTAGE_AFTER_ATTEMPTS = 60;
|
|
1872
|
+
var RECONNECT_LONG_OUTAGE_BACKOFF_MS = 5 * 6e4;
|
|
1873
|
+
var AUTH_RETRY_INTERVAL_MS = 75e4;
|
|
1870
1874
|
var MAX_FRAME_BYTES = 2 * 1024 * 1024;
|
|
1871
1875
|
var HELLO_CAPABILITIES = ["ack"];
|
|
1872
|
-
var
|
|
1876
|
+
var UNAMBIGUOUS_AUTH_CLOSE_CODES = /* @__PURE__ */ new Set([4401, 4403]);
|
|
1877
|
+
var AMBIGUOUS_AUTH_CLOSE_CODE = 1008;
|
|
1878
|
+
var SERVER_AUTH_CLOSE_REASONS = ["invalid token"];
|
|
1879
|
+
function isHandshakeRejection(code, reason) {
|
|
1880
|
+
if (UNAMBIGUOUS_AUTH_CLOSE_CODES.has(code)) return true;
|
|
1881
|
+
if (code !== AMBIGUOUS_AUTH_CLOSE_CODE) return false;
|
|
1882
|
+
const lower = reason.toLowerCase();
|
|
1883
|
+
return SERVER_AUTH_CLOSE_REASONS.some((known) => lower.includes(known));
|
|
1884
|
+
}
|
|
1873
1885
|
var AgentchatWsClient = class {
|
|
1874
1886
|
config;
|
|
1875
1887
|
logger;
|
|
@@ -1885,6 +1897,15 @@ var AgentchatWsClient = class {
|
|
|
1885
1897
|
ws = null;
|
|
1886
1898
|
attempt = 0;
|
|
1887
1899
|
_ackNegotiated = false;
|
|
1900
|
+
/**
|
|
1901
|
+
* Set by `closeSocket()` before it closes the current socket, read and
|
|
1902
|
+
* cleared by `handleClose()`. A close this client asked for says nothing
|
|
1903
|
+
* about the server, whatever code travelled with it.
|
|
1904
|
+
*/
|
|
1905
|
+
closeInitiatedLocally = false;
|
|
1906
|
+
/** One error line per long outage / per run of rejected keys, then debug. */
|
|
1907
|
+
longOutageAnnounced = false;
|
|
1908
|
+
authFailAnnounced = false;
|
|
1888
1909
|
helloAckTimer = null;
|
|
1889
1910
|
pingTimer = null;
|
|
1890
1911
|
pongTimer = null;
|
|
@@ -1924,21 +1945,14 @@ var AgentchatWsClient = class {
|
|
|
1924
1945
|
return this._ackNegotiated;
|
|
1925
1946
|
}
|
|
1926
1947
|
/**
|
|
1927
|
-
* Kick off connection. No-op if already connecting, authenticating,
|
|
1928
|
-
*
|
|
1929
|
-
* after rotating the API key before retrying.
|
|
1948
|
+
* Kick off connection. No-op if already connecting, authenticating, ready,
|
|
1949
|
+
* or waiting out a backoff / auth retry. Throws only on `CLOSED`.
|
|
1930
1950
|
*/
|
|
1931
1951
|
start() {
|
|
1932
|
-
if (this.state.kind === "AUTH_FAIL") {
|
|
1933
|
-
throw new AgentChatChannelError(
|
|
1934
|
-
"terminal-auth",
|
|
1935
|
-
"cannot start: channel is in AUTH_FAIL \u2014 rotate api key and call reconfigured()"
|
|
1936
|
-
);
|
|
1937
|
-
}
|
|
1938
1952
|
if (this.state.kind === "CLOSED") {
|
|
1939
1953
|
throw new Error("cannot start: client is closed. Create a new instance.");
|
|
1940
1954
|
}
|
|
1941
|
-
if (this.state.kind !== "DISCONNECTED") {
|
|
1955
|
+
if (this.state.kind !== "DISCONNECTED" || this.reconnectTimer) {
|
|
1942
1956
|
return;
|
|
1943
1957
|
}
|
|
1944
1958
|
this.openSocket(1);
|
|
@@ -1971,13 +1985,15 @@ var AgentchatWsClient = class {
|
|
|
1971
1985
|
}
|
|
1972
1986
|
}
|
|
1973
1987
|
/**
|
|
1974
|
-
* Signal that operator has rotated the API key
|
|
1975
|
-
*
|
|
1976
|
-
*
|
|
1988
|
+
* Signal that the operator has rotated the API key: leave AUTH_FAIL and
|
|
1989
|
+
* retry now instead of waiting for the slow retry timer. A no-op in every
|
|
1990
|
+
* other state (the client is already connecting or connected).
|
|
1977
1991
|
*/
|
|
1978
1992
|
reconfigured() {
|
|
1979
1993
|
if (this.state.kind !== "AUTH_FAIL") return;
|
|
1994
|
+
this.clearReconnectTimer();
|
|
1980
1995
|
this.applyEvent({ type: "RECONFIGURED" });
|
|
1996
|
+
this.openSocket(1);
|
|
1981
1997
|
}
|
|
1982
1998
|
on(event, handler) {
|
|
1983
1999
|
this.listeners[event].add(handler);
|
|
@@ -1987,7 +2003,9 @@ var AgentchatWsClient = class {
|
|
|
1987
2003
|
}
|
|
1988
2004
|
// ─── Internals: socket lifecycle ─────────────────────────────────────
|
|
1989
2005
|
openSocket(attempt) {
|
|
2006
|
+
if (this.state.kind === "CLOSED") return;
|
|
1990
2007
|
this.attempt = attempt;
|
|
2008
|
+
this.closeInitiatedLocally = false;
|
|
1991
2009
|
const now = this.now();
|
|
1992
2010
|
this.applyEvent({ type: "CONNECT", now, attempt });
|
|
1993
2011
|
const url = `${this.config.apiBase.replace(/^http/, "ws")}/v1/ws`;
|
|
@@ -2059,7 +2077,7 @@ var AgentchatWsClient = class {
|
|
|
2059
2077
|
this.emitError(
|
|
2060
2078
|
new AgentChatChannelError("retry-transient", "hello ack timeout")
|
|
2061
2079
|
);
|
|
2062
|
-
this.closeSocket(
|
|
2080
|
+
this.closeSocket(1001, "hello ack timeout");
|
|
2063
2081
|
}, HELLO_ACK_TIMEOUT_MS);
|
|
2064
2082
|
}
|
|
2065
2083
|
handleMessage(data, isBinary) {
|
|
@@ -2146,26 +2164,43 @@ var AgentchatWsClient = class {
|
|
|
2146
2164
|
this.logger.info({ ackNegotiated: this._ackNegotiated }, "hello.ok");
|
|
2147
2165
|
this.applyEvent({ type: "HELLO_OK", now });
|
|
2148
2166
|
this.attempt = 0;
|
|
2167
|
+
this.longOutageAnnounced = false;
|
|
2168
|
+
this.authFailAnnounced = false;
|
|
2149
2169
|
this.startHeartbeat();
|
|
2150
2170
|
this.emit("authenticated", now);
|
|
2151
2171
|
}
|
|
2172
|
+
/** The server answered HELLO with a rejection frame (not a close). */
|
|
2152
2173
|
handleAuthRejected(reason) {
|
|
2153
2174
|
if (this.helloAckTimer) {
|
|
2154
2175
|
this._clearTimeout(this.helloAckTimer);
|
|
2155
2176
|
this.helloAckTimer = null;
|
|
2156
2177
|
}
|
|
2157
|
-
this.
|
|
2178
|
+
this.enterAuthFail(reason);
|
|
2179
|
+
this.closeSocket(1e3, "auth rejected");
|
|
2180
|
+
}
|
|
2181
|
+
/**
|
|
2182
|
+
* The server rejected this key. AUTH_FAIL is not the end: retry a fresh
|
|
2183
|
+
* HELLO every `AUTH_RETRY_INTERVAL_MS` (jittered). The first rejection in a
|
|
2184
|
+
* run logs at error so an operator sees it; the following ones at debug.
|
|
2185
|
+
*/
|
|
2186
|
+
enterAuthFail(reason) {
|
|
2187
|
+
this.logger[this.authFailAnnounced ? "debug" : "error"](
|
|
2188
|
+
{ reason, retryIntervalMs: AUTH_RETRY_INTERVAL_MS, attempt: this.attempt },
|
|
2189
|
+
"auth rejected \u2014 retrying slowly until the key is accepted again"
|
|
2190
|
+
);
|
|
2191
|
+
this.authFailAnnounced = true;
|
|
2158
2192
|
this.applyEvent({ type: "AUTH_REJECTED", reason });
|
|
2159
2193
|
this.emitError(
|
|
2160
2194
|
new AgentChatChannelError("terminal-auth", `auth rejected: ${reason}`)
|
|
2161
2195
|
);
|
|
2162
|
-
this.
|
|
2196
|
+
this.scheduleAuthRetry();
|
|
2163
2197
|
}
|
|
2164
2198
|
handleClose(code, reason) {
|
|
2165
|
-
this.now();
|
|
2166
2199
|
const wasAuthenticating = this.state.kind === "AUTHENTICATING";
|
|
2167
2200
|
const wasDraining = this.state.kind === "DRAINING";
|
|
2168
|
-
const
|
|
2201
|
+
const ours = this.closeInitiatedLocally;
|
|
2202
|
+
this.closeInitiatedLocally = false;
|
|
2203
|
+
const serverAuthClose = !ours && isHandshakeRejection(code, reason);
|
|
2169
2204
|
this.stopHeartbeat();
|
|
2170
2205
|
if (this.helloAckTimer) {
|
|
2171
2206
|
this._clearTimeout(this.helloAckTimer);
|
|
@@ -2173,19 +2208,17 @@ var AgentchatWsClient = class {
|
|
|
2173
2208
|
}
|
|
2174
2209
|
this.ws = null;
|
|
2175
2210
|
this._ackNegotiated = false;
|
|
2176
|
-
|
|
2211
|
+
const kind = this.state.kind;
|
|
2212
|
+
if (kind === "CLOSED") {
|
|
2177
2213
|
this.logger.debug({ code, reason }, "socket closed after CLOSED \u2014 no-op");
|
|
2178
2214
|
return;
|
|
2179
2215
|
}
|
|
2180
|
-
if (
|
|
2181
|
-
this.
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
)
|
|
2187
|
-
);
|
|
2188
|
-
this.emit("closed");
|
|
2216
|
+
if (kind === "AUTH_FAIL") {
|
|
2217
|
+
this.logger.debug({ code, reason }, "socket closed after AUTH_FAIL \u2014 retry already scheduled");
|
|
2218
|
+
return;
|
|
2219
|
+
}
|
|
2220
|
+
if (serverAuthClose && wasAuthenticating) {
|
|
2221
|
+
this.enterAuthFail(`close ${code}: ${reason}`);
|
|
2189
2222
|
return;
|
|
2190
2223
|
}
|
|
2191
2224
|
this.applyEvent({ type: "SOCKET_CLOSED", code, reason });
|
|
@@ -2194,13 +2227,14 @@ var AgentchatWsClient = class {
|
|
|
2194
2227
|
return;
|
|
2195
2228
|
}
|
|
2196
2229
|
this.logger.info(
|
|
2197
|
-
{ code, reason, attempt: this.attempt },
|
|
2230
|
+
{ code, reason, ours, attempt: this.attempt },
|
|
2198
2231
|
"socket closed \u2014 scheduling reconnect"
|
|
2199
2232
|
);
|
|
2200
2233
|
this.scheduleReconnect(`close-${code}`);
|
|
2201
2234
|
}
|
|
2202
2235
|
closeSocket(code, reason) {
|
|
2203
2236
|
if (!this.ws) return;
|
|
2237
|
+
this.closeInitiatedLocally = true;
|
|
2204
2238
|
try {
|
|
2205
2239
|
this.ws.close(code, reason);
|
|
2206
2240
|
} catch {
|
|
@@ -2260,14 +2294,15 @@ var AgentchatWsClient = class {
|
|
|
2260
2294
|
if (this.state.kind === "CLOSED" || this.state.kind === "AUTH_FAIL") return;
|
|
2261
2295
|
if (this.reconnectTimer) return;
|
|
2262
2296
|
const nextAttempt = this.attempt + 1;
|
|
2263
|
-
if (nextAttempt >
|
|
2264
|
-
|
|
2265
|
-
this.logger.error(
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2297
|
+
if (nextAttempt > RECONNECT_LONG_OUTAGE_AFTER_ATTEMPTS && !this.longOutageAnnounced) {
|
|
2298
|
+
this.longOutageAnnounced = true;
|
|
2299
|
+
this.logger.error(
|
|
2300
|
+
{
|
|
2301
|
+
attempt: nextAttempt,
|
|
2302
|
+
maxBackoffMs: Math.max(this.config.reconnect.maxBackoffMs, RECONNECT_LONG_OUTAGE_BACKOFF_MS)
|
|
2303
|
+
},
|
|
2304
|
+
`still reconnecting after ${RECONNECT_LONG_OUTAGE_AFTER_ATTEMPTS} attempts \u2014 backing off further, not giving up`
|
|
2269
2305
|
);
|
|
2270
|
-
return;
|
|
2271
2306
|
}
|
|
2272
2307
|
const delay = this.computeReconnectDelay(nextAttempt);
|
|
2273
2308
|
this.metrics.incReconnect({ reason });
|
|
@@ -2280,13 +2315,41 @@ var AgentchatWsClient = class {
|
|
|
2280
2315
|
this.openSocket(nextAttempt);
|
|
2281
2316
|
}, delay);
|
|
2282
2317
|
}
|
|
2318
|
+
/** AUTH_FAIL's own cadence: a fresh HELLO every AUTH_RETRY_INTERVAL_MS, jittered. */
|
|
2319
|
+
scheduleAuthRetry() {
|
|
2320
|
+
if (this.state.kind !== "AUTH_FAIL") return;
|
|
2321
|
+
this.clearReconnectTimer();
|
|
2322
|
+
const nextAttempt = this.attempt + 1;
|
|
2323
|
+
const delay = this.jittered(AUTH_RETRY_INTERVAL_MS);
|
|
2324
|
+
this.metrics.incReconnect({ reason: "auth-retry" });
|
|
2325
|
+
this.logger.debug({ attempt: nextAttempt, delayMs: delay }, "scheduling auth retry");
|
|
2326
|
+
this.reconnectTimer = this._setTimeout(() => {
|
|
2327
|
+
this.reconnectTimer = null;
|
|
2328
|
+
this.openSocket(nextAttempt);
|
|
2329
|
+
}, delay);
|
|
2330
|
+
}
|
|
2331
|
+
clearReconnectTimer() {
|
|
2332
|
+
if (this.reconnectTimer) {
|
|
2333
|
+
this._clearTimeout(this.reconnectTimer);
|
|
2334
|
+
this.reconnectTimer = null;
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2283
2337
|
computeReconnectDelay(attempt) {
|
|
2284
|
-
const { initialBackoffMs, maxBackoffMs
|
|
2338
|
+
const { initialBackoffMs, maxBackoffMs } = this.config.reconnect;
|
|
2285
2339
|
const reconnectCount = Math.max(1, attempt - 1);
|
|
2286
2340
|
const exp = initialBackoffMs * Math.pow(2, Math.min(reconnectCount - 1, 20));
|
|
2287
|
-
const
|
|
2341
|
+
const cap = attempt > RECONNECT_LONG_OUTAGE_AFTER_ATTEMPTS ? Math.max(maxBackoffMs, RECONNECT_LONG_OUTAGE_BACKOFF_MS) : maxBackoffMs;
|
|
2342
|
+
return this.jittered(Math.min(exp, cap));
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Symmetric ±`jitterRatio`. Thundering-herd-safe: a fleet that all drops
|
|
2346
|
+
* at the same instant re-enters the connect queue spread across
|
|
2347
|
+
* ms * [1-jitterRatio, 1+jitterRatio].
|
|
2348
|
+
*/
|
|
2349
|
+
jittered(ms) {
|
|
2350
|
+
const { jitterRatio } = this.config.reconnect;
|
|
2288
2351
|
const jitter = 1 - jitterRatio + this.random() * 2 * jitterRatio;
|
|
2289
|
-
return Math.max(0, Math.floor(
|
|
2352
|
+
return Math.max(0, Math.floor(ms * jitter));
|
|
2290
2353
|
}
|
|
2291
2354
|
// ─── Internals: drain ────────────────────────────────────────────────
|
|
2292
2355
|
scheduleDrainDeadline(deadline) {
|
|
@@ -2329,6 +2392,9 @@ var AgentchatWsClient = class {
|
|
|
2329
2392
|
return;
|
|
2330
2393
|
}
|
|
2331
2394
|
this.state = next;
|
|
2395
|
+
if (next.kind === "CLOSED") {
|
|
2396
|
+
this.clearReconnectTimer();
|
|
2397
|
+
}
|
|
2332
2398
|
this.metrics.setConnectionState(next.kind);
|
|
2333
2399
|
this.logger.info(
|
|
2334
2400
|
{ from: prev.kind, to: next.kind, event: event.type },
|
|
@@ -3439,6 +3505,7 @@ var agentchatGatewayAdapter = {
|
|
|
3439
3505
|
gateFailOpen: readEnv_js.readReplyGateFailOpenFromEnv(),
|
|
3440
3506
|
...gateTimeoutMs !== void 0 ? { gateTimeoutMs } : {}
|
|
3441
3507
|
});
|
|
3508
|
+
let authBlocked = false;
|
|
3442
3509
|
return {
|
|
3443
3510
|
invoker,
|
|
3444
3511
|
handlers: {
|
|
@@ -3450,16 +3517,39 @@ var agentchatGatewayAdapter = {
|
|
|
3450
3517
|
void catchUpInvites(ctx.accountId, config, invoker, logger);
|
|
3451
3518
|
},
|
|
3452
3519
|
onError: (err) => {
|
|
3453
|
-
|
|
3520
|
+
const level = err.class_ === "terminal-auth" && authBlocked ? "debug" : "warn";
|
|
3521
|
+
ctx.log?.[level]?.(`[agentchat:${ctx.accountId}] runtime error: ${err.message} (class=${err.class_})`);
|
|
3454
3522
|
},
|
|
3455
3523
|
onStateChanged: (next) => {
|
|
3456
|
-
const running = next.kind !== "CLOSED" && next.kind !== "AUTH_FAIL";
|
|
3457
|
-
const connected = next.kind === "READY" || next.kind === "DEGRADED";
|
|
3458
|
-
const lifecycle = next.kind === "READY" || next.kind === "DEGRADED" ? "ready" : next.kind === "AUTH_FAIL" ? "blocked" : next.kind === "CLOSED" ? "stopped" : runtime.getHealth().counters.knocks > 0 ? "recovering" : "starting";
|
|
3459
|
-
ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running, connected, statusState: statusStateFor(next.kind) }, lifecycle));
|
|
3460
3524
|
if (next.kind === "AUTH_FAIL") {
|
|
3461
|
-
|
|
3525
|
+
if (authBlocked) {
|
|
3526
|
+
ctx.log?.debug?.(`[agentchat:${ctx.accountId}] still AUTH_FAIL (${next.reason}) \u2014 next retry in 10\u201315 min`);
|
|
3527
|
+
return;
|
|
3528
|
+
}
|
|
3529
|
+
authBlocked = true;
|
|
3530
|
+
ctx.log?.error?.(
|
|
3531
|
+
`[agentchat:${ctx.accountId}] AUTH_FAIL (${next.reason}) \u2014 the server rejected the key; retrying every 10\u201315 min; rotate the key or re-run openclaw channels add agentchat`
|
|
3532
|
+
);
|
|
3533
|
+
ctx.setStatus(
|
|
3534
|
+
withLifecycle(
|
|
3535
|
+
{ ...ctx.getStatus(), running: false, connected: false, statusState: "not-linked", lastDisconnect: { at: Date.now(), error: `AUTH_FAIL: ${next.reason}` } },
|
|
3536
|
+
"blocked"
|
|
3537
|
+
)
|
|
3538
|
+
);
|
|
3539
|
+
return;
|
|
3540
|
+
}
|
|
3541
|
+
if (authBlocked && next.kind !== "READY" && next.kind !== "CLOSED") {
|
|
3542
|
+
ctx.log?.debug?.(`[agentchat:${ctx.accountId}] AUTH_FAIL retry: ${next.kind.toLowerCase()}`);
|
|
3543
|
+
return;
|
|
3544
|
+
}
|
|
3545
|
+
if (authBlocked) {
|
|
3546
|
+
authBlocked = false;
|
|
3547
|
+
if (next.kind === "READY") ctx.log?.info?.(`[agentchat:${ctx.accountId}] key accepted again \u2014 AUTH_FAIL cleared`);
|
|
3462
3548
|
}
|
|
3549
|
+
const running = next.kind !== "CLOSED";
|
|
3550
|
+
const connected = next.kind === "READY" || next.kind === "DEGRADED";
|
|
3551
|
+
const lifecycle = next.kind === "READY" || next.kind === "DEGRADED" ? "ready" : next.kind === "CLOSED" ? "stopped" : runtime.getHealth().counters.knocks > 0 ? "recovering" : "starting";
|
|
3552
|
+
ctx.setStatus(withLifecycle({ ...ctx.getStatus(), running, connected, statusState: statusStateFor(next.kind) }, lifecycle));
|
|
3463
3553
|
}
|
|
3464
3554
|
}
|
|
3465
3555
|
};
|