{"record":{"id":"b0b2c642ff026669","repo":"paperclipai/paperclip","slug":"opencode-event-stream-closed-before-the-session-be","errorCode":null,"errorMessage":"OpenCode event stream closed before the session became terminal","messagePattern":"OpenCode event stream closed before the session became terminal","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.ts","lineNumber":1222,"sourceCode":"                ],\n                reason: \"OpenCode SSE frame parsed as JSON\",\n              });\n            }\n          } catch (error) {\n            if (frameId) {\n              this.#runtime.trace?.interpretation({\n                frameId,\n                stage: \"typescript_opencode_sse_parse\",\n                ruleId: \"opencode.sse.invalid_json\",\n                disposition: \"rejected\",\n                reason: `OpenCode SSE data was not valid JSON: ${String(error).slice(0, 400)}`,\n              });\n            }\n            throw error;\n          }\n          this.#mapProviderEvent(event, frameId);\n        }\n        throw new Error(\n          \"OpenCode event stream closed before the session became terminal\",\n        );\n      } catch (error) {\n        if (this.#closed || this.#abort.signal.aborted) return;\n        attempts += 1;\n        if (attempts > 3) {\n          this.#emit(\"harness.diagnostic\", {\n            code: \"opencode_sse_failed\",\n            message: redact(String(error), this.#runtime.sensitiveValues),\n          });\n          this.#events.fail(error);\n          return;\n        }\n        await new Promise((resolve) => setTimeout(resolve, 50 * attempts));\n      }\n    }\n  }\n","sourceCodeStart":1204,"sourceCodeEnd":1240,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/paperclip-runner/src/drivers/opencode/opencode-server-driver.ts#L1204-L1240","documentation":"Thrown when the SSE event stream from the OpenCode server ends (server closed the connection) while the session has not yet reached a terminal state. After up to 3 reconnect attempts the driver gives up and raises this so the caller knows the turn never completed.","triggerScenarios":"The OpenCode server process exits, restarts, or drops the SSE connection while the harness session is still awaiting a terminal event (e.g. turn completion), and reconnection attempts exceed the retry limit (attempts > 3).","commonSituations":"OpenCode server crashes mid-turn (OOM, panic); supervisor restarts the server during a long-running turn; network idle timeout closes the connection; machine sleep/resume breaks the socket.","solutions":["Inspect the OpenCode server logs for a crash or restart at the time of the drop and fix the underlying server failure.","Check that reconnect/backoff (attempts up to 3) is not being exhausted by frequent drops — increase stability of the host or the server.","If aborts were not intended, verify this.#abort is not being signaled by an upstream timeout that closes the stream.","Retry the turn; if the session is recoverable, re-attach with the provider session id instead of starting over."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runTurn();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"closed before the session became terminal\")) {\n    // inspect server logs for crash; reconnect using persisted providerSessionId and resume or re-run the turn\n  }\n}","preventionTips":["Run the OpenCode server under a supervisor and monitor for crashes","Avoid host sleep/network idle timeouts during long turns","Persist providerSessionId so the turn can be resumed after a drop"],"tags":["sse","streaming","connection-dropped","retry"],"backgroundTag":"connection-refused","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-10T03:14:50.855Z","contentChangedAt":"2026-09-10T03:14:50.855Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}