Skip to content

fix(bots): a bot woken by its own background work in a Slack DM is told to post itself - #50246

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/bot-dm-wake-note
Nov 27, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/bot-dm-wake-note

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When a bot starts a background job from a Slack DM and the job finishes later, the bot wakes up on its own. Anything it says then stays in Orca unless the bot posts it. For Slack threads, the bot is already told where the job came from and how to post there. Now the same note appears in a DM's own chat. The bot decides whether to post; Orca posts nothing by itself.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​23 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

What Changed

  • Before: orca orchestration worker-start in a bot's chat for a Slack DM, or for a thread inside a DM, printed no note. A turn that woke on its own there wasn't told that its final message stays in Orca, or that orca bot reply posts in the DM.
  • After: the note appears in those chats too: "this start came from the Slack conversation that woke you … orca bot reply --text "..." posts there".
  • The same proofs as for threads:
    • a connector message opened or joined the turn;
    • the turn's opening message carries this conversation's delivery stamp;
    • the turn's origin record names the same Slack channel.
  • Still no note:
    • the bot's own Chat (the shared one), including any older DM still bound to it;
    • another chat calling for it;
    • a channel with no thread.
  • No new posting path: plain orca bot reply already worked from such a turn in a DM's own chat. I checked the reply handler with a self-started turn in a per-DM chat, for both a bare DM and a thread inside a DM. The reply posted with no refusal. The connector service accepts a reply for any conversation bound to the host.

What this stops working for

Surface Changes?
Slack thread chats Nothing; same note, same rules.
A DM's own chat, a thread inside a DM Nothing stops. worker-start now prints the note when the turn is proven to be that DM's.
Bot's Chat (Home), including an older DM still bound to it Nothing; still no note, and bot reply there is still refused.
Orca-only chats, automations, terminals, remote (--on) starts Nothing; the note is read from the bot's own chat before the start is routed, as before.

Why

Slack DMs, and threads inside them, now each run in a bot chat of their own, the same as channel threads. The worker-start note was limited to channel threads only because DMs used to share the bot's Chat. That is no longer true for any new DM, so the same rule and the same proofs now apply to them. A larger saved-DM mechanism for the shared Chat (#50146) was closed in favor of this.

Linked Issue

No issue. This is a maintainer follow-up to #49406, which added the note for channel threads.

Visual Proof

The note and a later reply in a DM's chat, in dark and light, are in the details block below. Before this change, worker-start printed no note in a DM's chat.

Screenshots: the note in a DM's chat (dark, light) and a later reply

note dark

note light

later reply

Testing

  • I manually tested these changes locally: a scratch run of the real reply handler for a self-started turn in a per-DM chat (a bare DM and a thread inside a DM) posted with no refusal. The note was rendered in its chat row. macOS only; nothing here is platform-specific.
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

