agent-relay-runner 0.10.3 → 0.10.5
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/package.json
CHANGED
package/src/runner.ts
CHANGED
|
@@ -82,6 +82,7 @@ export class AgentRunner {
|
|
|
82
82
|
this.bus.on("command", (type, params, commandId, command) => {
|
|
83
83
|
void this.handleCommand(type, params, commandId, command);
|
|
84
84
|
});
|
|
85
|
+
this.bus.on("error", (code, message) => this.handleBusError(String(code), String(message)));
|
|
85
86
|
await this.bus.connect();
|
|
86
87
|
this.process = await this.spawnProvider();
|
|
87
88
|
this.publishStatus();
|
|
@@ -171,6 +172,7 @@ export class AgentRunner {
|
|
|
171
172
|
if (target !== this.agentId && target !== this.options.runnerId) return;
|
|
172
173
|
if (type !== "agent.shutdown" && type !== "agent.restart" && type !== "agent.kill") return;
|
|
173
174
|
|
|
175
|
+
const exitAfterCommand = type !== "agent.restart";
|
|
174
176
|
this.claims.startClaim("command", commandId);
|
|
175
177
|
this.publishStatus();
|
|
176
178
|
await this.updateCommand(commandId, "accepted");
|
|
@@ -179,12 +181,18 @@ export class AgentRunner {
|
|
|
179
181
|
if (type === "agent.restart") await this.restartProvider();
|
|
180
182
|
else await this.shutdownProvider(type === "agent.kill");
|
|
181
183
|
await this.updateCommand(commandId, "succeeded", { action: type, agentId: this.agentId, runnerId: this.options.runnerId });
|
|
182
|
-
if (type !== "agent.restart") setTimeout(() => void this.stop().finally(() => process.exit(0)), 10);
|
|
183
184
|
} catch (error) {
|
|
184
|
-
await this.updateCommand(commandId, "failed", undefined, error instanceof Error ? error.message : String(error));
|
|
185
|
+
await this.updateCommand(commandId, "failed", undefined, error instanceof Error ? error.message : String(error)).catch(() => {});
|
|
185
186
|
} finally {
|
|
186
187
|
this.claims.finishClaim("command", commandId);
|
|
187
|
-
if (
|
|
188
|
+
if (exitAfterCommand) {
|
|
189
|
+
await this.http.deleteAgent(this.agentId).catch(() => {});
|
|
190
|
+
setTimeout(() => void this.stop().catch((error) => {
|
|
191
|
+
console.error(`[runner] stop after command failed: ${error}`);
|
|
192
|
+
}).finally(() => process.exit(0)), 10);
|
|
193
|
+
} else if (!this.stopped) {
|
|
194
|
+
this.publishStatus();
|
|
195
|
+
}
|
|
188
196
|
}
|
|
189
197
|
}
|
|
190
198
|
|
|
@@ -209,7 +217,6 @@ export class AgentRunner {
|
|
|
209
217
|
}
|
|
210
218
|
this.claims.setTerminalStatus("offline");
|
|
211
219
|
this.publishStatus();
|
|
212
|
-
await this.http.deleteAgent(this.agentId).catch(() => {});
|
|
213
220
|
this.stopped = true;
|
|
214
221
|
}
|
|
215
222
|
|
|
@@ -217,6 +224,17 @@ export class AgentRunner {
|
|
|
217
224
|
await this.bus.updateCommand(commandId, { status, ...(result ? { result } : {}), ...(error ? { error } : {}) });
|
|
218
225
|
}
|
|
219
226
|
|
|
227
|
+
private handleBusError(code: string, message: string): void {
|
|
228
|
+
const action = runnerBusErrorAction(code, this.stopped);
|
|
229
|
+
if (action === "ignore") return;
|
|
230
|
+
console.error(`[runner] bus error ${code}: ${message}`);
|
|
231
|
+
if (action === "stop") {
|
|
232
|
+
void this.stop().catch((error) => {
|
|
233
|
+
console.error(`[runner] stop after bus error failed: ${error}`);
|
|
234
|
+
}).finally(() => process.exit(0));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
220
238
|
private setProviderStatus(status: SemanticStatus): void {
|
|
221
239
|
if (status === "busy") this.claims.setProviderBusy(true);
|
|
222
240
|
else if (status === "idle") this.claims.setProviderBusy(false);
|
|
@@ -271,6 +289,11 @@ export function runnerAgentStatus(status: "idle" | "busy" | "offline" | "error")
|
|
|
271
289
|
return status === "error" ? "offline" : status;
|
|
272
290
|
}
|
|
273
291
|
|
|
292
|
+
export function runnerBusErrorAction(code: string, stopped: boolean): "ignore" | "log" | "stop" {
|
|
293
|
+
if (code === "STALE_SESSION") return stopped ? "ignore" : "stop";
|
|
294
|
+
return "log";
|
|
295
|
+
}
|
|
296
|
+
|
|
274
297
|
function lifecycleCapabilities(): Record<string, true> {
|
|
275
298
|
return {
|
|
276
299
|
shutdownHard: true,
|