chenhg5/cc-connect · error

%s

Error message

%s

What it means

Wraps a bufio.Scanner error after the opencode stdout read loop: reading the CLI's JSON stream failed mid-turn (broken pipe after process death, or oversized lines). Emitted as EventError so the user sees the failed turn.

Source

Thrown at agent/opencode/session.go:234

	if err := scanner.Err(); err != nil {
		slog.Error("opencodeSession: scanner error", "error", err)
		evt := core.Event{Type: core.EventError, Error: fmt.Errorf("read stdout: %w", err)}
		select {
		case s.events <- evt:
		case <-s.ctx.Done():
			return
		}
		return
	}

	stderrMsg := stderrBuf.String()
	if stderrMsg != "" {
		slog.Error("opencodeSession: process error", "stderr", truncate(stderrMsg, 500))
		if strings.Contains(stderrMsg, "Session not found") {
			s.chatID.Store("")
			slog.Warn("opencodeSession: cleared stale session ID")
		}
		evt := core.Event{Type: core.EventError, Error: fmt.Errorf("%s", stderrMsg)}
		select {
		case s.events <- evt:
		case <-s.ctx.Done():
		}
		return
	}

	// Check if we received compaction_continue before readLoop ended.
	// If so, OpenCode will continue with a new turn - do NOT send EventResult.
	// The subsequent process will send its own EventResult when it finishes.
	if s.expectingContinue.Load() {
		slog.Info("opencodeSession: readLoop ended after compaction_continue, skipping EventResult", "session_id", s.CurrentSessionID())
		s.expectingContinue.Store(false)
		return
	}

	slog.Debug("opencodeSession: readLoop complete, sending fallback EventResult", "session_id", s.CurrentSessionID())
	s.sendEventResult()

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check whether the opencode process crashed (see stderr events)
  2. Retry — transient stream breakage occurs under load
  3. Report persistent oversized-line failures upstream
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at agent/opencode/session.go:234 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/b92b0fba68b4277f. Report an issue: GitHub.