Skip to content

feat: stop in-progress runs with the native stop button - #317

Draft
zimeg wants to merge 1 commit into
mainfrom
stop-button
Draft

zimeg wants to merge 1 commit into
mainfrom
stop-button

Conversation

@zimeg

@zimeg zimeg commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

This pull request adds support for the native stop button to all four starter agents, following agent_session_stopped.

  • Each manifest.json subscribes to agent_session_stopped. The starters already set the session to processing with set_status, so Slack now shows a stop button in place of a loader the user can't interact with.
  • A new agent_session_stopped.py listener stops the thread's in-flight runs, moves the session back to active with agents_sessions_setStatus, then posts "Stopped." in the thread. Slack doesn't change the status on a stop, so the app has to.
  • app_mentioned.py and message.py register each run before setting the status. A run that was stopped posts nothing more: no reply, and no ":warning: Something went wrong" for the stop.
  • How each subproject stops the run:
    • claude-agent-sdk (async): an asyncio.Event per run. When the stop button sets it, ClaudeSDKClient.interrupt() is called.
    • openai-agents-sdk (sync, so listeners run on worker threads): a threading.Event per run. StopHooks in agent/agent.py checks it in on_llm_start and on_tool_start, so the run ends before its next model or tool call.
    • pydantic-ai (sync): a CancellationToken per run, passed to run_sync. The token is thread-safe and also cancels a model call that's already under way.
    • vercel-ai-sdk: on Vercel, the stop event arrives in a different function invocation than the run it stops, so in-memory state can't reach the run. The stop is recorded in Runtime Cache (thread_context/stops.py) with its event_ts. The run checks it at each StreamStart and ends before the next step. It also checks before posting. A run counts as stopped only when the stop is newer than its message, so later messages start fresh. A model call that's already under way finishes before the run stops, along with any tools it calls, Slack MCP tools included. A cache that can't be read counts as not stopped, so a run's own reply or error still posts.
  • The READMEs get a "Stop button" entry under Using the App and list the new files.

The coding agents' stop handling is the reference. They also clear pending Approve / Deny buttons on a stop, but the starters have no approvals, so that part is left out.

Testing

  • Run each subproject with slack run (and vercel-ai-sdk deployed to Vercel) in a workspace with agent sessions.
  • Mention the agent or DM it, then click the stop button while it's thinking. Confirm "Stopped." posts in the thread, the loader clears, and no reply or warning follows.
  • Send another message in the same thread and confirm the agent answers normally.

🤖 Generated with Claude Code

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg added the enhancement New feature or request label Dec 1, 2026
@zimeg zimeg self-assigned this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant