Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(daemon): honest-ack diagnostic when a wake produces no effect

Claudetteb8013ca496b0
diff --git a/src/daemon/src/manager/agentRouter.test.ts b/src/daemon/src/manager/agentRouter.test.ts
index 074101e24..edc562c66 100644
--- a/src/daemon/src/manager/agentRouter.test.ts
+++ b/src/daemon/src/manager/agentRouter.test.ts
@@ -23,8 +23,16 @@ function stubLogger(): Logger & { calls: Record<"debug" | "info" | "warn" | "err
return logger;
}
-/** Fake manager recording deliver/register; enough for router behavior tests. */
-function fakeManager(initialStatuses: Record<string, "idle" | "starting" | "running" | "stopping"> = {}) {
+/**
+ * Fake manager recording deliver/register; enough for router behavior tests.
+ * `deliverReturns` controls the boolean `deliver` reports (whether the wake
+ * produced an executable effect) — leave undefined to mimic a legacy void
+ * `deliver`, which must NOT trigger the honest-ack diagnostic.
+ */
+function fakeManager(
+ initialStatuses: Record<string, "idle" | "starting" | "running" | "stopping"> = {},
+ deliverReturns?: boolean,
+) {
const delivers: Array<{ agentId: string; text: string; seq?: number }> = [];
const registers: Array<{ agentId: string; sessionId?: string; launchId?: string }> = [];
const forgets: string[] = [];
@@ -40,6 +48,7 @@ function fakeManager(initialStatuses: Record<string, "idle" | "starting" | "runn
deliver(agentId: string, m: { seq?: number; text: string }) {
delivers.push({ agentId, text: m.text, seq: m.seq });
order.push(`deliver:${agentId}`);
+ return deliverReturns;
},
forgetSession(agentId: string) {
forgets.push(agentId);
@@ -154,6 +163,45 @@ describe("AgentRouter — agent:wake", () => {
expect(delivers.length).toBe(2);
expect(wakeAcks.length).toBe(2);
});
+
+ it("logs an honest-ack diagnostic when deliver produced NO executable effect, keeping the wire ack ok", async () => {
+ const { mgr } = fakeManager({ a1: "running" }, false);
+ const { ch, wakeAcks, fire } = fakeChannel();
+ const logger = stubLogger();
+ const router = new AgentRouter({ manager: mgr, channel: ch, runtimeReport: [{ id: "mock" }], logger });
+ await router.start();
+
+ await fire({
+ type: "agent:wake",
+ agentId: "a1",
+ config: { version: 1, runtime: "mock", model: { kind: "default" }, mode: { kind: "default" } },
+ launchId: "l1",
+ unreadNotice: { kind: "unread_notice", channel: "/demo/general", latestSeq: 7 },
+ });
+
+ // Diagnostic surfaced (batch B), but the wire ack is still ok — reachability
+ // honesty is batch D, this router only reports the local "no effect" fact.
+ expect(logger.calls.info.some(([m]) => m === "agent:wake produced no effect (coalesced only)")).toBe(true);
+ expect(wakeAcks).toEqual([{ agentId: "a1", launchId: "l1", status: "ok" }]);
+ });
+
+ it("does NOT log the honest-ack diagnostic when deliver produced an effect", async () => {
+ const { mgr } = fakeManager({ a1: "idle" }, true);
+ const { ch, fire } = fakeChannel();
+ const logger = stubLogger();
+ const router = new AgentRouter({ manager: mgr, channel: ch, runtimeReport: [{ id: "mock" }], logger });
+ await router.start();
+
+ await fire({
+ type: "agent:wake",
+ agentId: "a1",
+ config: { version: 1, runtime: "mock", model: { kind: "default" }, mode: { kind: "default" } },
+ launchId: "l1",
+ unreadNotice: { kind: "unread_notice", channel: "/demo/general", latestSeq: 7 },
+ });
+
+ expect(logger.calls.info.some(([m]) => m === "agent:wake produced no effect (coalesced only)")).toBe(false);
+ });
});
describe("AgentRouter — agent:reset", () => {
diff --git a/src/daemon/src/manager/agentRouter.ts b/src/daemon/src/manager/agentRouter.ts
index dad02ec12..2db4d6142 100644
--- a/src/daemon/src/manager/agentRouter.ts
+++ b/src/daemon/src/manager/agentRouter.ts
@@ -407,7 +407,29 @@ export class AgentRouter {
const text = (this.opts.formatUnreadNoticeText ?? defaultFormatUnreadNoticeText)(cmd.unreadNotice);
// The manager (not this router) decides spawn vs. in-process notify
// vs. coalesce — see managerPolicy's `onWake`.
- this.opts.manager.deliver(cmd.agentId, { seq: cmd.unreadNotice.latestSeq, text });
+ const producedEffect = this.opts.manager.deliver(cmd.agentId, {
+ seq: cmd.unreadNotice.latestSeq,
+ text,
+ });
+ // Honest-ack diagnostic (plans/daemon-fsm-desync.md batch B): a wake
+ // that produced NO executable effect was only coalesced into the
+ // inbox. Benign for the queue-and-drain states (starting/stopping/
+ // reset-window/per-turn), but on a `running` agent it can mean the
+ // message is stacking behind a process that will never drain it (the
+ // deaf-orphan class). Surface it as a daemon-local log line so the
+ // stall stops masquerading as a healthy `status:"ok"` ack. This does
+ // NOT change the wire ack status — reachability-based honesty is
+ // batch D's job (it needs a liveness probe this router deliberately
+ // avoids). `producedEffect` is `false` for a legacy mock manager
+ // whose `deliver` returns void, so the diagnostic simply won't fire
+ // in those tests.
+ if (producedEffect === false) {
+ this.log.info("agent:wake produced no effect (coalesced only)", {
+ agentId: cmd.agentId,
+ beforeStatus,
+ latestSeq: cmd.unreadNotice.latestSeq,
+ });
+ }
if (channelScope && wasActive && beforeStatus === "running") {
this.opts.channel.reportAgentTyping?.({
agentId: cmd.agentId,
diff --git a/src/daemon/src/manager/managerRuntime.ts b/src/daemon/src/manager/managerRuntime.ts
index 0b5c210d9..cf6b0f25b 100644
--- a/src/daemon/src/manager/managerRuntime.ts
+++ b/src/daemon/src/manager/managerRuntime.ts
@@ -597,9 +597,19 @@ export class AgentProcessManager {
this.dispatch({ type: "register", agentId, caps });
}
- /** Inbound message for an agent → drives spawn/steer/queue per policy. */
- deliver(agentId: string, message: AgentMsg): void {
- this.dispatch({ type: "wake", agentId, message, nowMs: this.now() });
+ /**
+ * Inbound message for an agent → drives spawn/steer/queue per policy.
+ * Returns whether the wake produced any executable effect (spawn/send/
+ * gated_hold). `false` means the message was only coalesced into the inbox
+ * with nothing dispatched toward a process — benign for the queue-and-drain
+ * cases (starting/stopping/reset-window/per-turn), pathological for a
+ * deaf-but-`running` agent that will never drain. The router uses this for a
+ * daemon-local honest-ack diagnostic; it does NOT change the wire ack status.
+ * See plans/daemon-fsm-desync.md batch B.
+ */
+ deliver(agentId: string, message: AgentMsg): boolean {
+ const effects = this.dispatch({ type: "wake", agentId, message, nowMs: this.now() });
+ return effects.length > 0;
}
/**
@@ -872,7 +882,7 @@ export class AgentProcessManager {
/* Core dispatch: reduce → apply effects */
/* --------------------------------------------------------------- */
- private dispatch(event: ManagerEvent): void {
+ private dispatch(event: ManagerEvent): ManagerEffect[] {
const before = this.deriveActivitySnapshot(this.state);
const { state, effects } = reduceManager(this.state, event);
this.state = state;
@@ -887,6 +897,7 @@ export class AgentProcessManager {
}
}
}
+ return effects;
}
private deriveActivitySnapshot(state: ManagerState): Record<string, AgentActivityState> {