Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

A truncated streamed reply is accepted as a complete answer

未关闭
#1,467 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go, python

调研方向

Start with internal/provider/sse.go:129 and internal/provider/client.go:1741, then run the deterministic TestAStreamCutBeforeItsEndIsNotAnAnswer test. Compare it with TestStreamedTextAnswerCarriesNoToolCalls and the cut/hold stub.py scenarios. Done means premature EOF is treated as a stream failure, partial text is not finalized, terminal-frame streams still succeed, and the manual plus invalidates coverage are updated.

由索引模型根据 Issue 内容生成。

描述

area:provider area:session bug sev:serious

Seen on dev@debffabf6.

What happened

A stream that sends a content delta and then closes without finish_reason or [DONE] is returned as a complete answer. In the 2026-09-24 hand test, the chat finalized Partial ans. The same happened on #1410 and its dev base.

Replication

Deterministic (no model). Save as internal/provider/stream_cut_test.go and run go test ./internal/provider -run TestAStreamCutBeforeItsEndIsNotAnAnswer -count=1:

package provider

import (
	"context"
	"net/http"
	"testing"
)

// A stream that ends with neither a finish_reason nor [DONE] was cut; it is not an answer.
func TestAStreamCutBeforeItsEndIsNotAnAnswer(t *testing.T) {
	handler := http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
		writer.Header().Set("Content-Type", "text/event-stream")
		_, _ = writer.Write([]byte(`data: {"choices":[{"index":0,"delta":{"content":"Partial ans"}}]}` + "\n\n"))
	})
	client, err := NewClient(Config{
		APIKey: "k", BaseURL: "http://provider.test", Model: "sim/model", HTTPClient: handlerClient(handler),
	})
	if err != nil {
		t.Fatal(err)
	}
	ctx := WithStreamObserver(context.Background(), func(StreamEvent) {})
	response, err := client.CompleteWithMessages(ctx, userMessages("hi"))
	if err == nil {
		t.Fatalf("a stream cut before its end was returned as a complete answer: %q", response.Text())
	}
}

Today it fails with a stream cut before its end was returned as a complete answer: "Partial ans". The existing TestStreamedTextAnswerCarriesNoToolCalls, whose stream ends with finish_reason:"stop" and [DONE], is the control.

Through the real door (no model). This stub answers every request with one chunk and closes:

# stub.py: a provider whose every reply is one content chunk.
#   python3 stub.py cut   -> then the connection closes (no finish_reason, no [DONE])
#   python3 stub.py hold  -> then the connection stays open for ten minutes
import json, sys, time
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
MODE = sys.argv[1]
MODEL = "deepseek/deepseek-v4-flash"
class H(BaseHTTPRequestHandler):
    protocol_version = "HTTP/1.1"
    def log_message(self, *a): pass
    def do_GET(self):  # the model listing
        b = json.dumps({"object": "list", "data": [{"id": MODEL, "object": "model"}]}).encode()
        self.send_response(200); self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b)
    def do_POST(self):
        self.rfile.read(int(self.headers.get("Content-Length", "0")))
        self.send_response(200); self.send_header("Content-Type", "text/event-stream")
        self.send_header("Connection", "close"); self.end_headers()
        chunk = {"id": "c", "object": "chat.completion.chunk", "model": MODEL,
                 "choices": [{"index": 0, "delta": {"content": "Partial ans"}, "finish_reason": None}]}
        self.wfile.write(("data: " + json.dumps(chunk) + "\n\n").encode()); self.wfile.flush()
        if MODE == "hold": time.sleep(600)
        self.close_connection = True
srv = ThreadingHTTPServer(("", 0), H)
print("http://0.0.0.0:%d/v1" % srv.server_address[1], flush=True)
srv.serve_forever()
export CODEAF_HOME=$(mktemp -d) HOME=$(mktemp -d) OPENROUTER_API_KEY=<any non-empty value>
U=$(mktemp); python3 stub.py cut > "$U" & sleep 1
R=$(mktemp -d) && git -C "$R" init -q && cd "$R"
CODEAF_BASE_URL="$(cat "$U")" codeaf chat --no-host

Send reply with the word OK. Today the chat settles Partial ans as the reply.

Where

internal/provider/sse.go:129 returns EOF at transport close; internal/provider/client.go:1741 breaks its stream loop on that EOF even when no terminal marker was seen.

The fix

Track terminal completion separately from transport EOF. Treat a premature close as a cut eligible for the existing retry policy; do not journal the partial text as a finished answer.

Acceptance

  • e2e: codeaf chat against the cut stub above (or an httptest.NewServer stream in the tagged suite) that closes after one delta does not finalize Partial ans; the terminal-frame control does.
  • Unit: EOF with and without finish_reason or [DONE] has distinct outcomes.
  • Update the stream-failure manual and add the former EOF acceptance to invalidates.
主要语言
Go
星标
115
派生
14
平均合并
9 小时 35 分钟
30 天内合并 PR
752

环境准备

我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Agent-Field/CodeAF 的其他 Issue

查看 Agent-Field/CodeAF 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。