{"record":{"id":"fc912a62ce79fa0e","repo":"router-for-me/CLIProxyAPI","slug":"model-stream-bridge-is-unavailable","errorCode":null,"errorMessage":"model stream bridge is unavailable","messagePattern":"model stream bridge is unavailable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/pluginhost/model_stream_bridge.go","lineNumber":49,"sourceCode":"\t\tif cancel != nil {\n\t\t\tcancel()\n\t\t}\n\t\treturn \"\"\n\t}\n\tid := strconv.FormatUint(b.next.Add(1), 10)\n\tb.mu.Lock()\n\tb.streams[id] = modelStreamEntry{\n\t\townerCallbackID: ownerCallbackID,\n\t\tchunks:          chunks,\n\t\tcancel:          cancel,\n\t}\n\tb.mu.Unlock()\n\treturn id\n}\n\nfunc (b *modelStreamBridge) read(ctx context.Context, id string) (handlers.ModelExecutionChunk, bool, error) {\n\tif b == nil {\n\t\treturn handlers.ModelExecutionChunk{}, true, fmt.Errorf(\"model stream bridge is unavailable\")\n\t}\n\tif id == \"\" {\n\t\treturn handlers.ModelExecutionChunk{}, true, fmt.Errorf(\"model stream id is required\")\n\t}\n\tb.mu.Lock()\n\tentry, ok := b.streams[id]\n\tb.mu.Unlock()\n\tif !ok || entry.chunks == nil {\n\t\treturn handlers.ModelExecutionChunk{}, true, nil\n\t}\n\tif ctx == nil {\n\t\tctx = context.Background()\n\t}\n\tselect {\n\tcase <-ctx.Done():\n\t\tb.close(id)\n\t\treturn handlers.ModelExecutionChunk{}, true, ctx.Err()\n\tcase chunk, okRead := <-entry.chunks:","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/pluginhost/model_stream_bridge.go#L31-L67","documentation":"modelStreamBridge.read() guards b == nil, so calling read on a nil bridge (one that was never constructed or whose owner failed to initialize) yields this error. The bridge mediates streaming model execution chunks between the host and plugins; a nil bridge means the streaming bridge feature was not wired up in this build or code path.","triggerScenarios":"Invoking Host streaming-model APIs that route through the bridge before the bridge was created; embedding the SDK without initializing the model stream bridge; a host code path constructing Host partially in tests/mocks.","commonSituations":"Unit tests with a hand-built Host struct that skips bridge initialization; SDK embedding that bypasses the normal constructor.","solutions":["Construct the Host via its normal builder/constructor so the model stream bridge is initialized","Check for a nil bridge before issuing streaming model calls and return a clearer error","In tests, provide a real (or stub non-nil) bridge"],"exampleFix":"// before\nvar b *modelStreamBridge\nchunk, done, err := b.read(ctx, id)\n\n// after\nif b == nil {\n    return handlers.ModelExecutionChunk{}, true, errors.New(\"model streaming is not initialized\")\n}\nchunk, done, err := b.read(ctx, id)","handlingStrategy":"validation","validationCode":"if b == nil {\n    return handlers.ModelExecutionChunk{}, true, errors.New(\"model streaming is not initialized\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always construct Host through the SDK builder so the stream bridge is non-nil","In tests, inject a stub bridge rather than leaving the field nil"],"tags":["plugin","streaming","nil-guard","sdk"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}