The Open Framework for Building Agents
fix(eve): slack - stream reasoning status progressively (#107)
Andrew Barba159d4afab512
diff --git a/.changeset/smart-slack-reasoning.md b/.changeset/smart-slack-reasoning.mdnew file mode 100644index 000000000..fd6b224b4--- /dev/null+++ b/.changeset/smart-slack-reasoning.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Slack reasoning typing indicators now update progressively when the cumulative status grows by at least four characters, preventing opening fragments from remaining stale without issuing one Slack request per token.diff --git a/docs/channels/slack.mdx b/docs/channels/slack.mdxindex 0483eb2a3..c9bf73da5 100644--- a/docs/channels/slack.mdx+++ b/docs/channels/slack.mdx@@ -78,7 +78,7 @@ export default slackChannel({### Delivery-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 are visible in Slack status while the model is thinking; override `events["reasoning.appended"]` if you prefer generic wording. Override `onAppMention` or the `events` handlers to customize.+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.diff --git a/packages/eve/src/public/channels/slack/defaults.ts b/packages/eve/src/public/channels/slack/defaults.tsindex 96a5eb828..09c6f9fee 100644--- a/packages/eve/src/public/channels/slack/defaults.ts+++ b/packages/eve/src/public/channels/slack/defaults.ts@@ -21,6 +21,7 @@ import type {const log = createLogger("slack.defaults");const REASONING_TYPING_REFRESH_INTERVAL_MS = 5_000;+const REASONING_TYPING_MIN_PROGRESS_CHARS = 4;/*** Workspace-scoped projection of the Slack actor that produced@@ -123,14 +124,20 @@ export const defaultEvents: SlackChannelInternalEvents = {const line = firstNonEmptyLine(event.reasoningSoFar);if (line === undefined) return;+ const status = truncateTypingStatus(line);+ const lastStatus = channel.state.lastReasoningTypingStatus;+ const isProgressiveExtension =+ lastStatus !== null &&+ lastStatus !== undefined &&+ status.startsWith(lastStatus) &&+ status.length >= lastStatus.length + REASONING_TYPING_MIN_PROGRESS_CHARS;const now = Date.now();const lastAt = channel.state.lastReasoningTypingAtMs;- if (lastAt !== null && lastAt !== undefined) {+ if (!isProgressiveExtension && lastAt !== null && lastAt !== undefined) {const elapsed = now - lastAt;if (elapsed >= 0 && elapsed < REASONING_TYPING_REFRESH_INTERVAL_MS) return;}- const status = truncateTypingStatus(line);await channel.thread.startTyping(status);channel.state.lastReasoningTypingAtMs = now;channel.state.lastReasoningTypingStatus = status;diff --git a/packages/eve/src/public/channels/slack/slackChannel.test.ts b/packages/eve/src/public/channels/slack/slackChannel.test.tsindex 79cc03ae1..22c94a888 100644--- a/packages/eve/src/public/channels/slack/slackChannel.test.ts+++ b/packages/eve/src/public/channels/slack/slackChannel.test.ts@@ -255,10 +255,12 @@ async function firePost(describe("slackChannel() default event handlers", () => {let fetchMock: ReturnType<typeof vi.fn>;beforeEach(() => {- fetchMock = vi.fn().mockResolvedValue(- new Response(JSON.stringify({ ok: true, ts: "1700000001.000001" }), {- headers: { "content-type": "application/json" },- }),+ fetchMock = vi.fn().mockImplementation(() =>+ Promise.resolve(+ new Response(JSON.stringify({ ok: true, ts: "1700000001.000001" }), {+ headers: { "content-type": "application/json" },+ }),+ ),);vi.stubGlobal("fetch", fetchMock);});@@ -479,7 +481,34 @@ describe("slackChannel() default event handlers", () => {expect(ctx.state.lastReasoningTypingStatus).toBe(body.status);});- it("reasoning.appended throttles repeated status refreshes", async () => {+ it("reasoning.appended immediately publishes progressive extensions of four characters", async () => {+ vi.useFakeTimers();+ vi.setSystemTime(new Date("2026-06-18T12:00:00Z"));+ const adapter = withState(+ getAdapter(slackChannel({ credentials: { botToken: "xoxb-test" } })),+ THREAD_STATE,+ );+ const ctx = buildAdapterContext(adapter, stubAccessor());+ const reasoningEvent = (reasoningDelta: string, reasoningSoFar: string) =>+ makeEvent("reasoning.appended", {+ reasoningDelta,+ reasoningSoFar,+ sequence: 0,+ stepIndex: 0,+ turnId: "t1",+ });++ await callEvent(adapter, reasoningEvent("I", "I"), ctx);+ await callEvent(adapter, reasoningEvent(" ca", "I ca"), ctx);+ await callEvent(adapter, reasoningEvent("n", "I can"), ctx);++ const statuses = fetchMock.mock.calls.map(+ ([, init]) => parseSlackRequestBody(init as RequestInit).status,+ );+ expect(statuses).toEqual(["I", "I can"]);+ });++ it("reasoning.appended requires a matching prefix and four new characters", async () => {vi.useFakeTimers();vi.setSystemTime(new Date("2026-06-18T12:00:00Z"));const adapter = withState(@@ -496,20 +525,18 @@ describe("slackChannel() default event handlers", () => {turnId: "t1",});- await callEvent(adapter, reasoningEvent("Need to inspect the repo."), ctx);+ await callEvent(adapter, reasoningEvent("Need"), ctx);vi.setSystemTime(new Date("2026-06-18T12:00:01Z"));- await callEvent(adapter, reasoningEvent("Need to inspect the repo. Then test."), ctx);+ await callEvent(adapter, reasoningEvent("Need to"), ctx);+ await callEvent(adapter, reasoningEvent("Check something else"), ctx);vi.setSystemTime(new Date("2026-06-18T12:00:05Z"));- await callEvent(adapter, reasoningEvent("Need to inspect the repo. Then test again."), ctx);+ await callEvent(adapter, reasoningEvent("Need to"), ctx);expect(fetchMock).toHaveBeenCalledTimes(2);const statuses = fetchMock.mock.calls.map(([, init]) => parseSlackRequestBody(init as RequestInit).status,);- expect(statuses).toEqual([- "Need to inspect the repo.",- "Need to inspect the repo. Then test again.",- ]);+ expect(statuses).toEqual(["Need", "Need to"]);});it("turn.started resets reasoning status throttling", async () => {diff --git a/packages/eve/src/public/channels/slack/slackChannel.ts b/packages/eve/src/public/channels/slack/slackChannel.tsindex 1bcf23b58..ae8cf8eb8 100644--- a/packages/eve/src/public/channels/slack/slackChannel.ts+++ b/packages/eve/src/public/channels/slack/slackChannel.ts@@ -172,8 +172,8 @@ export interface SlackChannelState {pendingToolCallMessage?: string | null;/*** Last reasoning-derived typing indicator sent by the default- * `reasoning.appended` handler. Used to refresh Slack's status during- * long reasoning streams without sending one API call per delta.+ * `reasoning.appended` handler. Used to surface substantial progressive+ * extensions immediately while throttling smaller streamed deltas.*/lastReasoningTypingAtMs?: number | null;lastReasoningTypingStatus?: string | null;