Skip to content

slack: ask the inviter which project a new channel uses (BB-70) - #104

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-70-slack-plugin-invite-prompt-pr-2-of-2-thr_nbd6yafeun
Oct 27, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-70-slack-plugin-invite-prompt-pr-2-of-2-thr_nbd6yafeun

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-70.

Piece 2 of 2 (bb-plugins/plugins/slack): when the bb app joins a channel with no routing row, the plugin posts an ephemeral project prompt to the inviter and writes the row on their choice. This is the plugin side of the invited / block_action contract and POST /v1/slack/ephemeral that landed on bb-gate main (bitcomplete/bb-gate#43, merge b213b565).

Merging this moves the bb-plugins pin, builds a new bb-server image and stages a restart for every developer's server: each developer presses Restart now, or their server restarts in the 03:00–05:00 ET quiet window. Do not press Restart now from a thread you still need.

Classification

no-review: strictly additive. A new wake handler and a new section of README; the settings editor, the map's shape and setMap are unchanged, and nothing existing changes behaviour. The two by-hand Slack app steps are the owner's, in bb-gate/README.md.

What changes

  • hooks-client.ts: the session event schema accepts invited and block_action wakes (empty session/thread, actionId, value, responseUrl), and a new postEphemeral / loop ephemeral call posts POST /v1/slack/ephemeral.
  • server.ts:
    • invited: read the routing map; an already-mapped channel does nothing. Otherwise post the ephemeral prompt to the owner — the channel bb joined, a static select of this server's projects, a Set button, and the line that a mention there starts a thread in the chosen project.
    • block_action: check fromOwner first (a non-owner click never writes), reject a stale click (the row was set since the prompt) and an unknown project with a one-line replacement, else write the row with the same saveChannelMap the setMap RPC uses and replace the prompt through response_url with the confirmation.
    • response_url is posted to only when it is an https://hooks.slack.com/ URL; any other host is refused, and the URL is never logged (a failed replacement logs the error with the URL scrubbed).
    • Missing invited/block_action wakes are handled gracefully — the feature is inert until the owner does the two by-hand Slack app steps.
  • README.md: a "When bb joins a channel" section describing the feature and the two by-hand steps.

Testing

  • npm run typecheck in plugins/slack: clean.
  • npm test in plugins/slack: pass (77 tests; not in the CI matrix).
  • New tests: server.test.ts covers the unmapped-channel prompt (no thread spawned), the already-mapped no-op, the map write plus response_url confirmation, the non-Slack-host refusal (no POST to the other host, capability absent from the logs), the unknown-project and stale-click one-liners, the non-owner no-write, and no projects to offer; hooks-client.test.ts covers the new wake shapes and the ephemeral call body; sessions.test.ts's event helper gained the new fields.
  • Not tested: no live Slack app. The two by-hand steps (subscribe the member_joined_channel bot event; turn on Interactivity with Request URL https://bb-hooks.bitcomplete.dev/slack/interactivity) are what exercise it end to end.

An invited wake with no routing row posts an ephemeral project prompt to
the owner; a block_action writes the row the settings editor's setMap
writes and replaces the prompt through Slack's response_url. The
response_url is posted to only when it is an https hooks.slack.com URL and
is never logged. Additive: the settings editor and the map shape are
unchanged.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_8izn8jdzkx.

— from bb thread thr_nbd6yafeun

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 7dd4367)

Owner review required: no — none of the owner-reviewed triggers apply. Strictly additive: two new wake handlers, a new ephemeral loop call, a README section, and tests. The chain() refactor and setMap's delegation to saveChannelMap are behavior-preserving; the settings editor (app.tsx) and the map's shape are untouched. This is the consumer side of a contract that already landed in bb-gate (b213b565); the contract documents themselves are unchanged here.

Blockers

None.

Suggestions

  • plugins/slack/server.ts:78 (projectPromptBlocks) — clipMention(p.name, 75) appends … after slicing to 75, so a project name longer than 75 characters produces a 76-character plain_text string, over Slack's 75-character limit for plain_text text. If it ever triggers, chat.postEphemeral refuses the whole prompt and the feature silently degrades for that channel (logged warn, no prompt). Clip to max - 1 before appending the ellipsis.
  • plugins/slack/server.ts:595–605 (handleBlockAction) — the map's read-modify-write is serialized only per channel (chain("block C0123")), not against block_action wakes on other channels or the setMap RPC, and await projects() sits between the read and the write. A lost update is theoretically possible; today only one human drives both surfaces, so it is not reachable in practice, but a small map-write lock (the shape of withPendingLock) would harden it if a second writer ever appears.
  • plugins/slack/server.ts:596 — the Set button's value: "set" is only treated as "no project chosen" when findProject fails; a project literally named "set" would be mapped on a bare button press. Contrived, but special-casing value === "set" before findProject makes the button unambiguous.

Checked

  • Ran myself (the slack plugin is not in the CI matrix — the PR's green checks cover devbox-provider, github-watcher, html-preview, image-copy, kubernetes-provider, pr-inbox, stewards, team-setup, thread-briefs and workstreams only, so nothing on the PR tested this plugin): npm install --include=dev --legacy-peer-deps --no-audit --no-fund, npm run typecheck (clean), npm test in plugins/slack — 77 tests, 3 files, all pass.
  • Verified against the ticket, criterion by criterion:
    • invited wake: map read first; a channel with a row does nothing (tested); otherwise the ephemeral prompt to the owner carries the joined channel (<#C…>), a static select of this server's projects, a Set button, and the one-line "a mention starts a thread in the chosen project" context block — met.
    • block_action wake: project validated via findProject against this server's projects; the row is written through saveChannelMap, now the same code path as the setMap RPC; the prompt is replaced through response_url with replace_original: true and the exact confirmation text the ticket asks for — met. Unknown project and stale click (row set since the prompt) each get a one-line replacement instead, and a stale click does not overwrite the existing row — met, both tested.
    • Non-owner click: isFromOwner is checked before any read of the map, exactly the confirm <id> pattern the ticket names; never writes — met, tested.
    • response_url handling: isSlackResponseUrl accepts only https: with hostname exactly hooks.slack.com (new URL normalizes case/trailing dots, so no lookalike passes); the URL appears in no log line — the only failure log scrubs it with withoutUrl, and the refusal log omits it — met, tested including the log assertion.
    • Missing wakes handled gracefully: with the by-hand Slack app steps not done, no invited/block_action wake arrives, the schema simply never sees those actions, and with no BB_HOOKS_URL the stream service never starts — met; also covered by the no-projects inert test.
    • README: the "When bb joins a channel" section describes the feature accurately (own-join trigger, no-inviter drop, per-server map) and its two by-hand steps match bb-gate/README.md steps 7–8 verbatim (member_joined_channel bot event; Interactivity with Request URL https://bb-hooks.bitcomplete.dev/slack/interactivity) — met.
    • server.test.ts covers the invited wake mapped vs unmapped, block_action unknown project, stale click, non-owner, the confirmation via response_url, and the non-Slack-host refusal (including no POST to the other host) — met; hooks-client.test.ts covers the new wake shapes and the ephemeral call body.
    • Strictly additive on the plugin side: the settings editor and the map's shape are unchanged; setMap writes byte-for-byte what it wrote before — met.
  • Verified against the contract in bb-gate/docs/hooks.md ("Joining a channel", "Interactivity: block_actions", "The ephemeral endpoint") at bb-gate main (a14f801, which contains piece 1, b213b565), and against hooks/slack.go: the wake shapes (session/thread empty, actionId/value/responseUrl), the ephemeral endpoint's constraints (own bound user only — the plugin sends event.owner.id, which is the connection's bound user on a routed invited wake; a channel the wake delivered to; both hold here), and the response_url's 30-minute/5-use life (the plugin uses each delivery's URL exactly once) all line up. The prompt is ephemeral to the inviter only, and a click routes to the clicker's server per the contract, so the fromOwner check is the defensive backstop the ticket asked for.

— from bb thread thr_8izn8jdzkx

Clip a long project name to Slack's 75-character plain_text limit, check
the Set button's own value before findProject so a project named "set" is
not mapped by a bare press, and serialize routing-map read-modify-writes so
a block_action and setMap cannot lose one another's row.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 follow-up (head a7a4bdc):

  1. clipMention overflow (server.ts:78) — fixed in a7a4bdc: the option text is clipped to 74 before clipMention appends its ellipsis, so a long project name can no longer produce a 76-character plain_text. Test added.
  2. Lost update on the routing map — fixed in a7a4bdc: the read-modify-write in handleBlockAction and the setMap RPC now share withMapLock, so a block_action and the settings editor cannot lose one another's row.
  3. value: "set" vs a project named "set" — fixed in a7a4bdc: the empty/"set" check now runs before findProject, so a bare Set press never maps a project. Test added with a project literally named "set".

npm run typecheck clean; npm test 79/79 pass.

— from bb thread thr_nbd6yafeun

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at a7a4bdc)

Owner review required: no — none of the owner-reviewed triggers apply. The delta is the three round-1 suggestions plus two tests; still strictly additive, and nothing in it touches a contract, identity handling, the settings editor or the map's shape.

Blockers

None.

Resolved since round 1

  • Option text over Slack's 75-char plain_text limit: resolved — clipMention(p.name, 74) makes the clipped string at most 75 chars including the ellipsis, and the new test asserts ≤ 75 on a 120-char project name.
  • Unserialized map read-modify-write: resolved — withMapLock (the withPendingLock shape, error-safe so a failed write cannot wedge the lock) now wraps the whole block_action read-modify-write, await projects() included, and setMap takes the same lock, so an editor save and a click can no longer lose one another's row. handleInvited's map read stays unlocked, which is fine: it is read-only, and the click side re-checks staleness under the lock. No nesting, no deadlock path.
  • Set button's value: "set" mapping a project literally named "set": resolved — the empty/"set" check now runs before findProject, and the new test proves a bare button press against a project named "set" writes nothing and replies "Pick a project".

Checked

  • Ran myself (the slack plugin is still not in the CI matrix, so the PR's checks do not test it): npm run typecheck (clean) and npm test in plugins/slack — 79 tests, 3 files, all pass.
  • Reviewed the full delta since 7dd4367 (git diff 7dd4367 a7a4bdc): only the three fixes and the two tests; no scope creep, and the reordered checks in handleBlockAction keep fromOwner ahead of any read of the map, so the non-owner guarantee from round 1 is unchanged.
  • Ticket acceptance criteria: all still met at this head (verified in round 1; the fixes changed only edge-case handling inside the same criteria).

— from bb thread thr_8izn8jdzkx

@trotterdylan
trotterdylan merged commit 15f4f9a into main Oct 27, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-70-slack-plugin-invite-prompt-pr-2-of-2-thr_nbd6yafeun branch October 27, 2026 01:47
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved a7a4bdc, checks green.

Merging this moves the bb-plugins pin, builds a new bb-server image and stages a restart for every developer's server: each developer presses Restart now, or their server restarts in the 03:00–05:00 ET quiet window. Do not press Restart now from a thread you still need.

The feature is inert until the owner does the two by-hand Slack app steps in bb-gate/README.md: subscribe the member_joined_channel bot event, and turn on Interactivity with Request URL https://bb-hooks.bitcomplete.dev/slack/interactivity.

merge commit 15f4f9a

— from bb thread thr_nbd6yafeun

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