chenhg5/cc-connect · error
codex app-server line exceeds max size (%d bytes): %w
Error message
codex app-server line exceeds max size (%d bytes): %w
What it means
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.
Source
Thrown at agent/codex/appserver_session.go:1026
s.handleServerRequest(probe)
default:
// Notification (no id).
var notif rpcNotificationEnvelope
if err := json.Unmarshal(data, ¬if); err != nil {
slog.Debug("codex app-server: bad notification envelope", "error", err)
continue
}
s.handleNotification(notif.Method, notif.Params)
}
}
err := scanner.Err()
if err != nil {
if s.ctx.Err() == nil && !errors.Is(err, io.EOF) {
slog.Warn("codex app-server read failed", "error", err)
if errors.Is(err, bufio.ErrTooLong) {
s.emitError(fmt.Errorf("codex app-server line exceeds max size (%d bytes): %w", maxLineSize, err))
} else {
s.emitError(fmt.Errorf("codex app-server connection closed: %w", err))
}
}
s.alive.Store(false)
s.rejectPending(err)
s.rejectPendingApprovals(err)
return
}
s.alive.Store(false)
s.rejectPending(io.EOF)
s.rejectPendingApprovals(io.EOF)
}
func (s *appServerSession) stderrLoop(r io.Reader) {
defer s.wg.Done()
scanner := bufio.NewScanner(r)View on GitHub (pinned to 4000b2338a)
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
Example fix
// before scanner := bufio.NewScanner(r) scanner.Buffer(make([]byte, 0, 64*1024), maxLineSize) // e.g. 1MB, too small // after const maxLineSize = 64 << 20 // 64MB — large diffs/outputs no longer abort the reader scanner.Buffer(make([]byte, 0, 1024*1024), maxLineSize)
Defensive patterns
Strategy: try-catch
Try / catch
err := sess.Send(ctx, prompt, nil)
var fatal bool
if err != nil && !sess.IsAlive() {
// session dead (possibly ErrTooLong) → recreate session, optionally resend
sess, err = agent.StartSession(ctx, opts)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- read stdout: %w
- codex app-server thread id is empty
- codex app-server turn/start: %w
- codex app-server turn/start returned empty turn id
- codex app-server connection closed: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/4bc2789fa4224734.
Report an issue: GitHub.