{"record":{"id":"4bc2789fa4224734","repo":"chenhg5/cc-connect","slug":"codex-app-server-line-exceeds-max-size-d-bytes","errorCode":null,"errorMessage":"codex app-server line exceeds max size (%d bytes): %w","messagePattern":"codex app-server line exceeds max size \\((.+?) bytes\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/codex/appserver_session.go","lineNumber":1026,"sourceCode":"\t\t\ts.handleServerRequest(probe)\n\n\t\tdefault:\n\t\t\t// Notification (no id).\n\t\t\tvar notif rpcNotificationEnvelope\n\t\t\tif err := json.Unmarshal(data, &notif); err != nil {\n\t\t\t\tslog.Debug(\"codex app-server: bad notification envelope\", \"error\", err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ts.handleNotification(notif.Method, notif.Params)\n\t\t}\n\t}\n\n\terr := scanner.Err()\n\tif err != nil {\n\t\tif s.ctx.Err() == nil && !errors.Is(err, io.EOF) {\n\t\t\tslog.Warn(\"codex app-server read failed\", \"error\", err)\n\t\t\tif errors.Is(err, bufio.ErrTooLong) {\n\t\t\t\ts.emitError(fmt.Errorf(\"codex app-server line exceeds max size (%d bytes): %w\", maxLineSize, err))\n\t\t\t} else {\n\t\t\t\ts.emitError(fmt.Errorf(\"codex app-server connection closed: %w\", err))\n\t\t\t}\n\t\t}\n\t\ts.alive.Store(false)\n\t\ts.rejectPending(err)\n\t\ts.rejectPendingApprovals(err)\n\t\treturn\n\t}\n\n\ts.alive.Store(false)\n\ts.rejectPending(io.EOF)\n\ts.rejectPendingApprovals(io.EOF)\n}\n\nfunc (s *appServerSession) stderrLoop(r io.Reader) {\n\tdefer s.wg.Done()\n\tscanner := bufio.NewScanner(r)","sourceCodeStart":1008,"sourceCodeEnd":1044,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/appserver_session.go#L1008-L1044","documentation":"The app-server stdout read loop uses a bufio.Scanner bounded by maxLineSize; when a single JSON-RPC line exceeds that limit the scanner fails with bufio.ErrTooLong and the library emits this error. The oversized line is dropped — it cannot be parsed — and the session marks itself not alive and rejects pending requests.","triggerScenarios":"The codex app-server writes a single line larger than maxLineSize — typically a turn event embedding a huge file diff, a very long tool output, or a giant base64 payload — causing scanner.Scan() to fail with bufio.ErrTooLong.","commonSituations":"Agent reads or echoes an entire large file into a turn notification; codex streams compacted JSON with no line breaks for very large payloads; maxLineSize left at a small default while working with large repos.","solutions":["Increase maxLineSize (e.g. to 10–64 MB) to tolerate large JSON payloads from codex","Switch the read loop to bufio.Reader.ReadSlice/ReadString with manual buffering so arbitrarily long lines are handled instead of aborted","Reduce payload size on the codex side (truncate file contents passed to the agent, avoid pasting huge outputs)","If this recurs, replace Scanner with json.Decoder reading length-unbounded values from the same stream"],"exampleFix":"// before\nscanner := bufio.NewScanner(r)\nscanner.Buffer(make([]byte, 0, 64*1024), maxLineSize) // e.g. 1MB, too small\n// after\nconst maxLineSize = 64 << 20 // 64MB — large diffs/outputs no longer abort the reader\nscanner.Buffer(make([]byte, 0, 1024*1024), maxLineSize)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := sess.Send(ctx, prompt, nil)\nvar fatal bool\nif err != nil && !sess.IsAlive() {\n    // session dead (possibly ErrTooLong) → recreate session, optionally resend\n    sess, err = agent.StartSession(ctx, opts)\n}","preventionTips":["Size maxLineSize generously (tens of MB) for repo-scale payloads","Prefer bufio.Reader over bufio.Scanner for unbounded protocol lines","Truncate large file contents before handing them to the agent","Alert on this error — it means a whole turn's events were dropped"],"tags":["bufio","app-server","payload-size","stream"],"backgroundTag":"payload-too-large","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}