Skip to content

Commit 4e02986

Browse files
committed
fix: increase scanner buffer limit and track stream errors in tape (babysit)
- scanMaxID: increase bufio.Scanner buffer to 10MB to handle large tool outputs that exceed the default 64KB token limit - OnEndWithStreamOutput: track stream read errors and emit run event with "error" status instead of always reporting "ok"
1 parent 55bb3dd commit 4e02986

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

pkg/tape/eino_handler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,15 @@ func (h *EinoHandler) OnEndWithStreamOutput(ctx context.Context, info *callbacks
230230
output.Close()
231231
}()
232232
var chunks []callbacks.CallbackOutput
233+
var streamErr error
233234
for {
234235
ch, err := output.Recv()
235236
if errors.Is(err, io.EOF) {
236237
break
237238
}
238239
if err != nil {
239240
log.Printf("tape stream output recv: %v", err)
241+
streamErr = err
240242
break
241243
}
242244
chunks = append(chunks, ch)
@@ -250,7 +252,11 @@ func (h *EinoHandler) OnEndWithStreamOutput(ctx context.Context, info *callbacks
250252
if msg != nil {
251253
h.write(Message(messageToMap(msg), h.baseMeta()))
252254
}
253-
runData := map[string]any{"status": "ok"}
255+
status := "ok"
256+
if streamErr != nil {
257+
status = "error"
258+
}
259+
runData := map[string]any{"status": status}
254260
if usage != nil {
255261
runData["usage"] = map[string]any{
256262
"prompt_tokens": usage.PromptTokens,

pkg/tape/jsonl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func scanMaxID(path string) (int64, error) {
4444

4545
var maxID int64
4646
sc := bufio.NewScanner(f)
47+
// Allow entries up to 10 MB to handle large tool outputs in tape lines.
48+
sc.Buffer(make([]byte, 0, 64*1024), 10*1024*1024)
4749
for sc.Scan() {
4850
var row struct {
4951
ID int64 `json:"id"`

0 commit comments

Comments
 (0)