Skip to content

feat(web): expose public ts property on ChatStream#1880

Open
srtaalej wants to merge 1 commit into
mainfrom
ale-make-ts-public
Open

feat(web): expose public ts property on ChatStream#1880
srtaalej wants to merge 1 commit into
mainfrom
ale-make-ts-public

Conversation

@srtaalej
Copy link
Copy Markdown
Contributor

@srtaalej srtaalej commented May 27, 2026

Summary

  • Adds a public read-only ts property to ChatStream and AsyncChatStream, enabling users to call chat.update as a fallback when the server closes a stream due to undocumented timeouts.

Resolves #1859

Background

When Slack's server-side timeout kills a stream, both chat.appendStream and chat.stopStream return message_not_in_streaming_state. The message still exists but is stuck as a broken pill in the UI. The only recovery path is chat.update(ts=...), but ts was previously a private attribute (_stream_ts).

Changes

  • slack_sdk/web/chat_stream.py: Added ts property (read-only, returns Optional[str])
  • slack_sdk/web/async_chat_stream.py: Same (auto-generated via codegen)
  • tests/slack_sdk/web/test_chat_stream.py: Added test verifying ts is None before flush and set after
code snippet
from slack_sdk import WebClient
  from slack_sdk.errors import SlackApiError

  client = WebClient(token=...)


  def send_streaming(channel, thread_ts, team_id, user_id, content_iter):
      stream = client.chat_stream(
          channel=channel,
          thread_ts=thread_ts,
          recipient_team_id=team_id,
          recipient_user_id=user_id,
      )

      full_text = ""
      stream_alive = True

      for chunk in content_iter:
          full_text += chunk

          if stream_alive:
              try:
                  stream.append(markdown_text=chunk)
              except SlackApiError as e:
                  if e.response["error"] == "message_not_in_streaming_state":
                      stream_alive = False
                  else:
                      raise

          if not stream_alive:
              client.chat_update(channel=channel, ts=stream.ts, text=full_text)

      if stream_alive:
          stream.stop()
      else:
          client.chat_update(channel=channel, ts=stream.ts, text=full_text)

Test plan

  • Existing ChatStream tests pass
  • New test verifies ts is None before first flush and set after
  • CI passes

@srtaalej srtaalej requested a review from a team as a code owner May 27, 2026 18:02
@srtaalej srtaalej self-assigned this May 27, 2026
@srtaalej srtaalej added enhancement M-T: A feature request for new functionality discussion M-T: An issue where more input is needed to reach a decision labels May 27, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.13%. Comparing base (ff33cef) to head (406a8e3).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
slack_sdk/web/async_chat_stream.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1880      +/-   ##
==========================================
- Coverage   84.13%   84.13%   -0.01%     
==========================================
  Files         117      117              
  Lines       13337    13343       +6     
==========================================
+ Hits        11221    11226       +5     
- Misses       2116     2117       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

@WilliamBergamin WilliamBergamin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work 💯 this look good

Could we mirror the unit test to cover the async implementation, once added I think we are good to merge 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion M-T: An issue where more input is needed to reach a decision enhancement M-T: A feature request for new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

message_not_in_streaming_state after undocumented timeouts hit

2 participants