Skip to content

Commit b01c912

Browse files
fix(agents): align poll echo pruning with expiry
Expire both read and write-time records at the same inclusive TTL boundary. Cover adjacent times and retain inspectable Gateway/channel transport proof. Co-authored-by: qingminlong <[email protected]>
1 parent 5be01b4 commit b01c912

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

‎src/agents/tools/message-tool-execution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
703703
// sends a follow-up text can't leak a record forever in a long-lived
704704
// gateway; the map stays bounded to sessions that voted within the TTL.
705705
for (const [key, entry] of recentPollVoteBySession) {
706-
if (recordedAt - entry.recordedAt > POLL_VOTE_ECHO_TTL_MS) {
706+
if (recordedAt - entry.recordedAt >= POLL_VOTE_ECHO_TTL_MS) {
707707
recentPollVoteBySession.delete(key);
708708
}
709709
}

‎src/agents/tools/message-tool.test.ts‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,26 +1015,32 @@ describe("poll vote echo guard", () => {
10151015
expect(result.details).toMatchObject({ status: "suppressed", reason: "poll_vote_echo" });
10161016
});
10171017

1018-
it("allows a same-route echo at the exact TTL boundary", async () => {
1019-
vi.useFakeTimers();
1018+
it.each([
1019+
{ elapsedMs: 29_999, suppressed: true },
1020+
{ elapsedMs: 30_000, suppressed: false },
1021+
{ elapsedMs: 30_001, suppressed: false },
1022+
])("expires the same-route vote after $elapsedMs ms", async ({ elapsedMs, suppressed }) => {
1023+
const now = vi.spyOn(Date, "now").mockReturnValue(100_000);
10201024
try {
1021-
vi.setSystemTime(100_000);
1022-
const sessionKey = "agent:test:imessage:direct:ttl-boundary";
1025+
const sessionKey = `agent:test:imessage:direct:ttl-${elapsedMs}`;
10231026
const voteTool = createPollVoteTool("Black", sessionKey);
10241027
await castBlueVote(voteTool);
10251028

1026-
await vi.advanceTimersByTimeAsync(30_000);
1029+
now.mockReturnValue(100_000 + elapsedMs);
10271030
const nextRunTool = createPollVoteTool("Black", sessionKey);
10281031
const result = await nextRunTool.execute("send", {
10291032
action: "send",
10301033
channel: "imessage",
10311034
message: "🦞 Black.",
10321035
});
1033-
1034-
expect(result.details).not.toMatchObject({ status: "suppressed" });
1035-
expect(mocks.runMessageAction).toHaveBeenCalledTimes(2);
1036+
if (suppressed) {
1037+
expect(result.details).toMatchObject({ status: "suppressed", reason: "poll_vote_echo" });
1038+
} else {
1039+
expect(result.details).not.toMatchObject({ status: "suppressed" });
1040+
}
1041+
expect(mocks.runMessageAction).toHaveBeenCalledTimes(suppressed ? 1 : 2);
10361042
} finally {
1037-
vi.useRealTimers();
1043+
now.mockRestore();
10381044
}
10391045
});
10401046

0 commit comments

Comments
 (0)