From fe9ac32faf04f19dc5048b57ed79f6ecef652602 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 09:42:21 +0000 Subject: [PATCH 01/89] Add effect/chat with ChatTest and the conformance suite --- .changeset/effect-chat.md | 5 + packages/effect/package.json | 3 + packages/effect/src/chat/Chat.ts | 156 ++ packages/effect/src/chat/ChatAdapter.ts | 351 +++++ packages/effect/src/chat/ChatError.ts | 639 ++++++++ packages/effect/src/chat/ChatEvent.ts | 179 +++ packages/effect/src/chat/ChatHandler.ts | 100 ++ packages/effect/src/chat/ChatMessage.ts | 178 +++ packages/effect/src/chat/ChatTest.ts | 1381 ++++++++++++++++++ packages/effect/src/chat/ChatThread.ts | 132 ++ packages/effect/src/chat/index.ts | 54 + packages/effect/src/chat/internal/retries.ts | 7 + packages/effect/test/chat/Chat.test.ts | 54 + packages/effect/test/chat/ChatError.test.ts | 73 + packages/effect/test/chat/ChatTest.test.ts | 117 ++ 15 files changed, 3429 insertions(+) create mode 100644 .changeset/effect-chat.md create mode 100644 packages/effect/src/chat/Chat.ts create mode 100644 packages/effect/src/chat/ChatAdapter.ts create mode 100644 packages/effect/src/chat/ChatError.ts create mode 100644 packages/effect/src/chat/ChatEvent.ts create mode 100644 packages/effect/src/chat/ChatHandler.ts create mode 100644 packages/effect/src/chat/ChatMessage.ts create mode 100644 packages/effect/src/chat/ChatTest.ts create mode 100644 packages/effect/src/chat/ChatThread.ts create mode 100644 packages/effect/src/chat/index.ts create mode 100644 packages/effect/src/chat/internal/retries.ts create mode 100644 packages/effect/test/chat/Chat.test.ts create mode 100644 packages/effect/test/chat/ChatError.test.ts create mode 100644 packages/effect/test/chat/ChatTest.test.ts diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md new file mode 100644 index 00000000000..69d6627b867 --- /dev/null +++ b/.changeset/effect-chat.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Add `effect/chat`, an unstable, platform-neutral model and router for chat bots, with `ChatTest`, an in-memory adapter and the conformance suite adapters are tested against. diff --git a/packages/effect/package.json b/packages/effect/package.json index 46e5ae979ac..7eba8cffa52 100644 --- a/packages/effect/package.json +++ b/packages/effect/package.json @@ -34,6 +34,7 @@ ".": "./src/index.ts", "./testing": "./src/testing/index.ts", "./ai": "./src/ai/index.ts", + "./chat": "./src/chat/index.ts", "./cli": "./src/cli/index.ts", "./cluster": "./src/cluster/index.ts", "./crypto": "./src/crypto/index.ts", @@ -58,6 +59,7 @@ "./workers": "./src/workers/index.ts", "./*": "./src/*.ts", "./ai/internal/*": null, + "./chat/internal/*": null, "./cli/internal/*": null, "./cluster/internal/*": null, "./crypto/internal/*": null, @@ -94,6 +96,7 @@ ".": "./dist/index.js", "./testing": "./dist/testing/index.js", "./ai": "./dist/ai/index.js", + "./chat": "./dist/chat/index.js", "./cli": "./dist/cli/index.js", "./cluster": "./dist/cluster/index.js", "./crypto": "./dist/crypto/index.js", diff --git a/packages/effect/src/chat/Chat.ts b/packages/effect/src/chat/Chat.ts new file mode 100644 index 00000000000..a84560148a7 --- /dev/null +++ b/packages/effect/src/chat/Chat.ts @@ -0,0 +1,156 @@ +/** + * The routed outbound chat service. + * + * `Chat` has the ops of every registered adapter and routes each call by the + * address's platform. `Chat.layer` provides the router and an empty + * `ChatAdapter.Registry`; adapter layers stack on top with + * `Layer.provideMerge`, and a platform that is off is a layer left out. + * + * **Example** (Posting through the router) + * + * ```ts + * import { Effect } from "effect" + * import { Chat, ChatThread } from "effect/chat" + * + * const program = Effect.gen(function*() { + * const chat = yield* Chat.Chat + * const posted = yield* chat.post(ChatThread.make("slack", "T1/C1"), { markdown: "Hello" }) + * return posted.id + * }) + * ``` + * + * @stability unstable + * @since 4.1.5 + */ +import * as Context from "../Context.ts" +import * as Effect from "../Effect.ts" +import * as Layer from "../Layer.ts" +import * as Stream from "../Stream.ts" +import type { ChatAdapter, Descriptor, Ops, User } from "./ChatAdapter.ts" +import { Registry } from "./ChatAdapter.ts" +import { ChatError, NoAdapter } from "./ChatError.ts" +import type { ChatThread } from "./ChatThread.ts" +import { RetriesDisabled } from "./internal/retries.ts" + +/** + * Service that routes chat operations to the adapter registered for each + * address's platform. + * + * **Details** + * + * - Every op takes an address and goes to the adapter for + * `thread.platform`, failing with `NoAdapter` when there is none. + * - `getUser` takes the platform first, because a bare user id names none. + * - `descriptor` returns a platform's capabilities and limits. + * - Each call runs in a `Chat.{op}` span whose attributes are the platform, the + * op and, on failure, the error reason and retry value. + * + * @stability unstable + * @category services + * @since 4.1.5 + */ +export class Chat extends Context.Service< + Chat, + Omit & { + readonly getUser: ( + platform: string, + id: string, + options?: { readonly in?: ChatThread | undefined } + ) => Effect.Effect + readonly descriptor: (platform: string) => Effect.Effect + } +>()("effect/chat/Chat") {} + +const spanAttributes = (platform: string, op: string) => ({ "chat.platform": platform, "chat.op": op }) + +const annotateFailure = (error: ChatError) => + Effect.annotateCurrentSpan({ "chat.error.reason": error.reason._tag, "chat.error.retry": error.retry }) + +const make = Effect.sync(() => { + const adapters = new Map() + + const lookup = (platform: string, op: string): Effect.Effect => + Effect.suspend(() => { + const adapter = adapters.get(platform) + return adapter === undefined + ? Effect.fail(new ChatError({ platform, op, reason: new NoAdapter({}) })) + : Effect.succeed(adapter) + }) + + const route = ( + platform: string, + op: string, + f: (adapter: ChatAdapter) => Effect.Effect + ): Effect.Effect => + lookup(platform, op).pipe( + Effect.flatMap(f), + Effect.tapError(annotateFailure), + Effect.withSpan(`Chat.${op}`, { attributes: spanAttributes(platform, op) }) + ) + + const routeStream = ( + platform: string, + op: string, + f: (adapter: ChatAdapter) => Stream.Stream + ): Stream.Stream => + Stream.unwrap(Effect.map(lookup(platform, op), f)).pipe( + Stream.tapError(annotateFailure), + Stream.withSpan(`Chat.${op}`, { attributes: spanAttributes(platform, op) }) + ) + + const registry = Registry.of({ + register: (adapter) => Effect.sync(() => void adapters.set(adapter.descriptor.platform, adapter)), + get: (platform) => lookup(platform, "get"), + descriptors: Effect.sync(() => Array.from(adapters.values(), (adapter) => adapter.descriptor)) + }) + + const chat = Chat.of({ + post: (thread, content) => route(thread.platform, "post", (adapter) => adapter.post(thread, content)), + edit: (thread, messageId, content) => + route(thread.platform, "edit", (adapter) => adapter.edit(thread, messageId, content)), + delete: (thread, messageId) => route(thread.platform, "delete", (adapter) => adapter.delete(thread, messageId)), + fetchMessage: (thread, messageId) => + route(thread.platform, "fetchMessage", (adapter) => adapter.fetchMessage(thread, messageId)), + history: (thread, options) => + routeStream(thread.platform, "history", (adapter) => adapter.history(thread, options)), + download: (thread, attachment, options) => + routeStream(thread.platform, "download", (adapter) => adapter.download(thread, attachment, options)), + startThread: (thread, messageId, options) => + route(thread.platform, "startThread", (adapter) => adapter.startThread(thread, messageId, options)), + getThread: (thread) => route(thread.platform, "getThread", (adapter) => adapter.getThread(thread)), + opener: (thread) => route(thread.platform, "opener", (adapter) => adapter.opener(thread)), + getUser: (platform, id, options) => route(platform, "getUser", (adapter) => adapter.getUser(id, options)), + descriptor: (platform) => route(platform, "descriptor", (adapter) => Effect.succeed(adapter.descriptor)) + }) + + return Context.make(Registry, registry).pipe(Context.add(Chat, chat)) +}) + +/** + * Layer that provides the `Chat` router and an empty `ChatAdapter.Registry`. + * + * **When to use** + * + * Use as the base of a chat setup. Adapter layers go on top with + * `Layer.provideMerge`. + * + * @stability unstable + * @category layers + * @since 4.1.5 + */ +export const layer: Layer.Layer = Layer.effectContext(make) + +/** + * Runs an effect with adapter retries turned off, so every adapter call inside + * it makes one attempt. + * + * **Gotchas** + * + * The name is provisional. + * + * @stability unstable + * @category combinators + * @since 4.1.5 + */ +export const withoutRetries = (effect: Effect.Effect): Effect.Effect => + Effect.provideService(effect, RetriesDisabled, true) diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts new file mode 100644 index 00000000000..10b74b96637 --- /dev/null +++ b/packages/effect/src/chat/ChatAdapter.ts @@ -0,0 +1,351 @@ +/** + * What a chat platform adapter implements. + * + * An adapter is a set of `Ops` plus a static `Descriptor` of what the + * platform supports. Adapters register in the `Registry`, which `Chat` + * routes through by `thread.platform`. + * + * **Details** + * + * - Every op exists on every platform. Where the platform has no equivalent + * the op fails with `Unsupported`, naming the capability. + * - A post notifies nobody unless asked: mentions in Markdown do not notify by + * default. + * - Length is checked before the call, with `checkMessageLength`. + * - Adapters retry `retry` failures with `retrySafe` and never retry + * `uncertain` ones. + * + * @stability unstable + * @since 4.1.5 + */ +import * as Context from "../Context.ts" +import type * as DateTime from "../DateTime.ts" +import * as Duration from "../Duration.ts" +import * as Effect from "../Effect.ts" +import * as Layer from "../Layer.ts" +import type * as Option from "../Option.ts" +import type * as Schema from "../Schema.ts" +import type * as Scope from "../Scope.ts" +import type * as Stream from "../Stream.ts" +import type { Capability } from "./ChatError.ts" +import { ChatError, TooLarge } from "./ChatError.ts" +import type { ThreadKind } from "./ChatEvent.ts" +import type { Attachment, ChatMessage, ReplyTo } from "./ChatMessage.ts" +import type { ChatThread } from "./ChatThread.ts" +import { RetriesDisabled } from "./internal/retries.ts" + +/** + * Static description of a platform: its capabilities and limits, readable + * without a call to the platform. + * + * **Details** + * + * - An op whose capability is missing from `capabilities` fails with + * `Unsupported`. + * - `limits.messageLength` is the length of one message. What is counted, + * and in which unit, is still open; `checkMessageLength` holds the one + * place it is measured. + * - `limits.minWriteInterval` is the default floor between two writes to one + * thread, for streamed and multi-part posts. + * - `limits.streamLength` and `limits.streamAge` apply to native streams + * only. `streamLength` is never more than `messageLength`, so a stream's + * text always fits an `edit`. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface Descriptor { + readonly platform: string + readonly capabilities: ReadonlySet + readonly limits: { + readonly messageLength: number + readonly filesPerMessage: number + readonly uploadBytes: number + readonly minWriteInterval: Duration.Duration + readonly streamLength?: number | undefined + readonly streamAge?: Duration.Duration | undefined + } +} + +/** + * A file to upload with a post. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface File { + readonly name: string + readonly contentType: string + readonly content: Uint8Array +} + +/** + * The message a successful post created. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface Posted { + readonly id: string + readonly thread: ChatThread + readonly timestamp: DateTime.Utc +} + +/** + * What the platform says about an address. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface ThreadInfo { + readonly thread: ChatThread + readonly kind: ThreadKind + readonly name?: string | undefined + readonly topic?: string | undefined + readonly parent?: ChatThread | undefined + readonly createdAt?: DateTime.Utc | undefined + readonly raw: Schema.Json +} + +/** + * A user as the platform reports them. + * + * **Details** + * + * `name` is the guild nick when `in` was given and the platform has one. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface User { + readonly id: string + readonly name: string + readonly isBot: boolean + readonly isSelf: boolean + readonly raw: Schema.Json +} + +/** + * The operations of one platform. `Chat` has the same ops, routed by + * `thread.platform`. + * + * **Details** + * + * - `post` takes standard Markdown that must fit `limits.messageLength`. It + * never splits or truncates: the adapter checks the length itself and fails + * with `TooLarge` without calling the platform. Mentions in it notify nobody. + * - `fetchMessage` fails with `NotFound` for a message that is gone. + * - `history` pages lazily. `backward` runs newest to oldest, `forward` + * oldest to newest, and `from` is exclusive. A thread's oldest message is its + * opener, whose `thread` is the thread's parent: the one message in a + * thread's history that is not addressed to that thread. + * - `download` fails with `TooLarge` as soon as more than `maxBytes` arrive. + * - `startThread` returns the thread under `messageId`, created when there is + * none. It is get-or-create, and the only way from an opener to its thread. + * - `opener` is the message a thread hangs off: `None` for a channel or + * direct address, or when it was deleted. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface Ops { + readonly post: (thread: ChatThread, content: { + readonly markdown: string + readonly replyTo?: ReplyTo | undefined + readonly files?: ReadonlyArray | undefined + }) => Effect.Effect + readonly edit: ( + thread: ChatThread, + messageId: string, + content: { readonly markdown: string } + ) => Effect.Effect + readonly delete: (thread: ChatThread, messageId: string) => Effect.Effect + readonly fetchMessage: (thread: ChatThread, messageId: string) => Effect.Effect + readonly history: (thread: ChatThread, options: { + readonly direction: "backward" | "forward" + readonly from?: string | undefined + }) => Stream.Stream + readonly download: ( + thread: ChatThread, + attachment: Attachment, + options: { readonly maxBytes: number } + ) => Stream.Stream + readonly startThread: ( + thread: ChatThread, + messageId: string, + options?: { readonly name?: string | undefined } + ) => Effect.Effect + readonly getThread: (thread: ChatThread) => Effect.Effect + readonly opener: (thread: ChatThread) => Effect.Effect, ChatError> + readonly getUser: ( + id: string, + options?: { readonly in?: ChatThread | undefined } + ) => Effect.Effect +} + +/** + * A platform's native streaming of one message, used by `ChatMarkdown.stream` + * when present. It is adapter-facing and not on `Chat`. + * + * **Details** + * + * - `start` fails with `Unsupported` when the platform refuses the feature + * for this thread or recipient, and the caller falls back to post-then-edit. + * It holds nothing back: all of `markdown` is sent. + * - `append` is never retried by the adapter. `open` means the text was + * added apart from its last `held` characters, `stopped` means nothing was + * added because a user stopped the stream, and `closed` means nothing was + * added because the stream is closed or expired. `held` trailing characters + * were not sent and go again at the front of the next append; `flush` holds + * nothing back. A `TooLarge` failure means nothing was added and the stream + * is still open. + * - `stop` closes the stream. `stopped` says whether a user had clicked stop + * on it. It succeeds with `stopped: false` on a stream that is already + * closed. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface NativeStream { + readonly start: (thread: ChatThread, options: { + readonly markdown: string + readonly replyTo?: ReplyTo | undefined + readonly recipient?: string | undefined + }) => Effect.Effect + readonly append: ( + thread: ChatThread, + messageId: string, + markdown: string, + options?: { readonly flush?: boolean | undefined } + ) => Effect.Effect< + { readonly state: "open" | "stopped" | "closed"; readonly held: number }, + ChatError + > + readonly stop: ( + thread: ChatThread, + messageId: string, + options: { readonly end: "done" | "rotating" } + ) => Effect.Effect<{ readonly stopped: boolean }, ChatError> +} + +/** + * What an adapter package builds: the platform's ops, its descriptor and, + * when the platform has one, its native stream. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface ChatAdapter extends Ops { + readonly descriptor: Descriptor + readonly nativeStream?: NativeStream | undefined +} + +/** + * Service that holds the adapters by platform. `Chat.layer` provides it. + * + * **Details** + * + * `get` fails with `NoAdapter` for a platform with no adapter registered. + * Registering a second adapter for a platform replaces the first. + * + * @stability unstable + * @category services + * @since 4.1.5 + */ +export class Registry extends Context.Service Effect.Effect + readonly get: (platform: string) => Effect.Effect + readonly descriptors: Effect.Effect> +}>()("effect/chat/ChatAdapter/Registry") {} + +/** + * Creates the layer that registers an adapter in the `Registry`. + * + * **When to use** + * + * Use when building an adapter package's layer. A platform that is off is a + * layer left out. + * + * @stability unstable + * @category layers + * @since 4.1.5 + */ +export const layer = ( + adapter: Effect.Effect +): Layer.Layer | Registry> => + Layer.effectDiscard(Effect.gen(function*() { + const registry = yield* Registry + yield* registry.register(yield* adapter) + })) + +/** + * Fails with `TooLarge` when Markdown does not fit the descriptor's + * `limits.messageLength`. + * + * **When to use** + * + * Use when implementing `post`, `edit` and `NativeStream.start` in an adapter, + * so a message that is too long fails without a call to the platform. + * + * **Gotchas** + * + * It compares `markdown.length` with the limit. That measure is provisional: + * a platform that counts the escaped string it is sent can still refuse a + * message that passes. + * + * @stability unstable + * @category validation + * @since 4.1.5 + */ +export const checkMessageLength = ( + descriptor: Descriptor, + op: string, + markdown: string +): Effect.Effect => + markdown.length <= descriptor.limits.messageLength ? Effect.void : Effect.fail( + new ChatError({ platform: descriptor.platform, op, reason: new TooLarge({ detail: "message_too_long" }) }) + ) + +const maxRetries = 3 +const baseDelay = Duration.millis(500) + +/** + * Retries an adapter request with the policy adapters share. + * + * **Details** + * + * - Only failures whose retry value is `retry` are retried, up to three + * times. `uncertain` and `denied` failures are returned at once. + * - The wait is the error's `retryAfter` when it has one, otherwise an + * exponential backoff from 500 milliseconds. + * - Inside `Chat.withoutRetries` the request runs once. + * + * @stability unstable + * @category error handling + * @since 4.1.5 + */ +export const retrySafe = (effect: Effect.Effect): Effect.Effect => + Effect.flatMap(RetriesDisabled, (disabled) => { + if (disabled) { + return effect + } + const loop = (attempt: number): Effect.Effect => + Effect.catchIf( + effect, + (error) => error.retry === "retry" && attempt < maxRetries, + (error) => + Effect.flatMap( + Effect.sleep(error.retryAfter ?? Duration.times(baseDelay, 2 ** attempt)), + () => loop(attempt + 1) + ) + ) + return loop(0) + }) diff --git a/packages/effect/src/chat/ChatError.ts b/packages/effect/src/chat/ChatError.ts new file mode 100644 index 00000000000..75ebced7ba4 --- /dev/null +++ b/packages/effect/src/chat/ChatError.ts @@ -0,0 +1,639 @@ +/** + * The error every chat operation fails with. + * + * A `ChatError` records the platform and op, and holds one of twelve reasons. + * Each reason has a three-way retry value: `retry` means nothing happened and + * the request is safe to send again, `uncertain` means a write may or may not + * have landed, and `denied` means sending again gives the same answer. + * + * **Details** + * + * - `detail` is redacted: a platform code such as `channel_not_found`, never + * message text, file names or ids. + * - `cause` is the error underneath (an HTTP error, a client library error, a + * `SchemaError`). It is unredacted and can hold URLs, ids and payload + * values. Schema encoding keeps it and `toJSON` leaves it out, so logging an + * error does not print it. + * + * @stability unstable + * @since 4.1.5 + */ +import type * as Duration from "../Duration.ts" +import * as Predicate from "../Predicate.ts" +import * as Schema from "../Schema.ts" + +/** + * Schema for the retry value of a chat error. + * + * **Details** + * + * - `retry`: nothing happened, safe to send again. + * - `uncertain`: the write may or may not have landed. Adapters never retry it. + * - `denied`: sending again gives the same answer. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const Retry = Schema.Literals(["retry", "uncertain", "denied"]) + +/** + * The retry value of a chat error. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type Retry = typeof Retry.Type + +/** + * Schema for a capability name from `ChatAdapter.Descriptor`. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const Capability = Schema.Literals([ + "edit", + "delete", + "fetchMessage", + "history", + "download", + "files", + "replyTo", + "startThread", + "getThread", + "opener", + "getUser", + "nativeStream" +]) + +/** + * A capability name from `ChatAdapter.Descriptor`. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type Capability = typeof Capability.Type + +const detail = Schema.optionalKey(Schema.String) + +const cause = Schema.optional(Schema.Defect()) + +const withoutCause = (json: unknown): unknown => { + if (Predicate.isObject(json) && "cause" in json) { + const { cause: _, ...rest } = json as Record + return rest + } + return json +} + +const reasonMessage = (reason: { readonly _tag: string; readonly detail?: string | undefined }): string => + reason.detail === undefined ? reason._tag : `${reason._tag}: ${reason.detail}` + +/** + * Reason for a `ChatError`: the platform rate limited the request. + * + * **Details** + * + * Retry value `retry`: nothing happened. `retryAfter` is the wait the platform asked for, when it gave one. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class RateLimited extends Schema.TaggedError("effect/chat/ChatError/RateLimited")("RateLimited", { + retryAfter: Schema.optionalKey(Schema.Duration), + detail, + cause +}) { + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "retry" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for an `ChatError`: the platform has no equivalent for the op. + * + * **Details** + * + * Retry value `denied`. Every op exists on every platform and fails with this where the platform has no equivalent; `capability` names what is missing. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class Unsupported extends Schema.TaggedError("effect/chat/ChatError/Unsupported")("Unsupported", { + capability: Capability, + detail, + cause +}) { + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for a `ChatError`: the request failed in transport. + * + * **Details** + * + * Retry value `retry` when the request never left, `uncertain` when it did and no answer came. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class Transport extends Schema.TaggedError("effect/chat/ChatError/Transport")("Transport", { + retry: Retry, + detail, + cause +}) { + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for a `ChatError`: the platform answered with a server error. + * + * **Details** + * + * Retry value `retry` for reads, `uncertain` for writes. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class PlatformUnavailable + extends Schema.TaggedError("effect/chat/ChatError/PlatformUnavailable")("PlatformUnavailable", { + retry: Retry, + detail, + cause + }) +{ + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for a `ChatError`: no adapter is registered for the address's platform. + * + * **Details** + * + * Retry value `denied`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class NoAdapter extends Schema.TaggedError("effect/chat/ChatError/NoAdapter")("NoAdapter", { + detail, + cause +}) { + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for an `ChatError`: the platform refused the credentials: a bad or revoked token. + * + * **Details** + * + * Retry value `denied`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class Unauthenticated + extends Schema.TaggedError("effect/chat/ChatError/Unauthenticated")("Unauthenticated", { + detail, + cause + }) +{ + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for a `ChatError`: the platform refused the request: a missing scope, not in the channel, an archived thread. + * + * **Details** + * + * Retry value `denied`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class Forbidden extends Schema.TaggedError("effect/chat/ChatError/Forbidden")("Forbidden", { + detail, + cause +}) { + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for a `ChatError`: the thread, message, user or attachment is gone. + * + * **Details** + * + * Retry value `denied`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class NotFound extends Schema.TaggedError("effect/chat/ChatError/NotFound")("NotFound", { + detail, + cause +}) { + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for a `ChatError`: the request is past a descriptor limit: message length, file size or `download`'s `maxBytes`. + * + * **Details** + * + * Retry value `denied`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class TooLarge extends Schema.TaggedError("effect/chat/ChatError/TooLarge")("TooLarge", { + detail, + cause +}) { + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for an `ChatError`: the platform refused the request as malformed. + * + * **Details** + * + * Retry value `denied`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class InvalidRequest + extends Schema.TaggedError("effect/chat/ChatError/InvalidRequest")("InvalidRequest", { + detail, + cause + }) +{ + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for an `ChatError`: the platform answered with something the adapter cannot decode. + * + * **Details** + * + * Retry value `denied`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class InvalidResponse + extends Schema.TaggedError("effect/chat/ChatError/InvalidResponse")("InvalidResponse", { + detail, + cause + }) +{ + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "denied" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * Reason for an `ChatError`: the request failed for a reason the adapter cannot classify. + * + * **Details** + * + * Retry value `uncertain`: a write may or may not have landed. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class Unknown extends Schema.TaggedError("effect/chat/ChatError/Unknown")("Unknown", { + detail, + cause +}) { + /** + * The retry value of this reason, fixed per reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return "uncertain" + } + + override get message(): string { + return reasonMessage(this) + } + + override toJSON(): unknown { + return withoutCause(super.toJSON()) + } +} + +/** + * One of the twelve reasons a `ChatError` holds. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export type ChatErrorReason = + | RateLimited + | Unsupported + | Transport + | PlatformUnavailable + | NoAdapter + | Unauthenticated + | Forbidden + | NotFound + | TooLarge + | InvalidRequest + | InvalidResponse + | Unknown + +/** + * Schema for the twelve reasons a `ChatError` holds. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ChatErrorReason: Schema.Union<[ + typeof RateLimited, + typeof Unsupported, + typeof Transport, + typeof PlatformUnavailable, + typeof NoAdapter, + typeof Unauthenticated, + typeof Forbidden, + typeof NotFound, + typeof TooLarge, + typeof InvalidRequest, + typeof InvalidResponse, + typeof Unknown +]> = Schema.Union([ + RateLimited, + Unsupported, + Transport, + PlatformUnavailable, + NoAdapter, + Unauthenticated, + Forbidden, + NotFound, + TooLarge, + InvalidRequest, + InvalidResponse, + Unknown +]) + +const TypeId = "~effect/chat/ChatError" as const + +/** + * The error every chat operation fails with. + * + * **Details** + * + * - `op` is the operation that failed: `post`, `edit`, `history` and so on. + * - `cause` is the reason, so a failed span's stack trace carries the whole + * chain: the `ChatError`, the reason and the error under it. + * - `retry` and `retryAfter` delegate to the reason. + * - `message` is built from the platform, op, reason and `detail`, never from + * the cause. + * + * **Example** (Matching on a reason) + * + * ```ts import.meta.vitest + * import { Effect } from "effect" + * import { ChatError } from "effect/chat" + * + * const failing = Effect.fail( + * new ChatError.ChatError({ + * platform: "slack", + * op: "post", + * reason: new ChatError.NotFound({ detail: "channel_not_found" }) + * }) + * ) + * + * const program = failing.pipe( + * Effect.catchReason("ChatError", "NotFound", (reason) => Effect.succeed(reason.detail)) + * ) + * + * await Effect.runPromise(program) // => "channel_not_found" + * ``` + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class ChatError extends Schema.TaggedError("effect/chat/ChatError")("ChatError", { + platform: Schema.String, + op: Schema.String, + reason: ChatErrorReason +}) { + /** + * Marks the value as a `ChatError` for `isChatError`. + * + * @since 4.1.5 + */ + readonly [TypeId] = TypeId + + /** + * The reason, so the chain under it ends up in a failed span's stack trace. + * + * @since 4.1.5 + */ + override readonly cause = this.reason + + /** + * The retry value of the reason. + * + * @since 4.1.5 + */ + get retry(): Retry { + return this.reason.retry + } + + /** + * The wait the platform asked for before a retry, when the reason is + * `RateLimited` and it gave one. + * + * @since 4.1.5 + */ + get retryAfter(): Duration.Duration | undefined { + return this.reason._tag === "RateLimited" ? this.reason.retryAfter : undefined + } + + override get message(): string { + return `${this.platform}.${this.op}: ${this.reason.message}` + } + + override toJSON(): unknown { + return { + _tag: this._tag, + platform: this.platform, + op: this.op, + reason: this.reason.toJSON() + } + } +} + +/** + * Returns whether a value is a `ChatError`. + * + * @stability unstable + * @category guards + * @since 4.1.5 + */ +export const isChatError = (u: unknown): u is ChatError => Predicate.hasProperty(u, TypeId) diff --git a/packages/effect/src/chat/ChatEvent.ts b/packages/effect/src/chat/ChatEvent.ts new file mode 100644 index 00000000000..8dfc57a705c --- /dev/null +++ b/packages/effect/src/chat/ChatEvent.ts @@ -0,0 +1,179 @@ +/** + * Inbound events from a chat platform. + * + * Adapters deliver a `ChatEvent` to the consumer's `ChatHandler`. Delivery is + * at-least-once: `dedupeKey` gives two deliveries of one event the same key, + * and the library keeps no seen-store. + * + * @stability unstable + * @since 4.1.5 + */ +import * as Schema from "../Schema.ts" +import { ChatMessage } from "./ChatMessage.ts" +import * as ChatThread from "./ChatThread.ts" + +/** + * Schema for what an address turned out to be: a channel, a thread or a direct + * conversation. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ThreadKind = Schema.Literals(["channel", "thread", "direct"]) + +/** + * What an address turned out to be: a channel, a thread or a direct + * conversation. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ThreadKind = typeof ThreadKind.Type + +/** + * Schema for a message that arrived in a thread. + * + * **Details** + * + * `thread` equals `message.thread`. `raw` is the delivery envelope; the + * message payload is on `message.raw`. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const MessageCreated = Schema.TaggedStruct("MessageCreated", { + thread: ChatThread.ChatThread, + kind: ThreadKind, + message: ChatMessage, + raw: Schema.Json +}).annotate({ identifier: "ChatEvent.MessageCreated" }) + +/** + * A message that arrived in a thread. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type MessageCreated = typeof MessageCreated.Type + +const reaction = { + thread: ChatThread.ChatThread, + messageId: Schema.String, + messageAuthorId: Schema.optionalKey(Schema.String), + userId: Schema.String, + emoji: Schema.String, + timestamp: Schema.optionalKey(Schema.DateTimeUtc), + raw: Schema.Json +} + +/** + * Schema for a reaction a user added to a message. + * + * **Details** + * + * - `thread` is where the platform says it happened. On Slack this is the + * channel, even for a message in a thread; `Chat.fetchMessage` returns the + * message with its real address. + * - `emoji` is a Unicode emoji, or `custom:{name}` for one the adapter's table + * does not know. + * - `messageAuthorId` and `timestamp` are missing when the platform does not + * send them. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ReactionAdded = Schema.TaggedStruct("ReactionAdded", reaction).annotate({ + identifier: "ChatEvent.ReactionAdded" +}) + +/** + * A reaction a user added to a message. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ReactionAdded = typeof ReactionAdded.Type + +/** + * Schema for a reaction a user removed from a message. + * + * **Details** + * + * The fields mean the same as on `ReactionAdded`. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ReactionRemoved = Schema.TaggedStruct("ReactionRemoved", reaction).annotate({ + identifier: "ChatEvent.ReactionRemoved" +}) + +/** + * A reaction a user removed from a message. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ReactionRemoved = typeof ReactionRemoved.Type + +/** + * Schema for an inbound chat event. + * + * **Gotchas** + * + * The union is open: later releases add members such as edits and deletes, so + * a `switch` over `_tag` needs a `default`. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ChatEvent = Schema.Union([MessageCreated, ReactionAdded, ReactionRemoved]).annotate({ + identifier: "ChatEvent" +}) + +/** + * An inbound chat event. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ChatEvent = typeof ChatEvent.Type + +/** + * Returns the key two deliveries of one event share. + * + * **When to use** + * + * Use to drop redelivered events: delivery is at-least-once and the library + * keeps no seen-store. + * + * **Details** + * + * - A message is `message/{thread}/{id}`, with the thread in its + * `{platform}:{id}` form. + * - A reaction is `reaction/{messageId}/{userId}/{emoji}/{added|removed}`. + * + * @stability unstable + * @category getters + * @since 4.1.5 + */ +export const dedupeKey = (event: ChatEvent): string => { + switch (event._tag) { + case "MessageCreated": + return `message/${ChatThread.toString(event.message.thread)}/${event.message.id}` + case "ReactionAdded": + return `reaction/${event.messageId}/${event.userId}/${event.emoji}/added` + case "ReactionRemoved": + return `reaction/${event.messageId}/${event.userId}/${event.emoji}/removed` + } +} diff --git a/packages/effect/src/chat/ChatHandler.ts b/packages/effect/src/chat/ChatHandler.ts new file mode 100644 index 00000000000..77242db6fd8 --- /dev/null +++ b/packages/effect/src/chat/ChatHandler.ts @@ -0,0 +1,100 @@ +/** + * The service a consumer provides to receive chat events. + * + * Adapters take the `ChatHandler` service from context and call `handle` for + * every inbound event. The contract is "accept, fast": success means the event + * is the consumer's and is never redelivered. + * + * @stability unstable + * @since 4.1.5 + */ +import * as Context from "../Context.ts" +import * as Effect from "../Effect.ts" +import * as Layer from "../Layer.ts" +import * as Schema from "../Schema.ts" +import type * as Scope from "../Scope.ts" +import type { ChatEvent } from "./ChatEvent.ts" + +/** + * Error for an event that was not accepted. + * + * **Details** + * + * A handler fails with it to refuse an event, and an adapter's entry point + * fails with it when it could not finish normalising one. Slack answers 503 so + * the event is redelivered; the Discord gateway layer drops it. + * + * **Gotchas** + * + * It has no fields, so whoever raises it logs the reason first. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class NotAccepted extends Schema.TaggedError("effect/chat/ChatHandler/NotAccepted")( + "NotAccepted", + {} +) {} + +/** + * Service that receives inbound chat events, provided by the consumer. + * + * **Details** + * + * Adapters take the service and call `handle`. Success means the event is the + * consumer's and is never redelivered; `NotAccepted` refuses it. + * + * **Gotchas** + * + * Forking the work and returning loses events on a crash. How durable an + * accepted event is belongs to the consumer. + * + * @see {@link layer} for the only constructor + * + * @stability unstable + * @category services + * @since 4.1.5 + */ +export class ChatHandler extends Context.Service Effect.Effect +}>()("effect/chat/ChatHandler") {} + +/** + * Creates the `ChatHandler` layer from a function that handles one event. + * + * **Details** + * + * - The bot's own messages are dropped before `handle` runs, unless + * `deliverSelf` is `true`. Other bots' messages are delivered, flagged with + * `author.isBot`. + * - Every event runs in a `ChatHandler.handle` span and its own `Scope`. + * + * @stability unstable + * @category layers + * @since 4.1.5 + */ +export const layer = ( + handle: (event: ChatEvent) => Effect.Effect, + options?: { readonly deliverSelf?: boolean | undefined } +): Layer.Layer> => + Layer.effect( + ChatHandler, + Effect.contextWith((context: Context.Context>) => { + const deliverSelf = options?.deliverSelf === true + return Effect.succeed(ChatHandler.of({ + handle: (event) => { + if (!deliverSelf && event._tag === "MessageCreated" && event.message.author.isSelf) { + return Effect.void + } + return handle(event).pipe( + Effect.scoped, + Effect.provideContext(context), + Effect.withSpan("ChatHandler.handle", { + attributes: { "chat.platform": event.thread.platform, "chat.op": "handle" } + }) + ) + } + })) + }) + ) diff --git a/packages/effect/src/chat/ChatMessage.ts b/packages/effect/src/chat/ChatMessage.ts new file mode 100644 index 00000000000..ec669fdcc9d --- /dev/null +++ b/packages/effect/src/chat/ChatMessage.ts @@ -0,0 +1,178 @@ +/** + * Messages read from a chat platform. + * + * A `ChatMessage` has the same shape on every read path: inbound events, + * `Chat.fetchMessage` and `Chat.history`. Its `text` is the platform's own + * content string, verbatim, and its mentions are data with offsets into that + * text. + * + * @stability unstable + * @since 4.1.5 + */ +import * as Schema from "../Schema.ts" +import { ChatThread } from "./ChatThread.ts" + +/** + * Schema for the author of a message. + * + * **Details** + * + * `name` is a best-effort display name: whatever the payload carries. There + * is no lookup, so inbound messages and history can differ. Other bots' + * messages are delivered with `isBot: true`; `isSelf` marks the bot's own. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const Author = Schema.Struct({ + id: Schema.String, + name: Schema.optionalKey(Schema.String), + isBot: Schema.Boolean, + isSelf: Schema.Boolean +}).annotate({ identifier: "ChatMessage.Author" }) + +/** + * The author of a message. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type Author = typeof Author.Type + +/** + * Schema for a mention inside a message's text. + * + * **Details** + * + * `start` and `end` are offsets into `ChatMessage.text`, in UTF-16 code + * units, so `text.slice(start, end)` is the platform's own token for the + * mention. `id` is the platform id, or `here`, `channel` or `everyone` for + * a broadcast. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const Mention = Schema.Struct({ + kind: Schema.Literals(["user", "role", "channel", "broadcast"]), + id: Schema.String, + start: Schema.Int, + end: Schema.Int, + isSelf: Schema.Boolean +}).annotate({ identifier: "ChatMessage.Mention" }) + +/** + * A mention inside a message's text. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type Mention = typeof Mention.Type + +/** + * Schema for a file attached to a message. + * + * **Gotchas** + * + * An attachment never carries a URL. `Chat.download` resolves the id again. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const Attachment = Schema.Struct({ + id: Schema.String, + name: Schema.optionalKey(Schema.String), + contentType: Schema.optionalKey(Schema.String), + size: Schema.optionalKey(Schema.Int) +}).annotate({ identifier: "ChatMessage.Attachment" }) + +/** + * A file attached to a message. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type Attachment = typeof Attachment.Type + +/** + * Schema for the message a message replies to. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ReplyTo = Schema.Struct({ + messageId: Schema.String, + authorId: Schema.optionalKey(Schema.String) +}).annotate({ identifier: "ChatMessage.ReplyTo" }) + +/** + * The message a message replies to. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ReplyTo = typeof ReplyTo.Type + +/** + * Schema for a message read from a chat platform. + * + * **Details** + * + * - `thread` is the address the message was posted to, the same on every read + * path. It never changes: a message a thread hangs off stays in the parent, + * also once it has replies. `Chat.startThread(message.thread, message.id)` + * is the way from such a message to its thread. + * - `text` is the platform's own content string, verbatim, with mention tokens + * and code fences in place. + * - `raw` is the platform's message payload, as a JSON value. + * + * **Gotchas** + * + * `text` is a different format from outbound Markdown and cannot be posted + * back as is. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ChatMessage = Schema.Struct({ + id: Schema.String, + thread: ChatThread, + author: Author, + text: Schema.String, + mentions: Schema.Array(Mention), + replyTo: Schema.optionalKey(ReplyTo), + attachments: Schema.Array(Attachment), + timestamp: Schema.DateTimeUtc, + raw: Schema.Json +}).annotate({ identifier: "ChatMessage" }) + +/** + * A message read from a chat platform. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ChatMessage = typeof ChatMessage.Type + +/** + * Returns whether the message mentions the bot. + * + * **Gotchas** + * + * A reply to the bot is not a mention. Whether it counts as one is the + * consumer's policy. + * + * @stability unstable + * @category predicates + * @since 4.1.5 + */ +export const mentionsSelf = (message: ChatMessage): boolean => message.mentions.some((mention) => mention.isSelf) diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts new file mode 100644 index 00000000000..8fcd3c3fc6d --- /dev/null +++ b/packages/effect/src/chat/ChatTest.ts @@ -0,0 +1,1381 @@ +/** + * Testing tools for chat adapters and their consumers. + * + * \`layer\` builds a whole chat in memory: \`Chat\`, its registry and one fake + * adapter with configurable capabilities and fault injection. \`conformance\` + * is the suite of rules every adapter obeys, as plain Effects keyed by rule + * name. \`checkMessage\` and \`checkEvent\` assert the invariants every message + * and event holds, for fixture tests and live runs. + * + * **Details** + * + * The fake adapter's mention syntax is \`<@id>\` for a user, \`<@&id>\` for a + * role, \`<#id>\` for a channel and \`\` for a broadcast. + * + * @stability unstable + * @since 4.1.5 + */ +import * as Context from "../Context.ts" +import * as DateTime from "../DateTime.ts" +import * as Duration from "../Duration.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import * as Layer from "../Layer.ts" +import * as Option from "../Option.ts" +import * as Schema from "../Schema.ts" +import * as Stream from "../Stream.ts" +import * as Chat from "./Chat.ts" +import type { ChatAdapter, Descriptor, File, Posted } from "./ChatAdapter.ts" +import { checkMessageLength, Registry, retrySafe } from "./ChatAdapter.ts" +import type { Capability, ChatErrorReason } from "./ChatError.ts" +import { + ChatError, + Forbidden, + InvalidRequest, + isChatError, + NotFound, + RateLimited, + TooLarge, + Transport, + Unsupported +} from "./ChatError.ts" +import type { ThreadKind } from "./ChatEvent.ts" +import * as ChatEvent from "./ChatEvent.ts" +import { ChatHandler } from "./ChatHandler.ts" +import type { NotAccepted } from "./ChatHandler.ts" +import type { Attachment, Mention, ReplyTo } from "./ChatMessage.ts" +import * as ChatMessage from "./ChatMessage.ts" +import * as ChatThread from "./ChatThread.ts" + +/** + * Reads a slice of \`ChatMessage.text\` as one of the platform's mention + * tokens. + * + * **Details** + * + * The core does not know any platform's syntax, so the caller supplies it. A + * slice that is not a mention token returns \`None\`. + * + * **Gotchas** + * + * The name is provisional. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ParseMention = (slice: string) => Option.Option<{ + readonly kind: Mention["kind"] + readonly id: string +}> + +/** + * One call the fake adapter received, in order. Every attempt is a call, so a + * retried request shows up once per attempt. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface Call { + readonly op: string + readonly thread: ChatThread.ChatThread + readonly messageId?: string | undefined + readonly markdown?: string | undefined + readonly files?: ReadonlyArray | undefined + readonly outcome: "ok" | ChatErrorReason["_tag"] +} + +/** + * Service that controls the fake adapter built by \`layer\`. + * + * **Details** + * + * - \`makeThread\` creates a fresh address: a channel by default, a direct + * conversation, or a thread under a user's message in a fresh channel. + * - \`userPosts\` puts another identity's message in a thread and returns its + * event without delivering it. \`deliver\` delivers an event the way an + * adapter does, by calling the \`ChatHandler\` service. + * - \`messages\` is what a thread shows now, oldest first, and \`calls\` is every + * call the adapter received. + * - \`failNext\` makes the next \`times\` calls of \`op\` fail with \`reason\`. + * \`landed\` makes the write happen anyway, which is what \`uncertain\` means. + * + * @stability unstable + * @category services + * @since 4.1.5 + */ +export class ChatTest extends Context.Service Effect.Effect + readonly userPosts: (thread: ChatThread.ChatThread, message: { + readonly text: string + readonly authorId?: string | undefined + readonly isBot?: boolean | undefined + readonly mentionsSelf?: boolean | undefined + readonly replyTo?: ReplyTo | undefined + readonly files?: ReadonlyArray | undefined + }) => Effect.Effect + readonly deliver: (event: ChatEvent.ChatEvent) => Effect.Effect + readonly messages: (thread: ChatThread.ChatThread) => Effect.Effect> + readonly calls: Effect.Effect> + readonly failNext: (op: string, reason: ChatErrorReason, options?: { + readonly times?: number | undefined + readonly landed?: boolean | undefined + }) => Effect.Effect +}>()("effect/chat/ChatTest") {} + +// ----------------------------------------------------------------------------- +// fake adapter +// ----------------------------------------------------------------------------- + +const allCapabilities: ReadonlyArray = [ + "edit", + "delete", + "fetchMessage", + "history", + "download", + "files", + "replyTo", + "startThread", + "getThread", + "opener", + "getUser" +] + +interface StoredThread { + readonly thread: ChatThread.ChatThread + readonly kind: ThreadKind + readonly name?: string | undefined + readonly parent?: ChatThread.ChatThread | undefined + readonly openerId?: string | undefined + readonly createdAt: DateTime.Utc +} + +interface StoredMessage { + readonly id: string + readonly thread: ChatThread.ChatThread + readonly authorId: string + readonly isBot: boolean + readonly isSelf: boolean + text: string + mentions: ReadonlyArray + readonly replyTo?: ReplyTo | undefined + readonly attachments: ReadonlyArray<{ readonly attachment: Attachment; readonly content: Uint8Array }> + readonly timestamp: DateTime.Utc +} + +interface Fault { + readonly reason: ChatErrorReason + remaining: number + readonly landed: boolean +} + +const mentionPattern = /<(@&|@|#|!)([^<>\s]+)>/g + +const mentionKinds: Record = { + "@": "user", + "@&": "role", + "#": "channel", + "!": "broadcast" +} + +const parseMentions = (text: string, selfId: string): ReadonlyArray => + Array.from(text.matchAll(mentionPattern), (match) => { + const kind = mentionKinds[match[1]] + return { + kind, + id: match[2], + start: match.index, + end: match.index + match[0].length, + isSelf: kind === "user" && match[2] === selfId + } + }) + +const downloadChunkSize = 1024 + +const makeFake = (options: { + readonly platform: string + readonly selfId: string + readonly capabilities: ReadonlyArray + readonly limits: Partial +}) => { + const { platform, selfId } = options + const descriptor: Descriptor = { + platform, + capabilities: new Set(options.capabilities.filter((capability) => capability !== "nativeStream")), + limits: { + messageLength: 4000, + filesPerMessage: 10, + uploadBytes: 10 * 1024 * 1024, + minWriteInterval: Duration.zero, + ...options.limits + } + } + const threads = new Map() + const messages = new Map() + const order: Array = [] + const threadUnder = new Map() + const users = new Map([[selfId, { isBot: true }]]) + const calls: Array = [] + const faults = new Map>() + let counter = 0 + const nextId = (prefix: string) => prefix + String(++counter) + + const chatError = (op: string, reason: ChatErrorReason) => new ChatError({ platform, op, reason }) + const fail = (op: string, reason: ChatErrorReason) => Effect.fail(chatError(op, reason)) + + const toMessage = (message: StoredMessage): ChatMessage.ChatMessage => ({ + id: message.id, + thread: message.thread, + author: { + id: message.authorId, + name: message.isSelf ? "test-bot" : message.authorId, + isBot: message.isBot, + isSelf: message.isSelf + }, + text: message.text, + mentions: message.mentions, + ...(message.replyTo === undefined ? {} : { replyTo: message.replyTo }), + attachments: message.attachments.map((stored) => stored.attachment), + timestamp: message.timestamp, + raw: { + type: "message", + id: message.id, + channel: message.thread.id, + user: message.authorId, + text: message.text + } + }) + + const findThread = (op: string, thread: ChatThread.ChatThread) => + Effect.suspend(() => { + const stored = threads.get(thread.id) + return stored === undefined ? fail(op, new NotFound({ detail: "thread_not_found" })) : Effect.succeed(stored) + }) + + const listMessages = (stored: StoredThread): Array => { + const list: Array = [] + if (stored.openerId !== undefined) { + const opener = messages.get(stored.openerId) + if (opener !== undefined) list.push(opener) + } + for (const id of order) { + const message = messages.get(id) + if (message !== undefined && ChatThread.equals(message.thread, stored.thread)) list.push(message) + } + return list + } + + const findMessage = (op: string, thread: ChatThread.ChatThread, messageId: string) => + Effect.flatMap(findThread(op, thread), (stored) => { + const message = listMessages(stored).find((message) => message.id === messageId) + return message === undefined + ? fail(op, new NotFound({ detail: "message_not_found" })) + : Effect.succeed(message) + }) + + const store = (message: Omit) => + Effect.map(DateTime.now, (timestamp) => { + const stored: StoredMessage = { ...message, id: nextId("m"), timestamp } + messages.set(stored.id, stored) + order.push(stored.id) + return stored + }) + + const storeFiles = (files: ReadonlyArray | undefined) => + (files ?? []).map((file) => ({ + attachment: { + id: nextId("f"), + name: file.name, + contentType: file.contentType, + size: file.content.length + }, + content: file.content + })) + + const createThread = ( + op: string, + thread: ChatThread.ChatThread, + messageId: string, + name: string | undefined + ) => + Effect.flatMap(findMessage(op, thread, messageId), (message) => { + const existing = threadUnder.get(message.id) + if (existing !== undefined) return Effect.succeed(existing) + const parent = threads.get(message.thread.id)! + if (parent.kind === "thread" || !ChatThread.equals(message.thread, thread)) { + return fail(op, new InvalidRequest({ detail: "cannot_thread_reply" })) + } + return Effect.map(DateTime.now, (createdAt) => { + const created = ChatThread.make(platform, thread.id + "/" + message.id) + threads.set(created.id, { + thread: created, + kind: "thread", + name, + parent: thread, + openerId: message.id, + createdAt + }) + threadUnder.set(message.id, created) + return created + }) + }) + + const takeFault = (op: string): Fault | undefined => { + const queue = faults.get(op) + const fault = queue?.[0] + if (fault === undefined) return undefined + fault.remaining-- + if (fault.remaining <= 0) queue!.shift() + return fault + } + + const attempt = ( + call: Omit, + needs: ReadonlyArray, + body: Effect.Effect + ): Effect.Effect => + retrySafe(Effect.suspend(() => { + const record = (outcome: Call["outcome"]) => calls.push({ ...call, outcome }) + const missing = needs.find((capability) => !descriptor.capabilities.has(capability)) + if (missing !== undefined) { + record("Unsupported") + return fail(call.op, new Unsupported({ capability: missing })) + } + const fault = takeFault(call.op) + if (fault !== undefined) { + record(fault.reason._tag) + const failure = fail(call.op, fault.reason) + return fault.landed ? Effect.flatMap(Effect.exit(body), () => failure) : failure + } + return body.pipe( + Effect.tap(() => Effect.sync(() => record("ok"))), + Effect.tapError((error) => Effect.sync(() => record(error.reason._tag))) + ) + })) + + const adapter: ChatAdapter = { + descriptor, + post: (thread, content) => { + const files = content.files ?? [] + const needs: Array = [] + if (files.length > 0) needs.push("files") + if (content.replyTo !== undefined) needs.push("replyTo") + return attempt( + { op: "post", thread, markdown: content.markdown, files: content.files }, + needs, + Effect.gen(function*() { + yield* findThread("post", thread) + yield* checkMessageLength(descriptor, "post", content.markdown) + if ( + files.length > descriptor.limits.filesPerMessage || + files.some((file) => file.content.length > descriptor.limits.uploadBytes) + ) { + return yield* fail("post", new TooLarge({ detail: "file_too_large" })) + } + let replyTo: ReplyTo | undefined + if (content.replyTo !== undefined) { + const target = yield* findMessage("post", thread, content.replyTo.messageId) + replyTo = { messageId: target.id, authorId: target.authorId } + } + const stored = yield* store({ + thread, + authorId: selfId, + isBot: true, + isSelf: true, + text: content.markdown, + mentions: [], + replyTo, + attachments: storeFiles(files) + }) + return { id: stored.id, thread, timestamp: stored.timestamp } satisfies Posted + }) + ) + }, + edit: (thread, messageId, content) => + attempt( + { op: "edit", thread, messageId, markdown: content.markdown }, + ["edit"], + Effect.gen(function*() { + const message = yield* findMessage("edit", thread, messageId) + if (!message.isSelf) return yield* fail("edit", new Forbidden({ detail: "cant_update_message" })) + yield* checkMessageLength(descriptor, "edit", content.markdown) + message.text = content.markdown + message.mentions = [] + }) + ), + delete: (thread, messageId) => + attempt( + { op: "delete", thread, messageId }, + ["delete"], + Effect.gen(function*() { + const message = yield* findMessage("delete", thread, messageId) + if (!message.isSelf) return yield* fail("delete", new Forbidden({ detail: "cant_delete_message" })) + messages.delete(message.id) + }) + ), + fetchMessage: (thread, messageId) => + attempt( + { op: "fetchMessage", thread, messageId }, + ["fetchMessage"], + Effect.map(findMessage("fetchMessage", thread, messageId), toMessage) + ), + history: (thread, options) => + Stream.unwrap(attempt( + { op: "history", thread, messageId: options.from }, + ["history"], + Effect.gen(function*() { + const stored = yield* findThread("history", thread) + const list = listMessages(stored).map(toMessage) + if (options.direction === "backward") list.reverse() + if (options.from === undefined) return Stream.fromIterable(list) + const index = list.findIndex((message) => message.id === options.from) + if (index === -1) return yield* fail("history", new NotFound({ detail: "message_not_found" })) + return Stream.fromIterable(list.slice(index + 1)) + }) + )), + download: (thread, attachment, options) => + Stream.unwrap(attempt( + { op: "download", thread }, + ["download"], + Effect.suspend(() => { + let content: Uint8Array | undefined + for (const message of messages.values()) { + const found = message.attachments.find((stored) => stored.attachment.id === attachment.id) + if (found !== undefined) content = found.content + } + if (content === undefined) return fail("download", new NotFound({ detail: "file_not_found" })) + const chunks: Array = [] + for (let offset = 0; offset < content.length && offset < options.maxBytes; offset += downloadChunkSize) { + const end = Math.min(offset + downloadChunkSize, content.length) + if (end > options.maxBytes) break + chunks.push(content.slice(offset, end)) + } + const tooLarge = content.length > options.maxBytes + ? Stream.fail(chatError("download", new TooLarge({ detail: "max_bytes" }))) + : Stream.empty + return Effect.succeed(Stream.concat(Stream.fromIterable(chunks), tooLarge)) + }) + )), + startThread: (thread, messageId, startOptions) => + attempt( + { op: "startThread", thread, messageId }, + ["startThread"], + createThread("startThread", thread, messageId, startOptions?.name) + ), + getThread: (thread) => + attempt( + { op: "getThread", thread }, + ["getThread"], + Effect.map(findThread("getThread", thread), (stored) => ({ + thread: stored.thread, + kind: stored.kind, + name: stored.name, + parent: stored.parent, + createdAt: stored.createdAt, + raw: { id: stored.thread.id, kind: stored.kind } + })) + ), + opener: (thread) => + attempt( + { op: "opener", thread }, + ["opener"], + Effect.map(findThread("opener", thread), (stored) => { + const opener = stored.openerId === undefined ? undefined : messages.get(stored.openerId) + return opener === undefined ? Option.none() : Option.some(toMessage(opener)) + }) + ), + getUser: (id, userOptions) => + attempt( + { op: "getUser", thread: userOptions?.in ?? ChatThread.make(platform, "") }, + ["getUser"], + Effect.suspend(() => { + const user = users.get(id) + return user === undefined + ? fail("getUser", new NotFound({ detail: "user_not_found" })) + : Effect.succeed({ + id, + name: id === selfId ? "test-bot" : id, + isBot: user.isBot, + isSelf: id === selfId, + raw: { id } + }) + }) + ) + } + + const addThread = (kind: "channel" | "direct") => + Effect.map(DateTime.now, (createdAt) => { + const thread = ChatThread.make(platform, nextId(kind === "channel" ? "c" : "d")) + threads.set(thread.id, { thread, kind, createdAt }) + return thread + }) + + const userPosts: ChatTest["Service"]["userPosts"] = Effect.fnUntraced(function*(thread, message) { + const stored = threads.get(thread.id) + if (stored === undefined) return yield* Effect.die(new Error("ChatTest.userPosts: unknown thread")) + const authorId = message.authorId ?? "user" + const isBot = message.isBot ?? false + users.set(authorId, { isBot }) + const text = message.mentionsSelf === true ? "<@" + selfId + "> " + message.text : message.text + const replyTarget = message.replyTo === undefined ? undefined : messages.get(message.replyTo.messageId) + const created = yield* store({ + thread, + authorId, + isBot, + isSelf: false, + text, + mentions: parseMentions(text, selfId), + replyTo: message.replyTo === undefined ? undefined : { + messageId: message.replyTo.messageId, + ...(replyTarget === undefined ? {} : { authorId: replyTarget.authorId }) + }, + attachments: storeFiles(message.files) + }) + return ChatEvent.MessageCreated.make({ + thread, + kind: stored.kind, + message: toMessage(created), + raw: { type: "event_callback", event_id: nextId("e") } + }) + }) + + const service = ChatTest.of({ + platform, + selfId, + makeThread: (kind = "channel") => { + if (kind !== "thread") return addThread(kind) + return Effect.gen(function*() { + const channel = yield* addThread("channel") + const event = yield* userPosts(channel, { text: "thread opener" }) + const message = (event as ChatEvent.MessageCreated).message + return yield* Effect.orDie(createThread("makeThread", channel, message.id, undefined)) + }) + }, + userPosts, + deliver: (event) => Effect.flatMap(ChatHandler, (handler) => handler.handle(event)), + messages: (thread) => + Effect.sync(() => { + const stored = threads.get(thread.id) + return stored === undefined ? [] : listMessages(stored).map(toMessage) + }), + calls: Effect.sync(() => calls.slice()), + failNext: (op, reason, failOptions) => + Effect.sync(() => { + const queue = faults.get(op) ?? [] + queue.push({ reason, remaining: failOptions?.times ?? 1, landed: failOptions?.landed ?? false }) + faults.set(op, queue) + }) + }) + + return { adapter, service } +} + +/** + * Creates a whole chat in memory: \`Chat\`, its registry and one fake adapter. + * + * **When to use** + * + * Use to test code that posts and reads through \`Chat\`, and to run the + * conformance suite against the fake adapter. + * + * **Details** + * + * - The platform defaults to \`test\` and the bot's user id to \`bot\`. + * - Every capability is on by default, except \`nativeStream\`: the fake has no + * native stream yet. + * - The default limits are 4000 characters per message, 10 files of up to + * 10 MiB, and no write interval. + * - Two layers merged with different platforms share one \`Chat\`, so routing + * can be tested. The \`ChatTest\` service in context is the last one merged. + * + * @stability unstable + * @category layers + * @since 4.1.5 + */ +export const layer = (options?: { + readonly platform?: string | undefined + readonly selfId?: string | undefined + readonly capabilities?: ReadonlyArray | undefined + readonly limits?: Partial | undefined +}): Layer.Layer => + Layer.effect( + ChatTest, + Effect.gen(function*() { + const registry = yield* Registry + const { adapter, service } = makeFake({ + platform: options?.platform ?? "test", + selfId: options?.selfId ?? "bot", + capabilities: options?.capabilities ?? allCapabilities, + limits: options?.limits ?? {} + }) + yield* registry.register(adapter) + return service + }) + ).pipe(Layer.provideMerge(Chat.layer)) + +// ----------------------------------------------------------------------------- +// invariants +// ----------------------------------------------------------------------------- + +/** + * Error for a conformance rule or invariant that did not hold. + * + * **Details** + * + * \`rule\` names what failed, and \`expected\` and \`actual\` say how. A platform + * error behind the failure is in \`cause\`. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class ConformanceFailure extends Schema.TaggedError( + "effect/chat/ChatTest/ConformanceFailure" +)("ConformanceFailure", { + rule: Schema.String, + expected: Schema.String, + actual: Schema.String, + cause: Schema.optionalKey(Schema.Defect()) +}) { + override get message(): string { + return this.rule + ": expected " + this.expected + ", got " + this.actual + } +} + +const sameMentions = (a: ReadonlyArray, b: ReadonlyArray): boolean => + a.length === b.length && + a.every((mention, i) => { + const other = b[i] + return mention.kind === other.kind && mention.id === other.id && mention.start === other.start && + mention.end === other.end && mention.isSelf === other.isSelf + }) + +const sameReplyTo = (a: ReplyTo | undefined, b: ReplyTo | undefined): boolean => + a === undefined || b === undefined + ? a === b + : a.messageId === b.messageId && a.authorId === b.authorId + +/** + * Returns whether two reads of a message are the same message. + * + * **Details** + * + * It compares \`id\`, \`thread\`, \`author.id\`, \`author.isBot\`, \`author.isSelf\`, + * \`text\`, \`mentions\`, \`replyTo\`, \`timestamp\` and the attachment ids in order. + * \`raw\`, \`author.name\` and the optional attachment fields are left out. + * + * @stability unstable + * @category comparisons + * @since 4.1.5 + */ +export const sameMessage = (a: ChatMessage.ChatMessage, b: ChatMessage.ChatMessage): boolean => + a.id === b.id && + ChatThread.equals(a.thread, b.thread) && + a.author.id === b.author.id && + a.author.isBot === b.author.isBot && + a.author.isSelf === b.author.isSelf && + a.text === b.text && + sameMentions(a.mentions, b.mentions) && + sameReplyTo(a.replyTo, b.replyTo) && + DateTime.Equivalence(a.timestamp, b.timestamp) && + a.attachments.length === b.attachments.length && + a.attachments.every((attachment, i) => attachment.id === b.attachments[i].id) + +const canonicalJson = (value: unknown): string => + JSON.stringify(value, (_, v) => + v !== null && typeof v === "object" && !Array.isArray(v) + ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) + : v) + +const failure = (rule: string, expected: string, actual: string, cause?: unknown) => + new ConformanceFailure({ rule, expected, actual, ...(cause === undefined ? {} : { cause }) }) + +const check = (rule: string, condition: boolean, expected: string, actual: () => string) => + condition ? Effect.void : Effect.fail(failure(rule, expected, actual())) + +const MessageJson = Schema.toCodecJson(ChatMessage.ChatMessage) +const EventJson = Schema.toCodecJson(ChatEvent.ChatEvent) + +const roundTrip = >(rule: string, codec: S, value: S["Type"]) => + Effect.gen(function*() { + const encoded = yield* Schema.encodeEffect(codec)(value) + const decoded = yield* Schema.decodeEffect(codec)(encoded) + const again = yield* Schema.encodeEffect(codec)(decoded) + yield* check( + rule, + canonicalJson(encoded) === canonicalJson(again), + "an unchanged value after encoding and decoding", + () => canonicalJson(again) + ) + return decoded as S["Type"] + }).pipe( + Effect.catchTag( + "SchemaError", + (error) => Effect.fail(failure(rule, "a value that encodes and decodes", "SchemaError", error)) + ) + ) + +const checkThread = Effect.fnUntraced(function*(rule: string, thread: ChatThread.ChatThread, platform: string) { + yield* check(rule, thread.platform === platform, "platform " + platform, () => "platform " + thread.platform) + const decoded = ChatThread.fromString(ChatThread.toString(thread)) + yield* check( + rule, + Option.isSome(decoded) && ChatThread.equals(decoded.value, thread), + "a thread that survives its string codec", + () => ChatThread.toString(thread) + ) +}) + +const checkMessageWith = Effect.fnUntraced(function*(rule: string, message: ChatMessage.ChatMessage, options: { + readonly platform: string + readonly parseMention: ParseMention +}) { + yield* checkThread(rule, message.thread, options.platform) + const mentions = [...message.mentions].sort((a, b) => a.start - b.start) + let end = 0 + for (const mention of mentions) { + yield* check( + rule, + mention.start >= end && mention.start < mention.end && mention.end <= message.text.length, + "mentions inside text without overlap", + () => "mention at " + mention.start + "-" + mention.end + ) + end = mention.end + const parsed = options.parseMention(message.text.slice(mention.start, mention.end)) + yield* check( + rule, + Option.isSome(parsed) && parsed.value.kind === mention.kind && parsed.value.id === mention.id, + "a " + mention.kind + " mention token at " + mention.start + "-" + mention.end, + () => Option.isSome(parsed) ? "a " + parsed.value.kind + " token" : "no mention token" + ) + } + for (const attachment of message.attachments) { + yield* check( + rule, + attachment.id.length > 0 && !("url" in attachment) && !/^[a-z]+:\/\//i.test(attachment.id), + "an attachment with an id and no URL", + () => "attachment " + (attachment.id.length > 0 ? "with a URL" : "without an id") + ) + } + const decoded = yield* roundTrip(rule, MessageJson, message) + yield* check(rule, sameMessage(message, decoded), "the same message after decoding", () => "a different message") +}) + +/** + * Checks the invariants every message holds, for fixture tests and live runs. + * + * **Details** + * + * - Every mention sits inside \`text\`, mentions do not overlap, and each slice + * parses with \`parseMention\` as a token of the mention's kind and id. + * - \`thread.platform\` is the platform, and the thread survives its string + * codec. + * - The message encodes and decodes through its Schema unchanged, \`raw\` + * included. + * - Every attachment has an id and no URL. + * + * @stability unstable + * @category testing + * @since 4.1.5 + */ +export const checkMessage = (message: ChatMessage.ChatMessage, options: { + readonly platform: string + readonly parseMention: ParseMention +}): Effect.Effect => checkMessageWith("checkMessage", message, options) + +/** + * Checks the invariants every event holds, for fixture tests and live runs. + * + * **Details** + * + * - A message event's message passes \`checkMessage\`, and the event's thread is + * the message's. + * - \`thread.platform\` is the platform, and the thread survives its string + * codec. + * - The event encodes and decodes through its Schema unchanged, \`raw\` + * included, and two decodes have the same \`dedupeKey\`. + * - A reaction's \`dedupeKey\` differs between added and removed. + * + * @stability unstable + * @category testing + * @since 4.1.5 + */ +export const checkEvent = (event: ChatEvent.ChatEvent, options: { + readonly platform: string + readonly parseMention: ParseMention +}): Effect.Effect => + Effect.gen(function*() { + const rule = "checkEvent" + yield* checkThread(rule, event.thread, options.platform) + if (event._tag === "MessageCreated") { + yield* checkMessageWith(rule, event.message, options) + yield* check( + rule, + ChatThread.equals(event.thread, event.message.thread), + "the event's thread equal to the message's", + () => ChatThread.toString(event.thread) + ) + } else { + const { _tag, ...fields } = event + const flipped = _tag === "ReactionAdded" + ? ChatEvent.ReactionRemoved.make(fields) + : ChatEvent.ReactionAdded.make(fields) + yield* check( + rule, + ChatEvent.dedupeKey(flipped) !== ChatEvent.dedupeKey(event), + "different keys for an added and a removed reaction", + () => ChatEvent.dedupeKey(event) + ) + } + const first = yield* roundTrip(rule, EventJson, event) + const second = yield* roundTrip(rule, EventJson, event) + const key = ChatEvent.dedupeKey(event) + yield* check( + rule, + ChatEvent.dedupeKey(first) === key && ChatEvent.dedupeKey(second) === key, + "the same dedupeKey for every decode", + () => ChatEvent.dedupeKey(first) + " and " + ChatEvent.dedupeKey(second) + ) + }) + +// ----------------------------------------------------------------------------- +// conformance +// ----------------------------------------------------------------------------- + +const describeExit = (exit: Exit.Exit): string => { + if (Exit.isSuccess(exit)) return "success" + const error = Exit.findErrorOption(exit) + if (Option.isNone(error)) return "a defect or interruption" + return describeError(error.value) +} + +const describeError = (error: unknown): string => { + if (!isChatError(error)) return String(error) + return error.reason._tag === "Unsupported" + ? "Unsupported(" + error.reason.capability + ")" + : error.reason._tag +} + +const conformanceText = (rule: string) => "conformance " + rule + +class Tester { + readonly created: Array<{ readonly thread: ChatThread.ChatThread; readonly id: string }> = [] + readonly rule: string + readonly chat: Chat.Chat["Service"] + readonly descriptor: Descriptor + readonly options: ConformanceOptions + constructor(rule: string, chat: Chat.Chat["Service"], descriptor: Descriptor, options: ConformanceOptions) { + this.rule = rule + this.chat = chat + this.descriptor = descriptor + this.options = options + } + + get thread() { + return this.options.thread + } + + has(capability: Capability) { + return this.descriptor.capabilities.has(capability) + } + + call(effect: Effect.Effect): Effect.Effect { + return Effect.mapError(effect, (error) => { + const listed = error.reason._tag === "Unsupported" && this.has(error.reason.capability) + return failure( + this.rule, + "success", + describeError(error) + (listed ? " for a listed capability" : ""), + error + ) + }) + } + + collect(stream: Stream.Stream): Effect.Effect, ConformanceFailure> { + return this.call(Stream.runCollect(stream)) + } + + check(condition: boolean, expected: string, actual: () => string) { + return check(this.rule, condition, expected, actual) + } + + post( + content: { readonly markdown?: string; readonly replyTo?: ReplyTo; readonly files?: ReadonlyArray }, + thread = this.thread + ) { + return Effect.tap( + this.call(this.chat.post(thread, { markdown: conformanceText(this.rule), ...content })), + (posted) => Effect.sync(() => this.created.push({ thread, id: posted.id })) + ) + } + + userPosts(thread = this.thread) { + return Effect.flatMap( + this.options.userPosts(thread, conformanceText(this.rule)), + (event) => + event._tag === "MessageCreated" + ? Effect.succeed(event) + : Effect.fail(failure(this.rule, "a MessageCreated event from userPosts", event._tag)) + ) + } + + expectReason( + tag: ChatErrorReason["_tag"], + effect: Effect.Effect, + onSuccess?: (a: A) => void + ): Effect.Effect { + return Effect.flatMap(Effect.exit(effect), (exit) => { + if (Exit.isSuccess(exit)) onSuccess?.(exit.value) + const error = Exit.findErrorOption(exit) + const matches = Option.isSome(error) && isChatError(error.value) && error.value.reason._tag === tag + return matches ? Effect.void : Effect.fail(failure( + this.rule, + tag, + describeExit(exit), + Option.getOrUndefined(error) + )) + }) + } + + expectUnsupported(capability: Capability): Effect.Effect { + const expected = "Unsupported(" + capability + ")" + const expect = (effect: Effect.Effect, onSuccess?: (a: A) => void) => + Effect.flatMap(Effect.exit(effect), (exit) => { + if (Exit.isSuccess(exit)) onSuccess?.(exit.value) + const error = Exit.findErrorOption(exit) + const matches = Option.isSome(error) && isChatError(error.value) && + error.value.reason._tag === "Unsupported" && error.value.reason.capability === capability + return matches ? Effect.void : Effect.fail(failure( + this.rule, + expected, + describeExit(exit), + Option.getOrUndefined(error) + )) + }) + const track = (posted: Posted) => void this.created.push({ thread: this.thread, id: posted.id }) + const { chat, thread } = this + const text = conformanceText(this.rule) + switch (capability) { + case "edit": + return Effect.flatMap(this.post({}), (posted) => expect(chat.edit(thread, posted.id, { markdown: text }))) + case "delete": + return Effect.flatMap(this.post({}), (posted) => expect(chat.delete(thread, posted.id))) + case "fetchMessage": + return Effect.flatMap(this.post({}), (posted) => expect(chat.fetchMessage(thread, posted.id))) + case "history": + return expect(Stream.runDrain(Stream.take(chat.history(thread, { direction: "backward" }), 1))) + case "download": + return expect(Stream.runDrain(chat.download(thread, { id: "conformance-missing" }, { maxBytes: 1 }))) + case "files": + return expect(chat.post(thread, { markdown: text, files: [conformanceFile(this.rule)] }), track) + case "replyTo": + return Effect.flatMap( + this.post({}), + (target) => expect(chat.post(thread, { markdown: text, replyTo: { messageId: target.id } }), track) + ) + case "startThread": + return Effect.flatMap(this.post({}), (posted) => expect(chat.startThread(thread, posted.id))) + case "getThread": + return expect(chat.getThread(thread)) + case "opener": + return expect(chat.opener(thread)) + case "getUser": + return Effect.flatMap( + this.userPosts(), + (event) => expect(chat.getUser(this.options.platform, event.message.author.id)) + ) + case "nativeStream": + return Effect.flatMap( + Registry, + (registry) => + Effect.flatMap(this.call(registry.get(this.options.platform)), (adapter) => + this.check( + adapter.nativeStream === undefined, + "no nativeStream on an adapter whose descriptor lacks it", + () => "a nativeStream" + )) + ) + } + } + + get cleanup(): Effect.Effect { + return Effect.suspend(() => { + if (!this.has("delete")) return Effect.void + const created = this.created.splice(0).reverse() + return Effect.forEach(created, ({ id, thread }) => Effect.ignore(this.chat.delete(thread, id)), { + discard: true + }) + }) + } +} + +const conformanceFile = (rule: string): File => ({ + name: "conformance.txt", + contentType: "text/plain", + content: new TextEncoder().encode(conformanceText(rule) + " " + "x".repeat(64)) +}) + +const findIn = (messages: ReadonlyArray, id: string) => + messages.find((message) => message.id === id) + +const mentionLike = "@everyone @here <@U0000> <@&1> <#C0000>" + +interface ConformanceOptions { + readonly platform: string + readonly thread: ChatThread.ChatThread + readonly userPosts: (thread: ChatThread.ChatThread, text: string) => Effect.Effect + readonly parseMention: ParseMention + readonly failNext?: + | ((op: string, reason: ChatErrorReason, options?: { + readonly times?: number | undefined + readonly landed?: boolean | undefined + }) => Effect.Effect) + | undefined +} + +/** + * Creates the conformance suite, as plain Effects keyed by rule name, so any + * test runner can run them. + * + * **Details** + * + * - Each rule needs the adapter under test registered in \`Chat\` and a way to + * make another identity's message appear in \`thread\`, which must be a + * channel the suite may write to. + * - A rule is never skipped. When the descriptor lacks a capability a rule + * needs, the rule becomes its inverse: the op fails with \`Unsupported\`. + * There is an \`unsupported/{capability}\` rule for every capability, which + * passes when the capability is listed. + * - A listed capability never fails with \`Unsupported\`, which every rule + * checks as it goes. + * - The three \`retries/*\` rules exist only when \`failNext\` is given. + * - Every rule deletes what it posted when it ends, pass or fail, when the + * platform can delete. + * + * **Gotchas** + * + * The rules are provisional: they can be added, renamed, removed or tightened + * in any release until the suite is frozen. The \`retries/retrySafe\` rule + * waits for real time, so run the suite on a live \`Clock\`. + * + * @stability unstable + * @category testing + * @since 4.1.5 + */ +export const conformance = (options: { + readonly platform: string + readonly thread: ChatThread.ChatThread + readonly userPosts: (thread: ChatThread.ChatThread, text: string) => Effect.Effect + readonly parseMention: ParseMention + readonly failNext?: + | ((op: string, reason: ChatErrorReason, options?: { + readonly times?: number | undefined + readonly landed?: boolean | undefined + }) => Effect.Effect) + | undefined +}): Readonly>> => { + const rules: Record> = {} + const { parseMention, platform } = options + + const rule = ( + name: string, + needs: ReadonlyArray, + body: (t: Tester) => Effect.Effect + ) => { + rules[name] = Effect.gen(function*() { + const chat = yield* Chat.Chat + const descriptor = yield* Effect.mapError( + chat.descriptor(platform), + (error) => failure(name, "a registered adapter", describeError(error), error) + ) + const t = new Tester(name, chat, descriptor, options) + const missing = needs.find((capability) => !t.has(capability)) + return yield* (missing === undefined ? body(t) : t.expectUnsupported(missing)).pipe( + Effect.ensuring(t.cleanup) + ) + }) + } + + rule("post/fetchable", ["fetchMessage"], (t) => + Effect.gen(function*() { + const posted = yield* t.post({}) + const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check( + posted.id === message.id && ChatThread.equals(posted.thread, t.thread) && + ChatThread.equals(message.thread, t.thread), + "the posted message, addressed to " + ChatThread.toString(t.thread), + () => "message " + message.id + " in " + ChatThread.toString(message.thread) + ) + })) + + rule("post/authorIsSelf", ["fetchMessage"], (t) => + Effect.gen(function*() { + const posted = yield* t.post({}) + const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check( + message.author.isSelf && message.author.isBot, + "author.isSelf and author.isBot", + () => "isSelf " + message.author.isSelf + ", isBot " + message.author.isBot + ) + })) + + rule("post/replyTo", ["replyTo", "fetchMessage"], (t) => + Effect.gen(function*() { + const target = yield* t.post({}) + const reply = yield* t.post({ replyTo: { messageId: target.id } }) + const message = yield* t.call(t.chat.fetchMessage(t.thread, reply.id)) + yield* t.check( + message.replyTo?.messageId === target.id, + "replyTo " + target.id, + () => "replyTo " + message.replyTo?.messageId + ) + })) + + rule("post/files", ["files", "download", "fetchMessage"], (t) => + Effect.gen(function*() { + const file = conformanceFile(t.rule) + const posted = yield* t.post({ files: [file] }) + const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check(message.attachments.length === 1, "one attachment", () => message.attachments.length + "") + const chunks = yield* t.collect( + t.chat.download(t.thread, message.attachments[0], { maxBytes: file.content.length }) + ) + const bytes = new Uint8Array(chunks.reduce((n, chunk) => n + chunk.length, 0)) + chunks.reduce((offset, chunk) => (bytes.set(chunk, offset), offset + chunk.length), 0) + yield* t.check( + bytes.length === file.content.length && bytes.every((byte, i) => byte === file.content[i]), + "the uploaded bytes", + () => bytes.length + " different bytes" + ) + })) + + rule("post/tooLarge", [], (t) => + t.expectReason( + "TooLarge", + t.chat.post(t.thread, { markdown: "x".repeat(t.descriptor.limits.messageLength + 1) }), + (posted) => t.created.push({ thread: t.thread, id: posted.id }) + )) + + rule("post/noMentions", ["fetchMessage"], (t) => + Effect.gen(function*() { + const posted = yield* t.post({ markdown: mentionLike }) + const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check(message.mentions.length === 0, "no mentions", () => message.mentions.length + " mentions") + })) + + const goneId = Effect.fnUntraced(function*(t: Tester) { + const posted = yield* t.post({}) + if (!t.has("delete")) return posted.id + "0" + yield* t.call(t.chat.delete(t.thread, posted.id)) + return posted.id + }) + + rule("edit/keepsId", ["edit", "fetchMessage"], (t) => + Effect.gen(function*() { + const posted = yield* t.post({ markdown: conformanceText(t.rule) + " before" }) + const before = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.call(t.chat.edit(t.thread, posted.id, { markdown: conformanceText(t.rule) + " after" })) + const after = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check( + after.id === posted.id && after.text !== before.text, + "the same id with new text", + () => "id " + after.id + (after.text === before.text ? " with the old text" : "") + ) + })) + + rule("edit/unknownId", ["edit"], (t) => + Effect.flatMap( + goneId(t), + (id) => t.expectReason("NotFound", t.chat.edit(t.thread, id, { markdown: conformanceText(t.rule) })) + )) + + rule("edit/tooLarge", ["edit"], (t) => + Effect.flatMap(t.post({}), (posted) => + t.expectReason( + "TooLarge", + t.chat.edit(t.thread, posted.id, { markdown: "x".repeat(t.descriptor.limits.messageLength + 1) }) + ))) + + rule("delete/gone", ["delete", "fetchMessage"], (t) => + Effect.gen(function*() { + const posted = yield* t.post({}) + yield* t.call(t.chat.delete(t.thread, posted.id)) + yield* t.expectReason("NotFound", t.chat.fetchMessage(t.thread, posted.id)) + })) + + rule( + "delete/unknownId", + ["delete"], + (t) => Effect.flatMap(goneId(t), (id) => t.expectReason("NotFound", t.chat.delete(t.thread, id))) + ) + + rule("history/order", ["history"], (t) => + Effect.gen(function*() { + const a = yield* t.post({ markdown: conformanceText(t.rule) + " a" }) + const b = yield* t.post({ markdown: conformanceText(t.rule) + " b" }) + const c = yield* t.post({ markdown: conformanceText(t.rule) + " c" }) + const backward = yield* t.collect(Stream.take(t.chat.history(t.thread, { direction: "backward" }), 3)) + const forward = yield* t.collect( + Stream.take(t.chat.history(t.thread, { direction: "forward", from: a.id }), 2) + ) + const ids = (messages: ReadonlyArray) => messages.map((m) => m.id).join(",") + yield* t.check(ids(backward) === [c.id, b.id, a.id].join(","), "backward " + [c.id, b.id, a.id], () => + "backward " + ids(backward)) + yield* t.check(ids(forward) === [b.id, c.id].join(","), "forward " + [b.id, c.id], () => + "forward " + ids(forward)) + })) + + rule("history/fromExclusive", ["history"], (t) => + Effect.gen(function*() { + const a = yield* t.post({ markdown: conformanceText(t.rule) + " a" }) + const b = yield* t.post({ markdown: conformanceText(t.rule) + " b" }) + const before = yield* t.collect(Stream.take(t.chat.history(t.thread, { direction: "backward", from: b.id }), 1)) + const after = yield* t.collect(Stream.take(t.chat.history(t.thread, { direction: "forward", from: a.id }), 1)) + yield* t.check( + before[0]?.id === a.id && after[0]?.id === b.id, + "the message next to from, not from itself", + () => "backward " + before[0]?.id + ", forward " + after[0]?.id + ) + })) + + rule("history/sameAsInbound", ["history"], (t) => + Effect.gen(function*() { + const event = yield* t.userPosts() + const history = yield* t.collect(Stream.take(t.chat.history(t.thread, { direction: "backward" }), 20)) + const read = findIn(history, event.message.id) + yield* t.check( + read !== undefined && sameMessage(event.message, read), + "the inbound message in history", + () => read === undefined ? "no such message" : "a different message" + ) + })) + + rule("history/startsWithOpener", ["history", "startThread"], (t) => + Effect.gen(function*() { + const opener = yield* t.post({ markdown: conformanceText(t.rule) + " opener" }) + const thread = yield* t.call(t.chat.startThread(t.thread, opener.id, { name: conformanceText(t.rule) })) + yield* t.post({ markdown: conformanceText(t.rule) + " reply" }, thread) + const first = yield* t.collect(Stream.take(t.chat.history(thread, { direction: "forward" }), 1)) + yield* t.check( + first[0]?.id === opener.id && ChatThread.equals(first[0].thread, t.thread), + "the opener first, addressed to " + ChatThread.toString(t.thread), + () => + first[0] === undefined + ? "an empty history" + : "message " + first[0].id + " in " + ChatThread.toString(first[0].thread) + ) + })) + + rule("message/threadStable", ["fetchMessage", "history", "startThread"], (t) => + Effect.gen(function*() { + const event = yield* t.userPosts() + const id = event.message.id + const read = Effect.gen(function*() { + const fetched = yield* t.call(t.chat.fetchMessage(t.thread, id)) + const history = yield* t.collect(Stream.take(t.chat.history(t.thread, { direction: "backward" }), 20)) + return [fetched, findIn(history, id)] as const + }) + const before = yield* read + const thread = yield* t.call(t.chat.startThread(t.thread, id, { name: conformanceText(t.rule) })) + yield* t.post({ markdown: conformanceText(t.rule) + " reply" }, thread) + const after = yield* read + const reads = [event.message, ...before, ...after] + yield* t.check( + reads.every((message) => message !== undefined && ChatThread.equals(message.thread, t.thread)), + "every read addressed to " + ChatThread.toString(t.thread), + () => reads.map((message) => message === undefined ? "missing" : ChatThread.toString(message.thread)).join(", ") + ) + })) + + rule("inbound/fetchable", ["fetchMessage"], (t) => + Effect.gen(function*() { + const event = yield* t.userPosts() + const message = yield* t.call(t.chat.fetchMessage(event.thread, event.message.id)) + yield* t.check(sameMessage(event.message, message), "the inbound message", () => "a different message") + })) + + rule("inbound/notSelf", [], (t) => + Effect.gen(function*() { + const event = yield* t.userPosts() + yield* t.check(!event.message.author.isSelf, "author.isSelf false", () => "author.isSelf true") + yield* checkEvent(event, { platform, parseMention }).pipe( + Effect.mapError((error) => failure(t.rule, error.expected, error.actual, error.cause)) + ) + })) + + rule("download/maxBytes", ["files", "download", "fetchMessage"], (t) => + Effect.gen(function*() { + const file = conformanceFile(t.rule) + const posted = yield* t.post({ files: [file] }) + const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check(message.attachments.length === 1, "one attachment", () => message.attachments.length + "") + yield* t.expectReason( + "TooLarge", + Stream.runDrain(t.chat.download(t.thread, message.attachments[0], { maxBytes: 8 })) + ) + })) + + rule("startThread/idempotent", ["startThread"], (t) => + Effect.gen(function*() { + const posted = yield* t.post({}) + const first = yield* t.call(t.chat.startThread(t.thread, posted.id, { name: conformanceText(t.rule) })) + const second = yield* t.call(t.chat.startThread(t.thread, posted.id)) + yield* t.check( + ChatThread.equals(first, second), + ChatThread.toString(first), + () => ChatThread.toString(second) + ) + })) + + rule("opener/noneOutsideThread", ["opener"], (t) => + Effect.flatMap( + t.call(t.chat.opener(t.thread)), + (opener) => t.check(Option.isNone(opener), "no opener", () => "an opener") + )) + + for (const capability of [...allCapabilities, "nativeStream" as const]) { + rule("unsupported/" + capability, [], (t) => t.has(capability) ? Effect.void : t.expectUnsupported(capability)) + } + + const failNext = options.failNext + if (failNext !== undefined) { + rule("retries/noneWithoutRetries", [], (t) => + Effect.gen(function*() { + yield* failNext("post", new RateLimited({})) + yield* t.expectReason( + "RateLimited", + Chat.withoutRetries(t.chat.post(t.thread, { markdown: conformanceText(t.rule) })), + (posted) => t.created.push({ thread: t.thread, id: posted.id }) + ) + })) + + rule("retries/retrySafe", [], (t) => + Effect.gen(function*() { + const retryAfter = Duration.millis(100) + yield* failNext("post", new RateLimited({ retryAfter })) + const start = yield* DateTime.now + yield* t.post({}) + const elapsed = DateTime.distance(start, yield* DateTime.now) + yield* t.check( + Duration.isGreaterThanOrEqualTo(elapsed, retryAfter), + "a retry after " + Duration.format(retryAfter), + () => "a retry after " + Duration.format(elapsed) + ) + })) + + rule("retries/neverUncertain", [], (t) => + Effect.gen(function*() { + yield* failNext("post", new Transport({ retry: "uncertain" }), { landed: true }) + yield* t.expectReason( + "Transport", + t.chat.post(t.thread, { markdown: conformanceText(t.rule) }), + (posted) => t.created.push({ thread: t.thread, id: posted.id }) + ) + })) + } + + return rules +} diff --git a/packages/effect/src/chat/ChatThread.ts b/packages/effect/src/chat/ChatThread.ts new file mode 100644 index 00000000000..92082ef56b8 --- /dev/null +++ b/packages/effect/src/chat/ChatThread.ts @@ -0,0 +1,132 @@ +/** + * Addresses for chat threads. + * + * A `ChatThread` names a channel, a thread or a direct conversation on one + * platform. The address itself does not say which of the three it is: + * `ChatEvent.MessageCreated.kind` and `Chat.getThread` do. The `id` is opaque + * to the core and owned by the platform's adapter. + * + * @stability unstable + * @since 4.1.5 + */ +import * as Effect from "../Effect.ts" +import * as Option from "../Option.ts" +import * as Schema from "../Schema.ts" +import * as SchemaIssue from "../SchemaIssue.ts" +import * as SchemaTransformation from "../SchemaTransformation.ts" + +/** + * Schema for the address messages go to: a channel, a thread or a direct + * conversation on one platform. + * + * **Details** + * + * `id` is opaque to the core and owned by the adapter. Slack's is + * `{team}/{channel}` or `{team}/{channel}/{thread_ts}`, Discord's is the + * channel snowflake. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const ChatThread = Schema.Struct({ + platform: Schema.String, + id: Schema.String +}).annotate({ identifier: "ChatThread" }) + +/** + * The address messages go to: a channel, a thread or a direct conversation on + * one platform. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type ChatThread = typeof ChatThread.Type + +/** + * Creates a thread address from a platform name and the adapter's id. + * + * @stability unstable + * @category constructors + * @since 4.1.5 + */ +export const make = (platform: string, id: string): ChatThread => ({ platform, id }) + +/** + * Returns whether two thread addresses name the same platform and id. + * + * @stability unstable + * @category comparisons + * @since 4.1.5 + */ +export const equals = (self: ChatThread, that: ChatThread): boolean => + self.platform === that.platform && self.id === that.id + +/** + * Formats a thread address as `{platform}:{id}`. + * + * **When to use** + * + * Use to build session keys, entity ids and URLs from an address. + * + * **Gotchas** + * + * The format is frozen once released, because consumers persist it. + * + * @see {@link fromString} for the inverse + * + * @stability unstable + * @category converting + * @since 4.1.5 + */ +export const toString = (thread: ChatThread): string => `${thread.platform}:${thread.id}` + +/** + * Parses a `{platform}:{id}` string into a thread address. + * + * **Details** + * + * The platform is everything before the first `:`, so an id may contain + * `:`. Both parts must be non-empty, otherwise the result is `None`. + * + * @see {@link toString} for the inverse + * + * @stability unstable + * @category converting + * @since 4.1.5 + */ +export const fromString = (value: string): Option.Option => { + const index = value.indexOf(":") + if (index <= 0 || index === value.length - 1) { + return Option.none() + } + return Option.some(make(value.slice(0, index), value.slice(index + 1))) +} + +/** + * Schema that decodes a `{platform}:{id}` string into a `ChatThread` and + * encodes it back. + * + * **Gotchas** + * + * The string format is frozen once released, because consumers persist it. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const FromString: Schema.Codec = Schema.String.pipe( + Schema.decodeTo( + ChatThread, + SchemaTransformation.transformEffect({ + decode: (value, options) => + Option.match(fromString(value), { + onNone: () => + Effect.fail(new SchemaIssue.InvalidValue({ expected: "a {platform}:{id} string" }, value, options)), + onSome: Effect.succeed + }), + encode: (thread) => Effect.succeed(toString(thread)) + }) + ) +) diff --git a/packages/effect/src/chat/index.ts b/packages/effect/src/chat/index.ts new file mode 100644 index 00000000000..631ebf4c269 --- /dev/null +++ b/packages/effect/src/chat/index.ts @@ -0,0 +1,54 @@ +/** + * @stability unstable + * @since 4.1.5 + */ + +// @barrel: Auto-generated exports. Do not edit manually. + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as Chat from "./Chat.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatAdapter from "./ChatAdapter.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatError from "./ChatError.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatEvent from "./ChatEvent.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatHandler from "./ChatHandler.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatMessage from "./ChatMessage.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatTest from "./ChatTest.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatThread from "./ChatThread.ts" diff --git a/packages/effect/src/chat/internal/retries.ts b/packages/effect/src/chat/internal/retries.ts new file mode 100644 index 00000000000..2782f492e79 --- /dev/null +++ b/packages/effect/src/chat/internal/retries.ts @@ -0,0 +1,7 @@ +import * as Context from "../../Context.ts" +import { constFalse } from "../../Function.ts" + +/** @internal */ +export const RetriesDisabled = Context.Reference("effect/chat/Chat/RetriesDisabled", { + defaultValue: constFalse +}) diff --git a/packages/effect/test/chat/Chat.test.ts b/packages/effect/test/chat/Chat.test.ts new file mode 100644 index 00000000000..96db73dda65 --- /dev/null +++ b/packages/effect/test/chat/Chat.test.ts @@ -0,0 +1,54 @@ +import { assert, describe, it } from "@effect/vitest" +import { Effect, Layer, Tracer } from "effect" +import { Chat, ChatTest, ChatThread } from "effect/chat" + +const recordSpans = () => { + const spans: Array = [] + const tracer = Tracer.make({ + span: (options) => { + const span = new Tracer.NativeSpan(options) + spans.push(span) + return span + } + }) + return { spans, tracer } +} + +describe("Chat", () => { + it.effect("routes each address to its platform's adapter", () => + Effect.gen(function*() { + const chat = yield* Chat.Chat + const test = yield* ChatTest.ChatTest + const b = yield* test.makeThread() + yield* chat.post(b, { markdown: "to b" }) + assert.strictEqual((yield* chat.descriptor("a")).platform, "a") + const missing = yield* Effect.flip(chat.post(ChatThread.make("c", "x"), { markdown: "nowhere" })) + assert.strictEqual(missing.reason._tag, "NoAdapter") + assert.strictEqual(missing.op, "post") + assert.deepStrictEqual((yield* test.messages(b)).map((message) => message.text), ["to b"]) + }).pipe(Effect.provide(Layer.mergeAll(ChatTest.layer({ platform: "a" }), ChatTest.layer({ platform: "b" }))))) + + it.effect("sets only platform, op, error reason and retry value on its spans", () => + Effect.gen(function*() { + const { spans, tracer } = recordSpans() + const chat = yield* Chat.Chat + const test = yield* ChatTest.ChatTest + const thread = yield* test.makeThread() + yield* Effect.gen(function*() { + const posted = yield* chat.post(thread, { markdown: "hello" }) + yield* Effect.exit(chat.fetchMessage(thread, posted.id + "0")) + }).pipe(Effect.withTracer(tracer)) + assert.deepStrictEqual( + spans.map((span) => [span.name, Object.fromEntries(span.attributes)]), + [ + ["Chat.post", { "chat.platform": "test", "chat.op": "post" }], + ["Chat.fetchMessage", { + "chat.platform": "test", + "chat.op": "fetchMessage", + "chat.error.reason": "NotFound", + "chat.error.retry": "denied" + }] + ] + ) + }).pipe(Effect.provide(ChatTest.layer()))) +}) diff --git a/packages/effect/test/chat/ChatError.test.ts b/packages/effect/test/chat/ChatError.test.ts new file mode 100644 index 00000000000..b6015cea34b --- /dev/null +++ b/packages/effect/test/chat/ChatError.test.ts @@ -0,0 +1,73 @@ +import { assert, describe, it } from "@effect/vitest" +import { Duration, Effect, Schema } from "effect" +import { ChatError } from "effect/chat" + +const cause = new Error("https://example.com/files/secret.txt") + +const reasons: ReadonlyArray = [ + new ChatError.RateLimited({ retryAfter: Duration.seconds(3), detail: "ratelimited", cause }), + new ChatError.Unsupported({ capability: "edit", detail: "no_edit", cause }), + new ChatError.Transport({ retry: "uncertain", detail: "timeout", cause }), + new ChatError.PlatformUnavailable({ retry: "retry", detail: "503", cause }), + new ChatError.NoAdapter({ detail: "none", cause }), + new ChatError.Unauthenticated({ detail: "invalid_auth", cause }), + new ChatError.Forbidden({ detail: "not_in_channel", cause }), + new ChatError.NotFound({ detail: "channel_not_found", cause }), + new ChatError.TooLarge({ detail: "msg_too_long", cause }), + new ChatError.InvalidRequest({ detail: "invalid_blocks", cause }), + new ChatError.InvalidResponse({ detail: "bad_json", cause }), + new ChatError.Unknown({ detail: "unknown", cause }) +] + +describe("ChatError", () => { + it("fixes the retry value per reason", () => { + assert.deepStrictEqual( + reasons.map((reason) => reason.retry), + [ + "retry", + "denied", + "uncertain", + "retry", + "denied", + "denied", + "denied", + "denied", + "denied", + "denied", + "denied", + "uncertain" + ] + ) + }) + + it.effect("round-trips every reason through its Schema, cause included", () => + Effect.gen(function*() { + const codec = Schema.toCodecJson(ChatError.ChatError) + for (const reason of reasons) { + const error = new ChatError.ChatError({ platform: "slack", op: "post", reason }) + const decoded = yield* Schema.decodeEffect(codec)(yield* Schema.encodeEffect(codec)(error)) + assert.strictEqual(decoded.reason._tag, reason._tag) + assert.strictEqual(decoded.reason.detail, reason.detail) + assert.strictEqual(decoded.retry, error.retry) + assert.instanceOf(decoded.reason.cause, Error) + assert.strictEqual((decoded.reason.cause as Error).message, cause.message) + } + })) + + it("leaves cause out of toJSON and message", () => { + for (const reason of reasons) { + const error = new ChatError.ChatError({ platform: "slack", op: "post", reason }) + assert.notInclude(JSON.stringify(error), "secret") + assert.notInclude(JSON.stringify(reason), "secret") + assert.notInclude(error.message, "secret") + assert.strictEqual(error.cause, reason) + } + }) + + it("delegates retryAfter to the reason", () => { + const error = new ChatError.ChatError({ platform: "slack", op: "post", reason: reasons[0] }) + assert.deepStrictEqual(error.retryAfter, Duration.seconds(3)) + assert.isTrue(ChatError.isChatError(error)) + assert.isFalse(ChatError.isChatError(reasons[0])) + }) +}) diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts new file mode 100644 index 00000000000..ddcde12d15c --- /dev/null +++ b/packages/effect/test/chat/ChatTest.test.ts @@ -0,0 +1,117 @@ +import { assert, describe, it } from "@effect/vitest" +import { Effect, Exit, Option } from "effect" +import { ChatAdapter, ChatError, ChatHandler, ChatTest, ChatThread } from "effect/chat" + +const kinds = { "@": "user", "@&": "role", "#": "channel", "!": "broadcast" } as const + +const parseMention: ChatTest.ParseMention = (slice) => { + const match = /^<(@&|@|#|!)([^<>\s]+)>$/.exec(slice) + return match === null ? Option.none() : Option.some({ kind: kinds[match[1] as keyof typeof kinds], id: match[2] }) +} + +const suite = Effect.gen(function*() { + const test = yield* ChatTest.ChatTest + const thread = yield* test.makeThread() + return ChatTest.conformance({ + platform: test.platform, + thread, + userPosts: (thread, text) => test.userPosts(thread, { text }), + parseMention, + failNext: test.failNext + }) +}) + +const ruleNames = Object.keys(ChatTest.conformance({ + platform: "test", + thread: ChatThread.make("test", "c0"), + userPosts: () => Effect.die("unused"), + parseMention, + failNext: () => Effect.void +})) + +const capabilities = ChatError.Capability.literals.filter((capability) => capability !== "nativeStream") + +const runRule = (rule: string, options?: Parameters[0]) => + Effect.flatMap(suite, (rules) => rules[rule]).pipe(Effect.provide(ChatTest.layer(options))) + +describe("ChatTest", () => { + describe("conformance with every capability", () => { + for (const rule of ruleNames) { + it.live(rule, () => runRule(rule)) + } + }) + + for (const off of capabilities) { + describe(`conformance without ${off}`, () => { + for (const rule of ruleNames) { + it.live(rule, () => runRule(rule, { capabilities: capabilities.filter((c) => c !== off) })) + } + }) + } + + it.effect("fails unsupported/{capability} for a descriptor that leaves out a working op", () => + Effect.gen(function*() { + const registry = yield* ChatAdapter.Registry + const adapter = yield* registry.get("test") + const listed = new Set(adapter.descriptor.capabilities) + listed.delete("edit") + yield* registry.register({ ...adapter, descriptor: { ...adapter.descriptor, capabilities: listed } }) + const failure = yield* Effect.flip(Effect.flatMap(suite, (rules) => rules["unsupported/edit"])) + assert.strictEqual(failure.rule, "unsupported/edit") + assert.strictEqual(failure.actual, "success") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("fails a rule whose listed capability fails with Unsupported", () => + Effect.gen(function*() { + const registry = yield* ChatAdapter.Registry + const adapter = yield* registry.get("test") + yield* registry.register({ + ...adapter, + edit: () => + Effect.fail( + new ChatError.ChatError({ + platform: "test", + op: "edit", + reason: new ChatError.Unsupported({ capability: "edit" }) + }) + ) + }) + const failure = yield* Effect.flip(Effect.flatMap(suite, (rules) => rules["edit/keepsId"])) + assert.strictEqual(failure.actual, "Unsupported(edit) for a listed capability") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("checkMessage rejects a mention whose slice is not its token", () => + Effect.gen(function*() { + const test = yield* ChatTest.ChatTest + const thread = yield* test.makeThread() + const event = yield* test.userPosts(thread, { text: "hi", mentionsSelf: true }) + yield* ChatTest.checkEvent(event, { platform: "test", parseMention }) + assert.strictEqual(event._tag, "MessageCreated") + if (event._tag !== "MessageCreated") return + const shifted = { + ...event.message, + mentions: event.message.mentions.map((mention) => ({ ...mention, start: mention.start + 1 })) + } + const exit = yield* Effect.exit(ChatTest.checkMessage(shifted, { platform: "test", parseMention })) + assert.isTrue(Exit.isFailure(exit)) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("ChatHandler.layer drops the bot's own messages unless deliverSelf", () => + Effect.gen(function*() { + const test = yield* ChatTest.ChatTest + const thread = yield* test.makeThread() + const own = yield* test.userPosts(thread, { text: "own" }) + const self = own._tag === "MessageCreated" + ? { ...own, message: { ...own.message, author: { ...own.message.author, isSelf: true } } } + : own + const received: Array = [] + const handler = ChatHandler.layer((event) => Effect.sync(() => void received.push(event._tag))) + yield* test.deliver(self).pipe(Effect.provide(handler)) + yield* test.deliver(own).pipe(Effect.provide(handler)) + yield* test.deliver(self).pipe(Effect.provide(ChatHandler.layer( + (event) => Effect.sync(() => void received.push("self " + event._tag)), + { deliverSelf: true } + ))) + assert.deepStrictEqual(received, ["MessageCreated", "self MessageCreated"]) + }).pipe(Effect.provide(ChatTest.layer()))) +}) From 69626fd266eecbc409b7d05ccb745cecf25e8225 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 09:56:21 +0000 Subject: [PATCH 02/89] Check listed capabilities in unsupported rules and stop neverUncertain leaking a post --- packages/effect/src/chat/ChatTest.ts | 121 +++++++++++---------- packages/effect/test/chat/ChatTest.test.ts | 43 +++++++- 2 files changed, 105 insertions(+), 59 deletions(-) diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts index 8fcd3c3fc6d..38abd2a395c 100644 --- a/packages/effect/src/chat/ChatTest.ts +++ b/packages/effect/src/chat/ChatTest.ts @@ -1,16 +1,16 @@ /** * Testing tools for chat adapters and their consumers. * - * \`layer\` builds a whole chat in memory: \`Chat\`, its registry and one fake - * adapter with configurable capabilities and fault injection. \`conformance\` + * `layer` builds a whole chat in memory: `Chat`, its registry and one fake + * adapter with configurable capabilities and fault injection. `conformance` * is the suite of rules every adapter obeys, as plain Effects keyed by rule - * name. \`checkMessage\` and \`checkEvent\` assert the invariants every message + * name. `checkMessage` and `checkEvent` assert the invariants every message * and event holds, for fixture tests and live runs. * * **Details** * - * The fake adapter's mention syntax is \`<@id>\` for a user, \`<@&id>\` for a - * role, \`<#id>\` for a channel and \`\` for a broadcast. + * The fake adapter's mention syntax is `<@id>` for a user, `<@&id>` for a + * role, `<#id>` for a channel and `` for a broadcast. * * @stability unstable * @since 4.1.5 @@ -48,13 +48,13 @@ import * as ChatMessage from "./ChatMessage.ts" import * as ChatThread from "./ChatThread.ts" /** - * Reads a slice of \`ChatMessage.text\` as one of the platform's mention + * Reads a slice of `ChatMessage.text` as one of the platform's mention * tokens. * * **Details** * * The core does not know any platform's syntax, so the caller supplies it. A - * slice that is not a mention token returns \`None\`. + * slice that is not a mention token returns `None`. * * **Gotchas** * @@ -87,19 +87,19 @@ export interface Call { } /** - * Service that controls the fake adapter built by \`layer\`. + * Service that controls the fake adapter built by `layer`. * * **Details** * - * - \`makeThread\` creates a fresh address: a channel by default, a direct + * - `makeThread` creates a fresh address: a channel by default, a direct * conversation, or a thread under a user's message in a fresh channel. - * - \`userPosts\` puts another identity's message in a thread and returns its - * event without delivering it. \`deliver\` delivers an event the way an - * adapter does, by calling the \`ChatHandler\` service. - * - \`messages\` is what a thread shows now, oldest first, and \`calls\` is every + * - `userPosts` puts another identity's message in a thread and returns its + * event without delivering it. `deliver` delivers an event the way an + * adapter does, by calling the `ChatHandler` service. + * - `messages` is what a thread shows now, oldest first, and `calls` is every * call the adapter received. - * - \`failNext\` makes the next \`times\` calls of \`op\` fail with \`reason\`. - * \`landed\` makes the write happen anyway, which is what \`uncertain\` means. + * - `failNext` makes the next `times` calls of `op` fail with `reason`. + * `landed` makes the write happen anyway, which is what `uncertain` means. * * @stability unstable * @category services @@ -574,22 +574,22 @@ const makeFake = (options: { } /** - * Creates a whole chat in memory: \`Chat\`, its registry and one fake adapter. + * Creates a whole chat in memory: `Chat`, its registry and one fake adapter. * * **When to use** * - * Use to test code that posts and reads through \`Chat\`, and to run the + * Use to test code that posts and reads through `Chat`, and to run the * conformance suite against the fake adapter. * * **Details** * - * - The platform defaults to \`test\` and the bot's user id to \`bot\`. - * - Every capability is on by default, except \`nativeStream\`: the fake has no + * - The platform defaults to `test` and the bot's user id to `bot`. + * - Every capability is on by default, except `nativeStream`: the fake has no * native stream yet. * - The default limits are 4000 characters per message, 10 files of up to * 10 MiB, and no write interval. - * - Two layers merged with different platforms share one \`Chat\`, so routing - * can be tested. The \`ChatTest\` service in context is the last one merged. + * - Two layers merged with different platforms share one `Chat`, so routing + * can be tested. The `ChatTest` service in context is the last one merged. * * @stability unstable * @category layers @@ -625,8 +625,8 @@ export const layer = (options?: { * * **Details** * - * \`rule\` names what failed, and \`expected\` and \`actual\` say how. A platform - * error behind the failure is in \`cause\`. + * `rule` names what failed, and `expected` and `actual` say how. A platform + * error behind the failure is in `cause`. * * @stability unstable * @category errors @@ -663,9 +663,9 @@ const sameReplyTo = (a: ReplyTo | undefined, b: ReplyTo | undefined): boolean => * * **Details** * - * It compares \`id\`, \`thread\`, \`author.id\`, \`author.isBot\`, \`author.isSelf\`, - * \`text\`, \`mentions\`, \`replyTo\`, \`timestamp\` and the attachment ids in order. - * \`raw\`, \`author.name\` and the optional attachment fields are left out. + * It compares `id`, `thread`, `author.id`, `author.isBot`, `author.isSelf`, + * `text`, `mentions`, `replyTo`, `timestamp` and the attachment ids in order. + * `raw`, `author.name` and the optional attachment fields are left out. * * @stability unstable * @category comparisons @@ -769,11 +769,11 @@ const checkMessageWith = Effect.fnUntraced(function*(rule: string, message: Chat * * **Details** * - * - Every mention sits inside \`text\`, mentions do not overlap, and each slice - * parses with \`parseMention\` as a token of the mention's kind and id. - * - \`thread.platform\` is the platform, and the thread survives its string + * - Every mention sits inside `text`, mentions do not overlap, and each slice + * parses with `parseMention` as a token of the mention's kind and id. + * - `thread.platform` is the platform, and the thread survives its string * codec. - * - The message encodes and decodes through its Schema unchanged, \`raw\` + * - The message encodes and decodes through its Schema unchanged, `raw` * included. * - Every attachment has an id and no URL. * @@ -791,13 +791,13 @@ export const checkMessage = (message: ChatMessage.ChatMessage, options: { * * **Details** * - * - A message event's message passes \`checkMessage\`, and the event's thread is + * - A message event's message passes `checkMessage`, and the event's thread is * the message's. - * - \`thread.platform\` is the platform, and the thread survives its string + * - `thread.platform` is the platform, and the thread survives its string * codec. - * - The event encodes and decodes through its Schema unchanged, \`raw\` - * included, and two decodes have the same \`dedupeKey\`. - * - A reaction's \`dedupeKey\` differs between added and removed. + * - The event encodes and decodes through its Schema unchanged, `raw` + * included, and two decodes have the same `dedupeKey`. + * - A reaction's `dedupeKey` differs between added and removed. * * @stability unstable * @category testing @@ -940,15 +940,25 @@ class Tester { }) } - expectUnsupported(capability: Capability): Effect.Effect { - const expected = "Unsupported(" + capability + ")" + /** + * Calls the op behind `capability`. When the descriptor lacks it, the op + * must fail with `Unsupported` naming it. When it is listed, the op must + * not fail with `Unsupported` for a listed capability, so a descriptor that + * lies in either direction fails. + */ + probe(capability: Capability): Effect.Effect { + const listed = this.has(capability) + const expected = listed ? "no Unsupported for listed " + capability : "Unsupported(" + capability + ")" const expect = (effect: Effect.Effect, onSuccess?: (a: A) => void) => Effect.flatMap(Effect.exit(effect), (exit) => { if (Exit.isSuccess(exit)) onSuccess?.(exit.value) const error = Exit.findErrorOption(exit) - const matches = Option.isSome(error) && isChatError(error.value) && - error.value.reason._tag === "Unsupported" && error.value.reason.capability === capability - return matches ? Effect.void : Effect.fail(failure( + const reason = Option.isSome(error) && isChatError(error.value) ? error.value.reason : undefined + const holds = listed + ? Exit.isSuccess(exit) || + (reason !== undefined && !(reason._tag === "Unsupported" && this.has(reason.capability))) + : reason?._tag === "Unsupported" && reason.capability === capability + return holds ? Effect.void : Effect.fail(failure( this.rule, expected, describeExit(exit), @@ -993,9 +1003,9 @@ class Tester { (registry) => Effect.flatMap(this.call(registry.get(this.options.platform)), (adapter) => this.check( - adapter.nativeStream === undefined, - "no nativeStream on an adapter whose descriptor lacks it", - () => "a nativeStream" + (adapter.nativeStream !== undefined) === listed, + listed ? "a nativeStream, as the descriptor lists it" : "no nativeStream, as the descriptor lacks it", + () => adapter.nativeStream === undefined ? "no nativeStream" : "a nativeStream" )) ) } @@ -1042,24 +1052,25 @@ interface ConformanceOptions { * * **Details** * - * - Each rule needs the adapter under test registered in \`Chat\` and a way to - * make another identity's message appear in \`thread\`, which must be a + * - Each rule needs the adapter under test registered in `Chat` and a way to + * make another identity's message appear in `thread`, which must be a * channel the suite may write to. * - A rule is never skipped. When the descriptor lacks a capability a rule - * needs, the rule becomes its inverse: the op fails with \`Unsupported\`. - * There is an \`unsupported/{capability}\` rule for every capability, which - * passes when the capability is listed. - * - A listed capability never fails with \`Unsupported\`, which every rule + * needs, the rule becomes its inverse: the op fails with `Unsupported`. + * There is an `unsupported/{capability}` rule for every capability. When + * the capability is listed, it calls the op and fails if the op fails with + * `Unsupported`, so a descriptor that lies in either direction fails. + * - A listed capability never fails with `Unsupported`, which every rule * checks as it goes. - * - The three \`retries/*\` rules exist only when \`failNext\` is given. + * - The three `retries/*` rules exist only when `failNext` is given. * - Every rule deletes what it posted when it ends, pass or fail, when the * platform can delete. * * **Gotchas** * * The rules are provisional: they can be added, renamed, removed or tightened - * in any release until the suite is frozen. The \`retries/retrySafe\` rule - * waits for real time, so run the suite on a live \`Clock\`. + * in any release until the suite is frozen. The `retries/retrySafe` rule + * waits for real time, so run the suite on a live `Clock`. * * @stability unstable * @category testing @@ -1093,7 +1104,7 @@ export const conformance = (options: { ) const t = new Tester(name, chat, descriptor, options) const missing = needs.find((capability) => !t.has(capability)) - return yield* (missing === undefined ? body(t) : t.expectUnsupported(missing)).pipe( + return yield* (missing === undefined ? body(t) : t.probe(missing)).pipe( Effect.ensuring(t.cleanup) ) }) @@ -1337,7 +1348,7 @@ export const conformance = (options: { )) for (const capability of [...allCapabilities, "nativeStream" as const]) { - rule("unsupported/" + capability, [], (t) => t.has(capability) ? Effect.void : t.expectUnsupported(capability)) + rule("unsupported/" + capability, [], (t) => t.probe(capability)) } const failNext = options.failNext @@ -1368,7 +1379,7 @@ export const conformance = (options: { rule("retries/neverUncertain", [], (t) => Effect.gen(function*() { - yield* failNext("post", new Transport({ retry: "uncertain" }), { landed: true }) + yield* failNext("post", new Transport({ retry: "uncertain" })) yield* t.expectReason( "Transport", t.chat.post(t.thread, { markdown: conformanceText(t.rule) }), diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts index ddcde12d15c..f4a6605ee22 100644 --- a/packages/effect/test/chat/ChatTest.test.ts +++ b/packages/effect/test/chat/ChatTest.test.ts @@ -9,16 +9,18 @@ const parseMention: ChatTest.ParseMention = (slice) => { return match === null ? Option.none() : Option.some({ kind: kinds[match[1] as keyof typeof kinds], id: match[2] }) } -const suite = Effect.gen(function*() { - const test = yield* ChatTest.ChatTest - const thread = yield* test.makeThread() - return ChatTest.conformance({ +const rulesFor = (test: ChatTest.ChatTest["Service"], thread: ChatThread.ChatThread) => + ChatTest.conformance({ platform: test.platform, thread, userPosts: (thread, text) => test.userPosts(thread, { text }), parseMention, failNext: test.failNext }) + +const suite = Effect.gen(function*() { + const test = yield* ChatTest.ChatTest + return rulesFor(test, yield* test.makeThread()) }) const ruleNames = Object.keys(ChatTest.conformance({ @@ -80,6 +82,39 @@ describe("ChatTest", () => { assert.strictEqual(failure.actual, "Unsupported(edit) for a listed capability") }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("fails unsupported/{capability} for a listed op that fails with Unsupported", () => + Effect.gen(function*() { + const registry = yield* ChatAdapter.Registry + const adapter = yield* registry.get("test") + const unsupported = (capability: ChatError.Capability) => + Effect.fail( + new ChatError.ChatError({ + platform: "test", + op: capability, + reason: new ChatError.Unsupported({ capability }) + }) + ) + yield* registry.register({ + ...adapter, + getThread: () => unsupported("getThread"), + getUser: () => unsupported("getUser") + }) + const rules = yield* suite + for (const capability of ["getThread", "getUser"] as const) { + const failure = yield* Effect.flip(rules[`unsupported/${capability}`]) + assert.strictEqual(failure.actual, `Unsupported(${capability})`) + } + }).pipe(Effect.provide(ChatTest.layer()))) + + it.live("deletes every bot message the suite posts", () => + Effect.gen(function*() { + const test = yield* ChatTest.ChatTest + const thread = yield* test.makeThread() + yield* Effect.forEach(Object.values(rulesFor(test, thread)), (rule) => rule, { discard: true }) + const left = (yield* test.messages(thread)).filter((message) => message.author.isSelf) + assert.deepStrictEqual(left.map((message) => message.text), []) + }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("checkMessage rejects a mention whose slice is not its token", () => Effect.gen(function*() { const test = yield* ChatTest.ChatTest From fce9e4c7ab884cb3125e56a7e20e7262f6c368d1 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 10:03:17 +0000 Subject: [PATCH 03/89] Reject any Unsupported from a listed capability's probe --- packages/effect/src/chat/ChatTest.ts | 7 +++---- packages/effect/test/chat/ChatTest.test.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts index 38abd2a395c..7d691a5f8a8 100644 --- a/packages/effect/src/chat/ChatTest.ts +++ b/packages/effect/src/chat/ChatTest.ts @@ -943,8 +943,8 @@ class Tester { /** * Calls the op behind `capability`. When the descriptor lacks it, the op * must fail with `Unsupported` naming it. When it is listed, the op must - * not fail with `Unsupported` for a listed capability, so a descriptor that - * lies in either direction fails. + * not fail with `Unsupported` at all, whichever capability that names, so a + * descriptor that lies in either direction fails. */ probe(capability: Capability): Effect.Effect { const listed = this.has(capability) @@ -955,8 +955,7 @@ class Tester { const error = Exit.findErrorOption(exit) const reason = Option.isSome(error) && isChatError(error.value) ? error.value.reason : undefined const holds = listed - ? Exit.isSuccess(exit) || - (reason !== undefined && !(reason._tag === "Unsupported" && this.has(reason.capability))) + ? Exit.isSuccess(exit) || (reason !== undefined && reason._tag !== "Unsupported") : reason?._tag === "Unsupported" && reason.capability === capability return holds ? Effect.void : Effect.fail(failure( this.rule, diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts index f4a6605ee22..ad734503028 100644 --- a/packages/effect/test/chat/ChatTest.test.ts +++ b/packages/effect/test/chat/ChatTest.test.ts @@ -94,16 +94,20 @@ describe("ChatTest", () => { reason: new ChatError.Unsupported({ capability }) }) ) + const listed = new Set(adapter.descriptor.capabilities) + listed.delete("opener") yield* registry.register({ ...adapter, + descriptor: { ...adapter.descriptor, capabilities: listed }, getThread: () => unsupported("getThread"), - getUser: () => unsupported("getUser") + // names a capability the descriptor does leave out, but not the one probed + getUser: () => unsupported("opener") }) const rules = yield* suite - for (const capability of ["getThread", "getUser"] as const) { - const failure = yield* Effect.flip(rules[`unsupported/${capability}`]) - assert.strictEqual(failure.actual, `Unsupported(${capability})`) - } + const getThread = yield* Effect.flip(rules["unsupported/getThread"]) + assert.strictEqual(getThread.actual, "Unsupported(getThread)") + const getUser = yield* Effect.flip(rules["unsupported/getUser"]) + assert.strictEqual(getUser.actual, "Unsupported(opener)") }).pipe(Effect.provide(ChatTest.layer()))) it.live("deletes every bot message the suite posts", () => From 6b021355b8860903b60d6e46a89ba06c2feb93d2 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 17:20:05 +0000 Subject: [PATCH 04/89] Add ChatMarkdown for long and streamed Markdown Adds effect/chat/ChatMarkdown (post and stream over post-then-edit and NativeStream), the Descriptor measure contract from EFF-3689, and a native stream in the ChatTest fake with its conformance rules. --- .changeset/effect-chat.md | 2 +- packages/effect/src/chat/ChatAdapter.ts | 28 +- packages/effect/src/chat/ChatMarkdown.ts | 1063 +++++++++++++++++ packages/effect/src/chat/ChatTest.ts | 272 ++++- packages/effect/src/chat/index.ts | 6 + .../effect/test/chat/ChatMarkdown.test.ts | 483 ++++++++ packages/effect/test/chat/ChatTest.test.ts | 19 +- 7 files changed, 1846 insertions(+), 27 deletions(-) create mode 100644 packages/effect/src/chat/ChatMarkdown.ts create mode 100644 packages/effect/test/chat/ChatMarkdown.test.ts diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md index 69d6627b867..97cd948fc36 100644 --- a/.changeset/effect-chat.md +++ b/.changeset/effect-chat.md @@ -2,4 +2,4 @@ "effect": patch --- -Add `effect/chat`, an unstable, platform-neutral model and router for chat bots, with `ChatTest`, an in-memory adapter and the conformance suite adapters are tested against. +Add `effect/chat`, an unstable, platform-neutral model and router for chat bots, with `ChatMarkdown` for posting long and streamed Markdown, and `ChatTest`, an in-memory adapter and the conformance suite adapters are tested against. diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts index 10b74b96637..587279f0335 100644 --- a/packages/effect/src/chat/ChatAdapter.ts +++ b/packages/effect/src/chat/ChatAdapter.ts @@ -11,7 +11,8 @@ * the op fails with `Unsupported`, naming the capability. * - A post notifies nobody unless asked: mentions in Markdown do not notify by * default. - * - Length is checked before the call, with `checkMessageLength`. + * - Length is checked before the call, with `checkMessageLength`, in the + * unit the descriptor's `measure` counts. * - Adapters retry `retry` failures with `retrySafe` and never retry * `uncertain` ones. * @@ -42,9 +43,14 @@ import { RetriesDisabled } from "./internal/retries.ts" * * - An op whose capability is missing from `capabilities` fails with * `Unsupported`. - * - `limits.messageLength` is the length of one message. What is counted, - * and in which unit, is still open; `checkMessageLength` holds the one - * place it is measured. + * - `limits.messageLength` is the platform's own limit for one message, in + * the platform's own unit. + * - `measure` gives what a Markdown string costs against + * `limits.messageLength` and `limits.streamLength`. It is pure and makes + * no call to the platform. It is an upper bound, never less than what the + * adapter sends for the text, and it adds up: + * `measure(a + b) <= measure(a) + measure(b)`. It measures ASCII letters + * at one each. * - `limits.minWriteInterval` is the default floor between two writes to one * thread, for streamed and multi-part posts. * - `limits.streamLength` and `limits.streamAge` apply to native streams @@ -58,6 +64,7 @@ import { RetriesDisabled } from "./internal/retries.ts" export interface Descriptor { readonly platform: string readonly capabilities: ReadonlySet + readonly measure: (markdown: string) => number readonly limits: { readonly messageLength: number readonly filesPerMessage: number @@ -288,18 +295,19 @@ export const layer = ( /** * Fails with `TooLarge` when Markdown does not fit the descriptor's - * `limits.messageLength`. + * `limits.messageLength`, measured with the descriptor's `measure`. * * **When to use** * * Use when implementing `post`, `edit` and `NativeStream.start` in an adapter, * so a message that is too long fails without a call to the platform. * - * **Gotchas** + * **Details** * - * It compares `markdown.length` with the limit. That measure is provisional: - * a platform that counts the escaped string it is sent can still refuse a - * message that passes. + * Pass the string the adapter is about to send, after escaping. For a + * `measure` that counts what escaping adds, measuring the escaped string + * gives the exact cost, so a post is neither refused when the platform would + * take it nor passed when the platform would refuse it on length. * * @stability unstable * @category validation @@ -310,7 +318,7 @@ export const checkMessageLength = ( op: string, markdown: string ): Effect.Effect => - markdown.length <= descriptor.limits.messageLength ? Effect.void : Effect.fail( + descriptor.measure(markdown) <= descriptor.limits.messageLength ? Effect.void : Effect.fail( new ChatError({ platform: descriptor.platform, op, reason: new TooLarge({ detail: "message_too_long" }) }) ) diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts new file mode 100644 index 00000000000..cb092c73f57 --- /dev/null +++ b/packages/effect/src/chat/ChatMarkdown.ts @@ -0,0 +1,1063 @@ +/** + * Posting long and streamed Markdown through `Chat`. + * + * `post` splits Markdown that outgrows one message into parts at block + * boundaries. `stream` writes a stream of Markdown deltas as it arrives, by + * the adapter's native stream when it has one and otherwise by posting and + * then editing. Both sit above the adapter ops and use one splitter. + * + * **Example** (Streaming a reply) + * + * ```ts + * import { Effect, Stream } from "effect" + * import { ChatMarkdown, ChatThread } from "effect/chat" + * + * const reply = (deltas: Stream.Stream) => + * Effect.gen(function*() { + * const result = yield* ChatMarkdown.stream(ChatThread.make("slack", "T1/C1"), deltas) + * return result.parts.map((part) => part.messageId) + * }) + * ``` + * + * @stability unstable + * @since 4.1.5 + */ +import * as Cause from "../Cause.ts" +import * as Clock from "../Clock.ts" +import * as Data from "../Data.ts" +import type * as DateTime from "../DateTime.ts" +import * as Duration from "../Duration.ts" +import * as Effect from "../Effect.ts" +import * as Exit from "../Exit.ts" +import * as Fiber from "../Fiber.ts" +import * as Latch from "../Latch.ts" +import * as Option from "../Option.ts" +import * as Stream from "../Stream.ts" +import * as Chat from "./Chat.ts" +import type { Descriptor, File, NativeStream, Posted } from "./ChatAdapter.ts" +import { Registry } from "./ChatAdapter.ts" +import type { ChatError } from "./ChatError.ts" +import type { ReplyTo } from "./ChatMessage.ts" +import type { ChatThread } from "./ChatThread.ts" + +/** + * One message a call created. + * + * **Details** + * + * - `markdown` is the Markdown as it went out, with a reopened or closed code + * fence and a consumer's unattached note included. It is empty for the + * overflow file. + * - `text` is the slice of the input the part carries, without anything the + * layer added. The `text` of every part, in order, is the input. + * - `transport` is `post` for a part from `post`, `edit` for a streamed + * part written by post-then-edit and `native` for one written by the + * adapter's native stream, even if it was finished by an edit. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface Part { + readonly messageId: string + readonly timestamp: DateTime.Utc + readonly markdown: string + readonly text: string + readonly kind: "text" | "overflowFile" + readonly transport: "post" | "edit" | "native" +} + +/** + * What a call posted. + * + * **Details** + * + * - `parts` is empty when the input was empty: nothing is posted. + * - `stopped` means a user clicked stop on this reply (Slack's stop button). + * It can be true with the whole text delivered, when the consumer ignored + * the click. It is always false from `post`. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface Result { + readonly parts: ReadonlyArray + readonly stopped: boolean +} + +/** + * Error for a call that did not deliver its whole input. + * + * **Details** + * + * - `posted` is text the platform confirmed, `uncertain` is text sent in a + * write that failed `uncertain` and was never confirmed since, and + * `remaining` was never sent. The `text` of `posted`, then `uncertain`, + * then `remaining` is the input, with nothing in two of them. + * - `cause` is a `ChatError` from a write, the upstream's error `E`, or + * `Overflow` when the input outgrew `maxParts` and the overflow file. + * + * **Gotchas** + * + * It is not a `Schema.TaggedError`: it is generic in `E` and carries + * message text. `message` and `toJSON` leave the text out. + * + * @stability unstable + * @category errors + * @since 4.1.5 + */ +export class ChatMarkdownError extends Data.TaggedError("ChatMarkdownError")<{ + readonly posted: ReadonlyArray + readonly remaining: string + readonly uncertain?: string | undefined + readonly cause: + | { readonly _tag: "Chat"; readonly error: ChatError } + | { readonly _tag: "Upstream"; readonly error: E } + | { readonly _tag: "Overflow" } +}> { + override get message(): string { + const cause = this.cause._tag === "Chat" ? "Chat(" + this.cause.error.reason._tag + ")" : this.cause._tag + return "ChatMarkdown failed after " + this.posted.length + " part(s): " + cause + } + + /** + * The error without its message text. + */ + override toJSON(): unknown { + return { + _tag: this._tag, + posted: this.posted.map((part) => ({ messageId: part.messageId, kind: part.kind, transport: part.transport })), + cause: this.cause._tag === "Chat" ? { _tag: "Chat", error: this.cause.error.toJSON() } : { _tag: this.cause._tag } + } + } +} + +/** + * The options `post` and `stream` share. + * + * **Details** + * + * - `replyTo` applies to the first part. + * - `maxParts` defaults to 5, a provisional number. Past it, `overflow` + * decides: `fail`, the default, or `{ file }`, which sends the rest as one + * trailing file message that does not count against `maxParts`. + * - `minWriteInterval` is the floor between two writes. It defaults to the + * adapter's `limits.minWriteInterval`. + * - `onPart` runs for every message the call creates, the overflow file + * included, uninterruptibly with its post, so an interrupt can't lose an id. + * It has to be quick. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface Options { + readonly replyTo?: ReplyTo | undefined + readonly maxParts?: number | undefined + readonly overflow?: "fail" | { readonly file: { readonly name: string } } | undefined + readonly minWriteInterval?: Duration.Duration | undefined + readonly onPart?: ((part: Part) => Effect.Effect) | undefined +} + +// ----------------------------------------------------------------------------- +// Markdown scanning +// ----------------------------------------------------------------------------- + +interface Fence { + readonly marker: string + readonly line: string +} + +interface Line { + /** The index after the line's newline. */ + readonly end: number + /** The fence open after the line. */ + readonly fence: Fence | undefined + /** A part can end after this line: it is outside a fence, and blank or closing a fence. */ + readonly boundary: boolean +} + +const fencePattern = /^ {0,3}(`{3,}|~{3,})(.*)$/ + +const fenceAfter = ( + fence: Fence | undefined, + line: string +): { readonly fence: Fence | undefined; readonly closed: boolean } => { + const match = fencePattern.exec(line) + if (match === null) return { fence, closed: false } + const marker = match[1] + if (fence === undefined) { + return marker[0] === "`" && match[2].includes("`") + ? { fence, closed: false } + : { fence: { marker, line: line.trimStart() }, closed: false } + } + return marker[0] === fence.marker[0] && marker.length >= fence.marker.length && match[2].trim() === "" + ? { fence: undefined, closed: true } + : { fence, closed: false } +} + +/** + * The lines of `text`, read from a state of `fence`. Only complete lines + * count, unless `complete` says the text is finished. + */ +const scanLines = (text: string, fence: Fence | undefined, complete: boolean): Array => { + const lines: Array = [] + let start = 0 + while (start < text.length) { + const newline = text.indexOf("\n", start) + if (newline === -1 && !complete) break + const end = newline === -1 ? text.length : newline + 1 + const line = text.slice(start, newline === -1 ? text.length : newline).replace(/\r$/, "") + const step = fenceAfter(fence, line) + fence = step.fence + lines.push({ end, fence, boundary: fence === undefined && (step.closed || line.trim() === "") }) + start = end + } + return lines +} + +const fenceAt = (lines: ReadonlyArray, initial: Fence | undefined, index: number): Fence | undefined => { + let fence = initial + for (const line of lines) { + if (line.end > index) break + fence = line.fence + } + return fence +} + +const closing = (fence: Fence | undefined, markdown: string): string => + fence === undefined ? "" : (markdown === "" || markdown.endsWith("\n") ? "" : "\n") + fence.marker + +const reopening = (fence: Fence | undefined): string => fence === undefined ? "" : fence.line + "\n" + +const isBlank = (text: string) => text.trim() === "" + +/** Markdown for `text` written as a whole message: an open fence is closed. */ +const render = (prefix: string, text: string, fence: Fence | undefined): string => { + const markdown = prefix + text + return markdown + closing(fenceAt(scanLines(text, fence, true), fence, text.length), markdown) +} + +/** + * Where to cut `text` so that `prefix`, the cut text and a closing fence + * measure at most `room`: after the last block boundary that fits, else after + * the last line, else after the last whitespace, else at the last character. + * Never inside a surrogate pair, and never at 0. + */ +const fitCut = ( + measure: (markdown: string) => number, + text: string, + fence: Fence | undefined, + prefix: string, + room: number +): number => { + const lines = scanLines(text, fence, false) + const size = (cut: number) => { + const markdown = prefix + text.slice(0, cut) + return measure(markdown + closing(fenceAt(lines, fence, cut), markdown)) + } + const fits = (cut: number) => size(cut) <= room + let low = 0 + let high = text.length + while (low < high) { + const middle = Math.ceil((low + high) / 2) + if (fits(middle)) low = middle + else high = middle - 1 + } + const most = low + const candidates: Array = [] + for (let i = lines.length - 1; i >= 0; i--) { + if (lines[i].boundary && lines[i].end <= most) candidates.push(lines[i].end) + } + for (let i = lines.length - 1; i >= 0; i--) { + if (lines[i].end <= most) candidates.push(lines[i].end) + } + for (let i = most - 1; i > 0; i--) { + if (/\s/.test(text[i])) { + candidates.push(i + 1) + break + } + } + candidates.push(most) + for (const candidate of candidates) { + const cut = withoutSplitPair(text, candidate) + if (cut > 0 && fits(cut)) return cut + } + return Math.max(1, withoutSplitPair(text, most) || codePointEnd(text)) +} + +const isHighSurrogate = (code: number) => code >= 0xd800 && code <= 0xdbff + +const withoutSplitPair = (text: string, cut: number): number => + cut > 0 && cut < text.length && isHighSurrogate(text.charCodeAt(cut - 1)) ? cut - 1 : cut + +const codePointEnd = (text: string): number => isHighSurrogate(text.charCodeAt(0)) && text.length > 1 ? 2 : 1 + +/** Past this many held characters, a held line is released up to its last whitespace. */ +const holdLimit = 300 + +/** + * What an append may send of `pending` before the input is finished: up to + * the last complete line, unless inside a code fence. + */ +const releasable = (pending: string, fence: Fence | undefined): string => { + const lines = scanLines(pending, fence, false) + const complete = lines.length === 0 ? 0 : lines[lines.length - 1].end + if (fenceAt(lines, fence, complete) !== undefined) return pending + const tail = pending.slice(complete) + if (tail.length <= holdLimit) return pending.slice(0, complete) + const space = tail.search(/\s\S*$/) + return space === -1 ? pending : pending.slice(0, complete + space + 1) +} + +const utf8Length = (text: string): number => { + let bytes = 0 + for (let i = 0; i < text.length; i++) { + const code = text.charCodeAt(i) + bytes += code < 0x80 ? 1 : code < 0x800 ? 2 : code >= 0xd800 && code <= 0xdfff ? 2 : 3 + } + return bytes +} + +// ----------------------------------------------------------------------------- +// the reply +// ----------------------------------------------------------------------------- + +const defaultMaxParts = 5 +/** Consecutive `retry` failures of appends on one stream before the repair. Provisional. */ +const appendRetryLimit = 3 +/** A native stream rolls over at the next block boundary past this share of `streamLength`. */ +const softShare = 0.85 +/** A native stream rotates once it is this share of `streamAge` old. */ +const ageShare = 0.8 +/** How long finishing a failed or interrupted reply may take. */ +const finishTimeout = Duration.seconds(5) + +type FailureCause = ChatMarkdownError["cause"] + +interface Current { + readonly start: number + readonly fence: Fence | undefined + readonly prefix: string + readonly transport: Part["transport"] + /** Appending to an open native stream. */ + native: boolean + posted: Posted | undefined + /** The input index the platform confirmed up to. */ + confirmed: number + /** The input index a write that failed `uncertain` reached. */ + uncertain: number + /** Native: the input index appended up to. */ + sent: number + /** The input length when this part was last written. */ + attempted: number + /** The Markdown the platform last confirmed. */ + markdown: string + /** Native: what has been appended, by `measure`. */ + measured: number + startedAt: number + retries: number +} + +interface ReplyOptions extends Options { + readonly thread: ChatThread + readonly initial: string + readonly deltas?: Stream.Stream | undefined + readonly descriptor: Descriptor + readonly chat: Chat.Chat["Service"] + readonly native?: NativeStream | undefined + readonly recipient?: string | undefined + readonly files?: ReadonlyArray | undefined + readonly unattachedNote?: ((files: ReadonlyArray) => string) | undefined +} + +const firstError = (exit: Exit.Exit): ChatError | undefined => + Option.getOrUndefined(Exit.findErrorOption(exit)) + +const reply = (options: ReplyOptions): Effect.Effect, R | R2> => + Effect.suspend(() => { + const { chat, descriptor, thread } = options + const measure = descriptor.measure + const limits = descriptor.limits + const interval = Duration.toMillis(options.minWriteInterval ?? limits.minWriteInterval) + const maxParts = Math.max(1, options.maxParts ?? defaultMaxParts) + const overflow = options.overflow ?? "fail" + const streamLength = Math.min(limits.streamLength ?? limits.messageLength, limits.messageLength) + const streamAge = limits.streamAge === undefined ? undefined : Duration.toMillis(limits.streamAge) + const onPart = options.onPart ?? (() => Effect.void) + const native = options.native + const latch = Latch.makeUnsafe(false) + + let input = options.initial + let upstream: Exit.Exit | undefined = options.deltas === undefined ? Exit.void : undefined + let state: { readonly _tag: "Running" } | { readonly _tag: "Done"; readonly stopped: boolean } | { + readonly _tag: "Failed" + readonly cause: FailureCause + } = { _tag: "Running" } + let finishing = false + let nativeAllowed = native !== undefined && options.recipient !== undefined + let renderedNatively = false + let lastWrite = Number.NEGATIVE_INFINITY + let retryAt: number | undefined + let overflowStart: number | undefined + let overflowBytes = 0 + let overflowUncertain = false + let note: string | undefined + const parts: Array = [] + + const isRunning = () => state._tag === "Running" + const fail = (cause: FailureCause) => { + if (isRunning()) state = { _tag: "Failed", cause } + } + const failChat = (error: ChatError) => fail({ _tag: "Chat", error }) + const done = (stopped: boolean) => { + if (isRunning()) state = { _tag: "Done", stopped } + } + + const newPart = (start: number, fence: Fence | undefined): Current => ({ + start, + fence, + prefix: reopening(fence), + transport: options.deltas === undefined ? "post" : nativeAllowed ? "native" : "edit", + native: nativeAllowed, + posted: undefined, + confirmed: start, + uncertain: start, + sent: start, + attempted: -1, + markdown: "", + measured: 0, + startedAt: 0, + retries: 0 + }) + + let current = newPart(0, undefined) + + const toPart = (part: Current, posted: Posted, markdown: string, end: number): Part => ({ + messageId: posted.id, + timestamp: posted.timestamp, + markdown, + text: input.slice(part.start, end), + kind: "text", + transport: part.transport + }) + + /** The open fence at `index` of the input, read from the current part's complete lines. */ + const fenceAtInput = (part: Current, index: number): Fence | undefined => { + const text = input.slice(part.start, index) + return fenceAt(scanLines(text, part.fence, false), part.fence, text.length) + } + + const now = Clock.currentTimeMillis + + /** Waits for the floor since the previous write returned. */ + const pace: Effect.Effect = Effect.flatMap(now, (time) => { + const wait = lastWrite + interval - time + return wait > 0 ? Effect.sleep(Duration.millis(wait)) : Effect.void + }) + const wrote = Effect.flatMap(now, (time) => Effect.sync(() => void (lastWrite = time))) + + const write = (effect: Effect.Effect): Effect.Effect> => + Effect.andThen(pace, Effect.ensuring(Effect.exit(effect), wrote)) + + /** Creates a message and runs `onPart` for it, as one uninterruptible step. */ + const create = ( + effect: Effect.Effect, + part: (posted: Posted) => Part + ): Effect.Effect, never, R2> => + Effect.andThen( + pace, + Effect.uninterruptible( + Effect.ensuring(Effect.exit(Effect.tap(effect, (posted) => onPart(part(posted)))), wrote) + ) + ) + + const finishPart = (end: number) => { + const part = current + parts.push(toPart(part, part.posted!, part.markdown, end)) + current = newPart(end, fenceAtInput(part, end)) + if (parts.length >= maxParts) { + overflowStart = end + overflowBytes = utf8Length(input.slice(end)) + } + } + + // --- post-then-edit -------------------------------------------------------- + + /** Writes the current part as `input[start, end)`. `last` marks the part's final write. */ + const writeEdit = (end: number, last: boolean): Effect.Effect => + Effect.suspend(() => { + const part = current + const markdown = render(part.prefix, input.slice(part.start, end), part.fence) + part.attempted = input.length + if (part.posted === undefined) return postPart(part, end, markdown, last) + if (part.confirmed === end && part.markdown === markdown) return Effect.void + const edit = chat.edit(thread, part.posted.id, { markdown }) + return Effect.map(write(last ? edit : Chat.withoutRetries(edit)), (exit) => { + if (Exit.isSuccess(exit)) { + part.confirmed = part.uncertain = end + part.markdown = markdown + return + } + const error = firstError(exit) + if (error === undefined) return + if (error.retry === "uncertain") part.uncertain = Math.max(part.uncertain, end) + if (last || error.retry === "denied") failChat(error) + }) + }) + + const postPart = (part: Current, end: number, markdown: string, last: boolean): Effect.Effect => { + const files = last && end === input.length && upstream !== undefined && (options.files?.length ?? 0) > 0 + ? options.files + : undefined + const attempt = (markdown: string, files: ReadonlyArray | undefined) => + create( + chat.post(thread, { + markdown, + ...(parts.length === 0 && options.replyTo !== undefined ? { replyTo: options.replyTo } : {}), + ...(files === undefined ? {} : { files }) + }), + (posted) => toPart(part, posted, markdown, end) + ) + const settle = (exit: Exit.Exit, markdown: string) => { + if (Exit.isSuccess(exit)) { + part.posted = exit.value + part.markdown = markdown + part.confirmed = part.uncertain = end + return + } + const error = firstError(exit) + if (error === undefined) return + if (error.retry === "uncertain") part.uncertain = end + failChat(error) + } + return Effect.flatMap(attempt(markdown, files), (exit) => { + const error = firstError(exit) + if (files === undefined || options.unattachedNote === undefined || error?.retry !== "denied") { + return Effect.sync(() => settle(exit, markdown)) + } + // The platform refused the files: the last part goes out without them, ending in the note. + const text = options.unattachedNote(files) + if (measure(markdown + text) <= limits.messageLength) { + return Effect.map(attempt(markdown + text, undefined), (exit) => settle(exit, markdown + text)) + } + note = text + return Effect.map(attempt(markdown, undefined), (exit) => settle(exit, markdown)) + }) + } + + /** Posts an unattached note that did not fit the last part as a message of its own. */ + const postNote = (text: string): Effect.Effect => + Effect.map( + create(chat.post(thread, { markdown: text }), (posted) => ({ + messageId: posted.id, + timestamp: posted.timestamp, + markdown: text, + text: "", + kind: "text", + transport: "post" + })), + (exit) => { + if (Exit.isSuccess(exit)) { + parts.push({ + messageId: exit.value.id, + timestamp: exit.value.timestamp, + markdown: text, + text: "", + kind: "text", + transport: "post" + }) + return done(false) + } + const error = firstError(exit) + if (error !== undefined) failChat(error) + } + ) + + const stepEdit = (final: boolean): Effect.Effect => + Effect.suspend(() => { + const part = current + const body = input.slice(part.start) + const withFiles = parts.length === 0 && (options.files?.length ?? 0) > 0 + if (part.posted === undefined && isBlank(body) && !(final && withFiles)) { + if (final) done(false) + return Effect.void + } + if (measure(render(part.prefix, body, part.fence)) > limits.messageLength) { + const cut = part.start + fitCut(measure, body, part.fence, part.prefix, limits.messageLength) + return Effect.map(writeEdit(cut, true), () => { + if (isRunning()) finishPart(cut) + }) + } + return Effect.flatMap(writeEdit(input.length, final), () => { + if (!final || !isRunning()) return Effect.void + finishPart(input.length) + if (note !== undefined) return postNote(note) + done(false) + return Effect.void + }) + }) + + // --- native ---------------------------------------------------------------- + + /** Stops the native stream and says whether a user had clicked stop. A stop carries no text, so its failures are ignored. */ + const stopStream = (part: Current, end: "done" | "rotating"): Effect.Effect => + Effect.suspend(() => { + part.native = false + if (part.posted === undefined) return Effect.succeed(false) + return Effect.map(write(native!.stop(thread, part.posted.id, { end })), (exit) => + Exit.isSuccess(exit) && exit.value.stopped) + }) + + /** Ends a native part at `end`. The reply ends when `last`, or when a user had clicked stop. */ + const rollNative = (part: Current, end: number, last: boolean): Effect.Effect => + Effect.map(stopStream(part, last ? "done" : "rotating"), (stopped) => { + finishPart(end) + if (stopped || last) done(stopped) + }) + + const startNative = (final: boolean): Effect.Effect => + Effect.suspend(() => { + const part = current + const pending = input.slice(part.start) + const text = final ? pending : releasable(pending, part.fence) + if (isBlank(text)) { + if (final) done(false) + return Effect.void + } + part.attempted = input.length + const whole = render(part.prefix, text, part.fence) + const cut = measure(whole) > streamLength + ? fitCut(measure, text, part.fence, part.prefix, streamLength) + : text.length + const end = part.start + cut + const roll = cut < text.length + const markdown = roll || final ? render(part.prefix, text.slice(0, cut), part.fence) : part.prefix + text + return Effect.flatMap( + create( + native!.start(thread, { + markdown, + ...(parts.length === 0 && options.replyTo !== undefined ? { replyTo: options.replyTo } : {}), + recipient: options.recipient + }), + (posted) => toPart(part, posted, markdown, end) + ), + (exit): Effect.Effect => { + if (Exit.isFailure(exit)) { + const error = firstError(exit) + if (error === undefined) return Effect.void + return Effect.sync(() => { + if (error.reason._tag === "Unsupported" && !renderedNatively) { + nativeAllowed = false + current = newPart(part.start, part.fence) + return + } + if (error.retry === "uncertain") part.uncertain = end + failChat(error) + }) + } + renderedNatively = true + part.posted = exit.value + part.markdown = markdown + part.measured = measure(markdown) + part.confirmed = part.uncertain = part.sent = end + return Effect.flatMap(now, (time) => { + part.startedAt = time + return roll || final ? rollNative(part, end, !roll) : Effect.void + }) + } + ) + }) + + /** What the next append sends, and whether the part ends after it. */ + const nextAppend = (part: Current, final: boolean) => { + const pending = input.slice(part.sent) + const fence = fenceAtInput(part, part.sent) + const room = streamLength - part.measured + const soft = softShare * streamLength - part.measured + const lines = scanLines(pending, fence, false) + let piece = final ? pending : releasable(pending, fence) + let extra = final + ? closing(fenceAt(scanLines(pending, fence, true), fence, pending.length), part.markdown + pending) + : "" + let roll = false + if (measure(piece + extra) > soft) { + let boundary: number | undefined + for (const line of lines) { + if (!line.boundary) continue + const size = measure(pending.slice(0, line.end)) + if (size > room) break + if (size >= soft) { + boundary = line.end + break + } + } + if (boundary !== undefined) { + piece = pending.slice(0, boundary) + extra = "" + roll = true + } else if (measure(piece + extra) > room) { + const cut = fitCut(measure, pending, fence, "", room) + piece = pending.slice(0, cut) + extra = closing(fenceAt(lines, fence, cut), part.markdown + piece) + roll = true + } + } + return { piece, extra, roll, fits: measure(piece + extra) <= room } + } + + const appendNative = (final: boolean): Effect.Effect => + Effect.suspend(() => { + const part = current + const { extra, fits, piece, roll } = nextAppend(part, final) + if (piece === "" && extra === "") return final ? rollNative(part, part.sent, true) : Effect.void + // Not even the smallest cut fits what is left of the stream: the next part takes it. + if (!fits) return rollNative(part, part.sent, false) + part.attempted = input.length + const markdown = piece + extra + return Effect.flatMap( + write(native!.append(thread, part.posted!.id, markdown, { flush: final || roll })), + (exit): Effect.Effect => { + if (Exit.isSuccess(exit)) { + const { held, state } = exit.value + if (state === "stopped") { + return Effect.sync(() => { + part.native = false + finishPart(part.sent) + done(true) + }) + } + if (state === "closed") { + return Effect.sync(() => { + part.native = false + part.attempted = -1 + }) + } + const added = Math.max(0, markdown.length - held) + part.retries = 0 + part.sent += Math.min(piece.length, added) + part.confirmed = part.uncertain = part.sent + part.markdown += markdown.slice(0, added) + part.measured += measure(markdown.slice(0, added)) + return roll || (final && part.sent === input.length) ? rollNative(part, part.sent, !roll) : Effect.void + } + const error = firstError(exit) + if (error === undefined) return Effect.void + if (error.reason._tag === "TooLarge") return rollNative(part, part.sent, false) + if (error.retry === "retry") { + part.retries++ + if (part.retries >= appendRetryLimit) return repair(part) + const wait = error.retryAfter === undefined ? interval : Duration.toMillis(error.retryAfter) + return Effect.flatMap(now, (time) => Effect.sync(() => void (retryAt = time + wait))) + } + if (error.retry === "uncertain") { + part.uncertain = part.sent + piece.length + return repair(part) + } + return Effect.andThen(stopStream(part, "done"), Effect.sync(() => failChat(error))) + } + ) + }) + + /** Stops the stream, edits the part to its whole known text and carries on by post-then-edit. */ + const repair = (part: Current): Effect.Effect => + Effect.flatMap( + stopStream(part, "rotating"), + (stopped) => + Effect.map(writeEdit(Math.max(part.uncertain, part.sent), false), () => { + if (stopped && isRunning()) { + finishPart(part.confirmed) + done(true) + } + }) + ) + + const stepNative = (final: boolean): Effect.Effect => + Effect.suspend(() => { + const part = current + if (part.posted === undefined) return startNative(final) + if (final || streamAge === undefined) return appendNative(final) + return Effect.flatMap(now, (time) => + time - part.startedAt >= ageShare * streamAge + ? rollNative(part, part.sent, false) + : appendNative(final)) + }) + + // --- overflow -------------------------------------------------------------- + + const stepOverflow = (final: boolean): Effect.Effect => + Effect.suspend(() => { + const rest = input.slice(overflowStart!) + if (isBlank(rest)) { + if (final) done(false) + return Effect.void + } + if (overflow === "fail" || overflowBytes > limits.uploadBytes) { + fail({ _tag: "Overflow" }) + return Effect.void + } + // The upload is skipped when the reply failed or was interrupted. + if (!final || finishing) { + if (finishing) done(false) + return Effect.void + } + const file: File = { + name: overflow.file.name, + contentType: "text/markdown", + content: new TextEncoder().encode(rest) + } + const part = (posted: Posted): Part => ({ + messageId: posted.id, + timestamp: posted.timestamp, + markdown: "", + text: rest, + kind: "overflowFile", + transport: "post" + }) + return Effect.map(create(chat.post(thread, { markdown: "", files: [file] }), part), (exit) => { + if (Exit.isSuccess(exit)) { + parts.push(part(exit.value)) + overflowStart = input.length + return done(false) + } + const error = firstError(exit) + if (error === undefined) return + overflowUncertain = error.retry === "uncertain" + failChat(error) + }) + }) + + // --- the loop -------------------------------------------------------------- + + const hasWork = (): boolean => { + if (!isRunning() || upstream !== undefined) return true + if (overflowStart !== undefined) { + return !isBlank(input.slice(overflowStart)) && (overflow === "fail" || overflowBytes > limits.uploadBytes) + } + const part = current + if (input.length <= part.attempted) return false + if (!part.native) return !isBlank(input.slice(part.start)) + return part.posted === undefined + ? !isBlank(releasable(input.slice(part.start), part.fence)) + : releasable(input.slice(part.sent), fenceAtInput(part, part.sent)) !== "" + } + + /** Waits until there is something to write, or a retry is due. */ + const awaitWork: Effect.Effect = Effect.suspend(() => { + if (retryAt !== undefined) { + const at = retryAt + retryAt = undefined + return Effect.flatMap(now, (time) => time < at ? Effect.sleep(Duration.millis(at - time)) : Effect.void) + } + if (hasWork()) return Effect.void + latch.closeUnsafe() + return Effect.andThen(latch.await, awaitWork) + }) + + const step = (final: boolean): Effect.Effect => { + if (overflowStart !== undefined) return stepOverflow(final) + return current.native ? stepNative(final) : stepEdit(final) + } + + const loop: Effect.Effect = Effect.suspend(() => + isRunning() ? + Effect.flatMap(awaitWork, () => { + if (!isRunning() || (upstream !== undefined && Exit.isFailure(upstream))) return Effect.void + // The write takes whatever arrived while it waited for the floor. + return Effect.andThen(pace, Effect.suspend(() => step(upstream !== undefined))).pipe(Effect.andThen(loop)) + }) : + Effect.void + ) + + /** Writes what was received as the end of the reply, closing an open fence, within a short timeout. */ + const finish: Effect.Effect = Effect.suspend(() => { + finishing = true + const drain: Effect.Effect = Effect.suspend(() => + isRunning() ? Effect.andThen(step(true), drain) : Effect.void + ) + // Interruptible, so the timeout can cut it short when it runs in the interrupt finalizer. + return Effect.asVoid(Effect.timeoutOption(Effect.interruptible(drain), finishTimeout)) + }) + + const toError = (cause: FailureCause): ChatMarkdownError => { + const posted = parts.slice() + let uncertain = "" + let from: number + if (overflowStart !== undefined) { + from = overflowStart + if (overflowUncertain) { + uncertain = input.slice(from) + from = input.length + } + } else { + const part = current + if (part.posted !== undefined) posted.push(toPart(part, part.posted, part.markdown, part.confirmed)) + from = Math.max(part.confirmed, part.uncertain) + uncertain = input.slice(part.confirmed, from) + } + return new ChatMarkdownError({ + posted, + remaining: input.slice(from), + ...(uncertain === "" ? {} : { uncertain }), + cause + }) + } + + const consume: Effect.Effect = options.deltas === undefined + ? Effect.void + : Effect.flatMap( + Effect.exit(Stream.runForEach(options.deltas, (chunk) => + Effect.sync(() => { + input += chunk + if (overflowStart !== undefined) overflowBytes += utf8Length(chunk) + latch.openUnsafe() + }))), + (exit) => + Effect.sync(() => { + upstream = exit + latch.openUnsafe() + }) + ) + + return Effect.gen(function*() { + const fiber = yield* Effect.forkChild(consume) + yield* Effect.onInterrupt(loop, () => Effect.andThen(Fiber.interrupt(fiber), finish)) + yield* Fiber.interrupt(fiber) + if (upstream !== undefined && Exit.isFailure(upstream) && (isRunning() || state._tag === "Done")) { + const cause = upstream.cause + state = { _tag: "Running" } + yield* finish + const error = Cause.findErrorOption(cause) + if (Option.isNone(error)) return yield* Effect.failCause(cause as Cause.Cause) + state = { _tag: "Failed", cause: { _tag: "Upstream", error: error.value } } + } + yield* Effect.annotateCurrentSpan("chat.markdown.transport", renderedNatively ? "native" : current.transport) + if (state._tag === "Failed") return yield* Effect.fail(toError(state.cause)) + return { parts, stopped: state._tag === "Done" && state.stopped } + }) + }) + +// ----------------------------------------------------------------------------- +// the calls +// ----------------------------------------------------------------------------- + +/** + * Posts Markdown of any length, split into as many messages as it needs. + * + * **Details** + * + * - A part ends at a block boundary: after a blank line or a closed code + * fence. A block too long for one message is cut at a line, closing the code + * fence it is in and reopening it in the next part. Length is measured with + * the adapter's `measure`. + * - Each part is posted once and never edited. Parts are paced by + * `minWriteInterval`. + * - `files` go with the last part. When the platform refuses them with a + * `denied` failure and `unattachedNote` is given, the last part goes out + * without them, ending in the note, or followed by the note when it does not + * fit. Without `unattachedNote` the refusal fails the call. + * - An empty input posts nothing and succeeds with no parts, unless there are + * files, which then go out in a message of their own. + * + * **Gotchas** + * + * A failure in the middle leaves the parts already posted in place. The error + * says what was posted and what was not. + * + * @stability unstable + * @category constructors + * @since 4.1.5 + */ +export const post = ( + thread: ChatThread, + markdown: string, + options?: Options & { + readonly files?: ReadonlyArray | undefined + readonly unattachedNote?: ((files: ReadonlyArray) => string) | undefined + } +): Effect.Effect => + Effect.gen(function*() { + const chat = yield* Chat.Chat + const descriptor = yield* Effect.mapError( + chat.descriptor(thread.platform), + (error) => new ChatMarkdownError({ posted: [], remaining: markdown, cause: { _tag: "Chat", error } }) + ) + return yield* reply({ ...options, thread, initial: markdown, descriptor, chat }) + }).pipe(Effect.withSpan("ChatMarkdown.post", { attributes: { "chat.platform": thread.platform } })) + +/** + * Writes a stream of Markdown deltas as one reply, as the text arrives. + * + * **Details** + * + * - With a `recipient` and an adapter that has a native stream, the reply is + * written by native appends. Otherwise, or when the first native start fails + * with `Unsupported`, it posts and then edits. The result and the span say + * which ran. + * - Text that outgrows a message rolls over into a new one at a block + * boundary, and each new message counts against `maxParts`. A native stream + * rolls over at the next block boundary past 85% of `limits.streamLength`, + * and rotates once it is 80% of `limits.streamAge` old. + * - Writes are paced by `minWriteInterval`, on `Clock`. The next write is + * scheduled only after the previous one returns, and takes all the text that + * arrived meanwhile. + * - An append holds back the unfinished last line, unless inside a code fence. + * An edit closes an open code fence. + * - An intermediate edit that fails `retry` or `uncertain` is dropped, since + * the next edit carries the whole text. A `denied` failure, and any failure + * of a post or of a part's last edit, fails the reply. + * - A native append that fails `retry` is tried again after its + * `retryAfter`, or the write interval, whether or not new text arrived. + * Three in a row, or one `uncertain` failure, stop the stream, edit the part + * to its whole known text and carry on by post-then-edit. `TooLarge` starts + * the next part with the chunk. + * - `Result.stopped` is true when a user clicked stop on the reply. The + * upstream is then interrupted. + * - When the upstream fails or the call is interrupted, what was received is + * written out, with an open code fence closed, within a short timeout, and + * left posted. + * + * **Gotchas** + * + * - There are no files: post them after the result, when it is known whether + * the reply stopped. + * - To stop a reply, end `deltas` with `Stream.interruptWhen` or + * `Stream.haltWhen`, so a `Result` still comes back. Interrupting the call + * leaves only the ids collected through `onPart`. + * - Native writes go to the adapter through the `Registry`, so a layer that + * wraps `Chat` does not see them. + * - A native part that is rolled over on `TooLarge` or rotated on age can end + * inside an open code fence, since it can no longer be appended to. The next + * part reopens the fence. + * - Post-then-edit needs the `edit` capability. + * + * @stability unstable + * @category constructors + * @since 4.1.5 + */ +export const stream = ( + thread: ChatThread, + deltas: Stream.Stream, + options?: Options & { + readonly recipient?: string | undefined + } +): Effect.Effect, Chat.Chat | Registry | R | R2> => + Effect.gen(function*() { + const chat = yield* Chat.Chat + const registry = yield* Registry + const adapter = yield* Effect.mapError( + registry.get(thread.platform), + (error) => new ChatMarkdownError({ posted: [], remaining: "", cause: { _tag: "Chat", error } }) + ) + const native = adapter.descriptor.capabilities.has("nativeStream") ? adapter.nativeStream : undefined + return yield* reply({ + ...options, + thread, + initial: "", + deltas, + descriptor: adapter.descriptor, + chat, + native + }) + }).pipe(Effect.withSpan("ChatMarkdown.stream", { attributes: { "chat.platform": thread.platform } })) diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts index 7d691a5f8a8..9bfdd5ad2c6 100644 --- a/packages/effect/src/chat/ChatTest.ts +++ b/packages/effect/src/chat/ChatTest.ts @@ -15,6 +15,7 @@ * @stability unstable * @since 4.1.5 */ +import * as Clock from "../Clock.ts" import * as Context from "../Context.ts" import * as DateTime from "../DateTime.ts" import * as Duration from "../Duration.ts" @@ -25,7 +26,7 @@ import * as Option from "../Option.ts" import * as Schema from "../Schema.ts" import * as Stream from "../Stream.ts" import * as Chat from "./Chat.ts" -import type { ChatAdapter, Descriptor, File, Posted } from "./ChatAdapter.ts" +import type { ChatAdapter, Descriptor, File, NativeStream, Posted } from "./ChatAdapter.ts" import { checkMessageLength, Registry, retrySafe } from "./ChatAdapter.ts" import type { Capability, ChatErrorReason } from "./ChatError.ts" import { @@ -100,6 +101,13 @@ export interface Call { * call the adapter received. * - `failNext` makes the next `times` calls of `op` fail with `reason`. * `landed` makes the write happen anyway, which is what `uncertain` means. + * The native stream's ops are `nativeStream.start`, `nativeStream.append` + * and `nativeStream.stop`. + * - `clickStop` is a user clicking stop on a native stream. It closes + * nothing, as on Slack: the stream keeps taking text, and + * `NativeStream.stop` then reports `stopped: true`. + * - `closeStream` closes a native stream from outside, so the next append + * gives `closed`, or `stopped` after a click. * * @stability unstable * @category services @@ -124,6 +132,8 @@ export class ChatTest extends Context.Service Effect.Effect + readonly clickStop: (messageId: string) => Effect.Effect + readonly closeStream: (messageId: string) => Effect.Effect }>()("effect/chat/ChatTest") {} // ----------------------------------------------------------------------------- @@ -141,9 +151,26 @@ const allCapabilities: ReadonlyArray = [ "startThread", "getThread", "opener", - "getUser" + "getUser", + "nativeStream" ] +/** Counts code points. */ +const codePoints = (markdown: string): number => { + let count = 0 + for (const _ of markdown) count++ + return count +} + +interface StoredStream { + readonly startedAt: number + open: boolean + clicked: boolean +} + +/** An append holds back an unclosed `<` tail, as Slack does, up to this many characters. */ +const heldBound = 100 + interface StoredThread { readonly thread: ChatThread.ChatThread readonly kind: ThreadKind @@ -200,19 +227,25 @@ const makeFake = (options: { readonly selfId: string readonly capabilities: ReadonlyArray readonly limits: Partial + readonly measure: (markdown: string) => number }) => { const { platform, selfId } = options + const capabilities = new Set(options.capabilities) + const messageLength = options.limits.messageLength ?? 4000 const descriptor: Descriptor = { platform, - capabilities: new Set(options.capabilities.filter((capability) => capability !== "nativeStream")), + capabilities, + measure: options.measure, limits: { - messageLength: 4000, + messageLength, filesPerMessage: 10, uploadBytes: 10 * 1024 * 1024, minWriteInterval: Duration.zero, + ...(capabilities.has("nativeStream") ? { streamLength: messageLength, streamAge: Duration.minutes(10) } : {}), ...options.limits } } + const streams = new Map() const threads = new Map() const messages = new Map() const order: Array = [] @@ -335,9 +368,10 @@ const makeFake = (options: { const attempt = ( call: Omit, needs: ReadonlyArray, - body: Effect.Effect + body: Effect.Effect, + retries: boolean = true ): Effect.Effect => - retrySafe(Effect.suspend(() => { + (retries ? retrySafe : (effect: X) => effect)(Effect.suspend(() => { const record = (outcome: Call["outcome"]) => calls.push({ ...call, outcome }) const missing = needs.find((capability) => !descriptor.capabilities.has(capability)) if (missing !== undefined) { @@ -356,8 +390,98 @@ const makeFake = (options: { ) })) + /** Whether a native stream is open on the message, closing it once it is past `limits.streamAge`. */ + const isOpen = (messageId: string) => + Effect.map(Clock.currentTimeMillis, (now) => { + const stream = streams.get(messageId) + if (stream === undefined || !stream.open) return false + const age = descriptor.limits.streamAge + if (age !== undefined && now - stream.startedAt >= Duration.toMillis(age)) stream.open = false + return stream.open + }) + + const streamLength = () => descriptor.limits.streamLength ?? descriptor.limits.messageLength + + const nativeStream: NativeStream = { + start: (thread, content) => + attempt( + { op: "nativeStream.start", thread, markdown: content.markdown }, + content.replyTo === undefined ? ["nativeStream"] : ["nativeStream", "replyTo"], + Effect.gen(function*() { + yield* findThread("nativeStream.start", thread) + yield* checkMessageLength(descriptor, "nativeStream.start", content.markdown) + if (descriptor.measure(content.markdown) > streamLength()) { + return yield* fail("nativeStream.start", new TooLarge({ detail: "msg_too_long" })) + } + let replyTo: ReplyTo | undefined + if (content.replyTo !== undefined) { + const target = yield* findMessage("nativeStream.start", thread, content.replyTo.messageId) + replyTo = { messageId: target.id, authorId: target.authorId } + } + const stored = yield* store({ + thread, + authorId: selfId, + isBot: true, + isSelf: true, + text: content.markdown, + mentions: [], + replyTo, + attachments: [] + }) + streams.set(stored.id, { startedAt: yield* Clock.currentTimeMillis, open: true, clicked: false }) + return { id: stored.id, thread, timestamp: stored.timestamp } satisfies Posted + }) + ), + append: (thread, messageId, markdown, appendOptions) => + attempt( + { op: "nativeStream.append", thread, messageId, markdown }, + ["nativeStream"], + Effect.gen(function*() { + const message = yield* findMessage("nativeStream.append", thread, messageId) + const stream = streams.get(message.id) + if (stream === undefined || !(yield* isOpen(message.id))) { + return { state: stream?.clicked === true ? "stopped" as const : "closed" as const, held: 0 } + } + let held = 0 + const open = markdown.lastIndexOf("<") + if (appendOptions?.flush !== true && open !== -1 && !markdown.includes(">", open)) { + held = markdown.length - open + if (held > heldBound) held = 0 + } + const sent = markdown.slice(0, markdown.length - held) + if (descriptor.measure(message.text + sent) > streamLength()) { + return yield* fail("nativeStream.append", new TooLarge({ detail: "msg_too_long" })) + } + message.text += sent + return { state: "open" as const, held } + }), + false + ), + stop: (thread, messageId) => + attempt( + { op: "nativeStream.stop", thread, messageId }, + ["nativeStream"], + Effect.gen(function*() { + const message = yield* findMessage("nativeStream.stop", thread, messageId) + const stream = streams.get(message.id) + if (stream === undefined || !(yield* isOpen(message.id))) return { stopped: false } + stream.open = false + return { stopped: stream.clicked } + }) + ) + } + + const streamFor = (op: string, messageId: string) => + Effect.suspend(() => { + const stream = streams.get(messageId) + return stream === undefined + ? Effect.die(new Error("ChatTest." + op + ": no native stream " + messageId)) + : Effect.succeed(stream) + }) + const adapter: ChatAdapter = { descriptor, + ...(capabilities.has("nativeStream") ? { nativeStream } : {}), post: (thread, content) => { const files = content.files ?? [] const needs: Array = [] @@ -401,6 +525,9 @@ const makeFake = (options: { Effect.gen(function*() { const message = yield* findMessage("edit", thread, messageId) if (!message.isSelf) return yield* fail("edit", new Forbidden({ detail: "cant_update_message" })) + if (yield* isOpen(message.id)) { + return yield* fail("edit", new InvalidRequest({ detail: "streaming_state_conflict" })) + } yield* checkMessageLength(descriptor, "edit", content.markdown) message.text = content.markdown message.mentions = [] @@ -413,6 +540,9 @@ const makeFake = (options: { Effect.gen(function*() { const message = yield* findMessage("delete", thread, messageId) if (!message.isSelf) return yield* fail("delete", new Forbidden({ detail: "cant_delete_message" })) + if (yield* isOpen(message.id)) { + return yield* fail("delete", new InvalidRequest({ detail: "cant_delete_message" })) + } messages.delete(message.id) }) ), @@ -567,7 +697,9 @@ const makeFake = (options: { const queue = faults.get(op) ?? [] queue.push({ reason, remaining: failOptions?.times ?? 1, landed: failOptions?.landed ?? false }) faults.set(op, queue) - }) + }), + clickStop: (messageId) => Effect.map(streamFor("clickStop", messageId), (stream) => void (stream.clicked = true)), + closeStream: (messageId) => Effect.map(streamFor("closeStream", messageId), (stream) => void (stream.open = false)) }) return { adapter, service } @@ -584,10 +716,17 @@ const makeFake = (options: { * **Details** * * - The platform defaults to `test` and the bot's user id to `bot`. - * - Every capability is on by default, except `nativeStream`: the fake has no - * native stream yet. - * - The default limits are 4000 characters per message, 10 files of up to - * 10 MiB, and no write interval. + * - Every capability is on by default. + * - `measure` defaults to a count of code points, and the fake checks every + * length with it. + * - The default limits are 4000 per message, 10 files of up to 10 MiB, and no + * write interval. With `nativeStream` on, a stream takes up to + * `messageLength` and lasts 10 minutes. + * - The native stream behaves the way Slack's was found to. An append past + * `limits.streamLength` fails with `TooLarge` and adds nothing. A stream + * past `limits.streamAge`, on `Clock`, is closed. An append without + * `flush` holds back an unclosed `<` tail of up to 100 characters. An open + * stream refuses `edit` and `delete`. * - Two layers merged with different platforms share one `Chat`, so routing * can be tested. The `ChatTest` service in context is the last one merged. * @@ -600,6 +739,7 @@ export const layer = (options?: { readonly selfId?: string | undefined readonly capabilities?: ReadonlyArray | undefined readonly limits?: Partial | undefined + readonly measure?: ((markdown: string) => number) | undefined }): Layer.Layer => Layer.effect( ChatTest, @@ -609,7 +749,8 @@ export const layer = (options?: { platform: options?.platform ?? "test", selfId: options?.selfId ?? "bot", capabilities: options?.capabilities ?? allCapabilities, - limits: options?.limits ?? {} + limits: options?.limits ?? {}, + measure: options?.measure ?? codePoints }) yield* registry.register(adapter) return service @@ -1032,6 +1173,25 @@ const findIn = (messages: ReadonlyArray, id: string) => const mentionLike = "@everyone @here <@U0000> <@&1> <#C0000>" +/** Text a platform takes in any quantity: no emoji, which Slack limits separately. */ +const measureFitsBlock = "a < b & c > d\n\n```ts\nconst x = 1 < 2\n```\n\n\u{1D400}\u{1D401} caf\u00e9\n\n" + +const measureSamples: ReadonlyArray = [ + "", + "x", + "hello world", + "<", + "a < b", + "<@U0000>", + "& > &", + "```\ncode < 1\n```\n", + "```", + "\u{1D400}\u{1D401}", + "\u{1F600}\u{1F44D}\u{1F3FD}", + ":grinning:", + "caf\u00e9" +] + interface ConformanceOptions { readonly platform: string readonly thread: ChatThread.ChatThread @@ -1169,6 +1329,42 @@ export const conformance = (options: { (posted) => t.created.push({ thread: t.thread, id: posted.id }) )) + rule("descriptor/measureFits", [], (t) => + Effect.gen(function*() { + const { measure } = t.descriptor + const limit = t.descriptor.limits.messageLength + const largest = (make: (n: number) => string) => { + let low = 0 + let high = limit + while (low < high) { + const middle = Math.ceil((low + high) / 2) + if (measure(make(middle)) <= limit) low = middle + else high = middle - 1 + } + return make(low) + } + const blocks = largest((n) => measureFitsBlock.repeat(n)) + const markdown = largest((n) => blocks + "x".repeat(n)) + yield* t.post({ markdown }) + })) + + rule("descriptor/measureAdds", [], (t) => + Effect.gen(function*() { + const { measure } = t.descriptor + for (const a of measureSamples) { + for (const b of measureSamples) { + yield* t.check( + measure(a + b) <= measure(a) + measure(b), + "measure(a + b) <= measure(a) + measure(b)", + () => JSON.stringify(a) + " + " + JSON.stringify(b) + " measures " + measure(a + b) + ) + } + } + const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + yield* t.check(measure(letters) === letters.length, "ASCII letters measured at one each", () => + letters.length + " letters measure " + measure(letters)) + })) + rule("post/noMentions", ["fetchMessage"], (t) => Effect.gen(function*() { const posted = yield* t.post({ markdown: mentionLike }) @@ -1346,7 +1542,54 @@ export const conformance = (options: { (opener) => t.check(Option.isNone(opener), "no opener", () => "an opener") )) - for (const capability of [...allCapabilities, "nativeStream" as const]) { + rule("descriptor/streamFitsMessage", ["nativeStream"], (t) => { + const { messageLength, streamLength } = t.descriptor.limits + return t.check( + streamLength !== undefined && streamLength <= messageLength, + "limits.streamLength at most " + messageLength, + () => "limits.streamLength " + streamLength + ) + }) + + const openStream = Effect.fnUntraced(function*(t: Tester, markdown: string) { + const registry = yield* Registry + const adapter = yield* t.call(registry.get(platform)) + const native = adapter.nativeStream! + const event = yield* t.userPosts() + const posted = yield* t.call(native.start(t.thread, { markdown, recipient: event.message.author.id })) + t.created.push({ thread: t.thread, id: posted.id }) + return { native, posted } + }) + + rule("nativeStream/concatenates", ["nativeStream", "fetchMessage"], (t) => + Effect.gen(function*() { + const first = conformanceText(t.rule) + " one" + const { native, posted } = yield* openStream(t, first) + const appended = yield* t.call(native.append(t.thread, posted.id, " two", { flush: true })).pipe( + Effect.ensuring(Effect.ignore(native.stop(t.thread, posted.id, { end: "done" }))) + ) + yield* t.check(appended.state === "open" && appended.held === 0, "an open append holding nothing", () => + appended.state + " holding " + appended.held) + const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check(message.text === first + " two", JSON.stringify(first + " two"), () => + JSON.stringify(message.text)) + })) + + rule("nativeStream/appendAfterStop", ["nativeStream", "fetchMessage"], (t) => + Effect.gen(function*() { + const first = conformanceText(t.rule) + const { native, posted } = yield* openStream(t, first) + yield* t.call(native.stop(t.thread, posted.id, { end: "done" })) + const appended = yield* t.call(native.append(t.thread, posted.id, " after", { flush: true })) + const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id)) + yield* t.check( + appended.state === "closed" && message.text === first, + "closed, with the text unchanged", + () => appended.state + " with " + JSON.stringify(message.text) + ) + })) + + for (const capability of allCapabilities) { rule("unsupported/" + capability, [], (t) => t.probe(capability)) } @@ -1370,7 +1613,8 @@ export const conformance = (options: { yield* t.post({}) const elapsed = DateTime.distance(start, yield* DateTime.now) yield* t.check( - Duration.isGreaterThanOrEqualTo(elapsed, retryAfter), + // One millisecond of slack: a timer and the clock round to whole milliseconds apart. + Duration.toMillis(elapsed) + 1 >= Duration.toMillis(retryAfter), "a retry after " + Duration.format(retryAfter), () => "a retry after " + Duration.format(elapsed) ) diff --git a/packages/effect/src/chat/index.ts b/packages/effect/src/chat/index.ts index 631ebf4c269..243c7582827 100644 --- a/packages/effect/src/chat/index.ts +++ b/packages/effect/src/chat/index.ts @@ -35,6 +35,12 @@ export * as ChatEvent from "./ChatEvent.ts" */ export * as ChatHandler from "./ChatHandler.ts" +/** + * @stability unstable + * @since 4.1.5 + */ +export * as ChatMarkdown from "./ChatMarkdown.ts" + /** * @stability unstable * @since 4.1.5 diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts new file mode 100644 index 00000000000..50e3f3da5cb --- /dev/null +++ b/packages/effect/test/chat/ChatMarkdown.test.ts @@ -0,0 +1,483 @@ +import { assert, describe, it } from "@effect/vitest" +import { type Cause, Duration, Effect, Fiber, Queue, Stream } from "effect" +import { ChatError, ChatMarkdown, ChatTest } from "effect/chat" +import type { ChatThread } from "effect/chat" +import { TestClock } from "effect/testing" + +const codePoints = (markdown: string) => [...markdown].length + +const joined = (parts: ReadonlyArray) => parts.map((part) => part.text).join("") + +const paragraphs = (count: number, size: number) => + Array.from({ length: count }, (_, i) => ("Paragraph " + i + " ").padEnd(size, "x")).join("\n\n") + +const settle = Effect.forEach(Array.from({ length: 50 }), () => Effect.yieldNow, { discard: true }) + +const setup = Effect.gen(function*() { + const test = yield* ChatTest.ChatTest + const thread = yield* test.makeThread() + return { test, thread } +}) + +const texts = (test: ChatTest.ChatTest["Service"], thread: ChatThread.ChatThread) => + Effect.map(test.messages(thread), (messages) => messages.map((message) => message.text)) + +/** Runs `stream` over a queue the test feeds. */ +const feed = Effect.fnUntraced(function*( + thread: ChatThread.ChatThread, + options?: ChatMarkdown.Options & { readonly recipient?: string | undefined } +) { + const queue = yield* Queue.unbounded() + const fiber = yield* Effect.forkChild(ChatMarkdown.stream(thread, Stream.fromQueue(queue), options)) + const send = (chunk: string) => Effect.andThen(Queue.offer(queue, chunk), settle) + const end = Effect.andThen(Queue.end(queue), Fiber.join(fiber)) + return { fiber, send, end } +}) + +const lone = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(? { + describe("post", () => { + it.effect("posts nothing for empty input", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const result = yield* ChatMarkdown.post(thread, "") + assert.deepStrictEqual(result, { parts: [], stopped: false }) + assert.deepStrictEqual(yield* test.calls, []) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("posts short Markdown as one part", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const result = yield* ChatMarkdown.post(thread, "Hello *world*") + assert.strictEqual(result.parts.length, 1) + const [part] = result.parts + assert.deepStrictEqual([part.markdown, part.text, part.kind, part.transport], [ + "Hello *world*", + "Hello *world*", + "text", + "post" + ]) + assert.deepStrictEqual(yield* texts(test, thread), ["Hello *world*"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("splits at block boundaries", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const input = paragraphs(10, 40) + const result = yield* ChatMarkdown.post(thread, input, { maxParts: 10 }) + assert.isTrue(result.parts.length > 1) + assert.strictEqual(joined(result.parts), input) + for (const part of result.parts) assert.isAtMost(codePoints(part.markdown), 100) + for (const part of result.parts.slice(0, -1)) assert.isTrue(part.text.endsWith("\n\n"), part.text) + assert.deepStrictEqual(yield* texts(test, thread), result.parts.map((part) => part.markdown)) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 100 } })))) + + it.effect("closes a code fence and reopens it in the next part", () => + Effect.gen(function*() { + const { thread } = yield* setup + const input = "```ts\n" + "const a = 1\n".repeat(10) + "```\n" + const result = yield* ChatMarkdown.post(thread, input) + assert.isTrue(result.parts.length > 1) + assert.strictEqual(joined(result.parts), input) + assert.isTrue(result.parts[0].markdown.endsWith("\n```"), result.parts[0].markdown) + for (const part of result.parts.slice(1)) assert.isTrue(part.markdown.startsWith("```ts\n"), part.markdown) + for (const part of result.parts) assert.isAtMost(codePoints(part.markdown), 60) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 60 } })))) + + it.effect("measures with the adapter's measure", () => { + const measure = (markdown: string) => codePoints(markdown) + 3 * markdown.split("<").length - 3 + return Effect.gen(function*() { + const { thread } = yield* setup + const input = "a + Effect.gen(function*() { + const { thread } = yield* setup + const input = "\u{1F600}".repeat(12) + const result = yield* ChatMarkdown.post(thread, input) + assert.strictEqual(result.parts.length, 3) + assert.strictEqual(joined(result.parts), input) + for (const part of result.parts) assert.isFalse(lone.test(part.markdown), part.markdown) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 5 } })))) + + it.effect("replies with the first part only", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const event = yield* test.userPosts(thread, { text: "question" }) + assert(event._tag === "MessageCreated") + const replyTo = { messageId: event.message.id } + const result = yield* ChatMarkdown.post(thread, paragraphs(3, 20), { replyTo }) + const messages = yield* test.messages(thread) + const replies = result.parts.map((part) => messages.find((message) => message.id === part.messageId)?.replyTo) + assert.deepStrictEqual(replies.map((reply) => reply?.messageId), [event.message.id, undefined, undefined]) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + + it.effect("runs onPart for every part", () => + Effect.gen(function*() { + const { thread } = yield* setup + const seen: Array = [] + const result = yield* ChatMarkdown.post(thread, paragraphs(3, 20), { + onPart: (part) => Effect.sync(() => seen.push(part.messageId)) + }) + assert.deepStrictEqual(seen, result.parts.map((part) => part.messageId)) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + + it.effect("fails with Overflow past maxParts", () => + Effect.gen(function*() { + const { thread } = yield* setup + const input = paragraphs(5, 20) + const error = yield* Effect.flip(ChatMarkdown.post(thread, input, { maxParts: 2 })) + assert.strictEqual(error.cause._tag, "Overflow") + assert.strictEqual(error.posted.length, 2) + assert.isUndefined(error.uncertain) + assert.strictEqual(joined(error.posted) + error.remaining, input) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + + it.effect("uploads the rest past maxParts as a file", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const input = paragraphs(5, 20) + const result = yield* ChatMarkdown.post(thread, input, { maxParts: 2, overflow: { file: { name: "rest.md" } } }) + assert.deepStrictEqual(result.parts.map((part) => part.kind), ["text", "text", "overflowFile"]) + assert.strictEqual(joined(result.parts), input) + const last = (yield* test.messages(thread)).at(-1)! + assert.deepStrictEqual(last.attachments.map((attachment) => attachment.name), ["rest.md"]) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + + const files = [{ name: "a.txt", contentType: "text/plain", content: new TextEncoder().encode("a") }] + + it.effect("sends files with the last part", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + yield* ChatMarkdown.post(thread, paragraphs(3, 20), { files }) + const messages = yield* test.messages(thread) + assert.deepStrictEqual(messages.map((message) => message.attachments.length), [0, 0, 1]) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + + it.effect("ends in the unattached note when the files are refused", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_uploads_disabled" })) + const result = yield* ChatMarkdown.post(thread, "Report", { + files, + unattachedNote: (files) => "\n\n(" + files.length + " file not attached)" + }) + assert.deepStrictEqual(result.parts.map((part) => [part.markdown, part.text]), [[ + "Report\n\n(1 file not attached)", + "Report" + ]]) + const messages = yield* test.messages(thread) + assert.deepStrictEqual(messages.map((message) => message.attachments.length), [0]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("fails when the files are refused without a note", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_uploads_disabled" })) + const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", { files })) + assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden") + assert.deepStrictEqual([error.posted, error.remaining], [[], "Report"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("reports the text of an uncertain post as uncertain", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const input = paragraphs(3, 20) + const error = yield* Effect.flip(ChatMarkdown.post(thread, input, { + onPart: () => test.failNext("post", new ChatError.Unknown({ detail: "timeout" })) + })) + assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Unknown") + assert.strictEqual(error.posted.length, 1) + assert.strictEqual(error.uncertain, "Paragraph 1 xxxxxxxx\n\n") + assert.strictEqual(joined(error.posted) + error.uncertain + error.remaining, input) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + + it.effect("paces the parts by minWriteInterval", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const fiber = yield* Effect.forkChild(ChatMarkdown.post(thread, paragraphs(3, 20))) + yield* settle + assert.strictEqual((yield* test.calls).length, 1) + yield* TestClock.adjust("999 millis") + assert.strictEqual((yield* test.calls).length, 1) + yield* TestClock.adjust("1 millis") + assert.strictEqual((yield* test.calls).length, 2) + yield* TestClock.adjust("1 second") + const result = yield* Fiber.join(fiber) + assert.strictEqual(result.parts.length, 3) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30, minWriteInterval: Duration.seconds(1) } })))) + + it.effect("keeps message text out of the error's message and JSON", () => + Effect.gen(function*() { + const { thread } = yield* setup + const error = yield* Effect.flip(ChatMarkdown.post(thread, paragraphs(5, 20), { maxParts: 1 })) + assert.notInclude(error.message, "Paragraph") + assert.notInclude(JSON.stringify(error.toJSON()), "Paragraph") + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + }) + + describe("stream", () => { + it.effect("posts nothing for an empty stream", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const result = yield* ChatMarkdown.stream(thread, Stream.empty, { recipient: "U1" }) + assert.deepStrictEqual(result, { parts: [], stopped: false }) + assert.deepStrictEqual(yield* test.calls, []) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("posts and then edits without a recipient", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread) + yield* send("Hello") + yield* send(" world\n\n```ts\nconst") + const result = yield* end + assert.deepStrictEqual(result.parts.map((part) => part.transport), ["edit"]) + assert.deepStrictEqual(yield* texts(test, thread), ["Hello world\n\n```ts\nconst\n```"]) + const calls = yield* test.calls + assert.deepStrictEqual(calls.map((call) => call.op), ["post", "edit"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("writes natively with a recipient, sending held text again", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("hello\n") + yield* send("x < y\n") + yield* send("```ts\ncode") + const result = yield* end + assert.deepStrictEqual(result.parts.map((part) => [part.transport, part.text]), [[ + "native", + "hello\nx < y\n```ts\ncode" + ]]) + assert.deepStrictEqual(yield* texts(test, thread), ["hello\nx < y\n```ts\ncode\n```"]) + const calls = yield* test.calls + assert.deepStrictEqual(calls.map((call) => [call.op, call.markdown]), [ + ["nativeStream.start", "hello\n"], + ["nativeStream.append", "x < y\n"], + ["nativeStream.append", "< y\n```ts\ncode"], + ["nativeStream.append", "< y\n```ts\ncode\n```"], + ["nativeStream.stop", undefined] + ]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("rolls a native stream over at a block boundary", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + const input = paragraphs(6, 28) + "\n\n" + for (const chunk of input.split(/(?<=\n\n)/)) yield* send(chunk) + const result = yield* end + assert.isTrue(result.parts.length > 1) + assert.strictEqual(joined(result.parts), input) + for (const part of result.parts) { + assert.strictEqual(part.transport, "native") + assert.isTrue(part.text.endsWith("\n\n"), part.text) + } + const messages = yield* texts(test, thread) + assert.deepStrictEqual(messages, result.parts.map((part) => part.markdown)) + for (const message of messages) assert.isAtMost(codePoints(message), 100) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 100 } })))) + + it.effect("forces a rollover on a TooLarge append", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.TooLarge({ detail: "msg_too_long" })) + yield* send("two\n") + const result = yield* end + assert.deepStrictEqual(result.parts.map((part) => part.text), ["one\n", "two\n"]) + assert.deepStrictEqual(yield* texts(test, thread), ["one\n", "two\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("falls back to post-then-edit when the start is Unsupported", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + yield* test.failNext("nativeStream.start", new ChatError.Unsupported({ capability: "nativeStream" })) + const result = yield* ChatMarkdown.stream(thread, Stream.make("one\n", "two\n"), { recipient: "U1" }) + assert.deepStrictEqual(result.parts.map((part) => part.transport), ["edit"]) + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("reports a click on stop that the consumer ignored", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const ids: Array = [] + const { end, send } = yield* feed(thread, { + recipient: "U1", + onPart: (part) => Effect.sync(() => ids.push(part.messageId)) + }) + yield* send("one\n") + yield* test.clickStop(ids[0]) + yield* send("two\n") + const result = yield* end + assert.isTrue(result.stopped) + assert.strictEqual(joined(result.parts), "one\ntwo\n") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("ends the reply stopped when an append comes back stopped", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const ids: Array = [] + const { fiber, send } = yield* feed(thread, { + recipient: "U1", + onPart: (part) => Effect.sync(() => ids.push(part.messageId)) + }) + yield* send("one\n") + yield* test.clickStop(ids[0]) + yield* test.closeStream(ids[0]) + yield* send("two\n") + const result = yield* Fiber.join(fiber) + assert.isTrue(result.stopped) + assert.strictEqual(joined(result.parts), "one\n") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("carries on by edit when the stream is closed", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const ids: Array = [] + const { end, send } = yield* feed(thread, { + recipient: "U1", + onPart: (part) => Effect.sync(() => ids.push(part.messageId)) + }) + yield* send("one\n") + yield* test.closeStream(ids[0]) + yield* send("two\n") + const result = yield* end + assert.deepStrictEqual(result.parts.map((part) => [part.transport, part.text]), [["native", "one\ntwo\n"]]) + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\n"]) + const ops = (yield* test.calls).map((call) => call.op) + assert.include(ops, "edit") + assert.notInclude(ops, "nativeStream.stop") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("tries a failed append again on a timer", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.RateLimited({ retryAfter: Duration.seconds(2) })) + yield* send("two\n") + assert.deepStrictEqual(yield* texts(test, thread), ["one\n"]) + yield* TestClock.adjust("2 seconds") + yield* settle + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\n"]) + const result = yield* end + assert.strictEqual(joined(result.parts), "one\ntwo\n") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("repairs by edit after three retry failures", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.RateLimited({}), { times: 3 }) + yield* send("two\n") + yield* send("three\n") + const result = yield* end + assert.deepStrictEqual(result.parts.map((part) => [part.transport, part.text]), [[ + "native", + "one\ntwo\nthree\n" + ]]) + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree\n"]) + const ops = (yield* test.calls).map((call) => call.op) + assert.deepStrictEqual(ops.filter((op) => op === "nativeStream.append").length, 3) + assert.include(ops, "edit") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("repairs by edit after an uncertain append", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.Unknown({}), { landed: true }) + yield* send("two\n") + yield* send("three\n") + const result = yield* end + assert.strictEqual(joined(result.parts), "one\ntwo\nthree\n") + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("fails on a denied append, after stopping the stream", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { fiber, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.Forbidden({})) + yield* send("two\n") + const error = yield* Effect.flip(Fiber.join(fiber)) + assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden") + assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", undefined, "two\n"]) + assert.include((yield* test.calls).map((call) => call.op), "nativeStream.stop") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("finishes what was received when the upstream fails", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const deltas = Stream.concat(Stream.make("```ts\n", "code\n", "more"), Stream.fail("boom")) + const error = yield* Effect.flip(ChatMarkdown.stream(thread, deltas, { recipient: "U1" })) + assert.deepStrictEqual(error.cause, { _tag: "Upstream", error: "boom" }) + assert.deepStrictEqual([joined(error.posted), error.remaining], ["```ts\ncode\nmore", ""]) + assert.deepStrictEqual(yield* texts(test, thread), ["```ts\ncode\nmore\n```"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("finishes what was received when interrupted", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { fiber, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("```ts\ncode\n") + yield* Fiber.interrupt(fiber) + assert.deepStrictEqual(yield* texts(test, thread), ["```ts\ncode\n```"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("rotates a native stream on age", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* TestClock.adjust("9 minutes") + yield* send("two\n") + const result = yield* end + assert.deepStrictEqual(result.parts.map((part) => [part.transport, part.text]), [["native", "one\n"], [ + "native", + "two\n" + ]]) + assert.deepStrictEqual(yield* texts(test, thread), ["one\n", "two\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("takes the text that arrived while waiting for the write interval", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread) + yield* send("a\n") + yield* send("b\n") + yield* send("c\n") + yield* TestClock.adjust("1 second") + yield* settle + const calls = yield* test.calls + assert.deepStrictEqual(calls.map((call) => [call.op, call.markdown]), [["post", "a\n"], ["edit", "a\nb\nc\n"]]) + const ended = yield* Effect.forkChild(end) + yield* settle + yield* TestClock.adjust("1 second") + const result = yield* Fiber.join(ended) + assert.strictEqual(joined(result.parts), "a\nb\nc\n") + }).pipe(Effect.provide(ChatTest.layer({ limits: { minWriteInterval: Duration.seconds(1) } })))) + + it.effect("fails with Overflow past maxParts", () => + Effect.gen(function*() { + const { thread } = yield* setup + const input = paragraphs(5, 20) + const error = yield* Effect.flip(ChatMarkdown.stream(thread, Stream.make(input), { maxParts: 1 })) + assert.strictEqual(error.cause._tag, "Overflow") + assert.strictEqual(joined(error.posted) + error.remaining, input) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + }) +}) diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts index ad734503028..98788888a6a 100644 --- a/packages/effect/test/chat/ChatTest.test.ts +++ b/packages/effect/test/chat/ChatTest.test.ts @@ -1,6 +1,6 @@ import { assert, describe, it } from "@effect/vitest" import { Effect, Exit, Option } from "effect" -import { ChatAdapter, ChatError, ChatHandler, ChatTest, ChatThread } from "effect/chat" +import { Chat, ChatAdapter, ChatError, ChatHandler, ChatTest, ChatThread } from "effect/chat" const kinds = { "@": "user", "@&": "role", "#": "channel", "!": "broadcast" } as const @@ -31,7 +31,7 @@ const ruleNames = Object.keys(ChatTest.conformance({ failNext: () => Effect.void })) -const capabilities = ChatError.Capability.literals.filter((capability) => capability !== "nativeStream") +const capabilities = ChatError.Capability.literals const runRule = (rule: string, options?: Parameters[0]) => Effect.flatMap(suite, (rules) => rules[rule]).pipe(Effect.provide(ChatTest.layer(options))) @@ -153,4 +153,19 @@ describe("ChatTest", () => { ))) assert.deepStrictEqual(received, ["MessageCreated", "self MessageCreated"]) }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("checks lengths with the configured measure", () => + Effect.gen(function*() { + const test = yield* ChatTest.ChatTest + const chat = yield* Chat.Chat + const thread = yield* test.makeThread() + yield* chat.post(thread, { markdown: "x".repeat(10) }) + const exit = yield* Effect.exit(chat.post(thread, { markdown: "<".repeat(3) })) + assert.isTrue(Exit.isFailure(exit)) + const error = Exit.isFailure(exit) ? Option.getOrUndefined(Exit.findErrorOption(exit)) : undefined + assert.strictEqual(error?.reason._tag, "TooLarge") + }).pipe(Effect.provide(ChatTest.layer({ + limits: { messageLength: 10 }, + measure: (markdown) => markdown.length + 3 * (markdown.split("<").length - 1) + })))) }) From d2278509c7f0dd3f2479c7b81bd7db73f60b1c53 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 17:36:36 +0000 Subject: [PATCH 05/89] Fix ChatMarkdown review findings - Record a created message before onPart and before an interrupt can land, and make appends uninterruptible with their bookkeeping, so the finalizer never posts or appends the same text twice. - Keep files and trailing blank text with the last part after a cut, and send files with the overflow file. - Repair a native stream by edit with the whole known text, the retried chunk included, without waiting for more input. - Reserve room in a native stream to close the open code fence, and close it before a rollover or an age rotation. - Retry without files only for reasons a file refusal can give. --- packages/effect/src/chat/ChatMarkdown.ts | 520 +++++++++++------- .../effect/test/chat/ChatMarkdown.test.ts | 131 ++++- 2 files changed, 442 insertions(+), 209 deletions(-) diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts index cb092c73f57..d012ca3e653 100644 --- a/packages/effect/src/chat/ChatMarkdown.ts +++ b/packages/effect/src/chat/ChatMarkdown.ts @@ -145,8 +145,8 @@ export class ChatMarkdownError extends Data.TaggedError("ChatMarkdown * - `minWriteInterval` is the floor between two writes. It defaults to the * adapter's `limits.minWriteInterval`. * - `onPart` runs for every message the call creates, the overflow file - * included, uninterruptibly with its post, so an interrupt can't lose an id. - * It has to be quick. + * included, uninterruptibly with its post, so an interrupt can neither lose + * an id nor post the message twice. It has to be quick. * * @stability unstable * @category models @@ -354,8 +354,6 @@ interface Current { attempted: number /** The Markdown the platform last confirmed. */ markdown: string - /** Native: what has been appended, by `measure`. */ - measured: number startedAt: number retries: number } @@ -375,6 +373,25 @@ interface ReplyOptions extends Options { const firstError = (exit: Exit.Exit): ChatError | undefined => Option.getOrUndefined(Exit.findErrorOption(exit)) +/** + * Whether a post with files may have failed because of the files. No reason + * says which part was refused, so a post that fails like this is tried again + * without them. A refusal of the text comes back again and fails the call. + */ +const isFileRefusal = (exit: Exit.Exit): boolean => { + const reason = firstError(exit)?.reason + switch (reason?._tag) { + case "Forbidden": + case "TooLarge": + case "InvalidRequest": + return true + case "Unsupported": + return reason.capability === "files" + default: + return false + } +} + const reply = (options: ReplyOptions): Effect.Effect, R | R2> => Effect.suspend(() => { const { chat, descriptor, thread } = options @@ -427,7 +444,6 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect Effect.sync(() => void (lastWrite = time))) - const write = (effect: Effect.Effect): Effect.Effect> => - Effect.andThen(pace, Effect.ensuring(Effect.exit(effect), wrote)) + /** + * Writes after the floor. \`commit\` records the result before an interrupt + * can land, so the finalizer never sees a write that happened as one that + * did not. With \`whole\`, the write itself is uninterruptible too: an + * append interrupted in flight could have landed, and sending it again + * would repeat text. Edits and stops are safe to repeat. + */ + const write = ( + effect: Effect.Effect, + commit: (exit: Exit.Exit) => void, + whole: boolean + ): Effect.Effect> => + Effect.andThen( + pace, + Effect.uninterruptibleMask((restore) => + Effect.exit(whole ? effect : restore(effect)).pipe( + Effect.ensuring(wrote), + Effect.tap((exit) => Effect.sync(() => commit(exit))) + ) + ) + ) - /** Creates a message and runs `onPart` for it, as one uninterruptible step. */ + /** + * Creates a message, records it and runs \`onPart\` for it, as one + * uninterruptible step, so an interrupt can neither lose an id nor make + * the finalizer create the message again. + */ const create = ( effect: Effect.Effect, - part: (posted: Posted) => Part + part: (posted: Posted) => Part, + commit: (exit: Exit.Exit, time: number) => void ): Effect.Effect, never, R2> => Effect.andThen( pace, Effect.uninterruptible( - Effect.ensuring(Effect.exit(Effect.tap(effect, (posted) => onPart(part(posted)))), wrote) + Effect.exit(effect).pipe( + Effect.ensuring(wrote), + Effect.tap((exit) => + Effect.flatMap(now, (time) => { + commit(exit, time) + return Exit.isSuccess(exit) ? onPart(part(exit.value)) : Effect.void + }) + ) + ) ) ) @@ -483,18 +531,31 @@ const reply = (options: ReplyOptions): Effect.Effect { + const rest = input.slice(from) + const last = parts.length - 1 + if (rest !== "" && last >= 0) parts[last] = { ...parts[last], text: parts[last].text + rest } + done(false) + } + + const hasFiles = (options.files?.length ?? 0) > 0 + // --- post-then-edit -------------------------------------------------------- - /** Writes the current part as `input[start, end)`. `last` marks the part's final write. */ - const writeEdit = (end: number, last: boolean): Effect.Effect => + /** + * Writes the current part as \`input[start, end)\`. \`last\` marks the part's + * final write, and \`withFiles\` the reply's last part, which takes the files. + */ + const writeEdit = (end: number, last: boolean, withFiles: boolean): Effect.Effect => Effect.suspend(() => { const part = current const markdown = render(part.prefix, input.slice(part.start, end), part.fence) part.attempted = input.length - if (part.posted === undefined) return postPart(part, end, markdown, last) + if (part.posted === undefined) return postPart(part, end, markdown, withFiles && hasFiles) if (part.confirmed === end && part.markdown === markdown) return Effect.void const edit = chat.edit(thread, part.posted.id, { markdown }) - return Effect.map(write(last ? edit : Chat.withoutRetries(edit)), (exit) => { + return Effect.asVoid(write(last ? edit : Chat.withoutRetries(edit), (exit) => { if (Exit.isSuccess(exit)) { part.confirmed = part.uncertain = end part.markdown = markdown @@ -504,22 +565,17 @@ const reply = (options: ReplyOptions): Effect.Effect => { - const files = last && end === input.length && upstream !== undefined && (options.files?.length ?? 0) > 0 - ? options.files - : undefined - const attempt = (markdown: string, files: ReadonlyArray | undefined) => - create( - chat.post(thread, { - markdown, - ...(parts.length === 0 && options.replyTo !== undefined ? { replyTo: options.replyTo } : {}), - ...(files === undefined ? {} : { files }) - }), - (posted) => toPart(part, posted, markdown, end) - ) + const postPart = ( + part: Current, + end: number, + markdown: string, + withFiles: boolean + ): Effect.Effect => { + const files = withFiles ? options.files! : undefined + const unattachedNote = files === undefined ? undefined : options.unattachedNote const settle = (exit: Exit.Exit, markdown: string) => { if (Exit.isSuccess(exit)) { part.posted = exit.value @@ -532,70 +588,81 @@ const reply = (options: ReplyOptions): Effect.Effect { - const error = firstError(exit) - if (files === undefined || options.unattachedNote === undefined || error?.retry !== "denied") { - return Effect.sync(() => settle(exit, markdown)) - } - // The platform refused the files: the last part goes out without them, ending in the note. - const text = options.unattachedNote(files) + const attempt = (markdown: string, files: ReadonlyArray | undefined, fallback: boolean) => + create( + chat.post(thread, { + markdown, + ...(parts.length === 0 && options.replyTo !== undefined ? { replyTo: options.replyTo } : {}), + ...(files === undefined ? {} : { files }) + }), + (posted) => toPart(part, posted, markdown, end), + (exit) => { + // Left unsettled: the post goes out again without the files. + if (fallback && isFileRefusal(exit)) return + settle(exit, markdown) + } + ) + return Effect.flatMap(attempt(markdown, files, unattachedNote !== undefined), (exit) => { + if (unattachedNote === undefined || !isFileRefusal(exit)) return Effect.void + // The platform may have refused the files: the last part goes out without them, ending in the note. + // A refusal of the text itself comes back again, and fails the call. + const text = unattachedNote(files!) if (measure(markdown + text) <= limits.messageLength) { - return Effect.map(attempt(markdown + text, undefined), (exit) => settle(exit, markdown + text)) + return Effect.asVoid(attempt(markdown + text, undefined, false)) } note = text - return Effect.map(attempt(markdown, undefined), (exit) => settle(exit, markdown)) + return Effect.asVoid(attempt(markdown, undefined, false)) }) } /** Posts an unattached note that did not fit the last part as a message of its own. */ - const postNote = (text: string): Effect.Effect => - Effect.map( - create(chat.post(thread, { markdown: text }), (posted) => ({ - messageId: posted.id, - timestamp: posted.timestamp, - markdown: text, - text: "", - kind: "text", - transport: "post" - })), - (exit) => { - if (Exit.isSuccess(exit)) { - parts.push({ - messageId: exit.value.id, - timestamp: exit.value.timestamp, - markdown: text, - text: "", - kind: "text", - transport: "post" - }) - return done(false) - } - const error = firstError(exit) - if (error !== undefined) failChat(error) + const postNote = (text: string): Effect.Effect => { + const part = (posted: Posted): Part => ({ + messageId: posted.id, + timestamp: posted.timestamp, + markdown: text, + text: "", + kind: "text", + transport: "post" + }) + return Effect.asVoid(create(chat.post(thread, { markdown: text }), part, (exit) => { + note = undefined + if (Exit.isSuccess(exit)) { + parts.push(part(exit.value)) + return done(false) } - ) + const error = firstError(exit) + if (error !== undefined) failChat(error) + })) + } const stepEdit = (final: boolean): Effect.Effect => Effect.suspend(() => { const part = current const body = input.slice(part.start) - const withFiles = parts.length === 0 && (options.files?.length ?? 0) > 0 - if (part.posted === undefined && isBlank(body) && !(final && withFiles)) { - if (final) done(false) + if (part.posted === undefined && isBlank(body) && !(final && hasFiles && parts.length === 0)) { + if (final) finishReply(part.start) + return Effect.void + } + const end = (last: boolean): Effect.Effect => { + if (!last || !isRunning()) return Effect.void + if (note !== undefined) return postNote(note) + done(false) return Effect.void } if (measure(render(part.prefix, body, part.fence)) > limits.messageLength) { const cut = part.start + fitCut(measure, body, part.fence, part.prefix, limits.messageLength) - return Effect.map(writeEdit(cut, true), () => { - if (isRunning()) finishPart(cut) + // Only blank text follows the cut: this is the last part, so it takes the files and that text. + const last = final && isBlank(input.slice(cut)) + return Effect.flatMap(writeEdit(cut, true, last), () => { + if (!isRunning()) return Effect.void + finishPart(last ? input.length : cut) + return end(last) }) } - return Effect.flatMap(writeEdit(input.length, final), () => { - if (!final || !isRunning()) return Effect.void - finishPart(input.length) - if (note !== undefined) return postNote(note) - done(false) - return Effect.void + return Effect.flatMap(writeEdit(input.length, final, final), () => { + if (final && isRunning()) finishPart(input.length) + return end(final) }) }) @@ -606,15 +673,18 @@ const reply = (options: ReplyOptions): Effect.Effect { part.native = false if (part.posted === undefined) return Effect.succeed(false) - return Effect.map(write(native!.stop(thread, part.posted.id, { end })), (exit) => - Exit.isSuccess(exit) && exit.value.stopped) + return Effect.map( + write(native!.stop(thread, part.posted.id, { end }), () => {}, false), + (exit) => Exit.isSuccess(exit) && exit.value.stopped + ) }) - /** Ends a native part at `end`. The reply ends when `last`, or when a user had clicked stop. */ + /** Ends a native part at \`end\`. The reply ends when \`last\`, or when a user had clicked stop. */ const rollNative = (part: Current, end: number, last: boolean): Effect.Effect => Effect.map(stopStream(part, last ? "done" : "rotating"), (stopped) => { finishPart(end) - if (stopped || last) done(stopped) + if (stopped) done(true) + else if (last) finishReply(end) }) const startNative = (final: boolean): Effect.Effect => @@ -623,10 +693,11 @@ const reply = (options: ReplyOptions): Effect.Effect streamLength ? fitCut(measure, text, part.fence, part.prefix, streamLength) @@ -641,156 +712,172 @@ const reply = (options: ReplyOptions): Effect.Effect toPart(part, posted, markdown, end) - ), - (exit): Effect.Effect => { - if (Exit.isFailure(exit)) { + (posted) => toPart(part, posted, markdown, end), + (exit, time) => { + if (Exit.isSuccess(exit)) { + renderedNatively = true + part.posted = exit.value + part.markdown = markdown + part.confirmed = part.uncertain = part.sent = end + part.startedAt = time + return + } const error = firstError(exit) - if (error === undefined) return Effect.void - return Effect.sync(() => { - if (error.reason._tag === "Unsupported" && !renderedNatively) { - nativeAllowed = false - current = newPart(part.start, part.fence) - return - } - if (error.retry === "uncertain") part.uncertain = end - failChat(error) - }) + if (error === undefined) return + if (error.reason._tag === "Unsupported" && !renderedNatively) { + nativeAllowed = false + current = newPart(part.start, part.fence) + return + } + if (error.retry === "uncertain") part.uncertain = end + failChat(error) } - renderedNatively = true - part.posted = exit.value - part.markdown = markdown - part.measured = measure(markdown) - part.confirmed = part.uncertain = part.sent = end - return Effect.flatMap(now, (time) => { - part.startedAt = time - return roll || final ? rollNative(part, end, !roll) : Effect.void - }) - } + ), + (exit) => Exit.isSuccess(exit) && (roll || final) ? rollNative(part, end, !roll) : Effect.void ) }) - /** What the next append sends, and whether the part ends after it. */ - const nextAppend = (part: Current, final: boolean) => { + /** + * What the next append sends, and whether the part ends after it. Every + * append leaves room to close the code fence it ends in, so a part that + * rolls over on length always ends with its fence closed. \`rotate\` sends + * just that closing fence, for a stream about to rotate on age. + */ + const nextAppend = (part: Current, final: boolean, rotate: boolean) => { const pending = input.slice(part.sent) const fence = fenceAtInput(part, part.sent) - const room = streamLength - part.measured - const soft = softShare * streamLength - part.measured const lines = scanLines(pending, fence, false) - let piece = final ? pending : releasable(pending, fence) - let extra = final + const size = (text: string) => measure(part.markdown + text) + const closeAt = (piece: string) => closing(fenceAt(lines, fence, piece.length), part.markdown + piece) + const closeOnly = { piece: "", extra: closeAt(""), roll: true } + if (rotate) return closeOnly + const soft = softShare * streamLength + const piece = final ? pending : releasable(pending, fence) + const reserve = final ? closing(fenceAt(scanLines(pending, fence, true), fence, pending.length), part.markdown + pending) - : "" - let roll = false - if (measure(piece + extra) > soft) { - let boundary: number | undefined - for (const line of lines) { - if (!line.boundary) continue - const size = measure(pending.slice(0, line.end)) - if (size > room) break - if (size >= soft) { - boundary = line.end - break - } - } - if (boundary !== undefined) { - piece = pending.slice(0, boundary) - extra = "" - roll = true - } else if (measure(piece + extra) > room) { - const cut = fitCut(measure, pending, fence, "", room) - piece = pending.slice(0, cut) - extra = closing(fenceAt(lines, fence, cut), part.markdown + piece) - roll = true - } + : closeAt(piece) + const extra = final ? reserve : "" + if (size(piece + reserve) <= soft) return { piece, extra, roll: false } + for (const line of lines) { + if (!line.boundary || line.end > piece.length) continue + const measured = size(pending.slice(0, line.end)) + if (measured > streamLength) break + if (measured >= soft) return { piece: pending.slice(0, line.end), extra: "", roll: true } } - return { piece, extra, roll, fits: measure(piece + extra) <= room } + if (size(piece + reserve) <= streamLength) return { piece, extra, roll: false } + const cut = pending.slice(0, fitCut(measure, pending, fence, part.markdown, streamLength)) + // Not even the smallest cut fits with its closing fence: send just the closing fence. + return size(cut + closeAt(cut)) <= streamLength ? { piece: cut, extra: closeAt(cut), roll: true } : closeOnly } - const appendNative = (final: boolean): Effect.Effect => + const appendNative = (final: boolean, rotate: boolean): Effect.Effect => Effect.suspend(() => { const part = current - const { extra, fits, piece, roll } = nextAppend(part, final) - if (piece === "" && extra === "") return final ? rollNative(part, part.sent, true) : Effect.void - // Not even the smallest cut fits what is left of the stream: the next part takes it. - if (!fits) return rollNative(part, part.sent, false) + const { extra, piece, roll } = nextAppend(part, final, rotate) + if (piece === "" && extra === "") { + return roll || final ? rollNative(part, part.sent, !roll) : Effect.void + } part.attempted = input.length const markdown = piece + extra - return Effect.flatMap( - write(native!.append(thread, part.posted!.id, markdown, { flush: final || roll })), - (exit): Effect.Effect => { - if (Exit.isSuccess(exit)) { - const { held, state } = exit.value - if (state === "stopped") { - return Effect.sync(() => { - part.native = false - finishPart(part.sent) - done(true) - }) - } - if (state === "closed") { - return Effect.sync(() => { - part.native = false - part.attempted = -1 - }) - } + let next: { readonly _tag: "None" | "Roll" | "Repair" | "StopAndFail" } | { + readonly _tag: "Retry" + readonly wait: number + } = { _tag: "None" } + const commit = (exit: Exit.Exit<{ readonly state: string; readonly held: number }, ChatError>) => { + if (Exit.isSuccess(exit)) { + const { held, state } = exit.value + if (state === "stopped") { + part.native = false + finishPart(part.sent) + done(true) + } else if (state === "closed") { + part.native = false + part.attempted = -1 + } else { const added = Math.max(0, markdown.length - held) part.retries = 0 part.sent += Math.min(piece.length, added) part.confirmed = part.uncertain = part.sent part.markdown += markdown.slice(0, added) - part.measured += measure(markdown.slice(0, added)) - return roll || (final && part.sent === input.length) ? rollNative(part, part.sent, !roll) : Effect.void + if (roll || (final && part.sent === input.length)) next = { _tag: "Roll" } } + } else { const error = firstError(exit) - if (error === undefined) return Effect.void - if (error.reason._tag === "TooLarge") return rollNative(part, part.sent, false) - if (error.retry === "retry") { + if (error === undefined) { + // Interrupted before the append ran. + } else if (error.reason._tag === "TooLarge") { + next = { _tag: "Roll" } + } else if (error.retry === "retry") { part.retries++ - if (part.retries >= appendRetryLimit) return repair(part) - const wait = error.retryAfter === undefined ? interval : Duration.toMillis(error.retryAfter) - return Effect.flatMap(now, (time) => Effect.sync(() => void (retryAt = time + wait))) - } - if (error.retry === "uncertain") { + next = part.retries >= appendRetryLimit + ? { _tag: "Repair" } + : { + _tag: "Retry", + wait: error.retryAfter === undefined ? interval : Duration.toMillis(error.retryAfter) + } + } else if (error.retry === "uncertain") { part.uncertain = part.sent + piece.length - return repair(part) + next = { _tag: "Repair" } + } else { + failChat(error) + next = { _tag: "StopAndFail" } + } + } + } + return Effect.flatMap( + write(native!.append(thread, part.posted!.id, markdown, { flush: final || roll }), commit, true), + (exit): Effect.Effect => { + switch (next._tag) { + case "None": + return Effect.void + case "Roll": + // A TooLarge forces a rollover; the next part starts with the chunk. + return rollNative(part, part.sent, Exit.isSuccess(exit) && !roll) + case "Repair": + return repair(part) + case "StopAndFail": + return Effect.asVoid(stopStream(part, "done")) + case "Retry": { + const wait = next.wait + return Effect.flatMap(now, (time) => Effect.sync(() => void (retryAt = time + wait))) + } } - return Effect.andThen(stopStream(part, "done"), Effect.sync(() => failChat(error))) } ) }) - /** Stops the stream, edits the part to its whole known text and carries on by post-then-edit. */ + /** + * Stops the stream and carries on by post-then-edit: the next edit writes + * the part's whole known text, the chunk that failed included. + */ const repair = (part: Current): Effect.Effect => - Effect.flatMap( - stopStream(part, "rotating"), - (stopped) => - Effect.map(writeEdit(Math.max(part.uncertain, part.sent), false), () => { - if (stopped && isRunning()) { - finishPart(part.confirmed) - done(true) - } - }) - ) + Effect.flatMap(stopStream(part, "rotating"), (stopped) => { + part.attempted = -1 + if (!stopped) return Effect.void + // A user had clicked stop: settle what was sent, then end the reply. + return Effect.map(writeEdit(Math.max(part.uncertain, part.sent), false, false), () => { + if (!isRunning()) return + finishPart(part.confirmed) + done(true) + }) + }) const stepNative = (final: boolean): Effect.Effect => Effect.suspend(() => { const part = current if (part.posted === undefined) return startNative(final) - if (final || streamAge === undefined) return appendNative(final) - return Effect.flatMap(now, (time) => - time - part.startedAt >= ageShare * streamAge - ? rollNative(part, part.sent, false) - : appendNative(final)) + if (final || streamAge === undefined) return appendNative(final, false) + return Effect.flatMap(now, (time) => appendNative(final, time - part.startedAt >= ageShare * streamAge)) }) // --- overflow -------------------------------------------------------------- const stepOverflow = (final: boolean): Effect.Effect => Effect.suspend(() => { - const rest = input.slice(overflowStart!) + const start = overflowStart! + const rest = input.slice(start) if (isBlank(rest)) { - if (final) done(false) + if (final) finishReply(start) return Effect.void } if (overflow === "fail" || overflowBytes > limits.uploadBytes) { @@ -807,25 +894,34 @@ const reply = (options: ReplyOptions): Effect.Effect ({ + const part = (markdown: string) => (posted: Posted): Part => ({ messageId: posted.id, timestamp: posted.timestamp, - markdown: "", + markdown, text: rest, kind: "overflowFile", transport: "post" }) - return Effect.map(create(chat.post(thread, { markdown: "", files: [file] }), part), (exit) => { - if (Exit.isSuccess(exit)) { - parts.push(part(exit.value)) - overflowStart = input.length - return done(false) - } - const error = firstError(exit) - if (error === undefined) return - overflowUncertain = error.retry === "uncertain" - failChat(error) - }) + // The consumer's files go with the last message, which is this one. + const attempt = (markdown: string, files: ReadonlyArray, fallback: boolean) => + create(chat.post(thread, { markdown, files: [file, ...files] }), part(markdown), (exit) => { + if (Exit.isSuccess(exit)) { + parts.push(part(markdown)(exit.value)) + overflowStart = input.length + return done(false) + } + if (fallback && isFileRefusal(exit)) return + const error = firstError(exit) + if (error === undefined) return + overflowUncertain = error.retry === "uncertain" + failChat(error) + }) + const files = options.files ?? [] + const unattachedNote = files.length === 0 ? undefined : options.unattachedNote + return Effect.flatMap(attempt("", files, unattachedNote !== undefined), (exit) => + unattachedNote !== undefined && isFileRefusal(exit) + ? Effect.asVoid(attempt(unattachedNote(files).trim(), [], false)) + : Effect.void) }) // --- the loop -------------------------------------------------------------- @@ -953,10 +1049,14 @@ const reply = (options: ReplyOptions): Effect.Effect( * - Text that outgrows a message rolls over into a new one at a block * boundary, and each new message counts against `maxParts`. A native stream * rolls over at the next block boundary past 85% of `limits.streamLength`, - * and rotates once it is 80% of `limits.streamAge` old. + * and rotates once it is 80% of `limits.streamAge` old. Every append leaves + * room to close the code fence it ends in, and a rollover or rotation closes + * it. * - Writes are paced by `minWriteInterval`, on `Clock`. The next write is * scheduled only after the previous one returns, and takes all the text that * arrived meanwhile. @@ -1010,8 +1112,10 @@ export const post = ( * - A native append that fails `retry` is tried again after its * `retryAfter`, or the write interval, whether or not new text arrived. * Three in a row, or one `uncertain` failure, stop the stream, edit the part - * to its whole known text and carry on by post-then-edit. `TooLarge` starts - * the next part with the chunk. + * to its whole known text, the failed chunk included, and carry on by + * post-then-edit. `TooLarge` starts the next part with the chunk. + * - An append in flight finishes before an interrupt takes effect, so the + * finalizer never sends its text twice. * - `Result.stopped` is true when a user clicked stop on the reply. The * upstream is then interrupted. * - When the upstream fails or the call is interrupted, what was received is @@ -1027,9 +1131,9 @@ export const post = ( * leaves only the ids collected through `onPart`. * - Native writes go to the adapter through the `Registry`, so a layer that * wraps `Chat` does not see them. - * - A native part that is rolled over on `TooLarge` or rotated on age can end - * inside an open code fence, since it can no longer be appended to. The next - * part reopens the fence. + * - A native part that is rolled over on `TooLarge` can end inside an open + * code fence, since it can no longer be appended to. The next part reopens + * the fence. * - Post-then-edit needs the `edit` capability. * * @stability unstable diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts index 50e3f3da5cb..6fc0ec9c3c4 100644 --- a/packages/effect/test/chat/ChatMarkdown.test.ts +++ b/packages/effect/test/chat/ChatMarkdown.test.ts @@ -1,5 +1,5 @@ import { assert, describe, it } from "@effect/vitest" -import { type Cause, Duration, Effect, Fiber, Queue, Stream } from "effect" +import { type Cause, Deferred, Duration, Effect, Fiber, Queue, Stream } from "effect" import { ChatError, ChatMarkdown, ChatTest } from "effect/chat" import type { ChatThread } from "effect/chat" import { TestClock } from "effect/testing" @@ -186,6 +186,55 @@ describe("ChatMarkdown", () => { assert.deepStrictEqual([error.posted, error.remaining], [[], "Report"]) }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("fails when the text is refused, not the files", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + yield* test.failNext("post", new ChatError.TooLarge({ detail: "msg_blocks_too_long" }), { times: 2 }) + const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", { + files, + unattachedNote: () => " (file not attached)" + })) + assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "TooLarge") + assert.deepStrictEqual([error.posted, error.uncertain, error.remaining], [[], undefined, "Report"]) + assert.deepStrictEqual(yield* texts(test, thread), []) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("does not retry without the files for a failure unrelated to them", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + yield* test.failNext("post", new ChatError.NotFound({ detail: "channel_not_found" })) + const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", { + files, + unattachedNote: () => " (file not attached)" + })) + assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "NotFound") + assert.strictEqual((yield* test.calls).filter((call) => call.op === "post").length, 1) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("keeps the files and blank text that follow the last cut", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const input = "abcde\n\n" + const result = yield* ChatMarkdown.post(thread, input, { files }) + assert.deepStrictEqual(result.parts.map((part) => [part.markdown, part.text]), [["abcde", input]]) + const messages = yield* test.messages(thread) + assert.deepStrictEqual(messages.map((message) => message.attachments.length), [1]) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 5 } })))) + + it.effect("sends the files with the overflow file", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const input = paragraphs(5, 20) + const result = yield* ChatMarkdown.post(thread, input, { + files, + maxParts: 2, + overflow: { file: { name: "rest.md" } } + }) + assert.strictEqual(joined(result.parts), input) + const last = (yield* test.messages(thread)).at(-1)! + assert.deepStrictEqual(last.attachments.map((attachment) => attachment.name), ["rest.md", "a.txt"]) + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + it.effect("reports the text of an uncertain post as uncertain", () => Effect.gen(function*() { const { test, thread } = yield* setup @@ -438,6 +487,86 @@ describe("ChatMarkdown", () => { assert.deepStrictEqual(yield* texts(test, thread), ["```ts\ncode\n```"]) }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("does not post again when interrupted while onPart runs", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const entered = yield* Deferred.make() + const release = yield* Deferred.make() + const { fiber, send } = yield* feed(thread, { + recipient: "U1", + onPart: () => Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)) + }) + yield* send("hello\n") + yield* Deferred.await(entered) + const interrupt = yield* Effect.forkChild(Fiber.interrupt(fiber)) + yield* settle + yield* Deferred.succeed(release, undefined) + yield* Fiber.join(interrupt) + assert.deepStrictEqual(yield* texts(test, thread), ["hello\n"]) + const ops = (yield* test.calls).map((call) => call.op) + assert.deepStrictEqual(ops.filter((op) => op === "nativeStream.start").length, 1) + assert.include(ops, "nativeStream.stop") + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("repairs with the retried chunk while the upstream is paused", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.RateLimited({ retryAfter: Duration.millis(100) }), { + times: 3 + }) + yield* send("two\n") + yield* TestClock.adjust("200 millis") + yield* settle + const ops = (yield* test.calls).map((call) => call.op) + assert.strictEqual(ops.filter((op) => op === "nativeStream.append").length, 3) + assert.include(ops, "nativeStream.stop") + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("partitions an uncertain repair followed by a denied edit", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { fiber, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.Unknown({}), { landed: true }) + yield* test.failNext("edit", new ChatError.Unknown({}), { landed: true }) + yield* send("two\n") + yield* test.failNext("edit", new ChatError.Forbidden({})) + yield* send("three\n") + const error = yield* Effect.flip(Fiber.join(fiber)) + assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", "two\n", "three\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("leaves room in a native stream to close a code fence", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("~~~\n") + yield* send("a".repeat(16)) + const result = yield* end + assert.strictEqual(joined(result.parts), "~~~\n" + "a".repeat(16)) + const messages = yield* texts(test, thread) + assert.isTrue(messages.length > 1) + for (const message of messages) { + assert.isTrue(message.endsWith("\n~~~"), message) + assert.isAtMost(codePoints(message), 20) + } + }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 20 } })))) + + it.effect("closes a code fence before rotating on age", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("```ts\none\n") + yield* TestClock.adjust("9 minutes") + yield* send("two\n") + const result = yield* end + assert.deepStrictEqual(result.parts.map((part) => part.text), ["```ts\none\n", "two\n"]) + assert.deepStrictEqual(yield* texts(test, thread), ["```ts\none\n```", "```ts\ntwo\n```"]) + }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("rotates a native stream on age", () => Effect.gen(function*() { const { test, thread } = yield* setup From 6e956b6e5ab93c8b21a05dbb24efcb04e8d10033 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 17:58:07 +0000 Subject: [PATCH 06/89] Fix ChatMarkdown interruption findings and TooLarge file fallback - Run posts, starts and appends in a fiber of their own that commits its answer. An interrupt waits for it within the finish timeout, and only the timeout cuts it off, recording its text as uncertain. - Record a pending stop, rollover or repair in the reply state, so the finalizer resumes it after an interrupt. A stop cut off is sent again. - Add TooLarge.subject so an adapter can say the files were too large. The unattachedNote fallback retries a TooLarge only for subject files, and a text refusal fails the reply as settled in EFF-3689. --- packages/effect/src/chat/ChatAdapter.ts | 6 +- packages/effect/src/chat/ChatError.ts | 8 +- packages/effect/src/chat/ChatMarkdown.ts | 321 ++++++++++-------- packages/effect/src/chat/ChatTest.ts | 27 +- .../effect/test/chat/ChatMarkdown.test.ts | 131 ++++++- 5 files changed, 345 insertions(+), 148 deletions(-) diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts index 587279f0335..ad5ec038e98 100644 --- a/packages/effect/src/chat/ChatAdapter.ts +++ b/packages/effect/src/chat/ChatAdapter.ts @@ -319,7 +319,11 @@ export const checkMessageLength = ( markdown: string ): Effect.Effect => descriptor.measure(markdown) <= descriptor.limits.messageLength ? Effect.void : Effect.fail( - new ChatError({ platform: descriptor.platform, op, reason: new TooLarge({ detail: "message_too_long" }) }) + new ChatError({ + platform: descriptor.platform, + op, + reason: new TooLarge({ subject: "text", detail: "message_too_long" }) + }) ) const maxRetries = 3 diff --git a/packages/effect/src/chat/ChatError.ts b/packages/effect/src/chat/ChatError.ts index 75ebced7ba4..8de08217a80 100644 --- a/packages/effect/src/chat/ChatError.ts +++ b/packages/effect/src/chat/ChatError.ts @@ -351,13 +351,19 @@ export class NotFound extends Schema.TaggedError("effect/chat/ChatErro * * **Details** * - * Retry value `denied`. + * - Retry value `denied`. + * - `subject` says what was too large, when the adapter can tell: `text` for + * the message text, `files` for the files sent with it. An adapter sets it + * on every refusal of `post`, `edit` and `NativeStream` it can attribute. + * `ChatMarkdown` posts again without the files, ending in the consumer's + * note, only for `files`. * * @stability unstable * @category errors * @since 4.1.5 */ export class TooLarge extends Schema.TaggedError("effect/chat/ChatError/TooLarge")("TooLarge", { + subject: Schema.optionalKey(Schema.Literals(["text", "files"])), detail, cause }) { diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts index d012ca3e653..2d0e1526753 100644 --- a/packages/effect/src/chat/ChatMarkdown.ts +++ b/packages/effect/src/chat/ChatMarkdown.ts @@ -145,8 +145,8 @@ export class ChatMarkdownError extends Data.TaggedError("ChatMarkdown * - `minWriteInterval` is the floor between two writes. It defaults to the * adapter's `limits.minWriteInterval`. * - `onPart` runs for every message the call creates, the overflow file - * included, uninterruptibly with its post, so an interrupt can neither lose - * an id nor post the message twice. It has to be quick. + * included, uninterruptibly once its post returns, so an interrupt can + * neither lose an id nor post the message twice. It has to be quick. * * @stability unstable * @category models @@ -356,6 +356,15 @@ interface Current { markdown: string startedAt: number retries: number + /** A stop to send, and what follows it. Kept until the platform answers, so a stop cut off is sent again. */ + closing: Closing | undefined + /** A user clicked stop during a repair: the part is written up to here, then the reply ends. */ + stoppedAt: number | undefined +} + +interface Closing { + readonly end: "done" | "rotating" + readonly onStop: (stopped: boolean) => void } interface ReplyOptions extends Options { @@ -373,18 +382,24 @@ interface ReplyOptions extends Options { const firstError = (exit: Exit.Exit): ChatError | undefined => Option.getOrUndefined(Exit.findErrorOption(exit)) +/** Whether a write was cut off before the platform answered. */ +const unanswered = (exit: Exit.Exit): boolean => + Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause) + /** - * Whether a post with files may have failed because of the files. No reason - * says which part was refused, so a post that fails like this is tried again - * without them. A refusal of the text comes back again and fails the call. + * Whether a post with files may have failed because of the files, so it is + * tried again without them. A `TooLarge` counts only when the adapter says + * the files were too large: a refusal of text that measured as fitting fails + * the reply. */ const isFileRefusal = (exit: Exit.Exit): boolean => { const reason = firstError(exit)?.reason switch (reason?._tag) { case "Forbidden": - case "TooLarge": case "InvalidRequest": return true + case "TooLarge": + return reason.subject === "files" case "Unsupported": return reason.capability === "files" default: @@ -445,7 +460,9 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect Effect.sync(() => void (lastWrite = time))) /** - * Writes after the floor. \`commit\` records the result before an interrupt - * can land, so the finalizer never sees a write that happened as one that - * did not. With \`whole\`, the write itself is uninterruptible too: an - * append interrupted in flight could have landed, and sending it again - * would repeat text. Edits and stops are safe to repeat. + * Sends an edit or a stop after the floor. Both are safe to send again, so + * they stay interruptible. `commit` records the answer, or that there was + * none, before an interrupt can land. */ const write = ( effect: Effect.Effect, - commit: (exit: Exit.Exit) => void, - whole: boolean - ): Effect.Effect> => + commit: (exit: Exit.Exit) => void + ): Effect.Effect => Effect.andThen( pace, Effect.uninterruptibleMask((restore) => - Effect.exit(whole ? effect : restore(effect)).pipe( + Effect.exit(restore(effect)).pipe( Effect.ensuring(wrote), - Effect.tap((exit) => Effect.sync(() => commit(exit))) + Effect.flatMap((exit) => Effect.sync(() => commit(exit))) ) ) ) + /** The post, start or append in flight. */ + let inflight: Fiber.Fiber | undefined + /** - * Creates a message, records it and runs \`onPart\` for it, as one - * uninterruptible step, so an interrupt can neither lose an id nor make - * the finalizer create the message again. + * Sends a post, a start or an append after the floor. Sending one again + * could repeat text, so an interrupt of the reply does not cut it off: it + * runs in a fiber of its own, which commits the answer, and the finalizer + * waits for it. Only the finish timeout cuts it off, and `commit` then + * records that there was no answer. */ - const create = ( - effect: Effect.Effect, - part: (posted: Posted) => Part, - commit: (exit: Exit.Exit, time: number) => void - ): Effect.Effect, never, R2> => + const send = ( + effect: Effect.Effect, + commit: (exit: Exit.Exit, time: number) => Effect.Effect + ): Effect.Effect, never, R2> => Effect.andThen( pace, - Effect.uninterruptible( - Effect.exit(effect).pipe( - Effect.ensuring(wrote), - Effect.tap((exit) => - Effect.flatMap(now, (time) => { - commit(exit, time) - return Exit.isSuccess(exit) ? onPart(part(exit.value)) : Effect.void - }) + Effect.uninterruptibleMask((restore) => + Effect.forkChild( + Effect.uninterruptibleMask((restoreRequest) => + Effect.exit(restoreRequest(effect)).pipe( + Effect.ensuring(wrote), + Effect.tap((exit) => Effect.flatMap(now, (time) => commit(exit, time))), + Effect.ensuring(Effect.sync(() => void (inflight = undefined))) + ) ) - ) + ).pipe(Effect.flatMap((fiber) => { + inflight = fiber + return restore(Fiber.join(fiber)) + })) ) ) + /** + * Creates a message, records it and runs `onPart` for it, in one commit, + * so an interrupt can neither lose an id nor make the finalizer create the + * message again. + */ + const create = ( + effect: Effect.Effect, + part: (posted: Posted) => Part, + commit: (exit: Exit.Exit, time: number) => void + ): Effect.Effect, never, R2> => + send(effect, (exit, time) => { + commit(exit, time) + return Exit.isSuccess(exit) ? onPart(part(exit.value)) : Effect.void + }) + const finishPart = (end: number) => { const part = current parts.push(toPart(part, part.posted!, part.markdown, end)) @@ -544,8 +580,8 @@ const reply = (options: ReplyOptions): Effect.Effect => Effect.suspend(() => { @@ -555,17 +591,19 @@ const reply = (options: ReplyOptions): Effect.Effect { + return write(last ? edit : Chat.withoutRetries(edit), (exit) => { if (Exit.isSuccess(exit)) { part.confirmed = part.uncertain = end part.markdown = markdown return } + // Cut off, so it may have landed. The finalizer edits again. + if (unanswered(exit)) part.uncertain = Math.max(part.uncertain, end) const error = firstError(exit) if (error === undefined) return if (error.retry === "uncertain") part.uncertain = Math.max(part.uncertain, end) if (last || error.retry === "denied") failChat(error) - }, false)) + }) }) const postPart = ( @@ -583,6 +621,7 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect { if (unattachedNote === undefined || !isFileRefusal(exit)) return Effect.void // The platform may have refused the files: the last part goes out without them, ending in the note. - // A refusal of the text itself comes back again, and fails the call. const text = unattachedNote(files!) if (measure(markdown + text) <= limits.messageLength) { return Effect.asVoid(attempt(markdown + text, undefined, false)) @@ -639,6 +677,14 @@ const reply = (options: ReplyOptions): Effect.Effect => Effect.suspend(() => { const part = current + if (part.stoppedAt !== undefined) { + // A user clicked stop during a repair: settle what was sent, then end the reply. + return Effect.map(writeEdit(part.stoppedAt, false, false), () => { + if (!isRunning()) return + finishPart(part.confirmed) + done(true) + }) + } const body = input.slice(part.start) if (part.posted === undefined && isBlank(body) && !(final && hasFiles && parts.length === 0)) { if (final) finishReply(part.start) @@ -668,24 +714,41 @@ const reply = (options: ReplyOptions): Effect.Effect => - Effect.suspend(() => { + /** Sends the stop the current part is closing with. A stop carries no text, so its failures are ignored. */ + const sendStop = (part: Current, closing: Closing): Effect.Effect => + write(native!.stop(thread, part.posted!.id, { end: closing.end }), (exit) => { + // Cut off, so the stream may still be open. The finalizer sends the stop again. + if (unanswered(exit)) return + part.closing = undefined part.native = false - if (part.posted === undefined) return Effect.succeed(false) - return Effect.map( - write(native!.stop(thread, part.posted.id, { end }), () => {}, false), - (exit) => Exit.isSuccess(exit) && exit.value.stopped - ) + closing.onStop(Exit.isSuccess(exit) && exit.value.stopped) }) - /** Ends a native part at \`end\`. The reply ends when \`last\`, or when a user had clicked stop. */ - const rollNative = (part: Current, end: number, last: boolean): Effect.Effect => - Effect.map(stopStream(part, last ? "done" : "rotating"), (stopped) => { - finishPart(end) - if (stopped) done(true) - else if (last) finishReply(end) - }) + /** Ends a native part at `end` once its stop is answered. The reply ends when `last`, or when a user had clicked stop. */ + const rollNative = (part: Current, end: number, last: boolean) => { + part.closing = { + end: last ? "done" : "rotating", + onStop: (stopped) => { + finishPart(end) + if (stopped) done(true) + else if (last) finishReply(end) + } + } + } + + /** + * Stops the stream and carries on by post-then-edit: the next edit writes + * the part's whole known text, the chunk that failed included. + */ + const repair = (part: Current) => { + part.closing = { + end: "rotating", + onStop: (stopped) => { + part.attempted = -1 + if (stopped) part.stoppedAt = Math.max(part.uncertain, part.sent) + } + } + } const startNative = (final: boolean): Effect.Effect => Effect.suspend(() => { @@ -705,7 +768,7 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect Exit.isSuccess(exit) && (roll || final) ? rollNative(part, end, !roll) : Effect.void + ) ) }) /** * What the next append sends, and whether the part ends after it. Every * append leaves room to close the code fence it ends in, so a part that - * rolls over on length always ends with its fence closed. \`rotate\` sends + * rolls over on length always ends with its fence closed. `rotate` sends * just that closing fence, for a stream about to rotate on age. */ const nextAppend = (part: Current, final: boolean, rotate: boolean) => { @@ -770,20 +834,24 @@ const reply = (options: ReplyOptions): Effect.Effect => Effect.suspend(() => { const part = current const { extra, piece, roll } = nextAppend(part, final, rotate) if (piece === "" && extra === "") { - return roll || final ? rollNative(part, part.sent, !roll) : Effect.void + if (roll || final) rollNative(part, part.sent, !roll) + return Effect.void } part.attempted = input.length const markdown = piece + extra - let next: { readonly _tag: "None" | "Roll" | "Repair" | "StopAndFail" } | { - readonly _tag: "Retry" - readonly wait: number - } = { _tag: "None" } - const commit = (exit: Exit.Exit<{ readonly state: string; readonly held: number }, ChatError>) => { + const commit = ( + exit: Exit.Exit<{ readonly state: string; readonly held: number }, ChatError>, + time: number + ) => { if (Exit.isSuccess(exit)) { const { held, state } = exit.value if (state === "stopped") { @@ -799,69 +867,40 @@ const reply = (options: ReplyOptions): Effect.Effect= appendRetryLimit) repair(part) + else retryAt = time + (error.retryAfter === undefined ? interval : Duration.toMillis(error.retryAfter)) + } else if (error.retry === "uncertain") { + part.uncertain = part.sent + piece.length + repair(part) } else { - const error = firstError(exit) - if (error === undefined) { - // Interrupted before the append ran. - } else if (error.reason._tag === "TooLarge") { - next = { _tag: "Roll" } - } else if (error.retry === "retry") { - part.retries++ - next = part.retries >= appendRetryLimit - ? { _tag: "Repair" } - : { - _tag: "Retry", - wait: error.retryAfter === undefined ? interval : Duration.toMillis(error.retryAfter) - } - } else if (error.retry === "uncertain") { - part.uncertain = part.sent + piece.length - next = { _tag: "Repair" } - } else { - failChat(error) - next = { _tag: "StopAndFail" } - } + failChat(error) + part.closing = { end: "done", onStop: () => {} } } } - return Effect.flatMap( - write(native!.append(thread, part.posted!.id, markdown, { flush: final || roll }), commit, true), - (exit): Effect.Effect => { - switch (next._tag) { - case "None": - return Effect.void - case "Roll": - // A TooLarge forces a rollover; the next part starts with the chunk. - return rollNative(part, part.sent, Exit.isSuccess(exit) && !roll) - case "Repair": - return repair(part) - case "StopAndFail": - return Effect.asVoid(stopStream(part, "done")) - case "Retry": { - const wait = next.wait - return Effect.flatMap(now, (time) => Effect.sync(() => void (retryAt = time + wait))) - } - } - } + return Effect.asVoid( + send( + native!.append(thread, part.posted!.id, markdown, { flush: final || roll }), + (exit, time) => Effect.sync(() => commit(exit, time)) + ) ) }) - /** - * Stops the stream and carries on by post-then-edit: the next edit writes - * the part's whole known text, the chunk that failed included. - */ - const repair = (part: Current): Effect.Effect => - Effect.flatMap(stopStream(part, "rotating"), (stopped) => { - part.attempted = -1 - if (!stopped) return Effect.void - // A user had clicked stop: settle what was sent, then end the reply. - return Effect.map(writeEdit(Math.max(part.uncertain, part.sent), false, false), () => { - if (!isRunning()) return - finishPart(part.confirmed) - done(true) - }) - }) - const stepNative = (final: boolean): Effect.Effect => Effect.suspend(() => { const part = current @@ -911,6 +950,7 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect isRunning() || current.closing !== undefined + const hasWork = (): boolean => { - if (!isRunning() || upstream !== undefined) return true + if (!isRunning() || upstream !== undefined || current.closing !== undefined) return true if (overflowStart !== undefined) { return !isBlank(input.slice(overflowStart)) && (overflow === "fail" || overflowBytes > limits.uploadBytes) } @@ -952,14 +995,17 @@ const reply = (options: ReplyOptions): Effect.Effect => { + const closing = current.closing + if (closing !== undefined) return sendStop(current, closing) if (overflowStart !== undefined) return stepOverflow(final) return current.native ? stepNative(final) : stepEdit(final) } const loop: Effect.Effect = Effect.suspend(() => - isRunning() ? + active() ? Effect.flatMap(awaitWork, () => { - if (!isRunning() || (upstream !== undefined && Exit.isFailure(upstream))) return Effect.void + if (!active()) return Effect.void + if (current.closing === undefined && upstream !== undefined && Exit.isFailure(upstream)) return Effect.void // The write takes whatever arrived while it waited for the floor. return Effect.andThen(pace, Effect.suspend(() => step(upstream !== undefined))).pipe(Effect.andThen(loop)) }) : @@ -970,10 +1016,14 @@ const reply = (options: ReplyOptions): Effect.Effect = Effect.suspend(() => { finishing = true const drain: Effect.Effect = Effect.suspend(() => - isRunning() ? Effect.andThen(step(true), drain) : Effect.void + active() ? Effect.andThen(step(true), drain) : Effect.void + ) + // A write in flight commits first. Interruptible, so the timeout can cut it short in the interrupt finalizer. + const awaitInflight = Effect.suspend(() => inflight === undefined ? Effect.void : Fiber.await(inflight)) + return Effect.timeoutOption(Effect.interruptible(Effect.andThen(awaitInflight, drain)), finishTimeout).pipe( + Effect.andThen(Effect.suspend(() => inflight === undefined ? Effect.void : Fiber.interrupt(inflight))), + Effect.asVoid ) - // Interruptible, so the timeout can cut it short when it runs in the interrupt finalizer. - return Effect.asVoid(Effect.timeoutOption(Effect.interruptible(drain), finishTimeout)) }) const toError = (cause: FailureCause): ChatMarkdownError => { @@ -1052,11 +1102,13 @@ const reply = (options: ReplyOptions): Effect.Effect( * Three in a row, or one `uncertain` failure, stop the stream, edit the part * to its whole known text, the failed chunk included, and carry on by * post-then-edit. `TooLarge` starts the next part with the chunk. - * - An append in flight finishes before an interrupt takes effect, so the - * finalizer never sends its text twice. * - `Result.stopped` is true when a user clicked stop on the reply. The * upstream is then interrupted. * - When the upstream fails or the call is interrupted, what was received is * written out, with an open code fence closed, within a short timeout, and - * left posted. + * left posted. A post, start or append in flight is not cut off by the + * interrupt, since sending it again could repeat text: the finalizer waits + * for it, then sends what follows, a stop cut off by the interrupt + * included. Only the timeout cuts a write off. * * **Gotchas** * diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts index 9bfdd5ad2c6..e5ff7671468 100644 --- a/packages/effect/src/chat/ChatTest.ts +++ b/packages/effect/src/chat/ChatTest.ts @@ -411,7 +411,7 @@ const makeFake = (options: { yield* findThread("nativeStream.start", thread) yield* checkMessageLength(descriptor, "nativeStream.start", content.markdown) if (descriptor.measure(content.markdown) > streamLength()) { - return yield* fail("nativeStream.start", new TooLarge({ detail: "msg_too_long" })) + return yield* fail("nativeStream.start", new TooLarge({ subject: "text", detail: "msg_too_long" })) } let replyTo: ReplyTo | undefined if (content.replyTo !== undefined) { @@ -450,7 +450,7 @@ const makeFake = (options: { } const sent = markdown.slice(0, markdown.length - held) if (descriptor.measure(message.text + sent) > streamLength()) { - return yield* fail("nativeStream.append", new TooLarge({ detail: "msg_too_long" })) + return yield* fail("nativeStream.append", new TooLarge({ subject: "text", detail: "msg_too_long" })) } message.text += sent return { state: "open" as const, held } @@ -497,7 +497,7 @@ const makeFake = (options: { files.length > descriptor.limits.filesPerMessage || files.some((file) => file.content.length > descriptor.limits.uploadBytes) ) { - return yield* fail("post", new TooLarge({ detail: "file_too_large" })) + return yield* fail("post", new TooLarge({ subject: "files", detail: "file_too_large" })) } let replyTo: ReplyTo | undefined if (content.replyTo !== undefined) { @@ -1066,15 +1066,17 @@ class Tester { expectReason( tag: ChatErrorReason["_tag"], effect: Effect.Effect, - onSuccess?: (a: A) => void + onSuccess?: (a: A) => void, + refine?: { readonly expected: string; readonly test: (reason: ChatErrorReason) => boolean } ): Effect.Effect { return Effect.flatMap(Effect.exit(effect), (exit) => { if (Exit.isSuccess(exit)) onSuccess?.(exit.value) const error = Exit.findErrorOption(exit) - const matches = Option.isSome(error) && isChatError(error.value) && error.value.reason._tag === tag + const matches = Option.isSome(error) && isChatError(error.value) && error.value.reason._tag === tag && + (refine === undefined || refine.test(error.value.reason)) return matches ? Effect.void : Effect.fail(failure( this.rule, - tag, + refine === undefined ? tag : refine.expected, describeExit(exit), Option.getOrUndefined(error) )) @@ -1171,6 +1173,12 @@ const conformanceFile = (rule: string): File => ({ const findIn = (messages: ReadonlyArray, id: string) => messages.find((message) => message.id === id) +/** A refusal of the text must not blame the files, or `ChatMarkdown` would post again without them. */ +const textTooLarge = { + expected: "TooLarge without subject files", + test: (reason: ChatErrorReason) => reason._tag === "TooLarge" && reason.subject !== "files" +} + const mentionLike = "@everyone @here <@U0000> <@&1> <#C0000>" /** Text a platform takes in any quantity: no emoji, which Slack limits separately. */ @@ -1326,7 +1334,8 @@ export const conformance = (options: { t.expectReason( "TooLarge", t.chat.post(t.thread, { markdown: "x".repeat(t.descriptor.limits.messageLength + 1) }), - (posted) => t.created.push({ thread: t.thread, id: posted.id }) + (posted) => t.created.push({ thread: t.thread, id: posted.id }), + textTooLarge )) rule("descriptor/measureFits", [], (t) => @@ -1402,7 +1411,9 @@ export const conformance = (options: { Effect.flatMap(t.post({}), (posted) => t.expectReason( "TooLarge", - t.chat.edit(t.thread, posted.id, { markdown: "x".repeat(t.descriptor.limits.messageLength + 1) }) + t.chat.edit(t.thread, posted.id, { markdown: "x".repeat(t.descriptor.limits.messageLength + 1) }), + undefined, + textTooLarge ))) rule("delete/gone", ["delete", "fetchMessage"], (t) => diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts index 6fc0ec9c3c4..8354c74e1eb 100644 --- a/packages/effect/test/chat/ChatMarkdown.test.ts +++ b/packages/effect/test/chat/ChatMarkdown.test.ts @@ -1,6 +1,6 @@ import { assert, describe, it } from "@effect/vitest" import { type Cause, Deferred, Duration, Effect, Fiber, Queue, Stream } from "effect" -import { ChatError, ChatMarkdown, ChatTest } from "effect/chat" +import { Chat, ChatAdapter, ChatError, ChatMarkdown, ChatTest } from "effect/chat" import type { ChatThread } from "effect/chat" import { TestClock } from "effect/testing" @@ -30,8 +30,9 @@ const feed = Effect.fnUntraced(function*( const queue = yield* Queue.unbounded() const fiber = yield* Effect.forkChild(ChatMarkdown.stream(thread, Stream.fromQueue(queue), options)) const send = (chunk: string) => Effect.andThen(Queue.offer(queue, chunk), settle) + const close = Effect.andThen(Queue.end(queue), settle) const end = Effect.andThen(Queue.end(queue), Fiber.join(fiber)) - return { fiber, send, end } + return { fiber, send, close, end } }) const lone = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(? { assert.deepStrictEqual([error.posted, error.remaining], [[], "Report"]) }).pipe(Effect.provide(ChatTest.layer()))) - it.effect("fails when the text is refused, not the files", () => + it.effect("fails on a TooLarge that does not blame the files", () => Effect.gen(function*() { const { test, thread } = yield* setup - yield* test.failNext("post", new ChatError.TooLarge({ detail: "msg_blocks_too_long" }), { times: 2 }) + yield* test.failNext("post", new ChatError.TooLarge({ detail: "msg_blocks_too_long" })) const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", { files, unattachedNote: () => " (file not attached)" })) assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "TooLarge") assert.deepStrictEqual([error.posted, error.uncertain, error.remaining], [[], undefined, "Report"]) + assert.strictEqual((yield* test.calls).filter((call) => call.op === "post").length, 1) assert.deepStrictEqual(yield* texts(test, thread), []) }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("ends in the unattached note when the files are too large", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + yield* test.failNext("post", new ChatError.TooLarge({ subject: "files", detail: "file_too_large" })) + const result = yield* ChatMarkdown.post(thread, "Report", { + files, + unattachedNote: () => " (file not attached)" + }) + assert.deepStrictEqual(result.parts.map((part) => part.markdown), ["Report (file not attached)"]) + }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("does not retry without the files for a failure unrelated to them", () => Effect.gen(function*() { const { test, thread } = yield* setup @@ -608,5 +621,115 @@ describe("ChatMarkdown", () => { assert.strictEqual(error.cause._tag, "Overflow") assert.strictEqual(joined(error.posted) + error.remaining, input) }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } })))) + + /** Registers the test adapter with its native stream changed by `f`. */ + const patchNative = Effect.fnUntraced(function*( + f: (native: ChatAdapter.NativeStream) => Partial + ) { + const test = yield* ChatTest.ChatTest + const registry = yield* ChatAdapter.Registry + const adapter = yield* registry.get(test.platform) + const native = adapter.nativeStream! + yield* registry.register({ ...adapter, nativeStream: { ...native, ...f(native) } }) + }) + + it.effect("sends a stop again when interrupted during it", () => + Effect.gen(function*() { + const { thread } = yield* setup + const chat = yield* Chat.Chat + const entered = yield* Deferred.make() + let first = true + yield* patchNative((native) => ({ + stop: (...args) => + Effect.suspend(() => { + if (!first) return native.stop(...args) + first = false + return Effect.andThen(Deferred.succeed(entered, undefined), Effect.never) + }) + })) + const ids: Array = [] + const { close, fiber, send } = yield* feed(thread, { + recipient: "U1", + onPart: (part) => Effect.sync(() => void ids.push(part.messageId)) + }) + yield* send("hello\n") + yield* close + yield* Deferred.await(entered) + yield* Fiber.interrupt(fiber) + yield* chat.edit(thread, ids[0], { markdown: "edited" }) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("keeps a rollover due after an append that was in flight when interrupted", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const entered = yield* Deferred.make() + const release = yield* Deferred.make() + let first = true + yield* patchNative((native) => ({ + append: (...args) => + Effect.tap(native.append(...args), () => { + if (!first) return Effect.void + first = false + return Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)) + }) + })) + const { fiber, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("~~~\none\n") + yield* TestClock.adjust("9 minutes") + yield* send("two\n") + yield* Deferred.await(entered) + const interrupt = yield* Effect.forkChild(Fiber.interrupt(fiber)) + yield* settle + yield* Deferred.succeed(release, undefined) + yield* Fiber.join(interrupt) + assert.deepStrictEqual(yield* texts(test, thread), ["~~~\none\n~~~", "~~~\ntwo\n~~~"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("bounds an append in the interrupt finalizer by the finish timeout", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const entered = yield* Deferred.make() + yield* patchNative((native) => ({ + append: (...args) => + Effect.andThen(Deferred.succeed(entered, undefined), Effect.andThen(Effect.never, native.append(...args))) + })) + const { fiber, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("~~~\ncode") + const interrupt = yield* Effect.forkChild(Fiber.interrupt(fiber)) + yield* Deferred.await(entered) + yield* TestClock.adjust("6 seconds") + yield* Fiber.join(interrupt) + // The closing fence was cut off with the append. + assert.deepStrictEqual(yield* texts(test, thread), ["~~~\ncode"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("waits for an append in flight when interrupted, then finishes the reply", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const entered = yield* Deferred.make() + const release = yield* Deferred.make() + let first = true + yield* patchNative((native) => ({ + append: (...args) => + Effect.suspend(() => { + if (!first) return native.append(...args) + first = false + return Effect.andThen( + Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)), + native.append(...args) + ) + }) + })) + const { fiber, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* send("two\n") + yield* Deferred.await(entered) + yield* send("three") + const interrupt = yield* Effect.forkChild(Fiber.interrupt(fiber)) + yield* settle + yield* Deferred.succeed(release, undefined) + yield* Fiber.join(interrupt) + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree"]) + }).pipe(Effect.provide(ChatTest.layer()))) }) }) From fb9c548f5a648f7aaaf41a72d7a1d2eb7c50268e Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 18:07:14 +0000 Subject: [PATCH 07/89] Start the finish timeout when the upstream fails during a write Write fibers now live in a scope owned by the reply rather than the loop, and a failed upstream ends the loop at once. The finish timeout then starts while the write is still in flight: its answer is kept if it arrives in time, and its text is reported as uncertain if the timeout cuts it off. --- packages/effect/src/chat/ChatMarkdown.ts | 38 +++++--- .../effect/test/chat/ChatMarkdown.test.ts | 97 +++++++++++++++++++ 2 files changed, 123 insertions(+), 12 deletions(-) diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts index 2d0e1526753..3fef76f07fd 100644 --- a/packages/effect/src/chat/ChatMarkdown.ts +++ b/packages/effect/src/chat/ChatMarkdown.ts @@ -32,6 +32,7 @@ import * as Exit from "../Exit.ts" import * as Fiber from "../Fiber.ts" import * as Latch from "../Latch.ts" import * as Option from "../Option.ts" +import * as Scope from "../Scope.ts" import * as Stream from "../Stream.ts" import * as Chat from "./Chat.ts" import type { Descriptor, File, NativeStream, Posted } from "./ChatAdapter.ts" @@ -420,6 +421,10 @@ const reply = (options: ReplyOptions): Effect.Effect Effect.void) const native = options.native const latch = Latch.makeUnsafe(false) + /** Opens when the upstream fails, which ends the loop even while a write is in flight. */ + const upstreamFailed = Latch.makeUnsafe(false) + /** Holds the write fibers, so they outlive the loop and the finalizer can wait for them. */ + const writes = Scope.makeUnsafe() let input = options.initial let upstream: Exit.Exit | undefined = options.deltas === undefined ? Exit.void : undefined @@ -515,10 +520,11 @@ const reply = (options: ReplyOptions): Effect.Effect( effect: Effect.Effect, @@ -527,14 +533,15 @@ const reply = (options: ReplyOptions): Effect.Effect - Effect.forkChild( + Effect.forkIn( Effect.uninterruptibleMask((restoreRequest) => Effect.exit(restoreRequest(effect)).pipe( Effect.ensuring(wrote), Effect.tap((exit) => Effect.flatMap(now, (time) => commit(exit, time))), Effect.ensuring(Effect.sync(() => void (inflight = undefined))) ) - ) + ), + writes ).pipe(Effect.flatMap((fiber) => { inflight = fiber return restore(Fiber.join(fiber)) @@ -1063,12 +1070,17 @@ const reply = (options: ReplyOptions): Effect.Effect { upstream = exit latch.openUnsafe() + if (Exit.isFailure(exit)) upstreamFailed.openUnsafe() }) ) return Effect.gen(function*() { const fiber = yield* Effect.forkChild(consume) - yield* Effect.onInterrupt(loop, () => Effect.andThen(Fiber.interrupt(fiber), finish)) + // A failed upstream ends the loop at once, so the finish timeout starts even while a write is in flight. + yield* Effect.onInterrupt( + Effect.raceFirst(loop, upstreamFailed.await), + () => Effect.andThen(Fiber.interrupt(fiber), finish) + ) yield* Fiber.interrupt(fiber) if (upstream !== undefined && Exit.isFailure(upstream) && (isRunning() || state._tag === "Done")) { const cause = upstream.cause @@ -1081,7 +1093,7 @@ const reply = (options: ReplyOptions): Effect.Effect( * upstream is then interrupted. * - When the upstream fails or the call is interrupted, what was received is * written out, with an open code fence closed, within a short timeout, and - * left posted. A post, start or append in flight is not cut off by the - * interrupt, since sending it again could repeat text: the finalizer waits - * for it, then sends what follows, a stop cut off by the interrupt - * included. Only the timeout cuts a write off. + * left posted. The timeout starts at once, even while a write is in + * flight. A post, start or append in flight is not cut off by the failure + * or the interrupt, since sending it again could repeat text: the finalizer + * waits for it, then sends what follows, a stop cut off by the interrupt + * included. Only the timeout cuts a write off, and its text is then + * reported as `uncertain`. * * **Gotchas** * diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts index 8354c74e1eb..e19cb8198c5 100644 --- a/packages/effect/test/chat/ChatMarkdown.test.ts +++ b/packages/effect/test/chat/ChatMarkdown.test.ts @@ -703,6 +703,103 @@ describe("ChatMarkdown", () => { assert.deepStrictEqual(yield* texts(test, thread), ["~~~\ncode"]) }).pipe(Effect.provide(ChatTest.layer()))) + /** Runs `stream` over a queue the test can fail. */ + const feedFailable = Effect.fnUntraced(function*(thread: ChatThread.ChatThread) { + const queue = yield* Queue.unbounded() + const fiber = yield* Effect.forkChild( + Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), { recipient: "U1" })) + ) + return { queue, fiber } + }) + + /** Holds the first append until `release` completes, and records whether it was cut off. */ + const holdFirstAppend = Effect.fnUntraced(function*() { + const entered = yield* Deferred.make() + const release = yield* Deferred.make() + const state = { cancelled: false } + let first = true + yield* patchNative((native) => ({ + append: (...args) => + Effect.suspend(() => { + if (!first) return native.append(...args) + first = false + return Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)).pipe( + Effect.andThen(native.append(...args)), + Effect.onInterrupt(() => Effect.sync(() => void (state.cancelled = true))) + ) + }) + })) + return { entered, release, state } + }) + + it.effect("bounds an append in flight when the upstream fails", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { entered, release, state } = yield* holdFirstAppend() + const { fiber, queue } = yield* feedFailable(thread) + yield* Queue.offer(queue, "one\n") + yield* settle + yield* Queue.offer(queue, "two\n") + yield* Deferred.await(entered) + yield* Queue.fail(queue, "boom") + yield* settle + yield* TestClock.adjust("6 seconds") + const finished = fiber.pollUnsafe() !== undefined + yield* Deferred.succeed(release, undefined) + const error = yield* Fiber.join(fiber) + assert.isTrue(finished) + assert.isTrue(state.cancelled) + assert.deepStrictEqual(error.cause, { _tag: "Upstream", error: "boom" }) + assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", "two\n", ""]) + yield* settle + assert.deepStrictEqual(yield* texts(test, thread), ["one\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("keeps the answer of an append in flight when the upstream fails", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { entered, release } = yield* holdFirstAppend() + const { fiber, queue } = yield* feedFailable(thread) + yield* Queue.offer(queue, "one\n") + yield* settle + yield* Queue.offer(queue, "two\n") + yield* Deferred.await(entered) + yield* Queue.offer(queue, "three") + yield* Queue.fail(queue, "boom") + yield* settle + yield* Deferred.succeed(release, undefined) + const error = yield* Fiber.join(fiber) + assert.deepStrictEqual(error.cause, { _tag: "Upstream", error: "boom" }) + assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], [ + "one\ntwo\nthree", + undefined, + "" + ]) + assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("bounds an append begun while finishing after the upstream fails", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const { entered, release, state } = yield* holdFirstAppend() + const { fiber, queue } = yield* feedFailable(thread) + yield* Queue.offer(queue, "one\n") + yield* settle + yield* Queue.offer(queue, "two") + yield* settle + yield* Queue.fail(queue, "boom") + yield* Deferred.await(entered) + yield* TestClock.adjust("6 seconds") + const finished = fiber.pollUnsafe() !== undefined + yield* Deferred.succeed(release, undefined) + const error = yield* Fiber.join(fiber) + assert.isTrue(finished) + assert.isTrue(state.cancelled) + assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", "two", ""]) + yield* settle + assert.deepStrictEqual(yield* texts(test, thread), ["one\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("waits for an append in flight when interrupted, then finishes the reply", () => Effect.gen(function*() { const { test, thread } = yield* setup From f6826f160c7ddec47ca9fad69c26f5a8985b03b5 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 18:15:48 +0000 Subject: [PATCH 08/89] Send a failed reply's pending stop when the upstream fails The upstream-failure race could cut off the stop that follows a denied append. The reply had already failed, so the finish was skipped and the native stream stayed open. The finish now runs for a pending stop or write in that case too, sending only the stop, within the finish timeout, and keeping the Chat error the reply failed with. --- packages/effect/src/chat/ChatMarkdown.ts | 4 + .../effect/test/chat/ChatMarkdown.test.ts | 101 ++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts index 3fef76f07fd..c998f386572 100644 --- a/packages/effect/src/chat/ChatMarkdown.ts +++ b/packages/effect/src/chat/ChatMarkdown.ts @@ -1089,6 +1089,10 @@ const reply = (options: ReplyOptions): Effect.Effect) state = { _tag: "Failed", cause: { _tag: "Upstream", error: error.value } } + } else if (current.closing !== undefined || inflight !== undefined) { + // The reply failed already, and the race cut off its stop or write. The finish sends only that stop, + // within the timeout, since a failed reply writes no more text, and keeps the error it failed with. + yield* finish } yield* Effect.annotateCurrentSpan("chat.markdown.transport", renderedNatively ? "native" : current.transport) if (state._tag === "Failed") return yield* Effect.fail(toError(state.cause)) diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts index e19cb8198c5..8a3db75490b 100644 --- a/packages/effect/test/chat/ChatMarkdown.test.ts +++ b/packages/effect/test/chat/ChatMarkdown.test.ts @@ -800,6 +800,107 @@ describe("ChatMarkdown", () => { assert.deepStrictEqual(yield* texts(test, thread), ["one\n"]) }).pipe(Effect.provide(ChatTest.layer()))) + /** Holds the first stop until `release` completes. */ + const holdFirstStop = Effect.fnUntraced(function*() { + const entered = yield* Deferred.make() + const release = yield* Deferred.make() + let first = true + yield* patchNative((native) => ({ + stop: (...args) => + Effect.suspend(() => { + if (!first) return native.stop(...args) + first = false + return Effect.andThen( + Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)), + native.stop(...args) + ) + }) + })) + return { entered, release } + }) + + for (const failUpstream of [false, true]) { + it.effect( + failUpstream + ? "stops the stream after a denied append when the upstream then fails" + : "stops the stream after a denied append", + () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const chat = yield* Chat.Chat + const { entered, release } = yield* holdFirstStop() + const queue = yield* Queue.unbounded() + const ids: Array = [] + const fiber = yield* Effect.forkChild(Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), { + recipient: "U1", + onPart: (part) => Effect.sync(() => void ids.push(part.messageId)) + }))) + yield* Queue.offer(queue, "one\n") + yield* settle + yield* test.failNext("nativeStream.append", new ChatError.Forbidden({})) + yield* Queue.offer(queue, "two\n") + yield* Deferred.await(entered) + if (failUpstream) yield* Queue.fail(queue, "boom") + yield* settle + yield* Deferred.succeed(release, undefined) + const error = yield* Fiber.join(fiber) + assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden") + assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], [ + "one\n", + undefined, + "two\n" + ]) + const ops = (yield* test.calls).map((call) => call.op) + assert.strictEqual(ops.filter((op) => op === "nativeStream.append").length, 1) + assert.deepStrictEqual(yield* texts(test, thread), ["one\n"]) + yield* chat.edit(thread, ids[0], { markdown: "edited" }) + }).pipe(Effect.provide(ChatTest.layer())) + ) + } + + it.effect("bounds the stop of a failed reply by the finish timeout when the upstream fails", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const entered = yield* Deferred.make() + yield* patchNative(() => ({ stop: () => Effect.andThen(Deferred.succeed(entered, undefined), Effect.never) })) + const queue = yield* Queue.unbounded() + const fiber = yield* Effect.forkChild( + Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), { recipient: "U1" })) + ) + yield* Queue.offer(queue, "one\n") + yield* settle + yield* test.failNext("nativeStream.append", new ChatError.Forbidden({})) + yield* Queue.offer(queue, "two\n") + yield* Deferred.await(entered) + yield* Queue.fail(queue, "boom") + yield* settle + yield* TestClock.adjust("6 seconds") + const error = yield* Fiber.join(fiber) + assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden") + assert.deepStrictEqual([joined(error.posted), error.remaining], ["one\n", "two\n"]) + }).pipe(Effect.provide(ChatTest.layer()))) + + it.effect("stops the stream after a denied append when interrupted during the stop", () => + Effect.gen(function*() { + const { test, thread } = yield* setup + const chat = yield* Chat.Chat + const { entered } = yield* holdFirstStop() + const ids: Array = [] + const { fiber, send } = yield* feed(thread, { + recipient: "U1", + onPart: (part) => Effect.sync(() => void ids.push(part.messageId)) + }) + yield* send("one\n") + yield* test.failNext("nativeStream.append", new ChatError.Forbidden({})) + yield* send("two\n") + yield* Deferred.await(entered) + yield* Fiber.interrupt(fiber) + const ops = (yield* test.calls).map((call) => call.op) + assert.strictEqual(ops.filter((op) => op === "nativeStream.append").length, 1) + assert.deepStrictEqual(yield* texts(test, thread), ["one\n"]) + yield* chat.edit(thread, ids[0], { markdown: "edited" }) + }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("waits for an append in flight when interrupted, then finishes the reply", () => Effect.gen(function*() { const { test, thread } = yield* setup From cdc70d2b809099dc07a81fb8172d55335d6cca3f Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 19:19:15 +0000 Subject: [PATCH 09/89] Add StopRequested to ChatEvent A user asking the bot to stop working in a thread, as Slack's stop button does. Its dedupe key is stop/{thread}/{id}, where id is the platform's id for the request (Slack's event_ts). --- packages/effect/src/chat/ChatEvent.ts | 41 ++++++++++++++++++++- packages/effect/src/chat/ChatTest.ts | 2 +- packages/effect/test/chat/ChatEvent.test.ts | 30 +++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 packages/effect/test/chat/ChatEvent.test.ts diff --git a/packages/effect/src/chat/ChatEvent.ts b/packages/effect/src/chat/ChatEvent.ts index 8dfc57a705c..4f9fa7666e1 100644 --- a/packages/effect/src/chat/ChatEvent.ts +++ b/packages/effect/src/chat/ChatEvent.ts @@ -124,6 +124,41 @@ export const ReactionRemoved = Schema.TaggedStruct("ReactionRemoved", reaction). */ export type ReactionRemoved = typeof ReactionRemoved.Type +/** + * Schema for a user asking the bot to stop working in a thread, as Slack's + * stop button does. + * + * **Details** + * + * - Nothing has been stopped. The streams in `messageIds` stay open and keep + * taking text until the consumer ends them, and the platform shows a + * disabled button until then. + * - `messageIds` is empty when no stream was open. + * - `id` is the platform's id for the request, Slack's `event_ts`. Two + * deliveries of one request share it. + * - It has no `kind`. + * + * @stability unstable + * @category schemas + * @since 4.1.5 + */ +export const StopRequested = Schema.TaggedStruct("StopRequested", { + thread: ChatThread.ChatThread, + id: Schema.String, + userId: Schema.String, + messageIds: Schema.Array(Schema.String), + raw: Schema.Json +}).annotate({ identifier: "ChatEvent.StopRequested" }) + +/** + * A user asking the bot to stop working in a thread. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export type StopRequested = typeof StopRequested.Type + /** * Schema for an inbound chat event. * @@ -136,7 +171,7 @@ export type ReactionRemoved = typeof ReactionRemoved.Type * @category schemas * @since 4.1.5 */ -export const ChatEvent = Schema.Union([MessageCreated, ReactionAdded, ReactionRemoved]).annotate({ +export const ChatEvent = Schema.Union([MessageCreated, ReactionAdded, ReactionRemoved, StopRequested]).annotate({ identifier: "ChatEvent" }) @@ -162,6 +197,8 @@ export type ChatEvent = typeof ChatEvent.Type * - A message is `message/{thread}/{id}`, with the thread in its * `{platform}:{id}` form. * - A reaction is `reaction/{messageId}/{userId}/{emoji}/{added|removed}`. + * - A stop request is `stop/{thread}/{id}`. + * - Slack's `message` and `app_mention` for one message share a key. * * @stability unstable * @category getters @@ -175,5 +212,7 @@ export const dedupeKey = (event: ChatEvent): string => { return `reaction/${event.messageId}/${event.userId}/${event.emoji}/added` case "ReactionRemoved": return `reaction/${event.messageId}/${event.userId}/${event.emoji}/removed` + case "StopRequested": + return `stop/${ChatThread.toString(event.thread)}/${event.id}` } } diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts index e5ff7671468..557d50d3eba 100644 --- a/packages/effect/src/chat/ChatTest.ts +++ b/packages/effect/src/chat/ChatTest.ts @@ -959,7 +959,7 @@ export const checkEvent = (event: ChatEvent.ChatEvent, options: { "the event's thread equal to the message's", () => ChatThread.toString(event.thread) ) - } else { + } else if (event._tag !== "StopRequested") { const { _tag, ...fields } = event const flipped = _tag === "ReactionAdded" ? ChatEvent.ReactionRemoved.make(fields) diff --git a/packages/effect/test/chat/ChatEvent.test.ts b/packages/effect/test/chat/ChatEvent.test.ts new file mode 100644 index 00000000000..936729a2a0c --- /dev/null +++ b/packages/effect/test/chat/ChatEvent.test.ts @@ -0,0 +1,30 @@ +import { assert, describe, it } from "@effect/vitest" +import * as ChatEvent from "effect/chat/ChatEvent" +import * as Schema from "effect/Schema" + +const thread = { platform: "slack", id: "T1/C1/1794454017.568519" } + +describe("ChatEvent", () => { + describe("StopRequested", () => { + const event: ChatEvent.StopRequested = { + _tag: "StopRequested", + thread, + id: "1794454026.522466", + userId: "U1", + messageIds: ["1794454017.726189"], + raw: { event: { type: "agent_session_stopped" } } + } + + it("is a ChatEvent", () => { + assert.isTrue(Schema.is(ChatEvent.ChatEvent)(event)) + assert.isTrue(Schema.is(ChatEvent.ChatEvent)({ ...event, messageIds: [] })) + }) + + it("dedupeKey is stop/{thread}/{id}", () => { + assert.strictEqual(ChatEvent.dedupeKey(event), "stop/slack:T1/C1/1794454017.568519/1794454026.522466") + // A redelivery has the same key, whatever streams it lists. + assert.strictEqual(ChatEvent.dedupeKey({ ...event, messageIds: [] }), ChatEvent.dedupeKey(event)) + assert.notStrictEqual(ChatEvent.dedupeKey({ ...event, id: "1794454030.000000" }), ChatEvent.dedupeKey(event)) + }) + }) +}) From b7e482ad87bf837284dfa95c9673335b21b7f8b5 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 19:19:15 +0000 Subject: [PATCH 10/89] Add @effect/chat-slack The Slack adapter for effect/chat: the Events API webhook, the pure normaliser, every adapter op over a minimal Web API client, native streaming with the agent session status and the stop button, and the Slack emoji table generated from iamcal/emoji-data v16.0.0. --- .changeset/chat-slack.md | 6 + .changeset/config.json | 1 + .github/workflows/snapshot.yml | 2 +- README.md | 1 + deno.json | 2 +- packages/chat/slack/README.md | 25 + packages/chat/slack/package.json | 70 + .../chat/slack/scripts/generate-emoji.mjs | 191 ++ packages/chat/slack/src/SlackChat.ts | 334 +++ packages/chat/slack/src/SlackWebApi.ts | 136 ++ packages/chat/slack/src/index.ts | 18 + packages/chat/slack/src/internal/adapter.ts | 594 +++++ packages/chat/slack/src/internal/address.ts | 50 + packages/chat/slack/src/internal/emoji.ts | 204 ++ packages/chat/slack/src/internal/emojiData.ts | 1965 +++++++++++++++++ packages/chat/slack/src/internal/errors.ts | 151 ++ packages/chat/slack/src/internal/escape.ts | 248 +++ packages/chat/slack/src/internal/length.ts | 44 + packages/chat/slack/src/internal/mentions.ts | 164 ++ packages/chat/slack/src/internal/normalize.ts | 226 ++ packages/chat/slack/src/internal/options.ts | 22 + packages/chat/slack/src/internal/webhook.ts | 157 ++ packages/chat/slack/test/SlackChat.test.ts | 496 +++++ packages/chat/slack/test/emoji.test.ts | 215 ++ packages/chat/slack/test/escape.test.ts | 81 + .../recorded/agent-session-stopped.json | 80 + .../recorded/assistant-thread-root.json | 220 ++ .../fixtures/recorded/conversations-info.json | 150 ++ .../slack/test/fixtures/recorded/errors.json | 347 +++ .../test/fixtures/recorded/file-share.json | 351 +++ .../fixtures/recorded/markdown-mentions.json | 425 ++++ .../test/fixtures/recorded/me-message.json | 136 ++ .../test/fixtures/recorded/reactions.json | 480 ++++ .../slack/test/fixtures/recorded/stream.json | 587 +++++ .../fixtures/recorded/thread-broadcast.json | 405 ++++ .../recorded/thread-root-before-after.json | 472 ++++ .../test/fixtures/recorded/unfurl-edit.json | 1207 ++++++++++ .../test/fixtures/recorded/users-info.json | 193 ++ packages/chat/slack/test/live.test.ts | 86 + packages/chat/slack/test/normalize.test.ts | 279 +++ packages/chat/slack/test/utils.ts | 128 ++ packages/chat/slack/test/webhook.test.ts | 165 ++ packages/chat/slack/tsconfig.json | 8 + pnpm-lock.yaml | 6 + pnpm-workspace.yaml | 1 + scripts/circular.mjs | 2 +- scripts/clean.mjs | 2 +- tsconfig.packages.json | 1 + tsconfig.tests.json | 2 + vitest.config.ts | 1 + 50 files changed, 11133 insertions(+), 4 deletions(-) create mode 100644 .changeset/chat-slack.md create mode 100644 packages/chat/slack/README.md create mode 100644 packages/chat/slack/package.json create mode 100644 packages/chat/slack/scripts/generate-emoji.mjs create mode 100644 packages/chat/slack/src/SlackChat.ts create mode 100644 packages/chat/slack/src/SlackWebApi.ts create mode 100644 packages/chat/slack/src/index.ts create mode 100644 packages/chat/slack/src/internal/adapter.ts create mode 100644 packages/chat/slack/src/internal/address.ts create mode 100644 packages/chat/slack/src/internal/emoji.ts create mode 100644 packages/chat/slack/src/internal/emojiData.ts create mode 100644 packages/chat/slack/src/internal/errors.ts create mode 100644 packages/chat/slack/src/internal/escape.ts create mode 100644 packages/chat/slack/src/internal/length.ts create mode 100644 packages/chat/slack/src/internal/mentions.ts create mode 100644 packages/chat/slack/src/internal/normalize.ts create mode 100644 packages/chat/slack/src/internal/options.ts create mode 100644 packages/chat/slack/src/internal/webhook.ts create mode 100644 packages/chat/slack/test/SlackChat.test.ts create mode 100644 packages/chat/slack/test/emoji.test.ts create mode 100644 packages/chat/slack/test/escape.test.ts create mode 100644 packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json create mode 100644 packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json create mode 100644 packages/chat/slack/test/fixtures/recorded/conversations-info.json create mode 100644 packages/chat/slack/test/fixtures/recorded/errors.json create mode 100644 packages/chat/slack/test/fixtures/recorded/file-share.json create mode 100644 packages/chat/slack/test/fixtures/recorded/markdown-mentions.json create mode 100644 packages/chat/slack/test/fixtures/recorded/me-message.json create mode 100644 packages/chat/slack/test/fixtures/recorded/reactions.json create mode 100644 packages/chat/slack/test/fixtures/recorded/stream.json create mode 100644 packages/chat/slack/test/fixtures/recorded/thread-broadcast.json create mode 100644 packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json create mode 100644 packages/chat/slack/test/fixtures/recorded/unfurl-edit.json create mode 100644 packages/chat/slack/test/fixtures/recorded/users-info.json create mode 100644 packages/chat/slack/test/live.test.ts create mode 100644 packages/chat/slack/test/normalize.test.ts create mode 100644 packages/chat/slack/test/utils.ts create mode 100644 packages/chat/slack/test/webhook.test.ts create mode 100644 packages/chat/slack/tsconfig.json diff --git a/.changeset/chat-slack.md b/.changeset/chat-slack.md new file mode 100644 index 00000000000..57dbbcbb404 --- /dev/null +++ b/.changeset/chat-slack.md @@ -0,0 +1,6 @@ +--- +"@effect/chat-slack": patch +"effect": patch +--- + +Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook, native streaming replies and the agent stop button. Add the `StopRequested` chat event. diff --git a/.changeset/config.json b/.changeset/config.json index 0d7c5d7293b..b641be2c2d7 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -23,6 +23,7 @@ "@effect/ai-openai-compat", "@effect/ai-openrouter", "@effect/atom-react", + "@effect/chat-slack", "@effect/atom-solid", "@effect/atom-vue", "@effect/docgen", diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 69e9e25288b..8ff8b2256ea 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -46,4 +46,4 @@ jobs: run: pnpm build - name: Create snapshot id: snapshot - run: pnpm exec pkg-pr-new publish --pnpm --comment=off ./packages/* ./packages/atom/* ./packages/ai/* ./packages/platform/* ./packages/sql/* ./packages/tools/* + run: pnpm exec pkg-pr-new publish --pnpm --comment=off ./packages/* ./packages/atom/* ./packages/ai/* ./packages/chat/* ./packages/platform/* ./packages/sql/* ./packages/tools/* diff --git a/README.md b/README.md index 23384e97a57..461e5c97874 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ This monorepo contains the core `effect` package alongside integration packages | [`@effect/ai-typesafe`](packages/ai/typesafe) | TypeSafe decision provider for the Effect AI modules | [docs](https://effect.website/docs/v4/api/ai-typesafe) | | [`@effect/ai-openai-compat`](packages/ai/openai-compat) | OpenAI-compatible API provider for the Effect AI modules | [docs](https://effect.website/docs/v4/api/ai-openai-compat) | | [`@effect/ai-openrouter`](packages/ai/openrouter) | OpenRouter provider for the Effect AI modules | [docs](https://effect.website/docs/v4/api/ai-openrouter) | +| [`@effect/chat-slack`](packages/chat/slack) | Slack adapter for `effect/chat` | [docs](https://effect.website/docs/v4/api/chat-slack) | | [`@effect/atom-react`](packages/atom/react) | React bindings for Effect Atom | [docs](https://effect.website/docs/v4/api/atom-react) | | [`@effect/atom-solid`](packages/atom/solid) | SolidJS bindings for Effect Atom | [docs](https://effect.website/docs/v4/api/atom-solid) | | [`@effect/atom-vue`](packages/atom/vue) | Vue bindings for Effect Atom | [docs](https://effect.website/docs/v4/api/atom-vue) | diff --git a/deno.json b/deno.json index ca3138a08f9..632b786f0fd 100644 --- a/deno.json +++ b/deno.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/denoland/deno/refs/heads/main/cli/schemas/config-file.v1.json", "nodeModulesDir": "manual", "unstable": ["bare-node-builtins", "node-globals", "net"], - "workspace": ["./packages/*", "./packages/platform/*"], + "workspace": ["./packages/*", "./packages/chat/*", "./packages/platform/*"], "exclude": [ "**/*.mjs", "**/*.cjs", diff --git a/packages/chat/slack/README.md b/packages/chat/slack/README.md new file mode 100644 index 00000000000..7a842d9eba6 --- /dev/null +++ b/packages/chat/slack/README.md @@ -0,0 +1,25 @@ +# @effect/chat-slack + +A [Slack](https://slack.com) adapter for `effect/chat`. Includes the Events API webhook, a pure event normaliser for Socket Mode or your own transport, a minimal Web API client, native streaming replies with the agent stop button, and the Slack emoji table. + +## Installation + +```sh +npm install effect @effect/chat-slack +``` + +## Links + +- [Website](https://effect.website): documentation, guides, and news. +- [Reference](https://effect.website/docs/v4/api/chat-slack): API documentation for this package. +- [Discord](https://discord.gg/effect-ts): ask questions, share what you're building, and talk to the core team. +- [Community](https://effect.website/community-hub): meetups and events, or bring Effect to your own. +- [Issues](https://github.com/Effect-TS/effect/issues): bug reports and feature requests. + +## Let's talk + +Whether your team is considering Effect, rolling it out, or already running it in production, we'd love to hear from you: what you're building, what works, and what you need from Effect next. + +- **Talk to the maintainers.** Introduce your team on [Discord](https://discord.gg/effect-ts) or email [contact@effectful.co](mailto:contact@effectful.co). We're happy to connect privately on Slack or Discord for feedback and help with adoption. +- **Production support.** We're exploring how to better support teams running Effect in production. If your organization has specific support needs, let's discuss them. +- **Adoption help.** Our [adoption partners](https://effect.website/adoption-partners) offer implementation, consulting, team extension, training, and commercial support. diff --git a/packages/chat/slack/package.json b/packages/chat/slack/package.json new file mode 100644 index 00000000000..8ce38e294a9 --- /dev/null +++ b/packages/chat/slack/package.json @@ -0,0 +1,70 @@ +{ + "name": "@effect/chat-slack", + "version": "4.1.4", + "type": "module", + "license": "MIT", + "description": "The Slack adapter for effect/chat", + "homepage": "https://effect.website", + "repository": { + "type": "git", + "url": "https://github.com/Effect-TS/effect.git", + "directory": "packages/chat/slack" + }, + "bugs": { + "url": "https://github.com/Effect-TS/effect/issues" + }, + "tags": [ + "typescript", + "chat", + "slack" + ], + "keywords": [ + "typescript", + "chat", + "slack" + ], + "sideEffects": [], + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts", + "./*": "./src/*.ts", + "./internal/*": null, + "./index": null, + "./*/index": null + }, + "files": [ + "src/**/*.ts", + "dist/**/*.js", + "dist/**/*.js.map", + "dist/**/*.d.ts", + "dist/**/*.d.ts.map", + "AGENTS.md", + "CLAUDE.md", + "ai-docs/**/*" + ], + "publishConfig": { + "access": "public", + "provenance": true, + "exports": { + "./package.json": "./package.json", + ".": "./dist/index.js", + "./*": "./dist/*.js", + "./internal/*": null, + "./index": null, + "./*/index": null + } + }, + "scripts": { + "codegen": "effect-utils codegen", + "codegen:emoji": "node scripts/generate-emoji.mjs", + "build": "tsc -b tsconfig.json && pnpm babel", + "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps", + "check": "tsc -b tsconfig.json" + }, + "devDependencies": { + "effect": "workspace:^" + }, + "peerDependencies": { + "effect": "workspace:^" + } +} diff --git a/packages/chat/slack/scripts/generate-emoji.mjs b/packages/chat/slack/scripts/generate-emoji.mjs new file mode 100644 index 00000000000..2b54d0d639c --- /dev/null +++ b/packages/chat/slack/scripts/generate-emoji.mjs @@ -0,0 +1,191 @@ +// Generates src/internal/emojiData.ts from a pinned copy of iamcal/emoji-data. +// +// Usage (from packages/chat/slack): node scripts/generate-emoji.mjs +// +// The source is pinned by commit, byte size and SHA-256 digest. Any mismatch +// aborts the run without touching the output. The output is deterministic, so +// a second run produces no diff. +import { createHash } from "node:crypto" +import { writeFileSync } from "node:fs" + +const PROJECT = "iamcal/emoji-data" +const TAG = "v16.0.0" +const COMMIT = "2771d0b1b3af25c069086e68e38f901c3dda8bdf" +const SOURCE_URL = "https://raw.githubusercontent.com/iamcal/emoji-data/" + COMMIT + "/emoji.json" +const SIZE = 1313457 +const SHA256 = "1d602e65be88772bf8cc368ce16b855d719eeddbafe128d471b80203f494d29f" +const COUNTS = { emoji: 1911, names: 1972, variations: 1875 } + +// Copied verbatim from https://github.com/iamcal/emoji-data/blob//LICENSE +const LICENSE = [ + "The MIT License (MIT)", + "", + "Copyright (c) 2013 Cal Henderson", + "", + "Permission is hereby granted, free of charge, to any person obtaining a copy", + "of this software and associated documentation files (the \"Software\"), to deal", + "in the Software without restriction, including without limitation the rights", + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell", + "copies of the Software, and to permit persons to whom the Software is", + "furnished to do so, subject to the following conditions:", + "", + "The above copyright notice and this permission notice shall be included in all", + "copies or substantial portions of the Software.", + "", + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", + "SOFTWARE." +] + +// Skin tone modifier code point -> Slack "skin-tone-N" digit. +const TONES = { "1F3FB": "2", "1F3FC": "3", "1F3FD": "4", "1F3FE": "5", "1F3FF": "6" } + +const OUTPUT = new URL("../src/internal/emojiData.ts", import.meta.url) + +const fail = (message) => { + throw new Error("generate-emoji: " + message) +} + +const response = await fetch(SOURCE_URL) +if (!response.ok) fail("GET " + SOURCE_URL + " returned " + response.status) +const bytes = new Uint8Array(await response.arrayBuffer()) +if (bytes.byteLength !== SIZE) fail("expected " + SIZE + " bytes, got " + bytes.byteLength) +const digest = createHash("sha256").update(bytes).digest("hex") +if (digest !== SHA256) fail("expected sha256 " + SHA256 + ", got " + digest) + +const emoji = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)) + +const SEQUENCE = /^[0-9A-F]{4,6}(-[0-9A-F]{4,6})*$/ +const NAME = /^[a-z0-9_+-]+$/ + +const sequence = (value) => { + if (typeof value !== "string" || !SEQUENCE.test(value)) fail("bad code point sequence " + JSON.stringify(value)) + return value.toLowerCase() +} + +const withoutVariationSelector = (unified) => + unified.split("-").filter((codePoint) => codePoint !== "fe0f").join("-") + +// "" = none, "!" = the unified sequence without U+FE0F, otherwise the sequence. +const nonQualified = (unified, value) => { + if (value === null || value === undefined) return "" + const encoded = sequence(value) + if (encoded === unified) fail("non_qualified equals unified: " + value) + return encoded === withoutVariationSelector(unified) ? "!" : encoded +} + +const names = new Set() +const sequences = new Set() +const claim = (set, value, what) => { + if (set.has(value)) fail("duplicate " + what + " " + value) + set.add(value) +} + +let nameCount = 0 +let variationCount = 0 +const lines = [] +const sorted = [...emoji].sort((a, b) => (a.unified < b.unified ? -1 : a.unified > b.unified ? 1 : 0)) + +for (const entry of sorted) { + if (!Array.isArray(entry.short_names) || entry.short_names[0] !== entry.short_name) { + fail("short_name is not the first short_names entry for " + entry.unified) + } + for (const name of entry.short_names) { + if (typeof name !== "string" || !NAME.test(name)) fail("bad short name " + JSON.stringify(name)) + claim(names, name, "short name") + nameCount++ + } + const unified = sequence(entry.unified) + claim(sequences, unified, "sequence") + const nq = nonQualified(unified, entry.non_qualified) + if (nq !== "") claim(sequences, nq === "!" ? withoutVariationSelector(unified) : nq, "sequence") + + const fields = [entry.short_names.join(","), unified, nq] + if (entry.skin_variations !== undefined) { + // Variations sharing a template (the variation's unified sequence with each + // skin tone modifier replaced by "*") are stored as one group. + const groups = new Map() + for (const key of Object.keys(entry.skin_variations).sort()) { + const modifiers = key.split("-") + const tones = modifiers.map((codePoint) => TONES[codePoint] ?? fail("unknown skin tone key " + key)) + const variation = entry.skin_variations[key] + const variationUnified = sequence(variation.unified) + claim(sequences, variationUnified, "sequence") + const variationNq = nonQualified(variationUnified, variation.non_qualified) + if (variationNq !== "") { + if (variationNq !== "!") fail("unsupported skin variation non_qualified " + variation.non_qualified) + claim(sequences, withoutVariationSelector(variationUnified), "sequence") + } + let index = 0 + const template = variationUnified.split("-").map((codePoint) => { + if (TONES[codePoint.toUpperCase()] === undefined) return codePoint + if (codePoint.toUpperCase() !== modifiers[index++]) fail("skin tone order mismatch in " + variation.unified) + return "*" + }).join("-") + if (index !== modifiers.length) fail("skin tone count mismatch in " + variation.unified) + const group = template + (variationNq === "" ? "" : ":" + variationNq) + if (!groups.has(group)) groups.set(group, []) + groups.get(group).push(tones.join("")) + variationCount++ + // Round trip: the stored form must reproduce the upstream sequence. + let fill = 0 + const expanded = template.split("-").map((codePoint) => (codePoint === "*" ? modifiers[fill++].toLowerCase() : codePoint)) + .join("-") + if (expanded !== variationUnified) fail("template round trip failed for " + variation.unified) + } + fields.push([...groups].map(([group, keys]) => keys.join(",") + ":" + group).join(";")) + } + lines.push(fields.join("|")) +} + +const counts = { emoji: lines.length, names: nameCount, variations: variationCount } +for (const key of Object.keys(COUNTS)) { + if (counts[key] !== COUNTS[key]) fail("expected " + COUNTS[key] + " " + key + ", got " + counts[key]) +} + +const output = [ + "/**", + " * Slack emoji short names and code point sequences.", + " *", + " * Generated by scripts/generate-emoji.mjs. Do not edit.", + " *", + " * Source:", + " * - Project: " + PROJECT, + " * - Tag: " + TAG, + " * - Commit: " + COMMIT, + " * - URL: " + SOURCE_URL, + " * - SHA-256: " + SHA256, + " * - Size: " + SIZE + " bytes", + " * - License: MIT (reproduced below)", + " *", + " * Format: one emoji per line (" + counts.emoji + " emoji, " + counts.names + " short names, " + counts.variations + + " skin tone variations), sorted by unified:", + " *", + " * short_names|unified|non_qualified[|variations]", + " *", + " * - short_names: comma separated, the first one is short_name", + " * - unified: lowercase hex code points joined by \"-\"", + " * - non_qualified: empty for none, \"!\" for unified without U+FE0F, otherwise", + " * a code point sequence", + " * - variations: \";\" separated groups of skin_variations entries, each", + " * keys:template[:non_qualified]. keys is a comma separated list of upstream", + " * skin_variations keys, written as one Slack skin-tone-N digit (2-6) per", + " * modifier. template is the variation's unified sequence with each modifier", + " * replaced by \"*\", filled in key order. non_qualified is empty or \"!\"", + " *", + ...LICENSE.map((line) => (line === "" ? " *" : " * " + line)), + " *", + " * @internal", + " */", + "", + "/** @internal */", + "export const emojiData = `" + lines.join("\n") + "`", + "" +].join("\n") + +writeFileSync(OUTPUT, output) +console.log("wrote " + OUTPUT.pathname + " (" + Buffer.byteLength(output) + " bytes)") diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts new file mode 100644 index 00000000000..16775eba2ef --- /dev/null +++ b/packages/chat/slack/src/SlackChat.ts @@ -0,0 +1,334 @@ +/** + * The Slack adapter for `effect/chat`: the `Registry` layer, the Events API + * webhook, the pure normaliser, address helpers and the scoped post options. + * + * **Details** + * + * - Bot token scopes: `chat:write`, `channels:history`, `groups:history`, + * `im:history`, `mpim:history`, `channels:read`, `groups:read`, + * `im:read`, `mpim:read`, `users:read`, `reactions:read`, `files:read` + * and `files:write`. + * - Event subscriptions, sent to `layerWebhook`'s path: `message.channels`, + * `message.groups`, `message.im`, `message.mpim`, `app_mention`, + * `reaction_added`, `reaction_removed` and `agent_session_stopped`. + * - Slack's stop button also needs the app declared as an agent with + * `features.agent_view` in the manifest. Slack documents that declaration + * as irreversible. Without it the adapter's session status calls answer + * `not_authorized`; it then stops making them, and replies still work. + * - A click on the stop button stops nothing by itself: the consumer gets a + * `StopRequested` and ends the reply. Until it does, the user sees a + * disabled button. + * + * @stability unstable + * @since 4.1.5 + */ +import { Registry } from "effect/chat/ChatAdapter" +import type { ChatError } from "effect/chat/ChatError" +import type { ChatEvent } from "effect/chat/ChatEvent" +import { ChatHandler } from "effect/chat/ChatHandler" +import type { ParseMention } from "effect/chat/ChatTest" +import type { ChatThread } from "effect/chat/ChatThread" +import * as Context from "effect/Context" +import * as Duration from "effect/Duration" +import * as Effect from "effect/Effect" +import { dual } from "effect/Function" +import * as HttpClient from "effect/http/HttpClient" +import * as HttpRouter from "effect/http/HttpRouter" +import * as Layer from "effect/Layer" +import * as Option from "effect/Option" +import type * as Redacted from "effect/Redacted" +import type * as Schema from "effect/Schema" +import * as Adapter from "./internal/adapter.ts" +import * as Address from "./internal/address.ts" +import * as Emoji from "./internal/emoji.ts" +import * as Errors from "./internal/errors.ts" +import * as Mentions from "./internal/mentions.ts" +import * as Normalize from "./internal/normalize.ts" +import { CurrentPostOptions } from "./internal/options.ts" +import * as Webhook from "./internal/webhook.ts" +import { SlackWebApi } from "./SlackWebApi.ts" +import * as WebApi from "./SlackWebApi.ts" + +const isRecord = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u) + +/** + * A Slack user from `users.info`, with guest and Slack Connect status. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface SlackUser { + readonly id: string + readonly teamId: string + readonly name: string + readonly isBot: boolean + readonly isRestricted: boolean + readonly isUltraRestricted: boolean + /** A Slack Connect user from another organisation. */ + readonly isStranger: boolean + readonly deleted: boolean + readonly raw: Schema.Json +} + +/** + * The Slack side of the adapter, for what the core has no op for. + * + * **Details** + * + * - `botUserId` comes from `auth.test`, read once. A failed read is tried + * again next time. + * - `user` calls `users.info` each time. Nothing is cached. + * + * @stability unstable + * @category services + * @since 4.1.5 + */ +export class SlackChat extends Context.Service + readonly user: (id: string) => Effect.Effect +}>()("@effect/chat-slack/SlackChat") {} + +/** + * Registers the Slack adapter in the `Registry`, for one workspace. + * + * **Details** + * + * - Content goes out as `markdown_text`. A `<` outside inline and fenced + * code is sent as `<`, so no mention token notifies unless + * `withPostOptions({ notify })` allows it. + * - `post` fails with `TooLarge` before calling Slack when the text as sent + * passes 12,000 code points, or 13,200 with every emoji counted as its + * shortcode. `edit` applies only the first limit, as Slack does. + * - A post with files uploads them and shares them as one message. Its text + * goes as Slack mrkdwn, since such a message takes no `markdown_text`. + * - `replyTo` is not supported. + * - A message from another app or an incoming webhook (`bot_message`) has + * the `bot_id` as its author id. `getUser` on that id fails `NotFound`. + * - A thread root whose subtype is not a message, such as an agent-view + * chat's `assistant_app_thread` root, is treated as deleted: `opener` + * gives `None` and history starts at the first reply. + * - The native stream needs a thread and a recipient, and rotates before + * Slack's ten minute cap. A reply that ends after a click on the stop + * button moves the agent session off `processing`. + * + * @stability unstable + * @category layers + * @since 4.1.5 + */ +export const layer = (options: { + readonly botToken: Redacted.Redacted + readonly teamId: string +}): Layer.Layer => + Layer.effect( + SlackChat, + Effect.gen(function*() { + const api = yield* SlackWebApi + const http = yield* HttpClient.HttpClient + const registry = yield* Registry + let cached: string | undefined + const botUserId: Effect.Effect = Effect.suspend(() => { + if (cached !== undefined) return Effect.succeed(cached) + return api.call("auth.test", {}).pipe( + Effect.mapError(Errors.withOp("botUserId")), + Effect.flatMap((answer) => { + const id = isRecord(answer) ? answer.user_id : undefined + if (typeof id !== "string" || id === "") { + return Effect.fail(Errors.chatError("botUserId", Errors.invalidResponse(false, "missing_user_id"))) + } + cached = id + return Effect.succeed(id) + }) + ) + }) + const { adapter, user } = Adapter.make({ + api, + http, + botToken: options.botToken, + teamId: options.teamId, + botUserId + }) + yield* registry.register(adapter) + return SlackChat.of({ teamId: options.teamId, botUserId, user }) + }) + ).pipe(Layer.provideMerge(WebApi.layer({ botToken: options.botToken }))) + +/** + * The address of a Slack channel, direct conversation or thread: + * `{team}/{channel}`, or `{team}/{channel}/{threadTs}` for a thread. + * + * @stability unstable + * @category constructors + * @since 4.1.5 + */ +export const thread: (parts: { + readonly team: string + readonly channel: string + readonly threadTs?: string | undefined +}) => ChatThread = Address.thread + +/** + * The parts of a Slack address, or `None` for another platform's or a + * malformed one. + * + * @stability unstable + * @category destructors + * @since 4.1.5 + */ +export const parts: (thread: ChatThread) => Option.Option<{ + readonly team: string + readonly channel: string + readonly threadTs?: string | undefined +}> = Address.parts + +/** + * `POST {path}`: the Events API webhook. + * + * **Details** + * + * - Checks the `v0` signature with the signing secret and a five minute + * window, then answers `url_verification`. + * - An envelope for another app, another workspace or of another type is + * answered 200 and dropped. + * - The events go through `normalize` to the `ChatHandler`, one at a time. + * - Answers 503, so Slack retries, when the handler fails `NotAccepted` or + * runs past `deadline` (2.5 seconds by default), and 413 past + * `maxBodyBytes` (1 MiB by default). + * - Slack redelivers on a timeout or an error, so an event can arrive twice. + * `ChatEvent.dedupeKey` gives the two deliveries equal keys. + * + * @stability unstable + * @category layers + * @since 4.1.5 + */ +export const layerWebhook = (options: { + readonly path: `/${string}` + readonly signingSecret: Redacted.Redacted + readonly appId: string + readonly deadline?: Duration.Duration | undefined + readonly maxBodyBytes?: number | undefined +}): Layer.Layer => + HttpRouter.use(Effect.fnUntraced(function*(router) { + const slack = yield* SlackChat + const handler = yield* ChatHandler + const verify = yield* Webhook.makeVerifier(options.signingSecret) + const webhookOptions: Webhook.Options = { + verify, + appId: options.appId, + teamId: slack.teamId, + botUserId: slack.botUserId, + handle: handler.handle, + deadline: options.deadline ?? Duration.millis(2500), + maxBodyBytes: options.maxBodyBytes ?? 1024 * 1024 + } + yield* router.add("POST", options.path, (request) => Webhook.handleRequest(request, webhookOptions)) + })) + +/** + * The normaliser, for Socket Mode or a consumer's own transport. + * + * **Details** + * + * - Pure: takes an `event_callback` envelope, gives zero or more events. + * - An envelope for another workspace gives none. The team in an address is + * the workspace, from the envelope's `team_id` or `authorizations`. + * - `message` and `app_mention` for one message give equal events. An + * `app_mention` that carries `edited` gives none. + * - A message subtype other than `file_share`, `thread_broadcast`, + * `bot_message` and `me_message` gives none. + * - Mentions come from the message's `rich_text` block when it has one, + * and from `text` outside code otherwise. + * - `agent_session_stopped` gives a `StopRequested`. + * - `raw` is the envelope without its verification `token`. + * + * @stability unstable + * @category normalization + * @since 4.1.5 + */ +export const normalize: ( + envelope: unknown, + context: { readonly teamId: string; readonly botUserId: string } +) => ReadonlyArray = Normalize.normalize + +/** + * Slack options for every write inside an effect. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface SlackPostOptions { + /** Which mention tokens may notify. Default: none. */ + readonly notify?: { + readonly users?: ReadonlyArray | undefined + readonly groups?: ReadonlyArray | undefined + readonly broadcast?: boolean | undefined + } | undefined + /** + * Link and media previews. Default false, which sends `unfurl_links` and + * `unfurl_media` both false; true sends both true. + * + * **Details** + * + * - It applies to `post` only: `chat.update` has no unfurl parameter. + * An edit that adds a link gets no preview either way, which a live + * check confirmed, so a post-then-edit stream never unfurls. + * - Slack disables unfurling in streaming messages, so it does nothing on + * a native stream. + */ + readonly unfurl?: boolean | undefined + /** Default true where the workspace supports it. */ + readonly nativeStream?: boolean | undefined + /** For a Connect channel, where the recipient is on another team. */ + readonly recipientTeamId?: string | undefined + /** The agent session status at a normal end of a native stream. Default `active`. */ + readonly sessionStatusAtEnd?: "active" | "processing" | "suspended" | "closed" | undefined +} + +/** + * Scoped Slack options for every write inside `effect`. Nested calls merge, + * the inner one winning field by field. + * + * @stability unstable + * @category combinators + * @since 4.1.5 + */ +export const withPostOptions: { + (options: SlackPostOptions): (effect: Effect.Effect) => Effect.Effect + (effect: Effect.Effect, options: SlackPostOptions): Effect.Effect +} = dual( + 2, + (effect: Effect.Effect, options: SlackPostOptions): Effect.Effect => + Effect.updateService(effect, CurrentPostOptions, (current) => ({ ...current, ...options })) +) + +/** + * A Slack emoji name, with or without colons and with skin tone suffixes, as + * Unicode. `None` for a name the table doesn't know, such as a custom emoji. + * + * @stability unstable + * @category emoji + * @since 4.1.5 + */ +export const emojiFromName = (name: string): Option.Option => Option.fromUndefinedOr(Emoji.fromName(name)) + +/** + * An emoji as its Slack name, without colons. + * + * @stability unstable + * @category emoji + * @since 4.1.5 + */ +export const emojiToName = (emoji: string): Option.Option => Option.fromUndefinedOr(Emoji.toName(emoji)) + +/** + * Reads one Slack mention token, such as `<@U123>`, ``, + * `<#C123|name>` or ``, for `ChatTest.checkMessage`, + * `ChatTest.checkEvent` and `ChatTest.conformance`. + * + * @stability unstable + * @category testing + * @since 4.1.5 + */ +export const parseMention: ParseMention = (slice) => Option.fromUndefinedOr(Mentions.parseToken(slice)) diff --git a/packages/chat/slack/src/SlackWebApi.ts b/packages/chat/slack/src/SlackWebApi.ts new file mode 100644 index 00000000000..663fb609850 --- /dev/null +++ b/packages/chat/slack/src/SlackWebApi.ts @@ -0,0 +1,136 @@ +/** + * The minimal Slack Web API client the adapter is built on. It is public, so + * a consumer can call a method the adapter has no op for, with the same error + * mapping and the same rule for writes. + * + * @stability unstable + * @since 4.1.5 + */ +import { retrySafe } from "effect/chat/ChatAdapter" +import type { ChatError } from "effect/chat/ChatError" +import * as Context from "effect/Context" +import * as Effect from "effect/Effect" +import * as HttpClient from "effect/http/HttpClient" +import * as HttpClientRequest from "effect/http/HttpClientRequest" +import * as Layer from "effect/Layer" +import * as Redacted from "effect/Redacted" +import type * as Schema from "effect/Schema" +import * as Errors from "./internal/errors.ts" + +/** + * Options for one Web API call. + * + * @stability unstable + * @category models + * @since 4.1.5 + */ +export interface CallOptions { + /** + * The call changes something. It is never retried after the request left, + * and a failure that may have landed is `uncertain`. + */ + readonly write?: boolean | undefined + /** Retry `retry` failures, as `ChatAdapter.retrySafe` does. Default true. */ + readonly retry?: boolean | undefined +} + +/** + * The minimal Web API client, with the bot token. + * + * **Details** + * + * - `call` posts form parameters to `https://slack.com/api/{method}`. A + * string goes as it is, any other value as JSON, and `undefined` is left + * out. It succeeds with the answer once Slack says `ok`. + * - An `ok: false` answer fails with the reason for Slack's error code, which + * becomes the reason's `detail`. `ratelimited` and an HTTP 429 give + * `RateLimited` with the `Retry-After` wait. + * - A write never repeats once the request left: a transport failure, a + * server error or an unreadable answer is `uncertain`. A read retries + * `retry` failures unless `retry: false`. + * - The error's `op` is the method name. + * + * @stability unstable + * @category services + * @since 4.1.5 + */ +export class SlackWebApi extends Context.Service>, + options?: CallOptions | undefined + ) => Effect.Effect +}>()("@effect/chat-slack/SlackWebApi") {} + +const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u) + +const formBody = (body: Readonly>): Record => { + const out: Record = {} + for (const [key, value] of Object.entries(body)) { + if (value === undefined) continue + out[key] = typeof value === "string" ? value : JSON.stringify(value) + } + return out +} + +/** + * Builds the client from an `HttpClient` and a bot token. + * + * @stability unstable + * @category constructors + * @since 4.1.5 + */ +export const make = Effect.fnUntraced(function*(options: { + readonly botToken: Redacted.Redacted + readonly baseUrl?: string | undefined +}) { + const http = yield* HttpClient.HttpClient + const baseUrl = options.baseUrl ?? "https://slack.com/api" + + const once = (method: string, body: Readonly>, write: boolean) => { + const fail = (reason: Parameters[1]) => Effect.fail(Errors.chatError(method, reason)) + const request = HttpClientRequest.post(`${baseUrl}/${method}`).pipe( + HttpClientRequest.bearerToken(Redacted.value(options.botToken)), + HttpClientRequest.bodyUrlParams(formBody(body)) + ) + return http.execute(request).pipe( + Effect.catch((error) => fail(Errors.transport(write, error.reason._tag, error))), + Effect.flatMap((response) => { + const retryAfter = Errors.parseRetryAfter(response.headers["retry-after"]) + if (response.status < 200 || response.status >= 300) { + return fail(Errors.reasonForStatus(response.status, { write, retryAfter })) + } + return response.json.pipe( + Effect.catch((error) => fail(Errors.invalidResponse(write, "invalid_json", error))), + Effect.flatMap((json): Effect.Effect => { + if (!isObject(json) || typeof json.ok !== "boolean") { + return fail(Errors.invalidResponse(write, "invalid_response")) + } + if (json.ok) return Effect.succeed(json) + const code = typeof json.error === "string" ? json.error : "unknown_error" + return fail(Errors.reasonForCode(code, { write, retryAfter })) + }) + ) + }) + ) + } + + return SlackWebApi.of({ + call: (method, body, callOptions) => { + const call = once(method, body, callOptions?.write === true) + return callOptions?.retry === false ? call : retrySafe(call) + } + }) +}) + +/** + * The client as a layer. + * + * @stability unstable + * @category layers + * @since 4.1.5 + */ +export const layer = (options: { + readonly botToken: Redacted.Redacted + readonly baseUrl?: string | undefined +}): Layer.Layer => Layer.effect(SlackWebApi, make(options)) diff --git a/packages/chat/slack/src/index.ts b/packages/chat/slack/src/index.ts new file mode 100644 index 00000000000..78e24fa7cb8 --- /dev/null +++ b/packages/chat/slack/src/index.ts @@ -0,0 +1,18 @@ +/** + * @stability unstable + * @since 4.1.5 + */ + +// @barrel: Auto-generated exports. Do not edit manually. + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as SlackChat from "./SlackChat.ts" + +/** + * @stability unstable + * @since 4.1.5 + */ +export * as SlackWebApi from "./SlackWebApi.ts" diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts new file mode 100644 index 00000000000..7eef3b075c5 --- /dev/null +++ b/packages/chat/slack/src/internal/adapter.ts @@ -0,0 +1,594 @@ +import type { ChatAdapter, Descriptor, File, Posted, ThreadInfo } from "effect/chat/ChatAdapter" +import { type ChatError, type ChatErrorReason, TooLarge, Unknown, Unsupported } from "effect/chat/ChatError" +import type { ChatMessage } from "effect/chat/ChatMessage" +import type { ChatThread } from "effect/chat/ChatThread" +import * as DateTime from "effect/DateTime" +import * as Duration from "effect/Duration" +import * as Effect from "effect/Effect" +import type * as HttpClient from "effect/http/HttpClient" +import * as HttpClientRequest from "effect/http/HttpClientRequest" +import * as Option from "effect/Option" +import * as Redacted from "effect/Redacted" +import type * as Schema from "effect/Schema" +import * as Stream from "effect/Stream" +import * as Address from "./address.ts" +import * as Errors from "./errors.ts" +import * as Escape from "./escape.ts" +import * as Length from "./length.ts" +import * as Normalize from "./normalize.ts" +import { CurrentPostOptions, type SessionStatus } from "./options.ts" + +type Json = Schema.Json +type JsonObject = { readonly [key: string]: Json } + +const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u) + +const string = (object: JsonObject, key: string): string | undefined => { + const value = object[key] + return typeof value === "string" && value.length > 0 ? value : undefined +} + +const object = (object: JsonObject, key: string): JsonObject | undefined => { + const value = object[key] + return isObject(value) ? value : undefined +} + +/** @internal */ +export interface Api { + readonly call: ( + method: string, + body: Readonly>, + options?: { readonly write?: boolean | undefined; readonly retry?: boolean | undefined } + ) => Effect.Effect +} + +/** @internal */ +export interface SlackUser { + readonly id: string + readonly teamId: string + readonly name: string + readonly isBot: boolean + readonly isRestricted: boolean + readonly isUltraRestricted: boolean + readonly isStranger: boolean + readonly deleted: boolean + readonly raw: Json +} + +/** @internal */ +export const descriptor: Descriptor = { + platform: Address.platform, + capabilities: new Set([ + "edit", + "delete", + "fetchMessage", + "history", + "download", + "files", + "startThread", + "getThread", + "opener", + "getUser", + "nativeStream" + ]), + measure: Length.measure, + limits: { + messageLength: Length.messageLength, + filesPerMessage: 10, + uploadBytes: 1024 * 1024 * 1024, + minWriteInterval: Duration.seconds(1), + streamLength: Length.messageLength, + streamAge: Duration.minutes(10) + } +} + +const pageSize = 200 + +/** `files.info` reads for the share of a fresh upload, at this interval. */ +const shareAttempts = 20 +const shareInterval = Duration.millis(500) + +/** Codes on `chat.startStream` that mean the feature is off for this thread. */ +const streamUnsupported = new Set(["channel_type_not_supported", "feature_disabled", "not_allowed_token_type"]) + +interface StreamState { + escape: Escape.State + text: string + stopped: boolean +} + +const hasDetail = (code: string) => (error: ChatError): boolean => error.reason.detail === code + +const userName = (user: JsonObject): string => { + const profile = object(user, "profile") + return (profile === undefined ? undefined : string(profile, "display_name") ?? string(profile, "real_name")) ?? + string(user, "real_name") ?? string(user, "name") ?? string(user, "id") ?? "" +} + +/** @internal */ +export const make = (options: { + readonly api: Api + readonly http: HttpClient.HttpClient + readonly botToken: Redacted.Redacted + readonly teamId: string + readonly botUserId: Effect.Effect +}) => { + const { api, teamId } = options + const streams = new Map() + let declaredAgent = true + + const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason)) + + const call = ( + op: string, + method: string, + body: Readonly>, + callOptions?: { readonly write?: boolean | undefined; readonly retry?: boolean | undefined } + ) => api.call(method, body, callOptions).pipe(Effect.mapError(Errors.withOp(op))) + + const resolve = (op: string, thread: ChatThread): Effect.Effect => { + const parts = Address.parts(thread) + return Option.isSome(parts) && parts.value.team === teamId + ? Effect.succeed(parts.value) + : fail(op, Errors.invalidRequest("invalid_thread")) + } + + const tsOf = (op: string, write: boolean) => (answer: Json): Effect.Effect => { + const ts = isObject(answer) ? string(answer, "ts") : undefined + return ts === undefined ? fail(op, Errors.invalidResponse(write, "missing_ts")) : Effect.succeed(ts) + } + + const checkSent = (op: string, sent: string, emoji: boolean): Effect.Effect => { + if (Length.codePoints(sent) > Length.messageLength) { + return fail(op, new TooLarge({ subject: "text", detail: "msg_too_long" })) + } + if (emoji && Length.blocksCost(sent) > Length.blocksLength) { + return fail(op, new TooLarge({ subject: "text", detail: "msg_blocks_too_long" })) + } + return Effect.void + } + + const messages = (answer: Json): ReadonlyArray => + isObject(answer) && Array.isArray(answer.messages) ? answer.messages : [] + + const nextCursor = (answer: Json): Option.Option => { + const metadata = isObject(answer) ? object(answer, "response_metadata") : undefined + const cursor = metadata === undefined ? undefined : string(metadata, "next_cursor") + return cursor === undefined ? Option.none() : Option.some(cursor) + } + + /** One message by ts, in or out of a thread, as Slack stores it. */ + const fetchRaw = (op: string, channel: string, ts: string): Effect.Effect => + call(op, "conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 2 }).pipe( + Effect.flatMap((answer) => { + const found = messages(answer).find((message) => isObject(message) && message.ts === ts) + return found === undefined ? fail(op, Errors.notFound("message_not_found")) : Effect.succeed(found) + }) + ) + + const fetchMessage = Effect.fnUntraced(function*(op: string, thread: ChatThread, messageId: string) { + const parts = yield* resolve(op, thread) + const botUserId = yield* options.botUserId + const raw = yield* fetchRaw(op, parts.channel, messageId) + const message = Normalize.message(raw, { team: teamId, channel: parts.channel, botUserId }) + return message === undefined ? yield* fail(op, Errors.notFound("not_a_message")) : message + }) + + const sessionStatus = (channel: string, threadTs: string, status: SessionStatus): Effect.Effect => + declaredAgent + ? call("nativeStream.stop", "agents.sessions.setStatus", { channel_id: channel, thread_ts: threadTs, status }, { + write: true, + retry: false + }).pipe( + Effect.tapError((error) => + Effect.sync(() => { + if (hasDetail("not_authorized")(error)) declaredAgent = false + }) + ), + Effect.catch((error) => Effect.logDebug("agents.sessions.setStatus failed", error)), + Effect.asVoid + ) + : Effect.void + + // Files + + const stage = (file: File): Effect.Effect<{ readonly id: string; readonly title: string }, ChatError> => + Effect.gen(function*() { + const answer = yield* call("post", "files.getUploadURLExternal", { + filename: file.name, + length: file.content.length + }) + const uploadUrl = isObject(answer) ? string(answer, "upload_url") : undefined + const fileId = isObject(answer) ? string(answer, "file_id") : undefined + if (uploadUrl === undefined || fileId === undefined) { + return yield* fail("post", Errors.invalidResponse(false, "missing_upload_url")) + } + // Staging posts nothing, so every failure here is safe to retry. + const response = yield* options.http.execute( + HttpClientRequest.post(uploadUrl).pipe(HttpClientRequest.bodyUint8Array(file.content, file.contentType)) + ).pipe(Effect.mapError((error) => Errors.chatError("post", Errors.transport(false, "upload_failed", error)))) + if (response.status < 200 || response.status >= 300) { + return yield* fail("post", Errors.reasonForStatus(response.status, { write: false })) + } + return { id: fileId, title: file.name } + }) + + /** The ts of the message that shared a fresh upload, from `files.info`. */ + const shareTs = (answer: Json, channel: string, threadTs: string | undefined): string | undefined => { + const file = isObject(answer) ? object(answer, "file") : undefined + const shares = file === undefined ? undefined : object(file, "shares") + if (shares === undefined) return undefined + for (const visibility of ["public", "private"]) { + const byChannel = object(shares, visibility) + const list = byChannel === undefined ? undefined : byChannel[channel] + if (!Array.isArray(list)) continue + for (const share of list) { + if (!isObject(share)) continue + const ts = string(share, "ts") + const shareThread = string(share, "thread_ts") + if ( + ts !== undefined && + (threadTs === undefined ? shareThread === undefined || shareThread === ts : shareThread === threadTs) + ) { + return ts + } + } + } + return undefined + } + + const postFiles = ( + thread: ChatThread, + parts: Address.Parts, + markdown: string, + files: ReadonlyArray, + notify: Escape.Notify + ): Effect.Effect => + Effect.gen(function*() { + if (files.length > descriptor.limits.filesPerMessage) { + return yield* fail("post", new TooLarge({ subject: "files", detail: "too_many_files" })) + } + if (files.some((file) => file.content.length > descriptor.limits.uploadBytes)) { + return yield* fail("post", new TooLarge({ subject: "files", detail: "file_too_large" })) + } + // A message with files takes no `markdown_text`: its text goes as mrkdwn. + const comment = markdown.trim() === "" ? undefined : Escape.toMrkdwn(markdown, notify) + if (comment !== undefined) yield* checkSent("post", comment, true) + const staged = yield* Effect.forEach(files, stage) + yield* call("post", "files.completeUploadExternal", { + files: staged, + channel_id: parts.channel, + thread_ts: parts.threadTs, + initial_comment: comment + }, { write: true }) + // The answer carries no message ts. Slack fills the file's shares soon after. + for (let attempt = 0; attempt < shareAttempts; attempt++) { + if (attempt > 0) yield* Effect.sleep(shareInterval) + const info = yield* call("post", "files.info", { file: staged[0].id }) + const ts = shareTs(info, parts.channel, parts.threadTs) + if (ts !== undefined) return { id: ts, thread, timestamp: Normalize.timestamp(ts) } + } + return yield* fail("post", new Unknown({ detail: "share_ts_unknown" })) + }) + + // History + + const page = (op: string, method: string, body: Record) => (cursor: string | undefined) => + call(op, method, { ...body, cursor }).pipe( + Effect.map((answer) => [messages(answer), nextCursor(answer)] as const) + ) + + const history: ChatAdapter["history"] = (thread, { direction, from }) => + Stream.unwrap(Effect.gen(function*() { + const parts = yield* resolve("history", thread) + const botUserId = yield* options.botUserId + const context = { team: teamId, channel: parts.channel, botUserId } + const after = (message: ChatMessage) => + from === undefined || + (direction === "forward" + ? Address.compareTs(message.id, from) > 0 + : Address.compareTs(message.id, from) < 0) + const normalized = (raw: Stream.Stream) => + raw.pipe( + Stream.map((message) => Normalize.message(message, context)), + Stream.filter((message): message is ChatMessage => message !== undefined && after(message)) + ) + const reversed = (stream: Stream.Stream) => + Stream.unwrap(Effect.map(Stream.runCollect(stream), (all) => Stream.fromIterable(Array.from(all).reverse()))) + if (parts.threadTs !== undefined) { + // Oldest first, from the thread's start. Slack puts the opener on every page. + const threadTs = parts.threadTs + const bound = from === undefined ? {} : direction === "forward" ? { oldest: from } : { latest: from } + const replies = page("history", "conversations.replies", { + channel: parts.channel, + ts: threadTs, + limit: pageSize, + ...bound + }) + const stream = normalized( + Stream.paginate(undefined as string | undefined, (cursor) => + Effect.map(replies(cursor), ([found, next]) => + [ + cursor === undefined + ? found + : found.filter((message) => !(isObject(message) && message.ts === threadTs)), + next + ] as const)) + ) + return direction === "forward" ? stream : reversed(stream) + } + // Newest first. A reply broadcast to the channel is the thread's. + const bound = from === undefined ? {} : direction === "forward" ? { oldest: from } : { latest: from } + const stream = normalized( + Stream.paginate( + undefined as string | undefined, + page("history", "conversations.history", { channel: parts.channel, limit: pageSize, ...bound }) + ) + ).pipe(Stream.filter((message) => message.thread.id === thread.id)) + return direction === "backward" ? stream : reversed(stream) + })) + + // Native stream + + const nativeStream: NonNullable = { + start: Effect.fnUntraced(function*(thread, start) { + const op = "nativeStream.start" + const postOptions = yield* CurrentPostOptions + if (postOptions.nativeStream === false) { + return yield* fail(op, new Unsupported({ capability: "nativeStream", detail: "disabled" })) + } + const parts = yield* resolve(op, thread) + if (parts.threadTs === undefined || start.recipient === undefined || start.replyTo !== undefined) { + return yield* fail(op, new Unsupported({ capability: "nativeStream" })) + } + const escaped = Escape.escape(start.markdown, postOptions.notify ?? {}, { flush: true }) + yield* checkSent(op, escaped.sent, true) + const answer = yield* call(op, "chat.startStream", { + channel: parts.channel, + thread_ts: parts.threadTs, + recipient_user_id: start.recipient, + recipient_team_id: postOptions.recipientTeamId ?? parts.team, + markdown_text: escaped.sent === "" ? undefined : escaped.sent + }, { write: true, retry: false }).pipe( + Effect.catchIf( + (error) => error.reason.detail !== undefined && streamUnsupported.has(error.reason.detail), + (error) => + fail( + op, + new Unsupported({ + capability: "nativeStream", + ...(error.reason.detail === undefined ? {} : { detail: error.reason.detail }), + cause: error + }) + ) + ) + ) + const ts = yield* tsOf(op, true)(answer) + streams.set(ts, { escape: escaped.state, text: escaped.sent, stopped: false }) + return { id: ts, thread, timestamp: Normalize.timestamp(ts) } + }), + append: Effect.fnUntraced(function*(thread, messageId, markdown, appendOptions) { + const op = "nativeStream.append" + const parts = yield* resolve(op, thread) + const postOptions = yield* CurrentPostOptions + const state = streams.get(messageId) ?? { escape: Escape.initialState, text: "", stopped: false } + const escaped = Escape.escape(markdown, postOptions.notify ?? {}, { + state: state.escape, + flush: appendOptions?.flush === true + }) + const held = markdown.length - escaped.consumed + if (escaped.sent === "") return { state: "open" as const, held } + yield* checkSent(op, state.text + escaped.sent, true) + return yield* call(op, "chat.appendStream", { + channel: parts.channel, + ts: messageId, + markdown_text: escaped.sent + }, { write: true, retry: false }).pipe( + Effect.map(() => { + streams.set(messageId, { escape: escaped.state, text: state.text + escaped.sent, stopped: false }) + return { state: "open" as const, held } + }), + Effect.catchIf( + hasDetail("message_not_in_streaming_state"), + () => Effect.succeed({ state: "closed" as const, held: 0 }) + ), + Effect.catchIf(hasDetail("stopped_by_user"), () => + Effect.sync(() => { + streams.set(messageId, { ...state, stopped: true }) + return { state: "stopped" as const, held: 0 } + })) + ) + }), + stop: Effect.fnUntraced(function*(thread, messageId, stopOptions) { + const op = "nativeStream.stop" + const parts = yield* resolve(op, thread) + const postOptions = yield* CurrentPostOptions + const state = streams.get(messageId) + streams.delete(messageId) + const status = stopOptions.end === "rotating" ? "processing" : postOptions.sessionStatusAtEnd + const body = { channel: parts.channel, ts: messageId } + const stop = status === undefined || !declaredAgent + ? call(op, "chat.stopStream", body, { write: true, retry: false }) + : call(op, "chat.stopStream", { ...body, session_status: status }, { write: true, retry: false }).pipe( + Effect.catchIf(hasDetail("not_authorized"), () => { + declaredAgent = false + return call(op, "chat.stopStream", body, { write: true, retry: false }) + }) + ) + const answer = yield* stop.pipe( + Effect.map(Option.some), + Effect.catchIf(hasDetail("message_not_in_streaming_state"), () => Effect.succeed(Option.none())) + ) + const message = Option.isSome(answer) && isObject(answer.value) ? object(answer.value, "message") : undefined + const context = message === undefined ? undefined : object(message, "ai_context") + const result = Option.isSome(answer) && isObject(answer.value) ? answer.value.result_status : undefined + const stopped = state?.stopped === true || result === "stopped_by_user" || + (context !== undefined && context.result_status === "stopped_by_user") + if (stopped && stopOptions.end === "done" && parts.threadTs !== undefined) { + yield* sessionStatus(parts.channel, parts.threadTs, postOptions.sessionStatusAtEnd ?? "active") + } + return { stopped } + }) + } + + // Users + + const user = (id: string): Effect.Effect => + call("user", "users.info", { user: id }).pipe( + Effect.flatMap((answer) => { + const raw = isObject(answer) ? object(answer, "user") : undefined + const userId = raw === undefined ? undefined : string(raw, "id") + if (raw === undefined || userId === undefined) { + return fail("user", Errors.invalidResponse(false, "missing_user")) + } + const userTeam = string(raw, "team_id") ?? teamId + return Effect.succeed({ + id: userId, + teamId: userTeam, + name: userName(raw), + isBot: raw.is_bot === true, + isRestricted: raw.is_restricted === true, + isUltraRestricted: raw.is_ultra_restricted === true, + isStranger: raw.is_stranger === true || (userTeam !== teamId && raw.enterprise_user === undefined), + deleted: raw.deleted === true, + raw + }) + }) + ) + + /** A `bot_message` author is a bot id, which `users.info` answers with `NotFound`. */ + const getUser: ChatAdapter["getUser"] = Effect.fnUntraced(function*(id) { + const botUserId = yield* options.botUserId + const found = yield* user(id).pipe(Effect.mapError(Errors.withOp("getUser"))) + return { id: found.id, name: found.name, isBot: found.isBot, isSelf: found.id === botUserId, raw: found.raw } + }) + + const adapter: ChatAdapter = { + descriptor, + nativeStream, + post: Effect.fnUntraced(function*(thread, content) { + const parts = yield* resolve("post", thread) + if (content.replyTo !== undefined) return yield* fail("post", new Unsupported({ capability: "replyTo" })) + const postOptions = yield* CurrentPostOptions + const notify = postOptions.notify ?? {} + if (content.files !== undefined && content.files.length > 0) { + return yield* postFiles(thread, parts, content.markdown, content.files, notify) + } + const sent = Escape.escape(content.markdown, notify, { flush: true }).sent + yield* checkSent("post", sent, true) + const unfurl = postOptions.unfurl === true + const ts = yield* call("post", "chat.postMessage", { + channel: parts.channel, + thread_ts: parts.threadTs, + markdown_text: sent, + unfurl_links: unfurl, + unfurl_media: unfurl + }, { write: true }).pipe(Effect.flatMap(tsOf("post", true))) + return { id: ts, thread, timestamp: Normalize.timestamp(ts) } + }), + edit: Effect.fnUntraced(function*(thread, messageId, content) { + const parts = yield* resolve("edit", thread) + const postOptions = yield* CurrentPostOptions + const sent = Escape.escape(content.markdown, postOptions.notify ?? {}, { flush: true }).sent + // Slack does not apply its emoji limit to `chat.update`. + yield* checkSent("edit", sent, false) + yield* call("edit", "chat.update", { channel: parts.channel, ts: messageId, markdown_text: sent }, { + write: true + }) + }), + delete: Effect.fnUntraced(function*(thread, messageId) { + const parts = yield* resolve("delete", thread) + const body = { channel: parts.channel, ts: messageId } + yield* call("delete", "chat.delete", body, { write: true }).pipe( + // Slack refuses to delete an open stream: stop it, then delete. + Effect.catchIf( + hasDetail("cant_delete_message"), + (error) => + call("delete", "chat.stopStream", body, { write: true, retry: false }).pipe( + Effect.matchEffect({ + onFailure: () => Effect.fail(error), + onSuccess: () => { + streams.delete(messageId) + return call("delete", "chat.delete", body, { write: true }) + } + }) + ) + ) + ) + }), + fetchMessage: (thread, messageId) => fetchMessage("fetchMessage", thread, messageId), + history, + download: (thread, attachment, { maxBytes }) => + Stream.unwrap(Effect.gen(function*() { + const op = "download" + yield* resolve(op, thread) + const tooLarge = Errors.chatError(op, new TooLarge({ subject: "files", detail: "max_bytes" })) + if (attachment.size !== undefined && attachment.size > maxBytes) return yield* Effect.fail(tooLarge) + const answer = yield* call(op, "files.info", { file: attachment.id }) + const file = isObject(answer) ? object(answer, "file") : undefined + const url = file === undefined ? undefined : string(file, "url_private_download") ?? string(file, "url_private") + if (url === undefined) return yield* fail(op, Errors.invalidResponse(false, "missing_url")) + const response = yield* options.http.execute( + HttpClientRequest.get(url).pipe(HttpClientRequest.bearerToken(Redacted.value(options.botToken))) + ).pipe(Effect.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag, error)))) + if (response.status < 200 || response.status >= 300) { + return yield* fail(op, Errors.reasonForStatus(response.status, { write: false })) + } + let received = 0 + return response.stream.pipe( + Stream.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag, error))), + Stream.mapEffect((chunk) => { + received += chunk.length + return received > maxBytes ? Effect.fail(tooLarge) : Effect.succeed(chunk) + }) + ) + })), + startThread: (thread, messageId) => + resolve("startThread", thread).pipe( + Effect.map((parts) => + parts.threadTs === undefined + ? Address.thread({ team: parts.team, channel: parts.channel, threadTs: messageId }) + : thread + ) + ), + getThread: Effect.fnUntraced(function*(thread) { + const parts = yield* resolve("getThread", thread) + const answer = yield* call("getThread", "conversations.info", { channel: parts.channel }) + const channel = isObject(answer) ? object(answer, "channel") : undefined + if (channel === undefined) return yield* fail("getThread", Errors.invalidResponse(false, "missing_channel")) + const direct = channel.is_im === true || channel.is_mpim === true + const topic = object(channel, "topic") + const topicValue = topic === undefined ? undefined : string(topic, "value") + const name = direct ? undefined : string(channel, "name") + const created = channel.created + const createdAt = parts.threadTs !== undefined + ? Normalize.timestamp(parts.threadTs) + : typeof created === "number" && Number.isFinite(created) + ? DateTime.makeUnsafe(created * 1000) + : undefined + return { + thread, + kind: parts.threadTs !== undefined ? "thread" : direct ? "direct" : "channel", + ...(parts.threadTs === undefined && name !== undefined ? { name } : {}), + ...(parts.threadTs === undefined && topicValue !== undefined ? { topic: topicValue } : {}), + ...(parts.threadTs === undefined + ? {} + : { parent: Address.thread({ team: parts.team, channel: parts.channel }) }), + ...(createdAt === undefined ? {} : { createdAt }), + raw: channel + } satisfies ThreadInfo + }), + opener: Effect.fnUntraced(function*(thread) { + const parts = yield* resolve("opener", thread) + if (parts.threadTs === undefined) return Option.none() + const channelAddress = Address.thread({ team: parts.team, channel: parts.channel }) + return yield* fetchMessage("opener", channelAddress, parts.threadTs).pipe( + Effect.map(Option.some), + Effect.catchIf((error) => error.reason._tag === "NotFound", () => Effect.succeed(Option.none())) + ) + }), + getUser + } + + return { adapter, user } +} diff --git a/packages/chat/slack/src/internal/address.ts b/packages/chat/slack/src/internal/address.ts new file mode 100644 index 00000000000..0854cb5e0c7 --- /dev/null +++ b/packages/chat/slack/src/internal/address.ts @@ -0,0 +1,50 @@ +import * as ChatThread from "effect/chat/ChatThread" +import * as Option from "effect/Option" + +/** @internal */ +export const platform = "slack" + +/** @internal */ +export interface Parts { + readonly team: string + readonly channel: string + readonly threadTs?: string | undefined +} + +/** @internal */ +export const thread = (parts: Parts): ChatThread.ChatThread => + ChatThread.make( + platform, + parts.threadTs === undefined + ? `${parts.team}/${parts.channel}` + : `${parts.team}/${parts.channel}/${parts.threadTs}` + ) + +/** @internal */ +export const parts = (address: ChatThread.ChatThread): Option.Option => { + if (address.platform !== platform) return Option.none() + const segments = address.id.split("/") + if (segments.length < 2 || segments.length > 3 || segments.some((segment) => segment.length === 0)) { + return Option.none() + } + return Option.some( + segments.length === 2 + ? { team: segments[0], channel: segments[1] } + : { team: segments[0], channel: segments[1], threadTs: segments[2] } + ) +} + +/** @internal */ +export const isDirectChannel = (channel: string): boolean => channel.startsWith("D") + +/** Compares two Slack `ts` values in time order. @internal */ +export const compareTs = (a: string, b: string): number => { + const [aSeconds, aMicros = ""] = a.split(".") + const [bSeconds, bMicros = ""] = b.split(".") + const seconds = Number(aSeconds) - Number(bSeconds) + if (seconds !== 0) return seconds < 0 ? -1 : 1 + const width = Math.max(aMicros.length, bMicros.length) + const left = aMicros.padEnd(width, "0") + const right = bMicros.padEnd(width, "0") + return left < right ? -1 : left > right ? 1 : 0 +} diff --git a/packages/chat/slack/src/internal/emoji.ts b/packages/chat/slack/src/internal/emoji.ts new file mode 100644 index 00000000000..837ea0e6b62 --- /dev/null +++ b/packages/chat/slack/src/internal/emoji.ts @@ -0,0 +1,204 @@ +import { emojiData } from "./emojiData.ts" + +interface Entry { + readonly unified: string + /** skin_variations keyed by Slack tone digits: "3" or "23" */ + readonly variations: ReadonlyMap +} + +interface Table { + readonly byName: ReadonlyMap + /** Emoji string (unified or non_qualified, toned or not) to Slack name without colons */ + readonly bySequence: ReadonlyMap + /** First code point of a multi code point sequence to its UTF-16 lengths, longest first */ + readonly lengthsByFirst: ReadonlyMap> + /** Cost of a lone surrogate, the highest cost of any single code point emoji */ + readonly loneSurrogateCost: number +} + +const decode = (sequence: string): string => { + const codePoints = sequence.split("-") + let out = "" + for (let i = 0; i < codePoints.length; i++) out += String.fromCodePoint(parseInt(codePoints[i], 16)) + return out +} + +const withoutVariationSelector = (emoji: string): string => emoji.replaceAll("\uFE0F", "") + +const toneSuffix = (tones: string): string => { + let out = "" + for (let i = 0; i < tones.length; i++) out += "::skin-tone-" + tones[i] + return out +} + +// Decoded by hand: optimised String.prototype.codePointAt returned wrong values +// around lone surrogates on Node 26.8 (V8), which broke blocksCost. +const codePointAt = (text: string, index: number): number => { + const high = text.charCodeAt(index) + if (high < 0xd800 || high > 0xdbff || index + 1 >= text.length) return high + const low = text.charCodeAt(index + 1) + return low < 0xdc00 || low > 0xdfff ? high : (high - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000 +} + +const build = (): Table => { + const byName = new Map() + const bySequence = new Map() + const lengths = new Map>() + let loneSurrogateCost = 0 + + const addSequence = (emoji: string, name: string) => { + bySequence.set(emoji, name) + const first = codePointAt(emoji, 0) + if (emoji.length > (first > 0xffff ? 2 : 1)) { + let set = lengths.get(first) + if (set === undefined) lengths.set(first, set = new Set()) + set.add(emoji.length) + } else { + loneSurrogateCost = Math.max(loneSurrogateCost, name.length + 2) + } + } + + for (const line of emojiData.split("\n")) { + const [names, unifiedHex, nonQualified, variationGroups] = line.split("|") + const shortNames = names.split(",") + const shortName = shortNames[0] + const unified = decode(unifiedHex) + addSequence(unified, shortName) + if (nonQualified !== "") { + addSequence(nonQualified === "!" ? withoutVariationSelector(unified) : decode(nonQualified), shortName) + } + const variations = new Map() + if (variationGroups !== undefined) { + for (const group of variationGroups.split(";")) { + const [keys, template, variationNonQualified] = group.split(":") + for (const tones of keys.split(",")) { + let index = 0 + const variation = decode( + template.replace(/\*/g, () => (0x1f3fb + Number(tones[index++]) - 2).toString(16)) + ) + variations.set(tones, variation) + const name = shortName + toneSuffix(tones) + addSequence(variation, name) + if (variationNonQualified === "!") addSequence(withoutVariationSelector(variation), name) + } + } + } + const entry: Entry = { unified, variations } + for (const name of shortNames) byName.set(name, entry) + } + + const lengthsByFirst = new Map>() + for (const [first, set] of lengths) lengthsByFirst.set(first, [...set].sort((a, b) => b - a)) + + return { byName, bySequence, lengthsByFirst, loneSurrogateCost } +} + +let cached: Table | undefined +const table = (): Table => cached ??= build() + +const SKIN_TONE = /^skin-tone-([2-6])$/ + +/** + * Resolve a Slack emoji name to its fully qualified emoji. + * + * Accepts any alias, with or without surrounding colons, followed by up to + * two `::skin-tone-N` suffixes (`+1::skin-tone-3`, + * `handshake::skin-tone-2::skin-tone-5`). Toned emoji come from upstream + * `skin_variations` only; a tone the emoji does not have yields `undefined`. + * Two equal tones and a single tone are treated as the same request, since + * upstream keys some emoji one way (`handshake`) and some the other + * (`people_holding_hands`). + * + * @internal + */ +export const fromName = (name: string): string | undefined => { + const bare = name.length >= 2 && name.startsWith(":") && name.endsWith(":") ? name.slice(1, -1) : name + const parts = bare.split("::") + const entry = table().byName.get(parts[0]) + if (entry === undefined) return undefined + if (parts.length === 1) return entry.unified + if (parts.length > 3) return undefined + let tones = "" + for (let i = 1; i < parts.length; i++) { + const match = SKIN_TONE.exec(parts[i]) + if (match === null) return undefined + tones += match[1] + } + const exact = entry.variations.get(tones) + if (exact !== undefined) return exact + if (tones.length === 1) return entry.variations.get(tones + tones) + return tones[0] === tones[1] ? entry.variations.get(tones[0]) : undefined +} + +/** + * Resolve an emoji (fully qualified or not, toned or not) to its primary Slack + * name without colons, for example `+1` or `+1::skin-tone-3`. + * + * @internal + */ +export const toName = (emoji: string): string | undefined => table().bySequence.get(emoji) + +// Code points that are never an emoji on their own but join or modify emoji +// sequences. Charging them more than one keeps blocksCost subadditive: an +// emoji sequence split anywhere costs at least as much as the whole sequence. +const ZERO_WIDTH_JOINER = 0x200d +const COMBINING_ENCLOSING_KEYCAP = 0x20e3 +const ZERO_WIDTH_JOINER_COST = 10 +const COMBINING_ENCLOSING_KEYCAP_COST = 12 +const REGIONAL_INDICATOR_COST = 6 +const HAIR_COMPONENT_COST = 4 + +const codePointCost = (codePoint: number, loneSurrogateCost: number): number => { + if (codePoint === ZERO_WIDTH_JOINER) return ZERO_WIDTH_JOINER_COST + if (codePoint === COMBINING_ENCLOSING_KEYCAP) return COMBINING_ENCLOSING_KEYCAP_COST + if (codePoint >= 0x1f1e6 && codePoint <= 0x1f1ff) return REGIONAL_INDICATOR_COST + if (codePoint >= 0x1f9b0 && codePoint <= 0x1f9b3) return HAIR_COMPONENT_COST + if (codePoint >= 0xd800 && codePoint <= 0xdfff) return loneSurrogateCost + return 1 +} + +/** + * Measure text the way Slack counts it against the 13,200 character + * `msg_blocks_too_long` limit: every emoji counts as its `:short_name:` form + * (`👍🏽` is `:+1::skin-tone-4:`, 17), everything else as one per code point. + * + * The result is the cheapest split of the text into emoji and single code + * points. For every emoji in the table this is exactly its `:short_name:` + * length, and since the cheapest split of `a + b` is at most the cheapest split + * of `a` followed by that of `b`, `blocksCost(a + b) <= blocksCost(a) + + * blocksCost(b)` for all strings. To keep that true when a split lands inside an + * emoji, code points that only occur inside emoji sequences (zero width + * joiner, keycap, regional indicators, hair components) cost more than one + * when they stand alone, and so does a lone surrogate. + * + * Runs in O(text length × candidate sequence lengths). + * + * @internal + */ +export const blocksCost = (text: string): number => { + const { bySequence, lengthsByFirst, loneSurrogateCost } = table() + const length = text.length + // costs[i] is the cheapest cost of text.slice(0, i), -1 when i is inside a code point + const costs = new Int32Array(length + 1).fill(-1) + costs[0] = 0 + for (let i = 0; i < length; i++) { + const before = costs[i] + if (before < 0) continue + const codePoint = codePointAt(text, i) + const width = codePoint > 0xffff ? 2 : 1 + const single = bySequence.get(text.slice(i, i + width)) + const singleCost = before + (single === undefined ? codePointCost(codePoint, loneSurrogateCost) : single.length + 2) + if (costs[i + width] < 0 || singleCost < costs[i + width]) costs[i + width] = singleCost + const candidates = lengthsByFirst.get(codePoint) + if (candidates === undefined) continue + for (const candidate of candidates) { + const end = i + candidate + if (end > length) continue + const name = bySequence.get(text.slice(i, end)) + if (name === undefined) continue + const cost = before + name.length + 2 + if (costs[end] < 0 || cost < costs[end]) costs[end] = cost + } + } + return costs[length] +} diff --git a/packages/chat/slack/src/internal/emojiData.ts b/packages/chat/slack/src/internal/emojiData.ts new file mode 100644 index 00000000000..6ba13f3eb8a --- /dev/null +++ b/packages/chat/slack/src/internal/emojiData.ts @@ -0,0 +1,1965 @@ +/** + * Slack emoji short names and code point sequences. + * + * Generated by scripts/generate-emoji.mjs. Do not edit. + * + * Source: + * - Project: iamcal/emoji-data + * - Tag: v16.0.0 + * - Commit: 2771d0b1b3af25c069086e68e38f901c3dda8bdf + * - URL: https://raw.githubusercontent.com/iamcal/emoji-data/2771d0b1b3af25c069086e68e38f901c3dda8bdf/emoji.json + * - SHA-256: 1d602e65be88772bf8cc368ce16b855d719eeddbafe128d471b80203f494d29f + * - Size: 1313457 bytes + * - License: MIT (reproduced below) + * + * Format: one emoji per line (1911 emoji, 1972 short names, 1875 skin tone variations), sorted by unified: + * + * short_names|unified|non_qualified[|variations] + * + * - short_names: comma separated, the first one is short_name + * - unified: lowercase hex code points joined by "-" + * - non_qualified: empty for none, "!" for unified without U+FE0F, otherwise + * a code point sequence + * - variations: ";" separated groups of skin_variations entries, each + * keys:template[:non_qualified]. keys is a comma separated list of upstream + * skin_variations keys, written as one Slack skin-tone-N digit (2-6) per + * modifier. template is the variation's unified sequence with each modifier + * replaced by "*", filled in key order. non_qualified is empty or "!" + * + * The MIT License (MIT) + * + * Copyright (c) 2013 Cal Henderson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * @internal + */ + +/** @internal */ +export const emojiData = `hash|0023-fe0f-20e3|! +keycap_star|002a-fe0f-20e3|! +zero|0030-fe0f-20e3|! +one|0031-fe0f-20e3|! +two|0032-fe0f-20e3|! +three|0033-fe0f-20e3|! +four|0034-fe0f-20e3|! +five|0035-fe0f-20e3|! +six|0036-fe0f-20e3|! +seven|0037-fe0f-20e3|! +eight|0038-fe0f-20e3|! +nine|0039-fe0f-20e3|! +copyright|00a9-fe0f|! +registered|00ae-fe0f|! +mahjong|1f004| +black_joker|1f0cf| +a|1f170-fe0f|! +b|1f171-fe0f|! +o2|1f17e-fe0f|! +parking|1f17f-fe0f|! +ab|1f18e| +cl|1f191| +cool|1f192| +free|1f193| +id|1f194| +new|1f195| +ng|1f196| +ok|1f197| +sos|1f198| +up|1f199| +vs|1f19a| +flag-ac|1f1e6-1f1e8| +flag-ad|1f1e6-1f1e9| +flag-ae|1f1e6-1f1ea| +flag-af|1f1e6-1f1eb| +flag-ag|1f1e6-1f1ec| +flag-ai|1f1e6-1f1ee| +flag-al|1f1e6-1f1f1| +flag-am|1f1e6-1f1f2| +flag-ao|1f1e6-1f1f4| +flag-aq|1f1e6-1f1f6| +flag-ar|1f1e6-1f1f7| +flag-as|1f1e6-1f1f8| +flag-at|1f1e6-1f1f9| +flag-au|1f1e6-1f1fa| +flag-aw|1f1e6-1f1fc| +flag-ax|1f1e6-1f1fd| +flag-az|1f1e6-1f1ff| +flag-ba|1f1e7-1f1e6| +flag-bb|1f1e7-1f1e7| +flag-bd|1f1e7-1f1e9| +flag-be|1f1e7-1f1ea| +flag-bf|1f1e7-1f1eb| +flag-bg|1f1e7-1f1ec| +flag-bh|1f1e7-1f1ed| +flag-bi|1f1e7-1f1ee| +flag-bj|1f1e7-1f1ef| +flag-bl|1f1e7-1f1f1| +flag-bm|1f1e7-1f1f2| +flag-bn|1f1e7-1f1f3| +flag-bo|1f1e7-1f1f4| +flag-bq|1f1e7-1f1f6| +flag-br|1f1e7-1f1f7| +flag-bs|1f1e7-1f1f8| +flag-bt|1f1e7-1f1f9| +flag-bv|1f1e7-1f1fb| +flag-bw|1f1e7-1f1fc| +flag-by|1f1e7-1f1fe| +flag-bz|1f1e7-1f1ff| +flag-ca|1f1e8-1f1e6| +flag-cc|1f1e8-1f1e8| +flag-cd|1f1e8-1f1e9| +flag-cf|1f1e8-1f1eb| +flag-cg|1f1e8-1f1ec| +flag-ch|1f1e8-1f1ed| +flag-ci|1f1e8-1f1ee| +flag-ck|1f1e8-1f1f0| +flag-cl|1f1e8-1f1f1| +flag-cm|1f1e8-1f1f2| +cn,flag-cn|1f1e8-1f1f3| +flag-co|1f1e8-1f1f4| +flag-cp|1f1e8-1f1f5| +flag-sark|1f1e8-1f1f6| +flag-cr|1f1e8-1f1f7| +flag-cu|1f1e8-1f1fa| +flag-cv|1f1e8-1f1fb| +flag-cw|1f1e8-1f1fc| +flag-cx|1f1e8-1f1fd| +flag-cy|1f1e8-1f1fe| +flag-cz|1f1e8-1f1ff| +de,flag-de|1f1e9-1f1ea| +flag-dg|1f1e9-1f1ec| +flag-dj|1f1e9-1f1ef| +flag-dk|1f1e9-1f1f0| +flag-dm|1f1e9-1f1f2| +flag-do|1f1e9-1f1f4| +flag-dz|1f1e9-1f1ff| +flag-ea|1f1ea-1f1e6| +flag-ec|1f1ea-1f1e8| +flag-ee|1f1ea-1f1ea| +flag-eg|1f1ea-1f1ec| +flag-eh|1f1ea-1f1ed| +flag-er|1f1ea-1f1f7| +es,flag-es|1f1ea-1f1f8| +flag-et|1f1ea-1f1f9| +flag-eu|1f1ea-1f1fa| +flag-fi|1f1eb-1f1ee| +flag-fj|1f1eb-1f1ef| +flag-fk|1f1eb-1f1f0| +flag-fm|1f1eb-1f1f2| +flag-fo|1f1eb-1f1f4| +fr,flag-fr|1f1eb-1f1f7| +flag-ga|1f1ec-1f1e6| +gb,uk,flag-gb|1f1ec-1f1e7| +flag-gd|1f1ec-1f1e9| +flag-ge|1f1ec-1f1ea| +flag-gf|1f1ec-1f1eb| +flag-gg|1f1ec-1f1ec| +flag-gh|1f1ec-1f1ed| +flag-gi|1f1ec-1f1ee| +flag-gl|1f1ec-1f1f1| +flag-gm|1f1ec-1f1f2| +flag-gn|1f1ec-1f1f3| +flag-gp|1f1ec-1f1f5| +flag-gq|1f1ec-1f1f6| +flag-gr|1f1ec-1f1f7| +flag-gs|1f1ec-1f1f8| +flag-gt|1f1ec-1f1f9| +flag-gu|1f1ec-1f1fa| +flag-gw|1f1ec-1f1fc| +flag-gy|1f1ec-1f1fe| +flag-hk|1f1ed-1f1f0| +flag-hm|1f1ed-1f1f2| +flag-hn|1f1ed-1f1f3| +flag-hr|1f1ed-1f1f7| +flag-ht|1f1ed-1f1f9| +flag-hu|1f1ed-1f1fa| +flag-ic|1f1ee-1f1e8| +flag-id|1f1ee-1f1e9| +flag-ie|1f1ee-1f1ea| +flag-il|1f1ee-1f1f1| +flag-im|1f1ee-1f1f2| +flag-in|1f1ee-1f1f3| +flag-io|1f1ee-1f1f4| +flag-iq|1f1ee-1f1f6| +flag-ir|1f1ee-1f1f7| +flag-is|1f1ee-1f1f8| +it,flag-it|1f1ee-1f1f9| +flag-je|1f1ef-1f1ea| +flag-jm|1f1ef-1f1f2| +flag-jo|1f1ef-1f1f4| +jp,flag-jp|1f1ef-1f1f5| +flag-ke|1f1f0-1f1ea| +flag-kg|1f1f0-1f1ec| +flag-kh|1f1f0-1f1ed| +flag-ki|1f1f0-1f1ee| +flag-km|1f1f0-1f1f2| +flag-kn|1f1f0-1f1f3| +flag-kp|1f1f0-1f1f5| +kr,flag-kr|1f1f0-1f1f7| +flag-kw|1f1f0-1f1fc| +flag-ky|1f1f0-1f1fe| +flag-kz|1f1f0-1f1ff| +flag-la|1f1f1-1f1e6| +flag-lb|1f1f1-1f1e7| +flag-lc|1f1f1-1f1e8| +flag-li|1f1f1-1f1ee| +flag-lk|1f1f1-1f1f0| +flag-lr|1f1f1-1f1f7| +flag-ls|1f1f1-1f1f8| +flag-lt|1f1f1-1f1f9| +flag-lu|1f1f1-1f1fa| +flag-lv|1f1f1-1f1fb| +flag-ly|1f1f1-1f1fe| +flag-ma|1f1f2-1f1e6| +flag-mc|1f1f2-1f1e8| +flag-md|1f1f2-1f1e9| +flag-me|1f1f2-1f1ea| +flag-mf|1f1f2-1f1eb| +flag-mg|1f1f2-1f1ec| +flag-mh|1f1f2-1f1ed| +flag-mk|1f1f2-1f1f0| +flag-ml|1f1f2-1f1f1| +flag-mm|1f1f2-1f1f2| +flag-mn|1f1f2-1f1f3| +flag-mo|1f1f2-1f1f4| +flag-mp|1f1f2-1f1f5| +flag-mq|1f1f2-1f1f6| +flag-mr|1f1f2-1f1f7| +flag-ms|1f1f2-1f1f8| +flag-mt|1f1f2-1f1f9| +flag-mu|1f1f2-1f1fa| +flag-mv|1f1f2-1f1fb| +flag-mw|1f1f2-1f1fc| +flag-mx|1f1f2-1f1fd| +flag-my|1f1f2-1f1fe| +flag-mz|1f1f2-1f1ff| +flag-na|1f1f3-1f1e6| +flag-nc|1f1f3-1f1e8| +flag-ne|1f1f3-1f1ea| +flag-nf|1f1f3-1f1eb| +flag-ng|1f1f3-1f1ec| +flag-ni|1f1f3-1f1ee| +flag-nl|1f1f3-1f1f1| +flag-no|1f1f3-1f1f4| +flag-np|1f1f3-1f1f5| +flag-nr|1f1f3-1f1f7| +flag-nu|1f1f3-1f1fa| +flag-nz|1f1f3-1f1ff| +flag-om|1f1f4-1f1f2| +flag-pa|1f1f5-1f1e6| +flag-pe|1f1f5-1f1ea| +flag-pf|1f1f5-1f1eb| +flag-pg|1f1f5-1f1ec| +flag-ph|1f1f5-1f1ed| +flag-pk|1f1f5-1f1f0| +flag-pl|1f1f5-1f1f1| +flag-pm|1f1f5-1f1f2| +flag-pn|1f1f5-1f1f3| +flag-pr|1f1f5-1f1f7| +flag-ps|1f1f5-1f1f8| +flag-pt|1f1f5-1f1f9| +flag-pw|1f1f5-1f1fc| +flag-py|1f1f5-1f1fe| +flag-qa|1f1f6-1f1e6| +flag-re|1f1f7-1f1ea| +flag-ro|1f1f7-1f1f4| +flag-rs|1f1f7-1f1f8| +ru,flag-ru|1f1f7-1f1fa| +flag-rw|1f1f7-1f1fc| +flag-sa|1f1f8-1f1e6| +flag-sb|1f1f8-1f1e7| +flag-sc|1f1f8-1f1e8| +flag-sd|1f1f8-1f1e9| +flag-se|1f1f8-1f1ea| +flag-sg|1f1f8-1f1ec| +flag-sh|1f1f8-1f1ed| +flag-si|1f1f8-1f1ee| +flag-sj|1f1f8-1f1ef| +flag-sk|1f1f8-1f1f0| +flag-sl|1f1f8-1f1f1| +flag-sm|1f1f8-1f1f2| +flag-sn|1f1f8-1f1f3| +flag-so|1f1f8-1f1f4| +flag-sr|1f1f8-1f1f7| +flag-ss|1f1f8-1f1f8| +flag-st|1f1f8-1f1f9| +flag-sv|1f1f8-1f1fb| +flag-sx|1f1f8-1f1fd| +flag-sy|1f1f8-1f1fe| +flag-sz|1f1f8-1f1ff| +flag-ta|1f1f9-1f1e6| +flag-tc|1f1f9-1f1e8| +flag-td|1f1f9-1f1e9| +flag-tf|1f1f9-1f1eb| +flag-tg|1f1f9-1f1ec| +flag-th|1f1f9-1f1ed| +flag-tj|1f1f9-1f1ef| +flag-tk|1f1f9-1f1f0| +flag-tl|1f1f9-1f1f1| +flag-tm|1f1f9-1f1f2| +flag-tn|1f1f9-1f1f3| +flag-to|1f1f9-1f1f4| +flag-tr|1f1f9-1f1f7| +flag-tt|1f1f9-1f1f9| +flag-tv|1f1f9-1f1fb| +flag-tw|1f1f9-1f1fc| +flag-tz|1f1f9-1f1ff| +flag-ua|1f1fa-1f1e6| +flag-ug|1f1fa-1f1ec| +flag-um|1f1fa-1f1f2| +flag-un|1f1fa-1f1f3| +us,flag-us|1f1fa-1f1f8| +flag-uy|1f1fa-1f1fe| +flag-uz|1f1fa-1f1ff| +flag-va|1f1fb-1f1e6| +flag-vc|1f1fb-1f1e8| +flag-ve|1f1fb-1f1ea| +flag-vg|1f1fb-1f1ec| +flag-vi|1f1fb-1f1ee| +flag-vn|1f1fb-1f1f3| +flag-vu|1f1fb-1f1fa| +flag-wf|1f1fc-1f1eb| +flag-ws|1f1fc-1f1f8| +flag-xk|1f1fd-1f1f0| +flag-ye|1f1fe-1f1ea| +flag-yt|1f1fe-1f1f9| +flag-za|1f1ff-1f1e6| +flag-zm|1f1ff-1f1f2| +flag-zw|1f1ff-1f1fc| +koko|1f201| +sa|1f202-fe0f|! +u7121|1f21a| +u6307|1f22f| +u7981|1f232| +u7a7a|1f233| +u5408|1f234| +u6e80|1f235| +u6709|1f236| +u6708|1f237-fe0f|! +u7533|1f238| +u5272|1f239| +u55b6|1f23a| +ideograph_advantage|1f250| +accept|1f251| +cyclone|1f300| +foggy|1f301| +closed_umbrella|1f302| +night_with_stars|1f303| +sunrise_over_mountains|1f304| +sunrise|1f305| +city_sunset|1f306| +city_sunrise|1f307| +rainbow|1f308| +bridge_at_night|1f309| +ocean|1f30a| +volcano|1f30b| +milky_way|1f30c| +earth_africa|1f30d| +earth_americas|1f30e| +earth_asia|1f30f| +globe_with_meridians|1f310| +new_moon|1f311| +waxing_crescent_moon|1f312| +first_quarter_moon|1f313| +moon,waxing_gibbous_moon|1f314| +full_moon|1f315| +waning_gibbous_moon|1f316| +last_quarter_moon|1f317| +waning_crescent_moon|1f318| +crescent_moon|1f319| +new_moon_with_face|1f31a| +first_quarter_moon_with_face|1f31b| +last_quarter_moon_with_face|1f31c| +full_moon_with_face|1f31d| +sun_with_face|1f31e| +star2|1f31f| +stars|1f320| +thermometer|1f321-fe0f|! +mostly_sunny,sun_small_cloud|1f324-fe0f|! +barely_sunny,sun_behind_cloud|1f325-fe0f|! +partly_sunny_rain,sun_behind_rain_cloud|1f326-fe0f|! +rain_cloud|1f327-fe0f|! +snow_cloud|1f328-fe0f|! +lightning,lightning_cloud|1f329-fe0f|! +tornado,tornado_cloud|1f32a-fe0f|! +fog|1f32b-fe0f|! +wind_blowing_face|1f32c-fe0f|! +hotdog|1f32d| +taco|1f32e| +burrito|1f32f| +chestnut|1f330| +seedling|1f331| +evergreen_tree|1f332| +deciduous_tree|1f333| +palm_tree|1f334| +cactus|1f335| +hot_pepper|1f336-fe0f|! +tulip|1f337| +cherry_blossom|1f338| +rose|1f339| +hibiscus|1f33a| +sunflower|1f33b| +blossom|1f33c| +corn|1f33d| +ear_of_rice|1f33e| +herb|1f33f| +four_leaf_clover|1f340| +maple_leaf|1f341| +fallen_leaf|1f342| +leaves|1f343| +mushroom|1f344| +brown_mushroom|1f344-200d-1f7eb| +tomato|1f345| +eggplant|1f346| +grapes|1f347| +melon|1f348| +watermelon|1f349| +tangerine|1f34a| +lemon|1f34b| +lime|1f34b-200d-1f7e9| +banana|1f34c| +pineapple|1f34d| +apple|1f34e| +green_apple|1f34f| +pear|1f350| +peach|1f351| +cherries|1f352| +strawberry|1f353| +hamburger|1f354| +pizza|1f355| +meat_on_bone|1f356| +poultry_leg|1f357| +rice_cracker|1f358| +rice_ball|1f359| +rice|1f35a| +curry|1f35b| +ramen|1f35c| +spaghetti|1f35d| +bread|1f35e| +fries|1f35f| +sweet_potato|1f360| +dango|1f361| +oden|1f362| +sushi|1f363| +fried_shrimp|1f364| +fish_cake|1f365| +icecream|1f366| +shaved_ice|1f367| +ice_cream|1f368| +doughnut|1f369| +cookie|1f36a| +chocolate_bar|1f36b| +candy|1f36c| +lollipop|1f36d| +custard|1f36e| +honey_pot|1f36f| +cake|1f370| +bento|1f371| +stew|1f372| +fried_egg,cooking|1f373| +fork_and_knife|1f374| +tea|1f375| +sake|1f376| +wine_glass|1f377| +cocktail|1f378| +tropical_drink|1f379| +beer|1f37a| +beers|1f37b| +baby_bottle|1f37c| +knife_fork_plate|1f37d-fe0f|! +champagne|1f37e| +popcorn|1f37f| +ribbon|1f380| +gift|1f381| +birthday|1f382| +jack_o_lantern|1f383| +christmas_tree|1f384| +santa|1f385||2,3,4,5,6:1f385-* +fireworks|1f386| +sparkler|1f387| +balloon|1f388| +tada|1f389| +confetti_ball|1f38a| +tanabata_tree|1f38b| +crossed_flags|1f38c| +bamboo|1f38d| +dolls|1f38e| +flags|1f38f| +wind_chime|1f390| +rice_scene|1f391| +school_satchel|1f392| +mortar_board|1f393| +medal|1f396-fe0f|! +reminder_ribbon|1f397-fe0f|! +studio_microphone|1f399-fe0f|! +level_slider|1f39a-fe0f|! +control_knobs|1f39b-fe0f|! +film_frames|1f39e-fe0f|! +admission_tickets|1f39f-fe0f|! +carousel_horse|1f3a0| +ferris_wheel|1f3a1| +roller_coaster|1f3a2| +fishing_pole_and_fish|1f3a3| +microphone|1f3a4| +movie_camera|1f3a5| +cinema|1f3a6| +headphones|1f3a7| +art|1f3a8| +tophat|1f3a9| +circus_tent|1f3aa| +ticket|1f3ab| +clapper|1f3ac| +performing_arts|1f3ad| +video_game|1f3ae| +dart|1f3af| +slot_machine|1f3b0| +8ball|1f3b1| +game_die|1f3b2| +bowling|1f3b3| +flower_playing_cards|1f3b4| +musical_note|1f3b5| +notes|1f3b6| +saxophone|1f3b7| +guitar|1f3b8| +musical_keyboard|1f3b9| +trumpet|1f3ba| +violin|1f3bb| +musical_score|1f3bc| +running_shirt_with_sash|1f3bd| +tennis|1f3be| +ski|1f3bf| +basketball|1f3c0| +checkered_flag|1f3c1| +snowboarder|1f3c2||2,3,4,5,6:1f3c2-* +runner,running|1f3c3||2,3,4,5,6:1f3c3-* +woman-running|1f3c3-200d-2640-fe0f|!|2,3,4,5,6:1f3c3-*-200d-2640-fe0f:! +woman_running_facing_right|1f3c3-200d-2640-fe0f-200d-27a1-fe0f|!|2,3,4,5,6:1f3c3-*-200d-2640-fe0f-200d-27a1-fe0f:! +man-running|1f3c3-200d-2642-fe0f|!|2,3,4,5,6:1f3c3-*-200d-2642-fe0f:! +man_running_facing_right|1f3c3-200d-2642-fe0f-200d-27a1-fe0f|!|2,3,4,5,6:1f3c3-*-200d-2642-fe0f-200d-27a1-fe0f:! +person_running_facing_right|1f3c3-200d-27a1-fe0f|!|2,3,4,5,6:1f3c3-*-200d-27a1-fe0f:! +surfer|1f3c4||2,3,4,5,6:1f3c4-* +woman-surfing|1f3c4-200d-2640-fe0f|!|2,3,4,5,6:1f3c4-*-200d-2640-fe0f:! +man-surfing|1f3c4-200d-2642-fe0f|!|2,3,4,5,6:1f3c4-*-200d-2642-fe0f:! +sports_medal|1f3c5| +trophy|1f3c6| +horse_racing|1f3c7||2,3,4,5,6:1f3c7-* +football|1f3c8| +rugby_football|1f3c9| +swimmer|1f3ca||2,3,4,5,6:1f3ca-* +woman-swimming|1f3ca-200d-2640-fe0f|!|2,3,4,5,6:1f3ca-*-200d-2640-fe0f:! +man-swimming|1f3ca-200d-2642-fe0f|!|2,3,4,5,6:1f3ca-*-200d-2642-fe0f:! +weight_lifter|1f3cb-fe0f|!|2,3,4,5,6:1f3cb-* +woman-lifting-weights|1f3cb-fe0f-200d-2640-fe0f|!|2,3,4,5,6:1f3cb-*-200d-2640-fe0f:! +man-lifting-weights|1f3cb-fe0f-200d-2642-fe0f|!|2,3,4,5,6:1f3cb-*-200d-2642-fe0f:! +golfer|1f3cc-fe0f|!|2,3,4,5,6:1f3cc-* +woman-golfing|1f3cc-fe0f-200d-2640-fe0f|!|2,3,4,5,6:1f3cc-*-200d-2640-fe0f:! +man-golfing|1f3cc-fe0f-200d-2642-fe0f|!|2,3,4,5,6:1f3cc-*-200d-2642-fe0f:! +racing_motorcycle|1f3cd-fe0f|! +racing_car|1f3ce-fe0f|! +cricket_bat_and_ball|1f3cf| +volleyball|1f3d0| +field_hockey_stick_and_ball|1f3d1| +ice_hockey_stick_and_puck|1f3d2| +table_tennis_paddle_and_ball|1f3d3| +snow_capped_mountain|1f3d4-fe0f|! +camping|1f3d5-fe0f|! +beach_with_umbrella|1f3d6-fe0f|! +building_construction|1f3d7-fe0f|! +house_buildings|1f3d8-fe0f|! +cityscape|1f3d9-fe0f|! +derelict_house_building|1f3da-fe0f|! +classical_building|1f3db-fe0f|! +desert|1f3dc-fe0f|! +desert_island|1f3dd-fe0f|! +national_park|1f3de-fe0f|! +stadium|1f3df-fe0f|! +house|1f3e0| +house_with_garden|1f3e1| +office|1f3e2| +post_office|1f3e3| +european_post_office|1f3e4| +hospital|1f3e5| +bank|1f3e6| +atm|1f3e7| +hotel|1f3e8| +love_hotel|1f3e9| +convenience_store|1f3ea| +school|1f3eb| +department_store|1f3ec| +factory|1f3ed| +izakaya_lantern,lantern|1f3ee| +japanese_castle|1f3ef| +european_castle|1f3f0| +waving_white_flag|1f3f3-fe0f|! +rainbow-flag|1f3f3-fe0f-200d-1f308|! +transgender_flag|1f3f3-fe0f-200d-26a7-fe0f|! +waving_black_flag|1f3f4| +pirate_flag|1f3f4-200d-2620-fe0f|! +flag-england|1f3f4-e0067-e0062-e0065-e006e-e0067-e007f| +flag-scotland|1f3f4-e0067-e0062-e0073-e0063-e0074-e007f| +flag-wales|1f3f4-e0067-e0062-e0077-e006c-e0073-e007f| +rosette|1f3f5-fe0f|! +label|1f3f7-fe0f|! +badminton_racquet_and_shuttlecock|1f3f8| +bow_and_arrow|1f3f9| +amphora|1f3fa| +skin-tone-2|1f3fb| +skin-tone-3|1f3fc| +skin-tone-4|1f3fd| +skin-tone-5|1f3fe| +skin-tone-6|1f3ff| +rat|1f400| +mouse2|1f401| +ox|1f402| +water_buffalo|1f403| +cow2|1f404| +tiger2|1f405| +leopard|1f406| +rabbit2|1f407| +cat2|1f408| +black_cat|1f408-200d-2b1b| +dragon|1f409| +crocodile|1f40a| +whale2|1f40b| +snail|1f40c| +snake|1f40d| +racehorse|1f40e| +ram|1f40f| +goat|1f410| +sheep|1f411| +monkey|1f412| +rooster|1f413| +chicken|1f414| +dog2|1f415| +service_dog|1f415-200d-1f9ba| +pig2|1f416| +boar|1f417| +elephant|1f418| +octopus|1f419| +shell|1f41a| +bug|1f41b| +ant|1f41c| +bee,honeybee|1f41d| +ladybug,lady_beetle|1f41e| +fish|1f41f| +tropical_fish|1f420| +blowfish|1f421| +turtle|1f422| +hatching_chick|1f423| +baby_chick|1f424| +hatched_chick|1f425| +bird|1f426| +phoenix|1f426-200d-1f525| +black_bird|1f426-200d-2b1b| +penguin|1f427| +koala|1f428| +poodle|1f429| +dromedary_camel|1f42a| +camel|1f42b| +dolphin,flipper|1f42c| +mouse|1f42d| +cow|1f42e| +tiger|1f42f| +rabbit|1f430| +cat|1f431| +dragon_face|1f432| +whale|1f433| +horse|1f434| +monkey_face|1f435| +dog|1f436| +pig|1f437| +frog|1f438| +hamster|1f439| +wolf|1f43a| +bear|1f43b| +polar_bear|1f43b-200d-2744-fe0f|! +panda_face|1f43c| +pig_nose|1f43d| +feet,paw_prints|1f43e| +chipmunk|1f43f-fe0f|! +eyes|1f440| +eye|1f441-fe0f|! +eye-in-speech-bubble|1f441-fe0f-200d-1f5e8-fe0f|! +ear|1f442||2,3,4,5,6:1f442-* +nose|1f443||2,3,4,5,6:1f443-* +lips|1f444| +tongue|1f445| +point_up_2|1f446||2,3,4,5,6:1f446-* +point_down|1f447||2,3,4,5,6:1f447-* +point_left|1f448||2,3,4,5,6:1f448-* +point_right|1f449||2,3,4,5,6:1f449-* +facepunch,punch|1f44a||2,3,4,5,6:1f44a-* +wave|1f44b||2,3,4,5,6:1f44b-* +ok_hand|1f44c||2,3,4,5,6:1f44c-* ++1,thumbsup|1f44d||2,3,4,5,6:1f44d-* +-1,thumbsdown|1f44e||2,3,4,5,6:1f44e-* +clap|1f44f||2,3,4,5,6:1f44f-* +open_hands|1f450||2,3,4,5,6:1f450-* +crown|1f451| +womans_hat|1f452| +eyeglasses|1f453| +necktie|1f454| +shirt,tshirt|1f455| +jeans|1f456| +dress|1f457| +kimono|1f458| +bikini|1f459| +womans_clothes|1f45a| +purse|1f45b| +handbag|1f45c| +pouch|1f45d| +mans_shoe,shoe|1f45e| +athletic_shoe|1f45f| +high_heel|1f460| +sandal|1f461| +boot|1f462| +footprints|1f463| +bust_in_silhouette|1f464| +busts_in_silhouette|1f465| +boy|1f466||2,3,4,5,6:1f466-* +girl|1f467||2,3,4,5,6:1f467-* +man|1f468||2,3,4,5,6:1f468-* +male-farmer|1f468-200d-1f33e||2,3,4,5,6:1f468-*-200d-1f33e +male-cook|1f468-200d-1f373||2,3,4,5,6:1f468-*-200d-1f373 +man_feeding_baby|1f468-200d-1f37c||2,3,4,5,6:1f468-*-200d-1f37c +male-student|1f468-200d-1f393||2,3,4,5,6:1f468-*-200d-1f393 +male-singer|1f468-200d-1f3a4||2,3,4,5,6:1f468-*-200d-1f3a4 +male-artist|1f468-200d-1f3a8||2,3,4,5,6:1f468-*-200d-1f3a8 +male-teacher|1f468-200d-1f3eb||2,3,4,5,6:1f468-*-200d-1f3eb +male-factory-worker|1f468-200d-1f3ed||2,3,4,5,6:1f468-*-200d-1f3ed +man-boy|1f468-200d-1f466| +man-boy-boy|1f468-200d-1f466-200d-1f466| +man-girl|1f468-200d-1f467| +man-girl-boy|1f468-200d-1f467-200d-1f466| +man-girl-girl|1f468-200d-1f467-200d-1f467| +man-man-boy|1f468-200d-1f468-200d-1f466| +man-man-boy-boy|1f468-200d-1f468-200d-1f466-200d-1f466| +man-man-girl|1f468-200d-1f468-200d-1f467| +man-man-girl-boy|1f468-200d-1f468-200d-1f467-200d-1f466| +man-man-girl-girl|1f468-200d-1f468-200d-1f467-200d-1f467| +man-woman-boy|1f468-200d-1f469-200d-1f466| +man-woman-boy-boy|1f468-200d-1f469-200d-1f466-200d-1f466| +man-woman-girl|1f468-200d-1f469-200d-1f467| +man-woman-girl-boy|1f468-200d-1f469-200d-1f467-200d-1f466| +man-woman-girl-girl|1f468-200d-1f469-200d-1f467-200d-1f467| +male-technologist|1f468-200d-1f4bb||2,3,4,5,6:1f468-*-200d-1f4bb +male-office-worker|1f468-200d-1f4bc||2,3,4,5,6:1f468-*-200d-1f4bc +male-mechanic|1f468-200d-1f527||2,3,4,5,6:1f468-*-200d-1f527 +male-scientist|1f468-200d-1f52c||2,3,4,5,6:1f468-*-200d-1f52c +male-astronaut|1f468-200d-1f680||2,3,4,5,6:1f468-*-200d-1f680 +male-firefighter|1f468-200d-1f692||2,3,4,5,6:1f468-*-200d-1f692 +man_with_probing_cane|1f468-200d-1f9af||2,3,4,5,6:1f468-*-200d-1f9af +man_with_white_cane_facing_right|1f468-200d-1f9af-200d-27a1-fe0f|!|2,3,4,5,6:1f468-*-200d-1f9af-200d-27a1-fe0f:! +red_haired_man|1f468-200d-1f9b0||2,3,4,5,6:1f468-*-200d-1f9b0 +curly_haired_man|1f468-200d-1f9b1||2,3,4,5,6:1f468-*-200d-1f9b1 +bald_man|1f468-200d-1f9b2||2,3,4,5,6:1f468-*-200d-1f9b2 +white_haired_man|1f468-200d-1f9b3||2,3,4,5,6:1f468-*-200d-1f9b3 +man_in_motorized_wheelchair|1f468-200d-1f9bc||2,3,4,5,6:1f468-*-200d-1f9bc +man_in_motorized_wheelchair_facing_right|1f468-200d-1f9bc-200d-27a1-fe0f|!|2,3,4,5,6:1f468-*-200d-1f9bc-200d-27a1-fe0f:! +man_in_manual_wheelchair|1f468-200d-1f9bd||2,3,4,5,6:1f468-*-200d-1f9bd +man_in_manual_wheelchair_facing_right|1f468-200d-1f9bd-200d-27a1-fe0f|!|2,3,4,5,6:1f468-*-200d-1f9bd-200d-27a1-fe0f:! +male-doctor|1f468-200d-2695-fe0f|!|2,3,4,5,6:1f468-*-200d-2695-fe0f:! +male-judge|1f468-200d-2696-fe0f|!|2,3,4,5,6:1f468-*-200d-2696-fe0f:! +male-pilot|1f468-200d-2708-fe0f|!|2,3,4,5,6:1f468-*-200d-2708-fe0f:! +man-heart-man|1f468-200d-2764-fe0f-200d-1f468|!|22,23,24,25,26,32,33,34,35,36,42,43,44,45,46,52,53,54,55,56,62,63,64,65,66:1f468-*-200d-2764-fe0f-200d-1f468-*:! +man-kiss-man|1f468-200d-2764-fe0f-200d-1f48b-200d-1f468|!|22,23,24,25,26,32,33,34,35,36,42,43,44,45,46,52,53,54,55,56,62,63,64,65,66:1f468-*-200d-2764-fe0f-200d-1f48b-200d-1f468-*:! +woman|1f469||2,3,4,5,6:1f469-* +female-farmer|1f469-200d-1f33e||2,3,4,5,6:1f469-*-200d-1f33e +female-cook|1f469-200d-1f373||2,3,4,5,6:1f469-*-200d-1f373 +woman_feeding_baby|1f469-200d-1f37c||2,3,4,5,6:1f469-*-200d-1f37c +female-student|1f469-200d-1f393||2,3,4,5,6:1f469-*-200d-1f393 +female-singer|1f469-200d-1f3a4||2,3,4,5,6:1f469-*-200d-1f3a4 +female-artist|1f469-200d-1f3a8||2,3,4,5,6:1f469-*-200d-1f3a8 +female-teacher|1f469-200d-1f3eb||2,3,4,5,6:1f469-*-200d-1f3eb +female-factory-worker|1f469-200d-1f3ed||2,3,4,5,6:1f469-*-200d-1f3ed +woman-boy|1f469-200d-1f466| +woman-boy-boy|1f469-200d-1f466-200d-1f466| +woman-girl|1f469-200d-1f467| +woman-girl-boy|1f469-200d-1f467-200d-1f466| +woman-girl-girl|1f469-200d-1f467-200d-1f467| +woman-woman-boy|1f469-200d-1f469-200d-1f466| +woman-woman-boy-boy|1f469-200d-1f469-200d-1f466-200d-1f466| +woman-woman-girl|1f469-200d-1f469-200d-1f467| +woman-woman-girl-boy|1f469-200d-1f469-200d-1f467-200d-1f466| +woman-woman-girl-girl|1f469-200d-1f469-200d-1f467-200d-1f467| +female-technologist|1f469-200d-1f4bb||2,3,4,5,6:1f469-*-200d-1f4bb +female-office-worker|1f469-200d-1f4bc||2,3,4,5,6:1f469-*-200d-1f4bc +female-mechanic|1f469-200d-1f527||2,3,4,5,6:1f469-*-200d-1f527 +female-scientist|1f469-200d-1f52c||2,3,4,5,6:1f469-*-200d-1f52c +female-astronaut|1f469-200d-1f680||2,3,4,5,6:1f469-*-200d-1f680 +female-firefighter|1f469-200d-1f692||2,3,4,5,6:1f469-*-200d-1f692 +woman_with_probing_cane|1f469-200d-1f9af||2,3,4,5,6:1f469-*-200d-1f9af +woman_with_white_cane_facing_right|1f469-200d-1f9af-200d-27a1-fe0f|!|2,3,4,5,6:1f469-*-200d-1f9af-200d-27a1-fe0f:! +red_haired_woman|1f469-200d-1f9b0||2,3,4,5,6:1f469-*-200d-1f9b0 +curly_haired_woman|1f469-200d-1f9b1||2,3,4,5,6:1f469-*-200d-1f9b1 +bald_woman|1f469-200d-1f9b2||2,3,4,5,6:1f469-*-200d-1f9b2 +white_haired_woman|1f469-200d-1f9b3||2,3,4,5,6:1f469-*-200d-1f9b3 +woman_in_motorized_wheelchair|1f469-200d-1f9bc||2,3,4,5,6:1f469-*-200d-1f9bc +woman_in_motorized_wheelchair_facing_right|1f469-200d-1f9bc-200d-27a1-fe0f|!|2,3,4,5,6:1f469-*-200d-1f9bc-200d-27a1-fe0f:! +woman_in_manual_wheelchair|1f469-200d-1f9bd||2,3,4,5,6:1f469-*-200d-1f9bd +woman_in_manual_wheelchair_facing_right|1f469-200d-1f9bd-200d-27a1-fe0f|!|2,3,4,5,6:1f469-*-200d-1f9bd-200d-27a1-fe0f:! +female-doctor|1f469-200d-2695-fe0f|!|2,3,4,5,6:1f469-*-200d-2695-fe0f:! +female-judge|1f469-200d-2696-fe0f|!|2,3,4,5,6:1f469-*-200d-2696-fe0f:! +female-pilot|1f469-200d-2708-fe0f|!|2,3,4,5,6:1f469-*-200d-2708-fe0f:! +woman-heart-man|1f469-200d-2764-fe0f-200d-1f468|!|22,23,24,25,26,32,33,34,35,36,42,43,44,45,46,52,53,54,55,56,62,63,64,65,66:1f469-*-200d-2764-fe0f-200d-1f468-*:! +woman-heart-woman|1f469-200d-2764-fe0f-200d-1f469|!|22,23,24,25,26,32,33,34,35,36,42,43,44,45,46,52,53,54,55,56,62,63,64,65,66:1f469-*-200d-2764-fe0f-200d-1f469-*:! +woman-kiss-man|1f469-200d-2764-fe0f-200d-1f48b-200d-1f468|!|22,23,24,25,26,32,33,34,35,36,42,43,44,45,46,52,53,54,55,56,62,63,64,65,66:1f469-*-200d-2764-fe0f-200d-1f48b-200d-1f468-*:! +woman-kiss-woman|1f469-200d-2764-fe0f-200d-1f48b-200d-1f469|!|22,23,24,25,26,32,33,34,35,36,42,43,44,45,46,52,53,54,55,56,62,63,64,65,66:1f469-*-200d-2764-fe0f-200d-1f48b-200d-1f469-*:! +family|1f46a| +man_and_woman_holding_hands,woman_and_man_holding_hands,couple|1f46b||2,3,4,5,6:1f46b-*;23,24,25,26,32,34,35,36,42,43,45,46,52,53,54,56,62,63,64,65:1f469-*-200d-1f91d-200d-1f468-* +two_men_holding_hands,men_holding_hands|1f46c||2,3,4,5,6:1f46c-*;23,24,25,26,32,34,35,36,42,43,45,46,52,53,54,56,62,63,64,65:1f468-*-200d-1f91d-200d-1f468-* +two_women_holding_hands,women_holding_hands|1f46d||2,3,4,5,6:1f46d-*;23,24,25,26,32,34,35,36,42,43,45,46,52,53,54,56,62,63,64,65:1f469-*-200d-1f91d-200d-1f469-* +cop|1f46e||2,3,4,5,6:1f46e-* +female-police-officer|1f46e-200d-2640-fe0f|!|2,3,4,5,6:1f46e-*-200d-2640-fe0f:! +male-police-officer|1f46e-200d-2642-fe0f|!|2,3,4,5,6:1f46e-*-200d-2642-fe0f:! +dancers|1f46f| +women-with-bunny-ears-partying,woman-with-bunny-ears-partying|1f46f-200d-2640-fe0f|! +men-with-bunny-ears-partying,man-with-bunny-ears-partying|1f46f-200d-2642-fe0f|! +bride_with_veil|1f470||2,3,4,5,6:1f470-* +woman_with_veil|1f470-200d-2640-fe0f|!|2,3,4,5,6:1f470-*-200d-2640-fe0f:! +man_with_veil|1f470-200d-2642-fe0f|!|2,3,4,5,6:1f470-*-200d-2642-fe0f:! +person_with_blond_hair|1f471||2,3,4,5,6:1f471-* +blond-haired-woman|1f471-200d-2640-fe0f|!|2,3,4,5,6:1f471-*-200d-2640-fe0f:! +blond-haired-man|1f471-200d-2642-fe0f|!|2,3,4,5,6:1f471-*-200d-2642-fe0f:! +man_with_gua_pi_mao|1f472||2,3,4,5,6:1f472-* +man_with_turban|1f473||2,3,4,5,6:1f473-* +woman-wearing-turban|1f473-200d-2640-fe0f|!|2,3,4,5,6:1f473-*-200d-2640-fe0f:! +man-wearing-turban|1f473-200d-2642-fe0f|!|2,3,4,5,6:1f473-*-200d-2642-fe0f:! +older_man|1f474||2,3,4,5,6:1f474-* +older_woman|1f475||2,3,4,5,6:1f475-* +baby|1f476||2,3,4,5,6:1f476-* +construction_worker|1f477||2,3,4,5,6:1f477-* +female-construction-worker|1f477-200d-2640-fe0f|!|2,3,4,5,6:1f477-*-200d-2640-fe0f:! +male-construction-worker|1f477-200d-2642-fe0f|!|2,3,4,5,6:1f477-*-200d-2642-fe0f:! +princess|1f478||2,3,4,5,6:1f478-* +japanese_ogre|1f479| +japanese_goblin|1f47a| +ghost|1f47b| +angel|1f47c||2,3,4,5,6:1f47c-* +alien|1f47d| +space_invader|1f47e| +imp|1f47f| +skull|1f480| +information_desk_person|1f481||2,3,4,5,6:1f481-* +woman-tipping-hand|1f481-200d-2640-fe0f|!|2,3,4,5,6:1f481-*-200d-2640-fe0f:! +man-tipping-hand|1f481-200d-2642-fe0f|!|2,3,4,5,6:1f481-*-200d-2642-fe0f:! +guardsman|1f482||2,3,4,5,6:1f482-* +female-guard|1f482-200d-2640-fe0f|!|2,3,4,5,6:1f482-*-200d-2640-fe0f:! +male-guard|1f482-200d-2642-fe0f|!|2,3,4,5,6:1f482-*-200d-2642-fe0f:! +dancer|1f483||2,3,4,5,6:1f483-* +lipstick|1f484| +nail_care|1f485||2,3,4,5,6:1f485-* +massage|1f486||2,3,4,5,6:1f486-* +woman-getting-massage|1f486-200d-2640-fe0f|!|2,3,4,5,6:1f486-*-200d-2640-fe0f:! +man-getting-massage|1f486-200d-2642-fe0f|!|2,3,4,5,6:1f486-*-200d-2642-fe0f:! +haircut|1f487||2,3,4,5,6:1f487-* +woman-getting-haircut|1f487-200d-2640-fe0f|!|2,3,4,5,6:1f487-*-200d-2640-fe0f:! +man-getting-haircut|1f487-200d-2642-fe0f|!|2,3,4,5,6:1f487-*-200d-2642-fe0f:! +barber|1f488| +syringe|1f489| +pill|1f48a| +kiss|1f48b| +love_letter|1f48c| +ring|1f48d| +gem|1f48e| +couplekiss|1f48f||2,3,4,5,6:1f48f-*;23,24,25,26,32,34,35,36,42,43,45,46,52,53,54,56,62,63,64,65:1f9d1-*-200d-2764-fe0f-200d-1f48b-200d-1f9d1-*:! +bouquet|1f490| +couple_with_heart|1f491||2,3,4,5,6:1f491-*;23,24,25,26,32,34,35,36,42,43,45,46,52,53,54,56,62,63,64,65:1f9d1-*-200d-2764-fe0f-200d-1f9d1-*:! +wedding|1f492| +heartbeat|1f493| +broken_heart|1f494| +two_hearts|1f495| +sparkling_heart|1f496| +heartpulse|1f497| +cupid|1f498| +blue_heart|1f499| +green_heart|1f49a| +yellow_heart|1f49b| +purple_heart|1f49c| +gift_heart|1f49d| +revolving_hearts|1f49e| +heart_decoration|1f49f| +diamond_shape_with_a_dot_inside|1f4a0| +bulb|1f4a1| +anger|1f4a2| +bomb|1f4a3| +zzz|1f4a4| +boom,collision|1f4a5| +sweat_drops|1f4a6| +droplet|1f4a7| +dash|1f4a8| +hankey,poop,shit|1f4a9| +muscle|1f4aa||2,3,4,5,6:1f4aa-* +dizzy|1f4ab| +speech_balloon|1f4ac| +thought_balloon|1f4ad| +white_flower|1f4ae| +100|1f4af| +moneybag|1f4b0| +currency_exchange|1f4b1| +heavy_dollar_sign|1f4b2| +credit_card|1f4b3| +yen|1f4b4| +dollar|1f4b5| +euro|1f4b6| +pound|1f4b7| +money_with_wings|1f4b8| +chart|1f4b9| +seat|1f4ba| +computer|1f4bb| +briefcase|1f4bc| +minidisc|1f4bd| +floppy_disk|1f4be| +cd|1f4bf| +dvd|1f4c0| +file_folder|1f4c1| +open_file_folder|1f4c2| +page_with_curl|1f4c3| +page_facing_up|1f4c4| +date|1f4c5| +calendar|1f4c6| +card_index|1f4c7| +chart_with_upwards_trend|1f4c8| +chart_with_downwards_trend|1f4c9| +bar_chart|1f4ca| +clipboard|1f4cb| +pushpin|1f4cc| +round_pushpin|1f4cd| +paperclip|1f4ce| +straight_ruler|1f4cf| +triangular_ruler|1f4d0| +bookmark_tabs|1f4d1| +ledger|1f4d2| +notebook|1f4d3| +notebook_with_decorative_cover|1f4d4| +closed_book|1f4d5| +book,open_book|1f4d6| +green_book|1f4d7| +blue_book|1f4d8| +orange_book|1f4d9| +books|1f4da| +name_badge|1f4db| +scroll|1f4dc| +memo,pencil|1f4dd| +telephone_receiver|1f4de| +pager|1f4df| +fax|1f4e0| +satellite_antenna|1f4e1| +loudspeaker|1f4e2| +mega|1f4e3| +outbox_tray|1f4e4| +inbox_tray|1f4e5| +package|1f4e6| +e-mail|1f4e7| +incoming_envelope|1f4e8| +envelope_with_arrow|1f4e9| +mailbox_closed|1f4ea| +mailbox|1f4eb| +mailbox_with_mail|1f4ec| +mailbox_with_no_mail|1f4ed| +postbox|1f4ee| +postal_horn|1f4ef| +newspaper|1f4f0| +iphone|1f4f1| +calling|1f4f2| +vibration_mode|1f4f3| +mobile_phone_off|1f4f4| +no_mobile_phones|1f4f5| +signal_strength|1f4f6| +camera|1f4f7| +camera_with_flash|1f4f8| +video_camera|1f4f9| +tv|1f4fa| +radio|1f4fb| +vhs|1f4fc| +film_projector|1f4fd-fe0f|! +prayer_beads|1f4ff| +twisted_rightwards_arrows|1f500| +repeat|1f501| +repeat_one|1f502| +arrows_clockwise|1f503| +arrows_counterclockwise|1f504| +low_brightness|1f505| +high_brightness|1f506| +mute|1f507| +speaker|1f508| +sound|1f509| +loud_sound|1f50a| +battery|1f50b| +electric_plug|1f50c| +mag|1f50d| +mag_right|1f50e| +lock_with_ink_pen|1f50f| +closed_lock_with_key|1f510| +key|1f511| +lock|1f512| +unlock|1f513| +bell|1f514| +no_bell|1f515| +bookmark|1f516| +link|1f517| +radio_button|1f518| +back|1f519| +end|1f51a| +on|1f51b| +soon|1f51c| +top|1f51d| +underage|1f51e| +keycap_ten|1f51f| +capital_abcd|1f520| +abcd|1f521| +1234|1f522| +symbols|1f523| +abc|1f524| +fire|1f525| +flashlight|1f526| +wrench|1f527| +hammer|1f528| +nut_and_bolt|1f529| +hocho,knife|1f52a| +gun|1f52b| +microscope|1f52c| +telescope|1f52d| +crystal_ball|1f52e| +six_pointed_star|1f52f| +beginner|1f530| +trident|1f531| +black_square_button|1f532| +white_square_button|1f533| +red_circle|1f534| +large_blue_circle|1f535| +large_orange_diamond|1f536| +large_blue_diamond|1f537| +small_orange_diamond|1f538| +small_blue_diamond|1f539| +small_red_triangle|1f53a| +small_red_triangle_down|1f53b| +arrow_up_small|1f53c| +arrow_down_small|1f53d| +om_symbol|1f549-fe0f|! +dove_of_peace|1f54a-fe0f|! +kaaba|1f54b| +mosque|1f54c| +synagogue|1f54d| +menorah_with_nine_branches|1f54e| +clock1|1f550| +clock2|1f551| +clock3|1f552| +clock4|1f553| +clock5|1f554| +clock6|1f555| +clock7|1f556| +clock8|1f557| +clock9|1f558| +clock10|1f559| +clock11|1f55a| +clock12|1f55b| +clock130|1f55c| +clock230|1f55d| +clock330|1f55e| +clock430|1f55f| +clock530|1f560| +clock630|1f561| +clock730|1f562| +clock830|1f563| +clock930|1f564| +clock1030|1f565| +clock1130|1f566| +clock1230|1f567| +candle|1f56f-fe0f|! +mantelpiece_clock|1f570-fe0f|! +hole|1f573-fe0f|! +man_in_business_suit_levitating|1f574-fe0f|!|2,3,4,5,6:1f574-* +sleuth_or_spy|1f575-fe0f|!|2,3,4,5,6:1f575-* +female-detective|1f575-fe0f-200d-2640-fe0f|!|2,3,4,5,6:1f575-*-200d-2640-fe0f:! +male-detective|1f575-fe0f-200d-2642-fe0f|!|2,3,4,5,6:1f575-*-200d-2642-fe0f:! +dark_sunglasses|1f576-fe0f|! +spider|1f577-fe0f|! +spider_web|1f578-fe0f|! +joystick|1f579-fe0f|! +man_dancing|1f57a||2,3,4,5,6:1f57a-* +linked_paperclips|1f587-fe0f|! +lower_left_ballpoint_pen|1f58a-fe0f|! +lower_left_fountain_pen|1f58b-fe0f|! +lower_left_paintbrush|1f58c-fe0f|! +lower_left_crayon|1f58d-fe0f|! +raised_hand_with_fingers_splayed|1f590-fe0f|!|2,3,4,5,6:1f590-* +middle_finger,reversed_hand_with_middle_finger_extended|1f595||2,3,4,5,6:1f595-* +spock-hand|1f596||2,3,4,5,6:1f596-* +black_heart|1f5a4| +desktop_computer|1f5a5-fe0f|! +printer|1f5a8-fe0f|! +three_button_mouse|1f5b1-fe0f|! +trackball|1f5b2-fe0f|! +frame_with_picture|1f5bc-fe0f|! +card_index_dividers|1f5c2-fe0f|! +card_file_box|1f5c3-fe0f|! +file_cabinet|1f5c4-fe0f|! +wastebasket|1f5d1-fe0f|! +spiral_note_pad|1f5d2-fe0f|! +spiral_calendar_pad|1f5d3-fe0f|! +compression|1f5dc-fe0f|! +old_key|1f5dd-fe0f|! +rolled_up_newspaper|1f5de-fe0f|! +dagger_knife|1f5e1-fe0f|! +speaking_head_in_silhouette|1f5e3-fe0f|! +left_speech_bubble|1f5e8-fe0f|! +right_anger_bubble|1f5ef-fe0f|! +ballot_box_with_ballot|1f5f3-fe0f|! +world_map|1f5fa-fe0f|! +mount_fuji|1f5fb| +tokyo_tower|1f5fc| +statue_of_liberty|1f5fd| +japan|1f5fe| +moyai|1f5ff| +grinning|1f600| +grin|1f601| +joy|1f602| +smiley|1f603| +smile|1f604| +sweat_smile|1f605| +laughing,satisfied|1f606| +innocent|1f607| +smiling_imp|1f608| +wink|1f609| +blush|1f60a| +yum|1f60b| +relieved|1f60c| +heart_eyes|1f60d| +sunglasses|1f60e| +smirk|1f60f| +neutral_face|1f610| +expressionless|1f611| +unamused|1f612| +sweat|1f613| +pensive|1f614| +confused|1f615| +confounded|1f616| +kissing|1f617| +kissing_heart|1f618| +kissing_smiling_eyes|1f619| +kissing_closed_eyes|1f61a| +stuck_out_tongue|1f61b| +stuck_out_tongue_winking_eye|1f61c| +stuck_out_tongue_closed_eyes|1f61d| +disappointed|1f61e| +worried|1f61f| +angry|1f620| +rage|1f621| +cry|1f622| +persevere|1f623| +triumph|1f624| +disappointed_relieved|1f625| +frowning|1f626| +anguished|1f627| +fearful|1f628| +weary|1f629| +sleepy|1f62a| +tired_face|1f62b| +grimacing|1f62c| +sob|1f62d| +open_mouth|1f62e| +face_exhaling|1f62e-200d-1f4a8| +hushed|1f62f| +cold_sweat|1f630| +scream|1f631| +astonished|1f632| +flushed|1f633| +sleeping|1f634| +dizzy_face|1f635| +face_with_spiral_eyes|1f635-200d-1f4ab| +no_mouth|1f636| +face_in_clouds|1f636-200d-1f32b-fe0f|! +mask|1f637| +smile_cat|1f638| +joy_cat|1f639| +smiley_cat|1f63a| +heart_eyes_cat|1f63b| +smirk_cat|1f63c| +kissing_cat|1f63d| +pouting_cat|1f63e| +crying_cat_face|1f63f| +scream_cat|1f640| +slightly_frowning_face|1f641| +slightly_smiling_face|1f642| +head_shaking_horizontally|1f642-200d-2194-fe0f|! +head_shaking_vertically|1f642-200d-2195-fe0f|! +upside_down_face|1f643| +face_with_rolling_eyes|1f644| +no_good|1f645||2,3,4,5,6:1f645-* +woman-gesturing-no|1f645-200d-2640-fe0f|!|2,3,4,5,6:1f645-*-200d-2640-fe0f:! +man-gesturing-no|1f645-200d-2642-fe0f|!|2,3,4,5,6:1f645-*-200d-2642-fe0f:! +ok_woman|1f646||2,3,4,5,6:1f646-* +woman-gesturing-ok|1f646-200d-2640-fe0f|!|2,3,4,5,6:1f646-*-200d-2640-fe0f:! +man-gesturing-ok|1f646-200d-2642-fe0f|!|2,3,4,5,6:1f646-*-200d-2642-fe0f:! +bow|1f647||2,3,4,5,6:1f647-* +woman-bowing|1f647-200d-2640-fe0f|!|2,3,4,5,6:1f647-*-200d-2640-fe0f:! +man-bowing|1f647-200d-2642-fe0f|!|2,3,4,5,6:1f647-*-200d-2642-fe0f:! +see_no_evil|1f648| +hear_no_evil|1f649| +speak_no_evil|1f64a| +raising_hand|1f64b||2,3,4,5,6:1f64b-* +woman-raising-hand|1f64b-200d-2640-fe0f|!|2,3,4,5,6:1f64b-*-200d-2640-fe0f:! +man-raising-hand|1f64b-200d-2642-fe0f|!|2,3,4,5,6:1f64b-*-200d-2642-fe0f:! +raised_hands|1f64c||2,3,4,5,6:1f64c-* +person_frowning|1f64d||2,3,4,5,6:1f64d-* +woman-frowning|1f64d-200d-2640-fe0f|!|2,3,4,5,6:1f64d-*-200d-2640-fe0f:! +man-frowning|1f64d-200d-2642-fe0f|!|2,3,4,5,6:1f64d-*-200d-2642-fe0f:! +person_with_pouting_face|1f64e||2,3,4,5,6:1f64e-* +woman-pouting|1f64e-200d-2640-fe0f|!|2,3,4,5,6:1f64e-*-200d-2640-fe0f:! +man-pouting|1f64e-200d-2642-fe0f|!|2,3,4,5,6:1f64e-*-200d-2642-fe0f:! +pray|1f64f||2,3,4,5,6:1f64f-* +rocket|1f680| +helicopter|1f681| +steam_locomotive|1f682| +railway_car|1f683| +bullettrain_side|1f684| +bullettrain_front|1f685| +train2|1f686| +metro|1f687| +light_rail|1f688| +station|1f689| +tram|1f68a| +train|1f68b| +bus|1f68c| +oncoming_bus|1f68d| +trolleybus|1f68e| +busstop|1f68f| +minibus|1f690| +ambulance|1f691| +fire_engine|1f692| +police_car|1f693| +oncoming_police_car|1f694| +taxi|1f695| +oncoming_taxi|1f696| +car,red_car|1f697| +oncoming_automobile|1f698| +blue_car|1f699| +truck|1f69a| +articulated_lorry|1f69b| +tractor|1f69c| +monorail|1f69d| +mountain_railway|1f69e| +suspension_railway|1f69f| +mountain_cableway|1f6a0| +aerial_tramway|1f6a1| +ship|1f6a2| +rowboat|1f6a3||2,3,4,5,6:1f6a3-* +woman-rowing-boat|1f6a3-200d-2640-fe0f|!|2,3,4,5,6:1f6a3-*-200d-2640-fe0f:! +man-rowing-boat|1f6a3-200d-2642-fe0f|!|2,3,4,5,6:1f6a3-*-200d-2642-fe0f:! +speedboat|1f6a4| +traffic_light|1f6a5| +vertical_traffic_light|1f6a6| +construction|1f6a7| +rotating_light|1f6a8| +triangular_flag_on_post|1f6a9| +door|1f6aa| +no_entry_sign|1f6ab| +smoking|1f6ac| +no_smoking|1f6ad| +put_litter_in_its_place|1f6ae| +do_not_litter|1f6af| +potable_water|1f6b0| +non-potable_water|1f6b1| +bike|1f6b2| +no_bicycles|1f6b3| +bicyclist|1f6b4||2,3,4,5,6:1f6b4-* +woman-biking|1f6b4-200d-2640-fe0f|!|2,3,4,5,6:1f6b4-*-200d-2640-fe0f:! +man-biking|1f6b4-200d-2642-fe0f|!|2,3,4,5,6:1f6b4-*-200d-2642-fe0f:! +mountain_bicyclist|1f6b5||2,3,4,5,6:1f6b5-* +woman-mountain-biking|1f6b5-200d-2640-fe0f|!|2,3,4,5,6:1f6b5-*-200d-2640-fe0f:! +man-mountain-biking|1f6b5-200d-2642-fe0f|!|2,3,4,5,6:1f6b5-*-200d-2642-fe0f:! +walking|1f6b6||2,3,4,5,6:1f6b6-* +woman-walking|1f6b6-200d-2640-fe0f|!|2,3,4,5,6:1f6b6-*-200d-2640-fe0f:! +woman_walking_facing_right|1f6b6-200d-2640-fe0f-200d-27a1-fe0f|!|2,3,4,5,6:1f6b6-*-200d-2640-fe0f-200d-27a1-fe0f:! +man-walking|1f6b6-200d-2642-fe0f|!|2,3,4,5,6:1f6b6-*-200d-2642-fe0f:! +man_walking_facing_right|1f6b6-200d-2642-fe0f-200d-27a1-fe0f|!|2,3,4,5,6:1f6b6-*-200d-2642-fe0f-200d-27a1-fe0f:! +person_walking_facing_right|1f6b6-200d-27a1-fe0f|!|2,3,4,5,6:1f6b6-*-200d-27a1-fe0f:! +no_pedestrians|1f6b7| +children_crossing|1f6b8| +mens|1f6b9| +womens|1f6ba| +restroom|1f6bb| +baby_symbol|1f6bc| +toilet|1f6bd| +wc|1f6be| +shower|1f6bf| +bath|1f6c0||2,3,4,5,6:1f6c0-* +bathtub|1f6c1| +passport_control|1f6c2| +customs|1f6c3| +baggage_claim|1f6c4| +left_luggage|1f6c5| +couch_and_lamp|1f6cb-fe0f|! +sleeping_accommodation|1f6cc||2,3,4,5,6:1f6cc-* +shopping_bags|1f6cd-fe0f|! +bellhop_bell|1f6ce-fe0f|! +bed|1f6cf-fe0f|! +place_of_worship|1f6d0| +octagonal_sign|1f6d1| +shopping_trolley|1f6d2| +hindu_temple|1f6d5| +hut|1f6d6| +elevator|1f6d7| +wireless|1f6dc| +playground_slide|1f6dd| +wheel|1f6de| +ring_buoy|1f6df| +hammer_and_wrench|1f6e0-fe0f|! +shield|1f6e1-fe0f|! +oil_drum|1f6e2-fe0f|! +motorway|1f6e3-fe0f|! +railway_track|1f6e4-fe0f|! +motor_boat|1f6e5-fe0f|! +small_airplane|1f6e9-fe0f|! +airplane_departure|1f6eb| +airplane_arriving|1f6ec| +satellite|1f6f0-fe0f|! +passenger_ship|1f6f3-fe0f|! +scooter|1f6f4| +motor_scooter|1f6f5| +canoe|1f6f6| +sled|1f6f7| +flying_saucer|1f6f8| +skateboard|1f6f9| +auto_rickshaw|1f6fa| +pickup_truck|1f6fb| +roller_skate|1f6fc| +large_orange_circle|1f7e0| +large_yellow_circle|1f7e1| +large_green_circle|1f7e2| +large_purple_circle|1f7e3| +large_brown_circle|1f7e4| +large_red_square|1f7e5| +large_blue_square|1f7e6| +large_orange_square|1f7e7| +large_yellow_square|1f7e8| +large_green_square|1f7e9| +large_purple_square|1f7ea| +large_brown_square|1f7eb| +heavy_equals_sign|1f7f0| +pinched_fingers|1f90c||2,3,4,5,6:1f90c-* +white_heart|1f90d| +brown_heart|1f90e| +pinching_hand|1f90f||2,3,4,5,6:1f90f-* +zipper_mouth_face|1f910| +money_mouth_face|1f911| +face_with_thermometer|1f912| +nerd_face|1f913| +thinking_face|1f914| +face_with_head_bandage|1f915| +robot_face|1f916| +hugging_face|1f917| +the_horns,sign_of_the_horns|1f918||2,3,4,5,6:1f918-* +call_me_hand|1f919||2,3,4,5,6:1f919-* +raised_back_of_hand|1f91a||2,3,4,5,6:1f91a-* +left-facing_fist|1f91b||2,3,4,5,6:1f91b-* +right-facing_fist|1f91c||2,3,4,5,6:1f91c-* +handshake|1f91d||2,3,4,5,6:1f91d-*;23,24,25,26,32,34,35,36,42,43,45,46,52,53,54,56,62,63,64,65:1faf1-*-200d-1faf2-* +crossed_fingers,hand_with_index_and_middle_fingers_crossed|1f91e||2,3,4,5,6:1f91e-* +i_love_you_hand_sign|1f91f||2,3,4,5,6:1f91f-* +face_with_cowboy_hat|1f920| +clown_face|1f921| +nauseated_face|1f922| +rolling_on_the_floor_laughing|1f923| +drooling_face|1f924| +lying_face|1f925| +face_palm|1f926||2,3,4,5,6:1f926-* +woman-facepalming|1f926-200d-2640-fe0f|!|2,3,4,5,6:1f926-*-200d-2640-fe0f:! +man-facepalming|1f926-200d-2642-fe0f|!|2,3,4,5,6:1f926-*-200d-2642-fe0f:! +sneezing_face|1f927| +face_with_raised_eyebrow,face_with_one_eyebrow_raised|1f928| +star-struck,grinning_face_with_star_eyes|1f929| +zany_face,grinning_face_with_one_large_and_one_small_eye|1f92a| +shushing_face,face_with_finger_covering_closed_lips|1f92b| +face_with_symbols_on_mouth,serious_face_with_symbols_covering_mouth|1f92c| +face_with_hand_over_mouth,smiling_face_with_smiling_eyes_and_hand_covering_mouth|1f92d| +face_vomiting,face_with_open_mouth_vomiting|1f92e| +exploding_head,shocked_face_with_exploding_head|1f92f| +pregnant_woman|1f930||2,3,4,5,6:1f930-* +breast-feeding|1f931||2,3,4,5,6:1f931-* +palms_up_together|1f932||2,3,4,5,6:1f932-* +selfie|1f933||2,3,4,5,6:1f933-* +prince|1f934||2,3,4,5,6:1f934-* +person_in_tuxedo|1f935||2,3,4,5,6:1f935-* +woman_in_tuxedo|1f935-200d-2640-fe0f|!|2,3,4,5,6:1f935-*-200d-2640-fe0f:! +man_in_tuxedo|1f935-200d-2642-fe0f|!|2,3,4,5,6:1f935-*-200d-2642-fe0f:! +mrs_claus,mother_christmas|1f936||2,3,4,5,6:1f936-* +shrug|1f937||2,3,4,5,6:1f937-* +woman-shrugging|1f937-200d-2640-fe0f|!|2,3,4,5,6:1f937-*-200d-2640-fe0f:! +man-shrugging|1f937-200d-2642-fe0f|!|2,3,4,5,6:1f937-*-200d-2642-fe0f:! +person_doing_cartwheel|1f938||2,3,4,5,6:1f938-* +woman-cartwheeling|1f938-200d-2640-fe0f|!|2,3,4,5,6:1f938-*-200d-2640-fe0f:! +man-cartwheeling|1f938-200d-2642-fe0f|!|2,3,4,5,6:1f938-*-200d-2642-fe0f:! +juggling|1f939||2,3,4,5,6:1f939-* +woman-juggling|1f939-200d-2640-fe0f|!|2,3,4,5,6:1f939-*-200d-2640-fe0f:! +man-juggling|1f939-200d-2642-fe0f|!|2,3,4,5,6:1f939-*-200d-2642-fe0f:! +fencer|1f93a| +wrestlers|1f93c| +woman-wrestling|1f93c-200d-2640-fe0f|! +man-wrestling|1f93c-200d-2642-fe0f|! +water_polo|1f93d||2,3,4,5,6:1f93d-* +woman-playing-water-polo|1f93d-200d-2640-fe0f|!|2,3,4,5,6:1f93d-*-200d-2640-fe0f:! +man-playing-water-polo|1f93d-200d-2642-fe0f|!|2,3,4,5,6:1f93d-*-200d-2642-fe0f:! +handball|1f93e||2,3,4,5,6:1f93e-* +woman-playing-handball|1f93e-200d-2640-fe0f|!|2,3,4,5,6:1f93e-*-200d-2640-fe0f:! +man-playing-handball|1f93e-200d-2642-fe0f|!|2,3,4,5,6:1f93e-*-200d-2642-fe0f:! +diving_mask|1f93f| +wilted_flower|1f940| +drum_with_drumsticks|1f941| +clinking_glasses|1f942| +tumbler_glass|1f943| +spoon|1f944| +goal_net|1f945| +first_place_medal|1f947| +second_place_medal|1f948| +third_place_medal|1f949| +boxing_glove|1f94a| +martial_arts_uniform|1f94b| +curling_stone|1f94c| +lacrosse|1f94d| +softball|1f94e| +flying_disc|1f94f| +croissant|1f950| +avocado|1f951| +cucumber|1f952| +bacon|1f953| +potato|1f954| +carrot|1f955| +baguette_bread|1f956| +green_salad|1f957| +shallow_pan_of_food|1f958| +stuffed_flatbread|1f959| +egg|1f95a| +glass_of_milk|1f95b| +peanuts|1f95c| +kiwifruit|1f95d| +pancakes|1f95e| +dumpling|1f95f| +fortune_cookie|1f960| +takeout_box|1f961| +chopsticks|1f962| +bowl_with_spoon|1f963| +cup_with_straw|1f964| +coconut|1f965| +broccoli|1f966| +pie|1f967| +pretzel|1f968| +cut_of_meat|1f969| +sandwich|1f96a| +canned_food|1f96b| +leafy_green|1f96c| +mango|1f96d| +moon_cake|1f96e| +bagel|1f96f| +smiling_face_with_3_hearts|1f970| +yawning_face|1f971| +smiling_face_with_tear|1f972| +partying_face|1f973| +woozy_face|1f974| +hot_face|1f975| +cold_face|1f976| +ninja|1f977||2,3,4,5,6:1f977-* +disguised_face|1f978| +face_holding_back_tears|1f979| +pleading_face|1f97a| +sari|1f97b| +lab_coat|1f97c| +goggles|1f97d| +hiking_boot|1f97e| +womans_flat_shoe|1f97f| +crab|1f980| +lion_face|1f981| +scorpion|1f982| +turkey|1f983| +unicorn_face|1f984| +eagle|1f985| +duck|1f986| +bat|1f987| +shark|1f988| +owl|1f989| +fox_face|1f98a| +butterfly|1f98b| +deer|1f98c| +gorilla|1f98d| +lizard|1f98e| +rhinoceros|1f98f| +shrimp|1f990| +squid|1f991| +giraffe_face|1f992| +zebra_face|1f993| +hedgehog|1f994| +sauropod|1f995| +t-rex|1f996| +cricket|1f997| +kangaroo|1f998| +llama|1f999| +peacock|1f99a| +hippopotamus|1f99b| +parrot|1f99c| +raccoon|1f99d| +lobster|1f99e| +mosquito|1f99f| +microbe|1f9a0| +badger|1f9a1| +swan|1f9a2| +mammoth|1f9a3| +dodo|1f9a4| +sloth|1f9a5| +otter|1f9a6| +orangutan|1f9a7| +skunk|1f9a8| +flamingo|1f9a9| +oyster|1f9aa| +beaver|1f9ab| +bison|1f9ac| +seal|1f9ad| +guide_dog|1f9ae| +probing_cane|1f9af| +bone|1f9b4| +leg|1f9b5||2,3,4,5,6:1f9b5-* +foot|1f9b6||2,3,4,5,6:1f9b6-* +tooth|1f9b7| +superhero|1f9b8||2,3,4,5,6:1f9b8-* +female_superhero|1f9b8-200d-2640-fe0f|!|2,3,4,5,6:1f9b8-*-200d-2640-fe0f:! +male_superhero|1f9b8-200d-2642-fe0f|!|2,3,4,5,6:1f9b8-*-200d-2642-fe0f:! +supervillain|1f9b9||2,3,4,5,6:1f9b9-* +female_supervillain|1f9b9-200d-2640-fe0f|!|2,3,4,5,6:1f9b9-*-200d-2640-fe0f:! +male_supervillain|1f9b9-200d-2642-fe0f|!|2,3,4,5,6:1f9b9-*-200d-2642-fe0f:! +safety_vest|1f9ba| +ear_with_hearing_aid|1f9bb||2,3,4,5,6:1f9bb-* +motorized_wheelchair|1f9bc| +manual_wheelchair|1f9bd| +mechanical_arm|1f9be| +mechanical_leg|1f9bf| +cheese_wedge|1f9c0| +cupcake|1f9c1| +salt|1f9c2| +beverage_box|1f9c3| +garlic|1f9c4| +onion|1f9c5| +falafel|1f9c6| +waffle|1f9c7| +butter|1f9c8| +mate_drink|1f9c9| +ice_cube|1f9ca| +bubble_tea|1f9cb| +troll|1f9cc| +standing_person|1f9cd||2,3,4,5,6:1f9cd-* +woman_standing|1f9cd-200d-2640-fe0f|!|2,3,4,5,6:1f9cd-*-200d-2640-fe0f:! +man_standing|1f9cd-200d-2642-fe0f|!|2,3,4,5,6:1f9cd-*-200d-2642-fe0f:! +kneeling_person|1f9ce||2,3,4,5,6:1f9ce-* +woman_kneeling|1f9ce-200d-2640-fe0f|!|2,3,4,5,6:1f9ce-*-200d-2640-fe0f:! +woman_kneeling_facing_right|1f9ce-200d-2640-fe0f-200d-27a1-fe0f|!|2,3,4,5,6:1f9ce-*-200d-2640-fe0f-200d-27a1-fe0f:! +man_kneeling|1f9ce-200d-2642-fe0f|!|2,3,4,5,6:1f9ce-*-200d-2642-fe0f:! +man_kneeling_facing_right|1f9ce-200d-2642-fe0f-200d-27a1-fe0f|!|2,3,4,5,6:1f9ce-*-200d-2642-fe0f-200d-27a1-fe0f:! +person_kneeling_facing_right|1f9ce-200d-27a1-fe0f|!|2,3,4,5,6:1f9ce-*-200d-27a1-fe0f:! +deaf_person|1f9cf||2,3,4,5,6:1f9cf-* +deaf_woman|1f9cf-200d-2640-fe0f|!|2,3,4,5,6:1f9cf-*-200d-2640-fe0f:! +deaf_man|1f9cf-200d-2642-fe0f|!|2,3,4,5,6:1f9cf-*-200d-2642-fe0f:! +face_with_monocle|1f9d0| +adult|1f9d1||2,3,4,5,6:1f9d1-* +farmer|1f9d1-200d-1f33e||2,3,4,5,6:1f9d1-*-200d-1f33e +cook|1f9d1-200d-1f373||2,3,4,5,6:1f9d1-*-200d-1f373 +person_feeding_baby|1f9d1-200d-1f37c||2,3,4,5,6:1f9d1-*-200d-1f37c +mx_claus|1f9d1-200d-1f384||2,3,4,5,6:1f9d1-*-200d-1f384 +student|1f9d1-200d-1f393||2,3,4,5,6:1f9d1-*-200d-1f393 +singer|1f9d1-200d-1f3a4||2,3,4,5,6:1f9d1-*-200d-1f3a4 +artist|1f9d1-200d-1f3a8||2,3,4,5,6:1f9d1-*-200d-1f3a8 +teacher|1f9d1-200d-1f3eb||2,3,4,5,6:1f9d1-*-200d-1f3eb +factory_worker|1f9d1-200d-1f3ed||2,3,4,5,6:1f9d1-*-200d-1f3ed +technologist|1f9d1-200d-1f4bb||2,3,4,5,6:1f9d1-*-200d-1f4bb +office_worker|1f9d1-200d-1f4bc||2,3,4,5,6:1f9d1-*-200d-1f4bc +mechanic|1f9d1-200d-1f527||2,3,4,5,6:1f9d1-*-200d-1f527 +scientist|1f9d1-200d-1f52c||2,3,4,5,6:1f9d1-*-200d-1f52c +astronaut|1f9d1-200d-1f680||2,3,4,5,6:1f9d1-*-200d-1f680 +firefighter|1f9d1-200d-1f692||2,3,4,5,6:1f9d1-*-200d-1f692 +people_holding_hands|1f9d1-200d-1f91d-200d-1f9d1||22,23,24,25,26,32,33,34,35,36,42,43,44,45,46,52,53,54,55,56,62,63,64,65,66:1f9d1-*-200d-1f91d-200d-1f9d1-* +person_with_probing_cane|1f9d1-200d-1f9af||2,3,4,5,6:1f9d1-*-200d-1f9af +person_with_white_cane_facing_right|1f9d1-200d-1f9af-200d-27a1-fe0f|!|2,3,4,5,6:1f9d1-*-200d-1f9af-200d-27a1-fe0f:! +red_haired_person|1f9d1-200d-1f9b0||2,3,4,5,6:1f9d1-*-200d-1f9b0 +curly_haired_person|1f9d1-200d-1f9b1||2,3,4,5,6:1f9d1-*-200d-1f9b1 +bald_person|1f9d1-200d-1f9b2||2,3,4,5,6:1f9d1-*-200d-1f9b2 +white_haired_person|1f9d1-200d-1f9b3||2,3,4,5,6:1f9d1-*-200d-1f9b3 +person_in_motorized_wheelchair|1f9d1-200d-1f9bc||2,3,4,5,6:1f9d1-*-200d-1f9bc +person_in_motorized_wheelchair_facing_right|1f9d1-200d-1f9bc-200d-27a1-fe0f|!|2,3,4,5,6:1f9d1-*-200d-1f9bc-200d-27a1-fe0f:! +person_in_manual_wheelchair|1f9d1-200d-1f9bd||2,3,4,5,6:1f9d1-*-200d-1f9bd +person_in_manual_wheelchair_facing_right|1f9d1-200d-1f9bd-200d-27a1-fe0f|!|2,3,4,5,6:1f9d1-*-200d-1f9bd-200d-27a1-fe0f:! +family_adult_adult_child|1f9d1-200d-1f9d1-200d-1f9d2| +family_adult_adult_child_child|1f9d1-200d-1f9d1-200d-1f9d2-200d-1f9d2| +family_adult_child|1f9d1-200d-1f9d2| +family_adult_child_child|1f9d1-200d-1f9d2-200d-1f9d2| +health_worker|1f9d1-200d-2695-fe0f|!|2,3,4,5,6:1f9d1-*-200d-2695-fe0f:! +judge|1f9d1-200d-2696-fe0f|!|2,3,4,5,6:1f9d1-*-200d-2696-fe0f:! +pilot|1f9d1-200d-2708-fe0f|!|2,3,4,5,6:1f9d1-*-200d-2708-fe0f:! +child|1f9d2||2,3,4,5,6:1f9d2-* +older_adult|1f9d3||2,3,4,5,6:1f9d3-* +bearded_person|1f9d4||2,3,4,5,6:1f9d4-* +woman_with_beard|1f9d4-200d-2640-fe0f|!|2,3,4,5,6:1f9d4-*-200d-2640-fe0f:! +man_with_beard|1f9d4-200d-2642-fe0f|!|2,3,4,5,6:1f9d4-*-200d-2642-fe0f:! +person_with_headscarf|1f9d5||2,3,4,5,6:1f9d5-* +person_in_steamy_room|1f9d6||2,3,4,5,6:1f9d6-* +woman_in_steamy_room|1f9d6-200d-2640-fe0f|!|2,3,4,5,6:1f9d6-*-200d-2640-fe0f:! +man_in_steamy_room|1f9d6-200d-2642-fe0f|!|2,3,4,5,6:1f9d6-*-200d-2642-fe0f:! +person_climbing|1f9d7||2,3,4,5,6:1f9d7-* +woman_climbing|1f9d7-200d-2640-fe0f|!|2,3,4,5,6:1f9d7-*-200d-2640-fe0f:! +man_climbing|1f9d7-200d-2642-fe0f|!|2,3,4,5,6:1f9d7-*-200d-2642-fe0f:! +person_in_lotus_position|1f9d8||2,3,4,5,6:1f9d8-* +woman_in_lotus_position|1f9d8-200d-2640-fe0f|!|2,3,4,5,6:1f9d8-*-200d-2640-fe0f:! +man_in_lotus_position|1f9d8-200d-2642-fe0f|!|2,3,4,5,6:1f9d8-*-200d-2642-fe0f:! +mage|1f9d9||2,3,4,5,6:1f9d9-* +female_mage|1f9d9-200d-2640-fe0f|!|2,3,4,5,6:1f9d9-*-200d-2640-fe0f:! +male_mage|1f9d9-200d-2642-fe0f|!|2,3,4,5,6:1f9d9-*-200d-2642-fe0f:! +fairy|1f9da||2,3,4,5,6:1f9da-* +female_fairy|1f9da-200d-2640-fe0f|!|2,3,4,5,6:1f9da-*-200d-2640-fe0f:! +male_fairy|1f9da-200d-2642-fe0f|!|2,3,4,5,6:1f9da-*-200d-2642-fe0f:! +vampire|1f9db||2,3,4,5,6:1f9db-* +female_vampire|1f9db-200d-2640-fe0f|!|2,3,4,5,6:1f9db-*-200d-2640-fe0f:! +male_vampire|1f9db-200d-2642-fe0f|!|2,3,4,5,6:1f9db-*-200d-2642-fe0f:! +merperson|1f9dc||2,3,4,5,6:1f9dc-* +mermaid|1f9dc-200d-2640-fe0f|!|2,3,4,5,6:1f9dc-*-200d-2640-fe0f:! +merman|1f9dc-200d-2642-fe0f|!|2,3,4,5,6:1f9dc-*-200d-2642-fe0f:! +elf|1f9dd||2,3,4,5,6:1f9dd-* +female_elf|1f9dd-200d-2640-fe0f|!|2,3,4,5,6:1f9dd-*-200d-2640-fe0f:! +male_elf|1f9dd-200d-2642-fe0f|!|2,3,4,5,6:1f9dd-*-200d-2642-fe0f:! +genie|1f9de| +female_genie|1f9de-200d-2640-fe0f|! +male_genie|1f9de-200d-2642-fe0f|! +zombie|1f9df| +female_zombie|1f9df-200d-2640-fe0f|! +male_zombie|1f9df-200d-2642-fe0f|! +brain|1f9e0| +orange_heart|1f9e1| +billed_cap|1f9e2| +scarf|1f9e3| +gloves|1f9e4| +coat|1f9e5| +socks|1f9e6| +red_envelope|1f9e7| +firecracker|1f9e8| +jigsaw|1f9e9| +test_tube|1f9ea| +petri_dish|1f9eb| +dna|1f9ec| +compass|1f9ed| +abacus|1f9ee| +fire_extinguisher|1f9ef| +toolbox|1f9f0| +bricks|1f9f1| +magnet|1f9f2| +luggage|1f9f3| +lotion_bottle|1f9f4| +thread|1f9f5| +yarn|1f9f6| +safety_pin|1f9f7| +teddy_bear|1f9f8| +broom|1f9f9| +basket|1f9fa| +roll_of_paper|1f9fb| +soap|1f9fc| +sponge|1f9fd| +receipt|1f9fe| +nazar_amulet|1f9ff| +ballet_shoes|1fa70| +one-piece_swimsuit|1fa71| +briefs|1fa72| +shorts|1fa73| +thong_sandal|1fa74| +light_blue_heart|1fa75| +grey_heart|1fa76| +pink_heart|1fa77| +drop_of_blood|1fa78| +adhesive_bandage|1fa79| +stethoscope|1fa7a| +x-ray|1fa7b| +crutch|1fa7c| +yo-yo|1fa80| +kite|1fa81| +parachute|1fa82| +boomerang|1fa83| +magic_wand|1fa84| +pinata|1fa85| +nesting_dolls|1fa86| +maracas|1fa87| +flute|1fa88| +harp|1fa89| +shovel|1fa8f| +ringed_planet|1fa90| +chair|1fa91| +razor|1fa92| +axe|1fa93| +diya_lamp|1fa94| +banjo|1fa95| +military_helmet|1fa96| +accordion|1fa97| +long_drum|1fa98| +coin|1fa99| +carpentry_saw|1fa9a| +screwdriver|1fa9b| +ladder|1fa9c| +hook|1fa9d| +mirror|1fa9e| +window|1fa9f| +plunger|1faa0| +sewing_needle|1faa1| +knot|1faa2| +bucket|1faa3| +mouse_trap|1faa4| +toothbrush|1faa5| +headstone|1faa6| +placard|1faa7| +rock|1faa8| +mirror_ball|1faa9| +identification_card|1faaa| +low_battery|1faab| +hamsa|1faac| +folding_hand_fan|1faad| +hair_pick|1faae| +khanda|1faaf| +fly|1fab0| +worm|1fab1| +beetle|1fab2| +cockroach|1fab3| +potted_plant|1fab4| +wood|1fab5| +feather|1fab6| +lotus|1fab7| +coral|1fab8| +empty_nest|1fab9| +nest_with_eggs|1faba| +hyacinth|1fabb| +jellyfish|1fabc| +wing|1fabd| +leafless_tree|1fabe| +goose|1fabf| +anatomical_heart|1fac0| +lungs|1fac1| +people_hugging|1fac2| +pregnant_man|1fac3||2,3,4,5,6:1fac3-* +pregnant_person|1fac4||2,3,4,5,6:1fac4-* +person_with_crown|1fac5||2,3,4,5,6:1fac5-* +fingerprint|1fac6| +moose|1face| +donkey|1facf| +blueberries|1fad0| +bell_pepper|1fad1| +olive|1fad2| +flatbread|1fad3| +tamale|1fad4| +fondue|1fad5| +teapot|1fad6| +pouring_liquid|1fad7| +beans|1fad8| +jar|1fad9| +ginger_root|1fada| +pea_pod|1fadb| +root_vegetable|1fadc| +splatter|1fadf| +melting_face|1fae0| +saluting_face|1fae1| +face_with_open_eyes_and_hand_over_mouth|1fae2| +face_with_peeking_eye|1fae3| +face_with_diagonal_mouth|1fae4| +dotted_line_face|1fae5| +biting_lip|1fae6| +bubbles|1fae7| +shaking_face|1fae8| +face_with_bags_under_eyes|1fae9| +hand_with_index_finger_and_thumb_crossed|1faf0||2,3,4,5,6:1faf0-* +rightwards_hand|1faf1||2,3,4,5,6:1faf1-* +leftwards_hand|1faf2||2,3,4,5,6:1faf2-* +palm_down_hand|1faf3||2,3,4,5,6:1faf3-* +palm_up_hand|1faf4||2,3,4,5,6:1faf4-* +index_pointing_at_the_viewer|1faf5||2,3,4,5,6:1faf5-* +heart_hands|1faf6||2,3,4,5,6:1faf6-* +leftwards_pushing_hand|1faf7||2,3,4,5,6:1faf7-* +rightwards_pushing_hand|1faf8||2,3,4,5,6:1faf8-* +bangbang|203c-fe0f|! +interrobang|2049-fe0f|! +tm|2122-fe0f|! +information_source|2139-fe0f|! +left_right_arrow|2194-fe0f|! +arrow_up_down|2195-fe0f|! +arrow_upper_left|2196-fe0f|! +arrow_upper_right|2197-fe0f|! +arrow_lower_right|2198-fe0f|! +arrow_lower_left|2199-fe0f|! +leftwards_arrow_with_hook|21a9-fe0f|! +arrow_right_hook|21aa-fe0f|! +watch|231a| +hourglass|231b| +keyboard|2328-fe0f|! +eject|23cf-fe0f|! +fast_forward|23e9| +rewind|23ea| +arrow_double_up|23eb| +arrow_double_down|23ec| +black_right_pointing_double_triangle_with_vertical_bar|23ed-fe0f|! +black_left_pointing_double_triangle_with_vertical_bar|23ee-fe0f|! +black_right_pointing_triangle_with_double_vertical_bar|23ef-fe0f|! +alarm_clock|23f0| +stopwatch|23f1-fe0f|! +timer_clock|23f2-fe0f|! +hourglass_flowing_sand|23f3| +double_vertical_bar|23f8-fe0f|! +black_square_for_stop|23f9-fe0f|! +black_circle_for_record|23fa-fe0f|! +m|24c2-fe0f|! +black_small_square|25aa-fe0f|! +white_small_square|25ab-fe0f|! +arrow_forward|25b6-fe0f|! +arrow_backward|25c0-fe0f|! +white_medium_square|25fb-fe0f|! +black_medium_square|25fc-fe0f|! +white_medium_small_square|25fd| +black_medium_small_square|25fe| +sunny|2600-fe0f|! +cloud|2601-fe0f|! +umbrella|2602-fe0f|! +snowman|2603-fe0f|! +comet|2604-fe0f|! +phone,telephone|260e-fe0f|! +ballot_box_with_check|2611-fe0f|! +umbrella_with_rain_drops|2614| +coffee|2615| +shamrock|2618-fe0f|! +point_up|261d-fe0f|!|2,3,4,5,6:261d-* +skull_and_crossbones|2620-fe0f|! +radioactive_sign|2622-fe0f|! +biohazard_sign|2623-fe0f|! +orthodox_cross|2626-fe0f|! +star_and_crescent|262a-fe0f|! +peace_symbol|262e-fe0f|! +yin_yang|262f-fe0f|! +wheel_of_dharma|2638-fe0f|! +white_frowning_face|2639-fe0f|! +relaxed|263a-fe0f|! +female_sign|2640-fe0f|! +male_sign|2642-fe0f|! +aries|2648| +taurus|2649| +gemini|264a| +cancer|264b| +leo|264c| +virgo|264d| +libra|264e| +scorpius|264f| +sagittarius|2650| +capricorn|2651| +aquarius|2652| +pisces|2653| +chess_pawn|265f-fe0f|! +spades|2660-fe0f|! +clubs|2663-fe0f|! +hearts|2665-fe0f|! +diamonds|2666-fe0f|! +hotsprings|2668-fe0f|! +recycle|267b-fe0f|! +infinity|267e-fe0f|! +wheelchair|267f| +hammer_and_pick|2692-fe0f|! +anchor|2693| +crossed_swords|2694-fe0f|! +medical_symbol,staff_of_aesculapius|2695-fe0f|! +scales|2696-fe0f|! +alembic|2697-fe0f|! +gear|2699-fe0f|! +atom_symbol|269b-fe0f|! +fleur_de_lis|269c-fe0f|! +warning|26a0-fe0f|! +zap|26a1| +transgender_symbol|26a7-fe0f|! +white_circle|26aa| +black_circle|26ab| +coffin|26b0-fe0f|! +funeral_urn|26b1-fe0f|! +soccer|26bd| +baseball|26be| +snowman_without_snow|26c4| +partly_sunny|26c5| +thunder_cloud_and_rain|26c8-fe0f|! +ophiuchus|26ce| +pick|26cf-fe0f|! +helmet_with_white_cross|26d1-fe0f|! +chains|26d3-fe0f|! +broken_chain|26d3-fe0f-200d-1f4a5|! +no_entry|26d4| +shinto_shrine|26e9-fe0f|! +church|26ea| +mountain|26f0-fe0f|! +umbrella_on_ground|26f1-fe0f|! +fountain|26f2| +golf|26f3| +ferry|26f4-fe0f|! +boat,sailboat|26f5| +skier|26f7-fe0f|! +ice_skate|26f8-fe0f|! +person_with_ball|26f9-fe0f|!|2,3,4,5,6:26f9-* +woman-bouncing-ball|26f9-fe0f-200d-2640-fe0f|!|2,3,4,5,6:26f9-*-200d-2640-fe0f:! +man-bouncing-ball|26f9-fe0f-200d-2642-fe0f|!|2,3,4,5,6:26f9-*-200d-2642-fe0f:! +tent|26fa| +fuelpump|26fd| +scissors|2702-fe0f|! +white_check_mark|2705| +airplane|2708-fe0f|! +email,envelope|2709-fe0f|! +fist|270a||2,3,4,5,6:270a-* +hand,raised_hand|270b||2,3,4,5,6:270b-* +v|270c-fe0f|!|2,3,4,5,6:270c-* +writing_hand|270d-fe0f|!|2,3,4,5,6:270d-* +pencil2|270f-fe0f|! +black_nib|2712-fe0f|! +heavy_check_mark|2714-fe0f|! +heavy_multiplication_x|2716-fe0f|! +latin_cross|271d-fe0f|! +star_of_david|2721-fe0f|! +sparkles|2728| +eight_spoked_asterisk|2733-fe0f|! +eight_pointed_black_star|2734-fe0f|! +snowflake|2744-fe0f|! +sparkle|2747-fe0f|! +x|274c| +negative_squared_cross_mark|274e| +question|2753| +grey_question|2754| +grey_exclamation|2755| +exclamation,heavy_exclamation_mark|2757| +heavy_heart_exclamation_mark_ornament|2763-fe0f|! +heart|2764-fe0f|! +heart_on_fire|2764-fe0f-200d-1f525|! +mending_heart|2764-fe0f-200d-1fa79|! +heavy_plus_sign|2795| +heavy_minus_sign|2796| +heavy_division_sign|2797| +arrow_right|27a1-fe0f|! +curly_loop|27b0| +loop|27bf| +arrow_heading_up|2934-fe0f|! +arrow_heading_down|2935-fe0f|! +arrow_left|2b05-fe0f|! +arrow_up|2b06-fe0f|! +arrow_down|2b07-fe0f|! +black_large_square|2b1b| +white_large_square|2b1c| +star|2b50| +o|2b55| +wavy_dash|3030-fe0f|! +part_alternation_mark|303d-fe0f|! +congratulations|3297-fe0f|! +secret|3299-fe0f|!` diff --git a/packages/chat/slack/src/internal/errors.ts b/packages/chat/slack/src/internal/errors.ts new file mode 100644 index 00000000000..0ab0c227691 --- /dev/null +++ b/packages/chat/slack/src/internal/errors.ts @@ -0,0 +1,151 @@ +import { + ChatError, + type ChatErrorReason, + Forbidden, + InvalidRequest, + InvalidResponse, + NotFound, + PlatformUnavailable, + RateLimited, + TooLarge, + Transport, + Unauthenticated, + Unknown +} from "effect/chat/ChatError" +import * as Duration from "effect/Duration" +import { platform } from "./address.ts" + +const unauthenticated = new Set([ + "invalid_auth", + "not_authed", + "account_inactive", + "token_revoked", + "token_expired", + "org_login_required" +]) + +const forbidden = new Set([ + "access_denied", + "accesslimited", + "missing_scope", + "not_in_channel", + "is_archived", + "channel_is_archived", + "no_permission", + "not_allowed_token_type", + "not_authorized", + "restricted_action", + "restricted_action_read_only_channel", + "restricted_action_thread_only_channel", + "restricted_action_non_threadable_channel", + "cant_update_message", + "cant_delete_message", + "cant_delete_file", + "edit_window_closed", + "ekm_access_denied", + "enterprise_is_restricted", + "team_access_not_granted", + "posting_to_general_channel_denied", + "message_not_owned_by_app", + "messages_tab_disabled", + "message_limit_exceeded", + "thread_locked", + "user_is_restricted", + "feature_disabled", + "channel_type_not_supported" +]) + +const notFoundCodes = new Set([ + "channel_not_found", + "message_not_found", + "thread_not_found", + "user_not_found", + "users_not_found", + "file_not_found", + "file_deleted", + "bot_not_found", + "team_not_found" +]) + +const tooLarge = new Set(["msg_too_long", "msg_blocks_too_long"]) + +const serverErrors = new Set(["internal_error", "fatal_error", "service_unavailable", "request_timeout"]) + +/** + * Maps the `error` of an `ok: false` answer to a reason. `detail` is always + * Slack's error code, which holds no message text or ids. + * + * @internal + */ +export const reasonForCode = ( + code: string, + options: { readonly write: boolean; readonly retryAfter?: Duration.Duration | undefined } +): ChatErrorReason => { + if (code === "ratelimited" || code === "rate_limited") { + return new RateLimited({ + detail: code, + ...(options.retryAfter === undefined ? {} : { retryAfter: options.retryAfter }) + }) + } + if (unauthenticated.has(code)) return new Unauthenticated({ detail: code }) + if (forbidden.has(code)) return new Forbidden({ detail: code }) + if (notFoundCodes.has(code)) return new NotFound({ detail: code }) + if (tooLarge.has(code)) return new TooLarge({ subject: "text", detail: code }) + if (code === "file_too_large" || code === "too_many_files") return new TooLarge({ subject: "files", detail: code }) + if (serverErrors.has(code)) { + return new PlatformUnavailable({ retry: options.write ? "uncertain" : "retry", detail: code }) + } + return new InvalidRequest({ detail: code }) +} + +/** @internal */ +export const reasonForStatus = ( + status: number, + options: { readonly write: boolean; readonly retryAfter?: Duration.Duration | undefined; readonly cause?: unknown } +): ChatErrorReason => { + const detail = `http_${status}` + const cause = options.cause === undefined ? {} : { cause: options.cause } + if (status === 429) { + return new RateLimited({ + detail, + ...cause, + ...(options.retryAfter === undefined ? {} : { retryAfter: options.retryAfter }) + }) + } + if (status >= 500) return new PlatformUnavailable({ retry: options.write ? "uncertain" : "retry", detail, ...cause }) + if (status === 401) return new Unauthenticated({ detail, ...cause }) + if (status === 403) return new Forbidden({ detail, ...cause }) + if (status === 404) return new NotFound({ detail, ...cause }) + if (status === 413) return new TooLarge({ detail, ...cause }) + return new InvalidRequest({ detail, ...cause }) +} + +/** A request that failed before an answer came. @internal */ +export const transport = (write: boolean, detail: string, cause?: unknown): ChatErrorReason => + new Transport({ retry: write ? "uncertain" : "retry", detail, ...(cause === undefined ? {} : { cause }) }) + +/** An answer the adapter cannot read. A write may have landed. @internal */ +export const invalidResponse = (write: boolean, detail: string, cause?: unknown): ChatErrorReason => { + const fields = { detail, ...(cause === undefined ? {} : { cause }) } + return write ? new Unknown(fields) : new InvalidResponse(fields) +} + +/** @internal */ +export const parseRetryAfter = (value: string | undefined): Duration.Duration | undefined => { + if (value === undefined) return undefined + const seconds = Number(value) + return Number.isFinite(seconds) && seconds >= 0 ? Duration.seconds(seconds) : undefined +} + +/** @internal */ +export const chatError = (op: string, reason: ChatErrorReason): ChatError => new ChatError({ platform, op, reason }) + +/** @internal */ +export const withOp = (op: string) => (error: ChatError): ChatError => + error.op === op ? error : new ChatError({ platform: error.platform, op, reason: error.reason }) + +/** @internal */ +export const invalidRequest = (detail: string): ChatErrorReason => new InvalidRequest({ detail }) + +/** @internal */ +export const notFound = (detail: string): ChatErrorReason => new NotFound({ detail }) diff --git a/packages/chat/slack/src/internal/escape.ts b/packages/chat/slack/src/internal/escape.ts new file mode 100644 index 00000000000..95bb6426103 --- /dev/null +++ b/packages/chat/slack/src/internal/escape.ts @@ -0,0 +1,248 @@ +/** + * Escaping for Slack's `markdown_text`: a `<` outside inline and fenced code + * becomes `<`, so no mention token notifies, unless the scoped notify + * options allow that token. + */ + +/** @internal */ +export interface Notify { + readonly users?: ReadonlyArray | undefined + readonly groups?: ReadonlyArray | undefined + readonly broadcast?: boolean | undefined +} + +interface Fence { + readonly char: string + readonly length: number +} + +/** + * Where an escaper left off: the fence open at the start of the current line, + * and the raw text of that line consumed so far. + * + * @internal + */ +export interface State { + readonly fence: Fence | undefined + readonly line: string +} + +/** @internal */ +export const initialState: State = { fence: undefined, line: "" } + +/** @internal */ +export interface Escaped { + /** What to send for the consumed part of the input. */ + readonly sent: string + /** How many characters of the input were consumed. The rest is held. */ + readonly consumed: number + readonly state: State +} + +/** Past this many held characters, an undecided `<` is escaped anyway. */ +const holdBound = 300 + +const tokenPattern = /^<(@([UW][A-Z0-9]+)|!subteam\^([A-Z0-9]+)|!(here|channel|everyone))(\|[^<>]*)?>/ + +const allowsAny = (notify: Notify): boolean => + (notify.users?.length ?? 0) > 0 || (notify.groups?.length ?? 0) > 0 || notify.broadcast === true + +const allowedToken = (rest: string, notify: Notify): number => { + const match = tokenPattern.exec(rest) + if (match === null) return 0 + const [token, , user, group, broadcast] = match + if (user !== undefined) return notify.users?.includes(user) ? token.length : 0 + if (group !== undefined) return notify.groups?.includes(group) ? token.length : 0 + return broadcast !== undefined && notify.broadcast === true ? token.length : 0 +} + +const openingFence = /^ {0,3}(`{3,}|~{3,})(.*)$/ +const closingFence = /^ {0,3}(`{3,}|~{3,})[ \t]*\r?$/ + +const opensFence = (line: string): Fence | undefined => { + const match = openingFence.exec(line) + if (match === null) return undefined + const marker = match[1] + if (marker[0] === "`" && match[2].includes("`")) return undefined + return { char: marker[0], length: marker.length } +} + +const closesFence = (line: string, fence: Fence): boolean => { + const match = closingFence.exec(line) + return match !== null && match[1][0] === fence.char && match[1].length >= fence.length +} + +const backtickRun = (line: string, start: number): number => { + let end = start + while (line[end] === "`") end++ + return end - start +} + +/** + * The code spans of one line, as `[start, end)` pairs, and the position of a + * backtick run that opens a span the line has not closed yet. + */ +const codeSpans = (line: string): { readonly spans: Array; readonly open: number } => { + const spans: Array = [] + let i = 0 + let open = -1 + while (i < line.length) { + if (line[i] !== "`") { + i++ + continue + } + const length = backtickRun(line, i) + let j = i + length + let closed = -1 + while (j < line.length) { + if (line[j] === "`") { + const run = backtickRun(line, j) + if (run === length) { + closed = j + break + } + j += run + } else { + j++ + } + } + if (closed === -1) { + if (open === -1) open = i + i += length + } else { + spans.push([i, closed + length]) + i = closed + length + } + } + return { spans, open } +} + +/** + * Escapes `text`, continuing from `state`. Without `flush`, a `<` whose + * meaning the rest of the stream could still change is held: an unclosed + * token that the notify options might allow, or one after a backtick the line + * has not closed yet. With `flush`, or once the held text passes a bound, + * it is escaped. + * + * @internal + */ +export const escape = ( + text: string, + notify: Notify, + options?: { readonly state?: State | undefined; readonly flush?: boolean | undefined } +): Escaped => { + const state = options?.state ?? initialState + const flush = options?.flush === true + const full = state.line + text + const offset = state.line.length + const anyAllowed = allowsAny(notify) + let fence = state.fence + let out = "" + let lineStart = 0 + const emit = (from: number, to: number, piece?: string) => { + if (to <= offset) return + out += piece !== undefined ? piece : full.slice(Math.max(from, offset), to) + } + while (lineStart <= full.length) { + const newline = full.indexOf("\n", lineStart) + const complete = newline !== -1 + const lineEnd = complete ? newline : full.length + const line = full.slice(lineStart, lineEnd) + if (fence !== undefined) { + emit(lineStart, lineEnd) + if (complete && closesFence(line, fence)) fence = undefined + } else { + const opener = complete ? opensFence(line) : undefined + const { open, spans } = opener === undefined ? codeSpans(line) : { open: -1, spans: [] } + let i = 0 + let span = 0 + while (i < line.length) { + while (span < spans.length && spans[span][1] <= i) span++ + if (span < spans.length && spans[span][0] <= i) { + emit(lineStart + i, lineStart + spans[span][1]) + i = spans[span][1] + continue + } + const next = line.indexOf("<", i) + const stop = next === -1 ? line.length : Math.min(next, span < spans.length ? spans[span][0] : line.length) + if (stop > i) { + emit(lineStart + i, lineStart + stop) + i = stop + continue + } + // A `<` outside code. + const at = lineStart + i + const rest = line.slice(i) + const undecided = !flush && !complete && full.length - at <= holdBound && ( + (open !== -1 && open < i) || + (anyAllowed && !rest.includes(">") && /^<(@|!)?[\w^|]*$/.test(rest)) + ) + if (undecided) { + return { + sent: out, + consumed: at - offset, + state: { fence, line: full.slice(lineStart, at) } + } + } + const token = allowedToken(rest, notify) + if (token > 0) { + emit(at, at + token) + i += token + } else { + emit(at, at + 1, at >= offset ? "<" : undefined) + i += 1 + } + } + if (opener !== undefined) fence = opener + } + if (!complete) { + return { sent: out, consumed: full.length - offset, state: { fence, line } } + } + emit(lineEnd, lineEnd + 1) + lineStart = lineEnd + 1 + } + return { sent: out, consumed: full.length - offset, state: { fence, line: "" } } +} + +const mrkdwnEntities = (text: string): string => text.replace(/&/g, "&").replace(//g, ">") + +/** + * Markdown as Slack's mrkdwn, for the text of a message that carries files, + * which takes no `markdown_text`. Outside code, headings and bold become + * `*bold*`, strikethrough `~struck~` and links ``, a `>` that opens + * a quote stays, and `&`, `<` and `>` are escaped unless they belong to a + * token the notify options allow. + * + * @internal + */ +export const toMrkdwn = (markdown: string, notify: Notify): string => + markdown + .split(/(```[\s\S]*?```|`[^`\n]*`)/) + .map((part, index) => { + if (index % 2 === 1) return mrkdwnEntities(part.replace(/^```[\w+#.-]+\n/, "```\n")) + // Allowed tokens become private-use placeholders, so the conversions + // below can span them but never change them. + const tokens: Array = [] + let masked = "" + let i = 0 + while (i < part.length) { + const token = part[i] === "<" ? allowedToken(part.slice(i), notify) : 0 + if (token > 0) { + masked += `\uE000${tokens.push(part.slice(i, i + token)) - 1}\uE001` + i += token + } else { + masked += part[i] + i++ + } + } + return masked + .replace(/&/g, "&") + .replace(/|>/gm, (match, indent: string | undefined) => indent === undefined ? ">" : match) + .replace(/^#{1,6}[ \t]+(.+?)[ \t#]*$/gm, "*$1*") + .replace(/\*\*(.+?)\*\*|__(.+?)__/g, (_, star: string | undefined, under: string) => `*${star ?? under}*`) + .replace(/~~(.+?)~~/g, "~$1~") + .replace(/\[([^\]\n]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/g, "<$2|$1>") + .replace(/\uE000(\d+)\uE001/g, (_, index: string) => tokens[Number(index)]) + }) + .join("") diff --git a/packages/chat/slack/src/internal/length.ts b/packages/chat/slack/src/internal/length.ts new file mode 100644 index 00000000000..74b8970bef9 --- /dev/null +++ b/packages/chat/slack/src/internal/length.ts @@ -0,0 +1,44 @@ +import { blocksCost } from "./emoji.ts" + +/** `msg_too_long`: code points of `markdown_text` as sent, inclusive. @internal */ +export const messageLength = 12_000 + +/** `msg_blocks_too_long`: Slack's count with every emoji as its shortcode, inclusive. @internal */ +export const blocksLength = 13_200 + +/** @internal */ +export const codePoints = (text: string): number => { + let count = 0 + for (let i = 0; i < text.length; i++) { + const code = text.charCodeAt(i) + if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) { + const low = text.charCodeAt(i + 1) + if (low >= 0xdc00 && low <= 0xdfff) i++ + } + count++ + } + return count +} + +const lessThan = (text: string): number => { + let count = 0 + for (let i = text.indexOf("<"); i !== -1; i = text.indexOf("<", i + 1)) count++ + return count +} + +/** + * What a Markdown string costs against `messageLength`, as an upper bound + * that adds up. It is the larger of two counts: code points plus three for + * every `<`, which may be sent as `<`, and Slack's emoji-as-shortcode + * count scaled from 13,200 to 12,000. + * + * @internal + */ +export const measure = (markdown: string): number => + Math.max( + codePoints(markdown) + 3 * lessThan(markdown), + Math.ceil(blocksCost(markdown) * 10 / 11) + ) + +/** @internal */ +export { blocksCost } diff --git a/packages/chat/slack/src/internal/mentions.ts b/packages/chat/slack/src/internal/mentions.ts new file mode 100644 index 00000000000..89e9d5a0ab4 --- /dev/null +++ b/packages/chat/slack/src/internal/mentions.ts @@ -0,0 +1,164 @@ +import type { Mention } from "effect/chat/ChatMessage" + +type Kind = Mention["kind"] + +interface Target { + readonly kind: Kind + readonly id: string +} + +/** A mention token in `text`, as Slack writes it. */ +const tokenPattern = + /<(@([UW][A-Z0-9]+)|!subteam\^([A-Z0-9]+)|#(C[A-Z0-9]+|G[A-Z0-9]+)|!(here|channel|everyone))(\|[^<>]*)?>/g + +/** + * Parses one token, `<@U123>`, ``, `<#C123|name>` or + * ``, as the whole of `slice`. + * + * @internal + */ +export const parseToken = (slice: string): Target | undefined => { + tokenPattern.lastIndex = 0 + const match = tokenPattern.exec(slice) + if (match === null || match.index !== 0 || match[0].length !== slice.length) return undefined + return targetOf(match) +} + +const targetOf = (match: RegExpExecArray): Target => { + const [, , user, group, channel, broadcast] = match + if (user !== undefined) return { kind: "user", id: user } + if (group !== undefined) return { kind: "role", id: group } + if (channel !== undefined) return { kind: "channel", id: channel } + return { kind: "broadcast", id: broadcast! } +} + +interface Token extends Target { + readonly start: number + readonly end: number +} + +const tokens = (text: string, skipCode: boolean): Array => { + const code: Array = [] + if (skipCode) { + const codePattern = /```[\s\S]*?```|`[^`\n]+`/g + for (let match = codePattern.exec(text); match !== null; match = codePattern.exec(text)) { + code.push([match.index, match.index + match[0].length]) + } + } + const found: Array = [] + tokenPattern.lastIndex = 0 + for (let match = tokenPattern.exec(text); match !== null; match = tokenPattern.exec(text)) { + const start = match.index + if (code.some(([from, to]) => start >= from && start < to)) continue + found.push({ ...targetOf(match), start, end: start + match[0].length }) + } + return found +} + +const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u) + +interface Item extends Target { + readonly real: boolean +} + +/** + * The items of a message's `rich_text` blocks that a token in `text` can + * stand for, in order. A `user`, `usergroup`, `channel` or `broadcast` + * element is a real mention, unless it has code style or sits in a + * preformatted section. A token-shaped string in text elements (adjacent + * ones joined) is a literal, as is a code-styled element. `undefined` when + * the message has no `rich_text` block. + */ +const richTextItems = (blocks: unknown): Array | undefined => { + if (!Array.isArray(blocks)) return undefined + const rich = blocks.filter((block) => isObject(block) && block.type === "rich_text") + if (rich.length === 0) return undefined + const items: Array = [] + let pending = "" + const flushText = () => { + if (pending === "") return + for (const token of tokens(pending, false)) items.push({ kind: token.kind, id: token.id, real: false }) + pending = "" + } + const walk = (element: unknown, inCode: boolean): void => { + if (!isObject(element)) return + const code = inCode || element.type === "rich_text_preformatted" + const style = element.style + const literal = code || (isObject(style) && style.code === true) + let target: Target | undefined + switch (element.type) { + case "text": + if (typeof element.text === "string") pending += element.text + return + case "user": + if (typeof element.user_id === "string") target = { kind: "user", id: element.user_id } + break + case "usergroup": + if (typeof element.usergroup_id === "string") target = { kind: "role", id: element.usergroup_id } + break + case "channel": + if (typeof element.channel_id === "string") target = { kind: "channel", id: element.channel_id } + break + case "broadcast": + if (typeof element.range === "string") target = { kind: "broadcast", id: element.range } + break + } + if (target !== undefined) { + flushText() + items.push({ ...target, real: !literal }) + return + } + if (Array.isArray(element.elements)) { + flushText() + for (const child of element.elements) walk(child, code) + flushText() + } + } + for (const block of rich) walk(block, false) + flushText() + return items +} + +/** + * The mentions of a message with offsets into `text`. + * + * - With a `rich_text` block, the mentions are its real mention elements. + * The tokens in `text` are walked in order against the block's items: a + * token takes the next item it equals, and only a real item makes it a + * mention. When a real item is passed over without a token, the text scan + * below is used instead. + * - Without one, `text` is scanned, skipping backtick code spans and fences. + * That covers Block Kit posts, attachment-only posts and system messages. + * + * @internal + */ +export const extract = ( + text: string, + blocks: unknown, + botUserId: string +): Array => { + const toMention = (token: Token): Mention => ({ + kind: token.kind, + id: token.id, + start: token.start, + end: token.end, + isSelf: token.kind === "user" && token.id === botUserId + }) + const items = richTextItems(blocks) + if (items !== undefined) { + const matched: Array = [] + let next = 0 + let complete = true + for (const token of tokens(text, false)) { + let found = next + while (found < items.length && !(items[found].kind === token.kind && items[found].id === token.id)) found++ + if (found === items.length) continue + if (items.slice(next, found).some((item) => item.real)) complete = false + if (items[found].real) matched.push(toMention(token)) + next = found + 1 + } + if (items.slice(next).some((item) => item.real)) complete = false + if (complete) return matched + } + return tokens(text, true).map(toMention) +} diff --git a/packages/chat/slack/src/internal/normalize.ts b/packages/chat/slack/src/internal/normalize.ts new file mode 100644 index 00000000000..e909b3e4625 --- /dev/null +++ b/packages/chat/slack/src/internal/normalize.ts @@ -0,0 +1,226 @@ +import type * as ChatEvent from "effect/chat/ChatEvent" +import type * as ChatMessage from "effect/chat/ChatMessage" +import type * as ChatThread from "effect/chat/ChatThread" +import * as DateTime from "effect/DateTime" +import type * as Schema from "effect/Schema" +import { isDirectChannel, thread } from "./address.ts" +import * as Emoji from "./emoji.ts" +import * as Mentions from "./mentions.ts" + +/** + * The message subtypes that count as a message, for inbound events and for + * every read path alike. Anything else is rejected, so a subtype Slack adds + * later stays out until someone decides about it. + * + * @internal + */ +export const messageSubtypes: ReadonlySet = new Set([ + "file_share", + "thread_broadcast", + "bot_message", + "me_message" +]) + +type JsonObject = { readonly [key: string]: Schema.Json } + +const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u) + +const string = (object: JsonObject, key: string): string | undefined => { + const value = object[key] + return typeof value === "string" && value.length > 0 ? value : undefined +} + +const tsPattern = /^\d+\.\d+$/ + +/** When a Slack `ts` was sent. @internal */ +export const timestamp = (ts: string): DateTime.Utc => DateTime.makeUnsafe(Math.floor(Number(ts) * 1000)) + +/** @internal */ +export interface MessageContext { + readonly team: string + readonly channel: string + readonly botUserId: string +} + +const authorName = (message: JsonObject): string | undefined => { + const profile = message.user_profile + if (isObject(profile)) { + const name = string(profile, "display_name") ?? string(profile, "real_name") ?? string(profile, "name") + if (name !== undefined) return name + } + const bot = message.bot_profile + if (isObject(bot)) { + const name = string(bot, "name") + if (name !== undefined) return name + } + return string(message, "username") +} + +const attachments = (message: JsonObject): Array => { + const files = message.files + if (!Array.isArray(files)) return [] + const out: Array = [] + for (const file of files) { + if (!isObject(file)) continue + const id = string(file, "id") + if (id === undefined) continue + const name = string(file, "name") + const contentType = string(file, "mimetype") + const size = file.size + out.push({ + id, + ...(name === undefined ? {} : { name }), + ...(contentType === undefined ? {} : { contentType }), + ...(typeof size === "number" && Number.isSafeInteger(size) && size >= 0 ? { size } : {}) + }) + } + return out +} + +/** + * A Slack message payload as a `ChatMessage`, from an event or any read + * path. `undefined` when it is not a message: a subtype off the list, or no + * author. + * + * - The address is the channel when `thread_ts` is missing or equal to + * `ts`, and the thread otherwise. It never depends on later replies. + * - A `bot_message` has `bot_id` and no `user`: `author.id` is the + * `bot_id`, with `isBot` true. + * + * @internal + */ +export const message = (raw: unknown, context: MessageContext): ChatMessage.ChatMessage | undefined => { + if (!isObject(raw)) return undefined + const subtype = string(raw, "subtype") + if (subtype !== undefined && !messageSubtypes.has(subtype)) return undefined + const ts = string(raw, "ts") + if (ts === undefined || !tsPattern.test(ts)) return undefined + const user = string(raw, "user") + const botId = string(raw, "bot_id") + const authorId = user ?? botId + if (authorId === undefined) return undefined + const threadTs = string(raw, "thread_ts") + const text = typeof raw.text === "string" ? raw.text : "" + const name = authorName(raw) + return { + id: ts, + thread: thread({ + team: context.team, + channel: context.channel, + threadTs: threadTs === undefined || threadTs === ts ? undefined : threadTs + }), + author: { + id: authorId, + ...(name === undefined ? {} : { name }), + isBot: botId !== undefined || subtype === "bot_message" || user === context.botUserId, + isSelf: user !== undefined && user === context.botUserId + }, + text, + mentions: Mentions.extract(text, raw.blocks, context.botUserId), + attachments: attachments(raw), + timestamp: timestamp(ts), + raw + } +} + +const kindOf = (address: ChatThread.ChatThread, channel: string, channelType: string | undefined) => { + if (address.id.split("/").length === 3) return "thread" as const + return channelType === "im" || channelType === "mpim" || isDirectChannel(channel) + ? "direct" as const + : "channel" as const +} + +const forWorkspace = (envelope: JsonObject, teamId: string): boolean => { + if (envelope.team_id === teamId) return true + const authorizations = envelope.authorizations + return Array.isArray(authorizations) && + authorizations.some((authorization) => isObject(authorization) && authorization.team_id === teamId) +} + +/** The envelope as `raw`, without the deprecated verification `token`. */ +const envelopeRaw = (envelope: JsonObject): Schema.Json => { + if (!("token" in envelope)) return envelope + const { token: _, ...rest } = envelope + return rest +} + +/** An emoji name as Slack writes it, as Unicode, or `custom:{name}`. @internal */ +export const emoji = (name: string): string => Emoji.fromName(name) ?? `custom:${name}` + +/** + * The events in an `event_callback` envelope. + * + * @internal + */ +export const normalize = ( + envelope: unknown, + context: { readonly teamId: string; readonly botUserId: string } +): ReadonlyArray => { + if (!isObject(envelope) || envelope.type !== "event_callback") return [] + if (!forWorkspace(envelope, context.teamId)) return [] + const event = envelope.event + if (!isObject(event)) return [] + const raw = envelopeRaw(envelope) + const team = context.teamId + switch (event.type) { + case "message": + case "app_mention": { + if (event.type === "app_mention" && event.edited !== undefined) return [] + const channel = string(event, "channel") + if (channel === undefined) return [] + const normalized = message(event, { team, channel, botUserId: context.botUserId }) + if (normalized === undefined) return [] + return [{ + _tag: "MessageCreated", + thread: normalized.thread, + kind: kindOf(normalized.thread, channel, string(event, "channel_type")), + message: normalized, + raw + }] + } + case "reaction_added": + case "reaction_removed": { + const item = event.item + if (!isObject(item) || item.type !== "message") return [] + const channel = string(item, "channel") + const messageId = string(item, "ts") + const userId = string(event, "user") + const name = string(event, "reaction") + if (channel === undefined || messageId === undefined || userId === undefined || name === undefined) return [] + const messageAuthorId = string(event, "item_user") + const eventTs = string(event, "event_ts") + return [{ + _tag: event.type === "reaction_added" ? "ReactionAdded" : "ReactionRemoved", + thread: thread({ team, channel }), + messageId, + ...(messageAuthorId === undefined ? {} : { messageAuthorId }), + userId, + emoji: emoji(name), + ...(eventTs === undefined || !tsPattern.test(eventTs) ? {} : { timestamp: timestamp(eventTs) }), + raw + }] + } + case "agent_session_stopped": { + const channel = string(event, "channel") + const threadTs = string(event, "thread_ts") + const userId = string(event, "user") + const id = string(event, "event_ts") + if (channel === undefined || threadTs === undefined || userId === undefined || id === undefined) return [] + const streams = event.streaming_message_ts + return [{ + _tag: "StopRequested", + thread: thread({ team, channel, threadTs }), + id, + userId, + messageIds: Array.isArray(streams) + ? streams.filter((ts): ts is string => typeof ts === "string" && ts.length > 0) + : typeof streams === "string" && streams.length > 0 + ? [streams] + : [], + raw + }] + } + default: + return [] + } +} diff --git a/packages/chat/slack/src/internal/options.ts b/packages/chat/slack/src/internal/options.ts new file mode 100644 index 00000000000..76ccc9d26ae --- /dev/null +++ b/packages/chat/slack/src/internal/options.ts @@ -0,0 +1,22 @@ +import * as Context from "effect/Context" + +/** @internal */ +export type SessionStatus = "active" | "processing" | "suspended" | "closed" + +/** @internal */ +export interface PostOptions { + readonly notify?: { + readonly users?: ReadonlyArray | undefined + readonly groups?: ReadonlyArray | undefined + readonly broadcast?: boolean | undefined + } | undefined + readonly unfurl?: boolean | undefined + readonly nativeStream?: boolean | undefined + readonly recipientTeamId?: string | undefined + readonly sessionStatusAtEnd?: SessionStatus | undefined +} + +/** @internal */ +export const CurrentPostOptions = Context.Reference("@effect/chat-slack/CurrentPostOptions", { + defaultValue: () => ({}) +}) diff --git a/packages/chat/slack/src/internal/webhook.ts b/packages/chat/slack/src/internal/webhook.ts new file mode 100644 index 00000000000..a253a8e6a7f --- /dev/null +++ b/packages/chat/slack/src/internal/webhook.ts @@ -0,0 +1,157 @@ +import type { ChatError } from "effect/chat/ChatError" +import type * as ChatEvent from "effect/chat/ChatEvent" +import type { NotAccepted } from "effect/chat/ChatHandler" +import * as Clock from "effect/Clock" +import { WebCrypto } from "effect/crypto/WebCrypto" +import type * as Duration from "effect/Duration" +import * as Effect from "effect/Effect" +import type * as HttpServerRequest from "effect/http/HttpServerRequest" +import * as HttpServerResponse from "effect/http/HttpServerResponse" +import * as Option from "effect/Option" +import * as Redacted from "effect/Redacted" +import * as Stream from "effect/Stream" +import { normalize } from "./normalize.ts" + +/** How far a request's timestamp may be from now, as Slack recommends. */ +const maxSkewSeconds = 60 * 5 + +const encoder = new TextEncoder() + +const toHex = (bytes: Uint8Array): string => { + let out = "" + for (const byte of bytes) out += byte.toString(16).padStart(2, "0") + return out +} + +const timingSafeEqual = (a: string, b: string): boolean => { + if (a.length !== b.length) return false + let diff = 0 + for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i) + return diff === 0 +} + +/** + * Checks Slack's `v0` request signature: an HMAC-SHA256 of + * `v0:{timestamp}:{body}` with the signing secret, and a timestamp within + * five minutes of now. + * + * @internal + */ +export const makeVerifier = Effect.fnUntraced(function*(signingSecret: Redacted.Redacted) { + const crypto = yield* WebCrypto + const key = yield* Effect.promise(() => + crypto.subtle.importKey( + "raw", + encoder.encode(Redacted.value(signingSecret)), + { name: "HMAC", hash: "SHA-256" }, + false, + ["sign"] + ) + ) + return (headers: { readonly [key: string]: string | undefined }, body: Uint8Array): Effect.Effect => + Effect.gen(function*() { + const timestamp = headers["x-slack-request-timestamp"] + const signature = headers["x-slack-signature"] + if (timestamp === undefined || signature === undefined || !/^\d+$/.test(timestamp)) return false + const now = yield* Clock.currentTimeMillis + if (Math.abs(now / 1000 - Number(timestamp)) > maxSkewSeconds) return false + const prefix = encoder.encode(`v0:${timestamp}:`) + const message = new Uint8Array(prefix.length + body.length) + message.set(prefix) + message.set(body, prefix.length) + const mac = yield* Effect.promise(() => crypto.subtle.sign("HMAC", key, message)) + return timingSafeEqual(`v0=${toHex(new Uint8Array(mac))}`, signature) + }) +}) + +/** The body, or `None` once it passes `maxBytes`. @internal */ +export const readBody = ( + request: HttpServerRequest.HttpServerRequest, + maxBytes: number +): Effect.Effect> => { + const length = request.headers["content-length"] + if (length !== undefined && Number(length) > maxBytes) return Effect.succeed(Option.none()) + return Effect.gen(function*() { + const chunks: Array = [] + let total = 0 + const tooLarge = yield* request.stream.pipe( + Stream.takeUntil((chunk) => { + total += chunk.length + chunks.push(chunk) + return total > maxBytes + }), + Stream.runDrain, + Effect.as(false), + Effect.catch(() => Effect.succeed(true)) + ) + if (tooLarge || total > maxBytes) return Option.none() + const body = new Uint8Array(total) + let offset = 0 + for (const chunk of chunks) { + body.set(chunk, offset) + offset += chunk.length + } + return Option.some(body) + }) +} + +const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u) + +const ok = HttpServerResponse.empty({ status: 200 }) +const status = (code: number) => HttpServerResponse.empty({ status: code }) + +/** @internal */ +export interface Options { + readonly verify: (headers: { readonly [key: string]: string | undefined }, body: Uint8Array) => Effect.Effect + readonly appId: string + readonly teamId: string + readonly botUserId: Effect.Effect + readonly handle: (event: ChatEvent.ChatEvent) => Effect.Effect + readonly deadline: Duration.Duration + readonly maxBodyBytes: number +} + +/** + * One Events API request. + * + * - 413 past the body limit, 401 for a bad signature, 400 for a body that + * is not JSON. + * - `url_verification` is answered with its challenge. + * - An envelope for another app or workspace, or of another type, is + * answered 200 and dropped, so Slack does not retry it. + * - 503 when the bot user can't be read, the handler fails `NotAccepted`, + * or the handler runs past the deadline. Slack then retries. + * + * @internal + */ +export const handleRequest = ( + request: HttpServerRequest.HttpServerRequest, + options: Options +): Effect.Effect => + Effect.gen(function*() { + const body = yield* readBody(request, options.maxBodyBytes) + if (Option.isNone(body)) return status(413) + if (!(yield* options.verify(request.headers, body.value))) return status(401) + let envelope: unknown + try { + envelope = JSON.parse(new TextDecoder().decode(body.value)) + } catch { + return status(400) + } + if (!isObject(envelope)) return status(400) + if (envelope.type === "url_verification") { + return typeof envelope.challenge === "string" + ? HttpServerResponse.text(envelope.challenge) + : status(400) + } + if (envelope.type !== "event_callback" || envelope.api_app_id !== options.appId) return ok + const botUserId = yield* Effect.option(options.botUserId) + if (Option.isNone(botUserId)) return status(503) + const events = normalize(envelope, { teamId: options.teamId, botUserId: botUserId.value }) + const handled = yield* Effect.forEach(events, options.handle, { discard: true }).pipe( + Effect.timeoutOption(options.deadline), + Effect.map(Option.isSome), + Effect.catchTag("NotAccepted", () => Effect.succeed(false)) + ) + return handled ? ok : status(503) + }) diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts new file mode 100644 index 00000000000..db8ed5aa6e4 --- /dev/null +++ b/packages/chat/slack/test/SlackChat.test.ts @@ -0,0 +1,496 @@ +import * as SlackChat from "@effect/chat-slack/SlackChat" +import { SlackWebApi } from "@effect/chat-slack/SlackWebApi" +import { assert, describe, it } from "@effect/vitest" +import { checkMessage } from "effect/chat/ChatTest" +import * as Duration from "effect/Duration" +import * as Effect from "effect/Effect" +import * as Fiber from "effect/Fiber" +import * as Option from "effect/Option" +import * as Stream from "effect/Stream" +import * as TestClock from "effect/testing/TestClock" +import { adapter, authTest, botUserId, channel, checkOptions, fixture, makeFake, slackLayer, team } from "./utils.ts" + +const root = "1794509110.999799" +const channelThread = SlackChat.thread({ team, channel }) +const replyThread = SlackChat.thread({ team, channel, threadTs: root }) + +const run = ( + fake: ReturnType, + effect: Effect.Effect +) => effect.pipe(Effect.provide(slackLayer(fake))) as Effect.Effect + +const posted = (ts: string) => ({ ok: true, channel, ts }) + +const reason = (effect: Effect.Effect) => + Effect.flip(effect).pipe( + Effect.map((error) => ({ op: error.op, tag: error.reason._tag, detail: error.reason.detail, retry: error.retry })) + ) + +describe("post", () => { + it.effect("sends escaped markdown_text with unfurls off", () => { + const fake = makeFake({ "chat.postMessage": posted("1794509200.000100") }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const result = yield* slack.post(replyThread, { markdown: "hi <@U1> `<@U1>`" }) + assert.strictEqual(result.id, "1794509200.000100") + assert.deepStrictEqual(result.thread, replyThread) + assert.deepStrictEqual(fake.called("chat.postMessage")[0].params, { + channel, + thread_ts: root, + markdown_text: "hi <@U1> `<@U1>`", + unfurl_links: "false", + unfurl_media: "false" + }) + }) + ) + }) + + it.effect("withPostOptions allows a token and turns unfurls on", () => { + const fake = makeFake({ "chat.postMessage": posted("1794509200.000101") }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + yield* slack.post(channelThread, { markdown: "hi <@U1> <@U2>" }).pipe( + SlackChat.withPostOptions({ notify: { users: ["U1"] } }), + SlackChat.withPostOptions({ unfurl: true }) + ) + const params = fake.called("chat.postMessage")[0].params + assert.strictEqual(params.markdown_text, "hi <@U1> <@U2>") + assert.strictEqual(params.unfurl_links, "true") + assert.strictEqual(params.unfurl_media, "true") + assert.isUndefined(params.thread_ts) + }) + ) + }) + + it.effect("fails TooLarge before calling Slack", () => { + const fake = makeFake({}) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const cases = [ + "a".repeat(12_001), + // 3,001 `<` are 12,004 once escaped. + "<".repeat(3_001), + // 1,400 😀 are 1,400 code points but 14,000 with shortcodes. + "😀".repeat(1_400) + ] + for (const markdown of cases) { + const failure = yield* reason(slack.post(channelThread, { markdown })) + assert.strictEqual(failure.tag, "TooLarge") + } + assert.strictEqual(fake.calls.length, 0) + // 12,000 astral letters fit. + assert.strictEqual(slack.descriptor.measure("𝐀".repeat(12_000)), 12_000) + }) + ) + }) + + it.effect("edit skips the emoji limit", () => { + const fake = makeFake({ "chat.update": { ok: true } }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + yield* slack.edit(channelThread, "1794509200.000100", { markdown: "😀".repeat(1_400) }) + assert.strictEqual(fake.called("chat.update")[0].params.ts, "1794509200.000100") + assert.isUndefined(fake.called("chat.update")[0].params.unfurl_links) + }) + ) + }) + + it.effect("replyTo is unsupported", () => + run( + makeFake({}), + Effect.gen(function*() { + const slack = yield* adapter + const failure = yield* reason(slack.post(channelThread, { markdown: "x", replyTo: { messageId: "1.2" } })) + assert.strictEqual(failure.tag, "Unsupported") + assert.isFalse(slack.descriptor.capabilities.has("replyTo")) + }) + )) + + it.effect("files go up and are shared as one message", () => { + const fake = makeFake({ + "files.getUploadURLExternal": { ok: true, upload_url: "https://files.slack.test/upload/1", file_id: "F1" }, + "files.completeUploadExternal": { ok: true, files: [{ id: "F1" }] }, + "files.info": [ + { ok: true, file: { id: "F1", shares: {} } }, + { + ok: true, + file: { id: "F1", shares: { private: { [channel]: [{ ts: "1794509300.000100", thread_ts: root }] } } } + } + ] + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const result = yield* slack.post(replyThread, { + markdown: "**see** <@U1>", + files: [{ name: "a.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }] + }).pipe(Effect.forkChild) + yield* TestClock.adjust("1 second") + const value = yield* Fiber.join(result) + assert.strictEqual(value.id, "1794509300.000100") + const complete = fake.called("files.completeUploadExternal")[0].params + assert.strictEqual(complete.initial_comment, "*see* <@U1>") + assert.strictEqual(complete.thread_ts, root) + assert.deepStrictEqual(JSON.parse(complete.files), [{ id: "F1", title: "a.txt" }]) + assert.strictEqual(fake.called("/upload/1").length, 1) + }) + ) + }) +}) + +describe("errors", () => { + it.effect("maps Slack's codes", () => { + const fake = makeFake({ + "auth.test": authTest, + "chat.update": { ok: false, error: "invalid_auth" }, + "conversations.replies": { ok: false, error: "thread_not_found" }, + "chat.postMessage": { status: 500 }, + "conversations.info": { status: 429, headers: { "retry-after": "7" } }, + "users.info": { ok: false, error: "user_not_found" } + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + assert.deepStrictEqual(yield* reason(slack.edit(channelThread, "1.2", { markdown: "x" })), { + op: "edit", + tag: "Unauthenticated", + detail: "invalid_auth", + retry: "denied" + }) + assert.deepStrictEqual(yield* reason(slack.fetchMessage(channelThread, "1.2")), { + op: "fetchMessage", + tag: "NotFound", + detail: "thread_not_found", + retry: "denied" + }) + // A write that may have landed is never repeated. + assert.deepStrictEqual(yield* reason(slack.post(channelThread, { markdown: "x" })), { + op: "post", + tag: "PlatformUnavailable", + detail: "http_500", + retry: "uncertain" + }) + assert.strictEqual(fake.called("chat.postMessage").length, 1) + const api = yield* SlackWebApi + const limited = yield* Effect.flip(api.call("conversations.info", { channel }, { retry: false })) + assert.strictEqual(limited.reason._tag, "RateLimited") + assert.deepStrictEqual(limited.retryAfter, Duration.seconds(7)) + // A bot_message author is a bot id, which users.info does not know. + assert.strictEqual((yield* reason(slack.getUser("B0WEBHOOK"))).tag, "NotFound") + }) + ) + }) +}) + +describe("reads", () => { + const mentions = fixture("markdown-mentions") + const replies = mentions.calls.find((call) => call.method === "conversations.replies")!.response + + it.effect("fetchMessage normalises what Slack stored", () => { + const fake = makeFake({ "auth.test": authTest, "conversations.replies": replies }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const message = yield* slack.fetchMessage(channelThread, "1794509003.143939") + yield* checkMessage(message, checkOptions) + assert.deepStrictEqual(message.thread, channelThread) + assert.strictEqual(message.mentions.length, 2) + assert.deepStrictEqual(fake.called("conversations.replies")[0].params, { + channel, + ts: "1794509003.143939", + latest: "1794509003.143939", + oldest: "1794509003.143939", + inclusive: "true", + limit: "2" + }) + }) + ) + }) + + it.effect("opener is None for a channel, and for a root that is not a message", () => { + const fake = makeFake({ + "auth.test": authTest, + "conversations.replies": { + ok: true, + messages: [{ ts: root, thread_ts: root, subtype: "assistant_app_thread", user: botUserId, text: "New chat" }] + } + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + assert.isTrue(Option.isNone(yield* slack.opener(channelThread))) + assert.isTrue(Option.isNone(yield* slack.opener(replyThread))) + assert.strictEqual(fake.calls.filter((call) => call.method === "conversations.replies").length, 1) + }) + ) + }) + + it.effect("thread history in both directions, from exclusive", () => { + const message = (ts: string) => ({ ts, thread_ts: root, user: "U080YLYB277", text: ts }) + const fake = makeFake({ + "auth.test": authTest, + "conversations.replies": [ + { + ok: true, + messages: [message(root), message("1794509111.000001")], + response_metadata: { next_cursor: "page2" } + }, + { ok: true, messages: [message(root), message("1794509112.000001"), message("1794509113.000001")] } + ] + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const forward = yield* Stream.runCollect(slack.history(replyThread, { direction: "forward" })) + assert.deepStrictEqual(forward.map((m) => m.id), [ + root, + "1794509111.000001", + "1794509112.000001", + "1794509113.000001" + ]) + assert.deepStrictEqual(forward[0].thread, channelThread) + assert.deepStrictEqual(fake.called("conversations.replies")[1].params.cursor, "page2") + const backward = yield* Stream.runCollect( + slack.history(replyThread, { direction: "backward", from: "1794509113.000001" }) + ) + assert.deepStrictEqual(backward.map((m) => m.id), ["1794509112.000001", root]) + }) + ) + }) + + it.effect("getThread", () => { + const fake = makeFake({ + "conversations.info": { + ok: true, + channel: { id: channel, name: "chat-testing-123", created: 1794400000, topic: { value: "tests" } } + } + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const info = yield* slack.getThread(channelThread) + assert.strictEqual(info.kind, "channel") + assert.strictEqual(info.name, "chat-testing-123") + assert.strictEqual(info.topic, "tests") + const thread = yield* slack.getThread(replyThread) + assert.strictEqual(thread.kind, "thread") + assert.deepStrictEqual(thread.parent, channelThread) + assert.deepStrictEqual(yield* slack.startThread(channelThread, root), replyThread) + }) + ) + }) +}) + +describe("delete", () => { + it.effect("stops an open stream first", () => { + const fake = makeFake({ + "chat.delete": [{ ok: false, error: "cant_delete_message" }, { ok: true }], + "chat.stopStream": { ok: true } + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + yield* slack.delete(replyThread, "1794509111.134189") + assert.deepStrictEqual(fake.calls.map((call) => call.method), ["chat.delete", "chat.stopStream", "chat.delete"]) + }) + ) + }) +}) + +describe("nativeStream", () => { + const ts = "1794509111.134189" + + it.effect("start, append with a held tail, stop", () => { + const fake = makeFake({ + "chat.startStream": posted(ts), + "chat.appendStream": posted(ts), + "chat.stopStream": posted(ts) + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const native = slack.nativeStream! + const started = yield* native.start(replyThread, { markdown: "Hello ", recipient: "U080YLYB277" }) + assert.strictEqual(started.id, ts) + assert.deepStrictEqual(fake.called("chat.startStream")[0].params, { + channel, + thread_ts: root, + recipient_user_id: "U080YLYB277", + recipient_team_id: team, + markdown_text: "Hello " + }) + const notify = SlackChat.withPostOptions({ notify: { users: ["U1"] } }) + assert.deepStrictEqual(yield* native.append(replyThread, ts, "hi <@U", undefined).pipe(notify), { + state: "open", + held: 3 + }) + assert.deepStrictEqual(yield* native.append(replyThread, ts, "<@U1> a < b", { flush: true }).pipe(notify), { + state: "open", + held: 0 + }) + assert.deepStrictEqual( + fake.called("chat.appendStream").map((call) => call.params.markdown_text), + ["hi ", "<@U1> a < b"] + ) + assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: false }) + assert.isUndefined(fake.called("chat.stopStream")[0].params.session_status) + assert.strictEqual(fake.called("agents.sessions.setStatus").length, 0) + }) + ) + }) + + it.effect("is unsupported off a thread, without a recipient, or when turned off", () => + run( + makeFake({}), + Effect.gen(function*() { + const native = (yield* adapter).nativeStream! + const cases = [ + native.start(channelThread, { markdown: "x", recipient: "U1" }), + native.start(replyThread, { markdown: "x" }), + native.start(replyThread, { markdown: "x", recipient: "U1" }).pipe( + SlackChat.withPostOptions({ nativeStream: false }) + ) + ] + for (const start of cases) assert.strictEqual((yield* reason(start)).tag, "Unsupported") + }) + )) + + it.effect("closed, too large and stopped", () => { + const fake = makeFake({ + "chat.startStream": posted(ts), + "chat.appendStream": [ + { ok: false, error: "message_not_in_streaming_state" }, + { ok: false, error: "stopped_by_user" } + ], + "chat.stopStream": { ok: true, channel, ts, message: { ts, ai_context: { result_status: "stopped_by_user" } } }, + "agents.sessions.setStatus": { ok: true } + }) + return run( + fake, + Effect.gen(function*() { + const native = (yield* adapter).nativeStream! + yield* native.start(replyThread, { markdown: "a".repeat(11_990), recipient: "U1" }) + assert.strictEqual( + (yield* reason(native.append(replyThread, ts, "b".repeat(11), { flush: true }))).tag, + "TooLarge" + ) + assert.strictEqual(fake.called("chat.appendStream").length, 0) + assert.deepStrictEqual(yield* native.append(replyThread, ts, "c", { flush: true }), { + state: "closed", + held: 0 + }) + assert.deepStrictEqual(yield* native.append(replyThread, ts, "d", { flush: true }), { + state: "stopped", + held: 0 + }) + const result = yield* native.stop(replyThread, ts, { end: "done" }).pipe( + SlackChat.withPostOptions({ sessionStatusAtEnd: "suspended" }) + ) + assert.deepStrictEqual(result, { stopped: true }) + assert.strictEqual(fake.called("chat.stopStream")[0].params.session_status, "suspended") + assert.deepStrictEqual(fake.called("agents.sessions.setStatus")[0].params, { + channel_id: channel, + thread_ts: root, + status: "suspended" + }) + }) + ) + }) + + it.effect("rotates with processing, and stops asking once Slack says not_authorized", () => { + const fake = makeFake({ + "chat.stopStream": (params) => + params.session_status !== undefined + ? { ok: false, error: "not_authorized" } + : { ok: true, message: { ts, ai_context: { result_status: "stopped_by_user" } } }, + "agents.sessions.setStatus": { ok: false, error: "not_authorized" } + }) + return run( + fake, + Effect.gen(function*() { + const native = (yield* adapter).nativeStream! + assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "rotating" }), { stopped: true }) + assert.deepStrictEqual( + fake.called("chat.stopStream").map((call) => call.params.session_status), + ["processing", undefined] + ) + // Not a declared agent: no more session status, and a reply never fails over it. + assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: true }) + assert.strictEqual(fake.called("chat.stopStream").length, 3) + assert.isUndefined(fake.called("chat.stopStream")[2].params.session_status) + assert.strictEqual(fake.called("agents.sessions.setStatus").length, 0) + }) + ) + }) + + it.effect("stop on a closed stream succeeds", () => { + const fake = makeFake({ "chat.stopStream": { ok: false, error: "message_not_in_streaming_state" } }) + return run( + fake, + Effect.gen(function*() { + const native = (yield* adapter).nativeStream! + assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: false }) + }) + ) + }) +}) + +describe("SlackChat", () => { + it.effect("botUserId and user", () => { + const fake = makeFake({ + "auth.test": authTest, + "users.info": { + ok: true, + user: { + id: "U0EXT", + team_id: "T0OTHER", + name: "ext", + is_restricted: true, + is_stranger: true, + profile: { display_name: "Ext" } + } + } + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* SlackChat.SlackChat + assert.strictEqual(yield* slack.botUserId, botUserId) + assert.strictEqual(yield* slack.botUserId, botUserId) + assert.strictEqual(fake.called("auth.test").length, 1) + const user = yield* slack.user("U0EXT") + assert.include(user, { id: "U0EXT", teamId: "T0OTHER", name: "Ext", isRestricted: true, isStranger: true }) + }) + ) + }) + + it("emoji in both directions", () => { + assert.deepStrictEqual(SlackChat.emojiFromName(":+1::skin-tone-3:"), Option.some("👍🏼")) + assert.deepStrictEqual(SlackChat.emojiToName("👍"), Option.some("+1")) + assert.deepStrictEqual(SlackChat.emojiToName("❤"), Option.some("heart")) + assert.isTrue(Option.isNone(SlackChat.emojiFromName("party-parrot"))) + }) + + it("thread and parts", () => { + assert.deepStrictEqual(SlackChat.parts(replyThread), Option.some({ team, channel, threadTs: root })) + assert.deepStrictEqual(SlackChat.parts(channelThread), Option.some({ team, channel })) + assert.isTrue(Option.isNone(SlackChat.parts({ platform: "discord", id: "1/2" }))) + assert.isTrue(Option.isNone(SlackChat.parts({ platform: "slack", id: "T1" }))) + }) +}) diff --git a/packages/chat/slack/test/emoji.test.ts b/packages/chat/slack/test/emoji.test.ts new file mode 100644 index 00000000000..2d990a491be --- /dev/null +++ b/packages/chat/slack/test/emoji.test.ts @@ -0,0 +1,215 @@ +import { blocksCost, fromName, toName } from "@effect/chat-slack/internal/emoji" +import { emojiData } from "@effect/chat-slack/internal/emojiData" +import { assert, describe, it } from "@effect/vitest" + +interface Row { + readonly names: ReadonlyArray + /** Primary Slack name, with skin-tone suffixes for variations */ + readonly name: string + /** Whether the emoji is also written without U+FE0F */ + readonly nonQualified: boolean +} + +// Read the generated table directly, so these tests do not trust emoji.ts to parse it. +const rows: ReadonlyArray = emojiData.split("\n").flatMap((line) => { + const [names, , nonQualified, groups] = line.split("|") + const aliases = names.split(",") + const base: Row = { names: aliases, name: aliases[0], nonQualified: nonQualified === "!" } + const variations = groups === undefined ? [] : groups.split(";").flatMap((group) => { + const [keys, , variationNonQualified] = group.split(":") + return keys.split(",").map((tones): Row => ({ + names: [], + name: aliases[0] + [...tones].map((tone) => "::skin-tone-" + tone).join(""), + nonQualified: variationNonQualified === "!" + })) + }) + return [base, ...variations] +}) + +// Every emoji string the table defines, with its primary Slack name. +const sequences: ReadonlyArray = rows.flatMap((row) => { + const emoji = fromName(row.name)! + return row.nonQualified ? [[emoji, row.name], [emoji.replaceAll("\uFE0F", ""), row.name]] : [[emoji, row.name]] +}) + +describe("emoji", () => { + it("holds every emoji, name and skin tone variation from emoji-data v16.0.0", () => { + assert.strictEqual(emojiData.split("\n").length, 1911) + assert.strictEqual(rows.reduce((total, row) => total + row.names.length, 0), 1972) + assert.strictEqual(rows.filter((row) => row.names.length === 0).length, 1875) + assert.strictEqual(sequences.length, 4946) + assert.strictEqual(new Set(sequences.map(([emoji]) => emoji)).size, sequences.length) + }) + + describe("fromName", () => { + it("resolves every alias", () => { + assert.strictEqual(fromName("+1"), "👍") + assert.strictEqual(fromName("thumbsup"), "👍") + }) + + it("accepts surrounding colons", () => { + assert.strictEqual(fromName(":+1:"), "👍") + assert.strictEqual(fromName(":+1::skin-tone-3:"), "👍🏼") + }) + + it("returns the fully qualified emoji", () => { + assert.strictEqual(fromName("heart"), "❤️") + }) + + it("looks skin tones up in skin_variations", () => { + assert.strictEqual(fromName("+1::skin-tone-3"), "👍🏼") + assert.strictEqual(fromName("woman-running::skin-tone-6"), "🏃🏿‍♀️") + }) + + it("resolves two tones on multi person emoji", () => { + assert.strictEqual(fromName("people_holding_hands::skin-tone-2::skin-tone-5"), "🧑🏻‍🤝‍🧑🏾") + assert.strictEqual(fromName("handshake::skin-tone-2::skin-tone-5"), "🫱🏻‍🫲🏾") + }) + + it("treats one tone and two equal tones alike", () => { + assert.strictEqual(fromName("handshake::skin-tone-3"), "🤝🏼") + assert.strictEqual(fromName("handshake::skin-tone-3::skin-tone-3"), "🤝🏼") + assert.strictEqual(fromName("people_holding_hands::skin-tone-4"), "🧑🏽‍🤝‍🧑🏽") + assert.strictEqual(fromName("people_holding_hands::skin-tone-4::skin-tone-4"), "🧑🏽‍🤝‍🧑🏽") + }) + + it("resolves every alias and variation in the table", () => { + for (const row of rows) { + const emoji = fromName(row.name) + assert.isDefined(emoji, row.name) + for (const alias of row.names) assert.strictEqual(fromName(alias), emoji, alias) + } + }) + + it("returns undefined for unknown names and tones", () => { + assert.strictEqual(fromName("not_an_emoji"), undefined) + assert.strictEqual(fromName(""), undefined) + assert.strictEqual(fromName("::"), undefined) + assert.strictEqual(fromName(":+1"), undefined) + assert.strictEqual(fromName("grinning::skin-tone-3"), undefined) + assert.strictEqual(fromName("+1::skin-tone-1"), undefined) + assert.strictEqual(fromName("+1::skin-tone-7"), undefined) + assert.strictEqual(fromName("+1::skin-tone-2::skin-tone-3"), undefined) + assert.strictEqual(fromName("handshake::skin-tone-2::skin-tone-3::skin-tone-4"), undefined) + assert.strictEqual(fromName("+1::thumbsup"), undefined) + }) + }) + + describe("toName", () => { + it("returns the primary short name", () => { + assert.strictEqual(toName("👍"), "+1") + assert.strictEqual(toName("😀"), "grinning") + assert.strictEqual(toName("🧑‍🤝‍🧑"), "people_holding_hands") + }) + + it("matches emoji with and without U+FE0F", () => { + assert.strictEqual(toName("❤\uFE0F"), "heart") + assert.strictEqual(toName("❤"), "heart") + }) + + it("names toned emoji with skin-tone suffixes", () => { + assert.strictEqual(toName("👍🏼"), "+1::skin-tone-3") + assert.strictEqual(toName("🏃🏿‍♀️"), "woman-running::skin-tone-6") + assert.strictEqual(toName("🏃🏿‍♀"), "woman-running::skin-tone-6") + assert.strictEqual(toName("🧑🏻‍🤝‍🧑🏾"), "people_holding_hands::skin-tone-2::skin-tone-5") + assert.strictEqual(toName("🫱🏻‍🫲🏾"), "handshake::skin-tone-2::skin-tone-5") + }) + + it("returns undefined for anything that is not exactly one emoji", () => { + assert.strictEqual(toName(""), undefined) + assert.strictEqual(toName("a"), undefined) + assert.strictEqual(toName("👍👍"), undefined) + assert.strictEqual(toName("👍 "), undefined) + }) + + it("round trips with fromName for every emoji in the table", () => { + for (const [emoji, name] of sequences) { + assert.strictEqual(toName(emoji), name) + } + }) + }) + + describe("blocksCost", () => { + it("counts code points of plain text", () => { + assert.strictEqual(blocksCost(""), 0) + assert.strictEqual(blocksCost("abc"), 3) + assert.strictEqual(blocksCost("é日本"), 3) + assert.strictEqual(blocksCost("𝒜"), 1) + }) + + it("counts emoji as their :short_name: form", () => { + assert.strictEqual(blocksCost("😀"), 10) + assert.strictEqual(blocksCost("a😀"), 11) + assert.strictEqual(blocksCost("👍"), 4) + assert.strictEqual(blocksCost("👍🏽"), 17) + assert.strictEqual(blocksCost("🧑‍🤝‍🧑"), 22) + assert.strictEqual(blocksCost("❤"), 7) + assert.strictEqual(blocksCost("❤️"), 7) + assert.strictEqual(blocksCost("🇺🇸"), 4) + assert.strictEqual(blocksCost("#️⃣"), 6) + assert.strictEqual(blocksCost("hi 👍🏽!"), 3 + 17 + 1) + }) + + it("costs every emoji in the table exactly as its :short_name:", () => { + for (const [emoji, name] of sequences) { + assert.strictEqual(blocksCost(emoji), name.length + 2, name) + } + }) + + it("charges stray emoji components enough to stay subadditive", () => { + assert.strictEqual(blocksCost("1"), 1) + assert.strictEqual(blocksCost("1\u20E3"), 5) + assert.isAtLeast(blocksCost("1") + blocksCost("\u20E3"), 5) + assert.isAtLeast(blocksCost("🇺") + blocksCost("🇸"), blocksCost("🇺🇸")) + assert.isAtLeast(blocksCost("🏃") + blocksCost("\u200D➡️"), blocksCost("🏃‍➡️")) + assert.isAtLeast(blocksCost("\uD83D") + blocksCost("\uDE00"), blocksCost("😀")) + }) + + it("is subadditive", () => { + const emoji = sequences.map(([sequence]) => sequence) + const extras = [ + "a", + " ", + "1", + "#", + "\u200D", + "\uFE0F", + "\u20E3", + "🏽", + "🇺", + "🇸", + "🦰", + "\u{E0067}", + "\uD83D", + "\uDE00" + ] + let seed = 1 + const random = (n: number) => { + seed = (seed * 1103515245 + 12345) & 0x7fffffff + return seed % n + } + const piece = () => { + const kind = random(3) + if (kind === 0) return extras[random(extras.length)] + const sequence = emoji[random(emoji.length)] + if (kind === 1) return sequence + const from = random(sequence.length + 1) + const to = random(sequence.length + 1) + return sequence.slice(Math.min(from, to), Math.max(from, to)) + } + for (let i = 0; i < 20_000; i++) { + let text = "" + for (let j = 1 + random(8); j > 0; j--) text += piece() + const cut = random(text.length + 1) + const a = text.slice(0, cut) + const b = text.slice(cut) + assert.isAtMost(blocksCost(text), blocksCost(a) + blocksCost(b), JSON.stringify([a, b])) + } + }) + + it("measures long text", () => { + const text = "hello 👍🏽 world 🧑‍🤝‍🧑 #️⃣ 🇺🇸 ".repeat(2_000) + assert.strictEqual(blocksCost(text), 2_000 * (6 + 17 + 7 + 22 + 1 + 6 + 1 + 4 + 1)) + }) + }) +}) diff --git a/packages/chat/slack/test/escape.test.ts b/packages/chat/slack/test/escape.test.ts new file mode 100644 index 00000000000..8e03735176d --- /dev/null +++ b/packages/chat/slack/test/escape.test.ts @@ -0,0 +1,81 @@ +import { escape, toMrkdwn } from "@effect/chat-slack/internal/escape" +import { codePoints, measure } from "@effect/chat-slack/internal/length" +import { assert, describe, it } from "@effect/vitest" + +const sent = (text: string, notify = {}) => escape(text, notify, { flush: true }).sent + +describe("escape", () => { + it("escapes < outside code only", () => { + assert.strictEqual(sent("a <@U1> b"), "a <@U1> b") + assert.strictEqual(sent("`<@U1>` and ``x y``"), "`<@U1>` and ``x y``") + assert.strictEqual(sent("```\n<@U1>\n```\n<@U1>"), "```\n<@U1>\n```\n<@U1>") + assert.strictEqual(sent("~~~ts\nif (a < b) {}\n~~~"), "~~~ts\nif (a < b) {}\n~~~") + assert.strictEqual(sent("a `b < c"), "a `b < c") + assert.strictEqual(sent("\\<@U1>"), "\\<@U1>") + }) + + it("keeps the tokens the notify options allow", () => { + const notify = { users: ["U1"], groups: ["S1"], broadcast: true } + assert.strictEqual( + sent("<@U1> <@U2> ", notify), + "<@U1> <@U2> <!subteam^S2> " + ) + assert.strictEqual(sent("<@U1|name>", { users: ["U1"] }), "<@U1|name>") + assert.strictEqual(sent("", {}), "<!channel>") + }) + + it("holds a < the next chunk could still change", () => { + const notify = { users: ["U1"] } + const first = escape("hi <@U", notify) + assert.strictEqual(first.sent, "hi ") + assert.strictEqual(first.consumed, 3) + const second = escape("<@U1> there", notify, { state: first.state }) + assert.strictEqual(second.sent, "<@U1> there") + // With nothing allowed, a < is never undecided. + assert.strictEqual(escape("hi <@U", {}).sent, "hi <@U") + // After a backtick the line has not closed. + const code = escape("x `a <", {}) + assert.strictEqual(code.sent, "x `a ") + assert.strictEqual(escape(" { + const first = escape("```\na < b\n", {}) + assert.strictEqual(first.sent, "```\na < b\n") + const second = escape("c < d\n```\ne < f", {}, { state: first.state, flush: true }) + assert.strictEqual(second.sent, "c < d\n```\ne < f") + }) + + it("releases a held < past the bound", () => { + const text = "`a <" + "x".repeat(400) + const result = escape(text, {}) + assert.strictEqual(result.consumed, text.length) + assert.strictEqual(result.sent, "`a <" + "x".repeat(400)) + }) +}) + +describe("toMrkdwn", () => { + it("converts Markdown and escapes outside code", () => { + assert.strictEqual( + toMrkdwn("# Title\n**bold** ~~gone~~ [docs](https://effect.website) a < b & c <@U1>\n> quote\n``", {}), + "*Title*\n*bold* ~gone~ a < b & c <@U1>\n> quote\n`<x>`" + ) + assert.strictEqual(toMrkdwn("hi <@U1>", { users: ["U1"] }), "hi <@U1>") + }) +}) + +describe("measure", () => { + it("bounds what is sent and adds up", () => { + const samples = ["plain", "a < b", "<<<", "😀😀", "`<@U1>` ", "👍🏽 and 1\u20E3", "\ud83d", "🇺🇸"] + for (const a of samples) { + assert.isAtLeast(measure(a), codePoints(sent(a))) + for (const b of samples) assert.isAtMost(measure(a + b), measure(a) + measure(b)) + } + assert.strictEqual(measure("abc"), 3) + assert.strictEqual(measure("<"), 4) + // 1,200 😀 cost 12,000 against 13,200, scaled to 12,000 and rounded up. + assert.strictEqual(measure("😀".repeat(1200)), 10_910) + }) +}) diff --git a/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json b/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json new file mode 100644 index 00000000000..db6bcb0731d --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json @@ -0,0 +1,80 @@ +{ + "source": "EFF-3676 live runs G1 to G3, as janitor received them. G2 and G3 envelopes are as in G1, which was logged in full; their event objects are verbatim.", + "cases": { + "channelThread": { + "type": "event_callback", + "team_id": "T05479Z6JBW", + "api_app_id": "A0CCHBHDK7X", + "event_id": "Ev0CH0C5627L", + "event_time": 1794454026, + "is_ext_shared_channel": false, + "authorizations": [ + { + "team_id": "T05479Z6JBW", + "user_id": "U0CCLMD4S1L", + "is_bot": true, + "is_enterprise_install": false + } + ], + "event": { + "type": "agent_session_stopped", + "channel": "C0CH1LGJ4F3", + "user": "U080YLYB277", + "thread_ts": "1794454017.568519", + "event_ts": "1794454026.522466", + "streaming_message_ts": [ + "1794454017.726189" + ] + } + }, + "noStream": { + "type": "event_callback", + "team_id": "T05479Z6JBW", + "api_app_id": "A0CCHBHDK7X", + "event_id": "Ev0CGV9VQVEH", + "event_time": 1794454026, + "is_ext_shared_channel": false, + "authorizations": [ + { + "team_id": "T05479Z6JBW", + "user_id": "U0CCLMD4S1L", + "is_bot": true, + "is_enterprise_install": false + } + ], + "event": { + "type": "agent_session_stopped", + "channel": "C0CH1LGJ4F3", + "user": "U080YLYB277", + "thread_ts": "1794454354.780449", + "event_ts": "1794454367.470649" + } + }, + "direct": { + "type": "event_callback", + "team_id": "T05479Z6JBW", + "api_app_id": "A0CCHBHDK7X", + "event_id": "Ev0CGUC5LUKD", + "event_time": 1794454026, + "is_ext_shared_channel": false, + "authorizations": [ + { + "team_id": "T05479Z6JBW", + "user_id": "U0CCLMD4S1L", + "is_bot": true, + "is_enterprise_install": false + } + ], + "event": { + "type": "agent_session_stopped", + "channel": "D0CCGDG0E75", + "user": "U080YLYB277", + "thread_ts": "1794454526.171439", + "event_ts": "1794454532.803025", + "streaming_message_ts": [ + "1794454526.283939" + ] + } + } + } +} diff --git a/packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json b/packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json new file mode 100644 index 00000000000..1c3320ef4e2 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json @@ -0,0 +1,220 @@ +{ + "case": "read-only: the agent-view (assistant) thread root in the app DM", + "recordedAt": "2026-11-12T18:43:52.781Z", + "calls": [ + { + "method": "conversations.replies", + "encoding": "form", + "request": { + "channel": "D0CCGDG0E75", + "ts": "1794454526.171439", + "limit": 5 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794454526.171439", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794454526.171439", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794454526.283939", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "1af", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it." + } + ] + } + ] + } + ], + "agent_session": { + "status": "active", + "agent_bot_user_ids": [ + "U0CCLMD4S1L" + ], + "encoded_initiator_user_id": "U080YLYB277", + "agent_statuses": [ + { + "agent_bot_user_id": "U0CCLMD4S1L", + "status": "active", + "is_stoppable": true + } + ] + } + }, + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794454526.283939", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "G3 stream started. tick 2 after-click", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794454526.171439", + "parent_user_id": "U0CCLMD4S1L", + "blocks": [ + { + "type": "rich_text", + "block_id": "qmE9gL", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "G3 stream started. tick 2 after-click" + } + ] + } + ] + } + ], + "ai_context": { + "type": "default", + "result_status": "stopped_by_user", + "stopped_by_user_id": "U080YLYB277" + }, + "streaming_state": "completed" + } + ], + "has_more": false + } + }, + { + "method": "conversations.history", + "encoding": "form", + "request": { + "channel": "D0CCGDG0E75", + "latest": "1794454526.171439", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794454526.171439", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794454526.171439", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794454526.171439", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794454526.283939", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "CgoC", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it." + } + ] + } + ] + } + ], + "agent_session": { + "status": "active", + "agent_bot_user_ids": [ + "U0CCLMD4S1L" + ], + "encoded_initiator_user_id": "U080YLYB277", + "agent_statuses": [ + { + "agent_bot_user_id": "U0CCLMD4S1L", + "status": "active", + "is_stoppable": true + } + ] + } + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NDQ4Njg1MjkxNzk5" + } + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/conversations-info.json b/packages/chat/slack/test/fixtures/recorded/conversations-info.json new file mode 100644 index 00000000000..14c37396876 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/conversations-info.json @@ -0,0 +1,150 @@ +{ + "case": "conversations.info for the private test channel and the app DM", + "recordedAt": "2026-11-12T18:43:05.527Z", + "calls": [ + { + "method": "conversations.info", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": { + "id": "C0CH1LGJ4F3", + "created": 1794446158, + "creator": "U080YLYB277", + "is_org_shared": false, + "is_im": false, + "context_team_id": "T05479Z6JBW", + "updated": 1794446158426, + "name": "chat-testing-123", + "name_normalized": "chat-testing-123", + "is_channel": true, + "is_group": false, + "is_mpim": false, + "is_private": true, + "is_archived": false, + "is_general": false, + "is_shared": false, + "is_ext_shared": false, + "unlinked": 0, + "is_pending_ext_shared": false, + "pending_shared": [], + "parent_conversation": null, + "purpose": { + "value": "", + "creator": "", + "last_set": 0 + }, + "topic": { + "value": "", + "creator": "", + "last_set": 0 + }, + "shared_team_ids": [ + "T05479Z6JBW" + ], + "pending_connected_team_ids": [], + "is_member": true, + "is_open": true, + "last_read": "1794446158.561359", + "properties": {} + } + } + }, + { + "method": "conversations.info", + "encoding": "json", + "note": "same call with a JSON body", + "request": { + "channel": "C0CH1LGJ4F3" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "invalid_arguments", + "response_metadata": { + "messages": [ + "[ERROR] missing required field: channel" + ] + } + } + }, + { + "method": "conversations.info", + "encoding": "form", + "request": { + "channel": "D0CCGDG0E75" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": { + "id": "D0CCGDG0E75", + "created": 1793134568, + "is_org_shared": false, + "is_im": true, + "is_archived": false, + "context_team_id": "T05479Z6JBW", + "updated": 1793134568873, + "user": "U080YLYB277", + "last_read": "0000000000.000000", + "is_open": true, + "priority": 0, + "unread_count": 8, + "unread_count_display": 2, + "latest": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794454526.283939", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "G3 stream started. tick 2 after-click", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794454526.171439", + "parent_user_id": "U0CCLMD4S1L", + "blocks": [ + { + "type": "rich_text", + "block_id": "qmE9gL", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "G3 stream started. tick 2 after-click" + } + ] + } + ] + } + ], + "ai_context": { + "type": "default", + "result_status": "stopped_by_user", + "stopped_by_user_id": "U080YLYB277" + }, + "streaming_state": "completed" + } + } + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/errors.json b/packages/chat/slack/test/fixtures/recorded/errors.json new file mode 100644 index 00000000000..fd792afddd9 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/errors.json @@ -0,0 +1,347 @@ +{ + "case": "error bodies and HTTP statuses for common failure modes", + "recordedAt": "2026-11-12T18:44:56.644Z", + "calls": [ + { + "method": "chat.update", + "encoding": "json", + "note": "nonexistent ts", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1700000000.000100", + "markdown_text": "nope" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "message_not_found" + } + }, + { + "method": "chat.delete", + "encoding": "json", + "note": "nonexistent ts", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1700000000.000100" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "message_not_found" + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "note": "nonexistent channel", + "request": { + "channel": "C00000000", + "ts": "1700000000.000100" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "channel_not_found" + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "note": "existing channel, nonexistent thread ts", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1700000000.000100" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "thread_not_found" + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "latest/inclusive for a nonexistent ts (before channel creation)", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1700000000.000100", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1700000000.000100", + "messages": [], + "has_more": false, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0 + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "latest/inclusive for a nonexistent ts 1 microsecond after a real message: returns the previous message", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509000.352790", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509000.352790", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509000.352789", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: thread root (no mentions). Some _markdown_ here.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509000.352789", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509001.485739", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "TOu1os", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: thread root (no mentions). Some " + }, + { + "type": "text", + "text": "markdown", + "style": { + "italic": true + } + }, + { + "type": "text", + "text": " here." + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NDc5NTAzODIwNzA5" + } + } + }, + { + "method": "conversations.history", + "encoding": "json", + "note": "JSON body for conversations.history", + "request": { + "channel": "C0CH1LGJ4F3", + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509073.518429", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: reactions target", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "C7NS1J", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: reactions target" + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MDQ5MjQ1NjA5" + } + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "subteam token in markdown_text", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture: subteam " + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "invalid_blocks", + "errors": [ + "usergroup [S00000000] could not be found [json-pointer:/blocks/0/elements/0/elements/1/usergroup_id]" + ], + "response_metadata": { + "messages": [ + "[ERROR] usergroup [S00000000] could not be found [json-pointer:/blocks/0/elements/0/elements/1/usergroup_id]" + ] + } + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "markdown_text of 12,001 chars", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "msg_too_long" + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "markdown_text together with text", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture: markdown_text with text", + "text": "fallback" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "markdown_text_conflict" + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "nonexistent channel", + "request": { + "channel": "C00000000", + "markdown_text": "x" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "channel_not_found" + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "public channel the bot is not a member of (bot has no chat:write.public)", + "request": { + "channel": "C05479Z8Z0U", + "markdown_text": "Fixture: should be rejected" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "not_in_channel" + } + }, + { + "method": "auth.test", + "encoding": "json", + "note": "invalid token", + "request": {}, + "httpStatus": 200, + "tokenUsed": "invalid bot token string", + "response": { + "ok": false, + "error": "invalid_auth" + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "invalid token", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "x" + }, + "httpStatus": 200, + "tokenUsed": "invalid bot token string", + "response": { + "ok": false, + "error": "invalid_auth" + } + }, + { + "method": "auth.test", + "note": "no Authorization header", + "request": {}, + "httpStatus": 200, + "response": { + "ok": false, + "error": "not_authed" + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/file-share.json b/packages/chat/slack/test/fixtures/recorded/file-share.json new file mode 100644 index 00000000000..fc6e3bdc858 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/file-share.json @@ -0,0 +1,351 @@ +{ + "case": "upload a small text file into a channel thread with an initial_comment mentioning the bot; read back", + "recordedAt": "2026-11-12T18:43:52.706Z", + "calls": [ + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture: file share thread root" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509028.346289", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509028.346289", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: file share thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "kS27k6", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: file share thread root" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "files.getUploadURLExternal", + "encoding": "form", + "note": "files.getUploadURLExternal requires form encoding", + "request": { + "filename": "fixture.txt", + "length": 51 + }, + "httpStatus": 200, + "response": { + "ok": true, + "upload_url": "https://scrubbed.invalid/upload_url", + "file_id": "F0CH6RHTMRU" + } + }, + { + "method": "", + "request": { + "body": "<51 bytes text/plain>" + }, + "httpStatus": 200, + "response": { + "text": "OK - 51" + } + }, + { + "method": "files.completeUploadExternal", + "encoding": "json", + "request": { + "files": [ + { + "id": "F0CH6RHTMRU", + "title": "fixture.txt" + } + ], + "channel_id": "C0CH1LGJ4F3", + "thread_ts": "1794509028.346289", + "initial_comment": "Fixture: file for <@U0CCLMD4S1L>" + }, + "httpStatus": 200, + "response": { + "ok": true, + "files": [ + { + "id": "F0CH6RHTMRU", + "created": 1794509028, + "timestamp": 1794509028, + "mimetype": "", + "filetype": "", + "pretty_type": "", + "user": "U0CCLMD4S1L", + "user_team": "T05479Z6JBW", + "editable": false, + "size": 51, + "mode": "hosted", + "is_external": false, + "external_type": "", + "is_public": false, + "public_url_shared": false, + "display_as_bot": false, + "username": "", + "name": "fixture.txt", + "title": "fixture.txt", + "is_modified_by_ai": false, + "url_private": "https://scrubbed.invalid/url_private", + "url_private_download": "https://scrubbed.invalid/url_private_download", + "media_display_type": "unknown", + "permalink": "https://scrubbed.invalid/permalink", + "permalink_public": "https://scrubbed.invalid/permalink_public", + "comments_count": 0, + "is_starred": false, + "shares": {}, + "channels": [], + "groups": [], + "ims": [], + "has_more_shares": false, + "has_rich_preview": false, + "file_access": "visible" + } + ] + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509028.346289", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509028.346289", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: file share thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509028.346289", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509028.831169", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "kS27k6", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: file share thread root" + } + ] + } + ] + } + ] + }, + { + "text": "Fixture: file for <@U0CCLMD4S1L>", + "files": [ + { + "id": "F0CH6RHTMRU", + "created": 1794509028, + "timestamp": 1794509028, + "mimetype": "text/plain", + "filetype": "text", + "pretty_type": "Plain Text", + "user": "U0CCLMD4S1L", + "user_team": "T05479Z6JBW", + "editable": true, + "size": 51, + "mode": "snippet", + "is_external": false, + "external_type": "", + "is_public": false, + "public_url_shared": false, + "display_as_bot": false, + "username": "", + "name": "fixture.txt", + "title": "fixture.txt", + "is_modified_by_ai": false, + "url_private": "https://scrubbed.invalid/url_private", + "url_private_download": "https://scrubbed.invalid/url_private_download", + "permalink": "https://scrubbed.invalid/permalink", + "permalink_public": "https://scrubbed.invalid/permalink_public", + "edit_link": "https://scrubbed.invalid/edit_link", + "preview": "hello from the @effect/chat-slack fixture recorder\n", + "preview_highlight": "
\n
\n
hello from the @effect/chat-slack fixture recorder
\n
\n
\n
\n", + "lines": 2, + "lines_more": 0, + "preview_is_truncated": false, + "is_starred": false, + "skipped_shares": true, + "has_rich_preview": false, + "file_access": "visible" + } + ], + "upload": true, + "user": "U0CCLMD4S1L", + "display_as_bot": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "mP=", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: file for " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + } + ] + } + ] + } + ], + "type": "message", + "ts": "1794509028.831169", + "bot_id": "B0CCQH77VA5", + "thread_ts": "1794509028.346289", + "parent_user_id": "U0CCLMD4S1L" + } + ], + "has_more": false + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "thread replies are not in history (expected empty/other message)", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509028.831169", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509028.831169", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509028.346289", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: file share thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509028.346289", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509028.831169", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "kS27k6", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: file share thread root" + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MDA4MDc5NjA5" + } + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/markdown-mentions.json b/packages/chat/slack/test/fixtures/recorded/markdown-mentions.json new file mode 100644 index 00000000000..75d06d08952 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/markdown-mentions.json @@ -0,0 +1,425 @@ +{ + "case": "markdown_text with bot mention, channel token, tokens inside inline code and fenced code, <, bold, link; read back", + "recordedAt": "2026-11-12T18:43:24.731Z", + "calls": [ + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture mentions: hi <@U0CCLMD4S1L> in <#C0CH1LGJ4F3>.\nInline code: `<@U0CCLMD4S1L> <#C0CH1LGJ4F3>`\n```\nfenced <@U0CCLMD4S1L> <#C0CH1LGJ4F3>\n```\nEscaped: <not a tag> and a raw < sign, **bold** and [x](https://effect.website)", + "unfurl_links": false, + "unfurl_media": false + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509003.143939", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509003.143939", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture mentions: hi <@U0CCLMD4S1L> in <#C0CH1LGJ4F3>.\nInline code: `<@U0CCLMD4S1L> <#C0CH1LGJ4F3>`\n```fenced <@U0CCLMD4S1L> <#C0CH1LGJ4F3>```\nEscaped: <not a tag> and a raw < sign, *bold* and ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "UfdV4+", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture mentions: hi " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + }, + { + "type": "text", + "text": " in " + }, + { + "type": "channel", + "channel_id": "C0CH1LGJ4F3" + }, + { + "type": "text", + "text": "." + }, + { + "type": "text", + "text": "\n" + }, + { + "type": "text", + "text": "Inline code: " + }, + { + "type": "text", + "text": "<@U0CCLMD4S1L> <#C0CH1LGJ4F3>", + "style": { + "code": true + } + } + ] + }, + { + "type": "rich_text_preformatted", + "elements": [ + { + "type": "text", + "text": "fenced <@U0CCLMD4S1L> <#C0CH1LGJ4F3>" + } + ] + }, + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Escaped: " + }, + { + "type": "text", + "text": "<" + }, + { + "type": "text", + "text": "not a tag" + }, + { + "type": "text", + "text": ">" + }, + { + "type": "text", + "text": " and a raw < sign, " + }, + { + "type": "text", + "text": "bold", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": " and " + }, + { + "type": "link", + "url": "https://effect.website", + "text": "x" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509003.143939", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509003.143939", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture mentions: hi <@U0CCLMD4S1L> in <#C0CH1LGJ4F3>.\nInline code: `<@U0CCLMD4S1L> <#C0CH1LGJ4F3>`\n```fenced <@U0CCLMD4S1L> <#C0CH1LGJ4F3>```\nEscaped: <not a tag> and a raw < sign, *bold* and ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "UfdV4+", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture mentions: hi " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + }, + { + "type": "text", + "text": " in " + }, + { + "type": "channel", + "channel_id": "C0CH1LGJ4F3" + }, + { + "type": "text", + "text": "." + }, + { + "type": "text", + "text": "\n" + }, + { + "type": "text", + "text": "Inline code: " + }, + { + "type": "text", + "text": "<@U0CCLMD4S1L> <#C0CH1LGJ4F3>", + "style": { + "code": true + } + } + ] + }, + { + "type": "rich_text_preformatted", + "elements": [ + { + "type": "text", + "text": "fenced <@U0CCLMD4S1L> <#C0CH1LGJ4F3>" + } + ] + }, + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Escaped: " + }, + { + "type": "text", + "text": "<" + }, + { + "type": "text", + "text": "not a tag" + }, + { + "type": "text", + "text": ">" + }, + { + "type": "text", + "text": " and a raw < sign, " + }, + { + "type": "text", + "text": "bold", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": " and " + }, + { + "type": "link", + "url": "https://effect.website", + "text": "x" + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + }, + { + "method": "conversations.history", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509003.143939", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509003.143939", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509003.143939", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture mentions: hi <@U0CCLMD4S1L> in <#C0CH1LGJ4F3>.\nInline code: `<@U0CCLMD4S1L> <#C0CH1LGJ4F3>`\n```fenced <@U0CCLMD4S1L> <#C0CH1LGJ4F3>```\nEscaped: <not a tag> and a raw < sign, *bold* and ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "UfdV4+", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture mentions: hi " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + }, + { + "type": "text", + "text": " in " + }, + { + "type": "channel", + "channel_id": "C0CH1LGJ4F3" + }, + { + "type": "text", + "text": "." + }, + { + "type": "text", + "text": "\n" + }, + { + "type": "text", + "text": "Inline code: " + }, + { + "type": "text", + "text": "<@U0CCLMD4S1L> <#C0CH1LGJ4F3>", + "style": { + "code": true + } + } + ] + }, + { + "type": "rich_text_preformatted", + "elements": [ + { + "type": "text", + "text": "fenced <@U0CCLMD4S1L> <#C0CH1LGJ4F3>" + } + ] + }, + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Escaped: " + }, + { + "type": "text", + "text": "<" + }, + { + "type": "text", + "text": "not a tag" + }, + { + "type": "text", + "text": ">" + }, + { + "type": "text", + "text": " and a raw < sign, " + }, + { + "type": "text", + "text": "bold", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": " and " + }, + { + "type": "link", + "url": "https://effect.website", + "text": "x" + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MDAwMzUyNzg5" + } + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/me-message.json b/packages/chat/slack/test/fixtures/recorded/me-message.json new file mode 100644 index 00000000000..da9fed0e641 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/me-message.json @@ -0,0 +1,136 @@ +{ + "case": "chat.meMessage mentioning the bot; read back", + "recordedAt": "2026-11-12T18:43:28.103Z", + "calls": [ + { + "method": "chat.meMessage", + "encoding": "form", + "note": "chat.meMessage via form encoding", + "request": { + "channel": "C0CH1LGJ4F3", + "text": "Fixture: me message waves at <@U0CCLMD4S1L>" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509006.465359" + } + }, + { + "method": "conversations.history", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509006.465359", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509006.465359", + "messages": [ + { + "subtype": "me_message", + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509006.465359", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: me message waves at <@U0CCLMD4S1L|janitor2>", + "blocks": [ + { + "type": "rich_text", + "block_id": "+CZAP", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: me message waves at " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MDA0ODExODc5" + } + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509006.465359", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "subtype": "me_message", + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509006.465359", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: me message waves at <@U0CCLMD4S1L|janitor2>", + "blocks": [ + { + "type": "rich_text", + "block_id": "TYkp0", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: me message waves at " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + }, + { + "method": "chat.meMessage", + "encoding": "json", + "note": "same method with JSON body", + "request": { + "channel": "C0CH1LGJ4F3", + "text": "Fixture: me message (json body)" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509008.079609" + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/reactions.json b/packages/chat/slack/test/fixtures/recorded/reactions.json new file mode 100644 index 00000000000..0edb7d474a8 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/reactions.json @@ -0,0 +1,480 @@ +{ + "case": "reactions.add / reactions.get / reactions.remove with standard, skin-toned and alias emoji names; emoji.list (custom emoji lookup) is missing_scope for this bot so no custom emoji could be recorded", + "recordedAt": "2026-11-12T18:44:35.155Z", + "customEmojiName": null, + "calls": [ + { + "method": "emoji.list", + "encoding": "form", + "note": "bot lacks emoji:read; used to find a custom emoji", + "request": {}, + "httpStatus": 200, + "response": { + "ok": false, + "error": "missing_scope", + "needed": "emoji:read", + "provided": "channels:history,groups:history,im:history,im:read,reactions:read,users:read,chat:write,app_mentions:read,im:write,reactions:write,assistant:write,channels:read,groups:read,files:read,files:write" + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture: reactions target" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509073.518429", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509073.518429", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: reactions target", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "C7NS1J", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: reactions target" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "reactions.add", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "grinning" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.add", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "+1::skin-tone-3" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.add", + "encoding": "json", + "note": "alias name thumbsup with a tone", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "thumbsup::skin-tone-4" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.add", + "encoding": "json", + "note": "plain alias-free name", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "smile" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.add", + "encoding": "json", + "note": "adding the same reaction twice", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "grinning" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "already_reacted" + } + }, + { + "method": "reactions.add", + "encoding": "json", + "note": "unknown emoji name (also what a missing custom emoji would give)", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "not_a_real_emoji_xyz" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "invalid_name" + } + }, + { + "method": "reactions.add", + "encoding": "json", + "note": "name wrapped in colons", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": ":grinning:" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "invalid_name" + } + }, + { + "method": "reactions.get", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "full": true + }, + "httpStatus": 200, + "response": { + "ok": true, + "type": "message", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509073.518429", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: reactions target", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "C7NS1J", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: reactions target" + } + ] + } + ] + } + ], + "reactions": [ + { + "name": "+1::skin-tone-3", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + }, + { + "name": "+1::skin-tone-4", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + }, + { + "name": "grinning", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + }, + { + "name": "smile", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + } + ], + "permalink": "https://scrubbed.invalid/permalink" + }, + "channel": "C0CH1LGJ4F3" + } + }, + { + "method": "conversations.history", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509073.518429", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509073.518429", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509073.518429", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: reactions target", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "C7NS1J", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: reactions target" + } + ] + } + ] + } + ], + "reactions": [ + { + "name": "+1::skin-tone-3", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + }, + { + "name": "+1::skin-tone-4", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + }, + { + "name": "grinning", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + }, + { + "name": "smile", + "users": [ + "U0CCLMD4S1L" + ], + "count": 1 + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MDQ5MjQ1NjA5" + } + } + }, + { + "method": "reactions.remove", + "encoding": "json", + "note": "remove via the alias name used when adding", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "thumbsup::skin-tone-4" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.remove", + "encoding": "json", + "note": "removing using the name as returned by reactions.get", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "+1::skin-tone-3" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.remove", + "encoding": "json", + "note": "removing using the name as returned by reactions.get", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "grinning" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.remove", + "encoding": "json", + "note": "removing using the name as returned by reactions.get", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "smile" + }, + "httpStatus": 200, + "response": { + "ok": true + } + }, + { + "method": "reactions.remove", + "encoding": "json", + "note": "removing a reaction that is no longer present", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "name": "grinning" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "no_reaction" + } + }, + { + "method": "reactions.get", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "timestamp": "1794509073.518429", + "full": true + }, + "httpStatus": 200, + "response": { + "ok": true, + "type": "message", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509073.518429", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: reactions target", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "C7NS1J", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: reactions target" + } + ] + } + ] + } + ], + "permalink": "https://scrubbed.invalid/permalink" + }, + "channel": "C0CH1LGJ4F3" + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/stream.json b/packages/chat/slack/test/fixtures/recorded/stream.json new file mode 100644 index 00000000000..6e3d4fd2557 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/stream.json @@ -0,0 +1,587 @@ +{ + "case": "chat.startStream/appendStream/stopStream in a channel thread (recipient = the bot itself), update/delete while open, append and stop after stop, read back", + "recordedAt": "2026-11-12T18:45:13.099Z", + "calls": [ + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture: streaming thread root" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509110.999799", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509110.999799", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: streaming thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "s71/d3", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: streaming thread root" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "chat.startStream", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "thread_ts": "1794509110.999799", + "recipient_user_id": "U0CCLMD4S1L", + "recipient_team_id": "T05479Z6JBW" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189" + } + }, + { + "method": "chat.appendStream", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189", + "markdown_text": "Streaming **part one**. " + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189" + } + }, + { + "method": "chat.appendStream", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189", + "markdown_text": "Part two with <@U0CCLMD4S1L>." + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189" + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "note": "read while stream is open", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509110.999799", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509110.999799", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: streaming thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509110.999799", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509111.134189", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "s71/d3", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: streaming thread root" + } + ] + } + ] + } + ], + "agent_session": { + "status": "processing", + "agent_bot_user_ids": [ + "U0CCLMD4S1L" + ], + "date_status_processing_expire": 1794512711, + "agent_statuses": [ + { + "agent_bot_user_id": "U0CCLMD4S1L", + "status": "processing", + "date_status_processing_expire": 1794512711, + "is_stoppable": true + } + ] + } + }, + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509111.134189", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Streaming *part one*. Part two with <@U0CCLMD4S1L>.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509110.999799", + "parent_user_id": "U0CCLMD4S1L", + "streaming_state": "in_progress", + "blocks": [ + { + "type": "rich_text", + "block_id": "NylRdI", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Streaming " + }, + { + "type": "text", + "text": "part one", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": ". Part two with " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + }, + { + "type": "text", + "text": "." + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + }, + { + "method": "chat.update", + "encoding": "json", + "note": "update while stream is open", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189", + "markdown_text": "update while open" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "streaming_state_conflict" + } + }, + { + "method": "chat.delete", + "encoding": "json", + "note": "delete while stream is open", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "cant_delete_message" + } + }, + { + "method": "chat.stopStream", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509111.134189", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Streaming *part one*. Part two with <@U0CCLMD4S1L>.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509110.999799", + "parent_user_id": "U0CCLMD4S1L", + "blocks": [ + { + "type": "rich_text", + "block_id": "NylRdI", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Streaming " + }, + { + "type": "text", + "text": "part one", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": ". Part two with " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + }, + { + "type": "text", + "text": "." + } + ] + } + ] + } + ], + "streaming_state": "completed" + } + } + }, + { + "method": "chat.appendStream", + "encoding": "json", + "note": "append after stop", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189", + "markdown_text": "after stop" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "message_not_in_streaming_state" + } + }, + { + "method": "chat.stopStream", + "encoding": "json", + "note": "second stop", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "message_not_in_streaming_state" + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "note": "read after stop", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509110.999799", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509110.999799", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: streaming thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509110.999799", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509111.134189", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "s71/d3", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: streaming thread root" + } + ] + } + ] + } + ], + "agent_session": { + "status": "active", + "agent_bot_user_ids": [ + "U0CCLMD4S1L" + ], + "agent_statuses": [ + { + "agent_bot_user_id": "U0CCLMD4S1L", + "status": "active", + "is_stoppable": true + } + ] + } + }, + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509111.134189", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Streaming *part one*. Part two with <@U0CCLMD4S1L>.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509110.999799", + "parent_user_id": "U0CCLMD4S1L", + "blocks": [ + { + "type": "rich_text", + "block_id": "NylRdI", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Streaming " + }, + { + "type": "text", + "text": "part one", + "style": { + "bold": true + } + }, + { + "type": "text", + "text": ". Part two with " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + }, + { + "type": "text", + "text": "." + } + ] + } + ] + } + ], + "streaming_state": "completed" + } + ], + "has_more": false + } + }, + { + "method": "chat.update", + "encoding": "json", + "note": "update after stop", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189", + "markdown_text": "Streaming part one. Part two (edited after stop)." + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509111.134189", + "text": "Streaming part one. Part two (edited after stop).", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509113.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Streaming part one. Part two (edited after stop).", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509110.999799", + "parent_user_id": "U0CCLMD4S1L", + "blocks": [ + { + "type": "rich_text", + "block_id": "8CcUt3", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Streaming part one. Part two (edited after stop)." + } + ] + } + ] + } + ], + "streaming_state": "completed" + } + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/thread-broadcast.json b/packages/chat/slack/test/fixtures/recorded/thread-broadcast.json new file mode 100644 index 00000000000..9a657e55bf3 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/thread-broadcast.json @@ -0,0 +1,405 @@ +{ + "case": "thread reply with reply_broadcast: true mentioning the bot; read back via history (channel copy) and replies", + "recordedAt": "2026-11-12T18:43:26.438Z", + "calls": [ + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture: broadcast thread root" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509004.758279", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.758279", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "21wkcy", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast thread root" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "thread_ts": "1794509004.758279", + "reply_broadcast": true, + "markdown_text": "Fixture: broadcast reply to <@U0CCLMD4S1L>" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509004.811879", + "message": { + "subtype": "thread_broadcast", + "bot_id": "B0CCQH77VA5", + "thread_ts": "1794509004.758279", + "root": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.758279", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509004.758279", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509004.811879", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "21wkcy", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast thread root" + } + ] + } + ] + } + ] + }, + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.811879", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast reply to <@U0CCLMD4S1L>", + "blocks": [ + { + "type": "rich_text", + "block_id": "lMh39u", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast reply to " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509004.811879", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509004.811879", + "messages": [ + { + "subtype": "thread_broadcast", + "bot_id": "B0CCQH77VA5", + "thread_ts": "1794509004.758279", + "root": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.758279", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509004.758279", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509004.811879", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "21wkcy", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast thread root" + } + ] + } + ] + } + ] + }, + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.811879", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast reply to <@U0CCLMD4S1L>", + "blocks": [ + { + "type": "rich_text", + "block_id": "lMh39u", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast reply to " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MDA0NzU4Mjc5" + } + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509004.758279", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.758279", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509004.758279", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509004.811879", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "21wkcy", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast thread root" + } + ] + } + ] + } + ] + }, + { + "subtype": "thread_broadcast", + "bot_id": "B0CCQH77VA5", + "thread_ts": "1794509004.758279", + "root": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.758279", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast thread root", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509004.758279", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509004.811879", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "21wkcy", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast thread root" + } + ] + } + ] + } + ] + }, + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509004.811879", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: broadcast reply to <@U0CCLMD4S1L>", + "blocks": [ + { + "type": "rich_text", + "block_id": "lMh39u", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: broadcast reply to " + }, + { + "type": "user", + "user_id": "U0CCLMD4S1L" + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json b/packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json new file mode 100644 index 00000000000..c44ef86d745 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json @@ -0,0 +1,472 @@ +{ + "case": "a thread root read (history + replies) before and after its first reply; root posted with markdown_text", + "recordedAt": "2026-11-12T18:43:23.114Z", + "calls": [ + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture: thread root (no mentions). Some *markdown* here." + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509000.352789", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509000.352789", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: thread root (no mentions). Some _markdown_ here.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "TOu1os", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: thread root (no mentions). Some " + }, + { + "type": "text", + "text": "markdown", + "style": { + "italic": true + } + }, + { + "type": "text", + "text": " here." + } + ] + } + ] + } + ] + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509000.352789", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509000.352789", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509000.352789", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: thread root (no mentions). Some _markdown_ here.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "TOu1os", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: thread root (no mentions). Some " + }, + { + "type": "text", + "text": "markdown", + "style": { + "italic": true + } + }, + { + "type": "text", + "text": " here." + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NDc5NTAzODIwNzA5" + } + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509000.352789", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509000.352789", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: thread root (no mentions). Some _markdown_ here.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "TOu1os", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: thread root (no mentions). Some " + }, + { + "type": "text", + "text": "markdown", + "style": { + "italic": true + } + }, + { + "type": "text", + "text": " here." + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "request": { + "channel": "C0CH1LGJ4F3", + "thread_ts": "1794509000.352789", + "markdown_text": "Fixture: first reply in the thread." + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509001.485739", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509001.485739", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: first reply in the thread.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509000.352789", + "parent_user_id": "U0CCLMD4S1L", + "blocks": [ + { + "type": "rich_text", + "block_id": "vy+DO3", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: first reply in the thread." + } + ] + } + ] + } + ] + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509000.352789", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509000.352789", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509000.352789", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: thread root (no mentions). Some _markdown_ here.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509000.352789", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509001.485739", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "TOu1os", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: thread root (no mentions). Some " + }, + { + "type": "text", + "text": "markdown", + "style": { + "italic": true + } + }, + { + "type": "text", + "text": " here." + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NDc5NTAzODIwNzA5" + } + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509000.352789", + "limit": 10 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509000.352789", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: thread root (no mentions). Some _markdown_ here.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509000.352789", + "reply_count": 1, + "reply_users_count": 1, + "latest_reply": "1794509001.485739", + "reply_users": [ + "U0CCLMD4S1L" + ], + "is_locked": false, + "subscribed": false, + "blocks": [ + { + "type": "rich_text", + "block_id": "TOu1os", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: thread root (no mentions). Some " + }, + { + "type": "text", + "text": "markdown", + "style": { + "italic": true + } + }, + { + "type": "text", + "text": " here." + } + ] + } + ] + } + ] + }, + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509001.485739", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture: first reply in the thread.", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "thread_ts": "1794509000.352789", + "parent_user_id": "U0CCLMD4S1L", + "blocks": [ + { + "type": "rich_text", + "block_id": "vy+DO3", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture: first reply in the thread." + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/unfurl-edit.json b/packages/chat/slack/test/fixtures/recorded/unfurl-edit.json new file mode 100644 index 00000000000..bebcbeb4e27 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/unfurl-edit.json @@ -0,0 +1,1207 @@ +{ + "case": "does a message posted with unfurl_links/unfurl_media false gain an unfurl when chat.update adds a link? plus a control posted with the link and unfurls enabled; plus a second edit case posted WITHOUT unfurl params (defaults) then edited to add the link; plus edit case 3 / control 3 using URLs not previously posted in the channel (rules out Slack's same-URL unfurl de-duplication)", + "recordedAt": "2026-11-12T18:47:34.080Z", + "firstRecordedAt": "2026-11-12T18:46:15.379Z", + "calls": [ + { + "method": "chat.postMessage", + "encoding": "json", + "note": "edit case: initial post, unfurls disabled", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "no link yet", + "unfurl_links": false, + "unfurl_media": false + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509128.969019", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509128.969019", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "no link yet", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "owsBih", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "no link yet" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "control: link posted directly, unfurls enabled", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture control: https://github.com/Effect-TS/effect", + "unfurl_links": true, + "unfurl_media": true + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509129.029199", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509129.029199", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture control: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "gacOs0", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture control: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + } + }, + { + "method": "chat.update", + "encoding": "json", + "note": "edit case: add a link (chat.update has no unfurl params)", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509128.969019", + "markdown_text": "now with a link: https://github.com/Effect-TS/effect" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509128.969019", + "text": "now with a link: ", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509130.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "now with a link: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "sv5KYB", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "now with a link: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "edit case after 20s", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509128.969019", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509128.969019", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509128.969019", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509130.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "now with a link: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "sv5KYB", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "now with a link: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MTEwOTk5Nzk5" + } + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "note": "edit case after 20s", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509128.969019", + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509128.969019", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509130.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "now with a link: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "sv5KYB", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "now with a link: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "control after 20s", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509129.029199", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509129.029199", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509129.029199", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture control: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "attachments": [ + { + "from_url": "https://github.com/Effect-TS/effect", + "image_url": "https://scrubbed.invalid/image_url", + "image_width": 1200, + "image_height": 600, + "image_bytes": 42222, + "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png", + "original_url": "https://github.com/Effect-TS/effect", + "id": 1, + "fallback": "GitHub: GitHub - Effect-TS/effect: Build production-ready applications in TypeScript", + "text": "Build production-ready applications in TypeScript. Contribute to Effect-TS/effect development by creating an account on GitHub.", + "title": "GitHub - Effect-TS/effect: Build production-ready applications in TypeScript", + "title_link": "https://github.com/Effect-TS/effect", + "service_name": "GitHub", + "media_type": "external_link" + } + ], + "blocks": [ + { + "type": "rich_text", + "block_id": "gacOs0", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture control: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MTI4OTY5MDE5" + } + } + }, + { + "method": "conversations.replies", + "encoding": "form", + "note": "control after 20s", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509129.029199", + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509129.029199", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture control: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "attachments": [ + { + "from_url": "https://github.com/Effect-TS/effect", + "image_url": "https://scrubbed.invalid/image_url", + "image_width": 1200, + "image_height": 600, + "image_bytes": 42222, + "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png", + "original_url": "https://github.com/Effect-TS/effect", + "id": 1, + "fallback": "GitHub: GitHub - Effect-TS/effect: Build production-ready applications in TypeScript", + "text": "Build production-ready applications in TypeScript. Contribute to Effect-TS/effect development by creating an account on GitHub.", + "title": "GitHub - Effect-TS/effect: Build production-ready applications in TypeScript", + "title_link": "https://github.com/Effect-TS/effect", + "service_name": "GitHub", + "media_type": "external_link" + } + ], + "blocks": [ + { + "type": "rich_text", + "block_id": "gacOs0", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture control: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": false + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "edit case after ~45s", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509128.969019", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509128.969019", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509128.969019", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509130.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "now with a link: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "sv5KYB", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "now with a link: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MTEwOTk5Nzk5" + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "control after ~45s", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509129.029199", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509129.029199", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509129.029199", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture control: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "attachments": [ + { + "from_url": "https://github.com/Effect-TS/effect", + "image_url": "https://scrubbed.invalid/image_url", + "image_width": 1200, + "image_height": 600, + "image_bytes": 42222, + "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png", + "original_url": "https://github.com/Effect-TS/effect", + "id": 1, + "fallback": "GitHub: GitHub - Effect-TS/effect: Build production-ready applications in TypeScript", + "text": "Build production-ready applications in TypeScript. Contribute to Effect-TS/effect development by creating an account on GitHub.", + "title": "GitHub - Effect-TS/effect: Build production-ready applications in TypeScript", + "title_link": "https://github.com/Effect-TS/effect", + "service_name": "GitHub", + "media_type": "external_link" + } + ], + "blocks": [ + { + "type": "rich_text", + "block_id": "gacOs0", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture control: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MTI4OTY5MDE5" + } + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "edit case 2: initial post with no unfurl params", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "no link yet (default unfurl settings)" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509187.550629", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509187.550629", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "no link yet (default unfurl settings)", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "DWET6I", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "no link yet (default unfurl settings)" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "chat.update", + "encoding": "json", + "note": "edit case 2: add a link", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509187.550629", + "markdown_text": "edited to add https://github.com/Effect-TS/effect" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509187.550629", + "text": "edited to add ", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509188.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "edited to add ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "rDlbGF", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "edited to add " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "edit case 2 after ~25s", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509187.550629", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509187.550629", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509187.550629", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509188.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "edited to add ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "rDlbGF", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "edited to add " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect", + "text": "github.com/Effect-TS/effect", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MTI5MDI5MTk5" + } + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "edit case 3: initial post, default unfurl settings", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "no link yet (case 3)" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509227.845499", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509227.845499", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "no link yet (case 3)", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "Y7Owd/", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "no link yet (case 3)" + } + ] + } + ] + } + ] + } + } + }, + { + "method": "chat.postMessage", + "encoding": "json", + "note": "control 3: fresh URL posted directly, default unfurl settings", + "request": { + "channel": "C0CH1LGJ4F3", + "markdown_text": "Fixture control 3: https://github.com/Effect-TS/effect/issues/2" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509227.900709", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509227.900709", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture control 3: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "2ktf5k", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture control 3: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect/issues/2", + "text": "github.com/Effect-TS/effect/issues/2", + "truncated": true + } + ] + } + ] + } + ] + } + } + }, + { + "method": "chat.update", + "encoding": "json", + "note": "edit case 3: add a fresh URL", + "request": { + "channel": "C0CH1LGJ4F3", + "ts": "1794509227.845499", + "markdown_text": "edited to add https://github.com/Effect-TS/effect/issues/1" + }, + "httpStatus": 200, + "response": { + "ok": true, + "channel": "C0CH1LGJ4F3", + "ts": "1794509227.845499", + "text": "edited to add ", + "message": { + "user": "U0CCLMD4S1L", + "type": "message", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509228.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "edited to add ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "xucmzr", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "edited to add " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect/issues/1", + "text": "github.com/Effect-TS/effect/issues/1", + "truncated": true + } + ] + } + ] + } + ] + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "edit case 3 after ~25s", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509227.845499", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509227.845499", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509227.845499", + "edited": { + "user": "U0CCLMD4S1L", + "ts": "1794509228.000000" + }, + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "edited to add ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "blocks": [ + { + "type": "rich_text", + "block_id": "xucmzr", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "edited to add " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect/issues/1", + "text": "github.com/Effect-TS/effect/issues/1", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MTg3NTUwNjI5" + } + } + }, + { + "method": "conversations.history", + "encoding": "form", + "note": "control 3 after ~25s", + "request": { + "channel": "C0CH1LGJ4F3", + "latest": "1794509227.900709", + "inclusive": true, + "limit": 1 + }, + "httpStatus": 200, + "response": { + "ok": true, + "latest": "1794509227.900709", + "messages": [ + { + "user": "U0CCLMD4S1L", + "type": "message", + "ts": "1794509227.900709", + "bot_id": "B0CCQH77VA5", + "app_id": "A0CCHBHDK7X", + "text": "Fixture control 3: ", + "team": "T05479Z6JBW", + "bot_profile": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + }, + "team_id": "T05479Z6JBW" + }, + "attachments": [ + { + "from_url": "https://github.com/Effect-TS/effect/issues/2", + "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png", + "original_url": "https://github.com/Effect-TS/effect/issues/2", + "id": 1, + "fallback": "GitHub: Rpc - Zero Boilerplate by mikearnaldi · Pull Request #2 · Effect-TS/effect", + "text": "Reinterpret an effect to be executed against an http endpoint, missing server implementation and http", + "title": "Rpc - Zero Boilerplate by mikearnaldi · Pull Request #2 · Effect-TS/effect", + "title_link": "https://github.com/Effect-TS/effect/issues/2", + "service_name": "GitHub", + "media_type": "external_link" + } + ], + "blocks": [ + { + "type": "rich_text", + "block_id": "2ktf5k", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "Fixture control 3: " + }, + { + "type": "link", + "url": "https://github.com/Effect-TS/effect/issues/2", + "text": "github.com/Effect-TS/effect/issues/2", + "truncated": true + } + ] + } + ] + } + ] + } + ], + "has_more": true, + "pin_count": 0, + "channel_actions_ts": null, + "channel_actions_count": 0, + "response_metadata": { + "next_cursor": "bmV4dF90czoxNzk0NTA5MjI3ODQ1NDk5" + } + } + } + ] +} diff --git a/packages/chat/slack/test/fixtures/recorded/users-info.json b/packages/chat/slack/test/fixtures/recorded/users-info.json new file mode 100644 index 00000000000..8d1858714f7 --- /dev/null +++ b/packages/chat/slack/test/fixtures/recorded/users-info.json @@ -0,0 +1,193 @@ +{ + "case": "auth.test, users.info for the bot user and a human, bots.info for the bot, users.info on a bot id (error)", + "recordedAt": "2026-11-12T18:43:05.435Z", + "calls": [ + { + "method": "auth.test", + "encoding": "json", + "request": {}, + "httpStatus": 200, + "response": { + "ok": true, + "url": "https://effectfulworkspace.slack.com/", + "team": "Effectful", + "user": "janitor2", + "team_id": "T05479Z6JBW", + "user_id": "U0CCLMD4S1L", + "bot_id": "B0CCQH77VA5", + "is_enterprise_install": false + } + }, + { + "method": "users.info", + "encoding": "form", + "note": "users.info is documented as form/GET; json also tried below", + "request": { + "user": "U0CCLMD4S1L" + }, + "httpStatus": 200, + "response": { + "ok": true, + "user": { + "id": "U0CCLMD4S1L", + "name": "janitor2", + "is_bot": true, + "updated": 1794450518, + "is_app_user": false, + "team_id": "T05479Z6JBW", + "deleted": false, + "color": "619a4f", + "is_email_confirmed": false, + "real_name": "janitor", + "tz": "America/Los_Angeles", + "tz_label": "Pacific Standard Time", + "tz_offset": -28800, + "is_admin": false, + "is_owner": false, + "is_primary_owner": false, + "is_restricted": false, + "is_ultra_restricted": false, + "who_can_share_contact_card": "EVERYONE", + "profile": { + "real_name": "janitor", + "display_name": "", + "avatar_hash": "3d654eba937a", + "real_name_normalized": "janitor", + "display_name_normalized": "", + "image_24": "https://scrubbed.invalid/image_24", + "image_32": "https://scrubbed.invalid/image_32", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72", + "image_192": "https://scrubbed.invalid/image_192", + "image_512": "https://scrubbed.invalid/image_512", + "image_1024": "https://scrubbed.invalid/image_1024", + "image_original": "https://scrubbed.invalid/image_original", + "is_custom_image": true, + "first_name": "janitor", + "last_name": "", + "team": "T05479Z6JBW", + "title": "", + "phone": "", + "skype": "", + "status_text": "", + "status_text_canonical": "", + "status_emoji": "", + "status_emoji_display_info": [], + "status_expiration": 0, + "bot_id": "B0CCQH77VA5", + "api_app_id": "A0CCHBHDK7X", + "always_active": true + } + } + } + }, + { + "method": "users.info", + "encoding": "json", + "note": "same call with a JSON body", + "request": { + "user": "U0CCLMD4S1L" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "user_not_found" + } + }, + { + "method": "users.info", + "encoding": "form", + "request": { + "user": "U080YLYB277" + }, + "httpStatus": 200, + "response": { + "ok": true, + "user": { + "id": "U080YLYB277", + "name": "test.user", + "is_bot": false, + "updated": 1782289647, + "is_app_user": false, + "team_id": "T05479Z6JBW", + "deleted": false, + "color": "827327", + "is_email_confirmed": true, + "real_name": "Test User", + "tz": "Pacific/Auckland", + "tz_label": "New Zealand Daylight Time", + "tz_offset": 46800, + "is_admin": false, + "is_owner": false, + "is_primary_owner": false, + "is_restricted": false, + "is_ultra_restricted": false, + "who_can_share_contact_card": "EVERYONE", + "profile": { + "real_name": "Test User", + "display_name": "Test User", + "avatar_hash": "g51a1c442992", + "real_name_normalized": "Test User", + "display_name_normalized": "Test User", + "image_24": "https://scrubbed.invalid/image_24", + "image_32": "https://scrubbed.invalid/image_32", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72", + "image_192": "https://scrubbed.invalid/image_192", + "image_512": "https://scrubbed.invalid/image_512", + "first_name": "Test User", + "last_name": "Test User", + "team": "T05479Z6JBW", + "title": "", + "phone": "", + "skype": "", + "status_text": "", + "status_text_canonical": "", + "status_emoji": "", + "status_emoji_display_info": [], + "status_expiration": 0, + "huddle_state": "default_unset", + "huddle_state_expiration_ts": 0 + } + } + } + }, + { + "method": "bots.info", + "encoding": "form", + "request": { + "bot": "B0CCQH77VA5" + }, + "httpStatus": 200, + "response": { + "ok": true, + "bot": { + "id": "B0CCQH77VA5", + "deleted": false, + "name": "Janitor", + "updated": 1793135255, + "app_id": "A0CCHBHDK7X", + "user_id": "U0CCLMD4S1L", + "icons": { + "image_36": "https://scrubbed.invalid/image_36", + "image_48": "https://scrubbed.invalid/image_48", + "image_72": "https://scrubbed.invalid/image_72" + } + } + } + }, + { + "method": "users.info", + "encoding": "form", + "note": "users.info with a B... bot id", + "request": { + "user": "B0CCQH77VA5" + }, + "httpStatus": 200, + "response": { + "ok": false, + "error": "user_not_found" + } + } + ] +} diff --git a/packages/chat/slack/test/live.test.ts b/packages/chat/slack/test/live.test.ts new file mode 100644 index 00000000000..5cf50c115c4 --- /dev/null +++ b/packages/chat/slack/test/live.test.ts @@ -0,0 +1,86 @@ +/** + * The conformance suite against a real Slack workspace. Opt-in: it runs only + * when these are set, so CI skips it. + * + * - `SLACK_LIVE_BOT_TOKEN`, `SLACK_LIVE_TEAM_ID` and `SLACK_LIVE_CHANNEL`: the + * bot and a channel it may write to. + * - `SLACK_LIVE_USER_TOKEN`: a user token with `chat:write` and + * `channels:history`, for the rules that need another identity's + * message. Without it those rules fail at `userPosts`. + */ +import * as SlackChat from "@effect/chat-slack/SlackChat" +import * as SlackWebApi from "@effect/chat-slack/SlackWebApi" +import { describe, it } from "@effect/vitest" +import * as Chat from "effect/chat/Chat" +import type * as ChatEvent from "effect/chat/ChatEvent" +import { conformance } from "effect/chat/ChatTest" +import type * as ChatThread from "effect/chat/ChatThread" +import * as Effect from "effect/Effect" +import * as FetchHttpClient from "effect/http/FetchHttpClient" +import * as Layer from "effect/Layer" +import * as Redacted from "effect/Redacted" +import * as Semaphore from "effect/Semaphore" + +const botToken = process.env.SLACK_LIVE_BOT_TOKEN +const userToken = process.env.SLACK_LIVE_USER_TOKEN +const teamId = process.env.SLACK_LIVE_TEAM_ID +const channel = process.env.SLACK_LIVE_CHANNEL + +const field = (u: unknown, key: string): any => + typeof u === "object" && u !== null && !Array.isArray(u) ? (u as Record)[key] : undefined + +describe.skipIf(botToken === undefined || teamId === undefined || channel === undefined)("live conformance", () => { + const layer = SlackChat.layer({ botToken: Redacted.make(botToken!), teamId: teamId! }).pipe( + Layer.provideMerge(Chat.layer), + Layer.provide(FetchHttpClient.layer) + ) + + /** Posts as the user, reads the message back and normalises it as an inbound `message` event. */ + const userPosts = (thread: ChatThread.ChatThread, text: string): Effect.Effect => + Effect.gen(function*() { + if (userToken === undefined) return yield* Effect.die(new Error("SLACK_LIVE_USER_TOKEN is not set")) + const user = yield* SlackWebApi.make({ botToken: Redacted.make(userToken) }) + const bot = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) }) + const parts = SlackChat.parts(thread) + if (parts._tag === "None") return yield* Effect.die(new Error("not a Slack thread")) + const { threadTs } = parts.value + const posted = yield* user.call("chat.postMessage", { + channel: parts.value.channel, + text, + ...(threadTs === undefined ? {} : { thread_ts: threadTs }) + }, { write: true }) + const ts = field(posted, "ts") + const read = yield* user.call("conversations.replies", { + channel: parts.value.channel, + ts, + latest: ts, + oldest: ts, + inclusive: true, + limit: 1 + }) + const messages = field(read, "messages") + const message = Array.isArray(messages) ? messages.find((m: any) => m.ts === ts) : undefined + const auth = yield* bot.call("auth.test", {}) + const events = SlackChat.normalize({ + type: "event_callback", + team_id: parts.value.team, + event: { ...message, type: "message", channel: parts.value.channel, event_ts: ts } + }, { teamId: parts.value.team, botUserId: field(auth, "user_id") ?? "" }) + if (events.length !== 1) return yield* Effect.die(new Error(`userPosts normalised to ${events.length} events`)) + return events[0] + }).pipe(Effect.provide(FetchHttpClient.layer), Effect.orDie) + + const rules = conformance({ + platform: "slack", + thread: SlackChat.thread({ team: teamId ?? "", channel: channel ?? "" }), + userPosts, + parseMention: SlackChat.parseMention + }) + + // The rules share one channel and the project runs tests concurrently, so + // one rule at a time. + const one = Semaphore.makeUnsafe(1) + for (const [name, rule] of Object.entries(rules)) { + it.live(name, () => rule.pipe(Effect.provide(layer), Semaphore.withPermits(one, 1)), 600_000) + } +}) diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts new file mode 100644 index 00000000000..03ae9d17633 --- /dev/null +++ b/packages/chat/slack/test/normalize.test.ts @@ -0,0 +1,279 @@ +import { messageSubtypes } from "@effect/chat-slack/internal/normalize" +import * as SlackChat from "@effect/chat-slack/SlackChat" +import { assert, describe, it } from "@effect/vitest" +import type * as ChatEvent from "effect/chat/ChatEvent" +import { dedupeKey } from "effect/chat/ChatEvent" +import { checkEvent, checkMessage } from "effect/chat/ChatTest" +import * as ChatThread from "effect/chat/ChatThread" +import * as Effect from "effect/Effect" +import { botUserId, channel, checkOptions, fixture, messageEnvelope, recordedMessages, team } from "./utils.ts" + +const context = { teamId: team, botUserId } + +const created = (events: ReadonlyArray): ChatEvent.MessageCreated => { + assert.strictEqual(events.length, 1) + const event = events[0] + assert(event._tag === "MessageCreated") + return event +} + +/** The `message` and `app_mention` for one recorded message, checked as a pair. */ +const pair = Effect.fnUntraced(function*( + message: Record, + options?: { readonly channel?: string; readonly channelType?: string } +) { + const fromMessage = created(SlackChat.normalize(messageEnvelope(message, options), context)) + yield* checkEvent(fromMessage, checkOptions) + if (message.edited !== undefined) { + // An edit reuses the id of a message already delivered. + assert.deepStrictEqual( + SlackChat.normalize(messageEnvelope(message, { ...options, type: "app_mention" }), context), + [] + ) + return fromMessage + } + const fromMention = created( + SlackChat.normalize(messageEnvelope(message, { ...options, type: "app_mention" }), context) + ) + yield* checkEvent(fromMention, checkOptions) + assert.strictEqual(dedupeKey(fromMessage), dedupeKey(fromMention)) + const { raw: _a, ...left } = fromMessage.message + const { raw: _b, ...right } = fromMention.message + assert.deepStrictEqual(left, right) + assert.deepStrictEqual(fromMessage.thread, fromMention.thread) + return fromMessage +}) + +describe("normalize", () => { + it.effect("every recorded message passes checkMessage as a pair", () => + Effect.gen(function*() { + const names = [ + "markdown-mentions", + "me-message", + "thread-broadcast", + "thread-root-before-after", + "file-share", + "stream", + "unfurl-edit" + ] + let count = 0 + for (const name of names) { + for (const message of recordedMessages(name).values()) { + const event = yield* pair(message) + yield* checkMessage(event.message, checkOptions) + count++ + } + } + assert.isAbove(count, 10) + })) + + it.effect("mentions come from rich_text, not from code in text", () => + Effect.gen(function*() { + const message = recordedMessages("markdown-mentions").get("1794509003.143939") + const event = yield* pair(message) + assert.deepStrictEqual( + event.message.mentions.map(({ id, isSelf, kind }) => ({ kind, id, isSelf })), + [{ kind: "user", id: botUserId, isSelf: true }, { kind: "channel", id: channel, isSelf: false }] + ) + const [user] = event.message.mentions + assert.strictEqual(event.message.text.slice(user.start, user.end), `<@${botUserId}>`) + assert.isBelow(user.start, event.message.text.indexOf("Inline code")) + })) + + it.effect("without rich_text, text is scanned outside code", () => + Effect.gen(function*() { + const event = created(SlackChat.normalize( + messageEnvelope({ + ts: "1794509003.000001", + user: "U080YLYB277", + text: "hey <@U0CCLMD4S1L> `<@U999>` and " + }), + context + )) + yield* checkEvent(event, checkOptions) + assert.deepStrictEqual(event.message.mentions.map((mention) => mention.id), [botUserId, "here"]) + assert.isTrue(event.message.mentions[0].isSelf) + assert.isFalse(event.message.author.isSelf) + })) + + it.effect("a /me line that mentions the bot is a message", () => + Effect.gen(function*() { + const [message] = recordedMessages("me-message").values() + assert.strictEqual(message.subtype, "me_message") + const event = yield* pair(message) + assert.strictEqual(event.message.mentions.length, 1) + assert.isTrue(event.message.mentions[0].isSelf) + })) + + it.effect("a thread_broadcast is addressed to its thread", () => + Effect.gen(function*() { + const broadcast = [...recordedMessages("thread-broadcast").values()].find((m) => m.subtype === "thread_broadcast") + const event = yield* pair(broadcast) + assert.strictEqual(event.kind, "thread") + assert.deepStrictEqual(event.thread, SlackChat.thread({ team, channel, threadTs: broadcast.thread_ts })) + })) + + it.effect("a thread root keeps its channel address after its first reply", () => + Effect.gen(function*() { + const calls = fixture("thread-root-before-after").calls.filter((call) => call.method === "conversations.history") + const before = calls[0].response.messages[0] + const after = calls[1].response.messages.find((m: any) => m.ts === before.ts) + assert.strictEqual(after.thread_ts, after.ts) + const one = yield* pair(before) + const two = yield* pair(after) + assert.deepStrictEqual(one.thread, SlackChat.thread({ team, channel })) + assert.deepStrictEqual(two.thread, one.thread) + assert.strictEqual(dedupeKey(one), dedupeKey(two)) + })) + + it.effect("files are attachments, with an id and no URL", () => + Effect.gen(function*() { + const reply = recordedMessages("file-share").get("1794509028.831169") + const event = yield* pair(reply) + assert.strictEqual(event.message.attachments.length, 1) + assert.deepStrictEqual(event.message.attachments[0], { + id: "F0CH6RHTMRU", + name: "fixture.txt", + contentType: "text/plain", + size: 51 + }) + })) + + it.effect("a D channel is a direct", () => + Effect.gen(function*() { + const event = yield* pair( + { ts: "1794509003.000002", user: "U080YLYB277", text: "hi" }, + { channel: "D0CCGDG0E75" } + ) + assert.strictEqual(event.kind, "direct") + const group = yield* pair( + { ts: "1794509003.000003", user: "U080YLYB277", text: "hi" }, + { channel: "C0GROUP", channelType: "mpim" } + ) + assert.strictEqual(group.kind, "direct") + })) + + it.effect("a bot_message's author is its bot_id", () => + Effect.gen(function*() { + const event = yield* pair({ + ts: "1794509003.000004", + subtype: "bot_message", + bot_id: "B0WEBHOOK", + username: "incoming-webhook", + text: "deploy done <@U0CCLMD4S1L>" + }) + assert.deepStrictEqual(event.message.author, { + id: "B0WEBHOOK", + name: "incoming-webhook", + isBot: true, + isSelf: false + }) + })) + + it("drops an edited app_mention, other subtypes, other workspaces and other types", () => { + const message = { ts: "1794509003.000005", user: "U080YLYB277", text: "<@U0CCLMD4S1L>" } + const edited = messageEnvelope({ ...message, edited: { user: "U080YLYB277", ts: "1794509010.000000" } }, { + type: "app_mention" + }) + assert.deepStrictEqual(SlackChat.normalize(edited, context), []) + for (const subtype of ["channel_join", "message_changed", "message_deleted", "assistant_app_thread"]) { + assert.deepStrictEqual(SlackChat.normalize(messageEnvelope({ ...message, subtype }), context), []) + } + assert.deepStrictEqual(SlackChat.normalize(messageEnvelope(message, { teamId: "T0OTHER" }), context), []) + assert.deepStrictEqual(SlackChat.normalize({ type: "url_verification", challenge: "x" }, context), []) + assert.deepStrictEqual(SlackChat.normalize(null, context), []) + assert.deepStrictEqual([...messageSubtypes].sort(), ["bot_message", "file_share", "me_message", "thread_broadcast"]) + }) + + it("drops the verification token from raw", () => { + const event = created(SlackChat.normalize( + messageEnvelope({ ts: "1794509003.000006", user: "U080YLYB277", text: "hi" }), + context + )) + assert.isFalse("token" in (event.raw as object)) + }) +}) + +describe("reactions", () => { + const reaction = (type: "reaction_added" | "reaction_removed", name: string) => ({ + team_id: team, + api_app_id: "A0CCHBHDK7X", + type: "event_callback", + event_id: "Ev02", + event_time: 1794509100, + event: { + type, + user: "U080YLYB277", + reaction: name, + item_user: botUserId, + item: { type: "message", channel, ts: "1794509003.143939" }, + event_ts: "1794509100.000100" + } + }) + + it.effect("plain, toned and custom emoji", () => + Effect.gen(function*() { + // The names Slack stored in the reactions fixture. + const names = fixture("reactions").calls + .filter((call) => call.method === "reactions.add" && call.response.ok === true) + .map((call) => call.request.name as string) + assert.includeMembers(names, ["grinning", "+1::skin-tone-3"]) + const cases: ReadonlyArray = [ + ["grinning", "😀"], + ["+1", "👍"], + ["thumbsup", "👍"], + ["+1::skin-tone-3", "👍🏼"], + ["party-parrot", "custom:party-parrot"] + ] + for (const [name, emoji] of cases) { + const added = SlackChat.normalize(reaction("reaction_added", name), context) + const removed = SlackChat.normalize(reaction("reaction_removed", name), context) + assert.strictEqual(added.length, 1) + const event = added[0] + assert(event._tag === "ReactionAdded") + assert.strictEqual(event.emoji, emoji) + assert.strictEqual(event.messageAuthorId, botUserId) + assert.deepStrictEqual(event.thread, SlackChat.thread({ team, channel })) + yield* checkEvent(event, checkOptions) + yield* checkEvent(removed[0], checkOptions) + assert.notStrictEqual(dedupeKey(event), dedupeKey(removed[0])) + } + })) +}) + +describe("agent_session_stopped", () => { + const cases = fixture("agent-session-stopped").cases + + it.effect("the three captured payloads", () => + Effect.gen(function*() { + const expected: Record }> = { + channelThread: { channel, messageIds: ["1794454017.726189"] }, + noStream: { channel, messageIds: [] }, + direct: { channel: "D0CCGDG0E75", messageIds: ["1794454526.283939"] } + } + for (const [name, envelope] of Object.entries(cases)) { + const events = SlackChat.normalize(envelope, context) + assert.strictEqual(events.length, 1) + const event = events[0] + assert(event._tag === "StopRequested") + yield* checkEvent(event, checkOptions) + const { channel: eventChannel, messageIds } = expected[name] + const raw = envelope as any + assert.deepStrictEqual( + event.thread, + SlackChat.thread({ team, channel: eventChannel, threadTs: raw.event.thread_ts }) + ) + assert.deepStrictEqual(event.messageIds, messageIds) + assert.strictEqual(event.userId, "U080YLYB277") + assert.strictEqual(dedupeKey(event), `stop/${ChatThread.toString(event.thread)}/${raw.event.event_ts}`) + } + })) + + it("an empty streaming_message_ts gives no message ids", () => { + const envelope = structuredClone(cases.channelThread) + envelope.event.streaming_message_ts = [] + const [event] = SlackChat.normalize(envelope, context) + assert(event._tag === "StopRequested") + assert.deepStrictEqual(event.messageIds, []) + }) +}) diff --git a/packages/chat/slack/test/utils.ts b/packages/chat/slack/test/utils.ts new file mode 100644 index 00000000000..34641dac1c7 --- /dev/null +++ b/packages/chat/slack/test/utils.ts @@ -0,0 +1,128 @@ +import * as SlackChat from "@effect/chat-slack/SlackChat" +import * as Chat from "effect/chat/Chat" +import type { ChatAdapter } from "effect/chat/ChatAdapter" +import { Registry } from "effect/chat/ChatAdapter" +import * as Effect from "effect/Effect" +import * as HttpClient from "effect/http/HttpClient" +import type * as HttpClientRequest from "effect/http/HttpClientRequest" +import * as HttpClientResponse from "effect/http/HttpClientResponse" +import * as Layer from "effect/Layer" +import * as Redacted from "effect/Redacted" +import * as fs from "node:fs" + +export const team = "T05479Z6JBW" +export const botUserId = "U0CCLMD4S1L" +export const appId = "A0CCHBHDK7X" +export const channel = "C0CH1LGJ4F3" + +export const checkOptions = { platform: "slack", parseMention: SlackChat.parseMention } + +export interface RecordedCall { + readonly method: string + readonly label?: string + readonly request: Record + readonly response: any +} + +export const fixture = (name: string): { readonly calls: ReadonlyArray; readonly [key: string]: any } => + JSON.parse(fs.readFileSync(new URL(`./fixtures/recorded/${name}.json`, import.meta.url), "utf8")) + +/** Every message object a fixture's reads returned, by ts. */ +export const recordedMessages = (name: string): Map => { + const out = new Map() + for (const call of fixture(name).calls) { + const messages = call.response?.messages + if (Array.isArray(messages)) { for (const message of messages) out.set(message.ts, message) } + } + return out +} + +/** An `event_callback` envelope around a message as a read returned it. */ +export const messageEnvelope = ( + message: Record, + options?: { + readonly type?: "message" | "app_mention" | undefined + readonly channel?: string | undefined + readonly channelType?: string | undefined + readonly teamId?: string | undefined + } +) => ({ + token: "verification-token", + team_id: options?.teamId ?? team, + api_app_id: appId, + type: "event_callback", + event_id: "Ev01", + event_time: 1794509000, + authorizations: [{ team_id: options?.teamId ?? team, user_id: botUserId, is_bot: true }], + event: { + ...message, + type: options?.type ?? "message", + channel: options?.channel ?? channel, + ...(options?.type === "app_mention" ? {} : { channel_type: options?.channelType ?? "channel" }), + event_ts: message.ts + } +}) + +export interface FakeCall { + readonly method: string + readonly params: Record +} + +export type Answer = + | Record + | { readonly status: number; readonly headers?: Record; readonly body?: unknown } + +/** + * A scripted Slack. Each method answers from a queue of answers, the last + * one repeating, or `{ ok: true }` when it has none. + */ +export const makeFake = ( + script: Record | ((params: Record) => Answer)> +) => { + const calls: Array = [] + const queues = new Map>() + for (const [method, answer] of Object.entries(script)) { + if (Array.isArray(answer)) queues.set(method, [...answer]) + } + const respond = (request: HttpClientRequest.HttpClientRequest, url: URL): Response => { + const method = url.pathname.replace(/^\/api\//, "") + const body = request.body + const text = body._tag === "Uint8Array" ? body.text ?? new TextDecoder().decode(body.body) : "" + const params = Object.fromEntries(new URLSearchParams(text)) + calls.push({ method, params }) + const entry = script[method] + let answer: Answer + if (typeof entry === "function") answer = entry(params) + else if (Array.isArray(entry)) { + const queue = queues.get(method)! + answer = queue.length > 1 ? queue.shift()! : queue[0] + } else answer = (entry as Answer | undefined) ?? { ok: true } + if ("status" in answer && typeof answer.status === "number") { + const { body, headers, status } = answer as Extract + return new Response(body === undefined ? "" : JSON.stringify(body), { status, headers: headers ?? {} }) + } + return new Response(JSON.stringify(answer), { status: 200, headers: { "content-type": "application/json" } }) + } + const client = HttpClient.make((request, url) => + Effect.sync(() => HttpClientResponse.fromWeb(request, respond(request, url))) + ) + return { + calls, + called: (method: string) => calls.filter((call) => call.method === method), + layer: Layer.succeed(HttpClient.HttpClient, client) + } +} + +export const authTest = { ok: true, user_id: botUserId, team_id: team } + +/** `Chat`, `Registry` and the Slack adapter on a fake. */ +export const slackLayer = (fake: ReturnType) => + SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team }).pipe( + Layer.provideMerge(Chat.layer), + Layer.provide(fake.layer) + ) + +export const adapter: Effect.Effect = Effect.gen(function*() { + const registry = yield* Registry + return yield* registry.get("slack") +}) diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts new file mode 100644 index 00000000000..0c8cf0e6011 --- /dev/null +++ b/packages/chat/slack/test/webhook.test.ts @@ -0,0 +1,165 @@ +import { handleRequest, makeVerifier, type Options } from "@effect/chat-slack/internal/webhook" +import * as SlackChat from "@effect/chat-slack/SlackChat" +import { assert, describe, it } from "@effect/vitest" +import * as Chat from "effect/chat/Chat" +import { ChatError, PlatformUnavailable } from "effect/chat/ChatError" +import type * as ChatEvent from "effect/chat/ChatEvent" +import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler" +import * as Duration from "effect/Duration" +import * as Effect from "effect/Effect" +import * as HttpRouter from "effect/http/HttpRouter" +import * as HttpServerRequest from "effect/http/HttpServerRequest" +import * as HttpServerResponse from "effect/http/HttpServerResponse" +import * as Layer from "effect/Layer" +import * as Redacted from "effect/Redacted" +import { appId, authTest, botUserId, makeFake, messageEnvelope, team } from "./utils.ts" + +const secret = "8f742231b10e8888abcd99yyyzzz85a5" + +const sign = async (timestamp: string, body: string, key = secret) => { + const encoder = new TextEncoder() + const cryptoKey = await crypto.subtle.importKey( + "raw", + encoder.encode(key), + { name: "HMAC", hash: "SHA-256" }, + false, + ["sign"] + ) + const mac = new Uint8Array(await crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(`v0:${timestamp}:${body}`))) + return "v0=" + Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("") +} + +const unavailable = new ChatError({ + platform: "slack", + op: "auth.test", + reason: new PlatformUnavailable({ retry: "retry", detail: "http_503" }) +}) + +const now = () => String(Math.floor(Date.now() / 1000)) + +const request = async (body: string, options?: { readonly timestamp?: string; readonly key?: string }) => { + const timestamp = options?.timestamp ?? now() + return new Request("http://localhost/slack/events", { + method: "POST", + body, + headers: { + "content-type": "application/json", + "x-slack-request-timestamp": timestamp, + "x-slack-signature": await sign(timestamp, body, options?.key) + } + }) +} + +const message = messageEnvelope({ ts: "1794509003.000001", user: "U080YLYB277", text: "hi <@U0CCLMD4S1L>" }) + +const handle = Effect.fnUntraced(function*(options: Partial, web: Request) { + const verify = yield* makeVerifier(Redacted.make(secret)) + const events: Array = [] + const response = yield* handleRequest(HttpServerRequest.fromWeb(web), { + verify, + appId, + teamId: team, + botUserId: Effect.succeed(botUserId), + handle: (event) => Effect.sync(() => void events.push(event)), + deadline: Duration.seconds(2), + maxBodyBytes: 1024 * 1024, + ...options + }) + return { status: response.status, response, events } +}) + +describe("webhook", () => { + it.live("a signed event reaches the handler", () => + Effect.gen(function*() { + const result = yield* handle({}, yield* Effect.promise(() => request(JSON.stringify(message)))) + assert.strictEqual(result.status, 200) + assert.strictEqual(result.events.length, 1) + assert.strictEqual(result.events[0]._tag, "MessageCreated") + })) + + it.live("rejects a bad or stale signature", () => + Effect.gen(function*() { + const body = JSON.stringify(message) + const wrongKey = yield* handle({}, yield* Effect.promise(() => request(body, { key: "other" }))) + assert.strictEqual(wrongKey.status, 401) + const stale = String(Math.floor(Date.now() / 1000) - 6 * 60) + const old = yield* handle({}, yield* Effect.promise(() => request(body, { timestamp: stale }))) + assert.strictEqual(old.status, 401) + const unsigned = yield* handle({}, new Request("http://localhost/", { method: "POST", body })) + assert.strictEqual(unsigned.status, 401) + assert.strictEqual(wrongKey.events.length + old.events.length + unsigned.events.length, 0) + })) + + it.live("413 past the body limit, 400 for a body that is not JSON", () => + Effect.gen(function*() { + const big = yield* handle({ maxBodyBytes: 100 }, yield* Effect.promise(() => request("x".repeat(101)))) + assert.strictEqual(big.status, 413) + const notJson = yield* handle({}, yield* Effect.promise(() => request("not json"))) + assert.strictEqual(notJson.status, 400) + })) + + it.live("answers url_verification with its challenge", () => + Effect.gen(function*() { + const body = JSON.stringify({ + token: "t", + challenge: "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P", + type: "url_verification" + }) + const result = yield* handle({}, yield* Effect.promise(() => request(body))) + assert.strictEqual(result.status, 200) + const web = HttpServerResponse.toWeb(result.response) + assert.strictEqual( + yield* Effect.promise(() => web.text()), + "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P" + ) + })) + + it.live("drops another app's event with 200", () => + Effect.gen(function*() { + const result = yield* handle( + {}, + yield* Effect.promise(() => request(JSON.stringify({ ...message, api_app_id: "A0OTHER" }))) + ) + assert.strictEqual(result.status, 200) + assert.strictEqual(result.events.length, 0) + })) + + it.live("503 so Slack retries: no bot user, NotAccepted, past the deadline", () => + Effect.gen(function*() { + const body = JSON.stringify(message) + const noBot = yield* handle( + { botUserId: Effect.fail(unavailable) }, + yield* Effect.promise(() => request(body)) + ) + assert.strictEqual(noBot.status, 503) + assert.strictEqual(noBot.events.length, 0) + const refused = yield* handle( + { handle: () => Effect.fail(new NotAccepted()) }, + yield* Effect.promise(() => request(body)) + ) + assert.strictEqual(refused.status, 503) + const slow = yield* handle( + { handle: () => Effect.never, deadline: Duration.millis(20) }, + yield* Effect.promise(() => request(body)) + ) + assert.strictEqual(slow.status, 503) + })) + + it.live("layerWebhook serves the path", () => + Effect.gen(function*() { + const fake = makeFake({ "auth.test": authTest }) + const events: Array = [] + const app = SlackChat.layerWebhook({ path: "/slack/events", signingSecret: Redacted.make(secret), appId }).pipe( + Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })), + Layer.provide(Chat.layer), + Layer.provide(Layer.succeed(ChatHandler, { handle: (event) => Effect.sync(() => void events.push(event)) })), + Layer.provide(fake.layer) + ) + const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true }) + const response = yield* Effect.promise(() => request(JSON.stringify(message)).then((web) => handler(web))) + yield* Effect.promise(() => dispose()) + assert.strictEqual(response.status, 200) + assert.strictEqual(events.length, 1) + assert.strictEqual(fake.called("auth.test").length, 1) + })) +}) diff --git a/packages/chat/slack/tsconfig.json b/packages/chat/slack/tsconfig.json new file mode 100644 index 00000000000..e2a8ca19a0d --- /dev/null +++ b/packages/chat/slack/tsconfig.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "../../../tsconfig.base.json", + "include": ["src"], + "references": [ + { "path": "../../effect" } + ] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bebfa46784d..5ba69df20fb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -348,6 +348,12 @@ importers: specifier: ^3.5.45 version: 3.5.45(typescript@7.0.2) + packages/chat/slack: + devDependencies: + effect: + specifier: workspace:^ + version: link:../../effect + packages/effect: devDependencies: '@types/node': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index b36f0d6155d..83cd9417dba 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -5,6 +5,7 @@ packages: - packages/* - packages/ai/* - packages/atom/* + - packages/chat/* - packages/platform/* - packages/sql/* - packages/tools/* diff --git a/scripts/circular.mjs b/scripts/circular.mjs index 39fead0e60c..300792d0704 100644 --- a/scripts/circular.mjs +++ b/scripts/circular.mjs @@ -3,7 +3,7 @@ import * as glob from "glob" import madge from "madge" madge( - glob.globSync(["packages/*/src/**/*.ts", "packages/ai/*/src/**/*.ts", "packages/platform/*/src/**/*.ts"], { + glob.globSync(["packages/*/src/**/*.ts", "packages/ai/*/src/**/*.ts", "packages/chat/*/src/**/*.ts", "packages/platform/*/src/**/*.ts"], { ignore: [ "packages/sql-sqlite-bun/**", "packages/experimental/src/EventLogServer/Cloudflare.ts" diff --git a/scripts/clean.mjs b/scripts/clean.mjs index aad0b637ebc..ad0de4ad0bf 100644 --- a/scripts/clean.mjs +++ b/scripts/clean.mjs @@ -1,7 +1,7 @@ import * as Glob from "glob" import * as Fs from "node:fs" -const dirs = [".", ...Glob.sync("packages/*/"), ...Glob.sync("packages/sql/*/"), ...Glob.sync("packages/tools/*/"), ...Glob.sync("packages/ai/*/"), ...Glob.sync("packages/atom/*/"), ...Glob.sync("packages/platform/*/")] +const dirs = [".", ...Glob.sync("packages/*/"), ...Glob.sync("packages/sql/*/"), ...Glob.sync("packages/tools/*/"), ...Glob.sync("packages/ai/*/"), ...Glob.sync("packages/atom/*/"), ...Glob.sync("packages/chat/*/"), ...Glob.sync("packages/platform/*/")] dirs.forEach((pkg) => { const files = [".tsbuildinfo", "tsconfig.tsbuildinfo", "tsconfig.fixtures.tsbuildinfo", "tsconfig.src.tsbuildinfo", "docs", "build", "dist", "coverage"] if (pkg !== ".") { diff --git a/tsconfig.packages.json b/tsconfig.packages.json index e92c8e8fa6b..787dd90fd5f 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -13,6 +13,7 @@ { "path": "packages/ai/typesafe" }, { "path": "packages/ai/openrouter" }, { "path": "packages/atom/react" }, + { "path": "packages/chat/slack" }, { "path": "packages/atom/vue" }, { "path": "packages/atom/solid" }, { "path": "packages/opentelemetry" }, diff --git a/tsconfig.tests.json b/tsconfig.tests.json index 494126e37f6..17445c56e52 100644 --- a/tsconfig.tests.json +++ b/tsconfig.tests.json @@ -54,6 +54,8 @@ "@effect/ai-typesafe/*": ["./packages/ai/typesafe/src/*.ts"], "@effect/ai-openrouter": ["./packages/ai/openrouter/src/index.ts"], "@effect/ai-openrouter/*": ["./packages/ai/openrouter/src/*.ts"], + "@effect/chat-slack": ["./packages/chat/slack/src/index.ts"], + "@effect/chat-slack/*": ["./packages/chat/slack/src/*.ts"], "@effect/atom-react": ["./packages/atom/react/src/index.ts"], "@effect/atom-react/*": ["./packages/atom/react/src/*.ts"], "@effect/atom-vue": ["./packages/atom/vue/src/index.ts"], diff --git a/vitest.config.ts b/vitest.config.ts index 5a19ae900fc..150dfea01b6 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -133,6 +133,7 @@ export default defineConfig({ ...project("@effect/ai-typesafe", "packages/ai/typesafe"), ...project("@effect/ai-openai-compat", "packages/ai/openai-compat"), ...project("@effect/ai-openrouter", "packages/ai/openrouter"), + ...project("@effect/chat-slack", "packages/chat/slack"), ...project("@effect/atom-react", "packages/atom/react", true, { test: { environment: "jsdom", From 9eeed748e3de36451c8f04b8dfbfba9ac67756f7 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 19:22:38 +0000 Subject: [PATCH 11/89] Pace a Slack message's writes after a 429 After a 429 on a stream append or an edit, the next write to that message waits for the retry-after, and later writes to it wait twice the interval. --- packages/chat/slack/src/SlackChat.ts | 3 + packages/chat/slack/src/internal/adapter.ts | 78 ++++++++++++++++++--- packages/chat/slack/test/SlackChat.test.ts | 33 +++++++++ 3 files changed, 105 insertions(+), 9 deletions(-) diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts index 16775eba2ef..f8a2fe37217 100644 --- a/packages/chat/slack/src/SlackChat.ts +++ b/packages/chat/slack/src/SlackChat.ts @@ -109,6 +109,9 @@ export class SlackChat extends Context.Service Effect.fail(Errors.chatError(op, reason)) + /** + * Writes that grow one message: stream appends and edits. After a 429 on + * a message, its next write waits for the retry-after, and each later + * write waits twice the interval it waited before, for as long as the + * reply goes on. + */ + const paces = new Map() + const paced =
(messageId: string, write: Effect.Effect): Effect.Effect => + Effect.gen(function*() { + const pace = paces.get(messageId) + if (pace !== undefined) { + const wait = pace.nextAt - (yield* Clock.currentTimeMillis) + if (wait > 0) yield* Effect.sleep(Duration.millis(wait)) + } + return yield* write.pipe( + Effect.tap(() => + Effect.map(Clock.currentTimeMillis, (now) => { + const current = paces.get(messageId) + if (current !== undefined) paces.set(messageId, { ...current, nextAt: now + current.intervalMillis }) + }) + ), + Effect.tapError((error) => + error.reason._tag !== "RateLimited" ? Effect.void : Effect.map(Clock.currentTimeMillis, (now) => { + for (const [id, old] of paces) if (old.nextAt < now - paceIdleMillis) paces.delete(id) + const intervalMillis = 2 * (paces.get(messageId)?.intervalMillis ?? + Duration.toMillis(descriptor.limits.minWriteInterval)) + const retryAfter = error.retryAfter + paces.set(messageId, { + intervalMillis, + nextAt: now + (retryAfter === undefined ? intervalMillis : Duration.toMillis(retryAfter)) + }) + }) + ) + ) + }) + const call = ( op: string, method: string, @@ -379,11 +431,14 @@ export const make = (options: { const held = markdown.length - escaped.consumed if (escaped.sent === "") return { state: "open" as const, held } yield* checkSent(op, state.text + escaped.sent, true) - return yield* call(op, "chat.appendStream", { - channel: parts.channel, - ts: messageId, - markdown_text: escaped.sent - }, { write: true, retry: false }).pipe( + return yield* paced( + messageId, + call(op, "chat.appendStream", { + channel: parts.channel, + ts: messageId, + markdown_text: escaped.sent + }, { write: true, retry: false }) + ).pipe( Effect.map(() => { streams.set(messageId, { escape: escaped.state, text: state.text + escaped.sent, stopped: false }) return { state: "open" as const, held } @@ -405,6 +460,7 @@ export const make = (options: { const postOptions = yield* CurrentPostOptions const state = streams.get(messageId) streams.delete(messageId) + paces.delete(messageId) const status = stopOptions.end === "rotating" ? "processing" : postOptions.sessionStatusAtEnd const body = { channel: parts.channel, ts: messageId } const stop = status === undefined || !declaredAgent @@ -492,9 +548,13 @@ export const make = (options: { const sent = Escape.escape(content.markdown, postOptions.notify ?? {}, { flush: true }).sent // Slack does not apply its emoji limit to `chat.update`. yield* checkSent("edit", sent, false) - yield* call("edit", "chat.update", { channel: parts.channel, ts: messageId, markdown_text: sent }, { - write: true - }) + yield* retrySafe(paced( + messageId, + call("edit", "chat.update", { channel: parts.channel, ts: messageId, markdown_text: sent }, { + write: true, + retry: false + }) + )) }), delete: Effect.fnUntraced(function*(thread, messageId) { const parts = yield* resolve("delete", thread) diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts index db8ed5aa6e4..6860fa38ef0 100644 --- a/packages/chat/slack/test/SlackChat.test.ts +++ b/packages/chat/slack/test/SlackChat.test.ts @@ -439,6 +439,39 @@ describe("nativeStream", () => { ) }) + it.effect("a 429 waits the retry-after, then doubles the interval for that message", () => { + const fake = makeFake({ + "chat.appendStream": [{ status: 429, headers: { "retry-after": "3" } }, posted(ts)], + "chat.update": posted("1794509200.000100") + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const native = slack.nativeStream! + const limited = yield* reason(native.append(replyThread, ts, "a", { flush: true })) + assert.strictEqual(limited.tag, "RateLimited") + const appends = () => fake.called("chat.appendStream").length + const second = yield* Effect.forkChild(native.append(replyThread, ts, "b", { flush: true })) + yield* TestClock.adjust("2999 millis") + assert.strictEqual(appends(), 1) + yield* TestClock.adjust("1 millis") + yield* Fiber.join(second) + assert.strictEqual(appends(), 2) + // Two seconds now, twice the one second interval. + const third = yield* Effect.forkChild(native.append(replyThread, ts, "c", { flush: true })) + yield* TestClock.adjust("1999 millis") + assert.strictEqual(appends(), 2) + yield* TestClock.adjust("1 millis") + yield* Fiber.join(third) + assert.strictEqual(appends(), 3) + // Another message is not slowed. + yield* slack.edit(replyThread, "1794509200.000100", { markdown: "x" }) + assert.strictEqual(fake.called("chat.update").length, 1) + }) + ) + }) + it.effect("stop on a closed stream succeeds", () => { const fake = makeFake({ "chat.stopStream": { ok: false, error: "message_not_in_streaming_state" } }) return run( From ceabd05a46e5ffdd2f7b8df1c3ca9ad917e38511 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 19:42:26 +0000 Subject: [PATCH 12/89] Fix @effect/chat-slack review findings - Leave Slack's emoji-as-shortcode limit to Slack. The preflight counted `<` as four characters and refused text Slack accepts. - A failed files.info after the share is an uncertain post (Unknown), never a refusal or a retryable error. - The webhook deadline covers the bot user lookup. - Mentions come only from the rich_text block's real elements. Tokens are aligned with the block's items, and text never adds a mention. - A 429's doubled interval carries over a stream rotation to the reply's next part. - Edits to one message are at least 3 seconds apart, the spec's starting number. --- packages/chat/slack/src/SlackChat.ts | 16 ++- packages/chat/slack/src/internal/adapter.ts | 144 ++++++++++++++----- packages/chat/slack/src/internal/mentions.ts | 96 ++++++++++--- packages/chat/slack/src/internal/webhook.ts | 18 ++- packages/chat/slack/test/SlackChat.test.ts | 115 ++++++++++++++- packages/chat/slack/test/normalize.test.ts | 46 ++++++ packages/chat/slack/test/webhook.test.ts | 7 + 7 files changed, 370 insertions(+), 72 deletions(-) diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts index f8a2fe37217..7220cd9f911 100644 --- a/packages/chat/slack/src/SlackChat.ts +++ b/packages/chat/slack/src/SlackChat.ts @@ -98,9 +98,11 @@ export class SlackChat extends Context.Service Option.Option<{ * - An envelope for another app, another workspace or of another type is * answered 200 and dropped. * - The events go through `normalize` to the `ChatHandler`, one at a time. - * - Answers 503, so Slack retries, when the handler fails `NotAccepted` or - * runs past `deadline` (2.5 seconds by default), and 413 past + * - Answers 503, so Slack retries, when the handler fails `NotAccepted`, or + * when reading the bot user and running the handler take longer than + * `deadline` (2.5 seconds by default). Answers 413 past * `maxBodyBytes` (1 MiB by default). * - Slack redelivers on a timeout or an error, so an event can arrive twice. * `ChatEvent.dedupeKey` gives the two deliveries equal keys. diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts index feb9705b310..422ba5c2249 100644 --- a/packages/chat/slack/src/internal/adapter.ts +++ b/packages/chat/slack/src/internal/adapter.ts @@ -17,6 +17,7 @@ import type * as HttpClient from "effect/http/HttpClient" import * as HttpClientRequest from "effect/http/HttpClientRequest" import * as Option from "effect/Option" import * as Redacted from "effect/Redacted" +import * as Result from "effect/Result" import type * as Schema from "effect/Schema" import * as Stream from "effect/Stream" import * as Address from "./address.ts" @@ -99,6 +100,9 @@ const shareInterval = Duration.millis(500) /** Codes on `chat.startStream` that mean the feature is off for this thread. */ const streamUnsupported = new Set(["channel_type_not_supported", "feature_disabled", "not_allowed_token_type"]) +/** Floor between two edits to one message: the spec's starting number, provisional until measured. */ +const editIntervalMillis = 3_000 + /** How long a message's pace is kept after its last write. */ const paceIdleMillis = 15 * 60 * 1000 @@ -136,41 +140,74 @@ export const make = (options: { const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason)) /** - * Writes that grow one message: stream appends and edits. After a 429 on - * a message, its next write waits for the retry-after, and each later - * write waits twice the interval it waited before, for as long as the - * reply goes on. + * The pace of the writes that grow one reply: stream appends, stream + * starts after a rotation, and edits. + * + * - Edits to one message are at least `editIntervalMillis` apart. + * - After a 429, the next write waits for the retry-after, and each later + * write waits twice the interval it waited before, for the rest of the + * reply. A stream stopped with `end: "rotating"` hands its pace to the + * next stream started in that thread, the reply's next part. */ const paces = new Map() - const paced = (messageId: string, write: Effect.Effect): Effect.Effect => + const rotated = new Map() + + const remember = (map: Map, key: string, pace: Pace, now: number) => { + if (map.size >= 64) { for (const [old, value] of map) if (value.nextAt < now - paceIdleMillis) map.delete(old) } + map.set(key, pace) + } + + const paced = ( + options: { + /** The pace this write waits for. */ + readonly current: Pace | undefined + /** The interval doubled by a first 429. */ + readonly baseMillis: number + /** Kept between two writes even without a 429. */ + readonly floorMillis?: number | undefined + readonly save: (pace: Pace, now: number) => void + }, + write: Effect.Effect + ): Effect.Effect => Effect.gen(function*() { - const pace = paces.get(messageId) - if (pace !== undefined) { - const wait = pace.nextAt - (yield* Clock.currentTimeMillis) + const { current } = options + if (current !== undefined) { + const wait = current.nextAt - (yield* Clock.currentTimeMillis) if (wait > 0) yield* Effect.sleep(Duration.millis(wait)) } return yield* write.pipe( Effect.tap(() => Effect.map(Clock.currentTimeMillis, (now) => { - const current = paces.get(messageId) - if (current !== undefined) paces.set(messageId, { ...current, nextAt: now + current.intervalMillis }) + const intervalMillis = current?.intervalMillis ?? options.floorMillis + if (intervalMillis !== undefined) options.save({ intervalMillis, nextAt: now + intervalMillis }, now) }) ), Effect.tapError((error) => error.reason._tag !== "RateLimited" ? Effect.void : Effect.map(Clock.currentTimeMillis, (now) => { - for (const [id, old] of paces) if (old.nextAt < now - paceIdleMillis) paces.delete(id) - const intervalMillis = 2 * (paces.get(messageId)?.intervalMillis ?? - Duration.toMillis(descriptor.limits.minWriteInterval)) + const intervalMillis = 2 * + (current?.intervalMillis ?? Math.max(options.baseMillis, options.floorMillis ?? 0)) const retryAfter = error.retryAfter - paces.set(messageId, { + options.save({ intervalMillis, nextAt: now + (retryAfter === undefined ? intervalMillis : Duration.toMillis(retryAfter)) - }) + }, now) }) ) ) }) + const pacedMessage = ( + messageId: string, + write: Effect.Effect, + floorMillis?: number + ): Effect.Effect => + paced({ + current: paces.get(messageId), + baseMillis: Duration.toMillis(descriptor.limits.minWriteInterval), + floorMillis, + save: (pace, now) => remember(paces, messageId, pace, now) + }, write) + const call = ( op: string, method: string, @@ -190,15 +227,17 @@ export const make = (options: { return ts === undefined ? fail(op, Errors.invalidResponse(write, "missing_ts")) : Effect.succeed(ts) } - const checkSent = (op: string, sent: string, emoji: boolean): Effect.Effect => { - if (Length.codePoints(sent) > Length.messageLength) { - return fail(op, new TooLarge({ subject: "text", detail: "msg_too_long" })) - } - if (emoji && Length.blocksCost(sent) > Length.blocksLength) { - return fail(op, new TooLarge({ subject: "text", detail: "msg_blocks_too_long" })) - } - return Effect.void - } + /** + * Refuses text past 12,000 code points as sent, which Slack would refuse + * with `msg_too_long`. Slack's second count, with emoji as shortcodes, is + * left to Slack: `measure` only bounds it from above, because entities, + * code and Markdown markers render shorter than they are sent. Its refusal + * maps to `TooLarge` and leaves nothing behind. + */ + const checkSent = (op: string, sent: string): Effect.Effect => + Length.codePoints(sent) > Length.messageLength + ? fail(op, new TooLarge({ subject: "text", detail: "msg_too_long" })) + : Effect.void const messages = (answer: Json): ReadonlyArray => isObject(answer) && Array.isArray(answer.messages) ? answer.messages : [] @@ -305,7 +344,7 @@ export const make = (options: { } // A message with files takes no `markdown_text`: its text goes as mrkdwn. const comment = markdown.trim() === "" ? undefined : Escape.toMrkdwn(markdown, notify) - if (comment !== undefined) yield* checkSent("post", comment, true) + if (comment !== undefined) yield* checkSent("post", comment) const staged = yield* Effect.forEach(files, stage) yield* call("post", "files.completeUploadExternal", { files: staged, @@ -314,13 +353,24 @@ export const make = (options: { initial_comment: comment }, { write: true }) // The answer carries no message ts. Slack fills the file's shares soon after. + // The message exists from here on, so not finding its ts is an + // uncertain outcome, never a refusal or a retryable failure. + let lastError: ChatError | undefined for (let attempt = 0; attempt < shareAttempts; attempt++) { if (attempt > 0) yield* Effect.sleep(shareInterval) - const info = yield* call("post", "files.info", { file: staged[0].id }) - const ts = shareTs(info, parts.channel, parts.threadTs) + const info = yield* Effect.result(call("post", "files.info", { file: staged[0].id })) + if (Result.isFailure(info)) { + lastError = info.failure + if (lastError.reason.retry === "denied") break + continue + } + const ts = shareTs(info.success, parts.channel, parts.threadTs) if (ts !== undefined) return { id: ts, thread, timestamp: Normalize.timestamp(ts) } } - return yield* fail("post", new Unknown({ detail: "share_ts_unknown" })) + return yield* fail( + "post", + new Unknown({ detail: "share_ts_unknown", ...(lastError === undefined ? {} : { cause: lastError }) }) + ) }) // History @@ -394,8 +444,12 @@ export const make = (options: { return yield* fail(op, new Unsupported({ capability: "nativeStream" })) } const escaped = Escape.escape(start.markdown, postOptions.notify ?? {}, { flush: true }) - yield* checkSent(op, escaped.sent, true) - const answer = yield* call(op, "chat.startStream", { + yield* checkSent(op, escaped.sent) + const replyKey = `${parts.channel}/${parts.threadTs}` + const handedOver = rotated.get(replyKey) + rotated.delete(replyKey) + let pace = handedOver + const startCall = call(op, "chat.startStream", { channel: parts.channel, thread_ts: parts.threadTs, recipient_user_id: start.recipient, @@ -415,7 +469,19 @@ export const make = (options: { ) ) ) + const answer = yield* (handedOver === undefined ? startCall : paced({ + current: handedOver, + baseMillis: handedOver.intervalMillis, + save: (next) => { + pace = next + } + }, startCall)).pipe(Effect.tapError(() => + Effect.map(Clock.currentTimeMillis, (now) => { + if (pace !== undefined) remember(rotated, replyKey, pace, now) + }) + )) const ts = yield* tsOf(op, true)(answer) + if (pace !== undefined) remember(paces, ts, pace, yield* Clock.currentTimeMillis) streams.set(ts, { escape: escaped.state, text: escaped.sent, stopped: false }) return { id: ts, thread, timestamp: Normalize.timestamp(ts) } }), @@ -430,8 +496,8 @@ export const make = (options: { }) const held = markdown.length - escaped.consumed if (escaped.sent === "") return { state: "open" as const, held } - yield* checkSent(op, state.text + escaped.sent, true) - return yield* paced( + yield* checkSent(op, state.text + escaped.sent) + return yield* pacedMessage( messageId, call(op, "chat.appendStream", { channel: parts.channel, @@ -460,7 +526,11 @@ export const make = (options: { const postOptions = yield* CurrentPostOptions const state = streams.get(messageId) streams.delete(messageId) + const pace = paces.get(messageId) paces.delete(messageId) + if (pace !== undefined && stopOptions.end === "rotating") { + remember(rotated, `${parts.channel}/${parts.threadTs}`, pace, yield* Clock.currentTimeMillis) + } const status = stopOptions.end === "rotating" ? "processing" : postOptions.sessionStatusAtEnd const body = { channel: parts.channel, ts: messageId } const stop = status === undefined || !declaredAgent @@ -531,7 +601,7 @@ export const make = (options: { return yield* postFiles(thread, parts, content.markdown, content.files, notify) } const sent = Escape.escape(content.markdown, notify, { flush: true }).sent - yield* checkSent("post", sent, true) + yield* checkSent("post", sent) const unfurl = postOptions.unfurl === true const ts = yield* call("post", "chat.postMessage", { channel: parts.channel, @@ -546,14 +616,14 @@ export const make = (options: { const parts = yield* resolve("edit", thread) const postOptions = yield* CurrentPostOptions const sent = Escape.escape(content.markdown, postOptions.notify ?? {}, { flush: true }).sent - // Slack does not apply its emoji limit to `chat.update`. - yield* checkSent("edit", sent, false) - yield* retrySafe(paced( + yield* checkSent("edit", sent) + yield* retrySafe(pacedMessage( messageId, call("edit", "chat.update", { channel: parts.channel, ts: messageId, markdown_text: sent }, { write: true, retry: false - }) + }), + editIntervalMillis )) }), delete: Effect.fnUntraced(function*(thread, messageId) { diff --git a/packages/chat/slack/src/internal/mentions.ts b/packages/chat/slack/src/internal/mentions.ts index 89e9d5a0ab4..55024ddcbfa 100644 --- a/packages/chat/slack/src/internal/mentions.ts +++ b/packages/chat/slack/src/internal/mentions.ts @@ -119,14 +119,69 @@ const richTextItems = (blocks: unknown): Array | undefined => { return items } +const sameTarget = (a: Target, b: Target): boolean => a.kind === b.kind && a.id === b.id + +/** Past this many item and token pairs, the alignment is skipped for the fallback. */ +const maxAlignment = 1_000_000 + +/** + * Aligns the tokens in `text` with the block's items, in order. Every real + * item takes a token it equals, a literal item may take one or be passed + * over, and a token may stand for no item. Of the alignments, the one that + * pairs the most items wins, the earliest pairing first. Gives the token + * index of each real item, or `undefined` when no alignment pairs them all. + */ +const align = (items: ReadonlyArray, found: ReadonlyArray): Array | undefined => { + const n = items.length + const m = found.length + if ((n + 1) * (m + 1) > maxAlignment) return undefined + const impossible = -1 + const width = m + 1 + // best[i * width + j]: the most pairs for items i.. and tokens j.., or impossible. + const best = new Int32Array((n + 1) * width) + for (let i = n - 1; i >= 0; i--) { + best[i * width + m] = items[i].real ? impossible : 0 + } + for (let i = n - 1; i >= 0; i--) { + for (let j = m - 1; j >= 0; j--) { + let score = best[i * width + j + 1] + if (!items[i].real) score = Math.max(score, best[(i + 1) * width + j]) + if (sameTarget(items[i], found[j])) { + const rest = best[(i + 1) * width + j + 1] + if (rest !== impossible) score = Math.max(score, rest + 1) + } + best[i * width + j] = score + } + } + if (best[0] === impossible) return undefined + const out: Array = [] + let i = 0 + let j = 0 + while (i < n) { + const score = best[i * width + j] + const rest = j < m ? best[(i + 1) * width + j + 1] : impossible + if (j < m && sameTarget(items[i], found[j]) && rest !== impossible && rest + 1 === score) { + if (items[i].real) out.push(j) + i++ + j++ + } else if (!items[i].real && best[(i + 1) * width + j] === score) { + i++ + } else { + j++ + } + } + return out +} + /** * The mentions of a message with offsets into `text`. * - * - With a `rich_text` block, the mentions are its real mention elements. - * The tokens in `text` are walked in order against the block's items: a - * token takes the next item it equals, and only a real item makes it a - * mention. When a real item is passed over without a token, the text scan - * below is used instead. + * - With a `rich_text` block, the mentions are exactly its real mention + * elements. Their offsets come from aligning the tokens in `text` with the + * block's items, in order. When no alignment places every real item, + * because `text` has fewer occurrences of a token than the block, each + * real item takes the next unused token it equals, and one with none left + * is reported nowhere. `text` never adds a mention. * - Without one, `text` is scanned, skipping backtick code spans and fences. * That covers Block Kit posts, attachment-only posts and system messages. * @@ -145,20 +200,21 @@ export const extract = ( isSelf: token.kind === "user" && token.id === botUserId }) const items = richTextItems(blocks) - if (items !== undefined) { - const matched: Array = [] - let next = 0 - let complete = true - for (const token of tokens(text, false)) { - let found = next - while (found < items.length && !(items[found].kind === token.kind && items[found].id === token.id)) found++ - if (found === items.length) continue - if (items.slice(next, found).some((item) => item.real)) complete = false - if (items[found].real) matched.push(toMention(token)) - next = found + 1 - } - if (items.slice(next).some((item) => item.real)) complete = false - if (complete) return matched + if (items === undefined) return tokens(text, true).map(toMention) + const found = tokens(text, false) + const aligned = align(items, found) + if (aligned !== undefined) return aligned.map((index) => toMention(found[index])) + const used = new Set() + const mentions: Array = [] + let from = 0 + for (const item of items) { + if (!item.real) continue + let index = found.findIndex((token, k) => k >= from && !used.has(k) && sameTarget(item, token)) + if (index < 0) index = found.findIndex((token, k) => !used.has(k) && sameTarget(item, token)) + if (index < 0) continue + used.add(index) + from = index + 1 + mentions.push(toMention(found[index])) } - return tokens(text, true).map(toMention) + return mentions.sort((x, y) => x.start - y.start) } diff --git a/packages/chat/slack/src/internal/webhook.ts b/packages/chat/slack/src/internal/webhook.ts index a253a8e6a7f..53dfae7d16f 100644 --- a/packages/chat/slack/src/internal/webhook.ts +++ b/packages/chat/slack/src/internal/webhook.ts @@ -120,7 +120,8 @@ export interface Options { * - An envelope for another app or workspace, or of another type, is * answered 200 and dropped, so Slack does not retry it. * - 503 when the bot user can't be read, the handler fails `NotAccepted`, - * or the handler runs past the deadline. Slack then retries. + * or reading the bot user and running the handler take longer than the + * deadline. Slack then retries. * * @internal */ @@ -145,12 +146,17 @@ export const handleRequest = ( : status(400) } if (envelope.type !== "event_callback" || envelope.api_app_id !== options.appId) return ok - const botUserId = yield* Effect.option(options.botUserId) - if (Option.isNone(botUserId)) return status(503) - const events = normalize(envelope, { teamId: options.teamId, botUserId: botUserId.value }) - const handled = yield* Effect.forEach(events, options.handle, { discard: true }).pipe( + const callback = envelope + // The deadline covers the bot user lookup as well as the handlers. + const handled = yield* Effect.gen(function*() { + const botUserId = yield* Effect.option(options.botUserId) + if (Option.isNone(botUserId)) return false + const events = normalize(callback, { teamId: options.teamId, botUserId: botUserId.value }) + yield* Effect.forEach(events, options.handle, { discard: true }) + return true + }).pipe( Effect.timeoutOption(options.deadline), - Effect.map(Option.isSome), + Effect.map((done) => Option.isSome(done) && done.value), Effect.catchTag("NotAccepted", () => Effect.succeed(false)) ) return handled ? ok : status(503) diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts index 6860fa38ef0..74468c618b0 100644 --- a/packages/chat/slack/test/SlackChat.test.ts +++ b/packages/chat/slack/test/SlackChat.test.ts @@ -75,9 +75,7 @@ describe("post", () => { const cases = [ "a".repeat(12_001), // 3,001 `<` are 12,004 once escaped. - "<".repeat(3_001), - // 1,400 😀 are 1,400 code points but 14,000 with shortcodes. - "😀".repeat(1_400) + "<".repeat(3_001) ] for (const markdown of cases) { const failure = yield* reason(slack.post(channelThread, { markdown })) @@ -90,6 +88,26 @@ describe("post", () => { ) }) + it.effect("leaves the emoji count to Slack", () => { + const fake = makeFake({ + "chat.postMessage": [posted("1794509200.000100"), { ok: false, error: "msg_blocks_too_long" }] + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + // 14,000 if `<` cost 4, 11,000 as Slack counts it. + const markdown = "😀".repeat(1_000) + "<".repeat(1_000) + assert.isAtMost(slack.descriptor.measure(markdown), slack.descriptor.limits.messageLength) + yield* slack.post(channelThread, { markdown }) + // 1,400 😀 are 14,000 with shortcodes: Slack refuses, nothing is posted. + const failure = yield* reason(slack.post(channelThread, { markdown: "😀".repeat(1_400) })) + assert.deepStrictEqual(failure, { op: "post", tag: "TooLarge", detail: "msg_blocks_too_long", retry: "denied" }) + assert.strictEqual(fake.called("chat.postMessage").length, 2) + }) + ) + }) + it.effect("edit skips the emoji limit", () => { const fake = makeFake({ "chat.update": { ok: true } }) return run( @@ -147,6 +165,43 @@ describe("post", () => { }) }) +describe("files", () => { + const upload = { + "files.getUploadURLExternal": { ok: true, upload_url: "https://files.slack.test/upload/1", file_id: "F1" }, + "files.completeUploadExternal": { ok: true, files: [{ id: "F1" }] } + } + const file = { name: "a.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") } + + it.effect("a refused read after the share is an uncertain post, not a refusal", () => { + const fake = makeFake({ ...upload, "files.info": { ok: false, error: "missing_scope" } }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const failure = yield* reason(slack.post(replyThread, { markdown: "see", files: [file] })) + assert.deepStrictEqual(failure, { op: "post", tag: "Unknown", detail: "share_ts_unknown", retry: "uncertain" }) + assert.strictEqual(fake.called("files.info").length, 1) + }) + ) + }) + + it.effect("a failing read after the share is polled again, then uncertain", () => { + const fake = makeFake({ ...upload, "files.info": { status: 500 } }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const result = yield* Effect.forkChild(reason(slack.post(replyThread, { markdown: "see", files: [file] }))) + yield* TestClock.adjust("10 minutes") + const failure = yield* Fiber.join(result) + assert.strictEqual(failure.tag, "Unknown") + assert.strictEqual(failure.retry, "uncertain") + assert.isAbove(fake.called("files.info").length, 1) + }) + ) + }) +}) + describe("errors", () => { it.effect("maps Slack's codes", () => { const fake = makeFake({ @@ -472,6 +527,60 @@ describe("nativeStream", () => { ) }) + it.effect("the doubled interval outlives a rotation of the reply", () => { + const next = "1794509201.000100" + const fake = makeFake({ + "chat.appendStream": [{ status: 429, headers: { "retry-after": "3" } }, posted(ts), posted(next)], + "chat.stopStream": { ok: true, message: { ts } }, + "chat.startStream": posted(next) + }) + return run( + fake, + Effect.gen(function*() { + const native = (yield* adapter).nativeStream! + assert.strictEqual((yield* reason(native.append(replyThread, ts, "a", { flush: true }))).tag, "RateLimited") + yield* native.stop(replyThread, ts, { end: "rotating" }) + // The next part's start waits for the retry-after. + const start = yield* Effect.forkChild(native.start(replyThread, { markdown: "b", recipient: "U080YLYB277" })) + yield* TestClock.adjust("2999 millis") + assert.strictEqual(fake.called("chat.startStream").length, 0) + yield* TestClock.adjust("1 millis") + yield* Fiber.join(start) + // Its appends keep the doubled interval, two seconds. + const append = yield* Effect.forkChild(native.append(replyThread, next, "c", { flush: true })) + yield* TestClock.adjust("1999 millis") + assert.strictEqual(fake.called("chat.appendStream").length, 1) + yield* TestClock.adjust("1 millis") + yield* Fiber.join(append) + assert.strictEqual(fake.called("chat.appendStream").length, 2) + // A reply that ends hands nothing on. + yield* native.stop(replyThread, next, { end: "done" }) + yield* native.start(replyThread, { markdown: "d", recipient: "U080YLYB277" }) + assert.strictEqual(fake.called("chat.startStream").length, 2) + }) + ) + }) + + it.effect("edits to one message are three seconds apart", () => { + const other = "1794509200.000200" + const fake = makeFake({ "chat.update": { ok: true } }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + yield* slack.edit(replyThread, ts, { markdown: "a" }) + const second = yield* Effect.forkChild(slack.edit(replyThread, ts, { markdown: "ab" })) + // Another message is not held back. + yield* slack.edit(replyThread, other, { markdown: "x" }) + yield* TestClock.adjust("2999 millis") + assert.strictEqual(fake.called("chat.update").length, 2) + yield* TestClock.adjust("1 millis") + yield* Fiber.join(second) + assert.strictEqual(fake.called("chat.update").length, 3) + }) + ) + }) + it.effect("stop on a closed stream succeeds", () => { const fake = makeFake({ "chat.stopStream": { ok: false, error: "message_not_in_streaming_state" } }) return run( diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts index 03ae9d17633..3f120f39306 100644 --- a/packages/chat/slack/test/normalize.test.ts +++ b/packages/chat/slack/test/normalize.test.ts @@ -96,6 +96,52 @@ describe("normalize", () => { assert.isFalse(event.message.author.isSelf) })) + it.effect("text never adds a mention the rich_text block lacks", () => + Effect.gen(function*() { + const section = ( + elements: Array + ) => [{ type: "rich_text", elements: [{ type: "rich_text_section", elements }] }] + // Block items: literal U1, real U1, real U2, literal bot. + const event = created(SlackChat.normalize( + messageEnvelope({ + ts: "1794509003.000002", + user: "U080YLYB277", + text: `<@U1AAAA> <@U2BBBB> <@${botUserId}>`, + blocks: section([ + { type: "text", text: "<@U1AAAA>" }, + { type: "user", user_id: "U1AAAA" }, + { type: "text", text: " " }, + { type: "user", user_id: "U2BBBB" }, + { type: "text", text: ` <@${botUserId}>` } + ]) + }), + context + )) + yield* checkEvent(event, checkOptions) + assert.deepStrictEqual( + event.message.mentions.map(({ id, isSelf, start }) => ({ id, isSelf, start })), + [{ id: "U1AAAA", isSelf: false, start: 0 }, { id: "U2BBBB", isSelf: false, start: 10 }] + ) + // Two real U1 in the block and one token in text: one mention, at the token. + const short = created(SlackChat.normalize( + messageEnvelope({ + ts: "1794509003.000003", + user: "U080YLYB277", + text: `hi <@U1AAAA> <@${botUserId}>`, + blocks: section([ + { type: "user", user_id: "U1AAAA" }, + { type: "user", user_id: "U1AAAA" }, + { type: "text", text: ` <@${botUserId}>` } + ]) + }), + context + )) + assert.deepStrictEqual( + short.message.mentions.map(({ id, start }) => ({ id, start })), + [{ id: "U1AAAA", start: 3 }] + ) + })) + it.effect("a /me line that mentions the bot is a message", () => Effect.gen(function*() { const [message] = recordedMessages("me-message").values() diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts index 0c8cf0e6011..3a3c7186272 100644 --- a/packages/chat/slack/test/webhook.test.ts +++ b/packages/chat/slack/test/webhook.test.ts @@ -143,6 +143,13 @@ describe("webhook", () => { yield* Effect.promise(() => request(body)) ) assert.strictEqual(slow.status, 503) + // The deadline covers the bot user lookup too. + const slowBot = yield* handle( + { botUserId: Effect.never, deadline: Duration.millis(20) }, + yield* Effect.promise(() => request(body)) + ) + assert.strictEqual(slowBot.status, 503) + assert.strictEqual(slowBot.events.length, 0) })) it.live("layerWebhook serves the path", () => From 4255e1a1cf7034411aa3a765579d469140096dfc Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 19:54:24 +0000 Subject: [PATCH 13/89] Scope Slack's 429 backoff to a reply and fix mention alignment - NativeStream.start takes `continues`, the message id of the reply's previous part. ChatMarkdown passes it for every part after the first. The Slack adapter keys its 429 backoff by message and shares it with a stream started with `continues`, so the backoff follows its reply and never passes to another reply in the thread. A stop with end "done" drops it. - Each attempt of a paced write reads the pace afresh, so an edit retried after a 429 keeps the doubled interval. - Mention alignment marks the no-tokens-left state impossible while a real item remains, and reconstruction can't step past the tokens. Text with fewer tokens than real items no longer hangs. - Remove the unused blocksLength and blocksCost exports from length.ts. --- packages/chat/slack/src/SlackChat.ts | 3 +- packages/chat/slack/src/internal/adapter.ts | 126 ++++++++---------- packages/chat/slack/src/internal/length.ts | 6 - packages/chat/slack/src/internal/mentions.ts | 27 ++-- packages/chat/slack/test/SlackChat.test.ts | 51 +++++-- packages/chat/slack/test/normalize.test.ts | 65 +++++++++ packages/effect/src/chat/ChatAdapter.ts | 5 + packages/effect/src/chat/ChatMarkdown.ts | 1 + .../effect/test/chat/ChatMarkdown.test.ts | 19 +++ 9 files changed, 201 insertions(+), 102 deletions(-) diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts index 7220cd9f911..5c832c2dfec 100644 --- a/packages/chat/slack/src/SlackChat.ts +++ b/packages/chat/slack/src/SlackChat.ts @@ -114,7 +114,8 @@ export class SlackChat extends Context.Service Effect.fail(Errors.chatError(op, reason)) /** - * The pace of the writes that grow one reply: stream appends, stream - * starts after a rotation, and edits. + * The pace of the writes that grow one reply: stream appends, the starts + * of its later parts, and edits. * * - Edits to one message are at least `editIntervalMillis` apart. * - After a 429, the next write waits for the retry-after, and each later * write waits twice the interval it waited before, for the rest of the - * reply. A stream stopped with `end: "rotating"` hands its pace to the - * next stream started in that thread, the reply's next part. + * reply. The backoff is keyed by message and shared: a stream started + * with `continues` takes the backoff of the message it continues, and a + * stop with `end: "done"` drops it. + * - Each attempt reads the pace afresh, so a write retried after a 429 + * waits for it. */ - const paces = new Map() - const rotated = new Map() + const backoffs = new Map() + const nextEdit = new Map() - const remember = (map: Map, key: string, pace: Pace, now: number) => { - if (map.size >= 64) { for (const [old, value] of map) if (value.nextAt < now - paceIdleMillis) map.delete(old) } - map.set(key, pace) + const evict = (now: number) => { + if (nextEdit.size >= 64) { for (const [key, at] of nextEdit) if (at <= now) nextEdit.delete(key) } + if (backoffs.size >= 64) { + for (const [key, backoff] of backoffs) if (backoff.lastWrite < now - paceIdleMillis) backoffs.delete(key) + } } const paced = ( - options: { - /** The pace this write waits for. */ - readonly current: Pace | undefined - /** The interval doubled by a first 429. */ - readonly baseMillis: number - /** Kept between two writes even without a 429. */ - readonly floorMillis?: number | undefined - readonly save: (pace: Pace, now: number) => void - }, - write: Effect.Effect + messageId: string, + write: Effect.Effect, + kind: "edit" | "stream" ): Effect.Effect => Effect.gen(function*() { - const { current } = options - if (current !== undefined) { - const wait = current.nextAt - (yield* Clock.currentTimeMillis) - if (wait > 0) yield* Effect.sleep(Duration.millis(wait)) - } + const at = Math.max(backoffs.get(messageId)?.nextAt ?? 0, kind === "edit" ? nextEdit.get(messageId) ?? 0 : 0) + const wait = at - (yield* Clock.currentTimeMillis) + if (wait > 0) yield* Effect.sleep(Duration.millis(wait)) return yield* write.pipe( Effect.tap(() => Effect.map(Clock.currentTimeMillis, (now) => { - const intervalMillis = current?.intervalMillis ?? options.floorMillis - if (intervalMillis !== undefined) options.save({ intervalMillis, nextAt: now + intervalMillis }, now) + evict(now) + const backoff = backoffs.get(messageId) + if (backoff !== undefined) { + backoff.nextAt = now + backoff.intervalMillis + backoff.lastWrite = now + } + if (kind === "edit") nextEdit.set(messageId, now + editIntervalMillis) }) ), Effect.tapError((error) => error.reason._tag !== "RateLimited" ? Effect.void : Effect.map(Clock.currentTimeMillis, (now) => { - const intervalMillis = 2 * - (current?.intervalMillis ?? Math.max(options.baseMillis, options.floorMillis ?? 0)) + evict(now) + const base = kind === "edit" ? editIntervalMillis : Duration.toMillis(descriptor.limits.minWriteInterval) + const backoff = backoffs.get(messageId) ?? { intervalMillis: base, nextAt: now, lastWrite: now } + backoff.intervalMillis *= 2 const retryAfter = error.retryAfter - options.save({ - intervalMillis, - nextAt: now + (retryAfter === undefined ? intervalMillis : Duration.toMillis(retryAfter)) - }, now) + backoff.nextAt = now + (retryAfter === undefined ? backoff.intervalMillis : Duration.toMillis(retryAfter)) + backoff.lastWrite = now + backoffs.set(messageId, backoff) }) ) ) }) - const pacedMessage = ( - messageId: string, - write: Effect.Effect, - floorMillis?: number - ): Effect.Effect => - paced({ - current: paces.get(messageId), - baseMillis: Duration.toMillis(descriptor.limits.minWriteInterval), - floorMillis, - save: (pace, now) => remember(paces, messageId, pace, now) - }, write) - const call = ( op: string, method: string, @@ -445,10 +437,6 @@ export const make = (options: { } const escaped = Escape.escape(start.markdown, postOptions.notify ?? {}, { flush: true }) yield* checkSent(op, escaped.sent) - const replyKey = `${parts.channel}/${parts.threadTs}` - const handedOver = rotated.get(replyKey) - rotated.delete(replyKey) - let pace = handedOver const startCall = call(op, "chat.startStream", { channel: parts.channel, thread_ts: parts.threadTs, @@ -469,19 +457,12 @@ export const make = (options: { ) ) ) - const answer = yield* (handedOver === undefined ? startCall : paced({ - current: handedOver, - baseMillis: handedOver.intervalMillis, - save: (next) => { - pace = next - } - }, startCall)).pipe(Effect.tapError(() => - Effect.map(Clock.currentTimeMillis, (now) => { - if (pace !== undefined) remember(rotated, replyKey, pace, now) - }) - )) + // A later part of a reply goes at the reply's pace, and keeps it. + const continues = start.continues + const answer = yield* (continues === undefined ? startCall : paced(continues, startCall, "stream")) const ts = yield* tsOf(op, true)(answer) - if (pace !== undefined) remember(paces, ts, pace, yield* Clock.currentTimeMillis) + const backoff = continues === undefined ? undefined : backoffs.get(continues) + if (backoff !== undefined) backoffs.set(ts, backoff) streams.set(ts, { escape: escaped.state, text: escaped.sent, stopped: false }) return { id: ts, thread, timestamp: Normalize.timestamp(ts) } }), @@ -497,13 +478,14 @@ export const make = (options: { const held = markdown.length - escaped.consumed if (escaped.sent === "") return { state: "open" as const, held } yield* checkSent(op, state.text + escaped.sent) - return yield* pacedMessage( + return yield* paced( messageId, call(op, "chat.appendStream", { channel: parts.channel, ts: messageId, markdown_text: escaped.sent - }, { write: true, retry: false }) + }, { write: true, retry: false }), + "stream" ).pipe( Effect.map(() => { streams.set(messageId, { escape: escaped.state, text: state.text + escaped.sent, stopped: false }) @@ -526,10 +508,10 @@ export const make = (options: { const postOptions = yield* CurrentPostOptions const state = streams.get(messageId) streams.delete(messageId) - const pace = paces.get(messageId) - paces.delete(messageId) - if (pace !== undefined && stopOptions.end === "rotating") { - remember(rotated, `${parts.channel}/${parts.threadTs}`, pace, yield* Clock.currentTimeMillis) + // A rotating stop keeps the reply's backoff for its next part. + const backoff = backoffs.get(messageId) + if (backoff !== undefined && stopOptions.end === "done") { + for (const [key, value] of backoffs) if (value === backoff) backoffs.delete(key) } const status = stopOptions.end === "rotating" ? "processing" : postOptions.sessionStatusAtEnd const body = { channel: parts.channel, ts: messageId } @@ -617,13 +599,13 @@ export const make = (options: { const postOptions = yield* CurrentPostOptions const sent = Escape.escape(content.markdown, postOptions.notify ?? {}, { flush: true }).sent yield* checkSent("edit", sent) - yield* retrySafe(pacedMessage( + yield* retrySafe(paced( messageId, call("edit", "chat.update", { channel: parts.channel, ts: messageId, markdown_text: sent }, { write: true, retry: false }), - editIntervalMillis + "edit" )) }), delete: Effect.fnUntraced(function*(thread, messageId) { diff --git a/packages/chat/slack/src/internal/length.ts b/packages/chat/slack/src/internal/length.ts index 74b8970bef9..99184daa819 100644 --- a/packages/chat/slack/src/internal/length.ts +++ b/packages/chat/slack/src/internal/length.ts @@ -3,9 +3,6 @@ import { blocksCost } from "./emoji.ts" /** `msg_too_long`: code points of `markdown_text` as sent, inclusive. @internal */ export const messageLength = 12_000 -/** `msg_blocks_too_long`: Slack's count with every emoji as its shortcode, inclusive. @internal */ -export const blocksLength = 13_200 - /** @internal */ export const codePoints = (text: string): number => { let count = 0 @@ -39,6 +36,3 @@ export const measure = (markdown: string): number => codePoints(markdown) + 3 * lessThan(markdown), Math.ceil(blocksCost(markdown) * 10 / 11) ) - -/** @internal */ -export { blocksCost } diff --git a/packages/chat/slack/src/internal/mentions.ts b/packages/chat/slack/src/internal/mentions.ts index 55024ddcbfa..1c4d656947b 100644 --- a/packages/chat/slack/src/internal/mentions.ts +++ b/packages/chat/slack/src/internal/mentions.ts @@ -137,19 +137,20 @@ const align = (items: ReadonlyArray, found: ReadonlyArray): Array maxAlignment) return undefined const impossible = -1 const width = m + 1 - // best[i * width + j]: the most pairs for items i.. and tokens j.., or impossible. + // best[i * width + j]: the most pairs for items i.. and tokens j.., or + // impossible when some real item among i.. can't be paired. Row n, no + // items left, is all zero. const best = new Int32Array((n + 1) * width) - for (let i = n - 1; i >= 0; i--) { - best[i * width + m] = items[i].real ? impossible : 0 + const pairs = (i: number, j: number): number => { + if (j === m || !sameTarget(items[i], found[j])) return impossible + const rest = best[(i + 1) * width + j + 1] + return rest === impossible ? impossible : rest + 1 } for (let i = n - 1; i >= 0; i--) { - for (let j = m - 1; j >= 0; j--) { - let score = best[i * width + j + 1] + for (let j = m; j >= 0; j--) { + let score = pairs(i, j) if (!items[i].real) score = Math.max(score, best[(i + 1) * width + j]) - if (sameTarget(items[i], found[j])) { - const rest = best[(i + 1) * width + j + 1] - if (rest !== impossible) score = Math.max(score, rest + 1) - } + if (j < m) score = Math.max(score, best[i * width + j + 1]) best[i * width + j] = score } } @@ -157,17 +158,19 @@ const align = (items: ReadonlyArray, found: ReadonlyArray): Array = [] let i = 0 let j = 0 + // Every step moves i or j forward, so this ends after n + m steps. while (i < n) { const score = best[i * width + j] - const rest = j < m ? best[(i + 1) * width + j + 1] : impossible - if (j < m && sameTarget(items[i], found[j]) && rest !== impossible && rest + 1 === score) { + if (pairs(i, j) === score) { if (items[i].real) out.push(j) i++ j++ } else if (!items[i].real && best[(i + 1) * width + j] === score) { i++ - } else { + } else if (j < m && best[i * width + j + 1] === score) { j++ + } else { + return undefined } } return out diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts index 74468c618b0..0ac65ac45c5 100644 --- a/packages/chat/slack/test/SlackChat.test.ts +++ b/packages/chat/slack/test/SlackChat.test.ts @@ -527,36 +527,65 @@ describe("nativeStream", () => { ) }) - it.effect("the doubled interval outlives a rotation of the reply", () => { + it.effect("the doubled interval goes to the part that continues the reply, not to another reply", () => { const next = "1794509201.000100" + const other = "1794509202.000100" const fake = makeFake({ - "chat.appendStream": [{ status: 429, headers: { "retry-after": "3" } }, posted(ts), posted(next)], + "chat.appendStream": [{ status: 429, headers: { "retry-after": "3" } }, posted(other), posted(next)], "chat.stopStream": { ok: true, message: { ts } }, - "chat.startStream": posted(next) + "chat.startStream": [posted(other), posted(next), posted("1794509203.000100")] }) return run( fake, Effect.gen(function*() { const native = (yield* adapter).nativeStream! + const recipient = "U080YLYB277" assert.strictEqual((yield* reason(native.append(replyThread, ts, "a", { flush: true }))).tag, "RateLimited") yield* native.stop(replyThread, ts, { end: "rotating" }) - // The next part's start waits for the retry-after. - const start = yield* Effect.forkChild(native.start(replyThread, { markdown: "b", recipient: "U080YLYB277" })) + // Another reply in the thread starts and appends at once. + yield* native.start(replyThread, { markdown: "x", recipient }) + yield* native.append(replyThread, other, "y", { flush: true }) + assert.strictEqual(fake.called("chat.appendStream").length, 2) + // The reply's next part waits for the retry-after. + const start = yield* Effect.forkChild(native.start(replyThread, { markdown: "b", recipient, continues: ts })) yield* TestClock.adjust("2999 millis") - assert.strictEqual(fake.called("chat.startStream").length, 0) + assert.strictEqual(fake.called("chat.startStream").length, 1) yield* TestClock.adjust("1 millis") - yield* Fiber.join(start) + assert.strictEqual((yield* Fiber.join(start)).id, next) // Its appends keep the doubled interval, two seconds. const append = yield* Effect.forkChild(native.append(replyThread, next, "c", { flush: true })) yield* TestClock.adjust("1999 millis") - assert.strictEqual(fake.called("chat.appendStream").length, 1) + assert.strictEqual(fake.called("chat.appendStream").length, 2) yield* TestClock.adjust("1 millis") yield* Fiber.join(append) - assert.strictEqual(fake.called("chat.appendStream").length, 2) + assert.strictEqual(fake.called("chat.appendStream").length, 3) // A reply that ends hands nothing on. yield* native.stop(replyThread, next, { end: "done" }) - yield* native.start(replyThread, { markdown: "d", recipient: "U080YLYB277" }) - assert.strictEqual(fake.called("chat.startStream").length, 2) + yield* native.start(replyThread, { markdown: "d", recipient, continues: next }) + assert.strictEqual(fake.called("chat.startStream").length, 3) + }) + ) + }) + + it.effect("an edit retried after a 429 keeps the doubled interval", () => { + const fake = makeFake({ + "chat.update": [{ status: 429, headers: { "retry-after": "1" } }, { ok: true }, { ok: true }] + }) + return run( + fake, + Effect.gen(function*() { + const slack = yield* adapter + const first = yield* Effect.forkChild(slack.edit(replyThread, ts, { markdown: "a" })) + yield* TestClock.adjust("1 second") + yield* Fiber.join(first) + assert.strictEqual(fake.called("chat.update").length, 2) + // Six seconds, twice the three second floor. + const second = yield* Effect.forkChild(slack.edit(replyThread, ts, { markdown: "ab" })) + yield* TestClock.adjust("5999 millis") + assert.strictEqual(fake.called("chat.update").length, 2) + yield* TestClock.adjust("1 millis") + yield* Fiber.join(second) + assert.strictEqual(fake.called("chat.update").length, 3) }) ) }) diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts index 3f120f39306..783ef8100a7 100644 --- a/packages/chat/slack/test/normalize.test.ts +++ b/packages/chat/slack/test/normalize.test.ts @@ -1,3 +1,4 @@ +import { extract } from "@effect/chat-slack/internal/mentions" import { messageSubtypes } from "@effect/chat-slack/internal/normalize" import * as SlackChat from "@effect/chat-slack/SlackChat" import { assert, describe, it } from "@effect/vitest" @@ -142,6 +143,70 @@ describe("normalize", () => { ) })) + it.effect("a real mention with no token in text, past a literal, ends", () => + Effect.gen(function*() { + // Block items: real U1, literal U9, real U2. Text has only U1. + const event = created(SlackChat.normalize( + messageEnvelope({ + ts: "1794509003.000004", + user: "U080YLYB277", + text: "<@U1AAAA>", + blocks: [{ + type: "rich_text", + elements: [{ + type: "rich_text_section", + elements: [ + { type: "user", user_id: "U1AAAA" }, + { type: "text", text: " <@U9ZZZZ> " }, + { type: "user", user_id: "U2BBBB" } + ] + }] + }] + }), + context + )) + yield* checkEvent(event, checkOptions) + assert.deepStrictEqual( + event.message.mentions.map(({ id, start }) => ({ id, start })), + [{ id: "U1AAAA", start: 0 }] + ) + })) + + it("alignment ends and reports only real items, for every small case", () => { + const ids = ["U1AAAA", "U2BBBB", "U3CCCC"] + let seed = 7 + const next = (bound: number) => { + seed = (seed * 1103515245 + 12345) % 2147483648 + return seed % bound + } + for (let round = 0; round < 2_000; round++) { + const items = Array.from({ length: next(6) }, () => ({ id: ids[next(3)], real: next(2) === 0 })) + const text = Array.from({ length: next(6) }, () => `<@${ids[next(3)]}>`).join(" ") + const blocks = [{ + type: "rich_text", + elements: [{ + type: "rich_text_section", + elements: items.map((item) => + item.real ? { type: "user", user_id: item.id } : { type: "text", text: ` <@${item.id}> ` } + ) + }] + }] + const mentions = extract(text, blocks, botUserId) + const real = items.filter((item) => item.real).map((item) => item.id) + assert.isAtMost(mentions.length, real.length) + for (const id of new Set(mentions.map((mention) => mention.id))) { + assert.isAtMost( + mentions.filter((mention) => mention.id === id).length, + real.filter((item) => item === id).length, + JSON.stringify({ text, items }) + ) + } + const starts = mentions.map((mention) => mention.start) + assert.strictEqual(new Set(starts).size, starts.length) + for (const mention of mentions) assert.strictEqual(text.slice(mention.start, mention.end), `<@${mention.id}>`) + } + }) + it.effect("a /me line that mentions the bot is a message", () => Effect.gen(function*() { const [message] = recordedMessages("me-message").values() diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts index ad5ec038e98..a857f646466 100644 --- a/packages/effect/src/chat/ChatAdapter.ts +++ b/packages/effect/src/chat/ChatAdapter.ts @@ -215,6 +215,10 @@ export interface Ops { * - `stop` closes the stream. `stopped` says whether a user had clicked stop * on it. It succeeds with `stopped: false` on a stream that is already * closed. + * - `continues` on `start` is the message id of the reply's previous part, + * absent for a reply's first message. It tells the adapter which reply the + * stream belongs to, so state kept per reply, such as a rate limit's + * backoff, carries over a rotation and never passes to another reply. * * @stability unstable * @category models @@ -225,6 +229,7 @@ export interface NativeStream { readonly markdown: string readonly replyTo?: ReplyTo | undefined readonly recipient?: string | undefined + readonly continues?: string | undefined }) => Effect.Effect readonly append: ( thread: ChatThread, diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts index c998f386572..8cc65e0c278 100644 --- a/packages/effect/src/chat/ChatMarkdown.ts +++ b/packages/effect/src/chat/ChatMarkdown.ts @@ -780,6 +780,7 @@ const reply = (options: ReplyOptions): Effect.Effect toPart(part, posted, markdown, end), diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts index 8a3db75490b..f77fdb45e36 100644 --- a/packages/effect/test/chat/ChatMarkdown.test.ts +++ b/packages/effect/test/chat/ChatMarkdown.test.ts @@ -633,6 +633,25 @@ describe("ChatMarkdown", () => { yield* registry.register({ ...adapter, nativeStream: { ...native, ...f(native) } }) }) + it.effect("a rotated stream's start names the part it continues", () => + Effect.gen(function*() { + const { thread } = yield* setup + const continues: Array = [] + yield* patchNative((native) => ({ + start: (thread, options) => + Effect.suspend(() => { + continues.push(options.continues) + return native.start(thread, options) + }) + })) + const { end, send } = yield* feed(thread, { recipient: "U1" }) + yield* send("one\n") + yield* TestClock.adjust("9 minutes") + yield* send("two\n") + const result = yield* end + assert.deepStrictEqual(continues, [undefined, result.parts[0].messageId]) + }).pipe(Effect.provide(ChatTest.layer()))) + it.effect("sends a stop again when interrupted during it", () => Effect.gen(function*() { const { thread } = yield* setup From 88001f70cc3054704e0f4c06f6558bdc41509cf9 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 12 Nov 2026 21:00:08 +0000 Subject: [PATCH 14/89] Add captured Slack Events API deliveries as fixtures Thirteen cases, 24 deliveries, captured by janitor production's EFF-3709 fixture capture from chat-testing-123. Bodies are the delivered strings, minus the envelope token the capture drops and with avatar and file URLs replaced. No signature was logged. events.test.ts runs every delivery through the webhook, signed with a test secret, and checks what it normalises to. All were posted by the bot, so Slack sent no app_mention: the read-back pair tests are now labelled as reconstructed. --- packages/chat/slack/test/events.test.ts | 205 ++++++++++++++++++ .../fixtures/events/attachment-mention.json | 41 ++++ .../fixtures/events/block-kit-mention.json | 44 ++++ .../fixtures/events/code-only-mention.json | 35 +++ .../fixtures/events/edit-adds-mention.json | 52 +++++ .../fixtures/events/edit-keeps-mention.json | 52 +++++ .../fixtures/events/edit-removes-mention.json | 52 +++++ .../test/fixtures/events/file-mention.json | 35 +++ .../test/fixtures/events/me-message.json | 27 +++ .../test/fixtures/events/native-stream.json | 49 +++++ .../slack/test/fixtures/events/reactions.json | 83 +++++++ .../fixtures/events/thread-broadcast.json | 50 +++++ .../test/fixtures/events/thread-reply.json | 36 +++ .../test/fixtures/events/thread-root.json | 61 ++++++ packages/chat/slack/test/normalize.test.ts | 6 +- packages/chat/slack/test/utils.ts | 6 +- 16 files changed, 832 insertions(+), 2 deletions(-) create mode 100644 packages/chat/slack/test/events.test.ts create mode 100644 packages/chat/slack/test/fixtures/events/attachment-mention.json create mode 100644 packages/chat/slack/test/fixtures/events/block-kit-mention.json create mode 100644 packages/chat/slack/test/fixtures/events/code-only-mention.json create mode 100644 packages/chat/slack/test/fixtures/events/edit-adds-mention.json create mode 100644 packages/chat/slack/test/fixtures/events/edit-keeps-mention.json create mode 100644 packages/chat/slack/test/fixtures/events/edit-removes-mention.json create mode 100644 packages/chat/slack/test/fixtures/events/file-mention.json create mode 100644 packages/chat/slack/test/fixtures/events/me-message.json create mode 100644 packages/chat/slack/test/fixtures/events/native-stream.json create mode 100644 packages/chat/slack/test/fixtures/events/reactions.json create mode 100644 packages/chat/slack/test/fixtures/events/thread-broadcast.json create mode 100644 packages/chat/slack/test/fixtures/events/thread-reply.json create mode 100644 packages/chat/slack/test/fixtures/events/thread-root.json diff --git a/packages/chat/slack/test/events.test.ts b/packages/chat/slack/test/events.test.ts new file mode 100644 index 00000000000..251aa010b7a --- /dev/null +++ b/packages/chat/slack/test/events.test.ts @@ -0,0 +1,205 @@ +/** + * Events API deliveries captured from Slack (see fixtures/events). Each body + * is the string Slack sent, so these run the webhook on real bytes. + */ +import { handleRequest, makeVerifier } from "@effect/chat-slack/internal/webhook" +import * as SlackChat from "@effect/chat-slack/SlackChat" +import { assert, describe, it } from "@effect/vitest" +import type * as ChatEvent from "effect/chat/ChatEvent" +import { dedupeKey } from "effect/chat/ChatEvent" +import { checkEvent } from "effect/chat/ChatTest" +import * as Duration from "effect/Duration" +import * as Effect from "effect/Effect" +import * as HttpServerRequest from "effect/http/HttpServerRequest" +import * as Option from "effect/Option" +import * as Redacted from "effect/Redacted" +import * as fs from "node:fs" +import { appId, botUserId, channel, checkOptions, team } from "./utils.ts" + +interface Delivery { + readonly headers: Record + readonly body: string +} + +const captured = (name: string): ReadonlyArray => + JSON.parse(fs.readFileSync(new URL(`./fixtures/events/${name}.json`, import.meta.url), "utf8")).deliveries + +const cases = fs.readdirSync(new URL("./fixtures/events/", import.meta.url)) + .filter((file) => file.endsWith(".json")) + .map((file) => file.slice(0, -5)) + +const context = { teamId: team, botUserId } + +// Signed here, with a test secret: the capture never logs Slack's signature. +const secret = "captured-delivery-test-secret" + +const sign = async (timestamp: string, body: string) => { + const encoder = new TextEncoder() + const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [ + "sign" + ]) + const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, encoder.encode(`v0:${timestamp}:${body}`))) + return "v0=" + Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("") +} + +/** One delivery through the webhook, with its captured content type. */ +const deliver = Effect.fnUntraced(function*(delivery: Delivery) { + const timestamp = String(Math.floor(Date.now() / 1000)) + const signature = yield* Effect.promise(() => sign(timestamp, delivery.body)) + const web = new Request("http://localhost/slack/events", { + method: "POST", + body: delivery.body, + headers: { + "content-type": delivery.headers["content-type"], + "x-slack-request-timestamp": timestamp, + "x-slack-signature": signature + } + }) + const events: Array = [] + const response = yield* handleRequest(HttpServerRequest.fromWeb(web), { + verify: yield* makeVerifier(Redacted.make(secret)), + appId, + teamId: team, + botUserId: Effect.succeed(botUserId), + handle: (event) => Effect.sync(() => void events.push(event)), + deadline: Duration.seconds(2), + maxBodyBytes: 1024 * 1024 + }) + assert.strictEqual(response.status, 200) + return events +}) + +/** The events of every delivery of a case, in delivery order. */ +const deliveries = (name: string) => Effect.forEach(captured(name), deliver) + +const created = (events: ReadonlyArray): ChatEvent.MessageCreated => { + assert.strictEqual(events.length, 1) + const event = events[0] + assert(event._tag === "MessageCreated") + return event +} + +const mentions = (event: ChatEvent.MessageCreated) => + event.message.mentions.map(({ end, id, isSelf, start }) => ({ + id, + isSelf, + text: event.message.text.slice(start, end) + })) + +const partsOf = (thread: ChatEvent.MessageCreated["thread"]) => Option.getOrThrow(SlackChat.parts(thread)) + +const selfMention = (label = "") => [{ id: botUserId, isSelf: true, text: `<@${botUserId}${label}>` }] + +describe("captured Events API deliveries", () => { + it.live("every delivery passes the webhook and normalises as SlackChat.normalize does", () => + Effect.gen(function*() { + for (const name of cases) { + for (const delivery of captured(name)) { + assert.strictEqual(delivery.headers["content-type"], "application/json") + assert.isUndefined(delivery.headers["x-slack-signature"]) + const events = yield* deliver(delivery) + assert.deepStrictEqual(events, SlackChat.normalize(JSON.parse(delivery.body), context), name) + for (const event of events) yield* checkEvent(event, checkOptions) + } + } + })) + + it.live("a root mention, then the root's message_changed deliveries give nothing", () => + Effect.gen(function*() { + const [root, ...changed] = yield* deliveries("thread-root") + const event = created(root) + assert.deepStrictEqual(mentions(event), selfMention()) + assert.isTrue(event.message.author.isSelf) + assert.deepStrictEqual(partsOf(event.thread), { team, channel }) + assert.strictEqual(changed.length, 2) + for (const events of changed) assert.deepStrictEqual(events, []) + })) + + it.live("a thread reply and a thread_broadcast belong to the root's thread", () => + Effect.gen(function*() { + const root = created((yield* deliveries("thread-root"))[0]).message.id + const reply = created((yield* deliveries("thread-reply"))[0]) + assert.deepStrictEqual(partsOf(reply.thread), { team, channel, threadTs: root }) + assert.deepStrictEqual(mentions(reply), selfMention()) + // Slack sent a message_changed for the broadcast before the broadcast itself. + const [changed, broadcast] = yield* deliveries("thread-broadcast") + assert.deepStrictEqual(changed, []) + const event = created(broadcast) + assert.deepStrictEqual(partsOf(event.thread), { team, channel, threadTs: root }) + assert.deepStrictEqual(mentions(event), selfMention()) + })) + + it.live("an edit gives nothing, whether it keeps, adds or removes the mention", () => + Effect.gen(function*() { + const expected: Record> = { + "edit-keeps-mention": selfMention(), + "edit-adds-mention": [], + "edit-removes-mention": selfMention() + } + for (const [name, before] of Object.entries(expected)) { + const [original, edit] = yield* deliveries(name) + assert.deepStrictEqual(mentions(created(original)), before, name) + assert.deepStrictEqual(edit, [], name) + } + })) + + it.live("a mention only in code, a Block Kit section or an attachment is not reported", () => + Effect.gen(function*() { + for (const name of ["code-only-mention", "block-kit-mention", "attachment-mention"]) { + const event = created((yield* deliveries(name))[0]) + assert.deepStrictEqual(event.message.mentions, [], name) + } + })) + + it.live("a /me line keeps its labelled mention token", () => + Effect.gen(function*() { + const event = created((yield* deliveries("me-message"))[0]) + assert.deepStrictEqual(mentions(event), selfMention("|janitor2")) + })) + + it.live("a file share with a mention in its comment", () => + Effect.gen(function*() { + const event = created((yield* deliveries("file-mention"))[0]) + assert.deepStrictEqual(mentions(event), selfMention()) + assert.deepStrictEqual( + event.message.attachments.map(({ contentType, name, size }) => ({ contentType, name, size })), + [{ name: "fixture.txt", contentType: "text/plain", size: 13 }] + ) + })) + + it.live("reactions by name, with Slack's primary names and a skin tone", () => + Effect.gen(function*() { + const [message, ...reactions] = yield* deliveries("reactions") + const id = created(message).message.id + assert.deepStrictEqual( + reactions.map((events) => { + assert.strictEqual(events.length, 1) + const event = events[0] + assert(event._tag === "ReactionAdded" || event._tag === "ReactionRemoved") + assert.strictEqual(event.messageId, id) + return [event._tag, event.emoji] + }), + [["ReactionAdded", "👍"], ["ReactionAdded", "👍🏽"], ["ReactionAdded", "😀"], ["ReactionRemoved", "😀"]] + ) + // An add and its removal are different events. + assert.notStrictEqual(dedupeKey(reactions[2][0]), dedupeKey(reactions[3][0])) + })) + + it.live("a native stream arrives as an empty message from the bot, its text only as message_changed", () => + Effect.gen(function*() { + const [start, changed] = yield* deliveries("native-stream") + const event = created(start) + assert.strictEqual(event.message.text, "") + assert.isTrue(event.message.author.isSelf) + assert.deepStrictEqual(changed, []) + })) + + it.live("Slack sent no app_mention for the bot's own messages", () => + Effect.sync(() => { + for (const name of cases) { + for (const delivery of captured(name)) { + assert.notStrictEqual(JSON.parse(delivery.body).event.type, "app_mention") + } + } + })) +}) diff --git a/packages/chat/slack/test/fixtures/events/attachment-mention.json b/packages/chat/slack/test/fixtures/events/attachment-mention.json new file mode 100644 index 00000000000..74a41ebfa90 --- /dev/null +++ b/packages/chat/slack/test/fixtures/events/attachment-mention.json @@ -0,0 +1,41 @@ +{ + "case": "A mention only inside a legacy attachment", + "provenance": { + "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)", + "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel", + "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token", + "recordedAt": "2026-11-12T20:54:52.189Z", + "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced", + "headers": "The capture's allowlist. The signature is never logged" + }, + "actions": [ + { + "action": "chat.postMessage", + "ts": "1794516879.362179", + "request": { + "text": "attachment carrier [EFF-3694 20:54:24]", + "attachments": [ + { + "text": "attachment <@U0CCLMD4S1L>", + "fallback": "attachment" + } + ] + } + } + ], + "deliveries": [ + { + "loggedAt": "2026-11-12T20:54:40.254Z", + "headers": { + "x-slack-request-timestamp": "1794516879", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516879.362179\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"attachment carrier [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"attachments\":[{\"id\":1,\"fallback\":\"attachment\",\"text\":\"attachment <@U0CCLMD4S1L>\"}],\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"oLy\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"attachment carrier [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516879.362179\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85DKJ3Y\",\"event_time\":1794516879,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + } + ] +} diff --git a/packages/chat/slack/test/fixtures/events/block-kit-mention.json b/packages/chat/slack/test/fixtures/events/block-kit-mention.json new file mode 100644 index 00000000000..7e151cb52b7 --- /dev/null +++ b/packages/chat/slack/test/fixtures/events/block-kit-mention.json @@ -0,0 +1,44 @@ +{ + "case": "A mention only inside a Block Kit section; the fallback text has none", + "provenance": { + "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)", + "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel", + "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token", + "recordedAt": "2026-11-12T20:54:52.189Z", + "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced", + "headers": "The capture's allowlist. The signature is never logged" + }, + "actions": [ + { + "action": "chat.postMessage", + "ts": "1794516878.111629", + "request": { + "text": "block kit fallback [EFF-3694 20:54:24]", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "section <@U0CCLMD4S1L> [EFF-3694 20:54:24]" + } + } + ] + } + } + ], + "deliveries": [ + { + "loggedAt": "2026-11-12T20:54:38.438Z", + "headers": { + "x-slack-request-timestamp": "1794516878", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516878.111629\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"block kit fallback [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"section\",\"block_id\":\"us67M\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"section <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"verbatim\":false}}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516878.111629\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T1C5V1\",\"event_time\":1794516878,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + } + ] +} diff --git a/packages/chat/slack/test/fixtures/events/code-only-mention.json b/packages/chat/slack/test/fixtures/events/code-only-mention.json new file mode 100644 index 00000000000..d2e15b7e38f --- /dev/null +++ b/packages/chat/slack/test/fixtures/events/code-only-mention.json @@ -0,0 +1,35 @@ +{ + "case": "A mention only inside an inline code span", + "provenance": { + "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)", + "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel", + "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token", + "recordedAt": "2026-11-12T20:54:52.189Z", + "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced", + "headers": "The capture's allowlist. The signature is never logged" + }, + "actions": [ + { + "action": "chat.postMessage", + "ts": "1794516876.861899", + "request": { + "markdown_text": "in code `<@U0CCLMD4S1L>` only [EFF-3694 20:54:24]" + } + } + ], + "deliveries": [ + { + "loggedAt": "2026-11-12T20:54:37.834Z", + "headers": { + "x-slack-request-timestamp": "1794516876", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516876.861899\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"in code `<@U0CCLMD4S1L>` only [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"PuZn8E\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"in code \"},{\"type\":\"text\",\"text\":\"<@U0CCLMD4S1L>\",\"style\":{\"code\":true}},{\"type\":\"text\",\"text\":\" only [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516876.861899\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH4R6DQ4D\",\"event_time\":1794516876,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + } + ] +} diff --git a/packages/chat/slack/test/fixtures/events/edit-adds-mention.json b/packages/chat/slack/test/fixtures/events/edit-adds-mention.json new file mode 100644 index 00000000000..9d38f3b7f22 --- /dev/null +++ b/packages/chat/slack/test/fixtures/events/edit-adds-mention.json @@ -0,0 +1,52 @@ +{ + "case": "A message without a mention, edited to add one", + "provenance": { + "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)", + "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel", + "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token", + "recordedAt": "2026-11-12T20:54:52.189Z", + "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced", + "headers": "The capture's allowlist. The signature is never logged" + }, + "actions": [ + { + "action": "chat.postMessage", + "ts": "1794516871.790219", + "request": { + "markdown_text": "no mention yet [EFF-3694 20:54:24]" + } + }, + { + "action": "chat.update", + "ts": "1794516871.790219" + } + ], + "deliveries": [ + { + "loggedAt": "2026-11-12T20:54:32.569Z", + "headers": { + "x-slack-request-timestamp": "1794516871", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516871.790219\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"no mention yet [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"etv+WF\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"no mention yet [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516871.790219\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ4FCQJRE\",\"event_time\":1794516871,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + }, + { + "loggedAt": "2026-11-12T20:54:33.275Z", + "headers": { + "x-slack-request-timestamp": "1794516873", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516873.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"now <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"0rFf2G\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"now \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"ts\":\"1794516871.790219\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516871.790219\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"no mention yet [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"etv+WF\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"no mention yet [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516873.058800\",\"event_ts\":\"1794516873.058800\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGUNP1P5M\",\"event_time\":1794516873,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + } + ] +} diff --git a/packages/chat/slack/test/fixtures/events/edit-keeps-mention.json b/packages/chat/slack/test/fixtures/events/edit-keeps-mention.json new file mode 100644 index 00000000000..83ad2bcabf1 --- /dev/null +++ b/packages/chat/slack/test/fixtures/events/edit-keeps-mention.json @@ -0,0 +1,52 @@ +{ + "case": "A message that mentions the bot, edited with the mention kept", + "provenance": { + "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)", + "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel", + "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token", + "recordedAt": "2026-11-12T20:54:52.189Z", + "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced", + "headers": "The capture's allowlist. The signature is never logged" + }, + "actions": [ + { + "action": "chat.postMessage", + "ts": "1794516869.259869", + "request": { + "markdown_text": "before <@U0CCLMD4S1L> [EFF-3694 20:54:24]" + } + }, + { + "action": "chat.update", + "ts": "1794516869.259869" + } + ], + "deliveries": [ + { + "loggedAt": "2026-11-12T20:54:29.537Z", + "headers": { + "x-slack-request-timestamp": "1794516869", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516869.259869\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"before <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"okdLho\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"before \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516869.259869\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85C00T0\",\"event_time\":1794516869,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + }, + { + "loggedAt": "2026-11-12T20:54:32.095Z", + "headers": { + "x-slack-request-timestamp": "1794516870", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516870.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"after <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"q8h6hJ\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"after \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"ts\":\"1794516869.259869\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516869.259869\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"before <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"okdLho\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"before \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516870.058700\",\"event_ts\":\"1794516870.058700\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGUNNSSH5\",\"event_time\":1794516870,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + } + ] +} diff --git a/packages/chat/slack/test/fixtures/events/edit-removes-mention.json b/packages/chat/slack/test/fixtures/events/edit-removes-mention.json new file mode 100644 index 00000000000..615678ae815 --- /dev/null +++ b/packages/chat/slack/test/fixtures/events/edit-removes-mention.json @@ -0,0 +1,52 @@ +{ + "case": "A message that mentions the bot, edited to remove the mention", + "provenance": { + "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)", + "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel", + "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token", + "recordedAt": "2026-11-12T20:54:52.189Z", + "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced", + "headers": "The capture's allowlist. The signature is never logged" + }, + "actions": [ + { + "action": "chat.postMessage", + "ts": "1794516874.327439", + "request": { + "markdown_text": "mention <@U0CCLMD4S1L> for now [EFF-3694 20:54:24]" + } + }, + { + "action": "chat.update", + "ts": "1794516874.327439" + } + ], + "deliveries": [ + { + "loggedAt": "2026-11-12T20:54:35.045Z", + "headers": { + "x-slack-request-timestamp": "1794516874", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516874.327439\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"mention <@U0CCLMD4S1L> for now [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"7BKEu+\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"mention \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" for now [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516874.327439\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH4R5T1MK\",\"event_time\":1794516874,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + }, + { + "loggedAt": "2026-11-12T20:54:35.784Z", + "headers": { + "x-slack-request-timestamp": "1794516875", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516875.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"mention removed [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"7RC4kt\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"mention removed [EFF-3694 20:54:24]\"}]}]}],\"ts\":\"1794516874.327439\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516874.327439\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"mention <@U0CCLMD4S1L> for now [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"7BKEu+\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"mention \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" for now [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516875.058900\",\"event_ts\":\"1794516875.058900\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9UAP7KL\",\"event_time\":1794516875,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}", + "scrubbed": [ + "image_36", + "image_48", + "image_72" + ] + } + ] +} diff --git a/packages/chat/slack/test/fixtures/events/file-mention.json b/packages/chat/slack/test/fixtures/events/file-mention.json new file mode 100644 index 00000000000..0387952b91b --- /dev/null +++ b/packages/chat/slack/test/fixtures/events/file-mention.json @@ -0,0 +1,35 @@ +{ + "case": "A file upload whose comment mentions the bot", + "provenance": { + "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)", + "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel", + "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token", + "recordedAt": "2026-11-12T20:54:52.189Z", + "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced", + "headers": "The capture's allowlist. The signature is never logged" + }, + "actions": [ + { + "action": "files.completeUploadExternal", + "ts": "1794516902.053009", + "file": "F0CJ4FGJTPS" + } + ], + "deliveries": [ + { + "loggedAt": "2026-11-12T20:55:02.572Z", + "headers": { + "x-slack-request-timestamp": "1794516902", + "content-type": "application/json" + }, + "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"text\":\"file for <@U0CCLMD4S1L> [EFF-3694 20:55:01]\",\"files\":[{\"id\":\"F0CJ4FGJTPS\",\"created\":1794516901,\"timestamp\":1794516901,\"mimetype\":\"text\\/plain\",\"filetype\":\"text\",\"pretty_type\":\"Plain Text\",\"user\":\"U0CCLMD4S1L\",\"user_team\":\"T05479Z6JBW\",\"editable\":true,\"size\":13,\"mode\":\"snippet\",\"is_external\":false,\"external_type\":\"\",\"is_public\":false,\"public_url_shared\":false,\"display_as_bot\":false,\"username\":\"\",\"name\":\"fixture.txt\",\"title\":\"fixture.txt\",\"is_modified_by_ai\":false,\"url_private\":\"https:\\/\\/scrubbed.invalid\\/url_private\",\"url_private_download\":\"https:\\/\\/scrubbed.invalid\\/url_private_download\",\"permalink\":\"https:\\/\\/scrubbed.invalid\\/permalink\",\"permalink_public\":\"https:\\/\\/scrubbed.invalid\\/permalink_public\",\"edit_link\":\"https:\\/\\/scrubbed.invalid\\/edit_link\",\"preview\":\"fixture file\\n\",\"preview_highlight\":\"
\\n
\\n
fixture file<\\/pre><\\/div>\\n
<\\/pre><\\/div>\\n<\\/div>\\n<\\/div>\\n\",\"lines\":2,\"lines_more\":0,\"preview_is_truncated\":false,\"skipped_shares\":true,\"has_rich_preview\":false,\"file_access\":\"visible\"}],\"upload\":true,\"user\":\"U0CCLMD4S1L\",\"display_as_bot\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"h2N+\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"file for \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:55:01]\"}]}]}],\"ts\":\"1794516902.053009\",\"bot_id\":\"B0CCQH77VA5\",\"channel\":\"C0CH1LGJ4F3\",\"subtype\":\"file_share\",\"event_ts\":\"1794516902.053009\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T4TU1H\",\"event_time\":1794516902,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "edit_link",
+        "permalink",
+        "permalink_public",
+        "url_private",
+        "url_private_download"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/me-message.json b/packages/chat/slack/test/fixtures/events/me-message.json
new file mode 100644
index 00000000000..b375b0249c9
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/me-message.json
@@ -0,0 +1,27 @@
+{
+  "case": "A /me line (chat.meMessage) that mentions the bot",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
+    "recordedAt": "2026-11-12T20:54:52.189Z",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "actions": [
+    {
+      "action": "chat.meMessage",
+      "ts": "1794516880.615709"
+    }
+  ],
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T20:54:40.906Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516880",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"me_message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516880.615709\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"waves at <@U0CCLMD4S1L|janitor2> [EFF-3694 20:54:24]\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"rn7Rs\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"waves at \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516880.615709\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T1V1DH\",\"event_time\":1794516880,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/native-stream.json b/packages/chat/slack/test/fixtures/events/native-stream.json
new file mode 100644
index 00000000000..32c5da4d84b
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/native-stream.json
@@ -0,0 +1,49 @@
+{
+  "case": "A native stream started in a thread, appended to and stopped",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
+    "recordedAt": "2026-11-12T20:54:52.189Z",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "actions": [
+    {
+      "action": "chat.startStream",
+      "ts": "1794516888.347839"
+    },
+    {
+      "action": "chat.stopStream",
+      "ts": "1794516888.347839"
+    }
+  ],
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T20:54:48.550Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516888",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516888.347839\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"parent_user_id\":\"U0CCLMD4S1L\",\"streaming_state\":\"in_progress\",\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516888.347839\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ4FF66C8\",\"event_time\":1794516888,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:51.162Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516891",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"streaming [EFF-3694 20:54:24] more\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"parent_user_id\":\"U0CCLMD4S1L\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"rLSGFT\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"streaming [EFF-3694 20:54:24] more\"}]}]}],\"streaming_state\":\"completed\",\"ts\":\"1794516888.347839\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516888.347839\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"parent_user_id\":\"U0CCLMD4S1L\",\"streaming_state\":\"in_progress\"},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516890.059700\",\"event_ts\":\"1794516890.059700\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHDR2MAQL\",\"event_time\":1794516890,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/reactions.json b/packages/chat/slack/test/fixtures/events/reactions.json
new file mode 100644
index 00000000000..af50500c7e0
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/reactions.json
@@ -0,0 +1,83 @@
+{
+  "case": "A message, then thumbsup, +1::skin-tone-4 and grinning added, then grinning removed",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
+    "recordedAt": "2026-11-12T20:54:52.189Z",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "actions": [
+    {
+      "action": "chat.postMessage",
+      "ts": "1794516881.873469",
+      "request": {
+        "markdown_text": "react here [EFF-3694 20:54:24]"
+      }
+    },
+    {
+      "action": "reactions.add thumbsup",
+      "ts": "1794516881.873469"
+    },
+    {
+      "action": "reactions.add +1::skin-tone-4",
+      "ts": "1794516881.873469"
+    },
+    {
+      "action": "reactions.add grinning",
+      "ts": "1794516881.873469"
+    },
+    {
+      "action": "reactions.remove grinning",
+      "ts": "1794516881.873469"
+    }
+  ],
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T20:54:42.158Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516883",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516881.873469\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"react here [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"2l3VdF\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"react here [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T24A2X\",\"event_time\":1794516881,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:43.275Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516883",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"+1\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516883.059000\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85E7Z2S\",\"event_time\":1794516883,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:44.586Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516884",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"+1::skin-tone-4\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516884.059100\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85ECA1L\",\"event_time\":1794516884,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:45.873Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516885",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"grinning\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516885.059200\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGUNRA0LX\",\"event_time\":1794516885,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:47.111Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516887",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_removed\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"grinning\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516886.059300\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ4FENQF2\",\"event_time\":1794516886,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX3JlbW92ZWQiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/thread-broadcast.json b/packages/chat/slack/test/fixtures/events/thread-broadcast.json
new file mode 100644
index 00000000000..2589c2162ff
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/thread-broadcast.json
@@ -0,0 +1,50 @@
+{
+  "case": "A thread reply that mentions the bot, sent with also send to channel",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
+    "recordedAt": "2026-11-12T20:54:52.189Z",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "actions": [
+    {
+      "action": "chat.postMessage",
+      "ts": "1794516866.701379",
+      "request": {
+        "thread_ts": "1794516865.426549",
+        "reply_broadcast": true,
+        "markdown_text": "broadcast to <@U0CCLMD4S1L> [EFF-3694 20:54:24]"
+      }
+    }
+  ],
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T20:54:27.584Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516867",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"subtype\":\"thread_broadcast\",\"bot_id\":\"B0CCQH77VA5\",\"thread_ts\":\"1794516865.426549\",\"root\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516865.426549\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794516866.701379\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}]},\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"broadcast to <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"g1vhxK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"broadcast to \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"ts\":\"1794516866.701379\"},\"previous_message\":{\"subtype\":\"thread_broadcast\",\"bot_id\":\"B0CCQH77VA5\",\"thread_ts\":\"1794516865.426549\",\"root\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516865.426549\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794516866.701379\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}]},\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516866.701379\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"broadcast to <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"g1vhxK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"broadcast to \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516866.058500\",\"event_ts\":\"1794516866.058500\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHC158P41\",\"event_time\":1794516866,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:27.744Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516866",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"thread_broadcast\",\"bot_id\":\"B0CCQH77VA5\",\"thread_ts\":\"1794516865.426549\",\"root\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516865.426549\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794516866.701379\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}]},\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516866.701379\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"broadcast to <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"g1vhxK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"broadcast to \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516866.701379\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3SZSGKV\",\"event_time\":1794516866,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/thread-reply.json b/packages/chat/slack/test/fixtures/events/thread-reply.json
new file mode 100644
index 00000000000..e59a7fcb24a
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/thread-reply.json
@@ -0,0 +1,36 @@
+{
+  "case": "A thread reply that mentions the bot",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
+    "recordedAt": "2026-11-12T20:54:52.189Z",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "actions": [
+    {
+      "action": "chat.postMessage",
+      "ts": "1794516867.999329",
+      "request": {
+        "thread_ts": "1794516865.426549",
+        "markdown_text": "reply to <@U0CCLMD4S1L> [EFF-3694 20:54:24]"
+      }
+    }
+  ],
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T20:54:29.606Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516868",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516867.999329\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"reply to <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"parent_user_id\":\"U0CCLMD4S1L\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"nx\\/ZVl\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"reply to \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516867.999329\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGUNNJ3U7\",\"event_time\":1794516867,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/thread-root.json b/packages/chat/slack/test/fixtures/events/thread-root.json
new file mode 100644
index 00000000000..b401941b859
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/thread-root.json
@@ -0,0 +1,61 @@
+{
+  "case": "A root message that mentions the bot, then the message_changed deliveries Slack sent for it as replies and a native stream were added under it",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
+    "recordedAt": "2026-11-12T20:54:52.189Z",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "actions": [
+    {
+      "action": "chat.postMessage",
+      "ts": "1794516865.426549",
+      "request": {
+        "markdown_text": "hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]"
+      }
+    }
+  ],
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T20:54:26.289Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516865",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516865.426549\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516865.426549\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85BHSS2\",\"event_time\":1794516865,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:49.961Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516888",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"reply_count\":2,\"reply_users_count\":1,\"latest_reply\":\"1794516867.999329\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"date_status_processing_expire\":1794520488,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794520488,\"is_stoppable\":true}]},\"ts\":\"1794516865.426549\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516865.426549\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"reply_count\":2,\"reply_users_count\":1,\"latest_reply\":\"1794516867.999329\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516888.059400\",\"event_ts\":\"1794516888.059400\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ4FFFCUQ\",\"event_time\":1794516888,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T20:54:51.170Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794516891",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"reply_count\":3,\"reply_users_count\":1,\"latest_reply\":\"1794516888.347839\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"agent_session\":{\"status\":\"active\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"active\",\"is_stoppable\":true}]},\"ts\":\"1794516865.426549\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516865.426549\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"hello <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"reply_count\":3,\"reply_users_count\":1,\"latest_reply\":\"1794516888.347839\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"DQGPyG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"hello \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"date_status_processing_expire\":1794520488,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794520488,\"is_stoppable\":true}]}},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516890.059800\",\"event_ts\":\"1794516890.059800\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T3DM35\",\"event_time\":1794516890,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts
index 783ef8100a7..1d5ea384aaa 100644
--- a/packages/chat/slack/test/normalize.test.ts
+++ b/packages/chat/slack/test/normalize.test.ts
@@ -18,7 +18,11 @@ const created = (events: ReadonlyArray): ChatEvent.MessageC
   return event
 }
 
-/** The `message` and `app_mention` for one recorded message, checked as a pair. */
+/**
+ * A `message` and an `app_mention` envelope built from one read-back message,
+ * checked as a pair. This shows the two shapes normalise alike. It is not a
+ * captured pair: Slack sends no `app_mention` for the bot's own messages.
+ */
 const pair = Effect.fnUntraced(function*(
   message: Record,
   options?: { readonly channel?: string; readonly channelType?: string }
diff --git a/packages/chat/slack/test/utils.ts b/packages/chat/slack/test/utils.ts
index 34641dac1c7..4df8e804046 100644
--- a/packages/chat/slack/test/utils.ts
+++ b/packages/chat/slack/test/utils.ts
@@ -37,7 +37,11 @@ export const recordedMessages = (name: string): Map => {
   return out
 }
 
-/** An `event_callback` envelope around a message as a read returned it. */
+/**
+ * An `event_callback` envelope built around a message as a Web API read
+ * returned it. Reconstructed, not delivered by Slack: the captured
+ * deliveries are in `fixtures/events`.
+ */
 export const messageEnvelope = (
   message: Record,
   options?: {

From e8e2a1b5fb6d7a3c6f20cc1ec835b5bf50ecf1a4 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Thu, 12 Nov 2026 23:45:42 +0000
Subject: [PATCH 15/89] Add captured Slack deliveries for a person's messages
 and stops

Tim typed the H1 to H9 cases and clicked Stop in chat-testing-123 while
janitor production's EFF-3709 capture logged the deliveries. Thirteen new
cases, 54 of the 100 deliveries; the rest are janitor's status messages
for later cases. Bodies are verbatim apart from the envelope token and
avatar and file URLs. No delivery carried a retry header.

events.test.ts now checks six independently delivered message and
app_mention pairs normalise to the same event, that edits (including
the app_mention Slack sends when an edit adds a mention) give nothing,
reactions with a tone and a custom emoji, and the stop button.

The stops show only the first click in a thread names the open stream,
so StopRequested's docs no longer say an empty messageIds means no
stream was open. With no stream, Slack sends streaming_message_ts: [];
the recorded G2 event only lacked it because that log dropped it.
---
 packages/chat/slack/src/SlackChat.ts          |   3 +-
 packages/chat/slack/test/events.test.ts       | 175 +++++++++++++++++-
 .../fixtures/events/bot-reply-lifecycle.json  | 130 +++++++++++++
 .../fixtures/events/human-code-mention.json   |  21 +++
 .../events/human-edit-adds-mention.json       |  37 ++++
 .../events/human-edit-keeps-mention.json      |  45 +++++
 .../events/human-edit-removes-mention.json    |  45 +++++
 .../fixtures/events/human-file-mention.json   |  55 ++++++
 .../fixtures/events/human-me-message.json     |  29 +++
 .../test/fixtures/events/human-mention.json   |  37 ++++
 .../test/fixtures/events/human-plain.json     |  29 +++
 .../test/fixtures/events/human-reactions.json |  61 ++++++
 .../events/human-thread-broadcast.json        |  37 ++++
 .../test/fixtures/events/stop-no-stream.json  |  76 ++++++++
 .../test/fixtures/events/stop-stream.json     | 102 ++++++++++
 .../recorded/agent-session-stopped.json       |   2 +-
 packages/chat/slack/test/normalize.test.ts    |   4 +-
 packages/effect/src/chat/ChatEvent.ts         |  11 +-
 18 files changed, 888 insertions(+), 11 deletions(-)
 create mode 100644 packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-code-mention.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-edit-adds-mention.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-edit-keeps-mention.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-edit-removes-mention.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-file-mention.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-me-message.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-mention.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-plain.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-reactions.json
 create mode 100644 packages/chat/slack/test/fixtures/events/human-thread-broadcast.json
 create mode 100644 packages/chat/slack/test/fixtures/events/stop-no-stream.json
 create mode 100644 packages/chat/slack/test/fixtures/events/stop-stream.json

diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 5c832c2dfec..59ed5ca2286 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -17,7 +17,8 @@
  *   `not_authorized`; it then stops making them, and replies still work.
  * - A click on the stop button stops nothing by itself: the consumer gets a
  *   `StopRequested` and ends the reply. Until it does, the user sees a
- *   disabled button.
+ *   disabled button. Every click is a separate `StopRequested`, and only
+ *   the first in a thread lists the open stream in `messageIds`.
  *
  * @stability unstable
  * @since 4.1.5
diff --git a/packages/chat/slack/test/events.test.ts b/packages/chat/slack/test/events.test.ts
index 251aa010b7a..9e51107dbd7 100644
--- a/packages/chat/slack/test/events.test.ts
+++ b/packages/chat/slack/test/events.test.ts
@@ -7,7 +7,7 @@ import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { dedupeKey } from "effect/chat/ChatEvent"
-import { checkEvent } from "effect/chat/ChatTest"
+import { checkEvent, sameMessage } from "effect/chat/ChatTest"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as HttpServerRequest from "effect/http/HttpServerRequest"
@@ -97,6 +97,7 @@ describe("captured Events API deliveries", () => {
         for (const delivery of captured(name)) {
           assert.strictEqual(delivery.headers["content-type"], "application/json")
           assert.isUndefined(delivery.headers["x-slack-signature"])
+          assert.isUndefined(delivery.headers["x-slack-retry-num"])
           const events = yield* deliver(delivery)
           assert.deepStrictEqual(events, SlackChat.normalize(JSON.parse(delivery.body), context), name)
           for (const event of events) yield* checkEvent(event, checkOptions)
@@ -194,12 +195,180 @@ describe("captured Events API deliveries", () => {
       assert.deepStrictEqual(changed, [])
     }))
 
-  it.live("Slack sent no app_mention for the bot's own messages", () =>
+  it.live("Slack sent app_mention only for messages from a person", () =>
     Effect.sync(() => {
       for (const name of cases) {
         for (const delivery of captured(name)) {
-          assert.notStrictEqual(JSON.parse(delivery.body).event.type, "app_mention")
+          const event = JSON.parse(delivery.body).event
+          if (event.type === "app_mention") assert.strictEqual(event.user, person, name)
         }
       }
     }))
 })
+
+const person = "U080YLYB277"
+
+type Body = { readonly event: Record }
+
+/** The `message` and `app_mention` deliveries of one message, matched by ts. */
+const pairsOf = (name: string) => {
+  const bodies = captured(name).map((delivery): Body => JSON.parse(delivery.body))
+  return bodies.flatMap((mention) => {
+    if (mention.event.type !== "app_mention" || mention.event.edited !== undefined) return []
+    const message = bodies.filter((body) =>
+      body.event.type === "message" && body.event.ts === mention.event.ts && body.event.hidden === undefined
+    )
+    assert.strictEqual(message.length, 1, name)
+    return [[message[0], mention] as const]
+  })
+}
+
+describe("captured deliveries for messages a person typed", () => {
+  it.live("each message and app_mention pair normalises to the same event", () =>
+    Effect.gen(function*() {
+      const found: Array = []
+      for (const name of cases) {
+        for (const [message, mention] of pairsOf(name)) {
+          const fromMessage = created(SlackChat.normalize(message, context))
+          const fromMention = created(SlackChat.normalize(mention, context))
+          yield* checkEvent(fromMessage, checkOptions)
+          yield* checkEvent(fromMention, checkOptions)
+          assert.strictEqual(dedupeKey(fromMessage), dedupeKey(fromMention), name)
+          assert.isTrue(sameMessage(fromMessage.message, fromMention.message), name)
+          const { raw: _a, ...left } = fromMessage.message
+          const { raw: _b, ...right } = fromMention.message
+          assert.deepStrictEqual(left, right, name)
+          assert.deepStrictEqual(fromMessage.thread, fromMention.thread, name)
+          assert.isFalse(fromMessage.message.author.isSelf)
+          assert.deepStrictEqual(
+            mentions(fromMessage),
+            selfMention(String(message.event.subtype) === "me_message" ? "|janitor2" : "")
+          )
+          found.push(name)
+        }
+      }
+      assert.deepStrictEqual(found.sort(), [
+        "human-edit-keeps-mention",
+        "human-edit-removes-mention",
+        "human-file-mention",
+        "human-me-message",
+        "human-mention",
+        "human-thread-broadcast"
+      ])
+    }))
+
+  it.live("a plain message has no mention, and its later message_changed gives nothing", () =>
+    Effect.gen(function*() {
+      const [message, changed] = yield* deliveries("human-plain")
+      const event = created(message)
+      assert.strictEqual(event.message.author.id, person)
+      assert.isFalse(event.message.author.isSelf)
+      assert.isFalse(event.message.author.isBot)
+      assert.deepStrictEqual(event.message.mentions, [])
+      assert.deepStrictEqual(changed, [])
+    }))
+
+  it.live("a thread root's message_changed after its first reply gives nothing", () =>
+    Effect.gen(function*() {
+      const [message, mention, changed] = yield* deliveries("human-mention")
+      assert.strictEqual(created(message).message.id, created(mention).message.id)
+      assert.deepStrictEqual(changed, [])
+    }))
+
+  it.live("an edit gives nothing, including the app_mention Slack sends when it adds a mention", () =>
+    Effect.gen(function*() {
+      const [original, changed, mention] = yield* deliveries("human-edit-adds-mention")
+      assert.deepStrictEqual(created(original).message.mentions, [])
+      assert.deepStrictEqual(changed, [])
+      assert.deepStrictEqual(mention, [])
+      const [, , rootChanged, removed] = yield* deliveries("human-edit-removes-mention")
+      assert.deepStrictEqual(rootChanged, [])
+      assert.deepStrictEqual(removed, [])
+      const [, , kept, keptRoot] = yield* deliveries("human-edit-keeps-mention")
+      assert.deepStrictEqual(kept, [])
+      assert.deepStrictEqual(keptRoot, [])
+    }))
+
+  it.live("a literal @name in code is no mention", () =>
+    Effect.gen(function*() {
+      const [events] = yield* deliveries("human-code-mention")
+      assert.deepStrictEqual(created(events).message.mentions, [])
+    }))
+
+  it.live("a file share keeps its file, and its later message_changed gives nothing", () =>
+    Effect.gen(function*() {
+      const [message, , changed] = yield* deliveries("human-file-mention")
+      assert.deepStrictEqual(created(message).message.attachments.map(({ name }) => name), ["T3.svg"])
+      assert.deepStrictEqual(changed, [])
+    }))
+
+  it.live("a thread_broadcast belongs to the thread it was sent in", () =>
+    Effect.gen(function*() {
+      const root = created((yield* deliveries("human-plain"))[0]).message.id
+      const [message, changed] = yield* deliveries("human-thread-broadcast")
+      assert.deepStrictEqual(partsOf(created(message).thread), { team, channel, threadTs: root })
+      assert.deepStrictEqual(changed, [])
+    }))
+
+  it.live("reactions, with a skin tone and a custom emoji", () =>
+    Effect.gen(function*() {
+      const root = created((yield* deliveries("human-plain"))[0]).message.id
+      const reactions = (yield* deliveries("human-reactions")).map((events) => {
+        assert.strictEqual(events.length, 1)
+        const event = events[0]
+        assert(event._tag === "ReactionAdded" || event._tag === "ReactionRemoved")
+        assert.strictEqual(event.messageId, root)
+        assert.strictEqual(event.userId, person)
+        return event
+      })
+      assert.deepStrictEqual(reactions.map((event) => [event._tag, event.emoji]), [
+        ["ReactionAdded", "👍"],
+        ["ReactionRemoved", "👍"],
+        ["ReactionAdded", "👍🏼"],
+        ["ReactionRemoved", "👍🏼"],
+        ["ReactionAdded", "custom:effect"],
+        ["ReactionRemoved", "custom:effect"]
+      ])
+      assert.strictEqual(new Set(reactions.map(dedupeKey)).size, 6)
+    }))
+})
+
+describe("captured deliveries for the bot's replies and stops", () => {
+  it.live("janitor's status message, its edits and its deletion: only the posts are events", () =>
+    Effect.gen(function*() {
+      const results = yield* deliveries("bot-reply-lifecycle")
+      const posted = results.filter((events) => events.length > 0).map(created)
+      assert.strictEqual(posted.length, 2)
+      const root = created((yield* deliveries("human-mention"))[0]).message.id
+      for (const event of posted) {
+        assert.isTrue(event.message.author.isSelf)
+        assert.deepStrictEqual(partsOf(event.thread), { team, channel, threadTs: root })
+      }
+    }))
+
+  it.live("only the first click on Stop names the open stream", () =>
+    Effect.gen(function*() {
+      const results = yield* deliveries("stop-stream")
+      const root = created(results[0]).message.id
+      const stream = created(results[2])
+      assert.strictEqual(stream.message.text, "")
+      const stops = results.flat().filter((event) => event._tag === "StopRequested")
+      assert.deepStrictEqual(stops.map((event) => event.messageIds), [[stream.message.id], [], []])
+      for (const stop of stops) {
+        assert.strictEqual(stop.userId, person)
+        assert.deepStrictEqual(Option.getOrThrow(SlackChat.parts(stop.thread)), { team, channel, threadTs: root })
+      }
+      // Each click is its own request.
+      assert.strictEqual(new Set(stops.map(dedupeKey)).size, 3)
+    }))
+
+  it.live("a click on Stop with no stream open sends an empty streaming_message_ts", () =>
+    Effect.gen(function*() {
+      const bodies = captured("stop-no-stream").map((delivery) => JSON.parse(delivery.body).event)
+      const stops = bodies.filter((event) => event.type === "agent_session_stopped")
+      assert.deepStrictEqual(stops.map((event) => event.streaming_message_ts), [[], [], []])
+      const events = (yield* deliveries("stop-no-stream")).flat().filter((event) => event._tag === "StopRequested")
+      assert.deepStrictEqual(events.map((event) => event.messageIds), [[], [], []])
+      assert.strictEqual(new Set(events.map(dedupeKey)).size, 3)
+    }))
+})
diff --git a/packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json b/packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json
new file mode 100644
index 00000000000..c88fdd056cb
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json
@@ -0,0 +1,130 @@
+{
+  "case": "Janitor's answer to H2: a status message in the thread, its edits, the reply, then the status message deleted",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), as janitor production answered or as the session script posted",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:26:17.018Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525976",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525976.260709\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"uz3\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525976.260709\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH63VG21K\",\"event_time\":1794525976,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:19.965Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525979",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525979.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"b6\\/L\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"3CmG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525979.000200\",\"event_ts\":\"1794525979.000200\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9DGLH7Y\",\"event_time\":1794525979,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:23.456Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525982",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525982.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"pfu\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525979.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"VAX\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525982.000300\",\"event_ts\":\"1794525982.000300\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHD9ANC01\",\"event_time\":1794525982,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:26.299Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525985",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525985.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"10Wy2\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525982.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"Ydc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525985.000400\",\"event_ts\":\"1794525985.000400\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHF3R58TW\",\"event_time\":1794525985,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:29.336Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525988",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525988.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"+YN\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525985.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"14oq\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525988.000500\",\"event_ts\":\"1794525988.000500\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHB71C658\",\"event_time\":1794525988,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:32.037Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525991",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525991.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"pWp\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525988.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"wOn\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525991.000600\",\"event_ts\":\"1794525991.000600\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH55RV291\",\"event_time\":1794525991,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:35.148Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525995",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525995.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"5uL6\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525991.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"o580\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525995.000700\",\"event_ts\":\"1794525995.000700\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW1F94DD\",\"event_time\":1794525995,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:36.902Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525996",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525996.616959\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"What would you like me to do with \\u201cH2\\u201d\\u2014find a mention, or something else?\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"reply\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"f9Q1NP\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"What would you like me to do with \\u201cH2\\u201d\\u2014find a mention, or something else?\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525996.616959\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHD9CG3U1\",\"event_time\":1794525996,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:37.884Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525997",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_deleted\",\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525995.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"zwq7Z\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"deleted_ts\":\"1794525976.260709\",\"event_ts\":\"1794525997.000900\",\"ts\":\"1794525997.000900\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ5PK9LBS\",\"event_time\":1794525997,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-code-mention.json b/packages/chat/slack/test/fixtures/events/human-code-mention.json
new file mode 100644
index 00000000000..d80c7660391
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-code-mention.json
@@ -0,0 +1,21 @@
+{
+  "case": "H6: a literal @janitor inside inline code. Slack made no mention of it, so no app_mention came",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:28:12.537Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526092",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U080YLYB277\",\"ts\":\"1794526092.227099\",\"client_msg_id\":\"a0386042-19ac-4815-b509-faf89f434a6b\",\"text\":\"H6 `@janitor` \",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"gCKmr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H6 \"},{\"type\":\"text\",\"text\":\"@janitor \",\"style\":{\"code\":true}}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526092.227099\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW1RRRD5\",\"event_time\":1794526092,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-edit-adds-mention.json b/packages/chat/slack/test/fixtures/events/human-edit-adds-mention.json
new file mode 100644
index 00000000000..78ca2481690
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-edit-adds-mention.json
@@ -0,0 +1,37 @@
+{
+  "case": "H3: a message without a mention, edited to add one. The edit gave a message_changed and an app_mention carrying edited",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:26:28.004Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525987",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U080YLYB277\",\"ts\":\"1794525987.734039\",\"client_msg_id\":\"5b3a793b-0ca1-41d7-99d9-9590f7f50ac4\",\"text\":\"H3 no mention yet\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"KyCld\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H3 no mention yet\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525987.734039\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHD9B5VSM\",\"event_time\":1794525987,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:44.999Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526004",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"edited\":{\"user\":\"U080YLYB277\",\"ts\":\"1794526004.000000\"},\"client_msg_id\":\"5b3a793b-0ca1-41d7-99d9-9590f7f50ac4\",\"text\":\"H3 <@U0CCLMD4S1L> mention added\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"TlWRb\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H3 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention added\"}]}]}],\"ts\":\"1794525987.734039\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794525987.734039\",\"client_msg_id\":\"5b3a793b-0ca1-41d7-99d9-9590f7f50ac4\",\"text\":\"H3 no mention yet\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"KyCld\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H3 no mention yet\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526004.001100\",\"event_ts\":\"1794526004.001100\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH63YKJN9\",\"event_time\":1794526004,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:45.073Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526024",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"app_mention\",\"user\":\"U080YLYB277\",\"ts\":\"1794525987.734039\",\"edited\":{\"user\":\"U080YLYB277\",\"ts\":\"1794526004.000000\"},\"client_msg_id\":\"5b3a793b-0ca1-41d7-99d9-9590f7f50ac4\",\"text\":\"H3 <@U0CCLMD4S1L> mention added\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"TlWRb\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H3 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention added\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525987.734039\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH55TL6QK\",\"event_time\":1794525987,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-edit-keeps-mention.json b/packages/chat/slack/test/fixtures/events/human-edit-keeps-mention.json
new file mode 100644
index 00000000000..bacad1c34f9
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-edit-keeps-mention.json
@@ -0,0 +1,45 @@
+{
+  "case": "H5: a message that mentions the bot, edited with the mention kept, then a message_changed after thread replies",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:27:37.287Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526057",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U080YLYB277\",\"ts\":\"1794526057.057629\",\"client_msg_id\":\"08e4fbe1-2069-4589-be8e-9d80d0c2ab5b\",\"text\":\"H5 <@U0CCLMD4S1L> first\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"FehUf\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H5 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" first\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526057.057629\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHF3YMK1A\",\"event_time\":1794526057,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:27:37.363Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526057",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"app_mention\",\"user\":\"U080YLYB277\",\"ts\":\"1794526057.057629\",\"client_msg_id\":\"08e4fbe1-2069-4589-be8e-9d80d0c2ab5b\",\"text\":\"H5 <@U0CCLMD4S1L> first\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"FehUf\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H5 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" first\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526057.057629\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW1MT7AT\",\"event_time\":1794526057,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:27:44.903Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526064",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"edited\":{\"user\":\"U080YLYB277\",\"ts\":\"1794526064.000000\"},\"client_msg_id\":\"08e4fbe1-2069-4589-be8e-9d80d0c2ab5b\",\"text\":\"H5 <@U0CCLMD4S1L> edited\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526057.057629\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526058.717659\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"zXiSr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H5 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" edited\"}]}]}],\"ts\":\"1794526057.057629\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794526057.057629\",\"client_msg_id\":\"08e4fbe1-2069-4589-be8e-9d80d0c2ab5b\",\"text\":\"H5 <@U0CCLMD4S1L> first\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526057.057629\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526058.717659\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":true,\"last_read\":\"1794526057.057629\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"FehUf\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H5 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" first\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526064.002200\",\"event_ts\":\"1794526064.002200\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH6450HAR\",\"event_time\":1794526064,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:27:55.212Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526074",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"edited\":{\"user\":\"U080YLYB277\",\"ts\":\"1794526064.000000\"},\"client_msg_id\":\"08e4fbe1-2069-4589-be8e-9d80d0c2ab5b\",\"text\":\"H5 <@U0CCLMD4S1L> edited\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526057.057629\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526072.959879\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"zXiSr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H5 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" edited\"}]}]}],\"ts\":\"1794526057.057629\"},\"previous_message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794526057.057629\",\"edited\":{\"user\":\"U080YLYB277\",\"ts\":\"1794526064.000000\"},\"client_msg_id\":\"08e4fbe1-2069-4589-be8e-9d80d0c2ab5b\",\"text\":\"H5 <@U0CCLMD4S1L> edited\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526057.057629\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526072.959879\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"zXiSr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H5 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" edited\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526074.002900\",\"event_ts\":\"1794526074.002900\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH645QLDT\",\"event_time\":1794526074,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-edit-removes-mention.json b/packages/chat/slack/test/fixtures/events/human-edit-removes-mention.json
new file mode 100644
index 00000000000..afbee0b6713
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-edit-removes-mention.json
@@ -0,0 +1,45 @@
+{
+  "case": "H4: a message that mentions the bot, a message_changed after its first thread reply, then the edit removing the mention",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:27:05.063Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526024",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U080YLYB277\",\"ts\":\"1794526024.326099\",\"client_msg_id\":\"1b1e1d6f-67c3-4518-bfe2-2617a8297f5b\",\"text\":\"H4 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"R6gDK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H4 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526024.326099\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9DMH2Q6\",\"event_time\":1794526024,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:27:05.201Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526024",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"app_mention\",\"user\":\"U080YLYB277\",\"ts\":\"1794526024.326099\",\"client_msg_id\":\"1b1e1d6f-67c3-4518-bfe2-2617a8297f5b\",\"text\":\"H4 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"R6gDK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H4 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526024.326099\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9DMMFSS\",\"event_time\":1794526024,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:27:17.159Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526037",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"client_msg_id\":\"1b1e1d6f-67c3-4518-bfe2-2617a8297f5b\",\"text\":\"H4 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526024.326099\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526036.095559\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"R6gDK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H4 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}],\"ts\":\"1794526024.326099\"},\"previous_message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794526024.326099\",\"client_msg_id\":\"1b1e1d6f-67c3-4518-bfe2-2617a8297f5b\",\"text\":\"H4 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526024.326099\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526036.095559\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"R6gDK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H4 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526036.001800\",\"event_ts\":\"1794526036.001800\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH6429XJR\",\"event_time\":1794526036,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:27:21.734Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526041",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"edited\":{\"user\":\"U080YLYB277\",\"ts\":\"1794526041.000000\"},\"client_msg_id\":\"1b1e1d6f-67c3-4518-bfe2-2617a8297f5b\",\"text\":\"H4 mention removed\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526024.326099\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526036.095559\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"VOPJM\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H4 mention removed\"}]}]}],\"ts\":\"1794526024.326099\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794526024.326099\",\"client_msg_id\":\"1b1e1d6f-67c3-4518-bfe2-2617a8297f5b\",\"text\":\"H4 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794526024.326099\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526036.095559\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":true,\"last_read\":\"1794526024.326099\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"R6gDK\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H4 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526041.001900\",\"event_ts\":\"1794526041.001900\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH55XPQ1Z\",\"event_time\":1794526041,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-file-mention.json b/packages/chat/slack/test/fixtures/events/human-file-mention.json
new file mode 100644
index 00000000000..be316de3df0
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-file-mention.json
@@ -0,0 +1,55 @@
+{
+  "case": "H8: a file upload whose comment mentions the bot (file_share message and app_mention), then a message_changed after its first thread reply",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:29:07.390Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526147",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"text\":\"H8 <@U0CCLMD4S1L> file\",\"files\":[{\"id\":\"F0CDY7WPKU5\",\"created\":1793617539,\"timestamp\":1793617539,\"mimetype\":\"image\\/svg+xml\",\"filetype\":\"svg\",\"pretty_type\":\"SVG\",\"user\":\"U080YLYB277\",\"user_team\":\"T05479Z6JBW\",\"editable\":false,\"size\":1023,\"mode\":\"hosted\",\"is_external\":false,\"external_type\":\"\",\"is_public\":true,\"public_url_shared\":false,\"display_as_bot\":false,\"username\":\"\",\"name\":\"T3.svg\",\"title\":\"T3.svg\",\"is_modified_by_ai\":false,\"url_private\":\"https:\\/\\/scrubbed.invalid\\/url_private\",\"url_private_download\":\"https:\\/\\/scrubbed.invalid\\/url_private_download\",\"media_display_type\":\"unknown\",\"permalink\":\"https:\\/\\/scrubbed.invalid\\/permalink\",\"permalink_public\":\"https:\\/\\/scrubbed.invalid\\/permalink_public\",\"skipped_shares\":true,\"has_rich_preview\":false,\"file_access\":\"visible\"}],\"upload\":false,\"user\":\"U080YLYB277\",\"display_as_bot\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"vmQq2\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H8 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" file\"}]}]}],\"ts\":\"1794526147.127619\",\"client_msg_id\":\"bfaeb4c3-06ae-4962-9914-45b76bf4236f\",\"channel\":\"C0CH1LGJ4F3\",\"subtype\":\"file_share\",\"event_ts\":\"1794526147.127619\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH64E434M\",\"event_time\":1794526147,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "permalink",
+        "permalink_public",
+        "url_private",
+        "url_private_download"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:29:07.554Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526147",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"app_mention\",\"text\":\"H8 <@U0CCLMD4S1L> file\",\"files\":[{\"id\":\"F0CDY7WPKU5\",\"created\":1793617539,\"timestamp\":1793617539,\"mimetype\":\"image\\/svg+xml\",\"filetype\":\"svg\",\"pretty_type\":\"SVG\",\"user\":\"U080YLYB277\",\"user_team\":\"T05479Z6JBW\",\"editable\":false,\"size\":1023,\"mode\":\"hosted\",\"is_external\":false,\"external_type\":\"\",\"is_public\":true,\"public_url_shared\":false,\"display_as_bot\":false,\"username\":\"\",\"name\":\"T3.svg\",\"title\":\"T3.svg\",\"is_modified_by_ai\":false,\"url_private\":\"https:\\/\\/scrubbed.invalid\\/url_private\",\"url_private_download\":\"https:\\/\\/scrubbed.invalid\\/url_private_download\",\"media_display_type\":\"unknown\",\"permalink\":\"https:\\/\\/scrubbed.invalid\\/permalink\",\"permalink_public\":\"https:\\/\\/scrubbed.invalid\\/permalink_public\",\"is_starred\":false,\"skipped_shares\":true,\"has_rich_preview\":false,\"file_access\":\"visible\"}],\"upload\":false,\"user\":\"U080YLYB277\",\"display_as_bot\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"vmQq2\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H8 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" file\"}]}]}],\"ts\":\"1794526147.127619\",\"client_msg_id\":\"bfaeb4c3-06ae-4962-9914-45b76bf4236f\",\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526147.127619\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9E0NN14\",\"event_time\":1794526147,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}",
+      "scrubbed": [
+        "permalink",
+        "permalink_public",
+        "url_private",
+        "url_private_download"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:29:25.636Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526187",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"text\":\"H8 <@U0CCLMD4S1L> file\",\"files\":[{\"id\":\"F0CDY7WPKU5\",\"created\":1793617539,\"timestamp\":1793617539,\"mimetype\":\"image\\/svg+xml\",\"filetype\":\"svg\",\"pretty_type\":\"SVG\",\"user\":\"U080YLYB277\",\"user_team\":\"T05479Z6JBW\",\"editable\":false,\"size\":1023,\"mode\":\"hosted\",\"is_external\":false,\"external_type\":\"\",\"is_public\":true,\"public_url_shared\":false,\"display_as_bot\":false,\"username\":\"\",\"name\":\"T3.svg\",\"title\":\"T3.svg\",\"is_modified_by_ai\":false,\"url_private\":\"https:\\/\\/scrubbed.invalid\\/url_private\",\"url_private_download\":\"https:\\/\\/scrubbed.invalid\\/url_private_download\",\"media_display_type\":\"unknown\",\"permalink\":\"https:\\/\\/scrubbed.invalid\\/permalink\",\"permalink_public\":\"https:\\/\\/scrubbed.invalid\\/permalink_public\",\"skipped_shares\":true,\"has_rich_preview\":false,\"file_access\":\"visible\"}],\"upload\":false,\"user\":\"U080YLYB277\",\"display_as_bot\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"vmQq2\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H8 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" file\"}]}]}],\"type\":\"message\",\"client_msg_id\":\"bfaeb4c3-06ae-4962-9914-45b76bf4236f\",\"thread_ts\":\"1794526147.127619\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526163.740459\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"ts\":\"1794526147.127619\"},\"previous_message\":{\"text\":\"H8 <@U0CCLMD4S1L> file\",\"files\":[{\"id\":\"F0CDY7WPKU5\",\"created\":1793617539,\"timestamp\":1793617539,\"mimetype\":\"image\\/svg+xml\",\"filetype\":\"svg\",\"pretty_type\":\"SVG\",\"user\":\"U080YLYB277\",\"user_team\":\"T05479Z6JBW\",\"editable\":false,\"size\":1023,\"mode\":\"hosted\",\"is_external\":false,\"external_type\":\"\",\"is_public\":true,\"public_url_shared\":false,\"display_as_bot\":false,\"username\":\"\",\"name\":\"T3.svg\",\"title\":\"T3.svg\",\"is_modified_by_ai\":false,\"url_private\":\"https:\\/\\/scrubbed.invalid\\/url_private\",\"url_private_download\":\"https:\\/\\/scrubbed.invalid\\/url_private_download\",\"media_display_type\":\"unknown\",\"permalink\":\"https:\\/\\/scrubbed.invalid\\/permalink\",\"permalink_public\":\"https:\\/\\/scrubbed.invalid\\/permalink_public\",\"is_starred\":false,\"skipped_shares\":true,\"has_rich_preview\":false,\"file_access\":\"visible\"}],\"upload\":false,\"user\":\"U080YLYB277\",\"display_as_bot\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"vmQq2\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H8 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" file\"}]}]}],\"type\":\"message\",\"ts\":\"1794526147.127619\",\"client_msg_id\":\"bfaeb4c3-06ae-4962-9914-45b76bf4236f\",\"thread_ts\":\"1794526147.127619\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526163.740459\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526164.003900\",\"event_ts\":\"1794526164.003900\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW201CQP\",\"event_time\":1794526164,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "permalink",
+        "permalink_public",
+        "url_private",
+        "url_private_download"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-me-message.json b/packages/chat/slack/test/fixtures/events/human-me-message.json
new file mode 100644
index 00000000000..f7fd7a1ddc4
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-me-message.json
@@ -0,0 +1,29 @@
+{
+  "case": "H7: a /me line that mentions the bot; the app_mention arrived before the message, both with subtype me_message",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:28:30.070Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526109",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"app_mention\",\"subtype\":\"me_message\",\"user\":\"U080YLYB277\",\"ts\":\"1794526109.798279\",\"text\":\"H7 waves at <@U0CCLMD4S1L|janitor2>\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"xhNF0\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H7 waves at \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526109.798279\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH564V6R1\",\"event_time\":1794526109,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:28:30.533Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526109",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"me_message\",\"user\":\"U080YLYB277\",\"ts\":\"1794526109.798279\",\"text\":\"H7 waves at <@U0CCLMD4S1L|janitor2>\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"c\\/w\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H7 waves at \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526109.798279\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ5PX7ETA\",\"event_time\":1794526109,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-mention.json b/packages/chat/slack/test/fixtures/events/human-mention.json
new file mode 100644
index 00000000000..fee715cdaca
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-mention.json
@@ -0,0 +1,37 @@
+{
+  "case": "H2: a message that mentions the bot (message and app_mention), then the message_changed Slack sent for it after its first thread reply",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:26:14.684Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525974",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U080YLYB277\",\"ts\":\"1794525974.374799\",\"client_msg_id\":\"01614a30-5733-45d7-8932-c69a80d4b5f7\",\"text\":\"H2 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"NcHtr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H2 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525974.374799\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH55QC66P\",\"event_time\":1794525974,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:14.751Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525974",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"app_mention\",\"user\":\"U080YLYB277\",\"ts\":\"1794525974.374799\",\"client_msg_id\":\"01614a30-5733-45d7-8932-c69a80d4b5f7\",\"text\":\"H2 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"NcHtr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H2 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525974.374799\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH55QEKB5\",\"event_time\":1794525974,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:26:38.409Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525997",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"client_msg_id\":\"01614a30-5733-45d7-8932-c69a80d4b5f7\",\"text\":\"H2 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525974.374799\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794525996.616959\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"NcHtr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H2 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}],\"ts\":\"1794525974.374799\"},\"previous_message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794525974.374799\",\"client_msg_id\":\"01614a30-5733-45d7-8932-c69a80d4b5f7\",\"text\":\"H2 <@U0CCLMD4S1L> mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525974.374799\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794525996.616959\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"NcHtr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H2 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" mention\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525997.001000\",\"event_ts\":\"1794525997.001000\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHB72ALMQ\",\"event_time\":1794525997,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-plain.json b/packages/chat/slack/test/fixtures/events/human-plain.json
new file mode 100644
index 00000000000..22ae496892f
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-plain.json
@@ -0,0 +1,29 @@
+{
+  "case": "H1: a plain message without a mention, then the message_changed Slack sent for it after thread replies were added",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:25:54.192Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794525954",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U080YLYB277\",\"ts\":\"1794525953.901839\",\"client_msg_id\":\"0bdcb308-6582-479d-92bf-52a76ea9362c\",\"text\":\"H1 plain message, no mention\",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"yB8jc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H1 plain message, no mention\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525953.901839\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9DE3TF0\",\"event_time\":1794525953,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:30:54.029Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526253",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"client_msg_id\":\"0bdcb308-6582-479d-92bf-52a76ea9362c\",\"text\":\"H1 plain message, no mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525953.901839\",\"reply_count\":2,\"reply_users_count\":2,\"latest_reply\":\"1794526252.008029\",\"reply_users\":[\"U080YLYB277\",\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"yB8jc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H1 plain message, no mention\"}]}]}],\"ts\":\"1794525953.901839\"},\"previous_message\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794525953.901839\",\"client_msg_id\":\"0bdcb308-6582-479d-92bf-52a76ea9362c\",\"text\":\"H1 plain message, no mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525953.901839\",\"reply_count\":2,\"reply_users_count\":2,\"latest_reply\":\"1794526252.008029\",\"reply_users\":[\"U080YLYB277\",\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"yB8jc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H1 plain message, no mention\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526253.007100\",\"event_ts\":\"1794526253.007100\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW2CD895\",\"event_time\":1794526253,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-reactions.json b/packages/chat/slack/test/fixtures/events/human-reactions.json
new file mode 100644
index 00000000000..790c86f8f30
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-reactions.json
@@ -0,0 +1,61 @@
+{
+  "case": "Reactions on H1: +1, +1::skin-tone-3 and the custom emoji effect, each added and then removed",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:30:00.643Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526200",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U080YLYB277\",\"reaction\":\"+1\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794525953.901839\",\"channel_type\":\"group\"},\"item_user\":\"U080YLYB277\",\"event_ts\":\"1794526200.004600\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ5Q7DLUQ\",\"event_time\":1794526200,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:30:02.690Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526202",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_removed\",\"user\":\"U080YLYB277\",\"reaction\":\"+1\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794525953.901839\",\"channel_type\":\"group\"},\"item_user\":\"U080YLYB277\",\"event_ts\":\"1794526202.004800\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH64LTKGV\",\"event_time\":1794526202,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX3JlbW92ZWQiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:30:15.245Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526215",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U080YLYB277\",\"reaction\":\"+1::skin-tone-3\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794525953.901839\",\"channel_type\":\"group\"},\"item_user\":\"U080YLYB277\",\"event_ts\":\"1794526215.005300\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ5QAF5JL\",\"event_time\":1794526215,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:30:19.605Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526219",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_removed\",\"user\":\"U080YLYB277\",\"reaction\":\"+1::skin-tone-3\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794525953.901839\",\"channel_type\":\"group\"},\"item_user\":\"U080YLYB277\",\"event_ts\":\"1794526219.005500\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9EARFE2\",\"event_time\":1794526219,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX3JlbW92ZWQiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:30:25.029Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526224",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U080YLYB277\",\"reaction\":\"effect\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794525953.901839\",\"channel_type\":\"group\"},\"item_user\":\"U080YLYB277\",\"event_ts\":\"1794526224.005800\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHF4KCNMA\",\"event_time\":1794526224,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:30:28.577Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526228",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_removed\",\"user\":\"U080YLYB277\",\"reaction\":\"effect\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794525953.901839\",\"channel_type\":\"group\"},\"item_user\":\"U080YLYB277\",\"event_ts\":\"1794526228.006000\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH64R4FBP\",\"event_time\":1794526228,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX3JlbW92ZWQiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/human-thread-broadcast.json b/packages/chat/slack/test/fixtures/events/human-thread-broadcast.json
new file mode 100644
index 00000000000..4e0099b6b9e
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/human-thread-broadcast.json
@@ -0,0 +1,37 @@
+{
+  "case": "H9: a thread reply under H1 that mentions the bot, sent with also send to channel: thread_broadcast message, a message_changed, and a thread_broadcast app_mention",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:29:47.283Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526187",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"thread_broadcast\",\"user\":\"U080YLYB277\",\"thread_ts\":\"1794525953.901839\",\"root\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794525953.901839\",\"client_msg_id\":\"0bdcb308-6582-479d-92bf-52a76ea9362c\",\"text\":\"H1 plain message, no mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525953.901839\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526187.055299\",\"reply_users\":[\"U080YLYB277\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"yB8jc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H1 plain message, no mention\"}]}]}]},\"ts\":\"1794526187.055299\",\"client_msg_id\":\"2343e36e-bd61-44a6-b1c2-449558ab3285\",\"text\":\"H9 <@U0CCLMD4S1L> broadcast\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"iH0Dg\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H9 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" broadcast\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526187.055299\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHB7PAKTL\",\"event_time\":1794526187,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:29:47.445Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526187",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"subtype\":\"thread_broadcast\",\"user\":\"U080YLYB277\",\"thread_ts\":\"1794525953.901839\",\"root\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794525953.901839\",\"client_msg_id\":\"0bdcb308-6582-479d-92bf-52a76ea9362c\",\"text\":\"H1 plain message, no mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525953.901839\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526187.055299\",\"reply_users\":[\"U080YLYB277\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"yB8jc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H1 plain message, no mention\"}]}]}]},\"type\":\"message\",\"client_msg_id\":\"2343e36e-bd61-44a6-b1c2-449558ab3285\",\"text\":\"H9 <@U0CCLMD4S1L> broadcast\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"iH0Dg\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H9 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" broadcast\"}]}]}],\"ts\":\"1794526187.055299\"},\"previous_message\":{\"subtype\":\"thread_broadcast\",\"user\":\"U080YLYB277\",\"thread_ts\":\"1794525953.901839\",\"root\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794525953.901839\",\"client_msg_id\":\"0bdcb308-6582-479d-92bf-52a76ea9362c\",\"text\":\"H1 plain message, no mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525953.901839\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526187.055299\",\"reply_users\":[\"U080YLYB277\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"yB8jc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H1 plain message, no mention\"}]}]}]},\"type\":\"message\",\"ts\":\"1794526187.055299\",\"client_msg_id\":\"2343e36e-bd61-44a6-b1c2-449558ab3285\",\"text\":\"H9 <@U0CCLMD4S1L> broadcast\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"iH0Dg\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H9 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" broadcast\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526187.004100\",\"event_ts\":\"1794526187.004100\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW22MCSK\",\"event_time\":1794526187,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:29:47.627Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526187",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"app_mention\",\"subtype\":\"thread_broadcast\",\"user\":\"U080YLYB277\",\"thread_ts\":\"1794525953.901839\",\"root\":{\"user\":\"U080YLYB277\",\"type\":\"message\",\"ts\":\"1794525953.901839\",\"client_msg_id\":\"0bdcb308-6582-479d-92bf-52a76ea9362c\",\"text\":\"H1 plain message, no mention\",\"team\":\"T05479Z6JBW\",\"thread_ts\":\"1794525953.901839\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526187.055299\",\"reply_users\":[\"U080YLYB277\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"yB8jc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H1 plain message, no mention\"}]}]}]},\"ts\":\"1794526187.055299\",\"client_msg_id\":\"2343e36e-bd61-44a6-b1c2-449558ab3285\",\"text\":\"H9 <@U0CCLMD4S1L> broadcast\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"iH0Dg\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H9 \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" broadcast\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526187.055299\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW22QR4P\",\"event_time\":1794526187,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6ImFwcF9tZW50aW9uIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/stop-no-stream.json b/packages/chat/slack/test/fixtures/events/stop-no-stream.json
new file mode 100644
index 00000000000..e7ac131b053
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/stop-no-stream.json
@@ -0,0 +1,76 @@
+{
+  "case": "STOP-2: a root message with no stream, and three clicks on Stop, each with streaming_message_ts: []",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), as janitor production answered or as the session script posted; the stops by Tim Smart (U080YLYB277) clicking Stop",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:32:49.326Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526369",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794526369.028649\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"PAar\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526369.028649\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH657Q7N1\",\"event_time\":1794526369,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:32:49.380Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526369",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"RXi\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"title\":\"STOP-2\",\"date_status_processing_expire\":1794529969,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794529969,\"is_stoppable\":true}]},\"ts\":\"1794526369.028649\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794526369.028649\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"foR1o\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526369.007500\",\"event_ts\":\"1794526369.007500\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9EUMZ9C\",\"event_time\":1794526369,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:33:07.067Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526386",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526369.028649\",\"event_ts\":\"1794526386.998236\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ5QW60G0\",\"event_time\":1794526386,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:34:34.459Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526474",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526369.028649\",\"event_ts\":\"1794526474.378471\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH65J9S1K\",\"event_time\":1794526474,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:35:14.695Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526514",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526369.028649\",\"event_ts\":\"1794526514.598642\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHB8TAYBC\",\"event_time\":1794526514,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:36:08.073Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526566",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"qvM2e\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"agent_session\":{\"status\":\"active\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"title\":\"STOP-2\",\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"active\",\"is_stoppable\":true}]},\"ts\":\"1794526369.028649\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794526369.028649\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"lX=gQ\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"title\":\"STOP-2\",\"date_status_processing_expire\":1794529969,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794529969,\"is_stoppable\":true}]}},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526566.008000\",\"event_ts\":\"1794526566.008000\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH65W20HK\",\"event_time\":1794526566,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/events/stop-stream.json b/packages/chat/slack/test/fixtures/events/stop-stream.json
new file mode 100644
index 00000000000..4f1979d5175
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/events/stop-stream.json
@@ -0,0 +1,102 @@
+{
+  "case": "STOP-1: a root message, a native stream in its thread, and three clicks on Stop. Only the first agent_session_stopped names the stream; the later two carry an empty streaming_message_ts while it was still open",
+  "provenance": {
+    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
+    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
+    "author": "the janitor2 bot user (U0CCLMD4S1L), as janitor production answered or as the session script posted; the stops by Tim Smart (U080YLYB277) clicking Stop",
+    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
+    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
+    "headers": "The capture's allowlist. The signature is never logged"
+  },
+  "deliveries": [
+    {
+      "loggedAt": "2026-11-12T23:32:49.208Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526369",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794526368.981839\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-1 <@U080YLYB277> click Stop on the stream in this thread\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"lXXdG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-1 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" click Stop on the stream in this thread\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526368.981839\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH65863B7\",\"event_time\":1794526368,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:32:49.250Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526369",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-1 <@U080YLYB277> click Stop on the stream in this thread\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"xLw\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-1 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" click Stop on the stream in this thread\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"date_status_processing_expire\":1794529969,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794529969,\"is_stoppable\":true}]},\"ts\":\"1794526368.981839\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794526368.981839\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-1 <@U080YLYB277> click Stop on the stream in this thread\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"VbU\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-1 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" click Stop on the stream in this thread\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526369.007200\",\"event_ts\":\"1794526369.007200\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHDANGUHX\",\"event_time\":1794526369,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:32:49.992Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526369",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794526369.136369\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794526368.981839\",\"parent_user_id\":\"U0CCLMD4S1L\",\"streaming_state\":\"in_progress\",\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526369.136369\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHDANPU0Z\",\"event_time\":1794526369,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:33:17.113Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526397",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[\"1794526369.136369\"],\"thread_ts\":\"1794526368.981839\",\"event_ts\":\"1794526397.043711\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHDAQKQHX\",\"event_time\":1794526397,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:34:50.495Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526490",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526368.981839\",\"event_ts\":\"1794526490.421161\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH65KMBU5\",\"event_time\":1794526490,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:35:01.679Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526501",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526368.981839\",\"event_ts\":\"1794526501.600290\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHDB1MMB3\",\"event_time\":1794526501,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
+    },
+    {
+      "loggedAt": "2026-11-12T23:36:07.103Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526566",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-1 streaming. Click Stop. tick 1 tick 2 tick 3 tick 4 tick 5 tick 6 tick 7 tick 8 tick 9 tick 10 tick 11 tick 12 tick 13 tick 14 tick 15 tick 16 tick 17 tick 18 tick 19 tick 20 tick 21 tick 22 tick 23 tick 24 tick 25 tick 26 tick 27 tick 28 tick 29 tick 30 tick 31  (append after click)\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794526368.981839\",\"parent_user_id\":\"U0CCLMD4S1L\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"pCbIiy\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-1 streaming. Click Stop. tick 1 tick 2 tick 3 tick 4 tick 5 tick 6 tick 7 tick 8 tick 9 tick 10 tick 11 tick 12 tick 13 tick 14 tick 15 tick 16 tick 17 tick 18 tick 19 tick 20 tick 21 tick 22 tick 23 tick 24 tick 25 tick 26 tick 27 tick 28 tick 29 tick 30 tick 31  (append after click)\"}]}]}],\"ai_context\":{\"type\":\"default\",\"result_status\":\"stopped_by_user\",\"stopped_by_user_id\":\"U080YLYB277\"},\"streaming_state\":\"completed\",\"ts\":\"1794526369.136369\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794526369.136369\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-1 streaming. Click Stop. tick 1 tick 2 tick 3 tick 4 tick 5\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794526368.981839\",\"parent_user_id\":\"U0CCLMD4S1L\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"WhicAV\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-1 streaming. Click Stop. tick 1 tick 2 tick 3 tick 4 tick 5\"}]}]}],\"ai_context\":{\"type\":\"default\",\"result_status\":\"none\",\"stopped_by_user_id\":\"U080YLYB277\"},\"streaming_state\":\"in_progress\"},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526566.007700\",\"event_ts\":\"1794526566.007700\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW3DNVF1\",\"event_time\":1794526566,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    },
+    {
+      "loggedAt": "2026-11-12T23:36:07.506Z",
+      "headers": {
+        "x-slack-request-timestamp": "1794526566",
+        "content-type": "application/json"
+      },
+      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-1 <@U080YLYB277> click Stop on the stream in this thread\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794526368.981839\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526369.136369\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"NCu5\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-1 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" click Stop on the stream in this thread\"}]}]}],\"agent_session\":{\"status\":\"active\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"active\",\"is_stoppable\":true}]},\"ts\":\"1794526368.981839\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794526368.981839\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-1 <@U080YLYB277> click Stop on the stream in this thread\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794526368.981839\",\"reply_count\":1,\"reply_users_count\":1,\"latest_reply\":\"1794526369.136369\",\"reply_users\":[\"U0CCLMD4S1L\"],\"is_locked\":false,\"subscribed\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"N7JH\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-1 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" click Stop on the stream in this thread\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"date_status_processing_expire\":1794529969,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794529969,\"is_stoppable\":true}]}},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526566.007800\",\"event_ts\":\"1794526566.007800\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHB90A5B4\",\"event_time\":1794526566,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
+      "scrubbed": [
+        "image_36",
+        "image_48",
+        "image_72"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json b/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
index db6bcb0731d..73ab98f8747 100644
--- a/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
+++ b/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
@@ -1,5 +1,5 @@
 {
-  "source": "EFF-3676 live runs G1 to G3, as janitor received them. G2 and G3 envelopes are as in G1, which was logged in full; their event objects are verbatim.",
+  "source": "EFF-3676 live runs G1 to G3, as janitor received them. G2 and G3 envelopes are as in G1, which was logged in full; their event objects are as logged. G2's has no streaming_message_ts because that log dropped it; Slack sends an empty array (see fixtures/events/stop-no-stream.json). It is kept to show an absent field is tolerated.",
   "cases": {
     "channelThread": {
       "type": "event_callback",
diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts
index 1d5ea384aaa..ad53438fae6 100644
--- a/packages/chat/slack/test/normalize.test.ts
+++ b/packages/chat/slack/test/normalize.test.ts
@@ -20,8 +20,8 @@ const created = (events: ReadonlyArray): ChatEvent.MessageC
 
 /**
  * A `message` and an `app_mention` envelope built from one read-back message,
- * checked as a pair. This shows the two shapes normalise alike. It is not a
- * captured pair: Slack sends no `app_mention` for the bot's own messages.
+ * checked as a pair. This shows the two shapes normalise alike for every
+ * recorded message. It is not a captured pair: those are in `events.test.ts`.
  */
 const pair = Effect.fnUntraced(function*(
   message: Record,
diff --git a/packages/effect/src/chat/ChatEvent.ts b/packages/effect/src/chat/ChatEvent.ts
index 4f9fa7666e1..44e40a7c658 100644
--- a/packages/effect/src/chat/ChatEvent.ts
+++ b/packages/effect/src/chat/ChatEvent.ts
@@ -130,10 +130,13 @@ export type ReactionRemoved = typeof ReactionRemoved.Type
  *
  * **Details**
  *
- * - Nothing has been stopped. The streams in `messageIds` stay open and keep
- *   taking text until the consumer ends them, and the platform shows a
- *   disabled button until then.
- * - `messageIds` is empty when no stream was open.
+ * - Nothing has been stopped. The thread's streams stay open and keep taking
+ *   text until the consumer ends them, and the platform shows a disabled
+ *   button until then.
+ * - `messageIds` holds the streams the platform named. It is empty when no
+ *   stream was open, but an empty list does not mean none is: Slack names
+ *   the stream only on the first click in a thread. End the thread's reply
+ *   whatever it holds.
  * - `id` is the platform's id for the request, Slack's `event_ts`. Two
  *   deliveries of one request share it.
  * - It has no `kind`.

From e0a182714015c36e01e6938e2e11ea4d2b624cfc Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 01:40:44 +0000
Subject: [PATCH 16/89] add @effect/chat-discord

A Discord adapter for effect/chat on dfx: gateway dispatch with the
channel type lookup, the pure normalize, threads, reactions, history with
the thread opener, post-then-edit streaming, and recorded fixtures.
---
 .changeset/chat-discord.md                    |    5 +
 .changeset/config.json                        |    1 +
 README.md                                     |    1 +
 packages/chat/discord/README.md               |   27 +
 packages/chat/discord/package.json            |   71 ++
 packages/chat/discord/src/DiscordChat.ts      |  353 ++++++
 packages/chat/discord/src/index.ts            |   12 +
 packages/chat/discord/src/internal/adapter.ts |  447 +++++++
 packages/chat/discord/src/internal/errors.ts  |  140 +++
 packages/chat/discord/src/internal/length.ts  |   44 +
 .../chat/discord/src/internal/mentions.ts     |  101 ++
 .../chat/discord/src/internal/normalize.ts    |  342 +++++
 packages/chat/discord/src/internal/options.ts |   44 +
 .../chat/discord/test/DiscordChat.test.ts     |  654 ++++++++++
 .../test/fixtures/events/attachment.json      |   79 ++
 .../channel-message-without-channel-type.json |   61 +
 .../test/fixtures/events/channel-message.json |   65 +
 .../discord/test/fixtures/events/forum.json   |  119 ++
 .../test/fixtures/events/mentions.json        |  491 ++++++++
 .../test/fixtures/events/reactions.json       |  385 ++++++
 .../test/fixtures/events/reply-ping.json      |  429 +++++++
 .../test/fixtures/events/thread-messages.json |  221 ++++
 .../test/fixtures/events/thread-started.json  |  188 +++
 .../test/fixtures/events/webhook-message.json |   46 +
 .../test/fixtures/recorded/channels.json      |  181 +++
 .../test/fixtures/recorded/embeds.json        |  414 +++++++
 .../test/fixtures/recorded/errors.json        |  195 +++
 .../test/fixtures/recorded/history.json       | 1095 +++++++++++++++++
 .../test/fixtures/recorded/length.json        |  299 +++++
 .../test/fixtures/recorded/other-bots.json    |  445 +++++++
 .../discord/test/fixtures/recorded/posts.json | 1009 +++++++++++++++
 .../test/fixtures/recorded/reactions.json     |  197 +++
 .../discord/test/fixtures/recorded/users.json |  177 +++
 packages/chat/discord/test/live.test.ts       |  102 ++
 packages/chat/discord/test/normalize.test.ts  |  422 +++++++
 packages/chat/discord/test/utils.ts           |  137 +++
 packages/chat/discord/tsconfig.json           |    8 +
 packages/effect/src/chat/ChatTest.ts          |    4 -
 pnpm-lock.yaml                                |  125 ++
 tsconfig.packages.json                        |    1 +
 tsconfig.tests.json                           |    2 +
 vitest.config.ts                              |    5 +
 42 files changed, 9140 insertions(+), 4 deletions(-)
 create mode 100644 .changeset/chat-discord.md
 create mode 100644 packages/chat/discord/README.md
 create mode 100644 packages/chat/discord/package.json
 create mode 100644 packages/chat/discord/src/DiscordChat.ts
 create mode 100644 packages/chat/discord/src/index.ts
 create mode 100644 packages/chat/discord/src/internal/adapter.ts
 create mode 100644 packages/chat/discord/src/internal/errors.ts
 create mode 100644 packages/chat/discord/src/internal/length.ts
 create mode 100644 packages/chat/discord/src/internal/mentions.ts
 create mode 100644 packages/chat/discord/src/internal/normalize.ts
 create mode 100644 packages/chat/discord/src/internal/options.ts
 create mode 100644 packages/chat/discord/test/DiscordChat.test.ts
 create mode 100644 packages/chat/discord/test/fixtures/events/attachment.json
 create mode 100644 packages/chat/discord/test/fixtures/events/channel-message-without-channel-type.json
 create mode 100644 packages/chat/discord/test/fixtures/events/channel-message.json
 create mode 100644 packages/chat/discord/test/fixtures/events/forum.json
 create mode 100644 packages/chat/discord/test/fixtures/events/mentions.json
 create mode 100644 packages/chat/discord/test/fixtures/events/reactions.json
 create mode 100644 packages/chat/discord/test/fixtures/events/reply-ping.json
 create mode 100644 packages/chat/discord/test/fixtures/events/thread-messages.json
 create mode 100644 packages/chat/discord/test/fixtures/events/thread-started.json
 create mode 100644 packages/chat/discord/test/fixtures/events/webhook-message.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/channels.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/embeds.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/errors.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/history.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/length.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/other-bots.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/posts.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/reactions.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/users.json
 create mode 100644 packages/chat/discord/test/live.test.ts
 create mode 100644 packages/chat/discord/test/normalize.test.ts
 create mode 100644 packages/chat/discord/test/utils.ts
 create mode 100644 packages/chat/discord/tsconfig.json

diff --git a/.changeset/chat-discord.md b/.changeset/chat-discord.md
new file mode 100644
index 00000000000..7f8630a1562
--- /dev/null
+++ b/.changeset/chat-discord.md
@@ -0,0 +1,5 @@
+---
+"@effect/chat-discord": patch
+---
+
+Add `@effect/chat-discord`, an unstable Discord adapter for `effect/chat` built on dfx, with gateway dispatch, threads, reactions and post-then-edit streaming.
diff --git a/.changeset/config.json b/.changeset/config.json
index b641be2c2d7..be4231d482f 100644
--- a/.changeset/config.json
+++ b/.changeset/config.json
@@ -24,6 +24,7 @@
       "@effect/ai-openrouter",
       "@effect/atom-react",
       "@effect/chat-slack",
+      "@effect/chat-discord",
       "@effect/atom-solid",
       "@effect/atom-vue",
       "@effect/docgen",
diff --git a/README.md b/README.md
index 461e5c97874..f538082c1ce 100644
--- a/README.md
+++ b/README.md
@@ -85,6 +85,7 @@ This monorepo contains the core `effect` package alongside integration packages
 | [`@effect/ai-openai-compat`](packages/ai/openai-compat)               | OpenAI-compatible API provider for the Effect AI modules | [docs](https://effect.website/docs/v4/api/ai-openai-compat)        |
 | [`@effect/ai-openrouter`](packages/ai/openrouter)                     | OpenRouter provider for the Effect AI modules            | [docs](https://effect.website/docs/v4/api/ai-openrouter)           |
 | [`@effect/chat-slack`](packages/chat/slack)                           | Slack adapter for `effect/chat`                          | [docs](https://effect.website/docs/v4/api/chat-slack)              |
+| [`@effect/chat-discord`](packages/chat/discord)                       | Discord adapter for `effect/chat`                        | [docs](https://effect.website/docs/v4/api/chat-discord)            |
 | [`@effect/atom-react`](packages/atom/react)                           | React bindings for Effect Atom                           | [docs](https://effect.website/docs/v4/api/atom-react)              |
 | [`@effect/atom-solid`](packages/atom/solid)                           | SolidJS bindings for Effect Atom                         | [docs](https://effect.website/docs/v4/api/atom-solid)              |
 | [`@effect/atom-vue`](packages/atom/vue)                               | Vue bindings for Effect Atom                             | [docs](https://effect.website/docs/v4/api/atom-vue)                |
diff --git a/packages/chat/discord/README.md b/packages/chat/discord/README.md
new file mode 100644
index 00000000000..773f803cc4e
--- /dev/null
+++ b/packages/chat/discord/README.md
@@ -0,0 +1,27 @@
+# @effect/chat-discord
+
+A [Discord](https://discord.com) adapter for `effect/chat`, built on [dfx](https://github.com/tim-smart/dfx). Includes a structural gateway dispatch entry, a pure event normaliser, a default gateway layer, and every adapter op over dfx's REST client.
+
+The adapter reads message text, so the application needs the privileged **Message Content** intent, switched on in Discord's developer portal and requested in your dfx gateway config. Without it, message text is empty unless the message mentions the bot, and attachments are missing.
+
+## Installation
+
+```sh
+npm install effect dfx @effect/chat-discord
+```
+
+## Links
+
+- [Website](https://effect.website): documentation, guides, and news.
+- [Reference](https://effect.website/docs/v4/api/chat-discord): API documentation for this package.
+- [Discord](https://discord.gg/effect-ts): ask questions, share what you're building, and talk to the core team.
+- [Community](https://effect.website/community-hub): meetups and events, or bring Effect to your own.
+- [Issues](https://github.com/Effect-TS/effect/issues): bug reports and feature requests.
+
+## Let's talk
+
+Whether your team is considering Effect, rolling it out, or already running it in production, we'd love to hear from you: what you're building, what works, and what you need from Effect next.
+
+- **Talk to the maintainers.** Introduce your team on [Discord](https://discord.gg/effect-ts) or email [contact@effectful.co](mailto:contact@effectful.co). We're happy to connect privately on Slack or Discord for feedback and help with adoption.
+- **Production support.** We're exploring how to better support teams running Effect in production. If your organization has specific support needs, let's discuss them.
+- **Adoption help.** Our [adoption partners](https://effect.website/adoption-partners) offer implementation, consulting, team extension, training, and commercial support.
diff --git a/packages/chat/discord/package.json b/packages/chat/discord/package.json
new file mode 100644
index 00000000000..6edde31f495
--- /dev/null
+++ b/packages/chat/discord/package.json
@@ -0,0 +1,71 @@
+{
+  "name": "@effect/chat-discord",
+  "version": "4.1.4",
+  "type": "module",
+  "license": "MIT",
+  "description": "The Discord adapter for effect/chat",
+  "homepage": "https://effect.website",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/Effect-TS/effect.git",
+    "directory": "packages/chat/discord"
+  },
+  "bugs": {
+    "url": "https://github.com/Effect-TS/effect/issues"
+  },
+  "tags": [
+    "typescript",
+    "chat",
+    "discord"
+  ],
+  "keywords": [
+    "typescript",
+    "chat",
+    "discord"
+  ],
+  "sideEffects": [],
+  "exports": {
+    "./package.json": "./package.json",
+    ".": "./src/index.ts",
+    "./*": "./src/*.ts",
+    "./internal/*": null,
+    "./index": null,
+    "./*/index": null
+  },
+  "files": [
+    "src/**/*.ts",
+    "dist/**/*.js",
+    "dist/**/*.js.map",
+    "dist/**/*.d.ts",
+    "dist/**/*.d.ts.map",
+    "AGENTS.md",
+    "CLAUDE.md",
+    "ai-docs/**/*"
+  ],
+  "publishConfig": {
+    "access": "public",
+    "provenance": true,
+    "exports": {
+      "./package.json": "./package.json",
+      ".": "./dist/index.js",
+      "./*": "./dist/*.js",
+      "./internal/*": null,
+      "./index": null,
+      "./*/index": null
+    }
+  },
+  "scripts": {
+    "codegen": "effect-utils codegen",
+    "build": "tsc -b tsconfig.json && pnpm babel",
+    "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
+    "check": "tsc -b tsconfig.json"
+  },
+  "devDependencies": {
+    "dfx": "^1.1.1",
+    "effect": "workspace:^"
+  },
+  "peerDependencies": {
+    "dfx": "^1.1.1",
+    "effect": "workspace:^"
+  }
+}
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
new file mode 100644
index 00000000000..07c666f933f
--- /dev/null
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -0,0 +1,353 @@
+/**
+ * The Discord adapter for `effect/chat`: the `Registry` layer, the
+ * structural dispatch entry, the pure normaliser, a default gateway layer,
+ * address helpers and the scoped post options. It runs on dfx: every REST
+ * call goes through the `DiscordREST` in context.
+ *
+ * **Details**
+ *
+ * - Gateway intents: `GUILDS`, `GUILD_MESSAGES`, `GUILD_MESSAGE_REACTIONS`,
+ *   `DIRECT_MESSAGES`, `DIRECT_MESSAGE_REACTIONS` and `MESSAGE_CONTENT`.
+ *   They are set in the consumer's dfx config.
+ * - `MESSAGE_CONTENT` is a privileged intent: switch it on for the
+ *   application in Discord's developer portal. Without it, `text` is empty
+ *   on every message that doesn't mention the bot, and attachments are
+ *   missing.
+ * - Bot permissions: View Channel, Send Messages, Send Messages in Threads,
+ *   Create Public Threads, Read Message History and Attach Files.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import { DiscordGateway } from "dfx/DiscordGateway"
+import { DiscordREST } from "dfx/DiscordREST"
+import { Registry } from "effect/chat/ChatAdapter"
+import type { ChatError } from "effect/chat/ChatError"
+import type { ChatEvent, MessageCreated, ReactionAdded } from "effect/chat/ChatEvent"
+import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
+import type { ParseMention } from "effect/chat/ChatTest"
+import type { ChatThread } from "effect/chat/ChatThread"
+import * as Context from "effect/Context"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import { dual } from "effect/Function"
+import * as HttpClient from "effect/http/HttpClient"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import * as Result from "effect/Result"
+import * as Schema from "effect/Schema"
+import * as Stream from "effect/Stream"
+import * as Adapter from "./internal/adapter.ts"
+import * as Errors from "./internal/errors.ts"
+import * as Mentions from "./internal/mentions.ts"
+import * as Normalize from "./internal/normalize.ts"
+import { CurrentPostOptions } from "./internal/options.ts"
+
+/**
+ * The Discord side of the adapter, for what the core has no op for.
+ *
+ * **Details**
+ *
+ * - `botUserId` comes from `GET /users/@me`, read once. A failed read is
+ *   tried again next time.
+ * - `dispatch` takes one gateway dispatch, `{ t, d }`, and hands its
+ *   events to the `ChatHandler` one at a time. It reads `d` with a Schema
+ *   and ignores what it doesn't know, so it takes no dfx type.
+ * - When a `MESSAGE_CREATE` carries no `channel_type`, `dispatch` looks
+ *   the channel up, cached and with a five second timeout. A failed lookup
+ *   is logged and fails with `NotAccepted`. A lookup that would fail the same
+ *   way again, such as a deleted channel, is logged and the event dropped.
+ * - `guild` reads the channel, cached. `None` for a direct.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class DiscordChat extends Context.Service
+  readonly dispatch: (dispatch: {
+    readonly t: string
+    readonly d: unknown
+  }) => Effect.Effect
+  readonly guild: (thread: ChatThread) => Effect.Effect, ChatError>
+}>()("@effect/chat-discord/DiscordChat") {}
+
+/** The dispatches `normalize` reads. */
+const handled = new Set(["MESSAGE_CREATE", "MESSAGE_REACTION_ADD", "MESSAGE_REACTION_REMOVE"])
+
+const lookupTimeout = Duration.seconds(5)
+
+/**
+ * Registers the Discord adapter in the `Registry`.
+ *
+ * **Details**
+ *
+ * - Every REST call goes through the `DiscordREST` in context. dfx waits on
+ *   its rate-limit buckets and sends again after a 429, so a rate limit
+ *   shows up as a slower call. `HttpClient` is used only to download
+ *   attachments from Discord's CDN, with no token.
+ * - Content goes out as written: Discord reads Markdown itself. Every write
+ *   sends `allowed_mentions: { parse: [] }` and the `SUPPRESS_EMBEDS`
+ *   flag, on the post and on every edit, unless `withPostOptions` says
+ *   otherwise. A reply does not ping its author.
+ * - `post` and `edit` fail with `TooLarge` before calling Discord past
+ *   2,000 code points.
+ * - `replyTo` sends a message reference.
+ * - Only `DEFAULT`, `REPLY`, `CHAT_INPUT_COMMAND` and
+ *   `CONTEXT_MENU_COMMAND` messages are messages. A forward, a poll, a
+ *   sticker or a components-only message is `DEFAULT` and comes through,
+ *   often with `text: ""`. Its content stays on `raw`.
+ * - A deferred command reply arrives empty. Its text comes in a later edit,
+ *   which is not delivered, so only `history` and `fetchMessage` have it.
+ * - A webhook message has the webhook id as its author id and `isBot`.
+ *   `getUser` on that id fails `NotFound`.
+ * - A mention is reported when its token is in `content` outside code and
+ *   Discord says it resolved. A reply that pings its author is not a
+ *   mention. Only the bot's user mention is `isSelf`: a mention of its
+ *   managed role is the consumer's to recognise.
+ * - The address of a thread is its channel id. `startThread` names the
+ *   thread after the message's text, cut to 100 characters, and gives the
+ *   existing thread when the message already has one.
+ * - `history` of a thread started from a message puts the opener, from the
+ *   parent channel, in place of Discord's placeholder. When the opener is
+ *   deleted it starts at the first reply. A forum post's starter is in the
+ *   thread itself.
+ * - `getUser` with `in` gives the guild nick.
+ * - There is no native streaming: streamed replies post, then edit, at
+ *   least 1.5 seconds apart.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layer: Layer.Layer = Layer.effect(
+  DiscordChat,
+  Effect.gen(function*() {
+    const rest = yield* DiscordREST
+    const http = yield* HttpClient.HttpClient
+    const registry = yield* Registry
+    let cached: string | undefined
+    const botUserId: Effect.Effect = Effect.suspend(() => {
+      if (cached !== undefined) return Effect.succeed(cached)
+      return rest.getMyUser().pipe(
+        Effect.mapError((error) => Errors.chatError("botUserId", Errors.reasonForRestError(error, { write: false }))),
+        Effect.flatMap((user) => {
+          if (typeof user.id !== "string" || user.id === "") {
+            return Effect.fail(Errors.chatError("botUserId", Errors.invalidResponse(false, "missing_user_id")))
+          }
+          cached = user.id
+          return Effect.succeed(user.id)
+        })
+      )
+    })
+    const { adapter, channelType, guild } = yield* Adapter.make({ rest, http, botUserId })
+    yield* registry.register(adapter)
+
+    const refuse = (message: string, error: ChatError) =>
+      Effect.andThen(Effect.logWarning(message, error), Effect.fail(new NotAccepted()))
+
+    const dispatch = Effect.fnUntraced(function*(payload: { readonly t: string; readonly d: unknown }) {
+      if (!handled.has(payload.t)) return
+      const handler = yield* ChatHandler
+      const self = yield* Effect.catch(botUserId, (error) => refuse("discord dispatch: bot user lookup failed", error))
+      let result = Normalize.normalize(payload, { botUserId: self })
+      if (result._tag === "MissingChannelType") {
+        const lookup = yield* channelType(result.channelId).pipe(
+          Effect.timeoutOrElse({
+            duration: lookupTimeout,
+            orElse: () => Effect.fail(Errors.chatError("dispatch", Errors.transport(false, "lookup_timeout")))
+          }),
+          Effect.map(Option.some),
+          Effect.catch((error) =>
+            error.retry === "denied"
+              ? Effect.as(
+                Effect.logWarning("discord dispatch: channel lookup denied, event dropped", error),
+                Option.none()
+              )
+              : refuse("discord dispatch: channel lookup failed", error)
+          )
+        )
+        if (Option.isNone(lookup)) return
+        result = Normalize.normalize(payload, { botUserId: self, channelType: lookup.value })
+        if (result._tag === "MissingChannelType") return
+      }
+      for (const event of result.events) yield* handler.handle(event)
+    })
+
+    return DiscordChat.of({ botUserId, dispatch, guild })
+  })
+)
+
+/**
+ * The address of a Discord channel, thread or direct: its channel id.
+ *
+ * @stability unstable
+ * @category constructors
+ * @since 4.1.5
+ */
+export const thread: (channelId: string) => ChatThread = Normalize.thread
+
+/**
+ * Error for a message whose channel type is in neither the payload nor the
+ * context, from `normalize`.
+ *
+ * @stability unstable
+ * @category errors
+ * @since 4.1.5
+ */
+export class MissingChannelType extends Schema.TaggedError(
+  "@effect/chat-discord/DiscordChat/MissingChannelType"
+)("MissingChannelType", { channelId: Schema.String }) {}
+
+/**
+ * The normaliser behind `dispatch`, without delivering.
+ *
+ * **Details**
+ *
+ * - Pure: it never looks a channel up. It reads the channel type from the
+ *   payload's `channel_type`, then from `context.channelType`, Discord's
+ *   numeric type, and fails with `MissingChannelType` when neither has one.
+ * - Types 10, 11 and 12 are a `thread`, 1 and 3 a `direct`, and every
+ *   other type a `channel`.
+ * - `MESSAGE_CREATE`, `MESSAGE_REACTION_ADD` and
+ *   `MESSAGE_REACTION_REMOVE` give an event. Every other dispatch, and a
+ *   message type that is not a message, gives none.
+ * - A custom emoji is `custom:{name}`, its id left on `raw.emoji.id`.
+ * - `raw` is `d`, undecoded.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const normalize = (
+  dispatch: { readonly t: string; readonly d: unknown },
+  context: { readonly botUserId: string; readonly channelType?: number | undefined }
+): Result.Result, MissingChannelType> => {
+  const result = Normalize.normalize(dispatch, context)
+  return result._tag === "Events"
+    ? Result.succeed(result.events)
+    : Result.fail(new MissingChannelType({ channelId: result.channelId }))
+}
+
+/**
+ * The member on a message's or added reaction's `raw`: the guild, the
+ * roles and the nick.
+ *
+ * **Details**
+ *
+ * Pure, with no REST call. `None` for a direct, a webhook message, or a
+ * payload with no member. Discord sends no member on a removed reaction, so
+ * it takes none.
+ *
+ * @stability unstable
+ * @category accessors
+ * @since 4.1.5
+ */
+export const member = (event: MessageCreated | ReactionAdded): Option.Option<{
+  readonly guildId: string
+  readonly roles: ReadonlyArray
+  readonly nick?: string | undefined
+}> => Normalize.memberOf(event.raw)
+
+/**
+ * The guild on an event's `raw`.
+ *
+ * **Details**
+ *
+ * Pure, with no REST call. It works for every event, webhook messages and
+ * removed reactions included. `None` for a direct.
+ *
+ * @stability unstable
+ * @category accessors
+ * @since 4.1.5
+ */
+export const guildId = (event: ChatEvent): Option.Option => Normalize.guildIdOf(event.raw)
+
+/**
+ * For a long-running process: subscribes to dfx's gateway and feeds every
+ * dispatch to `DiscordChat.dispatch`, one at a time.
+ *
+ * **Details**
+ *
+ * Intents and sharding stay in the consumer's dfx config. An event that
+ * fails with `NotAccepted` is logged and dropped, since the gateway does
+ * not redeliver.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layerGateway: Layer.Layer = Layer.effectDiscard(
+  Effect.gen(function*() {
+    const gateway = yield* DiscordGateway
+    const discord = yield* DiscordChat
+    const handler = yield* ChatHandler
+    yield* gateway.dispatch.pipe(
+      Stream.runForEach((payload) => {
+        const t: unknown = payload.t
+        if (typeof t !== "string") return Effect.void
+        return discord.dispatch({ t, d: payload.d }).pipe(
+          Effect.provideService(ChatHandler, handler),
+          Effect.catchCause((cause) => Effect.logWarning("discord gateway: event dropped", cause))
+        )
+      }),
+      Effect.forkScoped
+    )
+  })
+)
+
+/**
+ * Discord options for every write inside an effect.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface DiscordPostOptions {
+  /**
+   * Who a write may notify. Default: nobody, and a reply does not ping its
+   * author. `everyone` allows `@everyone` and `@here`.
+   */
+  readonly notify?: {
+    readonly users?: ReadonlyArray | undefined
+    readonly roles?: ReadonlyArray | undefined
+    readonly everyone?: boolean | undefined
+    readonly repliedUser?: boolean | undefined
+  } | undefined
+  /**
+   * Link embeds. Default true, which sends the `SUPPRESS_EMBEDS` flag on
+   * the post and on every edit, so a link a later edit adds gets no embed
+   * either. False sends no flag on a post and clears it on an edit.
+   */
+  readonly suppressEmbeds?: boolean | undefined
+  /** For `startThread`, in minutes. Default: the channel's. */
+  readonly autoArchiveDuration?: 60 | 1440 | 4320 | 10080 | undefined
+}
+
+/**
+ * Scoped Discord options for every write inside `effect`. Nested calls
+ * merge, the inner one winning field by field.
+ *
+ * @stability unstable
+ * @category combinators
+ * @since 4.1.5
+ */
+export const withPostOptions: {
+  (options: DiscordPostOptions): (effect: Effect.Effect) => Effect.Effect
+  (effect: Effect.Effect, options: DiscordPostOptions): Effect.Effect
+} = dual(
+  2,
+  (effect: Effect.Effect, options: DiscordPostOptions): Effect.Effect =>
+    Effect.updateService(effect, CurrentPostOptions, (current) => ({ ...current, ...options }))
+)
+
+/**
+ * Reads one Discord mention token, `<@id>`, `<@!id>`, `<@&id>`,
+ * `<#id>`, `@everyone` or `@here`, for `ChatTest.checkMessage`,
+ * `ChatTest.checkEvent` and `ChatTest.conformance`.
+ *
+ * @stability unstable
+ * @category testing
+ * @since 4.1.5
+ */
+export const parseMention: ParseMention = (slice) => Option.fromUndefinedOr(Mentions.parseToken(slice))
diff --git a/packages/chat/discord/src/index.ts b/packages/chat/discord/src/index.ts
new file mode 100644
index 00000000000..fa6438bdf63
--- /dev/null
+++ b/packages/chat/discord/src/index.ts
@@ -0,0 +1,12 @@
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+
+// @barrel: Auto-generated exports. Do not edit manually.
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as DiscordChat from "./DiscordChat.ts"
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
new file mode 100644
index 00000000000..d8c61c6fbd0
--- /dev/null
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -0,0 +1,447 @@
+import type { DiscordREST } from "dfx/DiscordREST"
+import * as Cache from "effect/Cache"
+import {
+  type ChatAdapter,
+  checkMessageLength,
+  type Descriptor,
+  type File,
+  type Posted,
+  retrySafe,
+  type ThreadInfo,
+  type User
+} from "effect/chat/ChatAdapter"
+import { type ChatError, type ChatErrorReason, TooLarge } from "effect/chat/ChatError"
+import type { ChatMessage } from "effect/chat/ChatMessage"
+import type * as ChatThread from "effect/chat/ChatThread"
+import * as DateTime from "effect/DateTime"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Exit from "effect/Exit"
+import type * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import * as Option from "effect/Option"
+import * as Schema from "effect/Schema"
+import * as Stream from "effect/Stream"
+import * as Errors from "./errors.ts"
+import * as Length from "./length.ts"
+import * as Normalize from "./normalize.ts"
+import { allowedMentions, CurrentPostOptions, flags } from "./options.ts"
+
+type Json = Schema.Json
+type Rest = DiscordREST["Service"]
+
+/** @internal */
+export const descriptor: Descriptor = {
+  platform: Normalize.platform,
+  capabilities: new Set([
+    "edit",
+    "delete",
+    "fetchMessage",
+    "history",
+    "download",
+    "files",
+    "replyTo",
+    "startThread",
+    "getThread",
+    "opener",
+    "getUser"
+  ]),
+  measure: Length.codePoints,
+  limits: {
+    messageLength: Length.messageLength,
+    filesPerMessage: 10,
+    uploadBytes: 10 * 1024 * 1024,
+    minWriteInterval: Duration.millis(1500)
+  }
+}
+
+const pageSize = 100
+
+/** Discord's code for "a thread has already been created for this message". */
+const THREAD_ALREADY_CREATED = 160004
+/** Discord's code for "cannot execute action on this channel type". */
+const WRONG_CHANNEL_TYPE = 50024
+
+const optional = (schema: S) => Schema.optionalKey(Schema.NullOr(schema))
+
+const ChannelFields = Schema.Struct({
+  id: Schema.String,
+  type: Schema.Number,
+  guild_id: optional(Schema.String),
+  parent_id: optional(Schema.String),
+  name: optional(Schema.String),
+  topic: optional(Schema.String),
+  thread_metadata: optional(Schema.Struct({ create_timestamp: optional(Schema.String) }))
+})
+
+/**
+ * What the adapter reads from a channel.
+ *
+ * @internal
+ */
+export type Channel = typeof ChannelFields.Type & { readonly raw: Json }
+
+const decodeChannel = Schema.decodeUnknownOption(ChannelFields)
+
+const UserFields = Schema.Struct({
+  id: Schema.String,
+  username: optional(Schema.String),
+  global_name: optional(Schema.String),
+  bot: optional(Schema.Boolean)
+})
+
+const decodeUser = Schema.decodeUnknownOption(UserFields)
+
+const MemberFields = Schema.Struct({ nick: optional(Schema.String), user: optional(UserFields) })
+
+const decodeMember = Schema.decodeUnknownOption(MemberFields)
+
+const nonEmpty = (value: string | null | undefined): string | undefined =>
+  value === null || value === undefined || value === "" ? undefined : value
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+const snowflake = /^\d{1,20}$/
+
+/** @internal */
+export const make = Effect.fnUntraced(function*(options: {
+  readonly rest: Rest
+  readonly http: HttpClient.HttpClient
+  readonly botUserId: Effect.Effect
+}) {
+  const { rest } = options
+
+  const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
+
+  /** One REST call, its failure mapped to a `ChatError` and retried when nothing happened. */
+  const call = (op: string, effect: Effect.Effect, write = false): Effect.Effect =>
+    retrySafe(Effect.mapError(effect, (error) => Errors.chatError(op, Errors.reasonForRestError(error, { write }))))
+
+  const resolve = (op: string, thread: ChatThread.ChatThread): Effect.Effect =>
+    thread.platform === Normalize.platform && snowflake.test(thread.id)
+      ? Effect.succeed(thread.id)
+      : fail(op, Errors.invalidRequest("invalid_thread"))
+
+  const readChannel = (op: string, raw: unknown): Effect.Effect =>
+    Option.match(decodeChannel(raw), {
+      onNone: () => fail(op, Errors.invalidResponse(false, "invalid_channel")),
+      onSome: (fields) => Effect.succeed({ ...fields, raw: raw as Json })
+    })
+
+  /** Channels by id, for their type, parent and guild, none of which change. Failures are not kept. */
+  const channels = yield* Cache.makeWith(
+    (id: string) => Effect.flatMap(call("getChannel", rest.getChannel(id)), (raw) => readChannel("getChannel", raw)),
+    {
+      capacity: 1024,
+      timeToLive: (exit) => Exit.isSuccess(exit) ? Duration.hours(1) : Duration.zero
+    }
+  )
+
+  const channel = (op: string, id: string): Effect.Effect =>
+    Cache.get(channels, id).pipe(
+      Effect.mapError((error) => error.op === op ? error : Errors.chatError(op, error.reason))
+    )
+
+  const toMessage = (raw: unknown, botUserId: string): ChatMessage | undefined => {
+    const fields = Normalize.decodeMessageFields(raw)
+    return fields === undefined ? undefined : Normalize.message(raw as Json, fields, { botUserId })
+  }
+
+  const getMessage = (op: string, channelId: string, messageId: string): Effect.Effect =>
+    call(op, rest.getMessage(channelId, messageId)).pipe(Effect.map((raw) => raw as unknown as Json))
+
+  const fetchMessage = Effect.fnUntraced(function*(op: string, thread: ChatThread.ChatThread, messageId: string) {
+    const channelId = yield* resolve(op, thread)
+    const botUserId = yield* options.botUserId
+    const raw = yield* getMessage(op, channelId, messageId)
+    const message = toMessage(raw, botUserId)
+    return message === undefined ? yield* fail(op, Errors.notFound("not_a_message")) : message
+  })
+
+  const orNone = (effect: Effect.Effect): Effect.Effect, ChatError> =>
+    effect.pipe(
+      Effect.map(Option.some),
+      Effect.catchIf((error) => error.reason._tag === "NotFound", () => Effect.succeed(Option.none()))
+    )
+
+  // Writes
+
+  const toFile = (file: File) =>
+    new globalThis.File([file.content as Uint8Array], file.name, { type: file.contentType })
+
+  const post: ChatAdapter["post"] = Effect.fnUntraced(function*(thread, content) {
+    const op = "post"
+    const channelId = yield* resolve(op, thread)
+    const postOptions = yield* CurrentPostOptions
+    yield* checkMessageLength(descriptor, op, content.markdown)
+    const files = content.files ?? []
+    if (files.length > descriptor.limits.filesPerMessage) {
+      return yield* fail(op, new TooLarge({ subject: "files", detail: "too_many_files" }))
+    }
+    if (files.reduce((total, file) => total + file.content.length, 0) > descriptor.limits.uploadBytes) {
+      return yield* fail(op, new TooLarge({ subject: "files", detail: "upload_too_large" }))
+    }
+    const create = rest.createMessage(channelId, {
+      content: content.markdown,
+      allowed_mentions: allowedMentions(postOptions.notify),
+      flags: flags(postOptions),
+      ...(content.replyTo === undefined ? {} : { message_reference: { message_id: content.replyTo.messageId } }),
+      ...(files.length === 0 ? {} : { attachments: files.map((file, i) => ({ id: String(i), filename: file.name })) })
+    })
+    const answer = yield* call(op, files.length === 0 ? create : rest.withFiles(files.map(toFile))(create), true)
+    if (typeof answer.id !== "string" || typeof answer.timestamp !== "string") {
+      return yield* fail(op, Errors.invalidResponse(true, "missing_id"))
+    }
+    return { id: answer.id, thread, timestamp: DateTime.makeUnsafe(answer.timestamp) } satisfies Posted
+  })
+
+  const edit: ChatAdapter["edit"] = Effect.fnUntraced(function*(thread, messageId, content) {
+    const op = "edit"
+    const channelId = yield* resolve(op, thread)
+    const postOptions = yield* CurrentPostOptions
+    yield* checkMessageLength(descriptor, op, content.markdown)
+    yield* call(
+      op,
+      rest.updateMessage(channelId, messageId, {
+        content: content.markdown,
+        allowed_mentions: allowedMentions(postOptions.notify),
+        flags: flags(postOptions)
+      }),
+      true
+    )
+  })
+
+  const startThread: ChatAdapter["startThread"] = Effect.fnUntraced(function*(thread, messageId, startOptions) {
+    const op = "startThread"
+    const channelId = yield* resolve(op, thread)
+    const postOptions = yield* CurrentPostOptions
+    const given = nonEmpty(startOptions?.name?.trim())
+    const name = given ?? (yield* Effect.map(
+      getMessage(op, channelId, messageId),
+      (raw) => {
+        const text = isObject(raw) && typeof raw.content === "string" ? raw.content.replace(/\s+/g, " ").trim() : ""
+        return text === "" ? "Thread" : Length.cut(text, 100)
+      }
+    ))
+    return yield* call(
+      op,
+      rest.createThreadFromMessage(channelId, messageId, {
+        name: Length.cut(name, 100),
+        ...(postOptions.autoArchiveDuration === undefined
+          ? {}
+          : { auto_archive_duration: postOptions.autoArchiveDuration })
+      }),
+      true
+    ).pipe(
+      Effect.map((answer) => Normalize.thread(typeof answer.id === "string" ? answer.id : messageId)),
+      // The thread under a message has the message's id.
+      Effect.catchIf(Errors.hasCode(THREAD_ALREADY_CREATED), () => Effect.succeed(Normalize.thread(messageId))),
+      // A message in a thread has no thread of its own: the thread is the answer.
+      Effect.catchIf(Errors.hasCode(WRONG_CHANNEL_TYPE), (error) =>
+        Effect.flatMap(
+          channel(op, channelId),
+          (found) => Normalize.isThreadType(found.type) ? Effect.succeed(thread) : Effect.fail(error)
+        ))
+    )
+  })
+
+  // Reads
+
+  /**
+   * A thread's messages, with the `THREAD_STARTER_MESSAGE` placeholder
+   * replaced by the opener from the parent channel, or dropped when the
+   * opener is gone.
+   */
+  const history: ChatAdapter["history"] = (thread, { direction, from }) =>
+    Stream.unwrap(Effect.gen(function*() {
+      const op = "history"
+      const channelId = yield* resolve(op, thread)
+      const botUserId = yield* options.botUserId
+      const page = (cursor: string | undefined) =>
+        call(
+          op,
+          rest.listMessages(
+            channelId,
+            direction === "backward"
+              ? { ...(cursor === undefined ? {} : { before: cursor }), limit: pageSize }
+              : { after: cursor ?? "0", limit: pageSize }
+          )
+        ).pipe(Effect.map((answer) => {
+          const found: ReadonlyArray = Array.isArray(answer) ? answer as ReadonlyArray : []
+          const sorted = [...found].sort((a, b) =>
+            Normalize.compareIds(idOf(a), idOf(b)) * (direction === "backward" ? -1 : 1)
+          )
+          const last = sorted.at(-1)
+          return [
+            sorted,
+            found.length < pageSize || last === undefined ? Option.none() : Option.some(idOf(last))
+          ] as const
+        }))
+      const after = (message: ChatMessage) =>
+        from === undefined ||
+        (direction === "forward"
+          ? Normalize.compareIds(message.id, from) > 0
+          : Normalize.compareIds(message.id, from) < 0)
+      return Stream.paginate(from, page).pipe(
+        Stream.mapEffect((raw) => resolveStarter(op, raw, botUserId)),
+        Stream.filter((message): message is ChatMessage => message !== undefined && after(message))
+      )
+    }))
+
+  const idOf = (raw: Json): string => isObject(raw) && typeof raw.id === "string" ? raw.id : ""
+
+  const resolveStarter = (
+    op: string,
+    raw: Json,
+    botUserId: string
+  ): Effect.Effect => {
+    const fields = Normalize.decodeMessageFields(raw)
+    if (fields === undefined) return Effect.succeed(undefined)
+    if (fields.type !== Normalize.THREAD_STARTER_MESSAGE) {
+      return Effect.succeed(Normalize.message(raw, fields, { botUserId }))
+    }
+    const referenced = isObject(raw) ? raw.referenced_message : undefined
+    if (referenced === null) return Effect.succeed(undefined)
+    if (referenced !== undefined) return Effect.succeed(toMessage(referenced, botUserId))
+    const reference = fields.message_reference
+    const channelId = nonEmpty(reference?.channel_id)
+    const messageId = nonEmpty(reference?.message_id)
+    if (channelId === undefined || messageId === undefined) return Effect.succeed(undefined)
+    return orNone(getMessage(op, channelId, messageId)).pipe(
+      Effect.map((found) => Option.isSome(found) ? toMessage(found.value, botUserId) : undefined)
+    )
+  }
+
+  /**
+   * The message whose id is the thread's: in the thread for a forum post,
+   * otherwise in the parent channel.
+   */
+  const opener: ChatAdapter["opener"] = Effect.fnUntraced(function*(thread) {
+    const op = "opener"
+    const channelId = yield* resolve(op, thread)
+    const found = yield* channel(op, channelId)
+    if (!Normalize.isThreadType(found.type)) return Option.none()
+    const botUserId = yield* options.botUserId
+    const inThread = yield* orNone(getMessage(op, channelId, channelId))
+    const parent = nonEmpty(found.parent_id)
+    const raw = Option.isSome(inThread) || parent === undefined
+      ? inThread
+      : yield* orNone(getMessage(op, parent, channelId))
+    return Option.flatMap(raw, (raw) => Option.fromUndefinedOr(toMessage(raw, botUserId)))
+  })
+
+  const getThread: ChatAdapter["getThread"] = Effect.fnUntraced(function*(thread) {
+    const op = "getThread"
+    const channelId = yield* resolve(op, thread)
+    const found = yield* Effect.flatMap(call(op, rest.getChannel(channelId)), (raw) => readChannel(op, raw))
+    const kind = Normalize.kindOf(found.type)
+    const name = kind === "direct" ? undefined : nonEmpty(found.name)
+    const topic = nonEmpty(found.topic)
+    const parent = kind === "thread" ? nonEmpty(found.parent_id) : undefined
+    const created = nonEmpty(found.thread_metadata?.create_timestamp)
+    const createdAt = created === undefined ? Normalize.snowflakeTime(found.id) : DateTime.makeUnsafe(created)
+    return {
+      thread,
+      kind,
+      ...(name === undefined ? {} : { name }),
+      ...(topic === undefined ? {} : { topic }),
+      ...(parent === undefined ? {} : { parent: Normalize.thread(parent) }),
+      ...(createdAt === undefined ? {} : { createdAt }),
+      raw: found.raw
+    } satisfies ThreadInfo
+  })
+
+  const getUser: ChatAdapter["getUser"] = Effect.fnUntraced(function*(id, userOptions) {
+    const op = "getUser"
+    const botUserId = yield* options.botUserId
+    const where = userOptions?.in
+    const guildId = where === undefined
+      ? undefined
+      : nonEmpty((yield* channel(op, yield* resolve(op, where))).guild_id)
+    if (guildId !== undefined) {
+      const member = yield* orNone(call(op, rest.getGuildMember(guildId, id)))
+      if (Option.isSome(member)) {
+        const fields = Option.getOrUndefined(decodeMember(member.value))
+        const user = fields?.user
+        if (fields !== undefined && user !== null && user !== undefined) {
+          return {
+            id: user.id,
+            name: nonEmpty(fields.nick) ?? nonEmpty(user.global_name) ?? nonEmpty(user.username) ?? user.id,
+            isBot: user.bot === true,
+            isSelf: user.id === botUserId,
+            raw: member.value as unknown as Json
+          } satisfies User
+        }
+      }
+    }
+    const raw = yield* call(op, rest.getUser(id))
+    const user = Option.getOrUndefined(decodeUser(raw))
+    if (user === undefined) return yield* fail(op, Errors.invalidResponse(false, "invalid_user"))
+    return {
+      id: user.id,
+      name: nonEmpty(user.global_name) ?? nonEmpty(user.username) ?? user.id,
+      isBot: user.bot === true,
+      isSelf: user.id === botUserId,
+      raw: raw as unknown as Json
+    } satisfies User
+  })
+
+  const download: ChatAdapter["download"] = (thread, attachment, { maxBytes }) =>
+    Stream.unwrap(Effect.gen(function*() {
+      const op = "download"
+      const channelId = yield* resolve(op, thread)
+      const tooLarge = Errors.chatError(op, new TooLarge({ subject: "files", detail: "max_bytes" }))
+      if (attachment.size !== undefined && attachment.size > maxBytes) return yield* Effect.fail(tooLarge)
+      const ids = Normalize.parseAttachmentId(attachment.id)
+      if (ids === undefined) return yield* fail(op, Errors.invalidRequest("invalid_attachment"))
+      const raw = yield* getMessage(op, channelId, ids.messageId)
+      const list = isObject(raw) && Array.isArray(raw.attachments) ? raw.attachments : []
+      const found = list.find((item) => isObject(item) && item.id === ids.attachmentId)
+      const url = isObject(found) && typeof found.url === "string" ? found.url : undefined
+      if (url === undefined) return yield* fail(op, Errors.notFound("attachment_not_found"))
+      const response = yield* options.http.execute(HttpClientRequest.get(url)).pipe(
+        Effect.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag, error)))
+      )
+      if (response.status < 200 || response.status >= 300) {
+        return yield* fail(op, Errors.reasonForResponse(response.status, undefined, { write: false }))
+      }
+      let received = 0
+      return response.stream.pipe(
+        Stream.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag, error))),
+        Stream.mapEffect((chunk) => {
+          received += chunk.length
+          return received > maxBytes ? Effect.fail(tooLarge) : Effect.succeed(chunk)
+        })
+      )
+    }))
+
+  const adapter: ChatAdapter = {
+    descriptor,
+    post,
+    edit,
+    delete: Effect.fnUntraced(function*(thread, messageId) {
+      const channelId = yield* resolve("delete", thread)
+      yield* call("delete", rest.deleteMessage(channelId, messageId), true)
+    }),
+    fetchMessage: (thread, messageId) => fetchMessage("fetchMessage", thread, messageId),
+    history,
+    download,
+    startThread,
+    getThread,
+    opener,
+    getUser
+  }
+
+  /** The guild a channel or thread is in, from the cached channel. */
+  const guild = (thread: ChatThread.ChatThread): Effect.Effect, ChatError> =>
+    Effect.flatMap(
+      resolve("guild", thread),
+      (id) => Effect.map(channel("guild", id), (found) => Option.fromUndefinedOr(nonEmpty(found.guild_id)))
+    )
+
+  /** A channel's type, for `dispatch`. */
+  const channelType = (id: string): Effect.Effect =>
+    Effect.map(channel("dispatch", id), (found) => found.type)
+
+  return { adapter, guild, channelType }
+})
diff --git a/packages/chat/discord/src/internal/errors.ts b/packages/chat/discord/src/internal/errors.ts
new file mode 100644
index 00000000000..1eb29dcb93b
--- /dev/null
+++ b/packages/chat/discord/src/internal/errors.ts
@@ -0,0 +1,140 @@
+import {
+  ChatError,
+  type ChatErrorReason,
+  Forbidden,
+  InvalidRequest,
+  InvalidResponse,
+  NotFound,
+  PlatformUnavailable,
+  RateLimited,
+  TooLarge,
+  Transport,
+  Unauthenticated,
+  Unknown
+} from "effect/chat/ChatError"
+import * as Duration from "effect/Duration"
+import { platform } from "./normalize.ts"
+
+/** Discord's JSON error codes, by what they mean. */
+const notFoundCodes = new Set([10003, 10004, 10007, 10008, 10013, 10014, 10015])
+const forbiddenCodes = new Set([20001, 20028, 50001, 50005, 50013, 50021, 50083, 160005, 160006])
+const unauthenticatedCodes = new Set([0, 40001])
+const tooLargeFiles = new Set([40005, 50045])
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/** A 50035 whose errors say a field is too long. */
+const isTooLong = (data: Record): boolean => JSON.stringify(data.errors ?? {}).includes("MAX_LENGTH")
+
+const withCause = (cause: unknown) => (cause === undefined ? {} : { cause })
+
+/**
+ * The reason for an answer Discord sent: a JSON error `code` when there is
+ * one, otherwise the HTTP status. `detail` is the code, or `http_{status}`.
+ *
+ * @internal
+ */
+export const reasonForResponse = (
+  status: number,
+  data: unknown,
+  options: { readonly write: boolean; readonly cause?: unknown }
+): ChatErrorReason => {
+  const body = isObject(data) ? data : {}
+  const code = typeof body.code === "number" ? body.code : undefined
+  const cause = withCause(options.cause)
+  if (status === 429) {
+    const seconds = typeof body.retry_after === "number" ? body.retry_after : undefined
+    return new RateLimited({
+      detail: code === undefined ? "http_429" : String(code),
+      ...cause,
+      ...(seconds === undefined || seconds < 0 ? {} : { retryAfter: Duration.millis(Math.ceil(seconds * 1000)) })
+    })
+  }
+  if (status >= 500) {
+    return new PlatformUnavailable({ retry: options.write ? "uncertain" : "retry", detail: `http_${status}`, ...cause })
+  }
+  const detail = code === undefined ? `http_${status}` : String(code)
+  if (code !== undefined) {
+    if (notFoundCodes.has(code)) return new NotFound({ detail, ...cause })
+    if (forbiddenCodes.has(code)) return new Forbidden({ detail, ...cause })
+    if (tooLargeFiles.has(code)) return new TooLarge({ subject: "files", detail, ...cause })
+    if (code === 50035 && isTooLong(body)) return new TooLarge({ subject: "text", detail, ...cause })
+    if (unauthenticatedCodes.has(code) && status === 401) return new Unauthenticated({ detail, ...cause })
+  }
+  if (status === 401) return new Unauthenticated({ detail, ...cause })
+  if (status === 403) return new Forbidden({ detail, ...cause })
+  if (status === 404) return new NotFound({ detail, ...cause })
+  if (status === 413) return new TooLarge({ subject: "files", detail, ...cause })
+  return new InvalidRequest({ detail, ...cause })
+}
+
+/**
+ * A request that failed before an answer came.
+ *
+ * @internal
+ */
+export const transport = (write: boolean, detail: string, cause?: unknown): ChatErrorReason =>
+  new Transport({ retry: write ? "uncertain" : "retry", detail, ...withCause(cause) })
+
+/**
+ * An answer the adapter cannot read. A write may have landed.
+ *
+ * @internal
+ */
+export const invalidResponse = (write: boolean, detail: string, cause?: unknown): ChatErrorReason => {
+  const fields = { detail, ...withCause(cause) }
+  return write ? new Unknown(fields) : new InvalidResponse(fields)
+}
+
+/**
+ * The reason for a dfx `DiscordRESTError`, read structurally so no dfx
+ * type is needed: an `ErrorResponse` or `RatelimitedResponse` carries
+ * Discord's body in `data`, and an `HttpClientError` carries a `reason`.
+ *
+ * @internal
+ */
+export const reasonForRestError = (error: unknown, options: { readonly write: boolean }): ChatErrorReason => {
+  const tagged = isObject(error) ? error : {}
+  const tag = tagged._tag
+  const response = isObject(tagged.response) ? tagged.response : undefined
+  const status = typeof response?.status === "number" ? response.status : undefined
+  if (tag === "ErrorResponse" || tag === "RatelimitedResponse") {
+    return reasonForResponse(status ?? (tag === "RatelimitedResponse" ? 429 : 400), tagged.data, {
+      write: options.write,
+      cause: error
+    })
+  }
+  if (tag === "HttpClientError" && isObject(tagged.reason)) {
+    const reason = tagged.reason
+    const reasonResponse = isObject(reason.response) ? reason.response : undefined
+    const reasonStatus = typeof reasonResponse?.status === "number" ? reasonResponse.status : undefined
+    switch (reason._tag) {
+      case "StatusCodeError":
+        return reasonForResponse(reasonStatus ?? 500, undefined, { write: options.write, cause: error })
+      case "TransportError":
+        return transport(options.write, "transport", error)
+      case "EncodeError":
+      case "InvalidUrlError":
+        return new InvalidRequest({ detail: String(reason._tag), cause: error })
+      default:
+        return invalidResponse(options.write, String(reason._tag), error)
+    }
+  }
+  return new Unknown({ detail: "unknown", cause: error })
+}
+
+/** @internal */
+export const chatError = (op: string, reason: ChatErrorReason): ChatError => new ChatError({ platform, op, reason })
+
+/** @internal */
+export const invalidRequest = (detail: string): ChatErrorReason => new InvalidRequest({ detail })
+
+/** @internal */
+export const notFound = (detail: string): ChatErrorReason => new NotFound({ detail })
+
+/**
+ * Whether a failure carries Discord's JSON error code `code`.
+ *
+ * @internal
+ */
+export const hasCode = (code: number) => (error: ChatError): boolean => error.reason.detail === String(code)
diff --git a/packages/chat/discord/src/internal/length.ts b/packages/chat/discord/src/internal/length.ts
new file mode 100644
index 00000000000..6c514f99480
--- /dev/null
+++ b/packages/chat/discord/src/internal/length.ts
@@ -0,0 +1,44 @@
+/**
+ * Discord's limit on `content`, in code points, inclusive.
+ *
+ * @internal
+ */
+export const messageLength = 2000
+
+/**
+ * Code points, which is what Discord counts: a recorded probe took 2,000
+ * astral emoji (4,000 UTF-16 units) and refused 1,999 letters and a flag.
+ *
+ * @internal
+ */
+export const codePoints = (text: string): number => {
+  let count = 0
+  for (let i = 0; i < text.length; i++) {
+    const code = text.charCodeAt(i)
+    if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {
+      const low = text.charCodeAt(i + 1)
+      if (low >= 0xdc00 && low <= 0xdfff) i++
+    }
+    count++
+  }
+  return count
+}
+
+/**
+ * Cuts `text` to at most `max` code points.
+ *
+ * @internal
+ */
+export const cut = (text: string, max: number): string => {
+  let count = 0
+  for (let i = 0; i < text.length; i++) {
+    if (count === max) return text.slice(0, i)
+    const code = text.charCodeAt(i)
+    if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {
+      const low = text.charCodeAt(i + 1)
+      if (low >= 0xdc00 && low <= 0xdfff) i++
+    }
+    count++
+  }
+  return text
+}
diff --git a/packages/chat/discord/src/internal/mentions.ts b/packages/chat/discord/src/internal/mentions.ts
new file mode 100644
index 00000000000..3bc8a34868f
--- /dev/null
+++ b/packages/chat/discord/src/internal/mentions.ts
@@ -0,0 +1,101 @@
+import type { Mention } from "effect/chat/ChatMessage"
+
+type Kind = Mention["kind"]
+
+interface Target {
+  readonly kind: Kind
+  readonly id: string
+}
+
+/** A mention token as Discord writes it in `content`. */
+const tokenPattern = /<@!?(\d+)>|<@&(\d+)>|<#(\d+)>|@(everyone|here)/y
+
+const targetOf = (match: RegExpExecArray): Target => {
+  const [, user, role, channel, broadcast] = match
+  if (user !== undefined) return { kind: "user", id: user }
+  if (role !== undefined) return { kind: "role", id: role }
+  if (channel !== undefined) return { kind: "channel", id: channel }
+  return { kind: "broadcast", id: broadcast! }
+}
+
+const tokenAt = (text: string, index: number): RegExpExecArray | null => {
+  tokenPattern.lastIndex = index
+  return tokenPattern.exec(text)
+}
+
+/**
+ * Parses one token, `<@id>`, `<@!id>`, `<@&id>`, `<#id>`, `@everyone`
+ * or `@here`, as the whole of `slice`.
+ *
+ * @internal
+ */
+export const parseToken = (slice: string): Target | undefined => {
+  const match = tokenAt(slice, 0)
+  return match === null || match[0].length !== slice.length ? undefined : targetOf(match)
+}
+
+/**
+ * A token in `content` outside code, with its offsets.
+ *
+ * @internal
+ */
+export interface Token extends Target {
+  readonly start: number
+  readonly end: number
+}
+
+const isEscapable = (char: string | undefined): boolean => char !== undefined && /[^0-9A-Za-z\s]/.test(char)
+
+/** The index past the closing run of exactly `n` backticks, or -1. */
+const closingRun = (text: string, from: number, n: number): number => {
+  for (let i = from; i < text.length; i++) {
+    if (text[i] !== "`") continue
+    let run = 1
+    while (text[i + run] === "`") run++
+    if (run === n && i > from) return i + run
+    i += run - 1
+  }
+  return -1
+}
+
+/**
+ * The mention tokens in `content`, in order, skipping code blocks, inline
+ * code and tokens escaped with a backslash, as Discord's Markdown does.
+ *
+ * @internal
+ */
+export const tokens = (text: string): Array => {
+  const found: Array = []
+  let i = 0
+  while (i < text.length) {
+    const char = text[i]
+    if (char === "\\" && isEscapable(text[i + 1])) {
+      i += 2
+      continue
+    }
+    if (char === "`") {
+      let n = 1
+      while (text[i + n] === "`") n++
+      if (n >= 3) {
+        const end = text.indexOf("```", i + 3)
+        if (end !== -1) {
+          i = end + 3
+          continue
+        }
+      }
+      const end = closingRun(text, i + n, n)
+      i = end === -1 ? i + n : end
+      continue
+    }
+    if (char === "<" || char === "@") {
+      const match = tokenAt(text, i)
+      if (match !== null) {
+        found.push({ ...targetOf(match), start: i, end: i + match[0].length })
+        i += match[0].length
+        continue
+      }
+    }
+    i++
+  }
+  return found
+}
diff --git a/packages/chat/discord/src/internal/normalize.ts b/packages/chat/discord/src/internal/normalize.ts
new file mode 100644
index 00000000000..f8d9882bcbe
--- /dev/null
+++ b/packages/chat/discord/src/internal/normalize.ts
@@ -0,0 +1,342 @@
+import type { ChatEvent, ReactionAdded, ReactionRemoved, ThreadKind } from "effect/chat/ChatEvent"
+import type { Attachment, ChatMessage, Mention } from "effect/chat/ChatMessage"
+import * as ChatThread from "effect/chat/ChatThread"
+import * as DateTime from "effect/DateTime"
+import * as Option from "effect/Option"
+import * as Schema from "effect/Schema"
+import * as Mentions from "./mentions.ts"
+
+/** @internal */
+export const platform = "discord"
+
+/** @internal */
+export const thread = (channelId: string): ChatThread.ChatThread => ChatThread.make(platform, channelId)
+
+/**
+ * The message types that are a message: `DEFAULT`, `REPLY`,
+ * `CHAT_INPUT_COMMAND` and `CONTEXT_MENU_COMMAND`. Inbound and history
+ * both read it, and a type Discord adds later stays out.
+ *
+ * @internal
+ */
+export const messageTypes: ReadonlySet = new Set([0, 19, 20, 23])
+
+/** @internal */
+export const REPLY = 19
+
+/**
+ * The thread starter placeholder in a thread started from a message.
+ *
+ * @internal
+ */
+export const THREAD_STARTER_MESSAGE = 21
+
+/**
+ * Discord's channel type as a `kind`: 10, 11 and 12 are threads, 1 and 3
+ * directs, everything else a channel, unknown types included.
+ *
+ * @internal
+ */
+export const kindOf = (channelType: number): ThreadKind =>
+  channelType === 10 || channelType === 11 || channelType === 12
+    ? "thread"
+    : channelType === 1 || channelType === 3
+    ? "direct"
+    : "channel"
+
+/** @internal */
+export const isThreadType = (channelType: number): boolean => kindOf(channelType) === "thread"
+
+const optional = (schema: S) => Schema.optionalKey(Schema.NullOr(schema))
+
+const UserFields = Schema.Struct({
+  id: Schema.String,
+  username: optional(Schema.String),
+  global_name: optional(Schema.String),
+  bot: optional(Schema.Boolean)
+})
+
+const MemberFields = Schema.Struct({
+  nick: optional(Schema.String),
+  roles: optional(Schema.Array(Schema.String))
+})
+
+const AttachmentFields = Schema.Struct({
+  id: Schema.String,
+  filename: optional(Schema.String),
+  content_type: optional(Schema.String),
+  size: optional(Schema.Int)
+})
+
+const ReferenceFields = Schema.Struct({
+  type: optional(Schema.Number),
+  message_id: optional(Schema.String),
+  channel_id: optional(Schema.String)
+})
+
+/**
+ * What the normaliser reads from a message.
+ *
+ * @internal
+ */
+export const MessageFields = Schema.Struct({
+  id: Schema.String,
+  channel_id: Schema.String,
+  type: Schema.Number,
+  content: optional(Schema.String),
+  timestamp: Schema.String,
+  author: UserFields,
+  webhook_id: optional(Schema.String),
+  guild_id: optional(Schema.String),
+  channel_type: optional(Schema.Number),
+  member: optional(MemberFields),
+  mentions: optional(Schema.Array(Schema.Struct({ id: Schema.String }))),
+  mention_roles: optional(Schema.Array(Schema.String)),
+  mention_everyone: optional(Schema.Boolean),
+  attachments: optional(Schema.Array(AttachmentFields)),
+  message_reference: optional(ReferenceFields),
+  referenced_message: optional(Schema.Struct({ author: optional(Schema.Struct({ id: Schema.String })) }))
+})
+
+/** @internal */
+export type MessageFields = typeof MessageFields.Type
+
+const ReactionFields = Schema.Struct({
+  user_id: Schema.String,
+  channel_id: Schema.String,
+  message_id: Schema.String,
+  guild_id: optional(Schema.String),
+  message_author_id: optional(Schema.String),
+  member: optional(MemberFields),
+  emoji: Schema.Struct({ id: optional(Schema.String), name: optional(Schema.String) })
+})
+
+const decodeMessage = Schema.decodeUnknownOption(MessageFields)
+const decodeReaction = Schema.decodeUnknownOption(ReactionFields)
+
+/** @internal */
+export const decodeMessageFields = (raw: unknown): MessageFields | undefined =>
+  Option.getOrUndefined(decodeMessage(raw))
+
+/**
+ * An attachment's id: the message's id and the attachment's, since a download reads the message again.
+ *
+ * @internal
+ */
+export const attachmentId = (messageId: string, id: string): string => `${messageId}/${id}`
+
+/** @internal */
+export const parseAttachmentId = (
+  id: string
+): { readonly messageId: string; readonly attachmentId: string } | undefined => {
+  const parts = id.split("/")
+  return parts.length === 2 && parts[0] !== "" && parts[1] !== ""
+    ? { messageId: parts[0], attachmentId: parts[1] }
+    : undefined
+}
+
+/**
+ * The mentions in `content`: a token outside code that Discord says
+ * resolved, through `mentions` for a user, `mention_roles` for a role and
+ * `mention_everyone` for `@everyone` and `@here`. A channel token has no
+ * confirming field, so the token alone counts.
+ */
+const mentionsOf = (fields: MessageFields, text: string, botUserId: string): Array => {
+  const users = new Set((fields.mentions ?? []).map((user) => user.id))
+  const roles = new Set(fields.mention_roles ?? [])
+  const everyone = fields.mention_everyone === true
+  const found: Array = []
+  for (const token of Mentions.tokens(text)) {
+    const resolved = token.kind === "user"
+      ? users.has(token.id)
+      : token.kind === "role"
+      ? roles.has(token.id)
+      : token.kind === "broadcast"
+      ? everyone
+      : true
+    if (!resolved) continue
+    found.push({
+      kind: token.kind,
+      id: token.id,
+      start: token.start,
+      end: token.end,
+      isSelf: token.kind === "user" && token.id === botUserId
+    })
+  }
+  return found
+}
+
+const nonEmpty = (value: string | null | undefined): string | undefined =>
+  value === null || value === undefined || value === "" ? undefined : value
+
+/**
+ * A message payload, from the gateway or REST, as a `ChatMessage`.
+ * `undefined` for a type that is not a message.
+ *
+ * @internal
+ */
+export const message = (
+  raw: Schema.Json,
+  fields: MessageFields,
+  context: { readonly botUserId: string }
+): ChatMessage | undefined => {
+  if (!messageTypes.has(fields.type)) return undefined
+  const text = fields.content ?? ""
+  const webhook = nonEmpty(fields.webhook_id)
+  const name = webhook === undefined
+    ? nonEmpty(fields.member?.nick) ?? nonEmpty(fields.author.global_name) ?? nonEmpty(fields.author.username)
+    : nonEmpty(fields.author.username)
+  const reference = fields.message_reference
+  const replyId = fields.type === REPLY && (reference?.type ?? 0) === 0 ? nonEmpty(reference?.message_id) : undefined
+  const replyAuthor = fields.referenced_message?.author?.id
+  const attachments = (fields.attachments ?? []).map((attachment): Attachment => {
+    const name = nonEmpty(attachment.filename)
+    const contentType = nonEmpty(attachment.content_type)
+    return {
+      id: attachmentId(fields.id, attachment.id),
+      ...(name === undefined ? {} : { name }),
+      ...(contentType === undefined ? {} : { contentType }),
+      ...(typeof attachment.size === "number" ? { size: attachment.size } : {})
+    }
+  })
+  return {
+    id: fields.id,
+    thread: thread(fields.channel_id),
+    author: {
+      id: webhook ?? fields.author.id,
+      ...(name === undefined ? {} : { name }),
+      isBot: webhook !== undefined || fields.author.bot === true,
+      isSelf: webhook === undefined && fields.author.id === context.botUserId
+    },
+    text,
+    mentions: mentionsOf(fields, text, context.botUserId),
+    ...(replyId === undefined
+      ? {}
+      : { replyTo: { messageId: replyId, ...(replyAuthor === undefined ? {} : { authorId: replyAuthor }) } }),
+    attachments,
+    timestamp: DateTime.makeUnsafe(fields.timestamp),
+    raw
+  }
+}
+
+/**
+ * A reaction's emoji: the Unicode emoji, or `custom:{name}` for a guild's own.
+ *
+ * @internal
+ */
+export const emojiOf = (
+  emoji: { readonly id?: string | null | undefined; readonly name?: string | null | undefined }
+) =>
+  nonEmpty(emoji.id) === undefined
+    ? nonEmpty(emoji.name)
+    : `custom:${nonEmpty(emoji.name) ?? emoji.id}`
+
+/**
+ * The result of `normalize`: the events, or the channel whose type is missing.
+ *
+ * @internal
+ */
+export type Normalized =
+  | { readonly _tag: "Events"; readonly events: ReadonlyArray }
+  | { readonly _tag: "MissingChannelType"; readonly channelId: string }
+
+const none: Normalized = { _tag: "Events", events: [] }
+
+const events = (events: ReadonlyArray): Normalized => ({ _tag: "Events", events })
+
+/** @internal */
+export const normalize = (
+  dispatch: { readonly t: string; readonly d: unknown },
+  context: { readonly botUserId: string; readonly channelType?: number | undefined }
+): Normalized => {
+  const raw = dispatch.d as Schema.Json
+  switch (dispatch.t) {
+    case "MESSAGE_CREATE": {
+      const fields = decodeMessageFields(raw)
+      if (fields === undefined || !messageTypes.has(fields.type)) return none
+      const channelType = fields.channel_type ?? context.channelType
+      if (channelType === undefined) return { _tag: "MissingChannelType", channelId: fields.channel_id }
+      const created = message(raw, fields, context)
+      return created === undefined ? none : events([{
+        _tag: "MessageCreated",
+        thread: created.thread,
+        kind: kindOf(channelType),
+        message: created,
+        raw
+      }])
+    }
+    case "MESSAGE_REACTION_ADD":
+    case "MESSAGE_REACTION_REMOVE": {
+      const fields = Option.getOrUndefined(decodeReaction(raw))
+      const emoji = fields === undefined ? undefined : emojiOf(fields.emoji)
+      if (fields === undefined || emoji === undefined) return none
+      const authorId = nonEmpty(fields.message_author_id)
+      const reaction = {
+        thread: thread(fields.channel_id),
+        messageId: fields.message_id,
+        ...(authorId === undefined ? {} : { messageAuthorId: authorId }),
+        userId: fields.user_id,
+        emoji,
+        raw
+      }
+      return events([
+        dispatch.t === "MESSAGE_REACTION_ADD"
+          ? { _tag: "ReactionAdded", ...reaction } satisfies ReactionAdded
+          : { _tag: "ReactionRemoved", ...reaction } satisfies ReactionRemoved
+      ])
+    }
+    default:
+      return none
+  }
+}
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/** @internal */
+export const memberOf = (raw: unknown): Option.Option<{
+  readonly guildId: string
+  readonly roles: ReadonlyArray
+  readonly nick?: string | undefined
+}> => {
+  if (!isObject(raw)) return Option.none()
+  const guildId = raw.guild_id
+  const member = raw.member
+  if (typeof guildId !== "string" || guildId === "" || !isObject(member)) return Option.none()
+  const roles = Array.isArray(member.roles) ? member.roles.filter((role) => typeof role === "string") : []
+  const nick = typeof member.nick === "string" && member.nick !== "" ? member.nick : undefined
+  return Option.some({ guildId, roles, ...(nick === undefined ? {} : { nick }) })
+}
+
+/** @internal */
+export const guildIdOf = (raw: unknown): Option.Option =>
+  isObject(raw) && typeof raw.guild_id === "string" && raw.guild_id !== "" ? Option.some(raw.guild_id) : Option.none()
+
+const discordEpoch = BigInt(1420070400000)
+
+/**
+ * When a snowflake was made.
+ *
+ * @internal
+ */
+export const snowflakeTime = (id: string): DateTime.Utc | undefined => {
+  try {
+    return DateTime.makeUnsafe(Number((BigInt(id) >> BigInt(22)) + discordEpoch))
+  } catch {
+    return undefined
+  }
+}
+
+/**
+ * Orders two snowflakes.
+ *
+ * @internal
+ */
+export const compareIds = (a: string, b: string): number => {
+  try {
+    const x = BigInt(a)
+    const y = BigInt(b)
+    return x < y ? -1 : x > y ? 1 : 0
+  } catch {
+    return a.length !== b.length ? a.length - b.length : a < b ? -1 : a > b ? 1 : 0
+  }
+}
diff --git a/packages/chat/discord/src/internal/options.ts b/packages/chat/discord/src/internal/options.ts
new file mode 100644
index 00000000000..7d4f6536252
--- /dev/null
+++ b/packages/chat/discord/src/internal/options.ts
@@ -0,0 +1,44 @@
+import * as Context from "effect/Context"
+
+/** @internal */
+export interface PostOptions {
+  readonly notify?: {
+    readonly users?: ReadonlyArray | undefined
+    readonly roles?: ReadonlyArray | undefined
+    readonly everyone?: boolean | undefined
+    readonly repliedUser?: boolean | undefined
+  } | undefined
+  readonly suppressEmbeds?: boolean | undefined
+  readonly autoArchiveDuration?: 60 | 1440 | 4320 | 10080 | undefined
+}
+
+/** @internal */
+export const CurrentPostOptions = Context.Reference("@effect/chat-discord/CurrentPostOptions", {
+  defaultValue: () => ({})
+})
+
+/**
+ * Discord's `SUPPRESS_EMBEDS` message flag.
+ *
+ * @internal
+ */
+export const SUPPRESS_EMBEDS = 1 << 2
+
+/**
+ * The `allowed_mentions` for a write: nobody, unless `notify` says otherwise.
+ *
+ * @internal
+ */
+export const allowedMentions = (notify: PostOptions["notify"]) => ({
+  parse: notify?.everyone === true ? ["everyone" as const] : [],
+  users: notify?.users ?? [],
+  roles: notify?.roles ?? [],
+  replied_user: notify?.repliedUser === true
+})
+
+/**
+ * The flags for a write.
+ *
+ * @internal
+ */
+export const flags = (options: PostOptions): number => options.suppressEmbeds === false ? 0 : SUPPRESS_EMBEDS
diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
new file mode 100644
index 00000000000..a913c759166
--- /dev/null
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -0,0 +1,654 @@
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { assert, describe, it } from "@effect/vitest"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
+import { checkMessage } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import * as Fiber from "effect/Fiber"
+import * as Option from "effect/Option"
+import * as Stream from "effect/Stream"
+import * as TestClock from "effect/testing/TestClock"
+import {
+  adapter,
+  answer,
+  botUserId,
+  checkOptions,
+  discordLayer,
+  errorResponse,
+  events,
+  type Fake,
+  guild,
+  makeFake,
+  scratch,
+  statusCodeError,
+  step,
+  tim
+} from "./utils.ts"
+
+const run = (fake: Fake, effect: Effect.Effect, options?: { readonly download?: Uint8Array }) =>
+  effect.pipe(Effect.provide(discordLayer(fake, options))) as Effect.Effect
+
+const reason = (effect: Effect.Effect) =>
+  Effect.flip(effect).pipe(
+    Effect.map((error) => ({ op: error.op, tag: error.reason._tag, detail: error.reason.detail, retry: error.retry }))
+  )
+
+const channel = DiscordChat.thread(scratch)
+const posted = step("posts", "channel-plain").response
+
+const history = step("history", "thread-history")
+const threadId: string = step("history", "thread-start").response.id
+const thread = DiscordChat.thread(threadId)
+const threadChannel = step("history", "thread-get-channel").response
+
+const noMentions = { parse: [], users: [], roles: [], replied_user: false }
+
+describe("post", () => {
+  it.effect("sends the Markdown as is, notifying nobody and suppressing embeds", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const result = yield* discord.post(channel, { markdown: "hi <@1> @everyone **bold**" })
+        assert.strictEqual(result.id, posted.id)
+        assert.deepStrictEqual(result.thread, channel)
+        assert.deepStrictEqual(fake.called("createMessage"), [[scratch, {
+          content: "hi <@1> @everyone **bold**",
+          allowed_mentions: noMentions,
+          flags: 4
+        }]])
+      })
+    )
+  })
+
+  it.effect("withPostOptions allows mentions and embeds, merging nested calls", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42" } }).pipe(
+          DiscordChat.withPostOptions({ notify: { users: ["1"], roles: ["2"], everyone: true, repliedUser: true } }),
+          DiscordChat.withPostOptions({ suppressEmbeds: false })
+        )
+        assert.deepStrictEqual(fake.called("createMessage")[0][1], {
+          content: "hi",
+          allowed_mentions: { parse: ["everyone"], users: ["1"], roles: ["2"], replied_user: true },
+          flags: 0,
+          message_reference: { message_id: "42" }
+        })
+      })
+    )
+  })
+
+  it.effect("a reply does not ping its author by default", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42", authorId: tim } })
+        assert.deepStrictEqual(fake.called("createMessage")[0][1].allowed_mentions, noMentions)
+      })
+    )
+  })
+
+  it.effect("fails TooLarge past 2,000 code points without a call", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "a".repeat(2001) })), {
+          op: "post",
+          tag: "TooLarge",
+          detail: "message_too_long",
+          retry: "denied"
+        })
+        assert.deepStrictEqual(
+          yield* reason(discord.post(channel, { markdown: "a".repeat(1999) + "\u{1F1EC}\u{1F1E7}" })),
+          {
+            op: "post",
+            tag: "TooLarge",
+            detail: "message_too_long",
+            retry: "denied"
+          }
+        )
+        assert.strictEqual(fake.calls.length, 0)
+        // 2,000 astral emoji are 4,000 UTF-16 units, and Discord took them.
+        yield* discord.post(channel, { markdown: "\u{1F600}".repeat(2000) })
+        assert.strictEqual(fake.called("createMessage").length, 1)
+        assert.strictEqual(discord.descriptor.measure("\u{1F600}".repeat(2000)), 2000)
+      })
+    )
+  })
+
+  it.effect("uploads files with the message", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(step("posts", "attachment-fixed").response) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.post(channel, {
+          markdown: "with a file",
+          files: [{ name: "fixture.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }]
+        })
+        assert.strictEqual(fake.calls[0].files, 1)
+        assert.deepStrictEqual(fake.calls[0].args[1].attachments, [{ id: "0", filename: "fixture.txt" }])
+      })
+    )
+  })
+
+  it.effect("maps Discord's error bodies", () => {
+    const errors = (stepName: string) => () => answer(step("errors", stepName))
+    const cases = [
+      ["post-unknown-channel", { op: "post", tag: "NotFound", detail: "10003", retry: "denied" }],
+      ["post-empty", { op: "post", tag: "InvalidRequest", detail: "50006", retry: "denied" }],
+      ["length-2001-ascii", { op: "post", tag: "TooLarge", detail: "50035", retry: "denied" }]
+    ] as const
+    return Effect.forEach(cases, ([stepName, expected]) => {
+      const fake = makeFake({ createMessage: errors(stepName) })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const discord = yield* adapter
+          assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "x" })), expected)
+        })
+      )
+    }, { discard: true })
+  })
+
+  it.effect("a 5xx on a write is uncertain and not retried", () => {
+    const fake = makeFake({
+      createMessage: () => Effect.fail(statusCodeError(502)),
+      deleteMessage: () => Effect.fail(errorResponse(403, { code: 50013, message: "Missing Permissions" }))
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "x" })), {
+          op: "post",
+          tag: "PlatformUnavailable",
+          detail: "http_502",
+          retry: "uncertain"
+        })
+        assert.strictEqual(fake.called("createMessage").length, 1)
+        assert.deepStrictEqual(yield* reason(discord.delete(channel, "1")), {
+          op: "delete",
+          tag: "Forbidden",
+          detail: "50013",
+          retry: "denied"
+        })
+      })
+    )
+  })
+
+  it.effect("a 5xx on a read is retried", () => {
+    let attempts = 0
+    const fake = makeFake({
+      getMessage: () => attempts++ < 1 ? Effect.fail(statusCodeError(503)) : Effect.succeed(posted)
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const fiber = yield* Effect.forkChild(discord.fetchMessage(channel, posted.id))
+        yield* TestClock.adjust("1 second")
+        const message = yield* Fiber.join(fiber)
+        assert.strictEqual(message.id, posted.id)
+        assert.strictEqual(fake.called("getMessage").length, 2)
+      })
+    )
+  })
+
+  it.effect("rejects an address that is not a Discord channel id", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const result = yield* reason(discord.post(DiscordChat.thread("C123"), { markdown: "x" }))
+        assert.strictEqual(result.tag, "InvalidRequest")
+        assert.strictEqual(fake.calls.length, 0)
+      })
+    )
+  })
+})
+
+describe("edit", () => {
+  it.effect("sends allowed_mentions and the SUPPRESS_EMBEDS flag on every edit", () => {
+    const fake = makeFake({ updateMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.edit(channel, "1", { markdown: "now with https://effect.website" })
+        assert.deepStrictEqual(fake.called("updateMessage"), [[scratch, "1", {
+          content: "now with https://effect.website",
+          allowed_mentions: noMentions,
+          flags: 4
+        }]])
+        assert.deepStrictEqual(yield* reason(discord.edit(channel, "1", { markdown: "a".repeat(2001) })), {
+          op: "edit",
+          tag: "TooLarge",
+          detail: "message_too_long",
+          retry: "denied"
+        })
+      })
+    )
+  })
+})
+
+describe("startThread", () => {
+  it.effect("names the thread after the message, cut to 100 characters", () => {
+    const fake = makeFake({
+      getMessage: () => Effect.succeed({ ...posted, content: "  first line\nsecond " + "x".repeat(200) }),
+      createThreadFromMessage: () => Effect.succeed(step("history", "thread-start").response)
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const result = yield* discord.startThread(channel, threadId).pipe(
+          DiscordChat.withPostOptions({ autoArchiveDuration: 1440 })
+        )
+        assert.deepStrictEqual(result, thread)
+        const [[channelId, messageId, body]] = fake.called("createThreadFromMessage")
+        assert.strictEqual(channelId, scratch)
+        assert.strictEqual(messageId, threadId)
+        assert.strictEqual(body.name, ("first line second " + "x".repeat(200)).slice(0, 100))
+        assert.strictEqual(body.auto_archive_duration, 1440)
+      })
+    )
+  })
+
+  it.effect("160004 gives the existing thread, whose id is the message's", () => {
+    const fake = makeFake({ createThreadFromMessage: () => answer(step("errors", "thread-start-again")) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const result = yield* discord.startThread(channel, threadId, { name: "given" })
+        assert.deepStrictEqual(result, thread)
+        assert.strictEqual(fake.called("createThreadFromMessage")[0][2].name, "given")
+      })
+    )
+  })
+
+  it.effect("on a message in a thread, gives the thread", () => {
+    const fake = makeFake({
+      createThreadFromMessage: () => answer(step("errors", "forum-start-thread-again")),
+      getChannel: () => Effect.succeed(threadChannel)
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        assert.deepStrictEqual(yield* discord.startThread(thread, "1", { name: "x" }), thread)
+      })
+    )
+  })
+
+  it.effect("50024 elsewhere stays a failure", () => {
+    const fake = makeFake({
+      createThreadFromMessage: () => answer(step("errors", "forum-start-thread-again")),
+      getChannel: () => Effect.succeed(step("channels", "get-channel-dm").response)
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const result = yield* reason(discord.startThread(channel, "1", { name: "x" }))
+        assert.strictEqual(result.detail, "50024")
+      })
+    )
+  })
+})
+
+describe("history", () => {
+  const listFrom = (pages: ReadonlyArray) => (_: string, options: any) => {
+    const all = [...pages]
+    const id = (raw: any) => BigInt(raw.id)
+    const found = options.before !== undefined
+      ? all.filter((raw) => id(raw) < BigInt(options.before))
+      : options.after !== undefined
+      ? all.filter((raw) => id(raw) > BigInt(options.after))
+      : all
+    // Newest first, as Discord answers with either bound.
+    return Effect.succeed(found.sort((a, b) => (id(b) > id(a) ? 1 : -1)).slice(0, options.limit ?? 50))
+  }
+
+  it.effect("a thread started from a message has its opener first, addressed to the parent", () => {
+    const fake = makeFake({ listMessages: listFrom(history.response) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const forward = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "forward" })))
+        assert.deepStrictEqual(forward.map((message) => message.id), [
+          threadId,
+          ...history.response.filter((raw: any) => raw.type !== 21).map((raw: any) => raw.id).reverse()
+        ])
+        assert.deepStrictEqual(forward[0].thread, channel)
+        for (const message of forward.slice(1)) assert.deepStrictEqual(message.thread, thread)
+        for (const message of forward) yield* checkMessage(message, checkOptions)
+        const backward = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "backward" })))
+        assert.deepStrictEqual(backward.map((message) => message.id), forward.map((message) => message.id).reverse())
+        // `from` is exclusive, the opener included.
+        const after = Array.from(
+          yield* Stream.runCollect(discord.history(thread, { direction: "forward", from: threadId }))
+        )
+        assert.deepStrictEqual(after.map((message) => message.id), forward.slice(1).map((message) => message.id))
+        assert.strictEqual(fake.called("getMessage").length, 0)
+      })
+    )
+  })
+
+  it.effect("a thread whose opener was deleted starts at the first reply", () => {
+    const deleted = step("history", "thread-deleted-history").response
+    const fake = makeFake({ listMessages: listFrom(deleted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const thread = DiscordChat.thread(step("history", "thread-deleted-start").response.id)
+        const found = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "forward" })))
+        assert.deepStrictEqual(found.map((message) => message.id), [deleted.find((raw: any) => raw.type === 0).id])
+      })
+    )
+  })
+
+  it.effect("the opener is read when the placeholder carries no referenced_message", () => {
+    const placeholder = history.response.find((raw: any) => raw.type === 21)
+    const { referenced_message: opener, ...bare } = placeholder
+    const fake = makeFake({
+      listMessages: listFrom([bare]),
+      getMessage: (channelId: string, messageId: string) =>
+        channelId === scratch && messageId === threadId
+          ? Effect.succeed(opener)
+          : Effect.fail(errorResponse(404, { code: 10008, message: "Unknown Message" }))
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const found = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "backward" })))
+        assert.deepStrictEqual(found.map((message) => message.id), [threadId])
+      })
+    )
+  })
+
+  it.effect("pages until a short page", () => {
+    const many = Array.from(
+      { length: 250 },
+      (_, i) => ({ ...posted, id: String(1570607253965246584n + BigInt(i + 1)) })
+    )
+    const fake = makeFake({ listMessages: listFrom(many) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const found = Array.from(yield* Stream.runCollect(discord.history(channel, { direction: "backward" })))
+        assert.strictEqual(found.length, 250)
+        assert.strictEqual(fake.called("listMessages").length, 3)
+        assert.deepStrictEqual(fake.called("listMessages")[1][1], { before: found[99].id, limit: 100 })
+      })
+    )
+  })
+})
+
+describe("opener", () => {
+  it.effect("reads the message in the parent for a thread started from a message", () => {
+    const fake = makeFake({
+      getChannel: () => Effect.succeed(threadChannel),
+      getMessage: (channelId: string) =>
+        channelId === threadId
+          ? answer(step("history", "thread-get-opener-by-thread-id"))
+          : answer(step("history", "thread-get-opener"))
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const opener = Option.getOrThrow(yield* discord.opener(thread))
+        assert.strictEqual(opener.id, threadId)
+        assert.deepStrictEqual(opener.thread, channel)
+        assert.deepStrictEqual(fake.called("getMessage"), [[threadId, threadId], [scratch, threadId]])
+      })
+    )
+  })
+
+  it.effect("reads a forum post's starter in the post", () => {
+    const starter = step("history", "forum-get-starter").response
+    const fake = makeFake({
+      getChannel: () => Effect.succeed(step("history", "forum-post").response),
+      getMessage: () => Effect.succeed(starter)
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const opener = Option.getOrThrow(yield* discord.opener(DiscordChat.thread(starter.id)))
+        assert.strictEqual(opener.thread.id, starter.id)
+      })
+    )
+  })
+
+  it.effect("is None for a deleted opener and for a channel", () => {
+    const fake = makeFake({
+      getChannel: (id: string) =>
+        Effect.succeed(id === scratch ? step("channels", "get-channel-text").response : threadChannel),
+      getMessage: () => answer(step("history", "thread-deleted-get-opener"))
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        assert.isTrue(Option.isNone(yield* discord.opener(thread)))
+        assert.isTrue(Option.isNone(yield* discord.opener(channel)))
+      })
+    )
+  })
+})
+
+describe("getThread and getUser", () => {
+  it.effect("getThread gives the kind, name and parent", () => {
+    const fake = makeFake({
+      getChannel: (id: string) =>
+        Effect.succeed(
+          id === threadId
+            ? threadChannel
+            : id === scratch
+            ? step("channels", "get-channel-text").response
+            : step("channels", "get-channel-dm").response
+        )
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const info = yield* discord.getThread(thread)
+        assert.strictEqual(info.kind, "thread")
+        assert.strictEqual(info.name, "Fixture thread from a message")
+        assert.deepStrictEqual(info.parent, channel)
+        assert.isDefined(info.createdAt)
+        const text = yield* discord.getThread(channel)
+        assert.strictEqual(text.kind, "channel")
+        assert.strictEqual(text.name, "effect-chat-scratch")
+        assert.isUndefined(text.parent)
+        const dm = yield* discord.getThread(DiscordChat.thread(step("channels", "get-channel-dm").response.id))
+        assert.strictEqual(dm.kind, "direct")
+        assert.isUndefined(dm.name)
+      })
+    )
+  })
+
+  it.effect("getUser gives the guild nick with in, and NotFound for a webhook", () => {
+    const member = step("users", "get-member-bot").response
+    const fake = makeFake({
+      getChannel: () => Effect.succeed(step("channels", "get-channel-text").response),
+      getGuildMember: () => Effect.succeed({ ...member, nick: "Janny" }),
+      getUser: (id: string) =>
+        id === botUserId ? answer(step("users", "get-user-bot")) : answer(step("errors", "get-user-webhook"))
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const inGuild = yield* discord.getUser(botUserId, { in: channel })
+        assert.strictEqual(inGuild.name, "Janny")
+        assert.isTrue(inGuild.isSelf && inGuild.isBot)
+        assert.deepStrictEqual(fake.called("getGuildMember"), [[guild, botUserId]])
+        const plain = yield* discord.getUser(botUserId)
+        assert.strictEqual(plain.name, "Janitor")
+        assert.strictEqual((yield* reason(discord.getUser("1570607260156297307"))).tag, "NotFound")
+      })
+    )
+  })
+
+  it.effect("guild reads the channel once", () => {
+    const fake = makeFake({ getChannel: () => Effect.succeed(step("channels", "get-channel-text").response) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        assert.deepStrictEqual(yield* discord.guild(channel), Option.some(guild))
+        assert.deepStrictEqual(yield* discord.guild(channel), Option.some(guild))
+        assert.strictEqual(fake.called("getChannel").length, 1)
+      })
+    )
+  })
+})
+
+describe("download", () => {
+  it.effect("reads the message again for the URL and stops past maxBytes", () => {
+    const raw = step("posts", "attachment-fixed").response
+    const fake = makeFake({ getMessage: () => Effect.succeed(raw) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const event = yield* Effect.succeed(events("attachment")[0])
+        const [attachment] = (DiscordChat.normalize(event, { botUserId }) as any).success[0].message.attachments
+        const attachmentFromPost = { ...attachment, id: `${raw.id}/${raw.attachments[0].id}` }
+        const bytes = yield* Stream.runCollect(discord.download(channel, attachmentFromPost, { maxBytes: 100 }))
+        assert.strictEqual(new TextDecoder().decode(Array.from(bytes)[0]), "hello from effect/chat\n")
+        const tooLarge = yield* reason(
+          Stream.runCollect(discord.download(channel, attachmentFromPost, { maxBytes: 5 }))
+        )
+        assert.strictEqual(tooLarge.tag, "TooLarge")
+      }),
+      { download: new TextEncoder().encode("hello from effect/chat\n") }
+    )
+  })
+})
+
+describe("dispatch", () => {
+  const collect = () => {
+    const seen: Array = []
+    const handler = ChatHandler.of({ handle: (event) => Effect.sync(() => void seen.push(event)) })
+    return { seen, provide: Effect.provideService(ChatHandler, handler) }
+  }
+  const missing = events("channel-message-without-channel-type")[0]
+
+  it.effect("delivers a message with channel_type without a lookup", () => {
+    const fake = makeFake({})
+    const { provide, seen } = collect()
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        yield* provide(discord.dispatch(events("channel-message")[0]))
+        yield* provide(discord.dispatch({ t: "READY", d: {} }))
+        yield* provide(discord.dispatch(events("thread-started")[0]))
+        assert.strictEqual(seen.length, 1)
+        assert.strictEqual(fake.calls.length, 0)
+      })
+    )
+  })
+
+  it.effect("looks the channel up once when channel_type is missing", () => {
+    const fake = makeFake({ getChannel: () => Effect.succeed(threadChannel) })
+    const { provide, seen } = collect()
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        yield* provide(discord.dispatch(missing))
+        yield* provide(discord.dispatch(missing))
+        assert.strictEqual(seen.length, 2)
+        assert(seen[0]._tag === "MessageCreated")
+        assert.strictEqual(seen[0].kind, "thread")
+        assert.deepStrictEqual(fake.called("getChannel"), [[scratch]])
+      })
+    )
+  })
+
+  it.effect("fails NotAccepted when the lookup fails, and tries again next time", () => {
+    let attempts = 0
+    const fake = makeFake({
+      getChannel: () =>
+        attempts++ < 4
+          ? Effect.fail(statusCodeError(500))
+          : Effect.succeed(step("channels", "get-channel-text").response)
+    })
+    const { provide, seen } = collect()
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        const fiber = yield* Effect.forkChild(Effect.flip(provide(discord.dispatch(missing))))
+        yield* TestClock.adjust("10 seconds")
+        assert.instanceOf(yield* Fiber.join(fiber), NotAccepted)
+        assert.strictEqual(seen.length, 0)
+        yield* provide(discord.dispatch(missing))
+        assert.strictEqual(seen.length, 1)
+      })
+    )
+  })
+
+  it.effect("drops the event when the lookup is denied", () => {
+    const fake = makeFake({ getChannel: () => answer(step("errors", "get-channel-unknown")) })
+    const { provide, seen } = collect()
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        yield* provide(discord.dispatch(missing))
+        assert.strictEqual(seen.length, 0)
+      })
+    )
+  })
+
+  it.effect("fails NotAccepted when the lookup takes longer than five seconds", () => {
+    const fake = makeFake({ getChannel: () => Effect.never })
+    const { provide } = collect()
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        const fiber = yield* Effect.forkChild(Effect.flip(provide(discord.dispatch(missing))))
+        yield* TestClock.adjust("5 seconds")
+        assert.instanceOf(yield* Fiber.join(fiber), NotAccepted)
+      })
+    )
+  })
+
+  it.effect("passes the handler's NotAccepted on", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        const error = yield* Effect.flip(
+          discord.dispatch(events("channel-message")[0]).pipe(
+            Effect.provideService(ChatHandler, ChatHandler.of({ handle: () => Effect.fail(new NotAccepted()) }))
+          )
+        )
+        assert.instanceOf(error, NotAccepted)
+      })
+    )
+  })
+})
diff --git a/packages/chat/discord/test/fixtures/events/attachment.json b/packages/chat/discord/test/fixtures/events/attachment.json
new file mode 100644
index 00000000000..f073ce93988
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/attachment.json
@@ -0,0 +1,79 @@
+{
+  "case": "A message with a text attachment, uploaded as multipart; the attachments carry signed CDN URLs, scrubbed",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "the Janitor bot, through REST",
+    "recordedAt": "2026-11-13T01:30Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:30:02.519Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:30:02.447000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570611669015732315",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a message with an attachment, fixed",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [
+          {
+            "url": "https://cdn.discordapp.com/attachments/1570607253965246584/1570611668722122812/fixture.txt?scrubbed",
+            "size": 23,
+            "proxy_url": "https://media.discordapp.net/attachments/1570607253965246584/1570611668722122812/fixture.txt?scrubbed",
+            "id": "1570611668722122812",
+            "filename": "fixture.txt",
+            "content_type": "text/plain; charset=utf-8",
+            "content_scan_version": 0
+          }
+        ],
+        "guild_id": "840178841540362250"
+      },
+      "scrubbed": [
+        "$.attachments[0].url",
+        "$.attachments[0].proxy_url"
+      ]
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/channel-message-without-channel-type.json b/packages/chat/discord/test/fixtures/events/channel-message-without-channel-type.json
new file mode 100644
index 00000000000..71db98dffa7
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/channel-message-without-channel-type.json
@@ -0,0 +1,61 @@
+{
+  "case": "The channel-message dispatch with channel_type removed. Discord documents the field as optional, but no recorded delivery lacked it",
+  "provenance": {
+    "kind": "derived",
+    "from": "events/channel-message.json",
+    "change": "deleted d.channel_type"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:16:13.140Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:13+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608190062723103",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a plain message in a guild text channel",
+        "components": [],
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/channel-message.json b/packages/chat/discord/test/fixtures/events/channel-message.json
new file mode 100644
index 00000000000..541e43f3685
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/channel-message.json
@@ -0,0 +1,65 @@
+{
+  "case": "A message by the bot in a guild text channel, delivered with channel_type 0",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "the Janitor bot, through REST",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:16:13.140Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:13+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608190062723103",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a plain message in a guild text channel",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/forum.json b/packages/chat/discord/test/fixtures/events/forum.json
new file mode 100644
index 00000000000..fce682efbb7
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/forum.json
@@ -0,0 +1,119 @@
+{
+  "case": "A forum post: its starter, whose id is the thread's, and a later reply; channel_type 11",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "the Janitor bot, through REST",
+    "recordedAt": "2026-11-13T01:17Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:17:14.964Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:14.921000+00:00",
+        "position": 0,
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608449778098218",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: the starter of a forum post",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608449778098218",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:16.322Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:16.290000+00:00",
+        "position": 0,
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608455520227379",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a later reply in a forum post",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608449778098218",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/mentions.json b/packages/chat/discord/test/fixtures/events/mentions.json
new file mode 100644
index 00000000000..b16b11dd8b4
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/mentions.json
@@ -0,0 +1,491 @@
+{
+  "case": "Mention tokens sent through the webhook with allowed_mentions resolving them (or not), and the bot naming itself and a role with parse []: a token counts only outside code and when mentions, mention_roles or mention_everyone says it resolved",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "webhook effect-chat-fixtures and the Janitor bot",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:16:22.047Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:22.010000+00:00",
+        "pinned": false,
+        "mentions": [
+          {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          }
+        ],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608227853533387",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: <@1564742987727118426> as a plain user token",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:23.497Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:23.426000+00:00",
+        "pinned": false,
+        "mentions": [
+          {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          }
+        ],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608233792405568",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: <@!1564742987727118426> as a nickname token",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:25.076Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:24.944000+00:00",
+        "pinned": false,
+        "mentions": [
+          {
+            "username": "timsmart",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "449108784879763458",
+            "global_name": "Tim Smart",
+            "display_name_styles": null,
+            "discriminator": "0",
+            "collectibles": null,
+            "clan": null,
+            "avatar_decoration_data": null,
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+          }
+        ],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608240159625278",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: <@449108784879763458> another user",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:26.781Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:26.546000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [
+          "1570607256838479964"
+        ],
+        "mention_everyone": false,
+        "id": "1570608246878773301",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: <@&1570607256838479964> a role",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:28.532Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:28.416000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": true,
+        "id": "1570608254721982479",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: @everyone that resolves",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:29.956Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:29.899000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": true,
+        "id": "1570608260942397441",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: @here that resolves",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:31.721Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:31.658000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608268320051301",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: @everyone with parse empty",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:33.208Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:33.157000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608274607440034",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: <#1570605581192929301> a channel",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:35.385Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:35.311000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608283641970709",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: `<@1564742987727118426>` in a code span",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:36.882Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:36.848000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608290088484875",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: in a fence\n```\n<@1564742987727118426>\n```",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:38.528Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:38.346000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608296371425382",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: the bot naming <@1564742987727118426> and <@&1570607256838479964> with parse empty",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:40.029Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:39.899000+00:00",
+        "pinned": false,
+        "mentions": [
+          {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          }
+        ],
+        "mention_roles": [
+          "1570607256838479964"
+        ],
+        "mention_everyone": false,
+        "id": "1570608302885179546",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: <@1564742987727118426> and `<@449108784879763458>` and <@&1570607256838479964> and <#1570607253965246584>",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/reactions.json b/packages/chat/discord/test/fixtures/events/reactions.json
new file mode 100644
index 00000000000..dc292d12f9a
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/reactions.json
@@ -0,0 +1,385 @@
+{
+  "case": "MESSAGE_REACTION_ADD and MESSAGE_REACTION_REMOVE in a channel and in a thread, for a Unicode emoji, a skin-toned one and the guild's custom :effectchat:; removals carry no member and no message_author_id",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "the Janitor bot, through REST",
+    "recordedAt": "2026-11-13T01:17Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:17:26.307Z",
+      "t": "MESSAGE_REACTION_ADD",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608483965870101",
+        "message_author_id": "1564742987727118426",
+        "member": {
+          "user": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "display_name": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "emoji": {
+          "name": "👍",
+          "id": null
+        },
+        "channel_id": "1570607253965246584",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:27.600Z",
+      "t": "MESSAGE_REACTION_ADD",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608483965870101",
+        "message_author_id": "1564742987727118426",
+        "member": {
+          "user": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "display_name": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "emoji": {
+          "name": "👍🏽",
+          "id": null
+        },
+        "channel_id": "1570607253965246584",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:28.980Z",
+      "t": "MESSAGE_REACTION_ADD",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608483965870101",
+        "message_author_id": "1564742987727118426",
+        "member": {
+          "user": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "display_name": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "emoji": {
+          "name": "effectchat",
+          "id": "1570607258226790481"
+        },
+        "channel_id": "1570607253965246584",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:31.820Z",
+      "t": "MESSAGE_REACTION_REMOVE",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608483965870101",
+        "emoji": {
+          "name": "👍",
+          "id": null
+        },
+        "channel_id": "1570607253965246584",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:33.147Z",
+      "t": "MESSAGE_REACTION_REMOVE",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608483965870101",
+        "emoji": {
+          "name": "👍🏽",
+          "id": null
+        },
+        "channel_id": "1570607253965246584",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:34.434Z",
+      "t": "MESSAGE_REACTION_REMOVE",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608483965870101",
+        "emoji": {
+          "name": "effectchat",
+          "id": "1570607258226790481"
+        },
+        "channel_id": "1570607253965246584",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:35.742Z",
+      "t": "MESSAGE_REACTION_ADD",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608491532386377",
+        "message_author_id": "1564742987727118426",
+        "member": {
+          "user": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "display_name": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "emoji": {
+          "name": "👍",
+          "id": null
+        },
+        "channel_id": "1570608327602471024",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:37.218Z",
+      "t": "MESSAGE_REACTION_ADD",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608491532386377",
+        "message_author_id": "1564742987727118426",
+        "member": {
+          "user": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "display_name": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "emoji": {
+          "name": "👍🏽",
+          "id": null
+        },
+        "channel_id": "1570608327602471024",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:38.573Z",
+      "t": "MESSAGE_REACTION_ADD",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608491532386377",
+        "message_author_id": "1564742987727118426",
+        "member": {
+          "user": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "display_name": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "emoji": {
+          "name": "effectchat",
+          "id": "1570607258226790481"
+        },
+        "channel_id": "1570608327602471024",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:41.260Z",
+      "t": "MESSAGE_REACTION_REMOVE",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608491532386377",
+        "emoji": {
+          "name": "👍",
+          "id": null
+        },
+        "channel_id": "1570608327602471024",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:42.704Z",
+      "t": "MESSAGE_REACTION_REMOVE",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608491532386377",
+        "emoji": {
+          "name": "👍🏽",
+          "id": null
+        },
+        "channel_id": "1570608327602471024",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:44.046Z",
+      "t": "MESSAGE_REACTION_REMOVE",
+      "d": {
+        "user_id": "1564742987727118426",
+        "type": 0,
+        "message_id": "1570608491532386377",
+        "emoji": {
+          "name": "effectchat",
+          "id": "1570607258226790481"
+        },
+        "channel_id": "1570608327602471024",
+        "burst": false,
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/reply-ping.json b/packages/chat/discord/test/fixtures/events/reply-ping.json
new file mode 100644
index 00000000000..b217a6b7933
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/reply-ping.json
@@ -0,0 +1,429 @@
+{
+  "case": "Replies to the anchor message in #test typed by a person, ping on (Discord puts the replied-to author in mentions with no token in content) and ping off, then the bot's own two replies to a message with replied_user true and false",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "Tim Smart (449108784879763458), typing in the Discord client, then the Janitor bot through REST",
+    "recordedAt": "2026-11-13T01:17Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:17:05.947Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 19,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:05.904000+00:00",
+        "referenced_message": {
+          "type": 0,
+          "tts": false,
+          "timestamp": "2026-11-13T01:12:44.305000+00:00",
+          "pinned": false,
+          "mentions": [],
+          "mention_roles": [],
+          "mention_everyone": false,
+          "id": "1570607314732580917",
+          "flags": 0,
+          "embeds": [],
+          "edited_timestamp": null,
+          "content": "Fixture anchor for @effect/chat-discord (EFF-3695). Please reply to this message twice: once with the ping on, once with it off.",
+          "components": [],
+          "channel_type": 0,
+          "channel_id": "1570605581192929301",
+          "author": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "attachments": []
+        },
+        "pinned": false,
+        "nonce": "1570608410896891904",
+        "message_reference": {
+          "type": 0,
+          "message_id": "1570607314732580917",
+          "guild_id": "840178841540362250",
+          "channel_id": "1570605581192929301"
+        },
+        "mentions": [
+          {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "member": {
+              "roles": [
+                "1570605977017778196"
+              ],
+              "premium_since": null,
+              "pending": false,
+              "nick": null,
+              "mute": false,
+              "joined_at": "2026-11-13T01:07:25.410129+00:00",
+              "flags": 0,
+              "deaf": false,
+              "communication_disabled_until": null,
+              "banner": null,
+              "avatar": null
+            },
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          }
+        ],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2021-05-07T10:50:45.596000+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608411958182022",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Hello",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570605581192929301",
+        "author": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:12.937Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 19,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:12.887000+00:00",
+        "referenced_message": {
+          "type": 0,
+          "tts": false,
+          "timestamp": "2026-11-13T01:12:44.305000+00:00",
+          "pinned": false,
+          "mentions": [],
+          "mention_roles": [],
+          "mention_everyone": false,
+          "id": "1570607314732580917",
+          "flags": 0,
+          "embeds": [],
+          "edited_timestamp": null,
+          "content": "Fixture anchor for @effect/chat-discord (EFF-3695). Please reply to this message twice: once with the ping on, once with it off.",
+          "components": [],
+          "channel_type": 0,
+          "channel_id": "1570605581192929301",
+          "author": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "attachments": []
+        },
+        "pinned": false,
+        "nonce": "1570608439845978112",
+        "message_reference": {
+          "type": 0,
+          "message_id": "1570607314732580917",
+          "guild_id": "840178841540362250",
+          "channel_id": "1570605581192929301"
+        },
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2021-05-07T10:50:45.596000+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608441246883942",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Hello ping off",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570605581192929301",
+        "author": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:19.117Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 19,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:19.019000+00:00",
+        "referenced_message": {
+          "type": 0,
+          "tts": false,
+          "timestamp": "2026-11-13T01:16:13+00:00",
+          "pinned": false,
+          "mentions": [],
+          "mention_roles": [],
+          "mention_everyone": false,
+          "id": "1570608190062723103",
+          "flags": 0,
+          "embeds": [],
+          "edited_timestamp": null,
+          "content": "Fixture: a plain message in a guild text channel",
+          "components": [],
+          "channel_type": 0,
+          "channel_id": "1570607253965246584",
+          "author": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "attachments": []
+        },
+        "pinned": false,
+        "message_reference": {
+          "type": 0,
+          "message_id": "1570608190062723103",
+          "guild_id": "840178841540362250",
+          "channel_id": "1570607253965246584"
+        },
+        "mentions": [
+          {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "member": {
+              "roles": [
+                "1570605977017778196"
+              ],
+              "premium_since": null,
+              "pending": false,
+              "nick": null,
+              "mute": false,
+              "joined_at": "2026-11-13T01:07:25.410129+00:00",
+              "flags": 0,
+              "deaf": false,
+              "communication_disabled_until": null,
+              "banner": null,
+              "avatar": null
+            },
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          }
+        ],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608215308238930",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a reply with the ping on",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:20.669Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 19,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:20.534000+00:00",
+        "referenced_message": {
+          "type": 0,
+          "tts": false,
+          "timestamp": "2026-11-13T01:16:13+00:00",
+          "pinned": false,
+          "mentions": [],
+          "mention_roles": [],
+          "mention_everyone": false,
+          "id": "1570608190062723103",
+          "flags": 0,
+          "embeds": [],
+          "edited_timestamp": null,
+          "content": "Fixture: a plain message in a guild text channel",
+          "components": [],
+          "channel_type": 0,
+          "channel_id": "1570607253965246584",
+          "author": {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          },
+          "attachments": []
+        },
+        "pinned": false,
+        "message_reference": {
+          "type": 0,
+          "message_id": "1570608190062723103",
+          "guild_id": "840178841540362250",
+          "channel_id": "1570607253965246584"
+        },
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608221662740501",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a reply with the ping off",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/thread-messages.json b/packages/chat/discord/test/fixtures/events/thread-messages.json
new file mode 100644
index 00000000000..4b8fe985107
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/thread-messages.json
@@ -0,0 +1,221 @@
+{
+  "case": "Replies in a thread started from a message (by the bot and by the webhook, mentioning the bot), in a thread created without a message, and in a thread whose opener was then deleted; channel_type 11",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "the Janitor bot and webhook effect-chat-fixtures",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:16:50.146Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:50.045000+00:00",
+        "position": 0,
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608345440722956",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a reply in a thread started from a message",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608327602471024",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:16:52.016Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:51.911000+00:00",
+        "position": 1,
+        "pinned": false,
+        "mentions": [
+          {
+            "username": "Janitor",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "1564742987727118426",
+            "global_name": null,
+            "display_name_styles": null,
+            "discriminator": "5426",
+            "collectibles": null,
+            "clan": null,
+            "bot": true,
+            "avatar_decoration_data": null,
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+          }
+        ],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608353267159146",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a webhook reply in a thread, <@1564742987727118426>",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608327602471024",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:02.079Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:02.032000+00:00",
+        "position": 0,
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608395717972000",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: the first message in a thread created without a message",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608387434094622",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:09.492Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:09.258000+00:00",
+        "position": 0,
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608426025877659",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a reply before the opener is deleted",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608413061283862",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/thread-started.json b/packages/chat/discord/test/fixtures/events/thread-started.json
new file mode 100644
index 00000000000..86e20967364
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/thread-started.json
@@ -0,0 +1,188 @@
+{
+  "case": "What Discord delivers when a thread is started from a message (the THREAD_STARTER_MESSAGE, type 21, in the thread) and when one is created without a message (THREAD_CREATED, type 18, in the parent); both give no event",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "the Janitor bot, through REST",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:16:47.400Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 21,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:47.289000+00:00",
+        "position": 0,
+        "pinned": false,
+        "message_reference": {
+          "type": 0,
+          "message_id": "1570608327602471024",
+          "guild_id": "840178841540362250",
+          "channel_id": "1570607253965246584"
+        },
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608333881081877",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608327602471024",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:00.121Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 18,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:00.057000+00:00",
+        "pinned": false,
+        "message_reference": {
+          "type": 0,
+          "guild_id": "840178841540362250",
+          "channel_id": "1570608387434094622"
+        },
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608387434094622",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture thread without a message",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    },
+    {
+      "receivedAt": "2026-11-13T01:17:07.792Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "type": 21,
+        "tts": false,
+        "timestamp": "2026-11-13T01:17:07.747000+00:00",
+        "position": 0,
+        "pinned": false,
+        "message_reference": {
+          "type": 0,
+          "message_id": "1570608413061283862",
+          "guild_id": "840178841540362250",
+          "channel_id": "1570607253965246584"
+        },
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "member": {
+          "roles": [
+            "1570605977017778196"
+          ],
+          "premium_since": null,
+          "pending": false,
+          "nick": null,
+          "mute": false,
+          "joined_at": "2026-11-13T01:07:25.410129+00:00",
+          "flags": 0,
+          "deaf": false,
+          "communication_disabled_until": null,
+          "banner": null,
+          "avatar": null
+        },
+        "id": "1570608419688419446",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "",
+        "components": [],
+        "channel_type": 11,
+        "channel_id": "1570608413061283862",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/events/webhook-message.json b/packages/chat/discord/test/fixtures/events/webhook-message.json
new file mode 100644
index 00000000000..2c2dffee2c5
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/events/webhook-message.json
@@ -0,0 +1,46 @@
+{
+  "case": "A message from a webhook: author.id is the webhook id, webhook_id set, no member",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord gateway v10 dispatches to the Janitor application (1564742987727118426), logged by a local dfx-free websocket client with the GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGES, DIRECT_MESSAGE_REACTIONS and MESSAGE_CONTENT intents",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "author": "webhook effect-chat-fixtures (1570607260156297307)",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each d verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "dispatches": [
+    {
+      "receivedAt": "2026-11-13T01:16:14.492Z",
+      "t": "MESSAGE_CREATE",
+      "d": {
+        "webhook_id": "1570607260156297307",
+        "type": 0,
+        "tts": false,
+        "timestamp": "2026-11-13T01:16:14.460000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "id": "1570608196186411139",
+        "flags": 0,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "Fixture: a webhook message",
+        "components": [],
+        "channel_type": 0,
+        "channel_id": "1570607253965246584",
+        "author": {
+          "username": "effect-chat-fixtures",
+          "id": "1570607260156297307",
+          "global_name": null,
+          "discriminator": "0000",
+          "bot": true,
+          "avatar": null
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426",
+        "guild_id": "840178841540362250"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/channels.json b/packages/chat/discord/test/fixtures/recorded/channels.json
new file mode 100644
index 00000000000..c89b50d78b5
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/channels.json
@@ -0,0 +1,181 @@
+{
+  "case": "Channel reads: a text channel, a forum, a direct opened with Tim, and a thread",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:17Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "get-channel-text",
+      "method": "GET",
+      "path": "/channels/1570607253965246584",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1570607253965246584",
+        "type": 0,
+        "last_message_id": "1570608483965870101",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "effect-chat-scratch",
+        "parent_id": null,
+        "rate_limit_per_user": 0,
+        "topic": "Scratch channel for @effect/chat-discord fixtures (EFF-3695). Safe to delete.",
+        "position": 7,
+        "permission_overwrites": [
+          {
+            "id": "840178841540362250",
+            "type": 0,
+            "allow": "0",
+            "deny": "1024"
+          }
+        ],
+        "nsfw": false
+      }
+    },
+    {
+      "step": "get-channel-forum",
+      "method": "GET",
+      "path": "/channels/1570607255684915302",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1570607255684915302",
+        "type": 15,
+        "last_message_id": "1570608449778098218",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "effect-chat-forum",
+        "parent_id": null,
+        "rate_limit_per_user": 0,
+        "topic": "Scratch channel for @effect/chat-discord fixtures (EFF-3695). Safe to delete.",
+        "position": 0,
+        "permission_overwrites": [
+          {
+            "id": "840178841540362250",
+            "type": 0,
+            "allow": "0",
+            "deny": "1024"
+          }
+        ],
+        "nsfw": false,
+        "available_tags": [],
+        "default_reaction_emoji": null,
+        "default_sort_order": null,
+        "default_forum_layout": 0,
+        "default_tag_setting": "match_some",
+        "icon_emoji": null,
+        "theme_color": null,
+        "template": ""
+      }
+    },
+    {
+      "step": "dm-open",
+      "method": "POST",
+      "path": "/users/@me/channels",
+      "request": {
+        "recipient_id": "449108784879763458"
+      },
+      "status": 200,
+      "response": {
+        "id": "1570608637783572490",
+        "type": 1,
+        "last_message_id": null,
+        "flags": 0,
+        "recipients": [
+          {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ]
+      }
+    },
+    {
+      "step": "get-channel-dm",
+      "method": "GET",
+      "path": "/channels/1570608637783572490",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1570608637783572490",
+        "type": 1,
+        "last_message_id": null,
+        "flags": 0,
+        "recipients": [
+          {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ]
+      }
+    },
+    {
+      "step": "thread-get-channel",
+      "method": "GET",
+      "path": "/channels/1570608327602471024",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1570608327602471024",
+        "type": 11,
+        "last_message_id": "1570608353267159146",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "Fixture thread from a message",
+        "parent_id": "1570607253965246584",
+        "rate_limit_per_user": 0,
+        "bitrate": 64000,
+        "user_limit": 0,
+        "rtc_region": null,
+        "owner_id": "1564742987727118426",
+        "thread_metadata": {
+          "archived": false,
+          "archive_timestamp": "2026-11-13T01:16:47.280000+00:00",
+          "auto_archive_duration": 60,
+          "locked": false,
+          "create_timestamp": "2026-11-13T01:16:47.280000+00:00"
+        },
+        "message_count": 2,
+        "member_count": 1,
+        "total_message_sent": 2,
+        "member": {
+          "id": "1570608327602471024",
+          "user_id": "1564742987727118426",
+          "join_timestamp": "2026-11-13T01:16:47.281000+00:00",
+          "flags": 1,
+          "muted": false,
+          "mute_config": null
+        }
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/embeds.json b/packages/chat/discord/test/fixtures/recorded/embeds.json
new file mode 100644
index 00000000000..3f2b46b05b4
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/embeds.json
@@ -0,0 +1,414 @@
+{
+  "case": "SUPPRESS_EMBEDS: set on a post, kept through an edit that sends no flags and one that sends them; a post without it gets an embed",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:18Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "embed-post-suppressed",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: https://effect.website suppressed on post",
+        "flags": 4,
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: https://effect.website suppressed on post",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:23.451000+00:00",
+        "edited_timestamp": null,
+        "flags": 4,
+        "components": [],
+        "id": "1570608737213878394",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "embed-edit-adds-link-without-flag",
+      "method": "PATCH",
+      "path": "/channels/1570607253965246584/messages/1570608737213878394",
+      "request": {
+        "content": "Fixture: edit adds https://github.com/Effect-TS/effect without flags",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: edit adds https://github.com/Effect-TS/effect without flags",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:23.451000+00:00",
+        "edited_timestamp": "2026-11-13T01:18:24.973811+00:00",
+        "flags": 4,
+        "components": [],
+        "id": "1570608737213878394",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "embed-read-after-edit-without-flag",
+      "method": "GET",
+      "path": "/channels/1570607253965246584/messages/1570608737213878394",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: edit adds https://github.com/Effect-TS/effect without flags",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:23.451000+00:00",
+        "edited_timestamp": "2026-11-13T01:18:24.973000+00:00",
+        "flags": 4,
+        "components": [],
+        "id": "1570608737213878394",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "embed-post-plain",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: post without a link",
+        "flags": 4,
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: post without a link",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:30.633000+00:00",
+        "edited_timestamp": null,
+        "flags": 4,
+        "components": [],
+        "id": "1570608767337238549",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "embed-edit-adds-link-with-flag",
+      "method": "PATCH",
+      "path": "/channels/1570607253965246584/messages/1570608767337238549",
+      "request": {
+        "content": "Fixture: edit adds https://github.com/Effect-TS/effect with flags",
+        "flags": 4,
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: edit adds https://github.com/Effect-TS/effect with flags",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:30.633000+00:00",
+        "edited_timestamp": "2026-11-13T01:18:33.390847+00:00",
+        "flags": 4,
+        "components": [],
+        "id": "1570608767337238549",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "embed-read-after-edit-with-flag",
+      "method": "GET",
+      "path": "/channels/1570607253965246584/messages/1570608767337238549",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: edit adds https://github.com/Effect-TS/effect with flags",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:30.633000+00:00",
+        "edited_timestamp": "2026-11-13T01:18:33.390000+00:00",
+        "flags": 4,
+        "components": [],
+        "id": "1570608767337238549",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "embed-post-unsuppressed",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: https://effect.website not suppressed",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: https://effect.website not suppressed",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [
+          {
+            "type": "article",
+            "url": "https://effect.website/",
+            "title": "Effect | Production Grade TypeScript",
+            "provider": {
+              "name": "Effect"
+            },
+            "thumbnail": {
+              "url": "https://effect.website/og/index.png?v=8c9f1acacbf10295",
+              "proxy_url": "https://images-ext-1.discordapp.net/external/ac8H1c0fSuUVZaaFa8Kq5Ea8pOu0WAeL2xGxrJ6Y6Qc/%3Fv%3D8c9f1acacbf10295/https/effect.website/og/index.png",
+              "width": 1200,
+              "height": 630,
+              "content_type": "image/png",
+              "placeholder": "xQcGBIAIl3iIeIdyi3gHeAIAAA==",
+              "placeholder_version": 1,
+              "flags": 0
+            }
+          }
+        ],
+        "timestamp": "2026-11-13T01:18:39.014000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608802489700492",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "embed-read-unsuppressed",
+      "method": "GET",
+      "path": "/channels/1570607253965246584/messages/1570608802489700492",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: https://effect.website not suppressed",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [
+          {
+            "type": "article",
+            "url": "https://effect.website/",
+            "title": "Effect | Production Grade TypeScript",
+            "provider": {
+              "name": "Effect"
+            },
+            "thumbnail": {
+              "url": "https://effect.website/og/index.png?v=8c9f1acacbf10295",
+              "proxy_url": "https://images-ext-1.discordapp.net/external/ac8H1c0fSuUVZaaFa8Kq5Ea8pOu0WAeL2xGxrJ6Y6Qc/%3Fv%3D8c9f1acacbf10295/https/effect.website/og/index.png",
+              "width": 1200,
+              "height": 630,
+              "content_type": "image/png",
+              "placeholder": "xQcGBIAIl3iIeIdyi3gHeAIAAA==",
+              "placeholder_version": 1,
+              "flags": 0
+            }
+          }
+        ],
+        "timestamp": "2026-11-13T01:18:39.014000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608802489700492",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/errors.json b/packages/chat/discord/test/fixtures/recorded/errors.json
new file mode 100644
index 00000000000..66c75e03209
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/errors.json
@@ -0,0 +1,195 @@
+{
+  "case": "Error bodies: 160004 from a second startThread, 50024 from startThread in a forum post, unknown channel, message, user and member, an empty message, and content past the limit",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "thread-start-again",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages/1570608327602471024/threads",
+      "request": {
+        "name": "Fixture thread again"
+      },
+      "status": 400,
+      "response": {
+        "message": "A thread has already been created for this message",
+        "code": 160004
+      }
+    },
+    {
+      "step": "forum-start-thread-again",
+      "method": "POST",
+      "path": "/channels/1570608449778098218/messages/1570608449778098218/threads",
+      "request": {
+        "name": "again"
+      },
+      "status": 400,
+      "response": {
+        "message": "Cannot execute action on this channel type",
+        "code": 50024
+      }
+    },
+    {
+      "step": "get-channel-unknown",
+      "method": "GET",
+      "path": "/channels/1",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown Channel",
+        "code": 10003
+      }
+    },
+    {
+      "step": "get-user-unknown",
+      "method": "GET",
+      "path": "/users/1",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown User",
+        "code": 10013
+      }
+    },
+    {
+      "step": "get-user-webhook",
+      "method": "GET",
+      "path": "/users/1570607260156297307",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown User",
+        "code": 10013
+      }
+    },
+    {
+      "step": "get-member-unknown",
+      "method": "GET",
+      "path": "/guilds/840178841540362250/members/1",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown User",
+        "code": 10013
+      }
+    },
+    {
+      "step": "get-message-unknown",
+      "method": "GET",
+      "path": "/channels/1570607253965246584/messages/1",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown Message",
+        "code": 10008
+      }
+    },
+    {
+      "step": "edit-unknown",
+      "method": "PATCH",
+      "path": "/channels/1570607253965246584/messages/1",
+      "request": {
+        "content": "x"
+      },
+      "status": 404,
+      "response": {
+        "message": "Unknown Message",
+        "code": 10008
+      }
+    },
+    {
+      "step": "delete-unknown",
+      "method": "DELETE",
+      "path": "/channels/1570607253965246584/messages/1",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown Message",
+        "code": 10008
+      }
+    },
+    {
+      "step": "post-unknown-channel",
+      "method": "POST",
+      "path": "/channels/1/messages",
+      "request": {
+        "content": "x"
+      },
+      "status": 404,
+      "response": {
+        "message": "Unknown Channel",
+        "code": 10003
+      }
+    },
+    {
+      "step": "post-empty",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": ""
+      },
+      "status": 400,
+      "response": {
+        "message": "Cannot send an empty message",
+        "code": 50006
+      }
+    },
+    {
+      "step": "length-2001-ascii",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "content": {
+            "_errors": [
+              {
+                "code": "BASE_TYPE_MAX_LENGTH",
+                "message": "Must be 2000 or fewer in length."
+              }
+            ]
+          }
+        }
+      }
+    },
+    {
+      "step": "length-1999-plus-flag",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa🇬🇧",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "content": {
+            "_errors": [
+              {
+                "code": "BASE_TYPE_MAX_LENGTH",
+                "message": "Must be 2000 or fewer in length."
+              }
+            ]
+          }
+        }
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/history.json b/packages/chat/discord/test/fixtures/recorded/history.json
new file mode 100644
index 00000000000..b0e62fc0d33
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/history.json
@@ -0,0 +1,1095 @@
+{
+  "case": "Thread history: a thread started from a message (THREAD_STARTER_MESSAGE with referenced_message), the opener read in the parent and through the thread id, a thread created without a message, a thread whose opener was deleted (referenced_message null), and a forum post",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "thread-opener",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: a message a thread is started from",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: a message a thread is started from",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:45.792000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608327602471024",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "thread-start",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages/1570608327602471024/threads",
+      "request": {
+        "name": "Fixture thread from a message",
+        "auto_archive_duration": 60
+      },
+      "status": 201,
+      "response": {
+        "id": "1570608327602471024",
+        "type": 11,
+        "last_message_id": "1570608333881081877",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "Fixture thread from a message",
+        "parent_id": "1570607253965246584",
+        "rate_limit_per_user": 0,
+        "bitrate": 64000,
+        "user_limit": 0,
+        "rtc_region": null,
+        "owner_id": "1564742987727118426",
+        "thread_metadata": {
+          "archived": false,
+          "archive_timestamp": "2026-11-13T01:16:47.280866+00:00",
+          "auto_archive_duration": 60,
+          "locked": false,
+          "create_timestamp": "2026-11-13T01:16:47.280866+00:00"
+        },
+        "message_count": 0,
+        "member_count": 1,
+        "total_message_sent": 0,
+        "member": {
+          "id": "1570608327602471024",
+          "user_id": "1564742987727118426",
+          "join_timestamp": "2026-11-13T01:16:47.281657+00:00",
+          "flags": 1,
+          "muted": false,
+          "mute_config": null
+        }
+      }
+    },
+    {
+      "step": "thread-history",
+      "method": "GET",
+      "path": "/channels/1570608327602471024/messages?limit=50",
+      "request": null,
+      "status": 200,
+      "response": [
+        {
+          "type": 0,
+          "content": "Fixture: a webhook reply in a thread, <@1564742987727118426>",
+          "mentions": [
+            {
+              "id": "1564742987727118426",
+              "username": "Janitor",
+              "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+              "discriminator": "5426",
+              "public_flags": 0,
+              "flags": 0,
+              "bot": true,
+              "banner": null,
+              "accent_color": null,
+              "global_name": null,
+              "avatar_decoration_data": null,
+              "collectibles": null,
+              "display_name_styles": null,
+              "banner_color": null,
+              "clan": null,
+              "primary_guild": null
+            }
+          ],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:51.911000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608353267159146",
+          "channel_id": "1570608327602471024",
+          "author": {
+            "id": "1570607260156297307",
+            "username": "effect-chat-fixtures",
+            "avatar": null,
+            "discriminator": "0000",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "global_name": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "application_id": "1564742987727118426",
+          "webhook_id": "1570607260156297307",
+          "position": 1
+        },
+        {
+          "type": 0,
+          "content": "Fixture: a reply in a thread started from a message",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:50.045000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608345440722956",
+          "channel_id": "1570608327602471024",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "position": 0
+        },
+        {
+          "type": 21,
+          "content": "",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:47.289000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608333881081877",
+          "channel_id": "1570608327602471024",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "message_reference": {
+            "type": 0,
+            "channel_id": "1570607253965246584",
+            "message_id": "1570608327602471024",
+            "guild_id": "840178841540362250"
+          },
+          "position": 0,
+          "referenced_message": {
+            "type": 0,
+            "content": "Fixture: a message a thread is started from",
+            "mentions": [],
+            "mention_roles": [],
+            "attachments": [],
+            "embeds": [],
+            "timestamp": "2026-11-13T01:16:45.792000+00:00",
+            "edited_timestamp": null,
+            "flags": 32,
+            "components": [],
+            "id": "1570608327602471024",
+            "channel_id": "1570607253965246584",
+            "author": {
+              "id": "1564742987727118426",
+              "username": "Janitor",
+              "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+              "discriminator": "5426",
+              "public_flags": 0,
+              "flags": 0,
+              "bot": true,
+              "banner": null,
+              "accent_color": null,
+              "global_name": null,
+              "avatar_decoration_data": null,
+              "collectibles": null,
+              "display_name_styles": null,
+              "banner_color": null,
+              "clan": null,
+              "primary_guild": null
+            },
+            "pinned": false,
+            "mention_everyone": false,
+            "tts": false,
+            "thread": {
+              "id": "1570608327602471024",
+              "type": 11,
+              "last_message_id": "1570608353267159146",
+              "flags": 0,
+              "guild_id": "840178841540362250",
+              "name": "Fixture thread from a message",
+              "parent_id": "1570607253965246584",
+              "rate_limit_per_user": 0,
+              "bitrate": 64000,
+              "user_limit": 0,
+              "rtc_region": null,
+              "owner_id": "1564742987727118426",
+              "thread_metadata": {
+                "archived": false,
+                "archive_timestamp": "2026-11-13T01:16:47.280000+00:00",
+                "auto_archive_duration": 60,
+                "locked": false,
+                "create_timestamp": "2026-11-13T01:16:47.280000+00:00"
+              },
+              "message_count": 2,
+              "member_count": 1,
+              "total_message_sent": 2
+            }
+          }
+        }
+      ]
+    },
+    {
+      "step": "thread-history-forward",
+      "method": "GET",
+      "path": "/channels/1570608327602471024/messages?after=0&limit=50",
+      "request": null,
+      "status": 200,
+      "response": [
+        {
+          "type": 0,
+          "content": "Fixture: a webhook reply in a thread, <@1564742987727118426>",
+          "mentions": [
+            {
+              "id": "1564742987727118426",
+              "username": "Janitor",
+              "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+              "discriminator": "5426",
+              "public_flags": 0,
+              "flags": 0,
+              "bot": true,
+              "banner": null,
+              "accent_color": null,
+              "global_name": null,
+              "avatar_decoration_data": null,
+              "collectibles": null,
+              "display_name_styles": null,
+              "banner_color": null,
+              "clan": null,
+              "primary_guild": null
+            }
+          ],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:51.911000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608353267159146",
+          "channel_id": "1570608327602471024",
+          "author": {
+            "id": "1570607260156297307",
+            "username": "effect-chat-fixtures",
+            "avatar": null,
+            "discriminator": "0000",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "global_name": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "application_id": "1564742987727118426",
+          "webhook_id": "1570607260156297307",
+          "position": 1
+        },
+        {
+          "type": 0,
+          "content": "Fixture: a reply in a thread started from a message",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:50.045000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608345440722956",
+          "channel_id": "1570608327602471024",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "position": 0
+        },
+        {
+          "type": 21,
+          "content": "",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:47.289000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608333881081877",
+          "channel_id": "1570608327602471024",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "message_reference": {
+            "type": 0,
+            "channel_id": "1570607253965246584",
+            "message_id": "1570608327602471024",
+            "guild_id": "840178841540362250"
+          },
+          "position": 0,
+          "referenced_message": {
+            "type": 0,
+            "content": "Fixture: a message a thread is started from",
+            "mentions": [],
+            "mention_roles": [],
+            "attachments": [],
+            "embeds": [],
+            "timestamp": "2026-11-13T01:16:45.792000+00:00",
+            "edited_timestamp": null,
+            "flags": 32,
+            "components": [],
+            "id": "1570608327602471024",
+            "channel_id": "1570607253965246584",
+            "author": {
+              "id": "1564742987727118426",
+              "username": "Janitor",
+              "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+              "discriminator": "5426",
+              "public_flags": 0,
+              "flags": 0,
+              "bot": true,
+              "banner": null,
+              "accent_color": null,
+              "global_name": null,
+              "avatar_decoration_data": null,
+              "collectibles": null,
+              "display_name_styles": null,
+              "banner_color": null,
+              "clan": null,
+              "primary_guild": null
+            },
+            "pinned": false,
+            "mention_everyone": false,
+            "tts": false,
+            "thread": {
+              "id": "1570608327602471024",
+              "type": 11,
+              "last_message_id": "1570608353267159146",
+              "flags": 0,
+              "guild_id": "840178841540362250",
+              "name": "Fixture thread from a message",
+              "parent_id": "1570607253965246584",
+              "rate_limit_per_user": 0,
+              "bitrate": 64000,
+              "user_limit": 0,
+              "rtc_region": null,
+              "owner_id": "1564742987727118426",
+              "thread_metadata": {
+                "archived": false,
+                "archive_timestamp": "2026-11-13T01:16:47.280000+00:00",
+                "auto_archive_duration": 60,
+                "locked": false,
+                "create_timestamp": "2026-11-13T01:16:47.280000+00:00"
+              },
+              "message_count": 2,
+              "member_count": 1,
+              "total_message_sent": 2
+            }
+          }
+        }
+      ]
+    },
+    {
+      "step": "thread-get-channel",
+      "method": "GET",
+      "path": "/channels/1570608327602471024",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1570608327602471024",
+        "type": 11,
+        "last_message_id": "1570608353267159146",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "Fixture thread from a message",
+        "parent_id": "1570607253965246584",
+        "rate_limit_per_user": 0,
+        "bitrate": 64000,
+        "user_limit": 0,
+        "rtc_region": null,
+        "owner_id": "1564742987727118426",
+        "thread_metadata": {
+          "archived": false,
+          "archive_timestamp": "2026-11-13T01:16:47.280000+00:00",
+          "auto_archive_duration": 60,
+          "locked": false,
+          "create_timestamp": "2026-11-13T01:16:47.280000+00:00"
+        },
+        "message_count": 2,
+        "member_count": 1,
+        "total_message_sent": 2,
+        "member": {
+          "id": "1570608327602471024",
+          "user_id": "1564742987727118426",
+          "join_timestamp": "2026-11-13T01:16:47.281000+00:00",
+          "flags": 1,
+          "muted": false,
+          "mute_config": null
+        }
+      }
+    },
+    {
+      "step": "thread-get-opener",
+      "method": "GET",
+      "path": "/channels/1570607253965246584/messages/1570608327602471024",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: a message a thread is started from",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:45.792000+00:00",
+        "edited_timestamp": null,
+        "flags": 32,
+        "components": [],
+        "id": "1570608327602471024",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "thread": {
+          "id": "1570608327602471024",
+          "type": 11,
+          "last_message_id": "1570608353267159146",
+          "flags": 0,
+          "guild_id": "840178841540362250",
+          "name": "Fixture thread from a message",
+          "parent_id": "1570607253965246584",
+          "rate_limit_per_user": 0,
+          "bitrate": 64000,
+          "user_limit": 0,
+          "rtc_region": null,
+          "owner_id": "1564742987727118426",
+          "thread_metadata": {
+            "archived": false,
+            "archive_timestamp": "2026-11-13T01:16:47.280000+00:00",
+            "auto_archive_duration": 60,
+            "locked": false,
+            "create_timestamp": "2026-11-13T01:16:47.280000+00:00"
+          },
+          "message_count": 2,
+          "member_count": 1,
+          "total_message_sent": 2
+        }
+      }
+    },
+    {
+      "step": "thread-get-opener-by-thread-id",
+      "method": "GET",
+      "path": "/channels/1570608327602471024/messages/1570608327602471024",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown Message",
+        "code": 10008
+      }
+    },
+    {
+      "step": "thread-nomessage-start",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/threads",
+      "request": {
+        "name": "Fixture thread without a message",
+        "type": 11,
+        "auto_archive_duration": 60
+      },
+      "status": 201,
+      "response": {
+        "id": "1570608387434094622",
+        "type": 11,
+        "last_message_id": null,
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "Fixture thread without a message",
+        "parent_id": "1570607253965246584",
+        "rate_limit_per_user": 0,
+        "bitrate": 64000,
+        "user_limit": 0,
+        "rtc_region": null,
+        "owner_id": "1564742987727118426",
+        "thread_metadata": {
+          "archived": false,
+          "archive_timestamp": "2026-11-13T01:17:00.057000+00:00",
+          "auto_archive_duration": 60,
+          "locked": false,
+          "create_timestamp": "2026-11-13T01:17:00.057000+00:00"
+        },
+        "message_count": 0,
+        "member_count": 1,
+        "total_message_sent": 0,
+        "member": {
+          "id": "1570608387434094622",
+          "user_id": "1564742987727118426",
+          "join_timestamp": "2026-11-13T01:17:00.232722+00:00",
+          "flags": 1,
+          "muted": false,
+          "mute_config": null
+        }
+      }
+    },
+    {
+      "step": "thread-nomessage-history",
+      "method": "GET",
+      "path": "/channels/1570608387434094622/messages?limit=50",
+      "request": null,
+      "status": 200,
+      "response": [
+        {
+          "type": 0,
+          "content": "Fixture: the first message in a thread created without a message",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:17:02.032000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608395717972000",
+          "channel_id": "1570608387434094622",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "position": 0
+        }
+      ]
+    },
+    {
+      "step": "thread-deleted-opener",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: an opener that will be deleted",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: an opener that will be deleted",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:17:06.167000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608413061283862",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "thread-deleted-start",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages/1570608413061283862/threads",
+      "request": {
+        "name": "Fixture thread whose opener is deleted",
+        "auto_archive_duration": 60
+      },
+      "status": 201,
+      "response": {
+        "id": "1570608413061283862",
+        "type": 11,
+        "last_message_id": "1570608419688419446",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "Fixture thread whose opener is deleted",
+        "parent_id": "1570607253965246584",
+        "rate_limit_per_user": 0,
+        "bitrate": 64000,
+        "user_limit": 0,
+        "rtc_region": null,
+        "owner_id": "1564742987727118426",
+        "thread_metadata": {
+          "archived": false,
+          "archive_timestamp": "2026-11-13T01:17:07.739708+00:00",
+          "auto_archive_duration": 60,
+          "locked": false,
+          "create_timestamp": "2026-11-13T01:17:07.739708+00:00"
+        },
+        "message_count": 0,
+        "member_count": 1,
+        "total_message_sent": 0,
+        "member": {
+          "id": "1570608413061283862",
+          "user_id": "1564742987727118426",
+          "join_timestamp": "2026-11-13T01:17:07.740426+00:00",
+          "flags": 1,
+          "muted": false,
+          "mute_config": null
+        }
+      }
+    },
+    {
+      "step": "thread-deleted-history",
+      "method": "GET",
+      "path": "/channels/1570608413061283862/messages?limit=50",
+      "request": null,
+      "status": 200,
+      "response": [
+        {
+          "type": 0,
+          "content": "Fixture: a reply before the opener is deleted",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:17:09.258000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608426025877659",
+          "channel_id": "1570608413061283862",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "position": 0
+        },
+        {
+          "type": 21,
+          "content": "",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:17:07.747000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608419688419446",
+          "channel_id": "1570608413061283862",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "message_reference": {
+            "type": 0,
+            "channel_id": "1570607253965246584",
+            "message_id": "1570608413061283862",
+            "guild_id": "840178841540362250"
+          },
+          "position": 0,
+          "referenced_message": null
+        }
+      ]
+    },
+    {
+      "step": "thread-deleted-get-opener",
+      "method": "GET",
+      "path": "/channels/1570607253965246584/messages/1570608413061283862",
+      "request": null,
+      "status": 404,
+      "response": {
+        "message": "Unknown Message",
+        "code": 10008
+      }
+    },
+    {
+      "step": "forum-post",
+      "method": "POST",
+      "path": "/channels/1570607255684915302/threads",
+      "request": {
+        "name": "Fixture forum post",
+        "message": {
+          "content": "Fixture: the starter of a forum post",
+          "allowed_mentions": {
+            "parse": []
+          }
+        },
+        "auto_archive_duration": 60
+      },
+      "status": 201,
+      "response": {
+        "id": "1570608449778098218",
+        "type": 11,
+        "last_message_id": "1570608449778098218",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "Fixture forum post",
+        "parent_id": "1570607255684915302",
+        "rate_limit_per_user": 0,
+        "bitrate": 64000,
+        "user_limit": 0,
+        "rtc_region": null,
+        "owner_id": "1564742987727118426",
+        "thread_metadata": {
+          "archived": false,
+          "archive_timestamp": "2026-11-13T01:17:14.921000+00:00",
+          "auto_archive_duration": 60,
+          "locked": false,
+          "create_timestamp": "2026-11-13T01:17:14.921000+00:00"
+        },
+        "message_count": 0,
+        "member_count": 1,
+        "total_message_sent": 0,
+        "member": {
+          "id": "1570608449778098218",
+          "user_id": "1564742987727118426",
+          "join_timestamp": "2026-11-13T01:17:14.926069+00:00",
+          "flags": 1,
+          "muted": false,
+          "mute_config": null
+        },
+        "message": {
+          "type": 0,
+          "content": "Fixture: the starter of a forum post",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:17:14.921000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608449778098218",
+          "channel_id": "1570608449778098218",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "position": 0
+        }
+      }
+    },
+    {
+      "step": "forum-history",
+      "method": "GET",
+      "path": "/channels/1570608449778098218/messages?limit=50",
+      "request": null,
+      "status": 200,
+      "response": [
+        {
+          "type": 0,
+          "content": "Fixture: a later reply in a forum post",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:17:16.290000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608455520227379",
+          "channel_id": "1570608449778098218",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "position": 0
+        },
+        {
+          "type": 0,
+          "content": "Fixture: the starter of a forum post",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:17:14.921000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608449778098218",
+          "channel_id": "1570608449778098218",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "position": 0
+        }
+      ]
+    },
+    {
+      "step": "forum-get-starter",
+      "method": "GET",
+      "path": "/channels/1570608449778098218/messages/1570608449778098218",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: the starter of a forum post",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:17:14.921000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608449778098218",
+        "channel_id": "1570608449778098218",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "position": 0
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/length.json b/packages/chat/discord/test/fixtures/recorded/length.json
new file mode 100644
index 00000000000..e35528d45ed
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/length.json
@@ -0,0 +1,299 @@
+{
+  "case": "Content length probes: 2,000 ASCII, 2,000 astral emoji, 2,000 two-byte letters and 1,000 combining pairs pass; 2,001 ASCII and 1,999 letters plus a flag fail. Discord counts code points",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:18Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "length-2000-ascii",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:09.244000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608677625401476",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "length-2001-ascii",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "content": {
+            "_errors": [
+              {
+                "code": "BASE_TYPE_MAX_LENGTH",
+                "message": "Must be 2000 or fewer in length."
+              }
+            ]
+          }
+        }
+      }
+    },
+    {
+      "step": "length-2000-astral",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:11.935000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608688912273419",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "length-1001-astral",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:13.927000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608697267322883",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "length-2000-bmp",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:15.335000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608703172780053",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "length-2000-combining",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:18:16.737000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608709053452330",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "length-1999-plus-flag",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa🇬🇧",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "content": {
+            "_errors": [
+              {
+                "code": "BASE_TYPE_MAX_LENGTH",
+                "message": "Must be 2000 or fewer in length."
+              }
+            ]
+          }
+        }
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/other-bots.json b/packages/chat/discord/test/fixtures/recorded/other-bots.json
new file mode 100644
index 00000000000..44a413c7c49
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/other-bots.json
@@ -0,0 +1,445 @@
+{
+  "case": "Messages by other bots in the guild's #general, read through REST: slash command replies (type 20) from Tim's Test Bot, Polly and Effect Bot, a plain message and a reply (type 19)",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:28Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "other-bot-command-reply",
+      "method": "GET",
+      "path": "/channels/840178841540362253/messages/1112338250816831548",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 20,
+        "content": "Hello",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2023-05-28T11:15:05.240000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1112338250816831548",
+        "channel_id": "840178841540362253",
+        "author": {
+          "id": "841095454762205184",
+          "username": "Tim's Test Bot",
+          "avatar": null,
+          "discriminator": "4902",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "841095454762205184",
+        "interaction": {
+          "id": "1112338249915060285",
+          "type": 2,
+          "name": "hello",
+          "user": {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        },
+        "webhook_id": "841095454762205184"
+      }
+    },
+    {
+      "step": "other-bot-command-reply-empty",
+      "method": "GET",
+      "path": "/channels/840178841540362253/messages/1197424261783097434",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 20,
+        "content": "",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [
+          {
+            "type": "rich",
+            "title": "a text look",
+            "description": "Multiple votes are allowed.",
+            "color": 10070709,
+            "fields": [
+              {
+                "name": "jdhfhd (0)",
+                "value": "No votes",
+                "inline": false
+              },
+              {
+                "name": "jdkfjjfjdkfkf (0)",
+                "value": "No votes",
+                "inline": false
+              },
+              {
+                "name": "i48t84h (0)",
+                "value": "No votes",
+                "inline": false
+              }
+            ],
+            "content_scan_version": 4
+          }
+        ],
+        "timestamp": "2024-01-18T06:16:31.076000+00:00",
+        "edited_timestamp": "2024-01-18T06:16:46.623000+00:00",
+        "flags": 0,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "vote_65a8c23e75cb3d35044293e5_0",
+                "style": 1,
+                "label": "jdhfhd"
+              },
+              {
+                "type": 2,
+                "id": 3,
+                "custom_id": "vote_65a8c23e75cb3d35044293e5_1",
+                "style": 1,
+                "label": "jdkfjjfjdkfkf"
+              },
+              {
+                "type": 2,
+                "id": 4,
+                "custom_id": "vote_65a8c23e75cb3d35044293e5_2",
+                "style": 1,
+                "label": "i48t84h"
+              }
+            ]
+          }
+        ],
+        "id": "1197424261783097434",
+        "channel_id": "840178841540362253",
+        "author": {
+          "id": "848334981734596608",
+          "username": "Polly",
+          "avatar": "99eddd75a6c236bc0751205c93b2b03d",
+          "discriminator": "7293",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "848334981734596608",
+        "interaction": {
+          "id": "1197424259857928223",
+          "type": 2,
+          "name": "poll",
+          "user": {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        },
+        "webhook_id": "848334981734596608"
+      }
+    },
+    {
+      "step": "other-bot-command-reply-effect-bot",
+      "method": "GET",
+      "path": "/channels/840178841540362253/messages/1113758855839612981",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 20,
+        "content": "",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [
+          {
+            "type": "rich",
+            "url": "https://effect-ts.github.io/io/modules/Effect.ts.html#flatmap-1",
+            "title": "Effect.flatMap",
+            "description": "This function is a pipeable operator that maps over an Effect value, flattening the result of the mapping function into a new Effect value. Signature\n\n```typescript\nexport declare const flatMap: {\n  (f: (a: A) => Effect): (\n    self: Effect,\n  ) => Effect\n  (\n    self: Effect,\n    f: (a: A) => Effect,\n  ): Effect\n}\n\n```",
+            "color": 8924875,
+            "author": {
+              "name": "@effect/io"
+            },
+            "footer": {
+              "text": "Added in v1.0.0"
+            },
+            "content_scan_version": 4
+          }
+        ],
+        "timestamp": "2023-06-01T09:20:03.871000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1113758855839612981",
+        "channel_id": "840178841540362253",
+        "author": {
+          "id": "1101072322271641661",
+          "username": "Effect Bot",
+          "avatar": null,
+          "discriminator": "5597",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1101072322271641661",
+        "interaction": {
+          "id": "1113758852408692758",
+          "type": 2,
+          "name": "docs",
+          "user": {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        },
+        "webhook_id": "1101072322271641661"
+      }
+    },
+    {
+      "step": "other-bot-plain",
+      "method": "GET",
+      "path": "/channels/840178841540362253/messages/959400132728750140",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Pong!",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2022-04-01T10:33:36.435000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "959400132728750140",
+        "channel_id": "840178841540362253",
+        "author": {
+          "id": "841095454762205184",
+          "username": "Tim's Test Bot",
+          "avatar": null,
+          "discriminator": "4902",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "other-bot-reply",
+      "method": "GET",
+      "path": "/channels/840178841540362253/messages/1103552217971167293",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 19,
+        "content": "Hello!",
+        "mentions": [
+          {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2023-05-04T05:22:31.773000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1103552217971167293",
+        "channel_id": "840178841540362253",
+        "author": {
+          "id": "841095454762205184",
+          "username": "Tim's Test Bot",
+          "avatar": null,
+          "discriminator": "4902",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "message_reference": {
+          "type": 0,
+          "channel_id": "840178841540362253",
+          "message_id": "1103552216398303272",
+          "guild_id": "840178841540362250"
+        },
+        "referenced_message": {
+          "type": 19,
+          "content": "asdf",
+          "mentions": [
+            {
+              "id": "841095454762205184",
+              "username": "Tim's Test Bot",
+              "avatar": null,
+              "discriminator": "4902",
+              "public_flags": 0,
+              "flags": 0,
+              "bot": true,
+              "banner": null,
+              "accent_color": null,
+              "global_name": null,
+              "avatar_decoration_data": null,
+              "collectibles": null,
+              "display_name_styles": null,
+              "banner_color": null,
+              "clan": null,
+              "primary_guild": null
+            }
+          ],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2023-05-04T05:22:31.398000+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1103552216398303272",
+          "channel_id": "840178841540362253",
+          "author": {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false,
+          "message_reference": {
+            "type": 0,
+            "channel_id": "840178841540362253",
+            "message_id": "1103552140401725440",
+            "guild_id": "840178841540362250"
+          }
+        }
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/posts.json b/packages/chat/discord/test/fixtures/recorded/posts.json
new file mode 100644
index 00000000000..14f2c02f064
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/posts.json
@@ -0,0 +1,1009 @@
+{
+  "case": "Messages as createMessage and the webhook return them, for the posts behind the gateway fixtures",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:16Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "channel-plain",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: a plain message in a guild text channel",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: a plain message in a guild text channel",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:13+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608190062723103",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "webhook-plain",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: a webhook message",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: a webhook message",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:14.460000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608196186411139",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "attachment-fixed",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "multipart": {
+          "content": "Fixture: a message with an attachment, fixed",
+          "files": [
+            "fixture.txt (text/plain, 23 bytes)"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: a message with an attachment, fixed",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [
+          {
+            "id": "1570611668722122812",
+            "filename": "fixture.txt",
+            "size": 23,
+            "url": "https://cdn.discordapp.com/attachments/1570607253965246584/1570611668722122812/fixture.txt?scrubbed",
+            "proxy_url": "https://media.discordapp.net/attachments/1570607253965246584/1570611668722122812/fixture.txt?scrubbed",
+            "content_type": "text/plain; charset=utf-8",
+            "content_scan_version": 0
+          }
+        ],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:30:02.447000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570611669015732315",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      },
+      "scrubbed": [
+        "$.attachments[0].url",
+        "$.attachments[0].proxy_url"
+      ]
+    },
+    {
+      "step": "reply-bot-ping-on",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: a reply with the ping on",
+        "message_reference": {
+          "message_id": "1570608190062723103"
+        },
+        "allowed_mentions": {
+          "parse": [],
+          "replied_user": true
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 19,
+        "content": "Fixture: a reply with the ping on",
+        "mentions": [
+          {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:19.019000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608215308238930",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "message_reference": {
+          "type": 0,
+          "channel_id": "1570607253965246584",
+          "message_id": "1570608190062723103",
+          "guild_id": "840178841540362250"
+        },
+        "referenced_message": {
+          "type": 0,
+          "content": "Fixture: a plain message in a guild text channel",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:13+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608190062723103",
+          "channel_id": "1570607253965246584",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false
+        }
+      }
+    },
+    {
+      "step": "reply-bot-ping-off",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: a reply with the ping off",
+        "message_reference": {
+          "message_id": "1570608190062723103"
+        },
+        "allowed_mentions": {
+          "parse": [],
+          "replied_user": false
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 19,
+        "content": "Fixture: a reply with the ping off",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:20.534000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608221662740501",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "message_reference": {
+          "type": 0,
+          "channel_id": "1570607253965246584",
+          "message_id": "1570608190062723103",
+          "guild_id": "840178841540362250"
+        },
+        "referenced_message": {
+          "type": 0,
+          "content": "Fixture: a plain message in a guild text channel",
+          "mentions": [],
+          "mention_roles": [],
+          "attachments": [],
+          "embeds": [],
+          "timestamp": "2026-11-13T01:16:13+00:00",
+          "edited_timestamp": null,
+          "flags": 0,
+          "components": [],
+          "id": "1570608190062723103",
+          "channel_id": "1570607253965246584",
+          "author": {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "pinned": false,
+          "mention_everyone": false,
+          "tts": false
+        }
+      }
+    },
+    {
+      "step": "mention-bot",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: <@1564742987727118426> as a plain user token",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: <@1564742987727118426> as a plain user token",
+        "mentions": [
+          {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:22.010000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608227853533387",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-bot-nick",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: <@!1564742987727118426> as a nickname token",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: <@!1564742987727118426> as a nickname token",
+        "mentions": [
+          {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:23.426000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608233792405568",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-user",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: <@449108784879763458> another user",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: <@449108784879763458> another user",
+        "mentions": [
+          {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:24.944000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608240159625278",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-role",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: <@&1570607256838479964> a role",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: <@&1570607256838479964> a role",
+        "mentions": [],
+        "mention_roles": [
+          "1570607256838479964"
+        ],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:26.546000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608246878773301",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-everyone",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: @everyone that resolves",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: @everyone that resolves",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:28.416000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608254721982479",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": true,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-here",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: @here that resolves",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: @here that resolves",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:29.899000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608260942397441",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": true,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-everyone-suppressed",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: @everyone with parse empty",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: @everyone with parse empty",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:31.658000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608268320051301",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-channel",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: <#1570605581192929301> a channel",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: <#1570605581192929301> a channel",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:33.157000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608274607440034",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-code-span",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: `<@1564742987727118426>` in a code span",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: `<@1564742987727118426>` in a code span",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:35.311000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608283641970709",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-fence",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: in a fence\n```\n<@1564742987727118426>\n```",
+        "allowed_mentions": {
+          "parse": [
+            "users",
+            "roles",
+            "everyone"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: in a fence\n```\n<@1564742987727118426>\n```",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:36.848000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608290088484875",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    },
+    {
+      "step": "mention-bot-by-bot",
+      "method": "POST",
+      "path": "/channels/1570607253965246584/messages",
+      "request": {
+        "content": "Fixture: the bot naming <@1564742987727118426> and <@&1570607256838479964> with parse empty",
+        "allowed_mentions": {
+          "parse": []
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: the bot naming <@1564742987727118426> and <@&1570607256838479964> with parse empty",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:38.346000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608296371425382",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "mention-mixed",
+      "method": "POST",
+      "path": "/webhooks/1570607260156297307/{webhook_token}?wait=true",
+      "request": {
+        "content": "Fixture: <@1564742987727118426> and `<@449108784879763458>` and <@&1570607256838479964> and <#1570607253965246584>",
+        "allowed_mentions": {
+          "parse": [],
+          "users": [
+            "1564742987727118426"
+          ],
+          "roles": [
+            "1570607256838479964"
+          ]
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: <@1564742987727118426> and `<@449108784879763458>` and <@&1570607256838479964> and <#1570607253965246584>",
+        "mentions": [
+          {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ],
+        "mention_roles": [
+          "1570607256838479964"
+        ],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:16:39.899000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608302885179546",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1570607260156297307",
+          "username": "effect-chat-fixtures",
+          "avatar": null,
+          "discriminator": "0000",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "global_name": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "webhook_id": "1570607260156297307"
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/reactions.json b/packages/chat/discord/test/fixtures/recorded/reactions.json
new file mode 100644
index 00000000000..851dc8ae093
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/reactions.json
@@ -0,0 +1,197 @@
+{
+  "case": "A message read back while it carries a Unicode, a skin-toned and a custom reaction, in a channel and in a thread",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:17Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "reaction-read-channel",
+      "method": "GET",
+      "path": "/channels/1570607253965246584/messages/1570608483965870101",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: reactions target in a channel",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:17:23.072000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608483965870101",
+        "channel_id": "1570607253965246584",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "reactions": [
+          {
+            "emoji": {
+              "id": null,
+              "name": "👍"
+            },
+            "count": 1,
+            "count_details": {
+              "burst": 0,
+              "normal": 1
+            },
+            "burst_colors": [],
+            "me_burst": false,
+            "burst_me": false,
+            "me": true,
+            "burst_count": 0
+          },
+          {
+            "emoji": {
+              "id": null,
+              "name": "👍🏽"
+            },
+            "count": 1,
+            "count_details": {
+              "burst": 0,
+              "normal": 1
+            },
+            "burst_colors": [],
+            "me_burst": false,
+            "burst_me": false,
+            "me": true,
+            "burst_count": 0
+          },
+          {
+            "emoji": {
+              "id": "1570607258226790481",
+              "name": "effectchat"
+            },
+            "count": 1,
+            "count_details": {
+              "burst": 0,
+              "normal": 1
+            },
+            "burst_colors": [],
+            "me_burst": false,
+            "burst_me": false,
+            "me": true,
+            "burst_count": 0
+          }
+        ]
+      }
+    },
+    {
+      "step": "reaction-read-thread",
+      "method": "GET",
+      "path": "/channels/1570608327602471024/messages/1570608491532386377",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "Fixture: reactions target in a thread",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:17:24.876000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570608491532386377",
+        "channel_id": "1570608327602471024",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "position": 2,
+        "reactions": [
+          {
+            "emoji": {
+              "id": null,
+              "name": "👍"
+            },
+            "count": 1,
+            "count_details": {
+              "burst": 0,
+              "normal": 1
+            },
+            "burst_colors": [],
+            "me_burst": false,
+            "burst_me": false,
+            "me": true,
+            "burst_count": 0
+          },
+          {
+            "emoji": {
+              "id": null,
+              "name": "👍🏽"
+            },
+            "count": 1,
+            "count_details": {
+              "burst": 0,
+              "normal": 1
+            },
+            "burst_colors": [],
+            "me_burst": false,
+            "burst_me": false,
+            "me": true,
+            "burst_count": 0
+          },
+          {
+            "emoji": {
+              "id": "1570607258226790481",
+              "name": "effectchat"
+            },
+            "count": 1,
+            "count_details": {
+              "burst": 0,
+              "normal": 1
+            },
+            "burst_colors": [],
+            "me_burst": false,
+            "burst_me": false,
+            "me": true,
+            "burst_count": 0
+          }
+        ]
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/users.json b/packages/chat/discord/test/fixtures/recorded/users.json
new file mode 100644
index 00000000000..2808fd78389
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/users.json
@@ -0,0 +1,177 @@
+{
+  "case": "User and member reads: the bot, Tim, and the bot's own user",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
+    "recordedAt": "2026-11-13T01:17Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
+  },
+  "calls": [
+    {
+      "step": "get-user-bot",
+      "method": "GET",
+      "path": "/users/1564742987727118426",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1564742987727118426",
+        "username": "Janitor",
+        "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+        "discriminator": "5426",
+        "public_flags": 0,
+        "flags": 0,
+        "bot": true,
+        "banner": null,
+        "accent_color": null,
+        "global_name": null,
+        "avatar_decoration_data": null,
+        "collectibles": null,
+        "display_name_styles": null,
+        "banner_color": null,
+        "clan": null,
+        "primary_guild": null
+      }
+    },
+    {
+      "step": "get-user-tim",
+      "method": "GET",
+      "path": "/users/449108784879763458",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "449108784879763458",
+        "username": "timsmart",
+        "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+        "discriminator": "0",
+        "public_flags": 0,
+        "flags": 0,
+        "banner": null,
+        "accent_color": null,
+        "global_name": "Tim Smart",
+        "avatar_decoration_data": null,
+        "collectibles": null,
+        "display_name_styles": null,
+        "banner_color": null,
+        "clan": null,
+        "primary_guild": null
+      }
+    },
+    {
+      "step": "get-member-bot",
+      "method": "GET",
+      "path": "/guilds/840178841540362250/members/1564742987727118426",
+      "request": null,
+      "status": 200,
+      "response": {
+        "avatar": null,
+        "banner": null,
+        "communication_disabled_until": null,
+        "flags": 0,
+        "joined_at": "2026-11-13T01:07:25.410000+00:00",
+        "nick": null,
+        "pending": false,
+        "premium_since": null,
+        "roles": [
+          "1570605977017778196"
+        ],
+        "unusual_dm_activity_until": null,
+        "collectibles": null,
+        "display_name_styles": null,
+        "member_gaming_leaderboard_data": null,
+        "user": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "mute": false,
+        "deaf": false
+      }
+    },
+    {
+      "step": "get-member-tim",
+      "method": "GET",
+      "path": "/guilds/840178841540362250/members/449108784879763458",
+      "request": null,
+      "status": 200,
+      "response": {
+        "avatar": null,
+        "banner": null,
+        "communication_disabled_until": null,
+        "flags": 0,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "nick": null,
+        "pending": false,
+        "premium_since": null,
+        "roles": [],
+        "unusual_dm_activity_until": null,
+        "collectibles": null,
+        "display_name_styles": null,
+        "member_gaming_leaderboard_data": null,
+        "user": {
+          "id": "449108784879763458",
+          "username": "timsmart",
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+          "discriminator": "0",
+          "public_flags": 0,
+          "flags": 0,
+          "banner": null,
+          "accent_color": null,
+          "global_name": "Tim Smart",
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "mute": false,
+        "deaf": false
+      }
+    },
+    {
+      "step": "get-me",
+      "method": "GET",
+      "path": "/users/@me",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1564742987727118426",
+        "username": "Janitor",
+        "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+        "discriminator": "5426",
+        "public_flags": 0,
+        "flags": 0,
+        "bot": true,
+        "banner": null,
+        "accent_color": null,
+        "global_name": null,
+        "avatar_decoration_data": null,
+        "collectibles": null,
+        "display_name_styles": null,
+        "banner_color": null,
+        "clan": null,
+        "primary_guild": null,
+        "mfa_enabled": true,
+        "locale": "en-US",
+        "premium_type": 0,
+        "email": null,
+        "verified": true,
+        "bio": ""
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/live.test.ts b/packages/chat/discord/test/live.test.ts
new file mode 100644
index 00000000000..f6bc7a2b192
--- /dev/null
+++ b/packages/chat/discord/test/live.test.ts
@@ -0,0 +1,102 @@
+/**
+ * The conformance suite against a real Discord guild. Opt-in: it runs only
+ * when these are set, so CI skips it.
+ *
+ * - `DISCORD_LIVE_BOT_TOKEN` and `DISCORD_LIVE_CHANNEL`: the bot and a
+ *   scratch text channel it may write to. Threads that `startThread` makes
+ *   can't be deleted through the core ops, so they are left behind.
+ * - `DISCORD_LIVE_SECOND_BOT_TOKEN`: a second bot in the guild, for the
+ *   rules that need another identity's message. Without it,
+ *   `DISCORD_LIVE_WEBHOOK_URL`, a webhook on the channel, stands in. Without
+ *   either, those rules fail at `userPosts`.
+ */
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { describe, it } from "@effect/vitest"
+import { DiscordConfig, DiscordREST, DiscordRESTMemoryLive } from "dfx"
+import * as Chat from "effect/chat/Chat"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { conformance } from "effect/chat/ChatTest"
+import type * as ChatThread from "effect/chat/ChatThread"
+import * as Effect from "effect/Effect"
+import * as FetchHttpClient from "effect/http/FetchHttpClient"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+import * as Result from "effect/Result"
+import * as Semaphore from "effect/Semaphore"
+
+const botToken = process.env.DISCORD_LIVE_BOT_TOKEN
+const secondToken = process.env.DISCORD_LIVE_SECOND_BOT_TOKEN
+const webhookUrl = process.env.DISCORD_LIVE_WEBHOOK_URL
+const channel = process.env.DISCORD_LIVE_CHANNEL
+
+const restLayer = (token: string) =>
+  DiscordRESTMemoryLive.pipe(
+    Layer.provide(DiscordConfig.layer({ token: Redacted.make(token) })),
+    Layer.provide(FetchHttpClient.layer)
+  )
+
+describe.skipIf(botToken === undefined || channel === undefined)("live conformance", () => {
+  const bot = restLayer(botToken!)
+  const layer = DiscordChat.layer.pipe(
+    Layer.provideMerge(Chat.layer),
+    Layer.provideMerge(bot),
+    Layer.provide(FetchHttpClient.layer)
+  )
+
+  /** Posts as the other identity, reads the message back as the bot and normalises it as a `MESSAGE_CREATE`. */
+  const userPosts = (thread: ChatThread.ChatThread, text: string): Effect.Effect =>
+    Effect.gen(function*() {
+      const posted: { readonly id: string } = secondToken !== undefined
+        ? yield* Effect.flatMap(
+          DiscordREST,
+          (rest) => rest.createMessage(thread.id, { content: text, allowed_mentions: { parse: [] } })
+        ).pipe(
+          Effect.provide(restLayer(secondToken))
+        )
+        : webhookUrl !== undefined
+        ? yield* Effect.tryPromise(async () => {
+          const url = new URL(webhookUrl)
+          url.searchParams.set("wait", "true")
+          const channelInfo = await fetch(`https://discord.com/api/v10/channels/${thread.id}`, {
+            headers: { authorization: `Bot ${botToken}` }
+          }).then((response) => response.json())
+          if (channelInfo.type === 11 || channelInfo.type === 10 || channelInfo.type === 12) {
+            url.searchParams.set("thread_id", thread.id)
+          }
+          const response = await fetch(url, {
+            method: "POST",
+            headers: { "content-type": "application/json" },
+            body: JSON.stringify({ content: text, allowed_mentions: { parse: [] } })
+          })
+          if (!response.ok) throw new Error(`webhook answered ${response.status}`)
+          return response.json()
+        })
+        : yield* Effect.die(new Error("neither DISCORD_LIVE_SECOND_BOT_TOKEN nor DISCORD_LIVE_WEBHOOK_URL is set"))
+      const rest = yield* DiscordREST
+      const message = yield* rest.getMessage(thread.id, posted.id)
+      const info = yield* rest.getChannel(thread.id)
+      const discord = yield* DiscordChat.DiscordChat
+      const result = DiscordChat.normalize({ t: "MESSAGE_CREATE", d: message }, {
+        botUserId: yield* discord.botUserId,
+        channelType: info.type
+      })
+      if (Result.isFailure(result) || result.success.length !== 1) {
+        return yield* Effect.die(new Error("userPosts did not normalise to one event"))
+      }
+      return result.success[0]
+    }).pipe(Effect.provide(layer), Effect.orDie)
+
+  const rules = conformance({
+    platform: "discord",
+    thread: DiscordChat.thread(channel ?? ""),
+    userPosts,
+    parseMention: DiscordChat.parseMention
+  })
+
+  // The rules share one channel and the project runs tests concurrently, so
+  // one rule at a time.
+  const one = Semaphore.makeUnsafe(1)
+  for (const [name, rule] of Object.entries(rules)) {
+    it.live(name, () => rule.pipe(Effect.provide(layer), Semaphore.withPermits(one, 1)), 600_000)
+  }
+})
diff --git a/packages/chat/discord/test/normalize.test.ts b/packages/chat/discord/test/normalize.test.ts
new file mode 100644
index 00000000000..6d370279a8e
--- /dev/null
+++ b/packages/chat/discord/test/normalize.test.ts
@@ -0,0 +1,422 @@
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { tokens } from "@effect/chat-discord/internal/mentions"
+import { decodeMessageFields, message, messageTypes } from "@effect/chat-discord/internal/normalize"
+import { assert, describe, it } from "@effect/vitest"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { dedupeKey } from "effect/chat/ChatEvent"
+import { checkEvent, checkMessage } from "effect/chat/ChatTest"
+import * as ChatThread from "effect/chat/ChatThread"
+import * as Effect from "effect/Effect"
+import * as Option from "effect/Option"
+import * as Result from "effect/Result"
+import {
+  botUserId,
+  checkOptions,
+  type Dispatch,
+  eventFixtures,
+  events,
+  forum,
+  guild,
+  recorded,
+  role,
+  scratch,
+  step,
+  test,
+  tim,
+  webhook
+} from "./utils.ts"
+
+const context = { botUserId }
+
+const normalize = (dispatch: Dispatch): ReadonlyArray => {
+  const result = DiscordChat.normalize(dispatch, context)
+  assert(Result.isSuccess(result), "expected events")
+  return result.success
+}
+
+const created = (dispatch: Dispatch): ChatEvent.MessageCreated => {
+  const found = normalize(dispatch)
+  assert.strictEqual(found.length, 1)
+  const event = found[0]
+  assert(event._tag === "MessageCreated")
+  return event
+}
+
+const byContent = (name: string, prefix: string): Dispatch => {
+  const found = events(name).filter((dispatch) => String(dispatch.d.content).startsWith(prefix))
+  assert.strictEqual(found.length, 1, prefix)
+  return found[0]
+}
+
+const mentionsOf = (event: ChatEvent.MessageCreated) =>
+  event.message.mentions.map((mention) => ({
+    kind: mention.kind,
+    id: mention.id,
+    isSelf: mention.isSelf,
+    token: event.message.text.slice(mention.start, mention.end)
+  }))
+
+describe("normalize", () => {
+  it.effect("every recorded dispatch passes checkEvent", () =>
+    Effect.gen(function*() {
+      let count = 0
+      for (const name of eventFixtures()) {
+        for (const dispatch of events(name)) {
+          const result = DiscordChat.normalize(dispatch, { ...context, channelType: 0 })
+          assert(Result.isSuccess(result), name)
+          for (const event of result.success) {
+            yield* checkEvent(event, checkOptions)
+            count++
+          }
+        }
+      }
+      assert.isAbove(count, 35)
+    }))
+
+  it("a MESSAGE_CREATE with channel_type gives a channel message", () => {
+    const event = created(events("channel-message")[0])
+    assert.strictEqual(event.kind, "channel")
+    assert.deepStrictEqual(event.thread, DiscordChat.thread(scratch))
+    assert.deepStrictEqual(event.thread, event.message.thread)
+    assert.strictEqual(event.message.text, "Fixture: a plain message in a guild text channel")
+    assert.isTrue(event.message.author.isSelf)
+    assert.isTrue(event.message.author.isBot)
+    assert.deepStrictEqual(event.raw, events("channel-message")[0].d)
+    assert.strictEqual(event.message.raw, event.raw)
+  })
+
+  it("a MESSAGE_CREATE without channel_type fails MissingChannelType, then takes it from the context", () => {
+    const dispatch = events("channel-message-without-channel-type")[0]
+    assert.isUndefined(dispatch.d.channel_type)
+    const missing = DiscordChat.normalize(dispatch, context)
+    assert(Result.isFailure(missing))
+    assert.instanceOf(missing.failure, DiscordChat.MissingChannelType)
+    assert.strictEqual(missing.failure.channelId, scratch)
+    for (
+      const [channelType, kind] of [[0, "channel"], [11, "thread"], [1, "direct"], [15, "channel"], [
+        99,
+        "channel"
+      ]] as const
+    ) {
+      const result = DiscordChat.normalize(dispatch, { ...context, channelType })
+      assert(Result.isSuccess(result))
+      const event = result.success[0]
+      assert(event._tag === "MessageCreated")
+      assert.strictEqual(event.kind, kind)
+    }
+    // The payload's own type wins over the context.
+    const withType = DiscordChat.normalize(events("channel-message")[0], { ...context, channelType: 11 })
+    assert(Result.isSuccess(withType) && withType.success[0]._tag === "MessageCreated")
+    assert.strictEqual(withType.success[0].kind, "channel")
+  })
+
+  it("a reaction needs no channel type", () => {
+    for (const dispatch of events("reactions")) {
+      const result = DiscordChat.normalize(dispatch, context)
+      assert(Result.isSuccess(result))
+      assert.strictEqual(result.success.length, 1)
+    }
+  })
+
+  it("a message in a thread is addressed to the thread", () => {
+    for (const dispatch of events("thread-messages")) {
+      const event = created(dispatch)
+      assert.strictEqual(event.kind, "thread")
+      assert.deepStrictEqual(event.thread, DiscordChat.thread(dispatch.d.channel_id))
+      assert.notStrictEqual(dispatch.d.channel_id, scratch)
+    }
+  })
+
+  it("a forum post's starter is addressed to the post, whose id it shares", () => {
+    const [starter, reply] = events("forum").map(created)
+    assert.strictEqual(starter.kind, "thread")
+    assert.strictEqual(starter.message.id, starter.thread.id)
+    assert.deepStrictEqual(reply.thread, starter.thread)
+    assert.strictEqual(DiscordChat.guildId(starter).pipe(Option.getOrThrow), guild)
+  })
+
+  it("THREAD_STARTER_MESSAGE and THREAD_CREATED give no event", () => {
+    const dispatches = events("thread-started")
+    assert.deepStrictEqual(dispatches.map((dispatch) => dispatch.d.type).sort(), [18, 21, 21])
+    for (const dispatch of dispatches) assert.deepStrictEqual(normalize(dispatch), [])
+  })
+
+  it("only DEFAULT, REPLY, CHAT_INPUT_COMMAND and CONTEXT_MENU_COMMAND are messages", () => {
+    assert.deepStrictEqual([...messageTypes].sort((a, b) => a - b), [0, 19, 20, 23])
+    const base = events("channel-message")[0]
+    for (const type of [1, 6, 7, 8, 18, 21, 24, 46, 99]) {
+      assert.deepStrictEqual(normalize({ t: base.t, d: { ...base.d, type } }), [], String(type))
+    }
+  })
+
+  it("a webhook message has the webhook as its author", () => {
+    const event = created(events("webhook-message")[0])
+    assert.strictEqual(event.message.author.id, webhook)
+    assert.strictEqual(event.message.author.name, "effect-chat-fixtures")
+    assert.isTrue(event.message.author.isBot)
+    assert.isFalse(event.message.author.isSelf)
+    assert.isTrue(Option.isNone(DiscordChat.member(event)))
+    assert.strictEqual(Option.getOrThrow(DiscordChat.guildId(event)), guild)
+  })
+
+  it("a person's reply is a reply, not a mention, with the ping on or off", () => {
+    const [pingOn, pingOff] = events("reply-ping").filter((dispatch) => dispatch.d.author.id === tim)
+    // Discord lists the replied-to bot in mentions when the ping is on, with no token in content.
+    assert.deepStrictEqual(pingOn.d.mentions.map((user: any) => user.id), [botUserId])
+    assert.deepStrictEqual(pingOff.d.mentions, [])
+    for (const dispatch of [pingOn, pingOff]) {
+      const event = created(dispatch)
+      assert.deepStrictEqual(event.message.mentions, [])
+      assert.deepStrictEqual(event.message.replyTo, {
+        messageId: dispatch.d.message_reference.message_id,
+        authorId: botUserId
+      })
+      assert.isFalse(event.message.author.isBot)
+      assert.isFalse(event.message.author.isSelf)
+      assert.strictEqual(event.message.author.id, tim)
+      assert.deepStrictEqual(event.thread, DiscordChat.thread(test))
+      const member = Option.getOrThrow(DiscordChat.member(event))
+      assert.strictEqual(member.guildId, guild)
+      assert.deepStrictEqual(member.roles, dispatch.d.member.roles)
+    }
+  })
+
+  it("the bot's own replies, ping on or off, carry replyTo and no mention", () => {
+    for (const prefix of ["Fixture: a reply with the ping on", "Fixture: a reply with the ping off"]) {
+      const event = created(byContent("reply-ping", prefix))
+      assert.deepStrictEqual(event.message.mentions, [])
+      assert.strictEqual(event.message.replyTo?.authorId, botUserId)
+    }
+  })
+
+  it("an attachment has an id that names its message, and no URL", () => {
+    const event = created(events("attachment")[0])
+    assert.deepStrictEqual(event.message.attachments, [{
+      id: `${event.message.id}/${events("attachment")[0].d.attachments[0].id}`,
+      name: "fixture.txt",
+      contentType: "text/plain; charset=utf-8",
+      size: 23
+    }])
+  })
+
+  describe("mentions", () => {
+    const cases: ReadonlyArray<
+      readonly [string, ReadonlyArray<{ kind: string; id: string; isSelf: boolean; token: string }>]
+    > = [
+      ["Fixture: <@1564742987727118426> as a plain", [{
+        kind: "user",
+        id: botUserId,
+        isSelf: true,
+        token: `<@${botUserId}>`
+      }]],
+      ["Fixture: <@!", [{ kind: "user", id: botUserId, isSelf: true, token: `<@!${botUserId}>` }]],
+      [`Fixture: <@${tim}>`, [{ kind: "user", id: tim, isSelf: false, token: `<@${tim}>` }]],
+      ["Fixture: <@&", [{ kind: "role", id: role, isSelf: false, token: `<@&${role}>` }]],
+      ["Fixture: @everyone that", [{ kind: "broadcast", id: "everyone", isSelf: false, token: "@everyone" }]],
+      ["Fixture: @here", [{ kind: "broadcast", id: "here", isSelf: false, token: "@here" }]],
+      ["Fixture: @everyone with parse", []],
+      ["Fixture: <#", [{ kind: "channel", id: test, isSelf: false, token: `<#${test}>` }]],
+      ["Fixture: `<@", []],
+      ["Fixture: in a fence", []],
+      ["Fixture: the bot naming", []],
+      ["Fixture: <@1564742987727118426> and", [
+        { kind: "user", id: botUserId, isSelf: true, token: `<@${botUserId}>` },
+        { kind: "role", id: role, isSelf: false, token: `<@&${role}>` },
+        { kind: "channel", id: scratch, isSelf: false, token: `<#${scratch}>` }
+      ]]
+    ]
+    for (const [prefix, expected] of cases) {
+      it.effect(prefix, () =>
+        Effect.gen(function*() {
+          const event = created(byContent("mentions", prefix))
+          assert.deepStrictEqual(mentionsOf(event), expected)
+          yield* checkMessage(event.message, checkOptions)
+        }))
+    }
+
+    it("tokens skips code and escapes as Discord's Markdown does", () => {
+      const ids = (text: string) => tokens(text).map((token) => token.id)
+      assert.deepStrictEqual(ids("<@1> `<@2>` ``<@3>`` ```\n<@4>\n``` <@5>"), ["1", "5"])
+      assert.deepStrictEqual(ids("\\<@1> <@2>"), ["2"])
+      assert.deepStrictEqual(ids("`unclosed <@1>"), ["1"])
+      assert.deepStrictEqual(ids("a``b <@1>"), ["1"])
+      assert.deepStrictEqual(ids("@everyone@here <@&3><#4>"), ["everyone", "here", "3", "4"])
+    })
+
+    it("parseMention reads one whole token", () => {
+      assert.deepStrictEqual(DiscordChat.parseMention("<@1>"), Option.some({ kind: "user" as const, id: "1" }))
+      assert.deepStrictEqual(DiscordChat.parseMention("<@!1>"), Option.some({ kind: "user" as const, id: "1" }))
+      assert.deepStrictEqual(DiscordChat.parseMention("<@&2>"), Option.some({ kind: "role" as const, id: "2" }))
+      assert.deepStrictEqual(DiscordChat.parseMention("<#3>"), Option.some({ kind: "channel" as const, id: "3" }))
+      assert.deepStrictEqual(DiscordChat.parseMention("@here"), Option.some({ kind: "broadcast" as const, id: "here" }))
+      for (const slice of ["<@1> ", " <@1>", "<@x>", "@everyone!", "<@1><@2>", ""]) {
+        assert.isTrue(Option.isNone(DiscordChat.parseMention(slice)), slice)
+      }
+    })
+  })
+
+  describe("reactions", () => {
+    it.effect("added and removed, in a channel and a thread", () =>
+      Effect.gen(function*() {
+        const found = events("reactions").map(normalize).map((list) => list[0])
+        assert.strictEqual(found.length, 12)
+        for (const event of found) {
+          assert(event._tag === "ReactionAdded" || event._tag === "ReactionRemoved")
+          yield* checkEvent(event, checkOptions)
+          assert.strictEqual(event.userId, botUserId)
+          assert.isUndefined(event.timestamp)
+          assert.strictEqual(Option.getOrThrow(DiscordChat.guildId(event)), guild)
+          if (event._tag === "ReactionAdded") {
+            assert.strictEqual(event.messageAuthorId, botUserId)
+            assert.isTrue(Option.isSome(DiscordChat.member(event)))
+          } else {
+            assert.isUndefined(event.messageAuthorId)
+          }
+        }
+        assert.deepStrictEqual(found.slice(0, 3).map((event) => event._tag === "ReactionAdded" ? event.emoji : ""), [
+          "\u{1F44D}",
+          "\u{1F44D}\u{1F3FD}",
+          "custom:effectchat"
+        ])
+        assert.notStrictEqual(dedupeKey(found[0]), dedupeKey(found[3]))
+        assert.deepStrictEqual(found[6].thread, DiscordChat.thread("1570608327602471024"))
+      }))
+
+    it("the custom emoji's id stays on raw", () => {
+      const event = normalize(events("reactions")[2])[0]
+      assert.strictEqual((event.raw as any).emoji.id, "1570607258226790481")
+    })
+  })
+})
+
+/**
+ * Synthetic: nobody has yet sent these for the recorder. Each one is a
+ * recorded dispatch with the fields that differ changed by hand.
+ */
+describe("synthetic", () => {
+  const person = events("reply-ping").find((dispatch) => dispatch.d.author.id === tim)!
+  const fromPerson = (d: Record): Dispatch => {
+    const { message_reference: _, referenced_message: __, ...rest } = person.d
+    return { t: "MESSAGE_CREATE", d: { ...rest, type: 0, mentions: [], ...d } }
+  }
+
+  it.effect("a person mentioning the bot in a guild channel", () =>
+    Effect.gen(function*() {
+      const event = created(fromPerson({
+        content: `<@${botUserId}> hello`,
+        mentions: [person.d.referenced_message.author]
+      }))
+      assert.deepStrictEqual(mentionsOf(event), [{
+        kind: "user",
+        id: botUserId,
+        isSelf: true,
+        token: `<@${botUserId}>`
+      }])
+      assert.isFalse(event.message.author.isBot)
+      assert.strictEqual(event.kind, "channel")
+      yield* checkEvent(event, checkOptions)
+    }))
+
+  it.effect("a DM to the bot", () =>
+    Effect.gen(function*() {
+      const { guild_id: _, member: __, ...rest } = fromPerson({ content: "hello", channel_id: "1", channel_type: 1 }).d
+      const event = created({ t: "MESSAGE_CREATE", d: rest })
+      assert.strictEqual(event.kind, "direct")
+      assert.isTrue(Option.isNone(DiscordChat.guildId(event)))
+      assert.isTrue(Option.isNone(DiscordChat.member(event)))
+      yield* checkEvent(event, checkOptions)
+    }))
+
+  it.effect("a forward comes through as DEFAULT with empty text", () =>
+    Effect.gen(function*() {
+      const snapshot = { message: { content: "forwarded", type: 0, timestamp: person.d.timestamp } }
+      const event = created(fromPerson({
+        content: "",
+        message_reference: { type: 1, channel_id: scratch, message_id: "1" },
+        message_snapshots: [snapshot]
+      }))
+      assert.strictEqual(event.message.text, "")
+      assert.isUndefined(event.message.replyTo)
+      assert.deepStrictEqual((event.raw as any).message_snapshots, [snapshot])
+      yield* checkEvent(event, checkOptions)
+    }))
+
+  it.effect("slash command replies, immediate and deferred, and a context menu reply", () =>
+    Effect.gen(function*() {
+      const recordedReply = step("other-bots", "other-bot-command-reply").response
+      const reply = (d: Record): Dispatch => ({
+        t: "MESSAGE_CREATE",
+        d: { ...recordedReply, guild_id: guild, channel_type: 0, ...d }
+      })
+      const immediate = created(reply({}))
+      assert.isTrue(immediate.message.author.isBot)
+      assert.strictEqual(immediate.message.text, recordedReply.content)
+      // Deferred: empty with the LOADING flag. The text comes in a MESSAGE_UPDATE, which is not delivered.
+      const deferred = created(reply({ content: "", flags: 128 }))
+      assert.strictEqual(deferred.message.text, "")
+      assert.deepStrictEqual(normalize({ t: "MESSAGE_UPDATE", d: { ...recordedReply, flags: 0 } }), [])
+      const contextMenu = created(reply({ type: 23 }))
+      assert.isTrue(contextMenu.message.author.isBot)
+      for (const event of [immediate, deferred, contextMenu]) yield* checkEvent(event, checkOptions)
+    }))
+})
+
+describe("REST messages", () => {
+  const read = (raw: any) => {
+    const fields = decodeMessageFields(raw)
+    assert.isDefined(fields)
+    return message(raw, fields!, context)
+  }
+
+  it.effect("every recorded message passes checkMessage", () =>
+    Effect.gen(function*() {
+      let count = 0
+      for (const name of ["posts", "history", "other-bots", "reactions", "embeds"]) {
+        for (const call of recorded(name)) {
+          if (call.status >= 300 || call.response === null) continue
+          const list = Array.isArray(call.response) ? call.response : [call.response]
+          for (const raw of list) {
+            if (typeof raw.author !== "object") continue
+            const found = read(raw)
+            if (found === undefined) continue
+            yield* checkMessage(found, checkOptions)
+            count++
+          }
+        }
+      }
+      assert.isAbove(count, 30)
+    }))
+
+  it("other bots' command replies are messages from a bot", () => {
+    for (
+      const name of ["other-bot-command-reply", "other-bot-command-reply-empty", "other-bot-command-reply-effect-bot"]
+    ) {
+      const raw = step("other-bots", name).response
+      assert.strictEqual(raw.type, 20)
+      const found = read(raw)!
+      assert.isTrue(found.author.isBot)
+      assert.isFalse(found.author.isSelf)
+      assert.isUndefined(found.replyTo)
+    }
+    // A reply with only an embed comes through with empty text.
+    assert.strictEqual(read(step("other-bots", "other-bot-command-reply-empty").response)!.text, "")
+    const reply = read(step("other-bots", "other-bot-reply").response)!
+    assert.strictEqual(reply.replyTo?.messageId, "1103552216398303272")
+  })
+
+  it("the thread starter placeholder is not a message", () => {
+    const history = step("history", "thread-history").response
+    const placeholder = history.find((raw: any) => raw.type === 21)
+    assert.isUndefined(read(placeholder))
+    // The opener it points at is addressed to the parent channel.
+    const opener = read(placeholder.referenced_message)!
+    assert.deepStrictEqual(opener.thread, ChatThread.make("discord", scratch))
+    assert.strictEqual(opener.id, step("history", "thread-start").response.id)
+  })
+
+  it("a forum's starter read through REST is addressed to the post", () => {
+    const starter = read(step("history", "forum-get-starter").response)!
+    assert.strictEqual(starter.thread.id, starter.id)
+    assert.notStrictEqual(starter.thread.id, forum)
+  })
+})
diff --git a/packages/chat/discord/test/utils.ts b/packages/chat/discord/test/utils.ts
new file mode 100644
index 00000000000..fb668e61857
--- /dev/null
+++ b/packages/chat/discord/test/utils.ts
@@ -0,0 +1,137 @@
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { DiscordREST } from "dfx/DiscordREST"
+import * as Chat from "effect/chat/Chat"
+import type { ChatAdapter } from "effect/chat/ChatAdapter"
+import { Registry } from "effect/chat/ChatAdapter"
+import * as Effect from "effect/Effect"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Layer from "effect/Layer"
+import * as fs from "node:fs"
+
+/** The Janitor application the fixtures were recorded with. */
+export const botUserId = "1564742987727118426"
+export const tim = "449108784879763458"
+export const guild = "840178841540362250"
+export const scratch = "1570607253965246584"
+export const forum = "1570607255684915302"
+export const test = "1570605581192929301"
+export const role = "1570607256838479964"
+export const webhook = "1570607260156297307"
+
+export const checkOptions = { platform: "discord", parseMention: DiscordChat.parseMention }
+
+export interface Dispatch {
+  readonly receivedAt?: string
+  readonly t: string
+  readonly d: any
+}
+
+/** The dispatches of a gateway fixture in `fixtures/events`. */
+export const events = (name: string): ReadonlyArray =>
+  JSON.parse(fs.readFileSync(new URL(`./fixtures/events/${name}.json`, import.meta.url), "utf8")).dispatches
+
+export const eventFixtures = (): ReadonlyArray =>
+  fs.readdirSync(new URL("./fixtures/events", import.meta.url)).map((file) => file.replace(/\.json$/, ""))
+
+export interface RecordedCall {
+  readonly step: string
+  readonly method: string
+  readonly path: string
+  readonly request: any
+  readonly status: number
+  readonly response: any
+}
+
+/** The REST calls of a fixture in `fixtures/recorded`. */
+export const recorded = (name: string): ReadonlyArray =>
+  JSON.parse(fs.readFileSync(new URL(`./fixtures/recorded/${name}.json`, import.meta.url), "utf8")).calls
+
+/** The one recorded call for `step`. */
+export const step = (name: string, stepName: string): RecordedCall => {
+  const found = recorded(name).filter((call) => call.step === stepName)
+  if (found.length !== 1) throw new Error(`${name}/${stepName}: ${found.length} calls`)
+  return found[0]
+}
+
+/** What dfx fails with for a 4xx answer, as the adapter reads it. */
+export const errorResponse = (status: number, data: unknown) => ({
+  _tag: status === 429 ? "RatelimitedResponse" : "ErrorResponse",
+  data,
+  response: { status },
+  message: JSON.stringify(data)
+})
+
+/** What dfx fails with for a 5xx answer. */
+export const statusCodeError = (status: number) => ({
+  _tag: "HttpClientError",
+  reason: { _tag: "StatusCodeError", response: { status } }
+})
+
+/** A recorded call as the fake's answer: its body, or dfx's error for it. */
+export const answer = (call: RecordedCall): Effect.Effect =>
+  call.status >= 400 ? Effect.fail(errorResponse(call.status, call.response)) : Effect.succeed(call.response)
+
+type Handler = (...args: Array) => Effect.Effect
+
+export interface Fake {
+  readonly calls: Array<{ readonly method: string; readonly args: ReadonlyArray; readonly files?: number }>
+  readonly called: (method: string) => ReadonlyArray>
+  readonly service: DiscordREST["Service"]
+}
+
+/**
+ * A `DiscordREST` that answers from `handlers` and records every call. A
+ * method with no handler dies, so a test sees any call it didn't expect.
+ */
+export const makeFake = (handlers: Record): Fake => {
+  const calls: Array<{ method: string; args: ReadonlyArray; files?: number }> = []
+  let files: number | undefined
+  const service = new Proxy({}, {
+    get: (_, method: string) => {
+      if (method === "withFiles") {
+        return (list: ReadonlyArray) => (effect: Effect.Effect) =>
+          Effect.suspend(() => {
+            files = list.length
+            return Effect.ensuring(effect, Effect.sync(() => (files = undefined)))
+          })
+      }
+      return (...args: Array) =>
+        Effect.suspend(() => {
+          calls.push({ method, args, ...(files === undefined ? {} : { files }) })
+          const handler = handlers[method]
+          return handler === undefined ? Effect.die(new Error(`unexpected ${method}`)) : handler(...args)
+        })
+    }
+  }) as DiscordREST["Service"]
+  return {
+    calls,
+    called: (method) => calls.filter((call) => call.method === method).map((call) => call.args),
+    service
+  }
+}
+
+const getMyUser = () => Effect.succeed({ id: botUserId, username: "Janitor", bot: true })
+
+/** `DiscordChat.layer` over a fake, with `Chat` and an `HttpClient` that answers `download`. */
+export const discordLayer = (fake: Fake, options?: { readonly download?: Uint8Array | undefined }) =>
+  DiscordChat.layer.pipe(
+    Layer.provideMerge(Chat.layer),
+    Layer.provide(Layer.succeed(
+      DiscordREST,
+      new Proxy(fake.service, {
+        get: (target, key) => key === "getMyUser" ? getMyUser : (target as any)[key]
+      })
+    )),
+    Layer.provide(Layer.succeed(
+      HttpClient.HttpClient,
+      HttpClient.make((request) =>
+        Effect.succeed(HttpClientResponse.fromWeb(request, new Response(new Uint8Array(options?.download ?? []))))
+      )
+    ))
+  )
+
+export const adapter: Effect.Effect = Effect.gen(function*() {
+  const registry = yield* Registry
+  return yield* registry.get("discord")
+})
diff --git a/packages/chat/discord/tsconfig.json b/packages/chat/discord/tsconfig.json
new file mode 100644
index 00000000000..e2a8ca19a0d
--- /dev/null
+++ b/packages/chat/discord/tsconfig.json
@@ -0,0 +1,8 @@
+{
+  "$schema": "https://json.schemastore.org/tsconfig",
+  "extends": "../../../tsconfig.base.json",
+  "include": ["src"],
+  "references": [
+    { "path": "../../effect" }
+  ]
+}
diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index 557d50d3eba..4111f0b326c 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -57,10 +57,6 @@ import * as ChatThread from "./ChatThread.ts"
  * The core does not know any platform's syntax, so the caller supplies it. A
  * slice that is not a mention token returns `None`.
  *
- * **Gotchas**
- *
- * The name is provisional.
- *
  * @stability unstable
  * @category models
  * @since 4.1.5
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 5ba69df20fb..da401cb2a26 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -348,6 +348,15 @@ importers:
         specifier: ^3.5.45
         version: 3.5.45(typescript@7.0.2)
 
+  packages/chat/discord:
+    devDependencies:
+      dfx:
+        specifier: ^1.1.1
+        version: 1.1.1(effect@packages+effect)
+      effect:
+        specifier: workspace:^
+        version: link:../../effect
+
   packages/chat/slack:
     devDependencies:
       effect:
@@ -4151,12 +4160,18 @@ packages:
   '@types/babel__traverse@7.28.0':
     resolution: {integrity: sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q==}
 
+  '@types/body-parser@1.19.6':
+    resolution: {integrity: sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==}
+
   '@types/bun@1.4.4':
     resolution: {integrity: sha512-9wkRDXUXK124pEnAutE6n/l18j+i9GC5IAHK8TmX/2nlySETmky0OU6yL5U8pW1AoKh++AN9auDCr647BfurjQ==}
 
   '@types/chai@5.2.3':
     resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==}
 
+  '@types/connect@3.4.38':
+    resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==}
+
   '@types/deep-eql@4.0.2':
     resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==}
 
@@ -4175,12 +4190,21 @@ packages:
   '@types/estree@1.0.10':
     resolution: {integrity: sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==}
 
+  '@types/express-serve-static-core@4.19.9':
+    resolution: {integrity: sha512-QP2ESEe/ImWY0HDwNAnK9PvEffUyhLTnWkk7KXzHfyeWAnlrDe1fN77bXl6ia8KT3wPlmA7t9/VPRpnf4Ex9sg==}
+
+  '@types/express@4.17.25':
+    resolution: {integrity: sha512-dVd04UKsfpINUnK0yBoYHDF3xu7xVH4BuDotC/xGuycx4CgbP48X/KF/586bcObxT0HENHXEU8Nqtu6NR+eKhw==}
+
   '@types/gensync@1.0.5':
     resolution: {integrity: sha512-MbsRCT7mTikHwKZ0X+LVUTLRrZZRLipTuXEO9qOYO+zmjMVk81axyClMROf6uoPD9MRVu46bx8zoR0Ad9q3NAg==}
 
   '@types/graceful-fs@4.1.9':
     resolution: {integrity: sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ==}
 
+  '@types/http-errors@2.0.5':
+    resolution: {integrity: sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==}
+
   '@types/istanbul-lib-coverage@2.0.6':
     resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==}
 
@@ -4196,12 +4220,21 @@ packages:
   '@types/jsesc@2.5.1':
     resolution: {integrity: sha512-9VN+6yxLOPLOav+7PwjZbxiID2bVaeq0ED4qSQmdQTdjnXJSaCVKTR58t15oqH1H5t8Ng2ZX1SabJVoN9Q34bw==}
 
+  '@types/mime@1.3.5':
+    resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
+
   '@types/node@26.6.6':
     resolution: {integrity: sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==}
 
   '@types/nodemailer@8.0.2':
     resolution: {integrity: sha512-c7M5ox8p0nEOfbJ2E9Qcmt8/QCu/VzsiAhzBiZbvky2PhKZDHpKB3sQHBM5MEZNkCfBOaS6S9//AGPRTNB7IaA==}
 
+  '@types/qs@6.15.1':
+    resolution: {integrity: sha512-GZHUBZR9hckSUhrxmp1nG6NwdpM9fCunJwyThLW1X3AyHgd9IlHb6VANpQQqDr2o/qQp6McZ3y/IA2rVzKzSbw==}
+
+  '@types/range-parser@1.2.7':
+    resolution: {integrity: sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==}
+
   '@types/react-dom@19.3.0':
     resolution: {integrity: sha512-ZI7bU42mZXXKHn/qNLEw2IrbiINU7X5+vfgdixBHkCNpYWXjKgfQ/P+uyGb5CjOLB9UcnTeg3rylQtV2hym44Q==}
     peerDependencies:
@@ -4222,6 +4255,15 @@ packages:
   '@types/semver@7.8.0':
     resolution: {integrity: sha512-1mAINjtQCXXeLkJ9ehXkwOcBpqtLxiVtKhpUf83DdRNdQKV0iXZpaHYqRr7nj+wvxuJzoAmAwXI+sCNMv1CzLQ==}
 
+  '@types/send@0.17.6':
+    resolution: {integrity: sha512-Uqt8rPBE8SY0RK8JB1EzVOIZ32uqy8HwdxCnoCOsYrvnswqmFZ/k+9Ikidlk/ImhsdvBsloHbAlewb2IEBV/Og==}
+
+  '@types/send@1.2.1':
+    resolution: {integrity: sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==}
+
+  '@types/serve-static@1.15.10':
+    resolution: {integrity: sha512-tRs1dB+g8Itk72rlSI2ZrW6vZg0YrLI81iQSTkMmOqnqCaNr/8Ek4VwWcN5vZgCYWbg/JJSGBlUaYGAOP73qBw==}
+
   '@types/ssh2-streams@0.1.13':
     resolution: {integrity: sha512-faHyY3brO9oLEA0QlcO8N2wT7R0+1sHWZvQ+y3rMLwdY1ZyS1z0W3t65j9PqT4HmQ6ALzNe7RZlNuCNE0wBSWA==}
 
@@ -5081,10 +5123,22 @@ packages:
     peerDependencies:
       typescript: ^5.4.4 || ^6.0.2
 
+  dfx@1.1.1:
+    resolution: {integrity: sha512-g22vKD6+WtOX6a6PoUjZoryJGp3Ut//ve6jjvEFQ8ONB0zNRkDGdf4IVitNmzZcW8G9Ewsr1FR47A98UWWbmIA==}
+    peerDependencies:
+      effect: ^4.0.0
+
   diacritics-map@0.1.0:
     resolution: {integrity: sha512-3omnDTYrGigU0i4cJjvaKwD52B8aoqyX/NEIkukFFkogBemsIbhSa1O414fpTp5nuszJG6lvQ5vBvDVNCbSsaQ==}
     engines: {node: '>=0.8.0'}
 
+  discord-api-types@0.38.58:
+    resolution: {integrity: sha512-6utghVho47hBzmx8nIp+pKEDDNIlVk6On/J5Y1Q529payNLZjBsrw+mt+G5Y3NYRE3kgta6eBx5hRYVyfHGdOA==}
+
+  discord-verify@1.2.0:
+    resolution: {integrity: sha512-8qlrMROW8DhpzWWzgNq9kpeLDxKanWa4EDVoj/ASVv2nr+dSr4JPmu2tFSydf3hAGI/OIJTnZyD0JulMYIxx4w==}
+    engines: {node: '>=16'}
+
   docker-compose@1.5.0:
     resolution: {integrity: sha512-O+eD6c63+BJORUWddXA7uAlI6H1KLDPd/aS14k73nXYpFliM48C3xrrKB3sXsR1Fp/rHUZQe7+fJ+QA7+jepyw==}
     engines: {node: '>= 6.0.0'}
@@ -10330,6 +10384,12 @@ snapshots:
     dependencies:
       '@babel/types': 7.29.11
 
+  '@types/body-parser@1.19.6':
+    dependencies:
+      '@types/connect': 3.4.38
+      '@types/node': 26.6.6
+    optional: true
+
   '@types/bun@1.4.4':
     dependencies:
       bun-types: 1.4.4
@@ -10339,6 +10399,11 @@ snapshots:
       '@types/deep-eql': 4.0.2
       assertion-error: 2.0.1
 
+  '@types/connect@3.4.38':
+    dependencies:
+      '@types/node': 26.6.6
+    optional: true
+
   '@types/deep-eql@4.0.2': {}
 
   '@types/deno@2.7.0': {}
@@ -10358,12 +10423,31 @@ snapshots:
 
   '@types/estree@1.0.10': {}
 
+  '@types/express-serve-static-core@4.19.9':
+    dependencies:
+      '@types/node': 26.6.6
+      '@types/qs': 6.15.1
+      '@types/range-parser': 1.2.7
+      '@types/send': 1.2.1
+    optional: true
+
+  '@types/express@4.17.25':
+    dependencies:
+      '@types/body-parser': 1.19.6
+      '@types/express-serve-static-core': 4.19.9
+      '@types/qs': 6.15.1
+      '@types/serve-static': 1.15.10
+    optional: true
+
   '@types/gensync@1.0.5': {}
 
   '@types/graceful-fs@4.1.9':
     dependencies:
       '@types/node': 26.6.6
 
+  '@types/http-errors@2.0.5':
+    optional: true
+
   '@types/istanbul-lib-coverage@2.0.6': {}
 
   '@types/istanbul-lib-report@3.0.3':
@@ -10381,6 +10465,9 @@ snapshots:
 
   '@types/jsesc@2.5.1': {}
 
+  '@types/mime@1.3.5':
+    optional: true
+
   '@types/node@26.6.6':
     dependencies:
       undici-types: 8.9.0
@@ -10389,6 +10476,12 @@ snapshots:
     dependencies:
       '@types/node': 26.6.6
 
+  '@types/qs@6.15.1':
+    optional: true
+
+  '@types/range-parser@1.2.7':
+    optional: true
+
   '@types/react-dom@19.3.0(@types/react@19.3.0)':
     dependencies:
       '@types/react': 19.3.0
@@ -10407,6 +10500,24 @@ snapshots:
 
   '@types/semver@7.8.0': {}
 
+  '@types/send@0.17.6':
+    dependencies:
+      '@types/mime': 1.3.5
+      '@types/node': 26.6.6
+    optional: true
+
+  '@types/send@1.2.1':
+    dependencies:
+      '@types/node': 26.6.6
+    optional: true
+
+  '@types/serve-static@1.15.10':
+    dependencies:
+      '@types/http-errors': 2.0.5
+      '@types/node': 26.6.6
+      '@types/send': 0.17.6
+    optional: true
+
   '@types/ssh2-streams@0.1.13':
     dependencies:
       '@types/node': 26.6.6
@@ -11250,8 +11361,22 @@ snapshots:
     transitivePeerDependencies:
       - supports-color
 
+  dfx@1.1.1(effect@packages+effect):
+    dependencies:
+      discord-api-types: 0.38.58
+      effect: link:packages/effect
+    optionalDependencies:
+      discord-verify: 1.2.0
+
   diacritics-map@0.1.0: {}
 
+  discord-api-types@0.38.58: {}
+
+  discord-verify@1.2.0:
+    dependencies:
+      '@types/express': 4.17.25
+    optional: true
+
   docker-compose@1.5.0:
     dependencies:
       yaml: 2.9.1
diff --git a/tsconfig.packages.json b/tsconfig.packages.json
index 787dd90fd5f..6dd4da5a344 100644
--- a/tsconfig.packages.json
+++ b/tsconfig.packages.json
@@ -14,6 +14,7 @@
     { "path": "packages/ai/openrouter" },
     { "path": "packages/atom/react" },
     { "path": "packages/chat/slack" },
+    { "path": "packages/chat/discord" },
     { "path": "packages/atom/vue" },
     { "path": "packages/atom/solid" },
     { "path": "packages/opentelemetry" },
diff --git a/tsconfig.tests.json b/tsconfig.tests.json
index 17445c56e52..a9b0370f634 100644
--- a/tsconfig.tests.json
+++ b/tsconfig.tests.json
@@ -56,6 +56,8 @@
       "@effect/ai-openrouter/*": ["./packages/ai/openrouter/src/*.ts"],
       "@effect/chat-slack": ["./packages/chat/slack/src/index.ts"],
       "@effect/chat-slack/*": ["./packages/chat/slack/src/*.ts"],
+      "@effect/chat-discord": ["./packages/chat/discord/src/index.ts"],
+      "@effect/chat-discord/*": ["./packages/chat/discord/src/*.ts"],
       "@effect/atom-react": ["./packages/atom/react/src/index.ts"],
       "@effect/atom-react/*": ["./packages/atom/react/src/*.ts"],
       "@effect/atom-vue": ["./packages/atom/vue/src/index.ts"],
diff --git a/vitest.config.ts b/vitest.config.ts
index 150dfea01b6..ea9ddaf7b37 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -134,6 +134,11 @@ export default defineConfig({
       ...project("@effect/ai-openai-compat", "packages/ai/openai-compat"),
       ...project("@effect/ai-openrouter", "packages/ai/openrouter"),
       ...project("@effect/chat-slack", "packages/chat/slack"),
+      // dfx imports `effect`, which has to be the same instance as the tests'
+      // for things like `Redacted` to work, so vite resolves it too.
+      ...project("@effect/chat-discord", "packages/chat/discord", true, {
+        test: { server: { deps: { inline: ["dfx"] } } }
+      }),
       ...project("@effect/atom-react", "packages/atom/react", true, {
         test: {
           environment: "jsdom",

From 15d5d5abd5cd42ede270a80799050818c80a54cf Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 01:56:57 +0000
Subject: [PATCH 17/89] chat-discord: record Tim's typed mention and DM to the
 bot

Item 11 of the fixture list, read back through REST: the gateway
recorder had stopped before they were sent.
---
 .../chat/discord/test/DiscordChat.test.ts     |  21 +++
 .../discord/test/fixtures/recorded/human.json | 168 ++++++++++++++++++
 packages/chat/discord/test/normalize.test.ts  |  80 +++++++--
 3 files changed, 250 insertions(+), 19 deletions(-)
 create mode 100644 packages/chat/discord/test/fixtures/recorded/human.json

diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index a913c759166..f9d7210c81b 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -636,6 +636,27 @@ describe("dispatch", () => {
     )
   })
 
+  it.effect("delivers Tim's recorded mention after looking the channel up", () => {
+    // Derived dispatch: a REST body, which carries no channel_type.
+    const raw = step("human", "human-mention-get-message").response
+    const fake = makeFake({ getChannel: () => answer(step("human", "human-mention-get-channel")) })
+    const { provide, seen } = collect()
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* DiscordChat.DiscordChat
+        yield* provide(discord.dispatch({ t: "MESSAGE_CREATE", d: raw }))
+        assert.strictEqual(seen.length, 1)
+        const event = seen[0]
+        assert(event._tag === "MessageCreated")
+        assert.strictEqual(event.kind, "channel")
+        assert.isFalse(event.message.author.isBot)
+        assert.deepStrictEqual(event.message.mentions.map((mention) => mention.id), [botUserId])
+        assert.deepStrictEqual(fake.called("getChannel"), [[raw.channel_id]])
+      })
+    )
+  })
+
   it.effect("passes the handler's NotAccepted on", () => {
     const fake = makeFake({})
     return run(
diff --git a/packages/chat/discord/test/fixtures/recorded/human.json b/packages/chat/discord/test/fixtures/recorded/human.json
new file mode 100644
index 00000000000..7469223071a
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/human.json
@@ -0,0 +1,168 @@
+{
+  "case": "Item 11: a message Tim Smart typed in #test mentioning the bot, and a DM he sent the bot, each with its channel. Read back through REST because the gateway recorder had stopped before he sent them, so these are REST message objects: no guild_id, member or channel_type, which only gateway deliveries carry",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script; not gateway dispatches",
+    "where": "guild 840178841540362250 (Tim's test guild), #test 1570605581192929301, and the DM channel between Tim (449108784879763458) and the bot",
+    "author": "Tim Smart (449108784879763458), typing in the Discord client",
+    "sentAt": "2026-11-13T01:53Z",
+    "recordedAt": "2026-11-13T01:54Z, during EFF-3695",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed (none here)"
+  },
+  "calls": [
+    {
+      "step": "human-mention-get-message",
+      "method": "GET",
+      "path": "/channels/1570605581192929301/messages/1570617458174337055",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "<@1564742987727118426> hello",
+        "mentions": [
+          {
+            "id": "1564742987727118426",
+            "username": "Janitor",
+            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+            "discriminator": "5426",
+            "public_flags": 0,
+            "flags": 0,
+            "bot": true,
+            "banner": null,
+            "accent_color": null,
+            "global_name": null,
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:53:02.690000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570617458174337055",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "449108784879763458",
+          "username": "timsmart",
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+          "discriminator": "0",
+          "public_flags": 0,
+          "flags": 0,
+          "banner": null,
+          "accent_color": null,
+          "global_name": "Tim Smart",
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "human-mention-get-channel",
+      "method": "GET",
+      "path": "/channels/1570605581192929301",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1570605581192929301",
+        "type": 0,
+        "last_message_id": "1570617458174337055",
+        "flags": 0,
+        "guild_id": "840178841540362250",
+        "name": "test",
+        "parent_id": "840178841540362251",
+        "rate_limit_per_user": 0,
+        "topic": null,
+        "position": 6,
+        "permission_overwrites": [],
+        "nsfw": false
+      }
+    },
+    {
+      "step": "human-dm-get-message",
+      "method": "GET",
+      "path": "/channels/1570608637783572490/messages/1570617528227598377",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "hello DM",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T01:53:19.392000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570617528227598377",
+        "channel_id": "1570608637783572490",
+        "author": {
+          "id": "449108784879763458",
+          "username": "timsmart",
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+          "discriminator": "0",
+          "public_flags": 0,
+          "flags": 0,
+          "banner": null,
+          "accent_color": null,
+          "global_name": "Tim Smart",
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "human-dm-get-channel",
+      "method": "GET",
+      "path": "/channels/1570608637783572490",
+      "request": null,
+      "status": 200,
+      "response": {
+        "id": "1570608637783572490",
+        "type": 1,
+        "last_message_id": "1570617530232610907",
+        "flags": 0,
+        "recipients": [
+          {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        ]
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/normalize.test.ts b/packages/chat/discord/test/normalize.test.ts
index 6d370279a8e..e295346137b 100644
--- a/packages/chat/discord/test/normalize.test.ts
+++ b/packages/chat/discord/test/normalize.test.ts
@@ -290,42 +290,84 @@ describe("normalize", () => {
 })
 
 /**
- * Synthetic: nobody has yet sent these for the recorder. Each one is a
- * recorded dispatch with the fields that differ changed by hand.
+ * Item 11, recorded: Tim typed both in the Discord client. The gateway recorder
+ * had stopped by then, so the bodies are REST reads, which carry no
+ * `guild_id`, `member` or `channel_type`. The REST tests read them as history
+ * does. The dispatch tests wrap a body as a `MESSAGE_CREATE` with the
+ * channel's recorded type in the context, which makes those dispatches derived.
  */
-describe("synthetic", () => {
-  const person = events("reply-ping").find((dispatch) => dispatch.d.author.id === tim)!
-  const fromPerson = (d: Record): Dispatch => {
-    const { message_reference: _, referenced_message: __, ...rest } = person.d
-    return { t: "MESSAGE_CREATE", d: { ...rest, type: 0, mentions: [], ...d } }
+describe("a person's messages, recorded through REST", () => {
+  const read = (raw: any) => {
+    const fields = decodeMessageFields(raw)
+    assert.isDefined(fields)
+    return message(raw, fields!, context)!
   }
+  const mention = step("human", "human-mention-get-message").response
+  const dm = step("human", "human-dm-get-message").response
+  const derived = (raw: any): Dispatch => ({ t: "MESSAGE_CREATE", d: raw })
 
-  it.effect("a person mentioning the bot in a guild channel", () =>
+  it.effect("a typed mention of the bot in a guild channel", () =>
     Effect.gen(function*() {
-      const event = created(fromPerson({
-        content: `<@${botUserId}> hello`,
-        mentions: [person.d.referenced_message.author]
-      }))
-      assert.deepStrictEqual(mentionsOf(event), [{
+      assert.strictEqual(mention.content, `<@${botUserId}> hello`)
+      assert.deepStrictEqual(mention.mentions.map((user: any) => user.id), [botUserId])
+      const found = read(mention)
+      assert.strictEqual(found.author.id, tim)
+      assert.isFalse(found.author.isBot)
+      assert.isFalse(found.author.isSelf)
+      assert.deepStrictEqual(found.thread, DiscordChat.thread(test))
+      assert.deepStrictEqual(found.mentions, [{
         kind: "user",
         id: botUserId,
-        isSelf: true,
-        token: `<@${botUserId}>`
+        start: 0,
+        end: botUserId.length + 3,
+        isSelf: true
       }])
-      assert.isFalse(event.message.author.isBot)
+      yield* checkMessage(found, checkOptions)
+      // Derived dispatch: the REST body alone has no channel type.
+      assert(Result.isFailure(DiscordChat.normalize(derived(mention), context)))
+      const channelType = step("human", "human-mention-get-channel").response.type
+      assert.strictEqual(channelType, 0)
+      const result = DiscordChat.normalize(derived(mention), { ...context, channelType })
+      assert(Result.isSuccess(result))
+      const event = result.success[0]
+      assert(event._tag === "MessageCreated")
       assert.strictEqual(event.kind, "channel")
+      assert.deepStrictEqual(event.message.mentions, found.mentions)
       yield* checkEvent(event, checkOptions)
     }))
 
   it.effect("a DM to the bot", () =>
     Effect.gen(function*() {
-      const { guild_id: _, member: __, ...rest } = fromPerson({ content: "hello", channel_id: "1", channel_type: 1 }).d
-      const event = created({ t: "MESSAGE_CREATE", d: rest })
+      assert.strictEqual(dm.content, "hello DM")
+      const found = read(dm)
+      assert.strictEqual(found.author.id, tim)
+      assert.isFalse(found.author.isBot)
+      assert.isFalse(found.author.isSelf)
+      assert.deepStrictEqual(found.mentions, [])
+      yield* checkMessage(found, checkOptions)
+      const channelType = step("human", "human-dm-get-channel").response.type
+      assert.strictEqual(channelType, 1)
+      const result = DiscordChat.normalize(derived(dm), { ...context, channelType })
+      assert(Result.isSuccess(result))
+      const event = result.success[0]
+      assert(event._tag === "MessageCreated")
       assert.strictEqual(event.kind, "direct")
       assert.isTrue(Option.isNone(DiscordChat.guildId(event)))
       assert.isTrue(Option.isNone(DiscordChat.member(event)))
       yield* checkEvent(event, checkOptions)
     }))
+})
+
+/**
+ * Synthetic: nobody has yet sent these for the recorder. Each one is a
+ * recorded dispatch with the fields that differ changed by hand.
+ */
+describe("synthetic", () => {
+  const person = events("reply-ping").find((dispatch) => dispatch.d.author.id === tim)!
+  const fromPerson = (d: Record): Dispatch => {
+    const { message_reference: _, referenced_message: __, ...rest } = person.d
+    return { t: "MESSAGE_CREATE", d: { ...rest, type: 0, mentions: [], ...d } }
+  }
 
   it.effect("a forward comes through as DEFAULT with empty text", () =>
     Effect.gen(function*() {
@@ -371,7 +413,7 @@ describe("REST messages", () => {
   it.effect("every recorded message passes checkMessage", () =>
     Effect.gen(function*() {
       let count = 0
-      for (const name of ["posts", "history", "other-bots", "reactions", "embeds"]) {
+      for (const name of ["posts", "history", "other-bots", "reactions", "embeds", "human"]) {
         for (const call of recorded(name)) {
           if (call.status >= 300 || call.response === null) continue
           const list = Array.isArray(call.response) ? call.response : [call.response]

From 242597b1bdf2b93ba0fb073c568d3b545f3dd251 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 02:08:11 +0000
Subject: [PATCH 18/89] chat-discord: skip an unreadable opener and reject
 invalid timestamps

An opener the bot may not read (Forbidden) is treated like a deleted one:
history starts at the first reply and opener is None. A message whose
timestamp doesn't parse fails decoding instead of throwing from normalize,
and an unparseable timestamp in a post answer or thread metadata no
longer throws.
---
 packages/chat/discord/src/internal/adapter.ts | 18 ++++--
 .../chat/discord/src/internal/normalize.ts    |  4 +-
 .../chat/discord/test/DiscordChat.test.ts     | 61 +++++++++++++++++++
 packages/chat/discord/test/normalize.test.ts  |  6 ++
 4 files changed, 83 insertions(+), 6 deletions(-)

diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index d8c61c6fbd0..4c785162e6a 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -158,10 +158,14 @@ export const make = Effect.fnUntraced(function*(options: {
     return message === undefined ? yield* fail(op, Errors.notFound("not_a_message")) : message
   })
 
+  /** An optional read: none when the message is gone or the bot may not read it. */
   const orNone = (effect: Effect.Effect): Effect.Effect, ChatError> =>
     effect.pipe(
       Effect.map(Option.some),
-      Effect.catchIf((error) => error.reason._tag === "NotFound", () => Effect.succeed(Option.none()))
+      Effect.catchIf(
+        (error) => error.reason._tag === "NotFound" || error.reason._tag === "Forbidden",
+        () => Effect.succeed(Option.none())
+      )
     )
 
   // Writes
@@ -192,7 +196,9 @@ export const make = Effect.fnUntraced(function*(options: {
     if (typeof answer.id !== "string" || typeof answer.timestamp !== "string") {
       return yield* fail(op, Errors.invalidResponse(true, "missing_id"))
     }
-    return { id: answer.id, thread, timestamp: DateTime.makeUnsafe(answer.timestamp) } satisfies Posted
+    const timestamp = DateTime.make(answer.timestamp)
+    if (Option.isNone(timestamp)) return yield* fail(op, Errors.invalidResponse(true, "invalid_timestamp"))
+    return { id: answer.id, thread, timestamp: DateTime.toUtc(timestamp.value) } satisfies Posted
   })
 
   const edit: ChatAdapter["edit"] = Effect.fnUntraced(function*(thread, messageId, content) {
@@ -338,8 +344,12 @@ export const make = Effect.fnUntraced(function*(options: {
     const name = kind === "direct" ? undefined : nonEmpty(found.name)
     const topic = nonEmpty(found.topic)
     const parent = kind === "thread" ? nonEmpty(found.parent_id) : undefined
-    const created = nonEmpty(found.thread_metadata?.create_timestamp)
-    const createdAt = created === undefined ? Normalize.snowflakeTime(found.id) : DateTime.makeUnsafe(created)
+    // An unreadable creation time falls back to the id's.
+    const created = Option.flatMap(
+      Option.fromUndefinedOr(nonEmpty(found.thread_metadata?.create_timestamp)),
+      DateTime.make
+    )
+    const createdAt = Option.isSome(created) ? DateTime.toUtc(created.value) : Normalize.snowflakeTime(found.id)
     return {
       thread,
       kind,
diff --git a/packages/chat/discord/src/internal/normalize.ts b/packages/chat/discord/src/internal/normalize.ts
index f8d9882bcbe..d001d9118a8 100644
--- a/packages/chat/discord/src/internal/normalize.ts
+++ b/packages/chat/discord/src/internal/normalize.ts
@@ -84,7 +84,7 @@ export const MessageFields = Schema.Struct({
   channel_id: Schema.String,
   type: Schema.Number,
   content: optional(Schema.String),
-  timestamp: Schema.String,
+  timestamp: Schema.DateTimeUtcFromString,
   author: UserFields,
   webhook_id: optional(Schema.String),
   guild_id: optional(Schema.String),
@@ -214,7 +214,7 @@ export const message = (
       ? {}
       : { replyTo: { messageId: replyId, ...(replyAuthor === undefined ? {} : { authorId: replyAuthor }) } }),
     attachments,
-    timestamp: DateTime.makeUnsafe(fields.timestamp),
+    timestamp: fields.timestamp,
     raw
   }
 }
diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index f9d7210c81b..31f57b94e71 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -453,6 +453,67 @@ describe("opener", () => {
   })
 })
 
+describe("an opener the bot can't read", () => {
+  const forbidden = () => Effect.fail(errorResponse(403, { code: 50001, message: "Missing Access" }))
+
+  it.effect("history skips it and starts at the first reply", () => {
+    const placeholder = history.response.find((raw: any) => raw.type === 21)
+    const { referenced_message: _, ...bare } = placeholder
+    const reply = history.response.find((raw: any) => raw.type === 0)
+    const fake = makeFake({ listMessages: () => Effect.succeed([reply, bare]), getMessage: forbidden })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const found = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "forward" })))
+        assert.deepStrictEqual(found.map((message) => message.id), [reply.id])
+      })
+    )
+  })
+
+  it.effect("opener is None", () => {
+    const fake = makeFake({ getChannel: () => Effect.succeed(threadChannel), getMessage: forbidden })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        assert.isTrue(Option.isNone(yield* discord.opener(thread)))
+        assert.strictEqual(fake.called("getMessage").length, 2)
+      })
+    )
+  })
+
+  it.effect("a forbidden thread still fails history and opener", () => {
+    const fake = makeFake({ listMessages: forbidden, getChannel: forbidden })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        assert.strictEqual(
+          (yield* reason(Stream.runCollect(discord.history(thread, { direction: "forward" })))).tag,
+          "Forbidden"
+        )
+        assert.strictEqual((yield* reason(discord.opener(thread))).tag, "Forbidden")
+      })
+    )
+  })
+})
+
+describe("invalid timestamps", () => {
+  it.effect("a post answer with an invalid timestamp fails, as any unreadable write answer does", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed({ ...posted, timestamp: "not a date" }) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const result = yield* reason(discord.post(channel, { markdown: "x" }))
+        assert.strictEqual(result.tag, "Unknown")
+        assert.strictEqual(result.detail, "invalid_timestamp")
+      })
+    )
+  })
+})
+
 describe("getThread and getUser", () => {
   it.effect("getThread gives the kind, name and parent", () => {
     const fake = makeFake({
diff --git a/packages/chat/discord/test/normalize.test.ts b/packages/chat/discord/test/normalize.test.ts
index e295346137b..56740fe11d8 100644
--- a/packages/chat/discord/test/normalize.test.ts
+++ b/packages/chat/discord/test/normalize.test.ts
@@ -110,6 +110,12 @@ describe("normalize", () => {
     assert.strictEqual(withType.success[0].kind, "channel")
   })
 
+  it("a message with an invalid timestamp is dropped, not thrown", () => {
+    const base = events("channel-message")[0]
+    assert.deepStrictEqual(normalize({ t: base.t, d: { ...base.d, timestamp: "not a date" } }), [])
+    assert.isUndefined(decodeMessageFields({ ...base.d, timestamp: "not a date" }))
+  })
+
   it("a reaction needs no channel type", () => {
     for (const dispatch of events("reactions")) {
       const result = DiscordChat.normalize(dispatch, context)

From 7e659bce7856e9e411cc3ca2eb68e4bf67ccef1e Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 02:20:08 +0000
Subject: [PATCH 19/89] Fix Deno type checking of Discord live test responses

---
 packages/chat/discord/test/live.test.ts | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/packages/chat/discord/test/live.test.ts b/packages/chat/discord/test/live.test.ts
index f6bc7a2b192..969104e76f6 100644
--- a/packages/chat/discord/test/live.test.ts
+++ b/packages/chat/discord/test/live.test.ts
@@ -22,6 +22,7 @@ import * as FetchHttpClient from "effect/http/FetchHttpClient"
 import * as Layer from "effect/Layer"
 import * as Redacted from "effect/Redacted"
 import * as Result from "effect/Result"
+import * as Schema from "effect/Schema"
 import * as Semaphore from "effect/Semaphore"
 
 const botToken = process.env.DISCORD_LIVE_BOT_TOKEN
@@ -59,7 +60,7 @@ describe.skipIf(botToken === undefined || channel === undefined)("live conforman
           url.searchParams.set("wait", "true")
           const channelInfo = await fetch(`https://discord.com/api/v10/channels/${thread.id}`, {
             headers: { authorization: `Bot ${botToken}` }
-          }).then((response) => response.json())
+          }).then((response) => response.json()).then(Schema.decodeUnknownSync(Schema.Struct({ type: Schema.Number })))
           if (channelInfo.type === 11 || channelInfo.type === 10 || channelInfo.type === 12) {
             url.searchParams.set("thread_id", thread.id)
           }
@@ -69,7 +70,7 @@ describe.skipIf(botToken === undefined || channel === undefined)("live conforman
             body: JSON.stringify({ content: text, allowed_mentions: { parse: [] } })
           })
           if (!response.ok) throw new Error(`webhook answered ${response.status}`)
-          return response.json()
+          return Schema.decodeUnknownSync(Schema.Struct({ id: Schema.String }))(await response.json())
         })
         : yield* Effect.die(new Error("neither DISCORD_LIVE_SECOND_BOT_TOKEN nor DISCORD_LIVE_WEBHOOK_URL is set"))
       const rest = yield* DiscordREST

From 74c6a35a67ed54f0cc6706c641d945b86b566aed Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 05:43:52 +0000
Subject: [PATCH 20/89] Fix chat file refusal fallback and add conformance
 coverage

---
 .changeset/effect-chat.md                     |  2 +-
 packages/effect/src/chat/ChatAdapter.ts       |  6 ++-
 packages/effect/src/chat/ChatError.ts         | 21 ++++++--
 packages/effect/src/chat/ChatMarkdown.ts      | 28 +++--------
 packages/effect/src/chat/ChatMessage.ts       |  4 +-
 packages/effect/src/chat/ChatTest.ts          | 50 +++++++++++++++++--
 .../effect/test/chat/ChatMarkdown.test.ts     | 25 ++++++++--
 packages/effect/test/chat/ChatTest.test.ts    | 30 +++++++++++
 8 files changed, 129 insertions(+), 37 deletions(-)

diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 97cd948fc36..490342acd03 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -2,4 +2,4 @@
 "effect": patch
 ---
 
-Add `effect/chat`, an unstable, platform-neutral model and router for chat bots, with `ChatMarkdown` for posting long and streamed Markdown, and `ChatTest`, an in-memory adapter and the conformance suite adapters are tested against.
+Add unstable `effect/chat` APIs for chat bots, long and streamed Markdown with safe refused-file fallback, and in-memory adapter conformance testing.
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index a857f646466..4da7b848552 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -146,11 +146,15 @@ export interface User {
  * - `post` takes standard Markdown that must fit `limits.messageLength`. It
  *   never splits or truncates: the adapter checks the length itself and fails
  *   with `TooLarge` without calling the platform. Mentions in it notify nobody.
+ * - A `post` shows no link preview unless requested through the adapter's
+ *   scoped `withPostOptions`. This rule does not cover edits or native streams.
  * - `fetchMessage` fails with `NotFound` for a message that is gone.
  * - `history` pages lazily. `backward` runs newest to oldest, `forward`
  *   oldest to newest, and `from` is exclusive. A thread's oldest message is its
  *   opener, whose `thread` is the thread's parent: the one message in a
- *   thread's history that is not addressed to that thread.
+ *   thread's history that is not addressed to that thread. Without an opener,
+ *   history starts at the first reply, whether the opener was deleted or the
+ *   platform's thread root is not a message.
  * - `download` fails with `TooLarge` as soon as more than `maxBytes` arrive.
  * - `startThread` returns the thread under `messageId`, created when there is
  *   none. It is get-or-create, and the only way from an opener to its thread.
diff --git a/packages/effect/src/chat/ChatError.ts b/packages/effect/src/chat/ChatError.ts
index 8de08217a80..ab86b132d6f 100644
--- a/packages/effect/src/chat/ChatError.ts
+++ b/packages/effect/src/chat/ChatError.ts
@@ -9,7 +9,9 @@
  * **Details**
  *
  * - `detail` is redacted: a platform code such as `channel_not_found`, never
- *   message text, file names or ids.
+ *   message text, file names or ids. `file_refused` is fixed by the core: on
+ *   a `denied` reason it promises a file was refused and nothing is left
+ *   posted. It overrides platform error names; the original code stays on `cause`.
  * - `cause` is the error underneath (an HTTP error, a client library error, a
  *   `SchemaError`). It is unredacted and can hold URLs, ids and payload
  *   values. Schema encoding keeps it and `toJSON` leaves it out, so logging an
@@ -77,6 +79,15 @@ export const Capability = Schema.Literals([
  */
 export type Capability = typeof Capability.Type
 
+/**
+ * Detail for a refused file on any `denied` reason: nothing is left posted.
+ *
+ * @stability unstable
+ * @category constants
+ * @since 4.1.5
+ */
+export const fileRefused = "file_refused"
+
 const detail = Schema.optionalKey(Schema.String)
 
 const cause = Schema.optional(Schema.Defect())
@@ -347,7 +358,7 @@ export class NotFound extends Schema.TaggedError("effect/chat/ChatErro
 }
 
 /**
- * Reason for a `ChatError`: the request is past a descriptor limit: message length, file size or `download`'s `maxBytes`.
+ * Reason for a `ChatError`: the request is past a size limit: message length, file size or `download`'s `maxBytes`.
  *
  * **Details**
  *
@@ -355,8 +366,10 @@ export class NotFound extends Schema.TaggedError("effect/chat/ChatErro
  * - `subject` says what was too large, when the adapter can tell: `text` for
  *   the message text, `files` for the files sent with it. An adapter sets it
  *   on every refusal of `post`, `edit` and `NativeStream` it can attribute.
- *   `ChatMarkdown` posts again without the files, ending in the consumer's
- *   note, only for `files`.
+ * - Usually raised before the call. A platform-side size refusal carries
+ *   the platform's error name in `detail`, unless a file was refused: then
+ *   it is `file_refused`. `ChatMarkdown` keys its fallback on that detail,
+ *   not on `subject`.
  *
  * @stability unstable
  * @category errors
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index 8cc65e0c278..e9b0848c1fe 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -37,7 +37,7 @@ import * as Stream from "../Stream.ts"
 import * as Chat from "./Chat.ts"
 import type { Descriptor, File, NativeStream, Posted } from "./ChatAdapter.ts"
 import { Registry } from "./ChatAdapter.ts"
-import type { ChatError } from "./ChatError.ts"
+import { type ChatError, fileRefused } from "./ChatError.ts"
 import type { ReplyTo } from "./ChatMessage.ts"
 import type { ChatThread } from "./ChatThread.ts"
 
@@ -387,25 +387,10 @@ const firstError = (exit: Exit.Exit): ChatError | undefined =>
 const unanswered = (exit: Exit.Exit): boolean =>
   Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)
 
-/**
- * Whether a post with files may have failed because of the files, so it is
- * tried again without them. A `TooLarge` counts only when the adapter says
- * the files were too large: a refusal of text that measured as fitting fails
- * the reply.
- */
+/** Whether the adapter guarantees the files were refused and nothing remains posted. */
 const isFileRefusal = (exit: Exit.Exit): boolean => {
   const reason = firstError(exit)?.reason
-  switch (reason?._tag) {
-    case "Forbidden":
-    case "InvalidRequest":
-      return true
-    case "TooLarge":
-      return reason.subject === "files"
-    case "Unsupported":
-      return reason.capability === "files"
-    default:
-      return false
-  }
+  return reason?.retry === "denied" && reason.detail === fileRefused
 }
 
 const reply = (options: ReplyOptions): Effect.Effect, R | R2> =>
@@ -1118,12 +1103,11 @@ const reply = (options: ReplyOptions): Effect.Effect Effect.Effect
+  readonly refuseFiles: (options?: { readonly times?: number | undefined }) => Effect.Effect
   readonly clickStop: (messageId: string) => Effect.Effect
   readonly closeStream: (messageId: string) => Effect.Effect
 }>()("effect/chat/ChatTest") {}
@@ -248,6 +252,7 @@ const makeFake = (options: {
   const threadUnder = new Map()
   const users = new Map([[selfId, { isBot: true }]])
   const calls: Array = []
+  let refusedFiles = 0
   const faults = new Map>()
   let counter = 0
   const nextId = (prefix: string) => prefix + String(++counter)
@@ -374,6 +379,11 @@ const makeFake = (options: {
         record("Unsupported")
         return fail(call.op, new Unsupported({ capability: missing }))
       }
+      if (call.op === "post" && (call.files?.length ?? 0) > 0 && refusedFiles > 0) {
+        refusedFiles--
+        record("Forbidden")
+        return fail(call.op, new Forbidden({ detail: fileRefused }))
+      }
       const fault = takeFault(call.op)
       if (fault !== undefined) {
         record(fault.reason._tag)
@@ -493,7 +503,7 @@ const makeFake = (options: {
             files.length > descriptor.limits.filesPerMessage ||
             files.some((file) => file.content.length > descriptor.limits.uploadBytes)
           ) {
-            return yield* fail("post", new TooLarge({ subject: "files", detail: "file_too_large" }))
+            return yield* fail("post", new TooLarge({ subject: "files", detail: fileRefused }))
           }
           let replyTo: ReplyTo | undefined
           if (content.replyTo !== undefined) {
@@ -688,6 +698,10 @@ const makeFake = (options: {
         return stored === undefined ? [] : listMessages(stored).map(toMessage)
       }),
     calls: Effect.sync(() => calls.slice()),
+    refuseFiles: (options) =>
+      Effect.sync(() => {
+        refusedFiles += options?.times ?? 1
+      }),
     failNext: (op, reason, failOptions) =>
       Effect.sync(() => {
         const queue = faults.get(op) ?? []
@@ -1171,8 +1185,9 @@ const findIn = (messages: ReadonlyArray, id: string) =>
 
 /** A refusal of the text must not blame the files, or `ChatMarkdown` would post again without them. */
 const textTooLarge = {
-  expected: "TooLarge without subject files",
-  test: (reason: ChatErrorReason) => reason._tag === "TooLarge" && reason.subject !== "files"
+  expected: "TooLarge without subject files or detail file_refused",
+  test: (reason: ChatErrorReason) =>
+    reason._tag === "TooLarge" && reason.subject !== "files" && reason.detail !== fileRefused
 }
 
 const mentionLike = "@everyone @here <@U0000>   <@&1> <#C0000>"
@@ -1201,6 +1216,7 @@ interface ConformanceOptions {
   readonly thread: ChatThread.ChatThread
   readonly userPosts: (thread: ChatThread.ChatThread, text: string) => Effect.Effect
   readonly parseMention: ParseMention
+  readonly refuseFiles?: (() => Effect.Effect) | undefined
   readonly failNext?:
     | ((op: string, reason: ChatErrorReason, options?: {
       readonly times?: number | undefined
@@ -1226,6 +1242,7 @@ interface ConformanceOptions {
  * - A listed capability never fails with `Unsupported`, which every rule
  *   checks as it goes.
  * - The three `retries/*` rules exist only when `failNext` is given.
+ *   `post/refusedFile` exists only when `refuseFiles` is given.
  * - Every rule deletes what it posted when it ends, pass or fail, when the
  *   platform can delete.
  *
@@ -1244,6 +1261,7 @@ export const conformance = (options: {
   readonly thread: ChatThread.ChatThread
   readonly userPosts: (thread: ChatThread.ChatThread, text: string) => Effect.Effect
   readonly parseMention: ParseMention
+  readonly refuseFiles?: (() => Effect.Effect) | undefined
   readonly failNext?:
     | ((op: string, reason: ChatErrorReason, options?: {
       readonly times?: number | undefined
@@ -1326,6 +1344,32 @@ export const conformance = (options: {
       )
     }))
 
+  const refuseFiles = options.refuseFiles
+  if (refuseFiles !== undefined) {
+    rule("post/refusedFile", ["files", "history"], (t) =>
+      Effect.gen(function*() {
+        const before = yield* t.collect(t.chat.history(t.thread, { direction: "forward" }))
+        yield* refuseFiles()
+        const exit = yield* Effect.exit(t.chat.post(t.thread, {
+          markdown: conformanceText(t.rule),
+          files: [conformanceFile(t.rule)]
+        }))
+        if (Exit.isSuccess(exit)) t.created.push({ thread: t.thread, id: exit.value.id })
+        const error = Exit.findErrorOption(exit)
+        yield* t.check(
+          Option.isSome(error) && error.value.reason.retry === "denied" && error.value.reason.detail === fileRefused,
+          "denied with detail file_refused",
+          () => describeExit(exit)
+        )
+        const after = yield* t.collect(t.chat.history(t.thread, { direction: "forward" }))
+        yield* t.check(
+          after.length === before.length && after.every((message, i) => message.id === before[i].id),
+          "no new message",
+          () => after.length + " messages after, " + before.length + " before"
+        )
+      }))
+  }
+
   rule("post/tooLarge", [], (t) =>
     t.expectReason(
       "TooLarge",
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index f77fdb45e36..78dc8681c98 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -165,7 +165,7 @@ describe("ChatMarkdown", () => {
     it.effect("ends in the unattached note when the files are refused", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
-        yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_uploads_disabled" }))
+        yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_refused" }))
         const result = yield* ChatMarkdown.post(thread, "Report", {
           files,
           unattachedNote: (files) => "\n\n(" + files.length + " file not attached)"
@@ -181,7 +181,7 @@ describe("ChatMarkdown", () => {
     it.effect("fails when the files are refused without a note", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
-        yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_uploads_disabled" }))
+        yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_refused" }))
         const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", { files }))
         assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
         assert.deepStrictEqual([error.posted, error.remaining], [[], "Report"])
@@ -204,7 +204,7 @@ describe("ChatMarkdown", () => {
     it.effect("ends in the unattached note when the files are too large", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
-        yield* test.failNext("post", new ChatError.TooLarge({ subject: "files", detail: "file_too_large" }))
+        yield* test.failNext("post", new ChatError.TooLarge({ subject: "files", detail: "file_refused" }))
         const result = yield* ChatMarkdown.post(thread, "Report", {
           files,
           unattachedNote: () => " (file not attached)"
@@ -215,13 +215,28 @@ describe("ChatMarkdown", () => {
     it.effect("does not retry without the files for a failure unrelated to them", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
-        yield* test.failNext("post", new ChatError.NotFound({ detail: "channel_not_found" }))
+        yield* test.failNext("post", new ChatError.Forbidden({ detail: "missing_scope" }))
         const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", {
           files,
           unattachedNote: () => " (file not attached)"
         }))
-        assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "NotFound")
+        assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
+        assert.strictEqual((yield* test.calls).filter((call) => call.op === "post").length, 1)
+      }).pipe(Effect.provide(ChatTest.layer())))
+
+    it.effect("does not post a note for an uncertain file write", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        yield* test.failNext("post", new ChatError.Transport({ retry: "uncertain", detail: "file_refused" }), {
+          landed: true
+        })
+        const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", {
+          files,
+          unattachedNote: () => " (file not attached)"
+        }))
+        assert.isDefined(error.uncertain)
         assert.strictEqual((yield* test.calls).filter((call) => call.op === "post").length, 1)
+        assert.deepStrictEqual(yield* texts(test, thread), ["Report"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
     it.effect("keeps the files and blank text that follow the last cut", () =>
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index 98788888a6a..ec0f9f9f2a6 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -15,6 +15,7 @@ const rulesFor = (test: ChatTest.ChatTest["Service"], thread: ChatThread.ChatThr
     thread,
     userPosts: (thread, text) => test.userPosts(thread, { text }),
     parseMention,
+    refuseFiles: test.refuseFiles,
     failNext: test.failNext
   })
 
@@ -28,6 +29,7 @@ const ruleNames = Object.keys(ChatTest.conformance({
   thread: ChatThread.make("test", "c0"),
   userPosts: () => Effect.die("unused"),
   parseMention,
+  refuseFiles: () => Effect.void,
   failNext: () => Effect.void
 }))
 
@@ -37,6 +39,34 @@ const runRule = (rule: string, options?: Parameters[0]) =
   Effect.flatMap(suite, (rules) => rules[rule]).pipe(Effect.provide(ChatTest.layer(options)))
 
 describe("ChatTest", () => {
+  it("omits post/refusedFile without its hook", () => {
+    const rules = ChatTest.conformance({
+      platform: "test",
+      thread: ChatThread.make("test", "c0"),
+      userPosts: () => Effect.die("unused"),
+      parseMention
+    })
+    assert.isUndefined(rules["post/refusedFile"])
+  })
+
+  it.effect("refuseFiles counts only posts with files and leaves nothing posted", () =>
+    Effect.gen(function*() {
+      const test = yield* ChatTest.ChatTest
+      const chat = yield* Chat.Chat
+      const thread = yield* test.makeThread()
+      const files = [{ name: "a.txt", contentType: "text/plain", content: new Uint8Array([1]) }]
+      yield* test.refuseFiles({ times: 2 })
+      yield* chat.post(thread, { markdown: "text only" })
+      for (let i = 0; i < 2; i++) {
+        const error = yield* Effect.flip(chat.post(thread, { markdown: "refused", files }))
+        assert.strictEqual(error.reason.retry, "denied")
+        assert.strictEqual(error.reason.detail, ChatError.fileRefused)
+      }
+      assert.deepStrictEqual((yield* test.messages(thread)).map((message) => message.text), ["text only"])
+      yield* chat.post(thread, { markdown: "accepted", files })
+      assert.strictEqual((yield* test.messages(thread)).length, 2)
+    }).pipe(Effect.provide(ChatTest.layer())))
+
   describe("conformance with every capability", () => {
     for (const rule of ruleNames) {
       it.live(rule, () => runRule(rule))

From f6efe9eb7f9e062faddc83e31c65c2e5184fbaea Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 05:53:04 +0000
Subject: [PATCH 21/89] Tighten refused-file conformance checks and cleanup

---
 packages/effect/src/chat/ChatMarkdown.ts   |  5 ++-
 packages/effect/src/chat/ChatTest.ts       | 16 ++++++--
 packages/effect/test/chat/ChatTest.test.ts | 46 ++++++++++++++++++++++
 3 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index e9b0848c1fe..b6c20ebe440 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -1108,8 +1108,9 @@ const reply = (options: ReplyOptions): Effect.Effect message.id))
+        for (const message of after) {
+          if (message.author.isSelf && !beforeIds.has(message.id) && !t.created.some(({ id }) => id === message.id)) {
+            t.created.push({ thread: message.thread, id: message.id })
+          }
+        }
         const error = Exit.findErrorOption(exit)
+        const reason = Option.isSome(error) ? error.value.reason : undefined
+        const listed = reason?._tag === "Unsupported" && t.has(reason.capability)
         yield* t.check(
-          Option.isSome(error) && error.value.reason.retry === "denied" && error.value.reason.detail === fileRefused,
-          "denied with detail file_refused",
-          () => describeExit(exit)
+          !listed && reason?.retry === "denied" && reason.detail === fileRefused,
+          "denied with detail file_refused, not Unsupported for a listed capability",
+          () => describeExit(exit) + (listed ? " for a listed capability" : "")
         )
-        const after = yield* t.collect(t.chat.history(t.thread, { direction: "forward" }))
         yield* t.check(
           after.length === before.length && after.every((message, i) => message.id === before[i].id),
           "no new message",
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index ec0f9f9f2a6..53e2f9deaa5 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -81,6 +81,52 @@ describe("ChatTest", () => {
     })
   }
 
+  it.effect("post/refusedFile rejects Unsupported for a listed capability", () =>
+    Effect.gen(function*() {
+      const test = yield* ChatTest.ChatTest
+      const thread = yield* test.makeThread()
+      const rules = ChatTest.conformance({
+        platform: test.platform,
+        thread,
+        parseMention,
+        userPosts: (thread, text) => test.userPosts(thread, { text }),
+        refuseFiles: () =>
+          test.failNext(
+            "post",
+            new ChatError.Unsupported({
+              capability: "files",
+              detail: ChatError.fileRefused
+            })
+          )
+      })
+      const error = yield* Effect.flip(rules["post/refusedFile"])
+      assert.strictEqual(error.rule, "post/refusedFile")
+      assert.strictEqual(error.actual, "Unsupported(files) for a listed capability")
+    }).pipe(Effect.provide(ChatTest.layer())))
+
+  it.effect("post/refusedFile cleans up a refused write that landed", () =>
+    Effect.gen(function*() {
+      const test = yield* ChatTest.ChatTest
+      const thread = yield* test.makeThread()
+      const rules = ChatTest.conformance({
+        platform: test.platform,
+        thread,
+        parseMention,
+        userPosts: (thread, text) => test.userPosts(thread, { text }),
+        refuseFiles: () =>
+          test.failNext(
+            "post",
+            new ChatError.Forbidden({
+              detail: ChatError.fileRefused
+            }),
+            { landed: true }
+          )
+      })
+      const error = yield* Effect.flip(rules["post/refusedFile"])
+      assert.strictEqual(error.expected, "no new message")
+      assert.deepStrictEqual(yield* test.messages(thread), [])
+    }).pipe(Effect.provide(ChatTest.layer())))
+
   it.effect("fails unsupported/{capability} for a descriptor that leaves out a working op", () =>
     Effect.gen(function*() {
       const registry = yield* ChatAdapter.Registry

From 0c40597ffc918349fd35e0dc18f02513bb50d4ef Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 06:22:21 +0000
Subject: [PATCH 22/89] Send Slack posts and updates as a markdown block plus
 an escaped text

chat.postMessage and chat.update now go as blocks: [markdown] plus a text the adapter builds, with every <, > and & as an entity and allowed tokens intact, cut to 16,000 code points on a post and 3,800 UTF-8 bytes on an update. The bot's own messages read back with text rendered from their rich_text blocks. A two-tone emoji name no longer resolves.
---
 packages/chat/slack/src/SlackChat.ts          |  26 +-
 packages/chat/slack/src/internal/adapter.ts   |  27 +-
 packages/chat/slack/src/internal/emoji.ts     |  27 +-
 packages/chat/slack/src/internal/escape.ts    |  37 +-
 packages/chat/slack/src/internal/mentions.ts  |   8 +-
 packages/chat/slack/src/internal/normalize.ts |  17 +-
 packages/chat/slack/src/internal/richText.ts  | 294 ++++++++++++++
 packages/chat/slack/src/internal/text.ts      | 202 ++++++++++
 packages/chat/slack/test/SlackChat.test.ts    |  46 ++-
 packages/chat/slack/test/emoji.test.ts        |  70 ++--
 packages/chat/slack/test/events.test.ts       |   4 +-
 .../test/fixtures/synthetic/own-messages.json | 366 ++++++++++++++++++
 packages/chat/slack/test/live.test.ts         |  81 +++-
 packages/chat/slack/test/normalize.test.ts    |   5 +-
 packages/chat/slack/test/richText.test.ts     | 107 +++++
 packages/chat/slack/test/text.test.ts         | 152 ++++++++
 16 files changed, 1393 insertions(+), 76 deletions(-)
 create mode 100644 packages/chat/slack/src/internal/richText.ts
 create mode 100644 packages/chat/slack/src/internal/text.ts
 create mode 100644 packages/chat/slack/test/fixtures/synthetic/own-messages.json
 create mode 100644 packages/chat/slack/test/richText.test.ts
 create mode 100644 packages/chat/slack/test/text.test.ts

diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 59ed5ca2286..42813a11c45 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -96,9 +96,16 @@ export class SlackChat extends Context.Service` and `&` goes as an entity.
+ *   Slack decides who a message mentions from `text`, so no token notifies
+ *   unless `withPostOptions({ notify })` allows it. Allowed tokens stay
+ *   intact in both.
+ * - That `text` is cut to 16,000 code points on a post and 3,800 UTF-8
+ *   bytes on an edit, on a grapheme cluster boundary, ending in `…` with
+ *   the allowed tokens the cut left out appended. The cut never fails.
+ *   Stream appends still go as `markdown_text`.
  * - `post`, `edit` and stream writes fail with `TooLarge` before calling
  *   Slack when the text as sent passes 12,000 code points. Slack's second
  *   limit, 13,200 with every emoji counted as its shortcode, is left to
@@ -247,7 +254,13 @@ export const layerWebhook = (options: {
  * - A message subtype other than `file_share`, `thread_broadcast`,
  *   `bot_message` and `me_message` gives none.
  * - Mentions come from the message's `rich_text` block when it has one,
- *   and from `text` outside code otherwise.
+ *   and only for elements whose token is in `text`, since Slack decides a
+ *   mention from `text`. Without a `rich_text` block they come from `text`
+ *   outside code.
+ * - The bot's own messages with a `rich_text` block read back with `text`
+ *   rendered from the blocks as Markdown, whole and with its newlines, as
+ *   the stored `text` the adapter sent may be cut. Everyone else's `text`
+ *   is Slack's field as stored.
  * - `agent_session_stopped` gives a `StopRequested`.
  * - `raw` is the envelope without its verification `token`.
  *
@@ -313,8 +326,9 @@ export const withPostOptions: {
 )
 
 /**
- * A Slack emoji name, with or without colons and with skin tone suffixes, as
- * Unicode. `None` for a name the table doesn't know, such as a custom emoji.
+ * A Slack emoji name, with or without colons and with at most one skin tone
+ * suffix (`+1::skin-tone-4`), as Unicode. `None` for a name the table
+ * doesn't know, such as a custom emoji, and for a name with two tones.
  *
  * @stability unstable
  * @category emoji
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 48a0538db00..6a682ae710d 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -26,6 +26,7 @@ import * as Escape from "./escape.ts"
 import * as Length from "./length.ts"
 import * as Normalize from "./normalize.ts"
 import { CurrentPostOptions, type SessionStatus } from "./options.ts"
+import * as Text from "./text.ts"
 
 type Json = Schema.Json
 type JsonObject = { readonly [key: string]: Json }
@@ -231,6 +232,22 @@ export const make = (options: {
       ? fail(op, new TooLarge({ subject: "text", detail: "msg_too_long" }))
       : Effect.void
 
+  /**
+   * The body of a post or an update: the Markdown as one `markdown` block,
+   * and a `text` the adapter builds, cut to the call's budget. Slack decides
+   * mentions from `text`, and builds one with every token intact when none
+   * is sent, so `markdown_text` is never used on these two calls.
+   */
+  const messageContent = Effect.fnUntraced(
+    function*(op: string, markdown: string, notify: Escape.Notify, budget: Text.Budget) {
+      const body = Text.body(markdown, notify, budget)
+      yield* checkSent(op, body.sent)
+      if (body.text === "") return yield* fail(op, Errors.invalidRequest("no_text"))
+      if (body.dropped > 0) yield* Effect.annotateCurrentSpan("slack.text.dropped_tokens", body.dropped)
+      return { blocks: body.blocks, text: body.text }
+    }
+  )
+
   const messages = (answer: Json): ReadonlyArray =>
     isObject(answer) && Array.isArray(answer.messages) ? answer.messages : []
 
@@ -582,13 +599,12 @@ export const make = (options: {
       if (content.files !== undefined && content.files.length > 0) {
         return yield* postFiles(thread, parts, content.markdown, content.files, notify)
       }
-      const sent = Escape.escape(content.markdown, notify, { flush: true }).sent
-      yield* checkSent("post", sent)
+      const body = yield* messageContent("post", content.markdown, notify, Text.postBudget)
       const unfurl = postOptions.unfurl === true
       const ts = yield* call("post", "chat.postMessage", {
         channel: parts.channel,
         thread_ts: parts.threadTs,
-        markdown_text: sent,
+        ...body,
         unfurl_links: unfurl,
         unfurl_media: unfurl
       }, { write: true }).pipe(Effect.flatMap(tsOf("post", true)))
@@ -597,11 +613,10 @@ export const make = (options: {
     edit: Effect.fnUntraced(function*(thread, messageId, content) {
       const parts = yield* resolve("edit", thread)
       const postOptions = yield* CurrentPostOptions
-      const sent = Escape.escape(content.markdown, postOptions.notify ?? {}, { flush: true }).sent
-      yield* checkSent("edit", sent)
+      const body = yield* messageContent("edit", content.markdown, postOptions.notify ?? {}, Text.updateBudget)
       yield* retrySafe(paced(
         messageId,
-        call("edit", "chat.update", { channel: parts.channel, ts: messageId, markdown_text: sent }, {
+        call("edit", "chat.update", { channel: parts.channel, ts: messageId, ...body }, {
           write: true,
           retry: false
         }),
diff --git a/packages/chat/slack/src/internal/emoji.ts b/packages/chat/slack/src/internal/emoji.ts
index 837ea0e6b62..952d59b3a1d 100644
--- a/packages/chat/slack/src/internal/emoji.ts
+++ b/packages/chat/slack/src/internal/emoji.ts
@@ -101,13 +101,12 @@ const SKIN_TONE = /^skin-tone-([2-6])$/
 /**
  * Resolve a Slack emoji name to its fully qualified emoji.
  *
- * Accepts any alias, with or without surrounding colons, followed by up to
- * two `::skin-tone-N` suffixes (`+1::skin-tone-3`,
- * `handshake::skin-tone-2::skin-tone-5`). Toned emoji come from upstream
- * `skin_variations` only; a tone the emoji does not have yields `undefined`.
- * Two equal tones and a single tone are treated as the same request, since
- * upstream keys some emoji one way (`handshake`) and some the other
- * (`people_holding_hands`).
+ * Accepts any alias, with or without surrounding colons, followed by at most
+ * one `::skin-tone-N` suffix (`+1::skin-tone-3`). The toned emoji is the
+ * upstream `skin_variations` entry with that one tone, so `toName` on it
+ * gives the name back. A tone the emoji does not have, and a name with two
+ * tones, yield `undefined`: no recording shows what Slack sends for a
+ * two-tone reaction.
  *
  * @internal
  */
@@ -117,17 +116,9 @@ export const fromName = (name: string): string | undefined => {
   const entry = table().byName.get(parts[0])
   if (entry === undefined) return undefined
   if (parts.length === 1) return entry.unified
-  if (parts.length > 3) return undefined
-  let tones = ""
-  for (let i = 1; i < parts.length; i++) {
-    const match = SKIN_TONE.exec(parts[i])
-    if (match === null) return undefined
-    tones += match[1]
-  }
-  const exact = entry.variations.get(tones)
-  if (exact !== undefined) return exact
-  if (tones.length === 1) return entry.variations.get(tones + tones)
-  return tones[0] === tones[1] ? entry.variations.get(tones[0]) : undefined
+  if (parts.length !== 2) return undefined
+  const match = SKIN_TONE.exec(parts[1])
+  return match === null ? undefined : entry.variations.get(match[1])
 }
 
 /**
diff --git a/packages/chat/slack/src/internal/escape.ts b/packages/chat/slack/src/internal/escape.ts
index 95bb6426103..e8402bba84f 100644
--- a/packages/chat/slack/src/internal/escape.ts
+++ b/packages/chat/slack/src/internal/escape.ts
@@ -1,7 +1,12 @@
 /**
- * Escaping for Slack's `markdown_text`: a `<` outside inline and fenced code
- * becomes `<`, so no mention token notifies, unless the scoped notify
- * options allow that token.
+ * Escaping for what the adapter sends Slack.
+ *
+ * - The Markdown, in a `markdown` block or in `markdown_text`: a `<`
+ *   outside inline and fenced code becomes `<`, unless the scoped notify
+ *   options allow that token.
+ * - The `text` beside a `markdown` block, from which Slack decides who is
+ *   mentioned: every `<`, `>` and `&` becomes an entity, in code too, and
+ *   only the tokens the block keeps intact stay intact.
  */
 
 /** @internal */
@@ -129,10 +134,18 @@ const codeSpans = (line: string): { readonly spans: Array` and `&` as an entity, apart from allowed tokens. */
+    readonly entities?: boolean | undefined
+    /** Called with the span in the output of each allowed token kept intact. */
+    readonly onToken?: ((start: number, end: number) => void) | undefined
+  }
 ): Escaped => {
   const state = options?.state ?? initialState
   const flush = options?.flush === true
+  const entities = options?.entities === true
   const full = state.line + text
   const offset = state.line.length
   const anyAllowed = allowsAny(notify)
@@ -141,7 +154,11 @@ export const escape = (
   let lineStart = 0
   const emit = (from: number, to: number, piece?: string) => {
     if (to <= offset) return
-    out += piece !== undefined ? piece : full.slice(Math.max(from, offset), to)
+    if (piece !== undefined) out += piece
+    else {
+      const slice = full.slice(Math.max(from, offset), to)
+      out += entities ? textEntities(slice) : slice
+    }
   }
   while (lineStart <= full.length) {
     const newline = full.indexOf("\n", lineStart)
@@ -186,7 +203,9 @@ export const escape = (
         }
         const token = allowedToken(rest, notify)
         if (token > 0) {
-          emit(at, at + token)
+          const start = out.length
+          emit(at, at + token, at >= offset ? rest.slice(0, token) : undefined)
+          if (at >= offset) options?.onToken?.(start, out.length)
           i += token
         } else {
           emit(at, at + 1, at >= offset ? "<" : undefined)
@@ -204,7 +223,9 @@ export const escape = (
   return { sent: out, consumed: full.length - offset, state: { fence, line: "" } }
 }
 
-const mrkdwnEntities = (text: string): string => text.replace(/&/g, "&").replace(//g, ">")
+const entityOf: Record = { "&": "&", "<": "<", ">": ">" }
+
+const textEntities = (text: string): string => text.replace(/[&<>]/g, (char) => entityOf[char])
 
 /**
  * Markdown as Slack's mrkdwn, for the text of a message that carries files,
@@ -219,7 +240,7 @@ export const toMrkdwn = (markdown: string, notify: Notify): string =>
   markdown
     .split(/(```[\s\S]*?```|`[^`\n]*`)/)
     .map((part, index) => {
-      if (index % 2 === 1) return mrkdwnEntities(part.replace(/^```[\w+#.-]+\n/, "```\n"))
+      if (index % 2 === 1) return textEntities(part.replace(/^```[\w+#.-]+\n/, "```\n"))
       // Allowed tokens become private-use placeholders, so the conversions
       // below can span them but never change them.
       const tokens: Array = []
diff --git a/packages/chat/slack/src/internal/mentions.ts b/packages/chat/slack/src/internal/mentions.ts
index 1c4d656947b..f343b83d862 100644
--- a/packages/chat/slack/src/internal/mentions.ts
+++ b/packages/chat/slack/src/internal/mentions.ts
@@ -179,12 +179,14 @@ const align = (items: ReadonlyArray, found: ReadonlyArray): Array => {
  *   `ts`, and the thread otherwise. It never depends on later replies.
  * - A `bot_message` has `bot_id` and no `user`: `author.id` is the
  *   `bot_id`, with `isBot` true.
+ * - `text` is Slack's field as stored, except for a message the bot itself
+ *   wrote that has a `rich_text` block. Its `text` is rendered from the
+ *   blocks as Markdown, and its mentions are the mention elements outside
+ *   code, at the offsets the renderer wrote. The adapter's own `text` is
+ *   often cut, and the blocks hold the whole message. Slack's field stays on
+ *   `raw`.
  *
  * @internal
  */
@@ -100,7 +107,11 @@ export const message = (raw: unknown, context: MessageContext): ChatMessage.Chat
   const authorId = user ?? botId
   if (authorId === undefined) return undefined
   const threadTs = string(raw, "thread_ts")
-  const text = typeof raw.text === "string" ? raw.text : ""
+  const isSelf = user !== undefined && user === context.botUserId
+  const rendered = isSelf && Array.isArray(raw.blocks) && RichText.hasRichText(raw.blocks)
+    ? RichText.render(raw.blocks, context.botUserId)
+    : undefined
+  const text = rendered?.text ?? (typeof raw.text === "string" ? raw.text : "")
   const name = authorName(raw)
   return {
     id: ts,
@@ -113,10 +124,10 @@ export const message = (raw: unknown, context: MessageContext): ChatMessage.Chat
       id: authorId,
       ...(name === undefined ? {} : { name }),
       isBot: botId !== undefined || subtype === "bot_message" || user === context.botUserId,
-      isSelf: user !== undefined && user === context.botUserId
+      isSelf
     },
     text,
-    mentions: Mentions.extract(text, raw.blocks, context.botUserId),
+    mentions: rendered === undefined ? Mentions.extract(text, raw.blocks, context.botUserId) : [...rendered.mentions],
     attachments: attachments(raw),
     timestamp: timestamp(ts),
     raw
diff --git a/packages/chat/slack/src/internal/richText.ts b/packages/chat/slack/src/internal/richText.ts
new file mode 100644
index 00000000000..18f005cc6f4
--- /dev/null
+++ b/packages/chat/slack/src/internal/richText.ts
@@ -0,0 +1,294 @@
+/**
+ * Renders a message's `rich_text` blocks as Markdown, for the `text` of the
+ * bot's own messages. Slack stores the adapter's `markdown` block as
+ * `rich_text`, and the stored `text` is the adapter's `text`, which may be
+ * cut. Rendering the blocks gives the whole message back, with its newlines.
+ *
+ * The renderer is total: an element it does not know gives its `text`, or
+ * nothing.
+ */
+import type { Mention } from "effect/chat/ChatMessage"
+import * as Emoji from "./emoji.ts"
+
+type JsonObject = { readonly [key: string]: unknown }
+
+const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u)
+
+const stringOf = (object: JsonObject, key: string): string | undefined => {
+  const value = object[key]
+  return typeof value === "string" ? value : undefined
+}
+
+const elementsOf = (object: JsonObject): ReadonlyArray => Array.isArray(object.elements) ? object.elements : []
+
+/** @internal */
+export const hasRichText = (blocks: unknown): boolean =>
+  Array.isArray(blocks) && blocks.some((block) => isObject(block) && block.type === "rich_text")
+
+interface Style {
+  readonly bold: boolean
+  readonly italic: boolean
+  readonly strike: boolean
+  readonly code: boolean
+}
+
+const plain: Style = { bold: false, italic: false, strike: false, code: false }
+
+const styleOf = (element: JsonObject): Style => {
+  const style = element.style
+  if (!isObject(style)) return plain
+  return {
+    bold: style.bold === true,
+    italic: style.italic === true,
+    strike: style.strike === true,
+    code: style.code === true
+  }
+}
+
+const sameStyle = (a: Style, b: Style) =>
+  a.bold === b.bold && a.italic === b.italic && a.strike === b.strike && a.code === b.code
+
+const opening = (style: Style): string =>
+  (style.bold ? "**" : "") + (style.italic ? "*" : "") + (style.strike ? "~~" : "")
+
+const closing = (style: Style): string =>
+  (style.strike ? "~~" : "") + (style.italic ? "*" : "") + (style.bold ? "**" : "")
+
+const longestRun = (text: string, char: string): number => {
+  let longest = 0
+  let run = 0
+  for (const c of text) {
+    run = c === char ? run + 1 : 0
+    if (run > longest) longest = run
+  }
+  return longest
+}
+
+/** One element's content: plain text, or a mention token. */
+type Piece =
+  | { readonly _tag: "text"; readonly text: string }
+  | { readonly _tag: "mention"; readonly token: string; readonly kind: Mention["kind"]; readonly id: string }
+
+const emojiText = (element: JsonObject): string => {
+  const unicode = stringOf(element, "unicode")
+  if (unicode !== undefined && /^[0-9a-f]+(-[0-9a-f]+)*$/i.test(unicode)) {
+    const points = unicode.split("-").map((hex) => parseInt(hex, 16))
+    if (points.every((point) => point <= 0x10ffff)) return String.fromCodePoint(...points)
+  }
+  const name = stringOf(element, "name")
+  if (name === undefined) return ""
+  const tone = element.skin_tone
+  const full = typeof tone === "number" ? `${name}::skin-tone-${tone}` : name
+  return Emoji.fromName(full) ?? Emoji.fromName(name) ?? `:${full}:`
+}
+
+const pieceOf = (element: JsonObject): Piece => {
+  switch (element.type) {
+    case "text":
+      return { _tag: "text", text: stringOf(element, "text") ?? "" }
+    case "link": {
+      const url = stringOf(element, "url") ?? ""
+      const text = stringOf(element, "text")
+      // Slack stores a bare URL as a link whose text is the URL without its scheme.
+      const bare = text === undefined || text === "" || text === url ||
+        text === url.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "")
+      return { _tag: "text", text: bare ? url : `[${text}](${url})` }
+    }
+    case "user": {
+      const id = stringOf(element, "user_id")
+      if (id !== undefined) return { _tag: "mention", token: `<@${id}>`, kind: "user", id }
+      break
+    }
+    case "usergroup": {
+      const id = stringOf(element, "usergroup_id")
+      if (id !== undefined) return { _tag: "mention", token: ``, kind: "role", id }
+      break
+    }
+    case "channel": {
+      const id = stringOf(element, "channel_id")
+      if (id !== undefined) return { _tag: "mention", token: `<#${id}>`, kind: "channel", id }
+      break
+    }
+    case "broadcast": {
+      const id = stringOf(element, "range")
+      if (id !== undefined) return { _tag: "mention", token: ``, kind: "broadcast", id }
+      break
+    }
+    case "emoji":
+      return { _tag: "text", text: emojiText(element) }
+    case "date":
+      return { _tag: "text", text: stringOf(element, "fallback") ?? "" }
+    case "color":
+      return { _tag: "text", text: stringOf(element, "value") ?? "" }
+  }
+  return { _tag: "text", text: stringOf(element, "text") ?? "" }
+}
+
+const pieceText = (piece: Piece): string => piece._tag === "text" ? piece.text : piece.token
+
+interface Writer {
+  out: string
+  readonly mentions: Array
+  readonly botUserId: string
+}
+
+const write = (writer: Writer, text: string): void => {
+  writer.out += text
+}
+
+const mention = (writer: Writer, piece: Extract): void => {
+  const start = writer.out.length
+  writer.out += piece.token
+  writer.mentions.push({
+    kind: piece.kind,
+    id: piece.id,
+    start,
+    end: writer.out.length,
+    isSelf: piece.kind === "user" && piece.id === writer.botUserId
+  })
+}
+
+/** Starts a new line unless the output is empty or already ends one. */
+const newline = (writer: Writer): void => {
+  if (writer.out !== "" && !writer.out.endsWith("\n")) writer.out += "\n"
+}
+
+/**
+ * Inline elements, grouped into runs of one style so markers wrap a run and
+ * not each element. Whitespace at either end of a styled run goes outside
+ * its markers, where Markdown needs it. Code is a span, and a token in it is
+ * a literal.
+ */
+const inline = (writer: Writer, elements: ReadonlyArray): void => {
+  const items = elements.filter(isObject).map((element) => ({ piece: pieceOf(element), style: styleOf(element) }))
+  let i = 0
+  while (i < items.length) {
+    const style = items[i].style
+    let j = i + 1
+    while (j < items.length && sameStyle(items[j].style, style)) j++
+    const run = items.slice(i, j).map((item) => item.piece)
+    i = j
+    if (style.code) {
+      const content = run.map(pieceText).join("")
+      const fence = "`".repeat(longestRun(content, "`") + 1)
+      const pad = content.startsWith("`") || content.endsWith("`") ? " " : ""
+      write(writer, opening(style) + fence + pad + content + pad + fence + closing(style))
+      continue
+    }
+    const open = opening(style)
+    if (open === "") {
+      for (const piece of run) {
+        if (piece._tag === "text") write(writer, piece.text)
+        else mention(writer, piece)
+      }
+      continue
+    }
+    const first = run[0]
+    const last = run[run.length - 1]
+    const lead = first._tag === "text" ? /^\s*/.exec(first.text)![0] : ""
+    const trail = last._tag === "text" ? /\s*$/.exec(last.text)![0] : ""
+    if (run.length === 1 && first._tag === "text" && lead.length === first.text.length) {
+      write(writer, first.text)
+      continue
+    }
+    write(writer, lead + open)
+    run.forEach((piece, k) => {
+      if (piece._tag === "mention") return mention(writer, piece)
+      let text = piece.text
+      if (k === 0) text = text.slice(lead.length)
+      if (k === run.length - 1) text = text.slice(0, text.length - trail.length)
+      write(writer, text)
+    })
+    write(writer, closing(style) + trail)
+  }
+}
+
+/** Prefixes each line written since `from`, and moves the mentions in it to match. */
+const prefixLines = (writer: Writer, from: number, first: string, rest: string): void => {
+  const body = writer.out.slice(from)
+  const lines = body.split("\n")
+  let rewritten = ""
+  const shifts: Array = []
+  let position = from
+  lines.forEach((line, index) => {
+    const prefix = index === 0 ? first : rest
+    shifts.push([position, prefix.length])
+    rewritten += (index === 0 ? "" : "\n") + prefix + line
+    position += line.length + 1
+  })
+  writer.out = writer.out.slice(0, from) + rewritten
+  // Move the mentions written in this span by the prefixes before them.
+  for (let m = 0; m < writer.mentions.length; m++) {
+    const mention = writer.mentions[m]
+    if (mention.start < from) continue
+    let shift = 0
+    for (const [at, length] of shifts) if (at <= mention.start) shift += length
+    writer.mentions[m] = { ...mention, start: mention.start + shift, end: mention.end + shift }
+  }
+}
+
+const block = (writer: Writer, element: unknown): void => {
+  if (!isObject(element)) return
+  switch (element.type) {
+    case "rich_text_section":
+      return inline(writer, elementsOf(element))
+    case "rich_text_preformatted": {
+      // A fence holds no mention: every token is literal.
+      const content = elementsOf(element).filter(isObject).map((child) => pieceText(pieceOf(child))).join("")
+      const fence = "`".repeat(Math.max(3, longestRun(content, "`") + 1))
+      write(writer, fence + "\n" + content + (content.endsWith("\n") ? "" : "\n") + fence)
+      return
+    }
+    case "rich_text_quote": {
+      const from = writer.out.length
+      inline(writer, elementsOf(element))
+      return prefixLines(writer, from, "> ", "> ")
+    }
+    case "rich_text_list": {
+      const indent = "  ".repeat(typeof element.indent === "number" ? Math.max(0, element.indent) : 0)
+      const ordered = element.style === "ordered"
+      const offset = typeof element.offset === "number" ? element.offset : 0
+      elementsOf(element).forEach((item, index) => {
+        if (index > 0) write(writer, "\n")
+        const marker = ordered ? `${offset + index + 1}. ` : "- "
+        const from = writer.out.length
+        block(writer, item)
+        prefixLines(writer, from, indent + marker, indent + " ".repeat(marker.length))
+      })
+      return
+    }
+  }
+  const text = stringOf(element, "text")
+  if (text !== undefined) write(writer, text)
+}
+
+/**
+ * The Markdown of a message's blocks, with the mentions at the offsets the
+ * renderer wrote. A mention is a `user`, `usergroup`, `channel` or
+ * `broadcast` element outside code. Blocks other than `rich_text` give
+ * their `text` when it is a string, and nothing otherwise.
+ *
+ * @internal
+ */
+export const render = (blocks: ReadonlyArray, botUserId: string): {
+  readonly text: string
+  readonly mentions: ReadonlyArray
+} => {
+  const writer: Writer = { out: "", mentions: [], botUserId }
+  for (const item of blocks) {
+    if (!isObject(item)) continue
+    if (item.type === "rich_text") {
+      for (const element of elementsOf(item)) {
+        newline(writer)
+        block(writer, element)
+      }
+    } else {
+      const text = stringOf(item, "text")
+      if (text !== undefined && text !== "") {
+        newline(writer)
+        write(writer, text)
+      }
+    }
+  }
+  return { text: writer.out, mentions: writer.mentions }
+}
diff --git a/packages/chat/slack/src/internal/text.ts b/packages/chat/slack/src/internal/text.ts
new file mode 100644
index 00000000000..db68b15479d
--- /dev/null
+++ b/packages/chat/slack/src/internal/text.ts
@@ -0,0 +1,202 @@
+/**
+ * The `text` the adapter sends beside a `markdown` block on
+ * `chat.postMessage` and `chat.update`. Slack decides who a message
+ * mentions from this field, not from the blocks, so the adapter always
+ * builds it itself: Slack's own would carry every token intact.
+ */
+import * as Escape from "./escape.ts"
+import { codePoints } from "./length.ts"
+
+/**
+ * The budget for `text` on `chat.postMessage`, in code points. Slack cuts a
+ * longer one there without an error, and the cut can split an entity or a
+ * token.
+ *
+ * @internal
+ */
+export const postTextLength = 16_000
+
+/**
+ * The budget for `text` on `chat.update`, in UTF-8 bytes. Slack refuses a
+ * `text` over 4,000 bytes with `msg_too_long`.
+ *
+ * Provisional: whether Slack checks the 4,000 before or after it rewrites the
+ * text (it wraps a URL in `<…>`) is not known yet, so this keeps a reserve.
+ *
+ * @internal
+ */
+export const updateTextBytes = 3_800
+
+/** @internal */
+export interface Budget {
+  readonly unit: "codePoints" | "utf8"
+  readonly limit: number
+}
+
+/** @internal */
+export const postBudget: Budget = { unit: "codePoints", limit: postTextLength }
+
+/** @internal */
+export const updateBudget: Budget = { unit: "utf8", limit: updateTextBytes }
+
+/** @internal */
+export const utf8Bytes = (text: string): number => {
+  let count = 0
+  for (let i = 0; i < text.length; i++) {
+    const code = text.charCodeAt(i)
+    if (code < 0x80) count += 1
+    else if (code < 0x800) count += 2
+    else if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {
+      const low = text.charCodeAt(i + 1)
+      if (low >= 0xdc00 && low <= 0xdfff) {
+        count += 4
+        i++
+      } else {
+        count += 3
+      }
+    } else {
+      // A lone surrogate goes out as U+FFFD, which is three bytes too.
+      count += 3
+    }
+  }
+  return count
+}
+
+/** @internal */
+export const cost = (text: string, unit: Budget["unit"]): number => unit === "utf8" ? utf8Bytes(text) : codePoints(text)
+
+const marker = "…"
+const separator = " "
+
+let segmenter: Intl.Segmenter | undefined
+
+const entity = /&(?:lt|gt|amp);/g
+
+/** @internal */
+export interface Built {
+  readonly text: string
+  /** Allowed tokens that a cut had no room for. */
+  readonly dropped: number
+}
+
+/**
+ * Builds the `text` for a Markdown body and cuts it to `budget`.
+ *
+ * - Every `<`, `>` and `&` is an entity, in code too. The tokens the notify
+ *   options allow, outside code, stay intact, as they do in the block.
+ * - Past the budget, the text is cut on a grapheme cluster boundary that
+ *   splits no entity and no token, and ends in `…`. Each allowed token not
+ *   in the kept part is appended once, in order, after a space. The marker
+ *   and the spaces come out of the budget.
+ * - When the tokens alone don't fit, those that fit are kept and the rest
+ *   counted in `dropped`.
+ *
+ * @internal
+ */
+export const build = (markdown: string, notify: Escape.Notify, budget: Budget): Built => {
+  const spans: Array = []
+  const text = Escape.escape(markdown, notify, {
+    flush: true,
+    entities: true,
+    onToken: (start, end) => spans.push([start, end])
+  }).sent
+  const tokens = spans.map(([start, end]) => text.slice(start, end))
+  if (cost(text, budget.unit) <= budget.limit) return { text, dropped: 0 }
+
+  // Offsets inside an entity or a token, where no cut may fall.
+  const inside = new Uint8Array(text.length + 1)
+  const atomic = (start: number, end: number) => inside.fill(1, start + 1, end)
+  for (const [start, end] of spans) atomic(start, end)
+  entity.lastIndex = 0
+  for (let match = entity.exec(text); match !== null; match = entity.exec(text)) {
+    atomic(match.index, match.index + match[0].length)
+  }
+
+  // The tail is the marker plus each distinct token not yet in the head.
+  const distinct = [...new Set(tokens)]
+  const unit = budget.unit
+  const tokenCost = (token: string) => cost(separator + token, unit)
+  let tail = cost(marker, unit)
+  for (const token of distinct) tail += tokenCost(token)
+
+  // Every code point boundary outside an entity or a token where the head
+  // and the tail fit, from the start until the head alone is over.
+  const candidates: Array = []
+  const inHead = new Set()
+  let head = 0
+  let span = 0
+  let i = 0
+  for (;;) {
+    for (; span < spans.length && spans[span][1] <= i; span++) {
+      const token = tokens[span]
+      if (!inHead.has(token)) {
+        inHead.add(token)
+        tail -= tokenCost(token)
+      }
+    }
+    if (inside[i] === 0 && head + tail <= budget.limit) candidates.push(i)
+    if (i >= text.length) break
+    const code = text.charCodeAt(i)
+    const pair = code >= 0xd800 && code <= 0xdbff && i + 1 < text.length &&
+      text.charCodeAt(i + 1) >= 0xdc00 && text.charCodeAt(i + 1) <= 0xdfff
+    // A lone surrogate goes out as U+FFFD, three bytes.
+    head += unit === "codePoints" ? 1 : pair ? 4 : code < 0x80 ? 1 : code < 0x800 ? 2 : 3
+    i += pair ? 2 : 1
+    if (head > budget.limit) break
+  }
+
+  // The last of them on a grapheme cluster boundary.
+  segmenter ??= new Intl.Segmenter(undefined, { granularity: "grapheme" })
+  const segments = segmenter.segment(text)
+  let best = -1
+  for (let k = candidates.length - 1; k >= 0; k--) {
+    const at = candidates[k]
+    if (at === 0 || segments.containing(at)!.index === at) {
+      best = at
+      break
+    }
+  }
+
+  if (best >= 0) {
+    const kept = text.slice(0, best)
+    let out = kept + marker
+    for (const token of distinct) if (!kept.includes(token)) out += separator + token
+    return { text: out, dropped: 0 }
+  }
+  // Not even the tokens fit: keep those that do, in order.
+  let out = marker
+  let used = cost(marker, unit)
+  let dropped = 0
+  for (const token of distinct) {
+    const extra = tokenCost(token)
+    if (used + extra <= budget.limit) {
+      out += separator + token
+      used += extra
+    } else {
+      dropped++
+    }
+  }
+  return { text: out, dropped }
+}
+
+/** @internal */
+export interface Body {
+  /** The Markdown as sent in the block, for the length check. */
+  readonly sent: string
+  readonly blocks: ReadonlyArray<{ readonly type: "markdown"; readonly text: string }>
+  readonly text: string
+  readonly dropped: number
+}
+
+/**
+ * The content of a `chat.postMessage` or `chat.update`: the Markdown as one
+ * `markdown` block, escaped as `markdown_text` was, and the `text` from
+ * `build`.
+ *
+ * @internal
+ */
+export const body = (markdown: string, notify: Escape.Notify, budget: Budget): Body => {
+  const sent = Escape.escape(markdown, notify, { flush: true }).sent
+  const built = build(markdown, notify, budget)
+  return { sent, blocks: [{ type: "markdown", text: sent }], text: built.text, dropped: built.dropped }
+}
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 0ac65ac45c5..93c8f88b779 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -27,19 +27,20 @@ const reason = (effect: Effect.Effect) =>
   )
 
 describe("post", () => {
-  it.effect("sends escaped markdown_text with unfurls off", () => {
+  it.effect("sends a markdown block and an escaped text, with unfurls off", () => {
     const fake = makeFake({ "chat.postMessage": posted("1794509200.000100") })
     return run(
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const result = yield* slack.post(replyThread, { markdown: "hi <@U1> `<@U1>`" })
+        const result = yield* slack.post(replyThread, { markdown: "hi <@U1> `<@U1>` & >" })
         assert.strictEqual(result.id, "1794509200.000100")
         assert.deepStrictEqual(result.thread, replyThread)
         assert.deepStrictEqual(fake.called("chat.postMessage")[0].params, {
           channel,
           thread_ts: root,
-          markdown_text: "hi <@U1> `<@U1>`",
+          blocks: JSON.stringify([{ type: "markdown", text: "hi <@U1> `<@U1>` & >" }]),
+          text: "hi <@U1> `<@U1>` & >",
           unfurl_links: "false",
           unfurl_media: "false"
         })
@@ -58,7 +59,8 @@ describe("post", () => {
           SlackChat.withPostOptions({ unfurl: true })
         )
         const params = fake.called("chat.postMessage")[0].params
-        assert.strictEqual(params.markdown_text, "hi <@U1> <@U2>")
+        assert.deepStrictEqual(JSON.parse(params.blocks), [{ type: "markdown", text: "hi <@U1> <@U2>" }])
+        assert.strictEqual(params.text, "hi <@U1> <@U2>")
         assert.strictEqual(params.unfurl_links, "true")
         assert.strictEqual(params.unfurl_media, "true")
         assert.isUndefined(params.thread_ts)
@@ -88,6 +90,42 @@ describe("post", () => {
     )
   })
 
+  it.effect("never sends an empty text: a post or edit with no Markdown fails before the call", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        assert.deepStrictEqual(yield* reason(slack.post(channelThread, { markdown: "" })), {
+          op: "post",
+          tag: "InvalidRequest",
+          detail: "no_text",
+          retry: "denied"
+        })
+        assert.strictEqual((yield* reason(slack.edit(channelThread, "1.2", { markdown: "" }))).detail, "no_text")
+        assert.strictEqual(fake.calls.length, 0)
+      })
+    )
+  })
+
+  it.effect("an edit's text is cut to 3,800 bytes and keeps its allowed tokens", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        yield* slack.edit(channelThread, "1.2", { markdown: "<@U1> " + "é".repeat(5_000) + " <@U2>" }).pipe(
+          SlackChat.withPostOptions({ notify: { users: ["U1", "U2"] } })
+        )
+        const params = fake.called("chat.update")[0].params
+        assert.strictEqual(JSON.parse(params.blocks)[0].text, "<@U1> " + "é".repeat(5_000) + " <@U2>")
+        assert.isTrue(params.text.startsWith("<@U1> éé"))
+        assert.isTrue(params.text.endsWith("é… <@U2>"))
+        assert.isAtMost(new TextEncoder().encode(params.text).length, 3_800)
+      })
+    )
+  })
+
   it.effect("leaves the emoji count to Slack", () => {
     const fake = makeFake({
       "chat.postMessage": [posted("1794509200.000100"), { ok: false, error: "msg_blocks_too_long" }]
diff --git a/packages/chat/slack/test/emoji.test.ts b/packages/chat/slack/test/emoji.test.ts
index 2d990a491be..7fd8b18bb26 100644
--- a/packages/chat/slack/test/emoji.test.ts
+++ b/packages/chat/slack/test/emoji.test.ts
@@ -6,31 +6,46 @@ interface Row {
   readonly names: ReadonlyArray
   /** Primary Slack name, with skin-tone suffixes for variations */
   readonly name: string
+  /** How many skin tones the name carries */
+  readonly tones: number
+  readonly emoji: string
   /** Whether the emoji is also written without U+FE0F */
   readonly nonQualified: boolean
 }
 
+const decode = (hex: string): string => String.fromCodePoint(...hex.split("-").map((point) => parseInt(point, 16)))
+
 // Read the generated table directly, so these tests do not trust emoji.ts to parse it.
 const rows: ReadonlyArray = emojiData.split("\n").flatMap((line) => {
-  const [names, , nonQualified, groups] = line.split("|")
+  const [names, unified, nonQualified, groups] = line.split("|")
   const aliases = names.split(",")
-  const base: Row = { names: aliases, name: aliases[0], nonQualified: nonQualified === "!" }
+  const base: Row = {
+    names: aliases,
+    name: aliases[0],
+    tones: 0,
+    emoji: decode(unified),
+    nonQualified: nonQualified === "!"
+  }
   const variations = groups === undefined ? [] : groups.split(";").flatMap((group) => {
-    const [keys, , variationNonQualified] = group.split(":")
-    return keys.split(",").map((tones): Row => ({
-      names: [],
-      name: aliases[0] + [...tones].map((tone) => "::skin-tone-" + tone).join(""),
-      nonQualified: variationNonQualified === "!"
-    }))
+    const [keys, template, variationNonQualified] = group.split(":")
+    return keys.split(",").map((tones): Row => {
+      let index = 0
+      return {
+        names: [],
+        name: aliases[0] + [...tones].map((tone) => "::skin-tone-" + tone).join(""),
+        tones: tones.length,
+        emoji: decode(template.replace(/\*/g, () => (0x1f3fb + Number(tones[index++]) - 2).toString(16))),
+        nonQualified: variationNonQualified === "!"
+      }
+    })
   })
   return [base, ...variations]
 })
 
 // Every emoji string the table defines, with its primary Slack name.
-const sequences: ReadonlyArray = rows.flatMap((row) => {
-  const emoji = fromName(row.name)!
-  return row.nonQualified ? [[emoji, row.name], [emoji.replaceAll("\uFE0F", ""), row.name]] : [[emoji, row.name]]
-})
+const sequences: ReadonlyArray = rows.flatMap((row) =>
+  row.nonQualified ? [[row.emoji, row.name], [row.emoji.replaceAll("\uFE0F", ""), row.name]] : [[row.emoji, row.name]]
+)
 
 describe("emoji", () => {
   it("holds every emoji, name and skin tone variation from emoji-data v16.0.0", () => {
@@ -61,23 +76,23 @@ describe("emoji", () => {
       assert.strictEqual(fromName("woman-running::skin-tone-6"), "🏃🏿‍♀️")
     })
 
-    it("resolves two tones on multi person emoji", () => {
-      assert.strictEqual(fromName("people_holding_hands::skin-tone-2::skin-tone-5"), "🧑🏻‍🤝‍🧑🏾")
-      assert.strictEqual(fromName("handshake::skin-tone-2::skin-tone-5"), "🫱🏻‍🫲🏾")
+    it("gives none for a name with two tones, which no recording shows", () => {
+      assert.strictEqual(fromName("people_holding_hands::skin-tone-2::skin-tone-5"), undefined)
+      assert.strictEqual(fromName("handshake::skin-tone-2::skin-tone-5"), undefined)
+      assert.strictEqual(fromName("handshake::skin-tone-3::skin-tone-3"), undefined)
     })
 
-    it("treats one tone and two equal tones alike", () => {
+    it("gives a single tone only where the table has that one tone", () => {
       assert.strictEqual(fromName("handshake::skin-tone-3"), "🤝🏼")
-      assert.strictEqual(fromName("handshake::skin-tone-3::skin-tone-3"), "🤝🏼")
-      assert.strictEqual(fromName("people_holding_hands::skin-tone-4"), "🧑🏽‍🤝‍🧑🏽")
-      assert.strictEqual(fromName("people_holding_hands::skin-tone-4::skin-tone-4"), "🧑🏽‍🤝‍🧑🏽")
+      // Keyed by two tones upstream only.
+      assert.strictEqual(fromName("people_holding_hands::skin-tone-4"), undefined)
     })
 
-    it("resolves every alias and variation in the table", () => {
+    it("resolves every alias and every one-tone variation in the table", () => {
       for (const row of rows) {
-        const emoji = fromName(row.name)
-        assert.isDefined(emoji, row.name)
-        for (const alias of row.names) assert.strictEqual(fromName(alias), emoji, alias)
+        if (row.tones > 1) continue
+        assert.strictEqual(fromName(row.name), row.emoji, row.name)
+        for (const alias of row.names) assert.strictEqual(fromName(alias), row.emoji, alias)
       }
     })
 
@@ -122,11 +137,18 @@ describe("emoji", () => {
       assert.strictEqual(toName("👍 "), undefined)
     })
 
-    it("round trips with fromName for every emoji in the table", () => {
+    it("names every emoji in the table", () => {
       for (const [emoji, name] of sequences) {
         assert.strictEqual(toName(emoji), name)
       }
     })
+
+    it("round trips with fromName for every emoji with at most one tone", () => {
+      for (const row of rows) {
+        if (row.tones > 1) continue
+        assert.strictEqual(fromName(toName(row.emoji)!), row.emoji, row.name)
+      }
+    })
   })
 
   describe("blocksCost", () => {
diff --git a/packages/chat/slack/test/events.test.ts b/packages/chat/slack/test/events.test.ts
index 9e51107dbd7..a14d0208ac6 100644
--- a/packages/chat/slack/test/events.test.ts
+++ b/packages/chat/slack/test/events.test.ts
@@ -152,10 +152,10 @@ describe("captured Events API deliveries", () => {
       }
     }))
 
-  it.live("a /me line keeps its labelled mention token", () =>
+  it.live("the bot's own /me line reads back from its blocks, with the token the renderer wrote", () =>
     Effect.gen(function*() {
       const event = created((yield* deliveries("me-message"))[0])
-      assert.deepStrictEqual(mentions(event), selfMention("|janitor2"))
+      assert.deepStrictEqual(mentions(event), selfMention())
     }))
 
   it.live("a file share with a mention in its comment", () =>
diff --git a/packages/chat/slack/test/fixtures/synthetic/own-messages.json b/packages/chat/slack/test/fixtures/synthetic/own-messages.json
new file mode 100644
index 00000000000..751f3caeff4
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/synthetic/own-messages.json
@@ -0,0 +1,366 @@
+{
+  "synthetic": "Hand-written, not read back from Slack: the test workspace was not available for EFF-3750. The shapes follow the recorded rich_text in ../recorded and Slack's rich_text docs. Replace each with a recording when one is made.",
+  "case": "Stage 0 fixture 13: the bot's own posts read back, for the constructs and message kinds the recordings lack (strike, quotes, lists, named links, broadcasts, user groups, emoji, buttons, file-only).",
+  "cases": [
+    {
+      "name": "strike, bold italic and a code span holding a backtick",
+      "markdown": "~~gone~~ ***both*** ``a ` b``",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000100",
+        "text": "~~gone~~ ***both*** ``a ` b``",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_section",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "gone",
+                    "style": {
+                      "strike": true
+                    }
+                  },
+                  {
+                    "type": "text",
+                    "text": " "
+                  },
+                  {
+                    "type": "text",
+                    "text": "both",
+                    "style": {
+                      "bold": true,
+                      "italic": true
+                    }
+                  },
+                  {
+                    "type": "text",
+                    "text": " "
+                  },
+                  {
+                    "type": "text",
+                    "text": "a ` b",
+                    "style": {
+                      "code": true
+                    }
+                  }
+                ]
+              }
+            ]
+          }
+        ]
+      }
+    },
+    {
+      "name": "a quote over two lines with a mention",
+      "markdown": "> quoted <@U0CCLMD4S1L>\n> second line",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000200",
+        "text": "> quoted <@U0CCLMD4S1L>\n> second line",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_quote",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "quoted "
+                  },
+                  {
+                    "type": "user",
+                    "user_id": "U0CCLMD4S1L"
+                  },
+                  {
+                    "type": "text",
+                    "text": "\nsecond line"
+                  }
+                ]
+              }
+            ]
+          }
+        ]
+      }
+    },
+    {
+      "name": "a bullet list with a nested item, then an ordered list from 3",
+      "markdown": "- one\n  - nested\n- two\n3. three\n4. four",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000300",
+        "text": "- one\n  - nested\n- two\n3. three\n4. four",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_list",
+                "style": "bullet",
+                "indent": 0,
+                "elements": [
+                  {
+                    "type": "rich_text_section",
+                    "elements": [
+                      {
+                        "type": "text",
+                        "text": "one"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "type": "rich_text_list",
+                "style": "bullet",
+                "indent": 1,
+                "elements": [
+                  {
+                    "type": "rich_text_section",
+                    "elements": [
+                      {
+                        "type": "text",
+                        "text": "nested"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "type": "rich_text_list",
+                "style": "bullet",
+                "indent": 0,
+                "elements": [
+                  {
+                    "type": "rich_text_section",
+                    "elements": [
+                      {
+                        "type": "text",
+                        "text": "two"
+                      }
+                    ]
+                  }
+                ]
+              },
+              {
+                "type": "rich_text_list",
+                "style": "ordered",
+                "indent": 0,
+                "offset": 2,
+                "elements": [
+                  {
+                    "type": "rich_text_section",
+                    "elements": [
+                      {
+                        "type": "text",
+                        "text": "three"
+                      }
+                    ]
+                  },
+                  {
+                    "type": "rich_text_section",
+                    "elements": [
+                      {
+                        "type": "text",
+                        "text": "four"
+                      }
+                    ]
+                  }
+                ]
+              }
+            ]
+          }
+        ]
+      }
+    },
+    {
+      "name": "a named link, a broadcast, a user group, a toned emoji and a custom one",
+      "markdown": "see [the docs](https://effect.website)   👍🏼 :party-parrot:",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000400",
+        "text": "see <https://effect.website|the docs>   :+1::skin-tone-3: :party-parrot:",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_section",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "see "
+                  },
+                  {
+                    "type": "link",
+                    "url": "https://effect.website",
+                    "text": "the docs"
+                  },
+                  {
+                    "type": "text",
+                    "text": " "
+                  },
+                  {
+                    "type": "broadcast",
+                    "range": "here"
+                  },
+                  {
+                    "type": "text",
+                    "text": " "
+                  },
+                  {
+                    "type": "usergroup",
+                    "usergroup_id": "S0123ABC"
+                  },
+                  {
+                    "type": "text",
+                    "text": " "
+                  },
+                  {
+                    "type": "emoji",
+                    "name": "+1",
+                    "unicode": "1f44d-1f3fc",
+                    "skin_tone": 3
+                  },
+                  {
+                    "type": "text",
+                    "text": " "
+                  },
+                  {
+                    "type": "emoji",
+                    "name": "party-parrot"
+                  }
+                ]
+              }
+            ]
+          }
+        ]
+      }
+    },
+    {
+      "name": "with buttons: the actions block adds nothing to text",
+      "markdown": "Pick one",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000500",
+        "text": "Pick one",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_section",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "Pick one"
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "type": "actions",
+            "block_id": "act",
+            "elements": [
+              {
+                "type": "button",
+                "action_id": "a1",
+                "value": "yes",
+                "text": {
+                  "type": "plain_text",
+                  "text": "Approve"
+                }
+              },
+              {
+                "type": "button",
+                "action_id": "a2",
+                "value": "no",
+                "text": {
+                  "type": "plain_text",
+                  "text": "Deny"
+                }
+              }
+            ]
+          }
+        ]
+      }
+    },
+    {
+      "name": "file-only: the placeholder is the escaped file names",
+      "markdown": "report.pdf, data.csv",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000600",
+        "text": "report.pdf, data.csv",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_section",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "report.pdf, data.csv"
+                  }
+                ]
+              }
+            ]
+          }
+        ],
+        "files": [
+          {
+            "id": "F0SYN00001",
+            "name": "report.pdf",
+            "title": "report.pdf",
+            "mimetype": "application/pdf",
+            "size": 1024,
+            "url_private": "https://files.slack.com/files-pri/T05479Z6JBW-F0SYN00001/report.pdf"
+          },
+          {
+            "id": "F0SYN00002",
+            "name": "data.csv",
+            "title": "data.csv",
+            "mimetype": "text/csv",
+            "size": 12,
+            "url_private": "https://files.slack.com/files-pri/T05479Z6JBW-F0SYN00002/data.csv"
+          }
+        ]
+      }
+    }
+  ]
+}
diff --git a/packages/chat/slack/test/live.test.ts b/packages/chat/slack/test/live.test.ts
index 5cf50c115c4..762f433eac1 100644
--- a/packages/chat/slack/test/live.test.ts
+++ b/packages/chat/slack/test/live.test.ts
@@ -10,7 +10,7 @@
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import * as SlackWebApi from "@effect/chat-slack/SlackWebApi"
-import { describe, it } from "@effect/vitest"
+import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { conformance } from "effect/chat/ChatTest"
@@ -20,6 +20,7 @@ import * as FetchHttpClient from "effect/http/FetchHttpClient"
 import * as Layer from "effect/Layer"
 import * as Redacted from "effect/Redacted"
 import * as Semaphore from "effect/Semaphore"
+import { adapter } from "./utils.ts"
 
 const botToken = process.env.SLACK_LIVE_BOT_TOKEN
 const userToken = process.env.SLACK_LIVE_USER_TOKEN
@@ -84,3 +85,81 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
     it.live(name, () => rule.pipe(Effect.provide(layer), Semaphore.withPermits(one, 1)), 600_000)
   }
 })
+
+/**
+ * The Slack mention rule, live. It posts and edits mention-looking strings,
+ * in prose and in code, with the entity forms and ``, reads each
+ * message back and asserts the stored `text` holds no intact token. With
+ * `notify` allowed it asserts the token is in `text` and the element is in
+ * the blocks.
+ *
+ * It is a proxy: Slack decides a mention from the stored `text`, which was
+ * checked against one client's Activity feed (EFF-3730, EFF-3736). The
+ * stream inputs and the file posts belong to the stream and file routes, and
+ * are not here yet. The same assertions run in CI on the request bodies, in
+ * `text.test.ts`.
+ */
+describe.skipIf(botToken === undefined || teamId === undefined || channel === undefined)("live mention rule", () => {
+  const layer = SlackChat.layer({ botToken: Redacted.make(botToken!), teamId: teamId! }).pipe(
+    Layer.provideMerge(Chat.layer),
+    Layer.provide(FetchHttpClient.layer)
+  )
+  const token = /<(?:@[UW][A-Z0-9]+|#[CG][A-Z0-9]+|!subteam\^[A-Z0-9]+|!(?:here|channel|everyone))(?:\|[^<>]*)?>/g
+
+  it.live("no token is stored unless allowed, by post and by edit", () =>
+    Effect.gen(function*() {
+      const api = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) })
+      const self = field(yield* api.call("auth.test", {}), "user_id") as string
+      const slack = yield* adapter
+      const thread = SlackChat.thread({ team: teamId!, channel: channel! })
+      const stored = (ts: string) =>
+        api.call("conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 1 }).pipe(
+          Effect.map((answer) => (field(answer, "messages") as Array).find((message) => message.ts === ts))
+        )
+      const elements = (blocks: unknown): Array =>
+        Array.isArray(blocks) ? blocks.flatMap((block) => [block, ...elements(field(block, "elements"))]) : []
+      const inputs = [
+        `prose <@${self}> and  and `,
+        `inline \`<@${self}>\` and a fence\n\`\`\`\n<@${self}> \n\`\`\``,
+        `entities <@${self}> <@${self}> <@${self}> <@${self}> <!channel>`,
+        `no semicolon <@${self}> <@${self}> <@${self}>`,
+        `an unclosed fence\n\`\`\`\n<@${self}>`,
+        `nested \`\`a \` <@${self}> \`\` backticks`
+      ]
+      const posted: Array = []
+      const noToken = Effect.fnUntraced(function*(ts: string, label: string) {
+        const message = yield* stored(ts)
+        assert.deepStrictEqual(message.text.match(token), null, label)
+      })
+      for (const markdown of inputs) {
+        const post = yield* slack.post(thread, { markdown })
+        posted.push(post.id)
+        yield* noToken(post.id, `post ${markdown}`)
+      }
+      const edited = yield* slack.post(thread, { markdown: "to be edited" })
+      posted.push(edited.id)
+      for (const markdown of inputs) {
+        yield* slack.edit(thread, edited.id, { markdown })
+        yield* noToken(edited.id, `edit ${markdown}`)
+      }
+
+      // Allowed: the token is in text and the element in the blocks, by post
+      // and by a long edit whose text is cut.
+      const allowed = SlackChat.withPostOptions({ notify: { users: [self] } })
+      const check = Effect.fnUntraced(function*(ts: string, label: string) {
+        const message = yield* stored(ts)
+        assert.include(message.text, `<@${self}>`, label)
+        assert.isTrue(
+          elements(message.blocks).some((element) => element.type === "user" && element.user_id === self),
+          label
+        )
+      })
+      const allowedPost = yield* slack.post(thread, { markdown: `allowed <@${self}>` }).pipe(allowed)
+      posted.push(allowedPost.id)
+      yield* check(allowedPost.id, "post")
+      yield* slack.edit(thread, allowedPost.id, { markdown: "x".repeat(6_000) + ` <@${self}>` }).pipe(allowed)
+      yield* check(allowedPost.id, "long edit")
+
+      for (const id of posted) yield* slack.delete(thread, id).pipe(Effect.ignore)
+    }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)), 600_000)
+})
diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts
index ad53438fae6..ae70b114901 100644
--- a/packages/chat/slack/test/normalize.test.ts
+++ b/packages/chat/slack/test/normalize.test.ts
@@ -338,7 +338,10 @@ describe("reactions", () => {
         ["+1", "👍"],
         ["thumbsup", "👍"],
         ["+1::skin-tone-3", "👍🏼"],
-        ["party-parrot", "custom:party-parrot"]
+        ["party-parrot", "custom:party-parrot"],
+        // Synthetic: no recording has a two-tone reaction, so its name is
+        // not resolved and reads as custom (stage 0 fixture 16).
+        ["handshake::skin-tone-2::skin-tone-5", "custom:handshake::skin-tone-2::skin-tone-5"]
       ]
       for (const [name, emoji] of cases) {
         const added = SlackChat.normalize(reaction("reaction_added", name), context)
diff --git a/packages/chat/slack/test/richText.test.ts b/packages/chat/slack/test/richText.test.ts
new file mode 100644
index 00000000000..3feb07697bb
--- /dev/null
+++ b/packages/chat/slack/test/richText.test.ts
@@ -0,0 +1,107 @@
+import * as SlackChat from "@effect/chat-slack/SlackChat"
+import { assert, describe, it } from "@effect/vitest"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { checkMessage } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import * as fs from "node:fs"
+import { botUserId, checkOptions, fixture, messageEnvelope, team } from "./utils.ts"
+
+const context = { teamId: team, botUserId }
+
+const read = Effect.fnUntraced(function*(message: Record) {
+  const events = SlackChat.normalize(messageEnvelope(message), context)
+  assert.strictEqual(events.length, 1)
+  const event = events[0] as ChatEvent.MessageCreated
+  assert.strictEqual(event._tag, "MessageCreated")
+  // Includes that each mention's span parses as its token.
+  yield* checkMessage(event.message, checkOptions)
+  return event.message
+})
+
+/** A message a recorded read returned, by ts, edited or not. */
+const recorded = (name: string, ts: string, edited = false): Record => {
+  for (const call of fixture(name).calls) {
+    for (const message of call.response?.messages ?? []) {
+      if (message.ts === ts && (message.edited !== undefined) === edited) return message
+    }
+  }
+  throw new Error(`no message ${ts} in ${name}`)
+}
+
+const synthetic: {
+  readonly synthetic: string
+  readonly cases: ReadonlyArray<{ readonly name: string; readonly markdown: string; readonly message: any }>
+} = JSON.parse(fs.readFileSync(new URL("./fixtures/synthetic/own-messages.json", import.meta.url), "utf8"))
+
+describe("the bot's own messages read back", () => {
+  it.effect("give the Markdown they were posted with, from recordings", () =>
+    Effect.gen(function*() {
+      // The fixture posted raw markdown_text with `<not a tag>` typed
+      // as entities. Through the adapter the same message is ``.
+      const mentionsPost = fixture("markdown-mentions").calls[0].request.markdown_text as string
+      const cases: ReadonlyArray = [
+        ["thread-root-before-after", "1794509000.352789", "Fixture: thread root (no mentions). Some *markdown* here."],
+        ["markdown-mentions", "1794509003.143939", mentionsPost.replace("<not a tag>", "")],
+        ["thread-broadcast", "1794509004.811879", `Fixture: broadcast reply to <@${botUserId}>`],
+        ["file-share", "1794509028.831169", `Fixture: file for <@${botUserId}>`],
+        // Two appends.
+        ["stream", "1794509111.134189", `Streaming **part one**. Part two with <@${botUserId}>.`],
+        ["unfurl-edit", "1794509128.969019", "now with a link: https://github.com/Effect-TS/effect", true],
+        ["unfurl-edit", "1794509129.029199", "Fixture control: https://github.com/Effect-TS/effect"]
+      ]
+      for (const [name, ts, markdown, edited] of cases) {
+        const message = recorded(name, ts, edited)
+        const read_ = yield* read(message)
+        assert.strictEqual(read_.text, markdown, name)
+        // Slack's own field stays on raw.
+        assert.strictEqual((read_.raw as any).text, message.text, name)
+      }
+      // Slack stored the markdown-mentions text with its fence on one line.
+      assert.notStrictEqual(recorded("markdown-mentions", "1794509003.143939").text, mentionsPost)
+    }))
+
+  it.effect("mentions are the elements outside code, at the offsets the renderer wrote", () =>
+    Effect.gen(function*() {
+      const message = yield* read(recorded("markdown-mentions", "1794509003.143939"))
+      // The inline code and the fence hold the same tokens, as literals.
+      assert.deepStrictEqual(message.mentions.map((mention) => [mention.kind, mention.id, mention.isSelf]), [
+        ["user", botUserId, true],
+        ["channel", "C0CH1LGJ4F3", false]
+      ])
+    }))
+
+  it.effect("a me_message drops the label Slack wrote into the token", () =>
+    Effect.gen(function*() {
+      const stored = recorded("me-message", "1794509006.465359")
+      assert.strictEqual(stored.text, `Fixture: me message waves at <@${botUserId}|janitor2>`)
+      const message = yield* read(stored)
+      assert.strictEqual(message.text, `Fixture: me message waves at <@${botUserId}>`)
+    }))
+
+  it.effect("an agent DM thread root", () =>
+    Effect.gen(function*() {
+      const stored = recorded("assistant-thread-root", "1794454526.171439")
+      assert.isDefined(stored.agent_session)
+      const message = yield* read(stored)
+      assert.strictEqual(message.text, stored.text)
+      assert.isTrue(message.author.isSelf)
+    }))
+
+  it.effect("give the Markdown they were posted with, from synthetic messages", () =>
+    Effect.gen(function*() {
+      assert.match(synthetic.synthetic, /^Hand-written, not read back from Slack/)
+      for (const { markdown, message, name } of synthetic.cases) {
+        assert.strictEqual((yield* read(message)).text, markdown, name)
+      }
+    }))
+
+  it.effect("someone else's message keeps Slack's text", () =>
+    Effect.gen(function*() {
+      for (const { message, name } of synthetic.cases) {
+        const { app_id: _app, bot_id: _bot, ...rest } = message
+        const other = { ...rest, user: "U080YLYB277" }
+        const read_ = yield* read(other)
+        assert.strictEqual(read_.text, message.text, name)
+      }
+    }))
+})
diff --git a/packages/chat/slack/test/text.test.ts b/packages/chat/slack/test/text.test.ts
new file mode 100644
index 00000000000..16f04b13762
--- /dev/null
+++ b/packages/chat/slack/test/text.test.ts
@@ -0,0 +1,152 @@
+import * as Escape from "@effect/chat-slack/internal/escape"
+import * as Text from "@effect/chat-slack/internal/text"
+import * as SlackChat from "@effect/chat-slack/SlackChat"
+import { assert, describe, it } from "@effect/vitest"
+import * as Effect from "effect/Effect"
+import { adapter, channel, makeFake, slackLayer, team } from "./utils.ts"
+
+const codePoints = (text: string) => [...text].length
+const bytes = (text: string) => new TextEncoder().encode(text).length
+const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
+const graphemes = (text: string) => [...segmenter.segment(text)]
+const isBoundary = (text: string, index: number) =>
+  index === text.length || segmenter.segment(text).containing(index)!.index === index
+
+describe("build", () => {
+  it("writes every <, > and & as an entity, in code too, and keeps allowed tokens", () => {
+    const built = Text.build("a <@U1> <@U2> `` & > ", { users: ["U1"], broadcast: true }, Text.postBudget)
+    assert.strictEqual(built.text, "a <@U1> <@U2> `<b>` & > ")
+    assert.strictEqual(built.dropped, 0)
+  })
+
+  it("cuts a post at 16,000 code points and an update at 3,800 bytes, marker included", () => {
+    assert.strictEqual(Text.build("a".repeat(16_000), {}, Text.postBudget).text, "a".repeat(16_000))
+    assert.strictEqual(Text.build("a".repeat(16_001), {}, Text.postBudget).text, "a".repeat(15_999) + "…")
+    // An astral letter is one code point and four bytes.
+    assert.strictEqual(Text.build("𝐚".repeat(16_001), {}, Text.postBudget).text, "𝐚".repeat(15_999) + "…")
+    // "…" is three bytes.
+    assert.strictEqual(Text.build("é".repeat(1_900), {}, Text.updateBudget).text, "é".repeat(1_900))
+    assert.strictEqual(Text.build("é".repeat(1_901), {}, Text.updateBudget).text, "é".repeat(1_898) + "…")
+  })
+
+  it("cuts on a grapheme cluster boundary and splits no entity", () => {
+    const family = "👨‍👩‍👧‍👦"
+    const cut = Text.build(family.repeat(200), {}, Text.updateBudget).text
+    assert.strictEqual(cut, family.repeat(151) + "…")
+    assert.strictEqual(graphemes(cut).length, 152)
+    assert.strictEqual(Text.build("&".repeat(4_000), {}, Text.postBudget).text, "&".repeat(3_199) + "…")
+    assert.strictEqual(Text.build("<".repeat(1_000), {}, Text.updateBudget).text, "<".repeat(949) + "…")
+  })
+
+  it("appends each allowed token not in the kept head once, in order", () => {
+    const notify = { users: ["U1", "U2", "U3"] }
+    const built = Text.build("<@U2> " + "x".repeat(20_000) + " <@U1> <@U3> <@U1> <@U2>", notify, Text.postBudget)
+    assert.isTrue(built.text.startsWith("<@U2> xxx"))
+    assert.isTrue(built.text.endsWith("x… <@U1> <@U3>"))
+    assert.strictEqual(codePoints(built.text), 16_000)
+    assert.strictEqual(built.dropped, 0)
+  })
+
+  it("never cuts inside a token", () => {
+    const built = Text.build("x".repeat(15_997) + "<@U1>" + "y".repeat(10), { users: ["U1"] }, Text.postBudget)
+    assert.strictEqual(built.text, "x".repeat(15_993) + "… <@U1>")
+  })
+
+  it("keeps the tokens that fit when the tokens alone don't, and counts the rest", () => {
+    const users = Array.from({ length: 500 }, (_, i) => `U${1_000 + i}`)
+    const built = Text.build(users.map((user) => `<@${user}>`).join(" "), { users }, Text.updateBudget)
+    // "…" is 3 bytes and each " <@U1xxx>" 9.
+    assert.strictEqual(built.dropped, 79)
+    assert.strictEqual(built.text, "…" + users.slice(0, 421).map((user) => ` <@${user}>`).join(""))
+    assert.isAtMost(bytes(built.text), Text.updateTextBytes)
+  })
+})
+
+/**
+ * The CI half of the Slack mention rule: the same assertions the live rule
+ * makes on stored messages, made here on the request bodies the adapter
+ * builds for `chat.postMessage` and `chat.update`. Stream appends are left
+ * to the stream's own rule.
+ */
+describe("request bodies", () => {
+  const thread = SlackChat.thread({ team, channel })
+  const allowed = { users: ["U1"], broadcast: true }
+  const allowedTokens = ["<@U1>", ""]
+
+  // Pieces that spell tokens, entity forms, code and multi-unit characters.
+  const alphabet = ["<", "@U1", "!here", ">", "&", "lt;", "`", "x", "👍🏽", "\n"]
+  const words = (length: number): Array =>
+    length === 0 ? [""] : words(length - 1).flatMap((word) => alphabet.map((piece) => word + piece))
+  const short = [1, 2, 3].flatMap(words)
+  const withToken = short.filter((word) => word.includes("<"))
+
+  /** Repeats `word` until the text is past both budgets while the block stays within 12,000. */
+  const long = (word: string, notify: Escape.Notify): string => {
+    const sent = (markdown: string) => codePoints(Escape.escape(markdown, notify, { flush: true }).sent)
+    let times = Math.floor(11_900 / sent(word))
+    while (sent(word.repeat(times)) > 12_000) times = Math.floor(times / 2)
+    return word.repeat(times)
+  }
+
+  const check = (op: "post" | "edit", markdown: string, notify: Escape.Notify, params: Record) => {
+    const label = `${op} ${JSON.stringify(markdown.slice(0, 40))} ${JSON.stringify(notify)}`
+    const block = JSON.parse(params.blocks)[0].text as string
+    const text = params.text
+    assert.isUndefined(params.markdown_text, label)
+    assert.isAbove(text.length, 0, label)
+    if (op === "post") assert.isAtMost(codePoints(text), Text.postTextLength, label)
+    else assert.isAtMost(bytes(text), Text.updateTextBytes, label)
+    // No token survives in text but an allowed one, and every & starts an entity.
+    let rest = text
+    for (const token of allowedTokens) rest = rest.replaceAll(token, "")
+    assert.notMatch(rest, /[<>]|&(?!lt;|gt;|amp;)/, label)
+    // An allowed token the block sends intact is in text too, cut or not.
+    for (const token of allowedTokens) {
+      if (block.includes(token)) assert.include(text, token, label)
+    }
+    // A cut is a prefix of the whole text, on a grapheme boundary and outside an entity.
+    const whole = Text.build(markdown, notify, { unit: "codePoints", limit: Infinity }).text
+    if (text !== whole) {
+      const head = text.slice(0, text.lastIndexOf("…"))
+      assert.isTrue(whole.startsWith(head), label)
+      assert.notMatch(head, /&[a-z]*$/, label)
+      assert.isTrue(isBoundary(whole, head.length), label)
+    }
+  }
+
+  it.effect("hold the mention, budget and cut rules over a generated alphabet", () => {
+    const fake = makeFake({ "chat.postMessage": { ok: true, channel, ts: "1.1" } })
+    return Effect.gen(function*() {
+      const slack = yield* adapter
+      let count = 0
+      let cuts = 0
+      for (const notify of [{}, allowed] as ReadonlyArray) {
+        const inputs = [
+          ...short,
+          ...[1, 2].flatMap(words).map((word) => long(word, notify)),
+          // 3,300 `&` are 16,500 code points of text, so a token in the word is past either cut.
+          ...(notify === allowed ? withToken.map((word) => "&".repeat(3_300) + word) : [])
+        ]
+        for (const markdown of inputs) {
+          for (const op of ["post", "edit"] as const) {
+            const before = fake.calls.length
+            // A new message id for each edit, so pacing never waits.
+            const write = op === "post"
+              ? slack.post(thread, { markdown })
+              : slack.edit(thread, `1.${count + 2}`, { markdown })
+            yield* write.pipe(SlackChat.withPostOptions({ notify }))
+            const call = fake.calls[fake.calls.length - 1]
+            assert.strictEqual(fake.calls.length, before + 1)
+            assert.strictEqual(call.method, op === "post" ? "chat.postMessage" : "chat.update")
+            check(op, markdown, notify, call.params)
+            if (call.params.text.includes("…")) cuts++
+            count++
+          }
+        }
+      }
+      assert.strictEqual(count, 2 * (2 * (short.length + 110) + withToken.length))
+      // The long inputs reach both budgets.
+      assert.isAbove(cuts, 2 * withToken.length)
+    }).pipe(Effect.provide(slackLayer(fake)))
+  }, 60_000)
+})

From 8ca808612f15adc1bb4f3b1c6ca60271c75076aa Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 06:41:59 +0000
Subject: [PATCH 23/89] Escape literal Markdown in Slack read-backs and restore
 the one-tone fallback

- Text elements escape Markdown syntax when rendered, and code spans keep
  a space at each end.
- A one-tone name resolves to the same tone twice where upstream keys an
  emoji only by two tones.
- The generated mention test only exempts tokens the current notify allows.
- Document why a lone hair component costs 4.
---
 packages/chat/slack/src/internal/emoji.ts     | 13 ++-
 packages/chat/slack/src/internal/richText.ts  | 72 ++++++++++++++---
 packages/chat/slack/test/emoji.test.ts        | 11 ++-
 .../test/fixtures/synthetic/own-messages.json | 80 ++++++++++++++++++-
 packages/chat/slack/test/text.test.ts         | 10 ++-
 5 files changed, 165 insertions(+), 21 deletions(-)

diff --git a/packages/chat/slack/src/internal/emoji.ts b/packages/chat/slack/src/internal/emoji.ts
index 952d59b3a1d..d94f1f1b0da 100644
--- a/packages/chat/slack/src/internal/emoji.ts
+++ b/packages/chat/slack/src/internal/emoji.ts
@@ -103,8 +103,9 @@ const SKIN_TONE = /^skin-tone-([2-6])$/
  *
  * Accepts any alias, with or without surrounding colons, followed by at most
  * one `::skin-tone-N` suffix (`+1::skin-tone-3`). The toned emoji is the
- * upstream `skin_variations` entry with that one tone, so `toName` on it
- * gives the name back. A tone the emoji does not have, and a name with two
+ * upstream `skin_variations` entry with that one tone, or, for a multi-person
+ * emoji upstream keys only by two tones (`people_holding_hands`), the entry
+ * with that tone twice. A tone the emoji does not have, and a name with two
  * tones, yield `undefined`: no recording shows what Slack sends for a
  * two-tone reaction.
  *
@@ -118,7 +119,9 @@ export const fromName = (name: string): string | undefined => {
   if (parts.length === 1) return entry.unified
   if (parts.length !== 2) return undefined
   const match = SKIN_TONE.exec(parts[1])
-  return match === null ? undefined : entry.variations.get(match[1])
+  if (match === null) return undefined
+  const tone = match[1]
+  return entry.variations.get(tone) ?? entry.variations.get(tone + tone)
 }
 
 /**
@@ -137,6 +140,10 @@ const COMBINING_ENCLOSING_KEYCAP = 0x20e3
 const ZERO_WIDTH_JOINER_COST = 10
 const COMBINING_ENCLOSING_KEYCAP_COST = 12
 const REGIONAL_INDICATOR_COST = 6
+// Slack charges a lone hair component 1 (the spec's four override rows), but
+// with this split measure 1 would charge seven hair sequences below their
+// names: 🧑‍🦱 would split as :adult: + joiner + 🦱 for 18 against Slack's 21.
+// 4 is the least that keeps every hair sequence at its name.
 const HAIR_COMPONENT_COST = 4
 
 const codePointCost = (codePoint: number, loneSurrogateCost: number): number => {
diff --git a/packages/chat/slack/src/internal/richText.ts b/packages/chat/slack/src/internal/richText.ts
index 18f005cc6f4..77484cf7922 100644
--- a/packages/chat/slack/src/internal/richText.ts
+++ b/packages/chat/slack/src/internal/richText.ts
@@ -66,7 +66,7 @@ const longestRun = (text: string, char: string): number => {
 
 /** One element's content: plain text, or a mention token. */
 type Piece =
-  | { readonly _tag: "text"; readonly text: string }
+  | { readonly _tag: "text"; readonly text: string; readonly markdown?: true }
   | { readonly _tag: "mention"; readonly token: string; readonly kind: Mention["kind"]; readonly id: string }
 
 const emojiText = (element: JsonObject): string => {
@@ -92,7 +92,7 @@ const pieceOf = (element: JsonObject): Piece => {
       // Slack stores a bare URL as a link whose text is the URL without its scheme.
       const bare = text === undefined || text === "" || text === url ||
         text === url.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "")
-      return { _tag: "text", text: bare ? url : `[${text}](${url})` }
+      return { _tag: "text", text: bare ? url : `[${escapeInline(text)}](${url})`, markdown: true }
     }
     case "user": {
       const id = stringOf(element, "user_id")
@@ -126,6 +126,48 @@ const pieceOf = (element: JsonObject): Piece => {
 
 const pieceText = (piece: Piece): string => piece._tag === "text" ? piece.text : piece.token
 
+const wordChar = /[\p{L}\p{N}]/u
+const asciiPunctuation = /[!-/:-@[-`{-~]/
+
+/**
+ * Backslash-escapes what Markdown would read as inline syntax, so a text
+ * element's `*literal*` reads back literal. An underscore between two
+ * letters or digits opens nothing and is left alone, as is a backslash
+ * before anything but punctuation or a line end. `<` and `&` are left
+ * alone: the adapter sends them as literal text either way.
+ */
+const escapeInline = (text: string): string =>
+  text.replace(/[*_`~[\]\\]/g, (char, at: number) => {
+    const before = text[at - 1] ?? ""
+    const after = text[at + 1] ?? ""
+    if (char === "_" && wordChar.test(before) && wordChar.test(after)) return char
+    if (char === "\\" && after !== "" && after !== "\n" && !asciiPunctuation.test(after)) return char
+    return "\\" + char
+  })
+
+/** A line start that would open a heading, list or quote, or underline the line before it. */
+const blockStart = /^( {0,3})(?:([#]{1,6}|[-+])(?=[ \t]|$)|(>)|(\d{1,9})([.)])(?=[ \t]|$)|([-=])(?=[-= \t]*$))/
+
+const escapeLineStart = (line: string): string =>
+  line.replace(
+    blockStart,
+    (_, indent: string, marker?: string, quote?: string, digits?: string, delimiter?: string, rule?: string) =>
+      marker !== undefined
+        ? indent + "\\" + marker
+        : quote !== undefined
+        ? indent + "\\>"
+        : digits !== undefined
+        ? indent + digits + "\\" + delimiter
+        : indent + "\\" + rule
+  )
+
+/** A text element's content as Markdown that reads back as the same text. */
+const literal = (text: string, atLineStart: boolean): string =>
+  escapeInline(text)
+    .split("\n")
+    .map((line, index) => index > 0 || atLineStart ? escapeLineStart(line) : line)
+    .join("\n")
+
 interface Writer {
   out: string
   readonly mentions: Array
@@ -136,6 +178,13 @@ const write = (writer: Writer, text: string): void => {
   writer.out += text
 }
 
+/** Writes a piece outside code: a link as built, other text escaped, a mention as its token. */
+const writePiece = (writer: Writer, piece: Piece, text = pieceText(piece)): void => {
+  if (piece._tag === "mention") return mention(writer, piece)
+  if (piece.markdown === true) return write(writer, text)
+  write(writer, literal(text, writer.out === "" || writer.out.endsWith("\n")))
+}
+
 const mention = (writer: Writer, piece: Extract): void => {
   const start = writer.out.length
   writer.out += piece.token
@@ -171,16 +220,18 @@ const inline = (writer: Writer, elements: ReadonlyArray): void => {
     if (style.code) {
       const content = run.map(pieceText).join("")
       const fence = "`".repeat(longestRun(content, "`") + 1)
-      const pad = content.startsWith("`") || content.endsWith("`") ? " " : ""
+      // A backtick at either end would join the fence, and Markdown strips
+      // one space from each end of a span that starts and ends with one.
+      const pad = content.startsWith("`") || content.endsWith("`") ||
+          (content.startsWith(" ") && content.endsWith(" ") && content.trim() !== "")
+        ? " "
+        : ""
       write(writer, opening(style) + fence + pad + content + pad + fence + closing(style))
       continue
     }
     const open = opening(style)
     if (open === "") {
-      for (const piece of run) {
-        if (piece._tag === "text") write(writer, piece.text)
-        else mention(writer, piece)
-      }
+      for (const piece of run) writePiece(writer, piece)
       continue
     }
     const first = run[0]
@@ -188,16 +239,15 @@ const inline = (writer: Writer, elements: ReadonlyArray): void => {
     const lead = first._tag === "text" ? /^\s*/.exec(first.text)![0] : ""
     const trail = last._tag === "text" ? /\s*$/.exec(last.text)![0] : ""
     if (run.length === 1 && first._tag === "text" && lead.length === first.text.length) {
-      write(writer, first.text)
+      writePiece(writer, first)
       continue
     }
     write(writer, lead + open)
     run.forEach((piece, k) => {
-      if (piece._tag === "mention") return mention(writer, piece)
-      let text = piece.text
+      let text = pieceText(piece)
       if (k === 0) text = text.slice(lead.length)
       if (k === run.length - 1) text = text.slice(0, text.length - trail.length)
-      write(writer, text)
+      writePiece(writer, piece, text)
     })
     write(writer, closing(style) + trail)
   }
diff --git a/packages/chat/slack/test/emoji.test.ts b/packages/chat/slack/test/emoji.test.ts
index 7fd8b18bb26..7da68ae64bd 100644
--- a/packages/chat/slack/test/emoji.test.ts
+++ b/packages/chat/slack/test/emoji.test.ts
@@ -82,10 +82,10 @@ describe("emoji", () => {
       assert.strictEqual(fromName("handshake::skin-tone-3::skin-tone-3"), undefined)
     })
 
-    it("gives a single tone only where the table has that one tone", () => {
+    it("gives a single tone, or the same tone twice where upstream keys only by two", () => {
       assert.strictEqual(fromName("handshake::skin-tone-3"), "🤝🏼")
-      // Keyed by two tones upstream only.
-      assert.strictEqual(fromName("people_holding_hands::skin-tone-4"), undefined)
+      assert.strictEqual(fromName("people_holding_hands::skin-tone-4"), "🧑🏽‍🤝‍🧑🏽")
+      assert.strictEqual(fromName("people_holding_hands::skin-tone-1"), undefined)
     })
 
     it("resolves every alias and every one-tone variation in the table", () => {
@@ -185,6 +185,11 @@ describe("emoji", () => {
       assert.isAtLeast(blocksCost("🇺") + blocksCost("🇸"), blocksCost("🇺🇸"))
       assert.isAtLeast(blocksCost("🏃") + blocksCost("\u200D➡️"), blocksCost("🏃‍➡️"))
       assert.isAtLeast(blocksCost("\uD83D") + blocksCost("\uDE00"), blocksCost("😀"))
+      // Slack charges a lone hair component 1. At 3 or less, 🧑‍🦱 would split
+      // for less than :curly_haired_person:.
+      assert.strictEqual(blocksCost("\u{1F9B1}"), 4)
+      assert.strictEqual(blocksCost("🧑‍🦱"), ":curly_haired_person:".length)
+      assert.isBelow(blocksCost("🧑") + blocksCost("\u200D") + 3, blocksCost("🧑‍🦱"))
     })
 
     it("is subadditive", () => {
diff --git a/packages/chat/slack/test/fixtures/synthetic/own-messages.json b/packages/chat/slack/test/fixtures/synthetic/own-messages.json
index 751f3caeff4..1d7e6881fac 100644
--- a/packages/chat/slack/test/fixtures/synthetic/own-messages.json
+++ b/packages/chat/slack/test/fixtures/synthetic/own-messages.json
@@ -1,6 +1,6 @@
 {
   "synthetic": "Hand-written, not read back from Slack: the test workspace was not available for EFF-3750. The shapes follow the recorded rich_text in ../recorded and Slack's rich_text docs. Replace each with a recording when one is made.",
-  "case": "Stage 0 fixture 13: the bot's own posts read back, for the constructs and message kinds the recordings lack (strike, quotes, lists, named links, broadcasts, user groups, emoji, buttons, file-only).",
+  "case": "Stage 0 fixture 13: the bot's own posts read back, for the constructs and message kinds the recordings lack (strike, quotes, lists, named links, broadcasts, user groups, emoji, buttons, file-only, literal Markdown characters, code span padding).",
   "cases": [
     {
       "name": "strike, bold italic and a code span holding a backtick",
@@ -361,6 +361,84 @@
           }
         ]
       }
+    },
+    {
+      "name": "Markdown characters a text element holds as literals",
+      "markdown": "\\*not italic\\*, \\`not code\\`, \\~not struck\\~, \\[not\\](a link), snake_case, \\_edge\\_, C:\\dir\\\\\\*\n\\# not a heading\n\\- not a list\n1\\. not ordered\n\\> not a quote\n**2 \\* 3**",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000700",
+        "text": "*not italic*, `not code`, ~not struck~, [not](a link), snake_case, _edge_, C:\\dir\\*\n# not a heading\n- not a list\n1. not ordered\n> not a quote\n*2 * 3*",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_section",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "*not italic*, `not code`, ~not struck~, [not](a link), snake_case, _edge_, C:\\dir\\*\n# not a heading\n- not a list\n1. not ordered\n> not a quote\n"
+                  },
+                  {
+                    "type": "text",
+                    "text": "2 * 3",
+                    "style": {
+                      "bold": true
+                    }
+                  }
+                ]
+              }
+            ]
+          }
+        ]
+      }
+    },
+    {
+      "name": "a code span with a space at each end",
+      "markdown": "pad `  foo  ` end",
+      "message": {
+        "type": "message",
+        "user": "U0CCLMD4S1L",
+        "bot_id": "B0CCHBHDK7X",
+        "app_id": "A0CCHBHDK7X",
+        "team": "T05479Z6JBW",
+        "ts": "1794600000.000800",
+        "text": "pad ` foo ` end",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "syn",
+            "elements": [
+              {
+                "type": "rich_text_section",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "pad "
+                  },
+                  {
+                    "type": "text",
+                    "text": " foo ",
+                    "style": {
+                      "code": true
+                    }
+                  },
+                  {
+                    "type": "text",
+                    "text": " end"
+                  }
+                ]
+              }
+            ]
+          }
+        ]
+      }
     }
   ]
 }
diff --git a/packages/chat/slack/test/text.test.ts b/packages/chat/slack/test/text.test.ts
index 16f04b13762..d686bb660f8 100644
--- a/packages/chat/slack/test/text.test.ts
+++ b/packages/chat/slack/test/text.test.ts
@@ -71,7 +71,11 @@ describe("build", () => {
 describe("request bodies", () => {
   const thread = SlackChat.thread({ team, channel })
   const allowed = { users: ["U1"], broadcast: true }
-  const allowedTokens = ["<@U1>", ""]
+  /** The tokens `notify` lets through, of those the alphabet can spell. */
+  const allowedTokens = (notify: Escape.Notify): ReadonlyArray => [
+    ...(notify.users?.includes("U1") ? ["<@U1>"] : []),
+    ...(notify.broadcast === true ? [""] : [])
+  ]
 
   // Pieces that spell tokens, entity forms, code and multi-unit characters.
   const alphabet = ["<", "@U1", "!here", ">", "&", "lt;", "`", "x", "👍🏽", "\n"]
@@ -98,10 +102,10 @@ describe("request bodies", () => {
     else assert.isAtMost(bytes(text), Text.updateTextBytes, label)
     // No token survives in text but an allowed one, and every & starts an entity.
     let rest = text
-    for (const token of allowedTokens) rest = rest.replaceAll(token, "")
+    for (const token of allowedTokens(notify)) rest = rest.replaceAll(token, "")
     assert.notMatch(rest, /[<>]|&(?!lt;|gt;|amp;)/, label)
     // An allowed token the block sends intact is in text too, cut or not.
-    for (const token of allowedTokens) {
+    for (const token of allowedTokens(notify)) {
       if (block.includes(token)) assert.include(text, token, label)
     }
     // A cut is a prefix of the whole text, on a grapheme boundary and outside an entity.

From 5290e198af8339d356ccbab3f7a25a4b13f7a020 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 06:56:13 +0000
Subject: [PATCH 24/89] Carry files on a Slack post by post-then-attach

A post with files now uploads every file, completes them in one call with no channel, posts the message with chat.postMessage, then attaches the files with chat.update and file_ids. Both calls send the same blocks and text, cut to the 3,800-byte update budget. A post with files and no Markdown carries the escaped file names as a placeholder that stays. The files.info share poll and the mrkdwn initial_comment are gone.

The post is all-or-nothing. A denied upload call and the adapter's own size and count check fail with detail file_refused. A timed-out attach is retried. A refused attach deletes the message and then the files, and fails file_refused. When the message can't be deleted, the post fails Unknown, uncertain, detail attach_failed_message_left, with the new SlackAttachFailed as its cause. From the post on the route is uninterruptible and each call has a 30-second timeout.
---
 .changeset/chat-slack.md                     |   2 +-
 packages/chat/slack/README.md                |   5 +
 packages/chat/slack/src/SlackChat.ts         |  61 ++++-
 packages/chat/slack/src/internal/adapter.ts  | 182 ++++++++-----
 packages/chat/slack/src/internal/errors.ts   |  43 +++-
 packages/chat/slack/src/internal/escape.ts   |  41 ---
 packages/chat/slack/src/internal/richText.ts |   7 +
 packages/chat/slack/src/internal/text.ts     |  16 ++
 packages/chat/slack/test/SlackChat.test.ts   | 254 +++++++++++++++----
 packages/chat/slack/test/escape.test.ts      |  12 +-
 packages/chat/slack/test/live.test.ts        |  31 ++-
 packages/chat/slack/test/utils.ts            |  14 +-
 12 files changed, 488 insertions(+), 180 deletions(-)

diff --git a/.changeset/chat-slack.md b/.changeset/chat-slack.md
index 57dbbcbb404..144c8ea59ca 100644
--- a/.changeset/chat-slack.md
+++ b/.changeset/chat-slack.md
@@ -3,4 +3,4 @@
 "effect": patch
 ---
 
-Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook, native streaming replies and the agent stop button. Add the `StopRequested` chat event.
+Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook, native streaming replies, the agent stop button and all-or-nothing posts with files. Add the `StopRequested` chat event.
diff --git a/packages/chat/slack/README.md b/packages/chat/slack/README.md
index 7a842d9eba6..7f1139d28d0 100644
--- a/packages/chat/slack/README.md
+++ b/packages/chat/slack/README.md
@@ -8,6 +8,11 @@ A [Slack](https://slack.com) adapter for `effect/chat`. Includes the Events API
 npm install effect @effect/chat-slack
 ```
 
+## Known limits
+
+- A post with files has not been tested in a Slack Connect channel.
+- A post with files uploads the files, posts the message, then attaches the files to it. If Slack refuses the attach, the adapter deletes the message. A mention in that message can still notify before the delete, for a message that then disappears. With `ChatMarkdown`'s `unattachedNote`, the reply is posted again without the files, so the mention can notify twice.
+
 ## Links
 
 - [Website](https://effect.website): documentation, guides, and news.
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 42813a11c45..2d2489aef0d 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -24,11 +24,11 @@
  * @since 4.1.5
  */
 import { Registry } from "effect/chat/ChatAdapter"
-import type { ChatError } from "effect/chat/ChatError"
+import { type ChatError, ChatErrorReason } from "effect/chat/ChatError"
 import type { ChatEvent } from "effect/chat/ChatEvent"
 import { ChatHandler } from "effect/chat/ChatHandler"
 import type { ParseMention } from "effect/chat/ChatTest"
-import type { ChatThread } from "effect/chat/ChatThread"
+import { ChatThread } from "effect/chat/ChatThread"
 import * as Context from "effect/Context"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
@@ -38,7 +38,7 @@ import * as HttpRouter from "effect/http/HttpRouter"
 import * as Layer from "effect/Layer"
 import * as Option from "effect/Option"
 import type * as Redacted from "effect/Redacted"
-import type * as Schema from "effect/Schema"
+import * as Schema from "effect/Schema"
 import * as Adapter from "./internal/adapter.ts"
 import * as Address from "./internal/address.ts"
 import * as Emoji from "./internal/emoji.ts"
@@ -111,8 +111,25 @@ export class SlackChat extends Context.Service new SlackAttachFailed(fields)
       })
       yield* registry.register(adapter)
       return SlackChat.of({ teamId: options.teamId, botUserId, user })
     })
   ).pipe(Layer.provideMerge(WebApi.layer({ botToken: options.botToken })))
 
+/**
+ * The `cause` of a `post` with files that failed `uncertain` with detail
+ * `attach_failed_message_left`.
+ *
+ * **Details**
+ *
+ * - Slack refused to attach the files and the message could not be deleted,
+ *   so it exists without them. `messageId` is that message and `fileIds`
+ *   are its files, which are kept. `reason` is the attach's own.
+ * - Its `message` leaves the ids out.
+ *
+ * @stability unstable
+ * @category errors
+ * @since 4.1.5
+ */
+export class SlackAttachFailed
+  extends Schema.TaggedError("@effect/chat-slack/SlackChat/SlackAttachFailed")(
+    "SlackAttachFailed",
+    {
+      thread: ChatThread,
+      messageId: Schema.String,
+      fileIds: Schema.Array(Schema.String),
+      reason: ChatErrorReason
+    }
+  )
+{
+  override get message(): string {
+    return `Slack refused to attach the files and the message could not be deleted: ${this.reason.message}`
+  }
+}
+
 /**
  * The address of a Slack channel, direct conversation or thread:
  * `{team}/{channel}`, or `{team}/{channel}/{threadTs}` for a thread.
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 6a682ae710d..222e9f5982d 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -6,7 +6,14 @@ import {
   retrySafe,
   type ThreadInfo
 } from "effect/chat/ChatAdapter"
-import { type ChatError, type ChatErrorReason, TooLarge, Unknown, Unsupported } from "effect/chat/ChatError"
+import {
+  type ChatError,
+  type ChatErrorReason,
+  fileRefused,
+  TooLarge,
+  Unknown,
+  Unsupported
+} from "effect/chat/ChatError"
 import type { ChatMessage } from "effect/chat/ChatMessage"
 import type { ChatThread } from "effect/chat/ChatThread"
 import * as Clock from "effect/Clock"
@@ -94,9 +101,8 @@ export const descriptor: Descriptor = {
 
 const pageSize = 200
 
-/** `files.info` reads for the share of a fresh upload, at this interval. */
-const shareAttempts = 20
-const shareInterval = Duration.millis(500)
+/** The bound on each call of a file post from `chat.postMessage` on: the post, each attach and the rollback. */
+const fileCallTimeout = Duration.seconds(30)
 
 /** Codes on `chat.startStream` that mean the feature is off for this thread. */
 const streamUnsupported = new Set(["channel_type_not_supported", "feature_disabled", "not_allowed_token_type"])
@@ -135,6 +141,13 @@ export const make = (options: {
   readonly botToken: Redacted.Redacted
   readonly teamId: string
   readonly botUserId: Effect.Effect
+  /** Builds the `SlackAttachFailed` cause, which lives in the public module. */
+  readonly attachFailed: (fields: {
+    readonly thread: ChatThread
+    readonly messageId: string
+    readonly fileIds: ReadonlyArray
+    readonly reason: ChatErrorReason
+  }) => unknown
 }) => {
   const { api, teamId } = options
   const streams = new Map()
@@ -239,8 +252,7 @@ export const make = (options: {
    * is sent, so `markdown_text` is never used on these two calls.
    */
   const messageContent = Effect.fnUntraced(
-    function*(op: string, markdown: string, notify: Escape.Notify, budget: Text.Budget) {
-      const body = Text.body(markdown, notify, budget)
+    function*(op: string, body: Text.Body) {
       yield* checkSent(op, body.sent)
       if (body.text === "") return yield* fail(op, Errors.invalidRequest("no_text"))
       if (body.dropped > 0) yield* Effect.annotateCurrentSpan("slack.text.dropped_tokens", body.dropped)
@@ -292,6 +304,10 @@ export const make = (options: {
 
   // Files
 
+  /** A `denied` failure of an upload call refused a file. */
+  const refused = (error: ChatError): ChatError =>
+    error.reason.retry === "denied" ? Errors.chatError(error.op, Errors.fileRefused(error.reason)) : error
+
   const stage = (file: File): Effect.Effect<{ readonly id: string; readonly title: string }, ChatError> =>
     Effect.gen(function*() {
       const answer = yield* call("post", "files.getUploadURLExternal", {
@@ -311,76 +327,99 @@ export const make = (options: {
         return yield* fail("post", Errors.reasonForStatus(response.status, { write: false }))
       }
       return { id: fileId, title: file.name }
-    })
+    }).pipe(Effect.mapError(refused))
 
-  /** The ts of the message that shared a fresh upload, from `files.info`. */
-  const shareTs = (answer: Json, channel: string, threadTs: string | undefined): string | undefined => {
-    const file = isObject(answer) ? object(answer, "file") : undefined
-    const shares = file === undefined ? undefined : object(file, "shares")
-    if (shares === undefined) return undefined
-    for (const visibility of ["public", "private"]) {
-      const byChannel = object(shares, visibility)
-      const list = byChannel === undefined ? undefined : byChannel[channel]
-      if (!Array.isArray(list)) continue
-      for (const share of list) {
-        if (!isObject(share)) continue
-        const ts = string(share, "ts")
-        const shareThread = string(share, "thread_ts")
-        if (
-          ts !== undefined &&
-          (threadTs === undefined ? shareThread === undefined || shareThread === ts : shareThread === threadTs)
-        ) {
-          return ts
-        }
-      }
-    }
-    return undefined
-  }
+  /** One call of the post, the attach or the rollback, cut off after `fileCallTimeout`. */
+  const bounded = (effect: Effect.Effect, onTimeout: ChatErrorReason): Effect.Effect =>
+    Effect.timeoutOrElse(effect, { duration: fileCallTimeout, orElse: () => fail("post", onTimeout) })
 
-  const postFiles = (
+  /**
+   * Upload, post, then attach. The files are completed with no channel, so
+   * nothing is visible until `chat.postMessage`, and `chat.update` with
+   * `file_ids` attaches them. Both calls send the same body, with `text` under
+   * the update budget, so `text` never changes between them.
+   *
+   * From the post on, the route runs uninterruptible, with a timeout on each
+   * call. The attach replaces the file list, so it is retried. When it still
+   * fails, the message is deleted and then the files, best effort. If the
+   * message can't be deleted, it is left without its files and the post fails
+   * `uncertain` with a `SlackAttachFailed` as its cause, and the files are
+   * kept so the ids it carries still mean something.
+   */
+  const postFiles = Effect.fnUntraced(function*(
     thread: ChatThread,
     parts: Address.Parts,
     markdown: string,
     files: ReadonlyArray,
-    notify: Escape.Notify
-  ): Effect.Effect =>
-    Effect.gen(function*() {
-      if (files.length > descriptor.limits.filesPerMessage) {
-        return yield* fail("post", new TooLarge({ subject: "files", detail: "too_many_files" }))
-      }
-      if (files.some((file) => file.content.length > descriptor.limits.uploadBytes)) {
-        return yield* fail("post", new TooLarge({ subject: "files", detail: "file_too_large" }))
-      }
-      // A message with files takes no `markdown_text`: its text goes as mrkdwn.
-      const comment = markdown.trim() === "" ? undefined : Escape.toMrkdwn(markdown, notify)
-      if (comment !== undefined) yield* checkSent("post", comment)
-      const staged = yield* Effect.forEach(files, stage)
-      yield* call("post", "files.completeUploadExternal", {
-        files: staged,
-        channel_id: parts.channel,
-        thread_ts: parts.threadTs,
-        initial_comment: comment
-      }, { write: true })
-      // The answer carries no message ts. Slack fills the file's shares soon after.
-      // The message exists from here on, so not finding its ts is an
-      // uncertain outcome, never a refusal or a retryable failure.
-      let lastError: ChatError | undefined
-      for (let attempt = 0; attempt < shareAttempts; attempt++) {
-        if (attempt > 0) yield* Effect.sleep(shareInterval)
-        const info = yield* Effect.result(call("post", "files.info", { file: staged[0].id }))
-        if (Result.isFailure(info)) {
-          lastError = info.failure
-          if (lastError.reason.retry === "denied") break
-          continue
-        }
-        const ts = shareTs(info.success, parts.channel, parts.threadTs)
-        if (ts !== undefined) return { id: ts, thread, timestamp: Normalize.timestamp(ts) }
+    notify: Escape.Notify,
+    unfurl: boolean
+  ) {
+    if (
+      files.length > descriptor.limits.filesPerMessage ||
+      files.some((file) => file.content.length > descriptor.limits.uploadBytes)
+    ) {
+      return yield* fail("post", new TooLarge({ subject: "files", detail: fileRefused }))
+    }
+    const content = Text.body(markdown, notify, Text.updateBudget)
+    const body = yield* messageContent(
+      "post",
+      content.text === "" ? Text.placeholder(files.map((file) => file.name), Text.updateBudget) : content
+    )
+    const staged = yield* Effect.forEach(files, stage)
+    yield* call("post", "files.completeUploadExternal", { files: staged }).pipe(Effect.mapError(refused))
+    const fileIds = staged.map((file) => file.id)
+    const channel = parts.channel
+
+    return yield* Effect.uninterruptible(Effect.gen(function*() {
+      const removeFiles = Effect.forEach(
+        fileIds,
+        (file) =>
+          bounded(call("post", "files.delete", { file }, { write: true }), Errors.transport(true, "timeout")).pipe(
+            Effect.ignore
+          ),
+        { discard: true }
+      )
+      const ts = yield* bounded(
+        call("post", "chat.postMessage", {
+          channel,
+          thread_ts: parts.threadTs,
+          ...body,
+          unfurl_links: unfurl,
+          unfurl_media: unfurl
+        }, { write: true }).pipe(Effect.flatMap(tsOf("post", true))),
+        Errors.transport(true, "timeout")
+      ).pipe(Effect.tapError(() => removeFiles))
+      const posted: Posted = { id: ts, thread, timestamp: Normalize.timestamp(ts) }
+
+      const attached = yield* retrySafe(paced(
+        ts,
+        bounded(
+          call("post", "chat.update", { channel, ts, ...body, file_ids: fileIds }, { write: false, retry: false }),
+          Errors.transport(false, "timeout")
+        ),
+        "edit"
+      )).pipe(Effect.result)
+      if (Result.isSuccess(attached)) return posted
+
+      const error = attached.failure
+      yield* Effect.annotateCurrentSpan("slack.attach.failed", error.reason._tag)
+      const deleted = yield* bounded(
+        call("post", "chat.delete", { channel, ts }, { write: true }),
+        Errors.transport(true, "timeout")
+      ).pipe(Effect.result)
+      if (Result.isSuccess(deleted)) {
+        yield* removeFiles
+        return yield* Effect.fail(refused(error))
       }
       return yield* fail(
         "post",
-        new Unknown({ detail: "share_ts_unknown", ...(lastError === undefined ? {} : { cause: lastError }) })
+        new Unknown({
+          detail: "attach_failed_message_left",
+          cause: options.attachFailed({ thread, messageId: ts, fileIds, reason: error.reason })
+        })
       )
-    })
+    }))
+  })
 
   // History
 
@@ -596,11 +635,11 @@ export const make = (options: {
       if (content.replyTo !== undefined) return yield* fail("post", new Unsupported({ capability: "replyTo" }))
       const postOptions = yield* CurrentPostOptions
       const notify = postOptions.notify ?? {}
+      const unfurl = postOptions.unfurl === true
       if (content.files !== undefined && content.files.length > 0) {
-        return yield* postFiles(thread, parts, content.markdown, content.files, notify)
+        return yield* postFiles(thread, parts, content.markdown, content.files, notify, unfurl)
       }
-      const body = yield* messageContent("post", content.markdown, notify, Text.postBudget)
-      const unfurl = postOptions.unfurl === true
+      const body = yield* messageContent("post", Text.body(content.markdown, notify, Text.postBudget))
       const ts = yield* call("post", "chat.postMessage", {
         channel: parts.channel,
         thread_ts: parts.threadTs,
@@ -613,7 +652,10 @@ export const make = (options: {
     edit: Effect.fnUntraced(function*(thread, messageId, content) {
       const parts = yield* resolve("edit", thread)
       const postOptions = yield* CurrentPostOptions
-      const body = yield* messageContent("edit", content.markdown, postOptions.notify ?? {}, Text.updateBudget)
+      const body = yield* messageContent(
+        "edit",
+        Text.body(content.markdown, postOptions.notify ?? {}, Text.updateBudget)
+      )
       yield* retrySafe(paced(
         messageId,
         call("edit", "chat.update", { channel: parts.channel, ts: messageId, ...body }, {
diff --git a/packages/chat/slack/src/internal/errors.ts b/packages/chat/slack/src/internal/errors.ts
index 0ab0c227691..4c304329965 100644
--- a/packages/chat/slack/src/internal/errors.ts
+++ b/packages/chat/slack/src/internal/errors.ts
@@ -1,16 +1,19 @@
 import {
   ChatError,
   type ChatErrorReason,
+  fileRefused as fileRefusedDetail,
   Forbidden,
   InvalidRequest,
   InvalidResponse,
+  NoAdapter,
   NotFound,
   PlatformUnavailable,
   RateLimited,
   TooLarge,
   Transport,
   Unauthenticated,
-  Unknown
+  Unknown,
+  Unsupported
 } from "effect/chat/ChatError"
 import * as Duration from "effect/Duration"
 import { platform } from "./address.ts"
@@ -149,3 +152,41 @@ export const invalidRequest = (detail: string): ChatErrorReason => new InvalidRe
 
 /** @internal */
 export const notFound = (detail: string): ChatErrorReason => new NotFound({ detail })
+
+/**
+ * A `denied` reason from an upload call, or from the attach of a post whose
+ * rollback left nothing behind, as a refused file: the same reason with
+ * detail `file_refused`, and the reason it replaces, with Slack's code, as
+ * its `cause`. Any other reason is returned as it is.
+ *
+ * @internal
+ */
+export const fileRefused = (reason: ChatErrorReason): ChatErrorReason => {
+  if (reason.retry !== "denied" || reason.detail === fileRefusedDetail) return reason
+  const fields = { detail: fileRefusedDetail, cause: reason }
+  switch (reason._tag) {
+    case "Unsupported":
+      return new Unsupported({ capability: reason.capability, ...fields })
+    case "Transport":
+      return new Transport({ retry: reason.retry, ...fields })
+    case "PlatformUnavailable":
+      return new PlatformUnavailable({ retry: reason.retry, ...fields })
+    case "NoAdapter":
+      return new NoAdapter(fields)
+    case "Unauthenticated":
+      return new Unauthenticated(fields)
+    case "Forbidden":
+      return new Forbidden(fields)
+    case "NotFound":
+      return new NotFound(fields)
+    case "TooLarge":
+      return new TooLarge({ ...(reason.subject === undefined ? {} : { subject: reason.subject }), ...fields })
+    case "InvalidRequest":
+      return new InvalidRequest(fields)
+    case "InvalidResponse":
+      return new InvalidResponse(fields)
+    case "RateLimited":
+    case "Unknown":
+      return reason
+  }
+}
diff --git a/packages/chat/slack/src/internal/escape.ts b/packages/chat/slack/src/internal/escape.ts
index e8402bba84f..42c1435f9fa 100644
--- a/packages/chat/slack/src/internal/escape.ts
+++ b/packages/chat/slack/src/internal/escape.ts
@@ -226,44 +226,3 @@ export const escape = (
 const entityOf: Record = { "&": "&", "<": "<", ">": ">" }
 
 const textEntities = (text: string): string => text.replace(/[&<>]/g, (char) => entityOf[char])
-
-/**
- * Markdown as Slack's mrkdwn, for the text of a message that carries files,
- * which takes no `markdown_text`. Outside code, headings and bold become
- * `*bold*`, strikethrough `~struck~` and links ``, a `>` that opens
- * a quote stays, and `&`, `<` and `>` are escaped unless they belong to a
- * token the notify options allow.
- *
- * @internal
- */
-export const toMrkdwn = (markdown: string, notify: Notify): string =>
-  markdown
-    .split(/(```[\s\S]*?```|`[^`\n]*`)/)
-    .map((part, index) => {
-      if (index % 2 === 1) return textEntities(part.replace(/^```[\w+#.-]+\n/, "```\n"))
-      // Allowed tokens become private-use placeholders, so the conversions
-      // below can span them but never change them.
-      const tokens: Array = []
-      let masked = ""
-      let i = 0
-      while (i < part.length) {
-        const token = part[i] === "<" ? allowedToken(part.slice(i), notify) : 0
-        if (token > 0) {
-          masked += `\uE000${tokens.push(part.slice(i, i + token)) - 1}\uE001`
-          i += token
-        } else {
-          masked += part[i]
-          i++
-        }
-      }
-      return masked
-        .replace(/&/g, "&")
-        .replace(/|>/gm, (match, indent: string | undefined) => indent === undefined ? ">" : match)
-        .replace(/^#{1,6}[ \t]+(.+?)[ \t#]*$/gm, "*$1*")
-        .replace(/\*\*(.+?)\*\*|__(.+?)__/g, (_, star: string | undefined, under: string) => `*${star ?? under}*`)
-        .replace(/~~(.+?)~~/g, "~$1~")
-        .replace(/\[([^\]\n]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\)/g, "<$2|$1>")
-        .replace(/\uE000(\d+)\uE001/g, (_, index: string) => tokens[Number(index)])
-    })
-    .join("")
diff --git a/packages/chat/slack/src/internal/richText.ts b/packages/chat/slack/src/internal/richText.ts
index 77484cf7922..f4eae5bff5e 100644
--- a/packages/chat/slack/src/internal/richText.ts
+++ b/packages/chat/slack/src/internal/richText.ts
@@ -168,6 +168,13 @@ const literal = (text: string, atLineStart: boolean): string =>
     .map((line, index) => index > 0 || atLineStart ? escapeLineStart(line) : line)
     .join("\n")
 
+/**
+ * Markdown that renders `text` as written, as the start of a message.
+ *
+ * @internal
+ */
+export const escapeMarkdown = (text: string): string => literal(text, true)
+
 interface Writer {
   out: string
   readonly mentions: Array
diff --git a/packages/chat/slack/src/internal/text.ts b/packages/chat/slack/src/internal/text.ts
index db68b15479d..27478d92c41 100644
--- a/packages/chat/slack/src/internal/text.ts
+++ b/packages/chat/slack/src/internal/text.ts
@@ -6,6 +6,7 @@
  */
 import * as Escape from "./escape.ts"
 import { codePoints } from "./length.ts"
+import { escapeMarkdown } from "./richText.ts"
 
 /**
  * The budget for `text` on `chat.postMessage`, in code points. Slack cuts a
@@ -200,3 +201,18 @@ export const body = (markdown: string, notify: Escape.Notify, budget: Budget): B
   const built = build(markdown, notify, budget)
   return { sent, blocks: [{ type: "markdown", text: sent }], text: built.text, dropped: built.dropped }
 }
+
+/**
+ * The content of a post with files and no Markdown: the file names joined by
+ * ", ", escaped as Markdown in the block so they render as written, and with
+ * entities in `text`. No token in a name is allowed. It stays as the
+ * message.
+ *
+ * @internal
+ */
+export const placeholder = (names: ReadonlyArray, budget: Budget): Body => {
+  const joined = names.join(", ")
+  const sent = Escape.escape(escapeMarkdown(joined), {}, { flush: true }).sent
+  const built = build(joined, {}, budget)
+  return { sent, blocks: [{ type: "markdown", text: sent }], text: built.text, dropped: built.dropped }
+}
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 93c8f88b779..ecb10083aab 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -1,14 +1,26 @@
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { SlackWebApi } from "@effect/chat-slack/SlackWebApi"
 import { assert, describe, it } from "@effect/vitest"
-import { checkMessage } from "effect/chat/ChatTest"
+import { type ChatErrorReason, fileRefused } from "effect/chat/ChatError"
+import { checkMessage, conformance } from "effect/chat/ChatTest"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
 import * as Option from "effect/Option"
 import * as Stream from "effect/Stream"
 import * as TestClock from "effect/testing/TestClock"
-import { adapter, authTest, botUserId, channel, checkOptions, fixture, makeFake, slackLayer, team } from "./utils.ts"
+import {
+  adapter,
+  authTest,
+  botUserId,
+  channel,
+  checkOptions,
+  fixture,
+  hang,
+  makeFake,
+  slackLayer,
+  team
+} from "./utils.ts"
 
 const root = "1794509110.999799"
 const channelThread = SlackChat.thread({ team, channel })
@@ -169,72 +181,226 @@ describe("post", () => {
         assert.isFalse(slack.descriptor.capabilities.has("replyTo"))
       })
     ))
+})
+
+describe("files", () => {
+  const upload = (ids: ReadonlyArray) => {
+    let next = 0
+    return {
+      "files.getUploadURLExternal": () => {
+        const id = ids[next++]
+        return { ok: true, upload_url: `https://files.slack.test/upload/${id}`, file_id: id }
+      },
+      "files.completeUploadExternal": { ok: true, files: ids.map((id) => ({ id })) }
+    }
+  }
+  const file = (name: string) => ({ name, contentType: "text/plain", content: new TextEncoder().encode("hello") })
+  const ts = "1794509300.000100"
+  const methods = (fake: ReturnType) =>
+    fake.calls.map((call) => call.method).filter((method) => !method.startsWith("/upload/"))
+
+  it.effect("uploads, completes with no channel, posts, then attaches with the same body", () => {
+    const fake = makeFake({ ...upload(["F1", "F2"]), "chat.postMessage": posted(ts) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const markdown = "**see** <@U1> " + "a".repeat(5_000)
+        const result = yield* slack.post(replyThread, { markdown, files: [file("a.txt"), file("b.txt")] })
+        assert.strictEqual(result.id, ts)
+        assert.deepStrictEqual(methods(fake), [
+          "files.getUploadURLExternal",
+          "files.getUploadURLExternal",
+          "files.completeUploadExternal",
+          "chat.postMessage",
+          "chat.update"
+        ])
+        assert.deepStrictEqual(fake.called("files.completeUploadExternal")[0].params, {
+          files: JSON.stringify([{ id: "F1", title: "a.txt" }, { id: "F2", title: "b.txt" }])
+        })
+        const post = fake.called("chat.postMessage")[0].params
+        const attach = fake.called("chat.update")[0].params
+        assert.deepStrictEqual(attach, {
+          channel,
+          ts,
+          blocks: post.blocks,
+          text: post.text,
+          file_ids: JSON.stringify(["F1", "F2"])
+        })
+        // The text is cut to the update budget from the post on.
+        assert.isAtMost(new TextEncoder().encode(post.text).length, 3_800)
+        assert.isTrue(post.text.endsWith("…"))
+        assert.strictEqual(post.thread_ts, root)
+
+        // Later writes keep the files: no file_ids, and no files.delete.
+        const edit = yield* Effect.forkChild(slack.edit(replyThread, ts, { markdown: "edited" }))
+        yield* TestClock.adjust("3 seconds")
+        yield* Fiber.join(edit)
+        yield* slack.delete(replyThread, ts)
+        assert.isUndefined(fake.called("chat.update")[1].params.file_ids)
+        assert.strictEqual(fake.called("files.delete").length, 0)
+      })
+    )
+  })
+
+  it.effect("a post with files and no Markdown carries the escaped file names", () => {
+    const fake = makeFake({ ...upload(["F1", "F2"]), "chat.postMessage": posted(ts) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        yield* slack.post(channelThread, { markdown: "", files: [file("*a*.txt"), file("<@U1>.csv")] })
+        const post = fake.called("chat.postMessage")[0].params
+        assert.deepStrictEqual(JSON.parse(post.blocks), [{ type: "markdown", text: "\\*a\\*.txt, <@U1>.csv" }])
+        assert.strictEqual(post.text, "*a*.txt, <@U1>.csv")
+        assert.strictEqual(fake.called("chat.update")[0].params.text, post.text)
+      })
+    )
+  })
+
+  it.effect("too many files fail file_refused before any call", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const files = Array.from({ length: slack.descriptor.limits.filesPerMessage + 1 }, (_, i) => file(`${i}.txt`))
+        assert.deepStrictEqual(yield* reason(slack.post(channelThread, { markdown: "x", files })), {
+          op: "post",
+          tag: "TooLarge",
+          detail: fileRefused,
+          retry: "denied"
+        })
+        assert.deepStrictEqual(fake.calls, [])
+      })
+    )
+  })
 
-  it.effect("files go up and are shared as one message", () => {
+  it.effect("a file refused at the complete call posts nothing", () => {
     const fake = makeFake({
-      "files.getUploadURLExternal": { ok: true, upload_url: "https://files.slack.test/upload/1", file_id: "F1" },
-      "files.completeUploadExternal": { ok: true, files: [{ id: "F1" }] },
-      "files.info": [
-        { ok: true, file: { id: "F1", shares: {} } },
-        {
-          ok: true,
-          file: { id: "F1", shares: { private: { [channel]: [{ ts: "1794509300.000100", thread_ts: root }] } } }
-        }
-      ]
+      ...upload(["F1"]),
+      "files.completeUploadExternal": { ok: false, error: "invalid_arguments" }
     })
     return run(
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const result = yield* slack.post(replyThread, {
-          markdown: "**see** <@U1>",
-          files: [{ name: "a.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }]
-        }).pipe(Effect.forkChild)
-        yield* TestClock.adjust("1 second")
-        const value = yield* Fiber.join(result)
-        assert.strictEqual(value.id, "1794509300.000100")
-        const complete = fake.called("files.completeUploadExternal")[0].params
-        assert.strictEqual(complete.initial_comment, "*see* <@U1>")
-        assert.strictEqual(complete.thread_ts, root)
-        assert.deepStrictEqual(JSON.parse(complete.files), [{ id: "F1", title: "a.txt" }])
-        assert.strictEqual(fake.called("/upload/1").length, 1)
+        const error = yield* Effect.flip(slack.post(channelThread, { markdown: "x", files: [file("a.txt")] }))
+        assert.strictEqual(error.reason._tag, "InvalidRequest")
+        assert.strictEqual(error.reason.detail, fileRefused)
+        assert.strictEqual(error.retry, "denied")
+        // Slack's code stays on the cause.
+        assert.strictEqual((error.reason.cause as ChatErrorReason).detail, "invalid_arguments")
+        assert.strictEqual(fake.called("chat.postMessage").length, 0)
       })
     )
   })
-})
 
-describe("files", () => {
-  const upload = {
-    "files.getUploadURLExternal": { ok: true, upload_url: "https://files.slack.test/upload/1", file_id: "F1" },
-    "files.completeUploadExternal": { ok: true, files: [{ id: "F1" }] }
-  }
-  const file = { name: "a.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }
+  it.effect("a failed post removes the uploads", () => {
+    const fake = makeFake({ ...upload(["F1", "F2"]), "chat.postMessage": { ok: false, error: "not_in_channel" } })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const failure = yield* reason(slack.post(channelThread, { markdown: "x", files: [file("a"), file("b")] }))
+        assert.deepStrictEqual(failure, { op: "post", tag: "Forbidden", detail: "not_in_channel", retry: "denied" })
+        assert.deepStrictEqual(fake.called("files.delete").map((call) => call.params.file), ["F1", "F2"])
+        assert.strictEqual(fake.called("chat.update").length, 0)
+      })
+    )
+  })
 
-  it.effect("a refused read after the share is an uncertain post, not a refusal", () => {
-    const fake = makeFake({ ...upload, "files.info": { ok: false, error: "missing_scope" } })
+  it.effect("an attach that times out is retried", () => {
+    const fake = makeFake({ ...upload(["F1"]), "chat.postMessage": posted(ts), "chat.update": [hang, { ok: true }] })
     return run(
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const failure = yield* reason(slack.post(replyThread, { markdown: "see", files: [file] }))
-        assert.deepStrictEqual(failure, { op: "post", tag: "Unknown", detail: "share_ts_unknown", retry: "uncertain" })
-        assert.strictEqual(fake.called("files.info").length, 1)
+        const fiber = yield* Effect.forkChild(slack.post(channelThread, { markdown: "x", files: [file("a")] }))
+        yield* TestClock.adjust("31 seconds")
+        assert.strictEqual((yield* Fiber.join(fiber)).id, ts)
+        assert.strictEqual(fake.called("chat.update").length, 2)
+        assert.strictEqual(fake.called("chat.delete").length, 0)
       })
     )
   })
 
-  it.effect("a failing read after the share is polled again, then uncertain", () => {
-    const fake = makeFake({ ...upload, "files.info": { status: 500 } })
+  it.effect("a refused attach deletes the message and the files and fails file_refused", () => {
+    const fake = makeFake({
+      ...upload(["F1"]),
+      "chat.postMessage": posted(ts),
+      "chat.update": { ok: false, error: "file_not_found" }
+    })
     return run(
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const result = yield* Effect.forkChild(reason(slack.post(replyThread, { markdown: "see", files: [file] })))
-        yield* TestClock.adjust("10 minutes")
-        const failure = yield* Fiber.join(result)
-        assert.strictEqual(failure.tag, "Unknown")
-        assert.strictEqual(failure.retry, "uncertain")
-        assert.isAbove(fake.called("files.info").length, 1)
+        const error = yield* Effect.flip(slack.post(channelThread, { markdown: "x", files: [file("a")] }))
+        assert.deepStrictEqual([error.reason._tag, error.reason.detail, error.retry], [
+          "NotFound",
+          fileRefused,
+          "denied"
+        ])
+        assert.strictEqual(methods(fake).slice(-3).join(), "chat.update,chat.delete,files.delete")
+        assert.deepStrictEqual(fake.called("chat.delete")[0].params, { channel, ts })
+      })
+    )
+  })
+
+  it.effect("a rollback that can't delete the message fails uncertain with SlackAttachFailed", () => {
+    const fake = makeFake({
+      ...upload(["F1", "F2"]),
+      "chat.postMessage": posted(ts),
+      "chat.update": { ok: false, error: "file_not_found" },
+      "chat.delete": { ok: false, error: "cant_delete_message" }
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const error = yield* Effect.flip(slack.post(replyThread, { markdown: "x", files: [file("a"), file("b")] }))
+        assert.deepStrictEqual(
+          [error.reason._tag, error.reason.detail, error.retry],
+          ["Unknown", "attach_failed_message_left", "uncertain"]
+        )
+        const cause = error.reason.cause
+        assert.instanceOf(cause, SlackChat.SlackAttachFailed)
+        assert.deepStrictEqual(cause.thread, replyThread)
+        assert.strictEqual(cause.messageId, ts)
+        assert.deepStrictEqual(cause.fileIds, ["F1", "F2"])
+        assert.deepStrictEqual([cause.reason._tag, cause.reason.detail], ["NotFound", "file_not_found"])
+        assert.notInclude(cause.message, ts)
+        assert.notInclude(cause.message, "F1")
+        // The files are kept, so the ids it carries still mean something.
+        assert.strictEqual(fake.called("files.delete").length, 0)
+      })
+    )
+  })
+
+  it.effect("post/refusedFile passes over the stub", () => {
+    let refuse = false
+    const fake = makeFake({
+      ...upload(["F1"]),
+      "auth.test": authTest,
+      "conversations.history": { ok: true, messages: [] },
+      "files.completeUploadExternal": () =>
+        refuse ? { ok: false, error: "invalid_arguments" } : { ok: true, files: [{ id: "F1" }] }
+    })
+    const rules = conformance({
+      platform: "slack",
+      thread: channelThread,
+      userPosts: () => Effect.die("unused"),
+      parseMention: SlackChat.parseMention,
+      refuseFiles: () =>
+        Effect.sync(() => {
+          refuse = true
+        })
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        yield* rules["post/refusedFile"]
+        assert.strictEqual(fake.called("chat.postMessage").length, 0)
       })
     )
   })
diff --git a/packages/chat/slack/test/escape.test.ts b/packages/chat/slack/test/escape.test.ts
index 8e03735176d..8b72cdfa541 100644
--- a/packages/chat/slack/test/escape.test.ts
+++ b/packages/chat/slack/test/escape.test.ts
@@ -1,4 +1,4 @@
-import { escape, toMrkdwn } from "@effect/chat-slack/internal/escape"
+import { escape } from "@effect/chat-slack/internal/escape"
 import { codePoints, measure } from "@effect/chat-slack/internal/length"
 import { assert, describe, it } from "@effect/vitest"
 
@@ -56,16 +56,6 @@ describe("escape", () => {
   })
 })
 
-describe("toMrkdwn", () => {
-  it("converts Markdown and escapes outside code", () => {
-    assert.strictEqual(
-      toMrkdwn("# Title\n**bold** ~~gone~~ [docs](https://effect.website) a < b & c <@U1>\n> quote\n``", {}),
-      "*Title*\n*bold* ~gone~  a < b & c <@U1>\n> quote\n`<x>`"
-    )
-    assert.strictEqual(toMrkdwn("hi <@U1>", { users: ["U1"] }), "hi <@U1>")
-  })
-})
-
 describe("measure", () => {
   it("bounds what is sent and adds up", () => {
     const samples = ["plain", "a < b", "<<<", "😀😀", "`<@U1>` ", "👍🏽 and 1\u20E3", "\ud83d", "🇺🇸"]
diff --git a/packages/chat/slack/test/live.test.ts b/packages/chat/slack/test/live.test.ts
index 762f433eac1..a6fc3f059d8 100644
--- a/packages/chat/slack/test/live.test.ts
+++ b/packages/chat/slack/test/live.test.ts
@@ -94,10 +94,11 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
  * the blocks.
  *
  * It is a proxy: Slack decides a mention from the stored `text`, which was
- * checked against one client's Activity feed (EFF-3730, EFF-3736). The
- * stream inputs and the file posts belong to the stream and file routes, and
- * are not here yet. The same assertions run in CI on the request bodies, in
- * `text.test.ts`.
+ * checked against one client's Activity feed (EFF-3730, EFF-3736). It also
+ * makes a file post and a file-only post, and asserts each holds its file
+ * after the attach. The stream inputs belong to the stream route and are not
+ * here yet. The same assertions run in CI on the request bodies, in
+ * `text.test.ts` and `SlackChat.test.ts`.
  */
 describe.skipIf(botToken === undefined || teamId === undefined || channel === undefined)("live mention rule", () => {
   const layer = SlackChat.layer({ botToken: Redacted.make(botToken!), teamId: teamId! }).pipe(
@@ -160,6 +161,28 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
       yield* slack.edit(thread, allowedPost.id, { markdown: "x".repeat(6_000) + ` <@${self}>` }).pipe(allowed)
       yield* check(allowedPost.id, "long edit")
 
+      // A file post and a file-only post: the files are attached, and no
+      // token is stored, in the Markdown or in a file name.
+      const fileIds: Array = []
+      const withFile = Effect.fnUntraced(function*(markdown: string, name: string, label: string) {
+        const post = yield* slack.post(thread, {
+          markdown,
+          files: [{ name, contentType: "text/plain", content: new TextEncoder().encode(label) }]
+        })
+        posted.push(post.id)
+        const message = yield* stored(post.id)
+        const files: Array = message.files ?? []
+        fileIds.push(...files.map((file) => file.id))
+        assert.strictEqual(files.length, 1, label)
+        assert.deepStrictEqual(message.text.match(token), null, label)
+        return message
+      })
+      yield* withFile(inputs[1], "file.txt", "file post")
+      const fileOnly = yield* withFile("", `<@${self}>.txt`, "file-only post")
+      assert.strictEqual(fileOnly.text, `<@${self}>.txt`)
+
       for (const id of posted) yield* slack.delete(thread, id).pipe(Effect.ignore)
+      // `delete` keeps a message's files.
+      for (const file of fileIds) yield* api.call("files.delete", { file }, { write: true }).pipe(Effect.ignore)
     }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)), 600_000)
 })
diff --git a/packages/chat/slack/test/utils.ts b/packages/chat/slack/test/utils.ts
index 4df8e804046..a4a2bf4fd85 100644
--- a/packages/chat/slack/test/utils.ts
+++ b/packages/chat/slack/test/utils.ts
@@ -75,6 +75,10 @@ export interface FakeCall {
 export type Answer =
   | Record
   | { readonly status: number; readonly headers?: Record; readonly body?: unknown }
+  | typeof hang
+
+/** An answer that never comes. */
+export const hang = { hang: true } as const
 
 /**
  * A scripted Slack. Each method answers from a queue of answers, the last
@@ -88,7 +92,7 @@ export const makeFake = (
   for (const [method, answer] of Object.entries(script)) {
     if (Array.isArray(answer)) queues.set(method, [...answer])
   }
-  const respond = (request: HttpClientRequest.HttpClientRequest, url: URL): Response => {
+  const respond = (request: HttpClientRequest.HttpClientRequest, url: URL): Response | typeof hang => {
     const method = url.pathname.replace(/^\/api\//, "")
     const body = request.body
     const text = body._tag === "Uint8Array" ? body.text ?? new TextDecoder().decode(body.body) : ""
@@ -101,6 +105,7 @@ export const makeFake = (
       const queue = queues.get(method)!
       answer = queue.length > 1 ? queue.shift()! : queue[0]
     } else answer = (entry as Answer | undefined) ?? { ok: true }
+    if (answer === hang) return hang
     if ("status" in answer && typeof answer.status === "number") {
       const { body, headers, status } = answer as Extract
       return new Response(body === undefined ? "" : JSON.stringify(body), { status, headers: headers ?? {} })
@@ -108,7 +113,12 @@ export const makeFake = (
     return new Response(JSON.stringify(answer), { status: 200, headers: { "content-type": "application/json" } })
   }
   const client = HttpClient.make((request, url) =>
-    Effect.sync(() => HttpClientResponse.fromWeb(request, respond(request, url)))
+    Effect.suspend(() => {
+      const response = respond(request, url)
+      return response instanceof Response
+        ? Effect.succeed(HttpClientResponse.fromWeb(request, response))
+        : Effect.never
+    })
   )
   return {
     calls,

From 497faf56b641c5c0ca380cf2c21faf37e2058c11 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 07:06:03 +0000
Subject: [PATCH 25/89] Bound the whole Slack attach, retries and 429 waits
 included

The per-request timeout sat inside retrySafe and the pacing, so a long Retry-After on the attach kept the uninterruptible file post waiting with the message visible and unattached. The attach as a whole now has a one-minute deadline, past which it is rolled back. File cleanup runs concurrently under one timeout. SlackAttachFailed's docs now say the message may be left with or without its files.
---
 packages/chat/slack/src/SlackChat.ts        | 21 ++++++-----
 packages/chat/slack/src/internal/adapter.ts | 41 ++++++++++++++-------
 packages/chat/slack/test/SlackChat.test.ts  | 22 +++++++++++
 3 files changed, 61 insertions(+), 23 deletions(-)

diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 2d2489aef0d..d5cd5484379 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -119,11 +119,12 @@ export class SlackChat extends Context.Service
-          bounded(call("post", "files.delete", { file }, { write: true }), Errors.transport(true, "timeout")).pipe(
-            Effect.ignore
-          ),
-        { discard: true }
-      )
+      const removeFiles = bounded(
+        Effect.forEach(fileIds, (file) => call("post", "files.delete", { file }, { write: true }).pipe(Effect.ignore), {
+          concurrency: "unbounded",
+          discard: true
+        }),
+        Errors.transport(true, "timeout")
+      ).pipe(Effect.ignore)
       const ts = yield* bounded(
         call("post", "chat.postMessage", {
           channel,
@@ -398,7 +405,13 @@ export const make = (options: {
           Errors.transport(false, "timeout")
         ),
         "edit"
-      )).pipe(Effect.result)
+      )).pipe(
+        Effect.timeoutOrElse({
+          duration: attachDeadline,
+          orElse: () => fail("post", Errors.transport(false, "attach_deadline"))
+        }),
+        Effect.result
+      )
       if (Result.isSuccess(attached)) return posted
 
       const error = attached.failure
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index ecb10083aab..4f3975468dd 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -325,6 +325,28 @@ describe("files", () => {
     )
   })
 
+  it.effect("a long Retry-After on the attach is cut off by its deadline and rolled back, even when interrupted", () => {
+    const fake = makeFake({
+      ...upload(["F1"]),
+      "chat.postMessage": posted(ts),
+      "chat.update": { status: 429, headers: { "retry-after": "3600" } }
+    })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const fiber = yield* Effect.forkChild(slack.post(channelThread, { markdown: "x", files: [file("a")] }))
+        yield* TestClock.adjust("1 second")
+        const interrupting = yield* Effect.forkChild(Fiber.interrupt(fiber))
+        yield* TestClock.adjust("61 seconds")
+        yield* Fiber.join(interrupting)
+        assert.strictEqual(fake.called("chat.update").length, 1)
+        assert.deepStrictEqual(fake.called("chat.delete")[0].params, { channel, ts })
+        assert.deepStrictEqual(fake.called("files.delete").map((call) => call.params.file), ["F1"])
+      })
+    )
+  })
+
   it.effect("a refused attach deletes the message and the files and fails file_refused", () => {
     const fake = makeFake({
       ...upload(["F1"]),

From 3b2bdc164ff780cf7d43a92071eaf71054bb9904 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 07:37:30 +0000
Subject: [PATCH 26/89] Add buttons and modals to effect/chat and ChatTest

---
 .changeset/chat-adapters-actions.md           |    6 +
 .changeset/effect-chat-buttons.md             |    7 +
 packages/chat/discord/src/internal/adapter.ts |   12 +-
 .../chat/discord/test/DiscordChat.test.ts     |   23 +
 packages/chat/slack/src/internal/adapter.ts   |   10 +
 packages/chat/slack/test/SlackChat.test.ts    |   33 +
 packages/effect/src/chat/ChatAdapter.ts       |   49 +-
 packages/effect/src/chat/ChatError.ts         |   23 +-
 packages/effect/src/chat/ChatInteraction.ts   | 1531 +++++++++++++++++
 packages/effect/src/chat/ChatMarkdown.ts      |   92 +-
 packages/effect/src/chat/ChatTest.ts          |  693 +++++++-
 packages/effect/src/chat/ChatUi.ts            |  320 ++++
 packages/effect/src/chat/index.ts             |   12 +
 .../effect/test/chat/ChatInteraction.test.ts  |  269 +++
 .../effect/test/chat/ChatMarkdown.test.ts     |   37 +-
 packages/effect/test/chat/ChatTest.test.ts    |  226 ++-
 .../typetest/chat/ChatInteraction.tst.ts      |  121 ++
 17 files changed, 3408 insertions(+), 56 deletions(-)
 create mode 100644 .changeset/chat-adapters-actions.md
 create mode 100644 .changeset/effect-chat-buttons.md
 create mode 100644 packages/effect/src/chat/ChatInteraction.ts
 create mode 100644 packages/effect/src/chat/ChatUi.ts
 create mode 100644 packages/effect/test/chat/ChatInteraction.test.ts
 create mode 100644 packages/effect/typetest/chat/ChatInteraction.tst.ts

diff --git a/.changeset/chat-adapters-actions.md b/.changeset/chat-adapters-actions.md
new file mode 100644
index 00000000000..01da68acf2f
--- /dev/null
+++ b/.changeset/chat-adapters-actions.md
@@ -0,0 +1,6 @@
+---
+"@effect/chat-slack": patch
+"@effect/chat-discord": patch
+---
+
+Refuse a post or edit that carries buttons or selects with `Unsupported` instead of posting it without them, until the adapters support them.
diff --git a/.changeset/effect-chat-buttons.md b/.changeset/effect-chat-buttons.md
new file mode 100644
index 00000000000..847fbdf21b2
--- /dev/null
+++ b/.changeset/effect-chat-buttons.md
@@ -0,0 +1,7 @@
+---
+"effect": patch
+---
+
+Add buttons, selects and modals to `effect/chat`. The new `ChatUi` module has the elements, and the new `ChatInteraction` module has typed definitions, groups, `handle` with its deadline, and `layer`. `post` and `edit` take `actions`, `ChatMarkdown.post` sends them with the last part, and `Descriptor.measure` measures them. `ChatTest` gains `click`, `submit`, `interact`, `checkInteraction`, the `interactions` conformance hook and the buttons and modals rules.
+
+The conformance rules `unsupported/buttons` and `unsupported/selects` run against every adapter, without a new capability. A third-party adapter that ignores `actions` and posts anyway will start failing them. It should fail `Unsupported` naming `buttons` or `selects` until it supports them.
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index 4c785162e6a..225c19db5be 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -10,9 +10,10 @@ import {
   type ThreadInfo,
   type User
 } from "effect/chat/ChatAdapter"
-import { type ChatError, type ChatErrorReason, TooLarge } from "effect/chat/ChatError"
+import { type ChatError, type ChatErrorReason, TooLarge, Unsupported } from "effect/chat/ChatError"
 import type { ChatMessage } from "effect/chat/ChatMessage"
 import type * as ChatThread from "effect/chat/ChatThread"
+import type { Action } from "effect/chat/ChatUi"
 import * as DateTime from "effect/DateTime"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
@@ -113,6 +114,13 @@ export const make = Effect.fnUntraced(function*(options: {
 
   const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
 
+  /** The descriptor lists no buttons or selects yet, so a write that carries them is refused, never sent without them. */
+  const refuseActions = (op: string, actions: ReadonlyArray | undefined) =>
+    actions === undefined || actions.length === 0 ? Effect.void : fail(
+      op,
+      new Unsupported({ capability: actions.some((action) => action._tag !== "Select") ? "buttons" : "selects" })
+    )
+
   /** One REST call, its failure mapped to a `ChatError` and retried when nothing happened. */
   const call = (op: string, effect: Effect.Effect, write = false): Effect.Effect =>
     retrySafe(Effect.mapError(effect, (error) => Errors.chatError(op, Errors.reasonForRestError(error, { write }))))
@@ -176,6 +184,7 @@ export const make = Effect.fnUntraced(function*(options: {
   const post: ChatAdapter["post"] = Effect.fnUntraced(function*(thread, content) {
     const op = "post"
     const channelId = yield* resolve(op, thread)
+    yield* refuseActions(op, content.actions)
     const postOptions = yield* CurrentPostOptions
     yield* checkMessageLength(descriptor, op, content.markdown)
     const files = content.files ?? []
@@ -204,6 +213,7 @@ export const make = Effect.fnUntraced(function*(options: {
   const edit: ChatAdapter["edit"] = Effect.fnUntraced(function*(thread, messageId, content) {
     const op = "edit"
     const channelId = yield* resolve(op, thread)
+    yield* refuseActions(op, content.actions)
     const postOptions = yield* CurrentPostOptions
     yield* checkMessageLength(descriptor, op, content.markdown)
     yield* call(
diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index 31f57b94e71..9240f63302b 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -217,6 +217,29 @@ describe("post", () => {
   })
 })
 
+describe("buttons and selects", () => {
+  it.effect("are refused with Unsupported until the adapter supports them, calling nothing", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const post = yield* reason(discord.post(channel, {
+          markdown: "x",
+          actions: [{ _tag: "Button", id: "go", label: "Go" }]
+        }))
+        assert.deepStrictEqual([post.op, post.tag], ["post", "Unsupported"])
+        const edit = yield* reason(discord.edit(channel, "1", {
+          markdown: "x",
+          actions: [{ _tag: "Select", id: "pick", options: [{ label: "A", value: "a" }] }]
+        }))
+        assert.deepStrictEqual([edit.op, edit.tag], ["edit", "Unsupported"])
+        assert.strictEqual(fake.called("createMessage").length + fake.called("updateMessage").length, 0)
+      })
+    )
+  })
+})
+
 describe("edit", () => {
   it.effect("sends allowed_mentions and the SUPPRESS_EMBEDS flag on every edit", () => {
     const fake = makeFake({ updateMessage: () => Effect.succeed(posted) })
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 00f767a4c46..e1e273bed2c 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -16,6 +16,7 @@ import {
 } from "effect/chat/ChatError"
 import type { ChatMessage } from "effect/chat/ChatMessage"
 import type { ChatThread } from "effect/chat/ChatThread"
+import type { Action } from "effect/chat/ChatUi"
 import * as Clock from "effect/Clock"
 import * as DateTime from "effect/DateTime"
 import * as Duration from "effect/Duration"
@@ -162,6 +163,13 @@ export const make = (options: {
 
   const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
 
+  /** The descriptor lists no buttons or selects yet, so a write that carries them is refused, never sent without them. */
+  const refuseActions = (op: string, actions: ReadonlyArray | undefined) =>
+    actions === undefined || actions.length === 0 ? Effect.void : fail(
+      op,
+      new Unsupported({ capability: actions.some((action) => action._tag !== "Select") ? "buttons" : "selects" })
+    )
+
   /**
    * The pace of the writes that grow one reply: stream appends, the starts
    * of its later parts, and edits.
@@ -646,6 +654,7 @@ export const make = (options: {
     post: Effect.fnUntraced(function*(thread, content) {
       const parts = yield* resolve("post", thread)
       if (content.replyTo !== undefined) return yield* fail("post", new Unsupported({ capability: "replyTo" }))
+      yield* refuseActions("post", content.actions)
       const postOptions = yield* CurrentPostOptions
       const notify = postOptions.notify ?? {}
       const unfurl = postOptions.unfurl === true
@@ -664,6 +673,7 @@ export const make = (options: {
     }),
     edit: Effect.fnUntraced(function*(thread, messageId, content) {
       const parts = yield* resolve("edit", thread)
+      yield* refuseActions("edit", content.actions)
       const postOptions = yield* CurrentPostOptions
       const body = yield* messageContent(
         "edit",
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 4f3975468dd..70dfcb8d63c 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -183,6 +183,39 @@ describe("post", () => {
     ))
 })
 
+describe("buttons and selects", () => {
+  const button = { _tag: "Button", id: "go", label: "Go" } as const
+  const select = { _tag: "Select", id: "pick", options: [{ label: "A", value: "a" }] } as const
+
+  it.effect("are refused with Unsupported until the adapter supports them, calling nothing", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const post = yield* reason(slack.post(channelThread, { markdown: "x", actions: [button] }))
+        assert.deepStrictEqual([post.op, post.tag], ["post", "Unsupported"])
+        const edit = yield* reason(slack.edit(channelThread, "1.2", { markdown: "x", actions: [select] }))
+        assert.deepStrictEqual([edit.op, edit.tag], ["edit", "Unsupported"])
+        assert.strictEqual(fake.called("chat.postMessage").length + fake.called("chat.update").length, 0)
+      })
+    )
+  })
+
+  it.effect("pass unsupported/buttons and unsupported/selects over the stub", () => {
+    const rules = conformance({
+      platform: "slack",
+      thread: channelThread,
+      userPosts: () => Effect.die("unused"),
+      parseMention: SlackChat.parseMention
+    })
+    return run(
+      makeFake({ "auth.test": authTest }),
+      Effect.andThen(rules["unsupported/buttons"], rules["unsupported/selects"])
+    )
+  })
+})
+
 describe("files", () => {
   const upload = (ids: ReadonlyArray) => {
     let next = 0
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index 4da7b848552..ec599964913 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -33,6 +33,7 @@ import { ChatError, TooLarge } from "./ChatError.ts"
 import type { ThreadKind } from "./ChatEvent.ts"
 import type { Attachment, ChatMessage, ReplyTo } from "./ChatMessage.ts"
 import type { ChatThread } from "./ChatThread.ts"
+import type { Action } from "./ChatUi.ts"
 import { RetriesDisabled } from "./internal/retries.ts"
 
 /**
@@ -51,11 +52,30 @@ import { RetriesDisabled } from "./internal/retries.ts"
  *   adapter sends for the text, and it adds up:
  *   `measure(a + b) <= measure(a) + measure(b)`. It measures ASCII letters
  *   at one each.
+ * - `measure` takes the `actions` a message carries as an optional second
+ *   argument. Where text and elements share one budget (Slack) they add to
+ *   the cost, and elsewhere the argument is ignored. With it,
+ *   `measure(md, actions) <= measure(md) + measure("", actions)`, so a caller
+ *   can set room aside for the elements before it cuts the text,
+ *   `measure(md, actions) >= measure(md)`, and `measure(md, [])` is
+ *   `measure(md)`. A `measure` with one parameter fits the type.
  * - `limits.minWriteInterval` is the default floor between two writes to one
  *   thread, for streamed and multi-part posts.
  * - `limits.streamLength` and `limits.streamAge` apply to native streams
  *   only. `streamLength` is never more than `messageLength`, so a stream's
  *   text always fits an `edit`.
+ * - `limits.actionsPerMessage`, `limits.actionDataLength`,
+ *   `limits.modalMetadataLength` and `limits.modalFields` are there exactly
+ *   when the matching capability is (`buttons` for the first two, `modals`
+ *   for the last two). Each is the platform's number in the platform's unit,
+ *   as `messageLength` is. The adapter checks them exactly and fails
+ *   `TooLarge`: before the call for a message's elements, and before it
+ *   opens a modal.
+ *
+ * **Gotchas**
+ *
+ * Title and label limits of a modal are not on the descriptor. The adapter
+ * checks them the same way, and its docs list them.
  *
  * @stability unstable
  * @category models
@@ -64,7 +84,7 @@ import { RetriesDisabled } from "./internal/retries.ts"
 export interface Descriptor {
   readonly platform: string
   readonly capabilities: ReadonlySet
-  readonly measure: (markdown: string) => number
+  readonly measure: (markdown: string, actions?: ReadonlyArray) => number
   readonly limits: {
     readonly messageLength: number
     readonly filesPerMessage: number
@@ -72,6 +92,14 @@ export interface Descriptor {
     readonly minWriteInterval: Duration.Duration
     readonly streamLength?: number | undefined
     readonly streamAge?: Duration.Duration | undefined
+    /** How many elements one message's `actions` may hold. */
+    readonly actionsPerMessage?: number | undefined
+    /** The most an element's id and encoded value may take together. */
+    readonly actionDataLength?: number | undefined
+    /** The most a modal's id and its encoded metadata may take together, after what the adapter adds. */
+    readonly modalMetadataLength?: number | undefined
+    /** How many inputs and texts one modal may hold. */
+    readonly modalFields?: number | undefined
   }
 }
 
@@ -160,6 +188,11 @@ export interface User {
  *   none. It is get-or-create, and the only way from an opener to its thread.
  * - `opener` is the message a thread hangs off: `None` for a channel or
  *   direct address, or when it was deleted.
+ * - `actions` is a flat list of elements beside the Markdown, and the
+ *   adapter lays out the rows. A platform without an element fails
+ *   `Unsupported` before the call, naming `buttons` or `selects`. An
+ *   `edit` replaces the whole message, so an edit without `actions`
+ *   removes them.
  *
  * @stability unstable
  * @category models
@@ -170,11 +203,15 @@ export interface Ops {
     readonly markdown: string
     readonly replyTo?: ReplyTo | undefined
     readonly files?: ReadonlyArray | undefined
+    readonly actions?: ReadonlyArray | undefined
   }) => Effect.Effect
   readonly edit: (
     thread: ChatThread,
     messageId: string,
-    content: { readonly markdown: string }
+    content: {
+      readonly markdown: string
+      readonly actions?: ReadonlyArray | undefined
+    }
   ) => Effect.Effect
   readonly delete: (thread: ChatThread, messageId: string) => Effect.Effect
   readonly fetchMessage: (thread: ChatThread, messageId: string) => Effect.Effect
@@ -316,7 +353,8 @@ export const layer = (
  * Pass the string the adapter is about to send, after escaping. For a
  * `measure` that counts what escaping adds, measuring the escaped string
  * gives the exact cost, so a post is neither refused when the platform would
- * take it nor passed when the platform would refuse it on length.
+ * take it nor passed when the platform would refuse it on length. Pass the
+ * message's `actions` too, so they are measured with it.
  *
  * @stability unstable
  * @category validation
@@ -325,9 +363,10 @@ export const layer = (
 export const checkMessageLength = (
   descriptor: Descriptor,
   op: string,
-  markdown: string
+  markdown: string,
+  actions?: ReadonlyArray | undefined
 ): Effect.Effect =>
-  descriptor.measure(markdown) <= descriptor.limits.messageLength ? Effect.void : Effect.fail(
+  descriptor.measure(markdown, actions ?? []) <= descriptor.limits.messageLength ? Effect.void : Effect.fail(
     new ChatError({
       platform: descriptor.platform,
       op,
diff --git a/packages/effect/src/chat/ChatError.ts b/packages/effect/src/chat/ChatError.ts
index ab86b132d6f..d31cae882bb 100644
--- a/packages/effect/src/chat/ChatError.ts
+++ b/packages/effect/src/chat/ChatError.ts
@@ -51,6 +51,13 @@ export type Retry = typeof Retry.Type
 /**
  * Schema for a capability name from `ChatAdapter.Descriptor`.
  *
+ * **Details**
+ *
+ * - `buttons` covers buttons and link buttons, `selects` selects on a
+ *   message, and `modals` opening a modal from a click.
+ * - `modalErrors` is field errors put back into an open modal. A platform
+ *   without it answers `errors` some other way, so no op fails for it.
+ *
  * @stability unstable
  * @category schemas
  * @since 4.1.5
@@ -67,7 +74,11 @@ export const Capability = Schema.Literals([
   "getThread",
   "opener",
   "getUser",
-  "nativeStream"
+  "nativeStream",
+  "buttons",
+  "selects",
+  "modals",
+  "modalErrors"
 ])
 
 /**
@@ -88,6 +99,16 @@ export type Capability = typeof Capability.Type
  */
 export const fileRefused = "file_refused"
 
+/**
+ * Detail for a modal returned after the deadline: the reason is `NotFound`
+ * and the op `openModal`.
+ *
+ * @stability unstable
+ * @category constants
+ * @since 4.1.5
+ */
+export const interactionExpired = "interaction_expired"
+
 const detail = Schema.optionalKey(Schema.String)
 
 const cause = Schema.optional(Schema.Defect())
diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
new file mode 100644
index 00000000000..5c889fa93dd
--- /dev/null
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -0,0 +1,1531 @@
+/**
+ * Typed buttons, selects and modals, and the service that receives their
+ * clicks.
+ *
+ * A definition carries an element's id and the schemas of its values. It
+ * builds the element to post (`of`, `open`) and gives the typed slot of its
+ * handler, the way `Rpc` and `RpcGroup` do. A `group` of definitions becomes a
+ * layer of handlers, and `layer` provides the `Handler` service that adapters
+ * call.
+ *
+ * **Example** (A button that opens a modal)
+ *
+ * ```ts
+ * import { Effect, Layer, Schema } from "effect"
+ * import { ChatInteraction } from "effect/chat"
+ *
+ * const Deploy = Schema.Struct({ version: Schema.String })
+ *
+ * const Reject = ChatInteraction.button("reject", { label: "Reject", style: "danger", value: Deploy })
+ * const RejectReason = ChatInteraction.modal("reject-reason", {
+ *   title: "Reject deploy",
+ *   metadata: Deploy,
+ *   fields: {
+ *     reason: ChatInteraction.textInput({ label: "Reason", multiline: true })
+ *   }
+ * })
+ *
+ * const Interactions = ChatInteraction.group(Reject, RejectReason).toLayer({
+ *   reject: (click) => Effect.succeed(RejectReason.open({ metadata: click.value })),
+ *   "reject-reason": (submit) =>
+ *     submit.values.reason.length < 10
+ *       ? Effect.succeed(ChatInteraction.errors({ reason: "Say a bit more." }))
+ *       : Effect.succeed(ChatInteraction.close)
+ * }).pipe(Layer.provideMerge(ChatInteraction.layer()))
+ * ```
+ *
+ * **Details**
+ *
+ * - Clicks and submits are not `ChatEvent`s. They need an answer inside the
+ *   platform's 3 seconds, so they go to `Handler`, which answers by return
+ *   value and has no error channel.
+ * - Neither platform redelivers a click or a submit, so interactions carry no
+ *   dedupe key.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import * as Context from "../Context.ts"
+import type * as Duration from "../Duration.ts"
+import * as Effect from "../Effect.ts"
+import * as Exit from "../Exit.ts"
+import * as Fiber from "../Fiber.ts"
+import * as Layer from "../Layer.ts"
+import * as Option from "../Option.ts"
+import * as Schema from "../Schema.ts"
+import * as SchemaAST from "../SchemaAST.ts"
+import type { Scope } from "../Scope.ts"
+import { ChatError, interactionExpired, NotFound } from "./ChatError.ts"
+import { ChatThread } from "./ChatThread.ts"
+import * as ChatUi from "./ChatUi.ts"
+
+// -----------------------------------------------------------------------------
+// events
+// -----------------------------------------------------------------------------
+
+const origin = {
+  thread: ChatThread,
+  messageId: Schema.String,
+  userId: Schema.String,
+  raw: Schema.Json
+}
+
+/**
+ * Schema for a click on a button.
+ *
+ * **Details**
+ *
+ * - `value` is still encoded, and absent for a button with no value.
+ * - `thread` and `messageId` are where the message carrying the button
+ *   lives. `raw` is the platform's interaction payload.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export const ButtonClicked = Schema.TaggedStruct("ButtonClicked", {
+  id: Schema.String,
+  value: Schema.optionalKey(Schema.String),
+  ...origin
+})
+
+/**
+ * A click on a button.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export type ButtonClicked = typeof ButtonClicked.Type
+
+/**
+ * Schema for a choice in a select on a message. `value` is the chosen
+ * option's value, still encoded.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export const SelectChanged = Schema.TaggedStruct("SelectChanged", {
+  id: Schema.String,
+  value: Schema.String,
+  ...origin
+})
+
+/**
+ * A choice in a select on a message.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export type SelectChanged = typeof SelectChanged.Type
+
+/**
+ * Schema for a modal submit.
+ *
+ * **Details**
+ *
+ * - `thread` and `messageId` are those of the click that opened the modal. A
+ *   modal only opens from a click, so they are always there.
+ * - `metadata` is still encoded.
+ * - `values` are by field id, still encoded. An optional field left empty
+ *   has no key.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export const ModalSubmitted = Schema.TaggedStruct("ModalSubmitted", {
+  id: Schema.String,
+  metadata: Schema.optionalKey(Schema.String),
+  values: Schema.Record(Schema.String, Schema.String),
+  ...origin
+})
+
+/**
+ * A modal submit.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export type ModalSubmitted = typeof ModalSubmitted.Type
+
+/**
+ * Schema for what an adapter hands to `Handler`.
+ *
+ * **Details**
+ *
+ * Not part of `ChatEvent`: these need an answer inside the platform's 3
+ * seconds.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export const Interaction = Schema.Union([ButtonClicked, SelectChanged, ModalSubmitted])
+
+/**
+ * A click, a select choice or a modal submit.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export type Interaction = typeof Interaction.Type
+
+// -----------------------------------------------------------------------------
+// replies
+// -----------------------------------------------------------------------------
+
+/**
+ * Schema for the reply that acknowledges a click.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const Ack = Schema.TaggedStruct("Ack", {})
+
+/**
+ * The reply that acknowledges a click.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type Ack = typeof Ack.Type
+
+/**
+ * Schema for the reply that opens a modal. Only a click can return it.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const OpenModal = Schema.TaggedStruct("OpenModal", { modal: ChatUi.Modal })
+
+/**
+ * The reply that opens a modal.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type OpenModal = typeof OpenModal.Type
+
+/**
+ * Schema for the reply that closes a submitted modal.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const Close = Schema.TaggedStruct("Close", {})
+
+/**
+ * The reply that closes a submitted modal.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type Close = typeof Close.Type
+
+/**
+ * Schema for the reply that puts a message under each named field of a
+ * submitted modal. `errors` is by field id.
+ *
+ * **Details**
+ *
+ * With `modalErrors` the modal stays open with the messages under its
+ * fields. Without it the adapter answers some other way: on Discord a private
+ * reply lists them and the modal closes.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const Errors = Schema.TaggedStruct("Errors", {
+  errors: Schema.Record(Schema.String, Schema.String)
+})
+
+/**
+ * The reply that puts a message under each named field.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type Errors = typeof Errors.Type
+
+/**
+ * What a click's handler may answer.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type ClickReply = Ack | OpenModal
+
+/**
+ * What a submit's handler may answer.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type SubmitReply = Close | Errors
+
+/**
+ * Schema for what `handle` gives when the handler ran past the deadline.
+ *
+ * **Gotchas**
+ *
+ * `Late` is never sent to a platform. It is a tagged struct, so it is itself
+ * a JSON value: test for it with `Schema.is(ChatInteraction.Late)`.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const Late = Schema.TaggedStruct("Late", {})
+
+/**
+ * What `handle` gives when the handler ran past the deadline.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type Late = typeof Late.Type
+
+/**
+ * `Errors`, with the field ids it names kept in the type, so a typed submit
+ * handler can refuse a field the modal does not have. The extra property
+ * exists only in the type.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export interface FieldErrors extends Errors {
+  readonly "~fields"?: Field | undefined
+}
+
+/**
+ * Acknowledges a click.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const ack: Ack = Ack.make({})
+
+/**
+ * Closes a submitted modal.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const close: Close = Close.make({})
+
+/**
+ * Puts a message under each named field of a submitted modal.
+ *
+ * **Details**
+ *
+ * In a typed submit handler, only the modal's input ids are accepted.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const errors = (
+  errors: E
+): FieldErrors => Errors.make({ errors })
+
+// -----------------------------------------------------------------------------
+// typed events
+// -----------------------------------------------------------------------------
+
+/**
+ * A click as a button's handler receives it.
+ *
+ * **Details**
+ *
+ * `value` is decoded with the button's value schema, and `undefined` when it
+ * has none.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface Click {
+  readonly id: string
+  readonly value: Value
+  readonly thread: ChatThread
+  readonly messageId: string
+  readonly userId: string
+  readonly raw: Schema.Json
+}
+
+/**
+ * A choice as a select's handler receives it. `value` is the chosen option,
+ * decoded.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface Selected {
+  readonly id: string
+  readonly value: Value
+  readonly thread: ChatThread
+  readonly messageId: string
+  readonly userId: string
+  readonly raw: Schema.Json
+}
+
+/**
+ * A submit as a modal's handler receives it, with the metadata and values
+ * decoded.
+ *
+ * **Details**
+ *
+ * `values` has one key per input and none for `text`. An optional input left
+ * empty is `undefined`.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface Submit {
+  readonly id: string
+  readonly metadata: Metadata
+  readonly values: Values
+  readonly thread: ChatThread
+  readonly messageId: string
+  readonly userId: string
+  readonly raw: Schema.Json
+}
+
+// -----------------------------------------------------------------------------
+// values
+// -----------------------------------------------------------------------------
+
+/**
+ * The type id of definitions and groups.
+ *
+ * @stability unstable
+ * @category type ids
+ * @since 4.1.5
+ */
+export const TypeId = "~effect/chat/ChatInteraction"
+
+/**
+ * A value's schema.
+ *
+ * **Details**
+ *
+ * It may not need services, because it is encoded inside `of` and `open`,
+ * which are plain functions.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type ValueSchema = Schema.Codec
+
+type TypeOf = S extends ValueSchema ? S["Type"] : Fallback
+
+interface Wire {
+  readonly raw: boolean
+  readonly encode: (value: unknown) => unknown
+  readonly decode: (encoded: unknown) => Option.Option
+}
+
+const wires = new WeakMap()
+
+const stringOnly = (ast: SchemaAST.AST): boolean => {
+  switch (ast._tag) {
+    case "String":
+    case "TemplateLiteral":
+      return true
+    case "Literal":
+      return typeof ast.literal === "string"
+    case "Union":
+      return ast.types.length > 0 && ast.types.every(stringOnly)
+    default:
+      return false
+  }
+}
+
+const wireOf = (schema: ValueSchema): Wire => {
+  let wire = wires.get(schema)
+  if (wire === undefined) {
+    const codec = Schema.toCodecJson(schema)
+    const decode = Schema.decodeUnknownOption(codec)
+    wire = {
+      raw: stringOnly(SchemaAST.toEncoded(codec.ast)),
+      encode: Schema.encodeUnknownSync(codec),
+      decode: (encoded) => {
+        try {
+          return decode(encoded)
+        } catch {
+          return Option.none()
+        }
+      }
+    }
+    wires.set(schema, wire)
+  }
+  return wire
+}
+
+/**
+ * Encodes a value into the string an element carries.
+ *
+ * **When to use**
+ *
+ * Use when routing clicks yourself. `of` and `open` already run it.
+ *
+ * **Details**
+ *
+ * The value goes through `Schema.toCodecJson`. The form on the wire is decided
+ * once per schema, from the codec's encoded side, never per value:
+ *
+ * - when the encoded side can only be a string (`String`, a brand of it,
+ *   string literals, a template literal, or a union of those), the string is
+ *   sent as it is
+ * - otherwise the encoded value goes through `JSON.stringify`, and back
+ *   through `JSON.parse`
+ *
+ * **Gotchas**
+ *
+ * Throws when the value has no JSON form, as `Schema.encodeSync` does.
+ *
+ * @stability unstable
+ * @category values
+ * @since 4.1.5
+ */
+export const encodeValue = (schema: S, value: S["Type"]): string => {
+  const wire = wireOf(schema)
+  const encoded = wire.encode(value)
+  if (wire.raw) return encoded as string
+  const json = JSON.stringify(encoded)
+  if (json === undefined) throw new Error("ChatInteraction.encodeValue: the value has no JSON form")
+  return json
+}
+
+/**
+ * Decodes the string an element carried, as `encodeValue` wrote it.
+ *
+ * **Details**
+ *
+ * Gives none for a string that no longer decodes, which is what a value
+ * posted under an older schema can do.
+ *
+ * @stability unstable
+ * @category values
+ * @since 4.1.5
+ */
+export const decodeValue = (schema: S, encoded: string): Option.Option => {
+  const wire = wireOf(schema)
+  if (wire.raw) return wire.decode(encoded)
+  let parsed: unknown
+  try {
+    parsed = JSON.parse(encoded)
+  } catch {
+    return Option.none()
+  }
+  return wire.decode(parsed)
+}
+
+const optional = (key: K, value: V | undefined): { readonly [P in K]?: V } =>
+  (value === undefined ? {} : { [key]: value }) as { readonly [P in K]?: V }
+
+// -----------------------------------------------------------------------------
+// definitions
+// -----------------------------------------------------------------------------
+
+/**
+ * A button definition.
+ *
+ * **Details**
+ *
+ * `of` gives the element to post. It takes the value when the definition has
+ * a schema for one, and `overrides` change the label or style of this one
+ * element.
+ *
+ * **Gotchas**
+ *
+ * `of` throws when the value cannot be encoded (a schema with no JSON form),
+ * as `Schema.encodeSync` does.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export interface Button {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "button"
+  readonly id: Id
+  readonly label: string
+  readonly style: ChatUi.ButtonStyle | undefined
+  readonly value: Value
+  readonly of: (
+    ...args: Value extends ValueSchema ? [value: Value["Type"], overrides?: Button.Overrides]
+      : [overrides?: Button.Overrides]
+  ) => ChatUi.Button
+}
+
+/**
+ * Types that go with a button definition.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+export declare namespace Button {
+  /**
+   * What one element may change from its definition.
+   *
+   * @stability unstable
+   * @category models
+   * @since 4.1.5
+   */
+  export interface Overrides {
+    readonly label?: string | undefined
+    readonly style?: ChatUi.ButtonStyle | undefined
+  }
+}
+
+/**
+ * Defines a button.
+ *
+ * **Details**
+ *
+ * - The id names the handler in a `group`. It is sent to the platform as is,
+ *   and counts toward `limits.actionDataLength` with the encoded value.
+ * - With no `value` schema the button carries no value, and its click's
+ *   `value` is `undefined`.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export const button = (
+  id: Id,
+  options: {
+    readonly label: string
+    readonly style?: ChatUi.ButtonStyle | undefined
+    readonly value?: Value
+  }
+): Button => {
+  const value = options.value as Value
+  return {
+    [TypeId]: TypeId,
+    kind: "button",
+    id,
+    label: options.label,
+    style: options.style,
+    value,
+    of: ((...args: ReadonlyArray): ChatUi.Button => {
+      const overrides: Button.Overrides | undefined = value === undefined ? args[0] : args[1]
+      return {
+        _tag: "Button",
+        id,
+        label: overrides?.label ?? options.label,
+        ...optional("style", overrides?.style ?? options.style),
+        ...optional("value", value === undefined ? undefined : encodeValue(value, args[0]))
+      }
+    }) as Button["of"]
+  }
+}
+
+/**
+ * A select definition, for a message. Its options are given at the post, to
+ * `of`.
+ *
+ * **Gotchas**
+ *
+ * `of` throws when an option's value cannot be encoded.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export interface Select {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "select"
+  readonly id: Id
+  readonly placeholder: string | undefined
+  readonly value: Value
+  readonly of: (options: {
+    readonly options: ReadonlyArray<{ readonly label: string; readonly value: TypeOf }>
+    readonly selected?: TypeOf | undefined
+  }) => ChatUi.Select
+}
+
+/**
+ * Defines a single-choice select for a message.
+ *
+ * **Details**
+ *
+ * With no `value` schema the options' values are plain strings.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export const select = (
+  id: Id,
+  options: {
+    readonly placeholder?: string | undefined
+    readonly value?: Value
+  }
+): Select => {
+  const value = options.value as Value
+  const encode = (option: unknown): string => value === undefined ? option as string : encodeValue(value, option)
+  return {
+    [TypeId]: TypeId,
+    kind: "select",
+    id,
+    placeholder: options.placeholder,
+    value,
+    of: (args) => ({
+      _tag: "Select",
+      id,
+      ...optional("placeholder", options.placeholder),
+      options: args.options.map((option) => ({ label: option.label, value: encode(option.value) })),
+      ...optional("selected", args.selected === undefined ? undefined : encode(args.selected))
+    })
+  }
+}
+
+/**
+ * A text input in a modal, one line or several.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export interface TextInput {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "textInput"
+  readonly label: string
+  readonly multiline: boolean
+  readonly placeholder: string | undefined
+  readonly optional: Optional
+  readonly minLength: number | undefined
+  readonly maxLength: number | undefined
+}
+
+/**
+ * Defines a text input for a modal. Its id is its key in `fields`.
+ *
+ * **Details**
+ *
+ * Its value is a `string`, or `string | undefined` when `optional` is true.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export const textInput = (options: {
+  readonly label: string
+  readonly multiline?: boolean | undefined
+  readonly placeholder?: string | undefined
+  readonly optional?: Optional | undefined
+  readonly minLength?: number | undefined
+  readonly maxLength?: number | undefined
+}): TextInput> => ({
+  [TypeId]: TypeId,
+  kind: "textInput",
+  label: options.label,
+  multiline: options.multiline ?? false,
+  placeholder: options.placeholder,
+  optional: (options.optional ?? false) as Optional,
+  minLength: options.minLength,
+  maxLength: options.maxLength
+})
+
+/**
+ * A select in a modal whose options are fixed in the definition.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export interface Choice {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "choice"
+  readonly label: string
+  readonly placeholder: string | undefined
+  readonly options: ReadonlyArray<{ readonly label: string; readonly value: Value }>
+  readonly optional: Optional
+}
+
+/**
+ * Defines a select for a modal whose options are fixed here. Its value is the
+ * union of the option values.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export const choice = (options: {
+  readonly label: string
+  readonly placeholder?: string | undefined
+  readonly options: ReadonlyArray<{ readonly label: string; readonly value: Value }>
+  readonly optional?: Optional | undefined
+}): Choice> => ({
+  [TypeId]: TypeId,
+  kind: "choice",
+  label: options.label,
+  placeholder: options.placeholder,
+  options: options.options,
+  optional: (options.optional ?? false) as Optional
+})
+
+/**
+ * A select in a modal whose options are given when the modal opens.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export interface SelectInput<
+  out Value extends ValueSchema | undefined = undefined,
+  out Optional extends boolean = false
+> {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "selectInput"
+  readonly label: string
+  readonly placeholder: string | undefined
+  readonly value: Value
+  readonly optional: Optional
+}
+
+/**
+ * Defines a select for a modal. Its id is its key in `fields`, and its
+ * options are given to the modal's `open`.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export const selectInput = <
+  Value extends ValueSchema | undefined = undefined,
+  const Optional extends boolean = false
+>(options: {
+  readonly label: string
+  readonly placeholder?: string | undefined
+  readonly value?: Value
+  readonly optional?: Optional | undefined
+}): SelectInput> => ({
+  [TypeId]: TypeId,
+  kind: "selectInput",
+  label: options.label,
+  placeholder: options.placeholder,
+  value: options.value as Value,
+  optional: (options.optional ?? false) as Optional
+})
+
+/**
+ * Plain text between a modal's inputs.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export interface Text {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "text"
+  readonly text: string
+}
+
+/**
+ * Defines plain text for a modal. It has no value, so its key is not in
+ * `submit.values`.
+ *
+ * **Gotchas**
+ *
+ * The text is plain, not Markdown.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export const text = (text: string): Text => ({ [TypeId]: TypeId, kind: "text", text })
+
+/**
+ * Any field of a modal.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export type Field = TextInput | Choice | SelectInput | Text
+
+/**
+ * A modal's fields by id, shown in key order.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export interface Fields {
+  readonly [id: string]: Field
+}
+
+type Maybe = Optional extends true ? A | undefined : A
+
+/**
+ * The decoded value of one field.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export type FieldValue = F extends TextInput ? Maybe
+  : F extends Choice ? Maybe
+  : F extends SelectInput ? Maybe, Optional>
+  : never
+
+/**
+ * `submit.values`: one key per input, none for `text`.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export type Values = {
+  readonly [K in keyof Fs as Fs[K] extends Text ? never : K]: FieldValue
+}
+
+/**
+ * The options `open` must be given: one list per `selectInput` field.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export type SelectOptions = {
+  readonly [K in keyof Fs as Fs[K] extends SelectInput ? K : never]: Fs[K] extends
+    SelectInput ? ReadonlyArray<{ readonly label: string; readonly value: TypeOf }>
+    : never
+}
+
+/**
+ * What a modal's `open` takes: the metadata when the modal has a schema for
+ * it, the options of each `selectInput`, and initial values.
+ *
+ * @stability unstable
+ * @category fields
+ * @since 4.1.5
+ */
+export type OpenOptions =
+  & (Metadata extends ValueSchema ? { readonly metadata: Metadata["Type"] } : {})
+  & ({} extends SelectOptions ? {} : { readonly options: SelectOptions })
+  & { readonly initial?: { readonly [K in keyof Values]?: Values[K] | undefined } | undefined }
+
+/**
+ * A modal definition.
+ *
+ * **Details**
+ *
+ * `open` gives the reply that opens the modal. Only a click can return it.
+ *
+ * **Gotchas**
+ *
+ * `open` throws when the metadata or an option's value cannot be encoded.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export interface Modal<
+  out Id extends string,
+  in out Metadata extends ValueSchema | undefined = undefined,
+  in out Fs extends Fields = {}
+> {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "modal"
+  readonly id: Id
+  readonly title: string
+  readonly submitLabel: string | undefined
+  readonly metadata: Metadata
+  readonly fields: Fs
+  readonly open: (
+    ...args: {} extends OpenOptions ? [options?: OpenOptions]
+      : [options: OpenOptions]
+  ) => OpenModal
+}
+
+/**
+ * Defines a modal.
+ *
+ * **Details**
+ *
+ * - The id names the submit's handler in a `group`. With the encoded
+ *   metadata it counts toward `limits.modalMetadataLength`.
+ * - Inputs and texts together count toward `limits.modalFields`.
+ *
+ * **Gotchas**
+ *
+ * A modal the platform will not take can only fail after the click's handler
+ * returned it: the adapter acks the click, opens nothing and calls
+ * `Handler.refused`. A portable modal has a title of 24 or less, labels of 45
+ * or less, at most 5 fields, and an id plus metadata under 100 characters.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export const modal = <
+  const Id extends string,
+  const Fs extends Fields,
+  Metadata extends ValueSchema | undefined = undefined
+>(
+  id: Id,
+  options: {
+    readonly title: string
+    readonly submitLabel?: string | undefined
+    readonly metadata?: Metadata
+    readonly fields: Fs
+  }
+): Modal => {
+  const metadata = options.metadata as Metadata
+  const open = (args?: {
+    readonly metadata?: unknown
+    readonly options?: { readonly [id: string]: ReadonlyArray<{ readonly label: string; readonly value: unknown }> }
+    readonly initial?: { readonly [id: string]: unknown }
+  }): OpenModal => {
+    const elements: Array = []
+    for (const [field, definition] of Object.entries(options.fields)) {
+      const initial = args?.initial?.[field]
+      switch (definition.kind) {
+        case "text": {
+          elements.push({ _tag: "Text", text: definition.text })
+          break
+        }
+        case "textInput": {
+          elements.push({
+            _tag: "TextInput",
+            id: field,
+            label: definition.label,
+            ...optional("multiline", definition.multiline ? true : undefined),
+            ...optional("placeholder", definition.placeholder),
+            ...optional("initial", initial as string | undefined),
+            ...optional("optional", definition.optional ? true : undefined),
+            ...optional("minLength", definition.minLength),
+            ...optional("maxLength", definition.maxLength)
+          })
+          break
+        }
+        case "choice":
+        case "selectInput": {
+          const schema: ValueSchema | undefined = definition.kind === "selectInput" ? definition.value : undefined
+          const encode = (value: unknown): string => schema === undefined ? value as string : encodeValue(schema, value)
+          const choices = definition.kind === "choice" ? definition.options : args?.options?.[field] ?? []
+          elements.push({
+            _tag: "SelectInput",
+            id: field,
+            label: definition.label,
+            ...optional("placeholder", definition.placeholder),
+            options: choices.map((option) => ({ label: option.label, value: encode(option.value) })),
+            ...optional("initial", initial === undefined ? undefined : encode(initial)),
+            ...optional("optional", definition.optional ? true : undefined)
+          })
+          break
+        }
+      }
+    }
+    return OpenModal.make({
+      modal: {
+        _tag: "Modal",
+        id,
+        title: options.title,
+        ...optional("submitLabel", options.submitLabel),
+        ...optional("metadata", metadata === undefined ? undefined : encodeValue(metadata, args?.metadata)),
+        elements
+      }
+    })
+  }
+  return {
+    [TypeId]: TypeId,
+    kind: "modal",
+    id,
+    title: options.title,
+    submitLabel: options.submitLabel,
+    metadata,
+    fields: options.fields,
+    open: open as Modal["open"]
+  }
+}
+
+/**
+ * Any definition that has a handler.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export type Definition = Button | Select | Modal
+
+// -----------------------------------------------------------------------------
+// decoding
+// -----------------------------------------------------------------------------
+
+const matches = (definition: Definition, event: Interaction): boolean => {
+  switch (event._tag) {
+    case "ButtonClicked":
+      return definition.kind === "button"
+    case "SelectChanged":
+      return definition.kind === "select"
+    case "ModalSubmitted":
+      return definition.kind === "modal"
+  }
+}
+
+const decodeSubmit = (definition: Modal, event: ModalSubmitted): Option.Option => {
+  let metadata: unknown = undefined
+  if (definition.metadata !== undefined) {
+    if (event.metadata === undefined) return Option.none()
+    const decoded = decodeValue(definition.metadata, event.metadata)
+    if (Option.isNone(decoded)) return decoded
+    metadata = decoded.value
+  }
+  const values: Record = {}
+  for (const [id, field] of Object.entries(definition.fields as Fields)) {
+    if (field.kind === "text") continue
+    const encoded = Object.hasOwn(event.values, id) ? event.values[id] : undefined
+    if (encoded === undefined) {
+      if (!field.optional) return Option.none()
+      values[id] = undefined
+      continue
+    }
+    switch (field.kind) {
+      case "textInput": {
+        values[id] = encoded
+        break
+      }
+      case "choice": {
+        if (!field.options.some((option) => option.value === encoded)) return Option.none()
+        values[id] = encoded
+        break
+      }
+      case "selectInput": {
+        if (field.value === undefined) {
+          values[id] = encoded
+          break
+        }
+        const decoded = decodeValue(field.value, encoded)
+        if (Option.isNone(decoded)) return decoded
+        values[id] = decoded.value
+        break
+      }
+    }
+  }
+  return Option.some({ ...base(event), metadata, values })
+}
+
+const base = (event: Interaction) => ({
+  id: event.id,
+  thread: event.thread,
+  messageId: event.messageId,
+  userId: event.userId,
+  raw: event.raw
+})
+
+/** The event as the definition's handler takes it, or none when its value no longer decodes. */
+const decodeEvent = (definition: Definition, event: Interaction): Option.Option => {
+  switch (event._tag) {
+    case "ButtonClicked": {
+      if (definition.kind !== "button") return Option.none()
+      if (definition.value === undefined) return Option.some({ ...base(event), value: undefined })
+      if (event.value === undefined) return Option.none()
+      return Option.map(decodeValue(definition.value, event.value), (value) => ({ ...base(event), value }))
+    }
+    case "SelectChanged": {
+      if (definition.kind !== "select") return Option.none()
+      if (definition.value === undefined) return Option.some({ ...base(event), value: event.value })
+      return Option.map(decodeValue(definition.value, event.value), (value) => ({ ...base(event), value }))
+    }
+    case "ModalSubmitted": {
+      return definition.kind === "modal" ? decodeSubmit(definition, event) : Option.none()
+    }
+  }
+}
+
+const fallback = (event: Interaction): ClickReply | SubmitReply => event._tag === "ModalSubmitted" ? close : ack
+
+// -----------------------------------------------------------------------------
+// groups
+// -----------------------------------------------------------------------------
+
+/**
+ * The handler a definition asks for. None has an error channel.
+ *
+ * **Details**
+ *
+ * A button or a select answers `ack` or a modal to open. A modal answers
+ * `close` or `errors` naming its own inputs.
+ *
+ * @stability unstable
+ * @category groups
+ * @since 4.1.5
+ */
+export type HandlerFor = D extends Button
+  ? (click: Click>) => Effect.Effect
+  : D extends Select ?
+    (selected: Selected>) => Effect.Effect
+  : D extends Modal ? (
+      submit: Submit, Values>
+    ) => Effect.Effect & string>, never, any>
+  : never
+
+/**
+ * One handler per id in the group.
+ *
+ * @stability unstable
+ * @category groups
+ * @since 4.1.5
+ */
+export type HandlersFrom = {
+  readonly [Current in D as Current["id"]]: HandlerFor
+}
+
+/**
+ * The services a set of handlers needs.
+ *
+ * @stability unstable
+ * @category groups
+ * @since 4.1.5
+ */
+export type HandlersServices = {
+  readonly [K in keyof Handlers]: Handlers[K] extends (...args: any) => Effect.Effect ? R : never
+}[keyof Handlers]
+
+/**
+ * A set of definitions whose handlers are registered together.
+ *
+ * **Details**
+ *
+ * - `toLayer` registers the handlers, with their services provided. It needs
+ *   the `Registry` that `ChatInteraction.layer` provides.
+ * - `of` is the identity, for handlers written away from `toLayer`.
+ *
+ * **Gotchas**
+ *
+ * Two definitions with one id, in one group or across groups, are a defect
+ * when the layer is built.
+ *
+ * @stability unstable
+ * @category groups
+ * @since 4.1.5
+ */
+export interface Group {
+  readonly [TypeId]: typeof TypeId
+  readonly definitions: ReadonlyMap
+  readonly add: >(...definitions: More) => Group
+  readonly merge: >>(
+    ...groups: Groups
+  ) => Group>
+  readonly toLayer: , EX = never, RX = never>(
+    build: Handlers | Effect.Effect
+  ) => Layer.Layer | HandlersServices | Registry>
+  readonly of: >(handlers: Handlers) => Handlers
+}
+
+/**
+ * Types that go with a group.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+export declare namespace Group {
+  /**
+   * The definitions of a group.
+   *
+   * @stability unstable
+   * @category groups
+   * @since 4.1.5
+   */
+  export type Definitions = G extends Group ? D : never
+}
+
+const groupLists = new WeakMap, ReadonlyArray>()
+
+const makeGroup = (list: ReadonlyArray): Group => {
+  const self: Group = {
+    [TypeId]: TypeId,
+    definitions: new Map(list.map((definition) => [definition.id, definition])),
+    add: (...definitions) => makeGroup([...list, ...definitions]),
+    merge: (...groups) => makeGroup([...list, ...groups.flatMap((group) => groupLists.get(group) ?? [])]) as any,
+    toLayer: (build) =>
+      Layer.effectDiscard(Effect.gen(function*() {
+        const handlers: Record Effect.Effect> = Effect.isEffect(build)
+          ? yield* build
+          : build as any
+        const context = yield* Effect.context()
+        const registry = yield* Registry
+        yield* registry.register(list.map((definition): Registered => ({
+          definition,
+          handle: (event) => {
+            const typed = decodeEvent(definition, event)
+            return Option.isNone(typed)
+              ? Effect.succeed(fallback(event))
+              : Effect.provideContext(handlers[definition.id](typed.value), context)
+          }
+        })))
+      })) as any,
+    of: (handlers) => handlers
+  }
+  groupLists.set(self, list)
+  return self
+}
+
+/**
+ * Groups definitions so their handlers can be registered together.
+ *
+ * @stability unstable
+ * @category groups
+ * @since 4.1.5
+ */
+export const group = >(
+  ...definitions: Definitions
+): Group => makeGroup(definitions)
+
+// -----------------------------------------------------------------------------
+// handler service and registry
+// -----------------------------------------------------------------------------
+
+/**
+ * What an adapter calls with an interaction. Public, for a consumer that
+ * routes clicks itself.
+ *
+ * **Details**
+ *
+ * - The contract is to answer inside the platform's 3 seconds. There is no
+ *   error channel: a handler that cannot do its work still has to answer.
+ * - `refused` is called when a click's handler returned `OpenModal` and no
+ *   modal opened, after the click was acked: by the adapter (the platform
+ *   has no `modals`, the modal's id plus metadata is over
+ *   `limits.modalMetadataLength`, it has more than `limits.modalFields`
+ *   fields, a title or label is too long, or the platform refused the call)
+ *   or by `handle` (the reply came after the deadline). Only a click can be
+ *   refused: a submit's replies always have an answer the adapter can give.
+ *
+ * **Gotchas**
+ *
+ * Neither platform redelivers a click or a submit, so there is no dedupe key.
+ * A submit can still arrive twice for one modal: a handler that runs past
+ * the deadline is interrupted, the platform shows its own error, the modal
+ * stays open and the user can submit again. Nothing marks the second one as
+ * a repeat, and the first run may have been cut off part way.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class Handler extends Context.Service Effect.Effect
+  readonly submit: (event: ModalSubmitted) => Effect.Effect
+  readonly refused: (event: ButtonClicked | SelectChanged, error: ChatError) => Effect.Effect
+}>()("effect/chat/ChatInteraction/Handler") {}
+
+const lateClick = (event: ButtonClicked | SelectChanged) =>
+  new ChatError({
+    platform: event.thread.platform,
+    op: "openModal",
+    reason: new NotFound({ detail: interactionExpired })
+  })
+
+/**
+ * Calls `Handler.click` or `Handler.submit` and gives the reply, or `Late`
+ * when `deadline` passes first.
+ *
+ * **When to use**
+ *
+ * Use to deliver an interaction from an adapter. This is the one place the
+ * deadline rule lives. Both adapters and
+ * `ChatTest` call it, and a third-party adapter should.
+ *
+ * **Details**
+ *
+ * - A late click leaves its handler running, detached from the caller. When
+ *   it later returns `OpenModal`, the modal is dropped and `Handler.refused`
+ *   is called with a `ChatError` whose reason is `NotFound`, op `openModal`,
+ *   detail `interaction_expired`, platform `event.thread.platform`.
+ * - A late submit interrupts its handler.
+ * - `deadline` is the handler's share of the platform's 3 seconds, not the 3
+ *   seconds. The adapter subtracts what its own answer costs. This function
+ *   knows no platform.
+ *
+ * **Gotchas**
+ *
+ * A late click's handler keeps running only if the runtime lets it. One that
+ * stops work once the response is sent (Cloudflare Workers without
+ * `waitUntil`) kills it.
+ *
+ * @stability unstable
+ * @category handling
+ * @since 4.1.5
+ */
+export const handle: {
+  (event: ButtonClicked | SelectChanged, deadline: Duration.Duration): Effect.Effect
+  (event: ModalSubmitted, deadline: Duration.Duration): Effect.Effect
+  (event: Interaction, deadline: Duration.Duration): Effect.Effect
+} = (event: Interaction, deadline: Duration.Duration): Effect.Effect =>
+  Effect.gen(function*() {
+    const handler = yield* Handler
+    if (event._tag === "ModalSubmitted") {
+      const reply = yield* Effect.timeoutOption(handler.submit(event), deadline)
+      return Option.isSome(reply) ? reply.value : late
+    }
+    const fiber = yield* Effect.forkDetach(handler.click(event))
+    const exit = yield* Effect.onInterrupt(
+      Effect.timeoutOption(Fiber.await(fiber), deadline),
+      () => Fiber.interrupt(fiber)
+    )
+    if (Option.isSome(exit)) return yield* exit.value
+    yield* Effect.forkDetach(Effect.flatMap(
+      Fiber.await(fiber),
+      (exit) =>
+        Exit.isSuccess(exit) && exit.value._tag === "OpenModal" ? handler.refused(event, lateClick(event)) : Effect.void
+    ))
+    return late
+  })
+
+const late: Late = Late.make({})
+
+/**
+ * One registered definition with its handler, services already provided.
+ *
+ * **Details**
+ *
+ * `handle` answers `ack` or `close` without calling the handler when the
+ * event does not match the definition or its value no longer decodes.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export interface Registered {
+  readonly definition: Definition
+  readonly handle: (event: Interaction) => Effect.Effect
+}
+
+/**
+ * Where groups put their handlers. `ChatInteraction.layer` provides it.
+ *
+ * **Details**
+ *
+ * `register` dies when an id is already registered.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class Registry extends Context.Service) => Effect.Effect
+  readonly get: (id: string) => Effect.Effect
+}>()("effect/chat/ChatInteraction/Registry") {}
+
+/**
+ * Why an interaction reached no handler, or why its handler's reply was not
+ * carried out.
+ *
+ * **Details**
+ *
+ * - `UnknownId`: no definition has the id, or it is a definition of another
+ *   kind.
+ * - `InvalidValue`: the value or metadata no longer decodes, or a required
+ *   input is missing.
+ * - `ReplyRefused`: `Handler.refused` was called, with the adapter's error.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Unhandled =
+  | { readonly reason: "UnknownId" | "InvalidValue" }
+  | { readonly reason: "ReplyRefused"; readonly error: ChatError }
+
+/**
+ * The `Handler` that routes by id to the registered definitions, and an
+ * empty `Registry`. Group layers go on top with `Layer.provideMerge`.
+ *
+ * **Details**
+ *
+ * - An interaction with an unknown id, or with a value that no longer
+ *   decodes, is logged and answered `ack` or `close`. `unhandled` sees it
+ *   first. It cannot change the answer.
+ * - `Handler.refused` is routed to `unhandled` too, as `ReplyRefused`, and
+ *   logged.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layer = (options?: {
+  readonly unhandled?: ((event: Interaction, why: Unhandled) => Effect.Effect) | undefined
+}): Layer.Layer =>
+  Layer.effectContext(Effect.gen(function*() {
+    const context = yield* Effect.context()
+    const entries = new Map()
+    const report = (event: Interaction, why: Unhandled, message: string): Effect.Effect =>
+      Effect.andThen(
+        options?.unhandled === undefined ? Effect.void : Effect.provideContext(options.unhandled(event, why), context),
+        Effect.logWarning(message).pipe(Effect.annotateLogs({
+          "chat.platform": event.thread.platform,
+          "chat.interaction.id": event.id,
+          "chat.interaction.reason": why.reason
+        }))
+      )
+    const route = (event: Interaction): Effect.Effect =>
+      Effect.suspend(() => {
+        const entry = entries.get(event.id)
+        if (entry === undefined || !matches(entry.definition, event)) {
+          return Effect.as(
+            report(event, { reason: "UnknownId" }, "ChatInteraction: no handler for this id"),
+            fallback(event)
+          )
+        }
+        if (Option.isNone(decodeEvent(entry.definition, event))) {
+          return Effect.as(
+            report(event, { reason: "InvalidValue" }, "ChatInteraction: the value no longer decodes"),
+            fallback(event)
+          )
+        }
+        return entry.handle(event)
+      })
+    const registry = Registry.of({
+      register: (registered) =>
+        Effect.suspend(() => {
+          const ids = new Set()
+          for (const entry of registered) {
+            const id = entry.definition.id
+            if (entries.has(id) || ids.has(id)) {
+              return Effect.die(new Error("ChatInteraction: the id \"" + id + "\" is already registered"))
+            }
+            ids.add(id)
+          }
+          for (const entry of registered) entries.set(entry.definition.id, entry)
+          return Effect.void
+        }),
+      get: (id) => Effect.sync(() => entries.get(id))
+    })
+    const handler = Handler.of({
+      click: (event) => route(event) as Effect.Effect,
+      submit: (event) => route(event) as Effect.Effect,
+      refused: (event, error) =>
+        report(event, { reason: "ReplyRefused", error }, "ChatInteraction: the reply was not carried out").pipe(
+          Effect.annotateLogs("chat.error", error.message)
+        )
+    })
+    return Context.make(Handler, handler).pipe(Context.add(Registry, registry))
+  }))
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index b6c20ebe440..aaf26d41502 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -37,9 +37,10 @@ import * as Stream from "../Stream.ts"
 import * as Chat from "./Chat.ts"
 import type { Descriptor, File, NativeStream, Posted } from "./ChatAdapter.ts"
 import { Registry } from "./ChatAdapter.ts"
-import { type ChatError, fileRefused } from "./ChatError.ts"
+import { ChatError, fileRefused, TooLarge } from "./ChatError.ts"
 import type { ReplyTo } from "./ChatMessage.ts"
 import type { ChatThread } from "./ChatThread.ts"
+import type { Action } from "./ChatUi.ts"
 
 /**
  * One message a call created.
@@ -377,6 +378,7 @@ interface ReplyOptions extends Options {
   readonly native?: NativeStream | undefined
   readonly recipient?: string | undefined
   readonly files?: ReadonlyArray | undefined
+  readonly actions?: ReadonlyArray | undefined
   readonly unattachedNote?: ((files: ReadonlyArray) => string) | undefined
 }
 
@@ -568,6 +570,12 @@ const reply = (options: ReplyOptions): Effect.Effect 0
+    const actions = options.actions ?? []
+    const hasActions = actions.length > 0
+    /** What the reply's last part costs, measured with the actions it carries. */
+    const measureLast = hasActions ? (markdown: string) => measure(markdown, actions) : measure
+    /** The last part takes the files and the actions. */
+    const hasExtras = hasFiles || hasActions
 
     // --- post-then-edit --------------------------------------------------------
 
@@ -580,7 +588,7 @@ const reply = (options: ReplyOptions): Effect.Effect {
@@ -604,8 +612,9 @@ const reply = (options: ReplyOptions): Effect.Effect => {
-      const files = withFiles ? options.files! : undefined
+      const files = withFiles && hasFiles ? options.files! : undefined
       const unattachedNote = files === undefined ? undefined : options.unattachedNote
+      const extras = withFiles && hasActions ? { actions } : {}
       const settle = (exit: Exit.Exit, markdown: string) => {
         if (Exit.isSuccess(exit)) {
           part.posted = exit.value
@@ -624,7 +633,8 @@ const reply = (options: ReplyOptions): Effect.Effect toPart(part, posted, markdown, end),
           (exit) => {
@@ -637,7 +647,7 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect limits.messageLength) {
-          const cut = part.start + fitCut(measure, body, part.fence, part.prefix, limits.messageLength)
-          // Only blank text follows the cut: this is the last part, so it takes the files and that text.
+        const cutAt = (cut: number): Effect.Effect => {
+          // Only blank text follows the cut: this is the last part, so it takes the files, the actions and that text.
           const last = final && isBlank(input.slice(cut))
           return Effect.flatMap(writeEdit(cut, true, last), () => {
             if (!isRunning()) return Effect.void
@@ -698,6 +707,16 @@ const reply = (options: ReplyOptions): Effect.Effect
+          !final || !hasActions || !isBlank(input.slice(cut)) ||
+          measureLast(render(part.prefix, input.slice(part.start, cut), part.fence)) <= limits.messageLength
+        const withActions = () => part.start + fitCut(measureLast, body, part.fence, part.prefix, limits.messageLength)
+        if (measure(render(part.prefix, body, part.fence)) > limits.messageLength) {
+          const cut = part.start + fitCut(measure, body, part.fence, part.prefix, limits.messageLength)
+          return cutAt(lastFits(cut) ? cut : withActions())
+        }
+        if (!lastFits(input.length)) return cutAt(withActions())
         return Effect.flatMap(writeEdit(input.length, final, final), () => {
           if (final && isRunning()) finishPart(input.length)
           return end(final)
@@ -936,19 +955,23 @@ const reply = (options: ReplyOptions): Effect.Effect, fallback: boolean) =>
-          create(chat.post(thread, { markdown, files: [file, ...files] }), part(markdown), (exit) => {
-            if (Exit.isSuccess(exit)) {
-              parts.push(part(markdown)(exit.value))
-              overflowStart = input.length
-              return done(false)
+          create(
+            chat.post(thread, { markdown, files: [file, ...files], ...(hasActions ? { actions } : {}) }),
+            part(markdown),
+            (exit) => {
+              if (Exit.isSuccess(exit)) {
+                parts.push(part(markdown)(exit.value))
+                overflowStart = input.length
+                return done(false)
+              }
+              if (fallback && isFileRefusal(exit)) return
+              if (unanswered(exit)) overflowUncertain = true
+              const error = firstError(exit)
+              if (error === undefined) return
+              overflowUncertain = error.retry === "uncertain"
+              failChat(error)
             }
-            if (fallback && isFileRefusal(exit)) return
-            if (unanswered(exit)) overflowUncertain = true
-            const error = firstError(exit)
-            if (error === undefined) return
-            overflowUncertain = error.retry === "uncertain"
-            failChat(error)
-          })
+          )
         const files = options.files ?? []
         const unattachedNote = files.length === 0 ? undefined : options.unattachedNote
         return Effect.flatMap(attempt("", files, unattachedNote !== undefined), (exit) =>
@@ -1108,11 +1131,15 @@ const reply = (options: ReplyOptions): Effect.Effect(
   markdown: string,
   options?: Options & {
     readonly files?: ReadonlyArray | undefined
+    readonly actions?: ReadonlyArray | undefined
     readonly unattachedNote?: ((files: ReadonlyArray) => string) | undefined
   }
 ): Effect.Effect =>
   Effect.gen(function*() {
     const chat = yield* Chat.Chat
-    const descriptor = yield* Effect.mapError(
-      chat.descriptor(thread.platform),
-      (error) => new ChatMarkdownError({ posted: [], remaining: markdown, cause: { _tag: "Chat", error } })
-    )
+    const failed = (error: ChatError) =>
+      new ChatMarkdownError({ posted: [], remaining: markdown, cause: { _tag: "Chat", error } })
+    const descriptor = yield* Effect.mapError(chat.descriptor(thread.platform), failed)
+    const actions = options?.actions ?? []
+    if (actions.length > 0 && descriptor.measure("", actions) > descriptor.limits.messageLength) {
+      return yield* Effect.fail(failed(
+        new ChatError({
+          platform: thread.platform,
+          op: "post",
+          reason: new TooLarge({ detail: "actions_too_long" })
+        })
+      ))
+    }
     return yield* reply({ ...options, thread, initial: markdown, descriptor, chat })
   }).pipe(Effect.withSpan("ChatMarkdown.post", { attributes: { "chat.platform": thread.platform } }))
 
@@ -1183,6 +1220,9 @@ export const post = (
  *
  * - There are no files: post them after the result, when it is known whether
  *   the reply stopped.
+ * - There are no actions either. Add them after the result with
+ *   `chat.edit(thread, last.messageId, { markdown: last.markdown, actions })`,
+ *   where `last` is the final entry of `Result.parts`.
  * - To stop a reply, end `deltas` with `Stream.interruptWhen` or
  *   `Stream.haltWhen`, so a `Result` still comes back. Interrupting the call
  *   leaves only the ids collected through `onPart`.
diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index 3dedcf9b28a..97ce03ff091 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -4,8 +4,9 @@
  * `layer` builds a whole chat in memory: `Chat`, its registry and one fake
  * adapter with configurable capabilities and fault injection. `conformance`
  * is the suite of rules every adapter obeys, as plain Effects keyed by rule
- * name. `checkMessage` and `checkEvent` assert the invariants every message
- * and event holds, for fixture tests and live runs.
+ * name. `checkMessage`, `checkEvent` and `checkInteraction` assert the
+ * invariants every message, event and interaction holds, for fixture tests
+ * and live runs.
  *
  * **Details**
  *
@@ -45,9 +46,11 @@ import type { ThreadKind } from "./ChatEvent.ts"
 import * as ChatEvent from "./ChatEvent.ts"
 import { ChatHandler } from "./ChatHandler.ts"
 import type { NotAccepted } from "./ChatHandler.ts"
+import * as ChatInteraction from "./ChatInteraction.ts"
 import type { Attachment, Mention, ReplyTo } from "./ChatMessage.ts"
 import * as ChatMessage from "./ChatMessage.ts"
 import * as ChatThread from "./ChatThread.ts"
+import type * as ChatUi from "./ChatUi.ts"
 
 /**
  * Reads a slice of `ChatMessage.text` as one of the platform's mention
@@ -84,6 +87,19 @@ export interface Call {
   readonly outcome: "ok" | ChatErrorReason["_tag"]
 }
 
+/**
+ * Error for a click on an element the message does not carry, or on a
+ * message that is gone.
+ *
+ * @stability unstable
+ * @category errors
+ * @since 4.1.5
+ */
+export class NoSuchElement extends Schema.TaggedError("effect/chat/ChatTest/NoSuchElement")(
+  "NoSuchElement",
+  { messageId: Schema.String, id: Schema.String }
+) {}
+
 /**
  * Service that controls the fake adapter built by `layer`.
  *
@@ -107,6 +123,23 @@ export interface Call {
  *   `NativeStream.stop` then reports `stopped: true`.
  * - `closeStream` closes a native stream from outside, so the next append
  *   gives `closed`, or `stopped` after a click.
+ * - `click` builds the click on element `id` of a message from what the
+ *   fake stored at `post` or `edit`, without delivering it. For a select,
+ *   `option` is the encoded value of the option to choose, the first by
+ *   default. It fails `NoSuchElement` when the message has no such element,
+ *   or no such option, or is gone.
+ * - `submit` builds the submit of a modal. It takes the click that opened
+ *   it, because an `OpenModal` reply does not say where it was opened from
+ *   and a `ModalSubmitted` has to. `values` are by field id, still
+ *   encoded, and an empty one is left out, as for an optional field left
+ *   empty.
+ * - `interact` delivers an interaction the way an adapter does: through
+ *   `ChatInteraction.handle` with the layer's `interactionDeadline`, then
+ *   the fake's own checks on an `OpenModal` (the `modals` capability,
+ *   `limits.modalMetadataLength` against the modal's id plus its encoded
+ *   metadata, and `limits.modalFields`), calling `Handler.refused` when one
+ *   fails. It succeeds with the handler's reply as it returned it, or
+ *   `Late`. An `OpenModal` shows in `calls` as op `openModal`.
  *
  * @stability unstable
  * @category services
@@ -134,6 +167,28 @@ export class ChatTest extends Context.Service Effect.Effect
   readonly clickStop: (messageId: string) => Effect.Effect
   readonly closeStream: (messageId: string) => Effect.Effect
+  readonly click: (messageId: string, id: string, options?: {
+    readonly userId?: string | undefined
+    readonly option?: string | undefined
+  }) => Effect.Effect
+  readonly submit: (
+    click: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged,
+    opened: ChatInteraction.OpenModal,
+    values: Readonly>,
+    options?: { readonly userId?: string | undefined }
+  ) => Effect.Effect
+  readonly interact: {
+    (event: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged): Effect.Effect<
+      ChatInteraction.ClickReply | ChatInteraction.Late,
+      never,
+      ChatInteraction.Handler
+    >
+    (event: ChatInteraction.ModalSubmitted): Effect.Effect<
+      ChatInteraction.SubmitReply | ChatInteraction.Late,
+      never,
+      ChatInteraction.Handler
+    >
+  }
 }>()("effect/chat/ChatTest") {}
 
 // -----------------------------------------------------------------------------
@@ -152,7 +207,11 @@ const allCapabilities: ReadonlyArray = [
   "getThread",
   "opener",
   "getUser",
-  "nativeStream"
+  "nativeStream",
+  "buttons",
+  "selects",
+  "modals",
+  "modalErrors"
 ]
 
 /** Counts code points. */
@@ -191,6 +250,7 @@ interface StoredMessage {
   readonly replyTo?: ReplyTo | undefined
   readonly attachments: ReadonlyArray<{ readonly attachment: Attachment; readonly content: Uint8Array }>
   readonly timestamp: DateTime.Utc
+  actions: ReadonlyArray
 }
 
 interface Fault {
@@ -227,11 +287,13 @@ const makeFake = (options: {
   readonly selfId: string
   readonly capabilities: ReadonlyArray
   readonly limits: Partial
-  readonly measure: (markdown: string) => number
+  readonly measure: Descriptor["measure"]
+  readonly interactionDeadline: Duration.Duration
 }) => {
   const { platform, selfId } = options
   const capabilities = new Set(options.capabilities)
   const messageLength = options.limits.messageLength ?? 4000
+  const hasActions = capabilities.has("buttons") || capabilities.has("selects")
   const descriptor: Descriptor = {
     platform,
     capabilities,
@@ -242,6 +304,8 @@ const makeFake = (options: {
       uploadBytes: 10 * 1024 * 1024,
       minWriteInterval: Duration.zero,
       ...(capabilities.has("nativeStream") ? { streamLength: messageLength, streamAge: Duration.minutes(10) } : {}),
+      ...(hasActions ? { actionsPerMessage: 25, actionDataLength: 100 } : {}),
+      ...(capabilities.has("modals") ? { modalMetadataLength: 100, modalFields: 5 } : {}),
       ...options.limits
     }
   }
@@ -357,6 +421,50 @@ const makeFake = (options: {
       })
     })
 
+  /** The capabilities a message's elements need. */
+  const actionNeeds = (actions: ReadonlyArray | undefined): Array => {
+    const needs: Array = []
+    if (actions?.some((action) => action._tag !== "Select")) needs.push("buttons")
+    if (actions?.some((action) => action._tag === "Select")) needs.push("selects")
+    return needs
+  }
+
+  /** The element limits, counted in code points, as both adapters count them. */
+  const checkActions = (op: string, actions: ReadonlyArray) =>
+    Effect.suspend(() => {
+      const { actionDataLength, actionsPerMessage } = descriptor.limits
+      if (actionsPerMessage !== undefined && actions.length > actionsPerMessage) {
+        return fail(op, new TooLarge({ detail: "too_many_actions" }))
+      }
+      const data = actions.flatMap((action) =>
+        action._tag === "Button"
+          ? [codePoints(action.id) + codePoints(action.value ?? "")]
+          : action._tag === "Select"
+          ? action.options.map((option) => codePoints(action.id) + codePoints(option.value))
+          : []
+      )
+      if (actionDataLength !== undefined && data.some((length) => length > actionDataLength)) {
+        return fail(op, new TooLarge({ detail: "action_data_too_long" }))
+      }
+      return Effect.void
+    })
+
+  /** Why a modal would not open, if it would not. */
+  const modalRefusal = (modal: ChatUi.Modal): ChatError | undefined => {
+    const { modalFields, modalMetadataLength } = descriptor.limits
+    if (!capabilities.has("modals")) return chatError("openModal", new Unsupported({ capability: "modals" }))
+    if (
+      modalMetadataLength !== undefined &&
+      codePoints(modal.id) + codePoints(modal.metadata ?? "") > modalMetadataLength
+    ) {
+      return chatError("openModal", new TooLarge({ detail: "modal_metadata_too_long" }))
+    }
+    if (modalFields !== undefined && modal.elements.length > modalFields) {
+      return chatError("openModal", new TooLarge({ detail: "too_many_fields" }))
+    }
+    return undefined
+  }
+
   const takeFault = (op: string): Fault | undefined => {
     const queue = faults.get(op)
     const fault = queue?.[0]
@@ -432,7 +540,8 @@ const makeFake = (options: {
             text: content.markdown,
             mentions: [],
             replyTo,
-            attachments: []
+            attachments: [],
+            actions: []
           })
           streams.set(stored.id, { startedAt: yield* Clock.currentTimeMillis, open: true, clicked: false })
           return { id: stored.id, thread, timestamp: stored.timestamp } satisfies Posted
@@ -493,12 +602,14 @@ const makeFake = (options: {
       const needs: Array = []
       if (files.length > 0) needs.push("files")
       if (content.replyTo !== undefined) needs.push("replyTo")
+      needs.push(...actionNeeds(content.actions))
       return attempt(
         { op: "post", thread, markdown: content.markdown, files: content.files },
         needs,
         Effect.gen(function*() {
           yield* findThread("post", thread)
-          yield* checkMessageLength(descriptor, "post", content.markdown)
+          yield* checkMessageLength(descriptor, "post", content.markdown, content.actions)
+          yield* checkActions("post", content.actions ?? [])
           if (
             files.length > descriptor.limits.filesPerMessage ||
             files.some((file) => file.content.length > descriptor.limits.uploadBytes)
@@ -518,7 +629,8 @@ const makeFake = (options: {
             text: content.markdown,
             mentions: [],
             replyTo,
-            attachments: storeFiles(files)
+            attachments: storeFiles(files),
+            actions: content.actions ?? []
           })
           return { id: stored.id, thread, timestamp: stored.timestamp } satisfies Posted
         })
@@ -527,16 +639,18 @@ const makeFake = (options: {
     edit: (thread, messageId, content) =>
       attempt(
         { op: "edit", thread, messageId, markdown: content.markdown },
-        ["edit"],
+        ["edit", ...actionNeeds(content.actions)],
         Effect.gen(function*() {
           const message = yield* findMessage("edit", thread, messageId)
           if (!message.isSelf) return yield* fail("edit", new Forbidden({ detail: "cant_update_message" }))
           if (yield* isOpen(message.id)) {
             return yield* fail("edit", new InvalidRequest({ detail: "streaming_state_conflict" }))
           }
-          yield* checkMessageLength(descriptor, "edit", content.markdown)
+          yield* checkMessageLength(descriptor, "edit", content.markdown, content.actions)
+          yield* checkActions("edit", content.actions ?? [])
           message.text = content.markdown
           message.mentions = []
+          message.actions = content.actions ?? []
         })
       ),
     delete: (thread, messageId) =>
@@ -668,7 +782,8 @@ const makeFake = (options: {
         messageId: message.replyTo.messageId,
         ...(replyTarget === undefined ? {} : { authorId: replyTarget.authorId })
       },
-      attachments: storeFiles(message.files)
+      attachments: storeFiles(message.files),
+      actions: []
     })
     return ChatEvent.MessageCreated.make({
       thread,
@@ -709,7 +824,66 @@ const makeFake = (options: {
         faults.set(op, queue)
       }),
     clickStop: (messageId) => Effect.map(streamFor("clickStop", messageId), (stream) => void (stream.clicked = true)),
-    closeStream: (messageId) => Effect.map(streamFor("closeStream", messageId), (stream) => void (stream.open = false))
+    closeStream: (messageId) => Effect.map(streamFor("closeStream", messageId), (stream) => void (stream.open = false)),
+    click: (messageId, id, clickOptions) =>
+      Effect.suspend((): Effect.Effect<
+        ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged,
+        NoSuchElement
+      > => {
+        const message = messages.get(messageId)
+        const element = message?.actions.find((action) => action._tag !== "LinkButton" && action.id === id)
+        if (message === undefined || element === undefined || element._tag === "LinkButton") {
+          return Effect.fail(new NoSuchElement({ messageId, id }))
+        }
+        const origin = {
+          id,
+          thread: message.thread,
+          messageId,
+          userId: clickOptions?.userId ?? "user",
+          raw: { type: "interaction", id: nextId("i"), message: messageId, element: id }
+        }
+        if (element._tag === "Button") {
+          return Effect.succeed(ChatInteraction.ButtonClicked.make({
+            ...origin,
+            ...(element.value === undefined ? {} : { value: element.value })
+          }))
+        }
+        const option = clickOptions?.option === undefined
+          ? element.options[0]
+          : element.options.find((option) => option.value === clickOptions.option)
+        return option === undefined
+          ? Effect.fail(new NoSuchElement({ messageId, id }))
+          : Effect.succeed(ChatInteraction.SelectChanged.make({ ...origin, value: option.value }))
+      }),
+    submit: (click, opened, values, submitOptions) =>
+      Effect.sync(() =>
+        ChatInteraction.ModalSubmitted.make({
+          id: opened.modal.id,
+          ...(opened.modal.metadata === undefined ? {} : { metadata: opened.modal.metadata }),
+          values: Object.fromEntries(Object.entries(values).filter(([, value]) => value !== "")),
+          thread: click.thread,
+          messageId: click.messageId,
+          userId: submitOptions?.userId ?? click.userId,
+          raw: { type: "submission", id: nextId("i"), modal: opened.modal.id }
+        })
+      ),
+    interact: ((event: ChatInteraction.Interaction) =>
+      Effect.gen(function*() {
+        const reply = yield* ChatInteraction.handle(event, options.interactionDeadline)
+        if (reply._tag !== "OpenModal" || event._tag === "ModalSubmitted") return reply
+        const refusal = modalRefusal(reply.modal)
+        calls.push({
+          op: "openModal",
+          thread: event.thread,
+          messageId: event.messageId,
+          outcome: refusal === undefined ? "ok" : refusal.reason._tag
+        })
+        if (refusal !== undefined) {
+          const handler = yield* ChatInteraction.Handler
+          yield* handler.refused(event, refusal)
+        }
+        return reply
+      })) as ChatTest["Service"]["interact"]
   })
 
   return { adapter, service }
@@ -737,6 +911,11 @@ const makeFake = (options: {
  *   past `limits.streamAge`, on `Clock`, is closed. An append without
  *   `flush` holds back an unclosed `<` tail of up to 100 characters. An open
  *   stream refuses `edit` and `delete`.
+ * - With `buttons` or `selects` on, a message takes 25 elements, and an
+ *   element's id plus encoded value 100 code points. With `modals` on, a
+ *   modal's id plus encoded metadata takes 100 code points, and a modal 5
+ *   fields. Each limit is there only with its capability.
+ * - `interact` gives a handler 3 seconds by default, on `Clock`.
  * - Two layers merged with different platforms share one `Chat`, so routing
  *   can be tested. The `ChatTest` service in context is the last one merged.
  *
@@ -749,7 +928,8 @@ export const layer = (options?: {
   readonly selfId?: string | undefined
   readonly capabilities?: ReadonlyArray | undefined
   readonly limits?: Partial | undefined
-  readonly measure?: ((markdown: string) => number) | undefined
+  readonly measure?: Descriptor["measure"] | undefined
+  readonly interactionDeadline?: Duration.Duration | undefined
 }): Layer.Layer =>
   Layer.effect(
     ChatTest,
@@ -760,7 +940,8 @@ export const layer = (options?: {
         selfId: options?.selfId ?? "bot",
         capabilities: options?.capabilities ?? allCapabilities,
         limits: options?.limits ?? {},
-        measure: options?.measure ?? codePoints
+        measure: options?.measure ?? codePoints,
+        interactionDeadline: options?.interactionDeadline ?? Duration.seconds(3)
       })
       yield* registry.register(adapter)
       return service
@@ -992,10 +1173,104 @@ export const checkEvent = (event: ChatEvent.ChatEvent, options: {
     )
   })
 
+const InteractionJson = Schema.toCodecJson(ChatInteraction.Interaction)
+
+/**
+ * Checks the invariants every interaction holds, for a click or a submit from
+ * a fixture.
+ *
+ * **Details**
+ *
+ * - `thread.platform` is the platform, and the thread survives its string
+ *   codec.
+ * - The interaction encodes and decodes through its Schema unchanged, `raw`
+ *   included.
+ * - A `ModalSubmitted` has a non-empty `messageId`.
+ *
+ * It takes no `parseMention` and checks no dedupe key, since an interaction
+ * carries neither.
+ *
+ * @stability unstable
+ * @category testing
+ * @since 4.1.5
+ */
+export const checkInteraction = (interaction: ChatInteraction.Interaction, options: {
+  readonly platform: string
+}): Effect.Effect =>
+  Effect.gen(function*() {
+    const rule = "checkInteraction"
+    yield* checkThread(rule, interaction.thread, options.platform)
+    if (interaction._tag === "ModalSubmitted") {
+      yield* check(rule, interaction.messageId !== "", "a submit with a messageId", () => "an empty messageId")
+    }
+    yield* roundTrip(rule, InteractionJson, interaction)
+  })
+
 // -----------------------------------------------------------------------------
 // conformance
 // -----------------------------------------------------------------------------
 
+/**
+ * The click hook of `conformance`: a way to click, for the adapter under
+ * test.
+ *
+ * **Details**
+ *
+ * - `click` clicks the element `id` on a message the suite posted, through
+ *   the adapter's real entry, and fails `NoSuchElement` when the message
+ *   carries no such element. `option` is as in `ChatTest.click`.
+ * - `submit` submits the modal the last click opened, and submits it again
+ *   after an `errors` reply. It does nothing when no modal is open: the rule
+ *   then fails on the submit its handler never saw.
+ * - Both need `ChatInteraction.Handler` and nothing else. The suite provides
+ *   its own recording handler, so the entry must take its handler at the
+ *   call, not at layer build.
+ *
+ * @stability unstable
+ * @category testing
+ * @since 4.1.5
+ */
+export interface Interactions {
+  readonly click: (messageId: string, id: string, options?: {
+    readonly option?: string | undefined
+  }) => Effect.Effect
+  readonly submit: (
+    values: Readonly>
+  ) => Effect.Effect
+}
+
+/** What the suite's own `ChatInteraction.Handler` received, and how it answers. */
+class Recording {
+  readonly clicks: Array = []
+  readonly submits: Array = []
+  readonly refused: Array = []
+  onClick: (event: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged) => ChatInteraction.ClickReply = () =>
+    ChatInteraction.ack
+  onSubmit: (event: ChatInteraction.ModalSubmitted) => ChatInteraction.SubmitReply = () => ChatInteraction.close
+  readonly handler = ChatInteraction.Handler.of({
+    click: (event) =>
+      Effect.sync(() => {
+        this.clicks.push(event)
+        return this.onClick(event)
+      }),
+    submit: (event) =>
+      Effect.sync(() => {
+        this.submits.push(event)
+        return this.onSubmit(event)
+      }),
+    refused: (_, error) => Effect.sync(() => void this.refused.push(error))
+  })
+}
+
+const conformanceButton = (rule: string): ChatUi.Button => ({ _tag: "Button", id: "conformance", label: rule })
+
+const conformanceSelect = (rule: string): ChatUi.Select => ({
+  _tag: "Select",
+  id: "conformance",
+  placeholder: rule,
+  options: [{ label: "a", value: "a" }, { label: "b", value: "b" }]
+})
+
 const describeExit = (exit: Exit.Exit): string => {
   if (Exit.isSuccess(exit)) return "success"
   const error = Exit.findErrorOption(exit)
@@ -1029,6 +1304,61 @@ class Tester {
     return this.options.thread
   }
 
+  readonly recording = new Recording()
+
+  /** Clicks through the hook, with the suite's recording handler. */
+  clickExit(messageId: string, id: string, options?: { readonly option?: string | undefined }) {
+    const interactions = this.options.interactions!
+    return Effect.exit(Effect.provideService(
+      interactions.click(messageId, id, options),
+      ChatInteraction.Handler,
+      this.recording.handler
+    ))
+  }
+
+  click(messageId: string, id: string, options?: { readonly option?: string | undefined }) {
+    return Effect.flatMap(
+      this.clickExit(messageId, id, options),
+      (exit) =>
+        Exit.isSuccess(exit) ? Effect.void : Effect.fail(failure(
+          this.rule,
+          "a click on element " + id + " of message " + messageId,
+          describeExit(exit),
+          Option.getOrUndefined(Exit.findErrorOption(exit))
+        ))
+    )
+  }
+
+  submit(values: Readonly>) {
+    return Effect.provideService(
+      this.options.interactions!.submit(values),
+      ChatInteraction.Handler,
+      this.recording.handler
+    )
+  }
+
+  /** Checks a received interaction with `checkInteraction`, under this rule's name. */
+  checkInteraction(interaction: ChatInteraction.Interaction) {
+    return Effect.mapError(
+      checkInteraction(interaction, { platform: this.options.platform }),
+      (error) => failure(this.rule, error.expected, error.actual, error.cause)
+    )
+  }
+
+  /** A click whose handler answers with `modal`, and what the adapter did with it. */
+  openModal(modal: ChatInteraction.OpenModal) {
+    return Effect.gen({ self: this }, function*() {
+      // A modal opens from a click, on a select when there are no buttons.
+      const element = this.has("buttons") || !this.has("selects")
+        ? conformanceButton(this.rule)
+        : conformanceSelect(this.rule)
+      const posted = yield* this.post({ actions: [element] })
+      this.recording.onClick = () => modal
+      yield* this.click(posted.id, "conformance")
+      return posted
+    })
+  }
+
   has(capability: Capability) {
     return this.descriptor.capabilities.has(capability)
   }
@@ -1054,7 +1384,12 @@ class Tester {
   }
 
   post(
-    content: { readonly markdown?: string; readonly replyTo?: ReplyTo; readonly files?: ReadonlyArray },
+    content: {
+      readonly markdown?: string
+      readonly replyTo?: ReplyTo
+      readonly files?: ReadonlyArray
+      readonly actions?: ReadonlyArray
+    },
     thread = this.thread
   ) {
     return Effect.tap(
@@ -1149,6 +1484,32 @@ class Tester {
           this.userPosts(),
           (event) => expect(chat.getUser(this.options.platform, event.message.author.id))
         )
+      case "buttons":
+        return expect(chat.post(thread, { markdown: text, actions: [conformanceButton(this.rule)] }), track)
+      case "selects":
+        return expect(chat.post(thread, { markdown: text, actions: [conformanceSelect(this.rule)] }), track)
+      case "modals":
+        // A modal opens only from a click, so without the hook or anything to click there is nothing to probe.
+        return this.options.interactions === undefined || !(this.has("buttons") || this.has("selects"))
+          ? Effect.void
+          : Effect.gen({ self: this }, function*() {
+            yield* this.openModal(probeModal.open())
+            const refusal = this.recording.refused.find((error) => error.reason._tag === "Unsupported")
+            const holds = listed
+              ? refusal === undefined
+              : refusal?.reason._tag === "Unsupported" && refusal.reason.capability === "modals"
+            yield* this.check(
+              holds,
+              listed ? "no refusal Unsupported for listed modals" : "a refusal Unsupported(modals)",
+              () =>
+                this.recording.refused.length === 0
+                  ? "no refusal"
+                  : this.recording.refused.map(describeError).join(", ")
+            )
+          })
+      case "modalErrors":
+        // Its absence means a degraded answer, not a refusal, so it has no inverse.
+        return Effect.void
       case "nativeStream":
         return Effect.flatMap(
           Registry,
@@ -1211,12 +1572,29 @@ const measureSamples: ReadonlyArray = [
   "caf\u00e9"
 ]
 
+const probeModal = ChatInteraction.modal("conformance-modal", {
+  title: "Conformance",
+  fields: { answer: ChatInteraction.textInput({ label: "Answer" }) }
+})
+
+/** The fixed schemas of `actions/valueRoundTrips`, each with the value posted. */
+const valueCases: ReadonlyArray<{ readonly schema: ChatInteraction.ValueSchema; readonly value: unknown }> = [
+  { schema: Schema.String, value: "v1.4.2" },
+  { schema: Schema.Struct({ version: Schema.String, attempt: Schema.Number }), value: { version: "v1", attempt: 2 } },
+  { schema: Schema.Union([Schema.String, Schema.Number]), value: 123 },
+  { schema: Schema.Union([Schema.String, Schema.Number]), value: "123" },
+  { schema: Schema.String, value: "a < b & \"c\" \u{1D400}" }
+]
+
+const sameValue = (a: unknown, b: unknown) => typeof a === typeof b && canonicalJson(a) === canonicalJson(b)
+
 interface ConformanceOptions {
   readonly platform: string
   readonly thread: ChatThread.ChatThread
   readonly userPosts: (thread: ChatThread.ChatThread, text: string) => Effect.Effect
   readonly parseMention: ParseMention
   readonly refuseFiles?: (() => Effect.Effect) | undefined
+  readonly interactions?: Interactions | undefined
   readonly failNext?:
     | ((op: string, reason: ChatErrorReason, options?: {
       readonly times?: number | undefined
@@ -1243,14 +1621,24 @@ interface ConformanceOptions {
  *   checks as it goes.
  * - The three `retries/*` rules exist only when `failNext` is given.
  *   `post/refusedFile` exists only when `refuseFiles` is given.
+ * - The rules that need a click exist only when `interactions` is given,
+ *   since neither platform has an API that clicks. A live run leaves it out
+ *   and runs only the outbound rules. The suite provides its own recording
+ *   `ChatInteraction.Handler` to the hook, so the rules still need only
+ *   `Chat` and `Registry`.
+ * - `modalErrors` has no inverse rule: without it an `errors` reply is a
+ *   degraded answer, not a refusal.
  * - Every rule deletes what it posted when it ends, pass or fail, when the
  *   platform can delete.
  *
  * **Gotchas**
  *
- * The rules are provisional: they can be added, renamed, removed or tightened
- * in any release until the suite is frozen. The `retries/retrySafe` rule
- * waits for real time, so run the suite on a live `Clock`.
+ * Rule names are stable, an existing rule is never tightened, and a new rule
+ * arrives only behind a new capability or with a changeset saying third-party
+ * adapters may start failing. `unsupported/buttons` and
+ * `unsupported/selects` are such rules: an adapter that ignores `actions`
+ * and posts anyway fails them. The `retries/retrySafe` rule waits for real
+ * time, so run the suite on a live `Clock`.
  *
  * @stability unstable
  * @category testing
@@ -1262,6 +1650,7 @@ export const conformance = (options: {
   readonly userPosts: (thread: ChatThread.ChatThread, text: string) => Effect.Effect
   readonly parseMention: ParseMention
   readonly refuseFiles?: (() => Effect.Effect) | undefined
+  readonly interactions?: Interactions | undefined
   readonly failNext?:
     | ((op: string, reason: ChatErrorReason, options?: {
       readonly times?: number | undefined
@@ -1648,7 +2037,277 @@ export const conformance = (options: {
       )
     }))
 
+  // --- buttons and modals ----------------------------------------------------
+
+  const limit = (t: Tester, name: "actionsPerMessage" | "actionDataLength" | "modalMetadataLength" | "modalFields") =>
+    Effect.flatMap(
+      t.check(
+        t.descriptor.limits[name] !== undefined,
+        "limits." + name + " on a descriptor with its capability",
+        () => "no limits." + name
+      ),
+      () => Effect.succeed(t.descriptor.limits[name]!)
+    )
+
+  rule("actions/posts", ["buttons"], (t) =>
+    Effect.gen(function*() {
+      const posted = yield* t.post({ actions: [conformanceButton(t.rule)] })
+      if (!t.has("fetchMessage")) return
+      const message = yield* t.call(t.chat.fetchMessage(t.thread, posted.id))
+      yield* t.check(message.id === posted.id, "the posted message " + posted.id, () => "message " + message.id)
+    }))
+
+  rule("actions/tooMany", ["buttons"], (t) =>
+    Effect.gen(function*() {
+      const most = yield* limit(t, "actionsPerMessage")
+      const actions = Array.from({ length: most + 1 }, (_, i): ChatUi.Button => ({
+        _tag: "Button",
+        id: "c" + i,
+        label: "c" + i
+      }))
+      yield* t.expectReason(
+        "TooLarge",
+        t.chat.post(t.thread, { markdown: conformanceText(t.rule), actions }),
+        (posted) => t.created.push({ thread: t.thread, id: posted.id })
+      )
+    }))
+
+  rule("actions/dataTooLarge", ["buttons"], (t) =>
+    Effect.gen(function*() {
+      const most = yield* limit(t, "actionDataLength")
+      const id = most >= "conformance".length ? "conformance" : "c".repeat(most + 1)
+      const value = "x".repeat(most + 1 - id.length)
+      const button: ChatUi.Button = { _tag: "Button", id, label: "c", ...(value === "" ? {} : { value }) }
+      yield* t.expectReason(
+        "TooLarge",
+        t.chat.post(t.thread, { markdown: conformanceText(t.rule), actions: [button] }),
+        (posted) => t.created.push({ thread: t.thread, id: posted.id })
+      )
+    }))
+
+  rule("descriptor/measureAddsActions", ["buttons"], (t) =>
+    Effect.gen(function*() {
+      const { measure } = t.descriptor
+      const button = conformanceButton(t.rule)
+      const sets: ReadonlyArray> = [
+        [button],
+        [{ ...button, value: "a < b & \u{1D400}" }],
+        [button, { _tag: "LinkButton", label: "Link", url: "https://example.com/?a=1&b=<2>" }],
+        [conformanceSelect(t.rule)]
+      ]
+      for (const markdown of measureSamples) {
+        yield* t.check(measure(markdown, []) === measure(markdown), "measure(md, []) equal to measure(md)", () =>
+          JSON.stringify(markdown) + " measures " + measure(markdown, []) + " and " + measure(markdown))
+        for (const actions of sets) {
+          const both = measure(markdown, actions)
+          yield* t.check(
+            both <= measure(markdown) + measure("", actions) && both >= measure(markdown),
+            "measure(md) <= measure(md, actions) <= measure(md) + measure(\"\", actions)",
+            () =>
+              JSON.stringify(markdown) + " with " + actions.map((action) =>
+                action._tag
+              ) + " measures " + both
+          )
+        }
+      }
+    }))
+
+  rule("descriptor/measureFitsActions", ["buttons"], (t) =>
+    Effect.gen(function*() {
+      const { measure } = t.descriptor
+      const most = t.descriptor.limits.messageLength
+      const actions = [{ ...conformanceButton(t.rule), value: "x" }]
+      let low = 0
+      let high = most
+      while (low < high) {
+        const middle = Math.ceil((low + high) / 2)
+        if (measure("x".repeat(middle), actions) <= most) low = middle
+        else high = middle - 1
+      }
+      yield* t.post({ markdown: "x".repeat(low), actions })
+    }))
+
+  const interactions = options.interactions
+  if (interactions !== undefined) {
+    rule("actions/valueRoundTrips", ["buttons"], (t) =>
+      Effect.gen(function*() {
+        const buttons = valueCases.map(({ schema }, i) =>
+          ChatInteraction.button("v" + i, { label: "v" + i, value: schema })
+        )
+        const posted = yield* t.post({ actions: buttons.map((button, i) => button.of(valueCases[i].value)) })
+        for (const [i, { schema, value }] of valueCases.entries()) {
+          yield* t.click(posted.id, "v" + i)
+          const click = t.recording.clicks[i]
+          const decoded = click?._tag === "ButtonClicked" && click.value !== undefined
+            ? ChatInteraction.decodeValue(schema, click.value)
+            : Option.none()
+          yield* t.check(
+            Option.isSome(decoded) && sameValue(decoded.value, value),
+            "a value that decodes to " + canonicalJson(value),
+            () => click === undefined ? "no click" : "value " + JSON.stringify(click.value)
+          )
+        }
+      }))
+
+    rule("actions/absentValue", ["buttons"], (t) =>
+      Effect.gen(function*() {
+        const posted = yield* t.post({ actions: [conformanceButton(t.rule)] })
+        yield* t.click(posted.id, "conformance")
+        const click = t.recording.clicks[0]
+        yield* t.check(
+          click?._tag === "ButtonClicked" && !("value" in click),
+          "a click with no value key",
+          () => click === undefined ? "no click" : "value " + JSON.stringify(click.value)
+        )
+      }))
+
+    rule("actions/origin", ["buttons"], (t) =>
+      Effect.gen(function*() {
+        const posted = yield* t.post({ actions: [conformanceButton(t.rule)] })
+        yield* t.click(posted.id, "conformance")
+        const click = t.recording.clicks[0]
+        yield* t.check(
+          click !== undefined && click.messageId === posted.id && ChatThread.equals(click.thread, posted.thread),
+          "a click on " + posted.id + " in " + ChatThread.toString(posted.thread),
+          () => click === undefined ? "no click" : click.messageId + " in " + ChatThread.toString(click.thread)
+        )
+        yield* t.checkInteraction(click)
+      }))
+
+    rule("actions/selectValue", ["selects"], (t) =>
+      Effect.gen(function*() {
+        const posted = yield* t.post({ actions: [conformanceSelect(t.rule)] })
+        yield* t.click(posted.id, "conformance", { option: "b" })
+        const event = t.recording.clicks[0]
+        yield* t.check(
+          event?._tag === "SelectChanged" && event.value === "b",
+          "SelectChanged with value b",
+          () => event === undefined ? "no click" : event._tag + " with value " + JSON.stringify(event.value)
+        )
+        yield* t.checkInteraction(event)
+      }))
+
+    rule("edit/removesActions", ["buttons", "edit"], (t) =>
+      Effect.gen(function*() {
+        const posted = yield* t.post({ actions: [conformanceButton(t.rule)] })
+        yield* t.call(t.chat.edit(t.thread, posted.id, { markdown: conformanceText(t.rule) + " edited" }))
+        const exit = yield* t.clickExit(posted.id, "conformance")
+        const error = Exit.findErrorOption(exit)
+        yield* t.check(
+          Option.isSome(error) && error.value._tag === "NoSuchElement",
+          "NoSuchElement",
+          () => describeExit(exit)
+        )
+      }))
+
+    rule("edit/addsActions", ["buttons", "edit"], (t) =>
+      Effect.gen(function*() {
+        const posted = yield* t.post({})
+        yield* t.call(t.chat.edit(t.thread, posted.id, {
+          markdown: conformanceText(t.rule) + " edited",
+          actions: [conformanceButton(t.rule)]
+        }))
+        yield* t.click(posted.id, "conformance")
+        yield* t.check(t.recording.clicks.length === 1, "one click", () => t.recording.clicks.length + " clicks")
+      }))
+
+    rule("modal/origin", ["modals"], (t) =>
+      Effect.gen(function*() {
+        const posted = yield* t.openModal(probeModal.open())
+        yield* t.submit({ answer: "conformance" })
+        const submit = t.recording.submits[0]
+        yield* t.check(
+          submit !== undefined && submit.messageId === posted.id && ChatThread.equals(submit.thread, posted.thread),
+          "a submit from " + posted.id + " in " + ChatThread.toString(posted.thread),
+          () => submit === undefined ? "no submit" : submit.messageId + " in " + ChatThread.toString(submit.thread)
+        )
+        yield* t.checkInteraction(submit)
+      }))
+
+    rule("modal/metadataRoundTrips", ["modals"], (t) =>
+      Effect.gen(function*() {
+        const Metadata = Schema.Struct({ version: Schema.String })
+        const withMetadata = ChatInteraction.modal("conformance-meta", {
+          title: "Conformance",
+          metadata: Metadata,
+          fields: { answer: ChatInteraction.textInput({ label: "Answer" }) }
+        })
+        const value = { version: "v1 < \u{1D400}" }
+        yield* t.openModal(withMetadata.open({ metadata: value }))
+        yield* t.submit({ answer: "conformance" })
+        yield* t.openModal(probeModal.open())
+        yield* t.submit({ answer: "conformance" })
+        const [first, second] = t.recording.submits
+        const decoded = first?.metadata === undefined
+          ? Option.none()
+          : ChatInteraction.decodeValue(Metadata, first.metadata)
+        yield* t.check(
+          Option.isSome(decoded) && sameValue(decoded.value, value),
+          "metadata that decodes to " + canonicalJson(value),
+          () => first === undefined ? "no submit" : "metadata " + JSON.stringify(first.metadata)
+        )
+        yield* t.check(
+          second !== undefined && !("metadata" in second),
+          "a submit with no metadata key",
+          () => second === undefined ? "no submit" : "metadata " + JSON.stringify(second.metadata)
+        )
+      }))
+
+    const refusedTooLarge = Effect.fnUntraced(function*(t: Tester) {
+      yield* t.submit({})
+      const refusal = t.recording.refused[0]
+      yield* t.check(
+        refusal?.reason._tag === "TooLarge" && t.recording.submits.length === 0,
+        "a refusal TooLarge and no modal",
+        () =>
+          (refusal === undefined ? "no refusal" : "a refusal " + describeError(refusal)) +
+          (t.recording.submits.length === 0 ? "" : " and a submit")
+      )
+    })
+
+    rule("modal/metadataTooLarge", ["modals"], (t) =>
+      Effect.gen(function*() {
+        const most = yield* limit(t, "modalMetadataLength")
+        const id = "conformance-big"
+        const big = ChatInteraction.modal(id, {
+          title: "Conformance",
+          metadata: Schema.String,
+          fields: { answer: ChatInteraction.textInput({ label: "Answer" }) }
+        })
+        yield* t.openModal(big.open({ metadata: "x".repeat(Math.max(0, most + 1 - id.length)) }))
+        yield* refusedTooLarge(t)
+      }))
+
+    rule("modal/tooManyFields", ["modals"], (t) =>
+      Effect.gen(function*() {
+        const most = yield* limit(t, "modalFields")
+        const fields: Record = {}
+        for (let i = 0; i <= most; i++) fields["f" + i] = ChatInteraction.textInput({ label: "F" + i })
+        yield* t.openModal(ChatInteraction.modal("conformance-many", { title: "Conformance", fields }).open())
+        yield* refusedTooLarge(t)
+      }))
+
+    // `modalErrors` means nothing without `modals`, so the rule needs both.
+    rule("modal/errorsKeepOpen", ["modals", "modalErrors"], (t) =>
+      Effect.gen(function*() {
+        t.recording.onSubmit = () =>
+          t.recording.submits.length === 1 ? ChatInteraction.errors({ answer: "Again." }) : ChatInteraction.close
+        yield* t.openModal(probeModal.open())
+        yield* t.submit({ answer: "first" })
+        yield* t.submit({ answer: "second" })
+        const second = t.recording.submits[1]
+        yield* t.check(
+          second !== undefined && second.id === "conformance-modal",
+          "a second submit of the same modal",
+          () => t.recording.submits.length + " submits"
+        )
+      }))
+
+    rule("unsupported/modals", ["buttons"], (t) => t.probe("modals"))
+  }
+
   for (const capability of allCapabilities) {
+    if (capability === "modals" || capability === "modalErrors") continue
     rule("unsupported/" + capability, [], (t) => t.probe(capability))
   }
 
diff --git a/packages/effect/src/chat/ChatUi.ts b/packages/effect/src/chat/ChatUi.ts
new file mode 100644
index 00000000000..0c138b00f8f
--- /dev/null
+++ b/packages/effect/src/chat/ChatUi.ts
@@ -0,0 +1,320 @@
+/**
+ * The plain elements of buttons, selects and modals.
+ *
+ * These are what goes on the wire, into `ChatTest` and into storage. Every
+ * element is a Schema tagged struct and every value in one is already a
+ * string. `ChatInteraction` holds the typed definitions that build them and
+ * receive their clicks. A consumer that routes clicks itself builds them with
+ * each schema's own `make`.
+ *
+ * **Details**
+ *
+ * - `post` and `edit` take a flat list of `Action`s beside the Markdown,
+ *   and the adapter lays out the rows.
+ * - Text in a modal is plain, not Markdown, because a Slack modal cannot hold
+ *   a `markdown` block.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import * as Schema from "../Schema.ts"
+
+/**
+ * Schema for the style of a button.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const ButtonStyle = Schema.Literals(["default", "primary", "danger"])
+
+/**
+ * The style of a button.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type ButtonStyle = typeof ButtonStyle.Type
+
+/**
+ * Schema for a button on a message.
+ *
+ * **Details**
+ *
+ * `value` is the encoded value, absent when the definition has no value
+ * schema.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const Button = Schema.TaggedStruct("Button", {
+  id: Schema.String,
+  label: Schema.String,
+  style: Schema.optionalKey(ButtonStyle),
+  value: Schema.optionalKey(Schema.String)
+})
+
+/**
+ * A button on a message.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Button = typeof Button.Type
+
+/**
+ * Schema for a button that opens a URL.
+ *
+ * **Details**
+ *
+ * It produces no click, so it has no id and no handler.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const LinkButton = Schema.TaggedStruct("LinkButton", {
+  label: Schema.String,
+  url: Schema.String
+})
+
+/**
+ * A button that opens a URL.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type LinkButton = typeof LinkButton.Type
+
+/**
+ * Schema for one option of a select. `value` is the encoded value.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const SelectOption = Schema.Struct({
+  label: Schema.String,
+  value: Schema.String
+})
+
+/**
+ * One option of a select.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type SelectOption = typeof SelectOption.Type
+
+/**
+ * Schema for a single-choice select on a message.
+ *
+ * **Details**
+ *
+ * `selected` is the `value` of the option shown as chosen.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const Select = Schema.TaggedStruct("Select", {
+  id: Schema.String,
+  placeholder: Schema.optionalKey(Schema.String),
+  options: Schema.Array(SelectOption),
+  selected: Schema.optionalKey(Schema.String)
+})
+
+/**
+ * A single-choice select on a message.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Select = typeof Select.Type
+
+/**
+ * Schema for what `post` and `edit` take in `actions`.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const Action = Schema.Union([Button, LinkButton, Select])
+
+/**
+ * What `post` and `edit` take in `actions`: a button, a link button or a
+ * select.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Action = typeof Action.Type
+
+/**
+ * Schema for a text input in a modal, one line or several.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const TextInput = Schema.TaggedStruct("TextInput", {
+  id: Schema.String,
+  label: Schema.String,
+  multiline: Schema.optionalKey(Schema.Boolean),
+  placeholder: Schema.optionalKey(Schema.String),
+  initial: Schema.optionalKey(Schema.String),
+  optional: Schema.optionalKey(Schema.Boolean),
+  minLength: Schema.optionalKey(Schema.Int),
+  maxLength: Schema.optionalKey(Schema.Int)
+})
+
+/**
+ * A text input in a modal.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type TextInput = typeof TextInput.Type
+
+/**
+ * Schema for a single-choice select in a modal.
+ *
+ * **Details**
+ *
+ * Both `ChatInteraction.choice` and `ChatInteraction.selectInput` fields
+ * become this. `initial` is the `value` of the option chosen when the modal
+ * opens.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const SelectInput = Schema.TaggedStruct("SelectInput", {
+  id: Schema.String,
+  label: Schema.String,
+  placeholder: Schema.optionalKey(Schema.String),
+  options: Schema.Array(SelectOption),
+  initial: Schema.optionalKey(Schema.String),
+  optional: Schema.optionalKey(Schema.Boolean)
+})
+
+/**
+ * A single-choice select in a modal.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type SelectInput = typeof SelectInput.Type
+
+/**
+ * Schema for plain text in a modal.
+ *
+ * **Details**
+ *
+ * Not Markdown: a Slack modal cannot hold a `markdown` block.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const Text = Schema.TaggedStruct("Text", {
+  text: Schema.String
+})
+
+/**
+ * Plain text in a modal.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Text = typeof Text.Type
+
+/**
+ * Schema for one element of a modal.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const ModalElement = Schema.Union([TextInput, SelectInput, Text])
+
+/**
+ * One element of a modal: a text input, a select or plain text.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type ModalElement = typeof ModalElement.Type
+
+/**
+ * Schema for a modal.
+ *
+ * **Details**
+ *
+ * - `metadata` is the consumer's encoded metadata. The adapter adds the
+ *   thread and message of the click that opened the modal beside it.
+ * - The elements are shown in order.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const Modal = Schema.TaggedStruct("Modal", {
+  id: Schema.String,
+  title: Schema.String,
+  submitLabel: Schema.optionalKey(Schema.String),
+  metadata: Schema.optionalKey(Schema.String),
+  elements: Schema.Array(ModalElement)
+})
+
+/**
+ * A modal.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Modal = typeof Modal.Type
+
+/**
+ * Creates a button that opens a URL.
+ *
+ * **When to use**
+ *
+ * Use to put a link beside the buttons of a message. It is the one element
+ * with no definition in `ChatInteraction`, since it produces no click.
+ *
+ * **Example** (Posting a link button)
+ *
+ * ```ts
+ * import { Effect } from "effect"
+ * import { Chat, ChatThread, ChatUi } from "effect/chat"
+ *
+ * const program = Effect.gen(function*() {
+ *   const chat = yield* Chat.Chat
+ *   yield* chat.post(ChatThread.make("slack", "T1/C1"), {
+ *     markdown: "The diff is ready.",
+ *     actions: [ChatUi.linkButton({ label: "Diff", url: "https://example.com/diff" })]
+ *   })
+ * })
+ * ```
+ *
+ * @stability unstable
+ * @category constructors
+ * @since 4.1.5
+ */
+export const linkButton = (options: {
+  readonly label: string
+  readonly url: string
+}): LinkButton => LinkButton.make({ label: options.label, url: options.url })
diff --git a/packages/effect/src/chat/index.ts b/packages/effect/src/chat/index.ts
index 243c7582827..ab206ecce22 100644
--- a/packages/effect/src/chat/index.ts
+++ b/packages/effect/src/chat/index.ts
@@ -35,6 +35,12 @@ export * as ChatEvent from "./ChatEvent.ts"
  */
 export * as ChatHandler from "./ChatHandler.ts"
 
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as ChatInteraction from "./ChatInteraction.ts"
+
 /**
  * @stability unstable
  * @since 4.1.5
@@ -58,3 +64,9 @@ export * as ChatTest from "./ChatTest.ts"
  * @since 4.1.5
  */
 export * as ChatThread from "./ChatThread.ts"
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as ChatUi from "./ChatUi.ts"
diff --git a/packages/effect/test/chat/ChatInteraction.test.ts b/packages/effect/test/chat/ChatInteraction.test.ts
new file mode 100644
index 00000000000..86791838b65
--- /dev/null
+++ b/packages/effect/test/chat/ChatInteraction.test.ts
@@ -0,0 +1,269 @@
+import { assert, describe, it } from "@effect/vitest"
+import { Deferred, Duration, Effect, Fiber, Layer, Option, Schema } from "effect"
+import { ChatError, ChatInteraction, ChatTest, ChatThread } from "effect/chat"
+import { TestClock } from "effect/testing"
+
+const Deploy = Schema.Struct({ version: Schema.String })
+const thread = ChatThread.make("test", "c1")
+const origin = { thread, messageId: "m1", userId: "u1", raw: null }
+
+const clicked = (id: string, value?: string) =>
+  ChatInteraction.ButtonClicked.make({ id, ...origin, ...(value === undefined ? {} : { value }) })
+
+describe("ChatInteraction", () => {
+  describe("encodeValue / decodeValue", () => {
+    it("sends a string-only schema as it is", () => {
+      assert.strictEqual(ChatInteraction.encodeValue(Schema.String, "v1.4.2"), "v1.4.2")
+      assert.strictEqual(ChatInteraction.encodeValue(Schema.Literals(["a", "b"]), "a"), "a")
+      assert.deepStrictEqual(ChatInteraction.decodeValue(Schema.String, "\"quoted\""), Option.some("\"quoted\""))
+    })
+
+    it("sends anything else as JSON, decided by the schema and not the value", () => {
+      const StringOrNumber = Schema.Union([Schema.String, Schema.Number])
+      assert.strictEqual(ChatInteraction.encodeValue(StringOrNumber, "123"), "\"123\"")
+      assert.strictEqual(ChatInteraction.encodeValue(StringOrNumber, 123), "123")
+      assert.deepStrictEqual(ChatInteraction.decodeValue(StringOrNumber, "\"123\""), Option.some("123"))
+      assert.deepStrictEqual(ChatInteraction.decodeValue(StringOrNumber, "123"), Option.some(123))
+      assert.strictEqual(ChatInteraction.encodeValue(Deploy, { version: "v1" }), "{\"version\":\"v1\"}")
+    })
+
+    it("round-trips through a schema with a transformation", () => {
+      const encoded = ChatInteraction.encodeValue(Schema.NumberFromString, 42)
+      assert.strictEqual(encoded, "42")
+      assert.deepStrictEqual(ChatInteraction.decodeValue(Schema.NumberFromString, encoded), Option.some(42))
+    })
+
+    it("gives none for a string that no longer decodes", () => {
+      assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Deploy, "not json")))
+      assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Deploy, "{\"version\":1}")))
+      assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Schema.Literals(["a"]), "b")))
+    })
+  })
+
+  describe("definitions", () => {
+    it("button.of encodes the value and takes overrides", () => {
+      const Approve = ChatInteraction.button("approve", { label: "Approve", style: "primary", value: Deploy })
+      assert.deepStrictEqual(Approve.of({ version: "v1" }, { label: "Ship v1" }), {
+        _tag: "Button",
+        id: "approve",
+        label: "Ship v1",
+        style: "primary",
+        value: "{\"version\":\"v1\"}"
+      })
+      const Plain = ChatInteraction.button("plain", { label: "Plain" })
+      assert.deepStrictEqual(Plain.of(), { _tag: "Button", id: "plain", label: "Plain" })
+    })
+
+    it("select.of encodes each option and the selected one", () => {
+      const Pick = ChatInteraction.select("pick", { placeholder: "Pick", value: Schema.Number })
+      assert.deepStrictEqual(Pick.of({ options: [{ label: "One", value: 1 }], selected: 1 }), {
+        _tag: "Select",
+        id: "pick",
+        placeholder: "Pick",
+        options: [{ label: "One", value: "1" }],
+        selected: "1"
+      })
+    })
+
+    it("modal.open builds the elements in field order, with encoded metadata and options", () => {
+      const Reason = ChatInteraction.modal("reason", {
+        title: "Why",
+        metadata: Deploy,
+        fields: {
+          intro: ChatInteraction.text("Tell us."),
+          reason: ChatInteraction.textInput({ label: "Reason", multiline: true, maxLength: 200 }),
+          env: ChatInteraction.selectInput({ label: "Env", value: Schema.Number, optional: true })
+        }
+      })
+      const opened = Reason.open({
+        metadata: { version: "v1" },
+        options: { env: [{ label: "Prod", value: 1 }] },
+        initial: { env: 1 }
+      })
+      assert.isTrue(Schema.is(ChatInteraction.OpenModal)(opened))
+      assert.deepStrictEqual(opened.modal, {
+        _tag: "Modal",
+        id: "reason",
+        title: "Why",
+        metadata: "{\"version\":\"v1\"}",
+        elements: [
+          { _tag: "Text", text: "Tell us." },
+          { _tag: "TextInput", id: "reason", label: "Reason", multiline: true, maxLength: 200 },
+          {
+            _tag: "SelectInput",
+            id: "env",
+            label: "Env",
+            options: [{ label: "Prod", value: "1" }],
+            initial: "1",
+            optional: true
+          }
+        ]
+      })
+    })
+
+    it("errors builds an Errors reply", () => {
+      assert.deepStrictEqual(ChatInteraction.errors({ reason: "Say more." }), {
+        _tag: "Errors",
+        errors: { reason: "Say more." }
+      })
+    })
+  })
+
+  describe("layer and groups", () => {
+    const Approve = ChatInteraction.button("approve", { label: "Approve", value: Deploy })
+    const Reason = ChatInteraction.modal("reason", {
+      title: "Why",
+      metadata: Deploy,
+      fields: {
+        reason: ChatInteraction.textInput({ label: "Reason" }),
+        severity: ChatInteraction.choice({ label: "Severity", options: [{ label: "Low", value: "low" }] }),
+        note: ChatInteraction.textInput({ label: "Note", optional: true })
+      }
+    })
+    const seen: Array = []
+    const unhandled: Array = []
+    const Interactions = ChatInteraction.group(Approve).add(Reason).toLayer({
+      approve: (click) =>
+        Effect.sync(() => seen.push(click.value)).pipe(Effect.as(Reason.open({ metadata: click.value }))),
+      reason: (submit) =>
+        Effect.sync(() => {
+          seen.push({ metadata: submit.metadata, values: submit.values })
+          return submit.values.reason.length < 3 ? ChatInteraction.errors({ reason: "Longer." }) : ChatInteraction.close
+        })
+    }).pipe(Layer.provideMerge(ChatInteraction.layer({
+      unhandled: (event, why) => Effect.sync(() => void unhandled.push(event.id + ":" + why.reason))
+    })))
+
+    it.effect("routes a click and a submit to the typed handlers", () =>
+      Effect.gen(function*() {
+        seen.length = 0
+        const handler = yield* ChatInteraction.Handler
+        const reply = yield* handler.click(clicked("approve", ChatInteraction.encodeValue(Deploy, { version: "v1" })))
+        assert.strictEqual(reply._tag, "OpenModal")
+        const submitted = ChatInteraction.ModalSubmitted.make({
+          id: "reason",
+          metadata: (reply as ChatInteraction.OpenModal).modal.metadata!,
+          values: { reason: "ok", severity: "low" },
+          ...origin
+        })
+        assert.deepStrictEqual(yield* handler.submit(submitted), ChatInteraction.errors({ reason: "Longer." }))
+        assert.deepStrictEqual(seen, [
+          { version: "v1" },
+          { metadata: { version: "v1" }, values: { reason: "ok", severity: "low", note: undefined } }
+        ])
+      }).pipe(Effect.provide(Interactions)))
+
+    it.effect("answers an unknown id or a value that no longer decodes without a handler", () =>
+      Effect.gen(function*() {
+        seen.length = 0
+        unhandled.length = 0
+        const handler = yield* ChatInteraction.Handler
+        assert.deepStrictEqual(yield* handler.click(clicked("nope")), ChatInteraction.ack)
+        assert.deepStrictEqual(yield* handler.click(clicked("approve", "{")), ChatInteraction.ack)
+        assert.deepStrictEqual(yield* handler.click(clicked("reason")), ChatInteraction.ack)
+        const badChoice = ChatInteraction.ModalSubmitted.make({
+          id: "reason",
+          metadata: "{\"version\":\"v1\"}",
+          values: { reason: "long enough", severity: "high" },
+          ...origin
+        })
+        assert.deepStrictEqual(yield* handler.submit(badChoice), ChatInteraction.close)
+        assert.deepStrictEqual(seen, [])
+        assert.deepStrictEqual(unhandled, [
+          "nope:UnknownId",
+          "approve:InvalidValue",
+          "reason:UnknownId",
+          "reason:InvalidValue"
+        ])
+      }).pipe(Effect.provide(Interactions)))
+
+    it.effect("dies on an id registered twice", () =>
+      Effect.gen(function*() {
+        const twice = ChatInteraction.group(Approve).toLayer({ approve: () => Effect.succeed(ChatInteraction.ack) })
+        const exit = yield* Effect.exit(Layer.build(twice.pipe(Layer.provideMerge(Interactions))))
+        assert.isTrue(exit._tag === "Failure")
+      }).pipe(Effect.scoped))
+  })
+
+  describe("handle", () => {
+    const deadline = Duration.seconds(3)
+    const handlerWith = (options: {
+      readonly click?: Effect.Effect
+      readonly submit?: Effect.Effect
+      readonly refused?: (error: ChatError.ChatError) => Effect.Effect
+    }) =>
+      ChatInteraction.Handler.of({
+        click: () => options.click ?? Effect.succeed(ChatInteraction.ack),
+        submit: () => options.submit ?? Effect.succeed(ChatInteraction.close),
+        refused: (_, error) => options.refused?.(error) ?? Effect.void
+      })
+
+    it.effect("gives the reply inside the deadline", () =>
+      Effect.gen(function*() {
+        const reply = yield* ChatInteraction.handle(clicked("a"), deadline).pipe(
+          Effect.provideService(ChatInteraction.Handler, handlerWith({}))
+        )
+        assert.deepStrictEqual(reply, ChatInteraction.ack)
+      }))
+
+    it.effect("gives Late for a late click, and refuses its modal with interaction_expired", () =>
+      Effect.gen(function*() {
+        const refused = yield* Deferred.make()
+        const opened = ChatInteraction.modal("m", { title: "M", fields: {} }).open()
+        const handler = handlerWith({
+          click: Effect.as(Effect.sleep("5 seconds"), opened),
+          refused: (error) => Deferred.succeed(refused, error).pipe(Effect.asVoid)
+        })
+        const fiber = yield* ChatInteraction.handle(clicked("a"), deadline).pipe(
+          Effect.provideService(ChatInteraction.Handler, handler),
+          Effect.forkChild
+        )
+        yield* TestClock.adjust("3 seconds")
+        const reply = yield* Fiber.join(fiber)
+        assert.isTrue(Schema.is(ChatInteraction.Late)(reply))
+        // The click's handler is still running, and its modal can no longer open.
+        yield* TestClock.adjust("2 seconds")
+        const error = yield* Deferred.await(refused)
+        assert.strictEqual(error.op, "openModal")
+        assert.strictEqual(error.platform, "test")
+        assert.strictEqual(error.reason._tag, "NotFound")
+        assert.strictEqual(error.reason.detail, ChatError.interactionExpired)
+      }))
+
+    it.effect("interrupts a late submit", () =>
+      Effect.gen(function*() {
+        let interrupted = false
+        const handler = handlerWith({
+          submit: Effect.as(Effect.sleep("5 seconds"), ChatInteraction.close).pipe(
+            Effect.onInterrupt(() => Effect.sync(() => void (interrupted = true)))
+          )
+        })
+        const submitted = ChatInteraction.ModalSubmitted.make({ id: "m", values: {}, ...origin })
+        const fiber = yield* ChatInteraction.handle(submitted, deadline).pipe(
+          Effect.provideService(ChatInteraction.Handler, handler),
+          Effect.forkChild
+        )
+        yield* TestClock.adjust("3 seconds")
+        assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
+        assert.isTrue(interrupted)
+      }))
+  })
+
+  describe("ChatTest.interact", () => {
+    it.effect("uses the layer's interactionDeadline", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const handler = ChatInteraction.Handler.of({
+          click: () => Effect.as(Effect.sleep("2 seconds"), ChatInteraction.ack),
+          submit: () => Effect.succeed(ChatInteraction.close),
+          refused: () => Effect.void
+        })
+        const fiber = yield* test.interact(clicked("a")).pipe(
+          Effect.provideService(ChatInteraction.Handler, handler),
+          Effect.forkChild
+        )
+        yield* TestClock.adjust("1 second")
+        assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
+      }).pipe(Effect.provide(ChatTest.layer({ interactionDeadline: Duration.seconds(1) }))))
+  })
+})
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index 78dc8681c98..1480cbe0096 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -1,7 +1,7 @@
 import { assert, describe, it } from "@effect/vitest"
 import { type Cause, Deferred, Duration, Effect, Fiber, Queue, Stream } from "effect"
-import { Chat, ChatAdapter, ChatError, ChatMarkdown, ChatTest } from "effect/chat"
-import type { ChatThread } from "effect/chat"
+import { Chat, ChatAdapter, ChatError, ChatInteraction, ChatMarkdown, ChatTest } from "effect/chat"
+import type { ChatThread, ChatUi } from "effect/chat"
 import { TestClock } from "effect/testing"
 
 const codePoints = (markdown: string) => [...markdown].length
@@ -263,6 +263,39 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(last.attachments.map((attachment) => attachment.name), ["rest.md", "a.txt"])
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
 
+    const button = ChatInteraction.button("go", { label: "Go" }).of()
+    /** Each element costs 10, as escaping and block JSON make one cost something on Slack. */
+    const withActions = (markdown: string, actions?: ReadonlyArray) =>
+      codePoints(markdown) + 10 * (actions?.length ?? 0)
+
+    it.effect("sends actions with the last part", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const result = yield* ChatMarkdown.post(thread, paragraphs(3, 15), { actions: [button] })
+        assert.strictEqual(result.parts.length, 3)
+        const [first, , last] = result.parts
+        assert.strictEqual((yield* Effect.flip(test.click(first.messageId, "go")))._tag, "NoSuchElement")
+        assert.strictEqual((yield* test.click(last.messageId, "go")).messageId, last.messageId)
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
+
+    it.effect("cuts the last part earlier to leave room for the actions", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        // 25 code points fit alone, but not with the actions' 10.
+        const input = "aaaaaaaaaa\n\nbbbbbbbbbbbbb"
+        const result = yield* ChatMarkdown.post(thread, input, { actions: [button] })
+        assert.deepStrictEqual(result.parts.map((part) => part.text), ["aaaaaaaaaa\n\n", "bbbbbbbbbbbbb"])
+        yield* test.click(result.parts[1].messageId, "go")
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
+
+    it.effect("fails TooLarge before posting when the actions alone do not fit", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const error = yield* Effect.flip(ChatMarkdown.post(thread, "a", { actions: [button] }))
+        assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "TooLarge")
+        assert.deepStrictEqual(yield* test.messages(thread), [])
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 9 }, measure: withActions }))))
+
     it.effect("reports the text of an uncertain post as uncertain", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index 53e2f9deaa5..7451ba92933 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -1,6 +1,6 @@
 import { assert, describe, it } from "@effect/vitest"
-import { Effect, Exit, Option } from "effect"
-import { Chat, ChatAdapter, ChatError, ChatHandler, ChatTest, ChatThread } from "effect/chat"
+import { Effect, Exit, Option, Schema } from "effect"
+import { Chat, ChatAdapter, ChatError, ChatHandler, ChatInteraction, ChatTest, ChatThread, ChatUi } from "effect/chat"
 
 const kinds = { "@": "user", "@&": "role", "#": "channel", "!": "broadcast" } as const
 
@@ -9,6 +9,34 @@ const parseMention: ChatTest.ParseMention = (slice) => {
   return match === null ? Option.none() : Option.some({ kind: kinds[match[1] as keyof typeof kinds], id: match[2] })
 }
 
+/** The conformance click hook, over the fake's own entry. */
+const interactionsFor = (test: ChatTest.ChatTest["Service"]): ChatTest.Interactions => {
+  let open: {
+    readonly click: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
+    readonly opened: ChatInteraction.OpenModal
+  } | undefined
+  return {
+    click: Effect.fnUntraced(function*(messageId, id, options) {
+      const click = yield* test.click(messageId, id, options)
+      const handler = yield* ChatInteraction.Handler
+      let refused = false
+      const reply = yield* test.interact(click).pipe(
+        Effect.provideService(ChatInteraction.Handler, {
+          ...handler,
+          refused: (event, error) =>
+            Effect.andThen(Effect.sync(() => void (refused = true)), handler.refused(event, error))
+        })
+      )
+      open = reply._tag === "OpenModal" && !refused ? { click, opened: reply } : undefined
+    }),
+    submit: Effect.fnUntraced(function*(values) {
+      if (open === undefined) return
+      const reply = yield* test.interact(yield* test.submit(open.click, open.opened, values))
+      if (reply._tag !== "Errors") open = undefined
+    })
+  }
+}
+
 const rulesFor = (test: ChatTest.ChatTest["Service"], thread: ChatThread.ChatThread) =>
   ChatTest.conformance({
     platform: test.platform,
@@ -16,7 +44,8 @@ const rulesFor = (test: ChatTest.ChatTest["Service"], thread: ChatThread.ChatThr
     userPosts: (thread, text) => test.userPosts(thread, { text }),
     parseMention,
     refuseFiles: test.refuseFiles,
-    failNext: test.failNext
+    failNext: test.failNext,
+    interactions: interactionsFor(test)
   })
 
 const suite = Effect.gen(function*() {
@@ -30,7 +59,8 @@ const ruleNames = Object.keys(ChatTest.conformance({
   userPosts: () => Effect.die("unused"),
   parseMention,
   refuseFiles: () => Effect.void,
-  failNext: () => Effect.void
+  failNext: () => Effect.void,
+  interactions: { click: () => Effect.void, submit: () => Effect.void }
 }))
 
 const capabilities = ChatError.Capability.literals
@@ -186,6 +216,194 @@ describe("ChatTest", () => {
       assert.strictEqual(getUser.actual, "Unsupported(opener)")
     }).pipe(Effect.provide(ChatTest.layer())))
 
+  describe("buttons and modals", () => {
+    const Approve = ChatInteraction.button("approve", { label: "Approve", value: Schema.Number })
+    const Pick = ChatInteraction.select("pick", {})
+    const Ask = ChatInteraction.modal("ask", {
+      title: "Ask",
+      metadata: Schema.String,
+      fields: { answer: ChatInteraction.textInput({ label: "Answer", optional: true }) }
+    })
+    const replying = (reply: ChatInteraction.ClickReply, refused: Array) =>
+      ChatInteraction.Handler.of({
+        click: () => Effect.succeed(reply),
+        submit: () => Effect.succeed(ChatInteraction.close),
+        refused: (_, error) => Effect.sync(() => void refused.push(error))
+      })
+
+    it("lists the hook rules only with the hook, and unsupported/buttons always", () => {
+      const withoutHook = Object.keys(ChatTest.conformance({
+        platform: "test",
+        thread: ChatThread.make("test", "c0"),
+        userPosts: () => Effect.die("unused"),
+        parseMention
+      }))
+      for (
+        const name of ["unsupported/buttons", "unsupported/selects", "actions/tooMany", "descriptor/measureFitsActions"]
+      ) {
+        assert.include(withoutHook, name)
+      }
+      for (const name of ["actions/valueRoundTrips", "modal/origin", "unsupported/modals"]) {
+        assert.notInclude(withoutHook, name)
+        assert.include(ruleNames, name)
+      }
+      assert.notInclude(ruleNames, "unsupported/modalErrors")
+    })
+
+    it.effect("fails Unsupported for an element whose capability is off", () =>
+      Effect.gen(function*() {
+        const thread = yield* Effect.flatMap(ChatTest.ChatTest, (test) => test.makeThread())
+        const chat = yield* Chat.Chat
+        const button = yield* Effect.flip(chat.post(thread, { markdown: "a", actions: [Approve.of(1)] }))
+        assert.strictEqual(button.reason._tag === "Unsupported" && button.reason.capability, "buttons")
+        const selectError = yield* Effect.flip(chat.post(thread, {
+          markdown: "a",
+          actions: [Pick.of({ options: [{ label: "A", value: "a" }] })]
+        }))
+        assert.strictEqual(selectError.reason._tag === "Unsupported" && selectError.reason.capability, "selects")
+      }).pipe(Effect.provide(ChatTest.layer({
+        capabilities: capabilities.filter((c) => c !== "buttons" && c !== "selects")
+      }))))
+
+    it.effect("checks actionsPerMessage and actionDataLength in code points", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const chat = yield* Chat.Chat
+        const thread = yield* test.makeThread()
+        const many = yield* Effect.flip(chat.post(thread, {
+          markdown: "a",
+          actions: [Approve.of(1), Approve.of(2), Approve.of(3)]
+        }))
+        assert.strictEqual(many.reason._tag, "TooLarge")
+        // "approve" is 7 and "12" is 2: 9 code points fit, 10 do not.
+        yield* chat.post(thread, { markdown: "a", actions: [Approve.of(12)] })
+        const long = yield* Effect.flip(chat.post(thread, { markdown: "a", actions: [Approve.of(123)] }))
+        assert.strictEqual(long.reason._tag, "TooLarge")
+        assert.strictEqual((yield* test.messages(thread)).length, 1)
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { actionsPerMessage: 2, actionDataLength: 9 } }))))
+
+    it.effect("click builds the event from what was posted or edited", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const chat = yield* Chat.Chat
+        const thread = yield* test.makeThread()
+        const posted = yield* chat.post(thread, {
+          markdown: "a",
+          actions: [
+            Approve.of(7),
+            Pick.of({ options: [{ label: "A", value: "a" }, { label: "B", value: "b" }] }),
+            ChatUi.linkButton({ label: "Docs", url: "https://effect.website" })
+          ]
+        })
+        const click = yield* test.click(posted.id, "approve", { userId: "u2" })
+        assert.strictEqual(click._tag, "ButtonClicked")
+        assert.strictEqual(click.value, "7")
+        assert.strictEqual(click.userId, "u2")
+        assert.strictEqual(click.messageId, posted.id)
+        yield* ChatTest.checkInteraction(click, { platform: "test" })
+        const first = yield* test.click(posted.id, "pick")
+        assert.strictEqual(first._tag === "SelectChanged" && first.value, "a")
+        const second = yield* test.click(posted.id, "pick", { option: "b" })
+        assert.strictEqual(second._tag === "SelectChanged" && second.value, "b")
+        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "pick", { option: "c" })))._tag, "NoSuchElement")
+        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "missing")))._tag, "NoSuchElement")
+        yield* chat.edit(thread, posted.id, { markdown: "b" })
+        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "approve")))._tag, "NoSuchElement")
+        yield* chat.delete(thread, posted.id)
+        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "approve")))._tag, "NoSuchElement")
+      }).pipe(Effect.provide(ChatTest.layer())))
+
+    it.effect("submit keeps the click's origin and leaves out empty values", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const chat = yield* Chat.Chat
+        const thread = yield* test.makeThread()
+        const posted = yield* chat.post(thread, { markdown: "a", actions: [Approve.of(1)] })
+        const click = yield* test.click(posted.id, "approve")
+        const submitted = yield* test.submit(click, Ask.open({ metadata: "m" }), { answer: "" })
+        assert.strictEqual(submitted.id, "ask")
+        assert.strictEqual(submitted.metadata, "m")
+        assert.deepStrictEqual(submitted.values, {})
+        assert.strictEqual(submitted.messageId, posted.id)
+        yield* ChatTest.checkInteraction(submitted, { platform: "test" })
+      }).pipe(Effect.provide(ChatTest.layer())))
+
+    it.effect("interact refuses a modal the fake would not open, and records openModal", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const chat = yield* Chat.Chat
+        const thread = yield* test.makeThread()
+        const posted = yield* chat.post(thread, { markdown: "a", actions: [Approve.of(1)] })
+        const click = yield* test.click(posted.id, "approve")
+        const refused: Array = []
+        const opened = Ask.open({ metadata: "x".repeat(10) })
+        const reply = yield* test.interact(click).pipe(
+          Effect.provideService(ChatInteraction.Handler, replying(opened, refused))
+        )
+        assert.deepStrictEqual(reply, opened)
+        assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag]), [["openModal", "TooLarge"]])
+        const calls = (yield* test.calls).filter((call) => call.op === "openModal")
+        assert.deepStrictEqual(calls.map((call) => [call.messageId, call.outcome]), [[posted.id, "TooLarge"]])
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { modalMetadataLength: 12 } }))))
+
+    it.effect("interact refuses any modal without the modals capability", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const chat = yield* Chat.Chat
+        const thread = yield* test.makeThread()
+        const posted = yield* chat.post(thread, { markdown: "a", actions: [Approve.of(1)] })
+        const refused: Array = []
+        yield* test.interact(yield* test.click(posted.id, "approve")).pipe(
+          Effect.provideService(ChatInteraction.Handler, replying(Ask.open({ metadata: "m" }), refused))
+        )
+        const reason = refused[0]?.reason
+        assert.strictEqual(reason?._tag === "Unsupported" && reason.capability, "modals")
+      }).pipe(Effect.provide(ChatTest.layer({ capabilities: capabilities.filter((c) => c !== "modals") }))))
+
+    it.effect("checkInteraction rejects a submit with no messageId and a foreign platform", () =>
+      Effect.gen(function*() {
+        const submitted = ChatInteraction.ModalSubmitted.make({
+          id: "ask",
+          values: {},
+          thread: ChatThread.make("test", "c1"),
+          messageId: "",
+          userId: "u",
+          raw: null
+        })
+        const empty = yield* Effect.flip(ChatTest.checkInteraction(submitted, { platform: "test" }))
+        assert.strictEqual(empty.actual, "an empty messageId")
+        const foreign = yield* Effect.flip(ChatTest.checkInteraction(submitted, { platform: "other" }))
+        assert.strictEqual(foreign.rule, "checkInteraction")
+      }))
+
+    it.effect("fails unsupported/buttons for an adapter that ignores actions", () =>
+      Effect.gen(function*() {
+        const registry = yield* ChatAdapter.Registry
+        const adapter = yield* registry.get("test")
+        const listed = new Set(adapter.descriptor.capabilities)
+        listed.delete("buttons")
+        yield* registry.register({ ...adapter, descriptor: { ...adapter.descriptor, capabilities: listed } })
+        const failure = yield* Effect.flip(Effect.flatMap(suite, (rules) => rules["unsupported/buttons"]))
+        assert.strictEqual(failure.actual, "success")
+      }).pipe(Effect.provide(ChatTest.layer())))
+
+    it.effect("fails edit/removesActions for an adapter that keeps the elements on edit", () =>
+      Effect.gen(function*() {
+        const registry = yield* ChatAdapter.Registry
+        const adapter = yield* registry.get("test")
+        yield* registry.register({
+          ...adapter,
+          edit: (thread, messageId, content) =>
+            adapter.edit(thread, messageId, {
+              markdown: content.markdown,
+              actions: [ChatInteraction.button("conformance", { label: "kept" }).of()]
+            })
+        })
+        const failure = yield* Effect.flip(Effect.flatMap(suite, (rules) => rules["edit/removesActions"]))
+        assert.strictEqual(failure.expected, "NoSuchElement")
+      }).pipe(Effect.provide(ChatTest.layer())))
+  })
+
   it.live("deletes every bot message the suite posts", () =>
     Effect.gen(function*() {
       const test = yield* ChatTest.ChatTest
diff --git a/packages/effect/typetest/chat/ChatInteraction.tst.ts b/packages/effect/typetest/chat/ChatInteraction.tst.ts
new file mode 100644
index 00000000000..242179c68df
--- /dev/null
+++ b/packages/effect/typetest/chat/ChatInteraction.tst.ts
@@ -0,0 +1,121 @@
+import { Context, Duration, Effect, type Layer, Schema } from "effect"
+import { ChatError, ChatInteraction, type ChatUi } from "effect/chat"
+import { describe, expect, it } from "tstyche"
+
+const EnvId = Schema.String.pipe(Schema.brand("EnvId"))
+type EnvId = typeof EnvId.Type
+
+class DeployQueue extends Context.Service Effect.Effect
+}>()("DeployQueue") {}
+
+const Deploy = Schema.Struct({ version: Schema.String })
+
+const Approve = ChatInteraction.button("approve", { label: "Approve", value: Deploy })
+const Refresh = ChatInteraction.button("refresh", { label: "Refresh" })
+const PickEnv = ChatInteraction.select("pick-env", { value: EnvId })
+const RejectReason = ChatInteraction.modal("reject-reason", {
+  title: "Reject deploy",
+  metadata: Deploy,
+  fields: {
+    intro: ChatInteraction.text("Tell the author why."),
+    reason: ChatInteraction.textInput({ label: "Reason", multiline: true }),
+    note: ChatInteraction.textInput({ label: "Note", optional: true }),
+    severity: ChatInteraction.choice({
+      label: "Severity",
+      options: [{ label: "Low", value: "low" }, { label: "High", value: "high" }]
+    }),
+    env: ChatInteraction.selectInput({ label: "Environment", value: EnvId })
+  }
+})
+const Feedback = ChatInteraction.modal("feedback", {
+  title: "Feedback",
+  fields: { body: ChatInteraction.textInput({ label: "Feedback" }) }
+})
+
+describe("ChatInteraction", () => {
+  it("of takes the value its schema asks for", () => {
+    expect(Approve.of({ version: "v1" })).type.toBe()
+    expect(Approve.of).type.not.toBeCallableWith()
+    expect(Approve.of).type.not.toBeCallableWith({ version: 1 })
+    expect(Refresh.of).type.not.toBeCallableWith({ version: "v1" })
+    expect(PickEnv.of).type.not.toBeCallableWith({ options: [{ label: "Prod", value: "prod" }] })
+  })
+
+  it("open needs the metadata and the selectInput options", () => {
+    expect(RejectReason.open).type.not.toBeCallableWith()
+    expect(RejectReason.open).type.not.toBeCallableWith({ metadata: { version: "v1" } })
+    expect(Feedback.open()).type.toBe()
+  })
+
+  it("types each handler from its definition", () => {
+    const Group = ChatInteraction.group(Approve, Refresh, PickEnv, RejectReason, Feedback)
+    const layer = Group.toLayer(Effect.gen(function*() {
+      const queue = yield* DeployQueue
+      return {
+        approve: (click) => {
+          expect(click.value).type.toBe<{ readonly version: string }>()
+          return queue.offer(click.value).pipe(Effect.as(ChatInteraction.ack))
+        },
+        refresh: (click) => {
+          expect(click.value).type.toBe()
+          return Effect.succeed(Feedback.open())
+        },
+        "pick-env": (selected) => {
+          expect(selected.value).type.toBe()
+          return Effect.succeed(ChatInteraction.ack)
+        },
+        "reject-reason": (submit) => {
+          expect(submit.values).type.toBe<{
+            readonly reason: string
+            readonly note: string | undefined
+            readonly severity: "low" | "high"
+            readonly env: EnvId
+          }>()
+          expect(submit.metadata).type.toBe<{ readonly version: string }>()
+          return Effect.succeed(ChatInteraction.errors({ reason: "Say a bit more." }))
+        },
+        feedback: (submit) => {
+          expect(submit.metadata).type.toBe()
+          return Effect.succeed(ChatInteraction.close)
+        }
+      }
+    }))
+    expect(layer).type.toBe>()
+  })
+
+  it("refuses a missing handler, a wrong reply and an error for an unknown field", () => {
+    const Small = ChatInteraction.group(Approve, RejectReason)
+    expect(Small.toLayer).type.not.toBeCallableWith({ approve: () => Effect.succeed(ChatInteraction.ack) })
+    expect(Small.toLayer).type.not.toBeCallableWith({
+      approve: () => Effect.succeed(ChatInteraction.close),
+      "reject-reason": () => Effect.succeed(ChatInteraction.close)
+    })
+    expect(Small.toLayer).type.not.toBeCallableWith({
+      approve: () => Effect.succeed(ChatInteraction.ack),
+      "reject-reason": () => Effect.succeed(Feedback.open())
+    })
+    expect(Small.toLayer).type.not.toBeCallableWith({
+      approve: () => Effect.succeed(ChatInteraction.ack),
+      "reject-reason": () => Effect.succeed(ChatInteraction.errors({ intro: "A text has no error." }))
+    })
+  })
+
+  it("handle gives the reply of the event's kind, or Late", () => {
+    const click = ChatInteraction.handle(
+      {} as ChatInteraction.ButtonClicked,
+      Duration.seconds(2)
+    )
+    expect(click).type.toBe<
+      Effect.Effect
+    >()
+    const submit = ChatInteraction.handle({} as ChatInteraction.ModalSubmitted, Duration.seconds(2))
+    expect(submit).type.toBe<
+      Effect.Effect
+    >()
+  })
+
+  it("keeps the error details literal", () => {
+    expect(ChatError.interactionExpired).type.toBe<"interaction_expired">()
+  })
+})

From 9f9d1337bdef39a4c907670592ff146f5df31fa7 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 07:56:07 +0000
Subject: [PATCH 27/89] Fix late submit deadline, action placement and grapheme
 cuts in effect/chat

---
 .changeset/effect-chat-buttons.md             |   2 +
 packages/effect/src/chat/ChatInteraction.ts   |  17 ++-
 packages/effect/src/chat/ChatMarkdown.ts      | 125 ++++++++++++++----
 .../effect/test/chat/ChatInteraction.test.ts  |  24 +++-
 .../effect/test/chat/ChatMarkdown.test.ts     |  72 ++++++++++
 5 files changed, 208 insertions(+), 32 deletions(-)

diff --git a/.changeset/effect-chat-buttons.md b/.changeset/effect-chat-buttons.md
index 847fbdf21b2..f7c438e6a1e 100644
--- a/.changeset/effect-chat-buttons.md
+++ b/.changeset/effect-chat-buttons.md
@@ -4,4 +4,6 @@
 
 Add buttons, selects and modals to `effect/chat`. The new `ChatUi` module has the elements, and the new `ChatInteraction` module has typed definitions, groups, `handle` with its deadline, and `layer`. `post` and `edit` take `actions`, `ChatMarkdown.post` sends them with the last part, and `Descriptor.measure` measures them. `ChatTest` gains `click`, `submit`, `interact`, `checkInteraction`, the `interactions` conformance hook and the buttons and modals rules.
 
+`ChatMarkdown` now cuts long text only at grapheme cluster boundaries, where it used to avoid only splitting a surrogate pair.
+
 The conformance rules `unsupported/buttons` and `unsupported/selects` run against every adapter, without a new capability. A third-party adapter that ignores `actions` and posts anyway will start failing them. It should fail `Unsupported` naming `buttons` or `selects` until it supports them.
diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
index 5c889fa93dd..d2cd9177e3e 100644
--- a/packages/effect/src/chat/ChatInteraction.ts
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -1360,7 +1360,8 @@ const lateClick = (event: ButtonClicked | SelectChanged) =>
  *   it later returns `OpenModal`, the modal is dropped and `Handler.refused`
  *   is called with a `ChatError` whose reason is `NotFound`, op `openModal`,
  *   detail `interaction_expired`, platform `event.thread.platform`.
- * - A late submit interrupts its handler.
+ * - A late submit interrupts its handler. `Late` is given at the deadline,
+ *   without waiting for the handler's finalizers to finish.
  * - `deadline` is the handler's share of the platform's 3 seconds, not the 3
  *   seconds. The adapter subtracts what its own answer costs. This function
  *   knows no platform.
@@ -1382,16 +1383,20 @@ export const handle: {
 } = (event: Interaction, deadline: Duration.Duration): Effect.Effect =>
   Effect.gen(function*() {
     const handler = yield* Handler
-    if (event._tag === "ModalSubmitted") {
-      const reply = yield* Effect.timeoutOption(handler.submit(event), deadline)
-      return Option.isSome(reply) ? reply.value : late
-    }
-    const fiber = yield* Effect.forkDetach(handler.click(event))
+    // Detached, so the reply at the deadline waits for neither a late click nor a late submit's cleanup.
+    const fiber: Fiber.Fiber = yield* Effect.forkDetach(
+      event._tag === "ModalSubmitted" ? handler.submit(event) : handler.click(event)
+    )
     const exit = yield* Effect.onInterrupt(
       Effect.timeoutOption(Fiber.await(fiber), deadline),
       () => Fiber.interrupt(fiber)
     )
     if (Option.isSome(exit)) return yield* exit.value
+    if (event._tag === "ModalSubmitted") {
+      // Requests the interrupt without waiting for it to finish.
+      yield* Effect.forkDetach(Fiber.interrupt(fiber))
+      return late
+    }
     yield* Effect.forkDetach(Effect.flatMap(
       Fiber.await(fiber),
       (exit) =>
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index aaf26d41502..a5d6982ccbd 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -245,7 +245,7 @@ const render = (prefix: string, text: string, fence: Fence | undefined): string
  * Where to cut `text` so that `prefix`, the cut text and a closing fence
  * measure at most `room`: after the last block boundary that fits, else after
  * the last line, else after the last whitespace, else at the last character.
- * Never inside a surrogate pair, and never at 0.
+ * Never inside a grapheme cluster, and never at 0.
  */
 const fitCut = (
   measure: (markdown: string) => number,
@@ -282,19 +282,36 @@ const fitCut = (
     }
   }
   candidates.push(most)
+  const clusters = graphemes(text)
   for (const candidate of candidates) {
-    const cut = withoutSplitPair(text, candidate)
+    const cut = clusterStart(clusters, text, candidate)
     if (cut > 0 && fits(cut)) return cut
   }
-  return Math.max(1, withoutSplitPair(text, most) || codePointEnd(text))
+  // Not even one cluster fits: the cut goes after the first one, and the write fails `TooLarge`.
+  return clusterStart(clusters, text, most) || clusterEnd(clusters, 0)
 }
 
-const isHighSurrogate = (code: number) => code >= 0xd800 && code <= 0xdbff
+let segmenter: Intl.Segmenter | undefined
 
-const withoutSplitPair = (text: string, cut: number): number =>
-  cut > 0 && cut < text.length && isHighSurrogate(text.charCodeAt(cut - 1)) ? cut - 1 : cut
+/** The grapheme clusters of `text`. `Intl.Segmenter` is created on first use, so only a cut needs it. */
+const graphemes = (text: string): Intl.Segments =>
+  (segmenter ??= new Intl.Segmenter(undefined, { granularity: "grapheme" })).segment(text)
 
-const codePointEnd = (text: string): number => isHighSurrogate(text.charCodeAt(0)) && text.length > 1 ? 2 : 1
+/** The grapheme cluster boundary at or before `cut`. */
+const clusterStart = (clusters: Intl.Segments, text: string, cut: number): number =>
+  cut <= 0 || cut >= text.length ? cut : clusters.containing(cut)!.index
+
+/** The end of the grapheme cluster that contains `index`. */
+const clusterEnd = (clusters: Intl.Segments, index: number): number => {
+  const cluster = clusters.containing(index)!
+  return cluster.index + cluster.segment.length
+}
+
+/** Where the last grapheme cluster of `text` that is not whitespace starts, or -1 for blank text. */
+const lastContentStart = (text: string): number => {
+  const end = text.trimEnd().length
+  return end === 0 ? -1 : graphemes(text).containing(end - 1)!.index
+}
 
 /** Past this many held characters, a held line is released up to its last whitespace. */
 const holdLimit = 300
@@ -576,6 +593,14 @@ const reply = (options: ReplyOptions): Effect.Effect measure(markdown, actions) : measure
     /** The last part takes the files and the actions. */
     const hasExtras = hasFiles || hasActions
+    /**
+     * Set when not even the text's last grapheme cluster fits beside the
+     * actions: the text is posted without them, and the files and the
+     * actions follow in a message of their own.
+     */
+    let extrasAlone = false
+    /** Whether the note posted on its own takes the actions. */
+    let noteActions = false
 
     // --- post-then-edit --------------------------------------------------------
 
@@ -614,7 +639,7 @@ const reply = (options: ReplyOptions): Effect.Effect => {
       const files = withFiles && hasFiles ? options.files! : undefined
       const unattachedNote = files === undefined ? undefined : options.unattachedNote
-      const extras = withFiles && hasActions ? { actions } : {}
+      const withActions = withFiles && hasActions
       const settle = (exit: Exit.Exit, markdown: string) => {
         if (Exit.isSuccess(exit)) {
           part.posted = exit.value
@@ -628,13 +653,18 @@ const reply = (options: ReplyOptions): Effect.Effect | undefined, fallback: boolean) =>
+      const attempt = (
+        markdown: string,
+        files: ReadonlyArray | undefined,
+        fallback: boolean,
+        withActions: boolean
+      ) =>
         create(
           chat.post(thread, {
             markdown,
             ...(parts.length === 0 && options.replyTo !== undefined ? { replyTo: options.replyTo } : {}),
             ...(files === undefined ? {} : { files }),
-            ...extras
+            ...(withActions ? { actions } : {})
           }),
           (posted) => toPart(part, posted, markdown, end),
           (exit) => {
@@ -643,15 +673,17 @@ const reply = (options: ReplyOptions): Effect.Effect {
+      return Effect.flatMap(attempt(markdown, files, unattachedNote !== undefined, withActions), (exit) => {
         if (unattachedNote === undefined || !isFileRefusal(exit)) return Effect.void
         // The platform may have refused the files: the last part goes out without them, ending in the note.
         const text = unattachedNote(files!)
         if (measureLast(markdown + text) <= limits.messageLength) {
-          return Effect.asVoid(attempt(markdown + text, undefined, false))
+          return Effect.asVoid(attempt(markdown + text, undefined, false, withActions))
         }
+        // The note is the last message now, so it takes the actions when they fit beside it.
         note = text
-        return Effect.asVoid(attempt(markdown, undefined, false))
+        noteActions = withActions && measure(text, actions) <= limits.messageLength
+        return Effect.asVoid(attempt(markdown, undefined, false, withActions && !noteActions))
       })
     }
 
@@ -665,7 +697,8 @@ const reply = (options: ReplyOptions): Effect.Effect {
+      const post = chat.post(thread, { markdown: text, ...(noteActions ? { actions } : {}) })
+      return Effect.asVoid(create(post, part, (exit) => {
         note = undefined
         if (Exit.isSuccess(exit)) {
           parts.push(part(exit.value))
@@ -676,6 +709,28 @@ const reply = (options: ReplyOptions): Effect.Effect = Effect.suspend(() => {
+      extrasAlone = false
+      if (parts.length >= maxParts) {
+        fail({ _tag: "Overflow" })
+        return Effect.void
+      }
+      const part = newPart(input.length, undefined)
+      current = part
+      return Effect.flatMap(postPart(part, input.length, "", true), () => {
+        if (!isRunning()) return Effect.void
+        finishPart(input.length)
+        if (note !== undefined) return postNote(note)
+        done(false)
+        return Effect.void
+      })
+    })
+
     const stepEdit = (final: boolean): Effect.Effect =>
       Effect.suspend(() => {
         const part = current
@@ -694,6 +749,7 @@ const reply = (options: ReplyOptions): Effect.Effect => {
           if (!last || !isRunning()) return Effect.void
+          if (extrasAlone) return postExtras
           if (note !== undefined) return postNote(note)
           done(false)
           return Effect.void
@@ -701,7 +757,7 @@ const reply = (options: ReplyOptions): Effect.Effect => {
           // Only blank text follows the cut: this is the last part, so it takes the files, the actions and that text.
           const last = final && isBlank(input.slice(cut))
-          return Effect.flatMap(writeEdit(cut, true, last), () => {
+          return Effect.flatMap(writeEdit(cut, true, last && !extrasAlone), () => {
             if (!isRunning()) return Effect.void
             finishPart(last ? input.length : cut)
             return end(last)
@@ -709,15 +765,29 @@ const reply = (options: ReplyOptions): Effect.Effect
-          !final || !hasActions || !isBlank(input.slice(cut)) ||
+          !final || !hasActions || extrasAlone || !isBlank(input.slice(cut)) ||
           measureLast(render(part.prefix, input.slice(part.start, cut), part.fence)) <= limits.messageLength
-        const withActions = () => part.start + fitCut(measureLast, body, part.fence, part.prefix, limits.messageLength)
-        if (measure(render(part.prefix, body, part.fence)) > limits.messageLength) {
-          const cut = part.start + fitCut(measure, body, part.fence, part.prefix, limits.messageLength)
-          return cutAt(lastFits(cut) ? cut : withActions())
+        const cut = measure(render(part.prefix, body, part.fence)) > limits.messageLength
+          ? part.start + fitCut(measure, body, part.fence, part.prefix, limits.messageLength)
+          : input.length
+        if (!lastFits(cut)) {
+          // The cut would end the reply, and the actions don't fit beside its text. Only the last part
+          // makes room for them: this part is cut before the text's last grapheme cluster, so it isn't the
+          // last, and fills its whole budget. When not even that cluster fits beside the actions, they go
+          // in a message of their own.
+          const keep = lastContentStart(body)
+          const tailStart = part.start + keep
+          const tailFence = fenceAtInput(part, tailStart)
+          const tail = render(reopening(tailFence), input.slice(tailStart), tailFence)
+          if (keep > 0 && measureLast(tail) <= limits.messageLength) {
+            return cutAt(
+              part.start + fitCut(measure, body.slice(0, keep), part.fence, part.prefix, limits.messageLength)
+            )
+          }
+          extrasAlone = true
         }
-        if (!lastFits(input.length)) return cutAt(withActions())
-        return Effect.flatMap(writeEdit(input.length, final, final), () => {
+        if (cut < input.length) return cutAt(cut)
+        return Effect.flatMap(writeEdit(input.length, final, final && !extrasAlone), () => {
           if (final && isRunning()) finishPart(input.length)
           return end(final)
         })
@@ -1132,9 +1202,14 @@ const reply = (options: ReplyOptions): Effect.Effect {
         assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
         assert.isTrue(interrupted)
       }))
+    it.effect("gives Late at the deadline without waiting for a late submit's cleanup", () =>
+      Effect.gen(function*() {
+        const cleaned = yield* Deferred.make()
+        const handler = handlerWith({
+          submit: Effect.never.pipe(
+            Effect.onInterrupt(() => Effect.andThen(Effect.sleep("5 seconds"), Deferred.succeed(cleaned, undefined)))
+          )
+        })
+        const submitted = ChatInteraction.ModalSubmitted.make({ id: "m", values: {}, ...origin })
+        const fiber = yield* ChatInteraction.handle(submitted, deadline).pipe(
+          Effect.provideService(ChatInteraction.Handler, handler),
+          Effect.forkChild
+        )
+        yield* TestClock.adjust("3 seconds")
+        const exit = fiber.pollUnsafe()
+        assert.isDefined(exit)
+        assert.isTrue(Exit.isSuccess(exit!) && Schema.is(ChatInteraction.Late)(exit.value))
+        // The interrupt was requested, and the cleanup still runs to its end.
+        assert.isFalse(yield* Deferred.isDone(cleaned))
+        yield* TestClock.adjust("5 seconds")
+        yield* Deferred.await(cleaned)
+      }))
   })
 
   describe("ChatTest.interact", () => {
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index 1480cbe0096..01621d62adb 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -296,6 +296,78 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* test.messages(thread), [])
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 9 }, measure: withActions }))))
 
+    /** One element costs `cost`, so a test can leave as little room beside it as it needs. */
+    const costing = (cost: number) => (markdown: string, actions?: ReadonlyArray) =>
+      codePoints(markdown) + cost * (actions?.length ?? 0)
+
+    it.effect("fills the parts before the last one without leaving room for the actions", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const result = yield* ChatMarkdown.post(thread, "a".repeat(25), { actions: [button] })
+        assert.deepStrictEqual(result.parts.map((part) => part.text), ["a".repeat(24), "a"])
+        yield* test.click(result.parts[1].messageId, "go")
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: costing(29) }))))
+
+    it.effect("posts the actions in a message of their own when no text fits beside them", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const result = yield* ChatMarkdown.post(thread, "Hello", { actions: [button], files })
+        assert.deepStrictEqual(result.parts.map((part) => part.text), ["Hello", ""])
+        const messages = yield* test.messages(thread)
+        assert.deepStrictEqual(messages.map((message) => [message.text, message.attachments.length]), [
+          ["Hello", 0],
+          ["", 1]
+        ])
+        assert.strictEqual((yield* Effect.flip(test.click(result.parts[0].messageId, "go")))._tag, "NoSuchElement")
+        yield* test.click(result.parts[1].messageId, "go")
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: costing(30) }))))
+
+    it.effect("fails Overflow when the actions' own message has no part left", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const error = yield* Effect.flip(ChatMarkdown.post(thread, "Hello", { actions: [button], maxParts: 1 }))
+        assert.strictEqual(error.cause._tag, "Overflow")
+        assert.deepStrictEqual([error.posted.map((part) => part.text), error.remaining], [["Hello"], ""])
+        assert.strictEqual((yield* test.messages(thread)).length, 1)
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: costing(30) }))))
+
+    it.effect("moves the actions to an unattached note posted on its own", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_refused" }))
+        const result = yield* ChatMarkdown.post(thread, "a".repeat(20), {
+          actions: [button],
+          files,
+          unattachedNote: () => " note"
+        })
+        assert.deepStrictEqual(result.parts.map((part) => part.markdown), ["a".repeat(20), " note"])
+        assert.strictEqual((yield* Effect.flip(test.click(result.parts[0].messageId, "go")))._tag, "NoSuchElement")
+        yield* test.click(result.parts[1].messageId, "go")
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
+
+    it.effect("never cuts inside a grapheme cluster to leave room for the actions", () =>
+      Effect.gen(function*() {
+        const { thread } = yield* setup
+        const input = "1234567890a\u0301" + "b".repeat(13)
+        const result = yield* ChatMarkdown.post(thread, input, { actions: [button] })
+        assert.strictEqual(joined(result.parts), input)
+        for (const part of result.parts) assert.isFalse(part.text.startsWith("\u0301"), part.text)
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: costing(19) }))))
+
+    it.effect("never cuts inside a grapheme cluster on a hard cut", () =>
+      Effect.gen(function*() {
+        const { thread } = yield* setup
+        // The 10th code unit is the "e" of "e\u0301", and the flag is two code points of one cluster.
+        const input = "aaaaaaaaae\u0301bbbbbbb\u{1F1EF}\u{1F1F5}cc"
+        const result = yield* ChatMarkdown.post(thread, input)
+        assert.strictEqual(joined(result.parts), input)
+        assert.deepStrictEqual(result.parts.map((part) => part.text), [
+          "aaaaaaaaa",
+          "e\u0301bbbbbbb",
+          "\u{1F1EF}\u{1F1F5}cc"
+        ])
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 10 } }))))
+
     it.effect("reports the text of an uncertain post as uncertain", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup

From fce4eacd5a06b3c738cb67f9a44500e0314a14b8 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 08:02:53 +0000
Subject: [PATCH 28/89] Post actions after an unattached note that has no room
 for them

---
 packages/effect/src/chat/ChatMarkdown.ts      | 70 +++++++++++++------
 .../effect/test/chat/ChatMarkdown.test.ts     | 16 +++++
 2 files changed, 63 insertions(+), 23 deletions(-)

diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index a5d6982ccbd..41434ee13c6 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -601,6 +601,8 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect => {
+    /** Posts a message after the text that is not part of it: the unattached note, or the actions alone. */
+    const postAfter = (text: string, withActions: boolean): Effect.Effect => {
       const part = (posted: Posted): Part => ({
         messageId: posted.id,
         timestamp: posted.timestamp,
@@ -697,17 +702,40 @@ const reply = (options: ReplyOptions): Effect.Effect {
+      const post = chat.post(thread, { markdown: text, ...(withActions ? { actions } : {}) })
+      return Effect.flatMap(
+        create(post, part, (exit) => {
+          if (Exit.isSuccess(exit)) return void parts.push(part(exit.value))
+          const error = firstError(exit)
+          if (error !== undefined) failChat(error)
+        }),
+        () => isRunning() ? finishAfter : Effect.void
+      )
+    }
+
+    /**
+     * Ends the reply once the text is posted: the unattached note that did
+     * not fit the last part follows, then the actions when they fit beside
+     * neither. The actions' message counts against `maxParts`, and with no
+     * part left the reply fails `Overflow`.
+     */
+    const finishAfter: Effect.Effect = Effect.suspend(() => {
+      if (note !== undefined) {
+        const text = note
         note = undefined
-        if (Exit.isSuccess(exit)) {
-          parts.push(part(exit.value))
-          return done(false)
+        return postAfter(text, noteActions)
+      }
+      if (actionsAfter) {
+        actionsAfter = false
+        if (parts.length >= maxParts) {
+          fail({ _tag: "Overflow" })
+          return Effect.void
         }
-        const error = firstError(exit)
-        if (error !== undefined) failChat(error)
-      }))
-    }
+        return postAfter("", true)
+      }
+      done(false)
+      return Effect.void
+    })
 
     /**
      * Posts the files and the actions in a message of their own, after the
@@ -725,9 +753,7 @@ const reply = (options: ReplyOptions): Effect.Effect {
         if (!isRunning()) return Effect.void
         finishPart(input.length)
-        if (note !== undefined) return postNote(note)
-        done(false)
-        return Effect.void
+        return finishAfter
       })
     })
 
@@ -749,10 +775,7 @@ const reply = (options: ReplyOptions): Effect.Effect => {
           if (!last || !isRunning()) return Effect.void
-          if (extrasAlone) return postExtras
-          if (note !== undefined) return postNote(note)
-          done(false)
-          return Effect.void
+          return extrasAlone ? postExtras : finishAfter
         }
         const cutAt = (cut: number): Effect.Effect => {
           // Only blank text follows the cut: this is the last part, so it takes the files, the actions and that text.
@@ -1208,8 +1231,9 @@ const reply = (options: ReplyOptions): Effect.Effect {
         yield* test.click(result.parts[1].messageId, "go")
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
 
+    it.effect("posts the actions after an unattached note that has no room for them", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_refused" }))
+        const result = yield* ChatMarkdown.post(thread, "a".repeat(20), {
+          actions: [button],
+          files,
+          unattachedNote: () => "n".repeat(25)
+        })
+        assert.deepStrictEqual(result.parts.map((part) => part.markdown), ["a".repeat(20), "n".repeat(25), ""])
+        for (const part of result.parts.slice(0, 2)) {
+          assert.strictEqual((yield* Effect.flip(test.click(part.messageId, "go")))._tag, "NoSuchElement")
+        }
+        yield* test.click(result.parts[2].messageId, "go")
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
+
     it.effect("never cuts inside a grapheme cluster to leave room for the actions", () =>
       Effect.gen(function*() {
         const { thread } = yield* setup

From 9b07bbec9b72d9b82ef6f1189d4cfa1c8fb8957b Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 08:22:13 +0000
Subject: [PATCH 29/89] Add buttons, selects and modals to
 @effect/chat-discord, and mark refused files

---
 .changeset/chat-adapters-actions.md           |   3 +-
 .changeset/chat-discord.md                    |   2 +-
 packages/chat/discord/README.md               |   2 +-
 packages/chat/discord/src/DiscordChat.ts      | 113 ++++++-
 packages/chat/discord/src/internal/adapter.ts | 126 ++++++--
 packages/chat/discord/src/internal/errors.ts  |  46 ++-
 .../chat/discord/src/internal/interactions.ts | 304 ++++++++++++++++++
 .../chat/discord/test/DiscordChat.test.ts     | 157 ++++++++-
 .../chat/discord/test/conformance.test.ts     |  48 +++
 packages/chat/discord/test/discord.ts         | 162 ++++++++++
 .../chat/discord/test/interactions.test.ts    | 291 +++++++++++++++++
 packages/chat/discord/test/live.test.ts       |   6 +
 12 files changed, 1221 insertions(+), 39 deletions(-)
 create mode 100644 packages/chat/discord/src/internal/interactions.ts
 create mode 100644 packages/chat/discord/test/conformance.test.ts
 create mode 100644 packages/chat/discord/test/discord.ts
 create mode 100644 packages/chat/discord/test/interactions.test.ts

diff --git a/.changeset/chat-adapters-actions.md b/.changeset/chat-adapters-actions.md
index 01da68acf2f..72776167fdf 100644
--- a/.changeset/chat-adapters-actions.md
+++ b/.changeset/chat-adapters-actions.md
@@ -1,6 +1,5 @@
 ---
 "@effect/chat-slack": patch
-"@effect/chat-discord": patch
 ---
 
-Refuse a post or edit that carries buttons or selects with `Unsupported` instead of posting it without them, until the adapters support them.
+Refuse a post or edit that carries buttons or selects with `Unsupported` instead of posting it without them, until the adapter supports them.
diff --git a/.changeset/chat-discord.md b/.changeset/chat-discord.md
index 7f8630a1562..1a93ce872d9 100644
--- a/.changeset/chat-discord.md
+++ b/.changeset/chat-discord.md
@@ -2,4 +2,4 @@
 "@effect/chat-discord": patch
 ---
 
-Add `@effect/chat-discord`, an unstable Discord adapter for `effect/chat` built on dfx, with gateway dispatch, threads, reactions and post-then-edit streaming.
+Add `@effect/chat-discord`, an unstable Discord adapter for `effect/chat` built on dfx, with gateway dispatch, threads, reactions, post-then-edit streaming, and buttons, selects and modals through `DiscordChat.interaction` and `layerGatewayInteractions`.
diff --git a/packages/chat/discord/README.md b/packages/chat/discord/README.md
index 773f803cc4e..46a2a89ec96 100644
--- a/packages/chat/discord/README.md
+++ b/packages/chat/discord/README.md
@@ -1,6 +1,6 @@
 # @effect/chat-discord
 
-A [Discord](https://discord.com) adapter for `effect/chat`, built on [dfx](https://github.com/tim-smart/dfx). Includes a structural gateway dispatch entry, a pure event normaliser, a default gateway layer, and every adapter op over dfx's REST client.
+A [Discord](https://discord.com) adapter for `effect/chat`, built on [dfx](https://github.com/tim-smart/dfx). Includes structural entries for gateway dispatches and interactions, pure normalisers, default gateway layers, buttons, selects and modals, and every adapter op over dfx's REST client.
 
 The adapter reads message text, so the application needs the privileged **Message Content** intent, switched on in Discord's developer portal and requested in your dfx gateway config. Without it, message text is empty unless the message mentions the bot, and attachments are missing.
 
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index 07c666f933f..fffbb44011d 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -1,7 +1,7 @@
 /**
  * The Discord adapter for `effect/chat`: the `Registry` layer, the
- * structural dispatch entry, the pure normaliser, a default gateway layer,
- * address helpers and the scoped post options. It runs on dfx: every REST
+ * structural dispatch and interaction entries, the pure normalisers, two
+ * default gateway layers, address helpers and the scoped post options. It runs on dfx: every REST
  * call goes through the `DiscordREST` in context.
  *
  * **Details**
@@ -25,6 +25,7 @@ import { Registry } from "effect/chat/ChatAdapter"
 import type { ChatError } from "effect/chat/ChatError"
 import type { ChatEvent, MessageCreated, ReactionAdded } from "effect/chat/ChatEvent"
 import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
 import type { ParseMention } from "effect/chat/ChatTest"
 import type { ChatThread } from "effect/chat/ChatThread"
 import * as Context from "effect/Context"
@@ -39,6 +40,7 @@ import * as Schema from "effect/Schema"
 import * as Stream from "effect/Stream"
 import * as Adapter from "./internal/adapter.ts"
 import * as Errors from "./internal/errors.ts"
+import * as Interactions from "./internal/interactions.ts"
 import * as Mentions from "./internal/mentions.ts"
 import * as Normalize from "./internal/normalize.ts"
 import { CurrentPostOptions } from "./internal/options.ts"
@@ -57,6 +59,22 @@ import { CurrentPostOptions } from "./internal/options.ts"
  *   the channel up, cached and with a five second timeout. A failed lookup
  *   is logged and fails with `NotAccepted`. A lookup that would fail the same
  *   way again, such as a deleted channel, is logged and the event dropped.
+ * - `interaction` takes one `INTERACTION_CREATE` payload, from the gateway
+ *   or from an HTTP interactions endpoint. It reads it with a Schema, so it
+ *   takes no dfx type, and ignores an interaction that is not from an
+ *   element this adapter built, a slash command for one. It calls the
+ *   handler through `ChatInteraction.handle` and answers through the
+ *   interaction callback endpoint, which has to land inside Discord's 3
+ *   seconds: `deadline` is the handler's share, 2 seconds by default.
+ * - A click is answered with callback type 6, or type 9 for `OpenModal`.
+ *   A submit's `close` is type 6. An `errors` reply is type 4 with the
+ *   ephemeral flag, listing each message as plain text, and the modal closes: Discord
+ *   can't show an error inside a modal, so the descriptor has no
+ *   `modalErrors`.
+ * - A modal that can't be built, or whose callback fails, goes to
+ *   `Handler.refused`. A callback that comes back 404 `Unknown interaction`
+ *   was late: for a modal that is `NotFound` with detail
+ *   `interaction_expired`. A failed ack is logged.
  * - `guild` reads the channel, cached. `None` for a direct.
  *
  * @stability unstable
@@ -69,6 +87,10 @@ export class DiscordChat extends Context.Service Effect.Effect
+  readonly interaction: (interaction: unknown, options?: {
+    /** The handler's share of Discord's 3 seconds. Default 2 seconds. */
+    readonly deadline?: Duration.Duration | undefined
+  }) => Effect.Effect
   readonly guild: (thread: ChatThread) => Effect.Effect, ChatError>
 }>()("@effect/chat-discord/DiscordChat") {}
 
@@ -92,6 +114,26 @@ const lookupTimeout = Duration.seconds(5)
  *   otherwise. A reply does not ping its author.
  * - `post` and `edit` fail with `TooLarge` before calling Discord past
  *   2,000 code points.
+ * - A refused file fails `denied` with detail `file_refused` and leaves
+ *   nothing posted: more than 10 files or 10 MiB, by the adapter's own
+ *   check, or any `denied` answer to a post with files. The reason Discord
+ *   gave is the `cause`.
+ * - A message's elements go out as classic components beside `content`,
+ *   in action rows: five buttons to a row and a select alone in its row, in
+ *   the order given, up to five rows. More fail `TooLarge` before the call.
+ *   An `edit` without `actions` removes the ones there were.
+ * - A button's id and encoded value share one `custom_id`, joined by one
+ *   character, and so do a modal's id and its metadata. An id may not
+ *   contain U+241F, the join. `limits.actionDataLength` and
+ *   `limits.modalMetadataLength` are 99 code points, the 100 of
+ *   `custom_id` less the join.
+ * - Button styles: `default` is secondary, `primary` primary and
+ *   `danger` danger.
+ * - A modal's inputs are Label components around a text input or a string
+ *   select, and a `text` is a text display. Inputs and texts together are
+ *   5 at most. A modal over that, or with a title or label over 45
+ *   characters, reaches `Handler.refused` as `TooLarge`. Discord has no
+ *   submit label, so `submitLabel` is not shown.
  * - `replyTo` sends a message reference.
  * - Only `DEFAULT`, `REPLY`, `CHAT_INPUT_COMMAND` and
  *   `CONTEXT_MENU_COMMAND` messages are messages. A forward, a poll, a
@@ -140,7 +182,7 @@ export const layer: Layer.Layer
@@ -174,7 +216,7 @@ export const layer: Layer.Layer = Layer.effectDiscard(
+  Effect.gen(function*() {
+    const gateway = yield* DiscordGateway
+    const discord = yield* DiscordChat
+    const handler = yield* ChatInteraction.Handler
+    yield* gateway.fromDispatch("INTERACTION_CREATE").pipe(
+      Stream.mapEffect(
+        (payload) =>
+          discord.interaction(payload).pipe(
+            Effect.provideService(ChatInteraction.Handler, handler),
+            Effect.catchCause((cause) => Effect.logWarning("discord gateway: interaction dropped", cause))
+          ),
+        { concurrency: "unbounded" }
+      ),
+      Stream.runDrain,
+      Effect.forkScoped
+    )
+  })
+)
+
+/**
+ * The normaliser behind `DiscordChat.interaction`.
+ *
+ * **Details**
+ *
+ * - Pure. A click on a button gives `ButtonClicked`, with the id and value
+ *   split from the `custom_id`. A string select gives `SelectChanged`, and
+ *   a modal's submit `ModalSubmitted`, its metadata split from the modal's
+ *   `custom_id`.
+ * - The thread and message come from the `message` Discord sends with the
+ *   interaction, so a modal's submit carries the message whose element
+ *   opened it.
+ * - A submit's `values` hold each answered input by id. An input left
+ *   empty is absent.
+ * - Anything else, a slash command or an interaction with no message, is
+ *   `None`.
+ * - `raw` is the payload, undecoded.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const normalizeInteraction: (interaction: unknown) => Option.Option =
+  Interactions.normalize
+
 /**
  * Discord options for every write inside an effect.
  *
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index 225c19db5be..211144b4112 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -1,4 +1,5 @@
 import type { DiscordREST } from "dfx/DiscordREST"
+import type * as Discord from "dfx/types"
 import * as Cache from "effect/Cache"
 import {
   type ChatAdapter,
@@ -10,7 +11,15 @@ import {
   type ThreadInfo,
   type User
 } from "effect/chat/ChatAdapter"
-import { type ChatError, type ChatErrorReason, TooLarge, Unsupported } from "effect/chat/ChatError"
+import {
+  type ChatError,
+  type ChatErrorReason,
+  fileRefused,
+  interactionExpired,
+  NotFound,
+  TooLarge
+} from "effect/chat/ChatError"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
 import type { ChatMessage } from "effect/chat/ChatMessage"
 import type * as ChatThread from "effect/chat/ChatThread"
 import type { Action } from "effect/chat/ChatUi"
@@ -24,6 +33,7 @@ import * as Option from "effect/Option"
 import * as Schema from "effect/Schema"
 import * as Stream from "effect/Stream"
 import * as Errors from "./errors.ts"
+import * as Interactions from "./interactions.ts"
 import * as Length from "./length.ts"
 import * as Normalize from "./normalize.ts"
 import { allowedMentions, CurrentPostOptions, flags } from "./options.ts"
@@ -45,14 +55,19 @@ export const descriptor: Descriptor = {
     "startThread",
     "getThread",
     "opener",
-    "getUser"
+    "getUser",
+    "buttons",
+    "selects",
+    "modals"
   ]),
-  measure: Length.codePoints,
+  // Components sit beside `content`, so the elements cost nothing here.
+  measure: (markdown) => Length.codePoints(markdown),
   limits: {
     messageLength: Length.messageLength,
     filesPerMessage: 10,
     uploadBytes: 10 * 1024 * 1024,
-    minWriteInterval: Duration.millis(1500)
+    minWriteInterval: Duration.millis(1500),
+    ...Interactions.limits
   }
 }
 
@@ -62,6 +77,8 @@ const pageSize = 100
 const THREAD_ALREADY_CREATED = 160004
 /** Discord's code for "cannot execute action on this channel type". */
 const WRONG_CHANNEL_TYPE = 50024
+/** Discord's code for "unknown interaction": a callback after the 3 seconds. */
+const UNKNOWN_INTERACTION = 10062
 
 const optional = (schema: S) => Schema.optionalKey(Schema.NullOr(schema))
 
@@ -114,12 +131,11 @@ export const make = Effect.fnUntraced(function*(options: {
 
   const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
 
-  /** The descriptor lists no buttons or selects yet, so a write that carries them is refused, never sent without them. */
-  const refuseActions = (op: string, actions: ReadonlyArray | undefined) =>
-    actions === undefined || actions.length === 0 ? Effect.void : fail(
-      op,
-      new Unsupported({ capability: actions.some((action) => action._tag !== "Select") ? "buttons" : "selects" })
-    )
+  /** A message's elements as action rows, checked before any call. */
+  const components = (op: string, actions: ReadonlyArray | undefined) => {
+    const rows = Interactions.rows(actions ?? [])
+    return Array.isArray(rows) ? Effect.succeed(rows) : fail(op, rows)
+  }
 
   /** One REST call, its failure mapped to a `ChatError` and retried when nothing happened. */
   const call = (op: string, effect: Effect.Effect, write = false): Effect.Effect =>
@@ -184,24 +200,31 @@ export const make = Effect.fnUntraced(function*(options: {
   const post: ChatAdapter["post"] = Effect.fnUntraced(function*(thread, content) {
     const op = "post"
     const channelId = yield* resolve(op, thread)
-    yield* refuseActions(op, content.actions)
+    const rows = yield* components(op, content.actions)
     const postOptions = yield* CurrentPostOptions
     yield* checkMessageLength(descriptor, op, content.markdown)
     const files = content.files ?? []
-    if (files.length > descriptor.limits.filesPerMessage) {
-      return yield* fail(op, new TooLarge({ subject: "files", detail: "too_many_files" }))
-    }
-    if (files.reduce((total, file) => total + file.content.length, 0) > descriptor.limits.uploadBytes) {
-      return yield* fail(op, new TooLarge({ subject: "files", detail: "upload_too_large" }))
+    // The adapter's own count and size check refuses the file the way Discord would.
+    if (
+      files.length > descriptor.limits.filesPerMessage ||
+      files.reduce((total, file) => total + file.content.length, 0) > descriptor.limits.uploadBytes
+    ) {
+      return yield* fail(op, new TooLarge({ subject: "files", detail: fileRefused }))
     }
     const create = rest.createMessage(channelId, {
       content: content.markdown,
       allowed_mentions: allowedMentions(postOptions.notify),
       flags: flags(postOptions),
+      ...(rows.length === 0 ? {} : { components: rows }),
       ...(content.replyTo === undefined ? {} : { message_reference: { message_id: content.replyTo.messageId } }),
       ...(files.length === 0 ? {} : { attachments: files.map((file, i) => ({ id: String(i), filename: file.name })) })
     })
-    const answer = yield* call(op, files.length === 0 ? create : rest.withFiles(files.map(toFile))(create), true)
+    const answer = yield* (files.length === 0
+      ? call(op, create, true)
+      // Discord creates the message and its files in one request, so a denied answer left nothing posted.
+      : call(op, rest.withFiles(files.map(toFile))(create), true).pipe(
+        Effect.mapError((error) => Errors.chatError(op, Errors.fileRefused(error.reason)))
+      ))
     if (typeof answer.id !== "string" || typeof answer.timestamp !== "string") {
       return yield* fail(op, Errors.invalidResponse(true, "missing_id"))
     }
@@ -213,7 +236,7 @@ export const make = Effect.fnUntraced(function*(options: {
   const edit: ChatAdapter["edit"] = Effect.fnUntraced(function*(thread, messageId, content) {
     const op = "edit"
     const channelId = yield* resolve(op, thread)
-    yield* refuseActions(op, content.actions)
+    const rows = yield* components(op, content.actions)
     const postOptions = yield* CurrentPostOptions
     yield* checkMessageLength(descriptor, op, content.markdown)
     yield* call(
@@ -221,7 +244,9 @@ export const make = Effect.fnUntraced(function*(options: {
       rest.updateMessage(channelId, messageId, {
         content: content.markdown,
         allowed_mentions: allowedMentions(postOptions.notify),
-        flags: flags(postOptions)
+        flags: flags(postOptions),
+        // Always sent, so an edit without elements removes the ones there were.
+        components: rows
       }),
       true
     )
@@ -463,5 +488,66 @@ export const make = Effect.fnUntraced(function*(options: {
   const channelType = (id: string): Effect.Effect =>
     Effect.map(channel("dispatch", id), (found) => found.type)
 
-  return { adapter, guild, channelType }
+  // Interactions
+
+  /** One callback, Discord's answer to an interaction. */
+  const callback = (
+    op: string,
+    to: { readonly id: string; readonly token: string },
+    payload: Discord.CreateInteractionResponseRequest
+  ): Effect.Effect =>
+    Effect.asVoid(call(op, rest.createInteractionResponse(to.id, to.token, { payload }), true))
+
+  const logged = (effect: Effect.Effect) =>
+    Effect.catch(effect, (error) => Effect.logWarning("@effect/chat-discord: an interaction callback failed", error))
+
+  /**
+   * Normalises an `INTERACTION_CREATE` payload, runs the handler inside
+   * `deadline` and answers through the callback endpoint.
+   */
+  const interaction = (
+    raw: unknown,
+    interactionOptions?: { readonly deadline?: Duration.Duration | undefined }
+  ): Effect.Effect =>
+    Effect.gen(function*() {
+      const event = Interactions.normalize(raw)
+      const to = Interactions.answerTo(raw)
+      if (Option.isNone(event) || to === undefined) return
+      const reply = yield* ChatInteraction.handle(event.value, interactionOptions?.deadline ?? Duration.seconds(2))
+      switch (reply._tag) {
+        // Too late to answer: Discord shows its own banner.
+        case "Late":
+          return
+        case "Ack":
+        case "Close":
+          return yield* logged(callback("ack", to, Interactions.ackCallback))
+        case "Errors":
+          return yield* logged(callback("errors", to, Interactions.errorsCallback(reply.errors)))
+        case "OpenModal": {
+          const click = event.value as ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
+          const handler = yield* ChatInteraction.Handler
+          const data = Interactions.modalData(reply.modal)
+          if (!("custom_id" in data)) {
+            // The click is still answered, so the person sees no failure for a modal that could not be built.
+            yield* logged(callback("ack", to, Interactions.ackCallback))
+            return yield* handler.refused(click, Errors.chatError("openModal", data))
+          }
+          yield* callback("openModal", to, Interactions.modalCallback(data)).pipe(
+            Effect.catch((error) =>
+              handler.refused(
+                click,
+                Errors.hasCode(UNKNOWN_INTERACTION)(error)
+                  ? Errors.chatError(
+                    "openModal",
+                    new NotFound({ detail: interactionExpired, cause: error.reason })
+                  )
+                  : error
+              )
+            )
+          )
+        }
+      }
+    })
+
+  return { adapter, guild, channelType, interaction }
 })
diff --git a/packages/chat/discord/src/internal/errors.ts b/packages/chat/discord/src/internal/errors.ts
index 1eb29dcb93b..4bc44c89973 100644
--- a/packages/chat/discord/src/internal/errors.ts
+++ b/packages/chat/discord/src/internal/errors.ts
@@ -1,16 +1,19 @@
 import {
   ChatError,
   type ChatErrorReason,
+  fileRefused as fileRefusedDetail,
   Forbidden,
   InvalidRequest,
   InvalidResponse,
+  NoAdapter,
   NotFound,
   PlatformUnavailable,
   RateLimited,
   TooLarge,
   Transport,
   Unauthenticated,
-  Unknown
+  Unknown,
+  Unsupported
 } from "effect/chat/ChatError"
 import * as Duration from "effect/Duration"
 import { platform } from "./normalize.ts"
@@ -108,6 +111,10 @@ export const reasonForRestError = (error: unknown, options: { readonly write: bo
     const reason = tagged.reason
     const reasonResponse = isObject(reason.response) ? reason.response : undefined
     const reasonStatus = typeof reasonResponse?.status === "number" ? reasonResponse.status : undefined
+    // An error status whose body is not JSON, such as a 413 from the edge, is still Discord's answer.
+    if (reasonStatus !== undefined && reasonStatus >= 400 && reasonStatus < 500) {
+      return reasonForResponse(reasonStatus, undefined, { write: options.write, cause: error })
+    }
     switch (reason._tag) {
       case "StatusCodeError":
         return reasonForResponse(reasonStatus ?? 500, undefined, { write: options.write, cause: error })
@@ -138,3 +145,40 @@ export const notFound = (detail: string): ChatErrorReason => new NotFound({ deta
  * @internal
  */
 export const hasCode = (code: number) => (error: ChatError): boolean => error.reason.detail === String(code)
+
+/**
+ * A `denied` reason from a post that carries files, as a refused file: the
+ * same reason with detail `file_refused`, and the reason it replaces, with
+ * Discord's code, as its `cause`. Any other reason is returned as it is.
+ *
+ * @internal
+ */
+export const fileRefused = (reason: ChatErrorReason): ChatErrorReason => {
+  if (reason.retry !== "denied" || reason.detail === fileRefusedDetail) return reason
+  const fields = { detail: fileRefusedDetail, cause: reason }
+  switch (reason._tag) {
+    case "Unsupported":
+      return new Unsupported({ capability: reason.capability, ...fields })
+    case "Transport":
+      return new Transport({ retry: reason.retry, ...fields })
+    case "PlatformUnavailable":
+      return new PlatformUnavailable({ retry: reason.retry, ...fields })
+    case "NoAdapter":
+      return new NoAdapter(fields)
+    case "Unauthenticated":
+      return new Unauthenticated(fields)
+    case "Forbidden":
+      return new Forbidden(fields)
+    case "NotFound":
+      return new NotFound(fields)
+    case "TooLarge":
+      return new TooLarge({ ...(reason.subject === undefined ? {} : { subject: reason.subject }), ...fields })
+    case "InvalidRequest":
+      return new InvalidRequest(fields)
+    case "InvalidResponse":
+      return new InvalidResponse(fields)
+    case "RateLimited":
+    case "Unknown":
+      return reason
+  }
+}
diff --git a/packages/chat/discord/src/internal/interactions.ts b/packages/chat/discord/src/internal/interactions.ts
new file mode 100644
index 00000000000..23da46a9800
--- /dev/null
+++ b/packages/chat/discord/src/internal/interactions.ts
@@ -0,0 +1,304 @@
+import type * as Discord from "dfx/types"
+import type { ChatErrorReason } from "effect/chat/ChatError"
+import { InvalidRequest, TooLarge } from "effect/chat/ChatError"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type * as ChatUi from "effect/chat/ChatUi"
+import * as Option from "effect/Option"
+import * as Schema from "effect/Schema"
+import { codePoints, cut, messageLength } from "./length.ts"
+import * as Normalize from "./normalize.ts"
+
+/**
+ * The one character between an id and its value in a `custom_id`, for a
+ * button and for a modal's metadata. An id may not hold it, so the first one
+ * in a `custom_id` is the join.
+ *
+ * @internal
+ */
+export const join = "\u241F"
+
+/** @internal */
+export const limits = {
+  actionsPerMessage: 25,
+  actionDataLength: 99,
+  modalMetadataLength: 99,
+  modalFields: 5
+} as const
+
+/** Discord's limits on rows, a row's buttons, a modal's title and an input's label. */
+const rowsPerMessage = 5
+const buttonsPerRow = 5
+const titleLength = 45
+const labelLength = 45
+
+/** Discord's interaction callback types. */
+const DEFERRED_UPDATE_MESSAGE = 6
+const CHANNEL_MESSAGE_WITH_SOURCE = 4
+const MODAL = 9
+const EPHEMERAL = 1 << 6
+
+/** `custom_id` for an id and an optional value. */
+const customId = (id: string, value: string | undefined): string => value === undefined ? id : id + join + value
+
+/** An id and its value from a `custom_id`, split at the first join. */
+const splitCustomId = (customId: string): { readonly id: string; readonly value?: string } => {
+  const at = customId.indexOf(join)
+  return at === -1 ? { id: customId } : { id: customId.slice(0, at), value: customId.slice(at + 1) }
+}
+
+const buttonStyle = (style: ChatUi.ButtonStyle | undefined): Discord.ButtonStyleTypes =>
+  style === "primary" ? 1 : style === "danger" ? 4 : 2
+
+type Row = Discord.ActionRowComponentForMessageRequest
+type Component = Row["components"][number]
+
+/**
+ * A message's elements as action rows, or why they can't go: five buttons to
+ * a row and a select alone in its row, in the order given, up to five rows.
+ *
+ * @internal
+ */
+export const rows = (actions: ReadonlyArray): Array | ChatErrorReason => {
+  if (actions.length > limits.actionsPerMessage) return new TooLarge({ detail: "too_many_actions" })
+  const out: Array<{ type: 1; components: Array }> = []
+  let open: Array | undefined
+  for (const action of actions) {
+    switch (action._tag) {
+      case "Button":
+      case "LinkButton": {
+        if (action._tag === "Button") {
+          if (action.id.includes(join)) return new InvalidRequest({ detail: "invalid_action_id" })
+          if (codePoints(action.id) + codePoints(action.value ?? "") > limits.actionDataLength) {
+            return new TooLarge({ detail: "action_data_too_long" })
+          }
+        }
+        const button: Component = action._tag === "Button"
+          ? {
+            type: 2,
+            style: buttonStyle(action.style),
+            label: action.label,
+            custom_id: customId(action.id, action.value)
+          }
+          : { type: 2, style: 5, label: action.label, url: action.url }
+        if (open === undefined || open.length === buttonsPerRow) {
+          open = [button]
+          out.push({ type: 1, components: open })
+        } else {
+          open.push(button)
+        }
+        break
+      }
+      case "Select": {
+        const id = codePoints(action.id)
+        if (action.options.some((option) => id + codePoints(option.value) > limits.actionDataLength)) {
+          return new TooLarge({ detail: "action_data_too_long" })
+        }
+        open = undefined
+        out.push({
+          type: 1,
+          components: [{
+            type: 3,
+            custom_id: action.id,
+            ...(action.placeholder === undefined ? {} : { placeholder: action.placeholder }),
+            options: action.options.map((option) => ({
+              label: option.label,
+              value: option.value,
+              ...(option.value === action.selected ? { default: true } : {})
+            })),
+            min_values: 1,
+            max_values: 1
+          }]
+        })
+        break
+      }
+    }
+  }
+  return out.length > rowsPerMessage ? new TooLarge({ detail: "too_many_actions" }) : out
+}
+
+/**
+ * Discord's Markdown escape for any ASCII punctuation, so a modal's text
+ * shows as written.
+ */
+const plain = (text: string): string => text.replace(/[!-/:-@[-`{-~]/g, "\\$&")
+
+type ModalData = Discord.ModalInteractionCallbackRequestData
+
+/**
+ * The callback data that opens `modal`, or why it can't open. Inputs are
+ * Label components around a text input or a string select, and a `Text` is
+ * a text display. Discord has no submit label, so `submitLabel` is not sent.
+ *
+ * @internal
+ */
+export const modalData = (modal: ChatUi.Modal): ModalData | ChatErrorReason => {
+  if (modal.id.includes(join)) return new InvalidRequest({ detail: "invalid_modal_id" })
+  if (codePoints(modal.id) + codePoints(modal.metadata ?? "") > limits.modalMetadataLength) {
+    return new TooLarge({ detail: "modal_metadata_too_long" })
+  }
+  if (modal.elements.length > limits.modalFields) return new TooLarge({ detail: "too_many_fields" })
+  if (codePoints(modal.title) > titleLength) return new TooLarge({ detail: "title_too_long" })
+  const components: Array = []
+  for (const element of modal.elements) {
+    if (element._tag === "Text") {
+      components.push({ type: 10, content: plain(element.text) })
+      continue
+    }
+    if (codePoints(element.label) > labelLength) return new TooLarge({ detail: "label_too_long" })
+    const required = element.optional !== true
+    components.push({
+      type: 18,
+      label: element.label,
+      component: element._tag === "TextInput"
+        ? {
+          type: 4,
+          custom_id: element.id,
+          style: element.multiline === true ? 2 : 1,
+          required,
+          ...(element.placeholder === undefined ? {} : { placeholder: element.placeholder }),
+          ...(element.initial === undefined ? {} : { value: element.initial }),
+          ...(element.minLength === undefined ? {} : { min_length: element.minLength }),
+          ...(element.maxLength === undefined ? {} : { max_length: element.maxLength })
+        }
+        : {
+          type: 3,
+          custom_id: element.id,
+          required,
+          min_values: required ? 1 : 0,
+          max_values: 1,
+          ...(element.placeholder === undefined ? {} : { placeholder: element.placeholder }),
+          options: element.options.map((option) => ({
+            label: option.label,
+            value: option.value,
+            ...(option.value === element.initial ? { default: true } : {})
+          }))
+        }
+    })
+  }
+  return { custom_id: customId(modal.id, modal.metadata), title: modal.title, components }
+}
+
+type Callback = Discord.CreateInteractionResponseRequest
+
+/** @internal */
+export const ackCallback: Callback = { type: DEFERRED_UPDATE_MESSAGE }
+
+/** @internal */
+export const modalCallback = (data: ModalData): Callback => ({ type: MODAL, data })
+
+/**
+ * The answer to an `errors` reply: a private message listing each one, as
+ * plain text, cut to fit one message. The modal closes.
+ *
+ * @internal
+ */
+export const errorsCallback = (errors: Readonly>): Callback => ({
+  type: CHANNEL_MESSAGE_WITH_SOURCE,
+  data: {
+    content: cut(Object.values(errors).map((message) => "- " + plain(message)).join("\n"), messageLength),
+    allowed_mentions: { parse: [] },
+    flags: EPHEMERAL
+  }
+})
+
+// Inbound
+
+const optional = (schema: S) => Schema.optionalKey(Schema.NullOr(schema))
+
+const Input = Schema.Struct({
+  type: Schema.Number,
+  custom_id: optional(Schema.String),
+  value: optional(Schema.String),
+  values: optional(Schema.Array(Schema.String))
+})
+
+const ModalComponent = Schema.Struct({
+  type: Schema.Number,
+  component: optional(Input),
+  components: optional(Schema.Array(Input))
+})
+
+const InteractionFields = Schema.Struct({
+  id: Schema.String,
+  type: Schema.Number,
+  token: Schema.String,
+  channel_id: optional(Schema.String),
+  member: optional(Schema.Struct({ user: optional(Schema.Struct({ id: Schema.String })) })),
+  user: optional(Schema.Struct({ id: Schema.String })),
+  message: optional(Schema.Struct({ id: Schema.String, channel_id: optional(Schema.String) })),
+  data: Schema.Struct({
+    custom_id: Schema.String,
+    component_type: optional(Schema.Number),
+    values: optional(Schema.Array(Schema.String)),
+    components: optional(Schema.Array(ModalComponent))
+  })
+})
+
+const decodeFields = Schema.decodeUnknownOption(InteractionFields)
+
+/** Discord's interaction types for a component click and a modal submit. */
+const MESSAGE_COMPONENT = 3
+const MODAL_SUBMIT = 5
+
+/**
+ * The id and token to answer an interaction with, read from its payload.
+ *
+ * @internal
+ */
+export const answerTo = (raw: unknown): { readonly id: string; readonly token: string } | undefined =>
+  Option.getOrUndefined(Option.map(decodeFields(raw), ({ id, token }) => ({ id, token })))
+
+/**
+ * The interaction a payload is, when it is a click on a button or string
+ * select, or a submit of a modal opened from a message. Anything else, a
+ * slash command for one, is none.
+ *
+ * @internal
+ */
+export const normalize = (raw: unknown): Option.Option => {
+  const decoded = decodeFields(raw)
+  if (Option.isNone(decoded)) return Option.none()
+  const fields = decoded.value
+  const message = fields.message
+  const userId = fields.member?.user?.id ?? fields.user?.id
+  const channelId = message?.channel_id ?? fields.channel_id
+  if (
+    message === null || message === undefined || userId === undefined || channelId === null || channelId === undefined
+  ) {
+    return Option.none()
+  }
+  const origin = { thread: Normalize.thread(channelId), messageId: message.id, userId, raw: raw as Schema.Json }
+  const { data } = fields
+  if (fields.type === MESSAGE_COMPONENT && data.component_type === 2) {
+    const { id, value } = splitCustomId(data.custom_id)
+    return Option.some(ChatInteraction.ButtonClicked.make({ id, ...(value === undefined ? {} : { value }), ...origin }))
+  }
+  if (fields.type === MESSAGE_COMPONENT && data.component_type === 3) {
+    const value = data.values?.[0]
+    return value === undefined
+      ? Option.none()
+      : Option.some(ChatInteraction.SelectChanged.make({ id: data.custom_id, value, ...origin }))
+  }
+  if (fields.type === MODAL_SUBMIT) {
+    const values: Record = {}
+    for (const component of data.components ?? []) {
+      const inputs = component.component === null || component.component === undefined
+        ? component.components ?? []
+        : [component.component]
+      for (const input of inputs) {
+        const value = input.value ?? input.values?.[0]
+        if (typeof input.custom_id === "string" && value !== null && value !== undefined && value !== "") {
+          values[input.custom_id] = value
+        }
+      }
+    }
+    const { id, value: metadata } = splitCustomId(data.custom_id)
+    return Option.some(ChatInteraction.ModalSubmitted.make({
+      id,
+      ...(metadata === undefined ? {} : { metadata }),
+      values,
+      ...origin
+    }))
+  }
+  return Option.none()
+}
diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index 9240f63302b..5a05455c8c5 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -3,6 +3,7 @@ import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
 import { checkMessage } from "effect/chat/ChatTest"
+import type * as ChatUi from "effect/chat/ChatUi"
 import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
 import * as Option from "effect/Option"
@@ -218,23 +219,158 @@ describe("post", () => {
 })
 
 describe("buttons and selects", () => {
-  it.effect("are refused with Unsupported until the adapter supports them, calling nothing", () => {
+  const button = (i: number): ChatUi.Button => ({ _tag: "Button", id: "b" + i, label: "B" + i })
+  const select: ChatUi.Select = {
+    _tag: "Select",
+    id: "pick",
+    placeholder: "Pick",
+    options: [{ label: "A", value: "a" }, { label: "B", value: "b" }],
+    selected: "b"
+  }
+  const rowsOf = (fake: Fake) => fake.called("createMessage")[0][1].components
+
+  it.effect("go out as action rows: five buttons to a row and a select alone in its row", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.post(channel, {
+          markdown: "x",
+          actions: [
+            { _tag: "Button", id: "go", label: "Go", style: "primary", value: "v" },
+            { _tag: "Button", id: "stop", label: "Stop", style: "danger" },
+            { _tag: "LinkButton", label: "Docs", url: "https://effect.website" },
+            select,
+            ...Array.from({ length: 6 }, (_, i) => button(i))
+          ]
+        })
+        assert.deepStrictEqual(rowsOf(fake), [
+          {
+            type: 1,
+            components: [
+              { type: 2, style: 1, label: "Go", custom_id: "go\u241Fv" },
+              { type: 2, style: 4, label: "Stop", custom_id: "stop" },
+              { type: 2, style: 5, label: "Docs", url: "https://effect.website" }
+            ]
+          },
+          {
+            type: 1,
+            components: [{
+              type: 3,
+              custom_id: "pick",
+              placeholder: "Pick",
+              options: [{ label: "A", value: "a" }, { label: "B", value: "b", default: true }],
+              min_values: 1,
+              max_values: 1
+            }]
+          },
+          {
+            type: 1,
+            components: [0, 1, 2, 3, 4].map((i) => ({ type: 2, style: 2, label: "B" + i, custom_id: "b" + i }))
+          },
+          { type: 1, components: [{ type: 2, style: 2, label: "B5", custom_id: "b5" }] }
+        ])
+      })
+    )
+  })
+
+  it.effect("fail TooLarge before the call when the rows run out or a custom_id would pass 100", () => {
     const fake = makeFake({})
     return run(
       fake,
       Effect.gen(function*() {
         const discord = yield* adapter
-        const post = yield* reason(discord.post(channel, {
+        const post = (actions: ReadonlyArray) =>
+          reason(discord.post(channel, { markdown: "x", actions }))
+        assert.deepStrictEqual(discord.descriptor.limits.actionsPerMessage, 25)
+        assert.strictEqual((yield* post(Array.from({ length: 26 }, (_, i) => button(i)))).detail, "too_many_actions")
+        // Six selects need six rows.
+        assert.strictEqual((yield* post(Array.from({ length: 6 }, () => select))).detail, "too_many_actions")
+        // 99 code points of id and value fit, with the join, in Discord's 100.
+        const astral = "\u{1D400}"
+        assert.strictEqual(
+          (yield* post([{ _tag: "Button", id: "id", label: "x", value: astral.repeat(98) }])).detail,
+          "action_data_too_long"
+        )
+        assert.strictEqual(
+          (yield* post([{ ...select, options: [{ label: "x", value: "x".repeat(96) }] }])).tag,
+          "TooLarge"
+        )
+        assert.strictEqual(
+          (yield* post([{ _tag: "Button", id: "a\u241Fb", label: "x" }])).tag,
+          "InvalidRequest"
+        )
+        assert.strictEqual(fake.calls.length, 0)
+      })
+    )
+  })
+
+  it.effect("an id and value of 99 code points fit", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.post(channel, {
           markdown: "x",
-          actions: [{ _tag: "Button", id: "go", label: "Go" }]
-        }))
-        assert.deepStrictEqual([post.op, post.tag], ["post", "Unsupported"])
-        const edit = yield* reason(discord.edit(channel, "1", {
+          actions: [{ _tag: "Button", id: "id", label: "x", value: "\u{1D400}".repeat(97) }]
+        })
+        assert.strictEqual(fake.called("createMessage").length, 1)
+      })
+    )
+  })
+})
+
+describe("files", () => {
+  const file = { name: "fixture.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }
+  const refused = (fail: () => Effect.Effect) => {
+    const fake = makeFake({ createMessage: fail })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const error = yield* Effect.flip(discord.post(channel, { markdown: "x", files: [file] }))
+        return { tag: error.reason._tag, detail: error.reason.detail, retry: error.retry, cause: error.reason.cause }
+      })
+    )
+  }
+
+  it.effect("a denied answer to a post with files is file_refused, with Discord's reason as the cause", () =>
+    Effect.gen(function*() {
+      for (const [status, code] of [[400, 40005], [400, 50045], [403, 50013]] as const) {
+        const result = yield* refused(() => Effect.fail(errorResponse(status, { code, message: "refused" })))
+        assert.strictEqual(result.detail, "file_refused")
+        assert.strictEqual(result.retry, "denied")
+        assert.strictEqual((result.cause as any).detail, String(code))
+      }
+      // A 413 from Discord's edge has no JSON body.
+      const edge = yield* refused(() =>
+        Effect.fail({ _tag: "HttpClientError", reason: { _tag: "DecodeError", response: { status: 413 } } })
+      )
+      assert.deepStrictEqual([edge.tag, edge.detail, edge.retry], ["TooLarge", "file_refused", "denied"])
+      // A failure that is not denied keeps its own reason.
+      const unavailable = yield* refused(() => Effect.fail(statusCodeError(502)))
+      assert.deepStrictEqual([unavailable.tag, unavailable.detail], ["PlatformUnavailable", "http_502"])
+    }))
+
+  it.effect("the adapter's own count and size check is file_refused, without a call", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const tooMany = yield* reason(
+          discord.post(channel, { markdown: "x", files: Array.from({ length: 11 }, () => file) })
+        )
+        const tooBig = yield* reason(discord.post(channel, {
           markdown: "x",
-          actions: [{ _tag: "Select", id: "pick", options: [{ label: "A", value: "a" }] }]
+          files: [{ ...file, content: new Uint8Array(10 * 1024 * 1024 + 1) }]
         }))
-        assert.deepStrictEqual([edit.op, edit.tag], ["edit", "Unsupported"])
-        assert.strictEqual(fake.called("createMessage").length + fake.called("updateMessage").length, 0)
+        for (const result of [tooMany, tooBig]) {
+          assert.deepStrictEqual(result, { op: "post", tag: "TooLarge", detail: "file_refused", retry: "denied" })
+        }
+        assert.strictEqual(fake.calls.length, 0)
       })
     )
   })
@@ -251,7 +387,8 @@ describe("edit", () => {
         assert.deepStrictEqual(fake.called("updateMessage"), [[scratch, "1", {
           content: "now with https://effect.website",
           allowed_mentions: noMentions,
-          flags: 4
+          flags: 4,
+          components: []
         }]])
         assert.deepStrictEqual(yield* reason(discord.edit(channel, "1", { markdown: "a".repeat(2001) })), {
           op: "edit",
diff --git a/packages/chat/discord/test/conformance.test.ts b/packages/chat/discord/test/conformance.test.ts
new file mode 100644
index 00000000000..0b8524d03f6
--- /dev/null
+++ b/packages/chat/discord/test/conformance.test.ts
@@ -0,0 +1,48 @@
+/**
+ * The conformance rules for files, buttons and modals, against the adapter
+ * over a stubbed `DiscordREST` that keeps what was posted. Clicks and
+ * submits are built from the posted components and go through
+ * `DiscordChat.interaction`, so the callback answers are tested too.
+ */
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { describe, it } from "@effect/vitest"
+import { conformance } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import { makeDiscord } from "./discord.ts"
+import { discordLayer, scratch } from "./utils.ts"
+
+const portable = (name: string) =>
+  name === "post/refusedFile" ||
+  name.startsWith("actions/") ||
+  name.startsWith("modal/") ||
+  name.startsWith("edit/") && name.endsWith("Actions") ||
+  name.startsWith("descriptor/measure") && name.endsWith("Actions") ||
+  name === "unsupported/buttons" ||
+  name === "unsupported/selects" ||
+  name === "unsupported/modals"
+
+describe("conformance over the stubbed DiscordREST", () => {
+  const names = Object.keys(conformance({
+    platform: "discord",
+    thread: DiscordChat.thread(scratch),
+    userPosts: () => Effect.die("unused"),
+    parseMention: DiscordChat.parseMention,
+    refuseFiles: () => Effect.void,
+    interactions: { click: () => Effect.void, submit: () => Effect.void }
+  })).filter(portable)
+
+  for (const name of names) {
+    it.effect(name, () => {
+      const discord = makeDiscord()
+      const rules = conformance({
+        platform: "discord",
+        thread: DiscordChat.thread(scratch),
+        userPosts: () => Effect.die("unused"),
+        parseMention: DiscordChat.parseMention,
+        refuseFiles: discord.refuseFiles,
+        interactions: discord.interactions
+      })
+      return Effect.andThen(discord.bind, rules[name]).pipe(Effect.provide(discordLayer(discord.fake)))
+    })
+  }
+})
diff --git a/packages/chat/discord/test/discord.ts b/packages/chat/discord/test/discord.ts
new file mode 100644
index 00000000000..6a5b2afa371
--- /dev/null
+++ b/packages/chat/discord/test/discord.ts
@@ -0,0 +1,162 @@
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { type Interactions, NoSuchElement } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import { botUserId, errorResponse, type Fake, guild, makeFake, tim } from "./utils.ts"
+
+/** The join between an id and its value in a `custom_id`, as the adapter writes it. */
+const join = "\u241F"
+
+const idOf = (customId: string): string => customId.split(join)[0]
+
+/**
+ * A Discord that keeps the messages the adapter posts, with their
+ * components, and records every interaction callback. `interactions` is the
+ * conformance hook: it builds Discord's `INTERACTION_CREATE` payload from
+ * what was posted and sends it through `DiscordChat.interaction`.
+ */
+export const makeDiscord = (channelType = 0) => {
+  const messages = new Map()
+  const callbacks: Array<{ readonly id: string; readonly token: string; readonly payload: any }> = []
+  let next = 1570700000000000000n
+  let refuse = 0
+  let interactionCount = 0
+  const nextId = () => String(next++)
+
+  const unknownMessage = () => Effect.fail(errorResponse(404, { code: 10008, message: "Unknown Message" }))
+
+  const fake: Fake = makeFake({
+    getChannel: (id: string) => Effect.succeed({ id, type: channelType, guild_id: guild, name: "scratch" }),
+    createMessage: (channelId: string, body: any) => {
+      if ((body.attachments ?? []).length > 0 && refuse > 0) {
+        refuse--
+        return Effect.fail(errorResponse(400, { code: 40005, message: "Request entity too large" }))
+      }
+      const id = nextId()
+      const message = {
+        id,
+        channel_id: channelId,
+        type: 0,
+        content: body.content,
+        timestamp: new Date(Number((BigInt(id) >> 22n) + 1420070400000n)).toISOString(),
+        author: { id: botUserId, username: "Janitor", bot: true },
+        attachments: [],
+        components: body.components ?? []
+      }
+      messages.set(id, message)
+      return Effect.succeed(message)
+    },
+    updateMessage: (_channelId: string, id: string, body: any) => {
+      const message = messages.get(id)
+      if (message === undefined) return unknownMessage()
+      message.content = body.content
+      if (body.components !== undefined) message.components = body.components
+      return Effect.succeed(message)
+    },
+    getMessage: (_channelId: string, id: string) => {
+      const message = messages.get(id)
+      return message === undefined ? unknownMessage() : Effect.succeed(message)
+    },
+    deleteMessage: (_channelId: string, id: string) =>
+      messages.delete(id) ? Effect.succeed(undefined) : unknownMessage(),
+    listMessages: (channelId: string, params: { after?: string; before?: string; limit: number }) =>
+      Effect.succeed(
+        [...messages.values()]
+          .filter((message) =>
+            message.channel_id === channelId &&
+            (params.after === undefined || BigInt(message.id) > BigInt(params.after)) &&
+            (params.before === undefined || BigInt(message.id) < BigInt(params.before))
+          )
+          .sort((a, b) => (BigInt(b.id) > BigInt(a.id) ? 1 : -1))
+          .slice(0, params.limit)
+      ),
+    createInteractionResponse: (id: string, token: string, options: { payload: any }) => {
+      callbacks.push({ id, token, payload: options.payload })
+      return Effect.succeed(null)
+    }
+  })
+
+  /** The modal the last click opened, with the message it was opened from. */
+  let opened: { readonly data: any; readonly message: any } | undefined
+
+  /** The service the hook delivers through, set by `bind`. */
+  let service: DiscordChat.DiscordChat["Service"] | undefined
+
+  const deliver = Effect.fnUntraced(function*(payload: Record) {
+    const before = callbacks.length
+    yield* service!.interaction(payload)
+    return callbacks.slice(before).find((callback) => callback.id === payload.id)?.payload
+  })
+
+  const base = (message: any) => {
+    const n = ++interactionCount
+    return {
+      id: "9" + String(n).padStart(18, "0"),
+      application_id: botUserId,
+      token: "token-" + n,
+      version: 1,
+      channel_id: message.channel_id,
+      guild_id: guild,
+      member: { user: { id: tim, username: "tim" }, roles: [] },
+      message
+    }
+  }
+
+  /** The conformance hook. It delivers through the service `bind` saw last. */
+  const interactions: Interactions = {
+    click: Effect.fnUntraced(function*(messageId, id, options) {
+      const message = messages.get(messageId)
+      const component = (message?.components ?? [])
+        .flatMap((row: any) => row.components)
+        .find((component: any) => typeof component.custom_id === "string" && idOf(component.custom_id) === id)
+      if (component === undefined) return yield* Effect.fail(new NoSuchElement({ messageId, id }))
+      const value = component.type === 3 ? options?.option ?? component.options[0].value : undefined
+      const answer = yield* deliver({
+        ...base(message),
+        type: 3,
+        data: {
+          custom_id: component.custom_id,
+          component_type: component.type,
+          ...(value === undefined ? {} : { values: [value] })
+        }
+      })
+      opened = answer?.type === 9 ? { data: answer.data, message } : undefined
+    }),
+    submit: Effect.fnUntraced(function*(values) {
+      if (opened === undefined) return
+      const { data, message } = opened
+      const components = data.components.map((component: any) => {
+        if (component.type !== 18) return { type: component.type }
+        const input = component.component
+        const value = values[input.custom_id]
+        return {
+          type: 18,
+          component: input.type === 4
+            ? { type: 4, custom_id: input.custom_id, value: value ?? "" }
+            : { type: 3, custom_id: input.custom_id, values: value === undefined ? [] : [value] }
+        }
+      })
+      yield* deliver({
+        ...base(message),
+        type: 5,
+        data: { custom_id: data.custom_id, components }
+      })
+      // Discord closes the modal on every answer, `errors` included.
+      opened = undefined
+    })
+  }
+
+  return {
+    fake,
+    bind: Effect.tap(DiscordChat.DiscordChat, (discord) =>
+      Effect.sync(() => {
+        service = discord
+      })),
+    messages,
+    callbacks,
+    interactions,
+    refuseFiles: () =>
+      Effect.sync(() => {
+        refuse++
+      })
+  }
+}
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
new file mode 100644
index 00000000000..5f48bba0f43
--- /dev/null
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -0,0 +1,291 @@
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { assert, describe, it } from "@effect/vitest"
+import type { ChatError } from "effect/chat/ChatError"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import { checkInteraction } from "effect/chat/ChatTest"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Fiber from "effect/Fiber"
+import * as Option from "effect/Option"
+import * as TestClock from "effect/testing/TestClock"
+import { botUserId, discordLayer, errorResponse, type Fake, guild, makeFake, scratch, tim } from "./utils.ts"
+
+const message = { id: "1570700000000000001", channel_id: scratch }
+
+const click = (data: Record, extra: Record = {}) => ({
+  id: "1570700000000000100",
+  application_id: botUserId,
+  type: 3,
+  token: "token",
+  version: 1,
+  guild_id: guild,
+  channel_id: scratch,
+  member: { user: { id: tim } },
+  message,
+  data,
+  ...extra
+})
+
+const submit = (customId: string, components: ReadonlyArray) =>
+  click({ custom_id: customId, components }, { type: 5 })
+
+const omit = (raw: Record, key: string) => {
+  const { [key]: _, ...rest } = raw
+  return rest
+}
+
+const some = (raw: unknown) => {
+  const interaction = DiscordChat.normalizeInteraction(raw)
+  assert.isTrue(Option.isSome(interaction))
+  return Option.getOrThrow(interaction)
+}
+
+describe("normalizeInteraction", () => {
+  it.effect("a button splits its custom_id into id and value at the first join", () =>
+    Effect.gen(function*() {
+      const withValue = some(click({ custom_id: "go\u241Fa\u241Fb", component_type: 2 }))
+      assert.deepStrictEqual(
+        withValue,
+        ChatInteraction.ButtonClicked.make({
+          id: "go",
+          value: "a\u241Fb",
+          thread: DiscordChat.thread(scratch),
+          messageId: message.id,
+          userId: tim,
+          raw: withValue.raw
+        })
+      )
+      const without = some(click({ custom_id: "go", component_type: 2 }))
+      assert.isFalse("value" in without)
+      // In a direct the user is on `user`, not `member`.
+      const direct = some({ ...omit(click({ custom_id: "go", component_type: 2 }), "member"), user: { id: tim } })
+      assert.strictEqual(direct.userId, tim)
+      for (const interaction of [withValue, without, direct]) {
+        yield* checkInteraction(interaction, { platform: "discord" })
+      }
+    }))
+
+  it("a string select gives its one value", () => {
+    const changed = some(click({ custom_id: "pick", component_type: 3, values: ["b"] }))
+    assert.deepStrictEqual([changed._tag, changed.id, (changed as ChatInteraction.SelectChanged).value], [
+      "SelectChanged",
+      "pick",
+      "b"
+    ])
+  })
+
+  it.effect("a submit reads each Label's input, leaves an empty one out and splits the metadata", () =>
+    Effect.gen(function*() {
+      const submitted = some(submit("form\u241F{\"v\":1}", [
+        { type: 10 },
+        { type: 18, component: { type: 4, custom_id: "name", value: "Tim" } },
+        { type: 18, component: { type: 4, custom_id: "note", value: "" } },
+        { type: 18, component: { type: 3, custom_id: "size", values: ["l"] } },
+        { type: 18, component: { type: 3, custom_id: "none", values: [] } },
+        // The older shape: an action row around the input.
+        { type: 1, components: [{ type: 4, custom_id: "old", value: "row" }] }
+      ]))
+      assert.strictEqual(submitted._tag, "ModalSubmitted")
+      const { id, metadata, values } = submitted as ChatInteraction.ModalSubmitted
+      assert.deepStrictEqual({ id, metadata, values }, {
+        id: "form",
+        metadata: "{\"v\":1}",
+        values: { name: "Tim", size: "l", old: "row" }
+      })
+      assert.strictEqual(submitted.messageId, message.id)
+      yield* checkInteraction(submitted, { platform: "discord" })
+      assert.isFalse("metadata" in some(submit("form", [])))
+    }))
+
+  it("anything not from an element the adapter built is None", () => {
+    for (
+      const raw of [
+        click({ id: "1", name: "ping", type: 1 }, { type: 2 }),
+        { type: 1, id: "1", token: "t" },
+        click({ custom_id: "users", component_type: 5, values: [tim] }),
+        omit(click({ custom_id: "go", component_type: 2 }), "message"),
+        "not an object"
+      ]
+    ) {
+      assert.isTrue(Option.isNone(DiscordChat.normalizeInteraction(raw)))
+    }
+  })
+})
+
+describe("interaction", () => {
+  const recording = (reply: {
+    readonly click?: ChatInteraction.ClickReply
+    readonly submit?: ChatInteraction.SubmitReply
+    readonly delay?: Duration.Duration
+  }) => {
+    const received: Array = []
+    const refused: Array = []
+    const handler = ChatInteraction.Handler.of({
+      click: (event) =>
+        Effect.as(
+          Effect.andThen(Effect.sleep(reply.delay ?? Duration.zero), Effect.sync(() => received.push(event))),
+          reply.click ?? ChatInteraction.ack
+        ),
+      submit: (event) => Effect.as(Effect.sync(() => received.push(event)), reply.submit ?? ChatInteraction.close),
+      refused: (_, error) => Effect.sync(() => void refused.push(error))
+    })
+    return { received, refused, handler }
+  }
+
+  const deliver = (
+    fake: Fake,
+    raw: unknown,
+    handler: ChatInteraction.Handler["Service"],
+    options?: { readonly deadline?: Duration.Duration }
+  ) =>
+    Effect.gen(function*() {
+      const discord = yield* DiscordChat.DiscordChat
+      yield* discord.interaction(raw, options).pipe(Effect.provideService(ChatInteraction.Handler, handler))
+    }).pipe(Effect.provide(discordLayer(fake)))
+
+  const answering = () => makeFake({ createInteractionResponse: () => Effect.succeed(null) })
+  const payloads = (fake: Fake) => fake.called("createInteractionResponse").map(([, , options]) => options.payload)
+
+  it.effect("acks a click and a close with type 6, to the interaction's id and token", () =>
+    Effect.gen(function*() {
+      const fake = answering()
+      const { handler, received } = recording({})
+      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
+      yield* deliver(fake, submit("form", []), handler)
+      assert.strictEqual(received.length, 2)
+      assert.deepStrictEqual(fake.called("createInteractionResponse").map(([id, token]) => [id, token]), [
+        ["1570700000000000100", "token"],
+        ["1570700000000000100", "token"]
+      ])
+      assert.deepStrictEqual(payloads(fake), [{ type: 6 }, { type: 6 }])
+    }))
+
+  it.effect("opens a modal with type 9: Labels around the inputs and a text display for a text", () =>
+    Effect.gen(function*() {
+      const fake = answering()
+      const modal = ChatInteraction.modal("form", {
+        title: "Release",
+        submitLabel: "Go",
+        fields: {
+          intro: ChatInteraction.text("Pick *one*."),
+          name: ChatInteraction.textInput({ label: "Name", placeholder: "Tim", maxLength: 20 }),
+          note: ChatInteraction.textInput({ label: "Note", multiline: true, optional: true }),
+          size: ChatInteraction.choice({
+            label: "Size",
+            options: [{ label: "S", value: "s" }, { label: "L", value: "l" }]
+          })
+        }
+      })
+      const { handler, refused } = recording({ click: modal.open() })
+      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
+      assert.deepStrictEqual(refused, [])
+      assert.deepStrictEqual(payloads(fake), [{
+        type: 9,
+        data: {
+          custom_id: "form",
+          title: "Release",
+          components: [
+            { type: 10, content: "Pick \\*one\\*\\." },
+            {
+              type: 18,
+              label: "Name",
+              component: { type: 4, custom_id: "name", style: 1, required: true, placeholder: "Tim", max_length: 20 }
+            },
+            { type: 18, label: "Note", component: { type: 4, custom_id: "note", style: 2, required: false } },
+            {
+              type: 18,
+              label: "Size",
+              component: {
+                type: 3,
+                custom_id: "size",
+                required: true,
+                min_values: 1,
+                max_values: 1,
+                options: [{ label: "S", value: "s" }, { label: "L", value: "l" }]
+              }
+            }
+          ]
+        }
+      }])
+    }))
+
+  it.effect("answers errors with a private message listing each one, escaped", () =>
+    Effect.gen(function*() {
+      const fake = answering()
+      const { handler } = recording({ submit: ChatInteraction.errors({ name: "Too short.", size: "Pick " }) })
+      yield* deliver(fake, submit("form", []), handler)
+      assert.deepStrictEqual(payloads(fake), [{
+        type: 4,
+        data: { content: "- Too short\\.\n- Pick \\", allowed_mentions: { parse: [] }, flags: 64 }
+      }])
+    }))
+
+  it.effect("a modal title or label over 45 reaches refused as TooLarge, and the click is still answered", () =>
+    Effect.gen(function*() {
+      for (
+        const modal of [
+          ChatInteraction.modal("form", { title: "t".repeat(46), fields: {} }),
+          ChatInteraction.modal("form", {
+            title: "t",
+            fields: { a: ChatInteraction.textInput({ label: "l".repeat(46) }) }
+          })
+        ]
+      ) {
+        const fake = answering()
+        const { handler, refused } = recording({ click: modal.open() })
+        yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
+        assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag]), [["openModal", "TooLarge"]])
+        assert.deepStrictEqual(payloads(fake), [{ type: 6 }])
+      }
+      // 45 fits.
+      const fake = answering()
+      const { handler, refused } = recording({
+        click: ChatInteraction.modal("form", { title: "t".repeat(45), fields: {} }).open()
+      })
+      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
+      assert.deepStrictEqual(refused, [])
+    }))
+
+  it.effect("a modal callback that comes back Unknown interaction is refused as interaction_expired", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({
+        createInteractionResponse: () =>
+          Effect.fail(errorResponse(404, { code: 10062, message: "Unknown interaction" }))
+      })
+      const { handler, refused } = recording({
+        click: ChatInteraction.modal("form", { title: "t", fields: {} }).open()
+      })
+      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
+      assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag, error.reason.detail]), [
+        ["openModal", "NotFound", "interaction_expired"]
+      ])
+      // A late ack is logged, not refused.
+      const ack = recording({})
+      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), ack.handler)
+      assert.deepStrictEqual(ack.refused, [])
+    }))
+
+  it.effect("sends nothing when the handler misses its deadline, 2 seconds by default", () =>
+    Effect.gen(function*() {
+      const fake = answering()
+      const { handler } = recording({ delay: Duration.seconds(3) })
+      const fiber = yield* Effect.forkChild(deliver(fake, click({ custom_id: "go", component_type: 2 }), handler))
+      yield* TestClock.adjust("2 seconds")
+      yield* Fiber.join(fiber)
+      assert.deepStrictEqual(payloads(fake), [])
+      const longer = yield* Effect.forkChild(
+        deliver(fake, click({ custom_id: "go", component_type: 2 }), handler, { deadline: Duration.seconds(5) })
+      )
+      yield* TestClock.adjust("3 seconds")
+      yield* Fiber.join(longer)
+      assert.deepStrictEqual(payloads(fake), [{ type: 6 }])
+    }))
+
+  it.effect("ignores an interaction it did not build, calling nothing", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({})
+      const { handler, received } = recording({})
+      yield* deliver(fake, click({ id: "1", name: "ping", type: 1 }, { type: 2 }), handler)
+      assert.deepStrictEqual([received.length, fake.calls.length], [0, 0])
+    }))
+})
diff --git a/packages/chat/discord/test/live.test.ts b/packages/chat/discord/test/live.test.ts
index 969104e76f6..747ecf679d8 100644
--- a/packages/chat/discord/test/live.test.ts
+++ b/packages/chat/discord/test/live.test.ts
@@ -9,6 +9,12 @@
  *   rules that need another identity's message. Without it,
  *   `DISCORD_LIVE_WEBHOOK_URL`, a webhook on the channel, stands in. Without
  *   either, those rules fail at `userPosts`.
+ *
+ * The outbound buttons and modals rules run here. Nothing can click a
+ * button through the API, so the rules that need a click take the
+ * `interactions` hook and run only over the stubbed REST in
+ * `conformance.test.ts`. Discord refuses no small file on demand, so
+ * `post/refusedFile` runs there too.
  */
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { describe, it } from "@effect/vitest"

From fd78d0ec3616e512954dc8fb4d5455d3ca037a0e Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 08:28:55 +0000
Subject: [PATCH 30/89] Keep a Discord modal input whose id is __proto__, and
 say what the live suite runs

---
 packages/chat/discord/src/internal/interactions.ts |  8 +++++++-
 packages/chat/discord/test/interactions.test.ts    | 12 ++++++++++++
 packages/chat/discord/test/live.test.ts            | 14 +++++++++-----
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/packages/chat/discord/src/internal/interactions.ts b/packages/chat/discord/src/internal/interactions.ts
index 23da46a9800..451b15b2999 100644
--- a/packages/chat/discord/src/internal/interactions.ts
+++ b/packages/chat/discord/src/internal/interactions.ts
@@ -288,7 +288,13 @@ export const normalize = (raw: unknown): Option.Option {
       assert.isFalse("metadata" in some(submit("form", [])))
     }))
 
+  it.effect("a submit keeps an input whose id is __proto__ as its own field", () =>
+    Effect.gen(function*() {
+      const submitted = some(submit("form", [
+        { type: 18, component: { type: 4, custom_id: "__proto__", value: "answered" } },
+        { type: 18, component: { type: 4, custom_id: "name", value: "Tim" } }
+      ])) as ChatInteraction.ModalSubmitted
+      assert.isTrue(Object.hasOwn(submitted.values, "__proto__"))
+      assert.strictEqual(submitted.values["__proto__"], "answered")
+      assert.deepStrictEqual(Object.keys(submitted.values), ["__proto__", "name"])
+      yield* checkInteraction(submitted, { platform: "discord" })
+    }))
+
   it("anything not from an element the adapter built is None", () => {
     for (
       const raw of [
diff --git a/packages/chat/discord/test/live.test.ts b/packages/chat/discord/test/live.test.ts
index 747ecf679d8..dbf768847d7 100644
--- a/packages/chat/discord/test/live.test.ts
+++ b/packages/chat/discord/test/live.test.ts
@@ -10,11 +10,15 @@
  *   `DISCORD_LIVE_WEBHOOK_URL`, a webhook on the channel, stands in. Without
  *   either, those rules fail at `userPosts`.
  *
- * The outbound buttons and modals rules run here. Nothing can click a
- * button through the API, so the rules that need a click take the
- * `interactions` hook and run only over the stubbed REST in
- * `conformance.test.ts`. Discord refuses no small file on demand, so
- * `post/refusedFile` runs there too.
+ * Of the buttons rules, only the outbound ones run here: `actions/posts`,
+ * `actions/tooMany`, `actions/dataTooLarge`, the two
+ * `descriptor/measure*Actions` rules and the `unsupported/buttons` and
+ * `unsupported/selects` probes. The suite is given no `interactions` hook,
+ * since nothing can click a button through the API, so no rule here clicks,
+ * opens or submits a modal, or calls `DiscordChat.interaction` and its
+ * callbacks. Those rules, and `post/refusedFile`, which needs `refuseFiles`,
+ * run only over the stubbed REST in `conformance.test.ts`. Live evidence
+ * for them needs a person clicking in a test guild.
  */
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { describe, it } from "@effect/vitest"

From e78c86bae845a7eace5dc252f3f254431f6ba5ae Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 08:41:16 +0000
Subject: [PATCH 31/89] Fix Slack text truncation on Bun

---
 packages/chat/slack/src/internal/text.ts | 13 ++++++-------
 packages/chat/slack/test/text.test.ts    |  2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/packages/chat/slack/src/internal/text.ts b/packages/chat/slack/src/internal/text.ts
index 27478d92c41..b423b6a5442 100644
--- a/packages/chat/slack/src/internal/text.ts
+++ b/packages/chat/slack/src/internal/text.ts
@@ -148,14 +148,13 @@ export const build = (markdown: string, notify: Escape.Notify, budget: Budget):
 
   // The last of them on a grapheme cluster boundary.
   segmenter ??= new Intl.Segmenter(undefined, { granularity: "grapheme" })
-  const segments = segmenter.segment(text)
   let best = -1
-  for (let k = candidates.length - 1; k >= 0; k--) {
-    const at = candidates[k]
-    if (at === 0 || segments.containing(at)!.index === at) {
-      best = at
-      break
-    }
+  let candidate = 0
+  // Iterate boundaries: Bun's containing() reports incorrect offsets for astral text.
+  for (const { index } of segmenter.segment(text)) {
+    while (candidate < candidates.length && candidates[candidate] < index) candidate++
+    if (candidate === candidates.length) break
+    if (candidates[candidate] === index) best = index
   }
 
   if (best >= 0) {
diff --git a/packages/chat/slack/test/text.test.ts b/packages/chat/slack/test/text.test.ts
index d686bb660f8..40a8ef5b658 100644
--- a/packages/chat/slack/test/text.test.ts
+++ b/packages/chat/slack/test/text.test.ts
@@ -10,7 +10,7 @@ const bytes = (text: string) => new TextEncoder().encode(text).length
 const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
 const graphemes = (text: string) => [...segmenter.segment(text)]
 const isBoundary = (text: string, index: number) =>
-  index === text.length || segmenter.segment(text).containing(index)!.index === index
+  index === text.length || graphemes(text).some((segment) => segment.index === index)
 
 describe("build", () => {
   it("writes every <, > and & as an entity, in code too, and keeps allowed tokens", () => {

From 89487881649c838cd520059168ccd03a6ad0091d Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 08:45:56 +0000
Subject: [PATCH 32/89] Record Discord's answers to action rows, custom_id
 lengths, unknown interactions and oversize uploads

---
 .../chat/discord/test/DiscordChat.test.ts     |  106 +-
 packages/chat/discord/test/discord.ts         |    5 +-
 .../test/fixtures/recorded/components.json    | 2345 +++++++++++++++++
 .../test/fixtures/recorded/uploads.json       |  218 ++
 .../chat/discord/test/interactions.test.ts    |    5 +-
 5 files changed, 2672 insertions(+), 7 deletions(-)
 create mode 100644 packages/chat/discord/test/fixtures/recorded/components.json
 create mode 100644 packages/chat/discord/test/fixtures/recorded/uploads.json

diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index 5a05455c8c5..137d204ae76 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -322,9 +322,103 @@ describe("buttons and selects", () => {
   })
 })
 
+describe("recorded components", () => {
+  // fixtures/recorded/components.json: what Discord accepted and refused in #test.
+  const call = (name: string) => step("components", name)
+  const styles = ["default", "primary", "danger"] as const
+  const sentRows = (actions: ReadonlyArray) => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.post(channel, { markdown: "x", actions })
+        return fake.called("createMessage")[0][1].components
+      })
+    )
+  }
+  const buttons = (from: number, to: number): Array =>
+    Array.from(
+      { length: to - from },
+      (_, i) => ({ _tag: "Button", id: "b" + (from + i), label: "b" + (from + i), value: "v" + (from + i) })
+    )
+  const options = (n: number) => Array.from({ length: n }, (_, i) => ({ label: "o" + i, value: "o" + i }))
+
+  it.effect("the rows the adapter builds are the rows Discord accepted", () =>
+    Effect.gen(function*() {
+      const cases: ReadonlyArray]> = [
+        ["rows-25-buttons", [
+          ...Array.from({ length: 24 }, (_, i): ChatUi.Action => ({
+            _tag: "Button",
+            id: "b" + i,
+            label: "b" + i,
+            value: "v" + i,
+            style: styles[i % 3]
+          })),
+          { _tag: "LinkButton", label: "link", url: "https://effect.website" }
+        ]],
+        ["rows-selects-and-buttons", [
+          ...buttons(0, 5),
+          { _tag: "Select", id: "s1", options: options(25), selected: "o3" },
+          ...buttons(5, 10),
+          { _tag: "Select", id: "s2", options: options(2) },
+          ...buttons(10, 15)
+        ]],
+        ["custom-id-100-ascii-with-join", [{ _tag: "Button", id: "a".repeat(98), label: "x", value: "b" }]],
+        // 100 code points but 150 UTF-16 units: Discord counts code points.
+        ["custom-id-100-code-points-astral", [{
+          _tag: "Button",
+          id: "a".repeat(49),
+          label: "x",
+          value: "\u{1F600}".repeat(50)
+        }]]
+      ]
+      for (const [name, actions] of cases) {
+        assert.strictEqual(call(name).status, 200)
+        assert.deepStrictEqual(yield* sentRows(actions), call(name).request.components, name)
+      }
+    }))
+
+  it.effect("what Discord refused, the adapter refuses before a call", () => {
+    const fake = makeFake({})
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        const post = (actions: ReadonlyArray) =>
+          reason(discord.post(channel, { markdown: "x", actions }))
+        const cases: ReadonlyArray, string]> = [
+          ["twenty-six-buttons", buttons(0, 26), "too_many_actions"],
+          [
+            "six-rows",
+            Array.from({ length: 6 }, (_, i) => ({ _tag: "Select", id: "s" + i, options: options(2) })),
+            "too_many_actions"
+          ],
+          [
+            "custom-id-101-ascii",
+            [{ _tag: "Button", id: "a".repeat(100), label: "x", value: "b" }],
+            "action_data_too_long"
+          ],
+          ["custom-id-101-code-points-astral", [{
+            _tag: "Button",
+            id: "a".repeat(50),
+            label: "x",
+            value: "\u{1F600}".repeat(50)
+          }], "action_data_too_long"]
+        ]
+        for (const [name, actions, detail] of cases) {
+          assert.deepStrictEqual([call(name).status, call(name).response.code], [400, 50035], name)
+          assert.deepStrictEqual(yield* post(actions), { op: "post", tag: "TooLarge", detail, retry: "denied" }, name)
+        }
+        assert.strictEqual(fake.calls.length, 0)
+      })
+    )
+  })
+})
+
 describe("files", () => {
   const file = { name: "fixture.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }
-  const refused = (fail: () => Effect.Effect) => {
+  const refused = (fail: () => Effect.Effect) => {
     const fake = makeFake({ createMessage: fail })
     return run(
       fake,
@@ -344,7 +438,11 @@ describe("files", () => {
         assert.strictEqual(result.retry, "denied")
         assert.strictEqual((result.cause as any).detail, String(code))
       }
-      // A 413 from Discord's edge has no JSON body.
+      // Discord's own 413, as recorded in fixtures/recorded/uploads.json.
+      const oversize = yield* refused(() => answer(step("uploads", "upload-20MiB-plus-1")))
+      assert.deepStrictEqual([oversize.tag, oversize.detail, oversize.retry], ["TooLarge", "file_refused", "denied"])
+      assert.strictEqual((oversize.cause as any).detail, "40005")
+      // A 413 with no JSON body, as a proxy in between might send.
       const edge = yield* refused(() =>
         Effect.fail({ _tag: "HttpClientError", reason: { _tag: "DecodeError", response: { status: 413 } } })
       )
@@ -371,6 +469,10 @@ describe("files", () => {
           assert.deepStrictEqual(result, { op: "post", tag: "TooLarge", detail: "file_refused", retry: "denied" })
         }
         assert.strictEqual(fake.calls.length, 0)
+        // The check refuses nothing Discord would take: it accepted 20 MiB in a guild with no boosts.
+        const accepted = step("uploads", "upload-20MiB")
+        assert.strictEqual(accepted.status, 200)
+        assert.isAtMost(discord.descriptor.limits.uploadBytes, accepted.request["files[0]"].bytes)
       })
     )
   })
diff --git a/packages/chat/discord/test/discord.ts b/packages/chat/discord/test/discord.ts
index 6a5b2afa371..099cdc20fa7 100644
--- a/packages/chat/discord/test/discord.ts
+++ b/packages/chat/discord/test/discord.ts
@@ -1,7 +1,7 @@
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { type Interactions, NoSuchElement } from "effect/chat/ChatTest"
 import * as Effect from "effect/Effect"
-import { botUserId, errorResponse, type Fake, guild, makeFake, tim } from "./utils.ts"
+import { answer, botUserId, errorResponse, type Fake, guild, makeFake, step, tim } from "./utils.ts"
 
 /** The join between an id and its value in a `custom_id`, as the adapter writes it. */
 const join = "\u241F"
@@ -29,7 +29,8 @@ export const makeDiscord = (channelType = 0) => {
     createMessage: (channelId: string, body: any) => {
       if ((body.attachments ?? []).length > 0 && refuse > 0) {
         refuse--
-        return Effect.fail(errorResponse(400, { code: 40005, message: "Request entity too large" }))
+        // Discord's answer to an oversize upload, from fixtures/recorded/uploads.json.
+        return answer(step("uploads", "upload-20MiB-plus-1"))
       }
       const id = nextId()
       const message = {
diff --git a/packages/chat/discord/test/fixtures/recorded/components.json b/packages/chat/discord/test/fixtures/recorded/components.json
new file mode 100644
index 00000000000..69afccf840e
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/components.json
@@ -0,0 +1,2345 @@
+{
+  "case": "Action rows as the adapter's rows() builds them and as Discord refuses them, an edit that clears them, custom_id length in code points, and callbacks for an interaction Discord doesn't know",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script",
+    "where": "guild 840178841540362250 (Tim's test guild); #test 1570605581192929301. The callbacks name no guild: their interaction id and token are made up, and Discord answers 10062 before it reads the body",
+    "recordedAt": "2026-11-13T08:40Z, during EFF-3755",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed. Every posted message was deleted after it was read"
+  },
+  "calls": [
+    {
+      "step": "rows-25-buttons",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: rows-25-buttons",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b0",
+                "custom_id": "b0␟v0"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b1",
+                "custom_id": "b1␟v1"
+              },
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b2",
+                "custom_id": "b2␟v2"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b3",
+                "custom_id": "b3␟v3"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b4",
+                "custom_id": "b4␟v4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b5",
+                "custom_id": "b5␟v5"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b6",
+                "custom_id": "b6␟v6"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b7",
+                "custom_id": "b7␟v7"
+              },
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b8",
+                "custom_id": "b8␟v8"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b9",
+                "custom_id": "b9␟v9"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b10",
+                "custom_id": "b10␟v10"
+              },
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b11",
+                "custom_id": "b11␟v11"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b12",
+                "custom_id": "b12␟v12"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b13",
+                "custom_id": "b13␟v13"
+              },
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b14",
+                "custom_id": "b14␟v14"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b15",
+                "custom_id": "b15␟v15"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b16",
+                "custom_id": "b16␟v16"
+              },
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b17",
+                "custom_id": "b17␟v17"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b18",
+                "custom_id": "b18␟v18"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b19",
+                "custom_id": "b19␟v19"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b20",
+                "custom_id": "b20␟v20"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b21",
+                "custom_id": "b21␟v21"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "b22",
+                "custom_id": "b22␟v22"
+              },
+              {
+                "type": 2,
+                "style": 4,
+                "label": "b23",
+                "custom_id": "b23␟v23"
+              },
+              {
+                "type": 2,
+                "style": 5,
+                "label": "link",
+                "url": "https://effect.website"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: rows-25-buttons",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:40:57.239000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "b0␟v0",
+                "style": 2,
+                "label": "b0"
+              },
+              {
+                "type": 2,
+                "id": 3,
+                "custom_id": "b1␟v1",
+                "style": 1,
+                "label": "b1"
+              },
+              {
+                "type": 2,
+                "id": 4,
+                "custom_id": "b2␟v2",
+                "style": 4,
+                "label": "b2"
+              },
+              {
+                "type": 2,
+                "id": 5,
+                "custom_id": "b3␟v3",
+                "style": 2,
+                "label": "b3"
+              },
+              {
+                "type": 2,
+                "id": 6,
+                "custom_id": "b4␟v4",
+                "style": 1,
+                "label": "b4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 7,
+            "components": [
+              {
+                "type": 2,
+                "id": 8,
+                "custom_id": "b5␟v5",
+                "style": 4,
+                "label": "b5"
+              },
+              {
+                "type": 2,
+                "id": 9,
+                "custom_id": "b6␟v6",
+                "style": 2,
+                "label": "b6"
+              },
+              {
+                "type": 2,
+                "id": 10,
+                "custom_id": "b7␟v7",
+                "style": 1,
+                "label": "b7"
+              },
+              {
+                "type": 2,
+                "id": 11,
+                "custom_id": "b8␟v8",
+                "style": 4,
+                "label": "b8"
+              },
+              {
+                "type": 2,
+                "id": 12,
+                "custom_id": "b9␟v9",
+                "style": 2,
+                "label": "b9"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 13,
+            "components": [
+              {
+                "type": 2,
+                "id": 14,
+                "custom_id": "b10␟v10",
+                "style": 1,
+                "label": "b10"
+              },
+              {
+                "type": 2,
+                "id": 15,
+                "custom_id": "b11␟v11",
+                "style": 4,
+                "label": "b11"
+              },
+              {
+                "type": 2,
+                "id": 16,
+                "custom_id": "b12␟v12",
+                "style": 2,
+                "label": "b12"
+              },
+              {
+                "type": 2,
+                "id": 17,
+                "custom_id": "b13␟v13",
+                "style": 1,
+                "label": "b13"
+              },
+              {
+                "type": 2,
+                "id": 18,
+                "custom_id": "b14␟v14",
+                "style": 4,
+                "label": "b14"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 19,
+            "components": [
+              {
+                "type": 2,
+                "id": 20,
+                "custom_id": "b15␟v15",
+                "style": 2,
+                "label": "b15"
+              },
+              {
+                "type": 2,
+                "id": 21,
+                "custom_id": "b16␟v16",
+                "style": 1,
+                "label": "b16"
+              },
+              {
+                "type": 2,
+                "id": 22,
+                "custom_id": "b17␟v17",
+                "style": 4,
+                "label": "b17"
+              },
+              {
+                "type": 2,
+                "id": 23,
+                "custom_id": "b18␟v18",
+                "style": 2,
+                "label": "b18"
+              },
+              {
+                "type": 2,
+                "id": 24,
+                "custom_id": "b19␟v19",
+                "style": 1,
+                "label": "b19"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 25,
+            "components": [
+              {
+                "type": 2,
+                "id": 26,
+                "custom_id": "b20␟v20",
+                "style": 4,
+                "label": "b20"
+              },
+              {
+                "type": 2,
+                "id": 27,
+                "custom_id": "b21␟v21",
+                "style": 2,
+                "label": "b21"
+              },
+              {
+                "type": 2,
+                "id": 28,
+                "custom_id": "b22␟v22",
+                "style": 1,
+                "label": "b22"
+              },
+              {
+                "type": 2,
+                "id": 29,
+                "custom_id": "b23␟v23",
+                "style": 4,
+                "label": "b23"
+              },
+              {
+                "type": 2,
+                "id": 30,
+                "style": 5,
+                "label": "link",
+                "url": "https://effect.website"
+              }
+            ]
+          }
+        ],
+        "id": "1570720111872975040",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "rows-25-buttons/read",
+      "method": "GET",
+      "path": "/channels/1570605581192929301/messages/1570720111872975040",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: rows-25-buttons",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:40:57.239000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "b0␟v0",
+                "style": 2,
+                "label": "b0"
+              },
+              {
+                "type": 2,
+                "id": 3,
+                "custom_id": "b1␟v1",
+                "style": 1,
+                "label": "b1"
+              },
+              {
+                "type": 2,
+                "id": 4,
+                "custom_id": "b2␟v2",
+                "style": 4,
+                "label": "b2"
+              },
+              {
+                "type": 2,
+                "id": 5,
+                "custom_id": "b3␟v3",
+                "style": 2,
+                "label": "b3"
+              },
+              {
+                "type": 2,
+                "id": 6,
+                "custom_id": "b4␟v4",
+                "style": 1,
+                "label": "b4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 7,
+            "components": [
+              {
+                "type": 2,
+                "id": 8,
+                "custom_id": "b5␟v5",
+                "style": 4,
+                "label": "b5"
+              },
+              {
+                "type": 2,
+                "id": 9,
+                "custom_id": "b6␟v6",
+                "style": 2,
+                "label": "b6"
+              },
+              {
+                "type": 2,
+                "id": 10,
+                "custom_id": "b7␟v7",
+                "style": 1,
+                "label": "b7"
+              },
+              {
+                "type": 2,
+                "id": 11,
+                "custom_id": "b8␟v8",
+                "style": 4,
+                "label": "b8"
+              },
+              {
+                "type": 2,
+                "id": 12,
+                "custom_id": "b9␟v9",
+                "style": 2,
+                "label": "b9"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 13,
+            "components": [
+              {
+                "type": 2,
+                "id": 14,
+                "custom_id": "b10␟v10",
+                "style": 1,
+                "label": "b10"
+              },
+              {
+                "type": 2,
+                "id": 15,
+                "custom_id": "b11␟v11",
+                "style": 4,
+                "label": "b11"
+              },
+              {
+                "type": 2,
+                "id": 16,
+                "custom_id": "b12␟v12",
+                "style": 2,
+                "label": "b12"
+              },
+              {
+                "type": 2,
+                "id": 17,
+                "custom_id": "b13␟v13",
+                "style": 1,
+                "label": "b13"
+              },
+              {
+                "type": 2,
+                "id": 18,
+                "custom_id": "b14␟v14",
+                "style": 4,
+                "label": "b14"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 19,
+            "components": [
+              {
+                "type": 2,
+                "id": 20,
+                "custom_id": "b15␟v15",
+                "style": 2,
+                "label": "b15"
+              },
+              {
+                "type": 2,
+                "id": 21,
+                "custom_id": "b16␟v16",
+                "style": 1,
+                "label": "b16"
+              },
+              {
+                "type": 2,
+                "id": 22,
+                "custom_id": "b17␟v17",
+                "style": 4,
+                "label": "b17"
+              },
+              {
+                "type": 2,
+                "id": 23,
+                "custom_id": "b18␟v18",
+                "style": 2,
+                "label": "b18"
+              },
+              {
+                "type": 2,
+                "id": 24,
+                "custom_id": "b19␟v19",
+                "style": 1,
+                "label": "b19"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 25,
+            "components": [
+              {
+                "type": 2,
+                "id": 26,
+                "custom_id": "b20␟v20",
+                "style": 4,
+                "label": "b20"
+              },
+              {
+                "type": 2,
+                "id": 27,
+                "custom_id": "b21␟v21",
+                "style": 2,
+                "label": "b21"
+              },
+              {
+                "type": 2,
+                "id": 28,
+                "custom_id": "b22␟v22",
+                "style": 1,
+                "label": "b22"
+              },
+              {
+                "type": 2,
+                "id": 29,
+                "custom_id": "b23␟v23",
+                "style": 4,
+                "label": "b23"
+              },
+              {
+                "type": 2,
+                "id": 30,
+                "style": 5,
+                "label": "link",
+                "url": "https://effect.website"
+              }
+            ]
+          }
+        ],
+        "id": "1570720111872975040",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "rows-25-buttons/edit-clears",
+      "method": "PATCH",
+      "path": "/channels/1570605581192929301/messages/1570720111872975040",
+      "request": {
+        "content": "effect-chat probe: edited",
+        "components": []
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: edited",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:40:57.239000+00:00",
+        "edited_timestamp": "2026-11-13T08:40:57.601507+00:00",
+        "flags": 0,
+        "components": [],
+        "id": "1570720111872975040",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "rows-selects-and-buttons",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: rows-selects-and-buttons",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b0",
+                "custom_id": "b0␟v0"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b1",
+                "custom_id": "b1␟v1"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b2",
+                "custom_id": "b2␟v2"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b3",
+                "custom_id": "b3␟v3"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b4",
+                "custom_id": "b4␟v4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 3,
+                "custom_id": "s1",
+                "options": [
+                  {
+                    "label": "o0",
+                    "value": "o0"
+                  },
+                  {
+                    "label": "o1",
+                    "value": "o1"
+                  },
+                  {
+                    "label": "o2",
+                    "value": "o2"
+                  },
+                  {
+                    "label": "o3",
+                    "value": "o3",
+                    "default": true
+                  },
+                  {
+                    "label": "o4",
+                    "value": "o4"
+                  },
+                  {
+                    "label": "o5",
+                    "value": "o5"
+                  },
+                  {
+                    "label": "o6",
+                    "value": "o6"
+                  },
+                  {
+                    "label": "o7",
+                    "value": "o7"
+                  },
+                  {
+                    "label": "o8",
+                    "value": "o8"
+                  },
+                  {
+                    "label": "o9",
+                    "value": "o9"
+                  },
+                  {
+                    "label": "o10",
+                    "value": "o10"
+                  },
+                  {
+                    "label": "o11",
+                    "value": "o11"
+                  },
+                  {
+                    "label": "o12",
+                    "value": "o12"
+                  },
+                  {
+                    "label": "o13",
+                    "value": "o13"
+                  },
+                  {
+                    "label": "o14",
+                    "value": "o14"
+                  },
+                  {
+                    "label": "o15",
+                    "value": "o15"
+                  },
+                  {
+                    "label": "o16",
+                    "value": "o16"
+                  },
+                  {
+                    "label": "o17",
+                    "value": "o17"
+                  },
+                  {
+                    "label": "o18",
+                    "value": "o18"
+                  },
+                  {
+                    "label": "o19",
+                    "value": "o19"
+                  },
+                  {
+                    "label": "o20",
+                    "value": "o20"
+                  },
+                  {
+                    "label": "o21",
+                    "value": "o21"
+                  },
+                  {
+                    "label": "o22",
+                    "value": "o22"
+                  },
+                  {
+                    "label": "o23",
+                    "value": "o23"
+                  },
+                  {
+                    "label": "o24",
+                    "value": "o24"
+                  }
+                ],
+                "min_values": 1,
+                "max_values": 1
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b5",
+                "custom_id": "b5␟v5"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b6",
+                "custom_id": "b6␟v6"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b7",
+                "custom_id": "b7␟v7"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b8",
+                "custom_id": "b8␟v8"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b9",
+                "custom_id": "b9␟v9"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 3,
+                "custom_id": "s2",
+                "options": [
+                  {
+                    "label": "o0",
+                    "value": "o0"
+                  },
+                  {
+                    "label": "o1",
+                    "value": "o1"
+                  }
+                ],
+                "min_values": 1,
+                "max_values": 1
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b10",
+                "custom_id": "b10␟v10"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b11",
+                "custom_id": "b11␟v11"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b12",
+                "custom_id": "b12␟v12"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b13",
+                "custom_id": "b13␟v13"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b14",
+                "custom_id": "b14␟v14"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: rows-selects-and-buttons",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:40:57.926000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "b0␟v0",
+                "style": 2,
+                "label": "b0"
+              },
+              {
+                "type": 2,
+                "id": 3,
+                "custom_id": "b1␟v1",
+                "style": 2,
+                "label": "b1"
+              },
+              {
+                "type": 2,
+                "id": 4,
+                "custom_id": "b2␟v2",
+                "style": 2,
+                "label": "b2"
+              },
+              {
+                "type": 2,
+                "id": 5,
+                "custom_id": "b3␟v3",
+                "style": 2,
+                "label": "b3"
+              },
+              {
+                "type": 2,
+                "id": 6,
+                "custom_id": "b4␟v4",
+                "style": 2,
+                "label": "b4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 7,
+            "components": [
+              {
+                "type": 3,
+                "id": 8,
+                "custom_id": "s1",
+                "min_values": 1,
+                "max_values": 1,
+                "options": [
+                  {
+                    "label": "o0",
+                    "value": "o0"
+                  },
+                  {
+                    "label": "o1",
+                    "value": "o1"
+                  },
+                  {
+                    "label": "o2",
+                    "value": "o2"
+                  },
+                  {
+                    "label": "o3",
+                    "value": "o3",
+                    "default": true
+                  },
+                  {
+                    "label": "o4",
+                    "value": "o4"
+                  },
+                  {
+                    "label": "o5",
+                    "value": "o5"
+                  },
+                  {
+                    "label": "o6",
+                    "value": "o6"
+                  },
+                  {
+                    "label": "o7",
+                    "value": "o7"
+                  },
+                  {
+                    "label": "o8",
+                    "value": "o8"
+                  },
+                  {
+                    "label": "o9",
+                    "value": "o9"
+                  },
+                  {
+                    "label": "o10",
+                    "value": "o10"
+                  },
+                  {
+                    "label": "o11",
+                    "value": "o11"
+                  },
+                  {
+                    "label": "o12",
+                    "value": "o12"
+                  },
+                  {
+                    "label": "o13",
+                    "value": "o13"
+                  },
+                  {
+                    "label": "o14",
+                    "value": "o14"
+                  },
+                  {
+                    "label": "o15",
+                    "value": "o15"
+                  },
+                  {
+                    "label": "o16",
+                    "value": "o16"
+                  },
+                  {
+                    "label": "o17",
+                    "value": "o17"
+                  },
+                  {
+                    "label": "o18",
+                    "value": "o18"
+                  },
+                  {
+                    "label": "o19",
+                    "value": "o19"
+                  },
+                  {
+                    "label": "o20",
+                    "value": "o20"
+                  },
+                  {
+                    "label": "o21",
+                    "value": "o21"
+                  },
+                  {
+                    "label": "o22",
+                    "value": "o22"
+                  },
+                  {
+                    "label": "o23",
+                    "value": "o23"
+                  },
+                  {
+                    "label": "o24",
+                    "value": "o24"
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 9,
+            "components": [
+              {
+                "type": 2,
+                "id": 10,
+                "custom_id": "b5␟v5",
+                "style": 2,
+                "label": "b5"
+              },
+              {
+                "type": 2,
+                "id": 11,
+                "custom_id": "b6␟v6",
+                "style": 2,
+                "label": "b6"
+              },
+              {
+                "type": 2,
+                "id": 12,
+                "custom_id": "b7␟v7",
+                "style": 2,
+                "label": "b7"
+              },
+              {
+                "type": 2,
+                "id": 13,
+                "custom_id": "b8␟v8",
+                "style": 2,
+                "label": "b8"
+              },
+              {
+                "type": 2,
+                "id": 14,
+                "custom_id": "b9␟v9",
+                "style": 2,
+                "label": "b9"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 15,
+            "components": [
+              {
+                "type": 3,
+                "id": 16,
+                "custom_id": "s2",
+                "min_values": 1,
+                "max_values": 1,
+                "options": [
+                  {
+                    "label": "o0",
+                    "value": "o0"
+                  },
+                  {
+                    "label": "o1",
+                    "value": "o1"
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 17,
+            "components": [
+              {
+                "type": 2,
+                "id": 18,
+                "custom_id": "b10␟v10",
+                "style": 2,
+                "label": "b10"
+              },
+              {
+                "type": 2,
+                "id": 19,
+                "custom_id": "b11␟v11",
+                "style": 2,
+                "label": "b11"
+              },
+              {
+                "type": 2,
+                "id": 20,
+                "custom_id": "b12␟v12",
+                "style": 2,
+                "label": "b12"
+              },
+              {
+                "type": 2,
+                "id": 21,
+                "custom_id": "b13␟v13",
+                "style": 2,
+                "label": "b13"
+              },
+              {
+                "type": 2,
+                "id": 22,
+                "custom_id": "b14␟v14",
+                "style": 2,
+                "label": "b14"
+              }
+            ]
+          }
+        ],
+        "id": "1570720114754723871",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "rows-selects-and-buttons/read",
+      "method": "GET",
+      "path": "/channels/1570605581192929301/messages/1570720114754723871",
+      "request": null,
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: rows-selects-and-buttons",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:40:57.926000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "b0␟v0",
+                "style": 2,
+                "label": "b0"
+              },
+              {
+                "type": 2,
+                "id": 3,
+                "custom_id": "b1␟v1",
+                "style": 2,
+                "label": "b1"
+              },
+              {
+                "type": 2,
+                "id": 4,
+                "custom_id": "b2␟v2",
+                "style": 2,
+                "label": "b2"
+              },
+              {
+                "type": 2,
+                "id": 5,
+                "custom_id": "b3␟v3",
+                "style": 2,
+                "label": "b3"
+              },
+              {
+                "type": 2,
+                "id": 6,
+                "custom_id": "b4␟v4",
+                "style": 2,
+                "label": "b4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 7,
+            "components": [
+              {
+                "type": 3,
+                "id": 8,
+                "custom_id": "s1",
+                "min_values": 1,
+                "max_values": 1,
+                "options": [
+                  {
+                    "label": "o0",
+                    "value": "o0"
+                  },
+                  {
+                    "label": "o1",
+                    "value": "o1"
+                  },
+                  {
+                    "label": "o2",
+                    "value": "o2"
+                  },
+                  {
+                    "label": "o3",
+                    "value": "o3",
+                    "default": true
+                  },
+                  {
+                    "label": "o4",
+                    "value": "o4"
+                  },
+                  {
+                    "label": "o5",
+                    "value": "o5"
+                  },
+                  {
+                    "label": "o6",
+                    "value": "o6"
+                  },
+                  {
+                    "label": "o7",
+                    "value": "o7"
+                  },
+                  {
+                    "label": "o8",
+                    "value": "o8"
+                  },
+                  {
+                    "label": "o9",
+                    "value": "o9"
+                  },
+                  {
+                    "label": "o10",
+                    "value": "o10"
+                  },
+                  {
+                    "label": "o11",
+                    "value": "o11"
+                  },
+                  {
+                    "label": "o12",
+                    "value": "o12"
+                  },
+                  {
+                    "label": "o13",
+                    "value": "o13"
+                  },
+                  {
+                    "label": "o14",
+                    "value": "o14"
+                  },
+                  {
+                    "label": "o15",
+                    "value": "o15"
+                  },
+                  {
+                    "label": "o16",
+                    "value": "o16"
+                  },
+                  {
+                    "label": "o17",
+                    "value": "o17"
+                  },
+                  {
+                    "label": "o18",
+                    "value": "o18"
+                  },
+                  {
+                    "label": "o19",
+                    "value": "o19"
+                  },
+                  {
+                    "label": "o20",
+                    "value": "o20"
+                  },
+                  {
+                    "label": "o21",
+                    "value": "o21"
+                  },
+                  {
+                    "label": "o22",
+                    "value": "o22"
+                  },
+                  {
+                    "label": "o23",
+                    "value": "o23"
+                  },
+                  {
+                    "label": "o24",
+                    "value": "o24"
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 9,
+            "components": [
+              {
+                "type": 2,
+                "id": 10,
+                "custom_id": "b5␟v5",
+                "style": 2,
+                "label": "b5"
+              },
+              {
+                "type": 2,
+                "id": 11,
+                "custom_id": "b6␟v6",
+                "style": 2,
+                "label": "b6"
+              },
+              {
+                "type": 2,
+                "id": 12,
+                "custom_id": "b7␟v7",
+                "style": 2,
+                "label": "b7"
+              },
+              {
+                "type": 2,
+                "id": 13,
+                "custom_id": "b8␟v8",
+                "style": 2,
+                "label": "b8"
+              },
+              {
+                "type": 2,
+                "id": 14,
+                "custom_id": "b9␟v9",
+                "style": 2,
+                "label": "b9"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 15,
+            "components": [
+              {
+                "type": 3,
+                "id": 16,
+                "custom_id": "s2",
+                "min_values": 1,
+                "max_values": 1,
+                "options": [
+                  {
+                    "label": "o0",
+                    "value": "o0"
+                  },
+                  {
+                    "label": "o1",
+                    "value": "o1"
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "id": 17,
+            "components": [
+              {
+                "type": 2,
+                "id": 18,
+                "custom_id": "b10␟v10",
+                "style": 2,
+                "label": "b10"
+              },
+              {
+                "type": 2,
+                "id": 19,
+                "custom_id": "b11␟v11",
+                "style": 2,
+                "label": "b11"
+              },
+              {
+                "type": 2,
+                "id": 20,
+                "custom_id": "b12␟v12",
+                "style": 2,
+                "label": "b12"
+              },
+              {
+                "type": 2,
+                "id": 21,
+                "custom_id": "b13␟v13",
+                "style": 2,
+                "label": "b13"
+              },
+              {
+                "type": 2,
+                "id": 22,
+                "custom_id": "b14␟v14",
+                "style": 2,
+                "label": "b14"
+              }
+            ]
+          }
+        ],
+        "id": "1570720114754723871",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "custom-id-100-ascii-with-join",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: custom-id-100-ascii-with-join",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "x",
+                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟b"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: custom-id-100-ascii-with-join",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:40:58.462000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟b",
+                "style": 2,
+                "label": "x"
+              }
+            ]
+          }
+        ],
+        "id": "1570720117002862676",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "custom-id-100-code-points-astral",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: custom-id-100-code-points-astral",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "x",
+                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: custom-id-100-code-points-astral",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:40:59.804000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
+                "style": 2,
+                "label": "x"
+              }
+            ]
+          }
+        ],
+        "id": "1570720122631356538",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      }
+    },
+    {
+      "step": "six-rows",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: six-rows",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b0",
+                "custom_id": "b0␟v0"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b1",
+                "custom_id": "b1␟v1"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b2",
+                "custom_id": "b2␟v2"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b3",
+                "custom_id": "b3␟v3"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b4",
+                "custom_id": "b4␟v4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b5",
+                "custom_id": "b5␟v5"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "components": {
+            "_errors": [
+              {
+                "code": "BASE_TYPE_MAX_LENGTH",
+                "message": "Must be 5 or fewer in length."
+              }
+            ]
+          }
+        }
+      }
+    },
+    {
+      "step": "six-buttons-in-a-row",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: six-buttons-in-a-row",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b0",
+                "custom_id": "b0␟v0"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b1",
+                "custom_id": "b1␟v1"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b2",
+                "custom_id": "b2␟v2"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b3",
+                "custom_id": "b3␟v3"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b4",
+                "custom_id": "b4␟v4"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b5",
+                "custom_id": "b5␟v5"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "components": {
+            "0": {
+              "components": {
+                "_errors": [
+                  {
+                    "code": "BASE_TYPE_BAD_LENGTH",
+                    "message": "Must be between 1 and 5 in length."
+                  }
+                ]
+              }
+            }
+          }
+        }
+      }
+    },
+    {
+      "step": "select-and-button-in-a-row",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: select-and-button-in-a-row",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 3,
+                "custom_id": "s",
+                "options": [
+                  {
+                    "label": "o0",
+                    "value": "o0"
+                  },
+                  {
+                    "label": "o1",
+                    "value": "o1"
+                  }
+                ],
+                "min_values": 1,
+                "max_values": 1
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b0",
+                "custom_id": "b0␟v0"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "components": {
+            "0": {
+              "components": {
+                "1": {
+                  "_errors": [
+                    {
+                      "code": "COMPONENT_LAYOUT_WIDTH_EXCEEDED",
+                      "message": "The specified component exceeds the maximum width"
+                    }
+                  ]
+                }
+              }
+            }
+          }
+        }
+      }
+    },
+    {
+      "step": "custom-id-101-ascii",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: custom-id-101-ascii",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "x",
+                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "components": {
+            "0": {
+              "components": {
+                "0": {
+                  "custom_id": {
+                    "_errors": [
+                      {
+                        "code": "BASE_TYPE_BAD_LENGTH",
+                        "message": "Must be between 1 and 100 in length."
+                      }
+                    ]
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    },
+    {
+      "step": "custom-id-101-code-points-astral",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: custom-id-101-code-points-astral",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "x",
+                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "components": {
+            "0": {
+              "components": {
+                "0": {
+                  "custom_id": {
+                    "_errors": [
+                      {
+                        "code": "BASE_TYPE_BAD_LENGTH",
+                        "message": "Must be between 1 and 100 in length."
+                      }
+                    ]
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    },
+    {
+      "step": "twenty-six-buttons",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "content": "effect-chat probe: twenty-six-buttons",
+        "allowed_mentions": {
+          "parse": []
+        },
+        "components": [
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b0",
+                "custom_id": "b0␟v0"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b1",
+                "custom_id": "b1␟v1"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b2",
+                "custom_id": "b2␟v2"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b3",
+                "custom_id": "b3␟v3"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b4",
+                "custom_id": "b4␟v4"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b5",
+                "custom_id": "b5␟v5"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b6",
+                "custom_id": "b6␟v6"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b7",
+                "custom_id": "b7␟v7"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b8",
+                "custom_id": "b8␟v8"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b9",
+                "custom_id": "b9␟v9"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b10",
+                "custom_id": "b10␟v10"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b11",
+                "custom_id": "b11␟v11"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b12",
+                "custom_id": "b12␟v12"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b13",
+                "custom_id": "b13␟v13"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b14",
+                "custom_id": "b14␟v14"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b15",
+                "custom_id": "b15␟v15"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b16",
+                "custom_id": "b16␟v16"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b17",
+                "custom_id": "b17␟v17"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b18",
+                "custom_id": "b18␟v18"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b19",
+                "custom_id": "b19␟v19"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b20",
+                "custom_id": "b20␟v20"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b21",
+                "custom_id": "b21␟v21"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b22",
+                "custom_id": "b22␟v22"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b23",
+                "custom_id": "b23␟v23"
+              },
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b24",
+                "custom_id": "b24␟v24"
+              }
+            ]
+          },
+          {
+            "type": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "b25",
+                "custom_id": "b25␟v25"
+              }
+            ]
+          }
+        ]
+      },
+      "status": 400,
+      "response": {
+        "message": "Invalid Form Body",
+        "code": 50035,
+        "errors": {
+          "components": {
+            "_errors": [
+              {
+                "code": "BASE_TYPE_MAX_LENGTH",
+                "message": "Must be 5 or fewer in length."
+              }
+            ]
+          }
+        }
+      }
+    },
+    {
+      "step": "callback-unknown-interaction-modal-45",
+      "method": "POST",
+      "path": "/interactions/1570720847549693952/invalid-token/callback",
+      "request": {
+        "type": 9,
+        "data": {
+          "custom_id": "m",
+          "title": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+          "components": [
+            {
+              "type": 18,
+              "label": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
+              "component": {
+                "type": 4,
+                "custom_id": "a",
+                "style": 1
+              }
+            }
+          ]
+        }
+      },
+      "status": 404,
+      "response": {
+        "message": "Unknown interaction",
+        "code": 10062
+      }
+    },
+    {
+      "step": "callback-unknown-interaction-modal-title-46",
+      "method": "POST",
+      "path": "/interactions/1570720847549693952/invalid-token/callback",
+      "request": {
+        "type": 9,
+        "data": {
+          "custom_id": "m",
+          "title": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+          "components": [
+            {
+              "type": 18,
+              "label": "y",
+              "component": {
+                "type": 4,
+                "custom_id": "a",
+                "style": 1
+              }
+            }
+          ]
+        }
+      },
+      "status": 404,
+      "response": {
+        "message": "Unknown interaction",
+        "code": 10062
+      }
+    },
+    {
+      "step": "callback-unknown-interaction-ack",
+      "method": "POST",
+      "path": "/interactions/1570720847549693952/invalid-token/callback",
+      "request": {
+        "type": 6
+      },
+      "status": 404,
+      "response": {
+        "message": "Unknown interaction",
+        "code": 10062
+      }
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/fixtures/recorded/uploads.json b/packages/chat/discord/test/fixtures/recorded/uploads.json
new file mode 100644
index 00000000000..0d931b9bc24
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/uploads.json
@@ -0,0 +1,218 @@
+{
+  "case": "Uploads around Discord's limit for the Janitor bot in a guild with no boosts: 10 MiB + 1 byte and 20 MiB are accepted, 20 MiB + 1 byte and 25 MiB are refused with a 413 and a JSON body",
+  "provenance": {
+    "kind": "recorded",
+    "source": "Discord REST v10 with the Janitor bot token, from a local script. request.files[0] gives the size of the upload, whose bytes are all zero",
+    "where": "guild 840178841540362250 (Tim's test guild); #test 1570605581192929301",
+    "recordedAt": "2026-11-13T08:41Z, during EFF-3755",
+    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed. Every posted message was deleted"
+  },
+  "calls": [
+    {
+      "step": "upload-10MiB-plus-1",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "payload_json": {
+          "content": "effect-chat probe: upload-over-limit",
+          "allowed_mentions": {
+            "parse": []
+          },
+          "attachments": [
+            {
+              "id": 0,
+              "filename": "probe.bin"
+            }
+          ]
+        },
+        "files[0]": {
+          "filename": "probe.bin",
+          "bytes": 10485761
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: upload-over-limit",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [
+          {
+            "id": "1570720143078850580",
+            "filename": "probe.bin",
+            "size": 10485761,
+            "url": "https://cdn.discordapp.com/attachments/1570605581192929301/1570720143078850580/probe.bin?scrubbed",
+            "proxy_url": "https://media.discordapp.net/attachments/1570605581192929301/1570720143078850580/probe.bin?scrubbed",
+            "content_type": "application/octet-stream",
+            "content_scan_version": 0
+          }
+        ],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:41:05.398000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570720146094424165",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      },
+      "contentType": "application/json",
+      "scrubbed": [
+        "$.attachments[0].url",
+        "$.attachments[0].proxy_url"
+      ]
+    },
+    {
+      "step": "upload-20MiB",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "payload_json": {
+          "content": "effect-chat probe: upload-20971520",
+          "allowed_mentions": {
+            "parse": []
+          },
+          "attachments": [
+            {
+              "id": 0,
+              "filename": "probe.bin"
+            }
+          ]
+        },
+        "files[0]": {
+          "filename": "probe.bin",
+          "bytes": 20971520
+        }
+      },
+      "status": 200,
+      "response": {
+        "type": 0,
+        "content": "effect-chat probe: upload-20971520",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [
+          {
+            "id": "1570720378395820032",
+            "filename": "probe.bin",
+            "size": 20971520,
+            "url": "https://cdn.discordapp.com/attachments/1570605581192929301/1570720378395820032/probe.bin?scrubbed",
+            "proxy_url": "https://media.discordapp.net/attachments/1570605581192929301/1570720378395820032/probe.bin?scrubbed",
+            "content_type": "application/octet-stream",
+            "content_scan_version": 0
+          }
+        ],
+        "embeds": [],
+        "timestamp": "2026-11-13T08:42:01.012000+00:00",
+        "edited_timestamp": null,
+        "flags": 0,
+        "components": [],
+        "id": "1570720379356581938",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false
+      },
+      "contentType": "application/json",
+      "scrubbed": [
+        "$.attachments[0].url",
+        "$.attachments[0].proxy_url"
+      ]
+    },
+    {
+      "step": "upload-20MiB-plus-1",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "payload_json": {
+          "content": "effect-chat probe: upload-20971521",
+          "allowed_mentions": {
+            "parse": []
+          },
+          "attachments": [
+            {
+              "id": 0,
+              "filename": "probe.bin"
+            }
+          ]
+        },
+        "files[0]": {
+          "filename": "probe.bin",
+          "bytes": 20971521
+        }
+      },
+      "status": 413,
+      "response": {
+        "message": "Request entity too large",
+        "code": 40005
+      },
+      "contentType": "application/json"
+    },
+    {
+      "step": "upload-25MiB",
+      "method": "POST",
+      "path": "/channels/1570605581192929301/messages",
+      "request": {
+        "payload_json": {
+          "content": "effect-chat probe: upload-26214400",
+          "allowed_mentions": {
+            "parse": []
+          },
+          "attachments": [
+            {
+              "id": 0,
+              "filename": "probe.bin"
+            }
+          ]
+        },
+        "files[0]": {
+          "filename": "probe.bin",
+          "bytes": 26214400
+        }
+      },
+      "status": 413,
+      "response": {
+        "message": "Request entity too large",
+        "code": 40005
+      },
+      "contentType": "application/json"
+    }
+  ]
+}
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index cf1791dcc91..a28d1d1de26 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -8,7 +8,7 @@ import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
 import * as Option from "effect/Option"
 import * as TestClock from "effect/testing/TestClock"
-import { botUserId, discordLayer, errorResponse, type Fake, guild, makeFake, scratch, tim } from "./utils.ts"
+import { answer, botUserId, discordLayer, type Fake, guild, makeFake, scratch, step, tim } from "./utils.ts"
 
 const message = { id: "1570700000000000001", channel_id: scratch }
 
@@ -261,8 +261,7 @@ describe("interaction", () => {
   it.effect("a modal callback that comes back Unknown interaction is refused as interaction_expired", () =>
     Effect.gen(function*() {
       const fake = makeFake({
-        createInteractionResponse: () =>
-          Effect.fail(errorResponse(404, { code: 10062, message: "Unknown interaction" }))
+        createInteractionResponse: () => answer(step("components", "callback-unknown-interaction-modal-45"))
       })
       const { handler, refused } = recording({
         click: ChatInteraction.modal("form", { title: "t", fields: {} }).open()

From 81a0a1aa379d35990de5ef372d83453ace2d9a7a Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 08:50:29 +0000
Subject: [PATCH 33/89] Describe the Discord upload limit as a conservative
 bound in the recorded uploads test

---
 packages/chat/discord/test/DiscordChat.test.ts | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index 137d204ae76..ad429321bec 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -469,7 +469,8 @@ describe("files", () => {
           assert.deepStrictEqual(result, { op: "post", tag: "TooLarge", detail: "file_refused", retry: "denied" })
         }
         assert.strictEqual(fake.calls.length, 0)
-        // The check refuses nothing Discord would take: it accepted 20 MiB in a guild with no boosts.
+        // The limit is a conservative bound, at most what Discord accepted (20 MiB in a guild with no
+        // boosts), so files between the two are refused here although Discord would take them.
         const accepted = step("uploads", "upload-20MiB")
         assert.strictEqual(accepted.status, 200)
         assert.isAtMost(discord.descriptor.limits.uploadBytes, accepted.request["files[0]"].bytes)

From 72b8b52edc7404ec204800ca923b29ad334aa04d Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 10:08:47 +0000
Subject: [PATCH 34/89] Stream Slack token shapes with a zero-width space and
 clean them up after the stop

A stream decodes the references for <, @ and !, so token shapes are found
on the decoded view and get U+200B after whatever spells the <, in prose
and code alike. Once stopped, a message whose appends differ from the
block path gets one chat.update as blocks plus text. Lone surrogates go
as U+FFFD and a trailing high surrogate is held, in the adapter and the
ChatTest fake.

Closes EFF-3753
---
 packages/chat/slack/src/SlackChat.ts        |  16 +-
 packages/chat/slack/src/internal/adapter.ts | 130 +++++++++++---
 packages/chat/slack/src/internal/escape.ts  | 185 ++++++++++++++++++++
 packages/chat/slack/test/SlackChat.test.ts  | 165 +++++++++++++++++
 packages/chat/slack/test/escape.test.ts     |  90 +++++++++-
 packages/chat/slack/test/live.test.ts       |  50 +++++-
 packages/chat/slack/test/text.test.ts       |  66 ++++++-
 packages/effect/src/chat/ChatAdapter.ts     |  18 +-
 packages/effect/src/chat/ChatTest.ts        |  18 +-
 packages/effect/test/chat/ChatTest.test.ts  |  12 ++
 10 files changed, 709 insertions(+), 41 deletions(-)

diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index d5cd5484379..753d14ac5b3 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -105,7 +105,21 @@ export class SlackChat extends Context.Service
+  text.replace(/[\ud800-\udbff](?![\udc00-\udfff])|(? (error: ChatError): boolean => error.reason.detail === code
 
 const userName = (user: JsonObject): string => {
@@ -501,6 +525,43 @@ export const make = (options: {
 
   // Native stream
 
+  /**
+   * The cleanup edit: once a stream is stopped, a message whose appends
+   * differ from what the block path would send is rewritten once as blocks
+   * plus `text`, which takes out the zero-width spaces. It carries no
+   * `actions`, since the stop never does.
+   *
+   * It is skipped when the block would pass 12,000 and when the edit fails,
+   * leaving the characters, failing nothing and saying so on the span. A
+   * message whose last append is unsettled is left to the layer's repair,
+   * which rewrites it, so it gets no second edit.
+   */
+  const cleanup = Effect.fnUntraced(function*(
+    channel: string,
+    messageId: string,
+    state: StreamState,
+    notify: Escape.Notify
+  ) {
+    let tokens = 0
+    const block = Escape.escape(state.markdown, notify, { flush: true, onToken: () => tokens++ }).sent
+    if (block === state.sent) return
+    const skip = (reason: string) => Effect.annotateCurrentSpan("slack.stream.cleanup", reason)
+    if (tokens > 0 && !cleanupWithAllowedToken) return yield* skip("allowed_token")
+    if (!state.settled) return yield* skip("unsettled")
+    const body = Text.body(state.markdown, notify, Text.updateBudget)
+    if (Length.codePoints(body.sent) > Length.messageLength) return yield* skip("too_long")
+    if (body.dropped > 0) yield* Effect.annotateCurrentSpan("slack.text.dropped_tokens", body.dropped)
+    const edited = yield* paced(
+      messageId,
+      call("nativeStream.stop", "chat.update", { channel, ts: messageId, blocks: body.blocks, text: body.text }, {
+        write: true,
+        retry: false
+      }),
+      "edit"
+    ).pipe(Effect.result)
+    yield* Effect.annotateCurrentSpan("slack.stream.cleanup", Result.isSuccess(edited) ? "edited" : "failed")
+  })
+
   const nativeStream: NonNullable = {
     start: Effect.fnUntraced(function*(thread, start) {
       const op = "nativeStream.start"
@@ -512,14 +573,15 @@ export const make = (options: {
       if (parts.threadTs === undefined || start.recipient === undefined || start.replyTo !== undefined) {
         return yield* fail(op, new Unsupported({ capability: "nativeStream" }))
       }
-      const escaped = Escape.escape(start.markdown, postOptions.notify ?? {}, { flush: true })
-      yield* checkSent(op, escaped.sent)
+      const escaped = Escape.escapeStream(start.markdown, postOptions.notify ?? {}, { flush: true })
+      const sent = wellFormed(escaped.sent)
+      yield* checkSent(op, sent)
       const startCall = call(op, "chat.startStream", {
         channel: parts.channel,
         thread_ts: parts.threadTs,
         recipient_user_id: start.recipient,
         recipient_team_id: postOptions.recipientTeamId ?? parts.team,
-        markdown_text: escaped.sent === "" ? undefined : escaped.sent
+        markdown_text: sent === "" ? undefined : sent
       }, { write: true, retry: false }).pipe(
         Effect.catchIf(
           (error) => error.reason.detail !== undefined && streamUnsupported.has(error.reason.detail),
@@ -540,43 +602,65 @@ export const make = (options: {
       const ts = yield* tsOf(op, true)(answer)
       const backoff = continues === undefined ? undefined : backoffs.get(continues)
       if (backoff !== undefined) backoffs.set(ts, backoff)
-      streams.set(ts, { escape: escaped.state, text: escaped.sent, stopped: false })
+      streams.set(ts, { escape: escaped.state, markdown: start.markdown, sent, stopped: false, settled: true })
       return { id: ts, thread, timestamp: Normalize.timestamp(ts) }
     }),
     append: Effect.fnUntraced(function*(thread, messageId, markdown, appendOptions) {
       const op = "nativeStream.append"
       const parts = yield* resolve(op, thread)
       const postOptions = yield* CurrentPostOptions
-      const state = streams.get(messageId) ?? { escape: Escape.initialState, text: "", stopped: false }
-      const escaped = Escape.escape(markdown, postOptions.notify ?? {}, {
-        state: state.escape,
-        flush: appendOptions?.flush === true
-      })
+      const state = streams.get(messageId) ??
+        { escape: Escape.initialState, markdown: "", sent: "", stopped: false, settled: true }
+      const flush = appendOptions?.flush === true
+      // A trailing high surrogate waits for its other half.
+      const input = !flush && /[\ud800-\udbff]$/.test(markdown) ? markdown.slice(0, -1) : markdown
+      const escaped = Escape.escapeStream(input, postOptions.notify ?? {}, { state: state.escape, flush })
       const held = markdown.length - escaped.consumed
       if (escaped.sent === "") return { state: "open" as const, held }
-      yield* checkSent(op, state.text + escaped.sent)
+      const sent = wellFormed(escaped.sent)
+      yield* checkSent(op, state.sent + sent)
+      const unsettle = Effect.sync(() => streams.set(messageId, { ...state, settled: false }))
       return yield* paced(
         messageId,
-        call(op, "chat.appendStream", {
-          channel: parts.channel,
-          ts: messageId,
-          markdown_text: escaped.sent
-        }, { write: true, retry: false }),
+        Effect.andThen(
+          unsettle,
+          call(op, "chat.appendStream", { channel: parts.channel, ts: messageId, markdown_text: sent }, {
+            write: true,
+            retry: false
+          })
+        ),
         "stream"
       ).pipe(
         Effect.map(() => {
-          streams.set(messageId, { escape: escaped.state, text: state.text + escaped.sent, stopped: false })
+          streams.set(messageId, {
+            escape: escaped.state,
+            markdown: state.markdown + input.slice(0, escaped.consumed),
+            sent: state.sent + sent,
+            stopped: false,
+            settled: true
+          })
           return { state: "open" as const, held }
         }),
         Effect.catchIf(
           hasDetail("message_not_in_streaming_state"),
-          () => Effect.succeed({ state: "closed" as const, held: 0 })
+          () =>
+            Effect.sync(() => {
+              // The layer carries on by editing the message, and sends no stop.
+              streams.delete(messageId)
+              return { state: "closed" as const, held: 0 }
+            })
         ),
         Effect.catchIf(hasDetail("stopped_by_user"), () =>
           Effect.sync(() => {
             streams.set(messageId, { ...state, stopped: true })
             return { state: "stopped" as const, held: 0 }
-          }))
+          })),
+        // Nothing was added.
+        Effect.tapError((error) =>
+          Effect.sync(() => {
+            if (error.retry === "denied") streams.set(messageId, state)
+          })
+        )
       )
     }),
     stop: Effect.fnUntraced(function*(thread, messageId, stopOptions) {
@@ -584,7 +668,6 @@ export const make = (options: {
       const parts = yield* resolve(op, thread)
       const postOptions = yield* CurrentPostOptions
       const state = streams.get(messageId)
-      streams.delete(messageId)
       // A rotating stop keeps the reply's backoff for its next part.
       const backoff = backoffs.get(messageId)
       if (backoff !== undefined && stopOptions.end === "done") {
@@ -604,11 +687,14 @@ export const make = (options: {
         Effect.map(Option.some),
         Effect.catchIf(hasDetail("message_not_in_streaming_state"), () => Effect.succeed(Option.none()))
       )
+      // Kept until the stop is answered, so a stop sent again after a cut-off one still cleans up.
+      streams.delete(messageId)
       const message = Option.isSome(answer) && isObject(answer.value) ? object(answer.value, "message") : undefined
       const context = message === undefined ? undefined : object(message, "ai_context")
       const result = Option.isSome(answer) && isObject(answer.value) ? answer.value.result_status : undefined
       const stopped = state?.stopped === true || result === "stopped_by_user" ||
         (context !== undefined && context.result_status === "stopped_by_user")
+      if (state !== undefined) yield* cleanup(parts.channel, messageId, state, postOptions.notify ?? {})
       if (stopped && stopOptions.end === "done" && parts.threadTs !== undefined) {
         yield* sessionStatus(parts.channel, parts.threadTs, postOptions.sessionStatusAtEnd ?? "active")
       }
diff --git a/packages/chat/slack/src/internal/escape.ts b/packages/chat/slack/src/internal/escape.ts
index 42c1435f9fa..e00d9011536 100644
--- a/packages/chat/slack/src/internal/escape.ts
+++ b/packages/chat/slack/src/internal/escape.ts
@@ -7,6 +7,8 @@
  * - The `text` beside a `markdown` block, from which Slack decides who is
  *   mentioned: every `<`, `>` and `&` becomes an entity, in code too, and
  *   only the tokens the block keeps intact stay intact.
+ * - A stream append, which has no `text`: `escapeStream` puts U+200B after
+ *   whatever spells the `<` of a token shape, in prose and in code alike.
  */
 
 /** @internal */
@@ -226,3 +228,186 @@ export const escape = (
 const entityOf: Record = { "&": "&", "<": "<", ">": ">" }
 
 const textEntities = (text: string): string => text.replace(/[&<>]/g, (char) => entityOf[char])
+
+const zeroWidthSpace = "\u200B"
+
+/** The character references a stream decodes for `<`, `@` and `!`, each only with its semicolon. */
+const references: ReadonlyArray = [
+  [/^&(?:lt|LT|#0*60|#[xX]0*3[cC]);/, "<"],
+  [/^&(?:commat|#0*64|#[xX]0*40);/, "@"],
+  [/^&(?:excl|#0*33|#[xX]0*21);/, "!"]
+]
+
+const referenceNames = ["lt", "LT", "commat", "excl"]
+
+/** Whether `text`, from its `&` on, could still grow into one of `references`. */
+const unfinishedReference = (text: string): boolean => {
+  const body = text.slice(1)
+  return /^#(?:[0-9]*|[xX][0-9a-fA-F]*)$/.test(body) || referenceNames.some((name) => name.startsWith(body))
+}
+
+interface Decoded {
+  readonly char: string
+  /** How many characters of the input spell it. */
+  readonly length: number
+}
+
+/** The character at `i` in the decoded view of `line`, which must be within it. */
+const decodeAt = (line: string, i: number): Decoded => {
+  if (line[i] === "&") {
+    const rest = line.slice(i, i + 16)
+    for (const [pattern, char] of references) {
+      const match = pattern.exec(rest)
+      if (match !== null) return { char, length: match[0].length }
+    }
+  }
+  return { char: line[i], length: 1 }
+}
+
+/**
+ * The character at `i` in the decoded view of `line`. `undefined` past
+ * the end of the text, and `unfinished` where the next chunk could still
+ * change it.
+ */
+const decodedAt = (line: string, i: number, ended: boolean): Decoded | "unfinished" | undefined => {
+  if (i >= line.length) return ended ? undefined : "unfinished"
+  const decoded = decodeAt(line, i)
+  return decoded.char === "&" && !ended && unfinishedReference(line.slice(i)) ? "unfinished" : decoded
+}
+
+/** `line` from `i` to its first `>`, or to its end, decoded, with the end in `line` of each decoded character. */
+const decodeToken = (line: string, i: number): { readonly text: string; readonly ends: ReadonlyArray } => {
+  const close = line.indexOf(">", i)
+  const end = close === -1 ? line.length : close + 1
+  let text = ""
+  const ends: Array = []
+  for (let j = i; j < end;) {
+    const decoded = decodeAt(line, j)
+    text += decoded.char
+    j += decoded.length
+    ends.push(j)
+  }
+  return { text, ends }
+}
+
+/**
+ * Escapes a stream's Markdown, continuing from `state`. Slack decodes the
+ * character references for `<`, `@` and `!` in a stream, joins one split
+ * across two appends, and has no `text` to send beside it, so:
+ *
+ * - Token shapes are found on the decoded view, which decodes those
+ *   references only with their semicolon, in prose and in code alike. A
+ *   shape is `<@`, or ` {
+  const state = options?.state ?? initialState
+  const flush = options?.flush === true
+  const full = state.line + text
+  const offset = state.line.length
+  const anyAllowed = allowsAny(notify)
+  let fence = state.fence
+  let out = ""
+  let lineStart = 0
+  const emit = (from: number, to: number) => {
+    if (to > offset) out += full.slice(Math.max(from, offset), to)
+  }
+  while (lineStart <= full.length) {
+    const newline = full.indexOf("\n", lineStart)
+    const complete = newline !== -1
+    const lineEnd = complete ? newline : full.length
+    const line = full.slice(lineStart, lineEnd)
+    const inFence = fence !== undefined
+    const opener = !inFence && complete ? opensFence(line) : undefined
+    const { open, spans } = inFence || opener !== undefined ? { open: -1, spans: [] } : codeSpans(line)
+    const hold = (i: number): Escaped => {
+      const at = lineStart + i
+      return { sent: out, consumed: at - offset, state: { fence, line: full.slice(lineStart, at) } }
+    }
+    let i = 0
+    let span = 0
+    while (i < line.length) {
+      const next = line.slice(i).search(/[<&]/)
+      if (next === -1) {
+        emit(lineStart + i, lineEnd)
+        break
+      }
+      emit(lineStart + i, lineStart + i + next)
+      i += next
+      const at = lineStart + i
+      const ended = complete || flush || full.length - at > holdBound
+      const first = decodedAt(line, i, ended)
+      if (first === "unfinished") return hold(i)
+      if (first === undefined || first.char !== "<") {
+        // An `&` that spells no `<`. What it spells is decided where it is used.
+        emit(at, at + 1)
+        i += 1
+        continue
+      }
+      const second = decodedAt(line, i + first.length, ended)
+      if (second === "unfinished") return hold(i)
+      let shape = second?.char === "@"
+      if (second?.char === "!") {
+        const third = decodedAt(line, i + first.length + second.length, ended)
+        if (third === "unfinished") return hold(i)
+        shape = third !== undefined && third.length === 1 && /[A-Za-z]/.test(third.char)
+      }
+      if (shape) {
+        const token = decodeToken(line, i)
+        const length = allowedToken(token.text, notify)
+        if (length > 0) {
+          emit(at, lineStart + token.ends[length - 1])
+          i = token.ends[length - 1]
+          continue
+        }
+        if (!ended && anyAllowed && !token.text.includes(">") && /^<(@|!)?[\w^|]*$/.test(token.text)) return hold(i)
+        emit(at, at + first.length)
+        if (at >= offset) out += zeroWidthSpace
+        i += first.length
+        continue
+      }
+      if (first.length > 1) {
+        // A reference for `<` that starts no token shape is left as written.
+        emit(at, at + first.length)
+        i += first.length
+        continue
+      }
+      while (span < spans.length && spans[span][1] <= i) span++
+      const inCode = inFence || opener !== undefined || (span < spans.length && spans[span][0] <= i)
+      if (!inCode && !ended && open !== -1 && open < i) return hold(i)
+      if (inCode) emit(at, at + 1)
+      else if (at >= offset) out += "<"
+      i += 1
+    }
+    if (inFence) {
+      if (complete && closesFence(line, fence!)) fence = undefined
+    } else if (opener !== undefined) {
+      fence = opener
+    }
+    if (!complete) {
+      return { sent: out, consumed: full.length - offset, state: { fence, line } }
+    }
+    emit(lineEnd, lineEnd + 1)
+    lineStart = lineEnd + 1
+  }
+  return { sent: out, consumed: full.length - offset, state: { fence, line: "" } }
+}
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 70dfcb8d63c..88c98df5d20 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -869,6 +869,171 @@ describe("nativeStream", () => {
     )
   })
 
+  describe("the cleanup edit", () => {
+    const z = "\u200B"
+    const recipient = "U080YLYB277"
+    /** Runs `effect` in a span and gives what it set as `slack.stream.cleanup`. */
+    const cleanupOf = Effect.fnUntraced(function*(effect: Effect.Effect) {
+      yield* effect
+      return (yield* Effect.currentSpan).attributes.get("slack.stream.cleanup")
+    }, Effect.withSpan("test"))
+    const updates = (fake: ReturnType) =>
+      fake.called("chat.update").map((call): Record => ({
+        ...call.params,
+        blocks: JSON.parse(call.params.blocks)
+      }))
+
+    it.effect("rewrites a stream whose appends differ from the block, once, after the stop, with no actions", () => {
+      const fake = makeFake({ "chat.startStream": posted(ts), "chat.appendStream": posted(ts) })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          yield* native.start(replyThread, { markdown: "Hi <@U2> ", recipient })
+          yield* native.append(replyThread, ts, "and `<@U3>` a < b", { flush: true })
+          assert.deepStrictEqual(
+            fake.calls.map((call) => call.method).filter((method) => method !== "auth.test"),
+            ["chat.startStream", "chat.appendStream"]
+          )
+          assert.strictEqual(fake.called("chat.startStream")[0].params.markdown_text, `Hi <${z}@U2> `)
+          assert.strictEqual(fake.called("chat.appendStream")[0].params.markdown_text, `and \`<${z}@U3>\` a < b`)
+          const cleanup = yield* cleanupOf(native.stop(replyThread, ts, { end: "done" }))
+          assert.strictEqual(cleanup, "edited")
+          assert.deepStrictEqual(fake.calls.map((call) => call.method).slice(-2), ["chat.stopStream", "chat.update"])
+          assert.deepStrictEqual(updates(fake), [{
+            channel,
+            ts,
+            blocks: [{ type: "markdown", text: "Hi <@U2> and `<@U3>` a < b" }],
+            text: "Hi <@U2> and `<@U3>` a < b"
+          }])
+        })
+      )
+    })
+
+    it.effect("runs for a message with an allowed token, which stays in text", () => {
+      const fake = makeFake({ "chat.startStream": posted(ts) })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          const allowed = SlackChat.withPostOptions({ notify: { users: ["U1"] } })
+          yield* native.start(replyThread, { markdown: "<@U1> <@U2>", recipient }).pipe(allowed)
+          assert.strictEqual(fake.called("chat.startStream")[0].params.markdown_text, `<@U1> <${z}@U2>`)
+          assert.strictEqual(
+            yield* cleanupOf(native.stop(replyThread, ts, { end: "rotating" }).pipe(allowed)),
+            "edited"
+          )
+          const [update] = updates(fake)
+          assert.deepStrictEqual(update.blocks, [{ type: "markdown", text: "<@U1> <@U2>" }])
+          assert.strictEqual(update.text, "<@U1> &lt;@U2>")
+        })
+      )
+    })
+
+    it.effect("is not sent when the appends match the block", () => {
+      const fake = makeFake({ "chat.startStream": posted(ts) })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          yield* native.start(replyThread, { markdown: "a < b `` < <@U1>", recipient }).pipe(
+            SlackChat.withPostOptions({ notify: { users: ["U1"] } })
+          )
+          const cleanup = yield* cleanupOf(
+            native.stop(replyThread, ts, { end: "done" }).pipe(SlackChat.withPostOptions({ notify: { users: ["U1"] } }))
+          )
+          assert.isUndefined(cleanup)
+          assert.strictEqual(fake.called("chat.update").length, 0)
+        })
+      )
+    })
+
+    it.effect("is skipped when the block would pass 12,000", () => {
+      const fake = makeFake({ "chat.startStream": posted(ts) })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          // 7 code points each as streamed, 9 in the block: 10,500 against 13,500.
+          yield* native.start(replyThread, { markdown: "<@U2> ".repeat(1_500), recipient })
+          assert.strictEqual(yield* cleanupOf(native.stop(replyThread, ts, { end: "done" })), "too_long")
+          assert.strictEqual(fake.called("chat.update").length, 0)
+        })
+      )
+    })
+
+    it.effect("is skipped when the edit fails, and the stop still succeeds", () => {
+      const fake = makeFake({
+        "chat.startStream": posted(ts),
+        "chat.update": { ok: false, error: "cant_update_message" }
+      })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          yield* native.start(replyThread, { markdown: "<@U2>", recipient })
+          let result: { readonly stopped: boolean } | undefined
+          const cleanup = yield* cleanupOf(
+            Effect.map(native.stop(replyThread, ts, { end: "done" }), (stopped) => (result = stopped))
+          )
+          assert.strictEqual(cleanup, "failed")
+          assert.deepStrictEqual(result, { stopped: false })
+          assert.strictEqual(fake.called("chat.update").length, 1)
+        })
+      )
+    })
+
+    it.effect("leaves a part the repair path rewrites to the repair edit", () => {
+      const fake = makeFake({
+        "chat.startStream": posted(ts),
+        "chat.appendStream": { status: 500 },
+        "chat.update": posted(ts)
+      })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const slack = yield* adapter
+          const native = slack.nativeStream!
+          yield* native.start(replyThread, { markdown: "a <@U2>", recipient })
+          const failed = yield* reason(native.append(replyThread, ts, " b", undefined))
+          assert.strictEqual(failed.retry, "uncertain")
+          // The layer's repair: stop, then edit the part to its whole known text.
+          assert.strictEqual(yield* cleanupOf(native.stop(replyThread, ts, { end: "rotating" })), "unsettled")
+          yield* slack.edit(replyThread, ts, { markdown: "a <@U2> b" })
+          assert.strictEqual(fake.called("chat.update").length, 1)
+          assert.strictEqual(fake.called("chat.update")[0].params.text, "a <@U2> b")
+        })
+      )
+    })
+  })
+
+  it.effect("holds a trailing high surrogate and sends any other lone surrogate as U+FFFD", () => {
+    const fake = makeFake({ "chat.startStream": posted(ts), "chat.appendStream": posted(ts) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const native = (yield* adapter).nativeStream!
+        yield* native.start(replyThread, { markdown: "x\udc00", recipient: "U1" })
+        assert.deepStrictEqual(yield* native.append(replyThread, ts, "a\ud83d", undefined), { state: "open", held: 1 })
+        assert.deepStrictEqual(yield* native.append(replyThread, ts, "\ud83d", undefined), { state: "open", held: 1 })
+        // With an unclosed < as well, the longer tail.
+        assert.deepStrictEqual(yield* native.append(replyThread, ts, "\ud83d\ude00 <\ud83d", undefined), {
+          state: "open",
+          held: 2
+        })
+        assert.deepStrictEqual(yield* native.append(replyThread, ts, "<\ud83d", { flush: true }), {
+          state: "open",
+          held: 0
+        })
+        assert.strictEqual(fake.called("chat.startStream")[0].params.markdown_text, "x\ufffd")
+        assert.deepStrictEqual(
+          fake.called("chat.appendStream").map((call) => call.params.markdown_text),
+          ["a", "😀 ", "<\ufffd"]
+        )
+      })
+    )
+  })
+
   it.effect("stop on a closed stream succeeds", () => {
     const fake = makeFake({ "chat.stopStream": { ok: false, error: "message_not_in_streaming_state" } })
     return run(
diff --git a/packages/chat/slack/test/escape.test.ts b/packages/chat/slack/test/escape.test.ts
index 8b72cdfa541..f71e5f9f3bc 100644
--- a/packages/chat/slack/test/escape.test.ts
+++ b/packages/chat/slack/test/escape.test.ts
@@ -1,4 +1,4 @@
-import { escape } from "@effect/chat-slack/internal/escape"
+import { escape, escapeStream } from "@effect/chat-slack/internal/escape"
 import { codePoints, measure } from "@effect/chat-slack/internal/length"
 import { assert, describe, it } from "@effect/vitest"
 
@@ -56,6 +56,94 @@ describe("escape", () => {
   })
 })
 
+describe("escapeStream", () => {
+  const z = "\u200B"
+  const streamed = (text: string, notify = {}) => escapeStream(text, notify, { flush: true }).sent
+
+  it("puts U+200B after whatever spells the < of a token shape, in prose and in code", () => {
+    assert.strictEqual(streamed("a <@U1> b"), `a <${z}@U1> b`)
+    assert.strictEqual(streamed("`<@U1>` and ```\n\n```"), `\`<${z}@U1>\` and \`\`\`\n<${z}!here>\n\`\`\``)
+    assert.strictEqual(
+      streamed("<@U1> <!channel> <@U1> <@U1> <@U1> <@U1>"),
+      [
+        `<${z}@U1>`,
+        `<${z}!channel>`,
+        `<${z}@U1>`,
+        `<${z}@U1>`,
+        `<${z}@U1>`,
+        `<${z}@U1>`
+      ].join(" ")
+    )
+    assert.strictEqual(
+      streamed("<@U1> <@U1> <@U1> <!here>"),
+      [
+        `<${z}@U1>`,
+        `<${z}@U1>`,
+        `<${z}@U1>`,
+        `<${z}!here>`
+      ].join(" ")
+    )
+    assert.strictEqual(streamed(" "), `<${z}!subteam^S1> <${z}!everyone>`)
+  })
+
+  it("leaves the rest to the block rule", () => {
+    //  "), "<!-- x --> <![CDATA[ y ]]>")
+    assert.strictEqual(streamed("a < b `c < d` <b> <"), "a < b `c < d` <b> <")
+    // Without the semicolon nothing decodes.
+    assert.strictEqual(
+      streamed("<@U1> <@U1> <@U1> <&commat U1>"),
+      "<@U1> <@U1> <@U1> <&commat U1>"
+    )
+    // Letters are not decoded.
+    assert.strictEqual(streamed(""), "<!here>")
+  })
+
+  it("sends an allowed token as it is", () => {
+    const notify = { users: ["U1"], groups: ["S1"], broadcast: true }
+    assert.strictEqual(
+      streamed("<@U1> <@U2>   `<@U1>` <@U1>", notify),
+      `<@U1> <${z}@U2>   \`<@U1>\` <@U1>`
+    )
+  })
+
+  it("holds an unclosed <, an unfinished reference and an undecided token", () => {
+    const notify = { users: ["U1"] }
+    const cases: ReadonlyArray = [
+      ["a <", "a "],
+      ["a  y", notify, { state: first.state })
+    assert.strictEqual(first.sent + second.sent, "x <@U1> y")
+    // flush and the bound send it.
+    assert.strictEqual(escapeStream("a &l", {}, { flush: true }).sent, "a &l")
+    assert.strictEqual(escapeStream("a <", {}, { flush: true }).sent, "a <")
+    const long = "<@U1|" + "x".repeat(400)
+    assert.strictEqual(escapeStream(long, notify).sent, `<${z}@U1|` + "x".repeat(400))
+  })
+})
+
 describe("measure", () => {
   it("bounds what is sent and adds up", () => {
     const samples = ["plain", "a < b", "<<<", "😀😀", "`<@U1>` ", "👍🏽 and 1\u20E3", "\ud83d", "🇺🇸"]
diff --git a/packages/chat/slack/test/live.test.ts b/packages/chat/slack/test/live.test.ts
index a6fc3f059d8..c5410086555 100644
--- a/packages/chat/slack/test/live.test.ts
+++ b/packages/chat/slack/test/live.test.ts
@@ -96,9 +96,11 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
  * It is a proxy: Slack decides a mention from the stored `text`, which was
  * checked against one client's Activity feed (EFF-3730, EFF-3736). It also
  * makes a file post and a file-only post, and asserts each holds its file
- * after the attach. The stream inputs belong to the stream route and are not
- * here yet. The same assertions run in CI on the request bodies, in
- * `text.test.ts` and `SlackChat.test.ts`.
+ * after the attach. It streams token shapes split at every position across
+ * two appends, and asserts that no token is stored and no U+200B is left once
+ * the stream is stopped. The stream needs a recipient, the identity of
+ * `SLACK_LIVE_USER_TOKEN`. The same assertions run in CI on the request
+ * bodies, in `text.test.ts` and `SlackChat.test.ts`.
  */
 describe.skipIf(botToken === undefined || teamId === undefined || channel === undefined)("live mention rule", () => {
   const layer = SlackChat.layer({ botToken: Redacted.make(botToken!), teamId: teamId! }).pipe(
@@ -185,4 +187,46 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
       // `delete` keeps a message's files.
       for (const file of fileIds) yield* api.call("files.delete", { file }, { write: true }).pipe(Effect.ignore)
     }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)), 600_000)
+
+  it.live("no token is stored and no U+200B is left by a stream split at every position", () =>
+    Effect.gen(function*() {
+      if (userToken === undefined) return yield* Effect.die(new Error("SLACK_LIVE_USER_TOKEN is not set"))
+      const api = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) })
+      const self = field(yield* api.call("auth.test", {}), "user_id") as string
+      const user = yield* SlackWebApi.make({ botToken: Redacted.make(userToken) })
+      const recipient = field(yield* user.call("auth.test", {}), "user_id") as string
+      const slack = yield* adapter
+      const native = slack.nativeStream!
+      const root = yield* slack.post(SlackChat.thread({ team: teamId!, channel: channel! }), { markdown: "streams" })
+      const thread = SlackChat.thread({ team: teamId!, channel: channel!, threadTs: root.id })
+      const stored = (ts: string) =>
+        api.call("conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 2 }).pipe(
+          Effect.map((answer) => (field(answer, "messages") as Array).find((message) => message.ts === ts))
+        )
+      const inputs = [
+        `<@${self}>`,
+        `<@${self}>`,
+        `<@${self}>`,
+        `<!here>`,
+        `\`\``,
+        // Without the semicolon nothing decodes.
+        `<@${self}> <@${self}>`
+      ]
+      const streamed = Effect.fnUntraced(function*(markdown: string, at: number) {
+        const label = `${JSON.stringify(markdown)} at ${at}`
+        const first = markdown.slice(0, at)
+        const started = yield* native.start(thread, { markdown: "s ", recipient })
+        const { held } = yield* native.append(thread, started.id, first, undefined)
+        yield* native.append(thread, started.id, first.slice(first.length - held) + markdown.slice(at), { flush: true })
+        yield* native.stop(thread, started.id, { end: "done" })
+        const message = yield* stored(started.id)
+        assert.deepStrictEqual(message.text.match(token), null, label)
+        assert.notInclude(JSON.stringify([message.text, message.blocks]), "\u200B", label)
+        yield* slack.delete(thread, started.id).pipe(Effect.ignore)
+      })
+      for (const markdown of inputs) {
+        for (let at = 0; at <= markdown.length; at++) yield* streamed(markdown, at)
+      }
+      yield* slack.delete(thread, root.id).pipe(Effect.ignore)
+    }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)), 3_600_000)
 })
diff --git a/packages/chat/slack/test/text.test.ts b/packages/chat/slack/test/text.test.ts
index 40a8ef5b658..9cf1cfd7536 100644
--- a/packages/chat/slack/test/text.test.ts
+++ b/packages/chat/slack/test/text.test.ts
@@ -65,8 +65,8 @@ describe("build", () => {
 /**
  * The CI half of the Slack mention rule: the same assertions the live rule
  * makes on stored messages, made here on the request bodies the adapter
- * builds for `chat.postMessage` and `chat.update`. Stream appends are left
- * to the stream's own rule.
+ * builds for `chat.postMessage` and `chat.update`. Stream appends are under
+ * "stream bodies".
  */
 describe("request bodies", () => {
   const thread = SlackChat.thread({ team, channel })
@@ -154,3 +154,65 @@ describe("request bodies", () => {
     }).pipe(Effect.provide(slackLayer(fake)))
   }, 60_000)
 })
+
+/**
+ * The CI half of the Slack mention rule for a stream: every input split at
+ * every position across two appends, with the held tail sent again as the
+ * layer does. Slack joins a reference split across appends, so the check is
+ * on what the appends add up to, decoded. Forms without a semicolon decode to
+ * nothing, so they must give no token.
+ */
+describe("stream bodies", () => {
+  const thread = SlackChat.thread({ team, channel, threadTs: "1794509110.999799" })
+  const token = /<(?:@[UW][A-Z0-9]+|!subteam\^[A-Z0-9]+|!(?:here|channel|everyone))(?:\|[^<>]*)?>/g
+  /** Slack's decoding on a stream, in code too, which is wider than Slack. */
+  const decode = (text: string) =>
+    text.replace(/&(?:lt|LT|#0*60|#[xX]0*3[cC]);/g, "<").replace(/&(?:commat|#0*64|#[xX]0*40);/g, "@").replace(
+      /&(?:excl|#0*33|#[xX]0*21);/g,
+      "!"
+    )
+  const alphabet = ["<", "<", "&l", "t;", "<", "@U1", "@", "!", "here", "`", "\n", "x", ">", "👍🏽"]
+  const words = (length: number): Array =>
+    length === 0 ? [""] : words(length - 1).flatMap((word) => alphabet.map((piece) => word + piece))
+
+  it.effect("hold the mention rule at every split, and leave no U+200B after the stream", () => {
+    let count = 0
+    // A new message for each stream, so the edit pacing never waits.
+    const fake = makeFake({ "chat.startStream": () => ({ ok: true, channel, ts: `1.${count}` }) })
+    return Effect.gen(function*() {
+      const native = (yield* adapter).nativeStream!
+      let cleaned = 0
+      for (const notify of [{}, { users: ["U1"] }] as ReadonlyArray) {
+        const allowed = notify.users === undefined ? [] : ["<@U1>"]
+        for (const word of [1, 2].flatMap(words)) {
+          for (let at = 0; at <= word.length; at++) {
+            const label = `${JSON.stringify(word)} at ${at} ${JSON.stringify(notify)}`
+            const before = fake.calls.length
+            const first = word.slice(0, at)
+            yield* Effect.gen(function*() {
+              const { id: ts } = yield* native.start(thread, { markdown: "s ", recipient: "U080YLYB277" })
+              const { held } = yield* native.append(thread, ts, first, undefined)
+              yield* native.append(thread, ts, first.slice(first.length - held) + word.slice(at), { flush: true })
+              yield* native.stop(thread, ts, { end: "done" })
+            }).pipe(SlackChat.withPostOptions({ notify }))
+            const calls = fake.calls.slice(before)
+            const streamed = calls.filter((call) => call.method !== "chat.update" && call.params.markdown_text)
+              .map((call) => call.params.markdown_text).join("")
+            // However it is split, the stream sends the same.
+            assert.strictEqual(streamed, Escape.escapeStream("s " + word, notify, { flush: true }).sent, label)
+            let rest = decode(streamed)
+            for (const allowedToken of allowed) rest = rest.replaceAll(allowedToken, "")
+            assert.deepStrictEqual(rest.match(token), null, label)
+            const update = calls.find((call) => call.method === "chat.update")
+            const left = update === undefined ? streamed : update.params.blocks + update.params.text
+            assert.notInclude(left, "\u200B", label)
+            if (update !== undefined) cleaned++
+            count++
+          }
+        }
+      }
+      assert.strictEqual(count, 2 * [1, 2].flatMap(words).reduce((sum, word) => sum + word.length + 1, 0))
+      assert.isAbove(cleaned, 0)
+    }).pipe(Effect.provide(slackLayer(fake)))
+  }, 60_000)
+})
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index ec599964913..ae920b15fca 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -245,14 +245,18 @@ export interface Ops {
  *
  * - `start` fails with `Unsupported` when the platform refuses the feature
  *   for this thread or recipient, and the caller falls back to post-then-edit.
- *   It holds nothing back: all of `markdown` is sent.
+ *   It holds nothing back: all of `markdown` is sent. Do not end `markdown`
+ *   inside a surrogate pair: a lone surrogate is sent as U+FFFD.
  * - `append` is never retried by the adapter. `open` means the text was
- *   added apart from its last `held` characters, `stopped` means nothing was
- *   added because a user stopped the stream, and `closed` means nothing was
- *   added because the stream is closed or expired. `held` trailing characters
- *   were not sent and go again at the front of the next append; `flush` holds
- *   nothing back. A `TooLarge` failure means nothing was added and the stream
- *   is still open.
+ *   added apart from its last `held` UTF-16 code units, `stopped` means
+ *   nothing was added because a user stopped the stream, and `closed` means
+ *   nothing was added because the stream is closed or expired.
+ * - `held` counts the trailing code units the adapter could not send yet,
+ *   such as an unclosed `<` or a high surrogate whose other half has not
+ *   arrived. The caller keeps `markdown.slice(markdown.length - held)` and
+ *   sends it again at the front of the next append. `flush` holds nothing
+ *   back and sends a lone surrogate as U+FFFD. A `TooLarge` failure means
+ *   nothing was added and the stream is still open.
  * - `stop` closes the stream. `stopped` says whether a user had clicked stop
  *   on it. It succeeds with `stopped: false` on a stream that is already
  *   closed.
diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index 97ce03ff091..aa76dc2e012 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -230,6 +230,10 @@ interface StoredStream {
 /** An append holds back an unclosed `<` tail, as Slack does, up to this many characters. */
 const heldBound = 100
 
+/** Every lone surrogate as U+FFFD, as `String.prototype.toWellFormed` gives. */
+const wellFormed = (text: string): string =>
+  text.replace(/[\ud800-\udbff](?![\udc00-\udfff])|(?", open)) {
+          if (!flush && open !== -1 && !markdown.includes(">", open)) {
             held = markdown.length - open
             if (held > heldBound) held = 0
           }
-          const sent = markdown.slice(0, markdown.length - held)
+          // A trailing high surrogate waits for its other half.
+          if (!flush && held === 0 && /[\ud800-\udbff]$/.test(markdown)) held = 1
+          const sent = wellFormed(markdown.slice(0, markdown.length - held))
           if (descriptor.measure(message.text + sent) > streamLength()) {
             return yield* fail("nativeStream.append", new TooLarge({ subject: "text", detail: "msg_too_long" }))
           }
@@ -909,8 +916,9 @@ const makeFake = (options: {
  * - The native stream behaves the way Slack's was found to. An append past
  *   `limits.streamLength` fails with `TooLarge` and adds nothing. A stream
  *   past `limits.streamAge`, on `Clock`, is closed. An append without
- *   `flush` holds back an unclosed `<` tail of up to 100 characters. An open
- *   stream refuses `edit` and `delete`.
+ *   `flush` holds back an unclosed `<` tail of up to 100 characters, or a
+ *   trailing high surrogate. Any other lone surrogate is stored as U+FFFD.
+ *   An open stream refuses `edit` and `delete`.
  * - With `buttons` or `selects` on, a message takes 25 elements, and an
  *   element's id plus encoded value 100 code points. With `modals` on, a
  *   modal's id plus encoded metadata takes 100 code points, and a modal 5
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index 7451ba92933..e1d712e6e52 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -462,4 +462,16 @@ describe("ChatTest", () => {
       limits: { messageLength: 10 },
       measure: (markdown) => markdown.length + 3 * (markdown.split("<").length - 1)
     }))))
+
+  it.effect("the native stream holds a trailing high surrogate and stores any other lone one as U+FFFD", () =>
+    Effect.gen(function*() {
+      const test = yield* ChatTest.ChatTest
+      const native = (yield* (yield* ChatAdapter.Registry).get("test")).nativeStream!
+      const thread = yield* test.makeThread()
+      const posted = yield* native.start(thread, { markdown: "x\udc00" })
+      assert.deepStrictEqual(yield* native.append(thread, posted.id, "a\ud83d", undefined), { state: "open", held: 1 })
+      yield* native.append(thread, posted.id, "\ud83d\ude00\ud83d", { flush: true })
+      const [message] = yield* test.messages(thread)
+      assert.strictEqual(message.text, "x\ufffda😀\ufffd")
+    }).pipe(Effect.provide(ChatTest.layer())))
 })

From bbe8e420611561d33e479d54a5a54d6ee10ded96 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 10:30:04 +0000
Subject: [PATCH 35/89] Close the Slack stream escape's boundary,
 long-reference and label gaps, and keep the cleanup until it runs

A shape that a start or flush sent only part of now gets U+200B at the
start of the next write. References decode with any number of leading
zeros. An allowed token's unclosed label is held. The cleanup state is
kept until the edit finishes, so a stop sent again after an interrupted
one runs it, and an append that finds the stream stopped by the user
runs the cleanup itself.

Closes EFF-3753
---
 packages/chat/slack/src/SlackChat.ts        |   9 +-
 packages/chat/slack/src/internal/adapter.ts |  56 ++++++---
 packages/chat/slack/src/internal/escape.ts  |  40 +++++--
 packages/chat/slack/test/SlackChat.test.ts  |  41 +++++++
 packages/chat/slack/test/live.test.ts       | 121 ++++++++++++--------
 packages/chat/slack/test/text.test.ts       |  84 +++++++++-----
 6 files changed, 246 insertions(+), 105 deletions(-)

diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 753d14ac5b3..be6676c41c6 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -112,14 +112,17 @@ export class SlackChat extends Context.Service 0) yield* Effect.annotateCurrentSpan("slack.text.dropped_tokens", body.dropped)
     const edited = yield* paced(
       messageId,
-      call("nativeStream.stop", "chat.update", { channel, ts: messageId, blocks: body.blocks, text: body.text }, {
+      call(op, "chat.update", { channel, ts: messageId, blocks: body.blocks, text: body.text }, {
         write: true,
         retry: false
       }),
@@ -562,6 +568,16 @@ export const make = (options: {
     yield* Effect.annotateCurrentSpan("slack.stream.cleanup", Result.isSuccess(edited) ? "edited" : "failed")
   })
 
+  const cleanup = (op: string, channel: string, messageId: string, notify: Escape.Notify): Effect.Effect =>
+    Effect.suspend(() => {
+      const state = streams.get(messageId)
+      if (state === undefined || state.cleaned) return Effect.void
+      return Effect.andThen(
+        cleanupEdit(op, channel, messageId, state, notify),
+        Effect.sync(() => void streams.set(messageId, { ...state, cleaned: true }))
+      )
+    })
+
   const nativeStream: NonNullable = {
     start: Effect.fnUntraced(function*(thread, start) {
       const op = "nativeStream.start"
@@ -602,7 +618,14 @@ export const make = (options: {
       const ts = yield* tsOf(op, true)(answer)
       const backoff = continues === undefined ? undefined : backoffs.get(continues)
       if (backoff !== undefined) backoffs.set(ts, backoff)
-      streams.set(ts, { escape: escaped.state, markdown: start.markdown, sent, stopped: false, settled: true })
+      streams.set(ts, {
+        escape: escaped.state,
+        markdown: start.markdown,
+        sent,
+        stopped: false,
+        settled: true,
+        cleaned: false
+      })
       return { id: ts, thread, timestamp: Normalize.timestamp(ts) }
     }),
     append: Effect.fnUntraced(function*(thread, messageId, markdown, appendOptions) {
@@ -610,7 +633,7 @@ export const make = (options: {
       const parts = yield* resolve(op, thread)
       const postOptions = yield* CurrentPostOptions
       const state = streams.get(messageId) ??
-        { escape: Escape.initialState, markdown: "", sent: "", stopped: false, settled: true }
+        { escape: Escape.initialState, markdown: "", sent: "", stopped: false, settled: true, cleaned: false }
       const flush = appendOptions?.flush === true
       // A trailing high surrogate waits for its other half.
       const input = !flush && /[\ud800-\udbff]$/.test(markdown) ? markdown.slice(0, -1) : markdown
@@ -637,7 +660,8 @@ export const make = (options: {
             markdown: state.markdown + input.slice(0, escaped.consumed),
             sent: state.sent + sent,
             stopped: false,
-            settled: true
+            settled: true,
+            cleaned: false
           })
           return { state: "open" as const, held }
         }),
@@ -650,11 +674,15 @@ export const make = (options: {
               return { state: "closed" as const, held: 0 }
             })
         ),
-        Effect.catchIf(hasDetail("stopped_by_user"), () =>
-          Effect.sync(() => {
-            streams.set(messageId, { ...state, stopped: true })
-            return { state: "stopped" as const, held: 0 }
-          })),
+        // Slack closed the stream, and the layer sends no stop after this, so the cleanup runs here.
+        Effect.catchIf(
+          hasDetail("stopped_by_user"),
+          () =>
+            Effect.sync(() => streams.set(messageId, { ...state, stopped: true })).pipe(
+              Effect.andThen(cleanup(op, parts.channel, messageId, postOptions.notify ?? {})),
+              Effect.as({ state: "stopped" as const, held: 0 })
+            )
+        ),
         // Nothing was added.
         Effect.tapError((error) =>
           Effect.sync(() => {
@@ -687,14 +715,14 @@ export const make = (options: {
         Effect.map(Option.some),
         Effect.catchIf(hasDetail("message_not_in_streaming_state"), () => Effect.succeed(Option.none()))
       )
-      // Kept until the stop is answered, so a stop sent again after a cut-off one still cleans up.
-      streams.delete(messageId)
       const message = Option.isSome(answer) && isObject(answer.value) ? object(answer.value, "message") : undefined
       const context = message === undefined ? undefined : object(message, "ai_context")
       const result = Option.isSome(answer) && isObject(answer.value) ? answer.value.result_status : undefined
       const stopped = state?.stopped === true || result === "stopped_by_user" ||
         (context !== undefined && context.result_status === "stopped_by_user")
-      if (state !== undefined) yield* cleanup(parts.channel, messageId, state, postOptions.notify ?? {})
+      yield* cleanup(op, parts.channel, messageId, postOptions.notify ?? {})
+      // Kept until now, so a stop sent again after a cut-off one still cleans up.
+      streams.delete(messageId)
       if (stopped && stopOptions.end === "done" && parts.threadTs !== undefined) {
         yield* sessionStatus(parts.channel, parts.threadTs, postOptions.sessionStatusAtEnd ?? "active")
       }
diff --git a/packages/chat/slack/src/internal/escape.ts b/packages/chat/slack/src/internal/escape.ts
index e00d9011536..56ab7e84a39 100644
--- a/packages/chat/slack/src/internal/escape.ts
+++ b/packages/chat/slack/src/internal/escape.ts
@@ -233,9 +233,9 @@ const zeroWidthSpace = "\u200B"
 
 /** The character references a stream decodes for `<`, `@` and `!`, each only with its semicolon. */
 const references: ReadonlyArray = [
-  [/^&(?:lt|LT|#0*60|#[xX]0*3[cC]);/, "<"],
-  [/^&(?:commat|#0*64|#[xX]0*40);/, "@"],
-  [/^&(?:excl|#0*33|#[xX]0*21);/, "!"]
+  [/&(?:lt|LT|#0*60|#[xX]0*3[cC]);/y, "<"],
+  [/&(?:commat|#0*64|#[xX]0*40);/y, "@"],
+  [/&(?:excl|#0*33|#[xX]0*21);/y, "!"]
 ]
 
 const referenceNames = ["lt", "LT", "commat", "excl"]
@@ -246,18 +246,24 @@ const unfinishedReference = (text: string): boolean => {
   return /^#(?:[0-9]*|[xX][0-9a-fA-F]*)$/.test(body) || referenceNames.some((name) => name.startsWith(body))
 }
 
+/** The start of a token an allowed one could still complete, label included. */
+const unclosedToken = /^<[@!][\w^]*(?:\|[^<>]*)?$/
+
 interface Decoded {
   readonly char: string
   /** How many characters of the input spell it. */
   readonly length: number
 }
 
-/** The character at `i` in the decoded view of `line`, which must be within it. */
+/**
+ * The character at `i` in the decoded view of `line`, which must be within
+ * it. A reference may have any number of leading zeros.
+ */
 const decodeAt = (line: string, i: number): Decoded => {
   if (line[i] === "&") {
-    const rest = line.slice(i, i + 16)
     for (const [pattern, char] of references) {
-      const match = pattern.exec(rest)
+      pattern.lastIndex = i
+      const match = pattern.exec(line)
       if (match !== null) return { char, length: match[0].length }
     }
   }
@@ -308,7 +314,9 @@ const decodeToken = (line: string, i: number): { readonly text: string; readonly
  * `<` with too little after it to tell, a trailing reference that is not
  * finished, an unclosed token the notify options might allow, and a `<`
  * after a backtick the line has not closed yet. Past a bound, or with
- * `flush`, it decides with what it has.
+ * `flush`, it decides with what it has. A shape that only the next chunk
+ * completes, after such a write, gets U+200B at the start of the next write,
+ * since Slack reads the writes joined.
  *
  * @internal
  */
@@ -354,7 +362,8 @@ export const escapeStream = (
       emit(lineStart + i, lineStart + i + next)
       i += next
       const at = lineStart + i
-      const ended = complete || flush || full.length - at > holdBound
+      // What an earlier write sent can't be held.
+      const ended = complete || flush || at < offset || full.length - at > holdBound
       const first = decodedAt(line, i, ended)
       if (first === "unfinished") return hold(i)
       if (first === undefined || first.char !== "<") {
@@ -366,10 +375,13 @@ export const escapeStream = (
       const second = decodedAt(line, i + first.length, ended)
       if (second === "unfinished") return hold(i)
       let shape = second?.char === "@"
+      // Where the text that makes it a shape ends.
+      let decided = i + first.length + (second?.length ?? 0)
       if (second?.char === "!") {
-        const third = decodedAt(line, i + first.length + second.length, ended)
+        const third = decodedAt(line, decided, ended)
         if (third === "unfinished") return hold(i)
         shape = third !== undefined && third.length === 1 && /[A-Za-z]/.test(third.char)
+        decided += third?.length ?? 0
       }
       if (shape) {
         const token = decodeToken(line, i)
@@ -379,9 +391,13 @@ export const escapeStream = (
           i = token.ends[length - 1]
           continue
         }
-        if (!ended && anyAllowed && !token.text.includes(">") && /^<(@|!)?[\w^|]*$/.test(token.text)) return hold(i)
-        emit(at, at + first.length)
-        if (at >= offset) out += zeroWidthSpace
+        if (!ended && anyAllowed && unclosedToken.test(token.text)) return hold(i)
+        // A shape an earlier write ended inside, which that write could not see, gets the space at the
+        // start of this one: Slack reads the writes joined.
+        if (lineStart + decided > offset) {
+          emit(at, at + first.length)
+          out += zeroWidthSpace
+        }
         i += first.length
         continue
       }
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 88c98df5d20..dfff46da0af 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -1005,6 +1005,47 @@ describe("nativeStream", () => {
         })
       )
     })
+
+    it.effect("runs again on a stop sent after one interrupted during it", () => {
+      const fake = makeFake({
+        "chat.startStream": posted(ts),
+        "chat.stopStream": [{ ok: true }, { ok: false, error: "message_not_in_streaming_state" }],
+        "chat.update": [hang, posted(ts)]
+      })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          yield* native.start(replyThread, { markdown: "<@U2>", recipient })
+          const first = yield* Effect.forkChild(native.stop(replyThread, ts, { end: "done" }))
+          yield* TestClock.adjust("1 millis")
+          assert.strictEqual(fake.called("chat.update").length, 1)
+          yield* Fiber.interrupt(first)
+          assert.strictEqual(yield* cleanupOf(native.stop(replyThread, ts, { end: "done" })), "edited")
+          assert.strictEqual(fake.called("chat.update").length, 2)
+        })
+      )
+    })
+
+    it.effect("runs when an append finds the stream stopped by the user, and only once", () => {
+      const fake = makeFake({
+        "chat.startStream": posted(ts),
+        "chat.appendStream": { ok: false, error: "stopped_by_user" },
+        "chat.stopStream": { ok: false, error: "message_not_in_streaming_state" }
+      })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          yield* native.start(replyThread, { markdown: "a <@U2>", recipient })
+          const appended = yield* cleanupOf(native.append(replyThread, ts, " b", { flush: true }))
+          assert.strictEqual(appended, "edited")
+          assert.deepStrictEqual(updates(fake)[0].blocks, [{ type: "markdown", text: "a <@U2>" }])
+          assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: true })
+          assert.strictEqual(fake.called("chat.update").length, 1)
+        })
+      )
+    })
   })
 
   it.effect("holds a trailing high surrogate and sends any other lone surrogate as U+FFFD", () => {
diff --git a/packages/chat/slack/test/live.test.ts b/packages/chat/slack/test/live.test.ts
index c5410086555..1565e6e8ef7 100644
--- a/packages/chat/slack/test/live.test.ts
+++ b/packages/chat/slack/test/live.test.ts
@@ -96,10 +96,11 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
  * It is a proxy: Slack decides a mention from the stored `text`, which was
  * checked against one client's Activity feed (EFF-3730, EFF-3736). It also
  * makes a file post and a file-only post, and asserts each holds its file
- * after the attach. It streams token shapes split at every position across
- * two appends, and asserts that no token is stored and no U+200B is left once
- * the stream is stopped. The stream needs a recipient, the identity of
- * `SLACK_LIVE_USER_TOKEN`. The same assertions run in CI on the request
+ * after the attach. It streams token shapes split at every position, across
+ * two appends and across the start and an append. It reads each stream back
+ * while it is open and asserts it holds no token that isn't allowed, and,
+ * split across appends, every allowed one. Once stopped, no U+200B is left.
+ * The stream needs a recipient, the identity of `SLACK_LIVE_USER_TOKEN`. The same assertions run in CI on the request
  * bodies, in `text.test.ts` and `SlackChat.test.ts`.
  */
 describe.skipIf(botToken === undefined || teamId === undefined || channel === undefined)("live mention rule", () => {
@@ -188,45 +189,75 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
       for (const file of fileIds) yield* api.call("files.delete", { file }, { write: true }).pipe(Effect.ignore)
     }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)), 600_000)
 
-  it.live("no token is stored and no U+200B is left by a stream split at every position", () =>
-    Effect.gen(function*() {
-      if (userToken === undefined) return yield* Effect.die(new Error("SLACK_LIVE_USER_TOKEN is not set"))
-      const api = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) })
-      const self = field(yield* api.call("auth.test", {}), "user_id") as string
-      const user = yield* SlackWebApi.make({ botToken: Redacted.make(userToken) })
-      const recipient = field(yield* user.call("auth.test", {}), "user_id") as string
-      const slack = yield* adapter
-      const native = slack.nativeStream!
-      const root = yield* slack.post(SlackChat.thread({ team: teamId!, channel: channel! }), { markdown: "streams" })
-      const thread = SlackChat.thread({ team: teamId!, channel: channel!, threadTs: root.id })
-      const stored = (ts: string) =>
-        api.call("conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 2 }).pipe(
-          Effect.map((answer) => (field(answer, "messages") as Array).find((message) => message.ts === ts))
-        )
-      const inputs = [
-        `<@${self}>`,
-        `<@${self}>`,
-        `<@${self}>`,
-        `<!here>`,
-        `\`\``,
-        // Without the semicolon nothing decodes.
-        `<@${self}> <@${self}>`
-      ]
-      const streamed = Effect.fnUntraced(function*(markdown: string, at: number) {
-        const label = `${JSON.stringify(markdown)} at ${at}`
-        const first = markdown.slice(0, at)
-        const started = yield* native.start(thread, { markdown: "s ", recipient })
-        const { held } = yield* native.append(thread, started.id, first, undefined)
-        yield* native.append(thread, started.id, first.slice(first.length - held) + markdown.slice(at), { flush: true })
-        yield* native.stop(thread, started.id, { end: "done" })
-        const message = yield* stored(started.id)
-        assert.deepStrictEqual(message.text.match(token), null, label)
-        assert.notInclude(JSON.stringify([message.text, message.blocks]), "\u200B", label)
-        yield* slack.delete(thread, started.id).pipe(Effect.ignore)
-      })
-      for (const markdown of inputs) {
-        for (let at = 0; at <= markdown.length; at++) yield* streamed(markdown, at)
-      }
-      yield* slack.delete(thread, root.id).pipe(Effect.ignore)
-    }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)), 3_600_000)
+  it.live(
+    "a stream split at every position stores only allowed tokens and leaves no U+200B",
+    () =>
+      Effect.gen(function*() {
+        if (userToken === undefined) return yield* Effect.die(new Error("SLACK_LIVE_USER_TOKEN is not set"))
+        const api = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) })
+        const self = field(yield* api.call("auth.test", {}), "user_id") as string
+        const user = yield* SlackWebApi.make({ botToken: Redacted.make(userToken) })
+        const recipient = field(yield* user.call("auth.test", {}), "user_id") as string
+        const slack = yield* adapter
+        const native = slack.nativeStream!
+        const root = yield* slack.post(SlackChat.thread({ team: teamId!, channel: channel! }), { markdown: "streams" })
+        const thread = SlackChat.thread({ team: teamId!, channel: channel!, threadTs: root.id })
+        const stored = (ts: string) =>
+          api.call("conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 2 }).pipe(
+            Effect.map((answer) => (field(answer, "messages") as Array).find((message) => message.ts === ts))
+          )
+        const none: ReadonlyArray = []
+        const inputs: ReadonlyArray]> = [
+          [`<@${self}>`, none],
+          [`<@${self}>`, [self]],
+          [`<@${self}|hello world>`, [self]],
+          [`<@${self}>`, none],
+          [`<@${self}>`, none],
+          [`<!here>`, none],
+          [`<@${self}>`, none],
+          [`<@${self}>`, none],
+          [`\`\``, none],
+          // Without the semicolon nothing decodes.
+          [`<@${self}> <@${self}>`, none]
+        ]
+        const tokens = (text: string) => text.match(token) ?? []
+        const streamed = Effect.fnUntraced(function*(
+          markdown: string,
+          users: ReadonlyArray,
+          at: number,
+          across: "appends" | "start"
+        ) {
+          const label = `${JSON.stringify(markdown)} at ${at} across ${across} allowing ${users}`
+          const allowed = (found: string) => users.some((id) => found.startsWith(`<@${id}`))
+          const first = markdown.slice(0, at)
+          let id: string
+          if (across === "start") {
+            id = (yield* native.start(thread, { markdown: "s " + first, recipient })).id
+            yield* native.append(thread, id, markdown.slice(at), { flush: true })
+          } else {
+            id = (yield* native.start(thread, { markdown: "s ", recipient })).id
+            const { held } = yield* native.append(thread, id, first, undefined)
+            yield* native.append(thread, id, first.slice(first.length - held) + markdown.slice(at), { flush: true })
+          }
+          // What the stream stored, which is what Slack decided mentions from.
+          const open = (yield* stored(id)).text as string
+          assert.deepStrictEqual(tokens(open).filter((found) => !allowed(found)), [], label)
+          // Held text keeps an allowed token whole. The start holds nothing, so it may break one.
+          if (across === "appends") assert.strictEqual(tokens(open).length, users.length, label)
+          yield* native.stop(thread, id, { end: "done" })
+          const message = yield* stored(id)
+          assert.deepStrictEqual(tokens(message.text).filter((found) => !allowed(found)), [], label)
+          assert.notInclude(JSON.stringify([message.text, message.blocks]), "\u200B", label)
+          yield* slack.delete(thread, id).pipe(Effect.ignore)
+        }, (effect, _markdown, users) => SlackChat.withPostOptions({ notify: { users } })(effect))
+        for (const [markdown, users] of inputs) {
+          for (let at = 0; at <= markdown.length; at++) {
+            yield* streamed(markdown, users, at, "appends")
+            yield* streamed(markdown, users, at, "start")
+          }
+        }
+        yield* slack.delete(thread, root.id).pipe(Effect.ignore)
+      }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)),
+    3_600_000
+  )
 })
diff --git a/packages/chat/slack/test/text.test.ts b/packages/chat/slack/test/text.test.ts
index 9cf1cfd7536..579ea009c7a 100644
--- a/packages/chat/slack/test/text.test.ts
+++ b/packages/chat/slack/test/text.test.ts
@@ -157,10 +157,11 @@ describe("request bodies", () => {
 
 /**
  * The CI half of the Slack mention rule for a stream: every input split at
- * every position across two appends, with the held tail sent again as the
- * layer does. Slack joins a reference split across appends, so the check is
- * on what the appends add up to, decoded. Forms without a semicolon decode to
- * nothing, so they must give no token.
+ * every position, across two appends with the held tail sent again as the
+ * layer does, and across the start and an append, where nothing is held.
+ * Slack joins a reference split across writes, so the check is on what the
+ * writes add up to, decoded. Forms without a semicolon decode to nothing, so
+ * they must give no token.
  */
 describe("stream bodies", () => {
   const thread = SlackChat.thread({ team, channel, threadTs: "1794509110.999799" })
@@ -171,48 +172,69 @@ describe("stream bodies", () => {
       /&(?:excl|#0*33|#[xX]0*21);/g,
       "!"
     )
+  const tokens = (text: string) => decode(text).match(token) ?? []
   const alphabet = ["<", "<", "&l", "t;", "<", "@U1", "@", "!", "here", "`", "\n", "x", ">", "👍🏽"]
   const words = (length: number): Array =>
     length === 0 ? [""] : words(length - 1).flatMap((word) => alphabet.map((piece) => word + piece))
+  /** Whole tokens, which the generated words are too short to spell. */
+  const seeds = [
+    "<@U1>",
+    "",
+    "<@U1>",
+    "<@U1>",
+    "<!here>",
+    "`<@U1>`",
+    "<@U1>",
+    "<@U1>",
+    "<@U1|hello world>",
+    "<@U1> <@U1>"
+  ]
 
   it.effect("hold the mention rule at every split, and leave no U+200B after the stream", () => {
     let count = 0
     // A new message for each stream, so the edit pacing never waits.
-    const fake = makeFake({ "chat.startStream": () => ({ ok: true, channel, ts: `1.${count}` }) })
+    const fake = makeFake({ "chat.startStream": () => ({ ok: true, channel, ts: `1.${count++}` }) })
     return Effect.gen(function*() {
       const native = (yield* adapter).nativeStream!
       let cleaned = 0
       for (const notify of [{}, { users: ["U1"] }] as ReadonlyArray) {
-        const allowed = notify.users === undefined ? [] : ["<@U1>"]
-        for (const word of [1, 2].flatMap(words)) {
+        const allowed = (found: string) => notify.users !== undefined && /^<@U1[|>]/.test(found)
+        for (const word of [...seeds, ...[1, 2].flatMap(words)]) {
           for (let at = 0; at <= word.length; at++) {
-            const label = `${JSON.stringify(word)} at ${at} ${JSON.stringify(notify)}`
-            const before = fake.calls.length
-            const first = word.slice(0, at)
-            yield* Effect.gen(function*() {
-              const { id: ts } = yield* native.start(thread, { markdown: "s ", recipient: "U080YLYB277" })
-              const { held } = yield* native.append(thread, ts, first, undefined)
-              yield* native.append(thread, ts, first.slice(first.length - held) + word.slice(at), { flush: true })
-              yield* native.stop(thread, ts, { end: "done" })
-            }).pipe(SlackChat.withPostOptions({ notify }))
-            const calls = fake.calls.slice(before)
-            const streamed = calls.filter((call) => call.method !== "chat.update" && call.params.markdown_text)
-              .map((call) => call.params.markdown_text).join("")
-            // However it is split, the stream sends the same.
-            assert.strictEqual(streamed, Escape.escapeStream("s " + word, notify, { flush: true }).sent, label)
-            let rest = decode(streamed)
-            for (const allowedToken of allowed) rest = rest.replaceAll(allowedToken, "")
-            assert.deepStrictEqual(rest.match(token), null, label)
-            const update = calls.find((call) => call.method === "chat.update")
-            const left = update === undefined ? streamed : update.params.blocks + update.params.text
-            assert.notInclude(left, "\u200B", label)
-            if (update !== undefined) cleaned++
-            count++
+            for (const across of ["appends", "start"] as const) {
+              const label = `${JSON.stringify(word)} at ${at} across ${across} ${JSON.stringify(notify)}`
+              const before = fake.calls.length
+              const first = word.slice(0, at)
+              yield* Effect.gen(function*() {
+                if (across === "start") {
+                  const { id: ts } = yield* native.start(thread, { markdown: "s " + first, recipient: "U080YLYB277" })
+                  yield* native.append(thread, ts, word.slice(at), { flush: true })
+                  return yield* native.stop(thread, ts, { end: "done" })
+                }
+                const { id: ts } = yield* native.start(thread, { markdown: "s ", recipient: "U080YLYB277" })
+                const { held } = yield* native.append(thread, ts, first, undefined)
+                yield* native.append(thread, ts, first.slice(first.length - held) + word.slice(at), { flush: true })
+                yield* native.stop(thread, ts, { end: "done" })
+              }).pipe(SlackChat.withPostOptions({ notify }))
+              const calls = fake.calls.slice(before)
+              const streamed = calls.filter((call) => call.method !== "chat.update" && call.params.markdown_text)
+                .map((call) => call.params.markdown_text).join("")
+              if (across === "appends") {
+                // Held text keeps every allowed token whole, and nothing else.
+                assert.deepStrictEqual(tokens(streamed), tokens("s " + word).filter(allowed), label)
+              } else {
+                // The start holds nothing, so it may break an allowed token, but never makes one.
+                assert.deepStrictEqual(tokens(streamed).filter((found) => !allowed(found)), [], label)
+              }
+              const update = calls.find((call) => call.method === "chat.update")
+              const left = update === undefined ? streamed : update.params.blocks + update.params.text
+              assert.notInclude(left, "\u200B", label)
+              if (update !== undefined) cleaned++
+            }
           }
         }
       }
-      assert.strictEqual(count, 2 * [1, 2].flatMap(words).reduce((sum, word) => sum + word.length + 1, 0))
       assert.isAbove(cleaned, 0)
     }).pipe(Effect.provide(slackLayer(fake)))
-  }, 60_000)
+  }, 120_000)
 })

From 2c3b82fcd8d54ae4444f2fa197b0b7408ca4c5fa Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 10:33:47 +0000
Subject: [PATCH 36/89] Set the Slack agent session status when an append finds
 the stream stopped by the user

The layer sends no stop after a stopped append, so the session stayed on
processing. The append now sets sessionStatusAtEnd, and a stop sent after
it doesn't set it again.

Closes EFF-3753
---
 packages/chat/slack/src/internal/adapter.ts | 11 +++++++++--
 packages/chat/slack/test/SlackChat.test.ts  | 18 ++++++++++--------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index d4239e694df..2682bb27019 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -674,12 +674,18 @@ export const make = (options: {
               return { state: "closed" as const, held: 0 }
             })
         ),
-        // Slack closed the stream, and the layer sends no stop after this, so the cleanup runs here.
+        // Slack closed the stream and the reply ends stopped. The layer sends no stop after this, so the
+        // cleanup and the session status go here.
         Effect.catchIf(
           hasDetail("stopped_by_user"),
           () =>
             Effect.sync(() => streams.set(messageId, { ...state, stopped: true })).pipe(
               Effect.andThen(cleanup(op, parts.channel, messageId, postOptions.notify ?? {})),
+              Effect.andThen(
+                parts.threadTs === undefined
+                  ? Effect.void
+                  : sessionStatus(parts.channel, parts.threadTs, postOptions.sessionStatusAtEnd ?? "active")
+              ),
               Effect.as({ state: "stopped" as const, held: 0 })
             )
         ),
@@ -723,7 +729,8 @@ export const make = (options: {
       yield* cleanup(op, parts.channel, messageId, postOptions.notify ?? {})
       // Kept until now, so a stop sent again after a cut-off one still cleans up.
       streams.delete(messageId)
-      if (stopped && stopOptions.end === "done" && parts.threadTs !== undefined) {
+      // An append that found the stream stopped has set the session status already.
+      if (stopped && state?.stopped !== true && stopOptions.end === "done" && parts.threadTs !== undefined) {
         yield* sessionStatus(parts.channel, parts.threadTs, postOptions.sessionStatusAtEnd ?? "active")
       }
       return { stopped }
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index dfff46da0af..1744c022c9f 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -709,20 +709,22 @@ describe("nativeStream", () => {
           state: "closed",
           held: 0
         })
-        assert.deepStrictEqual(yield* native.append(replyThread, ts, "d", { flush: true }), {
+        const suspended = SlackChat.withPostOptions({ sessionStatusAtEnd: "suspended" })
+        assert.deepStrictEqual(yield* native.append(replyThread, ts, "d", { flush: true }).pipe(suspended), {
           state: "stopped",
           held: 0
         })
-        const result = yield* native.stop(replyThread, ts, { end: "done" }).pipe(
-          SlackChat.withPostOptions({ sessionStatusAtEnd: "suspended" })
-        )
-        assert.deepStrictEqual(result, { stopped: true })
-        assert.strictEqual(fake.called("chat.stopStream")[0].params.session_status, "suspended")
-        assert.deepStrictEqual(fake.called("agents.sessions.setStatus")[0].params, {
+        // The layer sends no stop after a stopped append, so the append moves the session off processing.
+        assert.deepStrictEqual(fake.called("agents.sessions.setStatus").map((call) => call.params), [{
           channel_id: channel,
           thread_ts: root,
           status: "suspended"
-        })
+        }])
+        // A caller that stops anyway gets stopped, and the status isn't set twice.
+        const result = yield* native.stop(replyThread, ts, { end: "done" }).pipe(suspended)
+        assert.deepStrictEqual(result, { stopped: true })
+        assert.strictEqual(fake.called("chat.stopStream")[0].params.session_status, "suspended")
+        assert.strictEqual(fake.called("agents.sessions.setStatus").length, 1)
       })
     )
   })

From f36224f70b91cc1472986bf86ba0b70abaf56c41 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 11:05:14 +0000
Subject: [PATCH 37/89] Let the live Slack stream case run without a user token

SLACK_LIVE_RECIPIENT names the stream's recipient when
SLACK_LIVE_USER_TOKEN is not set. The case waits out Slack's
retry-after on a 429 and deletes each stream and the root even when it
fails.

Closes EFF-3753
---
 packages/chat/slack/test/live.test.ts | 63 +++++++++++++++++++--------
 1 file changed, 46 insertions(+), 17 deletions(-)

diff --git a/packages/chat/slack/test/live.test.ts b/packages/chat/slack/test/live.test.ts
index 1565e6e8ef7..2f52bc5c989 100644
--- a/packages/chat/slack/test/live.test.ts
+++ b/packages/chat/slack/test/live.test.ts
@@ -7,14 +7,18 @@
  * - `SLACK_LIVE_USER_TOKEN`: a user token with `chat:write` and
  *   `channels:history`, for the rules that need another identity's
  *   message. Without it those rules fail at `userPosts`.
+ * - `SLACK_LIVE_RECIPIENT`: a user id in the channel, the recipient of the
+ *   mention rule's streams when `SLACK_LIVE_USER_TOKEN` is not set.
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import * as SlackWebApi from "@effect/chat-slack/SlackWebApi"
 import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
+import type { ChatError } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { conformance } from "effect/chat/ChatTest"
 import type * as ChatThread from "effect/chat/ChatThread"
+import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as FetchHttpClient from "effect/http/FetchHttpClient"
 import * as Layer from "effect/Layer"
@@ -26,6 +30,18 @@ const botToken = process.env.SLACK_LIVE_BOT_TOKEN
 const userToken = process.env.SLACK_LIVE_USER_TOKEN
 const teamId = process.env.SLACK_LIVE_TEAM_ID
 const channel = process.env.SLACK_LIVE_CHANNEL
+const recipientId = process.env.SLACK_LIVE_RECIPIENT
+
+/** Runs a write again after Slack's retry-after, for the rules that make many. */
+const retrying = (effect: Effect.Effect): Effect.Effect =>
+  effect.pipe(Effect.catchIf(
+    (error) => error.reason._tag === "RateLimited",
+    (error) =>
+      Effect.andThen(
+        Effect.sleep(error.reason._tag === "RateLimited" ? error.reason.retryAfter ?? Duration.seconds(30) : 0),
+        retrying(effect)
+      )
+  ))
 
 const field = (u: unknown, key: string): any =>
   typeof u === "object" && u !== null && !Array.isArray(u) ? (u as Record)[key] : undefined
@@ -100,7 +116,8 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
  * two appends and across the start and an append. It reads each stream back
  * while it is open and asserts it holds no token that isn't allowed, and,
  * split across appends, every allowed one. Once stopped, no U+200B is left.
- * The stream needs a recipient, the identity of `SLACK_LIVE_USER_TOKEN`. The same assertions run in CI on the request
+ * The stream needs a recipient, the identity of `SLACK_LIVE_USER_TOKEN` or
+ * `SLACK_LIVE_RECIPIENT`. The same assertions run in CI on the request
  * bodies, in `text.test.ts` and `SlackChat.test.ts`.
  */
 describe.skipIf(botToken === undefined || teamId === undefined || channel === undefined)("live mention rule", () => {
@@ -193,14 +210,24 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
     "a stream split at every position stores only allowed tokens and leaves no U+200B",
     () =>
       Effect.gen(function*() {
-        if (userToken === undefined) return yield* Effect.die(new Error("SLACK_LIVE_USER_TOKEN is not set"))
         const api = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) })
         const self = field(yield* api.call("auth.test", {}), "user_id") as string
-        const user = yield* SlackWebApi.make({ botToken: Redacted.make(userToken) })
-        const recipient = field(yield* user.call("auth.test", {}), "user_id") as string
+        const recipient = userToken === undefined
+          ? recipientId
+          : field(
+            yield* (yield* SlackWebApi.make({ botToken: Redacted.make(userToken) })).call("auth.test", {}),
+            "user_id"
+          )
+        if (recipient === undefined) {
+          return yield* Effect.die(new Error("set SLACK_LIVE_USER_TOKEN or SLACK_LIVE_RECIPIENT"))
+        }
         const slack = yield* adapter
         const native = slack.nativeStream!
-        const root = yield* slack.post(SlackChat.thread({ team: teamId!, channel: channel! }), { markdown: "streams" })
+        const root = yield* Effect.acquireRelease(
+          slack.post(SlackChat.thread({ team: teamId!, channel: channel! }), { markdown: "streams" }),
+          (root) =>
+            retrying(slack.delete(SlackChat.thread({ team: teamId!, channel: channel! }), root.id)).pipe(Effect.ignore)
+        )
         const thread = SlackChat.thread({ team: teamId!, channel: channel!, threadTs: root.id })
         const stored = (ts: string) =>
           api.call("conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 2 }).pipe(
@@ -230,34 +257,36 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
           const label = `${JSON.stringify(markdown)} at ${at} across ${across} allowing ${users}`
           const allowed = (found: string) => users.some((id) => found.startsWith(`<@${id}`))
           const first = markdown.slice(0, at)
-          let id: string
+          const { id } = yield* Effect.acquireRelease(
+            retrying(native.start(thread, { markdown: across === "start" ? "s " + first : "s ", recipient })),
+            ({ id }) => retrying(slack.delete(thread, id)).pipe(Effect.ignore)
+          )
           if (across === "start") {
-            id = (yield* native.start(thread, { markdown: "s " + first, recipient })).id
-            yield* native.append(thread, id, markdown.slice(at), { flush: true })
+            yield* retrying(native.append(thread, id, markdown.slice(at), { flush: true }))
           } else {
-            id = (yield* native.start(thread, { markdown: "s ", recipient })).id
-            const { held } = yield* native.append(thread, id, first, undefined)
-            yield* native.append(thread, id, first.slice(first.length - held) + markdown.slice(at), { flush: true })
+            const { held } = yield* retrying(native.append(thread, id, first, undefined))
+            yield* retrying(
+              native.append(thread, id, first.slice(first.length - held) + markdown.slice(at), { flush: true })
+            )
           }
           // What the stream stored, which is what Slack decided mentions from.
           const open = (yield* stored(id)).text as string
           assert.deepStrictEqual(tokens(open).filter((found) => !allowed(found)), [], label)
           // Held text keeps an allowed token whole. The start holds nothing, so it may break one.
           if (across === "appends") assert.strictEqual(tokens(open).length, users.length, label)
-          yield* native.stop(thread, id, { end: "done" })
+          yield* retrying(native.stop(thread, id, { end: "done" }))
           const message = yield* stored(id)
           assert.deepStrictEqual(tokens(message.text).filter((found) => !allowed(found)), [], label)
           assert.notInclude(JSON.stringify([message.text, message.blocks]), "\u200B", label)
-          yield* slack.delete(thread, id).pipe(Effect.ignore)
-        }, (effect, _markdown, users) => SlackChat.withPostOptions({ notify: { users } })(effect))
+        }, (effect, _markdown, users) =>
+          SlackChat.withPostOptions({ notify: { users } })(effect), Effect.scoped)
         for (const [markdown, users] of inputs) {
           for (let at = 0; at <= markdown.length; at++) {
             yield* streamed(markdown, users, at, "appends")
             yield* streamed(markdown, users, at, "start")
           }
         }
-        yield* slack.delete(thread, root.id).pipe(Effect.ignore)
-      }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)),
-    3_600_000
+      }).pipe(Effect.scoped, Effect.provide(layer), Effect.provide(FetchHttpClient.layer)),
+    7_200_000
   )
 })

From aab5fffde27e6cf33d998e9e1943ee61db418314 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 11:20:54 +0000
Subject: [PATCH 38/89] Keep the Slack session status pending until it is set

A stopped append saved stopped before its cleanup and session status, and
the stop took that flag as proof the status was set. An append cut off
during its cleanup left the session on processing. The status now has its
own flag, set after the call, and a stop remembers a user stop Slack
reported and keeps the stream state until the status is set, so a stop
sent again finishes it.

Closes EFF-3753
---
 packages/chat/slack/src/internal/adapter.ts | 56 +++++++++++++++++----
 packages/chat/slack/test/SlackChat.test.ts  | 55 ++++++++++++++++++--
 2 files changed, 97 insertions(+), 14 deletions(-)

diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 2682bb27019..77ad8fd9766 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -143,6 +143,8 @@ interface StreamState {
   readonly settled: boolean
   /** Whether the cleanup edit has run or been skipped. */
   readonly cleaned: boolean
+  /** Whether the session status at the end has been set, for a stream stopped by the user. */
+  readonly ended: boolean
 }
 
 /**
@@ -568,6 +570,28 @@ export const make = (options: {
     yield* Effect.annotateCurrentSpan("slack.stream.cleanup", Result.isSuccess(edited) ? "edited" : "failed")
   })
 
+  /**
+   * Moves the agent session of a stopped stream off `processing`, once. It is
+   * marked only after the call, so an interrupted one runs again on the stop
+   * the layer's finaliser sends.
+   */
+  const endSession = (
+    channel: string,
+    threadTs: string | undefined,
+    messageId: string,
+    status: SessionStatus
+  ): Effect.Effect =>
+    Effect.suspend(() => {
+      if (threadTs === undefined || streams.get(messageId)?.ended === true) return Effect.void
+      return Effect.andThen(
+        sessionStatus(channel, threadTs, status),
+        Effect.sync(() => {
+          const state = streams.get(messageId)
+          if (state !== undefined) streams.set(messageId, { ...state, ended: true })
+        })
+      )
+    })
+
   const cleanup = (op: string, channel: string, messageId: string, notify: Escape.Notify): Effect.Effect =>
     Effect.suspend(() => {
       const state = streams.get(messageId)
@@ -624,7 +648,8 @@ export const make = (options: {
         sent,
         stopped: false,
         settled: true,
-        cleaned: false
+        cleaned: false,
+        ended: false
       })
       return { id: ts, thread, timestamp: Normalize.timestamp(ts) }
     }),
@@ -633,7 +658,15 @@ export const make = (options: {
       const parts = yield* resolve(op, thread)
       const postOptions = yield* CurrentPostOptions
       const state = streams.get(messageId) ??
-        { escape: Escape.initialState, markdown: "", sent: "", stopped: false, settled: true, cleaned: false }
+        {
+          escape: Escape.initialState,
+          markdown: "",
+          sent: "",
+          stopped: false,
+          settled: true,
+          cleaned: false,
+          ended: false
+        }
       const flush = appendOptions?.flush === true
       // A trailing high surrogate waits for its other half.
       const input = !flush && /[\ud800-\udbff]$/.test(markdown) ? markdown.slice(0, -1) : markdown
@@ -661,7 +694,8 @@ export const make = (options: {
             sent: state.sent + sent,
             stopped: false,
             settled: true,
-            cleaned: false
+            cleaned: false,
+            ended: false
           })
           return { state: "open" as const, held }
         }),
@@ -682,9 +716,7 @@ export const make = (options: {
             Effect.sync(() => streams.set(messageId, { ...state, stopped: true })).pipe(
               Effect.andThen(cleanup(op, parts.channel, messageId, postOptions.notify ?? {})),
               Effect.andThen(
-                parts.threadTs === undefined
-                  ? Effect.void
-                  : sessionStatus(parts.channel, parts.threadTs, postOptions.sessionStatusAtEnd ?? "active")
+                endSession(parts.channel, parts.threadTs, messageId, postOptions.sessionStatusAtEnd ?? "active")
               ),
               Effect.as({ state: "stopped" as const, held: 0 })
             )
@@ -726,13 +758,15 @@ export const make = (options: {
       const result = Option.isSome(answer) && isObject(answer.value) ? answer.value.result_status : undefined
       const stopped = state?.stopped === true || result === "stopped_by_user" ||
         (context !== undefined && context.result_status === "stopped_by_user")
+      // Remembered, so a stop sent again after a cut-off one, which Slack answers as not streaming, still ends the session.
+      const current = streams.get(messageId)
+      if (stopped && current !== undefined) streams.set(messageId, { ...current, stopped: true })
       yield* cleanup(op, parts.channel, messageId, postOptions.notify ?? {})
-      // Kept until now, so a stop sent again after a cut-off one still cleans up.
-      streams.delete(messageId)
-      // An append that found the stream stopped has set the session status already.
-      if (stopped && state?.stopped !== true && stopOptions.end === "done" && parts.threadTs !== undefined) {
-        yield* sessionStatus(parts.channel, parts.threadTs, postOptions.sessionStatusAtEnd ?? "active")
+      if (stopped && stopOptions.end === "done") {
+        yield* endSession(parts.channel, parts.threadTs, messageId, postOptions.sessionStatusAtEnd ?? "active")
       }
+      // Kept until now, so a stop sent again after a cut-off one still cleans up and ends the session.
+      streams.delete(messageId)
       return { stopped }
     })
   }
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 1744c022c9f..66ecbcf39ae 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -1011,8 +1011,12 @@ describe("nativeStream", () => {
     it.effect("runs again on a stop sent after one interrupted during it", () => {
       const fake = makeFake({
         "chat.startStream": posted(ts),
-        "chat.stopStream": [{ ok: true }, { ok: false, error: "message_not_in_streaming_state" }],
-        "chat.update": [hang, posted(ts)]
+        "chat.stopStream": [{ ok: true, result_status: "stopped_by_user" }, {
+          ok: false,
+          error: "message_not_in_streaming_state"
+        }],
+        "chat.update": [hang, posted(ts)],
+        "agents.sessions.setStatus": { ok: true }
       })
       return run(
         fake,
@@ -1023,8 +1027,15 @@ describe("nativeStream", () => {
           yield* TestClock.adjust("1 millis")
           assert.strictEqual(fake.called("chat.update").length, 1)
           yield* Fiber.interrupt(first)
-          assert.strictEqual(yield* cleanupOf(native.stop(replyThread, ts, { end: "done" })), "edited")
+          // Slack answers this one as not streaming, so the user's stop is known from the first.
+          let result: { readonly stopped: boolean } | undefined
+          const cleanup = yield* cleanupOf(
+            Effect.map(native.stop(replyThread, ts, { end: "done" }), (stopped) => (result = stopped))
+          )
+          assert.strictEqual(cleanup, "edited")
           assert.strictEqual(fake.called("chat.update").length, 2)
+          assert.deepStrictEqual(result, { stopped: true })
+          assert.strictEqual(fake.called("agents.sessions.setStatus").length, 1)
         })
       )
     })
@@ -1048,6 +1059,44 @@ describe("nativeStream", () => {
         })
       )
     })
+
+    it.effect("runs, with the session status, on the stops after that append is cut off", () => {
+      const fake = makeFake({
+        "chat.startStream": posted(ts),
+        "chat.appendStream": { ok: false, error: "stopped_by_user" },
+        "chat.stopStream": { ok: false, error: "message_not_in_streaming_state" },
+        "chat.update": [hang, posted(ts)],
+        "agents.sessions.setStatus": [hang, { ok: true }]
+      })
+      return run(
+        fake,
+        Effect.gen(function*() {
+          const native = (yield* adapter).nativeStream!
+          yield* native.start(replyThread, { markdown: "a <@U2>", recipient })
+          // Cut off during the cleanup.
+          const appended = yield* Effect.forkChild(native.append(replyThread, ts, " b", { flush: true }))
+          yield* TestClock.adjust("1 millis")
+          yield* Fiber.interrupt(appended)
+          assert.strictEqual(fake.called("chat.update").length, 1)
+          assert.strictEqual(fake.called("agents.sessions.setStatus").length, 0)
+          // The finaliser's stop, cut off during the session status.
+          const stopping = yield* Effect.forkChild(native.stop(replyThread, ts, { end: "done" }))
+          yield* TestClock.adjust("1 millis")
+          yield* Fiber.interrupt(stopping)
+          assert.strictEqual(fake.called("chat.update").length, 2)
+          assert.strictEqual(fake.called("agents.sessions.setStatus").length, 1)
+          assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: true })
+          assert.deepStrictEqual(fake.called("agents.sessions.setStatus").map((call) => call.params), [
+            { channel_id: channel, thread_ts: root, status: "active" },
+            { channel_id: channel, thread_ts: root, status: "active" }
+          ])
+          // A stop sent again sets it no third time.
+          yield* native.stop(replyThread, ts, { end: "done" })
+          assert.strictEqual(fake.called("agents.sessions.setStatus").length, 2)
+          assert.strictEqual(fake.called("chat.update").length, 2)
+        })
+      )
+    })
   })
 
   it.effect("holds a trailing high surrogate and sends any other lone surrogate as U+FFFD", () => {

From 469bec70189e24f1e19aca56b708af2440d89d8b Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 11:46:47 +0000
Subject: [PATCH 39/89] chat-slack: buttons, selects and modals

Elements go in one actions block after the markdown block on post, edit and the files route. SlackChat.interaction, layerInteractivity and normalizeInteraction handle block_actions and view_submission, open modals with views.open and answer a late submit with 503. measure counts the actions block with the EFF-3738 cost model, tested over the 38 measured rows. Closes EFF-3754.
---
 .changeset/chat-adapters-actions.md           |   5 -
 .changeset/chat-slack.md                      |   2 +-
 packages/chat/slack/src/SlackChat.ts          | 120 +++++-
 packages/chat/slack/src/internal/actions.ts   | 202 ++++++++++
 packages/chat/slack/src/internal/adapter.ts   |  41 +-
 packages/chat/slack/src/internal/emoji.ts     |  21 +
 .../chat/slack/src/internal/interactions.ts   | 359 ++++++++++++++++++
 packages/chat/slack/src/internal/length.ts    |  15 +-
 packages/chat/slack/src/internal/text.ts      |  45 ++-
 packages/chat/slack/src/internal/webhook.ts   |  50 +++
 packages/chat/slack/test/SlackChat.test.ts    | 106 +++++-
 packages/chat/slack/test/actions.test.ts      | 102 +++++
 packages/chat/slack/test/conformance.test.ts  |  45 +++
 .../test/fixtures/recorded/interactivity.json | 244 ++++++++++++
 packages/chat/slack/test/interactions.test.ts | 273 +++++++++++++
 packages/chat/slack/test/slack.ts             | 144 +++++++
 16 files changed, 1722 insertions(+), 52 deletions(-)
 delete mode 100644 .changeset/chat-adapters-actions.md
 create mode 100644 packages/chat/slack/src/internal/actions.ts
 create mode 100644 packages/chat/slack/src/internal/interactions.ts
 create mode 100644 packages/chat/slack/test/actions.test.ts
 create mode 100644 packages/chat/slack/test/conformance.test.ts
 create mode 100644 packages/chat/slack/test/fixtures/recorded/interactivity.json
 create mode 100644 packages/chat/slack/test/interactions.test.ts
 create mode 100644 packages/chat/slack/test/slack.ts

diff --git a/.changeset/chat-adapters-actions.md b/.changeset/chat-adapters-actions.md
deleted file mode 100644
index 72776167fdf..00000000000
--- a/.changeset/chat-adapters-actions.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-"@effect/chat-slack": patch
----
-
-Refuse a post or edit that carries buttons or selects with `Unsupported` instead of posting it without them, until the adapter supports them.
diff --git a/.changeset/chat-slack.md b/.changeset/chat-slack.md
index 144c8ea59ca..503c9150da0 100644
--- a/.changeset/chat-slack.md
+++ b/.changeset/chat-slack.md
@@ -3,4 +3,4 @@
 "effect": patch
 ---
 
-Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook, native streaming replies, the agent stop button and all-or-nothing posts with files. Add the `StopRequested` chat event.
+Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook, native streaming replies, the agent stop button, all-or-nothing posts with files, and buttons, selects and modals through `layerInteractivity` or `SlackChat.interaction`. Add the `StopRequested` chat event.
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index be6676c41c6..83f3abcc51f 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -1,6 +1,7 @@
 /**
  * The Slack adapter for `effect/chat`: the `Registry` layer, the Events API
- * webhook, the pure normaliser, address helpers and the scoped post options.
+ * webhook, the Interactivity route for buttons and modals, the pure
+ * normalisers, address helpers and the scoped post options.
  *
  * **Details**
  *
@@ -11,6 +12,12 @@
  * - Event subscriptions, sent to `layerWebhook`'s path: `message.channels`,
  *   `message.groups`, `message.im`, `message.mpim`, `app_mention`,
  *   `reaction_added`, `reaction_removed` and `agent_session_stopped`.
+ * - Buttons, selects and modals need Interactivity, which is its own
+ *   switch in the app settings, off by default, with its own Request URL,
+ *   separate from Event Subscriptions. Point it at `layerInteractivity`'s
+ *   path. With Socket Mode on, Slack sends interactions over the socket and
+ *   never to the URL: pass each payload to `SlackChat.interaction` and send
+ *   its result as the envelope ack's `payload`.
  * - Slack's stop button also needs the app declared as an agent with
  *   `features.agent_view` in the manifest. Slack documents that declaration
  *   as irreversible. Without it the adapter's session status calls answer
@@ -27,6 +34,7 @@ import { Registry } from "effect/chat/ChatAdapter"
 import { type ChatError, ChatErrorReason } from "effect/chat/ChatError"
 import type { ChatEvent } from "effect/chat/ChatEvent"
 import { ChatHandler } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
 import type { ParseMention } from "effect/chat/ChatTest"
 import { ChatThread } from "effect/chat/ChatThread"
 import * as Context from "effect/Context"
@@ -43,6 +51,7 @@ import * as Adapter from "./internal/adapter.ts"
 import * as Address from "./internal/address.ts"
 import * as Emoji from "./internal/emoji.ts"
 import * as Errors from "./internal/errors.ts"
+import * as Interactions from "./internal/interactions.ts"
 import * as Mentions from "./internal/mentions.ts"
 import * as Normalize from "./internal/normalize.ts"
 import { CurrentPostOptions } from "./internal/options.ts"
@@ -80,6 +89,25 @@ export interface SlackUser {
  * - `botUserId` comes from `auth.test`, read once. A failed read is tried
  *   again next time.
  * - `user` calls `users.info` each time. Nothing is cached.
+ * - `interaction` is the entry for a decoded Interactivity `payload`
+ *   (`block_actions` or `view_submission`), as `DiscordChat.interaction`
+ *   is for Discord. It normalises with `normalizeInteraction`, calls the
+ *   handler through `ChatInteraction.handle` inside `deadline` (2.5
+ *   seconds by default, the handler's share of Slack's 3), opens a modal
+ *   with `views.open` and calls `Handler.refused` when it can't.
+ * - It succeeds with the body to answer Slack with: the JSON of the 200 on
+ *   the Request URL, or the `payload` of the envelope ack on Socket Mode.
+ *   `undefined` is an empty answer: an ack, a close, a late click, or a
+ *   payload that is not from an element this adapter built.
+ * - `Late` is a submit whose handler ran past the deadline and was
+ *   interrupted. It is not an answer, since an empty one would close the
+ *   modal: `layerInteractivity` answers 503 for it, which keeps the modal
+ *   open, and a caller on Socket Mode sends no ack. `Late` is itself a
+ *   JSON value, so test for it with `Schema.is(ChatInteraction.Late)`
+ *   before treating the result as a body.
+ * - `interaction` checks no signature and no app id: that is the
+ *   transport's job. It needs `ChatInteraction.Handler` where it is
+ *   called, so the layer does not need it.
  *
  * @stability unstable
  * @category services
@@ -89,6 +117,10 @@ export class SlackChat extends Context.Service
   readonly user: (id: string) => Effect.Effect
+  readonly interaction: (payload: unknown, options?: {
+    /** The handler's share of Slack's 3 seconds. Default 2.5 seconds. */
+    readonly deadline?: Duration.Duration | undefined
+  }) => Effect.Effect
 }>()("@effect/chat-slack/SlackChat") {}
 
 /**
@@ -162,6 +194,23 @@ export class SlackChat extends Context.Service new SlackAttachFailed(fields)
       })
       yield* registry.register(adapter)
-      return SlackChat.of({ teamId: options.teamId, botUserId, user })
+      const interaction = Interactions.make({ api, teamId: options.teamId })
+      return SlackChat.of({ teamId: options.teamId, botUserId, user, interaction })
     })
   ).pipe(Layer.provideMerge(WebApi.layer({ botToken: options.botToken })))
 
@@ -310,6 +360,72 @@ export const layerWebhook = (options: {
     yield* router.add("POST", options.path, (request) => Webhook.handleRequest(request, webhookOptions))
   }))
 
+/**
+ * `POST {path}`: the Interactivity Request URL, which Slack posts
+ * form-encoded and separately from the Events API.
+ *
+ * **Details**
+ *
+ * - Checks the `v0` signature as `layerWebhook` does, decodes the form's
+ *   `payload` and drops one for another app with a 200.
+ * - Hands the payload to `SlackChat.interaction` with `deadline` (2.5
+ *   seconds by default). Its body is the response, and `Late` is answered
+ *   with a 503, so the modal stays open with Slack's own error. Answers 413
+ *   past `maxBodyBytes` (1 MiB by default).
+ * - Slack never redelivers an interaction, so a click or submit that is not
+ *   answered in time is lost. A user can submit again, as a new request.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layerInteractivity = (options: {
+  readonly path: `/${string}`
+  readonly signingSecret: Redacted.Redacted
+  readonly appId: string
+  readonly deadline?: Duration.Duration | undefined
+  readonly maxBodyBytes?: number | undefined
+}): Layer.Layer =>
+  HttpRouter.use(Effect.fnUntraced(function*(router) {
+    const slack = yield* SlackChat
+    const handler = yield* ChatInteraction.Handler
+    const verify = yield* Webhook.makeVerifier(options.signingSecret)
+    const interactivityOptions: Webhook.InteractivityOptions = {
+      verify,
+      appId: options.appId,
+      interaction: (payload, interactionOptions) =>
+        Effect.provideService(slack.interaction(payload, interactionOptions), ChatInteraction.Handler, handler),
+      deadline: options.deadline ?? Interactions.defaultDeadline,
+      maxBodyBytes: options.maxBodyBytes ?? 1024 * 1024
+    }
+    yield* router.add("POST", options.path, (request) => Webhook.handleInteractivity(request, interactivityOptions))
+  }))
+
+/**
+ * The normaliser behind `SlackChat.interaction`.
+ *
+ * **Details**
+ *
+ * - Pure: takes the decoded `payload` of a `block_actions` or
+ *   `view_submission` request.
+ * - None for any other payload, and for one that is not from an element
+ *   this adapter built: a block of the consumer's own, a link button, or a
+ *   view the adapter did not open.
+ * - A submit's thread and message are those of the click that opened the
+ *   modal, which the adapter packed into `private_metadata` beside the
+ *   consumer's metadata.
+ * - The team in an address is `context.teamId`. `raw` is the payload
+ *   without its verification `token`.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const normalizeInteraction: (
+  payload: unknown,
+  context: { readonly teamId: string }
+) => Option.Option = Interactions.normalize
+
 /**
  * The normaliser, for Socket Mode or a consumer's own transport.
  *
diff --git a/packages/chat/slack/src/internal/actions.ts b/packages/chat/slack/src/internal/actions.ts
new file mode 100644
index 00000000000..86a3667d1e9
--- /dev/null
+++ b/packages/chat/slack/src/internal/actions.ts
@@ -0,0 +1,202 @@
+/**
+ * A message's elements as Slack's `actions` block, and what that block
+ * costs against the 13,200 cap.
+ */
+import type { Action } from "effect/chat/ChatUi"
+import * as Emoji from "./emoji.ts"
+
+/**
+ * The `block_id` of the `actions` block the adapter builds, and so the
+ * mark of a click on one of its own elements. Five ASCII characters, the
+ * length of the id Slack generates, which `cost` charges.
+ *
+ * @internal
+ */
+export const blockId = "chat1"
+
+/**
+ * The one character the adapter reserves: a button or select id may not hold
+ * it, a link button's `action_id` starts with it, and it separates the
+ * parts of a modal's `private_metadata`.
+ *
+ * @internal
+ */
+export const join = "\u241F"
+
+interface PlainText {
+  readonly type: "plain_text"
+  readonly text: string
+}
+
+interface SelectOption {
+  readonly text: PlainText
+  readonly value: string
+}
+
+/** @internal */
+export type Element =
+  | {
+    readonly type: "button"
+    readonly action_id: string
+    readonly text: PlainText
+    readonly value?: string
+    readonly url?: string
+    readonly style?: "primary" | "danger"
+  }
+  | {
+    readonly type: "static_select"
+    readonly action_id: string
+    readonly placeholder?: PlainText
+    readonly options: ReadonlyArray
+    readonly initial_option?: SelectOption
+  }
+
+const plainText = (text: string): PlainText => ({ type: "plain_text", text })
+
+/** @internal */
+export const option = (label: string, value: string): SelectOption => ({ text: plainText(label), value })
+
+/**
+ * The elements for `actions`, in order. A button's id is its `action_id`
+ * and its value its `value`. A link button is a button with a `url`, and an
+ * `action_id` of the join and its index, which no id of the consumer's can
+ * be. A select's options carry their values, and `selected` is its
+ * `initial_option`.
+ *
+ * @internal
+ */
+export const elements = (actions: ReadonlyArray): Array =>
+  actions.map((action, index): Element => {
+    switch (action._tag) {
+      case "Button":
+        return {
+          type: "button",
+          action_id: action.id,
+          text: plainText(action.label),
+          ...(action.value === undefined ? {} : { value: action.value }),
+          ...(action.style === "primary" || action.style === "danger" ? { style: action.style } : {})
+        }
+      case "LinkButton":
+        return { type: "button", action_id: join + index, text: plainText(action.label), url: action.url }
+      case "Select": {
+        const selected = action.options.find((option) => option.value === action.selected)
+        return {
+          type: "static_select",
+          action_id: action.id,
+          ...(action.placeholder === undefined ? {} : { placeholder: plainText(action.placeholder) }),
+          options: action.options.map((entry) => option(entry.label, entry.value)),
+          ...(selected === undefined ? {} : { initial_option: option(selected.label, selected.value) })
+        }
+      }
+    }
+  })
+
+/**
+ * The `actions` block for a message's elements.
+ *
+ * @internal
+ */
+export const block = (actions: ReadonlyArray) => ({
+  type: "actions" as const,
+  block_id: blockId,
+  elements: elements(actions)
+})
+
+/**
+ * The `text` of a message with elements and no Markdown, before escaping:
+ * the button labels and the select placeholders, joined by a space.
+ *
+ * @internal
+ */
+export const labels = (actions: ReadonlyArray): string =>
+  actions.flatMap((action) =>
+    action._tag === "Select" ? action.placeholder === undefined ? [] : [action.placeholder] : [action.label]
+  ).join(" ")
+
+// Cost
+
+/** The fixed costs of "What `actionsCost` charges". */
+const costs = {
+  block: 56,
+  select: 52,
+  placeholder: 59,
+  option: 64,
+  initialOption: 18,
+  button: 95,
+  url: 9,
+  noValue: 11,
+  style: 18,
+  separator: 1
+} as const
+
+/** One UTF-16 unit as Slack's server writes it in JSON. */
+const unitCost = (code: number): number =>
+  code < 0x20 || code > 0x7e ? 6 : code === 0x2f || code === 0x22 || code === 0x5c ? 2 : 1
+
+/**
+ * A string as Slack's server writes it in JSON: 6 for any unit that is not
+ * printable ASCII, 2 for `/`, `"` and `\\`, 1 otherwise. An id, a value,
+ * a url and an option label cost this.
+ *
+ * @internal
+ */
+export const stringCost = (text: string): number => {
+  let cost = 0
+  for (let i = 0; i < text.length; i++) cost += unitCost(text.charCodeAt(i))
+  return cost
+}
+
+/**
+ * A button label or a placeholder: `<`, `>` and `&` are stored as
+ * entities, and an emoji costs the greater of its `:name:` and its escaped
+ * form.
+ *
+ * @internal
+ */
+export const labelCost = (text: string): number => {
+  let cost = 0
+  for (let i = 0; i < text.length;) {
+    const emoji = Emoji.longestAt(text, i)
+    if (emoji !== undefined) {
+      cost += Math.max(emoji.name.length + 2, 6 * emoji.length)
+      i += emoji.length
+      continue
+    }
+    const code = text.charCodeAt(i++)
+    cost += code === 0x3c || code === 0x3e ? 4 : code === 0x26 ? 5 : unitCost(code)
+  }
+  return cost
+}
+
+const optionCost = (option: SelectOption): number =>
+  costs.option + stringCost(option.text.text) + stringCost(option.value)
+
+const elementCost = (element: Element): number => {
+  if (element.type === "button") {
+    let cost = costs.button + labelCost(element.text.text) + stringCost(element.action_id) +
+      stringCost(element.value ?? "")
+    if (element.url !== undefined) {
+      cost += costs.url + stringCost(element.url) - (element.value === undefined ? costs.noValue : 0)
+    }
+    return element.style === undefined ? cost : cost + costs.style
+  }
+  let cost = costs.select + stringCost(element.action_id)
+  if (element.placeholder !== undefined) cost += costs.placeholder + labelCost(element.placeholder.text)
+  for (const option of element.options) cost += optionCost(option)
+  cost += Math.max(0, element.options.length - 1) * costs.separator
+  if (element.initial_option !== undefined) cost += costs.initialOption + optionCost(element.initial_option)
+  return cost
+}
+
+/**
+ * An upper bound on the `actions` block's JSON as Slack's server writes it,
+ * which the 13,200 cap charges. 0 for no elements.
+ *
+ * @internal
+ */
+export const cost = (elements: ReadonlyArray): number => {
+  if (elements.length === 0) return 0
+  let total = costs.block + (elements.length - 1) * costs.separator
+  for (const element of elements) total += elementCost(element)
+  return total
+}
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 77ad8fd9766..6ce31516afe 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -31,6 +31,7 @@ import * as Stream from "effect/Stream"
 import * as Address from "./address.ts"
 import * as Errors from "./errors.ts"
 import * as Escape from "./escape.ts"
+import * as Interactions from "./interactions.ts"
 import * as Length from "./length.ts"
 import * as Normalize from "./normalize.ts"
 import { CurrentPostOptions, type SessionStatus } from "./options.ts"
@@ -87,7 +88,11 @@ export const descriptor: Descriptor = {
     "getThread",
     "opener",
     "getUser",
-    "nativeStream"
+    "nativeStream",
+    "buttons",
+    "selects",
+    "modals",
+    "modalErrors"
   ]),
   measure: Length.measure,
   limits: {
@@ -96,7 +101,8 @@ export const descriptor: Descriptor = {
     uploadBytes: 1024 * 1024 * 1024,
     minWriteInterval: Duration.seconds(1),
     streamLength: Length.messageLength,
-    streamAge: Duration.minutes(10)
+    streamAge: Duration.minutes(10),
+    ...Interactions.limits
   }
 }
 
@@ -191,12 +197,11 @@ export const make = (options: {
 
   const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
 
-  /** The descriptor lists no buttons or selects yet, so a write that carries them is refused, never sent without them. */
-  const refuseActions = (op: string, actions: ReadonlyArray | undefined) =>
-    actions === undefined || actions.length === 0 ? Effect.void : fail(
-      op,
-      new Unsupported({ capability: actions.some((action) => action._tag !== "Select") ? "buttons" : "selects" })
-    )
+  /** Refuses elements Slack would refuse, or that the adapter could not tell from a consumer's. */
+  const checkActions = (op: string, actions: ReadonlyArray) => {
+    const refusal = Interactions.checkActions(actions)
+    return refusal === undefined ? Effect.void : fail(op, refusal)
+  }
 
   /**
    * The pace of the writes that grow one reply: stream appends, the starts
@@ -297,7 +302,7 @@ export const make = (options: {
   const messageContent = Effect.fnUntraced(
     function*(op: string, body: Text.Body) {
       yield* checkSent(op, body.sent)
-      if (body.text === "") return yield* fail(op, Errors.invalidRequest("no_text"))
+      if (body.text === "" && !Text.hasActions(body)) return yield* fail(op, Errors.invalidRequest("no_text"))
       if (body.dropped > 0) yield* Effect.annotateCurrentSpan("slack.text.dropped_tokens", body.dropped)
       return { blocks: body.blocks, text: body.text }
     }
@@ -395,6 +400,7 @@ export const make = (options: {
     parts: Address.Parts,
     markdown: string,
     files: ReadonlyArray,
+    actions: ReadonlyArray,
     notify: Escape.Notify,
     unfurl: boolean
   ) {
@@ -407,7 +413,10 @@ export const make = (options: {
     const content = Text.body(markdown, notify, Text.updateBudget)
     const body = yield* messageContent(
       "post",
-      content.text === "" ? Text.placeholder(files.map((file) => file.name), Text.updateBudget) : content
+      Text.withActions(
+        content.text === "" ? Text.placeholder(files.map((file) => file.name), Text.updateBudget) : content,
+        actions
+      )
     )
     const staged = yield* Effect.forEach(files, stage)
     yield* call("post", "files.completeUploadExternal", { files: staged }).pipe(Effect.mapError(refused))
@@ -809,14 +818,15 @@ export const make = (options: {
     post: Effect.fnUntraced(function*(thread, content) {
       const parts = yield* resolve("post", thread)
       if (content.replyTo !== undefined) return yield* fail("post", new Unsupported({ capability: "replyTo" }))
-      yield* refuseActions("post", content.actions)
+      const actions = content.actions ?? []
+      yield* checkActions("post", actions)
       const postOptions = yield* CurrentPostOptions
       const notify = postOptions.notify ?? {}
       const unfurl = postOptions.unfurl === true
       if (content.files !== undefined && content.files.length > 0) {
-        return yield* postFiles(thread, parts, content.markdown, content.files, notify, unfurl)
+        return yield* postFiles(thread, parts, content.markdown, content.files, actions, notify, unfurl)
       }
-      const body = yield* messageContent("post", Text.body(content.markdown, notify, Text.postBudget))
+      const body = yield* messageContent("post", Text.body(content.markdown, notify, Text.postBudget, actions))
       const ts = yield* call("post", "chat.postMessage", {
         channel: parts.channel,
         thread_ts: parts.threadTs,
@@ -828,11 +838,12 @@ export const make = (options: {
     }),
     edit: Effect.fnUntraced(function*(thread, messageId, content) {
       const parts = yield* resolve("edit", thread)
-      yield* refuseActions("edit", content.actions)
+      const actions = content.actions ?? []
+      yield* checkActions("edit", actions)
       const postOptions = yield* CurrentPostOptions
       const body = yield* messageContent(
         "edit",
-        Text.body(content.markdown, postOptions.notify ?? {}, Text.updateBudget)
+        Text.body(content.markdown, postOptions.notify ?? {}, Text.updateBudget, actions)
       )
       yield* retrySafe(paced(
         messageId,
diff --git a/packages/chat/slack/src/internal/emoji.ts b/packages/chat/slack/src/internal/emoji.ts
index d94f1f1b0da..1bf176e542c 100644
--- a/packages/chat/slack/src/internal/emoji.ts
+++ b/packages/chat/slack/src/internal/emoji.ts
@@ -132,6 +132,27 @@ export const fromName = (name: string): string | undefined => {
  */
 export const toName = (emoji: string): string | undefined => table().bySequence.get(emoji)
 
+/**
+ * The longest emoji in the table that starts at `index`, with its name and
+ * its length in UTF-16 units, or `undefined`.
+ *
+ * @internal
+ */
+export const longestAt = (
+  text: string,
+  index: number
+): { readonly name: string; readonly length: number } | undefined => {
+  const { bySequence, lengthsByFirst } = table()
+  const codePoint = codePointAt(text, index)
+  for (const length of lengthsByFirst.get(codePoint) ?? []) {
+    const name = index + length <= text.length ? bySequence.get(text.slice(index, index + length)) : undefined
+    if (name !== undefined) return { name, length }
+  }
+  const width = codePoint > 0xffff ? 2 : 1
+  const name = bySequence.get(text.slice(index, index + width))
+  return name === undefined ? undefined : { name, length: width }
+}
+
 // Code points that are never an emoji on their own but join or modify emoji
 // sequences. Charging them more than one keeps blocksCost subadditive: an
 // emoji sequence split anywhere costs at least as much as the whole sequence.
diff --git a/packages/chat/slack/src/internal/interactions.ts b/packages/chat/slack/src/internal/interactions.ts
new file mode 100644
index 00000000000..03634a6124b
--- /dev/null
+++ b/packages/chat/slack/src/internal/interactions.ts
@@ -0,0 +1,359 @@
+/**
+ * Slack's side of buttons, selects and modals: the checks on a message's
+ * elements, the view a modal opens as, and the interactivity payloads.
+ */
+import {
+  type ChatError,
+  type ChatErrorReason,
+  interactionExpired,
+  InvalidRequest,
+  NotFound,
+  TooLarge
+} from "effect/chat/ChatError"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type * as ChatUi from "effect/chat/ChatUi"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Option from "effect/Option"
+import * as Schema from "effect/Schema"
+import * as Actions from "./actions.ts"
+import * as Address from "./address.ts"
+import * as Errors from "./errors.ts"
+import { codePoints } from "./length.ts"
+
+type Json = Schema.Json
+type JsonObject = { readonly [key: string]: Json }
+
+/** @internal */
+export const limits = {
+  actionsPerMessage: 25,
+  actionDataLength: 2_000,
+  modalMetadataLength: 2_800,
+  modalFields: 100
+} as const
+
+/** Slack's limit on an `action_id` and a `callback_id`, in code points. */
+const idLength = 255
+/** Slack's limit on a modal's title. */
+const titleLength = 24
+/** Slack's limit on an input's label. */
+const labelLength = 2_000
+
+/** The submit label when the modal has none: Slack needs one on a view with inputs. */
+const defaultSubmitLabel = "Submit"
+
+/** The handler's share of Slack's 3 seconds. @internal */
+export const defaultDeadline = Duration.millis(2_500)
+
+/**
+ * Why a message's elements can't go, if they can't: more than 25, an id
+ * holding the join or longer than 255, or an id plus a value longer than
+ * 2,000. All count code points.
+ *
+ * @internal
+ */
+export const checkActions = (actions: ReadonlyArray): ChatErrorReason | undefined => {
+  if (actions.length > limits.actionsPerMessage) return new TooLarge({ detail: "too_many_actions" })
+  for (const action of actions) {
+    if (action._tag === "LinkButton") continue
+    if (action.id.includes(Actions.join)) return new InvalidRequest({ detail: "invalid_action_id" })
+    const id = codePoints(action.id)
+    if (id > idLength) return new TooLarge({ detail: "action_id_too_long" })
+    const values = action._tag === "Button" ? [action.value ?? ""] : action.options.map((option) => option.value)
+    if (values.some((value) => id + codePoints(value) > limits.actionDataLength)) {
+      return new TooLarge({ detail: "action_data_too_long" })
+    }
+  }
+  return undefined
+}
+
+// Modals
+
+/** Marks a `private_metadata` the adapter packed. */
+const metadataTag = "chat1"
+
+/** Where a click happened, which a submit gives back. */
+interface Origin {
+  readonly channel: string
+  readonly threadTs?: string | undefined
+  readonly messageId: string
+}
+
+/**
+ * The tag, the channel, the thread's ts or nothing, the message's ts and,
+ * when there is one, the consumer's metadata, joined. The metadata is last,
+ * so it may hold the join.
+ */
+const packMetadata = (origin: Origin, metadata: string | undefined): string =>
+  [metadataTag, origin.channel, origin.threadTs ?? "", origin.messageId, ...(metadata === undefined ? [] : [metadata])]
+    .join(Actions.join)
+
+const unpackMetadata = (
+  packed: string
+): { readonly origin: Origin; readonly metadata: string | undefined } | undefined => {
+  const parts = packed.split(Actions.join)
+  if (parts.length < 4 || parts[0] !== metadataTag || parts[1] === "" || parts[3] === "") return undefined
+  return {
+    origin: { channel: parts[1], threadTs: parts[2] === "" ? undefined : parts[2], messageId: parts[3] },
+    metadata: parts.length === 4 ? undefined : parts.slice(4).join(Actions.join)
+  }
+}
+
+const plainText = (text: string) => ({ type: "plain_text", text }) as const
+
+const inputBlock = (element: ChatUi.TextInput | ChatUi.SelectInput) => ({
+  type: "input",
+  block_id: element.id,
+  label: plainText(element.label),
+  optional: element.optional === true,
+  element: element._tag === "TextInput"
+    ? {
+      type: "plain_text_input",
+      action_id: element.id,
+      multiline: element.multiline === true,
+      ...(element.placeholder === undefined ? {} : { placeholder: plainText(element.placeholder) }),
+      ...(element.initial === undefined ? {} : { initial_value: element.initial }),
+      ...(element.minLength === undefined ? {} : { min_length: element.minLength }),
+      ...(element.maxLength === undefined ? {} : { max_length: element.maxLength })
+    }
+    : Actions.elements([{
+      _tag: "Select",
+      id: element.id,
+      options: element.options,
+      ...(element.placeholder === undefined ? {} : { placeholder: element.placeholder }),
+      ...(element.initial === undefined ? {} : { selected: element.initial })
+    }])[0]
+})
+
+/**
+ * The view that opens `modal` from `click`, or why it can't open.
+ *
+ * - Inputs are `input` blocks whose `block_id` is the field id, and a
+ *   `Text` is a `section` of plain text.
+ * - The modal's id is the `callback_id`. `private_metadata` holds the
+ *   click's channel, thread and message beside the consumer's metadata.
+ * - The modal's id plus its metadata is held to 2,800 code points, the id to
+ *   255, the title to 24 and each label to 2,000.
+ *
+ * @internal
+ */
+export const view = (
+  modal: ChatUi.Modal,
+  click: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
+): { readonly view: Readonly> } | { readonly refusal: ChatErrorReason } => {
+  const refuse = (refusal: ChatErrorReason) => ({ refusal })
+  const id = codePoints(modal.id)
+  if (id + codePoints(modal.metadata ?? "") > limits.modalMetadataLength) {
+    return refuse(new TooLarge({ detail: "modal_metadata_too_long" }))
+  }
+  if (id > idLength) return refuse(new TooLarge({ detail: "modal_id_too_long" }))
+  if (modal.elements.length > limits.modalFields) return refuse(new TooLarge({ detail: "too_many_fields" }))
+  if (codePoints(modal.title) > titleLength) return refuse(new TooLarge({ detail: "title_too_long" }))
+  const parts = Address.parts(click.thread)
+  if (Option.isNone(parts)) return refuse(new InvalidRequest({ detail: "invalid_thread" }))
+  const blocks: Array = []
+  for (const element of modal.elements) {
+    if (element._tag === "Text") {
+      blocks.push({ type: "section", text: plainText(element.text) })
+      continue
+    }
+    if (codePoints(element.label) > labelLength) return refuse(new TooLarge({ detail: "label_too_long" }))
+    blocks.push(inputBlock(element))
+  }
+  return {
+    view: {
+      type: "modal",
+      callback_id: modal.id,
+      title: plainText(modal.title),
+      submit: plainText(modal.submitLabel ?? defaultSubmitLabel),
+      private_metadata: packMetadata({ ...parts.value, messageId: click.messageId }, modal.metadata),
+      blocks
+    }
+  }
+}
+
+// Inbound
+
+const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u)
+
+const isJson = Schema.is(Schema.Json)
+
+const string = (object: JsonObject | undefined, key: string): string | undefined => {
+  const value = object?.[key]
+  return typeof value === "string" && value.length > 0 ? value : undefined
+}
+
+const object = (object: JsonObject | undefined, key: string): JsonObject | undefined => {
+  const value = object?.[key]
+  return isObject(value) ? value : undefined
+}
+
+/** The payload without its verification `token`. */
+const raw = (payload: JsonObject): Json => {
+  const { token: _, ...rest } = payload
+  return rest
+}
+
+const threadOf = (teamId: string, origin: Origin) =>
+  Address.thread({
+    team: teamId,
+    channel: origin.channel,
+    threadTs: origin.threadTs === origin.messageId ? undefined : origin.threadTs
+  })
+
+/** An own property, so an id such as `__proto__` keeps its answer. */
+const setOwn = (record: Record, key: string, value: string) =>
+  Object.defineProperty(record, key, { value, enumerable: true, writable: true, configurable: true })
+
+const clicked = (payload: JsonObject, teamId: string): Option.Option => {
+  const actions = payload.actions
+  const action = Array.isArray(actions) && actions.length === 1 && isObject(actions[0]) ? actions[0] : undefined
+  const id = string(action, "action_id")
+  // Only an element in the adapter's own block, and not a link button, whose click carries nothing.
+  if (action === undefined || id === undefined || action.block_id !== Actions.blockId || id.startsWith(Actions.join)) {
+    return Option.none()
+  }
+  const container = object(payload, "container")
+  const message = object(payload, "message")
+  const channel = string(container, "channel_id") ?? string(object(payload, "channel"), "id")
+  const messageId = string(container, "message_ts") ?? string(message, "ts")
+  const userId = string(object(payload, "user"), "id")
+  if (channel === undefined || messageId === undefined || userId === undefined) return Option.none()
+  const threadTs = string(message, "thread_ts") ?? string(container, "thread_ts")
+  const origin = { thread: threadOf(teamId, { channel, threadTs, messageId }), messageId, userId, raw: raw(payload) }
+  if (action.type === "button") {
+    const value = typeof action.value === "string" ? action.value : undefined
+    return Option.some(ChatInteraction.ButtonClicked.make({ id, ...(value === undefined ? {} : { value }), ...origin }))
+  }
+  const value = object(action, "selected_option")?.value
+  return action.type === "static_select" && typeof value === "string"
+    ? Option.some(ChatInteraction.SelectChanged.make({ id, value, ...origin }))
+    : Option.none()
+}
+
+/** The value of one input in `view.state.values`, or nothing for an empty one. */
+const inputValue = (input: Json): string | undefined => {
+  if (!isObject(input)) return undefined
+  const value = input.type === "static_select" ? object(input, "selected_option")?.value : input.value
+  return typeof value === "string" && value !== "" ? value : undefined
+}
+
+const submitted = (payload: JsonObject, teamId: string): Option.Option => {
+  const view = object(payload, "view")
+  const id = string(view, "callback_id")
+  const packed = string(view, "private_metadata")
+  const unpacked = packed === undefined ? undefined : unpackMetadata(packed)
+  const userId = string(object(payload, "user"), "id")
+  if (id === undefined || unpacked === undefined || userId === undefined) return Option.none()
+  const values: Record = {}
+  const state = object(object(view, "state"), "values") ?? {}
+  for (const blockId of Object.keys(state)) {
+    const inputs = object(state, blockId)
+    if (inputs === undefined) continue
+    for (const input of Object.values(inputs)) {
+      const value = inputValue(input)
+      if (value !== undefined) setOwn(values, blockId, value)
+    }
+  }
+  const { metadata, origin } = unpacked
+  return Option.some(ChatInteraction.ModalSubmitted.make({
+    id,
+    ...(metadata === undefined ? {} : { metadata }),
+    values,
+    thread: threadOf(teamId, origin),
+    messageId: origin.messageId,
+    userId,
+    raw: raw(payload)
+  }))
+}
+
+/**
+ * The interaction a decoded `payload` is: a click on a button or select in
+ * an `actions` block the adapter built, or a submit of a view it opened.
+ * Anything else, a link button's click and a value that is not JSON
+ * included, is none.
+ *
+ * @internal
+ */
+export const normalize = (
+  payload: unknown,
+  context: { readonly teamId: string }
+): Option.Option => {
+  if (!isObject(payload) || !isJson(payload)) return Option.none()
+  if (payload.type === "block_actions") return clicked(payload, context.teamId)
+  if (payload.type === "view_submission") return submitted(payload, context.teamId)
+  return Option.none()
+}
+
+/** @internal */
+export interface Api {
+  readonly call: (
+    method: string,
+    body: Readonly>,
+    options?: { readonly write?: boolean | undefined; readonly retry?: boolean | undefined }
+  ) => Effect.Effect
+}
+
+/** A trigger past its 3 seconds is the same refusal `handle` gives a late click. */
+const expired = (error: ChatError): ChatError =>
+  error.reason.detail === "expired_trigger_id"
+    ? Errors.chatError("openModal", new NotFound({ detail: interactionExpired, cause: error.reason }))
+    : error
+
+/**
+ * `SlackChat.interaction`: normalises, calls the handler through
+ * `ChatInteraction.handle` and gives the body to answer with.
+ *
+ * - An ack, a close, a late click and a payload that is not the adapter's
+ *   give `undefined`, an empty answer.
+ * - `errors` gives `response_action: "errors"`, keyed by field id.
+ * - A late submit gives `Late`.
+ * - `OpenModal` calls `views.open` with the click's `trigger_id` before
+ *   answering. A modal that can't be built, or that Slack refuses, goes to
+ *   `Handler.refused`, and the click is still acked.
+ *
+ * @internal
+ */
+export const make = (options: { readonly api: Api; readonly teamId: string }) =>
+(
+  payload: unknown,
+  interactionOptions?: { readonly deadline?: Duration.Duration | undefined }
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const event = normalize(payload, { teamId: options.teamId })
+    if (Option.isNone(event)) return undefined
+    const reply = yield* ChatInteraction.handle(event.value, interactionOptions?.deadline ?? defaultDeadline)
+    switch (reply._tag) {
+      case "Late":
+        // A late click is acked: its handler runs on and `handle` refuses a modal it opens.
+        return event.value._tag === "ModalSubmitted" ? reply : undefined
+      case "Ack":
+      case "Close":
+        return undefined
+      case "Errors":
+        return { response_action: "errors", errors: reply.errors }
+      case "OpenModal": {
+        const click = event.value as ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
+        const handler = yield* ChatInteraction.Handler
+        const built = view(reply.modal, click)
+        if ("refusal" in built) {
+          yield* handler.refused(click, Errors.chatError("openModal", built.refusal))
+          return undefined
+        }
+        const triggerId = isObject(payload) ? string(payload, "trigger_id") : undefined
+        if (triggerId === undefined) {
+          yield* handler.refused(click, Errors.chatError("openModal", new InvalidRequest({ detail: "no_trigger_id" })))
+          return undefined
+        }
+        yield* options.api.call("views.open", { trigger_id: triggerId, view: built.view }, {
+          write: true,
+          retry: false
+        })
+          .pipe(
+            Effect.mapError(Errors.withOp("openModal")),
+            Effect.catch((error) => handler.refused(click, expired(error)))
+          )
+        return undefined
+      }
+    }
+  })
diff --git a/packages/chat/slack/src/internal/length.ts b/packages/chat/slack/src/internal/length.ts
index 99184daa819..232e002b265 100644
--- a/packages/chat/slack/src/internal/length.ts
+++ b/packages/chat/slack/src/internal/length.ts
@@ -1,3 +1,5 @@
+import type { Action } from "effect/chat/ChatUi"
+import * as Actions from "./actions.ts"
 import { blocksCost } from "./emoji.ts"
 
 /** `msg_too_long`: code points of `markdown_text` as sent, inclusive. @internal */
@@ -24,15 +26,16 @@ const lessThan = (text: string): number => {
 }
 
 /**
- * What a Markdown string costs against `messageLength`, as an upper bound
- * that adds up. It is the larger of two counts: code points plus three for
- * every `<`, which may be sent as `<`, and Slack's emoji-as-shortcode
- * count scaled from 13,200 to 12,000.
+ * What a Markdown string and the elements beside it cost against
+ * `messageLength`, as an upper bound that adds up. It is the larger of two
+ * counts: code points plus three for every `<`, which may be sent as
+ * `<`, and Slack's 13,200 count, scaled to 12,000, of the text with each
+ * emoji as its shortcode plus the `actions` block's stored JSON.
  *
  * @internal
  */
-export const measure = (markdown: string): number =>
+export const measure = (markdown: string, actions?: ReadonlyArray): number =>
   Math.max(
     codePoints(markdown) + 3 * lessThan(markdown),
-    Math.ceil(blocksCost(markdown) * 10 / 11)
+    Math.ceil((blocksCost(markdown) + Actions.cost(Actions.elements(actions ?? []))) * 10 / 11)
   )
diff --git a/packages/chat/slack/src/internal/text.ts b/packages/chat/slack/src/internal/text.ts
index b423b6a5442..de740e892f5 100644
--- a/packages/chat/slack/src/internal/text.ts
+++ b/packages/chat/slack/src/internal/text.ts
@@ -4,6 +4,8 @@
  * mentions from this field, not from the blocks, so the adapter always
  * builds it itself: Slack's own would carry every token intact.
  */
+import type { Action } from "effect/chat/ChatUi"
+import * as Actions from "./actions.ts"
 import * as Escape from "./escape.ts"
 import { codePoints } from "./length.ts"
 import { escapeMarkdown } from "./richText.ts"
@@ -183,24 +185,57 @@ export const build = (markdown: string, notify: Escape.Notify, budget: Budget):
 export interface Body {
   /** The Markdown as sent in the block, for the length check. */
   readonly sent: string
-  readonly blocks: ReadonlyArray<{ readonly type: "markdown"; readonly text: string }>
+  readonly blocks: ReadonlyArray
   readonly text: string
   readonly dropped: number
 }
 
 /**
  * The content of a `chat.postMessage` or `chat.update`: the Markdown as one
- * `markdown` block, escaped as `markdown_text` was, and the `text` from
- * `build`.
+ * `markdown` block, escaped as `markdown_text` was, then the elements as
+ * one `actions` block, and the `text` from `build`.
+ *
+ * With elements and no Markdown there is no `markdown` block, and `text`
+ * is the button labels joined by a space, escaped. Slack's own fallback,
+ * which appends the word "button" to each label, never appears.
  *
  * @internal
  */
-export const body = (markdown: string, notify: Escape.Notify, budget: Budget): Body => {
+export const body = (
+  markdown: string,
+  notify: Escape.Notify,
+  budget: Budget,
+  actions: ReadonlyArray = []
+): Body => {
+  if (markdown === "" && actions.length > 0) {
+    const built = build(Actions.labels(actions), {}, budget)
+    return withActions({ sent: "", blocks: [], text: built.text, dropped: built.dropped }, actions)
+  }
   const sent = Escape.escape(markdown, notify, { flush: true }).sent
   const built = build(markdown, notify, budget)
-  return { sent, blocks: [{ type: "markdown", text: sent }], text: built.text, dropped: built.dropped }
+  return withActions(
+    { sent, blocks: [{ type: "markdown", text: sent }], text: built.text, dropped: built.dropped },
+    actions
+  )
 }
 
+/**
+ * `body` with the elements' `actions` block last, when there are any.
+ *
+ * @internal
+ */
+export const withActions = (body: Body, actions: ReadonlyArray): Body =>
+  actions.length === 0 ? body : { ...body, blocks: [...body.blocks, Actions.block(actions)] }
+
+/**
+ * Whether `body` has an `actions` block, which is content enough without
+ * `text`.
+ *
+ * @internal
+ */
+export const hasActions = (body: Body): boolean =>
+  body.blocks.some((block) => (block as { readonly type?: unknown }).type === "actions")
+
 /**
  * The content of a post with files and no Markdown: the file names joined by
  * ", ", escaped as Markdown in the block so they render as written, and with
diff --git a/packages/chat/slack/src/internal/webhook.ts b/packages/chat/slack/src/internal/webhook.ts
index 53dfae7d16f..68464f37d0b 100644
--- a/packages/chat/slack/src/internal/webhook.ts
+++ b/packages/chat/slack/src/internal/webhook.ts
@@ -1,6 +1,7 @@
 import type { ChatError } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import type { NotAccepted } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
 import * as Clock from "effect/Clock"
 import { WebCrypto } from "effect/crypto/WebCrypto"
 import type * as Duration from "effect/Duration"
@@ -9,6 +10,7 @@ import type * as HttpServerRequest from "effect/http/HttpServerRequest"
 import * as HttpServerResponse from "effect/http/HttpServerResponse"
 import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
+import * as Schema from "effect/Schema"
 import * as Stream from "effect/Stream"
 import { normalize } from "./normalize.ts"
 
@@ -161,3 +163,51 @@ export const handleRequest = (
     )
     return handled ? ok : status(503)
   })
+
+/** @internal */
+export interface InteractivityOptions {
+  readonly verify: Options["verify"]
+  readonly appId: string
+  readonly interaction: (
+    payload: unknown,
+    options: { readonly deadline: Duration.Duration }
+  ) => Effect.Effect
+  readonly deadline: Duration.Duration
+  readonly maxBodyBytes: number
+}
+
+const isLate = Schema.is(ChatInteraction.Late)
+
+/**
+ * One Interactivity request: a form-encoded body whose `payload` field
+ * holds the JSON.
+ *
+ * - 413 past the body limit, 401 for a bad signature, 400 for a body with
+ *   no `payload` that is a JSON object.
+ * - A payload for another app is answered 200 and dropped.
+ * - `Late` is answered 503, which keeps a modal open. Anything else is a
+ *   200, with the body as JSON when there is one.
+ *
+ * @internal
+ */
+export const handleInteractivity = (
+  request: HttpServerRequest.HttpServerRequest,
+  options: InteractivityOptions
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const body = yield* readBody(request, options.maxBodyBytes)
+    if (Option.isNone(body)) return status(413)
+    if (!(yield* options.verify(request.headers, body.value))) return status(401)
+    const field = new URLSearchParams(new TextDecoder().decode(body.value)).get("payload")
+    let payload: unknown
+    try {
+      payload = field === null ? undefined : JSON.parse(field)
+    } catch {
+      return status(400)
+    }
+    if (!isObject(payload)) return status(400)
+    if (payload.api_app_id !== options.appId) return ok
+    const answer = yield* options.interaction(payload, { deadline: options.deadline })
+    if (answer === undefined) return ok
+    return isLate(answer) ? status(503) : HttpServerResponse.jsonUnsafe(answer)
+  })
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 66ecbcf39ae..5f5d4e7cbf9 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -3,6 +3,7 @@ import { SlackWebApi } from "@effect/chat-slack/SlackWebApi"
 import { assert, describe, it } from "@effect/vitest"
 import { type ChatErrorReason, fileRefused } from "effect/chat/ChatError"
 import { checkMessage, conformance } from "effect/chat/ChatTest"
+import type { Action } from "effect/chat/ChatUi"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
@@ -184,34 +185,87 @@ describe("post", () => {
 })
 
 describe("buttons and selects", () => {
-  const button = { _tag: "Button", id: "go", label: "Go" } as const
-  const select = { _tag: "Select", id: "pick", options: [{ label: "A", value: "a" }] } as const
+  const button = { _tag: "Button", id: "go", label: "Go ", value: "v", style: "primary" } as const
+  const link = { _tag: "LinkButton", label: "Docs", url: "https://effect.website/docs" } as const
+  const select = {
+    _tag: "Select",
+    id: "pick",
+    options: [{ label: "A", value: "a" }, { label: "B", value: "b" }],
+    selected: "b"
+  } as const
 
-  it.effect("are refused with Unsupported until the adapter supports them, calling nothing", () => {
-    const fake = makeFake({})
+  it.effect("go as one actions block after the markdown, and with no markdown the labels are the text", () => {
+    const fake = makeFake({
+      "chat.postMessage": posted("1794509200.000100"),
+      "chat.update": posted("1794509200.000100")
+    })
     return run(
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const post = yield* reason(slack.post(channelThread, { markdown: "x", actions: [button] }))
-        assert.deepStrictEqual([post.op, post.tag], ["post", "Unsupported"])
-        const edit = yield* reason(slack.edit(channelThread, "1.2", { markdown: "x", actions: [select] }))
-        assert.deepStrictEqual([edit.op, edit.tag], ["edit", "Unsupported"])
-        assert.strictEqual(fake.called("chat.postMessage").length + fake.called("chat.update").length, 0)
+        yield* slack.post(channelThread, { markdown: "Pick", actions: [button, link, select] })
+        yield* slack.edit(channelThread, "1794509200.000100", { markdown: "", actions: [button, link] })
+        const [post] = fake.called("chat.postMessage")
+        assert.deepStrictEqual(JSON.parse(post.params.blocks), [
+          { type: "markdown", text: "Pick" },
+          {
+            type: "actions",
+            block_id: "chat1",
+            elements: [
+              {
+                type: "button",
+                action_id: "go",
+                text: { type: "plain_text", text: "Go " },
+                value: "v",
+                style: "primary"
+              },
+              {
+                type: "button",
+                action_id: "\u241F1",
+                text: { type: "plain_text", text: "Docs" },
+                url: "https://effect.website/docs"
+              },
+              {
+                type: "static_select",
+                action_id: "pick",
+                options: [
+                  { text: { type: "plain_text", text: "A" }, value: "a" },
+                  { text: { type: "plain_text", text: "B" }, value: "b" }
+                ],
+                initial_option: { text: { type: "plain_text", text: "B" }, value: "b" }
+              }
+            ]
+          }
+        ])
+        const [edit] = fake.called("chat.update")
+        assert.deepStrictEqual(JSON.parse(edit.params.blocks).map((block: any) => block.type), ["actions"])
+        assert.strictEqual(edit.params.text, "Go <now> Docs")
       })
     )
   })
 
-  it.effect("pass unsupported/buttons and unsupported/selects over the stub", () => {
-    const rules = conformance({
-      platform: "slack",
-      thread: channelThread,
-      userPosts: () => Effect.die("unused"),
-      parseMention: SlackChat.parseMention
-    })
+  it.effect("are refused before any call for an id Slack or the adapter can't take", () => {
+    const fake = makeFake({})
     return run(
-      makeFake({ "auth.test": authTest }),
-      Effect.andThen(rules["unsupported/buttons"], rules["unsupported/selects"])
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const refused = (actions: ReadonlyArray) =>
+          reason(slack.post(channelThread, { markdown: "x", actions }))
+        assert.deepStrictEqual(
+          [
+            yield* refused([{ ...button, id: "a\u241Fb" }]),
+            yield* refused([{ ...button, id: "日".repeat(256) }]),
+            yield* refused([{ ...select, id: "i".repeat(10), options: [{ label: "A", value: "v".repeat(1_991) }] }])
+          ].map((error) => [error.op, error.tag, error.detail]),
+          [
+            ["post", "InvalidRequest", "invalid_action_id"],
+            ["post", "TooLarge", "action_id_too_long"],
+            ["post", "TooLarge", "action_data_too_long"]
+          ]
+        )
+        assert.strictEqual(fake.called("chat.postMessage").length, 0)
+      })
     )
   })
 })
@@ -291,6 +345,22 @@ describe("files", () => {
     )
   })
 
+  it.effect("a post with files and buttons carries the actions block on the post and the attach", () => {
+    const fake = makeFake({ ...upload(["F1"]), "chat.postMessage": posted(ts) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const slack = yield* adapter
+        const actions = [{ _tag: "Button", id: "go", label: "Go" }] as const
+        yield* slack.post(channelThread, { markdown: "", files: [file("a.txt")], actions })
+        const post = fake.called("chat.postMessage")[0].params
+        assert.deepStrictEqual(JSON.parse(post.blocks).map((block: any) => block.type), ["markdown", "actions"])
+        assert.strictEqual(post.text, "a.txt")
+        assert.strictEqual(fake.called("chat.update")[0].params.blocks, post.blocks)
+      })
+    )
+  })
+
   it.effect("too many files fail file_refused before any call", () => {
     const fake = makeFake({})
     return run(
diff --git a/packages/chat/slack/test/actions.test.ts b/packages/chat/slack/test/actions.test.ts
new file mode 100644
index 00000000000..96a187f38fb
--- /dev/null
+++ b/packages/chat/slack/test/actions.test.ts
@@ -0,0 +1,102 @@
+/**
+ * `actionsCost` against the 38 rows measured in EFF-3738: each row is the
+ * `actions` block's elements as posted, and what the 13,200 cap charged for
+ * it, found by bisecting the text beside it.
+ */
+import { cost, type Element, labelCost, option, stringCost } from "@effect/chat-slack/internal/actions"
+import { assert, describe, it } from "@effect/vitest"
+
+const opts = (n: number, label = (i: number) => "Option " + i, value = (i: number) => "o" + i) =>
+  Array.from({ length: n }, (_, i) => option(label(i + 1), value(i + 1)))
+
+const S = (o: {
+  readonly id?: string
+  readonly ph?: string | null
+  readonly options?: ReadonlyArray>
+  readonly initial?: ReturnType
+} = {}): Element => ({
+  type: "static_select",
+  action_id: o.id ?? "sel1",
+  ...(o.ph === null ? {} : { placeholder: { type: "plain_text", text: o.ph ?? "Pick one" } }),
+  options: o.options ?? opts(3),
+  ...(o.initial === undefined ? {} : { initial_option: o.initial })
+})
+
+const B = (o: {
+  readonly id?: string
+  readonly label?: string
+  readonly url?: string
+  readonly value?: string | null
+} = {}): Element => ({
+  type: "button",
+  text: { type: "plain_text", text: o.label ?? "Test button" },
+  action_id: o.id ?? "eff3738_noop",
+  ...(o.url === undefined ? {} : { url: o.url }),
+  ...(o.value === null ? {} : { value: o.value ?? "v" })
+})
+
+const one = (label: string) => opts(1, () => label, () => "a")
+
+/** Name, elements, what Slack charged, and whether every string in it is ASCII. */
+const rows: ReadonlyArray, number, boolean]> = [
+  ["V1", [S({ options: one("A"), ph: null })], 173, true],
+  ["V2", [S({ options: one("A") })], 240, true],
+  ["V3", [S({ options: one("A"), ph: "x".repeat(75) })], 307, true],
+  ["V4", [S({ options: opts(2, () => "A", () => "a") })], 307, true],
+  ["V5", [S({ options: opts(3, () => "A", () => "a") })], 374, true],
+  ["V6", [S({ options: opts(10, () => "A", () => "a") })], 843, true],
+  ["V7", [S({ options: one("L".repeat(75)) })], 315, true],
+  ["V8", [S({ options: opts(1, () => "A", () => "v".repeat(150)) })], 389, true],
+  ["V9", [S({ options: opts(3) })], 398, true],
+  ["V10", [S({ options: opts(3), initial: option("Option 2", "o2") })], 490, true],
+  ["V11", [S({ options: one("\u{1F600}") })], 251, false],
+  ["V12", [S({ options: one("A"), ph: "\u{1F600}" })], 242, false],
+  ["V13", [S({ options: one("A"), id: "i".repeat(200) })], 436, true],
+  ["V14", [S({ options: opts(3) }), B()], 518, true],
+  ["V15", [B(), S({ options: opts(3) }), B({ id: "b2" })], 628, true],
+  ["V16", [S({ options: opts(3) }), S({ options: opts(3), id: "sel2" })], 746, true],
+  ["V17", [S({ options: opts(30) })], 2465, true],
+  ["V18", [S({ options: one("é".repeat(20)) })], 359, false],
+  ["V19", [S({ options: one("A\"<&>\\/") })], 249, true],
+  ["V20", [B()], 170, true],
+  ["V21", [B({ url: "https://effect.website/docs", value: null })], 197, true],
+  ["V22", [B({ url: "https://effect.website/docs", value: "v" })], 209, true],
+  ["V23", [B({ url: "https://effect.website/" + "p".repeat(500) + "?a=1&b=2", value: null })], 701, true],
+  ["V24", [B({ url: "https://effect.website/docs/a/b/c", value: null })], 206, true],
+  ["W1", [B({ label: "é".repeat(20) })], 279, false],
+  ["W2", [B({ label: "\u{1F644}" })], 183, false],
+  ["W3", [S({ options: one("\u{1F644}") })], 251, false],
+  ["W4", [S({ options: one("A"), ph: "\u{1F644}" })], 256, false],
+  ["W5", [S({ options: opts(1, () => "A", () => "é".repeat(10) + "/".repeat(10)) })], 319, false],
+  ["W6", [B({ id: "a/b/c/d/e", value: "é".repeat(20) + "/".repeat(20) })], 330, false],
+  ["W7", [S({ options: one("<&>".repeat(10)) })], 269, true],
+  ["W8", [B({ label: "<&>".repeat(10) })], 289, true],
+  ["W9", [S({ options: one(":grinning: :not_an_emoji:") })], 265, true],
+  ["W10", [B({ label: ":grinning: :not_an_emoji:" })], 184, true],
+  ["W11", [S({ options: one("\u{1F44D}\u{1F3FD} \u{1F1E6}\u{1F1FA} \u2764\uFE0F") })], 301, false],
+  ["W12", [B({ label: "\u{1F44D}\u{1F3FD} \u{1F1E6}\u{1F1FA} \u2764\uFE0F" })], 194, false],
+  ["W13", [S({ options: one("\u{1D49C}".repeat(5)) })], 299, false],
+  ["W14", [B({ label: "\u{1D49C}".repeat(5) })], 219, false]
+]
+
+describe("actionsCost", () => {
+  it("is never below what Slack charged, and at most 5 over on ASCII, for the 38 measured rows", () => {
+    assert.strictEqual(rows.length, 38)
+    for (const [name, elements, charged, ascii] of rows) {
+      const charge = cost(elements)
+      assert.isAtLeast(charge, charged, name)
+      if (ascii) assert.isAtMost(charge, charged + 5, name)
+    }
+  })
+
+  it("charges each string as JSON writes it", () => {
+    assert.strictEqual(cost([]), 0)
+    assert.strictEqual(stringCost("a/\"\\é\u{1D400}\n"), 1 + 2 + 2 + 2 + 6 + 12 + 6)
+    // Entities in a label, and an emoji at the greater of its name and its escaped form.
+    assert.strictEqual(labelCost("<>&"), 13)
+    assert.strictEqual(labelCost("\u{1F644}"), ":face_with_rolling_eyes:".length)
+    assert.strictEqual(labelCost("\u{1F600}"), 12)
+    // A 75-character Japanese label.
+    assert.strictEqual(labelCost("日".repeat(75)), 450)
+  })
+})
diff --git a/packages/chat/slack/test/conformance.test.ts b/packages/chat/slack/test/conformance.test.ts
new file mode 100644
index 00000000000..e3b8f2e5fbc
--- /dev/null
+++ b/packages/chat/slack/test/conformance.test.ts
@@ -0,0 +1,45 @@
+/**
+ * The conformance rules for buttons, selects and modals, against the adapter
+ * over a stubbed Web API that keeps what was posted. Clicks and submits are
+ * built from the posted blocks and the opened views and go through
+ * `SlackChat.interaction`, so the answers are tested too.
+ */
+import * as SlackChat from "@effect/chat-slack/SlackChat"
+import { describe, it } from "@effect/vitest"
+import { conformance } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import { makeSlack } from "./slack.ts"
+import { channel, slackLayer, team } from "./utils.ts"
+
+const thread = SlackChat.thread({ team, channel })
+
+const portable = (name: string) =>
+  name.startsWith("actions/") ||
+  name.startsWith("modal/") ||
+  name.startsWith("edit/") && name.endsWith("Actions") ||
+  name.startsWith("descriptor/measure") && name.endsWith("Actions") ||
+  name === "unsupported/buttons" ||
+  name === "unsupported/selects" ||
+  name === "unsupported/modals"
+
+const options = {
+  platform: "slack",
+  thread,
+  userPosts: () => Effect.die("unused"),
+  parseMention: SlackChat.parseMention
+}
+
+describe("conformance over the stubbed Web API", () => {
+  const names = Object.keys(conformance({
+    ...options,
+    interactions: { click: () => Effect.void, submit: () => Effect.void }
+  })).filter(portable)
+
+  for (const name of names) {
+    it.effect(name, () => {
+      const slack = makeSlack()
+      const rules = conformance({ ...options, interactions: slack.interactions })
+      return Effect.andThen(slack.bind, rules[name]).pipe(Effect.provide(slackLayer(slack.fake)))
+    })
+  }
+})
diff --git a/packages/chat/slack/test/fixtures/recorded/interactivity.json b/packages/chat/slack/test/fixtures/recorded/interactivity.json
new file mode 100644
index 00000000000..c338e7cfbae
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/recorded/interactivity.json
@@ -0,0 +1,244 @@
+{
+  "source": "EFF-3726 series H in chat-testing-123, as the Interactivity Request URL received them, with the verification token, response_url and most of trigger_id redacted. The click is on an element of a block another app built; the submit is of a view the adapter did not open.",
+  "cases": {
+    "block_actions": {
+      "type": "block_actions",
+      "user": {
+        "id": "U080YLYB277",
+        "username": "tim.smart",
+        "name": "tim.smart",
+        "team_id": "T05479Z6JBW"
+      },
+      "api_app_id": "A0CCHBHDK7X",
+      "token": "",
+      "container": {
+        "type": "message",
+        "message_ts": "1794535967.302589",
+        "channel_id": "C0CH1LGJ4F3",
+        "is_ephemeral": false
+      },
+      "trigger_id": "12585269731701",
+      "team": {
+        "id": "T05479Z6JBW",
+        "domain": "effectfulworkspace"
+      },
+      "enterprise": null,
+      "is_enterprise_install": false,
+      "channel": {
+        "id": "C0CH1LGJ4F3",
+        "name": "privategroup"
+      },
+      "message": {
+        "user": "U0CCLMD4S1L",
+        "type": "message",
+        "ts": "1794535967.302589",
+        "bot_id": "B0CCQH77VA5",
+        "app_id": "A0CCHBHDK7X",
+        "text": "EFF-3726 click test",
+        "team": "T05479Z6JBW",
+        "blocks": [
+          {
+            "type": "section",
+            "block_id": "q6zWT",
+            "text": {
+              "type": "mrkdwn",
+              "text": "*EFF-3726 click test (series H).* Click 1 to 7 in order, one at a time, and note what the client shows after each.",
+              "verbatim": false
+            }
+          },
+          {
+            "type": "actions",
+            "block_id": "h_clicks",
+            "elements": [
+              {
+                "type": "button",
+                "action_id": "ack_now",
+                "text": {
+                  "type": "plain_text",
+                  "text": "1 ack now",
+                  "emoji": true
+                },
+                "value": "ack_now"
+              },
+              {
+                "type": "button",
+                "action_id": "ack_late_5s",
+                "text": {
+                  "type": "plain_text",
+                  "text": "2 ack at 5s",
+                  "emoji": true
+                },
+                "value": "ack_late_5s"
+              },
+              {
+                "type": "button",
+                "action_id": "ack_late_20s",
+                "text": {
+                  "type": "plain_text",
+                  "text": "3 ack at 20s",
+                  "emoji": true
+                },
+                "value": "ack_late_20s"
+              },
+              {
+                "type": "button",
+                "action_id": "ack_never",
+                "text": {
+                  "type": "plain_text",
+                  "text": "4 never ack",
+                  "emoji": true
+                },
+                "value": "ack_never"
+              }
+            ]
+          },
+          {
+            "type": "actions",
+            "block_id": "h_modals",
+            "elements": [
+              {
+                "type": "button",
+                "action_id": "open_modal_ok",
+                "text": {
+                  "type": "plain_text",
+                  "text": "5 modal, submit acked",
+                  "emoji": true
+                },
+                "value": "open_modal_ok"
+              },
+              {
+                "type": "button",
+                "action_id": "open_modal_late_5s",
+                "text": {
+                  "type": "plain_text",
+                  "text": "6 modal, submit acked at 5s",
+                  "emoji": true
+                },
+                "value": "open_modal_late_5s"
+              },
+              {
+                "type": "button",
+                "action_id": "open_modal_never",
+                "text": {
+                  "type": "plain_text",
+                  "text": "7 modal, submit never acked",
+                  "emoji": true
+                },
+                "value": "open_modal_never"
+              }
+            ]
+          }
+        ]
+      },
+      "state": {
+        "values": {}
+      },
+      "response_url": "",
+      "actions": [
+        {
+          "type": "button",
+          "block_id": "h_modals",
+          "action_id": "open_modal_ok",
+          "text": {
+            "type": "plain_text",
+            "text": "5 modal, submit acked",
+            "emoji": true
+          },
+          "value": "open_modal_ok",
+          "action_ts": "1794536129.903602"
+        }
+      ]
+    },
+    "view_submission": {
+      "type": "view_submission",
+      "team": {
+        "id": "T05479Z6JBW",
+        "domain": "effectfulworkspace"
+      },
+      "user": {
+        "id": "U080YLYB277",
+        "username": "tim.smart",
+        "name": "tim.smart",
+        "team_id": "T05479Z6JBW"
+      },
+      "api_app_id": "A0CCHBHDK7X",
+      "token": "",
+      "trigger_id": "12618937762224",
+      "view": {
+        "id": "V0CHAHJNBSS",
+        "team_id": "T05479Z6JBW",
+        "type": "modal",
+        "blocks": [
+          {
+            "type": "section",
+            "block_id": "9aEq0",
+            "text": {
+              "type": "mrkdwn",
+              "text": "EFF-3726 test modal *submit_ok*. Wait for the test channel to say the limit probe is done before you submit.",
+              "verbatim": false
+            }
+          },
+          {
+            "type": "input",
+            "block_id": "b_note",
+            "label": {
+              "type": "plain_text",
+              "text": "Note",
+              "emoji": true
+            },
+            "optional": true,
+            "dispatch_action": false,
+            "element": {
+              "type": "plain_text_input",
+              "action_id": "note",
+              "dispatch_action_config": {
+                "trigger_actions_on": [
+                  "on_enter_pressed"
+                ]
+              }
+            }
+          }
+        ],
+        "private_metadata": "{\"q\":\"\\\"quoted\\\"\",\"amp\":\"a&b  <d>\",\"emoji\":\"😀👩🏽‍💻\",\"nl\":\"line1\\nline2\\ttab\",\"uni\":\"é ü 日本\",\"pad\":\"  trailing  \"}",
+        "callback_id": "submit_ok",
+        "state": {
+          "values": {
+            "b_note": {
+              "note": {
+                "type": "plain_text_input",
+                "value": "hello"
+              }
+            }
+          }
+        },
+        "hash": "1794536131.FvPOkwwj",
+        "title": {
+          "type": "plain_text",
+          "text": "EFF-3726",
+          "emoji": true
+        },
+        "clear_on_close": false,
+        "notify_on_close": false,
+        "close": {
+          "type": "plain_text",
+          "text": "Cancel",
+          "emoji": true
+        },
+        "submit": {
+          "type": "plain_text",
+          "text": "Submit",
+          "emoji": true
+        },
+        "previous_view_id": null,
+        "root_view_id": "V0CHAHJNBSS",
+        "app_id": "A0CCHBHDK7X",
+        "external_id": "",
+        "app_installed_team_id": "T05479Z6JBW",
+        "bot_id": "B0CCQH77VA5"
+      },
+      "response_urls": [],
+      "is_enterprise_install": false,
+      "enterprise": null
+    }
+  }
+}
diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
new file mode 100644
index 00000000000..197a8d75fdb
--- /dev/null
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -0,0 +1,273 @@
+/**
+ * Interactivity: the normaliser on recorded and built payloads, the answers
+ * `SlackChat.interaction` gives, and `layerInteractivity` over HTTP.
+ */
+import * as SlackChat from "@effect/chat-slack/SlackChat"
+import { assert, describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
+import type { ChatError } from "effect/chat/ChatError"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as ChatUi from "effect/chat/ChatUi"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as HttpRouter from "effect/http/HttpRouter"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+import { appId, authTest, channel, fixture, makeFake, slackLayer, team } from "./utils.ts"
+
+const recorded = fixture("interactivity").cases
+const join = "\u241F"
+const user = { id: "U080YLYB277", username: "tim", team_id: team }
+
+const click = (action: Record, message: Record = {}) => ({
+  type: "block_actions",
+  api_app_id: appId,
+  token: "verification",
+  trigger_id: "trigger-1",
+  user,
+  team: { id: team },
+  container: { type: "message", message_ts: "1794600001.000100", channel_id: channel },
+  channel: { id: channel },
+  message: { ts: "1794600001.000100", ...message },
+  actions: [{ block_id: "chat1", ...action }]
+})
+
+const submit = (privateMetadata: string, values: Record) => ({
+  type: "view_submission",
+  api_app_id: appId,
+  user,
+  team: { id: team },
+  trigger_id: "trigger-2",
+  view: { id: "V1", callback_id: "form", private_metadata: privateMetadata, state: { values } },
+  response_urls: []
+})
+
+const input = (value: string | null) => ({ field: { type: "plain_text_input", value } })
+
+describe("normalizeInteraction", () => {
+  const normalize = (payload: unknown) => SlackChat.normalizeInteraction(payload, { teamId: team })
+
+  it("ignores what the adapter did not build, recorded from Slack", () => {
+    assert.isTrue(Option.isNone(normalize(recorded.block_actions)))
+    assert.isTrue(Option.isNone(normalize(recorded.view_submission)))
+    assert.isTrue(Option.isNone(normalize(click({ type: "button", action_id: join + "0", url: "https://x.test" }))))
+    assert.isTrue(Option.isNone(normalize(click({ type: "button", action_id: "go", block_id: "theirs" }))))
+    assert.isTrue(Option.isNone(normalize(submit("theirs", {}))))
+    assert.isTrue(Option.isNone(normalize({ type: "shortcut" })))
+    assert.isTrue(Option.isNone(normalize("block_actions")))
+    assert.isTrue(Option.isNone(normalize({ ...click({ type: "button", action_id: "go" }), at: new Date(0) })))
+  })
+
+  it("gives a click its thread, message, value and raw payload without the token", () => {
+    const event = Option.getOrThrow(
+      normalize(click({ type: "button", action_id: "go", value: "v1" }, { thread_ts: "1794600000.000100" }))
+    )
+    assert.strictEqual(event._tag, "ButtonClicked")
+    if (event._tag !== "ButtonClicked") return
+    assert.deepStrictEqual(
+      [event.id, event.value, event.messageId, event.userId, event.thread.id],
+      ["go", "v1", "1794600001.000100", user.id, `${team}/${channel}/1794600000.000100`]
+    )
+    assert.isFalse("token" in (event.raw as object))
+    // A click on a thread's root is in the channel, not in its own thread.
+    const root = Option.getOrThrow(
+      normalize(click({ type: "button", action_id: "go" }, { thread_ts: "1794600001.000100" }))
+    )
+    assert.strictEqual(root.thread.id, `${team}/${channel}`)
+    assert.isFalse("value" in root)
+    const select = Option.getOrThrow(
+      normalize(click({ type: "static_select", action_id: "pick", selected_option: { value: "b" } }))
+    )
+    assert.deepStrictEqual([select._tag, (select as ChatInteraction.SelectChanged).value], ["SelectChanged", "b"])
+  })
+
+  it("gives a submit the click's origin and the consumer's metadata, which may hold the join", () => {
+    const metadata = `a${join}b`
+    const packed = ["chat1", channel, "1794600000.000100", "1794600001.000100", metadata].join(join)
+    // As JSON.parse gives it, with `__proto__` an own key.
+    const values = JSON.parse(
+      JSON.stringify({
+        proto: input("own"),
+        empty: input(null),
+        pick: { pick: { type: "static_select", selected_option: { value: "b" } } },
+        none: { none: { type: "static_select", selected_option: null } }
+      }).replace(`"proto"`, `"__proto__"`)
+    )
+    const event = Option.getOrThrow(normalize(submit(packed, values)))
+    assert.strictEqual(event._tag, "ModalSubmitted")
+    if (event._tag !== "ModalSubmitted") return
+    assert.deepStrictEqual(
+      [event.id, event.metadata, event.messageId, event.thread.id],
+      ["form", metadata, "1794600001.000100", `${team}/${channel}/1794600000.000100`]
+    )
+    assert.isTrue(Object.hasOwn(event.values, "__proto__"))
+    assert.strictEqual(event.values["__proto__"], "own")
+    assert.deepStrictEqual(Object.keys(event.values).sort(), ["__proto__", "pick"])
+    const bare = Option.getOrThrow(normalize(submit(["chat1", channel, "", "1794600001.000100"].join(join), {})))
+    assert.isFalse("metadata" in bare)
+    assert.strictEqual(bare.thread.id, `${team}/${channel}`)
+  })
+})
+
+const recording = () => {
+  const refused: Array = []
+  let onClick: () => Effect.Effect = () => Effect.succeed(ChatInteraction.ack)
+  let onSubmit: () => Effect.Effect = () => Effect.succeed(ChatInteraction.close)
+  return {
+    refused,
+    set click(f: typeof onClick) {
+      onClick = f
+    },
+    set submit(f: typeof onSubmit) {
+      onSubmit = f
+    },
+    layer: Layer.succeed(ChatInteraction.Handler, {
+      click: () => onClick(),
+      submit: () => onSubmit(),
+      refused: (_, error) => Effect.sync(() => void refused.push(error))
+    })
+  }
+}
+
+const modal = (metadata?: string) =>
+  ChatUi.Modal.make({
+    id: "form",
+    title: "Form",
+    ...(metadata === undefined ? {} : { metadata }),
+    elements: [ChatUi.TextInput.make({ id: "field", label: "Field" })]
+  })
+
+const packedFor = (metadata: string) => ["chat1", channel, "", "1794600001.000100", metadata].join(join)
+
+describe("SlackChat.interaction", () => {
+  const interact = (fake: ReturnType, handler: ReturnType, payload: unknown) =>
+    Effect.gen(function*() {
+      const slack = yield* SlackChat.SlackChat
+      return yield* slack.interaction(payload, { deadline: Duration.millis(50) })
+    }).pipe(Effect.provide(handler.layer), Effect.provide(slackLayer(fake)))
+
+  it.live("answers errors by field, and nothing for a close, an ack or a foreign payload", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest })
+      const handler = recording()
+      assert.isUndefined(yield* interact(fake, handler, submit(packedFor(""), {})))
+      assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
+      assert.isUndefined(yield* interact(fake, handler, recorded.block_actions))
+      handler.submit = () => Effect.succeed(ChatInteraction.errors({ field: "Too short" }))
+      assert.deepStrictEqual(
+        yield* interact(fake, handler, submit(packedFor(""), {})),
+        { response_action: "errors", errors: { field: "Too short" } }
+      )
+    }))
+
+  it.live("gives Late for a late submit and nothing for a late click", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest })
+      const handler = recording()
+      handler.submit = () => Effect.as(Effect.never, ChatInteraction.close)
+      handler.click = () => Effect.as(Effect.never, ChatInteraction.ack)
+      const late = yield* interact(fake, handler, submit(packedFor(""), {}))
+      assert.deepStrictEqual(late, ChatInteraction.Late.make({}))
+      assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
+    }))
+
+  it.live("opens a modal with the click's trigger, packing its origin beside the metadata", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest, "views.open": { ok: true, view: { id: "V1" } } })
+      const handler = recording()
+      handler.click = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("m") }))
+      const answer = yield* interact(
+        fake,
+        handler,
+        click({ type: "button", action_id: "go" }, { thread_ts: "1794600000.000100" })
+      )
+      assert.isUndefined(answer)
+      const [call] = fake.called("views.open")
+      assert.strictEqual(call.params.trigger_id, "trigger-1")
+      const view = JSON.parse(call.params.view)
+      assert.deepStrictEqual(
+        [view.callback_id, view.private_metadata, view.submit.text, view.blocks[0].block_id],
+        ["form", ["chat1", channel, "1794600000.000100", "1794600001.000100", "m"].join(join), "Submit", "field"]
+      )
+      assert.deepStrictEqual(handler.refused, [])
+    }))
+
+  it.live("refuses a modal Slack refuses, or that is too large, to Handler.refused, still acking", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest, "views.open": { ok: false, error: "expired_trigger_id" } })
+      const handler = recording()
+      handler.click = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal() }))
+      assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
+      handler.click = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("x".repeat(2_800)) }))
+      assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
+      assert.deepStrictEqual(
+        handler.refused.map((error) => [error.op, error.reason._tag, error.reason.detail]),
+        [["openModal", "NotFound", "interaction_expired"], ["openModal", "TooLarge", "modal_metadata_too_long"]]
+      )
+      assert.strictEqual(fake.called("views.open").length, 1)
+    }))
+})
+
+describe("layerInteractivity", () => {
+  const secret = "8f742231b10e8888abcd99yyyzzz85a5"
+
+  const sign = async (timestamp: string, body: string) => {
+    const encoder = new TextEncoder()
+    const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
+      "sign"
+    ])
+    const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, encoder.encode(`v0:${timestamp}:${body}`)))
+    return "v0=" + Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("")
+  }
+
+  const post = async (payload: unknown, options?: { readonly signature?: string }) => {
+    const body = new URLSearchParams({ payload: JSON.stringify(payload) }).toString()
+    const timestamp = String(Math.floor(Date.now() / 1000))
+    return new Request("http://localhost/slack/interactivity", {
+      method: "POST",
+      body,
+      headers: {
+        "content-type": "application/x-www-form-urlencoded",
+        "x-slack-request-timestamp": timestamp,
+        "x-slack-signature": options?.signature ?? await sign(timestamp, body)
+      }
+    })
+  }
+
+  it.live("answers a late submit 503, errors as JSON, and a bad signature 401", () =>
+    Effect.gen(function*() {
+      const handler = recording()
+      const app = SlackChat.layerInteractivity({
+        path: "/slack/interactivity",
+        signingSecret: Redacted.make(secret),
+        appId,
+        deadline: Duration.millis(50)
+      }).pipe(
+        Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
+        Layer.provide(Chat.layer),
+        Layer.provide(handler.layer),
+        Layer.provide(makeFake({ "auth.test": authTest }).layer)
+      )
+      const { dispose, handler: web } = HttpRouter.toWebHandler(app, { disableLogger: true })
+      const send = (payload: unknown, options?: { readonly signature?: string }) =>
+        Effect.promise(() => post(payload, options).then(web))
+
+      handler.submit = () => Effect.succeed(ChatInteraction.errors({ field: "Too short" }))
+      const errors = yield* send(submit(packedFor(""), {}))
+      assert.strictEqual(errors.status, 200)
+      assert.deepStrictEqual(yield* Effect.promise(() => errors.json()), {
+        response_action: "errors",
+        errors: { field: "Too short" }
+      })
+
+      handler.submit = () => Effect.as(Effect.never, ChatInteraction.close)
+      assert.strictEqual((yield* send(submit(packedFor(""), {}))).status, 503)
+
+      const closed = yield* send(click({ type: "button", action_id: "go" }))
+      assert.deepStrictEqual([closed.status, yield* Effect.promise(() => closed.text())], [200, ""])
+      assert.strictEqual((yield* send({ ...submit(packedFor(""), {}), api_app_id: "A0OTHER" })).status, 200)
+      assert.strictEqual((yield* send(submit(packedFor(""), {}), { signature: "v0=00" })).status, 401)
+      yield* Effect.promise(() => dispose())
+    }))
+})
diff --git a/packages/chat/slack/test/slack.ts b/packages/chat/slack/test/slack.ts
new file mode 100644
index 00000000000..ff56d28569f
--- /dev/null
+++ b/packages/chat/slack/test/slack.ts
@@ -0,0 +1,144 @@
+import * as SlackChat from "@effect/chat-slack/SlackChat"
+import { type Interactions, NoSuchElement } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import { appId, authTest, botUserId, makeFake, team } from "./utils.ts"
+
+const tim = "U080YLYB277"
+
+/**
+ * A Slack that keeps the messages the adapter posts, with their blocks, and
+ * records every view it opens. `interactions` is the conformance hook: it
+ * builds Slack's `block_actions` and `view_submission` payloads from what
+ * was posted and opened, sends them through `SlackChat.interaction` and
+ * keeps the answers.
+ */
+export const makeSlack = () => {
+  const messages = new Map()
+  const views: Array = []
+  const answers: Array = []
+  let next = 1794600000
+  let viewCount = 0
+
+  const fake = makeFake({
+    "auth.test": authTest,
+    "chat.postMessage": (params) => {
+      const ts = `${next++}.000100`
+      messages.set(ts, {
+        type: "message",
+        ts,
+        channel: params.channel,
+        ...(params.thread_ts === undefined ? {} : { thread_ts: params.thread_ts }),
+        user: botUserId,
+        bot_id: "B0CCQH77VA5",
+        app_id: appId,
+        team,
+        text: params.text,
+        blocks: JSON.parse(params.blocks)
+      })
+      return { ok: true, channel: params.channel, ts }
+    },
+    "chat.update": (params) => {
+      const message = messages.get(params.ts)
+      if (message === undefined) return { ok: false, error: "message_not_found" }
+      message.text = params.text
+      message.blocks = JSON.parse(params.blocks)
+      return { ok: true, channel: params.channel, ts: params.ts }
+    },
+    "chat.delete": (params) => messages.delete(params.ts) ? { ok: true } : { ok: false, error: "message_not_found" },
+    "conversations.replies": (params) => {
+      const message = messages.get(params.ts)
+      return message === undefined ? { ok: false, error: "thread_not_found" } : { ok: true, messages: [message] }
+    },
+    "views.open": (params) => {
+      const view = { ...JSON.parse(params.view), id: "V" + ++viewCount }
+      views.push(view)
+      return { ok: true, view }
+    }
+  })
+
+  /** The view the last click opened, until a submit closes it. */
+  let opened: any
+
+  /** The service the hook delivers through, set by `bind`. */
+  let service: SlackChat.SlackChat["Service"] | undefined
+
+  const deliver = Effect.fnUntraced(function*(payload: Record) {
+    const answer = yield* service!.interaction({ ...payload, token: "verification", api_app_id: appId })
+    answers.push(answer)
+    return answer
+  })
+
+  const user = { id: tim, username: "tim", name: "tim", team_id: team }
+
+  const interactions: Interactions = {
+    click: Effect.fnUntraced(function*(messageId, id, options) {
+      const message = messages.get(messageId)
+      const block = message?.blocks.find((block: any) => block.type === "actions")
+      const element = block?.elements.find((element: any) => element.action_id === id)
+      if (element === undefined) return yield* Effect.fail(new NoSuchElement({ messageId, id }))
+      const before = views.length
+      const value = element.type === "static_select" ? options?.option ?? element.options[0].value : undefined
+      yield* deliver({
+        type: "block_actions",
+        user,
+        team: { id: team, domain: "effectfulworkspace" },
+        container: { type: "message", message_ts: messageId, channel_id: message.channel, is_ephemeral: false },
+        trigger_id: "trigger-" + messageId,
+        channel: { id: message.channel, name: "scratch" },
+        message,
+        state: { values: {} },
+        response_url: "https://hooks.slack.test/actions",
+        actions: [{
+          ...element,
+          block_id: block.block_id,
+          ...(value === undefined ? {} : {
+            selected_option: element.options.find((option: any) => option.value === value)
+          }),
+          action_ts: "1794600000.000001"
+        }]
+      })
+      opened = views.length > before ? views[views.length - 1] : undefined
+    }),
+    submit: Effect.fnUntraced(function*(values) {
+      if (opened === undefined) return
+      const state: Record = {}
+      for (const block of opened.blocks) {
+        if (block.type !== "input") continue
+        const input = block.element
+        const value = values[block.block_id]
+        state[block.block_id] = {
+          [input.action_id]: input.type === "plain_text_input"
+            ? { type: input.type, value: value ?? null }
+            : {
+              type: input.type,
+              selected_option: value === undefined
+                ? null
+                : input.options.find((option: any) => option.value === value) ?? null
+            }
+        }
+      }
+      const answer: any = yield* deliver({
+        type: "view_submission",
+        team: { id: team, domain: "effectfulworkspace" },
+        user,
+        trigger_id: "trigger-submit",
+        view: { ...opened, team_id: team, state: { values: state }, hash: "1794600000.abc", app_id: appId },
+        response_urls: []
+      })
+      // An `errors` answer, or none in time, keeps the view open.
+      if (answer?.response_action !== "errors" && answer?._tag !== "Late") opened = undefined
+    })
+  }
+
+  return {
+    fake,
+    bind: Effect.tap(SlackChat.SlackChat, (slack) =>
+      Effect.sync(() => {
+        service = slack
+      })),
+    messages,
+    views,
+    answers,
+    interactions
+  }
+}

From 1d732555bf8c17db06e740f9ff6ffb9fd93902cb Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 11:54:30 +0000
Subject: [PATCH 40/89] chat-slack: document the modal title, label and submit
 label rules

---
 packages/chat/slack/src/SlackChat.ts | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 83f3abcc51f..4d133924645 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -95,6 +95,13 @@ export interface SlackUser {
  *   handler through `ChatInteraction.handle` inside `deadline` (2.5
  *   seconds by default, the handler's share of Slack's 3), opens a modal
  *   with `views.open` and calls `Handler.refused` when it can't.
+ * - A modal's title is held to 24 code points, each input label to 2,000 and
+ *   the modal's id to 255. These are not on the descriptor. A modal past one
+ *   of them is not opened: `Handler.refused` gets `TooLarge`, and the click
+ *   is still acked. A portable modal keeps its title to 24.
+ * - Slack needs a submit button on a modal with inputs, so a modal with no
+ *   `submitLabel` gets the English "Submit". Pass `submitLabel` to localise
+ *   it.
  * - It succeeds with the body to answer Slack with: the JSON of the 200 on
  *   the Request URL, or the `payload` of the envelope ack on Socket Mode.
  *   `undefined` is an empty answer: an ack, a close, a late click, or a

From ddda5831453ebbf6e2438bbc68d9c483df319a3a Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 11:58:59 +0000
Subject: [PATCH 41/89] Hold trailing graphemes in ChatMarkdown stream releases

---
 .changeset/effect-chat.md                     |  2 +-
 packages/effect/src/chat/ChatMarkdown.ts      | 18 ++++++++----
 .../effect/test/chat/ChatMarkdown.test.ts     | 29 +++++++++++++++++--
 3 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 490342acd03..73b3e6f253a 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -2,4 +2,4 @@
 "effect": patch
 ---
 
-Add unstable `effect/chat` APIs for chat bots, long and streamed Markdown with safe refused-file fallback, and in-memory adapter conformance testing.
+Add unstable `effect/chat` APIs for chat bots, grapheme-safe long and streamed Markdown with safe refused-file fallback, and in-memory adapter conformance testing.
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index 41434ee13c6..b3ea2450ac1 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -293,7 +293,7 @@ const fitCut = (
 
 let segmenter: Intl.Segmenter | undefined
 
-/** The grapheme clusters of `text`. `Intl.Segmenter` is created on first use, so only a cut needs it. */
+/** The grapheme clusters of `text`. `Intl.Segmenter` is created on first use. */
 const graphemes = (text: string): Intl.Segments =>
   (segmenter ??= new Intl.Segmenter(undefined, { granularity: "grapheme" })).segment(text)
 
@@ -323,11 +323,17 @@ const holdLimit = 300
 const releasable = (pending: string, fence: Fence | undefined): string => {
   const lines = scanLines(pending, fence, false)
   const complete = lines.length === 0 ? 0 : lines[lines.length - 1].end
-  if (fenceAt(lines, fence, complete) !== undefined) return pending
-  const tail = pending.slice(complete)
-  if (tail.length <= holdLimit) return pending.slice(0, complete)
-  const space = tail.search(/\s\S*$/)
-  return space === -1 ? pending : pending.slice(0, complete + space + 1)
+  if (complete === pending.length) return pending
+  if (fenceAt(lines, fence, complete) === undefined) {
+    const tail = pending.slice(complete)
+    if (tail.length <= holdLimit) return pending.slice(0, complete)
+    const space = tail.search(/\s\S*$/)
+    if (space !== -1) return pending.slice(0, complete + space + 1)
+  }
+  // The next delta may still extend the trailing cluster, even inside a fence.
+  let last = 0
+  for (const cluster of graphemes(pending)) last = cluster.index
+  return pending.slice(0, last)
 }
 
 const utf8Length = (text: string): number => {
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index ce574df00d7..892dc4e9dea 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -460,12 +460,35 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(calls.map((call) => [call.op, call.markdown]), [
           ["nativeStream.start", "hello\n"],
           ["nativeStream.append", "x < y\n"],
-          ["nativeStream.append", "< y\n```ts\ncode"],
+          ["nativeStream.append", "< y\n```ts\ncod"],
           ["nativeStream.append", "< y\n```ts\ncode\n```"],
           ["nativeStream.stop", undefined]
         ])
       }).pipe(Effect.provide(ChatTest.layer())))
 
+    for (const prefix of ["~~~\n", "x".repeat(301)]) {
+      for (const [first, rest, whole] of [["🇺", "🇸", "🇺🇸"], ["1", "\uFE0F\u20E3", "1️⃣"]]) {
+        it.effect(
+          `holds ${whole} across deltas ${prefix === "~~~\n" ? "inside a fence" : "in a long line"}`,
+          () =>
+            Effect.gen(function*() {
+              const { test, thread } = yield* setup
+              const { end, send } = yield* feed(thread, { recipient: "U1" })
+              yield* send(prefix + first)
+              assert.deepStrictEqual((yield* test.calls).map((call) => call.markdown), [prefix])
+              yield* send(rest + "\n")
+              assert.deepStrictEqual((yield* test.calls).map((call) => call.markdown), [prefix, whole + "\n"])
+              yield* send("z")
+              const result = yield* end
+              assert.strictEqual(joined(result.parts), prefix + whole + "\nz")
+              assert.deepStrictEqual(yield* texts(test, thread), [
+                prefix + whole + "\nz" + (prefix === "~~~\n" ? "\n~~~" : "")
+              ])
+            }).pipe(Effect.provide(ChatTest.layer()))
+        )
+      }
+    }
+
     it.effect("rolls a native stream over at a block boundary", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -854,8 +877,8 @@ describe("ChatMarkdown", () => {
         yield* Deferred.await(entered)
         yield* TestClock.adjust("6 seconds")
         yield* Fiber.join(interrupt)
-        // The closing fence was cut off with the append.
-        assert.deepStrictEqual(yield* texts(test, thread), ["~~~\ncode"])
+        // The held cluster and closing fence were cut off with the append.
+        assert.deepStrictEqual(yield* texts(test, thread), ["~~~\ncod"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
     /** Runs `stream` over a queue the test can fail. */

From c69fedc8a5c373b80dd6e9f68b21824f5a1c0199 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 12:04:32 +0000
Subject: [PATCH 42/89] Keep preceding grapheme when a stream delta splits a
 surrogate

---
 packages/effect/src/chat/ChatMarkdown.ts       |  4 +++-
 packages/effect/test/chat/ChatMarkdown.test.ts | 12 ++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index b3ea2450ac1..d6734d0d4fb 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -331,8 +331,10 @@ const releasable = (pending: string, fence: Fence | undefined): string => {
     if (space !== -1) return pending.slice(0, complete + space + 1)
   }
   // The next delta may still extend the trailing cluster, even inside a fence.
+  // A split surrogate may complete a code point that extends the preceding cluster.
+  const text = /[\ud800-\udbff]$/.test(pending) ? pending.slice(0, -1) : pending
   let last = 0
-  for (const cluster of graphemes(pending)) last = cluster.index
+  for (const cluster of graphemes(text)) last = cluster.index
   return pending.slice(0, last)
 }
 
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index 892dc4e9dea..0480493b7dd 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -467,9 +467,17 @@ describe("ChatMarkdown", () => {
       }).pipe(Effect.provide(ChatTest.layer())))
 
     for (const prefix of ["~~~\n", "x".repeat(301)]) {
-      for (const [first, rest, whole] of [["🇺", "🇸", "🇺🇸"], ["1", "\uFE0F\u20E3", "1️⃣"]]) {
+      for (
+        const [first, rest, whole] of [
+          ["🇺", "🇸", "🇺🇸"],
+          ["🇺\uD83C", "\uDDF8", "🇺🇸"],
+          ["1", "\uFE0F\u20E3", "1️⃣"]
+        ]
+      ) {
         it.effect(
-          `holds ${whole} across deltas ${prefix === "~~~\n" ? "inside a fence" : "in a long line"}`,
+          `holds ${whole} split at ${first.length} across deltas ${
+            prefix === "~~~\n" ? "inside a fence" : "in a long line"
+          }`,
           () =>
             Effect.gen(function*() {
               const { test, thread } = yield* setup

From c6b05eb9c6e6ace3a801a49a2ddec414ed1a3ffc Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 13:14:43 +0000
Subject: [PATCH 43/89] Preserve refused overflow text and bound Slack webhook
 requests

---
 .changeset/chat-slack.md                      |  2 +-
 .changeset/effect-chat.md                     |  2 +-
 packages/chat/slack/src/internal/webhook.ts   | 12 +++---
 packages/chat/slack/test/webhook.test.ts      | 40 +++++++++++++++++++
 packages/effect/src/chat/ChatMarkdown.ts      | 33 ++++++++++-----
 .../effect/test/chat/ChatMarkdown.test.ts     | 17 ++++++++
 6 files changed, 88 insertions(+), 18 deletions(-)

diff --git a/.changeset/chat-slack.md b/.changeset/chat-slack.md
index 503c9150da0..255ceb85a57 100644
--- a/.changeset/chat-slack.md
+++ b/.changeset/chat-slack.md
@@ -3,4 +3,4 @@
 "effect": patch
 ---
 
-Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook, native streaming replies, the agent stop button, all-or-nothing posts with files, and buttons, selects and modals through `layerInteractivity` or `SlackChat.interaction`. Add the `StopRequested` chat event.
+Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook with a whole-request deadline, native streaming replies, the agent stop button, all-or-nothing posts with files, and buttons, selects and modals through `layerInteractivity` or `SlackChat.interaction`. Add the `StopRequested` chat event.
diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 73b3e6f253a..9c137b877c9 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -2,4 +2,4 @@
 "effect": patch
 ---
 
-Add unstable `effect/chat` APIs for chat bots, grapheme-safe long and streamed Markdown with safe refused-file fallback, and in-memory adapter conformance testing.
+Add unstable `effect/chat` APIs for chat bots, grapheme-safe long and streamed Markdown with refused-file fallback that preserves overflow text, and in-memory adapter conformance testing.
diff --git a/packages/chat/slack/src/internal/webhook.ts b/packages/chat/slack/src/internal/webhook.ts
index 68464f37d0b..537bb9bbf9e 100644
--- a/packages/chat/slack/src/internal/webhook.ts
+++ b/packages/chat/slack/src/internal/webhook.ts
@@ -122,8 +122,8 @@ export interface Options {
  * - An envelope for another app or workspace, or of another type, is
  *   answered 200 and dropped, so Slack does not retry it.
  * - 503 when the bot user can't be read, the handler fails `NotAccepted`,
- *   or reading the bot user and running the handler take longer than the
- *   deadline. Slack then retries.
+ *   or the whole request (including its body and verification) takes longer
+ *   than the deadline. Slack then retries.
  *
  * @internal
  */
@@ -149,7 +149,6 @@ export const handleRequest = (
     }
     if (envelope.type !== "event_callback" || envelope.api_app_id !== options.appId) return ok
     const callback = envelope
-    // The deadline covers the bot user lookup as well as the handlers.
     const handled = yield* Effect.gen(function*() {
       const botUserId = yield* Effect.option(options.botUserId)
       if (Option.isNone(botUserId)) return false
@@ -157,12 +156,13 @@ export const handleRequest = (
       yield* Effect.forEach(events, options.handle, { discard: true })
       return true
     }).pipe(
-      Effect.timeoutOption(options.deadline),
-      Effect.map((done) => Option.isSome(done) && done.value),
       Effect.catchTag("NotAccepted", () => Effect.succeed(false))
     )
     return handled ? ok : status(503)
-  })
+  }).pipe(
+    Effect.timeoutOption(options.deadline),
+    Effect.map(Option.getOrElse(() => status(503)))
+  )
 
 /** @internal */
 export interface InteractivityOptions {
diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts
index 3a3c7186272..ba7802d7274 100644
--- a/packages/chat/slack/test/webhook.test.ts
+++ b/packages/chat/slack/test/webhook.test.ts
@@ -7,11 +7,13 @@ import type * as ChatEvent from "effect/chat/ChatEvent"
 import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
+import * as Fiber from "effect/Fiber"
 import * as HttpRouter from "effect/http/HttpRouter"
 import * as HttpServerRequest from "effect/http/HttpServerRequest"
 import * as HttpServerResponse from "effect/http/HttpServerResponse"
 import * as Layer from "effect/Layer"
 import * as Redacted from "effect/Redacted"
+import { TestClock } from "effect/testing"
 import { appId, authTest, botUserId, makeFake, messageEnvelope, team } from "./utils.ts"
 
 const secret = "8f742231b10e8888abcd99yyyzzz85a5"
@@ -152,6 +154,44 @@ describe("webhook", () => {
       assert.strictEqual(slowBot.events.length, 0)
     }))
 
+  it.effect("layerWebhook bounds a request whose body never finishes", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest })
+      const events: Array = []
+      const app = SlackChat.layerWebhook({
+        path: "/slack/events",
+        signingSecret: Redacted.make(secret),
+        appId,
+        deadline: Duration.seconds(2)
+      }).pipe(
+        Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
+        Layer.provide(Chat.layer),
+        Layer.provide(Layer.succeed(ChatHandler, { handle: (event) => Effect.sync(() => void events.push(event)) })),
+        Layer.provide(fake.layer)
+      )
+      const router = yield* HttpRouter.toHttpEffect(app)
+      let cancelled = false
+      const web = new Request("http://localhost/slack/events", {
+        method: "POST",
+        body: new ReadableStream({
+          cancel: () => {
+            cancelled = true
+          }
+        }),
+        duplex: "half",
+        headers: { "x-slack-request-timestamp": now(), "x-slack-signature": "v0=" + "0".repeat(64) }
+      } as RequestInit)
+      const fiber = yield* router.pipe(
+        Effect.provideService(HttpServerRequest.HttpServerRequest, HttpServerRequest.fromWeb(web)),
+        Effect.forkChild
+      )
+      yield* TestClock.adjust(2000)
+      const response = yield* Fiber.join(fiber)
+      assert.strictEqual(response.status, 503)
+      assert.strictEqual(events.length, 0)
+      assert.isTrue(cancelled)
+    }))
+
   it.live("layerWebhook serves the path", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest })
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index d6734d0d4fb..8446ab7c3e2 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -426,7 +426,7 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect = []
 
@@ -683,10 +684,9 @@ const reply = (options: ReplyOptions): Effect.Effect {
-        if (unattachedNote === undefined || !isFileRefusal(exit)) return Effect.void
+      const withoutFiles = () => {
         // The platform may have refused the files: the last part goes out without them, ending in the note.
-        const text = unattachedNote(files!)
+        const text = unattachedNote!(files!)
         if (measureLast(markdown + text) <= limits.messageLength) {
           return Effect.asVoid(attempt(markdown + text, undefined, false, withActions))
         }
@@ -697,7 +697,12 @@ const reply = (options: ReplyOptions): Effect.Effect unattachedNote !== undefined && isFileRefusal(exit) ? withoutFiles() : Effect.void
+      )
     }
 
     /** Posts a message after the text that is not part of it: the unattached note, or the actions alone. */
@@ -1075,10 +1080,16 @@ const reply = (options: ReplyOptions): Effect.Effect
-          unattachedNote !== undefined && isFileRefusal(exit)
-            ? Effect.asVoid(attempt(unattachedNote(files).trim(), [], false))
-            : Effect.void)
+        return Effect.asVoid(Effect.map(attempt("", files, unattachedNote !== undefined), (exit) => {
+          if (unattachedNote === undefined || !isFileRefusal(exit)) return
+          // The overflow file was refused too. Drain the remaining text through
+          // the normal splitter, without files or another maxParts overflow.
+          overflowFilesRefused = true
+          overflowStart = undefined
+          maxParts = Infinity
+          nativeAllowed = false
+          current.native = false
+        }))
       })
 
     // --- the loop --------------------------------------------------------------
@@ -1231,7 +1242,9 @@ const reply = (options: ReplyOptions): Effect.Effect {
         assert.deepStrictEqual(messages.map((message) => message.attachments.length), [1])
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 5 } }))))
 
+    it.effect("preserves overflow as text when files are refused", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        yield* test.refuseFiles({ times: 2 })
+        const input = paragraphs(5, 20)
+        const result = yield* ChatMarkdown.post(thread, input, {
+          files,
+          maxParts: 1,
+          overflow: { file: { name: "rest.md" } },
+          unattachedNote: () => " (not attached)"
+        })
+        assert.strictEqual(joined(result.parts), input)
+        const messages = yield* test.messages(thread)
+        assert.strictEqual(messages.map((message) => message.text).join(""), input + " (not attached)")
+        assert.isTrue(messages.every((message) => message.attachments.length === 0))
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
+
     it.effect("sends the files with the overflow file", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup

From 0417a8551a533b2ace9199736ba91d5d90081d64 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 19:24:41 +0000
Subject: [PATCH 44/89] Close the effect/chat gaps found by the Janitor dogfood

- chat-discord: layerDispatchHook delivers gateway dispatches from dfx's
  DispatchHook, before the shard stores their sequence, so a host that is
  evicted resumes from its ShardStateStore without losing the event it
  was handling. NotAccepted fails the hook and a RESUME replays the event;
  a handler defect is logged and dropped.
- chat-discord: withPostOptions({ failIfNotExists: false }) lets a reply
  to a deleted message go out without its reference.
- effect/chat: ReplyTo.isSelf and ChatMessage.repliesToSelf. mentionsSelf
  is unchanged. checkMessage requires isSelf wherever authorId is set.
- effect/chat: ChatMarkdownError.remainingFence names the code fence
  remaining was cut in.
- chat-slack: layerWebhook logs each 503 with what caused it.
---
 .changeset/chat-discord.md                    |   2 +-
 .changeset/chat-slack.md                      |   2 +-
 .changeset/effect-chat.md                     |   2 +-
 packages/chat/discord/src/DiscordChat.ts      | 134 +++++++++-
 packages/chat/discord/src/internal/adapter.ts |   7 +-
 .../chat/discord/src/internal/normalize.ts    |   7 +-
 packages/chat/discord/src/internal/options.ts |   1 +
 .../chat/discord/test/DiscordChat.test.ts     |  20 ++
 packages/chat/discord/test/gateway.test.ts    | 230 ++++++++++++++++++
 packages/chat/discord/test/normalize.test.ts  |  10 +-
 packages/chat/slack/src/SlackChat.ts          |  10 +-
 packages/chat/slack/src/internal/webhook.ts   |  37 ++-
 packages/chat/slack/test/webhook.test.ts      |  32 ++-
 packages/effect/src/chat/ChatMarkdown.ts      |   9 +
 packages/effect/src/chat/ChatMessage.ts       |  35 ++-
 packages/effect/src/chat/ChatTest.ts          |  19 +-
 .../effect/test/chat/ChatMarkdown.test.ts     |  37 +++
 packages/effect/test/chat/ChatTest.test.ts    |  48 +++-
 18 files changed, 609 insertions(+), 33 deletions(-)
 create mode 100644 packages/chat/discord/test/gateway.test.ts

diff --git a/.changeset/chat-discord.md b/.changeset/chat-discord.md
index 1a93ce872d9..80a9ff153d5 100644
--- a/.changeset/chat-discord.md
+++ b/.changeset/chat-discord.md
@@ -2,4 +2,4 @@
 "@effect/chat-discord": patch
 ---
 
-Add `@effect/chat-discord`, an unstable Discord adapter for `effect/chat` built on dfx, with gateway dispatch, threads, reactions, post-then-edit streaming, and buttons, selects and modals through `DiscordChat.interaction` and `layerGatewayInteractions`.
+Add `@effect/chat-discord`, an unstable Discord adapter for `effect/chat` built on dfx, with gateway dispatch, threads, reactions, post-then-edit streaming, and buttons, selects and modals through `DiscordChat.interaction` and `layerGatewayInteractions`. `layerDispatchHook` delivers gateway events before dfx stores their sequence, for a host that resumes from a `ShardStateStore` of its own, and `withPostOptions({ failIfNotExists: false })` lets a reply to a deleted message go out without its reference.
diff --git a/.changeset/chat-slack.md b/.changeset/chat-slack.md
index 255ceb85a57..b8bceebf13a 100644
--- a/.changeset/chat-slack.md
+++ b/.changeset/chat-slack.md
@@ -3,4 +3,4 @@
 "effect": patch
 ---
 
-Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook with a whole-request deadline, native streaming replies, the agent stop button, all-or-nothing posts with files, and buttons, selects and modals through `layerInteractivity` or `SlackChat.interaction`. Add the `StopRequested` chat event.
+Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook with a whole-request deadline and a log line saying what caused each 503, native streaming replies, the agent stop button, all-or-nothing posts with files, and buttons, selects and modals through `layerInteractivity` or `SlackChat.interaction`. Add the `StopRequested` chat event.
diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 9c137b877c9..aebd0577612 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -2,4 +2,4 @@
 "effect": patch
 ---
 
-Add unstable `effect/chat` APIs for chat bots, grapheme-safe long and streamed Markdown with refused-file fallback that preserves overflow text, and in-memory adapter conformance testing.
+Add unstable `effect/chat` APIs for chat bots, grapheme-safe long and streamed Markdown with refused-file fallback that preserves overflow text, and in-memory adapter conformance testing. `ChatMessage.repliesToSelf` reads the new `replyTo.isSelf`, which `ChatTest.checkMessage` requires of an adapter wherever `replyTo.authorId` is set, and `ChatMarkdownError.remainingFence` names the code fence `remaining` was cut in.
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index fffbb44011d..e8256b4fcd5 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -1,8 +1,8 @@
 /**
  * The Discord adapter for `effect/chat`: the `Registry` layer, the
- * structural dispatch and interaction entries, the pure normalisers, two
- * default gateway layers, address helpers and the scoped post options. It runs on dfx: every REST
- * call goes through the `DiscordREST` in context.
+ * structural dispatch and interaction entries, the pure normalisers, the
+ * gateway layers, address helpers and the scoped post options. It runs on
+ * dfx: every REST call goes through the `DiscordREST` in context.
  *
  * **Details**
  *
@@ -20,7 +20,9 @@
  * @since 4.1.5
  */
 import { DiscordGateway } from "dfx/DiscordGateway"
+import { DispatchHook } from "dfx/DiscordGateway/Shard/DispatchHook"
 import { DiscordREST } from "dfx/DiscordREST"
+import * as Cause from "effect/Cause"
 import { Registry } from "effect/chat/ChatAdapter"
 import type { ChatError } from "effect/chat/ChatError"
 import type { ChatEvent, MessageCreated, ReactionAdded } from "effect/chat/ChatEvent"
@@ -134,7 +136,9 @@ const lookupTimeout = Duration.seconds(5)
  *   5 at most. A modal over that, or with a title or label over 45
  *   characters, reaches `Handler.refused` as `TooLarge`. Discord has no
  *   submit label, so `submitLabel` is not shown.
- * - `replyTo` sends a message reference.
+ * - `replyTo` sends a message reference. Discord refuses a reply to a
+ *   message that is gone, unless `withPostOptions({ failIfNotExists: false })`
+ *   lets it through as a plain message.
  * - Only `DEFAULT`, `REPLY`, `CHAT_INPUT_COMMAND` and
  *   `CONTEXT_MENU_COMMAND` messages are messages. A forward, a poll, a
  *   sticker or a components-only message is `DEFAULT` and comes through,
@@ -311,9 +315,15 @@ export const guildId = (event: ChatEvent): Option.Option => Normalize.gu
  *
  * **Details**
  *
- * Intents and sharding stay in the consumer's dfx config. An event that
- * fails with `NotAccepted` is logged and dropped, since the gateway does
- * not redeliver.
+ * - Intents and sharding stay in the consumer's dfx config. So does the
+ *   gateway session: dfx keeps the session id, the resume URL and the
+ *   sequence in the `ShardStateStore` given to `DiscordGatewayLive`.
+ * - It reads dfx's stream of dispatches, which a dispatch reaches after its
+ *   sequence is stored. An event that fails with `NotAccepted` is logged
+ *   and dropped, and so is one the process stops in the middle of: Discord
+ *   does not send it again.
+ *
+ * @see {@link layerDispatchHook} for a host that is stopped and started again
  *
  * @stability unstable
  * @category layers
@@ -338,6 +348,110 @@ export const layerGateway: Layer.Layer()
+ *
+ * const SessionStore = Layer.succeed(
+ *   ShardStateStore,
+ *   ShardStateStore.of({
+ *     forShard: ([id, count]) => {
+ *       const key = `${id}/${count}`
+ *       return {
+ *         get: Effect.sync(() => Option.fromUndefinedOr(storage.get(key))),
+ *         set: (state) => Effect.sync(() => void storage.set(key, state)),
+ *         clear: Effect.sync(() => void storage.delete(key))
+ *       }
+ *     }
+ *   })
+ * )
+ *
+ * // Still needs `DiscordChat`, a `ChatHandler` and the rest of dfx's gateway.
+ * export const ShardResuming = ShardLive.pipe(
+ *   Layer.provide([DiscordChat.layerDispatchHook, SessionStore])
+ * )
+ * ```
+ *
+ * @see {@link layerGateway} for a process that runs until it is told to stop
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layerDispatchHook: Layer.Layer = Layer.effect(
+  DispatchHook,
+  Effect.gen(function*() {
+    const discord = yield* DiscordChat
+    const handler = yield* ChatHandler
+    return (payload) => {
+      const t: unknown = payload.t
+      if (typeof t !== "string" || !handled.has(t)) return Effect.void
+      return discord.dispatch({ t, d: payload.d }).pipe(
+        Effect.provideService(ChatHandler, handler),
+        // Refused or interrupted: the sequence stays unstored and a RESUME replays the event.
+        Effect.catchCause((cause): Effect.Effect =>
+          Cause.hasFails(cause) || Cause.hasInterrupts(cause)
+            ? Effect.failCause(cause)
+            : Effect.logError("discord gateway: handler defect, event dropped", cause)
+        ),
+        Effect.orDie
+      )
+    }
+  })
+)
+
 /**
  * For a long-running process: subscribes to dfx's gateway and feeds every
  * `INTERACTION_CREATE` to `DiscordChat.interaction`.
@@ -425,6 +539,12 @@ export interface DiscordPostOptions {
    * either. False sends no flag on a post and clears it on an edit.
    */
   readonly suppressEmbeds?: boolean | undefined
+  /**
+   * What a post with `replyTo` does when that message is gone. Default
+   * true: Discord refuses the post. False sends `fail_if_not_exists: false`,
+   * and Discord posts the message without the reference.
+   */
+  readonly failIfNotExists?: boolean | undefined
   /** For `startThread`, in minutes. Default: the channel's. */
   readonly autoArchiveDuration?: 60 | 1440 | 4320 | 10080 | undefined
 }
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index 211144b4112..c348098d912 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -216,7 +216,12 @@ export const make = Effect.fnUntraced(function*(options: {
       allowed_mentions: allowedMentions(postOptions.notify),
       flags: flags(postOptions),
       ...(rows.length === 0 ? {} : { components: rows }),
-      ...(content.replyTo === undefined ? {} : { message_reference: { message_id: content.replyTo.messageId } }),
+      ...(content.replyTo === undefined ? {} : {
+        message_reference: {
+          message_id: content.replyTo.messageId,
+          ...(postOptions.failIfNotExists === false ? { fail_if_not_exists: false } : {})
+        }
+      }),
       ...(files.length === 0 ? {} : { attachments: files.map((file, i) => ({ id: String(i), filename: file.name })) })
     })
     const answer = yield* (files.length === 0
diff --git a/packages/chat/discord/src/internal/normalize.ts b/packages/chat/discord/src/internal/normalize.ts
index d001d9118a8..312f1527272 100644
--- a/packages/chat/discord/src/internal/normalize.ts
+++ b/packages/chat/discord/src/internal/normalize.ts
@@ -212,7 +212,12 @@ export const message = (
     mentions: mentionsOf(fields, text, context.botUserId),
     ...(replyId === undefined
       ? {}
-      : { replyTo: { messageId: replyId, ...(replyAuthor === undefined ? {} : { authorId: replyAuthor }) } }),
+      : {
+        replyTo: {
+          messageId: replyId,
+          ...(replyAuthor === undefined ? {} : { authorId: replyAuthor, isSelf: replyAuthor === context.botUserId })
+        }
+      }),
     attachments,
     timestamp: fields.timestamp,
     raw
diff --git a/packages/chat/discord/src/internal/options.ts b/packages/chat/discord/src/internal/options.ts
index 7d4f6536252..302266d7e03 100644
--- a/packages/chat/discord/src/internal/options.ts
+++ b/packages/chat/discord/src/internal/options.ts
@@ -9,6 +9,7 @@ export interface PostOptions {
     readonly repliedUser?: boolean | undefined
   } | undefined
   readonly suppressEmbeds?: boolean | undefined
+  readonly failIfNotExists?: boolean | undefined
   readonly autoArchiveDuration?: 60 | 1440 | 4320 | 10080 | undefined
 }
 
diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index ad429321bec..7a3f32e097e 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -95,6 +95,26 @@ describe("post", () => {
     )
   })
 
+  it.effect("failIfNotExists false lets a reply to a deleted message go out without its reference", () => {
+    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
+    return run(
+      fake,
+      Effect.gen(function*() {
+        const discord = yield* adapter
+        yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42" } })
+        yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42" } }).pipe(
+          DiscordChat.withPostOptions({ failIfNotExists: false })
+        )
+        yield* discord.post(channel, { markdown: "hi" }).pipe(DiscordChat.withPostOptions({ failIfNotExists: false }))
+        assert.deepStrictEqual(fake.called("createMessage").map(([, body]) => body.message_reference), [
+          { message_id: "42" },
+          { message_id: "42", fail_if_not_exists: false },
+          undefined
+        ])
+      })
+    )
+  })
+
   it.effect("fails TooLarge past 2,000 code points without a call", () => {
     const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
     return run(
diff --git a/packages/chat/discord/test/gateway.test.ts b/packages/chat/discord/test/gateway.test.ts
new file mode 100644
index 00000000000..fd3ccc02d6f
--- /dev/null
+++ b/packages/chat/discord/test/gateway.test.ts
@@ -0,0 +1,230 @@
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { assert, describe, it } from "@effect/vitest"
+import * as DiscordConfig from "dfx/DiscordConfig"
+import { DiscordWS, type MessageSend, Reconnect } from "dfx/DiscordGateway/DiscordWS"
+import { MesssagingLive } from "dfx/DiscordGateway/Messaging"
+import * as Shard from "dfx/DiscordGateway/Shard"
+import { type ShardState, ShardStateStore } from "dfx/DiscordGateway/Shard/StateStore"
+import { MemoryRateLimitStoreLive, RateLimiterLive } from "dfx/RateLimit"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
+import * as Context from "effect/Context"
+import * as Effect from "effect/Effect"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import * as Queue from "effect/Queue"
+import * as Redacted from "effect/Redacted"
+import * as Socket from "effect/socket/Socket"
+import * as TestClock from "effect/testing/TestClock"
+import { discordLayer, events, makeFake } from "./utils.ts"
+
+/** Storage that outlives a host: what a Durable Object keeps between evictions. */
+type Storage = Map
+
+const sessionStore = (storage: Storage) =>
+  Layer.succeed(
+    ShardStateStore,
+    ShardStateStore.of({
+      forShard: ([id, count]) => {
+        const key = `${id}/${count}`
+        return {
+          get: Effect.sync(() => Option.fromUndefinedOr(storage.get(key))),
+          set: (state) => Effect.sync(() => void storage.set(key, state)),
+          clear: Effect.sync(() => void storage.delete(key))
+        }
+      }
+    })
+  )
+
+const stored = (storage: Storage) => storage.get("0/1")
+
+const hello = { op: 10, d: { heartbeat_interval: 41_250 } }
+const ready = {
+  op: 0,
+  t: "READY",
+  s: 1,
+  d: { session_id: "session-1", resume_gateway_url: "wss://resume.example" }
+}
+const created = events("channel-message")[0]
+const message = (s: number) => ({ op: 0, t: created.t, s, d: created.d })
+
+/** Lets the shard's fibers run until `done`. */
+const until = Effect.fnUntraced(function*(done: () => boolean) {
+  for (let i = 0; i < 1000 && !done(); i++) yield* Effect.yieldNow
+  assert.isTrue(done(), "the shard did not get there")
+})
+
+/**
+ * One host: dfx's real shard over a socket the test drives, with
+ * `layerDispatchHook` and `storage` behind it. Closing the scope stops the
+ * host, as an eviction does.
+ */
+const host = Effect.fnUntraced(function*(
+  storage: Storage,
+  handle: (event: ChatEvent.ChatEvent) => Effect.Effect
+) {
+  const inbound = yield* Queue.unbounded()
+  const written: Array = []
+  let onConnecting: Effect.Effect = Effect.void
+  const socket = Layer.succeed(
+    DiscordWS,
+    DiscordWS.of({
+      connect: (options) =>
+        Effect.sync(() => {
+          onConnecting = options.onConnecting
+          return {
+            take: Queue.take(inbound),
+            setUrl: () => Effect.void,
+            write: (sent) => Effect.sync(() => void written.push(sent))
+          }
+        })
+    })
+  )
+  const context = yield* Layer.build(
+    Layer.effect(Shard.Shard, Shard.make).pipe(
+      Layer.provide([socket, MesssagingLive, RateLimiterLive, sessionStore(storage), DiscordChat.layerDispatchHook]),
+      Layer.provide([
+        MemoryRateLimitStoreLive,
+        DiscordConfig.layer({ token: Redacted.make("token") }),
+        Layer.succeed(ChatHandler, ChatHandler.of({ handle })),
+        discordLayer(makeFake({}))
+      ])
+    )
+  )
+  yield* Context.get(context, Shard.Shard).connect([0, 1]).pipe(
+    Effect.provideService(Socket.WebSocketConstructor, () => {
+      throw new Error("the test drives the socket")
+    })
+  )
+  /** What the shard wrote with `op`: 2 is IDENTIFY and 6 RESUME. */
+  const sent = (op: number): Array =>
+    written.filter((payload): payload is Exclude => payload !== Reconnect).filter((payload) =>
+      payload.op === op
+    ).map((payload) => payload.d)
+  return {
+    receive: (payload: unknown) => Queue.offer(inbound, payload),
+    sent,
+    reconnects: () => written.filter((payload) => payload === Reconnect).length,
+    /** The socket opened again, as dfx's does after it drops the connection. */
+    reopened: Effect.suspend(() => onConnecting)
+  }
+})
+
+describe("layerDispatchHook", () => {
+  it.effect("a host built again resumes the stored session, having handled each event before its sequence was stored", () => {
+    const storage: Storage = new Map()
+    const seen: Array<{ readonly id: string; readonly storedSequence: number | null | undefined }> = []
+    const handle = (event: ChatEvent.ChatEvent) =>
+      Effect.sync(() => {
+        if (event._tag === "MessageCreated") {
+          seen.push({ id: event.message.id, storedSequence: stored(storage)?.sequence })
+        }
+      })
+    return Effect.gen(function*() {
+      yield* Effect.scoped(Effect.gen(function*() {
+        const first = yield* host(storage, handle)
+        yield* first.receive(hello)
+        yield* until(() => first.sent(2).length === 1)
+        assert.strictEqual(first.sent(6).length, 0)
+        yield* first.receive(ready)
+        yield* first.receive(message(2))
+        yield* until(() => stored(storage)?.sequence === 2)
+        assert.deepStrictEqual(seen, [{ id: created.d.id, storedSequence: 1 }])
+      }))
+      assert.deepStrictEqual(stored(storage), {
+        sessionId: "session-1",
+        resumeUrl: "wss://resume.example",
+        sequence: 2
+      })
+      yield* Effect.scoped(Effect.gen(function*() {
+        const second = yield* host(storage, handle)
+        yield* second.receive(hello)
+        yield* until(() => second.sent(6).length === 1)
+        assert.deepStrictEqual(second.sent(6), [{ token: "token", session_id: "session-1", seq: 2 }])
+        assert.strictEqual(second.sent(2).length, 0)
+      }))
+    })
+  })
+
+  it.effect("an event refused with NotAccepted is not stored and comes back with the RESUME", () => {
+    const storage: Storage = new Map()
+    let attempts = 0
+    const handle = () => Effect.suspend(() => attempts++ === 0 ? Effect.fail(new NotAccepted()) : Effect.void)
+    return Effect.scoped(Effect.gen(function*() {
+      const gateway = yield* host(storage, handle)
+      yield* gateway.receive(hello)
+      yield* gateway.receive(ready)
+      yield* until(() => stored(storage)?.sequence === 1)
+      yield* gateway.receive(message(2))
+      yield* until(() => gateway.reconnects() === 1)
+      assert.strictEqual(attempts, 1)
+      assert.strictEqual(stored(storage)?.sequence, 1)
+      // dfx waits a second after the first failure before it resumes.
+      yield* gateway.reopened
+      yield* gateway.receive(hello)
+      yield* TestClock.adjust("1 second")
+      yield* until(() => gateway.sent(6).length === 1)
+      assert.deepStrictEqual(gateway.sent(6), [{ token: "token", session_id: "session-1", seq: 1 }])
+      // Discord replays what came after sequence 1.
+      yield* gateway.receive(message(2))
+      yield* until(() => stored(storage)?.sequence === 2)
+      assert.strictEqual(attempts, 2)
+      assert.strictEqual(gateway.reconnects(), 1)
+    }))
+  })
+
+  it.effect("a host stopped in the middle of an event resumes from before it", () => {
+    const storage: Storage = new Map()
+    let started = 0
+    const handle = () =>
+      Effect.suspend(() => {
+        started++
+        return Effect.never
+      })
+    return Effect.gen(function*() {
+      yield* Effect.scoped(Effect.gen(function*() {
+        const first = yield* host(storage, handle)
+        yield* first.receive(hello)
+        yield* first.receive(ready)
+        yield* first.receive(message(2))
+        yield* until(() => started === 1)
+      }))
+      assert.strictEqual(stored(storage)?.sequence, 1)
+      yield* Effect.scoped(Effect.gen(function*() {
+        const second = yield* host(storage, handle)
+        yield* second.receive(hello)
+        yield* until(() => second.sent(6).length === 1)
+        assert.deepStrictEqual(second.sent(6), [{ token: "token", session_id: "session-1", seq: 1 }])
+      }))
+    })
+  })
+
+  it.effect("a handler defect is logged and the event dropped, so the events after it still arrive", () => {
+    const storage: Storage = new Map()
+    let handled = 0
+    const handle = () => Effect.suspend(() => handled++ === 0 ? Effect.die(new Error("bug")) : Effect.void)
+    return Effect.scoped(Effect.gen(function*() {
+      const gateway = yield* host(storage, handle)
+      yield* gateway.receive(hello)
+      yield* gateway.receive(ready)
+      yield* gateway.receive(message(2))
+      yield* gateway.receive(message(3))
+      yield* until(() => stored(storage)?.sequence === 3)
+      assert.strictEqual(handled, 2)
+      assert.strictEqual(gateway.reconnects(), 0)
+    }))
+  })
+
+  it.effect("a dispatch the adapter does not read never reaches the handler", () => {
+    const storage: Storage = new Map()
+    let handled = 0
+    return Effect.scoped(Effect.gen(function*() {
+      const gateway = yield* host(storage, () => Effect.sync(() => void handled++))
+      yield* gateway.receive(hello)
+      yield* gateway.receive(ready)
+      yield* gateway.receive({ op: 0, t: "TYPING_START", s: 2, d: {} })
+      yield* until(() => stored(storage)?.sequence === 2)
+      assert.strictEqual(handled, 0)
+    }))
+  })
+})
diff --git a/packages/chat/discord/test/normalize.test.ts b/packages/chat/discord/test/normalize.test.ts
index 56740fe11d8..cb0724b21a9 100644
--- a/packages/chat/discord/test/normalize.test.ts
+++ b/packages/chat/discord/test/normalize.test.ts
@@ -4,6 +4,7 @@ import { decodeMessageFields, message, messageTypes } from "@effect/chat-discord
 import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { dedupeKey } from "effect/chat/ChatEvent"
+import * as ChatMessage from "effect/chat/ChatMessage"
 import { checkEvent, checkMessage } from "effect/chat/ChatTest"
 import * as ChatThread from "effect/chat/ChatThread"
 import * as Effect from "effect/Effect"
@@ -175,8 +176,11 @@ describe("normalize", () => {
       assert.deepStrictEqual(event.message.mentions, [])
       assert.deepStrictEqual(event.message.replyTo, {
         messageId: dispatch.d.message_reference.message_id,
-        authorId: botUserId
+        authorId: botUserId,
+        isSelf: true
       })
+      assert.isTrue(ChatMessage.repliesToSelf(event.message))
+      assert.isFalse(ChatMessage.mentionsSelf(event.message))
       assert.isFalse(event.message.author.isBot)
       assert.isFalse(event.message.author.isSelf)
       assert.strictEqual(event.message.author.id, tim)
@@ -450,6 +454,10 @@ describe("REST messages", () => {
     assert.strictEqual(read(step("other-bots", "other-bot-command-reply-empty").response)!.text, "")
     const reply = read(step("other-bots", "other-bot-reply").response)!
     assert.strictEqual(reply.replyTo?.messageId, "1103552216398303272")
+    // A reply to someone else's message, or to one whose author Discord left out, is not one to the bot.
+    assert.notStrictEqual(reply.replyTo?.isSelf, true)
+    assert.strictEqual(reply.replyTo?.isSelf === undefined, reply.replyTo?.authorId === undefined)
+    assert.isFalse(ChatMessage.repliesToSelf(reply))
   })
 
   it("the thread starter placeholder is not a message", () => {
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 4d133924645..c213dda01d0 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -333,10 +333,12 @@ export const parts: (thread: ChatThread) => Option.Option<{
  * - An envelope for another app, another workspace or of another type is
  *   answered 200 and dropped.
  * - The events go through `normalize` to the `ChatHandler`, one at a time.
- * - Answers 503, so Slack retries, when the handler fails `NotAccepted`, or
- *   when reading the bot user and running the handler take longer than
- *   `deadline` (2.5 seconds by default). Answers 413 past
- *   `maxBodyBytes` (1 MiB by default).
+ * - Answers 503, so Slack retries, when the handler fails `NotAccepted`,
+ *   when the bot user can't be read, or when the request, from reading its
+ *   body to the handler's return, takes longer than `deadline` (2.5 seconds
+ *   by default). Each of the three is logged with its own message, the
+ *   unreadable bot user as an error with its `ChatError` and the other two
+ *   as warnings. Answers 413 past `maxBodyBytes` (1 MiB by default).
  * - Slack redelivers on a timeout or an error, so an event can arrive twice.
  *   `ChatEvent.dedupeKey` gives the two deliveries equal keys.
  *
diff --git a/packages/chat/slack/src/internal/webhook.ts b/packages/chat/slack/src/internal/webhook.ts
index 537bb9bbf9e..f71da27157e 100644
--- a/packages/chat/slack/src/internal/webhook.ts
+++ b/packages/chat/slack/src/internal/webhook.ts
@@ -102,6 +102,17 @@ const isObject = (u: unknown): u is Record => typeof u === "obj
 const ok = HttpServerResponse.empty({ status: 200 })
 const status = (code: number) => HttpServerResponse.empty({ status: code })
 
+/**
+ * What is logged with each 503 of the Events API route.
+ *
+ * @internal
+ */
+export const unavailable = {
+  botUser: "slack webhook: the bot user could not be read, answered 503",
+  notAccepted: "slack webhook: the handler refused the event, answered 503",
+  deadline: "slack webhook: the request passed its deadline, answered 503"
+} as const
+
 /** @internal */
 export interface Options {
   readonly verify: (headers: { readonly [key: string]: string | undefined }, body: Uint8Array) => Effect.Effect
@@ -123,7 +134,8 @@ export interface Options {
  *   answered 200 and dropped, so Slack does not retry it.
  * - 503 when the bot user can't be read, the handler fails `NotAccepted`,
  *   or the whole request (including its body and verification) takes longer
- *   than the deadline. Slack then retries.
+ *   than the deadline. Slack then retries. Each is logged with its own
+ *   message, since the status alone does not say which it was.
  *
  * @internal
  */
@@ -149,19 +161,22 @@ export const handleRequest = (
     }
     if (envelope.type !== "event_callback" || envelope.api_app_id !== options.appId) return ok
     const callback = envelope
-    const handled = yield* Effect.gen(function*() {
-      const botUserId = yield* Effect.option(options.botUserId)
-      if (Option.isNone(botUserId)) return false
-      const events = normalize(callback, { teamId: options.teamId, botUserId: botUserId.value })
-      yield* Effect.forEach(events, options.handle, { discard: true })
-      return true
-    }).pipe(
-      Effect.catchTag("NotAccepted", () => Effect.succeed(false))
+    const botUserId = yield* Effect.catch(
+      Effect.asSome(options.botUserId),
+      (error) => Effect.as(Effect.logError(unavailable.botUser, error), Option.none())
+    )
+    if (Option.isNone(botUserId)) return status(503)
+    const events = normalize(callback, { teamId: options.teamId, botUserId: botUserId.value })
+    return yield* Effect.forEach(events, options.handle, { discard: true }).pipe(
+      Effect.as(ok),
+      Effect.catchTag("NotAccepted", () => Effect.as(Effect.logWarning(unavailable.notAccepted), status(503)))
     )
-    return handled ? ok : status(503)
   }).pipe(
     Effect.timeoutOption(options.deadline),
-    Effect.map(Option.getOrElse(() => status(503)))
+    Effect.flatMap(Option.match({
+      onNone: () => Effect.as(Effect.logWarning(unavailable.deadline), status(503)),
+      onSome: Effect.succeed
+    }))
   )
 
 /** @internal */
diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts
index ba7802d7274..a09f459fbd4 100644
--- a/packages/chat/slack/test/webhook.test.ts
+++ b/packages/chat/slack/test/webhook.test.ts
@@ -1,4 +1,4 @@
-import { handleRequest, makeVerifier, type Options } from "@effect/chat-slack/internal/webhook"
+import { handleRequest, makeVerifier, type Options, unavailable as logged } from "@effect/chat-slack/internal/webhook"
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
@@ -12,6 +12,7 @@ import * as HttpRouter from "effect/http/HttpRouter"
 import * as HttpServerRequest from "effect/http/HttpServerRequest"
 import * as HttpServerResponse from "effect/http/HttpServerResponse"
 import * as Layer from "effect/Layer"
+import * as Logger from "effect/Logger"
 import * as Redacted from "effect/Redacted"
 import { TestClock } from "effect/testing"
 import { appId, authTest, botUserId, makeFake, messageEnvelope, team } from "./utils.ts"
@@ -70,6 +71,18 @@ const handle = Effect.fnUntraced(function*(options: Partial, web: Reque
   return { status: response.status, response, events }
 })
 
+/** Runs `effect` and gives back what it logged: each entry's level and arguments. */
+const withLogs = (effect: Effect.Effect) => {
+  const logs: Array<{ readonly level: string; readonly message: ReadonlyArray }> = []
+  const logger = Logger.make((options) => {
+    logs.push({
+      level: options.logLevel,
+      message: Array.isArray(options.message) ? options.message : [options.message]
+    })
+  })
+  return Effect.map(Effect.provide(effect, Logger.layer([logger])), (value) => ({ value, logs }))
+}
+
 describe("webhook", () => {
   it.live("a signed event reaches the handler", () =>
     Effect.gen(function*() {
@@ -154,6 +167,23 @@ describe("webhook", () => {
       assert.strictEqual(slowBot.events.length, 0)
     }))
 
+  it.live("each 503 is logged with what caused it", () =>
+    Effect.gen(function*() {
+      const body = JSON.stringify(message)
+      const web = Effect.promise(() => request(body))
+      const noBot = yield* withLogs(handle({ botUserId: Effect.fail(unavailable) }, yield* web))
+      const refused = yield* withLogs(handle({ handle: () => Effect.fail(new NotAccepted()) }, yield* web))
+      const slow = yield* withLogs(handle({ handle: () => Effect.never, deadline: Duration.millis(20) }, yield* web))
+      const fine = yield* withLogs(handle({}, yield* web))
+      assert.deepStrictEqual([noBot, refused, slow, fine].map(({ value }) => value.status), [503, 503, 503, 200])
+      // The unreadable bot user carries the ChatError that says why.
+      assert.deepStrictEqual(noBot.logs, [{ level: "Error", message: [logged.botUser, unavailable] }])
+      assert.deepStrictEqual(refused.logs, [{ level: "Warn", message: [logged.notAccepted] }])
+      assert.deepStrictEqual(slow.logs, [{ level: "Warn", message: [logged.deadline] }])
+      assert.deepStrictEqual(fine.logs, [])
+      assert.strictEqual(new Set(Object.values(logged)).size, 3)
+    }))
+
   it.effect("layerWebhook bounds a request whose body never finishes", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest })
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index 8446ab7c3e2..015200b8c7b 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -97,6 +97,9 @@ export interface Result {
  *   write that failed `uncertain` and was never confirmed since, and
  *   `remaining` was never sent. The `text` of `posted`, then `uncertain`,
  *   then `remaining` is the input, with nothing in two of them.
+ * - `remainingFence` is set when `remaining` starts inside a code fence:
+ *   the line that opened it, with its info string. Text sent later starts
+ *   with that line and a newline, then `remaining`.
  * - `cause` is a `ChatError` from a write, the upstream's error `E`, or
  *   `Overflow` when the input outgrew `maxParts` and the overflow file.
  *
@@ -112,6 +115,7 @@ export interface Result {
 export class ChatMarkdownError extends Data.TaggedError("ChatMarkdownError")<{
   readonly posted: ReadonlyArray
   readonly remaining: string
+  readonly remainingFence?: string | undefined
   readonly uncertain?: string | undefined
   readonly cause:
     | { readonly _tag: "Chat"; readonly error: ChatError }
@@ -1170,9 +1174,14 @@ const reply = (options: ReplyOptions): Effect.Effect({
         posted,
         remaining: input.slice(from),
+        ...(fence === undefined ? {} : { remainingFence: fence.line }),
         ...(uncertain === "" ? {} : { uncertain }),
         cause
       })
diff --git a/packages/effect/src/chat/ChatMessage.ts b/packages/effect/src/chat/ChatMessage.ts
index f379b46b689..ec96a3df8c3 100644
--- a/packages/effect/src/chat/ChatMessage.ts
+++ b/packages/effect/src/chat/ChatMessage.ts
@@ -102,13 +102,21 @@ export type Attachment = typeof Attachment.Type
 /**
  * Schema for the message a message replies to.
  *
+ * **Details**
+ *
+ * - `authorId` is there when the platform says who wrote the message
+ *   replied to. Discord leaves it out once that message is deleted.
+ * - `isSelf` says whether that author is the bot. An adapter sets it on
+ *   every message it reads that has an `authorId`. A write ignores both.
+ *
  * @stability unstable
  * @category schemas
  * @since 4.1.5
  */
 export const ReplyTo = Schema.Struct({
   messageId: Schema.String,
-  authorId: Schema.optionalKey(Schema.String)
+  authorId: Schema.optionalKey(Schema.String),
+  isSelf: Schema.optionalKey(Schema.Boolean)
 }).annotate({ identifier: "ChatMessage.ReplyTo" })
 
 /**
@@ -173,8 +181,33 @@ export type ChatMessage = typeof ChatMessage.Type
  * A reply to the bot is not a mention. Whether it counts as one is the
  * consumer's policy.
  *
+ * @see {@link repliesToSelf} for a reply to one of the bot's messages
+ *
  * @stability unstable
  * @category predicates
  * @since 4.1.5
  */
 export const mentionsSelf = (message: ChatMessage): boolean => message.mentions.some((mention) => mention.isSelf)
+
+/**
+ * Returns whether the message replies to one of the bot's own messages.
+ *
+ * **When to use**
+ *
+ * Use with `mentionsSelf` when a reply to the bot should count as addressed
+ * to it, whether or not the reply pings.
+ *
+ * **Gotchas**
+ *
+ * - It reads `replyTo.isSelf`, so it is false when the platform does not say
+ *   who wrote the message replied to.
+ * - A message in a Slack thread is not a reply to the thread's first
+ *   message: Slack messages carry no `replyTo`.
+ *
+ * @see {@link mentionsSelf} for a mention of the bot
+ *
+ * @stability unstable
+ * @category predicates
+ * @since 4.1.5
+ */
+export const repliesToSelf = (message: ChatMessage): boolean => message.replyTo?.isSelf === true
diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index aa76dc2e012..cc31497ec36 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -339,7 +339,11 @@ const makeFake = (options: {
     },
     text: message.text,
     mentions: message.mentions,
-    ...(message.replyTo === undefined ? {} : { replyTo: message.replyTo }),
+    ...(message.replyTo === undefined ? {} : {
+      replyTo: message.replyTo.authorId === undefined
+        ? message.replyTo
+        : { ...message.replyTo, isSelf: message.replyTo.authorId === selfId }
+    }),
     attachments: message.attachments.map((stored) => stored.attachment),
     timestamp: message.timestamp,
     raw: {
@@ -785,6 +789,7 @@ const makeFake = (options: {
       isSelf: false,
       text,
       mentions: parseMentions(text, selfId),
+      // The author is read from the stored message, as a platform does, not from the caller.
       replyTo: message.replyTo === undefined ? undefined : {
         messageId: message.replyTo.messageId,
         ...(replyTarget === undefined ? {} : { authorId: replyTarget.authorId })
@@ -996,7 +1001,7 @@ const sameMentions = (a: ReadonlyArray, b: ReadonlyArray): boo
 const sameReplyTo = (a: ReplyTo | undefined, b: ReplyTo | undefined): boolean =>
   a === undefined || b === undefined
     ? a === b
-    : a.messageId === b.messageId && a.authorId === b.authorId
+    : a.messageId === b.messageId && a.authorId === b.authorId && a.isSelf === b.isSelf
 
 /**
  * Returns whether two reads of a message are the same message.
@@ -1100,6 +1105,15 @@ const checkMessageWith = Effect.fnUntraced(function*(rule: string, message: Chat
       () => "attachment " + (attachment.id.length > 0 ? "with a URL" : "without an id")
     )
   }
+  if (message.replyTo !== undefined) {
+    const { authorId, isSelf } = message.replyTo
+    yield* check(
+      rule,
+      (authorId === undefined) === (isSelf === undefined),
+      "replyTo.isSelf set exactly when replyTo.authorId is",
+      () => "authorId " + authorId + ", isSelf " + isSelf
+    )
+  }
   const decoded = yield* roundTrip(rule, MessageJson, message)
   yield* check(rule, sameMessage(message, decoded), "the same message after decoding", () => "a different message")
 })
@@ -1116,6 +1130,7 @@ const checkMessageWith = Effect.fnUntraced(function*(rule: string, message: Chat
  * - The message encodes and decodes through its Schema unchanged, `raw`
  *   included.
  * - Every attachment has an id and no URL.
+ * - `replyTo.isSelf` is set exactly when `replyTo.authorId` is.
  *
  * @stability unstable
  * @category testing
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index 67e032a7fb6..817f83f7d7b 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -141,6 +141,43 @@ describe("ChatMarkdown", () => {
         assert.strictEqual(joined(error.posted) + error.remaining, input)
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
 
+    it.effect("remainingFence is the fence remaining was cut in, and reopening it gives the rest back", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const code = Array.from({ length: 6 }, (_, i) => "const line" + i + " = " + i).join("\n")
+        const input = "Intro\n\n~~~ts title\n" + code + "\n~~~\n\nOutro"
+        const error = yield* Effect.flip(ChatMarkdown.post(thread, input, { maxParts: 2 }))
+        assert.strictEqual(error.cause._tag, "Overflow")
+        assert.strictEqual(joined(error.posted) + error.remaining, input)
+        assert.isTrue(error.remaining.startsWith("const line"), error.remaining)
+        assert.strictEqual(error.remainingFence, "~~~ts title")
+        // Sent again with the fence reopened, the thread reads as the input does.
+        yield* ChatMarkdown.post(thread, error.remainingFence + "\n" + error.remaining)
+        const sent = yield* texts(test, thread)
+        assert.isTrue(sent.every((text) => (text.match(/^~~~/gm) ?? []).length % 2 === 0), sent.join("\n---\n"))
+        assert.deepStrictEqual(
+          sent.flatMap((text) => text.split("\n")).filter((line) => line.startsWith("const line")),
+          code.split("\n")
+        )
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 60 } }))))
+
+    it.effect("remainingFence is unset outside a fence and when nothing remains", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const outside = yield* Effect.flip(
+          ChatMarkdown.post(thread, "```ts\ncode\n```\n\n" + paragraphs(4, 20), { maxParts: 2 })
+        )
+        assert.isTrue(outside.remaining.startsWith("Paragraph"), outside.remaining)
+        assert.isUndefined(outside.remainingFence)
+        yield* test.failNext("post", new ChatError.Forbidden({}))
+        const refused = yield* Effect.flip(ChatMarkdown.post(thread, "```ts\ncode"))
+        assert.deepStrictEqual([refused.posted, refused.remaining, refused.remainingFence], [
+          [],
+          "```ts\ncode",
+          undefined
+        ])
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
+
     it.effect("uploads the rest past maxParts as a file", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index e1d712e6e52..0270b188af1 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -1,6 +1,16 @@
 import { assert, describe, it } from "@effect/vitest"
 import { Effect, Exit, Option, Schema } from "effect"
-import { Chat, ChatAdapter, ChatError, ChatHandler, ChatInteraction, ChatTest, ChatThread, ChatUi } from "effect/chat"
+import {
+  Chat,
+  ChatAdapter,
+  ChatError,
+  ChatHandler,
+  ChatInteraction,
+  ChatMessage,
+  ChatTest,
+  ChatThread,
+  ChatUi
+} from "effect/chat"
 
 const kinds = { "@": "user", "@&": "role", "#": "channel", "!": "broadcast" } as const
 
@@ -429,6 +439,42 @@ describe("ChatTest", () => {
       assert.isTrue(Exit.isFailure(exit))
     }).pipe(Effect.provide(ChatTest.layer())))
 
+  it.effect("repliesToSelf is true for a reply to the bot's message, and is not a mention", () =>
+    Effect.gen(function*() {
+      const test = yield* ChatTest.ChatTest
+      const chat = yield* Chat.Chat
+      const thread = yield* test.makeThread()
+      const message = (event: { readonly _tag: string; readonly message?: ChatMessage.ChatMessage }) => {
+        assert(event._tag === "MessageCreated" && event.message !== undefined)
+        return event.message
+      }
+      const own = yield* chat.post(thread, { markdown: "from the bot" })
+      const plain = message(yield* test.userPosts(thread, { text: "no reply" }))
+      const toBot = message(yield* test.userPosts(thread, { text: "to the bot", replyTo: { messageId: own.id } }))
+      const toUser = message(yield* test.userPosts(thread, { text: "to a person", replyTo: { messageId: plain.id } }))
+      const toGone = message(yield* test.userPosts(thread, { text: "to nothing", replyTo: { messageId: "gone" } }))
+      assert.deepStrictEqual(toBot.replyTo, { messageId: own.id, authorId: test.selfId, isSelf: true })
+      assert.deepStrictEqual(toUser.replyTo, { messageId: plain.id, authorId: "user", isSelf: false })
+      assert.deepStrictEqual(toGone.replyTo, { messageId: "gone" })
+      assert.deepStrictEqual(
+        [plain, toBot, toUser, toGone].map(ChatMessage.repliesToSelf),
+        [false, true, false, false]
+      )
+      // A reply is still not a mention.
+      assert.isFalse(ChatMessage.mentionsSelf(toBot))
+      for (const read of [toBot, toUser, toGone]) yield* ChatTest.checkMessage(read, { platform: "test", parseMention })
+      // History reads the same.
+      const history = yield* chat.fetchMessage(thread, toBot.id)
+      assert.isTrue(ChatMessage.repliesToSelf(history))
+      // An author without isSelf, or isSelf without an author, is not a message an adapter may read.
+      for (const replyTo of [{ messageId: own.id, authorId: test.selfId }, { messageId: own.id, isSelf: true }]) {
+        const exit = yield* Effect.exit(
+          ChatTest.checkMessage({ ...toBot, replyTo }, { platform: "test", parseMention })
+        )
+        assert.isTrue(Exit.isFailure(exit))
+      }
+    }).pipe(Effect.provide(ChatTest.layer())))
+
   it.effect("ChatHandler.layer drops the bot's own messages unless deliverSelf", () =>
     Effect.gen(function*() {
       const test = yield* ChatTest.ChatTest

From d950f2d1c56fe46b32cb094e20e2e6ffb7df56ce Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Fri, 13 Nov 2026 19:40:29 +0000
Subject: [PATCH 45/89] Document download bytes, getUser raw and the adapter
 services

From the second Janitor report on EFF-3790. No API change.

- download: Stream.mkUint8Array collects the stream into one array.
- getUser: what raw holds on Slack (users.info, with team_id) and on
  Discord (the guild member with roles when in is given).
- Both adapter layers provide their service beside registering the
  adapter, so a consumer reads it from context next to Chat.
- history: a backward read that stops early has not reached the opener.
---
 packages/chat/discord/src/DiscordChat.ts      |  8 ++++++-
 .../chat/discord/test/DiscordChat.test.ts     |  4 ++++
 packages/chat/slack/src/SlackChat.ts          |  6 +++++
 packages/chat/slack/test/SlackChat.test.ts    |  4 ++++
 packages/effect/src/chat/ChatAdapter.ts       | 10 ++++++--
 packages/effect/test/chat/ChatTest.test.ts    | 24 ++++++++++++++++++-
 6 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index e8256b4fcd5..e30ae14a729 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -158,7 +158,13 @@ const lookupTimeout = Duration.seconds(5)
  *   parent channel, in place of Discord's placeholder. When the opener is
  *   deleted it starts at the first reply. A forum post's starter is in the
  *   thread itself.
- * - `getUser` with `in` gives the guild nick.
+ * - `getUser` with `in` gives the guild nick, and its `raw` is Discord's
+ *   guild member, whose `roles` are the member's role ids. Without `in`, in
+ *   a direct, or for someone who left the guild, `raw` is the user.
+ * - The layer provides the `DiscordChat` service as well as registering the
+ *   adapter, and makes every call through the `DiscordREST` it is given. A
+ *   consumer that needs more of Discord than `Chat` has reads either from
+ *   context beside `Chat`. dfx keeps one rate-limit state for both.
  * - There is no native streaming: streamed replies post, then edit, at
  *   least 1.5 seconds apart.
  *
diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index 7a3f32e097e..dfc8888050f 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -844,9 +844,13 @@ describe("getThread and getUser", () => {
         const inGuild = yield* discord.getUser(botUserId, { in: channel })
         assert.strictEqual(inGuild.name, "Janny")
         assert.isTrue(inGuild.isSelf && inGuild.isBot)
+        // raw is the guild member, so the roles are there to read.
+        assert.deepStrictEqual(inGuild.raw, { ...member, nick: "Janny" })
+        assert.isTrue(Array.isArray(member.roles))
         assert.deepStrictEqual(fake.called("getGuildMember"), [[guild, botUserId]])
         const plain = yield* discord.getUser(botUserId)
         assert.strictEqual(plain.name, "Janitor")
+        assert.deepStrictEqual(plain.raw, step("users", "get-user-bot").response)
         assert.strictEqual((yield* reason(discord.getUser("1570607260156297307"))).tag, "NotFound")
       })
     )
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index c213dda01d0..808610685d4 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -190,6 +190,12 @@ export class SlackChat extends Context.Service {
         assert.strictEqual(fake.called("auth.test").length, 1)
         const user = yield* slack.user("U0EXT")
         assert.include(user, { id: "U0EXT", teamId: "T0OTHER", name: "Ext", isRestricted: true, isStranger: true })
+        // The core op reads the same record, with the team on raw.
+        const core = yield* (yield* adapter).getUser("U0EXT")
+        assert.deepStrictEqual(core.raw, user.raw)
+        assert.include(core.raw, { team_id: "T0OTHER" })
       })
     )
   })
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index ae920b15fca..91197a3dce7 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -151,7 +151,10 @@ export interface ThreadInfo {
  *
  * **Details**
  *
- * `name` is the guild nick when `in` was given and the platform has one.
+ * - `name` is the guild nick when `in` was given and the platform has one.
+ * - `raw` is the platform's own record of the user. What the model has no
+ *   field for, such as a Slack user's team or a Discord member's roles, is
+ *   read from there. Each adapter documents what its `raw` holds.
  *
  * @stability unstable
  * @category models
@@ -182,8 +185,11 @@ export interface User {
  *   opener, whose `thread` is the thread's parent: the one message in a
  *   thread's history that is not addressed to that thread. Without an opener,
  *   history starts at the first reply, whether the opener was deleted or the
- *   platform's thread root is not a message.
+ *   platform's thread root is not a message. A `backward` read that stops
+ *   early has not reached the opener: `opener` reads it by itself.
  * - `download` fails with `TooLarge` as soon as more than `maxBytes` arrive.
+ *   It streams, so a file is never held whole unless the caller asks:
+ *   `Stream.mkUint8Array` collects the stream into one array.
  * - `startThread` returns the thread under `messageId`, created when there is
  *   none. It is get-or-create, and the only way from an opener to its thread.
  * - `opener` is the message a thread hangs off: `None` for a channel or
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index 0270b188af1..b24a00169c8 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -1,5 +1,5 @@
 import { assert, describe, it } from "@effect/vitest"
-import { Effect, Exit, Option, Schema } from "effect"
+import { Effect, Exit, Option, Schema, Stream } from "effect"
 import {
   Chat,
   ChatAdapter,
@@ -475,6 +475,28 @@ describe("ChatTest", () => {
       }
     }).pipe(Effect.provide(ChatTest.layer())))
 
+  it.effect("Stream.mkUint8Array collects a download into the file's bytes", () =>
+    Effect.gen(function*() {
+      const test = yield* ChatTest.ChatTest
+      const chat = yield* Chat.Chat
+      const thread = yield* test.makeThread()
+      // Larger than one chunk of the fake's download.
+      const content = Uint8Array.from({ length: 3000 }, (_, i) => i % 251)
+      const event = yield* test.userPosts(thread, {
+        text: "a file",
+        files: [{ name: "data.bin", contentType: "application/octet-stream", content }]
+      })
+      assert(event._tag === "MessageCreated")
+      const [attachment] = event.message.attachments
+      const download = chat.download(thread, attachment, { maxBytes: content.length })
+      assert.isAbove((yield* Stream.runCollect(download)).length, 1)
+      assert.deepStrictEqual(yield* Stream.mkUint8Array(download), content)
+      const error = yield* Effect.flip(
+        Stream.mkUint8Array(chat.download(thread, attachment, { maxBytes: content.length - 1 }))
+      )
+      assert.strictEqual(error.reason._tag, "TooLarge")
+    }).pipe(Effect.provide(ChatTest.layer())))
+
   it.effect("ChatHandler.layer drops the bot's own messages unless deliverSelf", () =>
     Effect.gen(function*() {
       const test = yield* ChatTest.ChatTest

From f4152d1c84784e584a270ad2797638aa814134b1 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 19:14:27 +0000
Subject: [PATCH 46/89] Add slash commands, private replies and followUp to
 effect/chat

---
 .changeset/effect-chat-commands.md            |  15 +
 packages/effect/src/chat/Chat.ts              |   3 +
 packages/effect/src/chat/ChatAdapter.ts       |  14 +
 packages/effect/src/chat/ChatError.ts         |   9 +-
 packages/effect/src/chat/ChatInteraction.ts   | 376 +++++++++++++++---
 packages/effect/src/chat/ChatTest.ts          | 344 ++++++++++++++--
 .../effect/test/chat/ChatInteraction.test.ts  | 136 ++++++-
 packages/effect/test/chat/ChatTest.test.ts    |  56 ++-
 .../typetest/chat/ChatInteraction.tst.ts      |  43 ++
 9 files changed, 885 insertions(+), 111 deletions(-)
 create mode 100644 .changeset/effect-chat-commands.md

diff --git a/.changeset/effect-chat-commands.md b/.changeset/effect-chat-commands.md
new file mode 100644
index 00000000000..9a14849b0e7
--- /dev/null
+++ b/.changeset/effect-chat-commands.md
@@ -0,0 +1,15 @@
+---
+"effect": patch
+---
+
+Add slash commands and private replies to `effect/chat`. `ChatInteraction.command` defines a command with at most one text argument, which arrives as `CommandInvoked` and goes to `Handler.command`. A command handler answers with `respond`, `defer` or a modal's `open`, and `respond` and `defer` are private by default. `Chat.followUp` sends the answer a `Defer` promised, within `limits.followUpAge`. `ChatTest` gains `command`, a `submit` and `interact` that take a command, the hook's optional `command` and the `command/*` rules.
+
+Breaking for code written against the unreleased `effect/chat` APIs:
+
+- `ModalSubmitted.messageId` is optional, since a modal a command opened has no message. The typed submit's `messageId` is `string | undefined`, and `checkInteraction` no longer requires it.
+- `Handler` needs a `command`, and `refused` can be given a `CommandInvoked`.
+- `Interaction` gains `CommandInvoked`, and `handle` can give `Respond` and `Defer`.
+- `Capability` gains `commands` and `ephemeral`, and `ChatTest`'s default capabilities include both.
+- `Ops`, `ChatAdapter` and the `Chat` service gain `followUp`. A third-party adapter stops compiling until it has one: one without commands fails `Unsupported` naming `commands`.
+
+The conformance rule `unsupported/commands` runs against every adapter, without a new capability. A third-party adapter whose `followUp` does anything but fail `Unsupported` naming `commands` will start failing it.
diff --git a/packages/effect/src/chat/Chat.ts b/packages/effect/src/chat/Chat.ts
index a84560148a7..ad331b8b5b9 100644
--- a/packages/effect/src/chat/Chat.ts
+++ b/packages/effect/src/chat/Chat.ts
@@ -41,6 +41,7 @@ import { RetriesDisabled } from "./internal/retries.ts"
  * - Every op takes an address and goes to the adapter for
  *   `thread.platform`, failing with `NoAdapter` when there is none.
  * - `getUser` takes the platform first, because a bare user id names none.
+ * - `followUp` is routed by the platform of the deferred command's thread.
  * - `descriptor` returns a platform's capabilities and limits.
  * - Each call runs in a `Chat.{op}` span whose attributes are the platform, the
  *   op and, on failure, the error reason and retry value.
@@ -120,6 +121,8 @@ const make = Effect.sync(() => {
     getThread: (thread) => route(thread.platform, "getThread", (adapter) => adapter.getThread(thread)),
     opener: (thread) => route(thread.platform, "opener", (adapter) => adapter.opener(thread)),
     getUser: (platform, id, options) => route(platform, "getUser", (adapter) => adapter.getUser(id, options)),
+    followUp: (deferred, content) =>
+      route(deferred.command.thread.platform, "followUp", (adapter) => adapter.followUp(deferred, content)),
     descriptor: (platform) => route(platform, "descriptor", (adapter) => Effect.succeed(adapter.descriptor))
   })
 
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index 91197a3dce7..e0363b47f90 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -31,6 +31,7 @@ import type * as Stream from "../Stream.ts"
 import type { Capability } from "./ChatError.ts"
 import { ChatError, TooLarge } from "./ChatError.ts"
 import type { ThreadKind } from "./ChatEvent.ts"
+import type { Defer } from "./ChatInteraction.ts"
 import type { Attachment, ChatMessage, ReplyTo } from "./ChatMessage.ts"
 import type { ChatThread } from "./ChatThread.ts"
 import type { Action } from "./ChatUi.ts"
@@ -71,6 +72,8 @@ import { RetriesDisabled } from "./internal/retries.ts"
  *   as `messageLength` is. The adapter checks them exactly and fails
  *   `TooLarge`: before the call for a message's elements, and before it
  *   opens a modal.
+ * - `limits.followUpAge` is there exactly when `commands` is: how long after
+ *   a command its `followUp` still works.
  *
  * **Gotchas**
  *
@@ -100,6 +103,8 @@ export interface Descriptor {
     readonly modalMetadataLength?: number | undefined
     /** How many inputs and texts one modal may hold. */
     readonly modalFields?: number | undefined
+    /** How long after a command its `followUp` still works. */
+    readonly followUpAge?: Duration.Duration | undefined
   }
 }
 
@@ -199,6 +204,11 @@ export interface User {
  *   `Unsupported` before the call, naming `buttons` or `selects`. An
  *   `edit` replaces the whole message, so an edit without `actions`
  *   removes them.
+ * - `followUp` sends the answer a command's `Defer` promised, to whoever
+ *   its `visibility` names. It is routed by `deferred.command.thread`, sent
+ *   once per deferral and never retried. It takes no files. It fails
+ *   `NotFound` with detail `interaction_expired` past `limits.followUpAge`,
+ *   and `Unsupported` without `commands`.
  *
  * @stability unstable
  * @category models
@@ -241,6 +251,10 @@ export interface Ops {
     id: string,
     options?: { readonly in?: ChatThread | undefined }
   ) => Effect.Effect
+  readonly followUp: (deferred: Defer, content: {
+    readonly markdown: string
+    readonly actions?: ReadonlyArray | undefined
+  }) => Effect.Effect
 }
 
 /**
diff --git a/packages/effect/src/chat/ChatError.ts b/packages/effect/src/chat/ChatError.ts
index d31cae882bb..f94eaf4b654 100644
--- a/packages/effect/src/chat/ChatError.ts
+++ b/packages/effect/src/chat/ChatError.ts
@@ -54,9 +54,12 @@ export type Retry = typeof Retry.Type
  * **Details**
  *
  * - `buttons` covers buttons and link buttons, `selects` selects on a
- *   message, and `modals` opening a modal from a click.
+ *   message, and `modals` opening a modal from a click or a command.
  * - `modalErrors` is field errors put back into an open modal. A platform
  *   without it answers `errors` some other way, so no op fails for it.
+ * - `commands` is slash commands arriving, and `followUp` working.
+ * - `ephemeral` is a command's answer that only the person who ran it sees.
+ *   A platform with `commands` and without it refuses a private answer.
  *
  * @stability unstable
  * @category schemas
@@ -78,7 +81,9 @@ export const Capability = Schema.Literals([
   "buttons",
   "selects",
   "modals",
-  "modalErrors"
+  "modalErrors",
+  "commands",
+  "ephemeral"
 ])
 
 /**
diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
index d2cd9177e3e..667c3184213 100644
--- a/packages/effect/src/chat/ChatInteraction.ts
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -1,6 +1,6 @@
 /**
- * Typed buttons, selects and modals, and the service that receives their
- * clicks.
+ * Typed buttons, selects, modals and slash commands, and the service that
+ * receives their clicks, submits and commands.
  *
  * A definition carries an element's id and the schemas of its values. It
  * builds the element to post (`of`, `open`) and gives the typed slot of its
@@ -36,11 +36,11 @@
  *
  * **Details**
  *
- * - Clicks and submits are not `ChatEvent`s. They need an answer inside the
- *   platform's 3 seconds, so they go to `Handler`, which answers by return
- *   value and has no error channel.
- * - Neither platform redelivers a click or a submit, so interactions carry no
- *   dedupe key.
+ * - Clicks, submits and commands are not `ChatEvent`s. They need an answer
+ *   inside the platform's 3 seconds, so they go to `Handler`, which answers
+ *   by return value and has no error channel.
+ * - Neither platform redelivers a click, a submit or a command, so
+ *   interactions carry no dedupe key.
  *
  * @stability unstable
  * @since 4.1.5
@@ -126,8 +126,9 @@ export type SelectChanged = typeof SelectChanged.Type
  *
  * **Details**
  *
- * - `thread` and `messageId` are those of the click that opened the modal. A
- *   modal only opens from a click, so they are always there.
+ * - `thread` and `messageId` are those of the click that opened the modal.
+ *   A modal a command opened carries the command's `thread` and no
+ *   `messageId`.
  * - `metadata` is still encoded.
  * - `values` are by field id, still encoded. An optional field left empty
  *   has no key.
@@ -140,7 +141,10 @@ export const ModalSubmitted = Schema.TaggedStruct("ModalSubmitted", {
   id: Schema.String,
   metadata: Schema.optionalKey(Schema.String),
   values: Schema.Record(Schema.String, Schema.String),
-  ...origin
+  thread: ChatThread,
+  messageId: Schema.optionalKey(Schema.String),
+  userId: Schema.String,
+  raw: Schema.Json
 })
 
 /**
@@ -152,6 +156,41 @@ export const ModalSubmitted = Schema.TaggedStruct("ModalSubmitted", {
  */
 export type ModalSubmitted = typeof ModalSubmitted.Type
 
+/**
+ * Schema for a slash command.
+ *
+ * **Details**
+ *
+ * - `id` is the command's name, without the slash.
+ * - `text` is what was typed after the name, as the platform sent it, and
+ *   empty when nothing was. It is not normalised.
+ * - `thread` is where the command was typed. On Slack that is always a
+ *   channel or a direct: Slack does not deliver an app's command typed in a
+ *   thread. There is no `messageId`, since a command comes from no message.
+ * - `raw` is the platform's payload. It holds what `Chat.followUp` needs,
+ *   so it is a credential for as long as `limits.followUpAge`.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export const CommandInvoked = Schema.TaggedStruct("CommandInvoked", {
+  id: Schema.String,
+  text: Schema.String,
+  thread: ChatThread,
+  userId: Schema.String,
+  raw: Schema.Json
+})
+
+/**
+ * A slash command.
+ *
+ * @stability unstable
+ * @category events
+ * @since 4.1.5
+ */
+export type CommandInvoked = typeof CommandInvoked.Type
+
 /**
  * Schema for what an adapter hands to `Handler`.
  *
@@ -164,10 +203,10 @@ export type ModalSubmitted = typeof ModalSubmitted.Type
  * @category events
  * @since 4.1.5
  */
-export const Interaction = Schema.Union([ButtonClicked, SelectChanged, ModalSubmitted])
+export const Interaction = Schema.Union([ButtonClicked, SelectChanged, ModalSubmitted, CommandInvoked])
 
 /**
- * A click, a select choice or a modal submit.
+ * A click, a select choice, a modal submit or a slash command.
  *
  * @stability unstable
  * @category events
@@ -180,7 +219,9 @@ export type Interaction = typeof Interaction.Type
 // -----------------------------------------------------------------------------
 
 /**
- * Schema for the reply that acknowledges a click.
+ * Schema for the reply that acknowledges a click. It is also what the handler
+ * service answers a command with no definition, which the adapter sends
+ * nothing for.
  *
  * @stability unstable
  * @category replies
@@ -198,7 +239,8 @@ export const Ack = Schema.TaggedStruct("Ack", {})
 export type Ack = typeof Ack.Type
 
 /**
- * Schema for the reply that opens a modal. Only a click can return it.
+ * Schema for the reply that opens a modal. A click or a command can return
+ * it.
  *
  * @stability unstable
  * @category replies
@@ -278,6 +320,99 @@ export type ClickReply = Ack | OpenModal
  */
 export type SubmitReply = Close | Errors
 
+/**
+ * Schema for who sees the answer to a command: `"ephemeral"` for the person
+ * who ran it, `"public"` for the channel.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const Visibility = Schema.Literals(["ephemeral", "public"])
+
+/**
+ * Who sees the answer to a command.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type Visibility = typeof Visibility.Type
+
+/**
+ * Schema for the reply that answers a command with a message, at once.
+ *
+ * **Details**
+ *
+ * `markdown` and `actions` are rendered and checked the way `post` renders
+ * and checks them. The message gets no id: it cannot be edited, deleted or
+ * fetched afterwards.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const Respond = Schema.TaggedStruct("Respond", {
+  markdown: Schema.String,
+  actions: Schema.optionalKey(Schema.Array(ChatUi.Action)),
+  visibility: Visibility
+})
+
+/**
+ * The reply that answers a command with a message.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type Respond = typeof Respond.Type
+
+/**
+ * Schema for the reply that says a command's answer comes later, and the
+ * value `Chat.followUp` takes to send it.
+ *
+ * **Details**
+ *
+ * - It is plain data, so it can go on a queue to another process.
+ * - `visibility` is fixed here. `followUp` has none of its own.
+ *
+ * **Gotchas**
+ *
+ * It holds the command's `raw`, which is a credential for as long as
+ * `limits.followUpAge`.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const Defer = Schema.TaggedStruct("Defer", {
+  command: CommandInvoked,
+  visibility: Visibility
+})
+
+/**
+ * The reply that says a command's answer comes later.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type Defer = typeof Defer.Type
+
+/**
+ * What the handler service may answer a command with.
+ *
+ * **Details**
+ *
+ * `Ack` is what a command with no definition gets, and the adapter sends
+ * nothing for it. A typed command handler cannot return it.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export type CommandReply = Ack | Respond | OpenModal | Defer
+
 /**
  * Schema for what `handle` gives when the handler ran past the deadline.
  *
@@ -347,6 +482,51 @@ export const errors = (
   errors: E
 ): FieldErrors => Errors.make({ errors })
 
+/**
+ * Answers a command with a message, at once.
+ *
+ * **Details**
+ *
+ * `visibility` defaults to `"ephemeral"`: only the person who ran the
+ * command sees it. A platform without `ephemeral` refuses a private answer
+ * and sends nothing. It never sends it publicly instead.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const respond = (options: {
+  readonly markdown: string
+  readonly actions?: ReadonlyArray | undefined
+  readonly visibility?: Visibility | undefined
+}): Respond =>
+  Respond.make({
+    markdown: options.markdown,
+    ...optional("actions", options.actions),
+    visibility: options.visibility ?? "ephemeral"
+  })
+
+/**
+ * Answers a command with a promise of a later answer, sent with
+ * `Chat.followUp`.
+ *
+ * **When to use**
+ *
+ * Use when the work does not fit in the deadline. The handler returns the
+ * deferral and hands it to whatever does the work.
+ *
+ * **Details**
+ *
+ * `visibility` defaults to `"ephemeral"`, and holds for the follow-up.
+ *
+ * @stability unstable
+ * @category replies
+ * @since 4.1.5
+ */
+export const defer = (command: CommandInvoked, options?: {
+  readonly visibility?: Visibility | undefined
+}): Defer => Defer.make({ command, visibility: options?.visibility ?? "ephemeral" })
+
 // -----------------------------------------------------------------------------
 // typed events
 // -----------------------------------------------------------------------------
@@ -395,8 +575,10 @@ export interface Selected {
  *
  * **Details**
  *
- * `values` has one key per input and none for `text`. An optional input left
- * empty is `undefined`.
+ * - `values` has one key per input and none for `text`. An optional input
+ *   left empty is `undefined`.
+ * - `messageId` is the message whose element opened the modal, and
+ *   `undefined` when a command opened it.
  *
  * @stability unstable
  * @category models
@@ -407,7 +589,7 @@ export interface Submit {
   readonly metadata: Metadata
   readonly values: Values
   readonly thread: ChatThread
-  readonly messageId: string
+  readonly messageId: string | undefined
   readonly userId: string
   readonly raw: Schema.Json
 }
@@ -936,7 +1118,8 @@ export type OpenOptions {
+  readonly [TypeId]: typeof TypeId
+  readonly kind: "command"
+  readonly id: Id
+  readonly description: string
+  readonly argument: {
+    readonly name: string
+    readonly description: string
+    readonly required: boolean
+  } | undefined
+}
+
+/**
+ * Defines a slash command.
+ *
+ * **Details**
+ *
+ * - The id is the command's name without the slash. It shares the registry's
+ *   id space with buttons, selects and modals.
+ * - Slack sends everything typed after the name as one string. Discord gets
+ *   one `STRING` option named `argument.name`, and a command with no
+ *   `argument` has no options.
+ * - `argument.required` defaults to false. Discord's client enforces it.
+ *   Slack cannot, so a portable handler still checks for an empty `text`.
+ *
+ * **Gotchas**
+ *
+ * A portable name matches `^[a-z0-9_-]{1,31}$` and a portable description is
+ * 100 characters or less. Neither is checked here.
+ *
+ * @stability unstable
+ * @category definitions
+ * @since 4.1.5
+ */
+export const command = (id: Id, options: {
+  readonly description: string
+  readonly argument?: {
+    readonly name: string
+    readonly description: string
+    readonly required?: boolean | undefined
+  } | undefined
+}): Command => ({
+  [TypeId]: TypeId,
+  kind: "command",
+  id,
+  description: options.description,
+  argument: options.argument === undefined ? undefined : {
+    name: options.argument.name,
+    description: options.argument.description,
+    required: options.argument.required ?? false
+  }
+})
+
 /**
  * Any definition that has a handler.
  *
@@ -1073,7 +1321,7 @@ export const modal = <
  * @category definitions
  * @since 4.1.5
  */
-export type Definition = Button | Select | Modal
+export type Definition = Button | Select | Modal | Command
 
 // -----------------------------------------------------------------------------
 // decoding
@@ -1087,6 +1335,8 @@ const matches = (definition: Definition, event: Interaction): boolean => {
       return definition.kind === "select"
     case "ModalSubmitted":
       return definition.kind === "modal"
+    case "CommandInvoked":
+      return definition.kind === "command"
   }
 }
 
@@ -1132,7 +1382,7 @@ const decodeSubmit = (definition: Modal, event: ModalSubmitted
   return Option.some({ ...base(event), metadata, values })
 }
 
-const base = (event: Interaction) => ({
+const base = (event: ButtonClicked | SelectChanged | ModalSubmitted) => ({
   id: event.id,
   thread: event.thread,
   messageId: event.messageId,
@@ -1157,10 +1407,13 @@ const decodeEvent = (definition: Definition, event: Interaction): Option.Option<
     case "ModalSubmitted": {
       return definition.kind === "modal" ? decodeSubmit(definition, event) : Option.none()
     }
+    case "CommandInvoked": {
+      return definition.kind === "command" ? Option.some(event) : Option.none()
+    }
   }
 }
 
-const fallback = (event: Interaction): ClickReply | SubmitReply => event._tag === "ModalSubmitted" ? close : ack
+const fallback = (event: Interaction): Ack | Close => event._tag === "ModalSubmitted" ? close : ack
 
 // -----------------------------------------------------------------------------
 // groups
@@ -1172,7 +1425,9 @@ const fallback = (event: Interaction): ClickReply | SubmitReply => event._tag ==
  * **Details**
  *
  * A button or a select answers `ack` or a modal to open. A modal answers
- * `close` or `errors` naming its own inputs.
+ * `close` or `errors` naming its own inputs. A command answers `respond`,
+ * a modal to open or `defer`, and never `ack`: Discord has no silent answer
+ * to a command.
  *
  * @stability unstable
  * @category groups
@@ -1185,6 +1440,7 @@ export type HandlerFor = D extends Button ? (
       submit: Submit, Values>
     ) => Effect.Effect & string>, never, any>
+  : D extends Command ? (command: CommandInvoked) => Effect.Effect
   : never
 
 /**
@@ -1267,9 +1523,10 @@ const makeGroup = (list: ReadonlyArray): Group => {
     merge: (...groups) => makeGroup([...list, ...groups.flatMap((group) => groupLists.get(group) ?? [])]) as any,
     toLayer: (build) =>
       Layer.effectDiscard(Effect.gen(function*() {
-        const handlers: Record Effect.Effect> = Effect.isEffect(build)
-          ? yield* build
-          : build as any
+        const handlers: Record Effect.Effect> =
+          Effect.isEffect(build)
+            ? yield* build
+            : build as any
         const context = yield* Effect.context()
         const registry = yield* Registry
         yield* registry.register(list.map((definition): Registered => ({
@@ -1316,8 +1573,15 @@ export const group = >(
  *   has no `modals`, the modal's id plus metadata is over
  *   `limits.modalMetadataLength`, it has more than `limits.modalFields`
  *   fields, a title or label is too long, or the platform refused the call)
- *   or by `handle` (the reply came after the deadline). Only a click can be
- *   refused: a submit's replies always have an answer the adapter can give.
+ *   or by `handle` (the reply came after the deadline).
+ * - A command's reply can be refused too: a private answer without
+ *   `ephemeral`, an element the platform lacks, an answer over
+ *   `limits.messageLength` or an element limit, a modal that cannot open,
+ *   or a refusal by the platform. A submit's replies always have an answer
+ *   the adapter can give.
+ * - `command` answers `Ack` for a command it has no definition for, and the
+ *   adapter sends nothing for that. On Discord another library in the same
+ *   process can still answer it.
  *
  * **Gotchas**
  *
@@ -1334,7 +1598,11 @@ export const group = >(
 export class Handler extends Context.Service Effect.Effect
   readonly submit: (event: ModalSubmitted) => Effect.Effect
-  readonly refused: (event: ButtonClicked | SelectChanged, error: ChatError) => Effect.Effect
+  readonly command: (event: CommandInvoked) => Effect.Effect
+  readonly refused: (
+    event: ButtonClicked | SelectChanged | CommandInvoked,
+    error: ChatError
+  ) => Effect.Effect
 }>()("effect/chat/ChatInteraction/Handler") {}
 
 const lateClick = (event: ButtonClicked | SelectChanged) =>
@@ -1345,8 +1613,8 @@ const lateClick = (event: ButtonClicked | SelectChanged) =>
   })
 
 /**
- * Calls `Handler.click` or `Handler.submit` and gives the reply, or `Late`
- * when `deadline` passes first.
+ * Calls `Handler.click`, `Handler.submit` or `Handler.command` and gives
+ * the reply, or `Late` when `deadline` passes first.
  *
  * **When to use**
  *
@@ -1360,8 +1628,9 @@ const lateClick = (event: ButtonClicked | SelectChanged) =>
  *   it later returns `OpenModal`, the modal is dropped and `Handler.refused`
  *   is called with a `ChatError` whose reason is `NotFound`, op `openModal`,
  *   detail `interaction_expired`, platform `event.thread.platform`.
- * - A late submit interrupts its handler. `Late` is given at the deadline,
- *   without waiting for the handler's finalizers to finish.
+ * - A late submit or command interrupts its handler. `Late` is given at the
+ *   deadline, without waiting for the handler's finalizers to finish. A
+ *   command handler that cannot answer in time returns `defer` first.
  * - `deadline` is the handler's share of the platform's 3 seconds, not the 3
  *   seconds. The adapter subtracts what its own answer costs. This function
  *   knows no platform.
@@ -1379,20 +1648,28 @@ const lateClick = (event: ButtonClicked | SelectChanged) =>
 export const handle: {
   (event: ButtonClicked | SelectChanged, deadline: Duration.Duration): Effect.Effect
   (event: ModalSubmitted, deadline: Duration.Duration): Effect.Effect
-  (event: Interaction, deadline: Duration.Duration): Effect.Effect
+  (event: CommandInvoked, deadline: Duration.Duration): Effect.Effect
+  (
+    event: Interaction,
+    deadline: Duration.Duration
+  ): Effect.Effect
 } = (event: Interaction, deadline: Duration.Duration): Effect.Effect =>
   Effect.gen(function*() {
     const handler = yield* Handler
     // Detached, so the reply at the deadline waits for neither a late click nor a late submit's cleanup.
-    const fiber: Fiber.Fiber = yield* Effect.forkDetach(
-      event._tag === "ModalSubmitted" ? handler.submit(event) : handler.click(event)
+    const fiber: Fiber.Fiber = yield* Effect.forkDetach(
+      event._tag === "ModalSubmitted"
+        ? handler.submit(event)
+        : event._tag === "CommandInvoked"
+        ? handler.command(event)
+        : handler.click(event)
     )
     const exit = yield* Effect.onInterrupt(
       Effect.timeoutOption(Fiber.await(fiber), deadline),
       () => Fiber.interrupt(fiber)
     )
     if (Option.isSome(exit)) return yield* exit.value
-    if (event._tag === "ModalSubmitted") {
+    if (event._tag === "ModalSubmitted" || event._tag === "CommandInvoked") {
       // Requests the interrupt without waiting for it to finish.
       yield* Effect.forkDetach(Fiber.interrupt(fiber))
       return late
@@ -1413,7 +1690,8 @@ const late: Late = Late.make({})
  * **Details**
  *
  * `handle` answers `ack` or `close` without calling the handler when the
- * event does not match the definition or its value no longer decodes.
+ * event does not match the definition or its value no longer decodes. A
+ * command that does not match is answered `ack`.
  *
  * @stability unstable
  * @category services
@@ -1421,7 +1699,7 @@ const late: Late = Late.make({})
  */
 export interface Registered {
   readonly definition: Definition
-  readonly handle: (event: Interaction) => Effect.Effect
+  readonly handle: (event: Interaction) => Effect.Effect
 }
 
 /**
@@ -1469,6 +1747,9 @@ export type Unhandled =
  * - An interaction with an unknown id, or with a value that no longer
  *   decodes, is logged and answered `ack` or `close`. `unhandled` sees it
  *   first. It cannot change the answer.
+ * - A command with an unknown id is answered `ack`, which the adapter sends
+ *   nothing for, and logged at debug level: on Discord it may belong to
+ *   another library in the same process.
  * - `Handler.refused` is routed to `unhandled` too, as `ReplyRefused`, and
  *   logged.
  *
@@ -1485,13 +1766,15 @@ export const layer = (options?: {
     const report = (event: Interaction, why: Unhandled, message: string): Effect.Effect =>
       Effect.andThen(
         options?.unhandled === undefined ? Effect.void : Effect.provideContext(options.unhandled(event, why), context),
-        Effect.logWarning(message).pipe(Effect.annotateLogs({
-          "chat.platform": event.thread.platform,
-          "chat.interaction.id": event.id,
-          "chat.interaction.reason": why.reason
-        }))
+        (event._tag === "CommandInvoked" && why.reason === "UnknownId"
+          ? Effect.logDebug(message)
+          : Effect.logWarning(message)).pipe(Effect.annotateLogs({
+            "chat.platform": event.thread.platform,
+            "chat.interaction.id": event.id,
+            "chat.interaction.reason": why.reason
+          }))
       )
-    const route = (event: Interaction): Effect.Effect =>
+    const route = (event: Interaction): Effect.Effect =>
       Effect.suspend(() => {
         const entry = entries.get(event.id)
         if (entry === undefined || !matches(entry.definition, event)) {
@@ -1527,6 +1810,7 @@ export const layer = (options?: {
     const handler = Handler.of({
       click: (event) => route(event) as Effect.Effect,
       submit: (event) => route(event) as Effect.Effect,
+      command: (event) => route(event) as Effect.Effect,
       refused: (event, error) =>
         report(event, { reason: "ReplyRefused", error }, "ChatInteraction: the reply was not carried out").pipe(
           Effect.annotateLogs("chat.error", error.message)
diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index cc31497ec36..c1af77b7710 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -34,6 +34,7 @@ import {
   ChatError,
   fileRefused,
   Forbidden,
+  interactionExpired,
   InvalidRequest,
   isChatError,
   NotFound,
@@ -128,11 +129,14 @@ export class NoSuchElement extends Schema.TaggedError("effect/cha
  *   `option` is the encoded value of the option to choose, the first by
  *   default. It fails `NoSuchElement` when the message has no such element,
  *   or no such option, or is gone.
- * - `submit` builds the submit of a modal. It takes the click that opened
- *   it, because an `OpenModal` reply does not say where it was opened from
- *   and a `ModalSubmitted` has to. `values` are by field id, still
- *   encoded, and an empty one is left out, as for an optional field left
- *   empty.
+ * - `command` builds a command typed at `thread`, without delivering it.
+ *   `text` defaults to the empty string. The fake has no registration, so
+ *   any id can be typed.
+ * - `submit` builds the submit of a modal. It takes the click or the command
+ *   that opened it, because an `OpenModal` reply does not say where it was
+ *   opened from and a `ModalSubmitted` has to. A command gives a submit
+ *   with no `messageId`. `values` are by field id, still encoded, and an
+ *   empty one is left out, as for an optional field left empty.
  * - `interact` delivers an interaction the way an adapter does: through
  *   `ChatInteraction.handle` with the layer's `interactionDeadline`, then
  *   the fake's own checks on an `OpenModal` (the `modals` capability,
@@ -140,6 +144,17 @@ export class NoSuchElement extends Schema.TaggedError("effect/cha
  *   metadata, and `limits.modalFields`), calling `Handler.refused` when one
  *   fails. It succeeds with the handler's reply as it returned it, or
  *   `Late`. An `OpenModal` shows in `calls` as op `openModal`.
+ * - For a command, `interact` runs the checks of `post` on a `Respond`
+ *   (the element capabilities, `limits.messageLength` and the element
+ *   limits), and refuses a private `Respond` or `Defer` without
+ *   `ephemeral`. A `Respond` shows in `calls` as op `respond`, and a
+ *   `followUp` as op `followUp`, each with the command's thread and the
+ *   Markdown. Neither is stored as a message.
+ * - The fake's `followUp` succeeds once for a `Defer` that `interact`
+ *   returned, inside `limits.followUpAge` on `Clock`. Later, a second time,
+ *   or for a deferral the fake never saw, it fails `NotFound` with detail
+ *   `interaction_expired`. Failing the second call is stricter than either
+ *   platform, to catch a handler that relies on more than one.
  *
  * @stability unstable
  * @category services
@@ -171,8 +186,12 @@ export class ChatTest extends Context.Service Effect.Effect
+  readonly command: (thread: ChatThread.ChatThread, id: string, options?: {
+    readonly text?: string | undefined
+    readonly userId?: string | undefined
+  }) => Effect.Effect
   readonly submit: (
-    click: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged,
+    from: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatInteraction.CommandInvoked,
     opened: ChatInteraction.OpenModal,
     values: Readonly>,
     options?: { readonly userId?: string | undefined }
@@ -188,6 +207,11 @@ export class ChatTest extends Context.Service
+    (event: ChatInteraction.CommandInvoked): Effect.Effect<
+      ChatInteraction.CommandReply | ChatInteraction.Late,
+      never,
+      ChatInteraction.Handler
+    >
   }
 }>()("effect/chat/ChatTest") {}
 
@@ -211,7 +235,9 @@ const allCapabilities: ReadonlyArray = [
   "buttons",
   "selects",
   "modals",
-  "modalErrors"
+  "modalErrors",
+  "commands",
+  "ephemeral"
 ]
 
 /** Counts code points. */
@@ -310,6 +336,7 @@ const makeFake = (options: {
       ...(capabilities.has("nativeStream") ? { streamLength: messageLength, streamAge: Duration.minutes(10) } : {}),
       ...(hasActions ? { actionsPerMessage: 25, actionDataLength: 100 } : {}),
       ...(capabilities.has("modals") ? { modalMetadataLength: 100, modalFields: 5 } : {}),
+      ...(capabilities.has("commands") ? { followUpAge: Duration.minutes(15) } : {}),
       ...options.limits
     }
   }
@@ -320,6 +347,8 @@ const makeFake = (options: {
   const threadUnder = new Map()
   const users = new Map([[selfId, { isBot: true }]])
   const calls: Array = []
+  /** Deferrals `interact` returned, by the command's raw id, with when they were made. */
+  const deferrals = new Map()
   let refusedFiles = 0
   const faults = new Map>()
   let counter = 0
@@ -473,6 +502,19 @@ const makeFake = (options: {
     return undefined
   }
 
+  /** The capabilities a command's answer needs. */
+  const answerNeeds = (
+    visibility: ChatInteraction.Visibility,
+    actions?: ReadonlyArray | undefined
+  ): Array => [...(visibility === "ephemeral" ? ["ephemeral" as const] : []), ...actionNeeds(actions)]
+
+  /** The id the fake gave a command it built, which keys its deferral. */
+  const commandKey = (command: ChatInteraction.CommandInvoked): string | undefined => {
+    const raw = command.raw
+    const id = typeof raw === "object" && raw !== null ? (raw as { readonly id?: unknown }).id : undefined
+    return typeof id === "string" ? id : undefined
+  }
+
   const takeFault = (op: string): Fault | undefined => {
     const queue = faults.get(op)
     const fault = queue?.[0]
@@ -764,6 +806,27 @@ const makeFake = (options: {
               raw: { id }
             })
         })
+      ),
+    followUp: (deferred, content) =>
+      attempt(
+        { op: "followUp", thread: deferred.command.thread, markdown: content.markdown },
+        ["commands", ...answerNeeds(deferred.visibility, content.actions)],
+        Effect.gen(function*() {
+          const key = commandKey(deferred.command)
+          const stored = key === undefined ? undefined : deferrals.get(key)
+          const age = descriptor.limits.followUpAge
+          const now = yield* Clock.currentTimeMillis
+          if (
+            stored === undefined || stored.used ||
+            (age !== undefined && now - stored.at >= Duration.toMillis(age))
+          ) {
+            return yield* fail("followUp", new NotFound({ detail: interactionExpired }))
+          }
+          yield* checkMessageLength(descriptor, "followUp", content.markdown, content.actions)
+          yield* checkActions("followUp", content.actions ?? [])
+          stored.used = true
+        }),
+        false
       )
   }
 
@@ -867,29 +930,69 @@ const makeFake = (options: {
           ? Effect.fail(new NoSuchElement({ messageId, id }))
           : Effect.succeed(ChatInteraction.SelectChanged.make({ ...origin, value: option.value }))
       }),
-    submit: (click, opened, values, submitOptions) =>
+    command: (thread, id, commandOptions) =>
+      Effect.sync(() => {
+        const text = commandOptions?.text ?? ""
+        return ChatInteraction.CommandInvoked.make({
+          id,
+          text,
+          thread,
+          userId: commandOptions?.userId ?? "user",
+          raw: { type: "command", id: nextId("i"), command: id, text }
+        })
+      }),
+    submit: (from, opened, values, submitOptions) =>
       Effect.sync(() =>
         ChatInteraction.ModalSubmitted.make({
           id: opened.modal.id,
           ...(opened.modal.metadata === undefined ? {} : { metadata: opened.modal.metadata }),
           values: Object.fromEntries(Object.entries(values).filter(([, value]) => value !== "")),
-          thread: click.thread,
-          messageId: click.messageId,
-          userId: submitOptions?.userId ?? click.userId,
+          thread: from.thread,
+          ...(from._tag === "CommandInvoked" ? {} : { messageId: from.messageId }),
+          userId: submitOptions?.userId ?? from.userId,
           raw: { type: "submission", id: nextId("i"), modal: opened.modal.id }
         })
       ),
     interact: ((event: ChatInteraction.Interaction) =>
       Effect.gen(function*() {
         const reply = yield* ChatInteraction.handle(event, options.interactionDeadline)
-        if (reply._tag !== "OpenModal" || event._tag === "ModalSubmitted") return reply
-        const refusal = modalRefusal(reply.modal)
-        calls.push({
-          op: "openModal",
-          thread: event.thread,
-          messageId: event.messageId,
-          outcome: refusal === undefined ? "ok" : refusal.reason._tag
-        })
+        if (event._tag === "ModalSubmitted") return reply
+        let refusal: ChatError | undefined
+        switch (reply._tag) {
+          case "OpenModal": {
+            refusal = modalRefusal(reply.modal)
+            calls.push({
+              op: "openModal",
+              thread: event.thread,
+              ...(event._tag === "CommandInvoked" ? {} : { messageId: event.messageId }),
+              outcome: refusal === undefined ? "ok" : refusal.reason._tag
+            })
+            break
+          }
+          case "Respond": {
+            const exit = yield* Effect.exit(attempt(
+              { op: "respond", thread: event.thread, markdown: reply.markdown },
+              answerNeeds(reply.visibility, reply.actions),
+              Effect.andThen(
+                checkMessageLength(descriptor, "respond", reply.markdown, reply.actions),
+                checkActions("respond", reply.actions ?? [])
+              ),
+              false
+            ))
+            refusal = Exit.isFailure(exit) ? Option.getOrUndefined(Exit.findErrorOption(exit)) : undefined
+            break
+          }
+          case "Defer": {
+            const missing = answerNeeds(reply.visibility).find((capability) => !capabilities.has(capability))
+            if (missing !== undefined) {
+              refusal = chatError("defer", new Unsupported({ capability: missing }))
+              break
+            }
+            const key = event._tag === "CommandInvoked" ? commandKey(event) : undefined
+            if (key !== undefined) deferrals.set(key, { at: yield* Clock.currentTimeMillis, used: false })
+            break
+          }
+        }
         if (refusal !== undefined) {
           const handler = yield* ChatInteraction.Handler
           yield* handler.refused(event, refusal)
@@ -929,6 +1032,7 @@ const makeFake = (options: {
  *   modal's id plus encoded metadata takes 100 code points, and a modal 5
  *   fields. Each limit is there only with its capability.
  * - `interact` gives a handler 3 seconds by default, on `Clock`.
+ * - With `commands` on, `limits.followUpAge` is 15 minutes.
  * - Two layers merged with different platforms share one `Chat`, so routing
  *   can be tested. The `ChatTest` service in context is the last one merged.
  *
@@ -1199,8 +1303,8 @@ export const checkEvent = (event: ChatEvent.ChatEvent, options: {
 const InteractionJson = Schema.toCodecJson(ChatInteraction.Interaction)
 
 /**
- * Checks the invariants every interaction holds, for a click or a submit from
- * a fixture.
+ * Checks the invariants every interaction holds, for a click, a submit or a
+ * command from a fixture.
  *
  * **Details**
  *
@@ -1208,7 +1312,9 @@ const InteractionJson = Schema.toCodecJson(ChatInteraction.Interaction)
  *   codec.
  * - The interaction encodes and decodes through its Schema unchanged, `raw`
  *   included.
- * - A `ModalSubmitted` has a non-empty `messageId`.
+ * - A `ModalSubmitted`'s `messageId` is non-empty when it is there. A modal
+ *   a command opened has none.
+ * - A `CommandInvoked` has a non-empty `id`.
  *
  * It takes no `parseMention` and checks no dedupe key, since an interaction
  * carries neither.
@@ -1224,7 +1330,12 @@ export const checkInteraction = (interaction: ChatInteraction.Interaction, optio
     const rule = "checkInteraction"
     yield* checkThread(rule, interaction.thread, options.platform)
     if (interaction._tag === "ModalSubmitted") {
-      yield* check(rule, interaction.messageId !== "", "a submit with a messageId", () => "an empty messageId")
+      yield* check(rule, interaction.messageId !== "", "a submit with no messageId or a non-empty one", () =>
+        "an empty messageId")
+    }
+    if (interaction._tag === "CommandInvoked") {
+      yield* check(rule, interaction.id !== "", "a command with a non-empty id", () =>
+        "an empty id")
     }
     yield* roundTrip(rule, InteractionJson, interaction)
   })
@@ -1242,12 +1353,15 @@ export const checkInteraction = (interaction: ChatInteraction.Interaction, optio
  * - `click` clicks the element `id` on a message the suite posted, through
  *   the adapter's real entry, and fails `NoSuchElement` when the message
  *   carries no such element. `option` is as in `ChatTest.click`.
- * - `submit` submits the modal the last click opened, and submits it again
- *   after an `errors` reply. It does nothing when no modal is open: the rule
- *   then fails on the submit its handler never saw.
- * - Both need `ChatInteraction.Handler` and nothing else. The suite provides
- *   its own recording handler, so the entry must take its handler at the
- *   call, not at layer build.
+ * - `submit` submits the modal the last click or command opened, and
+ *   submits it again after an `errors` reply. It does nothing when no modal
+ *   is open: the rule then fails on the submit its handler never saw.
+ * - `command` sends a command typed at `thread` through the adapter's real
+ *   entry. The command rules exist only when it is given. It is optional, so
+ *   a hook written before commands still fits.
+ * - All three need `ChatInteraction.Handler` and nothing else. The suite
+ *   provides its own recording handler, so the entry must take its handler
+ *   at the call, not at layer build.
  *
  * @stability unstable
  * @category testing
@@ -1260,16 +1374,25 @@ export interface Interactions {
   readonly submit: (
     values: Readonly>
   ) => Effect.Effect
+  readonly command?:
+    | ((thread: ChatThread.ChatThread, id: string, options?: {
+      readonly text?: string | undefined
+    }) => Effect.Effect)
+    | undefined
 }
 
 /** What the suite's own `ChatInteraction.Handler` received, and how it answers. */
 class Recording {
   readonly clicks: Array = []
   readonly submits: Array = []
+  readonly commands: Array = []
+  readonly commandReplies: Array = []
   readonly refused: Array = []
   onClick: (event: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged) => ChatInteraction.ClickReply = () =>
     ChatInteraction.ack
   onSubmit: (event: ChatInteraction.ModalSubmitted) => ChatInteraction.SubmitReply = () => ChatInteraction.close
+  onCommand: (event: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply = (event) =>
+    ChatInteraction.respond({ markdown: conformanceText(event.id), visibility: "public" })
   readonly handler = ChatInteraction.Handler.of({
     click: (event) =>
       Effect.sync(() => {
@@ -1281,6 +1404,13 @@ class Recording {
         this.submits.push(event)
         return this.onSubmit(event)
       }),
+    command: (event) =>
+      Effect.sync(() => {
+        this.commands.push(event)
+        const reply = this.onCommand(event)
+        this.commandReplies.push(reply)
+        return reply
+      }),
     refused: (_, error) => Effect.sync(() => void this.refused.push(error))
   })
 }
@@ -1352,6 +1482,15 @@ class Tester {
     )
   }
 
+  /** Sends a command through the hook, with the suite's recording handler. */
+  command(id: string, options?: { readonly text?: string | undefined }) {
+    return Effect.provideService(
+      this.options.interactions!.command!(this.thread, id, options),
+      ChatInteraction.Handler,
+      this.recording.handler
+    )
+  }
+
   submit(values: Readonly>) {
     return Effect.provideService(
       this.options.interactions!.submit(values),
@@ -1533,6 +1672,41 @@ class Tester {
       case "modalErrors":
         // Its absence means a degraded answer, not a refusal, so it has no inverse.
         return Effect.void
+      case "commands":
+        // A deferral built by hand, which no adapter can follow up: it must fail, and not with Unsupported when listed.
+        return expect(chat.followUp(
+          ChatInteraction.defer(
+            ChatInteraction.CommandInvoked.make({
+              id: "conformance",
+              text: "",
+              thread,
+              userId: "conformance",
+              raw: {}
+            }),
+            { visibility: "public" }
+          ),
+          { markdown: text }
+        ))
+      case "ephemeral":
+        // A private answer exists only as the answer to a command, so without the hook there is nothing to probe.
+        return this.options.interactions?.command === undefined
+          ? Effect.void
+          : Effect.gen({ self: this }, function*() {
+            this.recording.onCommand = () => ChatInteraction.respond({ markdown: text })
+            yield* this.command("conformance")
+            const refusal = this.recording.refused.find((error) => error.reason._tag === "Unsupported")
+            const holds = listed
+              ? refusal === undefined
+              : refusal?.reason._tag === "Unsupported" && refusal.reason.capability === "ephemeral"
+            yield* this.check(
+              holds,
+              listed ? "no refusal Unsupported for listed ephemeral" : "a refusal Unsupported(ephemeral)",
+              () =>
+                this.recording.refused.length === 0
+                  ? "no refusal"
+                  : this.recording.refused.map(describeError).join(", ")
+            )
+          })
       case "nativeStream":
         return Effect.flatMap(
           Registry,
@@ -1651,6 +1825,10 @@ interface ConformanceOptions {
  *   `Chat` and `Registry`.
  * - `modalErrors` has no inverse rule: without it an `errors` reply is a
  *   degraded answer, not a refusal.
+ * - The `command/*` rules and `unsupported/ephemeral` exist only when
+ *   `interactions.command` is given. `unsupported/commands` always runs: it
+ *   calls `followUp` with a deferral the suite builds by hand, which must
+ *   fail `Unsupported` without `commands`, and fail some other way with it.
  * - Every rule deletes what it posted when it ends, pass or fail, when the
  *   platform can delete.
  *
@@ -1660,7 +1838,8 @@ interface ConformanceOptions {
  * arrives only behind a new capability or with a changeset saying third-party
  * adapters may start failing. `unsupported/buttons` and
  * `unsupported/selects` are such rules: an adapter that ignores `actions`
- * and posts anyway fails them. The `retries/retrySafe` rule waits for real
+ * and posts anyway fails them. So is `unsupported/commands`: an adapter whose
+ * `followUp` does anything but fail `Unsupported` fails it. The `retries/retrySafe` rule waits for real
  * time, so run the suite on a live `Clock`.
  *
  * @stability unstable
@@ -2329,8 +2508,111 @@ export const conformance = (options: {
     rule("unsupported/modals", ["buttons"], (t) => t.probe("modals"))
   }
 
+  if (interactions?.command !== undefined) {
+    const commandId = "conformance-command"
+
+    rule("command/arrives", ["commands"], (t) =>
+      Effect.gen(function*() {
+        const text = "deploy v1 < \u{1D400}"
+        yield* t.command(commandId, { text })
+        const command = t.recording.commands[0]
+        yield* t.check(
+          command !== undefined && command.id === commandId && command.text === text &&
+            ChatThread.equals(command.thread, t.thread),
+          "command " + commandId + " with text " + JSON.stringify(text) + " in " + ChatThread.toString(t.thread),
+          () =>
+            command === undefined
+              ? "no command"
+              : "command " + command.id + " with text " + JSON.stringify(command.text) + " in " +
+                ChatThread.toString(command.thread)
+        )
+        yield* t.checkInteraction(command)
+      }))
+
+    rule("command/emptyText", ["commands"], (t) =>
+      Effect.gen(function*() {
+        yield* t.command(commandId)
+        const command = t.recording.commands[0]
+        yield* t.check(
+          command !== undefined && command.text === "",
+          "a command with text \"\"",
+          () => command === undefined ? "no command" : "text " + JSON.stringify(command.text)
+        )
+      }))
+
+    const noRefusal = (t: Tester) =>
+      t.check(
+        t.recording.commands.length === 1 && t.recording.refused.length === 0,
+        "one command and no refusal",
+        () =>
+          t.recording.commands.length + " commands and refusals " +
+          (t.recording.refused.length === 0 ? "none" : t.recording.refused.map(describeError).join(", "))
+      )
+
+    rule("command/responds", ["commands"], (t) =>
+      Effect.gen(function*() {
+        t.recording.onCommand = () =>
+          ChatInteraction.respond({ markdown: conformanceText(t.rule), visibility: "public" })
+        yield* t.command(commandId)
+        yield* noRefusal(t)
+      }))
+
+    rule("command/respondsPrivately", ["commands", "ephemeral"], (t) =>
+      Effect.gen(function*() {
+        t.recording.onCommand = () => ChatInteraction.respond({ markdown: conformanceText(t.rule) })
+        yield* t.command(commandId)
+        yield* noRefusal(t)
+      }))
+
+    rule("command/respondTooLarge", ["commands"], (t) =>
+      Effect.gen(function*() {
+        const markdown = "x".repeat(t.descriptor.limits.messageLength + 1)
+        t.recording.onCommand = () => ChatInteraction.respond({ markdown, visibility: "public" })
+        yield* t.command(commandId)
+        const refusal = t.recording.refused[0]
+        yield* t.check(
+          refusal !== undefined && textTooLarge.test(refusal.reason),
+          "a refusal " + textTooLarge.expected,
+          () => refusal === undefined ? "no refusal" : "a refusal " + describeError(refusal)
+        )
+      }))
+
+    rule("command/followUp", ["commands"], (t) =>
+      Effect.gen(function*() {
+        t.recording.onCommand = (command) => ChatInteraction.defer(command, { visibility: "public" })
+        yield* t.command(commandId)
+        const deferred = t.recording.commandReplies[0]
+        if (deferred?._tag !== "Defer") {
+          return yield* Effect.fail(
+            failure(t.rule, "a Defer reply", deferred === undefined ? "no command" : deferred._tag)
+          )
+        }
+        yield* noRefusal(t)
+        yield* t.call(t.chat.followUp(deferred, { markdown: conformanceText(t.rule) }))
+      }))
+
+    rule("command/modalOrigin", ["commands", "modals"], (t) =>
+      Effect.gen(function*() {
+        t.recording.onCommand = () => probeModal.open()
+        yield* t.command(commandId)
+        yield* t.submit({ answer: "conformance" })
+        const submit = t.recording.submits[0]
+        yield* t.check(
+          submit !== undefined && submit.messageId === undefined && ChatThread.equals(submit.thread, t.thread),
+          "a submit in " + ChatThread.toString(t.thread) + " with no messageId",
+          () =>
+            submit === undefined
+              ? "no submit"
+              : "a submit in " + ChatThread.toString(submit.thread) + " with messageId " + submit.messageId
+        )
+        yield* t.checkInteraction(submit)
+      }))
+
+    rule("unsupported/ephemeral", ["commands"], (t) => t.probe("ephemeral"))
+  }
+
   for (const capability of allCapabilities) {
-    if (capability === "modals" || capability === "modalErrors") continue
+    if (capability === "modals" || capability === "modalErrors" || capability === "ephemeral") continue
     rule("unsupported/" + capability, [], (t) => t.probe(capability))
   }
 
diff --git a/packages/effect/test/chat/ChatInteraction.test.ts b/packages/effect/test/chat/ChatInteraction.test.ts
index 38a99410164..e9b4f29f0a3 100644
--- a/packages/effect/test/chat/ChatInteraction.test.ts
+++ b/packages/effect/test/chat/ChatInteraction.test.ts
@@ -1,6 +1,6 @@
 import { assert, describe, it } from "@effect/vitest"
 import { Deferred, Duration, Effect, Exit, Fiber, Layer, Option, Schema } from "effect"
-import { ChatError, ChatInteraction, ChatTest, ChatThread } from "effect/chat"
+import { Chat, ChatError, ChatInteraction, ChatTest, ChatThread } from "effect/chat"
 import { TestClock } from "effect/testing"
 
 const Deploy = Schema.Struct({ version: Schema.String })
@@ -10,6 +10,9 @@ const origin = { thread, messageId: "m1", userId: "u1", raw: null }
 const clicked = (id: string, value?: string) =>
   ChatInteraction.ButtonClicked.make({ id, ...origin, ...(value === undefined ? {} : { value }) })
 
+const invoked = (id: string, text = "") =>
+  ChatInteraction.CommandInvoked.make({ id, text, thread, userId: "u1", raw: { id: "i1" } })
+
 describe("ChatInteraction", () => {
   describe("encodeValue / decodeValue", () => {
     it("sends a string-only schema as it is", () => {
@@ -107,6 +110,22 @@ describe("ChatInteraction", () => {
         errors: { reason: "Say more." }
       })
     })
+
+    it("respond and defer answer privately by default, and a deferral survives JSON", () => {
+      assert.deepStrictEqual(ChatInteraction.respond({ markdown: "Hi" }), {
+        _tag: "Respond",
+        markdown: "Hi",
+        visibility: "ephemeral"
+      })
+      const deferred = ChatInteraction.defer(invoked("summarize"), { visibility: "public" })
+      const codec = Schema.toCodecJson(ChatInteraction.Defer)
+      const wire = JSON.parse(JSON.stringify(Schema.encodeSync(codec)(deferred)))
+      assert.deepStrictEqual(Schema.decodeUnknownSync(codec)(wire), {
+        _tag: "Defer",
+        command: { _tag: "CommandInvoked", id: "summarize", text: "", thread, userId: "u1", raw: { id: "i1" } },
+        visibility: "public"
+      })
+    })
   })
 
   describe("layer and groups", () => {
@@ -120,9 +139,14 @@ describe("ChatInteraction", () => {
         note: ChatInteraction.textInput({ label: "Note", optional: true })
       }
     })
+    const Ship = ChatInteraction.command("ship", {
+      description: "Ship a version",
+      argument: { name: "version", description: "The version" }
+    })
     const seen: Array = []
     const unhandled: Array = []
-    const Interactions = ChatInteraction.group(Approve).add(Reason).toLayer({
+    const Interactions = ChatInteraction.group(Approve).add(Reason, Ship).toLayer({
+      ship: (command) => Effect.succeed(ChatInteraction.respond({ markdown: "Shipping " + command.text })),
       approve: (click) =>
         Effect.sync(() => seen.push(click.value)).pipe(Effect.as(Reason.open({ metadata: click.value }))),
       reason: (submit) =>
@@ -153,6 +177,22 @@ describe("ChatInteraction", () => {
         ])
       }).pipe(Effect.provide(Interactions)))
 
+    it.effect("routes a command to its handler, and answers an unknown one Ack", () =>
+      Effect.gen(function*() {
+        unhandled.length = 0
+        const handler = yield* ChatInteraction.Handler
+        assert.deepStrictEqual(yield* handler.command(invoked("ship", "v1")), {
+          _tag: "Respond",
+          markdown: "Shipping v1",
+          visibility: "ephemeral"
+        })
+        assert.deepStrictEqual(yield* handler.command(invoked("nope")), ChatInteraction.ack)
+        // A command and a button share one id space: a command named like a button is not routed to it.
+        assert.deepStrictEqual(yield* handler.command(invoked("approve")), ChatInteraction.ack)
+        assert.deepStrictEqual(unhandled, ["nope:UnknownId", "approve:UnknownId"])
+        assert.deepStrictEqual(Ship.argument, { name: "version", description: "The version", required: false })
+      }).pipe(Effect.provide(Interactions)))
+
     it.effect("answers an unknown id or a value that no longer decodes without a handler", () =>
       Effect.gen(function*() {
         seen.length = 0
@@ -190,11 +230,13 @@ describe("ChatInteraction", () => {
     const handlerWith = (options: {
       readonly click?: Effect.Effect
       readonly submit?: Effect.Effect
+      readonly command?: Effect.Effect
       readonly refused?: (error: ChatError.ChatError) => Effect.Effect
     }) =>
       ChatInteraction.Handler.of({
         click: () => options.click ?? Effect.succeed(ChatInteraction.ack),
         submit: () => options.submit ?? Effect.succeed(ChatInteraction.close),
+        command: () => options.command ?? Effect.succeed(ChatInteraction.ack),
         refused: (_, error) => options.refused?.(error) ?? Effect.void
       })
 
@@ -230,22 +272,27 @@ describe("ChatInteraction", () => {
         assert.strictEqual(error.reason.detail, ChatError.interactionExpired)
       }))
 
-    it.effect("interrupts a late submit", () =>
+    it.effect("interrupts a late submit and a late command", () =>
       Effect.gen(function*() {
-        let interrupted = false
-        const handler = handlerWith({
-          submit: Effect.as(Effect.sleep("5 seconds"), ChatInteraction.close).pipe(
-            Effect.onInterrupt(() => Effect.sync(() => void (interrupted = true)))
+        let interrupted = 0
+        const slow = (reply: A) =>
+          Effect.as(Effect.sleep("5 seconds"), reply).pipe(
+            Effect.onInterrupt(() => Effect.sync(() => void interrupted++))
           )
+        const handler = handlerWith({
+          submit: slow(ChatInteraction.close),
+          command: slow(ChatInteraction.respond({ markdown: "late" }))
         })
         const submitted = ChatInteraction.ModalSubmitted.make({ id: "m", values: {}, ...origin })
-        const fiber = yield* ChatInteraction.handle(submitted, deadline).pipe(
-          Effect.provideService(ChatInteraction.Handler, handler),
-          Effect.forkChild
-        )
-        yield* TestClock.adjust("3 seconds")
-        assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
-        assert.isTrue(interrupted)
+        for (const event of [submitted, invoked("slow")]) {
+          const fiber = yield* ChatInteraction.handle(event, deadline).pipe(
+            Effect.provideService(ChatInteraction.Handler, handler),
+            Effect.forkChild
+          )
+          yield* TestClock.adjust("3 seconds")
+          assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
+        }
+        assert.strictEqual(interrupted, 2)
       }))
     it.effect("gives Late at the deadline without waiting for a late submit's cleanup", () =>
       Effect.gen(function*() {
@@ -278,6 +325,7 @@ describe("ChatInteraction", () => {
         const handler = ChatInteraction.Handler.of({
           click: () => Effect.as(Effect.sleep("2 seconds"), ChatInteraction.ack),
           submit: () => Effect.succeed(ChatInteraction.close),
+          command: () => Effect.succeed(ChatInteraction.ack),
           refused: () => Effect.void
         })
         const fiber = yield* test.interact(clicked("a")).pipe(
@@ -287,5 +335,65 @@ describe("ChatInteraction", () => {
         yield* TestClock.adjust("1 second")
         assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
       }).pipe(Effect.provide(ChatTest.layer({ interactionDeadline: Duration.seconds(1) }))))
+
+    const answering = (reply: (command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply) => {
+      const refused: Array = []
+      const handler = ChatInteraction.Handler.of({
+        click: () => Effect.succeed(ChatInteraction.ack),
+        submit: () => Effect.succeed(ChatInteraction.close),
+        command: (command) => Effect.succeed(reply(command)),
+        refused: (_, error) => Effect.sync(() => void refused.push(error))
+      })
+      return { handler, refused }
+    }
+
+    it.effect("follows up a deferral once, inside followUpAge", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const chat = yield* Chat.Chat
+        const channel = yield* test.makeThread()
+        const { handler } = answering((command) => ChatInteraction.defer(command))
+        const interact = (command: ChatInteraction.CommandInvoked) =>
+          Effect.provideService(test.interact(command), ChatInteraction.Handler, handler)
+        const first = yield* interact(yield* test.command(channel, "summarize"))
+        yield* chat.followUp(first as ChatInteraction.Defer, { markdown: "Done" })
+        const twice = yield* Effect.flip(chat.followUp(first as ChatInteraction.Defer, { markdown: "Again" }))
+        assert.strictEqual(twice.reason.detail, ChatError.interactionExpired)
+        const second = yield* interact(yield* test.command(channel, "summarize"))
+        yield* TestClock.adjust("15 minutes")
+        const expired = yield* Effect.flip(chat.followUp(second as ChatInteraction.Defer, { markdown: "Late" }))
+        assert.strictEqual(expired.reason._tag, "NotFound")
+        assert.strictEqual(expired.reason.detail, ChatError.interactionExpired)
+        const answers = (yield* test.calls).filter((call) => call.op === "followUp")
+        assert.deepStrictEqual(answers.map((call) => [call.markdown, call.outcome]), [
+          ["Done", "ok"],
+          ["Again", "NotFound"],
+          ["Late", "NotFound"]
+        ])
+        assert.deepStrictEqual(yield* test.messages(channel), [])
+      }).pipe(Effect.provide(ChatTest.layer())))
+
+    it.effect("refuses a private answer without ephemeral, and sends nothing", () =>
+      Effect.gen(function*() {
+        const test = yield* ChatTest.ChatTest
+        const channel = yield* test.makeThread()
+        const { handler, refused } = answering((command) =>
+          command.text === "defer" ? ChatInteraction.defer(command) : ChatInteraction.respond({ markdown: "Secret" })
+        )
+        for (const text of ["respond", "defer"]) {
+          yield* Effect.provideService(
+            test.interact(yield* test.command(channel, "secret", { text })),
+            ChatInteraction.Handler,
+            handler
+          )
+        }
+        assert.deepStrictEqual(
+          refused.map((error) => error.reason._tag === "Unsupported" && error.reason.capability),
+          ["ephemeral", "ephemeral"]
+        )
+        assert.deepStrictEqual((yield* test.calls).map((call) => [call.op, call.outcome]), [["respond", "Unsupported"]])
+      }).pipe(Effect.provide(ChatTest.layer({
+        capabilities: ChatError.Capability.literals.filter((capability) => capability !== "ephemeral")
+      }))))
   })
 })
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index b24a00169c8..af61e9b1551 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -22,26 +22,29 @@ const parseMention: ChatTest.ParseMention = (slice) => {
 /** The conformance click hook, over the fake's own entry. */
 const interactionsFor = (test: ChatTest.ChatTest["Service"]): ChatTest.Interactions => {
   let open: {
-    readonly click: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
+    readonly from: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatInteraction.CommandInvoked
     readonly opened: ChatInteraction.OpenModal
   } | undefined
+  const deliver = Effect.fnUntraced(function*(
+    from: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatInteraction.CommandInvoked
+  ) {
+    const handler = yield* ChatInteraction.Handler
+    let refused = false
+    const reply = yield* test.interact(from as ChatInteraction.CommandInvoked).pipe(
+      Effect.provideService(ChatInteraction.Handler, {
+        ...handler,
+        refused: (event, error) =>
+          Effect.andThen(Effect.sync(() => void (refused = true)), handler.refused(event, error))
+      })
+    )
+    open = reply._tag === "OpenModal" && !refused ? { from, opened: reply } : undefined
+  })
   return {
-    click: Effect.fnUntraced(function*(messageId, id, options) {
-      const click = yield* test.click(messageId, id, options)
-      const handler = yield* ChatInteraction.Handler
-      let refused = false
-      const reply = yield* test.interact(click).pipe(
-        Effect.provideService(ChatInteraction.Handler, {
-          ...handler,
-          refused: (event, error) =>
-            Effect.andThen(Effect.sync(() => void (refused = true)), handler.refused(event, error))
-        })
-      )
-      open = reply._tag === "OpenModal" && !refused ? { click, opened: reply } : undefined
-    }),
+    click: (messageId, id, options) => Effect.flatMap(test.click(messageId, id, options), deliver),
+    command: (thread, id, options) => Effect.flatMap(test.command(thread, id, options), deliver),
     submit: Effect.fnUntraced(function*(values) {
       if (open === undefined) return
-      const reply = yield* test.interact(yield* test.submit(open.click, open.opened, values))
+      const reply = yield* test.interact(yield* test.submit(open.from, open.opened, values))
       if (reply._tag !== "Errors") open = undefined
     })
   }
@@ -70,7 +73,7 @@ const ruleNames = Object.keys(ChatTest.conformance({
   parseMention,
   refuseFiles: () => Effect.void,
   failNext: () => Effect.void,
-  interactions: { click: () => Effect.void, submit: () => Effect.void }
+  interactions: { click: () => Effect.void, submit: () => Effect.void, command: () => Effect.void }
 }))
 
 const capabilities = ChatError.Capability.literals
@@ -238,6 +241,7 @@ describe("ChatTest", () => {
       ChatInteraction.Handler.of({
         click: () => Effect.succeed(reply),
         submit: () => Effect.succeed(ChatInteraction.close),
+        command: () => Effect.succeed(ChatInteraction.ack),
         refused: (_, error) => Effect.sync(() => void refused.push(error))
       })
 
@@ -253,7 +257,7 @@ describe("ChatTest", () => {
       ) {
         assert.include(withoutHook, name)
       }
-      for (const name of ["actions/valueRoundTrips", "modal/origin", "unsupported/modals"]) {
+      for (const name of ["actions/valueRoundTrips", "modal/origin", "unsupported/modals", "command/arrives"]) {
         assert.notInclude(withoutHook, name)
         assert.include(ruleNames, name)
       }
@@ -370,7 +374,23 @@ describe("ChatTest", () => {
         assert.strictEqual(reason?._tag === "Unsupported" && reason.capability, "modals")
       }).pipe(Effect.provide(ChatTest.layer({ capabilities: capabilities.filter((c) => c !== "modals") }))))
 
-    it.effect("checkInteraction rejects a submit with no messageId and a foreign platform", () =>
+    it("lists the command rules only with the hook's command, and unsupported/commands always", () => {
+      const withoutCommand = Object.keys(ChatTest.conformance({
+        platform: "test",
+        thread: ChatThread.make("test", "c0"),
+        userPosts: () => Effect.die("unused"),
+        parseMention,
+        interactions: { click: () => Effect.void, submit: () => Effect.void }
+      }))
+      assert.include(withoutCommand, "unsupported/commands")
+      assert.include(withoutCommand, "modal/origin")
+      for (const name of ["command/followUp", "command/modalOrigin", "unsupported/ephemeral"]) {
+        assert.notInclude(withoutCommand, name)
+        assert.include(ruleNames, name)
+      }
+    })
+
+    it.effect("checkInteraction rejects a submit with an empty messageId and a foreign platform", () =>
       Effect.gen(function*() {
         const submitted = ChatInteraction.ModalSubmitted.make({
           id: "ask",
diff --git a/packages/effect/typetest/chat/ChatInteraction.tst.ts b/packages/effect/typetest/chat/ChatInteraction.tst.ts
index 242179c68df..04e0cd0a171 100644
--- a/packages/effect/typetest/chat/ChatInteraction.tst.ts
+++ b/packages/effect/typetest/chat/ChatInteraction.tst.ts
@@ -101,6 +101,45 @@ describe("ChatInteraction", () => {
     })
   })
 
+  it("types a command's handler, which must answer with a message, a modal or a deferral", () => {
+    const Ship = ChatInteraction.command("ship", {
+      description: "Ship a version",
+      argument: { name: "version", description: "The version", required: true }
+    })
+    const Summarize = ChatInteraction.command("summarize", { description: "Summarize this thread" })
+    const Group = ChatInteraction.group(Ship, Summarize, Approve, Feedback)
+    const valid = {
+      ship: (command: ChatInteraction.CommandInvoked) => {
+        expect(command.text).type.toBe()
+        return Effect.succeed(ChatInteraction.respond({ markdown: "Ship " + command.text + "?" }))
+      },
+      summarize: (command: ChatInteraction.CommandInvoked) => Effect.succeed(ChatInteraction.defer(command)),
+      approve: () => Effect.succeed(Feedback.open()),
+      feedback: (submit: ChatInteraction.Submit) => {
+        expect(submit.messageId).type.toBe()
+        return Effect.succeed(ChatInteraction.close)
+      }
+    }
+    expect(Group.toLayer(valid)).type.toBe>()
+    expect(Group.toLayer).type.not.toBeCallableWith({ ...valid, ship: () => Effect.succeed(ChatInteraction.ack) })
+    expect(Group.toLayer).type.not.toBeCallableWith({ ...valid, ship: () => Effect.fail("boom") })
+    expect(Group.toLayer).type.not.toBeCallableWith({
+      ...valid,
+      approve: () => Effect.succeed(ChatInteraction.respond({ markdown: "A click cannot answer with a message." }))
+    })
+    expect(Group.toLayer).type.not.toBeCallableWith({
+      ...valid,
+      feedback: () => Effect.succeed(ChatInteraction.respond({ markdown: "Nor can a submit." }))
+    })
+    const { summarize: _, ...missing } = valid
+    expect(Group.toLayer).type.not.toBeCallableWith(missing)
+    expect(ChatInteraction.Handler.of).type.not.toBeCallableWith({
+      click: () => Effect.succeed(ChatInteraction.ack),
+      submit: () => Effect.succeed(ChatInteraction.close),
+      refused: () => Effect.void
+    })
+  })
+
   it("handle gives the reply of the event's kind, or Late", () => {
     const click = ChatInteraction.handle(
       {} as ChatInteraction.ButtonClicked,
@@ -113,6 +152,10 @@ describe("ChatInteraction", () => {
     expect(submit).type.toBe<
       Effect.Effect
     >()
+    const command = ChatInteraction.handle({} as ChatInteraction.CommandInvoked, Duration.seconds(2))
+    expect(command).type.toBe<
+      Effect.Effect
+    >()
   })
 
   it("keeps the error details literal", () => {

From e75284fde9c7a590eb3f9b3f7167498a08dd8c6a Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 19:14:27 +0000
Subject: [PATCH 47/89] chat-slack: slash commands, private replies and
 followUp

---
 .changeset/chat-slack-commands.md             |   5 +
 packages/chat/slack/src/SlackChat.ts          |  56 +++++--
 packages/chat/slack/src/internal/adapter.ts   |  79 ++++++++-
 .../chat/slack/src/internal/interactions.ts   | 118 +++++++++----
 packages/chat/slack/src/internal/webhook.ts   |  28 +++-
 packages/chat/slack/test/conformance.test.ts  |   9 +-
 packages/chat/slack/test/interactions.test.ts | 158 +++++++++++++++++-
 packages/chat/slack/test/slack.ts             |  18 +-
 packages/chat/slack/test/utils.ts             |  33 +++-
 9 files changed, 438 insertions(+), 66 deletions(-)
 create mode 100644 .changeset/chat-slack-commands.md

diff --git a/.changeset/chat-slack-commands.md b/.changeset/chat-slack-commands.md
new file mode 100644
index 00000000000..051077629ec
--- /dev/null
+++ b/.changeset/chat-slack-commands.md
@@ -0,0 +1,5 @@
+---
+"@effect/chat-slack": patch
+---
+
+Take slash commands. A command's Request URL is `layerInteractivity`'s path, and `SlackChat.interaction` takes a command's fields, from the form or a `slash_commands` envelope. `normalizeInteraction` now gives `CommandInvoked` for them, where it gave none. `respond` is answered in the response body with `response_type`, `defer` with an empty 200, a modal through the command's `trigger_id`, and a late command with `Late`. `Chat.followUp` posts once to the command's `response_url`, which must be on a Slack host, for 30 minutes. The descriptor lists `commands` and `ephemeral`. A modal a command opened submits without a `messageId`. The app needs the `commands` scope.
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index 808610685d4..e0477772e16 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -18,6 +18,17 @@
  *   path. With Socket Mode on, Slack sends interactions over the socket and
  *   never to the URL: pass each payload to `SlackChat.interaction` and send
  *   its result as the envelope ack's `payload`.
+ * - Slash commands need the `commands` scope. Declare each in the app
+ *   manifest under `features.slash_commands`, or in the app settings under
+ *   Slash Commands, with its Request URL set to `layerInteractivity`'s path.
+ *   The name, less its slash, is the id of the `ChatInteraction.command`,
+ *   and the manifest's description and usage hint are what Slack shows.
+ *   With Socket Mode on, commands come as `slash_commands` envelopes: pass
+ *   the envelope's `payload` to `SlackChat.interaction` in the same way.
+ * - A command can't be run inside a thread, so a command that acts on a
+ *   thread has to be told which one. Command names are shared by every app
+ *   in a workspace. "Escape channels, users, and links" is off by default;
+ *   with it on, `text` carries `<@U…|name>` and `<#C…|name>` tokens.
  * - Slack's stop button also needs the app declared as an agent with
  *   `features.agent_view` in the manifest. Slack documents that declaration
  *   as irreversible. Without it the adapter's session status calls answer
@@ -91,7 +102,9 @@ export interface SlackUser {
  * - `user` calls `users.info` each time. Nothing is cached.
  * - `interaction` is the entry for a decoded Interactivity `payload`
  *   (`block_actions` or `view_submission`), as `DiscordChat.interaction`
- *   is for Discord. It normalises with `normalizeInteraction`, calls the
+ *   is for Discord, and for a slash command: the form fields of its
+ *   request, or the `payload` of a `slash_commands` envelope, as one
+ *   object. It normalises with `normalizeInteraction`, calls the
  *   handler through `ChatInteraction.handle` inside `deadline` (2.5
  *   seconds by default, the handler's share of Slack's 3), opens a modal
  *   with `views.open` and calls `Handler.refused` when it can't.
@@ -104,14 +117,22 @@ export interface SlackUser {
  *   it.
  * - It succeeds with the body to answer Slack with: the JSON of the 200 on
  *   the Request URL, or the `payload` of the envelope ack on Socket Mode.
- *   `undefined` is an empty answer: an ack, a close, a late click, or a
- *   payload that is not from an element this adapter built.
- * - `Late` is a submit whose handler ran past the deadline and was
- *   interrupted. It is not an answer, since an empty one would close the
- *   modal: `layerInteractivity` answers 503 for it, which keeps the modal
- *   open, and a caller on Socket Mode sends no ack. `Late` is itself a
- *   JSON value, so test for it with `Schema.is(ChatInteraction.Late)`
+ *   For a command answered with `respond` that body is the message, with
+ *   `response_type` `ephemeral` or `in_channel`, after the checks of a
+ *   `post`; one that fails them goes to `Handler.refused`.
+ *   `undefined` is an empty answer: an ack, a close, a late click, a
+ *   deferred command, a command that opened a modal, a command nobody
+ *   handles, or a payload that is not from an element this adapter built.
+ * - `Late` is a submit or a command whose handler ran past the deadline
+ *   and was interrupted. It is not an answer, since an empty one would close
+ *   the modal, or tell the user the command worked: `layerInteractivity`
+ *   answers 503 for it, and a caller on Socket Mode sends no ack. `Late` is
+ *   itself a JSON value, so test for it with `Schema.is(ChatInteraction.Late)`
  *   before treating the result as a body.
+ * - `Chat.followUp` on a deferred command posts once to the command's
+ *   `response_url`, which must be on a Slack host, through the layer's
+ *   `HttpClient`. It is a write and is not retried. Slack takes it for 30
+ *   minutes.
  * - `interaction` checks no signature and no app id: that is the
  *   transport's job. It needs `ChatInteraction.Handler` where it is
  *   called, so the layer does not need it.
@@ -254,7 +275,7 @@ export const layer = (options: {
           })
         )
       })
-      const { adapter, user } = Adapter.make({
+      const { adapter, answer, user } = Adapter.make({
         api,
         http,
         botToken: options.botToken,
@@ -263,7 +284,7 @@ export const layer = (options: {
         attachFailed: (fields) => new SlackAttachFailed(fields)
       })
       yield* registry.register(adapter)
-      const interaction = Interactions.make({ api, teamId: options.teamId })
+      const interaction = Interactions.make({ api, teamId: options.teamId, answer })
       return SlackChat.of({ teamId: options.teamId, botUserId, user, interaction })
     })
   ).pipe(Layer.provideMerge(WebApi.layer({ botToken: options.botToken })))
@@ -383,6 +404,10 @@ export const layerWebhook = (options: {
  *
  * - Checks the `v0` signature as `layerWebhook` does, decodes the form's
  *   `payload` and drops one for another app with a 200.
+ * - It is also the Request URL of a slash command. A command's form has no
+ *   `payload` field and has a `command` field, which is how the route tells
+ *   the two apart. Its fields go to `SlackChat.interaction` as one object,
+ *   after the same signature and app checks.
  * - Hands the payload to `SlackChat.interaction` with `deadline` (2.5
  *   seconds by default). Its body is the response, and `Late` is answered
  *   with a 503, so the modal stays open with Slack's own error. Answers 413
@@ -422,15 +447,20 @@ export const layerInteractivity = (options: {
  * **Details**
  *
  * - Pure: takes the decoded `payload` of a `block_actions` or
- *   `view_submission` request.
+ *   `view_submission` request, or the fields of a slash command.
  * - None for any other payload, and for one that is not from an element
  *   this adapter built: a block of the consumer's own, a link button, or a
  *   view the adapter did not open.
+ * - Every command gives a `CommandInvoked`, known or not: the registry
+ *   decides that later. `id` is `command` less its slash, `text` is `text`
+ *   or the empty string, and the thread is the channel's.
  * - A submit's thread and message are those of the click that opened the
  *   modal, which the adapter packed into `private_metadata` beside the
- *   consumer's metadata.
+ *   consumer's metadata. A modal a command opened has no message, so its
+ *   submit has no `messageId`.
  * - The team in an address is `context.teamId`. `raw` is the payload
- *   without its verification `token`.
+ *   without its verification `token`. A command's holds its `response_url`,
+ *   so it is a credential for 30 minutes.
  *
  * @stability unstable
  * @category normalization
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 6ce31516afe..f797cc9a7cf 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -10,10 +10,13 @@ import {
   type ChatError,
   type ChatErrorReason,
   fileRefused,
+  interactionExpired,
+  NotFound,
   TooLarge,
   Unknown,
   Unsupported
 } from "effect/chat/ChatError"
+import type { Defer, Visibility } from "effect/chat/ChatInteraction"
 import type { ChatMessage } from "effect/chat/ChatMessage"
 import type { ChatThread } from "effect/chat/ChatThread"
 import type { Action } from "effect/chat/ChatUi"
@@ -92,7 +95,9 @@ export const descriptor: Descriptor = {
     "buttons",
     "selects",
     "modals",
-    "modalErrors"
+    "modalErrors",
+    "commands",
+    "ephemeral"
   ]),
   measure: Length.measure,
   limits: {
@@ -102,12 +107,26 @@ export const descriptor: Descriptor = {
     minWriteInterval: Duration.seconds(1),
     streamLength: Length.messageLength,
     streamAge: Duration.minutes(10),
+    followUpAge: Duration.minutes(30),
     ...Interactions.limits
   }
 }
 
 const pageSize = 200
 
+/**
+ * The hosts a command's `response_url` may point at. A deferral is data that
+ * may have crossed a queue, so the adapter posts only to Slack.
+ */
+const isSlackHost = (host: string): boolean =>
+  host === "slack.com" || host.endsWith(".slack.com") || host === "slack-gov.com" || host.endsWith(".slack-gov.com")
+
+/** What Slack is taken to answer for a `response_url` that is spent: assumed, not captured. */
+const spentResponseUrl = new Set(["expired_url", "used_url"])
+
+/** The `response_type` of a command's answer. */
+const responseType = (visibility: Visibility) => visibility === "ephemeral" ? "ephemeral" : "in_channel"
+
 /** The bound on each call of a file post from `chat.postMessage` on: the post, each attach and the rollback. */
 const fileCallTimeout = Duration.seconds(30)
 
@@ -812,9 +831,65 @@ export const make = (options: {
     return { id: found.id, name: found.name, isBot: found.isBot, isSelf: found.id === botUserId, raw: found.raw }
   })
 
+  /**
+   * The body of a command's answer, `Respond` or `followUp`: what a `post`
+   * of the same content sends with the default post options, after the same
+   * checks, with its `response_type`. `withPostOptions` does not reach it,
+   * so it notifies nobody and unfurls nothing.
+   */
+  const answer = Effect.fnUntraced(function*(
+    op: string,
+    content: { readonly markdown: string; readonly actions?: ReadonlyArray | undefined },
+    visibility: Visibility
+  ) {
+    const actions = content.actions ?? []
+    yield* checkActions(op, actions)
+    const body = yield* messageContent(op, Text.body(content.markdown, {}, Text.postBudget, actions))
+    return { response_type: responseType(visibility), ...body, unfurl_links: false, unfurl_media: false }
+  })
+
+  const responseUrl = (op: string, deferred: Defer): Effect.Effect => {
+    const raw = deferred.command.raw
+    const value = isObject(raw) ? string(raw, "response_url") : undefined
+    const url = value === undefined || !URL.canParse(value) ? undefined : new URL(value)
+    return url !== undefined && url.protocol === "https:" && isSlackHost(url.hostname)
+      ? Effect.succeed(url)
+      : fail(op, Errors.invalidRequest("invalid_response_url"))
+  }
+
+  /**
+   * One POST to the command's `response_url`, never retried. A spent URL is
+   * `NotFound` with detail `interaction_expired`.
+   */
+  const followUp: ChatAdapter["followUp"] = Effect.fnUntraced(function*(deferred, content) {
+    const op = "followUp"
+    const url = yield* responseUrl(op, deferred)
+    const body = yield* answer(op, content, deferred.visibility)
+    const response = yield* options.http.execute(
+      HttpClientRequest.post(url).pipe(HttpClientRequest.bodyJsonUnsafe(body))
+    ).pipe(Effect.mapError((error) => Errors.chatError(op, Errors.transport(true, error.reason._tag, error))))
+    if (response.status >= 200 && response.status < 300) return
+    const text = yield* Effect.orElseSucceed(response.text, () => "")
+    let code: string | undefined
+    try {
+      const parsed: unknown = JSON.parse(text)
+      code = isObject(parsed) ? string(parsed, "error") : undefined
+    } catch {
+      code = text.trim() === "" ? undefined : text.trim()
+    }
+    if (response.status === 404 || response.status === 410 || (code !== undefined && spentResponseUrl.has(code))) {
+      return yield* fail(
+        op,
+        new NotFound({ detail: interactionExpired, ...(code === undefined ? {} : { cause: code }) })
+      )
+    }
+    return yield* fail(op, Errors.reasonForStatus(response.status, { write: true, cause: code }))
+  })
+
   const adapter: ChatAdapter = {
     descriptor,
     nativeStream,
+    followUp,
     post: Effect.fnUntraced(function*(thread, content) {
       const parts = yield* resolve("post", thread)
       if (content.replyTo !== undefined) return yield* fail("post", new Unsupported({ capability: "replyTo" }))
@@ -948,5 +1023,5 @@ export const make = (options: {
     getUser
   }
 
-  return { adapter, user }
+  return { adapter, user, answer }
 }
diff --git a/packages/chat/slack/src/internal/interactions.ts b/packages/chat/slack/src/internal/interactions.ts
index 03634a6124b..cac49d61ed3 100644
--- a/packages/chat/slack/src/internal/interactions.ts
+++ b/packages/chat/slack/src/internal/interactions.ts
@@ -1,6 +1,7 @@
 /**
- * Slack's side of buttons, selects and modals: the checks on a message's
- * elements, the view a modal opens as, and the interactivity payloads.
+ * Slack's side of buttons, selects, modals and slash commands: the checks on
+ * a message's elements, the view a modal opens as, and the interactivity
+ * payloads and command forms.
  */
 import {
   type ChatError,
@@ -72,29 +73,38 @@ export const checkActions = (actions: ReadonlyArray): ChatErrorRe
 /** Marks a `private_metadata` the adapter packed. */
 const metadataTag = "chat1"
 
-/** Where a click happened, which a submit gives back. */
+/** Where a click or a command happened, which a submit gives back. A command has no message. */
 interface Origin {
   readonly channel: string
   readonly threadTs?: string | undefined
-  readonly messageId: string
+  readonly messageId?: string | undefined
 }
 
 /**
- * The tag, the channel, the thread's ts or nothing, the message's ts and,
- * when there is one, the consumer's metadata, joined. The metadata is last,
- * so it may hold the join.
+ * The tag, the channel, the thread's ts or nothing, the message's ts or
+ * nothing and, when there is one, the consumer's metadata, joined. The
+ * metadata is last, so it may hold the join.
  */
 const packMetadata = (origin: Origin, metadata: string | undefined): string =>
-  [metadataTag, origin.channel, origin.threadTs ?? "", origin.messageId, ...(metadata === undefined ? [] : [metadata])]
-    .join(Actions.join)
+  [
+    metadataTag,
+    origin.channel,
+    origin.threadTs ?? "",
+    origin.messageId ?? "",
+    ...(metadata === undefined ? [] : [metadata])
+  ].join(Actions.join)
 
 const unpackMetadata = (
   packed: string
 ): { readonly origin: Origin; readonly metadata: string | undefined } | undefined => {
   const parts = packed.split(Actions.join)
-  if (parts.length < 4 || parts[0] !== metadataTag || parts[1] === "" || parts[3] === "") return undefined
+  if (parts.length < 4 || parts[0] !== metadataTag || parts[1] === "") return undefined
   return {
-    origin: { channel: parts[1], threadTs: parts[2] === "" ? undefined : parts[2], messageId: parts[3] },
+    origin: {
+      channel: parts[1],
+      threadTs: parts[2] === "" ? undefined : parts[2],
+      messageId: parts[3] === "" ? undefined : parts[3]
+    },
     metadata: parts.length === 4 ? undefined : parts.slice(4).join(Actions.join)
   }
 }
@@ -126,12 +136,13 @@ const inputBlock = (element: ChatUi.TextInput | ChatUi.SelectInput) => ({
 })
 
 /**
- * The view that opens `modal` from `click`, or why it can't open.
+ * The view that opens `modal` from `from`, or why it can't open.
  *
  * - Inputs are `input` blocks whose `block_id` is the field id, and a
  *   `Text` is a `section` of plain text.
  * - The modal's id is the `callback_id`. `private_metadata` holds the
- *   click's channel, thread and message beside the consumer's metadata.
+ *   click's channel, thread and message beside the consumer's metadata. For
+ *   a command the message slot is empty.
  * - The modal's id plus its metadata is held to 2,800 code points, the id to
  *   255, the title to 24 and each label to 2,000.
  *
@@ -139,7 +150,7 @@ const inputBlock = (element: ChatUi.TextInput | ChatUi.SelectInput) => ({
  */
 export const view = (
   modal: ChatUi.Modal,
-  click: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
+  from: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatInteraction.CommandInvoked
 ): { readonly view: Readonly> } | { readonly refusal: ChatErrorReason } => {
   const refuse = (refusal: ChatErrorReason) => ({ refusal })
   const id = codePoints(modal.id)
@@ -149,7 +160,7 @@ export const view = (
   if (id > idLength) return refuse(new TooLarge({ detail: "modal_id_too_long" }))
   if (modal.elements.length > limits.modalFields) return refuse(new TooLarge({ detail: "too_many_fields" }))
   if (codePoints(modal.title) > titleLength) return refuse(new TooLarge({ detail: "title_too_long" }))
-  const parts = Address.parts(click.thread)
+  const parts = Address.parts(from.thread)
   if (Option.isNone(parts)) return refuse(new InvalidRequest({ detail: "invalid_thread" }))
   const blocks: Array = []
   for (const element of modal.elements) {
@@ -166,7 +177,10 @@ export const view = (
       callback_id: modal.id,
       title: plainText(modal.title),
       submit: plainText(modal.submitLabel ?? defaultSubmitLabel),
-      private_metadata: packMetadata({ ...parts.value, messageId: click.messageId }, modal.metadata),
+      private_metadata: packMetadata(
+        { ...parts.value, messageId: from._tag === "CommandInvoked" ? undefined : from.messageId },
+        modal.metadata
+      ),
       blocks
     }
   }
@@ -261,7 +275,28 @@ const submitted = (payload: JsonObject, teamId: string): Option.Option
+  isObject(payload) && payload.type === undefined && typeof payload.command === "string"
+
+const invoked = (payload: JsonObject, teamId: string): Option.Option => {
+  const command = string(payload, "command")
+  const channel = string(payload, "channel_id")
+  const userId = string(payload, "user_id")
+  const id = command?.startsWith("/") === true ? command.slice(1) : command
+  if (id === undefined || id === "" || channel === undefined || userId === undefined) return Option.none()
+  const text = typeof payload.text === "string" ? payload.text : ""
+  return Option.some(ChatInteraction.CommandInvoked.make({
+    id,
+    text,
+    // A command can't be typed in a thread, so its address is the channel's.
+    thread: Address.thread({ team: teamId, channel }),
     userId,
     raw: raw(payload)
   }))
@@ -269,9 +304,9 @@ const submitted = (payload: JsonObject, teamId: string): Option.Option
  * `SlackChat.interaction`: normalises, calls the handler through
  * `ChatInteraction.handle` and gives the body to answer with.
  *
- * - An ack, a close, a late click and a payload that is not the adapter's
- *   give `undefined`, an empty answer.
+ * - An ack, a close, a late click, a deferral and a payload that is not the
+ *   adapter's give `undefined`, an empty answer.
  * - `errors` gives `response_action: "errors"`, keyed by field id.
- * - A late submit gives `Late`.
- * - `OpenModal` calls `views.open` with the click's `trigger_id` before
- *   answering. A modal that can't be built, or that Slack refuses, goes to
- *   `Handler.refused`, and the click is still acked.
+ * - A late submit or command gives `Late`.
+ * - `OpenModal` calls `views.open` with the click's or command's
+ *   `trigger_id` before answering. A modal that can't be built, or that
+ *   Slack refuses, goes to `Handler.refused`, and the click is still acked.
+ * - `Respond` gives the message as the body, with its `response_type`. One
+ *   that fails the checks of a `post` goes to `Handler.refused` and gives
+ *   an empty answer.
  *
  * @internal
  */
-export const make = (options: { readonly api: Api; readonly teamId: string }) =>
+export const make = (options: {
+  readonly api: Api
+  readonly teamId: string
+  readonly answer: (
+    op: string,
+    content: { readonly markdown: string; readonly actions?: ReadonlyArray | undefined },
+    visibility: ChatInteraction.Visibility
+  ) => Effect.Effect>, ChatError>
+}) =>
 (
   payload: unknown,
   interactionOptions?: { readonly deadline?: Duration.Duration | undefined }
@@ -326,14 +373,27 @@ export const make = (options: { readonly api: Api; readonly teamId: string }) =>
     switch (reply._tag) {
       case "Late":
         // A late click is acked: its handler runs on and `handle` refuses a modal it opens.
-        return event.value._tag === "ModalSubmitted" ? reply : undefined
+        return event.value._tag === "ButtonClicked" || event.value._tag === "SelectChanged" ? undefined : reply
       case "Ack":
       case "Close":
+      case "Defer":
         return undefined
       case "Errors":
         return { response_action: "errors", errors: reply.errors }
+      case "Respond": {
+        const command = event.value as ChatInteraction.CommandInvoked
+        const handler = yield* ChatInteraction.Handler
+        return yield* options.answer("respond", reply, reply.visibility).pipe(
+          // The body is a post's, which is JSON.
+          Effect.map((body): Json | undefined => body as Json),
+          Effect.catch((error) => Effect.as(handler.refused(command, error), undefined))
+        )
+      }
       case "OpenModal": {
-        const click = event.value as ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
+        const click = event.value as
+          | ChatInteraction.ButtonClicked
+          | ChatInteraction.SelectChanged
+          | ChatInteraction.CommandInvoked
         const handler = yield* ChatInteraction.Handler
         const built = view(reply.modal, click)
         if ("refusal" in built) {
diff --git a/packages/chat/slack/src/internal/webhook.ts b/packages/chat/slack/src/internal/webhook.ts
index f71da27157e..24852e0e380 100644
--- a/packages/chat/slack/src/internal/webhook.ts
+++ b/packages/chat/slack/src/internal/webhook.ts
@@ -99,6 +99,10 @@ export const readBody = (
 
 const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
 
+/** An own property, so a field such as `__proto__` stays a field. */
+const setOwn = (record: Record, key: string, value: string) =>
+  Object.defineProperty(record, key, { value, enumerable: true, writable: true, configurable: true })
+
 const ok = HttpServerResponse.empty({ status: 200 })
 const status = (code: number) => HttpServerResponse.empty({ status: code })
 
@@ -195,11 +199,11 @@ const isLate = Schema.is(ChatInteraction.Late)
 
 /**
  * One Interactivity request: a form-encoded body whose `payload` field
- * holds the JSON.
+ * holds the JSON, or a slash command's, whose fields are the payload.
  *
  * - 413 past the body limit, 401 for a bad signature, 400 for a body with
- *   no `payload` that is a JSON object.
- * - A payload for another app is answered 200 and dropped.
+ *   neither a `payload` that is a JSON object nor a `command`.
+ * - A payload or command for another app is answered 200 and dropped.
  * - `Late` is answered 503, which keeps a modal open. Anything else is a
  *   200, with the body as JSON when there is one.
  *
@@ -213,12 +217,20 @@ export const handleInteractivity = (
     const body = yield* readBody(request, options.maxBodyBytes)
     if (Option.isNone(body)) return status(413)
     if (!(yield* options.verify(request.headers, body.value))) return status(401)
-    const field = new URLSearchParams(new TextDecoder().decode(body.value)).get("payload")
+    const form = new URLSearchParams(new TextDecoder().decode(body.value))
+    const field = form.get("payload")
     let payload: unknown
-    try {
-      payload = field === null ? undefined : JSON.parse(field)
-    } catch {
-      return status(400)
+    if (field === null && form.has("command")) {
+      // A slash command: its fields are the payload. A repeated field keeps its first value.
+      const fields: Record = {}
+      for (const [key, value] of form) if (!Object.hasOwn(fields, key)) setOwn(fields, key, value)
+      payload = fields
+    } else {
+      try {
+        payload = field === null ? undefined : JSON.parse(field)
+      } catch {
+        return status(400)
+      }
     }
     if (!isObject(payload)) return status(400)
     if (payload.api_app_id !== options.appId) return ok
diff --git a/packages/chat/slack/test/conformance.test.ts b/packages/chat/slack/test/conformance.test.ts
index e3b8f2e5fbc..77940ce337f 100644
--- a/packages/chat/slack/test/conformance.test.ts
+++ b/packages/chat/slack/test/conformance.test.ts
@@ -1,5 +1,5 @@
 /**
- * The conformance rules for buttons, selects and modals, against the adapter
+ * The conformance rules for buttons, selects, modals and commands, against the adapter
  * over a stubbed Web API that keeps what was posted. Clicks and submits are
  * built from the posted blocks and the opened views and go through
  * `SlackChat.interaction`, so the answers are tested too.
@@ -18,9 +18,12 @@ const portable = (name: string) =>
   name.startsWith("modal/") ||
   name.startsWith("edit/") && name.endsWith("Actions") ||
   name.startsWith("descriptor/measure") && name.endsWith("Actions") ||
+  name.startsWith("command/") ||
   name === "unsupported/buttons" ||
   name === "unsupported/selects" ||
-  name === "unsupported/modals"
+  name === "unsupported/modals" ||
+  name === "unsupported/commands" ||
+  name === "unsupported/ephemeral"
 
 const options = {
   platform: "slack",
@@ -32,7 +35,7 @@ const options = {
 describe("conformance over the stubbed Web API", () => {
   const names = Object.keys(conformance({
     ...options,
-    interactions: { click: () => Effect.void, submit: () => Effect.void }
+    interactions: { click: () => Effect.void, submit: () => Effect.void, command: () => Effect.void }
   })).filter(portable)
 
   for (const name of names) {
diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
index 197a8d75fdb..acb2729a912 100644
--- a/packages/chat/slack/test/interactions.test.ts
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -1,6 +1,8 @@
 /**
  * Interactivity: the normaliser on recorded and built payloads, the answers
- * `SlackChat.interaction` gives, and `layerInteractivity` over HTTP.
+ * `SlackChat.interaction` gives, `layerInteractivity` over HTTP, and a
+ * command's `followUp`. The command payloads are built from Slack's docs:
+ * none has been captured yet.
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { assert, describe, it } from "@effect/vitest"
@@ -14,7 +16,7 @@ import * as HttpRouter from "effect/http/HttpRouter"
 import * as Layer from "effect/Layer"
 import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
-import { appId, authTest, channel, fixture, makeFake, slackLayer, team } from "./utils.ts"
+import { appId, authTest, channel, commandFields, fixture, makeFake, responseUrl, slackLayer, team } from "./utils.ts"
 
 const recorded = fixture("interactivity").cases
 const join = "\u241F"
@@ -107,6 +109,26 @@ describe("normalizeInteraction", () => {
     const bare = Option.getOrThrow(normalize(submit(["chat1", channel, "", "1794600001.000100"].join(join), {})))
     assert.isFalse("metadata" in bare)
     assert.strictEqual(bare.thread.id, `${team}/${channel}`)
+    // A modal a command opened packs an empty message slot, and its submit has no messageId.
+    const fromCommand = Option.getOrThrow(normalize(submit(["chat1", channel, "", ""].join(join), {})))
+    assert.isFalse("messageId" in fromCommand)
+    assert.strictEqual(fromCommand.thread.id, `${team}/${channel}`)
+  })
+
+  it("gives a command its name without the slash, its text and the channel, known or not", () => {
+    const event = Option.getOrThrow(normalize(commandFields("/deploy", "v1 <@U1>")))
+    assert.strictEqual(event._tag, "CommandInvoked")
+    if (event._tag !== "CommandInvoked") return
+    assert.deepStrictEqual(
+      [event.id, event.text, event.userId, event.thread.id],
+      ["deploy", "v1 <@U1>", "U080YLYB277", `${team}/${channel}`]
+    )
+    assert.isFalse("token" in (event.raw as object))
+    assert.strictEqual((event.raw as any).response_url, responseUrl)
+    const { text: _, ...noText } = commandFields("/deploy", "")
+    assert.strictEqual((Option.getOrThrow(normalize(noText)) as ChatInteraction.CommandInvoked).text, "")
+    assert.isTrue(Option.isNone(normalize(commandFields("/", ""))))
+    assert.isTrue(Option.isNone(normalize(commandFields("/deploy", "", { channel_id: "" }))))
   })
 })
 
@@ -114,6 +136,8 @@ const recording = () => {
   const refused: Array = []
   let onClick: () => Effect.Effect = () => Effect.succeed(ChatInteraction.ack)
   let onSubmit: () => Effect.Effect = () => Effect.succeed(ChatInteraction.close)
+  let onCommand: (command: ChatInteraction.CommandInvoked) => Effect.Effect = () =>
+    Effect.succeed(ChatInteraction.ack)
   return {
     refused,
     set click(f: typeof onClick) {
@@ -122,9 +146,13 @@ const recording = () => {
     set submit(f: typeof onSubmit) {
       onSubmit = f
     },
+    set command(f: typeof onCommand) {
+      onCommand = f
+    },
     layer: Layer.succeed(ChatInteraction.Handler, {
       click: () => onClick(),
       submit: () => onSubmit(),
+      command: (command) => onCommand(command),
       refused: (_, error) => Effect.sync(() => void refused.push(error))
     })
   }
@@ -207,6 +235,86 @@ describe("SlackChat.interaction", () => {
       )
       assert.strictEqual(fake.called("views.open").length, 1)
     }))
+
+  it.live("answers a command with the message a post sends, privately by default, or refuses it", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest, "views.open": { ok: true, view: { id: "V1" } } })
+      const handler = recording()
+      const command = commandFields("/deploy", "v1")
+      handler.command = (event) =>
+        Effect.succeed(ChatInteraction.respond({ markdown: "Deploying **" + event.text + "**" }))
+      const answer: any = yield* interact(fake, handler, command)
+      assert.deepStrictEqual(
+        [answer.response_type, answer.text, answer.blocks[0].type, answer.blocks[0].text, answer.unfurl_links],
+        ["ephemeral", "Deploying **v1**", "markdown", "Deploying **v1**", false]
+      )
+      handler.command = () => Effect.succeed(ChatInteraction.respond({ markdown: "Hi", visibility: "public" }))
+      assert.strictEqual(((yield* interact(fake, handler, command)) as any).response_type, "in_channel")
+      // Nothing is answered for a deferral, a modal or a refused answer.
+      handler.command = (event) => Effect.succeed(ChatInteraction.defer(event))
+      assert.isUndefined(yield* interact(fake, handler, command))
+      handler.command = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("m") }))
+      assert.isUndefined(yield* interact(fake, handler, command))
+      const [call] = fake.called("views.open")
+      assert.strictEqual(call.params.trigger_id, "trigger-command")
+      assert.strictEqual(JSON.parse(call.params.view).private_metadata, ["chat1", channel, "", "", "m"].join(join))
+      handler.command = () => Effect.succeed(ChatInteraction.respond({ markdown: "x".repeat(12_001) }))
+      assert.isUndefined(yield* interact(fake, handler, command))
+      assert.deepStrictEqual(handler.refused.map((error) => [error.op, error.reason._tag]), [["respond", "TooLarge"]])
+    }))
+})
+
+describe("followUp", () => {
+  const deferred = (raw: Record, visibility: ChatInteraction.Visibility) =>
+    ChatInteraction.defer(
+      ChatInteraction.CommandInvoked.make({
+        id: "summarize",
+        text: "",
+        thread: SlackChat.thread({ team, channel }),
+        userId: "U080YLYB277",
+        raw: raw as any
+      }),
+      { visibility }
+    )
+
+  it.effect("posts once to the response_url with the deferral's response_type", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest, "response_url": { status: 200, body: "ok" } })
+      const { token: _, ...raw } = commandFields("/summarize", "")
+      yield* Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred(raw, "public"), { markdown: "Done" })).pipe(
+        Effect.provide(slackLayer(fake))
+      )
+      const calls = fake.called("response_url")
+      assert.deepStrictEqual(
+        calls.map(({ params }) => [params.url, params.response_type, params.text]),
+        [[responseUrl, "in_channel", "Done"]]
+      )
+    }))
+
+  it.effect("refuses a response_url off Slack, and maps a spent one to interaction_expired", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({
+        "auth.test": authTest,
+        "response_url": { status: 404, body: { ok: false, error: "expired_url" } }
+      })
+      const failure = (raw: Record) =>
+        Effect.flip(Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred(raw, "ephemeral"), { markdown: "x" })))
+          .pipe(
+            Effect.provide(slackLayer(fake))
+          )
+      const offSlack = yield* failure({ response_url: "https://hooks.slack.com.evil.test/commands/1" })
+      const plain = yield* failure({ response_url: responseUrl.replace("https:", "http:") })
+      const spent = yield* failure({ response_url: responseUrl })
+      assert.deepStrictEqual(
+        [offSlack, plain, spent].map((error) => [error.op, error.reason._tag, error.reason.detail]),
+        [
+          ["followUp", "InvalidRequest", "invalid_response_url"],
+          ["followUp", "InvalidRequest", "invalid_response_url"],
+          ["followUp", "NotFound", "interaction_expired"]
+        ]
+      )
+      assert.strictEqual(fake.called("response_url").length, 1)
+    }))
 })
 
 describe("layerInteractivity", () => {
@@ -221,8 +329,11 @@ describe("layerInteractivity", () => {
     return "v0=" + Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("")
   }
 
-  const post = async (payload: unknown, options?: { readonly signature?: string }) => {
-    const body = new URLSearchParams({ payload: JSON.stringify(payload) }).toString()
+  const post = async (
+    payload: unknown,
+    options?: { readonly signature?: string; readonly form?: Array<[string, string]> }
+  ) => {
+    const body = new URLSearchParams(options?.form ?? { payload: JSON.stringify(payload) }).toString()
     const timestamp = String(Math.floor(Date.now() / 1000))
     return new Request("http://localhost/slack/interactivity", {
       method: "POST",
@@ -235,6 +346,45 @@ describe("layerInteractivity", () => {
     })
   }
 
+  const serve = (handler: ReturnType) => {
+    const app = SlackChat.layerInteractivity({
+      path: "/slack/interactivity",
+      signingSecret: Redacted.make(secret),
+      appId,
+      deadline: Duration.millis(50)
+    }).pipe(
+      Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
+      Layer.provide(Chat.layer),
+      Layer.provide(handler.layer),
+      Layer.provide(makeFake({ "auth.test": authTest }).layer)
+    )
+    const { dispose, handler: web } = HttpRouter.toWebHandler(app, { disableLogger: true })
+    const send = (payload: unknown, options?: Parameters[1]) =>
+      Effect.promise(() => post(payload, options).then(web))
+    return { dispose: Effect.promise(() => dispose()), send }
+  }
+
+  it.live("takes a command's form, keeping a repeated field's first value, and answers a late one 503", () =>
+    Effect.gen(function*() {
+      const handler = recording()
+      const { dispose, send } = serve(handler)
+      const seen: Array = []
+      handler.command = (event) =>
+        Effect.sync(() => seen.push(event.text)).pipe(
+          Effect.as(ChatInteraction.respond({ markdown: "Hi", visibility: "public" }))
+        )
+      const form = (text: string) =>
+        [...Object.entries(commandFields("/deploy", text)), ["text", "second"]] as Array<[string, string]>
+      const answered = yield* send(undefined, { form: form("first") })
+      assert.strictEqual(answered.status, 200)
+      assert.strictEqual((yield* Effect.promise(() => answered.json())).response_type, "in_channel")
+      assert.deepStrictEqual(seen, ["first"])
+
+      handler.command = () => Effect.as(Effect.never, ChatInteraction.ack)
+      assert.strictEqual((yield* send(undefined, { form: form("late") })).status, 503)
+      yield* dispose
+    }))
+
   it.live("answers a late submit 503, errors as JSON, and a bad signature 401", () =>
     Effect.gen(function*() {
       const handler = recording()
diff --git a/packages/chat/slack/test/slack.ts b/packages/chat/slack/test/slack.ts
index ff56d28569f..61be506b452 100644
--- a/packages/chat/slack/test/slack.ts
+++ b/packages/chat/slack/test/slack.ts
@@ -1,7 +1,7 @@
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { type Interactions, NoSuchElement } from "effect/chat/ChatTest"
 import * as Effect from "effect/Effect"
-import { appId, authTest, botUserId, makeFake, team } from "./utils.ts"
+import { appId, authTest, botUserId, commandFields, makeFake, team } from "./utils.ts"
 
 const tim = "U080YLYB277"
 
@@ -9,8 +9,9 @@ const tim = "U080YLYB277"
  * A Slack that keeps the messages the adapter posts, with their blocks, and
  * records every view it opens. `interactions` is the conformance hook: it
  * builds Slack's `block_actions` and `view_submission` payloads from what
- * was posted and opened, sends them through `SlackChat.interaction` and
- * keeps the answers.
+ * was posted and opened, and a slash command's form fields, sends them
+ * through `SlackChat.interaction` and keeps the answers. A command's
+ * `response_url` answers `ok`.
  */
 export const makeSlack = () => {
   const messages = new Map()
@@ -53,7 +54,8 @@ export const makeSlack = () => {
       const view = { ...JSON.parse(params.view), id: "V" + ++viewCount }
       views.push(view)
       return { ok: true, view }
-    }
+    },
+    "response_url": { status: 200, body: "ok" }
   })
 
   /** The view the last click opened, until a submit closes it. */
@@ -71,6 +73,14 @@ export const makeSlack = () => {
   const user = { id: tim, username: "tim", name: "tim", team_id: team }
 
   const interactions: Interactions = {
+    command: Effect.fnUntraced(function*(thread, id, options) {
+      const parts = SlackChat.parts(thread)
+      if (parts._tag === "None") return
+      const before = views.length
+      const { token: _, ...fields } = commandFields("/" + id, options?.text ?? "", { channel_id: parts.value.channel })
+      yield* deliver(fields)
+      opened = views.length > before ? views[views.length - 1] : undefined
+    }),
     click: Effect.fnUntraced(function*(messageId, id, options) {
       const message = messages.get(messageId)
       const block = message?.blocks.find((block: any) => block.type === "actions")
diff --git a/packages/chat/slack/test/utils.ts b/packages/chat/slack/test/utils.ts
index a4a2bf4fd85..70405d4b029 100644
--- a/packages/chat/slack/test/utils.ts
+++ b/packages/chat/slack/test/utils.ts
@@ -69,7 +69,8 @@ export const messageEnvelope = (
 
 export interface FakeCall {
   readonly method: string
-  readonly params: Record
+  /** The form fields of a Web API call, or the JSON body of a `response_url` post with its `url`. */
+  readonly params: Record
 }
 
 export type Answer =
@@ -93,10 +94,12 @@ export const makeFake = (
     if (Array.isArray(answer)) queues.set(method, [...answer])
   }
   const respond = (request: HttpClientRequest.HttpClientRequest, url: URL): Response | typeof hang => {
-    const method = url.pathname.replace(/^\/api\//, "")
+    // A command's `response_url` takes JSON, and is recorded as one method.
+    const responseUrl = url.pathname.startsWith("/commands/")
+    const method = responseUrl ? "response_url" : url.pathname.replace(/^\/api\//, "")
     const body = request.body
     const text = body._tag === "Uint8Array" ? body.text ?? new TextDecoder().decode(body.body) : ""
-    const params = Object.fromEntries(new URLSearchParams(text))
+    const params = responseUrl ? { url: url.href, ...JSON.parse(text) } : Object.fromEntries(new URLSearchParams(text))
     calls.push({ method, params })
     const entry = script[method]
     let answer: Answer
@@ -129,6 +132,30 @@ export const makeFake = (
 
 export const authTest = { ok: true, user_id: botUserId, team_id: team }
 
+/** A command's `response_url`, on Slack's host as the adapter requires. */
+export const responseUrl = `https://hooks.slack.com/commands/${team}/1794600000/abcdef`
+
+/**
+ * A slash command's form fields, as Slack's docs list them. Built, not
+ * captured: no command has been recorded from Slack yet.
+ */
+export const commandFields = (command: string, text: string, overrides?: Record) => ({
+  token: "verification",
+  team_id: team,
+  team_domain: "effectfulworkspace",
+  channel_id: channel,
+  channel_name: "scratch",
+  user_id: "U080YLYB277",
+  user_name: "tim",
+  command,
+  text,
+  api_app_id: appId,
+  is_enterprise_install: "false",
+  response_url: responseUrl,
+  trigger_id: "trigger-command",
+  ...overrides
+})
+
 /** `Chat`, `Registry` and the Slack adapter on a fake. */
 export const slackLayer = (fake: ReturnType) =>
   SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team }).pipe(

From 25a4584f9b6e846bea75b669d9da3e2c3963c9ea Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 19:14:37 +0000
Subject: [PATCH 48/89] chat-discord: slash commands, private replies, followUp
 and commandRequests

---
 .changeset/chat-discord-commands.md           |   5 +
 packages/chat/discord/src/DiscordChat.ts      | 104 +++++++--
 packages/chat/discord/src/internal/adapter.ts | 139 +++++++++--
 .../chat/discord/src/internal/interactions.ts | 217 +++++++++++++++---
 .../chat/discord/test/conformance.test.ts     |   9 +-
 packages/chat/discord/test/discord.ts         |  54 ++++-
 .../chat/discord/test/interactions.test.ts    | 216 ++++++++++++++++-
 7 files changed, 655 insertions(+), 89 deletions(-)
 create mode 100644 .changeset/chat-discord-commands.md

diff --git a/.changeset/chat-discord-commands.md b/.changeset/chat-discord-commands.md
new file mode 100644
index 00000000000..4a5a899a483
--- /dev/null
+++ b/.changeset/chat-discord-commands.md
@@ -0,0 +1,5 @@
+---
+"@effect/chat-discord": patch
+---
+
+Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`.
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index e30ae14a729..399591746dd 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -15,6 +15,8 @@
  *   missing.
  * - Bot permissions: View Channel, Send Messages, Send Messages in Threads,
  *   Create Public Threads, Read Message History and Attach Files.
+ * - Slash commands need the `applications.commands` scope, and are
+ *   registered by the consumer with the payloads `commandRequests` gives.
  *
  * @stability unstable
  * @since 4.1.5
@@ -63,20 +65,30 @@ import { CurrentPostOptions } from "./internal/options.ts"
  *   way again, such as a deleted channel, is logged and the event dropped.
  * - `interaction` takes one `INTERACTION_CREATE` payload, from the gateway
  *   or from an HTTP interactions endpoint. It reads it with a Schema, so it
- *   takes no dfx type, and ignores an interaction that is not from an
- *   element this adapter built, a slash command for one. It calls the
- *   handler through `ChatInteraction.handle` and answers through the
- *   interaction callback endpoint, which has to land inside Discord's 3
- *   seconds: `deadline` is the handler's share, 2 seconds by default.
+ *   takes no dfx type, and ignores an interaction it can't express: a
+ *   message or user command, an autocomplete request, a slash command with
+ *   anything but at most one string option. It calls the handler through
+ *   `ChatInteraction.handle` and answers through the interaction callback
+ *   endpoint, which has to land inside Discord's 3 seconds: `deadline` is
+ *   the handler's share, 2 seconds by default.
  * - A click is answered with callback type 6, or type 9 for `OpenModal`.
  *   A submit's `close` is type 6. An `errors` reply is type 4 with the
  *   ephemeral flag, listing each message as plain text, and the modal closes: Discord
  *   can't show an error inside a modal, so the descriptor has no
  *   `modalErrors`.
- * - A modal that can't be built, or whose callback fails, goes to
- *   `Handler.refused`. A callback that comes back 404 `Unknown interaction`
- *   was late: for a modal that is `NotFound` with detail
- *   `interaction_expired`. A failed ack is logged.
+ * - A slash command goes to `Handler.command`. `respond` is callback type
+ *   4 with the message a `post` sends, `defer` type 5 and `OpenModal` type
+ *   9, each with the ephemeral flag when private. An `Ack`, which is what a
+ *   command nobody handles gets, sends nothing, so a command another library
+ *   owns is left to it.
+ * - `followUp` edits the deferred command's original response, with the
+ *   application id and token from its `raw`. It fails `NotFound` with detail
+ *   `interaction_expired` from 15 minutes after the command, read from the
+ *   interaction's id, without calling Discord.
+ * - A modal that can't be built, a reply to a command that fails the checks
+ *   of a `post`, or a callback that fails, goes to `Handler.refused`. A
+ *   callback that comes back 404 `Unknown interaction` was late: that is
+ *   `NotFound` with detail `interaction_expired`. A failed ack is logged.
  * - `guild` reads the channel, cached. `None` for a direct.
  *
  * @stability unstable
@@ -507,12 +519,17 @@ export const layerGatewayInteractions: Layer.Layer<
  *   `custom_id`.
  * - The thread and message come from the `message` Discord sends with the
  *   interaction, so a modal's submit carries the message whose element
- *   opened it.
+ *   opened it. A modal a command opened has no message, so its submit has
+ *   no `messageId`, and its thread is the channel.
  * - A submit's `values` hold each answered input by id. An input left
  *   empty is absent.
- * - Anything else, a slash command or an interaction with no message, is
- *   `None`.
- * - `raw` is the payload, undecoded.
+ * - A slash command with no options, or one string option, gives
+ *   `CommandInvoked`: `id` is its name and `text` the option's value or
+ *   the empty string.
+ * - Anything else, a message or user command, a slash command with other
+ *   options, or a click with no message, is `None`.
+ * - `raw` is the payload, undecoded. For a command it holds the token that
+ *   answers it, so it is a credential for 15 minutes.
  *
  * @stability unstable
  * @category normalization
@@ -521,6 +538,67 @@ export const layerGatewayInteractions: Layer.Layer<
 export const normalizeInteraction: (interaction: unknown) => Option.Option =
   Interactions.normalize
 
+/**
+ * The create payload of each command in `group`, in the group's order, for
+ * Discord's application commands endpoint.
+ *
+ * **Details**
+ *
+ * - Each is a `CHAT_INPUT` command with the definition's name and
+ *   description, and one `STRING` option when it has an `argument`. Each
+ *   fits dfx's `ApplicationCommandCreateRequest`.
+ * - The definitions in `group` that are not commands are skipped.
+ *
+ * **Gotchas**
+ *
+ * - The adapter registers nothing. Discord's bulk overwrite replaces the
+ *   application's whole list, so the consumer sends these beside its other
+ *   commands, in one call.
+ * - dfx's gateway runner syncs its own commands the same way when it
+ *   starts, which would delete these. A consumer running both adds these to
+ *   that list, or switches the sync off with `setInteractionsSync(false)`.
+ * - A field the definition lacks, such as `default_member_permissions`, is
+ *   spread onto the payload by the consumer.
+ *
+ * **Example** (Registering the commands beside dfx's own)
+ *
+ * ```ts import.meta.vitest
+ * import { DiscordChat } from "@effect/chat-discord"
+ * import { DiscordREST } from "dfx/DiscordREST"
+ * import { Effect } from "effect"
+ * import { ChatInteraction } from "effect/chat"
+ *
+ * const Commands = ChatInteraction.group(
+ *   ChatInteraction.command("summarize", { description: "Summarize this thread" })
+ * )
+ *
+ * export const register = Effect.gen(function*() {
+ *   const rest = yield* DiscordREST
+ *   const app = yield* rest.getMyApplication()
+ *   yield* rest.bulkSetApplicationCommands(app.id, [...DiscordChat.commandRequests(Commands)])
+ * })
+ * ```
+ *
+ * @stability unstable
+ * @category commands
+ * @since 4.1.5
+ */
+export const commandRequests: (group: ChatInteraction.Group) => ReadonlyArray<{
+  /** `CHAT_INPUT`. */
+  readonly type: 1
+  readonly name: string
+  readonly description: string
+  /** One `STRING` option when the command has an `argument`, absent otherwise. */
+  readonly options?:
+    | ReadonlyArray<{
+      readonly type: 3
+      readonly name: string
+      readonly description: string
+      readonly required: boolean
+    }>
+    | undefined
+}> = Interactions.commandRequests
+
 /**
  * Discord options for every write inside an effect.
  *
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index c348098d912..64a68f63296 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -23,6 +23,7 @@ import * as ChatInteraction from "effect/chat/ChatInteraction"
 import type { ChatMessage } from "effect/chat/ChatMessage"
 import type * as ChatThread from "effect/chat/ChatThread"
 import type { Action } from "effect/chat/ChatUi"
+import * as Clock from "effect/Clock"
 import * as DateTime from "effect/DateTime"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
@@ -58,7 +59,9 @@ export const descriptor: Descriptor = {
     "getUser",
     "buttons",
     "selects",
-    "modals"
+    "modals",
+    "commands",
+    "ephemeral"
   ]),
   // Components sit beside `content`, so the elements cost nothing here.
   measure: (markdown) => Length.codePoints(markdown),
@@ -67,6 +70,7 @@ export const descriptor: Descriptor = {
     filesPerMessage: 10,
     uploadBytes: 10 * 1024 * 1024,
     minWriteInterval: Duration.millis(1500),
+    followUpAge: Duration.minutes(15),
     ...Interactions.limits
   }
 }
@@ -79,6 +83,17 @@ const THREAD_ALREADY_CREATED = 160004
 const WRONG_CHANNEL_TYPE = 50024
 /** Discord's code for "unknown interaction": a callback after the 3 seconds. */
 const UNKNOWN_INTERACTION = 10062
+/**
+ * Discord's codes for an interaction token it no longer takes: "invalid
+ * webhook token" and "unknown webhook". Taken from the docs' list, not
+ * captured after 15 minutes.
+ */
+const SPENT_TOKEN = [50027, 10015]
+/** The start of Discord's snowflake clock, in Unix milliseconds. */
+const DISCORD_EPOCH = 1_420_070_400_000
+
+/** When a snowflake was made, in Unix milliseconds. */
+const snowflakeMillis = (id: string): number => Number(BigInt(id) >> BigInt("22")) + DISCORD_EPOCH
 
 const optional = (schema: S) => Schema.optionalKey(Schema.NullOr(schema))
 
@@ -465,10 +480,63 @@ export const make = Effect.fnUntraced(function*(options: {
       )
     }))
 
+  /**
+   * The message a `post` of the same content sends with the default post
+   * options, after the same checks: no mentions and no embeds.
+   * `withPostOptions` does not reach a command's answer.
+   */
+  const message = Effect.fnUntraced(function*(
+    op: string,
+    content: { readonly markdown: string; readonly actions?: ReadonlyArray | undefined }
+  ) {
+    const rows = yield* components(op, content.actions)
+    yield* checkMessageLength(descriptor, op, content.markdown)
+    return {
+      content: content.markdown,
+      allowed_mentions: allowedMentions(undefined),
+      flags: flags({}),
+      ...(rows.length === 0 ? {} : { components: rows })
+    }
+  })
+
+  /**
+   * Edits the original response of a deferred command, once. Refused before
+   * the call past `followUpAge`, read from the interaction's id. A token
+   * Discord no longer takes is `interaction_expired` too.
+   */
+  const followUp: ChatAdapter["followUp"] = Effect.fnUntraced(function*(deferred, content) {
+    const op = "followUp"
+    const to = deferred.command.thread.platform === Normalize.platform && snowflake.test(deferred.command.thread.id)
+      ? Interactions.followUpTo(deferred.command.raw)
+      : undefined
+    if (to === undefined || !snowflake.test(to.id)) return yield* fail(op, Errors.invalidRequest("invalid_interaction"))
+    const expired = new NotFound({ detail: interactionExpired })
+    const now = yield* Clock.currentTimeMillis
+    if (now - snowflakeMillis(to.id) >= Duration.toMillis(descriptor.limits.followUpAge!)) {
+      return yield* fail(op, expired)
+    }
+    const body = yield* message(op, content)
+    const ephemeral = deferred.visibility === "ephemeral" ? 1 << 6 : 0
+    yield* call(
+      op,
+      rest.updateOriginalWebhookMessage(to.applicationId, to.token, {
+        payload: { ...body, flags: body.flags | ephemeral }
+      }),
+      true
+    ).pipe(
+      Effect.mapError((error) =>
+        SPENT_TOKEN.some((code) => Errors.hasCode(code)(error))
+          ? Errors.chatError(op, new NotFound({ detail: interactionExpired, cause: error.reason }))
+          : error
+      )
+    )
+  })
+
   const adapter: ChatAdapter = {
     descriptor,
     post,
     edit,
+    followUp,
     delete: Effect.fnUntraced(function*(thread, messageId) {
       const channelId = yield* resolve("delete", thread)
       yield* call("delete", rest.deleteMessage(channelId, messageId), true)
@@ -525,34 +593,67 @@ export const make = Effect.fnUntraced(function*(options: {
           return
         case "Ack":
         case "Close":
+          // Type 6 is no answer to a command, so an unhandled one is left to whoever owns it.
+          if (event.value._tag === "CommandInvoked") return
           return yield* logged(callback("ack", to, Interactions.ackCallback))
         case "Errors":
           return yield* logged(callback("errors", to, Interactions.errorsCallback(reply.errors)))
         case "OpenModal": {
-          const click = event.value as ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged
-          const handler = yield* ChatInteraction.Handler
+          const from = event.value as
+            | ChatInteraction.ButtonClicked
+            | ChatInteraction.SelectChanged
+            | ChatInteraction.CommandInvoked
           const data = Interactions.modalData(reply.modal)
           if (!("custom_id" in data)) {
-            // The click is still answered, so the person sees no failure for a modal that could not be built.
-            yield* logged(callback("ack", to, Interactions.ackCallback))
-            return yield* handler.refused(click, Errors.chatError("openModal", data))
+            // A click is still answered, so the person sees no failure for a modal that could not be built.
+            // A command has no silent answer, so it gets none, and Discord shows its own failure.
+            if (from._tag !== "CommandInvoked") yield* logged(callback("ack", to, Interactions.ackCallback))
+            const handler = yield* ChatInteraction.Handler
+            return yield* handler.refused(from, Errors.chatError("openModal", data))
           }
-          yield* callback("openModal", to, Interactions.modalCallback(data)).pipe(
-            Effect.catch((error) =>
-              handler.refused(
-                click,
-                Errors.hasCode(UNKNOWN_INTERACTION)(error)
-                  ? Errors.chatError(
-                    "openModal",
-                    new NotFound({ detail: interactionExpired, cause: error.reason })
-                  )
-                  : error
-              )
-            )
-          )
+          return yield* answer(from, "openModal", to, Effect.succeed(Interactions.modalCallback(data)))
         }
+        case "Respond":
+          return yield* answer(
+            event.value as ChatInteraction.CommandInvoked,
+            "respond",
+            to,
+            Effect.map(message("respond", reply), (body) => Interactions.respondCallback(body, reply.visibility))
+          )
+        case "Defer":
+          return yield* answer(
+            event.value as ChatInteraction.CommandInvoked,
+            "defer",
+            to,
+            Effect.succeed(Interactions.deferCallback(reply.visibility))
+          )
       }
     })
 
+  /**
+   * Sends a reply that must land, or tells `Handler.refused`: a reply that
+   * fails its checks sends nothing, and a callback that comes back
+   * `Unknown interaction` was late, which is `interaction_expired`.
+   */
+  const answer = (
+    event: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatInteraction.CommandInvoked,
+    op: string,
+    to: { readonly id: string; readonly token: string },
+    payload: Effect.Effect
+  ): Effect.Effect =>
+    Effect.gen(function*() {
+      const handler = yield* ChatInteraction.Handler
+      yield* Effect.flatMap(payload, (built) => callback(op, to, built)).pipe(
+        Effect.catch((error) =>
+          handler.refused(
+            event,
+            Errors.hasCode(UNKNOWN_INTERACTION)(error)
+              ? Errors.chatError(op, new NotFound({ detail: interactionExpired, cause: error.reason }))
+              : error
+          )
+        )
+      )
+    })
+
   return { adapter, guild, channelType, interaction }
 })
diff --git a/packages/chat/discord/src/internal/interactions.ts b/packages/chat/discord/src/internal/interactions.ts
index 451b15b2999..6ace04de57b 100644
--- a/packages/chat/discord/src/internal/interactions.ts
+++ b/packages/chat/discord/src/internal/interactions.ts
@@ -34,6 +34,7 @@ const labelLength = 45
 /** Discord's interaction callback types. */
 const DEFERRED_UPDATE_MESSAGE = 6
 const CHANNEL_MESSAGE_WITH_SOURCE = 4
+const DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5
 const MODAL = 9
 const EPHEMERAL = 1 << 6
 
@@ -201,6 +202,33 @@ export const errorsCallback = (errors: Readonly>): Callba
   }
 })
 
+/**
+ * The answer to a `respond` reply: the message a `post` sends, with the
+ * ephemeral flag when private.
+ *
+ * @internal
+ */
+export const respondCallback = (message: {
+  readonly content: string
+  readonly allowed_mentions: Discord.MessageAllowedMentionsRequest
+  readonly flags: number
+  readonly components?: ReadonlyArray | undefined
+}, visibility: ChatInteraction.Visibility): Callback => ({
+  type: CHANNEL_MESSAGE_WITH_SOURCE,
+  data: { ...message, flags: message.flags | (visibility === "ephemeral" ? EPHEMERAL : 0) }
+})
+
+/**
+ * The answer to a `defer` reply. The visibility is fixed here and holds for
+ * the edit that follows.
+ *
+ * @internal
+ */
+export const deferCallback = (visibility: ChatInteraction.Visibility): Callback => ({
+  type: DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE,
+  ...(visibility === "ephemeral" ? { data: { flags: EPHEMERAL } } : {})
+})
+
 // Inbound
 
 const optional = (schema: S) => Schema.optionalKey(Schema.NullOr(schema))
@@ -218,8 +246,15 @@ const ModalComponent = Schema.Struct({
   components: optional(Schema.Array(Input))
 })
 
+const CommandOption = Schema.Struct({
+  type: Schema.Number,
+  name: optional(Schema.String),
+  value: optional(Schema.Unknown)
+})
+
 const InteractionFields = Schema.Struct({
   id: Schema.String,
+  application_id: optional(Schema.String),
   type: Schema.Number,
   token: Schema.String,
   channel_id: optional(Schema.String),
@@ -227,18 +262,25 @@ const InteractionFields = Schema.Struct({
   user: optional(Schema.Struct({ id: Schema.String })),
   message: optional(Schema.Struct({ id: Schema.String, channel_id: optional(Schema.String) })),
   data: Schema.Struct({
-    custom_id: Schema.String,
+    custom_id: optional(Schema.String),
     component_type: optional(Schema.Number),
     values: optional(Schema.Array(Schema.String)),
-    components: optional(Schema.Array(ModalComponent))
+    components: optional(Schema.Array(ModalComponent)),
+    name: optional(Schema.String),
+    type: optional(Schema.Number),
+    options: optional(Schema.Array(CommandOption))
   })
 })
 
 const decodeFields = Schema.decodeUnknownOption(InteractionFields)
 
-/** Discord's interaction types for a component click and a modal submit. */
+/** Discord's interaction types for a command, a component click and a modal submit. */
+const APPLICATION_COMMAND = 2
 const MESSAGE_COMPONENT = 3
 const MODAL_SUBMIT = 5
+/** Discord's command type for a slash command, and its option type for a string. */
+const CHAT_INPUT = 1
+const STRING = 3
 
 /**
  * The id and token to answer an interaction with, read from its payload.
@@ -248,10 +290,36 @@ const MODAL_SUBMIT = 5
 export const answerTo = (raw: unknown): { readonly id: string; readonly token: string } | undefined =>
   Option.getOrUndefined(Option.map(decodeFields(raw), ({ id, token }) => ({ id, token })))
 
+/**
+ * The application id and token a deferred command's response is edited
+ * with, and the interaction's id, read from its payload.
+ *
+ * @internal
+ */
+export const followUpTo = (
+  raw: unknown
+): { readonly id: string; readonly applicationId: string; readonly token: string } | undefined =>
+  Option.getOrUndefined(
+    Option.flatMap(decodeFields(raw), ({ application_id, id, token }) =>
+      typeof application_id === "string" && application_id !== ""
+        ? Option.some({ id, applicationId: application_id, token })
+        : Option.none())
+  )
+
+/**
+ * The text of a slash command's options: none, or one string. Undefined for
+ * anything else.
+ */
+const commandText = (options: ReadonlyArray | null | undefined): string | undefined => {
+  if (options === null || options === undefined || options.length === 0) return ""
+  const [option] = options
+  return options.length === 1 && option.type === STRING && typeof option.value === "string" ? option.value : undefined
+}
+
 /**
  * The interaction a payload is, when it is a click on a button or string
- * select, or a submit of a modal opened from a message. Anything else, a
- * slash command for one, is none.
+ * select, a submit of a modal, or a slash command with at most one string
+ * option. Anything else, a message or user command for one, is none.
  *
  * @internal
  */
@@ -262,49 +330,124 @@ export const normalize = (raw: unknown): Option.Option = {}
-    for (const component of data.components ?? []) {
-      const inputs = component.component === null || component.component === undefined
-        ? component.components ?? []
-        : [component.component]
-      for (const input of inputs) {
-        const value = input.value ?? input.values?.[0]
-        if (typeof input.custom_id === "string" && value !== null && value !== undefined && value !== "") {
-          // An own property, so an id such as `__proto__` keeps its answer.
-          Object.defineProperty(values, input.custom_id, {
-            value,
-            enumerable: true,
-            writable: true,
-            configurable: true
-          })
-        }
+  return Option.none()
+}
+
+/** A modal's submit. One a command opened has no `message`, and no `messageId`. */
+const submitted = (
+  fields: typeof InteractionFields.Type,
+  customIdValue: string,
+  channelId: string,
+  userId: string,
+  raw: unknown
+): Option.Option => {
+  const values: Record = {}
+  for (const component of fields.data.components ?? []) {
+    const inputs = component.component === null || component.component === undefined
+      ? component.components ?? []
+      : [component.component]
+    for (const input of inputs) {
+      const value = input.value ?? input.values?.[0]
+      if (typeof input.custom_id === "string" && value !== null && value !== undefined && value !== "") {
+        // An own property, so an id such as `__proto__` keeps its answer.
+        Object.defineProperty(values, input.custom_id, {
+          value,
+          enumerable: true,
+          writable: true,
+          configurable: true
+        })
       }
     }
-    const { id, value: metadata } = splitCustomId(data.custom_id)
-    return Option.some(ChatInteraction.ModalSubmitted.make({
-      id,
-      ...(metadata === undefined ? {} : { metadata }),
-      values,
-      ...origin
-    }))
   }
-  return Option.none()
+  const { id, value: metadata } = splitCustomId(customIdValue)
+  const message = fields.message
+  return Option.some(ChatInteraction.ModalSubmitted.make({
+    id,
+    ...(metadata === undefined ? {} : { metadata }),
+    values,
+    thread: Normalize.thread(channelId),
+    ...(message === null || message === undefined ? {} : { messageId: message.id }),
+    userId,
+    raw: raw as Schema.Json
+  }))
+}
+
+/**
+ * The create payload of each command in `group`, in the group's order.
+ *
+ * @internal
+ */
+export const commandRequests = (group: ChatInteraction.Group): ReadonlyArray<{
+  readonly type: 1
+  readonly name: string
+  readonly description: string
+  readonly options?:
+    | ReadonlyArray<{
+      readonly type: 3
+      readonly name: string
+      readonly description: string
+      readonly required: boolean
+    }>
+    | undefined
+}> => {
+  const out: Array<{
+    readonly type: 1
+    readonly name: string
+    readonly description: string
+    readonly options?: ReadonlyArray<{
+      readonly type: 3
+      readonly name: string
+      readonly description: string
+      readonly required: boolean
+    }>
+  }> = []
+  for (const definition of (group.definitions as ReadonlyMap).values()) {
+    if (definition.kind !== "command") continue
+    const { argument } = definition
+    out.push({
+      type: CHAT_INPUT,
+      name: definition.id,
+      description: definition.description,
+      ...(argument === undefined ? {} : {
+        options: [{
+          type: STRING,
+          name: argument.name,
+          description: argument.description,
+          required: argument.required
+        }]
+      })
+    })
+  }
+  return out
 }
diff --git a/packages/chat/discord/test/conformance.test.ts b/packages/chat/discord/test/conformance.test.ts
index 0b8524d03f6..778c4d641cd 100644
--- a/packages/chat/discord/test/conformance.test.ts
+++ b/packages/chat/discord/test/conformance.test.ts
@@ -1,5 +1,5 @@
 /**
- * The conformance rules for files, buttons and modals, against the adapter
+ * The conformance rules for files, buttons, modals and commands, against the adapter
  * over a stubbed `DiscordREST` that keeps what was posted. Clicks and
  * submits are built from the posted components and go through
  * `DiscordChat.interaction`, so the callback answers are tested too.
@@ -17,9 +17,12 @@ const portable = (name: string) =>
   name.startsWith("modal/") ||
   name.startsWith("edit/") && name.endsWith("Actions") ||
   name.startsWith("descriptor/measure") && name.endsWith("Actions") ||
+  name.startsWith("command/") ||
   name === "unsupported/buttons" ||
   name === "unsupported/selects" ||
-  name === "unsupported/modals"
+  name === "unsupported/modals" ||
+  name === "unsupported/commands" ||
+  name === "unsupported/ephemeral"
 
 describe("conformance over the stubbed DiscordREST", () => {
   const names = Object.keys(conformance({
@@ -28,7 +31,7 @@ describe("conformance over the stubbed DiscordREST", () => {
     userPosts: () => Effect.die("unused"),
     parseMention: DiscordChat.parseMention,
     refuseFiles: () => Effect.void,
-    interactions: { click: () => Effect.void, submit: () => Effect.void }
+    interactions: { click: () => Effect.void, submit: () => Effect.void, command: () => Effect.void }
   })).filter(portable)
 
   for (const name of names) {
diff --git a/packages/chat/discord/test/discord.ts b/packages/chat/discord/test/discord.ts
index 099cdc20fa7..df6d193a65b 100644
--- a/packages/chat/discord/test/discord.ts
+++ b/packages/chat/discord/test/discord.ts
@@ -10,13 +10,17 @@ const idOf = (customId: string): string => customId.split(join)[0]
 
 /**
  * A Discord that keeps the messages the adapter posts, with their
- * components, and records every interaction callback. `interactions` is the
- * conformance hook: it builds Discord's `INTERACTION_CREATE` payload from
- * what was posted and sends it through `DiscordChat.interaction`.
+ * components, and records every interaction callback and every edit of an
+ * original response. `interactions` is the conformance hook: it builds
+ * Discord's `INTERACTION_CREATE` payload from what was posted, or a slash
+ * command's, and sends it through `DiscordChat.interaction`. The command
+ * and its modal's submit without a message are built from Discord's docs,
+ * not captured.
  */
 export const makeDiscord = (channelType = 0) => {
   const messages = new Map()
   const callbacks: Array<{ readonly id: string; readonly token: string; readonly payload: any }> = []
+  const originals: Array<{ readonly applicationId: string; readonly token: string; readonly payload: any }> = []
   let next = 1570700000000000000n
   let refuse = 0
   let interactionCount = 0
@@ -73,11 +77,22 @@ export const makeDiscord = (channelType = 0) => {
     createInteractionResponse: (id: string, token: string, options: { payload: any }) => {
       callbacks.push({ id, token, payload: options.payload })
       return Effect.succeed(null)
+    },
+    updateOriginalWebhookMessage: (applicationId: string, token: string, options: { payload: any }) => {
+      // Only a token a type 5 callback answered has an original response to edit.
+      if (!callbacks.some((callback) => callback.token === token && callback.payload.type === 5)) {
+        return Effect.fail(errorResponse(404, { code: 10015, message: "Unknown Webhook" }))
+      }
+      originals.push({ applicationId, token, payload: options.payload })
+      return Effect.succeed({ id: nextId(), content: options.payload.content })
     }
   })
 
-  /** The modal the last click opened, with the message it was opened from. */
-  let opened: { readonly data: any; readonly message: any } | undefined
+  /**
+   * The modal the last click or command opened, with the message it was
+   * opened from, which a command has none of.
+   */
+  let opened: { readonly data: any; readonly channelId: string; readonly message?: any } | undefined
 
   /** The service the hook delivers through, set by `bind`. */
   let service: DiscordChat.DiscordChat["Service"] | undefined
@@ -88,17 +103,17 @@ export const makeDiscord = (channelType = 0) => {
     return callbacks.slice(before).find((callback) => callback.id === payload.id)?.payload
   })
 
-  const base = (message: any) => {
+  const base = (channelId: string, message?: any) => {
     const n = ++interactionCount
     return {
       id: "9" + String(n).padStart(18, "0"),
       application_id: botUserId,
       token: "token-" + n,
       version: 1,
-      channel_id: message.channel_id,
+      channel_id: channelId,
       guild_id: guild,
       member: { user: { id: tim, username: "tim" }, roles: [] },
-      message
+      ...(message === undefined ? {} : { message })
     }
   }
 
@@ -112,7 +127,7 @@ export const makeDiscord = (channelType = 0) => {
       if (component === undefined) return yield* Effect.fail(new NoSuchElement({ messageId, id }))
       const value = component.type === 3 ? options?.option ?? component.options[0].value : undefined
       const answer = yield* deliver({
-        ...base(message),
+        ...base(message.channel_id, message),
         type: 3,
         data: {
           custom_id: component.custom_id,
@@ -120,11 +135,25 @@ export const makeDiscord = (channelType = 0) => {
           ...(value === undefined ? {} : { values: [value] })
         }
       })
-      opened = answer?.type === 9 ? { data: answer.data, message } : undefined
+      opened = answer?.type === 9 ? { data: answer.data, channelId: message.channel_id, message } : undefined
+    }),
+    command: Effect.fnUntraced(function*(thread, id, options) {
+      const text = options?.text ?? ""
+      const answer = yield* deliver({
+        ...base(thread.id),
+        type: 2,
+        data: {
+          id: "1570700000000000999",
+          name: id,
+          type: 1,
+          ...(text === "" ? {} : { options: [{ type: 3, name: "text", value: text }] })
+        }
+      })
+      opened = answer?.type === 9 ? { data: answer.data, channelId: thread.id } : undefined
     }),
     submit: Effect.fnUntraced(function*(values) {
       if (opened === undefined) return
-      const { data, message } = opened
+      const { channelId, data, message } = opened
       const components = data.components.map((component: any) => {
         if (component.type !== 18) return { type: component.type }
         const input = component.component
@@ -137,7 +166,7 @@ export const makeDiscord = (channelType = 0) => {
         }
       })
       yield* deliver({
-        ...base(message),
+        ...base(channelId, message),
         type: 5,
         data: { custom_id: data.custom_id, components }
       })
@@ -154,6 +183,7 @@ export const makeDiscord = (channelType = 0) => {
       })),
     messages,
     callbacks,
+    originals,
     interactions,
     refuseFiles: () =>
       Effect.sync(() => {
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index a28d1d1de26..47ce464a32b 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -1,5 +1,11 @@
+/**
+ * Interactions: the normaliser, the callbacks `DiscordChat.interaction`
+ * answers with, `commandRequests` and a command's `followUp`. The slash
+ * command payloads are built from Discord's docs: none has been captured.
+ */
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { assert, describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
 import type { ChatError } from "effect/chat/ChatError"
 import * as ChatInteraction from "effect/chat/ChatInteraction"
 import { checkInteraction } from "effect/chat/ChatTest"
@@ -8,7 +14,18 @@ import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
 import * as Option from "effect/Option"
 import * as TestClock from "effect/testing/TestClock"
-import { answer, botUserId, discordLayer, type Fake, guild, makeFake, scratch, step, tim } from "./utils.ts"
+import {
+  answer,
+  botUserId,
+  discordLayer,
+  errorResponse,
+  type Fake,
+  guild,
+  makeFake,
+  scratch,
+  step,
+  tim
+} from "./utils.ts"
 
 const message = { id: "1570700000000000001", channel_id: scratch }
 
@@ -29,6 +46,14 @@ const click = (data: Record, extra: Record = {
 const submit = (customId: string, components: ReadonlyArray) =>
   click({ custom_id: customId, components }, { type: 5 })
 
+const slash = (name: string, options?: ReadonlyArray, data: Record = {}) =>
+  omit(
+    click({ id: "1570700000000000900", name, type: 1, ...(options === undefined ? {} : { options }), ...data }, {
+      type: 2
+    }),
+    "message"
+  )
+
 const omit = (raw: Record, key: string) => {
   const { [key]: _, ...rest } = raw
   return rest
@@ -92,7 +117,7 @@ describe("normalizeInteraction", () => {
         metadata: "{\"v\":1}",
         values: { name: "Tim", size: "l", old: "row" }
       })
-      assert.strictEqual(submitted.messageId, message.id)
+      assert.strictEqual((submitted as ChatInteraction.ModalSubmitted).messageId, message.id)
       yield* checkInteraction(submitted, { platform: "discord" })
       assert.isFalse("metadata" in some(submit("form", [])))
     }))
@@ -109,10 +134,43 @@ describe("normalizeInteraction", () => {
       yield* checkInteraction(submitted, { platform: "discord" })
     }))
 
-  it("anything not from an element the adapter built is None", () => {
+  it.effect("a slash command gives its name and its one string option, or the empty string", () =>
+    Effect.gen(function*() {
+      const bare = some(slash("summarize"))
+      assert.deepStrictEqual(
+        bare,
+        ChatInteraction.CommandInvoked.make({
+          id: "summarize",
+          text: "",
+          thread: DiscordChat.thread(scratch),
+          userId: tim,
+          raw: bare.raw
+        })
+      )
+      const withText = some(slash("deploy", [{ type: 3, name: "version", value: "v1 <@1>" }]))
+      assert.strictEqual((withText as ChatInteraction.CommandInvoked).text, "v1 <@1>")
+      yield* checkInteraction(bare, { platform: "discord" })
+      yield* checkInteraction(withText, { platform: "discord" })
+    }))
+
+  it.effect("a submit with no message, from a modal a command opened, has no messageId", () =>
+    Effect.gen(function*() {
+      const submitted = some(omit(submit("form", []), "message"))
+      assert.strictEqual(submitted._tag, "ModalSubmitted")
+      assert.isFalse("messageId" in submitted)
+      assert.deepStrictEqual(submitted.thread, DiscordChat.thread(scratch))
+      yield* checkInteraction(submitted, { platform: "discord" })
+    }))
+
+  it("anything not from an element the adapter built, or a command it can't express, is None", () => {
     for (
       const raw of [
-        click({ id: "1", name: "ping", type: 1 }, { type: 2 }),
+        // A user command, a slash command with an integer option, and one with two options.
+        slash("profile", undefined, { type: 2 }),
+        slash("roll", [{ type: 4, name: "sides", value: 6 }]),
+        slash("deploy", [{ type: 3, name: "a", value: "x" }, { type: 3, name: "b", value: "y" }]),
+        // Autocomplete for a command.
+        { ...slash("deploy", [{ type: 3, name: "version", value: "v", focused: true }]), type: 4 },
         { type: 1, id: "1", token: "t" },
         click({ custom_id: "users", component_type: 5, values: [tim] }),
         omit(click({ custom_id: "go", component_type: 2 }), "message"),
@@ -128,6 +186,7 @@ describe("interaction", () => {
   const recording = (reply: {
     readonly click?: ChatInteraction.ClickReply
     readonly submit?: ChatInteraction.SubmitReply
+    readonly command?: (command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply
     readonly delay?: Duration.Duration
   }) => {
     const received: Array = []
@@ -139,6 +198,11 @@ describe("interaction", () => {
           reply.click ?? ChatInteraction.ack
         ),
       submit: (event) => Effect.as(Effect.sync(() => received.push(event)), reply.submit ?? ChatInteraction.close),
+      command: (event) =>
+        Effect.as(
+          Effect.sync(() => received.push(event)),
+          reply.command === undefined ? ChatInteraction.ack : reply.command(event)
+        ),
       refused: (_, error) => Effect.sync(() => void refused.push(error))
     })
     return { received, refused, handler }
@@ -296,7 +360,149 @@ describe("interaction", () => {
     Effect.gen(function*() {
       const fake = makeFake({})
       const { handler, received } = recording({})
-      yield* deliver(fake, click({ id: "1", name: "ping", type: 1 }, { type: 2 }), handler)
+      yield* deliver(fake, slash("profile", undefined, { type: 2 }), handler)
       assert.deepStrictEqual([received.length, fake.calls.length], [0, 0])
     }))
+
+  it.effect("answers a command: type 4 for respond, 5 for defer, 9 for a modal, private with flag 64", () =>
+    Effect.gen(function*() {
+      const fake = answering()
+      const replies: Array<(command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply> = [
+        () => ChatInteraction.respond({ markdown: "Hi *there*" }),
+        () => ChatInteraction.respond({ markdown: "Hi", visibility: "public" }),
+        (command) => ChatInteraction.defer(command),
+        (command) => ChatInteraction.defer(command, { visibility: "public" }),
+        () => ChatInteraction.modal("form", { title: "t", fields: {} }).open()
+      ]
+      for (const reply of replies) {
+        const { handler, refused } = recording({ command: reply })
+        // withPostOptions does not reach a command's answer.
+        yield* DiscordChat.withPostOptions(deliver(fake, slash("summarize"), handler), {
+          suppressEmbeds: false,
+          notify: { everyone: true }
+        })
+        assert.deepStrictEqual(refused, [])
+      }
+      assert.deepStrictEqual(payloads(fake), [
+        // The message a post sends, embeds off with flag 4.
+        {
+          type: 4,
+          data: {
+            content: "Hi *there*",
+            allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] },
+            flags: 68
+          }
+        },
+        {
+          type: 4,
+          data: { content: "Hi", allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] }, flags: 4 }
+        },
+        { type: 5, data: { flags: 64 } },
+        { type: 5 },
+        { type: 9, data: { custom_id: "form", title: "t", components: [] } }
+      ])
+    }))
+
+  it.effect("sends nothing for a command nobody handles, and refuses a respond a post would refuse", () =>
+    Effect.gen(function*() {
+      const fake = answering()
+      const { handler, received, refused } = recording({})
+      yield* deliver(fake, slash("theirs"), handler)
+      assert.strictEqual(received.length, 1)
+      const tooLong = recording({ command: () => ChatInteraction.respond({ markdown: "x".repeat(2001) }) })
+      yield* deliver(fake, slash("summarize"), tooLong.handler)
+      assert.deepStrictEqual(refused, [])
+      assert.deepStrictEqual(tooLong.refused.map((error) => [error.op, error.reason._tag]), [["respond", "TooLarge"]])
+      assert.deepStrictEqual(payloads(fake), [])
+    }))
+})
+
+describe("commandRequests", () => {
+  it("gives a CHAT_INPUT command per definition, with one STRING option for an argument", () => {
+    const group = ChatInteraction.group(
+      ChatInteraction.command("summarize", { description: "Summarize this thread" }),
+      ChatInteraction.button("go", { label: "Go" }),
+      ChatInteraction.command("deploy", {
+        description: "Deploy a version",
+        argument: { name: "version", description: "The version", required: true }
+      }),
+      ChatInteraction.command("note", {
+        description: "Add a note",
+        argument: { name: "text", description: "The note" }
+      })
+    )
+    assert.deepStrictEqual(DiscordChat.commandRequests(group), [
+      { type: 1, name: "summarize", description: "Summarize this thread" },
+      {
+        type: 1,
+        name: "deploy",
+        description: "Deploy a version",
+        options: [{ type: 3, name: "version", description: "The version", required: true }]
+      },
+      {
+        type: 1,
+        name: "note",
+        description: "Add a note",
+        options: [{ type: 3, name: "text", description: "The note", required: false }]
+      }
+    ])
+  })
+})
+
+describe("followUp", () => {
+  const deferred = (visibility: ChatInteraction.Visibility) =>
+    ChatInteraction.defer(some(slash("summarize")) as ChatInteraction.CommandInvoked, { visibility })
+
+  const followUp = (fake: Fake, defer: ChatInteraction.Defer, markdown = "Done") =>
+    Effect.flatMap(Chat.Chat, (chat) => chat.followUp(defer, { markdown })).pipe(Effect.provide(discordLayer(fake)))
+
+  it.effect("edits the original response with the application id and token, private with flag 64", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ updateOriginalWebhookMessage: () => Effect.succeed({ id: "1" }) })
+      yield* followUp(fake, deferred("ephemeral"))
+      yield* followUp(fake, deferred("public"))
+      assert.deepStrictEqual(
+        fake.called("updateOriginalWebhookMessage").map(([applicationId, token, options]) => [
+          applicationId,
+          token,
+          options.payload
+        ]),
+        [
+          // Flag 4 keeps embeds off, as a post does.
+          [botUserId, "token", {
+            content: "Done",
+            allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] },
+            flags: 68
+          }],
+          [botUserId, "token", {
+            content: "Done",
+            allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] },
+            flags: 4
+          }]
+        ]
+      )
+    }))
+
+  it.effect("is interaction_expired from 15 minutes after the command without a call, or for a spent token", () =>
+    Effect.gen(function*() {
+      const issued = Number((BigInt("1570700000000000900") >> 22n) + 1420070400000n)
+      const spent = makeFake({
+        updateOriginalWebhookMessage: () =>
+          Effect.fail(errorResponse(401, { code: 50027, message: "Invalid Webhook Token" }))
+      })
+      yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) - 1)
+      const refused = yield* Effect.flip(followUp(spent, deferred("public")))
+      const tooLong = yield* Effect.flip(followUp(spent, deferred("public"), "x".repeat(2001)))
+      yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)))
+      const late = yield* Effect.flip(followUp(spent, deferred("public")))
+      assert.deepStrictEqual(
+        [refused, tooLong, late].map((error) => [error.op, error.reason._tag, error.reason.detail]),
+        [
+          ["followUp", "NotFound", "interaction_expired"],
+          ["followUp", "TooLarge", tooLong.reason.detail],
+          ["followUp", "NotFound", "interaction_expired"]
+        ]
+      )
+      assert.strictEqual(spent.called("updateOriginalWebhookMessage").length, 1)
+    }))
 })

From fde906a955377825243983c6aa90cc8e586f35a3 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 21:07:56 +0000
Subject: [PATCH 49/89] chat: recorded slash command fixtures, and docs from
 the EFF-3802 captures

---
 .changeset/chat-discord-commands.md           |    2 +-
 .changeset/chat-slack-commands.md             |    2 +-
 .changeset/effect-chat-commands.md            |    2 +-
 packages/chat/discord/src/DiscordChat.ts      |   13 +-
 packages/chat/discord/src/internal/adapter.ts |    6 +-
 packages/chat/discord/test/commands.test.ts   |  186 +++
 packages/chat/discord/test/discord.ts         |    4 +-
 .../test/fixtures/recorded/commands.json      | 1127 +++++++++++++++++
 .../chat/discord/test/interactions.test.ts    |    3 +-
 packages/chat/slack/src/SlackChat.ts          |   25 +-
 packages/chat/slack/src/internal/adapter.ts   |    5 +-
 packages/chat/slack/test/commands.test.ts     |  197 +++
 .../test/fixtures/recorded/commands.json      |  682 ++++++++++
 packages/chat/slack/test/interactions.test.ts |    7 +-
 packages/chat/slack/test/utils.ts             |    8 +-
 packages/effect/src/chat/Chat.ts              |    1 +
 packages/effect/src/chat/ChatAdapter.ts       |    6 +-
 packages/effect/src/chat/ChatInteraction.ts   |   17 +-
 packages/effect/src/chat/ChatTest.ts          |    3 +-
 19 files changed, 2264 insertions(+), 32 deletions(-)
 create mode 100644 packages/chat/discord/test/commands.test.ts
 create mode 100644 packages/chat/discord/test/fixtures/recorded/commands.json
 create mode 100644 packages/chat/slack/test/commands.test.ts
 create mode 100644 packages/chat/slack/test/fixtures/recorded/commands.json

diff --git a/.changeset/chat-discord-commands.md b/.changeset/chat-discord-commands.md
index 4a5a899a483..eebc9ba52fb 100644
--- a/.changeset/chat-discord-commands.md
+++ b/.changeset/chat-discord-commands.md
@@ -2,4 +2,4 @@
 "@effect/chat-discord": patch
 ---
 
-Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`.
+Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`. A second `followUp` replaces the first answer. After 15 minutes Discord answers 401 with code 50027, which is `NotFound` with detail `interaction_expired`.
diff --git a/.changeset/chat-slack-commands.md b/.changeset/chat-slack-commands.md
index 051077629ec..78816e5c157 100644
--- a/.changeset/chat-slack-commands.md
+++ b/.changeset/chat-slack-commands.md
@@ -2,4 +2,4 @@
 "@effect/chat-slack": patch
 ---
 
-Take slash commands. A command's Request URL is `layerInteractivity`'s path, and `SlackChat.interaction` takes a command's fields, from the form or a `slash_commands` envelope. `normalizeInteraction` now gives `CommandInvoked` for them, where it gave none. `respond` is answered in the response body with `response_type`, `defer` with an empty 200, a modal through the command's `trigger_id`, and a late command with `Late`. `Chat.followUp` posts once to the command's `response_url`, which must be on a Slack host, for 30 minutes. The descriptor lists `commands` and `ephemeral`. A modal a command opened submits without a `messageId`. The app needs the `commands` scope.
+Take slash commands. A command's Request URL is `layerInteractivity`'s path, and `SlackChat.interaction` takes a command's fields, from the form or a `slash_commands` envelope. `normalizeInteraction` now gives `CommandInvoked` for them, where it gave none. `respond` is answered in the response body with `response_type`, `defer` with an empty 200, a modal through the command's `trigger_id`, and a late command with `Late`. `Chat.followUp` posts once to the command's `response_url`, which must be on a Slack host, for 30 minutes. The descriptor lists `commands` and `ephemeral`. A modal a command opened submits without a `messageId`. The app needs the `commands` scope. A spent or expired `response_url` answers 404 `used_url` or `expired_url`, and `followUp` fails `NotFound` with detail `interaction_expired` for both. A mention in a command's answer goes out escaped and notifies nobody.
diff --git a/.changeset/effect-chat-commands.md b/.changeset/effect-chat-commands.md
index 9a14849b0e7..05d73aa9e18 100644
--- a/.changeset/effect-chat-commands.md
+++ b/.changeset/effect-chat-commands.md
@@ -2,7 +2,7 @@
 "effect": patch
 ---
 
-Add slash commands and private replies to `effect/chat`. `ChatInteraction.command` defines a command with at most one text argument, which arrives as `CommandInvoked` and goes to `Handler.command`. A command handler answers with `respond`, `defer` or a modal's `open`, and `respond` and `defer` are private by default. `Chat.followUp` sends the answer a `Defer` promised, within `limits.followUpAge`. `ChatTest` gains `command`, a `submit` and `interact` that take a command, the hook's optional `command` and the `command/*` rules.
+Add slash commands and private replies to `effect/chat`. `ChatInteraction.command` defines a command with at most one text argument, which arrives as `CommandInvoked` and goes to `Handler.command`. A command handler answers with `respond`, `defer` or a modal's `open`, and `respond` and `defer` are private by default. `Chat.followUp` sends the answer a `Defer` promised, within `limits.followUpAge`. `ChatTest` gains `command`, a `submit` and `interact` that take a command, the hook's optional `command` and the `command/*` rules. On a command's private answer, a click's `messageId` names where the click came from and no message `edit`, `delete` or `fetchMessage` can reach. Send one `followUp` per `Defer`: a second posts another message on Slack, replaces the first on Discord and fails in `ChatTest`.
 
 Breaking for code written against the unreleased `effect/chat` APIs:
 
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index 399591746dd..08f35c21c57 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -80,11 +80,16 @@ import { CurrentPostOptions } from "./internal/options.ts"
  *   4 with the message a `post` sends, `defer` type 5 and `OpenModal` type
  *   9, each with the ephemeral flag when private. An `Ack`, which is what a
  *   command nobody handles gets, sends nothing, so a command another library
- *   owns is left to it.
+ *   owns is left to it. `withPostOptions` does not reach a command's
+ *   answer: a mention in it renders and notifies nobody.
+ * - A click on a private answer carries the message, with the ephemeral flag
+ *   (64). Only the interaction's token reaches that message, so its
+ *   `messageId` is not one `Chat.edit`, `delete` or `fetchMessage` can use.
  * - `followUp` edits the deferred command's original response, with the
- *   application id and token from its `raw`. It fails `NotFound` with detail
- *   `interaction_expired` from 15 minutes after the command, read from the
- *   interaction's id, without calling Discord.
+ *   application id and token from its `raw`, so a second call replaces the
+ *   first answer. It fails `NotFound` with detail `interaction_expired`
+ *   from 15 minutes after the command, read from the interaction's id,
+ *   without calling Discord. Past that Discord answers 401 with code 50027.
  * - A modal that can't be built, a reply to a command that fails the checks
  *   of a `post`, or a callback that fails, goes to `Handler.refused`. A
  *   callback that comes back 404 `Unknown interaction` was late: that is
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index 64a68f63296..858e41a9c34 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -84,9 +84,9 @@ const WRONG_CHANNEL_TYPE = 50024
 /** Discord's code for "unknown interaction": a callback after the 3 seconds. */
 const UNKNOWN_INTERACTION = 10062
 /**
- * Discord's codes for an interaction token it no longer takes: "invalid
- * webhook token" and "unknown webhook". Taken from the docs' list, not
- * captured after 15 minutes.
+ * Discord's codes for an interaction token it no longer takes. After 15
+ * minutes it answered 401 with 50027 "Invalid Webhook Token", recorded in
+ * EFF-3802. 10015 "Unknown Webhook" is from the docs' list and was not seen.
  */
 const SPENT_TOKEN = [50027, 10015]
 /** The start of Discord's snowflake clock, in Unix milliseconds. */
diff --git a/packages/chat/discord/test/commands.test.ts b/packages/chat/discord/test/commands.test.ts
new file mode 100644
index 00000000000..b7f501cd0cf
--- /dev/null
+++ b/packages/chat/discord/test/commands.test.ts
@@ -0,0 +1,186 @@
+/**
+ * Slash commands against what Discord sent and what it took, recorded in
+ * #test of guild 840178841540362250 during EFF-3802:
+ * `fixtures/recorded/commands.json`.
+ */
+import * as DiscordChat from "@effect/chat-discord/DiscordChat"
+import { assert, describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Option from "effect/Option"
+import * as TestClock from "effect/testing/TestClock"
+import * as fs from "node:fs"
+import { botUserId, discordLayer, errorResponse, type Fake, makeFake, test, tim } from "./utils.ts"
+
+const recorded = JSON.parse(fs.readFileSync(new URL("./fixtures/recorded/commands.json", import.meta.url), "utf8"))
+
+// The definitions the capture ran, from eff-3802-capture.ts.
+const AckButton = ChatInteraction.button("cap-ack", { label: "Ack" })
+const ModalButton = ChatInteraction.button("cap-open", { label: "Open modal", style: "primary" })
+const Modal = ChatInteraction.modal("cap-modal", {
+  title: "Capture",
+  submitLabel: "Send",
+  fields: { note: ChatInteraction.textInput({ label: "Note (type err for a field error)" }) }
+})
+const actions = [AckButton.of(), ModalButton.of()]
+
+/** The capture's handler, by the command's text. */
+const reply = (command: ChatInteraction.CommandInvoked): ChatInteraction.CommandReply => {
+  switch (command.text) {
+    case "public":
+      return ChatInteraction.respond({
+        markdown: "**Public answer** with _Markdown_ and buttons",
+        actions,
+        visibility: "public"
+      })
+    case "mention":
+      return ChatInteraction.respond({ markdown: "Private answer mentioning <@" + command.userId + ">" })
+    case "modal":
+      return Modal.open()
+    case "defer":
+      return ChatInteraction.defer(command)
+    case "defer-public":
+      return ChatInteraction.defer(command, { visibility: "public" })
+    default:
+      return ChatInteraction.respond({
+        markdown: "**Private answer** with _Markdown_, a list:\n\n- one\n- two\n\nand buttons",
+        actions
+      })
+  }
+}
+
+const handler = ChatInteraction.Handler.of({
+  click: () => Effect.succeed(ChatInteraction.ack),
+  submit: (submit) =>
+    Effect.succeed(
+      submit.values.note === "err"
+        ? ChatInteraction.errors({ note: "That is the error you asked for" })
+        : ChatInteraction.close
+    ),
+  command: (command) => Effect.succeed(reply(command)),
+  refused: (_, error) => Effect.die(error)
+})
+
+const normalize = (payload: unknown) => Option.getOrThrow(DiscordChat.normalizeInteraction(payload))
+
+const deliver = (fake: Fake, payload: unknown) =>
+  Effect.flatMap(DiscordChat.DiscordChat, (discord) => discord.interaction(payload)).pipe(
+    Effect.provideService(ChatInteraction.Handler, handler),
+    Effect.provide(discordLayer(fake))
+  )
+
+const answering = () => makeFake({ createInteractionResponse: () => Effect.succeed(null) })
+
+/** The callbacks sent, as [interaction id, token, body]. */
+const callbacks = (fake: Fake) =>
+  fake.called("createInteractionResponse").map(([id, token, options]) => [id, token, options.payload])
+
+/** When Discord made an interaction, from its snowflake. */
+const issuedAt = (id: string) => Number((BigInt(id) >> 22n) + 1420070400000n)
+
+describe("recorded slash commands", () => {
+  it("normalizes each command the gateway delivered", () => {
+    for (const [what, payload] of Object.entries(recorded.commands)) {
+      const event = normalize(payload)
+      assert.strictEqual(event._tag, "CommandInvoked", what)
+      if (event._tag !== "CommandInvoked") return
+      assert.deepStrictEqual([event.id, event.text, event.userId, event.thread.id], [
+        "chat-capture",
+        payload.data.options?.[0]?.value ?? "",
+        tim,
+        test
+      ])
+    }
+  })
+
+  it.effect("answers each command with the callback Discord took", () =>
+    Effect.gen(function*() {
+      for (const what of ["private", "public", "mention", "modal", "defer", "deferPublic"]) {
+        const fake = answering()
+        const payload = recorded.commands[what]
+        yield* deliver(fake, payload)
+        assert.deepStrictEqual(callbacks(fake), [[payload.id, "", recorded.callbacks[what].payload]], what)
+        assert.strictEqual(recorded.callbacks[what].status, 204)
+      }
+      // Allowed mentions are empty: the mention renders and notifies nobody.
+      assert.deepStrictEqual(recorded.callbacks.mention.payload.data.allowed_mentions.parse, [])
+    }))
+
+  it.effect("takes a click on a private answer, whose message has the ephemeral flag, and acks it", () =>
+    Effect.gen(function*() {
+      const payload = recorded.clicks.privateAnswer
+      const click = normalize(payload)
+      assert.strictEqual(click._tag, "ButtonClicked")
+      if (click._tag !== "ButtonClicked") return
+      // The id names where the click came from, a message only the
+      // interaction's token reaches.
+      assert.deepStrictEqual([click.id, click.messageId, click.thread.id], ["cap-ack", payload.message.id, test])
+      assert.strictEqual(payload.message.flags & 64, 64)
+      const fake = answering()
+      yield* deliver(fake, payload)
+      assert.deepStrictEqual(callbacks(fake), [[
+        payload.id,
+        "",
+        recorded.clicks.privateAnswerCallback.payload
+      ]])
+    }))
+
+  it.effect("gives a submit of a command's modal no messageId, and answers it the way Discord took", () =>
+    Effect.gen(function*() {
+      for (const [what, callback] of [["submitErrors", "errorsCallback"], ["submitClose", "closeCallback"]] as const) {
+        const payload = recorded.commandModal[what]
+        assert.isFalse("message" in payload)
+        const submitted = normalize(payload)
+        assert.strictEqual(submitted._tag, "ModalSubmitted", what)
+        if (submitted._tag !== "ModalSubmitted") return
+        assert.deepStrictEqual([submitted.id, submitted.thread.id, submitted.userId], ["cap-modal", test, tim])
+        assert.isFalse("messageId" in submitted)
+        const fake = answering()
+        yield* deliver(fake, payload)
+        assert.deepStrictEqual(callbacks(fake), [[payload.id, "", recorded.commandModal[callback].payload]])
+      }
+      // Type 6 closed the modal.
+      assert.deepStrictEqual(recorded.commandModal.closeCallback.payload, { type: 6 })
+    }))
+
+  it.effect("follows up with the edit Discord took, and maps its answer after 15 minutes", () =>
+    Effect.gen(function*() {
+      const payload = recorded.commands.defer
+      const deferred = ChatInteraction.defer(normalize(payload) as ChatInteraction.CommandInvoked)
+      const followUp = (fake: Fake) =>
+        Effect.flatMap(
+          Chat.Chat,
+          (chat) => chat.followUp(deferred, { markdown: "**Deferred answer** to defer, with buttons", actions })
+        ).pipe(
+          Effect.provide(discordLayer(fake))
+        )
+      const issued = issuedAt(payload.id)
+      yield* TestClock.setTime(issued + 4_000)
+      const edited = makeFake({ updateOriginalWebhookMessage: () => Effect.succeed(recorded.followUp.response.body) })
+      yield* followUp(edited)
+      assert.deepStrictEqual(
+        edited.called("updateOriginalWebhookMessage").map(([applicationId, token, options]) => [
+          applicationId,
+          token,
+          options.payload
+        ]),
+        [[botUserId, "", recorded.followUp.request]]
+      )
+
+      // What Discord answered at 15.5 minutes, here returned early so the
+      // mapping is reached before the adapter's own refusal.
+      const { body, status } = recorded.expired.edit
+      assert.deepStrictEqual([status, body.code], [401, 50027])
+      const spent = makeFake({ updateOriginalWebhookMessage: () => Effect.fail(errorResponse(status, body)) })
+      const mapped = yield* Effect.flip(followUp(spent))
+      yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) + 30_000)
+      const refused = yield* Effect.flip(followUp(spent))
+      assert.deepStrictEqual([mapped, refused].map((error) => [error.op, error.reason._tag, error.reason.detail]), [
+        ["followUp", "NotFound", "interaction_expired"],
+        ["followUp", "NotFound", "interaction_expired"]
+      ])
+      assert.strictEqual(spent.called("updateOriginalWebhookMessage").length, 1)
+    }))
+})
diff --git a/packages/chat/discord/test/discord.ts b/packages/chat/discord/test/discord.ts
index df6d193a65b..44099bc613b 100644
--- a/packages/chat/discord/test/discord.ts
+++ b/packages/chat/discord/test/discord.ts
@@ -14,8 +14,8 @@ const idOf = (customId: string): string => customId.split(join)[0]
  * original response. `interactions` is the conformance hook: it builds
  * Discord's `INTERACTION_CREATE` payload from what was posted, or a slash
  * command's, and sends it through `DiscordChat.interaction`. The command
- * and its modal's submit without a message are built from Discord's docs,
- * not captured.
+ * and its modal's submit without a message are built with the shapes
+ * recorded in `fixtures/recorded/commands.json`.
  */
 export const makeDiscord = (channelType = 0) => {
   const messages = new Map()
diff --git a/packages/chat/discord/test/fixtures/recorded/commands.json b/packages/chat/discord/test/fixtures/recorded/commands.json
new file mode 100644
index 00000000000..c2da91b0129
--- /dev/null
+++ b/packages/chat/discord/test/fixtures/recorded/commands.json
@@ -0,0 +1,1127 @@
+{
+  "case": "Slash commands on Discord, as the gateway delivered them and as the adapter answered, with the clicks and submits that followed, the follow-up edit and what Discord answers after 15 minutes",
+  "provenance": {
+    "kind": "recorded",
+    "source": "The adapter at 53b4d54024 behind a logging proxy (eff-3802-capture.ts), with the Janitor bot (1564742987727118426) on the gateway and Tim running /chat-capture",
+    "where": "guild 840178841540362250 (Tim's test guild); #test 1570605581192929301. /chat-capture was registered on that guild only and deleted afterwards",
+    "recordedAt": "2026-11-14T19:54Z to 20:18Z, during EFF-3802",
+    "body": "Payloads and callback bodies verbatim, apart from the interaction token, which is replaced with . Network headers are left out",
+    "seenButNotInLog": [
+      "Callback type 6 closed the modal a command opened",
+      "The mention answer rendered <@449108784879763458> as a mention and did not notify",
+      "Seven followUps on one deferral left one message, edited to the seventh",
+      "A late command showed 'The application did not respond'"
+    ]
+  },
+  "commands": {
+    "private": {
+      "version": 1,
+      "type": 2,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571251955899310120",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "type": 1,
+        "name": "chat-capture",
+        "id": "1571251308462084127",
+        "guild_id": "840178841540362250"
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1570720379356581938",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "modal": {
+      "version": 1,
+      "type": 2,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571252100829155488",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "type": 1,
+        "options": [
+          {
+            "value": "modal",
+            "type": 3,
+            "name": "what"
+          }
+        ],
+        "name": "chat-capture",
+        "id": "1571251308462084127",
+        "guild_id": "840178841540362250"
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1570720379356581938",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "mention": {
+      "version": 1,
+      "type": 2,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571252264956469369",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "type": 1,
+        "options": [
+          {
+            "value": "mention",
+            "type": 3,
+            "name": "what"
+          }
+        ],
+        "name": "chat-capture",
+        "id": "1571251308462084127",
+        "guild_id": "840178841540362250"
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1570720379356581938",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "public": {
+      "version": 1,
+      "type": 2,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571252314214236321",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "type": 1,
+        "options": [
+          {
+            "value": "public",
+            "type": 3,
+            "name": "what"
+          }
+        ],
+        "name": "chat-capture",
+        "id": "1571251308462084127",
+        "guild_id": "840178841540362250"
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1570720379356581938",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "defer": {
+      "version": 1,
+      "type": 2,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571252354362249429",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "type": 1,
+        "options": [
+          {
+            "value": "defer",
+            "type": 3,
+            "name": "what"
+          }
+        ],
+        "name": "chat-capture",
+        "id": "1571251308462084127",
+        "guild_id": "840178841540362250"
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1571252315409612851",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "deferPublic": {
+      "version": 1,
+      "type": 2,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571254079961964664",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "type": 1,
+        "options": [
+          {
+            "value": "defer-public",
+            "type": 3,
+            "name": "what"
+          }
+        ],
+        "name": "chat-capture",
+        "id": "1571251308462084127",
+        "guild_id": "840178841540362250"
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1571252315409612851",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    }
+  },
+  "callbacks": {
+    "private": {
+      "status": 204,
+      "payload": {
+        "type": 4,
+        "data": {
+          "content": "**Private answer** with _Markdown_, a list:\n\n- one\n- two\n\nand buttons",
+          "allowed_mentions": {
+            "parse": [],
+            "users": [],
+            "roles": [],
+            "replied_user": false
+          },
+          "flags": 68,
+          "components": [
+            {
+              "type": 1,
+              "components": [
+                {
+                  "type": 2,
+                  "style": 2,
+                  "label": "Ack",
+                  "custom_id": "cap-ack"
+                },
+                {
+                  "type": 2,
+                  "style": 1,
+                  "label": "Open modal",
+                  "custom_id": "cap-open"
+                }
+              ]
+            }
+          ]
+        }
+      }
+    },
+    "modal": {
+      "status": 204,
+      "payload": {
+        "type": 9,
+        "data": {
+          "custom_id": "cap-modal",
+          "title": "Capture",
+          "components": [
+            {
+              "type": 18,
+              "label": "Note (type err for a field error)",
+              "component": {
+                "type": 4,
+                "custom_id": "note",
+                "style": 1,
+                "required": true
+              }
+            }
+          ]
+        }
+      }
+    },
+    "mention": {
+      "status": 204,
+      "payload": {
+        "type": 4,
+        "data": {
+          "content": "Private answer mentioning <@449108784879763458>",
+          "allowed_mentions": {
+            "parse": [],
+            "users": [],
+            "roles": [],
+            "replied_user": false
+          },
+          "flags": 68
+        }
+      }
+    },
+    "public": {
+      "status": 204,
+      "payload": {
+        "type": 4,
+        "data": {
+          "content": "**Public answer** with _Markdown_ and buttons",
+          "allowed_mentions": {
+            "parse": [],
+            "users": [],
+            "roles": [],
+            "replied_user": false
+          },
+          "flags": 4,
+          "components": [
+            {
+              "type": 1,
+              "components": [
+                {
+                  "type": 2,
+                  "style": 2,
+                  "label": "Ack",
+                  "custom_id": "cap-ack"
+                },
+                {
+                  "type": 2,
+                  "style": 1,
+                  "label": "Open modal",
+                  "custom_id": "cap-open"
+                }
+              ]
+            }
+          ]
+        }
+      }
+    },
+    "defer": {
+      "status": 204,
+      "payload": {
+        "type": 5,
+        "data": {
+          "flags": 64
+        }
+      }
+    },
+    "deferPublic": {
+      "status": 204,
+      "payload": {
+        "type": 5
+      }
+    }
+  },
+  "clicks": {
+    "privateAnswer": {
+      "version": 1,
+      "type": 3,
+      "token": "",
+      "message": {
+        "webhook_id": "1564742987727118426",
+        "type": 20,
+        "tts": false,
+        "timestamp": "2026-11-14T19:54:18.950000+00:00",
+        "pinned": false,
+        "mentions": [],
+        "mention_roles": [],
+        "mention_everyone": false,
+        "interaction_metadata": {
+          "user": {
+            "username": "timsmart",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "449108784879763458",
+            "global_name": "Tim Smart",
+            "display_name_styles": null,
+            "discriminator": "0",
+            "collectibles": null,
+            "clan": null,
+            "avatar_decoration_data": null,
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+          },
+          "type": 2,
+          "name": "chat-capture",
+          "id": "1571251955899310120",
+          "command_type": 1,
+          "authorizing_integration_owners": {
+            "0": "840178841540362250"
+          }
+        },
+        "interaction": {
+          "user": {
+            "username": "timsmart",
+            "public_flags": 0,
+            "primary_guild": null,
+            "id": "449108784879763458",
+            "global_name": "Tim Smart",
+            "display_name_styles": null,
+            "discriminator": "0",
+            "collectibles": null,
+            "clan": null,
+            "avatar_decoration_data": null,
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+          },
+          "type": 2,
+          "name": "chat-capture",
+          "id": "1571251955899310120"
+        },
+        "id": "1571251956796752013",
+        "flags": 68,
+        "embeds": [],
+        "edited_timestamp": null,
+        "content": "**Private answer** with _Markdown_, a list:\n\n- one\n- two\n\nand buttons",
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "style": 2,
+                "label": "Ack",
+                "id": 2,
+                "custom_id": "cap-ack"
+              },
+              {
+                "type": 2,
+                "style": 1,
+                "label": "Open modal",
+                "id": 3,
+                "custom_id": "cap-open"
+              }
+            ]
+          }
+        ],
+        "channel_id": "1570605581192929301",
+        "author": {
+          "username": "Janitor",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "1564742987727118426",
+          "global_name": null,
+          "display_name_styles": null,
+          "discriminator": "5426",
+          "collectibles": null,
+          "clan": null,
+          "bot": true,
+          "avatar_decoration_data": null,
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701"
+        },
+        "attachments": [],
+        "application_id": "1564742987727118426"
+      },
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571251977059573781",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "id": 2,
+        "custom_id": "cap-ack",
+        "component_type": 2
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1570720379356581938",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "privateAnswerCallback": {
+      "status": 204,
+      "payload": {
+        "type": 6
+      }
+    }
+  },
+  "commandModal": {
+    "submitErrors": {
+      "version": 1,
+      "type": 5,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571252118004703322",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "custom_id": "cap-modal",
+        "components": [
+          {
+            "type": 18,
+            "id": 1,
+            "component": {
+              "value": "err",
+              "type": 4,
+              "id": 2,
+              "custom_id": "note"
+            }
+          }
+        ]
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1570720379356581938",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "errorsCallback": {
+      "status": 204,
+      "payload": {
+        "type": 4,
+        "data": {
+          "content": "- That is the error you asked for",
+          "allowed_mentions": {
+            "parse": []
+          },
+          "flags": 64
+        }
+      }
+    },
+    "submitClose": {
+      "version": 1,
+      "type": 5,
+      "token": "",
+      "member": {
+        "user": {
+          "username": "timsmart",
+          "public_flags": 0,
+          "primary_guild": null,
+          "id": "449108784879763458",
+          "global_name": "Tim Smart",
+          "display_name_styles": null,
+          "discriminator": "0",
+          "collectibles": null,
+          "clan": null,
+          "avatar_decoration_data": null,
+          "avatar": "2eded1558c297f57913f8b7e4c6b7efc"
+        },
+        "unusual_dm_activity_until": null,
+        "roles": [],
+        "premium_since": null,
+        "permissions": "18014398509481983",
+        "pending": false,
+        "nick": null,
+        "mute": false,
+        "joined_at": "2021-05-07T10:50:45.596000+00:00",
+        "flags": 0,
+        "deaf": false,
+        "communication_disabled_until": null,
+        "banner": null,
+        "avatar": null
+      },
+      "locale": "en-GB",
+      "id": "1571252196744634570",
+      "guild_locale": "en-US",
+      "guild_id": "840178841540362250",
+      "guild": {
+        "locale": "en-US",
+        "id": "840178841540362250",
+        "features": []
+      },
+      "entitlements": [],
+      "entitlement_sku_ids": [],
+      "data": {
+        "custom_id": "cap-modal",
+        "components": [
+          {
+            "type": 18,
+            "id": 1,
+            "component": {
+              "value": "hello",
+              "type": 4,
+              "id": 2,
+              "custom_id": "note"
+            }
+          }
+        ]
+      },
+      "context": 0,
+      "channel_id": "1570605581192929301",
+      "channel": {
+        "type": 0,
+        "topic": null,
+        "rate_limit_per_user": 0,
+        "position": 6,
+        "permissions": "18014398509481983",
+        "parent_id": "840178841540362251",
+        "nsfw": false,
+        "name": "test",
+        "last_message_id": "1570720379356581938",
+        "id": "1570605581192929301",
+        "guild_id": "840178841540362250",
+        "flags": 0
+      },
+      "authorizing_integration_owners": {
+        "0": "840178841540362250"
+      },
+      "attachment_size_limit": 20971520,
+      "application_id": "1564742987727118426",
+      "app_permissions": "18014398509481983"
+    },
+    "closeCallback": {
+      "status": 204,
+      "payload": {
+        "type": 6
+      }
+    }
+  },
+  "followUp": {
+    "request": {
+      "content": "**Deferred answer** to defer, with buttons",
+      "allowed_mentions": {
+        "parse": [],
+        "users": [],
+        "roles": [],
+        "replied_user": false
+      },
+      "flags": 68,
+      "components": [
+        {
+          "type": 1,
+          "components": [
+            {
+              "type": 2,
+              "style": 2,
+              "label": "Ack",
+              "custom_id": "cap-ack"
+            },
+            {
+              "type": 2,
+              "style": 1,
+              "label": "Open modal",
+              "custom_id": "cap-open"
+            }
+          ]
+        }
+      ]
+    },
+    "response": {
+      "status": 200,
+      "body": {
+        "type": 20,
+        "content": "**Deferred answer** to defer, with buttons",
+        "mentions": [],
+        "mention_roles": [],
+        "attachments": [],
+        "embeds": [],
+        "timestamp": "2026-11-14T19:55:53.917000+00:00",
+        "edited_timestamp": null,
+        "flags": 68,
+        "components": [
+          {
+            "type": 1,
+            "id": 1,
+            "components": [
+              {
+                "type": 2,
+                "id": 2,
+                "custom_id": "cap-ack",
+                "style": 2,
+                "label": "Ack"
+              },
+              {
+                "type": 2,
+                "id": 3,
+                "custom_id": "cap-open",
+                "style": 1,
+                "label": "Open modal"
+              }
+            ]
+          }
+        ],
+        "id": "1571252355117088918",
+        "channel_id": "1570605581192929301",
+        "author": {
+          "id": "1564742987727118426",
+          "username": "Janitor",
+          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
+          "discriminator": "5426",
+          "public_flags": 0,
+          "flags": 0,
+          "bot": true,
+          "banner": null,
+          "accent_color": null,
+          "global_name": null,
+          "avatar_decoration_data": null,
+          "collectibles": null,
+          "display_name_styles": null,
+          "banner_color": null,
+          "clan": null,
+          "primary_guild": null
+        },
+        "pinned": false,
+        "mention_everyone": false,
+        "tts": false,
+        "application_id": "1564742987727118426",
+        "interaction": {
+          "id": "1571252354362249429",
+          "type": 2,
+          "name": "chat-capture",
+          "user": {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          }
+        },
+        "webhook_id": "1564742987727118426",
+        "interaction_metadata": {
+          "id": "1571252354362249429",
+          "type": 2,
+          "user": {
+            "id": "449108784879763458",
+            "username": "timsmart",
+            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
+            "discriminator": "0",
+            "public_flags": 0,
+            "flags": 0,
+            "banner": null,
+            "accent_color": null,
+            "global_name": "Tim Smart",
+            "avatar_decoration_data": null,
+            "collectibles": null,
+            "display_name_styles": null,
+            "banner_color": null,
+            "clan": null,
+            "primary_guild": null
+          },
+          "authorizing_integration_owners": {
+            "0": "840178841540362250"
+          },
+          "name": "chat-capture",
+          "command_type": 1
+        }
+      }
+    }
+  },
+  "expired": {
+    "note": "15.5 minutes after the command, sent by the capture script itself with the interaction's token, before the adapter's followUp, which refused without a request. The same answer came three times, for an edit of @original and for a new follow-up",
+    "edit": {
+      "method": "PATCH",
+      "path": "/webhooks/1564742987727118426//messages/@original",
+      "status": 401,
+      "body": {
+        "message": "Invalid Webhook Token",
+        "code": 50027
+      }
+    },
+    "followUp": {
+      "method": "POST",
+      "path": "/webhooks/1564742987727118426/",
+      "status": 401,
+      "body": {
+        "message": "Invalid Webhook Token",
+        "code": 50027
+      }
+    }
+  }
+}
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index 47ce464a32b..a22fd0c24fa 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -1,7 +1,8 @@
 /**
  * Interactions: the normaliser, the callbacks `DiscordChat.interaction`
  * answers with, `commandRequests` and a command's `followUp`. The slash
- * command payloads are built from Discord's docs: none has been captured.
+ * command payloads here are built from Discord's docs. The recorded ones are
+ * in `commands.test.ts`.
  */
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { assert, describe, it } from "@effect/vitest"
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index e0477772e16..cc668e9ddb8 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -25,8 +25,8 @@
  *   and the manifest's description and usage hint are what Slack shows.
  *   With Socket Mode on, commands come as `slash_commands` envelopes: pass
  *   the envelope's `payload` to `SlackChat.interaction` in the same way.
- * - A command can't be run inside a thread, so a command that acts on a
- *   thread has to be told which one. Command names are shared by every app
+ * - A command can't be run inside a thread: Slack doesn't offer it there.
+ *   A command that acts on a thread has to be told which one. Command names are shared by every app
  *   in a workspace. "Escape channels, users, and links" is off by default;
  *   with it on, `text` carries `<@U…|name>` and `<#C…|name>` tokens.
  * - Slack's stop button also needs the app declared as an agent with
@@ -119,20 +119,33 @@ export interface SlackUser {
  *   the Request URL, or the `payload` of the envelope ack on Socket Mode.
  *   For a command answered with `respond` that body is the message, with
  *   `response_type` `ephemeral` or `in_channel`, after the checks of a
- *   `post`; one that fails them goes to `Handler.refused`.
+ *   `post`; one that fails them goes to `Handler.refused`. A command's
+ *   answer mentions nobody: `withPostOptions` does not reach it, so
+ *   `<@U…>` goes out escaped and shows as text. There is no way to allow a
+ *   mention in it.
  *   `undefined` is an empty answer: an ack, a close, a late click, a
  *   deferred command, a command that opened a modal, a command nobody
  *   handles, or a payload that is not from an element this adapter built.
  * - `Late` is a submit or a command whose handler ran past the deadline
  *   and was interrupted. It is not an answer, since an empty one would close
  *   the modal, or tell the user the command worked: `layerInteractivity`
- *   answers 503 for it, and a caller on Socket Mode sends no ack. `Late` is
+ *   answers 503 for it, and a caller on Socket Mode sends no ack. For a
+ *   command, Slack's desktop client then shows its own private failure
+ *   notice and keeps the text; its iOS client shows nothing. `Late` is
  *   itself a JSON value, so test for it with `Schema.is(ChatInteraction.Late)`
  *   before treating the result as a body.
  * - `Chat.followUp` on a deferred command posts once to the command's
  *   `response_url`, which must be on a Slack host, through the layer's
- *   `HttpClient`. It is a write and is not retried. Slack takes it for 30
- *   minutes.
+ *   `HttpClient`. It is a write and is not retried. Slack takes five posts
+ *   to one `response_url` within 30 minutes, each a new message. A spent
+ *   or expired one answers 404 `used_url` or `expired_url`, which is
+ *   `NotFound` with detail `interaction_expired`.
+ * - A click on a private answer has no `message`. Its `messageId` is the
+ *   answer's `container.message_ts`, which no Web API method reaches:
+ *   `chat.update` on it answers `message_not_found`. `raw` has
+ *   `container.is_ephemeral`. A public answer reads back as a
+ *   `bot_message` whose `bot_id` is not the app's own, so it is not
+ *   `isSelf`.
  * - `interaction` checks no signature and no app id: that is the
  *   transport's job. It needs `ChatInteraction.Handler` where it is
  *   called, so the layer does not need it.
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index f797cc9a7cf..799634564b1 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -121,7 +121,10 @@ const pageSize = 200
 const isSlackHost = (host: string): boolean =>
   host === "slack.com" || host.endsWith(".slack.com") || host === "slack-gov.com" || host.endsWith(".slack-gov.com")
 
-/** What Slack is taken to answer for a `response_url` that is spent: assumed, not captured. */
+/**
+ * What a spent `response_url` answers, as plain text with a 404: `used_url`
+ * after five posts, `expired_url` after 30 minutes. Recorded in EFF-3802.
+ */
 const spentResponseUrl = new Set(["expired_url", "used_url"])
 
 /** The `response_type` of a command's answer. */
diff --git a/packages/chat/slack/test/commands.test.ts b/packages/chat/slack/test/commands.test.ts
new file mode 100644
index 00000000000..426e4da0d1e
--- /dev/null
+++ b/packages/chat/slack/test/commands.test.ts
@@ -0,0 +1,197 @@
+/**
+ * Slash commands against what Slack sent and what it took, recorded on
+ * janitor2 in test-janitor during EFF-3802: `fixtures/recorded/commands.json`.
+ * Slack's signature on these requests was not verified, see the fixture's
+ * provenance.
+ */
+import * as SlackChat from "@effect/chat-slack/SlackChat"
+import { assert, describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import { authTest, fixture, makeFake, slackLayer, team } from "./utils.ts"
+
+const recorded = fixture("commands")
+const channel = "C0CJMJ5UMUY"
+const tim = "U080YLYB277"
+
+// The definitions the capture ran, from eff-3802-capture.ts.
+const AckButton = ChatInteraction.button("cap-ack", { label: "Ack" })
+const ModalButton = ChatInteraction.button("cap-open", { label: "Open modal", style: "primary" })
+const Modal = ChatInteraction.modal("cap-modal", {
+  title: "Capture",
+  submitLabel: "Send",
+  fields: { note: ChatInteraction.textInput({ label: "Note (type err for a field error)" }) }
+})
+const actions = [AckButton.of(), ModalButton.of()]
+
+/** The capture's handler, by the command's text. */
+const reply = (command: ChatInteraction.CommandInvoked): ChatInteraction.CommandReply => {
+  switch (command.text) {
+    case "public":
+      return ChatInteraction.respond({
+        markdown: "**Public answer** with _Markdown_ and buttons",
+        actions,
+        visibility: "public"
+      })
+    case "mention":
+      return ChatInteraction.respond({ markdown: "Private answer mentioning <@" + command.userId + ">" })
+    case "modal":
+      return Modal.open()
+    case "defer":
+      return ChatInteraction.defer(command)
+    default:
+      return ChatInteraction.respond({
+        markdown: "**Private answer** with _Markdown_, a list:\n\n- one\n- two\n\nand buttons",
+        actions
+      })
+  }
+}
+
+const handler = Layer.succeed(ChatInteraction.Handler, {
+  click: () => Effect.succeed(ChatInteraction.ack),
+  submit: (submit) =>
+    Effect.succeed(
+      submit.values.note === "err"
+        ? ChatInteraction.errors({ note: "That is the error you asked for" })
+        : ChatInteraction.close
+    ),
+  command: (command) => Effect.succeed(reply(command)),
+  refused: (_, error) => Effect.die(error)
+})
+
+const normalize = (payload: unknown) => Option.getOrThrow(SlackChat.normalizeInteraction(payload, { teamId: team }))
+
+const interact = (fake: ReturnType, payload: unknown) =>
+  Effect.flatMap(SlackChat.SlackChat, (slack) => slack.interaction(payload, { deadline: Duration.seconds(1) })).pipe(
+    Effect.provide(handler),
+    Effect.provide(slackLayer(fake))
+  )
+
+describe("recorded slash commands", () => {
+  it("normalizes each command form Slack sent", () => {
+    for (const [what, form] of Object.entries>(recorded.commands)) {
+      const event = normalize(form)
+      assert.strictEqual(event._tag, "CommandInvoked", what)
+      if (event._tag !== "CommandInvoked") return
+      assert.deepStrictEqual([event.id, event.text, event.userId, event.thread.id], [
+        "chat-capture",
+        form.text,
+        tim,
+        `${team}/${channel}`
+      ])
+      assert.isFalse("token" in (event.raw as object))
+      assert.strictEqual((event.raw as any).response_url, form.response_url)
+    }
+  })
+
+  it.live("answers each command with the body Slack rendered", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest })
+      for (const what of ["private", "public", "mention", "defer"]) {
+        const answer = yield* interact(fake, recorded.commands[what])
+        assert.deepStrictEqual(answer, recorded.answers[what] ?? undefined, what)
+      }
+      // A mention is escaped, so a command's answer mentions nobody on Slack.
+      assert.include(recorded.answers.mention.text, "<@U080YLYB277>")
+    }))
+
+  it.live("opens a command's modal with the view Slack opened, which packs no message", () =>
+    Effect.gen(function*() {
+      const fake = makeFake({ "auth.test": authTest, "views.open": { ok: true, view: { id: "V0CHM1EJ691" } } })
+      assert.isUndefined(yield* interact(fake, recorded.commands.modal))
+      const [call] = fake.called("views.open")
+      assert.strictEqual(call.params.trigger_id, recorded.commandModal.viewsOpen.trigger_id)
+      assert.deepStrictEqual(JSON.parse(call.params.view), recorded.commandModal.viewsOpen.view)
+    }))
+
+  it.live("gives that modal's submit no messageId, and answers it the way Slack took", () =>
+    Effect.gen(function*() {
+      const submitted = normalize(recorded.commandModal.submitErrors)
+      assert.strictEqual(submitted._tag, "ModalSubmitted")
+      if (submitted._tag !== "ModalSubmitted") return
+      assert.deepStrictEqual([submitted.id, submitted.thread.id, submitted.userId, submitted.values], [
+        "cap-modal",
+        `${team}/${channel}`,
+        tim,
+        { note: "err" }
+      ])
+      assert.isFalse("messageId" in submitted)
+      const fake = makeFake({ "auth.test": authTest })
+      assert.deepStrictEqual(
+        yield* interact(fake, recorded.commandModal.submitErrors),
+        recorded.commandModal.errorsAnswer
+      )
+      assert.isUndefined(yield* interact(fake, recorded.commandModal.submitClose))
+      assert.isNull(recorded.commandModal.closeAnswer)
+    }))
+
+  it("takes a click on a private answer, which has no message, from its container", () => {
+    for (const what of ["privateAnswer", "privateFollowUp"]) {
+      const payload = recorded.clicks[what]
+      assert.isFalse("message" in payload)
+      const click = normalize(payload)
+      assert.strictEqual(click._tag, "ButtonClicked", what)
+      if (click._tag !== "ButtonClicked") return
+      // The id names where the click came from. chat.update on it answered
+      // message_not_found: a private answer is not a message Chat can reach.
+      assert.deepStrictEqual([click.id, click.messageId, click.thread.id], [
+        "cap-ack",
+        payload.container.message_ts,
+        `${team}/${channel}`
+      ])
+      assert.isTrue((click.raw as any).container.is_ephemeral)
+    }
+    const publicClick = normalize(recorded.clicks.publicAnswer)
+    assert.strictEqual(
+      (publicClick as ChatInteraction.ButtonClicked).messageId,
+      recorded.clicks.publicAnswer.message.ts
+    )
+    assert.isFalse((publicClick.raw as any).container.is_ephemeral)
+  })
+
+  it.effect("follows up with the body Slack rendered, and maps a spent and an expired response_url", () =>
+    Effect.gen(function*() {
+      const command = normalize(recorded.commands.defer) as ChatInteraction.CommandInvoked
+      const deferred = ChatInteraction.defer(command)
+      const followUp = (answer: { readonly status: number; readonly contentType: string; readonly body: string }) => {
+        const fake = makeFake({
+          "auth.test": authTest,
+          "response_url": { status: answer.status, headers: { "content-type": answer.contentType }, body: answer.body }
+        })
+        const sent = Effect.flatMap(
+          Chat.Chat,
+          (chat) => chat.followUp(deferred, { markdown: "**Deferred answer** to defer, with buttons", actions })
+        ).pipe(
+          Effect.provide(slackLayer(fake))
+        )
+        return { fake, sent }
+      }
+
+      const ok = followUp(recorded.responseUrl.followUp.response)
+      yield* ok.sent
+      const [{ params: { url, ...body } }] = ok.fake.called("response_url")
+      assert.strictEqual(url, new URL((command.raw as any).response_url).href)
+      assert.deepStrictEqual(body, recorded.responseUrl.followUp.request)
+
+      const answers = [recorded.responseUrl.spent.response, ...recorded.responseUrl.expired.responses]
+      for (const answer of answers) {
+        const error = yield* Effect.flip(followUp(answer).sent)
+        assert.deepStrictEqual([error.op, error.reason._tag, error.reason.detail, (error.reason as any).cause], [
+          "followUp",
+          "NotFound",
+          "interaction_expired",
+          answer.body
+        ])
+      }
+      assert.deepStrictEqual(answers.map((answer) => [answer.status, answer.body]), [
+        [404, "used_url"],
+        [404, "expired_url"],
+        [404, "expired_url"],
+        [404, "expired_url"]
+      ])
+    }))
+})
diff --git a/packages/chat/slack/test/fixtures/recorded/commands.json b/packages/chat/slack/test/fixtures/recorded/commands.json
new file mode 100644
index 00000000000..4e4115081a6
--- /dev/null
+++ b/packages/chat/slack/test/fixtures/recorded/commands.json
@@ -0,0 +1,682 @@
+{
+  "case": "Slash commands on Slack, as Slack sent them to the Request URL and as the adapter answered, with the clicks and submits that followed and what each response_url answered",
+  "provenance": {
+    "kind": "recorded",
+    "source": "The adapter at 53b4d54024 behind a logging proxy (eff-3802-capture.ts), with Tim running /chat-capture on janitor2 (A0CCHBHDK7X)",
+    "where": "Private channel test-janitor (C0CJMJ5UMUY) in T05479Z6JBW, over the Request URL. Not over Socket Mode",
+    "recordedAt": "2026-11-14T20:07Z to 20:46Z, during EFF-3802",
+    "body": "Form fields and payloads verbatim, apart from the verification token, the response_url path and trigger_id, which are replaced with . Network headers are left out. Each answer is the adapter's response body verbatim",
+    "signature": "Not verified against Slack's secret: the proxy re-signed each request with a throwaway key, so the adapter's verifier ran on the proxy's signature",
+    "seenButNotInLog": [
+      "Every answer here rendered on desktop: a markdown block and an actions block, privately and publicly, in the response body and through response_url",
+      "The mention answer showed <@U080YLYB277> as literal text, so it mentioned nobody",
+      "chat.update on the ts of two private answers answered message_not_found, and conversations.history did not list them",
+      "A late command (503 at 2,505 ms) showed Slackbot's private failure notice on desktop and nothing on iOS",
+      "The command is not offered inside a thread"
+    ]
+  },
+  "commands": {
+    "private": {
+      "token": "",
+      "team_id": "T05479Z6JBW",
+      "team_domain": "effectfulworkspace",
+      "channel_id": "C0CJMJ5UMUY",
+      "channel_name": "test-janitor",
+      "user_id": "U080YLYB277",
+      "user_name": "tim.smart",
+      "command": "/chat-capture",
+      "text": "",
+      "api_app_id": "A0CCHBHDK7X",
+      "is_enterprise_install": "false",
+      "response_url": "https://hooks.slack.com/commands/T05479Z6JBW/",
+      "trigger_id": ""
+    },
+    "modal": {
+      "token": "",
+      "team_id": "T05479Z6JBW",
+      "team_domain": "effectfulworkspace",
+      "channel_id": "C0CJMJ5UMUY",
+      "channel_name": "test-janitor",
+      "user_id": "U080YLYB277",
+      "user_name": "tim.smart",
+      "command": "/chat-capture",
+      "text": "modal",
+      "api_app_id": "A0CCHBHDK7X",
+      "is_enterprise_install": "false",
+      "response_url": "https://hooks.slack.com/commands/T05479Z6JBW/",
+      "trigger_id": ""
+    },
+    "mention": {
+      "token": "",
+      "team_id": "T05479Z6JBW",
+      "team_domain": "effectfulworkspace",
+      "channel_id": "C0CJMJ5UMUY",
+      "channel_name": "test-janitor",
+      "user_id": "U080YLYB277",
+      "user_name": "tim.smart",
+      "command": "/chat-capture",
+      "text": "mention",
+      "api_app_id": "A0CCHBHDK7X",
+      "is_enterprise_install": "false",
+      "response_url": "https://hooks.slack.com/commands/T05479Z6JBW/",
+      "trigger_id": ""
+    },
+    "public": {
+      "token": "",
+      "team_id": "T05479Z6JBW",
+      "team_domain": "effectfulworkspace",
+      "channel_id": "C0CJMJ5UMUY",
+      "channel_name": "test-janitor",
+      "user_id": "U080YLYB277",
+      "user_name": "tim.smart",
+      "command": "/chat-capture",
+      "text": "public",
+      "api_app_id": "A0CCHBHDK7X",
+      "is_enterprise_install": "false",
+      "response_url": "https://hooks.slack.com/commands/T05479Z6JBW/",
+      "trigger_id": ""
+    },
+    "defer": {
+      "token": "",
+      "team_id": "T05479Z6JBW",
+      "team_domain": "effectfulworkspace",
+      "channel_id": "C0CJMJ5UMUY",
+      "channel_name": "test-janitor",
+      "user_id": "U080YLYB277",
+      "user_name": "tim.smart",
+      "command": "/chat-capture",
+      "text": "defer",
+      "api_app_id": "A0CCHBHDK7X",
+      "is_enterprise_install": "false",
+      "response_url": "https://hooks.slack.com/commands/T05479Z6JBW/",
+      "trigger_id": ""
+    },
+    "spent": {
+      "token": "",
+      "team_id": "T05479Z6JBW",
+      "team_domain": "effectfulworkspace",
+      "channel_id": "C0CJMJ5UMUY",
+      "channel_name": "test-janitor",
+      "user_id": "U080YLYB277",
+      "user_name": "tim.smart",
+      "command": "/chat-capture",
+      "text": "spent",
+      "api_app_id": "A0CCHBHDK7X",
+      "is_enterprise_install": "false",
+      "response_url": "https://hooks.slack.com/commands/T05479Z6JBW/",
+      "trigger_id": ""
+    }
+  },
+  "answers": {
+    "private": {
+      "response_type": "ephemeral",
+      "blocks": [
+        {
+          "type": "markdown",
+          "text": "**Private answer** with _Markdown_, a list:\n\n- one\n- two\n\nand buttons"
+        },
+        {
+          "type": "actions",
+          "block_id": "chat1",
+          "elements": [
+            {
+              "type": "button",
+              "action_id": "cap-ack",
+              "text": {
+                "type": "plain_text",
+                "text": "Ack"
+              }
+            },
+            {
+              "type": "button",
+              "action_id": "cap-open",
+              "text": {
+                "type": "plain_text",
+                "text": "Open modal"
+              },
+              "style": "primary"
+            }
+          ]
+        }
+      ],
+      "text": "**Private answer** with _Markdown_, a list:\n\n- one\n- two\n\nand buttons",
+      "unfurl_links": false,
+      "unfurl_media": false
+    },
+    "mention": {
+      "response_type": "ephemeral",
+      "blocks": [
+        {
+          "type": "markdown",
+          "text": "Private answer mentioning <@U080YLYB277>"
+        }
+      ],
+      "text": "Private answer mentioning <@U080YLYB277>",
+      "unfurl_links": false,
+      "unfurl_media": false
+    },
+    "public": {
+      "response_type": "in_channel",
+      "blocks": [
+        {
+          "type": "markdown",
+          "text": "**Public answer** with _Markdown_ and buttons"
+        },
+        {
+          "type": "actions",
+          "block_id": "chat1",
+          "elements": [
+            {
+              "type": "button",
+              "action_id": "cap-ack",
+              "text": {
+                "type": "plain_text",
+                "text": "Ack"
+              }
+            },
+            {
+              "type": "button",
+              "action_id": "cap-open",
+              "text": {
+                "type": "plain_text",
+                "text": "Open modal"
+              },
+              "style": "primary"
+            }
+          ]
+        }
+      ],
+      "text": "**Public answer** with _Markdown_ and buttons",
+      "unfurl_links": false,
+      "unfurl_media": false
+    },
+    "defer": null
+  },
+  "clicks": {
+    "privateAnswer": {
+      "type": "block_actions",
+      "user": {
+        "id": "U080YLYB277",
+        "username": "tim.smart",
+        "name": "tim.smart",
+        "team_id": "T05479Z6JBW"
+      },
+      "api_app_id": "A0CCHBHDK7X",
+      "token": "",
+      "container": {
+        "type": "message",
+        "message_ts": "1794686832.000300",
+        "channel_id": "C0CJMJ5UMUY",
+        "is_ephemeral": true
+      },
+      "trigger_id": "",
+      "team": {
+        "id": "T05479Z6JBW",
+        "domain": "effectfulworkspace"
+      },
+      "enterprise": null,
+      "is_enterprise_install": false,
+      "channel": {
+        "id": "C0CJMJ5UMUY",
+        "name": "privategroup"
+      },
+      "state": {
+        "values": {}
+      },
+      "response_url": "https://hooks.slack.com/actions/T05479Z6JBW/",
+      "actions": [
+        {
+          "type": "button",
+          "block_id": "chat1",
+          "action_id": "cap-ack",
+          "text": {
+            "type": "plain_text",
+            "text": "Ack",
+            "emoji": true
+          },
+          "action_ts": "1794686835.443730"
+        }
+      ]
+    },
+    "publicAnswer": {
+      "type": "block_actions",
+      "user": {
+        "id": "U080YLYB277",
+        "username": "tim.smart",
+        "name": "tim.smart",
+        "team_id": "T05479Z6JBW"
+      },
+      "api_app_id": "A0CCHBHDK7X",
+      "token": "",
+      "container": {
+        "type": "message",
+        "message_ts": "1794686949.699459",
+        "channel_id": "C0CJMJ5UMUY",
+        "is_ephemeral": false
+      },
+      "trigger_id": "",
+      "team": {
+        "id": "T05479Z6JBW",
+        "domain": "effectfulworkspace"
+      },
+      "enterprise": null,
+      "is_enterprise_install": false,
+      "channel": {
+        "id": "C0CJMJ5UMUY",
+        "name": "privategroup"
+      },
+      "message": {
+        "subtype": "bot_message",
+        "text": "**Public answer** with _Markdown_ and buttons",
+        "type": "message",
+        "ts": "1794686949.699459",
+        "bot_id": "B0CHV4Y8LLR",
+        "blocks": [
+          {
+            "type": "rich_text",
+            "block_id": "D5Nptu",
+            "elements": [
+              {
+                "type": "rich_text_section",
+                "elements": [
+                  {
+                    "type": "text",
+                    "text": "Public answer",
+                    "style": {
+                      "bold": true
+                    }
+                  },
+                  {
+                    "type": "text",
+                    "text": " with "
+                  },
+                  {
+                    "type": "text",
+                    "text": "Markdown",
+                    "style": {
+                      "italic": true
+                    }
+                  },
+                  {
+                    "type": "text",
+                    "text": " and buttons"
+                  }
+                ]
+              }
+            ]
+          },
+          {
+            "type": "actions",
+            "block_id": "chat1",
+            "elements": [
+              {
+                "type": "button",
+                "action_id": "cap-ack",
+                "text": {
+                  "type": "plain_text",
+                  "text": "Ack",
+                  "emoji": true
+                }
+              },
+              {
+                "type": "button",
+                "action_id": "cap-open",
+                "text": {
+                  "type": "plain_text",
+                  "text": "Open modal",
+                  "emoji": true
+                },
+                "style": "primary"
+              }
+            ]
+          }
+        ]
+      },
+      "state": {
+        "values": {}
+      },
+      "response_url": "https://hooks.slack.com/actions/T05479Z6JBW/",
+      "actions": [
+        {
+          "type": "button",
+          "block_id": "chat1",
+          "action_id": "cap-ack",
+          "text": {
+            "type": "plain_text",
+            "text": "Ack",
+            "emoji": true
+          },
+          "action_ts": "1794686972.679850"
+        }
+      ]
+    },
+    "privateFollowUp": {
+      "type": "block_actions",
+      "user": {
+        "id": "U080YLYB277",
+        "username": "tim.smart",
+        "name": "tim.smart",
+        "team_id": "T05479Z6JBW"
+      },
+      "api_app_id": "A0CCHBHDK7X",
+      "token": "",
+      "container": {
+        "type": "message",
+        "message_ts": "1794687008.000500",
+        "channel_id": "C0CJMJ5UMUY",
+        "is_ephemeral": true
+      },
+      "trigger_id": "",
+      "team": {
+        "id": "T05479Z6JBW",
+        "domain": "effectfulworkspace"
+      },
+      "enterprise": null,
+      "is_enterprise_install": false,
+      "channel": {
+        "id": "C0CJMJ5UMUY",
+        "name": "privategroup"
+      },
+      "state": {
+        "values": {}
+      },
+      "response_url": "https://hooks.slack.com/actions/T05479Z6JBW/",
+      "actions": [
+        {
+          "type": "button",
+          "block_id": "chat1",
+          "action_id": "cap-ack",
+          "text": {
+            "type": "plain_text",
+            "text": "Ack",
+            "emoji": true
+          },
+          "action_ts": "1794687011.299505"
+        }
+      ]
+    }
+  },
+  "commandModal": {
+    "viewsOpen": {
+      "trigger_id": "",
+      "view": {
+        "type": "modal",
+        "callback_id": "cap-modal",
+        "title": {
+          "type": "plain_text",
+          "text": "Capture"
+        },
+        "submit": {
+          "type": "plain_text",
+          "text": "Send"
+        },
+        "private_metadata": "chat1␟C0CJMJ5UMUY␟␟",
+        "blocks": [
+          {
+            "type": "input",
+            "block_id": "note",
+            "label": {
+              "type": "plain_text",
+              "text": "Note (type err for a field error)"
+            },
+            "optional": false,
+            "element": {
+              "type": "plain_text_input",
+              "action_id": "note",
+              "multiline": false
+            }
+          }
+        ]
+      }
+    },
+    "submitErrors": {
+      "type": "view_submission",
+      "team": {
+        "id": "T05479Z6JBW",
+        "domain": "effectfulworkspace"
+      },
+      "user": {
+        "id": "U080YLYB277",
+        "username": "tim.smart",
+        "name": "tim.smart",
+        "team_id": "T05479Z6JBW"
+      },
+      "api_app_id": "A0CCHBHDK7X",
+      "token": "",
+      "trigger_id": "",
+      "view": {
+        "id": "V0CHM1EJ691",
+        "team_id": "T05479Z6JBW",
+        "type": "modal",
+        "blocks": [
+          {
+            "type": "input",
+            "block_id": "note",
+            "label": {
+              "type": "plain_text",
+              "text": "Note (type err for a field error)",
+              "emoji": true
+            },
+            "optional": false,
+            "dispatch_action": false,
+            "element": {
+              "type": "plain_text_input",
+              "action_id": "note",
+              "multiline": false,
+              "dispatch_action_config": {
+                "trigger_actions_on": [
+                  "on_enter_pressed"
+                ]
+              }
+            }
+          }
+        ],
+        "private_metadata": "chat1␟C0CJMJ5UMUY␟␟",
+        "callback_id": "cap-modal",
+        "state": {
+          "values": {
+            "note": {
+              "note": {
+                "type": "plain_text_input",
+                "value": "err"
+              }
+            }
+          }
+        },
+        "hash": "1794686859.YVYq8DJX",
+        "title": {
+          "type": "plain_text",
+          "text": "Capture",
+          "emoji": true
+        },
+        "clear_on_close": false,
+        "notify_on_close": false,
+        "close": null,
+        "submit": {
+          "type": "plain_text",
+          "text": "Send",
+          "emoji": true
+        },
+        "previous_view_id": null,
+        "root_view_id": "V0CHM1EJ691",
+        "app_id": "A0CCHBHDK7X",
+        "external_id": "",
+        "app_installed_team_id": "T05479Z6JBW",
+        "bot_id": "B0CCQH77VA5"
+      },
+      "response_urls": [],
+      "is_enterprise_install": false,
+      "enterprise": null
+    },
+    "errorsAnswer": {
+      "response_action": "errors",
+      "errors": {
+        "note": "That is the error you asked for"
+      }
+    },
+    "submitClose": {
+      "type": "view_submission",
+      "team": {
+        "id": "T05479Z6JBW",
+        "domain": "effectfulworkspace"
+      },
+      "user": {
+        "id": "U080YLYB277",
+        "username": "tim.smart",
+        "name": "tim.smart",
+        "team_id": "T05479Z6JBW"
+      },
+      "api_app_id": "A0CCHBHDK7X",
+      "token": "",
+      "trigger_id": "",
+      "view": {
+        "id": "V0CHM1EJ691",
+        "team_id": "T05479Z6JBW",
+        "type": "modal",
+        "blocks": [
+          {
+            "type": "input",
+            "block_id": "note",
+            "label": {
+              "type": "plain_text",
+              "text": "Note (type err for a field error)",
+              "emoji": true
+            },
+            "optional": false,
+            "dispatch_action": false,
+            "element": {
+              "type": "plain_text_input",
+              "action_id": "note",
+              "multiline": false,
+              "dispatch_action_config": {
+                "trigger_actions_on": [
+                  "on_enter_pressed"
+                ]
+              }
+            }
+          }
+        ],
+        "private_metadata": "chat1␟C0CJMJ5UMUY␟␟",
+        "callback_id": "cap-modal",
+        "state": {
+          "values": {
+            "note": {
+              "note": {
+                "type": "plain_text_input",
+                "value": "Hi"
+              }
+            }
+          }
+        },
+        "hash": "1794686859.YVYq8DJX",
+        "title": {
+          "type": "plain_text",
+          "text": "Capture",
+          "emoji": true
+        },
+        "clear_on_close": false,
+        "notify_on_close": false,
+        "close": null,
+        "submit": {
+          "type": "plain_text",
+          "text": "Send",
+          "emoji": true
+        },
+        "previous_view_id": null,
+        "root_view_id": "V0CHM1EJ691",
+        "app_id": "A0CCHBHDK7X",
+        "external_id": "",
+        "app_installed_team_id": "T05479Z6JBW",
+        "bot_id": "B0CCQH77VA5"
+      },
+      "response_urls": [],
+      "is_enterprise_install": false,
+      "enterprise": null
+    },
+    "closeAnswer": null
+  },
+  "responseUrl": {
+    "followUp": {
+      "request": {
+        "response_type": "ephemeral",
+        "blocks": [
+          {
+            "type": "markdown",
+            "text": "**Deferred answer** to defer, with buttons"
+          },
+          {
+            "type": "actions",
+            "block_id": "chat1",
+            "elements": [
+              {
+                "type": "button",
+                "action_id": "cap-ack",
+                "text": {
+                  "type": "plain_text",
+                  "text": "Ack"
+                }
+              },
+              {
+                "type": "button",
+                "action_id": "cap-open",
+                "text": {
+                  "type": "plain_text",
+                  "text": "Open modal"
+                },
+                "style": "primary"
+              }
+            ]
+          }
+        ],
+        "text": "**Deferred answer** to defer, with buttons",
+        "unfurl_links": false,
+        "unfurl_media": false
+      },
+      "response": {
+        "status": 200,
+        "contentType": "text/html",
+        "body": "ok"
+      }
+    },
+    "spent": {
+      "note": "Seven posts on the spent command's deferral, one a second: 1 to 5 answered 200 ok, 6 and 7 this",
+      "okStatuses": [
+        200,
+        200,
+        200,
+        200,
+        200
+      ],
+      "response": {
+        "status": 404,
+        "contentType": "text/html",
+        "body": "used_url"
+      }
+    },
+    "expired": {
+      "note": "30.5 minutes after the command, on all three deferrals",
+      "responses": [
+        {
+          "status": 404,
+          "contentType": "text/html",
+          "body": "expired_url"
+        },
+        {
+          "status": 404,
+          "contentType": "text/html",
+          "body": "expired_url"
+        },
+        {
+          "status": 404,
+          "contentType": "text/html",
+          "body": "expired_url"
+        }
+      ]
+    }
+  },
+  "late": {
+    "status": 503,
+    "ms": 2505,
+    "body": ""
+  }
+}
diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
index acb2729a912..c45753c4b43 100644
--- a/packages/chat/slack/test/interactions.test.ts
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -1,8 +1,8 @@
 /**
  * Interactivity: the normaliser on recorded and built payloads, the answers
  * `SlackChat.interaction` gives, `layerInteractivity` over HTTP, and a
- * command's `followUp`. The command payloads are built from Slack's docs:
- * none has been captured yet.
+ * command's `followUp`. The command payloads here are built. The recorded
+ * ones are in `commands.test.ts`.
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { assert, describe, it } from "@effect/vitest"
@@ -295,7 +295,8 @@ describe("followUp", () => {
     Effect.gen(function*() {
       const fake = makeFake({
         "auth.test": authTest,
-        "response_url": { status: 404, body: { ok: false, error: "expired_url" } }
+        // As recorded in fixtures/recorded/commands.json.
+        "response_url": { status: 404, headers: { "content-type": "text/html" }, body: "used_url" }
       })
       const failure = (raw: Record) =>
         Effect.flip(Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred(raw, "ephemeral"), { markdown: "x" })))
diff --git a/packages/chat/slack/test/utils.ts b/packages/chat/slack/test/utils.ts
index 70405d4b029..420ca32234b 100644
--- a/packages/chat/slack/test/utils.ts
+++ b/packages/chat/slack/test/utils.ts
@@ -111,7 +111,9 @@ export const makeFake = (
     if (answer === hang) return hang
     if ("status" in answer && typeof answer.status === "number") {
       const { body, headers, status } = answer as Extract
-      return new Response(body === undefined ? "" : JSON.stringify(body), { status, headers: headers ?? {} })
+      // A string goes as it is: a `response_url` answers in plain text.
+      const text = body === undefined ? "" : typeof body === "string" ? body : JSON.stringify(body)
+      return new Response(text, { status, headers: headers ?? {} })
     }
     return new Response(JSON.stringify(answer), { status: 200, headers: { "content-type": "application/json" } })
   }
@@ -136,8 +138,8 @@ export const authTest = { ok: true, user_id: botUserId, team_id: team }
 export const responseUrl = `https://hooks.slack.com/commands/${team}/1794600000/abcdef`
 
 /**
- * A slash command's form fields, as Slack's docs list them. Built, not
- * captured: no command has been recorded from Slack yet.
+ * A slash command's form fields, with the names and shapes of the ones
+ * recorded in `fixtures/recorded/commands.json` and values made up.
  */
 export const commandFields = (command: string, text: string, overrides?: Record) => ({
   token: "verification",
diff --git a/packages/effect/src/chat/Chat.ts b/packages/effect/src/chat/Chat.ts
index ad331b8b5b9..f1468b59b9f 100644
--- a/packages/effect/src/chat/Chat.ts
+++ b/packages/effect/src/chat/Chat.ts
@@ -42,6 +42,7 @@ import { RetriesDisabled } from "./internal/retries.ts"
  *   `thread.platform`, failing with `NoAdapter` when there is none.
  * - `getUser` takes the platform first, because a bare user id names none.
  * - `followUp` is routed by the platform of the deferred command's thread.
+ *   Call it once per deferral: what a second call does differs by platform.
  * - `descriptor` returns a platform's capabilities and limits.
  * - Each call runs in a `Chat.{op}` span whose attributes are the platform, the
  *   op and, on failure, the error reason and retry value.
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index e0363b47f90..ce9e76087eb 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -205,8 +205,10 @@ export interface User {
  *   `edit` replaces the whole message, so an edit without `actions`
  *   removes them.
  * - `followUp` sends the answer a command's `Defer` promised, to whoever
- *   its `visibility` names. It is routed by `deferred.command.thread`, sent
- *   once per deferral and never retried. It takes no files. It fails
+ *   its `visibility` names. It is routed by `deferred.command.thread` and
+ *   never retried. It takes no files. The contract is one call per
+ *   deferral: a second posts another message on Slack and replaces the
+ *   first on Discord, and `ChatTest`'s fake fails it. It fails
  *   `NotFound` with detail `interaction_expired` past `limits.followUpAge`,
  *   and `Unsupported` without `commands`.
  *
diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
index 667c3184213..5bdb35c8153 100644
--- a/packages/effect/src/chat/ChatInteraction.ts
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -79,6 +79,12 @@ const origin = {
  * - `thread` and `messageId` are where the message carrying the button
  *   lives. `raw` is the platform's interaction payload.
  *
+ * **Gotchas**
+ *
+ * On a command's private answer, `messageId` names where the click came
+ * from, not a message: `edit`, `delete` and `fetchMessage` can't reach
+ * it. Only `raw` tells the two apart.
+ *
  * @stability unstable
  * @category events
  * @since 4.1.5
@@ -100,7 +106,8 @@ export type ButtonClicked = typeof ButtonClicked.Type
 
 /**
  * Schema for a choice in a select on a message. `value` is the chosen
- * option's value, still encoded.
+ * option's value, still encoded. `messageId` is as on `ButtonClicked`, and
+ * on a command's private answer it is not a message either.
  *
  * @stability unstable
  * @category events
@@ -345,8 +352,10 @@ export type Visibility = typeof Visibility.Type
  * **Details**
  *
  * `markdown` and `actions` are rendered and checked the way `post` renders
- * and checks them. The message gets no id: it cannot be edited, deleted or
- * fetched afterwards.
+ * and checks them, with the default post options, so a mention in it
+ * notifies nobody. The message gets no id: it cannot be edited, deleted or
+ * fetched afterwards. A click on its elements carries a `messageId`, which
+ * for a private answer names the click's origin and no message.
  *
  * @stability unstable
  * @category replies
@@ -375,6 +384,8 @@ export type Respond = typeof Respond.Type
  *
  * - It is plain data, so it can go on a queue to another process.
  * - `visibility` is fixed here. `followUp` has none of its own.
+ * - Send one `followUp` for it. A second one is not portable: Slack posts
+ *   another message and Discord replaces the first.
  *
  * **Gotchas**
  *
diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index c1af77b7710..8c17ec68d02 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -154,7 +154,8 @@ export class NoSuchElement extends Schema.TaggedError("effect/cha
  *   returned, inside `limits.followUpAge` on `Clock`. Later, a second time,
  *   or for a deferral the fake never saw, it fails `NotFound` with detail
  *   `interaction_expired`. Failing the second call is stricter than either
- *   platform, to catch a handler that relies on more than one.
+ *   platform, to catch a handler that relies on more than one: Slack posts
+ *   another message and Discord replaces the first.
  *
  * @stability unstable
  * @category services

From d72dafa3a8a94393ef843a632abc43f07a4655cf Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 21:20:36 +0000
Subject: [PATCH 50/89] chat: apply the decisions on the EFF-3802 captures

---
 .changeset/chat-slack-commands.md             |  2 +-
 .changeset/effect-chat-commands.md            |  2 +-
 packages/chat/discord/src/DiscordChat.ts      | 17 ++++++--
 packages/chat/discord/test/commands.test.ts   | 19 ++++++---
 packages/chat/discord/test/discord.ts         | 11 ++++--
 .../chat/discord/test/interactions.test.ts    | 34 +++++++++++-----
 packages/chat/discord/test/utils.ts           |  8 ++++
 packages/chat/slack/src/SlackChat.ts          | 15 ++++---
 packages/chat/slack/src/internal/adapter.ts   |  2 +
 packages/chat/slack/test/commands.test.ts     | 14 +++++++
 packages/chat/slack/test/utils.ts             | 18 ++++-----
 packages/effect/src/chat/Chat.ts              |  6 ++-
 packages/effect/src/chat/ChatAdapter.ts       |  7 ++--
 packages/effect/src/chat/ChatInteraction.ts   | 39 ++++++++++++-------
 14 files changed, 138 insertions(+), 56 deletions(-)

diff --git a/.changeset/chat-slack-commands.md b/.changeset/chat-slack-commands.md
index 78816e5c157..298917813a6 100644
--- a/.changeset/chat-slack-commands.md
+++ b/.changeset/chat-slack-commands.md
@@ -2,4 +2,4 @@
 "@effect/chat-slack": patch
 ---
 
-Take slash commands. A command's Request URL is `layerInteractivity`'s path, and `SlackChat.interaction` takes a command's fields, from the form or a `slash_commands` envelope. `normalizeInteraction` now gives `CommandInvoked` for them, where it gave none. `respond` is answered in the response body with `response_type`, `defer` with an empty 200, a modal through the command's `trigger_id`, and a late command with `Late`. `Chat.followUp` posts once to the command's `response_url`, which must be on a Slack host, for 30 minutes. The descriptor lists `commands` and `ephemeral`. A modal a command opened submits without a `messageId`. The app needs the `commands` scope. A spent or expired `response_url` answers 404 `used_url` or `expired_url`, and `followUp` fails `NotFound` with detail `interaction_expired` for both. A mention in a command's answer goes out escaped and notifies nobody.
+Take slash commands. A command's Request URL is `layerInteractivity`'s path, and `SlackChat.interaction` takes a command's fields, from the form or a `slash_commands` envelope. `normalizeInteraction` now gives `CommandInvoked` for them, where it gave none. `respond` is answered in the response body with `response_type`, `defer` with an empty 200, a modal through the command's `trigger_id`, and a late command with `Late`. `Chat.followUp` posts once to the command's `response_url`, which must be on a Slack host, for 30 minutes. The descriptor lists `commands` and `ephemeral`. A modal a command opened submits without a `messageId`. The app needs the `commands` scope. A spent or expired `response_url` answers 404 `used_url` or `expired_url`, and `followUp` fails `NotFound` with detail `interaction_expired` for both. A mention in a command's answer goes out escaped and notifies nobody. `edit` on a private answer's `messageId` fails `NotFound`, as `chat.update` answers `message_not_found` for it.
diff --git a/.changeset/effect-chat-commands.md b/.changeset/effect-chat-commands.md
index 05d73aa9e18..3eef755c5a7 100644
--- a/.changeset/effect-chat-commands.md
+++ b/.changeset/effect-chat-commands.md
@@ -2,7 +2,7 @@
 "effect": patch
 ---
 
-Add slash commands and private replies to `effect/chat`. `ChatInteraction.command` defines a command with at most one text argument, which arrives as `CommandInvoked` and goes to `Handler.command`. A command handler answers with `respond`, `defer` or a modal's `open`, and `respond` and `defer` are private by default. `Chat.followUp` sends the answer a `Defer` promised, within `limits.followUpAge`. `ChatTest` gains `command`, a `submit` and `interact` that take a command, the hook's optional `command` and the `command/*` rules. On a command's private answer, a click's `messageId` names where the click came from and no message `edit`, `delete` or `fetchMessage` can reach. Send one `followUp` per `Defer`: a second posts another message on Slack, replaces the first on Discord and fails in `ChatTest`.
+Add slash commands and private replies to `effect/chat`. `ChatInteraction.command` defines a command with at most one text argument, which arrives as `CommandInvoked` and goes to `Handler.command`. A command handler answers with `respond`, `defer` or a modal's `open`, and `respond` and `defer` are private by default. `Chat.followUp` sends the answer a `Defer` promised, within `limits.followUpAge`. `ChatTest` gains `command`, a `submit` and `interact` that take a command, the hook's optional `command` and the `command/*` rules. On a command's private answer, a click's `messageId` tells which answer was clicked, and no message op works with it. A command's answer, `respond` or `followUp`, never mentions anyone. One `followUp` per `Defer` is the portable contract: the first is the answer, and a second posts another message on Slack, overwrites the first on Discord and fails in `ChatTest`.
 
 Breaking for code written against the unreleased `effect/chat` APIs:
 
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index 08f35c21c57..912eccaf3a7 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -81,15 +81,24 @@ import { CurrentPostOptions } from "./internal/options.ts"
  *   9, each with the ephemeral flag when private. An `Ack`, which is what a
  *   command nobody handles gets, sends nothing, so a command another library
  *   owns is left to it. `withPostOptions` does not reach a command's
- *   answer: a mention in it renders and notifies nobody.
+ *   answer, `respond` or `followUp`: a mention in it renders and notifies
+ *   nobody.
+ * - Commands were recorded in a guild channel over the gateway. A command
+ *   in a direct is from Discord's docs and was not run.
  * - A click on a private answer carries the message, with the ephemeral flag
- *   (64). Only the interaction's token reaches that message, so its
- *   `messageId` is not one `Chat.edit`, `delete` or `fetchMessage` can use.
+ *   (64). Its `messageId` tells which answer was clicked. Discord's docs
+ *   reach an interaction's messages only through its token, under
+ *   `/webhooks`, and say nothing of the channel routes `Chat.edit`,
+ *   `delete` and `fetchMessage` use on an ephemeral message. Treat the id
+ *   as one no message op works with. This is from the docs: no op on it was
+ *   run.
  * - `followUp` edits the deferred command's original response, with the
  *   application id and token from its `raw`, so a second call replaces the
  *   first answer. It fails `NotFound` with detail `interaction_expired`
  *   from 15 minutes after the command, read from the interaction's id,
- *   without calling Discord. Past that Discord answers 401 with code 50027.
+ *   without calling Discord. Past that Discord answers 401 with code 50027,
+ *   which is mapped the same if a call gets there. Code 10015 is mapped
+ *   from the docs and was not seen.
  * - A modal that can't be built, a reply to a command that fails the checks
  *   of a `post`, or a callback that fails, goes to `Handler.refused`. A
  *   callback that comes back 404 `Unknown interaction` was late: that is
diff --git a/packages/chat/discord/test/commands.test.ts b/packages/chat/discord/test/commands.test.ts
index b7f501cd0cf..379064cf445 100644
--- a/packages/chat/discord/test/commands.test.ts
+++ b/packages/chat/discord/test/commands.test.ts
@@ -11,10 +11,16 @@ import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Option from "effect/Option"
 import * as TestClock from "effect/testing/TestClock"
-import * as fs from "node:fs"
-import { botUserId, discordLayer, errorResponse, type Fake, makeFake, test, tim } from "./utils.ts"
-
-const recorded = JSON.parse(fs.readFileSync(new URL("./fixtures/recorded/commands.json", import.meta.url), "utf8"))
+import {
+  botUserId,
+  discordLayer,
+  errorResponse,
+  type Fake,
+  makeFake,
+  recordedCommands as recorded,
+  test,
+  tim
+} from "./utils.ts"
 
 // The definitions the capture ran, from eff-3802-capture.ts.
 const AckButton = ChatInteraction.button("cap-ack", { label: "Ack" })
@@ -169,8 +175,9 @@ describe("recorded slash commands", () => {
         [[botUserId, "", recorded.followUp.request]]
       )
 
-      // What Discord answered at 15.5 minutes, here returned early so the
-      // mapping is reached before the adapter's own refusal.
+      // What Discord answered at 15.5 minutes, 401 with 50027, here returned
+      // early so the mapping is reached before the adapter's own refusal. The
+      // live run refused before sending, so only this reaches the mapping.
       const { body, status } = recorded.expired.edit
       assert.deepStrictEqual([status, body.code], [401, 50027])
       const spent = makeFake({ updateOriginalWebhookMessage: () => Effect.fail(errorResponse(status, body)) })
diff --git a/packages/chat/discord/test/discord.ts b/packages/chat/discord/test/discord.ts
index 44099bc613b..76fa7f047ef 100644
--- a/packages/chat/discord/test/discord.ts
+++ b/packages/chat/discord/test/discord.ts
@@ -1,7 +1,7 @@
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { type Interactions, NoSuchElement } from "effect/chat/ChatTest"
 import * as Effect from "effect/Effect"
-import { answer, botUserId, errorResponse, type Fake, guild, makeFake, step, tim } from "./utils.ts"
+import { answer, botUserId, errorResponse, type Fake, guild, makeFake, recordedCommands, step, tim } from "./utils.ts"
 
 /** The join between an id and its value in a `custom_id`, as the adapter writes it. */
 const join = "\u241F"
@@ -13,9 +13,9 @@ const idOf = (customId: string): string => customId.split(join)[0]
  * components, and records every interaction callback and every edit of an
  * original response. `interactions` is the conformance hook: it builds
  * Discord's `INTERACTION_CREATE` payload from what was posted, or a slash
- * command's, and sends it through `DiscordChat.interaction`. The command
- * and its modal's submit without a message are built with the shapes
- * recorded in `fixtures/recorded/commands.json`.
+ * command's, and sends it through `DiscordChat.interaction`. A command
+ * starts from the one recorded in `fixtures/recorded/commands.json`, and so
+ * does the submit of the modal it opened, which has no message.
  */
 export const makeDiscord = (channelType = 0) => {
   const messages = new Map()
@@ -140,6 +140,8 @@ export const makeDiscord = (channelType = 0) => {
     command: Effect.fnUntraced(function*(thread, id, options) {
       const text = options?.text ?? ""
       const answer = yield* deliver({
+        ...recordedCommands.commands.private,
+        channel: { ...recordedCommands.commands.private.channel, id: thread.id, type: channelType },
         ...base(thread.id),
         type: 2,
         data: {
@@ -166,6 +168,7 @@ export const makeDiscord = (channelType = 0) => {
         }
       })
       yield* deliver({
+        ...(message === undefined ? recordedCommands.commandModal.submitClose : {}),
         ...base(channelId, message),
         type: 5,
         data: { custom_id: data.custom_id, components }
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index a22fd0c24fa..b999d06bbb0 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -1,8 +1,8 @@
 /**
  * Interactions: the normaliser, the callbacks `DiscordChat.interaction`
  * answers with, `commandRequests` and a command's `followUp`. The slash
- * command payloads here are built from Discord's docs. The recorded ones are
- * in `commands.test.ts`.
+ * command payloads here start from the ones recorded in EFF-3802, which
+ * `commands.test.ts` runs as they are.
  */
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { assert, describe, it } from "@effect/vitest"
@@ -23,6 +23,7 @@ import {
   type Fake,
   guild,
   makeFake,
+  recordedCommands,
   scratch,
   step,
   tim
@@ -47,13 +48,28 @@ const click = (data: Record, extra: Record = {
 const submit = (customId: string, components: ReadonlyArray) =>
   click({ custom_id: customId, components }, { type: 5 })
 
+/** A recorded interaction moved to scratch, with its own id and token. */
+const fromRecorded = (recorded: any, data: Record) => ({
+  ...recorded,
+  id: "1570700000000000100",
+  token: "token",
+  channel_id: scratch,
+  channel: { ...recorded.channel, id: scratch },
+  data
+})
+
 const slash = (name: string, options?: ReadonlyArray, data: Record = {}) =>
-  omit(
-    click({ id: "1570700000000000900", name, type: 1, ...(options === undefined ? {} : { options }), ...data }, {
-      type: 2
-    }),
-    "message"
-  )
+  fromRecorded(recordedCommands.commands.private, {
+    id: "1570700000000000900",
+    name,
+    type: 1,
+    ...(options === undefined ? {} : { options }),
+    ...data
+  })
+
+/** The submit of a modal a command opened, which has no message. */
+const commandSubmit = (customId: string, components: ReadonlyArray) =>
+  fromRecorded(recordedCommands.commandModal.submitClose, { custom_id: customId, components })
 
 const omit = (raw: Record, key: string) => {
   const { [key]: _, ...rest } = raw
@@ -156,7 +172,7 @@ describe("normalizeInteraction", () => {
 
   it.effect("a submit with no message, from a modal a command opened, has no messageId", () =>
     Effect.gen(function*() {
-      const submitted = some(omit(submit("form", []), "message"))
+      const submitted = some(commandSubmit("form", []))
       assert.strictEqual(submitted._tag, "ModalSubmitted")
       assert.isFalse("messageId" in submitted)
       assert.deepStrictEqual(submitted.thread, DiscordChat.thread(scratch))
diff --git a/packages/chat/discord/test/utils.ts b/packages/chat/discord/test/utils.ts
index fb668e61857..c429567efab 100644
--- a/packages/chat/discord/test/utils.ts
+++ b/packages/chat/discord/test/utils.ts
@@ -44,6 +44,14 @@ export interface RecordedCall {
 }
 
 /** The REST calls of a fixture in `fixtures/recorded`. */
+/**
+ * The slash commands recorded in EFF-3802, `fixtures/recorded/commands.json`.
+ * The built command payloads start from these.
+ */
+export const recordedCommands: any = JSON.parse(
+  fs.readFileSync(new URL("./fixtures/recorded/commands.json", import.meta.url), "utf8")
+)
+
 export const recorded = (name: string): ReadonlyArray =>
   JSON.parse(fs.readFileSync(new URL(`./fixtures/recorded/${name}.json`, import.meta.url), "utf8")).calls
 
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index cc668e9ddb8..a4530e1d367 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -25,6 +25,8 @@
  *   and the manifest's description and usage hint are what Slack shows.
  *   With Socket Mode on, commands come as `slash_commands` envelopes: pass
  *   the envelope's `payload` to `SlackChat.interaction` in the same way.
+ *   That path is from Slack's docs and was not run, nor were commands in
+ *   Slack Connect channels or directs.
  * - A command can't be run inside a thread: Slack doesn't offer it there.
  *   A command that acts on a thread has to be told which one. Command names are shared by every app
  *   in a workspace. "Escape channels, users, and links" is off by default;
@@ -120,8 +122,9 @@ export interface SlackUser {
  *   For a command answered with `respond` that body is the message, with
  *   `response_type` `ephemeral` or `in_channel`, after the checks of a
  *   `post`; one that fails them goes to `Handler.refused`. A command's
- *   answer mentions nobody: `withPostOptions` does not reach it, so
- *   `<@U…>` goes out escaped and shows as text. There is no way to allow a
+ *   answer, `respond` or `followUp`, mentions nobody: `withPostOptions`
+ *   does not reach it, so `<@U…>` goes out escaped and shows as text, as a
+ *   `post` without `withPostOptions` does. There is no way to allow a
  *   mention in it.
  *   `undefined` is an empty answer: an ack, a close, a late click, a
  *   deferred command, a command that opened a modal, a command nobody
@@ -139,10 +142,12 @@ export interface SlackUser {
  *   `HttpClient`. It is a write and is not retried. Slack takes five posts
  *   to one `response_url` within 30 minutes, each a new message. A spent
  *   or expired one answers 404 `used_url` or `expired_url`, which is
- *   `NotFound` with detail `interaction_expired`.
+ *   `NotFound` with detail `interaction_expired`. A 410 or a JSON `error`
+ *   with either string is mapped the same, from the docs: neither was seen.
  * - A click on a private answer has no `message`. Its `messageId` is the
- *   answer's `container.message_ts`, which no Web API method reaches:
- *   `chat.update` on it answers `message_not_found`. `raw` has
+ *   answer's `container.message_ts`, which tells which answer was clicked
+ *   and which no Web API method reaches: `chat.update` on it answers
+ *   `message_not_found`, so `edit` fails `NotFound`. `raw` has
  *   `container.is_ephemeral`. A public answer reads back as a
  *   `bot_message` whose `bot_id` is not the app's own, so it is not
  *   `isSelf`.
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 799634564b1..106162dbe7d 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -124,6 +124,8 @@ const isSlackHost = (host: string): boolean =>
 /**
  * What a spent `response_url` answers, as plain text with a 404: `used_url`
  * after five posts, `expired_url` after 30 minutes. Recorded in EFF-3802.
+ * The same strings in a JSON `error`, and a 410, are from Slack's docs and
+ * were never seen; they stay mapped.
  */
 const spentResponseUrl = new Set(["expired_url", "used_url"])
 
diff --git a/packages/chat/slack/test/commands.test.ts b/packages/chat/slack/test/commands.test.ts
index 426e4da0d1e..ffa9c16ad4f 100644
--- a/packages/chat/slack/test/commands.test.ts
+++ b/packages/chat/slack/test/commands.test.ts
@@ -153,6 +153,20 @@ describe("recorded slash commands", () => {
     assert.isFalse((publicClick.raw as any).container.is_ephemeral)
   })
 
+  it.effect("fails Chat.edit NotFound on a private answer's messageId, as Slack answered chat.update", () =>
+    Effect.gen(function*() {
+      const click = normalize(recorded.clicks.privateAnswer) as ChatInteraction.ButtonClicked
+      const fake = makeFake({ "auth.test": authTest, "chat.update": { ok: false, error: "message_not_found" } })
+      const error = yield* Effect.flip(
+        Effect.flatMap(Chat.Chat, (chat) => chat.edit(click.thread, click.messageId, { markdown: "Edited" })).pipe(
+          Effect.provide(slackLayer(fake))
+        )
+      )
+      assert.deepStrictEqual([error.op, error.reason._tag], ["edit", "NotFound"])
+      const [{ params }] = fake.called("chat.update")
+      assert.deepStrictEqual([params.channel, params.ts], [channel, recorded.clicks.privateAnswer.container.message_ts])
+    }))
+
   it.effect("follows up with the body Slack rendered, and maps a spent and an expired response_url", () =>
     Effect.gen(function*() {
       const command = normalize(recorded.commands.defer) as ChatInteraction.CommandInvoked
diff --git a/packages/chat/slack/test/utils.ts b/packages/chat/slack/test/utils.ts
index 420ca32234b..ff29a51e0aa 100644
--- a/packages/chat/slack/test/utils.ts
+++ b/packages/chat/slack/test/utils.ts
@@ -138,21 +138,21 @@ export const authTest = { ok: true, user_id: botUserId, team_id: team }
 export const responseUrl = `https://hooks.slack.com/commands/${team}/1794600000/abcdef`
 
 /**
- * A slash command's form fields, with the names and shapes of the ones
- * recorded in `fixtures/recorded/commands.json` and values made up.
+ * A slash command's form fields: the form recorded in
+ * `fixtures/recorded/commands.json`, with the command, its text, the
+ * channel, and a `response_url` and `trigger_id` the tests can use.
  */
-export const commandFields = (command: string, text: string, overrides?: Record) => ({
+export const commandFields = (
+  command: string,
+  text: string,
+  overrides?: Record
+): Record => ({
+  ...fixture("commands").commands.private,
   token: "verification",
-  team_id: team,
-  team_domain: "effectfulworkspace",
   channel_id: channel,
   channel_name: "scratch",
-  user_id: "U080YLYB277",
-  user_name: "tim",
   command,
   text,
-  api_app_id: appId,
-  is_enterprise_install: "false",
   response_url: responseUrl,
   trigger_id: "trigger-command",
   ...overrides
diff --git a/packages/effect/src/chat/Chat.ts b/packages/effect/src/chat/Chat.ts
index f1468b59b9f..f5a7d3effe3 100644
--- a/packages/effect/src/chat/Chat.ts
+++ b/packages/effect/src/chat/Chat.ts
@@ -42,7 +42,11 @@ import { RetriesDisabled } from "./internal/retries.ts"
  *   `thread.platform`, failing with `NoAdapter` when there is none.
  * - `getUser` takes the platform first, because a bare user id names none.
  * - `followUp` is routed by the platform of the deferred command's thread.
- *   Call it once per deferral: what a second call does differs by platform.
+ *   One call per deferral is the portable contract: the first is the
+ *   answer, and a second is platform-specific, a new message on Slack (up to
+ *   five) and an overwrite of the first on Discord. It is rendered as
+ *   `respond` is, so it never mentions anyone: Slack shows the token as
+ *   text and Discord renders it and notifies nobody.
  * - `descriptor` returns a platform's capabilities and limits.
  * - Each call runs in a `Chat.{op}` span whose attributes are the platform, the
  *   op and, on failure, the error reason and retry value.
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index ce9e76087eb..b7f225a45c5 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -206,9 +206,10 @@ export interface User {
  *   removes them.
  * - `followUp` sends the answer a command's `Defer` promised, to whoever
  *   its `visibility` names. It is routed by `deferred.command.thread` and
- *   never retried. It takes no files. The contract is one call per
- *   deferral: a second posts another message on Slack and replaces the
- *   first on Discord, and `ChatTest`'s fake fails it. It fails
+ *   never retried. It takes no files, and `withPostOptions` does not reach
+ *   it. The contract is one call per deferral: a second posts another
+ *   message on Slack and replaces the first on Discord. An adapter does not
+ *   stop it, and `ChatTest`'s fake fails it. It fails
  *   `NotFound` with detail `interaction_expired` past `limits.followUpAge`,
  *   and `Unsupported` without `commands`.
  *
diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
index 5bdb35c8153..dea72789c92 100644
--- a/packages/effect/src/chat/ChatInteraction.ts
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -81,9 +81,13 @@ const origin = {
  *
  * **Gotchas**
  *
- * On a command's private answer, `messageId` names where the click came
- * from, not a message: `edit`, `delete` and `fetchMessage` can't reach
- * it. Only `raw` tells the two apart.
+ * On a command's private answer, `messageId` still tells which answer was
+ * clicked, but no message op works with it: `edit`, `delete` and
+ * `fetchMessage` can't reach a private answer. On Slack `chat.update` on it
+ * answered `message_not_found` live, and `edit` fails `NotFound`. On
+ * Discord only the interaction's token reaches it, which is from Discord's
+ * docs and was not run. Only `raw` tells the two apart: Slack's
+ * `container.is_ephemeral`, Discord's `message.flags` with 64.
  *
  * @stability unstable
  * @category events
@@ -106,8 +110,9 @@ export type ButtonClicked = typeof ButtonClicked.Type
 
 /**
  * Schema for a choice in a select on a message. `value` is the chosen
- * option's value, still encoded. `messageId` is as on `ButtonClicked`, and
- * on a command's private answer it is not a message either.
+ * option's value, still encoded. `messageId` is as on `ButtonClicked`: on a
+ * command's private answer it tells which answer it was, and no message op
+ * works with it.
  *
  * @stability unstable
  * @category events
@@ -135,7 +140,9 @@ export type SelectChanged = typeof SelectChanged.Type
  *
  * - `thread` and `messageId` are those of the click that opened the modal.
  *   A modal a command opened carries the command's `thread` and no
- *   `messageId`.
+ *   `messageId`. A modal opened from a command's private answer carries
+ *   that answer's id, which no message op works with, as on
+ *   `ButtonClicked`.
  * - `metadata` is still encoded.
  * - `values` are by field id, still encoded. An optional field left empty
  *   has no key.
@@ -352,10 +359,12 @@ export type Visibility = typeof Visibility.Type
  * **Details**
  *
  * `markdown` and `actions` are rendered and checked the way `post` renders
- * and checks them, with the default post options, so a mention in it
- * notifies nobody. The message gets no id: it cannot be edited, deleted or
- * fetched afterwards. A click on its elements carries a `messageId`, which
- * for a private answer names the click's origin and no message.
+ * and checks them, with the default post options. `withPostOptions` does
+ * not reach it, so it never mentions anyone: on Slack a mention token is
+ * escaped and shows as text, and on Discord it renders and notifies nobody.
+ * The message gets no id: it cannot be edited, deleted or fetched
+ * afterwards. A click on its elements carries a `messageId`, which for a
+ * private answer tells which answer it was and works with no message op.
  *
  * @stability unstable
  * @category replies
@@ -384,8 +393,9 @@ export type Respond = typeof Respond.Type
  *
  * - It is plain data, so it can go on a queue to another process.
  * - `visibility` is fixed here. `followUp` has none of its own.
- * - Send one `followUp` for it. A second one is not portable: Slack posts
- *   another message and Discord replaces the first.
+ * - The first `followUp` for it is the answer. A second one is
+ *   platform-specific: Slack posts another message, up to five, and Discord
+ *   overwrites the first. Neither adapter stops it.
  *
  * **Gotchas**
  *
@@ -528,7 +538,10 @@ export const respond = (options: {
  *
  * **Details**
  *
- * `visibility` defaults to `"ephemeral"`, and holds for the follow-up.
+ * - `visibility` defaults to `"ephemeral"`, and holds for the follow-up.
+ * - One `Chat.followUp` per deferral is the portable contract. The first
+ *   call is the answer. A second is platform-specific: a new message on
+ *   Slack, up to five, and an overwrite of the first on Discord.
  *
  * @stability unstable
  * @category replies

From 1943966900dbe12077dcfe418b0fc3a925c26c83 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 21:31:11 +0000
Subject: [PATCH 51/89] chat-discord: send followUp once, without the shared
 retry

---
 .changeset/chat-discord-commands.md           |  2 +-
 packages/chat/discord/src/DiscordChat.ts      | 10 +++++--
 packages/chat/discord/src/internal/adapter.ts | 28 ++++++++-----------
 .../chat/discord/test/interactions.test.ts    | 15 ++++++++++
 4 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/.changeset/chat-discord-commands.md b/.changeset/chat-discord-commands.md
index eebc9ba52fb..8e26937749d 100644
--- a/.changeset/chat-discord-commands.md
+++ b/.changeset/chat-discord-commands.md
@@ -2,4 +2,4 @@
 "@effect/chat-discord": patch
 ---
 
-Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`. A second `followUp` replaces the first answer. After 15 minutes Discord answers 401 with code 50027, which is `NotFound` with detail `interaction_expired`.
+Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`. A second `followUp` replaces the first answer. `followUp` sends one request and does not retry it, so a 429 fails `RateLimited`. After 15 minutes Discord answers 401 with code 50027, which is `NotFound` with detail `interaction_expired`.
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index 912eccaf3a7..fbfa88993ed 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -96,9 +96,13 @@ import { CurrentPostOptions } from "./internal/options.ts"
  *   application id and token from its `raw`, so a second call replaces the
  *   first answer. It fails `NotFound` with detail `interaction_expired`
  *   from 15 minutes after the command, read from the interaction's id,
- *   without calling Discord. Past that Discord answers 401 with code 50027,
- *   which is mapped the same if a call gets there. Code 10015 is mapped
- *   from the docs and was not seen.
+ *   without calling Discord. It sends one request and the adapter never
+ *   retries it: a 429 that reaches the adapter fails `RateLimited`, for the
+ *   caller to retry or not. dfx's own REST client waits out a 429 and sends
+ *   again below the adapter, so with it a request can still land after 15
+ *   minutes. Past that Discord answers 401 with code 50027, which is
+ *   `interaction_expired` too. Code 10015 is mapped from the docs and was
+ *   not seen.
  * - A modal that can't be built, a reply to a command that fails the checks
  *   of a `post`, or a callback that fails, goes to `Handler.refused`. A
  *   callback that comes back 404 `Unknown interaction` was late: that is
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index 858e41a9c34..95daff70d1c 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -500,9 +500,10 @@ export const make = Effect.fnUntraced(function*(options: {
   })
 
   /**
-   * Edits the original response of a deferred command, once. Refused before
-   * the call past `followUpAge`, read from the interaction's id. A token
-   * Discord no longer takes is `interaction_expired` too.
+   * Edits the original response of a deferred command, in one attempt: not
+   * through `call`, whose retries would send again after the expiry check.
+   * Refused before the call past `followUpAge`, read from the interaction's
+   * id. A token Discord no longer takes is `interaction_expired` too.
    */
   const followUp: ChatAdapter["followUp"] = Effect.fnUntraced(function*(deferred, content) {
     const op = "followUp"
@@ -517,19 +518,14 @@ export const make = Effect.fnUntraced(function*(options: {
     }
     const body = yield* message(op, content)
     const ephemeral = deferred.visibility === "ephemeral" ? 1 << 6 : 0
-    yield* call(
-      op,
-      rest.updateOriginalWebhookMessage(to.applicationId, to.token, {
-        payload: { ...body, flags: body.flags | ephemeral }
-      }),
-      true
-    ).pipe(
-      Effect.mapError((error) =>
-        SPENT_TOKEN.some((code) => Errors.hasCode(code)(error))
-          ? Errors.chatError(op, new NotFound({ detail: interactionExpired, cause: error.reason }))
-          : error
-      )
-    )
+    yield* rest.updateOriginalWebhookMessage(to.applicationId, to.token, {
+      payload: { ...body, flags: body.flags | ephemeral }
+    }).pipe(Effect.mapError((cause) => {
+      const error = Errors.chatError(op, Errors.reasonForRestError(cause, { write: true }))
+      return SPENT_TOKEN.some((code) => Errors.hasCode(code)(error))
+        ? Errors.chatError(op, new NotFound({ detail: interactionExpired, cause: error.reason }))
+        : error
+    }))
   })
 
   const adapter: ChatAdapter = {
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index b999d06bbb0..34226924878 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -522,4 +522,19 @@ describe("followUp", () => {
       )
       assert.strictEqual(spent.called("updateOriginalWebhookMessage").length, 1)
     }))
+
+  it.effect("sends one request on a 429 just before 15 minutes, and fails RateLimited without retrying", () =>
+    Effect.gen(function*() {
+      const issued = Number((BigInt("1570700000000000900") >> 22n) + 1420070400000n)
+      const limited = makeFake({
+        updateOriginalWebhookMessage: () =>
+          Effect.fail(errorResponse(429, { message: "You are being rate limited.", retry_after: 0.6, global: false }))
+      })
+      yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) - 300)
+      const fiber = yield* Effect.forkChild(Effect.flip(followUp(limited, deferred("public"))))
+      yield* TestClock.adjust(Duration.seconds(10))
+      const error = yield* Fiber.join(fiber)
+      assert.deepStrictEqual([error.op, error.reason._tag], ["followUp", "RateLimited"])
+      assert.strictEqual(limited.called("updateOriginalWebhookMessage").length, 1)
+    }))
 })

From 705e6e132b944faf3304e062c158eacdabcb70f6 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 21:40:33 +0000
Subject: [PATCH 52/89] chat-discord: send followUp over the plain HttpClient,
 so dfx does not resend a 429

---
 .changeset/chat-discord-commands.md           |  2 +-
 packages/chat/discord/src/DiscordChat.ts      | 27 ++++++----
 packages/chat/discord/src/internal/adapter.ts | 39 ++++++++++++---
 .../chat/discord/test/interactions.test.ts    | 49 ++++++++++++++++---
 packages/chat/discord/test/utils.ts           | 32 ++++++++++--
 5 files changed, 121 insertions(+), 28 deletions(-)

diff --git a/.changeset/chat-discord-commands.md b/.changeset/chat-discord-commands.md
index 8e26937749d..fd8e809e2ce 100644
--- a/.changeset/chat-discord-commands.md
+++ b/.changeset/chat-discord-commands.md
@@ -2,4 +2,4 @@
 "@effect/chat-discord": patch
 ---
 
-Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`. A second `followUp` replaces the first answer. `followUp` sends one request and does not retry it, so a 429 fails `RateLimited`. After 15 minutes Discord answers 401 with code 50027, which is `NotFound` with detail `interaction_expired`.
+Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`. A second `followUp` replaces the first answer. `followUp` sends one HTTP request over the layer's `HttpClient`, not dfx's client, and never sends it again, so a 429 fails `RateLimited`. After 15 minutes Discord answers 401 with code 50027, which is `NotFound` with detail `interaction_expired`.
diff --git a/packages/chat/discord/src/DiscordChat.ts b/packages/chat/discord/src/DiscordChat.ts
index fbfa88993ed..e90c33eb19a 100644
--- a/packages/chat/discord/src/DiscordChat.ts
+++ b/packages/chat/discord/src/DiscordChat.ts
@@ -21,6 +21,7 @@
  * @stability unstable
  * @since 4.1.5
  */
+import { DiscordConfig } from "dfx/DiscordConfig"
 import { DiscordGateway } from "dfx/DiscordGateway"
 import { DispatchHook } from "dfx/DiscordGateway/Shard/DispatchHook"
 import { DiscordREST } from "dfx/DiscordREST"
@@ -96,11 +97,11 @@ import { CurrentPostOptions } from "./internal/options.ts"
  *   application id and token from its `raw`, so a second call replaces the
  *   first answer. It fails `NotFound` with detail `interaction_expired`
  *   from 15 minutes after the command, read from the interaction's id,
- *   without calling Discord. It sends one request and the adapter never
- *   retries it: a 429 that reaches the adapter fails `RateLimited`, for the
- *   caller to retry or not. dfx's own REST client waits out a 429 and sends
- *   again below the adapter, so with it a request can still land after 15
- *   minutes. Past that Discord answers 401 with code 50027, which is
+ *   without calling Discord. Otherwise it makes one HTTP request, through
+ *   the layer's `HttpClient` and not dfx's client, and never sends it
+ *   again, unless that `HttpClient` retries by itself: a 429 fails
+ *   `RateLimited`, for the caller to retry or not.
+ *   Discord answers 401 with code 50027 past 15 minutes, which is
  *   `interaction_expired` too. Code 10015 is mapped from the docs and was
  *   not seen.
  * - A modal that can't be built, a reply to a command that fails the checks
@@ -136,10 +137,14 @@ const lookupTimeout = Duration.seconds(5)
  *
  * **Details**
  *
- * - Every REST call goes through the `DiscordREST` in context. dfx waits on
- *   its rate-limit buckets and sends again after a 429, so a rate limit
- *   shows up as a slower call. `HttpClient` is used only to download
- *   attachments from Discord's CDN, with no token.
+ * - Every REST call but `followUp` goes through the `DiscordREST` in
+ *   context. dfx waits on its rate-limit buckets and sends again after a
+ *   429, so a rate limit shows up as a slower call.
+ * - `HttpClient` downloads attachments from Discord's CDN, with no token,
+ *   and sends `followUp`'s edit, which needs no bot token either. That edit
+ *   skips dfx's client so a 429 is not sent again past the 15 minutes. It
+ *   goes to the `rest.baseUrl` of the `DiscordConfig` in context, or
+ *   Discord's own API when there is none.
  * - Content goes out as written: Discord reads Markdown itself. Every write
  *   sends `allowed_mentions: { parse: [] }` and the `SUPPRESS_EMBEDS`
  *   flag, on the post and on every edit, unless `withPostOptions` says
@@ -222,7 +227,9 @@ export const layer: Layer.Layer Adapter.defaultBaseUrl, onSome: (_) => _.rest.baseUrl })
+    const { adapter, channelType, guild, interaction } = yield* Adapter.make({ rest, http, baseUrl, botUserId })
     yield* registry.register(adapter)
 
     const refuse = (message: string, error: ChatError) =>
diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index 95daff70d1c..7a9d9eb5c13 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -1,4 +1,5 @@
 import type { DiscordREST } from "dfx/DiscordREST"
+import * as Generated from "dfx/DiscordREST/Generated"
 import type * as Discord from "dfx/types"
 import * as Cache from "effect/Cache"
 import {
@@ -28,7 +29,8 @@ import * as DateTime from "effect/DateTime"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Exit from "effect/Exit"
-import type * as HttpClient from "effect/http/HttpClient"
+import { flow } from "effect/Function"
+import * as HttpClient from "effect/http/HttpClient"
 import * as HttpClientRequest from "effect/http/HttpClientRequest"
 import * as Option from "effect/Option"
 import * as Schema from "effect/Schema"
@@ -136,14 +138,38 @@ const isObject = (u: unknown): u is Record => typeof u === "object
 
 const snowflake = /^\d{1,20}$/
 
+/**
+ * Discord's API, as dfx's `DiscordConfig` has it by default.
+ *
+ * @internal
+ */
+export const defaultBaseUrl = "https://discord.com/api/v10"
+
 /** @internal */
 export const make = Effect.fnUntraced(function*(options: {
   readonly rest: Rest
   readonly http: HttpClient.HttpClient
+  readonly baseUrl: string
   readonly botUserId: Effect.Effect
 }) {
   const { rest } = options
 
+  /**
+   * dfx's requests for the interaction webhook, over the plain `HttpClient`.
+   * dfx's own client sends a request again after a 429, which for
+   * `followUp` could land past the 15 minutes the expiry check ran on. The
+   * webhook takes the interaction's token and no bot token.
+   */
+  const webhooks = Generated.make(
+    HttpClient.mapRequest(
+      options.http,
+      flow(
+        HttpClientRequest.prependUrl(options.baseUrl),
+        HttpClientRequest.setHeader("User-Agent", "DiscordBot (https://effect.website, 1)")
+      )
+    )
+  )
+
   const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
 
   /** A message's elements as action rows, checked before any call. */
@@ -500,10 +526,11 @@ export const make = Effect.fnUntraced(function*(options: {
   })
 
   /**
-   * Edits the original response of a deferred command, in one attempt: not
-   * through `call`, whose retries would send again after the expiry check.
-   * Refused before the call past `followUpAge`, read from the interaction's
-   * id. A token Discord no longer takes is `interaction_expired` too.
+   * Edits the original response of a deferred command in one HTTP request:
+   * not through `call`, nor dfx's client, whose retries would send again
+   * after the expiry check. Refused before the call past `followUpAge`,
+   * read from the interaction's id. A token Discord no longer takes is
+   * `interaction_expired` too.
    */
   const followUp: ChatAdapter["followUp"] = Effect.fnUntraced(function*(deferred, content) {
     const op = "followUp"
@@ -518,7 +545,7 @@ export const make = Effect.fnUntraced(function*(options: {
     }
     const body = yield* message(op, content)
     const ephemeral = deferred.visibility === "ephemeral" ? 1 << 6 : 0
-    yield* rest.updateOriginalWebhookMessage(to.applicationId, to.token, {
+    yield* webhooks.updateOriginalWebhookMessage(to.applicationId, to.token, {
       payload: { ...body, flags: body.flags | ephemeral }
     }).pipe(Effect.mapError((cause) => {
       const error = Errors.chatError(op, Errors.reasonForRestError(cause, { write: true }))
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index 34226924878..6881d57ebf7 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -6,14 +6,22 @@
  */
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { assert, describe, it } from "@effect/vitest"
+import * as DiscordConfig from "dfx/DiscordConfig"
+import { DiscordRESTLive } from "dfx/DiscordREST"
+import { MemoryRateLimitStoreLive } from "dfx/RateLimit"
 import * as Chat from "effect/chat/Chat"
 import type { ChatError } from "effect/chat/ChatError"
 import * as ChatInteraction from "effect/chat/ChatInteraction"
 import { checkInteraction } from "effect/chat/ChatTest"
+import * as Clock from "effect/Clock"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Layer from "effect/Layer"
 import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
 import * as TestClock from "effect/testing/TestClock"
 import {
   answer,
@@ -523,18 +531,45 @@ describe("followUp", () => {
       assert.strictEqual(spent.called("updateOriginalWebhookMessage").length, 1)
     }))
 
-  it.effect("sends one request on a 429 just before 15 minutes, and fails RateLimited without retrying", () =>
+  it.effect("sends one HTTP request through dfx's layers on a 429 just before 15 minutes, and fails RateLimited", () =>
     Effect.gen(function*() {
       const issued = Number((BigInt("1570700000000000900") >> 22n) + 1420070400000n)
-      const limited = makeFake({
-        updateOriginalWebhookMessage: () =>
-          Effect.fail(errorResponse(429, { message: "You are being rate limited.", retry_after: 0.6, global: false }))
-      })
+      const attempts: Array<{ readonly url: string; readonly authorized: boolean; readonly at: number }> = []
+      const http = HttpClient.make((request) =>
+        Effect.map(Clock.currentTimeMillis, (at) => {
+          attempts.push({ url: request.url, authorized: "authorization" in request.headers, at: at - issued })
+          return HttpClientResponse.fromWeb(
+            request,
+            Response.json({ message: "You are being rate limited.", retry_after: 0.6, global: false }, {
+              status: 429,
+              headers: { "retry-after": "0.6" }
+            })
+          )
+        })
+      )
+      // dfx's own REST layers, which wait out a 429 and send again, over an HTTP client that counts.
+      const layer = DiscordChat.layer.pipe(
+        Layer.provideMerge(Chat.layer),
+        Layer.provide(DiscordRESTLive),
+        Layer.provide([
+          DiscordConfig.layer({ token: Redacted.make("bot-token"), rest: { baseUrl: "https://discord.test/api" } }),
+          MemoryRateLimitStoreLive,
+          Layer.succeed(HttpClient.HttpClient, http)
+        ])
+      )
       yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) - 300)
-      const fiber = yield* Effect.forkChild(Effect.flip(followUp(limited, deferred("public"))))
+      const fiber = yield* Effect.forkChild(Effect.flip(
+        Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred("public"), { markdown: "Done" })).pipe(
+          Effect.provide(layer)
+        )
+      ))
       yield* TestClock.adjust(Duration.seconds(10))
       const error = yield* Fiber.join(fiber)
       assert.deepStrictEqual([error.op, error.reason._tag], ["followUp", "RateLimited"])
-      assert.strictEqual(limited.called("updateOriginalWebhookMessage").length, 1)
+      assert.deepStrictEqual(attempts, [{
+        url: `https://discord.test/api/webhooks/${botUserId}/token/messages/@original`,
+        authorized: false,
+        at: Duration.toMillis(Duration.minutes(15)) - 300
+      }])
     }))
 })
diff --git a/packages/chat/discord/test/utils.ts b/packages/chat/discord/test/utils.ts
index c429567efab..164244d5c00 100644
--- a/packages/chat/discord/test/utils.ts
+++ b/packages/chat/discord/test/utils.ts
@@ -5,6 +5,7 @@ import type { ChatAdapter } from "effect/chat/ChatAdapter"
 import { Registry } from "effect/chat/ChatAdapter"
 import * as Effect from "effect/Effect"
 import * as HttpClient from "effect/http/HttpClient"
+import type * as HttpClientRequest from "effect/http/HttpClientRequest"
 import * as HttpClientResponse from "effect/http/HttpClientResponse"
 import * as Layer from "effect/Layer"
 import * as fs from "node:fs"
@@ -121,7 +122,27 @@ export const makeFake = (handlers: Record): Fake => {
 
 const getMyUser = () => Effect.succeed({ id: botUserId, username: "Janitor", bot: true })
 
-/** `DiscordChat.layer` over a fake, with `Chat` and an `HttpClient` that answers `download`. */
+const originalResponse = /\/webhooks\/([^/]+)\/([^/]+)\/messages\/@original$/
+
+/**
+ * The fake's `updateOriginalWebhookMessage` as Discord's HTTP answer, for
+ * `followUp`, which sends over the plain `HttpClient`.
+ */
+const webhookEdit = (fake: Fake, request: HttpClientRequest.HttpClientRequest, path: RegExpExecArray) =>
+  fake.service.updateOriginalWebhookMessage(decodeURIComponent(path[1]), decodeURIComponent(path[2]), {
+    payload: request.body._tag === "Uint8Array" ? JSON.parse(new TextDecoder().decode(request.body.body)) : undefined
+  }).pipe(
+    Effect.match({
+      onSuccess: (body) => Response.json(body),
+      onFailure: (error: any) => Response.json(error.data ?? {}, { status: error.response.status })
+    }),
+    Effect.map((response) => HttpClientResponse.fromWeb(request, response))
+  )
+
+/**
+ * `DiscordChat.layer` over a fake, with `Chat` and an `HttpClient` that
+ * answers `download`, and an original response's edit from the fake.
+ */
 export const discordLayer = (fake: Fake, options?: { readonly download?: Uint8Array | undefined }) =>
   DiscordChat.layer.pipe(
     Layer.provideMerge(Chat.layer),
@@ -133,9 +154,12 @@ export const discordLayer = (fake: Fake, options?: { readonly download?: Uint8Ar
     )),
     Layer.provide(Layer.succeed(
       HttpClient.HttpClient,
-      HttpClient.make((request) =>
-        Effect.succeed(HttpClientResponse.fromWeb(request, new Response(new Uint8Array(options?.download ?? []))))
-      )
+      HttpClient.make((request) => {
+        const path = request.method === "PATCH" ? originalResponse.exec(request.url) : null
+        return path !== null
+          ? webhookEdit(fake, request, path)
+          : Effect.succeed(HttpClientResponse.fromWeb(request, new Response(new Uint8Array(options?.download ?? []))))
+      })
     ))
   )
 

From f3e4350f58a4348e8737f063418ece4d765726cb Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sat, 14 Nov 2026 21:49:08 +0000
Subject: [PATCH 53/89] Fix Slack command assertion under Deno types

---
 packages/chat/slack/test/interactions.test.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
index c45753c4b43..6e02e803706 100644
--- a/packages/chat/slack/test/interactions.test.ts
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -378,7 +378,7 @@ describe("layerInteractivity", () => {
         [...Object.entries(commandFields("/deploy", text)), ["text", "second"]] as Array<[string, string]>
       const answered = yield* send(undefined, { form: form("first") })
       assert.strictEqual(answered.status, 200)
-      assert.strictEqual((yield* Effect.promise(() => answered.json())).response_type, "in_channel")
+      assert.propertyVal(yield* Effect.promise(() => answered.json()), "response_type", "in_channel")
       assert.deepStrictEqual(seen, ["first"])
 
       handler.command = () => Effect.as(Effect.never, ChatInteraction.ack)

From a2d9bb9441508bf02337d6760fd891a744cff4fd Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 08:53:20 +0000
Subject: [PATCH 54/89] Consolidate chat release notes into one changeset

---
 .changeset/chat-discord-commands.md |  5 -----
 .changeset/chat-discord.md          |  5 -----
 .changeset/chat-slack-commands.md   |  5 -----
 .changeset/chat-slack.md            |  6 ------
 .changeset/effect-chat-buttons.md   |  9 ---------
 .changeset/effect-chat-commands.md  | 15 ---------------
 .changeset/effect-chat.md           | 12 +++++++++++-
 7 files changed, 11 insertions(+), 46 deletions(-)
 delete mode 100644 .changeset/chat-discord-commands.md
 delete mode 100644 .changeset/chat-discord.md
 delete mode 100644 .changeset/chat-slack-commands.md
 delete mode 100644 .changeset/chat-slack.md
 delete mode 100644 .changeset/effect-chat-buttons.md
 delete mode 100644 .changeset/effect-chat-commands.md

diff --git a/.changeset/chat-discord-commands.md b/.changeset/chat-discord-commands.md
deleted file mode 100644
index fd8e809e2ce..00000000000
--- a/.changeset/chat-discord-commands.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-"@effect/chat-discord": patch
----
-
-Take slash commands with no options or one string option, and add `DiscordChat.commandRequests`, which gives the registration payloads of a group's commands. The adapter registers nothing. `normalizeInteraction` now gives `CommandInvoked` for those commands, and a `ModalSubmitted` without a `messageId` for the submit of a modal a command opened, where it gave none for both. `respond` is callback type 4, `defer` type 5 and a modal type 9, with the ephemeral flag when private. A command nobody handles gets no callback, so one another library owns is left to it. `Chat.followUp` edits the original response for 15 minutes. The descriptor lists `commands` and `ephemeral`. A second `followUp` replaces the first answer. `followUp` sends one HTTP request over the layer's `HttpClient`, not dfx's client, and never sends it again, so a 429 fails `RateLimited`. After 15 minutes Discord answers 401 with code 50027, which is `NotFound` with detail `interaction_expired`.
diff --git a/.changeset/chat-discord.md b/.changeset/chat-discord.md
deleted file mode 100644
index 80a9ff153d5..00000000000
--- a/.changeset/chat-discord.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-"@effect/chat-discord": patch
----
-
-Add `@effect/chat-discord`, an unstable Discord adapter for `effect/chat` built on dfx, with gateway dispatch, threads, reactions, post-then-edit streaming, and buttons, selects and modals through `DiscordChat.interaction` and `layerGatewayInteractions`. `layerDispatchHook` delivers gateway events before dfx stores their sequence, for a host that resumes from a `ShardStateStore` of its own, and `withPostOptions({ failIfNotExists: false })` lets a reply to a deleted message go out without its reference.
diff --git a/.changeset/chat-slack-commands.md b/.changeset/chat-slack-commands.md
deleted file mode 100644
index 298917813a6..00000000000
--- a/.changeset/chat-slack-commands.md
+++ /dev/null
@@ -1,5 +0,0 @@
----
-"@effect/chat-slack": patch
----
-
-Take slash commands. A command's Request URL is `layerInteractivity`'s path, and `SlackChat.interaction` takes a command's fields, from the form or a `slash_commands` envelope. `normalizeInteraction` now gives `CommandInvoked` for them, where it gave none. `respond` is answered in the response body with `response_type`, `defer` with an empty 200, a modal through the command's `trigger_id`, and a late command with `Late`. `Chat.followUp` posts once to the command's `response_url`, which must be on a Slack host, for 30 minutes. The descriptor lists `commands` and `ephemeral`. A modal a command opened submits without a `messageId`. The app needs the `commands` scope. A spent or expired `response_url` answers 404 `used_url` or `expired_url`, and `followUp` fails `NotFound` with detail `interaction_expired` for both. A mention in a command's answer goes out escaped and notifies nobody. `edit` on a private answer's `messageId` fails `NotFound`, as `chat.update` answers `message_not_found` for it.
diff --git a/.changeset/chat-slack.md b/.changeset/chat-slack.md
deleted file mode 100644
index b8bceebf13a..00000000000
--- a/.changeset/chat-slack.md
+++ /dev/null
@@ -1,6 +0,0 @@
----
-"@effect/chat-slack": patch
-"effect": patch
----
-
-Add `@effect/chat-slack`, an unstable Slack adapter for `effect/chat`, with the Events API webhook with a whole-request deadline and a log line saying what caused each 503, native streaming replies, the agent stop button, all-or-nothing posts with files, and buttons, selects and modals through `layerInteractivity` or `SlackChat.interaction`. Add the `StopRequested` chat event.
diff --git a/.changeset/effect-chat-buttons.md b/.changeset/effect-chat-buttons.md
deleted file mode 100644
index f7c438e6a1e..00000000000
--- a/.changeset/effect-chat-buttons.md
+++ /dev/null
@@ -1,9 +0,0 @@
----
-"effect": patch
----
-
-Add buttons, selects and modals to `effect/chat`. The new `ChatUi` module has the elements, and the new `ChatInteraction` module has typed definitions, groups, `handle` with its deadline, and `layer`. `post` and `edit` take `actions`, `ChatMarkdown.post` sends them with the last part, and `Descriptor.measure` measures them. `ChatTest` gains `click`, `submit`, `interact`, `checkInteraction`, the `interactions` conformance hook and the buttons and modals rules.
-
-`ChatMarkdown` now cuts long text only at grapheme cluster boundaries, where it used to avoid only splitting a surrogate pair.
-
-The conformance rules `unsupported/buttons` and `unsupported/selects` run against every adapter, without a new capability. A third-party adapter that ignores `actions` and posts anyway will start failing them. It should fail `Unsupported` naming `buttons` or `selects` until it supports them.
diff --git a/.changeset/effect-chat-commands.md b/.changeset/effect-chat-commands.md
deleted file mode 100644
index 3eef755c5a7..00000000000
--- a/.changeset/effect-chat-commands.md
+++ /dev/null
@@ -1,15 +0,0 @@
----
-"effect": patch
----
-
-Add slash commands and private replies to `effect/chat`. `ChatInteraction.command` defines a command with at most one text argument, which arrives as `CommandInvoked` and goes to `Handler.command`. A command handler answers with `respond`, `defer` or a modal's `open`, and `respond` and `defer` are private by default. `Chat.followUp` sends the answer a `Defer` promised, within `limits.followUpAge`. `ChatTest` gains `command`, a `submit` and `interact` that take a command, the hook's optional `command` and the `command/*` rules. On a command's private answer, a click's `messageId` tells which answer was clicked, and no message op works with it. A command's answer, `respond` or `followUp`, never mentions anyone. One `followUp` per `Defer` is the portable contract: the first is the answer, and a second posts another message on Slack, overwrites the first on Discord and fails in `ChatTest`.
-
-Breaking for code written against the unreleased `effect/chat` APIs:
-
-- `ModalSubmitted.messageId` is optional, since a modal a command opened has no message. The typed submit's `messageId` is `string | undefined`, and `checkInteraction` no longer requires it.
-- `Handler` needs a `command`, and `refused` can be given a `CommandInvoked`.
-- `Interaction` gains `CommandInvoked`, and `handle` can give `Respond` and `Defer`.
-- `Capability` gains `commands` and `ephemeral`, and `ChatTest`'s default capabilities include both.
-- `Ops`, `ChatAdapter` and the `Chat` service gain `followUp`. A third-party adapter stops compiling until it has one: one without commands fails `Unsupported` naming `commands`.
-
-The conformance rule `unsupported/commands` runs against every adapter, without a new capability. A third-party adapter whose `followUp` does anything but fail `Unsupported` naming `commands` will start failing it.
diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index aebd0577612..9c441819d8e 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -1,5 +1,15 @@
 ---
 "effect": patch
+"@effect/chat-slack": patch
+"@effect/chat-discord": patch
 ---
 
-Add unstable `effect/chat` APIs for chat bots, grapheme-safe long and streamed Markdown with refused-file fallback that preserves overflow text, and in-memory adapter conformance testing. `ChatMessage.repliesToSelf` reads the new `replyTo.isSelf`, which `ChatTest.checkMessage` requires of an adapter wherever `replyTo.authorId` is set, and `ChatMarkdownError.remainingFence` names the code fence `remaining` was cut in.
+Add unstable `effect/chat` APIs and Slack/Discord adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
+
+### Migrating from earlier PR snapshots
+
+- Handle `CommandInvoked` in interaction handlers and exhaustive matches, and `Respond`/`Defer` results from `handle`. `ModalSubmitted.messageId` is optional for command-opened modals.
+- Implement `followUp` in custom adapters. Adapters without commands must fail it with `Unsupported` naming `commands`; unsupported actions must fail with `Unsupported` naming `buttons` or `selects`. These conformance rules run against every adapter. `ChatTest` includes `commands` and `ephemeral` by default.
+- Supply `replyTo.isSelf` wherever `replyTo.authorId` is set; `ChatMessage.repliesToSelf` reads it. `ChatMarkdownError.remainingFence` identifies the fence around unposted text.
+- Command replies are private by default and never notify mentions. Private-answer IDs identify interactions, not addressable messages. Use one `Chat.followUp` per deferral: repeats create another message on Slack, overwrite on Discord, and fail in `ChatTest`.
+- Configure Slack commands with the `commands` scope and `layerInteractivity` Request URL. Register Discord commands yourself using `DiscordChat.commandRequests`; the adapter does not register them.

From e121c5b6db27ab5379dcb9c003a756dc608ee22d Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 09:05:51 +0000
Subject: [PATCH 55/89] Reduce effect/chat tests to the distinct contracts and
 regressions

---
 .../chat/discord/test/DiscordChat.test.ts     | 182 +------
 packages/chat/discord/test/commands.test.ts   |  16 -
 .../test/fixtures/recorded/embeds.json        | 414 ---------------
 .../test/fixtures/recorded/length.json        | 299 -----------
 .../test/fixtures/recorded/reactions.json     | 197 -------
 packages/chat/discord/test/gateway.test.ts    |  13 -
 .../chat/discord/test/interactions.test.ts    | 207 +-------
 packages/chat/discord/test/normalize.test.ts  | 213 ++------
 packages/chat/discord/test/utils.ts           |   5 +-
 packages/chat/slack/test/SlackChat.test.ts    | 161 +-----
 packages/chat/slack/test/actions.test.ts      |  13 +-
 packages/chat/slack/test/commands.test.ts     |  23 +-
 packages/chat/slack/test/emoji.test.ts        | 101 +---
 packages/chat/slack/test/escape.test.ts       |   7 +-
 packages/chat/slack/test/events.test.ts       | 104 ----
 .../fixtures/events/edit-adds-mention.json    |  52 --
 .../fixtures/events/edit-keeps-mention.json   |  52 --
 .../fixtures/events/edit-removes-mention.json |  52 --
 .../test/fixtures/events/file-mention.json    |  35 --
 .../fixtures/events/human-code-mention.json   |  21 -
 .../slack/test/fixtures/events/reactions.json |  83 ---
 .../test/fixtures/events/stop-no-stream.json  |  76 ---
 .../recorded/agent-session-stopped.json       |   2 +-
 .../fixtures/recorded/conversations-info.json | 150 ------
 .../slack/test/fixtures/recorded/errors.json  | 347 -------------
 .../test/fixtures/recorded/reactions.json     | 480 ------------------
 .../test/fixtures/recorded/users-info.json    | 193 -------
 packages/chat/slack/test/interactions.test.ts | 121 +----
 packages/chat/slack/test/normalize.test.ts    | 164 +-----
 packages/chat/slack/test/richText.test.ts     |  28 +-
 packages/chat/slack/test/text.test.ts         |  50 --
 packages/chat/slack/test/webhook.test.ts      |  54 +-
 packages/effect/test/chat/ChatEvent.test.ts   |   6 -
 .../effect/test/chat/ChatInteraction.test.ts  |  63 +--
 .../effect/test/chat/ChatMarkdown.test.ts     | 390 ++------------
 packages/effect/test/chat/ChatTest.test.ts    | 441 +++-------------
 36 files changed, 277 insertions(+), 4538 deletions(-)
 delete mode 100644 packages/chat/discord/test/fixtures/recorded/embeds.json
 delete mode 100644 packages/chat/discord/test/fixtures/recorded/length.json
 delete mode 100644 packages/chat/discord/test/fixtures/recorded/reactions.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/edit-adds-mention.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/edit-keeps-mention.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/edit-removes-mention.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/file-mention.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/human-code-mention.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/reactions.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/stop-no-stream.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/conversations-info.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/errors.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/reactions.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/users-info.json

diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index dfc8888050f..aa1e97fd037 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -22,8 +22,7 @@ import {
   makeFake,
   scratch,
   statusCodeError,
-  step,
-  tim
+  step
 } from "./utils.ts"
 
 const run = (fake: Fake, effect: Effect.Effect, options?: { readonly download?: Uint8Array }) =>
@@ -83,31 +82,17 @@ describe("post", () => {
     )
   })
 
-  it.effect("a reply does not ping its author by default", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42", authorId: tim } })
-        assert.deepStrictEqual(fake.called("createMessage")[0][1].allowed_mentions, noMentions)
-      })
-    )
-  })
-
   it.effect("failIfNotExists false lets a reply to a deleted message go out without its reference", () => {
     const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
     return run(
       fake,
       Effect.gen(function*() {
         const discord = yield* adapter
-        yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42" } })
         yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42" } }).pipe(
           DiscordChat.withPostOptions({ failIfNotExists: false })
         )
         yield* discord.post(channel, { markdown: "hi" }).pipe(DiscordChat.withPostOptions({ failIfNotExists: false }))
         assert.deepStrictEqual(fake.called("createMessage").map(([, body]) => body.message_reference), [
-          { message_id: "42" },
           { message_id: "42", fail_if_not_exists: false },
           undefined
         ])
@@ -127,15 +112,6 @@ describe("post", () => {
           detail: "message_too_long",
           retry: "denied"
         })
-        assert.deepStrictEqual(
-          yield* reason(discord.post(channel, { markdown: "a".repeat(1999) + "\u{1F1EC}\u{1F1E7}" })),
-          {
-            op: "post",
-            tag: "TooLarge",
-            detail: "message_too_long",
-            retry: "denied"
-          }
-        )
         assert.strictEqual(fake.calls.length, 0)
         // 2,000 astral emoji are 4,000 UTF-16 units, and Discord took them.
         yield* discord.post(channel, { markdown: "\u{1F600}".repeat(2000) })
@@ -295,7 +271,7 @@ describe("buttons and selects", () => {
     )
   })
 
-  it.effect("fail TooLarge before the call when the rows run out or a custom_id would pass 100", () => {
+  it.effect("fail before the call when a select's id and option value pass 99 code points or an id holds the join", () => {
     const fake = makeFake({})
     return run(
       fake,
@@ -303,40 +279,14 @@ describe("buttons and selects", () => {
         const discord = yield* adapter
         const post = (actions: ReadonlyArray) =>
           reason(discord.post(channel, { markdown: "x", actions }))
-        assert.deepStrictEqual(discord.descriptor.limits.actionsPerMessage, 25)
-        assert.strictEqual((yield* post(Array.from({ length: 26 }, (_, i) => button(i)))).detail, "too_many_actions")
-        // Six selects need six rows.
-        assert.strictEqual((yield* post(Array.from({ length: 6 }, () => select))).detail, "too_many_actions")
-        // 99 code points of id and value fit, with the join, in Discord's 100.
-        const astral = "\u{1D400}"
-        assert.strictEqual(
-          (yield* post([{ _tag: "Button", id: "id", label: "x", value: astral.repeat(98) }])).detail,
-          "action_data_too_long"
-        )
-        assert.strictEqual(
-          (yield* post([{ ...select, options: [{ label: "x", value: "x".repeat(96) }] }])).tag,
-          "TooLarge"
-        )
-        assert.strictEqual(
-          (yield* post([{ _tag: "Button", id: "a\u241Fb", label: "x" }])).tag,
-          "InvalidRequest"
-        )
-        assert.strictEqual(fake.calls.length, 0)
-      })
-    )
-  })
-
-  it.effect("an id and value of 99 code points fit", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        yield* discord.post(channel, {
-          markdown: "x",
-          actions: [{ _tag: "Button", id: "id", label: "x", value: "\u{1D400}".repeat(97) }]
+        assert.deepStrictEqual(yield* post([{ ...select, options: [{ label: "x", value: "x".repeat(96) }] }]), {
+          op: "post",
+          tag: "TooLarge",
+          detail: "action_data_too_long",
+          retry: "denied"
         })
-        assert.strictEqual(fake.called("createMessage").length, 1)
+        assert.strictEqual((yield* post([{ _tag: "Button", id: "a\u241Fb", label: "x" }])).tag, "InvalidRequest")
+        assert.strictEqual(fake.calls.length, 0)
       })
     )
   })
@@ -345,59 +295,25 @@ describe("buttons and selects", () => {
 describe("recorded components", () => {
   // fixtures/recorded/components.json: what Discord accepted and refused in #test.
   const call = (name: string) => step("components", name)
-  const styles = ["default", "primary", "danger"] as const
-  const sentRows = (actions: ReadonlyArray) => {
+  const options = (n: number) => Array.from({ length: n }, (_, i) => ({ label: "o" + i, value: "o" + i }))
+
+  it.effect("a custom_id of 100 code points, the join included, goes out as Discord accepted it", () => {
     const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
     return run(
       fake,
       Effect.gen(function*() {
         const discord = yield* adapter
-        yield* discord.post(channel, { markdown: "x", actions })
-        return fake.called("createMessage")[0][1].components
-      })
-    )
-  }
-  const buttons = (from: number, to: number): Array =>
-    Array.from(
-      { length: to - from },
-      (_, i) => ({ _tag: "Button", id: "b" + (from + i), label: "b" + (from + i), value: "v" + (from + i) })
-    )
-  const options = (n: number) => Array.from({ length: n }, (_, i) => ({ label: "o" + i, value: "o" + i }))
-
-  it.effect("the rows the adapter builds are the rows Discord accepted", () =>
-    Effect.gen(function*() {
-      const cases: ReadonlyArray]> = [
-        ["rows-25-buttons", [
-          ...Array.from({ length: 24 }, (_, i): ChatUi.Action => ({
-            _tag: "Button",
-            id: "b" + i,
-            label: "b" + i,
-            value: "v" + i,
-            style: styles[i % 3]
-          })),
-          { _tag: "LinkButton", label: "link", url: "https://effect.website" }
-        ]],
-        ["rows-selects-and-buttons", [
-          ...buttons(0, 5),
-          { _tag: "Select", id: "s1", options: options(25), selected: "o3" },
-          ...buttons(5, 10),
-          { _tag: "Select", id: "s2", options: options(2) },
-          ...buttons(10, 15)
-        ]],
-        ["custom-id-100-ascii-with-join", [{ _tag: "Button", id: "a".repeat(98), label: "x", value: "b" }]],
         // 100 code points but 150 UTF-16 units: Discord counts code points.
-        ["custom-id-100-code-points-astral", [{
-          _tag: "Button",
-          id: "a".repeat(49),
-          label: "x",
-          value: "\u{1F600}".repeat(50)
-        }]]
-      ]
-      for (const [name, actions] of cases) {
+        const name = "custom-id-100-code-points-astral"
+        yield* discord.post(channel, {
+          markdown: "x",
+          actions: [{ _tag: "Button", id: "a".repeat(49), label: "x", value: "\u{1F600}".repeat(50) }]
+        })
         assert.strictEqual(call(name).status, 200)
-        assert.deepStrictEqual(yield* sentRows(actions), call(name).request.components, name)
-      }
-    }))
+        assert.deepStrictEqual(fake.called("createMessage")[0][1].components, call(name).request.components)
+      })
+    )
+  })
 
   it.effect("what Discord refused, the adapter refuses before a call", () => {
     const fake = makeFake({})
@@ -408,17 +324,12 @@ describe("recorded components", () => {
         const post = (actions: ReadonlyArray) =>
           reason(discord.post(channel, { markdown: "x", actions }))
         const cases: ReadonlyArray, string]> = [
-          ["twenty-six-buttons", buttons(0, 26), "too_many_actions"],
+          // Six selects need six rows, under the 25 elements.
           [
             "six-rows",
             Array.from({ length: 6 }, (_, i) => ({ _tag: "Select", id: "s" + i, options: options(2) })),
             "too_many_actions"
           ],
-          [
-            "custom-id-101-ascii",
-            [{ _tag: "Button", id: "a".repeat(100), label: "x", value: "b" }],
-            "action_data_too_long"
-          ],
           ["custom-id-101-code-points-astral", [{
             _tag: "Button",
             id: "a".repeat(50),
@@ -452,12 +363,9 @@ describe("files", () => {
 
   it.effect("a denied answer to a post with files is file_refused, with Discord's reason as the cause", () =>
     Effect.gen(function*() {
-      for (const [status, code] of [[400, 40005], [400, 50045], [403, 50013]] as const) {
-        const result = yield* refused(() => Effect.fail(errorResponse(status, { code, message: "refused" })))
-        assert.strictEqual(result.detail, "file_refused")
-        assert.strictEqual(result.retry, "denied")
-        assert.strictEqual((result.cause as any).detail, String(code))
-      }
+      const denied = yield* refused(() => Effect.fail(errorResponse(403, { code: 50013, message: "refused" })))
+      assert.deepStrictEqual([denied.detail, denied.retry], ["file_refused", "denied"])
+      assert.strictEqual((denied.cause as any).detail, "50013")
       // Discord's own 413, as recorded in fixtures/recorded/uploads.json.
       const oversize = yield* refused(() => answer(step("uploads", "upload-20MiB-plus-1")))
       assert.deepStrictEqual([oversize.tag, oversize.detail, oversize.retry], ["TooLarge", "file_refused", "denied"])
@@ -698,7 +606,6 @@ describe("opener", () => {
         const opener = Option.getOrThrow(yield* discord.opener(thread))
         assert.strictEqual(opener.id, threadId)
         assert.deepStrictEqual(opener.thread, channel)
-        assert.deepStrictEqual(fake.called("getMessage"), [[threadId, threadId], [scratch, threadId]])
       })
     )
   })
@@ -761,7 +668,6 @@ describe("an opener the bot can't read", () => {
       Effect.gen(function*() {
         const discord = yield* adapter
         assert.isTrue(Option.isNone(yield* discord.opener(thread)))
-        assert.strictEqual(fake.called("getMessage").length, 2)
       })
     )
   })
@@ -846,7 +752,6 @@ describe("getThread and getUser", () => {
         assert.isTrue(inGuild.isSelf && inGuild.isBot)
         // raw is the guild member, so the roles are there to read.
         assert.deepStrictEqual(inGuild.raw, { ...member, nick: "Janny" })
-        assert.isTrue(Array.isArray(member.roles))
         assert.deepStrictEqual(fake.called("getGuildMember"), [[guild, botUserId]])
         const plain = yield* discord.getUser(botUserId)
         assert.strictEqual(plain.name, "Janitor")
@@ -983,41 +888,4 @@ describe("dispatch", () => {
       })
     )
   })
-
-  it.effect("delivers Tim's recorded mention after looking the channel up", () => {
-    // Derived dispatch: a REST body, which carries no channel_type.
-    const raw = step("human", "human-mention-get-message").response
-    const fake = makeFake({ getChannel: () => answer(step("human", "human-mention-get-channel")) })
-    const { provide, seen } = collect()
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        yield* provide(discord.dispatch({ t: "MESSAGE_CREATE", d: raw }))
-        assert.strictEqual(seen.length, 1)
-        const event = seen[0]
-        assert(event._tag === "MessageCreated")
-        assert.strictEqual(event.kind, "channel")
-        assert.isFalse(event.message.author.isBot)
-        assert.deepStrictEqual(event.message.mentions.map((mention) => mention.id), [botUserId])
-        assert.deepStrictEqual(fake.called("getChannel"), [[raw.channel_id]])
-      })
-    )
-  })
-
-  it.effect("passes the handler's NotAccepted on", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        const error = yield* Effect.flip(
-          discord.dispatch(events("channel-message")[0]).pipe(
-            Effect.provideService(ChatHandler, ChatHandler.of({ handle: () => Effect.fail(new NotAccepted()) }))
-          )
-        )
-        assert.instanceOf(error, NotAccepted)
-      })
-    )
-  })
 })
diff --git a/packages/chat/discord/test/commands.test.ts b/packages/chat/discord/test/commands.test.ts
index 379064cf445..edef84bbcb7 100644
--- a/packages/chat/discord/test/commands.test.ts
+++ b/packages/chat/discord/test/commands.test.ts
@@ -87,20 +87,6 @@ const callbacks = (fake: Fake) =>
 const issuedAt = (id: string) => Number((BigInt(id) >> 22n) + 1420070400000n)
 
 describe("recorded slash commands", () => {
-  it("normalizes each command the gateway delivered", () => {
-    for (const [what, payload] of Object.entries(recorded.commands)) {
-      const event = normalize(payload)
-      assert.strictEqual(event._tag, "CommandInvoked", what)
-      if (event._tag !== "CommandInvoked") return
-      assert.deepStrictEqual([event.id, event.text, event.userId, event.thread.id], [
-        "chat-capture",
-        payload.data.options?.[0]?.value ?? "",
-        tim,
-        test
-      ])
-    }
-  })
-
   it.effect("answers each command with the callback Discord took", () =>
     Effect.gen(function*() {
       for (const what of ["private", "public", "mention", "modal", "defer", "deferPublic"]) {
@@ -110,8 +96,6 @@ describe("recorded slash commands", () => {
         assert.deepStrictEqual(callbacks(fake), [[payload.id, "", recorded.callbacks[what].payload]], what)
         assert.strictEqual(recorded.callbacks[what].status, 204)
       }
-      // Allowed mentions are empty: the mention renders and notifies nobody.
-      assert.deepStrictEqual(recorded.callbacks.mention.payload.data.allowed_mentions.parse, [])
     }))
 
   it.effect("takes a click on a private answer, whose message has the ephemeral flag, and acks it", () =>
diff --git a/packages/chat/discord/test/fixtures/recorded/embeds.json b/packages/chat/discord/test/fixtures/recorded/embeds.json
deleted file mode 100644
index 3f2b46b05b4..00000000000
--- a/packages/chat/discord/test/fixtures/recorded/embeds.json
+++ /dev/null
@@ -1,414 +0,0 @@
-{
-  "case": "SUPPRESS_EMBEDS: set on a post, kept through an edit that sends no flags and one that sends them; a post without it gets an embed",
-  "provenance": {
-    "kind": "recorded",
-    "source": "Discord REST v10 with the Janitor bot token, from a local script",
-    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
-    "recordedAt": "2026-11-13T01:18Z, during EFF-3695",
-    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
-  },
-  "calls": [
-    {
-      "step": "embed-post-suppressed",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "Fixture: https://effect.website suppressed on post",
-        "flags": 4,
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: https://effect.website suppressed on post",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:23.451000+00:00",
-        "edited_timestamp": null,
-        "flags": 4,
-        "components": [],
-        "id": "1570608737213878394",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "embed-edit-adds-link-without-flag",
-      "method": "PATCH",
-      "path": "/channels/1570607253965246584/messages/1570608737213878394",
-      "request": {
-        "content": "Fixture: edit adds https://github.com/Effect-TS/effect without flags",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: edit adds https://github.com/Effect-TS/effect without flags",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:23.451000+00:00",
-        "edited_timestamp": "2026-11-13T01:18:24.973811+00:00",
-        "flags": 4,
-        "components": [],
-        "id": "1570608737213878394",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "embed-read-after-edit-without-flag",
-      "method": "GET",
-      "path": "/channels/1570607253965246584/messages/1570608737213878394",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: edit adds https://github.com/Effect-TS/effect without flags",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:23.451000+00:00",
-        "edited_timestamp": "2026-11-13T01:18:24.973000+00:00",
-        "flags": 4,
-        "components": [],
-        "id": "1570608737213878394",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "embed-post-plain",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "Fixture: post without a link",
-        "flags": 4,
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: post without a link",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:30.633000+00:00",
-        "edited_timestamp": null,
-        "flags": 4,
-        "components": [],
-        "id": "1570608767337238549",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "embed-edit-adds-link-with-flag",
-      "method": "PATCH",
-      "path": "/channels/1570607253965246584/messages/1570608767337238549",
-      "request": {
-        "content": "Fixture: edit adds https://github.com/Effect-TS/effect with flags",
-        "flags": 4,
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: edit adds https://github.com/Effect-TS/effect with flags",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:30.633000+00:00",
-        "edited_timestamp": "2026-11-13T01:18:33.390847+00:00",
-        "flags": 4,
-        "components": [],
-        "id": "1570608767337238549",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "embed-read-after-edit-with-flag",
-      "method": "GET",
-      "path": "/channels/1570607253965246584/messages/1570608767337238549",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: edit adds https://github.com/Effect-TS/effect with flags",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:30.633000+00:00",
-        "edited_timestamp": "2026-11-13T01:18:33.390000+00:00",
-        "flags": 4,
-        "components": [],
-        "id": "1570608767337238549",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "embed-post-unsuppressed",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "Fixture: https://effect.website not suppressed",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: https://effect.website not suppressed",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [
-          {
-            "type": "article",
-            "url": "https://effect.website/",
-            "title": "Effect | Production Grade TypeScript",
-            "provider": {
-              "name": "Effect"
-            },
-            "thumbnail": {
-              "url": "https://effect.website/og/index.png?v=8c9f1acacbf10295",
-              "proxy_url": "https://images-ext-1.discordapp.net/external/ac8H1c0fSuUVZaaFa8Kq5Ea8pOu0WAeL2xGxrJ6Y6Qc/%3Fv%3D8c9f1acacbf10295/https/effect.website/og/index.png",
-              "width": 1200,
-              "height": 630,
-              "content_type": "image/png",
-              "placeholder": "xQcGBIAIl3iIeIdyi3gHeAIAAA==",
-              "placeholder_version": 1,
-              "flags": 0
-            }
-          }
-        ],
-        "timestamp": "2026-11-13T01:18:39.014000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608802489700492",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "embed-read-unsuppressed",
-      "method": "GET",
-      "path": "/channels/1570607253965246584/messages/1570608802489700492",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: https://effect.website not suppressed",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [
-          {
-            "type": "article",
-            "url": "https://effect.website/",
-            "title": "Effect | Production Grade TypeScript",
-            "provider": {
-              "name": "Effect"
-            },
-            "thumbnail": {
-              "url": "https://effect.website/og/index.png?v=8c9f1acacbf10295",
-              "proxy_url": "https://images-ext-1.discordapp.net/external/ac8H1c0fSuUVZaaFa8Kq5Ea8pOu0WAeL2xGxrJ6Y6Qc/%3Fv%3D8c9f1acacbf10295/https/effect.website/og/index.png",
-              "width": 1200,
-              "height": 630,
-              "content_type": "image/png",
-              "placeholder": "xQcGBIAIl3iIeIdyi3gHeAIAAA==",
-              "placeholder_version": 1,
-              "flags": 0
-            }
-          }
-        ],
-        "timestamp": "2026-11-13T01:18:39.014000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608802489700492",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    }
-  ]
-}
diff --git a/packages/chat/discord/test/fixtures/recorded/length.json b/packages/chat/discord/test/fixtures/recorded/length.json
deleted file mode 100644
index e35528d45ed..00000000000
--- a/packages/chat/discord/test/fixtures/recorded/length.json
+++ /dev/null
@@ -1,299 +0,0 @@
-{
-  "case": "Content length probes: 2,000 ASCII, 2,000 astral emoji, 2,000 two-byte letters and 1,000 combining pairs pass; 2,001 ASCII and 1,999 letters plus a flag fail. Discord counts code points",
-  "provenance": {
-    "kind": "recorded",
-    "source": "Discord REST v10 with the Janitor bot token, from a local script",
-    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
-    "recordedAt": "2026-11-13T01:18Z, during EFF-3695",
-    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
-  },
-  "calls": [
-    {
-      "step": "length-2000-ascii",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:09.244000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608677625401476",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "length-2001-ascii",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "content": {
-            "_errors": [
-              {
-                "code": "BASE_TYPE_MAX_LENGTH",
-                "message": "Must be 2000 or fewer in length."
-              }
-            ]
-          }
-        }
-      }
-    },
-    {
-      "step": "length-2000-astral",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:11.935000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608688912273419",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "length-1001-astral",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:13.927000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608697267322883",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "length-2000-bmp",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:15.335000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608703172780053",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "length-2000-combining",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:18:16.737000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608709053452330",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "length-1999-plus-flag",
-      "method": "POST",
-      "path": "/channels/1570607253965246584/messages",
-      "request": {
-        "content": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa🇬🇧",
-        "allowed_mentions": {
-          "parse": []
-        }
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "content": {
-            "_errors": [
-              {
-                "code": "BASE_TYPE_MAX_LENGTH",
-                "message": "Must be 2000 or fewer in length."
-              }
-            ]
-          }
-        }
-      }
-    }
-  ]
-}
diff --git a/packages/chat/discord/test/fixtures/recorded/reactions.json b/packages/chat/discord/test/fixtures/recorded/reactions.json
deleted file mode 100644
index 851dc8ae093..00000000000
--- a/packages/chat/discord/test/fixtures/recorded/reactions.json
+++ /dev/null
@@ -1,197 +0,0 @@
-{
-  "case": "A message read back while it carries a Unicode, a skin-toned and a custom reaction, in a channel and in a thread",
-  "provenance": {
-    "kind": "recorded",
-    "source": "Discord REST v10 with the Janitor bot token, from a local script",
-    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
-    "recordedAt": "2026-11-13T01:17Z, during EFF-3695",
-    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
-  },
-  "calls": [
-    {
-      "step": "reaction-read-channel",
-      "method": "GET",
-      "path": "/channels/1570607253965246584/messages/1570608483965870101",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: reactions target in a channel",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:17:23.072000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608483965870101",
-        "channel_id": "1570607253965246584",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false,
-        "reactions": [
-          {
-            "emoji": {
-              "id": null,
-              "name": "👍"
-            },
-            "count": 1,
-            "count_details": {
-              "burst": 0,
-              "normal": 1
-            },
-            "burst_colors": [],
-            "me_burst": false,
-            "burst_me": false,
-            "me": true,
-            "burst_count": 0
-          },
-          {
-            "emoji": {
-              "id": null,
-              "name": "👍🏽"
-            },
-            "count": 1,
-            "count_details": {
-              "burst": 0,
-              "normal": 1
-            },
-            "burst_colors": [],
-            "me_burst": false,
-            "burst_me": false,
-            "me": true,
-            "burst_count": 0
-          },
-          {
-            "emoji": {
-              "id": "1570607258226790481",
-              "name": "effectchat"
-            },
-            "count": 1,
-            "count_details": {
-              "burst": 0,
-              "normal": 1
-            },
-            "burst_colors": [],
-            "me_burst": false,
-            "burst_me": false,
-            "me": true,
-            "burst_count": 0
-          }
-        ]
-      }
-    },
-    {
-      "step": "reaction-read-thread",
-      "method": "GET",
-      "path": "/channels/1570608327602471024/messages/1570608491532386377",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Fixture: reactions target in a thread",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:17:24.876000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570608491532386377",
-        "channel_id": "1570608327602471024",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false,
-        "position": 2,
-        "reactions": [
-          {
-            "emoji": {
-              "id": null,
-              "name": "👍"
-            },
-            "count": 1,
-            "count_details": {
-              "burst": 0,
-              "normal": 1
-            },
-            "burst_colors": [],
-            "me_burst": false,
-            "burst_me": false,
-            "me": true,
-            "burst_count": 0
-          },
-          {
-            "emoji": {
-              "id": null,
-              "name": "👍🏽"
-            },
-            "count": 1,
-            "count_details": {
-              "burst": 0,
-              "normal": 1
-            },
-            "burst_colors": [],
-            "me_burst": false,
-            "burst_me": false,
-            "me": true,
-            "burst_count": 0
-          },
-          {
-            "emoji": {
-              "id": "1570607258226790481",
-              "name": "effectchat"
-            },
-            "count": 1,
-            "count_details": {
-              "burst": 0,
-              "normal": 1
-            },
-            "burst_colors": [],
-            "me_burst": false,
-            "burst_me": false,
-            "me": true,
-            "burst_count": 0
-          }
-        ]
-      }
-    }
-  ]
-}
diff --git a/packages/chat/discord/test/gateway.test.ts b/packages/chat/discord/test/gateway.test.ts
index fd3ccc02d6f..a30dac84e8e 100644
--- a/packages/chat/discord/test/gateway.test.ts
+++ b/packages/chat/discord/test/gateway.test.ts
@@ -214,17 +214,4 @@ describe("layerDispatchHook", () => {
       assert.strictEqual(gateway.reconnects(), 0)
     }))
   })
-
-  it.effect("a dispatch the adapter does not read never reaches the handler", () => {
-    const storage: Storage = new Map()
-    let handled = 0
-    return Effect.scoped(Effect.gen(function*() {
-      const gateway = yield* host(storage, () => Effect.sync(() => void handled++))
-      yield* gateway.receive(hello)
-      yield* gateway.receive(ready)
-      yield* gateway.receive({ op: 0, t: "TYPING_START", s: 2, d: {} })
-      yield* until(() => stored(storage)?.sequence === 2)
-      assert.strictEqual(handled, 0)
-    }))
-  })
 })
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index 6881d57ebf7..415b701caff 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -27,7 +27,6 @@ import {
   answer,
   botUserId,
   discordLayer,
-  errorResponse,
   type Fake,
   guild,
   makeFake,
@@ -75,10 +74,6 @@ const slash = (name: string, options?: ReadonlyArray, data: Record) =>
-  fromRecorded(recordedCommands.commandModal.submitClose, { custom_id: customId, components })
-
 const omit = (raw: Record, key: string) => {
   const { [key]: _, ...rest } = raw
   return rest
@@ -105,25 +100,14 @@ describe("normalizeInteraction", () => {
           raw: withValue.raw
         })
       )
-      const without = some(click({ custom_id: "go", component_type: 2 }))
-      assert.isFalse("value" in without)
       // In a direct the user is on `user`, not `member`.
       const direct = some({ ...omit(click({ custom_id: "go", component_type: 2 }), "member"), user: { id: tim } })
       assert.strictEqual(direct.userId, tim)
-      for (const interaction of [withValue, without, direct]) {
+      for (const interaction of [withValue, direct]) {
         yield* checkInteraction(interaction, { platform: "discord" })
       }
     }))
 
-  it("a string select gives its one value", () => {
-    const changed = some(click({ custom_id: "pick", component_type: 3, values: ["b"] }))
-    assert.deepStrictEqual([changed._tag, changed.id, (changed as ChatInteraction.SelectChanged).value], [
-      "SelectChanged",
-      "pick",
-      "b"
-    ])
-  })
-
   it.effect("a submit reads each Label's input, leaves an empty one out and splits the metadata", () =>
     Effect.gen(function*() {
       const submitted = some(submit("form\u241F{\"v\":1}", [
@@ -159,47 +143,17 @@ describe("normalizeInteraction", () => {
       yield* checkInteraction(submitted, { platform: "discord" })
     }))
 
-  it.effect("a slash command gives its name and its one string option, or the empty string", () =>
-    Effect.gen(function*() {
-      const bare = some(slash("summarize"))
-      assert.deepStrictEqual(
-        bare,
-        ChatInteraction.CommandInvoked.make({
-          id: "summarize",
-          text: "",
-          thread: DiscordChat.thread(scratch),
-          userId: tim,
-          raw: bare.raw
-        })
-      )
-      const withText = some(slash("deploy", [{ type: 3, name: "version", value: "v1 <@1>" }]))
-      assert.strictEqual((withText as ChatInteraction.CommandInvoked).text, "v1 <@1>")
-      yield* checkInteraction(bare, { platform: "discord" })
-      yield* checkInteraction(withText, { platform: "discord" })
-    }))
-
-  it.effect("a submit with no message, from a modal a command opened, has no messageId", () =>
-    Effect.gen(function*() {
-      const submitted = some(commandSubmit("form", []))
-      assert.strictEqual(submitted._tag, "ModalSubmitted")
-      assert.isFalse("messageId" in submitted)
-      assert.deepStrictEqual(submitted.thread, DiscordChat.thread(scratch))
-      yield* checkInteraction(submitted, { platform: "discord" })
-    }))
-
   it("anything not from an element the adapter built, or a command it can't express, is None", () => {
     for (
       const raw of [
-        // A user command, a slash command with an integer option, and one with two options.
+        // A user command, and a slash command with an integer option.
         slash("profile", undefined, { type: 2 }),
         slash("roll", [{ type: 4, name: "sides", value: 6 }]),
-        slash("deploy", [{ type: 3, name: "a", value: "x" }, { type: 3, name: "b", value: "y" }]),
         // Autocomplete for a command.
         { ...slash("deploy", [{ type: 3, name: "version", value: "v", focused: true }]), type: 4 },
-        { type: 1, id: "1", token: "t" },
+        // A user select, and a click with no message.
         click({ custom_id: "users", component_type: 5, values: [tim] }),
-        omit(click({ custom_id: "go", component_type: 2 }), "message"),
-        "not an object"
+        omit(click({ custom_id: "go", component_type: 2 }), "message")
       ]
     ) {
       assert.isTrue(Option.isNone(DiscordChat.normalizeInteraction(raw)))
@@ -247,20 +201,6 @@ describe("interaction", () => {
   const answering = () => makeFake({ createInteractionResponse: () => Effect.succeed(null) })
   const payloads = (fake: Fake) => fake.called("createInteractionResponse").map(([, , options]) => options.payload)
 
-  it.effect("acks a click and a close with type 6, to the interaction's id and token", () =>
-    Effect.gen(function*() {
-      const fake = answering()
-      const { handler, received } = recording({})
-      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
-      yield* deliver(fake, submit("form", []), handler)
-      assert.strictEqual(received.length, 2)
-      assert.deepStrictEqual(fake.called("createInteractionResponse").map(([id, token]) => [id, token]), [
-        ["1570700000000000100", "token"],
-        ["1570700000000000100", "token"]
-      ])
-      assert.deepStrictEqual(payloads(fake), [{ type: 6 }, { type: 6 }])
-    }))
-
   it.effect("opens a modal with type 9: Labels around the inputs and a text display for a text", () =>
     Effect.gen(function*() {
       const fake = answering()
@@ -310,41 +250,15 @@ describe("interaction", () => {
       }])
     }))
 
-  it.effect("answers errors with a private message listing each one, escaped", () =>
+  it.effect("a modal title over 45 reaches refused as TooLarge, and the click is still answered", () =>
     Effect.gen(function*() {
-      const fake = answering()
-      const { handler } = recording({ submit: ChatInteraction.errors({ name: "Too short.", size: "Pick " }) })
-      yield* deliver(fake, submit("form", []), handler)
-      assert.deepStrictEqual(payloads(fake), [{
-        type: 4,
-        data: { content: "- Too short\\.\n- Pick \\", allowed_mentions: { parse: [] }, flags: 64 }
-      }])
-    }))
-
-  it.effect("a modal title or label over 45 reaches refused as TooLarge, and the click is still answered", () =>
-    Effect.gen(function*() {
-      for (
-        const modal of [
-          ChatInteraction.modal("form", { title: "t".repeat(46), fields: {} }),
-          ChatInteraction.modal("form", {
-            title: "t",
-            fields: { a: ChatInteraction.textInput({ label: "l".repeat(46) }) }
-          })
-        ]
-      ) {
-        const fake = answering()
-        const { handler, refused } = recording({ click: modal.open() })
-        yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
-        assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag]), [["openModal", "TooLarge"]])
-        assert.deepStrictEqual(payloads(fake), [{ type: 6 }])
-      }
-      // 45 fits.
       const fake = answering()
       const { handler, refused } = recording({
-        click: ChatInteraction.modal("form", { title: "t".repeat(45), fields: {} }).open()
+        click: ChatInteraction.modal("form", { title: "t".repeat(46), fields: {} }).open()
       })
       yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
-      assert.deepStrictEqual(refused, [])
+      assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag]), [["openModal", "TooLarge"]])
+      assert.deepStrictEqual(payloads(fake), [{ type: 6 }])
     }))
 
   it.effect("a modal callback that comes back Unknown interaction is refused as interaction_expired", () =>
@@ -389,55 +303,29 @@ describe("interaction", () => {
       assert.deepStrictEqual([received.length, fake.calls.length], [0, 0])
     }))
 
-  it.effect("answers a command: type 4 for respond, 5 for defer, 9 for a modal, private with flag 64", () =>
+  it.effect("withPostOptions does not reach a command's answer", () =>
     Effect.gen(function*() {
       const fake = answering()
-      const replies: Array<(command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply> = [
-        () => ChatInteraction.respond({ markdown: "Hi *there*" }),
-        () => ChatInteraction.respond({ markdown: "Hi", visibility: "public" }),
-        (command) => ChatInteraction.defer(command),
-        (command) => ChatInteraction.defer(command, { visibility: "public" }),
-        () => ChatInteraction.modal("form", { title: "t", fields: {} }).open()
-      ]
-      for (const reply of replies) {
-        const { handler, refused } = recording({ command: reply })
-        // withPostOptions does not reach a command's answer.
-        yield* DiscordChat.withPostOptions(deliver(fake, slash("summarize"), handler), {
-          suppressEmbeds: false,
-          notify: { everyone: true }
-        })
-        assert.deepStrictEqual(refused, [])
-      }
-      assert.deepStrictEqual(payloads(fake), [
-        // The message a post sends, embeds off with flag 4.
-        {
-          type: 4,
-          data: {
-            content: "Hi *there*",
-            allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] },
-            flags: 68
-          }
-        },
-        {
-          type: 4,
-          data: { content: "Hi", allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] }, flags: 4 }
-        },
-        { type: 5, data: { flags: 64 } },
-        { type: 5 },
-        { type: 9, data: { custom_id: "form", title: "t", components: [] } }
-      ])
+      const { handler } = recording({
+        command: () => ChatInteraction.respond({ markdown: "Hi", visibility: "public" })
+      })
+      yield* DiscordChat.withPostOptions(deliver(fake, slash("summarize"), handler), {
+        suppressEmbeds: false,
+        notify: { everyone: true }
+      })
+      assert.deepStrictEqual(payloads(fake), [{
+        type: 4,
+        data: { content: "Hi", allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] }, flags: 4 }
+      }])
     }))
 
-  it.effect("sends nothing for a command nobody handles, and refuses a respond a post would refuse", () =>
+  it.effect("sends nothing for a command nobody handles", () =>
     Effect.gen(function*() {
       const fake = answering()
       const { handler, received, refused } = recording({})
       yield* deliver(fake, slash("theirs"), handler)
       assert.strictEqual(received.length, 1)
-      const tooLong = recording({ command: () => ChatInteraction.respond({ markdown: "x".repeat(2001) }) })
-      yield* deliver(fake, slash("summarize"), tooLong.handler)
       assert.deepStrictEqual(refused, [])
-      assert.deepStrictEqual(tooLong.refused.map((error) => [error.op, error.reason._tag]), [["respond", "TooLarge"]])
       assert.deepStrictEqual(payloads(fake), [])
     }))
 })
@@ -478,59 +366,6 @@ describe("followUp", () => {
   const deferred = (visibility: ChatInteraction.Visibility) =>
     ChatInteraction.defer(some(slash("summarize")) as ChatInteraction.CommandInvoked, { visibility })
 
-  const followUp = (fake: Fake, defer: ChatInteraction.Defer, markdown = "Done") =>
-    Effect.flatMap(Chat.Chat, (chat) => chat.followUp(defer, { markdown })).pipe(Effect.provide(discordLayer(fake)))
-
-  it.effect("edits the original response with the application id and token, private with flag 64", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({ updateOriginalWebhookMessage: () => Effect.succeed({ id: "1" }) })
-      yield* followUp(fake, deferred("ephemeral"))
-      yield* followUp(fake, deferred("public"))
-      assert.deepStrictEqual(
-        fake.called("updateOriginalWebhookMessage").map(([applicationId, token, options]) => [
-          applicationId,
-          token,
-          options.payload
-        ]),
-        [
-          // Flag 4 keeps embeds off, as a post does.
-          [botUserId, "token", {
-            content: "Done",
-            allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] },
-            flags: 68
-          }],
-          [botUserId, "token", {
-            content: "Done",
-            allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] },
-            flags: 4
-          }]
-        ]
-      )
-    }))
-
-  it.effect("is interaction_expired from 15 minutes after the command without a call, or for a spent token", () =>
-    Effect.gen(function*() {
-      const issued = Number((BigInt("1570700000000000900") >> 22n) + 1420070400000n)
-      const spent = makeFake({
-        updateOriginalWebhookMessage: () =>
-          Effect.fail(errorResponse(401, { code: 50027, message: "Invalid Webhook Token" }))
-      })
-      yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) - 1)
-      const refused = yield* Effect.flip(followUp(spent, deferred("public")))
-      const tooLong = yield* Effect.flip(followUp(spent, deferred("public"), "x".repeat(2001)))
-      yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)))
-      const late = yield* Effect.flip(followUp(spent, deferred("public")))
-      assert.deepStrictEqual(
-        [refused, tooLong, late].map((error) => [error.op, error.reason._tag, error.reason.detail]),
-        [
-          ["followUp", "NotFound", "interaction_expired"],
-          ["followUp", "TooLarge", tooLong.reason.detail],
-          ["followUp", "NotFound", "interaction_expired"]
-        ]
-      )
-      assert.strictEqual(spent.called("updateOriginalWebhookMessage").length, 1)
-    }))
-
   it.effect("sends one HTTP request through dfx's layers on a 429 just before 15 minutes, and fails RateLimited", () =>
     Effect.gen(function*() {
       const issued = Number((BigInt("1570700000000000900") >> 22n) + 1420070400000n)
diff --git a/packages/chat/discord/test/normalize.test.ts b/packages/chat/discord/test/normalize.test.ts
index cb0724b21a9..e27267fd8aa 100644
--- a/packages/chat/discord/test/normalize.test.ts
+++ b/packages/chat/discord/test/normalize.test.ts
@@ -1,12 +1,10 @@
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { tokens } from "@effect/chat-discord/internal/mentions"
-import { decodeMessageFields, message, messageTypes } from "@effect/chat-discord/internal/normalize"
 import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { dedupeKey } from "effect/chat/ChatEvent"
 import * as ChatMessage from "effect/chat/ChatMessage"
 import { checkEvent, checkMessage } from "effect/chat/ChatTest"
-import * as ChatThread from "effect/chat/ChatThread"
 import * as Effect from "effect/Effect"
 import * as Option from "effect/Option"
 import * as Result from "effect/Result"
@@ -16,9 +14,7 @@ import {
   type Dispatch,
   eventFixtures,
   events,
-  forum,
   guild,
-  recorded,
   role,
   scratch,
   step,
@@ -93,12 +89,7 @@ describe("normalize", () => {
     assert(Result.isFailure(missing))
     assert.instanceOf(missing.failure, DiscordChat.MissingChannelType)
     assert.strictEqual(missing.failure.channelId, scratch)
-    for (
-      const [channelType, kind] of [[0, "channel"], [11, "thread"], [1, "direct"], [15, "channel"], [
-        99,
-        "channel"
-      ]] as const
-    ) {
+    for (const [channelType, kind] of [[11, "thread"], [1, "direct"]] as const) {
       const result = DiscordChat.normalize(dispatch, { ...context, channelType })
       assert(Result.isSuccess(result))
       const event = result.success[0]
@@ -114,15 +105,6 @@ describe("normalize", () => {
   it("a message with an invalid timestamp is dropped, not thrown", () => {
     const base = events("channel-message")[0]
     assert.deepStrictEqual(normalize({ t: base.t, d: { ...base.d, timestamp: "not a date" } }), [])
-    assert.isUndefined(decodeMessageFields({ ...base.d, timestamp: "not a date" }))
-  })
-
-  it("a reaction needs no channel type", () => {
-    for (const dispatch of events("reactions")) {
-      const result = DiscordChat.normalize(dispatch, context)
-      assert(Result.isSuccess(result))
-      assert.strictEqual(result.success.length, 1)
-    }
   })
 
   it("a message in a thread is addressed to the thread", () => {
@@ -148,12 +130,9 @@ describe("normalize", () => {
     for (const dispatch of dispatches) assert.deepStrictEqual(normalize(dispatch), [])
   })
 
-  it("only DEFAULT, REPLY, CHAT_INPUT_COMMAND and CONTEXT_MENU_COMMAND are messages", () => {
-    assert.deepStrictEqual([...messageTypes].sort((a, b) => a - b), [0, 19, 20, 23])
+  it("a system message, such as a member join, gives no event", () => {
     const base = events("channel-message")[0]
-    for (const type of [1, 6, 7, 8, 18, 21, 24, 46, 99]) {
-      assert.deepStrictEqual(normalize({ t: base.t, d: { ...base.d, type } }), [], String(type))
-    }
+    assert.deepStrictEqual(normalize({ t: base.t, d: { ...base.d, type: 7 } }), [])
   })
 
   it("a webhook message has the webhook as its author", () => {
@@ -181,24 +160,12 @@ describe("normalize", () => {
       })
       assert.isTrue(ChatMessage.repliesToSelf(event.message))
       assert.isFalse(ChatMessage.mentionsSelf(event.message))
-      assert.isFalse(event.message.author.isBot)
-      assert.isFalse(event.message.author.isSelf)
-      assert.strictEqual(event.message.author.id, tim)
-      assert.deepStrictEqual(event.thread, DiscordChat.thread(test))
       const member = Option.getOrThrow(DiscordChat.member(event))
       assert.strictEqual(member.guildId, guild)
       assert.deepStrictEqual(member.roles, dispatch.d.member.roles)
     }
   })
 
-  it("the bot's own replies, ping on or off, carry replyTo and no mention", () => {
-    for (const prefix of ["Fixture: a reply with the ping on", "Fixture: a reply with the ping off"]) {
-      const event = created(byContent("reply-ping", prefix))
-      assert.deepStrictEqual(event.message.mentions, [])
-      assert.strictEqual(event.message.replyTo?.authorId, botUserId)
-    }
-  })
-
   it("an attachment has an id that names its message, and no URL", () => {
     const event = created(events("attachment")[0])
     assert.deepStrictEqual(event.message.attachments, [{
@@ -213,21 +180,10 @@ describe("normalize", () => {
     const cases: ReadonlyArray<
       readonly [string, ReadonlyArray<{ kind: string; id: string; isSelf: boolean; token: string }>]
     > = [
-      ["Fixture: <@1564742987727118426> as a plain", [{
-        kind: "user",
-        id: botUserId,
-        isSelf: true,
-        token: `<@${botUserId}>`
-      }]],
       ["Fixture: <@!", [{ kind: "user", id: botUserId, isSelf: true, token: `<@!${botUserId}>` }]],
       [`Fixture: <@${tim}>`, [{ kind: "user", id: tim, isSelf: false, token: `<@${tim}>` }]],
-      ["Fixture: <@&", [{ kind: "role", id: role, isSelf: false, token: `<@&${role}>` }]],
       ["Fixture: @everyone that", [{ kind: "broadcast", id: "everyone", isSelf: false, token: "@everyone" }]],
-      ["Fixture: @here", [{ kind: "broadcast", id: "here", isSelf: false, token: "@here" }]],
       ["Fixture: @everyone with parse", []],
-      ["Fixture: <#", [{ kind: "channel", id: test, isSelf: false, token: `<#${test}>` }]],
-      ["Fixture: `<@", []],
-      ["Fixture: in a fence", []],
       ["Fixture: the bot naming", []],
       ["Fixture: <@1564742987727118426> and", [
         { kind: "user", id: botUserId, isSelf: true, token: `<@${botUserId}>` },
@@ -249,17 +205,11 @@ describe("normalize", () => {
       assert.deepStrictEqual(ids("<@1> `<@2>` ``<@3>`` ```\n<@4>\n``` <@5>"), ["1", "5"])
       assert.deepStrictEqual(ids("\\<@1> <@2>"), ["2"])
       assert.deepStrictEqual(ids("`unclosed <@1>"), ["1"])
-      assert.deepStrictEqual(ids("a``b <@1>"), ["1"])
-      assert.deepStrictEqual(ids("@everyone@here <@&3><#4>"), ["everyone", "here", "3", "4"])
     })
 
     it("parseMention reads one whole token", () => {
-      assert.deepStrictEqual(DiscordChat.parseMention("<@1>"), Option.some({ kind: "user" as const, id: "1" }))
       assert.deepStrictEqual(DiscordChat.parseMention("<@!1>"), Option.some({ kind: "user" as const, id: "1" }))
-      assert.deepStrictEqual(DiscordChat.parseMention("<@&2>"), Option.some({ kind: "role" as const, id: "2" }))
-      assert.deepStrictEqual(DiscordChat.parseMention("<#3>"), Option.some({ kind: "channel" as const, id: "3" }))
-      assert.deepStrictEqual(DiscordChat.parseMention("@here"), Option.some({ kind: "broadcast" as const, id: "here" }))
-      for (const slice of ["<@1> ", " <@1>", "<@x>", "@everyone!", "<@1><@2>", ""]) {
+      for (const slice of ["<@1> ", "<@x>", "<@1><@2>"]) {
         assert.isTrue(Option.isNone(DiscordChat.parseMention(slice)), slice)
       }
     })
@@ -291,77 +241,52 @@ describe("normalize", () => {
         assert.notStrictEqual(dedupeKey(found[0]), dedupeKey(found[3]))
         assert.deepStrictEqual(found[6].thread, DiscordChat.thread("1570608327602471024"))
       }))
-
-    it("the custom emoji's id stays on raw", () => {
-      const event = normalize(events("reactions")[2])[0]
-      assert.strictEqual((event.raw as any).emoji.id, "1570607258226790481")
-    })
   })
 })
 
 /**
  * Item 11, recorded: Tim typed both in the Discord client. The gateway recorder
  * had stopped by then, so the bodies are REST reads, which carry no
- * `guild_id`, `member` or `channel_type`. The REST tests read them as history
- * does. The dispatch tests wrap a body as a `MESSAGE_CREATE` with the
- * channel's recorded type in the context, which makes those dispatches derived.
+ * `guild_id`, `member` or `channel_type`. Each is wrapped as a
+ * `MESSAGE_CREATE` with the channel's recorded type in the context, which
+ * makes the dispatch derived.
  */
 describe("a person's messages, recorded through REST", () => {
-  const read = (raw: any) => {
-    const fields = decodeMessageFields(raw)
-    assert.isDefined(fields)
-    return message(raw, fields!, context)!
+  const derived = (name: string): ChatEvent.MessageCreated => {
+    const raw = step("human", `human-${name}-get-message`).response
+    const channelType = step("human", `human-${name}-get-channel`).response.type
+    const result = DiscordChat.normalize({ t: "MESSAGE_CREATE", d: raw }, { ...context, channelType })
+    assert(Result.isSuccess(result) && result.success.length === 1)
+    const event = result.success[0]
+    assert(event._tag === "MessageCreated")
+    assert.strictEqual(event.message.author.id, tim)
+    assert.isFalse(event.message.author.isBot)
+    assert.isFalse(event.message.author.isSelf)
+    return event
   }
-  const mention = step("human", "human-mention-get-message").response
-  const dm = step("human", "human-dm-get-message").response
-  const derived = (raw: any): Dispatch => ({ t: "MESSAGE_CREATE", d: raw })
 
   it.effect("a typed mention of the bot in a guild channel", () =>
     Effect.gen(function*() {
-      assert.strictEqual(mention.content, `<@${botUserId}> hello`)
-      assert.deepStrictEqual(mention.mentions.map((user: any) => user.id), [botUserId])
-      const found = read(mention)
-      assert.strictEqual(found.author.id, tim)
-      assert.isFalse(found.author.isBot)
-      assert.isFalse(found.author.isSelf)
-      assert.deepStrictEqual(found.thread, DiscordChat.thread(test))
-      assert.deepStrictEqual(found.mentions, [{
+      const event = derived("mention")
+      assert.strictEqual(event.message.text, `<@${botUserId}> hello`)
+      assert.strictEqual(event.kind, "channel")
+      assert.deepStrictEqual(event.thread, DiscordChat.thread(test))
+      assert.deepStrictEqual(event.message.mentions, [{
         kind: "user",
         id: botUserId,
         start: 0,
         end: botUserId.length + 3,
         isSelf: true
       }])
-      yield* checkMessage(found, checkOptions)
-      // Derived dispatch: the REST body alone has no channel type.
-      assert(Result.isFailure(DiscordChat.normalize(derived(mention), context)))
-      const channelType = step("human", "human-mention-get-channel").response.type
-      assert.strictEqual(channelType, 0)
-      const result = DiscordChat.normalize(derived(mention), { ...context, channelType })
-      assert(Result.isSuccess(result))
-      const event = result.success[0]
-      assert(event._tag === "MessageCreated")
-      assert.strictEqual(event.kind, "channel")
-      assert.deepStrictEqual(event.message.mentions, found.mentions)
       yield* checkEvent(event, checkOptions)
     }))
 
   it.effect("a DM to the bot", () =>
     Effect.gen(function*() {
-      assert.strictEqual(dm.content, "hello DM")
-      const found = read(dm)
-      assert.strictEqual(found.author.id, tim)
-      assert.isFalse(found.author.isBot)
-      assert.isFalse(found.author.isSelf)
-      assert.deepStrictEqual(found.mentions, [])
-      yield* checkMessage(found, checkOptions)
-      const channelType = step("human", "human-dm-get-channel").response.type
-      assert.strictEqual(channelType, 1)
-      const result = DiscordChat.normalize(derived(dm), { ...context, channelType })
-      assert(Result.isSuccess(result))
-      const event = result.success[0]
-      assert(event._tag === "MessageCreated")
+      const event = derived("dm")
+      assert.strictEqual(event.message.text, "hello DM")
       assert.strictEqual(event.kind, "direct")
+      assert.deepStrictEqual(event.message.mentions, [])
       assert.isTrue(Option.isNone(DiscordChat.guildId(event)))
       assert.isTrue(Option.isNone(DiscordChat.member(event)))
       yield* checkEvent(event, checkOptions)
@@ -393,86 +318,30 @@ describe("synthetic", () => {
       yield* checkEvent(event, checkOptions)
     }))
 
-  it.effect("slash command replies, immediate and deferred, and a context menu reply", () =>
+  it.effect("another bot's command reply and context menu reply are messages, and a MESSAGE_UPDATE is not delivered", () =>
     Effect.gen(function*() {
       const recordedReply = step("other-bots", "other-bot-command-reply").response
       const reply = (d: Record): Dispatch => ({
         t: "MESSAGE_CREATE",
         d: { ...recordedReply, guild_id: guild, channel_type: 0, ...d }
       })
-      const immediate = created(reply({}))
-      assert.isTrue(immediate.message.author.isBot)
-      assert.strictEqual(immediate.message.text, recordedReply.content)
-      // Deferred: empty with the LOADING flag. The text comes in a MESSAGE_UPDATE, which is not delivered.
-      const deferred = created(reply({ content: "", flags: 128 }))
-      assert.strictEqual(deferred.message.text, "")
-      assert.deepStrictEqual(normalize({ t: "MESSAGE_UPDATE", d: { ...recordedReply, flags: 0 } }), [])
+      const command = created(reply({}))
+      assert.isTrue(command.message.author.isBot)
+      assert.isFalse(command.message.author.isSelf)
+      assert.strictEqual(command.message.text, recordedReply.content)
       const contextMenu = created(reply({ type: 23 }))
       assert.isTrue(contextMenu.message.author.isBot)
-      for (const event of [immediate, deferred, contextMenu]) yield* checkEvent(event, checkOptions)
-    }))
-})
-
-describe("REST messages", () => {
-  const read = (raw: any) => {
-    const fields = decodeMessageFields(raw)
-    assert.isDefined(fields)
-    return message(raw, fields!, context)
-  }
-
-  it.effect("every recorded message passes checkMessage", () =>
-    Effect.gen(function*() {
-      let count = 0
-      for (const name of ["posts", "history", "other-bots", "reactions", "embeds", "human"]) {
-        for (const call of recorded(name)) {
-          if (call.status >= 300 || call.response === null) continue
-          const list = Array.isArray(call.response) ? call.response : [call.response]
-          for (const raw of list) {
-            if (typeof raw.author !== "object") continue
-            const found = read(raw)
-            if (found === undefined) continue
-            yield* checkMessage(found, checkOptions)
-            count++
-          }
-        }
-      }
-      assert.isAbove(count, 30)
+      assert.deepStrictEqual(normalize({ t: "MESSAGE_UPDATE", d: { ...recordedReply, flags: 0 } }), [])
+      for (const event of [command, contextMenu]) yield* checkEvent(event, checkOptions)
     }))
 
-  it("other bots' command replies are messages from a bot", () => {
-    for (
-      const name of ["other-bot-command-reply", "other-bot-command-reply-empty", "other-bot-command-reply-effect-bot"]
-    ) {
-      const raw = step("other-bots", name).response
-      assert.strictEqual(raw.type, 20)
-      const found = read(raw)!
-      assert.isTrue(found.author.isBot)
-      assert.isFalse(found.author.isSelf)
-      assert.isUndefined(found.replyTo)
-    }
-    // A reply with only an embed comes through with empty text.
-    assert.strictEqual(read(step("other-bots", "other-bot-command-reply-empty").response)!.text, "")
-    const reply = read(step("other-bots", "other-bot-reply").response)!
-    assert.strictEqual(reply.replyTo?.messageId, "1103552216398303272")
-    // A reply to someone else's message, or to one whose author Discord left out, is not one to the bot.
-    assert.notStrictEqual(reply.replyTo?.isSelf, true)
-    assert.strictEqual(reply.replyTo?.isSelf === undefined, reply.replyTo?.authorId === undefined)
-    assert.isFalse(ChatMessage.repliesToSelf(reply))
-  })
-
-  it("the thread starter placeholder is not a message", () => {
-    const history = step("history", "thread-history").response
-    const placeholder = history.find((raw: any) => raw.type === 21)
-    assert.isUndefined(read(placeholder))
-    // The opener it points at is addressed to the parent channel.
-    const opener = read(placeholder.referenced_message)!
-    assert.deepStrictEqual(opener.thread, ChatThread.make("discord", scratch))
-    assert.strictEqual(opener.id, step("history", "thread-start").response.id)
-  })
-
-  it("a forum's starter read through REST is addressed to the post", () => {
-    const starter = read(step("history", "forum-get-starter").response)!
-    assert.strictEqual(starter.thread.id, starter.id)
-    assert.notStrictEqual(starter.thread.id, forum)
+  it("a reply to another user's message does not reply to the bot", () => {
+    const reply = created({
+      t: "MESSAGE_CREATE",
+      d: { ...step("other-bots", "other-bot-reply").response, guild_id: guild, channel_type: 0 }
+    })
+    assert.strictEqual(reply.message.replyTo?.messageId, "1103552216398303272")
+    assert.notStrictEqual(reply.message.replyTo?.isSelf, true)
+    assert.isFalse(ChatMessage.repliesToSelf(reply.message))
   })
 })
diff --git a/packages/chat/discord/test/utils.ts b/packages/chat/discord/test/utils.ts
index 164244d5c00..c910dd2900b 100644
--- a/packages/chat/discord/test/utils.ts
+++ b/packages/chat/discord/test/utils.ts
@@ -15,7 +15,6 @@ export const botUserId = "1564742987727118426"
 export const tim = "449108784879763458"
 export const guild = "840178841540362250"
 export const scratch = "1570607253965246584"
-export const forum = "1570607255684915302"
 export const test = "1570605581192929301"
 export const role = "1570607256838479964"
 export const webhook = "1570607260156297307"
@@ -44,7 +43,6 @@ export interface RecordedCall {
   readonly response: any
 }
 
-/** The REST calls of a fixture in `fixtures/recorded`. */
 /**
  * The slash commands recorded in EFF-3802, `fixtures/recorded/commands.json`.
  * The built command payloads start from these.
@@ -53,7 +51,8 @@ export const recordedCommands: any = JSON.parse(
   fs.readFileSync(new URL("./fixtures/recorded/commands.json", import.meta.url), "utf8")
 )
 
-export const recorded = (name: string): ReadonlyArray =>
+/** The REST calls of a fixture in `fixtures/recorded`. */
+const recorded = (name: string): ReadonlyArray =>
   JSON.parse(fs.readFileSync(new URL(`./fixtures/recorded/${name}.json`, import.meta.url), "utf8")).calls
 
 /** The one recorded call for `step`. */
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 79aac9b9118..b1c7d23df58 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -1,7 +1,7 @@
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { SlackWebApi } from "@effect/chat-slack/SlackWebApi"
 import { assert, describe, it } from "@effect/vitest"
-import { type ChatErrorReason, fileRefused } from "effect/chat/ChatError"
+import { fileRefused } from "effect/chat/ChatError"
 import { checkMessage, conformance } from "effect/chat/ChatTest"
 import type { Action } from "effect/chat/ChatUi"
 import * as Duration from "effect/Duration"
@@ -87,15 +87,9 @@ describe("post", () => {
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const cases = [
-          "a".repeat(12_001),
-          // 3,001 `<` are 12,004 once escaped.
-          "<".repeat(3_001)
-        ]
-        for (const markdown of cases) {
-          const failure = yield* reason(slack.post(channelThread, { markdown }))
-          assert.strictEqual(failure.tag, "TooLarge")
-        }
+        // 3,001 `<` are 12,004 once escaped.
+        const failure = yield* reason(slack.post(channelThread, { markdown: "<".repeat(3_001) }))
+        assert.strictEqual(failure.tag, "TooLarge")
         assert.strictEqual(fake.calls.length, 0)
         // 12,000 astral letters fit.
         assert.strictEqual(slack.descriptor.measure("𝐀".repeat(12_000)), 12_000)
@@ -121,24 +115,6 @@ describe("post", () => {
     )
   })
 
-  it.effect("an edit's text is cut to 3,800 bytes and keeps its allowed tokens", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        yield* slack.edit(channelThread, "1.2", { markdown: "<@U1> " + "é".repeat(5_000) + " <@U2>" }).pipe(
-          SlackChat.withPostOptions({ notify: { users: ["U1", "U2"] } })
-        )
-        const params = fake.called("chat.update")[0].params
-        assert.strictEqual(JSON.parse(params.blocks)[0].text, "<@U1> " + "é".repeat(5_000) + " <@U2>")
-        assert.isTrue(params.text.startsWith("<@U1> éé"))
-        assert.isTrue(params.text.endsWith("é… <@U2>"))
-        assert.isAtMost(new TextEncoder().encode(params.text).length, 3_800)
-      })
-    )
-  })
-
   it.effect("leaves the emoji count to Slack", () => {
     const fake = makeFake({
       "chat.postMessage": [posted("1794509200.000100"), { ok: false, error: "msg_blocks_too_long" }]
@@ -159,19 +135,6 @@ describe("post", () => {
     )
   })
 
-  it.effect("edit skips the emoji limit", () => {
-    const fake = makeFake({ "chat.update": { ok: true } })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        yield* slack.edit(channelThread, "1794509200.000100", { markdown: "😀".repeat(1_400) })
-        assert.strictEqual(fake.called("chat.update")[0].params.ts, "1794509200.000100")
-        assert.isUndefined(fake.called("chat.update")[0].params.unfurl_links)
-      })
-    )
-  })
-
   it.effect("replyTo is unsupported", () =>
     run(
       makeFake({}),
@@ -345,22 +308,6 @@ describe("files", () => {
     )
   })
 
-  it.effect("a post with files and buttons carries the actions block on the post and the attach", () => {
-    const fake = makeFake({ ...upload(["F1"]), "chat.postMessage": posted(ts) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const actions = [{ _tag: "Button", id: "go", label: "Go" }] as const
-        yield* slack.post(channelThread, { markdown: "", files: [file("a.txt")], actions })
-        const post = fake.called("chat.postMessage")[0].params
-        assert.deepStrictEqual(JSON.parse(post.blocks).map((block: any) => block.type), ["markdown", "actions"])
-        assert.strictEqual(post.text, "a.txt")
-        assert.strictEqual(fake.called("chat.update")[0].params.blocks, post.blocks)
-      })
-    )
-  })
-
   it.effect("too many files fail file_refused before any call", () => {
     const fake = makeFake({})
     return run(
@@ -379,26 +326,6 @@ describe("files", () => {
     )
   })
 
-  it.effect("a file refused at the complete call posts nothing", () => {
-    const fake = makeFake({
-      ...upload(["F1"]),
-      "files.completeUploadExternal": { ok: false, error: "invalid_arguments" }
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const error = yield* Effect.flip(slack.post(channelThread, { markdown: "x", files: [file("a.txt")] }))
-        assert.strictEqual(error.reason._tag, "InvalidRequest")
-        assert.strictEqual(error.reason.detail, fileRefused)
-        assert.strictEqual(error.retry, "denied")
-        // Slack's code stays on the cause.
-        assert.strictEqual((error.reason.cause as ChatErrorReason).detail, "invalid_arguments")
-        assert.strictEqual(fake.called("chat.postMessage").length, 0)
-      })
-    )
-  })
-
   it.effect("a failed post removes the uploads", () => {
     const fake = makeFake({ ...upload(["F1", "F2"]), "chat.postMessage": { ok: false, error: "not_in_channel" } })
     return run(
@@ -413,21 +340,6 @@ describe("files", () => {
     )
   })
 
-  it.effect("an attach that times out is retried", () => {
-    const fake = makeFake({ ...upload(["F1"]), "chat.postMessage": posted(ts), "chat.update": [hang, { ok: true }] })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const fiber = yield* Effect.forkChild(slack.post(channelThread, { markdown: "x", files: [file("a")] }))
-        yield* TestClock.adjust("31 seconds")
-        assert.strictEqual((yield* Fiber.join(fiber)).id, ts)
-        assert.strictEqual(fake.called("chat.update").length, 2)
-        assert.strictEqual(fake.called("chat.delete").length, 0)
-      })
-    )
-  })
-
   it.effect("a long Retry-After on the attach is cut off by its deadline and rolled back, even when interrupted", () => {
     const fake = makeFake({
       ...upload(["F1"]),
@@ -590,14 +502,6 @@ describe("reads", () => {
         yield* checkMessage(message, checkOptions)
         assert.deepStrictEqual(message.thread, channelThread)
         assert.strictEqual(message.mentions.length, 2)
-        assert.deepStrictEqual(fake.called("conversations.replies")[0].params, {
-          channel,
-          ts: "1794509003.143939",
-          latest: "1794509003.143939",
-          oldest: "1794509003.143939",
-          inclusive: "true",
-          limit: "2"
-        })
       })
     )
   })
@@ -982,26 +886,6 @@ describe("nativeStream", () => {
       )
     })
 
-    it.effect("runs for a message with an allowed token, which stays in text", () => {
-      const fake = makeFake({ "chat.startStream": posted(ts) })
-      return run(
-        fake,
-        Effect.gen(function*() {
-          const native = (yield* adapter).nativeStream!
-          const allowed = SlackChat.withPostOptions({ notify: { users: ["U1"] } })
-          yield* native.start(replyThread, { markdown: "<@U1> <@U2>", recipient }).pipe(allowed)
-          assert.strictEqual(fake.called("chat.startStream")[0].params.markdown_text, `<@U1> <${z}@U2>`)
-          assert.strictEqual(
-            yield* cleanupOf(native.stop(replyThread, ts, { end: "rotating" }).pipe(allowed)),
-            "edited"
-          )
-          const [update] = updates(fake)
-          assert.deepStrictEqual(update.blocks, [{ type: "markdown", text: "<@U1> <@U2>" }])
-          assert.strictEqual(update.text, "<@U1> &lt;@U2>")
-        })
-      )
-    })
-
     it.effect("is not sent when the appends match the block", () => {
       const fake = makeFake({ "chat.startStream": posted(ts) })
       return run(
@@ -1020,20 +904,6 @@ describe("nativeStream", () => {
       )
     })
 
-    it.effect("is skipped when the block would pass 12,000", () => {
-      const fake = makeFake({ "chat.startStream": posted(ts) })
-      return run(
-        fake,
-        Effect.gen(function*() {
-          const native = (yield* adapter).nativeStream!
-          // 7 code points each as streamed, 9 in the block: 10,500 against 13,500.
-          yield* native.start(replyThread, { markdown: "<@U2> ".repeat(1_500), recipient })
-          assert.strictEqual(yield* cleanupOf(native.stop(replyThread, ts, { end: "done" })), "too_long")
-          assert.strictEqual(fake.called("chat.update").length, 0)
-        })
-      )
-    })
-
     it.effect("is skipped when the edit fails, and the stop still succeeds", () => {
       const fake = makeFake({
         "chat.startStream": posted(ts),
@@ -1055,29 +925,6 @@ describe("nativeStream", () => {
       )
     })
 
-    it.effect("leaves a part the repair path rewrites to the repair edit", () => {
-      const fake = makeFake({
-        "chat.startStream": posted(ts),
-        "chat.appendStream": { status: 500 },
-        "chat.update": posted(ts)
-      })
-      return run(
-        fake,
-        Effect.gen(function*() {
-          const slack = yield* adapter
-          const native = slack.nativeStream!
-          yield* native.start(replyThread, { markdown: "a <@U2>", recipient })
-          const failed = yield* reason(native.append(replyThread, ts, " b", undefined))
-          assert.strictEqual(failed.retry, "uncertain")
-          // The layer's repair: stop, then edit the part to its whole known text.
-          assert.strictEqual(yield* cleanupOf(native.stop(replyThread, ts, { end: "rotating" })), "unsettled")
-          yield* slack.edit(replyThread, ts, { markdown: "a <@U2> b" })
-          assert.strictEqual(fake.called("chat.update").length, 1)
-          assert.strictEqual(fake.called("chat.update")[0].params.text, "a <@U2> b")
-        })
-      )
-    })
-
     it.effect("runs again on a stop sent after one interrupted during it", () => {
       const fake = makeFake({
         "chat.startStream": posted(ts),
diff --git a/packages/chat/slack/test/actions.test.ts b/packages/chat/slack/test/actions.test.ts
index 96a187f38fb..4fdfdbe92f8 100644
--- a/packages/chat/slack/test/actions.test.ts
+++ b/packages/chat/slack/test/actions.test.ts
@@ -3,7 +3,7 @@
  * `actions` block's elements as posted, and what the 13,200 cap charged for
  * it, found by bisecting the text beside it.
  */
-import { cost, type Element, labelCost, option, stringCost } from "@effect/chat-slack/internal/actions"
+import { cost, type Element, option } from "@effect/chat-slack/internal/actions"
 import { assert, describe, it } from "@effect/vitest"
 
 const opts = (n: number, label = (i: number) => "Option " + i, value = (i: number) => "o" + i) =>
@@ -88,15 +88,4 @@ describe("actionsCost", () => {
       if (ascii) assert.isAtMost(charge, charged + 5, name)
     }
   })
-
-  it("charges each string as JSON writes it", () => {
-    assert.strictEqual(cost([]), 0)
-    assert.strictEqual(stringCost("a/\"\\é\u{1D400}\n"), 1 + 2 + 2 + 2 + 6 + 12 + 6)
-    // Entities in a label, and an emoji at the greater of its name and its escaped form.
-    assert.strictEqual(labelCost("<>&"), 13)
-    assert.strictEqual(labelCost("\u{1F644}"), ":face_with_rolling_eyes:".length)
-    assert.strictEqual(labelCost("\u{1F600}"), 12)
-    // A 75-character Japanese label.
-    assert.strictEqual(labelCost("日".repeat(75)), 450)
-  })
 })
diff --git a/packages/chat/slack/test/commands.test.ts b/packages/chat/slack/test/commands.test.ts
index ffa9c16ad4f..699a2c3edf9 100644
--- a/packages/chat/slack/test/commands.test.ts
+++ b/packages/chat/slack/test/commands.test.ts
@@ -153,20 +153,6 @@ describe("recorded slash commands", () => {
     assert.isFalse((publicClick.raw as any).container.is_ephemeral)
   })
 
-  it.effect("fails Chat.edit NotFound on a private answer's messageId, as Slack answered chat.update", () =>
-    Effect.gen(function*() {
-      const click = normalize(recorded.clicks.privateAnswer) as ChatInteraction.ButtonClicked
-      const fake = makeFake({ "auth.test": authTest, "chat.update": { ok: false, error: "message_not_found" } })
-      const error = yield* Effect.flip(
-        Effect.flatMap(Chat.Chat, (chat) => chat.edit(click.thread, click.messageId, { markdown: "Edited" })).pipe(
-          Effect.provide(slackLayer(fake))
-        )
-      )
-      assert.deepStrictEqual([error.op, error.reason._tag], ["edit", "NotFound"])
-      const [{ params }] = fake.called("chat.update")
-      assert.deepStrictEqual([params.channel, params.ts], [channel, recorded.clicks.privateAnswer.container.message_ts])
-    }))
-
   it.effect("follows up with the body Slack rendered, and maps a spent and an expired response_url", () =>
     Effect.gen(function*() {
       const command = normalize(recorded.commands.defer) as ChatInteraction.CommandInvoked
@@ -191,8 +177,7 @@ describe("recorded slash commands", () => {
       assert.strictEqual(url, new URL((command.raw as any).response_url).href)
       assert.deepStrictEqual(body, recorded.responseUrl.followUp.request)
 
-      const answers = [recorded.responseUrl.spent.response, ...recorded.responseUrl.expired.responses]
-      for (const answer of answers) {
+      for (const answer of [recorded.responseUrl.spent.response, recorded.responseUrl.expired.responses[0]]) {
         const error = yield* Effect.flip(followUp(answer).sent)
         assert.deepStrictEqual([error.op, error.reason._tag, error.reason.detail, (error.reason as any).cause], [
           "followUp",
@@ -201,11 +186,5 @@ describe("recorded slash commands", () => {
           answer.body
         ])
       }
-      assert.deepStrictEqual(answers.map((answer) => [answer.status, answer.body]), [
-        [404, "used_url"],
-        [404, "expired_url"],
-        [404, "expired_url"],
-        [404, "expired_url"]
-      ])
     }))
 })
diff --git a/packages/chat/slack/test/emoji.test.ts b/packages/chat/slack/test/emoji.test.ts
index 7da68ae64bd..30fd7ba9e6e 100644
--- a/packages/chat/slack/test/emoji.test.ts
+++ b/packages/chat/slack/test/emoji.test.ts
@@ -48,37 +48,8 @@ const sequences: ReadonlyArray = rows.fl
 )
 
 describe("emoji", () => {
-  it("holds every emoji, name and skin tone variation from emoji-data v16.0.0", () => {
-    assert.strictEqual(emojiData.split("\n").length, 1911)
-    assert.strictEqual(rows.reduce((total, row) => total + row.names.length, 0), 1972)
-    assert.strictEqual(rows.filter((row) => row.names.length === 0).length, 1875)
-    assert.strictEqual(sequences.length, 4946)
-    assert.strictEqual(new Set(sequences.map(([emoji]) => emoji)).size, sequences.length)
-  })
-
   describe("fromName", () => {
-    it("resolves every alias", () => {
-      assert.strictEqual(fromName("+1"), "👍")
-      assert.strictEqual(fromName("thumbsup"), "👍")
-    })
-
-    it("accepts surrounding colons", () => {
-      assert.strictEqual(fromName(":+1:"), "👍")
-      assert.strictEqual(fromName(":+1::skin-tone-3:"), "👍🏼")
-    })
-
-    it("returns the fully qualified emoji", () => {
-      assert.strictEqual(fromName("heart"), "❤️")
-    })
-
-    it("looks skin tones up in skin_variations", () => {
-      assert.strictEqual(fromName("+1::skin-tone-3"), "👍🏼")
-      assert.strictEqual(fromName("woman-running::skin-tone-6"), "🏃🏿‍♀️")
-    })
-
-    it("gives none for a name with two tones, which no recording shows", () => {
-      assert.strictEqual(fromName("people_holding_hands::skin-tone-2::skin-tone-5"), undefined)
-      assert.strictEqual(fromName("handshake::skin-tone-2::skin-tone-5"), undefined)
+    it("gives none for a name with two tones, which no recording shows, even the same tone twice", () => {
       assert.strictEqual(fromName("handshake::skin-tone-3::skin-tone-3"), undefined)
     })
 
@@ -98,40 +69,16 @@ describe("emoji", () => {
 
     it("returns undefined for unknown names and tones", () => {
       assert.strictEqual(fromName("not_an_emoji"), undefined)
-      assert.strictEqual(fromName(""), undefined)
-      assert.strictEqual(fromName("::"), undefined)
       assert.strictEqual(fromName(":+1"), undefined)
       assert.strictEqual(fromName("grinning::skin-tone-3"), undefined)
       assert.strictEqual(fromName("+1::skin-tone-1"), undefined)
-      assert.strictEqual(fromName("+1::skin-tone-7"), undefined)
-      assert.strictEqual(fromName("+1::skin-tone-2::skin-tone-3"), undefined)
       assert.strictEqual(fromName("handshake::skin-tone-2::skin-tone-3::skin-tone-4"), undefined)
       assert.strictEqual(fromName("+1::thumbsup"), undefined)
     })
   })
 
   describe("toName", () => {
-    it("returns the primary short name", () => {
-      assert.strictEqual(toName("👍"), "+1")
-      assert.strictEqual(toName("😀"), "grinning")
-      assert.strictEqual(toName("🧑‍🤝‍🧑"), "people_holding_hands")
-    })
-
-    it("matches emoji with and without U+FE0F", () => {
-      assert.strictEqual(toName("❤\uFE0F"), "heart")
-      assert.strictEqual(toName("❤"), "heart")
-    })
-
-    it("names toned emoji with skin-tone suffixes", () => {
-      assert.strictEqual(toName("👍🏼"), "+1::skin-tone-3")
-      assert.strictEqual(toName("🏃🏿‍♀️"), "woman-running::skin-tone-6")
-      assert.strictEqual(toName("🏃🏿‍♀"), "woman-running::skin-tone-6")
-      assert.strictEqual(toName("🧑🏻‍🤝‍🧑🏾"), "people_holding_hands::skin-tone-2::skin-tone-5")
-      assert.strictEqual(toName("🫱🏻‍🫲🏾"), "handshake::skin-tone-2::skin-tone-5")
-    })
-
     it("returns undefined for anything that is not exactly one emoji", () => {
-      assert.strictEqual(toName(""), undefined)
       assert.strictEqual(toName("a"), undefined)
       assert.strictEqual(toName("👍👍"), undefined)
       assert.strictEqual(toName("👍 "), undefined)
@@ -142,56 +89,15 @@ describe("emoji", () => {
         assert.strictEqual(toName(emoji), name)
       }
     })
-
-    it("round trips with fromName for every emoji with at most one tone", () => {
-      for (const row of rows) {
-        if (row.tones > 1) continue
-        assert.strictEqual(fromName(toName(row.emoji)!), row.emoji, row.name)
-      }
-    })
   })
 
   describe("blocksCost", () => {
-    it("counts code points of plain text", () => {
-      assert.strictEqual(blocksCost(""), 0)
-      assert.strictEqual(blocksCost("abc"), 3)
-      assert.strictEqual(blocksCost("é日本"), 3)
-      assert.strictEqual(blocksCost("𝒜"), 1)
-    })
-
-    it("counts emoji as their :short_name: form", () => {
-      assert.strictEqual(blocksCost("😀"), 10)
-      assert.strictEqual(blocksCost("a😀"), 11)
-      assert.strictEqual(blocksCost("👍"), 4)
-      assert.strictEqual(blocksCost("👍🏽"), 17)
-      assert.strictEqual(blocksCost("🧑‍🤝‍🧑"), 22)
-      assert.strictEqual(blocksCost("❤"), 7)
-      assert.strictEqual(blocksCost("❤️"), 7)
-      assert.strictEqual(blocksCost("🇺🇸"), 4)
-      assert.strictEqual(blocksCost("#️⃣"), 6)
-      assert.strictEqual(blocksCost("hi 👍🏽!"), 3 + 17 + 1)
-    })
-
     it("costs every emoji in the table exactly as its :short_name:", () => {
       for (const [emoji, name] of sequences) {
         assert.strictEqual(blocksCost(emoji), name.length + 2, name)
       }
     })
 
-    it("charges stray emoji components enough to stay subadditive", () => {
-      assert.strictEqual(blocksCost("1"), 1)
-      assert.strictEqual(blocksCost("1\u20E3"), 5)
-      assert.isAtLeast(blocksCost("1") + blocksCost("\u20E3"), 5)
-      assert.isAtLeast(blocksCost("🇺") + blocksCost("🇸"), blocksCost("🇺🇸"))
-      assert.isAtLeast(blocksCost("🏃") + blocksCost("\u200D➡️"), blocksCost("🏃‍➡️"))
-      assert.isAtLeast(blocksCost("\uD83D") + blocksCost("\uDE00"), blocksCost("😀"))
-      // Slack charges a lone hair component 1. At 3 or less, 🧑‍🦱 would split
-      // for less than :curly_haired_person:.
-      assert.strictEqual(blocksCost("\u{1F9B1}"), 4)
-      assert.strictEqual(blocksCost("🧑‍🦱"), ":curly_haired_person:".length)
-      assert.isBelow(blocksCost("🧑") + blocksCost("\u200D") + 3, blocksCost("🧑‍🦱"))
-    })
-
     it("is subadditive", () => {
       const emoji = sequences.map(([sequence]) => sequence)
       const extras = [
@@ -233,10 +139,5 @@ describe("emoji", () => {
         assert.isAtMost(blocksCost(text), blocksCost(a) + blocksCost(b), JSON.stringify([a, b]))
       }
     })
-
-    it("measures long text", () => {
-      const text = "hello 👍🏽 world 🧑‍🤝‍🧑 #️⃣ 🇺🇸 ".repeat(2_000)
-      assert.strictEqual(blocksCost(text), 2_000 * (6 + 17 + 7 + 22 + 1 + 6 + 1 + 4 + 1))
-    })
   })
 })
diff --git a/packages/chat/slack/test/escape.test.ts b/packages/chat/slack/test/escape.test.ts
index f71e5f9f3bc..77e7a378d79 100644
--- a/packages/chat/slack/test/escape.test.ts
+++ b/packages/chat/slack/test/escape.test.ts
@@ -111,18 +111,13 @@ describe("escapeStream", () => {
     const notify = { users: ["U1"] }
     const cases: ReadonlyArray = [
       ["a <", "a "],
-      ["a  {
     Effect.gen(function*() {
       for (const name of cases) {
         for (const delivery of captured(name)) {
-          assert.strictEqual(delivery.headers["content-type"], "application/json")
-          assert.isUndefined(delivery.headers["x-slack-signature"])
-          assert.isUndefined(delivery.headers["x-slack-retry-num"])
           const events = yield* deliver(delivery)
           assert.deepStrictEqual(events, SlackChat.normalize(JSON.parse(delivery.body), context), name)
           for (const event of events) yield* checkEvent(event, checkOptions)
@@ -130,20 +127,6 @@ describe("captured Events API deliveries", () => {
       assert.deepStrictEqual(mentions(event), selfMention())
     }))
 
-  it.live("an edit gives nothing, whether it keeps, adds or removes the mention", () =>
-    Effect.gen(function*() {
-      const expected: Record> = {
-        "edit-keeps-mention": selfMention(),
-        "edit-adds-mention": [],
-        "edit-removes-mention": selfMention()
-      }
-      for (const [name, before] of Object.entries(expected)) {
-        const [original, edit] = yield* deliveries(name)
-        assert.deepStrictEqual(mentions(created(original)), before, name)
-        assert.deepStrictEqual(edit, [], name)
-      }
-    }))
-
   it.live("a mention only in code, a Block Kit section or an attachment is not reported", () =>
     Effect.gen(function*() {
       for (const name of ["code-only-mention", "block-kit-mention", "attachment-mention"]) {
@@ -158,34 +141,6 @@ describe("captured Events API deliveries", () => {
       assert.deepStrictEqual(mentions(event), selfMention())
     }))
 
-  it.live("a file share with a mention in its comment", () =>
-    Effect.gen(function*() {
-      const event = created((yield* deliveries("file-mention"))[0])
-      assert.deepStrictEqual(mentions(event), selfMention())
-      assert.deepStrictEqual(
-        event.message.attachments.map(({ contentType, name, size }) => ({ contentType, name, size })),
-        [{ name: "fixture.txt", contentType: "text/plain", size: 13 }]
-      )
-    }))
-
-  it.live("reactions by name, with Slack's primary names and a skin tone", () =>
-    Effect.gen(function*() {
-      const [message, ...reactions] = yield* deliveries("reactions")
-      const id = created(message).message.id
-      assert.deepStrictEqual(
-        reactions.map((events) => {
-          assert.strictEqual(events.length, 1)
-          const event = events[0]
-          assert(event._tag === "ReactionAdded" || event._tag === "ReactionRemoved")
-          assert.strictEqual(event.messageId, id)
-          return [event._tag, event.emoji]
-        }),
-        [["ReactionAdded", "👍"], ["ReactionAdded", "👍🏽"], ["ReactionAdded", "😀"], ["ReactionRemoved", "😀"]]
-      )
-      // An add and its removal are different events.
-      assert.notStrictEqual(dedupeKey(reactions[2][0]), dedupeKey(reactions[3][0]))
-    }))
-
   it.live("a native stream arrives as an empty message from the bot, its text only as message_changed", () =>
     Effect.gen(function*() {
       const [start, changed] = yield* deliveries("native-stream")
@@ -194,16 +149,6 @@ describe("captured Events API deliveries", () => {
       assert.isTrue(event.message.author.isSelf)
       assert.deepStrictEqual(changed, [])
     }))
-
-  it.live("Slack sent app_mention only for messages from a person", () =>
-    Effect.sync(() => {
-      for (const name of cases) {
-        for (const delivery of captured(name)) {
-          const event = JSON.parse(delivery.body).event
-          if (event.type === "app_mention") assert.strictEqual(event.user, person, name)
-        }
-      }
-    }))
 })
 
 const person = "U080YLYB277"
@@ -257,24 +202,6 @@ describe("captured deliveries for messages a person typed", () => {
       ])
     }))
 
-  it.live("a plain message has no mention, and its later message_changed gives nothing", () =>
-    Effect.gen(function*() {
-      const [message, changed] = yield* deliveries("human-plain")
-      const event = created(message)
-      assert.strictEqual(event.message.author.id, person)
-      assert.isFalse(event.message.author.isSelf)
-      assert.isFalse(event.message.author.isBot)
-      assert.deepStrictEqual(event.message.mentions, [])
-      assert.deepStrictEqual(changed, [])
-    }))
-
-  it.live("a thread root's message_changed after its first reply gives nothing", () =>
-    Effect.gen(function*() {
-      const [message, mention, changed] = yield* deliveries("human-mention")
-      assert.strictEqual(created(message).message.id, created(mention).message.id)
-      assert.deepStrictEqual(changed, [])
-    }))
-
   it.live("an edit gives nothing, including the app_mention Slack sends when it adds a mention", () =>
     Effect.gen(function*() {
       const [original, changed, mention] = yield* deliveries("human-edit-adds-mention")
@@ -289,27 +216,6 @@ describe("captured deliveries for messages a person typed", () => {
       assert.deepStrictEqual(keptRoot, [])
     }))
 
-  it.live("a literal @name in code is no mention", () =>
-    Effect.gen(function*() {
-      const [events] = yield* deliveries("human-code-mention")
-      assert.deepStrictEqual(created(events).message.mentions, [])
-    }))
-
-  it.live("a file share keeps its file, and its later message_changed gives nothing", () =>
-    Effect.gen(function*() {
-      const [message, , changed] = yield* deliveries("human-file-mention")
-      assert.deepStrictEqual(created(message).message.attachments.map(({ name }) => name), ["T3.svg"])
-      assert.deepStrictEqual(changed, [])
-    }))
-
-  it.live("a thread_broadcast belongs to the thread it was sent in", () =>
-    Effect.gen(function*() {
-      const root = created((yield* deliveries("human-plain"))[0]).message.id
-      const [message, changed] = yield* deliveries("human-thread-broadcast")
-      assert.deepStrictEqual(partsOf(created(message).thread), { team, channel, threadTs: root })
-      assert.deepStrictEqual(changed, [])
-    }))
-
   it.live("reactions, with a skin tone and a custom emoji", () =>
     Effect.gen(function*() {
       const root = created((yield* deliveries("human-plain"))[0]).message.id
@@ -361,14 +267,4 @@ describe("captured deliveries for the bot's replies and stops", () => {
       // Each click is its own request.
       assert.strictEqual(new Set(stops.map(dedupeKey)).size, 3)
     }))
-
-  it.live("a click on Stop with no stream open sends an empty streaming_message_ts", () =>
-    Effect.gen(function*() {
-      const bodies = captured("stop-no-stream").map((delivery) => JSON.parse(delivery.body).event)
-      const stops = bodies.filter((event) => event.type === "agent_session_stopped")
-      assert.deepStrictEqual(stops.map((event) => event.streaming_message_ts), [[], [], []])
-      const events = (yield* deliveries("stop-no-stream")).flat().filter((event) => event._tag === "StopRequested")
-      assert.deepStrictEqual(events.map((event) => event.messageIds), [[], [], []])
-      assert.strictEqual(new Set(events.map(dedupeKey)).size, 3)
-    }))
 })
diff --git a/packages/chat/slack/test/fixtures/events/edit-adds-mention.json b/packages/chat/slack/test/fixtures/events/edit-adds-mention.json
deleted file mode 100644
index 9d38f3b7f22..00000000000
--- a/packages/chat/slack/test/fixtures/events/edit-adds-mention.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
-  "case": "A message without a mention, edited to add one",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
-    "recordedAt": "2026-11-12T20:54:52.189Z",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "actions": [
-    {
-      "action": "chat.postMessage",
-      "ts": "1794516871.790219",
-      "request": {
-        "markdown_text": "no mention yet [EFF-3694 20:54:24]"
-      }
-    },
-    {
-      "action": "chat.update",
-      "ts": "1794516871.790219"
-    }
-  ],
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T20:54:32.569Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516871",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516871.790219\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"no mention yet [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"etv+WF\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"no mention yet [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516871.790219\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ4FCQJRE\",\"event_time\":1794516871,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:33.275Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516873",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516873.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"now <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"0rFf2G\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"now \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"ts\":\"1794516871.790219\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516871.790219\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"no mention yet [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"etv+WF\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"no mention yet [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516873.058800\",\"event_ts\":\"1794516873.058800\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGUNP1P5M\",\"event_time\":1794516873,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/edit-keeps-mention.json b/packages/chat/slack/test/fixtures/events/edit-keeps-mention.json
deleted file mode 100644
index 83ad2bcabf1..00000000000
--- a/packages/chat/slack/test/fixtures/events/edit-keeps-mention.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
-  "case": "A message that mentions the bot, edited with the mention kept",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
-    "recordedAt": "2026-11-12T20:54:52.189Z",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "actions": [
-    {
-      "action": "chat.postMessage",
-      "ts": "1794516869.259869",
-      "request": {
-        "markdown_text": "before <@U0CCLMD4S1L> [EFF-3694 20:54:24]"
-      }
-    },
-    {
-      "action": "chat.update",
-      "ts": "1794516869.259869"
-    }
-  ],
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T20:54:29.537Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516869",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516869.259869\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"before <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"okdLho\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"before \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516869.259869\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85C00T0\",\"event_time\":1794516869,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:32.095Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516870",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516870.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"after <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"q8h6hJ\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"after \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"ts\":\"1794516869.259869\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516869.259869\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"before <@U0CCLMD4S1L> [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"okdLho\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"before \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516870.058700\",\"event_ts\":\"1794516870.058700\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGUNNSSH5\",\"event_time\":1794516870,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/edit-removes-mention.json b/packages/chat/slack/test/fixtures/events/edit-removes-mention.json
deleted file mode 100644
index 615678ae815..00000000000
--- a/packages/chat/slack/test/fixtures/events/edit-removes-mention.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
-  "case": "A message that mentions the bot, edited to remove the mention",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
-    "recordedAt": "2026-11-12T20:54:52.189Z",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "actions": [
-    {
-      "action": "chat.postMessage",
-      "ts": "1794516874.327439",
-      "request": {
-        "markdown_text": "mention <@U0CCLMD4S1L> for now [EFF-3694 20:54:24]"
-      }
-    },
-    {
-      "action": "chat.update",
-      "ts": "1794516874.327439"
-    }
-  ],
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T20:54:35.045Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516874",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516874.327439\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"mention <@U0CCLMD4S1L> for now [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"7BKEu+\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"mention \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" for now [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516874.327439\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH4R5T1MK\",\"event_time\":1794516874,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:35.784Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516875",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516875.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"mention removed [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"7RC4kt\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"mention removed [EFF-3694 20:54:24]\"}]}]}],\"ts\":\"1794516874.327439\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516874.327439\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"mention <@U0CCLMD4S1L> for now [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"7BKEu+\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"mention \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" for now [EFF-3694 20:54:24]\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516875.058900\",\"event_ts\":\"1794516875.058900\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9UAP7KL\",\"event_time\":1794516875,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/file-mention.json b/packages/chat/slack/test/fixtures/events/file-mention.json
deleted file mode 100644
index 0387952b91b..00000000000
--- a/packages/chat/slack/test/fixtures/events/file-mention.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
-  "case": "A file upload whose comment mentions the bot",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
-    "recordedAt": "2026-11-12T20:54:52.189Z",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "actions": [
-    {
-      "action": "files.completeUploadExternal",
-      "ts": "1794516902.053009",
-      "file": "F0CJ4FGJTPS"
-    }
-  ],
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T20:55:02.572Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516902",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"text\":\"file for <@U0CCLMD4S1L> [EFF-3694 20:55:01]\",\"files\":[{\"id\":\"F0CJ4FGJTPS\",\"created\":1794516901,\"timestamp\":1794516901,\"mimetype\":\"text\\/plain\",\"filetype\":\"text\",\"pretty_type\":\"Plain Text\",\"user\":\"U0CCLMD4S1L\",\"user_team\":\"T05479Z6JBW\",\"editable\":true,\"size\":13,\"mode\":\"snippet\",\"is_external\":false,\"external_type\":\"\",\"is_public\":false,\"public_url_shared\":false,\"display_as_bot\":false,\"username\":\"\",\"name\":\"fixture.txt\",\"title\":\"fixture.txt\",\"is_modified_by_ai\":false,\"url_private\":\"https:\\/\\/scrubbed.invalid\\/url_private\",\"url_private_download\":\"https:\\/\\/scrubbed.invalid\\/url_private_download\",\"permalink\":\"https:\\/\\/scrubbed.invalid\\/permalink\",\"permalink_public\":\"https:\\/\\/scrubbed.invalid\\/permalink_public\",\"edit_link\":\"https:\\/\\/scrubbed.invalid\\/edit_link\",\"preview\":\"fixture file\\n\",\"preview_highlight\":\"
\\n
\\n
fixture file<\\/pre><\\/div>\\n
<\\/pre><\\/div>\\n<\\/div>\\n<\\/div>\\n\",\"lines\":2,\"lines_more\":0,\"preview_is_truncated\":false,\"skipped_shares\":true,\"has_rich_preview\":false,\"file_access\":\"visible\"}],\"upload\":true,\"user\":\"U0CCLMD4S1L\",\"display_as_bot\":false,\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"h2N+\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"file for \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:55:01]\"}]}]}],\"ts\":\"1794516902.053009\",\"bot_id\":\"B0CCQH77VA5\",\"channel\":\"C0CH1LGJ4F3\",\"subtype\":\"file_share\",\"event_ts\":\"1794516902.053009\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T4TU1H\",\"event_time\":1794516902,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "edit_link",
-        "permalink",
-        "permalink_public",
-        "url_private",
-        "url_private_download"
-      ]
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/human-code-mention.json b/packages/chat/slack/test/fixtures/events/human-code-mention.json
deleted file mode 100644
index d80c7660391..00000000000
--- a/packages/chat/slack/test/fixtures/events/human-code-mention.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
-  "case": "H6: a literal @janitor inside inline code. Slack made no mention of it, so no app_mention came",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "Tim Smart (U080YLYB277), typing in the Slack client",
-    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T23:28:12.537Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794526092",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U080YLYB277\",\"ts\":\"1794526092.227099\",\"client_msg_id\":\"a0386042-19ac-4815-b509-faf89f434a6b\",\"text\":\"H6 `@janitor` \",\"team\":\"T05479Z6JBW\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"gCKmr\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"H6 \"},{\"type\":\"text\",\"text\":\"@janitor \",\"style\":{\"code\":true}}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526092.227099\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW1RRRD5\",\"event_time\":1794526092,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/reactions.json b/packages/chat/slack/test/fixtures/events/reactions.json
deleted file mode 100644
index af50500c7e0..00000000000
--- a/packages/chat/slack/test/fixtures/events/reactions.json
+++ /dev/null
@@ -1,83 +0,0 @@
-{
-  "case": "A message, then thumbsup, +1::skin-tone-4 and grinning added, then grinning removed",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
-    "recordedAt": "2026-11-12T20:54:52.189Z",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "actions": [
-    {
-      "action": "chat.postMessage",
-      "ts": "1794516881.873469",
-      "request": {
-        "markdown_text": "react here [EFF-3694 20:54:24]"
-      }
-    },
-    {
-      "action": "reactions.add thumbsup",
-      "ts": "1794516881.873469"
-    },
-    {
-      "action": "reactions.add +1::skin-tone-4",
-      "ts": "1794516881.873469"
-    },
-    {
-      "action": "reactions.add grinning",
-      "ts": "1794516881.873469"
-    },
-    {
-      "action": "reactions.remove grinning",
-      "ts": "1794516881.873469"
-    }
-  ],
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T20:54:42.158Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516883",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516881.873469\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"react here [EFF-3694 20:54:24]\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"2l3VdF\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"react here [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T24A2X\",\"event_time\":1794516881,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:43.275Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516883",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"+1\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516883.059000\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85E7Z2S\",\"event_time\":1794516883,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:44.586Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516884",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"+1::skin-tone-4\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516884.059100\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH85ECA1L\",\"event_time\":1794516884,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:45.873Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516885",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_added\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"grinning\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516885.059200\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGUNRA0LX\",\"event_time\":1794516885,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX2FkZGVkIiwidGlkIjoiVDA1NDc5WjZKQlciLCJhaWQiOiJBMENDSEJIREs3WCIsImNpZCI6IkMwQ0gxTEdKNEYzIn0\"}"
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:47.111Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516887",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"reaction_removed\",\"user\":\"U0CCLMD4S1L\",\"reaction\":\"grinning\",\"item\":{\"type\":\"message\",\"channel\":\"C0CH1LGJ4F3\",\"ts\":\"1794516881.873469\",\"channel_type\":\"group\"},\"item_user\":\"U0CCLMD4S1L\",\"event_ts\":\"1794516886.059300\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ4FENQF2\",\"event_time\":1794516886,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6InJlYWN0aW9uX3JlbW92ZWQiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/stop-no-stream.json b/packages/chat/slack/test/fixtures/events/stop-no-stream.json
deleted file mode 100644
index e7ac131b053..00000000000
--- a/packages/chat/slack/test/fixtures/events/stop-no-stream.json
+++ /dev/null
@@ -1,76 +0,0 @@
-{
-  "case": "STOP-2: a root message with no stream, and three clicks on Stop, each with streaming_message_ts: []",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), as janitor production answered or as the session script posted; the stops by Tim Smart (U080YLYB277) clicking Stop",
-    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T23:32:49.326Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794526369",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794526369.028649\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"PAar\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794526369.028649\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH657Q7N1\",\"event_time\":1794526369,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:32:49.380Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794526369",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"RXi\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"title\":\"STOP-2\",\"date_status_processing_expire\":1794529969,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794529969,\"is_stoppable\":true}]},\"ts\":\"1794526369.028649\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794526369.028649\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"foR1o\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526369.007500\",\"event_ts\":\"1794526369.007500\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9EUMZ9C\",\"event_time\":1794526369,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:33:07.067Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794526386",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526369.028649\",\"event_ts\":\"1794526386.998236\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ5QW60G0\",\"event_time\":1794526386,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
-    },
-    {
-      "loggedAt": "2026-11-12T23:34:34.459Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794526474",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526369.028649\",\"event_ts\":\"1794526474.378471\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH65J9S1K\",\"event_time\":1794526474,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
-    },
-    {
-      "loggedAt": "2026-11-12T23:35:14.695Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794526514",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"agent_session_stopped\",\"channel\":\"C0CH1LGJ4F3\",\"user\":\"U080YLYB277\",\"streaming_message_ts\":[],\"thread_ts\":\"1794526369.028649\",\"event_ts\":\"1794526514.598642\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHB8TAYBC\",\"event_time\":1794526514,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false}"
-    },
-    {
-      "loggedAt": "2026-11-12T23:36:08.073Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794526566",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"qvM2e\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"agent_session\":{\"status\":\"active\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"title\":\"STOP-2\",\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"active\",\"is_stoppable\":true}]},\"ts\":\"1794526369.028649\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794526369.028649\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"STOP-2 <@U080YLYB277> no stream here; click Stop on this thread too\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"lX=gQ\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"STOP-2 \"},{\"type\":\"user\",\"user_id\":\"U080YLYB277\"},{\"type\":\"text\",\"text\":\" no stream here; click Stop on this thread too\"}]}]}],\"agent_session\":{\"status\":\"processing\",\"agent_bot_user_ids\":[\"U0CCLMD4S1L\"],\"encoded_initiator_user_id\":\"U080YLYB277\",\"title\":\"STOP-2\",\"date_status_processing_expire\":1794529969,\"agent_statuses\":[{\"agent_bot_user_id\":\"U0CCLMD4S1L\",\"status\":\"processing\",\"date_status_processing_expire\":1794529969,\"is_stoppable\":true}]}},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794526566.008000\",\"event_ts\":\"1794526566.008000\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH65W20HK\",\"event_time\":1794526566,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json b/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
index 73ab98f8747..0290459c3db 100644
--- a/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
+++ b/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
@@ -1,5 +1,5 @@
 {
-  "source": "EFF-3676 live runs G1 to G3, as janitor received them. G2 and G3 envelopes are as in G1, which was logged in full; their event objects are as logged. G2's has no streaming_message_ts because that log dropped it; Slack sends an empty array (see fixtures/events/stop-no-stream.json). It is kept to show an absent field is tolerated.",
+  "source": "EFF-3676 live runs G1 to G3, as janitor received them. G2 and G3 envelopes are as in G1, which was logged in full; their event objects are as logged. G2's has no streaming_message_ts because that log dropped it; Slack sends an empty array. It is kept to show an absent field is tolerated.",
   "cases": {
     "channelThread": {
       "type": "event_callback",
diff --git a/packages/chat/slack/test/fixtures/recorded/conversations-info.json b/packages/chat/slack/test/fixtures/recorded/conversations-info.json
deleted file mode 100644
index 14c37396876..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/conversations-info.json
+++ /dev/null
@@ -1,150 +0,0 @@
-{
-  "case": "conversations.info for the private test channel and the app DM",
-  "recordedAt": "2026-11-12T18:43:05.527Z",
-  "calls": [
-    {
-      "method": "conversations.info",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": {
-          "id": "C0CH1LGJ4F3",
-          "created": 1794446158,
-          "creator": "U080YLYB277",
-          "is_org_shared": false,
-          "is_im": false,
-          "context_team_id": "T05479Z6JBW",
-          "updated": 1794446158426,
-          "name": "chat-testing-123",
-          "name_normalized": "chat-testing-123",
-          "is_channel": true,
-          "is_group": false,
-          "is_mpim": false,
-          "is_private": true,
-          "is_archived": false,
-          "is_general": false,
-          "is_shared": false,
-          "is_ext_shared": false,
-          "unlinked": 0,
-          "is_pending_ext_shared": false,
-          "pending_shared": [],
-          "parent_conversation": null,
-          "purpose": {
-            "value": "",
-            "creator": "",
-            "last_set": 0
-          },
-          "topic": {
-            "value": "",
-            "creator": "",
-            "last_set": 0
-          },
-          "shared_team_ids": [
-            "T05479Z6JBW"
-          ],
-          "pending_connected_team_ids": [],
-          "is_member": true,
-          "is_open": true,
-          "last_read": "1794446158.561359",
-          "properties": {}
-        }
-      }
-    },
-    {
-      "method": "conversations.info",
-      "encoding": "json",
-      "note": "same call with a JSON body",
-      "request": {
-        "channel": "C0CH1LGJ4F3"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "invalid_arguments",
-        "response_metadata": {
-          "messages": [
-            "[ERROR] missing required field: channel"
-          ]
-        }
-      }
-    },
-    {
-      "method": "conversations.info",
-      "encoding": "form",
-      "request": {
-        "channel": "D0CCGDG0E75"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": {
-          "id": "D0CCGDG0E75",
-          "created": 1793134568,
-          "is_org_shared": false,
-          "is_im": true,
-          "is_archived": false,
-          "context_team_id": "T05479Z6JBW",
-          "updated": 1793134568873,
-          "user": "U080YLYB277",
-          "last_read": "0000000000.000000",
-          "is_open": true,
-          "priority": 0,
-          "unread_count": 8,
-          "unread_count_display": 2,
-          "latest": {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794454526.283939",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "G3 stream started. tick 2 after-click",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794454526.171439",
-            "parent_user_id": "U0CCLMD4S1L",
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "qmE9gL",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "G3 stream started. tick 2 after-click"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ],
-            "ai_context": {
-              "type": "default",
-              "result_status": "stopped_by_user",
-              "stopped_by_user_id": "U080YLYB277"
-            },
-            "streaming_state": "completed"
-          }
-        }
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/errors.json b/packages/chat/slack/test/fixtures/recorded/errors.json
deleted file mode 100644
index fd792afddd9..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/errors.json
+++ /dev/null
@@ -1,347 +0,0 @@
-{
-  "case": "error bodies and HTTP statuses for common failure modes",
-  "recordedAt": "2026-11-12T18:44:56.644Z",
-  "calls": [
-    {
-      "method": "chat.update",
-      "encoding": "json",
-      "note": "nonexistent ts",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1700000000.000100",
-        "markdown_text": "nope"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "message_not_found"
-      }
-    },
-    {
-      "method": "chat.delete",
-      "encoding": "json",
-      "note": "nonexistent ts",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1700000000.000100"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "message_not_found"
-      }
-    },
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "note": "nonexistent channel",
-      "request": {
-        "channel": "C00000000",
-        "ts": "1700000000.000100"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "channel_not_found"
-      }
-    },
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "note": "existing channel, nonexistent thread ts",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1700000000.000100"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "thread_not_found"
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "latest/inclusive for a nonexistent ts (before channel creation)",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1700000000.000100",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1700000000.000100",
-        "messages": [],
-        "has_more": false,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "latest/inclusive for a nonexistent ts 1 microsecond after a real message: returns the previous message",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509000.352790",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509000.352790",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509000.352789",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: thread root (no mentions). Some _markdown_ here.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794509000.352789",
-            "reply_count": 1,
-            "reply_users_count": 1,
-            "latest_reply": "1794509001.485739",
-            "reply_users": [
-              "U0CCLMD4S1L"
-            ],
-            "is_locked": false,
-            "subscribed": false,
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "TOu1os",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: thread root (no mentions). Some "
-                      },
-                      {
-                        "type": "text",
-                        "text": "markdown",
-                        "style": {
-                          "italic": true
-                        }
-                      },
-                      {
-                        "type": "text",
-                        "text": " here."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NDc5NTAzODIwNzA5"
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "json",
-      "note": "JSON body for conversations.history",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509073.518429",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: reactions target",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "C7NS1J",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: reactions target"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MDQ5MjQ1NjA5"
-        }
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "subteam token in markdown_text",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "Fixture: subteam "
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "invalid_blocks",
-        "errors": [
-          "usergroup [S00000000] could not be found [json-pointer:/blocks/0/elements/0/elements/1/usergroup_id]"
-        ],
-        "response_metadata": {
-          "messages": [
-            "[ERROR] usergroup [S00000000] could not be found [json-pointer:/blocks/0/elements/0/elements/1/usergroup_id]"
-          ]
-        }
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "markdown_text of 12,001 chars",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "msg_too_long"
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "markdown_text together with text",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "Fixture: markdown_text with text",
-        "text": "fallback"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "markdown_text_conflict"
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "nonexistent channel",
-      "request": {
-        "channel": "C00000000",
-        "markdown_text": "x"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "channel_not_found"
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "public channel the bot is not a member of (bot has no chat:write.public)",
-      "request": {
-        "channel": "C05479Z8Z0U",
-        "markdown_text": "Fixture: should be rejected"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "not_in_channel"
-      }
-    },
-    {
-      "method": "auth.test",
-      "encoding": "json",
-      "note": "invalid token",
-      "request": {},
-      "httpStatus": 200,
-      "tokenUsed": "invalid bot token string",
-      "response": {
-        "ok": false,
-        "error": "invalid_auth"
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "invalid token",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "x"
-      },
-      "httpStatus": 200,
-      "tokenUsed": "invalid bot token string",
-      "response": {
-        "ok": false,
-        "error": "invalid_auth"
-      }
-    },
-    {
-      "method": "auth.test",
-      "note": "no Authorization header",
-      "request": {},
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "not_authed"
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/reactions.json b/packages/chat/slack/test/fixtures/recorded/reactions.json
deleted file mode 100644
index 0edb7d474a8..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/reactions.json
+++ /dev/null
@@ -1,480 +0,0 @@
-{
-  "case": "reactions.add / reactions.get / reactions.remove with standard, skin-toned and alias emoji names; emoji.list (custom emoji lookup) is missing_scope for this bot so no custom emoji could be recorded",
-  "recordedAt": "2026-11-12T18:44:35.155Z",
-  "customEmojiName": null,
-  "calls": [
-    {
-      "method": "emoji.list",
-      "encoding": "form",
-      "note": "bot lacks emoji:read; used to find a custom emoji",
-      "request": {},
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "missing_scope",
-        "needed": "emoji:read",
-        "provided": "channels:history,groups:history,im:history,im:read,reactions:read,users:read,chat:write,app_mentions:read,im:write,reactions:write,assistant:write,channels:read,groups:read,files:read,files:write"
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "Fixture: reactions target"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509073.518429",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509073.518429",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "Fixture: reactions target",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "C7NS1J",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "Fixture: reactions target"
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "reactions.add",
-      "encoding": "json",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "grinning"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.add",
-      "encoding": "json",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "+1::skin-tone-3"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.add",
-      "encoding": "json",
-      "note": "alias name thumbsup with a tone",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "thumbsup::skin-tone-4"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.add",
-      "encoding": "json",
-      "note": "plain alias-free name",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "smile"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.add",
-      "encoding": "json",
-      "note": "adding the same reaction twice",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "grinning"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "already_reacted"
-      }
-    },
-    {
-      "method": "reactions.add",
-      "encoding": "json",
-      "note": "unknown emoji name (also what a missing custom emoji would give)",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "not_a_real_emoji_xyz"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "invalid_name"
-      }
-    },
-    {
-      "method": "reactions.add",
-      "encoding": "json",
-      "note": "name wrapped in colons",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": ":grinning:"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "invalid_name"
-      }
-    },
-    {
-      "method": "reactions.get",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "full": true
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "type": "message",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509073.518429",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "Fixture: reactions target",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "C7NS1J",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "Fixture: reactions target"
-                    }
-                  ]
-                }
-              ]
-            }
-          ],
-          "reactions": [
-            {
-              "name": "+1::skin-tone-3",
-              "users": [
-                "U0CCLMD4S1L"
-              ],
-              "count": 1
-            },
-            {
-              "name": "+1::skin-tone-4",
-              "users": [
-                "U0CCLMD4S1L"
-              ],
-              "count": 1
-            },
-            {
-              "name": "grinning",
-              "users": [
-                "U0CCLMD4S1L"
-              ],
-              "count": 1
-            },
-            {
-              "name": "smile",
-              "users": [
-                "U0CCLMD4S1L"
-              ],
-              "count": 1
-            }
-          ],
-          "permalink": "https://scrubbed.invalid/permalink"
-        },
-        "channel": "C0CH1LGJ4F3"
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509073.518429",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509073.518429",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509073.518429",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: reactions target",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "C7NS1J",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: reactions target"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ],
-            "reactions": [
-              {
-                "name": "+1::skin-tone-3",
-                "users": [
-                  "U0CCLMD4S1L"
-                ],
-                "count": 1
-              },
-              {
-                "name": "+1::skin-tone-4",
-                "users": [
-                  "U0CCLMD4S1L"
-                ],
-                "count": 1
-              },
-              {
-                "name": "grinning",
-                "users": [
-                  "U0CCLMD4S1L"
-                ],
-                "count": 1
-              },
-              {
-                "name": "smile",
-                "users": [
-                  "U0CCLMD4S1L"
-                ],
-                "count": 1
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MDQ5MjQ1NjA5"
-        }
-      }
-    },
-    {
-      "method": "reactions.remove",
-      "encoding": "json",
-      "note": "remove via the alias name used when adding",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "thumbsup::skin-tone-4"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.remove",
-      "encoding": "json",
-      "note": "removing using the name as returned by reactions.get",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "+1::skin-tone-3"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.remove",
-      "encoding": "json",
-      "note": "removing using the name as returned by reactions.get",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "grinning"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.remove",
-      "encoding": "json",
-      "note": "removing using the name as returned by reactions.get",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "smile"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true
-      }
-    },
-    {
-      "method": "reactions.remove",
-      "encoding": "json",
-      "note": "removing a reaction that is no longer present",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "name": "grinning"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "no_reaction"
-      }
-    },
-    {
-      "method": "reactions.get",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "timestamp": "1794509073.518429",
-        "full": true
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "type": "message",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509073.518429",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "Fixture: reactions target",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "C7NS1J",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "Fixture: reactions target"
-                    }
-                  ]
-                }
-              ]
-            }
-          ],
-          "permalink": "https://scrubbed.invalid/permalink"
-        },
-        "channel": "C0CH1LGJ4F3"
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/users-info.json b/packages/chat/slack/test/fixtures/recorded/users-info.json
deleted file mode 100644
index 8d1858714f7..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/users-info.json
+++ /dev/null
@@ -1,193 +0,0 @@
-{
-  "case": "auth.test, users.info for the bot user and a human, bots.info for the bot, users.info on a bot id (error)",
-  "recordedAt": "2026-11-12T18:43:05.435Z",
-  "calls": [
-    {
-      "method": "auth.test",
-      "encoding": "json",
-      "request": {},
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "url": "https://effectfulworkspace.slack.com/",
-        "team": "Effectful",
-        "user": "janitor2",
-        "team_id": "T05479Z6JBW",
-        "user_id": "U0CCLMD4S1L",
-        "bot_id": "B0CCQH77VA5",
-        "is_enterprise_install": false
-      }
-    },
-    {
-      "method": "users.info",
-      "encoding": "form",
-      "note": "users.info is documented as form/GET; json also tried below",
-      "request": {
-        "user": "U0CCLMD4S1L"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "user": {
-          "id": "U0CCLMD4S1L",
-          "name": "janitor2",
-          "is_bot": true,
-          "updated": 1794450518,
-          "is_app_user": false,
-          "team_id": "T05479Z6JBW",
-          "deleted": false,
-          "color": "619a4f",
-          "is_email_confirmed": false,
-          "real_name": "janitor",
-          "tz": "America/Los_Angeles",
-          "tz_label": "Pacific Standard Time",
-          "tz_offset": -28800,
-          "is_admin": false,
-          "is_owner": false,
-          "is_primary_owner": false,
-          "is_restricted": false,
-          "is_ultra_restricted": false,
-          "who_can_share_contact_card": "EVERYONE",
-          "profile": {
-            "real_name": "janitor",
-            "display_name": "",
-            "avatar_hash": "3d654eba937a",
-            "real_name_normalized": "janitor",
-            "display_name_normalized": "",
-            "image_24": "https://scrubbed.invalid/image_24",
-            "image_32": "https://scrubbed.invalid/image_32",
-            "image_48": "https://scrubbed.invalid/image_48",
-            "image_72": "https://scrubbed.invalid/image_72",
-            "image_192": "https://scrubbed.invalid/image_192",
-            "image_512": "https://scrubbed.invalid/image_512",
-            "image_1024": "https://scrubbed.invalid/image_1024",
-            "image_original": "https://scrubbed.invalid/image_original",
-            "is_custom_image": true,
-            "first_name": "janitor",
-            "last_name": "",
-            "team": "T05479Z6JBW",
-            "title": "",
-            "phone": "",
-            "skype": "",
-            "status_text": "",
-            "status_text_canonical": "",
-            "status_emoji": "",
-            "status_emoji_display_info": [],
-            "status_expiration": 0,
-            "bot_id": "B0CCQH77VA5",
-            "api_app_id": "A0CCHBHDK7X",
-            "always_active": true
-          }
-        }
-      }
-    },
-    {
-      "method": "users.info",
-      "encoding": "json",
-      "note": "same call with a JSON body",
-      "request": {
-        "user": "U0CCLMD4S1L"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "user_not_found"
-      }
-    },
-    {
-      "method": "users.info",
-      "encoding": "form",
-      "request": {
-        "user": "U080YLYB277"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "user": {
-          "id": "U080YLYB277",
-          "name": "test.user",
-          "is_bot": false,
-          "updated": 1782289647,
-          "is_app_user": false,
-          "team_id": "T05479Z6JBW",
-          "deleted": false,
-          "color": "827327",
-          "is_email_confirmed": true,
-          "real_name": "Test User",
-          "tz": "Pacific/Auckland",
-          "tz_label": "New Zealand Daylight Time",
-          "tz_offset": 46800,
-          "is_admin": false,
-          "is_owner": false,
-          "is_primary_owner": false,
-          "is_restricted": false,
-          "is_ultra_restricted": false,
-          "who_can_share_contact_card": "EVERYONE",
-          "profile": {
-            "real_name": "Test User",
-            "display_name": "Test User",
-            "avatar_hash": "g51a1c442992",
-            "real_name_normalized": "Test User",
-            "display_name_normalized": "Test User",
-            "image_24": "https://scrubbed.invalid/image_24",
-            "image_32": "https://scrubbed.invalid/image_32",
-            "image_48": "https://scrubbed.invalid/image_48",
-            "image_72": "https://scrubbed.invalid/image_72",
-            "image_192": "https://scrubbed.invalid/image_192",
-            "image_512": "https://scrubbed.invalid/image_512",
-            "first_name": "Test User",
-            "last_name": "Test User",
-            "team": "T05479Z6JBW",
-            "title": "",
-            "phone": "",
-            "skype": "",
-            "status_text": "",
-            "status_text_canonical": "",
-            "status_emoji": "",
-            "status_emoji_display_info": [],
-            "status_expiration": 0,
-            "huddle_state": "default_unset",
-            "huddle_state_expiration_ts": 0
-          }
-        }
-      }
-    },
-    {
-      "method": "bots.info",
-      "encoding": "form",
-      "request": {
-        "bot": "B0CCQH77VA5"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "bot": {
-          "id": "B0CCQH77VA5",
-          "deleted": false,
-          "name": "Janitor",
-          "updated": 1793135255,
-          "app_id": "A0CCHBHDK7X",
-          "user_id": "U0CCLMD4S1L",
-          "icons": {
-            "image_36": "https://scrubbed.invalid/image_36",
-            "image_48": "https://scrubbed.invalid/image_48",
-            "image_72": "https://scrubbed.invalid/image_72"
-          }
-        }
-      }
-    },
-    {
-      "method": "users.info",
-      "encoding": "form",
-      "note": "users.info with a B... bot id",
-      "request": {
-        "user": "B0CCQH77VA5"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": false,
-        "error": "user_not_found"
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
index 6e02e803706..d7cb8a095b6 100644
--- a/packages/chat/slack/test/interactions.test.ts
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -56,9 +56,6 @@ describe("normalizeInteraction", () => {
     assert.isTrue(Option.isNone(normalize(click({ type: "button", action_id: join + "0", url: "https://x.test" }))))
     assert.isTrue(Option.isNone(normalize(click({ type: "button", action_id: "go", block_id: "theirs" }))))
     assert.isTrue(Option.isNone(normalize(submit("theirs", {}))))
-    assert.isTrue(Option.isNone(normalize({ type: "shortcut" })))
-    assert.isTrue(Option.isNone(normalize("block_actions")))
-    assert.isTrue(Option.isNone(normalize({ ...click({ type: "button", action_id: "go" }), at: new Date(0) })))
   })
 
   it("gives a click its thread, message, value and raw payload without the token", () => {
@@ -109,22 +106,9 @@ describe("normalizeInteraction", () => {
     const bare = Option.getOrThrow(normalize(submit(["chat1", channel, "", "1794600001.000100"].join(join), {})))
     assert.isFalse("metadata" in bare)
     assert.strictEqual(bare.thread.id, `${team}/${channel}`)
-    // A modal a command opened packs an empty message slot, and its submit has no messageId.
-    const fromCommand = Option.getOrThrow(normalize(submit(["chat1", channel, "", ""].join(join), {})))
-    assert.isFalse("messageId" in fromCommand)
-    assert.strictEqual(fromCommand.thread.id, `${team}/${channel}`)
   })
 
-  it("gives a command its name without the slash, its text and the channel, known or not", () => {
-    const event = Option.getOrThrow(normalize(commandFields("/deploy", "v1 <@U1>")))
-    assert.strictEqual(event._tag, "CommandInvoked")
-    if (event._tag !== "CommandInvoked") return
-    assert.deepStrictEqual(
-      [event.id, event.text, event.userId, event.thread.id],
-      ["deploy", "v1 <@U1>", "U080YLYB277", `${team}/${channel}`]
-    )
-    assert.isFalse("token" in (event.raw as object))
-    assert.strictEqual((event.raw as any).response_url, responseUrl)
+  it("gives a command with no text an empty text, and ignores one with no name or channel", () => {
     const { text: _, ...noText } = commandFields("/deploy", "")
     assert.strictEqual((Option.getOrThrow(normalize(noText)) as ChatInteraction.CommandInvoked).text, "")
     assert.isTrue(Option.isNone(normalize(commandFields("/", ""))))
@@ -175,20 +159,6 @@ describe("SlackChat.interaction", () => {
       return yield* slack.interaction(payload, { deadline: Duration.millis(50) })
     }).pipe(Effect.provide(handler.layer), Effect.provide(slackLayer(fake)))
 
-  it.live("answers errors by field, and nothing for a close, an ack or a foreign payload", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({ "auth.test": authTest })
-      const handler = recording()
-      assert.isUndefined(yield* interact(fake, handler, submit(packedFor(""), {})))
-      assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
-      assert.isUndefined(yield* interact(fake, handler, recorded.block_actions))
-      handler.submit = () => Effect.succeed(ChatInteraction.errors({ field: "Too short" }))
-      assert.deepStrictEqual(
-        yield* interact(fake, handler, submit(packedFor(""), {})),
-        { response_action: "errors", errors: { field: "Too short" } }
-      )
-    }))
-
   it.live("gives Late for a late submit and nothing for a late click", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest })
@@ -200,27 +170,6 @@ describe("SlackChat.interaction", () => {
       assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
     }))
 
-  it.live("opens a modal with the click's trigger, packing its origin beside the metadata", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({ "auth.test": authTest, "views.open": { ok: true, view: { id: "V1" } } })
-      const handler = recording()
-      handler.click = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("m") }))
-      const answer = yield* interact(
-        fake,
-        handler,
-        click({ type: "button", action_id: "go" }, { thread_ts: "1794600000.000100" })
-      )
-      assert.isUndefined(answer)
-      const [call] = fake.called("views.open")
-      assert.strictEqual(call.params.trigger_id, "trigger-1")
-      const view = JSON.parse(call.params.view)
-      assert.deepStrictEqual(
-        [view.callback_id, view.private_metadata, view.submit.text, view.blocks[0].block_id],
-        ["form", ["chat1", channel, "1794600000.000100", "1794600001.000100", "m"].join(join), "Submit", "field"]
-      )
-      assert.deepStrictEqual(handler.refused, [])
-    }))
-
   it.live("refuses a modal Slack refuses, or that is too large, to Handler.refused, still acking", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest, "views.open": { ok: false, error: "expired_trigger_id" } })
@@ -236,30 +185,12 @@ describe("SlackChat.interaction", () => {
       assert.strictEqual(fake.called("views.open").length, 1)
     }))
 
-  it.live("answers a command with the message a post sends, privately by default, or refuses it", () =>
+  it.live("refuses a command answer that is too large to Handler.refused, answering nothing", () =>
     Effect.gen(function*() {
-      const fake = makeFake({ "auth.test": authTest, "views.open": { ok: true, view: { id: "V1" } } })
+      const fake = makeFake({ "auth.test": authTest })
       const handler = recording()
-      const command = commandFields("/deploy", "v1")
-      handler.command = (event) =>
-        Effect.succeed(ChatInteraction.respond({ markdown: "Deploying **" + event.text + "**" }))
-      const answer: any = yield* interact(fake, handler, command)
-      assert.deepStrictEqual(
-        [answer.response_type, answer.text, answer.blocks[0].type, answer.blocks[0].text, answer.unfurl_links],
-        ["ephemeral", "Deploying **v1**", "markdown", "Deploying **v1**", false]
-      )
-      handler.command = () => Effect.succeed(ChatInteraction.respond({ markdown: "Hi", visibility: "public" }))
-      assert.strictEqual(((yield* interact(fake, handler, command)) as any).response_type, "in_channel")
-      // Nothing is answered for a deferral, a modal or a refused answer.
-      handler.command = (event) => Effect.succeed(ChatInteraction.defer(event))
-      assert.isUndefined(yield* interact(fake, handler, command))
-      handler.command = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("m") }))
-      assert.isUndefined(yield* interact(fake, handler, command))
-      const [call] = fake.called("views.open")
-      assert.strictEqual(call.params.trigger_id, "trigger-command")
-      assert.strictEqual(JSON.parse(call.params.view).private_metadata, ["chat1", channel, "", "", "m"].join(join))
       handler.command = () => Effect.succeed(ChatInteraction.respond({ markdown: "x".repeat(12_001) }))
-      assert.isUndefined(yield* interact(fake, handler, command))
+      assert.isUndefined(yield* interact(fake, handler, commandFields("/deploy", "v1")))
       assert.deepStrictEqual(handler.refused.map((error) => [error.op, error.reason._tag]), [["respond", "TooLarge"]])
     }))
 })
@@ -291,13 +222,9 @@ describe("followUp", () => {
       )
     }))
 
-  it.effect("refuses a response_url off Slack, and maps a spent one to interaction_expired", () =>
+  it.effect("refuses a response_url off Slack before any call", () =>
     Effect.gen(function*() {
-      const fake = makeFake({
-        "auth.test": authTest,
-        // As recorded in fixtures/recorded/commands.json.
-        "response_url": { status: 404, headers: { "content-type": "text/html" }, body: "used_url" }
-      })
+      const fake = makeFake({ "auth.test": authTest })
       const failure = (raw: Record) =>
         Effect.flip(Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred(raw, "ephemeral"), { markdown: "x" })))
           .pipe(
@@ -305,16 +232,14 @@ describe("followUp", () => {
           )
       const offSlack = yield* failure({ response_url: "https://hooks.slack.com.evil.test/commands/1" })
       const plain = yield* failure({ response_url: responseUrl.replace("https:", "http:") })
-      const spent = yield* failure({ response_url: responseUrl })
       assert.deepStrictEqual(
-        [offSlack, plain, spent].map((error) => [error.op, error.reason._tag, error.reason.detail]),
+        [offSlack, plain].map((error) => [error.op, error.reason._tag, error.reason.detail]),
         [
           ["followUp", "InvalidRequest", "invalid_response_url"],
-          ["followUp", "InvalidRequest", "invalid_response_url"],
-          ["followUp", "NotFound", "interaction_expired"]
+          ["followUp", "InvalidRequest", "invalid_response_url"]
         ]
       )
-      assert.strictEqual(fake.called("response_url").length, 1)
+      assert.strictEqual(fake.called("response_url").length, 0)
     }))
 })
 
@@ -386,24 +311,10 @@ describe("layerInteractivity", () => {
       yield* dispose
     }))
 
-  it.live("answers a late submit 503, errors as JSON, and a bad signature 401", () =>
+  it.live("answers errors as JSON, an ack empty, and a bad signature 401", () =>
     Effect.gen(function*() {
       const handler = recording()
-      const app = SlackChat.layerInteractivity({
-        path: "/slack/interactivity",
-        signingSecret: Redacted.make(secret),
-        appId,
-        deadline: Duration.millis(50)
-      }).pipe(
-        Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
-        Layer.provide(Chat.layer),
-        Layer.provide(handler.layer),
-        Layer.provide(makeFake({ "auth.test": authTest }).layer)
-      )
-      const { dispose, handler: web } = HttpRouter.toWebHandler(app, { disableLogger: true })
-      const send = (payload: unknown, options?: { readonly signature?: string }) =>
-        Effect.promise(() => post(payload, options).then(web))
-
+      const { dispose, send } = serve(handler)
       handler.submit = () => Effect.succeed(ChatInteraction.errors({ field: "Too short" }))
       const errors = yield* send(submit(packedFor(""), {}))
       assert.strictEqual(errors.status, 200)
@@ -412,13 +323,9 @@ describe("layerInteractivity", () => {
         errors: { field: "Too short" }
       })
 
-      handler.submit = () => Effect.as(Effect.never, ChatInteraction.close)
-      assert.strictEqual((yield* send(submit(packedFor(""), {}))).status, 503)
-
-      const closed = yield* send(click({ type: "button", action_id: "go" }))
-      assert.deepStrictEqual([closed.status, yield* Effect.promise(() => closed.text())], [200, ""])
-      assert.strictEqual((yield* send({ ...submit(packedFor(""), {}), api_app_id: "A0OTHER" })).status, 200)
+      const acked = yield* send(click({ type: "button", action_id: "go" }))
+      assert.deepStrictEqual([acked.status, yield* Effect.promise(() => acked.text())], [200, ""])
       assert.strictEqual((yield* send(submit(packedFor(""), {}), { signature: "v0=00" })).status, 401)
-      yield* Effect.promise(() => dispose())
+      yield* dispose
     }))
 })
diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts
index ae70b114901..10cc4856239 100644
--- a/packages/chat/slack/test/normalize.test.ts
+++ b/packages/chat/slack/test/normalize.test.ts
@@ -1,11 +1,8 @@
-import { extract } from "@effect/chat-slack/internal/mentions"
-import { messageSubtypes } from "@effect/chat-slack/internal/normalize"
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { dedupeKey } from "effect/chat/ChatEvent"
 import { checkEvent, checkMessage } from "effect/chat/ChatTest"
-import * as ChatThread from "effect/chat/ChatThread"
 import * as Effect from "effect/Effect"
 import { botUserId, channel, checkOptions, fixture, messageEnvelope, recordedMessages, team } from "./utils.ts"
 
@@ -176,71 +173,6 @@ describe("normalize", () => {
       )
     }))
 
-  it("alignment ends and reports only real items, for every small case", () => {
-    const ids = ["U1AAAA", "U2BBBB", "U3CCCC"]
-    let seed = 7
-    const next = (bound: number) => {
-      seed = (seed * 1103515245 + 12345) % 2147483648
-      return seed % bound
-    }
-    for (let round = 0; round < 2_000; round++) {
-      const items = Array.from({ length: next(6) }, () => ({ id: ids[next(3)], real: next(2) === 0 }))
-      const text = Array.from({ length: next(6) }, () => `<@${ids[next(3)]}>`).join(" ")
-      const blocks = [{
-        type: "rich_text",
-        elements: [{
-          type: "rich_text_section",
-          elements: items.map((item) =>
-            item.real ? { type: "user", user_id: item.id } : { type: "text", text: ` <@${item.id}> ` }
-          )
-        }]
-      }]
-      const mentions = extract(text, blocks, botUserId)
-      const real = items.filter((item) => item.real).map((item) => item.id)
-      assert.isAtMost(mentions.length, real.length)
-      for (const id of new Set(mentions.map((mention) => mention.id))) {
-        assert.isAtMost(
-          mentions.filter((mention) => mention.id === id).length,
-          real.filter((item) => item === id).length,
-          JSON.stringify({ text, items })
-        )
-      }
-      const starts = mentions.map((mention) => mention.start)
-      assert.strictEqual(new Set(starts).size, starts.length)
-      for (const mention of mentions) assert.strictEqual(text.slice(mention.start, mention.end), `<@${mention.id}>`)
-    }
-  })
-
-  it.effect("a /me line that mentions the bot is a message", () =>
-    Effect.gen(function*() {
-      const [message] = recordedMessages("me-message").values()
-      assert.strictEqual(message.subtype, "me_message")
-      const event = yield* pair(message)
-      assert.strictEqual(event.message.mentions.length, 1)
-      assert.isTrue(event.message.mentions[0].isSelf)
-    }))
-
-  it.effect("a thread_broadcast is addressed to its thread", () =>
-    Effect.gen(function*() {
-      const broadcast = [...recordedMessages("thread-broadcast").values()].find((m) => m.subtype === "thread_broadcast")
-      const event = yield* pair(broadcast)
-      assert.strictEqual(event.kind, "thread")
-      assert.deepStrictEqual(event.thread, SlackChat.thread({ team, channel, threadTs: broadcast.thread_ts }))
-    }))
-
-  it.effect("a thread root keeps its channel address after its first reply", () =>
-    Effect.gen(function*() {
-      const calls = fixture("thread-root-before-after").calls.filter((call) => call.method === "conversations.history")
-      const before = calls[0].response.messages[0]
-      const after = calls[1].response.messages.find((m: any) => m.ts === before.ts)
-      assert.strictEqual(after.thread_ts, after.ts)
-      const one = yield* pair(before)
-      const two = yield* pair(after)
-      assert.deepStrictEqual(one.thread, SlackChat.thread({ team, channel }))
-      assert.deepStrictEqual(two.thread, one.thread)
-      assert.strictEqual(dedupeKey(one), dedupeKey(two))
-    }))
-
   it.effect("files are attachments, with an id and no URL", () =>
     Effect.gen(function*() {
       const reply = recordedMessages("file-share").get("1794509028.831169")
@@ -285,19 +217,12 @@ describe("normalize", () => {
       })
     }))
 
-  it("drops an edited app_mention, other subtypes, other workspaces and other types", () => {
+  it("drops other subtypes, other workspaces and other types", () => {
     const message = { ts: "1794509003.000005", user: "U080YLYB277", text: "<@U0CCLMD4S1L>" }
-    const edited = messageEnvelope({ ...message, edited: { user: "U080YLYB277", ts: "1794509010.000000" } }, {
-      type: "app_mention"
-    })
-    assert.deepStrictEqual(SlackChat.normalize(edited, context), [])
-    for (const subtype of ["channel_join", "message_changed", "message_deleted", "assistant_app_thread"]) {
-      assert.deepStrictEqual(SlackChat.normalize(messageEnvelope({ ...message, subtype }), context), [])
-    }
+    assert.deepStrictEqual(SlackChat.normalize(messageEnvelope({ ...message, subtype: "channel_join" }), context), [])
     assert.deepStrictEqual(SlackChat.normalize(messageEnvelope(message, { teamId: "T0OTHER" }), context), [])
     assert.deepStrictEqual(SlackChat.normalize({ type: "url_verification", challenge: "x" }, context), [])
     assert.deepStrictEqual(SlackChat.normalize(null, context), [])
-    assert.deepStrictEqual([...messageSubtypes].sort(), ["bot_message", "file_share", "me_message", "thread_broadcast"])
   })
 
   it("drops the verification token from raw", () => {
@@ -310,14 +235,14 @@ describe("normalize", () => {
 })
 
 describe("reactions", () => {
-  const reaction = (type: "reaction_added" | "reaction_removed", name: string) => ({
+  const reaction = (name: string) => ({
     team_id: team,
     api_app_id: "A0CCHBHDK7X",
     type: "event_callback",
     event_id: "Ev02",
     event_time: 1794509100,
     event: {
-      type,
+      type: "reaction_added",
       user: "U080YLYB277",
       reaction: name,
       item_user: botUserId,
@@ -326,72 +251,31 @@ describe("reactions", () => {
     }
   })
 
-  it.effect("plain, toned and custom emoji", () =>
+  it.effect("a name with two tones is a custom emoji, on the reacted message's author", () =>
     Effect.gen(function*() {
-      // The names Slack stored in the reactions fixture.
-      const names = fixture("reactions").calls
-        .filter((call) => call.method === "reactions.add" && call.response.ok === true)
-        .map((call) => call.request.name as string)
-      assert.includeMembers(names, ["grinning", "+1::skin-tone-3"])
-      const cases: ReadonlyArray = [
-        ["grinning", "😀"],
-        ["+1", "👍"],
-        ["thumbsup", "👍"],
-        ["+1::skin-tone-3", "👍🏼"],
-        ["party-parrot", "custom:party-parrot"],
-        // Synthetic: no recording has a two-tone reaction, so its name is
-        // not resolved and reads as custom (stage 0 fixture 16).
-        ["handshake::skin-tone-2::skin-tone-5", "custom:handshake::skin-tone-2::skin-tone-5"]
-      ]
-      for (const [name, emoji] of cases) {
-        const added = SlackChat.normalize(reaction("reaction_added", name), context)
-        const removed = SlackChat.normalize(reaction("reaction_removed", name), context)
-        assert.strictEqual(added.length, 1)
-        const event = added[0]
-        assert(event._tag === "ReactionAdded")
-        assert.strictEqual(event.emoji, emoji)
-        assert.strictEqual(event.messageAuthorId, botUserId)
-        assert.deepStrictEqual(event.thread, SlackChat.thread({ team, channel }))
-        yield* checkEvent(event, checkOptions)
-        yield* checkEvent(removed[0], checkOptions)
-        assert.notStrictEqual(dedupeKey(event), dedupeKey(removed[0]))
-      }
+      // No recording has a two-tone reaction, so its name is not resolved
+      // (stage 0 fixture 16).
+      const [event] = SlackChat.normalize(reaction("handshake::skin-tone-2::skin-tone-5"), context)
+      assert(event._tag === "ReactionAdded")
+      assert.strictEqual(event.emoji, "custom:handshake::skin-tone-2::skin-tone-5")
+      assert.strictEqual(event.messageAuthorId, botUserId)
+      assert.deepStrictEqual(event.thread, SlackChat.thread({ team, channel }))
+      yield* checkEvent(event, checkOptions)
     }))
 })
 
 describe("agent_session_stopped", () => {
-  const cases = fixture("agent-session-stopped").cases
-
-  it.effect("the three captured payloads", () =>
+  it.effect("a stop in a direct message", () =>
     Effect.gen(function*() {
-      const expected: Record }> = {
-        channelThread: { channel, messageIds: ["1794454017.726189"] },
-        noStream: { channel, messageIds: [] },
-        direct: { channel: "D0CCGDG0E75", messageIds: ["1794454526.283939"] }
-      }
-      for (const [name, envelope] of Object.entries(cases)) {
-        const events = SlackChat.normalize(envelope, context)
-        assert.strictEqual(events.length, 1)
-        const event = events[0]
-        assert(event._tag === "StopRequested")
-        yield* checkEvent(event, checkOptions)
-        const { channel: eventChannel, messageIds } = expected[name]
-        const raw = envelope as any
-        assert.deepStrictEqual(
-          event.thread,
-          SlackChat.thread({ team, channel: eventChannel, threadTs: raw.event.thread_ts })
-        )
-        assert.deepStrictEqual(event.messageIds, messageIds)
-        assert.strictEqual(event.userId, "U080YLYB277")
-        assert.strictEqual(dedupeKey(event), `stop/${ChatThread.toString(event.thread)}/${raw.event.event_ts}`)
-      }
+      const envelope = fixture("agent-session-stopped").cases.direct
+      const [event] = SlackChat.normalize(envelope, context)
+      assert(event._tag === "StopRequested")
+      yield* checkEvent(event, checkOptions)
+      assert.deepStrictEqual(
+        event.thread,
+        SlackChat.thread({ team, channel: "D0CCGDG0E75", threadTs: envelope.event.thread_ts })
+      )
+      assert.deepStrictEqual(event.messageIds, ["1794454526.283939"])
+      assert.strictEqual(event.userId, "U080YLYB277")
     }))
-
-  it("an empty streaming_message_ts gives no message ids", () => {
-    const envelope = structuredClone(cases.channelThread)
-    envelope.event.streaming_message_ts = []
-    const [event] = SlackChat.normalize(envelope, context)
-    assert(event._tag === "StopRequested")
-    assert.deepStrictEqual(event.messageIds, [])
-  })
 })
diff --git a/packages/chat/slack/test/richText.test.ts b/packages/chat/slack/test/richText.test.ts
index 3feb07697bb..fdcb4a0ee3f 100644
--- a/packages/chat/slack/test/richText.test.ts
+++ b/packages/chat/slack/test/richText.test.ts
@@ -60,24 +60,6 @@ describe("the bot's own messages read back", () => {
       assert.notStrictEqual(recorded("markdown-mentions", "1794509003.143939").text, mentionsPost)
     }))
 
-  it.effect("mentions are the elements outside code, at the offsets the renderer wrote", () =>
-    Effect.gen(function*() {
-      const message = yield* read(recorded("markdown-mentions", "1794509003.143939"))
-      // The inline code and the fence hold the same tokens, as literals.
-      assert.deepStrictEqual(message.mentions.map((mention) => [mention.kind, mention.id, mention.isSelf]), [
-        ["user", botUserId, true],
-        ["channel", "C0CH1LGJ4F3", false]
-      ])
-    }))
-
-  it.effect("a me_message drops the label Slack wrote into the token", () =>
-    Effect.gen(function*() {
-      const stored = recorded("me-message", "1794509006.465359")
-      assert.strictEqual(stored.text, `Fixture: me message waves at <@${botUserId}|janitor2>`)
-      const message = yield* read(stored)
-      assert.strictEqual(message.text, `Fixture: me message waves at <@${botUserId}>`)
-    }))
-
   it.effect("an agent DM thread root", () =>
     Effect.gen(function*() {
       const stored = recorded("assistant-thread-root", "1794454526.171439")
@@ -97,11 +79,9 @@ describe("the bot's own messages read back", () => {
 
   it.effect("someone else's message keeps Slack's text", () =>
     Effect.gen(function*() {
-      for (const { message, name } of synthetic.cases) {
-        const { app_id: _app, bot_id: _bot, ...rest } = message
-        const other = { ...rest, user: "U080YLYB277" }
-        const read_ = yield* read(other)
-        assert.strictEqual(read_.text, message.text, name)
-      }
+      const { message } = synthetic.cases.find(({ name }) => name.startsWith("Markdown characters"))!
+      const { app_id: _app, bot_id: _bot, ...rest } = message
+      const read_ = yield* read({ ...rest, user: "U080YLYB277" })
+      assert.strictEqual(read_.text, message.text)
     }))
 })
diff --git a/packages/chat/slack/test/text.test.ts b/packages/chat/slack/test/text.test.ts
index 579ea009c7a..2d47ffd8fea 100644
--- a/packages/chat/slack/test/text.test.ts
+++ b/packages/chat/slack/test/text.test.ts
@@ -12,56 +12,6 @@ const graphemes = (text: string) => [...segmenter.segment(text)]
 const isBoundary = (text: string, index: number) =>
   index === text.length || graphemes(text).some((segment) => segment.index === index)
 
-describe("build", () => {
-  it("writes every <, > and & as an entity, in code too, and keeps allowed tokens", () => {
-    const built = Text.build("a <@U1> <@U2> `` & > ", { users: ["U1"], broadcast: true }, Text.postBudget)
-    assert.strictEqual(built.text, "a <@U1> <@U2> `<b>` & > ")
-    assert.strictEqual(built.dropped, 0)
-  })
-
-  it("cuts a post at 16,000 code points and an update at 3,800 bytes, marker included", () => {
-    assert.strictEqual(Text.build("a".repeat(16_000), {}, Text.postBudget).text, "a".repeat(16_000))
-    assert.strictEqual(Text.build("a".repeat(16_001), {}, Text.postBudget).text, "a".repeat(15_999) + "…")
-    // An astral letter is one code point and four bytes.
-    assert.strictEqual(Text.build("𝐚".repeat(16_001), {}, Text.postBudget).text, "𝐚".repeat(15_999) + "…")
-    // "…" is three bytes.
-    assert.strictEqual(Text.build("é".repeat(1_900), {}, Text.updateBudget).text, "é".repeat(1_900))
-    assert.strictEqual(Text.build("é".repeat(1_901), {}, Text.updateBudget).text, "é".repeat(1_898) + "…")
-  })
-
-  it("cuts on a grapheme cluster boundary and splits no entity", () => {
-    const family = "👨‍👩‍👧‍👦"
-    const cut = Text.build(family.repeat(200), {}, Text.updateBudget).text
-    assert.strictEqual(cut, family.repeat(151) + "…")
-    assert.strictEqual(graphemes(cut).length, 152)
-    assert.strictEqual(Text.build("&".repeat(4_000), {}, Text.postBudget).text, "&".repeat(3_199) + "…")
-    assert.strictEqual(Text.build("<".repeat(1_000), {}, Text.updateBudget).text, "<".repeat(949) + "…")
-  })
-
-  it("appends each allowed token not in the kept head once, in order", () => {
-    const notify = { users: ["U1", "U2", "U3"] }
-    const built = Text.build("<@U2> " + "x".repeat(20_000) + " <@U1> <@U3> <@U1> <@U2>", notify, Text.postBudget)
-    assert.isTrue(built.text.startsWith("<@U2> xxx"))
-    assert.isTrue(built.text.endsWith("x… <@U1> <@U3>"))
-    assert.strictEqual(codePoints(built.text), 16_000)
-    assert.strictEqual(built.dropped, 0)
-  })
-
-  it("never cuts inside a token", () => {
-    const built = Text.build("x".repeat(15_997) + "<@U1>" + "y".repeat(10), { users: ["U1"] }, Text.postBudget)
-    assert.strictEqual(built.text, "x".repeat(15_993) + "… <@U1>")
-  })
-
-  it("keeps the tokens that fit when the tokens alone don't, and counts the rest", () => {
-    const users = Array.from({ length: 500 }, (_, i) => `U${1_000 + i}`)
-    const built = Text.build(users.map((user) => `<@${user}>`).join(" "), { users }, Text.updateBudget)
-    // "…" is 3 bytes and each " <@U1xxx>" 9.
-    assert.strictEqual(built.dropped, 79)
-    assert.strictEqual(built.text, "…" + users.slice(0, 421).map((user) => ` <@${user}>`).join(""))
-    assert.isAtMost(bytes(built.text), Text.updateTextBytes)
-  })
-})
-
 /**
  * The CI half of the Slack mention rule: the same assertions the live rule
  * makes on stored messages, made here on the request bodies the adapter
diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts
index a09f459fbd4..8ae9f412051 100644
--- a/packages/chat/slack/test/webhook.test.ts
+++ b/packages/chat/slack/test/webhook.test.ts
@@ -84,14 +84,6 @@ const withLogs = (effect: Effect.Effect) => {
 }
 
 describe("webhook", () => {
-  it.live("a signed event reaches the handler", () =>
-    Effect.gen(function*() {
-      const result = yield* handle({}, yield* Effect.promise(() => request(JSON.stringify(message))))
-      assert.strictEqual(result.status, 200)
-      assert.strictEqual(result.events.length, 1)
-      assert.strictEqual(result.events[0]._tag, "MessageCreated")
-    }))
-
   it.live("rejects a bad or stale signature", () =>
     Effect.gen(function*() {
       const body = JSON.stringify(message)
@@ -100,9 +92,7 @@ describe("webhook", () => {
       const stale = String(Math.floor(Date.now() / 1000) - 6 * 60)
       const old = yield* handle({}, yield* Effect.promise(() => request(body, { timestamp: stale })))
       assert.strictEqual(old.status, 401)
-      const unsigned = yield* handle({}, new Request("http://localhost/", { method: "POST", body }))
-      assert.strictEqual(unsigned.status, 401)
-      assert.strictEqual(wrongKey.events.length + old.events.length + unsigned.events.length, 0)
+      assert.strictEqual(wrongKey.events.length + old.events.length, 0)
     }))
 
   it.live("413 past the body limit, 400 for a body that is not JSON", () =>
@@ -139,35 +129,7 @@ describe("webhook", () => {
       assert.strictEqual(result.events.length, 0)
     }))
 
-  it.live("503 so Slack retries: no bot user, NotAccepted, past the deadline", () =>
-    Effect.gen(function*() {
-      const body = JSON.stringify(message)
-      const noBot = yield* handle(
-        { botUserId: Effect.fail(unavailable) },
-        yield* Effect.promise(() => request(body))
-      )
-      assert.strictEqual(noBot.status, 503)
-      assert.strictEqual(noBot.events.length, 0)
-      const refused = yield* handle(
-        { handle: () => Effect.fail(new NotAccepted()) },
-        yield* Effect.promise(() => request(body))
-      )
-      assert.strictEqual(refused.status, 503)
-      const slow = yield* handle(
-        { handle: () => Effect.never, deadline: Duration.millis(20) },
-        yield* Effect.promise(() => request(body))
-      )
-      assert.strictEqual(slow.status, 503)
-      // The deadline covers the bot user lookup too.
-      const slowBot = yield* handle(
-        { botUserId: Effect.never, deadline: Duration.millis(20) },
-        yield* Effect.promise(() => request(body))
-      )
-      assert.strictEqual(slowBot.status, 503)
-      assert.strictEqual(slowBot.events.length, 0)
-    }))
-
-  it.live("each 503 is logged with what caused it", () =>
+  it.live("503 so Slack retries, logged with what caused it: no bot user, NotAccepted, past the deadline", () =>
     Effect.gen(function*() {
       const body = JSON.stringify(message)
       const web = Effect.promise(() => request(body))
@@ -181,7 +143,17 @@ describe("webhook", () => {
       assert.deepStrictEqual(refused.logs, [{ level: "Warn", message: [logged.notAccepted] }])
       assert.deepStrictEqual(slow.logs, [{ level: "Warn", message: [logged.deadline] }])
       assert.deepStrictEqual(fine.logs, [])
-      assert.strictEqual(new Set(Object.values(logged)).size, 3)
+      assert.strictEqual(noBot.value.events.length, 0)
+    }))
+
+  it.live("the deadline covers the bot user lookup", () =>
+    Effect.gen(function*() {
+      const slowBot = yield* handle(
+        { botUserId: Effect.never, deadline: Duration.millis(20) },
+        yield* Effect.promise(() => request(JSON.stringify(message)))
+      )
+      assert.strictEqual(slowBot.status, 503)
+      assert.strictEqual(slowBot.events.length, 0)
     }))
 
   it.effect("layerWebhook bounds a request whose body never finishes", () =>
diff --git a/packages/effect/test/chat/ChatEvent.test.ts b/packages/effect/test/chat/ChatEvent.test.ts
index 936729a2a0c..f53870af250 100644
--- a/packages/effect/test/chat/ChatEvent.test.ts
+++ b/packages/effect/test/chat/ChatEvent.test.ts
@@ -1,6 +1,5 @@
 import { assert, describe, it } from "@effect/vitest"
 import * as ChatEvent from "effect/chat/ChatEvent"
-import * as Schema from "effect/Schema"
 
 const thread = { platform: "slack", id: "T1/C1/1794454017.568519" }
 
@@ -15,11 +14,6 @@ describe("ChatEvent", () => {
       raw: { event: { type: "agent_session_stopped" } }
     }
 
-    it("is a ChatEvent", () => {
-      assert.isTrue(Schema.is(ChatEvent.ChatEvent)(event))
-      assert.isTrue(Schema.is(ChatEvent.ChatEvent)({ ...event, messageIds: [] }))
-    })
-
     it("dedupeKey is stop/{thread}/{id}", () => {
       assert.strictEqual(ChatEvent.dedupeKey(event), "stop/slack:T1/C1/1794454017.568519/1794454026.522466")
       // A redelivery has the same key, whatever streams it lists.
diff --git a/packages/effect/test/chat/ChatInteraction.test.ts b/packages/effect/test/chat/ChatInteraction.test.ts
index e9b4f29f0a3..797c52da3f7 100644
--- a/packages/effect/test/chat/ChatInteraction.test.ts
+++ b/packages/effect/test/chat/ChatInteraction.test.ts
@@ -30,12 +30,6 @@ describe("ChatInteraction", () => {
       assert.strictEqual(ChatInteraction.encodeValue(Deploy, { version: "v1" }), "{\"version\":\"v1\"}")
     })
 
-    it("round-trips through a schema with a transformation", () => {
-      const encoded = ChatInteraction.encodeValue(Schema.NumberFromString, 42)
-      assert.strictEqual(encoded, "42")
-      assert.deepStrictEqual(ChatInteraction.decodeValue(Schema.NumberFromString, encoded), Option.some(42))
-    })
-
     it("gives none for a string that no longer decodes", () => {
       assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Deploy, "not json")))
       assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Deploy, "{\"version\":1}")))
@@ -57,17 +51,6 @@ describe("ChatInteraction", () => {
       assert.deepStrictEqual(Plain.of(), { _tag: "Button", id: "plain", label: "Plain" })
     })
 
-    it("select.of encodes each option and the selected one", () => {
-      const Pick = ChatInteraction.select("pick", { placeholder: "Pick", value: Schema.Number })
-      assert.deepStrictEqual(Pick.of({ options: [{ label: "One", value: 1 }], selected: 1 }), {
-        _tag: "Select",
-        id: "pick",
-        placeholder: "Pick",
-        options: [{ label: "One", value: "1" }],
-        selected: "1"
-      })
-    })
-
     it("modal.open builds the elements in field order, with encoded metadata and options", () => {
       const Reason = ChatInteraction.modal("reason", {
         title: "Why",
@@ -104,13 +87,6 @@ describe("ChatInteraction", () => {
       })
     })
 
-    it("errors builds an Errors reply", () => {
-      assert.deepStrictEqual(ChatInteraction.errors({ reason: "Say more." }), {
-        _tag: "Errors",
-        errors: { reason: "Say more." }
-      })
-    })
-
     it("respond and defer answer privately by default, and a deferral survives JSON", () => {
       assert.deepStrictEqual(ChatInteraction.respond({ markdown: "Hi" }), {
         _tag: "Respond",
@@ -240,14 +216,6 @@ describe("ChatInteraction", () => {
         refused: (_, error) => options.refused?.(error) ?? Effect.void
       })
 
-    it.effect("gives the reply inside the deadline", () =>
-      Effect.gen(function*() {
-        const reply = yield* ChatInteraction.handle(clicked("a"), deadline).pipe(
-          Effect.provideService(ChatInteraction.Handler, handlerWith({}))
-        )
-        assert.deepStrictEqual(reply, ChatInteraction.ack)
-      }))
-
     it.effect("gives Late for a late click, and refuses its modal with interaction_expired", () =>
       Effect.gen(function*() {
         const refused = yield* Deferred.make()
@@ -272,28 +240,23 @@ describe("ChatInteraction", () => {
         assert.strictEqual(error.reason.detail, ChatError.interactionExpired)
       }))
 
-    it.effect("interrupts a late submit and a late command", () =>
+    it.effect("interrupts a late command", () =>
       Effect.gen(function*() {
-        let interrupted = 0
-        const slow = (reply: A) =>
-          Effect.as(Effect.sleep("5 seconds"), reply).pipe(
-            Effect.onInterrupt(() => Effect.sync(() => void interrupted++))
-          )
+        let interrupted = false
         const handler = handlerWith({
-          submit: slow(ChatInteraction.close),
-          command: slow(ChatInteraction.respond({ markdown: "late" }))
-        })
-        const submitted = ChatInteraction.ModalSubmitted.make({ id: "m", values: {}, ...origin })
-        for (const event of [submitted, invoked("slow")]) {
-          const fiber = yield* ChatInteraction.handle(event, deadline).pipe(
-            Effect.provideService(ChatInteraction.Handler, handler),
-            Effect.forkChild
+          command: Effect.as(Effect.sleep("5 seconds"), ChatInteraction.respond({ markdown: "late" })).pipe(
+            Effect.onInterrupt(() => Effect.sync(() => void (interrupted = true)))
           )
-          yield* TestClock.adjust("3 seconds")
-          assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
-        }
-        assert.strictEqual(interrupted, 2)
+        })
+        const fiber = yield* ChatInteraction.handle(invoked("slow"), deadline).pipe(
+          Effect.provideService(ChatInteraction.Handler, handler),
+          Effect.forkChild
+        )
+        yield* TestClock.adjust("3 seconds")
+        assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
+        assert.isTrue(interrupted)
       }))
+
     it.effect("gives Late at the deadline without waiting for a late submit's cleanup", () =>
       Effect.gen(function*() {
         const cleaned = yield* Deferred.make()
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index 817f83f7d7b..f87e9abcc94 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -35,8 +35,6 @@ const feed = Effect.fnUntraced(function*(
   return { fiber, send, close, end }
 })
 
-const lone = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(? {
   describe("post", () => {
     it.effect("posts nothing for empty input", () =>
@@ -47,21 +45,6 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* test.calls, [])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("posts short Markdown as one part", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const result = yield* ChatMarkdown.post(thread, "Hello *world*")
-        assert.strictEqual(result.parts.length, 1)
-        const [part] = result.parts
-        assert.deepStrictEqual([part.markdown, part.text, part.kind, part.transport], [
-          "Hello *world*",
-          "Hello *world*",
-          "text",
-          "post"
-        ])
-        assert.deepStrictEqual(yield* texts(test, thread), ["Hello *world*"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("splits at block boundaries", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -98,16 +81,6 @@ describe("ChatMarkdown", () => {
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 50 }, measure })))
     })
 
-    it.effect("never cuts inside a surrogate pair", () =>
-      Effect.gen(function*() {
-        const { thread } = yield* setup
-        const input = "\u{1F600}".repeat(12)
-        const result = yield* ChatMarkdown.post(thread, input)
-        assert.strictEqual(result.parts.length, 3)
-        assert.strictEqual(joined(result.parts), input)
-        for (const part of result.parts) assert.isFalse(lone.test(part.markdown), part.markdown)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 5 } }))))
-
     it.effect("replies with the first part only", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -120,16 +93,6 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(replies.map((reply) => reply?.messageId), [event.message.id, undefined, undefined])
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
 
-    it.effect("runs onPart for every part", () =>
-      Effect.gen(function*() {
-        const { thread } = yield* setup
-        const seen: Array = []
-        const result = yield* ChatMarkdown.post(thread, paragraphs(3, 20), {
-          onPart: (part) => Effect.sync(() => seen.push(part.messageId))
-        })
-        assert.deepStrictEqual(seen, result.parts.map((part) => part.messageId))
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
-
     it.effect("fails with Overflow past maxParts", () =>
       Effect.gen(function*() {
         const { thread } = yield* setup
@@ -138,6 +101,7 @@ describe("ChatMarkdown", () => {
         assert.strictEqual(error.cause._tag, "Overflow")
         assert.strictEqual(error.posted.length, 2)
         assert.isUndefined(error.uncertain)
+        assert.isUndefined(error.remainingFence)
         assert.strictEqual(joined(error.posted) + error.remaining, input)
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
 
@@ -161,34 +125,6 @@ describe("ChatMarkdown", () => {
         )
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 60 } }))))
 
-    it.effect("remainingFence is unset outside a fence and when nothing remains", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const outside = yield* Effect.flip(
-          ChatMarkdown.post(thread, "```ts\ncode\n```\n\n" + paragraphs(4, 20), { maxParts: 2 })
-        )
-        assert.isTrue(outside.remaining.startsWith("Paragraph"), outside.remaining)
-        assert.isUndefined(outside.remainingFence)
-        yield* test.failNext("post", new ChatError.Forbidden({}))
-        const refused = yield* Effect.flip(ChatMarkdown.post(thread, "```ts\ncode"))
-        assert.deepStrictEqual([refused.posted, refused.remaining, refused.remainingFence], [
-          [],
-          "```ts\ncode",
-          undefined
-        ])
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
-
-    it.effect("uploads the rest past maxParts as a file", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const input = paragraphs(5, 20)
-        const result = yield* ChatMarkdown.post(thread, input, { maxParts: 2, overflow: { file: { name: "rest.md" } } })
-        assert.deepStrictEqual(result.parts.map((part) => part.kind), ["text", "text", "overflowFile"])
-        assert.strictEqual(joined(result.parts), input)
-        const last = (yield* test.messages(thread)).at(-1)!
-        assert.deepStrictEqual(last.attachments.map((attachment) => attachment.name), ["rest.md"])
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
-
     const files = [{ name: "a.txt", contentType: "text/plain", content: new TextEncoder().encode("a") }]
 
     it.effect("sends files with the last part", () =>
@@ -215,15 +151,6 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(messages.map((message) => message.attachments.length), [0])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("fails when the files are refused without a note", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        yield* test.failNext("post", new ChatError.Forbidden({ detail: "file_refused" }))
-        const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", { files }))
-        assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
-        assert.deepStrictEqual([error.posted, error.remaining], [[], "Report"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("fails on a TooLarge that does not blame the files", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -238,29 +165,6 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* texts(test, thread), [])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("ends in the unattached note when the files are too large", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        yield* test.failNext("post", new ChatError.TooLarge({ subject: "files", detail: "file_refused" }))
-        const result = yield* ChatMarkdown.post(thread, "Report", {
-          files,
-          unattachedNote: () => " (file not attached)"
-        })
-        assert.deepStrictEqual(result.parts.map((part) => part.markdown), ["Report (file not attached)"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("does not retry without the files for a failure unrelated to them", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        yield* test.failNext("post", new ChatError.Forbidden({ detail: "missing_scope" }))
-        const error = yield* Effect.flip(ChatMarkdown.post(thread, "Report", {
-          files,
-          unattachedNote: () => " (file not attached)"
-        }))
-        assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
-        assert.strictEqual((yield* test.calls).filter((call) => call.op === "post").length, 1)
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("does not post a note for an uncertain file write", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -312,6 +216,7 @@ describe("ChatMarkdown", () => {
           maxParts: 2,
           overflow: { file: { name: "rest.md" } }
         })
+        assert.deepStrictEqual(result.parts.map((part) => part.kind), ["text", "text", "overflowFile"])
         assert.strictEqual(joined(result.parts), input)
         const last = (yield* test.messages(thread)).at(-1)!
         assert.deepStrictEqual(last.attachments.map((attachment) => attachment.name), ["rest.md", "a.txt"])
@@ -322,16 +227,6 @@ describe("ChatMarkdown", () => {
     const withActions = (markdown: string, actions?: ReadonlyArray) =>
       codePoints(markdown) + 10 * (actions?.length ?? 0)
 
-    it.effect("sends actions with the last part", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const result = yield* ChatMarkdown.post(thread, paragraphs(3, 15), { actions: [button] })
-        assert.strictEqual(result.parts.length, 3)
-        const [first, , last] = result.parts
-        assert.strictEqual((yield* Effect.flip(test.click(first.messageId, "go")))._tag, "NoSuchElement")
-        assert.strictEqual((yield* test.click(last.messageId, "go")).messageId, last.messageId)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
-
     it.effect("cuts the last part earlier to leave room for the actions", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -339,6 +234,7 @@ describe("ChatMarkdown", () => {
         const input = "aaaaaaaaaa\n\nbbbbbbbbbbbbb"
         const result = yield* ChatMarkdown.post(thread, input, { actions: [button] })
         assert.deepStrictEqual(result.parts.map((part) => part.text), ["aaaaaaaaaa\n\n", "bbbbbbbbbbbbb"])
+        assert.strictEqual((yield* Effect.flip(test.click(result.parts[0].messageId, "go")))._tag, "NoSuchElement")
         yield* test.click(result.parts[1].messageId, "go")
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
 
@@ -415,15 +311,6 @@ describe("ChatMarkdown", () => {
         yield* test.click(result.parts[2].messageId, "go")
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
 
-    it.effect("never cuts inside a grapheme cluster to leave room for the actions", () =>
-      Effect.gen(function*() {
-        const { thread } = yield* setup
-        const input = "1234567890a\u0301" + "b".repeat(13)
-        const result = yield* ChatMarkdown.post(thread, input, { actions: [button] })
-        assert.strictEqual(joined(result.parts), input)
-        for (const part of result.parts) assert.isFalse(part.text.startsWith("\u0301"), part.text)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: costing(19) }))))
-
     it.effect("never cuts inside a grapheme cluster on a hard cut", () =>
       Effect.gen(function*() {
         const { thread } = yield* setup
@@ -520,35 +407,27 @@ describe("ChatMarkdown", () => {
         ])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    for (const prefix of ["~~~\n", "x".repeat(301)]) {
-      for (
-        const [first, rest, whole] of [
-          ["🇺", "🇸", "🇺🇸"],
-          ["🇺\uD83C", "\uDDF8", "🇺🇸"],
-          ["1", "\uFE0F\u20E3", "1️⃣"]
-        ]
-      ) {
-        it.effect(
-          `holds ${whole} split at ${first.length} across deltas ${
-            prefix === "~~~\n" ? "inside a fence" : "in a long line"
-          }`,
-          () =>
-            Effect.gen(function*() {
-              const { test, thread } = yield* setup
-              const { end, send } = yield* feed(thread, { recipient: "U1" })
-              yield* send(prefix + first)
-              assert.deepStrictEqual((yield* test.calls).map((call) => call.markdown), [prefix])
-              yield* send(rest + "\n")
-              assert.deepStrictEqual((yield* test.calls).map((call) => call.markdown), [prefix, whole + "\n"])
-              yield* send("z")
-              const result = yield* end
-              assert.strictEqual(joined(result.parts), prefix + whole + "\nz")
-              assert.deepStrictEqual(yield* texts(test, thread), [
-                prefix + whole + "\nz" + (prefix === "~~~\n" ? "\n~~~" : "")
-              ])
-            }).pipe(Effect.provide(ChatTest.layer()))
-        )
-      }
+    for (
+      const [where, prefix, first, rest, whole, close] of [
+        // A delta that ends in half a surrogate pair, inside a fence where whole lines are not held.
+        ["inside a fence", "~~~\n", "🇺\uD83C", "\uDDF8", "🇺🇸", "\n~~~"],
+        // A line past the hold limit with no whitespace to release up to.
+        ["in a long line", "x".repeat(301), "1", "\uFE0F\u20E3", "1️⃣", ""]
+      ]
+    ) {
+      it.effect(`holds a grapheme cluster split across deltas ${where}`, () =>
+        Effect.gen(function*() {
+          const { test, thread } = yield* setup
+          const { end, send } = yield* feed(thread, { recipient: "U1" })
+          yield* send(prefix + first)
+          assert.deepStrictEqual((yield* test.calls).map((call) => call.markdown), [prefix])
+          yield* send(rest + "\n")
+          assert.deepStrictEqual((yield* test.calls).map((call) => call.markdown), [prefix, whole + "\n"])
+          yield* send("z")
+          const result = yield* end
+          assert.strictEqual(joined(result.parts), prefix + whole + "\nz")
+          assert.deepStrictEqual(yield* texts(test, thread), [prefix + whole + "\nz" + close])
+        }).pipe(Effect.provide(ChatTest.layer())))
     }
 
     it.effect("rolls a native stream over at a block boundary", () =>
@@ -657,38 +536,6 @@ describe("ChatMarkdown", () => {
         assert.strictEqual(joined(result.parts), "one\ntwo\n")
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("repairs by edit after three retry failures", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { end, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("one\n")
-        yield* test.failNext("nativeStream.append", new ChatError.RateLimited({}), { times: 3 })
-        yield* send("two\n")
-        yield* send("three\n")
-        const result = yield* end
-        assert.deepStrictEqual(result.parts.map((part) => [part.transport, part.text]), [[
-          "native",
-          "one\ntwo\nthree\n"
-        ]])
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree\n"])
-        const ops = (yield* test.calls).map((call) => call.op)
-        assert.deepStrictEqual(ops.filter((op) => op === "nativeStream.append").length, 3)
-        assert.include(ops, "edit")
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("repairs by edit after an uncertain append", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { end, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("one\n")
-        yield* test.failNext("nativeStream.append", new ChatError.Unknown({}), { landed: true })
-        yield* send("two\n")
-        yield* send("three\n")
-        const result = yield* end
-        assert.strictEqual(joined(result.parts), "one\ntwo\nthree\n")
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree\n"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("fails on a denied append, after stopping the stream", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -712,15 +559,6 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* texts(test, thread), ["```ts\ncode\nmore\n```"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("finishes what was received when interrupted", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { fiber, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("```ts\ncode\n")
-        yield* Fiber.interrupt(fiber)
-        assert.deepStrictEqual(yield* texts(test, thread), ["```ts\ncode\n```"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("does not post again when interrupted while onPart runs", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -737,9 +575,7 @@ describe("ChatMarkdown", () => {
         yield* Deferred.succeed(release, undefined)
         yield* Fiber.join(interrupt)
         assert.deepStrictEqual(yield* texts(test, thread), ["hello\n"])
-        const ops = (yield* test.calls).map((call) => call.op)
-        assert.deepStrictEqual(ops.filter((op) => op === "nativeStream.start").length, 1)
-        assert.include(ops, "nativeStream.stop")
+        assert.include((yield* test.calls).map((call) => call.op), "nativeStream.stop")
       }).pipe(Effect.provide(ChatTest.layer())))
 
     it.effect("repairs with the retried chunk while the upstream is paused", () =>
@@ -801,21 +637,6 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* texts(test, thread), ["```ts\none\n```", "```ts\ntwo\n```"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("rotates a native stream on age", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { end, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("one\n")
-        yield* TestClock.adjust("9 minutes")
-        yield* send("two\n")
-        const result = yield* end
-        assert.deepStrictEqual(result.parts.map((part) => [part.transport, part.text]), [["native", "one\n"], [
-          "native",
-          "two\n"
-        ]])
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\n", "two\n"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("takes the text that arrived while waiting for the write interval", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -834,15 +655,6 @@ describe("ChatMarkdown", () => {
         assert.strictEqual(joined(result.parts), "a\nb\nc\n")
       }).pipe(Effect.provide(ChatTest.layer({ limits: { minWriteInterval: Duration.seconds(1) } }))))
 
-    it.effect("fails with Overflow past maxParts", () =>
-      Effect.gen(function*() {
-        const { thread } = yield* setup
-        const input = paragraphs(5, 20)
-        const error = yield* Effect.flip(ChatMarkdown.stream(thread, Stream.make(input), { maxParts: 1 }))
-        assert.strictEqual(error.cause._tag, "Overflow")
-        assert.strictEqual(joined(error.posted) + error.remaining, input)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
-
     /** Registers the test adapter with its native stream changed by `f`. */
     const patchNative = Effect.fnUntraced(function*(
       f: (native: ChatAdapter.NativeStream) => Partial
@@ -995,118 +807,30 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* texts(test, thread), ["one\n"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("keeps the answer of an append in flight when the upstream fails", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { entered, release } = yield* holdFirstAppend()
-        const { fiber, queue } = yield* feedFailable(thread)
-        yield* Queue.offer(queue, "one\n")
-        yield* settle
-        yield* Queue.offer(queue, "two\n")
-        yield* Deferred.await(entered)
-        yield* Queue.offer(queue, "three")
-        yield* Queue.fail(queue, "boom")
-        yield* settle
-        yield* Deferred.succeed(release, undefined)
-        const error = yield* Fiber.join(fiber)
-        assert.deepStrictEqual(error.cause, { _tag: "Upstream", error: "boom" })
-        assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], [
-          "one\ntwo\nthree",
-          undefined,
-          ""
-        ])
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("bounds an append begun while finishing after the upstream fails", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { entered, release, state } = yield* holdFirstAppend()
-        const { fiber, queue } = yield* feedFailable(thread)
-        yield* Queue.offer(queue, "one\n")
-        yield* settle
-        yield* Queue.offer(queue, "two")
-        yield* settle
-        yield* Queue.fail(queue, "boom")
-        yield* Deferred.await(entered)
-        yield* TestClock.adjust("6 seconds")
-        const finished = fiber.pollUnsafe() !== undefined
-        yield* Deferred.succeed(release, undefined)
-        const error = yield* Fiber.join(fiber)
-        assert.isTrue(finished)
-        assert.isTrue(state.cancelled)
-        assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", "two", ""])
-        yield* settle
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\n"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    /** Holds the first stop until `release` completes. */
-    const holdFirstStop = Effect.fnUntraced(function*() {
-      const entered = yield* Deferred.make()
-      const release = yield* Deferred.make()
-      let first = true
-      yield* patchNative((native) => ({
-        stop: (...args) =>
-          Effect.suspend(() => {
-            if (!first) return native.stop(...args)
-            first = false
-            return Effect.andThen(
-              Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)),
-              native.stop(...args)
-            )
-          })
-      }))
-      return { entered, release }
-    })
-
-    for (const failUpstream of [false, true]) {
-      it.effect(
-        failUpstream
-          ? "stops the stream after a denied append when the upstream then fails"
-          : "stops the stream after a denied append",
-        () =>
-          Effect.gen(function*() {
-            const { test, thread } = yield* setup
-            const chat = yield* Chat.Chat
-            const { entered, release } = yield* holdFirstStop()
-            const queue = yield* Queue.unbounded()
-            const ids: Array = []
-            const fiber = yield* Effect.forkChild(Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), {
-              recipient: "U1",
-              onPart: (part) => Effect.sync(() => void ids.push(part.messageId))
-            })))
-            yield* Queue.offer(queue, "one\n")
-            yield* settle
-            yield* test.failNext("nativeStream.append", new ChatError.Forbidden({}))
-            yield* Queue.offer(queue, "two\n")
-            yield* Deferred.await(entered)
-            if (failUpstream) yield* Queue.fail(queue, "boom")
-            yield* settle
-            yield* Deferred.succeed(release, undefined)
-            const error = yield* Fiber.join(fiber)
-            assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
-            assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], [
-              "one\n",
-              undefined,
-              "two\n"
-            ])
-            const ops = (yield* test.calls).map((call) => call.op)
-            assert.strictEqual(ops.filter((op) => op === "nativeStream.append").length, 1)
-            assert.deepStrictEqual(yield* texts(test, thread), ["one\n"])
-            yield* chat.edit(thread, ids[0], { markdown: "edited" })
-          }).pipe(Effect.provide(ChatTest.layer()))
-      )
-    }
-
-    it.effect("bounds the stop of a failed reply by the finish timeout when the upstream fails", () =>
+    it.effect("stops the stream after a denied append when the upstream then fails", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
+        const chat = yield* Chat.Chat
         const entered = yield* Deferred.make()
-        yield* patchNative(() => ({ stop: () => Effect.andThen(Deferred.succeed(entered, undefined), Effect.never) }))
+        const release = yield* Deferred.make()
+        let first = true
+        yield* patchNative((native) => ({
+          stop: (...args) =>
+            Effect.suspend(() => {
+              if (!first) return native.stop(...args)
+              first = false
+              return Effect.andThen(
+                Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)),
+                native.stop(...args)
+              )
+            })
+        }))
         const queue = yield* Queue.unbounded()
-        const fiber = yield* Effect.forkChild(
-          Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), { recipient: "U1" }))
-        )
+        const ids: Array = []
+        const fiber = yield* Effect.forkChild(Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), {
+          recipient: "U1",
+          onPart: (part) => Effect.sync(() => void ids.push(part.messageId))
+        })))
         yield* Queue.offer(queue, "one\n")
         yield* settle
         yield* test.failNext("nativeStream.append", new ChatError.Forbidden({}))
@@ -1114,30 +838,12 @@ describe("ChatMarkdown", () => {
         yield* Deferred.await(entered)
         yield* Queue.fail(queue, "boom")
         yield* settle
-        yield* TestClock.adjust("6 seconds")
+        yield* Deferred.succeed(release, undefined)
         const error = yield* Fiber.join(fiber)
         assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
-        assert.deepStrictEqual([joined(error.posted), error.remaining], ["one\n", "two\n"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("stops the stream after a denied append when interrupted during the stop", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const chat = yield* Chat.Chat
-        const { entered } = yield* holdFirstStop()
-        const ids: Array = []
-        const { fiber, send } = yield* feed(thread, {
-          recipient: "U1",
-          onPart: (part) => Effect.sync(() => void ids.push(part.messageId))
-        })
-        yield* send("one\n")
-        yield* test.failNext("nativeStream.append", new ChatError.Forbidden({}))
-        yield* send("two\n")
-        yield* Deferred.await(entered)
-        yield* Fiber.interrupt(fiber)
-        const ops = (yield* test.calls).map((call) => call.op)
-        assert.strictEqual(ops.filter((op) => op === "nativeStream.append").length, 1)
+        assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", undefined, "two\n"])
         assert.deepStrictEqual(yield* texts(test, thread), ["one\n"])
+        // An open native stream would refuse the edit.
         yield* chat.edit(thread, ids[0], { markdown: "edited" })
       }).pipe(Effect.provide(ChatTest.layer())))
 
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index af61e9b1551..5fbba7c3fc2 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -1,5 +1,5 @@
 import { assert, describe, it } from "@effect/vitest"
-import { Effect, Exit, Option, Schema, Stream } from "effect"
+import { Effect, Exit, Option } from "effect"
 import {
   Chat,
   ChatAdapter,
@@ -8,8 +8,7 @@ import {
   ChatInteraction,
   ChatMessage,
   ChatTest,
-  ChatThread,
-  ChatUi
+  ChatThread
 } from "effect/chat"
 
 const kinds = { "@": "user", "@&": "role", "#": "channel", "!": "broadcast" } as const
@@ -82,93 +81,43 @@ const runRule = (rule: string, options?: Parameters[0]) =
   Effect.flatMap(suite, (rules) => rules[rule]).pipe(Effect.provide(ChatTest.layer(options)))
 
 describe("ChatTest", () => {
-  it("omits post/refusedFile without its hook", () => {
-    const rules = ChatTest.conformance({
-      platform: "test",
-      thread: ChatThread.make("test", "c0"),
-      userPosts: () => Effect.die("unused"),
-      parseMention
-    })
-    assert.isUndefined(rules["post/refusedFile"])
-  })
-
-  it.effect("refuseFiles counts only posts with files and leaves nothing posted", () =>
-    Effect.gen(function*() {
-      const test = yield* ChatTest.ChatTest
-      const chat = yield* Chat.Chat
-      const thread = yield* test.makeThread()
-      const files = [{ name: "a.txt", contentType: "text/plain", content: new Uint8Array([1]) }]
-      yield* test.refuseFiles({ times: 2 })
-      yield* chat.post(thread, { markdown: "text only" })
-      for (let i = 0; i < 2; i++) {
-        const error = yield* Effect.flip(chat.post(thread, { markdown: "refused", files }))
-        assert.strictEqual(error.reason.retry, "denied")
-        assert.strictEqual(error.reason.detail, ChatError.fileRefused)
-      }
-      assert.deepStrictEqual((yield* test.messages(thread)).map((message) => message.text), ["text only"])
-      yield* chat.post(thread, { markdown: "accepted", files })
-      assert.strictEqual((yield* test.messages(thread)).length, 2)
-    }).pipe(Effect.provide(ChatTest.layer())))
-
   describe("conformance with every capability", () => {
     for (const rule of ruleNames) {
       it.live(rule, () => runRule(rule))
     }
   })
 
-  for (const off of capabilities) {
-    describe(`conformance without ${off}`, () => {
-      for (const rule of ruleNames) {
-        it.live(rule, () => runRule(rule, { capabilities: capabilities.filter((c) => c !== off) }))
-      }
-    })
-  }
+  describe("conformance without any capability", () => {
+    for (const rule of ruleNames) {
+      it.live(rule, () => runRule(rule, { capabilities: [] }))
+    }
+  })
 
-  it.effect("post/refusedFile rejects Unsupported for a listed capability", () =>
-    Effect.gen(function*() {
-      const test = yield* ChatTest.ChatTest
-      const thread = yield* test.makeThread()
-      const rules = ChatTest.conformance({
-        platform: test.platform,
-        thread,
-        parseMention,
-        userPosts: (thread, text) => test.userPosts(thread, { text }),
-        refuseFiles: () =>
-          test.failNext(
-            "post",
-            new ChatError.Unsupported({
-              capability: "files",
-              detail: ChatError.fileRefused
-            })
-          )
-      })
-      const error = yield* Effect.flip(rules["post/refusedFile"])
-      assert.strictEqual(error.rule, "post/refusedFile")
-      assert.strictEqual(error.actual, "Unsupported(files) for a listed capability")
-    }).pipe(Effect.provide(ChatTest.layer())))
+  // These rules probe their capability only while the one it builds on is on.
+  for (
+    const [rule, off] of [
+      ["unsupported/modals", "modals"],
+      ["modal/errorsKeepOpen", "modalErrors"],
+      ["unsupported/ephemeral", "ephemeral"]
+    ] as const
+  ) {
+    it.live(`conformance ${rule} without ${off}`, () =>
+      runRule(rule, { capabilities: capabilities.filter((c) => c !== off) }))
+  }
 
-  it.effect("post/refusedFile cleans up a refused write that landed", () =>
-    Effect.gen(function*() {
-      const test = yield* ChatTest.ChatTest
-      const thread = yield* test.makeThread()
-      const rules = ChatTest.conformance({
-        platform: test.platform,
-        thread,
-        parseMention,
-        userPosts: (thread, text) => test.userPosts(thread, { text }),
-        refuseFiles: () =>
-          test.failNext(
-            "post",
-            new ChatError.Forbidden({
-              detail: ChatError.fileRefused
-            }),
-            { landed: true }
-          )
-      })
-      const error = yield* Effect.flip(rules["post/refusedFile"])
-      assert.strictEqual(error.expected, "no new message")
-      assert.deepStrictEqual(yield* test.messages(thread), [])
-    }).pipe(Effect.provide(ChatTest.layer())))
+  it("lists the hook rules only with their hooks", () => {
+    const withoutHooks = Object.keys(ChatTest.conformance({
+      platform: "test",
+      thread: ChatThread.make("test", "c0"),
+      userPosts: () => Effect.die("unused"),
+      parseMention
+    }))
+    assert.include(withoutHooks, "unsupported/buttons")
+    for (const name of ["post/refusedFile", "actions/valueRoundTrips", "command/arrives", "retries/retrySafe"]) {
+      assert.notInclude(withoutHooks, name)
+      assert.include(ruleNames, name)
+    }
+  })
 
   it.effect("fails unsupported/{capability} for a descriptor that leaves out a working op", () =>
     Effect.gen(function*() {
@@ -201,239 +150,23 @@ describe("ChatTest", () => {
       assert.strictEqual(failure.actual, "Unsupported(edit) for a listed capability")
     }).pipe(Effect.provide(ChatTest.layer())))
 
-  it.effect("fails unsupported/{capability} for a listed op that fails with Unsupported", () =>
+  it.effect("post/refusedFile cleans up a refused write that landed", () =>
     Effect.gen(function*() {
-      const registry = yield* ChatAdapter.Registry
-      const adapter = yield* registry.get("test")
-      const unsupported = (capability: ChatError.Capability) =>
-        Effect.fail(
-          new ChatError.ChatError({
-            platform: "test",
-            op: capability,
-            reason: new ChatError.Unsupported({ capability })
-          })
-        )
-      const listed = new Set(adapter.descriptor.capabilities)
-      listed.delete("opener")
-      yield* registry.register({
-        ...adapter,
-        descriptor: { ...adapter.descriptor, capabilities: listed },
-        getThread: () => unsupported("getThread"),
-        // names a capability the descriptor does leave out, but not the one probed
-        getUser: () => unsupported("opener")
+      const test = yield* ChatTest.ChatTest
+      const thread = yield* test.makeThread()
+      const rules = ChatTest.conformance({
+        platform: test.platform,
+        thread,
+        parseMention,
+        userPosts: (thread, text) => test.userPosts(thread, { text }),
+        refuseFiles: () =>
+          test.failNext("post", new ChatError.Forbidden({ detail: ChatError.fileRefused }), { landed: true })
       })
-      const rules = yield* suite
-      const getThread = yield* Effect.flip(rules["unsupported/getThread"])
-      assert.strictEqual(getThread.actual, "Unsupported(getThread)")
-      const getUser = yield* Effect.flip(rules["unsupported/getUser"])
-      assert.strictEqual(getUser.actual, "Unsupported(opener)")
+      const error = yield* Effect.flip(rules["post/refusedFile"])
+      assert.strictEqual(error.expected, "no new message")
+      assert.deepStrictEqual(yield* test.messages(thread), [])
     }).pipe(Effect.provide(ChatTest.layer())))
 
-  describe("buttons and modals", () => {
-    const Approve = ChatInteraction.button("approve", { label: "Approve", value: Schema.Number })
-    const Pick = ChatInteraction.select("pick", {})
-    const Ask = ChatInteraction.modal("ask", {
-      title: "Ask",
-      metadata: Schema.String,
-      fields: { answer: ChatInteraction.textInput({ label: "Answer", optional: true }) }
-    })
-    const replying = (reply: ChatInteraction.ClickReply, refused: Array) =>
-      ChatInteraction.Handler.of({
-        click: () => Effect.succeed(reply),
-        submit: () => Effect.succeed(ChatInteraction.close),
-        command: () => Effect.succeed(ChatInteraction.ack),
-        refused: (_, error) => Effect.sync(() => void refused.push(error))
-      })
-
-    it("lists the hook rules only with the hook, and unsupported/buttons always", () => {
-      const withoutHook = Object.keys(ChatTest.conformance({
-        platform: "test",
-        thread: ChatThread.make("test", "c0"),
-        userPosts: () => Effect.die("unused"),
-        parseMention
-      }))
-      for (
-        const name of ["unsupported/buttons", "unsupported/selects", "actions/tooMany", "descriptor/measureFitsActions"]
-      ) {
-        assert.include(withoutHook, name)
-      }
-      for (const name of ["actions/valueRoundTrips", "modal/origin", "unsupported/modals", "command/arrives"]) {
-        assert.notInclude(withoutHook, name)
-        assert.include(ruleNames, name)
-      }
-      assert.notInclude(ruleNames, "unsupported/modalErrors")
-    })
-
-    it.effect("fails Unsupported for an element whose capability is off", () =>
-      Effect.gen(function*() {
-        const thread = yield* Effect.flatMap(ChatTest.ChatTest, (test) => test.makeThread())
-        const chat = yield* Chat.Chat
-        const button = yield* Effect.flip(chat.post(thread, { markdown: "a", actions: [Approve.of(1)] }))
-        assert.strictEqual(button.reason._tag === "Unsupported" && button.reason.capability, "buttons")
-        const selectError = yield* Effect.flip(chat.post(thread, {
-          markdown: "a",
-          actions: [Pick.of({ options: [{ label: "A", value: "a" }] })]
-        }))
-        assert.strictEqual(selectError.reason._tag === "Unsupported" && selectError.reason.capability, "selects")
-      }).pipe(Effect.provide(ChatTest.layer({
-        capabilities: capabilities.filter((c) => c !== "buttons" && c !== "selects")
-      }))))
-
-    it.effect("checks actionsPerMessage and actionDataLength in code points", () =>
-      Effect.gen(function*() {
-        const test = yield* ChatTest.ChatTest
-        const chat = yield* Chat.Chat
-        const thread = yield* test.makeThread()
-        const many = yield* Effect.flip(chat.post(thread, {
-          markdown: "a",
-          actions: [Approve.of(1), Approve.of(2), Approve.of(3)]
-        }))
-        assert.strictEqual(many.reason._tag, "TooLarge")
-        // "approve" is 7 and "12" is 2: 9 code points fit, 10 do not.
-        yield* chat.post(thread, { markdown: "a", actions: [Approve.of(12)] })
-        const long = yield* Effect.flip(chat.post(thread, { markdown: "a", actions: [Approve.of(123)] }))
-        assert.strictEqual(long.reason._tag, "TooLarge")
-        assert.strictEqual((yield* test.messages(thread)).length, 1)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { actionsPerMessage: 2, actionDataLength: 9 } }))))
-
-    it.effect("click builds the event from what was posted or edited", () =>
-      Effect.gen(function*() {
-        const test = yield* ChatTest.ChatTest
-        const chat = yield* Chat.Chat
-        const thread = yield* test.makeThread()
-        const posted = yield* chat.post(thread, {
-          markdown: "a",
-          actions: [
-            Approve.of(7),
-            Pick.of({ options: [{ label: "A", value: "a" }, { label: "B", value: "b" }] }),
-            ChatUi.linkButton({ label: "Docs", url: "https://effect.website" })
-          ]
-        })
-        const click = yield* test.click(posted.id, "approve", { userId: "u2" })
-        assert.strictEqual(click._tag, "ButtonClicked")
-        assert.strictEqual(click.value, "7")
-        assert.strictEqual(click.userId, "u2")
-        assert.strictEqual(click.messageId, posted.id)
-        yield* ChatTest.checkInteraction(click, { platform: "test" })
-        const first = yield* test.click(posted.id, "pick")
-        assert.strictEqual(first._tag === "SelectChanged" && first.value, "a")
-        const second = yield* test.click(posted.id, "pick", { option: "b" })
-        assert.strictEqual(second._tag === "SelectChanged" && second.value, "b")
-        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "pick", { option: "c" })))._tag, "NoSuchElement")
-        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "missing")))._tag, "NoSuchElement")
-        yield* chat.edit(thread, posted.id, { markdown: "b" })
-        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "approve")))._tag, "NoSuchElement")
-        yield* chat.delete(thread, posted.id)
-        assert.strictEqual((yield* Effect.flip(test.click(posted.id, "approve")))._tag, "NoSuchElement")
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("submit keeps the click's origin and leaves out empty values", () =>
-      Effect.gen(function*() {
-        const test = yield* ChatTest.ChatTest
-        const chat = yield* Chat.Chat
-        const thread = yield* test.makeThread()
-        const posted = yield* chat.post(thread, { markdown: "a", actions: [Approve.of(1)] })
-        const click = yield* test.click(posted.id, "approve")
-        const submitted = yield* test.submit(click, Ask.open({ metadata: "m" }), { answer: "" })
-        assert.strictEqual(submitted.id, "ask")
-        assert.strictEqual(submitted.metadata, "m")
-        assert.deepStrictEqual(submitted.values, {})
-        assert.strictEqual(submitted.messageId, posted.id)
-        yield* ChatTest.checkInteraction(submitted, { platform: "test" })
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("interact refuses a modal the fake would not open, and records openModal", () =>
-      Effect.gen(function*() {
-        const test = yield* ChatTest.ChatTest
-        const chat = yield* Chat.Chat
-        const thread = yield* test.makeThread()
-        const posted = yield* chat.post(thread, { markdown: "a", actions: [Approve.of(1)] })
-        const click = yield* test.click(posted.id, "approve")
-        const refused: Array = []
-        const opened = Ask.open({ metadata: "x".repeat(10) })
-        const reply = yield* test.interact(click).pipe(
-          Effect.provideService(ChatInteraction.Handler, replying(opened, refused))
-        )
-        assert.deepStrictEqual(reply, opened)
-        assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag]), [["openModal", "TooLarge"]])
-        const calls = (yield* test.calls).filter((call) => call.op === "openModal")
-        assert.deepStrictEqual(calls.map((call) => [call.messageId, call.outcome]), [[posted.id, "TooLarge"]])
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { modalMetadataLength: 12 } }))))
-
-    it.effect("interact refuses any modal without the modals capability", () =>
-      Effect.gen(function*() {
-        const test = yield* ChatTest.ChatTest
-        const chat = yield* Chat.Chat
-        const thread = yield* test.makeThread()
-        const posted = yield* chat.post(thread, { markdown: "a", actions: [Approve.of(1)] })
-        const refused: Array = []
-        yield* test.interact(yield* test.click(posted.id, "approve")).pipe(
-          Effect.provideService(ChatInteraction.Handler, replying(Ask.open({ metadata: "m" }), refused))
-        )
-        const reason = refused[0]?.reason
-        assert.strictEqual(reason?._tag === "Unsupported" && reason.capability, "modals")
-      }).pipe(Effect.provide(ChatTest.layer({ capabilities: capabilities.filter((c) => c !== "modals") }))))
-
-    it("lists the command rules only with the hook's command, and unsupported/commands always", () => {
-      const withoutCommand = Object.keys(ChatTest.conformance({
-        platform: "test",
-        thread: ChatThread.make("test", "c0"),
-        userPosts: () => Effect.die("unused"),
-        parseMention,
-        interactions: { click: () => Effect.void, submit: () => Effect.void }
-      }))
-      assert.include(withoutCommand, "unsupported/commands")
-      assert.include(withoutCommand, "modal/origin")
-      for (const name of ["command/followUp", "command/modalOrigin", "unsupported/ephemeral"]) {
-        assert.notInclude(withoutCommand, name)
-        assert.include(ruleNames, name)
-      }
-    })
-
-    it.effect("checkInteraction rejects a submit with an empty messageId and a foreign platform", () =>
-      Effect.gen(function*() {
-        const submitted = ChatInteraction.ModalSubmitted.make({
-          id: "ask",
-          values: {},
-          thread: ChatThread.make("test", "c1"),
-          messageId: "",
-          userId: "u",
-          raw: null
-        })
-        const empty = yield* Effect.flip(ChatTest.checkInteraction(submitted, { platform: "test" }))
-        assert.strictEqual(empty.actual, "an empty messageId")
-        const foreign = yield* Effect.flip(ChatTest.checkInteraction(submitted, { platform: "other" }))
-        assert.strictEqual(foreign.rule, "checkInteraction")
-      }))
-
-    it.effect("fails unsupported/buttons for an adapter that ignores actions", () =>
-      Effect.gen(function*() {
-        const registry = yield* ChatAdapter.Registry
-        const adapter = yield* registry.get("test")
-        const listed = new Set(adapter.descriptor.capabilities)
-        listed.delete("buttons")
-        yield* registry.register({ ...adapter, descriptor: { ...adapter.descriptor, capabilities: listed } })
-        const failure = yield* Effect.flip(Effect.flatMap(suite, (rules) => rules["unsupported/buttons"]))
-        assert.strictEqual(failure.actual, "success")
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("fails edit/removesActions for an adapter that keeps the elements on edit", () =>
-      Effect.gen(function*() {
-        const registry = yield* ChatAdapter.Registry
-        const adapter = yield* registry.get("test")
-        yield* registry.register({
-          ...adapter,
-          edit: (thread, messageId, content) =>
-            adapter.edit(thread, messageId, {
-              markdown: content.markdown,
-              actions: [ChatInteraction.button("conformance", { label: "kept" }).of()]
-            })
-        })
-        const failure = yield* Effect.flip(Effect.flatMap(suite, (rules) => rules["edit/removesActions"]))
-        assert.strictEqual(failure.expected, "NoSuchElement")
-      }).pipe(Effect.provide(ChatTest.layer())))
-  })
-
   it.live("deletes every bot message the suite posts", () =>
     Effect.gen(function*() {
       const test = yield* ChatTest.ChatTest
@@ -448,9 +181,8 @@ describe("ChatTest", () => {
       const test = yield* ChatTest.ChatTest
       const thread = yield* test.makeThread()
       const event = yield* test.userPosts(thread, { text: "hi", mentionsSelf: true })
-      yield* ChatTest.checkEvent(event, { platform: "test", parseMention })
-      assert.strictEqual(event._tag, "MessageCreated")
-      if (event._tag !== "MessageCreated") return
+      assert(event._tag === "MessageCreated")
+      yield* ChatTest.checkMessage(event.message, { platform: "test", parseMention })
       const shifted = {
         ...event.message,
         mentions: event.message.mentions.map((mention) => ({ ...mention, start: mention.start + 1 }))
@@ -459,7 +191,21 @@ describe("ChatTest", () => {
       assert.isTrue(Exit.isFailure(exit))
     }).pipe(Effect.provide(ChatTest.layer())))
 
-  it.effect("repliesToSelf is true for a reply to the bot's message, and is not a mention", () =>
+  it.effect("checkInteraction rejects an empty messageId", () =>
+    Effect.gen(function*() {
+      const submitted = ChatInteraction.ModalSubmitted.make({
+        id: "ask",
+        values: {},
+        thread: ChatThread.make("test", "c1"),
+        messageId: "",
+        userId: "u",
+        raw: null
+      })
+      const failure = yield* Effect.flip(ChatTest.checkInteraction(submitted, { platform: "test" }))
+      assert.strictEqual(failure.actual, "an empty messageId")
+    }))
+
+  it.effect("repliesToSelf is true only for a reply to the bot's message, and is not a mention", () =>
     Effect.gen(function*() {
       const test = yield* ChatTest.ChatTest
       const chat = yield* Chat.Chat
@@ -472,21 +218,9 @@ describe("ChatTest", () => {
       const plain = message(yield* test.userPosts(thread, { text: "no reply" }))
       const toBot = message(yield* test.userPosts(thread, { text: "to the bot", replyTo: { messageId: own.id } }))
       const toUser = message(yield* test.userPosts(thread, { text: "to a person", replyTo: { messageId: plain.id } }))
-      const toGone = message(yield* test.userPosts(thread, { text: "to nothing", replyTo: { messageId: "gone" } }))
-      assert.deepStrictEqual(toBot.replyTo, { messageId: own.id, authorId: test.selfId, isSelf: true })
-      assert.deepStrictEqual(toUser.replyTo, { messageId: plain.id, authorId: "user", isSelf: false })
-      assert.deepStrictEqual(toGone.replyTo, { messageId: "gone" })
-      assert.deepStrictEqual(
-        [plain, toBot, toUser, toGone].map(ChatMessage.repliesToSelf),
-        [false, true, false, false]
-      )
-      // A reply is still not a mention.
+      assert.deepStrictEqual([plain, toBot, toUser].map(ChatMessage.repliesToSelf), [false, true, false])
       assert.isFalse(ChatMessage.mentionsSelf(toBot))
-      for (const read of [toBot, toUser, toGone]) yield* ChatTest.checkMessage(read, { platform: "test", parseMention })
-      // History reads the same.
-      const history = yield* chat.fetchMessage(thread, toBot.id)
-      assert.isTrue(ChatMessage.repliesToSelf(history))
-      // An author without isSelf, or isSelf without an author, is not a message an adapter may read.
+      // checkMessage rejects an author without isSelf, and isSelf without an author.
       for (const replyTo of [{ messageId: own.id, authorId: test.selfId }, { messageId: own.id, isSelf: true }]) {
         const exit = yield* Effect.exit(
           ChatTest.checkMessage({ ...toBot, replyTo }, { platform: "test", parseMention })
@@ -495,28 +229,6 @@ describe("ChatTest", () => {
       }
     }).pipe(Effect.provide(ChatTest.layer())))
 
-  it.effect("Stream.mkUint8Array collects a download into the file's bytes", () =>
-    Effect.gen(function*() {
-      const test = yield* ChatTest.ChatTest
-      const chat = yield* Chat.Chat
-      const thread = yield* test.makeThread()
-      // Larger than one chunk of the fake's download.
-      const content = Uint8Array.from({ length: 3000 }, (_, i) => i % 251)
-      const event = yield* test.userPosts(thread, {
-        text: "a file",
-        files: [{ name: "data.bin", contentType: "application/octet-stream", content }]
-      })
-      assert(event._tag === "MessageCreated")
-      const [attachment] = event.message.attachments
-      const download = chat.download(thread, attachment, { maxBytes: content.length })
-      assert.isAbove((yield* Stream.runCollect(download)).length, 1)
-      assert.deepStrictEqual(yield* Stream.mkUint8Array(download), content)
-      const error = yield* Effect.flip(
-        Stream.mkUint8Array(chat.download(thread, attachment, { maxBytes: content.length - 1 }))
-      )
-      assert.strictEqual(error.reason._tag, "TooLarge")
-    }).pipe(Effect.provide(ChatTest.layer())))
-
   it.effect("ChatHandler.layer drops the bot's own messages unless deliverSelf", () =>
     Effect.gen(function*() {
       const test = yield* ChatTest.ChatTest
@@ -535,31 +247,4 @@ describe("ChatTest", () => {
       )))
       assert.deepStrictEqual(received, ["MessageCreated", "self MessageCreated"])
     }).pipe(Effect.provide(ChatTest.layer())))
-
-  it.effect("checks lengths with the configured measure", () =>
-    Effect.gen(function*() {
-      const test = yield* ChatTest.ChatTest
-      const chat = yield* Chat.Chat
-      const thread = yield* test.makeThread()
-      yield* chat.post(thread, { markdown: "x".repeat(10) })
-      const exit = yield* Effect.exit(chat.post(thread, { markdown: "<".repeat(3) }))
-      assert.isTrue(Exit.isFailure(exit))
-      const error = Exit.isFailure(exit) ? Option.getOrUndefined(Exit.findErrorOption(exit)) : undefined
-      assert.strictEqual(error?.reason._tag, "TooLarge")
-    }).pipe(Effect.provide(ChatTest.layer({
-      limits: { messageLength: 10 },
-      measure: (markdown) => markdown.length + 3 * (markdown.split("<").length - 1)
-    }))))
-
-  it.effect("the native stream holds a trailing high surrogate and stores any other lone one as U+FFFD", () =>
-    Effect.gen(function*() {
-      const test = yield* ChatTest.ChatTest
-      const native = (yield* (yield* ChatAdapter.Registry).get("test")).nativeStream!
-      const thread = yield* test.makeThread()
-      const posted = yield* native.start(thread, { markdown: "x\udc00" })
-      assert.deepStrictEqual(yield* native.append(thread, posted.id, "a\ud83d", undefined), { state: "open", held: 1 })
-      yield* native.append(thread, posted.id, "\ud83d\ude00\ud83d", { flush: true })
-      const [message] = yield* test.messages(thread)
-      assert.strictEqual(message.text, "x\ufffda😀\ufffd")
-    }).pipe(Effect.provide(ChatTest.layer())))
 })

From 2f2a526f4b6b9134d89134ce28e93ac5525f24a7 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 09:09:21 +0000
Subject: [PATCH 56/89] Trim repetitive chat implementation comments

---
 packages/chat/discord/src/internal/adapter.ts      |  3 +--
 packages/chat/discord/src/internal/interactions.ts |  5 ++---
 packages/chat/slack/src/internal/adapter.ts        |  5 ++---
 packages/chat/slack/src/internal/escape.ts         |  1 -
 packages/chat/slack/src/internal/interactions.ts   |  4 +---
 packages/chat/slack/src/internal/richText.ts       |  2 +-
 packages/effect/src/chat/ChatInteraction.ts        |  2 +-
 packages/effect/src/chat/ChatMarkdown.ts           | 12 +++++-------
 packages/effect/src/chat/ChatTest.ts               |  4 ++--
 9 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/packages/chat/discord/src/internal/adapter.ts b/packages/chat/discord/src/internal/adapter.ts
index 7a9d9eb5c13..5d34186b9f7 100644
--- a/packages/chat/discord/src/internal/adapter.ts
+++ b/packages/chat/discord/src/internal/adapter.ts
@@ -291,7 +291,7 @@ export const make = Effect.fnUntraced(function*(options: {
         content: content.markdown,
         allowed_mentions: allowedMentions(postOptions.notify),
         flags: flags(postOptions),
-        // Always sent, so an edit without elements removes the ones there were.
+        // Send empty components to clear existing elements.
         components: rows
       }),
       true
@@ -425,7 +425,6 @@ export const make = Effect.fnUntraced(function*(options: {
     const name = kind === "direct" ? undefined : nonEmpty(found.name)
     const topic = nonEmpty(found.topic)
     const parent = kind === "thread" ? nonEmpty(found.parent_id) : undefined
-    // An unreadable creation time falls back to the id's.
     const created = Option.flatMap(
       Option.fromUndefinedOr(nonEmpty(found.thread_metadata?.create_timestamp)),
       DateTime.make
diff --git a/packages/chat/discord/src/internal/interactions.ts b/packages/chat/discord/src/internal/interactions.ts
index 6ace04de57b..80a3a9f8955 100644
--- a/packages/chat/discord/src/internal/interactions.ts
+++ b/packages/chat/discord/src/internal/interactions.ts
@@ -283,7 +283,7 @@ const CHAT_INPUT = 1
 const STRING = 3
 
 /**
- * The id and token to answer an interaction with, read from its payload.
+ * Credentials for answering an interaction.
  *
  * @internal
  */
@@ -291,8 +291,7 @@ export const answerTo = (raw: unknown): { readonly id: string; readonly token: s
   Option.getOrUndefined(Option.map(decodeFields(raw), ({ id, token }) => ({ id, token })))
 
 /**
- * The application id and token a deferred command's response is edited
- * with, and the interaction's id, read from its payload.
+ * Credentials for editing a deferred command's response.
  *
  * @internal
  */
diff --git a/packages/chat/slack/src/internal/adapter.ts b/packages/chat/slack/src/internal/adapter.ts
index 106162dbe7d..c38166e2056 100644
--- a/packages/chat/slack/src/internal/adapter.ts
+++ b/packages/chat/slack/src/internal/adapter.ts
@@ -754,7 +754,6 @@ export const make = (options: {
               Effect.as({ state: "stopped" as const, held: 0 })
             )
         ),
-        // Nothing was added.
         Effect.tapError((error) =>
           Effect.sync(() => {
             if (error.retry === "denied") streams.set(messageId, state)
@@ -791,14 +790,14 @@ export const make = (options: {
       const result = Option.isSome(answer) && isObject(answer.value) ? answer.value.result_status : undefined
       const stopped = state?.stopped === true || result === "stopped_by_user" ||
         (context !== undefined && context.result_status === "stopped_by_user")
-      // Remembered, so a stop sent again after a cut-off one, which Slack answers as not streaming, still ends the session.
+      // Remember stopped_by_user across interruptions, even if a retry finds no open stream.
       const current = streams.get(messageId)
       if (stopped && current !== undefined) streams.set(messageId, { ...current, stopped: true })
       yield* cleanup(op, parts.channel, messageId, postOptions.notify ?? {})
       if (stopped && stopOptions.end === "done") {
         yield* endSession(parts.channel, parts.threadTs, messageId, postOptions.sessionStatusAtEnd ?? "active")
       }
-      // Kept until now, so a stop sent again after a cut-off one still cleans up and ends the session.
+      // Retain stream state until cleanup and session completion finish.
       streams.delete(messageId)
       return { stopped }
     })
diff --git a/packages/chat/slack/src/internal/escape.ts b/packages/chat/slack/src/internal/escape.ts
index 56ab7e84a39..3c48007fe78 100644
--- a/packages/chat/slack/src/internal/escape.ts
+++ b/packages/chat/slack/src/internal/escape.ts
@@ -189,7 +189,6 @@ export const escape = (
           i = stop
           continue
         }
-        // A `<` outside code.
         const at = lineStart + i
         const rest = line.slice(i)
         const undecided = !flush && !complete && full.length - at <= holdBound && (
diff --git a/packages/chat/slack/src/internal/interactions.ts b/packages/chat/slack/src/internal/interactions.ts
index cac49d61ed3..58a334796c9 100644
--- a/packages/chat/slack/src/internal/interactions.ts
+++ b/packages/chat/slack/src/internal/interactions.ts
@@ -81,9 +81,7 @@ interface Origin {
 }
 
 /**
- * The tag, the channel, the thread's ts or nothing, the message's ts or
- * nothing and, when there is one, the consumer's metadata, joined. The
- * metadata is last, so it may hold the join.
+ * Consumer metadata is last so it may contain the join delimiter.
  */
 const packMetadata = (origin: Origin, metadata: string | undefined): string =>
   [
diff --git a/packages/chat/slack/src/internal/richText.ts b/packages/chat/slack/src/internal/richText.ts
index f4eae5bff5e..02a574ea0f7 100644
--- a/packages/chat/slack/src/internal/richText.ts
+++ b/packages/chat/slack/src/internal/richText.ts
@@ -274,7 +274,7 @@ const prefixLines = (writer: Writer, from: number, first: string, rest: string):
     position += line.length + 1
   })
   writer.out = writer.out.slice(0, from) + rewritten
-  // Move the mentions written in this span by the prefixes before them.
+  // Adjust mention offsets for inserted prefixes.
   for (let m = 0; m < writer.mentions.length; m++) {
     const mention = writer.mentions[m]
     if (mention.start < from) continue
diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
index dea72789c92..aa46d88b189 100644
--- a/packages/effect/src/chat/ChatInteraction.ts
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -1694,7 +1694,7 @@ export const handle: {
     )
     if (Option.isSome(exit)) return yield* exit.value
     if (event._tag === "ModalSubmitted" || event._tag === "CommandInvoked") {
-      // Requests the interrupt without waiting for it to finish.
+      // Interrupt without delaying the deadline reply.
       yield* Effect.forkDetach(Fiber.interrupt(fiber))
       return late
     }
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index 015200b8c7b..0fe9449fa7d 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -689,7 +689,7 @@ const reply = (options: ReplyOptions): Effect.Effect {
-        // The platform may have refused the files: the last part goes out without them, ending in the note.
+        // Replace refused files with the unattached note.
         const text = unattachedNote!(files!)
         if (measureLast(markdown + text) <= limits.messageLength) {
           return Effect.asVoid(attempt(markdown + text, undefined, false, withActions))
@@ -811,10 +811,8 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect, fallback: boolean) =>
           create(
             chat.post(thread, { markdown, files: [file, ...files], ...(hasActions ? { actions } : {}) }),
diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index 8c17ec68d02..34786a7f069 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -1652,7 +1652,7 @@ class Tester {
       case "selects":
         return expect(chat.post(thread, { markdown: text, actions: [conformanceSelect(this.rule)] }), track)
       case "modals":
-        // A modal opens only from a click, so without the hook or anything to click there is nothing to probe.
+        // Probing a modal requires the interaction hook and a clickable element.
         return this.options.interactions === undefined || !(this.has("buttons") || this.has("selects"))
           ? Effect.void
           : Effect.gen({ self: this }, function*() {
@@ -1689,7 +1689,7 @@ class Tester {
           { markdown: text }
         ))
       case "ephemeral":
-        // A private answer exists only as the answer to a command, so without the hook there is nothing to probe.
+        // Probing a private answer requires the command hook.
         return this.options.interactions?.command === undefined
           ? Effect.void
           : Effect.gen({ self: this }, function*() {

From cfcdec3a797fb08b2952197bea43482d5a62f999 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 09:16:49 +0000
Subject: [PATCH 57/89] Restore unsigned webhook, select-origin modal and
 message lookup bound checks

---
 packages/chat/slack/test/SlackChat.test.ts | 7 +++++++
 packages/chat/slack/test/webhook.test.ts   | 6 ++++--
 packages/effect/test/chat/ChatTest.test.ts | 3 ++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index b1c7d23df58..e9ab632aae0 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -502,6 +502,13 @@ describe("reads", () => {
         yield* checkMessage(message, checkOptions)
         assert.deepStrictEqual(message.thread, channelThread)
         assert.strictEqual(message.mentions.length, 2)
+        // Both bounds at the message, inclusive, or Slack leaves the message out.
+        const { latest, oldest, inclusive } = fake.called("conversations.replies")[0].params
+        assert.deepStrictEqual({ latest, oldest, inclusive }, {
+          latest: "1794509003.143939",
+          oldest: "1794509003.143939",
+          inclusive: "true"
+        })
       })
     )
   })
diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts
index 8ae9f412051..e1b4f9c50dd 100644
--- a/packages/chat/slack/test/webhook.test.ts
+++ b/packages/chat/slack/test/webhook.test.ts
@@ -84,7 +84,7 @@ const withLogs = (effect: Effect.Effect) => {
 }
 
 describe("webhook", () => {
-  it.live("rejects a bad or stale signature", () =>
+  it.live("rejects a bad, stale or missing signature", () =>
     Effect.gen(function*() {
       const body = JSON.stringify(message)
       const wrongKey = yield* handle({}, yield* Effect.promise(() => request(body, { key: "other" })))
@@ -92,7 +92,9 @@ describe("webhook", () => {
       const stale = String(Math.floor(Date.now() / 1000) - 6 * 60)
       const old = yield* handle({}, yield* Effect.promise(() => request(body, { timestamp: stale })))
       assert.strictEqual(old.status, 401)
-      assert.strictEqual(wrongKey.events.length + old.events.length, 0)
+      const unsigned = yield* handle({}, new Request("http://localhost/", { method: "POST", body }))
+      assert.strictEqual(unsigned.status, 401)
+      assert.strictEqual(wrongKey.events.length + old.events.length + unsigned.events.length, 0)
     }))
 
   it.live("413 past the body limit, 400 for a body that is not JSON", () =>
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index 5fbba7c3fc2..4b148f5f7b0 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -93,9 +93,10 @@ describe("ChatTest", () => {
     }
   })
 
-  // These rules probe their capability only while the one it builds on is on.
+  // Paths that all-on and all-off miss: a probe gated on another capability, and a modal opened from a select.
   for (
     const [rule, off] of [
+      ["modal/origin", "buttons"],
       ["unsupported/modals", "modals"],
       ["modal/errorsKeepOpen", "modalErrors"],
       ["unsupported/ephemeral", "ephemeral"]

From d9016450d24ae098838d4506994275968d429302 Mon Sep 17 00:00:00 2001
From: Tim 
Date: Sun, 15 Nov 2026 22:23:44 +1300
Subject: [PATCH 58/89] Apply suggestion from @tim-smart

---
 .changeset/effect-chat.md | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 9c441819d8e..83f5f95d722 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -5,11 +5,3 @@
 ---
 
 Add unstable `effect/chat` APIs and Slack/Discord adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
-
-### Migrating from earlier PR snapshots
-
-- Handle `CommandInvoked` in interaction handlers and exhaustive matches, and `Respond`/`Defer` results from `handle`. `ModalSubmitted.messageId` is optional for command-opened modals.
-- Implement `followUp` in custom adapters. Adapters without commands must fail it with `Unsupported` naming `commands`; unsupported actions must fail with `Unsupported` naming `buttons` or `selects`. These conformance rules run against every adapter. `ChatTest` includes `commands` and `ephemeral` by default.
-- Supply `replyTo.isSelf` wherever `replyTo.authorId` is set; `ChatMessage.repliesToSelf` reads it. `ChatMarkdownError.remainingFence` identifies the fence around unposted text.
-- Command replies are private by default and never notify mentions. Private-answer IDs identify interactions, not addressable messages. Use one `Chat.followUp` per deferral: repeats create another message on Slack, overwrite on Discord, and fail in `ChatTest`.
-- Configure Slack commands with the `commands` scope and `layerInteractivity` Request URL. Register Discord commands yourself using `DiscordChat.commandRequests`; the adapter does not register them.

From f8da888006f9fedf71ffb6d812107494167098d9 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 09:23:49 +0000
Subject: [PATCH 59/89] Check the channel of Slack's single-message lookup

---
 packages/chat/slack/test/SlackChat.test.ts | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index e9ab632aae0..3af308410d2 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -502,9 +502,10 @@ describe("reads", () => {
         yield* checkMessage(message, checkOptions)
         assert.deepStrictEqual(message.thread, channelThread)
         assert.strictEqual(message.mentions.length, 2)
-        // Both bounds at the message, inclusive, or Slack leaves the message out.
-        const { latest, oldest, inclusive } = fake.called("conversations.replies")[0].params
-        assert.deepStrictEqual({ latest, oldest, inclusive }, {
+        // The thread's channel, with both bounds at the message, inclusive, or Slack leaves the message out.
+        const { channel: requested, latest, oldest, inclusive } = fake.called("conversations.replies")[0].params
+        assert.deepStrictEqual({ channel: requested, latest, oldest, inclusive }, {
+          channel,
           latest: "1794509003.143939",
           oldest: "1794509003.143939",
           inclusive: "true"

From a4bf326eaf58ca7dff66c2dced15a43d12333483 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 20:37:10 +0000
Subject: [PATCH 60/89] Use the Mac service for Slack signature verification

---
 .changeset/effect-chat.md                     |  2 +
 packages/chat/slack/README.md                 | 17 ++++++++
 packages/chat/slack/src/SlackChat.ts          | 19 +++++++-
 packages/chat/slack/src/internal/webhook.ts   | 36 +++++-----------
 packages/chat/slack/test/events.test.ts       |  3 +-
 packages/chat/slack/test/interactions.test.ts |  2 +
 packages/chat/slack/test/webhook.test.ts      | 43 +++++++++++++++++--
 7 files changed, 90 insertions(+), 32 deletions(-)

diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 83f5f95d722..d65ebb41e87 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -5,3 +5,5 @@
 ---
 
 Add unstable `effect/chat` APIs and Slack/Discord adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
+
+Slack webhook and interactivity layers require a `Mac` service. Provide a runtime layer such as `NodeCrypto.layerMac`, or `Mac.layerWebCrypto` with `SecureRandom.layerWebCrypto`.
diff --git a/packages/chat/slack/README.md b/packages/chat/slack/README.md
index 7f1139d28d0..794487181ec 100644
--- a/packages/chat/slack/README.md
+++ b/packages/chat/slack/README.md
@@ -8,6 +8,23 @@ A [Slack](https://slack.com) adapter for `effect/chat`. Includes the Events API
 npm install effect @effect/chat-slack
 ```
 
+## Signature verification
+
+`SlackChat.layerWebhook` and `SlackChat.layerInteractivity` require the
+`Mac` service; the adapter does not provide a default. Supply
+`NodeCrypto.layerMac` from `@effect/platform-node/NodeCrypto`,
+`BunCrypto.layerMac`, `DenoCrypto.layerMac`, or `BrowserCrypto.layerMac`
+from the corresponding platform package.
+
+For other runtimes such as Workers, provide
+`Mac.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto))`,
+using `effect/crypto/Mac`, `effect/Layer`, and `effect/crypto/SecureRandom`.
+Pass the chosen layer to each route layer with `Layer.provide`.
+
+An invalid signing secret fails layer construction as a defect. A verification
+error or malformed signature fails closed with HTTP 401. Requests must still
+have a digits-only timestamp within five minutes of the current clock.
+
 ## Known limits
 
 - A post with files has not been tested in a Slack Connect channel.
diff --git a/packages/chat/slack/src/SlackChat.ts b/packages/chat/slack/src/SlackChat.ts
index a4530e1d367..5dbbcb70f36 100644
--- a/packages/chat/slack/src/SlackChat.ts
+++ b/packages/chat/slack/src/SlackChat.ts
@@ -51,6 +51,7 @@ import * as ChatInteraction from "effect/chat/ChatInteraction"
 import type { ParseMention } from "effect/chat/ChatTest"
 import { ChatThread } from "effect/chat/ChatThread"
 import * as Context from "effect/Context"
+import type * as Mac from "effect/crypto/Mac"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import { dual } from "effect/Function"
@@ -387,6 +388,13 @@ export const parts: (thread: ChatThread) => Option.Option<{
  * - Slack redelivers on a timeout or an error, so an event can arrive twice.
  *   `ChatEvent.dedupeKey` gives the two deliveries equal keys.
  *
+ * Signature checks use the required `Mac` service. Provide
+ * `NodeCrypto.layerMac`, `BunCrypto.layerMac`, `DenoCrypto.layerMac`,
+ * `BrowserCrypto.layerMac`, or `Mac.layerWebCrypto` with
+ * `SecureRandom.layerWebCrypto` for other runtimes such as Workers.
+ * Key construction failures are configuration defects; verification errors
+ * fail the signature check (401).
+ *
  * @stability unstable
  * @category layers
  * @since 4.1.5
@@ -397,7 +405,7 @@ export const layerWebhook = (options: {
   readonly appId: string
   readonly deadline?: Duration.Duration | undefined
   readonly maxBodyBytes?: number | undefined
-}): Layer.Layer =>
+}): Layer.Layer =>
   HttpRouter.use(Effect.fnUntraced(function*(router) {
     const slack = yield* SlackChat
     const handler = yield* ChatHandler
@@ -433,6 +441,13 @@ export const layerWebhook = (options: {
  * - Slack never redelivers an interaction, so a click or submit that is not
  *   answered in time is lost. A user can submit again, as a new request.
  *
+ * Signature checks use the required `Mac` service. Provide
+ * `NodeCrypto.layerMac`, `BunCrypto.layerMac`, `DenoCrypto.layerMac`,
+ * `BrowserCrypto.layerMac`, or `Mac.layerWebCrypto` with
+ * `SecureRandom.layerWebCrypto` for other runtimes such as Workers.
+ * Key construction failures are configuration defects; verification errors
+ * fail the signature check (401).
+ *
  * @stability unstable
  * @category layers
  * @since 4.1.5
@@ -443,7 +458,7 @@ export const layerInteractivity = (options: {
   readonly appId: string
   readonly deadline?: Duration.Duration | undefined
   readonly maxBodyBytes?: number | undefined
-}): Layer.Layer =>
+}): Layer.Layer =>
   HttpRouter.use(Effect.fnUntraced(function*(router) {
     const slack = yield* SlackChat
     const handler = yield* ChatInteraction.Handler
diff --git a/packages/chat/slack/src/internal/webhook.ts b/packages/chat/slack/src/internal/webhook.ts
index 24852e0e380..4420de7893e 100644
--- a/packages/chat/slack/src/internal/webhook.ts
+++ b/packages/chat/slack/src/internal/webhook.ts
@@ -3,7 +3,7 @@ import type * as ChatEvent from "effect/chat/ChatEvent"
 import type { NotAccepted } from "effect/chat/ChatHandler"
 import * as ChatInteraction from "effect/chat/ChatInteraction"
 import * as Clock from "effect/Clock"
-import { WebCrypto } from "effect/crypto/WebCrypto"
+import * as Mac from "effect/crypto/Mac"
 import type * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import type * as HttpServerRequest from "effect/http/HttpServerRequest"
@@ -19,19 +19,6 @@ const maxSkewSeconds = 60 * 5
 
 const encoder = new TextEncoder()
 
-const toHex = (bytes: Uint8Array): string => {
-  let out = ""
-  for (const byte of bytes) out += byte.toString(16).padStart(2, "0")
-  return out
-}
-
-const timingSafeEqual = (a: string, b: string): boolean => {
-  if (a.length !== b.length) return false
-  let diff = 0
-  for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i)
-  return diff === 0
-}
-
 /**
  * Checks Slack's `v0` request signature: an HMAC-SHA256 of
  * `v0:{timestamp}:{body}` with the signing secret, and a timestamp within
@@ -40,29 +27,26 @@ const timingSafeEqual = (a: string, b: string): boolean => {
  * @internal
  */
 export const makeVerifier = Effect.fnUntraced(function*(signingSecret: Redacted.Redacted) {
-  const crypto = yield* WebCrypto
-  const key = yield* Effect.promise(() =>
-    crypto.subtle.importKey(
-      "raw",
-      encoder.encode(Redacted.value(signingSecret)),
-      { name: "HMAC", hash: "SHA-256" },
-      false,
-      ["sign"]
-    )
-  )
+  const mac = yield* Mac.Mac
+  // Invalid signing secrets are configuration defects, not route errors.
+  const key = yield* Mac.key(Mac.hmacSha256, encoder.encode(Redacted.value(signingSecret))).pipe(Effect.orDie)
   return (headers: { readonly [key: string]: string | undefined }, body: Uint8Array): Effect.Effect =>
     Effect.gen(function*() {
       const timestamp = headers["x-slack-request-timestamp"]
       const signature = headers["x-slack-signature"]
       if (timestamp === undefined || signature === undefined || !/^\d+$/.test(timestamp)) return false
+      if (!/^v0=(?:[0-9a-fA-F]{2})+$/.test(signature)) return false
+      const hex = signature.slice(3)
+      const tag = new Uint8Array(hex.length / 2)
+      for (let i = 0; i < tag.length; i++) tag[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16)
       const now = yield* Clock.currentTimeMillis
       if (Math.abs(now / 1000 - Number(timestamp)) > maxSkewSeconds) return false
       const prefix = encoder.encode(`v0:${timestamp}:`)
       const message = new Uint8Array(prefix.length + body.length)
       message.set(prefix)
       message.set(body, prefix.length)
-      const mac = yield* Effect.promise(() => crypto.subtle.sign("HMAC", key, message))
-      return timingSafeEqual(`v0=${toHex(new Uint8Array(mac))}`, signature)
+      // Crypto failures fail closed, like a mismatched signature.
+      return yield* mac.verify(key, tag, message).pipe(Effect.catch(() => Effect.succeed(false)))
     })
 })
 
diff --git a/packages/chat/slack/test/events.test.ts b/packages/chat/slack/test/events.test.ts
index 70202f97eac..f1f20c18198 100644
--- a/packages/chat/slack/test/events.test.ts
+++ b/packages/chat/slack/test/events.test.ts
@@ -4,6 +4,7 @@
  */
 import { handleRequest, makeVerifier } from "@effect/chat-slack/internal/webhook"
 import * as SlackChat from "@effect/chat-slack/SlackChat"
+import * as NodeCrypto from "@effect/platform-node/NodeCrypto"
 import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { dedupeKey } from "effect/chat/ChatEvent"
@@ -57,7 +58,7 @@ const deliver = Effect.fnUntraced(function*(delivery: Delivery) {
   })
   const events: Array = []
   const response = yield* handleRequest(HttpServerRequest.fromWeb(web), {
-    verify: yield* makeVerifier(Redacted.make(secret)),
+    verify: yield* makeVerifier(Redacted.make(secret)).pipe(Effect.provide(NodeCrypto.layerMac)),
     appId,
     teamId: team,
     botUserId: Effect.succeed(botUserId),
diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
index d7cb8a095b6..1598608aa0e 100644
--- a/packages/chat/slack/test/interactions.test.ts
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -5,6 +5,7 @@
  * ones are in `commands.test.ts`.
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
+import * as NodeCrypto from "@effect/platform-node/NodeCrypto"
 import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
 import type { ChatError } from "effect/chat/ChatError"
@@ -281,6 +282,7 @@ describe("layerInteractivity", () => {
     }).pipe(
       Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
       Layer.provide(Chat.layer),
+      Layer.provide(NodeCrypto.layerMac),
       Layer.provide(handler.layer),
       Layer.provide(makeFake({ "auth.test": authTest }).layer)
     )
diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts
index e1b4f9c50dd..3e0e6eb778a 100644
--- a/packages/chat/slack/test/webhook.test.ts
+++ b/packages/chat/slack/test/webhook.test.ts
@@ -1,10 +1,13 @@
 import { handleRequest, makeVerifier, type Options, unavailable as logged } from "@effect/chat-slack/internal/webhook"
 import * as SlackChat from "@effect/chat-slack/SlackChat"
+import * as NodeCrypto from "@effect/platform-node/NodeCrypto"
 import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
 import { ChatError, PlatformUnavailable } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
+import * as CryptoError from "effect/crypto/CryptoError"
+import * as Mac from "effect/crypto/Mac"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
@@ -56,7 +59,7 @@ const request = async (body: string, options?: { readonly timestamp?: string; re
 const message = messageEnvelope({ ts: "1794509003.000001", user: "U080YLYB277", text: "hi <@U0CCLMD4S1L>" })
 
 const handle = Effect.fnUntraced(function*(options: Partial, web: Request) {
-  const verify = yield* makeVerifier(Redacted.make(secret))
+  const verify = yield* makeVerifier(Redacted.make(secret)).pipe(Effect.provide(NodeCrypto.layerMac))
   const events: Array = []
   const response = yield* handleRequest(HttpServerRequest.fromWeb(web), {
     verify,
@@ -94,6 +97,11 @@ describe("webhook", () => {
       assert.strictEqual(old.status, 401)
       const unsigned = yield* handle({}, new Request("http://localhost/", { method: "POST", body }))
       assert.strictEqual(unsigned.status, 401)
+      for (const signature of ["00", "v0=0", "v0=gg", "v0=00"]) {
+        const web = yield* Effect.promise(() => request(body))
+        web.headers.set("x-slack-signature", signature)
+        assert.strictEqual((yield* handle({}, web)).status, 401)
+      }
       assert.strictEqual(wrongKey.events.length + old.events.length + unsigned.events.length, 0)
     }))
 
@@ -170,6 +178,7 @@ describe("webhook", () => {
       }).pipe(
         Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
         Layer.provide(Chat.layer),
+        Layer.provide(NodeCrypto.layerMac),
         Layer.provide(Layer.succeed(ChatHandler, { handle: (event) => Effect.sync(() => void events.push(event)) })),
         Layer.provide(fake.layer)
       )
@@ -196,18 +205,46 @@ describe("webhook", () => {
       assert.isTrue(cancelled)
     }))
 
-  it.live("layerWebhook serves the path", () =>
+  it.live("layerWebhook uses the supplied Mac and fails closed on crypto errors", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest })
       const events: Array = []
+      let fail = false
+      const mac = Layer.succeed(Mac.Mac, {
+        generateKey: () => Effect.die("unused"),
+        sign: () => Effect.die("unused"),
+        verify: Effect.fnUntraced(function*(key, tag, data) {
+          assert.strictEqual(key.algorithm, Mac.hmacSha256)
+          assert.deepStrictEqual(tag, new Uint8Array([0xab, 0xcd]))
+          assert.strictEqual(new TextDecoder().decode(yield* Mac.toBytes(key)), secret)
+          assert.strictEqual(new TextDecoder().decode(data).split(":").slice(2).join(":"), JSON.stringify(message))
+          return yield* fail
+            ? Effect.fail(
+              new CryptoError.CryptoError({
+                module: "Mac",
+                method: "verify",
+                reason: new CryptoError.InvalidKey({ description: "test failure" })
+              })
+            )
+            : Effect.succeed(true)
+        })
+      })
       const app = SlackChat.layerWebhook({ path: "/slack/events", signingSecret: Redacted.make(secret), appId }).pipe(
         Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
         Layer.provide(Chat.layer),
+        Layer.provide(mac),
         Layer.provide(Layer.succeed(ChatHandler, { handle: (event) => Effect.sync(() => void events.push(event)) })),
         Layer.provide(fake.layer)
       )
       const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true })
-      const response = yield* Effect.promise(() => request(JSON.stringify(message)).then((web) => handler(web)))
+      const send = Effect.promise(async () => {
+        const web = await request(JSON.stringify(message))
+        web.headers.set("x-slack-signature", "v0=abcd")
+        return handler(web)
+      })
+      const response = yield* send
+      fail = true
+      assert.strictEqual((yield* send).status, 401)
       yield* Effect.promise(() => dispose())
       assert.strictEqual(response.status, 200)
       assert.strictEqual(events.length, 1)

From 2ec59f031caf09e76c8c2d258c5e29ca1f64cc95 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 20:47:14 +0000
Subject: [PATCH 61/89] Post each streamed part once on an adapter without edit

ChatMarkdown.stream fell back to post-then-edit whenever there was no native
stream, so on an adapter without edit the first edit failed and left a
truncated reply. It now buffers each part and posts it once, at a rollover or
at the end. ChatHandler and ChatInteraction no longer promise that the
platform never delivers an accepted event or an interaction again.
---
 packages/effect/src/chat/ChatHandler.ts       |  8 +++--
 packages/effect/src/chat/ChatInteraction.ts   |  5 ++--
 packages/effect/src/chat/ChatMarkdown.ts      | 30 ++++++++++++++-----
 .../effect/test/chat/ChatMarkdown.test.ts     | 13 ++++++++
 4 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/packages/effect/src/chat/ChatHandler.ts b/packages/effect/src/chat/ChatHandler.ts
index 77242db6fd8..e0b6260e2cf 100644
--- a/packages/effect/src/chat/ChatHandler.ts
+++ b/packages/effect/src/chat/ChatHandler.ts
@@ -3,7 +3,8 @@
  *
  * Adapters take the `ChatHandler` service from context and call `handle` for
  * every inbound event. The contract is "accept, fast": success means the event
- * is the consumer's and is never redelivered.
+ * is the consumer's. The platform can still deliver it again, so drop
+ * repeats with `ChatEvent.dedupeKey`.
  *
  * @stability unstable
  * @since 4.1.5
@@ -42,8 +43,9 @@ export class NotAccepted extends Schema.TaggedError("effect/chat/Ch
  *
  * **Details**
  *
- * Adapters take the service and call `handle`. Success means the event is the
- * consumer's and is never redelivered; `NotAccepted` refuses it.
+ * Adapters take the service and call `handle`. Success hands the event to the
+ * consumer, and `NotAccepted` refuses it. Success does not stop the platform
+ * from delivering the event again: delivery is at-least-once.
  *
  * **Gotchas**
  *
diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
index aa46d88b189..cec3bbb4a56 100644
--- a/packages/effect/src/chat/ChatInteraction.ts
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -39,8 +39,9 @@
  * - Clicks, submits and commands are not `ChatEvent`s. They need an answer
  *   inside the platform's 3 seconds, so they go to `Handler`, which answers
  *   by return value and has no error channel.
- * - Neither platform redelivers a click, a submit or a command, so
- *   interactions carry no dedupe key.
+ * - Slack and Discord don't redeliver a click, a submit or a command, so
+ *   interactions carry no dedupe key. An adapter whose platform does
+ *   redeliver them documents a delivery key of its own.
  *
  * @stability unstable
  * @since 4.1.5
diff --git a/packages/effect/src/chat/ChatMarkdown.ts b/packages/effect/src/chat/ChatMarkdown.ts
index 0fe9449fa7d..8dbfa9984eb 100644
--- a/packages/effect/src/chat/ChatMarkdown.ts
+++ b/packages/effect/src/chat/ChatMarkdown.ts
@@ -3,8 +3,9 @@
  *
  * `post` splits Markdown that outgrows one message into parts at block
  * boundaries. `stream` writes a stream of Markdown deltas as it arrives, by
- * the adapter's native stream when it has one and otherwise by posting and
- * then editing. Both sit above the adapter ops and use one splitter.
+ * the adapter's native stream when it has one, otherwise by posting and then
+ * editing, and on an adapter without `edit` by posting each part once. Both
+ * sit above the adapter ops and use one splitter.
  *
  * **Example** (Streaming a reply)
  *
@@ -52,9 +53,10 @@ import type { Action } from "./ChatUi.ts"
  *   overflow file.
  * - `text` is the slice of the input the part carries, without anything the
  *   layer added. The `text` of every part, in order, is the input.
- * - `transport` is `post` for a part from `post`, `edit` for a streamed
- *   part written by post-then-edit and `native` for one written by the
- *   adapter's native stream, even if it was finished by an edit.
+ * - `transport` is `post` for a part from `post` and for a streamed part
+ *   posted once to an adapter without `edit`, `edit` for a streamed part
+ *   written by post-then-edit and `native` for one written by the adapter's
+ *   native stream, even if it was finished by an edit.
  *
  * @stability unstable
  * @category models
@@ -450,6 +452,8 @@ const reply = (options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect(options: ReplyOptions): Effect.Effect {
           if (final && isRunning()) finishPart(input.length)
           return end(final)
@@ -1313,6 +1322,10 @@ export const post = (
  *   written by native appends. Otherwise, or when the first native start fails
  *   with `Unsupported`, it posts and then edits. The result and the span say
  *   which ran.
+ * - On an adapter without `edit` the reply is buffered instead: each part is
+ *   posted once, when it rolls over or the reply ends, with transport
+ *   `post`. Nothing shows until then. An upstream failure or an interrupt
+ *   posts what was received, as above.
  * - Text that outgrows a message rolls over into a new one at a block
  *   boundary, and each new message counts against `maxParts`. A native stream
  *   rolls over at the next block boundary past 85% of `limits.streamLength`,
@@ -1349,7 +1362,9 @@ export const post = (
  *   the reply stopped.
  * - There are no actions either. Add them after the result with
  *   `chat.edit(thread, last.messageId, { markdown: last.markdown, actions })`,
- *   where `last` is the final entry of `Result.parts`.
+ *   where `last` is the final entry of `Result.parts`. Without `edit` they
+ *   can't be added to the reply: post them in a message of their own with
+ *   `chat.post(thread, { markdown, actions })`.
  * - To stop a reply, end `deltas` with `Stream.interruptWhen` or
  *   `Stream.haltWhen`, so a `Result` still comes back. Interrupting the call
  *   leaves only the ids collected through `onPart`.
@@ -1358,7 +1373,6 @@ export const post = (
  * - A native part that is rolled over on `TooLarge` can end inside an open
  *   code fence, since it can no longer be appended to. The next part reopens
  *   the fence.
- * - Post-then-edit needs the `edit` capability.
  *
  * @stability unstable
  * @category constructors
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index f87e9abcc94..b707f40f7a9 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -384,6 +384,19 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(calls.map((call) => call.op), ["post", "edit"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
+    it.effect("posts each part once, when it is final, without edit", () =>
+      Effect.gen(function*() {
+        const { test, thread } = yield* setup
+        const { end, send } = yield* feed(thread)
+        yield* send("one\n\n")
+        assert.deepStrictEqual(yield* test.calls, [])
+        yield* send("two ".repeat(10) + "\n\nthree")
+        const result = yield* end
+        assert.deepStrictEqual(result.parts.map((part) => part.transport), ["post", "post"])
+        assert.deepStrictEqual(yield* texts(test, thread), ["one\n\n" + "two ".repeat(10) + "\n\n", "three"])
+        assert.deepStrictEqual((yield* test.calls).map((call) => call.op), ["post", "post"])
+      }).pipe(Effect.provide(ChatTest.layer({ capabilities: ["files"], limits: { messageLength: 50 } }))))
+
     it.effect("writes natively with a recipient, sending held text again", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup

From 5569669ce223a4afe63e83c18b5783107fc4a865 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:09:59 +0000
Subject: [PATCH 62/89] Use a short label for the conformance length button

A platform with short button labels, such as WhatsApp's 20, refused the rule's name as a label.
---
 packages/effect/src/chat/ChatTest.ts | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/packages/effect/src/chat/ChatTest.ts b/packages/effect/src/chat/ChatTest.ts
index 34786a7f069..9bb4075ae6f 100644
--- a/packages/effect/src/chat/ChatTest.ts
+++ b/packages/effect/src/chat/ChatTest.ts
@@ -2319,7 +2319,8 @@ export const conformance = (options: {
     Effect.gen(function*() {
       const { measure } = t.descriptor
       const most = t.descriptor.limits.messageLength
-      const actions = [{ ...conformanceButton(t.rule), value: "x" }]
+      // A short label, so a platform whose labels are short still takes the button.
+      const actions = [{ ...conformanceButton(t.rule), label: "fits", value: "x" }]
       let low = 0
       let high = most
       while (low < high) {

From a7b574dbe427d848e18adf054e90a4b21e399339 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:09:59 +0000
Subject: [PATCH 63/89] Add the WhatsApp Cloud API adapter

One adapter per business phone number: posts with one Graph send, reply buttons, link buttons and lists, one file per post, the Meta webhook with signature checks and ordered dispatch, delivery and update keys, templates and read receipts. Groups are reserved and refused.
---
 .changeset/config.json                        |   1 +
 .changeset/effect-chat.md                     |   5 +-
 README.md                                     |   1 +
 packages/chat/whatsapp/README.md              |  43 ++
 packages/chat/whatsapp/package.json           |  69 +++
 packages/chat/whatsapp/src/WhatsAppChat.ts    | 456 ++++++++++++++++++
 .../chat/whatsapp/src/WhatsAppGraphApi.ts     | 146 ++++++
 packages/chat/whatsapp/src/WhatsAppUpdate.ts  | 142 ++++++
 packages/chat/whatsapp/src/index.ts           |  24 +
 .../chat/whatsapp/src/internal/actions.ts     | 216 +++++++++
 .../chat/whatsapp/src/internal/adapter.ts     | 290 +++++++++++
 .../chat/whatsapp/src/internal/address.ts     |  41 ++
 packages/chat/whatsapp/src/internal/errors.ts | 103 ++++
 .../chat/whatsapp/src/internal/normalize.ts   | 242 ++++++++++
 .../chat/whatsapp/src/internal/options.ts     |  19 +
 packages/chat/whatsapp/src/internal/text.ts   | 400 +++++++++++++++
 .../chat/whatsapp/src/internal/webhook.ts     | 207 ++++++++
 .../chat/whatsapp/test/WhatsAppChat.test.ts   | 338 +++++++++++++
 .../chat/whatsapp/test/conformance.test.ts    |  28 ++
 packages/chat/whatsapp/test/text.test.ts      |  91 ++++
 packages/chat/whatsapp/test/utils.ts          | 195 ++++++++
 packages/chat/whatsapp/tsconfig.json          |   8 +
 pnpm-lock.yaml                                |   6 +
 tsconfig.packages.json                        |   1 +
 tsconfig.tests.json                           |   2 +
 vitest.config.ts                              |   1 +
 26 files changed, 3073 insertions(+), 2 deletions(-)
 create mode 100644 packages/chat/whatsapp/README.md
 create mode 100644 packages/chat/whatsapp/package.json
 create mode 100644 packages/chat/whatsapp/src/WhatsAppChat.ts
 create mode 100644 packages/chat/whatsapp/src/WhatsAppGraphApi.ts
 create mode 100644 packages/chat/whatsapp/src/WhatsAppUpdate.ts
 create mode 100644 packages/chat/whatsapp/src/index.ts
 create mode 100644 packages/chat/whatsapp/src/internal/actions.ts
 create mode 100644 packages/chat/whatsapp/src/internal/adapter.ts
 create mode 100644 packages/chat/whatsapp/src/internal/address.ts
 create mode 100644 packages/chat/whatsapp/src/internal/errors.ts
 create mode 100644 packages/chat/whatsapp/src/internal/normalize.ts
 create mode 100644 packages/chat/whatsapp/src/internal/options.ts
 create mode 100644 packages/chat/whatsapp/src/internal/text.ts
 create mode 100644 packages/chat/whatsapp/src/internal/webhook.ts
 create mode 100644 packages/chat/whatsapp/test/WhatsAppChat.test.ts
 create mode 100644 packages/chat/whatsapp/test/conformance.test.ts
 create mode 100644 packages/chat/whatsapp/test/text.test.ts
 create mode 100644 packages/chat/whatsapp/test/utils.ts
 create mode 100644 packages/chat/whatsapp/tsconfig.json

diff --git a/.changeset/config.json b/.changeset/config.json
index be4231d482f..707bc0d160f 100644
--- a/.changeset/config.json
+++ b/.changeset/config.json
@@ -24,6 +24,7 @@
       "@effect/ai-openrouter",
       "@effect/atom-react",
       "@effect/chat-slack",
+      "@effect/chat-whatsapp",
       "@effect/chat-discord",
       "@effect/atom-solid",
       "@effect/atom-vue",
diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index d65ebb41e87..0dc487121f9 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -2,8 +2,9 @@
 "effect": patch
 "@effect/chat-slack": patch
 "@effect/chat-discord": patch
+"@effect/chat-whatsapp": patch
 ---
 
-Add unstable `effect/chat` APIs and Slack/Discord adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
+Add unstable `effect/chat` APIs and Slack, Discord and WhatsApp adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
 
-Slack webhook and interactivity layers require a `Mac` service. Provide a runtime layer such as `NodeCrypto.layerMac`, or `Mac.layerWebCrypto` with `SecureRandom.layerWebCrypto`.
+Slack webhook and interactivity layers, and the WhatsApp webhook layer, require a `Mac` service. Provide a runtime layer such as `NodeCrypto.layerMac`, or `Mac.layerWebCrypto` with `SecureRandom.layerWebCrypto`.
diff --git a/README.md b/README.md
index f538082c1ce..8aca4de4317 100644
--- a/README.md
+++ b/README.md
@@ -85,6 +85,7 @@ This monorepo contains the core `effect` package alongside integration packages
 | [`@effect/ai-openai-compat`](packages/ai/openai-compat)               | OpenAI-compatible API provider for the Effect AI modules | [docs](https://effect.website/docs/v4/api/ai-openai-compat)        |
 | [`@effect/ai-openrouter`](packages/ai/openrouter)                     | OpenRouter provider for the Effect AI modules            | [docs](https://effect.website/docs/v4/api/ai-openrouter)           |
 | [`@effect/chat-slack`](packages/chat/slack)                           | Slack adapter for `effect/chat`                          | [docs](https://effect.website/docs/v4/api/chat-slack)              |
+| [`@effect/chat-whatsapp`](packages/chat/whatsapp)                     | WhatsApp Cloud API adapter for `effect/chat`             | [docs](https://effect.website/docs/v4/api/chat-whatsapp)           |
 | [`@effect/chat-discord`](packages/chat/discord)                       | Discord adapter for `effect/chat`                        | [docs](https://effect.website/docs/v4/api/chat-discord)            |
 | [`@effect/atom-react`](packages/atom/react)                           | React bindings for Effect Atom                           | [docs](https://effect.website/docs/v4/api/atom-react)              |
 | [`@effect/atom-solid`](packages/atom/solid)                           | SolidJS bindings for Effect Atom                         | [docs](https://effect.website/docs/v4/api/atom-solid)              |
diff --git a/packages/chat/whatsapp/README.md b/packages/chat/whatsapp/README.md
new file mode 100644
index 00000000000..8324574a6a0
--- /dev/null
+++ b/packages/chat/whatsapp/README.md
@@ -0,0 +1,43 @@
+# @effect/chat-whatsapp
+
+A [WhatsApp Cloud API](https://developers.facebook.com/docs/whatsapp/cloud-api) adapter for `effect/chat`, for one business phone number. Includes the webhook, a pure normaliser for your own transport, a minimal Graph API client, delivery keys, template messages and read receipts.
+
+## Installation
+
+```sh
+npm install effect @effect/chat-whatsapp
+```
+
+## Signature verification
+
+`WhatsAppChat.layerWebhook` requires the `Mac` service; the adapter does not
+provide a default. Supply `NodeCrypto.layerMac` from
+`@effect/platform-node/NodeCrypto`, `BunCrypto.layerMac`,
+`DenoCrypto.layerMac`, or `BrowserCrypto.layerMac` from the corresponding
+platform package.
+
+For other runtimes such as Workers, provide
+`Mac.layerWebCrypto.pipe(Layer.provide(SecureRandom.layerWebCrypto))`.
+
+## Known limits
+
+- Groups are not supported. Group webhooks are logged and dropped, and an op on a group address fails.
+- WhatsApp has no edit or delete, so a streamed reply is posted part by part.
+- Outside the 24 hour customer service window only templates can be sent, with `WhatsAppChat.sendTemplate`.
+- Not yet checked against the live API: the unit Meta counts text limits in, how the rendered formatting shows, a `.md` file sent as `text/plain`, whether error 131047 comes back on the send or as a later status, the webhook's real timeout, and how a media header renders beside buttons.
+
+## Links
+
+- [Website](https://effect.website): documentation, guides, and news.
+- [Reference](https://effect.website/docs/v4/api/chat-whatsapp): API documentation for this package.
+- [Discord](https://discord.gg/effect-ts): ask questions, share what you're building, and talk to the core team.
+- [Community](https://effect.website/community-hub): meetups and events, or bring Effect to your own.
+- [Issues](https://github.com/Effect-TS/effect/issues): bug reports and feature requests.
+
+## Let's talk
+
+Whether your team is considering Effect, rolling it out, or already running it in production, we'd love to hear from you: what you're building, what works, and what you need from Effect next.
+
+- **Talk to the maintainers.** Introduce your team on [Discord](https://discord.gg/effect-ts) or email [contact@effectful.co](mailto:contact@effectful.co). We're happy to connect privately on Slack or Discord for feedback and help with adoption.
+- **Production support.** We're exploring how to better support teams running Effect in production. If your organization has specific support needs, let's discuss them.
+- **Adoption help.** Our [adoption partners](https://effect.website/adoption-partners) offer implementation, consulting, team extension, training, and commercial support.
diff --git a/packages/chat/whatsapp/package.json b/packages/chat/whatsapp/package.json
new file mode 100644
index 00000000000..510868a6da5
--- /dev/null
+++ b/packages/chat/whatsapp/package.json
@@ -0,0 +1,69 @@
+{
+  "name": "@effect/chat-whatsapp",
+  "version": "4.1.4",
+  "type": "module",
+  "license": "MIT",
+  "description": "The WhatsApp Cloud API adapter for effect/chat",
+  "homepage": "https://effect.website",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/Effect-TS/effect.git",
+    "directory": "packages/chat/whatsapp"
+  },
+  "bugs": {
+    "url": "https://github.com/Effect-TS/effect/issues"
+  },
+  "tags": [
+    "typescript",
+    "chat",
+    "whatsapp"
+  ],
+  "keywords": [
+    "typescript",
+    "chat",
+    "whatsapp"
+  ],
+  "sideEffects": [],
+  "exports": {
+    "./package.json": "./package.json",
+    ".": "./src/index.ts",
+    "./*": "./src/*.ts",
+    "./internal/*": null,
+    "./index": null,
+    "./*/index": null
+  },
+  "files": [
+    "src/**/*.ts",
+    "dist/**/*.js",
+    "dist/**/*.js.map",
+    "dist/**/*.d.ts",
+    "dist/**/*.d.ts.map",
+    "AGENTS.md",
+    "CLAUDE.md",
+    "ai-docs/**/*"
+  ],
+  "publishConfig": {
+    "access": "public",
+    "provenance": true,
+    "exports": {
+      "./package.json": "./package.json",
+      ".": "./dist/index.js",
+      "./*": "./dist/*.js",
+      "./internal/*": null,
+      "./index": null,
+      "./*/index": null
+    }
+  },
+  "scripts": {
+    "codegen": "effect-utils codegen",
+    "build": "tsc -b tsconfig.json && pnpm babel",
+    "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
+    "check": "tsc -b tsconfig.json"
+  },
+  "devDependencies": {
+    "effect": "workspace:^"
+  },
+  "peerDependencies": {
+    "effect": "workspace:^"
+  }
+}
diff --git a/packages/chat/whatsapp/src/WhatsAppChat.ts b/packages/chat/whatsapp/src/WhatsAppChat.ts
new file mode 100644
index 00000000000..27d8d58be44
--- /dev/null
+++ b/packages/chat/whatsapp/src/WhatsAppChat.ts
@@ -0,0 +1,456 @@
+/**
+ * The WhatsApp Cloud API adapter for `effect/chat`: the `Registry` layer
+ * for one business phone number, the webhook, the pure normaliser, delivery
+ * keys, templates, read receipts and the scoped post options.
+ *
+ * **Details**
+ *
+ * - Cloud API only. One adapter is one business phone number, and a
+ *   `Registry` holds one adapter per platform.
+ * - An address is `{phoneNumberId}/u/{user}`, where `user` is a phone
+ *   number in digits or a business-scoped user id (BSUID), such as
+ *   `US.13491208655302741918`. `{phoneNumberId}/g/{groupId}` is
+ *   reserved for groups, which are not supported yet: every op on it fails
+ *   `InvalidRequest` with detail `group_unsupported`, and group webhooks
+ *   are logged and dropped.
+ * - Inbound messages carry the BSUID form when the webhook has a BSUID, and
+ *   the phone number only when it has none. The adapter never rewrites an
+ *   address: a reply goes where the thread says. `WhatsAppUpdate.Alias`
+ *   reports a phone number and a BSUID that name one user.
+ * - A business may only write freely within 24 hours of the user's last
+ *   message. Outside it, a `post` fails `Forbidden` with detail
+ *   `outsideWindow`, and `sendTemplate` is the way to write.
+ * - The access token needs `whatsapp_business_messaging`. Subscribe the app
+ *   to the WhatsApp Business Account's `messages` field.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import { type Posted, Registry } from "effect/chat/ChatAdapter"
+import type { ChatError } from "effect/chat/ChatError"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { ChatHandler, type NotAccepted } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type { ParseMention } from "effect/chat/ChatTest"
+import type { ChatThread } from "effect/chat/ChatThread"
+import * as Context from "effect/Context"
+import type * as Mac from "effect/crypto/Mac"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import { dual } from "effect/Function"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpRouter from "effect/http/HttpRouter"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import type * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Adapter from "./internal/adapter.ts"
+import * as Address from "./internal/address.ts"
+import * as Errors from "./internal/errors.ts"
+import * as Normalize from "./internal/normalize.ts"
+import { CurrentPostOptions } from "./internal/options.ts"
+import * as Webhook from "./internal/webhook.ts"
+import { WhatsAppGraphApi } from "./WhatsAppGraphApi.ts"
+import * as GraphApi from "./WhatsAppGraphApi.ts"
+import type { WhatsAppUpdate } from "./WhatsAppUpdate.ts"
+
+/**
+ * The detail of a `post` refused outside the 24 hour customer service
+ * window, Graph error 131047. The reason is `Forbidden`. Write with
+ * `sendTemplate` instead.
+ *
+ * @stability unstable
+ * @category constants
+ * @since 4.1.5
+ */
+export const outsideWindow: string = Errors.outsideWindow
+
+/**
+ * A template message: its approved name, its language code, such as
+ * `en_US`, and Meta's `components` for its parameters, sent as they are.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface Template {
+  readonly name: string
+  readonly language: string
+  readonly components?: ReadonlyArray | undefined
+}
+
+/**
+ * What one webhook delivery holds, in order: messages and reactions, clicks,
+ * and updates.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Inbound =
+  | ChatEvent.MessageCreated
+  | ChatEvent.ReactionAdded
+  | ChatInteraction.ButtonClicked
+  | ChatInteraction.SelectChanged
+  | WhatsAppUpdate
+
+/**
+ * The WhatsApp side of the adapter, for what the core has no op for.
+ *
+ * **Details**
+ *
+ * - `sendTemplate` sends an approved template, which is how v1 writes
+ *   outside the 24 hour window. A template needs Meta's approval first; a
+ *   Direct Send template, where Meta offers it, does not need a separate
+ *   review. An authentication template with one-tap, zero-tap or copy-code
+ *   buttons can't be sent to a BSUID: Meta refuses it with error 131062,
+ *   which is `InvalidRequest`. Send those to a phone number address.
+ * - `markRead` marks a received message read, which shows blue ticks, and
+ *   with `typing` shows the typing indicator until the next message or for
+ *   up to 25 seconds.
+ * - `receive` runs one webhook delivery, already verified and parsed, as
+ *   `layerWebhook` does, for a consumer's own transport. It needs a
+ *   `ChatHandler`, and a `ChatInteraction.Handler` when there are
+ *   clicks: without one a click is logged and dropped. `deadline` is a
+ *   click handler's share, 3 seconds by default.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class WhatsAppChat extends Context.Service Effect.Effect
+  readonly markRead: (
+    thread: ChatThread,
+    messageId: string,
+    options?: { readonly typing?: boolean | undefined }
+  ) => Effect.Effect
+  readonly receive: (envelope: unknown, options?: {
+    readonly onUpdate?: ((update: WhatsAppUpdate) => Effect.Effect) | undefined
+    readonly deadline?: Duration.Duration | undefined
+  }) => Effect.Effect
+}>()("@effect/chat-whatsapp/WhatsAppChat") {}
+
+/**
+ * Registers the WhatsApp adapter in the `Registry`, for one business phone
+ * number.
+ *
+ * **Details**
+ *
+ * - Capabilities: `replyTo`, `files`, `download`, `getThread`,
+ *   `opener`, `buttons` and `selects`. Every other op fails
+ *   `Unsupported`. WhatsApp has no edit, so `ChatMarkdown` posts each
+ *   part of a streamed reply once.
+ * - Every `post` is one send, and every check runs before any upload or
+ *   send. `Posted` means Meta accepted the message, not that it was
+ *   delivered: a later `failed` status goes to `onUpdate`. A send that
+ *   failed after the request left is `uncertain`.
+ * - Markdown is rendered to WhatsApp's formatting: bold as `*b*`, italics
+ *   as `_i_`, strikethrough as `~s~`, a link as `label (url)`, a heading
+ *   as bold, a table without its delimiter row and a fence without its info
+ *   string. Each replacement is used only when it is no longer than the
+ *   Markdown it replaces, so the text never grows; anything else is sent as
+ *   typed. `descriptor.measure` counts the Markdown in UTF-16 units.
+ * - Link previews are off unless `withPostOptions({ linkPreview: true })`.
+ * - One file per post. It is uploaded, then sent as one media message with
+ *   the text as its caption, or as the header of a message with reply
+ *   buttons or a link button. Refused with `TooLarge`, subject `files` and
+ *   detail `file_refused`, before anything is sent: more than one file, a
+ *   MIME type outside Meta's table, `image/webp`, a file past its type's
+ *   size limit, audio with text or actions, text over 1,024 beside a file,
+ *   and a file beside a list. `text/markdown` is uploaded as
+ *   `text/plain`, with its bytes and name unchanged.
+ * - Actions: one to three buttons with labels up to 20 go as reply buttons;
+ *   a lone link button with a label up to 20 as a link button; otherwise
+ *   buttons and select options become the rows of one list, at most ten,
+ *   with labels up to 24. Link buttons beside anything else, or with a
+ *   longer label, are appended to the text as `Label: url` lines. A body
+ *   beside reply buttons or a link button is held to 1,024, which
+ *   `descriptor.measure` counts. A post with actions and no text gets the
+ *   labels, joined by ", ", as its text.
+ * - The list's button is the first select's placeholder, or
+ *   `withPostOptions({ listButton })`, "Options" by default, up to 20.
+ *   With buttons and a select, or two selects, each section has a title up
+ *   to 24: the select's placeholder, or `buttonsSection`, "Actions" by
+ *   default, for the buttons.
+ * - Refused before the call: more than ten rows (`TooLarge`,
+ *   `list_rows`), a label past its limit (`TooLarge`,
+ *   `label_too_long`), an id holding U+241F, two reply buttons with one
+ *   label, and two elements with one id and value (`InvalidRequest`). A
+ *   select's `selected` and a button's `style` are ignored.
+ * - `getThread` is built from the address alone, as `direct`. `opener`
+ *   is always `None`.
+ * - The pair rate limit is one message every 6 seconds to one user, which is
+ *   `limits.minWriteInterval`. Meta refuses a faster pace with error
+ *   131056, `RateLimited`.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layer = (options: {
+  readonly accessToken: Redacted.Redacted
+  readonly phoneNumberId: string
+  readonly baseUrl?: string | undefined
+}): Layer.Layer =>
+  Layer.effect(
+    WhatsAppChat,
+    Effect.gen(function*() {
+      const graph = yield* WhatsAppGraphApi
+      const http = yield* HttpClient.HttpClient
+      const registry = yield* Registry
+      const { adapter, markRead, sendTemplate } = Adapter.make({
+        graph,
+        http,
+        accessToken: options.accessToken,
+        phoneNumberId: options.phoneNumberId
+      })
+      yield* registry.register(adapter)
+      const context = { phoneNumberId: options.phoneNumberId }
+      return WhatsAppChat.of({
+        phoneNumberId: options.phoneNumberId,
+        sendTemplate,
+        markRead,
+        receive: (envelope, receiveOptions) =>
+          Effect.flatMap(ChatHandler, (handler) =>
+            Webhook.receive(Normalize.normalize(envelope, context), {
+              handle: handler.handle,
+              onUpdate: receiveOptions?.onUpdate,
+              clickDeadline: Effect.succeed(receiveOptions?.deadline ?? Duration.seconds(3))
+            }))
+      })
+    })
+  ).pipe(Layer.provideMerge(GraphApi.layer({ accessToken: options.accessToken, baseUrl: options.baseUrl })))
+
+/**
+ * The address of a WhatsApp user: `{phoneNumberId}/u/{user}`, where
+ * `user` is a phone number in digits or a BSUID.
+ *
+ * @stability unstable
+ * @category constructors
+ * @since 4.1.5
+ */
+export const thread = (parts: { readonly phoneNumberId: string; readonly user: string }): ChatThread =>
+  Address.thread({ phoneNumberId: parts.phoneNumberId, kind: "user", id: parts.user })
+
+/**
+ * The parts of a WhatsApp address, or `None` for another platform's or a
+ * malformed one. A group address, which is reserved, has `kind` `group`.
+ *
+ * @stability unstable
+ * @category destructors
+ * @since 4.1.5
+ */
+export const parts: (thread: ChatThread) => Option.Option<{
+  readonly phoneNumberId: string
+  readonly kind: "user" | "group"
+  readonly id: string
+}> = Address.parts
+
+/**
+ * `GET {path}` and `POST {path}`: the webhook's subscription check and its
+ * deliveries.
+ *
+ * **Details**
+ *
+ * - `GET` answers Meta's check with `hub.challenge` when `hub.verify_token`
+ *   is `verifyToken`, and 403 otherwise.
+ * - `POST` checks `X-Hub-Signature-256` with the app secret (401), reads
+ *   at most `maxBodyBytes` (3 MiB by default, 413), and drops a delivery
+ *   for another object or another phone number with a 200.
+ * - The updates run in order. Messages and reactions go to the
+ *   `ChatHandler`, clicks to `ChatInteraction.handle`, and statuses and
+ *   changed ids to `onUpdate`. A removed reaction is dropped.
+ * - A `NotAccepted` stops the delivery and answers 503, as does a request
+ *   that takes longer than `deadline` (4 seconds by default, provisional).
+ *   Meta then delivers the whole batch again, for up to 7 days, so a batch
+ *   that always runs past the deadline repeats until then.
+ * - A click never causes a 503. It gets what is left of the deadline, less
+ *   a margin. `Ack` and `Late` count as handled, and a late handler keeps
+ *   running. `OpenModal` goes to `Handler.refused` as
+ *   `Unsupported("modals")`. Without a `ChatInteraction.Handler` in the
+ *   layer's context, a click is logged and dropped.
+ * - Delivery is at least once. A message, a reaction or a click can arrive
+ *   twice, a click even at the same time as its first delivery. Drop
+ *   repeated events with `ChatEvent.dedupeKey`; a click handler for which
+ *   a second run is unsafe must claim `deliveryKey` atomically, before any
+ *   side effect. The adapter keeps no seen-store. Deliveries are not in
+ *   order either: order by the updates' timestamps.
+ *
+ * Signature checks use the required `Mac` service. Provide
+ * `NodeCrypto.layerMac`, `BunCrypto.layerMac`, `DenoCrypto.layerMac`,
+ * `BrowserCrypto.layerMac`, or `Mac.layerWebCrypto` with
+ * `SecureRandom.layerWebCrypto` for other runtimes such as Workers.
+ * Key construction failures are configuration defects; verification errors
+ * fail the signature check (401).
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layerWebhook = (options: {
+  readonly path: `/${string}`
+  readonly appSecret: Redacted.Redacted
+  readonly verifyToken: Redacted.Redacted
+  readonly onUpdate?: ((update: WhatsAppUpdate) => Effect.Effect) | undefined
+  readonly deadline?: Duration.Duration | undefined
+  readonly maxBodyBytes?: number | undefined
+}): Layer.Layer =>
+  HttpRouter.use(Effect.fnUntraced(function*(router) {
+    const whatsapp = yield* WhatsAppChat
+    const handler = yield* ChatHandler
+    const interactions = yield* Effect.serviceOption(ChatInteraction.Handler)
+    const verify = yield* Webhook.makeVerifier(options.appSecret)
+    const context = { phoneNumberId: whatsapp.phoneNumberId }
+    const webhookOptions: Webhook.Options = {
+      verify,
+      normalize: (envelope) => Normalize.normalize(envelope, context),
+      handle: handler.handle,
+      onUpdate: options.onUpdate,
+      deadline: options.deadline ?? Duration.seconds(4),
+      maxBodyBytes: options.maxBodyBytes ?? 3 * 1024 * 1024
+    }
+    yield* router.add(
+      "GET",
+      options.path,
+      (request) => Effect.succeed(Webhook.handleVerification(request, options.verifyToken))
+    )
+    yield* router.add("POST", options.path, (request) => {
+      const response = Webhook.handleRequest(request, webhookOptions)
+      return Option.isSome(interactions)
+        ? Effect.provideService(response, ChatInteraction.Handler, interactions.value)
+        : response
+    })
+  }))
+
+/**
+ * The normaliser, for a consumer's own transport.
+ *
+ * **Details**
+ *
+ * - Pure: takes a parsed webhook body, gives what it holds, in order. A
+ *   change for another phone number, and a group message, give nothing.
+ * - A message's `thread` is the sender's BSUID address when the webhook
+ *   has one, and its phone number address otherwise. `kind` is
+ *   `direct`. Text is as the user typed it, a caption for media, and empty
+ *   for a message with neither, such as a location. Media are attachments,
+ *   with the media id as their `id`.
+ * - `raw` of an event or a click is the change's `metadata`, the
+ *   sender's entry of `contacts`, with `wa_id` when Meta shares the
+ *   number, and the one message. `message.raw` is the message.
+ * - A reaction with an emoji is `ReactionAdded`; a removed reaction gives
+ *   nothing.
+ * - A reply button or a list row the adapter built is `ButtonClicked` or
+ *   `SelectChanged`, whose `messageId` is the message that carried it.
+ *   Any other interactive reply gives nothing.
+ * - Statuses give `Status`, and `Alias` too when they carry both ids. A
+ *   `system` message about a changed number or id gives `UserIdChanged`.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const normalize: (
+  envelope: unknown,
+  context: { readonly phoneNumberId: string }
+) => ReadonlyArray = Normalize.normalize
+
+const encodeKey = (parts: ReadonlyArray) => parts.map(encodeURIComponent).join("/")
+
+const phoneNumberOf = (thread: ChatThread) => thread.id.split("/")[0]
+
+/**
+ * The key of one delivery of a click or a reaction:
+ * `{phoneNumberId}/{messageId}`, the id of the webhook message that carried
+ * it, each part percent-encoded.
+ *
+ * **When to use**
+ *
+ * Use to make a click handler safe to run twice. Meta redelivers a batch
+ * that was not answered in time, so a click can run again, even at the same
+ * time as the first run. Claim the key atomically, such as with an insert
+ * that fails on a duplicate, before any side effect, and skip the click when
+ * the claim fails.
+ *
+ * @stability unstable
+ * @category getters
+ * @since 4.1.5
+ */
+export const deliveryKey = (
+  event: ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged | ChatEvent.ReactionAdded
+): string => {
+  const raw = event.raw as { readonly messages?: ReadonlyArray<{ readonly id?: unknown }> }
+  const id = Array.isArray(raw?.messages) && typeof raw.messages[0]?.id === "string" ? raw.messages[0].id : ""
+  return encodeKey([phoneNumberOf(event.thread), id])
+}
+
+/**
+ * The key of an update, for dropping a redelivered one, its parts
+ * percent-encoded and joined by `/`.
+ *
+ * **Details**
+ *
+ * - `Status`: `{phoneNumberId}/status/{messageId}/{status}`.
+ * - `UserIdChanged`: `{phoneNumberId}/user_changed/{id}`.
+ * - `Alias`: `{phoneNumberId}/alias/{messageId}/{status}/{phone}/{userId}`.
+ *
+ * @stability unstable
+ * @category getters
+ * @since 4.1.5
+ */
+export const updateKey = (update: WhatsAppUpdate): string => {
+  const phoneNumberId = phoneNumberOf(update.thread)
+  switch (update._tag) {
+    case "Status":
+      return encodeKey([phoneNumberId, "status", update.messageId, update.status])
+    case "UserIdChanged":
+      return encodeKey([phoneNumberId, "user_changed", update.id])
+    case "Alias":
+      return encodeKey([phoneNumberId, "alias", update.messageId, update.status, update.phone, update.userId])
+  }
+}
+
+/**
+ * WhatsApp options for every write inside an effect.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface WhatsAppPostOptions {
+  /** A preview of the first link in a text message. Default false. */
+  readonly linkPreview?: boolean | undefined
+  /** The button that opens a list, when no select has a placeholder. Default "Options", up to 20. */
+  readonly listButton?: string | undefined
+  /** The title of a list's buttons section beside a select. Default "Actions", up to 24. */
+  readonly buttonsSection?: string | undefined
+}
+
+/**
+ * Scoped WhatsApp options for every write inside `effect`. Nested calls
+ * merge, the inner one winning field by field.
+ *
+ * @stability unstable
+ * @category combinators
+ * @since 4.1.5
+ */
+export const withPostOptions: {
+  (options: WhatsAppPostOptions): (effect: Effect.Effect) => Effect.Effect
+  (effect: Effect.Effect, options: WhatsAppPostOptions): Effect.Effect
+} = dual(
+  2,
+  (effect: Effect.Effect, options: WhatsAppPostOptions): Effect.Effect =>
+    Effect.updateService(effect, CurrentPostOptions, (current) => ({ ...current, ...options }))
+)
+
+/**
+ * WhatsApp has no mention tokens outside groups, so nothing is a mention:
+ * for `ChatTest.checkMessage`, `ChatTest.checkEvent` and
+ * `ChatTest.conformance`.
+ *
+ * @stability unstable
+ * @category testing
+ * @since 4.1.5
+ */
+export const parseMention: ParseMention = () => Option.none()
diff --git a/packages/chat/whatsapp/src/WhatsAppGraphApi.ts b/packages/chat/whatsapp/src/WhatsAppGraphApi.ts
new file mode 100644
index 00000000000..12e0a7164f2
--- /dev/null
+++ b/packages/chat/whatsapp/src/WhatsAppGraphApi.ts
@@ -0,0 +1,146 @@
+/**
+ * The minimal Graph API client the WhatsApp adapter is built on. It is
+ * public, so a consumer can call an endpoint the adapter has no op for, with
+ * the same error mapping and the same rule for writes.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import { retrySafe } from "effect/chat/ChatAdapter"
+import type { ChatError, ChatErrorReason } from "effect/chat/ChatError"
+import * as Context from "effect/Context"
+import * as Effect from "effect/Effect"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Errors from "./internal/errors.ts"
+
+/**
+ * Options for one Graph call.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface CallOptions {
+  /** Default `GET`, or `POST` when there is a `body` or a `form`. */
+  readonly method?: "GET" | "POST" | "DELETE" | undefined
+  /** Sent as JSON. */
+  readonly body?: Readonly> | undefined
+  /** Sent as `multipart/form-data`, as a media upload is. */
+  readonly form?: FormData | undefined
+  /** Query parameters. */
+  readonly params?: Readonly> | undefined
+  /**
+   * The call changes something. It is never repeated once the request left,
+   * and a failure that may have landed is `uncertain`.
+   */
+  readonly write?: boolean | undefined
+  /** Retry `retry` failures, as `ChatAdapter.retrySafe` does. Default true. */
+  readonly retry?: boolean | undefined
+}
+
+/**
+ * The minimal Graph API client, with the access token.
+ *
+ * **Details**
+ *
+ * - `call` requests `{baseUrl}/{path}` with the token as a bearer token,
+ *   and succeeds with the JSON of a 2xx answer.
+ * - Another answer fails with the reason for its Graph error code, whose
+ *   `detail` is `graph_{code}` and whose `cause` is the Graph `error`
+ *   object, or for its HTTP status when it has no Graph error.
+ * - A write never repeats once the request left: a transport failure, a
+ *   server error or an unreadable answer is `uncertain`. A refusal that
+ *   Meta answers before sending, such as a rate limit, is retried unless
+ *   `retry: false`, as a read's `retry` failures are.
+ * - The error's `op` is the path.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class WhatsAppGraphApi extends Context.Service Effect.Effect
+}>()("@effect/chat-whatsapp/WhatsAppGraphApi") {}
+
+/**
+ * The Graph API version the adapter was written against.
+ *
+ * @stability unstable
+ * @category constants
+ * @since 4.1.5
+ */
+export const defaultBaseUrl = "https://graph.facebook.com/v24.0"
+
+/**
+ * Builds the client from an `HttpClient` and a system user access token.
+ *
+ * @stability unstable
+ * @category constructors
+ * @since 4.1.5
+ */
+export const make = Effect.fnUntraced(function*(options: {
+  readonly accessToken: Redacted.Redacted
+  readonly baseUrl?: string | undefined
+}) {
+  const http = yield* HttpClient.HttpClient
+  const baseUrl = options.baseUrl ?? defaultBaseUrl
+
+  const once = (path: string, callOptions: CallOptions) => {
+    const write = callOptions.write === true
+    const fail = (reason: ChatErrorReason) => Effect.fail(Errors.chatError(path, reason))
+    const method = callOptions.method ??
+      (callOptions.body !== undefined || callOptions.form !== undefined ? "POST" : "GET")
+    let request = HttpClientRequest.make(method)(`${baseUrl}/${path}`).pipe(
+      HttpClientRequest.bearerToken(Redacted.value(options.accessToken))
+    )
+    if (callOptions.params !== undefined) request = HttpClientRequest.setUrlParams(request, callOptions.params)
+    if (callOptions.form !== undefined) request = HttpClientRequest.bodyFormData(request, callOptions.form)
+    else if (callOptions.body !== undefined) request = HttpClientRequest.bodyJsonUnsafe(request, callOptions.body)
+    return http.execute(request).pipe(
+      Effect.catch((error) => fail(Errors.transport(write, error.reason._tag, error))),
+      Effect.flatMap((response) =>
+        response.json.pipe(
+          Effect.matchEffect({
+            onFailure: (error) =>
+              response.status >= 200 && response.status < 300
+                ? fail(Errors.invalidResponse(write, "invalid_json", error))
+                : fail(Errors.reasonForStatus(response.status, { write })),
+            onSuccess: (json): Effect.Effect => {
+              if (response.status >= 200 && response.status < 300) return Effect.succeed(json as Schema.Json)
+              const graph = Errors.graphError(json)
+              const cause = typeof json === "object" && json !== null && "error" in json ? json.error : json
+              return fail(
+                graph === undefined
+                  ? Errors.reasonForStatus(response.status, { write, cause })
+                  : Errors.reasonForGraphError(graph, { write, cause })
+              )
+            }
+          })
+        )
+      )
+    )
+  }
+
+  return WhatsAppGraphApi.of({
+    call: (path, callOptions = {}) => {
+      const call = once(path, callOptions)
+      return callOptions.retry === false ? call : retrySafe(call)
+    }
+  })
+})
+
+/**
+ * The client as a layer.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layer = (options: {
+  readonly accessToken: Redacted.Redacted
+  readonly baseUrl?: string | undefined
+}): Layer.Layer => Layer.effect(WhatsAppGraphApi, make(options))
diff --git a/packages/chat/whatsapp/src/WhatsAppUpdate.ts b/packages/chat/whatsapp/src/WhatsAppUpdate.ts
new file mode 100644
index 00000000000..60c942a1843
--- /dev/null
+++ b/packages/chat/whatsapp/src/WhatsAppUpdate.ts
@@ -0,0 +1,142 @@
+/**
+ * What WhatsApp reports beside messages: delivery statuses, a user's changed
+ * id, and the link between a phone number and a business-scoped user id.
+ * They go to the `onUpdate` of `WhatsAppChat.layerWebhook` and
+ * `WhatsAppChat.receive`, not to the `ChatHandler`.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import { ChatErrorReason } from "effect/chat/ChatError"
+import { ChatThread } from "effect/chat/ChatThread"
+import * as Schema from "effect/Schema"
+
+/**
+ * Schema for the status of a message the business sent.
+ *
+ * **Details**
+ *
+ * - `thread` is the recipient's address, with the business-scoped user id
+ *   when the status carries one and the phone number when it does not.
+ * - `messageId` is the id `post` gave. A `failed` status has the
+ *   `reason` for Meta's error, mapped as a refused call is.
+ * - `phone` and `userId` are the recipient's phone number and
+ *   business-scoped user id, each when the status carries it.
+ * - `raw` is the change's `metadata` and the one status.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const Status = Schema.TaggedStruct("Status", {
+  thread: ChatThread,
+  messageId: Schema.String,
+  status: Schema.Literals(["sent", "delivered", "read", "failed"]),
+  timestamp: Schema.optionalKey(Schema.DateTimeUtc),
+  reason: Schema.optionalKey(ChatErrorReason),
+  phone: Schema.optionalKey(Schema.String),
+  userId: Schema.optionalKey(Schema.String),
+  raw: Schema.Json
+})
+
+/**
+ * The status of a message the business sent.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Status = typeof Status.Type
+
+/**
+ * Schema for a user's changed phone number or business-scoped user id, from
+ * a `system` message.
+ *
+ * **Details**
+ *
+ * - `thread` is the user's new address. A thread kept under the old one no
+ *   longer receives messages from the user.
+ * - `id` is the system message's id. `change` is Meta's `type`:
+ *   `user_changed_number` or `user_changed_user_id`.
+ * - `userId`, `previousUserId` and `phone` are there when Meta sends
+ *   them. `previousPhone` is the system message's `from`.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const UserIdChanged = Schema.TaggedStruct("UserIdChanged", {
+  thread: ChatThread,
+  id: Schema.String,
+  change: Schema.Literals(["user_changed_number", "user_changed_user_id"]),
+  userId: Schema.optionalKey(Schema.String),
+  previousUserId: Schema.optionalKey(Schema.String),
+  phone: Schema.optionalKey(Schema.String),
+  previousPhone: Schema.optionalKey(Schema.String),
+  timestamp: Schema.optionalKey(Schema.DateTimeUtc),
+  raw: Schema.Json
+})
+
+/**
+ * A user's changed phone number or business-scoped user id.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type UserIdChanged = typeof UserIdChanged.Type
+
+/**
+ * Schema for a phone number and a business-scoped user id that name one
+ * user.
+ *
+ * **Details**
+ *
+ * - Given for every `sent`, `delivered` or `read` status that carries
+ *   both, beside the `Status`. Nothing is remembered between batches, so the
+ *   same pair comes again and again.
+ * - A message posted to a phone number address reports back with the
+ *   user's business-scoped id, which is how a consumer learns that the
+ *   inbound address (`thread`, always the business-scoped form) and the
+ *   phone number address are one user. The adapter never rewrites an
+ *   address.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const Alias = Schema.TaggedStruct("Alias", {
+  thread: ChatThread,
+  phone: Schema.String,
+  userId: Schema.String,
+  messageId: Schema.String,
+  status: Schema.Literals(["sent", "delivered", "read"]),
+  raw: Schema.Json
+})
+
+/**
+ * A phone number and a business-scoped user id that name one user.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Alias = typeof Alias.Type
+
+/**
+ * Schema for any update.
+ *
+ * @stability unstable
+ * @category schemas
+ * @since 4.1.5
+ */
+export const WhatsAppUpdate = Schema.Union([Status, UserIdChanged, Alias])
+
+/**
+ * Any update.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type WhatsAppUpdate = typeof WhatsAppUpdate.Type
diff --git a/packages/chat/whatsapp/src/index.ts b/packages/chat/whatsapp/src/index.ts
new file mode 100644
index 00000000000..84c2ba8db9e
--- /dev/null
+++ b/packages/chat/whatsapp/src/index.ts
@@ -0,0 +1,24 @@
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+
+// @barrel: Auto-generated exports. Do not edit manually.
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as WhatsAppChat from "./WhatsAppChat.ts"
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as WhatsAppGraphApi from "./WhatsAppGraphApi.ts"
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as WhatsAppUpdate from "./WhatsAppUpdate.ts"
diff --git a/packages/chat/whatsapp/src/internal/actions.ts b/packages/chat/whatsapp/src/internal/actions.ts
new file mode 100644
index 00000000000..34898538465
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/actions.ts
@@ -0,0 +1,216 @@
+import { type ChatErrorReason, InvalidRequest, TooLarge } from "effect/chat/ChatError"
+import type { Action, Button, LinkButton, Select } from "effect/chat/ChatUi"
+import { defaultButtonsSection, defaultListButton, type PostOptions } from "./options.ts"
+import { shortBodyLength } from "./text.ts"
+
+/** Between an element's id and its value in a wire id. @internal */
+export const join = "\u241F"
+
+/** @internal */
+export const limits = { actionsPerMessage: 10, actionDataLength: 198 } as const
+
+const replyLabelLength = 20
+const rowTitleLength = 24
+const listButtonLength = 20
+const sectionTitleLength = 24
+const maxRows = 10
+
+/** What the measure adds for a layout whose body is held to 1,024 rather than 4,096. @internal */
+export const shortBodyOffset = 4096 - shortBodyLength
+
+/** @internal */
+export type Kind = "none" | "reply" | "cta" | "list"
+
+/** @internal */
+export interface Shape {
+  readonly kind: Kind
+  /** The link buttons that go as `Label: url` lines after the body. */
+  readonly appended: ReadonlyArray
+}
+
+/** The layout of a message's actions, which depends on the actions alone. @internal */
+export const shape = (actions: ReadonlyArray): Shape => {
+  const buttons = actions.filter((action): action is Button => action._tag === "Button")
+  const links = actions.filter((action): action is LinkButton => action._tag === "LinkButton")
+  const selects = actions.filter((action) => action._tag === "Select")
+  if (buttons.length === 0 && selects.length === 0) {
+    return links.length === 1 && links[0].label.length <= replyLabelLength
+      ? { kind: "cta", appended: [] }
+      : { kind: "none", appended: links }
+  }
+  const reply = selects.length === 0 && buttons.length <= 3 &&
+    buttons.every((button) => button.label.length <= replyLabelLength)
+  return { kind: reply ? "reply" : "list", appended: links }
+}
+
+/** The body of a post with actions and no Markdown: the labels joined by ", ". @internal */
+export const generatedBody = (actions: ReadonlyArray): string =>
+  actions.map((action) =>
+    action._tag === "Select"
+      ? action.placeholder ?? action.options.map((option) => option.label).join(", ")
+      : action.label
+  ).join(", ")
+
+/** @internal */
+export const linkLines = (links: ReadonlyArray): string =>
+  links.map((link) => link.label + ": " + link.url).join("\n")
+
+/**
+ * What a message's actions add to the measure of its Markdown: the offset of
+ * a 1,024 body, the appended link lines with their separator, and the
+ * generated body, which is always counted.
+ *
+ * @internal
+ */
+export const measure = (actions: ReadonlyArray): number => {
+  if (actions.length === 0) return 0
+  const { appended, kind } = shape(actions)
+  return (kind === "reply" || kind === "cta" ? shortBodyOffset : 0) + generatedBody(actions).length +
+    (appended.length === 0 ? 0 : 2 + linkLines(appended).length)
+}
+
+/** The body as sent: the rendered Markdown, or the generated body, then the link lines. @internal */
+export const body = (rendered: string, actions: ReadonlyArray): string => {
+  const { appended, kind } = shape(actions)
+  const base = rendered.trim() !== "" ? rendered : kind === "none" ? "" : generatedBody(actions)
+  const lines = linkLines(appended)
+  return base === "" ? lines : lines === "" ? base : base + "\n\n" + lines
+}
+
+/** @internal */
+export const buttonWireId = (button: Button): string =>
+  "b" + button.id + (button.value === undefined ? "" : join + button.value)
+
+/** @internal */
+export const optionWireId = (select: Select, value: string): string => "s" + select.id + join + value
+
+/** A wire id read back: the tag, then the id and value split at the first U+241F. @internal */
+export const parseWireId = (
+  wire: string
+): { readonly kind: "button"; readonly id: string; readonly value?: string } | {
+  readonly kind: "select"
+  readonly id: string
+  readonly value: string
+} | undefined => {
+  const rest = wire.slice(1)
+  const at = rest.indexOf(join)
+  if (wire[0] === "b") {
+    return at < 0
+      ? { kind: "button", id: rest }
+      : { kind: "button", id: rest.slice(0, at), value: rest.slice(at + 1) }
+  }
+  if (wire[0] === "s" && at >= 0) return { kind: "select", id: rest.slice(0, at), value: rest.slice(at + 1) }
+  return undefined
+}
+
+/** The `interactive` object of a message, less its body and header. @internal */
+export type Interactive =
+  | { readonly type: "button"; readonly action: unknown }
+  | { readonly type: "cta_url"; readonly action: unknown }
+  | { readonly type: "list"; readonly action: unknown }
+
+/** @internal */
+export interface Plan {
+  readonly kind: Kind
+  readonly interactive?: Interactive | undefined
+}
+
+const tooLarge = (detail: string) => new TooLarge({ detail })
+const invalid = (detail: string) => new InvalidRequest({ detail })
+
+/**
+ * Checks a message's actions and builds their `interactive` object. Every
+ * refusal is found here, before any call.
+ *
+ * @internal
+ */
+export const plan = (actions: ReadonlyArray, options: PostOptions): Plan | ChatErrorReason => {
+  if (actions.length === 0) return { kind: "none" }
+  if (actions.length > limits.actionsPerMessage) return tooLarge("too_many_actions")
+  for (const action of actions) {
+    if (action._tag === "LinkButton") {
+      if (action.label.length > rowTitleLength) return tooLarge("label_too_long")
+      continue
+    }
+    if (action.id.includes(join)) return invalid("invalid_action_id")
+    if (action._tag === "Button") {
+      if (action.id.length + (action.value?.length ?? 0) > limits.actionDataLength) {
+        return tooLarge("action_data_too_long")
+      }
+    } else {
+      if (action.options.length === 0) return invalid("empty_select")
+      for (const option of action.options) {
+        if (action.id.length + option.value.length > limits.actionDataLength) return tooLarge("action_data_too_long")
+      }
+    }
+  }
+  const { kind } = shape(actions)
+  const buttons = actions.filter((action): action is Button => action._tag === "Button")
+  const selects = actions.filter((action): action is Select => action._tag === "Select")
+  const unique = (ids: ReadonlyArray) => new Set(ids).size === ids.length
+  switch (kind) {
+    case "none":
+      return { kind }
+    case "cta": {
+      const link = actions.find((action): action is LinkButton => action._tag === "LinkButton")!
+      return {
+        kind,
+        interactive: {
+          type: "cta_url",
+          action: { name: "cta_url", parameters: { display_text: link.label, url: link.url } }
+        }
+      }
+    }
+    case "reply": {
+      const ids = buttons.map(buttonWireId)
+      if (!unique(buttons.map((button) => button.label))) return invalid("duplicate_label")
+      if (!unique(ids)) return invalid("duplicate_id")
+      return {
+        kind,
+        interactive: {
+          type: "button",
+          action: {
+            buttons: buttons.map((button, i) => ({ type: "reply", reply: { id: ids[i], title: button.label } }))
+          }
+        }
+      }
+    }
+    case "list": {
+      const sections: Array<
+        { readonly title: string; readonly rows: Array<{ readonly id: string; readonly title: string }> }
+      > = []
+      const listButton = options.listButton ?? defaultListButton
+      if (buttons.length > 0) {
+        sections.push({
+          title: options.buttonsSection ?? defaultButtonsSection,
+          rows: buttons.map((button) => ({ id: buttonWireId(button), title: button.label }))
+        })
+      }
+      for (const select of selects) {
+        sections.push({
+          title: select.placeholder ?? listButton,
+          rows: select.options.map((option) => ({ id: optionWireId(select, option.value), title: option.label }))
+        })
+      }
+      const rows = sections.flatMap((section) => section.rows)
+      if (rows.length > maxRows) return tooLarge("list_rows")
+      if (rows.some((row) => row.title.length > rowTitleLength)) return tooLarge("label_too_long")
+      if (!unique(rows.map((row) => row.id))) return invalid("duplicate_id")
+      const opener = selects.find((select) => select.placeholder !== undefined)?.placeholder ?? listButton
+      if (opener.length > listButtonLength) return tooLarge("label_too_long")
+      if (sections.length > 1 && sections.some((section) => section.title.length > sectionTitleLength)) {
+        return tooLarge("label_too_long")
+      }
+      return {
+        kind,
+        interactive: {
+          type: "list",
+          action: {
+            button: opener,
+            sections: sections.map((section) => sections.length > 1 ? section : { rows: section.rows })
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/packages/chat/whatsapp/src/internal/adapter.ts b/packages/chat/whatsapp/src/internal/adapter.ts
new file mode 100644
index 00000000000..1798e41fb81
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/adapter.ts
@@ -0,0 +1,290 @@
+import { type ChatAdapter, checkMessageLength, type Descriptor, type File, type Posted } from "effect/chat/ChatAdapter"
+import {
+  type ChatError,
+  type ChatErrorReason,
+  fileRefused,
+  InvalidRequest,
+  TooLarge,
+  Unsupported
+} from "effect/chat/ChatError"
+import type { ChatThread } from "effect/chat/ChatThread"
+import * as DateTime from "effect/DateTime"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import type * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Stream from "effect/Stream"
+import type { WhatsAppGraphApi } from "../WhatsAppGraphApi.ts"
+import * as Actions from "./actions.ts"
+import * as Address from "./address.ts"
+import * as Errors from "./errors.ts"
+import { CurrentPostOptions } from "./options.ts"
+import * as Text from "./text.ts"
+
+type Json = Schema.Json
+type JsonObject = { readonly [key: string]: Json }
+
+const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u)
+
+const string = (object: JsonObject | undefined, key: string): string | undefined => {
+  const value = object?.[key]
+  return typeof value === "string" && value.length > 0 ? value : undefined
+}
+
+/** @internal */
+export const descriptor: Descriptor = {
+  platform: Address.platform,
+  capabilities: new Set(["replyTo", "files", "download", "getThread", "opener", "buttons", "selects"]),
+  measure: (markdown, actions) => Text.measure(markdown) + Actions.measure(actions ?? []),
+  limits: {
+    messageLength: Text.messageLength,
+    filesPerMessage: 1,
+    uploadBytes: 100 * 1024 * 1024,
+    minWriteInterval: Duration.seconds(6),
+    ...Actions.limits
+  }
+}
+
+type MediaType = "image" | "video" | "audio" | "document"
+
+const megabytes = (n: number) => n * 1024 * 1024
+
+/** Meta's supported media, by MIME type, with the largest upload of each. */
+const mediaTypes: Record = {
+  "image/jpeg": { type: "image", maxBytes: megabytes(5) },
+  "image/png": { type: "image", maxBytes: megabytes(5) },
+  "video/mp4": { type: "video", maxBytes: megabytes(16) },
+  "video/3gpp": { type: "video", maxBytes: megabytes(16) },
+  "audio/aac": { type: "audio", maxBytes: megabytes(16) },
+  "audio/amr": { type: "audio", maxBytes: megabytes(16) },
+  "audio/mpeg": { type: "audio", maxBytes: megabytes(16) },
+  "audio/mp4": { type: "audio", maxBytes: megabytes(16) },
+  "audio/ogg": { type: "audio", maxBytes: megabytes(16) },
+  "text/plain": { type: "document", maxBytes: megabytes(100) },
+  "application/pdf": { type: "document", maxBytes: megabytes(100) },
+  "application/msword": { type: "document", maxBytes: megabytes(100) },
+  "application/vnd.ms-excel": { type: "document", maxBytes: megabytes(100) },
+  "application/vnd.ms-powerpoint": { type: "document", maxBytes: megabytes(100) },
+  "application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
+    type: "document",
+    maxBytes: megabytes(100)
+  },
+  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": { type: "document", maxBytes: megabytes(100) },
+  "application/vnd.openxmlformats-officedocument.presentationml.presentation": {
+    type: "document",
+    maxBytes: megabytes(100)
+  }
+}
+
+/** The MIME type a file is uploaded as: without parameters, and `text/markdown` as `text/plain`. @internal */
+export const uploadType = (contentType: string): string => {
+  const base = contentType.split(";")[0].trim().toLowerCase()
+  return base === "text/markdown" ? "text/plain" : base
+}
+
+const refused = new TooLarge({ subject: "files", detail: fileRefused })
+
+/** A template message: its name, its language and Meta's `components`. @internal */
+export interface Template {
+  readonly name: string
+  readonly language: string
+  readonly components?: ReadonlyArray | undefined
+}
+
+/** @internal */
+export const make = (options: {
+  readonly graph: WhatsAppGraphApi["Service"]
+  readonly http: HttpClient.HttpClient
+  readonly accessToken: Redacted.Redacted
+  readonly phoneNumberId: string
+}) => {
+  const { graph, phoneNumberId } = options
+
+  const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
+
+  const withOp = (op: string) => (error: ChatError) => Errors.chatError(op, error.reason)
+
+  const unsupported = (op: string, capability: Unsupported["capability"]) => fail(op, new Unsupported({ capability }))
+
+  /** The user of a thread this adapter can write to. */
+  const resolve = (op: string, thread: ChatThread): Effect.Effect => {
+    const parts = Address.parts(thread)
+    if (Option.isNone(parts)) return fail(op, new InvalidRequest({ detail: "invalid_thread" }))
+    if (parts.value.kind === "group") return fail(op, new InvalidRequest({ detail: "group_unsupported" }))
+    if (parts.value.phoneNumberId !== phoneNumberId) {
+      return fail(op, new InvalidRequest({ detail: "other_phone_number" }))
+    }
+    return Effect.succeed(parts.value.id)
+  }
+
+  const recipient = (user: string) => Address.isBsuid(user) ? { recipient: user } : { to: user }
+
+  const send = Effect.fnUntraced(function*(op: string, thread: ChatThread, user: string, message: JsonObject) {
+    const answer = yield* graph.call(`${phoneNumberId}/messages`, {
+      body: { messaging_product: "whatsapp", recipient_type: "individual", ...recipient(user), ...message },
+      write: true
+    }).pipe(Effect.mapError(withOp(op)))
+    const messages = isObject(answer) && Array.isArray(answer.messages) ? answer.messages : []
+    const id = isObject(messages[0]) ? string(messages[0], "id") : undefined
+    if (id === undefined) return yield* fail(op, Errors.invalidResponse(true, "missing_message_id"))
+    const timestamp = yield* DateTime.now
+    return { id, thread, timestamp } satisfies Posted
+  })
+
+  /** The checks on a file, before anything is sent: its media type, or the refusal. */
+  const checkFile = (
+    files: ReadonlyArray,
+    caption: string,
+    plan: Actions.Plan
+  ): ChatErrorReason | { readonly file: File; readonly mime: string; readonly type: MediaType } => {
+    if (files.length > 1) return refused
+    const file = files[0]
+    const mime = uploadType(file.contentType)
+    const media = Object.hasOwn(mediaTypes, mime) ? mediaTypes[mime] : undefined
+    if (media === undefined || file.content.length > media.maxBytes) return refused
+    if (plan.kind === "list") return refused
+    if (media.type === "audio" && (caption.trim() !== "" || plan.kind !== "none")) return refused
+    if (caption.length > Text.shortBodyLength) return refused
+    return { file, mime, type: media.type }
+  }
+
+  const upload = (op: string, file: File, mime: string): Effect.Effect => {
+    const form = new FormData()
+    form.append("messaging_product", "whatsapp")
+    form.append("type", mime)
+    form.append("file", new Blob([file.content as Uint8Array], { type: mime }), file.name)
+    return graph.call(`${phoneNumberId}/media`, { form }).pipe(
+      Effect.mapError(withOp(op)),
+      Effect.flatMap((answer) => {
+        const id = isObject(answer) ? string(answer, "id") : undefined
+        return id === undefined ? fail(op, Errors.invalidResponse(false, "missing_media_id")) : Effect.succeed(id)
+      })
+    )
+  }
+
+  const post: ChatAdapter["post"] = Effect.fnUntraced(function*(thread, content) {
+    const op = "post"
+    const user = yield* resolve(op, thread)
+    const actions = content.actions ?? []
+    const postOptions = yield* CurrentPostOptions
+    const plan = Actions.plan(actions, postOptions)
+    if (!("kind" in plan)) return yield* fail(op, plan)
+    yield* checkMessageLength(descriptor, op, content.markdown, actions)
+    const text = Actions.body(Text.render(content.markdown), actions)
+    const files = content.files ?? []
+    const context = content.replyTo === undefined ? {} : { context: { message_id: content.replyTo.messageId } }
+    let header: JsonObject | undefined
+    if (files.length > 0) {
+      const checked = checkFile(files, text, plan)
+      if (!("file" in checked)) return yield* fail(op, checked)
+      const { file, mime, type } = checked
+      const id = yield* upload(op, file, mime)
+      const media: JsonObject = type === "document" ? { id, filename: file.name } : { id }
+      if (plan.interactive === undefined) {
+        const caption = type === "audio" || text.trim() === "" ? {} : { caption: text }
+        return yield* send(op, thread, user, { ...context, type, [type]: { ...media, ...caption } })
+      }
+      header = { type, [type]: media }
+    }
+    if (plan.interactive !== undefined) {
+      return yield* send(op, thread, user, {
+        ...context,
+        type: "interactive",
+        interactive: {
+          type: plan.interactive.type,
+          ...(header === undefined ? {} : { header }),
+          body: { text },
+          action: plan.interactive.action as Json
+        }
+      })
+    }
+    if (text.trim() === "") return yield* fail(op, new InvalidRequest({ detail: "empty_message" }))
+    return yield* send(op, thread, user, {
+      ...context,
+      type: "text",
+      text: { body: text, preview_url: postOptions.linkPreview === true }
+    })
+  })
+
+  const download: ChatAdapter["download"] = (thread, attachment, { maxBytes }) =>
+    Stream.unwrap(Effect.gen(function*() {
+      const op = "download"
+      yield* resolve(op, thread)
+      const tooLarge = Errors.chatError(op, new TooLarge({ subject: "files", detail: "max_bytes" }))
+      if (attachment.size !== undefined && attachment.size > maxBytes) return yield* Effect.fail(tooLarge)
+      const answer = yield* graph.call(encodeURIComponent(attachment.id), {
+        params: { phone_number_id: phoneNumberId }
+      }).pipe(Effect.mapError(withOp(op)))
+      const info = isObject(answer) ? answer : undefined
+      const url = string(info, "url")
+      if (url === undefined) return yield* fail(op, Errors.invalidResponse(false, "missing_url"))
+      const size = info?.file_size
+      if (typeof size === "number" && size > maxBytes) return yield* Effect.fail(tooLarge)
+      const response = yield* options.http.execute(
+        HttpClientRequest.get(url).pipe(HttpClientRequest.bearerToken(Redacted.value(options.accessToken)))
+      ).pipe(Effect.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag, error))))
+      if (response.status < 200 || response.status >= 300) {
+        return yield* fail(op, Errors.reasonForStatus(response.status, { write: false }))
+      }
+      let received = 0
+      return response.stream.pipe(
+        Stream.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag, error))),
+        Stream.mapEffect((chunk) => {
+          received += chunk.length
+          return received > maxBytes ? Effect.fail(tooLarge) : Effect.succeed(chunk)
+        })
+      )
+    }))
+
+  const adapter: ChatAdapter = {
+    descriptor,
+    post,
+    edit: () => unsupported("edit", "edit"),
+    delete: () => unsupported("delete", "delete"),
+    fetchMessage: () => unsupported("fetchMessage", "fetchMessage"),
+    history: () => Stream.fail(Errors.chatError("history", new Unsupported({ capability: "history" }))),
+    download,
+    startThread: () => unsupported("startThread", "startThread"),
+    getThread: (thread) =>
+      Effect.map(resolve("getThread", thread), (user) => ({
+        thread,
+        kind: "direct" as const,
+        raw: { phoneNumberId, user }
+      })),
+    opener: (thread) => Effect.as(resolve("opener", thread), Option.none()),
+    getUser: () => unsupported("getUser", "getUser"),
+    followUp: () => unsupported("followUp", "commands")
+  }
+
+  const sendTemplate = (thread: ChatThread, template: Template): Effect.Effect =>
+    Effect.flatMap(resolve("sendTemplate", thread), (user) =>
+      send("sendTemplate", thread, user, {
+        type: "template",
+        template: {
+          name: template.name,
+          language: { code: template.language },
+          ...(template.components === undefined ? {} : { components: template.components })
+        }
+      }))
+
+  const markRead = (
+    thread: ChatThread,
+    messageId: string,
+    markOptions?: { readonly typing?: boolean | undefined }
+  ): Effect.Effect =>
+    Effect.flatMap(resolve("markRead", thread), () =>
+      graph.call(`${phoneNumberId}/messages`, {
+        body: {
+          messaging_product: "whatsapp",
+          status: "read",
+          message_id: messageId,
+          ...(markOptions?.typing === true ? { typing_indicator: { type: "text" } } : {})
+        },
+        write: true
+      }).pipe(Effect.mapError(withOp("markRead")), Effect.asVoid))
+
+  return { adapter, sendTemplate, markRead }
+}
diff --git a/packages/chat/whatsapp/src/internal/address.ts b/packages/chat/whatsapp/src/internal/address.ts
new file mode 100644
index 00000000000..ce9a969c923
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/address.ts
@@ -0,0 +1,41 @@
+import * as ChatThread from "effect/chat/ChatThread"
+import * as Option from "effect/Option"
+
+/** @internal */
+export const platform = "whatsapp"
+
+/** @internal */
+export interface Parts {
+  readonly phoneNumberId: string
+  readonly kind: "user" | "group"
+  readonly id: string
+}
+
+const digits = /^\d+$/
+
+/**
+ * A business-scoped user id, such as `US.13491208655302741918`, or a parent
+ * one, such as `US.ENT.11815799212886844830`. The grammar is read from
+ * examples, not from a specification.
+ *
+ * @internal
+ */
+export const isBsuid = (id: string): boolean => /^[A-Z]{2}(?:\.[A-Z0-9]+)+$/.test(id)
+
+/** A phone number in digits, or a BSUID. @internal */
+export const isUser = (id: string): boolean => digits.test(id) || isBsuid(id)
+
+/** @internal */
+export const thread = (parts: Parts): ChatThread.ChatThread =>
+  ChatThread.make(platform, `${parts.phoneNumberId}/${parts.kind === "user" ? "u" : "g"}/${parts.id}`)
+
+/** @internal */
+export const parts = (address: ChatThread.ChatThread): Option.Option => {
+  if (address.platform !== platform) return Option.none()
+  const segments = address.id.split("/")
+  if (segments.length !== 3 || !digits.test(segments[0]) || segments[2].length === 0) return Option.none()
+  const [phoneNumberId, kind, id] = segments
+  if (kind === "u") return isUser(id) ? Option.some({ phoneNumberId, kind: "user", id }) : Option.none()
+  if (kind === "g") return Option.some({ phoneNumberId, kind: "group", id })
+  return Option.none()
+}
diff --git a/packages/chat/whatsapp/src/internal/errors.ts b/packages/chat/whatsapp/src/internal/errors.ts
new file mode 100644
index 00000000000..873b11bd6f8
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/errors.ts
@@ -0,0 +1,103 @@
+import {
+  ChatError,
+  type ChatErrorReason,
+  Forbidden,
+  InvalidRequest,
+  InvalidResponse,
+  NotFound,
+  PlatformUnavailable,
+  RateLimited,
+  TooLarge,
+  Transport,
+  Unauthenticated,
+  Unknown
+} from "effect/chat/ChatError"
+import { platform } from "./address.ts"
+
+/** The detail of a send refused outside the 24 hour window, Graph error 131047. @internal */
+export const outsideWindow = "graph_131047"
+
+const unauthenticated = new Set([0, 102, 190])
+
+const forbidden = new Set([
+  3,
+  10,
+  368,
+  131030,
+  131031,
+  131042,
+  131045,
+  131047,
+  131049,
+  131050,
+  133010
+])
+
+const rateLimited = new Set([4, 17, 32, 613, 80007, 130429, 131048, 131056])
+
+const unavailable = new Set([1, 2, 131000, 131016])
+
+/** An error a Graph answer carries, in an `error` field or in a status's `errors`. @internal */
+export interface GraphError {
+  readonly code: number
+  readonly subcode?: number | undefined
+}
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/** The Graph error in an answer's body, if it has one. @internal */
+export const graphError = (body: unknown): GraphError | undefined => {
+  const error = isObject(body) && isObject(body.error) ? body.error : body
+  if (!isObject(error) || typeof error.code !== "number") return undefined
+  return { code: error.code, ...(typeof error.error_subcode === "number" ? { subcode: error.error_subcode } : {}) }
+}
+
+/**
+ * Maps a Graph error code to a reason. `detail` is `graph_{code}`, which
+ * holds no message text or ids. The Graph error itself is the `cause`.
+ *
+ * @internal
+ */
+export const reasonForGraphError = (
+  error: GraphError,
+  options: { readonly write: boolean; readonly cause?: unknown }
+): ChatErrorReason => {
+  const fields = { detail: `graph_${error.code}`, ...(options.cause === undefined ? {} : { cause: options.cause }) }
+  if (rateLimited.has(error.code)) return new RateLimited(fields)
+  if (unauthenticated.has(error.code)) return new Unauthenticated(fields)
+  if (forbidden.has(error.code) || (error.code >= 200 && error.code < 300)) return new Forbidden(fields)
+  if (unavailable.has(error.code)) {
+    return new PlatformUnavailable({ retry: options.write ? "uncertain" : "retry", ...fields })
+  }
+  if (error.code === 100 && error.subcode === 33) return new NotFound(fields)
+  if (error.code === 131053) return new TooLarge({ subject: "files", ...fields })
+  return new InvalidRequest(fields)
+}
+
+/** @internal */
+export const reasonForStatus = (
+  status: number,
+  options: { readonly write: boolean; readonly cause?: unknown }
+): ChatErrorReason => {
+  const fields = { detail: `http_${status}`, ...(options.cause === undefined ? {} : { cause: options.cause }) }
+  if (status === 429) return new RateLimited(fields)
+  if (status >= 500) return new PlatformUnavailable({ retry: options.write ? "uncertain" : "retry", ...fields })
+  if (status === 401) return new Unauthenticated(fields)
+  if (status === 403) return new Forbidden(fields)
+  if (status === 404) return new NotFound(fields)
+  if (status === 413) return new TooLarge(fields)
+  return new InvalidRequest(fields)
+}
+
+/** A request that failed before an answer came. A write may have landed. @internal */
+export const transport = (write: boolean, detail: string, cause?: unknown): ChatErrorReason =>
+  new Transport({ retry: write ? "uncertain" : "retry", detail, ...(cause === undefined ? {} : { cause }) })
+
+/** An answer the adapter cannot read. A write may have landed. @internal */
+export const invalidResponse = (write: boolean, detail: string, cause?: unknown): ChatErrorReason => {
+  const fields = { detail, ...(cause === undefined ? {} : { cause }) }
+  return write ? new Unknown(fields) : new InvalidResponse(fields)
+}
+
+/** @internal */
+export const chatError = (op: string, reason: ChatErrorReason): ChatError => new ChatError({ platform, op, reason })
diff --git a/packages/chat/whatsapp/src/internal/normalize.ts b/packages/chat/whatsapp/src/internal/normalize.ts
new file mode 100644
index 00000000000..6c20b311ddb
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/normalize.ts
@@ -0,0 +1,242 @@
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import type * as ChatInteraction from "effect/chat/ChatInteraction"
+import type { Attachment, ChatMessage } from "effect/chat/ChatMessage"
+import type { ChatThread } from "effect/chat/ChatThread"
+import * as DateTime from "effect/DateTime"
+import type * as Schema from "effect/Schema"
+import type * as Update from "../WhatsAppUpdate.ts"
+import { parseWireId } from "./actions.ts"
+import * as Address from "./address.ts"
+import { reasonForGraphError } from "./errors.ts"
+
+type Json = Schema.Json
+type JsonObject = { readonly [key: string]: Json }
+
+/** What one webhook delivery holds, in order. @internal */
+export type Inbound =
+  | ChatEvent.MessageCreated
+  | ChatEvent.ReactionAdded
+  | ChatInteraction.ButtonClicked
+  | ChatInteraction.SelectChanged
+  | Update.WhatsAppUpdate
+
+/** A phone number without its formatting: Meta may show `display_phone_number` with `+`, spaces or dashes. */
+const digits = (phone: string) => phone.replace(/\D/g, "")
+
+const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u)
+
+const string = (object: JsonObject | undefined, key: string): string | undefined => {
+  const value = object?.[key]
+  return typeof value === "string" && value.length > 0 ? value : undefined
+}
+
+const object = (object: JsonObject | undefined, key: string): JsonObject | undefined => {
+  const value = object?.[key]
+  return isObject(value) ? value : undefined
+}
+
+const array = (value: Json | undefined): ReadonlyArray => Array.isArray(value) ? value : []
+
+const timestamp = (value: string | undefined) => {
+  const seconds = Number(value)
+  return value !== undefined && Number.isFinite(seconds) ? DateTime.makeUnsafe(seconds * 1000) : undefined
+}
+
+const media = ["image", "video", "audio", "document", "sticker"] as const
+
+/** Whether a message is from a group, which the adapter does not support yet. @internal */
+export const isGroupMessage = (message: Json): boolean =>
+  isObject(message) && (message.group_id !== undefined || string(object(message, "context"), "group_id") !== undefined)
+
+/** The messages of a delivery that are from groups. @internal */
+export const groupMessages = (envelope: unknown): number => {
+  let count = 0
+  if (!isObject(envelope)) return count
+  for (const entry of array(envelope.entry)) {
+    for (const change of array(isObject(entry) ? entry.changes : undefined)) {
+      const value = isObject(change) ? object(change, "value") : undefined
+      for (const message of array(value?.messages)) if (isGroupMessage(message)) count++
+      for (const status of array(value?.statuses)) if (isObject(status) && status.recipient_type === "group") count++
+    }
+  }
+  return count
+}
+
+const fromMessage = (
+  value: JsonObject,
+  metadata: JsonObject,
+  phoneNumberId: string,
+  message: Json
+): ReadonlyArray => {
+  if (!isObject(message) || isGroupMessage(message)) return []
+  const id = string(message, "id")
+  const contacts = array(value.contacts).filter(isObject)
+  const from = string(message, "from")
+  const fromUserId = string(message, "from_user_id")
+  const contact =
+    contacts.find((contact) =>
+      (fromUserId !== undefined && contact.user_id === fromUserId) || (from !== undefined && contact.wa_id === from)
+    ) ?? contacts[0]
+  const user = fromUserId ?? string(contact, "user_id") ?? from
+  if (id === undefined || user === undefined || !Address.isUser(user)) return []
+  const thread = Address.thread({ phoneNumberId, kind: "user", id: user })
+  const raw: Json = { metadata, contacts: contact === undefined ? [] : [contact], messages: [message] }
+  const at = timestamp(string(message, "timestamp"))
+  const type = string(message, "type")
+  switch (type) {
+    case "system": {
+      const system = object(message, "system")
+      const change = string(system, "type")
+      if (change !== "user_changed_number" && change !== "user_changed_user_id") return []
+      const next = string(system, "user_id") ?? string(system, "wa_id")
+      if (next === undefined || !Address.isUser(next)) return []
+      const userId = string(system, "user_id")
+      const previousUserId = string(system, "previous_user_id")
+      const phone = string(system, "wa_id")
+      return [{
+        _tag: "UserIdChanged",
+        thread: Address.thread({ phoneNumberId, kind: "user", id: next }),
+        id,
+        change,
+        ...(userId === undefined ? {} : { userId }),
+        ...(previousUserId === undefined ? {} : { previousUserId }),
+        ...(phone === undefined ? {} : { phone }),
+        ...(from === undefined ? {} : { previousPhone: from }),
+        ...(at === undefined ? {} : { timestamp: at }),
+        raw
+      }]
+    }
+    case "reaction": {
+      const reaction = object(message, "reaction")
+      const emoji = string(reaction, "emoji")
+      const messageId = string(reaction, "message_id")
+      // An empty emoji is a removed reaction, which is dropped.
+      if (emoji === undefined || messageId === undefined) return []
+      return [{
+        _tag: "ReactionAdded",
+        thread,
+        messageId,
+        userId: user,
+        emoji,
+        ...(at === undefined ? {} : { timestamp: at }),
+        raw
+      }]
+    }
+    case "interactive": {
+      const interactive = object(message, "interactive")
+      const reply = object(interactive, "button_reply") ?? object(interactive, "list_reply")
+      const wire = string(reply, "id")
+      const parsed = wire === undefined ? undefined : parseWireId(wire)
+      const messageId = string(object(message, "context"), "id")
+      if (parsed === undefined || messageId === undefined) return []
+      const origin = { thread, messageId, userId: user, raw }
+      return parsed.kind === "select"
+        ? [{ _tag: "SelectChanged", id: parsed.id, value: parsed.value, ...origin }]
+        : [{
+          _tag: "ButtonClicked",
+          id: parsed.id,
+          ...(parsed.value === undefined ? {} : { value: parsed.value }),
+          ...origin
+        }]
+    }
+    case "unsupported":
+    case "request_welcome":
+      return []
+  }
+  const attachments: Array = []
+  let text = string(object(message, "text"), "body") ?? string(object(message, "button"), "text") ?? ""
+  for (const kind of media) {
+    const item = object(message, kind)
+    const mediaId = string(item, "id")
+    if (mediaId === undefined) continue
+    const name = string(item, "filename")
+    const contentType = string(item, "mime_type")
+    attachments.push({
+      id: mediaId,
+      ...(name === undefined ? {} : { name }),
+      ...(contentType === undefined ? {} : { contentType })
+    })
+    text = string(item, "caption") ?? text
+  }
+  const context = object(message, "context")
+  const replyId = string(context, "id")
+  const quoted = string(context, "from")
+  const name = string(object(contact, "profile"), "name")
+  const chatMessage: ChatMessage = {
+    id,
+    thread,
+    author: { id: user, ...(name === undefined ? {} : { name }), isBot: false, isSelf: false },
+    text,
+    mentions: [],
+    ...(replyId === undefined ? {} : {
+      replyTo: {
+        messageId: replyId,
+        ...(quoted === undefined
+          ? {}
+          : { isSelf: digits(quoted) === digits(string(metadata, "display_phone_number") ?? "") })
+      }
+    }),
+    attachments,
+    timestamp: at ?? DateTime.makeUnsafe(0),
+    raw: message
+  }
+  return [{ _tag: "MessageCreated", thread, kind: "direct", message: chatMessage, raw }]
+}
+
+const statuses = new Set(["sent", "delivered", "read", "failed"])
+
+const fromStatus = (metadata: JsonObject, phoneNumberId: string, status: Json): ReadonlyArray => {
+  if (!isObject(status) || status.recipient_type === "group") return []
+  const messageId = string(status, "id")
+  const value = string(status, "status")
+  const phone = string(status, "recipient_id")
+  const userId = string(status, "recipient_user_id")
+  const user = userId ?? phone
+  if (messageId === undefined || value === undefined || !statuses.has(value) || user === undefined) return []
+  if (!Address.isUser(user)) return []
+  const thread: ChatThread = Address.thread({ phoneNumberId, kind: "user", id: user })
+  const raw: Json = { metadata, statuses: [status] }
+  const at = timestamp(string(status, "timestamp"))
+  const error = array(status.errors).find(isObject)
+  const code = error?.code
+  const out: Array = [{
+    _tag: "Status",
+    thread,
+    messageId,
+    status: value as Update.Status["status"],
+    ...(at === undefined ? {} : { timestamp: at }),
+    ...(value === "failed" && typeof code === "number"
+      ? { reason: reasonForGraphError({ code }, { write: false, cause: error }) }
+      : {}),
+    ...(phone === undefined ? {} : { phone }),
+    ...(userId === undefined ? {} : { userId }),
+    raw
+  }]
+  if (value !== "failed" && phone !== undefined && userId !== undefined) {
+    out.push({ _tag: "Alias", thread, phone, userId, messageId, status: value as Update.Alias["status"], raw })
+  }
+  return out
+}
+
+/** @internal */
+export const normalize = (envelope: unknown, context: { readonly phoneNumberId: string }): ReadonlyArray => {
+  const out: Array = []
+  if (!isObject(envelope) || envelope.object !== "whatsapp_business_account") return out
+  for (const entry of array(envelope.entry)) {
+    for (const change of array(isObject(entry) ? entry.changes : undefined)) {
+      if (!isObject(change) || change.field !== "messages") continue
+      const value = object(change, "value")
+      const metadata = object(value, "metadata")
+      if (
+        value === undefined || metadata === undefined || string(metadata, "phone_number_id") !== context.phoneNumberId
+      ) {
+        continue
+      }
+      for (const message of array(value.messages)) {
+        out.push(...fromMessage(value, metadata, context.phoneNumberId, message))
+      }
+      for (const status of array(value.statuses)) out.push(...fromStatus(metadata, context.phoneNumberId, status))
+    }
+  }
+  return out
+}
diff --git a/packages/chat/whatsapp/src/internal/options.ts b/packages/chat/whatsapp/src/internal/options.ts
new file mode 100644
index 00000000000..593117ec5c7
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/options.ts
@@ -0,0 +1,19 @@
+import * as Context from "effect/Context"
+
+/** @internal */
+export interface PostOptions {
+  readonly linkPreview?: boolean | undefined
+  readonly listButton?: string | undefined
+  readonly buttonsSection?: string | undefined
+}
+
+/** @internal */
+export const CurrentPostOptions = Context.Reference("@effect/chat-whatsapp/CurrentPostOptions", {
+  defaultValue: () => ({})
+})
+
+/** @internal */
+export const defaultListButton = "Options"
+
+/** @internal */
+export const defaultButtonsSection = "Actions"
diff --git a/packages/chat/whatsapp/src/internal/text.ts b/packages/chat/whatsapp/src/internal/text.ts
new file mode 100644
index 00000000000..60b13ca500e
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/text.ts
@@ -0,0 +1,400 @@
+/**
+ * Markdown to WhatsApp text.
+ *
+ * Each construct the renderer knows has a candidate replacement, rendered
+ * bottom-up, which is emitted only when it is no longer than the
+ * construct's source in code points, UTF-16 units and UTF-8 bytes. Otherwise
+ * the source is emitted as it is. Text between constructs is always kept, so
+ * the output is never longer than the input in any of the three units.
+ */
+
+/** The longest text message, and the measure's unit: UTF-16 code units. @internal */
+export const messageLength = 4096
+
+/** The longest caption, and the longest body beside reply buttons or a link button. @internal */
+export const shortBodyLength = 1024
+
+/** @internal */
+export const measure = (markdown: string): number => markdown.length
+
+const codePoints = (s: string): number => {
+  let n = 0
+  for (const _ of s) n++
+  return n
+}
+
+const utf8Bytes = (s: string): number => {
+  let n = 0
+  for (const char of s) {
+    const code = char.codePointAt(0)!
+    n += code < 0x80 ? 1 : code < 0x800 ? 2 : code < 0x10000 ? 3 : 4
+  }
+  return n
+}
+
+/** Whether `candidate` is no longer than `source` in all three units. @internal */
+export const fits = (candidate: string, source: string): boolean =>
+  candidate.length <= source.length && codePoints(candidate) <= codePoints(source) &&
+  utf8Bytes(candidate) <= utf8Bytes(source)
+
+const pick = (candidate: string, source: string): string => fits(candidate, source) ? candidate : source
+
+/** The characters WhatsApp formats with, which a decoded reference must not produce. */
+const formatting = new Set(["*", "_", "~", "`"])
+
+const entities: Record = {
+  amp: "&",
+  lt: "<",
+  gt: ">",
+  quot: "\"",
+  apos: "'",
+  nbsp: " ",
+  copy: "©",
+  reg: "®",
+  trade: "™",
+  hellip: "…",
+  mdash: "—",
+  ndash: "–",
+  lsquo: "‘",
+  rsquo: "’",
+  ldquo: "“",
+  rdquo: "”",
+  laquo: "«",
+  raquo: "»",
+  bull: "•",
+  middot: "·",
+  deg: "°",
+  plusmn: "±",
+  times: "×",
+  divide: "÷",
+  minus: "−",
+  euro: "€",
+  pound: "£",
+  yen: "¥",
+  cent: "¢",
+  sect: "§",
+  para: "¶",
+  larr: "←",
+  rarr: "→",
+  uarr: "↑",
+  darr: "↓",
+  harr: "↔",
+  lArr: "⇐",
+  rArr: "⇒",
+  hArr: "⇔",
+  le: "≤",
+  ge: "≥",
+  ne: "≠",
+  asymp: "≈",
+  infin: "∞",
+  frac12: "½",
+  frac14: "¼",
+  frac34: "¾",
+  iexcl: "¡",
+  iquest: "¿"
+}
+
+const decodeReference = (reference: string): string | undefined => {
+  const body = reference.slice(1, -1)
+  let decoded: string | undefined
+  if (body.startsWith("#")) {
+    const code = body[1] === "x" || body[1] === "X"
+      ? Number.parseInt(body.slice(2), 16)
+      : Number.parseInt(body.slice(1), 10)
+    decoded = code === 0 || code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff) ? "�" : String.fromCodePoint(code)
+  } else {
+    decoded = Object.hasOwn(entities, body) ? entities[body] : undefined
+  }
+  return decoded === undefined || formatting.has(decoded) ? undefined : decoded
+}
+
+const isWhitespace = (char: string | undefined) => char === undefined || /\s/u.test(char)
+const isPunctuation = (char: string | undefined) => char !== undefined && /[\p{P}\p{S}]/u.test(char)
+const isAsciiPunctuation = (char: string | undefined) => char !== undefined && /[!-/:-@[-`{-~]/.test(char)
+
+interface Atom {
+  readonly end: number
+  readonly text: string
+}
+
+const runLength = (s: string, i: number, char: string) => {
+  let j = i
+  while (s[j] === char) j++
+  return j - i
+}
+
+/** A code span from the backtick run at `i`, or the run itself when it has no match. */
+const codeSpan = (s: string, i: number): Atom => {
+  const n = runLength(s, i, "`")
+  let j = i + n
+  while (j < s.length) {
+    if (s[j] !== "`") {
+      j++
+      continue
+    }
+    const m = runLength(s, j, "`")
+    if (m === n) return { end: j + m, text: s.slice(i, j + m) }
+    j += m
+  }
+  return { end: i + n, text: s.slice(i, i + n) }
+}
+
+const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}:[^\s<>]*)>/
+const emailAutolink =
+  /^<([A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*)>/
+const html = /^(?:|<\/?[A-Za-z][A-Za-z0-9-]*(?:\s[^<>]*)?\/?>)/
+const reference = /^&(?:#[0-9]{1,7};|#[xX][0-9A-Fa-f]{1,6};|[A-Za-z][A-Za-z0-9]{1,31};)/
+
+/** The index of the `]` closing the `[` at `i`, skipping escapes and code spans. */
+const closeBracket = (s: string, i: number): number => {
+  let depth = 0
+  let j = i
+  while (j < s.length) {
+    const char = s[j]
+    if (char === "\\") j += 2
+    else if (char === "`") j = codeSpan(s, j).end
+    else {
+      if (char === "[") depth++
+      else if (char === "]" && --depth === 0) return j
+      j++
+    }
+  }
+  return -1
+}
+
+/** An inline destination and optional title from the `(` at `i`: the URL and the index after `)`. */
+const destination = (s: string, i: number): { readonly url: string; readonly end: number } | undefined => {
+  let j = i + 1
+  while (s[j] === " " || s[j] === "\t") j++
+  let url: string
+  if (s[j] === "<") {
+    const close = s.indexOf(">", j)
+    if (close < 0 || s.slice(j + 1, close).includes("<")) return undefined
+    url = s.slice(j + 1, close)
+    j = close + 1
+  } else {
+    const start = j
+    let depth = 0
+    while (j < s.length && !/\s/.test(s[j])) {
+      if (s[j] === "\\" && isAsciiPunctuation(s[j + 1])) j++
+      else if (s[j] === "(") depth++
+      else if (s[j] === ")") {
+        if (depth === 0) break
+        depth--
+      }
+      j++
+    }
+    if (depth !== 0) return undefined
+    url = s.slice(start, j)
+  }
+  const afterUrl = j
+  while (s[j] === " " || s[j] === "\t") j++
+  if (j > afterUrl && (s[j] === "\"" || s[j] === "'" || s[j] === "(")) {
+    const close = s[j] === "(" ? ")" : s[j]
+    let k = j + 1
+    while (k < s.length && s[k] !== close) k += s[k] === "\\" ? 2 : 1
+    if (k >= s.length) return undefined
+    j = k + 1
+    while (s[j] === " " || s[j] === "\t") j++
+  }
+  return s[j] === ")" ? { url, end: j + 1 } : undefined
+}
+
+/** A link or image from the `[` at `i`, `start` being the `!` of an image. */
+const link = (s: string, start: number, i: number): Atom | undefined => {
+  if (s[i + 1] === "^") {
+    const close = s.indexOf("]", i)
+    return close < 0 ? undefined : { end: close + 1, text: s.slice(start, close + 1) }
+  }
+  const close = closeBracket(s, i)
+  if (close < 0) return undefined
+  if (s[close + 1] === "[") {
+    const end = s.indexOf("]", close + 1)
+    return end < 0 ? undefined : { end: end + 1, text: s.slice(start, end + 1) }
+  }
+  if (s[close + 1] !== "(") return undefined
+  const target = destination(s, close + 1)
+  if (target === undefined) return undefined
+  const label = s.slice(i + 1, close)
+  const shown = start < i ? label : inline(label)
+  const candidate = label === "" || label === target.url ? target.url : shown + " (" + target.url + ")"
+  return { end: target.end, text: pick(candidate, s.slice(start, target.end)) }
+}
+
+/** The construct at `i` that is kept or replaced as a whole, if any. */
+const atom = (s: string, i: number): Atom | undefined => {
+  switch (s[i]) {
+    case "\\":
+      return isAsciiPunctuation(s[i + 1]) ? { end: i + 2, text: s.slice(i, i + 2) } : undefined
+    case "`":
+      return codeSpan(s, i)
+    case "<": {
+      const rest = s.slice(i)
+      const match = autolink.exec(rest) ?? emailAutolink.exec(rest)
+      if (match !== null) return { end: i + match[0].length, text: pick(match[1], match[0]) }
+      const tag = html.exec(rest)
+      return tag === null ? undefined : { end: i + tag[0].length, text: tag[0] }
+    }
+    case "!":
+      return s[i + 1] === "[" ? link(s, i, i + 1) : undefined
+    case "[":
+      return link(s, i, i)
+    case "&": {
+      const match = reference.exec(s.slice(i, i + 40))
+      if (match === null) return undefined
+      const decoded = decodeReference(match[0])
+      return { end: i + match[0].length, text: decoded === undefined ? match[0] : pick(decoded, match[0]) }
+    }
+  }
+  return undefined
+}
+
+const leftFlanking = (before: string | undefined, after: string | undefined) =>
+  !isWhitespace(after) && (!isPunctuation(after) || isWhitespace(before) || isPunctuation(before))
+
+const rightFlanking = (before: string | undefined, after: string | undefined) =>
+  !isWhitespace(before) && (!isPunctuation(before) || isWhitespace(after) || isPunctuation(after))
+
+const canOpen = (s: string, i: number, n: number) => {
+  const before = s[i - 1]
+  const after = s[i + n]
+  const left = leftFlanking(before, after)
+  return s[i] === "_" ? left && (!rightFlanking(before, after) || isPunctuation(before)) : left
+}
+
+const canClose = (s: string, i: number, n: number) => {
+  const before = s[i - 1]
+  const after = s[i + n]
+  const right = rightFlanking(before, after)
+  return s[i] === "_" ? right && (!leftFlanking(before, after) || isPunctuation(after)) : right
+}
+
+/** Emphasis or strikethrough from the delimiter run at `i`, if it has a closer. */
+const emphasis = (s: string, i: number): Atom | undefined => {
+  const char = s[i]
+  const n = runLength(s, i, char)
+  if (n > 2 || !canOpen(s, i, n)) return undefined
+  let j = i + n
+  while (j < s.length) {
+    const skipped = s[j] === "*" || s[j] === "_" || s[j] === "~" ? undefined : atom(s, j)
+    if (skipped !== undefined) {
+      j = skipped.end
+      continue
+    }
+    if (s[j] !== char) {
+      j++
+      continue
+    }
+    const m = runLength(s, j, char)
+    if (m === n && j > i + n && canClose(s, j, m)) {
+      const marker = char === "~" ? "~" : n === 2 ? "*" : "_"
+      const candidate = marker + inline(s.slice(i + n, j)) + marker
+      return { end: j + m, text: pick(candidate, s.slice(i, j + m)) }
+    }
+    j += m
+  }
+  return undefined
+}
+
+/** One line of inline Markdown. @internal */
+export const inline = (s: string): string => {
+  let out = ""
+  let i = 0
+  while (i < s.length) {
+    const char = s[i]
+    const found = char === "*" || char === "_" || char === "~" ? emphasis(s, i) : atom(s, i)
+    if (found !== undefined) {
+      out += found.text
+      i = found.end
+    } else if (char === "*" || char === "_" || char === "~") {
+      const n = runLength(s, i, char)
+      out += s.slice(i, i + n)
+      i += n
+    } else {
+      out += char
+      i++
+    }
+  }
+  return out
+}
+
+const fenceOpen = /^( {0,3})(`{3,}|~{3,})(.*)$/
+const atxHeading = /^ {0,3}(#{1,6})(?:[ \t]+(.*))?$/
+const setextUnderline = /^ {0,3}(?:=+|-+)[ \t]*$/
+const thematicBreak = /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/
+const definition = /^ {0,3}\[[^\]]+\]:/
+const blockStart = /^(?: {4}|\t| {0,3}(?:[>#|]|[-*+](?:[ \t]|$)|\d{1,9}[.)](?:[ \t]|$)|`{3}|~{3}))/
+const tableDelimiter = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/
+const containerPrefix = /^((?: {0,3}>[ \t]?)*)( {0,3}(?:[-*+]|\d{1,9}[.)])[ \t]+)?/
+
+const cells = (row: string) => row.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").length
+
+const isBlank = (line: string) => line.trim() === ""
+
+/**
+ * Markdown as WhatsApp text, never longer than the Markdown in code points,
+ * UTF-16 units or UTF-8 bytes.
+ *
+ * @internal
+ */
+export const render = (markdown: string): string => {
+  const lines = markdown.split(/(?<=\n)/)
+  const body = (k: number) => lines[k].replace(/\r?\n$/, "")
+  const eol = (k: number) => lines[k].slice(body(k).length)
+  let out = ""
+  let i = 0
+  while (i < lines.length) {
+    const line = body(i)
+    const fence = fenceOpen.exec(line)
+    if (fence !== null && !(fence[2][0] === "`" && fence[3].includes("`"))) {
+      const char = fence[2][0]
+      const closing = new RegExp("^ {0,3}" + (char === "~" ? "~" : "`") + "{" + fence[2].length + ",}[ \\t]*$")
+      let j = i + 1
+      while (j < lines.length && !closing.test(body(j))) j++
+      if (j >= lines.length) {
+        out += lines.slice(i).join("")
+        break
+      }
+      const content = lines.slice(i + 1, j).join("")
+      const source = lines.slice(i, j + 1).join("")
+      const candidate = "```" + eol(i) + content + "```" + eol(j)
+      out += content.includes("```") ? source : pick(candidate, source)
+      i = j + 1
+      continue
+    }
+    if (i + 1 < lines.length && line.includes("|") && tableDelimiter.test(body(i + 1)) && body(i + 1).includes("|")) {
+      if (cells(line) === cells(body(i + 1))) {
+        out += lines[i]
+        let j = i + 2
+        while (j < lines.length && !isBlank(body(j))) out += lines[j++]
+        i = j
+        continue
+      }
+    }
+    const heading = atxHeading.exec(line)
+    if (heading !== null) {
+      const content = (heading[2] ?? "").replace(/(?:^|[ \t]+)#+[ \t]*$/, "").trim()
+      out += (content === "" ? line : pick("*" + inline(content) + "*", line)) + eol(i)
+      i++
+      continue
+    }
+    if (
+      i + 1 < lines.length && !isBlank(line) && !blockStart.test(line) && !thematicBreak.test(line) &&
+      !definition.test(line) && (i === 0 || isBlank(body(i - 1))) && setextUnderline.test(body(i + 1))
+    ) {
+      const source = line + eol(i) + body(i + 1)
+      out += pick("*" + inline(line.trim()) + "*", source) + eol(i + 1)
+      i += 2
+      continue
+    }
+    if (/^(?: {4}|\t)/.test(line) || thematicBreak.test(line) || definition.test(line)) {
+      out += lines[i]
+      i++
+      continue
+    }
+    const prefix = containerPrefix.exec(line)![0]
+    out += prefix + inline(line.slice(prefix.length)) + eol(i)
+    i++
+  }
+  return out
+}
diff --git a/packages/chat/whatsapp/src/internal/webhook.ts b/packages/chat/whatsapp/src/internal/webhook.ts
new file mode 100644
index 00000000000..7c14dff9007
--- /dev/null
+++ b/packages/chat/whatsapp/src/internal/webhook.ts
@@ -0,0 +1,207 @@
+import { Unsupported } from "effect/chat/ChatError"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import type { NotAccepted } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as Clock from "effect/Clock"
+import * as Mac from "effect/crypto/Mac"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import type * as HttpServerRequest from "effect/http/HttpServerRequest"
+import * as HttpServerResponse from "effect/http/HttpServerResponse"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+import * as Stream from "effect/Stream"
+import type { WhatsAppUpdate } from "../WhatsAppUpdate.ts"
+import { chatError } from "./errors.ts"
+import { groupMessages, type Inbound } from "./normalize.ts"
+
+const encoder = new TextEncoder()
+
+/**
+ * Checks Meta's `X-Hub-Signature-256`: `sha256=` and the hex HMAC-SHA256
+ * of the raw body with the app secret.
+ *
+ * @internal
+ */
+export const makeVerifier = Effect.fnUntraced(function*(appSecret: Redacted.Redacted) {
+  const mac = yield* Mac.Mac
+  // An invalid app secret is a configuration defect, not a route error.
+  const key = yield* Mac.key(Mac.hmacSha256, encoder.encode(Redacted.value(appSecret))).pipe(Effect.orDie)
+  return (headers: { readonly [key: string]: string | undefined }, body: Uint8Array): Effect.Effect => {
+    const signature = headers["x-hub-signature-256"]
+    if (signature === undefined || !/^sha256=(?:[0-9a-fA-F]{2})+$/.test(signature)) return Effect.succeed(false)
+    const hex = signature.slice(7)
+    const tag = new Uint8Array(hex.length / 2)
+    for (let i = 0; i < tag.length; i++) tag[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16)
+    // Crypto failures fail closed, like a mismatched signature.
+    return mac.verify(key, tag, body).pipe(Effect.catch(() => Effect.succeed(false)))
+  }
+})
+
+/** The body, or `None` once it passes `maxBytes`. @internal */
+export const readBody = (
+  request: HttpServerRequest.HttpServerRequest,
+  maxBytes: number
+): Effect.Effect> => {
+  const length = request.headers["content-length"]
+  if (length !== undefined && Number(length) > maxBytes) return Effect.succeed(Option.none())
+  return Effect.gen(function*() {
+    const chunks: Array = []
+    let total = 0
+    const failed = yield* request.stream.pipe(
+      Stream.takeUntil((chunk) => {
+        total += chunk.length
+        chunks.push(chunk)
+        return total > maxBytes
+      }),
+      Stream.runDrain,
+      Effect.as(false),
+      Effect.catch(() => Effect.succeed(true))
+    )
+    if (failed || total > maxBytes) return Option.none()
+    const body = new Uint8Array(total)
+    let offset = 0
+    for (const chunk of chunks) {
+      body.set(chunk, offset)
+      offset += chunk.length
+    }
+    return Option.some(body)
+  })
+}
+
+const ok = HttpServerResponse.empty({ status: 200 })
+const status = (code: number) => HttpServerResponse.empty({ status: code })
+
+/** What is logged with each 503, and with a dropped delivery. @internal */
+export const logged = {
+  notAccepted: "whatsapp webhook: an update was refused, answered 503",
+  deadline: "whatsapp webhook: the request passed its deadline, answered 503",
+  noHandler: "whatsapp webhook: a click arrived with no ChatInteraction.Handler, dropped",
+  group: "whatsapp webhook: group messages are not supported, dropped"
+} as const
+
+/**
+ * Meta's subscription check: `hub.mode=subscribe` with the verify token is
+ * answered with `hub.challenge`, anything else 403.
+ *
+ * @internal
+ */
+export const handleVerification = (
+  request: HttpServerRequest.HttpServerRequest,
+  verifyToken: Redacted.Redacted
+): HttpServerResponse.HttpServerResponse => {
+  const params = new URL(request.url, "http://localhost").searchParams
+  const challenge = params.get("hub.challenge")
+  return params.get("hub.mode") === "subscribe" && params.get("hub.verify_token") === Redacted.value(verifyToken) &&
+      challenge !== null
+    ? HttpServerResponse.text(challenge)
+    : status(403)
+}
+
+/** @internal */
+export interface ReceiveOptions {
+  readonly handle: (event: ChatEvent.ChatEvent) => Effect.Effect
+  readonly onUpdate?: ((update: WhatsAppUpdate) => Effect.Effect) | undefined
+  /** How long the click about to run may take. */
+  readonly clickDeadline: Effect.Effect
+}
+
+/**
+ * Runs one delivery's updates in order. A `NotAccepted` stops the rest.
+ * A click never fails: `Ack` and `Late` count as handled, and
+ * `OpenModal` is refused with `Unsupported("modals")`.
+ *
+ * @internal
+ */
+export const receive = (
+  items: ReadonlyArray,
+  options: ReceiveOptions
+): Effect.Effect =>
+  Effect.forEach(items, (item): Effect.Effect => {
+    switch (item._tag) {
+      case "MessageCreated":
+      case "ReactionAdded":
+        return options.handle(item)
+      case "Status":
+      case "UserIdChanged":
+      case "Alias":
+        return options.onUpdate === undefined ? Effect.void : options.onUpdate(item)
+      case "ButtonClicked":
+      case "SelectChanged":
+        return Effect.flatMap(Effect.serviceOption(ChatInteraction.Handler), (handler) => {
+          if (Option.isNone(handler)) return Effect.logWarning(logged.noHandler)
+          return options.clickDeadline.pipe(
+            Effect.flatMap((deadline) => ChatInteraction.handle(item, deadline)),
+            Effect.provideService(ChatInteraction.Handler, handler.value),
+            Effect.flatMap((reply) =>
+              reply._tag === "OpenModal"
+                ? handler.value.refused(item, chatError("openModal", new Unsupported({ capability: "modals" })))
+                : Effect.void
+            )
+          )
+        })
+    }
+  }, { discard: true })
+
+/** @internal */
+export interface Options {
+  readonly verify: (headers: { readonly [key: string]: string | undefined }, body: Uint8Array) => Effect.Effect
+  readonly normalize: (envelope: unknown) => ReadonlyArray
+  readonly handle: ReceiveOptions["handle"]
+  readonly onUpdate?: ReceiveOptions["onUpdate"]
+  readonly deadline: Duration.Duration
+  readonly maxBodyBytes: number
+}
+
+/** What a click leaves of the deadline for the rest of the request. */
+const clickMargin = 250
+
+/**
+ * One webhook POST.
+ *
+ * - 413 past the body limit, 401 for a bad signature, 400 for a body that
+ *   is not a JSON object. Another `object` than
+ *   `whatsapp_business_account` is answered 200 and dropped.
+ * - 503 when an update fails `NotAccepted`, or the whole request takes
+ *   longer than the deadline. Meta then delivers the batch again.
+ * - A click gets what is left of the deadline, less a margin, so a slow
+ *   click handler is detached rather than passing the deadline.
+ *
+ * @internal
+ */
+export const handleRequest = (
+  request: HttpServerRequest.HttpServerRequest,
+  options: Options
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const until = (yield* Clock.currentTimeMillis) + Duration.toMillis(options.deadline)
+    const body = yield* readBody(request, options.maxBodyBytes)
+    if (Option.isNone(body)) return status(413)
+    if (!(yield* options.verify(request.headers, body.value))) return status(401)
+    let envelope: unknown
+    try {
+      envelope = JSON.parse(new TextDecoder().decode(body.value))
+    } catch {
+      return status(400)
+    }
+    if (typeof envelope !== "object" || envelope === null || Array.isArray(envelope)) return status(400)
+    if ((envelope as { readonly object?: unknown }).object !== "whatsapp_business_account") return ok
+    if (groupMessages(envelope) > 0) yield* Effect.logDebug(logged.group)
+    return yield* receive(options.normalize(envelope), {
+      handle: options.handle,
+      onUpdate: options.onUpdate,
+      clickDeadline: Effect.map(
+        Clock.currentTimeMillis,
+        (now) => Duration.millis(Math.max(0, until - now - clickMargin))
+      )
+    }).pipe(
+      Effect.as(ok),
+      Effect.catchTag("NotAccepted", () => Effect.as(Effect.logWarning(logged.notAccepted), status(503)))
+    )
+  }).pipe(
+    Effect.timeoutOption(options.deadline),
+    Effect.flatMap(Option.match({
+      onNone: () => Effect.as(Effect.logWarning(logged.deadline), status(503)),
+      onSome: Effect.succeed
+    }))
+  )
diff --git a/packages/chat/whatsapp/test/WhatsAppChat.test.ts b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
new file mode 100644
index 00000000000..26fa9aa263d
--- /dev/null
+++ b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
@@ -0,0 +1,338 @@
+import { handleRequest, handleVerification, makeVerifier } from "@effect/chat-whatsapp/internal/webhook"
+import * as WhatsAppChat from "@effect/chat-whatsapp/WhatsAppChat"
+import type { WhatsAppUpdate } from "@effect/chat-whatsapp/WhatsAppUpdate"
+import * as NodeCrypto from "@effect/platform-node/NodeCrypto"
+import { assert, describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
+import type { File } from "effect/chat/ChatAdapter"
+import type { ChatError } from "effect/chat/ChatError"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { NotAccepted } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type { Action } from "effect/chat/ChatUi"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as HttpServerRequest from "effect/http/HttpServerRequest"
+import * as Redacted from "effect/Redacted"
+import {
+  bsuid,
+  graphError,
+  inbound,
+  makeGraph,
+  phone,
+  phoneNumberId,
+  statuses,
+  thread,
+  whatsappLayer
+} from "./utils.ts"
+
+const post = (
+  content: {
+    readonly markdown: string
+    readonly actions?: ReadonlyArray
+    readonly files?: ReadonlyArray
+  },
+  to = thread
+) => Effect.flatMap(Chat.Chat, (chat) => chat.post(to, content))
+
+const run = (graph: ReturnType, effect: Effect.Effect) =>
+  effect.pipe(Effect.provide(whatsappLayer(graph)))
+
+const failure = (graph: ReturnType, effect: Effect.Effect) =>
+  run(graph, Effect.flip(effect)).pipe(Effect.map((error) => error.reason))
+
+const file = (name: string, contentType: string, size = 8): File => ({
+  name,
+  contentType,
+  content: new Uint8Array(size)
+})
+
+const button = (id: string, label: string, value?: string): Action => ({
+  _tag: "Button",
+  id,
+  label,
+  ...(value === undefined ? {} : { value })
+})
+
+describe("post", () => {
+  it.effect("sends rendered text to a BSUID as recipient and a phone number as to, without a preview", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      yield* run(graph, post({ markdown: "**hi** [docs](https://e.com)" }))
+      yield* run(graph, post({ markdown: "hi" }, WhatsAppChat.thread({ phoneNumberId, user: phone })))
+      const [first, second] = graph.sent()
+      assert.deepStrictEqual(first, {
+        messaging_product: "whatsapp",
+        recipient_type: "individual",
+        recipient: bsuid,
+        type: "text",
+        text: { body: "*hi* docs (https://e.com)", preview_url: false }
+      })
+      assert.strictEqual(second.to, phone)
+    }))
+
+  it.effect("lays out reply buttons, a link button, a list and appended links", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      yield* run(graph, post({ markdown: "", actions: [button("a", "Yes"), button("b", "No", "v")] }))
+      yield* run(graph, post({ markdown: "x", actions: [{ _tag: "LinkButton", label: "Docs", url: "https://e.com" }] }))
+      yield* run(
+        graph,
+        post({
+          markdown: "x",
+          actions: [
+            button("a", "Yes"),
+            { _tag: "Select", id: "env", placeholder: "Environment", options: [{ label: "Prod", value: "p" }] },
+            { _tag: "LinkButton", label: "Docs", url: "https://e.com" }
+          ]
+        })
+      )
+      const [reply, cta, list] = graph.sent().map((body) => body.interactive)
+      assert.deepStrictEqual(reply, {
+        type: "button",
+        body: { text: "Yes, No" },
+        action: {
+          buttons: [
+            { type: "reply", reply: { id: "ba", title: "Yes" } },
+            { type: "reply", reply: { id: "bb\u241Fv", title: "No" } }
+          ]
+        }
+      })
+      assert.deepStrictEqual(cta.action, {
+        name: "cta_url",
+        parameters: { display_text: "Docs", url: "https://e.com" }
+      })
+      assert.deepStrictEqual(list, {
+        type: "list",
+        body: { text: "x\n\nDocs: https://e.com" },
+        action: {
+          button: "Environment",
+          sections: [
+            { title: "Actions", rows: [{ id: "ba", title: "Yes" }] },
+            { title: "Environment", rows: [{ id: "senv\u241Fp", title: "Prod" }] }
+          ]
+        }
+      })
+    }))
+
+  it.effect("measures a short body layout, its link lines and its generated body", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      const descriptor = yield* run(graph, Effect.flatMap(Chat.Chat, (chat) => chat.descriptor("whatsapp")))
+      assert.strictEqual(descriptor.measure("ab", [button("a", "Yes")]), 2 + 3072 + 3)
+      const link: Action = { _tag: "LinkButton", label: "Docs", url: "u" }
+      assert.strictEqual(descriptor.measure("", [button("a", "Yes"), link]), 3072 + "Yes, Docs".length + 2 + 7)
+    }))
+
+  it.effect("refuses before any call", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      const rows = Array.from({ length: 6 }, (_, i) => button("b" + i, "b" + i))
+      const select: Action = {
+        _tag: "Select",
+        id: "s",
+        options: Array.from({ length: 5 }, (_, i) => ({ label: "o" + i, value: "o" + i }))
+      }
+      const refusals: ReadonlyArray, string, string]> = [
+        [post({ markdown: "x", actions: [...rows, select] }), "TooLarge", "list_rows"],
+        [post({ markdown: "x", actions: [button("a", "x".repeat(25))] }), "TooLarge", "label_too_long"],
+        [
+          post({ markdown: "x", actions: [button("a", "Same"), button("b", "Same")] }),
+          "InvalidRequest",
+          "duplicate_label"
+        ],
+        [post({ markdown: "x", actions: [button("a\u241F", "A")] }), "InvalidRequest", "invalid_action_id"],
+        [
+          post({ markdown: "x" }, { platform: "whatsapp", id: phoneNumberId + "/u/not-a-user" }),
+          "InvalidRequest",
+          "invalid_thread"
+        ],
+        [
+          post({ markdown: "x" }, { platform: "whatsapp", id: phoneNumberId + "/g/120363" }),
+          "InvalidRequest",
+          "group_unsupported"
+        ],
+        [
+          post({ markdown: "x", files: [file("a.txt", "text/plain"), file("b.txt", "text/plain")] }),
+          "TooLarge",
+          "file_refused"
+        ],
+        [post({ markdown: "x", files: [file("a.webp", "image/webp")] }), "TooLarge", "file_refused"],
+        [post({ markdown: "x", files: [file("a.png", "image/png", 5 * 1024 * 1024 + 1)] }), "TooLarge", "file_refused"],
+        [post({ markdown: "x", files: [file("a.ogg", "audio/ogg")] }), "TooLarge", "file_refused"],
+        [post({ markdown: "x".repeat(1025), files: [file("a.txt", "text/plain")] }), "TooLarge", "file_refused"],
+        [
+          post({ markdown: "x", actions: rows.slice(0, 4), files: [file("a.txt", "text/plain")] }),
+          "TooLarge",
+          "file_refused"
+        ]
+      ]
+      for (const [effect, tag, detail] of refusals) {
+        const reason = yield* failure(graph, effect)
+        assert.deepStrictEqual([reason._tag, reason.detail], [tag, detail])
+      }
+      assert.deepStrictEqual(graph.calls, [])
+    }))
+
+  it.effect("uploads a file as the header of reply buttons, and Markdown as text/plain", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      yield* run(
+        graph,
+        post({ markdown: "notes", actions: [button("a", "Ok")], files: [file("a.md", "text/markdown")] })
+      )
+      const [upload, send] = graph.calls
+      assert.strictEqual(upload.body.type, "text/plain")
+      assert.strictEqual(upload.body.file.name, "a.md")
+      assert.deepStrictEqual(send.body.interactive.header, {
+        type: "document",
+        document: { id: "media-1", filename: "a.md" }
+      })
+    }))
+
+  it.effect("maps 131047 to Forbidden outside the window", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      graph.next.set(phoneNumberId + "/messages", graphError(131047))
+      const reason = yield* failure(graph, post({ markdown: "x" }))
+      assert.deepStrictEqual([reason._tag, reason.detail], ["Forbidden", WhatsAppChat.outsideWindow])
+    }))
+})
+
+const secret = "app-secret"
+
+const sign = async (body: string) => {
+  const key = await crypto.subtle.importKey(
+    "raw",
+    new TextEncoder().encode(secret),
+    { name: "HMAC", hash: "SHA-256" },
+    false,
+    ["sign"]
+  )
+  const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(body)))
+  return "sha256=" + Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("")
+}
+
+const deliver = Effect.fnUntraced(function*(
+  envelope: unknown,
+  options?: {
+    readonly signature?: string
+    readonly refuse?: (event: ChatEvent.ChatEvent) => boolean
+    readonly onClick?: ChatInteraction.ClickReply
+  }
+) {
+  const body = JSON.stringify(envelope)
+  const signature = options?.signature ?? (yield* Effect.promise(() => sign(body)))
+  const verify = yield* makeVerifier(Redacted.make(secret)).pipe(Effect.provide(NodeCrypto.layerMac))
+  const seen: Array = []
+  const refused: Array = []
+  const response = yield* handleRequest(
+    HttpServerRequest.fromWeb(
+      new Request("http://localhost/whatsapp", { method: "POST", body, headers: { "x-hub-signature-256": signature } })
+    ),
+    {
+      verify,
+      normalize: (envelope) => WhatsAppChat.normalize(envelope, { phoneNumberId }),
+      handle: (event) =>
+        options?.refuse?.(event) === true
+          ? Effect.fail(new NotAccepted({}))
+          : Effect.sync(() => void seen.push(event._tag)),
+      onUpdate: (update: WhatsAppUpdate) => Effect.sync(() => void seen.push(update._tag)),
+      deadline: Duration.seconds(4),
+      maxBodyBytes: 1024 * 1024
+    }
+  ).pipe(Effect.provideService(
+    ChatInteraction.Handler,
+    ChatInteraction.Handler.of({
+      click: (event) => Effect.sync(() => (seen.push(event._tag), options?.onClick ?? ChatInteraction.ack)),
+      submit: () => Effect.succeed(ChatInteraction.close),
+      command: () => Effect.succeed(ChatInteraction.ack),
+      refused: (_, error) => Effect.sync(() => void refused.push(error))
+    })
+  ))
+  return { status: response.status, seen, refused }
+})
+
+describe("webhook", () => {
+  const text = inbound({ type: "text", text: { body: "hi" } })
+
+  it.effect("checks the signature and answers Meta's subscription check", () =>
+    Effect.gen(function*() {
+      assert.strictEqual((yield* deliver(text, { signature: "sha256=00" })).status, 401)
+      assert.strictEqual((yield* deliver(text)).status, 200)
+      const check = (token: string) =>
+        handleVerification(
+          HttpServerRequest.fromWeb(
+            new Request(`http://localhost/whatsapp?hub.mode=subscribe&hub.verify_token=${token}&hub.challenge=42`)
+          ),
+          Redacted.make("verify")
+        ).status
+      assert.deepStrictEqual([check("verify"), check("other")], [200, 403])
+    }))
+
+  it.effect("runs updates in order, drops a removed reaction and stops at NotAccepted with a 503", () =>
+    Effect.gen(function*() {
+      const batch = inbound({ type: "text", text: { body: "hi" } })
+      const value = batch.entry[0].changes[0].value as any
+      value.messages.push(
+        { ...value.messages[0], id: "wamid.r1", type: "reaction", reaction: { message_id: "wamid.out1", emoji: "" } },
+        { ...value.messages[0], id: "wamid.r2", type: "reaction", reaction: { message_id: "wamid.out1", emoji: "👍" } }
+      )
+      value.statuses = [{
+        id: "wamid.out1",
+        status: "read",
+        timestamp: "1794600001",
+        recipient_id: phone,
+        recipient_user_id: bsuid
+      }]
+      const ok = yield* deliver(batch)
+      assert.deepStrictEqual([ok.status, ok.seen], [200, ["MessageCreated", "ReactionAdded", "Status", "Alias"]])
+      const refused = yield* deliver(batch, { refuse: (event) => event._tag === "MessageCreated" })
+      assert.deepStrictEqual([refused.status, refused.seen], [503, []])
+    }))
+
+  it.effect("hands a click to the handler and refuses a modal as Unsupported", () =>
+    Effect.gen(function*() {
+      const click = inbound({
+        type: "interactive",
+        context: { from: "15550783881", id: "wamid.out1" },
+        interactive: { type: "list_reply", list_reply: { id: "senv\u241Fp\u241Fq", title: "Prod" } }
+      })
+      const modal = ChatInteraction.modal("m", { title: "M", fields: {} }).open()
+      const result = yield* deliver(click, { onClick: modal })
+      assert.deepStrictEqual([result.status, result.seen], [200, ["SelectChanged"]])
+      assert.strictEqual(result.refused[0]?.reason._tag, "Unsupported")
+      const [event] = WhatsAppChat.normalize(click, { phoneNumberId })
+      assert.deepStrictEqual(event._tag === "SelectChanged" && [event.id, event.value, event.messageId], [
+        "env",
+        "p\u241Fq",
+        "wamid.out1"
+      ])
+    }))
+})
+
+describe("keys", () => {
+  it("keys a delivery by its webhook message, and an update by its parts", () => {
+    const click = inbound({
+      type: "interactive",
+      context: { id: "wamid.out1" },
+      interactive: { type: "button_reply", button_reply: { id: "ba", title: "A" } }
+    })
+    const [event] = WhatsAppChat.normalize(click, { phoneNumberId })
+    const id = (click.entry[0].changes[0].value.messages[0] as any).id
+    assert.strictEqual(event._tag === "ButtonClicked" && WhatsAppChat.deliveryKey(event), `${phoneNumberId}/${id}`)
+    const updates = WhatsAppChat.normalize(
+      statuses({ id: "wamid.a/b", status: "delivered", recipient_id: phone, recipient_user_id: bsuid }),
+      { phoneNumberId }
+    )
+    assert.deepStrictEqual(
+      updates.map((update) =>
+        update._tag === "Status" || update._tag === "Alias" ? WhatsAppChat.updateKey(update) : ""
+      ),
+      [
+        `${phoneNumberId}/status/wamid.a%2Fb/delivered`,
+        `${phoneNumberId}/alias/wamid.a%2Fb/delivered/${phone}/${bsuid}`
+      ]
+    )
+  })
+})
diff --git a/packages/chat/whatsapp/test/conformance.test.ts b/packages/chat/whatsapp/test/conformance.test.ts
new file mode 100644
index 00000000000..6976205ab61
--- /dev/null
+++ b/packages/chat/whatsapp/test/conformance.test.ts
@@ -0,0 +1,28 @@
+/**
+ * The conformance suite against the adapter over a fake Graph API that keeps
+ * what was sent. Clicks are built from the sent reply buttons and list rows
+ * and go through `WhatsAppChat.receive`.
+ */
+import * as WhatsAppChat from "@effect/chat-whatsapp/WhatsAppChat"
+import { describe, it } from "@effect/vitest"
+import { conformance } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import { makeGraph, makeInteractions, thread, userPosts, whatsappLayer } from "./utils.ts"
+
+const options = { platform: "whatsapp", thread, userPosts, parseMention: WhatsAppChat.parseMention }
+
+describe("conformance over a fake Graph API", () => {
+  const names = Object.keys(conformance({
+    ...options,
+    interactions: { click: () => Effect.void, submit: () => Effect.void }
+  }))
+
+  for (const name of names) {
+    it.effect(name, () => {
+      const graph = makeGraph()
+      const { bind, interactions } = makeInteractions(graph)
+      const rules = conformance({ ...options, interactions })
+      return Effect.andThen(bind, rules[name]).pipe(Effect.provide(whatsappLayer(graph)))
+    })
+  }
+})
diff --git a/packages/chat/whatsapp/test/text.test.ts b/packages/chat/whatsapp/test/text.test.ts
new file mode 100644
index 00000000000..8cd42be842b
--- /dev/null
+++ b/packages/chat/whatsapp/test/text.test.ts
@@ -0,0 +1,91 @@
+import { fits, render } from "@effect/chat-whatsapp/internal/text"
+import { assert, describe, it } from "@effect/vitest"
+import * as fc from "fast-check"
+
+const cases: ReadonlyArray = [
+  ["**b** and __b__", "*b* and *b*"],
+  ["*i* and _i_", "_i_ and _i_"],
+  ["~~s~~ and ~s~", "~s~ and ~s~"],
+  ["**a *b* c**", "*a _b_ c*"],
+  ["[label](https://e.com \"title\")", "label (https://e.com)"],
+  ["![alt](https://e.com/a.png)", "alt (https://e.com/a.png)"],
+  ["[](https://e.com)", "https://e.com"],
+  ["![](https://e.com)", "https://e.com"],
+  ["", "https://e.com"],
+  ["# Title #", "*Title*"],
+  ["Title\n===\n", "*Title*\n"],
+  ["#", "#"],
+  ["# ", "# "],
+  ["| a | b |\n|---|---|\n| 1 | 2 |", "| a | b |\n| 1 | 2 |"],
+  ["~~~ts\n**x**\n~~~\n", "```\n**x**\n```\n"],
+  ["& < é 😀", "& < \u00e9 \u{1F600}"],
+  ["≫⃒ ≪⃒ * *", "≫⃒ ≪⃒ * *"],
+  ["[a][r] and [r]\n\n[r]: https://e.com", "[a][r] and [r]\n\n[r]: https://e.com"],
+  ["`**x**` ``a`` \\*x\\* **x**", "`**x**` ``a`` \\*x\\* *x*"],
+  ["a_b_c and 2*3*4", "a_b_c and 2_3_4"],
+  ["    **indented**", "    **indented**"],
+  ["- **item**\n> **quote**", "- *item*\n> *quote*"]
+]
+
+const longer = (input: string) => {
+  const output = render(input)
+  return fits(output, input) ? undefined : output
+}
+
+describe("render", () => {
+  it("renders each construct", () => {
+    for (const [input, expected] of cases) assert.strictEqual(render(input), expected, input)
+  })
+
+  it("never grows Markdown, in code points, UTF-16 units or UTF-8 bytes", () => {
+    const token = fc.constantFrom(
+      "*",
+      "**",
+      "_",
+      "__",
+      "~",
+      "~~",
+      "`",
+      "```",
+      "#",
+      "# ",
+      "[",
+      "]",
+      "(",
+      ")",
+      "![",
+      "<",
+      ">",
+      "&",
+      ";",
+      "\\",
+      "|",
+      "|---|",
+      "-",
+      "=",
+      "\n",
+      " ",
+      "a",
+      "\u00e9",
+      "\u{1F600}",
+      "https://e.com",
+      "&",
+      "&#",
+      "≫⃒",
+      "~~~",
+      "x"
+    )
+    fc.assert(fc.property(fc.array(token, { maxLength: 40 }), (tokens) => longer(tokens.join("")) === undefined))
+  })
+
+  it("never grows a character reference", () => {
+    const numbers = [0, 1, 0x2a, 0x7f, 0x80, 0x7ff, 0x800, 0xd800, 0xffff, 0x10000, 0x10ffff, 0x110000]
+    const references = [
+      ...["amp", "lt", "nbsp", "hellip", "mdash", "frac34", "iquest", "nGt", "ast"].map((name) => "&" + name),
+      ...numbers.flatMap((n) => ["&#" + n, "&#x" + n.toString(16)])
+    ]
+    for (const reference of references) {
+      for (const input of [reference, reference + ";"]) assert.strictEqual(longer(input), undefined, input)
+    }
+  })
+})
diff --git a/packages/chat/whatsapp/test/utils.ts b/packages/chat/whatsapp/test/utils.ts
new file mode 100644
index 00000000000..630ab3d022b
--- /dev/null
+++ b/packages/chat/whatsapp/test/utils.ts
@@ -0,0 +1,195 @@
+import * as WhatsAppChat from "@effect/chat-whatsapp/WhatsAppChat"
+import * as Chat from "effect/chat/Chat"
+import type { ChatEvent } from "effect/chat/ChatEvent"
+import { ChatHandler } from "effect/chat/ChatHandler"
+import { type Interactions, NoSuchElement } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import * as HttpClient from "effect/http/HttpClient"
+import type * as HttpClientRequest from "effect/http/HttpClientRequest"
+import * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+
+export const phoneNumberId = "106540352242922"
+export const business = "15550783881"
+export const bsuid = "US.13491208655302741918"
+export const phone = "16505551234"
+export const thread = WhatsAppChat.thread({ phoneNumberId, user: bsuid })
+
+export interface FakeCall {
+  readonly method: string
+  readonly path: string
+  readonly body: any
+}
+
+/** An answer with a status, or a JSON body for a 200. */
+export type Answer = { readonly status: number; readonly body?: unknown } | Record
+
+/** A Graph error answer, as Meta sends it. */
+export const graphError = (code: number, status = 400, subcode?: number): Answer => ({
+  status,
+  body: { error: { message: "refused", type: "OAuthException", code, error_subcode: subcode, fbtrace_id: "A" } }
+})
+
+/**
+ * A Graph API that keeps the messages the adapter sends by id, and the media
+ * it uploads. `next` holds one-shot answers for a path.
+ */
+export const makeGraph = () => {
+  const calls: Array = []
+  const messages = new Map()
+  const media = new Map()
+  const next = new Map()
+  let count = 0
+
+  const answer = async (request: HttpClientRequest.HttpClientRequest, url: URL): Promise => {
+    const path = url.host === "lookaside.test" ? url.pathname : url.pathname.replace(/^\/v[\d.]+\//, "")
+    const raw = request.body
+    let body: any
+    if (raw._tag === "FormData") body = Object.fromEntries(raw.formData.entries())
+    else if (raw._tag === "Uint8Array") body = JSON.parse(new TextDecoder().decode(raw.body))
+    calls.push({ method: request.method, path, body })
+    const scripted = next.get(path)
+    if (scripted !== undefined) {
+      next.delete(path)
+      return scripted
+    }
+    if (url.host === "lookaside.test") return media.get(path.slice(1))!.bytes
+    if (path === `${phoneNumberId}/media`) {
+      const id = "media-" + ++count
+      media.set(id, { type: body.type, bytes: new Uint8Array(await (body.file as Blob).arrayBuffer()) })
+      return { id }
+    }
+    if (path === `${phoneNumberId}/messages`) {
+      if (body.status === "read") return { success: true }
+      const id = "wamid.out" + ++count
+      messages.set(id, body)
+      const to = body.to ?? body.recipient
+      return {
+        messaging_product: "whatsapp",
+        contacts: [{ input: to, ...(body.to === undefined ? { user_id: to } : { wa_id: to }) }],
+        messages: [{ id }]
+      }
+    }
+    const stored = media.get(path)
+    if (stored === undefined) return graphError(100, 400, 33)
+    return { url: `https://lookaside.test/${path}`, mime_type: stored.type, file_size: stored.bytes.length, id: path }
+  }
+
+  const client = HttpClient.make((request, url) =>
+    Effect.promise(async () => {
+      const result = await answer(request, url)
+      const web = result instanceof Uint8Array
+        ? new Response(result as Uint8Array, { status: 200 })
+        : "status" in result && typeof result.status === "number"
+        ? new Response(JSON.stringify(result.body ?? {}), { status: result.status })
+        : new Response(JSON.stringify(result), { status: 200, headers: { "content-type": "application/json" } })
+      return HttpClientResponse.fromWeb(request, web)
+    })
+  )
+
+  return {
+    calls,
+    messages,
+    media,
+    next,
+    sent: () => calls.filter((call) => call.path === `${phoneNumberId}/messages`).map((call) => call.body),
+    layer: Layer.succeed(HttpClient.HttpClient, client)
+  }
+}
+
+/** `Chat`, `Registry` and the WhatsApp adapter on a fake Graph API. */
+export const whatsappLayer = (graph: ReturnType) =>
+  WhatsAppChat.layer({ accessToken: Redacted.make("EAAG-test"), phoneNumberId }).pipe(
+    Layer.provideMerge(Chat.layer),
+    Layer.provide(graph.layer)
+  )
+
+let inboundCount = 0
+
+/** A webhook delivery with one message from the test user. */
+export const inbound = (message: Record, options?: { readonly phoneNumberId?: string }) => ({
+  object: "whatsapp_business_account",
+  entry: [{
+    id: "102290129340398",
+    changes: [{
+      field: "messages",
+      value: {
+        messaging_product: "whatsapp",
+        metadata: { display_phone_number: business, phone_number_id: options?.phoneNumberId ?? phoneNumberId },
+        contacts: [{ profile: { name: "Sheena Nelson" }, user_id: bsuid, wa_id: phone }],
+        messages: [{
+          from: phone,
+          from_user_id: bsuid,
+          id: "wamid.in" + ++inboundCount,
+          timestamp: "1794600000",
+          ...message
+        }]
+      }
+    }]
+  }]
+})
+
+/** A webhook delivery with statuses. */
+export const statuses = (...items: ReadonlyArray>) => ({
+  object: "whatsapp_business_account",
+  entry: [{
+    id: "102290129340398",
+    changes: [{
+      field: "messages",
+      value: {
+        messaging_product: "whatsapp",
+        metadata: { display_phone_number: business, phone_number_id: phoneNumberId },
+        statuses: items
+      }
+    }]
+  }]
+})
+
+const join = "\u241F"
+
+/** The user's text, as `ChatTest.conformance` wants it. */
+export const userPosts = (_thread: unknown, text: string): Effect.Effect =>
+  Effect.sync(() =>
+    WhatsAppChat.normalize(inbound({ type: "text", text: { body: text } }), { phoneNumberId })[0] as ChatEvent
+  )
+
+/**
+ * The conformance hook: builds the `button_reply` or `list_reply` of a
+ * reply button or list row the adapter sent, and delivers it through
+ * `WhatsAppChat.receive`.
+ */
+export const makeInteractions = (graph: ReturnType) => {
+  let service: WhatsAppChat.WhatsAppChat["Service"] | undefined
+  const bind = Effect.tap(WhatsAppChat.WhatsAppChat, (whatsapp) =>
+    Effect.sync(() => {
+      service = whatsapp
+    }))
+  const interactions: Interactions = {
+    click: Effect.fnUntraced(function*(messageId, id, options) {
+      const interactive = graph.messages.get(messageId)?.interactive
+      const choices: Array<{ readonly id: string; readonly title: string }> = interactive?.type === "button"
+        ? interactive.action.buttons.map((button: any) => button.reply)
+        : interactive?.type === "list"
+        ? interactive.action.sections.flatMap((section: any) => section.rows)
+        : []
+      const choice = choices.find((choice) => {
+        if (choice.id.startsWith("b")) return choice.id.slice(1).split(join)[0] === id
+        const [select, ...value] = choice.id.slice(1).split(join)
+        return select === id && (options?.option === undefined || value.join(join) === options.option)
+      })
+      if (choice === undefined) return yield* Effect.fail(new NoSuchElement({ messageId, id }))
+      const kind = interactive.type === "button" ? "button_reply" : "list_reply"
+      yield* service!.receive(inbound({
+        type: "interactive",
+        context: { from: business, id: messageId },
+        interactive: { type: kind, [kind]: choice }
+      })).pipe(
+        Effect.provideService(ChatHandler, ChatHandler.of({ handle: () => Effect.void })),
+        Effect.orDie
+      )
+    }),
+    submit: () => Effect.void
+  }
+  return { bind, interactions }
+}
diff --git a/packages/chat/whatsapp/tsconfig.json b/packages/chat/whatsapp/tsconfig.json
new file mode 100644
index 00000000000..e2a8ca19a0d
--- /dev/null
+++ b/packages/chat/whatsapp/tsconfig.json
@@ -0,0 +1,8 @@
+{
+  "$schema": "https://json.schemastore.org/tsconfig",
+  "extends": "../../../tsconfig.base.json",
+  "include": ["src"],
+  "references": [
+    { "path": "../../effect" }
+  ]
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index da401cb2a26..11dcde3ec97 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -363,6 +363,12 @@ importers:
         specifier: workspace:^
         version: link:../../effect
 
+  packages/chat/whatsapp:
+    devDependencies:
+      effect:
+        specifier: workspace:^
+        version: link:../../effect
+
   packages/effect:
     devDependencies:
       '@types/node':
diff --git a/tsconfig.packages.json b/tsconfig.packages.json
index 6dd4da5a344..6501404c759 100644
--- a/tsconfig.packages.json
+++ b/tsconfig.packages.json
@@ -14,6 +14,7 @@
     { "path": "packages/ai/openrouter" },
     { "path": "packages/atom/react" },
     { "path": "packages/chat/slack" },
+    { "path": "packages/chat/whatsapp" },
     { "path": "packages/chat/discord" },
     { "path": "packages/atom/vue" },
     { "path": "packages/atom/solid" },
diff --git a/tsconfig.tests.json b/tsconfig.tests.json
index a9b0370f634..5591bfa3a2f 100644
--- a/tsconfig.tests.json
+++ b/tsconfig.tests.json
@@ -56,6 +56,8 @@
       "@effect/ai-openrouter/*": ["./packages/ai/openrouter/src/*.ts"],
       "@effect/chat-slack": ["./packages/chat/slack/src/index.ts"],
       "@effect/chat-slack/*": ["./packages/chat/slack/src/*.ts"],
+      "@effect/chat-whatsapp": ["./packages/chat/whatsapp/src/index.ts"],
+      "@effect/chat-whatsapp/*": ["./packages/chat/whatsapp/src/*.ts"],
       "@effect/chat-discord": ["./packages/chat/discord/src/index.ts"],
       "@effect/chat-discord/*": ["./packages/chat/discord/src/*.ts"],
       "@effect/atom-react": ["./packages/atom/react/src/index.ts"],
diff --git a/vitest.config.ts b/vitest.config.ts
index ea9ddaf7b37..2734f1e2d73 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -134,6 +134,7 @@ export default defineConfig({
       ...project("@effect/ai-openai-compat", "packages/ai/openai-compat"),
       ...project("@effect/ai-openrouter", "packages/ai/openrouter"),
       ...project("@effect/chat-slack", "packages/chat/slack"),
+      ...project("@effect/chat-whatsapp", "packages/chat/whatsapp"),
       // dfx imports `effect`, which has to be the same instance as the tests'
       // for things like `Redacted` to work, so vite resolves it too.
       ...project("@effect/chat-discord", "packages/chat/discord", true, {

From b2ecdb3bd3833db3b0376139e3abbe63aa31bff4 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:21:28 +0000
Subject: [PATCH 64/89] Add the Microsoft Teams adapter

A private @effect/chat-teams over the Bot Framework Connector, with capabilities that no tenant has confirmed behind unverified options. Jwks.makeRemote gains a filter for raw keys, and the ChatAdapter docs say how adapters derive messageLength and their own element caps.
---
 .changeset/effect-chat.md                     |   2 +
 packages/chat/teams/README.md                 |  73 +++
 packages/chat/teams/package.json              |  70 +++
 packages/chat/teams/src/TeamsChat.ts          | 445 ++++++++++++++++++
 packages/chat/teams/src/index.ts              |  12 +
 packages/chat/teams/src/internal/adapter.ts   | 381 +++++++++++++++
 packages/chat/teams/src/internal/address.ts   |  67 +++
 packages/chat/teams/src/internal/auth.ts      | 163 +++++++
 packages/chat/teams/src/internal/connector.ts | 267 +++++++++++
 packages/chat/teams/src/internal/download.ts  | 289 ++++++++++++
 packages/chat/teams/src/internal/envelope.ts  | 410 ++++++++++++++++
 packages/chat/teams/src/internal/errors.ts    |  94 ++++
 .../chat/teams/src/internal/interactions.ts   | 294 ++++++++++++
 packages/chat/teams/src/internal/length.ts    | 170 +++++++
 packages/chat/teams/src/internal/normalize.ts | 248 ++++++++++
 packages/chat/teams/src/internal/render.ts    | 242 ++++++++++
 packages/chat/teams/src/internal/webhook.ts   | 147 ++++++
 packages/chat/teams/test/conformance.test.ts  |  96 ++++
 packages/chat/teams/test/download.test.ts     | 104 ++++
 packages/chat/teams/test/envelope.test.ts     |  80 ++++
 packages/chat/teams/test/length.test.ts       |  33 ++
 packages/chat/teams/test/webhook.test.ts      | 132 ++++++
 packages/chat/teams/tsconfig.json             |   8 +
 packages/effect/src/chat/ChatAdapter.ts       |  10 +-
 packages/effect/src/jose/Jwks.ts              |  26 +-
 packages/effect/test/jose/Jwks.test.ts        |  22 +
 pnpm-lock.yaml                                |   6 +
 tsconfig.packages.json                        |   1 +
 tsconfig.tests.json                           |   2 +
 vitest.config.ts                              |   1 +
 30 files changed, 3889 insertions(+), 6 deletions(-)
 create mode 100644 packages/chat/teams/README.md
 create mode 100644 packages/chat/teams/package.json
 create mode 100644 packages/chat/teams/src/TeamsChat.ts
 create mode 100644 packages/chat/teams/src/index.ts
 create mode 100644 packages/chat/teams/src/internal/adapter.ts
 create mode 100644 packages/chat/teams/src/internal/address.ts
 create mode 100644 packages/chat/teams/src/internal/auth.ts
 create mode 100644 packages/chat/teams/src/internal/connector.ts
 create mode 100644 packages/chat/teams/src/internal/download.ts
 create mode 100644 packages/chat/teams/src/internal/envelope.ts
 create mode 100644 packages/chat/teams/src/internal/errors.ts
 create mode 100644 packages/chat/teams/src/internal/interactions.ts
 create mode 100644 packages/chat/teams/src/internal/length.ts
 create mode 100644 packages/chat/teams/src/internal/normalize.ts
 create mode 100644 packages/chat/teams/src/internal/render.ts
 create mode 100644 packages/chat/teams/src/internal/webhook.ts
 create mode 100644 packages/chat/teams/test/conformance.test.ts
 create mode 100644 packages/chat/teams/test/download.test.ts
 create mode 100644 packages/chat/teams/test/envelope.test.ts
 create mode 100644 packages/chat/teams/test/length.test.ts
 create mode 100644 packages/chat/teams/test/webhook.test.ts
 create mode 100644 packages/chat/teams/tsconfig.json

diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 0dc487121f9..9c627b56174 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -8,3 +8,5 @@
 Add unstable `effect/chat` APIs and Slack, Discord and WhatsApp adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
 
 Slack webhook and interactivity layers, and the WhatsApp webhook layer, require a `Mac` service. Provide a runtime layer such as `NodeCrypto.layerMac`, or `Mac.layerWebCrypto` with `SecureRandom.layerWebCrypto`.
+
+`Jwks.makeRemote` accepts a `filter` option that drops raw keys before they are decoded.
diff --git a/packages/chat/teams/README.md b/packages/chat/teams/README.md
new file mode 100644
index 00000000000..7fec4084b52
--- /dev/null
+++ b/packages/chat/teams/README.md
@@ -0,0 +1,73 @@
+# @effect/chat-teams
+
+A [Microsoft Teams](https://www.microsoft.com/microsoft-teams) adapter for `effect/chat`, over the Bot Framework Connector. It includes the messaging endpoint, a pure activity normaliser, and the address helpers.
+
+This package is private. Nothing in it has run against a real tenant yet, and it stays private until the live checks below pass.
+
+## Setup
+
+One layer serves one Entra tenant through a single-tenant Azure Bot registration:
+
+1. Register an app in Entra ID and create a client secret, or use a certificate or managed identity through a credentials provider.
+2. Create an Azure Bot resource of type single-tenant with that app id, turn on the Microsoft Teams channel, and point its messaging endpoint at the route given to `TeamsChat.layerWebhook`.
+3. Install the bot's app package in the tenant.
+
+```ts
+import * as TeamsChat from "@effect/chat-teams/TeamsChat"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+
+const Teams = TeamsChat.layerWebhook({ path: "/api/messages" }).pipe(
+  Layer.provideMerge(TeamsChat.layer({
+    appId: "",
+    tenantId: "",
+    credentials: Redacted.make("")
+  }))
+)
+```
+
+`TeamsChat.layer` needs `HttpClient`, the chat `Registry`, `Mac` and `Digest`. `TeamsChat.layerWebhook` needs `HttpRouter`, a `ChatHandler`, `HttpClient` and `Signature`. The adapter never calls `crypto.subtle` itself. Importing Bot Framework's public keys goes through `Jwk.importPublic`, which needs a `WebCrypto` reference whatever backend provides `Signature`.
+
+The cloud's endpoints and host allowlists come from `TeamsChat.publicCloud` or a `Cloud` of your own. They are configuration and are never read from an activity.
+
+## Capabilities
+
+By default the descriptor advertises `edit`, `delete`, `getThread` and `getUser`, alongside `post`. `getUser` needs `in`, the thread whose roster to read.
+
+These capabilities are implemented but stay off until their live checks pass. Turn them on with the `unverified` option, at your own risk:
+
+| Option        | Turns on                                    | Also needs        |
+| ------------- | ------------------------------------------- | ----------------- |
+| `buttons`     | `buttons` (buttons and link buttons)        | `interactionKeys` |
+| `modals`      | `modals`, `modalErrors` (dialogs)           | `buttons`         |
+| `commands`    | `commands`, `ephemeral` (targeted messages) |                   |
+| `startThread` | `startThread`                               |                   |
+| `download`    | `download`                                  |                   |
+
+A dialog opens only from a button whose id is listed in `modalButtons`. Any other `OpenModal` is refused as `Unsupported`.
+
+Not supported in this version: `fetchMessage`, `history` and `opener` (they need Microsoft Graph), `replyTo`, files, native streams and selects.
+
+## Security
+
+- Inbound requests need a Bot Framework token: RS256, with a key endorsed for `msteams`, the cloud's issuer, the app id as audience, and a `serviceurl` claim equal to the activity's `serviceUrl`. The channel must be `msteams` and the tenant the configured one. Anything else is answered 403.
+- Button and dialog tokens are signed (HS256) and bound to the app, the tenant and the conversation. They are not encrypted: anyone who sees a card can read a button's id and value.
+- Button tokens have no replay protection. A click can be sent again for as long as the conversation exists. Dialog tokens also bind the user and expire after an hour.
+- A command's private answer goes as a targeted message to the user who sent the command. If that fails, the answer is not posted in public.
+
+## Live checks
+
+None of these have run yet. They need a Microsoft 365 developer tenant, an Azure Bot resource and a public tunnel to the endpoint.
+
+- Base: posting, editing and deleting in a channel, a group chat and a personal chat; inbound messages and reactions; user ids; the message size budget (`messageLength` is 44,288 units, derived from a provisional 50,000-unit activity size).
+- `startThread`: replies addressed with `;messageid=`.
+- `buttons`: `Action.Execute` and its `Action.Submit` fallback reach the endpoint, with the signed token intact.
+- `modals` and `modalErrors`: `task/fetch` and `task/submit`, and a dialog kept open with field errors.
+- `commands` and `ephemeral`: targeted messages in and out.
+- `download`: Connector-hosted and pre-authorised file URLs.
+
+## Links
+
+- [Website](https://effect.website): documentation, guides, and news.
+- [Discord](https://discord.gg/effect-ts): ask questions, share what you're building, and talk to the core team.
+- [Issues](https://github.com/Effect-TS/effect/issues): bug reports and feature requests.
diff --git a/packages/chat/teams/package.json b/packages/chat/teams/package.json
new file mode 100644
index 00000000000..06c78cbb9e8
--- /dev/null
+++ b/packages/chat/teams/package.json
@@ -0,0 +1,70 @@
+{
+  "name": "@effect/chat-teams",
+  "version": "4.1.4",
+  "private": true,
+  "type": "module",
+  "license": "MIT",
+  "description": "The Microsoft Teams adapter for effect/chat",
+  "homepage": "https://effect.website",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/Effect-TS/effect.git",
+    "directory": "packages/chat/teams"
+  },
+  "bugs": {
+    "url": "https://github.com/Effect-TS/effect/issues"
+  },
+  "tags": [
+    "typescript",
+    "chat",
+    "teams"
+  ],
+  "keywords": [
+    "typescript",
+    "chat",
+    "teams"
+  ],
+  "sideEffects": [],
+  "exports": {
+    "./package.json": "./package.json",
+    ".": "./src/index.ts",
+    "./*": "./src/*.ts",
+    "./internal/*": null,
+    "./index": null,
+    "./*/index": null
+  },
+  "files": [
+    "src/**/*.ts",
+    "dist/**/*.js",
+    "dist/**/*.js.map",
+    "dist/**/*.d.ts",
+    "dist/**/*.d.ts.map",
+    "AGENTS.md",
+    "CLAUDE.md",
+    "ai-docs/**/*"
+  ],
+  "publishConfig": {
+    "access": "public",
+    "provenance": true,
+    "exports": {
+      "./package.json": "./package.json",
+      ".": "./dist/index.js",
+      "./*": "./dist/*.js",
+      "./internal/*": null,
+      "./index": null,
+      "./*/index": null
+    }
+  },
+  "scripts": {
+    "codegen": "effect-utils codegen",
+    "build": "tsc -b tsconfig.json && pnpm babel",
+    "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
+    "check": "tsc -b tsconfig.json"
+  },
+  "devDependencies": {
+    "effect": "workspace:^"
+  },
+  "peerDependencies": {
+    "effect": "workspace:^"
+  }
+}
diff --git a/packages/chat/teams/src/TeamsChat.ts b/packages/chat/teams/src/TeamsChat.ts
new file mode 100644
index 00000000000..43cb750d1bb
--- /dev/null
+++ b/packages/chat/teams/src/TeamsChat.ts
@@ -0,0 +1,445 @@
+/**
+ * The Microsoft Teams adapter for `effect/chat`, over the Bot Framework
+ * Connector: the `Registry` layer, the messaging endpoint, the pure
+ * normaliser and address helpers.
+ *
+ * **Details**
+ *
+ * - One layer serves one Entra tenant, with a single-tenant Azure Bot
+ *   registration. The cloud's endpoints and host allowlists come as a unit
+ *   from `publicCloud` or a `Cloud` of the consumer's own. They are
+ *   privileged configuration and never read from an activity.
+ * - Nothing here has run against a real tenant yet. The package is private
+ *   until it has. Capabilities beyond posting, editing, deleting and
+ *   reading threads and users are behind `unverified` options, off by
+ *   default, so a descriptor never advertises what no tenant confirmed.
+ * - Reading messages (`fetchMessage`, `history`, `opener`) needs
+ *   Microsoft Graph, which this version does not use. They are
+ *   `Unsupported`, as are `replyTo`, files and native streams.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import { Registry } from "effect/chat/ChatAdapter"
+import type { ChatError } from "effect/chat/ChatError"
+import type { ChatEvent } from "effect/chat/ChatEvent"
+import { ChatHandler } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type { ParseMention } from "effect/chat/ChatTest"
+import type { ChatThread } from "effect/chat/ChatThread"
+import * as Context from "effect/Context"
+import type * as Digest from "effect/crypto/Digest"
+import type * as Mac from "effect/crypto/Mac"
+import type * as Signature from "effect/crypto/Signature"
+import type * as DateTime from "effect/DateTime"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpRouter from "effect/http/HttpRouter"
+import type { SecretJwk } from "effect/jose/Jwk"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import type * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Adapter from "./internal/adapter.ts"
+import * as Address from "./internal/address.ts"
+import * as Auth from "./internal/auth.ts"
+import * as Connector from "./internal/connector.ts"
+import * as Envelope from "./internal/envelope.ts"
+import * as Interactions from "./internal/interactions.ts"
+import * as Normalize from "./internal/normalize.ts"
+import * as Webhook from "./internal/webhook.ts"
+
+/**
+ * The endpoints and host allowlists of one Microsoft cloud.
+ *
+ * **Details**
+ *
+ * - `connectorUrl` is where thread ops go. Ops tied to an inbound activity
+ *   (an invoke's answer, a command's answer, `followUp`) go to that
+ *   activity's `serviceUrl`, which must be `https:` on the default port
+ *   with a host exactly in `connectorHosts`, checked before a token is
+ *   attached. There is no fallback from one to the other.
+ * - `openIdMetadataUrl` and `issuer` check inbound tokens. The metadata's
+ *   `jwks_uri` must be on the metadata's own host.
+ * - `fileHostSuffixes` and `redirectHosts` bound downloads.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface Cloud {
+  /** The Connector base for thread ops, such as `https://smba.trafficmanager.net/teams`. */
+  readonly connectorUrl: string
+  /** The exact hosts an activity's `serviceUrl` may name. */
+  readonly connectorHosts: ReadonlyArray
+  /** Bot Framework's OpenID metadata. Its `jwks_uri` must be on the same host. */
+  readonly openIdMetadataUrl: string
+  /** The `iss` of an inbound token. */
+  readonly issuer: string
+  /** The Entra authority, without the tenant: `https://login.microsoftonline.com`. */
+  readonly loginUrl: string
+  /** The scope of a Connector token. */
+  readonly connectorScope: string
+  /** The host suffixes of a personal chat's pre-authorised file URL, matched at a label boundary. */
+  readonly fileHostSuffixes: ReadonlyArray
+  /** Extra exact hosts a download may be redirected to. */
+  readonly redirectHosts: ReadonlyArray
+}
+
+/**
+ * The public Azure cloud: Connector `smba.trafficmanager.net`, Bot
+ * Framework's OpenID metadata, Entra at `login.microsoftonline.com`, and
+ * `sharepoint.com` for files. No extra redirect hosts.
+ *
+ * @stability unstable
+ * @category constants
+ * @since 4.1.5
+ */
+export const publicCloud: Cloud = Connector.publicCloud
+
+/**
+ * How the adapter gets its Connector token: the bot's client secret, for
+ * client credentials against the tenant, or a provider that gets a token
+ * for a scope, for certificates or managed identities.
+ *
+ * **Details**
+ *
+ * A token is cached until five minutes before `expiresAt`. A token
+ * without `expiresAt` is not cached, and the provider is called for every
+ * request.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Credentials =
+  | Redacted.Redacted
+  | ((scope: string) => Effect.Effect<{
+    readonly token: Redacted.Redacted
+    readonly expiresAt?: DateTime.DateTime | undefined
+  }, ChatError>)
+
+/**
+ * Capabilities whose live checks have not passed. Each is off by default
+ * and, when off, is absent from the descriptor and its op fails
+ * `Unsupported`.
+ *
+ * **Details**
+ *
+ * - `buttons`: buttons and link buttons on a card. Needs
+ *   `interactionKeys`. Selects are never supported.
+ * - `modals`: dialogs opened by the buttons named in `modalButtons`, with
+ *   field errors. Needs `buttons`.
+ * - `commands`: agent slash commands, answered in private or in public,
+ *   and `followUp` for 24 hours. Also turns on `ephemeral`.
+ * - `startThread`: the reply chain under a channel post.
+ * - `download`: files on inbound messages.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface Unverified {
+  readonly buttons?: boolean | undefined
+  readonly modals?: boolean | undefined
+  readonly commands?: boolean | undefined
+  readonly startThread?: boolean | undefined
+  readonly download?: boolean | undefined
+}
+
+/**
+ * The Teams side of the adapter.
+ *
+ * **Details**
+ *
+ * - `call` sends one Connector request, with the bot's token, for what the
+ *   adapter has no op for. `path` starts with `/v3/` and has its segments
+ *   encoded. A `serviceUrl` routes it to an inbound activity's Connector,
+ *   after the allowlist check. A write is never retried once sent, and a
+ *   failure that may have landed is `uncertain`.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class TeamsChat extends Context.Service> | undefined
+    }
+  ) => Effect.Effect
+}>()("@effect/chat-teams/TeamsChat") {}
+
+/**
+ * Registers the Teams adapter in the `Registry`, for one tenant.
+ *
+ * **Details**
+ *
+ * - `post` and `edit` without elements send the Markdown as `text` with
+ *   `textFormat: "extendedmarkdown"`, with every `<` and `&` as an entity,
+ *   so no HTML and no `` mention forms. Mentions notify nobody.
+ * - With elements, the message is one Adaptive Card and no `text`:
+ *   `TextBlock`, `CodeBlock` and `Table` elements from the Markdown, then
+ *   `ActionSet` rows. An `edit` may switch between the two forms.
+ * - `limits.messageLength` is a budget, not Microsoft's number. It is the
+ *   provisional size `Edge` (50,000 UTF-16 units of activity JSON, half of
+ *   the 100 KB Microsoft documents, until a live check sets it) less a fixed
+ *   reservation `R` for the card's structure, the auxiliary members and
+ *   4,000 units of mention entities: 44,288 today. `measure` prices each
+ *   unit by what escaping and card structure can make of it.
+ * - A button carries a signed token (HS256 JWT) under the card data key
+ *   `effect`, bound to the app, the tenant and the conversation. It is
+ *   signed, not encrypted: anyone who sees the card can read the id and
+ *   value. A token has no replay protection: a click can be sent again
+ *   while the conversation exists. A dialog token also binds the user and
+ *   expires after an hour.
+ * - The adapter's own caps, as Teams publishes none: 6 elements per message,
+ *   200 code units for an element's id plus value, 10 fields per modal and
+ *   1,000 code units for a modal's id plus metadata. A message with every
+ *   element at its cap still fits `messageLength`.
+ * - `getUser` needs `in`, the thread whose roster to read: without it
+ *   it fails `InvalidRequest` with `thread_required`. A user's id is the
+ *   Entra object id when Teams sends one, and the Connector id (`29:…`,
+ *   `28:…`) otherwise; `raw` keeps the Connector record.
+ * - The layer provides `TeamsChat` beside registering the adapter. It
+ *   needs `Mac` and `Digest` for the interaction tokens; the adapter
+ *   never calls `crypto.subtle` itself.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layer = (options: {
+  readonly appId: string
+  readonly tenantId: string
+  readonly credentials: Credentials
+  readonly cloud?: Cloud | undefined
+  /**
+   * The keys that sign button and dialog tokens. The first signs, and any
+   * verifies by its `kid`, so a rotation adds a key in front and drops the
+   * old one later. Each needs a distinct `kid` of 1 to 16 characters from
+   * `[A-Za-z0-9_-]` and at least 32 bytes. Without keys, there are no
+   * buttons or modals.
+   */
+  readonly interactionKeys?: readonly [Redacted.Redacted, ...Array>] | undefined
+  /** The ids of the buttons that open a dialog. Only these may answer `OpenModal`. */
+  readonly modalButtons?: ReadonlyArray | undefined
+  readonly unverified?: Unverified | undefined
+}): Layer.Layer =>
+  Layer.effect(
+    TeamsChat,
+    Effect.gen(function*() {
+      const http = yield* HttpClient.HttpClient
+      const registry = yield* Registry
+      const cloud = options.cloud ?? publicCloud
+      const tokens = Connector.makeTokens({
+        http,
+        cloud,
+        appId: options.appId,
+        tenantId: options.tenantId,
+        credentials: options.credentials
+      })
+      const connector = Connector.make({ http, cloud, token: tokens })
+      const envelope = options.interactionKeys === undefined
+        ? undefined
+        : yield* Envelope.make({ appId: options.appId, tenantId: options.tenantId, keys: options.interactionKeys })
+      const modalButtons = new Set(options.modalButtons ?? [])
+      const { adapter, answer } = Adapter.make({
+        connector,
+        http,
+        cloud,
+        appId: options.appId,
+        tenantId: options.tenantId,
+        envelope,
+        unverified: options.unverified ?? {},
+        token: tokens(cloud.connectorScope),
+        modalButtons
+      })
+      yield* registry.register(adapter)
+      const service = TeamsChat.of({
+        appId: options.appId,
+        tenantId: options.tenantId,
+        cloud,
+        call: (method, path, body, callOptions) => connector.call(method, path, body, callOptions)
+      })
+      Adapter.internals.set(service, { capabilities: adapter.descriptor.capabilities, envelope, modalButtons, answer })
+      return service
+    })
+  )
+
+/**
+ * `POST {path}`: the bot's messaging endpoint.
+ *
+ * **Details**
+ *
+ * - Checks the bearer token: RS256 with a key from Bot Framework's key set
+ *   that is endorsed for `msteams`, the cloud's issuer, the app id as
+ *   audience, five minutes of skew and an `exp`. Then the token's
+ *   `serviceurl` must equal the activity's `serviceUrl`, `channelId`
+ *   must be `msteams` and the tenant the layer's. Any failure is 403. A
+ *   key set that can't be read is 503.
+ * - A targeted activity, one only the bot can see, is classified before
+ *   anything else, whatever its type. A targeted message takes the command
+ *   path: its first word names the command and the rest is its `text`. One
+ *   that names no registered command is acked and nothing is sent. A
+ *   targeted invoke goes to the interaction handler. Any other targeted
+ *   activity is answered 200 and dropped. None reaches the `ChatHandler`,
+ *   `onUnhandled`, or anything public.
+ * - Invokes go to `ChatInteraction.Handler` within `interactionDeadline`
+ *   (4 seconds by default). Without a `Handler` in context, every invoke
+ *   and every targeted message gets an empty 200.
+ * - Other activities go through `normalize` to the `ChatHandler`: 200
+ *   when it succeeds, 503 when it fails `NotAccepted` or a message can't
+ *   be normalised. An activity with no event goes to `onUnhandled` and is
+ *   answered 200. Past `deadline` (10 seconds by default) the handler is
+ *   interrupted and the answer is 503. Each 503 is logged with its reason.
+ * - Answers 413 past `maxBodyBytes` (1 MiB by default).
+ *
+ * Token checks need the `Signature` service. Importing the key set's
+ * public keys goes through `Jwk.importPublic`, which needs a `WebCrypto`
+ * reference whatever crypto backend provides `Signature`.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layerWebhook = (options: {
+  readonly path: `/${string}`
+  readonly deadline?: Duration.Input | undefined
+  readonly interactionDeadline?: Duration.Input | undefined
+  readonly maxBodyBytes?: number | undefined
+  readonly onUnhandled?: ((activity: Schema.Json) => Effect.Effect) | undefined
+}): Layer.Layer<
+  never,
+  never,
+  HttpRouter.HttpRouter | TeamsChat | ChatHandler | HttpClient.HttpClient | Signature.Signature
+> =>
+  HttpRouter.use(Effect.fnUntraced(function*(router) {
+    const teams = yield* TeamsChat
+    const internals = Adapter.internals.get(teams)
+    if (internals === undefined) return yield* Effect.die(new Error("TeamsChat.layerWebhook needs TeamsChat.layer"))
+    const handler = yield* ChatHandler
+    const interactionHandler = yield* Effect.serviceOption(ChatInteraction.Handler)
+    const interactionRegistry = yield* Effect.serviceOption(ChatInteraction.Registry)
+    const verify = yield* Auth.makeVerifier({ cloud: teams.cloud, appId: teams.appId, tenantId: teams.tenantId })
+    const interactionOptions: Interactions.Options = {
+      capabilities: internals.capabilities,
+      envelope: internals.envelope,
+      modalButtons: internals.modalButtons,
+      answer: internals.answer,
+      deadline: options.interactionDeadline === undefined
+        ? Interactions.defaultDeadline
+        : Duration.fromInputUnsafe(options.interactionDeadline)
+    }
+    const webhookOptions: Webhook.Options = {
+      verify,
+      context: {
+        appId: teams.appId,
+        connectorHosts: new Set(teams.cloud.connectorHosts),
+        fileHostSuffixes: teams.cloud.fileHostSuffixes
+      },
+      handle: handler.handle,
+      onUnhandled: options.onUnhandled ?? (() => Effect.void),
+      invoke: (activity) =>
+        Option.isNone(interactionHandler)
+          ? Effect.succeed({ status: 200 })
+          : Effect.provideService(
+            Interactions.invoke(activity, interactionOptions),
+            ChatInteraction.Handler,
+            interactionHandler.value
+          ),
+      command: (activity) =>
+        Option.isNone(interactionHandler) || Option.isNone(interactionRegistry)
+          ? Effect.void
+          : Effect.provideService(
+            Interactions.command(activity, {
+              ...interactionOptions,
+              isRegistered: (id) =>
+                Effect.map(interactionRegistry.value.get(id), (entry) => entry?.definition.kind === "command")
+            }),
+            ChatInteraction.Handler,
+            interactionHandler.value
+          ),
+      deadline: options.deadline ?? Duration.seconds(10),
+      maxBodyBytes: options.maxBodyBytes ?? 1024 * 1024
+    }
+    yield* router.add("POST", options.path, (request) => Webhook.handleRequest(request, webhookOptions))
+  }))
+
+/**
+ * The address of a Teams conversation: the Bot Framework conversation id as
+ * it is. A channel thread is the channel's id followed by
+ * `;messageid={root}`.
+ *
+ * @stability unstable
+ * @category constructors
+ * @since 4.1.5
+ */
+export const thread: (conversationId: string) => ChatThread = Address.thread
+
+/**
+ * The parts of a Teams address, or `None` for another platform's or a
+ * malformed one.
+ *
+ * @stability unstable
+ * @category destructors
+ * @since 4.1.5
+ */
+export const parts: (thread: ChatThread) => Option.Option<{
+  readonly conversationId: string
+  readonly base: string
+  readonly root?: string | undefined
+}> = Address.parts
+
+/**
+ * The normaliser, for a consumer's own transport. It checks no token: that
+ * is the transport's job.
+ *
+ * **Details**
+ *
+ * - Pure: takes an activity, gives zero or more events.
+ * - A `message` gives a `MessageCreated`. Its `text` is Teams' `text` as
+ *   delivered, with `…` for each mention, where `mentions` point.
+ *   A channel post is addressed to the channel, a reply to the post's
+ *   thread.
+ * - `messageReaction` gives a `ReactionAdded` or `ReactionRemoved` per
+ *   reaction. The six types Teams documents are Unicode emoji; any other is
+ *   `custom:{type}`.
+ * - A targeted activity, a card submit and anything else give none.
+ * - `raw` is the activity.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const normalize = (
+  activity: unknown,
+  context: { readonly appId: string; readonly cloud?: Cloud | undefined }
+): ReadonlyArray => {
+  const cloud = context.cloud ?? publicCloud
+  return Normalize.normalize(activity, {
+    appId: context.appId,
+    connectorHosts: new Set(cloud.connectorHosts),
+    fileHostSuffixes: cloud.fileHostSuffixes
+  })
+}
+
+/**
+ * Reads one Teams mention, `…`, for `ChatTest`. The tag holds a
+ * display name and no id, so this is always `None`; a message's
+ * `mentions` come from its entities.
+ *
+ * @stability unstable
+ * @category testing
+ * @since 4.1.5
+ */
+export const parseMention: ParseMention = () => Option.none()
diff --git a/packages/chat/teams/src/index.ts b/packages/chat/teams/src/index.ts
new file mode 100644
index 00000000000..ce93f54b6bf
--- /dev/null
+++ b/packages/chat/teams/src/index.ts
@@ -0,0 +1,12 @@
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+
+// @barrel: Auto-generated exports. Do not edit manually.
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as TeamsChat from "./TeamsChat.ts"
diff --git a/packages/chat/teams/src/internal/adapter.ts b/packages/chat/teams/src/internal/adapter.ts
new file mode 100644
index 00000000000..02db4d75744
--- /dev/null
+++ b/packages/chat/teams/src/internal/adapter.ts
@@ -0,0 +1,381 @@
+import {
+  type ChatAdapter,
+  checkMessageLength,
+  type Descriptor,
+  type Posted,
+  type ThreadInfo,
+  type User
+} from "effect/chat/ChatAdapter"
+import { type Capability, type ChatError, type ChatErrorReason, interactionExpired } from "effect/chat/ChatError"
+import type { Defer } from "effect/chat/ChatInteraction"
+import type { Attachment } from "effect/chat/ChatMessage"
+import type { ChatThread } from "effect/chat/ChatThread"
+import type { Action } from "effect/chat/ChatUi"
+import * as Clock from "effect/Clock"
+import * as DateTime from "effect/DateTime"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import type * as HttpClient from "effect/http/HttpClient"
+import * as Option from "effect/Option"
+import type * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Stream from "effect/Stream"
+import * as Address from "./address.ts"
+import { type Cloud, type Connector, segment } from "./connector.ts"
+import * as Download from "./download.ts"
+import type * as Envelope from "./envelope.ts"
+import * as Errors from "./errors.ts"
+import * as Length from "./length.ts"
+import { botId, isObject, object, string, userId } from "./normalize.ts"
+import * as Render from "./render.ts"
+
+/**
+ * The capabilities a layer may turn on that no tenant run has confirmed
+ * yet. Each is off by default.
+ *
+ * @internal
+ */
+export interface Unverified {
+  readonly buttons?: boolean | undefined
+  readonly modals?: boolean | undefined
+  readonly commands?: boolean | undefined
+  readonly startThread?: boolean | undefined
+  readonly download?: boolean | undefined
+}
+
+/** The adapter's own cap on elements in one message. @internal */
+export const actionsPerMessage = Render.actionsPerRow
+
+/** The adapter's own cap on an element's id plus value, in UTF-16 code units. @internal */
+export const actionDataLength = 200
+
+/** The adapter's own cap on a modal's id plus metadata. @internal */
+export const modalMetadataLength = 1_000
+
+/** The adapter's own cap on a modal's inputs and texts. @internal */
+export const modalFields = 10
+
+/** How long a targeted message can be answered. @internal */
+export const followUpAge = Duration.hours(24)
+
+/** @internal */
+export const capabilitiesOf = (unverified: Unverified, hasKeys: boolean): ReadonlySet => {
+  const set = new Set(["edit", "delete", "getThread", "getUser"])
+  if (unverified.startThread === true) set.add("startThread")
+  if (unverified.download === true) set.add("download")
+  if (hasKeys && unverified.buttons === true) {
+    set.add("buttons")
+    if (unverified.modals === true) {
+      set.add("modals")
+      set.add("modalErrors")
+    }
+  }
+  if (unverified.commands === true) {
+    set.add("commands")
+    set.add("ephemeral")
+  }
+  return set
+}
+
+/** @internal */
+export const makeDescriptor = (capabilities: ReadonlySet, tokenLength: Length.TokenLength): Descriptor => ({
+  platform: Address.platform,
+  capabilities,
+  measure: Length.makeMeasure(tokenLength),
+  limits: {
+    messageLength: Length.messageLength,
+    filesPerMessage: 0,
+    uploadBytes: 0,
+    minWriteInterval: Duration.seconds(1),
+    ...(capabilities.has("buttons") ? { actionsPerMessage, actionDataLength } : {}),
+    ...(capabilities.has("modals") ? { modalMetadataLength, modalFields } : {}),
+    ...(capabilities.has("commands") ? { followUpAge } : {})
+  }
+})
+
+/** A fallback token length for a layer without keys: the largest a token can be. */
+const noKeys: Length.TokenLength = () => 0
+
+/** @internal */
+export interface Options {
+  readonly connector: Connector
+  readonly http: HttpClient.HttpClient
+  readonly cloud: Cloud
+  readonly appId: string
+  readonly tenantId: string
+  readonly envelope: Envelope.Envelope | undefined
+  readonly unverified: Unverified
+  readonly token: Effect.Effect, ChatError>
+  /** The ids of the buttons that open a dialog. */
+  readonly modalButtons: ReadonlySet
+}
+
+/** @internal */
+export interface Made {
+  readonly adapter: ChatAdapter
+  /**
+   * Sends a command's answer through the inbound `serviceUrl` in `raw`:
+   * private as a targeted message to the command's user, public as a new
+   * post. A failure is never retried in the other form.
+   */
+  readonly answer: (
+    op: string,
+    raw: Schema.Json,
+    content: { readonly markdown: string; readonly actions?: ReadonlyArray | undefined },
+    visibility: "ephemeral" | "public"
+  ) => Effect.Effect
+}
+
+/**
+ * Swaps the action of each button that opens a dialog for an
+ * `Action.Submit` with `task/fetch`, which is smaller than the
+ * `Action.Execute` and its fallback that the measure counted.
+ */
+const opensDialogs = (
+  activity: Record,
+  modalButtons: ReadonlySet,
+  tokens: ReadonlyMap
+): Record => {
+  const openers = new Map()
+  for (const [action, token] of tokens) {
+    if (action._tag === "Button" && modalButtons.has(action.id)) openers.set(token, action)
+  }
+  if (openers.size === 0) return activity
+  const swap = (node: unknown): unknown => {
+    if (Array.isArray(node)) return node.map(swap)
+    if (typeof node !== "object" || node === null) return node
+    const record = node as Record
+    const data = record.data as Record | undefined
+    const token = record.type === "Action.Execute" && typeof data?.effect === "string" ? data.effect : undefined
+    const opener = token === undefined ? undefined : openers.get(token)
+    if (opener !== undefined) {
+      return { type: "Action.Submit", title: opener.label, data: { msteams: { type: "task/fetch" }, effect: token } }
+    }
+    const out: Record = {}
+    for (const [key, value] of Object.entries(record)) out[key] = swap(value)
+    return out
+  }
+  return swap(activity) as Record
+}
+
+const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
+
+/** @internal */
+export const make = (options: Options): Made => {
+  const capabilities = capabilitiesOf(options.unverified, options.envelope !== undefined)
+  const descriptor = makeDescriptor(capabilities, options.envelope?.tokenLength ?? noKeys)
+  const { connector } = options
+  const self = botId(options.appId)
+
+  const unsupported = (op: string, capability: Capability) => fail(op, Errors.unsupported(capability))
+
+  const address = (op: string, thread: ChatThread): Effect.Effect => {
+    const parts = Address.parts(thread)
+    return Option.isSome(parts) ? Effect.succeed(parts.value) : fail(op, Errors.invalidRequest("invalid_thread"))
+  }
+
+  const checkId = (op: string, id: string): Effect.Effect =>
+    id.length === 0 || id.length > Address.maxIdLength ? fail(op, Errors.invalidRequest("invalid_id")) : Effect.void
+
+  /**
+   * The activity body for Markdown and elements: the text form without
+   * elements, one card with them. Checks capabilities and limits first.
+   */
+  const body = (
+    op: string,
+    conversationId: string,
+    content: { readonly markdown: string; readonly actions?: ReadonlyArray | undefined }
+  ): Effect.Effect, ChatError> =>
+    Effect.gen(function*() {
+      const actions = content.actions ?? []
+      if (actions.some((action) => action._tag === "Select")) return yield* unsupported(op, "selects")
+      if (actions.length > 0 && (!capabilities.has("buttons") || options.envelope === undefined)) {
+        return yield* unsupported(op, "buttons")
+      }
+      yield* checkMessageLength(descriptor, op, content.markdown, actions)
+      if (actions.length === 0) return Render.textActivity(content.markdown)
+      if (actions.length > actionsPerMessage) return yield* fail(op, Errors.tooLarge(undefined, "too_many_actions"))
+      const tokens = new Map()
+      for (const action of actions) {
+        if (action._tag !== "Button") continue
+        if (action.id.length + (action.value?.length ?? 0) > actionDataLength) {
+          return yield* fail(op, Errors.tooLarge(undefined, "action_data_too_long"))
+        }
+        const token = yield* Effect.mapError(
+          options.envelope!.signButton(conversationId, {
+            id: action.id,
+            ...(action.value === undefined ? {} : { value: action.value })
+          }),
+          (reason) => Errors.chatError(op, reason)
+        )
+        tokens.set(action, token)
+      }
+      return opensDialogs(
+        Render.cardActivity(content.markdown, actions, (button) => tokens.get(button)!),
+        options.modalButtons,
+        tokens
+      )
+    })
+
+  const now = Effect.map(Clock.currentTimeMillis, (millis) => DateTime.makeUnsafe(millis))
+
+  const activityId = (op: string, answer: Schema.Json | undefined): Effect.Effect => {
+    const id = isObject(answer) ? string(answer, "id") : undefined
+    return id === undefined ? fail(op, Errors.invalidResponse(true, "missing_id")) : Effect.succeed(id)
+  }
+
+  const activities = (conversationId: string) => `/v3/conversations/${segment(conversationId)}/activities`
+
+  const adapter: ChatAdapter = {
+    descriptor,
+    post: Effect.fnUntraced(function*(thread, content) {
+      const op = "post"
+      const parts = yield* address(op, thread)
+      if (content.files !== undefined && content.files.length > 0) return yield* unsupported(op, "files")
+      if (content.replyTo !== undefined) return yield* unsupported(op, "replyTo")
+      const activity = yield* body(op, parts.conversationId, content)
+      const answer = yield* connector.call("POST", activities(parts.conversationId), activity, { write: true, op })
+      const id = yield* activityId(op, answer)
+      return { id, thread, timestamp: yield* now } satisfies Posted
+    }),
+    edit: Effect.fnUntraced(function*(thread, messageId, content) {
+      const op = "edit"
+      const parts = yield* address(op, thread)
+      yield* checkId(op, messageId)
+      const activity = yield* body(op, parts.conversationId, content)
+      yield* connector.call(
+        "PUT",
+        `${activities(parts.conversationId)}/${segment(messageId)}`,
+        { ...activity, id: messageId },
+        { write: true, op }
+      )
+    }),
+    delete: Effect.fnUntraced(function*(thread, messageId) {
+      const op = "delete"
+      const parts = yield* address(op, thread)
+      yield* checkId(op, messageId)
+      yield* connector.call("DELETE", `${activities(parts.conversationId)}/${segment(messageId)}`, undefined, {
+        write: true,
+        op
+      })
+    }),
+    fetchMessage: () => unsupported("fetchMessage", "fetchMessage"),
+    history: () => Stream.fail(Errors.chatError("history", Errors.unsupported("history"))),
+    download: (_thread: ChatThread, attachment: Attachment, downloadOptions: { readonly maxBytes: number }) =>
+      capabilities.has("download")
+        ? Download.download(attachment.id, {
+          maxBytes: downloadOptions.maxBytes,
+          token: options.token,
+          connectorHosts: new Set(options.cloud.connectorHosts),
+          fileHostSuffixes: options.cloud.fileHostSuffixes,
+          redirectHosts: new Set(options.cloud.redirectHosts),
+          http: options.http
+        })
+        : Stream.fail(Errors.chatError("download", Errors.unsupported("download"))),
+    startThread: Effect.fnUntraced(function*(thread, messageId) {
+      const op = "startThread"
+      if (!capabilities.has("startThread")) return yield* unsupported(op, "startThread")
+      const parts = yield* address(op, thread)
+      yield* checkId(op, messageId)
+      if (parts.root !== undefined) return parts.root === messageId ? thread : Address.threadOf(parts.base, messageId)
+      if (!Address.isChannel(parts.base)) return yield* fail(op, Errors.invalidRequest("not_a_channel"))
+      if (!/^\d+$/.test(messageId)) return yield* fail(op, Errors.invalidRequest("invalid_id"))
+      return Address.threadOf(parts.base, messageId)
+    }),
+    getThread: Effect.fnUntraced(function*(thread) {
+      const op = "getThread"
+      const parts = yield* address(op, thread)
+      const raw = yield* connector.call(
+        "GET",
+        `/v3/conversations/${segment(parts.base)}/pagedmembers`,
+        undefined,
+        { op, query: { pageSize: "1" } }
+      )
+      const info: ThreadInfo = {
+        thread,
+        kind: Address.kind(parts.conversationId),
+        ...(parts.root === undefined ? {} : { parent: Address.thread(parts.base) }),
+        raw: raw ?? null
+      }
+      return info
+    }),
+    opener: () => unsupported("opener", "opener"),
+    getUser: Effect.fnUntraced(function*(id, userOptions) {
+      const op = "getUser"
+      if (userOptions?.in === undefined) return yield* fail(op, Errors.invalidRequest("thread_required"))
+      const parts = yield* address(op, userOptions.in)
+      yield* checkId(op, id)
+      const raw = yield* connector.call(
+        "GET",
+        `/v3/conversations/${segment(parts.base)}/members/${segment(id)}`,
+        undefined,
+        { op }
+      )
+      const connectorId = isObject(raw) ? string(raw, "id") : undefined
+      const canonical = isObject(raw) ? userId(raw) : undefined
+      if (!isObject(raw) || connectorId === undefined || canonical === undefined) {
+        return yield* fail(op, Errors.invalidResponse(false, "invalid_member"))
+      }
+      const user: User = {
+        id: canonical,
+        name: string(raw, "name") ?? string(raw, "givenName") ?? canonical,
+        isBot: connectorId.startsWith("28:"),
+        isSelf: connectorId === self,
+        raw
+      }
+      return user
+    }),
+    followUp: Effect.fnUntraced(function*(deferred: Defer, content) {
+      const op = "followUp"
+      if (!capabilities.has("commands")) return yield* unsupported(op, "commands")
+      const raw = deferred.command.raw
+      const sent = isObject(raw) ? string(raw, "timestamp") : undefined
+      const at = sent === undefined ? undefined : Option.getOrUndefined(DateTime.make(sent))
+      const current = yield* Clock.currentTimeMillis
+      if (at === undefined || current - DateTime.toEpochMillis(at) > Duration.toMillis(followUpAge)) {
+        return yield* fail(op, Errors.notFound(interactionExpired))
+      }
+      yield* answer(op, raw, content, deferred.visibility)
+    })
+  }
+
+  const answer: Made["answer"] = Effect.fnUntraced(function*(op, raw, content, visibility) {
+    if (!isObject(raw)) return yield* fail(op, Errors.invalidRequest("invalid_command"))
+    const serviceUrl = string(raw, "serviceUrl")
+    const conversationId = string(object(raw, "conversation"), "id")
+    const messageId = string(raw, "id")
+    const from = object(raw, "from")
+    const recipientId = string(from, "id")
+    if (
+      serviceUrl === undefined || conversationId === undefined || messageId === undefined ||
+      recipientId === undefined
+    ) {
+      return yield* fail(op, Errors.invalidRequest("invalid_command"))
+    }
+    for (const id of [conversationId, messageId, recipientId]) yield* checkId(op, id)
+    const activity = yield* body(op, conversationId, content)
+    if (visibility === "ephemeral") {
+      const name = string(from, "name")
+      yield* connector.call("POST", activities(conversationId), {
+        ...activity,
+        recipient: { id: recipientId, ...(name === undefined ? {} : { name }) },
+        entities: [{ type: "targetedMessageInfo", messageId }]
+      }, { write: true, op, serviceUrl, query: { isTargetedActivity: "true" } })
+    } else {
+      yield* connector.call("POST", activities(conversationId), activity, { write: true, op, serviceUrl })
+    }
+  })
+
+  return { adapter, answer }
+}
+
+/** What `layerWebhook` needs from the layer that registered the adapter. @internal */
+export interface Internals {
+  readonly capabilities: ReadonlySet
+  readonly envelope: Envelope.Envelope | undefined
+  readonly modalButtons: ReadonlySet
+  readonly answer: Made["answer"]
+}
+
+/** Keyed by the `TeamsChat` service the layer built. @internal */
+export const internals = new WeakMap()
diff --git a/packages/chat/teams/src/internal/address.ts b/packages/chat/teams/src/internal/address.ts
new file mode 100644
index 00000000000..28316d77b73
--- /dev/null
+++ b/packages/chat/teams/src/internal/address.ts
@@ -0,0 +1,67 @@
+import type { ThreadKind } from "effect/chat/ChatEvent"
+import * as ChatThread from "effect/chat/ChatThread"
+import * as Option from "effect/Option"
+
+/** @internal */
+export const platform = "teams"
+
+const replyChain = ";messageid="
+
+/**
+ * A Teams address is the Bot Framework conversation id as it is. A channel
+ * thread is the channel's id with `;messageid={root}` after it.
+ *
+ * @internal
+ */
+export const thread = (conversationId: string): ChatThread.ChatThread => ChatThread.make(platform, conversationId)
+
+/** @internal */
+export interface Parts {
+  /** The conversation id, as the Connector takes it. */
+  readonly conversationId: string
+  /** The conversation without a reply chain suffix. */
+  readonly base: string
+  /** The root message of a channel thread. */
+  readonly root?: string | undefined
+}
+
+/** @internal */
+export const parts = (address: ChatThread.ChatThread): Option.Option => {
+  if (address.platform !== platform || address.id.length === 0 || address.id.length > maxIdLength) {
+    return Option.none()
+  }
+  const at = address.id.indexOf(replyChain)
+  if (at === -1) return Option.some({ conversationId: address.id, base: address.id })
+  const base = address.id.slice(0, at)
+  const root = address.id.slice(at + replyChain.length)
+  if (base.length === 0 || !/^\d+$/.test(root)) return Option.none()
+  return Option.some({ conversationId: address.id, base, root })
+}
+
+/** The conversation id without its reply chain suffix. @internal */
+export const baseConversation = (conversationId: string): string => {
+  const at = conversationId.indexOf(replyChain)
+  return at === -1 ? conversationId : conversationId.slice(0, at)
+}
+
+/** @internal */
+export const threadOf = (base: string, root: string): ChatThread.ChatThread => thread(`${base}${replyChain}${root}`)
+
+/** A personal chat: a one-to-one conversation with the bot. @internal */
+export const isDirect = (conversationId: string): boolean => conversationId.startsWith("a:")
+
+/** A team channel, as opposed to a group or personal chat. @internal */
+export const isChannel = (conversationId: string): boolean =>
+  /@thread\.(tacv2|skype)$/.test(baseConversation(conversationId))
+
+/** @internal */
+export const kind = (conversationId: string): ThreadKind =>
+  conversationId.includes(replyChain) ? "thread" : isDirect(conversationId) ? "direct" : "channel"
+
+/**
+ * The longest id the adapter puts in a request: a conversation, message,
+ * user or tenant id. A longer one fails `InvalidRequest` before the call.
+ *
+ * @internal
+ */
+export const maxIdLength = 256
diff --git a/packages/chat/teams/src/internal/auth.ts b/packages/chat/teams/src/internal/auth.ts
new file mode 100644
index 00000000000..36fd4213ecd
--- /dev/null
+++ b/packages/chat/teams/src/internal/auth.ts
@@ -0,0 +1,163 @@
+import * as Clock from "effect/Clock"
+import type * as Signature from "effect/crypto/Signature"
+import * as Effect from "effect/Effect"
+import * as Exit from "effect/Exit"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import * as Jwks from "effect/jose/Jwks"
+import * as Jwt from "effect/jose/Jwt"
+import * as Schema from "effect/Schema"
+import * as Scope from "effect/Scope"
+import * as Semaphore from "effect/Semaphore"
+import { type Cloud, send } from "./connector.ts"
+
+/** The longest `Authorization` header read. Anything longer is refused unread. */
+const maxAuthorizationLength = 16 * 1024
+
+/** How long after a failed metadata or key set fetch the next is tried. */
+const retryAfter = 30_000
+
+/** The longest OpenID metadata document read. */
+const maxMetadataBytes = 64 * 1024
+
+const Claims = Schema.Struct({
+  serviceurl: Schema.optionalKey(Schema.String),
+  serviceUrl: Schema.optionalKey(Schema.String)
+})
+
+/**
+ * Keeps a key only when its `endorsements` is an array of strings holding
+ * `msteams`. A key without them is dropped: fails closed.
+ *
+ * @internal
+ */
+export const endorsedForTeams = (jwk: { readonly [key: string]: unknown }): boolean => {
+  const endorsements = jwk.endorsements
+  return Array.isArray(endorsements) && endorsements.every((e) => typeof e === "string") &&
+    endorsements.includes("msteams")
+}
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/** @internal */
+export type Verdict = "ok" | "forbidden" | "unavailable"
+
+/** What the token is checked against, from the activity's body. @internal */
+export interface Activity {
+  readonly serviceUrl: unknown
+  readonly channelId: unknown
+  readonly tenantId: string | undefined
+}
+
+/** The tenant of an activity: `conversation.tenantId`, else `channelData.tenant.id`. @internal */
+export const tenantOf = (activity: Record): string | undefined => {
+  const conversation = activity.conversation
+  if (isObject(conversation) && typeof conversation.tenantId === "string") return conversation.tenantId
+  const channelData = activity.channelData
+  if (isObject(channelData) && isObject(channelData.tenant) && typeof channelData.tenant.id === "string") {
+    return channelData.tenant.id
+  }
+  return undefined
+}
+
+/**
+ * Checks a Bot Framework bearer token: RS256 with a key endorsed for
+ * `msteams` from the cloud's key set, the cloud's issuer, the app id as
+ * audience, five minutes of skew and a required `exp`. Then the
+ * `serviceurl` claim must equal the activity's `serviceUrl`, its
+ * `channelId` must be `msteams` and its tenant the configured one.
+ *
+ * The key set is found lazily from the cloud's OpenID metadata, whose
+ * `jwks_uri` must be `https:` on the metadata's own host. Neither fetch
+ * follows a redirect. A key set that can't be read is `unavailable`, so
+ * the webhook answers 503 and Teams retries; every other failure is
+ * `forbidden`.
+ *
+ * @internal
+ */
+export const makeVerifier = Effect.fnUntraced(function*(options: {
+  readonly cloud: Cloud
+  readonly appId: string
+  readonly tenantId: string
+}) {
+  const http = yield* HttpClient.HttpClient
+  const scope = yield* Effect.scope
+  const signature = yield* Effect.context()
+  const lock = Semaphore.makeUnsafe(1)
+  let keys: Jwks.Jwks["Service"] | undefined
+  let failedAt = Number.NEGATIVE_INFINITY
+
+  const jwksUri = Effect.gen(function*() {
+    const metadataUrl = new URL(options.cloud.openIdMetadataUrl)
+    const response = yield* send(http, HttpClientRequest.get(metadataUrl.href), false, "openIdMetadata")
+    if (response.status !== 200) return yield* Effect.fail("metadata_status" as const)
+    const body = yield* Effect.orElseSucceed(response.text, () => "")
+    if (body.length === 0 || body.length > maxMetadataBytes) return yield* Effect.fail("metadata_size" as const)
+    let json: unknown
+    try {
+      json = JSON.parse(body)
+    } catch {
+      return yield* Effect.fail("metadata_json" as const)
+    }
+    const uri = isObject(json) ? json.jwks_uri : undefined
+    if (typeof uri !== "string") return yield* Effect.fail("metadata_jwks_uri" as const)
+    const parsed = new URL(uri)
+    if (parsed.protocol !== "https:" || parsed.port !== "" || parsed.hostname !== metadataUrl.hostname) {
+      return yield* Effect.fail("metadata_jwks_host" as const)
+    }
+    return parsed.href
+  }).pipe(Effect.scoped)
+
+  // The key set, found once. A failure is not retried for `retryAfter`, so
+  // unauthenticated requests can't drive a metadata fetch each.
+  const keySet: Effect.Effect = lock.withPermit(Effect.gen(function*() {
+    if (keys !== undefined) return keys
+    const now = yield* Clock.currentTimeMillis
+    if (now - failedAt < retryAfter) return undefined
+    const made = yield* jwksUri.pipe(
+      Effect.flatMap((url) => Jwks.makeRemote({ url, filter: endorsedForTeams })),
+      Effect.provideService(Scope.Scope, scope),
+      Effect.provideService(HttpClient.HttpClient, http),
+      Effect.option
+    )
+    if (made._tag === "None") {
+      failedAt = now
+      return undefined
+    }
+    keys = made.value
+    return keys
+  }))
+
+  return (authorization: string | undefined, activity: Activity): Effect.Effect =>
+    Effect.gen(function*() {
+      if (authorization === undefined || authorization.length > maxAuthorizationLength) return "forbidden"
+      const match = /^Bearer ([A-Za-z0-9_.-]+)$/.exec(authorization)
+      if (match === null) return "forbidden"
+      const resolved = yield* keySet
+      if (resolved === undefined) return "unavailable"
+      const exit = yield* Jwt.verifyWithKeySet(Claims, match[1], {
+        algorithms: ["RS256"],
+        issuer: options.cloud.issuer,
+        audience: options.appId,
+        clockTolerance: "5 minutes",
+        requiredClaims: ["exp"]
+      }).pipe(
+        Effect.provideService(Jwks.Jwks, resolved),
+        Effect.provideContext(signature),
+        Effect.exit
+      )
+      if (Exit.isFailure(exit)) {
+        const unavailable = exit.cause.reasons.some((reason) =>
+          reason._tag === "Fail" && reason.error._tag === "JoseError" &&
+          reason.error.reason._tag === "KeySetUnavailable"
+        )
+        return unavailable ? "unavailable" : "forbidden"
+      }
+      const claims = exit.value.claims
+      const claimed = claims.serviceurl ?? claims.serviceUrl
+      if (typeof activity.serviceUrl !== "string" || claimed !== activity.serviceUrl) return "forbidden"
+      if (activity.channelId !== "msteams") return "forbidden"
+      if (activity.tenantId !== options.tenantId) return "forbidden"
+      return "ok"
+    })
+})
diff --git a/packages/chat/teams/src/internal/connector.ts b/packages/chat/teams/src/internal/connector.ts
new file mode 100644
index 00000000000..733974b85d0
--- /dev/null
+++ b/packages/chat/teams/src/internal/connector.ts
@@ -0,0 +1,267 @@
+import { retrySafe } from "effect/chat/ChatAdapter"
+import type { ChatError, ChatErrorReason } from "effect/chat/ChatError"
+import * as Clock from "effect/Clock"
+import * as DateTime from "effect/DateTime"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as FetchHttpClient from "effect/http/FetchHttpClient"
+import type * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import type * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Semaphore from "effect/Semaphore"
+import * as Errors from "./errors.ts"
+
+/**
+ * The endpoints and hosts of one Microsoft cloud. All of it is privileged
+ * configuration: nothing here is ever read from an activity.
+ *
+ * @internal
+ */
+export interface Cloud {
+  /** The Connector base for thread ops, such as `https://smba.trafficmanager.net/teams`. */
+  readonly connectorUrl: string
+  /** The exact hosts an activity's `serviceUrl` may name. */
+  readonly connectorHosts: ReadonlyArray
+  /** Bot Framework's OpenID metadata. Its `jwks_uri` must be on the same host. */
+  readonly openIdMetadataUrl: string
+  /** The `iss` of an inbound token. */
+  readonly issuer: string
+  /** The Entra authority, without the tenant: `https://login.microsoftonline.com`. */
+  readonly loginUrl: string
+  /** The scope of a Connector token. */
+  readonly connectorScope: string
+  /** The host suffixes of a personal chat's pre-authorised file URL. */
+  readonly fileHostSuffixes: ReadonlyArray
+  /** Extra exact hosts a download may be redirected to. */
+  readonly redirectHosts: ReadonlyArray
+}
+
+/** @internal */
+export const publicCloud: Cloud = {
+  connectorUrl: "https://smba.trafficmanager.net/teams",
+  connectorHosts: ["smba.trafficmanager.net"],
+  openIdMetadataUrl: "https://login.botframework.com/v1/.well-known/openidconfiguration",
+  issuer: "https://api.botframework.com",
+  loginUrl: "https://login.microsoftonline.com",
+  connectorScope: "https://api.botframework.com/.default",
+  fileHostSuffixes: ["sharepoint.com"],
+  redirectHosts: []
+}
+
+/** A token and when it stops working. @internal */
+export interface Token {
+  readonly token: Redacted.Redacted
+  readonly expiresAt?: DateTime.DateTime | undefined
+}
+
+/** @internal */
+export type Credentials =
+  | Redacted.Redacted
+  | ((scope: string) => Effect.Effect)
+
+/** How long before `expiresAt` a cached token is dropped. */
+const refreshMargin = Duration.minutes(5)
+
+/**
+ * The trust step for a Connector base URL: `https:`, the default port, no
+ * userinfo and an exact host in the allowlist. Gives the URL without a
+ * trailing slash, or `undefined`.
+ *
+ * @internal
+ */
+export const trustedServiceUrl = (url: string, hosts: ReadonlyArray): string | undefined => {
+  let parsed: URL
+  try {
+    parsed = new URL(url)
+  } catch {
+    return undefined
+  }
+  if (
+    parsed.protocol !== "https:" || parsed.port !== "" || parsed.username !== "" || parsed.password !== "" ||
+    parsed.search !== "" || parsed.hash !== "" || !hosts.includes(parsed.hostname)
+  ) {
+    return undefined
+  }
+  return parsed.origin + parsed.pathname.replace(/\/+$/, "")
+}
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/**
+ * Gets a token by client credentials, or from the consumer's provider, and
+ * caches it until five minutes before it expires. A token with no expiry is
+ * not cached.
+ *
+ * @internal
+ */
+export const makeTokens = (options: {
+  readonly http: HttpClient.HttpClient
+  readonly cloud: Cloud
+  readonly appId: string
+  readonly tenantId: string
+  readonly credentials: Credentials
+}) => {
+  const cache = new Map; readonly until: number }>()
+  const lock = Semaphore.makeUnsafe(1)
+  const fail = (reason: ChatErrorReason) => Effect.fail(Errors.chatError("token", reason))
+
+  const clientCredentials = (secret: Redacted.Redacted) => (scope: string): Effect.Effect =>
+    Effect.gen(function*() {
+      const url = `${options.cloud.loginUrl}/${encodeURIComponent(options.tenantId)}/oauth2/v2.0/token`
+      const request = HttpClientRequest.post(url).pipe(
+        HttpClientRequest.bodyUrlParams({
+          grant_type: "client_credentials",
+          client_id: options.appId,
+          client_secret: Redacted.value(secret),
+          scope
+        })
+      )
+      const response = yield* send(options.http, request, false, "token")
+      if (response.status !== 200) {
+        return yield* fail(Errors.reasonForStatus(response.status, { write: false }))
+      }
+      const json = yield* response.json.pipe(
+        Effect.catch((cause) => fail(Errors.invalidResponse(false, "invalid_json", cause)))
+      )
+      if (!isObject(json) || typeof json.access_token !== "string" || json.access_token === "") {
+        return yield* fail(Errors.invalidResponse(false, "missing_access_token"))
+      }
+      const now = yield* Clock.currentTimeMillis
+      const expiresIn = typeof json.expires_in === "number" ? json.expires_in : Number(json.expires_in)
+      return {
+        token: Redacted.make(json.access_token),
+        ...(Number.isFinite(expiresIn) && expiresIn > 0
+          ? { expiresAt: DateTime.makeUnsafe(now + expiresIn * 1000) }
+          : {})
+      }
+    })
+
+  const provider = Redacted.isRedacted(options.credentials)
+    ? clientCredentials(options.credentials)
+    : options.credentials
+
+  return (scope: string): Effect.Effect, ChatError> =>
+    lock.withPermit(Effect.gen(function*() {
+      const now = yield* Clock.currentTimeMillis
+      const cached = cache.get(scope)
+      if (cached !== undefined && cached.until > now) return cached.token
+      cache.delete(scope)
+      const token = yield* retrySafe(provider(scope))
+      if (token.expiresAt !== undefined) {
+        const until = DateTime.toEpochMillis(token.expiresAt) - Duration.toMillis(refreshMargin)
+        if (until > now) cache.set(scope, { token: token.token, until })
+      }
+      return token.token
+    }))
+}
+
+/**
+ * Sends one request with redirects off. A response from another URL than
+ * the request's means something followed a redirect, and is refused.
+ *
+ * @internal
+ */
+export const send = (
+  http: HttpClient.HttpClient,
+  request: HttpClientRequest.HttpClientRequest,
+  write: boolean,
+  op: string
+): Effect.Effect =>
+  http.execute(request).pipe(
+    Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }),
+    Effect.catch((error) => Effect.fail(Errors.chatError(op, Errors.transport(write, error.reason._tag, error)))),
+    Effect.flatMap((response) =>
+      response.url !== "" && response.url !== request.url
+        ? Effect.fail(Errors.chatError(op, Errors.untrustedUrl()))
+        : Effect.succeed(response)
+    )
+  )
+
+/** @internal */
+export interface CallOptions {
+  readonly write?: boolean | undefined
+  readonly retry?: boolean | undefined
+  /**
+   * The activity's own `serviceUrl`, for an op tied to an inbound activity.
+   * It is checked against the allowlist before a token is attached. Absent,
+   * the cloud's global Connector URL is used.
+   */
+  readonly serviceUrl?: string | undefined
+  readonly query?: Readonly> | undefined
+  /** The op for the error. Default: the method and path. */
+  readonly op?: string | undefined
+}
+
+/** @internal */
+export interface Connector {
+  readonly call: (
+    method: "GET" | "POST" | "PUT" | "DELETE",
+    path: string,
+    body: unknown,
+    options?: CallOptions | undefined
+  ) => Effect.Effect
+}
+
+/**
+ * The Connector client. `path` starts with `/v3/` and has its segments
+ * encoded by the caller.
+ *
+ * @internal
+ */
+export const make = (options: {
+  readonly http: HttpClient.HttpClient
+  readonly cloud: Cloud
+  readonly token: (scope: string) => Effect.Effect, ChatError>
+}): Connector => {
+  const once = (
+    method: "GET" | "POST" | "PUT" | "DELETE",
+    path: string,
+    body: unknown,
+    callOptions: CallOptions | undefined
+  ): Effect.Effect => {
+    const write = callOptions?.write === true
+    const op = callOptions?.op ?? `${method} ${path.split("/").slice(0, 3).join("/")}`
+    const fail = (reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
+    return Effect.gen(function*() {
+      const base = callOptions?.serviceUrl === undefined
+        ? options.cloud.connectorUrl
+        : trustedServiceUrl(callOptions.serviceUrl, options.cloud.connectorHosts)
+      if (base === undefined) return yield* fail(Errors.untrustedUrl())
+      const token = yield* Effect.mapError(options.token(options.cloud.connectorScope), Errors.withOp(op))
+      let request = HttpClientRequest.make(method)(base + path).pipe(
+        HttpClientRequest.bearerToken(Redacted.value(token)),
+        HttpClientRequest.setHeader("accept", "application/json")
+      )
+      if (callOptions?.query !== undefined) request = HttpClientRequest.setUrlParams(request, callOptions.query)
+      if (body !== undefined) request = HttpClientRequest.bodyJsonUnsafe(request, body)
+      const response = yield* send(options.http, request, write, op)
+      const retryAfter = Errors.parseRetryAfter(response.headers["retry-after"])
+      if (response.status < 200 || response.status >= 300) {
+        const json = yield* Effect.orElseSucceed(response.json, () => undefined)
+        const error = isObject(json) && isObject(json.error) ? json.error : undefined
+        const code = typeof error?.code === "string" ? error.code : undefined
+        return yield* fail(Errors.reasonForStatus(response.status, { write, retryAfter, code }))
+      }
+      const text = yield* response.text.pipe(
+        Effect.catch((cause) => fail(Errors.invalidResponse(write, "invalid_body", cause)))
+      )
+      if (text.trim() === "") return undefined
+      try {
+        return JSON.parse(text) as Schema.Json
+      } catch (cause) {
+        return yield* fail(Errors.invalidResponse(write, "invalid_json", cause))
+      }
+    }).pipe(Effect.scoped)
+  }
+  return {
+    call: (method, path, body, callOptions) => {
+      const call = once(method, path, body, callOptions)
+      return callOptions?.retry === false ? call : retrySafe(call)
+    }
+  }
+}
+
+/** Encodes one path segment. @internal */
+export const segment = (value: string): string => encodeURIComponent(value)
diff --git a/packages/chat/teams/src/internal/download.ts b/packages/chat/teams/src/internal/download.ts
new file mode 100644
index 00000000000..399a82a9123
--- /dev/null
+++ b/packages/chat/teams/src/internal/download.ts
@@ -0,0 +1,289 @@
+import type { ChatError, ChatErrorReason } from "effect/chat/ChatError"
+import type * as ChatMessage from "effect/chat/ChatMessage"
+import * as Effect from "effect/Effect"
+import * as FetchHttpClient from "effect/http/FetchHttpClient"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import type * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+import * as Stream from "effect/Stream"
+import * as Errors from "./errors.ts"
+
+const op = "download"
+
+/** The content type of a personal chat file the bot may fetch without credentials. @internal */
+export const fileDownloadInfo = "application/vnd.microsoft.teams.file.download.info"
+
+/**
+ * An attachment id is one of:
+ *
+ * - `connector:{url}`: a Connector attachment view, fetched with the bot token.
+ * - `preauth:{url}`: a pre-authenticated file URL, fetched with no credentials.
+ *   The URL itself grants access, so it is never logged.
+ * - `url:{url}`: any other URL. It is kept so the message shows the file,
+ *   but `download` refuses it.
+ *
+ * @internal
+ */
+export type Kind = "connector" | "preauth" | "url"
+
+const kinds: ReadonlyArray = ["connector", "preauth", "url"]
+
+/**
+ * The path of a Connector attachment view:
+ * `/{region}/v3/attachments/{id}/views/{view}`, where the region segment may be
+ * absent. Each segment is letters, digits, `_` or `-`, and the URL has no
+ * query.
+ *
+ * @internal
+ */
+export const connectorPath = /^(?:\/[A-Za-z0-9_-]+)?\/v3\/attachments\/[A-Za-z0-9_-]+\/views\/[A-Za-z0-9_-]+$/
+
+/** Whether `host` is `suffix` or ends with `.{suffix}`. @internal */
+export const underSuffix = (host: string, suffixes: ReadonlyArray): boolean =>
+  suffixes.some((raw) => {
+    const suffix = raw.toLowerCase().replace(/^\./, "")
+    return suffix.length > 0 && (host === suffix || host.endsWith(`.${suffix}`))
+  })
+
+const isIpLiteral = (host: string): boolean => host.startsWith("[") || /^\d+\.\d+\.\d+\.\d+$/.test(host)
+
+const parse = (input: string, base?: string): URL | undefined => {
+  try {
+    return new URL(input, base)
+  } catch {
+    return undefined
+  }
+}
+
+/**
+ * Parses `input` and checks the parts every hop needs: `https:`, no userinfo,
+ * the default port and a host name rather than an IP literal. The fragment is
+ * dropped, since it is never sent.
+ *
+ * @internal
+ */
+export const safeUrl = (input: string, base?: string): URL | undefined => {
+  const url = parse(input, base)
+  if (
+    url === undefined || url.protocol !== "https:" || url.username !== "" || url.password !== "" ||
+    url.port !== "" || url.hostname.length === 0 || isIpLiteral(url.hostname)
+  ) {
+    return undefined
+  }
+  url.hash = ""
+  return url
+}
+
+const isObject = (value: unknown): value is Record =>
+  typeof value === "object" && value !== null && !Array.isArray(value)
+
+const string = (record: Record, key: string): string | undefined => {
+  const value = record[key]
+  return typeof value === "string" && value.length > 0 ? value : undefined
+}
+
+const size = (record: Record): number | undefined => {
+  const value = record.size
+  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined
+}
+
+/**
+ * Turns a Bot Framework activity attachment into a chat attachment.
+ *
+ * - `connector:` when `contentUrl` has the origin of the activity's
+ *   `serviceUrl`, its host is in `connectorHosts` and its path is
+ *   {@link connectorPath}.
+ * - `preauth:` for a file download info attachment in a personal chat whose
+ *   `content.downloadUrl` is under one of `fileHostSuffixes`. Its
+ *   `contentType` is Teams' own, so it is left out.
+ * - `url:` for any other `https:` or `http:` `contentUrl`.
+ *
+ * An attachment with no usable URL, such as a card or the HTML copy of the
+ * message, is `undefined`.
+ *
+ * @internal
+ */
+export const classify = (attachment: unknown, context: {
+  readonly serviceUrl: string
+  readonly conversationType?: string | undefined
+  readonly connectorHosts: ReadonlySet
+  readonly fileHostSuffixes: ReadonlyArray
+}): ChatMessage.Attachment | undefined => {
+  if (!isObject(attachment)) return undefined
+  const contentType = string(attachment, "contentType")
+  const name = string(attachment, "name")
+  const content = isObject(attachment.content) ? attachment.content : undefined
+  const make = (id: string, type: string | undefined, bytes: number | undefined): ChatMessage.Attachment => ({
+    id,
+    ...(name === undefined ? {} : { name }),
+    ...(type === undefined ? {} : { contentType: type }),
+    ...(bytes === undefined ? {} : { size: bytes })
+  })
+
+  if (contentType === fileDownloadInfo && context.conversationType === "personal" && content !== undefined) {
+    const raw = string(content, "downloadUrl")
+    const url = raw === undefined ? undefined : safeUrl(raw)
+    if (url !== undefined && underSuffix(url.hostname, context.fileHostSuffixes)) {
+      return make(`preauth:${url.href}`, undefined, size(content) ?? size(attachment))
+    }
+  }
+
+  const raw = string(attachment, "contentUrl")
+  if (raw === undefined) return undefined
+  const type = contentType === fileDownloadInfo ? undefined : contentType
+  const url = safeUrl(raw)
+  const service = parse(context.serviceUrl)
+  if (
+    url !== undefined && service !== undefined && url.origin === service.origin &&
+    context.connectorHosts.has(url.hostname) && url.search === "" && connectorPath.test(url.pathname)
+  ) {
+    return make(`connector:${url.href}`, type, size(attachment))
+  }
+  const other = parse(raw)
+  if (other === undefined || (other.protocol !== "https:" && other.protocol !== "http:")) return undefined
+  return make(`url:${other.href}`, type, size(attachment))
+}
+
+/**
+ * Splits an attachment id into its kind and URL.
+ *
+ * @internal
+ */
+export const parseId = (id: string): { readonly kind: Kind; readonly url: string } | undefined => {
+  const at = id.indexOf(":")
+  if (at === -1) return undefined
+  const kind = kinds.find((kind) => kind === id.slice(0, at))
+  return kind === undefined ? undefined : { kind, url: id.slice(at + 1) }
+}
+
+/** @internal */
+export interface DownloadOptions {
+  readonly maxBytes: number
+  /** The bot token. It is read only for a `connector:` id, and sent on its first request only. */
+  readonly token: Effect.Effect, ChatError>
+  /** Exact Connector hosts. */
+  readonly connectorHosts: ReadonlySet
+  /** Host suffixes for pre-authenticated file URLs, matched at a label boundary. */
+  readonly fileHostSuffixes: ReadonlyArray
+  /** Exact hosts a redirect may also go to. Empty by default. */
+  readonly redirectHosts?: ReadonlySet | undefined
+  readonly http?: HttpClient.HttpClient | undefined
+}
+
+/** The most redirects one download follows. @internal */
+export const maxRedirects = 3
+
+const redirects: ReadonlySet = new Set([301, 302, 303, 307, 308])
+
+const fail = (reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
+
+/**
+ * Streams the file behind an attachment id.
+ *
+ * Every hop, the first and each redirect, must pass {@link safeUrl} and have a
+ * host in the id's allowlist (exact `connectorHosts` for `connector:`,
+ * `fileHostSuffixes` for `preauth:`) or in `redirectHosts`. The first hop of a
+ * `connector:` id must also have the {@link connectorPath} shape. A URL that
+ * fails fails `Forbidden` with detail `untrusted_url`.
+ *
+ * Requests carry only the headers set here: the bearer token, on the first
+ * hop of a `connector:` id. Redirects are read by hand, at most
+ * {@link maxRedirects} of them, and only 301, 302, 303, 307 and 308, each sent
+ * again as a GET. Fetch runs with `redirect: "manual"`, and a response from
+ * another URL than the request's is refused, since a client followed a
+ * redirect without the checks.
+ *
+ * Errors and spans hold the host only: a `preauth:` URL is a credential.
+ * The client's own span is turned off for the same reason, as it records the
+ * whole URL.
+ *
+ * @internal
+ */
+export function download(
+  id: string,
+  options: DownloadOptions & { readonly http: HttpClient.HttpClient }
+): Stream.Stream
+export function download(
+  id: string,
+  options: DownloadOptions
+): Stream.Stream
+export function download(
+  id: string,
+  options: DownloadOptions
+): Stream.Stream {
+  return Stream.unwrap(Effect.gen(function*() {
+    const parsed = parseId(id)
+    if (parsed === undefined) return yield* fail(Errors.invalidRequest("attachment_id"))
+    if (parsed.kind === "url") return yield* fail(Errors.unsupported("download", "url_attachment"))
+    const { kind } = parsed
+    const redirectHosts = options.redirectHosts ?? new Set()
+    const allowed = (url: URL): boolean =>
+      (kind === "connector"
+        ? options.connectorHosts.has(url.hostname)
+        : underSuffix(url.hostname, options.fileHostSuffixes))
+      || redirectHosts.has(url.hostname)
+
+    const first = safeUrl(parsed.url)
+    if (
+      first === undefined || !allowed(first) ||
+      (kind === "connector" && (first.search !== "" || !connectorPath.test(first.pathname)))
+    ) {
+      return yield* fail(Errors.untrustedUrl())
+    }
+
+    const http = HttpClient.withScope(options.http ?? (yield* HttpClient.HttpClient))
+    const tooLarge = Errors.chatError(op, Errors.tooLarge("files", "max_bytes"))
+
+    const send = (url: URL, hop: number) =>
+      Effect.gen(function*() {
+        let request = HttpClientRequest.get(url.href)
+        if (kind === "connector" && hop === 0) {
+          const token = yield* Effect.mapError(options.token, Errors.withOp(op))
+          request = HttpClientRequest.bearerToken(request, Redacted.value(token))
+        }
+        const sent = Option.getOrUndefined(HttpClientRequest.toUrl(request))?.href
+        const response = yield* http.execute(request).pipe(
+          Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }),
+          Effect.provideService(HttpClient.TracerDisabledWhen, () => true),
+          Effect.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag)))
+        )
+        yield* Effect.annotateCurrentSpan("http.response.status_code", response.status)
+        if (response.url !== sent) return yield* fail(Errors.untrustedUrl())
+        return response
+      }).pipe(
+        Effect.withSpan("TeamsChat.download.request", {
+          kind: "client",
+          attributes: { "server.address": url.hostname, "teams.download.hop": hop }
+        })
+      )
+
+    let url = first
+    let response: HttpClientResponse.HttpClientResponse
+    for (let hop = 0;; hop++) {
+      response = yield* send(url, hop)
+      if (!redirects.has(response.status)) break
+      if (hop === maxRedirects) return yield* fail(Errors.invalidResponse(false, "too_many_redirects"))
+      const location = response.headers.location
+      if (location === undefined) return yield* fail(Errors.invalidResponse(false, "missing_location"))
+      const next = safeUrl(location, url.href)
+      if (next === undefined || !allowed(next)) return yield* fail(Errors.untrustedUrl())
+      url = next
+    }
+
+    if (response.status < 200 || response.status >= 300) {
+      return yield* fail(Errors.reasonForStatus(response.status, { write: false }))
+    }
+    const length = Number(response.headers["content-length"])
+    if (Number.isFinite(length) && length > options.maxBytes) return yield* Effect.fail(tooLarge)
+    let received = 0
+    return response.stream.pipe(
+      Stream.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag))),
+      Stream.mapEffect((chunk) => {
+        received += chunk.length
+        return received > options.maxBytes ? Effect.fail(tooLarge) : Effect.succeed(chunk)
+      })
+    )
+  }))
+}
diff --git a/packages/chat/teams/src/internal/envelope.ts b/packages/chat/teams/src/internal/envelope.ts
new file mode 100644
index 00000000000..bab628a9748
--- /dev/null
+++ b/packages/chat/teams/src/internal/envelope.ts
@@ -0,0 +1,410 @@
+/**
+ * The envelope a button or dialog carries in its `effect` data key: a compact
+ * HS256 JWT bound to the bot, the tenant and the conversation. A dialog token
+ * also binds the user it opened for and holds the modal's definition, so a
+ * submit is checked against what was signed.
+ */
+import type { NonEmptyReadonlyArray } from "effect/Array"
+import type { ChatErrorReason } from "effect/chat/ChatError"
+import type * as ChatUi from "effect/chat/ChatUi"
+import * as Clock from "effect/Clock"
+import * as Digest from "effect/crypto/Digest"
+import * as Mac from "effect/crypto/Mac"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Base64Url from "effect/encoding/Base64Url"
+import * as Jwk from "effect/jose/Jwk"
+import * as Jwt from "effect/jose/Jwt"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+import * as Schema from "effect/Schema"
+import { baseConversation, maxIdLength } from "./address.ts"
+import { invalidRequest, tooLarge } from "./errors.ts"
+
+/** The data key that holds the token. A modal field may not use it. @internal */
+export const reservedKey = "effect"
+
+/**
+ * Bounds on what a token holds, in UTF-16 code units. `definition` bounds the
+ * UTF-8 bytes of a modal's JSON without its metadata.
+ *
+ * @internal
+ */
+export const limits = {
+  id: maxIdLength,
+  kid: 16,
+  buttonValue: 2_000,
+  metadata: 2_800,
+  text: 4_000,
+  fields: 100,
+  options: 100,
+  definition: 16_000
+} as const
+
+/** The default max length of a text input. @internal */
+export const defaultMaxLength = limits.text
+
+/** How long a dialog token is good for when the caller gives no ttl. @internal */
+export const defaultDialogTtl = Duration.hours(1)
+
+const typ = { button: "teams-button", dialog: "teams-dialog" } as const
+
+// Schemas
+
+const bounded = (max: number) => Schema.String.check(Schema.isMaxLength(max))
+const Id = bounded(limits.id)
+const Text = bounded(limits.text)
+const Hash = Schema.String.check(Schema.isBetweenLength(43, 43))
+const Length = Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: limits.text }))
+
+const SelectOption = Schema.Struct({ label: Text, value: Text })
+const Options = Schema.Array(SelectOption).check(Schema.isMaxLength(limits.options))
+
+const Definition = Schema.TaggedStruct("Modal", {
+  id: Id,
+  title: Text,
+  submitLabel: Schema.optionalKey(Text),
+  elements: Schema.Array(Schema.Union([
+    Schema.TaggedStruct("TextInput", {
+      id: Id,
+      label: Text,
+      multiline: Schema.optionalKey(Schema.Boolean),
+      placeholder: Schema.optionalKey(Text),
+      initial: Schema.optionalKey(Text),
+      optional: Schema.optionalKey(Schema.Boolean),
+      minLength: Schema.optionalKey(Length),
+      maxLength: Schema.optionalKey(Length)
+    }),
+    Schema.TaggedStruct("SelectInput", {
+      id: Id,
+      label: Text,
+      placeholder: Schema.optionalKey(Text),
+      options: Options,
+      initial: Schema.optionalKey(Text),
+      optional: Schema.optionalKey(Schema.Boolean)
+    }),
+    Schema.TaggedStruct("Text", { text: Text })
+  ])).check(Schema.isMaxLength(limits.fields))
+})
+
+const ButtonClaims = Schema.Struct({
+  aud: Id,
+  tid: Id,
+  cnv: Hash,
+  id: Id,
+  val: Schema.optionalKey(bounded(limits.buttonValue))
+})
+
+const DialogClaims = Schema.Struct({
+  aud: Id,
+  tid: Id,
+  cnv: Hash,
+  sub: Id,
+  exp: Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER })),
+  mid: Schema.optionalKey(Id),
+  def: Definition,
+  md: Schema.optionalKey(bounded(limits.metadata))
+})
+
+// Lengths
+
+const encoder = new TextEncoder()
+const utf8Length = (text: string): number => encoder.encode(text).length
+const base64Length = (bytes: number): number => Math.ceil(bytes * 4 / 3)
+/** A string of `n` code units is at most 6 bytes each in JSON, plus quotes. */
+const jsonString = (n: number): number => 6 * n + 2
+/** An HS256 signature is 32 bytes. */
+const signatureLength = base64Length(32)
+/** The conversation hash: base64url of a SHA-256 digest. */
+const hashLength = base64Length(32)
+
+const headerJson = (kid: string, type: string): string => JSON.stringify({ alg: "HS256", kid, typ: type })
+
+/**
+ * The longest token `signButton` or `signDialog` can produce. A longer value
+ * is refused before it is parsed.
+ *
+ * @internal
+ */
+export const maxTokenLength: number = (() => {
+  const header = utf8Length(headerJson("", typ.dialog)) + limits.kid
+  const button = utf8Length(JSON.stringify({ aud: "", tid: "", cnv: "", id: "", val: "" })) - 2 * 5 +
+    3 * jsonString(limits.id) + jsonString(hashLength) + jsonString(limits.buttonValue)
+  const dialog = utf8Length(JSON.stringify({ aud: "", tid: "", cnv: "", sub: "", exp: 0, mid: "", def: 0, md: "" })) -
+    2 * 6 - 2 + 4 * jsonString(limits.id) + jsonString(hashLength) + String(Number.MAX_SAFE_INTEGER).length +
+    limits.definition + jsonString(limits.metadata)
+  return base64Length(header) + 1 + base64Length(Math.max(button, dialog)) + 1 + signatureLength
+})()
+
+/** @internal */
+export interface ButtonContext {
+  readonly appId: string
+  readonly tenantId: string
+  /** The kid of the signing key. */
+  readonly kid: string
+}
+
+const buttonClaims = (
+  context: Omit,
+  cnv: string,
+  button: { readonly id: string; readonly value?: string | undefined }
+): typeof ButtonClaims.Type => ({
+  aud: context.appId,
+  tid: context.tenantId,
+  cnv,
+  id: button.id,
+  ...(button.value === undefined ? {} : { val: button.value })
+})
+
+/**
+ * The exact length of the token `signButton` produces for `button`, without
+ * signing it. The header and claims are deterministic JSON and the hash and
+ * signature have fixed lengths.
+ *
+ * @internal
+ */
+export const buttonTokenLength = (
+  context: ButtonContext,
+  button: { readonly id: string; readonly value?: string | undefined }
+): number =>
+  base64Length(utf8Length(headerJson(context.kid, typ.button))) + 1 +
+  base64Length(utf8Length(JSON.stringify(buttonClaims(context, "x".repeat(hashLength), button)))) + 1 +
+  signatureLength
+
+// Checks
+
+/** Whether a field of `modal` uses the reserved `effect` id. @internal */
+export const hasReservedField = (modal: ChatUi.Modal): boolean =>
+  modal.elements.some((element) => element._tag !== "Text" && element.id === reservedKey)
+
+const definitionOf = (modal: ChatUi.Modal): typeof Definition.Type => {
+  const { metadata: _, ...definition } = modal
+  return definition
+}
+
+const isDefinition = Schema.is(Definition)
+
+/**
+ * Why `modal` cannot go in a dialog token, if it can't: a field with the
+ * reserved id, or more than the limits allow.
+ *
+ * @internal
+ */
+export const checkModal = (modal: ChatUi.Modal): ChatErrorReason | undefined => {
+  if (hasReservedField(modal)) return invalidRequest("reserved_field_id")
+  if (modal.metadata !== undefined && modal.metadata.length > limits.metadata) {
+    return tooLarge(undefined, "modal_metadata_too_long")
+  }
+  const definition = definitionOf(modal)
+  if (!isDefinition(definition) || utf8Length(JSON.stringify(definition)) > limits.definition) {
+    return tooLarge(undefined, "modal_too_large")
+  }
+  return undefined
+}
+
+/** Why `button` cannot go in a button token, if it can't. @internal */
+export const checkButton = (
+  button: { readonly id: string; readonly value?: string | undefined }
+): ChatErrorReason | undefined =>
+  button.id.length > limits.id
+    ? tooLarge(undefined, "action_id_too_long")
+    : button.value !== undefined && button.value.length > limits.buttonValue
+    ? tooLarge(undefined, "action_data_too_long")
+    : undefined
+
+/**
+ * The values of a dialog submit, checked against the signed definition, or
+ * nothing when they don't match it.
+ *
+ * - Keys are the ids of the inputs. The reserved `effect` key is skipped.
+ * - Every value is a string. An optional input left empty has no key.
+ * - A text input is held to its `minLength` and `maxLength` (default 4,000),
+ *   and a select to its options.
+ *
+ * @internal
+ */
+export const validateSubmission = (
+  definition: ChatUi.Modal,
+  values: unknown
+): Option.Option> => {
+  if (typeof values !== "object" || values === null || Array.isArray(values)) return Option.none()
+  const input = values as Record
+  const fields = new Map()
+  for (const element of definition.elements) {
+    if (element._tag !== "Text") fields.set(element.id, element)
+  }
+  for (const key of Object.keys(input)) {
+    if (key !== reservedKey && !fields.has(key)) return Option.none()
+  }
+  const out: Record = {}
+  for (const [id, field] of fields) {
+    const value = Object.hasOwn(input, id) ? input[id] : undefined
+    if (value !== undefined && typeof value !== "string") return Option.none()
+    if (value === undefined || value === "") {
+      if (field.optional === true) continue
+      return Option.none()
+    }
+    if (field._tag === "TextInput") {
+      if (value.length < (field.minLength ?? 0) || value.length > (field.maxLength ?? defaultMaxLength)) {
+        return Option.none()
+      }
+    } else if (!field.options.some((option) => option.value === value)) {
+      return Option.none()
+    }
+    Object.defineProperty(out, id, { value, enumerable: true, writable: true, configurable: true })
+  }
+  return Option.some(out)
+}
+
+// Envelope
+
+/** @internal */
+export interface Button {
+  readonly id: string
+  readonly value?: string | undefined
+}
+
+/** @internal */
+export interface Dialog {
+  /** The message the click came from. Absent when a command opened it. */
+  readonly messageId?: string | undefined
+  readonly modal: ChatUi.Modal
+}
+
+/** @internal */
+export interface Envelope {
+  /** Fails with the reason `button` is over the limits. */
+  readonly signButton: (conversationId: string, button: Button) => Effect.Effect
+  /** The button the token was signed for, if it was signed for this conversation. */
+  readonly verifyButton: (
+    token: unknown,
+    activity: { readonly conversationId: string }
+  ) => Effect.Effect>
+  /** Fails with the reason the modal or an id is refused. */
+  readonly signDialog: (
+    conversationId: string,
+    dialog: Dialog & { readonly userId: string; readonly ttl?: Duration.Input | undefined }
+  ) => Effect.Effect
+  /** The dialog the token was signed for, if it is unexpired and for this conversation and user. */
+  readonly verifyDialog: (
+    token: unknown,
+    activity: { readonly conversationId: string; readonly userId: string }
+  ) => Effect.Effect>
+  /** `buttonTokenLength` with this envelope's app, tenant and signing key. */
+  readonly tokenLength: (button: Button) => number
+}
+
+const validKid = /^[A-Za-z0-9_-]{1,16}$/
+
+/**
+ * Builds the envelope. The first key signs, and a token is verified with the
+ * key its `kid` names. A key without a valid `kid`, a repeated `kid` or
+ * a key under 32 bytes is a defect.
+ *
+ * @internal
+ */
+export const make = Effect.fnUntraced(function*(options: {
+  readonly appId: string
+  readonly tenantId: string
+  readonly keys: NonEmptyReadonlyArray>
+}): Effect.fn.Return {
+  const keys = new Map>()
+  for (const input of options.keys) {
+    const kid = Redacted.value(input).kid
+    if (kid === undefined || !validKid.test(kid)) {
+      return yield* Effect.die(new Error("Each Teams interaction key needs a kid of 1 to 16 [A-Za-z0-9_-]"))
+    }
+    if (keys.has(kid)) return yield* Effect.die(new Error(`The Teams interaction key kid "${kid}" is repeated`))
+    keys.set(kid, yield* Effect.orDie(Jwk.importSecret(input, "HS256")))
+  }
+  const signing = keys.get(Redacted.value(options.keys[0]).kid!)!
+  const context: ButtonContext = { appId: options.appId, tenantId: options.tenantId, kid: signing.kid! }
+  const mac = yield* Mac.Mac
+  const digest = yield* Digest.Digest
+
+  const hash = (conversationId: string): Effect.Effect =>
+    Effect.map(
+      digest.digest(Digest.sha256, encoder.encode(baseConversation(conversationId))),
+      (bytes) => Base64Url.encode(bytes)
+    )
+
+  const sign = (schema: S, claims: S["Type"], type: string) =>
+    Jwt.sign(schema, claims, signing, { typ: type }).pipe(
+      Effect.map(Redacted.value),
+      Effect.provideService(Mac.Mac, mac),
+      Effect.orDie
+    )
+
+  const verify = (
+    schema: Schema.ConstraintDecoder,
+    token: unknown,
+    type: string,
+    conversationId: string,
+    policy: Jwt.VerifyOptions
+  ): Effect.Effect> => {
+    if (typeof token !== "string" || token.length > maxTokenLength) return Effect.succeedNone
+    return Effect.gen(function*() {
+      const header = (yield* Jwt.decodeUnverified(token)).protectedHeader
+      const key = header.kid === undefined ? undefined : keys.get(header.kid)
+      if (key === undefined) return Option.none()
+      const verified = yield* Jwt.verify(schema, token, key, { ...policy, audience: options.appId })
+      if (verified.protectedHeader.typ !== type) return Option.none()
+      const claims = verified.claims as A & { readonly tid: string; readonly cnv: string }
+      if (claims.tid !== options.tenantId || claims.cnv !== (yield* hash(conversationId))) return Option.none()
+      return Option.some(verified.claims)
+    }).pipe(
+      Effect.provideService(Mac.Mac, mac),
+      Effect.catch(() => Effect.succeedNone)
+    )
+  }
+
+  return {
+    signButton: (conversationId, button) => {
+      const refusal = checkButton(button)
+      if (refusal !== undefined) return Effect.fail(refusal)
+      return Effect.flatMap(
+        hash(conversationId),
+        (cnv) => sign(ButtonClaims, buttonClaims(context, cnv, button), typ.button)
+      )
+    },
+    verifyButton: (token, activity) =>
+      Effect.map(
+        verify(ButtonClaims, token, typ.button, activity.conversationId, {}),
+        Option.map((claims) => ({ id: claims.id, ...(claims.val === undefined ? {} : { value: claims.val }) }))
+      ),
+    signDialog: (conversationId, dialog) => {
+      const refusal = checkModal(dialog.modal) ??
+        (dialog.userId.length > limits.id || (dialog.messageId?.length ?? 0) > limits.id
+          ? invalidRequest("id_too_long")
+          : undefined)
+      if (refusal !== undefined) return Effect.fail(refusal)
+      return Effect.gen(function*() {
+        const now = yield* Clock.currentTimeMillis
+        const exp = Math.floor((now + Duration.toMillis(dialog.ttl ?? defaultDialogTtl)) / 1000)
+        const { metadata } = dialog.modal
+        return yield* sign(DialogClaims, {
+          aud: options.appId,
+          tid: options.tenantId,
+          cnv: yield* hash(conversationId),
+          sub: dialog.userId,
+          exp,
+          ...(dialog.messageId === undefined ? {} : { mid: dialog.messageId }),
+          def: definitionOf(dialog.modal),
+          ...(metadata === undefined ? {} : { md: metadata })
+        }, typ.dialog)
+      })
+    },
+    verifyDialog: (token, activity) =>
+      Effect.map(
+        verify(DialogClaims, token, typ.dialog, activity.conversationId, {
+          subject: activity.userId,
+          requiredClaims: ["exp", "sub"]
+        }),
+        Option.map((claims): Dialog => ({
+          ...(claims.mid === undefined ? {} : { messageId: claims.mid }),
+          modal: { ...claims.def, ...(claims.md === undefined ? {} : { metadata: claims.md }) }
+        }))
+      ),
+    tokenLength: (button) => buttonTokenLength(context, button)
+  }
+})
diff --git a/packages/chat/teams/src/internal/errors.ts b/packages/chat/teams/src/internal/errors.ts
new file mode 100644
index 00000000000..480779072af
--- /dev/null
+++ b/packages/chat/teams/src/internal/errors.ts
@@ -0,0 +1,94 @@
+import {
+  type Capability,
+  ChatError,
+  type ChatErrorReason,
+  Forbidden,
+  InvalidRequest,
+  InvalidResponse,
+  NotFound,
+  PlatformUnavailable,
+  RateLimited,
+  TooLarge,
+  Transport,
+  Unauthenticated,
+  Unknown,
+  Unsupported
+} from "effect/chat/ChatError"
+import * as Duration from "effect/Duration"
+import { platform } from "./address.ts"
+
+/**
+ * The reason for an HTTP status from the Connector. `detail` is
+ * `http_{status}`, or the Connector's error `code` when it sent one, which
+ * holds no message text or ids.
+ *
+ * @internal
+ */
+export const reasonForStatus = (
+  status: number,
+  options: {
+    readonly write: boolean
+    readonly code?: string | undefined
+    readonly retryAfter?: Duration.Duration | undefined
+    readonly cause?: unknown
+  }
+): ChatErrorReason => {
+  const detail = options.code !== undefined && /^[A-Za-z0-9_.-]{1,64}$/.test(options.code)
+    ? options.code
+    : `http_${status}`
+  const cause = options.cause === undefined ? {} : { cause: options.cause }
+  if (status === 429) {
+    return new RateLimited({
+      detail,
+      ...cause,
+      ...(options.retryAfter === undefined ? {} : { retryAfter: options.retryAfter })
+    })
+  }
+  if (status >= 500) return new PlatformUnavailable({ retry: options.write ? "uncertain" : "retry", detail, ...cause })
+  if (status === 401) return new Unauthenticated({ detail, ...cause })
+  if (status === 403) return new Forbidden({ detail, ...cause })
+  if (status === 404) return new NotFound({ detail, ...cause })
+  if (status === 413) return new TooLarge({ detail, ...cause })
+  return new InvalidRequest({ detail, ...cause })
+}
+
+/** A request that failed before an answer came. @internal */
+export const transport = (write: boolean, detail: string, cause?: unknown): ChatErrorReason =>
+  new Transport({ retry: write ? "uncertain" : "retry", detail, ...(cause === undefined ? {} : { cause }) })
+
+/** An answer the adapter cannot read. A write may have landed. @internal */
+export const invalidResponse = (write: boolean, detail: string, cause?: unknown): ChatErrorReason => {
+  const fields = { detail, ...(cause === undefined ? {} : { cause }) }
+  return write ? new Unknown(fields) : new InvalidResponse(fields)
+}
+
+/** @internal */
+export const parseRetryAfter = (value: string | undefined): Duration.Duration | undefined => {
+  if (value === undefined) return undefined
+  const seconds = Number(value)
+  return Number.isFinite(seconds) && seconds >= 0 ? Duration.seconds(seconds) : undefined
+}
+
+/** @internal */
+export const chatError = (op: string, reason: ChatErrorReason): ChatError => new ChatError({ platform, op, reason })
+
+/** @internal */
+export const withOp = (op: string) => (error: ChatError): ChatError =>
+  error.op === op ? error : new ChatError({ platform: error.platform, op, reason: error.reason })
+
+/** @internal */
+export const invalidRequest = (detail: string): ChatErrorReason => new InvalidRequest({ detail })
+
+/** @internal */
+export const notFound = (detail: string): ChatErrorReason => new NotFound({ detail })
+
+/** @internal */
+export const unsupported = (capability: Capability, detail?: string): ChatErrorReason =>
+  new Unsupported({ capability, ...(detail === undefined ? {} : { detail }) })
+
+/** @internal */
+export const tooLarge = (subject: "text" | "files" | undefined, detail: string): ChatErrorReason =>
+  new TooLarge({ ...(subject === undefined ? {} : { subject }), detail })
+
+/** A URL outside the adapter's allowlists. Its host is the only part kept. @internal */
+export const untrustedUrl = (): ChatErrorReason => new Forbidden({ detail: "untrusted_url" })
diff --git a/packages/chat/teams/src/internal/interactions.ts b/packages/chat/teams/src/internal/interactions.ts
new file mode 100644
index 00000000000..c2da0365bdc
--- /dev/null
+++ b/packages/chat/teams/src/internal/interactions.ts
@@ -0,0 +1,294 @@
+import type { Capability, ChatError } from "effect/chat/ChatError"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type { ChatThread } from "effect/chat/ChatThread"
+import type * as ChatUi from "effect/chat/ChatUi"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Option from "effect/Option"
+import * as Schema from "effect/Schema"
+import type { Made } from "./adapter.ts"
+import { modalFields, modalMetadataLength } from "./adapter.ts"
+import * as Address from "./address.ts"
+import * as Envelope from "./envelope.ts"
+import * as Errors from "./errors.ts"
+import { isObject, object, string, threadOf, userId } from "./normalize.ts"
+import * as Render from "./render.ts"
+
+type JsonObject = { readonly [key: string]: Schema.Json }
+
+/** The default share of Teams' invoke timeout the handler gets. @internal */
+export const defaultDeadline = Duration.seconds(4)
+
+/** An answer to an invoke: the HTTP status and the JSON body, if any. @internal */
+export interface InvokeResponse {
+  readonly status: number
+  readonly body?: Schema.Json | undefined
+}
+
+const isLate = Schema.is(ChatInteraction.Late)
+
+const ok: InvokeResponse = { status: 200 }
+
+/** What an invoke that fails a check gets. It names no reason. */
+const safeFailure = (name: string): InvokeResponse =>
+  name === "adaptiveCard/action"
+    ? {
+      status: 200,
+      body: {
+        statusCode: 400,
+        type: "application/vnd.microsoft.error",
+        value: { code: "BadRequest", message: "This action could not be completed." }
+      }
+    }
+    : { status: 200, body: { task: { type: "message", value: "This action could not be completed." } } }
+
+const executeAck: InvokeResponse = {
+  status: 200,
+  body: { statusCode: 200, type: "application/vnd.microsoft.activity.message", value: "" }
+}
+
+/** @internal */
+export interface Options {
+  readonly capabilities: ReadonlySet
+  readonly envelope: Envelope.Envelope | undefined
+  /** The ids of the buttons that open a dialog. */
+  readonly modalButtons: ReadonlySet
+  readonly answer: Made["answer"]
+  readonly deadline: Duration.Duration
+}
+
+const refused = (event: ChatInteraction.ButtonClicked | ChatInteraction.CommandInvoked, error: ChatError) =>
+  Effect.flatMap(ChatInteraction.Handler, (handler) => handler.refused(event, error))
+
+/**
+ * Where the message an invoke came from lives. A card posted as a channel
+ * post has the channel as its address, as `normalize` gives it.
+ */
+const cardThread = (activity: JsonObject): ChatThread | undefined => {
+  const conversationId = string(object(activity, "conversation"), "id")
+  const messageId = string(activity, "replyToId")
+  if (conversationId === undefined || conversationId.length > Address.maxIdLength) return undefined
+  const parts = Address.parts(Address.thread(conversationId))
+  if (Option.isNone(parts)) return undefined
+  return parts.value.root !== undefined && parts.value.root === messageId
+    ? Address.thread(parts.value.base)
+    : Address.thread(conversationId)
+}
+
+/** The adaptive card of a dialog, built only from the signed definition. */
+const dialogCard = (modal: ChatUi.Modal, token: string, errors?: Readonly>) => {
+  const body: Array = []
+  for (const element of modal.elements) {
+    if (element._tag === "Text") {
+      body.push(Render.textBlock(Render.escapeText(Render.wellFormed(element.text))))
+      continue
+    }
+    if (element._tag === "TextInput") {
+      body.push({
+        type: "Input.Text",
+        id: element.id,
+        label: element.label,
+        isMultiline: element.multiline === true,
+        isRequired: element.optional !== true,
+        maxLength: element.maxLength ?? Envelope.defaultMaxLength,
+        ...(element.placeholder === undefined ? {} : { placeholder: element.placeholder }),
+        ...(element.initial === undefined ? {} : { value: element.initial })
+      })
+    } else {
+      body.push({
+        type: "Input.ChoiceSet",
+        id: element.id,
+        label: element.label,
+        style: "compact",
+        isRequired: element.optional !== true,
+        choices: element.options.map((option) => ({ title: option.label, value: option.value })),
+        ...(element.placeholder === undefined ? {} : { placeholder: element.placeholder }),
+        ...(element.initial === undefined ? {} : { value: element.initial })
+      })
+    }
+    const error = errors?.[element.id]
+    if (error !== undefined) {
+      body.push({ ...Render.textBlock(Render.escapeText(Render.wellFormed(error))), color: "attention" })
+    }
+  }
+  return {
+    task: {
+      type: "continue",
+      value: {
+        title: modal.title,
+        card: {
+          contentType: Render.cardContentType,
+          content: {
+            ...Render.card(body),
+            actions: [{
+              type: "Action.Submit",
+              title: modal.submitLabel ?? "Submit",
+              data: { [Envelope.reservedKey]: token }
+            }]
+          }
+        }
+      }
+    }
+  }
+}
+
+const modalRefusal = (modal: ChatUi.Modal) => {
+  const fields = modal.elements.length
+  if (fields > modalFields) return Errors.tooLarge(undefined, "too_many_modal_fields")
+  if (modal.id.length + (modal.metadata?.length ?? 0) > modalMetadataLength) {
+    return Errors.tooLarge(undefined, "modal_metadata_too_long")
+  }
+  return Envelope.checkModal(modal)
+}
+
+/**
+ * One verified invoke, or a card's `Action.Submit` fallback, which comes as
+ * a `message` with a `value`.
+ *
+ * - `adaptiveCard/action` and the fallback are clicks. A click can't open
+ *   a dialog there: an `OpenModal` goes to `Handler.refused` as
+ *   `Unsupported`.
+ * - `task/fetch` is a click on a button named in `modalButtons`, whose
+ *   `OpenModal` opens the dialog, signed for the clicking user.
+ * - `task/submit` is a dialog submit, checked against its signed
+ *   definition.
+ * - A token that does not verify, or values that do not match the
+ *   definition, get the safe failure and dispatch nothing.
+ *
+ * @internal
+ */
+export const invoke = (
+  activity: JsonObject,
+  options: Options
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const name = activity.type === "message" ? "message" : string(activity, "name") ?? ""
+    const failure = safeFailure(name)
+    const envelope = options.envelope
+    if (envelope === undefined || !options.capabilities.has("buttons")) return failure
+    const conversationId = string(object(activity, "conversation"), "id")
+    const from = object(activity, "from")
+    const user = from === undefined ? undefined : userId(from)
+    if (conversationId === undefined || user === undefined) return failure
+    const value = object(activity, "value")
+    const data = name === "adaptiveCard/action"
+      ? object(object(value, "action"), "data")
+      : name === "message"
+      ? value
+      : object(value, "data")
+    const token = data?.[Envelope.reservedKey]
+
+    if (name === "task/submit") {
+      if (!options.capabilities.has("modals")) return failure
+      const dialog = yield* envelope.verifyDialog(token, { conversationId, userId: user })
+      if (Option.isNone(dialog)) return failure
+      const values = Envelope.validateSubmission(dialog.value.modal, data)
+      const at = threadOf(activity)
+      if (Option.isNone(values) || at === undefined) return failure
+      const modal = dialog.value.modal
+      const event = ChatInteraction.ModalSubmitted.make({
+        id: modal.id,
+        ...(modal.metadata === undefined ? {} : { metadata: modal.metadata }),
+        values: values.value,
+        thread: at.thread,
+        ...(dialog.value.messageId === undefined ? {} : { messageId: dialog.value.messageId }),
+        userId: user,
+        raw: activity
+      })
+      const reply = yield* ChatInteraction.handle(event, options.deadline)
+      if (isLate(reply)) return failure
+      if (reply._tag === "Errors") {
+        return { status: 200, body: dialogCard(modal, token as string, reply.errors) as Schema.Json }
+      }
+      return ok
+    }
+
+    if (name !== "adaptiveCard/action" && name !== "message" && name !== "task/fetch") return failure
+    const button = yield* envelope.verifyButton(token, { conversationId })
+    const thread = cardThread(activity)
+    const messageId = string(activity, "replyToId")
+    if (Option.isNone(button) || thread === undefined || messageId === undefined) return failure
+    const opensDialog = name === "task/fetch"
+    if (opensDialog !== options.modalButtons.has(button.value.id)) return failure
+    const event = ChatInteraction.ButtonClicked.make({
+      id: button.value.id,
+      ...(button.value.value === undefined ? {} : { value: button.value.value }),
+      thread,
+      messageId,
+      userId: user,
+      raw: activity
+    })
+    const reply = yield* ChatInteraction.handle(event, options.deadline)
+    const acked = name === "adaptiveCard/action" ? executeAck : name === "message" ? ok : failure
+    if (isLate(reply) || reply._tag === "Ack") return acked
+    if (!opensDialog || !options.capabilities.has("modals")) {
+      yield* refused(event, Errors.chatError("openModal", Errors.unsupported("modals")))
+      return acked
+    }
+    const refusal = modalRefusal(reply.modal)
+    if (refusal !== undefined) {
+      yield* refused(event, Errors.chatError("openModal", refusal))
+      return failure
+    }
+    const signed = yield* Effect.result(
+      envelope.signDialog(conversationId, { userId: user, messageId, modal: reply.modal })
+    )
+    if (signed._tag === "Failure") {
+      yield* refused(event, Errors.chatError("openModal", signed.failure))
+      return failure
+    }
+    return { status: 200, body: dialogCard(reply.modal, signed.success) as Schema.Json }
+  })
+
+/** Leading `…` tokens, spaces and one slash, before a command's name. */
+const commandPrefix = /^(?:\s|[^<]*<\/at>)*\/?/
+
+/**
+ * A verified targeted message. Its first word names the command, and the
+ * rest is the command's `text`. A message whose first word names no
+ * registered command is acked and nothing is sent. Nothing here ever
+ * reaches `ChatHandler` or posts in public unless the handler asks.
+ *
+ * @internal
+ */
+export const command = (
+  activity: JsonObject,
+  options: Options & { readonly isRegistered: (id: string) => Effect.Effect }
+): Effect.Effect =>
+  Effect.gen(function*() {
+    if (!options.capabilities.has("commands")) return
+    const text = typeof activity.text === "string" ? activity.text : ""
+    const rest = text.replace(commandPrefix, "")
+    const match = /^(\S+)\s*([\s\S]*)$/.exec(rest)
+    const from = object(activity, "from")
+    const user = from === undefined ? undefined : userId(from)
+    const at = threadOf(activity)
+    if (match === null || user === undefined || at === undefined) return
+    const id = match[1]
+    if (!(yield* options.isRegistered(id))) return
+    const event = ChatInteraction.CommandInvoked.make({
+      id,
+      text: match[2],
+      thread: at.thread,
+      userId: user,
+      raw: activity
+    })
+    const reply = yield* ChatInteraction.handle(event, options.deadline)
+    if (isLate(reply)) return
+    switch (reply._tag) {
+      case "Ack":
+      case "Defer":
+        return
+      case "OpenModal":
+        return yield* refused(event, Errors.chatError("openModal", Errors.unsupported("modals")))
+      case "Respond":
+        return yield* options.answer("respond", activity, {
+          markdown: reply.markdown,
+          ...(reply.actions === undefined ? {} : { actions: reply.actions })
+        }, reply.visibility).pipe(Effect.catch((error) => refused(event, error)))
+    }
+  })
+
+/** Whether a `message` is a card's `Action.Submit` fallback. @internal */
+export const isSubmitFallback = (activity: JsonObject): boolean =>
+  activity.type === "message" && isObject(activity.value) && Envelope.reservedKey in activity.value
diff --git a/packages/chat/teams/src/internal/length.ts b/packages/chat/teams/src/internal/length.ts
new file mode 100644
index 00000000000..bd875764012
--- /dev/null
+++ b/packages/chat/teams/src/internal/length.ts
@@ -0,0 +1,170 @@
+/**
+ * What a message costs against the Connector's limit, counted in UTF-16
+ * units of `JSON.stringify(activity)`, the serialised activity body.
+ *
+ * Every fixed size here comes from serialising the templates in
+ * `render.ts`, so the numbers follow the renderer.
+ */
+import type { Action } from "effect/chat/ChatUi"
+import { maxIdLength } from "./address.ts"
+import * as Render from "./render.ts"
+
+const size = (value: unknown): number => JSON.stringify(value).length
+
+/** An element in an array, with the comma before or after it. */
+const element = (value: unknown): number => size(value) + 1
+
+/**
+ * The size of a serialised activity body the Connector takes, in UTF-16
+ * units.
+ *
+ * Provisional: Microsoft documents no exact number, and this is not verified
+ * against the Connector yet.
+ *
+ * @internal
+ */
+export const Edge = 50_000
+
+/** The text form with empty `text`. @internal */
+export const S = size(Render.textActivity(""))
+
+/** The card form with an empty card body. @internal */
+export const T = size(Render.cardActivityOf([]))
+
+/** One table cell and its column definition. @internal */
+export const K = element(Render.tableCell("")) + element(Render.column)
+
+/**
+ * The largest element group a source line can add: a `TextBlock`, a
+ * `CodeBlock` (with `PlainText` as its language), or a `Table` with one
+ * row of one cell, which is also more than a new row of one cell.
+ *
+ * @internal
+ */
+export const E = Math.max(
+  element(Render.textBlock("")),
+  element(Render.codeBlock("", "PlainText")),
+  element(Render.table([[""]]))
+)
+
+const id = "x".repeat(maxIdLength)
+
+/**
+ * The members the adapter may add to an activity besides what the renderer
+ * gives, each id at `maxIdLength`: `replyToId`, `recipient`, and
+ * `entities` holding a `streaminfo` entity, the AI-generated label and a
+ * `targetedMessageInfo` entity. Ids are sent without JSON escapes.
+ *
+ * @internal
+ */
+export const A = size({
+  replyToId: id,
+  recipient: { id },
+  entities: [
+    { type: "streaminfo", streamId: id, streamType: "informative", streamSequence: Number.MAX_SAFE_INTEGER },
+    {
+      type: "https://schema.org/Message",
+      "@type": "Message",
+      "@context": "https://schema.org",
+      "@id": "",
+      additionalType: ["AIGeneratedContent"]
+    },
+    { type: "targetedMessageInfo", messageId: id }
+  ]
+}) - 1
+
+/**
+ * Units set aside for mention entities.
+ *
+ * Provisional: the adapter does not send mentions in v1.
+ *
+ * @internal
+ */
+export const M_units = 4_000
+
+/** Units set aside for file attachments: none, files are not sent in v1. @internal */
+export const F_units = 0
+
+/**
+ * The fixed part of a message: the larger of the two forms with the first
+ * element of the card. The first source line has no line break before it to
+ * pay for its element, so `E` is reserved once for it.
+ *
+ * @internal
+ */
+export const skeleton = Math.max(S, T + E)
+
+/** @internal */
+export const R = skeleton + A + M_units + F_units
+
+/** @internal */
+export const messageLength = Edge - R
+
+/**
+ * What one UTF-16 unit of the source can cost once rendered and serialised.
+ * A line break pays for the element its line may start, and a pipe for the
+ * table cell and column it may add.
+ */
+const unit = (code: number): number => {
+  switch (code) {
+    case 0x0a:
+    case 0x0d:
+      return 2 + E
+    case 0x7c:
+      return 1 + K
+    case 0x22:
+    case 0x5c:
+    case 0x09:
+      return 2
+    case 0x24:
+      return 3
+    case 0x3c:
+      return 4
+    case 0x26:
+      return 5
+    default:
+      return code < 0x20 ? 6 : 1
+  }
+}
+
+/** @internal */
+export const weight = (text: string): number => {
+  let total = 0
+  for (let i = 0; i < text.length; i++) total += unit(text.charCodeAt(i))
+  return total
+}
+
+const row = element(Render.actionSet([]))
+
+/** @internal */
+export type TokenLength = (button: { readonly id: string; readonly value?: string | undefined }) => number
+
+const actionCost = (action: Action, tokenLength: TokenLength): number => {
+  switch (action._tag) {
+    case "Button":
+      return element(Render.buttonAction({ ...action, label: "" }, "")) + 2 * weight(action.label) +
+        2 * tokenLength(action) + row
+    case "LinkButton":
+      return element(Render.linkAction({ ...action, label: "", url: "" })) + weight(action.label) +
+        weight(action.url) + row
+    case "Select":
+      // The adapter refuses a select before it renders anything.
+      return 0
+  }
+}
+
+/**
+ * The descriptor's `measure`: the weight of each unit of the Markdown plus
+ * the cost of each action, where a button's cost holds its token twice (the
+ * action and its fallback) at `tokenLength`, and each action pays for a
+ * whole `ActionSet` row. With `R` added it is never less than the size of
+ * either form of the activity.
+ *
+ * @internal
+ */
+export const makeMeasure =
+  (tokenLength: TokenLength) => (markdown: string, actions?: ReadonlyArray): number => {
+    let total = weight(markdown)
+    for (const action of actions ?? []) total += actionCost(action, tokenLength)
+    return total
+  }
diff --git a/packages/chat/teams/src/internal/normalize.ts b/packages/chat/teams/src/internal/normalize.ts
new file mode 100644
index 00000000000..34ad72f0001
--- /dev/null
+++ b/packages/chat/teams/src/internal/normalize.ts
@@ -0,0 +1,248 @@
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import type * as ChatMessage from "effect/chat/ChatMessage"
+import type * as ChatThread from "effect/chat/ChatThread"
+import * as DateTime from "effect/DateTime"
+import * as Option from "effect/Option"
+import type * as Schema from "effect/Schema"
+import * as Address from "./address.ts"
+import * as Download from "./download.ts"
+
+type JsonObject = { readonly [key: string]: Schema.Json }
+
+/** @internal */
+export const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/** @internal */
+export const string = (object: JsonObject | undefined, key: string): string | undefined => {
+  const value = object?.[key]
+  return typeof value === "string" && value.length > 0 ? value : undefined
+}
+
+/** @internal */
+export const object = (object: JsonObject | undefined, key: string): JsonObject | undefined => {
+  const value = object?.[key]
+  return isObject(value) ? value : undefined
+}
+
+/** @internal */
+export interface Context {
+  readonly appId: string
+  readonly connectorHosts: ReadonlySet
+  readonly fileHostSuffixes: ReadonlyArray
+}
+
+/** The bot's own Connector id. @internal */
+export const botId = (appId: string): string => `28:${appId}`
+
+/**
+ * The public id of a user: the Entra object id for a person, the Connector
+ * id (`29:…`, `28:…`) for a bot or anyone without one.
+ *
+ * @internal
+ */
+export const userId = (account: JsonObject): string | undefined =>
+  string(account, "aadObjectId") ?? string(account, "id")
+
+/**
+ * Whether the activity was sent to the bot alone, as a targeted message.
+ * Read from `recipient.isTargeted`.
+ *
+ * @internal
+ */
+export const isTargeted = (activity: JsonObject): boolean => object(activity, "recipient")?.isTargeted === true
+
+/**
+ * Where an activity's message lives, and what kind of address it is. A
+ * channel post's conversation names the post itself as its reply chain
+ * root: such a post is addressed to the channel, and is the opener of the
+ * thread under it.
+ *
+ * @internal
+ */
+export const threadOf = (
+  activity: JsonObject
+): { readonly thread: ChatThread.ChatThread; readonly kind: ChatEvent.ThreadKind } | undefined => {
+  const conversationId = string(object(activity, "conversation"), "id")
+  if (conversationId === undefined || conversationId.length > Address.maxIdLength) return undefined
+  const parts = Address.parts(Address.thread(conversationId))
+  if (Option.isNone(parts)) return undefined
+  const id = string(activity, "id")
+  if (parts.value.root !== undefined && parts.value.root === id) {
+    return { thread: Address.thread(parts.value.base), kind: "channel" }
+  }
+  const conversationType = string(object(activity, "conversation"), "conversationType")
+  return {
+    thread: Address.thread(conversationId),
+    kind: parts.value.root !== undefined ? "thread" : conversationType === "personal" ? "direct" : "channel"
+  }
+}
+
+const timestamp = (activity: JsonObject): DateTime.Utc | undefined => {
+  const value = string(activity, "timestamp")
+  if (value === undefined) return undefined
+  return Option.getOrUndefined(DateTime.make(value).pipe(Option.map(DateTime.toUtc)))
+}
+
+const mentionKind = (mentioned: JsonObject, conversationId: string): ChatMessage.Mention["kind"] => {
+  if (string(mentioned, "type") === "tag") return "role"
+  const id = string(mentioned, "id") ?? ""
+  if (id === Address.baseConversation(conversationId) || id.startsWith("19:")) return "channel"
+  return "user"
+}
+
+/**
+ * The mention entities, in order, located in `text` by their `` text.
+ * An entity whose text is not found is left out.
+ */
+const mentions = (activity: JsonObject, text: string, self: string): Array => {
+  const entities = activity.entities
+  if (!Array.isArray(entities)) return []
+  const conversationId = string(object(activity, "conversation"), "id") ?? ""
+  const out: Array = []
+  let from = 0
+  for (const entity of entities) {
+    if (!isObject(entity) || entity.type !== "mention") continue
+    const mentioned = object(entity, "mentioned")
+    const token = string(entity, "text")
+    const id = mentioned === undefined ? undefined : userId(mentioned)
+    if (mentioned === undefined || token === undefined || id === undefined) continue
+    const start = text.indexOf(token, from)
+    if (start === -1) continue
+    from = start + token.length
+    out.push({
+      kind: mentionKind(mentioned, conversationId),
+      id,
+      start,
+      end: start + token.length,
+      isSelf: string(mentioned, "id") === self
+    })
+  }
+  return out
+}
+
+const attachments = (activity: JsonObject, context: Context): Array => {
+  const list = activity.attachments
+  const serviceUrl = string(activity, "serviceUrl")
+  if (!Array.isArray(list) || serviceUrl === undefined) return []
+  const conversationType = string(object(activity, "conversation"), "conversationType")
+  const out: Array = []
+  for (const attachment of list) {
+    if (isObject(attachment) && attachment.contentType === "text/html") continue
+    const classified = Download.classify(attachment, {
+      serviceUrl,
+      ...(conversationType === undefined ? {} : { conversationType }),
+      connectorHosts: context.connectorHosts,
+      fileHostSuffixes: context.fileHostSuffixes
+    })
+    if (classified !== undefined) out.push(classified)
+  }
+  return out
+}
+
+/**
+ * A `message` activity as a `ChatMessage`.
+ *
+ * - `text` is Teams' `text` as delivered, with `…` for each
+ *   mention, which is where `mentions` point.
+ * - The author id follows `userId`. `raw` keeps the Connector id.
+ *
+ * @internal
+ */
+export const message = (activity: JsonObject, context: Context): ChatMessage.ChatMessage | undefined => {
+  const id = string(activity, "id")
+  const from = object(activity, "from")
+  const author = from === undefined ? undefined : userId(from)
+  const at = threadOf(activity)
+  const time = timestamp(activity)
+  if (id === undefined || from === undefined || author === undefined || at === undefined || time === undefined) {
+    return undefined
+  }
+  const self = botId(context.appId)
+  const connectorId = string(from, "id") ?? ""
+  const text = typeof activity.text === "string" ? activity.text : ""
+  const name = string(from, "name")
+  return {
+    id,
+    thread: at.thread,
+    author: {
+      id: author,
+      ...(name === undefined ? {} : { name }),
+      isBot: connectorId.startsWith("28:"),
+      isSelf: connectorId === self
+    },
+    text,
+    mentions: mentions(activity, text, self),
+    attachments: attachments(activity, context),
+    timestamp: time,
+    raw: activity
+  }
+}
+
+const reactionEmoji: Readonly> = {
+  like: "\u{1F44D}",
+  heart: "\u2764\uFE0F",
+  laugh: "\u{1F606}",
+  surprised: "\u{1F62E}",
+  sad: "\u{1F622}",
+  angry: "\u{1F621}"
+}
+
+/**
+ * A Teams reaction type as an emoji: the six documented types as Unicode,
+ * any other as `custom:{type}`.
+ *
+ * @internal
+ */
+export const emoji = (type: string): string => reactionEmoji[type] ?? `custom:${type}`
+
+const reactions = (activity: JsonObject): Array => {
+  const messageId = string(activity, "replyToId")
+  const from = object(activity, "from")
+  const user = from === undefined ? undefined : userId(from)
+  const at = threadOf(activity)
+  if (messageId === undefined || user === undefined || at === undefined) return []
+  const time = timestamp(activity)
+  const out: Array = []
+  for (const [key, tag] of [["reactionsAdded", "ReactionAdded"], ["reactionsRemoved", "ReactionRemoved"]] as const) {
+    const list = activity[key]
+    if (!Array.isArray(list)) continue
+    for (const reaction of list) {
+      const type = isObject(reaction) ? string(reaction, "type") : undefined
+      if (type === undefined) continue
+      out.push({
+        _tag: tag,
+        thread: at.thread,
+        messageId,
+        userId: user,
+        emoji: emoji(type),
+        ...(time === undefined ? {} : { timestamp: time }),
+        raw: activity
+      })
+    }
+  }
+  return out
+}
+
+/**
+ * A verified, untargeted activity as zero or more events. A `message`
+ * carrying a card submit (`value`) is an interaction, not a message, and
+ * gives none here.
+ *
+ * @internal
+ */
+export const normalize = (activity: unknown, context: Context): ReadonlyArray => {
+  if (!isObject(activity) || isTargeted(activity)) return []
+  switch (activity.type) {
+    case "message": {
+      if (activity.value !== undefined) return []
+      const at = threadOf(activity)
+      const created = message(activity, context)
+      if (at === undefined || created === undefined) return []
+      return [{ _tag: "MessageCreated", thread: at.thread, kind: at.kind, message: created, raw: activity }]
+    }
+    case "messageReaction":
+      return reactions(activity)
+    default:
+      return []
+  }
+}
diff --git a/packages/chat/teams/src/internal/render.ts b/packages/chat/teams/src/internal/render.ts
new file mode 100644
index 00000000000..f19e77f8d70
--- /dev/null
+++ b/packages/chat/teams/src/internal/render.ts
@@ -0,0 +1,242 @@
+/**
+ * Renders Markdown as a Bot Framework activity for Teams. A message is sent
+ * in one of two forms, never mixed: text, when it has no actions, and an
+ * Adaptive Card, when it has.
+ *
+ * The renderer keeps to the rules that make `Length.measure` an upper
+ * bound: a source line gives at most one element, a table row has at most
+ * one cell more than it has pipes, each source unit is sent at most once,
+ * and nothing is sent beyond the templates below and the source text.
+ */
+import type { Action, Button, LinkButton } from "effect/chat/ChatUi"
+
+/** @internal */
+export const cardContentType = "application/vnd.microsoft.card.adaptive"
+
+/**
+ * The most actions in one `ActionSet` row: the number of actions Teams
+ * shows in a row before it moves the rest into an overflow menu.
+ *
+ * @internal
+ */
+export const actionsPerRow = 6
+
+/** Lone surrogates become U+FFFD, which JSON sends as one unit. @internal */
+export const wellFormed = (text: string): string =>
+  text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?` mention or entity
+ * forms in text Teams reads as Markdown.
+ *
+ * @internal
+ */
+export const escapeText = (text: string): string => text.replace(/[<&]/g, (c) => c === "<" ? "<" : "&")
+
+/** @internal */
+export const textActivity = (markdown: string): Record => ({
+  type: "message",
+  text: escapeText(wellFormed(markdown)),
+  textFormat: "extendedmarkdown"
+})
+
+/** @internal */
+export const textBlock = (text: string) => ({ type: "TextBlock", text, wrap: true })
+
+/** @internal */
+export const codeBlock = (codeSnippet: string, language: string) => ({ type: "CodeBlock", codeSnippet, language })
+
+/** @internal */
+export const column = { width: 1 }
+
+/** @internal */
+export const tableCell = (text: string) => ({ type: "TableCell", items: [textBlock(text)] })
+
+/** @internal */
+export const tableRow = (cells: ReadonlyArray) => ({ type: "TableRow", cells: cells.map(tableCell) })
+
+/** A table with one column for each cell of its widest row. @internal */
+export const table = (rows: ReadonlyArray>) => ({
+  type: "Table",
+  firstRowAsHeaders: true,
+  columns: Array.from({ length: Math.max(0, ...rows.map((row) => row.length)) }, () => column),
+  rows: rows.map(tableRow)
+})
+
+/** @internal */
+export const actionSet = (actions: ReadonlyArray) => ({ type: "ActionSet", actions })
+
+/** @internal */
+export const card = (body: ReadonlyArray) => ({
+  type: "AdaptiveCard",
+  version: "1.5",
+  body,
+  msteams: { width: "Full" }
+})
+
+/** @internal */
+export const cardActivityOf = (body: ReadonlyArray): Record => ({
+  type: "message",
+  attachments: [{ contentType: cardContentType, content: card(body) }]
+})
+
+const styles = { primary: "positive", danger: "destructive" } as const
+
+/**
+ * `Action.Execute`, with `Action.Submit` as the fallback for clients
+ * without Universal Actions. `token` carries the button's id and value.
+ *
+ * @internal
+ */
+export const buttonAction = (button: Button, token: string) => {
+  const title = wellFormed(button.label)
+  const style = button.style === "primary" || button.style === "danger" ? { style: styles[button.style] } : {}
+  return {
+    type: "Action.Execute",
+    title,
+    verb: "effect",
+    data: { effect: token },
+    ...style,
+    fallback: { type: "Action.Submit", title, data: { effect: token } }
+  }
+}
+
+/** @internal */
+export const linkAction = (link: LinkButton) => ({
+  type: "Action.OpenUrl",
+  title: wellFormed(link.label),
+  url: wellFormed(link.url)
+})
+
+/**
+ * The card form. Selects are not rendered: the adapter refuses them first.
+ *
+ * @internal
+ */
+export const cardActivity = (
+  markdown: string,
+  actions: ReadonlyArray,
+  encode: (button: Button) => string
+): Record => {
+  const body: Array = blocks(markdown)
+  const rendered: Array = []
+  for (const action of actions) {
+    if (action._tag === "Button") rendered.push(buttonAction(action, encode(action)))
+    else if (action._tag === "LinkButton") rendered.push(linkAction(action))
+  }
+  for (let i = 0; i < rendered.length; i += actionsPerRow) {
+    body.push(actionSet(rendered.slice(i, i + actionsPerRow)))
+  }
+  return cardActivityOf(body)
+}
+
+interface Fence {
+  readonly marker: string
+  readonly language: string
+}
+
+const fenceOpen = (line: string): Fence | undefined => {
+  const match = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line)
+  if (match === null) return undefined
+  const [, marker, info] = match
+  if (marker[0] === "`" && info.includes("`")) return undefined
+  const word = info.trim().split(/\s+/)[0]
+  return { marker, language: word === "" ? "PlainText" : word }
+}
+
+const fenceCloses = (fence: Fence, line: string): boolean => {
+  const match = /^ {0,3}(`{3,}|~{3,})[ \t]*$/.exec(line)
+  return match !== null && match[1][0] === fence.marker[0] && match[1].length >= fence.marker.length
+}
+
+const delimiterRow = /^[ \t]*\|?(?:[ \t]*:?-+:?[ \t]*\|)*[ \t]*:?-+:?[ \t]*\|?[ \t]*$/
+
+const isDelimiter = (line: string): boolean => line.includes("|") && delimiterRow.test(line)
+
+/** The cells of a table row. There are never more than its pipes plus one. */
+const cells = (line: string): Array => {
+  let row = line.trim()
+  if (row.startsWith("|")) row = row.slice(1)
+  if (row.endsWith("|") && !row.endsWith("\\|")) row = row.slice(0, -1)
+  return row.split(/(? escapeText(cell.trim().replace(/\\\|/g, "|")))
+}
+
+/**
+ * One line of a paragraph, with the block syntax a TextBlock cannot show
+ * taken off: quote markers and heading markers are dropped, and the first
+ * list marker is kept. `> - # x` becomes `- x`.
+ */
+const flatten = (line: string): string => {
+  let rest = line
+  let marker = ""
+  for (;;) {
+    const quote = /^ {0,3}> ?/.exec(rest)
+    if (quote !== null) {
+      rest = rest.slice(quote[0].length)
+      continue
+    }
+    if (marker === "") {
+      const list = /^[ \t]*(?:[-*+]|\d{1,9}[.)])(?:[ \t]+|$)/.exec(rest)
+      if (list !== null) {
+        marker = list[0]
+        rest = rest.slice(marker.length)
+        continue
+      }
+    }
+    const heading = /^ {0,3}#{1,6}(?:[ \t]+|$)/.exec(rest)
+    if (heading !== null) {
+      rest = rest.slice(heading[0].length)
+      continue
+    }
+    return marker + rest
+  }
+}
+
+/**
+ * The card body for Markdown: `TextBlock`, `CodeBlock` and `Table`
+ * elements in the order of the source. Consecutive lines of text share one
+ * `TextBlock`, joined by `\n`.
+ *
+ * @internal
+ */
+export const blocks = (markdown: string): Array => {
+  const lines = wellFormed(markdown).split(/\r\n|\r|\n/)
+  const body: Array = []
+  let text: Array = []
+  const flush = () => {
+    let start = 0
+    let end = text.length
+    while (start < end && text[start].trim() === "") start++
+    while (end > start && text[end - 1].trim() === "") end--
+    if (start < end) body.push(textBlock(escapeText(text.slice(start, end).join("\n"))))
+    text = []
+  }
+  let i = 0
+  while (i < lines.length) {
+    const line = lines[i]
+    const fence = fenceOpen(line)
+    if (fence !== undefined) {
+      flush()
+      const code: Array = []
+      i++
+      while (i < lines.length && !fenceCloses(fence, lines[i])) code.push(lines[i++])
+      i++
+      body.push(codeBlock(code.join("\n"), fence.language))
+      continue
+    }
+    if (line.includes("|") && i + 1 < lines.length && isDelimiter(lines[i + 1])) {
+      flush()
+      const rows = [cells(line)]
+      i += 2
+      while (i < lines.length && lines[i].includes("|") && fenceOpen(lines[i]) === undefined) {
+        rows.push(cells(lines[i++]))
+      }
+      body.push(table(rows))
+      continue
+    }
+    text.push(flatten(line))
+    i++
+  }
+  flush()
+  return body
+}
diff --git a/packages/chat/teams/src/internal/webhook.ts b/packages/chat/teams/src/internal/webhook.ts
new file mode 100644
index 00000000000..cada89286fc
--- /dev/null
+++ b/packages/chat/teams/src/internal/webhook.ts
@@ -0,0 +1,147 @@
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import type { NotAccepted } from "effect/chat/ChatHandler"
+import type * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import type * as HttpServerRequest from "effect/http/HttpServerRequest"
+import * as HttpServerResponse from "effect/http/HttpServerResponse"
+import * as Option from "effect/Option"
+import type * as Schema from "effect/Schema"
+import * as Stream from "effect/Stream"
+import { tenantOf, type Verdict } from "./auth.ts"
+import type { InvokeResponse } from "./interactions.ts"
+import { isSubmitFallback } from "./interactions.ts"
+import { type Context, isObject, isTargeted, normalize } from "./normalize.ts"
+
+type JsonObject = { readonly [key: string]: Schema.Json }
+
+/** The body, or `None` once it passes `maxBytes`. @internal */
+export const readBody = (
+  request: HttpServerRequest.HttpServerRequest,
+  maxBytes: number
+): Effect.Effect> => {
+  const length = request.headers["content-length"]
+  if (length !== undefined && Number(length) > maxBytes) return Effect.succeed(Option.none())
+  return Effect.gen(function*() {
+    const chunks: Array = []
+    let total = 0
+    const tooLarge = yield* request.stream.pipe(
+      Stream.takeUntil((chunk) => {
+        total += chunk.length
+        chunks.push(chunk)
+        return total > maxBytes
+      }),
+      Stream.runDrain,
+      Effect.as(false),
+      Effect.catch(() => Effect.succeed(true))
+    )
+    if (tooLarge || total > maxBytes) return Option.none()
+    const body = new Uint8Array(total)
+    let offset = 0
+    for (const chunk of chunks) {
+      body.set(chunk, offset)
+      offset += chunk.length
+    }
+    return Option.some(body)
+  })
+}
+
+const status = (code: number) => HttpServerResponse.empty({ status: code })
+
+/**
+ * What is logged with each 503 of the route.
+ *
+ * @internal
+ */
+export const unavailable = {
+  keys: "teams webhook: the signing keys could not be read, answered 503",
+  normalize: "teams webhook: the activity could not be normalised, answered 503",
+  notAccepted: "teams webhook: the handler refused the event, answered 503",
+  deadline: "teams webhook: the request passed its deadline, answered 503"
+} as const
+
+/** @internal */
+export interface Options {
+  readonly verify: (authorization: string | undefined, activity: {
+    readonly serviceUrl: unknown
+    readonly channelId: unknown
+    readonly tenantId: string | undefined
+  }) => Effect.Effect
+  readonly context: Context
+  readonly handle: (event: ChatEvent.ChatEvent) => Effect.Effect
+  readonly onUnhandled: (activity: JsonObject) => Effect.Effect
+  readonly invoke: (activity: JsonObject) => Effect.Effect
+  readonly command: (activity: JsonObject) => Effect.Effect
+  readonly deadline: Duration.Input
+  readonly maxBodyBytes: number
+}
+
+const respond = (response: InvokeResponse) =>
+  response.body === undefined
+    ? status(response.status)
+    : HttpServerResponse.jsonUnsafe(response.body, { status: response.status })
+
+/**
+ * One Bot Framework activity.
+ *
+ * - 413 past the body limit, 400 for a body that is not a JSON object.
+ * - 403 when the token, its `serviceurl`, the channel or the tenant does
+ *   not check out, and 503 when the signing keys can't be read.
+ * - A targeted activity is classified first, whatever its type: a message
+ *   takes the command path, an invoke goes to the interaction handler, and
+ *   anything else is answered 200 and dropped. None reaches `ChatHandler`
+ *   or `onUnhandled`.
+ * - An invoke, or a card's submit fallback, goes to the interaction
+ *   handler, whose answer is the response.
+ * - Every other activity is normalised and handed to the `ChatHandler`
+ *   one event at a time: 200 when all succeed, 503 when one fails
+ *   `NotAccepted`, or when a `message` can't be normalised. Any other
+ *   activity that gives no event goes to `onUnhandled` and is answered 200.
+ * - 503 past `deadline`, the handler interrupted. Each 503 is logged with
+ *   its own message.
+ *
+ * @internal
+ */
+export const handleRequest = (
+  request: HttpServerRequest.HttpServerRequest,
+  options: Options
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const body = yield* readBody(request, options.maxBodyBytes)
+    if (Option.isNone(body)) return status(413)
+    let activity: unknown
+    try {
+      activity = JSON.parse(new TextDecoder().decode(body.value))
+    } catch {
+      return status(400)
+    }
+    if (!isObject(activity)) return status(400)
+    const verdict = yield* options.verify(request.headers.authorization, {
+      serviceUrl: activity.serviceUrl,
+      channelId: activity.channelId,
+      tenantId: tenantOf(activity)
+    })
+    if (verdict === "forbidden") return status(403)
+    if (verdict === "unavailable") return yield* Effect.as(Effect.logWarning(unavailable.keys), status(503))
+    if (isTargeted(activity)) {
+      if (activity.type === "message") return yield* Effect.as(options.command(activity), status(200))
+      if (activity.type === "invoke") return respond(yield* options.invoke(activity))
+      return status(200)
+    }
+    if (activity.type === "invoke") return respond(yield* options.invoke(activity))
+    if (isSubmitFallback(activity)) return respond(yield* options.invoke(activity))
+    const events = normalize(activity, options.context)
+    if (events.length === 0 && activity.type === "message") {
+      return yield* Effect.as(Effect.logWarning(unavailable.normalize), status(503))
+    }
+    if (events.length === 0) return yield* Effect.as(options.onUnhandled(activity), status(200))
+    return yield* Effect.forEach(events, options.handle, { discard: true }).pipe(
+      Effect.as(status(200)),
+      Effect.catchTag("NotAccepted", () => Effect.as(Effect.logWarning(unavailable.notAccepted), status(503)))
+    )
+  }).pipe(
+    Effect.timeoutOption(options.deadline),
+    Effect.flatMap(Option.match({
+      onNone: () => Effect.as(Effect.logWarning(unavailable.deadline), status(503)),
+      onSome: Effect.succeed
+    }))
+  )
diff --git a/packages/chat/teams/test/conformance.test.ts b/packages/chat/teams/test/conformance.test.ts
new file mode 100644
index 00000000000..9279724874a
--- /dev/null
+++ b/packages/chat/teams/test/conformance.test.ts
@@ -0,0 +1,96 @@
+/**
+ * The conformance suite against the default layer, over a stubbed Connector
+ * that answers every write. Capabilities behind `unverified` are off, so
+ * their rules check that the descriptor leaves them out and the ops refuse.
+ */
+import * as TeamsChat from "@effect/chat-teams/TeamsChat"
+import { describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
+import { conformance } from "effect/chat/ChatTest"
+import * as Digest from "effect/crypto/Digest"
+import * as Mac from "effect/crypto/Mac"
+import * as SecureRandom from "effect/crypto/SecureRandom"
+import * as Effect from "effect/Effect"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+
+const appId = "00000000-0000-0000-0000-0000000000a1"
+const tenantId = "00000000-0000-0000-0000-0000000000b2"
+const conversationId = "19:conformance@thread.tacv2"
+const thread = TeamsChat.thread(conversationId)
+
+const json = (body: unknown, status = 200) =>
+  new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } })
+
+const makeConnector = () => {
+  let next = 1_700_000_000_000
+  const posted = new Set()
+  return HttpClient.make((request, url) =>
+    Effect.sync(() => {
+      let response: Response
+      if (url.host === "login.microsoftonline.com") {
+        response = json({ access_token: "token", expires_in: 3600, token_type: "Bearer" })
+      } else if (request.method === "POST") {
+        const id = String(next++)
+        posted.add(id)
+        response = json({ id })
+      } else if (request.method === "PUT" || request.method === "DELETE") {
+        const id = decodeURIComponent(url.pathname.split("/").pop()!)
+        const known = posted.has(id)
+        if (request.method === "DELETE") posted.delete(id)
+        response = known ? json({}) : json({ error: { code: "ActivityNotFound" } }, 404)
+      } else if (url.pathname.includes("/members/")) {
+        response = json({ id: "29:user", aadObjectId: "user", name: "User" })
+      } else response = json({ members: [] })
+      return HttpClientResponse.fromWeb(request, response)
+    })
+  )
+}
+
+const layer = () =>
+  TeamsChat.layer({ appId, tenantId, credentials: Redacted.make("secret") }).pipe(
+    Layer.provideMerge(Chat.layer),
+    Layer.provide(Layer.succeed(HttpClient.HttpClient, makeConnector())),
+    Layer.provide(Layer.mergeAll(Digest.layerWebCrypto, Mac.layerWebCrypto)),
+    Layer.provide(SecureRandom.layerWebCrypto)
+  )
+
+let sequence = 0
+
+const options = {
+  platform: "teams",
+  thread,
+  parseMention: TeamsChat.parseMention,
+  userPosts: (at: typeof thread, text: string) =>
+    Effect.sync(() => {
+      const parts = TeamsChat.parts(at)
+      const id = String(1_800_000_000_000 + sequence++)
+      const events = TeamsChat.normalize({
+        type: "message",
+        id,
+        timestamp: new Date().toISOString(),
+        serviceUrl: "https://smba.trafficmanager.net/teams",
+        channelId: "msteams",
+        from: { id: "29:user", aadObjectId: "user", name: "User" },
+        recipient: { id: `28:${appId}`, name: "Bot" },
+        conversation: {
+          id: parts._tag === "Some" ? parts.value.conversationId : conversationId,
+          conversationType: "channel",
+          tenantId
+        },
+        channelData: { tenant: { id: tenantId } },
+        textFormat: "plain",
+        text
+      }, { appId })
+      return events[0]!
+    })
+}
+
+describe("conformance over the stubbed Connector", () => {
+  const names = Object.keys(conformance(options))
+  for (const name of names) {
+    it.effect(name, () => conformance(options)[name].pipe(Effect.provide(layer())))
+  }
+})
diff --git a/packages/chat/teams/test/download.test.ts b/packages/chat/teams/test/download.test.ts
new file mode 100644
index 00000000000..6aecdf43982
--- /dev/null
+++ b/packages/chat/teams/test/download.test.ts
@@ -0,0 +1,104 @@
+import * as Download from "@effect/chat-teams/internal/download"
+import { assert, describe, it } from "@effect/vitest"
+import type { ChatError } from "effect/chat/ChatError"
+import * as Context from "effect/Context"
+import * as Effect from "effect/Effect"
+import * as FetchHttpClient from "effect/http/FetchHttpClient"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Redacted from "effect/Redacted"
+import * as Stream from "effect/Stream"
+
+interface Sent {
+  readonly url: string
+  readonly authorization: string | undefined
+  readonly redirect: RequestRedirect | undefined
+}
+
+const serve = (handler: (url: string) => Response) => {
+  const sent: Array = []
+  const http = HttpClient.make((request, url, _signal, fiber) =>
+    Effect.sync(() => {
+      sent.push({
+        url: url.href,
+        authorization: request.headers.authorization,
+        redirect: Context.getOrUndefined(fiber.context, FetchHttpClient.RequestInit)?.redirect
+      })
+      return HttpClientResponse.fromWeb(request, handler(url.href))
+    })
+  )
+  return { sent, http }
+}
+
+const connectorUrl = "https://smba.trafficmanager.net/amer/v3/attachments/0-cus-d1-abc/views/original"
+
+const options = (http: HttpClient.HttpClient, maxBytes = 1024) => ({
+  http,
+  maxBytes,
+  token: Effect.succeed(Redacted.make("secret")),
+  connectorHosts: new Set(["smba.trafficmanager.net"]),
+  fileHostSuffixes: ["sharepoint.com"],
+  redirectHosts: new Set(["cdn.example.com"])
+})
+
+const reasonOf = (stream: Stream.Stream) =>
+  Stream.runDrain(stream).pipe(Effect.flip, Effect.map((error) => error.reason))
+
+describe("download", () => {
+  it.effect("sends the token to the Connector and streams the body", () =>
+    Effect.gen(function*() {
+      const { http, sent } = serve(() => new Response("hello"))
+      const bytes = yield* Stream.mkUint8Array(Download.download(`connector:${connectorUrl}`, options(http)))
+      assert.strictEqual(new TextDecoder().decode(bytes), "hello")
+      assert.deepStrictEqual(sent, [{ url: connectorUrl, authorization: "Bearer secret", redirect: "manual" }])
+    }))
+
+  it.effect("refuses a redirect off the allowlist and sends the token on the first hop only", () =>
+    Effect.gen(function*() {
+      const { http, sent } = serve((url) =>
+        new Response(null, {
+          status: 302,
+          headers: { location: url === connectorUrl ? "https://cdn.example.com/file" : "https://evil.example/file" }
+        })
+      )
+      const reason = yield* reasonOf(Download.download(`connector:${connectorUrl}`, options(http)))
+      assert.strictEqual(reason._tag, "Forbidden")
+      assert.strictEqual(reason.detail, "untrusted_url")
+      assert.deepStrictEqual(sent.map((request) => [request.url, request.authorization]), [
+        [connectorUrl, "Bearer secret"],
+        ["https://cdn.example.com/file", undefined]
+      ])
+    }))
+
+  it.effect("fails TooLarge past maxBytes", () =>
+    Effect.gen(function*() {
+      const { http } = serve(() => new Response(new Uint8Array(16)))
+      const reason = yield* reasonOf(Download.download(`connector:${connectorUrl}`, options(http, 8)))
+      assert.strictEqual(reason._tag, "TooLarge")
+    }))
+})
+
+describe("classify", () => {
+  it("refuses a lookalike file host", () => {
+    const context = {
+      serviceUrl: "https://smba.trafficmanager.net/amer/",
+      conversationType: "personal",
+      connectorHosts: new Set(["smba.trafficmanager.net"]),
+      fileHostSuffixes: ["sharepoint.com"]
+    }
+    const attachment = (host: string) => ({
+      contentType: Download.fileDownloadInfo,
+      contentUrl: `https://${host}/personal/a/report.pdf`,
+      name: "report.pdf",
+      content: { downloadUrl: `https://${host}/download.aspx?tempauth=x` }
+    })
+    assert.deepStrictEqual(Download.classify(attachment("contoso.sharepoint.com"), context), {
+      id: "preauth:https://contoso.sharepoint.com/download.aspx?tempauth=x",
+      name: "report.pdf"
+    })
+    assert.deepStrictEqual(Download.classify(attachment("evilsharepoint.com"), context), {
+      id: "url:https://evilsharepoint.com/personal/a/report.pdf",
+      name: "report.pdf"
+    })
+  })
+})
diff --git a/packages/chat/teams/test/envelope.test.ts b/packages/chat/teams/test/envelope.test.ts
new file mode 100644
index 00000000000..13ec0d82eee
--- /dev/null
+++ b/packages/chat/teams/test/envelope.test.ts
@@ -0,0 +1,80 @@
+import * as Envelope from "@effect/chat-teams/internal/envelope"
+import { assert, describe, it } from "@effect/vitest"
+import type * as ChatUi from "effect/chat/ChatUi"
+import { Digest, Mac, SecureRandom } from "effect/crypto"
+import * as Effect from "effect/Effect"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+
+const layer = Layer.mergeAll(Digest.layerWebCrypto, Mac.layerWebCrypto).pipe(
+  Layer.provideMerge(SecureRandom.layerWebCrypto)
+)
+
+const k1 = Redacted.make({ kty: "oct", kid: "k1", k: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc" } as const)
+const k2 = Redacted.make({ kty: "oct", kid: "k2", k: "CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg" } as const)
+
+const options = { appId: "app-1", tenantId: "tenant-1" }
+const conversation = "19:abc@thread.tacv2"
+
+describe("envelope", () => {
+  it.effect("round trips a button, from any message of the conversation", () =>
+    Effect.gen(function*() {
+      const envelope = yield* Envelope.make({ ...options, keys: [k1] })
+      const token = yield* envelope.signButton(conversation, { id: "approve", value: "42" })
+      const verified = yield* envelope.verifyButton(token, { conversationId: `${conversation};messageid=123` })
+      assert.deepStrictEqual(verified, Option.some({ id: "approve", value: "42" }))
+    }).pipe(Effect.provide(layer)))
+
+  it.effect("refuses another conversation, a tampered token and an unknown kid", () =>
+    Effect.gen(function*() {
+      const envelope = yield* Envelope.make({ ...options, keys: [k1] })
+      const token = yield* envelope.signButton(conversation, { id: "approve" })
+      assert.isTrue(Option.isNone(yield* envelope.verifyButton(token, { conversationId: "19:other@thread.tacv2" })))
+
+      const [header, payload, signature] = token.split(".")
+      const tampered = `${header}.${payload}.${signature.slice(0, -2)}${signature.endsWith("AA") ? "BA" : "AA"}`
+      assert.isTrue(Option.isNone(yield* envelope.verifyButton(tampered, { conversationId: conversation })))
+
+      const other = yield* Envelope.make({ ...options, keys: [k2] })
+      const unknownKid = yield* other.signButton(conversation, { id: "approve" })
+      assert.isTrue(Option.isNone(yield* envelope.verifyButton(unknownKid, { conversationId: conversation })))
+
+      const rotated = yield* Envelope.make({ ...options, keys: [k2, k1] })
+      assert.isTrue(Option.isSome(yield* rotated.verifyButton(token, { conversationId: conversation })))
+    }).pipe(Effect.provide(layer)))
+
+  it.effect("buttonTokenLength is the length of the signed token", () =>
+    Effect.gen(function*() {
+      const envelope = yield* Envelope.make({ ...options, keys: [k1] })
+      for (const button of [{ id: "a" }, { id: "pick", value: "caf\u00e9 \"quoted\" \u{1F600}" }]) {
+        const token = yield* envelope.signButton(conversation, button)
+        assert.strictEqual(Envelope.buttonTokenLength({ ...options, kid: "k1" }, button), token.length)
+        assert.isTrue(token.length <= Envelope.maxTokenLength)
+      }
+    }).pipe(Effect.provide(layer)))
+
+  it.effect("round trips a dialog and checks its submit against the definition", () =>
+    Effect.gen(function*() {
+      const envelope = yield* Envelope.make({ ...options, keys: [k1] })
+      const modal: ChatUi.Modal = {
+        _tag: "Modal",
+        id: "deploy",
+        title: "Deploy",
+        metadata: "m",
+        elements: [
+          { _tag: "SelectInput", id: "env", label: "Env", options: [{ label: "Prod", value: "prod" }] },
+          { _tag: "TextInput", id: "note", label: "Note", optional: true }
+        ]
+      }
+      const token = yield* envelope.signDialog(conversation, { userId: "u1", messageId: "m1", modal })
+      assert.isTrue(Option.isNone(yield* envelope.verifyDialog(token, { conversationId: conversation, userId: "u2" })))
+      const verified = yield* envelope.verifyDialog(token, { conversationId: conversation, userId: "u1" })
+      assert.deepStrictEqual(verified, Option.some({ messageId: "m1", modal }))
+      assert.deepStrictEqual(
+        Envelope.validateSubmission(modal, { effect: token, env: "prod", note: "" }),
+        Option.some({ env: "prod" })
+      )
+      assert.isTrue(Option.isNone(Envelope.validateSubmission(modal, { env: "staging" })))
+    }).pipe(Effect.provide(layer)))
+})
diff --git a/packages/chat/teams/test/length.test.ts b/packages/chat/teams/test/length.test.ts
new file mode 100644
index 00000000000..00e6778a09b
--- /dev/null
+++ b/packages/chat/teams/test/length.test.ts
@@ -0,0 +1,33 @@
+import * as Length from "@effect/chat-teams/internal/length"
+import * as Render from "@effect/chat-teams/internal/render"
+import { describe, expect, it } from "@effect/vitest"
+import type * as ChatUi from "effect/chat/ChatUi"
+
+const tokenLength = (button: { readonly id: string; readonly value?: string | undefined }) =>
+  20 + button.id.length + (button.value?.length ?? 0)
+const encode = (button: ChatUi.Button) => "t".repeat(tokenLength(button))
+const measure = Length.makeMeasure(tokenLength)
+
+const actions: ReadonlyArray = [
+  { _tag: "Button", id: "approve", label: "Yes & ", style: "danger", value: "v" },
+  { _tag: "LinkButton", label: "Docs", url: "https://example.com/?a=1&b=<2>" }
+]
+
+const fits = (markdown: string, actions: ReadonlyArray) =>
+  expect(JSON.stringify(Render.cardActivity(markdown, actions, encode)).length).toBeLessThanOrEqual(
+    measure(markdown, actions) + Length.R
+  )
+
+describe("measure", () => {
+  it("bounds a fence pair", () => fits(["```\nx\n", "```\np\n\nq\n\nr"].join(""), actions))
+
+  it("bounds nested block syntax on one line", () => fits("> - # x", actions))
+
+  it("bounds a table", () => fits("| a | b |\n| - | - |\n| c | d |", actions))
+
+  it("bounds a card without actions", () => {
+    const markdown = "# Title\n\nsome *text* & \n\n```ts\nconst x = 1\n```"
+    fits(markdown, [])
+    expect(measure(markdown, [])).toBe(measure(markdown))
+  })
+})
diff --git a/packages/chat/teams/test/webhook.test.ts b/packages/chat/teams/test/webhook.test.ts
new file mode 100644
index 00000000000..41cc7d860b7
--- /dev/null
+++ b/packages/chat/teams/test/webhook.test.ts
@@ -0,0 +1,132 @@
+/**
+ * The messaging endpoint through `layerWebhook`, with tokens signed by a
+ * key in a stubbed Bot Framework key set.
+ */
+import * as TeamsChat from "@effect/chat-teams/TeamsChat"
+import { assert, describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { ChatHandler } from "effect/chat/ChatHandler"
+import * as Digest from "effect/crypto/Digest"
+import * as Mac from "effect/crypto/Mac"
+import * as SecureRandom from "effect/crypto/SecureRandom"
+import * as Signature from "effect/crypto/Signature"
+import * as Effect from "effect/Effect"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as HttpRouter from "effect/http/HttpRouter"
+import { Jwk, Jwt } from "effect/jose"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+import * as Schema from "effect/Schema"
+
+const appId = "00000000-0000-0000-0000-0000000000a1"
+const tenantId = "00000000-0000-0000-0000-0000000000b2"
+const serviceUrl = "https://smba.trafficmanager.net/emea/"
+const keysUrl = "https://login.botframework.com/v1/.well-known/keys"
+
+const crypto = Layer.mergeAll(Digest.layerWebCrypto, Mac.layerWebCrypto, Signature.layerWebCrypto).pipe(
+  Layer.provideMerge(SecureRandom.layerWebCrypto)
+)
+
+const Claims = Schema.Struct({
+  iss: Schema.String,
+  aud: Schema.String,
+  exp: Schema.Number,
+  serviceurl: Schema.String
+})
+
+const activity = (overrides?: Record) => ({
+  type: "message",
+  id: "1800000000001",
+  timestamp: "2026-11-15T10:00:00.000Z",
+  serviceUrl,
+  channelId: "msteams",
+  from: { id: "29:user", aadObjectId: "user", name: "User" },
+  recipient: { id: `28:${appId}`, name: "Bot" },
+  conversation: { id: "a:direct", conversationType: "personal", tenantId },
+  channelData: { tenant: { id: tenantId } },
+  text: "hello",
+  ...overrides
+})
+
+const setup = Effect.gen(function*() {
+  const pair = yield* Jwk.generateKeyPair({ algorithm: "RS256", kid: "k1" })
+  const key = yield* Jwk.importPrivate(pair.privateKey, "RS256")
+  const token = (claimed = serviceUrl) =>
+    Effect.map(
+      Jwt.sign(
+        Claims,
+        {
+          iss: "https://api.botframework.com",
+          aud: appId,
+          exp: Math.floor(Date.now() / 1000) + 600,
+          serviceurl: claimed
+        },
+        key,
+        { kid: "k1" }
+      ),
+      Redacted.value
+    )
+  const http = HttpClient.make((request, url) =>
+    Effect.sync(() => {
+      const body = url.href === keysUrl
+        ? { keys: [{ ...pair.publicKey, endorsements: ["msteams"] }] }
+        : url.pathname.endsWith("/openidconfiguration")
+        ? { jwks_uri: keysUrl }
+        : {}
+      return HttpClientResponse.fromWeb(request, Response.json(body))
+    })
+  )
+  const events: Array = []
+  const app = TeamsChat.layerWebhook({ path: "/api/messages" }).pipe(
+    Layer.provide(TeamsChat.layer({ appId, tenantId, credentials: Redacted.make("secret") })),
+    Layer.provide(Chat.layer),
+    Layer.provide(Layer.succeed(ChatHandler, { handle: (event) => Effect.sync(() => void events.push(event)) })),
+    Layer.provide(Layer.succeed(HttpClient.HttpClient, http)),
+    Layer.provide(crypto)
+  )
+  const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true })
+  yield* Effect.addFinalizer(() => Effect.promise(() => dispose()))
+  const send = (body: unknown, authorization?: string) =>
+    Effect.promise(() =>
+      handler(
+        new Request("http://localhost/api/messages", {
+          method: "POST",
+          body: JSON.stringify(body),
+          headers: {
+            "content-type": "application/json",
+            ...(authorization === undefined ? {} : { authorization })
+          }
+        })
+      )
+    ).pipe(Effect.map((response) => response.status))
+  return { events, send, token }
+})
+
+describe("layerWebhook", () => {
+  it.effect("answers 403 without a valid token, and for a token bound to another serviceUrl", () =>
+    Effect.gen(function*() {
+      const { events, send, token } = yield* setup
+      assert.strictEqual(yield* send(activity()), 403)
+      assert.strictEqual(yield* send(activity(), "Bearer not.a.token"), 403)
+      const other = yield* token("https://smba.trafficmanager.net/amer/")
+      assert.strictEqual(yield* send(activity(), `Bearer ${other}`), 403)
+      const wrongTenant = activity({ conversation: { id: "a:direct", conversationType: "personal", tenantId: "x" } })
+      assert.strictEqual(yield* send(wrongTenant, `Bearer ${yield* token()}`), 403)
+      assert.strictEqual(events.length, 0)
+    }).pipe(Effect.provide(crypto)))
+
+  it.effect("hands a verified message to the ChatHandler, and drops a targeted one", () =>
+    Effect.gen(function*() {
+      const { events, send, token } = yield* setup
+      const bearer = `Bearer ${yield* token()}`
+      assert.strictEqual(yield* send(activity(), bearer), 200)
+      assert.strictEqual(
+        yield* send(activity({ id: "1800000000002", recipient: { id: `28:${appId}`, isTargeted: true } }), bearer),
+        200
+      )
+      assert.strictEqual(events.length, 1)
+      assert.strictEqual(events[0]._tag, "MessageCreated")
+    }).pipe(Effect.provide(crypto)))
+})
diff --git a/packages/chat/teams/tsconfig.json b/packages/chat/teams/tsconfig.json
new file mode 100644
index 00000000000..e2a8ca19a0d
--- /dev/null
+++ b/packages/chat/teams/tsconfig.json
@@ -0,0 +1,8 @@
+{
+  "$schema": "https://json.schemastore.org/tsconfig",
+  "extends": "../../../tsconfig.base.json",
+  "include": ["src"],
+  "references": [
+    { "path": "../../effect" }
+  ]
+}
diff --git a/packages/effect/src/chat/ChatAdapter.ts b/packages/effect/src/chat/ChatAdapter.ts
index b7f225a45c5..fd76e737f1d 100644
--- a/packages/effect/src/chat/ChatAdapter.ts
+++ b/packages/effect/src/chat/ChatAdapter.ts
@@ -46,7 +46,10 @@ import { RetriesDisabled } from "./internal/retries.ts"
  * - An op whose capability is missing from `capabilities` fails with
  *   `Unsupported`.
  * - `limits.messageLength` is the platform's own limit for one message, in
- *   the platform's own unit.
+ *   the platform's own unit. Where every message also carries a fixed
+ *   overhead that the text does not, such as a card's structure, it is that
+ *   limit less a fixed reservation for the overhead, and the adapter's docs
+ *   give both numbers.
  * - `measure` gives what a Markdown string costs against
  *   `limits.messageLength` and `limits.streamLength`. It is pure and makes
  *   no call to the platform. It is an upper bound, never less than what the
@@ -69,7 +72,10 @@ import { RetriesDisabled } from "./internal/retries.ts"
  *   `limits.modalMetadataLength` and `limits.modalFields` are there exactly
  *   when the matching capability is (`buttons` for the first two, `modals`
  *   for the last two). Each is the platform's number in the platform's unit,
- *   as `messageLength` is. The adapter checks them exactly and fails
+ *   as `messageLength` is. Where the platform publishes none, it is the
+ *   adapter's own cap, documented as the adapter's, and set so that a
+ *   message holding every element at its cap still fits `messageLength`.
+ *   The adapter checks them exactly and fails
  *   `TooLarge`: before the call for a message's elements, and before it
  *   opens a modal.
  * - `limits.followUpAge` is there exactly when `commands` is: how long after
diff --git a/packages/effect/src/jose/Jwks.ts b/packages/effect/src/jose/Jwks.ts
index e03c64a1318..5d5d94a60ba 100644
--- a/packages/effect/src/jose/Jwks.ts
+++ b/packages/effect/src/jose/Jwks.ts
@@ -228,6 +228,17 @@ export interface RemoteOptions {
    * Maximum number of keys in the set. Defaults to 64.
    */
   readonly maxKeys?: number | undefined
+  /**
+   * Keeps only the raw keys it returns `true` for, before the set is decoded.
+   *
+   * **Details**
+   *
+   * It sees each member of `keys` as the endpoint sent it, with members such
+   * as `x5c` or a provider's own `endorsements` that decoding drops. Keys
+   * that are not JSON objects are dropped without a call. `maxKeys` counts
+   * the set before filtering, so a filter cannot raise the limit.
+   */
+  readonly filter?: ((jwk: { readonly [key: string]: unknown }) => boolean) | undefined
 }
 
 interface Snapshot {
@@ -302,6 +313,7 @@ export const makeRemote = Effect.fnUntraced(function*(
   const timeout = yield* positiveMillis("timeout", options.timeout ?? "5 seconds")
   const maxResponseBytes = yield* positiveInteger("maxResponseBytes", options.maxResponseBytes ?? 131072)
   const maxKeys = yield* positiveInteger("maxKeys", options.maxKeys ?? 64)
+  const filter = options.filter
 
   const client = HttpClient.withScope(yield* HttpClient.HttpClient)
   const scope = yield* Effect.scope
@@ -337,12 +349,18 @@ export const makeRemote = Effect.fnUntraced(function*(
       body.set(chunk, length)
       return Effect.succeed(length + chunk.length)
     })
-    const keySet = yield* Schema.decodeUnknownEffect(KeySet)(parseJsonObject(body.subarray(0, length))).pipe(
-      Effect.mapError((cause) => unavailable("The key set document is invalid", cause))
-    )
-    if (keySet.keys.length > maxKeys) {
+    const document = parseJsonObject(body.subarray(0, length))
+    const rawKeys = document?.keys
+    if (Array.isArray(rawKeys) && rawKeys.length > maxKeys) {
       return yield* unavailable(`The key set has more than ${maxKeys} keys`)
     }
+    const filtered = filter === undefined || !Array.isArray(rawKeys) ? document : {
+      ...document,
+      keys: rawKeys.filter((jwk) => typeof jwk === "object" && jwk !== null && !Array.isArray(jwk) && filter(jwk))
+    }
+    const keySet = yield* Schema.decodeUnknownEffect(KeySet)(filtered).pipe(
+      Effect.mapError((cause) => unavailable("The key set document is invalid", cause))
+    )
     return { keys: supportedKeys(keySet), expiresAt: (yield* Clock.currentTimeMillis) + timeToLive }
   }).pipe(
     Effect.scoped,
diff --git a/packages/effect/test/jose/Jwks.test.ts b/packages/effect/test/jose/Jwks.test.ts
index 4f3faba8881..f56b9add1df 100644
--- a/packages/effect/test/jose/Jwks.test.ts
+++ b/packages/effect/test/jose/Jwks.test.ts
@@ -121,6 +121,28 @@ it.effect("caches remote key sets, coalesces concurrent refreshes, and refreshes
     assert.strictEqual(requests, 4)
   }).pipe(Effect.provide(layer)))
 
+it.effect("filters raw keys before decoding, and counts maxKeys before filtering", () =>
+  Effect.gen(function*() {
+    const endorsed = { ...ec, kid: "endorsed", endorsements: ["msteams"] }
+    const document = { keys: [endorsed, { ...ec, kid: "other", endorsements: ["skype"] }, { ...ec, kid: "bare" }, 1] }
+    const filter = (jwk: { readonly [key: string]: unknown }) =>
+      Array.isArray(jwk.endorsements) && jwk.endorsements.includes("msteams")
+    const client = serve(() => Effect.succeed(new Response(JSON.stringify(document))))
+
+    const keys = Context.get(
+      yield* Layer.build(Jwks.layerRemote({ url, filter }).pipe(Layer.provide(client))),
+      Jwks.Jwks
+    )
+    assert.strictEqual((yield* keys.resolve({ algorithm: "ES256" })).kid, "endorsed")
+    assertReason(yield* keys.resolve({ algorithm: "ES256", kid: "bare" }).pipe(Effect.flip), "KeyNotFound")
+
+    const limited = Context.get(
+      yield* Layer.build(Jwks.layerRemote({ url, filter, maxKeys: 3 }).pipe(Layer.provide(client))),
+      Jwks.Jwks
+    )
+    assertReason(yield* limited.resolve({ algorithm: "ES256" }).pipe(Effect.flip), "KeySetUnavailable")
+  }).pipe(Effect.provide(layer)))
+
 it.effect("refetches an expired key set at once when timeToLive is shorter than cooldown", () =>
   Effect.gen(function*() {
     let requests = 0
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 11dcde3ec97..128e8a67a40 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -363,6 +363,12 @@ importers:
         specifier: workspace:^
         version: link:../../effect
 
+  packages/chat/teams:
+    devDependencies:
+      effect:
+        specifier: workspace:^
+        version: link:../../effect
+
   packages/chat/whatsapp:
     devDependencies:
       effect:
diff --git a/tsconfig.packages.json b/tsconfig.packages.json
index 6501404c759..4261fc32473 100644
--- a/tsconfig.packages.json
+++ b/tsconfig.packages.json
@@ -16,6 +16,7 @@
     { "path": "packages/chat/slack" },
     { "path": "packages/chat/whatsapp" },
     { "path": "packages/chat/discord" },
+    { "path": "packages/chat/teams" },
     { "path": "packages/atom/vue" },
     { "path": "packages/atom/solid" },
     { "path": "packages/opentelemetry" },
diff --git a/tsconfig.tests.json b/tsconfig.tests.json
index 5591bfa3a2f..2dae6fe6e07 100644
--- a/tsconfig.tests.json
+++ b/tsconfig.tests.json
@@ -60,6 +60,8 @@
       "@effect/chat-whatsapp/*": ["./packages/chat/whatsapp/src/*.ts"],
       "@effect/chat-discord": ["./packages/chat/discord/src/index.ts"],
       "@effect/chat-discord/*": ["./packages/chat/discord/src/*.ts"],
+      "@effect/chat-teams": ["./packages/chat/teams/src/index.ts"],
+      "@effect/chat-teams/*": ["./packages/chat/teams/src/*.ts"],
       "@effect/atom-react": ["./packages/atom/react/src/index.ts"],
       "@effect/atom-react/*": ["./packages/atom/react/src/*.ts"],
       "@effect/atom-vue": ["./packages/atom/vue/src/index.ts"],
diff --git a/vitest.config.ts b/vitest.config.ts
index 2734f1e2d73..e3ed6a9d3bb 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -140,6 +140,7 @@ export default defineConfig({
       ...project("@effect/chat-discord", "packages/chat/discord", true, {
         test: { server: { deps: { inline: ["dfx"] } } }
       }),
+      ...project("@effect/chat-teams", "packages/chat/teams"),
       ...project("@effect/atom-react", "packages/atom/react", true, {
         test: {
           environment: "jsdom",

From 5aa569406e6a9073bbdbc242c5086d90b5434913 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:26:05 +0000
Subject: [PATCH 65/89] Fix the WhatsApp review findings

Report a changed BSUID that has no sender, answer the webhook deadline without waiting for finalizers, keep a modal refusal from delaying a click, map a refused upload to file_refused, and keep shortcut references, multi-line definitions and container-nested fences as typed.
---
 packages/chat/whatsapp/src/WhatsAppChat.ts    | 11 +--
 .../chat/whatsapp/src/internal/adapter.ts     | 10 ++-
 .../chat/whatsapp/src/internal/normalize.ts   | 60 +++++++++-------
 packages/chat/whatsapp/src/internal/text.ts   | 30 +++++---
 .../chat/whatsapp/src/internal/webhook.ts     | 37 +++++++---
 .../chat/whatsapp/test/WhatsAppChat.test.ts   | 72 +++++++++++++++++--
 packages/chat/whatsapp/test/text.test.ts      |  6 +-
 7 files changed, 175 insertions(+), 51 deletions(-)

diff --git a/packages/chat/whatsapp/src/WhatsAppChat.ts b/packages/chat/whatsapp/src/WhatsAppChat.ts
index 27d8d58be44..5b254b6934b 100644
--- a/packages/chat/whatsapp/src/WhatsAppChat.ts
+++ b/packages/chat/whatsapp/src/WhatsAppChat.ts
@@ -151,7 +151,8 @@ export class WhatsAppChat extends Context.Service Option.Option<{
  * - A `NotAccepted` stops the delivery and answers 503, as does a request
  *   that takes longer than `deadline` (4 seconds by default, provisional).
  *   Meta then delivers the whole batch again, for up to 7 days, so a batch
- *   that always runs past the deadline repeats until then.
+ *   that always runs past the deadline repeats until then. At the deadline
+ *   the work is interrupted without waiting for its finalizers.
  * - A click never causes a 503. It gets what is left of the deadline, less
  *   a margin. `Ack` and `Late` count as handled, and a late handler keeps
  *   running. `OpenModal` goes to `Handler.refused` as
- *   `Unsupported("modals")`. Without a `ChatInteraction.Handler` in the
+ *   `Unsupported("modals")`, which is awaited only within the click's share. Without a `ChatInteraction.Handler` in the
  *   layer's context, a click is logged and dropped.
  * - Delivery is at least once. A message, a reaction or a click can arrive
  *   twice, a click even at the same time as its first delivery. Drop
diff --git a/packages/chat/whatsapp/src/internal/adapter.ts b/packages/chat/whatsapp/src/internal/adapter.ts
index 1798e41fb81..fcfbb266180 100644
--- a/packages/chat/whatsapp/src/internal/adapter.ts
+++ b/packages/chat/whatsapp/src/internal/adapter.ts
@@ -157,7 +157,15 @@ export const make = (options: {
     form.append("type", mime)
     form.append("file", new Blob([file.content as Uint8Array], { type: mime }), file.name)
     return graph.call(`${phoneNumberId}/media`, { form }).pipe(
-      Effect.mapError(withOp(op)),
+      // Meta refusing the file itself is a file refusal: nothing was sent, so the text can go without it.
+      Effect.mapError((error) =>
+        Errors.chatError(
+          op,
+          error.reason._tag === "TooLarge" || error.reason._tag === "InvalidRequest"
+            ? new TooLarge({ subject: "files", detail: fileRefused, cause: error.reason })
+            : error.reason
+        )
+      ),
       Effect.flatMap((answer) => {
         const id = isObject(answer) ? string(answer, "id") : undefined
         return id === undefined ? fail(op, Errors.invalidResponse(false, "missing_media_id")) : Effect.succeed(id)
diff --git a/packages/chat/whatsapp/src/internal/normalize.ts b/packages/chat/whatsapp/src/internal/normalize.ts
index 6c20b311ddb..b9e5fa3b394 100644
--- a/packages/chat/whatsapp/src/internal/normalize.ts
+++ b/packages/chat/whatsapp/src/internal/normalize.ts
@@ -62,6 +62,38 @@ export const groupMessages = (envelope: unknown): number => {
   return count
 }
 
+/** A changed phone number or BSUID, addressed by the user's new id. */
+const fromSystem = (
+  value: JsonObject,
+  metadata: JsonObject,
+  phoneNumberId: string,
+  message: JsonObject,
+  id: string,
+  at: DateTime.Utc | undefined
+): ReadonlyArray => {
+  const system = object(message, "system")
+  const change = string(system, "type")
+  if (change !== "user_changed_number" && change !== "user_changed_user_id") return []
+  const userId = string(system, "user_id")
+  const phone = string(system, "wa_id")
+  const next = userId ?? phone
+  if (next === undefined || !Address.isUser(next)) return []
+  const previousUserId = string(system, "previous_user_id")
+  const previousPhone = string(message, "from")
+  return [{
+    _tag: "UserIdChanged",
+    thread: Address.thread({ phoneNumberId, kind: "user", id: next }),
+    id,
+    change,
+    ...(userId === undefined ? {} : { userId }),
+    ...(previousUserId === undefined ? {} : { previousUserId }),
+    ...(phone === undefined ? {} : { phone }),
+    ...(previousPhone === undefined ? {} : { previousPhone }),
+    ...(at === undefined ? {} : { timestamp: at }),
+    raw: { metadata, contacts: array(value.contacts).filter(isObject), messages: [message] }
+  }]
+}
+
 const fromMessage = (
   value: JsonObject,
   metadata: JsonObject,
@@ -70,6 +102,10 @@ const fromMessage = (
 ): ReadonlyArray => {
   if (!isObject(message) || isGroupMessage(message)) return []
   const id = string(message, "id")
+  const at = timestamp(string(message, "timestamp"))
+  const type = string(message, "type")
+  // A changed BSUID can arrive with no sender at all: the new id is only in `system`.
+  if (type === "system") return id === undefined ? [] : fromSystem(value, metadata, phoneNumberId, message, id, at)
   const contacts = array(value.contacts).filter(isObject)
   const from = string(message, "from")
   const fromUserId = string(message, "from_user_id")
@@ -81,31 +117,7 @@ const fromMessage = (
   if (id === undefined || user === undefined || !Address.isUser(user)) return []
   const thread = Address.thread({ phoneNumberId, kind: "user", id: user })
   const raw: Json = { metadata, contacts: contact === undefined ? [] : [contact], messages: [message] }
-  const at = timestamp(string(message, "timestamp"))
-  const type = string(message, "type")
   switch (type) {
-    case "system": {
-      const system = object(message, "system")
-      const change = string(system, "type")
-      if (change !== "user_changed_number" && change !== "user_changed_user_id") return []
-      const next = string(system, "user_id") ?? string(system, "wa_id")
-      if (next === undefined || !Address.isUser(next)) return []
-      const userId = string(system, "user_id")
-      const previousUserId = string(system, "previous_user_id")
-      const phone = string(system, "wa_id")
-      return [{
-        _tag: "UserIdChanged",
-        thread: Address.thread({ phoneNumberId, kind: "user", id: next }),
-        id,
-        change,
-        ...(userId === undefined ? {} : { userId }),
-        ...(previousUserId === undefined ? {} : { previousUserId }),
-        ...(phone === undefined ? {} : { phone }),
-        ...(from === undefined ? {} : { previousPhone: from }),
-        ...(at === undefined ? {} : { timestamp: at }),
-        raw
-      }]
-    }
     case "reaction": {
       const reaction = object(message, "reaction")
       const emoji = string(reaction, "emoji")
diff --git a/packages/chat/whatsapp/src/internal/text.ts b/packages/chat/whatsapp/src/internal/text.ts
index 60b13ca500e..e697ca59cef 100644
--- a/packages/chat/whatsapp/src/internal/text.ts
+++ b/packages/chat/whatsapp/src/internal/text.ts
@@ -212,9 +212,11 @@ const link = (s: string, start: number, i: number): Atom | undefined => {
     const end = s.indexOf("]", close + 1)
     return end < 0 ? undefined : { end: end + 1, text: s.slice(start, end + 1) }
   }
-  if (s[close + 1] !== "(") return undefined
+  // A shortcut reference, or plain brackets: either way it is kept as typed.
+  const verbatim = { end: close + 1, text: s.slice(start, close + 1) }
+  if (s[close + 1] !== "(") return verbatim
   const target = destination(s, close + 1)
-  if (target === undefined) return undefined
+  if (target === undefined) return verbatim
   const label = s.slice(i + 1, close)
   const shown = start < i ? label : inline(label)
   const candidate = label === "" || label === target.url ? target.url : shown + " (" + target.url + ")"
@@ -345,10 +347,16 @@ export const render = (markdown: string): string => {
   let i = 0
   while (i < lines.length) {
     const line = body(i)
-    const fence = fenceOpen.exec(line)
+    const prefix = containerPrefix.exec(line)![0]
+    const rest = line.slice(prefix.length)
+    const fence = fenceOpen.exec(rest)
     if (fence !== null && !(fence[2][0] === "`" && fence[3].includes("`"))) {
+      // A fence inside a quote or list item closes on any line whose container markers precede the fence.
+      const nested = prefix !== ""
       const char = fence[2][0]
-      const closing = new RegExp("^ {0,3}" + (char === "~" ? "~" : "`") + "{" + fence[2].length + ",}[ \\t]*$")
+      const closing = new RegExp(
+        (nested ? "^[ \\t>]*" : "^ {0,3}") + (char === "~" ? "~" : "`") + "{" + fence[2].length + ",}[ \\t]*$"
+      )
       let j = i + 1
       while (j < lines.length && !closing.test(body(j))) j++
       if (j >= lines.length) {
@@ -358,10 +366,17 @@ export const render = (markdown: string): string => {
       const content = lines.slice(i + 1, j).join("")
       const source = lines.slice(i, j + 1).join("")
       const candidate = "```" + eol(i) + content + "```" + eol(j)
-      out += content.includes("```") ? source : pick(candidate, source)
+      out += nested || content.includes("```") ? source : pick(candidate, source)
       i = j + 1
       continue
     }
+    if (definition.test(rest)) {
+      // A definition's destination and title may continue on the next lines.
+      let j = i
+      while (j < lines.length && !isBlank(body(j).slice(containerPrefix.exec(body(j))![0].length))) out += lines[j++]
+      i = j
+      continue
+    }
     if (i + 1 < lines.length && line.includes("|") && tableDelimiter.test(body(i + 1)) && body(i + 1).includes("|")) {
       if (cells(line) === cells(body(i + 1))) {
         out += lines[i]
@@ -387,13 +402,12 @@ export const render = (markdown: string): string => {
       i += 2
       continue
     }
-    if (/^(?: {4}|\t)/.test(line) || thematicBreak.test(line) || definition.test(line)) {
+    if (/^(?: {4}|\t)/.test(line) || thematicBreak.test(line)) {
       out += lines[i]
       i++
       continue
     }
-    const prefix = containerPrefix.exec(line)![0]
-    out += prefix + inline(line.slice(prefix.length)) + eol(i)
+    out += prefix + inline(rest) + eol(i)
     i++
   }
   return out
diff --git a/packages/chat/whatsapp/src/internal/webhook.ts b/packages/chat/whatsapp/src/internal/webhook.ts
index 7c14dff9007..4de34aa7c4b 100644
--- a/packages/chat/whatsapp/src/internal/webhook.ts
+++ b/packages/chat/whatsapp/src/internal/webhook.ts
@@ -6,6 +6,7 @@ import * as Clock from "effect/Clock"
 import * as Mac from "effect/crypto/Mac"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
+import * as Fiber from "effect/Fiber"
 import type * as HttpServerRequest from "effect/http/HttpServerRequest"
 import * as HttpServerResponse from "effect/http/HttpServerResponse"
 import * as Option from "effect/Option"
@@ -135,7 +136,15 @@ export const receive = (
             Effect.provideService(ChatInteraction.Handler, handler.value),
             Effect.flatMap((reply) =>
               reply._tag === "OpenModal"
-                ? handler.value.refused(item, chatError("openModal", new Unsupported({ capability: "modals" })))
+                // Awaited only for what is left of the click's share, then left running.
+                ? Effect.forkDetach(
+                  handler.value.refused(item, chatError("openModal", new Unsupported({ capability: "modals" })))
+                ).pipe(
+                  Effect.flatMap((fiber) =>
+                    Effect.flatMap(options.clickDeadline, (left) => Effect.timeoutOption(Fiber.await(fiber), left))
+                  ),
+                  Effect.asVoid
+                )
                 : Effect.void
             )
           )
@@ -166,12 +175,30 @@ const clickMargin = 250
  *   longer than the deadline. Meta then delivers the batch again.
  * - A click gets what is left of the deadline, less a margin, so a slow
  *   click handler is detached rather than passing the deadline.
+ * - At the deadline the work is interrupted without waiting for its
+ *   finalizers, so a slow release can't hold the 503 past Meta's cutoff.
  *
  * @internal
  */
 export const handleRequest = (
   request: HttpServerRequest.HttpServerRequest,
   options: Options
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const fiber = yield* Effect.forkDetach(work(request, options))
+    const response = yield* Effect.onInterrupt(
+      Effect.timeoutOption(Fiber.join(fiber), options.deadline),
+      () => Fiber.interrupt(fiber)
+    )
+    if (Option.isSome(response)) return response.value
+    yield* Effect.forkDetach(Fiber.interrupt(fiber))
+    yield* Effect.logWarning(logged.deadline)
+    return status(503)
+  })
+
+const work = (
+  request: HttpServerRequest.HttpServerRequest,
+  options: Options
 ): Effect.Effect =>
   Effect.gen(function*() {
     const until = (yield* Clock.currentTimeMillis) + Duration.toMillis(options.deadline)
@@ -198,10 +225,4 @@ export const handleRequest = (
       Effect.as(ok),
       Effect.catchTag("NotAccepted", () => Effect.as(Effect.logWarning(logged.notAccepted), status(503)))
     )
-  }).pipe(
-    Effect.timeoutOption(options.deadline),
-    Effect.flatMap(Option.match({
-      onNone: () => Effect.as(Effect.logWarning(logged.deadline), status(503)),
-      onSome: Effect.succeed
-    }))
-  )
+  })
diff --git a/packages/chat/whatsapp/test/WhatsAppChat.test.ts b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
index 26fa9aa263d..c034aced154 100644
--- a/packages/chat/whatsapp/test/WhatsAppChat.test.ts
+++ b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
@@ -9,7 +9,9 @@ import type { ChatError } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { NotAccepted } from "effect/chat/ChatHandler"
 import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as ChatMarkdown from "effect/chat/ChatMarkdown"
 import type { Action } from "effect/chat/ChatUi"
+import * as Deferred from "effect/Deferred"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as HttpServerRequest from "effect/http/HttpServerRequest"
@@ -190,6 +192,21 @@ describe("post", () => {
       })
     }))
 
+  it.effect("posts the text alone when Meta refuses the upload", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      graph.next.set(phoneNumberId + "/media", graphError(131053))
+      yield* run(
+        graph,
+        ChatMarkdown.post(thread, "Report", {
+          files: [file("a.txt", "text/plain")],
+          unattachedNote: () => " (not attached)",
+          minWriteInterval: Duration.zero
+        })
+      )
+      assert.deepStrictEqual(graph.sent().map((body) => body.text.body), ["Report (not attached)"])
+    }))
+
   it.effect("maps 131047 to Forbidden outside the window", () =>
     Effect.gen(function*() {
       const graph = makeGraph()
@@ -218,7 +235,10 @@ const deliver = Effect.fnUntraced(function*(
   options?: {
     readonly signature?: string
     readonly refuse?: (event: ChatEvent.ChatEvent) => boolean
+    readonly handle?: (event: ChatEvent.ChatEvent) => Effect.Effect
     readonly onClick?: ChatInteraction.ClickReply
+    readonly onRefused?: (error: ChatError) => Effect.Effect
+    readonly deadline?: Duration.Duration
   }
 ) {
   const body = JSON.stringify(envelope)
@@ -236,9 +256,11 @@ const deliver = Effect.fnUntraced(function*(
       handle: (event) =>
         options?.refuse?.(event) === true
           ? Effect.fail(new NotAccepted({}))
+          : options?.handle !== undefined
+          ? options.handle(event)
           : Effect.sync(() => void seen.push(event._tag)),
       onUpdate: (update: WhatsAppUpdate) => Effect.sync(() => void seen.push(update._tag)),
-      deadline: Duration.seconds(4),
+      deadline: options?.deadline ?? Duration.seconds(4),
       maxBodyBytes: 1024 * 1024
     }
   ).pipe(Effect.provideService(
@@ -247,7 +269,8 @@ const deliver = Effect.fnUntraced(function*(
       click: (event) => Effect.sync(() => (seen.push(event._tag), options?.onClick ?? ChatInteraction.ack)),
       submit: () => Effect.succeed(ChatInteraction.close),
       command: () => Effect.succeed(ChatInteraction.ack),
-      refused: (_, error) => Effect.sync(() => void refused.push(error))
+      refused: (_, error) =>
+        Effect.andThen(Effect.sync(() => void refused.push(error)), options?.onRefused?.(error) ?? Effect.void)
     })
   ))
   return { status: response.status, seen, refused }
@@ -291,7 +314,18 @@ describe("webhook", () => {
       assert.deepStrictEqual([refused.status, refused.seen], [503, []])
     }))
 
-  it.effect("hands a click to the handler and refuses a modal as Unsupported", () =>
+  it.live("answers 503 at the deadline without waiting for a slow finalizer", () =>
+    Effect.gen(function*() {
+      const start = Date.now()
+      const result = yield* deliver(text, {
+        handle: () => Effect.never.pipe(Effect.ensuring(Effect.sleep("5 seconds"))),
+        deadline: Duration.millis(50)
+      })
+      assert.strictEqual(result.status, 503)
+      assert.isBelow(Date.now() - start, 2000)
+    }))
+
+  it.live("hands a click to the handler and refuses a modal as Unsupported", () =>
     Effect.gen(function*() {
       const click = inbound({
         type: "interactive",
@@ -299,9 +333,15 @@ describe("webhook", () => {
         interactive: { type: "list_reply", list_reply: { id: "senv\u241Fp\u241Fq", title: "Prod" } }
       })
       const modal = ChatInteraction.modal("m", { title: "M", fields: {} }).open()
-      const result = yield* deliver(click, { onClick: modal })
+      const refusal = yield* Deferred.make()
+      // The refusal callback never finishes, and the click is still answered 200.
+      const result = yield* deliver(click, {
+        onClick: modal,
+        onRefused: (error) => Effect.andThen(Deferred.succeed(refusal, error), Effect.never),
+        deadline: Duration.millis(500)
+      })
       assert.deepStrictEqual([result.status, result.seen], [200, ["SelectChanged"]])
-      assert.strictEqual(result.refused[0]?.reason._tag, "Unsupported")
+      assert.strictEqual((yield* Deferred.await(refusal)).reason._tag, "Unsupported")
       const [event] = WhatsAppChat.normalize(click, { phoneNumberId })
       assert.deepStrictEqual(event._tag === "SelectChanged" && [event.id, event.value, event.messageId], [
         "env",
@@ -311,6 +351,28 @@ describe("webhook", () => {
     }))
 })
 
+describe("normalize", () => {
+  it("reports a changed BSUID that arrives with no sender or contact", () => {
+    const envelope = inbound({
+      type: "system",
+      system: { type: "user_changed_user_id", user_id: "US.99", body: "changed" }
+    })
+    const value = envelope.entry[0].changes[0].value as any
+    delete value.contacts
+    delete value.messages[0].from
+    delete value.messages[0].from_user_id
+    const [update] = WhatsAppChat.normalize(envelope, { phoneNumberId })
+    assert.deepStrictEqual(
+      update._tag === "UserIdChanged" && [update.thread.id, update.userId, WhatsAppChat.updateKey(update)],
+      [
+        `${phoneNumberId}/u/US.99`,
+        "US.99",
+        `${phoneNumberId}/user_changed/${value.messages[0].id}`
+      ]
+    )
+  })
+})
+
 describe("keys", () => {
   it("keys a delivery by its webhook message, and an update by its parts", () => {
     const click = inbound({
diff --git a/packages/chat/whatsapp/test/text.test.ts b/packages/chat/whatsapp/test/text.test.ts
index 8cd42be842b..de8c85f139b 100644
--- a/packages/chat/whatsapp/test/text.test.ts
+++ b/packages/chat/whatsapp/test/text.test.ts
@@ -24,7 +24,11 @@ const cases: ReadonlyArray = [
   ["`**x**` ``a`` \\*x\\* **x**", "`**x**` ``a`` \\*x\\* *x*"],
   ["a_b_c and 2*3*4", "a_b_c and 2_3_4"],
   ["    **indented**", "    **indented**"],
-  ["- **item**\n> **quote**", "- *item*\n> *quote*"]
+  ["- **item**\n> **quote**", "- *item*\n> *quote*"],
+  ["[**x**] and ![**y**]\n\n[**x**]: https://e.com", "[**x**] and ![**y**]\n\n[**x**]: https://e.com"],
+  ["[r]:\n  \n  \"**t**\"\n\n**x**", "[r]:\n  \n  \"**t**\"\n\n*x*"],
+  ["> ~~~js\n> **x**\n> ~~~\n\n**y**", "> ~~~js\n> **x**\n> ~~~\n\n*y*"],
+  ["- ```\n  **x**\n  ```", "- ```\n  **x**\n  ```"]
 ]
 
 const longer = (input: string) => {

From 153e2c41bde9fd4ccd092357aabe6afa8026f2c6 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:41:43 +0000
Subject: [PATCH 66/89] Fix the second round of WhatsApp review findings

Fork the webhook worker under a mask so a cancellation always interrupts it, match a nested fence's closer inside the opener's quotes and list items, and end a kept definition or table at the start of a block.
---
 packages/chat/whatsapp/src/internal/text.ts   | 99 +++++++++++++++----
 .../chat/whatsapp/src/internal/webhook.ts     | 28 +++---
 .../chat/whatsapp/test/WhatsAppChat.test.ts   | 29 ++++++
 packages/chat/whatsapp/test/text.test.ts      | 13 ++-
 4 files changed, 137 insertions(+), 32 deletions(-)

diff --git a/packages/chat/whatsapp/src/internal/text.ts b/packages/chat/whatsapp/src/internal/text.ts
index e697ca59cef..2527180f4d8 100644
--- a/packages/chat/whatsapp/src/internal/text.ts
+++ b/packages/chat/whatsapp/src/internal/text.ts
@@ -327,12 +327,64 @@ const thematicBreak = /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/
 const definition = /^ {0,3}\[[^\]]+\]:/
 const blockStart = /^(?: {4}|\t| {0,3}(?:[>#|]|[-*+](?:[ \t]|$)|\d{1,9}[.)](?:[ \t]|$)|`{3}|~{3}))/
 const tableDelimiter = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/
-const containerPrefix = /^((?: {0,3}>[ \t]?)*)( {0,3}(?:[-*+]|\d{1,9}[.)])[ \t]+)?/
+const quoteMarker = /^ {0,3}>[ \t]?/
+const listMarker = /^( {0,3}(?:[-*+]|\d{1,9}[.)]))([ \t]+|$)/
 
 const cells = (row: string) => row.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").length
 
 const isBlank = (line: string) => line.trim() === ""
 
+/**
+ * The quotes and list items a line opens, outermost first, and the rest of
+ * the line. A quote is 0, and a list item the indentation its content needs.
+ */
+const containers = (line: string): { readonly stack: ReadonlyArray; readonly rest: string } => {
+  const stack: Array = []
+  let rest = line
+  while (true) {
+    const quote = quoteMarker.exec(rest)
+    if (quote !== null) {
+      stack.push(0)
+      rest = rest.slice(quote[0].length)
+      continue
+    }
+    const item = listMarker.exec(rest)
+    if (item === null || thematicBreak.test(rest)) break
+    // Five spaces or more after the marker start indented code, whose content starts after one.
+    const width = item[2] === "" || item[2].length >= 5 ? item[1].length + 1 : item[0].length
+    stack.push(width)
+    rest = rest.slice(Math.min(width, item[0].length))
+  }
+  return { stack, rest }
+}
+
+/** What is left of a line inside the containers of `stack`, or `undefined` when the line ends one of them. */
+const inside = (line: string, stack: ReadonlyArray): string | undefined => {
+  let rest = line
+  for (const width of stack) {
+    if (width === 0) {
+      const quote = quoteMarker.exec(rest)
+      if (quote === null) return undefined
+      rest = rest.slice(quote[0].length)
+      continue
+    }
+    if (isBlank(rest)) return ""
+    let column = 0
+    let k = 0
+    while (column < width && (rest[k] === " " || rest[k] === "\t")) {
+      column += rest[k] === "\t" ? 4 - (column % 4) : 1
+      k++
+    }
+    if (column < width) return undefined
+    rest = rest.slice(k)
+  }
+  return rest
+}
+
+/** Whether a line starts a block, which ends a definition or a table that was being kept as typed. */
+const opensBlock = (line: string) =>
+  fenceOpen.test(line) || atxHeading.test(line) || thematicBreak.test(line) || containers(line).stack.length > 0
+
 /**
  * Markdown as WhatsApp text, never longer than the Markdown in code points,
  * UTF-16 units or UTF-8 bytes.
@@ -347,33 +399,42 @@ export const render = (markdown: string): string => {
   let i = 0
   while (i < lines.length) {
     const line = body(i)
-    const prefix = containerPrefix.exec(line)![0]
-    const rest = line.slice(prefix.length)
+    const { rest, stack } = containers(line)
     const fence = fenceOpen.exec(rest)
     if (fence !== null && !(fence[2][0] === "`" && fence[3].includes("`"))) {
-      // A fence inside a quote or list item closes on any line whose container markers precede the fence.
-      const nested = prefix !== ""
-      const char = fence[2][0]
-      const closing = new RegExp(
-        (nested ? "^[ \\t>]*" : "^ {0,3}") + (char === "~" ? "~" : "`") + "{" + fence[2].length + ",}[ \\t]*$"
-      )
+      // The closer is matched inside the opener's quotes and list items. A line outside them ends the code too.
+      const closing = new RegExp("^ {0,3}" + (fence[2][0] === "~" ? "~" : "`") + "{" + fence[2].length + ",}[ \\t]*$")
       let j = i + 1
-      while (j < lines.length && !closing.test(body(j))) j++
-      if (j >= lines.length) {
-        out += lines.slice(i).join("")
-        break
+      let closed = false
+      for (; j < lines.length; j++) {
+        const code = inside(body(j), stack)
+        if (code === undefined) break
+        if (closing.test(code)) {
+          closed = true
+          break
+        }
+      }
+      if (!closed) {
+        out += lines.slice(i, j).join("")
+        i = j
+        continue
       }
       const content = lines.slice(i + 1, j).join("")
       const source = lines.slice(i, j + 1).join("")
       const candidate = "```" + eol(i) + content + "```" + eol(j)
-      out += nested || content.includes("```") ? source : pick(candidate, source)
+      out += stack.length > 0 || content.includes("```") ? source : pick(candidate, source)
       i = j + 1
       continue
     }
     if (definition.test(rest)) {
-      // A definition's destination and title may continue on the next lines.
-      let j = i
-      while (j < lines.length && !isBlank(body(j).slice(containerPrefix.exec(body(j))![0].length))) out += lines[j++]
+      // A destination or title may continue on the next lines, up to a blank line or the start of a block.
+      out += lines[i]
+      let j = i + 1
+      while (j < lines.length) {
+        const next = inside(body(j), stack) ?? body(j)
+        if (isBlank(next) || opensBlock(next)) break
+        out += lines[j++]
+      }
       i = j
       continue
     }
@@ -381,7 +442,7 @@ export const render = (markdown: string): string => {
       if (cells(line) === cells(body(i + 1))) {
         out += lines[i]
         let j = i + 2
-        while (j < lines.length && !isBlank(body(j))) out += lines[j++]
+        while (j < lines.length && !isBlank(body(j)) && !opensBlock(body(j))) out += lines[j++]
         i = j
         continue
       }
@@ -407,7 +468,7 @@ export const render = (markdown: string): string => {
       i++
       continue
     }
-    out += prefix + inline(rest) + eol(i)
+    out += line.slice(0, line.length - rest.length) + inline(rest) + eol(i)
     i++
   }
   return out
diff --git a/packages/chat/whatsapp/src/internal/webhook.ts b/packages/chat/whatsapp/src/internal/webhook.ts
index 4de34aa7c4b..8d0afc769af 100644
--- a/packages/chat/whatsapp/src/internal/webhook.ts
+++ b/packages/chat/whatsapp/src/internal/webhook.ts
@@ -184,17 +184,23 @@ export const handleRequest = (
   request: HttpServerRequest.HttpServerRequest,
   options: Options
 ): Effect.Effect =>
-  Effect.gen(function*() {
-    const fiber = yield* Effect.forkDetach(work(request, options))
-    const response = yield* Effect.onInterrupt(
-      Effect.timeoutOption(Fiber.join(fiber), options.deadline),
-      () => Fiber.interrupt(fiber)
-    )
-    if (Option.isSome(response)) return response.value
-    yield* Effect.forkDetach(Fiber.interrupt(fiber))
-    yield* Effect.logWarning(logged.deadline)
-    return status(503)
-  })
+  // Masked, so a cancellation can't land between forking the worker and
+  // arranging its interruption; only the wait itself is interruptible.
+  Effect.uninterruptibleMask((restore) =>
+    Effect.gen(function*() {
+      const fiber = yield* Effect.forkDetach(work(request, options))
+      // Interrupted without being awaited, here and at the deadline, so no finalizer delays the answer.
+      const stop = Effect.asVoid(Effect.forkDetach(Fiber.interrupt(fiber)))
+      const response = yield* Effect.onInterrupt(
+        restore(Effect.timeoutOption(Fiber.join(fiber), options.deadline)),
+        () => stop
+      )
+      if (Option.isSome(response)) return response.value
+      yield* stop
+      yield* Effect.logWarning(logged.deadline)
+      return status(503)
+    })
+  )
 
 const work = (
   request: HttpServerRequest.HttpServerRequest,
diff --git a/packages/chat/whatsapp/test/WhatsAppChat.test.ts b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
index c034aced154..3439e085860 100644
--- a/packages/chat/whatsapp/test/WhatsAppChat.test.ts
+++ b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
@@ -14,8 +14,10 @@ import type { Action } from "effect/chat/ChatUi"
 import * as Deferred from "effect/Deferred"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
+import * as Fiber from "effect/Fiber"
 import * as HttpServerRequest from "effect/http/HttpServerRequest"
 import * as Redacted from "effect/Redacted"
+import * as Scheduler from "effect/Scheduler"
 import {
   bsuid,
   graphError,
@@ -325,6 +327,33 @@ describe("webhook", () => {
       assert.isBelow(Date.now() - start, 2000)
     }))
 
+  it.live("interrupts the worker when the request is cancelled at any step", () =>
+    Effect.gen(function*() {
+      // Each budget makes the request yield, and be cancelled, at a different step.
+      for (let budget = 1; budget <= 40; budget++) {
+        let started = false
+        let stopped = false
+        const request = handleRequest(
+          HttpServerRequest.fromWeb(new Request("http://localhost/whatsapp", { method: "POST", body: "{}" })),
+          {
+            verify: () =>
+              Effect.andThen(
+                Effect.sync(() => (started = true)),
+                Effect.onInterrupt(Effect.never, () => Effect.sync(() => (stopped = true)))
+              ),
+            normalize: () => [],
+            handle: () => Effect.void,
+            deadline: Duration.seconds(4),
+            maxBodyBytes: 1024
+          }
+        ).pipe(Effect.provideService(Scheduler.MaxOpsBeforeYield, budget))
+        const fiber = yield* Effect.forkChild(request, { startImmediately: true })
+        yield* Fiber.interrupt(fiber)
+        yield* Effect.sleep("20 millis")
+        assert.isFalse(started && !stopped, `MaxOpsBeforeYield ${budget}`)
+      }
+    }))
+
   it.live("hands a click to the handler and refuses a modal as Unsupported", () =>
     Effect.gen(function*() {
       const click = inbound({
diff --git a/packages/chat/whatsapp/test/text.test.ts b/packages/chat/whatsapp/test/text.test.ts
index de8c85f139b..c61890ee0db 100644
--- a/packages/chat/whatsapp/test/text.test.ts
+++ b/packages/chat/whatsapp/test/text.test.ts
@@ -28,7 +28,12 @@ const cases: ReadonlyArray = [
   ["[**x**] and ![**y**]\n\n[**x**]: https://e.com", "[**x**] and ![**y**]\n\n[**x**]: https://e.com"],
   ["[r]:\n  \n  \"**t**\"\n\n**x**", "[r]:\n  \n  \"**t**\"\n\n*x*"],
   ["> ~~~js\n> **x**\n> ~~~\n\n**y**", "> ~~~js\n> **x**\n> ~~~\n\n*y*"],
-  ["- ```\n  **x**\n  ```", "- ```\n  **x**\n  ```"]
+  ["- ```\n  **x**\n  ```", "- ```\n  **x**\n  ```"],
+  ["> ~~~js\n> > ~~~\n> **x**\n> ~~~\n\n**y**", "> ~~~js\n> > ~~~\n> **x**\n> ~~~\n\n*y*"],
+  ["- > ~~~\n  >       ~~~\n  > **x**\n  > ~~~", "- > ~~~\n  >       ~~~\n  > **x**\n  > ~~~"],
+  ["> ~~~\n> **x**\n\n**y**", "> ~~~\n> **x**\n\n*y*"],
+  ["[r]: /url\n~~~js\n\n**x**\n~~~", "[r]: /url\n```\n\n**x**\n```"],
+  ["| a |\n|---|\n~~~\n\n**x**\n~~~", "| a |\n```\n\n**x**\n```"]
 ]
 
 const longer = (input: string) => {
@@ -77,7 +82,11 @@ describe("render", () => {
       "&#",
       "≫⃒",
       "~~~",
-      "x"
+      "x",
+      "> ",
+      "- ",
+      "  ",
+      "[r]: u"
     )
     fc.assert(fc.property(fc.array(token, { maxLength: 40 }), (tokens) => longer(tokens.join("")) === undefined))
   })

From 95ed7dd0ec40b7adde68f32360409609d0db45e3 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:45:46 +0000
Subject: [PATCH 67/89] Protect chat interaction startup from caller
 cancellation

---
 packages/effect/src/chat/ChatInteraction.ts   | 57 ++++++++++---------
 .../effect/test/chat/ChatInteraction.test.ts  | 34 ++++++++++-
 2 files changed, 64 insertions(+), 27 deletions(-)

diff --git a/packages/effect/src/chat/ChatInteraction.ts b/packages/effect/src/chat/ChatInteraction.ts
index cec3bbb4a56..68560824a4a 100644
--- a/packages/effect/src/chat/ChatInteraction.ts
+++ b/packages/effect/src/chat/ChatInteraction.ts
@@ -1679,33 +1679,38 @@ export const handle: {
     deadline: Duration.Duration
   ): Effect.Effect
 } = (event: Interaction, deadline: Duration.Duration): Effect.Effect =>
-  Effect.gen(function*() {
-    const handler = yield* Handler
-    // Detached, so the reply at the deadline waits for neither a late click nor a late submit's cleanup.
-    const fiber: Fiber.Fiber = yield* Effect.forkDetach(
-      event._tag === "ModalSubmitted"
-        ? handler.submit(event)
-        : event._tag === "CommandInvoked"
-        ? handler.command(event)
-        : handler.click(event)
-    )
-    const exit = yield* Effect.onInterrupt(
-      Effect.timeoutOption(Fiber.await(fiber), deadline),
-      () => Fiber.interrupt(fiber)
-    )
-    if (Option.isSome(exit)) return yield* exit.value
-    if (event._tag === "ModalSubmitted" || event._tag === "CommandInvoked") {
-      // Interrupt without delaying the deadline reply.
-      yield* Effect.forkDetach(Fiber.interrupt(fiber))
+  // Keep startup and the deadline handoff atomic with respect to caller interruption.
+  Effect.uninterruptibleMask((restore) =>
+    Effect.gen(function*() {
+      const handler = yield* Handler
+      // Detached, so the reply at the deadline waits for neither a late click nor a late submit's cleanup.
+      const fiber: Fiber.Fiber = yield* Effect.forkDetach(
+        event._tag === "ModalSubmitted"
+          ? handler.submit(event)
+          : event._tag === "CommandInvoked"
+          ? handler.command(event)
+          : handler.click(event)
+      )
+      const exit = yield* Effect.onInterrupt(
+        restore(Effect.timeoutOption(Fiber.await(fiber), deadline)),
+        () => Fiber.interrupt(fiber)
+      )
+      if (Option.isSome(exit)) return yield* exit.value
+      if (event._tag === "ModalSubmitted" || event._tag === "CommandInvoked") {
+        // Interrupt without delaying the deadline reply.
+        yield* Effect.forkDetach(Fiber.interrupt(fiber))
+        return late
+      }
+      yield* Effect.forkDetach(Effect.flatMap(
+        Fiber.await(fiber),
+        (exit) =>
+          Exit.isSuccess(exit) && exit.value._tag === "OpenModal"
+            ? handler.refused(event, lateClick(event))
+            : Effect.void
+      ))
       return late
-    }
-    yield* Effect.forkDetach(Effect.flatMap(
-      Fiber.await(fiber),
-      (exit) =>
-        Exit.isSuccess(exit) && exit.value._tag === "OpenModal" ? handler.refused(event, lateClick(event)) : Effect.void
-    ))
-    return late
-  })
+    })
+  )
 
 const late: Late = Late.make({})
 
diff --git a/packages/effect/test/chat/ChatInteraction.test.ts b/packages/effect/test/chat/ChatInteraction.test.ts
index 797c52da3f7..a0f04208318 100644
--- a/packages/effect/test/chat/ChatInteraction.test.ts
+++ b/packages/effect/test/chat/ChatInteraction.test.ts
@@ -1,5 +1,5 @@
 import { assert, describe, it } from "@effect/vitest"
-import { Deferred, Duration, Effect, Exit, Fiber, Layer, Option, Schema } from "effect"
+import { Deferred, Duration, Effect, Exit, Fiber, Layer, Option, Scheduler, Schema } from "effect"
 import { Chat, ChatError, ChatInteraction, ChatTest, ChatThread } from "effect/chat"
 import { TestClock } from "effect/testing"
 
@@ -216,6 +216,38 @@ describe("ChatInteraction", () => {
         refused: (_, error) => options.refused?.(error) ?? Effect.void
       })
 
+    it.effect("interrupts the handler when cancelled during startup", () =>
+      Effect.gen(function*() {
+        const release = yield* Deferred.make()
+        yield* Effect.gen(function*() {
+          // Cancel at successive scheduler yields, including between fork and cleanup registration.
+          for (let budget = 1; budget <= 40; budget++) {
+            let started = false
+            let stopped = false
+            const handler = handlerWith({
+              click: Effect.acquireUseRelease(
+                Effect.sync(() => {
+                  started = true
+                }),
+                () => Deferred.await(release),
+                () =>
+                  Effect.sync(() => {
+                    stopped = true
+                  })
+              )
+            })
+            const fiber = yield* ChatInteraction.handle(clicked("a"), deadline).pipe(
+              Effect.provideService(ChatInteraction.Handler, handler),
+              Effect.provideService(Scheduler.MaxOpsBeforeYield, budget),
+              Effect.forkChild({ startImmediately: true })
+            )
+            yield* Fiber.interrupt(fiber)
+            yield* TestClock.adjust("1 millis")
+            assert.isFalse(started && !stopped, `MaxOpsBeforeYield ${budget}`)
+          }
+        }).pipe(Effect.ensuring(Deferred.succeed(release, ChatInteraction.ack)))
+      }))
+
     it.effect("gives Late for a late click, and refuses its modal with interaction_expired", () =>
       Effect.gen(function*() {
         const refused = yield* Deferred.make()

From d18a86cd8c8edbfb609f7ea3bd5b87f7c510a564 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:48:00 +0000
Subject: [PATCH 68/89] Fix the Teams review findings

---
 packages/chat/teams/README.md                 |  77 ++++++++---
 packages/chat/teams/src/TeamsChat.ts          |  43 +++++--
 packages/chat/teams/src/internal/adapter.ts   |  68 ++++------
 packages/chat/teams/src/internal/auth.ts      |  51 ++++++--
 packages/chat/teams/src/internal/connector.ts |  35 ++++-
 packages/chat/teams/src/internal/download.ts  |  19 +--
 packages/chat/teams/src/internal/envelope.ts  |  71 +++++++++--
 .../chat/teams/src/internal/interactions.ts   |  49 ++++---
 packages/chat/teams/src/internal/render.ts    |  78 +++++++++++-
 packages/chat/teams/test/conformance.test.ts  |  70 +++++++++-
 packages/chat/teams/test/download.test.ts     |  10 ++
 packages/chat/teams/test/envelope.test.ts     |  14 +-
 packages/chat/teams/test/interactions.test.ts | 120 ++++++++++++++++++
 packages/chat/teams/test/length.test.ts       |  25 +++-
 packages/chat/teams/test/webhook.test.ts      |  38 +++++-
 15 files changed, 625 insertions(+), 143 deletions(-)
 create mode 100644 packages/chat/teams/test/interactions.test.ts

diff --git a/packages/chat/teams/README.md b/packages/chat/teams/README.md
index 7fec4084b52..cc4f5268fa8 100644
--- a/packages/chat/teams/README.md
+++ b/packages/chat/teams/README.md
@@ -2,7 +2,7 @@
 
 A [Microsoft Teams](https://www.microsoft.com/microsoft-teams) adapter for `effect/chat`, over the Bot Framework Connector. It includes the messaging endpoint, a pure activity normaliser, and the address helpers.
 
-This package is private. Nothing in it has run against a real tenant yet, and it stays private until the live checks below pass.
+This package is private. Nothing in it has run against a real tenant, the default capabilities included. It stays private until every check under [Release checks](#release-checks) has tenant evidence.
 
 ## Setup
 
@@ -28,13 +28,17 @@ const Teams = TeamsChat.layerWebhook({ path: "/api/messages" }).pipe(
 
 `TeamsChat.layer` needs `HttpClient`, the chat `Registry`, `Mac` and `Digest`. `TeamsChat.layerWebhook` needs `HttpRouter`, a `ChatHandler`, `HttpClient` and `Signature`. The adapter never calls `crypto.subtle` itself. Importing Bot Framework's public keys goes through `Jwk.importPublic`, which needs a `WebCrypto` reference whatever backend provides `Signature`.
 
+The `HttpClient` must add no credentials of its own and follow no redirects. The adapter decides per request which host gets the bot's token, asks Fetch for `redirect: "manual"`, and fails a response that came from another URL than the one it sent to. With a client other than `FetchHttpClient`, or middleware that rewrites requests, keep both properties.
+
 The cloud's endpoints and host allowlists come from `TeamsChat.publicCloud` or a `Cloud` of your own. They are configuration and are never read from an activity.
 
 ## Capabilities
 
-By default the descriptor advertises `edit`, `delete`, `getThread` and `getUser`, alongside `post`. `getUser` needs `in`, the thread whose roster to read.
+Every capability below is unverified against a tenant. They fall in three groups.
+
+**On by default:** `post`, `edit`, `delete`, `getThread` and `getUser`. `getUser` needs `in`, the thread whose roster to read.
 
-These capabilities are implemented but stay off until their live checks pass. Turn them on with the `unverified` option, at your own risk:
+**Implemented, off by default.** Turn these on with the `unverified` option, at your own risk. Turning one on advertises a capability no tenant has confirmed:
 
 | Option        | Turns on                                    | Also needs        |
 | ------------- | ------------------------------------------- | ----------------- |
@@ -46,25 +50,64 @@ These capabilities are implemented but stay off until their live checks pass. Tu
 
 A dialog opens only from a button whose id is listed in `modalButtons`. Any other `OpenModal` is refused as `Unsupported`.
 
-Not supported in this version: `fetchMessage`, `history` and `opener` (they need Microsoft Graph), `replyTo`, files, native streams and selects.
+**Not implemented in this version.** These are `Unsupported` whatever the options:
 
-## Security
+- `fetchMessage`, `history` and `opener`. They need Microsoft Graph, which is deferred.
+- `replyTo` (quoted replies).
+- Files: `filesPerMessage` is 0, and the size reservation holds nothing for them.
+- Native streams. Streams are posted and then edited.
+- Selects.
 
-- Inbound requests need a Bot Framework token: RS256, with a key endorsed for `msteams`, the cloud's issuer, the app id as audience, and a `serviceurl` claim equal to the activity's `serviceUrl`. The channel must be `msteams` and the tenant the configured one. Anything else is answered 403.
-- Button and dialog tokens are signed (HS256) and bound to the app, the tenant and the conversation. They are not encrypted: anyone who sees a card can read a button's id and value.
-- Button tokens have no replay protection. A click can be sent again for as long as the conversation exists. Dialog tokens also bind the user and expire after an hour.
-- A command's private answer goes as a targeted message to the user who sent the command. If that fails, the answer is not posted in public.
+The element caps are the adapter's own, since Teams publishes none: 6 elements per message and 10 fields per modal. `actionDataLength` (1,000) and `modalMetadataLength` (4,000) count the signed token that carries the data, envelope included. With a GUID app and tenant that leaves about 500 ASCII characters for a button's id and value, and about 1,900 for a modal's id and metadata.
 
-## Live checks
+## Security
 
-None of these have run yet. They need a Microsoft 365 developer tenant, an Azure Bot resource and a public tunnel to the endpoint.
+- Inbound requests need a Bot Framework token: RS256, with a key endorsed for `msteams`, the cloud's issuer, the app id as audience, and a `serviceurl` claim equal to the activity's `serviceUrl`. The channel must be `msteams` and the tenant the configured one. Anything else is answered 403. The OpenID metadata and the key set are fetched with redirects off. Metadata over 64 KiB, or with a `jwks_uri` that is not a URL, is answered 503.
+- The bot's token goes only to a Connector host from the cloud's allowlist, over `https:` on the default port. A download sends it only when the first URL is on its own class's allowlist. `redirectHosts` admits a host as a redirect target, never as the first hop, and a redirect hop gets no token.
+- Button and dialog tokens are signed (HS256) and bound to the app, the tenant and the conversation. They are not encrypted: anyone who sees a card can read a button's id and value, and a modal's metadata. Do not put secrets in them.
+- Button tokens have no replay protection. A click can be sent again for as long as the conversation exists. Dialog tokens also bind the user and the exact conversation id of the click, and expire after an hour. Signing does not stop a submit from arriving twice, so handlers still authorise and stay idempotent.
+- A command's private answer goes as a targeted message to the user who sent the command. If that fails, the answer is not posted in public.
 
-- Base: posting, editing and deleting in a channel, a group chat and a personal chat; inbound messages and reactions; user ids; the message size budget (`messageLength` is 44,288 units, derived from a provisional 50,000-unit activity size).
-- `startThread`: replies addressed with `;messageid=`.
-- `buttons`: `Action.Execute` and its `Action.Submit` fallback reach the endpoint, with the signed token intact.
-- `modals` and `modalErrors`: `task/fetch` and `task/submit`, and a dialog kept open with field errors.
-- `commands` and `ephemeral`: targeted messages in and out.
-- `download`: Connector-hosted and pre-authorised file URLs.
+## Release checks
+
+None of these has run. They need a Microsoft 365 developer tenant, an Azure Bot resource and a public tunnel to the endpoint. Each check gates only what it names. A failed check removes that capability, or blocks release when it gates the base.
+
+| Gate                                             | Checks                                                                                                                              | If a check fails                                                                                                       |
+| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
+| Base: `post`, `edit`, `delete`, events, user ids | 1, 12, 4, 8, 9, 10, 16, 7, 18                                                                                                       | No release. Check 4 failing for an op brings in a `serviceUrl` resolver first. Check 10 failing changes the docs only. |
+| `startThread`                                    | 12                                                                                                                                  | Absent                                                                                                                 |
+| `buttons`                                        | 1, 9, 2, 3                                                                                                                          | Absent, or absent from private answers only                                                                            |
+| `modals`                                         | 17, the `task/fetch` and `task/submit` envelopes, the older-client fallback, `Ack` on a declared button leaving nothing open, 2, 13 | Absent                                                                                                                 |
+| `modalErrors`                                    | 13                                                                                                                                  | Absent: `Errors` then closes the dialog and sends a private message                                                    |
+| `commands`, `ephemeral`                          | 3, 4                                                                                                                                | Absent. Targeted activities are still classified first and never reach anything public.                                |
+| Native streams                                   | 5, 4                                                                                                                                | Stays absent, so post-then-edit                                                                                        |
+| `replyTo`                                        | 14                                                                                                                                  | Stays absent                                                                                                           |
+| Files                                            | 1, and the attachment header limits Teams accepts                                                                                   | Stay absent                                                                                                            |
+| `download`                                       | 18                                                                                                                                  | Absent                                                                                                                 |
+| Reaction events                                  | 11                                                                                                                                  | Unknown types pass through as the raw string                                                                           |
+| Graph reads                                      | 6, and history ordering                                                                                                             | Deferred                                                                                                               |
+| Selects                                          | 15                                                                                                                                  | Not in v1, so it gates nothing                                                                                         |
+
+The checks:
+
+1. The text form and the card form each arrive as one message with an id that `PUT` can edit, and `PUT` can switch between them. For files, an attachments-only activity with a card and images is one message.
+2. The deadline for `adaptiveCard/action`, `task/fetch` and `task/submit` answers, and the failure answer that shows nothing unsafe.
+3. The wire shape of a slash command in each scope: a leading slash or not, where the targeted flag appears (expected `recipient.isTargeted`), whether personal chats show the slash menu, no public fallback on failure, no Prompt Preview on a public answer, and a click on a private answer making no public activity.
+4. Edit, delete, streaming and targeted sends all work through the global `serviceUrl`, and a targeted send works through the inbound `serviceUrl`.
+5. Streaming over raw REST in group chats and channels, with a stored `replyTo` after the inbound request has returned, and a second stream answering the same message after a rotation.
+6. Whether the Connector's activity id equals the Graph message id, and the Graph chat id of a personal bot chat.
+7. Member lookup, targeted recipients and mention entities accept an Entra object id.
+8. How `<`, `&` and `$` are escaped in `extendedmarkdown`, and whether bot messages unfurl links.
+9. The real size edge for text and for cards. It sets `Edge` and the reservation `R`, and may only raise a term.
+10. Whether a non-2xx answer is redelivered, and whether a retry keeps the activity id.
+11. Reaction `type` strings beyond the six documented ones.
+12. Which route makes a new top-level channel post and returns its id, and that the id is the reply chain's root.
+13. Whether `ContinueTask` re-renders the dialog in place, where the errors show, and the size cap of a dialog card.
+14. Quoted replies over raw REST in channels and group chats.
+15. That `Input.ChoiceSet` has no submit-on-change in current Teams clients.
+16. The issuer, audience and endorsements on inbound tokens for a single-tenant registration.
+17. Whether an `adaptiveCard/action` answer can carry a task continuation that opens a dialog. If it can, `modalButtons` goes away.
+18. The hosts actually seen for `serviceUrl`, image `contentUrl` and `downloadUrl` in each cloud and scope, and their redirect chains. These are written into the cloud presets. Nothing is added at runtime.
 
 ## Links
 
diff --git a/packages/chat/teams/src/TeamsChat.ts b/packages/chat/teams/src/TeamsChat.ts
index 43cb750d1bb..968147cdbe6 100644
--- a/packages/chat/teams/src/TeamsChat.ts
+++ b/packages/chat/teams/src/TeamsChat.ts
@@ -9,13 +9,17 @@
  *   registration. The cloud's endpoints and host allowlists come as a unit
  *   from `publicCloud` or a `Cloud` of the consumer's own. They are
  *   privileged configuration and never read from an activity.
- * - Nothing here has run against a real tenant yet. The package is private
- *   until it has. Capabilities beyond posting, editing, deleting and
- *   reading threads and users are behind `unverified` options, off by
- *   default, so a descriptor never advertises what no tenant confirmed.
- * - Reading messages (`fetchMessage`, `history`, `opener`) needs
- *   Microsoft Graph, which this version does not use. They are
- *   `Unsupported`, as are `replyTo`, files and native streams.
+ * - Nothing here has run against a real tenant, the default capabilities
+ *   included. The package stays private until every release check in the
+ *   README has tenant evidence.
+ * - Implemented but unverified, and off by default: `buttons`, `modals`,
+ *   `modalErrors`, `commands`, `ephemeral`, `startThread` and
+ *   `download`, each behind an `unverified` option. Turning one on
+ *   advertises a capability no tenant has confirmed.
+ * - Not implemented in this version, whatever the options: reading
+ *   messages (`fetchMessage`, `history`, `opener`, which need Microsoft
+ *   Graph), `replyTo`, files, native streams and selects. They are
+ *   `Unsupported`.
  *
  * @stability unstable
  * @since 4.1.5
@@ -186,7 +190,8 @@ export class TeamsChat extends Context.Service` mention forms. Mentions notify nobody.
+ *   so no HTML and no `` mention forms, and every `$` outside code as
+ *   `\$`, so Teams reads no math. Mentions notify nobody.
  * - With elements, the message is one Adaptive Card and no `text`:
  *   `TextBlock`, `CodeBlock` and `Table` elements from the Markdown, then
  *   `ActionSet` rows. An `edit` may switch between the two forms.
@@ -202,10 +207,19 @@ export class TeamsChat extends Context.Service Effect.Effect
 }
 
-/**
- * Swaps the action of each button that opens a dialog for an
- * `Action.Submit` with `task/fetch`, which is smaller than the
- * `Action.Execute` and its fallback that the measure counted.
- */
-const opensDialogs = (
-  activity: Record,
-  modalButtons: ReadonlySet,
-  tokens: ReadonlyMap
-): Record => {
-  const openers = new Map()
-  for (const [action, token] of tokens) {
-    if (action._tag === "Button" && modalButtons.has(action.id)) openers.set(token, action)
-  }
-  if (openers.size === 0) return activity
-  const swap = (node: unknown): unknown => {
-    if (Array.isArray(node)) return node.map(swap)
-    if (typeof node !== "object" || node === null) return node
-    const record = node as Record
-    const data = record.data as Record | undefined
-    const token = record.type === "Action.Execute" && typeof data?.effect === "string" ? data.effect : undefined
-    const opener = token === undefined ? undefined : openers.get(token)
-    if (opener !== undefined) {
-      return { type: "Action.Submit", title: opener.label, data: { msteams: { type: "task/fetch" }, effect: token } }
-    }
-    const out: Record = {}
-    for (const [key, value] of Object.entries(record)) out[key] = swap(value)
-    return out
-  }
-  return swap(activity) as Record
-}
-
 const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
 
 /** @internal */
@@ -198,7 +179,7 @@ export const make = (options: Options): Made => {
       const tokens = new Map()
       for (const action of actions) {
         if (action._tag !== "Button") continue
-        if (action.id.length + (action.value?.length ?? 0) > actionDataLength) {
+        if (options.envelope!.tokenLength(action) > actionDataLength) {
           return yield* fail(op, Errors.tooLarge(undefined, "action_data_too_long"))
         }
         const token = yield* Effect.mapError(
@@ -210,10 +191,11 @@ export const make = (options: Options): Made => {
         )
         tokens.set(action, token)
       }
-      return opensDialogs(
-        Render.cardActivity(content.markdown, actions, (button) => tokens.get(button)!),
-        options.modalButtons,
-        tokens
+      return Render.cardActivity(
+        content.markdown,
+        actions,
+        (button) => tokens.get(button)!,
+        (button) => options.modalButtons.has(button.id)
       )
     })
 
@@ -355,10 +337,10 @@ export const make = (options: Options): Made => {
     for (const id of [conversationId, messageId, recipientId]) yield* checkId(op, id)
     const activity = yield* body(op, conversationId, content)
     if (visibility === "ephemeral") {
-      const name = string(from, "name")
       yield* connector.call("POST", activities(conversationId), {
         ...activity,
-        recipient: { id: recipientId, ...(name === undefined ? {} : { name }) },
+        // Only the id: `Length.A` reserves it, and an unbounded name would break the size bound.
+        recipient: { id: recipientId },
         entities: [{ type: "targetedMessageInfo", messageId }]
       }, { write: true, op, serviceUrl, query: { isTargetedActivity: "true" } })
     } else {
diff --git a/packages/chat/teams/src/internal/auth.ts b/packages/chat/teams/src/internal/auth.ts
index 36fd4213ecd..b5c8d22d0d0 100644
--- a/packages/chat/teams/src/internal/auth.ts
+++ b/packages/chat/teams/src/internal/auth.ts
@@ -4,12 +4,14 @@ import * as Effect from "effect/Effect"
 import * as Exit from "effect/Exit"
 import * as HttpClient from "effect/http/HttpClient"
 import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import type * as HttpClientResponse from "effect/http/HttpClientResponse"
 import * as Jwks from "effect/jose/Jwks"
 import * as Jwt from "effect/jose/Jwt"
 import * as Schema from "effect/Schema"
 import * as Scope from "effect/Scope"
 import * as Semaphore from "effect/Semaphore"
-import { type Cloud, send } from "./connector.ts"
+import * as Stream from "effect/Stream"
+import { type Cloud, noRedirects, send } from "./connector.ts"
 
 /** The longest `Authorization` header read. Anything longer is refused unread. */
 const maxAuthorizationLength = 16 * 1024
@@ -37,6 +39,34 @@ export const endorsedForTeams = (jwk: { readonly [key: string]: unknown }): bool
     endorsements.includes("msteams")
 }
 
+const parseUrl = (input: string): URL | undefined => {
+  try {
+    return new URL(input)
+  } catch {
+    return undefined
+  }
+}
+
+/** The body, or `undefined` once it passes `maxBytes` or can't be read. Never reads past the limit. */
+const readBounded = (
+  response: HttpClientResponse.HttpClientResponse,
+  maxBytes: number
+): Effect.Effect => {
+  const declared = Number(response.headers["content-length"])
+  if (Number.isFinite(declared) && declared > maxBytes) return Effect.succeed(undefined)
+  const body = new Uint8Array(maxBytes)
+  return Stream.runFoldEffect(response.stream, () => 0, (length, chunk) =>
+    chunk.length > maxBytes - length
+      ? Effect.fail("too_large" as const)
+      : Effect.sync(() => {
+        body.set(chunk, length)
+        return length + chunk.length
+      })).pipe(
+      Effect.map((length) => body.subarray(0, length)),
+      Effect.orElseSucceed(() => undefined)
+    )
+}
+
 const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
 
 /** @internal */
@@ -69,7 +99,9 @@ export const tenantOf = (activity: Record): string | undefined
  *
  * The key set is found lazily from the cloud's OpenID metadata, whose
  * `jwks_uri` must be `https:` on the metadata's own host. Neither fetch
- * follows a redirect. A key set that can't be read is `unavailable`, so
+ * follows a redirect: the key set's client has Fetch's redirects off for
+ * each request, refreshes included. The metadata is read to at most 64 KiB.
+ * Metadata that can't be fetched, read or parsed is `unavailable`. A key set that can't be read is `unavailable`, so
  * the webhook answers 503 and Teams retries; every other failure is
  * `forbidden`.
  *
@@ -88,20 +120,21 @@ export const makeVerifier = Effect.fnUntraced(function*(options: {
   let failedAt = Number.NEGATIVE_INFINITY
 
   const jwksUri = Effect.gen(function*() {
-    const metadataUrl = new URL(options.cloud.openIdMetadataUrl)
+    const metadataUrl = parseUrl(options.cloud.openIdMetadataUrl)
+    if (metadataUrl === undefined) return yield* Effect.fail("metadata_url" as const)
     const response = yield* send(http, HttpClientRequest.get(metadataUrl.href), false, "openIdMetadata")
     if (response.status !== 200) return yield* Effect.fail("metadata_status" as const)
-    const body = yield* Effect.orElseSucceed(response.text, () => "")
-    if (body.length === 0 || body.length > maxMetadataBytes) return yield* Effect.fail("metadata_size" as const)
+    const body = yield* readBounded(response, maxMetadataBytes)
+    if (body === undefined || body.length === 0) return yield* Effect.fail("metadata_size" as const)
     let json: unknown
     try {
-      json = JSON.parse(body)
+      json = JSON.parse(new TextDecoder().decode(body))
     } catch {
       return yield* Effect.fail("metadata_json" as const)
     }
     const uri = isObject(json) ? json.jwks_uri : undefined
-    if (typeof uri !== "string") return yield* Effect.fail("metadata_jwks_uri" as const)
-    const parsed = new URL(uri)
+    const parsed = typeof uri === "string" ? parseUrl(uri) : undefined
+    if (parsed === undefined) return yield* Effect.fail("metadata_jwks_uri" as const)
     if (parsed.protocol !== "https:" || parsed.port !== "" || parsed.hostname !== metadataUrl.hostname) {
       return yield* Effect.fail("metadata_jwks_host" as const)
     }
@@ -117,7 +150,7 @@ export const makeVerifier = Effect.fnUntraced(function*(options: {
     const made = yield* jwksUri.pipe(
       Effect.flatMap((url) => Jwks.makeRemote({ url, filter: endorsedForTeams })),
       Effect.provideService(Scope.Scope, scope),
-      Effect.provideService(HttpClient.HttpClient, http),
+      Effect.provideService(HttpClient.HttpClient, noRedirects(http)),
       Effect.option
     )
     if (made._tag === "None") {
diff --git a/packages/chat/teams/src/internal/connector.ts b/packages/chat/teams/src/internal/connector.ts
index 733974b85d0..435676f414d 100644
--- a/packages/chat/teams/src/internal/connector.ts
+++ b/packages/chat/teams/src/internal/connector.ts
@@ -5,9 +5,10 @@ import * as DateTime from "effect/DateTime"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as FetchHttpClient from "effect/http/FetchHttpClient"
-import type * as HttpClient from "effect/http/HttpClient"
+import * as HttpClient from "effect/http/HttpClient"
 import * as HttpClientRequest from "effect/http/HttpClientRequest"
 import type * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
 import type * as Schema from "effect/Schema"
 import * as Semaphore from "effect/Semaphore"
@@ -157,9 +158,34 @@ export const makeTokens = (options: {
     }))
 }
 
+/**
+ * The client with Fetch's redirects off, for every request it sends,
+ * including those made by code the adapter hands it to, such as the key set.
+ *
+ * @internal
+ */
+export const noRedirects = (http: HttpClient.HttpClient): HttpClient.HttpClient =>
+  HttpClient.transform(
+    http,
+    (effect) => Effect.provideService(effect, FetchHttpClient.RequestInit, { redirect: "manual" })
+  )
+
+/**
+ * The URL a request goes to, with its query parameters and without a hash.
+ *
+ * @internal
+ */
+export const effectiveUrl = (request: HttpClientRequest.HttpClientRequest): string | undefined => {
+  const url = Option.getOrUndefined(HttpClientRequest.toUrl(request))
+  if (url === undefined) return undefined
+  url.hash = ""
+  return url.href
+}
+
 /**
  * Sends one request with redirects off. A response from another URL than
- * the request's means something followed a redirect, and is refused.
+ * the request's, query included, means something followed a redirect, and
+ * is refused.
  *
  * @internal
  */
@@ -169,11 +195,10 @@ export const send = (
   write: boolean,
   op: string
 ): Effect.Effect =>
-  http.execute(request).pipe(
-    Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }),
+  noRedirects(http).execute(request).pipe(
     Effect.catch((error) => Effect.fail(Errors.chatError(op, Errors.transport(write, error.reason._tag, error)))),
     Effect.flatMap((response) =>
-      response.url !== "" && response.url !== request.url
+      response.url !== effectiveUrl(request)
         ? Effect.fail(Errors.chatError(op, Errors.untrustedUrl()))
         : Effect.succeed(response)
     )
diff --git a/packages/chat/teams/src/internal/download.ts b/packages/chat/teams/src/internal/download.ts
index 399a82a9123..bafa3187dc5 100644
--- a/packages/chat/teams/src/internal/download.ts
+++ b/packages/chat/teams/src/internal/download.ts
@@ -182,9 +182,10 @@ const fail = (reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reaso
 /**
  * Streams the file behind an attachment id.
  *
- * Every hop, the first and each redirect, must pass {@link safeUrl} and have a
- * host in the id's allowlist (exact `connectorHosts` for `connector:`,
- * `fileHostSuffixes` for `preauth:`) or in `redirectHosts`. The first hop of a
+ * Every hop must pass {@link safeUrl}. The first must have a host in the id's
+ * own allowlist (exact `connectorHosts` for `connector:`, `fileHostSuffixes`
+ * for `preauth:`), and a redirect a host there or in `redirectHosts`. A
+ * redirect host never receives the token. The first hop of a
  * `connector:` id must also have the {@link connectorPath} shape. A URL that
  * fails fails `Forbidden` with detail `untrusted_url`.
  *
@@ -219,15 +220,17 @@ export function download(
     if (parsed.kind === "url") return yield* fail(Errors.unsupported("download", "url_attachment"))
     const { kind } = parsed
     const redirectHosts = options.redirectHosts ?? new Set()
-    const allowed = (url: URL): boolean =>
-      (kind === "connector"
+    // The id's own allowlist. `redirectHosts` never vouches for the first
+    // hop, since the first hop of a `connector:` id is the one with the token.
+    const own = (url: URL): boolean =>
+      kind === "connector"
         ? options.connectorHosts.has(url.hostname)
-        : underSuffix(url.hostname, options.fileHostSuffixes))
-      || redirectHosts.has(url.hostname)
+        : underSuffix(url.hostname, options.fileHostSuffixes)
+    const allowed = (url: URL): boolean => own(url) || redirectHosts.has(url.hostname)
 
     const first = safeUrl(parsed.url)
     if (
-      first === undefined || !allowed(first) ||
+      first === undefined || !own(first) ||
       (kind === "connector" && (first.search !== "" || !connectorPath.test(first.pathname)))
     ) {
       return yield* fail(Errors.untrustedUrl())
diff --git a/packages/chat/teams/src/internal/envelope.ts b/packages/chat/teams/src/internal/envelope.ts
index bab628a9748..dfdd91ed13c 100644
--- a/packages/chat/teams/src/internal/envelope.ts
+++ b/packages/chat/teams/src/internal/envelope.ts
@@ -99,6 +99,7 @@ const DialogClaims = Schema.Struct({
   aud: Id,
   tid: Id,
   cnv: Hash,
+  cid: Id,
   sub: Id,
   exp: Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER })),
   mid: Schema.optionalKey(Id),
@@ -130,8 +131,9 @@ export const maxTokenLength: number = (() => {
   const header = utf8Length(headerJson("", typ.dialog)) + limits.kid
   const button = utf8Length(JSON.stringify({ aud: "", tid: "", cnv: "", id: "", val: "" })) - 2 * 5 +
     3 * jsonString(limits.id) + jsonString(hashLength) + jsonString(limits.buttonValue)
-  const dialog = utf8Length(JSON.stringify({ aud: "", tid: "", cnv: "", sub: "", exp: 0, mid: "", def: 0, md: "" })) -
-    2 * 6 - 2 + 4 * jsonString(limits.id) + jsonString(hashLength) + String(Number.MAX_SAFE_INTEGER).length +
+  const dialog =
+    utf8Length(JSON.stringify({ aud: "", tid: "", cnv: "", cid: "", sub: "", exp: 0, mid: "", def: 0, md: "" })) -
+    2 * 7 - 2 + 5 * jsonString(limits.id) + jsonString(hashLength) + String(Number.MAX_SAFE_INTEGER).length +
     limits.definition + jsonString(limits.metadata)
   return base64Length(header) + 1 + base64Length(Math.max(button, dialog)) + 1 + signatureLength
 })()
@@ -171,6 +173,34 @@ export const buttonTokenLength = (
   base64Length(utf8Length(JSON.stringify(buttonClaims(context, "x".repeat(hashLength), button)))) + 1 +
   signatureLength
 
+const longestId = "x".repeat(limits.id)
+
+/**
+ * What a modal's id and metadata take in a dialog token, with everything
+ * the adapter adds: the header, the fixed claims with each id at its
+ * longest, the definition's shell and the signature. The rest of the
+ * definition (title, labels, options) is held to `limits.definition`
+ * instead. Pure: the same modal always gives the same length.
+ *
+ * @internal
+ */
+export const dialogTokenLength = (
+  context: ButtonContext,
+  modal: { readonly id: string; readonly metadata?: string | undefined }
+): number =>
+  base64Length(utf8Length(headerJson(context.kid, typ.dialog))) + 1 +
+  base64Length(utf8Length(JSON.stringify({
+    aud: context.appId,
+    tid: context.tenantId,
+    cnv: "x".repeat(hashLength),
+    cid: longestId,
+    sub: longestId,
+    exp: Number.MAX_SAFE_INTEGER,
+    mid: longestId,
+    def: { _tag: "Modal", id: modal.id, title: "", elements: [] },
+    ...(modal.metadata === undefined ? {} : { md: modal.metadata })
+  }))) + 1 + signatureLength
+
 // Checks
 
 /** Whether a field of `modal` uses the reserved `effect` id. @internal */
@@ -266,6 +296,11 @@ export interface Button {
 
 /** @internal */
 export interface Dialog {
+  /**
+   * The conversation id the click came from, as Teams sent it. A submit
+   * must come from the same one.
+   */
+  readonly conversationId: string
   /** The message the click came from. Absent when a command opened it. */
   readonly messageId?: string | undefined
   readonly modal: ChatUi.Modal
@@ -282,16 +317,20 @@ export interface Envelope {
   ) => Effect.Effect>
   /** Fails with the reason the modal or an id is refused. */
   readonly signDialog: (
-    conversationId: string,
     dialog: Dialog & { readonly userId: string; readonly ttl?: Duration.Input | undefined }
   ) => Effect.Effect
-  /** The dialog the token was signed for, if it is unexpired and for this conversation and user. */
+  /**
+   * The dialog the token was signed for, if it is unexpired, for this user,
+   * and from exactly this conversation id.
+   */
   readonly verifyDialog: (
     token: unknown,
     activity: { readonly conversationId: string; readonly userId: string }
   ) => Effect.Effect>
   /** `buttonTokenLength` with this envelope's app, tenant and signing key. */
   readonly tokenLength: (button: Button) => number
+  /** `dialogTokenLength` with this envelope's app, tenant and signing key. */
+  readonly dialogLength: (modal: { readonly id: string; readonly metadata?: string | undefined }) => number
 }
 
 const validKid = /^[A-Za-z0-9_-]{1,16}$/
@@ -372,9 +411,10 @@ export const make = Effect.fnUntraced(function*(options: {
         verify(ButtonClaims, token, typ.button, activity.conversationId, {}),
         Option.map((claims) => ({ id: claims.id, ...(claims.val === undefined ? {} : { value: claims.val }) }))
       ),
-    signDialog: (conversationId, dialog) => {
+    signDialog: (dialog) => {
       const refusal = checkModal(dialog.modal) ??
-        (dialog.userId.length > limits.id || (dialog.messageId?.length ?? 0) > limits.id
+        (dialog.userId.length > limits.id || (dialog.messageId?.length ?? 0) > limits.id ||
+            dialog.conversationId.length > limits.id
           ? invalidRequest("id_too_long")
           : undefined)
       if (refusal !== undefined) return Effect.fail(refusal)
@@ -385,7 +425,8 @@ export const make = Effect.fnUntraced(function*(options: {
         return yield* sign(DialogClaims, {
           aud: options.appId,
           tid: options.tenantId,
-          cnv: yield* hash(conversationId),
+          cnv: yield* hash(dialog.conversationId),
+          cid: dialog.conversationId,
           sub: dialog.userId,
           exp,
           ...(dialog.messageId === undefined ? {} : { mid: dialog.messageId }),
@@ -400,11 +441,17 @@ export const make = Effect.fnUntraced(function*(options: {
           subject: activity.userId,
           requiredClaims: ["exp", "sub"]
         }),
-        Option.map((claims): Dialog => ({
-          ...(claims.mid === undefined ? {} : { messageId: claims.mid }),
-          modal: { ...claims.def, ...(claims.md === undefined ? {} : { metadata: claims.md }) }
-        }))
+        (verified) =>
+          verified.pipe(
+            Option.filter((claims) => claims.cid === activity.conversationId),
+            Option.map((claims): Dialog => ({
+              conversationId: claims.cid,
+              ...(claims.mid === undefined ? {} : { messageId: claims.mid }),
+              modal: { ...claims.def, ...(claims.md === undefined ? {} : { metadata: claims.md }) }
+            }))
+          )
       ),
-    tokenLength: (button) => buttonTokenLength(context, button)
+    tokenLength: (button) => buttonTokenLength(context, button),
+    dialogLength: (modal) => dialogTokenLength(context, modal)
   }
 })
diff --git a/packages/chat/teams/src/internal/interactions.ts b/packages/chat/teams/src/internal/interactions.ts
index c2da0365bdc..9b42b431d0d 100644
--- a/packages/chat/teams/src/internal/interactions.ts
+++ b/packages/chat/teams/src/internal/interactions.ts
@@ -64,9 +64,7 @@ const refused = (event: ChatInteraction.ButtonClicked | ChatInteraction.CommandI
  * Where the message an invoke came from lives. A card posted as a channel
  * post has the channel as its address, as `normalize` gives it.
  */
-const cardThread = (activity: JsonObject): ChatThread | undefined => {
-  const conversationId = string(object(activity, "conversation"), "id")
-  const messageId = string(activity, "replyToId")
+const cardThread = (conversationId: string | undefined, messageId: string | undefined): ChatThread | undefined => {
   if (conversationId === undefined || conversationId.length > Address.maxIdLength) return undefined
   const parts = Address.parts(Address.thread(conversationId))
   if (Option.isNone(parts)) return undefined
@@ -76,7 +74,21 @@ const cardThread = (activity: JsonObject): ChatThread | undefined => {
 }
 
 /** The adaptive card of a dialog, built only from the signed definition. */
-const dialogCard = (modal: ChatUi.Modal, token: string, errors?: Readonly>) => {
+const dialogCard = (
+  modal: ChatUi.Modal,
+  token: string,
+  submitted?: {
+    readonly values: Readonly>
+    readonly errors: Readonly>
+  }
+) => {
+  // A dialog sent again with errors keeps what the user entered, not the
+  // definition's `initial`. Lookups are own properties only, so a field id
+  // such as `constructor` reads nothing inherited.
+  const own = (record: Readonly>, key: string): string | undefined =>
+    Object.hasOwn(record, key) && typeof record[key] === "string" ? record[key] : undefined
+  const valueOf = (element: ChatUi.TextInput | ChatUi.SelectInput) =>
+    submitted === undefined ? element.initial : own(submitted.values, element.id)
   const body: Array = []
   for (const element of modal.elements) {
     if (element._tag === "Text") {
@@ -92,7 +104,7 @@ const dialogCard = (modal: ChatUi.Modal, token: string, errors?: Readonly ({ title: option.label, value: option.value })),
         ...(element.placeholder === undefined ? {} : { placeholder: element.placeholder }),
-        ...(element.initial === undefined ? {} : { value: element.initial })
+        ...(valueOf(element) === undefined ? {} : { value: valueOf(element) })
       })
     }
-    const error = errors?.[element.id]
+    const error = submitted === undefined ? undefined : own(submitted.errors, element.id)
     if (error !== undefined) {
       body.push({ ...Render.textBlock(Render.escapeText(Render.wellFormed(error))), color: "attention" })
     }
@@ -132,10 +144,10 @@ const dialogCard = (modal: ChatUi.Modal, token: string, errors?: Readonly {
+const modalRefusal = (modal: ChatUi.Modal, envelope: Envelope.Envelope) => {
   const fields = modal.elements.length
   if (fields > modalFields) return Errors.tooLarge(undefined, "too_many_modal_fields")
-  if (modal.id.length + (modal.metadata?.length ?? 0) > modalMetadataLength) {
+  if (envelope.dialogLength(modal) > modalMetadataLength) {
     return Errors.tooLarge(undefined, "modal_metadata_too_long")
   }
   return Envelope.checkModal(modal)
@@ -183,14 +195,16 @@ export const invoke = (
       const dialog = yield* envelope.verifyDialog(token, { conversationId, userId: user })
       if (Option.isNone(dialog)) return failure
       const values = Envelope.validateSubmission(dialog.value.modal, data)
-      const at = threadOf(activity)
-      if (Option.isNone(values) || at === undefined) return failure
+      // The thread of the click that opened it, from the signed conversation
+      // id and message, never from the submit.
+      const origin = cardThread(dialog.value.conversationId, dialog.value.messageId)
+      if (Option.isNone(values) || origin === undefined) return failure
       const modal = dialog.value.modal
       const event = ChatInteraction.ModalSubmitted.make({
         id: modal.id,
         ...(modal.metadata === undefined ? {} : { metadata: modal.metadata }),
         values: values.value,
-        thread: at.thread,
+        thread: origin,
         ...(dialog.value.messageId === undefined ? {} : { messageId: dialog.value.messageId }),
         userId: user,
         raw: activity
@@ -198,15 +212,18 @@ export const invoke = (
       const reply = yield* ChatInteraction.handle(event, options.deadline)
       if (isLate(reply)) return failure
       if (reply._tag === "Errors") {
-        return { status: 200, body: dialogCard(modal, token as string, reply.errors) as Schema.Json }
+        return {
+          status: 200,
+          body: dialogCard(modal, token as string, { values: values.value, errors: reply.errors }) as Schema.Json
+        }
       }
       return ok
     }
 
     if (name !== "adaptiveCard/action" && name !== "message" && name !== "task/fetch") return failure
     const button = yield* envelope.verifyButton(token, { conversationId })
-    const thread = cardThread(activity)
     const messageId = string(activity, "replyToId")
+    const thread = cardThread(conversationId, messageId)
     if (Option.isNone(button) || thread === undefined || messageId === undefined) return failure
     const opensDialog = name === "task/fetch"
     if (opensDialog !== options.modalButtons.has(button.value.id)) return failure
@@ -225,13 +242,13 @@ export const invoke = (
       yield* refused(event, Errors.chatError("openModal", Errors.unsupported("modals")))
       return acked
     }
-    const refusal = modalRefusal(reply.modal)
+    const refusal = modalRefusal(reply.modal, envelope)
     if (refusal !== undefined) {
       yield* refused(event, Errors.chatError("openModal", refusal))
       return failure
     }
     const signed = yield* Effect.result(
-      envelope.signDialog(conversationId, { userId: user, messageId, modal: reply.modal })
+      envelope.signDialog({ conversationId, userId: user, messageId, modal: reply.modal })
     )
     if (signed._tag === "Failure") {
       yield* refused(event, Errors.chatError("openModal", signed.failure))
diff --git a/packages/chat/teams/src/internal/render.ts b/packages/chat/teams/src/internal/render.ts
index f19e77f8d70..6e780f500ca 100644
--- a/packages/chat/teams/src/internal/render.ts
+++ b/packages/chat/teams/src/internal/render.ts
@@ -36,7 +36,7 @@ export const escapeText = (text: string): string => text.replace(/[<&]/g, (c) =>
 /** @internal */
 export const textActivity = (markdown: string): Record => ({
   type: "message",
-  text: escapeText(wellFormed(markdown)),
+  text: escapeDollars(escapeText(wellFormed(markdown))),
   textFormat: "extendedmarkdown"
 })
 
@@ -101,6 +101,18 @@ export const buttonAction = (button: Button, token: string) => {
   }
 }
 
+/**
+ * A button that opens a dialog: an `Action.Submit` with `task/fetch`,
+ * smaller than the `Action.Execute` and fallback the measure prices.
+ *
+ * @internal
+ */
+export const dialogAction = (button: Button, token: string) => ({
+  type: "Action.Submit",
+  title: wellFormed(button.label),
+  data: { msteams: { type: "task/fetch" }, effect: token }
+})
+
 /** @internal */
 export const linkAction = (link: LinkButton) => ({
   type: "Action.OpenUrl",
@@ -116,13 +128,15 @@ export const linkAction = (link: LinkButton) => ({
 export const cardActivity = (
   markdown: string,
   actions: ReadonlyArray,
-  encode: (button: Button) => string
+  encode: (button: Button) => string,
+  opensDialog: (button: Button) => boolean = () => false
 ): Record => {
   const body: Array = blocks(markdown)
   const rendered: Array = []
   for (const action of actions) {
-    if (action._tag === "Button") rendered.push(buttonAction(action, encode(action)))
-    else if (action._tag === "LinkButton") rendered.push(linkAction(action))
+    if (action._tag === "Button") {
+      rendered.push(opensDialog(action) ? dialogAction(action, encode(action)) : buttonAction(action, encode(action)))
+    } else if (action._tag === "LinkButton") rendered.push(linkAction(action))
   }
   for (let i = 0; i < rendered.length; i += actionsPerRow) {
     body.push(actionSet(rendered.slice(i, i + actionsPerRow)))
@@ -149,6 +163,62 @@ const fenceCloses = (fence: Fence, line: string): boolean => {
   return match !== null && match[1][0] === fence.marker[0] && match[1].length >= fence.marker.length
 }
 
+/**
+ * Escapes each `$` outside code as `\$`, so that Teams reads no math in
+ * the text form. A `$` the Markdown already escapes, after an odd run of
+ * backslashes, is left alone, and so is code: fenced blocks and code spans
+ * on one line. One unit per `$` at most, as `Length.weight` prices it.
+ *
+ * @internal
+ */
+export const escapeDollars = (markdown: string): string => {
+  const parts = markdown.split(/(\r\n|\r|\n)/)
+  let fence: Fence | undefined
+  for (let i = 0; i < parts.length; i += 2) {
+    const line = parts[i]
+    if (fence !== undefined) {
+      if (fenceCloses(fence, line)) fence = undefined
+      continue
+    }
+    fence = fenceOpen(line)
+    if (fence === undefined) parts[i] = escapeLine(line)
+  }
+  return parts.join("")
+}
+
+const escapeLine = (line: string): string => {
+  let out = ""
+  let i = 0
+  while (i < line.length) {
+    const char = line[i]
+    if (char === "`") {
+      let run = 1
+      while (line[i + run] === "`") run++
+      const ticks = "`".repeat(run)
+      const close = findRun(line, ticks, i + run)
+      const end = close === -1 ? i + run : close + run
+      out += line.slice(i, end)
+      i = end
+      continue
+    }
+    if (char === "$") {
+      let backslashes = 0
+      while (line[i - 1 - backslashes] === "\\") backslashes++
+      out += backslashes % 2 === 0 ? "\\$" : "$"
+    } else out += char
+    i++
+  }
+  return out
+}
+
+/** The index of a run of exactly `ticks` from `from`, or -1. */
+const findRun = (line: string, ticks: string, from: number): number => {
+  for (let at = line.indexOf(ticks, from); at !== -1; at = line.indexOf(ticks, at + 1)) {
+    if (line[at - 1] !== "`" && line[at + ticks.length] !== "`") return at
+  }
+  return -1
+}
+
 const delimiterRow = /^[ \t]*\|?(?:[ \t]*:?-+:?[ \t]*\|)*[ \t]*:?-+:?[ \t]*\|?[ \t]*$/
 
 const isDelimiter = (line: string): boolean => line.includes("|") && delimiterRow.test(line)
diff --git a/packages/chat/teams/test/conformance.test.ts b/packages/chat/teams/test/conformance.test.ts
index 9279724874a..17e8a38179a 100644
--- a/packages/chat/teams/test/conformance.test.ts
+++ b/packages/chat/teams/test/conformance.test.ts
@@ -3,8 +3,10 @@
  * that answers every write. Capabilities behind `unverified` are off, so
  * their rules check that the descriptor leaves them out and the ops refuse.
  */
+import * as Adapter from "@effect/chat-teams/internal/adapter"
+import * as Length from "@effect/chat-teams/internal/length"
 import * as TeamsChat from "@effect/chat-teams/TeamsChat"
-import { describe, it } from "@effect/vitest"
+import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
 import { conformance } from "effect/chat/ChatTest"
 import * as Digest from "effect/crypto/Digest"
@@ -24,11 +26,12 @@ const thread = TeamsChat.thread(conversationId)
 const json = (body: unknown, status = 200) =>
   new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } })
 
-const makeConnector = () => {
+const makeConnector = (sent: Array<{ readonly url: URL; readonly body: string }> = []) => {
   let next = 1_700_000_000_000
   const posted = new Set()
   return HttpClient.make((request, url) =>
     Effect.sync(() => {
+      if (request.body._tag === "Uint8Array") sent.push({ url, body: new TextDecoder().decode(request.body.body) })
       let response: Response
       if (url.host === "login.microsoftonline.com") {
         response = json({ access_token: "token", expires_in: 3600, token_type: "Bearer" })
@@ -44,15 +47,20 @@ const makeConnector = () => {
       } else if (url.pathname.includes("/members/")) {
         response = json({ id: "29:user", aadObjectId: "user", name: "User" })
       } else response = json({ members: [] })
+      // As Fetch does: the response names the URL it came from, query included.
+      Object.defineProperty(response, "url", { value: url.href })
       return HttpClientResponse.fromWeb(request, response)
     })
   )
 }
 
-const layer = () =>
-  TeamsChat.layer({ appId, tenantId, credentials: Redacted.make("secret") }).pipe(
+const layer = (
+  extra: Partial[0]> = {},
+  sent?: Array<{ readonly url: URL; readonly body: string }>
+) =>
+  TeamsChat.layer({ appId, tenantId, credentials: Redacted.make("secret"), ...extra }).pipe(
     Layer.provideMerge(Chat.layer),
-    Layer.provide(Layer.succeed(HttpClient.HttpClient, makeConnector())),
+    Layer.provide(Layer.succeed(HttpClient.HttpClient, makeConnector(sent))),
     Layer.provide(Layer.mergeAll(Digest.layerWebCrypto, Mac.layerWebCrypto)),
     Layer.provide(SecureRandom.layerWebCrypto)
   )
@@ -94,3 +102,55 @@ describe("conformance over the stubbed Connector", () => {
     it.effect(name, () => conformance(options)[name].pipe(Effect.provide(layer())))
   }
 })
+
+describe("reads over the stubbed Connector", () => {
+  it.effect("getThread sends its query and accepts the answer", () =>
+    Effect.gen(function*() {
+      const chat = yield* Chat.Chat
+      const info = yield* chat.getThread(thread)
+      assert.strictEqual(info.kind, "channel")
+    }).pipe(Effect.provide(layer())))
+})
+
+describe("buttons over the stubbed Connector", () => {
+  const buttons = layer({
+    interactionKeys: [Redacted.make({ kty: "oct", kid: "k1", k: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc" })],
+    unverified: { buttons: true }
+  })
+
+  it.effect("counts the signed envelope against actionDataLength", () =>
+    Effect.gen(function*() {
+      const chat = yield* Chat.Chat
+      // The raw id and value fit the cap; with the envelope they do not.
+      const over = { _tag: "Button", id: "b", label: "B", value: "v".repeat(Adapter.actionDataLength - 1) } as const
+      const error = yield* Effect.flip(chat.post(thread, { markdown: "x", actions: [over] }))
+      assert.strictEqual(error.reason._tag, "TooLarge")
+      const posted = yield* chat.post(thread, { markdown: "x", actions: [{ ...over, value: "v".repeat(400) }] })
+      assert.isString(posted.id)
+    }).pipe(Effect.provide(buttons)))
+})
+
+describe("command answers over the stubbed Connector", () => {
+  it.effect("a private answer names its recipient by id alone, so it stays in the size bound", () => {
+    const sent: Array<{ readonly url: URL; readonly body: string }> = []
+    return Effect.gen(function*() {
+      const service = yield* TeamsChat.TeamsChat
+      const raw = {
+        type: "message",
+        id: "1",
+        serviceUrl: "https://smba.trafficmanager.net/teams",
+        from: { id: "29:user", aadObjectId: "user", name: "n".repeat(10_000) },
+        conversation: { id: conversationId }
+      }
+      yield* Adapter.internals.get(service)!.answer(
+        "respond",
+        raw,
+        { markdown: "a".repeat(Length.messageLength) },
+        "ephemeral"
+      )
+      const answer = sent.find(({ url }) => url.searchParams.get("isTargetedActivity") === "true")!
+      assert.deepStrictEqual(JSON.parse(answer.body).recipient, { id: "29:user" })
+      assert.isAtMost(answer.body.length, Length.Edge)
+    }).pipe(Effect.provide(layer({}, sent)))
+  })
+})
diff --git a/packages/chat/teams/test/download.test.ts b/packages/chat/teams/test/download.test.ts
index 6aecdf43982..524c318282f 100644
--- a/packages/chat/teams/test/download.test.ts
+++ b/packages/chat/teams/test/download.test.ts
@@ -70,6 +70,16 @@ describe("download", () => {
       ])
     }))
 
+  it.effect("never sends the token to a redirect host named as the first hop", () =>
+    Effect.gen(function*() {
+      const { http, sent } = serve(() => new Response("hello"))
+      const id = "connector:https://cdn.example.com/v3/attachments/a/views/original"
+      const reason = yield* reasonOf(Download.download(id, options(http)))
+      assert.strictEqual(reason._tag, "Forbidden")
+      assert.strictEqual(reason.detail, "untrusted_url")
+      assert.deepStrictEqual(sent, [])
+    }))
+
   it.effect("fails TooLarge past maxBytes", () =>
     Effect.gen(function*() {
       const { http } = serve(() => new Response(new Uint8Array(16)))
diff --git a/packages/chat/teams/test/envelope.test.ts b/packages/chat/teams/test/envelope.test.ts
index 13ec0d82eee..1406f197443 100644
--- a/packages/chat/teams/test/envelope.test.ts
+++ b/packages/chat/teams/test/envelope.test.ts
@@ -67,10 +67,16 @@ describe("envelope", () => {
           { _tag: "TextInput", id: "note", label: "Note", optional: true }
         ]
       }
-      const token = yield* envelope.signDialog(conversation, { userId: "u1", messageId: "m1", modal })
-      assert.isTrue(Option.isNone(yield* envelope.verifyDialog(token, { conversationId: conversation, userId: "u2" })))
-      const verified = yield* envelope.verifyDialog(token, { conversationId: conversation, userId: "u1" })
-      assert.deepStrictEqual(verified, Option.some({ messageId: "m1", modal }))
+      const opened = `${conversation};messageid=123`
+      const token = yield* envelope.signDialog({ conversationId: opened, userId: "u1", messageId: "123", modal })
+      assert.isTrue(Option.isNone(yield* envelope.verifyDialog(token, { conversationId: opened, userId: "u2" })))
+      // The same channel, another reply chain: refused, so a submit keeps the click's origin.
+      const moved = `${conversation};messageid=456`
+      assert.isTrue(Option.isNone(yield* envelope.verifyDialog(token, { conversationId: moved, userId: "u1" })))
+      const verified = yield* envelope.verifyDialog(token, { conversationId: opened, userId: "u1" })
+      assert.deepStrictEqual(verified, Option.some({ conversationId: opened, messageId: "123", modal }))
+      assert.isTrue(token.length <= Envelope.maxTokenLength)
+      assert.isTrue(envelope.dialogLength(modal) >= Envelope.dialogTokenLength({ ...options, kid: "k1" }, { id: "" }))
       assert.deepStrictEqual(
         Envelope.validateSubmission(modal, { effect: token, env: "prod", note: "" }),
         Option.some({ env: "prod" })
diff --git a/packages/chat/teams/test/interactions.test.ts b/packages/chat/teams/test/interactions.test.ts
new file mode 100644
index 00000000000..76054e1d59e
--- /dev/null
+++ b/packages/chat/teams/test/interactions.test.ts
@@ -0,0 +1,120 @@
+/**
+ * Dialog invokes, called directly with a recording handler: where a submit
+ * says it came from, what an error reply shows, and what counts against the
+ * modal cap.
+ */
+import { modalMetadataLength } from "@effect/chat-teams/internal/adapter"
+import * as Envelope from "@effect/chat-teams/internal/envelope"
+import * as Interactions from "@effect/chat-teams/internal/interactions"
+import * as TeamsChat from "@effect/chat-teams/TeamsChat"
+import { assert, describe, it } from "@effect/vitest"
+import type { ChatError } from "effect/chat/ChatError"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type * as ChatUi from "effect/chat/ChatUi"
+import { Digest, Mac, SecureRandom } from "effect/crypto"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+
+const crypto = Layer.mergeAll(Digest.layerWebCrypto, Mac.layerWebCrypto).pipe(
+  Layer.provideMerge(SecureRandom.layerWebCrypto)
+)
+
+const key = Redacted.make({ kty: "oct", kid: "k1", k: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc" } as const)
+const appId = "00000000-0000-0000-0000-0000000000a1"
+const tenantId = "00000000-0000-0000-0000-0000000000b2"
+const channel = "19:abc@thread.tacv2"
+const from = { id: "29:user", aadObjectId: "user" }
+
+const modal: ChatUi.Modal = {
+  _tag: "Modal",
+  id: "deploy",
+  title: "Deploy",
+  elements: [
+    { _tag: "TextInput", id: "constructor", label: "Name", initial: "first" },
+    { _tag: "TextInput", id: "note", label: "Note", initial: "draft" }
+  ]
+}
+
+const setup = Effect.fnUntraced(function*(open: ChatUi.Modal) {
+  const envelope = yield* Envelope.make({ appId, tenantId, keys: [key] })
+  const submits: Array = []
+  const refusals: Array = []
+  const handler = ChatInteraction.Handler.of({
+    click: () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: open })),
+    submit: (event) => {
+      submits.push(event)
+      return Effect.succeed(ChatInteraction.errors({ note: "Too short" }))
+    },
+    command: () => Effect.succeed(ChatInteraction.ack),
+    refused: (_, error) => Effect.sync(() => void refusals.push(error))
+  })
+  const options: Interactions.Options = {
+    capabilities: new Set(["buttons", "modals", "modalErrors"]),
+    envelope,
+    modalButtons: new Set(["open"]),
+    answer: () => Effect.die("unused"),
+    deadline: Duration.seconds(1)
+  }
+  const invoke = (activity: Record) =>
+    Interactions.invoke(activity, options).pipe(Effect.provideService(ChatInteraction.Handler, handler))
+  // A click on a card posted as a channel post: the root of its own reply chain.
+  const clicked = `${channel};messageid=123`
+  const button = yield* envelope.signButton(channel, { id: "open" })
+  const opened = yield* invoke({
+    type: "invoke",
+    name: "task/fetch",
+    from,
+    conversation: { id: clicked },
+    replyToId: "123",
+    value: { data: { effect: button } }
+  })
+  const dialogToken = (body: unknown): string | undefined =>
+    (body as any)?.task?.value?.card?.content?.actions?.[0]?.data?.effect
+  const submit = (conversationId: string, values: Record) =>
+    invoke({
+      type: "invoke",
+      name: "task/submit",
+      from,
+      conversation: { id: conversationId },
+      value: { data: { effect: dialogToken(opened.body) ?? null, ...values } }
+    })
+  return { clicked, opened, submit, submits, refusals }
+})
+
+describe("dialogs", () => {
+  it.effect("a submit keeps the thread and message of the click, and from no other reply chain", () =>
+    Effect.gen(function*() {
+      const { clicked, submit, submits } = yield* setup(modal)
+      const moved = yield* submit(`${channel};messageid=456`, { constructor: "a", note: "b" })
+      assert.strictEqual(moved.status, 200)
+      assert.strictEqual(submits.length, 0)
+
+      yield* submit(clicked, { constructor: "a", note: "b" })
+      assert.strictEqual(submits.length, 1)
+      assert.deepStrictEqual(submits[0].thread, TeamsChat.thread(channel))
+      assert.strictEqual(submits[0].messageId, "123")
+    }).pipe(Effect.provide(crypto)))
+
+  it.effect("an error reply keeps what the user entered, and reads no inherited key", () =>
+    Effect.gen(function*() {
+      const { clicked, submit } = yield* setup(modal)
+      const reply = yield* submit(clicked, { constructor: "edited", note: "b" })
+      const body = (reply.body as any).task.value.card.content.body as ReadonlyArray
+      const inputs = body.filter((element) => element.type === "Input.Text")
+      assert.deepStrictEqual(inputs.map((input) => input.value), ["edited", "b"])
+      const texts = body.filter((element) => element.type === "TextBlock").map((element) => element.text)
+      assert.deepStrictEqual(texts, ["Too short"])
+    }).pipe(Effect.provide(crypto)))
+
+  it.effect("counts the signed envelope against modalMetadataLength", () =>
+    Effect.gen(function*() {
+      // The raw id and metadata fit the cap; with the envelope they do not.
+      const metadata = "m".repeat(modalMetadataLength - modal.id.length)
+      const { opened, refusals } = yield* setup({ ...modal, metadata })
+      assert.notStrictEqual((opened.body as any)?.task?.type, "continue")
+      assert.strictEqual(refusals[0]?.reason._tag, "TooLarge")
+    }).pipe(Effect.provide(crypto)))
+})
diff --git a/packages/chat/teams/test/length.test.ts b/packages/chat/teams/test/length.test.ts
index 00e6778a09b..3604b720404 100644
--- a/packages/chat/teams/test/length.test.ts
+++ b/packages/chat/teams/test/length.test.ts
@@ -13,8 +13,12 @@ const actions: ReadonlyArray = [
   { _tag: "LinkButton", label: "Docs", url: "https://example.com/?a=1&b=<2>" }
 ]
 
-const fits = (markdown: string, actions: ReadonlyArray) =>
-  expect(JSON.stringify(Render.cardActivity(markdown, actions, encode)).length).toBeLessThanOrEqual(
+const fits = (
+  markdown: string,
+  actions: ReadonlyArray,
+  opensDialog?: (button: ChatUi.Button) => boolean
+) =>
+  expect(JSON.stringify(Render.cardActivity(markdown, actions, encode, opensDialog)).length).toBeLessThanOrEqual(
     measure(markdown, actions) + Length.R
   )
 
@@ -30,4 +34,21 @@ describe("measure", () => {
     fits(markdown, [])
     expect(measure(markdown, [])).toBe(measure(markdown))
   })
+
+  it("bounds a dialog button whose label has lone surrogates", () => {
+    fits("x", [{ _tag: "Button", id: "open", label: "\uD800".repeat(20_000) }], () => true)
+  })
+
+  it("bounds the text form with its dollar escapes", () => {
+    const markdown = "$".repeat(10_000) + "\\$"
+    expect(JSON.stringify(Render.textActivity(markdown)).length).toBeLessThanOrEqual(measure(markdown) + Length.R)
+  })
+})
+
+describe("textActivity", () => {
+  it("escapes each dollar outside code, so Teams reads no math", () => {
+    const markdown = "$x$ \\$y \\\\$z `$c$`\n```\n$$\n```\n$"
+    const sent = "\\$x\\$ \\$y \\\\\\$z `$c$`\n```\n$$\n```\n\\$"
+    expect(Render.textActivity(markdown).text).toBe(sent)
+  })
 })
diff --git a/packages/chat/teams/test/webhook.test.ts b/packages/chat/teams/test/webhook.test.ts
index 41cc7d860b7..97bfdd35d4c 100644
--- a/packages/chat/teams/test/webhook.test.ts
+++ b/packages/chat/teams/test/webhook.test.ts
@@ -7,11 +7,13 @@ import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { ChatHandler } from "effect/chat/ChatHandler"
+import * as Context from "effect/Context"
 import * as Digest from "effect/crypto/Digest"
 import * as Mac from "effect/crypto/Mac"
 import * as SecureRandom from "effect/crypto/SecureRandom"
 import * as Signature from "effect/crypto/Signature"
 import * as Effect from "effect/Effect"
+import * as FetchHttpClient from "effect/http/FetchHttpClient"
 import * as HttpClient from "effect/http/HttpClient"
 import * as HttpClientResponse from "effect/http/HttpClientResponse"
 import * as HttpRouter from "effect/http/HttpRouter"
@@ -50,7 +52,7 @@ const activity = (overrides?: Record) => ({
   ...overrides
 })
 
-const setup = Effect.gen(function*() {
+const setup = Effect.fnUntraced(function*(options?: { readonly jwksUri?: string }) {
   const pair = yield* Jwk.generateKeyPair({ algorithm: "RS256", kid: "k1" })
   const key = yield* Jwk.importPrivate(pair.privateKey, "RS256")
   const token = (claimed = serviceUrl) =>
@@ -68,12 +70,17 @@ const setup = Effect.gen(function*() {
       ),
       Redacted.value
     )
-  const http = HttpClient.make((request, url) =>
+  const fetched: Array<{ readonly url: string; readonly redirect: RequestRedirect | undefined }> = []
+  const http = HttpClient.make((request, url, _signal, fiber) =>
     Effect.sync(() => {
+      fetched.push({
+        url: url.href,
+        redirect: Context.getOrUndefined(fiber.context, FetchHttpClient.RequestInit)?.redirect
+      })
       const body = url.href === keysUrl
         ? { keys: [{ ...pair.publicKey, endorsements: ["msteams"] }] }
         : url.pathname.endsWith("/openidconfiguration")
-        ? { jwks_uri: keysUrl }
+        ? { jwks_uri: options?.jwksUri ?? keysUrl }
         : {}
       return HttpClientResponse.fromWeb(request, Response.json(body))
     })
@@ -101,13 +108,13 @@ const setup = Effect.gen(function*() {
         })
       )
     ).pipe(Effect.map((response) => response.status))
-  return { events, send, token }
+  return { events, fetched, send, token }
 })
 
 describe("layerWebhook", () => {
   it.effect("answers 403 without a valid token, and for a token bound to another serviceUrl", () =>
     Effect.gen(function*() {
-      const { events, send, token } = yield* setup
+      const { events, send, token } = yield* setup()
       assert.strictEqual(yield* send(activity()), 403)
       assert.strictEqual(yield* send(activity(), "Bearer not.a.token"), 403)
       const other = yield* token("https://smba.trafficmanager.net/amer/")
@@ -119,7 +126,7 @@ describe("layerWebhook", () => {
 
   it.effect("hands a verified message to the ChatHandler, and drops a targeted one", () =>
     Effect.gen(function*() {
-      const { events, send, token } = yield* setup
+      const { events, send, token } = yield* setup()
       const bearer = `Bearer ${yield* token()}`
       assert.strictEqual(yield* send(activity(), bearer), 200)
       assert.strictEqual(
@@ -129,4 +136,23 @@ describe("layerWebhook", () => {
       assert.strictEqual(events.length, 1)
       assert.strictEqual(events[0]._tag, "MessageCreated")
     }).pipe(Effect.provide(crypto)))
+
+  it.effect("fetches the metadata and the key set with redirects off", () =>
+    Effect.gen(function*() {
+      const { fetched, send, token } = yield* setup()
+      assert.strictEqual(yield* send(activity(), `Bearer ${yield* token()}`), 200)
+      const discovery = fetched.filter((request) => request.url.startsWith("https://login.botframework.com/"))
+      assert.deepStrictEqual(discovery.map((request) => request.url), [
+        "https://login.botframework.com/v1/.well-known/openidconfiguration",
+        keysUrl
+      ])
+      assert.isTrue(discovery.every((request) => request.redirect === "manual"))
+    }).pipe(Effect.provide(crypto)))
+
+  it.effect("answers 503 for metadata whose jwks_uri is not a URL", () =>
+    Effect.gen(function*() {
+      const { events, send, token } = yield* setup({ jwksUri: "not a URL" })
+      assert.strictEqual(yield* send(activity(), `Bearer ${yield* token()}`), 503)
+      assert.strictEqual(events.length, 0)
+    }).pipe(Effect.provide(crypto)))
 })

From b9f5b3a0bba1c7a9e786d6b7d6768838f6f92bde Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:49:31 +0000
Subject: [PATCH 69/89] Keep a tab's leftover columns when matching a nested
 fence's closer

A tab only partly taken by a list item's indentation left the rest looking like a closing fence, so the code after it was rendered.
---
 packages/chat/whatsapp/src/internal/text.ts | 43 ++++++++++++++-------
 packages/chat/whatsapp/test/text.test.ts    |  3 +-
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/packages/chat/whatsapp/src/internal/text.ts b/packages/chat/whatsapp/src/internal/text.ts
index 2527180f4d8..06042a50a5d 100644
--- a/packages/chat/whatsapp/src/internal/text.ts
+++ b/packages/chat/whatsapp/src/internal/text.ts
@@ -358,7 +358,26 @@ const containers = (line: string): { readonly stack: ReadonlyArray; read
   return { stack, rest }
 }
 
-/** What is left of a line inside the containers of `stack`, or `undefined` when the line ends one of them. */
+/**
+ * A line with the tabs of its indentation and container markers expanded to
+ * the next multiple of four columns, so a tab only partly taken by a
+ * container leaves its other columns. Used to find blocks, never as output.
+ */
+const expandIndent = (line: string): string => {
+  let out = ""
+  for (let k = 0; k < line.length; k++) {
+    const char = line[k]
+    if (char === "\t") out += " ".repeat(4 - (out.length % 4))
+    else if (/[ >\-*+.)0-9]/.test(char)) out += char
+    else return out + line.slice(k)
+  }
+  return out
+}
+
+/**
+ * What is left of a line, with its indentation expanded, inside the
+ * containers of `stack`, or `undefined` when the line ends one of them.
+ */
 const inside = (line: string, stack: ReadonlyArray): string | undefined => {
   let rest = line
   for (const width of stack) {
@@ -369,14 +388,8 @@ const inside = (line: string, stack: ReadonlyArray): string | undefined
       continue
     }
     if (isBlank(rest)) return ""
-    let column = 0
-    let k = 0
-    while (column < width && (rest[k] === " " || rest[k] === "\t")) {
-      column += rest[k] === "\t" ? 4 - (column % 4) : 1
-      k++
-    }
-    if (column < width) return undefined
-    rest = rest.slice(k)
+    if (!rest.startsWith(" ".repeat(width))) return undefined
+    rest = rest.slice(width)
   }
   return rest
 }
@@ -399,7 +412,7 @@ export const render = (markdown: string): string => {
   let i = 0
   while (i < lines.length) {
     const line = body(i)
-    const { rest, stack } = containers(line)
+    const { rest, stack } = containers(expandIndent(line))
     const fence = fenceOpen.exec(rest)
     if (fence !== null && !(fence[2][0] === "`" && fence[3].includes("`"))) {
       // The closer is matched inside the opener's quotes and list items. A line outside them ends the code too.
@@ -407,7 +420,7 @@ export const render = (markdown: string): string => {
       let j = i + 1
       let closed = false
       for (; j < lines.length; j++) {
-        const code = inside(body(j), stack)
+        const code = inside(expandIndent(body(j)), stack)
         if (code === undefined) break
         if (closing.test(code)) {
           closed = true
@@ -431,7 +444,7 @@ export const render = (markdown: string): string => {
       out += lines[i]
       let j = i + 1
       while (j < lines.length) {
-        const next = inside(body(j), stack) ?? body(j)
+        const next = inside(expandIndent(body(j)), stack) ?? expandIndent(body(j))
         if (isBlank(next) || opensBlock(next)) break
         out += lines[j++]
       }
@@ -442,7 +455,7 @@ export const render = (markdown: string): string => {
       if (cells(line) === cells(body(i + 1))) {
         out += lines[i]
         let j = i + 2
-        while (j < lines.length && !isBlank(body(j)) && !opensBlock(body(j))) out += lines[j++]
+        while (j < lines.length && !isBlank(body(j)) && !opensBlock(expandIndent(body(j)))) out += lines[j++]
         i = j
         continue
       }
@@ -468,7 +481,9 @@ export const render = (markdown: string): string => {
       i++
       continue
     }
-    out += line.slice(0, line.length - rest.length) + inline(rest) + eol(i)
+    // The text is cut from the line as typed, so the output keeps its tabs.
+    const text = containers(line).rest
+    out += line.slice(0, line.length - text.length) + inline(text) + eol(i)
     i++
   }
   return out
diff --git a/packages/chat/whatsapp/test/text.test.ts b/packages/chat/whatsapp/test/text.test.ts
index c61890ee0db..2ae3893fe95 100644
--- a/packages/chat/whatsapp/test/text.test.ts
+++ b/packages/chat/whatsapp/test/text.test.ts
@@ -33,7 +33,8 @@ const cases: ReadonlyArray = [
   ["- > ~~~\n  >       ~~~\n  > **x**\n  > ~~~", "- > ~~~\n  >       ~~~\n  > **x**\n  > ~~~"],
   ["> ~~~\n> **x**\n\n**y**", "> ~~~\n> **x**\n\n*y*"],
   ["[r]: /url\n~~~js\n\n**x**\n~~~", "[r]: /url\n```\n\n**x**\n```"],
-  ["| a |\n|---|\n~~~\n\n**x**\n~~~", "| a |\n```\n\n**x**\n```"]
+  ["| a |\n|---|\n~~~\n\n**x**\n~~~", "| a |\n```\n\n**x**\n```"],
+  ["- ~~~js\n\t  ~~~\n  **x**\n  ~~~", "- ~~~js\n\t  ~~~\n  **x**\n  ~~~"]
 ]
 
 const longer = (input: string) => {

From c474fd0f44e6a7da50ca6cf6ad110fbaca789385 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:56:09 +0000
Subject: [PATCH 70/89] Keep indented code inside quotes and list items as
 typed

The indented-code guard checked the line as typed, so a quoted or listed code line with tab indentation fell through to inline rendering. It now checks what is left inside the containers, with tabs expanded, and still emits the line as typed.
---
 packages/chat/whatsapp/src/internal/text.ts | 3 ++-
 packages/chat/whatsapp/test/text.test.ts    | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/packages/chat/whatsapp/src/internal/text.ts b/packages/chat/whatsapp/src/internal/text.ts
index 06042a50a5d..6566eb31dc3 100644
--- a/packages/chat/whatsapp/src/internal/text.ts
+++ b/packages/chat/whatsapp/src/internal/text.ts
@@ -476,7 +476,8 @@ export const render = (markdown: string): string => {
       i += 2
       continue
     }
-    if (/^(?: {4}|\t)/.test(line) || thematicBreak.test(line)) {
+    // Indented code, measured inside its quotes and list items with tabs expanded, is kept as typed.
+    if (/^ {4}/.test(rest) || thematicBreak.test(line)) {
       out += lines[i]
       i++
       continue
diff --git a/packages/chat/whatsapp/test/text.test.ts b/packages/chat/whatsapp/test/text.test.ts
index 2ae3893fe95..763711e35f9 100644
--- a/packages/chat/whatsapp/test/text.test.ts
+++ b/packages/chat/whatsapp/test/text.test.ts
@@ -34,7 +34,8 @@ const cases: ReadonlyArray = [
   ["> ~~~\n> **x**\n\n**y**", "> ~~~\n> **x**\n\n*y*"],
   ["[r]: /url\n~~~js\n\n**x**\n~~~", "[r]: /url\n```\n\n**x**\n```"],
   ["| a |\n|---|\n~~~\n\n**x**\n~~~", "| a |\n```\n\n**x**\n```"],
-  ["- ~~~js\n\t  ~~~\n  **x**\n  ~~~", "- ~~~js\n\t  ~~~\n  **x**\n  ~~~"]
+  ["- ~~~js\n\t  ~~~\n  **x**\n  ~~~", "- ~~~js\n\t  ~~~\n  **x**\n  ~~~"],
+  [">\t  ~~~\n>\t  **x**\n>\t  ~~~", ">\t  ~~~\n>\t  **x**\n>\t  ~~~"]
 ]
 
 const longer = (input: string) => {

From 79657136f6b0da4c7c8cc40a0eb736477705fb1c Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 21:54:34 +0000
Subject: [PATCH 71/89] Count the whole signed dialog token against the Teams
 modal cap

---
 packages/chat/teams/README.md                 |  2 +-
 packages/chat/teams/src/TeamsChat.ts          |  4 +-
 packages/chat/teams/src/internal/adapter.ts   |  9 +-
 packages/chat/teams/src/internal/envelope.ts  | 33 +-------
 .../chat/teams/src/internal/interactions.ts   | 23 +++---
 packages/chat/teams/test/envelope.test.ts     |  1 -
 packages/chat/teams/test/interactions.test.ts |  2 +-
 packages/chat/teams/test/webhook.test.ts      | 82 +++++++++++++++++--
 8 files changed, 100 insertions(+), 56 deletions(-)

diff --git a/packages/chat/teams/README.md b/packages/chat/teams/README.md
index cc4f5268fa8..94d2fa0ae8b 100644
--- a/packages/chat/teams/README.md
+++ b/packages/chat/teams/README.md
@@ -58,7 +58,7 @@ A dialog opens only from a button whose id is listed in `modalButtons`. Any othe
 - Native streams. Streams are posted and then edited.
 - Selects.
 
-The element caps are the adapter's own, since Teams publishes none: 6 elements per message and 10 fields per modal. `actionDataLength` (1,000) and `modalMetadataLength` (4,000) count the signed token that carries the data, envelope included. With a GUID app and tenant that leaves about 500 ASCII characters for a button's id and value, and about 1,900 for a modal's id and metadata.
+The element caps are the adapter's own, since Teams publishes none: 6 elements per message and 10 fields per modal. `actionDataLength` (1,000) and `modalMetadataLength` (4,000) count the whole signed token that carries the data, envelope included. With a GUID app and tenant that leaves about 500 ASCII characters for a button's id and value. A dialog token also carries the modal's definition, so its id, metadata, title, labels, options and texts share about 1,880 bytes of JSON. A modal over that is refused `TooLarge` before anything opens. Check 13 may raise the cap once the dialog card's real size limit is known.
 
 ## Security
 
diff --git a/packages/chat/teams/src/TeamsChat.ts b/packages/chat/teams/src/TeamsChat.ts
index 968147cdbe6..a15fd6bf79e 100644
--- a/packages/chat/teams/src/TeamsChat.ts
+++ b/packages/chat/teams/src/TeamsChat.ts
@@ -212,7 +212,9 @@ export class TeamsChat extends Context.Service
-  base64Length(utf8Length(headerJson(context.kid, typ.dialog))) + 1 +
-  base64Length(utf8Length(JSON.stringify({
-    aud: context.appId,
-    tid: context.tenantId,
-    cnv: "x".repeat(hashLength),
-    cid: longestId,
-    sub: longestId,
-    exp: Number.MAX_SAFE_INTEGER,
-    mid: longestId,
-    def: { _tag: "Modal", id: modal.id, title: "", elements: [] },
-    ...(modal.metadata === undefined ? {} : { md: modal.metadata })
-  }))) + 1 + signatureLength
-
 // Checks
 
 /** Whether a field of `modal` uses the reserved `effect` id. @internal */
@@ -329,8 +301,6 @@ export interface Envelope {
   ) => Effect.Effect>
   /** `buttonTokenLength` with this envelope's app, tenant and signing key. */
   readonly tokenLength: (button: Button) => number
-  /** `dialogTokenLength` with this envelope's app, tenant and signing key. */
-  readonly dialogLength: (modal: { readonly id: string; readonly metadata?: string | undefined }) => number
 }
 
 const validKid = /^[A-Za-z0-9_-]{1,16}$/
@@ -451,7 +421,6 @@ export const make = Effect.fnUntraced(function*(options: {
             }))
           )
       ),
-    tokenLength: (button) => buttonTokenLength(context, button),
-    dialogLength: (modal) => dialogTokenLength(context, modal)
+    tokenLength: (button) => buttonTokenLength(context, button)
   }
 })
diff --git a/packages/chat/teams/src/internal/interactions.ts b/packages/chat/teams/src/internal/interactions.ts
index 9b42b431d0d..b3c8885f9f5 100644
--- a/packages/chat/teams/src/internal/interactions.ts
+++ b/packages/chat/teams/src/internal/interactions.ts
@@ -144,14 +144,10 @@ const dialogCard = (
   }
 }
 
-const modalRefusal = (modal: ChatUi.Modal, envelope: Envelope.Envelope) => {
-  const fields = modal.elements.length
-  if (fields > modalFields) return Errors.tooLarge(undefined, "too_many_modal_fields")
-  if (envelope.dialogLength(modal) > modalMetadataLength) {
-    return Errors.tooLarge(undefined, "modal_metadata_too_long")
-  }
-  return Envelope.checkModal(modal)
-}
+const modalRefusal = (modal: ChatUi.Modal) =>
+  modal.elements.length > modalFields
+    ? Errors.tooLarge(undefined, "too_many_modal_fields")
+    : Envelope.checkModal(modal)
 
 /**
  * One verified invoke, or a card's `Action.Submit` fallback, which comes as
@@ -242,7 +238,7 @@ export const invoke = (
       yield* refused(event, Errors.chatError("openModal", Errors.unsupported("modals")))
       return acked
     }
-    const refusal = modalRefusal(reply.modal, envelope)
+    const refusal = modalRefusal(reply.modal)
     if (refusal !== undefined) {
       yield* refused(event, Errors.chatError("openModal", refusal))
       return failure
@@ -250,8 +246,13 @@ export const invoke = (
     const signed = yield* Effect.result(
       envelope.signDialog({ conversationId, userId: user, messageId, modal: reply.modal })
     )
-    if (signed._tag === "Failure") {
-      yield* refused(event, Errors.chatError("openModal", signed.failure))
+    // `modalMetadataLength` holds the whole signed token: the definition,
+    // the metadata and every claim. Signing is local, so the check is exact
+    // and nothing has opened yet.
+    const tooLong = signed._tag === "Success" && signed.success.length > modalMetadataLength
+    if (signed._tag === "Failure" || tooLong) {
+      const reason = signed._tag === "Failure" ? signed.failure : Errors.tooLarge(undefined, "modal_too_large")
+      yield* refused(event, Errors.chatError("openModal", reason))
       return failure
     }
     return { status: 200, body: dialogCard(reply.modal, signed.success) as Schema.Json }
diff --git a/packages/chat/teams/test/envelope.test.ts b/packages/chat/teams/test/envelope.test.ts
index 1406f197443..fcaa1780ecc 100644
--- a/packages/chat/teams/test/envelope.test.ts
+++ b/packages/chat/teams/test/envelope.test.ts
@@ -76,7 +76,6 @@ describe("envelope", () => {
       const verified = yield* envelope.verifyDialog(token, { conversationId: opened, userId: "u1" })
       assert.deepStrictEqual(verified, Option.some({ conversationId: opened, messageId: "123", modal }))
       assert.isTrue(token.length <= Envelope.maxTokenLength)
-      assert.isTrue(envelope.dialogLength(modal) >= Envelope.dialogTokenLength({ ...options, kid: "k1" }, { id: "" }))
       assert.deepStrictEqual(
         Envelope.validateSubmission(modal, { effect: token, env: "prod", note: "" }),
         Option.some({ env: "prod" })
diff --git a/packages/chat/teams/test/interactions.test.ts b/packages/chat/teams/test/interactions.test.ts
index 76054e1d59e..fcf36e0c3e7 100644
--- a/packages/chat/teams/test/interactions.test.ts
+++ b/packages/chat/teams/test/interactions.test.ts
@@ -109,7 +109,7 @@ describe("dialogs", () => {
       assert.deepStrictEqual(texts, ["Too short"])
     }).pipe(Effect.provide(crypto)))
 
-  it.effect("counts the signed envelope against modalMetadataLength", () =>
+  it.effect("counts the metadata's signed envelope against modalMetadataLength", () =>
     Effect.gen(function*() {
       // The raw id and metadata fit the cap; with the envelope they do not.
       const metadata = "m".repeat(modalMetadataLength - modal.id.length)
diff --git a/packages/chat/teams/test/webhook.test.ts b/packages/chat/teams/test/webhook.test.ts
index 97bfdd35d4c..a742e5f649b 100644
--- a/packages/chat/teams/test/webhook.test.ts
+++ b/packages/chat/teams/test/webhook.test.ts
@@ -2,11 +2,16 @@
  * The messaging endpoint through `layerWebhook`, with tokens signed by a
  * key in a stubbed Bot Framework key set.
  */
+import { modalMetadataLength } from "@effect/chat-teams/internal/adapter"
+import * as Envelope from "@effect/chat-teams/internal/envelope"
 import * as TeamsChat from "@effect/chat-teams/TeamsChat"
 import { assert, describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
+import type { ChatError } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { ChatHandler } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import type * as ChatUi from "effect/chat/ChatUi"
 import * as Context from "effect/Context"
 import * as Digest from "effect/crypto/Digest"
 import * as Mac from "effect/crypto/Mac"
@@ -52,7 +57,11 @@ const activity = (overrides?: Record) => ({
   ...overrides
 })
 
-const setup = Effect.fnUntraced(function*(options?: { readonly jwksUri?: string }) {
+const setup = Effect.fnUntraced(function*(options?: {
+  readonly jwksUri?: string
+  readonly teams?: Partial[0]>
+  readonly interactions?: ChatInteraction.Handler["Service"]
+}) {
   const pair = yield* Jwk.generateKeyPair({ algorithm: "RS256", kid: "k1" })
   const key = yield* Jwk.importPrivate(pair.privateKey, "RS256")
   const token = (claimed = serviceUrl) =>
@@ -87,15 +96,20 @@ const setup = Effect.fnUntraced(function*(options?: { readonly jwksUri?: string
   )
   const events: Array = []
   const app = TeamsChat.layerWebhook({ path: "/api/messages" }).pipe(
-    Layer.provide(TeamsChat.layer({ appId, tenantId, credentials: Redacted.make("secret") })),
+    Layer.provide(TeamsChat.layer({ appId, tenantId, credentials: Redacted.make("secret"), ...options?.teams })),
     Layer.provide(Chat.layer),
+    Layer.provide(
+      options?.interactions === undefined
+        ? Layer.empty
+        : Layer.succeed(ChatInteraction.Handler, options.interactions)
+    ),
     Layer.provide(Layer.succeed(ChatHandler, { handle: (event) => Effect.sync(() => void events.push(event)) })),
     Layer.provide(Layer.succeed(HttpClient.HttpClient, http)),
     Layer.provide(crypto)
   )
   const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true })
   yield* Effect.addFinalizer(() => Effect.promise(() => dispose()))
-  const send = (body: unknown, authorization?: string) =>
+  const exchange = (body: unknown, authorization?: string) =>
     Effect.promise(() =>
       handler(
         new Request("http://localhost/api/messages", {
@@ -107,8 +121,10 @@ const setup = Effect.fnUntraced(function*(options?: { readonly jwksUri?: string
           }
         })
       )
-    ).pipe(Effect.map((response) => response.status))
-  return { events, fetched, send, token }
+    )
+  const send = (body: unknown, authorization?: string) =>
+    Effect.map(exchange(body, authorization), (response) => response.status)
+  return { events, exchange, fetched, send, token }
 })
 
 describe("layerWebhook", () => {
@@ -155,4 +171,60 @@ describe("layerWebhook", () => {
       assert.strictEqual(yield* send(activity(), `Bearer ${yield* token()}`), 503)
       assert.strictEqual(events.length, 0)
     }).pipe(Effect.provide(crypto)))
+
+  it.effect("opens a dialog only when its whole signed token fits modalMetadataLength", () =>
+    Effect.gen(function*() {
+      const interactionKey = Redacted.make(
+        { kty: "oct", kid: "k1", k: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc" } as const
+      )
+      // Short id and no metadata: the definition alone makes the token long.
+      const modal = (text: string): ChatUi.Modal => ({
+        _tag: "Modal",
+        id: "m",
+        title: "Modal",
+        elements: [{ _tag: "Text", text }, { _tag: "TextInput", id: "answer", label: "Answer" }]
+      })
+      const refusals: Array = []
+      const { exchange, token } = yield* setup({
+        teams: {
+          interactionKeys: [interactionKey],
+          modalButtons: ["open"],
+          unverified: { buttons: true, modals: true }
+        },
+        interactions: {
+          click: (event) =>
+            Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("x".repeat(Number(event.value))) })),
+          submit: () => Effect.succeed(ChatInteraction.close),
+          command: () => Effect.succeed(ChatInteraction.ack),
+          refused: (_, error) => Effect.sync(() => void refusals.push(error))
+        }
+      })
+      const envelope = yield* Envelope.make({ appId, tenantId, keys: [interactionKey] })
+      const bearer = `Bearer ${yield* token()}`
+      const open = Effect.fnUntraced(function*(textLength: number) {
+        const button = yield* envelope.signButton("a:direct", { id: "open", value: String(textLength) })
+        const response = yield* exchange(
+          activity({
+            type: "invoke",
+            name: "task/fetch",
+            replyToId: "1800000000000",
+            value: { data: { effect: button } }
+          }),
+          bearer
+        )
+        const body = yield* Effect.promise(() => response.json())
+        return body?.task?.type === "continue"
+          ? body.task.value.card.content.actions[0].data.effect as string
+          : undefined
+      })
+
+      const big = yield* open(3_500)
+      assert.isUndefined(big)
+      assert.strictEqual(refusals[0]?.reason._tag, "TooLarge")
+
+      const small = yield* open(1_000)
+      assert.isString(small)
+      assert.isAtMost(small!.length, modalMetadataLength)
+      assert.strictEqual(refusals.length, 1)
+    }).pipe(Effect.provide(crypto)))
 })

From a81ad78b0a51f3731afe464ade29622657acf578 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 22:00:17 +0000
Subject: [PATCH 72/89] Add the Telegram Bot API adapter

---
 packages/chat/telegram/README.md              |  95 ++++
 packages/chat/telegram/package.json           |  70 +++
 packages/chat/telegram/src/TelegramBotApi.ts  | 282 ++++++++++
 packages/chat/telegram/src/TelegramChat.ts    | 515 ++++++++++++++++++
 packages/chat/telegram/src/index.ts           |  18 +
 .../chat/telegram/src/internal/actions.ts     |  97 ++++
 .../chat/telegram/src/internal/adapter.ts     | 333 +++++++++++
 .../chat/telegram/src/internal/address.ts     |  33 ++
 .../chat/telegram/src/internal/commands.ts    |  37 ++
 packages/chat/telegram/src/internal/errors.ts | 137 +++++
 .../chat/telegram/src/internal/markdown.ts    | 448 +++++++++++++++
 .../chat/telegram/src/internal/normalize.ts   | 276 ++++++++++
 .../chat/telegram/src/internal/options.ts     |  12 +
 .../chat/telegram/src/internal/polling.ts     |  86 +++
 .../chat/telegram/src/internal/receive.ts     | 272 +++++++++
 .../chat/telegram/src/internal/webhook.ts     | 101 ++++
 .../chat/telegram/test/TelegramChat.test.ts   | 348 ++++++++++++
 .../chat/telegram/test/conformance.test.ts    |  29 +
 packages/chat/telegram/test/markdown.test.ts  |  75 +++
 packages/chat/telegram/test/utils.ts          | 221 ++++++++
 packages/chat/telegram/tsconfig.json          |   8 +
 pnpm-lock.yaml                                |   6 +
 tsconfig.packages.json                        |   1 +
 tsconfig.tests.json                           |   2 +
 vitest.config.ts                              |   1 +
 25 files changed, 3503 insertions(+)
 create mode 100644 packages/chat/telegram/README.md
 create mode 100644 packages/chat/telegram/package.json
 create mode 100644 packages/chat/telegram/src/TelegramBotApi.ts
 create mode 100644 packages/chat/telegram/src/TelegramChat.ts
 create mode 100644 packages/chat/telegram/src/index.ts
 create mode 100644 packages/chat/telegram/src/internal/actions.ts
 create mode 100644 packages/chat/telegram/src/internal/adapter.ts
 create mode 100644 packages/chat/telegram/src/internal/address.ts
 create mode 100644 packages/chat/telegram/src/internal/commands.ts
 create mode 100644 packages/chat/telegram/src/internal/errors.ts
 create mode 100644 packages/chat/telegram/src/internal/markdown.ts
 create mode 100644 packages/chat/telegram/src/internal/normalize.ts
 create mode 100644 packages/chat/telegram/src/internal/options.ts
 create mode 100644 packages/chat/telegram/src/internal/polling.ts
 create mode 100644 packages/chat/telegram/src/internal/receive.ts
 create mode 100644 packages/chat/telegram/src/internal/webhook.ts
 create mode 100644 packages/chat/telegram/test/TelegramChat.test.ts
 create mode 100644 packages/chat/telegram/test/conformance.test.ts
 create mode 100644 packages/chat/telegram/test/markdown.test.ts
 create mode 100644 packages/chat/telegram/test/utils.ts
 create mode 100644 packages/chat/telegram/tsconfig.json

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
new file mode 100644
index 00000000000..9cc2fe537a3
--- /dev/null
+++ b/packages/chat/telegram/README.md
@@ -0,0 +1,95 @@
+# @effect/chat-telegram
+
+A [Telegram](https://telegram.org) adapter for `effect/chat`, over the Bot API. It includes a webhook endpoint, a long-polling loop, a pure update normaliser, and the address helpers.
+
+This package is private. Nothing in it has run against Telegram yet, and it stays private until the live checks below pass.
+
+## Setup
+
+Create a bot with [@BotFather](https://t.me/BotFather) and keep its token. Pick one transport: a webhook, or polling for a long-running process. Telegram allows only one at a time.
+
+```ts
+import * as TelegramChat from "@effect/chat-telegram/TelegramChat"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+
+const token = Redacted.make("")
+const secretToken = Redacted.make("<32 to 256 characters of A-Za-z0-9_->")
+
+const Webhook = TelegramChat.layerWebhook({ path: "/telegram", secretToken }).pipe(
+  Layer.provideMerge(TelegramChat.layer({ token }))
+)
+
+const Polling = TelegramChat.layerPolling().pipe(
+  Layer.provideMerge(TelegramChat.layer({ token }))
+)
+```
+
+`TelegramChat.layer` needs `HttpClient` and the chat `Registry`. `TelegramChat.layerWebhook` also needs `HttpRouter` and a `ChatHandler`, and `TelegramChat.layerPolling` a `ChatHandler`. Clicks and commands go to `ChatInteraction.Handler` when one is in context.
+
+Register the webhook once with `TelegramChat.setWebhook({ url, secretToken })`, which sets exactly the `allowed_updates` the adapter reads. The adapter never calls it, or `deleteWebhook`, on its own. Polling fails to start with `InvalidRequest` and detail `conflict` while a webhook is set.
+
+`environment: "test"` uses Telegram's [test environment](https://core.telegram.org/bots/features#dedicated-test-environment). `apiUrl` points at a local Bot API server.
+
+## Capabilities
+
+By default the descriptor advertises `edit`, `delete`, `replyTo`, `download`, `getThread` and `getUser`, alongside `post`. Posts and edits are rich messages (`sendRichMessage`). `getUser` needs `in`, the chat to look the user up in.
+
+These capabilities are implemented but stay off until their live checks pass. Turn them on with the `unverified` option, at your own risk:
+
+| Option     | Turns on   | Live checks |
+| ---------- | ---------- | ----------- |
+| `files`    | `files`    | 6           |
+| `buttons`  | `buttons`  | 7, 8        |
+| `commands` | `commands` | 7, 9, 10    |
+
+An edit of a message posted with files may drop its media. Live check 6 decides whether that is so.
+
+Not supported in this version: `ephemeral`, `fetchMessage`, `history`, `opener`, `startThread`, selects, modals, native streams, reactions (outbound and as events), and typing. A private answer to a command is refused through `ChatInteraction.Handler.refused` with `Unsupported`, and is never posted in public. A `message_reaction` update goes to `onUnhandled`.
+
+Updates from business connections, a channel's direct messages and guest mode are never dispatched: they go to `onUnhandled`. A business chat's button is answered so the client stops waiting.
+
+## Security
+
+- The bot token is in the URL path of every Bot API call. The adapter turns off the HTTP client's own spans for these calls, writes its own span with the path as `/bot/{method}`, never follows a redirect, and keeps the token out of every error.
+- The webhook needs the `X-Telegram-Bot-Api-Secret-Token` header, compared in constant time, before it reads the body. An app that records server request headers must add `TelegramChat.secretHeader` to `Headers.CurrentRedactedNames`.
+- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`.
+- A click is dispatched only when its `data` matches a button in Telegram's own copy of the message. That shows the bot put the button there, not that it is still current or that this user may press it.
+
+## Redelivery
+
+Telegram sends an update again until it gets a 200, clicks and commands included. The webhook answers 503 when the `ChatHandler` fails `NotAccepted` or passes its deadline, and Telegram retries. Polling retries an update up to `maxAttempts` times, then logs it and moves on.
+
+A handler whose work must not run twice keys it with `TelegramChat.deliveryKey(event.raw, { botId })`:
+
+1. Record the key and do the work in one transaction.
+2. Reply only after the commit.
+3. When the key is already there, answer a repeated click with `Ack` and a repeated command with `Defer`, so a command is never handled twice and never falls through to `MessageCreated`.
+
+## Live checks
+
+None of these have run yet. Most run in the test environment, with a test bot, two test users and a forum supergroup where the bot is an admin. Check 17 repeats the ones that matter on production.
+
+1. Rich messages render on current clients, and what older ones show.
+2. The rich-Markdown dialect and its escapes, matching the escaping above.
+3. The limits: what 32,768 counts, what a block is, nesting and table columns.
+4. Link previews on rich posts and edits, and whether they can be turned off.
+5. Whether a plain `@user`, a `tg://user` link and a `text_mention` notify.
+6. Rich-message media over multipart `attach://`, and edits of a message with media.
+7. Webhook and polling redelivery after a 503 or a dropped connection.
+8. Callback queries: the server's copy of `reply_markup`, forged `data`, delayed clicks.
+9. Ephemeral commands, with an author and a bystander.
+10. The error responses behind the error mapping.
+11. Forum topics and the General topic.
+12. Reaction updates.
+13. Edit pacing and `retry_after`.
+14. `getChatMember` as a non-admin.
+15. Whether a plain `@bot` mention reaches a bot in privacy mode.
+16. Inbound rich messages.
+17. A production smoke check of 1, 4, 5, 9, 13 and 15.
+
+## Links
+
+- [Website](https://effect.website): documentation, guides, and news.
+- [Discord](https://discord.gg/effect-ts): ask questions, share what you're building, and talk to the core team.
+- [Issues](https://github.com/Effect-TS/effect/issues): bug reports and feature requests.
diff --git a/packages/chat/telegram/package.json b/packages/chat/telegram/package.json
new file mode 100644
index 00000000000..9a9f4129def
--- /dev/null
+++ b/packages/chat/telegram/package.json
@@ -0,0 +1,70 @@
+{
+  "name": "@effect/chat-telegram",
+  "version": "4.1.4",
+  "private": true,
+  "type": "module",
+  "license": "MIT",
+  "description": "The Telegram Bot API adapter for effect/chat",
+  "homepage": "https://effect.website",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/Effect-TS/effect.git",
+    "directory": "packages/chat/telegram"
+  },
+  "bugs": {
+    "url": "https://github.com/Effect-TS/effect/issues"
+  },
+  "tags": [
+    "typescript",
+    "chat",
+    "telegram"
+  ],
+  "keywords": [
+    "typescript",
+    "chat",
+    "telegram"
+  ],
+  "sideEffects": [],
+  "exports": {
+    "./package.json": "./package.json",
+    ".": "./src/index.ts",
+    "./*": "./src/*.ts",
+    "./internal/*": null,
+    "./index": null,
+    "./*/index": null
+  },
+  "files": [
+    "src/**/*.ts",
+    "dist/**/*.js",
+    "dist/**/*.js.map",
+    "dist/**/*.d.ts",
+    "dist/**/*.d.ts.map",
+    "AGENTS.md",
+    "CLAUDE.md",
+    "ai-docs/**/*"
+  ],
+  "publishConfig": {
+    "access": "public",
+    "provenance": true,
+    "exports": {
+      "./package.json": "./package.json",
+      ".": "./dist/index.js",
+      "./*": "./dist/*.js",
+      "./internal/*": null,
+      "./index": null,
+      "./*/index": null
+    }
+  },
+  "scripts": {
+    "codegen": "effect-utils codegen",
+    "build": "tsc -b tsconfig.json && pnpm babel",
+    "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
+    "check": "tsc -b tsconfig.json"
+  },
+  "devDependencies": {
+    "effect": "workspace:^"
+  },
+  "peerDependencies": {
+    "effect": "workspace:^"
+  }
+}
diff --git a/packages/chat/telegram/src/TelegramBotApi.ts b/packages/chat/telegram/src/TelegramBotApi.ts
new file mode 100644
index 00000000000..41a9b9a5b1f
--- /dev/null
+++ b/packages/chat/telegram/src/TelegramBotApi.ts
@@ -0,0 +1,282 @@
+/**
+ * The minimal Bot API client the Telegram adapter is built on. It is public,
+ * so a consumer can call a method the adapter has no op for, with the same
+ * error mapping, the same rule for writes and the same care for the token.
+ *
+ * **Details**
+ *
+ * The bot token is part of every request's path, and `HttpClient` records
+ * the path of a request in its span and in its errors. So the client's own
+ * span is turned off for every request made here, and each call gets a span
+ * `TelegramBotApi.{method}` whose `url.path` is `/bot/{method}`.
+ * Every failure becomes a `ChatError` whose `cause` holds no request,
+ * response or URL.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import { type File, retrySafe } from "effect/chat/ChatAdapter"
+import type { ChatError, ChatErrorReason } from "effect/chat/ChatError"
+import { ChatThread } from "effect/chat/ChatThread"
+import * as Context from "effect/Context"
+import * as Effect from "effect/Effect"
+import * as FetchHttpClient from "effect/http/FetchHttpClient"
+import * as HttpClient from "effect/http/HttpClient"
+import * as HttpClientRequest from "effect/http/HttpClientRequest"
+import type * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+import * as Schema from "effect/Schema"
+import * as Stream from "effect/Stream"
+import * as Address from "./internal/address.ts"
+import * as Errors from "./internal/errors.ts"
+
+/**
+ * Which Telegram environment a bot lives in. The test environment has its
+ * own accounts and bots, and its methods sit under `/bot/test/`.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Environment = "production" | "test"
+
+/**
+ * The cause of a `NotFound` with detail `chat_migrated`: the group became
+ * a supergroup, which has a new chat id. The adapter does not follow it,
+ * since the consumer is the one that stores the old address.
+ *
+ * @stability unstable
+ * @category errors
+ * @since 4.1.5
+ */
+export class TelegramChatMigrated extends Schema.TaggedError(
+  "@effect/chat-telegram/TelegramBotApi/TelegramChatMigrated"
+)("TelegramChatMigrated", {
+  thread: ChatThread
+}) {
+  override get message(): string {
+    return "The Telegram group became a supergroup with a new address"
+  }
+}
+
+/**
+ * Options for one Bot API call.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface CallOptions {
+  /**
+   * The call changes something. It is never repeated once the request left,
+   * and a failure that may have landed is `uncertain`.
+   */
+  readonly write?: boolean | undefined
+  /** Files sent as parts of a `multipart/form-data` body, each under its `field`. */
+  readonly files?: ReadonlyArray<{ readonly field: string; readonly file: File }> | undefined
+  /** Retry `retry` failures, as `ChatAdapter.retrySafe` does. Default true. */
+  readonly retry?: boolean | undefined
+}
+
+/**
+ * The Bot API client, with the bot's token.
+ *
+ * **Details**
+ *
+ * - `call` posts `params` to a method and succeeds with its `result`.
+ *   Objects in `params` are sent as JSON; with `files` the body is
+ *   multipart and each object is a JSON string part.
+ * - An answer with `ok: false` fails with the reason for its `error_code`
+ *   and `parameters`. Its `detail` is a fixed string, never Telegram's
+ *   description, which can quote the message. A `migrate_to_chat_id` gives
+ *   `NotFound` with detail `chat_migrated` and a `TelegramChatMigrated`
+ *   cause.
+ * - `file` streams a file by its `file_path` from `getFile`, failing
+ *   `TooLarge` once more than `maxBytes` arrive. Redirects are refused.
+ * - `botId` is the numeric id in front of the token's colon.
+ * - The error's `op` is the method.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class TelegramBotApi extends Context.Service> | undefined,
+    options?: CallOptions | undefined
+  ) => Effect.Effect
+  readonly file: (filePath: string, options: { readonly maxBytes: number }) => Stream.Stream
+}>()("@effect/chat-telegram/TelegramBotApi") {}
+
+/**
+ * The cloud Bot API server.
+ *
+ * @stability unstable
+ * @category constants
+ * @since 4.1.5
+ */
+export const defaultApiUrl = "https://api.telegram.org"
+
+const methodName = /^[A-Za-z]{1,64}$/
+const filePath = /^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+const formValue = (value: unknown): string => typeof value === "string" ? value : JSON.stringify(value)
+
+/**
+ * Builds the client from an `HttpClient` and a bot token.
+ *
+ * **Details**
+ *
+ * Fails `Unauthenticated` with detail `invalid_token` when the token has
+ * no numeric bot id in front of a colon. `apiUrl` is for a local Bot API
+ * server and is privileged configuration.
+ *
+ * @stability unstable
+ * @category constructors
+ * @since 4.1.5
+ */
+export const make = Effect.fnUntraced(function*(options: {
+  readonly token: Redacted.Redacted
+  readonly environment?: Environment | undefined
+  readonly apiUrl?: string | undefined
+}) {
+  const http = yield* HttpClient.HttpClient
+  const environment = options.environment ?? "production"
+  const apiUrl = (options.apiUrl ?? defaultApiUrl).replace(/\/+$/, "")
+  const botId = /^(\d{1,20}):[A-Za-z0-9_-]+$/.exec(Redacted.value(options.token))?.[1]
+  if (botId === undefined) {
+    return yield* Effect.fail(Errors.chatError("layer", Errors.unauthenticatedToken))
+  }
+  const suffix = environment === "test" ? "/test" : ""
+  const methodUrl = (method: string) => `${apiUrl}/bot${Redacted.value(options.token)}${suffix}/${method}`
+  const fileUrl = (path: string) => `${apiUrl}/file/bot${Redacted.value(options.token)}${suffix}/${path}`
+
+  // Redirects are never followed: the next hop would see the token in the path.
+  const send = (request: HttpClientRequest.HttpClientRequest, op: string, write: boolean) =>
+    Effect.flatMap(Effect.serviceOption(FetchHttpClient.RequestInit), (init) =>
+      http.execute(request).pipe(
+        Effect.provideService(HttpClient.TracerDisabledWhen, () => true),
+        Effect.provideService(FetchHttpClient.RequestInit, {
+          ...(init._tag === "Some" ? init.value : {}),
+          redirect: "manual"
+        }),
+        Effect.mapError((error) => Errors.chatError(op, Errors.transport(write, error.reason._tag)))
+      ))
+
+  const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
+
+  const decode = (op: string, write: boolean, response: HttpClientResponse.HttpClientResponse) =>
+    response.json.pipe(
+      Effect.matchEffect({
+        onFailure: () =>
+          response.status >= 200 && response.status < 300
+            ? fail(op, Errors.invalidResponse(write, "invalid_json"))
+            : fail(op, Errors.reasonForApiError({ code: response.status, description: "" }, { write })),
+        onSuccess: (body): Effect.Effect => {
+          if (isObject(body) && body.ok === true && "result" in body) return Effect.succeed(body.result as Schema.Json)
+          const error = Errors.apiError(body, response.status) ??
+            (response.status >= 200 && response.status < 300
+              ? undefined
+              : { code: response.status, description: "" })
+          if (error === undefined) return fail(op, Errors.invalidResponse(write, "invalid_answer"))
+          const cause = error.migrateTo === undefined
+            ? undefined
+            : new TelegramChatMigrated({ thread: Address.thread(error.migrateTo) })
+          return fail(op, Errors.reasonForApiError(error, { write, cause }))
+        }
+      })
+    )
+
+  const once = (method: string, params: Readonly>, callOptions: CallOptions) => {
+    const write = callOptions.write === true
+    let request = HttpClientRequest.post(methodUrl(method))
+    if (callOptions.files !== undefined && callOptions.files.length > 0) {
+      const form = new FormData()
+      for (const [key, value] of Object.entries(params)) {
+        if (value !== undefined) form.append(key, formValue(value))
+      }
+      for (const { field, file } of callOptions.files) {
+        form.append(
+          field,
+          new Blob([file.content as Uint8Array], { type: file.contentType }),
+          file.name
+        )
+      }
+      request = HttpClientRequest.bodyFormData(request, form)
+    } else {
+      request = HttpClientRequest.bodyJsonUnsafe(request, params)
+    }
+    return Effect.flatMap(send(request, method, write), (response) => decode(method, write, response)).pipe(
+      Effect.withSpan(`TelegramBotApi.${method}`, {
+        kind: "client",
+        attributes: {
+          "http.request.method": "POST",
+          "url.path": `/bot${suffix}/${method}`,
+          "telegram.method": method
+        }
+      })
+    )
+  }
+
+  const call: TelegramBotApi["Service"]["call"] = (method, params = {}, callOptions = {}) => {
+    if (!methodName.test(method)) return fail(method, Errors.invalidRequest("invalid_method"))
+    const effect = once(method, params, callOptions)
+    return callOptions.retry === false ? effect : retrySafe(effect)
+  }
+
+  const file: TelegramBotApi["Service"]["file"] = (path, { maxBytes }) =>
+    Stream.unwrap(
+      Effect.gen(function*() {
+        const op = "download"
+        if (!filePath.test(path) || path.split("/").some((segment) => segment === "." || segment === "..")) {
+          return yield* fail(op, Errors.invalidResponse(false, "untrusted_file_path"))
+        }
+        const url = fileUrl(path)
+        const response = yield* send(HttpClientRequest.get(url), op, false)
+        if (response.status >= 300 && response.status < 400) {
+          return yield* fail(op, Errors.invalidResponse(false, "redirect"))
+        }
+        if (response.url !== url) return yield* fail(op, Errors.invalidResponse(false, "redirect"))
+        if (response.status < 200 || response.status >= 300) {
+          return yield* fail(op, Errors.reasonForApiError({ code: response.status, description: "" }, { write: false }))
+        }
+        const tooLarge = Errors.chatError(op, Errors.tooLarge("files", "max_bytes"))
+        const length = Number(response.headers["content-length"])
+        if (Number.isFinite(length) && length > maxBytes) return yield* Effect.fail(tooLarge)
+        let received = 0
+        return response.stream.pipe(
+          Stream.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag))),
+          Stream.mapEffect((chunk) => {
+            received += chunk.length
+            return received > maxBytes ? Effect.fail(tooLarge) : Effect.succeed(chunk)
+          })
+        )
+      }).pipe(
+        Effect.withSpan("TelegramBotApi.file", {
+          kind: "client",
+          attributes: { "http.request.method": "GET", "url.path": "/file/bot" }
+        })
+      )
+    )
+
+  return TelegramBotApi.of({ botId, environment, call, file })
+})
+
+/**
+ * The client as a layer.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layer = (options: {
+  readonly token: Redacted.Redacted
+  readonly environment?: Environment | undefined
+  readonly apiUrl?: string | undefined
+}): Layer.Layer => Layer.effect(TelegramBotApi, make(options))
diff --git a/packages/chat/telegram/src/TelegramChat.ts b/packages/chat/telegram/src/TelegramChat.ts
new file mode 100644
index 00000000000..35192f63152
--- /dev/null
+++ b/packages/chat/telegram/src/TelegramChat.ts
@@ -0,0 +1,515 @@
+/**
+ * The Telegram adapter for `effect/chat`, over the Bot API: the `Registry`
+ * layer, the webhook and polling transports, the pure normaliser and the
+ * address helpers.
+ *
+ * **Details**
+ *
+ * - Raw REST over `HttpClient`, through `TelegramBotApi`, which keeps the
+ *   bot token out of spans and errors.
+ * - Posts and edits are rich messages (`sendRichMessage`,
+ *   `editMessageText` with `rich_message`), in Markdown escaped so that
+ *   consumer text reaches no raw HTML, image, math, spoiler or non-web
+ *   link.
+ * - Nothing here has run against Telegram yet, and the package is private
+ *   until it has. Files, buttons and commands are behind `unverified`
+ *   options, off by default, so a descriptor never advertises what no live
+ *   check confirmed.
+ * - There is no `ephemeral`: a private answer to a command is refused
+ *   through `Handler.refused`, never posted. `fetchMessage`, `history`,
+ *   `opener`, `startThread`, selects, modals, native streams and reaction
+ *   events are not in this version.
+ *
+ * @stability unstable
+ * @since 4.1.5
+ */
+import { Registry } from "effect/chat/ChatAdapter"
+import type { ChatError } from "effect/chat/ChatError"
+import type { ChatEvent } from "effect/chat/ChatEvent"
+import { ChatHandler } from "effect/chat/ChatHandler"
+import type * as ChatInteraction from "effect/chat/ChatInteraction"
+import type { ParseMention } from "effect/chat/ChatTest"
+import type { ChatThread } from "effect/chat/ChatThread"
+import * as Context from "effect/Context"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import { dual } from "effect/Function"
+import type * as HttpClient from "effect/http/HttpClient"
+import * as HttpRouter from "effect/http/HttpRouter"
+import * as Layer from "effect/Layer"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Adapter from "./internal/adapter.ts"
+import * as Address from "./internal/address.ts"
+import * as Commands from "./internal/commands.ts"
+import * as Errors from "./internal/errors.ts"
+import * as Normalize from "./internal/normalize.ts"
+import { CurrentPostOptions } from "./internal/options.ts"
+import * as Polling from "./internal/polling.ts"
+import * as Receive from "./internal/receive.ts"
+import * as Webhook from "./internal/webhook.ts"
+import * as TelegramBotApi from "./TelegramBotApi.ts"
+
+/**
+ * Capabilities that are built but stay off until their live checks pass.
+ *
+ * **Details**
+ *
+ * - `files`: rich-message media sent as multipart `attach://` parts,
+ *   up to 10 per post and 50 MB each.
+ * - `buttons`: inline keyboards. A click is dispatched only when its
+ *   `data` matches a button in Telegram's copy of the message.
+ * - `commands`: messages that start with a `bot_command` for this bot.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface Unverified {
+  readonly files?: boolean | undefined
+  readonly buttons?: boolean | undefined
+  readonly commands?: boolean | undefined
+}
+
+/**
+ * What became of one update given to `receive`.
+ *
+ * **Details**
+ *
+ * - `accepted`: its event was accepted, or its click or command was
+ *   answered, refused or not.
+ * - `unhandled`: it gave nothing and went to `onUnhandled`.
+ * - `notAccepted`: the `ChatHandler` failed `NotAccepted` or passed
+ *   `deadline`.
+ * - `invalid`: it is not an update, or it should give an event and could
+ *   not be read.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export type Outcome = "accepted" | "unhandled" | "notAccepted" | "invalid"
+
+/**
+ * Options for running updates.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface ReceiveOptions {
+  /** Updates that give no event, the excluded contexts among them. */
+  readonly onUnhandled?: ((update: Schema.Json) => Effect.Effect) | undefined
+  /** How long `ChatHandler.handle` has. Default 10 seconds. */
+  readonly deadline?: Duration.Input | undefined
+  /** A click handler's share before the click is answered. Default 2.5 seconds. */
+  readonly clickDeadline?: Duration.Input | undefined
+  /** A command handler's share. Default 10 seconds. */
+  readonly commandDeadline?: Duration.Input | undefined
+}
+
+/**
+ * The Telegram adapter's own service.
+ *
+ * **Details**
+ *
+ * - `botId` is the numeric id in front of the token's colon.
+ * - `receive` runs one update, already authenticated and parsed, as both
+ *   transports do, for a consumer's own transport. It needs a
+ *   `ChatHandler`. Clicks and commands go to `ChatInteraction.Handler`
+ *   when there is one in context: without it a click is answered and
+ *   dropped, and a command is an ordinary message.
+ *
+ * @stability unstable
+ * @category services
+ * @since 4.1.5
+ */
+export class TelegramChat extends Context.Service Effect.Effect
+}>()("@effect/chat-telegram/TelegramChat") {}
+
+/**
+ * Registers the Telegram adapter in the `Registry` and provides the
+ * `TelegramChat` and `TelegramBotApi` services.
+ *
+ * **Details**
+ *
+ * - The descriptor has `edit`, `delete`, `replyTo`, `download`,
+ *   `getThread` and `getUser`, beside `post`, and whatever `unverified`
+ *   turns on.
+ * - `environment: "test"` uses Telegram's test environment.
+ * - `apiUrl` is for a local Bot API server and is privileged configuration.
+ * - Fails `Unauthenticated` when the token has no bot id. The token is not
+ *   checked against Telegram here; the first call does that.
+ * - The bot's username, which commands and `@` mentions need, is read with
+ *   `getMe` on the first message and kept. While it can't be read, a
+ *   message update is `invalid`, and Telegram sends it again.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layer = (options: {
+  readonly token: Redacted.Redacted
+  readonly environment?: TelegramBotApi.Environment | undefined
+  readonly apiUrl?: string | undefined
+  readonly unverified?: Unverified | undefined
+}): Layer.Layer =>
+  Layer.effect(
+    TelegramChat,
+    Effect.gen(function*() {
+      const api = yield* TelegramBotApi.TelegramBotApi
+      const registry = yield* Registry
+      const capabilities = Adapter.capabilitiesOf(options.unverified ?? {})
+      const { adapter, answer } = Adapter.make({ api, capabilities })
+      yield* registry.register(adapter)
+      let username: string | undefined
+      const env: Receive.Environment = {
+        api,
+        capabilities,
+        answer,
+        username: Effect.suspend(() =>
+          username !== undefined ? Effect.succeed(username) : api.call("getMe").pipe(
+            Effect.flatMap((me) => {
+              const name = Normalize.isObject(me) ? Normalize.string(me, "username") : undefined
+              if (name === undefined) {
+                return Effect.fail(Errors.chatError("getMe", Errors.invalidResponse(false, "missing_username")))
+              }
+              username = name
+              return Effect.succeed(name)
+            })
+          )
+        )
+      }
+      return TelegramChat.of({
+        botId: api.botId,
+        environment: api.environment,
+        receive: Effect.fnUntraced(function*(update, receiveOptions) {
+          const handler = yield* ChatHandler
+          return yield* Receive.receive(update, env, receiveOptions ?? {}, handler.handle)
+        })
+      })
+    })
+  ).pipe(Layer.provideMerge(TelegramBotApi.layer(options)))
+
+/**
+ * The header Telegram sends the webhook secret in. An app that records
+ * server request headers must add it to `Headers.CurrentRedactedNames`,
+ * keeping the names already there.
+ *
+ * @stability unstable
+ * @category constants
+ * @since 4.1.5
+ */
+export const secretHeader: string = Webhook.secretHeader
+
+/**
+ * `POST {path}`: the bot's webhook.
+ *
+ * **Details**
+ *
+ * - The `X-Telegram-Bot-Api-Secret-Token` header must equal
+ *   `secretToken`, compared in constant time. Otherwise the answer is 401
+ *   and the body is not read. The layer fails unless `secretToken` is 32 to
+ *   256 characters of `A-Za-z0-9_-`.
+ * - 413 past `maxBodyBytes` (1 MiB by default), 400 for a body that is not
+ *   an update.
+ * - The update goes through `receive`: 200 for `accepted` and
+ *   `unhandled`, 503 for `notAccepted` and `invalid`, which Telegram
+ *   sends again. A click or command is answered 200 after its reply
+ *   attempt.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layerWebhook = (
+  options: ReceiveOptions & {
+    readonly path: `/${string}`
+    readonly secretToken: Redacted.Redacted
+    readonly maxBodyBytes?: number | undefined
+  }
+): Layer.Layer =>
+  HttpRouter.use(Effect.fnUntraced(function*(router) {
+    const secret = Redacted.value(options.secretToken)
+    if (!Webhook.validSecret(secret)) {
+      return yield* Effect.fail(Errors.chatError("layerWebhook", Errors.invalidRequest("invalid_secret_token")))
+    }
+    const telegram = yield* TelegramChat
+    const context = yield* Effect.context()
+    const encoded = new TextEncoder().encode(secret)
+    yield* router.add("POST", options.path, (request) =>
+      Webhook.handleRequest(request, {
+        secret: encoded,
+        maxBodyBytes: options.maxBodyBytes ?? 1024 * 1024,
+        receive: (update) => Effect.provideContext(telegram.receive(update, options), context)
+      }))
+  }))
+
+/**
+ * Long polling with `getUpdates`, for a long-running process.
+ *
+ * **Details**
+ *
+ * - Updates run one at a time, in order, through `receive`. An update is
+ *   confirmed only after it ran, so a process that dies part way sees it
+ *   again.
+ * - `notAccepted` and `invalid` are retried up to `maxAttempts` times (3
+ *   by default) with a backoff, then logged as an error and skipped:
+ *   `getUpdates` is one queue, and retrying forever would stall the bot.
+ * - The layer fails with `InvalidRequest` and detail `conflict` when
+ *   Telegram answers 409 at start: a webhook is set, or another process
+ *   polls. It never deletes a webhook itself. A later 409 stops polling
+ *   with an error log.
+ *
+ * @stability unstable
+ * @category layers
+ * @since 4.1.5
+ */
+export const layerPolling = (options: ReceiveOptions & {
+  /** The long-poll timeout. Default 30 seconds. */
+  readonly timeout?: Duration.Input | undefined
+  readonly maxAttempts?: number | undefined
+} = {}): Layer.Layer =>
+  Layer.effectDiscard(Effect.gen(function*() {
+    const telegram = yield* TelegramChat
+    const api = yield* TelegramBotApi.TelegramBotApi
+    const context = yield* Effect.context()
+    const pollingOptions: Polling.Options = {
+      api,
+      timeout: options.timeout === undefined ? Duration.seconds(30) : Duration.fromInputUnsafe(options.timeout),
+      maxAttempts: Math.max(1, options.maxAttempts ?? 3),
+      receive: (update) => Effect.provideContext(telegram.receive(update, options), context)
+    }
+    const first = yield* Polling.getUpdates(api, undefined, Duration.zero).pipe(Effect.mapError(Polling.conflict))
+    yield* Effect.forkScoped(Polling.loop(first, pollingOptions))
+  }))
+
+/**
+ * Registers the webhook with exactly the `allowed_updates` the adapter
+ * reads. It is never called by the adapter itself.
+ *
+ * @stability unstable
+ * @category webhooks
+ * @since 4.1.5
+ */
+export const setWebhook = (options: {
+  readonly url: string
+  readonly secretToken: Redacted.Redacted
+  readonly maxConnections?: number | undefined
+  readonly dropPendingUpdates?: boolean | undefined
+}): Effect.Effect =>
+  Effect.gen(function*() {
+    const secret = Redacted.value(options.secretToken)
+    if (!Webhook.validSecret(secret)) {
+      return yield* Effect.fail(Errors.chatError("setWebhook", Errors.invalidRequest("invalid_secret_token")))
+    }
+    const api = yield* TelegramBotApi.TelegramBotApi
+    yield* api.call("setWebhook", {
+      url: options.url,
+      secret_token: secret,
+      allowed_updates: Receive.allowedUpdates,
+      ...(options.maxConnections === undefined ? {} : { max_connections: options.maxConnections }),
+      ...(options.dropPendingUpdates === undefined ? {} : { drop_pending_updates: options.dropPendingUpdates })
+    }, { write: true })
+  })
+
+/**
+ * The `setMyCommands` payload for a group's commands.
+ *
+ * **Details**
+ *
+ * - Fails `InvalidRequest` with detail `invalid_command_names` when a
+ *   command id is not `[a-z0-9_]{1,32}`. The portable rule allows `-`;
+ *   Telegram does not.
+ * - An `argument` has no Telegram counterpart and is appended to the
+ *   description.
+ * - Commands are registered as ordinary, not ephemeral: this version has
+ *   no `ephemeral`.
+ *
+ * @stability unstable
+ * @category commands
+ * @since 4.1.5
+ */
+export const commandRequests = (
+  group: ChatInteraction.Group
+): Effect.Effect<
+  { readonly commands: ReadonlyArray<{ readonly command: string; readonly description: string }> },
+  ChatError
+> => {
+  const result = Commands.botCommands(group)
+  return "invalid" in result
+    ? Effect.fail(Errors.chatError("commandRequests", Errors.invalidRequest("invalid_command_names")))
+    : Effect.succeed(result)
+}
+
+/**
+ * Sends a group's commands with `setMyCommands`.
+ *
+ * @stability unstable
+ * @category commands
+ * @since 4.1.5
+ */
+export const setCommands = (
+  group: ChatInteraction.Group,
+  options?: { readonly scope?: Schema.Json | undefined; readonly languageCode?: string | undefined }
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const payload = yield* commandRequests(group)
+    const api = yield* TelegramBotApi.TelegramBotApi
+    yield* api.call("setMyCommands", {
+      commands: payload.commands,
+      ...(options?.scope === undefined ? {} : { scope: options.scope }),
+      ...(options?.languageCode === undefined ? {} : { language_code: options.languageCode })
+    }, { write: true })
+  })
+
+/**
+ * The address of a chat, or of a forum topic in it.
+ *
+ * @stability unstable
+ * @category constructors
+ * @since 4.1.5
+ */
+export const thread: (chatId: string | number, messageThreadId?: string | number | undefined) => ChatThread =
+  Address.thread
+
+/**
+ * The parts of a Telegram address, or `None` for another platform's or a
+ * malformed one.
+ *
+ * @stability unstable
+ * @category destructors
+ * @since 4.1.5
+ */
+export const parts: (thread: ChatThread) => Option.Option<{
+  readonly chatId: string
+  readonly messageThreadId?: string | undefined
+}> = Address.parts
+
+/**
+ * What the normalisers need to know about the bot.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface NormalizeContext {
+  readonly botId: string
+  /** The bot's username without `@`, from `getMe`. */
+  readonly botUsername: string
+  readonly environment?: TelegramBotApi.Environment | undefined
+}
+
+/**
+ * The normaliser, for a consumer's own transport. It checks no secret:
+ * that is the transport's job.
+ *
+ * **Details**
+ *
+ * - A `message` or `channel_post` with text, a caption, a file or rich
+ *   content gives a `MessageCreated`. `text` is verbatim, and empty for
+ *   an inbound rich message, whose content is only in `raw`.
+ * - `text_mention` entities are mentions by id. An `@username` is a
+ *   mention only when it names the bot.
+ * - The author is `sender_chat` when there is one, else `from`.
+ * - A private (ephemeral) message, a service message, and anything from a
+ *   business connection, a channel's direct messages or guest mode give
+ *   none, as does every other update. Commands are messages here too:
+ *   `receive` is what routes them.
+ * - `raw` is the update.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const normalize: (update: unknown, context: NormalizeContext) => ReadonlyArray = Normalize.normalize
+
+/**
+ * The click or command of an update, as `receive` would dispatch it.
+ *
+ * **Details**
+ *
+ * A click is given only when its `data` is the `callback_data` of a button
+ * in Telegram's own copy of the message. That proves the bot put the button
+ * there, not that it is still current or that this user may press it.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const normalizeInteraction = (
+  update: unknown,
+  context: NormalizeContext
+): Option.Option => {
+  if (!Normalize.isObject(update)) return Option.none()
+  return Option.fromUndefinedOr(Receive.clickEvent(update) ?? Receive.commandEvent(update, context))
+}
+
+/**
+ * The delivery key of an update, or of an event or interaction whose `raw`
+ * is one: `{botId}.{update_id}.{date}`, with `test.` in front in the test
+ * environment. Telegram sends an update again until it gets a 200 (or an
+ * offset moves past it), clicks and commands included, so a handler whose
+ * work must not run twice keeps this key with its work in one transaction.
+ *
+ * @stability unstable
+ * @category normalization
+ * @since 4.1.5
+ */
+export const deliveryKey = (
+  raw: unknown,
+  context: { readonly botId: string; readonly environment?: TelegramBotApi.Environment | undefined }
+): Option.Option => Option.fromUndefinedOr(Normalize.deliveryId(raw, context))
+
+/**
+ * Reads a mention for `ChatTest`. A mention's text is a display name or an
+ * `@username`, neither of which holds the id, so this is always `None`;
+ * a message's `mentions` come from its entities.
+ *
+ * @stability unstable
+ * @category testing
+ * @since 4.1.5
+ */
+export const parseMention: ParseMention = () => Option.none()
+
+/**
+ * Telegram options for every write inside an effect.
+ *
+ * @stability unstable
+ * @category models
+ * @since 4.1.5
+ */
+export interface TelegramPostOptions {
+  /**
+   * Users whose `[name](tg://user?id=…)` links in the Markdown stay links.
+   * Any other `tg://` link becomes text. Default: none.
+   */
+  readonly notify?: { readonly users?: ReadonlyArray | undefined } | undefined
+  /** Sends posts with `disable_notification`. */
+  readonly silent?: boolean | undefined
+}
+
+/**
+ * Scoped Telegram options for every write inside `effect`. Nested calls
+ * merge, the inner one winning field by field. Answers to commands and
+ * follow-ups ignore them.
+ *
+ * @stability unstable
+ * @category combinators
+ * @since 4.1.5
+ */
+export const withPostOptions: {
+  (options: TelegramPostOptions): (effect: Effect.Effect) => Effect.Effect
+  (effect: Effect.Effect, options: TelegramPostOptions): Effect.Effect
+} = dual(
+  2,
+  (effect: Effect.Effect, options: TelegramPostOptions): Effect.Effect =>
+    Effect.updateService(effect, CurrentPostOptions, (current) => ({ ...current, ...options }))
+)
diff --git a/packages/chat/telegram/src/index.ts b/packages/chat/telegram/src/index.ts
new file mode 100644
index 00000000000..7d3abb55339
--- /dev/null
+++ b/packages/chat/telegram/src/index.ts
@@ -0,0 +1,18 @@
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+
+// @barrel: Auto-generated exports. Do not edit manually.
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as TelegramBotApi from "./TelegramBotApi.ts"
+
+/**
+ * @stability unstable
+ * @since 4.1.5
+ */
+export * as TelegramChat from "./TelegramChat.ts"
diff --git a/packages/chat/telegram/src/internal/actions.ts b/packages/chat/telegram/src/internal/actions.ts
new file mode 100644
index 00000000000..07befe4091a
--- /dev/null
+++ b/packages/chat/telegram/src/internal/actions.ts
@@ -0,0 +1,97 @@
+import type { ChatErrorReason } from "effect/chat/ChatError"
+import type * as ChatUi from "effect/chat/ChatUi"
+import * as Errors from "./errors.ts"
+
+/** The adapter's own cap, as Telegram publishes no button count. @internal */
+export const actionsPerMessage = 100
+
+/** `callback_data` is 1 to 64 bytes, less the separator. @internal */
+export const actionDataLength = 63
+
+/** Between a button's id and its value in `callback_data`. @internal */
+export const separator = "\u001f"
+
+const encoder = new TextEncoder()
+
+const bytes = (s: string) => encoder.encode(s).length
+
+/** A button's `callback_data`: its id, and its value after the separator when it has one. @internal */
+export const callbackData = (button: { readonly id: string; readonly value?: string | undefined }): string =>
+  button.value === undefined ? button.id : button.id + separator + button.value
+
+/** The id and value of `callback_data`. @internal */
+export const parseData = (data: string): { readonly id: string; readonly value?: string | undefined } => {
+  const at = data.indexOf(separator)
+  return at === -1 ? { id: data } : { id: data.slice(0, at), value: data.slice(at + 1) }
+}
+
+/** A label short enough to share a row with two others. */
+const shortLabel = 12
+
+const perRow = 3
+
+type KeyboardButton =
+  | { readonly text: string; readonly callback_data: string; readonly style?: string }
+  | { readonly text: string; readonly url: string }
+
+/**
+ * The inline keyboard of a message's actions, or the reason it can't be
+ * sent: a select (`Unsupported`), too many elements, data past 63 bytes,
+ * an id holding the separator, or a link that is not http or https.
+ *
+ * @internal
+ */
+export const keyboard = (
+  actions: ReadonlyArray
+): { readonly inline_keyboard: ReadonlyArray> } | ChatErrorReason => {
+  if (actions.some((action) => action._tag === "Select")) return Errors.unsupported("selects")
+  if (actions.length > actionsPerMessage) return Errors.tooLarge(undefined, "too_many_actions")
+  const buttons: Array = []
+  for (const action of actions) {
+    if (action._tag === "Button") {
+      if (action.id.includes(separator)) return Errors.invalidRequest("invalid_action_id")
+      if (bytes(action.id) + bytes(action.value ?? "") > actionDataLength) {
+        return Errors.tooLarge(undefined, "action_data_too_long")
+      }
+      buttons.push({
+        text: action.label,
+        callback_data: callbackData(action),
+        ...(action.style === "primary" || action.style === "danger" ? { style: action.style } : {})
+      })
+    } else if (action._tag === "LinkButton") {
+      if (!/^https?:\/\//i.test(action.url)) return Errors.invalidRequest("untrusted_url")
+      buttons.push({ text: action.label, url: action.url })
+    }
+  }
+  const rows: Array> = []
+  let row: Array = []
+  for (const button of buttons) {
+    const short = button.text.length <= shortLabel
+    if (!short || row.length === perRow || row.some((b) => b.text.length > shortLabel)) {
+      if (row.length > 0) rows.push(row)
+      row = []
+    }
+    row.push(button)
+  }
+  if (row.length > 0) rows.push(row)
+  return { inline_keyboard: rows }
+}
+
+/** Every `callback_data` in a message's `reply_markup`. @internal */
+export const keyboardData = (replyMarkup: unknown): ReadonlySet => {
+  const data = new Set()
+  const rows = typeof replyMarkup === "object" && replyMarkup !== null
+    ? (replyMarkup as { readonly inline_keyboard?: unknown }).inline_keyboard
+    : undefined
+  if (!Array.isArray(rows)) return data
+  for (const row of rows) {
+    if (!Array.isArray(row)) continue
+    for (const button of row) {
+      const value = typeof button === "object" && button !== null
+        ? (button as { readonly callback_data?: unknown }).callback_data
+        : undefined
+      if (typeof value === "string") data.add(value)
+    }
+  }
+  return data
+}
diff --git a/packages/chat/telegram/src/internal/adapter.ts b/packages/chat/telegram/src/internal/adapter.ts
new file mode 100644
index 00000000000..3c458e4beed
--- /dev/null
+++ b/packages/chat/telegram/src/internal/adapter.ts
@@ -0,0 +1,333 @@
+import {
+  type ChatAdapter,
+  checkMessageLength,
+  type Descriptor,
+  type File,
+  type Posted,
+  type ThreadInfo
+} from "effect/chat/ChatAdapter"
+import { type Capability, type ChatError, type ChatErrorReason, interactionExpired } from "effect/chat/ChatError"
+import type * as ChatInteraction from "effect/chat/ChatInteraction"
+import type { ChatThread } from "effect/chat/ChatThread"
+import type * as ChatUi from "effect/chat/ChatUi"
+import * as DateTime from "effect/DateTime"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Option from "effect/Option"
+import * as Stream from "effect/Stream"
+import type { TelegramBotApi } from "../TelegramBotApi.ts"
+import * as Actions from "./actions.ts"
+import * as Address from "./address.ts"
+import * as Errors from "./errors.ts"
+import * as Markdown from "./markdown.ts"
+import { integer, isObject, messageOf, object, string } from "./normalize.ts"
+import { CurrentPostOptions } from "./options.ts"
+
+/** Capabilities that are built but not yet confirmed against Telegram. @internal */
+export interface Unverified {
+  readonly files?: boolean | undefined
+  readonly buttons?: boolean | undefined
+  readonly commands?: boolean | undefined
+}
+
+/** @internal */
+export const capabilitiesOf = (unverified: Unverified): ReadonlySet => {
+  const set = new Set(["edit", "delete", "replyTo", "download", "getThread", "getUser"])
+  if (unverified.files === true) set.add("files")
+  if (unverified.buttons === true) set.add("buttons")
+  if (unverified.commands === true) set.add("commands")
+  return set
+}
+
+/** How long Telegram takes an answer to a command, from the command's `date`. @internal */
+export const followUpAge = Duration.seconds(15)
+
+/** The largest file the cloud Bot API server hands out. @internal */
+export const downloadLimit = 20 * 1024 * 1024
+
+/** @internal */
+export const descriptorOf = (capabilities: ReadonlySet): Descriptor => ({
+  platform: Address.platform,
+  capabilities,
+  measure: (markdown) => Markdown.measure(markdown),
+  limits: {
+    messageLength: Markdown.messageLength,
+    filesPerMessage: capabilities.has("files") ? Markdown.filesPerMessage : 0,
+    uploadBytes: 50 * 1024 * 1024,
+    minWriteInterval: Duration.seconds(3),
+    ...(capabilities.has("buttons")
+      ? { actionsPerMessage: Actions.actionsPerMessage, actionDataLength: Actions.actionDataLength }
+      : {}),
+    ...(capabilities.has("commands") ? { followUpAge } : {})
+  }
+})
+
+/** Where a command's answer goes: the chat it came from, and the message to reply to, if any. @internal */
+export interface Origin {
+  readonly thread: ChatThread
+  readonly replyTo?: number | undefined
+  /** The command's `date`, in seconds. */
+  readonly date: number
+}
+
+/**
+ * Where a command's answers go. A reply to an ephemeral command would have
+ * to be ephemeral itself, and a reply would quote the private prompt, so
+ * a public answer to one is a new post.
+ *
+ * @internal
+ */
+export const originOf = (command: ChatInteraction.CommandInvoked): Origin | undefined => {
+  const raw = command.raw
+  const message = isObject(raw) ? messageOf(raw) : undefined
+  const id = integer(message, "message_id")
+  const date = integer(message, "date")
+  if (id === undefined || date === undefined) return undefined
+  return { thread: command.thread, ...(id === 0 ? {} : { replyTo: id }), date }
+}
+
+/** @internal */
+export const make = (options: {
+  readonly api: TelegramBotApi["Service"]
+  readonly capabilities: ReadonlySet
+}) => {
+  const { api, capabilities } = options
+  const descriptor = descriptorOf(capabilities)
+
+  const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
+
+  const unsupported = (op: string, capability: Capability) => fail(op, Errors.unsupported(capability))
+
+  const resolve = (op: string, thread: ChatThread): Effect.Effect => {
+    const parts = Address.parts(thread)
+    return Option.isNone(parts) ? fail(op, Errors.invalidRequest("invalid_thread")) : Effect.succeed(parts.value)
+  }
+
+  const target = (parts: Address.Parts) => ({
+    chat_id: Number(parts.chatId),
+    ...(parts.messageThreadId === undefined ? {} : { message_thread_id: Number(parts.messageThreadId) })
+  })
+
+  /** A message id Telegram can act on, or `NotFound` without a call: a private answer's label reaches nothing. */
+  const messageId = (op: string, id: string): Effect.Effect => {
+    const n = Address.messageId(id)
+    return n === undefined ? fail(op, Errors.notFound("message_not_found")) : Effect.succeed(n)
+  }
+
+  const markup = (op: string, actions: ReadonlyArray) => {
+    if (actions.length === 0) return Effect.succeed(undefined)
+    if (actions.some((action) => action._tag === "Select")) return unsupported(op, "selects")
+    if (!capabilities.has("buttons")) return unsupported(op, "buttons")
+    const keyboard = Actions.keyboard(actions)
+    return "inline_keyboard" in keyboard ? Effect.succeed(keyboard) : fail(op, keyboard)
+  }
+
+  const checkFiles = (op: string, files: ReadonlyArray) => {
+    if (files.length === 0) return Effect.void
+    if (!capabilities.has("files")) return unsupported(op, "files")
+    if (files.length > descriptor.limits.filesPerMessage) return fail(op, Errors.refusedFile)
+    if (files.some((file) => file.content.length > descriptor.limits.uploadBytes)) return fail(op, Errors.refusedFile)
+    return Effect.void
+  }
+
+  const richMessage = Effect.fnUntraced(function*(markdown: string, files: number) {
+    const postOptions = yield* CurrentPostOptions
+    return {
+      markdown: Markdown.render(markdown, {
+        mentions: new Set(postOptions.notify?.users ?? []),
+        files
+      }),
+      skip_entity_detection: true,
+      ...(files === 0 ? {} : {
+        media: Array.from({ length: files }, (_, i) => ({
+          id: `f${i + 1}`,
+          media: { type: "document", media: `attach://f${i + 1}` }
+        }))
+      })
+    }
+  })
+
+  const posted = (op: string, thread: ChatThread, answer: unknown): Effect.Effect => {
+    const message = isObject(answer) ? answer : undefined
+    const id = integer(message, "message_id")
+    const date = integer(message, "date")
+    if (id === undefined || id === 0) return fail(op, Errors.invalidResponse(true, "missing_message_id"))
+    return Effect.map(
+      date === undefined ? DateTime.now : Effect.succeed(DateTime.makeUnsafe(date * 1000)),
+      (timestamp) => ({ id: String(id), thread, timestamp })
+    )
+  }
+
+  /** One `sendRichMessage`. `retry` false for answers, which are never retried. */
+  const send = Effect.fnUntraced(function*(op: string, thread: ChatThread, content: {
+    readonly markdown: string
+    readonly actions?: ReadonlyArray | undefined
+    readonly files?: ReadonlyArray | undefined
+    readonly replyTo?: number | undefined
+    readonly retry?: boolean | undefined
+  }) {
+    const parts = yield* resolve(op, thread)
+    const actions = content.actions ?? []
+    const files = content.files ?? []
+    const replyMarkup = yield* markup(op, actions)
+    yield* checkFiles(op, files)
+    yield* checkMessageLength(descriptor, op, content.markdown, actions)
+    if (content.markdown.trim() === "" && files.length === 0) {
+      return yield* fail(op, Errors.invalidRequest("empty_message"))
+    }
+    const postOptions = yield* CurrentPostOptions
+    const answer = yield* api.call("sendRichMessage", {
+      ...target(parts),
+      rich_message: yield* richMessage(content.markdown, files.length),
+      ...(content.replyTo === undefined
+        ? {}
+        : { reply_parameters: { message_id: content.replyTo, allow_sending_without_reply: false } }),
+      ...(replyMarkup === undefined ? {} : { reply_markup: replyMarkup }),
+      ...(postOptions.silent === true ? { disable_notification: true } : {})
+    }, {
+      write: true,
+      retry: content.retry,
+      files: files.map((file, i) => ({ field: `f${i + 1}`, file }))
+    }).pipe(Effect.mapError(Errors.withOp(op)))
+    return yield* posted(op, thread, answer)
+  })
+
+  const post: ChatAdapter["post"] = Effect.fnUntraced(function*(thread, content) {
+    const replyTo = content.replyTo === undefined ? undefined : yield* messageId("post", content.replyTo.messageId)
+    return yield* send("post", thread, { ...content, replyTo })
+  })
+
+  const edit: ChatAdapter["edit"] = Effect.fnUntraced(function*(thread, id, content) {
+    const op = "edit"
+    const parts = yield* resolve(op, thread)
+    const message = yield* messageId(op, id)
+    const actions = content.actions ?? []
+    const replyMarkup = yield* markup(op, actions)
+    yield* checkMessageLength(descriptor, op, content.markdown, actions)
+    if (content.markdown.trim() === "") return yield* fail(op, Errors.invalidRequest("empty_message"))
+    yield* api.call("editMessageText", {
+      chat_id: Number(parts.chatId),
+      message_id: message,
+      rich_message: yield* richMessage(content.markdown, 0),
+      // An edit replaces the whole message: no actions removes the keyboard.
+      reply_markup: replyMarkup ?? { inline_keyboard: [] }
+    }, { write: true }).pipe(
+      Effect.catchIf(
+        (error) => error.reason._tag === "InvalidRequest" && error.reason.detail === "not_modified",
+        () => Effect.void
+      ),
+      Effect.mapError(Errors.withOp(op))
+    )
+  })
+
+  const deleteMessage: ChatAdapter["delete"] = Effect.fnUntraced(function*(thread, id) {
+    const op = "delete"
+    const parts = yield* resolve(op, thread)
+    const message = yield* messageId(op, id)
+    yield* api.call("deleteMessage", { chat_id: Number(parts.chatId), message_id: message }, { write: true }).pipe(
+      Effect.mapError(Errors.withOp(op))
+    )
+  })
+
+  const download: ChatAdapter["download"] = (thread, attachment, { maxBytes }) =>
+    Stream.unwrap(Effect.gen(function*() {
+      const op = "download"
+      yield* resolve(op, thread)
+      const limit = Math.min(maxBytes, downloadLimit)
+      const tooLarge = Errors.tooLarge("files", "max_bytes")
+      if (attachment.size !== undefined && attachment.size > limit) return yield* fail(op, tooLarge)
+      const answer = yield* api.call("getFile", { file_id: attachment.id }).pipe(Effect.mapError(Errors.withOp(op)))
+      const info = isObject(answer) ? answer : undefined
+      const path = string(info, "file_path")
+      const size = integer(info, "file_size")
+      if (size !== undefined && size > limit) return yield* fail(op, tooLarge)
+      if (path === undefined) return yield* fail(op, Errors.invalidResponse(false, "missing_file_path"))
+      return api.file(path, { maxBytes: limit })
+    }))
+
+  const getThread: ChatAdapter["getThread"] = Effect.fnUntraced(function*(thread) {
+    const op = "getThread"
+    const parts = yield* resolve(op, thread)
+    const answer = yield* api.call("getChat", { chat_id: Number(parts.chatId) }).pipe(
+      Effect.mapError(Errors.withOp(op))
+    )
+    const chat = isObject(answer) ? answer : undefined
+    if (parts.messageThreadId !== undefined) {
+      return { thread, kind: "thread", parent: Address.thread(parts.chatId), raw: answer } satisfies ThreadInfo
+    }
+    const name = string(chat, "title") ??
+      ([string(chat, "first_name"), string(chat, "last_name")].filter((part) => part !== undefined).join(" ") ||
+        undefined)
+    const topic = string(chat, "description")
+    return {
+      thread,
+      kind: chat?.type === "private" ? "direct" : "channel",
+      ...(name === undefined ? {} : { name }),
+      ...(topic === undefined ? {} : { topic }),
+      raw: answer
+    } satisfies ThreadInfo
+  })
+
+  const getUser: ChatAdapter["getUser"] = Effect.fnUntraced(function*(id, userOptions) {
+    const op = "getUser"
+    if (userOptions?.in === undefined) return yield* fail(op, Errors.invalidRequest("in_required"))
+    const parts = yield* resolve(op, userOptions.in)
+    if (!/^[1-9]\d{0,15}$/.test(id)) return yield* fail(op, Errors.notFound("user_not_found"))
+    const answer = yield* api.call("getChatMember", { chat_id: Number(parts.chatId), user_id: Number(id) }).pipe(
+      Effect.mapError(Errors.withOp(op))
+    )
+    const user = object(isObject(answer) ? answer : undefined, "user")
+    if (user === undefined || String(integer(user, "id")) !== id) {
+      return yield* fail(op, Errors.invalidResponse(false, "missing_user"))
+    }
+    const name = [string(user, "first_name"), string(user, "last_name")].filter((part) => part !== undefined).join(" ")
+    return {
+      id,
+      name: name === "" ? string(user, "username") ?? id : name,
+      isBot: user.is_bot === true,
+      isSelf: id === api.botId,
+      raw: answer
+    }
+  })
+
+  /** A public answer to a command. Never retried, so a timeout can't post it twice. @internal */
+  const answer = (op: string, origin: Origin, content: {
+    readonly markdown: string
+    readonly actions?: ReadonlyArray | undefined
+  }): Effect.Effect =>
+    send(op, origin.thread, { ...content, replyTo: origin.replyTo, retry: false }).pipe(
+      Effect.provideService(CurrentPostOptions, {})
+    )
+
+  const followUp: ChatAdapter["followUp"] = Effect.fnUntraced(function*(deferred, content) {
+    const op = "followUp"
+    if (!capabilities.has("commands")) return yield* unsupported(op, "commands")
+    if (deferred.visibility === "ephemeral") return yield* unsupported(op, "ephemeral")
+    const origin = originOf(deferred.command)
+    if (origin === undefined) return yield* fail(op, Errors.invalidRequest("invalid_command"))
+    const now = yield* DateTime.now
+    const deadline = (origin.date + 1) * 1000 + Duration.toMillis(followUpAge)
+    if (DateTime.toEpochMillis(now) > deadline) return yield* fail(op, Errors.notFound(interactionExpired))
+    yield* answer(op, origin, content)
+  })
+
+  const adapter: ChatAdapter = {
+    descriptor,
+    post,
+    edit,
+    delete: deleteMessage,
+    fetchMessage: () => unsupported("fetchMessage", "fetchMessage"),
+    history: () => Stream.fail(Errors.chatError("history", Errors.unsupported("history"))),
+    download,
+    startThread: () => unsupported("startThread", "startThread"),
+    getThread,
+    opener: () => unsupported("opener", "opener"),
+    getUser,
+    followUp
+  }
+
+  return { adapter, answer }
+}
+
+/** @internal */
+export type Made = ReturnType
diff --git a/packages/chat/telegram/src/internal/address.ts b/packages/chat/telegram/src/internal/address.ts
new file mode 100644
index 00000000000..a53f7d2e75b
--- /dev/null
+++ b/packages/chat/telegram/src/internal/address.ts
@@ -0,0 +1,33 @@
+import * as ChatThread from "effect/chat/ChatThread"
+import * as Option from "effect/Option"
+
+/** @internal */
+export const platform = "telegram"
+
+const chatId = /^-?[1-9]\d{0,15}$/
+const topicId = /^[1-9]\d{0,9}$/
+
+/** The address of a chat, or of a topic in it. @internal */
+export const thread = (chat: string | number, messageThreadId?: string | number | undefined): ChatThread.ChatThread =>
+  ChatThread.make(platform, messageThreadId === undefined ? String(chat) : `${chat}/${messageThreadId}`)
+
+/** The parts of an address. @internal */
+export interface Parts {
+  readonly chatId: string
+  readonly messageThreadId?: string | undefined
+}
+
+/** @internal */
+export const parts = (address: ChatThread.ChatThread): Option.Option => {
+  if (address.platform !== platform) return Option.none()
+  const [chat, topic, ...rest] = address.id.split("/")
+  if (rest.length > 0 || !chatId.test(chat)) return Option.none()
+  if (topic === undefined) return Option.some({ chatId: chat })
+  return topicId.test(topic) ? Option.some({ chatId: chat, messageThreadId: topic }) : Option.none()
+}
+
+/** The prefix of the label a private answer's message id gets: `e{ephemeral_message_id}.{date}`. @internal */
+export const ephemeralPrefix = "e"
+
+/** A message id as Telegram takes it, or undefined. @internal */
+export const messageId = (id: string): number | undefined => /^[1-9]\d{0,15}$/.test(id) ? Number(id) : undefined
diff --git a/packages/chat/telegram/src/internal/commands.ts b/packages/chat/telegram/src/internal/commands.ts
new file mode 100644
index 00000000000..0099432edd1
--- /dev/null
+++ b/packages/chat/telegram/src/internal/commands.ts
@@ -0,0 +1,37 @@
+import type * as ChatInteraction from "effect/chat/ChatInteraction"
+
+/** @internal */
+export interface BotCommand {
+  readonly command: string
+  readonly description: string
+}
+
+/**
+ * The `commands` of `setMyCommands` for a group's command definitions, or
+ * the ids Telegram can't take: its names are `[a-z0-9_]{1,32}`. A
+ * command's `argument` has no Telegram counterpart and is appended to its
+ * description, cut to 256 characters.
+ *
+ * @internal
+ */
+export const botCommands = (
+  group: ChatInteraction.Group
+): { readonly commands: ReadonlyArray } | { readonly invalid: ReadonlyArray } => {
+  const commands: Array = []
+  const invalid: Array = []
+  for (const definition of (group.definitions as ReadonlyMap).values()) {
+    if (definition.kind !== "command") continue
+    if (!/^[a-z0-9_]{1,32}$/.test(definition.id)) {
+      invalid.push(definition.id)
+      continue
+    }
+    const argument = definition.argument === undefined
+      ? ""
+      : ` <${definition.argument.name}${definition.argument.required ? "" : "?"}>: ${definition.argument.description}`
+    commands.push({
+      command: definition.id,
+      description: Array.from(definition.description + argument).slice(0, 256).join("")
+    })
+  }
+  return invalid.length > 0 ? { invalid } : { commands }
+}
diff --git a/packages/chat/telegram/src/internal/errors.ts b/packages/chat/telegram/src/internal/errors.ts
new file mode 100644
index 00000000000..59275ea958c
--- /dev/null
+++ b/packages/chat/telegram/src/internal/errors.ts
@@ -0,0 +1,137 @@
+import {
+  type Capability,
+  ChatError,
+  type ChatErrorReason,
+  fileRefused,
+  Forbidden,
+  InvalidRequest,
+  InvalidResponse,
+  NotFound,
+  PlatformUnavailable,
+  RateLimited,
+  TooLarge,
+  Transport,
+  Unauthenticated,
+  Unknown,
+  Unsupported
+} from "effect/chat/ChatError"
+import * as Duration from "effect/Duration"
+import { platform } from "./address.ts"
+
+/** @internal */
+export const chatError = (op: string, reason: ChatErrorReason): ChatError => new ChatError({ platform, op, reason })
+
+/** @internal */
+export const withOp = (op: string) => (error: ChatError): ChatError => chatError(op, error.reason)
+
+/** @internal */
+export const unsupported = (capability: Capability): ChatErrorReason => new Unsupported({ capability })
+
+/** @internal */
+export const invalidRequest = (detail: string): ChatErrorReason => new InvalidRequest({ detail })
+
+/** @internal */
+export const notFound = (detail: string): ChatErrorReason => new NotFound({ detail })
+
+/** @internal */
+export const tooLarge = (subject: "text" | "files" | undefined, detail: string): ChatErrorReason =>
+  new TooLarge({ ...(subject === undefined ? {} : { subject }), detail })
+
+/** @internal */
+export const unauthenticatedToken: ChatErrorReason = new Unauthenticated({ detail: "invalid_token" })
+
+/** @internal */
+export const refusedFile: ChatErrorReason = new TooLarge({ subject: "files", detail: fileRefused })
+
+/** The error Telegram answers with, without its description. @internal */
+export interface ApiError {
+  readonly code: number
+  readonly description: string
+  readonly retryAfter?: number | undefined
+  readonly migrateTo?: number | undefined
+}
+
+const isObject = (u: unknown): u is Record => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/** The error in a body that says `ok: false`, or undefined. @internal */
+export const apiError = (body: unknown, status: number): ApiError | undefined => {
+  if (!isObject(body) || body.ok !== false) return undefined
+  const parameters = isObject(body.parameters) ? body.parameters : {}
+  return {
+    code: typeof body.error_code === "number" ? body.error_code : status,
+    description: typeof body.description === "string" ? body.description.toLowerCase() : "",
+    ...(typeof parameters.retry_after === "number" ? { retryAfter: parameters.retry_after } : {}),
+    ...(typeof parameters.migrate_to_chat_id === "number" ? { migrateTo: parameters.migrate_to_chat_id } : {})
+  }
+}
+
+/**
+ * Descriptions that refine a 400 or a 403, matched as substrings. Each gives
+ * a fixed detail: a description can quote the message, so it never goes
+ * into an error. The table grows from captured answers (live check 10).
+ */
+const refinements: ReadonlyArray ChatErrorReason, string]> = [
+  ["message is not modified", invalidRequest, "not_modified"],
+  ["message to edit not found", notFound, "message_not_found"],
+  ["message to delete not found", notFound, "message_not_found"],
+  ["message to be replied not found", notFound, "reply_target_not_found"],
+  ["message not found", notFound, "message_not_found"],
+  ["chat not found", notFound, "chat_not_found"],
+  ["thread not found", notFound, "thread_not_found"],
+  ["user not found", notFound, "user_not_found"],
+  ["participant_id_invalid", notFound, "user_not_found"],
+  ["message can't be deleted", (detail) => new Forbidden({ detail }), "cannot_delete"],
+  ["message can't be edited", (detail) => new Forbidden({ detail }), "cannot_edit"],
+  ["not enough rights", (detail) => new Forbidden({ detail }), "not_enough_rights"],
+  ["have no rights", (detail) => new Forbidden({ detail }), "not_enough_rights"],
+  ["bot was blocked", (detail) => new Forbidden({ detail }), "blocked"],
+  ["bot was kicked", (detail) => new Forbidden({ detail }), "kicked"],
+  ["bot is not a member", (detail) => new Forbidden({ detail }), "not_a_member"],
+  ["too long", (detail) => tooLarge("text", detail), "message_too_long"],
+  ["too many blocks", (detail) => tooLarge("text", detail), "too_many_blocks"],
+  ["file is too big", () => refusedFile, fileRefused],
+  ["wrong file", () => refusedFile, fileRefused]
+]
+
+/** The detail of a chat that became a supergroup. @internal */
+export const chatMigrated = "chat_migrated"
+
+/**
+ * Maps one Telegram error. `cause` is attached as given: the caller passes
+ * nothing that holds a URL or message text.
+ *
+ * @internal
+ */
+export const reasonForApiError = (
+  error: ApiError,
+  options: { readonly write: boolean; readonly cause?: unknown }
+): ChatErrorReason => {
+  const cause = options.cause === undefined ? {} : { cause: options.cause }
+  if (error.code === 429) {
+    return new RateLimited({
+      detail: "telegram_429",
+      ...(error.retryAfter === undefined ? {} : { retryAfter: Duration.seconds(error.retryAfter) })
+    })
+  }
+  if (error.migrateTo !== undefined) return new NotFound({ detail: chatMigrated, ...cause })
+  if (error.code === 401 || error.code === 404) return new Unauthenticated({ detail: `telegram_${error.code}` })
+  if (error.code >= 500) {
+    return new PlatformUnavailable({ retry: options.write ? "uncertain" : "retry", detail: `telegram_${error.code}` })
+  }
+  if (error.code === 409) return invalidRequest("conflict")
+  if (error.code === 400 || error.code === 403) {
+    for (const [needle, make, detail] of refinements) {
+      if (error.description.includes(needle)) return make(detail)
+    }
+    return error.code === 403 ? new Forbidden({ detail: "telegram_403" }) : invalidRequest("telegram_400")
+  }
+  return invalidRequest(`telegram_${error.code}`)
+}
+
+/** A request that failed before an answer came. A write may have landed. No cause: it would hold the URL. @internal */
+export const transport = (write: boolean, detail: string): ChatErrorReason =>
+  new Transport({ retry: write ? "uncertain" : "retry", detail })
+
+/** An answer the adapter cannot read. A write may have landed. @internal */
+export const invalidResponse = (write: boolean, detail: string): ChatErrorReason =>
+  write ? new Unknown({ detail }) : new InvalidResponse({ detail })
diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
new file mode 100644
index 00000000000..b158847d5c0
--- /dev/null
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -0,0 +1,448 @@
+/**
+ * Rich Markdown for `sendRichMessage`: the escaping that keeps consumer
+ * Markdown from reaching Telegram's raw HTML, images, math, spoilers and
+ * non-web links, and the `measure` that bounds what it costs.
+ *
+ * @internal
+ */
+
+/** What one line break or block marker costs, so that a message in budget stays under 500 blocks. @internal */
+export const block = 65
+
+/** Telegram's rich message limit, read as UTF-8 bytes. @internal */
+export const richLimit = 32_768
+
+/** Files one post may carry. @internal */
+export const filesPerMessage = 10
+
+/** The most nesting and table columns Telegram renders. @internal */
+export const maxDepth = 16
+
+/** @internal */
+export const maxColumns = 20
+
+/** The reference to the `n`th file of a post, at the end of the Markdown. @internal */
+export const mediaReference = (n: number): string => `\n\n![](tg://document?id=f${n})`
+
+/**
+ * What the budget keeps back for media references and the fence a post
+ * with files may need to close: each reference's bytes and its block, one
+ * block for the message's first, which `measure` does not charge, and 8
+ * bytes for the fence.
+ *
+ * @internal
+ */
+export const reservation = filesPerMessage * (32 + block) + block + 8
+
+/** @internal */
+export const messageLength = richLimit - reservation
+
+const twoByteEscapes = new Set(["$", "=", "|", "!", "[", "]", "*", "_", "~", "`"])
+const blockMarkers = new Set([">", "-", "+", "*", ".", ")"])
+
+const isDigit = (c: string) => c >= "0" && c <= "9"
+
+/**
+ * A sum of per-character costs, each fixed or depending only on what comes
+ * before the character on its own line, which makes it subadditive:
+ *
+ * - a code point in the Basic Multilingual Plane costs its UTF-8 length,
+ *   and each UTF-16 surrogate 3, enough for the U+FFFD a lone one becomes.
+ *   NUL costs 3 too, as Markdown turns it into U+FFFD.
+ * - `<` costs 4, and `$ = | ! [ ] * _ ~` and the backtick 2, their
+ *   escaped length or more, whether or not they are escaped in context.
+ * - `\n` and `\r` cost `block`, as does a block marker (`>`, a bullet,
+ *   the dot or parenthesis of a number) before any other text on its line.
+ *
+ * @internal
+ */
+export const measure = (markdown: string): number => {
+  let cost = 0
+  let prefix = true
+  for (let i = 0; i < markdown.length; i++) {
+    const code = markdown.charCodeAt(i)
+    if (code === 10 || code === 13) {
+      cost += block
+      prefix = true
+      continue
+    }
+    if (code >= 0xd800 && code <= 0xdfff) {
+      cost += 3
+      prefix = false
+      continue
+    }
+    const c = markdown[i]
+    if (prefix) {
+      if (c === " " || c === "\t" || isDigit(c)) {
+        cost += 1
+        continue
+      }
+      if (blockMarkers.has(c)) {
+        cost += block
+        continue
+      }
+      prefix = false
+    }
+    cost += code === 0 ? 3 : c === "<" ? 4 : twoByteEscapes.has(c) ? 2 : code < 0x80 ? 1 : code < 0x800 ? 2 : 3
+  }
+  return cost
+}
+
+const punctuation = /[!-/:-@[-`{-~]/
+
+const isSpace = (c: string | undefined) => c === undefined || /\s/.test(c)
+
+/** A line that opens a top-level fence: at column 0, three or more backticks or tildes. */
+const fenceOpen = /^(`{3,}|~{3,})(.*)$/
+
+interface Fence {
+  readonly char: string
+  readonly length: number
+}
+
+const opens = (line: string): Fence | undefined => {
+  const match = fenceOpen.exec(line)
+  if (match === null || (match[1][0] === "`" && match[2].includes("`"))) return undefined
+  return { char: match[1][0], length: match[1].length }
+}
+
+const closes = (line: string, fence: Fence): boolean => {
+  const match = /^ {0,3}(`+|~+)[ \t]*$/.exec(line)
+  return match !== null && match[1][0] === fence.char && match[1].length >= fence.length
+}
+
+const delimiterRow = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/
+
+/** The cells of a table row, split at unescaped pipes as GFM does, even inside code. */
+const cellCount = (line: string): number => {
+  let count = 1
+  for (let i = 0; i < line.length; i++) {
+    if (line[i] === "\\") i++
+    else if (line[i] === "|") count++
+  }
+  const trimmed = line.trim()
+  if (trimmed.startsWith("|")) count--
+  if (trimmed.length > 1 && trimmed.endsWith("|") && !trimmed.endsWith("\\|")) count--
+  return count
+}
+
+const hasPipe = (line: string) => cellCount(line) > 1 || line.trim().startsWith("|")
+
+/** The decoded form of a link destination, as a Markdown parser and then a URL parser read it. */
+const decodeDestination = (raw: string): { readonly unescaped: string; readonly decoded: string } | undefined => {
+  let unescaped = raw.replace(/\\([!-/:-@[-`{-~])/g, "$1")
+  unescaped = unescaped.replace(/&#(\d{1,7});/g, (_, n: string) => String.fromCodePoint(Math.min(Number(n), 0x10ffff)))
+    .replace(/&#[xX]([0-9a-fA-F]{1,6});/g, (_, n: string) => String.fromCodePoint(Math.min(parseInt(n, 16), 0x10ffff)))
+    .replace(
+      /&(amp|lt|gt|quot|apos);/g,
+      (_, name: string) =>
+        name === "amp" ? "&" : name === "lt" ? "<" : name === "gt" ? ">" : name === "quot" ? "\"" : "'"
+    )
+  // Any other named reference could be one of HTML's many, such as `:`.
+  if (/&[A-Za-z][A-Za-z0-9]*;/.test(unescaped)) return undefined
+  try {
+    return { unescaped, decoded: decodeURIComponent(unescaped) }
+  } catch {
+    return undefined
+  }
+}
+
+const allowedScheme = /^(?:https?:\/\/|mailto:)/i
+
+/** Whether a link to `raw` may stay: http, https and mailto, or a mention the post allows. */
+const allowedDestination = (raw: string, mentions: ReadonlySet): boolean => {
+  const destination = decodeDestination(raw)
+  if (destination === undefined) return false
+  if (allowedScheme.test(destination.unescaped) && allowedScheme.test(destination.decoded)) return true
+  const mention = /^tg:\/\/user\?id=(\d{1,20})$/.exec(destination.decoded)
+  return mention !== null && destination.unescaped === destination.decoded && mentions.has(mention[1])
+}
+
+/** The raw destination after `](` at `start`, or undefined when it is not on this line or is in angle brackets. */
+const inlineDestination = (line: string, start: number): string | undefined => {
+  let i = start
+  while (line[i] === " " || line[i] === "\t") i++
+  if (i >= line.length || line[i] === "<") return undefined
+  let depth = 0
+  let end = i
+  for (; end < line.length; end++) {
+    const c = line[end]
+    if (c === "\\") {
+      end++
+      continue
+    }
+    if (/\s/.test(c)) break
+    if (c === "(") depth++
+    else if (c === ")") {
+      if (depth === 0) break
+      depth--
+    }
+  }
+  return line.slice(i, end)
+}
+
+/** The destination of a reference definition after `]:`, when it is on this line. */
+const definitionDestination = (line: string, start: number): string | undefined => {
+  const match = /^[ \t]*(\S+)/.exec(line.slice(start))
+  return match === null || match[1].startsWith("<") ? undefined : match[1]
+}
+
+/**
+ * The code spans of a line, as `[start, end)` pairs, paired the way
+ * CommonMark pairs backtick runs. A run with no partner on the line is
+ * not a span: the renderer escapes it, so no span can pair across lines.
+ * In a table row a span holding a pipe is refused, since GFM splits cells
+ * before it reads code.
+ */
+const codeSpans = (line: string, tableRow: boolean): Array => {
+  const spans: Array = []
+  let i = 0
+  while (i < line.length) {
+    const c = line[i]
+    if (c === "\\" && i + 1 < line.length && punctuation.test(line[i + 1])) {
+      i += 2
+      continue
+    }
+    if (c !== "`") {
+      i++
+      continue
+    }
+    let length = 0
+    while (line[i + length] === "`") length++
+    let j = i + length
+    let close = -1
+    while (j < line.length) {
+      if (line[j] !== "`") {
+        j++
+        continue
+      }
+      let run = 0
+      while (line[j + run] === "`") run++
+      if (run === length) {
+        close = j
+        break
+      }
+      j += run
+    }
+    if (close === -1 || (tableRow && line.slice(i, close).includes("|"))) {
+      i += length
+      continue
+    }
+    spans.push([i, close + length])
+    i = close + length
+  }
+  return spans
+}
+
+const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>]*>/
+
+/** The inline nesting carried through one paragraph. */
+interface Inline {
+  readonly stack: Array
+}
+
+interface LineContext {
+  readonly tableRow: boolean
+  readonly widePipes: boolean
+  readonly inline: Inline
+  readonly mentions: ReadonlySet
+}
+
+/**
+ * The container markers at the start of a line, with those past the depth
+ * limit escaped, and where the line's text starts.
+ */
+const renderPrefix = (line: string): { readonly text: string; readonly rest: number; readonly depth: number } => {
+  let out = ""
+  let i = 0
+  let depth = 0
+  let indent = 0
+  for (;;) {
+    const space = /^[ \t]*/.exec(line.slice(i))![0]
+    indent += space.length
+    out += space
+    i += space.length
+    const marker = /^(?:>|[-+*](?=[ \t]|$)|\d{1,9}[.)](?=[ \t]|$))/.exec(line.slice(i))
+    if (marker === null) break
+    depth++
+    const token = marker[0]
+    const escape = depth + Math.floor(indent / 2) >= maxDepth
+    out += escape ? token.slice(0, -1) + "\\" + token.slice(-1) : token
+    i += token.length
+  }
+  return { text: out, rest: i, depth: depth + Math.floor(indent / 2) }
+}
+
+const renderLine = (line: string, context: LineContext): string => {
+  const prefix = renderPrefix(line)
+  const setext = /^ {0,3}=+[ \t]*$/.test(line)
+  const spans = codeSpans(line, context.tableRow)
+  const footnote = line.slice(prefix.rest).startsWith("[^")
+  const limit = Math.max(0, maxDepth - 1 - prefix.depth)
+  const stack = context.inline.stack
+  let out = prefix.text
+  let span = 0
+  let firstBracket = true
+  let i = prefix.rest
+  while (i < line.length) {
+    while (span < spans.length && spans[span][1] <= i) span++
+    if (span < spans.length && spans[span][0] === i) {
+      out += line.slice(spans[span][0], spans[span][1])
+      i = spans[span][1]
+      continue
+    }
+    const c = line[i]
+    const next = line[i + 1]
+    if (c === "\\" && next !== undefined && punctuation.test(next)) {
+      out += c + next
+      i += 2
+      continue
+    }
+    switch (c) {
+      case "`":
+        out += "\\`"
+        i++
+        continue
+      case "<": {
+        const match = autolink.exec(line.slice(i))
+        const end = match === null ? -1 : i + match[0].length
+        const overlaps = match !== null && spans.some(([start]) => start > i && start < end)
+        if (match !== null && !overlaps && /^(?:https?|mailto)$/i.test(match[1])) {
+          out += match[0]
+          i = end
+        } else {
+          out += "\\<"
+          i++
+        }
+        continue
+      }
+      case "$":
+        out += "\\$"
+        i++
+        continue
+      case "=":
+        out += setext ? "=" : "\\="
+        i++
+        continue
+      case "|":
+        out += context.tableRow && !context.widePipes ? "|" : "\\|"
+        i++
+        continue
+      case "!":
+        out += next === "[" ? "\\!" : "!"
+        i++
+        continue
+      case "]": {
+        let keep = true
+        if (next === "(") {
+          const destination = inlineDestination(line, i + 2)
+          keep = destination !== undefined && allowedDestination(destination, context.mentions)
+        } else if (next === ":" && !(footnote && firstBracket)) {
+          const destination = definitionDestination(line, i + 2)
+          keep = destination !== undefined && allowedDestination(destination, context.mentions)
+        }
+        firstBracket = false
+        out += keep ? "]" : "\\]"
+        i++
+        continue
+      }
+      case "*":
+      case "_":
+      case "~": {
+        let end = i
+        while (line[end] === c) end++
+        const run = line.slice(i, end)
+        const before = i === 0 ? undefined : line[i - 1]
+        const after = line[end]
+        if (!isSpace(before) && stack.length > 0 && stack[stack.length - 1] === c) {
+          stack.pop()
+          out += run
+        } else if (!isSpace(after)) {
+          if (stack.length + 1 > limit) {
+            out += run.split("").map((char) => "\\" + char).join("")
+          } else {
+            stack.push(c)
+            out += run
+          }
+        } else {
+          out += run
+        }
+        i = end
+        continue
+      }
+      default:
+        out += c
+        i++
+    }
+  }
+  return out
+}
+
+/** @internal */
+export interface RenderOptions {
+  /** User ids whose `[name](tg://user?id=…)` links may stay. */
+  readonly mentions?: ReadonlySet | undefined
+  /** How many files the post references at the end. */
+  readonly files?: number | undefined
+}
+
+/**
+ * Consumer Markdown as rich Markdown that keeps to what `measure` charged:
+ *
+ * - Top-level fences (at column 0) pass verbatim, as do code spans whose
+ *   backticks pair on one line. Everything else is escaped as needed.
+ * - `<` is escaped unless it opens an http, https or mailto autolink, so
+ *   there is no raw HTML. `$` and `=` are escaped (math, marks), as is
+ *   `|` outside tables (spoilers), and `!` before `[` (images).
+ * - A link or reference definition whose destination, decoded as a
+ *   Markdown parser and then a URL parser would, is not http, https or
+ *   mailto has its `]` escaped, so it is text. A `tg://user` link stays
+ *   for an id in `mentions`.
+ * - Container markers and emphasis past 16 levels are escaped, and a table
+ *   wider than 20 columns has its pipes escaped.
+ * - `files` references are added at the end, after closing a fence left
+ *   open.
+ *
+ * @internal
+ */
+export const render = (markdown: string, options: RenderOptions = {}): string => {
+  const mentions = options.mentions ?? new Set()
+  const lines = markdown.replace(/\r\n?/g, "\n").replace(/\0/g, "\ufffd").split("\n")
+  const fenced: Array = []
+  let fence: Fence | undefined
+  for (const line of lines) {
+    if (fence !== undefined) {
+      fenced.push(true)
+      if (closes(line, fence)) fence = undefined
+      continue
+    }
+    fence = opens(line)
+    fenced.push(fence !== undefined)
+  }
+  const tableRows = new Map()
+  for (let i = 0; i + 1 < lines.length; i++) {
+    if (fenced[i] || fenced[i + 1] || tableRows.has(i)) continue
+    if (!delimiterRow.test(lines[i + 1]) || !lines[i + 1].includes("|") || !hasPipe(lines[i])) continue
+    const columns = cellCount(lines[i])
+    if (columns !== cellCount(lines[i + 1])) continue
+    let end = i + 2
+    while (end < lines.length && !fenced[end] && lines[end].trim() !== "") end++
+    const rows = Array.from({ length: end - i }, (_, k) => i + k)
+    for (const row of rows) tableRows.set(row, columns > maxColumns || cellCount(lines[row]) > maxColumns)
+    i = end - 1
+  }
+  const inline: Inline = { stack: [] }
+  const out = lines.map((line, i) => {
+    if (fenced[i]) return line
+    if (line.trim() === "") inline.stack.length = 0
+    const wide = tableRows.get(i)
+    return renderLine(line, { tableRow: wide !== undefined, widePipes: wide === true, inline, mentions })
+  })
+  let text = out.join("\n")
+  const files = options.files ?? 0
+  if (files > 0) {
+    if (fence !== undefined) text += "\n" + fence.char.repeat(fence.length)
+    for (let n = 1; n <= files; n++) text += mediaReference(n)
+  }
+  return text
+}
diff --git a/packages/chat/telegram/src/internal/normalize.ts b/packages/chat/telegram/src/internal/normalize.ts
new file mode 100644
index 00000000000..095f7a01567
--- /dev/null
+++ b/packages/chat/telegram/src/internal/normalize.ts
@@ -0,0 +1,276 @@
+import * as ChatEvent from "effect/chat/ChatEvent"
+import type * as ChatMessage from "effect/chat/ChatMessage"
+import type { ChatThread } from "effect/chat/ChatThread"
+import * as DateTime from "effect/DateTime"
+import type * as Schema from "effect/Schema"
+import * as Address from "./address.ts"
+
+/** @internal */
+export type JsonObject = { readonly [key: string]: Schema.Json }
+
+/** @internal */
+export const isObject = (u: unknown): u is JsonObject => typeof u === "object" && u !== null && !Array.isArray(u)
+
+/** @internal */
+export const object = (o: JsonObject | undefined, key: string): JsonObject | undefined => {
+  const value = o?.[key]
+  return isObject(value) ? value : undefined
+}
+
+/** @internal */
+export const string = (o: JsonObject | undefined, key: string): string | undefined => {
+  const value = o?.[key]
+  return typeof value === "string" ? value : undefined
+}
+
+/** @internal */
+export const integer = (o: JsonObject | undefined, key: string): number | undefined => {
+  const value = o?.[key]
+  return typeof value === "number" && Number.isSafeInteger(value) ? value : undefined
+}
+
+/** What normalising needs to know about the bot. @internal */
+export interface Context {
+  readonly botId: string
+  /** The bot's username, without `@`, from `getMe`. */
+  readonly botUsername?: string | undefined
+  readonly environment?: "production" | "test" | undefined
+}
+
+/**
+ * Whether a message belongs to a context v1 leaves out: a business
+ * connection, a channel's direct messages chat, or guest mode.
+ *
+ * @internal
+ */
+export const isExcluded = (message: JsonObject): boolean =>
+  "business_connection_id" in message ||
+  "guest_query_id" in message ||
+  "guest_bot_caller_user" in message ||
+  "guest_bot_caller_chat" in message ||
+  "direct_messages_topic" in message ||
+  object(message, "chat")?.is_direct_messages === true
+
+/** Whether a message is a private answer or input: `message_id` 0 with an `ephemeral_message_id`. @internal */
+export const isEphemeral = (message: JsonObject): boolean =>
+  integer(message, "message_id") === 0 && integer(message, "ephemeral_message_id") !== undefined
+
+/** The address and kind of the chat a message is in. @internal */
+export const threadOf = (
+  message: JsonObject
+): { readonly thread: ChatThread; readonly kind: ChatEvent.ThreadKind } | undefined => {
+  const chat = object(message, "chat")
+  const chatId = integer(chat, "id")
+  if (chat === undefined || chatId === undefined) return undefined
+  const topic = message.is_topic_message === true ? integer(message, "message_thread_id") : undefined
+  if (topic !== undefined) return { thread: Address.thread(chatId, topic), kind: "thread" }
+  return { thread: Address.thread(chatId), kind: chat.type === "private" ? "direct" : "channel" }
+}
+
+/** A message's id as events carry it: the real id, or `e{ephemeral_message_id}.{date}` for a private one. @internal */
+export const messageIdOf = (message: JsonObject): string | undefined => {
+  const id = integer(message, "message_id")
+  if (id === undefined) return undefined
+  if (id !== 0) return String(id)
+  const ephemeral = integer(message, "ephemeral_message_id")
+  return ephemeral === undefined ? undefined : `${Address.ephemeralPrefix}${ephemeral}.${integer(message, "date") ?? 0}`
+}
+
+const displayName = (user: JsonObject) => {
+  const name = [string(user, "first_name"), string(user, "last_name")].filter((part) => part !== undefined).join(" ")
+  return name === "" ? string(user, "username") : name
+}
+
+const authorOf = (message: JsonObject, context: Context): ChatMessage.Author | undefined => {
+  const senderChat = object(message, "sender_chat")
+  const senderChatId = integer(senderChat, "id")
+  if (senderChat !== undefined && senderChatId !== undefined) {
+    const title = string(senderChat, "title")
+    return { id: String(senderChatId), ...(title === undefined ? {} : { name: title }), isBot: false, isSelf: false }
+  }
+  const from = object(message, "from")
+  const fromId = integer(from, "id")
+  if (from === undefined || fromId === undefined) return undefined
+  const name = displayName(from)
+  return {
+    id: String(fromId),
+    ...(name === undefined ? {} : { name }),
+    isBot: from.is_bot === true,
+    isSelf: String(fromId) === context.botId
+  }
+}
+
+const mentionsOf = (text: string, entities: ReadonlyArray, context: Context) => {
+  const mentions: Array = []
+  const self = context.botUsername?.toLowerCase()
+  for (const entity of entities) {
+    if (!isObject(entity)) continue
+    const start = integer(entity, "offset")
+    const length = integer(entity, "length")
+    if (start === undefined || length === undefined || start < 0 || start + length > text.length) continue
+    const end = start + length
+    if (entity.type === "text_mention") {
+      const user = integer(object(entity, "user"), "id")
+      if (user !== undefined) {
+        mentions.push({ kind: "user", id: String(user), start, end, isSelf: String(user) === context.botId })
+      }
+    } else if (entity.type === "mention" && self !== undefined && text.slice(start + 1, end).toLowerCase() === self) {
+      mentions.push({ kind: "user", id: context.botId, start, end, isSelf: true })
+    }
+  }
+  return mentions
+}
+
+const attachmentsOf = (message: JsonObject): Array => {
+  const out: Array = []
+  const add = (file: JsonObject | undefined) => {
+    const id = string(file, "file_id")
+    if (id === undefined) return
+    const name = string(file, "file_name")
+    const contentType = string(file, "mime_type")
+    const size = integer(file, "file_size")
+    out.push({
+      id,
+      ...(name === undefined ? {} : { name }),
+      ...(contentType === undefined ? {} : { contentType }),
+      ...(size === undefined ? {} : { size })
+    })
+  }
+  for (const key of ["document", "audio", "video", "voice", "animation"]) add(object(message, key))
+  const photo = message.photo
+  if (Array.isArray(photo) && photo.length > 0) {
+    let largest: JsonObject | undefined
+    for (const size of photo) {
+      if (!isObject(size)) continue
+      const area = (integer(size, "width") ?? 0) * (integer(size, "height") ?? 0)
+      const best = (integer(largest, "width") ?? 0) * (integer(largest, "height") ?? 0)
+      if (largest === undefined || area > best) largest = size
+    }
+    add(largest)
+  }
+  return out
+}
+
+const replyToOf = (message: JsonObject, context: Context): ChatMessage.ReplyTo | undefined => {
+  const reply = object(message, "reply_to_message")
+  const id = integer(reply, "message_id")
+  if (reply === undefined || id === undefined || id === 0) return undefined
+  // A message in a topic replies to the topic's creation message, which is not a reply.
+  if (
+    message.is_topic_message === true &&
+    (id === integer(message, "message_thread_id") || "forum_topic_created" in reply)
+  ) {
+    return undefined
+  }
+  const author = integer(object(reply, "from"), "id")
+  return author === undefined
+    ? { messageId: String(id) }
+    : { messageId: String(id), authorId: String(author), isSelf: String(author) === context.botId }
+}
+
+/** The message of an update that carries one: `message` or `channel_post`. @internal */
+export const messageOf = (update: JsonObject): JsonObject | undefined =>
+  object(update, "message") ?? object(update, "channel_post")
+
+/** The text of a message, verbatim, and its entities. @internal */
+export const textOf = (
+  message: JsonObject
+): { readonly text: string; readonly entities: ReadonlyArray } => {
+  const text = string(message, "text")
+  if (text !== undefined) return { text, entities: Array.isArray(message.entities) ? message.entities : [] }
+  const caption = string(message, "caption") ?? ""
+  return { text: caption, entities: Array.isArray(message.caption_entities) ? message.caption_entities : [] }
+}
+
+/**
+ * The `MessageCreated` of an update's message, or undefined for one that
+ * gives none: an excluded context, a private (ephemeral) message, a message
+ * with no id, and a service message, with no text, caption, file or rich
+ * content. `invalid` is a message that should give one and can't be read.
+ *
+ * @internal
+ */
+export const messageCreated = (
+  update: JsonObject,
+  context: Context
+): ChatEvent.MessageCreated | "none" | "invalid" => {
+  const message = messageOf(update)
+  if (message === undefined || isExcluded(message) || integer(message, "message_id") === 0) return "none"
+  const { entities, text } = textOf(message)
+  const attachments = attachmentsOf(message)
+  if (text === "" && attachments.length === 0 && !("rich_message" in message)) return "none"
+  const at = threadOf(message)
+  const id = messageIdOf(message)
+  const author = authorOf(message, context)
+  const date = integer(message, "date")
+  if (at === undefined || id === undefined || author === undefined || date === undefined) return "invalid"
+  const replyTo = replyToOf(message, context)
+  return ChatEvent.MessageCreated.make({
+    thread: at.thread,
+    kind: at.kind,
+    message: {
+      id,
+      thread: at.thread,
+      author,
+      text,
+      mentions: mentionsOf(text, entities, context),
+      ...(replyTo === undefined ? {} : { replyTo }),
+      attachments,
+      timestamp: DateTime.makeUnsafe(date * 1000),
+      raw: message
+    },
+    raw: update
+  })
+}
+
+/** A command typed as a message: its lowercased name and what follows it. @internal */
+export interface Command {
+  readonly id: string
+  readonly text: string
+}
+
+/**
+ * The command a message holds: its first entity is a `bot_command` at
+ * offset 0, naming this bot or no bot. `undefined` when a command names a
+ * bot and the bot's username is not known.
+ *
+ * @internal
+ */
+export const commandOf = (message: JsonObject, context: Context): Command | undefined => {
+  const { entities, text } = textOf(message)
+  const first = entities[0]
+  if (!isObject(first) || first.type !== "bot_command" || integer(first, "offset") !== 0) return undefined
+  const length = integer(first, "length")
+  if (length === undefined || length < 2 || length > text.length) return undefined
+  // The entity's length is Telegram's: it never covers a `-`, which `commandRequests` refuses.
+  const match = /^\/([A-Za-z0-9_-]{1,32})(?:@([A-Za-z0-9_]+))?$/.exec(text.slice(0, length))
+  if (match === null) return undefined
+  if (match[2] !== undefined && match[2].toLowerCase() !== context.botUsername?.toLowerCase()) return undefined
+  let rest = text.slice(length)
+  if (rest.startsWith(" ") || rest.startsWith("\n")) rest = rest.slice(1)
+  return { id: match[1].toLowerCase(), text: rest }
+}
+
+/** The date of an update's message or callback message, 0 when there is none. */
+const dateOf = (update: JsonObject): number =>
+  integer(messageOf(update), "date") ?? integer(object(object(update, "callback_query"), "message"), "date") ?? 0
+
+/**
+ * The delivery id of an update: `{botId}.{update_id}.{date}`, with `test.`
+ * in front in the test environment.
+ *
+ * @internal
+ */
+export const deliveryId = (update: unknown, context: Pick): string | undefined => {
+  if (!isObject(update)) return undefined
+  const id = integer(update, "update_id")
+  if (id === undefined) return undefined
+  return `${context.environment === "test" ? "test." : ""}${context.botId}.${id}.${dateOf(update)}`
+}
+
+/** The events of an update, as `TelegramChat.normalize` gives them. @internal */
+export const normalize = (update: unknown, context: Context): ReadonlyArray => {
+  if (!isObject(update)) return []
+  const event = messageCreated(update, context)
+  return typeof event === "string" ? [] : [event]
+}
diff --git a/packages/chat/telegram/src/internal/options.ts b/packages/chat/telegram/src/internal/options.ts
new file mode 100644
index 00000000000..e25ba08f048
--- /dev/null
+++ b/packages/chat/telegram/src/internal/options.ts
@@ -0,0 +1,12 @@
+import * as Context from "effect/Context"
+
+/** @internal */
+export interface PostOptions {
+  readonly notify?: { readonly users?: ReadonlyArray | undefined } | undefined
+  readonly silent?: boolean | undefined
+}
+
+/** @internal */
+export const CurrentPostOptions = Context.Reference("@effect/chat-telegram/CurrentPostOptions", {
+  defaultValue: () => ({})
+})
diff --git a/packages/chat/telegram/src/internal/polling.ts b/packages/chat/telegram/src/internal/polling.ts
new file mode 100644
index 00000000000..73a7631ad57
--- /dev/null
+++ b/packages/chat/telegram/src/internal/polling.ts
@@ -0,0 +1,86 @@
+import type { ChatError } from "effect/chat/ChatError"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import type { TelegramBotApi } from "../TelegramBotApi.ts"
+import * as Errors from "./errors.ts"
+import { integer, isObject } from "./normalize.ts"
+import { allowedUpdates, type Outcome } from "./receive.ts"
+
+/** @internal */
+export interface Options {
+  readonly api: TelegramBotApi["Service"]
+  readonly timeout: Duration.Duration
+  readonly maxAttempts: number
+  readonly receive: (update: unknown) => Effect.Effect
+}
+
+const isConflict = (error: ChatError) => error.reason._tag === "InvalidRequest" && error.reason.detail === "conflict"
+
+/** One `getUpdates`, from `offset`. @internal */
+export const getUpdates = (api: TelegramBotApi["Service"], offset: number | undefined, timeout: Duration.Duration) =>
+  api.call("getUpdates", {
+    ...(offset === undefined ? {} : { offset }),
+    timeout: Math.floor(Duration.toSeconds(timeout)),
+    allowed_updates: allowedUpdates
+  }).pipe(Effect.map((result) => Array.isArray(result) ? result : []))
+
+/**
+ * Runs one update, retrying `notAccepted` and `invalid` up to
+ * `maxAttempts` times with a backoff from one second. Then it is logged
+ * and skipped: `getUpdates` is one ordered queue, and retrying forever
+ * would stall every chat.
+ *
+ * @internal
+ */
+export const runUpdate = (update: unknown, options: Options): Effect.Effect =>
+  Effect.gen(function*() {
+    for (let attempt = 1;; attempt++) {
+      const outcome = yield* options.receive(update)
+      if (outcome === "accepted" || outcome === "unhandled") return
+      if (attempt >= options.maxAttempts) {
+        return yield* Effect.logError("telegram polling: an update was not accepted, skipped").pipe(
+          Effect.annotateLogs({ "telegram.update_id": isObject(update) ? integer(update, "update_id") : undefined })
+        )
+      }
+      yield* Effect.sleep(Duration.seconds(2 ** (attempt - 1)))
+    }
+  })
+
+/**
+ * The polling loop. `first` is the answer of the call the layer made
+ * itself. Each update's offset is confirmed by the next call only once the
+ * update was run, so a process that dies part way sees it again.
+ *
+ * @internal
+ */
+export const loop = (first: ReadonlyArray, options: Options): Effect.Effect =>
+  Effect.gen(function*() {
+    let batch = first
+    let offset: number | undefined
+    for (;;) {
+      for (const update of batch) {
+        yield* runUpdate(update, options)
+        const id = isObject(update) ? integer(update, "update_id") : undefined
+        if (id !== undefined) offset = id + 1
+      }
+      const next = yield* Effect.result(getUpdates(options.api, offset, options.timeout))
+      if (next._tag === "Success") {
+        batch = next.success
+        continue
+      }
+      batch = []
+      if (isConflict(next.failure)) {
+        return yield* Effect.logError(
+          "telegram polling: getUpdates answered 409, another poller or a webhook is active; polling stopped"
+        )
+      }
+      yield* Effect.logWarning("telegram polling: getUpdates failed, retrying").pipe(
+        Effect.annotateLogs({ "chat.error.reason": next.failure.reason._tag })
+      )
+      yield* Effect.sleep(Duration.seconds(5))
+    }
+  })
+
+/** The error the layer fails with on a 409 at start. @internal */
+export const conflict = (error: ChatError): ChatError =>
+  isConflict(error) ? Errors.chatError("layerPolling", Errors.invalidRequest("conflict")) : error
diff --git a/packages/chat/telegram/src/internal/receive.ts b/packages/chat/telegram/src/internal/receive.ts
new file mode 100644
index 00000000000..67e371037ea
--- /dev/null
+++ b/packages/chat/telegram/src/internal/receive.ts
@@ -0,0 +1,272 @@
+import type { Capability, ChatError } from "effect/chat/ChatError"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import type { NotAccepted } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as Duration from "effect/Duration"
+import * as Effect from "effect/Effect"
+import * as Option from "effect/Option"
+import * as Schema from "effect/Schema"
+import type { TelegramBotApi } from "../TelegramBotApi.ts"
+import * as Actions from "./actions.ts"
+import type { Made } from "./adapter.ts"
+import { originOf } from "./adapter.ts"
+import * as Errors from "./errors.ts"
+import {
+  commandOf,
+  type Context,
+  integer,
+  isEphemeral,
+  isExcluded,
+  isObject,
+  type JsonObject,
+  messageCreated,
+  messageIdOf,
+  messageOf,
+  object,
+  string,
+  threadOf
+} from "./normalize.ts"
+
+/**
+ * What became of one update.
+ *
+ * - `accepted`: its event was accepted, or its interaction was answered.
+ * - `unhandled`: it gave nothing, and went to `onUnhandled`.
+ * - `notAccepted`: the `ChatHandler` refused its event, or it passed the deadline.
+ * - `invalid`: it should give an event and could not be read.
+ *
+ * @internal
+ */
+export type Outcome = "accepted" | "unhandled" | "notAccepted" | "invalid"
+
+/** @internal */
+export const defaults = {
+  deadline: Duration.seconds(10),
+  clickDeadline: Duration.millis(2500),
+  commandDeadline: Duration.seconds(10)
+} as const
+
+/** The update types the adapter reads, for `allowed_updates`. @internal */
+export const allowedUpdates = ["message", "channel_post", "callback_query"] as const
+
+/** @internal */
+export interface Options {
+  readonly onUnhandled?: ((update: Schema.Json) => Effect.Effect) | undefined
+  readonly deadline?: Duration.Input | undefined
+  readonly clickDeadline?: Duration.Input | undefined
+  readonly commandDeadline?: Duration.Input | undefined
+}
+
+/** @internal */
+export interface Environment {
+  readonly api: TelegramBotApi["Service"]
+  readonly capabilities: ReadonlySet
+  readonly answer: Made["answer"]
+  /** The bot's username, read once from `getMe`. */
+  readonly username: Effect.Effect
+}
+
+const isLate = Schema.is(ChatInteraction.Late)
+
+const duration = (input: Duration.Input | undefined, fallback: Duration.Duration) =>
+  input === undefined ? fallback : Duration.fromInputUnsafe(input)
+
+const refused = (
+  handler: ChatInteraction.Handler["Service"],
+  event: ChatInteraction.ButtonClicked | ChatInteraction.CommandInvoked,
+  error: ChatError
+) => handler.refused(event, error)
+
+const answerQuery = (api: TelegramBotApi["Service"], id: string) =>
+  api.call("answerCallbackQuery", { callback_query_id: id }, { write: true, retry: false }).pipe(
+    Effect.catch((error) =>
+      Effect.logWarning("telegram: answerCallbackQuery failed").pipe(
+        Effect.annotateLogs({ "chat.error.reason": error.reason._tag })
+      )
+    )
+  )
+
+/** A callback the adapter leaves alone: inline mode, a game, or an excluded context. */
+const isForeignCallback = (query: JsonObject): boolean => {
+  const message = object(query, "message")
+  return message === undefined || typeof query.data !== "string" || isExcluded(message)
+}
+
+/**
+ * The click of a `callback_query`, only when its `data` is the
+ * `callback_data` of a button in Telegram's own copy of the message:
+ * `data` comes from the client and can be anything. Undefined for an
+ * inaccessible message, a message with no keyboard, or a mismatch.
+ *
+ * @internal
+ */
+export const clickEvent = (update: JsonObject): ChatInteraction.ButtonClicked | undefined => {
+  const query = object(update, "callback_query")
+  const message = object(query, "message")
+  const data = string(query, "data")
+  if (query === undefined || message === undefined || data === undefined || isForeignCallback(query)) return undefined
+  const user = integer(object(query, "from"), "id")
+  const at = threadOf(message)
+  const messageId = messageIdOf(message)
+  if (
+    integer(message, "date") === 0 || !Actions.keyboardData(message.reply_markup).has(data) ||
+    user === undefined || at === undefined || messageId === undefined
+  ) return undefined
+  const parsed = Actions.parseData(data)
+  return ChatInteraction.ButtonClicked.make({
+    id: parsed.id,
+    ...(parsed.value === undefined ? {} : { value: parsed.value }),
+    thread: at.thread,
+    messageId,
+    userId: String(user),
+    raw: update
+  })
+}
+
+/** A click. Every click is answered, since the client shows a progress bar until it is. */
+const click = (
+  update: JsonObject,
+  id: string,
+  env: Environment,
+  options: Options,
+  handler: Option.Option
+): Effect.Effect =>
+  Effect.gen(function*() {
+    const answer = answerQuery(env.api, id)
+    if (Option.isNone(handler) || !env.capabilities.has("buttons")) return yield* answer
+    const event = clickEvent(update)
+    if (event === undefined) {
+      yield* Effect.logWarning("telegram: a click matched no button on its message, answered and dropped").pipe(
+        Effect.annotateLogs({ "chat.interaction.reason": "InvalidValue" })
+      )
+      return yield* answer
+    }
+    const reply = yield* Effect.provideService(
+      ChatInteraction.handle(event, duration(options.clickDeadline, defaults.clickDeadline)),
+      ChatInteraction.Handler,
+      handler.value
+    )
+    yield* answer
+    if (!isLate(reply) && reply._tag === "OpenModal") {
+      yield* refused(handler.value, event, Errors.chatError("openModal", Errors.unsupported("modals")))
+    }
+  })
+
+/** The command of a message update, for this bot. @internal */
+export const commandEvent = (update: JsonObject, context: Context): ChatInteraction.CommandInvoked | undefined => {
+  const message = messageOf(update)
+  if (message === undefined || isExcluded(message)) return undefined
+  const found = commandOf(message, context)
+  const at = threadOf(message)
+  const user = integer(object(message, "from"), "id") ?? integer(object(message, "sender_chat"), "id")
+  if (found === undefined || at === undefined || user === undefined) return undefined
+  return ChatInteraction.CommandInvoked.make({
+    id: found.id,
+    text: found.text,
+    thread: at.thread,
+    userId: String(user),
+    raw: update
+  })
+}
+
+/**
+ * A command. `false` when it was not handled: no handler, no
+ * `commands`, or an `Ack`, which means no definition matched.
+ */
+const command = (
+  event: ChatInteraction.CommandInvoked,
+  env: Environment,
+  options: Options,
+  handler: Option.Option
+): Effect.Effect =>
+  Effect.gen(function*() {
+    if (Option.isNone(handler) || !env.capabilities.has("commands")) return false
+    const reply = yield* Effect.provideService(
+      ChatInteraction.handle(event, duration(options.commandDeadline, defaults.commandDeadline)),
+      ChatInteraction.Handler,
+      handler.value
+    )
+    if (isLate(reply)) return true
+    switch (reply._tag) {
+      case "Ack":
+        return false
+      case "Defer":
+        return true
+      case "OpenModal":
+        yield* refused(handler.value, event, Errors.chatError("openModal", Errors.unsupported("modals")))
+        return true
+      case "Respond": {
+        // No `ephemeral` in this version: a private answer is refused, never posted.
+        if (reply.visibility === "ephemeral") {
+          yield* refused(handler.value, event, Errors.chatError("respond", Errors.unsupported("ephemeral")))
+          return true
+        }
+        const origin = originOf(event)
+        if (origin === undefined) return true
+        yield* env.answer("respond", origin, {
+          markdown: reply.markdown,
+          ...(reply.actions === undefined ? {} : { actions: reply.actions })
+        }).pipe(Effect.catch((error) => refused(handler.value, event, error)))
+        return true
+      }
+    }
+  })
+
+/**
+ * One update, as both transports run it.
+ *
+ * - A click goes to `ChatInteraction.Handler` and is answered.
+ * - An ephemeral message only ever takes the command path. Whatever its
+ *   answer, it never reaches `ChatHandler` or `onUnhandled`.
+ * - A command goes to `ChatInteraction.Handler`. One answered `Ack`
+ *   continues as an ordinary message.
+ * - A message with content becomes `MessageCreated` for `ChatHandler`,
+ *   within `deadline`.
+ * - Anything else, including the excluded contexts, goes to `onUnhandled`.
+ *
+ * @internal
+ */
+export const receive = (
+  update: unknown,
+  env: Environment,
+  options: Options,
+  handle: (event: ChatEvent.ChatEvent) => Effect.Effect
+): Effect.Effect =>
+  Effect.gen(function*() {
+    if (!isObject(update) || integer(update, "update_id") === undefined) return "invalid"
+    const unhandled = Effect.as(options.onUnhandled?.(update) ?? Effect.void, "unhandled" as const)
+    const handler = yield* Effect.serviceOption(ChatInteraction.Handler)
+    const query = object(update, "callback_query")
+    if (query !== undefined) {
+      if (isForeignCallback(query)) {
+        // A business chat's button is answered, so its client stops waiting, but never dispatched.
+        const id = string(query, "id")
+        const message = object(query, "message")
+        if (id !== undefined && message !== undefined && isExcluded(message)) yield* answerQuery(env.api, id)
+        return yield* unhandled
+      }
+      const id = string(query, "id")
+      if (id === undefined) return "invalid"
+      return yield* Effect.as(click(update, id, env, options, handler), "accepted" as const)
+    }
+    const message = messageOf(update)
+    if (message === undefined || isExcluded(message)) return yield* unhandled
+    const username = yield* Effect.option(env.username)
+    if (Option.isNone(username)) return "invalid"
+    const context: Context = { botId: env.api.botId, botUsername: username.value, environment: env.api.environment }
+    const found = commandEvent(update, context)
+    if (isEphemeral(message)) {
+      if (found !== undefined) yield* command(found, env, options, handler)
+      return "accepted"
+    }
+    if (integer(message, "message_id") === 0) return yield* unhandled
+    if (found !== undefined && (yield* command(found, env, options, handler))) return "accepted"
+    const event = messageCreated(update, context)
+    if (event === "none") return yield* unhandled
+    if (event === "invalid") return "invalid"
+    return yield* handle(event).pipe(
+      Effect.timeoutOption(duration(options.deadline, defaults.deadline)),
+      Effect.map(Option.match({ onNone: () => "notAccepted" as const, onSome: () => "accepted" as const })),
+      Effect.catchTag("NotAccepted", () => Effect.succeed("notAccepted" as const))
+    )
+  })
diff --git a/packages/chat/telegram/src/internal/webhook.ts b/packages/chat/telegram/src/internal/webhook.ts
new file mode 100644
index 00000000000..a34f9c77730
--- /dev/null
+++ b/packages/chat/telegram/src/internal/webhook.ts
@@ -0,0 +1,101 @@
+import { timingSafeEqual } from "effect/crypto/Mac"
+import * as Effect from "effect/Effect"
+import type * as HttpServerRequest from "effect/http/HttpServerRequest"
+import * as HttpServerResponse from "effect/http/HttpServerResponse"
+import * as Option from "effect/Option"
+import * as Stream from "effect/Stream"
+import type { Outcome } from "./receive.ts"
+
+/** The header Telegram sends the webhook secret in. @internal */
+export const secretHeader = "x-telegram-bot-api-secret-token"
+
+/** Telegram's rule for a secret, with the adapter's floor of 32 characters. @internal */
+export const validSecret = (secret: string): boolean => /^[A-Za-z0-9_-]{32,256}$/.test(secret)
+
+const encoder = new TextEncoder()
+
+/** Whether a header holds the secret, compared in constant time. @internal */
+export const checkSecret = (header: string | undefined, secret: Uint8Array): boolean =>
+  header !== undefined && timingSafeEqual(encoder.encode(header), secret)
+
+/** The body, or `None` once it passes `maxBytes`. @internal */
+export const readBody = (
+  request: HttpServerRequest.HttpServerRequest,
+  maxBytes: number
+): Effect.Effect> => {
+  const length = request.headers["content-length"]
+  if (length !== undefined && Number(length) > maxBytes) return Effect.succeed(Option.none())
+  return Effect.gen(function*() {
+    const chunks: Array = []
+    let total = 0
+    const failed = yield* request.stream.pipe(
+      Stream.takeUntil((chunk) => {
+        total += chunk.length
+        chunks.push(chunk)
+        return total > maxBytes
+      }),
+      Stream.runDrain,
+      Effect.as(false),
+      Effect.catch(() => Effect.succeed(true))
+    )
+    if (failed || total > maxBytes) return Option.none()
+    const body = new Uint8Array(total)
+    let offset = 0
+    for (const chunk of chunks) {
+      body.set(chunk, offset)
+      offset += chunk.length
+    }
+    return Option.some(body)
+  })
+}
+
+const status = (code: number) => HttpServerResponse.empty({ status: code })
+
+/** What is logged with each 503. @internal */
+export const unavailable = {
+  invalid: "telegram webhook: the update could not be read, answered 503",
+  notAccepted: "telegram webhook: the handler refused the event or passed the deadline, answered 503"
+} as const
+
+/**
+ * One webhook request.
+ *
+ * - 401 without the secret, before the body is read. 413 past
+ *   `maxBodyBytes`, 400 for a body that is not an update.
+ * - 200 once the update was accepted, answered or sent to `onUnhandled`.
+ * - 503 when its event was not accepted in time, or could not be read.
+ *
+ * @internal
+ */
+export const handleRequest = (
+  request: HttpServerRequest.HttpServerRequest,
+  options: {
+    readonly secret: Uint8Array
+    readonly maxBodyBytes: number
+    readonly receive: (update: unknown) => Effect.Effect
+  }
+): Effect.Effect =>
+  Effect.gen(function*() {
+    if (!checkSecret(request.headers[secretHeader], options.secret)) return status(401)
+    const body = yield* readBody(request, options.maxBodyBytes)
+    if (Option.isNone(body)) return status(413)
+    let update: unknown
+    try {
+      update = JSON.parse(new TextDecoder().decode(body.value))
+    } catch {
+      return status(400)
+    }
+    if (typeof update !== "object" || update === null || typeof (update as any).update_id !== "number") {
+      return status(400)
+    }
+    const outcome = yield* options.receive(update)
+    switch (outcome) {
+      case "accepted":
+      case "unhandled":
+        return status(200)
+      case "invalid":
+        return yield* Effect.as(Effect.logWarning(unavailable.invalid), status(503))
+      case "notAccepted":
+        return yield* Effect.as(Effect.logWarning(unavailable.notAccepted), status(503))
+    }
+  })
diff --git a/packages/chat/telegram/test/TelegramChat.test.ts b/packages/chat/telegram/test/TelegramChat.test.ts
new file mode 100644
index 00000000000..4411ae3bc93
--- /dev/null
+++ b/packages/chat/telegram/test/TelegramChat.test.ts
@@ -0,0 +1,348 @@
+/**
+ * The adapter's own guarantees, over a fake Bot API: the token stays out of
+ * errors, spans and logs (T1), the webhook secret (T2), private answers
+ * (T5), clicks (T6), excluded contexts (T7) and acceptance (T8).
+ */
+import * as TelegramChat from "@effect/chat-telegram/TelegramChat"
+import { assert, describe, it } from "@effect/vitest"
+import * as Cause from "effect/Cause"
+import * as Chat from "effect/chat/Chat"
+import type { ChatError } from "effect/chat/ChatError"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
+import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as Effect from "effect/Effect"
+import * as Exit from "effect/Exit"
+import * as HttpRouter from "effect/http/HttpRouter"
+import * as Layer from "effect/Layer"
+import * as Logger from "effect/Logger"
+import * as Option from "effect/Option"
+import * as Redacted from "effect/Redacted"
+import type * as Schema from "effect/Schema"
+import * as Tracer from "effect/Tracer"
+import {
+  apiError,
+  botId,
+  callbackUpdate,
+  chatId,
+  commandUpdate,
+  context,
+  type FakeApi,
+  makeApi,
+  messageUpdate,
+  telegramLayer,
+  thread,
+  token,
+  unverified
+} from "./utils.ts"
+
+const secret = "s".repeat(32)
+
+/** What reached the consumer, by kind. */
+const makeRecorder = (options?: {
+  readonly command?: (event: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply
+  readonly refuse?: boolean
+}) => {
+  const events: Array = []
+  const clicks: Array = []
+  const commands: Array = []
+  const refused: Array = []
+  const unhandled: Array = []
+  const handler = ChatHandler.of({
+    handle: (event) =>
+      options?.refuse === true ? Effect.fail(new NotAccepted({})) : Effect.sync(() => void events.push(event))
+  })
+  const interactions = ChatInteraction.Handler.of({
+    click: (event) => Effect.sync(() => (clicks.push(event), ChatInteraction.ack)),
+    submit: () => Effect.succeed(ChatInteraction.close),
+    command: (event) => Effect.sync(() => (commands.push(event), options?.command?.(event) ?? ChatInteraction.ack)),
+    refused: (_, error) => Effect.sync(() => void refused.push(error))
+  })
+  const onUnhandled = (update: Schema.Json) => Effect.sync(() => void unhandled.push(update))
+  return { events, clicks, commands, refused, unhandled, handler, interactions, onUnhandled }
+}
+
+type Recorder = ReturnType
+
+/** Runs updates through `TelegramChat.receive`, as the transports do. */
+const receive = (api: FakeApi, recorder: Recorder, ...updates: ReadonlyArray) =>
+  Effect.gen(function*() {
+    const telegram = yield* TelegramChat.TelegramChat
+    const outcomes: Array = []
+    for (const update of updates) {
+      outcomes.push(yield* telegram.receive(update, { onUnhandled: recorder.onUnhandled }))
+    }
+    return outcomes
+  }).pipe(
+    Effect.provideService(ChatHandler, recorder.handler),
+    Effect.provideService(ChatInteraction.Handler, recorder.interactions),
+    Effect.provide(telegramLayer(api))
+  )
+
+/** An ephemeral command: message id 0, with its own private id. */
+const ephemeralCommand = (name: string, ephemeralId: number) =>
+  commandUpdate(name, "", { message_id: 0, ephemeral_message_id: ephemeralId })
+
+describe("credentials", () => {
+  it.effect("keeps the token out of errors, spans and logs", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const spans: Array = []
+      const logs: Array = []
+      const tracer = Tracer.make({
+        span(options) {
+          const span = new Tracer.NativeSpan(options)
+          spans.push(span)
+          return span
+        }
+      })
+      const logger = Logger.formatJson.pipe(Logger.map((line): void => void logs.push(line)))
+      api.next.set("sendRichMessage", apiError(401, "Unauthorized"))
+      const exit = yield* Effect.flatMap(Chat.Chat, (chat) => chat.post(thread, { markdown: "hi" })).pipe(
+        Effect.tapCause((cause) => Effect.logError("post failed", cause)),
+        Effect.exit,
+        Effect.provide(telegramLayer(api)),
+        Effect.provide(Logger.layer([logger])),
+        Effect.provideService(Tracer.Tracer, tracer)
+      )
+      assert.isTrue(Exit.isFailure(exit))
+      const seen = [
+        Exit.isFailure(exit) ? Cause.pretty(exit.cause) : "",
+        JSON.stringify(exit),
+        ...logs,
+        ...spans.map((span) => JSON.stringify([span.name, [...span.attributes], span.events]))
+      ].join("\n")
+      assert.isTrue(spans.some((span) => span.name === "TelegramBotApi.sendRichMessage"))
+      assert.isTrue(seen.includes("/bot/sendRichMessage"))
+      assert.isFalse(seen.includes(token))
+      assert.isFalse(seen.includes(token.split(":")[1]))
+    }))
+
+  it.effect("refuses a token without a bot id", () =>
+    Effect.gen(function*() {
+      const exit = yield* Layer.build(
+        TelegramChat.layer({ token: Redacted.make("not-a-token") }).pipe(
+          Layer.provide(Chat.layer),
+          Layer.provide(makeApi().layer)
+        )
+      ).pipe(Effect.scoped, Effect.exit)
+      assert.isTrue(Exit.isFailure(exit))
+      assert.isFalse(JSON.stringify(exit).includes("not-a-token"))
+    }))
+})
+
+const webhook = Effect.fnUntraced(function*(api: FakeApi, recorder: Recorder) {
+  const app = TelegramChat.layerWebhook({
+    path: "/telegram",
+    secretToken: Redacted.make(secret),
+    maxBodyBytes: 4096,
+    onUnhandled: recorder.onUnhandled
+  }).pipe(
+    Layer.provide(telegramLayer(api)),
+    Layer.provide(Layer.succeed(ChatHandler, recorder.handler))
+  )
+  const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true })
+  yield* Effect.addFinalizer(() => Effect.promise(() => dispose()))
+  return (body: string, header?: string) =>
+    Effect.promise(() =>
+      handler(
+        new Request("http://localhost/telegram", {
+          method: "POST",
+          body,
+          headers: {
+            "content-type": "application/json",
+            ...(header === undefined ? {} : { [TelegramChat.secretHeader]: header })
+          }
+        })
+      )
+    ).pipe(Effect.map((response) => response.status))
+})
+
+describe("layerWebhook", () => {
+  it.effect("needs the secret, then answers for the body and the outcome", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recorder = makeRecorder()
+      const send = yield* webhook(api, recorder)
+      const body = JSON.stringify(messageUpdate({ text: "hi" }))
+      assert.strictEqual(yield* send(body), 401)
+      assert.strictEqual(yield* send(body, "s".repeat(31)), 401)
+      assert.strictEqual(yield* send(body, "t".repeat(32)), 401)
+      assert.strictEqual(recorder.events.length, 0)
+      assert.strictEqual(yield* send("x".repeat(5000), secret), 413)
+      assert.strictEqual(yield* send("{", secret), 400)
+      assert.strictEqual(yield* send(JSON.stringify({ message: {} }), secret), 400)
+      assert.strictEqual(yield* send(body, secret), 200)
+      assert.strictEqual(recorder.events.length, 1)
+      assert.strictEqual(yield* send(JSON.stringify({ update_id: 1, poll: {} }), secret), 200)
+      assert.strictEqual(recorder.unhandled.length, 1)
+    }))
+
+  it.effect("answers 503 when the handler does not accept", () =>
+    Effect.gen(function*() {
+      const send = yield* webhook(makeApi(), makeRecorder({ refuse: true }))
+      assert.strictEqual(yield* send(JSON.stringify(messageUpdate({ text: "hi" })), secret), 503)
+    }))
+
+  it.effect("refuses a short secret", () =>
+    Effect.gen(function*() {
+      const app = TelegramChat.layerWebhook({ path: "/telegram", secretToken: Redacted.make("short") }).pipe(
+        Layer.provide(telegramLayer(makeApi())),
+        Layer.provide(Layer.succeed(ChatHandler, makeRecorder().handler)),
+        Layer.provide(HttpRouter.layer)
+      )
+      const exit = yield* Layer.build(app).pipe(Effect.scoped, Effect.exit)
+      assert.isTrue(Exit.isFailure(exit))
+    }))
+})
+
+describe("private answers", () => {
+  it.effect("refuses an ephemeral answer and never posts it", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recorder = makeRecorder({ command: () => ChatInteraction.respond({ markdown: "secret" }) })
+      const outcomes = yield* receive(api, recorder, commandUpdate("deploy"), ephemeralCommand("deploy", 7))
+      assert.deepStrictEqual(outcomes, ["accepted", "accepted"])
+      assert.strictEqual(recorder.commands.length, 2)
+      assert.deepStrictEqual(recorder.refused.map((error) => error.reason._tag), ["Unsupported", "Unsupported"])
+      assert.strictEqual(api.sent("sendRichMessage").length, 0)
+      assert.strictEqual(recorder.events.length + recorder.unhandled.length, 0)
+    }))
+
+  it.effect("answers an ephemeral command in public without quoting it", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recorder = makeRecorder({
+        command: () => ChatInteraction.respond({ markdown: "done", visibility: "public" })
+      })
+      yield* receive(api, recorder, commandUpdate("deploy"), ephemeralCommand("deploy", 7))
+      const [quoted, unquoted] = api.sent("sendRichMessage")
+      assert.isDefined(quoted.reply_parameters)
+      assert.isUndefined(unquoted.reply_parameters)
+      assert.strictEqual(unquoted.chat_id, chatId)
+    }))
+
+  it.effect("keeps an ephemeral message that is not a command from every handler", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recorder = makeRecorder()
+      yield* receive(api, recorder, messageUpdate({ text: "psst", message_id: 0, ephemeral_message_id: 9 }))
+      assert.strictEqual(recorder.events.length + recorder.unhandled.length + recorder.commands.length, 0)
+    }))
+})
+
+describe("clicks", () => {
+  const keyboard = { inline_keyboard: [[{ text: "Yes", callback_data: "approve" }]] }
+  const message = (extra?: Record) => ({
+    message_id: 5,
+    date: 1_800_000_000,
+    chat: { id: chatId, type: "supergroup" },
+    text: "x",
+    reply_markup: keyboard,
+    ...extra
+  })
+
+  it.effect("dispatches only data from Telegram's copy of the keyboard, and answers every click", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recorder = makeRecorder()
+      yield* receive(
+        api,
+        recorder,
+        callbackUpdate(message(), "approve"),
+        callbackUpdate(message(), "forged"),
+        callbackUpdate(message({ reply_markup: undefined }), "approve"),
+        callbackUpdate(message({ date: 0 }), "approve")
+      )
+      assert.deepStrictEqual(recorder.clicks.map((click) => [click.id, click.messageId]), [["approve", "5"]])
+      assert.strictEqual(api.sent("answerCallbackQuery").length, 4)
+    }))
+})
+
+describe("excluded contexts", () => {
+  it.effect("sends business, channel direct-message and guest updates to onUnhandled", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recorder = makeRecorder()
+      const business = { message_id: 3, date: 1, chat: { id: 1, type: "private" }, business_connection_id: "b" }
+      yield* receive(
+        api,
+        recorder,
+        { update_id: 1, business_message: { ...business, text: "hi" } },
+        messageUpdate({ text: "hi", business_connection_id: "b" }),
+        messageUpdate({ text: "hi", chat: { id: chatId, type: "supergroup", is_direct_messages: true } }),
+        messageUpdate({ text: "hi", direct_messages_topic: { topic_id: 1 } }),
+        commandUpdate("deploy", "", { business_connection_id: "b" }),
+        callbackUpdate({ ...business, reply_markup: { inline_keyboard: [[{ text: "a", callback_data: "a" }]] } }, "a"),
+        { update_id: 2, message_reaction: { chat: { id: chatId, type: "supergroup" }, message_id: 1 } }
+      )
+      assert.strictEqual(recorder.unhandled.length, 7)
+      assert.strictEqual(recorder.events.length + recorder.commands.length + recorder.clicks.length, 0)
+      assert.strictEqual(api.sent("answerCallbackQuery").length, 1)
+    }))
+
+  it("gives no event from the normaliser", () => {
+    const update = messageUpdate({ text: "hi", business_connection_id: "b" })
+    assert.deepStrictEqual(TelegramChat.normalize(update, context), [])
+  })
+})
+
+describe("acceptance", () => {
+  it("keys deliveries by bot, update and date, and keeps ephemeral commands apart", () => {
+    const first = ephemeralCommand("deploy", 7)
+    const second = ephemeralCommand("deploy", 8)
+    const key = (raw: unknown) => Option.getOrThrow(TelegramChat.deliveryKey(raw, { botId }))
+    assert.strictEqual(key(first), `${botId}.${first.update_id}.${first.message.date}`)
+    assert.strictEqual(key(structuredClone(first)), key(first))
+    assert.notStrictEqual(key(first), key(second))
+    const test = TelegramChat.deliveryKey(first, { botId, environment: "test" })
+    assert.isTrue(Option.getOrThrow(test).startsWith("test."))
+  })
+
+  it.effect("confirms a polled update only after it ran", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recorder = makeRecorder()
+      const first = messageUpdate({ text: "one" })
+      const second = messageUpdate({ text: "two" })
+      api.updates.push([first, second])
+      yield* Layer.build(
+        TelegramChat.layerPolling({ onUnhandled: recorder.onUnhandled }).pipe(
+          Layer.provideMerge(telegramLayer(api, { unverified })),
+          Layer.provide(Layer.succeed(ChatHandler, recorder.handler))
+        )
+      )
+      while (api.sent("getUpdates").length < 2) yield* Effect.yieldNow
+      const [start, next] = api.sent("getUpdates")
+      assert.isUndefined(start.offset)
+      assert.deepStrictEqual(start.allowed_updates, ["message", "channel_post", "callback_query"])
+      assert.strictEqual(next.offset, second.update_id + 1)
+      assert.strictEqual(recorder.events.length, 2)
+    }).pipe(Effect.scoped))
+
+  it.effect("fails to start polling when Telegram answers 409", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      api.next.set("getUpdates", apiError(409, "Conflict: can't use getUpdates method while webhook is active"))
+      const exit = yield* Layer.build(
+        TelegramChat.layerPolling().pipe(
+          Layer.provideMerge(telegramLayer(api)),
+          Layer.provide(Layer.succeed(ChatHandler, makeRecorder().handler))
+        )
+      ).pipe(Effect.scoped, Effect.exit)
+      assert.isTrue(Exit.isFailure(exit))
+      assert.isTrue(Exit.isFailure(exit) && Cause.pretty(exit.cause).includes("conflict"))
+    }))
+})
+
+describe("commandRequests", () => {
+  it.effect("refuses ids Telegram can't register", () =>
+    Effect.gen(function*() {
+      const ok = ChatInteraction.group(ChatInteraction.command("deploy", { description: "Deploy" }))
+      const bad = ChatInteraction.group(ChatInteraction.command("ship-it", { description: "Ship" }))
+      assert.deepStrictEqual(yield* TelegramChat.commandRequests(ok), {
+        commands: [{ command: "deploy", description: "Deploy" }]
+      })
+      assert.isTrue(Exit.isFailure(yield* Effect.exit(TelegramChat.commandRequests(bad))))
+    }))
+})
diff --git a/packages/chat/telegram/test/conformance.test.ts b/packages/chat/telegram/test/conformance.test.ts
new file mode 100644
index 00000000000..75cbb5209b0
--- /dev/null
+++ b/packages/chat/telegram/test/conformance.test.ts
@@ -0,0 +1,29 @@
+/**
+ * The conformance suite against the adapter with every `unverified`
+ * capability on, over a fake Bot API that keeps what was sent. Clicks and
+ * commands are built from what was sent and go through
+ * `TelegramChat.receive`.
+ */
+import * as TelegramChat from "@effect/chat-telegram/TelegramChat"
+import { describe, it } from "@effect/vitest"
+import { conformance } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import { makeApi, makeInteractions, telegramLayer, thread, userPosts } from "./utils.ts"
+
+const options = { platform: "telegram", thread, userPosts, parseMention: TelegramChat.parseMention }
+
+describe("conformance over a fake Bot API", () => {
+  const names = Object.keys(conformance({
+    ...options,
+    interactions: { click: () => Effect.void, submit: () => Effect.void, command: () => Effect.void }
+  }))
+
+  for (const name of names) {
+    it.effect(name, () => {
+      const api = makeApi()
+      const { bind, interactions } = makeInteractions(api)
+      const rules = conformance({ ...options, interactions })
+      return Effect.andThen(bind, rules[name]).pipe(Effect.provide(telegramLayer(api)))
+    })
+  }
+})
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
new file mode 100644
index 00000000000..3794c13531b
--- /dev/null
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -0,0 +1,75 @@
+/**
+ * T3 and T4: the rendered Markdown stays within what `measure` charged and
+ * carries no raw HTML, image, math, spoiler or link outside http, https and
+ * mailto. The corpus is checked by hand against GFM; live check 2 confirms
+ * Telegram's parser agrees.
+ */
+import { measure, messageLength, render, reservation } from "@effect/chat-telegram/internal/markdown"
+import { assert, describe, it } from "@effect/vitest"
+import * as fc from "fast-check"
+
+const cases: ReadonlyArray = [
+  ["hi  ", "\\hi\\  \\"],
+  ["![a](https://e.com/a.png) ![b][r]", "\\![a](https://e.com/a.png) \\![b][r]"],
+  ["[me](tg://user?id=1) [ok](tg://user?id=2)", "[me\\](tg://user?id\\=1) [ok](tg://user?id\\=2)"],
+  [
+    "[a](tg://x) [b](tg%3A//x) [c](tg\\://x) [d](javascript:x)",
+    "[a\\](tg://x) [b\\](tg%3A//x) [c\\](tg\\://x) [d\\](javascript:x)"
+  ],
+  ["[r]\n\n[r]: tg://user?id=1", "[r]\n\n[r\\]: tg://user?id\\=1"],
+  ["$x$ ==m== ||s||", "\\$x\\$ \\=\\=m\\=\\= \\|\\|s\\|\\|"],
+  ["| a | b |\n|---|---|\n| 1 | 2 |", "| a | b |\n|---|---|\n| 1 | 2 |"],
+  ["`` and `open", "`` and \\`open"],
+  [">".repeat(17) + " x", ">".repeat(15) + "\\>\\> x"]
+]
+
+const bytes = (s: string) => new TextEncoder().encode(s).length
+
+const markdown = fc.string({
+  unit: fc.oneof(
+    fc.constantFrom(
+      ..."<>$=|![]()*_~`#-+.:/\\&;\n\r \t0123456789abc",
+      "\u0000",
+      "é",
+      "€",
+      "😀",
+      "\ud800",
+      "tg://",
+      "https://"
+    ),
+    fc.string({ maxLength: 3 })
+  ),
+  maxLength: 200
+})
+
+describe("render", () => {
+  it("escapes the hostile corpus", () => {
+    for (const [input, expected] of cases) assert.strictEqual(render(input, { mentions: new Set(["2"]) }), expected)
+  })
+
+  it("escapes the pipes of a table wider than 20 columns", () => {
+    const row = (cell: string) => "|" + ` ${cell} |`.repeat(21)
+    const out = render(row("c") + "\n" + row("-"))
+    assert.isFalse(/(^|[^\\])\|/.test(out))
+  })
+
+  it("closes an open fence before the media references", () => {
+    assert.strictEqual(render("```\n", { files: 1 }), "```\n\n```\n\n![](tg://document?id=f1)")
+  })
+
+  it("never exceeds measure, with the reservation for files", () => {
+    fc.assert(fc.property(markdown, fc.integer({ min: 0, max: 10 }), (input, files) => {
+      assert.isAtMost(bytes(render(input)), measure(input))
+      assert.isAtMost(bytes(render(input, { files })), measure(input) + reservation)
+    }))
+    assert.strictEqual(messageLength + reservation, 32_768)
+  })
+})
+
+describe("measure", () => {
+  it("is subadditive", () => {
+    fc.assert(fc.property(markdown, markdown, (a, b) => {
+      assert.isAtMost(measure(a + b), measure(a) + measure(b))
+    }))
+  })
+})
diff --git a/packages/chat/telegram/test/utils.ts b/packages/chat/telegram/test/utils.ts
new file mode 100644
index 00000000000..64a2fa1dc2d
--- /dev/null
+++ b/packages/chat/telegram/test/utils.ts
@@ -0,0 +1,221 @@
+import * as TelegramChat from "@effect/chat-telegram/TelegramChat"
+import * as Chat from "effect/chat/Chat"
+import type { ChatEvent } from "effect/chat/ChatEvent"
+import { ChatHandler } from "effect/chat/ChatHandler"
+import { type Interactions, NoSuchElement } from "effect/chat/ChatTest"
+import * as Effect from "effect/Effect"
+import * as HttpClient from "effect/http/HttpClient"
+import type * as HttpClientRequest from "effect/http/HttpClientRequest"
+import * as HttpClientResponse from "effect/http/HttpClientResponse"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+
+/** A marker token: no error, span or log may contain it. */
+export const token = "123456789:AAH-marker_TOKEN_must_not_leak"
+export const botId = "123456789"
+export const username = "effect_bot"
+export const chatId = -1001234567890
+export const thread = TelegramChat.thread(chatId)
+export const user = { id: 4242, is_bot: false, first_name: "Ada" }
+
+export interface Call {
+  readonly method: string
+  readonly body: any
+}
+
+const ok = (result: unknown) => ({ status: 200, body: { ok: true, result } })
+
+/** A Bot API error answer, as Telegram sends it. */
+export const apiError = (code: number, description: string, parameters?: unknown) => ({
+  status: code,
+  body: { ok: false, error_code: code, description, ...(parameters === undefined ? {} : { parameters }) }
+})
+
+type Answer = { readonly status: number; readonly body: unknown }
+
+const readBody = (request: HttpClientRequest.HttpClientRequest): any => {
+  const raw = request.body
+  if (raw._tag === "Uint8Array") return JSON.parse(new TextDecoder().decode(raw.body))
+  if (raw._tag !== "FormData") return {}
+  const body: Record = {}
+  for (const [key, value] of raw.formData.entries()) {
+    if (typeof value !== "string") body[key] = value
+    else {
+      try {
+        body[key] = JSON.parse(value)
+      } catch {
+        body[key] = value
+      }
+    }
+  }
+  return body
+}
+
+/**
+ * A Bot API that keeps the messages the adapter sends by id. `next` holds
+ * one-shot answers for a method.
+ */
+export const makeApi = () => {
+  const calls: Array = []
+  const messages = new Map()
+  const next = new Map()
+  /** The batches `getUpdates` gives, in order. Once they run out it never answers. */
+  const updates: Array> = []
+  let count = 100
+
+  const answer = (method: string, body: any): Answer => {
+    switch (method) {
+      case "getMe":
+        return ok({ id: Number(botId), is_bot: true, first_name: "Effect", username })
+      case "sendRichMessage": {
+        const id = ++count
+        messages.set(id, body)
+        return ok({
+          message_id: id,
+          date: Math.floor(Date.now() / 1000),
+          chat: { id: body.chat_id, type: "supergroup", title: "Effect" },
+          ...(body.reply_markup === undefined ? {} : { reply_markup: body.reply_markup })
+        })
+      }
+      case "editMessageText":
+        if (!messages.has(body.message_id)) return apiError(400, "Bad Request: message to edit not found")
+        messages.set(body.message_id, { ...messages.get(body.message_id), ...body })
+        return ok(true)
+      case "deleteMessage":
+        if (!messages.delete(body.message_id)) return apiError(400, "Bad Request: message to delete not found")
+        return ok(true)
+      case "getChat":
+        return ok({ id: body.chat_id, type: "supergroup", title: "Effect" })
+      case "getChatMember":
+        return ok({ status: "member", user: { ...user, id: body.user_id } })
+      case "getFile":
+        return ok({ file_id: body.file_id, file_unique_id: "u", file_size: 5, file_path: "documents/file_1.txt" })
+      case "answerCallbackQuery":
+      case "setWebhook":
+      case "setMyCommands":
+        return ok(true)
+      default:
+        return apiError(404, "Not Found")
+    }
+  }
+
+  const client = HttpClient.make((request, url) =>
+    Effect.suspend(() => {
+      const file = /^\/file\/bot[^/]+\/(.+)$/.exec(url.pathname)
+      if (file !== null) {
+        calls.push({ method: "file", body: file[1] })
+        return Effect.succeed(HttpClientResponse.fromWeb(request, new Response(new TextEncoder().encode("hello"))))
+      }
+      const method = url.pathname.split("/").pop()!
+      const body = readBody(request)
+      calls.push({ method, body })
+      let scripted = next.get(method)
+      if (scripted !== undefined) next.delete(method)
+      if (scripted === undefined && method === "getUpdates") {
+        const batch = updates.shift()
+        if (batch === undefined) return Effect.never
+        scripted = ok(batch)
+      }
+      const { body: json, status } = scripted ?? answer(method, body)
+      return Effect.succeed(HttpClientResponse.fromWeb(
+        request,
+        new Response(JSON.stringify(json), { status, headers: { "content-type": "application/json" } })
+      ))
+    })
+  )
+
+  return {
+    calls,
+    messages,
+    next,
+    updates,
+    sent: (method: string) => calls.filter((call) => call.method === method).map((call) => call.body),
+    layer: Layer.succeed(HttpClient.HttpClient, client)
+  }
+}
+
+export type FakeApi = ReturnType
+
+/** Every capability on, as the conformance suite and the interaction tests want. */
+export const unverified = { files: true, buttons: true, commands: true }
+
+/** `Chat`, `Registry` and the adapter on a fake Bot API. */
+export const telegramLayer = (api: FakeApi, options?: { readonly unverified?: TelegramChat.Unverified }) =>
+  TelegramChat.layer({ token: Redacted.make(token), unverified: options?.unverified ?? unverified }).pipe(
+    Layer.provideMerge(Chat.layer),
+    Layer.provide(api.layer)
+  )
+
+let updateId = 900_000
+
+/** An update with one message from `from` in the test supergroup. */
+export const messageUpdate = (message: Record, from: object = user) => {
+  const id = ++updateId
+  return {
+    update_id: id,
+    message: {
+      message_id: id,
+      date: Math.floor(Date.now() / 1000),
+      chat: { id: chatId, type: "supergroup", title: "Effect" },
+      from,
+      ...message
+    }
+  }
+}
+
+/** A command message, with its `bot_command` entity. */
+export const commandUpdate = (name: string, text = "", extra?: Record) =>
+  messageUpdate({
+    text: text === "" ? `/${name}` : `/${name} ${text}`,
+    entities: [{ type: "bot_command", offset: 0, length: name.length + 1 }],
+    ...extra
+  })
+
+/** A click on `data` from `user`, on the message as Telegram keeps it. */
+export const callbackUpdate = (message: Record | undefined, data: string) => ({
+  update_id: ++updateId,
+  callback_query: {
+    id: "cq" + updateId,
+    from: user,
+    chat_instance: "1",
+    data,
+    ...(message === undefined ? {} : { message })
+  }
+})
+
+export const context = { botId, botUsername: username }
+
+/** The user's text, as `ChatTest.conformance` wants it. */
+export const userPosts = (_thread: unknown, text: string): Effect.Effect =>
+  Effect.sync(() => TelegramChat.normalize(messageUpdate({ text }), context)[0])
+
+const noHandler = Layer.succeed(ChatHandler, ChatHandler.of({ handle: () => Effect.void }))
+
+/** The conformance hook: clicks and commands go through `TelegramChat.receive`. */
+export const makeInteractions = (api: FakeApi) => {
+  let service: TelegramChat.TelegramChat["Service"] | undefined
+  const bind = Effect.tap(TelegramChat.TelegramChat, (telegram) =>
+    Effect.sync(() => {
+      service = telegram
+    }))
+  const receive = (update: unknown) => service!.receive(update).pipe(Effect.provide(noHandler), Effect.asVoid)
+  const interactions: Interactions = {
+    click: Effect.fnUntraced(function*(messageId, id) {
+      const sent = api.messages.get(Number(messageId))
+      const buttons: Array<{ readonly callback_data?: string }> = sent?.reply_markup?.inline_keyboard?.flat() ?? []
+      const button = buttons.find((b) => b.callback_data?.split("\u001f")[0] === id)
+      if (button?.callback_data === undefined) return yield* Effect.fail(new NoSuchElement({ messageId, id }))
+      yield* receive(callbackUpdate({
+        message_id: Number(messageId),
+        date: Math.floor(Date.now() / 1000),
+        chat: { id: sent.chat_id, type: "supergroup", title: "Effect" },
+        from: { id: Number(botId), is_bot: true, first_name: "Effect" },
+        text: "x",
+        reply_markup: sent.reply_markup
+      }, button.callback_data))
+    }),
+    submit: () => Effect.void,
+    command: (_thread, id, options) => receive(commandUpdate(id, options?.text ?? ""))
+  }
+  return { bind, interactions }
+}
diff --git a/packages/chat/telegram/tsconfig.json b/packages/chat/telegram/tsconfig.json
new file mode 100644
index 00000000000..e2a8ca19a0d
--- /dev/null
+++ b/packages/chat/telegram/tsconfig.json
@@ -0,0 +1,8 @@
+{
+  "$schema": "https://json.schemastore.org/tsconfig",
+  "extends": "../../../tsconfig.base.json",
+  "include": ["src"],
+  "references": [
+    { "path": "../../effect" }
+  ]
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 128e8a67a40..cd32f8defa1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -369,6 +369,12 @@ importers:
         specifier: workspace:^
         version: link:../../effect
 
+  packages/chat/telegram:
+    devDependencies:
+      effect:
+        specifier: workspace:^
+        version: link:../../effect
+
   packages/chat/whatsapp:
     devDependencies:
       effect:
diff --git a/tsconfig.packages.json b/tsconfig.packages.json
index 4261fc32473..8dc98fa56a8 100644
--- a/tsconfig.packages.json
+++ b/tsconfig.packages.json
@@ -17,6 +17,7 @@
     { "path": "packages/chat/whatsapp" },
     { "path": "packages/chat/discord" },
     { "path": "packages/chat/teams" },
+    { "path": "packages/chat/telegram" },
     { "path": "packages/atom/vue" },
     { "path": "packages/atom/solid" },
     { "path": "packages/opentelemetry" },
diff --git a/tsconfig.tests.json b/tsconfig.tests.json
index 2dae6fe6e07..742bdd83457 100644
--- a/tsconfig.tests.json
+++ b/tsconfig.tests.json
@@ -62,6 +62,8 @@
       "@effect/chat-discord/*": ["./packages/chat/discord/src/*.ts"],
       "@effect/chat-teams": ["./packages/chat/teams/src/index.ts"],
       "@effect/chat-teams/*": ["./packages/chat/teams/src/*.ts"],
+      "@effect/chat-telegram": ["./packages/chat/telegram/src/index.ts"],
+      "@effect/chat-telegram/*": ["./packages/chat/telegram/src/*.ts"],
       "@effect/atom-react": ["./packages/atom/react/src/index.ts"],
       "@effect/atom-react/*": ["./packages/atom/react/src/*.ts"],
       "@effect/atom-vue": ["./packages/atom/vue/src/index.ts"],
diff --git a/vitest.config.ts b/vitest.config.ts
index e3ed6a9d3bb..09beb64028b 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -141,6 +141,7 @@ export default defineConfig({
         test: { server: { deps: { inline: ["dfx"] } } }
       }),
       ...project("@effect/chat-teams", "packages/chat/teams"),
+      ...project("@effect/chat-telegram", "packages/chat/telegram"),
       ...project("@effect/atom-react", "packages/atom/react", true, {
         test: {
           environment: "jsdom",

From cfacbdfb5e54914967a6c383d3d75e16611cfa0e Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 22:16:34 +0000
Subject: [PATCH 73/89] Narrow Teams webhook test JSON for Deno

---
 packages/chat/teams/test/webhook.test.ts | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/packages/chat/teams/test/webhook.test.ts b/packages/chat/teams/test/webhook.test.ts
index a742e5f649b..18acad8ec9d 100644
--- a/packages/chat/teams/test/webhook.test.ts
+++ b/packages/chat/teams/test/webhook.test.ts
@@ -213,8 +213,19 @@ describe("layerWebhook", () => {
           bearer
         )
         const body = yield* Effect.promise(() => response.json())
-        return body?.task?.type === "continue"
-          ? body.task.value.card.content.actions[0].data.effect as string
+        return Schema.is(Schema.Struct({
+            task: Schema.Struct({
+              type: Schema.Literal("continue"),
+              value: Schema.Struct({
+                card: Schema.Struct({
+                  content: Schema.Struct({
+                    actions: Schema.Array(Schema.Struct({ data: Schema.Struct({ effect: Schema.String }) }))
+                  })
+                })
+              })
+            })
+          }))(body)
+          ? body.task.value.card.content.actions[0]?.data.effect
           : undefined
       })
 

From 81c7cbbf862e2e011f3dc6ccdefbecbf07395b39 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 22:16:34 +0000
Subject: [PATCH 74/89] Set an explicit heap budget for the full Node CI suite

---
 .github/workflows/check.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index 3380c03bde6..1bb71e099cd 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -164,7 +164,8 @@ jobs:
             node: ""
             deno: ""
             bun: ""
-            command: pnpm test --max-concurrency=10
+            # The full suite exceeds Node's default ~2 GiB heap on this runner.
+            command: NODE_OPTIONS=--max-old-space-size=4096 pnpm test --max-concurrency=10
           # Node 25 and older handle upgrade request bodies differently.
           - runtime: Node 24 (platform-node)
             node: 24

From 92929b6d5ce58cc1f1308f4c6273e168ef16b1b1 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 22:35:51 +0000
Subject: [PATCH 75/89] Fix Telegram renderer bypasses and cover durable
 acceptance

Close the escape bypasses a GFM parse found: backticks in link titles,
indented fences, emphasis runs past the nesting limit, tables ended by
another block, and backslashes inside bare URLs. Check the rendered
output with micromark's GFM parser, a test-only dependency.

Take an anonymous admin's command principal from sender_chat, and give
an animation one attachment. Test the README's secret-header redaction
and the durable-acceptance recipe, and document the click and command
deadlines and the release status.
---
 packages/chat/telegram/README.md              |  48 +-
 packages/chat/telegram/package.json           |   6 +-
 packages/chat/telegram/src/TelegramChat.ts    |  31 +-
 .../chat/telegram/src/internal/markdown.ts    | 304 ++++++----
 .../chat/telegram/src/internal/normalize.ts   |   5 +-
 .../chat/telegram/src/internal/receive.ts     |   3 +-
 .../chat/telegram/test/TelegramChat.test.ts   | 173 +++++-
 packages/chat/telegram/test/gfm.ts            |  75 +++
 packages/chat/telegram/test/markdown.test.ts  |  80 ++-
 pnpm-lock.yaml                                | 535 ++++++++++++++++++
 10 files changed, 1113 insertions(+), 147 deletions(-)
 create mode 100644 packages/chat/telegram/test/gfm.ts

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index 9cc2fe537a3..43455cf74f4 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -2,7 +2,7 @@
 
 A [Telegram](https://telegram.org) adapter for `effect/chat`, over the Bot API. It includes a webhook endpoint, a long-polling loop, a pure update normaliser, and the address helpers.
 
-This package is private. Nothing in it has run against Telegram yet, and it stays private until the live checks below pass.
+This package is private, and it is not released. Nothing in it has run against Telegram yet, the default capabilities included: rich posts and edits, the escaping, link previews and notifications are as unverified as files, buttons and commands. It stays private until the base live checks below pass (1, 2, 3, 4, 5, 7, 10, 11, 15, 16 and 17). Passing unit tests do not lift that. Releasing it then means removing `private`, adding the package to the release setup, and adding its changeset.
 
 ## Setup
 
@@ -35,13 +35,13 @@ Register the webhook once with `TelegramChat.setWebhook({ url, secretToken })`,
 
 By default the descriptor advertises `edit`, `delete`, `replyTo`, `download`, `getThread` and `getUser`, alongside `post`. Posts and edits are rich messages (`sendRichMessage`). `getUser` needs `in`, the chat to look the user up in.
 
-These capabilities are implemented but stay off until their live checks pass. Turn them on with the `unverified` option, at your own risk:
+These capabilities are implemented but stay off until their live checks pass, on top of the base checks. Turn them on with the `unverified` option, at your own risk:
 
-| Option     | Turns on   | Live checks |
-| ---------- | ---------- | ----------- |
-| `files`    | `files`    | 6           |
-| `buttons`  | `buttons`  | 7, 8        |
-| `commands` | `commands` | 7, 9, 10    |
+| Option     | Turns on   | Live checks, besides the base ones |
+| ---------- | ---------- | ---------------------------------- |
+| `files`    | `files`    | 6                                  |
+| `buttons`  | `buttons`  | 8                                  |
+| `commands` | `commands` | 9                                  |
 
 An edit of a message posted with files may drop its media. Live check 6 decides whether that is so.
 
@@ -52,19 +52,41 @@ Updates from business connections, a channel's direct messages and guest mode ar
 ## Security
 
 - The bot token is in the URL path of every Bot API call. The adapter turns off the HTTP client's own spans for these calls, writes its own span with the path as `/bot/{method}`, never follows a redirect, and keeps the token out of every error.
-- The webhook needs the `X-Telegram-Bot-Api-Secret-Token` header, compared in constant time, before it reads the body. An app that records server request headers must add `TelegramChat.secretHeader` to `Headers.CurrentRedactedNames`.
+- The webhook needs the `X-Telegram-Bot-Api-Secret-Token` header, compared in constant time, before it reads the body. Server spans record no headers by default. An app that records them (`HttpMiddleware.TracerHeaderFilter`) must add `TelegramChat.secretHeader` to `Headers.CurrentRedactedNames`, keeping the names already there, in the layer it serves. `Layer.provide` on the webhook alone does not reach the server span, `Layer.provideMerge` does:
+
+  ```ts
+  import * as Effect from "effect/Effect"
+  import * as Headers from "effect/http/Headers"
+
+  const RedactSecret = Layer.effect(
+    Headers.CurrentRedactedNames,
+    Effect.gen(function*() {
+      return [...yield* Headers.CurrentRedactedNames, TelegramChat.secretHeader]
+    })
+  )
+
+  const App = Webhook.pipe(Layer.provideMerge(RedactSecret))
+  ```
 - Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`.
 - A click is dispatched only when its `data` matches a button in Telegram's own copy of the message. That shows the bot put the button there, not that it is still current or that this user may press it.
 
 ## Redelivery
 
-Telegram sends an update again until it gets a 200, clicks and commands included. The webhook answers 503 when the `ChatHandler` fails `NotAccepted` or passes its deadline, and Telegram retries. Polling retries an update up to `maxAttempts` times, then logs it and moves on.
+Telegram sends an update again until it gets a 200, clicks and commands included. Polling sees it again until the offset moves past it. The webhook answers 503 when the `ChatHandler` fails `NotAccepted` or passes `deadline` (10 seconds), and Telegram retries. Polling retries an update up to `maxAttempts` times, then logs it and moves on.
+
+Clicks and commands are different. Their handlers have a deadline of their own, and when it passes the update counts as answered: the webhook answers 200 and polling moves its offset. Telegram does not send it again.
+
+- A click handler has `clickDeadline` (2.5 seconds). Then the click is answered so the button stops spinning, and the handler keeps running, detached. If it fails or the process dies after that, nothing repeats the click.
+- A command handler has `commandDeadline` (10 seconds). Then it is interrupted. If it had not committed, the command is lost.
+- A handler that fails, rather than passing its deadline, is answered and refused through `ChatInteraction.Handler.refused`, not redelivered.
+
+A handler whose work must not be lost or done twice keys it with `TelegramChat.deliveryKey(event.raw, { botId })`. The adapter keeps no store, so this is the consumer's to do:
 
-A handler whose work must not run twice keys it with `TelegramChat.deliveryKey(event.raw, { botId })`:
+1. In one transaction, insert the key under a unique constraint, together with a work item that a worker picks up, also after a crash.
+2. Return only after the commit: success from the `ChatHandler`, `Ack` for a click, `Defer` for a command. The worker does the work, and for a command sends the `followUp`.
+3. When the insert hits the constraint, the work is already safe: answer the same way at once. A repeated command answers `Defer`, never `Ack`, which would turn it into `MessageCreated`.
 
-1. Record the key and do the work in one transaction.
-2. Reply only after the commit.
-3. When the key is already there, answer a repeated click with `Ack` and a repeated command with `Defer`, so a command is never handled twice and never falls through to `MessageCreated`.
+A crash before the commit leaves nothing, and the repeat does the work. A concurrent repeat waits on the constraint for the first transaction. This holds only while the transaction commits within the deadline above: for clicks and commands a late commit is not repeated. External side effects, such as a payment, still need their own idempotency key (the delivery key works). Nothing here gives exactly-once effects.
 
 ## Live checks
 
diff --git a/packages/chat/telegram/package.json b/packages/chat/telegram/package.json
index 9a9f4129def..9066c42639f 100644
--- a/packages/chat/telegram/package.json
+++ b/packages/chat/telegram/package.json
@@ -62,7 +62,11 @@
     "check": "tsc -b tsconfig.json"
   },
   "devDependencies": {
-    "effect": "workspace:^"
+    "@types/mdast": "^4.0.4",
+    "effect": "workspace:^",
+    "mdast-util-from-markdown": "^2.0.2",
+    "mdast-util-gfm": "^3.1.0",
+    "micromark-extension-gfm": "^3.0.0"
   },
   "peerDependencies": {
     "effect": "workspace:^"
diff --git a/packages/chat/telegram/src/TelegramChat.ts b/packages/chat/telegram/src/TelegramChat.ts
index 35192f63152..c5e4f81cfce 100644
--- a/packages/chat/telegram/src/TelegramChat.ts
+++ b/packages/chat/telegram/src/TelegramChat.ts
@@ -11,10 +11,10 @@
  *   `editMessageText` with `rich_message`), in Markdown escaped so that
  *   consumer text reaches no raw HTML, image, math, spoiler or non-web
  *   link.
- * - Nothing here has run against Telegram yet, and the package is private
- *   until it has. Files, buttons and commands are behind `unverified`
- *   options, off by default, so a descriptor never advertises what no live
- *   check confirmed.
+ * - Nothing here has run against Telegram yet, the default capabilities
+ *   included, and the package stays private until the base live checks
+ *   pass. Files, buttons and commands need further checks, so they are
+ *   behind `unverified` options, off by default.
  * - There is no `ephemeral`: a private answer to a command is refused
  *   through `Handler.refused`, never posted. `fetchMessage`, `history`,
  *   `opener`, `startThread`, selects, modals, native streams and reaction
@@ -101,11 +101,19 @@ export type Outcome = "accepted" | "unhandled" | "notAccepted" | "invalid"
 export interface ReceiveOptions {
   /** Updates that give no event, the excluded contexts among them. */
   readonly onUnhandled?: ((update: Schema.Json) => Effect.Effect) | undefined
-  /** How long `ChatHandler.handle` has. Default 10 seconds. */
+  /** How long `ChatHandler.handle` has before the update is `notAccepted`. Default 10 seconds. */
   readonly deadline?: Duration.Input | undefined
-  /** A click handler's share before the click is answered. Default 2.5 seconds. */
+  /**
+   * How long a click handler has before the click is answered. Default 2.5
+   * seconds. The handler then keeps running, detached, and the update is
+   * `accepted`: Telegram does not send it again.
+   */
   readonly clickDeadline?: Duration.Input | undefined
-  /** A command handler's share. Default 10 seconds. */
+  /**
+   * How long a command handler has. Default 10 seconds. The handler is then
+   * interrupted, and the update is `accepted`: Telegram does not send it
+   * again.
+   */
   readonly commandDeadline?: Duration.Input | undefined
 }
 
@@ -201,7 +209,9 @@ export const layer = (options: {
 /**
  * The header Telegram sends the webhook secret in. An app that records
  * server request headers must add it to `Headers.CurrentRedactedNames`,
- * keeping the names already there.
+ * keeping the names already there, in the layer it serves:
+ * `Layer.provideMerge` reaches the server span, `Layer.provide` on the
+ * webhook alone does not. The README has the setup.
  *
  * @stability unstable
  * @category constants
@@ -457,7 +467,10 @@ export const normalizeInteraction = (
  * is one: `{botId}.{update_id}.{date}`, with `test.` in front in the test
  * environment. Telegram sends an update again until it gets a 200 (or an
  * offset moves past it), clicks and commands included, so a handler whose
- * work must not run twice keeps this key with its work in one transaction.
+ * work must not be lost or run twice commits this key and a recoverable
+ * work item in one transaction before it returns. A click or command
+ * past its deadline counts as answered and is not sent again, so that
+ * holds only for a commit within the deadline. The README has the recipe.
  *
  * @stability unstable
  * @category normalization
diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
index b158847d5c0..ac2b14f7bd7 100644
--- a/packages/chat/telegram/src/internal/markdown.ts
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -49,8 +49,9 @@ const isDigit = (c: string) => c >= "0" && c <= "9"
  * - a code point in the Basic Multilingual Plane costs its UTF-8 length,
  *   and each UTF-16 surrogate 3, enough for the U+FFFD a lone one becomes.
  *   NUL costs 3 too, as Markdown turns it into U+FFFD.
- * - `<` costs 4, and `$ = | ! [ ] * _ ~` and the backtick 2, their
- *   escaped length or more, whether or not they are escaped in context.
+ * - `<` costs 4, a backslash 3 (`%5C` in a bare URL), and
+ *   `$ = | ! [ ] * _ ~` and the backtick 2, their escaped length or more,
+ *   whether or not they are escaped in context.
  * - `\n` and `\r` cost `block`, as does a block marker (`>`, a bullet,
  *   the dot or parenthesis of a number) before any other text on its line.
  *
@@ -83,7 +84,17 @@ export const measure = (markdown: string): number => {
       }
       prefix = false
     }
-    cost += code === 0 ? 3 : c === "<" ? 4 : twoByteEscapes.has(c) ? 2 : code < 0x80 ? 1 : code < 0x800 ? 2 : 3
+    cost += code === 0 || c === "\\"
+      ? 3
+      : c === "<"
+      ? 4
+      : twoByteEscapes.has(c)
+      ? 2
+      : code < 0x80
+      ? 1
+      : code < 0x800
+      ? 2
+      : 3
   }
   return cost
 }
@@ -92,18 +103,19 @@ const punctuation = /[!-/:-@[-`{-~]/
 
 const isSpace = (c: string | undefined) => c === undefined || /\s/.test(c)
 
-/** A line that opens a top-level fence: at column 0, three or more backticks or tildes. */
-const fenceOpen = /^(`{3,}|~{3,})(.*)$/
+/** A line that opens a fence: up to three spaces, then three or more backticks or tildes. */
+const fenceOpen = /^( {0,3})(`{3,}|~{3,})(.*)$/
 
 interface Fence {
   readonly char: string
   readonly length: number
+  readonly indent: number
 }
 
 const opens = (line: string): Fence | undefined => {
   const match = fenceOpen.exec(line)
-  if (match === null || (match[1][0] === "`" && match[2].includes("`"))) return undefined
-  return { char: match[1][0], length: match[1].length }
+  if (match === null || (match[2][0] === "`" && match[3].includes("`"))) return undefined
+  return { char: match[2][0], length: match[2].length, indent: match[1].length }
 }
 
 const closes = (line: string, fence: Fence): boolean => {
@@ -111,6 +123,12 @@ const closes = (line: string, fence: Fence): boolean => {
   return match !== null && match[1][0] === fence.char && match[1].length >= fence.length
 }
 
+/** A line that may open a list item or footnote, which an indented fence could belong to. */
+const container = /^[ \t>]*(?:[-+*]|\d{1,9}[.)])(?:[ \t]|$)|^[ \t>]*\[\^/
+
+/** A line GFM may read as the start of another block, which ends a table and is no paragraph. */
+const blockStart = /^(?: {0,3}[#>\-*+_~`<=]| {0,3}\d{1,9}[.)]| {4}| {0,3}\t)/
+
 const delimiterRow = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/
 
 /** The cells of a table row, split at unescaped pipes as GFM does, even inside code. */
@@ -158,27 +176,69 @@ const allowedDestination = (raw: string, mentions: ReadonlySet): boolean
   return mention !== null && destination.unescaped === destination.decoded && mentions.has(mention[1])
 }
 
-/** The raw destination after `](` at `start`, or undefined when it is not on this line or is in angle brackets. */
-const inlineDestination = (line: string, start: number): string | undefined => {
-  let i = start
-  while (line[i] === " " || line[i] === "\t") i++
-  if (i >= line.length || line[i] === "<") return undefined
+/**
+ * A link's `(destination "title")` from the `(` at `start`, when all of it
+ * is on this line and the destination is not in angle brackets. A tail
+ * that goes on to the next line, as CommonMark allows, is not one: the
+ * link is then refused.
+ */
+const linkTail = (line: string, start: number): { readonly destination: string; readonly end: number } | undefined => {
+  const blank = (c: string | undefined) => c === " " || c === "\t"
+  let i = start + 1
+  while (blank(line[i])) i++
+  if (line[i] === "<") return undefined
+  const from = i
   let depth = 0
-  let end = i
-  for (; end < line.length; end++) {
-    const c = line[end]
-    if (c === "\\") {
-      end++
+  for (; i < line.length; i++) {
+    const c = line[i]
+    if (c === "\\" && punctuation.test(line[i + 1] ?? "")) {
+      i++
       continue
     }
-    if (/\s/.test(c)) break
+    if (c.charCodeAt(0) <= 0x20) break
     if (c === "(") depth++
     else if (c === ")") {
       if (depth === 0) break
       depth--
     }
   }
-  return line.slice(i, end)
+  const destination = line.slice(from, i)
+  const spaced = blank(line[i])
+  while (blank(line[i])) i++
+  const open = line[i]
+  if (spaced && (open === "\"" || open === "'" || open === "(")) {
+    const close = open === "(" ? ")" : open
+    for (i++; i < line.length && line[i] !== close; i++) {
+      if (line[i] === "\\" && punctuation.test(line[i + 1] ?? "")) i++
+      else if (open === "(" && line[i] === "(") return undefined
+    }
+    if (i >= line.length) return undefined
+    i++
+    while (blank(line[i])) i++
+  }
+  return line[i] === ")" ? { destination, end: i + 1 } : undefined
+}
+
+const tailEscapes = new Set(["`", "$", "=", "|", "!", "[", "]", "*", "_", "~"])
+
+/**
+ * A kept link's tail with every character that is syntax elsewhere
+ * escaped. CommonMark decodes the escapes in destinations and titles, so
+ * the link is the same, and a parser that does not read the link sees
+ * inert text.
+ */
+const escapeTail = (tail: string): string => {
+  let out = ""
+  for (let i = 0; i < tail.length; i++) {
+    const c = tail[i]
+    if (c === "\\" && punctuation.test(tail[i + 1] ?? "")) {
+      // `\<` and `<` decode alike, but after a bare URL only one is inert.
+      out += tail[++i] === "<" ? "<" : c + tail[i]
+      continue
+    }
+    out += c === "<" ? "<" : tailEscapes.has(c) ? "\\" + c : c
+  }
+  return out
 }
 
 /** The destination of a reference definition after `]:`, when it is on this line. */
@@ -188,55 +248,38 @@ const definitionDestination = (line: string, start: number): string | undefined
 }
 
 /**
- * The code spans of a line, as `[start, end)` pairs, paired the way
- * CommonMark pairs backtick runs. A run with no partner on the line is
- * not a span: the renderer escapes it, so no span can pair across lines.
- * In a table row a span holding a pipe is refused, since GFM splits cells
- * before it reads code.
+ * The end of the code span whose opening backticks are at `start`, found as
+ * CommonMark finds it: the next run of as many backticks on the line. A
+ * run with no partner on the line opens no span: the renderer escapes it,
+ * so no span can pair across lines. In a table row a span holding a pipe
+ * is refused, since GFM splits cells before it reads code.
  */
-const codeSpans = (line: string, tableRow: boolean): Array => {
-  const spans: Array = []
-  let i = 0
-  while (i < line.length) {
-    const c = line[i]
-    if (c === "\\" && i + 1 < line.length && punctuation.test(line[i + 1])) {
-      i += 2
-      continue
-    }
-    if (c !== "`") {
-      i++
+const codeSpanEnd = (line: string, start: number, tableRow: boolean): number | undefined => {
+  let length = 0
+  while (line[start + length] === "`") length++
+  for (let j = start + length; j < line.length;) {
+    if (line[j] !== "`") {
+      j++
       continue
     }
-    let length = 0
-    while (line[i + length] === "`") length++
-    let j = i + length
-    let close = -1
-    while (j < line.length) {
-      if (line[j] !== "`") {
-        j++
-        continue
-      }
-      let run = 0
-      while (line[j + run] === "`") run++
-      if (run === length) {
-        close = j
-        break
-      }
-      j += run
-    }
-    if (close === -1 || (tableRow && line.slice(i, close).includes("|"))) {
-      i += length
-      continue
-    }
-    spans.push([i, close + length])
-    i = close + length
+    let run = 0
+    while (line[j + run] === "`") run++
+    if (run === length) return tableRow && line.slice(start, j).includes("|") ? undefined : j + run
+    j += run
   }
-  return spans
+  return undefined
 }
 
-const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>]*>/
+/**
+ * Where GFM starts a bare URL link. It runs to the next space, taking
+ * backslashes and backticks with it, so inside one an escape is not
+ * needed and a backtick opens no span.
+ */
+const bareUrl = /^(?:https?:\/\/|www\.)/i
+
+const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>`]*>/
 
-/** The inline nesting carried through one paragraph. */
+/** The inline nesting carried through one paragraph, one entry per delimiter. */
 interface Inline {
   readonly stack: Array
 }
@@ -244,6 +287,7 @@ interface Inline {
 interface LineContext {
   readonly tableRow: boolean
   readonly widePipes: boolean
+  readonly setext: boolean
   readonly inline: Inline
   readonly mentions: ReadonlySet
 }
@@ -275,43 +319,53 @@ const renderPrefix = (line: string): { readonly text: string; readonly rest: num
 
 const renderLine = (line: string, context: LineContext): string => {
   const prefix = renderPrefix(line)
-  const setext = /^ {0,3}=+[ \t]*$/.test(line)
-  const spans = codeSpans(line, context.tableRow)
-  const footnote = line.slice(prefix.rest).startsWith("[^")
+  const footnote = /^\[\^[\w-]+\]:/.test(line.slice(prefix.rest))
   const limit = Math.max(0, maxDepth - 1 - prefix.depth)
   const stack = context.inline.stack
   let out = prefix.text
-  let span = 0
-  let firstBracket = true
+  let urlEnd = -1
   let i = prefix.rest
   while (i < line.length) {
-    while (span < spans.length && spans[span][1] <= i) span++
-    if (span < spans.length && spans[span][0] === i) {
-      out += line.slice(spans[span][0], spans[span][1])
-      i = spans[span][1]
-      continue
-    }
     const c = line[i]
     const next = line[i + 1]
+    if (i >= urlEnd && bareUrl.test(line.slice(i, i + 8))) {
+      urlEnd = i
+      while (urlEnd < line.length && line[urlEnd] !== " " && line[urlEnd] !== "\t") urlEnd++
+    }
+    const inUrl = i < urlEnd
+    // In a bare URL a backslash escapes nothing, outside one it does: as
+    // `%5C` it is the same character to a browser and inert to both.
+    if (c === "\\" && inUrl && next !== undefined && punctuation.test(next)) {
+      out += "%5C"
+      i++
+      continue
+    }
     if (c === "\\" && next !== undefined && punctuation.test(next)) {
       out += c + next
       i += 2
       continue
     }
     switch (c) {
-      case "`":
-        out += "\\`"
-        i++
+      case "`": {
+        const end = inUrl ? undefined : codeSpanEnd(line, i, context.tableRow)
+        if (end !== undefined) {
+          out += line.slice(i, end)
+          i = end
+          continue
+        }
+        while (line[i] === "`") {
+          out += "\\`"
+          i++
+        }
         continue
+      }
       case "<": {
-        const match = autolink.exec(line.slice(i))
-        const end = match === null ? -1 : i + match[0].length
-        const overlaps = match !== null && spans.some(([start]) => start > i && start < end)
-        if (match !== null && !overlaps && /^(?:https?|mailto)$/i.test(match[1])) {
+        const match = inUrl ? null : autolink.exec(line.slice(i))
+        if (match !== null && /^(?:https?|mailto)$/i.test(match[1])) {
           out += match[0]
-          i = end
+          i += match[0].length
         } else {
-          out += "\\<"
+          out += "<"
           i++
         }
         continue
@@ -321,7 +375,7 @@ const renderLine = (line: string, context: LineContext): string => {
         i++
         continue
       case "=":
-        out += setext ? "=" : "\\="
+        out += context.setext ? "=" : "\\="
         i++
         continue
       case "|":
@@ -333,16 +387,20 @@ const renderLine = (line: string, context: LineContext): string => {
         i++
         continue
       case "]": {
-        let keep = true
         if (next === "(") {
-          const destination = inlineDestination(line, i + 2)
-          keep = destination !== undefined && allowedDestination(destination, context.mentions)
-        } else if (next === ":" && !(footnote && firstBracket)) {
+          const tail = linkTail(line, i + 1)
+          if (tail !== undefined && allowedDestination(tail.destination, context.mentions)) {
+            out += "](" + escapeTail(line.slice(i + 2, tail.end - 1)) + ")"
+            i = tail.end
+            continue
+          }
+          out += "\\]"
+        } else if (next === ":" && !(footnote && i === line.indexOf("]", prefix.rest))) {
           const destination = definitionDestination(line, i + 2)
-          keep = destination !== undefined && allowedDestination(destination, context.mentions)
+          out += destination !== undefined && allowedDestination(destination, context.mentions) ? "]" : "\\]"
+        } else {
+          out += "]"
         }
-        firstBracket = false
-        out += keep ? "]" : "\\]"
         i++
         continue
       }
@@ -354,19 +412,23 @@ const renderLine = (line: string, context: LineContext): string => {
         const run = line.slice(i, end)
         const before = i === 0 ? undefined : line[i - 1]
         const after = line[end]
-        if (!isSpace(before) && stack.length > 0 && stack[stack.length - 1] === c) {
-          stack.pop()
-          out += run
-        } else if (!isSpace(after)) {
-          if (stack.length + 1 > limit) {
+        let open = run.length
+        if (!isSpace(before) && stack[stack.length - 1] === c) {
+          while (open > 0 && stack[stack.length - 1] === c) {
+            stack.pop()
+            open--
+          }
+        }
+        // A run of n delimiters can nest n levels: `***a*b*c*` is three.
+        if (open > 0 && !isSpace(after)) {
+          if (stack.length + open > limit) {
             out += run.split("").map((char) => "\\" + char).join("")
-          } else {
-            stack.push(c)
-            out += run
+            i = end
+            continue
           }
-        } else {
-          out += run
+          for (let k = 0; k < open; k++) stack.push(c)
         }
+        out += run
         i = end
         continue
       }
@@ -389,17 +451,23 @@ export interface RenderOptions {
 /**
  * Consumer Markdown as rich Markdown that keeps to what `measure` charged:
  *
- * - Top-level fences (at column 0) pass verbatim, as do code spans whose
- *   backticks pair on one line. Everything else is escaped as needed.
- * - `<` is escaped unless it opens an http, https or mailto autolink, so
- *   there is no raw HTML. `$` and `=` are escaped (math, marks), as is
- *   `|` outside tables (spoilers), and `!` before `[` (images).
+ * - Fences pass verbatim, as do code spans, which are found left to right
+ *   as CommonMark finds them. A fence indented by one to three spaces after
+ *   a list item could belong to it, so from such a fence on nothing is
+ *   verbatim. Inside a bare URL a backtick opens no span.
+ * - `<` becomes `<` unless it opens an http, https or mailto autolink,
+ *   so there is no raw HTML, also after a bare URL, which would take a
+ *   backslash with it. `$` and `=` are escaped (math, marks), except `=`
+ *   under a paragraph line (a setext heading), as is `|` outside tables
+ *   (spoilers), and `!` before `[` (images).
  * - A link or reference definition whose destination, decoded as a
  *   Markdown parser and then a URL parser would, is not http, https or
  *   mailto has its `]` escaped, so it is text. A `tg://user` link stays
- *   for an id in `mentions`.
- * - Container markers and emphasis past 16 levels are escaped, and a table
- *   wider than 20 columns has its pipes escaped.
+ *   for an id in `mentions`. A kept link's tail must end on its line and
+ *   has its syntax characters escaped.
+ * - Container markers and emphasis past 16 levels are escaped, counting a
+ *   run of n delimiters as n levels, and a table wider than 20 columns has
+ *   its pipes escaped. A table ends at a line that may start another block.
  * - `files` references are added at the end, after closing a fence left
  *   open.
  *
@@ -410,23 +478,32 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
   const lines = markdown.replace(/\r\n?/g, "\n").replace(/\0/g, "\ufffd").split("\n")
   const fenced: Array = []
   let fence: Fence | undefined
+  let containers = false
+  let verbatim = true
   for (const line of lines) {
     if (fence !== undefined) {
       fenced.push(true)
       if (closes(line, fence)) fence = undefined
       continue
     }
-    fence = opens(line)
-    fenced.push(fence !== undefined)
+    const opened = verbatim ? opens(line) : undefined
+    if (opened !== undefined && opened.indent > 0 && containers) verbatim = false
+    else if (opened !== undefined) {
+      fence = opened
+      fenced.push(true)
+      continue
+    }
+    if (container.test(line)) containers = true
+    fenced.push(false)
   }
   const tableRows = new Map()
   for (let i = 0; i + 1 < lines.length; i++) {
-    if (fenced[i] || fenced[i + 1] || tableRows.has(i)) continue
+    if (fenced[i] || fenced[i + 1] || tableRows.has(i) || blockStart.test(lines[i])) continue
     if (!delimiterRow.test(lines[i + 1]) || !lines[i + 1].includes("|") || !hasPipe(lines[i])) continue
     const columns = cellCount(lines[i])
     if (columns !== cellCount(lines[i + 1])) continue
     let end = i + 2
-    while (end < lines.length && !fenced[end] && lines[end].trim() !== "") end++
+    while (end < lines.length && !fenced[end] && lines[end].trim() !== "" && !blockStart.test(lines[end])) end++
     const rows = Array.from({ length: end - i }, (_, k) => i + k)
     for (const row of rows) tableRows.set(row, columns > maxColumns || cellCount(lines[row]) > maxColumns)
     i = end - 1
@@ -436,7 +513,10 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     if (fenced[i]) return line
     if (line.trim() === "") inline.stack.length = 0
     const wide = tableRows.get(i)
-    return renderLine(line, { tableRow: wide !== undefined, widePipes: wide === true, inline, mentions })
+    const above = i === 0 ? undefined : lines[i - 1]
+    const setext = /^ {0,3}=+[ \t]*$/.test(line) && above !== undefined && above.trim() !== "" && !fenced[i - 1] &&
+      !tableRows.has(i - 1) && !blockStart.test(above) && !/^ {0,3}\[/.test(above)
+    return renderLine(line, { tableRow: wide !== undefined, widePipes: wide === true, setext, inline, mentions })
   })
   let text = out.join("\n")
   const files = options.files ?? 0
diff --git a/packages/chat/telegram/src/internal/normalize.ts b/packages/chat/telegram/src/internal/normalize.ts
index 095f7a01567..b29ba8a004d 100644
--- a/packages/chat/telegram/src/internal/normalize.ts
+++ b/packages/chat/telegram/src/internal/normalize.ts
@@ -136,7 +136,10 @@ const attachmentsOf = (message: JsonObject): Array => {
       ...(size === undefined ? {} : { size })
     })
   }
-  for (const key of ["document", "audio", "video", "voice", "animation"]) add(object(message, key))
+  // An animation comes with a copy of itself as `document`, for older clients.
+  const animation = object(message, "animation")
+  add(animation ?? object(message, "document"))
+  for (const key of ["audio", "video", "voice"]) add(object(message, key))
   const photo = message.photo
   if (Array.isArray(photo) && photo.length > 0) {
     let largest: JsonObject | undefined
diff --git a/packages/chat/telegram/src/internal/receive.ts b/packages/chat/telegram/src/internal/receive.ts
index 67e371037ea..b387dadd8fa 100644
--- a/packages/chat/telegram/src/internal/receive.ts
+++ b/packages/chat/telegram/src/internal/receive.ts
@@ -158,7 +158,8 @@ export const commandEvent = (update: JsonObject, context: Context): ChatInteract
   if (message === undefined || isExcluded(message)) return undefined
   const found = commandOf(message, context)
   const at = threadOf(message)
-  const user = integer(object(message, "from"), "id") ?? integer(object(message, "sender_chat"), "id")
+  // As in `normalize`: an anonymous admin's `from` is Telegram's shared stand-in, the chat is the sender.
+  const user = integer(object(message, "sender_chat"), "id") ?? integer(object(message, "from"), "id")
   if (found === undefined || at === undefined || user === undefined) return undefined
   return ChatInteraction.CommandInvoked.make({
     id: found.id,
diff --git a/packages/chat/telegram/test/TelegramChat.test.ts b/packages/chat/telegram/test/TelegramChat.test.ts
index 4411ae3bc93..284d01cea9f 100644
--- a/packages/chat/telegram/test/TelegramChat.test.ts
+++ b/packages/chat/telegram/test/TelegramChat.test.ts
@@ -1,7 +1,8 @@
 /**
- * The adapter's own guarantees, over a fake Bot API: the token stays out of
- * errors, spans and logs (T1), the webhook secret (T2), private answers
- * (T5), clicks (T6), excluded contexts (T7) and acceptance (T8).
+ * The adapter's own guarantees, over a fake Bot API: the token and the
+ * webhook secret stay out of errors, spans and logs (T1), the webhook secret
+ * (T2), private answers (T5), clicks (T6), excluded contexts (T7) and
+ * acceptance (T8).
  */
 import * as TelegramChat from "@effect/chat-telegram/TelegramChat"
 import { assert, describe, it } from "@effect/vitest"
@@ -11,14 +12,19 @@ import type { ChatError } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
 import * as ChatInteraction from "effect/chat/ChatInteraction"
+import * as Deferred from "effect/Deferred"
 import * as Effect from "effect/Effect"
 import * as Exit from "effect/Exit"
+import * as Fiber from "effect/Fiber"
+import * as Headers from "effect/http/Headers"
+import * as HttpMiddleware from "effect/http/HttpMiddleware"
 import * as HttpRouter from "effect/http/HttpRouter"
 import * as Layer from "effect/Layer"
 import * as Logger from "effect/Logger"
 import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
 import type * as Schema from "effect/Schema"
+import * as Semaphore from "effect/Semaphore"
 import * as Tracer from "effect/Tracer"
 import {
   apiError,
@@ -131,7 +137,11 @@ describe("credentials", () => {
     }))
 })
 
-const webhook = Effect.fnUntraced(function*(api: FakeApi, recorder: Recorder) {
+const webhook = Effect.fnUntraced(function*(
+  api: FakeApi,
+  recorder: Recorder,
+  server: Layer.Layer = Layer.empty
+) {
   const app = TelegramChat.layerWebhook({
     path: "/telegram",
     secretToken: Redacted.make(secret),
@@ -139,11 +149,12 @@ const webhook = Effect.fnUntraced(function*(api: FakeApi, recorder: Recorder) {
     onUnhandled: recorder.onUnhandled
   }).pipe(
     Layer.provide(telegramLayer(api)),
-    Layer.provide(Layer.succeed(ChatHandler, recorder.handler))
+    Layer.provide(Layer.succeed(ChatHandler, recorder.handler)),
+    Layer.provideMerge(server)
   )
   const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true })
   yield* Effect.addFinalizer(() => Effect.promise(() => dispose()))
-  return (body: string, header?: string) =>
+  return (body: string, header?: string, headers?: Record) =>
     Effect.promise(() =>
       handler(
         new Request("http://localhost/telegram", {
@@ -151,6 +162,7 @@ const webhook = Effect.fnUntraced(function*(api: FakeApi, recorder: Recorder) {
           body,
           headers: {
             "content-type": "application/json",
+            ...headers,
             ...(header === undefined ? {} : { [TelegramChat.secretHeader]: header })
           }
         })
@@ -178,6 +190,40 @@ describe("layerWebhook", () => {
       assert.strictEqual(recorder.unhandled.length, 1)
     }))
 
+  it.effect("keeps the secret out of server spans that capture every header, set up as the README says", () =>
+    Effect.gen(function*() {
+      const spans: Array = []
+      const tracer = Tracer.make({
+        span(options) {
+          const span = new Tracer.NativeSpan(options)
+          spans.push(span)
+          return span
+        }
+      })
+      // The README's setup: the names reach the server, and keep the defaults.
+      const RedactSecret = Layer.effect(
+        Headers.CurrentRedactedNames,
+        Effect.gen(function*() {
+          return [...yield* Headers.CurrentRedactedNames, TelegramChat.secretHeader]
+        })
+      )
+      const server = Layer.mergeAll(
+        RedactSecret,
+        Layer.succeed(HttpMiddleware.TracerHeaderFilter, () => true),
+        Layer.succeed(Tracer.Tracer, tracer)
+      )
+      const send = yield* webhook(makeApi(), makeRecorder(), server)
+      const status = yield* send(JSON.stringify(messageUpdate({ text: "hi" })), secret, {
+        authorization: "Bearer marker"
+      })
+      assert.strictEqual(status, 200)
+      const attributes = new Map(spans.find((span) => span.kind === "server")?.attributes)
+      assert.strictEqual(attributes.get("http.request.header.x-telegram-bot-api-secret-token"), "")
+      assert.strictEqual(attributes.get("http.request.header.authorization"), "")
+      assert.strictEqual(attributes.get("http.request.header.content-type"), "application/json")
+      assert.isFalse(JSON.stringify(spans.map((span) => [...span.attributes])).includes(secret))
+    }))
+
   it.effect("answers 503 when the handler does not accept", () =>
     Effect.gen(function*() {
       const send = yield* webhook(makeApi(), makeRecorder({ refuse: true }))
@@ -335,6 +381,121 @@ describe("acceptance", () => {
     }))
 })
 
+describe("durable acceptance", () => {
+  /**
+   * The README's recipe on an in-memory store. The key and its work item
+   * commit together, and an insert waits for the one in flight, as a unique
+   * constraint does. `beforeCommit` is where the handler's work can crash.
+   */
+  const makeRecipe = (beforeCommit: (attempt: number) => Effect.Effect) => {
+    const recorder = makeRecorder()
+    const work = new Map()
+    const log: Array = []
+    const constraint = Semaphore.makeUnsafe(1)
+    let attempts = 0
+    const insert = (raw: Schema.Json, item: string) =>
+      constraint.withPermits(1)(Effect.suspend(() => {
+        const key = Option.getOrThrow(TelegramChat.deliveryKey(raw, { botId }))
+        if (work.has(key)) return Effect.sync(() => void log.push("repeat"))
+        return Effect.andThen(
+          beforeCommit(++attempts),
+          Effect.sync(() => {
+            work.set(key, item)
+            log.push("commit")
+          })
+        )
+      }))
+    const interactions = ChatInteraction.Handler.of({
+      ...recorder.interactions,
+      click: (event) => Effect.as(insert(event.raw, event.id), ChatInteraction.ack),
+      command: (event) =>
+        Effect.as(insert(event.raw, event.text), ChatInteraction.defer(event, { visibility: "public" }))
+    })
+    return { ...recorder, interactions, work, log, attempts: () => attempts }
+  }
+
+  const blocked = Effect.fnUntraced(function*(recipe: { readonly attempts: () => number }, n: number) {
+    while (recipe.attempts() < n) yield* Effect.yieldNow
+  })
+
+  it.effect("redoes a command that crashed before its commit", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recipe = makeRecipe((attempt) => attempt === 1 ? Effect.never : Effect.void)
+      const update = commandUpdate("deploy", "prod")
+      const crashed = yield* Effect.forkChild(receive(api, recipe, update))
+      yield* blocked(recipe, 1)
+      yield* Fiber.interrupt(crashed)
+      assert.strictEqual(recipe.work.size, 0)
+      assert.deepStrictEqual(yield* receive(api, recipe, update), ["accepted"])
+      assert.deepStrictEqual([...recipe.work.values()], ["prod"])
+      assert.strictEqual(recipe.events.length, 0)
+    }))
+
+  it.effect("answers a concurrent repeat only after the first commits", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const release = yield* Deferred.make()
+      const recipe = makeRecipe(() => Deferred.await(release))
+      const update = commandUpdate("deploy", "prod")
+      const first = yield* Effect.forkChild(receive(api, recipe, update))
+      yield* blocked(recipe, 1)
+      const repeat = yield* Effect.forkChild(
+        Effect.tap(receive(api, recipe, update), () => Effect.sync(() => void recipe.log.push("repeat answered")))
+      )
+      for (let i = 0; i < 10; i++) yield* Effect.yieldNow
+      assert.deepStrictEqual(recipe.log, [])
+      yield* Deferred.succeed(release, void 0)
+      assert.deepStrictEqual([yield* Fiber.join(first), yield* Fiber.join(repeat)], [["accepted"], ["accepted"]])
+      assert.deepStrictEqual(recipe.log, ["commit", "repeat", "repeat answered"])
+      assert.strictEqual(recipe.work.size, 1)
+      assert.strictEqual(recipe.events.length, 0)
+    }))
+
+  it.effect("answers a repeat after the commit, and never turns a command into a message", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const recipe = makeRecipe(() => Effect.void)
+      const command = commandUpdate("deploy", "prod")
+      const click = callbackUpdate({
+        message_id: 5,
+        date: 1_800_000_000,
+        chat: { id: chatId, type: "supergroup" },
+        text: "x",
+        reply_markup: { inline_keyboard: [[{ text: "Yes", callback_data: "approve" }]] }
+      }, "approve")
+      const outcomes = yield* receive(api, recipe, command, command, click, click)
+      assert.deepStrictEqual(outcomes, ["accepted", "accepted", "accepted", "accepted"])
+      assert.deepStrictEqual(recipe.log, ["commit", "repeat", "commit", "repeat"])
+      assert.strictEqual(recipe.events.length, 0)
+      assert.strictEqual(api.sent("answerCallbackQuery").length, 2)
+    }))
+})
+
+describe("senders and files", () => {
+  // Telegram's stand-in `from` for anonymous group admins.
+  const anonymous = { id: 1087968824, is_bot: true, first_name: "Group", username: "GroupAnonymousBot" }
+
+  it.effect("gives an anonymous admin's command the group as its user", () =>
+    Effect.gen(function*() {
+      const recorder = makeRecorder()
+      const asGroup = (id: number) =>
+        commandUpdate("deploy", "", { from: anonymous, sender_chat: { id, type: "supergroup", title: "G" } })
+      yield* receive(makeApi(), recorder, asGroup(-1001), asGroup(-1002))
+      assert.deepStrictEqual(recorder.commands.map((command) => command.userId), ["-1001", "-1002"])
+    }))
+
+  it("gives an animation one attachment, not its document copy too", () => {
+    const file = { file_id: "anim", file_unique_id: "u", mime_type: "video/mp4" }
+    const [event] = TelegramChat.normalize(
+      messageUpdate({ animation: { ...file, width: 1, height: 1, duration: 1 }, document: file }),
+      context
+    )
+    assert.strictEqual(event._tag, "MessageCreated")
+    assert.deepStrictEqual(event._tag === "MessageCreated" ? event.message.attachments.map((a) => a.id) : [], ["anim"])
+  })
+})
+
 describe("commandRequests", () => {
   it.effect("refuses ids Telegram can't register", () =>
     Effect.gen(function*() {
diff --git a/packages/chat/telegram/test/gfm.ts b/packages/chat/telegram/test/gfm.ts
new file mode 100644
index 00000000000..6c7fca9d6d3
--- /dev/null
+++ b/packages/chat/telegram/test/gfm.ts
@@ -0,0 +1,75 @@
+import type * as Mdast from "mdast"
+import { fromMarkdown } from "mdast-util-from-markdown"
+import { gfmFromMarkdown } from "mdast-util-gfm"
+import { gfm } from "micromark-extension-gfm"
+
+/** What a GFM parse of rendered Markdown holds that the renderer promises it never will. */
+export interface Findings {
+  readonly html: ReadonlyArray
+  readonly images: number
+  readonly links: ReadonlyArray
+  readonly maxDepth: number
+  readonly maxColumns: number
+  readonly blocks: number
+  /** Text that reached the parser with an unescaped `|`, `$` or `=`, Telegram's spoiler, math and mark syntax. */
+  readonly active: ReadonlyArray
+}
+
+const nesting = new Set(["blockquote", "listItem", "emphasis", "strong", "delete"])
+const blockTypes = new Set([
+  "paragraph",
+  "heading",
+  "code",
+  "thematicBreak",
+  "listItem",
+  "tableRow",
+  "blockquote",
+  "html"
+])
+
+export const parse = (markdown: string): Mdast.Root =>
+  fromMarkdown(markdown, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] })
+
+export const inspect = (markdown: string): Findings => {
+  const html: Array = []
+  const links: Array = []
+  let images = 0
+  let maxDepth = 0
+  let maxColumns = 0
+  let blocks = 0
+  const active: Array = []
+  const visit = (node: Mdast.Nodes, depth: number) => {
+    const d = nesting.has(node.type) ? depth + 1 : depth
+    maxDepth = Math.max(maxDepth, d)
+    if (blockTypes.has(node.type)) blocks++
+    switch (node.type) {
+      case "text": {
+        if (node.position === undefined) break
+        const source = markdown.slice(node.position.start.offset, node.position.end.offset)
+        if (/(?:^|[^\\])(?:\\\\)*[|$=]/.test(source)) active.push(source)
+        break
+      }
+      case "html":
+        html.push(node.value)
+        break
+      case "image":
+      case "imageReference":
+        images++
+        break
+      case "link":
+        links.push(node.url)
+        // An autolink's text is its URL, which no parser reads as syntax.
+        if (markdown[node.position?.start.offset ?? -1] === "<") return
+        break
+      case "definition":
+        links.push(node.url)
+        break
+      case "table":
+        for (const row of node.children) maxColumns = Math.max(maxColumns, row.children.length)
+        break
+    }
+    if ("children" in node) { for (const child of node.children) visit(child as Mdast.Nodes, d) }
+  }
+  visit(parse(markdown), 0)
+  return { html, images, links, maxDepth, maxColumns, blocks, active }
+}
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 3794c13531b..9de7ac6602b 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -1,15 +1,23 @@
 /**
  * T3 and T4: the rendered Markdown stays within what `measure` charged and
  * carries no raw HTML, image, math, spoiler or link outside http, https and
- * mailto. The corpus is checked by hand against GFM; live check 2 confirms
- * Telegram's parser agrees.
+ * mailto. A GFM parser reads the output; live check 2 confirms Telegram's
+ * parser agrees with it.
  */
-import { measure, messageLength, render, reservation } from "@effect/chat-telegram/internal/markdown"
+import {
+  maxColumns,
+  maxDepth,
+  measure,
+  messageLength,
+  render,
+  reservation
+} from "@effect/chat-telegram/internal/markdown"
 import { assert, describe, it } from "@effect/vitest"
 import * as fc from "fast-check"
+import { inspect } from "./gfm.ts"
 
 const cases: ReadonlyArray = [
-  ["hi  ", "\\hi\\  \\"],
+  ["hi  ", "<b>hi</b>  <javascript:alert(1)>"],
   ["![a](https://e.com/a.png) ![b][r]", "\\![a](https://e.com/a.png) \\![b][r]"],
   ["[me](tg://user?id=1) [ok](tg://user?id=2)", "[me\\](tg://user?id\\=1) [ok](tg://user?id\\=2)"],
   [
@@ -25,6 +33,50 @@ const cases: ReadonlyArray = [
 
 const bytes = (s: string) => new TextEncoder().encode(s).length
 
+const mentions = new Set(["2"])
+
+/** Fails with what a GFM parse of `render(input)` finds that the renderer promises it never holds. */
+const assertInert = (input: string) => {
+  const out = render(input, { mentions })
+  const found = inspect(out)
+  const context = JSON.stringify(input) + " rendered " + JSON.stringify(out)
+  assert.deepStrictEqual(found.html, [], context)
+  assert.strictEqual(found.images, 0, context)
+  assert.deepStrictEqual(
+    found.links.filter((url) => !/^(?:https?:\/\/|mailto:)/i.test(url) && url !== "tg://user?id=2"),
+    [],
+    context
+  )
+  assert.deepStrictEqual(found.active, [], context)
+  assert.isAtMost(found.maxDepth, maxDepth, context)
+  assert.isAtMost(found.maxColumns, maxColumns, context)
+}
+
+const hostile = fc.string({
+  unit: fc.constantFrom(
+    ..."<>$=|![]()*_~`#-+.:/\\&;\n \t\"'0a",
+    "~~~",
+    "```",
+    " ~~~",
+    "- ",
+    "> ",
+    "1. ",
+    "https://e.com",
+    "www.e.co",
+    "x@e.co",
+    "tg://user?id=1",
+    "",
+    "](",
+    "[^",
+    "[^a]: ",
+    "|---|",
+    "\\]",
+    "\\<",
+    "\\`"
+  ),
+  maxLength: 60
+})
+
 const markdown = fc.string({
   unit: fc.oneof(
     fc.constantFrom(
@@ -47,6 +99,26 @@ describe("render", () => {
     for (const [input, expected] of cases) assert.strictEqual(render(input, { mentions: new Set(["2"]) }), expected)
   })
 
+  it("leaves a GFM parser no HTML, image, foreign link, math, spoiler or excess nesting", () => {
+    for (
+      const input of [
+        // a backtick in a link title is not a code span
+        "[x](https://e.com \"`\") Click `",
+        "[x](https://e.com \"`\") ![i](https://e.com/i.png) [ping](tg://user?id=123) `",
+        // a fence may be indented up to three spaces
+        " ~~~\nx\n~~~\n[ping](tg://user?id=123) ",
+        // each delimiter of a run is a level
+        "_".repeat(36) + "x" + "_".repeat(36),
+        // a heading ends a table
+        "| a | b |\n|---|---|\n# heading\n||secret||",
+        // a backslash in a bare URL escapes nothing
+        "https://e.com\\ ](https://e.com\\ )",
+        "[^]: [^a]: x\n="
+      ]
+    ) assertInert(input)
+    fc.assert(fc.property(hostile, (input) => assertInert(input)), { numRuns: 2000 })
+  })
+
   it("escapes the pipes of a table wider than 20 columns", () => {
     const row = (cell: string) => "|" + ` ${cell} |`.repeat(21)
     const out = render(row("c") + "\n" + row("-"))
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index cd32f8defa1..4f921417ebb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -371,9 +371,21 @@ importers:
 
   packages/chat/telegram:
     devDependencies:
+      '@types/mdast':
+        specifier: ^4.0.4
+        version: 4.0.4
       effect:
         specifier: workspace:^
         version: link:../../effect
+      mdast-util-from-markdown:
+        specifier: ^2.0.2
+        version: 2.1.0(supports-color@10.2.2)
+      mdast-util-gfm:
+        specifier: ^3.1.0
+        version: 3.1.0(supports-color@10.2.2)
+      micromark-extension-gfm:
+        specifier: ^3.0.0
+        version: 3.0.0
 
   packages/chat/whatsapp:
     devDependencies:
@@ -4190,6 +4202,9 @@ packages:
   '@types/connect@3.4.38':
     resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==}
 
+  '@types/debug@4.1.13':
+    resolution: {integrity: sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw==}
+
   '@types/deep-eql@4.0.2':
     resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==}
 
@@ -4238,9 +4253,15 @@ packages:
   '@types/jsesc@2.5.1':
     resolution: {integrity: sha512-9VN+6yxLOPLOav+7PwjZbxiID2bVaeq0ED4qSQmdQTdjnXJSaCVKTR58t15oqH1H5t8Ng2ZX1SabJVoN9Q34bw==}
 
+  '@types/mdast@4.0.4':
+    resolution: {integrity: sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==}
+
   '@types/mime@1.3.5':
     resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==}
 
+  '@types/ms@2.1.0':
+    resolution: {integrity: sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==}
+
   '@types/node@26.6.6':
     resolution: {integrity: sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==}
 
@@ -4297,6 +4318,9 @@ packages:
   '@types/swagger2openapi@7.0.4':
     resolution: {integrity: sha512-ffMqzciTDihOKH4Q//9Ond1yb5JP1P5FC/aFPsLK4blea1Fwk2aYctiNCkAh5etDYFswFXS+5LV/vuGkf+PU6A==}
 
+  '@types/unist@3.0.3':
+    resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==}
+
   '@types/whatwg-mimetype@3.0.2':
     resolution: {integrity: sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==}
 
@@ -4865,6 +4889,9 @@ packages:
   capnweb@0.12.0:
     resolution: {integrity: sha512-jgZ/LMtMVTi+RVlooIslH78Gg23XbDTdvcLghWx3oz17D6u5GuJARt+uhZk/wcTo+f81eeabfnow4d3zLBj+JQ==}
 
+  ccount@2.0.1:
+    resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==}
+
   chai@6.3.0:
     resolution: {integrity: sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==}
     engines: {node: '>=18'}
@@ -4880,6 +4907,9 @@ packages:
   change-case@5.4.4:
     resolution: {integrity: sha512-HRQyTk2/YPEkt9TnUPbOpr64Uw3KOicFWPVBb+xiHvd6eBx/qPr9xqfBFDT8P2vWsvvz4jbEkfDe71W3VyNu2w==}
 
+  character-entities@2.0.2:
+    resolution: {integrity: sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ==}
+
   chokidar@5.0.0:
     resolution: {integrity: sha512-TQMmc3w+5AxjpL8iIiwebF73dRDF4fBIieAqGn9RGCWaEVwQ6Fb2cGe31Yns0RRIzii5goJ1Y7xbMwo1TxMplw==}
     engines: {node: '>= 20.19.0'}
@@ -5050,6 +5080,9 @@ packages:
   decimal.js@10.6.0:
     resolution: {integrity: sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==}
 
+  decode-named-character-reference@1.3.0:
+    resolution: {integrity: sha512-GtpQYB283KrPp6nRw50q3U9/VfOutZOe103qlN7BPP6Ad27xYnOIWv4lPzo8HCAL+mMZofJ9KEy30fq6MfaK6Q==}
+
   deep-extend@0.6.0:
     resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==}
     engines: {node: '>=4.0.0'}
@@ -5141,6 +5174,9 @@ packages:
     peerDependencies:
       typescript: ^5.4.4 || ^6.0.2
 
+  devlop@1.1.0:
+    resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==}
+
   dfx@1.1.1:
     resolution: {integrity: sha512-g22vKD6+WtOX6a6PoUjZoryJGp3Ut//ve6jjvEFQ8ONB0zNRkDGdf4IVitNmzZcW8G9Ewsr1FR47A98UWWbmIA==}
     peerDependencies:
@@ -5270,6 +5306,10 @@ packages:
     resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==}
     engines: {node: '>=10'}
 
+  escape-string-regexp@5.0.0:
+    resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==}
+    engines: {node: '>=12'}
+
   escodegen@2.1.0:
     resolution: {integrity: sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==}
     engines: {node: '>=6.0'}
@@ -6030,6 +6070,9 @@ packages:
   long@5.3.2:
     resolution: {integrity: sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==}
 
+  longest-streak@3.1.0:
+    resolution: {integrity: sha512-9Ri+o0JYgehTaVBBDoMqIl8GXtbWg711O3srftcHhZ0dqnETqLaoIK0x17fUw9rFSlK/0NlsKe0Ahhyl5pXE2g==}
+
   loose-envify@1.4.0:
     resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
     hasBin: true
@@ -6086,12 +6129,48 @@ packages:
     resolution: {integrity: sha512-TurLymbyLyo+kAUUAV9ggR9EPcDjP/ctlv9QAFiqUH7c+t6FlsbivPo9OKTU8xdOx9oNd2drW/Fi5RRElQbUqA==}
     engines: {node: '>=0.10.0'}
 
+  markdown-table@3.1.0:
+    resolution: {integrity: sha512-xpeSCdM+B+6P3ncfgaB7FoDbtJ30xAe6Z18TGT7AgXJsHqCElCICZovQqdRMm7kHgpTyYv36EupqewoFFSB8vw==}
+
   marky@1.3.0:
     resolution: {integrity: sha512-ocnPZQLNpvbedwTy9kNrQEsknEfgvcLMvOtz3sFeWApDq1MXH1TqkCIx58xlpESsfwQOnuBO9beyQuNGzVvuhQ==}
 
   math-random@1.0.4:
     resolution: {integrity: sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==}
 
+  mdast-util-find-and-replace@3.0.4:
+    resolution: {integrity: sha512-z4B5c6jrnJ1ltOQemhWYPBSAo6y42Z8Gt2yEgfgNTMcLSU59B8bfj8Z8AnAlJrBGLnqkdAUZ7jdDEqQw3KuipQ==}
+
+  mdast-util-from-markdown@2.1.0:
+    resolution: {integrity: sha512-KRLgmPaP2H1ul2bpoJkOS+9pAcDAAj9Nu1mqLnh8NLeJG5tlvj42TH80PIGBpROWlRXLk0lDrWNuZCFy/tsB4A==}
+
+  mdast-util-gfm-autolink-literal@2.1.0:
+    resolution: {integrity: sha512-Jx6QSK8wDo558Bcf7q+1pe0v81g2PVs09Hlvu9xJHmCFRF3sAPW7vXFVIAwBncs3sde92WbsVqNxwdqViA2XnQ==}
+
+  mdast-util-gfm-footnote@2.1.0:
+    resolution: {integrity: sha512-sqpDWlsHn7Ac9GNZQMeUzPQSMzR6Wv0WKRNvQRg0KqHh02fpTz69Qc1QSseNX29bhz1ROIyNyxExfawVKTm1GQ==}
+
+  mdast-util-gfm-strikethrough@2.0.1:
+    resolution: {integrity: sha512-OuJHqvr455pwu2OaOrir7dbzqs4jlWKOtlu9L6GjcIjjQwNyw02VntQsr/Ek6/A13vgnXfUhBekWRUP1OkNivw==}
+
+  mdast-util-gfm-table@2.0.1:
+    resolution: {integrity: sha512-fiIjPrAy4kz68/eFbPHhsiWDGHhqUSVoU1XsfLM5DsEPXw7MxgiVVyulUggFRckVWeT1KXQXkg5vm3kv4oMSOA==}
+
+  mdast-util-gfm-task-list-item@2.0.1:
+    resolution: {integrity: sha512-jXVO1hvB2hs82g1esi7I9nIJDqiijbQLIyH2jDUb5s7jIAZMr/79h0VHSq7XHKTqpLARRm+DDNjduB7S9+6XZA==}
+
+  mdast-util-gfm@3.1.0:
+    resolution: {integrity: sha512-0ulfdQOM3ysHhCJ1p06l0b0VKlhU0wuQs3thxZQagjcjPrlFRqY215uZGHHJan9GEAXd9MbfPjFJz+qMkVR6zQ==}
+
+  mdast-util-phrasing@4.1.0:
+    resolution: {integrity: sha512-TqICwyvJJpBwvGAMZjj4J2n0X8QWp21b9l0o7eXyVJ25YNWYbJDVIyD1bZXE6WtV6RmKJVYmQAKWa0zWOABz2w==}
+
+  mdast-util-to-markdown@2.2.3:
+    resolution: {integrity: sha512-dImdB6VZRMRac1SwAW6o1c0ESk/7pFFAMCMuKM+9v7LpTSthMM5nzXpqKw4Mjo66aXVKhNkyrP4bMB9MurPyWg==}
+
+  mdast-util-to-string@4.0.0:
+    resolution: {integrity: sha512-0H44vDimn51F0YwvxSJSm0eCDOJTRlmN0R1yBh4HLj9wiV1Dn0QoXGbvFAWj2hSItVTlCmBF1hqKlIyUBVFLPg==}
+
   mdn-data@2.27.1:
     resolution: {integrity: sha512-9Yubnt3e8A0OKwxYSXyhLymGW4sCufcLG6VdiDdUGVkPhpqLxlvP5vl1983gQjJl3tqbrM731mjaZaP68AgosQ==}
 
@@ -6159,6 +6238,93 @@ packages:
     engines: {node: '>=20.19.4'}
     hasBin: true
 
+  micromark-core-commonmark@2.0.4:
+    resolution: {integrity: sha512-wxEeE8v8XVvOrxn1TZj74qYhAtTQsSqufHVS3uNVyT1MupXxhyaHk8/9xDNPh9BmL77QNDgWTkZ3RsYHB2ry7w==}
+
+  micromark-extension-gfm-autolink-literal@2.1.0:
+    resolution: {integrity: sha512-oOg7knzhicgQ3t4QCjCWgTmfNhvQbDDnJeVu9v81r7NltNCVmhPy1fJRX27pISafdjL+SVc4d3l48Gb6pbRypw==}
+
+  micromark-extension-gfm-footnote@2.1.0:
+    resolution: {integrity: sha512-/yPhxI1ntnDNsiHtzLKYnE3vf9JZ6cAisqVDauhp4CEHxlb4uoOTxOCJ+9s51bIB8U1N1FJ1RXOKTIlD5B/gqw==}
+
+  micromark-extension-gfm-strikethrough@2.1.0:
+    resolution: {integrity: sha512-ADVjpOOkjz1hhkZLlBiYA9cR2Anf8F4HqZUO6e5eDcPQd0Txw5fxLzzxnEkSkfnD0wziSGiv7sYhk/ktvbf1uw==}
+
+  micromark-extension-gfm-table@2.1.2:
+    resolution: {integrity: sha512-pRzm4kDTu0MjlmBkxmS9yYhw60nncfcEwu9NNdPFSQEFXS95ZKyIIyTSHu/o3ReBUrLKYEq+7YaXCRn/bPB4MA==}
+
+  micromark-extension-gfm-tagfilter@2.0.0:
+    resolution: {integrity: sha512-xHlTOmuCSotIA8TW1mDIM6X2O1SiX5P9IuDtqGonFhEK0qgRI4yeC6vMxEV2dgyr2TiD+2PQ10o+cOhdVAcwfg==}
+
+  micromark-extension-gfm-task-list-item@2.1.0:
+    resolution: {integrity: sha512-qIBZhqxqI6fjLDYFTBIa4eivDMnP+OZqsNwmQ3xNLE4Cxwc+zfQEfbs6tzAo2Hjq+bh6q5F+Z8/cksrLFYWQQw==}
+
+  micromark-extension-gfm@3.0.0:
+    resolution: {integrity: sha512-vsKArQsicm7t0z2GugkCKtZehqUm31oeGBV/KVSorWSy8ZlNAv7ytjFhvaryUiCUJYqs+NoE6AFhpQvBTM6Q4w==}
+
+  micromark-factory-destination@2.0.1:
+    resolution: {integrity: sha512-Xe6rDdJlkmbFRExpTOmRj9N3MaWmbAgdpSrBQvCFqhezUn4AHqJHbaEnfbVYYiexVSs//tqOdY/DxhjdCiJnIA==}
+
+  micromark-factory-label@2.0.1:
+    resolution: {integrity: sha512-VFMekyQExqIW7xIChcXn4ok29YE3rnuyveW3wZQWWqF4Nv9Wk5rgJ99KzPvHjkmPXF93FXIbBp6YdW3t71/7Vg==}
+
+  micromark-factory-space@2.1.0:
+    resolution: {integrity: sha512-fS8hnLIjnjvdQIj39Geug8wWsR0HrYZ43KShKxNfwT7t2LOHo/LbWZEzEaSOjwtjdCsjoE6syHhonEzW0zv0+Q==}
+
+  micromark-factory-title@2.0.1:
+    resolution: {integrity: sha512-5bZ+3CjhAd9eChYTHsjy6TGxpOFSKgKKJPJxr293jTbfry2KDoWkhBb6TcPVB4NmzaPhMs1Frm9AZH7OD4Cjzw==}
+
+  micromark-factory-whitespace@2.0.1:
+    resolution: {integrity: sha512-Ob0nuZ3PKt/n0hORHyvoD9uZhr+Za8sFoP+OnMcnWK5lngSzALgQYKMr9RJVOWLqQYuyn6ulqGWSXdwf6F80lQ==}
+
+  micromark-util-character@2.1.1:
+    resolution: {integrity: sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==}
+
+  micromark-util-chunked@2.0.1:
+    resolution: {integrity: sha512-QUNFEOPELfmvv+4xiNg2sRYeS/P84pTW0TCgP5zc9FpXetHY0ab7SxKyAQCNCc1eK0459uoLI1y5oO5Vc1dbhA==}
+
+  micromark-util-classify-character@2.0.1:
+    resolution: {integrity: sha512-K0kHzM6afW/MbeWYWLjoHQv1sgg2Q9EccHEDzSkxiP/EaagNzCm7T/WMKZ3rjMbvIpvBiZgwR3dKMygtA4mG1Q==}
+
+  micromark-util-combine-extensions@2.0.1:
+    resolution: {integrity: sha512-OnAnH8Ujmy59JcyZw8JSbK9cGpdVY44NKgSM7E9Eh7DiLS2E9RNQf0dONaGDzEG9yjEl5hcqeIsj4hfRkLH/Bg==}
+
+  micromark-util-decode-numeric-character-reference@2.0.2:
+    resolution: {integrity: sha512-ccUbYk6CwVdkmCQMyr64dXz42EfHGkPQlBj5p7YVGzq8I7CtjXZJrubAYezf7Rp+bjPseiROqe7G6foFd+lEuw==}
+
+  micromark-util-decode-string@2.0.1:
+    resolution: {integrity: sha512-nDV/77Fj6eH1ynwscYTOsbK7rR//Uj0bZXBwJZRfaLEJ1iGBR6kIfNmlNqaqJf649EP0F3NWNdeJi03elllNUQ==}
+
+  micromark-util-edit-map@1.0.0:
+    resolution: {integrity: sha512-Pa2ljlsEL6sVwFaYeyrOLSYbQt73JvGbPOYFq+9AElXiSnfI5Q4465RRZ1sHv7lDjDOnGRDDaqPXqClqWK/q1Q==}
+
+  micromark-util-encode@2.0.1:
+    resolution: {integrity: sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==}
+
+  micromark-util-html-tag-name@2.0.1:
+    resolution: {integrity: sha512-2cNEiYDhCWKI+Gs9T0Tiysk136SnR13hhO8yW6BGNyhOC4qYFnwF1nKfD3HFAIXA5c45RrIG1ub11GiXeYd1xA==}
+
+  micromark-util-normalize-identifier@2.0.1:
+    resolution: {integrity: sha512-sxPqmo70LyARJs0w2UclACPUUEqltCkJ6PhKdMIDuJ3gSf/Q+/GIe3WKl0Ijb/GyH9lOpUkRAO2wp0GVkLvS9Q==}
+
+  micromark-util-resolve-all@2.0.1:
+    resolution: {integrity: sha512-VdQyxFWFT2/FGJgwQnJYbe1jjQoNTS4RjglmSjTUlpUMa95Htx9NHeYW4rGDJzbjvCsl9eLjMQwGeElsqmzcHg==}
+
+  micromark-util-sanitize-uri@2.0.1:
+    resolution: {integrity: sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==}
+
+  micromark-util-subtokenize@2.1.0:
+    resolution: {integrity: sha512-XQLu552iSctvnEcgXw6+Sx75GflAPNED1qx7eBJ+wydBb2KCbRZe+NwvIEEMM83uml1+2WSXpBAcp9IUCgCYWA==}
+
+  micromark-util-symbol@2.0.1:
+    resolution: {integrity: sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==}
+
+  micromark-util-types@2.0.3:
+    resolution: {integrity: sha512-oxB2Ik03hI0gv+VNn9tnh1t1YEe9MDPptViAEgfdf3YQHsn0pzGTgCdlSCJXcwhqm8phaEuM7zeEu3QQzVBrPg==}
+
+  micromark@4.0.3:
+    resolution: {integrity: sha512-oGYfQzHSG5dOMovQcJ3fyTmZlWAWpi0XA0sJwJs+i6OT88o1+Jtw/8z0CmdowSLxGhhFK89rQ/oXph/wN02PNw==}
+
   micromatch@4.0.8:
     resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==}
     engines: {node: '>=8.6'}
@@ -7418,6 +7584,18 @@ packages:
   unenv@2.0.0-rc.24:
     resolution: {integrity: sha512-i7qRCmY42zmCwnYlh9H2SvLEypEFGye5iRmEMKjcGi7zk9UquigRjFtTLz0TYqr0ZGLZhaMHl/foy1bZR+Cwlw==}
 
+  unist-util-is@6.0.1:
+    resolution: {integrity: sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==}
+
+  unist-util-stringify-position@4.0.0:
+    resolution: {integrity: sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==}
+
+  unist-util-visit-parents@6.1.0:
+    resolution: {integrity: sha512-vKXxz6O38sKDj1mtx/k2cWvkkFBuYGx6uGrlzBkVeWCRF/F8sdI0j3Wbkz/5rVNRRuVc8UrgRdbCxNhmYXgP3w==}
+
+  unist-util-visit@5.2.0:
+    resolution: {integrity: sha512-fpsYs/VVoZxfGY9/j3FQpZmN8wdLJaV1Pt38AaJNZu9uKIHcFU3halCdBveEq1HGKO1OEfJY65w1zvoFV1b3qQ==}
+
   unpipe@1.0.0:
     resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
     engines: {node: '>= 0.8'}
@@ -7764,6 +7942,9 @@ packages:
   zod@4.6.7:
     resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==}
 
+  zwitch@2.0.4:
+    resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
+
 snapshots:
 
   '@adobe/css-tools@4.5.0': {}
@@ -10422,6 +10603,10 @@ snapshots:
       '@types/node': 26.6.6
     optional: true
 
+  '@types/debug@4.1.13':
+    dependencies:
+      '@types/ms': 2.1.0
+
   '@types/deep-eql@4.0.2': {}
 
   '@types/deno@2.7.0': {}
@@ -10483,9 +10668,15 @@ snapshots:
 
   '@types/jsesc@2.5.1': {}
 
+  '@types/mdast@4.0.4':
+    dependencies:
+      '@types/unist': 3.0.3
+
   '@types/mime@1.3.5':
     optional: true
 
+  '@types/ms@2.1.0': {}
+
   '@types/node@26.6.6':
     dependencies:
       undici-types: 8.9.0
@@ -10556,6 +10747,8 @@ snapshots:
       '@types/node': 26.6.6
       openapi-types: 12.1.3
 
+  '@types/unist@3.0.3': {}
+
   '@types/whatwg-mimetype@3.0.2': {}
 
   '@types/ws@8.18.2':
@@ -11106,6 +11299,8 @@ snapshots:
 
   capnweb@0.12.0: {}
 
+  ccount@2.0.1: {}
+
   chai@6.3.0: {}
 
   chalk@4.1.2:
@@ -11117,6 +11312,8 @@ snapshots:
 
   change-case@5.4.4: {}
 
+  character-entities@2.0.2: {}
+
   chokidar@5.0.0:
     dependencies:
       readdirp: 5.1.1
@@ -11286,6 +11483,10 @@ snapshots:
 
   decimal.js@10.6.0: {}
 
+  decode-named-character-reference@1.3.0:
+    dependencies:
+      character-entities: 2.0.2
+
   deep-extend@0.6.0: {}
 
   deepmerge@4.3.1: {}
@@ -11379,6 +11580,10 @@ snapshots:
     transitivePeerDependencies:
       - supports-color
 
+  devlop@1.1.0:
+    dependencies:
+      dequal: 2.0.3
+
   dfx@1.1.1(effect@packages+effect):
     dependencies:
       discord-api-types: 0.38.58
@@ -11535,6 +11740,8 @@ snapshots:
 
   escape-string-regexp@4.0.0: {}
 
+  escape-string-regexp@5.0.0: {}
+
   escodegen@2.1.0:
     dependencies:
       esprima: 4.0.1
@@ -12319,6 +12526,8 @@ snapshots:
 
   long@5.3.2: {}
 
+  longest-streak@3.1.0: {}
+
   loose-envify@1.4.0:
     dependencies:
       js-tokens: 4.0.0
@@ -12383,10 +12592,118 @@ snapshots:
 
   markdown-link@0.1.1: {}
 
+  markdown-table@3.1.0: {}
+
   marky@1.3.0: {}
 
   math-random@1.0.4: {}
 
+  mdast-util-find-and-replace@3.0.4:
+    dependencies:
+      '@types/mdast': 4.0.4
+      escape-string-regexp: 5.0.0
+      unist-util-is: 6.0.1
+      unist-util-visit-parents: 6.1.0
+
+  mdast-util-from-markdown@2.1.0(supports-color@10.2.2):
+    dependencies:
+      '@types/mdast': 4.0.4
+      '@types/unist': 3.0.3
+      decode-named-character-reference: 1.3.0
+      devlop: 1.1.0
+      mdast-util-to-string: 4.0.0
+      micromark: 4.0.3(supports-color@10.2.2)
+      micromark-util-decode-numeric-character-reference: 2.0.2
+      micromark-util-decode-string: 2.0.1
+      micromark-util-normalize-identifier: 2.0.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+      unist-util-stringify-position: 4.0.0
+    transitivePeerDependencies:
+      - supports-color
+
+  mdast-util-gfm-autolink-literal@2.1.0:
+    dependencies:
+      '@types/mdast': 4.0.4
+      ccount: 2.0.1
+      devlop: 1.1.0
+      mdast-util-find-and-replace: 3.0.4
+      micromark-util-character: 2.1.1
+
+  mdast-util-gfm-footnote@2.1.0(supports-color@10.2.2):
+    dependencies:
+      '@types/mdast': 4.0.4
+      devlop: 1.1.0
+      mdast-util-from-markdown: 2.1.0(supports-color@10.2.2)
+      mdast-util-to-markdown: 2.2.3
+      micromark-util-normalize-identifier: 2.0.1
+    transitivePeerDependencies:
+      - supports-color
+
+  mdast-util-gfm-strikethrough@2.0.1(supports-color@10.2.2):
+    dependencies:
+      '@types/mdast': 4.0.4
+      mdast-util-from-markdown: 2.1.0(supports-color@10.2.2)
+      mdast-util-to-markdown: 2.2.3
+    transitivePeerDependencies:
+      - supports-color
+
+  mdast-util-gfm-table@2.0.1(supports-color@10.2.2):
+    dependencies:
+      '@types/mdast': 4.0.4
+      devlop: 1.1.0
+      markdown-table: 3.1.0
+      mdast-util-from-markdown: 2.1.0(supports-color@10.2.2)
+      mdast-util-to-markdown: 2.2.3
+      mdast-util-to-string: 4.0.0
+      unist-util-visit: 5.2.0
+    transitivePeerDependencies:
+      - supports-color
+
+  mdast-util-gfm-task-list-item@2.0.1(supports-color@10.2.2):
+    dependencies:
+      '@types/mdast': 4.0.4
+      devlop: 1.1.0
+      mdast-util-from-markdown: 2.1.0(supports-color@10.2.2)
+      mdast-util-to-markdown: 2.2.3
+    transitivePeerDependencies:
+      - supports-color
+
+  mdast-util-gfm@3.1.0(supports-color@10.2.2):
+    dependencies:
+      mdast-util-from-markdown: 2.1.0(supports-color@10.2.2)
+      mdast-util-gfm-autolink-literal: 2.1.0
+      mdast-util-gfm-footnote: 2.1.0(supports-color@10.2.2)
+      mdast-util-gfm-strikethrough: 2.0.1(supports-color@10.2.2)
+      mdast-util-gfm-table: 2.0.1(supports-color@10.2.2)
+      mdast-util-gfm-task-list-item: 2.0.1(supports-color@10.2.2)
+      mdast-util-to-markdown: 2.2.3
+    transitivePeerDependencies:
+      - supports-color
+
+  mdast-util-phrasing@4.1.0:
+    dependencies:
+      '@types/mdast': 4.0.4
+      unist-util-is: 6.0.1
+
+  mdast-util-to-markdown@2.2.3:
+    dependencies:
+      '@types/mdast': 4.0.4
+      '@types/unist': 3.0.3
+      longest-streak: 3.1.0
+      mdast-util-phrasing: 4.1.0
+      mdast-util-to-string: 4.0.0
+      micromark-util-character: 2.1.1
+      micromark-util-classify-character: 2.0.1
+      micromark-util-decode-string: 2.0.1
+      micromark-util-html-tag-name: 2.0.1
+      unist-util-visit: 5.2.0
+      zwitch: 2.0.4
+
+  mdast-util-to-string@4.0.0:
+    dependencies:
+      '@types/mdast': 4.0.4
+
   mdn-data@2.27.1: {}
 
   memoize-one@5.2.1: {}
@@ -12567,6 +12884,203 @@ snapshots:
       - supports-color
       - utf-8-validate
 
+  micromark-core-commonmark@2.0.4:
+    dependencies:
+      decode-named-character-reference: 1.3.0
+      devlop: 1.1.0
+      micromark-factory-destination: 2.0.1
+      micromark-factory-label: 2.0.1
+      micromark-factory-space: 2.1.0
+      micromark-factory-title: 2.0.1
+      micromark-factory-whitespace: 2.0.1
+      micromark-util-character: 2.1.1
+      micromark-util-chunked: 2.0.1
+      micromark-util-classify-character: 2.0.1
+      micromark-util-edit-map: 1.0.0
+      micromark-util-html-tag-name: 2.0.1
+      micromark-util-normalize-identifier: 2.0.1
+      micromark-util-resolve-all: 2.0.1
+      micromark-util-subtokenize: 2.1.0
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-extension-gfm-autolink-literal@2.1.0:
+    dependencies:
+      micromark-util-character: 2.1.1
+      micromark-util-sanitize-uri: 2.0.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-extension-gfm-footnote@2.1.0:
+    dependencies:
+      devlop: 1.1.0
+      micromark-core-commonmark: 2.0.4
+      micromark-factory-space: 2.1.0
+      micromark-util-character: 2.1.1
+      micromark-util-normalize-identifier: 2.0.1
+      micromark-util-sanitize-uri: 2.0.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-extension-gfm-strikethrough@2.1.0:
+    dependencies:
+      devlop: 1.1.0
+      micromark-util-chunked: 2.0.1
+      micromark-util-classify-character: 2.0.1
+      micromark-util-resolve-all: 2.0.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-extension-gfm-table@2.1.2:
+    dependencies:
+      devlop: 1.1.0
+      micromark-factory-space: 2.1.0
+      micromark-util-character: 2.1.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-extension-gfm-tagfilter@2.0.0:
+    dependencies:
+      micromark-util-types: 2.0.3
+
+  micromark-extension-gfm-task-list-item@2.1.0:
+    dependencies:
+      devlop: 1.1.0
+      micromark-factory-space: 2.1.0
+      micromark-util-character: 2.1.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-extension-gfm@3.0.0:
+    dependencies:
+      micromark-extension-gfm-autolink-literal: 2.1.0
+      micromark-extension-gfm-footnote: 2.1.0
+      micromark-extension-gfm-strikethrough: 2.1.0
+      micromark-extension-gfm-table: 2.1.2
+      micromark-extension-gfm-tagfilter: 2.0.0
+      micromark-extension-gfm-task-list-item: 2.1.0
+      micromark-util-combine-extensions: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-factory-destination@2.0.1:
+    dependencies:
+      micromark-util-character: 2.1.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-factory-label@2.0.1:
+    dependencies:
+      devlop: 1.1.0
+      micromark-util-character: 2.1.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-factory-space@2.1.0:
+    dependencies:
+      micromark-util-character: 2.1.1
+      micromark-util-types: 2.0.3
+
+  micromark-factory-title@2.0.1:
+    dependencies:
+      micromark-factory-space: 2.1.0
+      micromark-util-character: 2.1.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-factory-whitespace@2.0.1:
+    dependencies:
+      micromark-factory-space: 2.1.0
+      micromark-util-character: 2.1.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-util-character@2.1.1:
+    dependencies:
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-util-chunked@2.0.1:
+    dependencies:
+      micromark-util-symbol: 2.0.1
+
+  micromark-util-classify-character@2.0.1:
+    dependencies:
+      micromark-util-character: 2.1.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-util-combine-extensions@2.0.1:
+    dependencies:
+      micromark-util-chunked: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-util-decode-numeric-character-reference@2.0.2:
+    dependencies:
+      micromark-util-symbol: 2.0.1
+
+  micromark-util-decode-string@2.0.1:
+    dependencies:
+      decode-named-character-reference: 1.3.0
+      micromark-util-character: 2.1.1
+      micromark-util-decode-numeric-character-reference: 2.0.2
+      micromark-util-symbol: 2.0.1
+
+  micromark-util-edit-map@1.0.0:
+    dependencies:
+      micromark-util-types: 2.0.3
+
+  micromark-util-encode@2.0.1: {}
+
+  micromark-util-html-tag-name@2.0.1: {}
+
+  micromark-util-normalize-identifier@2.0.1:
+    dependencies:
+      micromark-util-symbol: 2.0.1
+
+  micromark-util-resolve-all@2.0.1:
+    dependencies:
+      micromark-util-types: 2.0.3
+
+  micromark-util-sanitize-uri@2.0.1:
+    dependencies:
+      micromark-util-character: 2.1.1
+      micromark-util-encode: 2.0.1
+      micromark-util-symbol: 2.0.1
+
+  micromark-util-subtokenize@2.1.0:
+    dependencies:
+      devlop: 1.1.0
+      micromark-util-chunked: 2.0.1
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+
+  micromark-util-symbol@2.0.1: {}
+
+  micromark-util-types@2.0.3: {}
+
+  micromark@4.0.3(supports-color@10.2.2):
+    dependencies:
+      '@types/debug': 4.1.13
+      debug: 4.4.3(supports-color@10.2.2)
+      decode-named-character-reference: 1.3.0
+      devlop: 1.1.0
+      micromark-core-commonmark: 2.0.4
+      micromark-factory-space: 2.1.0
+      micromark-util-character: 2.1.1
+      micromark-util-chunked: 2.0.1
+      micromark-util-combine-extensions: 2.0.1
+      micromark-util-decode-numeric-character-reference: 2.0.2
+      micromark-util-edit-map: 1.0.0
+      micromark-util-encode: 2.0.1
+      micromark-util-normalize-identifier: 2.0.1
+      micromark-util-resolve-all: 2.0.1
+      micromark-util-sanitize-uri: 2.0.1
+      micromark-util-subtokenize: 2.1.0
+      micromark-util-symbol: 2.0.1
+      micromark-util-types: 2.0.3
+    transitivePeerDependencies:
+      - supports-color
+
   micromatch@4.0.8:
     dependencies:
       braces: 3.0.3
@@ -14046,6 +14560,25 @@ snapshots:
     dependencies:
       pathe: 2.0.3
 
+  unist-util-is@6.0.1:
+    dependencies:
+      '@types/unist': 3.0.3
+
+  unist-util-stringify-position@4.0.0:
+    dependencies:
+      '@types/unist': 3.0.3
+
+  unist-util-visit-parents@6.1.0:
+    dependencies:
+      '@types/unist': 3.0.3
+      unist-util-is: 6.0.1
+
+  unist-util-visit@5.2.0:
+    dependencies:
+      '@types/unist': 3.0.3
+      unist-util-is: 6.0.1
+      unist-util-visit-parents: 6.1.0
+
   unpipe@1.0.0: {}
 
   unplugin-utils@0.2.5:
@@ -14312,3 +14845,5 @@ snapshots:
       readable-stream: 4.8.0
 
   zod@4.6.7: {}
+
+  zwitch@2.0.4: {}

From 360e36edf3f9e4ddc1f2522f82212f55dcd7716e Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 23:03:36 +0000
Subject: [PATCH 76/89] chat-telegram: conservative escaping for ambiguous
 Markdown, deadline tests

- Emphasis: every delimiter run that could open counts toward the depth
  limit and closers are never subtracted; the limit accounts for the
  deepest container in the paragraph, so lazy continuation lines and
  intraword underscores cannot exceed 16 levels.
- Tables keep their pipes only when neither row is indented and the
  header follows a blank line, a heading or the start of the text, so
  footnote text is no longer read as a table.
- A setext `=` is kept only under plain top-level paragraph lines.
- assertInert enforces 500 blocks for in-budget output, with a property
  that fills the budget with block-heavy lines.
- Public receive tests cross the message, click and command deadlines.
---
 packages/chat/telegram/README.md              |   2 +-
 .../chat/telegram/src/internal/markdown.ts    |  94 +++++++----
 .../chat/telegram/test/TelegramChat.test.ts   | 150 ++++++++++++++----
 packages/chat/telegram/test/markdown.test.ts  |  40 ++++-
 4 files changed, 224 insertions(+), 62 deletions(-)

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index 43455cf74f4..a29298a2ef9 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -67,7 +67,7 @@ Updates from business connections, a channel's direct messages and guest mode ar
 
   const App = Webhook.pipe(Layer.provideMerge(RedactSecret))
   ```
-- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`.
+- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading, and past 15 delimiters that could open emphasis in one paragraph the rest are shown as written.
 - A click is dispatched only when its `data` matches a button in Telegram's own copy of the message. That shows the bot put the button there, not that it is still current or that this user may press it.
 
 ## Redelivery
diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
index ac2b14f7bd7..9af5e168159 100644
--- a/packages/chat/telegram/src/internal/markdown.ts
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -101,8 +101,6 @@ export const measure = (markdown: string): number => {
 
 const punctuation = /[!-/:-@[-`{-~]/
 
-const isSpace = (c: string | undefined) => c === undefined || /\s/.test(c)
-
 /** A line that opens a fence: up to three spaces, then three or more backticks or tildes. */
 const fenceOpen = /^( {0,3})(`{3,}|~{3,})(.*)$/
 
@@ -127,7 +125,26 @@ const closes = (line: string, fence: Fence): boolean => {
 const container = /^[ \t>]*(?:[-+*]|\d{1,9}[.)])(?:[ \t]|$)|^[ \t>]*\[\^/
 
 /** A line GFM may read as the start of another block, which ends a table and is no paragraph. */
-const blockStart = /^(?: {0,3}[#>\-*+_~`<=]| {0,3}\d{1,9}[.)]| {4}| {0,3}\t)/
+const blockStart = /^(?: {0,3}[#>\-*+_~`<=[]| {0,3}\d{1,9}[.)]| {4}| {0,3}\t)/
+
+/** Where a line's container markers end, as far as `startsBlock` needs to know. */
+const quotes = /^(?: {0,3}> ?)* {0,3}/
+
+/**
+ * Whether a line starts a block wherever it is, so that it can be no
+ * paragraph's continuation: an ATX heading, or a list item with content
+ * that may interrupt a paragraph (a bullet, or an ordered item numbered 1
+ * or following one of its list). Tabs and other lines say no, which is
+ * safe: the inline count goes on.
+ */
+const startsBlock = (line: string, previousItem: string | undefined): string | undefined | true => {
+  const rest = line.slice(quotes.exec(line)![0].length)
+  if (/^(?:#{1,6}(?: |$)|[-+*] +\S)/.test(rest)) return true
+  const item = /^(\d{1,9})([.)]) +\S/.exec(rest)
+  if (item === null) return undefined
+  const key = line.slice(0, line.length - rest.length) + item[2]
+  return item[1] === "1" || key === previousItem ? key : undefined
+}
 
 const delimiterRow = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*\|?[ \t]*$/
 
@@ -279,9 +296,17 @@ const bareUrl = /^(?:https?:\/\/|www\.)/i
 
 const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>`]*>/
 
-/** The inline nesting carried through one paragraph, one entry per delimiter. */
+/**
+ * What one paragraph may already nest. `open` counts every delimiter that
+ * could open emphasis, and none is taken back for one that may close it:
+ * whether a run closes, and what, depends on flanking rules and links that
+ * this renderer does not follow, and a node needs at least one opener.
+ * `containers` is the most container depth of the paragraph's lines, as a
+ * lazy continuation line stays in containers it does not repeat.
+ */
 interface Inline {
-  readonly stack: Array
+  open: number
+  containers: number
 }
 
 interface LineContext {
@@ -320,8 +345,9 @@ const renderPrefix = (line: string): { readonly text: string; readonly rest: num
 const renderLine = (line: string, context: LineContext): string => {
   const prefix = renderPrefix(line)
   const footnote = /^\[\^[\w-]+\]:/.test(line.slice(prefix.rest))
-  const limit = Math.max(0, maxDepth - 1 - prefix.depth)
-  const stack = context.inline.stack
+  const inline = context.inline
+  inline.containers = Math.max(inline.containers, prefix.depth)
+  const limit = Math.max(0, maxDepth - 1 - inline.containers)
   let out = prefix.text
   let urlEnd = -1
   let i = prefix.rest
@@ -410,23 +436,16 @@ const renderLine = (line: string, context: LineContext): string => {
         let end = i
         while (line[end] === c) end++
         const run = line.slice(i, end)
-        const before = i === 0 ? undefined : line[i - 1]
         const after = line[end]
-        let open = run.length
-        if (!isSpace(before) && stack[stack.length - 1] === c) {
-          while (open > 0 && stack[stack.length - 1] === c) {
-            stack.pop()
-            open--
-          }
-        }
-        // A run of n delimiters can nest n levels: `***a*b*c*` is three.
-        if (open > 0 && !isSpace(after)) {
-          if (stack.length + open > limit) {
+        // A run of n delimiters can open n levels: `***a*b*c*` is three.
+        // One followed by a space or the line's end can't open.
+        if (after !== undefined && after !== " " && after !== "\t") {
+          if (inline.open + run.length > limit) {
             out += run.split("").map((char) => "\\" + char).join("")
             i = end
             continue
           }
-          for (let k = 0; k < open; k++) stack.push(c)
+          inline.open += run.length
         }
         out += run
         i = end
@@ -458,16 +477,21 @@ export interface RenderOptions {
  * - `<` becomes `<` unless it opens an http, https or mailto autolink,
  *   so there is no raw HTML, also after a bare URL, which would take a
  *   backslash with it. `$` and `=` are escaped (math, marks), except `=`
- *   under a paragraph line (a setext heading), as is `|` outside tables
+ *   under a paragraph of plain top-level lines (a setext heading), as is `|` outside tables
  *   (spoilers), and `!` before `[` (images).
  * - A link or reference definition whose destination, decoded as a
  *   Markdown parser and then a URL parser would, is not http, https or
  *   mailto has its `]` escaped, so it is text. A `tg://user` link stays
  *   for an id in `mentions`. A kept link's tail must end on its line and
  *   has its syntax characters escaped.
- * - Container markers and emphasis past 16 levels are escaped, counting a
- *   run of n delimiters as n levels, and a table wider than 20 columns has
- *   its pipes escaped. A table ends at a line that may start another block.
+ * - Container markers and emphasis past 16 levels are escaped. Every
+ *   delimiter that could open emphasis counts as a level until the
+ *   paragraph ends, at a blank line or a line that surely starts a block,
+ *   and a lazy continuation line keeps the paragraph's container depth.
+ * - A table keeps its pipes only when its header is at the start of a line
+ *   after a blank line, a heading or the start of the text, where it can
+ *   be no paragraph's continuation. A table wider than 20 columns has its
+ *   pipes escaped. A table ends at a line that may start another block.
  * - `files` references are added at the end, after closing a fence left
  *   open.
  *
@@ -499,6 +523,10 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
   const tableRows = new Map()
   for (let i = 0; i + 1 < lines.length; i++) {
     if (fenced[i] || fenced[i + 1] || tableRows.has(i) || blockStart.test(lines[i])) continue
+    // Neither row indented, nor the header after a line it could continue.
+    if (/^\s/.test(lines[i]) || /^\s/.test(lines[i + 1])) continue
+    const above = i === 0 ? "" : lines[i - 1]
+    if (above.trim() !== "" && !/^#{1,6}(?: |$)/.test(above)) continue
     if (!delimiterRow.test(lines[i + 1]) || !lines[i + 1].includes("|") || !hasPipe(lines[i])) continue
     const columns = cellCount(lines[i])
     if (columns !== cellCount(lines[i + 1])) continue
@@ -508,14 +536,24 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     for (const row of rows) tableRows.set(row, columns > maxColumns || cellCount(lines[row]) > maxColumns)
     i = end - 1
   }
-  const inline: Inline = { stack: [] }
+  const inline: Inline = { open: 0, containers: 0 }
+  let item: string | undefined
+  // Whether every line since the last blank one is plain text at the top
+  // level: no container, definition, table or other block that a `=` under
+  // it could be the lazy continuation of.
+  let plain = true
   const out = lines.map((line, i) => {
+    const blank = line.trim() === ""
+    const setext = plain && i > 0 && lines[i - 1].trim() !== "" && /^ {0,3}=+[ \t]*$/.test(line)
+    plain = !fenced[i] && (blank || (plain && !/^\s/.test(line) && !blockStart.test(line) && !line.includes("|")))
     if (fenced[i]) return line
-    if (line.trim() === "") inline.stack.length = 0
     const wide = tableRows.get(i)
-    const above = i === 0 ? undefined : lines[i - 1]
-    const setext = /^ {0,3}=+[ \t]*$/.test(line) && above !== undefined && above.trim() !== "" && !fenced[i - 1] &&
-      !tableRows.has(i - 1) && !blockStart.test(above) && !/^ {0,3}\[/.test(above)
+    const starts = blank ? undefined : startsBlock(line, item)
+    item = typeof starts === "string" ? starts : undefined
+    if (blank || starts !== undefined || wide !== undefined) {
+      inline.open = 0
+      inline.containers = 0
+    }
     return renderLine(line, { tableRow: wide !== undefined, widePipes: wide === true, setext, inline, mentions })
   })
   let text = out.join("\n")
diff --git a/packages/chat/telegram/test/TelegramChat.test.ts b/packages/chat/telegram/test/TelegramChat.test.ts
index 284d01cea9f..b1a5fd3efd1 100644
--- a/packages/chat/telegram/test/TelegramChat.test.ts
+++ b/packages/chat/telegram/test/TelegramChat.test.ts
@@ -25,6 +25,7 @@ import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
 import type * as Schema from "effect/Schema"
 import * as Semaphore from "effect/Semaphore"
+import * as TestClock from "effect/testing/TestClock"
 import * as Tracer from "effect/Tracer"
 import {
   apiError,
@@ -381,39 +382,38 @@ describe("acceptance", () => {
     }))
 })
 
-describe("durable acceptance", () => {
-  /**
-   * The README's recipe on an in-memory store. The key and its work item
-   * commit together, and an insert waits for the one in flight, as a unique
-   * constraint does. `beforeCommit` is where the handler's work can crash.
-   */
-  const makeRecipe = (beforeCommit: (attempt: number) => Effect.Effect) => {
-    const recorder = makeRecorder()
-    const work = new Map()
-    const log: Array = []
-    const constraint = Semaphore.makeUnsafe(1)
-    let attempts = 0
-    const insert = (raw: Schema.Json, item: string) =>
-      constraint.withPermits(1)(Effect.suspend(() => {
-        const key = Option.getOrThrow(TelegramChat.deliveryKey(raw, { botId }))
-        if (work.has(key)) return Effect.sync(() => void log.push("repeat"))
-        return Effect.andThen(
-          beforeCommit(++attempts),
-          Effect.sync(() => {
-            work.set(key, item)
-            log.push("commit")
-          })
-        )
-      }))
-    const interactions = ChatInteraction.Handler.of({
-      ...recorder.interactions,
-      click: (event) => Effect.as(insert(event.raw, event.id), ChatInteraction.ack),
-      command: (event) =>
-        Effect.as(insert(event.raw, event.text), ChatInteraction.defer(event, { visibility: "public" }))
-    })
-    return { ...recorder, interactions, work, log, attempts: () => attempts }
-  }
+/**
+ * The README's recipe on an in-memory store. The key and its work item
+ * commit together, and an insert waits for the one in flight, as a unique
+ * constraint does. `beforeCommit` is where the handler's work can crash.
+ */
+const makeRecipe = (beforeCommit: (attempt: number) => Effect.Effect) => {
+  const recorder = makeRecorder()
+  const work = new Map()
+  const log: Array = []
+  const constraint = Semaphore.makeUnsafe(1)
+  let attempts = 0
+  const insert = (raw: Schema.Json, item: string) =>
+    constraint.withPermits(1)(Effect.suspend(() => {
+      const key = Option.getOrThrow(TelegramChat.deliveryKey(raw, { botId }))
+      if (work.has(key)) return Effect.sync(() => void log.push("repeat"))
+      return Effect.andThen(
+        beforeCommit(++attempts),
+        Effect.sync(() => {
+          work.set(key, item)
+          log.push("commit")
+        })
+      )
+    }))
+  const interactions = ChatInteraction.Handler.of({
+    ...recorder.interactions,
+    click: (event) => Effect.as(insert(event.raw, event.id), ChatInteraction.ack),
+    command: (event) => Effect.as(insert(event.raw, event.text), ChatInteraction.defer(event, { visibility: "public" }))
+  })
+  return { ...recorder, interactions, work, log, attempts: () => attempts }
+}
 
+describe("durable acceptance", () => {
   const blocked = Effect.fnUntraced(function*(recipe: { readonly attempts: () => number }, n: number) {
     while (recipe.attempts() < n) yield* Effect.yieldNow
   })
@@ -472,6 +472,92 @@ describe("durable acceptance", () => {
     }))
 })
 
+describe("deadlines", () => {
+  const until = Effect.fnUntraced(function*(done: () => boolean) {
+    while (!done()) yield* Effect.yieldNow
+  })
+
+  it.effect("answers a click at its deadline and lets its handler run on, so a late commit is never repeated", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const release = yield* Deferred.make()
+      const clicks: Array = []
+      const recorder = makeRecorder()
+      const late = {
+        ...recorder,
+        interactions: ChatInteraction.Handler.of({
+          ...recorder.interactions,
+          click: () =>
+            Effect.as(
+              Effect.andThen(
+                Effect.sync(() => void clicks.push("started")),
+                Effect.andThen(Deferred.await(release), Effect.sync(() => void clicks.push("committed")))
+              ),
+              ChatInteraction.ack
+            )
+        })
+      }
+      const click = callbackUpdate({
+        message_id: 5,
+        date: 1_800_000_000,
+        chat: { id: chatId, type: "supergroup" },
+        text: "x",
+        reply_markup: { inline_keyboard: [[{ text: "Yes", callback_data: "approve" }]] }
+      }, "approve")
+      const fiber = yield* Effect.forkChild(receive(api, late, click))
+      yield* until(() => clicks.length > 0)
+      yield* TestClock.adjust("2499 millis")
+      assert.isUndefined(fiber.pollUnsafe())
+      assert.strictEqual(api.sent("answerCallbackQuery").length, 0)
+      yield* TestClock.adjust("1 millis")
+      assert.deepStrictEqual(yield* Fiber.join(fiber), ["accepted"])
+      assert.strictEqual(api.sent("answerCallbackQuery").length, 1)
+      assert.deepStrictEqual(clicks, ["started"])
+      yield* Deferred.succeed(release, void 0)
+      yield* until(() => clicks.length > 1)
+      assert.deepStrictEqual(clicks, ["started", "committed"])
+    }))
+
+  it.effect("refuses a message whose handler outlives its deadline, so Telegram redelivers it", () =>
+    Effect.gen(function*() {
+      const started: Array = []
+      const stuck = {
+        ...makeRecorder(),
+        handler: ChatHandler.of({
+          handle: () => Effect.andThen(Effect.sync(() => void started.push("started")), Effect.never)
+        })
+      }
+      const fiber = yield* Effect.forkChild(receive(makeApi(), stuck, messageUpdate({ text: "hi" })))
+      yield* until(() => started.length > 0)
+      yield* TestClock.adjust("9999 millis")
+      assert.isUndefined(fiber.pollUnsafe())
+      yield* TestClock.adjust("1 millis")
+      assert.deepStrictEqual(yield* Fiber.join(fiber), ["notAccepted"])
+    }))
+
+  it.effect("interrupts a command at its deadline and still counts it answered, never as a message", () =>
+    Effect.gen(function*() {
+      const api = makeApi()
+      const steps: Array = []
+      const recipe = makeRecipe(() =>
+        Effect.andThen(
+          Effect.sync(() => void steps.push("started")),
+          Effect.onInterrupt(Effect.never, () => Effect.sync(() => void steps.push("interrupted")))
+        )
+      )
+      const fiber = yield* Effect.forkChild(receive(api, recipe, commandUpdate("deploy", "prod")))
+      yield* until(() => steps.length > 0)
+      yield* TestClock.adjust("9999 millis")
+      assert.isUndefined(fiber.pollUnsafe())
+      yield* TestClock.adjust("1 millis")
+      assert.deepStrictEqual(yield* Fiber.join(fiber), ["accepted"])
+      yield* until(() => steps.length > 1)
+      assert.deepStrictEqual(steps, ["started", "interrupted"])
+      assert.strictEqual(recipe.work.size, 0)
+      assert.strictEqual(recipe.events.length + recipe.unhandled.length, 0)
+    }))
+})
+
 describe("senders and files", () => {
   // Telegram's stand-in `from` for anonymous group admins.
   const anonymous = { id: 1087968824, is_bot: true, first_name: "Group", username: "GroupAnonymousBot" }
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 9de7ac6602b..777e7433693 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -16,6 +16,9 @@ import { assert, describe, it } from "@effect/vitest"
 import * as fc from "fast-check"
 import { inspect } from "./gfm.ts"
 
+/** The most blocks Telegram renders in one message. */
+const maxBlocks = 500
+
 const cases: ReadonlyArray = [
   ["hi  ", "<b>hi</b>  <javascript:alert(1)>"],
   ["![a](https://e.com/a.png) ![b][r]", "\\![a](https://e.com/a.png) \\![b][r]"],
@@ -50,6 +53,7 @@ const assertInert = (input: string) => {
   assert.deepStrictEqual(found.active, [], context)
   assert.isAtMost(found.maxDepth, maxDepth, context)
   assert.isAtMost(found.maxColumns, maxColumns, context)
+  if (measure(input) <= messageLength) assert.isAtMost(found.blocks, maxBlocks, context)
 }
 
 const hostile = fc.string({
@@ -113,12 +117,46 @@ describe("render", () => {
         "| a | b |\n|---|---|\n# heading\n||secret||",
         // a backslash in a bare URL escapes nothing
         "https://e.com\\ ](https://e.com\\ )",
-        "[^]: [^a]: x\n="
+        "[^]: [^a]: x\n=",
+        // a lazy continuation line stays in the containers it does not repeat
+        ">".repeat(15) + " x\n" + "_".repeat(14) + "x" + "_".repeat(14),
+        "2. <\n x_\n=",
+        "[^a]: b\na\n=",
+        "|a|\n|-|\na\n=\n|a|\n|-|\na\n=",
+        // an intraword underscore closes nothing
+        "_a_b ".repeat(17) + "x_" + " x_".repeat(16),
+        // a footnote's text, or an indented delimiter row, is no table
+        "[^a]: x|y\n---|---\n||secret||",
+        "x|y\n\t---|---"
       ]
     ) assertInert(input)
     fc.assert(fc.property(hostile, (input) => assertInert(input)), { numRuns: 2000 })
   })
 
+  it("keeps output within the budget under 500 blocks", () => {
+    const line = fc.constantFrom(
+      "- a\n",
+      "> - a\n",
+      "- - - a\n",
+      "1. a\n",
+      "# a\n",
+      "a\n",
+      "a\n=\n",
+      "___\n",
+      "|a|\n|-|\n",
+      "[^a]: b\n",
+      "```\n```\n"
+    )
+    fc.assert(
+      fc.property(fc.array(line, { minLength: 1, maxLength: 4 }), (lines) => {
+        let input = ""
+        for (let k = 0; measure(input + lines[k]) <= messageLength; k = (k + 1) % lines.length) input += lines[k]
+        assertInert(input)
+      }),
+      { numRuns: 40 }
+    )
+  })
+
   it("escapes the pipes of a table wider than 20 columns", () => {
     const row = (cell: string) => "|" + ` ${cell} |`.repeat(21)
     const out = render(row("c") + "\n" + row("-"))

From 3df85a19c68a2908ec9ca72949048bcd464262fd Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 23:10:01 +0000
Subject: [PATCH 77/89] chat-telegram: treat only space and tab lines as blank
 in the renderer

A line of U+00A0 or other non-ASCII whitespace is paragraph text to
CommonMark, but trim() made the renderer treat it as a blank line. That
reset the emphasis and container counts and allowed a new table after
it. One isBlank predicate now governs paragraph, setext and table state.

Adds the review's two inputs to the parser-backed corpus and non-ASCII
whitespace (U+00A0, U+3000, \v, \f) to the hostile generator.
---
 packages/chat/telegram/src/internal/markdown.ts | 14 ++++++++++----
 packages/chat/telegram/test/markdown.test.ts    | 12 ++++++++++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
index 9af5e168159..ecd269d4bab 100644
--- a/packages/chat/telegram/src/internal/markdown.ts
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -161,6 +161,12 @@ const cellCount = (line: string): number => {
   return count
 }
 
+/**
+ * A blank line as CommonMark defines it: only spaces and tabs. Other
+ * whitespace, such as U+00A0, is paragraph text and ends nothing.
+ */
+const isBlank = (line: string): boolean => /^[ \t]*$/.test(line)
+
 const hasPipe = (line: string) => cellCount(line) > 1 || line.trim().startsWith("|")
 
 /** The decoded form of a link destination, as a Markdown parser and then a URL parser read it. */
@@ -526,12 +532,12 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     // Neither row indented, nor the header after a line it could continue.
     if (/^\s/.test(lines[i]) || /^\s/.test(lines[i + 1])) continue
     const above = i === 0 ? "" : lines[i - 1]
-    if (above.trim() !== "" && !/^#{1,6}(?: |$)/.test(above)) continue
+    if (!isBlank(above) && !/^#{1,6}(?: |$)/.test(above)) continue
     if (!delimiterRow.test(lines[i + 1]) || !lines[i + 1].includes("|") || !hasPipe(lines[i])) continue
     const columns = cellCount(lines[i])
     if (columns !== cellCount(lines[i + 1])) continue
     let end = i + 2
-    while (end < lines.length && !fenced[end] && lines[end].trim() !== "" && !blockStart.test(lines[end])) end++
+    while (end < lines.length && !fenced[end] && !isBlank(lines[end]) && !blockStart.test(lines[end])) end++
     const rows = Array.from({ length: end - i }, (_, k) => i + k)
     for (const row of rows) tableRows.set(row, columns > maxColumns || cellCount(lines[row]) > maxColumns)
     i = end - 1
@@ -543,8 +549,8 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
   // it could be the lazy continuation of.
   let plain = true
   const out = lines.map((line, i) => {
-    const blank = line.trim() === ""
-    const setext = plain && i > 0 && lines[i - 1].trim() !== "" && /^ {0,3}=+[ \t]*$/.test(line)
+    const blank = isBlank(line)
+    const setext = plain && i > 0 && !isBlank(lines[i - 1]) && /^ {0,3}=+[ \t]*$/.test(line)
     plain = !fenced[i] && (blank || (plain && !/^\s/.test(line) && !blockStart.test(line) && !line.includes("|")))
     if (fenced[i]) return line
     const wide = tableRows.get(i)
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 777e7433693..4d9f61d9a21 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -76,7 +76,12 @@ const hostile = fc.string({
     "|---|",
     "\\]",
     "\\<",
-    "\\`"
+    "\\`",
+    // whitespace that is not a blank line to CommonMark
+    "\u00a0",
+    "\u3000",
+    "\v",
+    "\f"
   ),
   maxLength: 60
 })
@@ -127,7 +132,10 @@ describe("render", () => {
         "_a_b ".repeat(17) + "x_" + " x_".repeat(16),
         // a footnote's text, or an indented delimiter row, is no table
         "[^a]: x|y\n---|---\n||secret||",
-        "x|y\n\t---|---"
+        "x|y\n\t---|---",
+        // a line of U+00A0 is text, so it ends no paragraph
+        ">".repeat(15) + " x\n\u00a0\n" + "_".repeat(14) + "x" + "_".repeat(14),
+        "[^a]: z\n\u00a0\nx|y\n---|---\n||secret||"
       ]
     ) assertInert(input)
     fc.assert(fc.property(hostile, (input) => assertInert(input)), { numRuns: 2000 })

From 9a101a1232649cea6227e418b7b2d9cea1157bca Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 23:34:41 +0000
Subject: [PATCH 78/89] test(chat-slack): isolate modal refusal from wall-clock
 deadline

---
 packages/chat/slack/test/interactions.test.ts | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
index 1598608aa0e..888519ff4ed 100644
--- a/packages/chat/slack/test/interactions.test.ts
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -171,7 +171,8 @@ describe("SlackChat.interaction", () => {
       assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
     }))
 
-  it.live("refuses a modal Slack refuses, or that is too large, to Handler.refused, still acking", () =>
+  // Keep validation and API error mapping independent of the handler's wall-clock deadline.
+  it.effect("refuses a modal Slack refuses, or that is too large, to Handler.refused, still acking", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest, "views.open": { ok: false, error: "expired_trigger_id" } })
       const handler = recording()

From 329de2f95d79968d865f14f35d1beb86bd717c3c Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Sun, 15 Nov 2026 23:55:59 +0000
Subject: [PATCH 79/89] Reconcile the WhatsApp adapter with the live API checks

Refuse a reply button whose wire id is over 256 UTF-8 bytes before the call, add an optional messagingAccountId sent as messaging_account_id, raise the webhook deadline to 10 seconds, and record what the live checks covered and what is still unchecked.
---
 packages/chat/whatsapp/README.md              | 20 +++++++++-
 packages/chat/whatsapp/src/WhatsAppChat.ts    | 39 ++++++++++++++-----
 .../chat/whatsapp/src/internal/actions.ts     |  5 ++-
 .../chat/whatsapp/src/internal/adapter.ts     |  4 +-
 packages/chat/whatsapp/src/internal/text.ts   |  8 +++-
 .../chat/whatsapp/test/WhatsAppChat.test.ts   | 22 +++++++++++
 packages/chat/whatsapp/test/utils.ts          |  7 +++-
 7 files changed, 89 insertions(+), 16 deletions(-)

diff --git a/packages/chat/whatsapp/README.md b/packages/chat/whatsapp/README.md
index 8324574a6a0..fe6fe4a697e 100644
--- a/packages/chat/whatsapp/README.md
+++ b/packages/chat/whatsapp/README.md
@@ -24,7 +24,25 @@ For other runtimes such as Workers, provide
 - Groups are not supported. Group webhooks are logged and dropped, and an op on a group address fails.
 - WhatsApp has no edit or delete, so a streamed reply is posted part by part.
 - Outside the 24 hour customer service window only templates can be sent, with `WhatsAppChat.sendTemplate`.
-- Not yet checked against the live API: the unit Meta counts text limits in, how the rendered formatting shows, a `.md` file sent as `text/plain`, whether error 131047 comes back on the send or as a later status, the webhook's real timeout, and how a media header renders beside buttons.
+- A user can tap more than one reply button of a message, or pick one list row twice. Each tap is its own click.
+
+## Live checks
+
+Checked on Graph API `v23.0` from a Meta test number to one phone. The default `baseUrl` is `v24.0`, where these have not been repeated.
+
+- Meta counts text, interactive bodies, button and row titles, and row ids in code points. The adapter counts UTF-16 units, which is never less. A reply button id is counted in UTF-8 bytes, up to 256, and the adapter checks it that way.
+- The rendered formatting displays as intended, and literal `*`, `_` and escapes display as typed.
+- A `.md` file sent as `text/plain` arrives with its name.
+- A media header beside reply buttons or a link button renders.
+- Meta gave up on a webhook response after about 22 seconds. The default `deadline` is 10 seconds.
+- Six messages to one user in 4.4 seconds were accepted. That is one burst, not a sustained rate, so `minWriteInterval` stays at Meta's documented 6 seconds.
+
+Not yet checked:
+
+- Whether error 131047 comes back on the send or as a later status.
+- Sending to a BSUID from a production number. A test number only sends to its allow-listed phone numbers.
+- Sending from a production number whose business has Messaging accounts and a payment method, with and without `messagingAccountId`.
+- Groups.
 
 ## Links
 
diff --git a/packages/chat/whatsapp/src/WhatsAppChat.ts b/packages/chat/whatsapp/src/WhatsAppChat.ts
index 5b254b6934b..4a44e581bb1 100644
--- a/packages/chat/whatsapp/src/WhatsAppChat.ts
+++ b/packages/chat/whatsapp/src/WhatsAppChat.ts
@@ -152,7 +152,11 @@ export class WhatsAppChat extends Context.Service =>
   Layer.effect(
@@ -206,7 +221,8 @@ export const layer = (options: {
         graph,
         http,
         accessToken: options.accessToken,
-        phoneNumberId: options.phoneNumberId
+        phoneNumberId: options.phoneNumberId,
+        messagingAccountId: options.messagingAccountId
       })
       yield* registry.register(adapter)
       const context = { phoneNumberId: options.phoneNumberId }
@@ -265,10 +281,11 @@ export const parts: (thread: ChatThread) => Option.Option<{
  *   `ChatHandler`, clicks to `ChatInteraction.handle`, and statuses and
  *   changed ids to `onUpdate`. A removed reaction is dropped.
  * - A `NotAccepted` stops the delivery and answers 503, as does a request
- *   that takes longer than `deadline` (4 seconds by default, provisional).
- *   Meta then delivers the whole batch again, for up to 7 days, so a batch
- *   that always runs past the deadline repeats until then. At the deadline
- *   the work is interrupted without waiting for its finalizers.
+ *   that takes longer than `deadline`, 10 seconds by default. Meta then
+ *   delivers the whole batch again, for up to 7 days, so a batch that
+ *   always runs past the deadline repeats until then. At the deadline the
+ *   work is interrupted without waiting for its finalizers. In a live check
+ *   Meta gave up on a response after about 22 seconds and redelivered.
  * - A click never causes a 503. It gets what is left of the deadline, less
  *   a margin. `Ack` and `Late` count as handled, and a late handler keeps
  *   running. `OpenModal` goes to `Handler.refused` as
@@ -280,6 +297,10 @@ export const parts: (thread: ChatThread) => Option.Option<{
  *   a second run is unsafe must claim `deliveryKey` atomically, before any
  *   side effect. The adapter keeps no seen-store. Deliveries are not in
  *   order either: order by the updates' timestamps.
+ * - A user can tap more than one reply button of a message, or pick one
+ *   list row twice. Each tap is a click of its own, with its own
+ *   `deliveryKey`, so a choice that must be made once needs its own
+ *   claim.
  *
  * Signature checks use the required `Mac` service. Provide
  * `NodeCrypto.layerMac`, `BunCrypto.layerMac`, `DenoCrypto.layerMac`,
@@ -311,7 +332,7 @@ export const layerWebhook = (options: {
       normalize: (envelope) => Normalize.normalize(envelope, context),
       handle: handler.handle,
       onUpdate: options.onUpdate,
-      deadline: options.deadline ?? Duration.seconds(4),
+      deadline: options.deadline ?? Duration.seconds(10),
       maxBodyBytes: options.maxBodyBytes ?? 3 * 1024 * 1024
     }
     yield* router.add(
diff --git a/packages/chat/whatsapp/src/internal/actions.ts b/packages/chat/whatsapp/src/internal/actions.ts
index 34898538465..e21c36a161d 100644
--- a/packages/chat/whatsapp/src/internal/actions.ts
+++ b/packages/chat/whatsapp/src/internal/actions.ts
@@ -1,7 +1,7 @@
 import { type ChatErrorReason, InvalidRequest, TooLarge } from "effect/chat/ChatError"
 import type { Action, Button, LinkButton, Select } from "effect/chat/ChatUi"
 import { defaultButtonsSection, defaultListButton, type PostOptions } from "./options.ts"
-import { shortBodyLength } from "./text.ts"
+import { shortBodyLength, utf8Bytes } from "./text.ts"
 
 /** Between an element's id and its value in a wire id. @internal */
 export const join = "\u241F"
@@ -9,6 +9,8 @@ export const join = "\u241F"
 /** @internal */
 export const limits = { actionsPerMessage: 10, actionDataLength: 198 } as const
 
+/** Meta counts a reply button's id in UTF-8 bytes, unlike every other limit. */
+const replyIdBytes = 256
 const replyLabelLength = 20
 const rowTitleLength = 24
 const listButtonLength = 20
@@ -165,6 +167,7 @@ export const plan = (actions: ReadonlyArray, options: PostOptions): Plan
       const ids = buttons.map(buttonWireId)
       if (!unique(buttons.map((button) => button.label))) return invalid("duplicate_label")
       if (!unique(ids)) return invalid("duplicate_id")
+      if (ids.some((id) => utf8Bytes(id) > replyIdBytes)) return tooLarge("action_data_too_long")
       return {
         kind,
         interactive: {
diff --git a/packages/chat/whatsapp/src/internal/adapter.ts b/packages/chat/whatsapp/src/internal/adapter.ts
index fcfbb266180..1841a532aa7 100644
--- a/packages/chat/whatsapp/src/internal/adapter.ts
+++ b/packages/chat/whatsapp/src/internal/adapter.ts
@@ -100,8 +100,10 @@ export const make = (options: {
   readonly http: HttpClient.HttpClient
   readonly accessToken: Redacted.Redacted
   readonly phoneNumberId: string
+  readonly messagingAccountId?: string | undefined
 }) => {
   const { graph, phoneNumberId } = options
+  const account = options.messagingAccountId === undefined ? {} : { messaging_account_id: options.messagingAccountId }
 
   const fail = (op: string, reason: ChatErrorReason) => Effect.fail(Errors.chatError(op, reason))
 
@@ -124,7 +126,7 @@ export const make = (options: {
 
   const send = Effect.fnUntraced(function*(op: string, thread: ChatThread, user: string, message: JsonObject) {
     const answer = yield* graph.call(`${phoneNumberId}/messages`, {
-      body: { messaging_product: "whatsapp", recipient_type: "individual", ...recipient(user), ...message },
+      body: { messaging_product: "whatsapp", recipient_type: "individual", ...account, ...recipient(user), ...message },
       write: true
     }).pipe(Effect.mapError(withOp(op)))
     const messages = isObject(answer) && Array.isArray(answer.messages) ? answer.messages : []
diff --git a/packages/chat/whatsapp/src/internal/text.ts b/packages/chat/whatsapp/src/internal/text.ts
index 6566eb31dc3..d73defd394b 100644
--- a/packages/chat/whatsapp/src/internal/text.ts
+++ b/packages/chat/whatsapp/src/internal/text.ts
@@ -8,7 +8,10 @@
  * the output is never longer than the input in any of the three units.
  */
 
-/** The longest text message, and the measure's unit: UTF-16 code units. @internal */
+/**
+ * The longest text message, and the measure's unit: UTF-16 code units, which
+ * are never fewer than the code points Meta counts. @internal
+ */
 export const messageLength = 4096
 
 /** The longest caption, and the longest body beside reply buttons or a link button. @internal */
@@ -23,7 +26,8 @@ const codePoints = (s: string): number => {
   return n
 }
 
-const utf8Bytes = (s: string): number => {
+/** @internal */
+export const utf8Bytes = (s: string): number => {
   let n = 0
   for (const char of s) {
     const code = char.codePointAt(0)!
diff --git a/packages/chat/whatsapp/test/WhatsAppChat.test.ts b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
index 3439e085860..df4c8406632 100644
--- a/packages/chat/whatsapp/test/WhatsAppChat.test.ts
+++ b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
@@ -178,6 +178,28 @@ describe("post", () => {
       assert.deepStrictEqual(graph.calls, [])
     }))
 
+  it.effect("refuses a reply button whose wire id is over 256 UTF-8 bytes", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      // "b", the id and U+241F take 5 bytes, so 125 "é" and one "a" make 256.
+      yield* run(graph, post({ markdown: "x", actions: [button("x", "Yes", "é".repeat(125) + "a")] }))
+      assert.strictEqual(graph.calls.length, 1)
+      const reason = yield* failure(graph, post({ markdown: "x", actions: [button("x", "Yes", "é".repeat(126))] }))
+      assert.deepStrictEqual([reason._tag, reason.detail], ["TooLarge", "action_data_too_long"])
+      assert.strictEqual(graph.calls.length, 1)
+    }))
+
+  it.effect("names the messaging account on every send when one is configured", () =>
+    Effect.gen(function*() {
+      const graph = makeGraph()
+      yield* Effect.gen(function*() {
+        yield* post({ markdown: "hi" })
+        const whatsapp = yield* WhatsAppChat.WhatsAppChat
+        yield* whatsapp.sendTemplate(thread, { name: "hello", language: "en_US" })
+      }).pipe(Effect.provide(whatsappLayer(graph, { messagingAccountId: "ma-1" })))
+      assert.deepStrictEqual(graph.sent().map((body) => body.messaging_account_id), ["ma-1", "ma-1"])
+    }))
+
   it.effect("uploads a file as the header of reply buttons, and Markdown as text/plain", () =>
     Effect.gen(function*() {
       const graph = makeGraph()
diff --git a/packages/chat/whatsapp/test/utils.ts b/packages/chat/whatsapp/test/utils.ts
index 630ab3d022b..1c702880a56 100644
--- a/packages/chat/whatsapp/test/utils.ts
+++ b/packages/chat/whatsapp/test/utils.ts
@@ -99,8 +99,11 @@ export const makeGraph = () => {
 }
 
 /** `Chat`, `Registry` and the WhatsApp adapter on a fake Graph API. */
-export const whatsappLayer = (graph: ReturnType) =>
-  WhatsAppChat.layer({ accessToken: Redacted.make("EAAG-test"), phoneNumberId }).pipe(
+export const whatsappLayer = (
+  graph: ReturnType,
+  options?: { readonly messagingAccountId?: string }
+) =>
+  WhatsAppChat.layer({ accessToken: Redacted.make("EAAG-test"), phoneNumberId, ...options }).pipe(
     Layer.provideMerge(Chat.layer),
     Layer.provide(graph.layer)
   )

From a52fcf6c575799ab3451363bc30d962e400e1b1f Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 00:01:29 +0000
Subject: [PATCH 80/89] Scope the WhatsApp counting and messaging account docs
 to what was checked

---
 packages/chat/whatsapp/README.md           |  2 +-
 packages/chat/whatsapp/src/WhatsAppChat.ts | 20 +++++++++++++-------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/packages/chat/whatsapp/README.md b/packages/chat/whatsapp/README.md
index fe6fe4a697e..2c079ab9f3c 100644
--- a/packages/chat/whatsapp/README.md
+++ b/packages/chat/whatsapp/README.md
@@ -30,7 +30,7 @@ For other runtimes such as Workers, provide
 
 Checked on Graph API `v23.0` from a Meta test number to one phone. The default `baseUrl` is `v24.0`, where these have not been repeated.
 
-- Meta counts text, interactive bodies, button and row titles, and row ids in code points. The adapter counts UTF-16 units, which is never less. A reply button id is counted in UTF-8 bytes, up to 256, and the adapter checks it that way.
+- Meta counts text bodies, interactive bodies, reply button titles, list row titles and row ids in code points. The adapter counts UTF-16 units, which is never less. Captions, the list button and section titles were not measured. A reply button id is counted in UTF-8 bytes, up to 256, and the adapter checks it that way.
 - The rendered formatting displays as intended, and literal `*`, `_` and escapes display as typed.
 - A `.md` file sent as `text/plain` arrives with its name.
 - A media header beside reply buttons or a link button renders.
diff --git a/packages/chat/whatsapp/src/WhatsAppChat.ts b/packages/chat/whatsapp/src/WhatsAppChat.ts
index 4a44e581bb1..899cc3260ba 100644
--- a/packages/chat/whatsapp/src/WhatsAppChat.ts
+++ b/packages/chat/whatsapp/src/WhatsAppChat.ts
@@ -153,10 +153,13 @@ export class WhatsAppChat extends Context.Service
Date: Mon, 16 Nov 2026 13:25:35 +1300
Subject: [PATCH 81/89] chat-telegram: fix what the production live checks
 found

Live checks 1 to 5, 7, 10, 11 and 13 to 16 ran against the production
Bot API. Telegram's rich Markdown differs from CommonMark in ways the GFM
oracle could not see:

- It closes a link at an escaped `]` and ignores `\<`, `\:` and other
  escapes, so `[x](tg://...)`, a consumer's `[x\](tg://...)` and
  `\` stayed live. Refused links now lose their `(`, refused
  definitions their opening `[`, and unhonored escapes become numeric
  character references. The GFM oracle now flags unhonored escapes.
- It reads destinations verbatim, so escaping them corrupted every link
  with a query string and turned allowed tg://user mentions into plain
  links. Kept destinations are sent verbatim, titles dropped; a link is
  kept only with its opener on the line, a definition only at the top
  level after a blank line or another definition.
- It reads definitions past other brackets and with leading space.
- It opens emphasis between spaces (`2 * 3 * 4`); such runs are escaped.
- It refuses a paragraph past about 4,387 inline nodes and about 773
  references to one footnote, which in-budget code spans and footnotes
  could reach. Both are now capped.
- Its rich message errors (RICH_MESSAGE_*) matched no refinement and all
  mapped to telegram_400. They are now mapped.

Adds an opt-in live conformance test and records the results, the
privacy-mode mention rule and in-order redelivery in the README.
---
 packages/chat/telegram/README.md              |  45 ++--
 packages/chat/telegram/src/TelegramChat.ts    |   7 +-
 packages/chat/telegram/src/internal/errors.ts |   9 +-
 .../chat/telegram/src/internal/markdown.ts    | 209 ++++++++++++++----
 .../chat/telegram/test/TelegramChat.test.ts   |  25 +++
 packages/chat/telegram/test/gfm.ts            |  14 +-
 packages/chat/telegram/test/live.test.ts      |  75 +++++++
 packages/chat/telegram/test/markdown.test.ts  |  38 +++-
 8 files changed, 351 insertions(+), 71 deletions(-)
 create mode 100644 packages/chat/telegram/test/live.test.ts

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index a29298a2ef9..b60e384ef81 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -2,7 +2,7 @@
 
 A [Telegram](https://telegram.org) adapter for `effect/chat`, over the Bot API. It includes a webhook endpoint, a long-polling loop, a pure update normaliser, and the address helpers.
 
-This package is private, and it is not released. Nothing in it has run against Telegram yet, the default capabilities included: rich posts and edits, the escaping, link previews and notifications are as unverified as files, buttons and commands. It stays private until the base live checks below pass (1, 2, 3, 4, 5, 7, 10, 11, 15, 16 and 17). Passing unit tests do not lift that. Releasing it then means removing `private`, adding the package to the release setup, and adding its changeset.
+This package is private, and it is not released. The base live checks (1, 2, 3, 4, 5, 7, 10, 11, 15, 16 and 17) ran against production on 16 Nov 2026, and their results are below. Check 17 still needs check 9. Files, buttons and commands are not verified. Releasing it means removing `private`, adding the package to the release setup, and adding its changeset.
 
 ## Setup
 
@@ -27,6 +27,8 @@ const Polling = TelegramChat.layerPolling().pipe(
 
 `TelegramChat.layer` needs `HttpClient` and the chat `Registry`. `TelegramChat.layerWebhook` also needs `HttpRouter` and a `ChatHandler`, and `TelegramChat.layerPolling` a `ChatHandler`. Clicks and commands go to `ChatInteraction.Handler` when one is in context.
 
+In a group, a bot in privacy mode receives commands, replies to its own messages and service messages, but not a plain `@bot` mention. To see mentions, turn privacy mode off in @BotFather or make the bot an admin.
+
 Register the webhook once with `TelegramChat.setWebhook({ url, secretToken })`, which sets exactly the `allowed_updates` the adapter reads. The adapter never calls it, or `deleteWebhook`, on its own. Polling fails to start with `InvalidRequest` and detail `conflict` while a webhook is set.
 
 `environment: "test"` uses Telegram's [test environment](https://core.telegram.org/bots/features#dedicated-test-environment). `apiUrl` points at a local Bot API server.
@@ -67,13 +69,16 @@ Updates from business connections, a channel's direct messages and guest mode ar
 
   const App = Webhook.pipe(Layer.provideMerge(RedactSecret))
   ```
-- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading, and past 15 delimiters that could open emphasis in one paragraph the rest are shown as written.
+- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, and a definition only at the top level after a blank line.
+- Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading; a `*` or `_` with space on both sides is escaped, as Telegram would open emphasis with it; and past 15 delimiters that could open emphasis, or 4,000 code spans, links and footnote references in one paragraph, or 700 footnote references in a message, the rest are shown as written. Telegram still pairs emphasis more loosely than CommonMark: `a* b*` is italic.
 - A click is dispatched only when its `data` matches a button in Telegram's own copy of the message. That shows the bot put the button there, not that it is still current or that this user may press it.
 
 ## Redelivery
 
 Telegram sends an update again until it gets a 200, clicks and commands included. Polling sees it again until the offset moves past it. The webhook answers 503 when the `ChatHandler` fails `NotAccepted` or passes `deadline` (10 seconds), and Telegram retries. Polling retries an update up to `maxAttempts` times, then logs it and moves on.
 
+Telegram delivers updates in order, for the whole bot: while one is refused, the ones after it wait. It retries after about 0.3, 2, 4, 8, 16 and 32 seconds, keeping the `update_id`, and gives up on a webhook request after 60 seconds. A handler that refuses a lot stalls every chat, so `NotAccepted` is for short outages.
+
 Clicks and commands are different. Their handlers have a deadline of their own, and when it passes the update counts as answered: the webhook answers 200 and polling moves its offset. Telegram does not send it again.
 
 - A click handler has `clickDeadline` (2.5 seconds). Then the click is answered so the button stops spinning, and the handler keeps running, detached. If it fails or the process dies after that, nothing repeats the click.
@@ -90,25 +95,25 @@ A crash before the commit leaves nothing, and the repeat does the work. A concur
 
 ## Live checks
 
-None of these have run yet. Most run in the test environment, with a test bot, two test users and a forum supergroup where the bot is an admin. Check 17 repeats the ones that matter on production.
-
-1. Rich messages render on current clients, and what older ones show.
-2. The rich-Markdown dialect and its escapes, matching the escaping above.
-3. The limits: what 32,768 counts, what a block is, nesting and table columns.
-4. Link previews on rich posts and edits, and whether they can be turned off.
-5. Whether a plain `@user`, a `tg://user` link and a `text_mention` notify.
-6. Rich-message media over multipart `attach://`, and edits of a message with media.
-7. Webhook and polling redelivery after a 503 or a dropped connection.
-8. Callback queries: the server's copy of `reply_markup`, forged `data`, delayed clicks.
-9. Ephemeral commands, with an author and a bystander.
+Checks 1 to 5, 7, 10, 11 and 13 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin bot and a forum supergroup. That also covers check 17, except for 9. `test/live.test.ts` runs the conformance suite against the Bot API when `TELEGRAM_LIVE_BOT_TOKEN`, `TELEGRAM_LIVE_BOT2_TOKEN` and `TELEGRAM_LIVE_CHAT` are set.
+
+1. Rich messages render on macOS desktop and mobile clients. Not seen: Web, Android and older clients.
+2. The rich-Markdown dialect, the escapes Telegram honors, and its readings of links, definitions and emphasis. The escaping follows what it found.
+3. The limits: 32,768 rendered characters (non-ASCII text counts less), 500 blocks with a list counting one per item, 16 levels of nesting, 20 table columns, about 4,387 inline nodes per paragraph and about 773 references to one footnote. A code block is one block. `measure` stays under each of these.
+4. No link preview on rich posts or edits.
+5. A plain `@user` notifies nobody, and an allowed `tg://user` link is a mention.
+6. Not run: rich-message media over multipart `attach://`, and edits of a message with media.
+7. Webhook redelivery after a 503 or a dropped connection, as described under Redelivery.
+8. Not run: callback queries, the server's copy of `reply_markup`, forged `data`, delayed clicks.
+9. Not run: ephemeral commands, with an author and a bystander.
 10. The error responses behind the error mapping.
-11. Forum topics and the General topic.
-12. Reaction updates.
-13. Edit pacing and `retry_after`.
-14. `getChatMember` as a non-admin.
-15. Whether a plain `@bot` mention reaches a bot in privacy mode.
-16. Inbound rich messages.
-17. A production smoke check of 1, 4, 5, 9, 13 and 15.
+11. Forum topics and the General topic. Topics in private chats were not tried.
+12. Not run: reaction updates.
+13. Edit pacing: one edit every 3 seconds in a group gets no 429. Back-to-back edits got one after 19, with `retry_after` 43.
+14. `getChatMember` as a non-admin works for members and non-members, and fails `NotFound` for another bot.
+15. A plain `@bot` mention does not reach a bot in privacy mode. A reply does.
+16. Inbound rich messages: a bot never receives another bot's messages, so they arrive only as a reply target, with `rich_message` and no `text`.
+17. A production smoke check of 1, 4, 5, 9, 13 and 15: all but 9 ran.
 
 ## Links
 
diff --git a/packages/chat/telegram/src/TelegramChat.ts b/packages/chat/telegram/src/TelegramChat.ts
index c5e4f81cfce..24b47981c3f 100644
--- a/packages/chat/telegram/src/TelegramChat.ts
+++ b/packages/chat/telegram/src/TelegramChat.ts
@@ -11,10 +11,9 @@
  *   `editMessageText` with `rich_message`), in Markdown escaped so that
  *   consumer text reaches no raw HTML, image, math, spoiler or non-web
  *   link.
- * - Nothing here has run against Telegram yet, the default capabilities
- *   included, and the package stays private until the base live checks
- *   pass. Files, buttons and commands need further checks, so they are
- *   behind `unverified` options, off by default.
+ * - The base live checks ran against production. Files, buttons and
+ *   commands need further checks, so they are behind `unverified`
+ *   options, off by default.
  * - There is no `ephemeral`: a private answer to a command is refused
  *   through `Handler.refused`, never posted. `fetchMessage`, `history`,
  *   `opener`, `startThread`, selects, modals, native streams and reaction
diff --git a/packages/chat/telegram/src/internal/errors.ts b/packages/chat/telegram/src/internal/errors.ts
index 59275ea958c..1fbf2d29166 100644
--- a/packages/chat/telegram/src/internal/errors.ts
+++ b/packages/chat/telegram/src/internal/errors.ts
@@ -87,8 +87,15 @@ const refinements: ReadonlyArray ChatError
   ["bot was blocked", (detail) => new Forbidden({ detail }), "blocked"],
   ["bot was kicked", (detail) => new Forbidden({ detail }), "kicked"],
   ["bot is not a member", (detail) => new Forbidden({ detail }), "not_a_member"],
+  // A rich message's limits, as live check 3 found them.
+  ["rich_message_text_too_long", (detail) => tooLarge("text", detail), "message_too_long"],
+  ["rich_message_too_large", (detail) => tooLarge("text", detail), "message_too_large"],
+  ["rich_message_blocks_too_many", (detail) => tooLarge("text", detail), "too_many_blocks"],
+  ["rich_message_depth_invalid", invalidRequest, "too_deep"],
+  ["rich_message_table_cols_too_many", invalidRequest, "too_many_columns"],
+  ["rich_message_empty", invalidRequest, "empty_message"],
+  ["rich_message_markdown_invalid", invalidRequest, "invalid_markdown"],
   ["too long", (detail) => tooLarge("text", detail), "message_too_long"],
-  ["too many blocks", (detail) => tooLarge("text", detail), "too_many_blocks"],
   ["file is too big", () => refusedFile, fileRefused],
   ["wrong file", () => refusedFile, fileRefused]
 ]
diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
index ecd269d4bab..b5a75825bcb 100644
--- a/packages/chat/telegram/src/internal/markdown.ts
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -9,7 +9,7 @@
 /** What one line break or block marker costs, so that a message in budget stays under 500 blocks. @internal */
 export const block = 65
 
-/** Telegram's rich message limit, read as UTF-8 bytes. @internal */
+/** Telegram's rich message limit. It counts rendered characters, which UTF-8 bytes of the source bound. @internal */
 export const richLimit = 32_768
 
 /** Files one post may carry. @internal */
@@ -49,7 +49,8 @@ const isDigit = (c: string) => c >= "0" && c <= "9"
  * - a code point in the Basic Multilingual Plane costs its UTF-8 length,
  *   and each UTF-16 surrogate 3, enough for the U+FFFD a lone one becomes.
  *   NUL costs 3 too, as Markdown turns it into U+FFFD.
- * - `<` costs 4, a backslash 3 (`%5C` in a bare URL), and
+ * - `<` costs 4, a backslash 5 (the numeric reference, such as `]`,
+ *   that an escape Telegram ignores becomes), and
  *   `$ = | ! [ ] * _ ~` and the backtick 2, their escaped length or more,
  *   whether or not they are escaped in context.
  * - `\n` and `\r` cost `block`, as does a block marker (`>`, a bullet,
@@ -84,7 +85,9 @@ export const measure = (markdown: string): number => {
       }
       prefix = false
     }
-    cost += code === 0 || c === "\\"
+    cost += c === "\\"
+      ? 5
+      : code === 0
       ? 3
       : c === "<"
       ? 4
@@ -242,32 +245,45 @@ const linkTail = (line: string, start: number): { readonly destination: string;
   return line[i] === ")" ? { destination, end: i + 1 } : undefined
 }
 
-const tailEscapes = new Set(["`", "$", "=", "|", "!", "[", "]", "*", "_", "~"])
+/**
+ * The punctuation whose backslash escape Telegram honors. Before any other
+ * punctuation the backslash stays as text and the character is read as
+ * syntax: `\` is bold. `\]` hides the bracket from emphasis but still
+ * closes a link or a definition label, so it is not here either.
+ */
+const honored = new Set("!#$()*+-.=>[\\_`{|}~")
+
+/** A consumer's escape of `c` as Telegram reads it: kept, or a numeric character reference. */
+const escapeOf = (c: string): string => honored.has(c) ? "\\" + c : `&#${c.charCodeAt(0)};`
 
 /**
- * A kept link's tail with every character that is syntax elsewhere
- * escaped. CommonMark decodes the escapes in destinations and titles, so
- * the link is the same, and a parser that does not read the link sees
- * inert text.
+ * A kept destination as Telegram needs it. Telegram reads a destination
+ * verbatim, with no escapes, so they are decoded, a parenthesis or
+ * backslash percent-encoded, and a `<` too, which would end the link.
  */
-const escapeTail = (tail: string): string => {
-  let out = ""
-  for (let i = 0; i < tail.length; i++) {
-    const c = tail[i]
-    if (c === "\\" && punctuation.test(tail[i + 1] ?? "")) {
-      // `\<` and `<` decode alike, but after a bare URL only one is inert.
-      out += tail[++i] === "<" ? "<" : c + tail[i]
-      continue
-    }
-    out += c === "<" ? "<" : tailEscapes.has(c) ? "\\" + c : c
-  }
-  return out
+const destinationOf = (raw: string): string =>
+  raw.replace(/\\([!-/:-@[-`{-~])| {
+    const c = escaped ?? match
+    return percentEncoded[c] ?? c
+  })
+
+const percentEncoded: Readonly> = {
+  "(": "%28",
+  ")": "%29",
+  "\\": "%5C",
+  "<": "%3C",
+  ">": "%3E"
 }
 
 /** The destination of a reference definition after `]:`, when it is on this line. */
-const definitionDestination = (line: string, start: number): string | undefined => {
+const definitionDestination = (
+  line: string,
+  start: number
+): { readonly destination: string; readonly end: number } | undefined => {
   const match = /^[ \t]*(\S+)/.exec(line.slice(start))
-  return match === null || match[1].startsWith("<") ? undefined : match[1]
+  return match === null || match[1].startsWith("<")
+    ? undefined
+    : { destination: match[1], end: start + match[0].length }
 }
 
 /**
@@ -300,6 +316,9 @@ const codeSpanEnd = (line: string, start: number, tableRow: boolean): number | u
  */
 const bareUrl = /^(?:https?:\/\/|www\.)/i
 
+/** A thematic break, whose delimiters stand alone. */
+const thematicBreak = /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/
+
 const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>`]*>/
 
 /**
@@ -308,19 +327,39 @@ const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>`]*>/
  * whether a run closes, and what, depends on flanking rules and links that
  * this renderer does not follow, and a node needs at least one opener.
  * `containers` is the most container depth of the paragraph's lines, as a
- * lazy continuation line stays in containers it does not repeat.
+ * lazy continuation line stays in containers it does not repeat. `nodes`
+ * counts the code spans, links and footnote references, which Telegram
+ * caps per paragraph.
  */
 interface Inline {
   open: number
   containers: number
+  nodes: number
 }
 
+/** The inline nodes one paragraph may hold. Telegram refuses a paragraph past about 4,387. @internal */
+export const maxInlineNodes = 4000
+
+/** What one footnote reference costs against `maxInlineNodes`: its superscript, anchor and link. */
+const footnoteNodes = 3
+
+/** The footnote references one message may hold. Telegram refuses about 774 to one footnote. @internal */
+export const maxFootnoteReferences = 700
+
 interface LineContext {
   readonly tableRow: boolean
   readonly widePipes: boolean
   readonly setext: boolean
   readonly inline: Inline
   readonly mentions: ReadonlySet
+  /** Footnote references so far in the message. */
+  readonly footnotes: { count: number }
+  /**
+   * Whether a definition may start this line: after a blank line, the
+   * start of the text or another definition, outside containers. Set to
+   * whether this line kept one.
+   */
+  readonly definitions: { allowed: boolean }
 }
 
 /**
@@ -354,6 +393,20 @@ const renderLine = (line: string, context: LineContext): string => {
   const inline = context.inline
   inline.containers = Math.max(inline.containers, prefix.depth)
   const limit = Math.max(0, maxDepth - 1 - inline.containers)
+  /** Counts `n` inline nodes, or says no when the paragraph has no room left. */
+  const node = (n: number): boolean => {
+    if (inline.nodes + n > maxInlineNodes) return false
+    inline.nodes += n
+    return true
+  }
+  // Where the line's opening `[` is in `out`, for a definition refused at its `]:`.
+  const label = line[prefix.rest] === "[" ? prefix.text.length : undefined
+  let labelEscaped = false
+  const definitionAllowed = context.definitions.allowed && prefix.depth === 0
+  context.definitions.allowed = false
+  // The `[` that could still open a link, as CommonMark counts them: each
+  // \`]` takes the nearest, and a link takes them all.
+  let openers = 0
   let out = prefix.text
   let urlEnd = -1
   let i = prefix.rest
@@ -373,14 +426,14 @@ const renderLine = (line: string, context: LineContext): string => {
       continue
     }
     if (c === "\\" && next !== undefined && punctuation.test(next)) {
-      out += c + next
+      out += escapeOf(next)
       i += 2
       continue
     }
     switch (c) {
       case "`": {
         const end = inUrl ? undefined : codeSpanEnd(line, i, context.tableRow)
-        if (end !== undefined) {
+        if (end !== undefined && node(1)) {
           out += line.slice(i, end)
           i = end
           continue
@@ -393,7 +446,7 @@ const renderLine = (line: string, context: LineContext): string => {
       }
       case "<": {
         const match = inUrl ? null : autolink.exec(line.slice(i))
-        if (match !== null && /^(?:https?|mailto)$/i.test(match[1])) {
+        if (match !== null && /^(?:https?|mailto)$/i.test(match[1]) && node(1)) {
           out += match[0]
           i += match[0].length
         } else {
@@ -418,21 +471,62 @@ const renderLine = (line: string, context: LineContext): string => {
         out += next === "[" ? "\\!" : "!"
         i++
         continue
+      case "[":
+        // A footnote reference, unless it opens the line's footnote definition.
+        if (next === "^" && !(footnote && i === prefix.rest)) {
+          if (context.footnotes.count >= maxFootnoteReferences || !node(footnoteNodes)) {
+            out += "\\["
+            i++
+            continue
+          }
+          context.footnotes.count++
+        } else if (!inUrl) {
+          openers++
+        }
+        out += "["
+        i++
+        continue
       case "]": {
+        // Telegram closes a link at `]` even when it is escaped, so a refused
+        // link loses its `(` and a refused definition its opening `[`. A
+        // kept destination is sent verbatim, which is inert only if it is
+        // read as one: a link needs an opener on its line, a definition the
+        // start of a line where one may stand.
+        const opened = openers > 0
+        if (opened) openers--
         if (next === "(") {
           const tail = linkTail(line, i + 1)
-          if (tail !== undefined && allowedDestination(tail.destination, context.mentions)) {
-            out += "](" + escapeTail(line.slice(i + 2, tail.end - 1)) + ")"
+          if (
+            opened && tail !== undefined && allowedDestination(tail.destination, context.mentions) && node(1)
+          ) {
+            out += "](" + destinationOf(tail.destination) + ")"
             i = tail.end
+            openers = 0
             continue
           }
-          out += "\\]"
-        } else if (next === ":" && !(footnote && i === line.indexOf("]", prefix.rest))) {
-          const destination = definitionDestination(line, i + 2)
-          out += destination !== undefined && allowedDestination(destination, context.mentions) ? "]" : "\\]"
-        } else {
-          out += "]"
+          out += "]\\("
+          i += 2
+          continue
         }
+        if (next === ":" && !(footnote && i === line.indexOf("]", prefix.rest))) {
+          const definition = definitionDestination(line, i + 2)
+          if (
+            definitionAllowed && label !== undefined && i === line.indexOf("]", prefix.rest) &&
+            definition !== undefined && allowedDestination(definition.destination, context.mentions)
+          ) {
+            out += "]: " + destinationOf(definition.destination)
+            i = definition.end
+            context.definitions.allowed = true
+            continue
+          }
+          // Telegram reads a definition wherever the line's first `[` closes
+          // at a `]:`, also past other brackets.
+          if (label !== undefined && !labelEscaped && out[label] === "[") {
+            out = out.slice(0, label) + "\\" + out.slice(label)
+            labelEscaped = true
+          }
+        }
+        out += "]"
         i++
         continue
       }
@@ -443,9 +537,17 @@ const renderLine = (line: string, context: LineContext): string => {
         while (line[end] === c) end++
         const run = line.slice(i, end)
         const after = line[end]
+        const spaced = (ch: string | undefined) => ch === undefined || ch === " " || ch === "\t"
+        // A run with space on both sides is text to CommonMark, but Telegram
+        // opens emphasis with it: `2 * 3 * 4` (live check 2).
+        if (spaced(i === prefix.rest ? undefined : line[i - 1]) && spaced(after) && !thematicBreak.test(line)) {
+          out += run.split("").map((char) => "\\" + char).join("")
+          i = end
+          continue
+        }
         // A run of n delimiters can open n levels: `***a*b*c*` is three.
         // One followed by a space or the line's end can't open.
-        if (after !== undefined && after !== " " && after !== "\t") {
+        if (!spaced(after)) {
           if (inline.open + run.length > limit) {
             out += run.split("").map((char) => "\\" + char).join("")
             i = end
@@ -485,11 +587,20 @@ export interface RenderOptions {
  *   backslash with it. `$` and `=` are escaped (math, marks), except `=`
  *   under a paragraph of plain top-level lines (a setext heading), as is `|` outside tables
  *   (spoilers), and `!` before `[` (images).
+ * - A backslash escape Telegram ignores becomes a numeric character
+ *   reference, so `\<` is no HTML and `\]` closes no link.
  * - A link or reference definition whose destination, decoded as a
  *   Markdown parser and then a URL parser would, is not http, https or
- *   mailto has its `]` escaped, so it is text. A `tg://user` link stays
- *   for an id in `mentions`. A kept link's tail must end on its line and
- *   has its syntax characters escaped.
+ *   mailto is text: a link loses its `(`, a definition its opening `[`.
+ *   A `tg://user` link stays for an id in `mentions`. A kept link needs its
+ *   `[` and its whole tail on its line, a kept definition the top level
+ *   after a blank line or another definition. Its destination is sent as
+ *   Telegram reads it, verbatim, and its title is dropped.
+ * - A `*`, `_` or `~` run with space on both sides is escaped, outside a
+ *   thematic break: Telegram would open emphasis with it.
+ * - Code spans, links and footnote references past `maxInlineNodes` in a
+ *   paragraph, or footnote references past `maxFootnoteReferences` in the
+ *   message, are text.
  * - Container markers and emphasis past 16 levels are escaped. Every
  *   delimiter that could open emphasis counts as a level until the
  *   paragraph ends, at a blank line or a line that surely starts a block,
@@ -542,7 +653,9 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     for (const row of rows) tableRows.set(row, columns > maxColumns || cellCount(lines[row]) > maxColumns)
     i = end - 1
   }
-  const inline: Inline = { open: 0, containers: 0 }
+  const inline: Inline = { open: 0, containers: 0, nodes: 0 }
+  const footnotes = { count: 0 }
+  const definitions = { allowed: true }
   let item: string | undefined
   // Whether every line since the last blank one is plain text at the top
   // level: no container, definition, table or other block that a `=` under
@@ -552,15 +665,29 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     const blank = isBlank(line)
     const setext = plain && i > 0 && !isBlank(lines[i - 1]) && /^ {0,3}=+[ \t]*$/.test(line)
     plain = !fenced[i] && (blank || (plain && !/^\s/.test(line) && !blockStart.test(line) && !line.includes("|")))
-    if (fenced[i]) return line
+    if (fenced[i]) {
+      definitions.allowed = false
+      return line
+    }
     const wide = tableRows.get(i)
     const starts = blank ? undefined : startsBlock(line, item)
     item = typeof starts === "string" ? starts : undefined
     if (blank || starts !== undefined || wide !== undefined) {
       inline.open = 0
       inline.containers = 0
+      inline.nodes = 0
     }
-    return renderLine(line, { tableRow: wide !== undefined, widePipes: wide === true, setext, inline, mentions })
+    const rendered = renderLine(line, {
+      tableRow: wide !== undefined,
+      widePipes: wide === true,
+      setext,
+      inline,
+      mentions,
+      footnotes,
+      definitions
+    })
+    if (blank) definitions.allowed = true
+    return rendered
   })
   let text = out.join("\n")
   const files = options.files ?? 0
diff --git a/packages/chat/telegram/test/TelegramChat.test.ts b/packages/chat/telegram/test/TelegramChat.test.ts
index b1a5fd3efd1..f8d74d2bae5 100644
--- a/packages/chat/telegram/test/TelegramChat.test.ts
+++ b/packages/chat/telegram/test/TelegramChat.test.ts
@@ -171,6 +171,31 @@ const webhook = Effect.fnUntraced(function*(
     ).pipe(Effect.map((response) => response.status))
 })
 
+describe("errors", () => {
+  it.effect("maps the rich message errors captured in live check 10", () =>
+    Effect.gen(function*() {
+      const captured: ReadonlyArray = [
+        ["RICH_MESSAGE_TEXT_TOO_LONG", "TooLarge", "message_too_long"],
+        ["RICH_MESSAGE_TOO_LARGE", "TooLarge", "message_too_large"],
+        ["RICH_MESSAGE_BLOCKS_TOO_MANY", "TooLarge", "too_many_blocks"],
+        ["RICH_MESSAGE_DEPTH_INVALID", "InvalidRequest", "too_deep"],
+        ["RICH_MESSAGE_TABLE_COLS_TOO_MANY", "InvalidRequest", "too_many_columns"],
+        ["RICH_MESSAGE_EMPTY", "InvalidRequest", "empty_message"],
+        ["RICH_MESSAGE_MARKDOWN_INVALID", "InvalidRequest", "invalid_markdown"]
+      ]
+      for (const [description, tag, detail] of captured) {
+        const api = makeApi()
+        api.next.set("sendRichMessage", apiError(400, `Bad Request: ${description}`))
+        const error = yield* Effect.flatMap(Chat.Chat, (chat) => chat.post(thread, { markdown: "hi" })).pipe(
+          Effect.flip,
+          Effect.provide(telegramLayer(api))
+        )
+        assert.strictEqual(error.reason._tag, tag, description)
+        assert.strictEqual("detail" in error.reason ? error.reason.detail : undefined, detail, description)
+      }
+    }))
+})
+
 describe("layerWebhook", () => {
   it.effect("needs the secret, then answers for the body and the outcome", () =>
     Effect.gen(function*() {
diff --git a/packages/chat/telegram/test/gfm.ts b/packages/chat/telegram/test/gfm.ts
index 6c7fca9d6d3..6f25e68436d 100644
--- a/packages/chat/telegram/test/gfm.ts
+++ b/packages/chat/telegram/test/gfm.ts
@@ -13,8 +13,16 @@ export interface Findings {
   readonly blocks: number
   /** Text that reached the parser with an unescaped `|`, `$` or `=`, Telegram's spoiler, math and mark syntax. */
   readonly active: ReadonlyArray
+  /**
+   * Text holding a backslash escape Telegram does not honor, which it shows
+   * as a backslash and then reads the character as syntax (live check 2).
+   */
+  readonly unhonored: ReadonlyArray
 }
 
+/** Punctuation whose backslash escape Telegram honors. */
+const honored = /[!#$()*+\-.=>[\\_`{|}~]/
+
 const nesting = new Set(["blockquote", "listItem", "emphasis", "strong", "delete"])
 const blockTypes = new Set([
   "paragraph",
@@ -38,6 +46,7 @@ export const inspect = (markdown: string): Findings => {
   let maxColumns = 0
   let blocks = 0
   const active: Array = []
+  const unhonored: Array = []
   const visit = (node: Mdast.Nodes, depth: number) => {
     const d = nesting.has(node.type) ? depth + 1 : depth
     maxDepth = Math.max(maxDepth, d)
@@ -47,6 +56,9 @@ export const inspect = (markdown: string): Findings => {
         if (node.position === undefined) break
         const source = markdown.slice(node.position.start.offset, node.position.end.offset)
         if (/(?:^|[^\\])(?:\\\\)*[|$=]/.test(source)) active.push(source)
+        for (const match of source.matchAll(/(?:^|[^\\])(?:\\\\)*\\([!-/:-@[-`{-~])/g)) {
+          if (!honored.test(match[1])) unhonored.push(source)
+        }
         break
       }
       case "html":
@@ -71,5 +83,5 @@ export const inspect = (markdown: string): Findings => {
     if ("children" in node) { for (const child of node.children) visit(child as Mdast.Nodes, d) }
   }
   visit(parse(markdown), 0)
-  return { html, images, links, maxDepth, maxColumns, blocks, active }
+  return { html, images, links, maxDepth, maxColumns, blocks, active, unhonored }
 }
diff --git a/packages/chat/telegram/test/live.test.ts b/packages/chat/telegram/test/live.test.ts
new file mode 100644
index 00000000000..edd4320b5a9
--- /dev/null
+++ b/packages/chat/telegram/test/live.test.ts
@@ -0,0 +1,75 @@
+/**
+ * The conformance suite against the real Bot API. Opt-in: it runs only when
+ * these are set, so CI skips it.
+ *
+ * - `TELEGRAM_LIVE_BOT_TOKEN` and `TELEGRAM_LIVE_CHAT`: the bot and a group
+ *   it may write to, as a chat id.
+ * - `TELEGRAM_LIVE_BOT2_TOKEN`: a second bot in the group, for the rules
+ *   that need another identity's message. Its message is sent with
+ *   `sendMessage` and normalised as an inbound update, since bots never
+ *   receive each other's messages. Without it those rules fail at
+ *   `userPosts`.
+ *
+ * Only the default capabilities run: files, buttons and commands stay off
+ * until their own live checks pass.
+ */
+import * as TelegramBotApi from "@effect/chat-telegram/TelegramBotApi"
+import * as TelegramChat from "@effect/chat-telegram/TelegramChat"
+import { describe, it } from "@effect/vitest"
+import * as Chat from "effect/chat/Chat"
+import type * as ChatEvent from "effect/chat/ChatEvent"
+import { conformance } from "effect/chat/ChatTest"
+import type * as ChatThread from "effect/chat/ChatThread"
+import * as Effect from "effect/Effect"
+import * as FetchHttpClient from "effect/http/FetchHttpClient"
+import * as Layer from "effect/Layer"
+import * as Redacted from "effect/Redacted"
+import * as Semaphore from "effect/Semaphore"
+
+const botToken = process.env.TELEGRAM_LIVE_BOT_TOKEN
+const secondToken = process.env.TELEGRAM_LIVE_BOT2_TOKEN
+const chat = process.env.TELEGRAM_LIVE_CHAT
+
+describe.skipIf(botToken === undefined || chat === undefined)("live conformance", () => {
+  const layer = TelegramChat.layer({ token: Redacted.make(botToken!) }).pipe(
+    Layer.provideMerge(Chat.layer),
+    Layer.provide(FetchHttpClient.layer)
+  )
+
+  /** Posts as the second bot and normalises the answer as the update the first bot would get. */
+  const userPosts = (thread: ChatThread.ChatThread, text: string): Effect.Effect =>
+    Effect.gen(function*() {
+      if (secondToken === undefined) return yield* Effect.die(new Error("TELEGRAM_LIVE_BOT2_TOKEN is not set"))
+      const parts = TelegramChat.parts(thread)
+      if (parts._tag === "None") return yield* Effect.die(new Error("not a Telegram thread"))
+      const second = yield* TelegramBotApi.make({ token: Redacted.make(secondToken) })
+      const message = yield* second.call("sendMessage", {
+        chat_id: Number(parts.value.chatId),
+        ...(parts.value.messageThreadId === undefined
+          ? {}
+          : { message_thread_id: Number(parts.value.messageThreadId) }),
+        text
+      }, { write: true })
+      const bot = yield* TelegramBotApi.TelegramBotApi
+      const me = yield* bot.call("getMe")
+      const events = TelegramChat.normalize({ update_id: 1, message }, {
+        botId: bot.botId,
+        botUsername: (me as { readonly username: string }).username
+      })
+      if (events.length !== 1) return yield* Effect.die(new Error("userPosts did not normalise to one event"))
+      return events[0]
+    }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer), Effect.orDie)
+
+  const rules = conformance({
+    platform: "telegram",
+    thread: TelegramChat.thread(chat ?? "0"),
+    userPosts,
+    parseMention: TelegramChat.parseMention
+  })
+
+  // The rules share one group and Telegram paces group writes, so one rule at a time.
+  const one = Semaphore.makeUnsafe(1)
+  for (const [name, rule] of Object.entries(rules)) {
+    it.live(name, () => rule.pipe(Effect.provide(layer), Semaphore.withPermits(one, 1)), 600_000)
+  }
+})
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 4d9f61d9a21..7f6b9660103 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -7,6 +7,8 @@
 import {
   maxColumns,
   maxDepth,
+  maxFootnoteReferences,
+  maxInlineNodes,
   measure,
   messageLength,
   render,
@@ -19,19 +21,37 @@ import { inspect } from "./gfm.ts"
 /** The most blocks Telegram renders in one message. */
 const maxBlocks = 500
 
+// Live check 2 found that Telegram ignores the escapes `\]` and `\<`, reads destinations
+// verbatim, reads definitions more loosely than CommonMark and opens emphasis
+// between spaces: the last six cases.
 const cases: ReadonlyArray = [
   ["hi  ", "<b>hi</b>  <javascript:alert(1)>"],
   ["![a](https://e.com/a.png) ![b][r]", "\\![a](https://e.com/a.png) \\![b][r]"],
-  ["[me](tg://user?id=1) [ok](tg://user?id=2)", "[me\\](tg://user?id\\=1) [ok](tg://user?id\\=2)"],
+  ["[me](tg://user?id=1) [ok](tg://user?id=2)", "[me]\\(tg://user?id\\=1) [ok](tg://user?id=2)"],
   [
     "[a](tg://x) [b](tg%3A//x) [c](tg\\://x) [d](javascript:x)",
-    "[a\\](tg://x) [b\\](tg%3A//x) [c\\](tg\\://x) [d\\](javascript:x)"
+    "[a]\\(tg://x) [b]\\(tg%3A//x) [c]\\(tg://x) [d]\\(javascript:x)"
   ],
-  ["[r]\n\n[r]: tg://user?id=1", "[r]\n\n[r\\]: tg://user?id\\=1"],
+  ["[r]\n\n[r]: tg://user?id=1", "[r]\n\n\\[r]: tg://user?id\\=1"],
   ["$x$ ==m== ||s||", "\\$x\\$ \\=\\=m\\=\\= \\|\\|s\\|\\|"],
   ["| a | b |\n|---|---|\n| 1 | 2 |", "| a | b |\n|---|---|\n| 1 | 2 |"],
   ["`` and `open", "`` and \\`open"],
-  [">".repeat(17) + " x", ">".repeat(15) + "\\>\\> x"]
+  [">>>>>>>>>>>>>>>>> x", ">>>>>>>>>>>>>>>\\>\\> x"],
+  ["[x\\](tg://resolve?domain=telegram) \\x\\", "[x](tg://resolve?domain\\=telegram) <b>x</b>"],
+  [
+    "[a](https://e.com/?q=1&x=2 \"t\") [b](https://e.com/a_b*c\\(d\\))",
+    "[a](https://e.com/?q=1&x=2) [b](https://e.com/a_b*c%28d%29)"
+  ],
+  [
+    "](https://e.com||s||) [a [b](https://e.com) c](https://e.com)",
+    "]\\(https://e.com\\|\\|s\\|\\|) [a [b](https://e.com) c]\\(https://e.com)"
+  ],
+  [
+    "[a][b]: tg://x\n\n [c]: tg://x\n\ntext\n[d]: https://e.com",
+    "\\[a][b]: tg://x\n\n \\[c]: tg://x\n\ntext\n\\[d]: https://e.com"
+  ],
+  ["a\\:b \\@c \\^d \\&", "a:b @c ^d &amp;"],
+  ["2 * 3 * 4 a _ b\n\n***", "2 \\* 3 \\* 4 a \\_ b\n\n***"]
 ]
 
 const bytes = (s: string) => new TextEncoder().encode(s).length
@@ -51,6 +71,7 @@ const assertInert = (input: string) => {
     context
   )
   assert.deepStrictEqual(found.active, [], context)
+  assert.deepStrictEqual(found.unhonored, [], context)
   assert.isAtMost(found.maxDepth, maxDepth, context)
   assert.isAtMost(found.maxColumns, maxColumns, context)
   if (measure(input) <= messageLength) assert.isAtMost(found.blocks, maxBlocks, context)
@@ -165,6 +186,15 @@ describe("render", () => {
     )
   })
 
+  it("caps the code spans, links and footnote references Telegram refuses past a limit", () => {
+    const spans = render("`a` ".repeat(maxInlineNodes + 10))
+    assert.strictEqual(spans.match(/(? "x[^1]".repeat(100)).join("\n\n") + "\n\n[^1]: n")
+    assert.strictEqual(references.match(/(? {
     const row = (cell: string) => "|" + ` ${cell} |`.repeat(21)
     const out = render(row("c") + "\n" + row("-"))

From 754c1b6c3b5098516217dbb3d318be2bb3e2d6ff Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 13:35:44 +1300
Subject: [PATCH 82/89] chat-telegram: record live checks 8 and 9

Clicks carry Telegram's current keyboard, which caps at 100 buttons and
8 per row without an error. Ephemeral commands arrive with message_id 0,
ephemeral_message_id and receiver_user and take only the command path.
Private answers are refused and nothing is posted. The bystander half of
check 9 and forged click data were not tried.
---
 packages/chat/telegram/README.md | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index b60e384ef81..4a71c97f61b 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -2,7 +2,7 @@
 
 A [Telegram](https://telegram.org) adapter for `effect/chat`, over the Bot API. It includes a webhook endpoint, a long-polling loop, a pure update normaliser, and the address helpers.
 
-This package is private, and it is not released. The base live checks (1, 2, 3, 4, 5, 7, 10, 11, 15, 16 and 17) ran against production on 16 Nov 2026, and their results are below. Check 17 still needs check 9. Files, buttons and commands are not verified. Releasing it means removing `private`, adding the package to the release setup, and adding its changeset.
+This package is private, and it is not released. The base live checks (1, 2, 3, 4, 5, 7, 10, 11, 15, 16 and 17) ran against production on 16 Nov 2026, and their results are below. Checks 8 and 9 ran too, except for a forged click and check 9's bystander, which needs a second person. Files and reactions are not verified. Releasing it means removing `private`, adding the package to the release setup, and adding its changeset.
 
 ## Setup
 
@@ -95,7 +95,7 @@ A crash before the commit leaves nothing, and the repeat does the work. A concur
 
 ## Live checks
 
-Checks 1 to 5, 7, 10, 11 and 13 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin bot and a forum supergroup. That also covers check 17, except for 9. `test/live.test.ts` runs the conformance suite against the Bot API when `TELEGRAM_LIVE_BOT_TOKEN`, `TELEGRAM_LIVE_BOT2_TOKEN` and `TELEGRAM_LIVE_CHAT` are set.
+Checks 1 to 5, 7 to 11 and 13 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin bot, one person and a forum supergroup. That also covers check 17, except for check 9's bystander. `test/live.test.ts` runs the conformance suite against the Bot API when `TELEGRAM_LIVE_BOT_TOKEN`, `TELEGRAM_LIVE_BOT2_TOKEN` and `TELEGRAM_LIVE_CHAT` are set.
 
 1. Rich messages render on macOS desktop and mobile clients. Not seen: Web, Android and older clients.
 2. The rich-Markdown dialect, the escapes Telegram honors, and its readings of links, definitions and emphasis. The escaping follows what it found.
@@ -104,8 +104,8 @@ Checks 1 to 5, 7, 10, 11 and 13 to 16 ran on production on 16 Nov 2026, with a b
 5. A plain `@user` notifies nobody, and an allowed `tg://user` link is a mention.
 6. Not run: rich-message media over multipart `attach://`, and edits of a message with media.
 7. Webhook redelivery after a 503 or a dropped connection, as described under Redelivery.
-8. Not run: callback queries, the server's copy of `reply_markup`, forged `data`, delayed clicks.
-9. Not run: ephemeral commands, with an author and a bystander.
+8. Callback queries carry Telegram's copy of `reply_markup`, which an edit replaces. Telegram keeps at most 100 buttons and 8 per row, and drops the rest without an error. A click answered at the 2.5-second deadline stops spinning about 4 seconds after the tap. Not tried: a forged `data` from a modified client.
+9. Commands, with the author only. A typed command and one picked from the menu arrive alike. In a group, a command registered with `is_ephemeral` arrives with `message_id` 0, an `ephemeral_message_id` and `receiver_user`, and goes only to the command handler; in a private chat it is an ordinary command. A private answer is refused with `Unsupported` and nothing is posted. A public follow-up within 15 seconds replies to the command, and later fails `NotFound` with `interaction_expired`. Not tried: a bystander.
 10. The error responses behind the error mapping.
 11. Forum topics and the General topic. Topics in private chats were not tried.
 12. Not run: reaction updates.
@@ -113,7 +113,7 @@ Checks 1 to 5, 7, 10, 11 and 13 to 16 ran on production on 16 Nov 2026, with a b
 14. `getChatMember` as a non-admin works for members and non-members, and fails `NotFound` for another bot.
 15. A plain `@bot` mention does not reach a bot in privacy mode. A reply does.
 16. Inbound rich messages: a bot never receives another bot's messages, so they arrive only as a reply target, with `rich_message` and no `text`.
-17. A production smoke check of 1, 4, 5, 9, 13 and 15: all but 9 ran.
+17. A production smoke check of 1, 4, 5, 9, 13 and 15: all ran, except check 9's bystander.
 
 ## Links
 

From 7ec491bc53eaa82f7fc35f7a04c5b08d58d80d1c Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 13:40:33 +1300
Subject: [PATCH 83/89] chat-telegram: make the package publishable

The base live checks passed on production after the renderer fixes, so
@effect/chat-telegram is no longer private. It joins the fixed release
group and the effect-chat changeset, and is listed in the root README.
Files, buttons and commands stay behind the unverified options.
---
 .changeset/config.json              | 1 +
 .changeset/effect-chat.md           | 3 ++-
 README.md                           | 1 +
 packages/chat/telegram/README.md    | 2 +-
 packages/chat/telegram/package.json | 1 -
 5 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/.changeset/config.json b/.changeset/config.json
index 707bc0d160f..67552f02d7a 100644
--- a/.changeset/config.json
+++ b/.changeset/config.json
@@ -26,6 +26,7 @@
       "@effect/chat-slack",
       "@effect/chat-whatsapp",
       "@effect/chat-discord",
+      "@effect/chat-telegram",
       "@effect/atom-solid",
       "@effect/atom-vue",
       "@effect/docgen",
diff --git a/.changeset/effect-chat.md b/.changeset/effect-chat.md
index 9c627b56174..857b94d55a8 100644
--- a/.changeset/effect-chat.md
+++ b/.changeset/effect-chat.md
@@ -3,9 +3,10 @@
 "@effect/chat-slack": patch
 "@effect/chat-discord": patch
 "@effect/chat-whatsapp": patch
+"@effect/chat-telegram": patch
 ---
 
-Add unstable `effect/chat` APIs and Slack, Discord and WhatsApp adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
+Add unstable `effect/chat` APIs and Slack, Discord, WhatsApp and Telegram adapters for chat bots, with grapheme-safe Markdown streaming, buttons, selects, modals, slash commands, private/deferred command replies, and adapter conformance testing.
 
 Slack webhook and interactivity layers, and the WhatsApp webhook layer, require a `Mac` service. Provide a runtime layer such as `NodeCrypto.layerMac`, or `Mac.layerWebCrypto` with `SecureRandom.layerWebCrypto`.
 
diff --git a/README.md b/README.md
index 8aca4de4317..590e44bec4b 100644
--- a/README.md
+++ b/README.md
@@ -87,6 +87,7 @@ This monorepo contains the core `effect` package alongside integration packages
 | [`@effect/chat-slack`](packages/chat/slack)                           | Slack adapter for `effect/chat`                          | [docs](https://effect.website/docs/v4/api/chat-slack)              |
 | [`@effect/chat-whatsapp`](packages/chat/whatsapp)                     | WhatsApp Cloud API adapter for `effect/chat`             | [docs](https://effect.website/docs/v4/api/chat-whatsapp)           |
 | [`@effect/chat-discord`](packages/chat/discord)                       | Discord adapter for `effect/chat`                        | [docs](https://effect.website/docs/v4/api/chat-discord)            |
+| [`@effect/chat-telegram`](packages/chat/telegram)                     | Telegram Bot API adapter for `effect/chat`               | [docs](https://effect.website/docs/v4/api/chat-telegram)           |
 | [`@effect/atom-react`](packages/atom/react)                           | React bindings for Effect Atom                           | [docs](https://effect.website/docs/v4/api/atom-react)              |
 | [`@effect/atom-solid`](packages/atom/solid)                           | SolidJS bindings for Effect Atom                         | [docs](https://effect.website/docs/v4/api/atom-solid)              |
 | [`@effect/atom-vue`](packages/atom/vue)                               | Vue bindings for Effect Atom                             | [docs](https://effect.website/docs/v4/api/atom-vue)                |
diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index 4a71c97f61b..04c6eec3324 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -2,7 +2,7 @@
 
 A [Telegram](https://telegram.org) adapter for `effect/chat`, over the Bot API. It includes a webhook endpoint, a long-polling loop, a pure update normaliser, and the address helpers.
 
-This package is private, and it is not released. The base live checks (1, 2, 3, 4, 5, 7, 10, 11, 15, 16 and 17) ran against production on 16 Nov 2026, and their results are below. Checks 8 and 9 ran too, except for a forged click and check 9's bystander, which needs a second person. Files and reactions are not verified. Releasing it means removing `private`, adding the package to the release setup, and adding its changeset.
+The live checks ran against production on 16 Nov 2026, and their results are below. Not verified: files, reactions, a forged click, and what a bystander sees of a command. Files, buttons and commands stay behind the `unverified` options.
 
 ## Setup
 
diff --git a/packages/chat/telegram/package.json b/packages/chat/telegram/package.json
index 9066c42639f..462ef4c2c78 100644
--- a/packages/chat/telegram/package.json
+++ b/packages/chat/telegram/package.json
@@ -1,7 +1,6 @@
 {
   "name": "@effect/chat-telegram",
   "version": "4.1.4",
-  "private": true,
   "type": "module",
   "license": "MIT",
   "description": "The Telegram Bot API adapter for effect/chat",

From 418065ff35a39fa1a122f46a4d6c74fbbc2306b2 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 00:51:19 +0000
Subject: [PATCH 84/89] chat-telegram: keep a destination only behind an
 unambiguous label
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

A kept link's destination is sent verbatim, which is inert only if it is
read as a link. A nested label, a full or collapsed reference before it
(`[a][b](…)`, `[a][](…)`) or a footnote reference can each leave the
outer brackets as text, and the destination as Markdown. A destination
is now kept only when its label holds no other bracket and no `]` comes
right before it.

- Each `[` that could open a link or reference counts toward
  maxInlineNodes, so shortcut and full references are capped too.
- A destination with unbalanced parentheses is no link to CommonMark,
  so it is no longer kept.
- A `[` that starts a line and is not closed on it is escaped, since a
  definition's label may end on a later line.
- The GFM oracle reads escapes in one pass, so `\!\` is caught,
  and counts inline nodes per paragraph for assertInert.
- The live suite runs only when all three variables are set, as the
  README says. The README no longer claims cross-chat stalling, which
  was not tried, and lists the polling side of check 7 as not run.
---
 packages/chat/telegram/README.md              | 10 ++--
 .../chat/telegram/src/internal/markdown.ts    | 50 +++++++++++++------
 packages/chat/telegram/test/gfm.ts            | 33 ++++++++++--
 packages/chat/telegram/test/live.test.ts      | 10 ++--
 packages/chat/telegram/test/markdown.test.ts  | 32 +++++++++++-
 5 files changed, 104 insertions(+), 31 deletions(-)

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index 04c6eec3324..e73413d4ff7 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -69,15 +69,15 @@ Updates from business connections, a channel's direct messages and guest mode ar
 
   const App = Webhook.pipe(Layer.provideMerge(RedactSecret))
   ```
-- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, and a definition only at the top level after a blank line.
-- Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading; a `*` or `_` with space on both sides is escaped, as Telegram would open emphasis with it; and past 15 delimiters that could open emphasis, or 4,000 code spans, links and footnote references in one paragraph, or 700 footnote references in a message, the rest are shown as written. Telegram still pairs emphasis more loosely than CommonMark: `a* b*` is italic.
+- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, its label has no other bracket in it and no `]` comes right before it, and a definition only at the top level after a blank line.
+- Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading; a `*` or `_` with space on both sides is escaped, as Telegram would open emphasis with it; and past 15 delimiters that could open emphasis, or 4,000 code spans, footnote references and `[` that could open a link or reference in one paragraph, or 700 footnote references in a message, the rest are shown as written. Telegram still pairs emphasis more loosely than CommonMark: `a* b*` is italic.
 - A click is dispatched only when its `data` matches a button in Telegram's own copy of the message. That shows the bot put the button there, not that it is still current or that this user may press it.
 
 ## Redelivery
 
 Telegram sends an update again until it gets a 200, clicks and commands included. Polling sees it again until the offset moves past it. The webhook answers 503 when the `ChatHandler` fails `NotAccepted` or passes `deadline` (10 seconds), and Telegram retries. Polling retries an update up to `maxAttempts` times, then logs it and moves on.
 
-Telegram delivers updates in order, for the whole bot: while one is refused, the ones after it wait. It retries after about 0.3, 2, 4, 8, 16 and 32 seconds, keeping the `update_id`, and gives up on a webhook request after 60 seconds. A handler that refuses a lot stalls every chat, so `NotAccepted` is for short outages.
+Telegram delivers webhook updates in order: while one is refused, the ones after it wait. This was seen in one chat. Whether updates for other chats wait too was not tried, so assume a refused update can stall every chat, and keep `NotAccepted` for short outages. Telegram retries after about 0.3, 2, 4, 8, 16 and 32 seconds, keeping the `update_id`, and gives up on a webhook request after 60 seconds.
 
 Clicks and commands are different. Their handlers have a deadline of their own, and when it passes the update counts as answered: the webhook answers 200 and polling moves its offset. Telegram does not send it again.
 
@@ -95,7 +95,7 @@ A crash before the commit leaves nothing, and the repeat does the work. A concur
 
 ## Live checks
 
-Checks 1 to 5, 7 to 11 and 13 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin bot, one person and a forum supergroup. That also covers check 17, except for check 9's bystander. `test/live.test.ts` runs the conformance suite against the Bot API when `TELEGRAM_LIVE_BOT_TOKEN`, `TELEGRAM_LIVE_BOT2_TOKEN` and `TELEGRAM_LIVE_CHAT` are set.
+Checks 1 to 5, 7 to 11 and 13 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin bot, one person and a forum supergroup. That also covers check 17, except for check 9's bystander. `test/live.test.ts` runs the conformance suite against the Bot API only when all of `TELEGRAM_LIVE_BOT_TOKEN`, `TELEGRAM_LIVE_BOT2_TOKEN` and `TELEGRAM_LIVE_CHAT` are set, so CI skips it.
 
 1. Rich messages render on macOS desktop and mobile clients. Not seen: Web, Android and older clients.
 2. The rich-Markdown dialect, the escapes Telegram honors, and its readings of links, definitions and emphasis. The escaping follows what it found.
@@ -103,7 +103,7 @@ Checks 1 to 5, 7 to 11 and 13 to 16 ran on production on 16 Nov 2026, with a bot
 4. No link preview on rich posts or edits.
 5. A plain `@user` notifies nobody, and an allowed `tg://user` link is a mention.
 6. Not run: rich-message media over multipart `attach://`, and edits of a message with media.
-7. Webhook redelivery after a 503 or a dropped connection, as described under Redelivery.
+7. Webhook redelivery after a 503 or a dropped connection, as described under Redelivery. Not run: the polling side, and whether a refused update holds back other chats.
 8. Callback queries carry Telegram's copy of `reply_markup`, which an edit replaces. Telegram keeps at most 100 buttons and 8 per row, and drops the rest without an error. A click answered at the 2.5-second deadline stops spinning about 4 seconds after the tap. Not tried: a forged `data` from a modified client.
 9. Commands, with the author only. A typed command and one picked from the menu arrive alike. In a group, a command registered with `is_ephemeral` arrives with `message_id` 0, an `ephemeral_message_id` and `receiver_user`, and goes only to the command handler; in a private chat it is an ordinary command. A private answer is refused with `Unsupported` and nothing is posted. A public follow-up within 15 seconds replies to the command, and later fails `NotFound` with `interaction_expired`. Not tried: a bystander.
 10. The error responses behind the error mapping.
diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
index b5a75825bcb..6e4d7345acf 100644
--- a/packages/chat/telegram/src/internal/markdown.ts
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -228,6 +228,8 @@ const linkTail = (line: string, start: number): { readonly destination: string;
       depth--
     }
   }
+  // CommonMark keeps only balanced parentheses in a destination.
+  if (depth > 0) return undefined
   const destination = line.slice(from, i)
   const spaced = blank(line[i])
   while (blank(line[i])) i++
@@ -404,9 +406,14 @@ const renderLine = (line: string, context: LineContext): string => {
   let labelEscaped = false
   const definitionAllowed = context.definitions.allowed && prefix.depth === 0
   context.definitions.allowed = false
-  // The `[` that could still open a link, as CommonMark counts them: each
-  // \`]` takes the nearest, and a link takes them all.
-  let openers = 0
+  // Where the `[` of a label with no other bracket in it is, until a `]`
+  // closes it. Only such a label keeps its destination: around a nested
+  // label, a reference or a footnote, whether the outer brackets make a
+  // link depends on definitions and on Telegram's precedence, and a raw
+  // tail would be read as Markdown.
+  let opener: number | undefined
+  // Where each `[` not yet closed on this line is in `out`.
+  const unclosed: Array = []
   let out = prefix.text
   let urlEnd = -1
   let i = prefix.rest
@@ -480,9 +487,17 @@ const renderLine = (line: string, context: LineContext): string => {
             continue
           }
           context.footnotes.count++
+          opener = undefined
         } else if (!inUrl) {
-          openers++
+          // Each `[` that could open a link or a reference counts as a node.
+          if (!node(1)) {
+            out += "\\["
+            i++
+            continue
+          }
+          opener = i
         }
+        unclosed.push(out.length)
         out += "["
         i++
         continue
@@ -492,16 +507,15 @@ const renderLine = (line: string, context: LineContext): string => {
         // kept destination is sent verbatim, which is inert only if it is
         // read as one: a link needs an opener on its line, a definition the
         // start of a line where one may stand.
-        const opened = openers > 0
-        if (opened) openers--
+        // Not `[a][b](…)` or `[a][](…)`, where `[a]` may be the link.
+        const plain = opener !== undefined && line[opener - 1] !== "]"
+        opener = undefined
+        unclosed.pop()
         if (next === "(") {
           const tail = linkTail(line, i + 1)
-          if (
-            opened && tail !== undefined && allowedDestination(tail.destination, context.mentions) && node(1)
-          ) {
+          if (plain && tail !== undefined && allowedDestination(tail.destination, context.mentions)) {
             out += "](" + destinationOf(tail.destination) + ")"
             i = tail.end
-            openers = 0
             continue
           }
           out += "]\\("
@@ -511,7 +525,7 @@ const renderLine = (line: string, context: LineContext): string => {
         if (next === ":" && !(footnote && i === line.indexOf("]", prefix.rest))) {
           const definition = definitionDestination(line, i + 2)
           if (
-            definitionAllowed && label !== undefined && i === line.indexOf("]", prefix.rest) &&
+            definitionAllowed && label !== undefined && out[label] === "[" && i === line.indexOf("]", prefix.rest) &&
             definition !== undefined && allowedDestination(definition.destination, context.mentions)
           ) {
             out += "]: " + destinationOf(definition.destination)
@@ -564,6 +578,9 @@ const renderLine = (line: string, context: LineContext): string => {
         i++
     }
   }
+  // A label left open at the start of a line could close on a later one,
+  // as a definition's.
+  if (label !== undefined && unclosed[0] === label) out = out.slice(0, label) + "\\" + out.slice(label)
   return out
 }
 
@@ -593,14 +610,17 @@ export interface RenderOptions {
  *   Markdown parser and then a URL parser would, is not http, https or
  *   mailto is text: a link loses its `(`, a definition its opening `[`.
  *   A `tg://user` link stays for an id in `mentions`. A kept link needs its
- *   `[` and its whole tail on its line, a kept definition the top level
+ *   `[` and its whole tail on its line, a label with no other bracket in
+ *   it, and no `]` right before it, a kept definition the top level
  *   after a blank line or another definition. Its destination is sent as
  *   Telegram reads it, verbatim, and its title is dropped.
  * - A `*`, `_` or `~` run with space on both sides is escaped, outside a
  *   thematic break: Telegram would open emphasis with it.
- * - Code spans, links and footnote references past `maxInlineNodes` in a
- *   paragraph, or footnote references past `maxFootnoteReferences` in the
- *   message, are text.
+ * - Code spans, `[` that could open a link or reference, and footnote
+ *   references past `maxInlineNodes` in a paragraph, or footnote
+ *   references past `maxFootnoteReferences` in the message, are text. A
+ *   `[` that starts a line and is not closed on it is escaped, as it could
+ *   open a definition whose label ends on a later line.
  * - Container markers and emphasis past 16 levels are escaped. Every
  *   delimiter that could open emphasis counts as a level until the
  *   paragraph ends, at a blank line or a line that surely starts a block,
diff --git a/packages/chat/telegram/test/gfm.ts b/packages/chat/telegram/test/gfm.ts
index 6f25e68436d..ef39a7b41ab 100644
--- a/packages/chat/telegram/test/gfm.ts
+++ b/packages/chat/telegram/test/gfm.ts
@@ -18,6 +18,12 @@ export interface Findings {
    * as a backslash and then reads the character as syntax (live check 2).
    */
   readonly unhonored: ReadonlyArray
+  /**
+   * The most inline nodes in one paragraph, as the renderer counts them:
+   * code spans, links and references written with `[` or `<`, and footnote
+   * references at three each. Bare URLs are not counted.
+   */
+  readonly inline: number
 }
 
 /** Punctuation whose backslash escape Telegram honors. */
@@ -47,17 +53,38 @@ export const inspect = (markdown: string): Findings => {
   let blocks = 0
   const active: Array = []
   const unhonored: Array = []
+  let inline = 0
+  /** The inline nodes under `node`, as `Findings.inline` counts them. */
+  const count = (node: Mdast.Nodes): number => {
+    const own = node.type === "inlineCode"
+      ? 1
+      : node.type === "footnoteReference"
+      ? 3
+      : (node.type === "link" || node.type === "linkReference") &&
+          /[[<]/.test(markdown[node.position?.start.offset ?? -1] ?? "")
+      ? 1
+      : 0
+    return "children" in node
+      ? node.children.reduce((sum, child) => sum + count(child as Mdast.Nodes), own)
+      : own
+  }
   const visit = (node: Mdast.Nodes, depth: number) => {
     const d = nesting.has(node.type) ? depth + 1 : depth
     maxDepth = Math.max(maxDepth, d)
     if (blockTypes.has(node.type)) blocks++
+    if (node.type === "paragraph" || node.type === "heading" || node.type === "tableCell") {
+      inline = Math.max(inline, count(node))
+    }
     switch (node.type) {
       case "text": {
         if (node.position === undefined) break
         const source = markdown.slice(node.position.start.offset, node.position.end.offset)
         if (/(?:^|[^\\])(?:\\\\)*[|$=]/.test(source)) active.push(source)
-        for (const match of source.matchAll(/(?:^|[^\\])(?:\\\\)*\\([!-/:-@[-`{-~])/g)) {
-          if (!honored.test(match[1])) unhonored.push(source)
+        // One pass, so that an escape right after another is still seen.
+        for (let i = 0; i < source.length; i++) {
+          if (source[i] !== "\\") continue
+          const next = source[++i]
+          if (next !== undefined && /[!-/:-@[-`{-~]/.test(next) && !honored.test(next)) unhonored.push(source)
         }
         break
       }
@@ -83,5 +110,5 @@ export const inspect = (markdown: string): Findings => {
     if ("children" in node) { for (const child of node.children) visit(child as Mdast.Nodes, d) }
   }
   visit(parse(markdown), 0)
-  return { html, images, links, maxDepth, maxColumns, blocks, active, unhonored }
+  return { html, images, links, maxDepth, maxColumns, blocks, active, unhonored, inline }
 }
diff --git a/packages/chat/telegram/test/live.test.ts b/packages/chat/telegram/test/live.test.ts
index edd4320b5a9..42e2e40fb37 100644
--- a/packages/chat/telegram/test/live.test.ts
+++ b/packages/chat/telegram/test/live.test.ts
@@ -1,14 +1,13 @@
 /**
  * The conformance suite against the real Bot API. Opt-in: it runs only when
- * these are set, so CI skips it.
+ * all three of these are set, so CI skips it.
  *
  * - `TELEGRAM_LIVE_BOT_TOKEN` and `TELEGRAM_LIVE_CHAT`: the bot and a group
  *   it may write to, as a chat id.
  * - `TELEGRAM_LIVE_BOT2_TOKEN`: a second bot in the group, for the rules
  *   that need another identity's message. Its message is sent with
  *   `sendMessage` and normalised as an inbound update, since bots never
- *   receive each other's messages. Without it those rules fail at
- *   `userPosts`.
+ *   receive each other's messages.
  *
  * Only the default capabilities run: files, buttons and commands stay off
  * until their own live checks pass.
@@ -30,7 +29,7 @@ const botToken = process.env.TELEGRAM_LIVE_BOT_TOKEN
 const secondToken = process.env.TELEGRAM_LIVE_BOT2_TOKEN
 const chat = process.env.TELEGRAM_LIVE_CHAT
 
-describe.skipIf(botToken === undefined || chat === undefined)("live conformance", () => {
+describe.skipIf(botToken === undefined || secondToken === undefined || chat === undefined)("live conformance", () => {
   const layer = TelegramChat.layer({ token: Redacted.make(botToken!) }).pipe(
     Layer.provideMerge(Chat.layer),
     Layer.provide(FetchHttpClient.layer)
@@ -39,10 +38,9 @@ describe.skipIf(botToken === undefined || chat === undefined)("live conformance"
   /** Posts as the second bot and normalises the answer as the update the first bot would get. */
   const userPosts = (thread: ChatThread.ChatThread, text: string): Effect.Effect =>
     Effect.gen(function*() {
-      if (secondToken === undefined) return yield* Effect.die(new Error("TELEGRAM_LIVE_BOT2_TOKEN is not set"))
       const parts = TelegramChat.parts(thread)
       if (parts._tag === "None") return yield* Effect.die(new Error("not a Telegram thread"))
-      const second = yield* TelegramBotApi.make({ token: Redacted.make(secondToken) })
+      const second = yield* TelegramBotApi.make({ token: Redacted.make(secondToken!) })
       const message = yield* second.call("sendMessage", {
         chat_id: Number(parts.value.chatId),
         ...(parts.value.messageThreadId === undefined
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 7f6b9660103..65662b34f1a 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -37,7 +37,7 @@ const cases: ReadonlyArray = [
   ["| a | b |\n|---|---|\n| 1 | 2 |", "| a | b |\n|---|---|\n| 1 | 2 |"],
   ["`` and `open", "`` and \\`open"],
   [">>>>>>>>>>>>>>>>> x", ">>>>>>>>>>>>>>>\\>\\> x"],
-  ["[x\\](tg://resolve?domain=telegram) \\x\\", "[x](tg://resolve?domain\\=telegram) <b>x</b>"],
+  ["[x\\](tg://resolve?domain=telegram) \\x\\", "\\[x](tg://resolve?domain\\=telegram) <b>x</b>"],
   [
     "[a](https://e.com/?q=1&x=2 \"t\") [b](https://e.com/a_b*c\\(d\\))",
     "[a](https://e.com/?q=1&x=2) [b](https://e.com/a_b*c%28d%29)"
@@ -74,6 +74,7 @@ const assertInert = (input: string) => {
   assert.deepStrictEqual(found.unhonored, [], context)
   assert.isAtMost(found.maxDepth, maxDepth, context)
   assert.isAtMost(found.maxColumns, maxColumns, context)
+  assert.isAtMost(found.inline, maxInlineNodes, context)
   if (measure(input) <= messageLength) assert.isAtMost(found.blocks, maxBlocks, context)
 }
 
@@ -99,6 +100,8 @@ const hostile = fc.string({
     "\\<",
     "\\`",
     // whitespace that is not a blank line to CommonMark
+    "[a]",
+    "\n[a]: mailto:x\n",
     "\u00a0",
     "\u3000",
     "\v",
@@ -156,7 +159,21 @@ describe("render", () => {
         "x|y\n\t---|---",
         // a line of U+00A0 is text, so it ends no paragraph
         ">".repeat(15) + " x\n\u00a0\n" + "_".repeat(14) + "x" + "_".repeat(14),
-        "[^a]: z\n\u00a0\nx|y\n---|---\n||secret||"
+        "[^a]: z\n\u00a0\nx|y\n---|---\n||secret||",
+        // a nested label, a reference or a footnote may turn the outer link
+        // into text, and its destination into Markdown
+        "[outer [inner]](mailto:[pwn](tg://user?id=1))\n\n[inner]: https://safe.com",
+        "[outer [inner]](mailto:![pwn](tg://document?id=f1))\n\n[inner]: https://safe.com",
+        "[outer [inner]](mailto:||spoiler||)\n\n[inner]: https://safe.com",
+        "[a][inner](mailto:[pwn](tg://user?id=1))\n\n[inner]: https://safe.com",
+        "[inner][](mailto:[pwn](tg://user?id=1))\n\n[inner]: https://safe.com",
+        "[x [^a]](mailto:[pwn](tg://user?id=1))\n\n[^a]: z",
+        "[x [^a](mailto:[pwn](tg://user?id=1))\n\n[^a]: z",
+        // unbalanced parentheses end no destination
+        "[](mailto:$(> )",
+        // a definition's label may span lines
+        "[\n[a]: [",
+        "[x\\](a)\n]: tg://user?id=1\n\n[x](a)\n]"
       ]
     ) assertInert(input)
     fc.assert(fc.property(hostile, (input) => assertInert(input)), { numRuns: 2000 })
@@ -191,10 +208,21 @@ describe("render", () => {
     assert.strictEqual(spans.match(/(? "x[^1]".repeat(100)).join("\n\n") + "\n\n[^1]: n")
     assert.strictEqual(references.match(/(? {
+    assert.deepStrictEqual(inspect(String.raw`\!\`).unhonored, [String.raw`\!\`])
+  })
+
   it("escapes the pipes of a table wider than 20 columns", () => {
     const row = (cell: string) => "|" + ` ${cell} |`.repeat(21)
     const out = render(row("c") + "\n" + row("-"))

From 1c7e7e65b0de4814aa4e1f42fadd65bf1bfeba3e Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 14:18:24 +1300
Subject: [PATCH 85/89] chat-telegram: record live checks 6 and 12

Rich-message media: up to 50 files per message (51 is refused with 413),
names and MIME types kept except some characters outside Latin-1, and an
edit drops the media. Downloads through the adapter are byte for byte.
Reactions carry the user's whole set before and after and normalise to
no event.
---
 packages/chat/telegram/README.md | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index e73413d4ff7..6725572f19c 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -2,7 +2,7 @@
 
 A [Telegram](https://telegram.org) adapter for `effect/chat`, over the Bot API. It includes a webhook endpoint, a long-polling loop, a pure update normaliser, and the address helpers.
 
-The live checks ran against production on 16 Nov 2026, and their results are below. Not verified: files, reactions, a forged click, and what a bystander sees of a command. Files, buttons and commands stay behind the `unverified` options.
+The live checks ran against production on 16 Nov 2026, and their results are below. Not verified: a forged click, and what a bystander sees of a command. Files, buttons and commands stay behind the `unverified` options.
 
 ## Setup
 
@@ -45,7 +45,7 @@ These capabilities are implemented but stay off until their live checks pass, on
 | `buttons`  | `buttons`  | 8                                  |
 | `commands` | `commands` | 9                                  |
 
-An edit of a message posted with files may drop its media. Live check 6 decides whether that is so.
+An edit of a message posted with files drops its media (live check 6).
 
 Not supported in this version: `ephemeral`, `fetchMessage`, `history`, `opener`, `startThread`, selects, modals, native streams, reactions (outbound and as events), and typing. A private answer to a command is refused through `ChatInteraction.Handler.refused` with `Unsupported`, and is never posted in public. A `message_reaction` update goes to `onUnhandled`.
 
@@ -95,20 +95,20 @@ A crash before the commit leaves nothing, and the repeat does the work. A concur
 
 ## Live checks
 
-Checks 1 to 5, 7 to 11 and 13 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin bot, one person and a forum supergroup. That also covers check 17, except for check 9's bystander. `test/live.test.ts` runs the conformance suite against the Bot API only when all of `TELEGRAM_LIVE_BOT_TOKEN`, `TELEGRAM_LIVE_BOT2_TOKEN` and `TELEGRAM_LIVE_CHAT` are set, so CI skips it.
+Checks 1 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin bot, one person and a forum supergroup. That also covers check 17, except for check 9's bystander. `test/live.test.ts` runs the conformance suite against the Bot API only when all of `TELEGRAM_LIVE_BOT_TOKEN`, `TELEGRAM_LIVE_BOT2_TOKEN` and `TELEGRAM_LIVE_CHAT` are set, so CI skips it.
 
 1. Rich messages render on macOS desktop and mobile clients. Not seen: Web, Android and older clients.
 2. The rich-Markdown dialect, the escapes Telegram honors, and its readings of links, definitions and emphasis. The escaping follows what it found.
 3. The limits: 32,768 rendered characters (non-ASCII text counts less), 500 blocks with a list counting one per item, 16 levels of nesting, 20 table columns, about 4,387 inline nodes per paragraph and about 773 references to one footnote. A code block is one block. `measure` stays under each of these.
 4. No link preview on rich posts or edits.
 5. A plain `@user` notifies nobody, and an allowed `tg://user` link is a mention.
-6. Not run: rich-message media over multipart `attach://`, and edits of a message with media.
+6. Rich-message media over multipart `attach://`: up to 50 files in one message, 51 is refused with 413; 10 MB files; file names and MIME types kept, except that Telegram turns some characters outside Latin-1, such as `–`, into spaces. An edit drops the media. A download through the adapter is byte for byte.
 7. Webhook redelivery after a 503 or a dropped connection, as described under Redelivery. Not run: the polling side, and whether a refused update holds back other chats.
 8. Callback queries carry Telegram's copy of `reply_markup`, which an edit replaces. Telegram keeps at most 100 buttons and 8 per row, and drops the rest without an error. A click answered at the 2.5-second deadline stops spinning about 4 seconds after the tap. Not tried: a forged `data` from a modified client.
 9. Commands, with the author only. A typed command and one picked from the menu arrive alike. In a group, a command registered with `is_ephemeral` arrives with `message_id` 0, an `ephemeral_message_id` and `receiver_user`, and goes only to the command handler; in a private chat it is an ordinary command. A private answer is refused with `Unsupported` and nothing is posted. A public follow-up within 15 seconds replies to the command, and later fails `NotFound` with `interaction_expired`. Not tried: a bystander.
 10. The error responses behind the error mapping.
 11. Forum topics and the General topic. Topics in private chats were not tried.
-12. Not run: reaction updates.
+12. Reaction updates reach an admin bot that asks for `message_reaction`, which the adapter does not. Each carries the user's whole set before and after, as `old_reaction` and `new_reaction`: add, change and remove each give one update. They normalise to no event. Not tried: custom and paid emoji, and `actor_chat`.
 13. Edit pacing: one edit every 3 seconds in a group gets no 429. Back-to-back edits got one after 19, with `retry_after` 43.
 14. `getChatMember` as a non-admin works for members and non-members, and fails `NotFound` for another bot.
 15. A plain `@bot` mention does not reach a bot in privacy mode. A reply does.

From 1e2ab2f876c17e43ca9d4da62e97188f5e40cbfb Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 14:27:29 +1300
Subject: [PATCH 86/89] chat-telegram: record the forged click check

As a user client, clicks with data not on the message's current
keyboard (forged, tampered, from another message, or from a keyboard an
edit replaced) are refused by Telegram with DATA_INVALID. Only genuine
clicks reach the adapter, whose own check is a second layer.
---
 packages/chat/telegram/README.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index 6725572f19c..a36df741d33 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -2,7 +2,7 @@
 
 A [Telegram](https://telegram.org) adapter for `effect/chat`, over the Bot API. It includes a webhook endpoint, a long-polling loop, a pure update normaliser, and the address helpers.
 
-The live checks ran against production on 16 Nov 2026, and their results are below. Not verified: a forged click, and what a bystander sees of a command. Files, buttons and commands stay behind the `unverified` options.
+The live checks ran against production on 16 Nov 2026, and their results are below. Not verified: what a bystander sees of a command. Files, buttons and commands stay behind the `unverified` options.
 
 ## Setup
 
@@ -71,7 +71,7 @@ Updates from business connections, a channel's direct messages and guest mode ar
   ```
 - Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, its label has no other bracket in it and no `]` comes right before it, and a definition only at the top level after a blank line.
 - Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading; a `*` or `_` with space on both sides is escaped, as Telegram would open emphasis with it; and past 15 delimiters that could open emphasis, or 4,000 code spans, footnote references and `[` that could open a link or reference in one paragraph, or 700 footnote references in a message, the rest are shown as written. Telegram still pairs emphasis more loosely than CommonMark: `a* b*` is italic.
-- A click is dispatched only when its `data` matches a button in Telegram's own copy of the message. That shows the bot put the button there, not that it is still current or that this user may press it.
+- A click is dispatched only when its `data` matches a button in Telegram's own copy of the message, and Telegram already refuses data that is not on the current keyboard (live check 8). Neither says that this user may press it.
 
 ## Redelivery
 
@@ -104,7 +104,7 @@ Checks 1 to 16 ran on production on 16 Nov 2026, with a bot, a second non-admin
 5. A plain `@user` notifies nobody, and an allowed `tg://user` link is a mention.
 6. Rich-message media over multipart `attach://`: up to 50 files in one message, 51 is refused with 413; 10 MB files; file names and MIME types kept, except that Telegram turns some characters outside Latin-1, such as `–`, into spaces. An edit drops the media. A download through the adapter is byte for byte.
 7. Webhook redelivery after a 503 or a dropped connection, as described under Redelivery. Not run: the polling side, and whether a refused update holds back other chats.
-8. Callback queries carry Telegram's copy of `reply_markup`, which an edit replaces. Telegram keeps at most 100 buttons and 8 per row, and drops the rest without an error. A click answered at the 2.5-second deadline stops spinning about 4 seconds after the tap. Not tried: a forged `data` from a modified client.
+8. Callback queries carry Telegram's copy of `reply_markup`, which an edit replaces. Telegram keeps at most 100 buttons and 8 per row, and drops the rest without an error. A click answered at the 2.5-second deadline stops spinning about 4 seconds after the tap. Telegram itself refuses, with `DATA_INVALID`, a click whose `data` is not on the message's current keyboard: forged, tampered, from another message, or from a keyboard an edit replaced. The adapter's own check is a second layer.
 9. Commands, with the author only. A typed command and one picked from the menu arrive alike. In a group, a command registered with `is_ephemeral` arrives with `message_id` 0, an `ephemeral_message_id` and `receiver_user`, and goes only to the command handler; in a private chat it is an ordinary command. A private answer is refused with `Unsupported` and nothing is posted. A public follow-up within 15 seconds replies to the command, and later fails `NotFound` with `interaction_expired`. Not tried: a bystander.
 10. The error responses behind the error mapping.
 11. Forum topics and the General topic. Topics in private chats were not tried.

From 173358c25d2485e1369f7d967c40d93d47aeb0fe Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 01:41:45 +0000
Subject: [PATCH 87/89] chat-telegram: keep a definition only where its label
 and destination are unambiguous

A line whose first [ meets a ]: is now decided up front from the raw
line: kept as a definition only at the top level after a blank line,
with a plain label (no bracket, code span, autolink or escaped ]), not
blank, not footnote-like, at most 999 characters, and nothing after an
allowed destination but a title. Otherwise its [ is escaped before the
line is read, so a raw destination never follows a label that is text.
Links and definitions share one destination scanner.

Also: autolinks refuse control characters; a footnote marker behind a
tab or four spaces is not a footnote; a delimiter row that is a list
item, or a lone pipe, heads no table; code spans split at pipes on lines
GFM may still read as table rows.
---
 packages/chat/telegram/README.md              |   2 +-
 .../chat/telegram/src/internal/markdown.ts    | 164 ++++++++++++------
 packages/chat/telegram/test/markdown.test.ts  |  40 ++++-
 3 files changed, 152 insertions(+), 54 deletions(-)

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index a36df741d33..ac37e83f0b7 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -69,7 +69,7 @@ Updates from business connections, a channel's direct messages and guest mode ar
 
   const App = Webhook.pipe(Layer.provideMerge(RedactSecret))
   ```
-- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, its label has no other bracket in it and no `]` comes right before it, and a definition only at the top level after a blank line.
+- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, its label has no other bracket in it and no `]` comes right before it, and its destination has balanced parentheses. A line whose first `[` meets a `]:` is kept as a definition only at the top level after a blank line, with a plain label that starts the line (no other bracket, code span, autolink or escaped `]`), and with nothing after its destination but a title. Otherwise its `[` is escaped.
 - Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading; a `*` or `_` with space on both sides is escaped, as Telegram would open emphasis with it; and past 15 delimiters that could open emphasis, or 4,000 code spans, footnote references and `[` that could open a link or reference in one paragraph, or 700 footnote references in a message, the rest are shown as written. Telegram still pairs emphasis more loosely than CommonMark: `a* b*` is italic.
 - A click is dispatched only when its `data` matches a button in Telegram's own copy of the message, and Telegram already refuses data that is not on the current keyboard (live check 8). Neither says that this user may press it.
 
diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
index 6e4d7345acf..ab5c4e39453 100644
--- a/packages/chat/telegram/src/internal/markdown.ts
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -170,7 +170,8 @@ const cellCount = (line: string): number => {
  */
 const isBlank = (line: string): boolean => /^[ \t]*$/.test(line)
 
-const hasPipe = (line: string) => cellCount(line) > 1 || line.trim().startsWith("|")
+/** Whether a line can head a table: GFM reads no cell in a lone `|`. */
+const hasPipe = (line: string) => (cellCount(line) > 1 || line.trim().startsWith("|")) && line.trim() !== "|"
 
 /** The decoded form of a link destination, as a Markdown parser and then a URL parser read it. */
 const decodeDestination = (raw: string): { readonly unescaped: string; readonly decoded: string } | undefined => {
@@ -202,15 +203,20 @@ const allowedDestination = (raw: string, mentions: ReadonlySet): boolean
   return mention !== null && destination.unescaped === destination.decoded && mentions.has(mention[1])
 }
 
+const blank = (c: string | undefined): boolean => c === " " || c === "\t"
+
 /**
- * A link's `(destination "title")` from the `(` at `start`, when all of it
- * is on this line and the destination is not in angle brackets. A tail
- * that goes on to the next line, as CommonMark allows, is not one: the
- * link is then refused.
+ * The destination and optional title from `start`, as CommonMark reads
+ * them when they are on this line: a destination not in angle brackets, up
+ * to a space, a control character or a `)` it did not open, with its
+ * parentheses balanced, then a title after a space. `end` is past the
+ * title and the blanks after it.
  */
-const linkTail = (line: string, start: number): { readonly destination: string; readonly end: number } | undefined => {
-  const blank = (c: string | undefined) => c === " " || c === "\t"
-  let i = start + 1
+const destinationAndTitle = (
+  line: string,
+  start: number
+): { readonly destination: string; readonly end: number } | undefined => {
+  let i = start
   while (blank(line[i])) i++
   if (line[i] === "<") return undefined
   const from = i
@@ -221,14 +227,14 @@ const linkTail = (line: string, start: number): { readonly destination: string;
       i++
       continue
     }
-    if (c.charCodeAt(0) <= 0x20) break
+    const code = c.charCodeAt(0)
+    if (code <= 0x20 || code === 0x7f) break
     if (c === "(") depth++
     else if (c === ")") {
       if (depth === 0) break
       depth--
     }
   }
-  // CommonMark keeps only balanced parentheses in a destination.
   if (depth > 0) return undefined
   const destination = line.slice(from, i)
   const spaced = blank(line[i])
@@ -244,7 +250,17 @@ const linkTail = (line: string, start: number): { readonly destination: string;
     i++
     while (blank(line[i])) i++
   }
-  return line[i] === ")" ? { destination, end: i + 1 } : undefined
+  return { destination, end: i }
+}
+
+/**
+ * A link's `(destination "title")` from the `(` at `start`, when all of it
+ * is on this line. A tail that goes on to the next line, as CommonMark
+ * allows, is not one: the link is then refused.
+ */
+const linkTail = (line: string, start: number): { readonly destination: string; readonly end: number } | undefined => {
+  const tail = destinationAndTitle(line, start + 1)
+  return tail !== undefined && line[tail.end] === ")" ? { destination: tail.destination, end: tail.end + 1 } : undefined
 }
 
 /**
@@ -277,15 +293,44 @@ const percentEncoded: Readonly> = {
   ">": "%3E"
 }
 
-/** The destination of a reference definition after `]:`, when it is on this line. */
-const definitionDestination = (
+/**
+ * The destination of a reference definition after `]:`, when the rest of
+ * the line is a nonempty destination and an optional title. Anything else
+ * after it, a title that goes on to the next line, or a destination there,
+ * makes it no definition here.
+ */
+const definitionDestination = (line: string, start: number): string | undefined => {
+  const tail = destinationAndTitle(line, start)
+  return tail !== undefined && tail.end === line.length ? tail.destination : undefined
+}
+
+/** The most characters CommonMark reads between a label's brackets. */
+const maxLabelLength = 999
+
+/**
+ * A label CommonMark and the renderer both close at its first `]`: no
+ * other bracket, code span or autolink in it, and no escape at its end.
+ */
+const simpleLabel = /^(?:[^\\[\]`<]|\\.)*$/
+
+/**
+ * The reference definition the line whose first `[` is at `start` may
+ * keep: a simple label, not blank, not a footnote's and at most 999
+ * characters, closed by `]:`, then a destination it allows.
+ */
+const keptDefinition = (
   line: string,
-  start: number
-): { readonly destination: string; readonly end: number } | undefined => {
-  const match = /^[ \t]*(\S+)/.exec(line.slice(start))
-  return match === null || match[1].startsWith("<")
-    ? undefined
-    : { destination: match[1], end: start + match[0].length }
+  start: number,
+  mentions: ReadonlySet
+): { readonly close: number; readonly destination: string } | undefined => {
+  const close = line.indexOf("]", start)
+  const text = line.slice(start + 1, close)
+  if (
+    close < 0 || line[close + 1] !== ":" || !simpleLabel.test(text) || isBlank(text) || text[0] === "^" ||
+    text.length > maxLabelLength
+  ) return undefined
+  const destination = definitionDestination(line, close + 2)
+  return destination !== undefined && allowedDestination(destination, mentions) ? { close, destination } : undefined
 }
 
 /**
@@ -321,7 +366,7 @@ const bareUrl = /^(?:https?:\/\/|www\.)/i
 /** A thematic break, whose delimiters stand alone. */
 const thematicBreak = /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/
 
-const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>`]*>/
+const autolink = /^<([A-Za-z][A-Za-z0-9+.-]{1,31}):[^\s<>`\p{Cc}]*>/u
 
 /**
  * What one paragraph may already nest. `open` counts every delimiter that
@@ -350,6 +395,8 @@ export const maxFootnoteReferences = 700
 
 interface LineContext {
   readonly tableRow: boolean
+  /** Whether GFM may read the line as a table row, which splits code spans at pipes. */
+  readonly cells: boolean
   readonly widePipes: boolean
   readonly setext: boolean
   readonly inline: Inline
@@ -391,7 +438,10 @@ const renderPrefix = (line: string): { readonly text: string; readonly rest: num
 
 const renderLine = (line: string, context: LineContext): string => {
   const prefix = renderPrefix(line)
-  const footnote = /^\[\^[\w-]+\]:/.test(line.slice(prefix.rest))
+  // A footnote definition opens a block, so not behind a tab or four
+  // spaces: there, after a definition, GFM reads one with a label `^a`.
+  const indent = /[ \t]*$/.exec(line.slice(0, prefix.rest))![0]
+  const footnote = !indent.includes("\t") && indent.length < 4 && /^\[\^[\w-]+\]:/.test(line.slice(prefix.rest))
   const inline = context.inline
   inline.containers = Math.max(inline.containers, prefix.depth)
   const limit = Math.max(0, maxDepth - 1 - inline.containers)
@@ -401,11 +451,20 @@ const renderLine = (line: string, context: LineContext): string => {
     inline.nodes += n
     return true
   }
-  // Where the line's opening `[` is in `out`, for a definition refused at its `]:`.
-  const label = line[prefix.rest] === "[" ? prefix.text.length : undefined
-  let labelEscaped = false
-  const definitionAllowed = context.definitions.allowed && prefix.depth === 0
+  // Telegram reads a definition wherever the line's first `[` closes at a
+  // `]:`, also past other brackets, code or autolinks, and GFM reads one
+  // at the start of a footnote's text. One is kept only where CommonMark
+  // reads the same, with a label and destination both accept. Otherwise
+  // the line's `[` is escaped before it is read, so no raw destination is
+  // sent behind a label that is text.
+  const shaped = line[prefix.rest] === "[" &&
+    line.includes("]:", footnote ? line.indexOf("]:", prefix.rest) + 2 : prefix.rest)
+  const definition = shaped && context.definitions.allowed && prefix.depth === 0 ?
+    keptDefinition(line, prefix.rest, context.mentions) :
+    undefined
   context.definitions.allowed = false
+  // Where the line's opening `[` is in `out`, while it may close on a later line.
+  const label = line[prefix.rest] === "[" ? prefix.text.length : undefined
   // Where the `[` of a label with no other bracket in it is, until a `]`
   // closes it. Only such a label keeps its destination: around a nested
   // label, a reference or a footnote, whether the outer brackets make a
@@ -417,6 +476,10 @@ const renderLine = (line: string, context: LineContext): string => {
   let out = prefix.text
   let urlEnd = -1
   let i = prefix.rest
+  if (shaped && definition === undefined) {
+    out += "\\["
+    i++
+  }
   while (i < line.length) {
     const c = line[i]
     const next = line[i + 1]
@@ -439,7 +502,7 @@ const renderLine = (line: string, context: LineContext): string => {
     }
     switch (c) {
       case "`": {
-        const end = inUrl ? undefined : codeSpanEnd(line, i, context.tableRow)
+        const end = inUrl ? undefined : codeSpanEnd(line, i, context.cells)
         if (end !== undefined && node(1)) {
           out += line.slice(i, end)
           i = end
@@ -503,12 +566,11 @@ const renderLine = (line: string, context: LineContext): string => {
         continue
       case "]": {
         // Telegram closes a link at `]` even when it is escaped, so a refused
-        // link loses its `(` and a refused definition its opening `[`. A
-        // kept destination is sent verbatim, which is inert only if it is
-        // read as one: a link needs an opener on its line, a definition the
-        // start of a line where one may stand.
-        // Not `[a][b](…)` or `[a][](…)`, where `[a]` may be the link.
+        // link loses its `(`. A kept destination is sent verbatim, which is
+        // inert only if it is read as one: a link needs an opener on its
+        // line, and not `[a][b](…)` or `[a][](…)`, where `[a]` may be the link.
         const plain = opener !== undefined && line[opener - 1] !== "]"
+        const labelOpener = opener
         opener = undefined
         unclosed.pop()
         if (next === "(") {
@@ -522,23 +584,10 @@ const renderLine = (line: string, context: LineContext): string => {
           i += 2
           continue
         }
-        if (next === ":" && !(footnote && i === line.indexOf("]", prefix.rest))) {
-          const definition = definitionDestination(line, i + 2)
-          if (
-            definitionAllowed && label !== undefined && out[label] === "[" && i === line.indexOf("]", prefix.rest) &&
-            definition !== undefined && allowedDestination(definition.destination, context.mentions)
-          ) {
-            out += "]: " + destinationOf(definition.destination)
-            i = definition.end
-            context.definitions.allowed = true
-            continue
-          }
-          // Telegram reads a definition wherever the line's first `[` closes
-          // at a `]:`, also past other brackets.
-          if (label !== undefined && !labelEscaped && out[label] === "[") {
-            out = out.slice(0, label) + "\\" + out.slice(label)
-            labelEscaped = true
-          }
+        // The `[` at the line's start counted as a node, so it is still a label.
+        if (definition !== undefined && i === definition.close && labelOpener === prefix.rest) {
+          context.definitions.allowed = true
+          return out + "]: " + destinationOf(definition.destination)
         }
         out += "]"
         i++
@@ -611,9 +660,15 @@ export interface RenderOptions {
  *   mailto is text: a link loses its `(`, a definition its opening `[`.
  *   A `tg://user` link stays for an id in `mentions`. A kept link needs its
  *   `[` and its whole tail on its line, a label with no other bracket in
- *   it, and no `]` right before it, a kept definition the top level
- *   after a blank line or another definition. Its destination is sent as
- *   Telegram reads it, verbatim, and its title is dropped.
+ *   it, and no `]` right before it. A line whose first `[` meets a `]:`
+ *   is a definition to Telegram, and is kept only at the top level after
+ *   a blank line or another definition, with a label that starts the
+ *   line, holds no other bracket, code span, autolink or escaped `]`, is
+ *   not blank or a footnote's and is at most 999 characters, and with
+ *   nothing after its destination but a title. Otherwise its `[` is
+ *   escaped. Either needs balanced parentheses and no control character
+ *   in its destination. Its destination is sent as Telegram reads it,
+ *   verbatim, and its title is dropped.
  * - A `*`, `_` or `~` run with space on both sides is escaped, outside a
  *   thematic break: Telegram would open emphasis with it.
  * - Code spans, `[` that could open a link or reference, and footnote
@@ -658,6 +713,7 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     fenced.push(false)
   }
   const tableRows = new Map()
+  const cellLines = new Set()
   for (let i = 0; i + 1 < lines.length; i++) {
     if (fenced[i] || fenced[i + 1] || tableRows.has(i) || blockStart.test(lines[i])) continue
     // Neither row indented, nor the header after a line it could continue.
@@ -665,12 +721,17 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     const above = i === 0 ? "" : lines[i - 1]
     if (!isBlank(above) && !/^#{1,6}(?: |$)/.test(above)) continue
     if (!delimiterRow.test(lines[i + 1]) || !lines[i + 1].includes("|") || !hasPipe(lines[i])) continue
+    // A delimiter row that is also a list item ends the paragraph first.
+    if (/^ {0,3}-[ \t]+\S/.test(lines[i + 1])) continue
     const columns = cellCount(lines[i])
     if (columns !== cellCount(lines[i + 1])) continue
     let end = i + 2
     while (end < lines.length && !fenced[end] && !isBlank(lines[end]) && !blockStart.test(lines[end])) end++
     const rows = Array.from({ length: end - i }, (_, k) => i + k)
     for (const row of rows) tableRows.set(row, columns > maxColumns || cellCount(lines[row]) > maxColumns)
+    // GFM ends a table at fewer lines than `blockStart` names, so a line
+    // past its rows here may still be one of its rows there.
+    for (let k = end; k < lines.length && !fenced[k] && !isBlank(lines[k]); k++) cellLines.add(k)
     i = end - 1
   }
   const inline: Inline = { open: 0, containers: 0, nodes: 0 }
@@ -699,6 +760,7 @@ export const render = (markdown: string, options: RenderOptions = {}): string =>
     }
     const rendered = renderLine(line, {
       tableRow: wide !== undefined,
+      cells: wide !== undefined || cellLines.has(i),
       widePipes: wide === true,
       setext,
       inline,
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 65662b34f1a..4f3bf534484 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -51,7 +51,12 @@ const cases: ReadonlyArray = [
     "\\[a][b]: tg://x\n\n \\[c]: tg://x\n\ntext\n\\[d]: https://e.com"
   ],
   ["a\\:b \\@c \\^d \\&", "a:b @c ^d &amp;"],
-  ["2 * 3 * 4 a _ b\n\n***", "2 \\* 3 \\* 4 a \\_ b\n\n***"]
+  ["2 * 3 * 4 a _ b\n\n***", "2 \\* 3 \\* 4 a \\_ b\n\n***"],
+  // a definition is refused once, keeps no title, and loses no text
+  [
+    "[a[b]: https://e.com\n\n[^ a]: https://e.com\n\n[c]: https://e.com \"t\"\n[d]: https://e.com d",
+    "\\[a[b]: https://e.com\n\n\\[^ a]: https://e.com\n\n[c]: https://e.com\n\\[d]: https://e.com d"
+  ]
 ]
 
 const bytes = (s: string) => new TextEncoder().encode(s).length
@@ -157,6 +162,12 @@ describe("render", () => {
         // a footnote's text, or an indented delimiter row, is no table
         "[^a]: x|y\n---|---\n||secret||",
         "x|y\n\t---|---",
+        // nor a delimiter row that starts a list item
+        "a|b\n- |-|",
+        // nor a lone pipe a header
+        "|\n-|",
+        // a table goes on past a line it does not end at
+        "|a|\n|---|\n[a]: mailto:x\nb `|`",
         // a line of U+00A0 is text, so it ends no paragraph
         ">".repeat(15) + " x\n\u00a0\n" + "_".repeat(14) + "x" + "_".repeat(14),
         "[^a]: z\n\u00a0\nx|y\n---|---\n||secret||",
@@ -173,7 +184,29 @@ describe("render", () => {
         "[](mailto:$(> )",
         // a definition's label may span lines
         "[\n[a]: [",
-        "[x\\](a)\n]: tg://user?id=1\n\n[x](a)\n]"
+        "[x\\](a)\n]: tg://user?id=1\n\n[x](a)\n]",
+        // nor a definition with a nested, blank or overlong label, or with
+        // more than a destination and a title on its line
+        "[a[b]: mailto:[pwn](tg://user?id=1)",
+        "[]: mailto:[pwn](tg://user?id=1)",
+        "[a]: mailto:[pwn](tg://user?id=1)(",
+        "[ ]: mailto:[pwn](tg://user?id=1)",
+        "[" + "a".repeat(1000) + "]: mailto:[pwn](tg://user?id=1)",
+        "[a]: mailto:[pwn](tg://user?id=1) b",
+        "[a]: mailto:[pwn](tg://user?id=1) \"t",
+        "[a]: mailto:\u007f[pwn](tg://user?id=1)",
+        "[a]: mailto:x [b]: mailto:[pwn](tg://user?id=1)",
+        // a code span or an autolink hides no label's end from CommonMark
+        "[`]: x` ](tg://user?id=1)",
+        "[\u0001`> >\\\"]: `]\"^<>",
+        "[",
+        "[>\\]: mailto:]:[^a]",
+        // indented, a footnote's label is a definition's
+        "[a]: mailto:x\n\t[^a]: tg://x",
+        "[a]: mailto:x\n    [^a]: tg://x",
+        "[^a]: [a]:<",
+        // nor is an autolink with a control character one
+        ""
       ]
     ) assertInert(input)
     fc.assert(fc.property(hostile, (input) => assertInert(input)), { numRuns: 2000 })
@@ -215,6 +248,9 @@ describe("render", () => {
     // four nodes a repeat, 40 past the cap
     const mixed = "[a] `b` [c](https://e.com) [d][a] ".repeat(maxInlineNodes / 4 + 10) + "\n\n[a]: https://e.com"
     assert.isAtMost(inspect(render(mixed)).inline, maxInlineNodes)
+    // a definition past the cap keeps no destination behind its escaped label
+    const definitions = "[a]: https://e.com\n".repeat(maxInlineNodes) + "[b]: mailto:[pwn](tg://user?id=1)"
+    assert.deepStrictEqual(inspect(render(definitions)).links.filter((url) => url.startsWith("tg:")), [])
     const references = render(Array.from({ length: 10 }, () => "x[^1]".repeat(100)).join("\n\n") + "\n\n[^1]: n")
     assert.strictEqual(references.match(/(?
Date: Mon, 16 Nov 2026 01:55:37 +0000
Subject: [PATCH 88/89] chat-telegram: bound a kept label's rendered length and
 a destination's nesting

A definition's label is now measured as the renderer will send it: an
escape counts as up to seven characters and each of $ = | * _ ~ as two,
and the bound must stay within CommonMark's 999. A label that grows past
it as it is escaped is refused up front, so its raw destination is not
copied behind text.

The destination scanner shared by links and definitions refuses
parentheses nested more than three deep, the least CommonMark lets a
parser support. GFM refuses a link past 32, which left its raw tail as
Markdown.
---
 packages/chat/telegram/README.md              |  2 +-
 .../chat/telegram/src/internal/markdown.ts    | 34 ++++++++++++++++---
 packages/chat/telegram/test/markdown.test.ts  | 19 ++++++++++-
 3 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/packages/chat/telegram/README.md b/packages/chat/telegram/README.md
index ac37e83f0b7..9e8a2d8b926 100644
--- a/packages/chat/telegram/README.md
+++ b/packages/chat/telegram/README.md
@@ -69,7 +69,7 @@ Updates from business connections, a channel's direct messages and guest mode ar
 
   const App = Webhook.pipe(Layer.provideMerge(RedactSecret))
   ```
-- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, its label has no other bracket in it and no `]` comes right before it, and its destination has balanced parentheses. A line whose first `[` meets a `]:` is kept as a definition only at the top level after a blank line, with a plain label that starts the line (no other bracket, code span, autolink or escaped `]`), and with nothing after its destination but a title. Otherwise its `[` is escaped.
+- Consumer Markdown is escaped so that it reaches no raw HTML, image, math, spoiler, highlight, or link outside `http`, `https` and `mailto`. A `tg://user` link stays only for users listed in `withPostOptions({ notify: { users } })`. Telegram honors only some backslash escapes, and it closes a link at an escaped `]`, so the other escapes become numeric character references, and a refused link or definition is broken at its `(` or its opening `[`. A kept link is sent with its destination verbatim, as Telegram reads it, and without its title. It is kept only when its `[` is on the same line, its label has no other bracket in it and no `]` comes right before it, and its destination has balanced parentheses at most three deep, the least CommonMark lets a parser support. A line whose first `[` meets a `]:` is kept as a definition only at the top level after a blank line, with a plain label that starts the line (no other bracket, code span, autolink or escaped `]`) and stays within 999 characters once escaped, and with nothing after its destination but a title. Otherwise its `[` is escaped.
 - Where Markdown is ambiguous the escaping errs toward plain text: a table keeps its pipes only after a blank line or a heading; a `*` or `_` with space on both sides is escaped, as Telegram would open emphasis with it; and past 15 delimiters that could open emphasis, or 4,000 code spans, footnote references and `[` that could open a link or reference in one paragraph, or 700 footnote references in a message, the rest are shown as written. Telegram still pairs emphasis more loosely than CommonMark: `a* b*` is italic.
 - A click is dispatched only when its `data` matches a button in Telegram's own copy of the message, and Telegram already refuses data that is not on the current keyboard (live check 8). Neither says that this user may press it.
 
diff --git a/packages/chat/telegram/src/internal/markdown.ts b/packages/chat/telegram/src/internal/markdown.ts
index ab5c4e39453..41af949f43a 100644
--- a/packages/chat/telegram/src/internal/markdown.ts
+++ b/packages/chat/telegram/src/internal/markdown.ts
@@ -205,11 +205,18 @@ const allowedDestination = (raw: string, mentions: ReadonlySet): boolean
 
 const blank = (c: string | undefined): boolean => c === " " || c === "\t"
 
+/**
+ * The deepest parentheses a kept destination may nest. CommonMark lets a
+ * parser refuse deeper ones once it supports three, and GFM refuses past
+ * 32 in a link, which would leave the rest of the link as Markdown.
+ */
+const maxDestinationDepth = 3
+
 /**
  * The destination and optional title from `start`, as CommonMark reads
  * them when they are on this line: a destination not in angle brackets, up
  * to a space, a control character or a `)` it did not open, with its
- * parentheses balanced, then a title after a space. `end` is past the
+ * parentheses balanced and at most three deep, then a title after a space. `end` is past the
  * title and the blanks after it.
  */
 const destinationAndTitle = (
@@ -229,8 +236,9 @@ const destinationAndTitle = (
     }
     const code = c.charCodeAt(0)
     if (code <= 0x20 || code === 0x7f) break
-    if (c === "(") depth++
-    else if (c === ")") {
+    if (c === "(") {
+      if (++depth > maxDestinationDepth) return undefined
+    } else if (c === ")") {
       if (depth === 0) break
       depth--
     }
@@ -307,6 +315,22 @@ const definitionDestination = (line: string, start: number): string | undefined
 /** The most characters CommonMark reads between a label's brackets. */
 const maxLabelLength = 999
 
+/**
+ * The most characters the renderer can make of a simple label: an escape
+ * becomes at most `%5C<`, and each of `$ = | * _ ~` at most two. The
+ * label it sends, not the consumer's, must fit in 999.
+ */
+const renderedLabelBound = (text: string): number => {
+  let n = 0
+  for (let i = 0; i < text.length; i++) {
+    if (text[i] === "\\") {
+      n += 7
+      i++
+    } else n += "$=|*_~".includes(text[i]) ? 2 : 1
+  }
+  return n
+}
+
 /**
  * A label CommonMark and the renderer both close at its first `]`: no
  * other bracket, code span or autolink in it, and no escape at its end.
@@ -316,7 +340,7 @@ const simpleLabel = /^(?:[^\\[\]`<]|\\.)*$/
 /**
  * The reference definition the line whose first `[` is at `start` may
  * keep: a simple label, not blank, not a footnote's and at most 999
- * characters, closed by `]:`, then a destination it allows.
+ * characters once rendered, closed by `]:`, then a destination it allows.
  */
 const keptDefinition = (
   line: string,
@@ -327,7 +351,7 @@ const keptDefinition = (
   const text = line.slice(start + 1, close)
   if (
     close < 0 || line[close + 1] !== ":" || !simpleLabel.test(text) || isBlank(text) || text[0] === "^" ||
-    text.length > maxLabelLength
+    renderedLabelBound(text) > maxLabelLength
   ) return undefined
   const destination = definitionDestination(line, close + 2)
   return destination !== undefined && allowedDestination(destination, mentions) ? { close, destination } : undefined
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 4f3bf534484..64638eeb1b7 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -56,7 +56,13 @@ const cases: ReadonlyArray = [
   [
     "[a[b]: https://e.com\n\n[^ a]: https://e.com\n\n[c]: https://e.com \"t\"\n[d]: https://e.com d",
     "\\[a[b]: https://e.com\n\n\\[^ a]: https://e.com\n\n[c]: https://e.com\n\\[d]: https://e.com d"
-  ]
+  ],
+  // a label that renders to 999 characters stays a definition, one of 1,000 does not
+  ["[" + "$".repeat(499) + "]: mailto:x", "[" + "\\$".repeat(499) + "]: mailto:x"],
+  ["[" + "$".repeat(500) + "]: mailto:x", "\\[" + "\\$".repeat(500) + "]: mailto:x"],
+  // a destination keeps parentheses three deep, not four
+  ["[a](https://e.com/(((x))))", "[a](https://e.com/(((x))))"],
+  ["[a](https://e.com/((((x)))))", "[a]\\(https://e.com/((((x)))))"]
 ]
 
 const bytes = (s: string) => new TextEncoder().encode(s).length
@@ -192,6 +198,17 @@ describe("render", () => {
         "[a]: mailto:[pwn](tg://user?id=1)(",
         "[ ]: mailto:[pwn](tg://user?id=1)",
         "[" + "a".repeat(1000) + "]: mailto:[pwn](tg://user?id=1)",
+        // nor one whose label grows past 999 characters as it is escaped
+        "[" + "$".repeat(500) + "]: mailto:[pwn](tg://user?id=1)",
+        "[" + "|".repeat(500) + "]: mailto:[pwn](tg://user?id=1)",
+        "[" + "\\^".repeat(200) + "]: mailto:[pwn](tg://user?id=1)",
+        "[" + "\\<".repeat(150) + "]: mailto:[pwn](tg://user?id=1)",
+        // in a bare URL each `\<` becomes `%5C<`
+        "[www.e.co/" + "\\<".repeat(142) + "]: mailto:[pwn](tg://user?id=1)",
+        // nor a destination nested deeper than a parser may read
+        "[x](mailto:" + "(".repeat(32) + "[pwn](tg://user?id=1)" + ")".repeat(32) + ")",
+        "[x](mailto:" + "(".repeat(3) + "[pwn](tg://user?id=1)" + ")".repeat(3) + ")",
+        "[x]: mailto:" + "(".repeat(32) + "[pwn](tg://user?id=1)" + ")".repeat(32),
         "[a]: mailto:[pwn](tg://user?id=1) b",
         "[a]: mailto:[pwn](tg://user?id=1) \"t",
         "[a]: mailto:\u007f[pwn](tg://user?id=1)",

From 7ad4fee77261b3ce26aca2962c0dbff50d6389d7 Mon Sep 17 00:00:00 2001
From: Tim Smart 
Date: Mon, 16 Nov 2026 02:35:19 +0000
Subject: [PATCH 89/89] Cut effect/chat and adapter tests to distinct
 contracts, boundaries and regressions

---
 .../chat/discord/test/DiscordChat.test.ts     |  968 ++-----
 packages/chat/discord/test/commands.test.ts   |  111 +-
 .../chat/discord/test/conformance.test.ts     |   23 +-
 packages/chat/discord/test/discord.ts         |   10 +-
 .../test/fixtures/recorded/components.json    | 2345 -----------------
 .../discord/test/fixtures/recorded/human.json |  168 --
 .../test/fixtures/recorded/other-bots.json    |  445 ----
 packages/chat/discord/test/gateway.test.ts    |   26 -
 .../chat/discord/test/interactions.test.ts    |  420 +--
 packages/chat/discord/test/normalize.test.ts  |  317 +--
 packages/chat/discord/test/utils.ts           |   34 +-
 packages/chat/slack/test/SlackChat.test.ts    |  488 +---
 packages/chat/slack/test/actions.test.ts      |   35 +-
 packages/chat/slack/test/commands.test.ts     |  104 +-
 packages/chat/slack/test/conformance.test.ts  |   41 +-
 packages/chat/slack/test/emoji.test.ts        |  186 +-
 packages/chat/slack/test/escape.test.ts       |  131 +-
 packages/chat/slack/test/events.test.ts       |   65 +-
 .../fixtures/events/bot-reply-lifecycle.json  |  130 -
 .../test/fixtures/events/me-message.json      |   27 -
 .../test/fixtures/events/native-stream.json   |   49 -
 .../recorded/agent-session-stopped.json       |   80 -
 .../recorded/assistant-thread-root.json       |  220 --
 .../test/fixtures/recorded/interactivity.json |  244 --
 .../test/fixtures/recorded/me-message.json    |  136 -
 .../recorded/thread-root-before-after.json    |  472 ----
 .../test/fixtures/recorded/unfurl-edit.json   | 1207 ---------
 packages/chat/slack/test/interactions.test.ts |  159 +-
 packages/chat/slack/test/live.test.ts         |  208 +-
 packages/chat/slack/test/normalize.test.ts    |  301 +--
 packages/chat/slack/test/richText.test.ts     |   36 +-
 packages/chat/slack/test/slack.ts             |   32 +-
 packages/chat/slack/test/utils.ts             |   14 +-
 packages/chat/slack/test/webhook.test.ts      |   58 +-
 packages/chat/teams/test/download.test.ts     |   19 +-
 packages/chat/teams/test/envelope.test.ts     |   23 +-
 packages/chat/teams/test/interactions.test.ts |  120 -
 packages/chat/teams/test/length.test.ts       |   69 +-
 packages/chat/teams/test/webhook.test.ts      |  141 +-
 .../chat/telegram/test/TelegramChat.test.ts   |  683 ++---
 packages/chat/telegram/test/gfm.ts            |    5 +-
 packages/chat/telegram/test/markdown.test.ts  |  308 +--
 packages/chat/telegram/test/utils.ts          |   32 +-
 .../chat/whatsapp/test/WhatsAppChat.test.ts   |   42 +-
 packages/chat/whatsapp/test/text.test.ts      |    2 -
 packages/chat/whatsapp/test/utils.ts          |    1 -
 packages/effect/test/chat/Chat.test.ts        |    2 -
 packages/effect/test/chat/ChatError.test.ts   |    3 -
 packages/effect/test/chat/ChatEvent.test.ts   |    1 -
 .../effect/test/chat/ChatInteraction.test.ts  |  210 +-
 .../effect/test/chat/ChatMarkdown.test.ts     |  389 +--
 packages/effect/test/chat/ChatTest.test.ts    |   18 +-
 .../typetest/chat/ChatInteraction.tst.ts      |   84 +-
 53 files changed, 1423 insertions(+), 10019 deletions(-)
 delete mode 100644 packages/chat/discord/test/fixtures/recorded/components.json
 delete mode 100644 packages/chat/discord/test/fixtures/recorded/human.json
 delete mode 100644 packages/chat/discord/test/fixtures/recorded/other-bots.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/me-message.json
 delete mode 100644 packages/chat/slack/test/fixtures/events/native-stream.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/interactivity.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/me-message.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json
 delete mode 100644 packages/chat/slack/test/fixtures/recorded/unfurl-edit.json
 delete mode 100644 packages/chat/teams/test/interactions.test.ts

diff --git a/packages/chat/discord/test/DiscordChat.test.ts b/packages/chat/discord/test/DiscordChat.test.ts
index aa1e97fd037..35b67f2159b 100644
--- a/packages/chat/discord/test/DiscordChat.test.ts
+++ b/packages/chat/discord/test/DiscordChat.test.ts
@@ -1,9 +1,8 @@
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { assert, describe, it } from "@effect/vitest"
+import type { ChatAdapter } from "effect/chat/ChatAdapter"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { ChatHandler, NotAccepted } from "effect/chat/ChatHandler"
-import { checkMessage } from "effect/chat/ChatTest"
-import type * as ChatUi from "effect/chat/ChatUi"
 import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
 import * as Option from "effect/Option"
@@ -13,7 +12,6 @@ import {
   adapter,
   answer,
   botUserId,
-  checkOptions,
   discordLayer,
   errorResponse,
   events,
@@ -25,8 +23,16 @@ import {
   step
 } from "./utils.ts"
 
-const run = (fake: Fake, effect: Effect.Effect, options?: { readonly download?: Uint8Array }) =>
-  effect.pipe(Effect.provide(discordLayer(fake, options))) as Effect.Effect
+/** Runs `body` with the adapter over a fake answering from `handlers`. */
+const withAdapter = (
+  handlers: Parameters[0],
+  body: (discord: ChatAdapter, fake: Fake) => Effect.Effect
+) => {
+  const fake = makeFake(handlers)
+  return Effect.flatMap(adapter, (discord) => body(discord, fake)).pipe(
+    Effect.provide(discordLayer(fake))
+  ) as Effect.Effect
+}
 
 const reason = (effect: Effect.Effect) =>
   Effect.flip(effect).pipe(
@@ -35,77 +41,46 @@ const reason = (effect: Effect.Effect) =>
 
 const channel = DiscordChat.thread(scratch)
 const posted = step("posts", "channel-plain").response
+const answers = { createMessage: () => Effect.succeed(posted) }
 
 const history = step("history", "thread-history")
 const threadId: string = step("history", "thread-start").response.id
 const thread = DiscordChat.thread(threadId)
 const threadChannel = step("history", "thread-get-channel").response
+const forbidden = () => Effect.fail(errorResponse(403, { code: 50001, message: "Missing Access" }))
 
 const noMentions = { parse: [], users: [], roles: [], replied_user: false }
 
 describe("post", () => {
-  it.effect("sends the Markdown as is, notifying nobody and suppressing embeds", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
+  it.effect("sends the Markdown as is, notifying nobody and suppressing embeds", () =>
+    withAdapter(answers, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        const result = yield* discord.post(channel, { markdown: "hi <@1> @everyone **bold**" })
-        assert.strictEqual(result.id, posted.id)
-        assert.deepStrictEqual(result.thread, channel)
+        yield* discord.post(channel, { markdown: "hi <@1> @everyone **bold**" })
         assert.deepStrictEqual(fake.called("createMessage"), [[scratch, {
           content: "hi <@1> @everyone **bold**",
           allowed_mentions: noMentions,
           flags: 4
         }]])
-      })
-    )
-  })
+      })))
 
-  it.effect("withPostOptions allows mentions and embeds, merging nested calls", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
+  it.effect("withPostOptions sets mentions, embeds and the reference, merging nested calls", () =>
+    withAdapter(answers, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
         yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42" } }).pipe(
           DiscordChat.withPostOptions({ notify: { users: ["1"], roles: ["2"], everyone: true, repliedUser: true } }),
-          DiscordChat.withPostOptions({ suppressEmbeds: false })
+          DiscordChat.withPostOptions({ suppressEmbeds: false, failIfNotExists: false })
         )
         assert.deepStrictEqual(fake.called("createMessage")[0][1], {
           content: "hi",
           allowed_mentions: { parse: ["everyone"], users: ["1"], roles: ["2"], replied_user: true },
           flags: 0,
-          message_reference: { message_id: "42" }
+          message_reference: { message_id: "42", fail_if_not_exists: false }
         })
-      })
-    )
-  })
+      })))
 
-  it.effect("failIfNotExists false lets a reply to a deleted message go out without its reference", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
+  it.effect("counts the 2,000 limit in code points, failing past it without a call", () =>
+    withAdapter(answers, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        yield* discord.post(channel, { markdown: "hi", replyTo: { messageId: "42" } }).pipe(
-          DiscordChat.withPostOptions({ failIfNotExists: false })
-        )
-        yield* discord.post(channel, { markdown: "hi" }).pipe(DiscordChat.withPostOptions({ failIfNotExists: false }))
-        assert.deepStrictEqual(fake.called("createMessage").map(([, body]) => body.message_reference), [
-          { message_id: "42", fail_if_not_exists: false },
-          undefined
-        ])
-      })
-    )
-  })
-
-  it.effect("fails TooLarge past 2,000 code points without a call", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
         assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "a".repeat(2001) })), {
           op: "post",
           tag: "TooLarge",
@@ -116,132 +91,92 @@ describe("post", () => {
         // 2,000 astral emoji are 4,000 UTF-16 units, and Discord took them.
         yield* discord.post(channel, { markdown: "\u{1F600}".repeat(2000) })
         assert.strictEqual(fake.called("createMessage").length, 1)
-        assert.strictEqual(discord.descriptor.measure("\u{1F600}".repeat(2000)), 2000)
-      })
-    )
-  })
-
-  it.effect("uploads files with the message", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(step("posts", "attachment-fixed").response) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        yield* discord.post(channel, {
-          markdown: "with a file",
-          files: [{ name: "fixture.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }]
-        })
-        assert.strictEqual(fake.calls[0].files, 1)
-        assert.deepStrictEqual(fake.calls[0].args[1].attachments, [{ id: "0", filename: "fixture.txt" }])
-      })
-    )
-  })
-
-  it.effect("maps Discord's error bodies", () => {
-    const errors = (stepName: string) => () => answer(step("errors", stepName))
-    const cases = [
-      ["post-unknown-channel", { op: "post", tag: "NotFound", detail: "10003", retry: "denied" }],
-      ["post-empty", { op: "post", tag: "InvalidRequest", detail: "50006", retry: "denied" }],
-      ["length-2001-ascii", { op: "post", tag: "TooLarge", detail: "50035", retry: "denied" }]
-    ] as const
-    return Effect.forEach(cases, ([stepName, expected]) => {
-      const fake = makeFake({ createMessage: errors(stepName) })
-      return run(
-        fake,
-        Effect.gen(function*() {
-          const discord = yield* adapter
-          assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "x" })), expected)
-        })
-      )
-    }, { discard: true })
-  })
-
-  it.effect("a 5xx on a write is uncertain and not retried", () => {
-    const fake = makeFake({
-      createMessage: () => Effect.fail(statusCodeError(502)),
-      deleteMessage: () => Effect.fail(errorResponse(403, { code: 50013, message: "Missing Permissions" }))
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "x" })), {
-          op: "post",
-          tag: "PlatformUnavailable",
-          detail: "http_502",
-          retry: "uncertain"
-        })
-        assert.strictEqual(fake.called("createMessage").length, 1)
-        assert.deepStrictEqual(yield* reason(discord.delete(channel, "1")), {
-          op: "delete",
-          tag: "Forbidden",
-          detail: "50013",
-          retry: "denied"
-        })
-      })
-    )
-  })
+      })))
+
+  it.effect("maps Discord's failures, sending a write once and a 5xx on it as uncertain", () =>
+    Effect.forEach(
+      [
+        [answer(step("errors", "post-unknown-channel")), { tag: "NotFound", detail: "10003", retry: "denied" }],
+        [answer(step("errors", "length-2001-ascii")), { tag: "TooLarge", detail: "50035", retry: "denied" }],
+        [Effect.fail(statusCodeError(502)), { tag: "PlatformUnavailable", detail: "http_502", retry: "uncertain" }]
+      ] as const,
+      ([failure, expected]) =>
+        withAdapter({ createMessage: () => failure }, (discord, fake) =>
+          Effect.gen(function*() {
+            assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "x" })), { op: "post", ...expected })
+            assert.strictEqual(fake.calls.length, 1)
+          })),
+      { discard: true }
+    ))
 
   it.effect("a 5xx on a read is retried", () => {
     let attempts = 0
-    const fake = makeFake({
+    return withAdapter({
       getMessage: () => attempts++ < 1 ? Effect.fail(statusCodeError(503)) : Effect.succeed(posted)
-    })
-    return run(
-      fake,
+    }, (discord) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
         const fiber = yield* Effect.forkChild(discord.fetchMessage(channel, posted.id))
         yield* TestClock.adjust("1 second")
-        const message = yield* Fiber.join(fiber)
-        assert.strictEqual(message.id, posted.id)
-        assert.strictEqual(fake.called("getMessage").length, 2)
-      })
-    )
+        assert.strictEqual((yield* Fiber.join(fiber)).id, posted.id)
+      }))
   })
 
-  it.effect("rejects an address that is not a Discord channel id", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
+  it.effect("rejects an address that is not a Discord channel id", () =>
+    withAdapter({}, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        const result = yield* reason(discord.post(DiscordChat.thread("C123"), { markdown: "x" }))
+        const result = yield* reason(discord.post(DiscordChat.thread("../C123"), { markdown: "x" }))
         assert.strictEqual(result.tag, "InvalidRequest")
         assert.strictEqual(fake.calls.length, 0)
-      })
-    )
-  })
+      })))
+
+  it.effect("a post answer with an invalid timestamp fails instead of throwing", () =>
+    withAdapter(
+      { createMessage: () => Effect.succeed({ ...posted, timestamp: "not a date" }) },
+      (discord) =>
+        Effect.gen(function*() {
+          const result = yield* reason(discord.post(channel, { markdown: "x" }))
+          assert.deepStrictEqual([result.tag, result.detail], ["Unknown", "invalid_timestamp"])
+        })
+    ))
+
+  it.effect("the adapter's own file count and size check is file_refused, without a call", () =>
+    withAdapter({}, (discord, fake) =>
+      Effect.gen(function*() {
+        const file = { name: "fixture.txt", contentType: "text/plain", content: new Uint8Array(1) }
+        const tooMany = Array.from({ length: discord.descriptor.limits.filesPerMessage + 1 }, () => file)
+        const tooBig = [{ ...file, content: new Uint8Array(discord.descriptor.limits.uploadBytes + 1) }]
+        for (const files of [tooMany, tooBig]) {
+          assert.deepStrictEqual(yield* reason(discord.post(channel, { markdown: "x", files })), {
+            op: "post",
+            tag: "TooLarge",
+            detail: "file_refused",
+            retry: "denied"
+          })
+        }
+        assert.strictEqual(fake.calls.length, 0)
+      })))
 })
 
-describe("buttons and selects", () => {
-  const button = (i: number): ChatUi.Button => ({ _tag: "Button", id: "b" + i, label: "B" + i })
-  const select: ChatUi.Select = {
-    _tag: "Select",
-    id: "pick",
-    placeholder: "Pick",
-    options: [{ label: "A", value: "a" }, { label: "B", value: "b" }],
-    selected: "b"
-  }
-  const rowsOf = (fake: Fake) => fake.called("createMessage")[0][1].components
-
-  it.effect("go out as action rows: five buttons to a row and a select alone in its row", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
+describe("actions", () => {
+  it.effect("go out as action rows: five buttons to a row and a select alone in its row", () =>
+    withAdapter(answers, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
         yield* discord.post(channel, {
           markdown: "x",
           actions: [
             { _tag: "Button", id: "go", label: "Go", style: "primary", value: "v" },
             { _tag: "Button", id: "stop", label: "Stop", style: "danger" },
             { _tag: "LinkButton", label: "Docs", url: "https://effect.website" },
-            select,
-            ...Array.from({ length: 6 }, (_, i) => button(i))
+            {
+              _tag: "Select",
+              id: "pick",
+              options: [{ label: "A", value: "a" }, { label: "B", value: "b" }],
+              selected: "b"
+            },
+            ...Array.from({ length: 3 }, (_, i) => ({ _tag: "Button" as const, id: "b" + i, label: "B" + i }))
           ]
         })
-        assert.deepStrictEqual(rowsOf(fake), [
+        assert.deepStrictEqual(fake.called("createMessage")[0][1].components, [
           {
             type: 1,
             components: [
@@ -255,637 +190,294 @@ describe("buttons and selects", () => {
             components: [{
               type: 3,
               custom_id: "pick",
-              placeholder: "Pick",
               options: [{ label: "A", value: "a" }, { label: "B", value: "b", default: true }],
               min_values: 1,
               max_values: 1
             }]
           },
-          {
-            type: 1,
-            components: [0, 1, 2, 3, 4].map((i) => ({ type: 2, style: 2, label: "B" + i, custom_id: "b" + i }))
-          },
-          { type: 1, components: [{ type: 2, style: 2, label: "B5", custom_id: "b5" }] }
+          { type: 1, components: [0, 1, 2].map((i) => ({ type: 2, style: 2, label: "B" + i, custom_id: "b" + i })) }
         ])
-      })
-    )
-  })
-
-  it.effect("fail before the call when a select's id and option value pass 99 code points or an id holds the join", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const post = (actions: ReadonlyArray) =>
-          reason(discord.post(channel, { markdown: "x", actions }))
-        assert.deepStrictEqual(yield* post([{ ...select, options: [{ label: "x", value: "x".repeat(96) }] }]), {
-          op: "post",
-          tag: "TooLarge",
-          detail: "action_data_too_long",
-          retry: "denied"
-        })
-        assert.strictEqual((yield* post([{ _tag: "Button", id: "a\u241Fb", label: "x" }])).tag, "InvalidRequest")
-        assert.strictEqual(fake.calls.length, 0)
-      })
-    )
-  })
-})
-
-describe("recorded components", () => {
-  // fixtures/recorded/components.json: what Discord accepted and refused in #test.
-  const call = (name: string) => step("components", name)
-  const options = (n: number) => Array.from({ length: n }, (_, i) => ({ label: "o" + i, value: "o" + i }))
+      })))
 
-  it.effect("a custom_id of 100 code points, the join included, goes out as Discord accepted it", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
+  it.effect("an id holding the join, which would forge a value, fails before the call", () =>
+    withAdapter({}, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        // 100 code points but 150 UTF-16 units: Discord counts code points.
-        const name = "custom-id-100-code-points-astral"
-        yield* discord.post(channel, {
-          markdown: "x",
-          actions: [{ _tag: "Button", id: "a".repeat(49), label: "x", value: "\u{1F600}".repeat(50) }]
-        })
-        assert.strictEqual(call(name).status, 200)
-        assert.deepStrictEqual(fake.called("createMessage")[0][1].components, call(name).request.components)
-      })
-    )
-  })
-
-  it.effect("what Discord refused, the adapter refuses before a call", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const post = (actions: ReadonlyArray) =>
-          reason(discord.post(channel, { markdown: "x", actions }))
-        const cases: ReadonlyArray, string]> = [
-          // Six selects need six rows, under the 25 elements.
-          [
-            "six-rows",
-            Array.from({ length: 6 }, (_, i) => ({ _tag: "Select", id: "s" + i, options: options(2) })),
-            "too_many_actions"
-          ],
-          ["custom-id-101-code-points-astral", [{
-            _tag: "Button",
-            id: "a".repeat(50),
-            label: "x",
-            value: "\u{1F600}".repeat(50)
-          }], "action_data_too_long"]
-        ]
-        for (const [name, actions, detail] of cases) {
-          assert.deepStrictEqual([call(name).status, call(name).response.code], [400, 50035], name)
-          assert.deepStrictEqual(yield* post(actions), { op: "post", tag: "TooLarge", detail, retry: "denied" }, name)
-        }
-        assert.strictEqual(fake.calls.length, 0)
-      })
-    )
-  })
-})
-
-describe("files", () => {
-  const file = { name: "fixture.txt", contentType: "text/plain", content: new TextEncoder().encode("hello") }
-  const refused = (fail: () => Effect.Effect) => {
-    const fake = makeFake({ createMessage: fail })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const error = yield* Effect.flip(discord.post(channel, { markdown: "x", files: [file] }))
-        return { tag: error.reason._tag, detail: error.reason.detail, retry: error.retry, cause: error.reason.cause }
-      })
-    )
-  }
-
-  it.effect("a denied answer to a post with files is file_refused, with Discord's reason as the cause", () =>
-    Effect.gen(function*() {
-      const denied = yield* refused(() => Effect.fail(errorResponse(403, { code: 50013, message: "refused" })))
-      assert.deepStrictEqual([denied.detail, denied.retry], ["file_refused", "denied"])
-      assert.strictEqual((denied.cause as any).detail, "50013")
-      // Discord's own 413, as recorded in fixtures/recorded/uploads.json.
-      const oversize = yield* refused(() => answer(step("uploads", "upload-20MiB-plus-1")))
-      assert.deepStrictEqual([oversize.tag, oversize.detail, oversize.retry], ["TooLarge", "file_refused", "denied"])
-      assert.strictEqual((oversize.cause as any).detail, "40005")
-      // A 413 with no JSON body, as a proxy in between might send.
-      const edge = yield* refused(() =>
-        Effect.fail({ _tag: "HttpClientError", reason: { _tag: "DecodeError", response: { status: 413 } } })
-      )
-      assert.deepStrictEqual([edge.tag, edge.detail, edge.retry], ["TooLarge", "file_refused", "denied"])
-      // A failure that is not denied keeps its own reason.
-      const unavailable = yield* refused(() => Effect.fail(statusCodeError(502)))
-      assert.deepStrictEqual([unavailable.tag, unavailable.detail], ["PlatformUnavailable", "http_502"])
-    }))
-
-  it.effect("the adapter's own count and size check is file_refused, without a call", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const tooMany = yield* reason(
-          discord.post(channel, { markdown: "x", files: Array.from({ length: 11 }, () => file) })
+        const result = yield* reason(
+          discord.post(channel, { markdown: "x", actions: [{ _tag: "Button", id: "a\u241Fb", label: "x" }] })
         )
-        const tooBig = yield* reason(discord.post(channel, {
-          markdown: "x",
-          files: [{ ...file, content: new Uint8Array(10 * 1024 * 1024 + 1) }]
-        }))
-        for (const result of [tooMany, tooBig]) {
-          assert.deepStrictEqual(result, { op: "post", tag: "TooLarge", detail: "file_refused", retry: "denied" })
-        }
+        assert.strictEqual(result.tag, "InvalidRequest")
         assert.strictEqual(fake.calls.length, 0)
-        // The limit is a conservative bound, at most what Discord accepted (20 MiB in a guild with no
-        // boosts), so files between the two are refused here although Discord would take them.
-        const accepted = step("uploads", "upload-20MiB")
-        assert.strictEqual(accepted.status, 200)
-        assert.isAtMost(discord.descriptor.limits.uploadBytes, accepted.request["files[0]"].bytes)
-      })
-    )
-  })
+      })))
 })
 
-describe("edit", () => {
-  it.effect("sends allowed_mentions and the SUPPRESS_EMBEDS flag on every edit", () => {
-    const fake = makeFake({ updateMessage: () => Effect.succeed(posted) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        yield* discord.edit(channel, "1", { markdown: "now with https://effect.website" })
-        assert.deepStrictEqual(fake.called("updateMessage"), [[scratch, "1", {
-          content: "now with https://effect.website",
-          allowed_mentions: noMentions,
-          flags: 4,
-          components: []
-        }]])
-        assert.deepStrictEqual(yield* reason(discord.edit(channel, "1", { markdown: "a".repeat(2001) })), {
-          op: "edit",
-          tag: "TooLarge",
-          detail: "message_too_long",
-          retry: "denied"
-        })
+it.effect("edit sends allowed_mentions and the SUPPRESS_EMBEDS flag", () =>
+  withAdapter({ updateMessage: () => Effect.succeed(posted) }, (discord, fake) =>
+    Effect.gen(function*() {
+      yield* discord.edit(channel, "1", { markdown: "now with https://effect.website" })
+      assert.deepStrictEqual(fake.called("updateMessage"), [[scratch, "1", {
+        content: "now with https://effect.website",
+        allowed_mentions: noMentions,
+        flags: 4,
+        components: []
+      }]])
+    })))
+
+it.effect("edit fails TooLarge past 2,000 code points without a call", () =>
+  withAdapter({}, (discord, fake) =>
+    Effect.gen(function*() {
+      assert.deepStrictEqual(yield* reason(discord.edit(channel, "1", { markdown: "a".repeat(2001) })), {
+        op: "edit",
+        tag: "TooLarge",
+        detail: "message_too_long",
+        retry: "denied"
       })
-    )
-  })
-})
+      assert.strictEqual(fake.calls.length, 0)
+    })))
 
 describe("startThread", () => {
-  it.effect("names the thread after the message, cut to 100 characters", () => {
-    const fake = makeFake({
+  it.effect("names the thread after the message, cut to 100 characters", () =>
+    withAdapter({
       getMessage: () => Effect.succeed({ ...posted, content: "  first line\nsecond " + "x".repeat(200) }),
       createThreadFromMessage: () => Effect.succeed(step("history", "thread-start").response)
-    })
-    return run(
-      fake,
+    }, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        const result = yield* discord.startThread(channel, threadId).pipe(
-          DiscordChat.withPostOptions({ autoArchiveDuration: 1440 })
+        assert.deepStrictEqual(yield* discord.startThread(channel, threadId), thread)
+        assert.strictEqual(
+          fake.called("createThreadFromMessage")[0][2].name,
+          ("first line second " + "x".repeat(200)).slice(0, 100)
         )
-        assert.deepStrictEqual(result, thread)
-        const [[channelId, messageId, body]] = fake.called("createThreadFromMessage")
-        assert.strictEqual(channelId, scratch)
-        assert.strictEqual(messageId, threadId)
-        assert.strictEqual(body.name, ("first line second " + "x".repeat(200)).slice(0, 100))
-        assert.strictEqual(body.auto_archive_duration, 1440)
-      })
-    )
-  })
+      })))
 
-  it.effect("160004 gives the existing thread, whose id is the message's", () => {
-    const fake = makeFake({ createThreadFromMessage: () => answer(step("errors", "thread-start-again")) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const result = yield* discord.startThread(channel, threadId, { name: "given" })
-        assert.deepStrictEqual(result, thread)
-        assert.strictEqual(fake.called("createThreadFromMessage")[0][2].name, "given")
-      })
-    )
-  })
+  it.effect("160004 gives the existing thread, whose id is the message's", () =>
+    withAdapter(
+      { createThreadFromMessage: () => answer(step("errors", "thread-start-again")) },
+      (discord) =>
+        Effect.gen(function*() {
+          assert.deepStrictEqual(yield* discord.startThread(channel, threadId, { name: "x" }), thread)
+        })
+    ))
 
-  it.effect("on a message in a thread, gives the thread", () => {
-    const fake = makeFake({
+  it.effect("50024 on a message in a thread gives the thread, and elsewhere fails", () =>
+    withAdapter({
       createThreadFromMessage: () => answer(step("errors", "forum-start-thread-again")),
-      getChannel: () => Effect.succeed(threadChannel)
-    })
-    return run(
-      fake,
+      getChannel: (id: string) =>
+        Effect.succeed(id === threadId ? threadChannel : step("channels", "get-channel-dm").response)
+    }, (discord) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
         assert.deepStrictEqual(yield* discord.startThread(thread, "1", { name: "x" }), thread)
-      })
-    )
-  })
-
-  it.effect("50024 elsewhere stays a failure", () => {
-    const fake = makeFake({
-      createThreadFromMessage: () => answer(step("errors", "forum-start-thread-again")),
-      getChannel: () => Effect.succeed(step("channels", "get-channel-dm").response)
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const result = yield* reason(discord.startThread(channel, "1", { name: "x" }))
-        assert.strictEqual(result.detail, "50024")
-      })
-    )
-  })
+        assert.strictEqual((yield* reason(discord.startThread(channel, "1", { name: "x" }))).detail, "50024")
+      })))
 })
 
-describe("history", () => {
-  const listFrom = (pages: ReadonlyArray) => (_: string, options: any) => {
-    const all = [...pages]
-    const id = (raw: any) => BigInt(raw.id)
-    const found = options.before !== undefined
-      ? all.filter((raw) => id(raw) < BigInt(options.before))
-      : options.after !== undefined
-      ? all.filter((raw) => id(raw) > BigInt(options.after))
-      : all
-    // Newest first, as Discord answers with either bound.
-    return Effect.succeed(found.sort((a, b) => (id(b) > id(a) ? 1 : -1)).slice(0, options.limit ?? 50))
-  }
-
-  it.effect("a thread started from a message has its opener first, addressed to the parent", () => {
-    const fake = makeFake({ listMessages: listFrom(history.response) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const forward = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "forward" })))
-        assert.deepStrictEqual(forward.map((message) => message.id), [
-          threadId,
-          ...history.response.filter((raw: any) => raw.type !== 21).map((raw: any) => raw.id).reverse()
-        ])
-        assert.deepStrictEqual(forward[0].thread, channel)
-        for (const message of forward.slice(1)) assert.deepStrictEqual(message.thread, thread)
-        for (const message of forward) yield* checkMessage(message, checkOptions)
-        const backward = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "backward" })))
-        assert.deepStrictEqual(backward.map((message) => message.id), forward.map((message) => message.id).reverse())
-        // `from` is exclusive, the opener included.
-        const after = Array.from(
-          yield* Stream.runCollect(discord.history(thread, { direction: "forward", from: threadId }))
-        )
-        assert.deepStrictEqual(after.map((message) => message.id), forward.slice(1).map((message) => message.id))
-        assert.strictEqual(fake.called("getMessage").length, 0)
-      })
-    )
-  })
+describe("history and opener", () => {
+  /** `listMessages` over `all`, newest first, as Discord answers with either bound. */
+  const listFrom =
+    (all: ReadonlyArray) =>
+    (_: string, { after, before, limit }: { after?: string; before?: string; limit: number }) =>
+      Effect.succeed(
+        all.filter((raw) =>
+          (after === undefined || BigInt(raw.id) > BigInt(after)) &&
+          (before === undefined || BigInt(raw.id) < BigInt(before))
+        ).sort((a, b) => (BigInt(b.id) > BigInt(a.id) ? 1 : -1)).slice(0, limit)
+      )
 
-  it.effect("a thread whose opener was deleted starts at the first reply", () => {
-    const deleted = step("history", "thread-deleted-history").response
-    const fake = makeFake({ listMessages: listFrom(deleted) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const thread = DiscordChat.thread(step("history", "thread-deleted-start").response.id)
-        const found = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "forward" })))
-        assert.deepStrictEqual(found.map((message) => message.id), [deleted.find((raw: any) => raw.type === 0).id])
-      })
+  it.effect("history pages until a short page", () => {
+    const many = Array.from(
+      { length: 250 },
+      (_, i) => ({ ...posted, id: String(1570607253965246584n + BigInt(i + 1)) })
     )
+    return withAdapter({ listMessages: listFrom(many) }, (discord) =>
+      Effect.gen(function*() {
+        const found = yield* Stream.runCollect(discord.history(channel, { direction: "backward" }))
+        assert.deepStrictEqual(Array.from(found, (message) => message.id), many.map((raw) => raw.id).reverse())
+      }))
   })
 
-  it.effect("the opener is read when the placeholder carries no referenced_message", () => {
-    const placeholder = history.response.find((raw: any) => raw.type === 21)
-    const { referenced_message: opener, ...bare } = placeholder
-    const fake = makeFake({
-      listMessages: listFrom([bare]),
-      getMessage: (channelId: string, messageId: string) =>
-        channelId === scratch && messageId === threadId
-          ? Effect.succeed(opener)
-          : Effect.fail(errorResponse(404, { code: 10008, message: "Unknown Message" }))
-    })
-    return run(
-      fake,
+  it.effect("history of a thread started from a message has its opener first, addressed to the parent", () =>
+    withAdapter({ listMessages: listFrom(history.response) }, (discord) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        const found = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "backward" })))
-        assert.deepStrictEqual(found.map((message) => message.id), [threadId])
-      })
-    )
-  })
+        const [opener, ...replies] = Array.from(
+          yield* Stream.runCollect(discord.history(thread, { direction: "forward" }))
+        )
+        assert.deepStrictEqual([opener.id, opener.thread], [threadId, channel])
+        assert.deepStrictEqual(
+          replies.map((message) => message.id),
+          history.response.filter((raw: any) => raw.type !== 21).map((raw: any) => raw.id).reverse()
+        )
+        for (const message of replies) assert.deepStrictEqual(message.thread, thread)
+      })))
 
-  it.effect("pages until a short page", () => {
-    const many = Array.from(
-      { length: 250 },
-      (_, i) => ({ ...posted, id: String(1570607253965246584n + BigInt(i + 1)) })
-    )
-    const fake = makeFake({ listMessages: listFrom(many) })
-    return run(
-      fake,
+  it.effect("history of a thread whose opener was deleted starts at the first reply", () => {
+    const deleted = step("history", "thread-deleted-history").response
+    const deletedThread = DiscordChat.thread(step("history", "thread-deleted-start").response.id)
+    return withAdapter({ listMessages: listFrom(deleted) }, (discord) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        const found = Array.from(yield* Stream.runCollect(discord.history(channel, { direction: "backward" })))
-        assert.strictEqual(found.length, 250)
-        assert.strictEqual(fake.called("listMessages").length, 3)
-        assert.deepStrictEqual(fake.called("listMessages")[1][1], { before: found[99].id, limit: 100 })
-      })
-    )
+        const found = yield* Stream.runCollect(discord.history(deletedThread, { direction: "forward" }))
+        assert.deepStrictEqual(Array.from(found, (message) => message.id), [
+          deleted.find((raw: any) => raw.type === 0).id
+        ])
+      }))
   })
-})
 
-describe("opener", () => {
-  it.effect("reads the message in the parent for a thread started from a message", () => {
-    const fake = makeFake({
+  it.effect("opener reads the message in the parent for a thread started from a message", () =>
+    withAdapter({
       getChannel: () => Effect.succeed(threadChannel),
       getMessage: (channelId: string) =>
-        channelId === threadId
-          ? answer(step("history", "thread-get-opener-by-thread-id"))
-          : answer(step("history", "thread-get-opener"))
-    })
-    return run(
-      fake,
+        answer(step("history", channelId === threadId ? "thread-get-opener-by-thread-id" : "thread-get-opener"))
+    }, (discord) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
         const opener = Option.getOrThrow(yield* discord.opener(thread))
         assert.strictEqual(opener.id, threadId)
         assert.deepStrictEqual(opener.thread, channel)
-      })
-    )
-  })
+      })))
 
-  it.effect("reads a forum post's starter in the post", () => {
+  it.effect("opener reads a forum post's starter in the post", () => {
     const starter = step("history", "forum-get-starter").response
-    const fake = makeFake({
+    return withAdapter({
       getChannel: () => Effect.succeed(step("history", "forum-post").response),
       getMessage: () => Effect.succeed(starter)
-    })
-    return run(
-      fake,
+    }, (discord) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
         const opener = Option.getOrThrow(yield* discord.opener(DiscordChat.thread(starter.id)))
-        assert.strictEqual(opener.thread.id, starter.id)
-      })
-    )
+        assert.deepStrictEqual([opener.id, opener.thread.id], [starter.id, starter.id])
+      }))
   })
 
-  it.effect("is None for a deleted opener and for a channel", () => {
-    const fake = makeFake({
+  it.effect("opener is None for a deleted opener and for a channel", () =>
+    withAdapter({
       getChannel: (id: string) =>
         Effect.succeed(id === scratch ? step("channels", "get-channel-text").response : threadChannel),
       getMessage: () => answer(step("history", "thread-deleted-get-opener"))
-    })
-    return run(
-      fake,
+    }, (discord) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
         assert.isTrue(Option.isNone(yield* discord.opener(thread)))
         assert.isTrue(Option.isNone(yield* discord.opener(channel)))
-      })
-    )
-  })
-})
+      })))
 
-describe("an opener the bot can't read", () => {
-  const forbidden = () => Effect.fail(errorResponse(403, { code: 50001, message: "Missing Access" }))
-
-  it.effect("history skips it and starts at the first reply", () => {
-    const placeholder = history.response.find((raw: any) => raw.type === 21)
-    const { referenced_message: _, ...bare } = placeholder
+  it.effect("history skips an opener the bot can't read and starts at the first reply", () => {
+    const { referenced_message: _, ...bare } = history.response.find((raw: any) => raw.type === 21)
     const reply = history.response.find((raw: any) => raw.type === 0)
-    const fake = makeFake({ listMessages: () => Effect.succeed([reply, bare]), getMessage: forbidden })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const found = Array.from(yield* Stream.runCollect(discord.history(thread, { direction: "forward" })))
-        assert.deepStrictEqual(found.map((message) => message.id), [reply.id])
-      })
-    )
-  })
-
-  it.effect("opener is None", () => {
-    const fake = makeFake({ getChannel: () => Effect.succeed(threadChannel), getMessage: forbidden })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        assert.isTrue(Option.isNone(yield* discord.opener(thread)))
-      })
+    return withAdapter(
+      { listMessages: () => Effect.succeed([reply, bare]), getMessage: forbidden },
+      (discord) =>
+        Effect.gen(function*() {
+          const found = yield* Stream.runCollect(discord.history(thread, { direction: "forward" }))
+          assert.deepStrictEqual(Array.from(found, (message) => message.id), [reply.id])
+        })
     )
   })
 
-  it.effect("a forbidden thread still fails history and opener", () => {
-    const fake = makeFake({ listMessages: forbidden, getChannel: forbidden })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        assert.strictEqual(
-          (yield* reason(Stream.runCollect(discord.history(thread, { direction: "forward" })))).tag,
-          "Forbidden"
-        )
-        assert.strictEqual((yield* reason(discord.opener(thread))).tag, "Forbidden")
-      })
-    )
-  })
+  it.effect("opener is None when the bot can't read it", () =>
+    withAdapter(
+      { getChannel: () => Effect.succeed(threadChannel), getMessage: forbidden },
+      (discord) =>
+        Effect.gen(function*() {
+          assert.isTrue(Option.isNone(yield* discord.opener(thread)))
+        })
+    ))
 })
 
-describe("invalid timestamps", () => {
-  it.effect("a post answer with an invalid timestamp fails, as any unreadable write answer does", () => {
-    const fake = makeFake({ createMessage: () => Effect.succeed({ ...posted, timestamp: "not a date" }) })
-    return run(
-      fake,
+it.effect("download reads the message again for the URL and fails TooLarge past maxBytes", () => {
+  const raw = step("posts", "attachment-fixed").response
+  const attachment = { id: `${raw.id}/${raw.attachments[0].id}` }
+  const content = new TextEncoder().encode("hello from effect/chat\n")
+  return withAdapter(
+    { getMessage: () => Effect.succeed(raw), download: () => Effect.succeed(content) },
+    (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        const result = yield* reason(discord.post(channel, { markdown: "x" }))
-        assert.strictEqual(result.tag, "Unknown")
-        assert.strictEqual(result.detail, "invalid_timestamp")
+        const bytes = yield* Stream.runCollect(discord.download(channel, attachment, { maxBytes: content.length }))
+        assert.deepStrictEqual(Array.from(bytes), [content])
+        assert.deepStrictEqual(fake.called("download")[0], [raw.attachments[0].url])
+        const tooLarge = yield* reason(Stream.runCollect(discord.download(channel, attachment, { maxBytes: 5 })))
+        assert.deepStrictEqual([tooLarge.tag, tooLarge.detail], ["TooLarge", "max_bytes"])
       })
-    )
-  })
+  )
 })
 
 describe("getThread and getUser", () => {
   it.effect("getThread gives the kind, name and parent", () => {
-    const fake = makeFake({
-      getChannel: (id: string) =>
-        Effect.succeed(
-          id === threadId
-            ? threadChannel
-            : id === scratch
-            ? step("channels", "get-channel-text").response
-            : step("channels", "get-channel-dm").response
-        )
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const info = yield* discord.getThread(thread)
-        assert.strictEqual(info.kind, "thread")
-        assert.strictEqual(info.name, "Fixture thread from a message")
-        assert.deepStrictEqual(info.parent, channel)
-        assert.isDefined(info.createdAt)
-        const text = yield* discord.getThread(channel)
-        assert.strictEqual(text.kind, "channel")
-        assert.strictEqual(text.name, "effect-chat-scratch")
-        assert.isUndefined(text.parent)
-        const dm = yield* discord.getThread(DiscordChat.thread(step("channels", "get-channel-dm").response.id))
-        assert.strictEqual(dm.kind, "direct")
-        assert.isUndefined(dm.name)
-      })
+    const dm = step("channels", "get-channel-dm").response
+    return withAdapter(
+      { getChannel: (id: string) => Effect.succeed(id === threadId ? threadChannel : dm) },
+      (discord) =>
+        Effect.gen(function*() {
+          const info = yield* discord.getThread(thread)
+          assert.deepStrictEqual([info.kind, info.name, info.parent], [
+            "thread",
+            "Fixture thread from a message",
+            channel
+          ])
+          const direct = yield* discord.getThread(DiscordChat.thread(dm.id))
+          assert.deepStrictEqual([direct.kind, direct.name], ["direct", undefined])
+        })
     )
   })
 
-  it.effect("getUser gives the guild nick with in, and NotFound for a webhook", () => {
-    const member = step("users", "get-member-bot").response
-    const fake = makeFake({
+  it.effect("getUser with in gives the guild nick, with the member as raw", () => {
+    const member = { ...step("users", "get-member-bot").response, nick: "Janny" }
+    return withAdapter({
       getChannel: () => Effect.succeed(step("channels", "get-channel-text").response),
-      getGuildMember: () => Effect.succeed({ ...member, nick: "Janny" }),
-      getUser: (id: string) =>
-        id === botUserId ? answer(step("users", "get-user-bot")) : answer(step("errors", "get-user-webhook"))
-    })
-    return run(
-      fake,
+      getGuildMember: () => Effect.succeed(member),
+      getUser: () => answer(step("users", "get-user-bot"))
+    }, (discord, fake) =>
       Effect.gen(function*() {
-        const discord = yield* adapter
-        const inGuild = yield* discord.getUser(botUserId, { in: channel })
-        assert.strictEqual(inGuild.name, "Janny")
-        assert.isTrue(inGuild.isSelf && inGuild.isBot)
-        // raw is the guild member, so the roles are there to read.
-        assert.deepStrictEqual(inGuild.raw, { ...member, nick: "Janny" })
+        const user = yield* discord.getUser(botUserId, { in: channel })
+        assert.strictEqual(user.name, "Janny")
+        assert.deepStrictEqual(user.raw, member)
         assert.deepStrictEqual(fake.called("getGuildMember"), [[guild, botUserId]])
-        const plain = yield* discord.getUser(botUserId)
-        assert.strictEqual(plain.name, "Janitor")
-        assert.deepStrictEqual(plain.raw, step("users", "get-user-bot").response)
-        assert.strictEqual((yield* reason(discord.getUser("1570607260156297307"))).tag, "NotFound")
-      })
-    )
-  })
-
-  it.effect("guild reads the channel once", () => {
-    const fake = makeFake({ getChannel: () => Effect.succeed(step("channels", "get-channel-text").response) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        assert.deepStrictEqual(yield* discord.guild(channel), Option.some(guild))
-        assert.deepStrictEqual(yield* discord.guild(channel), Option.some(guild))
-        assert.strictEqual(fake.called("getChannel").length, 1)
-      })
-    )
+        assert.strictEqual((yield* discord.getUser(botUserId)).name, "Janitor")
+      }))
   })
 })
 
-describe("download", () => {
-  it.effect("reads the message again for the URL and stops past maxBytes", () => {
-    const raw = step("posts", "attachment-fixed").response
-    const fake = makeFake({ getMessage: () => Effect.succeed(raw) })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* adapter
-        const event = yield* Effect.succeed(events("attachment")[0])
-        const [attachment] = (DiscordChat.normalize(event, { botUserId }) as any).success[0].message.attachments
-        const attachmentFromPost = { ...attachment, id: `${raw.id}/${raw.attachments[0].id}` }
-        const bytes = yield* Stream.runCollect(discord.download(channel, attachmentFromPost, { maxBytes: 100 }))
-        assert.strictEqual(new TextDecoder().decode(Array.from(bytes)[0]), "hello from effect/chat\n")
-        const tooLarge = yield* reason(
-          Stream.runCollect(discord.download(channel, attachmentFromPost, { maxBytes: 5 }))
-        )
-        assert.strictEqual(tooLarge.tag, "TooLarge")
-      }),
-      { download: new TextEncoder().encode("hello from effect/chat\n") }
-    )
-  })
-})
-
-describe("dispatch", () => {
-  const collect = () => {
-    const seen: Array = []
-    const handler = ChatHandler.of({ handle: (event) => Effect.sync(() => void seen.push(event)) })
-    return { seen, provide: Effect.provideService(ChatHandler, handler) }
-  }
+describe("dispatch without channel_type", () => {
   const missing = events("channel-message-without-channel-type")[0]
+  /** Dispatches `missing` through `DiscordChat.dispatch`, keeping what the handler saw. */
+  const dispatcher = (seen: Array) =>
+    Effect.map(DiscordChat.DiscordChat, (discord) =>
+      discord.dispatch(missing).pipe(
+        Effect.provideService(
+          ChatHandler,
+          ChatHandler.of({ handle: (event) => Effect.sync(() => void seen.push(event)) })
+        )
+      ))
 
-  it.effect("delivers a message with channel_type without a lookup", () => {
-    const fake = makeFake({})
-    const { provide, seen } = collect()
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        yield* provide(discord.dispatch(events("channel-message")[0]))
-        yield* provide(discord.dispatch({ t: "READY", d: {} }))
-        yield* provide(discord.dispatch(events("thread-started")[0]))
-        assert.strictEqual(seen.length, 1)
-        assert.strictEqual(fake.calls.length, 0)
-      })
-    )
-  })
-
-  it.effect("looks the channel up once when channel_type is missing", () => {
-    const fake = makeFake({ getChannel: () => Effect.succeed(threadChannel) })
-    const { provide, seen } = collect()
-    return run(
-      fake,
+  it.effect("looks the channel up once", () =>
+    withAdapter({ getChannel: () => Effect.succeed(threadChannel) }, (_, fake) =>
       Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        yield* provide(discord.dispatch(missing))
-        yield* provide(discord.dispatch(missing))
-        assert.strictEqual(seen.length, 2)
-        assert(seen[0]._tag === "MessageCreated")
-        assert.strictEqual(seen[0].kind, "thread")
+        const seen: Array = []
+        const dispatch = yield* dispatcher(seen)
+        yield* dispatch
+        yield* dispatch
+        assert.deepStrictEqual(seen.map((event) => event._tag === "MessageCreated" && event.kind), ["thread", "thread"])
         assert.deepStrictEqual(fake.called("getChannel"), [[scratch]])
-      })
-    )
-  })
+      })))
 
   it.effect("fails NotAccepted when the lookup fails, and tries again next time", () => {
     let attempts = 0
-    const fake = makeFake({
+    return withAdapter({
       getChannel: () =>
         attempts++ < 4
           ? Effect.fail(statusCodeError(500))
           : Effect.succeed(step("channels", "get-channel-text").response)
-    })
-    const { provide, seen } = collect()
-    return run(
-      fake,
+    }, () =>
       Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        const fiber = yield* Effect.forkChild(Effect.flip(provide(discord.dispatch(missing))))
+        const seen: Array = []
+        const dispatch = yield* dispatcher(seen)
+        const fiber = yield* Effect.forkChild(Effect.flip(dispatch))
         yield* TestClock.adjust("10 seconds")
         assert.instanceOf(yield* Fiber.join(fiber), NotAccepted)
         assert.strictEqual(seen.length, 0)
-        yield* provide(discord.dispatch(missing))
+        yield* dispatch
         assert.strictEqual(seen.length, 1)
-      })
-    )
+      }))
   })
 
-  it.effect("drops the event when the lookup is denied", () => {
-    const fake = makeFake({ getChannel: () => answer(step("errors", "get-channel-unknown")) })
-    const { provide, seen } = collect()
-    return run(
-      fake,
+  it.effect("drops the event when the lookup is denied", () =>
+    withAdapter({ getChannel: () => answer(step("errors", "get-channel-unknown")) }, () =>
       Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        yield* provide(discord.dispatch(missing))
+        const seen: Array = []
+        yield* Effect.flatten(dispatcher(seen))
         assert.strictEqual(seen.length, 0)
-      })
-    )
-  })
-
-  it.effect("fails NotAccepted when the lookup takes longer than five seconds", () => {
-    const fake = makeFake({ getChannel: () => Effect.never })
-    const { provide } = collect()
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const discord = yield* DiscordChat.DiscordChat
-        const fiber = yield* Effect.forkChild(Effect.flip(provide(discord.dispatch(missing))))
-        yield* TestClock.adjust("5 seconds")
-        assert.instanceOf(yield* Fiber.join(fiber), NotAccepted)
-      })
-    )
-  })
+      })))
 })
diff --git a/packages/chat/discord/test/commands.test.ts b/packages/chat/discord/test/commands.test.ts
index edef84bbcb7..838ca43ac01 100644
--- a/packages/chat/discord/test/commands.test.ts
+++ b/packages/chat/discord/test/commands.test.ts
@@ -11,26 +11,18 @@ import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Option from "effect/Option"
 import * as TestClock from "effect/testing/TestClock"
-import {
-  botUserId,
-  discordLayer,
-  errorResponse,
-  type Fake,
-  makeFake,
-  recordedCommands as recorded,
-  test,
-  tim
-} from "./utils.ts"
+import { botUserId, discordLayer, errorResponse, type Fake, makeFake, recordedCommands as recorded } from "./utils.ts"
 
 // The definitions the capture ran, from eff-3802-capture.ts.
-const AckButton = ChatInteraction.button("cap-ack", { label: "Ack" })
-const ModalButton = ChatInteraction.button("cap-open", { label: "Open modal", style: "primary" })
+const actions = [
+  ChatInteraction.button("cap-ack", { label: "Ack" }).of(),
+  ChatInteraction.button("cap-open", { label: "Open modal", style: "primary" }).of()
+]
 const Modal = ChatInteraction.modal("cap-modal", {
   title: "Capture",
   submitLabel: "Send",
   fields: { note: ChatInteraction.textInput({ label: "Note (type err for a field error)" }) }
 })
-const actions = [AckButton.of(), ModalButton.of()]
 
 /** The capture's handler, by the command's text. */
 const reply = (command: ChatInteraction.CommandInvoked): ChatInteraction.CommandReply => {
@@ -59,83 +51,32 @@ const reply = (command: ChatInteraction.CommandInvoked): ChatInteraction.Command
 
 const handler = ChatInteraction.Handler.of({
   click: () => Effect.succeed(ChatInteraction.ack),
-  submit: (submit) =>
-    Effect.succeed(
-      submit.values.note === "err"
-        ? ChatInteraction.errors({ note: "That is the error you asked for" })
-        : ChatInteraction.close
-    ),
+  submit: () => Effect.succeed(ChatInteraction.close),
   command: (command) => Effect.succeed(reply(command)),
   refused: (_, error) => Effect.die(error)
 })
 
 const normalize = (payload: unknown) => Option.getOrThrow(DiscordChat.normalizeInteraction(payload))
 
-const deliver = (fake: Fake, payload: unknown) =>
-  Effect.flatMap(DiscordChat.DiscordChat, (discord) => discord.interaction(payload)).pipe(
-    Effect.provideService(ChatInteraction.Handler, handler),
-    Effect.provide(discordLayer(fake))
-  )
-
-const answering = () => makeFake({ createInteractionResponse: () => Effect.succeed(null) })
-
-/** The callbacks sent, as [interaction id, token, body]. */
-const callbacks = (fake: Fake) =>
-  fake.called("createInteractionResponse").map(([id, token, options]) => [id, token, options.payload])
-
-/** When Discord made an interaction, from its snowflake. */
-const issuedAt = (id: string) => Number((BigInt(id) >> 22n) + 1420070400000n)
-
 describe("recorded slash commands", () => {
   it.effect("answers each command with the callback Discord took", () =>
     Effect.gen(function*() {
       for (const what of ["private", "public", "mention", "modal", "defer", "deferPublic"]) {
-        const fake = answering()
+        const fake = makeFake({ createInteractionResponse: () => Effect.succeed(null) })
         const payload = recorded.commands[what]
-        yield* deliver(fake, payload)
-        assert.deepStrictEqual(callbacks(fake), [[payload.id, "", recorded.callbacks[what].payload]], what)
-        assert.strictEqual(recorded.callbacks[what].status, 204)
-      }
-    }))
-
-  it.effect("takes a click on a private answer, whose message has the ephemeral flag, and acks it", () =>
-    Effect.gen(function*() {
-      const payload = recorded.clicks.privateAnswer
-      const click = normalize(payload)
-      assert.strictEqual(click._tag, "ButtonClicked")
-      if (click._tag !== "ButtonClicked") return
-      // The id names where the click came from, a message only the
-      // interaction's token reaches.
-      assert.deepStrictEqual([click.id, click.messageId, click.thread.id], ["cap-ack", payload.message.id, test])
-      assert.strictEqual(payload.message.flags & 64, 64)
-      const fake = answering()
-      yield* deliver(fake, payload)
-      assert.deepStrictEqual(callbacks(fake), [[
-        payload.id,
-        "",
-        recorded.clicks.privateAnswerCallback.payload
-      ]])
-    }))
-
-  it.effect("gives a submit of a command's modal no messageId, and answers it the way Discord took", () =>
-    Effect.gen(function*() {
-      for (const [what, callback] of [["submitErrors", "errorsCallback"], ["submitClose", "closeCallback"]] as const) {
-        const payload = recorded.commandModal[what]
-        assert.isFalse("message" in payload)
-        const submitted = normalize(payload)
-        assert.strictEqual(submitted._tag, "ModalSubmitted", what)
-        if (submitted._tag !== "ModalSubmitted") return
-        assert.deepStrictEqual([submitted.id, submitted.thread.id, submitted.userId], ["cap-modal", test, tim])
-        assert.isFalse("messageId" in submitted)
-        const fake = answering()
-        yield* deliver(fake, payload)
-        assert.deepStrictEqual(callbacks(fake), [[payload.id, "", recorded.commandModal[callback].payload]])
+        yield* Effect.flatMap(DiscordChat.DiscordChat, (discord) => discord.interaction(payload)).pipe(
+          Effect.provideService(ChatInteraction.Handler, handler),
+          Effect.provide(discordLayer(fake))
+        )
+        assert.deepStrictEqual(
+          fake.called("createInteractionResponse").map(([id, token, options]) => [id, token, options.payload]),
+          [[payload.id, "", recorded.callbacks[what].payload]],
+          what
+        )
       }
-      // Type 6 closed the modal.
-      assert.deepStrictEqual(recorded.commandModal.closeCallback.payload, { type: 6 })
     }))
 
-  it.effect("follows up with the edit Discord took, and maps its answer after 15 minutes", () =>
+  it.effect("follows up with the edit Discord took, and is interaction_expired once the token is spent", () =>
     Effect.gen(function*() {
       const payload = recorded.commands.defer
       const deferred = ChatInteraction.defer(normalize(payload) as ChatInteraction.CommandInvoked)
@@ -143,10 +84,8 @@ describe("recorded slash commands", () => {
         Effect.flatMap(
           Chat.Chat,
           (chat) => chat.followUp(deferred, { markdown: "**Deferred answer** to defer, with buttons", actions })
-        ).pipe(
-          Effect.provide(discordLayer(fake))
-        )
-      const issued = issuedAt(payload.id)
+        ).pipe(Effect.provide(discordLayer(fake)))
+      const issued = Number((BigInt(payload.id) >> 22n) + 1420070400000n)
       yield* TestClock.setTime(issued + 4_000)
       const edited = makeFake({ updateOriginalWebhookMessage: () => Effect.succeed(recorded.followUp.response.body) })
       yield* followUp(edited)
@@ -159,12 +98,12 @@ describe("recorded slash commands", () => {
         [[botUserId, "", recorded.followUp.request]]
       )
 
-      // What Discord answered at 15.5 minutes, 401 with 50027, here returned
-      // early so the mapping is reached before the adapter's own refusal. The
-      // live run refused before sending, so only this reaches the mapping.
-      const { body, status } = recorded.expired.edit
-      assert.deepStrictEqual([status, body.code], [401, 50027])
-      const spent = makeFake({ updateOriginalWebhookMessage: () => Effect.fail(errorResponse(status, body)) })
+      // What Discord answered at 15.5 minutes, 401 with 50027, returned here
+      // early; past 15 minutes the adapter refuses without a call.
+      const spent = makeFake({
+        updateOriginalWebhookMessage: () =>
+          Effect.fail(errorResponse(recorded.expired.edit.status, recorded.expired.edit.body))
+      })
       const mapped = yield* Effect.flip(followUp(spent))
       yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) + 30_000)
       const refused = yield* Effect.flip(followUp(spent))
diff --git a/packages/chat/discord/test/conformance.test.ts b/packages/chat/discord/test/conformance.test.ts
index 778c4d641cd..1da8556bf2c 100644
--- a/packages/chat/discord/test/conformance.test.ts
+++ b/packages/chat/discord/test/conformance.test.ts
@@ -24,28 +24,21 @@ const portable = (name: string) =>
   name === "unsupported/commands" ||
   name === "unsupported/ephemeral"
 
-describe("conformance over the stubbed DiscordREST", () => {
-  const names = Object.keys(conformance({
+const rules = (discord: ReturnType) =>
+  conformance({
     platform: "discord",
     thread: DiscordChat.thread(scratch),
     userPosts: () => Effect.die("unused"),
     parseMention: DiscordChat.parseMention,
-    refuseFiles: () => Effect.void,
-    interactions: { click: () => Effect.void, submit: () => Effect.void, command: () => Effect.void }
-  })).filter(portable)
+    refuseFiles: discord.refuseFiles,
+    interactions: discord.interactions
+  })
 
-  for (const name of names) {
+describe("conformance over the stubbed DiscordREST", () => {
+  for (const name of Object.keys(rules(makeDiscord())).filter(portable)) {
     it.effect(name, () => {
       const discord = makeDiscord()
-      const rules = conformance({
-        platform: "discord",
-        thread: DiscordChat.thread(scratch),
-        userPosts: () => Effect.die("unused"),
-        parseMention: DiscordChat.parseMention,
-        refuseFiles: discord.refuseFiles,
-        interactions: discord.interactions
-      })
-      return Effect.andThen(discord.bind, rules[name]).pipe(Effect.provide(discordLayer(discord.fake)))
+      return Effect.andThen(discord.bind, rules(discord)[name]).pipe(Effect.provide(discordLayer(discord.fake)))
     })
   }
 })
diff --git a/packages/chat/discord/test/discord.ts b/packages/chat/discord/test/discord.ts
index 76fa7f047ef..fd5cdb4deb6 100644
--- a/packages/chat/discord/test/discord.ts
+++ b/packages/chat/discord/test/discord.ts
@@ -10,8 +10,7 @@ const idOf = (customId: string): string => customId.split(join)[0]
 
 /**
  * A Discord that keeps the messages the adapter posts, with their
- * components, and records every interaction callback and every edit of an
- * original response. `interactions` is the conformance hook: it builds
+ * components, and records every interaction callback. `interactions` is the conformance hook: it builds
  * Discord's `INTERACTION_CREATE` payload from what was posted, or a slash
  * command's, and sends it through `DiscordChat.interaction`. A command
  * starts from the one recorded in `fixtures/recorded/commands.json`, and so
@@ -20,7 +19,6 @@ const idOf = (customId: string): string => customId.split(join)[0]
 export const makeDiscord = (channelType = 0) => {
   const messages = new Map()
   const callbacks: Array<{ readonly id: string; readonly token: string; readonly payload: any }> = []
-  const originals: Array<{ readonly applicationId: string; readonly token: string; readonly payload: any }> = []
   let next = 1570700000000000000n
   let refuse = 0
   let interactionCount = 0
@@ -78,12 +76,11 @@ export const makeDiscord = (channelType = 0) => {
       callbacks.push({ id, token, payload: options.payload })
       return Effect.succeed(null)
     },
-    updateOriginalWebhookMessage: (applicationId: string, token: string, options: { payload: any }) => {
+    updateOriginalWebhookMessage: (_applicationId: string, token: string, options: { payload: any }) => {
       // Only a token a type 5 callback answered has an original response to edit.
       if (!callbacks.some((callback) => callback.token === token && callback.payload.type === 5)) {
         return Effect.fail(errorResponse(404, { code: 10015, message: "Unknown Webhook" }))
       }
-      originals.push({ applicationId, token, payload: options.payload })
       return Effect.succeed({ id: nextId(), content: options.payload.content })
     }
   })
@@ -184,9 +181,6 @@ export const makeDiscord = (channelType = 0) => {
       Effect.sync(() => {
         service = discord
       })),
-    messages,
-    callbacks,
-    originals,
     interactions,
     refuseFiles: () =>
       Effect.sync(() => {
diff --git a/packages/chat/discord/test/fixtures/recorded/components.json b/packages/chat/discord/test/fixtures/recorded/components.json
deleted file mode 100644
index 69afccf840e..00000000000
--- a/packages/chat/discord/test/fixtures/recorded/components.json
+++ /dev/null
@@ -1,2345 +0,0 @@
-{
-  "case": "Action rows as the adapter's rows() builds them and as Discord refuses them, an edit that clears them, custom_id length in code points, and callbacks for an interaction Discord doesn't know",
-  "provenance": {
-    "kind": "recorded",
-    "source": "Discord REST v10 with the Janitor bot token, from a local script",
-    "where": "guild 840178841540362250 (Tim's test guild); #test 1570605581192929301. The callbacks name no guild: their interaction id and token are made up, and Discord answers 10062 before it reads the body",
-    "recordedAt": "2026-11-13T08:40Z, during EFF-3755",
-    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed. Every posted message was deleted after it was read"
-  },
-  "calls": [
-    {
-      "step": "rows-25-buttons",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: rows-25-buttons",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b0",
-                "custom_id": "b0␟v0"
-              },
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b1",
-                "custom_id": "b1␟v1"
-              },
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b2",
-                "custom_id": "b2␟v2"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b3",
-                "custom_id": "b3␟v3"
-              },
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b4",
-                "custom_id": "b4␟v4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b5",
-                "custom_id": "b5␟v5"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b6",
-                "custom_id": "b6␟v6"
-              },
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b7",
-                "custom_id": "b7␟v7"
-              },
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b8",
-                "custom_id": "b8␟v8"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b9",
-                "custom_id": "b9␟v9"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b10",
-                "custom_id": "b10␟v10"
-              },
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b11",
-                "custom_id": "b11␟v11"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b12",
-                "custom_id": "b12␟v12"
-              },
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b13",
-                "custom_id": "b13␟v13"
-              },
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b14",
-                "custom_id": "b14␟v14"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b15",
-                "custom_id": "b15␟v15"
-              },
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b16",
-                "custom_id": "b16␟v16"
-              },
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b17",
-                "custom_id": "b17␟v17"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b18",
-                "custom_id": "b18␟v18"
-              },
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b19",
-                "custom_id": "b19␟v19"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b20",
-                "custom_id": "b20␟v20"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b21",
-                "custom_id": "b21␟v21"
-              },
-              {
-                "type": 2,
-                "style": 1,
-                "label": "b22",
-                "custom_id": "b22␟v22"
-              },
-              {
-                "type": 2,
-                "style": 4,
-                "label": "b23",
-                "custom_id": "b23␟v23"
-              },
-              {
-                "type": 2,
-                "style": 5,
-                "label": "link",
-                "url": "https://effect.website"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "effect-chat probe: rows-25-buttons",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T08:40:57.239000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [
-          {
-            "type": 1,
-            "id": 1,
-            "components": [
-              {
-                "type": 2,
-                "id": 2,
-                "custom_id": "b0␟v0",
-                "style": 2,
-                "label": "b0"
-              },
-              {
-                "type": 2,
-                "id": 3,
-                "custom_id": "b1␟v1",
-                "style": 1,
-                "label": "b1"
-              },
-              {
-                "type": 2,
-                "id": 4,
-                "custom_id": "b2␟v2",
-                "style": 4,
-                "label": "b2"
-              },
-              {
-                "type": 2,
-                "id": 5,
-                "custom_id": "b3␟v3",
-                "style": 2,
-                "label": "b3"
-              },
-              {
-                "type": 2,
-                "id": 6,
-                "custom_id": "b4␟v4",
-                "style": 1,
-                "label": "b4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 7,
-            "components": [
-              {
-                "type": 2,
-                "id": 8,
-                "custom_id": "b5␟v5",
-                "style": 4,
-                "label": "b5"
-              },
-              {
-                "type": 2,
-                "id": 9,
-                "custom_id": "b6␟v6",
-                "style": 2,
-                "label": "b6"
-              },
-              {
-                "type": 2,
-                "id": 10,
-                "custom_id": "b7␟v7",
-                "style": 1,
-                "label": "b7"
-              },
-              {
-                "type": 2,
-                "id": 11,
-                "custom_id": "b8␟v8",
-                "style": 4,
-                "label": "b8"
-              },
-              {
-                "type": 2,
-                "id": 12,
-                "custom_id": "b9␟v9",
-                "style": 2,
-                "label": "b9"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 13,
-            "components": [
-              {
-                "type": 2,
-                "id": 14,
-                "custom_id": "b10␟v10",
-                "style": 1,
-                "label": "b10"
-              },
-              {
-                "type": 2,
-                "id": 15,
-                "custom_id": "b11␟v11",
-                "style": 4,
-                "label": "b11"
-              },
-              {
-                "type": 2,
-                "id": 16,
-                "custom_id": "b12␟v12",
-                "style": 2,
-                "label": "b12"
-              },
-              {
-                "type": 2,
-                "id": 17,
-                "custom_id": "b13␟v13",
-                "style": 1,
-                "label": "b13"
-              },
-              {
-                "type": 2,
-                "id": 18,
-                "custom_id": "b14␟v14",
-                "style": 4,
-                "label": "b14"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 19,
-            "components": [
-              {
-                "type": 2,
-                "id": 20,
-                "custom_id": "b15␟v15",
-                "style": 2,
-                "label": "b15"
-              },
-              {
-                "type": 2,
-                "id": 21,
-                "custom_id": "b16␟v16",
-                "style": 1,
-                "label": "b16"
-              },
-              {
-                "type": 2,
-                "id": 22,
-                "custom_id": "b17␟v17",
-                "style": 4,
-                "label": "b17"
-              },
-              {
-                "type": 2,
-                "id": 23,
-                "custom_id": "b18␟v18",
-                "style": 2,
-                "label": "b18"
-              },
-              {
-                "type": 2,
-                "id": 24,
-                "custom_id": "b19␟v19",
-                "style": 1,
-                "label": "b19"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 25,
-            "components": [
-              {
-                "type": 2,
-                "id": 26,
-                "custom_id": "b20␟v20",
-                "style": 4,
-                "label": "b20"
-              },
-              {
-                "type": 2,
-                "id": 27,
-                "custom_id": "b21␟v21",
-                "style": 2,
-                "label": "b21"
-              },
-              {
-                "type": 2,
-                "id": 28,
-                "custom_id": "b22␟v22",
-                "style": 1,
-                "label": "b22"
-              },
-              {
-                "type": 2,
-                "id": 29,
-                "custom_id": "b23␟v23",
-                "style": 4,
-                "label": "b23"
-              },
-              {
-                "type": 2,
-                "id": 30,
-                "style": 5,
-                "label": "link",
-                "url": "https://effect.website"
-              }
-            ]
-          }
-        ],
-        "id": "1570720111872975040",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "rows-25-buttons/read",
-      "method": "GET",
-      "path": "/channels/1570605581192929301/messages/1570720111872975040",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "effect-chat probe: rows-25-buttons",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T08:40:57.239000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [
-          {
-            "type": 1,
-            "id": 1,
-            "components": [
-              {
-                "type": 2,
-                "id": 2,
-                "custom_id": "b0␟v0",
-                "style": 2,
-                "label": "b0"
-              },
-              {
-                "type": 2,
-                "id": 3,
-                "custom_id": "b1␟v1",
-                "style": 1,
-                "label": "b1"
-              },
-              {
-                "type": 2,
-                "id": 4,
-                "custom_id": "b2␟v2",
-                "style": 4,
-                "label": "b2"
-              },
-              {
-                "type": 2,
-                "id": 5,
-                "custom_id": "b3␟v3",
-                "style": 2,
-                "label": "b3"
-              },
-              {
-                "type": 2,
-                "id": 6,
-                "custom_id": "b4␟v4",
-                "style": 1,
-                "label": "b4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 7,
-            "components": [
-              {
-                "type": 2,
-                "id": 8,
-                "custom_id": "b5␟v5",
-                "style": 4,
-                "label": "b5"
-              },
-              {
-                "type": 2,
-                "id": 9,
-                "custom_id": "b6␟v6",
-                "style": 2,
-                "label": "b6"
-              },
-              {
-                "type": 2,
-                "id": 10,
-                "custom_id": "b7␟v7",
-                "style": 1,
-                "label": "b7"
-              },
-              {
-                "type": 2,
-                "id": 11,
-                "custom_id": "b8␟v8",
-                "style": 4,
-                "label": "b8"
-              },
-              {
-                "type": 2,
-                "id": 12,
-                "custom_id": "b9␟v9",
-                "style": 2,
-                "label": "b9"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 13,
-            "components": [
-              {
-                "type": 2,
-                "id": 14,
-                "custom_id": "b10␟v10",
-                "style": 1,
-                "label": "b10"
-              },
-              {
-                "type": 2,
-                "id": 15,
-                "custom_id": "b11␟v11",
-                "style": 4,
-                "label": "b11"
-              },
-              {
-                "type": 2,
-                "id": 16,
-                "custom_id": "b12␟v12",
-                "style": 2,
-                "label": "b12"
-              },
-              {
-                "type": 2,
-                "id": 17,
-                "custom_id": "b13␟v13",
-                "style": 1,
-                "label": "b13"
-              },
-              {
-                "type": 2,
-                "id": 18,
-                "custom_id": "b14␟v14",
-                "style": 4,
-                "label": "b14"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 19,
-            "components": [
-              {
-                "type": 2,
-                "id": 20,
-                "custom_id": "b15␟v15",
-                "style": 2,
-                "label": "b15"
-              },
-              {
-                "type": 2,
-                "id": 21,
-                "custom_id": "b16␟v16",
-                "style": 1,
-                "label": "b16"
-              },
-              {
-                "type": 2,
-                "id": 22,
-                "custom_id": "b17␟v17",
-                "style": 4,
-                "label": "b17"
-              },
-              {
-                "type": 2,
-                "id": 23,
-                "custom_id": "b18␟v18",
-                "style": 2,
-                "label": "b18"
-              },
-              {
-                "type": 2,
-                "id": 24,
-                "custom_id": "b19␟v19",
-                "style": 1,
-                "label": "b19"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 25,
-            "components": [
-              {
-                "type": 2,
-                "id": 26,
-                "custom_id": "b20␟v20",
-                "style": 4,
-                "label": "b20"
-              },
-              {
-                "type": 2,
-                "id": 27,
-                "custom_id": "b21␟v21",
-                "style": 2,
-                "label": "b21"
-              },
-              {
-                "type": 2,
-                "id": 28,
-                "custom_id": "b22␟v22",
-                "style": 1,
-                "label": "b22"
-              },
-              {
-                "type": 2,
-                "id": 29,
-                "custom_id": "b23␟v23",
-                "style": 4,
-                "label": "b23"
-              },
-              {
-                "type": 2,
-                "id": 30,
-                "style": 5,
-                "label": "link",
-                "url": "https://effect.website"
-              }
-            ]
-          }
-        ],
-        "id": "1570720111872975040",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "rows-25-buttons/edit-clears",
-      "method": "PATCH",
-      "path": "/channels/1570605581192929301/messages/1570720111872975040",
-      "request": {
-        "content": "effect-chat probe: edited",
-        "components": []
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "effect-chat probe: edited",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T08:40:57.239000+00:00",
-        "edited_timestamp": "2026-11-13T08:40:57.601507+00:00",
-        "flags": 0,
-        "components": [],
-        "id": "1570720111872975040",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "rows-selects-and-buttons",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: rows-selects-and-buttons",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b0",
-                "custom_id": "b0␟v0"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b1",
-                "custom_id": "b1␟v1"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b2",
-                "custom_id": "b2␟v2"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b3",
-                "custom_id": "b3␟v3"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b4",
-                "custom_id": "b4␟v4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 3,
-                "custom_id": "s1",
-                "options": [
-                  {
-                    "label": "o0",
-                    "value": "o0"
-                  },
-                  {
-                    "label": "o1",
-                    "value": "o1"
-                  },
-                  {
-                    "label": "o2",
-                    "value": "o2"
-                  },
-                  {
-                    "label": "o3",
-                    "value": "o3",
-                    "default": true
-                  },
-                  {
-                    "label": "o4",
-                    "value": "o4"
-                  },
-                  {
-                    "label": "o5",
-                    "value": "o5"
-                  },
-                  {
-                    "label": "o6",
-                    "value": "o6"
-                  },
-                  {
-                    "label": "o7",
-                    "value": "o7"
-                  },
-                  {
-                    "label": "o8",
-                    "value": "o8"
-                  },
-                  {
-                    "label": "o9",
-                    "value": "o9"
-                  },
-                  {
-                    "label": "o10",
-                    "value": "o10"
-                  },
-                  {
-                    "label": "o11",
-                    "value": "o11"
-                  },
-                  {
-                    "label": "o12",
-                    "value": "o12"
-                  },
-                  {
-                    "label": "o13",
-                    "value": "o13"
-                  },
-                  {
-                    "label": "o14",
-                    "value": "o14"
-                  },
-                  {
-                    "label": "o15",
-                    "value": "o15"
-                  },
-                  {
-                    "label": "o16",
-                    "value": "o16"
-                  },
-                  {
-                    "label": "o17",
-                    "value": "o17"
-                  },
-                  {
-                    "label": "o18",
-                    "value": "o18"
-                  },
-                  {
-                    "label": "o19",
-                    "value": "o19"
-                  },
-                  {
-                    "label": "o20",
-                    "value": "o20"
-                  },
-                  {
-                    "label": "o21",
-                    "value": "o21"
-                  },
-                  {
-                    "label": "o22",
-                    "value": "o22"
-                  },
-                  {
-                    "label": "o23",
-                    "value": "o23"
-                  },
-                  {
-                    "label": "o24",
-                    "value": "o24"
-                  }
-                ],
-                "min_values": 1,
-                "max_values": 1
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b5",
-                "custom_id": "b5␟v5"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b6",
-                "custom_id": "b6␟v6"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b7",
-                "custom_id": "b7␟v7"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b8",
-                "custom_id": "b8␟v8"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b9",
-                "custom_id": "b9␟v9"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 3,
-                "custom_id": "s2",
-                "options": [
-                  {
-                    "label": "o0",
-                    "value": "o0"
-                  },
-                  {
-                    "label": "o1",
-                    "value": "o1"
-                  }
-                ],
-                "min_values": 1,
-                "max_values": 1
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b10",
-                "custom_id": "b10␟v10"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b11",
-                "custom_id": "b11␟v11"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b12",
-                "custom_id": "b12␟v12"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b13",
-                "custom_id": "b13␟v13"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b14",
-                "custom_id": "b14␟v14"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "effect-chat probe: rows-selects-and-buttons",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T08:40:57.926000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [
-          {
-            "type": 1,
-            "id": 1,
-            "components": [
-              {
-                "type": 2,
-                "id": 2,
-                "custom_id": "b0␟v0",
-                "style": 2,
-                "label": "b0"
-              },
-              {
-                "type": 2,
-                "id": 3,
-                "custom_id": "b1␟v1",
-                "style": 2,
-                "label": "b1"
-              },
-              {
-                "type": 2,
-                "id": 4,
-                "custom_id": "b2␟v2",
-                "style": 2,
-                "label": "b2"
-              },
-              {
-                "type": 2,
-                "id": 5,
-                "custom_id": "b3␟v3",
-                "style": 2,
-                "label": "b3"
-              },
-              {
-                "type": 2,
-                "id": 6,
-                "custom_id": "b4␟v4",
-                "style": 2,
-                "label": "b4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 7,
-            "components": [
-              {
-                "type": 3,
-                "id": 8,
-                "custom_id": "s1",
-                "min_values": 1,
-                "max_values": 1,
-                "options": [
-                  {
-                    "label": "o0",
-                    "value": "o0"
-                  },
-                  {
-                    "label": "o1",
-                    "value": "o1"
-                  },
-                  {
-                    "label": "o2",
-                    "value": "o2"
-                  },
-                  {
-                    "label": "o3",
-                    "value": "o3",
-                    "default": true
-                  },
-                  {
-                    "label": "o4",
-                    "value": "o4"
-                  },
-                  {
-                    "label": "o5",
-                    "value": "o5"
-                  },
-                  {
-                    "label": "o6",
-                    "value": "o6"
-                  },
-                  {
-                    "label": "o7",
-                    "value": "o7"
-                  },
-                  {
-                    "label": "o8",
-                    "value": "o8"
-                  },
-                  {
-                    "label": "o9",
-                    "value": "o9"
-                  },
-                  {
-                    "label": "o10",
-                    "value": "o10"
-                  },
-                  {
-                    "label": "o11",
-                    "value": "o11"
-                  },
-                  {
-                    "label": "o12",
-                    "value": "o12"
-                  },
-                  {
-                    "label": "o13",
-                    "value": "o13"
-                  },
-                  {
-                    "label": "o14",
-                    "value": "o14"
-                  },
-                  {
-                    "label": "o15",
-                    "value": "o15"
-                  },
-                  {
-                    "label": "o16",
-                    "value": "o16"
-                  },
-                  {
-                    "label": "o17",
-                    "value": "o17"
-                  },
-                  {
-                    "label": "o18",
-                    "value": "o18"
-                  },
-                  {
-                    "label": "o19",
-                    "value": "o19"
-                  },
-                  {
-                    "label": "o20",
-                    "value": "o20"
-                  },
-                  {
-                    "label": "o21",
-                    "value": "o21"
-                  },
-                  {
-                    "label": "o22",
-                    "value": "o22"
-                  },
-                  {
-                    "label": "o23",
-                    "value": "o23"
-                  },
-                  {
-                    "label": "o24",
-                    "value": "o24"
-                  }
-                ]
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 9,
-            "components": [
-              {
-                "type": 2,
-                "id": 10,
-                "custom_id": "b5␟v5",
-                "style": 2,
-                "label": "b5"
-              },
-              {
-                "type": 2,
-                "id": 11,
-                "custom_id": "b6␟v6",
-                "style": 2,
-                "label": "b6"
-              },
-              {
-                "type": 2,
-                "id": 12,
-                "custom_id": "b7␟v7",
-                "style": 2,
-                "label": "b7"
-              },
-              {
-                "type": 2,
-                "id": 13,
-                "custom_id": "b8␟v8",
-                "style": 2,
-                "label": "b8"
-              },
-              {
-                "type": 2,
-                "id": 14,
-                "custom_id": "b9␟v9",
-                "style": 2,
-                "label": "b9"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 15,
-            "components": [
-              {
-                "type": 3,
-                "id": 16,
-                "custom_id": "s2",
-                "min_values": 1,
-                "max_values": 1,
-                "options": [
-                  {
-                    "label": "o0",
-                    "value": "o0"
-                  },
-                  {
-                    "label": "o1",
-                    "value": "o1"
-                  }
-                ]
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 17,
-            "components": [
-              {
-                "type": 2,
-                "id": 18,
-                "custom_id": "b10␟v10",
-                "style": 2,
-                "label": "b10"
-              },
-              {
-                "type": 2,
-                "id": 19,
-                "custom_id": "b11␟v11",
-                "style": 2,
-                "label": "b11"
-              },
-              {
-                "type": 2,
-                "id": 20,
-                "custom_id": "b12␟v12",
-                "style": 2,
-                "label": "b12"
-              },
-              {
-                "type": 2,
-                "id": 21,
-                "custom_id": "b13␟v13",
-                "style": 2,
-                "label": "b13"
-              },
-              {
-                "type": 2,
-                "id": 22,
-                "custom_id": "b14␟v14",
-                "style": 2,
-                "label": "b14"
-              }
-            ]
-          }
-        ],
-        "id": "1570720114754723871",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "rows-selects-and-buttons/read",
-      "method": "GET",
-      "path": "/channels/1570605581192929301/messages/1570720114754723871",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "effect-chat probe: rows-selects-and-buttons",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T08:40:57.926000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [
-          {
-            "type": 1,
-            "id": 1,
-            "components": [
-              {
-                "type": 2,
-                "id": 2,
-                "custom_id": "b0␟v0",
-                "style": 2,
-                "label": "b0"
-              },
-              {
-                "type": 2,
-                "id": 3,
-                "custom_id": "b1␟v1",
-                "style": 2,
-                "label": "b1"
-              },
-              {
-                "type": 2,
-                "id": 4,
-                "custom_id": "b2␟v2",
-                "style": 2,
-                "label": "b2"
-              },
-              {
-                "type": 2,
-                "id": 5,
-                "custom_id": "b3␟v3",
-                "style": 2,
-                "label": "b3"
-              },
-              {
-                "type": 2,
-                "id": 6,
-                "custom_id": "b4␟v4",
-                "style": 2,
-                "label": "b4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 7,
-            "components": [
-              {
-                "type": 3,
-                "id": 8,
-                "custom_id": "s1",
-                "min_values": 1,
-                "max_values": 1,
-                "options": [
-                  {
-                    "label": "o0",
-                    "value": "o0"
-                  },
-                  {
-                    "label": "o1",
-                    "value": "o1"
-                  },
-                  {
-                    "label": "o2",
-                    "value": "o2"
-                  },
-                  {
-                    "label": "o3",
-                    "value": "o3",
-                    "default": true
-                  },
-                  {
-                    "label": "o4",
-                    "value": "o4"
-                  },
-                  {
-                    "label": "o5",
-                    "value": "o5"
-                  },
-                  {
-                    "label": "o6",
-                    "value": "o6"
-                  },
-                  {
-                    "label": "o7",
-                    "value": "o7"
-                  },
-                  {
-                    "label": "o8",
-                    "value": "o8"
-                  },
-                  {
-                    "label": "o9",
-                    "value": "o9"
-                  },
-                  {
-                    "label": "o10",
-                    "value": "o10"
-                  },
-                  {
-                    "label": "o11",
-                    "value": "o11"
-                  },
-                  {
-                    "label": "o12",
-                    "value": "o12"
-                  },
-                  {
-                    "label": "o13",
-                    "value": "o13"
-                  },
-                  {
-                    "label": "o14",
-                    "value": "o14"
-                  },
-                  {
-                    "label": "o15",
-                    "value": "o15"
-                  },
-                  {
-                    "label": "o16",
-                    "value": "o16"
-                  },
-                  {
-                    "label": "o17",
-                    "value": "o17"
-                  },
-                  {
-                    "label": "o18",
-                    "value": "o18"
-                  },
-                  {
-                    "label": "o19",
-                    "value": "o19"
-                  },
-                  {
-                    "label": "o20",
-                    "value": "o20"
-                  },
-                  {
-                    "label": "o21",
-                    "value": "o21"
-                  },
-                  {
-                    "label": "o22",
-                    "value": "o22"
-                  },
-                  {
-                    "label": "o23",
-                    "value": "o23"
-                  },
-                  {
-                    "label": "o24",
-                    "value": "o24"
-                  }
-                ]
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 9,
-            "components": [
-              {
-                "type": 2,
-                "id": 10,
-                "custom_id": "b5␟v5",
-                "style": 2,
-                "label": "b5"
-              },
-              {
-                "type": 2,
-                "id": 11,
-                "custom_id": "b6␟v6",
-                "style": 2,
-                "label": "b6"
-              },
-              {
-                "type": 2,
-                "id": 12,
-                "custom_id": "b7␟v7",
-                "style": 2,
-                "label": "b7"
-              },
-              {
-                "type": 2,
-                "id": 13,
-                "custom_id": "b8␟v8",
-                "style": 2,
-                "label": "b8"
-              },
-              {
-                "type": 2,
-                "id": 14,
-                "custom_id": "b9␟v9",
-                "style": 2,
-                "label": "b9"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 15,
-            "components": [
-              {
-                "type": 3,
-                "id": 16,
-                "custom_id": "s2",
-                "min_values": 1,
-                "max_values": 1,
-                "options": [
-                  {
-                    "label": "o0",
-                    "value": "o0"
-                  },
-                  {
-                    "label": "o1",
-                    "value": "o1"
-                  }
-                ]
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "id": 17,
-            "components": [
-              {
-                "type": 2,
-                "id": 18,
-                "custom_id": "b10␟v10",
-                "style": 2,
-                "label": "b10"
-              },
-              {
-                "type": 2,
-                "id": 19,
-                "custom_id": "b11␟v11",
-                "style": 2,
-                "label": "b11"
-              },
-              {
-                "type": 2,
-                "id": 20,
-                "custom_id": "b12␟v12",
-                "style": 2,
-                "label": "b12"
-              },
-              {
-                "type": 2,
-                "id": 21,
-                "custom_id": "b13␟v13",
-                "style": 2,
-                "label": "b13"
-              },
-              {
-                "type": 2,
-                "id": 22,
-                "custom_id": "b14␟v14",
-                "style": 2,
-                "label": "b14"
-              }
-            ]
-          }
-        ],
-        "id": "1570720114754723871",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "custom-id-100-ascii-with-join",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: custom-id-100-ascii-with-join",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "x",
-                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟b"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "effect-chat probe: custom-id-100-ascii-with-join",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T08:40:58.462000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [
-          {
-            "type": 1,
-            "id": 1,
-            "components": [
-              {
-                "type": 2,
-                "id": 2,
-                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟b",
-                "style": 2,
-                "label": "x"
-              }
-            ]
-          }
-        ],
-        "id": "1570720117002862676",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "custom-id-100-code-points-astral",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: custom-id-100-code-points-astral",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "x",
-                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "effect-chat probe: custom-id-100-code-points-astral",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T08:40:59.804000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [
-          {
-            "type": 1,
-            "id": 1,
-            "components": [
-              {
-                "type": 2,
-                "id": 2,
-                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa␟😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
-                "style": 2,
-                "label": "x"
-              }
-            ]
-          }
-        ],
-        "id": "1570720122631356538",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "1564742987727118426",
-          "username": "Janitor",
-          "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-          "discriminator": "5426",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "six-rows",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: six-rows",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b0",
-                "custom_id": "b0␟v0"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b1",
-                "custom_id": "b1␟v1"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b2",
-                "custom_id": "b2␟v2"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b3",
-                "custom_id": "b3␟v3"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b4",
-                "custom_id": "b4␟v4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b5",
-                "custom_id": "b5␟v5"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "components": {
-            "_errors": [
-              {
-                "code": "BASE_TYPE_MAX_LENGTH",
-                "message": "Must be 5 or fewer in length."
-              }
-            ]
-          }
-        }
-      }
-    },
-    {
-      "step": "six-buttons-in-a-row",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: six-buttons-in-a-row",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b0",
-                "custom_id": "b0␟v0"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b1",
-                "custom_id": "b1␟v1"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b2",
-                "custom_id": "b2␟v2"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b3",
-                "custom_id": "b3␟v3"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b4",
-                "custom_id": "b4␟v4"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b5",
-                "custom_id": "b5␟v5"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "components": {
-            "0": {
-              "components": {
-                "_errors": [
-                  {
-                    "code": "BASE_TYPE_BAD_LENGTH",
-                    "message": "Must be between 1 and 5 in length."
-                  }
-                ]
-              }
-            }
-          }
-        }
-      }
-    },
-    {
-      "step": "select-and-button-in-a-row",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: select-and-button-in-a-row",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 3,
-                "custom_id": "s",
-                "options": [
-                  {
-                    "label": "o0",
-                    "value": "o0"
-                  },
-                  {
-                    "label": "o1",
-                    "value": "o1"
-                  }
-                ],
-                "min_values": 1,
-                "max_values": 1
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b0",
-                "custom_id": "b0␟v0"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "components": {
-            "0": {
-              "components": {
-                "1": {
-                  "_errors": [
-                    {
-                      "code": "COMPONENT_LAYOUT_WIDTH_EXCEEDED",
-                      "message": "The specified component exceeds the maximum width"
-                    }
-                  ]
-                }
-              }
-            }
-          }
-        }
-      }
-    },
-    {
-      "step": "custom-id-101-ascii",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: custom-id-101-ascii",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "x",
-                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "components": {
-            "0": {
-              "components": {
-                "0": {
-                  "custom_id": {
-                    "_errors": [
-                      {
-                        "code": "BASE_TYPE_BAD_LENGTH",
-                        "message": "Must be between 1 and 100 in length."
-                      }
-                    ]
-                  }
-                }
-              }
-            }
-          }
-        }
-      }
-    },
-    {
-      "step": "custom-id-101-code-points-astral",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: custom-id-101-code-points-astral",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "x",
-                "custom_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "components": {
-            "0": {
-              "components": {
-                "0": {
-                  "custom_id": {
-                    "_errors": [
-                      {
-                        "code": "BASE_TYPE_BAD_LENGTH",
-                        "message": "Must be between 1 and 100 in length."
-                      }
-                    ]
-                  }
-                }
-              }
-            }
-          }
-        }
-      }
-    },
-    {
-      "step": "twenty-six-buttons",
-      "method": "POST",
-      "path": "/channels/1570605581192929301/messages",
-      "request": {
-        "content": "effect-chat probe: twenty-six-buttons",
-        "allowed_mentions": {
-          "parse": []
-        },
-        "components": [
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b0",
-                "custom_id": "b0␟v0"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b1",
-                "custom_id": "b1␟v1"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b2",
-                "custom_id": "b2␟v2"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b3",
-                "custom_id": "b3␟v3"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b4",
-                "custom_id": "b4␟v4"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b5",
-                "custom_id": "b5␟v5"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b6",
-                "custom_id": "b6␟v6"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b7",
-                "custom_id": "b7␟v7"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b8",
-                "custom_id": "b8␟v8"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b9",
-                "custom_id": "b9␟v9"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b10",
-                "custom_id": "b10␟v10"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b11",
-                "custom_id": "b11␟v11"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b12",
-                "custom_id": "b12␟v12"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b13",
-                "custom_id": "b13␟v13"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b14",
-                "custom_id": "b14␟v14"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b15",
-                "custom_id": "b15␟v15"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b16",
-                "custom_id": "b16␟v16"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b17",
-                "custom_id": "b17␟v17"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b18",
-                "custom_id": "b18␟v18"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b19",
-                "custom_id": "b19␟v19"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b20",
-                "custom_id": "b20␟v20"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b21",
-                "custom_id": "b21␟v21"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b22",
-                "custom_id": "b22␟v22"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b23",
-                "custom_id": "b23␟v23"
-              },
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b24",
-                "custom_id": "b24␟v24"
-              }
-            ]
-          },
-          {
-            "type": 1,
-            "components": [
-              {
-                "type": 2,
-                "style": 2,
-                "label": "b25",
-                "custom_id": "b25␟v25"
-              }
-            ]
-          }
-        ]
-      },
-      "status": 400,
-      "response": {
-        "message": "Invalid Form Body",
-        "code": 50035,
-        "errors": {
-          "components": {
-            "_errors": [
-              {
-                "code": "BASE_TYPE_MAX_LENGTH",
-                "message": "Must be 5 or fewer in length."
-              }
-            ]
-          }
-        }
-      }
-    },
-    {
-      "step": "callback-unknown-interaction-modal-45",
-      "method": "POST",
-      "path": "/interactions/1570720847549693952/invalid-token/callback",
-      "request": {
-        "type": 9,
-        "data": {
-          "custom_id": "m",
-          "title": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
-          "components": [
-            {
-              "type": 18,
-              "label": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
-              "component": {
-                "type": 4,
-                "custom_id": "a",
-                "style": 1
-              }
-            }
-          ]
-        }
-      },
-      "status": 404,
-      "response": {
-        "message": "Unknown interaction",
-        "code": 10062
-      }
-    },
-    {
-      "step": "callback-unknown-interaction-modal-title-46",
-      "method": "POST",
-      "path": "/interactions/1570720847549693952/invalid-token/callback",
-      "request": {
-        "type": 9,
-        "data": {
-          "custom_id": "m",
-          "title": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
-          "components": [
-            {
-              "type": 18,
-              "label": "y",
-              "component": {
-                "type": 4,
-                "custom_id": "a",
-                "style": 1
-              }
-            }
-          ]
-        }
-      },
-      "status": 404,
-      "response": {
-        "message": "Unknown interaction",
-        "code": 10062
-      }
-    },
-    {
-      "step": "callback-unknown-interaction-ack",
-      "method": "POST",
-      "path": "/interactions/1570720847549693952/invalid-token/callback",
-      "request": {
-        "type": 6
-      },
-      "status": 404,
-      "response": {
-        "message": "Unknown interaction",
-        "code": 10062
-      }
-    }
-  ]
-}
diff --git a/packages/chat/discord/test/fixtures/recorded/human.json b/packages/chat/discord/test/fixtures/recorded/human.json
deleted file mode 100644
index 7469223071a..00000000000
--- a/packages/chat/discord/test/fixtures/recorded/human.json
+++ /dev/null
@@ -1,168 +0,0 @@
-{
-  "case": "Item 11: a message Tim Smart typed in #test mentioning the bot, and a DM he sent the bot, each with its channel. Read back through REST because the gateway recorder had stopped before he sent them, so these are REST message objects: no guild_id, member or channel_type, which only gateway deliveries carry",
-  "provenance": {
-    "kind": "recorded",
-    "source": "Discord REST v10 with the Janitor bot token, from a local script; not gateway dispatches",
-    "where": "guild 840178841540362250 (Tim's test guild), #test 1570605581192929301, and the DM channel between Tim (449108784879763458) and the bot",
-    "author": "Tim Smart (449108784879763458), typing in the Discord client",
-    "sentAt": "2026-11-13T01:53Z",
-    "recordedAt": "2026-11-13T01:54Z, during EFF-3695",
-    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed (none here)"
-  },
-  "calls": [
-    {
-      "step": "human-mention-get-message",
-      "method": "GET",
-      "path": "/channels/1570605581192929301/messages/1570617458174337055",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "<@1564742987727118426> hello",
-        "mentions": [
-          {
-            "id": "1564742987727118426",
-            "username": "Janitor",
-            "avatar": "07aaab1f8e37dd6b088b6f21d1332701",
-            "discriminator": "5426",
-            "public_flags": 0,
-            "flags": 0,
-            "bot": true,
-            "banner": null,
-            "accent_color": null,
-            "global_name": null,
-            "avatar_decoration_data": null,
-            "collectibles": null,
-            "display_name_styles": null,
-            "banner_color": null,
-            "clan": null,
-            "primary_guild": null
-          }
-        ],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:53:02.690000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570617458174337055",
-        "channel_id": "1570605581192929301",
-        "author": {
-          "id": "449108784879763458",
-          "username": "timsmart",
-          "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-          "discriminator": "0",
-          "public_flags": 0,
-          "flags": 0,
-          "banner": null,
-          "accent_color": null,
-          "global_name": "Tim Smart",
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "human-mention-get-channel",
-      "method": "GET",
-      "path": "/channels/1570605581192929301",
-      "request": null,
-      "status": 200,
-      "response": {
-        "id": "1570605581192929301",
-        "type": 0,
-        "last_message_id": "1570617458174337055",
-        "flags": 0,
-        "guild_id": "840178841540362250",
-        "name": "test",
-        "parent_id": "840178841540362251",
-        "rate_limit_per_user": 0,
-        "topic": null,
-        "position": 6,
-        "permission_overwrites": [],
-        "nsfw": false
-      }
-    },
-    {
-      "step": "human-dm-get-message",
-      "method": "GET",
-      "path": "/channels/1570608637783572490/messages/1570617528227598377",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "hello DM",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2026-11-13T01:53:19.392000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1570617528227598377",
-        "channel_id": "1570608637783572490",
-        "author": {
-          "id": "449108784879763458",
-          "username": "timsmart",
-          "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-          "discriminator": "0",
-          "public_flags": 0,
-          "flags": 0,
-          "banner": null,
-          "accent_color": null,
-          "global_name": "Tim Smart",
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "human-dm-get-channel",
-      "method": "GET",
-      "path": "/channels/1570608637783572490",
-      "request": null,
-      "status": 200,
-      "response": {
-        "id": "1570608637783572490",
-        "type": 1,
-        "last_message_id": "1570617530232610907",
-        "flags": 0,
-        "recipients": [
-          {
-            "id": "449108784879763458",
-            "username": "timsmart",
-            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-            "discriminator": "0",
-            "public_flags": 0,
-            "flags": 0,
-            "banner": null,
-            "accent_color": null,
-            "global_name": "Tim Smart",
-            "avatar_decoration_data": null,
-            "collectibles": null,
-            "display_name_styles": null,
-            "banner_color": null,
-            "clan": null,
-            "primary_guild": null
-          }
-        ]
-      }
-    }
-  ]
-}
diff --git a/packages/chat/discord/test/fixtures/recorded/other-bots.json b/packages/chat/discord/test/fixtures/recorded/other-bots.json
deleted file mode 100644
index 44a413c7c49..00000000000
--- a/packages/chat/discord/test/fixtures/recorded/other-bots.json
+++ /dev/null
@@ -1,445 +0,0 @@
-{
-  "case": "Messages by other bots in the guild's #general, read through REST: slash command replies (type 20) from Tim's Test Bot, Polly and Effect Bot, a plain message and a reply (type 19)",
-  "provenance": {
-    "kind": "recorded",
-    "source": "Discord REST v10 with the Janitor bot token, from a local script",
-    "where": "guild 840178841540362250 (Tim's test guild); #effect-chat-scratch 1570607253965246584, #effect-chat-forum 1570607255684915302 and #test 1570605581192929301",
-    "recordedAt": "2026-11-13T01:28Z, during EFF-3695",
-    "body": "Each response verbatim, apart from signed CDN URLs, whose query is replaced; see scrubbed"
-  },
-  "calls": [
-    {
-      "step": "other-bot-command-reply",
-      "method": "GET",
-      "path": "/channels/840178841540362253/messages/1112338250816831548",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 20,
-        "content": "Hello",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2023-05-28T11:15:05.240000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1112338250816831548",
-        "channel_id": "840178841540362253",
-        "author": {
-          "id": "841095454762205184",
-          "username": "Tim's Test Bot",
-          "avatar": null,
-          "discriminator": "4902",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false,
-        "application_id": "841095454762205184",
-        "interaction": {
-          "id": "1112338249915060285",
-          "type": 2,
-          "name": "hello",
-          "user": {
-            "id": "449108784879763458",
-            "username": "timsmart",
-            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-            "discriminator": "0",
-            "public_flags": 0,
-            "flags": 0,
-            "banner": null,
-            "accent_color": null,
-            "global_name": "Tim Smart",
-            "avatar_decoration_data": null,
-            "collectibles": null,
-            "display_name_styles": null,
-            "banner_color": null,
-            "clan": null,
-            "primary_guild": null
-          }
-        },
-        "webhook_id": "841095454762205184"
-      }
-    },
-    {
-      "step": "other-bot-command-reply-empty",
-      "method": "GET",
-      "path": "/channels/840178841540362253/messages/1197424261783097434",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 20,
-        "content": "",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [
-          {
-            "type": "rich",
-            "title": "a text look",
-            "description": "Multiple votes are allowed.",
-            "color": 10070709,
-            "fields": [
-              {
-                "name": "jdhfhd (0)",
-                "value": "No votes",
-                "inline": false
-              },
-              {
-                "name": "jdkfjjfjdkfkf (0)",
-                "value": "No votes",
-                "inline": false
-              },
-              {
-                "name": "i48t84h (0)",
-                "value": "No votes",
-                "inline": false
-              }
-            ],
-            "content_scan_version": 4
-          }
-        ],
-        "timestamp": "2024-01-18T06:16:31.076000+00:00",
-        "edited_timestamp": "2024-01-18T06:16:46.623000+00:00",
-        "flags": 0,
-        "components": [
-          {
-            "type": 1,
-            "id": 1,
-            "components": [
-              {
-                "type": 2,
-                "id": 2,
-                "custom_id": "vote_65a8c23e75cb3d35044293e5_0",
-                "style": 1,
-                "label": "jdhfhd"
-              },
-              {
-                "type": 2,
-                "id": 3,
-                "custom_id": "vote_65a8c23e75cb3d35044293e5_1",
-                "style": 1,
-                "label": "jdkfjjfjdkfkf"
-              },
-              {
-                "type": 2,
-                "id": 4,
-                "custom_id": "vote_65a8c23e75cb3d35044293e5_2",
-                "style": 1,
-                "label": "i48t84h"
-              }
-            ]
-          }
-        ],
-        "id": "1197424261783097434",
-        "channel_id": "840178841540362253",
-        "author": {
-          "id": "848334981734596608",
-          "username": "Polly",
-          "avatar": "99eddd75a6c236bc0751205c93b2b03d",
-          "discriminator": "7293",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false,
-        "application_id": "848334981734596608",
-        "interaction": {
-          "id": "1197424259857928223",
-          "type": 2,
-          "name": "poll",
-          "user": {
-            "id": "449108784879763458",
-            "username": "timsmart",
-            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-            "discriminator": "0",
-            "public_flags": 0,
-            "flags": 0,
-            "banner": null,
-            "accent_color": null,
-            "global_name": "Tim Smart",
-            "avatar_decoration_data": null,
-            "collectibles": null,
-            "display_name_styles": null,
-            "banner_color": null,
-            "clan": null,
-            "primary_guild": null
-          }
-        },
-        "webhook_id": "848334981734596608"
-      }
-    },
-    {
-      "step": "other-bot-command-reply-effect-bot",
-      "method": "GET",
-      "path": "/channels/840178841540362253/messages/1113758855839612981",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 20,
-        "content": "",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [
-          {
-            "type": "rich",
-            "url": "https://effect-ts.github.io/io/modules/Effect.ts.html#flatmap-1",
-            "title": "Effect.flatMap",
-            "description": "This function is a pipeable operator that maps over an Effect value, flattening the result of the mapping function into a new Effect value. Signature\n\n```typescript\nexport declare const flatMap: {\n  (f: (a: A) => Effect): (\n    self: Effect,\n  ) => Effect\n  (\n    self: Effect,\n    f: (a: A) => Effect,\n  ): Effect\n}\n\n```",
-            "color": 8924875,
-            "author": {
-              "name": "@effect/io"
-            },
-            "footer": {
-              "text": "Added in v1.0.0"
-            },
-            "content_scan_version": 4
-          }
-        ],
-        "timestamp": "2023-06-01T09:20:03.871000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1113758855839612981",
-        "channel_id": "840178841540362253",
-        "author": {
-          "id": "1101072322271641661",
-          "username": "Effect Bot",
-          "avatar": null,
-          "discriminator": "5597",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false,
-        "application_id": "1101072322271641661",
-        "interaction": {
-          "id": "1113758852408692758",
-          "type": 2,
-          "name": "docs",
-          "user": {
-            "id": "449108784879763458",
-            "username": "timsmart",
-            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-            "discriminator": "0",
-            "public_flags": 0,
-            "flags": 0,
-            "banner": null,
-            "accent_color": null,
-            "global_name": "Tim Smart",
-            "avatar_decoration_data": null,
-            "collectibles": null,
-            "display_name_styles": null,
-            "banner_color": null,
-            "clan": null,
-            "primary_guild": null
-          }
-        },
-        "webhook_id": "1101072322271641661"
-      }
-    },
-    {
-      "step": "other-bot-plain",
-      "method": "GET",
-      "path": "/channels/840178841540362253/messages/959400132728750140",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 0,
-        "content": "Pong!",
-        "mentions": [],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2022-04-01T10:33:36.435000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "959400132728750140",
-        "channel_id": "840178841540362253",
-        "author": {
-          "id": "841095454762205184",
-          "username": "Tim's Test Bot",
-          "avatar": null,
-          "discriminator": "4902",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false
-      }
-    },
-    {
-      "step": "other-bot-reply",
-      "method": "GET",
-      "path": "/channels/840178841540362253/messages/1103552217971167293",
-      "request": null,
-      "status": 200,
-      "response": {
-        "type": 19,
-        "content": "Hello!",
-        "mentions": [
-          {
-            "id": "449108784879763458",
-            "username": "timsmart",
-            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-            "discriminator": "0",
-            "public_flags": 0,
-            "flags": 0,
-            "banner": null,
-            "accent_color": null,
-            "global_name": "Tim Smart",
-            "avatar_decoration_data": null,
-            "collectibles": null,
-            "display_name_styles": null,
-            "banner_color": null,
-            "clan": null,
-            "primary_guild": null
-          }
-        ],
-        "mention_roles": [],
-        "attachments": [],
-        "embeds": [],
-        "timestamp": "2023-05-04T05:22:31.773000+00:00",
-        "edited_timestamp": null,
-        "flags": 0,
-        "components": [],
-        "id": "1103552217971167293",
-        "channel_id": "840178841540362253",
-        "author": {
-          "id": "841095454762205184",
-          "username": "Tim's Test Bot",
-          "avatar": null,
-          "discriminator": "4902",
-          "public_flags": 0,
-          "flags": 0,
-          "bot": true,
-          "banner": null,
-          "accent_color": null,
-          "global_name": null,
-          "avatar_decoration_data": null,
-          "collectibles": null,
-          "display_name_styles": null,
-          "banner_color": null,
-          "clan": null,
-          "primary_guild": null
-        },
-        "pinned": false,
-        "mention_everyone": false,
-        "tts": false,
-        "message_reference": {
-          "type": 0,
-          "channel_id": "840178841540362253",
-          "message_id": "1103552216398303272",
-          "guild_id": "840178841540362250"
-        },
-        "referenced_message": {
-          "type": 19,
-          "content": "asdf",
-          "mentions": [
-            {
-              "id": "841095454762205184",
-              "username": "Tim's Test Bot",
-              "avatar": null,
-              "discriminator": "4902",
-              "public_flags": 0,
-              "flags": 0,
-              "bot": true,
-              "banner": null,
-              "accent_color": null,
-              "global_name": null,
-              "avatar_decoration_data": null,
-              "collectibles": null,
-              "display_name_styles": null,
-              "banner_color": null,
-              "clan": null,
-              "primary_guild": null
-            }
-          ],
-          "mention_roles": [],
-          "attachments": [],
-          "embeds": [],
-          "timestamp": "2023-05-04T05:22:31.398000+00:00",
-          "edited_timestamp": null,
-          "flags": 0,
-          "components": [],
-          "id": "1103552216398303272",
-          "channel_id": "840178841540362253",
-          "author": {
-            "id": "449108784879763458",
-            "username": "timsmart",
-            "avatar": "2eded1558c297f57913f8b7e4c6b7efc",
-            "discriminator": "0",
-            "public_flags": 0,
-            "flags": 0,
-            "banner": null,
-            "accent_color": null,
-            "global_name": "Tim Smart",
-            "avatar_decoration_data": null,
-            "collectibles": null,
-            "display_name_styles": null,
-            "banner_color": null,
-            "clan": null,
-            "primary_guild": null
-          },
-          "pinned": false,
-          "mention_everyone": false,
-          "tts": false,
-          "message_reference": {
-            "type": 0,
-            "channel_id": "840178841540362253",
-            "message_id": "1103552140401725440",
-            "guild_id": "840178841540362250"
-          }
-        }
-      }
-    }
-  ]
-}
diff --git a/packages/chat/discord/test/gateway.test.ts b/packages/chat/discord/test/gateway.test.ts
index a30dac84e8e..cc74ffc9226 100644
--- a/packages/chat/discord/test/gateway.test.ts
+++ b/packages/chat/discord/test/gateway.test.ts
@@ -173,32 +173,6 @@ describe("layerDispatchHook", () => {
     }))
   })
 
-  it.effect("a host stopped in the middle of an event resumes from before it", () => {
-    const storage: Storage = new Map()
-    let started = 0
-    const handle = () =>
-      Effect.suspend(() => {
-        started++
-        return Effect.never
-      })
-    return Effect.gen(function*() {
-      yield* Effect.scoped(Effect.gen(function*() {
-        const first = yield* host(storage, handle)
-        yield* first.receive(hello)
-        yield* first.receive(ready)
-        yield* first.receive(message(2))
-        yield* until(() => started === 1)
-      }))
-      assert.strictEqual(stored(storage)?.sequence, 1)
-      yield* Effect.scoped(Effect.gen(function*() {
-        const second = yield* host(storage, handle)
-        yield* second.receive(hello)
-        yield* until(() => second.sent(6).length === 1)
-        assert.deepStrictEqual(second.sent(6), [{ token: "token", session_id: "session-1", seq: 1 }])
-      }))
-    })
-  })
-
   it.effect("a handler defect is logged and the event dropped, so the events after it still arrive", () => {
     const storage: Storage = new Map()
     let handled = 0
diff --git a/packages/chat/discord/test/interactions.test.ts b/packages/chat/discord/test/interactions.test.ts
index 415b701caff..176f37c5d53 100644
--- a/packages/chat/discord/test/interactions.test.ts
+++ b/packages/chat/discord/test/interactions.test.ts
@@ -1,18 +1,10 @@
-/**
- * Interactions: the normaliser, the callbacks `DiscordChat.interaction`
- * answers with, `commandRequests` and a command's `followUp`. The slash
- * command payloads here start from the ones recorded in EFF-3802, which
- * `commands.test.ts` runs as they are.
- */
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
 import { assert, describe, it } from "@effect/vitest"
 import * as DiscordConfig from "dfx/DiscordConfig"
 import { DiscordRESTLive } from "dfx/DiscordREST"
 import { MemoryRateLimitStoreLive } from "dfx/RateLimit"
 import * as Chat from "effect/chat/Chat"
-import type { ChatError } from "effect/chat/ChatError"
 import * as ChatInteraction from "effect/chat/ChatInteraction"
-import { checkInteraction } from "effect/chat/ChatTest"
 import * as Clock from "effect/Clock"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
@@ -23,18 +15,7 @@ import * as Layer from "effect/Layer"
 import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
 import * as TestClock from "effect/testing/TestClock"
-import {
-  answer,
-  botUserId,
-  discordLayer,
-  type Fake,
-  guild,
-  makeFake,
-  recordedCommands,
-  scratch,
-  step,
-  tim
-} from "./utils.ts"
+import { botUserId, discordLayer, type Fake, guild, makeFake, recordedCommands, scratch, tim } from "./utils.ts"
 
 const message = { id: "1570700000000000001", channel_id: scratch }
 
@@ -52,98 +33,61 @@ const click = (data: Record, extra: Record = {
   ...extra
 })
 
-const submit = (customId: string, components: ReadonlyArray) =>
-  click({ custom_id: customId, components }, { type: 5 })
+const submit = (components: ReadonlyArray) => click({ custom_id: "form", components }, { type: 5 })
 
-/** A recorded interaction moved to scratch, with its own id and token. */
-const fromRecorded = (recorded: any, data: Record) => ({
-  ...recorded,
+const slash = (name: string, options?: ReadonlyArray, data: Record = {}) => ({
+  ...recordedCommands.commands.private,
   id: "1570700000000000100",
   token: "token",
-  channel_id: scratch,
-  channel: { ...recorded.channel, id: scratch },
-  data
+  data: { id: "1570700000000000900", name, type: 1, ...(options === undefined ? {} : { options }), ...data }
 })
 
-const slash = (name: string, options?: ReadonlyArray, data: Record = {}) =>
-  fromRecorded(recordedCommands.commands.private, {
-    id: "1570700000000000900",
-    name,
-    type: 1,
-    ...(options === undefined ? {} : { options }),
-    ...data
-  })
-
-const omit = (raw: Record, key: string) => {
-  const { [key]: _, ...rest } = raw
-  return rest
-}
-
-const some = (raw: unknown) => {
-  const interaction = DiscordChat.normalizeInteraction(raw)
-  assert.isTrue(Option.isSome(interaction))
-  return Option.getOrThrow(interaction)
-}
+const some = (raw: unknown) => Option.getOrThrow(DiscordChat.normalizeInteraction(raw))
 
 describe("normalizeInteraction", () => {
-  it.effect("a button splits its custom_id into id and value at the first join", () =>
-    Effect.gen(function*() {
-      const withValue = some(click({ custom_id: "go\u241Fa\u241Fb", component_type: 2 }))
+  it("a button splits its custom_id into id and value at the first join, from a member or a direct's user", () => {
+    const { member: _, ...direct } = click({ custom_id: "go\u241Fa\u241Fb", component_type: 2 })
+    for (const raw of [click({ custom_id: "go\u241Fa\u241Fb", component_type: 2 }), { ...direct, user: { id: tim } }]) {
+      const clicked = some(raw)
       assert.deepStrictEqual(
-        withValue,
+        clicked,
         ChatInteraction.ButtonClicked.make({
           id: "go",
           value: "a\u241Fb",
           thread: DiscordChat.thread(scratch),
           messageId: message.id,
           userId: tim,
-          raw: withValue.raw
+          raw: clicked.raw
         })
       )
-      // In a direct the user is on `user`, not `member`.
-      const direct = some({ ...omit(click({ custom_id: "go", component_type: 2 }), "member"), user: { id: tim } })
-      assert.strictEqual(direct.userId, tim)
-      for (const interaction of [withValue, direct]) {
-        yield* checkInteraction(interaction, { platform: "discord" })
-      }
-    }))
+    }
+  })
 
-  it.effect("a submit reads each Label's input, leaves an empty one out and splits the metadata", () =>
-    Effect.gen(function*() {
-      const submitted = some(submit("form\u241F{\"v\":1}", [
-        { type: 10 },
-        { type: 18, component: { type: 4, custom_id: "name", value: "Tim" } },
-        { type: 18, component: { type: 4, custom_id: "note", value: "" } },
-        { type: 18, component: { type: 3, custom_id: "size", values: ["l"] } },
-        { type: 18, component: { type: 3, custom_id: "none", values: [] } },
-        // The older shape: an action row around the input.
-        { type: 1, components: [{ type: 4, custom_id: "old", value: "row" }] }
-      ]))
-      assert.strictEqual(submitted._tag, "ModalSubmitted")
-      const { id, metadata, values } = submitted as ChatInteraction.ModalSubmitted
-      assert.deepStrictEqual({ id, metadata, values }, {
-        id: "form",
-        metadata: "{\"v\":1}",
-        values: { name: "Tim", size: "l", old: "row" }
-      })
-      assert.strictEqual((submitted as ChatInteraction.ModalSubmitted).messageId, message.id)
-      yield* checkInteraction(submitted, { platform: "discord" })
-      assert.isFalse("metadata" in some(submit("form", [])))
-    }))
+  it("a submit reads each input, a Label's or an action row's, and leaves an empty one out", () => {
+    const submitted = some(submit([
+      { type: 10 },
+      { type: 18, component: { type: 4, custom_id: "name", value: "Tim" } },
+      { type: 18, component: { type: 4, custom_id: "note", value: "" } },
+      { type: 18, component: { type: 3, custom_id: "size", values: ["l"] } },
+      { type: 18, component: { type: 3, custom_id: "none", values: [] } },
+      { type: 1, components: [{ type: 4, custom_id: "old", value: "row" }] }
+    ]))
+    assert(submitted._tag === "ModalSubmitted")
+    assert.deepStrictEqual(submitted.values, { name: "Tim", size: "l", old: "row" })
+  })
 
-  it.effect("a submit keeps an input whose id is __proto__ as its own field", () =>
-    Effect.gen(function*() {
-      const submitted = some(submit("form", [
-        { type: 18, component: { type: 4, custom_id: "__proto__", value: "answered" } },
-        { type: 18, component: { type: 4, custom_id: "name", value: "Tim" } }
-      ])) as ChatInteraction.ModalSubmitted
-      assert.isTrue(Object.hasOwn(submitted.values, "__proto__"))
-      assert.strictEqual(submitted.values["__proto__"], "answered")
-      assert.deepStrictEqual(Object.keys(submitted.values), ["__proto__", "name"])
-      yield* checkInteraction(submitted, { platform: "discord" })
-    }))
+  it("a submit keeps an input whose id is __proto__ as its own field", () => {
+    const submitted = some(submit([
+      { type: 18, component: { type: 4, custom_id: "__proto__", value: "answered" } },
+      { type: 18, component: { type: 4, custom_id: "name", value: "Tim" } }
+    ]))
+    assert(submitted._tag === "ModalSubmitted")
+    assert.isTrue(Object.hasOwn(submitted.values, "__proto__"))
+    assert.deepStrictEqual(Object.entries(submitted.values), [["__proto__", "answered"], ["name", "Tim"]])
+  })
 
   it("anything not from an element the adapter built, or a command it can't express, is None", () => {
+    const { message: _, ...noMessage } = click({ custom_id: "go", component_type: 2 })
     for (
       const raw of [
         // A user command, and a slash command with an integer option.
@@ -153,7 +97,7 @@ describe("normalizeInteraction", () => {
         { ...slash("deploy", [{ type: 3, name: "version", value: "v", focused: true }]), type: 4 },
         // A user select, and a click with no message.
         click({ custom_id: "users", component_type: 5, values: [tim] }),
-        omit(click({ custom_id: "go", component_type: 2 }), "message")
+        noMessage
       ]
     ) {
       assert.isTrue(Option.isNone(DiscordChat.normalizeInteraction(raw)))
@@ -162,30 +106,16 @@ describe("normalizeInteraction", () => {
 })
 
 describe("interaction", () => {
-  const recording = (reply: {
-    readonly click?: ChatInteraction.ClickReply
-    readonly submit?: ChatInteraction.SubmitReply
-    readonly command?: (command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply
+  const handler = (options: {
     readonly delay?: Duration.Duration
-  }) => {
-    const received: Array = []
-    const refused: Array = []
-    const handler = ChatInteraction.Handler.of({
-      click: (event) =>
-        Effect.as(
-          Effect.andThen(Effect.sleep(reply.delay ?? Duration.zero), Effect.sync(() => received.push(event))),
-          reply.click ?? ChatInteraction.ack
-        ),
-      submit: (event) => Effect.as(Effect.sync(() => received.push(event)), reply.submit ?? ChatInteraction.close),
-      command: (event) =>
-        Effect.as(
-          Effect.sync(() => received.push(event)),
-          reply.command === undefined ? ChatInteraction.ack : reply.command(event)
-        ),
-      refused: (_, error) => Effect.sync(() => void refused.push(error))
+    readonly command?: ChatInteraction.CommandReply
+  }) =>
+    ChatInteraction.Handler.of({
+      click: () => Effect.as(Effect.sleep(options.delay ?? Duration.zero), ChatInteraction.ack),
+      submit: () => Effect.succeed(ChatInteraction.close),
+      command: () => Effect.succeed(options.command ?? ChatInteraction.ack),
+      refused: (_, error) => Effect.die(error)
     })
-    return { received, refused, handler }
-  }
 
   const deliver = (
     fake: Fake,
@@ -193,218 +123,106 @@ describe("interaction", () => {
     handler: ChatInteraction.Handler["Service"],
     options?: { readonly deadline?: Duration.Duration }
   ) =>
-    Effect.gen(function*() {
-      const discord = yield* DiscordChat.DiscordChat
-      yield* discord.interaction(raw, options).pipe(Effect.provideService(ChatInteraction.Handler, handler))
-    }).pipe(Effect.provide(discordLayer(fake)))
+    Effect.flatMap(DiscordChat.DiscordChat, (discord) => discord.interaction(raw, options)).pipe(
+      Effect.provideService(ChatInteraction.Handler, handler),
+      Effect.provide(discordLayer(fake))
+    )
 
   const answering = () => makeFake({ createInteractionResponse: () => Effect.succeed(null) })
   const payloads = (fake: Fake) => fake.called("createInteractionResponse").map(([, , options]) => options.payload)
 
-  it.effect("opens a modal with type 9: Labels around the inputs and a text display for a text", () =>
-    Effect.gen(function*() {
-      const fake = answering()
-      const modal = ChatInteraction.modal("form", {
-        title: "Release",
-        submitLabel: "Go",
-        fields: {
-          intro: ChatInteraction.text("Pick *one*."),
-          name: ChatInteraction.textInput({ label: "Name", placeholder: "Tim", maxLength: 20 }),
-          note: ChatInteraction.textInput({ label: "Note", multiline: true, optional: true }),
-          size: ChatInteraction.choice({
-            label: "Size",
-            options: [{ label: "S", value: "s" }, { label: "L", value: "l" }]
-          })
-        }
-      })
-      const { handler, refused } = recording({ click: modal.open() })
-      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
-      assert.deepStrictEqual(refused, [])
-      assert.deepStrictEqual(payloads(fake), [{
-        type: 9,
-        data: {
-          custom_id: "form",
-          title: "Release",
-          components: [
-            { type: 10, content: "Pick \\*one\\*\\." },
-            {
-              type: 18,
-              label: "Name",
-              component: { type: 4, custom_id: "name", style: 1, required: true, placeholder: "Tim", max_length: 20 }
-            },
-            { type: 18, label: "Note", component: { type: 4, custom_id: "note", style: 2, required: false } },
-            {
-              type: 18,
-              label: "Size",
-              component: {
-                type: 3,
-                custom_id: "size",
-                required: true,
-                min_values: 1,
-                max_values: 1,
-                options: [{ label: "S", value: "s" }, { label: "L", value: "l" }]
-              }
-            }
-          ]
-        }
-      }])
-    }))
-
-  it.effect("a modal title over 45 reaches refused as TooLarge, and the click is still answered", () =>
-    Effect.gen(function*() {
-      const fake = answering()
-      const { handler, refused } = recording({
-        click: ChatInteraction.modal("form", { title: "t".repeat(46), fields: {} }).open()
-      })
-      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
-      assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag]), [["openModal", "TooLarge"]])
-      assert.deepStrictEqual(payloads(fake), [{ type: 6 }])
-    }))
-
-  it.effect("a modal callback that comes back Unknown interaction is refused as interaction_expired", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({
-        createInteractionResponse: () => answer(step("components", "callback-unknown-interaction-modal-45"))
-      })
-      const { handler, refused } = recording({
-        click: ChatInteraction.modal("form", { title: "t", fields: {} }).open()
-      })
-      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), handler)
-      assert.deepStrictEqual(refused.map((error) => [error.op, error.reason._tag, error.reason.detail]), [
-        ["openModal", "NotFound", "interaction_expired"]
-      ])
-      // A late ack is logged, not refused.
-      const ack = recording({})
-      yield* deliver(fake, click({ custom_id: "go", component_type: 2 }), ack.handler)
-      assert.deepStrictEqual(ack.refused, [])
-    }))
-
   it.effect("sends nothing when the handler misses its deadline, 2 seconds by default", () =>
     Effect.gen(function*() {
       const fake = answering()
-      const { handler } = recording({ delay: Duration.seconds(3) })
-      const fiber = yield* Effect.forkChild(deliver(fake, click({ custom_id: "go", component_type: 2 }), handler))
+      const late = handler({ delay: Duration.seconds(3) })
+      const fiber = yield* Effect.forkChild(deliver(fake, click({ custom_id: "go", component_type: 2 }), late))
       yield* TestClock.adjust("2 seconds")
       yield* Fiber.join(fiber)
       assert.deepStrictEqual(payloads(fake), [])
       const longer = yield* Effect.forkChild(
-        deliver(fake, click({ custom_id: "go", component_type: 2 }), handler, { deadline: Duration.seconds(5) })
+        deliver(fake, click({ custom_id: "go", component_type: 2 }), late, { deadline: Duration.seconds(5) })
       )
       yield* TestClock.adjust("3 seconds")
       yield* Fiber.join(longer)
       assert.deepStrictEqual(payloads(fake), [{ type: 6 }])
     }))
 
-  it.effect("ignores an interaction it did not build, calling nothing", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({})
-      const { handler, received } = recording({})
-      yield* deliver(fake, slash("profile", undefined, { type: 2 }), handler)
-      assert.deepStrictEqual([received.length, fake.calls.length], [0, 0])
-    }))
-
-  it.effect("withPostOptions does not reach a command's answer", () =>
+  it.effect("withPostOptions does not reach a command's answer, which notifies nobody", () =>
     Effect.gen(function*() {
       const fake = answering()
-      const { handler } = recording({
-        command: () => ChatInteraction.respond({ markdown: "Hi", visibility: "public" })
-      })
-      yield* DiscordChat.withPostOptions(deliver(fake, slash("summarize"), handler), {
-        suppressEmbeds: false,
-        notify: { everyone: true }
-      })
+      yield* DiscordChat.withPostOptions(
+        deliver(
+          fake,
+          slash("summarize"),
+          handler({
+            command: ChatInteraction.respond({ markdown: "Hi", visibility: "public" })
+          })
+        ),
+        { suppressEmbeds: false, notify: { everyone: true } }
+      )
       assert.deepStrictEqual(payloads(fake), [{
         type: 4,
         data: { content: "Hi", allowed_mentions: { parse: [], replied_user: false, roles: [], users: [] }, flags: 4 }
       }])
     }))
-
-  it.effect("sends nothing for a command nobody handles", () =>
-    Effect.gen(function*() {
-      const fake = answering()
-      const { handler, received, refused } = recording({})
-      yield* deliver(fake, slash("theirs"), handler)
-      assert.strictEqual(received.length, 1)
-      assert.deepStrictEqual(refused, [])
-      assert.deepStrictEqual(payloads(fake), [])
-    }))
 })
 
-describe("commandRequests", () => {
-  it("gives a CHAT_INPUT command per definition, with one STRING option for an argument", () => {
-    const group = ChatInteraction.group(
-      ChatInteraction.command("summarize", { description: "Summarize this thread" }),
-      ChatInteraction.button("go", { label: "Go" }),
-      ChatInteraction.command("deploy", {
-        description: "Deploy a version",
-        argument: { name: "version", description: "The version", required: true }
-      }),
-      ChatInteraction.command("note", {
-        description: "Add a note",
-        argument: { name: "text", description: "The note" }
-      })
-    )
-    assert.deepStrictEqual(DiscordChat.commandRequests(group), [
-      { type: 1, name: "summarize", description: "Summarize this thread" },
-      {
-        type: 1,
-        name: "deploy",
-        description: "Deploy a version",
-        options: [{ type: 3, name: "version", description: "The version", required: true }]
-      },
-      {
-        type: 1,
-        name: "note",
-        description: "Add a note",
-        options: [{ type: 3, name: "text", description: "The note", required: false }]
-      }
-    ])
-  })
+it("commandRequests gives a CHAT_INPUT command per definition, with one STRING option for an argument", () => {
+  const group = ChatInteraction.group(
+    ChatInteraction.command("summarize", { description: "Summarize this thread" }),
+    ChatInteraction.button("go", { label: "Go" }),
+    ChatInteraction.command("note", { description: "Add a note", argument: { name: "text", description: "The note" } })
+  )
+  assert.deepStrictEqual(DiscordChat.commandRequests(group), [
+    { type: 1, name: "summarize", description: "Summarize this thread" },
+    {
+      type: 1,
+      name: "note",
+      description: "Add a note",
+      options: [{ type: 3, name: "text", description: "The note", required: false }]
+    }
+  ])
 })
 
-describe("followUp", () => {
-  const deferred = (visibility: ChatInteraction.Visibility) =>
-    ChatInteraction.defer(some(slash("summarize")) as ChatInteraction.CommandInvoked, { visibility })
-
-  it.effect("sends one HTTP request through dfx's layers on a 429 just before 15 minutes, and fails RateLimited", () =>
-    Effect.gen(function*() {
-      const issued = Number((BigInt("1570700000000000900") >> 22n) + 1420070400000n)
-      const attempts: Array<{ readonly url: string; readonly authorized: boolean; readonly at: number }> = []
-      const http = HttpClient.make((request) =>
-        Effect.map(Clock.currentTimeMillis, (at) => {
-          attempts.push({ url: request.url, authorized: "authorization" in request.headers, at: at - issued })
-          return HttpClientResponse.fromWeb(
-            request,
-            Response.json({ message: "You are being rate limited.", retry_after: 0.6, global: false }, {
-              status: 429,
-              headers: { "retry-after": "0.6" }
-            })
-          )
-        })
-      )
-      // dfx's own REST layers, which wait out a 429 and send again, over an HTTP client that counts.
-      const layer = DiscordChat.layer.pipe(
-        Layer.provideMerge(Chat.layer),
-        Layer.provide(DiscordRESTLive),
-        Layer.provide([
-          DiscordConfig.layer({ token: Redacted.make("bot-token"), rest: { baseUrl: "https://discord.test/api" } }),
-          MemoryRateLimitStoreLive,
-          Layer.succeed(HttpClient.HttpClient, http)
-        ])
-      )
-      yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) - 300)
-      const fiber = yield* Effect.forkChild(Effect.flip(
-        Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred("public"), { markdown: "Done" })).pipe(
-          Effect.provide(layer)
+it.effect("followUp sends one HTTP request through dfx's layers on a 429 just before 15 minutes, and fails RateLimited", () =>
+  Effect.gen(function*() {
+    const deferred = ChatInteraction.defer(some(slash("summarize")) as ChatInteraction.CommandInvoked, {
+      visibility: "public"
+    })
+    const issued = Number((BigInt("1570700000000000100") >> 22n) + 1420070400000n)
+    const attempts: Array<{ readonly url: string; readonly authorized: boolean; readonly at: number }> = []
+    const http = HttpClient.make((request) =>
+      Effect.map(Clock.currentTimeMillis, (at) => {
+        attempts.push({ url: request.url, authorized: "authorization" in request.headers, at: at - issued })
+        return HttpClientResponse.fromWeb(
+          request,
+          Response.json({ message: "You are being rate limited.", retry_after: 0.6, global: false }, {
+            status: 429,
+            headers: { "retry-after": "0.6" }
+          })
         )
-      ))
-      yield* TestClock.adjust(Duration.seconds(10))
-      const error = yield* Fiber.join(fiber)
-      assert.deepStrictEqual([error.op, error.reason._tag], ["followUp", "RateLimited"])
-      assert.deepStrictEqual(attempts, [{
-        url: `https://discord.test/api/webhooks/${botUserId}/token/messages/@original`,
-        authorized: false,
-        at: Duration.toMillis(Duration.minutes(15)) - 300
-      }])
-    }))
-})
+      })
+    )
+    // dfx's own REST layers, which wait out a 429 and send again, over an HTTP client that counts.
+    const layer = DiscordChat.layer.pipe(
+      Layer.provideMerge(Chat.layer),
+      Layer.provide(DiscordRESTLive),
+      Layer.provide([
+        DiscordConfig.layer({ token: Redacted.make("bot-token"), rest: { baseUrl: "https://discord.test/api" } }),
+        MemoryRateLimitStoreLive,
+        Layer.succeed(HttpClient.HttpClient, http)
+      ])
+    )
+    yield* TestClock.setTime(issued + Duration.toMillis(Duration.minutes(15)) - 300)
+    const fiber = yield* Effect.forkChild(Effect.flip(
+      Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred, { markdown: "Done" })).pipe(Effect.provide(layer))
+    ))
+    yield* TestClock.adjust(Duration.seconds(10))
+    const error = yield* Fiber.join(fiber)
+    assert.deepStrictEqual([error.op, error.reason._tag], ["followUp", "RateLimited"])
+    assert.deepStrictEqual(attempts, [{
+      url: `https://discord.test/api/webhooks/${botUserId}/token/messages/@original`,
+      authorized: false,
+      at: Duration.toMillis(Duration.minutes(15)) - 300
+    }])
+  }))
diff --git a/packages/chat/discord/test/normalize.test.ts b/packages/chat/discord/test/normalize.test.ts
index e27267fd8aa..96e4d1d56a4 100644
--- a/packages/chat/discord/test/normalize.test.ts
+++ b/packages/chat/discord/test/normalize.test.ts
@@ -1,28 +1,16 @@
 import * as DiscordChat from "@effect/chat-discord/DiscordChat"
-import { tokens } from "@effect/chat-discord/internal/mentions"
 import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
-import { dedupeKey } from "effect/chat/ChatEvent"
 import * as ChatMessage from "effect/chat/ChatMessage"
-import { checkEvent, checkMessage } from "effect/chat/ChatTest"
+import { checkEvent } from "effect/chat/ChatTest"
 import * as Effect from "effect/Effect"
 import * as Option from "effect/Option"
 import * as Result from "effect/Result"
-import {
-  botUserId,
-  checkOptions,
-  type Dispatch,
-  eventFixtures,
-  events,
-  guild,
-  role,
-  scratch,
-  step,
-  test,
-  tim,
-  webhook
-} from "./utils.ts"
+import * as fs from "node:fs"
+import { botUserId, type Dispatch, events, guild, scratch, tim } from "./utils.ts"
 
+const role = "1570607256838479964"
+const checkOptions = { platform: "discord", parseMention: DiscordChat.parseMention }
 const context = { botUserId }
 
 const normalize = (dispatch: Dispatch): ReadonlyArray => {
@@ -32,35 +20,21 @@ const normalize = (dispatch: Dispatch): ReadonlyArray => {
 }
 
 const created = (dispatch: Dispatch): ChatEvent.MessageCreated => {
-  const found = normalize(dispatch)
-  assert.strictEqual(found.length, 1)
-  const event = found[0]
-  assert(event._tag === "MessageCreated")
+  const [event, ...rest] = normalize(dispatch)
+  assert(event._tag === "MessageCreated" && rest.length === 0)
   return event
 }
 
-const byContent = (name: string, prefix: string): Dispatch => {
-  const found = events(name).filter((dispatch) => String(dispatch.d.content).startsWith(prefix))
-  assert.strictEqual(found.length, 1, prefix)
-  return found[0]
-}
-
-const mentionsOf = (event: ChatEvent.MessageCreated) =>
-  event.message.mentions.map((mention) => ({
-    kind: mention.kind,
-    id: mention.id,
-    isSelf: mention.isSelf,
-    token: event.message.text.slice(mention.start, mention.end)
-  }))
+const base = events("channel-message")[0]
 
 describe("normalize", () => {
   it.effect("every recorded dispatch passes checkEvent", () =>
     Effect.gen(function*() {
       let count = 0
-      for (const name of eventFixtures()) {
-        for (const dispatch of events(name)) {
+      for (const file of fs.readdirSync(new URL("./fixtures/events", import.meta.url))) {
+        for (const dispatch of events(file.replace(/\.json$/, ""))) {
           const result = DiscordChat.normalize(dispatch, { ...context, channelType: 0 })
-          assert(Result.isSuccess(result), name)
+          assert(Result.isSuccess(result), file)
           for (const event of result.success) {
             yield* checkEvent(event, checkOptions)
             count++
@@ -70,82 +44,33 @@ describe("normalize", () => {
       assert.isAbove(count, 35)
     }))
 
-  it("a MESSAGE_CREATE with channel_type gives a channel message", () => {
-    const event = created(events("channel-message")[0])
-    assert.strictEqual(event.kind, "channel")
-    assert.deepStrictEqual(event.thread, DiscordChat.thread(scratch))
-    assert.deepStrictEqual(event.thread, event.message.thread)
-    assert.strictEqual(event.message.text, "Fixture: a plain message in a guild text channel")
-    assert.isTrue(event.message.author.isSelf)
-    assert.isTrue(event.message.author.isBot)
-    assert.deepStrictEqual(event.raw, events("channel-message")[0].d)
-    assert.strictEqual(event.message.raw, event.raw)
-  })
-
   it("a MESSAGE_CREATE without channel_type fails MissingChannelType, then takes it from the context", () => {
     const dispatch = events("channel-message-without-channel-type")[0]
-    assert.isUndefined(dispatch.d.channel_type)
     const missing = DiscordChat.normalize(dispatch, context)
     assert(Result.isFailure(missing))
     assert.instanceOf(missing.failure, DiscordChat.MissingChannelType)
     assert.strictEqual(missing.failure.channelId, scratch)
-    for (const [channelType, kind] of [[11, "thread"], [1, "direct"]] as const) {
+    const kind = (dispatch: Dispatch, channelType: number) => {
       const result = DiscordChat.normalize(dispatch, { ...context, channelType })
-      assert(Result.isSuccess(result))
-      const event = result.success[0]
-      assert(event._tag === "MessageCreated")
-      assert.strictEqual(event.kind, kind)
+      assert(Result.isSuccess(result) && result.success[0]._tag === "MessageCreated")
+      return result.success[0].kind
     }
+    assert.deepStrictEqual([kind(dispatch, 11), kind(dispatch, 1)], ["thread", "direct"])
     // The payload's own type wins over the context.
-    const withType = DiscordChat.normalize(events("channel-message")[0], { ...context, channelType: 11 })
-    assert(Result.isSuccess(withType) && withType.success[0]._tag === "MessageCreated")
-    assert.strictEqual(withType.success[0].kind, "channel")
+    assert.strictEqual(kind(base, 11), "channel")
   })
 
   it("a message with an invalid timestamp is dropped, not thrown", () => {
-    const base = events("channel-message")[0]
     assert.deepStrictEqual(normalize({ t: base.t, d: { ...base.d, timestamp: "not a date" } }), [])
   })
 
-  it("a message in a thread is addressed to the thread", () => {
-    for (const dispatch of events("thread-messages")) {
-      const event = created(dispatch)
-      assert.strictEqual(event.kind, "thread")
-      assert.deepStrictEqual(event.thread, DiscordChat.thread(dispatch.d.channel_id))
-      assert.notStrictEqual(dispatch.d.channel_id, scratch)
-    }
-  })
-
-  it("a forum post's starter is addressed to the post, whose id it shares", () => {
-    const [starter, reply] = events("forum").map(created)
-    assert.strictEqual(starter.kind, "thread")
-    assert.strictEqual(starter.message.id, starter.thread.id)
-    assert.deepStrictEqual(reply.thread, starter.thread)
-    assert.strictEqual(DiscordChat.guildId(starter).pipe(Option.getOrThrow), guild)
-  })
-
   it("THREAD_STARTER_MESSAGE and THREAD_CREATED give no event", () => {
     const dispatches = events("thread-started")
     assert.deepStrictEqual(dispatches.map((dispatch) => dispatch.d.type).sort(), [18, 21, 21])
     for (const dispatch of dispatches) assert.deepStrictEqual(normalize(dispatch), [])
   })
 
-  it("a system message, such as a member join, gives no event", () => {
-    const base = events("channel-message")[0]
-    assert.deepStrictEqual(normalize({ t: base.t, d: { ...base.d, type: 7 } }), [])
-  })
-
-  it("a webhook message has the webhook as its author", () => {
-    const event = created(events("webhook-message")[0])
-    assert.strictEqual(event.message.author.id, webhook)
-    assert.strictEqual(event.message.author.name, "effect-chat-fixtures")
-    assert.isTrue(event.message.author.isBot)
-    assert.isFalse(event.message.author.isSelf)
-    assert.isTrue(Option.isNone(DiscordChat.member(event)))
-    assert.strictEqual(Option.getOrThrow(DiscordChat.guildId(event)), guild)
-  })
-
-  it("a person's reply is a reply, not a mention, with the ping on or off", () => {
+  it("a person's reply to the bot is a reply, not a mention, with the ping on or off", () => {
     const [pingOn, pingOff] = events("reply-ping").filter((dispatch) => dispatch.d.author.id === tim)
     // Discord lists the replied-to bot in mentions when the ping is on, with no token in content.
     assert.deepStrictEqual(pingOn.d.mentions.map((user: any) => user.id), [botUserId])
@@ -153,195 +78,63 @@ describe("normalize", () => {
     for (const dispatch of [pingOn, pingOff]) {
       const event = created(dispatch)
       assert.deepStrictEqual(event.message.mentions, [])
-      assert.deepStrictEqual(event.message.replyTo, {
-        messageId: dispatch.d.message_reference.message_id,
-        authorId: botUserId,
-        isSelf: true
-      })
       assert.isTrue(ChatMessage.repliesToSelf(event.message))
-      assert.isFalse(ChatMessage.mentionsSelf(event.message))
-      const member = Option.getOrThrow(DiscordChat.member(event))
-      assert.strictEqual(member.guildId, guild)
-      assert.deepStrictEqual(member.roles, dispatch.d.member.roles)
+      assert.deepStrictEqual(Option.getOrThrow(DiscordChat.member(event)).roles, dispatch.d.member.roles)
     }
   })
 
-  it("an attachment has an id that names its message, and no URL", () => {
-    const event = created(events("attachment")[0])
-    assert.deepStrictEqual(event.message.attachments, [{
-      id: `${event.message.id}/${events("attachment")[0].d.attachments[0].id}`,
-      name: "fixture.txt",
-      contentType: "text/plain; charset=utf-8",
-      size: 23
-    }])
-  })
-
   describe("mentions", () => {
+    const mentionsOf = (event: ChatEvent.MessageCreated) =>
+      event.message.mentions.map((mention) => ({
+        kind: mention.kind,
+        id: mention.id,
+        isSelf: mention.isSelf,
+        token: event.message.text.slice(mention.start, mention.end)
+      }))
     const cases: ReadonlyArray<
       readonly [string, ReadonlyArray<{ kind: string; id: string; isSelf: boolean; token: string }>]
     > = [
       ["Fixture: <@!", [{ kind: "user", id: botUserId, isSelf: true, token: `<@!${botUserId}>` }]],
-      [`Fixture: <@${tim}>`, [{ kind: "user", id: tim, isSelf: false, token: `<@${tim}>` }]],
-      ["Fixture: @everyone that", [{ kind: "broadcast", id: "everyone", isSelf: false, token: "@everyone" }]],
-      ["Fixture: @everyone with parse", []],
-      ["Fixture: the bot naming", []],
       ["Fixture: <@1564742987727118426> and", [
         { kind: "user", id: botUserId, isSelf: true, token: `<@${botUserId}>` },
         { kind: "role", id: role, isSelf: false, token: `<@&${role}>` },
         { kind: "channel", id: scratch, isSelf: false, token: `<#${scratch}>` }
-      ]]
+      ]],
+      ["Fixture: @everyone that", [{ kind: "broadcast", id: "everyone", isSelf: false, token: "@everyone" }]],
+      // Posted without the ping, so Discord did not resolve it.
+      ["Fixture: @everyone with parse", []]
     ]
     for (const [prefix, expected] of cases) {
-      it.effect(prefix, () =>
-        Effect.gen(function*() {
-          const event = created(byContent("mentions", prefix))
-          assert.deepStrictEqual(mentionsOf(event), expected)
-          yield* checkMessage(event.message, checkOptions)
-        }))
+      it(prefix, () => {
+        const found = events("mentions").filter((dispatch) => String(dispatch.d.content).startsWith(prefix))
+        assert.strictEqual(found.length, 1, prefix)
+        assert.deepStrictEqual(mentionsOf(created(found[0])), expected)
+      })
     }
 
-    it("tokens skips code and escapes as Discord's Markdown does", () => {
-      const ids = (text: string) => tokens(text).map((token) => token.id)
-      assert.deepStrictEqual(ids("<@1> `<@2>` ``<@3>`` ```\n<@4>\n``` <@5>"), ["1", "5"])
-      assert.deepStrictEqual(ids("\\<@1> <@2>"), ["2"])
-      assert.deepStrictEqual(ids("`unclosed <@1>"), ["1"])
-    })
-
-    it("parseMention reads one whole token", () => {
-      assert.deepStrictEqual(DiscordChat.parseMention("<@!1>"), Option.some({ kind: "user" as const, id: "1" }))
-      for (const slice of ["<@1> ", "<@x>", "<@1><@2>"]) {
-        assert.isTrue(Option.isNone(DiscordChat.parseMention(slice)), slice)
-      }
-    })
-  })
-
-  describe("reactions", () => {
-    it.effect("added and removed, in a channel and a thread", () =>
-      Effect.gen(function*() {
-        const found = events("reactions").map(normalize).map((list) => list[0])
-        assert.strictEqual(found.length, 12)
-        for (const event of found) {
-          assert(event._tag === "ReactionAdded" || event._tag === "ReactionRemoved")
-          yield* checkEvent(event, checkOptions)
-          assert.strictEqual(event.userId, botUserId)
-          assert.isUndefined(event.timestamp)
-          assert.strictEqual(Option.getOrThrow(DiscordChat.guildId(event)), guild)
-          if (event._tag === "ReactionAdded") {
-            assert.strictEqual(event.messageAuthorId, botUserId)
-            assert.isTrue(Option.isSome(DiscordChat.member(event)))
-          } else {
-            assert.isUndefined(event.messageAuthorId)
-          }
+    it("a token in code or escaped is not a mention", () => {
+      const event = created({
+        t: base.t,
+        d: {
+          ...base.d,
+          content: "<@1> `<@2>` ``<@3>`` ```\n<@4>\n``` \\<@5> <@6>",
+          mentions: ["1", "2", "3", "4", "5", "6"].map((id) => ({ id }))
         }
-        assert.deepStrictEqual(found.slice(0, 3).map((event) => event._tag === "ReactionAdded" ? event.emoji : ""), [
-          "\u{1F44D}",
-          "\u{1F44D}\u{1F3FD}",
-          "custom:effectchat"
-        ])
-        assert.notStrictEqual(dedupeKey(found[0]), dedupeKey(found[3]))
-        assert.deepStrictEqual(found[6].thread, DiscordChat.thread("1570608327602471024"))
-      }))
-  })
-})
-
-/**
- * Item 11, recorded: Tim typed both in the Discord client. The gateway recorder
- * had stopped by then, so the bodies are REST reads, which carry no
- * `guild_id`, `member` or `channel_type`. Each is wrapped as a
- * `MESSAGE_CREATE` with the channel's recorded type in the context, which
- * makes the dispatch derived.
- */
-describe("a person's messages, recorded through REST", () => {
-  const derived = (name: string): ChatEvent.MessageCreated => {
-    const raw = step("human", `human-${name}-get-message`).response
-    const channelType = step("human", `human-${name}-get-channel`).response.type
-    const result = DiscordChat.normalize({ t: "MESSAGE_CREATE", d: raw }, { ...context, channelType })
-    assert(Result.isSuccess(result) && result.success.length === 1)
-    const event = result.success[0]
-    assert(event._tag === "MessageCreated")
-    assert.strictEqual(event.message.author.id, tim)
-    assert.isFalse(event.message.author.isBot)
-    assert.isFalse(event.message.author.isSelf)
-    return event
-  }
-
-  it.effect("a typed mention of the bot in a guild channel", () =>
-    Effect.gen(function*() {
-      const event = derived("mention")
-      assert.strictEqual(event.message.text, `<@${botUserId}> hello`)
-      assert.strictEqual(event.kind, "channel")
-      assert.deepStrictEqual(event.thread, DiscordChat.thread(test))
-      assert.deepStrictEqual(event.message.mentions, [{
-        kind: "user",
-        id: botUserId,
-        start: 0,
-        end: botUserId.length + 3,
-        isSelf: true
-      }])
-      yield* checkEvent(event, checkOptions)
-    }))
-
-  it.effect("a DM to the bot", () =>
-    Effect.gen(function*() {
-      const event = derived("dm")
-      assert.strictEqual(event.message.text, "hello DM")
-      assert.strictEqual(event.kind, "direct")
-      assert.deepStrictEqual(event.message.mentions, [])
-      assert.isTrue(Option.isNone(DiscordChat.guildId(event)))
-      assert.isTrue(Option.isNone(DiscordChat.member(event)))
-      yield* checkEvent(event, checkOptions)
-    }))
-})
-
-/**
- * Synthetic: nobody has yet sent these for the recorder. Each one is a
- * recorded dispatch with the fields that differ changed by hand.
- */
-describe("synthetic", () => {
-  const person = events("reply-ping").find((dispatch) => dispatch.d.author.id === tim)!
-  const fromPerson = (d: Record): Dispatch => {
-    const { message_reference: _, referenced_message: __, ...rest } = person.d
-    return { t: "MESSAGE_CREATE", d: { ...rest, type: 0, mentions: [], ...d } }
-  }
-
-  it.effect("a forward comes through as DEFAULT with empty text", () =>
-    Effect.gen(function*() {
-      const snapshot = { message: { content: "forwarded", type: 0, timestamp: person.d.timestamp } }
-      const event = created(fromPerson({
-        content: "",
-        message_reference: { type: 1, channel_id: scratch, message_id: "1" },
-        message_snapshots: [snapshot]
-      }))
-      assert.strictEqual(event.message.text, "")
-      assert.isUndefined(event.message.replyTo)
-      assert.deepStrictEqual((event.raw as any).message_snapshots, [snapshot])
-      yield* checkEvent(event, checkOptions)
-    }))
-
-  it.effect("another bot's command reply and context menu reply are messages, and a MESSAGE_UPDATE is not delivered", () =>
-    Effect.gen(function*() {
-      const recordedReply = step("other-bots", "other-bot-command-reply").response
-      const reply = (d: Record): Dispatch => ({
-        t: "MESSAGE_CREATE",
-        d: { ...recordedReply, guild_id: guild, channel_type: 0, ...d }
       })
-      const command = created(reply({}))
-      assert.isTrue(command.message.author.isBot)
-      assert.isFalse(command.message.author.isSelf)
-      assert.strictEqual(command.message.text, recordedReply.content)
-      const contextMenu = created(reply({ type: 23 }))
-      assert.isTrue(contextMenu.message.author.isBot)
-      assert.deepStrictEqual(normalize({ t: "MESSAGE_UPDATE", d: { ...recordedReply, flags: 0 } }), [])
-      for (const event of [command, contextMenu]) yield* checkEvent(event, checkOptions)
-    }))
-
-  it("a reply to another user's message does not reply to the bot", () => {
-    const reply = created({
-      t: "MESSAGE_CREATE",
-      d: { ...step("other-bots", "other-bot-reply").response, guild_id: guild, channel_type: 0 }
+      assert.deepStrictEqual(event.message.mentions.map((mention) => mention.id), ["1", "6"])
     })
-    assert.strictEqual(reply.message.replyTo?.messageId, "1103552216398303272")
-    assert.notStrictEqual(reply.message.replyTo?.isSelf, true)
-    assert.isFalse(ChatMessage.repliesToSelf(reply.message))
+  })
+
+  it("reactions give the emoji, custom ones by name, and the message's author when added", () => {
+    const found = events("reactions").map((dispatch) => normalize(dispatch)[0])
+    assert.deepStrictEqual(
+      found.slice(0, 4).map((event) =>
+        event._tag === "ReactionAdded" ? [event.emoji, event.messageAuthorId] : [event._tag]
+      ),
+      [["\u{1F44D}", botUserId], ["\u{1F44D}\u{1F3FD}", botUserId], ["custom:effectchat", botUserId], [
+        "ReactionRemoved"
+      ]]
+    )
+    assert.strictEqual(Option.getOrThrow(DiscordChat.guildId(found[0])), guild)
   })
 })
diff --git a/packages/chat/discord/test/utils.ts b/packages/chat/discord/test/utils.ts
index c910dd2900b..721e0d295e1 100644
--- a/packages/chat/discord/test/utils.ts
+++ b/packages/chat/discord/test/utils.ts
@@ -15,11 +15,6 @@ export const botUserId = "1564742987727118426"
 export const tim = "449108784879763458"
 export const guild = "840178841540362250"
 export const scratch = "1570607253965246584"
-export const test = "1570605581192929301"
-export const role = "1570607256838479964"
-export const webhook = "1570607260156297307"
-
-export const checkOptions = { platform: "discord", parseMention: DiscordChat.parseMention }
 
 export interface Dispatch {
   readonly receivedAt?: string
@@ -31,10 +26,7 @@ export interface Dispatch {
 export const events = (name: string): ReadonlyArray =>
   JSON.parse(fs.readFileSync(new URL(`./fixtures/events/${name}.json`, import.meta.url), "utf8")).dispatches
 
-export const eventFixtures = (): ReadonlyArray =>
-  fs.readdirSync(new URL("./fixtures/events", import.meta.url)).map((file) => file.replace(/\.json$/, ""))
-
-export interface RecordedCall {
+interface RecordedCall {
   readonly step: string
   readonly method: string
   readonly path: string
@@ -83,7 +75,7 @@ export const answer = (call: RecordedCall): Effect.Effect =>
 type Handler = (...args: Array) => Effect.Effect
 
 export interface Fake {
-  readonly calls: Array<{ readonly method: string; readonly args: ReadonlyArray; readonly files?: number }>
+  readonly calls: Array<{ readonly method: string; readonly args: ReadonlyArray }>
   readonly called: (method: string) => ReadonlyArray>
   readonly service: DiscordREST["Service"]
 }
@@ -93,20 +85,13 @@ export interface Fake {
  * method with no handler dies, so a test sees any call it didn't expect.
  */
 export const makeFake = (handlers: Record): Fake => {
-  const calls: Array<{ method: string; args: ReadonlyArray; files?: number }> = []
-  let files: number | undefined
+  const calls: Array<{ method: string; args: ReadonlyArray }> = []
   const service = new Proxy({}, {
     get: (_, method: string) => {
-      if (method === "withFiles") {
-        return (list: ReadonlyArray) => (effect: Effect.Effect) =>
-          Effect.suspend(() => {
-            files = list.length
-            return Effect.ensuring(effect, Effect.sync(() => (files = undefined)))
-          })
-      }
+      if (method === "withFiles") return () => (effect: Effect.Effect) => effect
       return (...args: Array) =>
         Effect.suspend(() => {
-          calls.push({ method, args, ...(files === undefined ? {} : { files }) })
+          calls.push({ method, args })
           const handler = handlers[method]
           return handler === undefined ? Effect.die(new Error(`unexpected ${method}`)) : handler(...args)
         })
@@ -140,9 +125,10 @@ const webhookEdit = (fake: Fake, request: HttpClientRequest.HttpClientRequest, p
 
 /**
  * `DiscordChat.layer` over a fake, with `Chat` and an `HttpClient` that
- * answers `download`, and an original response's edit from the fake.
+ * answers an original response's edit from the fake, and any other request,
+ * an attachment's download, from its `download` handler.
  */
-export const discordLayer = (fake: Fake, options?: { readonly download?: Uint8Array | undefined }) =>
+export const discordLayer = (fake: Fake) =>
   DiscordChat.layer.pipe(
     Layer.provideMerge(Chat.layer),
     Layer.provide(Layer.succeed(
@@ -157,7 +143,9 @@ export const discordLayer = (fake: Fake, options?: { readonly download?: Uint8Ar
         const path = request.method === "PATCH" ? originalResponse.exec(request.url) : null
         return path !== null
           ? webhookEdit(fake, request, path)
-          : Effect.succeed(HttpClientResponse.fromWeb(request, new Response(new Uint8Array(options?.download ?? []))))
+          : (fake.service as any).download(request.url).pipe(
+            Effect.map((bytes: Uint8Array) => HttpClientResponse.fromWeb(request, new Response(bytes)))
+          )
       })
     ))
   )
diff --git a/packages/chat/slack/test/SlackChat.test.ts b/packages/chat/slack/test/SlackChat.test.ts
index 3af308410d2..f2d2b3b5cfa 100644
--- a/packages/chat/slack/test/SlackChat.test.ts
+++ b/packages/chat/slack/test/SlackChat.test.ts
@@ -1,9 +1,7 @@
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { SlackWebApi } from "@effect/chat-slack/SlackWebApi"
 import { assert, describe, it } from "@effect/vitest"
-import { fileRefused } from "effect/chat/ChatError"
-import { checkMessage, conformance } from "effect/chat/ChatTest"
-import type { Action } from "effect/chat/ChatUi"
+import { checkMessage } from "effect/chat/ChatTest"
 import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as Fiber from "effect/Fiber"
@@ -46,9 +44,7 @@ describe("post", () => {
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const result = yield* slack.post(replyThread, { markdown: "hi <@U1> `<@U1>` & >" })
-        assert.strictEqual(result.id, "1794509200.000100")
-        assert.deepStrictEqual(result.thread, replyThread)
+        yield* slack.post(replyThread, { markdown: "hi <@U1> `<@U1>` & >" })
         assert.deepStrictEqual(fake.called("chat.postMessage")[0].params, {
           channel,
           thread_ts: root,
@@ -75,24 +71,6 @@ describe("post", () => {
         assert.deepStrictEqual(JSON.parse(params.blocks), [{ type: "markdown", text: "hi <@U1> <@U2>" }])
         assert.strictEqual(params.text, "hi <@U1> <@U2>")
         assert.strictEqual(params.unfurl_links, "true")
-        assert.strictEqual(params.unfurl_media, "true")
-        assert.isUndefined(params.thread_ts)
-      })
-    )
-  })
-
-  it.effect("fails TooLarge before calling Slack", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        // 3,001 `<` are 12,004 once escaped.
-        const failure = yield* reason(slack.post(channelThread, { markdown: "<".repeat(3_001) }))
-        assert.strictEqual(failure.tag, "TooLarge")
-        assert.strictEqual(fake.calls.length, 0)
-        // 12,000 astral letters fit.
-        assert.strictEqual(slack.descriptor.measure("𝐀".repeat(12_000)), 12_000)
       })
     )
   })
@@ -124,110 +102,41 @@ describe("post", () => {
       Effect.gen(function*() {
         const slack = yield* adapter
         // 14,000 if `<` cost 4, 11,000 as Slack counts it.
-        const markdown = "😀".repeat(1_000) + "<".repeat(1_000)
-        assert.isAtMost(slack.descriptor.measure(markdown), slack.descriptor.limits.messageLength)
-        yield* slack.post(channelThread, { markdown })
+        yield* slack.post(channelThread, { markdown: "😀".repeat(1_000) + "<".repeat(1_000) })
         // 1,400 😀 are 14,000 with shortcodes: Slack refuses, nothing is posted.
         const failure = yield* reason(slack.post(channelThread, { markdown: "😀".repeat(1_400) }))
         assert.deepStrictEqual(failure, { op: "post", tag: "TooLarge", detail: "msg_blocks_too_long", retry: "denied" })
-        assert.strictEqual(fake.called("chat.postMessage").length, 2)
       })
     )
   })
-
-  it.effect("replyTo is unsupported", () =>
-    run(
-      makeFake({}),
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const failure = yield* reason(slack.post(channelThread, { markdown: "x", replyTo: { messageId: "1.2" } }))
-        assert.strictEqual(failure.tag, "Unsupported")
-        assert.isFalse(slack.descriptor.capabilities.has("replyTo"))
-      })
-    ))
 })
 
 describe("buttons and selects", () => {
-  const button = { _tag: "Button", id: "go", label: "Go ", value: "v", style: "primary" } as const
-  const link = { _tag: "LinkButton", label: "Docs", url: "https://effect.website/docs" } as const
-  const select = {
-    _tag: "Select",
-    id: "pick",
-    options: [{ label: "A", value: "a" }, { label: "B", value: "b" }],
-    selected: "b"
-  } as const
+  const button = { _tag: "Button", id: "go", label: "Go ", value: "v" } as const
 
-  it.effect("go as one actions block after the markdown, and with no markdown the labels are the text", () => {
-    const fake = makeFake({
-      "chat.postMessage": posted("1794509200.000100"),
-      "chat.update": posted("1794509200.000100")
-    })
+  it.effect("with no Markdown, the text is the escaped labels", () => {
+    const fake = makeFake({ "chat.postMessage": posted("1794509200.000100") })
     return run(
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        yield* slack.post(channelThread, { markdown: "Pick", actions: [button, link, select] })
-        yield* slack.edit(channelThread, "1794509200.000100", { markdown: "", actions: [button, link] })
-        const [post] = fake.called("chat.postMessage")
-        assert.deepStrictEqual(JSON.parse(post.params.blocks), [
-          { type: "markdown", text: "Pick" },
-          {
-            type: "actions",
-            block_id: "chat1",
-            elements: [
-              {
-                type: "button",
-                action_id: "go",
-                text: { type: "plain_text", text: "Go " },
-                value: "v",
-                style: "primary"
-              },
-              {
-                type: "button",
-                action_id: "\u241F1",
-                text: { type: "plain_text", text: "Docs" },
-                url: "https://effect.website/docs"
-              },
-              {
-                type: "static_select",
-                action_id: "pick",
-                options: [
-                  { text: { type: "plain_text", text: "A" }, value: "a" },
-                  { text: { type: "plain_text", text: "B" }, value: "b" }
-                ],
-                initial_option: { text: { type: "plain_text", text: "B" }, value: "b" }
-              }
-            ]
-          }
-        ])
-        const [edit] = fake.called("chat.update")
-        assert.deepStrictEqual(JSON.parse(edit.params.blocks).map((block: any) => block.type), ["actions"])
-        assert.strictEqual(edit.params.text, "Go <now> Docs")
+        yield* slack.post(channelThread, { markdown: "", actions: [button] })
+        assert.strictEqual(fake.called("chat.postMessage")[0].params.text, "Go <!channel>")
       })
     )
   })
 
-  it.effect("are refused before any call for an id Slack or the adapter can't take", () => {
+  it.effect("an id holding the adapter's separator is refused before any call", () => {
     const fake = makeFake({})
     return run(
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const refused = (actions: ReadonlyArray) =>
-          reason(slack.post(channelThread, { markdown: "x", actions }))
-        assert.deepStrictEqual(
-          [
-            yield* refused([{ ...button, id: "a\u241Fb" }]),
-            yield* refused([{ ...button, id: "日".repeat(256) }]),
-            yield* refused([{ ...select, id: "i".repeat(10), options: [{ label: "A", value: "v".repeat(1_991) }] }])
-          ].map((error) => [error.op, error.tag, error.detail]),
-          [
-            ["post", "InvalidRequest", "invalid_action_id"],
-            ["post", "TooLarge", "action_id_too_long"],
-            ["post", "TooLarge", "action_data_too_long"]
-          ]
+        const failure = yield* reason(
+          slack.post(channelThread, { markdown: "x", actions: [{ ...button, id: "a\u241Fb" }] })
         )
-        assert.strictEqual(fake.called("chat.postMessage").length, 0)
+        assert.deepStrictEqual([failure.tag, failure.detail], ["InvalidRequest", "invalid_action_id"])
+        assert.deepStrictEqual(fake.calls, [])
       })
     )
   })
@@ -246,8 +155,6 @@ describe("files", () => {
   }
   const file = (name: string) => ({ name, contentType: "text/plain", content: new TextEncoder().encode("hello") })
   const ts = "1794509300.000100"
-  const methods = (fake: ReturnType) =>
-    fake.calls.map((call) => call.method).filter((method) => !method.startsWith("/upload/"))
 
   it.effect("uploads, completes with no channel, posts, then attaches with the same body", () => {
     const fake = makeFake({ ...upload(["F1", "F2"]), "chat.postMessage": posted(ts) })
@@ -255,22 +162,22 @@ describe("files", () => {
       fake,
       Effect.gen(function*() {
         const slack = yield* adapter
-        const markdown = "**see** <@U1> " + "a".repeat(5_000)
-        const result = yield* slack.post(replyThread, { markdown, files: [file("a.txt"), file("b.txt")] })
-        assert.strictEqual(result.id, ts)
-        assert.deepStrictEqual(methods(fake), [
-          "files.getUploadURLExternal",
-          "files.getUploadURLExternal",
-          "files.completeUploadExternal",
-          "chat.postMessage",
-          "chat.update"
-        ])
+        yield* slack.post(replyThread, { markdown: "a".repeat(5_000), files: [file("a.txt"), file("b.txt")] })
+        assert.deepStrictEqual(
+          fake.calls.map((call) => call.method).filter((method) => !method.startsWith("/upload/")),
+          [
+            "files.getUploadURLExternal",
+            "files.getUploadURLExternal",
+            "files.completeUploadExternal",
+            "chat.postMessage",
+            "chat.update"
+          ]
+        )
         assert.deepStrictEqual(fake.called("files.completeUploadExternal")[0].params, {
           files: JSON.stringify([{ id: "F1", title: "a.txt" }, { id: "F2", title: "b.txt" }])
         })
         const post = fake.called("chat.postMessage")[0].params
-        const attach = fake.called("chat.update")[0].params
-        assert.deepStrictEqual(attach, {
+        assert.deepStrictEqual(fake.called("chat.update")[0].params, {
           channel,
           ts,
           blocks: post.blocks,
@@ -279,16 +186,6 @@ describe("files", () => {
         })
         // The text is cut to the update budget from the post on.
         assert.isAtMost(new TextEncoder().encode(post.text).length, 3_800)
-        assert.isTrue(post.text.endsWith("…"))
-        assert.strictEqual(post.thread_ts, root)
-
-        // Later writes keep the files: no file_ids, and no files.delete.
-        const edit = yield* Effect.forkChild(slack.edit(replyThread, ts, { markdown: "edited" }))
-        yield* TestClock.adjust("3 seconds")
-        yield* Fiber.join(edit)
-        yield* slack.delete(replyThread, ts)
-        assert.isUndefined(fake.called("chat.update")[1].params.file_ids)
-        assert.strictEqual(fake.called("files.delete").length, 0)
       })
     )
   })
@@ -303,39 +200,6 @@ describe("files", () => {
         const post = fake.called("chat.postMessage")[0].params
         assert.deepStrictEqual(JSON.parse(post.blocks), [{ type: "markdown", text: "\\*a\\*.txt, <@U1>.csv" }])
         assert.strictEqual(post.text, "*a*.txt, <@U1>.csv")
-        assert.strictEqual(fake.called("chat.update")[0].params.text, post.text)
-      })
-    )
-  })
-
-  it.effect("too many files fail file_refused before any call", () => {
-    const fake = makeFake({})
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const files = Array.from({ length: slack.descriptor.limits.filesPerMessage + 1 }, (_, i) => file(`${i}.txt`))
-        assert.deepStrictEqual(yield* reason(slack.post(channelThread, { markdown: "x", files })), {
-          op: "post",
-          tag: "TooLarge",
-          detail: fileRefused,
-          retry: "denied"
-        })
-        assert.deepStrictEqual(fake.calls, [])
-      })
-    )
-  })
-
-  it.effect("a failed post removes the uploads", () => {
-    const fake = makeFake({ ...upload(["F1", "F2"]), "chat.postMessage": { ok: false, error: "not_in_channel" } })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const failure = yield* reason(slack.post(channelThread, { markdown: "x", files: [file("a"), file("b")] }))
-        assert.deepStrictEqual(failure, { op: "post", tag: "Forbidden", detail: "not_in_channel", retry: "denied" })
-        assert.deepStrictEqual(fake.called("files.delete").map((call) => call.params.file), ["F1", "F2"])
-        assert.strictEqual(fake.called("chat.update").length, 0)
       })
     )
   })
@@ -362,28 +226,6 @@ describe("files", () => {
     )
   })
 
-  it.effect("a refused attach deletes the message and the files and fails file_refused", () => {
-    const fake = makeFake({
-      ...upload(["F1"]),
-      "chat.postMessage": posted(ts),
-      "chat.update": { ok: false, error: "file_not_found" }
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const error = yield* Effect.flip(slack.post(channelThread, { markdown: "x", files: [file("a")] }))
-        assert.deepStrictEqual([error.reason._tag, error.reason.detail, error.retry], [
-          "NotFound",
-          fileRefused,
-          "denied"
-        ])
-        assert.strictEqual(methods(fake).slice(-3).join(), "chat.update,chat.delete,files.delete")
-        assert.deepStrictEqual(fake.called("chat.delete")[0].params, { channel, ts })
-      })
-    )
-  })
-
   it.effect("a rollback that can't delete the message fails uncertain with SlackAttachFailed", () => {
     const fake = makeFake({
       ...upload(["F1", "F2"]),
@@ -405,53 +247,19 @@ describe("files", () => {
         assert.deepStrictEqual(cause.thread, replyThread)
         assert.strictEqual(cause.messageId, ts)
         assert.deepStrictEqual(cause.fileIds, ["F1", "F2"])
-        assert.deepStrictEqual([cause.reason._tag, cause.reason.detail], ["NotFound", "file_not_found"])
-        assert.notInclude(cause.message, ts)
-        assert.notInclude(cause.message, "F1")
         // The files are kept, so the ids it carries still mean something.
         assert.strictEqual(fake.called("files.delete").length, 0)
       })
     )
   })
-
-  it.effect("post/refusedFile passes over the stub", () => {
-    let refuse = false
-    const fake = makeFake({
-      ...upload(["F1"]),
-      "auth.test": authTest,
-      "conversations.history": { ok: true, messages: [] },
-      "files.completeUploadExternal": () =>
-        refuse ? { ok: false, error: "invalid_arguments" } : { ok: true, files: [{ id: "F1" }] }
-    })
-    const rules = conformance({
-      platform: "slack",
-      thread: channelThread,
-      userPosts: () => Effect.die("unused"),
-      parseMention: SlackChat.parseMention,
-      refuseFiles: () =>
-        Effect.sync(() => {
-          refuse = true
-        })
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        yield* rules["post/refusedFile"]
-        assert.strictEqual(fake.called("chat.postMessage").length, 0)
-      })
-    )
-  })
 })
 
 describe("errors", () => {
-  it.effect("maps Slack's codes", () => {
+  it.effect("maps Slack's answers, and never repeats a write that may have landed", () => {
     const fake = makeFake({
-      "auth.test": authTest,
       "chat.update": { ok: false, error: "invalid_auth" },
-      "conversations.replies": { ok: false, error: "thread_not_found" },
       "chat.postMessage": { status: 500 },
-      "conversations.info": { status: 429, headers: { "retry-after": "7" } },
-      "users.info": { ok: false, error: "user_not_found" }
+      "conversations.info": { status: 429, headers: { "retry-after": "7" } }
     })
     return run(
       fake,
@@ -463,13 +271,6 @@ describe("errors", () => {
           detail: "invalid_auth",
           retry: "denied"
         })
-        assert.deepStrictEqual(yield* reason(slack.fetchMessage(channelThread, "1.2")), {
-          op: "fetchMessage",
-          tag: "NotFound",
-          detail: "thread_not_found",
-          retry: "denied"
-        })
-        // A write that may have landed is never repeated.
         assert.deepStrictEqual(yield* reason(slack.post(channelThread, { markdown: "x" })), {
           op: "post",
           tag: "PlatformUnavailable",
@@ -481,18 +282,15 @@ describe("errors", () => {
         const limited = yield* Effect.flip(api.call("conversations.info", { channel }, { retry: false }))
         assert.strictEqual(limited.reason._tag, "RateLimited")
         assert.deepStrictEqual(limited.retryAfter, Duration.seconds(7))
-        // A bot_message author is a bot id, which users.info does not know.
-        assert.strictEqual((yield* reason(slack.getUser("B0WEBHOOK"))).tag, "NotFound")
       })
     )
   })
 })
 
 describe("reads", () => {
-  const mentions = fixture("markdown-mentions")
-  const replies = mentions.calls.find((call) => call.method === "conversations.replies")!.response
-
   it.effect("fetchMessage normalises what Slack stored", () => {
+    const replies = fixture("markdown-mentions").calls.find((call) => call.method === "conversations.replies")!
+      .response
     const fake = makeFake({ "auth.test": authTest, "conversations.replies": replies })
     return run(
       fake,
@@ -500,10 +298,9 @@ describe("reads", () => {
         const slack = yield* adapter
         const message = yield* slack.fetchMessage(channelThread, "1794509003.143939")
         yield* checkMessage(message, checkOptions)
-        assert.deepStrictEqual(message.thread, channelThread)
         assert.strictEqual(message.mentions.length, 2)
         // The thread's channel, with both bounds at the message, inclusive, or Slack leaves the message out.
-        const { channel: requested, latest, oldest, inclusive } = fake.called("conversations.replies")[0].params
+        const { channel: requested, inclusive, latest, oldest } = fake.called("conversations.replies")[0].params
         assert.deepStrictEqual({ channel: requested, latest, oldest, inclusive }, {
           channel,
           latest: "1794509003.143939",
@@ -514,26 +311,7 @@ describe("reads", () => {
     )
   })
 
-  it.effect("opener is None for a channel, and for a root that is not a message", () => {
-    const fake = makeFake({
-      "auth.test": authTest,
-      "conversations.replies": {
-        ok: true,
-        messages: [{ ts: root, thread_ts: root, subtype: "assistant_app_thread", user: botUserId, text: "New chat" }]
-      }
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        assert.isTrue(Option.isNone(yield* slack.opener(channelThread)))
-        assert.isTrue(Option.isNone(yield* slack.opener(replyThread)))
-        assert.strictEqual(fake.calls.filter((call) => call.method === "conversations.replies").length, 1)
-      })
-    )
-  })
-
-  it.effect("thread history in both directions, from exclusive", () => {
+  it.effect("thread history pages in both directions, from exclusive", () => {
     const message = (ts: string) => ({ ts, thread_ts: root, user: "U080YLYB277", text: ts })
     const fake = makeFake({
       "auth.test": authTest,
@@ -557,8 +335,6 @@ describe("reads", () => {
           "1794509112.000001",
           "1794509113.000001"
         ])
-        assert.deepStrictEqual(forward[0].thread, channelThread)
-        assert.deepStrictEqual(fake.called("conversations.replies")[1].params.cursor, "page2")
         const backward = yield* Stream.runCollect(
           slack.history(replyThread, { direction: "backward", from: "1794509113.000001" })
         )
@@ -579,13 +355,10 @@ describe("reads", () => {
       Effect.gen(function*() {
         const slack = yield* adapter
         const info = yield* slack.getThread(channelThread)
-        assert.strictEqual(info.kind, "channel")
-        assert.strictEqual(info.name, "chat-testing-123")
-        assert.strictEqual(info.topic, "tests")
+        assert.deepStrictEqual([info.kind, info.name, info.topic], ["channel", "chat-testing-123", "tests"])
         const thread = yield* slack.getThread(replyThread)
         assert.strictEqual(thread.kind, "thread")
         assert.deepStrictEqual(thread.parent, channelThread)
-        assert.deepStrictEqual(yield* slack.startThread(channelThread, root), replyThread)
       })
     )
   })
@@ -611,46 +384,6 @@ describe("delete", () => {
 describe("nativeStream", () => {
   const ts = "1794509111.134189"
 
-  it.effect("start, append with a held tail, stop", () => {
-    const fake = makeFake({
-      "chat.startStream": posted(ts),
-      "chat.appendStream": posted(ts),
-      "chat.stopStream": posted(ts)
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const native = slack.nativeStream!
-        const started = yield* native.start(replyThread, { markdown: "Hello ", recipient: "U080YLYB277" })
-        assert.strictEqual(started.id, ts)
-        assert.deepStrictEqual(fake.called("chat.startStream")[0].params, {
-          channel,
-          thread_ts: root,
-          recipient_user_id: "U080YLYB277",
-          recipient_team_id: team,
-          markdown_text: "Hello "
-        })
-        const notify = SlackChat.withPostOptions({ notify: { users: ["U1"] } })
-        assert.deepStrictEqual(yield* native.append(replyThread, ts, "hi <@U", undefined).pipe(notify), {
-          state: "open",
-          held: 3
-        })
-        assert.deepStrictEqual(yield* native.append(replyThread, ts, "<@U1> a < b", { flush: true }).pipe(notify), {
-          state: "open",
-          held: 0
-        })
-        assert.deepStrictEqual(
-          fake.called("chat.appendStream").map((call) => call.params.markdown_text),
-          ["hi ", "<@U1> a < b"]
-        )
-        assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: false })
-        assert.isUndefined(fake.called("chat.stopStream")[0].params.session_status)
-        assert.strictEqual(fake.called("agents.sessions.setStatus").length, 0)
-      })
-    )
-  })
-
   it.effect("is unsupported off a thread, without a recipient, or when turned off", () =>
     run(
       makeFake({}),
@@ -674,7 +407,6 @@ describe("nativeStream", () => {
         { ok: false, error: "message_not_in_streaming_state" },
         { ok: false, error: "stopped_by_user" }
       ],
-      "chat.stopStream": { ok: true, channel, ts, message: { ts, ai_context: { result_status: "stopped_by_user" } } },
       "agents.sessions.setStatus": { ok: true }
     })
     return run(
@@ -702,11 +434,6 @@ describe("nativeStream", () => {
           thread_ts: root,
           status: "suspended"
         }])
-        // A caller that stops anyway gets stopped, and the status isn't set twice.
-        const result = yield* native.stop(replyThread, ts, { end: "done" }).pipe(suspended)
-        assert.deepStrictEqual(result, { stopped: true })
-        assert.strictEqual(fake.called("chat.stopStream")[0].params.session_status, "suspended")
-        assert.strictEqual(fake.called("agents.sessions.setStatus").length, 1)
       })
     )
   })
@@ -737,46 +464,13 @@ describe("nativeStream", () => {
     )
   })
 
-  it.effect("a 429 waits the retry-after, then doubles the interval for that message", () => {
-    const fake = makeFake({
-      "chat.appendStream": [{ status: 429, headers: { "retry-after": "3" } }, posted(ts)],
-      "chat.update": posted("1794509200.000100")
-    })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const slack = yield* adapter
-        const native = slack.nativeStream!
-        const limited = yield* reason(native.append(replyThread, ts, "a", { flush: true }))
-        assert.strictEqual(limited.tag, "RateLimited")
-        const appends = () => fake.called("chat.appendStream").length
-        const second = yield* Effect.forkChild(native.append(replyThread, ts, "b", { flush: true }))
-        yield* TestClock.adjust("2999 millis")
-        assert.strictEqual(appends(), 1)
-        yield* TestClock.adjust("1 millis")
-        yield* Fiber.join(second)
-        assert.strictEqual(appends(), 2)
-        // Two seconds now, twice the one second interval.
-        const third = yield* Effect.forkChild(native.append(replyThread, ts, "c", { flush: true }))
-        yield* TestClock.adjust("1999 millis")
-        assert.strictEqual(appends(), 2)
-        yield* TestClock.adjust("1 millis")
-        yield* Fiber.join(third)
-        assert.strictEqual(appends(), 3)
-        // Another message is not slowed.
-        yield* slack.edit(replyThread, "1794509200.000100", { markdown: "x" })
-        assert.strictEqual(fake.called("chat.update").length, 1)
-      })
-    )
-  })
-
-  it.effect("the doubled interval goes to the part that continues the reply, not to another reply", () => {
+  it.effect("after a 429 the reply's next part waits, then doubles its interval, and another reply does not", () => {
     const next = "1794509201.000100"
     const other = "1794509202.000100"
     const fake = makeFake({
       "chat.appendStream": [{ status: 429, headers: { "retry-after": "3" } }, posted(other), posted(next)],
       "chat.stopStream": { ok: true, message: { ts } },
-      "chat.startStream": [posted(other), posted(next), posted("1794509203.000100")]
+      "chat.startStream": [posted(other), posted(next)]
     })
     return run(
       fake,
@@ -802,10 +496,6 @@ describe("nativeStream", () => {
         yield* TestClock.adjust("1 millis")
         yield* Fiber.join(append)
         assert.strictEqual(fake.called("chat.appendStream").length, 3)
-        // A reply that ends hands nothing on.
-        yield* native.stop(replyThread, next, { end: "done" })
-        yield* native.start(replyThread, { markdown: "d", recipient, continues: next })
-        assert.strictEqual(fake.called("chat.startStream").length, 3)
       })
     )
   })
@@ -856,16 +546,6 @@ describe("nativeStream", () => {
   describe("the cleanup edit", () => {
     const z = "\u200B"
     const recipient = "U080YLYB277"
-    /** Runs `effect` in a span and gives what it set as `slack.stream.cleanup`. */
-    const cleanupOf = Effect.fnUntraced(function*(effect: Effect.Effect) {
-      yield* effect
-      return (yield* Effect.currentSpan).attributes.get("slack.stream.cleanup")
-    }, Effect.withSpan("test"))
-    const updates = (fake: ReturnType) =>
-      fake.called("chat.update").map((call): Record => ({
-        ...call.params,
-        blocks: JSON.parse(call.params.blocks)
-      }))
 
     it.effect("rewrites a stream whose appends differ from the block, once, after the stop, with no actions", () => {
       const fake = makeFake({ "chat.startStream": posted(ts), "chat.appendStream": posted(ts) })
@@ -875,60 +555,22 @@ describe("nativeStream", () => {
           const native = (yield* adapter).nativeStream!
           yield* native.start(replyThread, { markdown: "Hi <@U2> ", recipient })
           yield* native.append(replyThread, ts, "and `<@U3>` a < b", { flush: true })
-          assert.deepStrictEqual(
-            fake.calls.map((call) => call.method).filter((method) => method !== "auth.test"),
-            ["chat.startStream", "chat.appendStream"]
-          )
           assert.strictEqual(fake.called("chat.startStream")[0].params.markdown_text, `Hi <${z}@U2> `)
           assert.strictEqual(fake.called("chat.appendStream")[0].params.markdown_text, `and \`<${z}@U3>\` a < b`)
-          const cleanup = yield* cleanupOf(native.stop(replyThread, ts, { end: "done" }))
-          assert.strictEqual(cleanup, "edited")
+          yield* native.stop(replyThread, ts, { end: "done" })
           assert.deepStrictEqual(fake.calls.map((call) => call.method).slice(-2), ["chat.stopStream", "chat.update"])
-          assert.deepStrictEqual(updates(fake), [{
-            channel,
-            ts,
-            blocks: [{ type: "markdown", text: "Hi <@U2> and `<@U3>` a < b" }],
-            text: "Hi <@U2> and `<@U3>` a < b"
-          }])
-        })
-      )
-    })
-
-    it.effect("is not sent when the appends match the block", () => {
-      const fake = makeFake({ "chat.startStream": posted(ts) })
-      return run(
-        fake,
-        Effect.gen(function*() {
-          const native = (yield* adapter).nativeStream!
-          yield* native.start(replyThread, { markdown: "a < b `` < <@U1>", recipient }).pipe(
-            SlackChat.withPostOptions({ notify: { users: ["U1"] } })
-          )
-          const cleanup = yield* cleanupOf(
-            native.stop(replyThread, ts, { end: "done" }).pipe(SlackChat.withPostOptions({ notify: { users: ["U1"] } }))
-          )
-          assert.isUndefined(cleanup)
-          assert.strictEqual(fake.called("chat.update").length, 0)
-        })
-      )
-    })
-
-    it.effect("is skipped when the edit fails, and the stop still succeeds", () => {
-      const fake = makeFake({
-        "chat.startStream": posted(ts),
-        "chat.update": { ok: false, error: "cant_update_message" }
-      })
-      return run(
-        fake,
-        Effect.gen(function*() {
-          const native = (yield* adapter).nativeStream!
-          yield* native.start(replyThread, { markdown: "<@U2>", recipient })
-          let result: { readonly stopped: boolean } | undefined
-          const cleanup = yield* cleanupOf(
-            Effect.map(native.stop(replyThread, ts, { end: "done" }), (stopped) => (result = stopped))
+          assert.deepStrictEqual(
+            fake.called("chat.update").map((call): Record => ({
+              ...call.params,
+              blocks: JSON.parse(call.params.blocks)
+            })),
+            [{
+              channel,
+              ts,
+              blocks: [{ type: "markdown", text: "Hi <@U2> and `<@U3>` a < b" }],
+              text: "Hi <@U2> and `<@U3>` a < b"
+            }]
           )
-          assert.strictEqual(cleanup, "failed")
-          assert.deepStrictEqual(result, { stopped: false })
-          assert.strictEqual(fake.called("chat.update").length, 1)
         })
       )
     })
@@ -953,13 +595,8 @@ describe("nativeStream", () => {
           assert.strictEqual(fake.called("chat.update").length, 1)
           yield* Fiber.interrupt(first)
           // Slack answers this one as not streaming, so the user's stop is known from the first.
-          let result: { readonly stopped: boolean } | undefined
-          const cleanup = yield* cleanupOf(
-            Effect.map(native.stop(replyThread, ts, { end: "done" }), (stopped) => (result = stopped))
-          )
-          assert.strictEqual(cleanup, "edited")
+          assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: true })
           assert.strictEqual(fake.called("chat.update").length, 2)
-          assert.deepStrictEqual(result, { stopped: true })
           assert.strictEqual(fake.called("agents.sessions.setStatus").length, 1)
         })
       )
@@ -976,9 +613,10 @@ describe("nativeStream", () => {
         Effect.gen(function*() {
           const native = (yield* adapter).nativeStream!
           yield* native.start(replyThread, { markdown: "a <@U2>", recipient })
-          const appended = yield* cleanupOf(native.append(replyThread, ts, " b", { flush: true }))
-          assert.strictEqual(appended, "edited")
-          assert.deepStrictEqual(updates(fake)[0].blocks, [{ type: "markdown", text: "a <@U2>" }])
+          yield* native.append(replyThread, ts, " b", { flush: true })
+          assert.deepStrictEqual(fake.called("chat.update").map((call) => JSON.parse(call.params.blocks)), [
+            [{ type: "markdown", text: "a <@U2>" }]
+          ])
           assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: true })
           assert.strictEqual(fake.called("chat.update").length, 1)
         })
@@ -1050,17 +688,6 @@ describe("nativeStream", () => {
       })
     )
   })
-
-  it.effect("stop on a closed stream succeeds", () => {
-    const fake = makeFake({ "chat.stopStream": { ok: false, error: "message_not_in_streaming_state" } })
-    return run(
-      fake,
-      Effect.gen(function*() {
-        const native = (yield* adapter).nativeStream!
-        assert.deepStrictEqual(yield* native.stop(replyThread, ts, { end: "done" }), { stopped: false })
-      })
-    )
-  })
 })
 
 describe("SlackChat", () => {
@@ -1084,14 +711,8 @@ describe("SlackChat", () => {
       Effect.gen(function*() {
         const slack = yield* SlackChat.SlackChat
         assert.strictEqual(yield* slack.botUserId, botUserId)
-        assert.strictEqual(yield* slack.botUserId, botUserId)
-        assert.strictEqual(fake.called("auth.test").length, 1)
         const user = yield* slack.user("U0EXT")
         assert.include(user, { id: "U0EXT", teamId: "T0OTHER", name: "Ext", isRestricted: true, isStranger: true })
-        // The core op reads the same record, with the team on raw.
-        const core = yield* (yield* adapter).getUser("U0EXT")
-        assert.deepStrictEqual(core.raw, user.raw)
-        assert.include(core.raw, { team_id: "T0OTHER" })
       })
     )
   })
@@ -1102,11 +723,4 @@ describe("SlackChat", () => {
     assert.deepStrictEqual(SlackChat.emojiToName("❤"), Option.some("heart"))
     assert.isTrue(Option.isNone(SlackChat.emojiFromName("party-parrot")))
   })
-
-  it("thread and parts", () => {
-    assert.deepStrictEqual(SlackChat.parts(replyThread), Option.some({ team, channel, threadTs: root }))
-    assert.deepStrictEqual(SlackChat.parts(channelThread), Option.some({ team, channel }))
-    assert.isTrue(Option.isNone(SlackChat.parts({ platform: "discord", id: "1/2" })))
-    assert.isTrue(Option.isNone(SlackChat.parts({ platform: "slack", id: "T1" })))
-  })
 })
diff --git a/packages/chat/slack/test/actions.test.ts b/packages/chat/slack/test/actions.test.ts
index 4fdfdbe92f8..05e79bb89cf 100644
--- a/packages/chat/slack/test/actions.test.ts
+++ b/packages/chat/slack/test/actions.test.ts
@@ -1,7 +1,7 @@
 /**
- * `actionsCost` against the 38 rows measured in EFF-3738: each row is the
- * `actions` block's elements as posted, and what the 13,200 cap charged for
- * it, found by bisecting the text beside it.
+ * `actionsCost` against rows measured in EFF-3738, one per charge it makes:
+ * each row is the `actions` block's elements as posted, and what the 13,200
+ * cap charged for it, found by bisecting the text beside it.
  */
 import { cost, type Element, option } from "@effect/chat-slack/internal/actions"
 import { assert, describe, it } from "@effect/vitest"
@@ -41,47 +41,22 @@ const one = (label: string) => opts(1, () => label, () => "a")
 const rows: ReadonlyArray, number, boolean]> = [
   ["V1", [S({ options: one("A"), ph: null })], 173, true],
   ["V2", [S({ options: one("A") })], 240, true],
-  ["V3", [S({ options: one("A"), ph: "x".repeat(75) })], 307, true],
-  ["V4", [S({ options: opts(2, () => "A", () => "a") })], 307, true],
-  ["V5", [S({ options: opts(3, () => "A", () => "a") })], 374, true],
   ["V6", [S({ options: opts(10, () => "A", () => "a") })], 843, true],
-  ["V7", [S({ options: one("L".repeat(75)) })], 315, true],
-  ["V8", [S({ options: opts(1, () => "A", () => "v".repeat(150)) })], 389, true],
-  ["V9", [S({ options: opts(3) })], 398, true],
   ["V10", [S({ options: opts(3), initial: option("Option 2", "o2") })], 490, true],
-  ["V11", [S({ options: one("\u{1F600}") })], 251, false],
-  ["V12", [S({ options: one("A"), ph: "\u{1F600}" })], 242, false],
-  ["V13", [S({ options: one("A"), id: "i".repeat(200) })], 436, true],
-  ["V14", [S({ options: opts(3) }), B()], 518, true],
   ["V15", [B(), S({ options: opts(3) }), B({ id: "b2" })], 628, true],
-  ["V16", [S({ options: opts(3) }), S({ options: opts(3), id: "sel2" })], 746, true],
-  ["V17", [S({ options: opts(30) })], 2465, true],
   ["V18", [S({ options: one("é".repeat(20)) })], 359, false],
-  ["V19", [S({ options: one("A\"<&>\\/") })], 249, true],
   ["V20", [B()], 170, true],
   ["V21", [B({ url: "https://effect.website/docs", value: null })], 197, true],
   ["V22", [B({ url: "https://effect.website/docs", value: "v" })], 209, true],
-  ["V23", [B({ url: "https://effect.website/" + "p".repeat(500) + "?a=1&b=2", value: null })], 701, true],
-  ["V24", [B({ url: "https://effect.website/docs/a/b/c", value: null })], 206, true],
   ["W1", [B({ label: "é".repeat(20) })], 279, false],
   ["W2", [B({ label: "\u{1F644}" })], 183, false],
-  ["W3", [S({ options: one("\u{1F644}") })], 251, false],
   ["W4", [S({ options: one("A"), ph: "\u{1F644}" })], 256, false],
-  ["W5", [S({ options: opts(1, () => "A", () => "é".repeat(10) + "/".repeat(10)) })], 319, false],
-  ["W6", [B({ id: "a/b/c/d/e", value: "é".repeat(20) + "/".repeat(20) })], 330, false],
-  ["W7", [S({ options: one("<&>".repeat(10)) })], 269, true],
   ["W8", [B({ label: "<&>".repeat(10) })], 289, true],
-  ["W9", [S({ options: one(":grinning: :not_an_emoji:") })], 265, true],
-  ["W10", [B({ label: ":grinning: :not_an_emoji:" })], 184, true],
-  ["W11", [S({ options: one("\u{1F44D}\u{1F3FD} \u{1F1E6}\u{1F1FA} \u2764\uFE0F") })], 301, false],
-  ["W12", [B({ label: "\u{1F44D}\u{1F3FD} \u{1F1E6}\u{1F1FA} \u2764\uFE0F" })], 194, false],
-  ["W13", [S({ options: one("\u{1D49C}".repeat(5)) })], 299, false],
-  ["W14", [B({ label: "\u{1D49C}".repeat(5) })], 219, false]
+  ["W13", [S({ options: one("\u{1D49C}".repeat(5)) })], 299, false]
 ]
 
 describe("actionsCost", () => {
-  it("is never below what Slack charged, and at most 5 over on ASCII, for the 38 measured rows", () => {
-    assert.strictEqual(rows.length, 38)
+  it("is never below what Slack charged, and at most 5 over on ASCII, for the measured rows", () => {
     for (const [name, elements, charged, ascii] of rows) {
       const charge = cost(elements)
       assert.isAtLeast(charge, charged, name)
diff --git a/packages/chat/slack/test/commands.test.ts b/packages/chat/slack/test/commands.test.ts
index 699a2c3edf9..032fcfaf66d 100644
--- a/packages/chat/slack/test/commands.test.ts
+++ b/packages/chat/slack/test/commands.test.ts
@@ -16,17 +16,12 @@ import { authTest, fixture, makeFake, slackLayer, team } from "./utils.ts"
 
 const recorded = fixture("commands")
 const channel = "C0CJMJ5UMUY"
-const tim = "U080YLYB277"
 
 // The definitions the capture ran, from eff-3802-capture.ts.
-const AckButton = ChatInteraction.button("cap-ack", { label: "Ack" })
-const ModalButton = ChatInteraction.button("cap-open", { label: "Open modal", style: "primary" })
-const Modal = ChatInteraction.modal("cap-modal", {
-  title: "Capture",
-  submitLabel: "Send",
-  fields: { note: ChatInteraction.textInput({ label: "Note (type err for a field error)" }) }
-})
-const actions = [AckButton.of(), ModalButton.of()]
+const actions = [
+  ChatInteraction.button("cap-ack", { label: "Ack" }).of(),
+  ChatInteraction.button("cap-open", { label: "Open modal", style: "primary" }).of()
+]
 
 /** The capture's handler, by the command's text. */
 const reply = (command: ChatInteraction.CommandInvoked): ChatInteraction.CommandReply => {
@@ -39,8 +34,6 @@ const reply = (command: ChatInteraction.CommandInvoked): ChatInteraction.Command
       })
     case "mention":
       return ChatInteraction.respond({ markdown: "Private answer mentioning <@" + command.userId + ">" })
-    case "modal":
-      return Modal.open()
     case "defer":
       return ChatInteraction.defer(command)
     default:
@@ -52,13 +45,8 @@ const reply = (command: ChatInteraction.CommandInvoked): ChatInteraction.Command
 }
 
 const handler = Layer.succeed(ChatInteraction.Handler, {
-  click: () => Effect.succeed(ChatInteraction.ack),
-  submit: (submit) =>
-    Effect.succeed(
-      submit.values.note === "err"
-        ? ChatInteraction.errors({ note: "That is the error you asked for" })
-        : ChatInteraction.close
-    ),
+  click: () => Effect.die("unused"),
+  submit: () => Effect.die("unused"),
   command: (command) => Effect.succeed(reply(command)),
   refused: (_, error) => Effect.die(error)
 })
@@ -72,22 +60,6 @@ const interact = (fake: ReturnType, payload: unknown) =>
   )
 
 describe("recorded slash commands", () => {
-  it("normalizes each command form Slack sent", () => {
-    for (const [what, form] of Object.entries>(recorded.commands)) {
-      const event = normalize(form)
-      assert.strictEqual(event._tag, "CommandInvoked", what)
-      if (event._tag !== "CommandInvoked") return
-      assert.deepStrictEqual([event.id, event.text, event.userId, event.thread.id], [
-        "chat-capture",
-        form.text,
-        tim,
-        `${team}/${channel}`
-      ])
-      assert.isFalse("token" in (event.raw as object))
-      assert.strictEqual((event.raw as any).response_url, form.response_url)
-    }
-  })
-
   it.live("answers each command with the body Slack rendered", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest })
@@ -95,62 +67,20 @@ describe("recorded slash commands", () => {
         const answer = yield* interact(fake, recorded.commands[what])
         assert.deepStrictEqual(answer, recorded.answers[what] ?? undefined, what)
       }
-      // A mention is escaped, so a command's answer mentions nobody on Slack.
-      assert.include(recorded.answers.mention.text, "<@U080YLYB277>")
-    }))
-
-  it.live("opens a command's modal with the view Slack opened, which packs no message", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({ "auth.test": authTest, "views.open": { ok: true, view: { id: "V0CHM1EJ691" } } })
-      assert.isUndefined(yield* interact(fake, recorded.commands.modal))
-      const [call] = fake.called("views.open")
-      assert.strictEqual(call.params.trigger_id, recorded.commandModal.viewsOpen.trigger_id)
-      assert.deepStrictEqual(JSON.parse(call.params.view), recorded.commandModal.viewsOpen.view)
-    }))
-
-  it.live("gives that modal's submit no messageId, and answers it the way Slack took", () =>
-    Effect.gen(function*() {
-      const submitted = normalize(recorded.commandModal.submitErrors)
-      assert.strictEqual(submitted._tag, "ModalSubmitted")
-      if (submitted._tag !== "ModalSubmitted") return
-      assert.deepStrictEqual([submitted.id, submitted.thread.id, submitted.userId, submitted.values], [
-        "cap-modal",
-        `${team}/${channel}`,
-        tim,
-        { note: "err" }
-      ])
-      assert.isFalse("messageId" in submitted)
-      const fake = makeFake({ "auth.test": authTest })
-      assert.deepStrictEqual(
-        yield* interact(fake, recorded.commandModal.submitErrors),
-        recorded.commandModal.errorsAnswer
-      )
-      assert.isUndefined(yield* interact(fake, recorded.commandModal.submitClose))
-      assert.isNull(recorded.commandModal.closeAnswer)
     }))
 
   it("takes a click on a private answer, which has no message, from its container", () => {
-    for (const what of ["privateAnswer", "privateFollowUp"]) {
-      const payload = recorded.clicks[what]
-      assert.isFalse("message" in payload)
-      const click = normalize(payload)
-      assert.strictEqual(click._tag, "ButtonClicked", what)
-      if (click._tag !== "ButtonClicked") return
-      // The id names where the click came from. chat.update on it answered
-      // message_not_found: a private answer is not a message Chat can reach.
-      assert.deepStrictEqual([click.id, click.messageId, click.thread.id], [
-        "cap-ack",
-        payload.container.message_ts,
-        `${team}/${channel}`
-      ])
-      assert.isTrue((click.raw as any).container.is_ephemeral)
-    }
-    const publicClick = normalize(recorded.clicks.publicAnswer)
-    assert.strictEqual(
-      (publicClick as ChatInteraction.ButtonClicked).messageId,
-      recorded.clicks.publicAnswer.message.ts
-    )
-    assert.isFalse((publicClick.raw as any).container.is_ephemeral)
+    const payload = recorded.clicks.privateAnswer
+    assert.isFalse("message" in payload)
+    const click = normalize(payload)
+    assert.strictEqual(click._tag, "ButtonClicked")
+    // The id names where the click came from. chat.update on it answered
+    // message_not_found: a private answer is not a message Chat can reach.
+    assert.deepStrictEqual([click.id, (click as ChatInteraction.ButtonClicked).messageId, click.thread.id], [
+      "cap-ack",
+      payload.container.message_ts,
+      `${team}/${channel}`
+    ])
   })
 
   it.effect("follows up with the body Slack rendered, and maps a spent and an expired response_url", () =>
diff --git a/packages/chat/slack/test/conformance.test.ts b/packages/chat/slack/test/conformance.test.ts
index 77940ce337f..513d8d5b14f 100644
--- a/packages/chat/slack/test/conformance.test.ts
+++ b/packages/chat/slack/test/conformance.test.ts
@@ -1,8 +1,7 @@
 /**
- * The conformance rules for buttons, selects, modals and commands, against the adapter
- * over a stubbed Web API that keeps what was posted. Clicks and submits are
- * built from the posted blocks and the opened views and go through
- * `SlackChat.interaction`, so the answers are tested too.
+ * The conformance rules against the adapter over a stubbed Web API that keeps
+ * what was posted. Clicks, submits and commands are built from the posted
+ * blocks and the opened views and go through `SlackChat.interaction`.
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { describe, it } from "@effect/vitest"
@@ -11,23 +10,22 @@ import * as Effect from "effect/Effect"
 import { makeSlack } from "./slack.ts"
 import { channel, slackLayer, team } from "./utils.ts"
 
-const thread = SlackChat.thread({ team, channel })
-
-const portable = (name: string) =>
-  name.startsWith("actions/") ||
-  name.startsWith("modal/") ||
-  name.startsWith("edit/") && name.endsWith("Actions") ||
-  name.startsWith("descriptor/measure") && name.endsWith("Actions") ||
-  name.startsWith("command/") ||
-  name === "unsupported/buttons" ||
-  name === "unsupported/selects" ||
-  name === "unsupported/modals" ||
-  name === "unsupported/commands" ||
-  name === "unsupported/ephemeral"
+/** Rules that need a user's message, a thread's history or a stored file, which the stub does not keep: live.test.ts runs them. */
+const liveOnly = new Set([
+  "post/files",
+  "download/maxBytes",
+  "history/sameAsInbound",
+  "message/threadStable",
+  "inbound/fetchable",
+  "inbound/notSelf",
+  "nativeStream/concatenates",
+  "nativeStream/appendAfterStop",
+  "unsupported/getUser"
+])
 
 const options = {
   platform: "slack",
-  thread,
+  thread: SlackChat.thread({ team, channel }),
   userPosts: () => Effect.die("unused"),
   parseMention: SlackChat.parseMention
 }
@@ -35,13 +33,14 @@ const options = {
 describe("conformance over the stubbed Web API", () => {
   const names = Object.keys(conformance({
     ...options,
-    interactions: { click: () => Effect.void, submit: () => Effect.void, command: () => Effect.void }
-  })).filter(portable)
+    interactions: { click: () => Effect.void, submit: () => Effect.void, command: () => Effect.void },
+    refuseFiles: () => Effect.void
+  })).filter((name) => !liveOnly.has(name))
 
   for (const name of names) {
     it.effect(name, () => {
       const slack = makeSlack()
-      const rules = conformance({ ...options, interactions: slack.interactions })
+      const rules = conformance({ ...options, interactions: slack.interactions, refuseFiles: slack.refuseFiles })
       return Effect.andThen(slack.bind, rules[name]).pipe(Effect.provide(slackLayer(slack.fake)))
     })
   }
diff --git a/packages/chat/slack/test/emoji.test.ts b/packages/chat/slack/test/emoji.test.ts
index 30fd7ba9e6e..d321e9fd98a 100644
--- a/packages/chat/slack/test/emoji.test.ts
+++ b/packages/chat/slack/test/emoji.test.ts
@@ -1,143 +1,77 @@
-import { blocksCost, fromName, toName } from "@effect/chat-slack/internal/emoji"
+import { blocksCost } from "@effect/chat-slack/internal/emoji"
 import { emojiData } from "@effect/chat-slack/internal/emojiData"
+import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { assert, describe, it } from "@effect/vitest"
-
-interface Row {
-  readonly names: ReadonlyArray
-  /** Primary Slack name, with skin-tone suffixes for variations */
-  readonly name: string
-  /** How many skin tones the name carries */
-  readonly tones: number
-  readonly emoji: string
-  /** Whether the emoji is also written without U+FE0F */
-  readonly nonQualified: boolean
-}
+import * as Option from "effect/Option"
 
 const decode = (hex: string): string => String.fromCodePoint(...hex.split("-").map((point) => parseInt(point, 16)))
 
-// Read the generated table directly, so these tests do not trust emoji.ts to parse it.
-const rows: ReadonlyArray = emojiData.split("\n").flatMap((line) => {
-  const [names, unified, nonQualified, groups] = line.split("|")
-  const aliases = names.split(",")
-  const base: Row = {
-    names: aliases,
-    name: aliases[0],
-    tones: 0,
-    emoji: decode(unified),
-    nonQualified: nonQualified === "!"
-  }
+/** An emoji, and the same without U+FE0F where the table says it is also written so. */
+const written = (emoji: string, nonQualified: string | undefined) =>
+  nonQualified === "!" ? [emoji, emoji.replaceAll("\uFE0F", "")] : [emoji]
+
+// Every emoji string the generated table defines, read from the table directly
+// so the fuzz does not trust emoji.ts to parse it.
+const sequences: ReadonlyArray = emojiData.split("\n").flatMap((line) => {
+  const [, unified, nonQualified, groups] = line.split("|")
   const variations = groups === undefined ? [] : groups.split(";").flatMap((group) => {
     const [keys, template, variationNonQualified] = group.split(":")
-    return keys.split(",").map((tones): Row => {
+    return keys.split(",").flatMap((tones) => {
       let index = 0
-      return {
-        names: [],
-        name: aliases[0] + [...tones].map((tone) => "::skin-tone-" + tone).join(""),
-        tones: tones.length,
-        emoji: decode(template.replace(/\*/g, () => (0x1f3fb + Number(tones[index++]) - 2).toString(16))),
-        nonQualified: variationNonQualified === "!"
-      }
+      const emoji = decode(template.replace(/\*/g, () => (0x1f3fb + Number(tones[index++]) - 2).toString(16)))
+      return written(emoji, variationNonQualified)
     })
   })
-  return [base, ...variations]
+  return [...written(decode(unified), nonQualified), ...variations]
 })
 
-// Every emoji string the table defines, with its primary Slack name.
-const sequences: ReadonlyArray = rows.flatMap((row) =>
-  row.nonQualified ? [[row.emoji, row.name], [row.emoji.replaceAll("\uFE0F", ""), row.name]] : [[row.emoji, row.name]]
-)
-
 describe("emoji", () => {
-  describe("fromName", () => {
-    it("gives none for a name with two tones, which no recording shows, even the same tone twice", () => {
-      assert.strictEqual(fromName("handshake::skin-tone-3::skin-tone-3"), undefined)
-    })
-
-    it("gives a single tone, or the same tone twice where upstream keys only by two", () => {
-      assert.strictEqual(fromName("handshake::skin-tone-3"), "🤝🏼")
-      assert.strictEqual(fromName("people_holding_hands::skin-tone-4"), "🧑🏽‍🤝‍🧑🏽")
-      assert.strictEqual(fromName("people_holding_hands::skin-tone-1"), undefined)
-    })
-
-    it("resolves every alias and every one-tone variation in the table", () => {
-      for (const row of rows) {
-        if (row.tones > 1) continue
-        assert.strictEqual(fromName(row.name), row.emoji, row.name)
-        for (const alias of row.names) assert.strictEqual(fromName(alias), row.emoji, alias)
-      }
-    })
-
-    it("returns undefined for unknown names and tones", () => {
-      assert.strictEqual(fromName("not_an_emoji"), undefined)
-      assert.strictEqual(fromName(":+1"), undefined)
-      assert.strictEqual(fromName("grinning::skin-tone-3"), undefined)
-      assert.strictEqual(fromName("+1::skin-tone-1"), undefined)
-      assert.strictEqual(fromName("handshake::skin-tone-2::skin-tone-3::skin-tone-4"), undefined)
-      assert.strictEqual(fromName("+1::thumbsup"), undefined)
-    })
+  it("gives a single tone, or the same tone twice where upstream keys only by two", () => {
+    assert.deepStrictEqual(SlackChat.emojiFromName("handshake::skin-tone-3"), Option.some("🤝🏼"))
+    assert.deepStrictEqual(SlackChat.emojiFromName("people_holding_hands::skin-tone-4"), Option.some("🧑🏽‍🤝‍🧑🏽"))
+    assert.isTrue(Option.isNone(SlackChat.emojiFromName("people_holding_hands::skin-tone-1")))
   })
 
-  describe("toName", () => {
-    it("returns undefined for anything that is not exactly one emoji", () => {
-      assert.strictEqual(toName("a"), undefined)
-      assert.strictEqual(toName("👍👍"), undefined)
-      assert.strictEqual(toName("👍 "), undefined)
-    })
-
-    it("names every emoji in the table", () => {
-      for (const [emoji, name] of sequences) {
-        assert.strictEqual(toName(emoji), name)
-      }
-    })
-  })
-
-  describe("blocksCost", () => {
-    it("costs every emoji in the table exactly as its :short_name:", () => {
-      for (const [emoji, name] of sequences) {
-        assert.strictEqual(blocksCost(emoji), name.length + 2, name)
-      }
-    })
-
-    it("is subadditive", () => {
-      const emoji = sequences.map(([sequence]) => sequence)
-      const extras = [
-        "a",
-        " ",
-        "1",
-        "#",
-        "\u200D",
-        "\uFE0F",
-        "\u20E3",
-        "🏽",
-        "🇺",
-        "🇸",
-        "🦰",
-        "\u{E0067}",
-        "\uD83D",
-        "\uDE00"
-      ]
-      let seed = 1
-      const random = (n: number) => {
-        seed = (seed * 1103515245 + 12345) & 0x7fffffff
-        return seed % n
-      }
-      const piece = () => {
-        const kind = random(3)
-        if (kind === 0) return extras[random(extras.length)]
-        const sequence = emoji[random(emoji.length)]
-        if (kind === 1) return sequence
-        const from = random(sequence.length + 1)
-        const to = random(sequence.length + 1)
-        return sequence.slice(Math.min(from, to), Math.max(from, to))
-      }
-      for (let i = 0; i < 20_000; i++) {
-        let text = ""
-        for (let j = 1 + random(8); j > 0; j--) text += piece()
-        const cut = random(text.length + 1)
-        const a = text.slice(0, cut)
-        const b = text.slice(cut)
-        assert.isAtMost(blocksCost(text), blocksCost(a) + blocksCost(b), JSON.stringify([a, b]))
-      }
-    })
+  // Also the guard for optimised String.prototype.codePointAt, which returned
+  // wrong values around lone surrogates on Node 26.8 (V8).
+  it("blocksCost is subadditive", () => {
+    const extras = [
+      "a",
+      " ",
+      "1",
+      "#",
+      "\u200D",
+      "\uFE0F",
+      "\u20E3",
+      "🏽",
+      "🇺",
+      "🇸",
+      "🦰",
+      "\u{E0067}",
+      "\uD83D",
+      "\uDE00"
+    ]
+    let seed = 1
+    const random = (n: number) => {
+      seed = (seed * 1103515245 + 12345) & 0x7fffffff
+      return seed % n
+    }
+    const piece = () => {
+      const kind = random(3)
+      if (kind === 0) return extras[random(extras.length)]
+      const sequence = sequences[random(sequences.length)]
+      if (kind === 1) return sequence
+      const from = random(sequence.length + 1)
+      const to = random(sequence.length + 1)
+      return sequence.slice(Math.min(from, to), Math.max(from, to))
+    }
+    for (let i = 0; i < 20_000; i++) {
+      let text = ""
+      for (let j = 1 + random(8); j > 0; j--) text += piece()
+      const cut = random(text.length + 1)
+      const a = text.slice(0, cut)
+      const b = text.slice(cut)
+      assert.isAtMost(blocksCost(text), blocksCost(a) + blocksCost(b), JSON.stringify([a, b]))
+    }
   })
 })
diff --git a/packages/chat/slack/test/escape.test.ts b/packages/chat/slack/test/escape.test.ts
index 77e7a378d79..8e4f948b8ef 100644
--- a/packages/chat/slack/test/escape.test.ts
+++ b/packages/chat/slack/test/escape.test.ts
@@ -1,5 +1,4 @@
-import { escape, escapeStream } from "@effect/chat-slack/internal/escape"
-import { codePoints, measure } from "@effect/chat-slack/internal/length"
+import { escape } from "@effect/chat-slack/internal/escape"
 import { assert, describe, it } from "@effect/vitest"
 
 const sent = (text: string, notify = {}) => escape(text, notify, { flush: true }).sent
@@ -23,132 +22,4 @@ describe("escape", () => {
     assert.strictEqual(sent("<@U1|name>", { users: ["U1"] }), "<@U1|name>")
     assert.strictEqual(sent("", {}), "<!channel>")
   })
-
-  it("holds a < the next chunk could still change", () => {
-    const notify = { users: ["U1"] }
-    const first = escape("hi <@U", notify)
-    assert.strictEqual(first.sent, "hi ")
-    assert.strictEqual(first.consumed, 3)
-    const second = escape("<@U1> there", notify, { state: first.state })
-    assert.strictEqual(second.sent, "<@U1> there")
-    // With nothing allowed, a < is never undecided.
-    assert.strictEqual(escape("hi <@U", {}).sent, "hi <@U")
-    // After a backtick the line has not closed.
-    const code = escape("x `a <", {})
-    assert.strictEqual(code.sent, "x `a ")
-    assert.strictEqual(escape(" {
-    const first = escape("```\na < b\n", {})
-    assert.strictEqual(first.sent, "```\na < b\n")
-    const second = escape("c < d\n```\ne < f", {}, { state: first.state, flush: true })
-    assert.strictEqual(second.sent, "c < d\n```\ne < f")
-  })
-
-  it("releases a held < past the bound", () => {
-    const text = "`a <" + "x".repeat(400)
-    const result = escape(text, {})
-    assert.strictEqual(result.consumed, text.length)
-    assert.strictEqual(result.sent, "`a <" + "x".repeat(400))
-  })
-})
-
-describe("escapeStream", () => {
-  const z = "\u200B"
-  const streamed = (text: string, notify = {}) => escapeStream(text, notify, { flush: true }).sent
-
-  it("puts U+200B after whatever spells the < of a token shape, in prose and in code", () => {
-    assert.strictEqual(streamed("a <@U1> b"), `a <${z}@U1> b`)
-    assert.strictEqual(streamed("`<@U1>` and ```\n\n```"), `\`<${z}@U1>\` and \`\`\`\n<${z}!here>\n\`\`\``)
-    assert.strictEqual(
-      streamed("<@U1> <!channel> <@U1> <@U1> <@U1> <@U1>"),
-      [
-        `<${z}@U1>`,
-        `<${z}!channel>`,
-        `<${z}@U1>`,
-        `<${z}@U1>`,
-        `<${z}@U1>`,
-        `<${z}@U1>`
-      ].join(" ")
-    )
-    assert.strictEqual(
-      streamed("<@U1> <@U1> <@U1> <!here>"),
-      [
-        `<${z}@U1>`,
-        `<${z}@U1>`,
-        `<${z}@U1>`,
-        `<${z}!here>`
-      ].join(" ")
-    )
-    assert.strictEqual(streamed(" "), `<${z}!subteam^S1> <${z}!everyone>`)
-  })
-
-  it("leaves the rest to the block rule", () => {
-    //  "), "<!-- x --> <![CDATA[ y ]]>")
-    assert.strictEqual(streamed("a < b `c < d` <b> <"), "a < b `c < d` <b> <")
-    // Without the semicolon nothing decodes.
-    assert.strictEqual(
-      streamed("<@U1> <@U1> <@U1> <&commat U1>"),
-      "<@U1> <@U1> <@U1> <&commat U1>"
-    )
-    // Letters are not decoded.
-    assert.strictEqual(streamed(""), "<!here>")
-  })
-
-  it("sends an allowed token as it is", () => {
-    const notify = { users: ["U1"], groups: ["S1"], broadcast: true }
-    assert.strictEqual(
-      streamed("<@U1> <@U2>   `<@U1>` <@U1>", notify),
-      `<@U1> <${z}@U2>   \`<@U1>\` <@U1>`
-    )
-  })
-
-  it("holds an unclosed <, an unfinished reference and an undecided token", () => {
-    const notify = { users: ["U1"] }
-    const cases: ReadonlyArray = [
-      ["a <", "a "],
-      ["a &l", "a "],
-      ["a ", "a "],
-      ["a ", "a "],
-      ["a &comm", "a "],
-      ["a <", "a "],
-      ["`a <", "`a "],
-      ["a &", "a &"]
-    ]
-    for (const [text, sent] of cases) {
-      const result = escapeStream(text, {})
-      assert.strictEqual(result.sent, sent, text)
-      assert.strictEqual(result.consumed, sent.length, text)
-    }
-    // A shape is decided at once unless an allowed token could still close it.
-    assert.strictEqual(escapeStream("a <@U", {}).sent, `a <${z}@U`)
-    assert.strictEqual(escapeStream("a <@U", notify).sent, "a ")
-    // The held tail goes again at the front of the next chunk.
-    const first = escapeStream("x &l", notify)
-    const second = escapeStream("<@U1> y", notify, { state: first.state })
-    assert.strictEqual(first.sent + second.sent, "x <@U1> y")
-    // flush and the bound send it.
-    assert.strictEqual(escapeStream("a &l", {}, { flush: true }).sent, "a &l")
-    assert.strictEqual(escapeStream("a <", {}, { flush: true }).sent, "a <")
-    const long = "<@U1|" + "x".repeat(400)
-    assert.strictEqual(escapeStream(long, notify).sent, `<${z}@U1|` + "x".repeat(400))
-  })
-})
-
-describe("measure", () => {
-  it("bounds what is sent and adds up", () => {
-    const samples = ["plain", "a < b", "<<<", "😀😀", "`<@U1>` ", "👍🏽 and 1\u20E3", "\ud83d", "🇺🇸"]
-    for (const a of samples) {
-      assert.isAtLeast(measure(a), codePoints(sent(a)))
-      for (const b of samples) assert.isAtMost(measure(a + b), measure(a) + measure(b))
-    }
-    assert.strictEqual(measure("abc"), 3)
-    assert.strictEqual(measure("<"), 4)
-    // 1,200 😀 cost 12,000 against 13,200, scaled to 12,000 and rounded up.
-    assert.strictEqual(measure("😀".repeat(1200)), 10_910)
-  })
 })
diff --git a/packages/chat/slack/test/events.test.ts b/packages/chat/slack/test/events.test.ts
index f1f20c18198..8b0a744b80d 100644
--- a/packages/chat/slack/test/events.test.ts
+++ b/packages/chat/slack/test/events.test.ts
@@ -103,29 +103,14 @@ describe("captured Events API deliveries", () => {
       }
     }))
 
-  it.live("a root mention, then the root's message_changed deliveries give nothing", () =>
-    Effect.gen(function*() {
-      const [root, ...changed] = yield* deliveries("thread-root")
-      const event = created(root)
-      assert.deepStrictEqual(mentions(event), selfMention())
-      assert.isTrue(event.message.author.isSelf)
-      assert.deepStrictEqual(partsOf(event.thread), { team, channel })
-      assert.strictEqual(changed.length, 2)
-      for (const events of changed) assert.deepStrictEqual(events, [])
-    }))
-
   it.live("a thread reply and a thread_broadcast belong to the root's thread", () =>
     Effect.gen(function*() {
       const root = created((yield* deliveries("thread-root"))[0]).message.id
       const reply = created((yield* deliveries("thread-reply"))[0])
       assert.deepStrictEqual(partsOf(reply.thread), { team, channel, threadTs: root })
-      assert.deepStrictEqual(mentions(reply), selfMention())
       // Slack sent a message_changed for the broadcast before the broadcast itself.
-      const [changed, broadcast] = yield* deliveries("thread-broadcast")
-      assert.deepStrictEqual(changed, [])
-      const event = created(broadcast)
-      assert.deepStrictEqual(partsOf(event.thread), { team, channel, threadTs: root })
-      assert.deepStrictEqual(mentions(event), selfMention())
+      const [, broadcast] = yield* deliveries("thread-broadcast")
+      assert.deepStrictEqual(partsOf(created(broadcast).thread), { team, channel, threadTs: root })
     }))
 
   it.live("a mention only in code, a Block Kit section or an attachment is not reported", () =>
@@ -135,25 +120,8 @@ describe("captured Events API deliveries", () => {
         assert.deepStrictEqual(event.message.mentions, [], name)
       }
     }))
-
-  it.live("the bot's own /me line reads back from its blocks, with the token the renderer wrote", () =>
-    Effect.gen(function*() {
-      const event = created((yield* deliveries("me-message"))[0])
-      assert.deepStrictEqual(mentions(event), selfMention())
-    }))
-
-  it.live("a native stream arrives as an empty message from the bot, its text only as message_changed", () =>
-    Effect.gen(function*() {
-      const [start, changed] = yield* deliveries("native-stream")
-      const event = created(start)
-      assert.strictEqual(event.message.text, "")
-      assert.isTrue(event.message.author.isSelf)
-      assert.deepStrictEqual(changed, [])
-    }))
 })
 
-const person = "U080YLYB277"
-
 type Body = { readonly event: Record }
 
 /** The `message` and `app_mention` deliveries of one message, matched by ts. */
@@ -177,15 +145,12 @@ describe("captured deliveries for messages a person typed", () => {
         for (const [message, mention] of pairsOf(name)) {
           const fromMessage = created(SlackChat.normalize(message, context))
           const fromMention = created(SlackChat.normalize(mention, context))
-          yield* checkEvent(fromMessage, checkOptions)
-          yield* checkEvent(fromMention, checkOptions)
           assert.strictEqual(dedupeKey(fromMessage), dedupeKey(fromMention), name)
           assert.isTrue(sameMessage(fromMessage.message, fromMention.message), name)
           const { raw: _a, ...left } = fromMessage.message
           const { raw: _b, ...right } = fromMention.message
           assert.deepStrictEqual(left, right, name)
           assert.deepStrictEqual(fromMessage.thread, fromMention.thread, name)
-          assert.isFalse(fromMessage.message.author.isSelf)
           assert.deepStrictEqual(
             mentions(fromMessage),
             selfMention(String(message.event.subtype) === "me_message" ? "|janitor2" : "")
@@ -209,12 +174,6 @@ describe("captured deliveries for messages a person typed", () => {
       assert.deepStrictEqual(created(original).message.mentions, [])
       assert.deepStrictEqual(changed, [])
       assert.deepStrictEqual(mention, [])
-      const [, , rootChanged, removed] = yield* deliveries("human-edit-removes-mention")
-      assert.deepStrictEqual(rootChanged, [])
-      assert.deepStrictEqual(removed, [])
-      const [, , kept, keptRoot] = yield* deliveries("human-edit-keeps-mention")
-      assert.deepStrictEqual(kept, [])
-      assert.deepStrictEqual(keptRoot, [])
     }))
 
   it.live("reactions, with a skin tone and a custom emoji", () =>
@@ -225,7 +184,6 @@ describe("captured deliveries for messages a person typed", () => {
         const event = events[0]
         assert(event._tag === "ReactionAdded" || event._tag === "ReactionRemoved")
         assert.strictEqual(event.messageId, root)
-        assert.strictEqual(event.userId, person)
         return event
       })
       assert.deepStrictEqual(reactions.map((event) => [event._tag, event.emoji]), [
@@ -240,19 +198,7 @@ describe("captured deliveries for messages a person typed", () => {
     }))
 })
 
-describe("captured deliveries for the bot's replies and stops", () => {
-  it.live("janitor's status message, its edits and its deletion: only the posts are events", () =>
-    Effect.gen(function*() {
-      const results = yield* deliveries("bot-reply-lifecycle")
-      const posted = results.filter((events) => events.length > 0).map(created)
-      assert.strictEqual(posted.length, 2)
-      const root = created((yield* deliveries("human-mention"))[0]).message.id
-      for (const event of posted) {
-        assert.isTrue(event.message.author.isSelf)
-        assert.deepStrictEqual(partsOf(event.thread), { team, channel, threadTs: root })
-      }
-    }))
-
+describe("captured deliveries for stops", () => {
   it.live("only the first click on Stop names the open stream", () =>
     Effect.gen(function*() {
       const results = yield* deliveries("stop-stream")
@@ -261,10 +207,7 @@ describe("captured deliveries for the bot's replies and stops", () => {
       assert.strictEqual(stream.message.text, "")
       const stops = results.flat().filter((event) => event._tag === "StopRequested")
       assert.deepStrictEqual(stops.map((event) => event.messageIds), [[stream.message.id], [], []])
-      for (const stop of stops) {
-        assert.strictEqual(stop.userId, person)
-        assert.deepStrictEqual(Option.getOrThrow(SlackChat.parts(stop.thread)), { team, channel, threadTs: root })
-      }
+      for (const stop of stops) assert.deepStrictEqual(partsOf(stop.thread), { team, channel, threadTs: root })
       // Each click is its own request.
       assert.strictEqual(new Set(stops.map(dedupeKey)).size, 3)
     }))
diff --git a/packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json b/packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json
deleted file mode 100644
index c88fdd056cb..00000000000
--- a/packages/chat/slack/test/fixtures/events/bot-reply-lifecycle.json
+++ /dev/null
@@ -1,130 +0,0 @@
-{
-  "case": "Janitor's answer to H2: a status message in the thread, its edits, the reply, then the status message deleted",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), as janitor production answered or as the session script posted",
-    "recordedAt": "2026-11-12T23:25:50Z to 2026-11-12T23:36:10Z, a session run with Jarvis on EFF-3694",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T23:26:17.018Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525976",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525976.260709\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"uz3\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525976.260709\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH63VG21K\",\"event_time\":1794525976,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:19.965Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525979",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525979.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"b6\\/L\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"3CmG\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525979.000200\",\"event_ts\":\"1794525979.000200\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH9DGLH7Y\",\"event_time\":1794525979,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:23.456Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525982",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525982.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"pfu\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525979.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"VAX\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525982.000300\",\"event_ts\":\"1794525982.000300\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHD9ANC01\",\"event_time\":1794525982,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:26.299Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525985",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525985.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"10Wy2\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525982.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"Ydc\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525985.000400\",\"event_ts\":\"1794525985.000400\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHF3R58TW\",\"event_time\":1794525985,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:29.336Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525988",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525988.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"+YN\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525985.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"14oq\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 00s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525988.000500\",\"event_ts\":\"1794525988.000500\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHB71C658\",\"event_time\":1794525988,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:32.037Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525991",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525991.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"pWp\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525988.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"wOn\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 03s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525991.000600\",\"event_ts\":\"1794525991.000600\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH55RV291\",\"event_time\":1794525991,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:35.148Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525995",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525995.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"5uL6\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}],\"ts\":\"1794525976.260709\",\"source_team\":\"T05479Z6JBW\",\"user_team\":\"T05479Z6JBW\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525991.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"o580\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 06s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794525995.000700\",\"event_ts\":\"1794525995.000700\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CGW1F94DD\",\"event_time\":1794525995,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:36.902Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525996",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525996.616959\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"What would you like me to do with \\u201cH2\\u201d\\u2014find a mention, or something else?\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"reply\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"f9Q1NP\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"What would you like me to do with \\u201cH2\\u201d\\u2014find a mention, or something else?\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794525996.616959\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHD9CG3U1\",\"event_time\":1794525996,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T23:26:37.884Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794525997",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_deleted\",\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794525976.260709\",\"edited\":{\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794525995.000000\"},\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794525974.374799\",\"parent_user_id\":\"U080YLYB277\",\"metadata\":{\"event_type\":\"janitor_output\",\"event_payload\":{\"kind\":\"status\"}},\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"zwq7Z\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Starting \\u00b7 0m 09s \\u00b7 \"},{\"type\":\"link\",\"url\":\"https:\\/\\/janitor.effectful.co\\/chat\\/sessions\\/slack\\/T05479Z6JBW\\/C0CH1LGJ4F3\\/1794525974.374799\"}]}]}]},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"deleted_ts\":\"1794525976.260709\",\"event_ts\":\"1794525997.000900\",\"ts\":\"1794525997.000900\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ5PK9LBS\",\"event_time\":1794525997,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/me-message.json b/packages/chat/slack/test/fixtures/events/me-message.json
deleted file mode 100644
index b375b0249c9..00000000000
--- a/packages/chat/slack/test/fixtures/events/me-message.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
-  "case": "A /me line (chat.meMessage) that mentions the bot",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
-    "recordedAt": "2026-11-12T20:54:52.189Z",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "actions": [
-    {
-      "action": "chat.meMessage",
-      "ts": "1794516880.615709"
-    }
-  ],
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T20:54:40.906Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516880",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"me_message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516880.615709\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"waves at <@U0CCLMD4S1L|janitor2> [EFF-3694 20:54:24]\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"rn7Rs\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"waves at \"},{\"type\":\"user\",\"user_id\":\"U0CCLMD4S1L\"},{\"type\":\"text\",\"text\":\" [EFF-3694 20:54:24]\"}]}]}],\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516880.615709\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CH3T1V1DH\",\"event_time\":1794516880,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}"
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/events/native-stream.json b/packages/chat/slack/test/fixtures/events/native-stream.json
deleted file mode 100644
index 32c5da4d84b..00000000000
--- a/packages/chat/slack/test/fixtures/events/native-stream.json
+++ /dev/null
@@ -1,49 +0,0 @@
-{
-  "case": "A native stream started in a thread, appended to and stopped",
-  "provenance": {
-    "source": "Slack Events API deliveries to the janitor2 app (A0CCHBHDK7X), logged by janitor production's EFF-3709 fixture capture (Effect-TS/janitor a751115)",
-    "channel": "chat-testing-123 (C0CH1LGJ4F3), a private channel",
-    "author": "the janitor2 bot user (U0CCLMD4S1L), through the bot token",
-    "recordedAt": "2026-11-12T20:54:52.189Z",
-    "body": "The delivered JSON string, verbatim apart from the envelope token member, which the capture removes, and the members listed in a delivery's scrubbed, whose URLs are replaced",
-    "headers": "The capture's allowlist. The signature is never logged"
-  },
-  "actions": [
-    {
-      "action": "chat.startStream",
-      "ts": "1794516888.347839"
-    },
-    {
-      "action": "chat.stopStream",
-      "ts": "1794516888.347839"
-    }
-  ],
-  "deliveries": [
-    {
-      "loggedAt": "2026-11-12T20:54:48.550Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516888",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"user\":\"U0CCLMD4S1L\",\"ts\":\"1794516888.347839\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"parent_user_id\":\"U0CCLMD4S1L\",\"streaming_state\":\"in_progress\",\"channel\":\"C0CH1LGJ4F3\",\"event_ts\":\"1794516888.347839\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CJ4FF66C8\",\"event_time\":1794516888,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    },
-    {
-      "loggedAt": "2026-11-12T20:54:51.162Z",
-      "headers": {
-        "x-slack-request-timestamp": "1794516891",
-        "content-type": "application/json"
-      },
-      "body": "{\"team_id\":\"T05479Z6JBW\",\"context_team_id\":\"T05479Z6JBW\",\"context_enterprise_id\":null,\"api_app_id\":\"A0CCHBHDK7X\",\"event\":{\"type\":\"message\",\"subtype\":\"message_changed\",\"message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"streaming [EFF-3694 20:54:24] more\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"parent_user_id\":\"U0CCLMD4S1L\",\"blocks\":[{\"type\":\"rich_text\",\"block_id\":\"rLSGFT\",\"elements\":[{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"streaming [EFF-3694 20:54:24] more\"}]}]}],\"streaming_state\":\"completed\",\"ts\":\"1794516888.347839\"},\"previous_message\":{\"user\":\"U0CCLMD4S1L\",\"type\":\"message\",\"ts\":\"1794516888.347839\",\"bot_id\":\"B0CCQH77VA5\",\"app_id\":\"A0CCHBHDK7X\",\"text\":\"\",\"team\":\"T05479Z6JBW\",\"bot_profile\":{\"id\":\"B0CCQH77VA5\",\"deleted\":false,\"name\":\"Janitor\",\"updated\":1793135255,\"app_id\":\"A0CCHBHDK7X\",\"user_id\":\"U0CCLMD4S1L\",\"icons\":{\"image_36\":\"https:\\/\\/scrubbed.invalid\\/image_36\",\"image_48\":\"https:\\/\\/scrubbed.invalid\\/image_48\",\"image_72\":\"https:\\/\\/scrubbed.invalid\\/image_72\"},\"team_id\":\"T05479Z6JBW\"},\"thread_ts\":\"1794516865.426549\",\"parent_user_id\":\"U0CCLMD4S1L\",\"streaming_state\":\"in_progress\"},\"channel\":\"C0CH1LGJ4F3\",\"hidden\":true,\"ts\":\"1794516890.059700\",\"event_ts\":\"1794516890.059700\",\"channel_type\":\"group\"},\"type\":\"event_callback\",\"event_id\":\"Ev0CHDR2MAQL\",\"event_time\":1794516890,\"authorizations\":[{\"enterprise_id\":null,\"team_id\":\"T05479Z6JBW\",\"user_id\":\"U0CCLMD4S1L\",\"is_bot\":true,\"is_enterprise_install\":false}],\"is_ext_shared_channel\":false,\"event_context\":\"4-eyJldCI6Im1lc3NhZ2UiLCJ0aWQiOiJUMDU0NzlaNkpCVyIsImFpZCI6IkEwQ0NIQkhESzdYIiwiY2lkIjoiQzBDSDFMR0o0RjMifQ\"}",
-      "scrubbed": [
-        "image_36",
-        "image_48",
-        "image_72"
-      ]
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json b/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
deleted file mode 100644
index 0290459c3db..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/agent-session-stopped.json
+++ /dev/null
@@ -1,80 +0,0 @@
-{
-  "source": "EFF-3676 live runs G1 to G3, as janitor received them. G2 and G3 envelopes are as in G1, which was logged in full; their event objects are as logged. G2's has no streaming_message_ts because that log dropped it; Slack sends an empty array. It is kept to show an absent field is tolerated.",
-  "cases": {
-    "channelThread": {
-      "type": "event_callback",
-      "team_id": "T05479Z6JBW",
-      "api_app_id": "A0CCHBHDK7X",
-      "event_id": "Ev0CH0C5627L",
-      "event_time": 1794454026,
-      "is_ext_shared_channel": false,
-      "authorizations": [
-        {
-          "team_id": "T05479Z6JBW",
-          "user_id": "U0CCLMD4S1L",
-          "is_bot": true,
-          "is_enterprise_install": false
-        }
-      ],
-      "event": {
-        "type": "agent_session_stopped",
-        "channel": "C0CH1LGJ4F3",
-        "user": "U080YLYB277",
-        "thread_ts": "1794454017.568519",
-        "event_ts": "1794454026.522466",
-        "streaming_message_ts": [
-          "1794454017.726189"
-        ]
-      }
-    },
-    "noStream": {
-      "type": "event_callback",
-      "team_id": "T05479Z6JBW",
-      "api_app_id": "A0CCHBHDK7X",
-      "event_id": "Ev0CGV9VQVEH",
-      "event_time": 1794454026,
-      "is_ext_shared_channel": false,
-      "authorizations": [
-        {
-          "team_id": "T05479Z6JBW",
-          "user_id": "U0CCLMD4S1L",
-          "is_bot": true,
-          "is_enterprise_install": false
-        }
-      ],
-      "event": {
-        "type": "agent_session_stopped",
-        "channel": "C0CH1LGJ4F3",
-        "user": "U080YLYB277",
-        "thread_ts": "1794454354.780449",
-        "event_ts": "1794454367.470649"
-      }
-    },
-    "direct": {
-      "type": "event_callback",
-      "team_id": "T05479Z6JBW",
-      "api_app_id": "A0CCHBHDK7X",
-      "event_id": "Ev0CGUC5LUKD",
-      "event_time": 1794454026,
-      "is_ext_shared_channel": false,
-      "authorizations": [
-        {
-          "team_id": "T05479Z6JBW",
-          "user_id": "U0CCLMD4S1L",
-          "is_bot": true,
-          "is_enterprise_install": false
-        }
-      ],
-      "event": {
-        "type": "agent_session_stopped",
-        "channel": "D0CCGDG0E75",
-        "user": "U080YLYB277",
-        "thread_ts": "1794454526.171439",
-        "event_ts": "1794454532.803025",
-        "streaming_message_ts": [
-          "1794454526.283939"
-        ]
-      }
-    }
-  }
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json b/packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json
deleted file mode 100644
index 1c3320ef4e2..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/assistant-thread-root.json
+++ /dev/null
@@ -1,220 +0,0 @@
-{
-  "case": "read-only: the agent-view (assistant) thread root in the app DM",
-  "recordedAt": "2026-11-12T18:43:52.781Z",
-  "calls": [
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "request": {
-        "channel": "D0CCGDG0E75",
-        "ts": "1794454526.171439",
-        "limit": 5
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794454526.171439",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794454526.171439",
-            "reply_count": 1,
-            "reply_users_count": 1,
-            "latest_reply": "1794454526.283939",
-            "reply_users": [
-              "U0CCLMD4S1L"
-            ],
-            "is_locked": false,
-            "subscribed": false,
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "1af",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ],
-            "agent_session": {
-              "status": "active",
-              "agent_bot_user_ids": [
-                "U0CCLMD4S1L"
-              ],
-              "encoded_initiator_user_id": "U080YLYB277",
-              "agent_statuses": [
-                {
-                  "agent_bot_user_id": "U0CCLMD4S1L",
-                  "status": "active",
-                  "is_stoppable": true
-                }
-              ]
-            }
-          },
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794454526.283939",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "G3 stream started. tick 2 after-click",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794454526.171439",
-            "parent_user_id": "U0CCLMD4S1L",
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "qmE9gL",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "G3 stream started. tick 2 after-click"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ],
-            "ai_context": {
-              "type": "default",
-              "result_status": "stopped_by_user",
-              "stopped_by_user_id": "U080YLYB277"
-            },
-            "streaming_state": "completed"
-          }
-        ],
-        "has_more": false
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "request": {
-        "channel": "D0CCGDG0E75",
-        "latest": "1794454526.171439",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794454526.171439",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794454526.171439",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794454526.171439",
-            "reply_count": 1,
-            "reply_users_count": 1,
-            "latest_reply": "1794454526.283939",
-            "reply_users": [
-              "U0CCLMD4S1L"
-            ],
-            "is_locked": false,
-            "subscribed": false,
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "CgoC",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "G3 stop button test (EFF-3676). A stream starts in this thread now. Click Stop as soon as you see it."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ],
-            "agent_session": {
-              "status": "active",
-              "agent_bot_user_ids": [
-                "U0CCLMD4S1L"
-              ],
-              "encoded_initiator_user_id": "U080YLYB277",
-              "agent_statuses": [
-                {
-                  "agent_bot_user_id": "U0CCLMD4S1L",
-                  "status": "active",
-                  "is_stoppable": true
-                }
-              ]
-            }
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NDQ4Njg1MjkxNzk5"
-        }
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/interactivity.json b/packages/chat/slack/test/fixtures/recorded/interactivity.json
deleted file mode 100644
index c338e7cfbae..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/interactivity.json
+++ /dev/null
@@ -1,244 +0,0 @@
-{
-  "source": "EFF-3726 series H in chat-testing-123, as the Interactivity Request URL received them, with the verification token, response_url and most of trigger_id redacted. The click is on an element of a block another app built; the submit is of a view the adapter did not open.",
-  "cases": {
-    "block_actions": {
-      "type": "block_actions",
-      "user": {
-        "id": "U080YLYB277",
-        "username": "tim.smart",
-        "name": "tim.smart",
-        "team_id": "T05479Z6JBW"
-      },
-      "api_app_id": "A0CCHBHDK7X",
-      "token": "",
-      "container": {
-        "type": "message",
-        "message_ts": "1794535967.302589",
-        "channel_id": "C0CH1LGJ4F3",
-        "is_ephemeral": false
-      },
-      "trigger_id": "12585269731701",
-      "team": {
-        "id": "T05479Z6JBW",
-        "domain": "effectfulworkspace"
-      },
-      "enterprise": null,
-      "is_enterprise_install": false,
-      "channel": {
-        "id": "C0CH1LGJ4F3",
-        "name": "privategroup"
-      },
-      "message": {
-        "user": "U0CCLMD4S1L",
-        "type": "message",
-        "ts": "1794535967.302589",
-        "bot_id": "B0CCQH77VA5",
-        "app_id": "A0CCHBHDK7X",
-        "text": "EFF-3726 click test",
-        "team": "T05479Z6JBW",
-        "blocks": [
-          {
-            "type": "section",
-            "block_id": "q6zWT",
-            "text": {
-              "type": "mrkdwn",
-              "text": "*EFF-3726 click test (series H).* Click 1 to 7 in order, one at a time, and note what the client shows after each.",
-              "verbatim": false
-            }
-          },
-          {
-            "type": "actions",
-            "block_id": "h_clicks",
-            "elements": [
-              {
-                "type": "button",
-                "action_id": "ack_now",
-                "text": {
-                  "type": "plain_text",
-                  "text": "1 ack now",
-                  "emoji": true
-                },
-                "value": "ack_now"
-              },
-              {
-                "type": "button",
-                "action_id": "ack_late_5s",
-                "text": {
-                  "type": "plain_text",
-                  "text": "2 ack at 5s",
-                  "emoji": true
-                },
-                "value": "ack_late_5s"
-              },
-              {
-                "type": "button",
-                "action_id": "ack_late_20s",
-                "text": {
-                  "type": "plain_text",
-                  "text": "3 ack at 20s",
-                  "emoji": true
-                },
-                "value": "ack_late_20s"
-              },
-              {
-                "type": "button",
-                "action_id": "ack_never",
-                "text": {
-                  "type": "plain_text",
-                  "text": "4 never ack",
-                  "emoji": true
-                },
-                "value": "ack_never"
-              }
-            ]
-          },
-          {
-            "type": "actions",
-            "block_id": "h_modals",
-            "elements": [
-              {
-                "type": "button",
-                "action_id": "open_modal_ok",
-                "text": {
-                  "type": "plain_text",
-                  "text": "5 modal, submit acked",
-                  "emoji": true
-                },
-                "value": "open_modal_ok"
-              },
-              {
-                "type": "button",
-                "action_id": "open_modal_late_5s",
-                "text": {
-                  "type": "plain_text",
-                  "text": "6 modal, submit acked at 5s",
-                  "emoji": true
-                },
-                "value": "open_modal_late_5s"
-              },
-              {
-                "type": "button",
-                "action_id": "open_modal_never",
-                "text": {
-                  "type": "plain_text",
-                  "text": "7 modal, submit never acked",
-                  "emoji": true
-                },
-                "value": "open_modal_never"
-              }
-            ]
-          }
-        ]
-      },
-      "state": {
-        "values": {}
-      },
-      "response_url": "",
-      "actions": [
-        {
-          "type": "button",
-          "block_id": "h_modals",
-          "action_id": "open_modal_ok",
-          "text": {
-            "type": "plain_text",
-            "text": "5 modal, submit acked",
-            "emoji": true
-          },
-          "value": "open_modal_ok",
-          "action_ts": "1794536129.903602"
-        }
-      ]
-    },
-    "view_submission": {
-      "type": "view_submission",
-      "team": {
-        "id": "T05479Z6JBW",
-        "domain": "effectfulworkspace"
-      },
-      "user": {
-        "id": "U080YLYB277",
-        "username": "tim.smart",
-        "name": "tim.smart",
-        "team_id": "T05479Z6JBW"
-      },
-      "api_app_id": "A0CCHBHDK7X",
-      "token": "",
-      "trigger_id": "12618937762224",
-      "view": {
-        "id": "V0CHAHJNBSS",
-        "team_id": "T05479Z6JBW",
-        "type": "modal",
-        "blocks": [
-          {
-            "type": "section",
-            "block_id": "9aEq0",
-            "text": {
-              "type": "mrkdwn",
-              "text": "EFF-3726 test modal *submit_ok*. Wait for the test channel to say the limit probe is done before you submit.",
-              "verbatim": false
-            }
-          },
-          {
-            "type": "input",
-            "block_id": "b_note",
-            "label": {
-              "type": "plain_text",
-              "text": "Note",
-              "emoji": true
-            },
-            "optional": true,
-            "dispatch_action": false,
-            "element": {
-              "type": "plain_text_input",
-              "action_id": "note",
-              "dispatch_action_config": {
-                "trigger_actions_on": [
-                  "on_enter_pressed"
-                ]
-              }
-            }
-          }
-        ],
-        "private_metadata": "{\"q\":\"\\\"quoted\\\"\",\"amp\":\"a&b  <d>\",\"emoji\":\"😀👩🏽‍💻\",\"nl\":\"line1\\nline2\\ttab\",\"uni\":\"é ü 日本\",\"pad\":\"  trailing  \"}",
-        "callback_id": "submit_ok",
-        "state": {
-          "values": {
-            "b_note": {
-              "note": {
-                "type": "plain_text_input",
-                "value": "hello"
-              }
-            }
-          }
-        },
-        "hash": "1794536131.FvPOkwwj",
-        "title": {
-          "type": "plain_text",
-          "text": "EFF-3726",
-          "emoji": true
-        },
-        "clear_on_close": false,
-        "notify_on_close": false,
-        "close": {
-          "type": "plain_text",
-          "text": "Cancel",
-          "emoji": true
-        },
-        "submit": {
-          "type": "plain_text",
-          "text": "Submit",
-          "emoji": true
-        },
-        "previous_view_id": null,
-        "root_view_id": "V0CHAHJNBSS",
-        "app_id": "A0CCHBHDK7X",
-        "external_id": "",
-        "app_installed_team_id": "T05479Z6JBW",
-        "bot_id": "B0CCQH77VA5"
-      },
-      "response_urls": [],
-      "is_enterprise_install": false,
-      "enterprise": null
-    }
-  }
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/me-message.json b/packages/chat/slack/test/fixtures/recorded/me-message.json
deleted file mode 100644
index da9fed0e641..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/me-message.json
+++ /dev/null
@@ -1,136 +0,0 @@
-{
-  "case": "chat.meMessage mentioning the bot; read back",
-  "recordedAt": "2026-11-12T18:43:28.103Z",
-  "calls": [
-    {
-      "method": "chat.meMessage",
-      "encoding": "form",
-      "note": "chat.meMessage via form encoding",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "text": "Fixture: me message waves at <@U0CCLMD4S1L>"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509006.465359"
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509006.465359",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509006.465359",
-        "messages": [
-          {
-            "subtype": "me_message",
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509006.465359",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: me message waves at <@U0CCLMD4S1L|janitor2>",
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "+CZAP",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: me message waves at "
-                      },
-                      {
-                        "type": "user",
-                        "user_id": "U0CCLMD4S1L"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MDA0ODExODc5"
-        }
-      }
-    },
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509006.465359",
-        "limit": 10
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "messages": [
-          {
-            "subtype": "me_message",
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509006.465359",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: me message waves at <@U0CCLMD4S1L|janitor2>",
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "TYkp0",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: me message waves at "
-                      },
-                      {
-                        "type": "user",
-                        "user_id": "U0CCLMD4S1L"
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": false
-      }
-    },
-    {
-      "method": "chat.meMessage",
-      "encoding": "json",
-      "note": "same method with JSON body",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "text": "Fixture: me message (json body)"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509008.079609"
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json b/packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json
deleted file mode 100644
index c44ef86d745..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/thread-root-before-after.json
+++ /dev/null
@@ -1,472 +0,0 @@
-{
-  "case": "a thread root read (history + replies) before and after its first reply; root posted with markdown_text",
-  "recordedAt": "2026-11-12T18:43:23.114Z",
-  "calls": [
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "Fixture: thread root (no mentions). Some *markdown* here."
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509000.352789",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509000.352789",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "Fixture: thread root (no mentions). Some _markdown_ here.",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "TOu1os",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "Fixture: thread root (no mentions). Some "
-                    },
-                    {
-                      "type": "text",
-                      "text": "markdown",
-                      "style": {
-                        "italic": true
-                      }
-                    },
-                    {
-                      "type": "text",
-                      "text": " here."
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509000.352789",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509000.352789",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509000.352789",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: thread root (no mentions). Some _markdown_ here.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "TOu1os",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: thread root (no mentions). Some "
-                      },
-                      {
-                        "type": "text",
-                        "text": "markdown",
-                        "style": {
-                          "italic": true
-                        }
-                      },
-                      {
-                        "type": "text",
-                        "text": " here."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NDc5NTAzODIwNzA5"
-        }
-      }
-    },
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509000.352789",
-        "limit": 10
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509000.352789",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: thread root (no mentions). Some _markdown_ here.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "TOu1os",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: thread root (no mentions). Some "
-                      },
-                      {
-                        "type": "text",
-                        "text": "markdown",
-                        "style": {
-                          "italic": true
-                        }
-                      },
-                      {
-                        "type": "text",
-                        "text": " here."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": false
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "thread_ts": "1794509000.352789",
-        "markdown_text": "Fixture: first reply in the thread."
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509001.485739",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509001.485739",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "Fixture: first reply in the thread.",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "thread_ts": "1794509000.352789",
-          "parent_user_id": "U0CCLMD4S1L",
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "vy+DO3",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "Fixture: first reply in the thread."
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509000.352789",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509000.352789",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509000.352789",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: thread root (no mentions). Some _markdown_ here.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794509000.352789",
-            "reply_count": 1,
-            "reply_users_count": 1,
-            "latest_reply": "1794509001.485739",
-            "reply_users": [
-              "U0CCLMD4S1L"
-            ],
-            "is_locked": false,
-            "subscribed": false,
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "TOu1os",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: thread root (no mentions). Some "
-                      },
-                      {
-                        "type": "text",
-                        "text": "markdown",
-                        "style": {
-                          "italic": true
-                        }
-                      },
-                      {
-                        "type": "text",
-                        "text": " here."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NDc5NTAzODIwNzA5"
-        }
-      }
-    },
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509000.352789",
-        "limit": 10
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509000.352789",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: thread root (no mentions). Some _markdown_ here.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794509000.352789",
-            "reply_count": 1,
-            "reply_users_count": 1,
-            "latest_reply": "1794509001.485739",
-            "reply_users": [
-              "U0CCLMD4S1L"
-            ],
-            "is_locked": false,
-            "subscribed": false,
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "TOu1os",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: thread root (no mentions). Some "
-                      },
-                      {
-                        "type": "text",
-                        "text": "markdown",
-                        "style": {
-                          "italic": true
-                        }
-                      },
-                      {
-                        "type": "text",
-                        "text": " here."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          },
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509001.485739",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture: first reply in the thread.",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "thread_ts": "1794509000.352789",
-            "parent_user_id": "U0CCLMD4S1L",
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "vy+DO3",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture: first reply in the thread."
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": false
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/fixtures/recorded/unfurl-edit.json b/packages/chat/slack/test/fixtures/recorded/unfurl-edit.json
deleted file mode 100644
index bebcbeb4e27..00000000000
--- a/packages/chat/slack/test/fixtures/recorded/unfurl-edit.json
+++ /dev/null
@@ -1,1207 +0,0 @@
-{
-  "case": "does a message posted with unfurl_links/unfurl_media false gain an unfurl when chat.update adds a link? plus a control posted with the link and unfurls enabled; plus a second edit case posted WITHOUT unfurl params (defaults) then edited to add the link; plus edit case 3 / control 3 using URLs not previously posted in the channel (rules out Slack's same-URL unfurl de-duplication)",
-  "recordedAt": "2026-11-12T18:47:34.080Z",
-  "firstRecordedAt": "2026-11-12T18:46:15.379Z",
-  "calls": [
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "edit case: initial post, unfurls disabled",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "no link yet",
-        "unfurl_links": false,
-        "unfurl_media": false
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509128.969019",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509128.969019",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "no link yet",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "owsBih",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "no link yet"
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "control: link posted directly, unfurls enabled",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "Fixture control: https://github.com/Effect-TS/effect",
-        "unfurl_links": true,
-        "unfurl_media": true
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509129.029199",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509129.029199",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "Fixture control: ",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "gacOs0",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "Fixture control: "
-                    },
-                    {
-                      "type": "link",
-                      "url": "https://github.com/Effect-TS/effect",
-                      "text": "github.com/Effect-TS/effect",
-                      "truncated": true
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "chat.update",
-      "encoding": "json",
-      "note": "edit case: add a link (chat.update has no unfurl params)",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509128.969019",
-        "markdown_text": "now with a link: https://github.com/Effect-TS/effect"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509128.969019",
-        "text": "now with a link: ",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "edited": {
-            "user": "U0CCLMD4S1L",
-            "ts": "1794509130.000000"
-          },
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "now with a link: ",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "sv5KYB",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "now with a link: "
-                    },
-                    {
-                      "type": "link",
-                      "url": "https://github.com/Effect-TS/effect",
-                      "text": "github.com/Effect-TS/effect",
-                      "truncated": true
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "edit case after 20s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509128.969019",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509128.969019",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509128.969019",
-            "edited": {
-              "user": "U0CCLMD4S1L",
-              "ts": "1794509130.000000"
-            },
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "now with a link: ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "sv5KYB",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "now with a link: "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect",
-                        "text": "github.com/Effect-TS/effect",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MTEwOTk5Nzk5"
-        }
-      }
-    },
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "note": "edit case after 20s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509128.969019",
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509128.969019",
-            "edited": {
-              "user": "U0CCLMD4S1L",
-              "ts": "1794509130.000000"
-            },
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "now with a link: ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "sv5KYB",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "now with a link: "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect",
-                        "text": "github.com/Effect-TS/effect",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": false
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "control after 20s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509129.029199",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509129.029199",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509129.029199",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture control: ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "attachments": [
-              {
-                "from_url": "https://github.com/Effect-TS/effect",
-                "image_url": "https://scrubbed.invalid/image_url",
-                "image_width": 1200,
-                "image_height": 600,
-                "image_bytes": 42222,
-                "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png",
-                "original_url": "https://github.com/Effect-TS/effect",
-                "id": 1,
-                "fallback": "GitHub: GitHub - Effect-TS/effect: Build production-ready applications in TypeScript",
-                "text": "Build production-ready applications in TypeScript. Contribute to Effect-TS/effect development by creating an account on GitHub.",
-                "title": "GitHub - Effect-TS/effect: Build production-ready applications in TypeScript",
-                "title_link": "https://github.com/Effect-TS/effect",
-                "service_name": "GitHub",
-                "media_type": "external_link"
-              }
-            ],
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "gacOs0",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture control: "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect",
-                        "text": "github.com/Effect-TS/effect",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MTI4OTY5MDE5"
-        }
-      }
-    },
-    {
-      "method": "conversations.replies",
-      "encoding": "form",
-      "note": "control after 20s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509129.029199",
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509129.029199",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture control: ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "attachments": [
-              {
-                "from_url": "https://github.com/Effect-TS/effect",
-                "image_url": "https://scrubbed.invalid/image_url",
-                "image_width": 1200,
-                "image_height": 600,
-                "image_bytes": 42222,
-                "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png",
-                "original_url": "https://github.com/Effect-TS/effect",
-                "id": 1,
-                "fallback": "GitHub: GitHub - Effect-TS/effect: Build production-ready applications in TypeScript",
-                "text": "Build production-ready applications in TypeScript. Contribute to Effect-TS/effect development by creating an account on GitHub.",
-                "title": "GitHub - Effect-TS/effect: Build production-ready applications in TypeScript",
-                "title_link": "https://github.com/Effect-TS/effect",
-                "service_name": "GitHub",
-                "media_type": "external_link"
-              }
-            ],
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "gacOs0",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture control: "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect",
-                        "text": "github.com/Effect-TS/effect",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": false
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "edit case after ~45s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509128.969019",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509128.969019",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509128.969019",
-            "edited": {
-              "user": "U0CCLMD4S1L",
-              "ts": "1794509130.000000"
-            },
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "now with a link: ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "sv5KYB",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "now with a link: "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect",
-                        "text": "github.com/Effect-TS/effect",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MTEwOTk5Nzk5"
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "control after ~45s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509129.029199",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509129.029199",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509129.029199",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture control: ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "attachments": [
-              {
-                "from_url": "https://github.com/Effect-TS/effect",
-                "image_url": "https://scrubbed.invalid/image_url",
-                "image_width": 1200,
-                "image_height": 600,
-                "image_bytes": 42222,
-                "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png",
-                "original_url": "https://github.com/Effect-TS/effect",
-                "id": 1,
-                "fallback": "GitHub: GitHub - Effect-TS/effect: Build production-ready applications in TypeScript",
-                "text": "Build production-ready applications in TypeScript. Contribute to Effect-TS/effect development by creating an account on GitHub.",
-                "title": "GitHub - Effect-TS/effect: Build production-ready applications in TypeScript",
-                "title_link": "https://github.com/Effect-TS/effect",
-                "service_name": "GitHub",
-                "media_type": "external_link"
-              }
-            ],
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "gacOs0",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture control: "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect",
-                        "text": "github.com/Effect-TS/effect",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MTI4OTY5MDE5"
-        }
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "edit case 2: initial post with no unfurl params",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "no link yet (default unfurl settings)"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509187.550629",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509187.550629",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "no link yet (default unfurl settings)",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "DWET6I",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "no link yet (default unfurl settings)"
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "chat.update",
-      "encoding": "json",
-      "note": "edit case 2: add a link",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509187.550629",
-        "markdown_text": "edited to add https://github.com/Effect-TS/effect"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509187.550629",
-        "text": "edited to add ",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "edited": {
-            "user": "U0CCLMD4S1L",
-            "ts": "1794509188.000000"
-          },
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "edited to add ",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "rDlbGF",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "edited to add "
-                    },
-                    {
-                      "type": "link",
-                      "url": "https://github.com/Effect-TS/effect",
-                      "text": "github.com/Effect-TS/effect",
-                      "truncated": true
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "edit case 2 after ~25s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509187.550629",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509187.550629",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509187.550629",
-            "edited": {
-              "user": "U0CCLMD4S1L",
-              "ts": "1794509188.000000"
-            },
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "edited to add ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "rDlbGF",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "edited to add "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect",
-                        "text": "github.com/Effect-TS/effect",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MTI5MDI5MTk5"
-        }
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "edit case 3: initial post, default unfurl settings",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "no link yet (case 3)"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509227.845499",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509227.845499",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "no link yet (case 3)",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "Y7Owd/",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "no link yet (case 3)"
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "chat.postMessage",
-      "encoding": "json",
-      "note": "control 3: fresh URL posted directly, default unfurl settings",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "markdown_text": "Fixture control 3: https://github.com/Effect-TS/effect/issues/2"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509227.900709",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "ts": "1794509227.900709",
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "Fixture control 3: ",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "2ktf5k",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "Fixture control 3: "
-                    },
-                    {
-                      "type": "link",
-                      "url": "https://github.com/Effect-TS/effect/issues/2",
-                      "text": "github.com/Effect-TS/effect/issues/2",
-                      "truncated": true
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "chat.update",
-      "encoding": "json",
-      "note": "edit case 3: add a fresh URL",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509227.845499",
-        "markdown_text": "edited to add https://github.com/Effect-TS/effect/issues/1"
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "channel": "C0CH1LGJ4F3",
-        "ts": "1794509227.845499",
-        "text": "edited to add ",
-        "message": {
-          "user": "U0CCLMD4S1L",
-          "type": "message",
-          "edited": {
-            "user": "U0CCLMD4S1L",
-            "ts": "1794509228.000000"
-          },
-          "bot_id": "B0CCQH77VA5",
-          "app_id": "A0CCHBHDK7X",
-          "text": "edited to add ",
-          "team": "T05479Z6JBW",
-          "bot_profile": {
-            "id": "B0CCQH77VA5",
-            "deleted": false,
-            "name": "Janitor",
-            "updated": 1793135255,
-            "app_id": "A0CCHBHDK7X",
-            "user_id": "U0CCLMD4S1L",
-            "icons": {
-              "image_36": "https://scrubbed.invalid/image_36",
-              "image_48": "https://scrubbed.invalid/image_48",
-              "image_72": "https://scrubbed.invalid/image_72"
-            },
-            "team_id": "T05479Z6JBW"
-          },
-          "blocks": [
-            {
-              "type": "rich_text",
-              "block_id": "xucmzr",
-              "elements": [
-                {
-                  "type": "rich_text_section",
-                  "elements": [
-                    {
-                      "type": "text",
-                      "text": "edited to add "
-                    },
-                    {
-                      "type": "link",
-                      "url": "https://github.com/Effect-TS/effect/issues/1",
-                      "text": "github.com/Effect-TS/effect/issues/1",
-                      "truncated": true
-                    }
-                  ]
-                }
-              ]
-            }
-          ]
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "edit case 3 after ~25s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509227.845499",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509227.845499",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509227.845499",
-            "edited": {
-              "user": "U0CCLMD4S1L",
-              "ts": "1794509228.000000"
-            },
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "edited to add ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "xucmzr",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "edited to add "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect/issues/1",
-                        "text": "github.com/Effect-TS/effect/issues/1",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MTg3NTUwNjI5"
-        }
-      }
-    },
-    {
-      "method": "conversations.history",
-      "encoding": "form",
-      "note": "control 3 after ~25s",
-      "request": {
-        "channel": "C0CH1LGJ4F3",
-        "latest": "1794509227.900709",
-        "inclusive": true,
-        "limit": 1
-      },
-      "httpStatus": 200,
-      "response": {
-        "ok": true,
-        "latest": "1794509227.900709",
-        "messages": [
-          {
-            "user": "U0CCLMD4S1L",
-            "type": "message",
-            "ts": "1794509227.900709",
-            "bot_id": "B0CCQH77VA5",
-            "app_id": "A0CCHBHDK7X",
-            "text": "Fixture control 3: ",
-            "team": "T05479Z6JBW",
-            "bot_profile": {
-              "id": "B0CCQH77VA5",
-              "deleted": false,
-              "name": "Janitor",
-              "updated": 1793135255,
-              "app_id": "A0CCHBHDK7X",
-              "user_id": "U0CCLMD4S1L",
-              "icons": {
-                "image_36": "https://scrubbed.invalid/image_36",
-                "image_48": "https://scrubbed.invalid/image_48",
-                "image_72": "https://scrubbed.invalid/image_72"
-              },
-              "team_id": "T05479Z6JBW"
-            },
-            "attachments": [
-              {
-                "from_url": "https://github.com/Effect-TS/effect/issues/2",
-                "service_icon": "https://a.slack-edge.com/80588/img/unfurl_icons/github.png",
-                "original_url": "https://github.com/Effect-TS/effect/issues/2",
-                "id": 1,
-                "fallback": "GitHub: Rpc - Zero Boilerplate by mikearnaldi · Pull Request #2 · Effect-TS/effect",
-                "text": "Reinterpret an effect to be executed against an http endpoint, missing server implementation and http",
-                "title": "Rpc - Zero Boilerplate by mikearnaldi · Pull Request #2 · Effect-TS/effect",
-                "title_link": "https://github.com/Effect-TS/effect/issues/2",
-                "service_name": "GitHub",
-                "media_type": "external_link"
-              }
-            ],
-            "blocks": [
-              {
-                "type": "rich_text",
-                "block_id": "2ktf5k",
-                "elements": [
-                  {
-                    "type": "rich_text_section",
-                    "elements": [
-                      {
-                        "type": "text",
-                        "text": "Fixture control 3: "
-                      },
-                      {
-                        "type": "link",
-                        "url": "https://github.com/Effect-TS/effect/issues/2",
-                        "text": "github.com/Effect-TS/effect/issues/2",
-                        "truncated": true
-                      }
-                    ]
-                  }
-                ]
-              }
-            ]
-          }
-        ],
-        "has_more": true,
-        "pin_count": 0,
-        "channel_actions_ts": null,
-        "channel_actions_count": 0,
-        "response_metadata": {
-          "next_cursor": "bmV4dF90czoxNzk0NTA5MjI3ODQ1NDk5"
-        }
-      }
-    }
-  ]
-}
diff --git a/packages/chat/slack/test/interactions.test.ts b/packages/chat/slack/test/interactions.test.ts
index 888519ff4ed..49be542e129 100644
--- a/packages/chat/slack/test/interactions.test.ts
+++ b/packages/chat/slack/test/interactions.test.ts
@@ -1,8 +1,8 @@
 /**
- * Interactivity: the normaliser on recorded and built payloads, the answers
+ * Interactivity: the normaliser on built payloads, the answers
  * `SlackChat.interaction` gives, `layerInteractivity` over HTTP, and a
- * command's `followUp`. The command payloads here are built. The recorded
- * ones are in `commands.test.ts`.
+ * command's `followUp`. The recorded command payloads are in
+ * `commands.test.ts`.
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import * as NodeCrypto from "@effect/platform-node/NodeCrypto"
@@ -17,9 +17,8 @@ import * as HttpRouter from "effect/http/HttpRouter"
 import * as Layer from "effect/Layer"
 import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
-import { appId, authTest, channel, commandFields, fixture, makeFake, responseUrl, slackLayer, team } from "./utils.ts"
+import { appId, authTest, channel, commandFields, makeFake, responseUrl, slackLayer, team } from "./utils.ts"
 
-const recorded = fixture("interactivity").cases
 const join = "\u241F"
 const user = { id: "U080YLYB277", username: "tim", team_id: team }
 
@@ -51,38 +50,21 @@ const input = (value: string | null) => ({ field: { type: "plain_text_input", va
 describe("normalizeInteraction", () => {
   const normalize = (payload: unknown) => SlackChat.normalizeInteraction(payload, { teamId: team })
 
-  it("ignores what the adapter did not build, recorded from Slack", () => {
-    assert.isTrue(Option.isNone(normalize(recorded.block_actions)))
-    assert.isTrue(Option.isNone(normalize(recorded.view_submission)))
+  it("ignores what the adapter did not build", () => {
     assert.isTrue(Option.isNone(normalize(click({ type: "button", action_id: join + "0", url: "https://x.test" }))))
     assert.isTrue(Option.isNone(normalize(click({ type: "button", action_id: "go", block_id: "theirs" }))))
     assert.isTrue(Option.isNone(normalize(submit("theirs", {}))))
   })
 
-  it("gives a click its thread, message, value and raw payload without the token", () => {
+  it("gives a click on a thread's root the channel, and a raw payload without the token", () => {
     const event = Option.getOrThrow(
-      normalize(click({ type: "button", action_id: "go", value: "v1" }, { thread_ts: "1794600000.000100" }))
-    )
-    assert.strictEqual(event._tag, "ButtonClicked")
-    if (event._tag !== "ButtonClicked") return
-    assert.deepStrictEqual(
-      [event.id, event.value, event.messageId, event.userId, event.thread.id],
-      ["go", "v1", "1794600001.000100", user.id, `${team}/${channel}/1794600000.000100`]
-    )
-    assert.isFalse("token" in (event.raw as object))
-    // A click on a thread's root is in the channel, not in its own thread.
-    const root = Option.getOrThrow(
       normalize(click({ type: "button", action_id: "go" }, { thread_ts: "1794600001.000100" }))
     )
-    assert.strictEqual(root.thread.id, `${team}/${channel}`)
-    assert.isFalse("value" in root)
-    const select = Option.getOrThrow(
-      normalize(click({ type: "static_select", action_id: "pick", selected_option: { value: "b" } }))
-    )
-    assert.deepStrictEqual([select._tag, (select as ChatInteraction.SelectChanged).value], ["SelectChanged", "b"])
+    assert.strictEqual(event.thread.id, `${team}/${channel}`)
+    assert.isFalse("token" in (event.raw as object))
   })
 
-  it("gives a submit the click's origin and the consumer's metadata, which may hold the join", () => {
+  it("gives a submit the consumer's metadata, which may hold the join, and own keys only", () => {
     const metadata = `a${join}b`
     const packed = ["chat1", channel, "1794600000.000100", "1794600001.000100", metadata].join(join)
     // As JSON.parse gives it, with `__proto__` an own key.
@@ -97,23 +79,10 @@ describe("normalizeInteraction", () => {
     const event = Option.getOrThrow(normalize(submit(packed, values)))
     assert.strictEqual(event._tag, "ModalSubmitted")
     if (event._tag !== "ModalSubmitted") return
-    assert.deepStrictEqual(
-      [event.id, event.metadata, event.messageId, event.thread.id],
-      ["form", metadata, "1794600001.000100", `${team}/${channel}/1794600000.000100`]
-    )
+    assert.strictEqual(event.metadata, metadata)
     assert.isTrue(Object.hasOwn(event.values, "__proto__"))
     assert.strictEqual(event.values["__proto__"], "own")
     assert.deepStrictEqual(Object.keys(event.values).sort(), ["__proto__", "pick"])
-    const bare = Option.getOrThrow(normalize(submit(["chat1", channel, "", "1794600001.000100"].join(join), {})))
-    assert.isFalse("metadata" in bare)
-    assert.strictEqual(bare.thread.id, `${team}/${channel}`)
-  })
-
-  it("gives a command with no text an empty text, and ignores one with no name or channel", () => {
-    const { text: _, ...noText } = commandFields("/deploy", "")
-    assert.strictEqual((Option.getOrThrow(normalize(noText)) as ChatInteraction.CommandInvoked).text, "")
-    assert.isTrue(Option.isNone(normalize(commandFields("/", ""))))
-    assert.isTrue(Option.isNone(normalize(commandFields("/deploy", "", { channel_id: "" }))))
   })
 })
 
@@ -143,15 +112,14 @@ const recording = () => {
   }
 }
 
-const modal = (metadata?: string) =>
-  ChatUi.Modal.make({
-    id: "form",
-    title: "Form",
-    ...(metadata === undefined ? {} : { metadata }),
-    elements: [ChatUi.TextInput.make({ id: "field", label: "Field" })]
-  })
+const modal = ChatUi.Modal.make({
+  id: "form",
+  title: "Form",
+  elements: [ChatUi.TextInput.make({ id: "field", label: "Field" })]
+})
 
-const packedFor = (metadata: string) => ["chat1", channel, "", "1794600001.000100", metadata].join(join)
+/** What the adapter packs for a modal a click on a channel message opened. */
+const packed = ["chat1", channel, "", "1794600001.000100", ""].join(join)
 
 describe("SlackChat.interaction", () => {
   const interact = (fake: ReturnType, handler: ReturnType, payload: unknown) =>
@@ -166,81 +134,54 @@ describe("SlackChat.interaction", () => {
       const handler = recording()
       handler.submit = () => Effect.as(Effect.never, ChatInteraction.close)
       handler.click = () => Effect.as(Effect.never, ChatInteraction.ack)
-      const late = yield* interact(fake, handler, submit(packedFor(""), {}))
+      const late = yield* interact(fake, handler, submit(packed, {}))
       assert.deepStrictEqual(late, ChatInteraction.Late.make({}))
       assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
     }))
 
   // Keep validation and API error mapping independent of the handler's wall-clock deadline.
-  it.effect("refuses a modal Slack refuses, or that is too large, to Handler.refused, still acking", () =>
+  it.effect("refuses a modal Slack refuses to Handler.refused, still acking", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest, "views.open": { ok: false, error: "expired_trigger_id" } })
       const handler = recording()
-      handler.click = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal() }))
-      assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
-      handler.click = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("x".repeat(2_800)) }))
+      handler.click = () => Effect.succeed(ChatInteraction.OpenModal.make({ modal }))
       assert.isUndefined(yield* interact(fake, handler, click({ type: "button", action_id: "go" })))
       assert.deepStrictEqual(
         handler.refused.map((error) => [error.op, error.reason._tag, error.reason.detail]),
-        [["openModal", "NotFound", "interaction_expired"], ["openModal", "TooLarge", "modal_metadata_too_long"]]
+        [["openModal", "NotFound", "interaction_expired"]]
       )
-      assert.strictEqual(fake.called("views.open").length, 1)
-    }))
-
-  it.live("refuses a command answer that is too large to Handler.refused, answering nothing", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({ "auth.test": authTest })
-      const handler = recording()
-      handler.command = () => Effect.succeed(ChatInteraction.respond({ markdown: "x".repeat(12_001) }))
-      assert.isUndefined(yield* interact(fake, handler, commandFields("/deploy", "v1")))
-      assert.deepStrictEqual(handler.refused.map((error) => [error.op, error.reason._tag]), [["respond", "TooLarge"]])
     }))
 })
 
 describe("followUp", () => {
-  const deferred = (raw: Record, visibility: ChatInteraction.Visibility) =>
-    ChatInteraction.defer(
-      ChatInteraction.CommandInvoked.make({
-        id: "summarize",
-        text: "",
-        thread: SlackChat.thread({ team, channel }),
-        userId: "U080YLYB277",
-        raw: raw as any
-      }),
-      { visibility }
-    )
-
-  it.effect("posts once to the response_url with the deferral's response_type", () =>
-    Effect.gen(function*() {
-      const fake = makeFake({ "auth.test": authTest, "response_url": { status: 200, body: "ok" } })
-      const { token: _, ...raw } = commandFields("/summarize", "")
-      yield* Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred(raw, "public"), { markdown: "Done" })).pipe(
-        Effect.provide(slackLayer(fake))
-      )
-      const calls = fake.called("response_url")
-      assert.deepStrictEqual(
-        calls.map(({ params }) => [params.url, params.response_type, params.text]),
-        [[responseUrl, "in_channel", "Done"]]
-      )
-    }))
-
   it.effect("refuses a response_url off Slack before any call", () =>
     Effect.gen(function*() {
       const fake = makeFake({ "auth.test": authTest })
-      const failure = (raw: Record) =>
-        Effect.flip(Effect.flatMap(Chat.Chat, (chat) => chat.followUp(deferred(raw, "ephemeral"), { markdown: "x" })))
-          .pipe(
-            Effect.provide(slackLayer(fake))
-          )
-      const offSlack = yield* failure({ response_url: "https://hooks.slack.com.evil.test/commands/1" })
-      const plain = yield* failure({ response_url: responseUrl.replace("https:", "http:") })
-      assert.deepStrictEqual(
-        [offSlack, plain].map((error) => [error.op, error.reason._tag, error.reason.detail]),
-        [
-          ["followUp", "InvalidRequest", "invalid_response_url"],
-          ["followUp", "InvalidRequest", "invalid_response_url"]
-        ]
-      )
+      const failure = (url: string) =>
+        Chat.Chat.pipe(
+          Effect.flatMap((chat) =>
+            chat.followUp(
+              ChatInteraction.defer(ChatInteraction.CommandInvoked.make({
+                id: "summarize",
+                text: "",
+                thread: SlackChat.thread({ team, channel }),
+                userId: "U080YLYB277",
+                raw: { response_url: url }
+              })),
+              { markdown: "x" }
+            )
+          ),
+          Effect.flip,
+          Effect.provide(slackLayer(fake))
+        )
+      for (const url of ["https://hooks.slack.com.evil.test/commands/1", responseUrl.replace("https:", "http:")]) {
+        const error = yield* failure(url)
+        assert.deepStrictEqual([error.op, error.reason._tag, error.reason.detail], [
+          "followUp",
+          "InvalidRequest",
+          "invalid_response_url"
+        ])
+      }
       assert.strictEqual(fake.called("response_url").length, 0)
     }))
 })
@@ -314,21 +255,19 @@ describe("layerInteractivity", () => {
       yield* dispose
     }))
 
-  it.live("answers errors as JSON, an ack empty, and a bad signature 401", () =>
+  it.live("answers errors as JSON, and a bad signature 401", () =>
     Effect.gen(function*() {
       const handler = recording()
       const { dispose, send } = serve(handler)
       handler.submit = () => Effect.succeed(ChatInteraction.errors({ field: "Too short" }))
-      const errors = yield* send(submit(packedFor(""), {}))
+      const errors = yield* send(submit(packed, {}))
       assert.strictEqual(errors.status, 200)
       assert.deepStrictEqual(yield* Effect.promise(() => errors.json()), {
         response_action: "errors",
         errors: { field: "Too short" }
       })
 
-      const acked = yield* send(click({ type: "button", action_id: "go" }))
-      assert.deepStrictEqual([acked.status, yield* Effect.promise(() => acked.text())], [200, ""])
-      assert.strictEqual((yield* send(submit(packedFor(""), {}), { signature: "v0=00" })).status, 401)
+      assert.strictEqual((yield* send(submit(packed, {}), { signature: "v0=00" })).status, 401)
       yield* dispose
     }))
 })
diff --git a/packages/chat/slack/test/live.test.ts b/packages/chat/slack/test/live.test.ts
index 2f52bc5c989..5cf50c115c4 100644
--- a/packages/chat/slack/test/live.test.ts
+++ b/packages/chat/slack/test/live.test.ts
@@ -7,41 +7,24 @@
  * - `SLACK_LIVE_USER_TOKEN`: a user token with `chat:write` and
  *   `channels:history`, for the rules that need another identity's
  *   message. Without it those rules fail at `userPosts`.
- * - `SLACK_LIVE_RECIPIENT`: a user id in the channel, the recipient of the
- *   mention rule's streams when `SLACK_LIVE_USER_TOKEN` is not set.
  */
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import * as SlackWebApi from "@effect/chat-slack/SlackWebApi"
-import { assert, describe, it } from "@effect/vitest"
+import { describe, it } from "@effect/vitest"
 import * as Chat from "effect/chat/Chat"
-import type { ChatError } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
 import { conformance } from "effect/chat/ChatTest"
 import type * as ChatThread from "effect/chat/ChatThread"
-import * as Duration from "effect/Duration"
 import * as Effect from "effect/Effect"
 import * as FetchHttpClient from "effect/http/FetchHttpClient"
 import * as Layer from "effect/Layer"
 import * as Redacted from "effect/Redacted"
 import * as Semaphore from "effect/Semaphore"
-import { adapter } from "./utils.ts"
 
 const botToken = process.env.SLACK_LIVE_BOT_TOKEN
 const userToken = process.env.SLACK_LIVE_USER_TOKEN
 const teamId = process.env.SLACK_LIVE_TEAM_ID
 const channel = process.env.SLACK_LIVE_CHANNEL
-const recipientId = process.env.SLACK_LIVE_RECIPIENT
-
-/** Runs a write again after Slack's retry-after, for the rules that make many. */
-const retrying = (effect: Effect.Effect): Effect.Effect =>
-  effect.pipe(Effect.catchIf(
-    (error) => error.reason._tag === "RateLimited",
-    (error) =>
-      Effect.andThen(
-        Effect.sleep(error.reason._tag === "RateLimited" ? error.reason.retryAfter ?? Duration.seconds(30) : 0),
-        retrying(effect)
-      )
-  ))
 
 const field = (u: unknown, key: string): any =>
   typeof u === "object" && u !== null && !Array.isArray(u) ? (u as Record)[key] : undefined
@@ -101,192 +84,3 @@ describe.skipIf(botToken === undefined || teamId === undefined || channel === un
     it.live(name, () => rule.pipe(Effect.provide(layer), Semaphore.withPermits(one, 1)), 600_000)
   }
 })
-
-/**
- * The Slack mention rule, live. It posts and edits mention-looking strings,
- * in prose and in code, with the entity forms and ``, reads each
- * message back and asserts the stored `text` holds no intact token. With
- * `notify` allowed it asserts the token is in `text` and the element is in
- * the blocks.
- *
- * It is a proxy: Slack decides a mention from the stored `text`, which was
- * checked against one client's Activity feed (EFF-3730, EFF-3736). It also
- * makes a file post and a file-only post, and asserts each holds its file
- * after the attach. It streams token shapes split at every position, across
- * two appends and across the start and an append. It reads each stream back
- * while it is open and asserts it holds no token that isn't allowed, and,
- * split across appends, every allowed one. Once stopped, no U+200B is left.
- * The stream needs a recipient, the identity of `SLACK_LIVE_USER_TOKEN` or
- * `SLACK_LIVE_RECIPIENT`. The same assertions run in CI on the request
- * bodies, in `text.test.ts` and `SlackChat.test.ts`.
- */
-describe.skipIf(botToken === undefined || teamId === undefined || channel === undefined)("live mention rule", () => {
-  const layer = SlackChat.layer({ botToken: Redacted.make(botToken!), teamId: teamId! }).pipe(
-    Layer.provideMerge(Chat.layer),
-    Layer.provide(FetchHttpClient.layer)
-  )
-  const token = /<(?:@[UW][A-Z0-9]+|#[CG][A-Z0-9]+|!subteam\^[A-Z0-9]+|!(?:here|channel|everyone))(?:\|[^<>]*)?>/g
-
-  it.live("no token is stored unless allowed, by post and by edit", () =>
-    Effect.gen(function*() {
-      const api = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) })
-      const self = field(yield* api.call("auth.test", {}), "user_id") as string
-      const slack = yield* adapter
-      const thread = SlackChat.thread({ team: teamId!, channel: channel! })
-      const stored = (ts: string) =>
-        api.call("conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 1 }).pipe(
-          Effect.map((answer) => (field(answer, "messages") as Array).find((message) => message.ts === ts))
-        )
-      const elements = (blocks: unknown): Array =>
-        Array.isArray(blocks) ? blocks.flatMap((block) => [block, ...elements(field(block, "elements"))]) : []
-      const inputs = [
-        `prose <@${self}> and  and `,
-        `inline \`<@${self}>\` and a fence\n\`\`\`\n<@${self}> \n\`\`\``,
-        `entities <@${self}> <@${self}> <@${self}> <@${self}> <!channel>`,
-        `no semicolon <@${self}> <@${self}> <@${self}>`,
-        `an unclosed fence\n\`\`\`\n<@${self}>`,
-        `nested \`\`a \` <@${self}> \`\` backticks`
-      ]
-      const posted: Array = []
-      const noToken = Effect.fnUntraced(function*(ts: string, label: string) {
-        const message = yield* stored(ts)
-        assert.deepStrictEqual(message.text.match(token), null, label)
-      })
-      for (const markdown of inputs) {
-        const post = yield* slack.post(thread, { markdown })
-        posted.push(post.id)
-        yield* noToken(post.id, `post ${markdown}`)
-      }
-      const edited = yield* slack.post(thread, { markdown: "to be edited" })
-      posted.push(edited.id)
-      for (const markdown of inputs) {
-        yield* slack.edit(thread, edited.id, { markdown })
-        yield* noToken(edited.id, `edit ${markdown}`)
-      }
-
-      // Allowed: the token is in text and the element in the blocks, by post
-      // and by a long edit whose text is cut.
-      const allowed = SlackChat.withPostOptions({ notify: { users: [self] } })
-      const check = Effect.fnUntraced(function*(ts: string, label: string) {
-        const message = yield* stored(ts)
-        assert.include(message.text, `<@${self}>`, label)
-        assert.isTrue(
-          elements(message.blocks).some((element) => element.type === "user" && element.user_id === self),
-          label
-        )
-      })
-      const allowedPost = yield* slack.post(thread, { markdown: `allowed <@${self}>` }).pipe(allowed)
-      posted.push(allowedPost.id)
-      yield* check(allowedPost.id, "post")
-      yield* slack.edit(thread, allowedPost.id, { markdown: "x".repeat(6_000) + ` <@${self}>` }).pipe(allowed)
-      yield* check(allowedPost.id, "long edit")
-
-      // A file post and a file-only post: the files are attached, and no
-      // token is stored, in the Markdown or in a file name.
-      const fileIds: Array = []
-      const withFile = Effect.fnUntraced(function*(markdown: string, name: string, label: string) {
-        const post = yield* slack.post(thread, {
-          markdown,
-          files: [{ name, contentType: "text/plain", content: new TextEncoder().encode(label) }]
-        })
-        posted.push(post.id)
-        const message = yield* stored(post.id)
-        const files: Array = message.files ?? []
-        fileIds.push(...files.map((file) => file.id))
-        assert.strictEqual(files.length, 1, label)
-        assert.deepStrictEqual(message.text.match(token), null, label)
-        return message
-      })
-      yield* withFile(inputs[1], "file.txt", "file post")
-      const fileOnly = yield* withFile("", `<@${self}>.txt`, "file-only post")
-      assert.strictEqual(fileOnly.text, `<@${self}>.txt`)
-
-      for (const id of posted) yield* slack.delete(thread, id).pipe(Effect.ignore)
-      // `delete` keeps a message's files.
-      for (const file of fileIds) yield* api.call("files.delete", { file }, { write: true }).pipe(Effect.ignore)
-    }).pipe(Effect.provide(layer), Effect.provide(FetchHttpClient.layer)), 600_000)
-
-  it.live(
-    "a stream split at every position stores only allowed tokens and leaves no U+200B",
-    () =>
-      Effect.gen(function*() {
-        const api = yield* SlackWebApi.make({ botToken: Redacted.make(botToken!) })
-        const self = field(yield* api.call("auth.test", {}), "user_id") as string
-        const recipient = userToken === undefined
-          ? recipientId
-          : field(
-            yield* (yield* SlackWebApi.make({ botToken: Redacted.make(userToken) })).call("auth.test", {}),
-            "user_id"
-          )
-        if (recipient === undefined) {
-          return yield* Effect.die(new Error("set SLACK_LIVE_USER_TOKEN or SLACK_LIVE_RECIPIENT"))
-        }
-        const slack = yield* adapter
-        const native = slack.nativeStream!
-        const root = yield* Effect.acquireRelease(
-          slack.post(SlackChat.thread({ team: teamId!, channel: channel! }), { markdown: "streams" }),
-          (root) =>
-            retrying(slack.delete(SlackChat.thread({ team: teamId!, channel: channel! }), root.id)).pipe(Effect.ignore)
-        )
-        const thread = SlackChat.thread({ team: teamId!, channel: channel!, threadTs: root.id })
-        const stored = (ts: string) =>
-          api.call("conversations.replies", { channel, ts, latest: ts, oldest: ts, inclusive: true, limit: 2 }).pipe(
-            Effect.map((answer) => (field(answer, "messages") as Array).find((message) => message.ts === ts))
-          )
-        const none: ReadonlyArray = []
-        const inputs: ReadonlyArray]> = [
-          [`<@${self}>`, none],
-          [`<@${self}>`, [self]],
-          [`<@${self}|hello world>`, [self]],
-          [`<@${self}>`, none],
-          [`<@${self}>`, none],
-          [`<!here>`, none],
-          [`<@${self}>`, none],
-          [`<@${self}>`, none],
-          [`\`\``, none],
-          // Without the semicolon nothing decodes.
-          [`<@${self}> <@${self}>`, none]
-        ]
-        const tokens = (text: string) => text.match(token) ?? []
-        const streamed = Effect.fnUntraced(function*(
-          markdown: string,
-          users: ReadonlyArray,
-          at: number,
-          across: "appends" | "start"
-        ) {
-          const label = `${JSON.stringify(markdown)} at ${at} across ${across} allowing ${users}`
-          const allowed = (found: string) => users.some((id) => found.startsWith(`<@${id}`))
-          const first = markdown.slice(0, at)
-          const { id } = yield* Effect.acquireRelease(
-            retrying(native.start(thread, { markdown: across === "start" ? "s " + first : "s ", recipient })),
-            ({ id }) => retrying(slack.delete(thread, id)).pipe(Effect.ignore)
-          )
-          if (across === "start") {
-            yield* retrying(native.append(thread, id, markdown.slice(at), { flush: true }))
-          } else {
-            const { held } = yield* retrying(native.append(thread, id, first, undefined))
-            yield* retrying(
-              native.append(thread, id, first.slice(first.length - held) + markdown.slice(at), { flush: true })
-            )
-          }
-          // What the stream stored, which is what Slack decided mentions from.
-          const open = (yield* stored(id)).text as string
-          assert.deepStrictEqual(tokens(open).filter((found) => !allowed(found)), [], label)
-          // Held text keeps an allowed token whole. The start holds nothing, so it may break one.
-          if (across === "appends") assert.strictEqual(tokens(open).length, users.length, label)
-          yield* retrying(native.stop(thread, id, { end: "done" }))
-          const message = yield* stored(id)
-          assert.deepStrictEqual(tokens(message.text).filter((found) => !allowed(found)), [], label)
-          assert.notInclude(JSON.stringify([message.text, message.blocks]), "\u200B", label)
-        }, (effect, _markdown, users) =>
-          SlackChat.withPostOptions({ notify: { users } })(effect), Effect.scoped)
-        for (const [markdown, users] of inputs) {
-          for (let at = 0; at <= markdown.length; at++) {
-            yield* streamed(markdown, users, at, "appends")
-            yield* streamed(markdown, users, at, "start")
-          }
-        }
-      }).pipe(Effect.scoped, Effect.provide(layer), Effect.provide(FetchHttpClient.layer)),
-    7_200_000
-  )
-})
diff --git a/packages/chat/slack/test/normalize.test.ts b/packages/chat/slack/test/normalize.test.ts
index 10cc4856239..1b56a6ead89 100644
--- a/packages/chat/slack/test/normalize.test.ts
+++ b/packages/chat/slack/test/normalize.test.ts
@@ -1,10 +1,9 @@
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import { assert, describe, it } from "@effect/vitest"
 import type * as ChatEvent from "effect/chat/ChatEvent"
-import { dedupeKey } from "effect/chat/ChatEvent"
-import { checkEvent, checkMessage } from "effect/chat/ChatTest"
+import { checkEvent } from "effect/chat/ChatTest"
 import * as Effect from "effect/Effect"
-import { botUserId, channel, checkOptions, fixture, messageEnvelope, recordedMessages, team } from "./utils.ts"
+import { botUserId, checkOptions, fixture, messageEnvelope, team } from "./utils.ts"
 
 const context = { teamId: team, botUserId }
 
@@ -15,267 +14,109 @@ const created = (events: ReadonlyArray): ChatEvent.MessageC
   return event
 }
 
-/**
- * A `message` and an `app_mention` envelope built from one read-back message,
- * checked as a pair. This shows the two shapes normalise alike for every
- * recorded message. It is not a captured pair: those are in `events.test.ts`.
- */
-const pair = Effect.fnUntraced(function*(
-  message: Record,
-  options?: { readonly channel?: string; readonly channelType?: string }
-) {
-  const fromMessage = created(SlackChat.normalize(messageEnvelope(message, options), context))
-  yield* checkEvent(fromMessage, checkOptions)
-  if (message.edited !== undefined) {
-    // An edit reuses the id of a message already delivered.
-    assert.deepStrictEqual(
-      SlackChat.normalize(messageEnvelope(message, { ...options, type: "app_mention" }), context),
-      []
-    )
-    return fromMessage
-  }
-  const fromMention = created(
-    SlackChat.normalize(messageEnvelope(message, { ...options, type: "app_mention" }), context)
-  )
-  yield* checkEvent(fromMention, checkOptions)
-  assert.strictEqual(dedupeKey(fromMessage), dedupeKey(fromMention))
-  const { raw: _a, ...left } = fromMessage.message
-  const { raw: _b, ...right } = fromMention.message
-  assert.deepStrictEqual(left, right)
-  assert.deepStrictEqual(fromMessage.thread, fromMention.thread)
-  return fromMessage
-})
-
-describe("normalize", () => {
-  it.effect("every recorded message passes checkMessage as a pair", () =>
-    Effect.gen(function*() {
-      const names = [
-        "markdown-mentions",
-        "me-message",
-        "thread-broadcast",
-        "thread-root-before-after",
-        "file-share",
-        "stream",
-        "unfurl-edit"
-      ]
-      let count = 0
-      for (const name of names) {
-        for (const message of recordedMessages(name).values()) {
-          const event = yield* pair(message)
-          yield* checkMessage(event.message, checkOptions)
-          count++
-        }
-      }
-      assert.isAbove(count, 10)
-    }))
+const normalize = (message: Record, options?: Parameters[1]) =>
+  created(SlackChat.normalize(messageEnvelope(message, options), context))
 
-  it.effect("mentions come from rich_text, not from code in text", () =>
-    Effect.gen(function*() {
-      const message = recordedMessages("markdown-mentions").get("1794509003.143939")
-      const event = yield* pair(message)
-      assert.deepStrictEqual(
-        event.message.mentions.map(({ id, isSelf, kind }) => ({ kind, id, isSelf })),
-        [{ kind: "user", id: botUserId, isSelf: true }, { kind: "channel", id: channel, isSelf: false }]
-      )
-      const [user] = event.message.mentions
-      assert.strictEqual(event.message.text.slice(user.start, user.end), `<@${botUserId}>`)
-      assert.isBelow(user.start, event.message.text.indexOf("Inline code"))
-    }))
+const section = (
+  elements: Array
+) => [{ type: "rich_text", elements: [{ type: "rich_text_section", elements }] }]
 
+describe("normalize", () => {
   it.effect("without rich_text, text is scanned outside code", () =>
     Effect.gen(function*() {
-      const event = created(SlackChat.normalize(
-        messageEnvelope({
-          ts: "1794509003.000001",
-          user: "U080YLYB277",
-          text: "hey <@U0CCLMD4S1L> `<@U999>` and "
-        }),
-        context
-      ))
+      const event = normalize({
+        ts: "1794509003.000001",
+        user: "U080YLYB277",
+        text: "hey <@U0CCLMD4S1L> `<@U999>` and "
+      })
       yield* checkEvent(event, checkOptions)
       assert.deepStrictEqual(event.message.mentions.map((mention) => mention.id), [botUserId, "here"])
       assert.isTrue(event.message.mentions[0].isSelf)
-      assert.isFalse(event.message.author.isSelf)
     }))
 
   it.effect("text never adds a mention the rich_text block lacks", () =>
     Effect.gen(function*() {
-      const section = (
-        elements: Array
-      ) => [{ type: "rich_text", elements: [{ type: "rich_text_section", elements }] }]
       // Block items: literal U1, real U1, real U2, literal bot.
-      const event = created(SlackChat.normalize(
-        messageEnvelope({
-          ts: "1794509003.000002",
-          user: "U080YLYB277",
-          text: `<@U1AAAA> <@U2BBBB> <@${botUserId}>`,
-          blocks: section([
-            { type: "text", text: "<@U1AAAA>" },
-            { type: "user", user_id: "U1AAAA" },
-            { type: "text", text: " " },
-            { type: "user", user_id: "U2BBBB" },
-            { type: "text", text: ` <@${botUserId}>` }
-          ])
-        }),
-        context
-      ))
+      const event = normalize({
+        ts: "1794509003.000002",
+        user: "U080YLYB277",
+        text: `<@U1AAAA> <@U2BBBB> <@${botUserId}>`,
+        blocks: section([
+          { type: "text", text: "<@U1AAAA>" },
+          { type: "user", user_id: "U1AAAA" },
+          { type: "text", text: " " },
+          { type: "user", user_id: "U2BBBB" },
+          { type: "text", text: ` <@${botUserId}>` }
+        ])
+      })
       yield* checkEvent(event, checkOptions)
       assert.deepStrictEqual(
         event.message.mentions.map(({ id, isSelf, start }) => ({ id, isSelf, start })),
         [{ id: "U1AAAA", isSelf: false, start: 0 }, { id: "U2BBBB", isSelf: false, start: 10 }]
       )
-      // Two real U1 in the block and one token in text: one mention, at the token.
-      const short = created(SlackChat.normalize(
-        messageEnvelope({
-          ts: "1794509003.000003",
-          user: "U080YLYB277",
-          text: `hi <@U1AAAA> <@${botUserId}>`,
-          blocks: section([
-            { type: "user", user_id: "U1AAAA" },
-            { type: "user", user_id: "U1AAAA" },
-            { type: "text", text: ` <@${botUserId}>` }
-          ])
-        }),
-        context
-      ))
-      assert.deepStrictEqual(
-        short.message.mentions.map(({ id, start }) => ({ id, start })),
-        [{ id: "U1AAAA", start: 3 }]
-      )
     }))
 
   it.effect("a real mention with no token in text, past a literal, ends", () =>
     Effect.gen(function*() {
       // Block items: real U1, literal U9, real U2. Text has only U1.
-      const event = created(SlackChat.normalize(
-        messageEnvelope({
-          ts: "1794509003.000004",
-          user: "U080YLYB277",
-          text: "<@U1AAAA>",
-          blocks: [{
-            type: "rich_text",
-            elements: [{
-              type: "rich_text_section",
-              elements: [
-                { type: "user", user_id: "U1AAAA" },
-                { type: "text", text: " <@U9ZZZZ> " },
-                { type: "user", user_id: "U2BBBB" }
-              ]
-            }]
-          }]
-        }),
-        context
-      ))
+      const event = normalize({
+        ts: "1794509003.000004",
+        user: "U080YLYB277",
+        text: "<@U1AAAA>",
+        blocks: section([
+          { type: "user", user_id: "U1AAAA" },
+          { type: "text", text: " <@U9ZZZZ> " },
+          { type: "user", user_id: "U2BBBB" }
+        ])
+      })
       yield* checkEvent(event, checkOptions)
-      assert.deepStrictEqual(
-        event.message.mentions.map(({ id, start }) => ({ id, start })),
-        [{ id: "U1AAAA", start: 0 }]
-      )
+      assert.deepStrictEqual(event.message.mentions.map(({ id, start }) => ({ id, start })), [{
+        id: "U1AAAA",
+        start: 0
+      }])
     }))
 
-  it.effect("files are attachments, with an id and no URL", () =>
-    Effect.gen(function*() {
-      const reply = recordedMessages("file-share").get("1794509028.831169")
-      const event = yield* pair(reply)
-      assert.strictEqual(event.message.attachments.length, 1)
-      assert.deepStrictEqual(event.message.attachments[0], {
-        id: "F0CH6RHTMRU",
-        name: "fixture.txt",
-        contentType: "text/plain",
-        size: 51
-      })
-    }))
+  it("files are attachments, with an id and no URL", () => {
+    const reply = fixture("file-share").calls.flatMap((call) => call.response?.messages ?? [])
+      .find((message: any) => message.ts === "1794509028.831169")
+    assert.deepStrictEqual(normalize(reply).message.attachments, [{
+      id: "F0CH6RHTMRU",
+      name: "fixture.txt",
+      contentType: "text/plain",
+      size: 51
+    }])
+  })
 
-  it.effect("a D channel is a direct", () =>
-    Effect.gen(function*() {
-      const event = yield* pair(
-        { ts: "1794509003.000002", user: "U080YLYB277", text: "hi" },
-        { channel: "D0CCGDG0E75" }
-      )
-      assert.strictEqual(event.kind, "direct")
-      const group = yield* pair(
-        { ts: "1794509003.000003", user: "U080YLYB277", text: "hi" },
-        { channel: "C0GROUP", channelType: "mpim" }
-      )
-      assert.strictEqual(group.kind, "direct")
-    }))
+  it("a D or mpim channel is a direct", () => {
+    const message = { ts: "1794509003.000002", user: "U080YLYB277", text: "hi" }
+    assert.strictEqual(normalize(message, { channel: "D0CCGDG0E75" }).kind, "direct")
+    assert.strictEqual(normalize(message, { channel: "C0GROUP", channelType: "mpim" }).kind, "direct")
+  })
 
-  it.effect("a bot_message's author is its bot_id", () =>
-    Effect.gen(function*() {
-      const event = yield* pair({
-        ts: "1794509003.000004",
-        subtype: "bot_message",
-        bot_id: "B0WEBHOOK",
-        username: "incoming-webhook",
-        text: "deploy done <@U0CCLMD4S1L>"
-      })
-      assert.deepStrictEqual(event.message.author, {
-        id: "B0WEBHOOK",
-        name: "incoming-webhook",
-        isBot: true,
-        isSelf: false
-      })
-    }))
+  it("a bot_message's author is its bot_id", () => {
+    const event = normalize({
+      ts: "1794509003.000004",
+      subtype: "bot_message",
+      bot_id: "B0WEBHOOK",
+      username: "incoming-webhook",
+      text: "deploy done <@U0CCLMD4S1L>"
+    })
+    assert.deepStrictEqual(event.message.author, {
+      id: "B0WEBHOOK",
+      name: "incoming-webhook",
+      isBot: true,
+      isSelf: false
+    })
+  })
 
-  it("drops other subtypes, other workspaces and other types", () => {
+  it("drops other subtypes and other workspaces", () => {
     const message = { ts: "1794509003.000005", user: "U080YLYB277", text: "<@U0CCLMD4S1L>" }
     assert.deepStrictEqual(SlackChat.normalize(messageEnvelope({ ...message, subtype: "channel_join" }), context), [])
     assert.deepStrictEqual(SlackChat.normalize(messageEnvelope(message, { teamId: "T0OTHER" }), context), [])
-    assert.deepStrictEqual(SlackChat.normalize({ type: "url_verification", challenge: "x" }, context), [])
-    assert.deepStrictEqual(SlackChat.normalize(null, context), [])
   })
 
   it("drops the verification token from raw", () => {
-    const event = created(SlackChat.normalize(
-      messageEnvelope({ ts: "1794509003.000006", user: "U080YLYB277", text: "hi" }),
-      context
-    ))
+    const event = normalize({ ts: "1794509003.000006", user: "U080YLYB277", text: "hi" })
     assert.isFalse("token" in (event.raw as object))
   })
 })
-
-describe("reactions", () => {
-  const reaction = (name: string) => ({
-    team_id: team,
-    api_app_id: "A0CCHBHDK7X",
-    type: "event_callback",
-    event_id: "Ev02",
-    event_time: 1794509100,
-    event: {
-      type: "reaction_added",
-      user: "U080YLYB277",
-      reaction: name,
-      item_user: botUserId,
-      item: { type: "message", channel, ts: "1794509003.143939" },
-      event_ts: "1794509100.000100"
-    }
-  })
-
-  it.effect("a name with two tones is a custom emoji, on the reacted message's author", () =>
-    Effect.gen(function*() {
-      // No recording has a two-tone reaction, so its name is not resolved
-      // (stage 0 fixture 16).
-      const [event] = SlackChat.normalize(reaction("handshake::skin-tone-2::skin-tone-5"), context)
-      assert(event._tag === "ReactionAdded")
-      assert.strictEqual(event.emoji, "custom:handshake::skin-tone-2::skin-tone-5")
-      assert.strictEqual(event.messageAuthorId, botUserId)
-      assert.deepStrictEqual(event.thread, SlackChat.thread({ team, channel }))
-      yield* checkEvent(event, checkOptions)
-    }))
-})
-
-describe("agent_session_stopped", () => {
-  it.effect("a stop in a direct message", () =>
-    Effect.gen(function*() {
-      const envelope = fixture("agent-session-stopped").cases.direct
-      const [event] = SlackChat.normalize(envelope, context)
-      assert(event._tag === "StopRequested")
-      yield* checkEvent(event, checkOptions)
-      assert.deepStrictEqual(
-        event.thread,
-        SlackChat.thread({ team, channel: "D0CCGDG0E75", threadTs: envelope.event.thread_ts })
-      )
-      assert.deepStrictEqual(event.messageIds, ["1794454526.283939"])
-      assert.strictEqual(event.userId, "U080YLYB277")
-    }))
-})
diff --git a/packages/chat/slack/test/richText.test.ts b/packages/chat/slack/test/richText.test.ts
index fdcb4a0ee3f..8a90710a987 100644
--- a/packages/chat/slack/test/richText.test.ts
+++ b/packages/chat/slack/test/richText.test.ts
@@ -18,18 +18,11 @@ const read = Effect.fnUntraced(function*(message: Record) {
   return event.message
 })
 
-/** A message a recorded read returned, by ts, edited or not. */
-const recorded = (name: string, ts: string, edited = false): Record => {
-  for (const call of fixture(name).calls) {
-    for (const message of call.response?.messages ?? []) {
-      if (message.ts === ts && (message.edited !== undefined) === edited) return message
-    }
-  }
-  throw new Error(`no message ${ts} in ${name}`)
-}
+/** A message a recorded read returned, by ts. */
+const recorded = (name: string, ts: string): Record =>
+  fixture(name).calls.flatMap((call) => call.response?.messages ?? []).find((message: any) => message.ts === ts)
 
 const synthetic: {
-  readonly synthetic: string
   readonly cases: ReadonlyArray<{ readonly name: string; readonly markdown: string; readonly message: any }>
 } = JSON.parse(fs.readFileSync(new URL("./fixtures/synthetic/own-messages.json", import.meta.url), "utf8"))
 
@@ -39,18 +32,13 @@ describe("the bot's own messages read back", () => {
       // The fixture posted raw markdown_text with `<not a tag>` typed
       // as entities. Through the adapter the same message is ``.
       const mentionsPost = fixture("markdown-mentions").calls[0].request.markdown_text as string
-      const cases: ReadonlyArray = [
-        ["thread-root-before-after", "1794509000.352789", "Fixture: thread root (no mentions). Some *markdown* here."],
+      const cases: ReadonlyArray = [
         ["markdown-mentions", "1794509003.143939", mentionsPost.replace("<not a tag>", "")],
-        ["thread-broadcast", "1794509004.811879", `Fixture: broadcast reply to <@${botUserId}>`],
-        ["file-share", "1794509028.831169", `Fixture: file for <@${botUserId}>`],
         // Two appends.
-        ["stream", "1794509111.134189", `Streaming **part one**. Part two with <@${botUserId}>.`],
-        ["unfurl-edit", "1794509128.969019", "now with a link: https://github.com/Effect-TS/effect", true],
-        ["unfurl-edit", "1794509129.029199", "Fixture control: https://github.com/Effect-TS/effect"]
+        ["stream", "1794509111.134189", `Streaming **part one**. Part two with <@${botUserId}>.`]
       ]
-      for (const [name, ts, markdown, edited] of cases) {
-        const message = recorded(name, ts, edited)
+      for (const [name, ts, markdown] of cases) {
+        const message = recorded(name, ts)
         const read_ = yield* read(message)
         assert.strictEqual(read_.text, markdown, name)
         // Slack's own field stays on raw.
@@ -60,18 +48,8 @@ describe("the bot's own messages read back", () => {
       assert.notStrictEqual(recorded("markdown-mentions", "1794509003.143939").text, mentionsPost)
     }))
 
-  it.effect("an agent DM thread root", () =>
-    Effect.gen(function*() {
-      const stored = recorded("assistant-thread-root", "1794454526.171439")
-      assert.isDefined(stored.agent_session)
-      const message = yield* read(stored)
-      assert.strictEqual(message.text, stored.text)
-      assert.isTrue(message.author.isSelf)
-    }))
-
   it.effect("give the Markdown they were posted with, from synthetic messages", () =>
     Effect.gen(function*() {
-      assert.match(synthetic.synthetic, /^Hand-written, not read back from Slack/)
       for (const { markdown, message, name } of synthetic.cases) {
         assert.strictEqual((yield* read(message)).text, markdown, name)
       }
diff --git a/packages/chat/slack/test/slack.ts b/packages/chat/slack/test/slack.ts
index 61be506b452..0d17e552e32 100644
--- a/packages/chat/slack/test/slack.ts
+++ b/packages/chat/slack/test/slack.ts
@@ -9,16 +9,17 @@ const tim = "U080YLYB277"
  * A Slack that keeps the messages the adapter posts, with their blocks, and
  * records every view it opens. `interactions` is the conformance hook: it
  * builds Slack's `block_actions` and `view_submission` payloads from what
- * was posted and opened, and a slash command's form fields, sends them
- * through `SlackChat.interaction` and keeps the answers. A command's
- * `response_url` answers `ok`.
+ * was posted and opened, and a slash command's form fields, and sends them
+ * through `SlackChat.interaction`. A command's
+ * `response_url` answers `ok`. `refuseFiles` makes the next file upload
+ * fail.
  */
 export const makeSlack = () => {
   const messages = new Map()
   const views: Array = []
-  const answers: Array = []
   let next = 1794600000
   let viewCount = 0
+  let refuse = false
 
   const fake = makeFake({
     "auth.test": authTest,
@@ -55,6 +56,13 @@ export const makeSlack = () => {
       views.push(view)
       return { ok: true, view }
     },
+    "conversations.history": (params) => ({
+      ok: true,
+      messages: [...messages.values()].filter((message) => message.channel === params.channel).reverse()
+    }),
+    "files.getUploadURLExternal": { ok: true, upload_url: "https://files.slack.test/upload/F1", file_id: "F1" },
+    "files.completeUploadExternal": () =>
+      refuse ? { ok: false, error: "invalid_arguments" } : { ok: true, files: [{ id: "F1" }] },
     "response_url": { status: 200, body: "ok" }
   })
 
@@ -64,11 +72,8 @@ export const makeSlack = () => {
   /** The service the hook delivers through, set by `bind`. */
   let service: SlackChat.SlackChat["Service"] | undefined
 
-  const deliver = Effect.fnUntraced(function*(payload: Record) {
-    const answer = yield* service!.interaction({ ...payload, token: "verification", api_app_id: appId })
-    answers.push(answer)
-    return answer
-  })
+  const deliver = (payload: Record) =>
+    service!.interaction({ ...payload, token: "verification", api_app_id: appId })
 
   const user = { id: tim, username: "tim", name: "tim", team_id: team }
 
@@ -146,9 +151,10 @@ export const makeSlack = () => {
       Effect.sync(() => {
         service = slack
       })),
-    messages,
-    views,
-    answers,
-    interactions
+    interactions,
+    refuseFiles: () =>
+      Effect.sync(() => {
+        refuse = true
+      })
   }
 }
diff --git a/packages/chat/slack/test/utils.ts b/packages/chat/slack/test/utils.ts
index ff29a51e0aa..c70b5d1d8fb 100644
--- a/packages/chat/slack/test/utils.ts
+++ b/packages/chat/slack/test/utils.ts
@@ -17,7 +17,7 @@ export const channel = "C0CH1LGJ4F3"
 
 export const checkOptions = { platform: "slack", parseMention: SlackChat.parseMention }
 
-export interface RecordedCall {
+interface RecordedCall {
   readonly method: string
   readonly label?: string
   readonly request: Record
@@ -27,16 +27,6 @@ export interface RecordedCall {
 export const fixture = (name: string): { readonly calls: ReadonlyArray; readonly [key: string]: any } =>
   JSON.parse(fs.readFileSync(new URL(`./fixtures/recorded/${name}.json`, import.meta.url), "utf8"))
 
-/** Every message object a fixture's reads returned, by ts. */
-export const recordedMessages = (name: string): Map => {
-  const out = new Map()
-  for (const call of fixture(name).calls) {
-    const messages = call.response?.messages
-    if (Array.isArray(messages)) { for (const message of messages) out.set(message.ts, message) }
-  }
-  return out
-}
-
 /**
  * An `event_callback` envelope built around a message as a Web API read
  * returned it. Reconstructed, not delivered by Slack: the captured
@@ -73,7 +63,7 @@ export interface FakeCall {
   readonly params: Record
 }
 
-export type Answer =
+type Answer =
   | Record
   | { readonly status: number; readonly headers?: Record; readonly body?: unknown }
   | typeof hang
diff --git a/packages/chat/slack/test/webhook.test.ts b/packages/chat/slack/test/webhook.test.ts
index 3e0e6eb778a..d5a36574036 100644
--- a/packages/chat/slack/test/webhook.test.ts
+++ b/packages/chat/slack/test/webhook.test.ts
@@ -1,4 +1,4 @@
-import { handleRequest, makeVerifier, type Options, unavailable as logged } from "@effect/chat-slack/internal/webhook"
+import { handleRequest, makeVerifier, type Options } from "@effect/chat-slack/internal/webhook"
 import * as SlackChat from "@effect/chat-slack/SlackChat"
 import * as NodeCrypto from "@effect/platform-node/NodeCrypto"
 import { assert, describe, it } from "@effect/vitest"
@@ -15,7 +15,6 @@ import * as HttpRouter from "effect/http/HttpRouter"
 import * as HttpServerRequest from "effect/http/HttpServerRequest"
 import * as HttpServerResponse from "effect/http/HttpServerResponse"
 import * as Layer from "effect/Layer"
-import * as Logger from "effect/Logger"
 import * as Redacted from "effect/Redacted"
 import { TestClock } from "effect/testing"
 import { appId, authTest, botUserId, makeFake, messageEnvelope, team } from "./utils.ts"
@@ -74,18 +73,6 @@ const handle = Effect.fnUntraced(function*(options: Partial, web: Reque
   return { status: response.status, response, events }
 })
 
-/** Runs `effect` and gives back what it logged: each entry's level and arguments. */
-const withLogs = (effect: Effect.Effect) => {
-  const logs: Array<{ readonly level: string; readonly message: ReadonlyArray }> = []
-  const logger = Logger.make((options) => {
-    logs.push({
-      level: options.logLevel,
-      message: Array.isArray(options.message) ? options.message : [options.message]
-    })
-  })
-  return Effect.map(Effect.provide(effect, Logger.layer([logger])), (value) => ({ value, logs }))
-}
-
 describe("webhook", () => {
   it.live("rejects a bad, stale or missing signature", () =>
     Effect.gen(function*() {
@@ -97,20 +84,16 @@ describe("webhook", () => {
       assert.strictEqual(old.status, 401)
       const unsigned = yield* handle({}, new Request("http://localhost/", { method: "POST", body }))
       assert.strictEqual(unsigned.status, 401)
-      for (const signature of ["00", "v0=0", "v0=gg", "v0=00"]) {
-        const web = yield* Effect.promise(() => request(body))
-        web.headers.set("x-slack-signature", signature)
-        assert.strictEqual((yield* handle({}, web)).status, 401)
-      }
+      const malformed = yield* Effect.promise(() => request(body))
+      malformed.headers.set("x-slack-signature", "v0=gg")
+      assert.strictEqual((yield* handle({}, malformed)).status, 401)
       assert.strictEqual(wrongKey.events.length + old.events.length + unsigned.events.length, 0)
     }))
 
-  it.live("413 past the body limit, 400 for a body that is not JSON", () =>
+  it.live("413 past the body limit", () =>
     Effect.gen(function*() {
       const big = yield* handle({ maxBodyBytes: 100 }, yield* Effect.promise(() => request("x".repeat(101))))
       assert.strictEqual(big.status, 413)
-      const notJson = yield* handle({}, yield* Effect.promise(() => request("not json")))
-      assert.strictEqual(notJson.status, 400)
     }))
 
   it.live("answers url_verification with its challenge", () =>
@@ -139,21 +122,14 @@ describe("webhook", () => {
       assert.strictEqual(result.events.length, 0)
     }))
 
-  it.live("503 so Slack retries, logged with what caused it: no bot user, NotAccepted, past the deadline", () =>
+  it.live("503 so Slack retries: no bot user, NotAccepted, past the deadline", () =>
     Effect.gen(function*() {
-      const body = JSON.stringify(message)
-      const web = Effect.promise(() => request(body))
-      const noBot = yield* withLogs(handle({ botUserId: Effect.fail(unavailable) }, yield* web))
-      const refused = yield* withLogs(handle({ handle: () => Effect.fail(new NotAccepted()) }, yield* web))
-      const slow = yield* withLogs(handle({ handle: () => Effect.never, deadline: Duration.millis(20) }, yield* web))
-      const fine = yield* withLogs(handle({}, yield* web))
-      assert.deepStrictEqual([noBot, refused, slow, fine].map(({ value }) => value.status), [503, 503, 503, 200])
-      // The unreadable bot user carries the ChatError that says why.
-      assert.deepStrictEqual(noBot.logs, [{ level: "Error", message: [logged.botUser, unavailable] }])
-      assert.deepStrictEqual(refused.logs, [{ level: "Warn", message: [logged.notAccepted] }])
-      assert.deepStrictEqual(slow.logs, [{ level: "Warn", message: [logged.deadline] }])
-      assert.deepStrictEqual(fine.logs, [])
-      assert.strictEqual(noBot.value.events.length, 0)
+      const web = Effect.promise(() => request(JSON.stringify(message)))
+      const noBot = yield* handle({ botUserId: Effect.fail(unavailable) }, yield* web)
+      const refused = yield* handle({ handle: () => Effect.fail(new NotAccepted()) }, yield* web)
+      const slow = yield* handle({ handle: () => Effect.never, deadline: Duration.millis(20) }, yield* web)
+      assert.deepStrictEqual([noBot, refused, slow].map(({ status }) => status), [503, 503, 503])
+      assert.strictEqual(noBot.events.length, 0)
     }))
 
   it.live("the deadline covers the bot user lookup", () =>
@@ -213,12 +189,9 @@ describe("webhook", () => {
       const mac = Layer.succeed(Mac.Mac, {
         generateKey: () => Effect.die("unused"),
         sign: () => Effect.die("unused"),
-        verify: Effect.fnUntraced(function*(key, tag, data) {
+        verify: (key) => {
           assert.strictEqual(key.algorithm, Mac.hmacSha256)
-          assert.deepStrictEqual(tag, new Uint8Array([0xab, 0xcd]))
-          assert.strictEqual(new TextDecoder().decode(yield* Mac.toBytes(key)), secret)
-          assert.strictEqual(new TextDecoder().decode(data).split(":").slice(2).join(":"), JSON.stringify(message))
-          return yield* fail
+          return fail
             ? Effect.fail(
               new CryptoError.CryptoError({
                 module: "Mac",
@@ -227,7 +200,7 @@ describe("webhook", () => {
               })
             )
             : Effect.succeed(true)
-        })
+        }
       })
       const app = SlackChat.layerWebhook({ path: "/slack/events", signingSecret: Redacted.make(secret), appId }).pipe(
         Layer.provide(SlackChat.layer({ botToken: Redacted.make("xoxb-test"), teamId: team })),
@@ -248,6 +221,5 @@ describe("webhook", () => {
       yield* Effect.promise(() => dispose())
       assert.strictEqual(response.status, 200)
       assert.strictEqual(events.length, 1)
-      assert.strictEqual(fake.called("auth.test").length, 1)
     }))
 })
diff --git a/packages/chat/teams/test/download.test.ts b/packages/chat/teams/test/download.test.ts
index 524c318282f..3ccbe1f4eb0 100644
--- a/packages/chat/teams/test/download.test.ts
+++ b/packages/chat/teams/test/download.test.ts
@@ -53,7 +53,7 @@ describe("download", () => {
       assert.deepStrictEqual(sent, [{ url: connectorUrl, authorization: "Bearer secret", redirect: "manual" }])
     }))
 
-  it.effect("refuses a redirect off the allowlist and sends the token on the first hop only", () =>
+  it.effect("sends the token on the first hop only, and never to an untrusted URL", () =>
     Effect.gen(function*() {
       const { http, sent } = serve((url) =>
         new Response(null, {
@@ -61,23 +61,18 @@ describe("download", () => {
           headers: { location: url === connectorUrl ? "https://cdn.example.com/file" : "https://evil.example/file" }
         })
       )
-      const reason = yield* reasonOf(Download.download(`connector:${connectorUrl}`, options(http)))
-      assert.strictEqual(reason._tag, "Forbidden")
-      assert.strictEqual(reason.detail, "untrusted_url")
+      const redirected = yield* reasonOf(Download.download(`connector:${connectorUrl}`, options(http)))
+      assert.deepStrictEqual([redirected._tag, redirected.detail], ["Forbidden", "untrusted_url"])
       assert.deepStrictEqual(sent.map((request) => [request.url, request.authorization]), [
         [connectorUrl, "Bearer secret"],
         ["https://cdn.example.com/file", undefined]
       ])
-    }))
 
-  it.effect("never sends the token to a redirect host named as the first hop", () =>
-    Effect.gen(function*() {
-      const { http, sent } = serve(() => new Response("hello"))
+      // A redirect host named as the first hop.
       const id = "connector:https://cdn.example.com/v3/attachments/a/views/original"
-      const reason = yield* reasonOf(Download.download(id, options(http)))
-      assert.strictEqual(reason._tag, "Forbidden")
-      assert.strictEqual(reason.detail, "untrusted_url")
-      assert.deepStrictEqual(sent, [])
+      const first = yield* reasonOf(Download.download(id, options(http)))
+      assert.deepStrictEqual([first._tag, first.detail], ["Forbidden", "untrusted_url"])
+      assert.strictEqual(sent.length, 2)
     }))
 
   it.effect("fails TooLarge past maxBytes", () =>
diff --git a/packages/chat/teams/test/envelope.test.ts b/packages/chat/teams/test/envelope.test.ts
index fcaa1780ecc..d68724a43e6 100644
--- a/packages/chat/teams/test/envelope.test.ts
+++ b/packages/chat/teams/test/envelope.test.ts
@@ -18,15 +18,7 @@ const options = { appId: "app-1", tenantId: "tenant-1" }
 const conversation = "19:abc@thread.tacv2"
 
 describe("envelope", () => {
-  it.effect("round trips a button, from any message of the conversation", () =>
-    Effect.gen(function*() {
-      const envelope = yield* Envelope.make({ ...options, keys: [k1] })
-      const token = yield* envelope.signButton(conversation, { id: "approve", value: "42" })
-      const verified = yield* envelope.verifyButton(token, { conversationId: `${conversation};messageid=123` })
-      assert.deepStrictEqual(verified, Option.some({ id: "approve", value: "42" }))
-    }).pipe(Effect.provide(layer)))
-
-  it.effect("refuses another conversation, a tampered token and an unknown kid", () =>
+  it.effect("refuses a button from another conversation, a tampered token and an unknown kid", () =>
     Effect.gen(function*() {
       const envelope = yield* Envelope.make({ ...options, keys: [k1] })
       const token = yield* envelope.signButton(conversation, { id: "approve" })
@@ -44,17 +36,7 @@ describe("envelope", () => {
       assert.isTrue(Option.isSome(yield* rotated.verifyButton(token, { conversationId: conversation })))
     }).pipe(Effect.provide(layer)))
 
-  it.effect("buttonTokenLength is the length of the signed token", () =>
-    Effect.gen(function*() {
-      const envelope = yield* Envelope.make({ ...options, keys: [k1] })
-      for (const button of [{ id: "a" }, { id: "pick", value: "caf\u00e9 \"quoted\" \u{1F600}" }]) {
-        const token = yield* envelope.signButton(conversation, button)
-        assert.strictEqual(Envelope.buttonTokenLength({ ...options, kid: "k1" }, button), token.length)
-        assert.isTrue(token.length <= Envelope.maxTokenLength)
-      }
-    }).pipe(Effect.provide(layer)))
-
-  it.effect("round trips a dialog and checks its submit against the definition", () =>
+  it.effect("binds a dialog to its user and reply chain, and a submit to its definition", () =>
     Effect.gen(function*() {
       const envelope = yield* Envelope.make({ ...options, keys: [k1] })
       const modal: ChatUi.Modal = {
@@ -75,7 +57,6 @@ describe("envelope", () => {
       assert.isTrue(Option.isNone(yield* envelope.verifyDialog(token, { conversationId: moved, userId: "u1" })))
       const verified = yield* envelope.verifyDialog(token, { conversationId: opened, userId: "u1" })
       assert.deepStrictEqual(verified, Option.some({ conversationId: opened, messageId: "123", modal }))
-      assert.isTrue(token.length <= Envelope.maxTokenLength)
       assert.deepStrictEqual(
         Envelope.validateSubmission(modal, { effect: token, env: "prod", note: "" }),
         Option.some({ env: "prod" })
diff --git a/packages/chat/teams/test/interactions.test.ts b/packages/chat/teams/test/interactions.test.ts
deleted file mode 100644
index fcf36e0c3e7..00000000000
--- a/packages/chat/teams/test/interactions.test.ts
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * Dialog invokes, called directly with a recording handler: where a submit
- * says it came from, what an error reply shows, and what counts against the
- * modal cap.
- */
-import { modalMetadataLength } from "@effect/chat-teams/internal/adapter"
-import * as Envelope from "@effect/chat-teams/internal/envelope"
-import * as Interactions from "@effect/chat-teams/internal/interactions"
-import * as TeamsChat from "@effect/chat-teams/TeamsChat"
-import { assert, describe, it } from "@effect/vitest"
-import type { ChatError } from "effect/chat/ChatError"
-import * as ChatInteraction from "effect/chat/ChatInteraction"
-import type * as ChatUi from "effect/chat/ChatUi"
-import { Digest, Mac, SecureRandom } from "effect/crypto"
-import * as Duration from "effect/Duration"
-import * as Effect from "effect/Effect"
-import * as Layer from "effect/Layer"
-import * as Redacted from "effect/Redacted"
-import type * as Schema from "effect/Schema"
-
-const crypto = Layer.mergeAll(Digest.layerWebCrypto, Mac.layerWebCrypto).pipe(
-  Layer.provideMerge(SecureRandom.layerWebCrypto)
-)
-
-const key = Redacted.make({ kty: "oct", kid: "k1", k: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc" } as const)
-const appId = "00000000-0000-0000-0000-0000000000a1"
-const tenantId = "00000000-0000-0000-0000-0000000000b2"
-const channel = "19:abc@thread.tacv2"
-const from = { id: "29:user", aadObjectId: "user" }
-
-const modal: ChatUi.Modal = {
-  _tag: "Modal",
-  id: "deploy",
-  title: "Deploy",
-  elements: [
-    { _tag: "TextInput", id: "constructor", label: "Name", initial: "first" },
-    { _tag: "TextInput", id: "note", label: "Note", initial: "draft" }
-  ]
-}
-
-const setup = Effect.fnUntraced(function*(open: ChatUi.Modal) {
-  const envelope = yield* Envelope.make({ appId, tenantId, keys: [key] })
-  const submits: Array = []
-  const refusals: Array = []
-  const handler = ChatInteraction.Handler.of({
-    click: () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: open })),
-    submit: (event) => {
-      submits.push(event)
-      return Effect.succeed(ChatInteraction.errors({ note: "Too short" }))
-    },
-    command: () => Effect.succeed(ChatInteraction.ack),
-    refused: (_, error) => Effect.sync(() => void refusals.push(error))
-  })
-  const options: Interactions.Options = {
-    capabilities: new Set(["buttons", "modals", "modalErrors"]),
-    envelope,
-    modalButtons: new Set(["open"]),
-    answer: () => Effect.die("unused"),
-    deadline: Duration.seconds(1)
-  }
-  const invoke = (activity: Record) =>
-    Interactions.invoke(activity, options).pipe(Effect.provideService(ChatInteraction.Handler, handler))
-  // A click on a card posted as a channel post: the root of its own reply chain.
-  const clicked = `${channel};messageid=123`
-  const button = yield* envelope.signButton(channel, { id: "open" })
-  const opened = yield* invoke({
-    type: "invoke",
-    name: "task/fetch",
-    from,
-    conversation: { id: clicked },
-    replyToId: "123",
-    value: { data: { effect: button } }
-  })
-  const dialogToken = (body: unknown): string | undefined =>
-    (body as any)?.task?.value?.card?.content?.actions?.[0]?.data?.effect
-  const submit = (conversationId: string, values: Record) =>
-    invoke({
-      type: "invoke",
-      name: "task/submit",
-      from,
-      conversation: { id: conversationId },
-      value: { data: { effect: dialogToken(opened.body) ?? null, ...values } }
-    })
-  return { clicked, opened, submit, submits, refusals }
-})
-
-describe("dialogs", () => {
-  it.effect("a submit keeps the thread and message of the click, and from no other reply chain", () =>
-    Effect.gen(function*() {
-      const { clicked, submit, submits } = yield* setup(modal)
-      const moved = yield* submit(`${channel};messageid=456`, { constructor: "a", note: "b" })
-      assert.strictEqual(moved.status, 200)
-      assert.strictEqual(submits.length, 0)
-
-      yield* submit(clicked, { constructor: "a", note: "b" })
-      assert.strictEqual(submits.length, 1)
-      assert.deepStrictEqual(submits[0].thread, TeamsChat.thread(channel))
-      assert.strictEqual(submits[0].messageId, "123")
-    }).pipe(Effect.provide(crypto)))
-
-  it.effect("an error reply keeps what the user entered, and reads no inherited key", () =>
-    Effect.gen(function*() {
-      const { clicked, submit } = yield* setup(modal)
-      const reply = yield* submit(clicked, { constructor: "edited", note: "b" })
-      const body = (reply.body as any).task.value.card.content.body as ReadonlyArray
-      const inputs = body.filter((element) => element.type === "Input.Text")
-      assert.deepStrictEqual(inputs.map((input) => input.value), ["edited", "b"])
-      const texts = body.filter((element) => element.type === "TextBlock").map((element) => element.text)
-      assert.deepStrictEqual(texts, ["Too short"])
-    }).pipe(Effect.provide(crypto)))
-
-  it.effect("counts the metadata's signed envelope against modalMetadataLength", () =>
-    Effect.gen(function*() {
-      // The raw id and metadata fit the cap; with the envelope they do not.
-      const metadata = "m".repeat(modalMetadataLength - modal.id.length)
-      const { opened, refusals } = yield* setup({ ...modal, metadata })
-      assert.notStrictEqual((opened.body as any)?.task?.type, "continue")
-      assert.strictEqual(refusals[0]?.reason._tag, "TooLarge")
-    }).pipe(Effect.provide(crypto)))
-})
diff --git a/packages/chat/teams/test/length.test.ts b/packages/chat/teams/test/length.test.ts
index 3604b720404..98f899081bb 100644
--- a/packages/chat/teams/test/length.test.ts
+++ b/packages/chat/teams/test/length.test.ts
@@ -1,54 +1,37 @@
 import * as Length from "@effect/chat-teams/internal/length"
 import * as Render from "@effect/chat-teams/internal/render"
-import { describe, expect, it } from "@effect/vitest"
+import { assert, describe, it } from "@effect/vitest"
 import type * as ChatUi from "effect/chat/ChatUi"
 
-const tokenLength = (button: { readonly id: string; readonly value?: string | undefined }) =>
-  20 + button.id.length + (button.value?.length ?? 0)
-const encode = (button: ChatUi.Button) => "t".repeat(tokenLength(button))
-const measure = Length.makeMeasure(tokenLength)
-
-const actions: ReadonlyArray = [
-  { _tag: "Button", id: "approve", label: "Yes & ", style: "danger", value: "v" },
-  { _tag: "LinkButton", label: "Docs", url: "https://example.com/?a=1&b=<2>" }
-]
-
-const fits = (
-  markdown: string,
-  actions: ReadonlyArray,
-  opensDialog?: (button: ChatUi.Button) => boolean
-) =>
-  expect(JSON.stringify(Render.cardActivity(markdown, actions, encode, opensDialog)).length).toBeLessThanOrEqual(
-    measure(markdown, actions) + Length.R
-  )
-
-describe("measure", () => {
-  it("bounds a fence pair", () => fits(["```\nx\n", "```\np\n\nq\n\nr"].join(""), actions))
-
-  it("bounds nested block syntax on one line", () => fits("> - # x", actions))
-
-  it("bounds a table", () => fits("| a | b |\n| - | - |\n| c | d |", actions))
-
-  it("bounds a card without actions", () => {
-    const markdown = "# Title\n\nsome *text* & \n\n```ts\nconst x = 1\n```"
-    fits(markdown, [])
-    expect(measure(markdown, [])).toBe(measure(markdown))
+describe("render", () => {
+  it("measure bounds each serialised form", () => {
+    const tokenLength = (button: { readonly id: string; readonly value?: string | undefined }) =>
+      20 + button.id.length + (button.value?.length ?? 0)
+    const measure = Length.makeMeasure(tokenLength)
+    const actions: ReadonlyArray = [
+      { _tag: "Button", id: "approve", label: "Yes & ", style: "danger", value: "v" },
+      { _tag: "LinkButton", label: "Docs", url: "https://example.com/?a=1&b=<2>" }
+    ]
+    const cards: ReadonlyArray<
+      readonly [string, ReadonlyArray, ((button: ChatUi.Button) => boolean)?]
+    > = [
+      ["```\nx\n```\np\n\nq\n\nr", actions],
+      ["> - # x", actions],
+      ["| a | b |\n| - | - |\n| c | d |", actions],
+      // A dialog button's label with lone surrogates.
+      ["x", [{ _tag: "Button", id: "open", label: "\uD800".repeat(20_000) }], () => true]
+    ]
+    for (const [markdown, actions, opensDialog] of cards) {
+      const card = Render.cardActivity(markdown, actions, (button) => "t".repeat(tokenLength(button)), opensDialog)
+      assert.isAtMost(JSON.stringify(card).length, measure(markdown, actions) + Length.R, markdown)
+    }
+    const dollars = "$".repeat(10_000) + "\\$"
+    assert.isAtMost(JSON.stringify(Render.textActivity(dollars)).length, measure(dollars) + Length.R)
   })
 
-  it("bounds a dialog button whose label has lone surrogates", () => {
-    fits("x", [{ _tag: "Button", id: "open", label: "\uD800".repeat(20_000) }], () => true)
-  })
-
-  it("bounds the text form with its dollar escapes", () => {
-    const markdown = "$".repeat(10_000) + "\\$"
-    expect(JSON.stringify(Render.textActivity(markdown)).length).toBeLessThanOrEqual(measure(markdown) + Length.R)
-  })
-})
-
-describe("textActivity", () => {
   it("escapes each dollar outside code, so Teams reads no math", () => {
     const markdown = "$x$ \\$y \\\\$z `$c$`\n```\n$$\n```\n$"
     const sent = "\\$x\\$ \\$y \\\\\\$z `$c$`\n```\n$$\n```\n\\$"
-    expect(Render.textActivity(markdown).text).toBe(sent)
+    assert.strictEqual(Render.textActivity(markdown).text, sent)
   })
 })
diff --git a/packages/chat/teams/test/webhook.test.ts b/packages/chat/teams/test/webhook.test.ts
index 18acad8ec9d..bc367ba4d8f 100644
--- a/packages/chat/teams/test/webhook.test.ts
+++ b/packages/chat/teams/test/webhook.test.ts
@@ -171,71 +171,94 @@ describe("layerWebhook", () => {
       assert.strictEqual(yield* send(activity(), `Bearer ${yield* token()}`), 503)
       assert.strictEqual(events.length, 0)
     }).pipe(Effect.provide(crypto)))
+})
+
+describe("dialogs through layerWebhook", () => {
+  const interactionKey = Redacted.make(
+    { kty: "oct", kid: "k1", k: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc" } as const
+  )
+  const channel = "19:abc@thread.tacv2"
+  // A click on a card posted as a channel post: the root of its own reply chain.
+  const clicked = `${channel};messageid=123`
+  const modal: ChatUi.Modal = {
+    _tag: "Modal",
+    id: "deploy",
+    title: "Deploy",
+    elements: [
+      { _tag: "TextInput", id: "constructor", label: "Name", initial: "first" },
+      { _tag: "TextInput", id: "note", label: "Note", initial: "draft" }
+    ]
+  }
+
+  const open = Effect.fnUntraced(function*(opens: ChatUi.Modal) {
+    const submits: Array = []
+    const refusals: Array = []
+    const { exchange, token } = yield* setup({
+      teams: { interactionKeys: [interactionKey], modalButtons: ["open"], unverified: { buttons: true, modals: true } },
+      interactions: {
+        click: () => Effect.succeed(ChatInteraction.OpenModal.make({ modal: opens })),
+        submit: (event) =>
+          Effect.sync(() => {
+            submits.push(event)
+            return ChatInteraction.errors({ note: "Too short" })
+          }),
+        command: () => Effect.succeed(ChatInteraction.ack),
+        refused: (_, error) => Effect.sync(() => void refusals.push(error))
+      }
+    })
+    const bearer = `Bearer ${yield* token()}`
+    const invoke = (overrides: Record) =>
+      exchange(
+        activity({
+          type: "invoke",
+          conversation: { id: clicked, conversationType: "channel", tenantId },
+          ...overrides
+        }),
+        bearer
+      ).pipe(Effect.flatMap((response) => Effect.promise((): Promise => response.json())))
+    const envelope = yield* Envelope.make({ appId, tenantId, keys: [interactionKey] })
+    const button = yield* envelope.signButton(channel, { id: "open" })
+    const opened = yield* invoke({ name: "task/fetch", replyToId: "123", value: { data: { effect: button } } })
+    const dialog: string | undefined = opened?.task?.value?.card?.content?.actions?.[0]?.data?.effect
+    const submit = (values: Record) =>
+      invoke({ name: "task/submit", value: { data: { effect: dialog ?? null, ...values } } })
+    return { dialog, refusals, submit, submits }
+  })
 
   it.effect("opens a dialog only when its whole signed token fits modalMetadataLength", () =>
     Effect.gen(function*() {
-      const interactionKey = Redacted.make(
-        { kty: "oct", kid: "k1", k: "BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc" } as const
-      )
       // Short id and no metadata: the definition alone makes the token long.
-      const modal = (text: string): ChatUi.Modal => ({
-        _tag: "Modal",
-        id: "m",
-        title: "Modal",
-        elements: [{ _tag: "Text", text }, { _tag: "TextInput", id: "answer", label: "Answer" }]
-      })
-      const refusals: Array = []
-      const { exchange, token } = yield* setup({
-        teams: {
-          interactionKeys: [interactionKey],
-          modalButtons: ["open"],
-          unverified: { buttons: true, modals: true }
-        },
-        interactions: {
-          click: (event) =>
-            Effect.succeed(ChatInteraction.OpenModal.make({ modal: modal("x".repeat(Number(event.value))) })),
-          submit: () => Effect.succeed(ChatInteraction.close),
-          command: () => Effect.succeed(ChatInteraction.ack),
-          refused: (_, error) => Effect.sync(() => void refusals.push(error))
-        }
-      })
-      const envelope = yield* Envelope.make({ appId, tenantId, keys: [interactionKey] })
-      const bearer = `Bearer ${yield* token()}`
-      const open = Effect.fnUntraced(function*(textLength: number) {
-        const button = yield* envelope.signButton("a:direct", { id: "open", value: String(textLength) })
-        const response = yield* exchange(
-          activity({
-            type: "invoke",
-            name: "task/fetch",
-            replyToId: "1800000000000",
-            value: { data: { effect: button } }
-          }),
-          bearer
-        )
-        const body = yield* Effect.promise(() => response.json())
-        return Schema.is(Schema.Struct({
-            task: Schema.Struct({
-              type: Schema.Literal("continue"),
-              value: Schema.Struct({
-                card: Schema.Struct({
-                  content: Schema.Struct({
-                    actions: Schema.Array(Schema.Struct({ data: Schema.Struct({ effect: Schema.String }) }))
-                  })
-                })
-              })
-            })
-          }))(body)
-          ? body.task.value.card.content.actions[0]?.data.effect
-          : undefined
+      const withText = (length: number): ChatUi.Modal => ({
+        ...modal,
+        elements: [{ _tag: "Text", text: "x".repeat(length) }, ...modal.elements]
       })
+      const big = yield* open(withText(3_500))
+      assert.isUndefined(big.dialog)
+      assert.strictEqual(big.refusals[0]?.reason._tag, "TooLarge")
+
+      const small = yield* open(withText(1_000))
+      assert.isString(small.dialog)
+      assert.isAtMost(small.dialog!.length, modalMetadataLength)
+      assert.strictEqual(small.refusals.length, 0)
+    }).pipe(Effect.provide(crypto)))
 
-      const big = yield* open(3_500)
-      assert.isUndefined(big)
-      assert.strictEqual(refusals[0]?.reason._tag, "TooLarge")
+  it.effect("a submit keeps the thread and message of the click", () =>
+    Effect.gen(function*() {
+      const { submit, submits } = yield* open(modal)
+      yield* submit({ constructor: "a", note: "b" })
+      assert.strictEqual(submits.length, 1)
+      assert.deepStrictEqual(submits[0].thread, TeamsChat.thread(channel))
+      assert.strictEqual(submits[0].messageId, "123")
+    }).pipe(Effect.provide(crypto)))
 
-      const small = yield* open(1_000)
-      assert.isString(small)
-      assert.isAtMost(small!.length, modalMetadataLength)
-      assert.strictEqual(refusals.length, 1)
+  it.effect("an error reply keeps what the user entered, and reads no inherited key", () =>
+    Effect.gen(function*() {
+      const { submit } = yield* open(modal)
+      const reply = yield* submit({ constructor: "edited", note: "b" })
+      const body: ReadonlyArray = reply.task.value.card.content.body
+      const inputs = body.filter((element) => element.type === "Input.Text")
+      assert.deepStrictEqual(inputs.map((input) => input.value), ["edited", "b"])
+      const texts = body.filter((element) => element.type === "TextBlock").map((element) => element.text)
+      assert.deepStrictEqual(texts, ["Too short"])
     }).pipe(Effect.provide(crypto)))
 })
diff --git a/packages/chat/telegram/test/TelegramChat.test.ts b/packages/chat/telegram/test/TelegramChat.test.ts
index f8d74d2bae5..8351fd93894 100644
--- a/packages/chat/telegram/test/TelegramChat.test.ts
+++ b/packages/chat/telegram/test/TelegramChat.test.ts
@@ -1,12 +1,11 @@
 /**
- * The adapter's own guarantees, over a fake Bot API: the token and the
- * webhook secret stay out of errors, spans and logs (T1), the webhook secret
- * (T2), private answers (T5), clicks (T6), excluded contexts (T7) and
- * acceptance (T8).
+ * The adapter's own guarantees, over a fake Bot API, that the conformance
+ * suite does not see: credentials stay out of errors, spans and logs, the
+ * webhook's answers, private answers, clicks, excluded contexts, delivery
+ * keys, polling and deadlines.
  */
 import * as TelegramChat from "@effect/chat-telegram/TelegramChat"
 import { assert, describe, it } from "@effect/vitest"
-import * as Cause from "effect/Cause"
 import * as Chat from "effect/chat/Chat"
 import type { ChatError } from "effect/chat/ChatError"
 import type * as ChatEvent from "effect/chat/ChatEvent"
@@ -24,7 +23,6 @@ import * as Logger from "effect/Logger"
 import * as Option from "effect/Option"
 import * as Redacted from "effect/Redacted"
 import type * as Schema from "effect/Schema"
-import * as Semaphore from "effect/Semaphore"
 import * as TestClock from "effect/testing/TestClock"
 import * as Tracer from "effect/Tracer"
 import {
@@ -39,16 +37,16 @@ import {
   messageUpdate,
   telegramLayer,
   thread,
-  token,
-  unverified
+  token
 } from "./utils.ts"
 
 const secret = "s".repeat(32)
 
 /** What reached the consumer, by kind. */
 const makeRecorder = (options?: {
-  readonly command?: (event: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply
-  readonly refuse?: boolean
+  readonly command?: () => Effect.Effect
+  readonly click?: Effect.Effect
+  readonly handle?: Effect.Effect
 }) => {
   const events: Array = []
   const clicks: Array = []
@@ -56,13 +54,16 @@ const makeRecorder = (options?: {
   const refused: Array = []
   const unhandled: Array = []
   const handler = ChatHandler.of({
-    handle: (event) =>
-      options?.refuse === true ? Effect.fail(new NotAccepted({})) : Effect.sync(() => void events.push(event))
+    handle: (event) => options?.handle ?? Effect.sync(() => void events.push(event))
   })
   const interactions = ChatInteraction.Handler.of({
-    click: (event) => Effect.sync(() => (clicks.push(event), ChatInteraction.ack)),
+    click: (event) => Effect.as(options?.click ?? Effect.sync(() => void clicks.push(event)), ChatInteraction.ack),
     submit: () => Effect.succeed(ChatInteraction.close),
-    command: (event) => Effect.sync(() => (commands.push(event), options?.command?.(event) ?? ChatInteraction.ack)),
+    command: (event) =>
+      Effect.andThen(
+        Effect.sync(() => void commands.push(event)),
+        options?.command?.() ?? Effect.succeed(ChatInteraction.ack)
+      ),
     refused: (_, error) => Effect.sync(() => void refused.push(error))
   })
   const onUnhandled = (update: Schema.Json) => Effect.sync(() => void unhandled.push(update))
@@ -86,176 +87,141 @@ const receive = (api: FakeApi, recorder: Recorder, ...updates: ReadonlyArray
-  commandUpdate(name, "", { message_id: 0, ephemeral_message_id: ephemeralId })
+const spanTracer = () => {
+  const spans: Array = []
+  const tracer = Tracer.make({
+    span(options) {
+      const span = new Tracer.NativeSpan(options)
+      spans.push(span)
+      return span
+    }
+  })
+  return { spans, tracer }
+}
 
-describe("credentials", () => {
-  it.effect("keeps the token out of errors, spans and logs", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      const spans: Array = []
-      const logs: Array = []
-      const tracer = Tracer.make({
-        span(options) {
-          const span = new Tracer.NativeSpan(options)
-          spans.push(span)
-          return span
-        }
-      })
-      const logger = Logger.formatJson.pipe(Logger.map((line): void => void logs.push(line)))
-      api.next.set("sendRichMessage", apiError(401, "Unauthorized"))
-      const exit = yield* Effect.flatMap(Chat.Chat, (chat) => chat.post(thread, { markdown: "hi" })).pipe(
-        Effect.tapCause((cause) => Effect.logError("post failed", cause)),
-        Effect.exit,
-        Effect.provide(telegramLayer(api)),
-        Effect.provide(Logger.layer([logger])),
-        Effect.provideService(Tracer.Tracer, tracer)
-      )
-      assert.isTrue(Exit.isFailure(exit))
-      const seen = [
-        Exit.isFailure(exit) ? Cause.pretty(exit.cause) : "",
-        JSON.stringify(exit),
-        ...logs,
-        ...spans.map((span) => JSON.stringify([span.name, [...span.attributes], span.events]))
-      ].join("\n")
-      assert.isTrue(spans.some((span) => span.name === "TelegramBotApi.sendRichMessage"))
-      assert.isTrue(seen.includes("/bot/sendRichMessage"))
-      assert.isFalse(seen.includes(token))
-      assert.isFalse(seen.includes(token.split(":")[1]))
-    }))
+/** What makes a message private: id 0, with its own private id. */
+const ephemeral = { message_id: 0, ephemeral_message_id: 7 }
 
-  it.effect("refuses a token without a bot id", () =>
-    Effect.gen(function*() {
-      const exit = yield* Layer.build(
-        TelegramChat.layer({ token: Redacted.make("not-a-token") }).pipe(
-          Layer.provide(Chat.layer),
-          Layer.provide(makeApi().layer)
-        )
-      ).pipe(Effect.scoped, Effect.exit)
-      assert.isTrue(Exit.isFailure(exit))
-      assert.isFalse(JSON.stringify(exit).includes("not-a-token"))
-    }))
+/** A click on `data`, on a message whose keyboard has one `approve` button. */
+const click = (data: string, date = 1_800_000_000) =>
+  callbackUpdate({
+    message_id: 5,
+    date,
+    chat: { id: chatId, type: "supergroup" },
+    text: "x",
+    reply_markup: { inline_keyboard: [[{ text: "Yes", callback_data: "approve" }]] }
+  }, data)
+
+/** Yields until `done` holds. */
+const until = Effect.fnUntraced(function*(done: () => boolean) {
+  while (!done()) yield* Effect.yieldNow
 })
 
-const webhook = Effect.fnUntraced(function*(
-  api: FakeApi,
-  recorder: Recorder,
-  server: Layer.Layer = Layer.empty
-) {
-  const app = TelegramChat.layerWebhook({
-    path: "/telegram",
-    secretToken: Redacted.make(secret),
-    maxBodyBytes: 4096,
-    onUnhandled: recorder.onUnhandled
-  }).pipe(
-    Layer.provide(telegramLayer(api)),
-    Layer.provide(Layer.succeed(ChatHandler, recorder.handler)),
-    Layer.provideMerge(server)
-  )
-  const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true })
-  yield* Effect.addFinalizer(() => Effect.promise(() => dispose()))
-  return (body: string, header?: string, headers?: Record) =>
-    Effect.promise(() =>
-      handler(
-        new Request("http://localhost/telegram", {
-          method: "POST",
-          body,
-          headers: {
-            "content-type": "application/json",
-            ...headers,
-            ...(header === undefined ? {} : { [TelegramChat.secretHeader]: header })
-          }
-        })
+it.effect("keeps the token out of errors, spans and logs", () =>
+  Effect.gen(function*() {
+    const api = makeApi()
+    const { spans, tracer } = spanTracer()
+    const logs: Array = []
+    const logger = Logger.formatJson.pipe(Logger.map((line): void => void logs.push(line)))
+    api.next.set("sendRichMessage", apiError(401, "Unauthorized"))
+    const exit = yield* Effect.flatMap(Chat.Chat, (chat) => chat.post(thread, { markdown: "hi" })).pipe(
+      Effect.tapCause((cause) => Effect.logError("post failed", cause)),
+      Effect.exit,
+      Effect.provide(telegramLayer(api)),
+      Effect.provide(Logger.layer([logger])),
+      Effect.provideService(Tracer.Tracer, tracer)
+    )
+    assert.isTrue(Exit.isFailure(exit))
+    assert.isTrue(spans.some((span) => span.name === "TelegramBotApi.sendRichMessage"))
+    const seen = [
+      JSON.stringify(exit),
+      ...logs,
+      ...spans.map((span) => JSON.stringify([span.name, [...span.attributes], span.events]))
+    ].join("\n")
+    assert.isFalse(seen.includes(token.split(":")[1]))
+  }))
+
+it.effect("maps the rich message errors captured in live check 10", () =>
+  Effect.gen(function*() {
+    const captured: ReadonlyArray = [
+      ["RICH_MESSAGE_TOO_LARGE", "TooLarge", "message_too_large"],
+      ["RICH_MESSAGE_DEPTH_INVALID", "InvalidRequest", "too_deep"]
+    ]
+    for (const [description, tag, detail] of captured) {
+      const api = makeApi()
+      api.next.set("sendRichMessage", apiError(400, `Bad Request: ${description}`))
+      const error = yield* Effect.flatMap(Chat.Chat, (chat) => chat.post(thread, { markdown: "hi" })).pipe(
+        Effect.flip,
+        Effect.provide(telegramLayer(api))
       )
-    ).pipe(Effect.map((response) => response.status))
-})
+      assert.deepStrictEqual([error.reason._tag, (error.reason as { readonly detail?: string }).detail], [tag, detail])
+    }
+  }))
 
-describe("errors", () => {
-  it.effect("maps the rich message errors captured in live check 10", () =>
-    Effect.gen(function*() {
-      const captured: ReadonlyArray = [
-        ["RICH_MESSAGE_TEXT_TOO_LONG", "TooLarge", "message_too_long"],
-        ["RICH_MESSAGE_TOO_LARGE", "TooLarge", "message_too_large"],
-        ["RICH_MESSAGE_BLOCKS_TOO_MANY", "TooLarge", "too_many_blocks"],
-        ["RICH_MESSAGE_DEPTH_INVALID", "InvalidRequest", "too_deep"],
-        ["RICH_MESSAGE_TABLE_COLS_TOO_MANY", "InvalidRequest", "too_many_columns"],
-        ["RICH_MESSAGE_EMPTY", "InvalidRequest", "empty_message"],
-        ["RICH_MESSAGE_MARKDOWN_INVALID", "InvalidRequest", "invalid_markdown"]
-      ]
-      for (const [description, tag, detail] of captured) {
-        const api = makeApi()
-        api.next.set("sendRichMessage", apiError(400, `Bad Request: ${description}`))
-        const error = yield* Effect.flatMap(Chat.Chat, (chat) => chat.post(thread, { markdown: "hi" })).pipe(
-          Effect.flip,
-          Effect.provide(telegramLayer(api))
+describe("layerWebhook", () => {
+  const webhook = Effect.fnUntraced(function*(recorder: Recorder, server: Layer.Layer = Layer.empty) {
+    const app = TelegramChat.layerWebhook({ path: "/telegram", secretToken: Redacted.make(secret), maxBodyBytes: 4096 })
+      .pipe(
+        Layer.provide(telegramLayer(makeApi())),
+        Layer.provide(Layer.succeed(ChatHandler, recorder.handler)),
+        Layer.provideMerge(server)
+      )
+    const { dispose, handler } = HttpRouter.toWebHandler(app, { disableLogger: true })
+    yield* Effect.addFinalizer(() => Effect.promise(() => dispose()))
+    return (body: string, header?: string) =>
+      Effect.promise(() =>
+        handler(
+          new Request("http://localhost/telegram", {
+            method: "POST",
+            body,
+            headers: header === undefined ? {} : { [TelegramChat.secretHeader]: header }
+          })
         )
-        assert.strictEqual(error.reason._tag, tag, description)
-        assert.strictEqual("detail" in error.reason ? error.reason.detail : undefined, detail, description)
-      }
-    }))
-})
+      ).pipe(Effect.map((response) => response.status))
+  })
+  const update = JSON.stringify(messageUpdate({ text: "hi" }))
 
-describe("layerWebhook", () => {
-  it.effect("needs the secret, then answers for the body and the outcome", () =>
+  it.effect("needs the secret, then answers for the body", () =>
     Effect.gen(function*() {
-      const api = makeApi()
       const recorder = makeRecorder()
-      const send = yield* webhook(api, recorder)
-      const body = JSON.stringify(messageUpdate({ text: "hi" }))
-      assert.strictEqual(yield* send(body), 401)
-      assert.strictEqual(yield* send(body, "s".repeat(31)), 401)
-      assert.strictEqual(yield* send(body, "t".repeat(32)), 401)
+      const send = yield* webhook(recorder)
+      assert.strictEqual(yield* send(update), 401)
+      assert.strictEqual(yield* send(update, "t".repeat(32)), 401)
       assert.strictEqual(recorder.events.length, 0)
       assert.strictEqual(yield* send("x".repeat(5000), secret), 413)
       assert.strictEqual(yield* send("{", secret), 400)
       assert.strictEqual(yield* send(JSON.stringify({ message: {} }), secret), 400)
-      assert.strictEqual(yield* send(body, secret), 200)
+      assert.strictEqual(yield* send(update, secret), 200)
       assert.strictEqual(recorder.events.length, 1)
-      assert.strictEqual(yield* send(JSON.stringify({ update_id: 1, poll: {} }), secret), 200)
-      assert.strictEqual(recorder.unhandled.length, 1)
+    }))
+
+  it.effect("answers 503 when the handler does not accept", () =>
+    Effect.gen(function*() {
+      const send = yield* webhook(makeRecorder({ handle: Effect.fail(new NotAccepted({})) }))
+      assert.strictEqual(yield* send(update, secret), 503)
     }))
 
   it.effect("keeps the secret out of server spans that capture every header, set up as the README says", () =>
     Effect.gen(function*() {
-      const spans: Array = []
-      const tracer = Tracer.make({
-        span(options) {
-          const span = new Tracer.NativeSpan(options)
-          spans.push(span)
-          return span
-        }
-      })
-      // The README's setup: the names reach the server, and keep the defaults.
+      const { spans, tracer } = spanTracer()
       const RedactSecret = Layer.effect(
         Headers.CurrentRedactedNames,
-        Effect.gen(function*() {
-          return [...yield* Headers.CurrentRedactedNames, TelegramChat.secretHeader]
-        })
+        Effect.map(Headers.CurrentRedactedNames, (names) => [...names, TelegramChat.secretHeader])
       )
-      const server = Layer.mergeAll(
-        RedactSecret,
-        Layer.succeed(HttpMiddleware.TracerHeaderFilter, () => true),
-        Layer.succeed(Tracer.Tracer, tracer)
+      const send = yield* webhook(
+        makeRecorder(),
+        Layer.mergeAll(
+          RedactSecret,
+          Layer.succeed(HttpMiddleware.TracerHeaderFilter, () => true),
+          Layer.succeed(Tracer.Tracer, tracer)
+        )
       )
-      const send = yield* webhook(makeApi(), makeRecorder(), server)
-      const status = yield* send(JSON.stringify(messageUpdate({ text: "hi" })), secret, {
-        authorization: "Bearer marker"
-      })
-      assert.strictEqual(status, 200)
+      assert.strictEqual(yield* send(update, secret), 200)
       const attributes = new Map(spans.find((span) => span.kind === "server")?.attributes)
       assert.strictEqual(attributes.get("http.request.header.x-telegram-bot-api-secret-token"), "")
-      assert.strictEqual(attributes.get("http.request.header.authorization"), "")
-      assert.strictEqual(attributes.get("http.request.header.content-type"), "application/json")
       assert.isFalse(JSON.stringify(spans.map((span) => [...span.attributes])).includes(secret))
     }))
 
-  it.effect("answers 503 when the handler does not accept", () =>
-    Effect.gen(function*() {
-      const send = yield* webhook(makeApi(), makeRecorder({ refuse: true }))
-      assert.strictEqual(yield* send(JSON.stringify(messageUpdate({ text: "hi" })), secret), 503)
-    }))
-
   it.effect("refuses a short secret", () =>
     Effect.gen(function*() {
       const app = TelegramChat.layerWebhook({ path: "/telegram", secretToken: Redacted.make("short") }).pipe(
@@ -263,20 +229,19 @@ describe("layerWebhook", () => {
         Layer.provide(Layer.succeed(ChatHandler, makeRecorder().handler)),
         Layer.provide(HttpRouter.layer)
       )
-      const exit = yield* Layer.build(app).pipe(Effect.scoped, Effect.exit)
-      assert.isTrue(Exit.isFailure(exit))
+      assert.isTrue(Exit.isFailure(yield* Layer.build(app).pipe(Effect.scoped, Effect.exit)))
     }))
 })
 
-describe("private answers", () => {
+describe("private messages", () => {
+  const command = commandUpdate("deploy", "", ephemeral)
+
   it.effect("refuses an ephemeral answer and never posts it", () =>
     Effect.gen(function*() {
       const api = makeApi()
-      const recorder = makeRecorder({ command: () => ChatInteraction.respond({ markdown: "secret" }) })
-      const outcomes = yield* receive(api, recorder, commandUpdate("deploy"), ephemeralCommand("deploy", 7))
-      assert.deepStrictEqual(outcomes, ["accepted", "accepted"])
-      assert.strictEqual(recorder.commands.length, 2)
-      assert.deepStrictEqual(recorder.refused.map((error) => error.reason._tag), ["Unsupported", "Unsupported"])
+      const recorder = makeRecorder({ command: () => Effect.succeed(ChatInteraction.respond({ markdown: "secret" })) })
+      assert.deepStrictEqual(yield* receive(api, recorder, command), ["accepted"])
+      assert.deepStrictEqual(recorder.refused.map((error) => error.reason._tag), ["Unsupported"])
       assert.strictEqual(api.sent("sendRichMessage").length, 0)
       assert.strictEqual(recorder.events.length + recorder.unhandled.length, 0)
     }))
@@ -285,275 +250,105 @@ describe("private answers", () => {
     Effect.gen(function*() {
       const api = makeApi()
       const recorder = makeRecorder({
-        command: () => ChatInteraction.respond({ markdown: "done", visibility: "public" })
+        command: () => Effect.succeed(ChatInteraction.respond({ markdown: "done", visibility: "public" }))
       })
-      yield* receive(api, recorder, commandUpdate("deploy"), ephemeralCommand("deploy", 7))
-      const [quoted, unquoted] = api.sent("sendRichMessage")
-      assert.isDefined(quoted.reply_parameters)
-      assert.isUndefined(unquoted.reply_parameters)
-      assert.strictEqual(unquoted.chat_id, chatId)
+      yield* receive(api, recorder, command)
+      const [sent] = api.sent("sendRichMessage")
+      assert.strictEqual(sent.chat_id, chatId)
+      assert.isUndefined(sent.reply_parameters)
     }))
 
   it.effect("keeps an ephemeral message that is not a command from every handler", () =>
     Effect.gen(function*() {
-      const api = makeApi()
       const recorder = makeRecorder()
-      yield* receive(api, recorder, messageUpdate({ text: "psst", message_id: 0, ephemeral_message_id: 9 }))
+      yield* receive(makeApi(), recorder, messageUpdate({ text: "psst", ...ephemeral }))
       assert.strictEqual(recorder.events.length + recorder.unhandled.length + recorder.commands.length, 0)
     }))
 })
 
-describe("clicks", () => {
-  const keyboard = { inline_keyboard: [[{ text: "Yes", callback_data: "approve" }]] }
-  const message = (extra?: Record) => ({
-    message_id: 5,
-    date: 1_800_000_000,
-    chat: { id: chatId, type: "supergroup" },
-    text: "x",
-    reply_markup: keyboard,
-    ...extra
-  })
-
-  it.effect("dispatches only data from Telegram's copy of the keyboard, and answers every click", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      const recorder = makeRecorder()
-      yield* receive(
-        api,
-        recorder,
-        callbackUpdate(message(), "approve"),
-        callbackUpdate(message(), "forged"),
-        callbackUpdate(message({ reply_markup: undefined }), "approve"),
-        callbackUpdate(message({ date: 0 }), "approve")
-      )
-      assert.deepStrictEqual(recorder.clicks.map((click) => [click.id, click.messageId]), [["approve", "5"]])
-      assert.strictEqual(api.sent("answerCallbackQuery").length, 4)
-    }))
-})
-
-describe("excluded contexts", () => {
-  it.effect("sends business, channel direct-message and guest updates to onUnhandled", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      const recorder = makeRecorder()
-      const business = { message_id: 3, date: 1, chat: { id: 1, type: "private" }, business_connection_id: "b" }
-      yield* receive(
-        api,
-        recorder,
-        { update_id: 1, business_message: { ...business, text: "hi" } },
-        messageUpdate({ text: "hi", business_connection_id: "b" }),
-        messageUpdate({ text: "hi", chat: { id: chatId, type: "supergroup", is_direct_messages: true } }),
-        messageUpdate({ text: "hi", direct_messages_topic: { topic_id: 1 } }),
-        commandUpdate("deploy", "", { business_connection_id: "b" }),
-        callbackUpdate({ ...business, reply_markup: { inline_keyboard: [[{ text: "a", callback_data: "a" }]] } }, "a"),
-        { update_id: 2, message_reaction: { chat: { id: chatId, type: "supergroup" }, message_id: 1 } }
-      )
-      assert.strictEqual(recorder.unhandled.length, 7)
-      assert.strictEqual(recorder.events.length + recorder.commands.length + recorder.clicks.length, 0)
-      assert.strictEqual(api.sent("answerCallbackQuery").length, 1)
-    }))
-
-  it("gives no event from the normaliser", () => {
-    const update = messageUpdate({ text: "hi", business_connection_id: "b" })
-    assert.deepStrictEqual(TelegramChat.normalize(update, context), [])
-  })
-})
-
-describe("acceptance", () => {
-  it("keys deliveries by bot, update and date, and keeps ephemeral commands apart", () => {
-    const first = ephemeralCommand("deploy", 7)
-    const second = ephemeralCommand("deploy", 8)
-    const key = (raw: unknown) => Option.getOrThrow(TelegramChat.deliveryKey(raw, { botId }))
-    assert.strictEqual(key(first), `${botId}.${first.update_id}.${first.message.date}`)
-    assert.strictEqual(key(structuredClone(first)), key(first))
-    assert.notStrictEqual(key(first), key(second))
-    const test = TelegramChat.deliveryKey(first, { botId, environment: "test" })
-    assert.isTrue(Option.getOrThrow(test).startsWith("test."))
-  })
-
-  it.effect("confirms a polled update only after it ran", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      const recorder = makeRecorder()
-      const first = messageUpdate({ text: "one" })
-      const second = messageUpdate({ text: "two" })
-      api.updates.push([first, second])
-      yield* Layer.build(
-        TelegramChat.layerPolling({ onUnhandled: recorder.onUnhandled }).pipe(
-          Layer.provideMerge(telegramLayer(api, { unverified })),
-          Layer.provide(Layer.succeed(ChatHandler, recorder.handler))
-        )
-      )
-      while (api.sent("getUpdates").length < 2) yield* Effect.yieldNow
-      const [start, next] = api.sent("getUpdates")
-      assert.isUndefined(start.offset)
-      assert.deepStrictEqual(start.allowed_updates, ["message", "channel_post", "callback_query"])
-      assert.strictEqual(next.offset, second.update_id + 1)
-      assert.strictEqual(recorder.events.length, 2)
-    }).pipe(Effect.scoped))
-
-  it.effect("fails to start polling when Telegram answers 409", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      api.next.set("getUpdates", apiError(409, "Conflict: can't use getUpdates method while webhook is active"))
-      const exit = yield* Layer.build(
-        TelegramChat.layerPolling().pipe(
-          Layer.provideMerge(telegramLayer(api)),
-          Layer.provide(Layer.succeed(ChatHandler, makeRecorder().handler))
-        )
-      ).pipe(Effect.scoped, Effect.exit)
-      assert.isTrue(Exit.isFailure(exit))
-      assert.isTrue(Exit.isFailure(exit) && Cause.pretty(exit.cause).includes("conflict"))
-    }))
+it.effect("dispatches only data from Telegram's copy of the keyboard, and answers every click", () =>
+  Effect.gen(function*() {
+    const api = makeApi()
+    const recorder = makeRecorder()
+    // A message Telegram can no longer show the bot comes with date 0.
+    yield* receive(api, recorder, click("approve"), click("forged"), click("approve", 0))
+    assert.deepStrictEqual(recorder.clicks.map((click) => [click.id, click.messageId]), [["approve", "5"]])
+    assert.strictEqual(api.sent("answerCallbackQuery").length, 3)
+  }))
+
+it.effect("sends business and channel direct-message updates to onUnhandled, and answers their clicks", () =>
+  Effect.gen(function*() {
+    const api = makeApi()
+    const recorder = makeRecorder()
+    const business = { message_id: 3, date: 1, chat: { id: 1, type: "private" }, business_connection_id: "b" }
+    yield* receive(
+      api,
+      recorder,
+      messageUpdate({ text: "hi", business_connection_id: "b" }),
+      messageUpdate({ text: "hi", chat: { id: chatId, type: "supergroup", is_direct_messages: true } }),
+      callbackUpdate({ ...business, reply_markup: { inline_keyboard: [[{ text: "a", callback_data: "a" }]] } }, "a")
+    )
+    assert.strictEqual(recorder.unhandled.length, 3)
+    assert.strictEqual(recorder.events.length + recorder.clicks.length, 0)
+    assert.strictEqual(api.sent("answerCallbackQuery").length, 1)
+  }))
+
+it("keys deliveries by bot, update and date, and by environment", () => {
+  const update = messageUpdate({ text: "hi" })
+  const key = (environment?: "test") => Option.getOrThrow(TelegramChat.deliveryKey(update, { botId, environment }))
+  assert.strictEqual(key(), `${botId}.${update.update_id}.${update.message.date}`)
+  assert.strictEqual(key("test"), `test.${key()}`)
 })
 
-/**
- * The README's recipe on an in-memory store. The key and its work item
- * commit together, and an insert waits for the one in flight, as a unique
- * constraint does. `beforeCommit` is where the handler's work can crash.
- */
-const makeRecipe = (beforeCommit: (attempt: number) => Effect.Effect) => {
-  const recorder = makeRecorder()
-  const work = new Map()
-  const log: Array = []
-  const constraint = Semaphore.makeUnsafe(1)
-  let attempts = 0
-  const insert = (raw: Schema.Json, item: string) =>
-    constraint.withPermits(1)(Effect.suspend(() => {
-      const key = Option.getOrThrow(TelegramChat.deliveryKey(raw, { botId }))
-      if (work.has(key)) return Effect.sync(() => void log.push("repeat"))
-      return Effect.andThen(
-        beforeCommit(++attempts),
-        Effect.sync(() => {
-          work.set(key, item)
-          log.push("commit")
-        })
-      )
-    }))
-  const interactions = ChatInteraction.Handler.of({
-    ...recorder.interactions,
-    click: (event) => Effect.as(insert(event.raw, event.id), ChatInteraction.ack),
-    command: (event) => Effect.as(insert(event.raw, event.text), ChatInteraction.defer(event, { visibility: "public" }))
-  })
-  return { ...recorder, interactions, work, log, attempts: () => attempts }
-}
-
-describe("durable acceptance", () => {
-  const blocked = Effect.fnUntraced(function*(recipe: { readonly attempts: () => number }, n: number) {
-    while (recipe.attempts() < n) yield* Effect.yieldNow
-  })
-
-  it.effect("redoes a command that crashed before its commit", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      const recipe = makeRecipe((attempt) => attempt === 1 ? Effect.never : Effect.void)
-      const update = commandUpdate("deploy", "prod")
-      const crashed = yield* Effect.forkChild(receive(api, recipe, update))
-      yield* blocked(recipe, 1)
-      yield* Fiber.interrupt(crashed)
-      assert.strictEqual(recipe.work.size, 0)
-      assert.deepStrictEqual(yield* receive(api, recipe, update), ["accepted"])
-      assert.deepStrictEqual([...recipe.work.values()], ["prod"])
-      assert.strictEqual(recipe.events.length, 0)
-    }))
-
-  it.effect("answers a concurrent repeat only after the first commits", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      const release = yield* Deferred.make()
-      const recipe = makeRecipe(() => Deferred.await(release))
-      const update = commandUpdate("deploy", "prod")
-      const first = yield* Effect.forkChild(receive(api, recipe, update))
-      yield* blocked(recipe, 1)
-      const repeat = yield* Effect.forkChild(
-        Effect.tap(receive(api, recipe, update), () => Effect.sync(() => void recipe.log.push("repeat answered")))
+it.effect("confirms a polled update only after it ran", () =>
+  Effect.gen(function*() {
+    const api = makeApi()
+    const recorder = makeRecorder()
+    const last = messageUpdate({ text: "two" })
+    api.updates.push([messageUpdate({ text: "one" }), last])
+    yield* Layer.build(
+      TelegramChat.layerPolling().pipe(
+        Layer.provideMerge(telegramLayer(api)),
+        Layer.provide(Layer.succeed(ChatHandler, recorder.handler))
       )
-      for (let i = 0; i < 10; i++) yield* Effect.yieldNow
-      assert.deepStrictEqual(recipe.log, [])
-      yield* Deferred.succeed(release, void 0)
-      assert.deepStrictEqual([yield* Fiber.join(first), yield* Fiber.join(repeat)], [["accepted"], ["accepted"]])
-      assert.deepStrictEqual(recipe.log, ["commit", "repeat", "repeat answered"])
-      assert.strictEqual(recipe.work.size, 1)
-      assert.strictEqual(recipe.events.length, 0)
-    }))
-
-  it.effect("answers a repeat after the commit, and never turns a command into a message", () =>
-    Effect.gen(function*() {
-      const api = makeApi()
-      const recipe = makeRecipe(() => Effect.void)
-      const command = commandUpdate("deploy", "prod")
-      const click = callbackUpdate({
-        message_id: 5,
-        date: 1_800_000_000,
-        chat: { id: chatId, type: "supergroup" },
-        text: "x",
-        reply_markup: { inline_keyboard: [[{ text: "Yes", callback_data: "approve" }]] }
-      }, "approve")
-      const outcomes = yield* receive(api, recipe, command, command, click, click)
-      assert.deepStrictEqual(outcomes, ["accepted", "accepted", "accepted", "accepted"])
-      assert.deepStrictEqual(recipe.log, ["commit", "repeat", "commit", "repeat"])
-      assert.strictEqual(recipe.events.length, 0)
-      assert.strictEqual(api.sent("answerCallbackQuery").length, 2)
-    }))
-})
+    )
+    yield* until(() => api.sent("getUpdates").length >= 2)
+    const [start, next] = api.sent("getUpdates")
+    assert.isUndefined(start.offset)
+    assert.strictEqual(next.offset, last.update_id + 1)
+    assert.strictEqual(recorder.events.length, 2)
+  }))
 
 describe("deadlines", () => {
-  const until = Effect.fnUntraced(function*(done: () => boolean) {
-    while (!done()) yield* Effect.yieldNow
-  })
-
   it.effect("answers a click at its deadline and lets its handler run on, so a late commit is never repeated", () =>
     Effect.gen(function*() {
       const api = makeApi()
       const release = yield* Deferred.make()
-      const clicks: Array = []
-      const recorder = makeRecorder()
-      const late = {
-        ...recorder,
-        interactions: ChatInteraction.Handler.of({
-          ...recorder.interactions,
-          click: () =>
-            Effect.as(
-              Effect.andThen(
-                Effect.sync(() => void clicks.push("started")),
-                Effect.andThen(Deferred.await(release), Effect.sync(() => void clicks.push("committed")))
-              ),
-              ChatInteraction.ack
-            )
-        })
-      }
-      const click = callbackUpdate({
-        message_id: 5,
-        date: 1_800_000_000,
-        chat: { id: chatId, type: "supergroup" },
-        text: "x",
-        reply_markup: { inline_keyboard: [[{ text: "Yes", callback_data: "approve" }]] }
-      }, "approve")
-      const fiber = yield* Effect.forkChild(receive(api, late, click))
-      yield* until(() => clicks.length > 0)
+      const steps: Array = []
+      const recorder = makeRecorder({
+        click: Effect.andThen(
+          Effect.sync(() => void steps.push("started")),
+          Effect.andThen(Deferred.await(release), Effect.sync(() => void steps.push("committed")))
+        )
+      })
+      const fiber = yield* Effect.forkChild(receive(api, recorder, click("approve")))
+      yield* until(() => steps.length > 0)
       yield* TestClock.adjust("2499 millis")
-      assert.isUndefined(fiber.pollUnsafe())
       assert.strictEqual(api.sent("answerCallbackQuery").length, 0)
       yield* TestClock.adjust("1 millis")
       assert.deepStrictEqual(yield* Fiber.join(fiber), ["accepted"])
       assert.strictEqual(api.sent("answerCallbackQuery").length, 1)
-      assert.deepStrictEqual(clicks, ["started"])
       yield* Deferred.succeed(release, void 0)
-      yield* until(() => clicks.length > 1)
-      assert.deepStrictEqual(clicks, ["started", "committed"])
+      yield* until(() => steps.length > 1)
+      assert.deepStrictEqual(steps, ["started", "committed"])
     }))
 
   it.effect("refuses a message whose handler outlives its deadline, so Telegram redelivers it", () =>
     Effect.gen(function*() {
-      const started: Array = []
-      const stuck = {
-        ...makeRecorder(),
-        handler: ChatHandler.of({
-          handle: () => Effect.andThen(Effect.sync(() => void started.push("started")), Effect.never)
-        })
-      }
-      const fiber = yield* Effect.forkChild(receive(makeApi(), stuck, messageUpdate({ text: "hi" })))
-      yield* until(() => started.length > 0)
+      let started = false
+      const recorder = makeRecorder({ handle: Effect.andThen(Effect.sync(() => void (started = true)), Effect.never) })
+      const fiber = yield* Effect.forkChild(receive(makeApi(), recorder, messageUpdate({ text: "hi" })))
+      yield* until(() => started)
       yield* TestClock.adjust("9999 millis")
       assert.isUndefined(fiber.pollUnsafe())
       yield* TestClock.adjust("1 millis")
@@ -562,59 +357,49 @@ describe("deadlines", () => {
 
   it.effect("interrupts a command at its deadline and still counts it answered, never as a message", () =>
     Effect.gen(function*() {
-      const api = makeApi()
       const steps: Array = []
-      const recipe = makeRecipe(() =>
-        Effect.andThen(
-          Effect.sync(() => void steps.push("started")),
-          Effect.onInterrupt(Effect.never, () => Effect.sync(() => void steps.push("interrupted")))
-        )
-      )
-      const fiber = yield* Effect.forkChild(receive(api, recipe, commandUpdate("deploy", "prod")))
-      yield* until(() => steps.length > 0)
+      const recorder = makeRecorder({
+        command: () => Effect.onInterrupt(Effect.never, () => Effect.sync(() => void steps.push("interrupted")))
+      })
+      const fiber = yield* Effect.forkChild(receive(makeApi(), recorder, commandUpdate("deploy", "prod")))
+      yield* until(() => recorder.commands.length > 0)
       yield* TestClock.adjust("9999 millis")
       assert.isUndefined(fiber.pollUnsafe())
       yield* TestClock.adjust("1 millis")
       assert.deepStrictEqual(yield* Fiber.join(fiber), ["accepted"])
-      yield* until(() => steps.length > 1)
-      assert.deepStrictEqual(steps, ["started", "interrupted"])
-      assert.strictEqual(recipe.work.size, 0)
-      assert.strictEqual(recipe.events.length + recipe.unhandled.length, 0)
+      yield* until(() => steps.length > 0)
+      assert.strictEqual(recorder.events.length + recorder.unhandled.length, 0)
     }))
 })
 
-describe("senders and files", () => {
-  // Telegram's stand-in `from` for anonymous group admins.
-  const anonymous = { id: 1087968824, is_bot: true, first_name: "Group", username: "GroupAnonymousBot" }
-
-  it.effect("gives an anonymous admin's command the group as its user", () =>
-    Effect.gen(function*() {
-      const recorder = makeRecorder()
-      const asGroup = (id: number) =>
-        commandUpdate("deploy", "", { from: anonymous, sender_chat: { id, type: "supergroup", title: "G" } })
-      yield* receive(makeApi(), recorder, asGroup(-1001), asGroup(-1002))
-      assert.deepStrictEqual(recorder.commands.map((command) => command.userId), ["-1001", "-1002"])
-    }))
-
-  it("gives an animation one attachment, not its document copy too", () => {
-    const file = { file_id: "anim", file_unique_id: "u", mime_type: "video/mp4" }
-    const [event] = TelegramChat.normalize(
-      messageUpdate({ animation: { ...file, width: 1, height: 1, duration: 1 }, document: file }),
-      context
+it.effect("gives an anonymous admin's command the group as its user", () =>
+  Effect.gen(function*() {
+    const recorder = makeRecorder()
+    // Telegram's stand-in `from` for anonymous group admins.
+    const anonymous = { id: 1087968824, is_bot: true, first_name: "Group", username: "GroupAnonymousBot" }
+    yield* receive(
+      makeApi(),
+      recorder,
+      commandUpdate("deploy", "", { from: anonymous, sender_chat: { id: -1001, type: "supergroup", title: "G" } })
     )
-    assert.strictEqual(event._tag, "MessageCreated")
-    assert.deepStrictEqual(event._tag === "MessageCreated" ? event.message.attachments.map((a) => a.id) : [], ["anim"])
-  })
+    assert.deepStrictEqual(recorder.commands.map((command) => command.userId), ["-1001"])
+  }))
+
+it("gives an animation one attachment, not its document copy too", () => {
+  const file = { file_id: "anim", file_unique_id: "u", mime_type: "video/mp4" }
+  const [event] = TelegramChat.normalize(
+    messageUpdate({ animation: { ...file, width: 1, height: 1, duration: 1 }, document: file }),
+    context
+  )
+  assert.deepStrictEqual(event._tag === "MessageCreated" ? event.message.attachments.map((a) => a.id) : [], ["anim"])
 })
 
-describe("commandRequests", () => {
-  it.effect("refuses ids Telegram can't register", () =>
-    Effect.gen(function*() {
-      const ok = ChatInteraction.group(ChatInteraction.command("deploy", { description: "Deploy" }))
-      const bad = ChatInteraction.group(ChatInteraction.command("ship-it", { description: "Ship" }))
-      assert.deepStrictEqual(yield* TelegramChat.commandRequests(ok), {
-        commands: [{ command: "deploy", description: "Deploy" }]
-      })
-      assert.isTrue(Exit.isFailure(yield* Effect.exit(TelegramChat.commandRequests(bad))))
-    }))
-})
+it.effect("commandRequests refuses ids Telegram can't register", () =>
+  Effect.gen(function*() {
+    const ok = ChatInteraction.group(ChatInteraction.command("deploy", { description: "Deploy" }))
+    const bad = ChatInteraction.group(ChatInteraction.command("ship-it", { description: "Ship" }))
+    assert.deepStrictEqual(yield* TelegramChat.commandRequests(ok), {
+      commands: [{ command: "deploy", description: "Deploy" }]
+    })
+    assert.isTrue(Exit.isFailure(yield* Effect.exit(TelegramChat.commandRequests(bad))))
+  }))
diff --git a/packages/chat/telegram/test/gfm.ts b/packages/chat/telegram/test/gfm.ts
index ef39a7b41ab..556e6ab4639 100644
--- a/packages/chat/telegram/test/gfm.ts
+++ b/packages/chat/telegram/test/gfm.ts
@@ -41,9 +41,6 @@ const blockTypes = new Set([
   "html"
 ])
 
-export const parse = (markdown: string): Mdast.Root =>
-  fromMarkdown(markdown, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] })
-
 export const inspect = (markdown: string): Findings => {
   const html: Array = []
   const links: Array = []
@@ -109,6 +106,6 @@ export const inspect = (markdown: string): Findings => {
     }
     if ("children" in node) { for (const child of node.children) visit(child as Mdast.Nodes, d) }
   }
-  visit(parse(markdown), 0)
+  visit(fromMarkdown(markdown, { extensions: [gfm()], mdastExtensions: [gfmFromMarkdown()] }), 0)
   return { html, images, links, maxDepth, maxColumns, blocks, active, unhonored, inline }
 }
diff --git a/packages/chat/telegram/test/markdown.test.ts b/packages/chat/telegram/test/markdown.test.ts
index 64638eeb1b7..152ccadd6e1 100644
--- a/packages/chat/telegram/test/markdown.test.ts
+++ b/packages/chat/telegram/test/markdown.test.ts
@@ -1,8 +1,8 @@
 /**
- * T3 and T4: the rendered Markdown stays within what `measure` charged and
- * carries no raw HTML, image, math, spoiler or link outside http, https and
- * mailto. A GFM parser reads the output; live check 2 confirms Telegram's
- * parser agrees with it.
+ * The rendered Markdown stays within what `measure` charged and Telegram's
+ * limits, and carries no raw HTML, image, math, spoiler or link outside
+ * http, https and mailto. A GFM parser reads the output; live check 2
+ * confirms Telegram's parser agrees with it.
  */
 import {
   maxColumns,
@@ -18,55 +18,7 @@ import { assert, describe, it } from "@effect/vitest"
 import * as fc from "fast-check"
 import { inspect } from "./gfm.ts"
 
-/** The most blocks Telegram renders in one message. */
-const maxBlocks = 500
-
-// Live check 2 found that Telegram ignores the escapes `\]` and `\<`, reads destinations
-// verbatim, reads definitions more loosely than CommonMark and opens emphasis
-// between spaces: the last six cases.
-const cases: ReadonlyArray = [
-  ["hi  ", "<b>hi</b>  <javascript:alert(1)>"],
-  ["![a](https://e.com/a.png) ![b][r]", "\\![a](https://e.com/a.png) \\![b][r]"],
-  ["[me](tg://user?id=1) [ok](tg://user?id=2)", "[me]\\(tg://user?id\\=1) [ok](tg://user?id=2)"],
-  [
-    "[a](tg://x) [b](tg%3A//x) [c](tg\\://x) [d](javascript:x)",
-    "[a]\\(tg://x) [b]\\(tg%3A//x) [c]\\(tg://x) [d]\\(javascript:x)"
-  ],
-  ["[r]\n\n[r]: tg://user?id=1", "[r]\n\n\\[r]: tg://user?id\\=1"],
-  ["$x$ ==m== ||s||", "\\$x\\$ \\=\\=m\\=\\= \\|\\|s\\|\\|"],
-  ["| a | b |\n|---|---|\n| 1 | 2 |", "| a | b |\n|---|---|\n| 1 | 2 |"],
-  ["`` and `open", "`` and \\`open"],
-  [">>>>>>>>>>>>>>>>> x", ">>>>>>>>>>>>>>>\\>\\> x"],
-  ["[x\\](tg://resolve?domain=telegram) \\x\\", "\\[x](tg://resolve?domain\\=telegram) <b>x</b>"],
-  [
-    "[a](https://e.com/?q=1&x=2 \"t\") [b](https://e.com/a_b*c\\(d\\))",
-    "[a](https://e.com/?q=1&x=2) [b](https://e.com/a_b*c%28d%29)"
-  ],
-  [
-    "](https://e.com||s||) [a [b](https://e.com) c](https://e.com)",
-    "]\\(https://e.com\\|\\|s\\|\\|) [a [b](https://e.com) c]\\(https://e.com)"
-  ],
-  [
-    "[a][b]: tg://x\n\n [c]: tg://x\n\ntext\n[d]: https://e.com",
-    "\\[a][b]: tg://x\n\n \\[c]: tg://x\n\ntext\n\\[d]: https://e.com"
-  ],
-  ["a\\:b \\@c \\^d \\&", "a:b @c ^d &amp;"],
-  ["2 * 3 * 4 a _ b\n\n***", "2 \\* 3 \\* 4 a \\_ b\n\n***"],
-  // a definition is refused once, keeps no title, and loses no text
-  [
-    "[a[b]: https://e.com\n\n[^ a]: https://e.com\n\n[c]: https://e.com \"t\"\n[d]: https://e.com d",
-    "\\[a[b]: https://e.com\n\n\\[^ a]: https://e.com\n\n[c]: https://e.com\n\\[d]: https://e.com d"
-  ],
-  // a label that renders to 999 characters stays a definition, one of 1,000 does not
-  ["[" + "$".repeat(499) + "]: mailto:x", "[" + "\\$".repeat(499) + "]: mailto:x"],
-  ["[" + "$".repeat(500) + "]: mailto:x", "\\[" + "\\$".repeat(500) + "]: mailto:x"],
-  // a destination keeps parentheses three deep, not four
-  ["[a](https://e.com/(((x))))", "[a](https://e.com/(((x))))"],
-  ["[a](https://e.com/((((x)))))", "[a]\\(https://e.com/((((x)))))"]
-]
-
-const bytes = (s: string) => new TextEncoder().encode(s).length
-
+/** The users whose `tg://user` links stay links. */
 const mentions = new Set(["2"])
 
 /** Fails with what a GFM parse of `render(input)` finds that the renderer promises it never holds. */
@@ -86,200 +38,134 @@ const assertInert = (input: string) => {
   assert.isAtMost(found.maxDepth, maxDepth, context)
   assert.isAtMost(found.maxColumns, maxColumns, context)
   assert.isAtMost(found.inline, maxInlineNodes, context)
-  if (measure(input) <= messageLength) assert.isAtMost(found.blocks, maxBlocks, context)
+  // The most blocks Telegram renders in one message.
+  if (measure(input) <= messageLength) assert.isAtMost(found.blocks, 500, context)
 }
 
-const hostile = fc.string({
-  unit: fc.constantFrom(
-    ..."<>$=|![]()*_~`#-+.:/\\&;\n \t\"'0a",
-    "~~~",
-    "```",
-    " ~~~",
-    "- ",
-    "> ",
-    "1. ",
-    "https://e.com",
-    "www.e.co",
-    "x@e.co",
-    "tg://user?id=1",
-    "",
-    "](",
-    "[^",
-    "[^a]: ",
-    "|---|",
-    "\\]",
-    "\\<",
-    "\\`",
-    // whitespace that is not a blank line to CommonMark
-    "[a]",
-    "\n[a]: mailto:x\n",
-    "\u00a0",
-    "\u3000",
-    "\v",
-    "\f"
-  ),
-  maxLength: 60
-})
-
-const markdown = fc.string({
-  unit: fc.oneof(
-    fc.constantFrom(
-      ..."<>$=|![]()*_~`#-+.:/\\&;\n\r \t0123456789abc",
-      "\u0000",
-      "é",
-      "€",
-      "😀",
-      "\ud800",
-      "tg://",
-      "https://"
-    ),
-    fc.string({ maxLength: 3 })
-  ),
-  maxLength: 200
-})
-
 describe("render", () => {
   it("escapes the hostile corpus", () => {
-    for (const [input, expected] of cases) assert.strictEqual(render(input, { mentions: new Set(["2"]) }), expected)
+    // Live check 2 found that Telegram ignores the escapes `\]` and `\<`, reads
+    // destinations verbatim, reads definitions more loosely than CommonMark
+    // and opens emphasis between spaces.
+    const cases: ReadonlyArray = [
+      ["hi  ", "<b>hi</b>  <javascript:alert(1)>"],
+      ["![a](https://e.com/a.png) ![b][r]", "\\![a](https://e.com/a.png) \\![b][r]"],
+      ["[me](tg://user?id=1) [ok](tg://user?id=2)", "[me]\\(tg://user?id\\=1) [ok](tg://user?id=2)"],
+      ["| a | b |\n|---|---|\n| 1 | 2 |", "| a | b |\n|---|---|\n| 1 | 2 |"],
+      [">>>>>>>>>>>>>>>>> x", ">>>>>>>>>>>>>>>\\>\\> x"],
+      [
+        "[x\\](tg://resolve?domain=telegram) \\x\\",
+        "\\[x](tg://resolve?domain\\=telegram) <b>x</b>"
+      ],
+      [
+        "[a](https://e.com/?q=1&x=2 \"t\") [b](https://e.com/a_b*c\\(d\\))",
+        "[a](https://e.com/?q=1&x=2) [b](https://e.com/a_b*c%28d%29)"
+      ],
+      [
+        "[a][b]: tg://x\n\n [c]: tg://x\n\ntext\n[d]: https://e.com",
+        "\\[a][b]: tg://x\n\n \\[c]: tg://x\n\ntext\n\\[d]: https://e.com"
+      ],
+      ["2 * 3 * 4 a _ b\n\n***", "2 \\* 3 \\* 4 a \\_ b\n\n***"],
+      // a definition is refused once, keeps no title, and loses no text
+      [
+        "[a[b]: https://e.com\n\n[^ a]: https://e.com\n\n[c]: https://e.com \"t\"\n[d]: https://e.com d",
+        "\\[a[b]: https://e.com\n\n\\[^ a]: https://e.com\n\n[c]: https://e.com\n\\[d]: https://e.com d"
+      ],
+      // a label that renders to 999 characters stays a definition, one of 1,000 does not
+      ["[" + "$".repeat(499) + "]: mailto:x", "[" + "\\$".repeat(499) + "]: mailto:x"],
+      ["[" + "$".repeat(500) + "]: mailto:x", "\\[" + "\\$".repeat(500) + "]: mailto:x"],
+      // a destination keeps parentheses three deep, not four
+      ["[a](https://e.com/(((x))))", "[a](https://e.com/(((x))))"],
+      ["[a](https://e.com/((((x)))))", "[a]\\(https://e.com/((((x)))))"]
+    ]
+    for (const [input, expected] of cases) assert.strictEqual(render(input, { mentions }), expected)
   })
 
   it("leaves a GFM parser no HTML, image, foreign link, math, spoiler or excess nesting", () => {
     for (
       const input of [
-        // a backtick in a link title is not a code span
-        "[x](https://e.com \"`\") Click `",
-        "[x](https://e.com \"`\") ![i](https://e.com/i.png) [ping](tg://user?id=123) `",
         // a fence may be indented up to three spaces
         " ~~~\nx\n~~~\n[ping](tg://user?id=123) ",
-        // each delimiter of a run is a level
-        "_".repeat(36) + "x" + "_".repeat(36),
         // a heading ends a table
         "| a | b |\n|---|---|\n# heading\n||secret||",
-        // a backslash in a bare URL escapes nothing
-        "https://e.com\\ ](https://e.com\\ )",
-        "[^]: [^a]: x\n=",
         // a lazy continuation line stays in the containers it does not repeat
         ">".repeat(15) + " x\n" + "_".repeat(14) + "x" + "_".repeat(14),
         "2. <\n x_\n=",
-        "[^a]: b\na\n=",
-        "|a|\n|-|\na\n=\n|a|\n|-|\na\n=",
-        // an intraword underscore closes nothing
-        "_a_b ".repeat(17) + "x_" + " x_".repeat(16),
-        // a footnote's text, or an indented delimiter row, is no table
+        // a footnote's text is no table
         "[^a]: x|y\n---|---\n||secret||",
-        "x|y\n\t---|---",
-        // nor a delimiter row that starts a list item
-        "a|b\n- |-|",
         // nor a lone pipe a header
         "|\n-|",
         // a table goes on past a line it does not end at
         "|a|\n|---|\n[a]: mailto:x\nb `|`",
         // a line of U+00A0 is text, so it ends no paragraph
         ">".repeat(15) + " x\n\u00a0\n" + "_".repeat(14) + "x" + "_".repeat(14),
-        "[^a]: z\n\u00a0\nx|y\n---|---\n||secret||",
-        // a nested label, a reference or a footnote may turn the outer link
-        // into text, and its destination into Markdown
-        "[outer [inner]](mailto:[pwn](tg://user?id=1))\n\n[inner]: https://safe.com",
-        "[outer [inner]](mailto:![pwn](tg://document?id=f1))\n\n[inner]: https://safe.com",
-        "[outer [inner]](mailto:||spoiler||)\n\n[inner]: https://safe.com",
+        // a reference may turn the outer link into text, and its destination into Markdown
         "[a][inner](mailto:[pwn](tg://user?id=1))\n\n[inner]: https://safe.com",
-        "[inner][](mailto:[pwn](tg://user?id=1))\n\n[inner]: https://safe.com",
-        "[x [^a]](mailto:[pwn](tg://user?id=1))\n\n[^a]: z",
-        "[x [^a](mailto:[pwn](tg://user?id=1))\n\n[^a]: z",
         // unbalanced parentheses end no destination
         "[](mailto:$(> )",
-        // a definition's label may span lines
-        "[\n[a]: [",
-        "[x\\](a)\n]: tg://user?id=1\n\n[x](a)\n]",
-        // nor a definition with a nested, blank or overlong label, or with
-        // more than a destination and a title on its line
-        "[a[b]: mailto:[pwn](tg://user?id=1)",
-        "[]: mailto:[pwn](tg://user?id=1)",
-        "[a]: mailto:[pwn](tg://user?id=1)(",
-        "[ ]: mailto:[pwn](tg://user?id=1)",
-        "[" + "a".repeat(1000) + "]: mailto:[pwn](tg://user?id=1)",
-        // nor one whose label grows past 999 characters as it is escaped
-        "[" + "$".repeat(500) + "]: mailto:[pwn](tg://user?id=1)",
-        "[" + "|".repeat(500) + "]: mailto:[pwn](tg://user?id=1)",
-        "[" + "\\^".repeat(200) + "]: mailto:[pwn](tg://user?id=1)",
-        "[" + "\\<".repeat(150) + "]: mailto:[pwn](tg://user?id=1)",
-        // in a bare URL each `\<` becomes `%5C<`
-        "[www.e.co/" + "\\<".repeat(142) + "]: mailto:[pwn](tg://user?id=1)",
-        // nor a destination nested deeper than a parser may read
-        "[x](mailto:" + "(".repeat(32) + "[pwn](tg://user?id=1)" + ")".repeat(32) + ")",
-        "[x](mailto:" + "(".repeat(3) + "[pwn](tg://user?id=1)" + ")".repeat(3) + ")",
-        "[x]: mailto:" + "(".repeat(32) + "[pwn](tg://user?id=1)" + ")".repeat(32),
-        "[a]: mailto:[pwn](tg://user?id=1) b",
-        "[a]: mailto:[pwn](tg://user?id=1) \"t",
-        "[a]: mailto:\u007f[pwn](tg://user?id=1)",
-        "[a]: mailto:x [b]: mailto:[pwn](tg://user?id=1)",
         // a code span or an autolink hides no label's end from CommonMark
-        "[`]: x` ](tg://user?id=1)",
-        "[\u0001`> >\\\"]: `]\"^<>",
-        "[",
         "[>\\]: mailto:]:[^a]",
         // indented, a footnote's label is a definition's
-        "[a]: mailto:x\n\t[^a]: tg://x",
         "[a]: mailto:x\n    [^a]: tg://x",
-        "[^a]: [a]:<",
         // nor is an autolink with a control character one
         ""
       ]
     ) assertInert(input)
-    fc.assert(fc.property(hostile, (input) => assertInert(input)), { numRuns: 2000 })
+    const hostile = fc.string({
+      unit: fc.constantFrom(
+        ..."<>$=|![]()*_~`#-+.:/\\&;\n \t\"'0a",
+        "~~~",
+        "```",
+        " ~~~",
+        "- ",
+        "> ",
+        "1. ",
+        "https://e.com",
+        "www.e.co",
+        "x@e.co",
+        "tg://user?id=1",
+        "",
+        "](",
+        "[^",
+        "[^a]: ",
+        "|---|",
+        "\\]",
+        "\\<",
+        "\\`",
+        "[a]",
+        "\n[a]: mailto:x\n",
+        // whitespace that is not a blank line to CommonMark
+        "\u00a0",
+        "\u3000",
+        "\v",
+        "\f"
+      ),
+      maxLength: 60
+    })
+    fc.assert(fc.property(hostile, assertInert), { numRuns: 500 })
   })
 
-  it("keeps output within the budget under 500 blocks", () => {
-    const line = fc.constantFrom(
-      "- a\n",
-      "> - a\n",
-      "- - - a\n",
-      "1. a\n",
-      "# a\n",
-      "a\n",
-      "a\n=\n",
-      "___\n",
-      "|a|\n|-|\n",
-      "[^a]: b\n",
-      "```\n```\n"
-    )
-    fc.assert(
-      fc.property(fc.array(line, { minLength: 1, maxLength: 4 }), (lines) => {
-        let input = ""
-        for (let k = 0; measure(input + lines[k]) <= messageLength; k = (k + 1) % lines.length) input += lines[k]
-        assertInert(input)
-      }),
-      { numRuns: 40 }
-    )
+  it("keeps output that fills the budget under 500 blocks", () => {
+    for (const line of ["- - - a\n", "1. a\n"]) {
+      let input = ""
+      while (measure(input + line) <= messageLength) input += line
+      assertInert(input)
+    }
   })
 
-  it("caps the code spans, links and footnote references Telegram refuses past a limit", () => {
+  it("caps the code spans, references and footnote references Telegram refuses past a limit", () => {
     const spans = render("`a` ".repeat(maxInlineNodes + 10))
     assert.strictEqual(spans.match(/(? url.startsWith("tg:")), [])
     const references = render(Array.from({ length: 10 }, () => "x[^1]".repeat(100)).join("\n\n") + "\n\n[^1]: n")
     assert.strictEqual(references.match(/(? {
-    assert.deepStrictEqual(inspect(String.raw`\!\`).unhonored, [String.raw`\!\`])
-  })
-
   it("escapes the pipes of a table wider than 20 columns", () => {
     const row = (cell: string) => "|" + ` ${cell} |`.repeat(21)
-    const out = render(row("c") + "\n" + row("-"))
-    assert.isFalse(/(^|[^\\])\|/.test(out))
+    assert.isFalse(/(^|[^\\])\|/.test(render(row("c") + "\n" + row("-"))))
   })
 
   it("closes an open fence before the media references", () => {
@@ -287,18 +173,26 @@ describe("render", () => {
   })
 
   it("never exceeds measure, with the reservation for files", () => {
+    const markdown = fc.string({
+      unit: fc.oneof(
+        fc.constantFrom(
+          ..."<>$=|![]()*_~`#-+.:/\\&;\n\r \t0123456789abc",
+          "\u0000",
+          "é",
+          "€",
+          "😀",
+          "\ud800",
+          "tg://",
+          "https://"
+        ),
+        fc.string({ maxLength: 3 })
+      ),
+      maxLength: 200
+    })
+    const bytes = (s: string) => new TextEncoder().encode(s).length
     fc.assert(fc.property(markdown, fc.integer({ min: 0, max: 10 }), (input, files) => {
       assert.isAtMost(bytes(render(input)), measure(input))
       assert.isAtMost(bytes(render(input, { files })), measure(input) + reservation)
     }))
-    assert.strictEqual(messageLength + reservation, 32_768)
-  })
-})
-
-describe("measure", () => {
-  it("is subadditive", () => {
-    fc.assert(fc.property(markdown, markdown, (a, b) => {
-      assert.isAtMost(measure(a + b), measure(a) + measure(b))
-    }))
   })
 })
diff --git a/packages/chat/telegram/test/utils.ts b/packages/chat/telegram/test/utils.ts
index 64a2fa1dc2d..06790921d4b 100644
--- a/packages/chat/telegram/test/utils.ts
+++ b/packages/chat/telegram/test/utils.ts
@@ -13,15 +13,10 @@ import * as Redacted from "effect/Redacted"
 /** A marker token: no error, span or log may contain it. */
 export const token = "123456789:AAH-marker_TOKEN_must_not_leak"
 export const botId = "123456789"
-export const username = "effect_bot"
+const username = "effect_bot"
 export const chatId = -1001234567890
 export const thread = TelegramChat.thread(chatId)
-export const user = { id: 4242, is_bot: false, first_name: "Ada" }
-
-export interface Call {
-  readonly method: string
-  readonly body: any
-}
+const user = { id: 4242, is_bot: false, first_name: "Ada" }
 
 const ok = (result: unknown) => ({ status: 200, body: { ok: true, result } })
 
@@ -56,7 +51,7 @@ const readBody = (request: HttpClientRequest.HttpClientRequest): any => {
  * one-shot answers for a method.
  */
 export const makeApi = () => {
-  const calls: Array = []
+  const calls: Array<{ readonly method: string; readonly body: any }> = []
   const messages = new Map()
   const next = new Map()
   /** The batches `getUpdates` gives, in order. Once they run out it never answers. */
@@ -91,8 +86,6 @@ export const makeApi = () => {
       case "getFile":
         return ok({ file_id: body.file_id, file_unique_id: "u", file_size: 5, file_path: "documents/file_1.txt" })
       case "answerCallbackQuery":
-      case "setWebhook":
-      case "setMyCommands":
         return ok(true)
       default:
         return apiError(404, "Not Found")
@@ -136,12 +129,9 @@ export const makeApi = () => {
 
 export type FakeApi = ReturnType
 
-/** Every capability on, as the conformance suite and the interaction tests want. */
-export const unverified = { files: true, buttons: true, commands: true }
-
-/** `Chat`, `Registry` and the adapter on a fake Bot API. */
-export const telegramLayer = (api: FakeApi, options?: { readonly unverified?: TelegramChat.Unverified }) =>
-  TelegramChat.layer({ token: Redacted.make(token), unverified: options?.unverified ?? unverified }).pipe(
+/** `Chat`, `Registry` and the adapter on a fake Bot API, with every capability on. */
+export const telegramLayer = (api: FakeApi) =>
+  TelegramChat.layer({ token: Redacted.make(token), unverified: { files: true, buttons: true, commands: true } }).pipe(
     Layer.provideMerge(Chat.layer),
     Layer.provide(api.layer)
   )
@@ -172,15 +162,9 @@ export const commandUpdate = (name: string, text = "", extra?: Record | undefined, data: string) => ({
+export const callbackUpdate = (message: Record, data: string) => ({
   update_id: ++updateId,
-  callback_query: {
-    id: "cq" + updateId,
-    from: user,
-    chat_instance: "1",
-    data,
-    ...(message === undefined ? {} : { message })
-  }
+  callback_query: { id: "cq" + updateId, from: user, chat_instance: "1", data, message }
 })
 
 export const context = { botId, botUsername: username }
diff --git a/packages/chat/whatsapp/test/WhatsAppChat.test.ts b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
index df4c8406632..05485d90dd4 100644
--- a/packages/chat/whatsapp/test/WhatsAppChat.test.ts
+++ b/packages/chat/whatsapp/test/WhatsAppChat.test.ts
@@ -119,15 +119,6 @@ describe("post", () => {
       })
     }))
 
-  it.effect("measures a short body layout, its link lines and its generated body", () =>
-    Effect.gen(function*() {
-      const graph = makeGraph()
-      const descriptor = yield* run(graph, Effect.flatMap(Chat.Chat, (chat) => chat.descriptor("whatsapp")))
-      assert.strictEqual(descriptor.measure("ab", [button("a", "Yes")]), 2 + 3072 + 3)
-      const link: Action = { _tag: "LinkButton", label: "Docs", url: "u" }
-      assert.strictEqual(descriptor.measure("", [button("a", "Yes"), link]), 3072 + "Yes, Docs".length + 2 + 7)
-    }))
-
   it.effect("refuses before any call", () =>
     Effect.gen(function*() {
       const graph = makeGraph()
@@ -146,6 +137,12 @@ describe("post", () => {
           "duplicate_label"
         ],
         [post({ markdown: "x", actions: [button("a\u241F", "A")] }), "InvalidRequest", "invalid_action_id"],
+        // The wire id "bx\u241F" + 126 "é" is 257 UTF-8 bytes, though within actionDataLength.
+        [
+          post({ markdown: "x", actions: [button("x", "Yes", "é".repeat(126))] }),
+          "TooLarge",
+          "action_data_too_long"
+        ],
         [
           post({ markdown: "x" }, { platform: "whatsapp", id: phoneNumberId + "/u/not-a-user" }),
           "InvalidRequest",
@@ -178,17 +175,6 @@ describe("post", () => {
       assert.deepStrictEqual(graph.calls, [])
     }))
 
-  it.effect("refuses a reply button whose wire id is over 256 UTF-8 bytes", () =>
-    Effect.gen(function*() {
-      const graph = makeGraph()
-      // "b", the id and U+241F take 5 bytes, so 125 "é" and one "a" make 256.
-      yield* run(graph, post({ markdown: "x", actions: [button("x", "Yes", "é".repeat(125) + "a")] }))
-      assert.strictEqual(graph.calls.length, 1)
-      const reason = yield* failure(graph, post({ markdown: "x", actions: [button("x", "Yes", "é".repeat(126))] }))
-      assert.deepStrictEqual([reason._tag, reason.detail], ["TooLarge", "action_data_too_long"])
-      assert.strictEqual(graph.calls.length, 1)
-    }))
-
   it.effect("names the messaging account on every send when one is configured", () =>
     Effect.gen(function*() {
       const graph = makeGraph()
@@ -393,12 +379,6 @@ describe("webhook", () => {
       })
       assert.deepStrictEqual([result.status, result.seen], [200, ["SelectChanged"]])
       assert.strictEqual((yield* Deferred.await(refusal)).reason._tag, "Unsupported")
-      const [event] = WhatsAppChat.normalize(click, { phoneNumberId })
-      assert.deepStrictEqual(event._tag === "SelectChanged" && [event.id, event.value, event.messageId], [
-        "env",
-        "p\u241Fq",
-        "wamid.out1"
-      ])
     }))
 })
 
@@ -425,15 +405,7 @@ describe("normalize", () => {
 })
 
 describe("keys", () => {
-  it("keys a delivery by its webhook message, and an update by its parts", () => {
-    const click = inbound({
-      type: "interactive",
-      context: { id: "wamid.out1" },
-      interactive: { type: "button_reply", button_reply: { id: "ba", title: "A" } }
-    })
-    const [event] = WhatsAppChat.normalize(click, { phoneNumberId })
-    const id = (click.entry[0].changes[0].value.messages[0] as any).id
-    assert.strictEqual(event._tag === "ButtonClicked" && WhatsAppChat.deliveryKey(event), `${phoneNumberId}/${id}`)
+  it("keys an update by its parts, escaped", () => {
     const updates = WhatsAppChat.normalize(
       statuses({ id: "wamid.a/b", status: "delivered", recipient_id: phone, recipient_user_id: bsuid }),
       { phoneNumberId }
diff --git a/packages/chat/whatsapp/test/text.test.ts b/packages/chat/whatsapp/test/text.test.ts
index 763711e35f9..f123941d4ed 100644
--- a/packages/chat/whatsapp/test/text.test.ts
+++ b/packages/chat/whatsapp/test/text.test.ts
@@ -10,12 +10,10 @@ const cases: ReadonlyArray = [
   ["[label](https://e.com \"title\")", "label (https://e.com)"],
   ["![alt](https://e.com/a.png)", "alt (https://e.com/a.png)"],
   ["[](https://e.com)", "https://e.com"],
-  ["![](https://e.com)", "https://e.com"],
   ["", "https://e.com"],
   ["# Title #", "*Title*"],
   ["Title\n===\n", "*Title*\n"],
   ["#", "#"],
-  ["# ", "# "],
   ["| a | b |\n|---|---|\n| 1 | 2 |", "| a | b |\n| 1 | 2 |"],
   ["~~~ts\n**x**\n~~~\n", "```\n**x**\n```\n"],
   ["& < é 😀", "& < \u00e9 \u{1F600}"],
diff --git a/packages/chat/whatsapp/test/utils.ts b/packages/chat/whatsapp/test/utils.ts
index 1c702880a56..0da50cdb3de 100644
--- a/packages/chat/whatsapp/test/utils.ts
+++ b/packages/chat/whatsapp/test/utils.ts
@@ -91,7 +91,6 @@ export const makeGraph = () => {
   return {
     calls,
     messages,
-    media,
     next,
     sent: () => calls.filter((call) => call.path === `${phoneNumberId}/messages`).map((call) => call.body),
     layer: Layer.succeed(HttpClient.HttpClient, client)
diff --git a/packages/effect/test/chat/Chat.test.ts b/packages/effect/test/chat/Chat.test.ts
index 96db73dda65..6989bcd66e8 100644
--- a/packages/effect/test/chat/Chat.test.ts
+++ b/packages/effect/test/chat/Chat.test.ts
@@ -21,10 +21,8 @@ describe("Chat", () => {
       const test = yield* ChatTest.ChatTest
       const b = yield* test.makeThread()
       yield* chat.post(b, { markdown: "to b" })
-      assert.strictEqual((yield* chat.descriptor("a")).platform, "a")
       const missing = yield* Effect.flip(chat.post(ChatThread.make("c", "x"), { markdown: "nowhere" }))
       assert.strictEqual(missing.reason._tag, "NoAdapter")
-      assert.strictEqual(missing.op, "post")
       assert.deepStrictEqual((yield* test.messages(b)).map((message) => message.text), ["to b"])
     }).pipe(Effect.provide(Layer.mergeAll(ChatTest.layer({ platform: "a" }), ChatTest.layer({ platform: "b" })))))
 
diff --git a/packages/effect/test/chat/ChatError.test.ts b/packages/effect/test/chat/ChatError.test.ts
index b6015cea34b..f4644a8da73 100644
--- a/packages/effect/test/chat/ChatError.test.ts
+++ b/packages/effect/test/chat/ChatError.test.ts
@@ -60,14 +60,11 @@ describe("ChatError", () => {
       assert.notInclude(JSON.stringify(error), "secret")
       assert.notInclude(JSON.stringify(reason), "secret")
       assert.notInclude(error.message, "secret")
-      assert.strictEqual(error.cause, reason)
     }
   })
 
   it("delegates retryAfter to the reason", () => {
     const error = new ChatError.ChatError({ platform: "slack", op: "post", reason: reasons[0] })
     assert.deepStrictEqual(error.retryAfter, Duration.seconds(3))
-    assert.isTrue(ChatError.isChatError(error))
-    assert.isFalse(ChatError.isChatError(reasons[0]))
   })
 })
diff --git a/packages/effect/test/chat/ChatEvent.test.ts b/packages/effect/test/chat/ChatEvent.test.ts
index f53870af250..788bcbe9fa6 100644
--- a/packages/effect/test/chat/ChatEvent.test.ts
+++ b/packages/effect/test/chat/ChatEvent.test.ts
@@ -18,7 +18,6 @@ describe("ChatEvent", () => {
       assert.strictEqual(ChatEvent.dedupeKey(event), "stop/slack:T1/C1/1794454017.568519/1794454026.522466")
       // A redelivery has the same key, whatever streams it lists.
       assert.strictEqual(ChatEvent.dedupeKey({ ...event, messageIds: [] }), ChatEvent.dedupeKey(event))
-      assert.notStrictEqual(ChatEvent.dedupeKey({ ...event, id: "1794454030.000000" }), ChatEvent.dedupeKey(event))
     })
   })
 })
diff --git a/packages/effect/test/chat/ChatInteraction.test.ts b/packages/effect/test/chat/ChatInteraction.test.ts
index a0f04208318..3ccc1e4c6fc 100644
--- a/packages/effect/test/chat/ChatInteraction.test.ts
+++ b/packages/effect/test/chat/ChatInteraction.test.ts
@@ -13,94 +13,60 @@ const clicked = (id: string, value?: string) =>
 const invoked = (id: string, text = "") =>
   ChatInteraction.CommandInvoked.make({ id, text, thread, userId: "u1", raw: { id: "i1" } })
 
-describe("ChatInteraction", () => {
-  describe("encodeValue / decodeValue", () => {
-    it("sends a string-only schema as it is", () => {
-      assert.strictEqual(ChatInteraction.encodeValue(Schema.String, "v1.4.2"), "v1.4.2")
-      assert.strictEqual(ChatInteraction.encodeValue(Schema.Literals(["a", "b"]), "a"), "a")
-      assert.deepStrictEqual(ChatInteraction.decodeValue(Schema.String, "\"quoted\""), Option.some("\"quoted\""))
-    })
-
-    it("sends anything else as JSON, decided by the schema and not the value", () => {
-      const StringOrNumber = Schema.Union([Schema.String, Schema.Number])
-      assert.strictEqual(ChatInteraction.encodeValue(StringOrNumber, "123"), "\"123\"")
-      assert.strictEqual(ChatInteraction.encodeValue(StringOrNumber, 123), "123")
-      assert.deepStrictEqual(ChatInteraction.decodeValue(StringOrNumber, "\"123\""), Option.some("123"))
-      assert.deepStrictEqual(ChatInteraction.decodeValue(StringOrNumber, "123"), Option.some(123))
-      assert.strictEqual(ChatInteraction.encodeValue(Deploy, { version: "v1" }), "{\"version\":\"v1\"}")
-    })
+const handlerWith = (options: {
+  readonly click?: Effect.Effect
+  readonly submit?: Effect.Effect
+  readonly command?: (command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply
+  readonly refused?: (error: ChatError.ChatError) => Effect.Effect
+}) =>
+  ChatInteraction.Handler.of({
+    click: () => options.click ?? Effect.succeed(ChatInteraction.ack),
+    submit: () => options.submit ?? Effect.succeed(ChatInteraction.close),
+    command: (command) => Effect.succeed(options.command?.(command) ?? ChatInteraction.ack),
+    refused: (_, error) => options.refused?.(error) ?? Effect.void
+  })
 
-    it("gives none for a string that no longer decodes", () => {
-      assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Deploy, "not json")))
-      assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Deploy, "{\"version\":1}")))
-      assert.isTrue(Option.isNone(ChatInteraction.decodeValue(Schema.Literals(["a"]), "b")))
-    })
+describe("ChatInteraction", () => {
+  it("encodes a value by its schema: a string-only schema as it is, anything else as JSON", () => {
+    const StringOrNumber = Schema.Union([Schema.String, Schema.Number])
+    assert.strictEqual(ChatInteraction.encodeValue(Schema.String, "v1.4.2"), "v1.4.2")
+    assert.deepStrictEqual(ChatInteraction.decodeValue(Schema.String, "\"quoted\""), Option.some("\"quoted\""))
+    assert.strictEqual(ChatInteraction.encodeValue(StringOrNumber, "123"), "\"123\"")
+    assert.deepStrictEqual(ChatInteraction.decodeValue(StringOrNumber, "123"), Option.some(123))
   })
 
-  describe("definitions", () => {
-    it("button.of encodes the value and takes overrides", () => {
-      const Approve = ChatInteraction.button("approve", { label: "Approve", style: "primary", value: Deploy })
-      assert.deepStrictEqual(Approve.of({ version: "v1" }, { label: "Ship v1" }), {
-        _tag: "Button",
-        id: "approve",
-        label: "Ship v1",
-        style: "primary",
-        value: "{\"version\":\"v1\"}"
-      })
-      const Plain = ChatInteraction.button("plain", { label: "Plain" })
-      assert.deepStrictEqual(Plain.of(), { _tag: "Button", id: "plain", label: "Plain" })
+  it("modal.open builds the elements in field order, with encoded metadata and options", () => {
+    const Reason = ChatInteraction.modal("reason", {
+      title: "Why",
+      metadata: Deploy,
+      fields: {
+        intro: ChatInteraction.text("Tell us."),
+        reason: ChatInteraction.textInput({ label: "Reason", multiline: true, maxLength: 200 }),
+        env: ChatInteraction.selectInput({ label: "Env", value: Schema.Number, optional: true })
+      }
     })
-
-    it("modal.open builds the elements in field order, with encoded metadata and options", () => {
-      const Reason = ChatInteraction.modal("reason", {
-        title: "Why",
-        metadata: Deploy,
-        fields: {
-          intro: ChatInteraction.text("Tell us."),
-          reason: ChatInteraction.textInput({ label: "Reason", multiline: true, maxLength: 200 }),
-          env: ChatInteraction.selectInput({ label: "Env", value: Schema.Number, optional: true })
-        }
-      })
-      const opened = Reason.open({
-        metadata: { version: "v1" },
-        options: { env: [{ label: "Prod", value: 1 }] },
-        initial: { env: 1 }
-      })
-      assert.isTrue(Schema.is(ChatInteraction.OpenModal)(opened))
-      assert.deepStrictEqual(opened.modal, {
-        _tag: "Modal",
-        id: "reason",
-        title: "Why",
-        metadata: "{\"version\":\"v1\"}",
-        elements: [
-          { _tag: "Text", text: "Tell us." },
-          { _tag: "TextInput", id: "reason", label: "Reason", multiline: true, maxLength: 200 },
-          {
-            _tag: "SelectInput",
-            id: "env",
-            label: "Env",
-            options: [{ label: "Prod", value: "1" }],
-            initial: "1",
-            optional: true
-          }
-        ]
-      })
+    const opened = Reason.open({
+      metadata: { version: "v1" },
+      options: { env: [{ label: "Prod", value: 1 }] },
+      initial: { env: 1 }
     })
-
-    it("respond and defer answer privately by default, and a deferral survives JSON", () => {
-      assert.deepStrictEqual(ChatInteraction.respond({ markdown: "Hi" }), {
-        _tag: "Respond",
-        markdown: "Hi",
-        visibility: "ephemeral"
-      })
-      const deferred = ChatInteraction.defer(invoked("summarize"), { visibility: "public" })
-      const codec = Schema.toCodecJson(ChatInteraction.Defer)
-      const wire = JSON.parse(JSON.stringify(Schema.encodeSync(codec)(deferred)))
-      assert.deepStrictEqual(Schema.decodeUnknownSync(codec)(wire), {
-        _tag: "Defer",
-        command: { _tag: "CommandInvoked", id: "summarize", text: "", thread, userId: "u1", raw: { id: "i1" } },
-        visibility: "public"
-      })
+    assert.deepStrictEqual(opened.modal, {
+      _tag: "Modal",
+      id: "reason",
+      title: "Why",
+      metadata: "{\"version\":\"v1\"}",
+      elements: [
+        { _tag: "Text", text: "Tell us." },
+        { _tag: "TextInput", id: "reason", label: "Reason", multiline: true, maxLength: 200 },
+        {
+          _tag: "SelectInput",
+          id: "env",
+          label: "Env",
+          options: [{ label: "Prod", value: "1" }],
+          initial: "1",
+          optional: true
+        }
+      ]
     })
   })
 
@@ -138,7 +104,7 @@ describe("ChatInteraction", () => {
       Effect.gen(function*() {
         seen.length = 0
         const handler = yield* ChatInteraction.Handler
-        const reply = yield* handler.click(clicked("approve", ChatInteraction.encodeValue(Deploy, { version: "v1" })))
+        const reply = yield* handler.click(clicked("approve", Approve.of({ version: "v1" }).value))
         assert.strictEqual(reply._tag, "OpenModal")
         const submitted = ChatInteraction.ModalSubmitted.make({
           id: "reason",
@@ -166,7 +132,6 @@ describe("ChatInteraction", () => {
         // A command and a button share one id space: a command named like a button is not routed to it.
         assert.deepStrictEqual(yield* handler.command(invoked("approve")), ChatInteraction.ack)
         assert.deepStrictEqual(unhandled, ["nope:UnknownId", "approve:UnknownId"])
-        assert.deepStrictEqual(Ship.argument, { name: "version", description: "The version", required: false })
       }).pipe(Effect.provide(Interactions)))
 
     it.effect("answers an unknown id or a value that no longer decodes without a handler", () =>
@@ -203,18 +168,6 @@ describe("ChatInteraction", () => {
 
   describe("handle", () => {
     const deadline = Duration.seconds(3)
-    const handlerWith = (options: {
-      readonly click?: Effect.Effect
-      readonly submit?: Effect.Effect
-      readonly command?: Effect.Effect
-      readonly refused?: (error: ChatError.ChatError) => Effect.Effect
-    }) =>
-      ChatInteraction.Handler.of({
-        click: () => options.click ?? Effect.succeed(ChatInteraction.ack),
-        submit: () => options.submit ?? Effect.succeed(ChatInteraction.close),
-        command: () => options.command ?? Effect.succeed(ChatInteraction.ack),
-        refused: (_, error) => options.refused?.(error) ?? Effect.void
-      })
 
     it.effect("interrupts the handler when cancelled during startup", () =>
       Effect.gen(function*() {
@@ -272,23 +225,6 @@ describe("ChatInteraction", () => {
         assert.strictEqual(error.reason.detail, ChatError.interactionExpired)
       }))
 
-    it.effect("interrupts a late command", () =>
-      Effect.gen(function*() {
-        let interrupted = false
-        const handler = handlerWith({
-          command: Effect.as(Effect.sleep("5 seconds"), ChatInteraction.respond({ markdown: "late" })).pipe(
-            Effect.onInterrupt(() => Effect.sync(() => void (interrupted = true)))
-          )
-        })
-        const fiber = yield* ChatInteraction.handle(invoked("slow"), deadline).pipe(
-          Effect.provideService(ChatInteraction.Handler, handler),
-          Effect.forkChild
-        )
-        yield* TestClock.adjust("3 seconds")
-        assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
-        assert.isTrue(interrupted)
-      }))
-
     it.effect("gives Late at the deadline without waiting for a late submit's cleanup", () =>
       Effect.gen(function*() {
         const cleaned = yield* Deferred.make()
@@ -314,40 +250,12 @@ describe("ChatInteraction", () => {
   })
 
   describe("ChatTest.interact", () => {
-    it.effect("uses the layer's interactionDeadline", () =>
-      Effect.gen(function*() {
-        const test = yield* ChatTest.ChatTest
-        const handler = ChatInteraction.Handler.of({
-          click: () => Effect.as(Effect.sleep("2 seconds"), ChatInteraction.ack),
-          submit: () => Effect.succeed(ChatInteraction.close),
-          command: () => Effect.succeed(ChatInteraction.ack),
-          refused: () => Effect.void
-        })
-        const fiber = yield* test.interact(clicked("a")).pipe(
-          Effect.provideService(ChatInteraction.Handler, handler),
-          Effect.forkChild
-        )
-        yield* TestClock.adjust("1 second")
-        assert.isTrue(Schema.is(ChatInteraction.Late)(yield* Fiber.join(fiber)))
-      }).pipe(Effect.provide(ChatTest.layer({ interactionDeadline: Duration.seconds(1) }))))
-
-    const answering = (reply: (command: ChatInteraction.CommandInvoked) => ChatInteraction.CommandReply) => {
-      const refused: Array = []
-      const handler = ChatInteraction.Handler.of({
-        click: () => Effect.succeed(ChatInteraction.ack),
-        submit: () => Effect.succeed(ChatInteraction.close),
-        command: (command) => Effect.succeed(reply(command)),
-        refused: (_, error) => Effect.sync(() => void refused.push(error))
-      })
-      return { handler, refused }
-    }
-
     it.effect("follows up a deferral once, inside followUpAge", () =>
       Effect.gen(function*() {
         const test = yield* ChatTest.ChatTest
         const chat = yield* Chat.Chat
         const channel = yield* test.makeThread()
-        const { handler } = answering((command) => ChatInteraction.defer(command))
+        const handler = handlerWith({ command: (command) => ChatInteraction.defer(command) })
         const interact = (command: ChatInteraction.CommandInvoked) =>
           Effect.provideService(test.interact(command), ChatInteraction.Handler, handler)
         const first = yield* interact(yield* test.command(channel, "summarize"))
@@ -359,22 +267,18 @@ describe("ChatInteraction", () => {
         const expired = yield* Effect.flip(chat.followUp(second as ChatInteraction.Defer, { markdown: "Late" }))
         assert.strictEqual(expired.reason._tag, "NotFound")
         assert.strictEqual(expired.reason.detail, ChatError.interactionExpired)
-        const answers = (yield* test.calls).filter((call) => call.op === "followUp")
-        assert.deepStrictEqual(answers.map((call) => [call.markdown, call.outcome]), [
-          ["Done", "ok"],
-          ["Again", "NotFound"],
-          ["Late", "NotFound"]
-        ])
-        assert.deepStrictEqual(yield* test.messages(channel), [])
       }).pipe(Effect.provide(ChatTest.layer())))
 
     it.effect("refuses a private answer without ephemeral, and sends nothing", () =>
       Effect.gen(function*() {
         const test = yield* ChatTest.ChatTest
         const channel = yield* test.makeThread()
-        const { handler, refused } = answering((command) =>
-          command.text === "defer" ? ChatInteraction.defer(command) : ChatInteraction.respond({ markdown: "Secret" })
-        )
+        const refused: Array = []
+        const handler = handlerWith({
+          command: (command) =>
+            command.text === "defer" ? ChatInteraction.defer(command) : ChatInteraction.respond({ markdown: "Secret" }),
+          refused: (error) => Effect.sync(() => void refused.push(error))
+        })
         for (const text of ["respond", "defer"]) {
           yield* Effect.provideService(
             test.interact(yield* test.command(channel, "secret", { text })),
diff --git a/packages/effect/test/chat/ChatMarkdown.test.ts b/packages/effect/test/chat/ChatMarkdown.test.ts
index b707f40f7a9..93443eaa0be 100644
--- a/packages/effect/test/chat/ChatMarkdown.test.ts
+++ b/packages/effect/test/chat/ChatMarkdown.test.ts
@@ -22,29 +22,52 @@ const setup = Effect.gen(function*() {
 const texts = (test: ChatTest.ChatTest["Service"], thread: ChatThread.ChatThread) =>
   Effect.map(test.messages(thread), (messages) => messages.map((message) => message.text))
 
-/** Runs `stream` over a queue the test feeds. */
+/** Runs `stream` over a queue the test feeds, ends or fails. */
 const feed = Effect.fnUntraced(function*(
   thread: ChatThread.ChatThread,
   options?: ChatMarkdown.Options & { readonly recipient?: string | undefined }
 ) {
-  const queue = yield* Queue.unbounded()
+  const queue = yield* Queue.unbounded()
   const fiber = yield* Effect.forkChild(ChatMarkdown.stream(thread, Stream.fromQueue(queue), options))
   const send = (chunk: string) => Effect.andThen(Queue.offer(queue, chunk), settle)
+  const fail = (error: string) => Effect.andThen(Queue.fail(queue, error), settle)
   const close = Effect.andThen(Queue.end(queue), settle)
   const end = Effect.andThen(Queue.end(queue), Fiber.join(fiber))
-  return { fiber, send, close, end }
+  return { fiber, send, fail, close, end }
+})
+
+/** Registers the test adapter with its native stream changed by `f`. */
+const patchNative = Effect.fnUntraced(function*(
+  f: (native: ChatAdapter.NativeStream) => Partial
+) {
+  const test = yield* ChatTest.ChatTest
+  const registry = yield* ChatAdapter.Registry
+  const adapter = yield* registry.get(test.platform)
+  const native = adapter.nativeStream!
+  yield* registry.register({ ...adapter, nativeStream: { ...native, ...f(native) } })
+})
+
+/** Holds the first native `append` or `stop` until `release` completes. */
+const holdFirst = Effect.fnUntraced(function*(op: "append" | "stop") {
+  const entered = yield* Deferred.make()
+  const release = yield* Deferred.make()
+  let first = true
+  const hold = (effect: Effect.Effect) =>
+    Effect.suspend(() => {
+      if (!first) return effect
+      first = false
+      return Deferred.succeed(entered, undefined).pipe(Effect.andThen(Deferred.await(release)), Effect.andThen(effect))
+    })
+  yield* patchNative((native) =>
+    op === "append"
+      ? { append: (...args) => hold(native.append(...args)) }
+      : { stop: (...args) => hold(native.stop(...args)) }
+  )
+  return { entered, release }
 })
 
 describe("ChatMarkdown", () => {
   describe("post", () => {
-    it.effect("posts nothing for empty input", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const result = yield* ChatMarkdown.post(thread, "")
-        assert.deepStrictEqual(result, { parts: [], stopped: false })
-        assert.deepStrictEqual(yield* test.calls, [])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("splits at block boundaries", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -69,18 +92,6 @@ describe("ChatMarkdown", () => {
         for (const part of result.parts) assert.isAtMost(codePoints(part.markdown), 60)
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 60 } }))))
 
-    it.effect("measures with the adapter's measure", () => {
-      const measure = (markdown: string) => codePoints(markdown) + 3 * markdown.split("<").length - 3
-      return Effect.gen(function*() {
-        const { thread } = yield* setup
-        const input = "a
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -93,18 +104,6 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(replies.map((reply) => reply?.messageId), [event.message.id, undefined, undefined])
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
 
-    it.effect("fails with Overflow past maxParts", () =>
-      Effect.gen(function*() {
-        const { thread } = yield* setup
-        const input = paragraphs(5, 20)
-        const error = yield* Effect.flip(ChatMarkdown.post(thread, input, { maxParts: 2 }))
-        assert.strictEqual(error.cause._tag, "Overflow")
-        assert.strictEqual(error.posted.length, 2)
-        assert.isUndefined(error.uncertain)
-        assert.isUndefined(error.remainingFence)
-        assert.strictEqual(joined(error.posted) + error.remaining, input)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
-
     it.effect("remainingFence is the fence remaining was cut in, and reopening it gives the rest back", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -127,14 +126,6 @@ describe("ChatMarkdown", () => {
 
     const files = [{ name: "a.txt", contentType: "text/plain", content: new TextEncoder().encode("a") }]
 
-    it.effect("sends files with the last part", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        yield* ChatMarkdown.post(thread, paragraphs(3, 20), { files })
-        const messages = yield* test.messages(thread)
-        assert.deepStrictEqual(messages.map((message) => message.attachments.length), [0, 0, 1])
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
-
     it.effect("ends in the unattached note when the files are refused", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -161,7 +152,6 @@ describe("ChatMarkdown", () => {
         }))
         assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "TooLarge")
         assert.deepStrictEqual([error.posted, error.uncertain, error.remaining], [[], undefined, "Report"])
-        assert.strictEqual((yield* test.calls).filter((call) => call.op === "post").length, 1)
         assert.deepStrictEqual(yield* texts(test, thread), [])
       }).pipe(Effect.provide(ChatTest.layer())))
 
@@ -175,8 +165,7 @@ describe("ChatMarkdown", () => {
           files,
           unattachedNote: () => " (file not attached)"
         }))
-        assert.isDefined(error.uncertain)
-        assert.strictEqual((yield* test.calls).filter((call) => call.op === "post").length, 1)
+        assert.deepStrictEqual([error.posted, error.uncertain, error.remaining], [[], "Report", ""])
         assert.deepStrictEqual(yield* texts(test, thread), ["Report"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
@@ -223,20 +212,9 @@ describe("ChatMarkdown", () => {
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
 
     const button = ChatInteraction.button("go", { label: "Go" }).of()
-    /** Each element costs 10, as escaping and block JSON make one cost something on Slack. */
-    const withActions = (markdown: string, actions?: ReadonlyArray) =>
-      codePoints(markdown) + 10 * (actions?.length ?? 0)
-
-    it.effect("cuts the last part earlier to leave room for the actions", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        // 25 code points fit alone, but not with the actions' 10.
-        const input = "aaaaaaaaaa\n\nbbbbbbbbbbbbb"
-        const result = yield* ChatMarkdown.post(thread, input, { actions: [button] })
-        assert.deepStrictEqual(result.parts.map((part) => part.text), ["aaaaaaaaaa\n\n", "bbbbbbbbbbbbb"])
-        assert.strictEqual((yield* Effect.flip(test.click(result.parts[0].messageId, "go")))._tag, "NoSuchElement")
-        yield* test.click(result.parts[1].messageId, "go")
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
+    /** One element costs `cost`, so a test can leave as little room beside it as it needs. */
+    const costing = (cost: number) => (markdown: string, actions?: ReadonlyArray) =>
+      codePoints(markdown) + cost * (actions?.length ?? 0)
 
     it.effect("fails TooLarge before posting when the actions alone do not fit", () =>
       Effect.gen(function*() {
@@ -244,11 +222,7 @@ describe("ChatMarkdown", () => {
         const error = yield* Effect.flip(ChatMarkdown.post(thread, "a", { actions: [button] }))
         assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "TooLarge")
         assert.deepStrictEqual(yield* test.messages(thread), [])
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 9 }, measure: withActions }))))
-
-    /** One element costs `cost`, so a test can leave as little room beside it as it needs. */
-    const costing = (cost: number) => (markdown: string, actions?: ReadonlyArray) =>
-      codePoints(markdown) + cost * (actions?.length ?? 0)
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 9 }, measure: costing(10) }))))
 
     it.effect("fills the parts before the last one without leaving room for the actions", () =>
       Effect.gen(function*() {
@@ -293,7 +267,7 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(result.parts.map((part) => part.markdown), ["a".repeat(20), " note"])
         assert.strictEqual((yield* Effect.flip(test.click(result.parts[0].messageId, "go")))._tag, "NoSuchElement")
         yield* test.click(result.parts[1].messageId, "go")
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: costing(10) }))))
 
     it.effect("posts the actions after an unattached note that has no room for them", () =>
       Effect.gen(function*() {
@@ -309,7 +283,7 @@ describe("ChatMarkdown", () => {
           assert.strictEqual((yield* Effect.flip(test.click(part.messageId, "go")))._tag, "NoSuchElement")
         }
         yield* test.click(result.parts[2].messageId, "go")
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: withActions }))))
+      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 }, measure: costing(10) }))))
 
     it.effect("never cuts inside a grapheme cluster on a hard cut", () =>
       Effect.gen(function*() {
@@ -325,34 +299,6 @@ describe("ChatMarkdown", () => {
         ])
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 10 } }))))
 
-    it.effect("reports the text of an uncertain post as uncertain", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const input = paragraphs(3, 20)
-        const error = yield* Effect.flip(ChatMarkdown.post(thread, input, {
-          onPart: () => test.failNext("post", new ChatError.Unknown({ detail: "timeout" }))
-        }))
-        assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Unknown")
-        assert.strictEqual(error.posted.length, 1)
-        assert.strictEqual(error.uncertain, "Paragraph 1 xxxxxxxx\n\n")
-        assert.strictEqual(joined(error.posted) + error.uncertain + error.remaining, input)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30 } }))))
-
-    it.effect("paces the parts by minWriteInterval", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const fiber = yield* Effect.forkChild(ChatMarkdown.post(thread, paragraphs(3, 20)))
-        yield* settle
-        assert.strictEqual((yield* test.calls).length, 1)
-        yield* TestClock.adjust("999 millis")
-        assert.strictEqual((yield* test.calls).length, 1)
-        yield* TestClock.adjust("1 millis")
-        assert.strictEqual((yield* test.calls).length, 2)
-        yield* TestClock.adjust("1 second")
-        const result = yield* Fiber.join(fiber)
-        assert.strictEqual(result.parts.length, 3)
-      }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 30, minWriteInterval: Duration.seconds(1) } }))))
-
     it.effect("keeps message text out of the error's message and JSON", () =>
       Effect.gen(function*() {
         const { thread } = yield* setup
@@ -363,27 +309,6 @@ describe("ChatMarkdown", () => {
   })
 
   describe("stream", () => {
-    it.effect("posts nothing for an empty stream", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const result = yield* ChatMarkdown.stream(thread, Stream.empty, { recipient: "U1" })
-        assert.deepStrictEqual(result, { parts: [], stopped: false })
-        assert.deepStrictEqual(yield* test.calls, [])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("posts and then edits without a recipient", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { end, send } = yield* feed(thread)
-        yield* send("Hello")
-        yield* send(" world\n\n```ts\nconst")
-        const result = yield* end
-        assert.deepStrictEqual(result.parts.map((part) => part.transport), ["edit"])
-        assert.deepStrictEqual(yield* texts(test, thread), ["Hello world\n\n```ts\nconst\n```"])
-        const calls = yield* test.calls
-        assert.deepStrictEqual(calls.map((call) => call.op), ["post", "edit"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("posts each part once, when it is final, without edit", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -394,7 +319,6 @@ describe("ChatMarkdown", () => {
         const result = yield* end
         assert.deepStrictEqual(result.parts.map((part) => part.transport), ["post", "post"])
         assert.deepStrictEqual(yield* texts(test, thread), ["one\n\n" + "two ".repeat(10) + "\n\n", "three"])
-        assert.deepStrictEqual((yield* test.calls).map((call) => call.op), ["post", "post"])
       }).pipe(Effect.provide(ChatTest.layer({ capabilities: ["files"], limits: { messageLength: 50 } }))))
 
     it.effect("writes natively with a recipient, sending held text again", () =>
@@ -473,29 +397,13 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* texts(test, thread), ["one\n", "two\n"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("falls back to post-then-edit when the start is Unsupported", () =>
+    it.effect("falls back to post-then-edit when the start is Unsupported, closing an open fence", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
         yield* test.failNext("nativeStream.start", new ChatError.Unsupported({ capability: "nativeStream" }))
-        const result = yield* ChatMarkdown.stream(thread, Stream.make("one\n", "two\n"), { recipient: "U1" })
+        const result = yield* ChatMarkdown.stream(thread, Stream.make("one\n", "```ts\ncode"), { recipient: "U1" })
         assert.deepStrictEqual(result.parts.map((part) => part.transport), ["edit"])
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\n"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("reports a click on stop that the consumer ignored", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const ids: Array = []
-        const { end, send } = yield* feed(thread, {
-          recipient: "U1",
-          onPart: (part) => Effect.sync(() => ids.push(part.messageId))
-        })
-        yield* send("one\n")
-        yield* test.clickStop(ids[0])
-        yield* send("two\n")
-        const result = yield* end
-        assert.isTrue(result.stopped)
-        assert.strictEqual(joined(result.parts), "one\ntwo\n")
+        assert.deepStrictEqual(yield* texts(test, thread), ["one\n```ts\ncode\n```"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
     it.effect("ends the reply stopped when an append comes back stopped", () =>
@@ -529,47 +437,6 @@ describe("ChatMarkdown", () => {
         const result = yield* end
         assert.deepStrictEqual(result.parts.map((part) => [part.transport, part.text]), [["native", "one\ntwo\n"]])
         assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\n"])
-        const ops = (yield* test.calls).map((call) => call.op)
-        assert.include(ops, "edit")
-        assert.notInclude(ops, "nativeStream.stop")
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("tries a failed append again on a timer", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { end, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("one\n")
-        yield* test.failNext("nativeStream.append", new ChatError.RateLimited({ retryAfter: Duration.seconds(2) }))
-        yield* send("two\n")
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\n"])
-        yield* TestClock.adjust("2 seconds")
-        yield* settle
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\n"])
-        const result = yield* end
-        assert.strictEqual(joined(result.parts), "one\ntwo\n")
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("fails on a denied append, after stopping the stream", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { fiber, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("one\n")
-        yield* test.failNext("nativeStream.append", new ChatError.Forbidden({}))
-        yield* send("two\n")
-        const error = yield* Effect.flip(Fiber.join(fiber))
-        assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
-        assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", undefined, "two\n"])
-        assert.include((yield* test.calls).map((call) => call.op), "nativeStream.stop")
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("finishes what was received when the upstream fails", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const deltas = Stream.concat(Stream.make("```ts\n", "code\n", "more"), Stream.fail("boom"))
-        const error = yield* Effect.flip(ChatMarkdown.stream(thread, deltas, { recipient: "U1" }))
-        assert.deepStrictEqual(error.cause, { _tag: "Upstream", error: "boom" })
-        assert.deepStrictEqual([joined(error.posted), error.remaining], ["```ts\ncode\nmore", ""])
-        assert.deepStrictEqual(yield* texts(test, thread), ["```ts\ncode\nmore\n```"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
     it.effect("does not post again when interrupted while onPart runs", () =>
@@ -638,18 +505,6 @@ describe("ChatMarkdown", () => {
         }
       }).pipe(Effect.provide(ChatTest.layer({ limits: { messageLength: 20 } }))))
 
-    it.effect("closes a code fence before rotating on age", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const { end, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("```ts\none\n")
-        yield* TestClock.adjust("9 minutes")
-        yield* send("two\n")
-        const result = yield* end
-        assert.deepStrictEqual(result.parts.map((part) => part.text), ["```ts\none\n", "two\n"])
-        assert.deepStrictEqual(yield* texts(test, thread), ["```ts\none\n```", "```ts\ntwo\n```"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
     it.effect("takes the text that arrived while waiting for the write interval", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
@@ -668,17 +523,6 @@ describe("ChatMarkdown", () => {
         assert.strictEqual(joined(result.parts), "a\nb\nc\n")
       }).pipe(Effect.provide(ChatTest.layer({ limits: { minWriteInterval: Duration.seconds(1) } }))))
 
-    /** Registers the test adapter with its native stream changed by `f`. */
-    const patchNative = Effect.fnUntraced(function*(
-      f: (native: ChatAdapter.NativeStream) => Partial
-    ) {
-      const test = yield* ChatTest.ChatTest
-      const registry = yield* ChatAdapter.Registry
-      const adapter = yield* registry.get(test.platform)
-      const native = adapter.nativeStream!
-      yield* registry.register({ ...adapter, nativeStream: { ...native, ...f(native) } })
-    })
-
     it.effect("a rotated stream's start names the part it continues", () =>
       Effect.gen(function*() {
         const { thread } = yield* setup
@@ -702,16 +546,7 @@ describe("ChatMarkdown", () => {
       Effect.gen(function*() {
         const { thread } = yield* setup
         const chat = yield* Chat.Chat
-        const entered = yield* Deferred.make()
-        let first = true
-        yield* patchNative((native) => ({
-          stop: (...args) =>
-            Effect.suspend(() => {
-              if (!first) return native.stop(...args)
-              first = false
-              return Effect.andThen(Deferred.succeed(entered, undefined), Effect.never)
-            })
-        }))
+        const { entered } = yield* holdFirst("stop")
         const ids: Array = []
         const { close, fiber, send } = yield* feed(thread, {
           recipient: "U1",
@@ -721,23 +556,14 @@ describe("ChatMarkdown", () => {
         yield* close
         yield* Deferred.await(entered)
         yield* Fiber.interrupt(fiber)
+        // An open native stream would refuse the edit.
         yield* chat.edit(thread, ids[0], { markdown: "edited" })
       }).pipe(Effect.provide(ChatTest.layer())))
 
     it.effect("keeps a rollover due after an append that was in flight when interrupted", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
-        const entered = yield* Deferred.make()
-        const release = yield* Deferred.make()
-        let first = true
-        yield* patchNative((native) => ({
-          append: (...args) =>
-            Effect.tap(native.append(...args), () => {
-              if (!first) return Effect.void
-              first = false
-              return Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release))
-            })
-        }))
+        const { entered, release } = yield* holdFirst("append")
         const { fiber, send } = yield* feed(thread, { recipient: "U1" })
         yield* send("~~~\none\n")
         yield* TestClock.adjust("9 minutes")
@@ -750,70 +576,20 @@ describe("ChatMarkdown", () => {
         assert.deepStrictEqual(yield* texts(test, thread), ["~~~\none\n~~~", "~~~\ntwo\n~~~"])
       }).pipe(Effect.provide(ChatTest.layer())))
 
-    it.effect("bounds an append in the interrupt finalizer by the finish timeout", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const entered = yield* Deferred.make()
-        yield* patchNative((native) => ({
-          append: (...args) =>
-            Effect.andThen(Deferred.succeed(entered, undefined), Effect.andThen(Effect.never, native.append(...args)))
-        }))
-        const { fiber, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("~~~\ncode")
-        const interrupt = yield* Effect.forkChild(Fiber.interrupt(fiber))
-        yield* Deferred.await(entered)
-        yield* TestClock.adjust("6 seconds")
-        yield* Fiber.join(interrupt)
-        // The held cluster and closing fence were cut off with the append.
-        assert.deepStrictEqual(yield* texts(test, thread), ["~~~\ncod"])
-      }).pipe(Effect.provide(ChatTest.layer())))
-
-    /** Runs `stream` over a queue the test can fail. */
-    const feedFailable = Effect.fnUntraced(function*(thread: ChatThread.ChatThread) {
-      const queue = yield* Queue.unbounded()
-      const fiber = yield* Effect.forkChild(
-        Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), { recipient: "U1" }))
-      )
-      return { queue, fiber }
-    })
-
-    /** Holds the first append until `release` completes, and records whether it was cut off. */
-    const holdFirstAppend = Effect.fnUntraced(function*() {
-      const entered = yield* Deferred.make()
-      const release = yield* Deferred.make()
-      const state = { cancelled: false }
-      let first = true
-      yield* patchNative((native) => ({
-        append: (...args) =>
-          Effect.suspend(() => {
-            if (!first) return native.append(...args)
-            first = false
-            return Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)).pipe(
-              Effect.andThen(native.append(...args)),
-              Effect.onInterrupt(() => Effect.sync(() => void (state.cancelled = true)))
-            )
-          })
-      }))
-      return { entered, release, state }
-    })
-
     it.effect("bounds an append in flight when the upstream fails", () =>
       Effect.gen(function*() {
         const { test, thread } = yield* setup
-        const { entered, release, state } = yield* holdFirstAppend()
-        const { fiber, queue } = yield* feedFailable(thread)
-        yield* Queue.offer(queue, "one\n")
-        yield* settle
-        yield* Queue.offer(queue, "two\n")
+        const { entered, release } = yield* holdFirst("append")
+        const { fail, fiber, send } = yield* feed(thread, { recipient: "U1" })
+        yield* send("one\n")
+        yield* send("two\n")
         yield* Deferred.await(entered)
-        yield* Queue.fail(queue, "boom")
-        yield* settle
+        yield* fail("boom")
         yield* TestClock.adjust("6 seconds")
         const finished = fiber.pollUnsafe() !== undefined
         yield* Deferred.succeed(release, undefined)
-        const error = yield* Fiber.join(fiber)
+        const error = yield* Effect.flip(Fiber.join(fiber))
         assert.isTrue(finished)
-        assert.isTrue(state.cancelled)
         assert.deepStrictEqual(error.cause, { _tag: "Upstream", error: "boom" })
         assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", "two\n", ""])
         yield* settle
@@ -824,69 +600,24 @@ describe("ChatMarkdown", () => {
       Effect.gen(function*() {
         const { test, thread } = yield* setup
         const chat = yield* Chat.Chat
-        const entered = yield* Deferred.make()
-        const release = yield* Deferred.make()
-        let first = true
-        yield* patchNative((native) => ({
-          stop: (...args) =>
-            Effect.suspend(() => {
-              if (!first) return native.stop(...args)
-              first = false
-              return Effect.andThen(
-                Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)),
-                native.stop(...args)
-              )
-            })
-        }))
-        const queue = yield* Queue.unbounded()
+        const { entered, release } = yield* holdFirst("stop")
         const ids: Array = []
-        const fiber = yield* Effect.forkChild(Effect.flip(ChatMarkdown.stream(thread, Stream.fromQueue(queue), {
+        const { fail, fiber, send } = yield* feed(thread, {
           recipient: "U1",
           onPart: (part) => Effect.sync(() => void ids.push(part.messageId))
-        })))
-        yield* Queue.offer(queue, "one\n")
-        yield* settle
+        })
+        yield* send("one\n")
         yield* test.failNext("nativeStream.append", new ChatError.Forbidden({}))
-        yield* Queue.offer(queue, "two\n")
+        yield* send("two\n")
         yield* Deferred.await(entered)
-        yield* Queue.fail(queue, "boom")
-        yield* settle
+        yield* fail("boom")
         yield* Deferred.succeed(release, undefined)
-        const error = yield* Fiber.join(fiber)
+        const error = yield* Effect.flip(Fiber.join(fiber))
         assert.strictEqual(error.cause._tag === "Chat" && error.cause.error.reason._tag, "Forbidden")
         assert.deepStrictEqual([joined(error.posted), error.uncertain, error.remaining], ["one\n", undefined, "two\n"])
         assert.deepStrictEqual(yield* texts(test, thread), ["one\n"])
         // An open native stream would refuse the edit.
         yield* chat.edit(thread, ids[0], { markdown: "edited" })
       }).pipe(Effect.provide(ChatTest.layer())))
-
-    it.effect("waits for an append in flight when interrupted, then finishes the reply", () =>
-      Effect.gen(function*() {
-        const { test, thread } = yield* setup
-        const entered = yield* Deferred.make()
-        const release = yield* Deferred.make()
-        let first = true
-        yield* patchNative((native) => ({
-          append: (...args) =>
-            Effect.suspend(() => {
-              if (!first) return native.append(...args)
-              first = false
-              return Effect.andThen(
-                Effect.andThen(Deferred.succeed(entered, undefined), Deferred.await(release)),
-                native.append(...args)
-              )
-            })
-        }))
-        const { fiber, send } = yield* feed(thread, { recipient: "U1" })
-        yield* send("one\n")
-        yield* send("two\n")
-        yield* Deferred.await(entered)
-        yield* send("three")
-        const interrupt = yield* Effect.forkChild(Fiber.interrupt(fiber))
-        yield* settle
-        yield* Deferred.succeed(release, undefined)
-        yield* Fiber.join(interrupt)
-        assert.deepStrictEqual(yield* texts(test, thread), ["one\ntwo\nthree"])
-      }).pipe(Effect.provide(ChatTest.layer())))
   })
 })
diff --git a/packages/effect/test/chat/ChatTest.test.ts b/packages/effect/test/chat/ChatTest.test.ts
index 4b148f5f7b0..8626313129c 100644
--- a/packages/effect/test/chat/ChatTest.test.ts
+++ b/packages/effect/test/chat/ChatTest.test.ts
@@ -87,8 +87,9 @@ describe("ChatTest", () => {
     }
   })
 
+  // With a capability off, a gated rule only probes it, as unsupported/{capability} does.
   describe("conformance without any capability", () => {
-    for (const rule of ruleNames) {
+    for (const rule of ruleNames.filter((name) => name.startsWith("unsupported/"))) {
       it.live(rule, () => runRule(rule, { capabilities: [] }))
     }
   })
@@ -177,21 +178,6 @@ describe("ChatTest", () => {
       assert.deepStrictEqual(left.map((message) => message.text), [])
     }).pipe(Effect.provide(ChatTest.layer())))
 
-  it.effect("checkMessage rejects a mention whose slice is not its token", () =>
-    Effect.gen(function*() {
-      const test = yield* ChatTest.ChatTest
-      const thread = yield* test.makeThread()
-      const event = yield* test.userPosts(thread, { text: "hi", mentionsSelf: true })
-      assert(event._tag === "MessageCreated")
-      yield* ChatTest.checkMessage(event.message, { platform: "test", parseMention })
-      const shifted = {
-        ...event.message,
-        mentions: event.message.mentions.map((mention) => ({ ...mention, start: mention.start + 1 }))
-      }
-      const exit = yield* Effect.exit(ChatTest.checkMessage(shifted, { platform: "test", parseMention }))
-      assert.isTrue(Exit.isFailure(exit))
-    }).pipe(Effect.provide(ChatTest.layer())))
-
   it.effect("checkInteraction rejects an empty messageId", () =>
     Effect.gen(function*() {
       const submitted = ChatInteraction.ModalSubmitted.make({
diff --git a/packages/effect/typetest/chat/ChatInteraction.tst.ts b/packages/effect/typetest/chat/ChatInteraction.tst.ts
index 04e0cd0a171..d2d74b8f67d 100644
--- a/packages/effect/typetest/chat/ChatInteraction.tst.ts
+++ b/packages/effect/typetest/chat/ChatInteraction.tst.ts
@@ -1,5 +1,5 @@
-import { Context, Duration, Effect, type Layer, Schema } from "effect"
-import { ChatError, ChatInteraction, type ChatUi } from "effect/chat"
+import { Context, Effect, type Layer, Schema } from "effect"
+import { ChatInteraction } from "effect/chat"
 import { describe, expect, it } from "tstyche"
 
 const EnvId = Schema.String.pipe(Schema.brand("EnvId"))
@@ -32,14 +32,13 @@ const Feedback = ChatInteraction.modal("feedback", {
   title: "Feedback",
   fields: { body: ChatInteraction.textInput({ label: "Feedback" }) }
 })
+const Ship = ChatInteraction.command("ship", { description: "Ship a version" })
 
 describe("ChatInteraction", () => {
   it("of takes the value its schema asks for", () => {
-    expect(Approve.of({ version: "v1" })).type.toBe()
     expect(Approve.of).type.not.toBeCallableWith()
     expect(Approve.of).type.not.toBeCallableWith({ version: 1 })
     expect(Refresh.of).type.not.toBeCallableWith({ version: "v1" })
-    expect(PickEnv.of).type.not.toBeCallableWith({ options: [{ label: "Prod", value: "prod" }] })
   })
 
   it("open needs the metadata and the selectInput options", () => {
@@ -84,81 +83,26 @@ describe("ChatInteraction", () => {
     expect(layer).type.toBe>()
   })
 
-  it("refuses a missing handler, a wrong reply and an error for an unknown field", () => {
-    const Small = ChatInteraction.group(Approve, RejectReason)
-    expect(Small.toLayer).type.not.toBeCallableWith({ approve: () => Effect.succeed(ChatInteraction.ack) })
-    expect(Small.toLayer).type.not.toBeCallableWith({
-      approve: () => Effect.succeed(ChatInteraction.close),
-      "reject-reason": () => Effect.succeed(ChatInteraction.close)
-    })
-    expect(Small.toLayer).type.not.toBeCallableWith({
-      approve: () => Effect.succeed(ChatInteraction.ack),
-      "reject-reason": () => Effect.succeed(Feedback.open())
-    })
-    expect(Small.toLayer).type.not.toBeCallableWith({
-      approve: () => Effect.succeed(ChatInteraction.ack),
-      "reject-reason": () => Effect.succeed(ChatInteraction.errors({ intro: "A text has no error." }))
-    })
-  })
-
-  it("types a command's handler, which must answer with a message, a modal or a deferral", () => {
-    const Ship = ChatInteraction.command("ship", {
-      description: "Ship a version",
-      argument: { name: "version", description: "The version", required: true }
-    })
-    const Summarize = ChatInteraction.command("summarize", { description: "Summarize this thread" })
-    const Group = ChatInteraction.group(Ship, Summarize, Approve, Feedback)
+  it("refuses a missing handler, a failing handler, a reply of the wrong kind and an error for an unknown field", () => {
+    const Group = ChatInteraction.group(Approve, RejectReason, Ship)
     const valid = {
-      ship: (command: ChatInteraction.CommandInvoked) => {
-        expect(command.text).type.toBe()
-        return Effect.succeed(ChatInteraction.respond({ markdown: "Ship " + command.text + "?" }))
-      },
-      summarize: (command: ChatInteraction.CommandInvoked) => Effect.succeed(ChatInteraction.defer(command)),
-      approve: () => Effect.succeed(Feedback.open()),
-      feedback: (submit: ChatInteraction.Submit) => {
-        expect(submit.messageId).type.toBe()
-        return Effect.succeed(ChatInteraction.close)
-      }
+      approve: () => Effect.succeed(ChatInteraction.ack),
+      "reject-reason": () => Effect.succeed(ChatInteraction.close),
+      ship: (command: ChatInteraction.CommandInvoked) => Effect.succeed(ChatInteraction.defer(command))
     }
     expect(Group.toLayer(valid)).type.toBe>()
-    expect(Group.toLayer).type.not.toBeCallableWith({ ...valid, ship: () => Effect.succeed(ChatInteraction.ack) })
+    const { ship: _, ...missing } = valid
+    expect(Group.toLayer).type.not.toBeCallableWith(missing)
     expect(Group.toLayer).type.not.toBeCallableWith({ ...valid, ship: () => Effect.fail("boom") })
+    expect(Group.toLayer).type.not.toBeCallableWith({ ...valid, approve: () => Effect.succeed(ChatInteraction.close) })
     expect(Group.toLayer).type.not.toBeCallableWith({
       ...valid,
-      approve: () => Effect.succeed(ChatInteraction.respond({ markdown: "A click cannot answer with a message." }))
+      "reject-reason": () => Effect.succeed(Feedback.open())
     })
+    expect(Group.toLayer).type.not.toBeCallableWith({ ...valid, ship: () => Effect.succeed(ChatInteraction.ack) })
     expect(Group.toLayer).type.not.toBeCallableWith({
       ...valid,
-      feedback: () => Effect.succeed(ChatInteraction.respond({ markdown: "Nor can a submit." }))
-    })
-    const { summarize: _, ...missing } = valid
-    expect(Group.toLayer).type.not.toBeCallableWith(missing)
-    expect(ChatInteraction.Handler.of).type.not.toBeCallableWith({
-      click: () => Effect.succeed(ChatInteraction.ack),
-      submit: () => Effect.succeed(ChatInteraction.close),
-      refused: () => Effect.void
+      "reject-reason": () => Effect.succeed(ChatInteraction.errors({ intro: "A text has no error." }))
     })
   })
-
-  it("handle gives the reply of the event's kind, or Late", () => {
-    const click = ChatInteraction.handle(
-      {} as ChatInteraction.ButtonClicked,
-      Duration.seconds(2)
-    )
-    expect(click).type.toBe<
-      Effect.Effect
-    >()
-    const submit = ChatInteraction.handle({} as ChatInteraction.ModalSubmitted, Duration.seconds(2))
-    expect(submit).type.toBe<
-      Effect.Effect
-    >()
-    const command = ChatInteraction.handle({} as ChatInteraction.CommandInvoked, Duration.seconds(2))
-    expect(command).type.toBe<
-      Effect.Effect
-    >()
-  })
-
-  it("keeps the error details literal", () => {
-    expect(ChatError.interactionExpired).type.toBe<"interaction_expired">()
-  })
 })