Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(daemon): suppress runtime_error audit for intentional-kill death rattle

Claudette#9873f6c7d0fa572c
diff --git a/src/daemon/src/manager/managerRuntime.test.ts b/src/daemon/src/manager/managerRuntime.test.ts
index 0b8ffb050..64ccf55cb 100644
--- a/src/daemon/src/manager/managerRuntime.test.ts
+++ b/src/daemon/src/manager/managerRuntime.test.ts
@@ -1102,6 +1102,23 @@ describe("AgentProcessManager — error audit emission", () => {
expect(payload.message).toContain("429");
});
+ it("does NOT emit a `runtime_error` row for an error event during an intentional kill (resetting=true)", () => {
+ const onBotAuditEvent = vi.fn();
+ const { mgr, session } = makeManager({ onBotAuditEvent });
+ mgr.deliver("a1", { seq: 1, text: "hello" });
+
+ // Establish, then enter the reset/nap kill window before the dying
+ // process fires its interrupted-turn "death rattle" error.
+ session.fire("runtime_event", { kind: "session_init", sessionId: "s1" });
+ mgr.markResetting("a1");
+ session.fire("runtime_event", { kind: "error", message: "turn interrupted" });
+
+ const errCalls = onBotAuditEvent.mock.calls.filter(
+ ([, ev]) => (ev as { kind?: string })?.kind === "error",
+ );
+ expect(errCalls).toHaveLength(0);
+ });
+
it("scrubs secrets out of an error message before it becomes an audit row", () => {
const onBotAuditEvent = vi.fn();
const { mgr, session } = makeManager({ onBotAuditEvent });
diff --git a/src/daemon/src/manager/managerRuntime.ts b/src/daemon/src/manager/managerRuntime.ts
index 14e8a5af7..0b5c210d9 100644
--- a/src/daemon/src/manager/managerRuntime.ts
+++ b/src/daemon/src/manager/managerRuntime.ts
@@ -1303,7 +1303,15 @@ export class AgentProcessManager {
// so it lands in the bot's activity log. `hasEstablished` is already true
// here (this fires from the `runtime_event` subscriber), so the scope is
// `runtime`, not `spawn`.
- if (ev.kind === "error") {
+ //
+ // EXCEPT during an intentional kill (reset / nap / model_switch): the
+ // dying process, interrupted mid-turn, emits a final error `result`
+ // ("death rattle") that is teardown noise, not a fault. `agent.resetting`
+ // is true across the whole kill→respawn window (set at `begin_reset`
+ // before `stop()`, cleared at `onExit`/`spawned`), and the reborn session
+ // isn't spawned until AFTER the flag clears — so gating on it drops only
+ // the intentional-kill noise, never a live session's genuine error.
+ if (ev.kind === "error" && !this.state.agents[agentId]?.resetting) {
this.emitErrorAudit(agentId, "runtime", "runtime_error", ev.message ?? "Runtime error");
}
// Bot audit hook — thinking + non-Bash tool_call, no correlation.