feat(api): !stop ends the Slack agent's running turn
Merged
AV
2mo ago+11116+11116+01234567890123456789012345678901234567890123456789-8-8-0123456789
Summary
!stop(or!cancel) in a thread or DM ends the agent's running turn. The reply is "Stopping.", then the turn posts "Stopped. Anything I completed before that is listed below." with its Changes footer. With nothing running: "Nothing is running in this thread."- Deleting the "Working..." placeholder never did anything; the job runs on the API until it finishes or hits its deadline. This is the way to end it.
How It Works
!stopupsertsstop_requested_aton the thread session, stamped with the stop message's own Slack timestamp, so it works before the thread's first session row exists and while a turn is still in preflight.- A turn's claim keeps a stop request only if it is newer than the message that started the turn; older ones were aimed at an earlier turn and are cleared. So
!stopfollowed by a fresh mention does not stop the fresh one. - The agent loop checks the flag before each model request and before each tool call, comparing against the running turn's message. A set flag ends the turn through the same static-copy path as the time limit, so completed actions are kept and reported, and the placeholder and π are cleared.
- Cost: one small row read per step, at most a few dozen per turn.
Migration
0118_slack_thread_stop_requested: one nullable column. PR D (#7589) also generates an 0118; whichever merges second regenerates its migration.
Manual QA (Superset workspace)
- Slow request β while π is on, reply
!stopβ "Stopping.", then the stopped reply within a step, placeholder gone, π cleared - Same in a DM
-
!stopin an idle thread β "Nothing is running in this thread."; a mention right after runs normally - Two-tool request,
!stopduring the first tool β second tool never runs, footer lists the first
Testing
bun testin apps/api (169 pass) and packages/db (13 pass)bunx tsc --noEmit --pretty falsein apps/api and packages/db (exit 0)bunx biome check apps packages- The claim's ordering SQL and the upsert verified against a local Postgres
https://claude.ai/code/session_01YDDSQYG6WSZn4jXWTR3Pid
Summary by CodeRabbit
-
New Features
- Added
!stopand!cancelcommands to stop active Slack agent runs. - Stop commands are also recognized in direct messages.
- Stop requests apply based on message timing, including requests sent before a run begins.
- Added clear responses indicating whether a run was stopped or none was active.
- Added
-
Bug Fixes
- Prevented additional model requests and tool actions after a stop request is detected.
- Direct-message quieting commands remain ordinary text and do not disable agent responses.