Skip to content

slack: forward message edits and deletions to the thread (BB-146) - #183

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-146-slack-plugin-edits-and-deletions-thr_4kpcrwi3ha
Oct 31, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-146-slack-plugin-edits-and-deletions-thr_4kpcrwi3ha

Conversation

@trotterdylan

@trotterdylan trotterdylan commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Implements BB-146. The bb-gate half (bitcomplete/bb-gate#67) already routes a DM edit or deletion as action: "edited" / "deleted" with the original message's ts; this half applies the correction in the plugin.

Any merge to bb-plugins main moves the pin, builds a new bb-server image and stages a restart for every developer's server — Restart now, or the 03:00–05:00 US Eastern quiet window.

Classification

owner-reviewed: this is the plugin half of the bb-gate Slack wake contract — it widens the wake schema (sessionEventSchema's action enum and the new ts field) that bb-gate-hooks sends against. No bigDecisions entry's paths match the changed files, so the decision is the owner's (@trotterdylan), not the project steward's. (Review round 1 corrected this line from no-review.)

What changes

  • hooks-client.ts: action accepts edited/deleted; the wake carries ts.
  • sessions.ts: a bounded per-session wakes map (last 8), keyed by ts, recording how each wake was delivered (held, queued with the queued row's id/version, or started).
  • server.ts: handleCorrection keys on action first and matches the wake by ts:
    • queued edit → rewrites the queued row in place (queuedMessages.update with expectedUpdatedAt); a row that moved on (404/409) falls back to a steer, a transient failure is left alone so the stale row cannot arrive after the correction;
    • started/finished edit → steers with the original and new text, and the correction owes its own reply when the turn already replied;
    • queued delete → removes the queued row and drops the wake's reply obligation;
    • started/finished delete → steers "disregard it" and owes no reply (and sets no thinking indicator);
    • unknown ts → dropped;
    • non-owner edit → held for the owner's confirmation, like the original; a non-owner deletion of their held message withdraws the pending request.
    • message.dispatched flips a queued wake to started; message.cancelled drops it.
  • README.md: documents the correction rule.

API note: the ticket names threads.editMessage for the queued branch. That endpoint rewrites a message that has already been dispatched and refuses while a queued row is claimed (bb core thread-edit-message.ts, hasClaimedQueuedThreadMessages), so it cannot rewrite a queued row. The queued branches therefore use threads.queuedMessages.update / delete — the in-place rewrite and removal the ticket describes — with expectedUpdatedAt as the queued-row optimistic check in place of expectedRequestSequence. The steer branches use the existing BB-145 path. Verified against bb core at desktop-v0.48.1 in review round 1.

Testing

  • npm run typecheck and npm test in plugins/slack: pass (159 tests; 12 new; not in the CI matrix).
  • The 12 new tests cover: queued edit rewrites in place (and a second edit), a queued message's files line survives a second edit, post-start edit steers, queued edit after message.dispatched steers, queued edit whose row moved on steers, a transient queued-update failure does not steer, queued delete removes, post-start delete steers, a deletion sets no thinking status, unknown-ts edit ignored, non-owner edit held, non-owner deletion of a held message withdraws it.
  • Not tested: the live bb-gate → Slack path end to end (no Slack workspace wired to a test server); the queued-row and steer calls are exercised against the plugin-SDK fake host.

— from bb thread thr_4kpcrwi3ha

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_e37xchuq7p.

— from bb thread thr_4kpcrwi3ha

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (glm-5p3, at eee53cb)

Owner review required: yes — cross-repo wake-contract/schema change: this is the plugin half of the contract change the ticket itself marks "Cross-repo contract change, owner-reviewed", and the diff widens the wake schema (sessionEventSchema's action enum and new ts field) that bb-gate-hooks sends against (the sender half, bb-gate#67, is already merged and shipping these wakes). bb stewards gate bitcomplete/bb-plugins#183 confirms no decide-list entry's paths match the changed files, so the decision is the owner's, not the project steward's. @trotterdylan, this one needs your approval.

Blockers

  1. PR body: Classification line — it claims no-review, but the change is owner-reviewed (trigger above; the ticket's own Done-when says so, and no bigDecisions entry's paths match, which makes it the owner's rather than the project steward's). The body must be corrected before merge.
  2. plugins/slack/server.ts:1129 — the queued-edit branch patches the recorded wake with files: event.files, but a correction wake never carries files: bb-gate's parseSlackMessageCorrection (hooks/slack.go, 401aa3d) sets no Files, so SlackWake.Files is nil and the plugin reads []. The first in-place rewrite is fine (rebuiltWakeText reads wake.files), but that patch empties the recorded files, so a second edit of the same file-bearing queued message rebuilds the row without its files line — the agent loses the "files were attached and not forwarded" framing. This defeats the schema's own comment in sessions.ts ("The message's attachments, so a rebuilt wake keeps its files line"). Fix: keep wake.files in the recorded entry (drop files from the patch at :1129, and mind the same wipe at :1147), and add a test for a second edit of a message that carried files.
  3. plugins/slack/server.ts:1303 — steerCorrection sets the "is thinking…" status for every correction, including deletions, which owe no reply. When a deletion's steer starts a turn on an otherwise-quiet thread and the agent obeys "No reply is needed for this deletion", nothing ever clears the indicator: slack_reply never runs, the backstop is not owed (the obligation was uncounted), slack_ack is refused ("Every message … already has its reply") because answered >= events, and onThreadIdle's status clear only covers untagged sessions. The Slack thread shows "bb is thinking…" indefinitely. Fix: skip the thinking status when owesReply is false (or clear it when the correction's own turn ends silent).

Suggestions

  • handleCorrection ignores a non-owner's deletion of their own held message ("nothing to do"), which leaves the owner's pending confirm r-… request standing for words that no longer exist. Withdrawing it (takePending + forgetWake + uncountWake, as the trusted path at :1163 does) would match the ticket's spirit; as is, the owner can just not confirm, so this is not blocking.
  • The queued-edit fallback steers on any update error, including a transient one where the row is still queued: the stale row then dispatches after the correction, so the agent sees the old text after being told the new one. Distinguishing 404/409 (row moved on — steer) from transient errors (report/keep, as sendToThread's failed path does) would avoid that ordering; rare, so not blocking.
  • handleEditedWake's wake.state === "held" branch looks unreachable — a held wake's author is a non-owner, and only they can edit it, so handleCorrection's untrusted check always intercepts first. Harmless as defence; a one-line comment saying so would keep the next reader from hunting for the case.

Checked

  • API note verified against bb core (checkout at desktop-v0.48.1, the current BB_REF): the reasoning holds. thread-edit-message.ts refuses while a queued row is claimed (hasClaimedQueuedThreadMessages → 409 "Wait for queued messages being sent before editing a message") and its request schema drops sendAt because "an edit rewrites a message that has already been dispatched" — a queued row has no turn to edit, so threads.editMessage cannot do the queued branch. threads.queuedMessages.update is the right call: the contract takes expectedUpdatedAt, 409s on claimed/stale, and returns the row with a new updatedAt (the PR stores it for the second edit); delete removes the row and the server emits message.cancelled on it; threads.send's response is the delivery: "sent" | "queued" union carrying queuedMessage.id/.updatedAt, which sendToThread reads exactly. The expectedUpdatedAt-for-expectedRequestSequence substitution is sound.
  • Ran: npm run typecheck and npm test in plugins/slack — pass (155 tests, 8 new). The plugins CI matrix does not include slack, so CI never ran this suite; I ran it.
  • Verified against ticket:
    • Service tests (bb-gate half, merged as slack: start a conversation's thread on the project's connected machine (BB-38) #67 at 401aa3d): DM edit/delete route with the right action and original ts; other subtypes still drop (TestSlackMessageCorrections in hooks/slack_test.go, including the channel_join and non-DM cases) — met.
    • Queued edit rewrites in place (incl. a second edit) — met, modulo blocker 2's files wipe; post-start edit steers — met; queued delete removes and drops the reply obligation — met; post-start delete steers, owes no reply — met, modulo blocker 3's stuck status; edit of an unknown ts ignored — met.
    • Depends on BB-145's steer path — present on main and reused correctly, including the steeredAt mark from the message.dispatch hook, which covers correction steers' backstop matching.
    • Cross-repo contract, owner-reviewed, bb-gate first — bb-gate half merged first; this half's lane is owner-reviewed (blocker 1).

— from bb thread thr_e37xchuq7p

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed in 4e79cc6:

  • Blocker 1 (Classification): fixed. The body now reads owner-reviewed — the plugin half of the bb-gate Slack wake contract, no bigDecisions entry's paths matching, so the owner decides.
  • Blocker 2 (files wipe): fixed. The queued-edit and steer patches no longer write files, so the recorded attachments survive a correction. Added a test: a second edit of a file-bearing queued message keeps its shot.png line.
  • Blocker 3 (thinking status on deletion): fixed. steerCorrection sets the indicator only when owesReply is true. Added a test that a deletion adds no status.
  • Suggestion (non-owner deletion of a held message): taken. An untrusted deletion of a held wake now withdraws the pending request (takePending + forgetWake + uncountWake). Added a test.
  • Suggestion (transient queued-update failure): taken. Only 404/409/410 steer (the row moved on); a transient error leaves the wake queued so the stale row cannot arrive after the correction. Added a test.
  • Suggestion (held branch unreachable): added a one-line comment saying the untrusted check intercepts it and the branch is kept as defence.

npm run typecheck and npm test in plugins/slack: pass (159 tests; 12 new).

— from bb thread thr_4kpcrwi3ha

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (glm-5p3, at 4e79cc6)

Blockers

  1. plugins/slack/server.ts:1236 — the new untrusted held-deletion branch can eat a confirmed instruction's outstanding reply. Trace: a non-owner's message is held (countWake, then the confirm prompt backstop answers that wake, so answered == events); the owner confirms it (the confirm <id> message gets its own counted, outstanding wake and the instruction is delivered under its ts — but the original message's record still says state: "held", nothing marks it confirmed); the non-owner then deletes their original message → the branch runs, takePending returns null (the request was already taken), forgetWake runs, and since answered < events is now true (the confirm wake is the outstanding one), uncountWake drops that wake's obligation — the confirmed instruction's turn can then end silent with no backstop. Two things follow: in the intended still-held case the uncountWake is a no-op (the prompt already answered the held wake), so it is dead-or-harmful as written; and the branch should only act when takePending actually returned the request — if nothing waits under the id, ignore the deletion like the confirmed guard does. (Marking the original wake confirmed — or forgetting it — at confirm time would fix the stale record at its source and is the more thorough version.) To be fair, this branch was my round-1 suggestion under-specified; the fix is small. A test for "non-owner deletes their message after the owner confirmed" should pin it.

Resolved since round 1

  • Blocker 1 (Classification claimed no-review): resolved by 4e79cc6 — the body now reads owner-reviewed with the right reasoning.
  • Blocker 2 (recorded files wiped on a queued edit, second edit drops the files line): resolved — the patches no longer write files, and the new "keeps a queued message's files line across a second edit" test pins it.
  • Blocker 3 (deletion steer leaves "is thinking…" stuck): resolved — the status is set only when owesReply, with a test.
  • Suggestions: all three addressed — held-request withdrawal on non-owner delete (this round's blocker is the sharp edge of it), transient queued-row errors no longer steer (only 404/409/410 do, with a 503 test), and the defensive held branch now says so in a comment.

Checked

  • Ran: npm run typecheck and npm test in plugins/slack — pass (159 tests; the plugins CI matrix still does not include slack, so I ran it).
  • Verified against ticket: unchanged from round 1 — service tests landed in bb-gate#67; queued edit rewrites in place, post-start edit steers, queued delete removes, post-start delete steers, unknown-ts edit ignored, BB-145 steer path reused correctly. All met; the one open item is the blocker above.

— from bb thread thr_e37xchuq7p

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 2 addressed in fd146ac:

  • Blocker 1 (held deletion can eat a confirmed instruction's reply): fixed. The untrusted held-deletion branch now withdraws only when takePending actually returns the request; when nothing waits under the id, the request was already confirmed, so the deletion is ignored and the confirm wake keeps its obligation. The harmful uncountWake is removed from both held-deletion paths (the confirm prompt already answered the held wake, so it was never owed a reply). Added a test: after the owner confirms, a non-owner deletion of the original message leaves events/answered unchanged and sends no steer.

npm run typecheck and npm test in plugins/slack: pass (160 tests).

— from bb thread thr_4kpcrwi3ha

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (glm-5p3, at fd146ac)

Owner review required: yes — cross-repo wake-contract/schema change (the plugin half of the owner-reviewed contract change the ticket names; the diff widens the wake schema bb-gate-hooks sends against). No bigDecisions entry's paths match the changed files, so the decision is the owner's. @trotterdylan, this one needs your approval.

No blockers remain.

Resolved since round 2

  • Blocker 1 (untrusted held-deletion could uncount a confirmed instruction's outstanding reply): resolved by fd146ac — both held-deletion paths withdraw only when takePending returns the still-waiting request, the harmful uncountWake is gone from both, a deletion after confirmation is ignored with the confirm wake keeping its obligation, and the new "ignores a non-owner's deletion after the owner confirmed their message" test pins the accounting (events/answered unchanged, no new send). Exactly the fix round 2 asked for.

Suggestions

  • None open. (The round-1 suggestions were all addressed in round 2; the stale held record after confirmation is now handled correctly at the consumer, so marking it confirmed at confirm time is no longer needed for correctness — it would only be tidiness.)

Checked

  • Ran: npm run typecheck and npm test in plugins/slack — pass (160 tests; the plugins CI matrix still does not include slack, so I ran it).
  • Verified against ticket, all met: service tests (edit/delete in a DM route with the right action and original ts; other subtypes still drop) landed in bb-gate#67 at 401aa3d; queued edit rewrites in place (files line kept across repeat edits); post-start edit steers; queued delete removes; post-start delete steers owing no reply and no stuck thinking indicator; unknown-ts edit ignored; BB-145's steer path reused correctly; the cross-repo contract is owner-reviewed with bb-gate first.
  • The PR's API note (threads.queuedMessages.update/delete rather than threads.editMessage for the queued branches) was verified against bb core at desktop-v0.48.1 in round 1 and holds.

— from bb thread thr_e37xchuq7p

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Approved fd146ac from the Stewards page

@trotterdylan
trotterdylan merged commit f5a1ce3 into main Oct 31, 2026
22 checks passed
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed lane, reviewer approved fd146ac, checks green, approved by the owner.
merge commit f5a1ce3
Note: merging this moves the pin and stages a restart for every developer's server (Restart now, or in the 03:00–05:00 ET quiet window).

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