Socket Mode: ack() with text starting with '{' is never sent (JSONDecodeError)

Aberta
#1,594 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@sahiljagtap08 já está trabalhando nisso.

Desde 8/10/2026.

  • #1593 de @sahiljagtap08 — aberto

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
backend

Direção de pesquisa

The JSON parse happens in send_response in slack_bolt/adapter/socket_mode/internals.py and in send_async_response in async_internals.py, where a body starting with { is passed to json.loads without error handling. Read those two functions, then reproduce with an ack string such as "{curly braces". Done means both paths fall back to sending the text as a plain string instead of raising. A fix already exists in open PR #1593, so check that thread before starting new work.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

auto-triage-stale
Reproducible in:
The slack_bolt version
slack_bolt==1.30.0
slack_sdk==3.45.0
Python runtime version
Python 3.12.5
OS info
macOS 27.0
Steps to reproduce:

In Socket Mode, call ack() with a plain text string that starts with { but is not valid JSON.

import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

app = App(token=os.environ["SLACK_BOT_TOKEN"])

@app.command("/hello")
def hello(ack):
    ack("{curly braces are fun}")

SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
  1. Start the app in Socket Mode.
  2. Run /hello in Slack.
Expected result:

Slack receives the ack and shows the text {curly braces are fun} as the response.

Actual result:

The ack is never sent. Slack shows "failed with the error operation_timeout" and the app logs a json.JSONDecodeError.

The cause is in slack_bolt/adapter/socket_mode/internals.py (send_response) and async_internals.py (send_async_response). They decide the ack body is JSON by checking whether the text starts with {, and then call json.loads() on it without handling a parse failure:

if content_type.startswith("application/json"):
    payload = json.loads(bolt_resp.body)

BoltResponse sets Content-Type: application/json for any string body that starts with {, so the same problem happens with ack("{", ...), ack("{foo"), or any text that happens to begin with that character. The non-Socket-Mode HTTP path does not have this issue because the body is sent through as-is.

I have a fix ready in #1593 that falls back to sending the string as {"text": body} whenever it cannot be parsed as a JSON object. Opening this issue at the maintainers' request so it can be tracked.

Requirements

I have read the Contributing guidelines and Code of Conduct.

Linguagem predominante
Python
Estrelas
1.3k
Forks
300
Merge médio
19h 33min
PRs com merge (30d)
25

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de slackapi/bolt-python

Todas as issues de slackapi/bolt-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.