replicas-engine 0.1.1221 → 0.1.1223
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/{asp-host-MTMDV3HK.js → asp-host-J6MUQPK6.js} +2 -2
- package/dist/src/{chunk-LO42IHKY.js → chunk-BY64IPRE.js} +3 -3
- package/dist/src/{chunk-3M2EIHTB.js → chunk-CISR2MNI.js} +1 -1
- package/dist/src/{chunk-BF4B3STE.js → chunk-GXL65UNT.js} +1 -1
- package/dist/src/headless-agent.js +2 -2
- package/dist/src/index.js +3 -3
- package/package.json +1 -1
- package/scripts/engine-watchdog.sh +49 -8
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
listRunningCodexModels,
|
|
9
9
|
restartCodexAspHost,
|
|
10
10
|
restartCodexAspHostIfRunning
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-BY64IPRE.js";
|
|
12
12
|
import "./chunk-KQWDACDY.js";
|
|
13
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-GXL65UNT.js";
|
|
14
14
|
import "./chunk-XMAORHV5.js";
|
|
15
15
|
import "./chunk-UZSNFLDQ.js";
|
|
16
16
|
import "./chunk-VJTB4BFU.js";
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
AppServerProcess,
|
|
16
16
|
buildCodexAgentEnv
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-GXL65UNT.js";
|
|
18
18
|
import {
|
|
19
19
|
SUBPROCESS_MAX_BUFFER,
|
|
20
20
|
execFileAsync
|
|
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
291
291
|
await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
|
|
292
292
|
await this.applyCredentialsResponse(data);
|
|
293
293
|
setAgentCredentialSnapshot("codex", data);
|
|
294
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
294
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-J6MUQPK6.js");
|
|
295
295
|
await restartCodexAspHostIfRunning2();
|
|
296
296
|
});
|
|
297
297
|
await this.start(true);
|
|
@@ -313,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
313
313
|
const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
|
|
314
314
|
await this.applyCredentialsResponse(data);
|
|
315
315
|
if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
|
|
316
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
316
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-J6MUQPK6.js");
|
|
317
317
|
await restartCodexAspHostIfRunning2();
|
|
318
318
|
}
|
|
319
319
|
setAgentCredentialSnapshot("codex", data);
|
|
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
|
|
|
240
240
|
if (method === "foundry") return "azure";
|
|
241
241
|
return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
|
|
242
242
|
}
|
|
243
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
243
|
+
var ENGINE_PACKAGE_VERSION = "0.1.1223";
|
|
244
244
|
var INITIALIZE_METHOD = "initialize";
|
|
245
245
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
246
246
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
recoverCompletedTurn,
|
|
14
14
|
spawnMuseMsp,
|
|
15
15
|
startMuseSession
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-CISR2MNI.js";
|
|
17
17
|
import {
|
|
18
18
|
AppServerProcess,
|
|
19
19
|
buildCodexAgentEnv
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-GXL65UNT.js";
|
|
21
21
|
import "./chunk-XMAORHV5.js";
|
|
22
22
|
import {
|
|
23
23
|
AGENT,
|
package/dist/src/index.js
CHANGED
|
@@ -64,7 +64,7 @@ import {
|
|
|
64
64
|
spawnMuseMsp,
|
|
65
65
|
startMuseSession,
|
|
66
66
|
uuidV7
|
|
67
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-CISR2MNI.js";
|
|
68
68
|
import {
|
|
69
69
|
publishedPullRequestUrls
|
|
70
70
|
} from "./chunk-SUSXUDD3.js";
|
|
@@ -140,7 +140,7 @@ import {
|
|
|
140
140
|
timestampFromSeconds,
|
|
141
141
|
upsertCredentialFileLines,
|
|
142
142
|
writeSecureCredentialFile
|
|
143
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-BY64IPRE.js";
|
|
144
144
|
import {
|
|
145
145
|
ENGINE_ENV,
|
|
146
146
|
monolithRequest,
|
|
@@ -152,7 +152,7 @@ import {
|
|
|
152
152
|
} from "./chunk-KQWDACDY.js";
|
|
153
153
|
import {
|
|
154
154
|
getCodexModelProvider
|
|
155
|
-
} from "./chunk-
|
|
155
|
+
} from "./chunk-GXL65UNT.js";
|
|
156
156
|
import {
|
|
157
157
|
SUBPROCESS_MAX_BUFFER,
|
|
158
158
|
execAsync,
|
package/package.json
CHANGED
|
@@ -9,8 +9,10 @@ PIDFILE="/tmp/replicas-engine.pid"
|
|
|
9
9
|
MAX_BACKOFF=60
|
|
10
10
|
BACKOFF=1
|
|
11
11
|
RESTART_COUNT=0
|
|
12
|
-
MAX_RESTARTS=20
|
|
13
12
|
STABLE_THRESHOLD=300
|
|
13
|
+
HEALTH_INTERVAL=10
|
|
14
|
+
HEALTH_TIMEOUT=10
|
|
15
|
+
HEALTH_MAX_TIMEOUTS=3
|
|
14
16
|
BUN_INSTALL="${BUN_INSTALL:-/usr/local/bun}"
|
|
15
17
|
if [ -d "$BUN_INSTALL/bin" ]; then
|
|
16
18
|
export BUN_INSTALL
|
|
@@ -37,6 +39,45 @@ cleanup() {
|
|
|
37
39
|
|
|
38
40
|
trap cleanup SIGTERM SIGINT
|
|
39
41
|
|
|
42
|
+
cpu_counters() {
|
|
43
|
+
awk '/^cpu /{print $2+$3+$4+$5+$6+$7+$8+$9, $5+$6; exit}' /proc/stat
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# The status route's rule (memory >= 90% or CPU >= 95%): a starved engine recovers once the load ends.
|
|
47
|
+
sandbox_overloaded() {
|
|
48
|
+
awk -v before="$1" -v after="$(cpu_counters)" '
|
|
49
|
+
/^MemTotal:/ { total = $2 }
|
|
50
|
+
/^MemAvailable:/ { available = $2 }
|
|
51
|
+
END {
|
|
52
|
+
split(before, b, " "); split(after, a, " ")
|
|
53
|
+
cpu = a[1] > b[1] ? 100 * (1 - (a[2] - b[2]) / (a[1] - b[1])) : 0
|
|
54
|
+
exit !((total > 0 && 100 * (total - available) / total >= 90) || cpu >= 95)
|
|
55
|
+
}' /proc/meminfo
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
# Only timeouts count: a refused connection means the engine is still booting.
|
|
59
|
+
monitor_engine_health() {
|
|
60
|
+
local pid=$1 timeouts=0 cpu
|
|
61
|
+
while kill -0 "$pid" 2>/dev/null; do
|
|
62
|
+
sleep "$HEALTH_INTERVAL" || true
|
|
63
|
+
cpu=$(cpu_counters)
|
|
64
|
+
curl -s -o /dev/null --noproxy "*" --max-time "$HEALTH_TIMEOUT" "http://127.0.0.1:${REPLICAS_ENGINE_PORT:-3737}/health"
|
|
65
|
+
if [ $? -ne 28 ]; then
|
|
66
|
+
timeouts=0
|
|
67
|
+
elif sandbox_overloaded "$cpu"; then
|
|
68
|
+
timeouts=0
|
|
69
|
+
log "Engine is slow to answer /health while the sandbox is overloaded. Leaving it."
|
|
70
|
+
else
|
|
71
|
+
timeouts=$((timeouts + 1))
|
|
72
|
+
fi
|
|
73
|
+
if [ "$timeouts" -ge "$HEALTH_MAX_TIMEOUTS" ]; then
|
|
74
|
+
log "Engine did not answer /health $timeouts times in a row. Killing it."
|
|
75
|
+
kill -KILL "$pid" 2>/dev/null
|
|
76
|
+
return
|
|
77
|
+
fi
|
|
78
|
+
done
|
|
79
|
+
}
|
|
80
|
+
|
|
40
81
|
# Default RLIMIT_MEMLOCK is 8 MB; engine needs ~120 MB. Cap at 512 MB so a
|
|
41
82
|
# runaway can't lock the whole sandbox.
|
|
42
83
|
sudo prlimit --memlock=536870912:536870912 --pid $$ 2>/dev/null || true
|
|
@@ -76,12 +117,8 @@ if [ -r "$ENGINE_BIN" ]; then
|
|
|
76
117
|
ENGINE_CMD=("$NODE_BIN" "$ENGINE_BIN")
|
|
77
118
|
fi
|
|
78
119
|
fi
|
|
120
|
+
# Never gives up: on the nohup launch path nothing would restart a watchdog that exited.
|
|
79
121
|
while true; do
|
|
80
|
-
if [ "$RESTART_COUNT" -ge "$MAX_RESTARTS" ]; then
|
|
81
|
-
log "Exceeded max restarts ($MAX_RESTARTS). Giving up."
|
|
82
|
-
exit 1
|
|
83
|
-
fi
|
|
84
|
-
|
|
85
122
|
BOOTSTRAP_LOG="/tmp/replicas-engine-bootstrap-$(date +%Y%m%d-%H%M%S).log"
|
|
86
123
|
log "Starting replicas-engine (attempt $((RESTART_COUNT + 1)))${ENGINE_FLAG:+ [$ENGINE_FLAG]}"
|
|
87
124
|
|
|
@@ -93,16 +130,20 @@ while true; do
|
|
|
93
130
|
fi
|
|
94
131
|
ENGINE_PID=$!
|
|
95
132
|
echo "$ENGINE_PID" > "$PIDFILE"
|
|
133
|
+
monitor_engine_health "$ENGINE_PID" &
|
|
134
|
+
MONITOR_PID=$!
|
|
96
135
|
|
|
97
136
|
wait "$ENGINE_PID"
|
|
98
137
|
EXIT_CODE=$?
|
|
138
|
+
kill "$MONITOR_PID" 2>/dev/null
|
|
99
139
|
END_TIME=$(date +%s)
|
|
100
140
|
UPTIME=$((END_TIME - START_TIME))
|
|
101
141
|
|
|
102
142
|
rm -f "$PIDFILE"
|
|
103
143
|
|
|
104
|
-
#
|
|
105
|
-
|
|
144
|
+
# Stopping the sandbox signals this watchdog (see cleanup), so an engine killed on its own
|
|
145
|
+
# (143 from an agent's `kill`/`pkill`, 137 from SIGKILL) is a crash to restart.
|
|
146
|
+
if [ $EXIT_CODE -eq 0 ]; then
|
|
106
147
|
log "Engine exited (code $EXIT_CODE). Not restarting."
|
|
107
148
|
exit 0
|
|
108
149
|
fi
|