internal/runtime/executor: MetaExecutor.ExecuteStream silently closes with err=nil on clean EOF before terminal response.completed/incomplete event

Open Beginner friendly
#7,971 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend

Research direction

Start in internal/runtime/executor/meta_executor_stream.go at ExecuteStream (lines 98, 253-255, 285-296), then compare the post-loop error path with meta_executor_execute.go:312. Reproduce with go test -v -race -count=1 -run TestRepro_MetaExecutorStreamSilentTruncationOnCleanEOF ./internal/runtime/executor. Done means a clean EOF with terminalDelivered == false emits a terminal StreamChunk error (BadGateway) and calls reporter.PublishFailure.

Written by the indexing model from the issue text.

Description

Is it a request payload issue?
  • Yes, this is a request payload issue.
  • No, it's another issue (internal/runtime/executor).
Describe the bug

(*MetaExecutor).ExecuteStream (internal/runtime/executor/meta_executor_stream.go:98, 253-255, 285-296) tracks terminalDelivered (set to true only upon receiving response.completed or response.incomplete), but after the scanner.Scan() loop exits it only checks if errScan := scanner.Err(); errScan != nil.

When an upstream HTTP 200 SSE stream closes cleanly (io.EOF, scanner.Err() == nil) before delivering a terminal event, !terminalDelivered is never checked. No error chunk is emitted and reporter.PublishFailure is never called (unlike (*MetaExecutor).Execute at meta_executor_execute.go:312), causing truncated responses to complete as HTTP 200 with err == nil.

Environment & verification scope
  • CLIProxyAPI revision: origin/dev at 32842348 (confirmed on v8.1.2)
  • OS / Go: Windows 11 amd64, go1.27.4
  • Component: internal/runtime/executor/meta_executor_stream.go (ExecuteStream)
End-to-End Pipeline Trace (Verified on origin/dev 32842348)
  1. (*MetaExecutor).ExecuteStream (meta_executor_stream.go:98, 253-255, 285-296) reads data: {"type":"response.output_text.delta",...} and exits scanner.Scan() on clean io.EOF (scanner.Err() == nil) with terminalDelivered == false.
  2. Post-loop cleanup skips emitting any error chunk when scanner.Err() == nil, closing out cleanly.
Minimal reproduction & Observed vs Expected
go test -v -race -count=1 -run TestRepro_MetaExecutorStreamSilentTruncationOnCleanEOF ./internal/runtime/executor

Observed output (origin/dev 32842348):

=== RUN   TestRepro_MetaExecutorStreamSilentTruncationOnCleanEOF
    repro_v812_exec_test.go:85: MetaExecutor.ExecuteStream closed with err=<nil> on clean EOF without terminal response.completed/incomplete
--- FAIL: TestRepro_MetaExecutorStreamSilentTruncationOnCleanEOF (0.00s)
Check / Field Observed (origin/dev 32842348) Expected
Clean EOF with terminalDelivered == false out closes with Err == nil Emits terminal StreamChunk{Err: ...} and calls reporter.PublishFailure
Suggested minimal fix

In (*MetaExecutor).ExecuteStream (meta_executor_stream.go:285-296), when scanner.Err() == nil && ctx.Err() == nil && !terminalDelivered, emit a terminal StreamChunk{Err: statusErr{code: http.StatusBadGateway, msg: "upstream stream closed before terminal event"}} and record failure.

What ran / Not run
  • Ran: Hermetic go test -v -race -count=1 -run TestRepro_MetaExecutorStreamSilentTruncationOnCleanEOF ./internal/runtime/executor against origin/dev (32842348).
  • Not run: Live upstream Meta stream.
Dominant language
Go
Stars
58.8k
Forks
9k
Avg merge
14h 20m
Merged PRs (30d)
67

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from router-for-me/CLIProxyAPI

All issues in router-for-me/CLIProxyAPI

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.