@clawling/clawchat-plugin-openclaw 2026.7.6-1 → 2026.7.6-2
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/dist/src/refresh-manager.js +19 -0
- package/package.json +1 -1
- package/src/refresh-manager.ts +21 -0
|
@@ -24,6 +24,13 @@ export const MIN_REFRESH_INTERVAL_MS = 30_000;
|
|
|
24
24
|
export const PROACTIVE_JITTER_MS = 5 * MINUTE_MS;
|
|
25
25
|
/** §A.0 — fallback access-token TTL when `exp` is unparseable. */
|
|
26
26
|
export const ACCESS_TOKEN_TTL_MS = 24 * HOUR_MS;
|
|
27
|
+
/**
|
|
28
|
+
* §A.1 — Node stores a `setTimeout` delay in a signed 32-bit int; a delay above
|
|
29
|
+
* this silently clamps to 1ms and fires *immediately*. Long-lived (~30-day)
|
|
30
|
+
* access tokens push `refresh_at - now` well past this, so the proactive wait is
|
|
31
|
+
* chunked into at-most-this-long sleeps that re-arm until the real time.
|
|
32
|
+
*/
|
|
33
|
+
export const MAX_TIMER_DELAY_MS = 2_147_483_647; // 2^31 - 1
|
|
27
34
|
/**
|
|
28
35
|
* §A.0/§A.1 — compute the absolute epoch-ms at which to proactively refresh.
|
|
29
36
|
* `refresh_at = exp - max(30min, min(2h, 0.25 * (exp - iat)))` plus jitter.
|
|
@@ -204,6 +211,18 @@ export class RefreshManager {
|
|
|
204
211
|
jitterMs,
|
|
205
212
|
});
|
|
206
213
|
const delayMs = Math.max(0, refreshAtMs - this.now());
|
|
214
|
+
if (delayMs > MAX_TIMER_DELAY_MS) {
|
|
215
|
+
// Too far out for a single setTimeout without 32-bit overflow (which would
|
|
216
|
+
// fire at 1ms and trigger an immediate refresh + WS reconnect, cancelling
|
|
217
|
+
// any in-flight send). Sleep one max chunk, then re-arm from the still-live
|
|
218
|
+
// token for the remaining wait.
|
|
219
|
+
this.ports.log?.debug?.(`clawchat-plugin-openclaw proactive timer chunked delayMs=${delayMs} chunk=${MAX_TIMER_DELAY_MS}`);
|
|
220
|
+
this.proactiveTimer = this.setTimer(() => {
|
|
221
|
+
this.proactiveTimer = null;
|
|
222
|
+
this.armProactiveTimer(activatedAtMs);
|
|
223
|
+
}, MAX_TIMER_DELAY_MS);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
207
226
|
this.ports.log?.debug?.(`clawchat-plugin-openclaw proactive timer armed delayMs=${delayMs}`);
|
|
208
227
|
this.proactiveTimer = this.setTimer(() => {
|
|
209
228
|
this.proactiveTimer = null;
|
package/package.json
CHANGED
package/src/refresh-manager.ts
CHANGED
|
@@ -32,6 +32,13 @@ export const MIN_REFRESH_INTERVAL_MS = 30_000;
|
|
|
32
32
|
export const PROACTIVE_JITTER_MS = 5 * MINUTE_MS;
|
|
33
33
|
/** §A.0 — fallback access-token TTL when `exp` is unparseable. */
|
|
34
34
|
export const ACCESS_TOKEN_TTL_MS = 24 * HOUR_MS;
|
|
35
|
+
/**
|
|
36
|
+
* §A.1 — Node stores a `setTimeout` delay in a signed 32-bit int; a delay above
|
|
37
|
+
* this silently clamps to 1ms and fires *immediately*. Long-lived (~30-day)
|
|
38
|
+
* access tokens push `refresh_at - now` well past this, so the proactive wait is
|
|
39
|
+
* chunked into at-most-this-long sleeps that re-arm until the real time.
|
|
40
|
+
*/
|
|
41
|
+
export const MAX_TIMER_DELAY_MS = 2_147_483_647; // 2^31 - 1
|
|
35
42
|
|
|
36
43
|
/** Opaque timer handle — `setTimeout` returns a `Timeout` in node, a number in others. */
|
|
37
44
|
export type TimerHandle = ReturnType<typeof setTimeout> | number;
|
|
@@ -296,6 +303,20 @@ export class RefreshManager {
|
|
|
296
303
|
jitterMs,
|
|
297
304
|
});
|
|
298
305
|
const delayMs = Math.max(0, refreshAtMs - this.now());
|
|
306
|
+
if (delayMs > MAX_TIMER_DELAY_MS) {
|
|
307
|
+
// Too far out for a single setTimeout without 32-bit overflow (which would
|
|
308
|
+
// fire at 1ms and trigger an immediate refresh + WS reconnect, cancelling
|
|
309
|
+
// any in-flight send). Sleep one max chunk, then re-arm from the still-live
|
|
310
|
+
// token for the remaining wait.
|
|
311
|
+
this.ports.log?.debug?.(
|
|
312
|
+
`clawchat-plugin-openclaw proactive timer chunked delayMs=${delayMs} chunk=${MAX_TIMER_DELAY_MS}`,
|
|
313
|
+
);
|
|
314
|
+
this.proactiveTimer = this.setTimer(() => {
|
|
315
|
+
this.proactiveTimer = null;
|
|
316
|
+
this.armProactiveTimer(activatedAtMs);
|
|
317
|
+
}, MAX_TIMER_DELAY_MS);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
299
320
|
this.ports.log?.debug?.(
|
|
300
321
|
`clawchat-plugin-openclaw proactive timer armed delayMs=${delayMs}`,
|
|
301
322
|
);
|