Repository navigation
Description
Priority
P1 · impact H · effort M · risk M/L for major API convergence.
Evidence
- src/canonical.ts:264 decides canonical-vs-legacy from optional fields and ignores canonical metadata. Minimal canonical messages + metadata is treated as legacy.
- src/canonical.ts:186 then nests canonical tenantId/requestId into metadata.custom rather than preserving identity.
- src/canonical.ts:167 drops all system messages except the first selected one.
- src/canonical.ts:196 discards requirements and most namespaced providerOptions when converting to execution input.
- src/index.ts:381 and src/factory.ts:407 only execute LLMRequest. Canonical normalizers are helpers, not the runtime execution boundary claimed by README.md:80.
- src/model-catalog.ts:1205 pinned introspection uses the first catalog match, regardless of available provider. Factory src/factory.ts:1231 instead considers configured hosts and built-in tools. For openai/gpt-oss-120b configured only on Groq, a pinned plan can report Cerebras.
- src/gateway-routing.ts:153 treats supportsTools as a proxy for native structured output.
- src/model-catalog.ts:953 does not enforce streaming, output/context bounds or requested built-in tools.
- src/index.ts:289 LLMProviders is a forwarding facade over LLMProviderFactory. These are not two independent engines.
Verified: normalizeLLMRequest({messages, metadata: {tenantId: 'a', requestId: 'r'}}) loses metadata.tenantId and stores the fields under metadata.custom.
Proposed implementation
Patch the identity loss with explicit discriminated entry points: normalizeLegacyRequest and normalizeCanonicalRequest, retain the old union helper as compatibility with a documented ambiguous-shape policy. Add a canonical generate method in a minor, explicitly named to avoid structurally overlapping overload confusion.
Use one provider-aware route planner for introspection and execution. Filter every fallback candidate against hard requirements; do not append incompatible defaults after filtering. Return a typed no-route error when none can satisfy requirements. Preserve attempt/fallback metadata from actual execution rather than asking consumers to fabricate routing history.
Add distinct supportsJsonObject/supportsJsonSchema metadata and output/context limits. Caller-required constraints must be preserved; emulation requires opt-in and is visible in the response.
Next major: one canonical execution request, one main client class, namespaced provider options, explicit provider/model identity. Deprecate legacy aliases/factory convenience duplication; keep migration helper/codemod. Batch removal of already deprecated ImageProvider into that major; keep vision analysis.
Tests / acceptance
- Minimal canonical input, metadata-only input, mixed shapes and identity/cache round-trips are covered.
- Multiple system messages have defined preservation/rejection semantics.
- Groq-only collided model plan equals dispatched provider/model.
- Pinned/unavailable models, custom models, tools, built-in tools, streaming, JSON schemas and long context are checked through fallback.
- Required constraints cannot disappear through canonical conversion.
- Route introspection never reports an unavailable provider as executable.
- Type tests demonstrate canonical entry point and major migration path.
Related: #87 is the existing parent contract issue; this issue specifies reproducible gaps beyond closed #81/#82. Retain #87 as the broad consumer-facing integration contract.
Activity
stackbilt-admin commentedon Oct 13, 2026
Local implementation checkpoint — 2026-10-12
This work is uncommitted/unpushed on
main, based on8a9eda6c058d63f0ec08332f6a408aaf409232cf, and is not merged or released. Keep this issue open pending review/integration. The local handoff isdocs/maintenance/issue-sweep.md; it will travel with the code.Focused identity/introspection phase implemented:
normalizeCanonicalRequest()preserves identity/cache in metadata-only canonical requests.normalizeLegacyRequest()explicitly keeps nested legacy metadata custom. The old union helper retains its ambiguous-shape compatibility policy, now documented.systemPromptoverrides them; canonical system-role history is retained.getRoutingInfo()uses the execution planner plus current admission state. Catalog pinned-model introspection chooses configured hosts, reports the host's catalog entry and checks requested built-in tools. Groq-onlyopenai/gpt-oss-120bno longer reports Cerebras.NoRouteErrorcovers absent routes. Gateway debug plans retain diagnostic capability reports and exposeexecutable: falsefor failed capabilities; no unavailable provider is fabricated merely to satisfy a pinned catalog lookup.Evidence: nine
canonical-identity-routing.test.tscases plus existing canonical/catalog/gateway suites and public docs.Remaining: canonical execution API, hard requirements through every fallback, native JSON capability metadata, streaming/context/output limits, pinned/custom-model policy and actual attempt/degradation history. Diagnostic
executable: trueis not full execution enforcement. Do not close the broader API convergence issue.Validation for the combined local sweep: 605 tests pass across 27 files, TypeScript typecheck passes, Worker-targeted bundle/import smoke passes. Packed entrypoint exports/client methods and all 33 JavaScript sourcemaps were checked on Windows with Node 24.19.0/npm 11.17.0. No live/billable providers or workerd execution; this does not prove minimum Node-version compatibility.
feat: streaming lifecycle, tenant-safe caching, client-scoped resilie…
stackbilt-admin commentedon Nov 8, 2026
Context-window enforcement (the "long context [is] checked through fallback" item above) is written up in detail on #136: #136 (comment). In short: selection and fallback don't check estimated input tokens against
maxContextLength(onlygetGatewayRoutePlanwarns), and context overflow comes back as an error that doesn't fall back, so a request that would fit another model fails. The proposed fix there is to treat input + requested output as a hard requirement during selection and fallback.stackbilt-admin commentedon Nov 8, 2026
Correction to my comment above. Context overflow does fall back under the default config: the built-in fallback rules include a catch-all
errorrule. It only ends the request withfallbackRules: []orallowFallback: false. The gap is a wasted (possibly billed) call to a model that's too small, not a failed request. Details: #136 (comment). #147 adds the check as an opt-incontextWindowRoutingoption rather than changing default routing.feat: opt-in context-window routing (#147)