Skip to content

fix(agent-scan): accept null content deltas and usage-only chunks in SSE replies - #731

Merged
boy-hack merged 1 commit into
Tencent:mainfrom
jaeminbird:fix/agent-scan-openai-sse-chunks
Oct 30, 2026
Merged

boy-hack merged 1 commit into
Tencent:mainfrom
jaeminbird:fix/agent-scan-openai-sse-chunks

Conversation

@jaeminbird

Copy link
Copy Markdown
Contributor

Summary

_parse_sse_response fails on two standard OpenAI stream shapes, so the HTTP provider check reports a working streaming endpoint as an error:

  • A delta with "content": null (OpenAI tool-call chunks, DeepSeek reasoning chunks) reaches "".join(...): sequence item 0: expected str instance, NoneType found.
  • With stream_options.include_usage, the last chunk is {"choices": [], "usage": {...}}, and last_data.get("choices", [{}])[0] raises list index out of range.

Content is now appended only when it is a string, and finish_reason comes from the last chunk that carries one.

Type of change

  • Bug fix

How was this tested?

  • A real local text/event-stream server through _make_http_request: both streams failed before; now success=True with output Hello.
  • Two new tests in agent-scan/pytests/test_agent_adapter.py fail on main and pass with the fix; pytest agent-scan/pytests passes (Python 3.12).

Related issue

N/A

Checklist

  • go build ./... succeeds locally (no Go changes)
  • I followed the existing file/rule format conventions for this contribution type
  • I have not introduced hardcoded secrets or credentials

@boy-hack

Copy link
Copy Markdown
Collaborator

Verified locally — both crashes reproduce on main and the fix resolves them cleanly.

Reproduction on main (isolated worktree at origin/main):

  • Tool-call/reasoning chunk with "content": null → TypeError: sequence item 0: expected str instance, NoneType found at the "".join(...) accumulation.
  • Usage-only final chunk ("choices": [] with stream_options.include_usage) → IndexError: list index out of range at last_data.get("choices", [{}])[0].

Fix verification (isolated worktree at PR head 2d5f8610):

  • Null-content delta is skipped (isinstance(content, str) guard); output = "Hello".
  • finish_reason is now accumulated from the last chunk that carries one instead of read from the final chunk, so usage-only tails no longer crash; result: finish_reason="stop" with usage preserved.

Suite: main = 68 passed; PR head = 70 passed (the 2 new regression tests account for the delta, zero drift).

CI green (GITHUB_OPENSOURCE_SCAN_PIPELINE@PULL_REQUEST). Diff scope is 2 files in agent-scan only. LGTM — merging.

@boy-hack
boy-hack merged commit 851e3f2 into Tencent:main Oct 30, 2026
2 checks passed
@jaeminbird
jaeminbird deleted the fix/agent-scan-openai-sse-chunks branch October 30, 2026 06:40
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