Skip to content

fix(adapters): accept dict StreamChunks in slack/github/google_chat streams#105

Merged
patrick-chinchill merged 4 commits into
mainfrom
claude/accept-dict-streamchunks-slack-github-gchat
May 28, 2026
Merged

fix(adapters): accept dict StreamChunks in slack/github/google_chat streams#105
patrick-chinchill merged 4 commits into
mainfrom
claude/accept-dict-streamchunks-slack-github-gchat

Conversation

@patrick-chinchill
Copy link
Copy Markdown
Collaborator

Summary

Replacement PR for #97 (could not push merge resolution to tony's fork from the automated session). Original commits by @tony-chinchill-ai preserved in branch history. Adds:

Changes (unchanged from #97)

Aligns slack/github/google_chat stream loops with the dict-shaped StreamChunk contract that thread.py (line 1218) and the Teams adapter already honor.

  • Slack adapter: dispatch loop gets isinstance(chunk, dict) and chunk.get("type") == "markdown_text" branch; send_structured_chunk rewritten to use a _read() helper that handles both dict and dataclass shapes; fallback warning rewritten to name the actual possible causes (missing scopes / malformed payload / transient API error) instead of pinning the blame on the app manifest.
  • GitHub & Google Chat adapters: same isinstance(chunk, dict) branch in each stream accumulator.

Why this is the right shape

Port-correctness fix, not a new contract. In TS chat-sdk, dict-vs-dataclass distinction doesn't exist; Python's hasattr check is object-only, so the port must add the dict branch explicitly. Mirrors dict branches already present in thread.py:640/661/1218 and adapters/teams/adapter.py:927.

Test plan

  • uv run ruff check src/ tests/ scripts/ — clean
  • uv run ruff format --check src/ tests/ scripts/ — clean (197/197)
  • uv run python scripts/audit_test_quality.py — 0 hard failures
  • uv run pytest tests/test_slack_api.py tests/test_github_adapter.py tests/test_google_chat_adapter.py -q — 132 passed
  • 2 new regression tests in TestStream (dict markdown_text routes through renderer; dict task_update forwarded as structured chunk)

Closes #97.


Generated by Claude Code


Generated by Claude Code

tony-chinchill-ai and others added 4 commits May 20, 2026 21:34
…treams

`_from_full_stream` (thread.py:1218-1226) explicitly forwards
`{"type": "markdown_text" | "task_update" | "plan_update", ...}` dict
chunks unchanged, so downstream adapters MUST accept both the dataclass
and dict shapes of `StreamChunk`. The Teams adapter already does
(adapter.py:927), but slack/github/google_chat only check
`hasattr(chunk, "type")` — which is False for dicts in Python — so dict
chunks were silently dropped or, worse, raised AttributeError inside
Slack's `send_structured_chunk` and downgraded the entire stream to
text-only with a misleading warning about missing assistant_view scopes.

Changes:
- slack/adapter.py: route dict markdown_text through the renderer; add
  a `_read(name)` helper in `send_structured_chunk` so dict and dataclass
  field access share one code path; tighten the fallback warning to
  enumerate the actual possible causes (missing scope OR malformed
  chunk OR transient Slack API error) instead of pointing solely at
  the manifest.
- github/adapter.py: accept dict markdown_text chunks in the accumulator.
- google_chat/adapter.py: same.
- test_slack_api.py: two regression tests in TestStream covering the two
  distinct adapter branches affected (renderer dispatch + structured
  chunk forwarding). Both fail when the dict branches are reverted.

This brings the Python adapters in line with the SDK's own internal
contract — adapters do not enforce a dataclass-only shape for chunks
that `_from_full_stream` is documented and tested to pass through as
dicts.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@patrick-chinchill, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 20 minutes and 29 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b511e477-dc30-473c-84ab-b07eb19430ae

📥 Commits

Reviewing files that changed from the base of the PR and between b1004b1 and ed1deaf.

📒 Files selected for processing (4)
  • src/chat_sdk/adapters/github/adapter.py
  • src/chat_sdk/adapters/google_chat/adapter.py
  • src/chat_sdk/adapters/slack/adapter.py
  • tests/test_slack_api.py

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for dict-shaped stream chunks (such as markdown_text and task_update) across the GitHub, Google Chat, and Slack adapters, ensuring they are handled similarly to their dataclass counterparts. It also refactors Slack's structured chunk processing to handle both dictionary and object shapes and adds corresponding unit tests. Feedback on the changes suggests using is not None instead of a truthiness check on text_value in the Slack adapter to avoid silently ignoring empty strings.

Comment on lines +3765 to +3766
if isinstance(text_value, str) and text_value:
await push_text_and_flush(text_value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The truthiness check and text_value silently ignores empty strings (""), which are falsy but valid string values. To avoid silently ignoring valid falsy values, we should use is not None instead of a truthiness check.

Suggested change
if isinstance(text_value, str) and text_value:
await push_text_and_flush(text_value)
if text_value is not None:
await push_text_and_flush(text_value)
References
  1. When checking for optional values that can be falsy but valid (e.g., 0, empty string, empty list), use is not None instead of a truthiness check to avoid silently ignoring them.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed1deaf0ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +3759 to +3766
elif isinstance(chunk, dict) and chunk.get("type") == "markdown_text":
# Dict-shaped StreamChunks are part of the contract: the
# `_from_full_stream` normalizer in thread.py forwards dict
# `{type: "markdown_text", ...}` items unchanged, so adapters
# must handle them the same as the dataclass form.
text_value = chunk.get("text")
if isinstance(text_value, str) and text_value:
await push_text_and_flush(text_value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve dict text in Slack no-thread fallback

When Slack streaming is invoked for a top-level DM/channel id with no thread_ts, this new dict handling is never reached because the method returns through the earlier post_message fallback, whose accumulator still only accepts strings and dataclass chunks. Since _from_full_stream forwards {"type":"markdown_text", "text": ...} dict chunks unchanged, those streams post an empty/partial fallback message instead of the rendered text; mirror this branch in the no-thread accumulator as well.

Useful? React with 👍 / 👎.

@patrick-chinchill patrick-chinchill merged commit be0852e into main May 28, 2026
10 checks passed
patrick-chinchill added a commit that referenced this pull request May 28, 2026
Synced to upstream vercel/chat@4.27.0 (release commit f55378a).

Upstream parity ports: chat.get_user across 8 adapters (#90), Slack Socket Mode (#86, closes #68), Slack dynamic bot_token resolver + webhook_verifier (#87), Teams native DM streaming (#88), Telegram MarkdownV2 (#89), Discord card text dedup (#89), Slack streaming team_id + Teams DM Graph conversation IDs (#85), Slack adapter bug-fix sweep (#89), ExternalSelect.initial_option + option_groups (#84), Slack @mention email-safe regex (#91).

Python-only improvements: markdown parser completeness (#101), streaming markdown list/table chunk-boundary (#99), Slack files_upload_v2 kwarg fix (#103), dict-shaped StreamChunk support (#105), Google Chat card-text markdown rendering (#92), adapter init logs + adapter-list in not-found errors (#104).

Sync-process documentation captures the review-loop discipline lessons from this wave (docs/UPSTREAM_SYNC.md + docs/SELF_REVIEW.md).

Fidelity workflow stays pinned to chat@4.26.0 — upstream did not publish a chat@4.27.0 tag for the Apr 30 monorepo cut.

4036 tests pass, 3 skipped, 0 failed.
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.

3 participants