fix: register crash-recording exit handler after all validation passes

Move the process.on('exit') handler that records gateway crashes to
after all CLI validation checks (port, auth, bind, etc.) so that user
configuration errors are not incorrectly counted as gateway crashes.

Addresses review feedback from @greptile-apps.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Protocol-zero-0 2026-02-20 15:32:57 +00:00
parent 6eb7b2dc9d
commit 430b320cd0

View File

@ -215,12 +215,6 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
throw err;
}
process.on("exit", (code) => {
if (code !== 0) {
recordGatewayCrash(stateDir);
}
});
if (devMode) {
await ensureDevGatewayConfig({ reset: Boolean(opts.reset) });
}
@ -445,6 +439,12 @@ async function runGatewayCommand(opts: GatewayRunOpts) {
}
: undefined;
process.on("exit", (code) => {
if (code !== 0) {
recordGatewayCrash(stateDir);
}
});
try {
await runGatewayLoop({
runtime: defaultRuntime,