connector-wake-reply.test.ts drives the real connector.wakeReplyPlace handler. I removed each rule in turn and confirmed a test fails:

  • own chat only (not the bot's Chat);
  • a bare channel is refused;
  • the origin names the same channel;
  • the delivery mark;
  • the opener stamp.

Performance

None, because this only runs once per worker start from a bot chat. A DM chat now also does the origin read thread chats already do, which reads only the newest turn and gives up rather than reading the chat's history.

Risk

The riskiest part is naming a place the start didn't come from. A reply would then still go to the chat's own conversation, so the worst case is a misleading note. All three proofs must hold, and the bot's shared Chat is still excluded. Nothing is saved or migrated, and a plain revert undoes it.

Level: Low

AI Disclosure

Review

Self-reviewed for correctness, security, and performance. A fresh review and an independent regression audit of the final head found no code problems; the perf scan passed.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No change to security boundaries, platforms, SSH/remote hosts (the note is read from the bot's own chat before a start is routed), mobile, or saved data. An older machine without this change simply prints no note in a DM's chat.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…ld to post itself

Slack DMs, and threads inside them, now each run in a chat of their own. The
worker-start note stage 1 gives a thread chat now names a DM's own chat too, on
the same proofs (delivery mark, opener stamp, origin record), so a turn that
starts on its own there is told bot reply posts there. The bot's Chat still gets
no note.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: PASS (head 7cedcd0)

No perf findings. The change loosens one gate: wakeReplyPlace used to return early for DM chats and threads inside DMs, and now goes on to read the turn's origin for them. That read already ran for channel-thread chats on main, and it's the only work newly reached. Its cost is fixed per call and doesn't grow with history.

Work newly reached, one row per piece

Work Trigger Population Bound
connector.wakeReplyPlace handler gates (bot-wake-reply-place.ts:19-32) one per orca orchestration worker-start from a bot chat (CLI call, 5 s client timeout) 1 session O(1); slackPlaceOf is a split plus 2 regex tests
readBotTurnOrigin → readNewestBotActingTurn(..., widen=false) (bot-turn-origin.ts:23, bot-acting-turn-read.ts:25) same, now also for DM chats and DM-thread chats with a delivered turn whose origin is Slack newest turn only (latestTurns: 1, anchorsOnly, indexedOnly, turnShape) one indexed journal window read. indexedOnly throws JournalWindowNotIndexed (caught, returns null) instead of falling back to every send, so the cost never scales with chat history
db.getBotRequest / botRequestActsFor per message in that turn same messages in the newest turn's anchor rows sync node:sqlite point lookups on main by message_id (PRIMARY KEY); the count is bounded by one turn's sends, not by chats or history

Price at the reference fleet (100+ agents, a dozen calling the CLI every few seconds): only bot chats reach this, once per worker-start. Even if every CLI call were a worker-start, that's a few calls per second. Each call is one newest-turn indexed read plus a handful of PK lookups, about the same as the thread case already on main. No subprocesses, no timers, no subscriptions, no retained state.

Regression classes touched

  • Expensive code newly reachable past a gate: matched. The newly reached path is bounded by the newest turn and indexedOnly, has no history or fleet scan, and is the same work thread chats already paid on main. Disproved.
  • Sync fs or SQLite on Electron main: matched (getBotRequest). These are PK point lookups bounded by one turn, run once per worker-start, not per keystroke, poll or status update. Disproved.
  • New idle wakeups: no matching code. Nothing is added at idle (0 → 0/s on main, renderer and daemon).

Six questions

  1. Work before the skip gate: reviewed. The cheap gates (delivered, answer id, bot kind and id, Slack source, slackPlaceOf) all run before the origin read.
  2. Ownership multiplying work: not applicable. One call per CLI invocation, with no per-row or per-pane owners.
  3. Thread and storage layer: reviewed. The SQLite PK lookups run on main, and the journal read is bounded to one turn.
  4. Growth and progress: reviewed. latestTurns: 1 with no widening loop (widen=false returns on the first pass), so nothing grows with history.
  5. Execution host: not applicable. No host probes; it reads local runtime state only.
  6. Obsolete work stopping: reviewed. Nothing is retained; the CLI side gives up after 5 s, and the host-side read is bounded.

Not covered: no runtime timing was measured. The impact above comes from the work counts in the source.

@brennanb2025
brennanb2025 marked this pull request as ready for review November 27, 2026 02:10
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

wakeReplyPlace no longer requires a thread timestamp or excludes Slack channel IDs beginning with D. Tests cover channel and DM place attribution, including matching origins, delivery information, and bot-chat targets.

Merge Risk: Minimal · up to 7cedc

Bots woken by their own background work in a Slack DM now get the note telling them how to post a reply. Eligibility checks stay strict, and no concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a bot woken by its own background work in a Slack DM is now told to post itself. The changeset extends the worker-start note to DM and DM-thread bot chats, which match…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template closely. It includes ELI5, What Changed (before/after, scope table, and mechanism), Why, Visual Proof with screenshots, Testing with manual and automate…
Full details: Title check

Explanation

The title names the main change: a bot woken by its own background work in a Slack DM is now told to post itself. The changeset extends the worker-start note to DM and DM-thread bot chats, which matches this. The title is 86 characters, slightly long but still a single clear sentence.

Full details: Description check

Explanation

The description follows the repository template closely. It includes ELI5, What Changed (before/after, scope table, and mechanism), Why, Visual Proof with screenshots, Testing with manual and automated test notes, Performance, Risk with level and revert path, Agent skill boundary, Notes, and Checklist. The AI Disclosure section is empty, but the template says to skip it for internal StablyAI contributors, and the author does not appear to be an outside contributor. The Linked Issue section says no issue exists and calls this a maintainer follow-up to #49406. The template says outside contributors must link an issue, so this only matters if the author is an outside contributor. The Review section is brief but states self-review. The Performance section gives a reason. Remaining gaps are minor.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6e3d8847-fa6a-40e9-914e-a199804a7c4d
Commits

Reviewing files that changed from the base of the PR and between 4b7c4d4 and 7cedcd0.

Files selected for processing: 2

  • src/main/bots/bot-wake-reply-place.ts
  • src/main/runtime/rpc/methods/connectors/connector-wake-reply.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status for 7cedcd0

The problem: a bot that starts a background job from a Slack DM wakes up on its own when the job finishes. It wasn't told where the job came from or how to post there. Channel threads already got that note.

The change: the worker-start note now also names a DM's own chat and a thread inside a DM, on the same three proofs as threads. The bot's shared Chat still gets no note. Nothing posts on its own; the bot uses its normal reply command.

Verified:

  • An independent regression audit on the change merged onto current main found nothing to fix.
  • A fresh code review found it correct. It confirmed the origin place id for a DM is the DM's own channel, and that a reply from such a turn posts.
  • The perf scan passed: the only new work is the newest-turn origin read that thread chats already do.
  • Each rule has a test that fails without it.
  • A direct run of the reply handler for a self-started turn in a DM's chat posted, with no refusal.
  • CI is green.

Fixed after review: the PR body now follows the repo template.

Deferred: the DM test case reuses a "the thread …" label from the shared test helper. It is naming only and hides no failure.

@brennanb2025
brennanb2025 merged commit e0e058e into main Nov 27, 2026
83 of 84 checks passed
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