Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): retire Slack approval cards in place so grouped messages stay under 50 blocks (#4348)

roboeve[bot]85d1fcb92709
diff --git a/.changeset/slack-approval-cards-block-limit.md b/.changeset/slack-approval-cards-block-limit.md
new file mode 100644
index 000000000..7daf0a127
--- /dev/null
+++ b/.changeset/slack-approval-cards-block-limit.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Slack now removes the buttons from every settled tool-approval card when one step posts many approvals. Before, a grouped message could grow past Slack's 50-block limit as cards settled, Slack rejected the update, and settled cards kept their Approve and Cancel buttons. A settled card now shows the outcome and who answered on the card itself instead of in extra lines below it.
diff --git a/packages/eve/src/public/channels/slack/approval-cards.ts b/packages/eve/src/public/channels/slack/approval-cards.ts
index fa39a5573..0743d38ca 100644
--- a/packages/eve/src/public/channels/slack/approval-cards.ts
+++ b/packages/eve/src/public/channels/slack/approval-cards.ts
@@ -14,6 +14,7 @@ import {
renderInputRequestPostParts,
type SlackInputRequestPostPart,
} from "#public/channels/slack/hitl.js";
+import { answeredBlocksFromActionBlock } from "#public/channels/slack/interaction-cards.js";
import {
SLACK_MAX_BLOCKS_PER_MESSAGE,
truncateMessageText,
@@ -145,23 +146,17 @@ async function settleApprovalCard(
const messageChannelId = card.messageChannelId ?? channel.state.channelId;
if (messageChannelId === null) return;
+ // Grouped messages can already hold Slack's 50-block maximum, so a retired
+ // card must stay one block or every later update is rejected.
const blocks = card.messageBlocks.flatMap((block) => {
if (!blockContainsRequestAction(block, requestId)) return [block];
- if (typeof block !== "object" || block === null) return [];
- const candidate = block as Record<string, unknown>;
- if (candidate.type !== "card") {
- return buildAnsweredBlocks({
+ return (
+ answeredBlocksFromActionBlock({
answerLabel: answer.label,
- promptBlocks: [],
- userId: answer.userId,
- });
- }
- const { actions: _actions, subtext: _subtext, ...withoutActions } = candidate;
- return buildAnsweredBlocks({
- answerLabel: answer.label,
- promptBlocks: [withoutActions],
- userId: answer.userId,
- });
+ block,
+ userId: answer.userId ?? "",
+ }) ?? buildAnsweredBlocks({ answerLabel: answer.label, promptBlocks: [] })
+ );
});
for (const [otherId, pendingCard] of Object.entries(next)) {
if (pendingCard.messageTs === card.messageTs) {
diff --git a/packages/eve/src/public/channels/slack/defaults.test.ts b/packages/eve/src/public/channels/slack/defaults.test.ts
index 296fb9224..86bf924a3 100644
--- a/packages/eve/src/public/channels/slack/defaults.test.ts
+++ b/packages/eve/src/public/channels/slack/defaults.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest";
import type { SessionContext } from "#public/definitions/callback-context.js";
import { defaultInputRequestedHandler } from "#public/channels/slack/approval-cards.js";
import { defaultEvents } from "#public/channels/slack/defaults.js";
+import { SLACK_MAX_BLOCKS_PER_MESSAGE } from "#public/channels/slack/limits.js";
import type { SlackChannelState, SlackEventContext } from "#public/channels/slack/slackChannel.js";
import { captureLogRecords } from "#internal/testing/log-records.js";
@@ -485,6 +486,70 @@ describe("defaultEvents approval lifecycle", () => {
}
}
});
+
+ it.each([
+ { count: 50, settledBy: "approval.settled" },
+ { count: 50, settledBy: "input.resolved" },
+ { count: 87, settledBy: "approval.settled" },
+ { count: 87, settledBy: "input.resolved" },
+ ] as const)(
+ "retires every card of $count grouped approvals settled by $settledBy",
+ async ({ count, settledBy }) => {
+ const { channel, post, request } = buildChannelStub({
+ slackUsersByPrincipal: { "slack:T1:U777": "U777" },
+ });
+ const messages = new Map<string, readonly unknown[]>();
+ post.mockImplementation(async (message: { blocks: unknown[] }) => {
+ const ts = `ts${messages.size + 1}`;
+ messages.set(ts, message.blocks);
+ return { id: ts, raw: { ok: true } };
+ });
+ let rejectedUpdates = 0;
+ request.mockImplementation(async (operation: string, body: unknown) => {
+ const { blocks, ts } = body as { blocks?: unknown[]; ts: string };
+ if (operation === "chat.update" && blocks !== undefined) {
+ // Slack rejects the whole update when a message exceeds its block cap.
+ if (blocks.length > SLACK_MAX_BLOCKS_PER_MESSAGE) {
+ rejectedUpdates += 1;
+ return { error: "invalid_blocks", ok: false };
+ }
+ messages.set(ts, blocks);
+ }
+ if (operation === "chat.delete") messages.delete(ts);
+ return { ok: true };
+ });
+ const requests = Array.from({ length: count }, (_, index) =>
+ approvalRequest(`approval-${index}`),
+ );
+
+ await defaultInputRequestedHandler()(
+ { requests, sequence: 1, stepIndex: 0, turnId: "turn-1" },
+ channel,
+ sessionCtx,
+ );
+ for (const [index, { requestId }] of requests.entries()) {
+ const step = { sequence: index + 2, stepIndex: index + 1, turnId: "turn-1" };
+ if (settledBy === "approval.settled") {
+ await defaultEvents["approval.settled"]!(
+ { outcome: "approved", requestId, responderPrincipalId: "slack:T1:U777", ...step },
+ channel,
+ sessionCtx,
+ );
+ } else {
+ await defaultEvents["input.resolved"]!(
+ { resolutions: [{ kind: "tool-approval", outcome: "approved", requestId }], ...step },
+ channel,
+ sessionCtx,
+ );
+ }
+ }
+
+ const liveCards = [...messages.values()]
+ .flat()
+ .filter((block) => (block as { actions?: unknown }).actions !== undefined).length;
+ expect({ liveCards, rejectedUpdates }).toEqual({ liveCards: 0, rejectedUpdates: 0 });
+ },
+ );
});
describe("defaultEvents authorization.required", () => {
diff --git a/packages/eve/src/public/channels/slack/interaction-cards.ts b/packages/eve/src/public/channels/slack/interaction-cards.ts
index e097c7d7b..11946efdb 100644
--- a/packages/eve/src/public/channels/slack/interaction-cards.ts
+++ b/packages/eve/src/public/channels/slack/interaction-cards.ts
@@ -71,7 +71,8 @@ function actionsContainActionId(actions: unknown, actionId: string): boolean {
return actions.some((element) => isObjectRecord(element) && element.action_id === actionId);
}
-function answeredBlocksFromActionBlock(input: {
+/** Retires an answered `card` in place: same single block, buttons replaced by the answer. */
+export function answeredBlocksFromActionBlock(input: {
readonly answerLabel: string;
readonly block: unknown;
readonly userId: string;