Skip to content

Port chat to the effect/chat PR snapshot - #189

Merged
tim-smart merged 6 commits into
mainfrom
agent/nelson/7cbf9fc23d34
Nov 13, 2026
Merged

tim-smart merged 6 commits into
mainfrom
agent/nelson/7cbf9fc23d34

Conversation

@tim-smart

@tim-smart tim-smart commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Moves Janitor's Slack and Discord chat onto effect/chat, @effect/chat-slack and @effect/chat-discord from the Effect-TS/effect#10581 snapshot, so we can dogfood the API before that PR lands.

Approved for production (2026-11-13). Tim approved merging this with its snapshot pins and dogfooding it on production: "This is fine for production. We don't need a separate environment." A merge to main deploys production through the usual Check → Deploy workflows. The approval covers this PR only. It doesn't cover merging Effect-TS/effect#10581, and the Slack and Discord app settings, scopes and intents stay as they are.

Closes EFF-3766

Snapshot provenance

  • Commit eeccfc1bc8a8cb1d338c2dd85fd41a138047517f of #10581, published by build https://github.com/Effect-TS/effect/actions/runs/43432011317. It adds the fixes for the two defects this dogfood reported (see below) to 42cf7c0, which the PR used before.
  • Every effect / @effect/* catalog entry (except @effect/tsgo, which is versioned separately) is https://pkg.pr.new/Effect-TS/effect/<pkg>@eeccfc1…. @effect/chat-slack and @effect/chat-discord are new catalog entries used by apps/cluster.
  • pnpm-lock.yaml: all 219 pkg.pr.new references point at eeccfc1…, no registry effect or @effect/* package is left, and a single effect (4.1.4) resolves.
  • blockExoticSubdeps: false lets the existing overrides hand the URL to subdependencies (e.g. @foldkit/vite-plugin's @effect/platform-node). Restore the default when the catalog returns to registry versions.

What moved

  • Chat/Platform.ts: replies go through ChatMarkdown.post (postMarkdown), with the overflow uploaded as reply.md and refused files noted in the text. Downloads use Chat.download, history uses Chat.history. uploadFile and the hand-rolled chunking are gone.
  • Slack: SlackChat.layer / layerWebhook replace the Web API client, the signature verifier and the event decoding. Admission still uses users.info (via SlackChat.user) with the one-hour cache. 👍 approvals read the message with chat.fetchMessage. McpServers uses SlackWebApi for conversations.info.
  • Discord: the Durable Object keeps its own dfx shard (resume and seen-ids live in its storage) and hands MESSAGE_CREATE / MESSAGE_REACTION_ADD to DiscordChat.dispatch. The ingress is a ChatHandler. Threads start with chat.startThread. Posts use DiscordChat.withPostOptions to ping only named users and the replied-to author.
  • Session behaviour, admission rules, DM pointers, dedupe and approvals are unchanged; the tests for them pass with only harness changes.

Behaviour kept from before the port

These came up in review (EFF-3766) and now behave as on main, each with a test that fails without the fix:

  • Refused files with an overflowing reply. The rest of the reply is posted as text, ending in the "Couldn't attach" note, and nothing already posted goes out again. When the cut falls inside a code fence, the fence is opened again and closed before the note, and the code's whitespace is kept. ChatMarkdown does this itself since eeccfc1, so Janitor's recovery (recoverRemaining) is gone. The tests stay and now run against the library: overflow on Slack and Discord, a cut inside a closed fence, and an unterminated fence with trailing spaces.
  • Slack webhook deadline. The whole request, reading the body included, is bounded by 2.5s and answered 503 past it. @effect/chat-slack's deadline covers that since eeccfc1, so Janitor's middleware (answerWithin) is gone. The streaming-body test stays. Every 503 is now logged as Slack webhook answered 503 by a route middleware that only reads the response status, with no deadline of its own and nothing from the request. Unlike main's Slack webhook failed with error: "Timeout", it doesn't name a timeout: the adapter answers a timeout and an unreadable bot user with the same 503. A handler refusal still logs Slack webhook failed with its error first.
  • /me actions. The adapter passes me_message on as a new message. Janitor's subtype allow-list (none, file_share, thread_broadcast; plus bot_message in history) is back in ingress and history.
  • Discord reply to a deleted message. It goes out as a plain message, as fail_if_not_exists: false did. The adapter can't send that field, so Janitor retries without the reference when Discord refuses it before anything posted.

Behaviour changes from main

Tim saw this table with the production approval above and raised no objection, so these ship as they are. That is acceptance of the table as a whole, not a sign-off item by item. Restoring any of them means bypassing the adapter for the very thing we're dogfooding:

Change Before Now Why
Long replies Over 3 (Slack) / 5 (Discord) messages: the whole reply as reply.md The first 3 / 5 parts as messages, the rest as reply.md ChatMarkdown's overflow design; no text is lost.
Slack janitor_output metadata On every post Gone SlackPostOptions has no metadata field. Nothing in Janitor reads it.
Slack event for another app/workspace 403 200, dropped The adapter's choice. Slack retries non-2xx, so 200 avoids pointless redelivery.
Slack files refused while attaching Text posted, then the note The adapter deletes the post and reposts the text with the note Same end state in the thread.
Discord allowed_mentions parse: ["users"] Explicit users list from the <@id>s in the text Pings the same people.

Gaps found in the snapshot (feedback for #10581)

Posted with reproductions on EFF-3691:

  • Fixed in eeccfc1: ChatMarkdown overflow file plus refused files lost the overflow, and SlackChat.layerWebhook's deadline didn't cover reading the body.
  • ChatMarkdownError.remaining doesn't say which code fence it was cut in. Janitor no longer needs it, but a consumer recovering after another failure would.
  • layerWebhook gives no way to tell a deadline timeout from an unreadable bot user: both are a bare 503, so Janitor logs the status without a cause.
  • No post metadata option on Slack; no fail_if_not_exists on Discord.
  • mentionsSelf ignores replies to the bot; Janitor keeps that rule with replyTo.authorId.
  • Discord thread addresses carry no guild, so Janitor takes it from config for session keys.
  • DiscordChat.layerGateway can't resume from external storage, so it doesn't fit a Durable Object.
  • ChatMarkdown paces writes on the Clock, so platform tests need TestClock.

Validation

Locally on fb7f239, the same steps as CI:

  • vp install --frozen-lockfile: up to date
  • vp check: 0 errors (2073 warnings; the baseline was ~2000, the increase is all unstable-api-usage from the new imports and tests)
  • vp run @janitor/cluster#graphql:check: exit 0
  • vp test: 157 files, 1029 tests passed

Dogfooding and rollback

Dogfooding happens on production, as Tim approved: no isolated stage and no local run. After Deploy succeeds, representative Slack and Discord flows are exercised in channels agreed with Tim, and the results are recorded on EFF-3766.

Rollback is git revert of this PR's merge commit on main. Check runs on the revert, and Deploy redeploys production from it. The revert restores the registry 4.1.3 catalog and lockfile. No data migration is needed: the Slack and Discord app settings and scopes, the Discord intents, the secrets, the database, session keys and the gateway Durable Object's storage (shard session and seen ids) keep the format they have on main. After a rollback, check that vp install --frozen-lockfile resolves no pkg.pr.new URL.

main keeps pinning a PR snapshot until #10581 is released. Moving to the release is a separate PR.

Pins every Effect package to the pkg.pr.new snapshot of Effect-TS/effect#10581
at 42cf7c0 and moves Slack and Discord onto effect/chat, @effect/chat-slack and
@effect/chat-discord: posting, history, downloads, the Slack webhook and the
Discord gateway's dispatch.
- Post the overflow of a reply whose files are refused as text: ChatMarkdown's
  fallback keeps the overflow file, so the platform refuses it again.
- Bound the whole Slack webhook request by 2.5 seconds, body included.
- Keep Slack's subtype allow-list in ingress and history, so /me actions
  start nothing.
- Post a Discord reply to a since-deleted message as a plain message, as
  fail_if_not_exists: false did, instead of mentioning its author.
ChatMarkdownError.remaining is a raw slice of the input: posted on its own,
a continuation inside a code fence rendered outside it and lost its
indentation.
…ixes

Moves every Effect package to the eeccfc1 snapshot of Effect-TS/effect#10581.
ChatMarkdown now posts the overflow of a reply whose files are refused as
text, in the code fence it was cut in, and @effect/chat-slack's webhook
deadline covers reading the body. Janitor's workarounds for both come out;
their regression tests stay and run against the library.
The adapter answers a deadline timeout with a plain 503, so the timeout log
the removed deadline middleware wrote was gone. A route middleware now logs
every 503 from the response status alone, without naming a cause it can't
know and without the request's content.
@tim-smart
tim-smart merged commit c333d4f into main Nov 13, 2026
4 checks passed
@tim-smart
tim-smart deleted the agent/nelson/7cbf9fc23d34 branch November 13, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant