{"record":{"id":"bcb197d237b7509a","repo":"chenhg5/cc-connect","slug":"read-stdout-w-bcb197","errorCode":null,"errorMessage":"read stdout: %w","messagePattern":"read stdout: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/opencode/session.go","lineNumber":218,"sourceCode":"\n\tfor scanner.Scan() {\n\t\tline := scanner.Text()\n\t\tif line == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar raw map[string]any\n\t\tif err := json.Unmarshal([]byte(line), &raw); err != nil {\n\t\t\tslog.Debug(\"opencodeSession: non-JSON line\", \"line\", line)\n\t\t\tcontinue\n\t\t}\n\n\t\ts.handleEvent(raw)\n\t}\n\n\tif err := scanner.Err(); err != nil {\n\t\tslog.Error(\"opencodeSession: scanner error\", \"error\", err)\n\t\tevt := core.Event{Type: core.EventError, Error: fmt.Errorf(\"read stdout: %w\", err)}\n\t\tselect {\n\t\tcase s.events <- evt:\n\t\tcase <-s.ctx.Done():\n\t\t\treturn\n\t\t}\n\t\treturn\n\t}\n\n\tstderrMsg := stderrBuf.String()\n\tif stderrMsg != \"\" {\n\t\tslog.Error(\"opencodeSession: process error\", \"stderr\", truncate(stderrMsg, 500))\n\t\tif strings.Contains(stderrMsg, \"Session not found\") {\n\t\t\ts.chatID.Store(\"\")\n\t\t\tslog.Warn(\"opencodeSession: cleared stale session ID\")\n\t\t}\n\t\tevt := core.Event{Type: core.EventError, Error: fmt.Errorf(\"%s\", stderrMsg)}\n\t\tselect {\n\t\tcase s.events <- evt:","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/opencode/session.go#L200-L236","documentation":"Wrapped bufio.Scanner error emitted by the opencode session's stdout read loop when the JSON-lines stream from the opencode process terminates abnormally (I/O failure, buffer overflow, or process death) rather than clean EOF; surfaced to the platform as an EventError.","triggerScenarios":"Thrown at agent/opencode/session.go:218 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Log and forward the error event so the user sees the agent stream died","Check whether the opencode process exited (non-zero exit, OOM, crash) and restart the session if configured","Raise bufio.Scanner buffer size if lines exceed the 64KB default","Ensure the process is reaped and the session marked closed so the next turn starts fresh"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}