Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): slack schedules - prevent proactive hook conflicts (#262)

Andrew Barbaab3e6e8cafbc
diff --git a/.changeset/unique-slack-hook-tokens.md b/.changeset/unique-slack-hook-tokens.md
new file mode 100644
index 000000000..983be5184
--- /dev/null
+++ b/.changeset/unique-slack-hook-tokens.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Give each threadless proactive Slack session a unique temporary continuation token so overlapping scheduled runs targeting the same channel do not conflict before they anchor to a Slack thread.
diff --git a/docs/channels/slack.mdx b/docs/channels/slack.mdx
index f385a1a9d..00ac5b3d7 100644
--- a/docs/channels/slack.mdx
+++ b/docs/channels/slack.mdx
@@ -80,7 +80,7 @@ export default slackChannel({
The default handlers reply in-thread and show progress. Typing indicators post automatically: `Thinking…` on inbound, `Working…` on `turn.started`, a truncated reasoning snippet on `reasoning.appended`, and tool status on `actions.requested`. Reasoning snippets build progressively: extensions of at least four characters appear immediately, while smaller streamed deltas use the five-second refresh interval to avoid one Slack request per token. Override `events["reasoning.appended"]` if you prefer generic wording. Override `onAppMention` or the `events` handlers to customize.
-When a session starts without a `threadTs` (say, from a schedule or `receive(slack, ...)`), it anchors on the first agent post, and later posts and mentions resume that same session. Pass `initialMessage` with a `Card` to land a structured anchor first instead. `threadTs` and `initialMessage` are mutually exclusive.
+When a session starts without a `threadTs` (say, from a schedule or `receive(slack, ...)`), eve gives it a unique temporary continuation token. The first agent post anchors the session to the Slack message timestamp, and later posts and mentions resume that same session. Pass `initialMessage` with a `Card` to land a structured anchor first instead. `threadTs` and `initialMessage` are mutually exclusive.
The example below overrides `onAppMention` to gate on an authored message and posts the completed reply to the thread. Event handlers receive `(eventData, channel, ctx)`, with Slack platform handles on `channel.thread` and `channel.slack`:
diff --git a/packages/eve/src/channel/schedule.test.ts b/packages/eve/src/channel/schedule.test.ts
index 549bad23f..374dabb34 100644
--- a/packages/eve/src/channel/schedule.test.ts
+++ b/packages/eve/src/channel/schedule.test.ts
@@ -123,7 +123,9 @@ describe("ScheduleDispatcher", () => {
expect(runtime.run).toHaveBeenCalledTimes(1);
const runInput = vi.mocked(runtime.run).mock.calls[0]![0];
- expect(runInput.continuationToken).toBe("slack:C0123ABC:");
+ expect(runInput.continuationToken).toMatch(
+ /^slack:C0123ABC:[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/,
+ );
expect(runInput.auth).toEqual(SCHEDULE_APP_AUTH);
} finally {
vi.unstubAllEnvs();
diff --git a/packages/eve/src/public/channels/slack/slackChannel.test.ts b/packages/eve/src/public/channels/slack/slackChannel.test.ts
index 27bee2aba..8e57b283b 100644
--- a/packages/eve/src/public/channels/slack/slackChannel.test.ts
+++ b/packages/eve/src/public/channels/slack/slackChannel.test.ts
@@ -1471,6 +1471,34 @@ describe("slackChannel().receive", () => {
expect(options.auth.principalId).toBe("p");
});
+ it("gives each threadless proactive session a unique temporary continuation token", async () => {
+ const randomUUID = vi
+ .spyOn(crypto, "randomUUID")
+ .mockReturnValueOnce("00000000-0000-4000-8000-000000000001")
+ .mockReturnValueOnce("00000000-0000-4000-8000-000000000002");
+ const send = vi.fn().mockResolvedValue({ id: "s", continuationToken: "ct" });
+
+ try {
+ const receive = buildReceive();
+ const input = {
+ message: "run the check",
+ target: { channelId: "C123" },
+ auth: null,
+ };
+
+ await receive(input, { send });
+ await receive(input, { send });
+
+ expect(send.mock.calls.map(([, options]) => options.continuationToken)).toEqual([
+ "C123:00000000-0000-4000-8000-000000000001",
+ "C123:00000000-0000-4000-8000-000000000002",
+ ]);
+ expect(send.mock.calls.map(([, options]) => options.state.threadTs)).toEqual([null, null]);
+ } finally {
+ randomUUID.mockRestore();
+ }
+ });
+
it("requires channelId", async () => {
const send = vi.fn();
await expect(
diff --git a/packages/eve/src/public/channels/slack/slackChannel.ts b/packages/eve/src/public/channels/slack/slackChannel.ts
index 97bb7d5ca..a54e3d126 100644
--- a/packages/eve/src/public/channels/slack/slackChannel.ts
+++ b/packages/eve/src/public/channels/slack/slackChannel.ts
@@ -584,9 +584,13 @@ export function slackChannel(config: SlackChannelConfig = {}): SlackChannel {
threadTs = posted.id;
}
+ // Threadless proactive runs need distinct identities until their first
+ // Slack post supplies the real thread timestamp and re-keys the session.
+ const continuationThreadTs = threadTs || crypto.randomUUID();
+
return send(input.message, {
auth: input.auth,
- continuationToken: slackContinuationToken(channelId, threadTs),
+ continuationToken: slackContinuationToken(channelId, continuationThreadTs),
state: {
channelId,
threadTs: threadTs || null,