Skip to content

fix(labels): renderizar JSON no GET/POST de labels (corrige 204 que apagava tags)#145

Open
agbid wants to merge 1 commit into
evolution-foundation:mainfrom
agbid:fix/labels-endpoint-204-render
Open

fix(labels): renderizar JSON no GET/POST de labels (corrige 204 que apagava tags)#145
agbid wants to merge 1 commit into
evolution-foundation:mainfrom
agbid:fix/labels-endpoint-204-render

Conversation

@agbid

@agbid agbid commented Jun 13, 2026

Copy link
Copy Markdown

Resumo

  • Cherry-pick do commit fe17f72 (já presente em develop) para main como hotfix.
  • LabelConcern#index e #create setavam @labels mas não renderizavam resposta, e não há view jbuilder — o Rails respondia 204 No Content com corpo vazio.
  • Qualquer consumidor que lê labels atuais via GET /conversations/:id/labels (ex.: a tool manage_conversation_labels do AI Processor) recebia 204 vazio, concluía "0 labels" e, como o POST faz update_labels (replace, não append), um "add" do agente apagava todas as labels existentes da conversa — incluindo atendimento_ia, que mantém a IA elegível para responder. Sem ela, o postback seguinte falha (422) e a resposta é descartada.

Mudança

render json: { payload: @labels } em index e create (formato payload já é o esperado pelos consumidores existentes).

Descoberto via

Teste end-to-end do agente "Inter Rural - Atendimento" com allow_manage_labels=true: um remove de label reportou sucesso ("None of the requested labels were present; nothing to update") mas a label permaneceu no banco — comportamento consistente com current_labels sempre vindo [] por causa do 204.

Test plan

  • Aplicar em ambiente de teste e repetir: GET /conversations/:id/labels deve retornar {"payload": [...]} com as labels reais (não 204).
  • add de uma label em conversa que já tem outras labels deve preservar as existentes.
  • remove de uma label existente deve realmente removê-la (labels resultante sem o item removido).

Summary by Sourcery

Return labels as JSON payload from label create and index actions to prevent 204 responses that cleared conversation tags.

Bug Fixes:

  • Fix label create endpoint to respond with the current labels in a JSON payload instead of an empty 204 response.
  • Fix label index endpoint to return the existing labels in a JSON payload so consumers can correctly preserve and update conversation labels.

…pagava tags)

LabelConcern#index e #create setavam @labels mas não renderizavam nada, e não
há view jbuilder para o controller — então o Rails respondia 204 No Content com
corpo vazio. Isso quebrava qualquer consumidor do endpoint que lê os labels
atuais: a tool manage_conversation_labels do AI Processor faz GET antes de um
add, recebia 204 vazio, concluía "0 labels", e como o POST faz update_labels
(replace, não append) acabava apagando todas as etiquetas existentes — incluindo
atendimento_ia, que mantém a IA elegível. Sem ela, o postback seguinte dá 422 e
a resposta é descartada.

Correção: render json: { payload: @labels } em ambas as actions. Formato payload
é o esperado pelos consumidores (a tool normaliza via chave payload). O frontend
não consome este GET (lê labels por broadcast), então a mudança é de baixo risco.
@sourcery-ai

sourcery-ai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds explicit JSON rendering for labels in the LabelConcern index and create actions so that GET/POST /labels return the current labels instead of a 204 No Content, preventing clients from mistakenly clearing existing labels.

Sequence diagram for GET/POST labels JSON rendering

sequenceDiagram
    actor Client
    participant LabelsController
    participant Model

    Client->>LabelsController: GET /conversations/:id/labels
    LabelsController->>Model: label_list
    Model-->>LabelsController: label_list
    LabelsController-->>Client: render json payload

    Client->>LabelsController: POST /conversations/:id/labels
    LabelsController->>Model: update_labels(labels)
    LabelsController->>Model: label_list
    Model-->>LabelsController: label_list
    LabelsController-->>Client: render json payload
Loading

File-Level Changes

Change Details Files
Ensure label index and create actions return JSON payload with current labels instead of an empty 204 response.
  • After updating labels in create, assign model.label_list to an instance variable and render it as JSON under the payload key.
  • In index, load model.label_list into an instance variable and render it as JSON under the payload key.
  • Align response shape with existing consumers by keeping the { payload: [...] } format.
app/controllers/concerns/label_concern.rb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

2 participants