Dashboard › opencode-lore › Distillation
cd9b5ae8-2e37-4a99-b59f-8d6351126800["lore_tm_v1_0wRkRSURd2ttoJ2sMMMHcOUJqmboMh0roUKHNa7xeFo","lore_tm_v1_Q2v9dOY611bMP86sXfHjtBYxoBVCrMy3JiwKaw7Lgbw","lore_tm_v1_3vGo6aNDkGIRSVlrwqTrf0Ie433kwFGHQeODkajfras","lore_tm_v1_FgacBPaHsJq4Z_sryqwKgO2g7mUXojXFlWTjlucZhT8","lore_tm_v1_Qj99VjpoBCdux33dn9ra4jpVzkvcFiVMs66PUR2eJHI","lore_tm_v1_X4uP6cKKCdM8CtqBQ39m5Ci3G3I38eSiBFHe1oe1mlQ","lore_tm_v1_wV_CXUCdo5O2BYeirZm183GakEDciL3lZQHUjeRd4SM","lore_tm_v1_KL9onFgupzo7XAvF-MolA8CFE-6q6x5GIeWjVSTwFEk","lore_tm_v1_V_hDQn32mPmZQRbJ8EdeSegAYS8GiPvdNlb_Weez3hQ","lore_tm_v1_XNPYvTU0tRtdaTMNGz_FQEkzacY2TKfPdQmpZBGWGeQ","lore_tm_v1_mhITPVB140gRIJDlJ6KuPJw52pgvzYQ6YXB5Ap96nEM","lore_tm_v1_YeEtS3WGN4kI2hGCYdZ4sLmKl4bCb5wxqze63AW600U","lore_tm_v1_oBFlrv1I4Vr5s3edRWjT8eSneej30_79IOYtwnGGzkA","lore_tm_v1_eCIKuakdxmuN2Rq85EQ80JK2s-0OhNkBmduPNMc8EAY","lore_tm_v1_ALFwHHas9p8Oq1iOfUGf6kT06gosLZAvHjetQb_U0dw","lore_tm_v1_DFeaG5jyDe8RsCbxSc5ZTJKT-3_OAL-y3Coo_iqiemA","lore_tm_v1_MLwHhXaDSAmLzcMBZ0CPb_xzOym1Jv6qttopgSjg30Q","lore_tm_v1_bB5YV_5zdOp18CXJKf-0aNeX0yFISkphnAeBLX8zv6k","lore_tm_v1_Dyj4RrU_7sTTFd2-oWVN4ZD_NgGHH6bwaaTZ16FVz50"]
Date: Sep 16, 2026
handlePassthrough() in packages/gateway/src/pipeline.ts:15595 creates a foreground abort scope, calls forwardToUpstream(), and wraps the body with wrapBodyWithCleanup(). At lines 15627-15631, non-2xx upstream responses bypass SSE validation and return through preserveUpstreamErrorResponse() so provider 4xx/429 errors remain ordinary HTTP responses instead of being converted to status 200 or a synthetic stream failure.vertex to wire protocol anthropic at packages/gateway/src/pipeline.ts:15642-15643. Same-wire streaming responses use validatedMetaStream(); same-wire non-streaming Responses payloads are checked with parseResponsesNonStreamEnvelope(). Cross-protocol Anthropic/Vertex streams translate through translateAnthropicStreamToOpenAI(), translateAnthropicStreamToResponses(), or translateAnthropicStreamToGemini(), all with strict: true.validatedMetaStream() handles Anthropic streams with AnthropicSSEValidator, OpenAI streams with accumulateOpenAISSEStream({ strict: true, stopAtTerminal: true, consumeUntilDone: true }), and Gemini streams with accumulateGeminiSSEStream({ strict: true, stopAtTerminal: true }). Downstream cancellation aborts with DOMException("client disconnected", "AbortError").packages/gateway/test/openai-responses.test.ts, 17 in packages/gateway/test/openai-responses-recall-aware-stream.test.ts, and 14 in packages/gateway/test/openai-responses-stream.test.ts. Existing non-stream tests cover Responses JSON construction, tool_useβfunction_call, native output preservation, max_tokensβincomplete, resp_ ID prefixing, and inclusion/omission of input_tokens_details.cached_tokens and prompt_tokens_details.cached_tokens.setGenAiUsageAttributes() in packages/gateway/src/sentry.ts:150 always sets gen_ai.usage.input_tokens and gen_ai.usage.output_tokens, defaulting absent values to 0; it sets gen_ai.usage.input_tokens.cached and gen_ai.usage.input_tokens.cache_write only when the corresponding usage values are non-null. It optionally sets gen_ai.response.model and explicitly avoids recording input/output message content as a privacy boundary.setCacheAnalyticsAttributes() in packages/gateway/src/sentry.ts:190 records lore.cache.turn, rounded-to-three-decimal lore.cache.hit_rate, rounded-to-three-decimal lore.cache.prefix_match, lore.cache.divergence_point, lore.cache.divergence_reason, and lore.cache.bust_cause; early divergences below 5% prefix match may include short byte snippets for forensic debugging.recordConversationCost() in packages/gateway/src/cost-tracker.ts:664 computes a conversation call cost, accumulates total cost plus exact input/output/cache-read/cache-write token counts, increments costs.conversation.turns, resets the daily period when needed, adds the call to the daily ledger, and updates the cost-rate EMA. Optional TTL is "5m" or "1h"; "1h" cache writes are charged at 2Γ the base rate.packages/gateway/src/cost-tracker.ts map "lore-distill"βdistillation, "lore-curator"βcuration, "lore-compact"βcompaction, and "lore-query-expand"βrecall; unknown worker IDs default to distillation.emitCostMetric() in packages/gateway/src/sentry.ts:408 asynchronously fetches cached model pricing and emits lore.llm_cost_usd as a Sentry distribution with model, call_type, and unit "dollar". Cost sums uncached input, cache read, cache write, and output; batch calls apply a 0.5Γ multiplier to every token category, while "1h" TTL applies a 2Γ cache-write multiplier. Pricing failures are silently ignored because metrics are best-effort.emitSessionCostMetrics() in packages/gateway/src/sentry.ts:475 runs when a session goes idle, skips missing sessions and sessions with zero conversation turns, and derives actual cost, worker cost, savings, and savings percentage before emitting session metrics.packages/gateway/test/openai-responses-recall-aware-stream.test.ts documents the original true-streaming regression: buffered accumulateResponsesSSEStream withheld all client bytes until slow reasoning-heavy upstream completion, triggering opencodeβs 10-second ProviderHeaderTimeoutError. streamResponsesRecallAware instead forwards events live while intercepting a recall function call, emitting a marker, running the follow-up, and rebuilding terminal response.completed.sseEvent(), streamFrom(), drain(), created(), recallCall(), and sparseVisibleFunctionCall(). afterEach() clears setRecallContinuationFailureHook() and setPrincipalTransportFailureHook() and restores a silent log sink.streamResponsesRecallAware() a valid response.created, malformed event: error payload containing pentest-provider-diagnostic, and valid response.completed, then inspect whether the diagnostic or error leaked and whether response.failed was generated. The first probe did not execute because tsx/esbuild compiled /eval.ts as CJS and rejected top-level await: Top-level await is currently not supported with the "cjs" output format./home/byk/Code/opencode-lore-provider-error/packages/gateway/node_modules/@loreai/core/dist/node/index.js with MODULE_NOT_FOUND. Thus neither failed probe established runtime behavior for malformed provider error events.packages/gateway/package.json identifies @loreai/gateway version 0.40.0, uses "type": "module", requires Node >=22.15, declares @loreai/core: "workspace:*" as a dev dependency, and exposes build/start scripts tsx script/build.ts, tsx script/bundle.ts, tsx script/build.ts --binary, tsx script/build-binary-sea.ts, and tsx src/index.ts.handleAnthropicMessages() in packages/gateway/src/server.ts:471 decodes compressed request bodies before JSON parsing, returns HTTP 400 invalid_request_error for malformed JSON or request parsing failures, and converts exceptions from handleRequest() into HTTP 502 api_error with message Gateway pipeline error: ${msg}.handleModelsPassthrough() in packages/gateway/src/server.ts:508 forwards provider authentication headers, preserves anthropic-version, overlays configured administrator credentials, and targets ${config.upstreamAnthropic}/v1/models. A source note says this endpoint supports only Anthropic upstream; OpenAI clients may have their API key rejected until routing is based on auth-header type.handleOpenAIChatCompletions(), handleGeminiGenerateContent(), handleOpenAIResponses(), and handleOpenAICodexResponses() in packages/gateway/src/server.ts all call handleRequest() and convert thrown pipeline errors into HTTP 502 api_error responses containing Gateway pipeline error: ${msg}.handleGeminiGenerateContent() matches version-independent Gemini paths with /\/models\/([^/:]+):(generateContent|streamGenerateContent)$/; it normalizes query-form ?key= authentication into x-goog-api-key when the header is absent, because the upstream URL is rebuilt and would otherwise drop the query parameter.handleOpenAIResponses() parses via parseOpenAIResponsesRequestChunks(decodedRequestChunks(...)); malformed or unfinished streams return a connection-closing HTTP 400 with invalid_request_error and "Invalid JSON body". handleOpenAICodexResponses() similarly parses with parseOpenAICodexRequestChunks() and routes POST /v1/codex/responses to the OpenAI Responses wire format while preserving Codex controls such as store: false and include.vitest.config.ts aliases @loreai/core to packages/core/src and @loreai/gateway to packages/gateway/src at top-level resolve.alias; a comment records that placing aliases under test.resolve.alias silently resolved stale dist builds and masked real failures.testTimeout and hookTimeout both 300_000 ms. Test environment variables are NODE_ENV=test, SENTRY_ENABLED=0, and LORE_DEBUG=0; setup preloads ./packages/core/test/setup.ts.v8 and reporters text, json, html, and lcov; exclusions include tests, setup/helpers, scripts, dist, packages/website/**, packages/pi/**, eval files, config files, and scripts/**.tsconfig.json extends ./tsconfig.base.json, sets noEmit: true, includes packages/*/src, packages/*/test, packages/*/script, packages/*/scripts, and packages/*/eval, and excludes node_modules and **/dist.packages/core/test/setup.ts creates an isolated temporary directory with mkdtempSync(join(tmpdir(), "lore-test-")) and sets process.env.LORE_DB_PATH to join(tmp, "test.db").