Repository navigation
fix(dsh): bind llm.resolveModelInfo to its service receiver — every window resolve throws, stripping x-bili-plugin-context-window - #1943
Conversation
refreshModelInfo detached the host's llm.resolveModelInfo and called it without a
receiver. dsh-llm registers it as a class method whose first statement is
this.resolveModelInfoFor(...), so every resolve rejected with
Cannot read properties of undefined (reading 'resolveModelInfoFor')
for every provider and every model. The failure-shaped cache then stored
{provider, model} with no window, so headersFor never stamped
x-bili-plugin-context-window and the proxy sized the session against its
unconfigured fallback. ranxianglei#1812's cooldown retry cannot help: the call fails
deterministically, so each retry fails the same way.
The error text names an inner dsh-llm method, which points the search away
from the detached call site, so no existing report covers this.
Fixes ranxianglei#1942
Verification scopeCorrecting the Verification section above to match what was actually run on this head:
The change is confined to |
[bot] 🏷 Review of #1943 (external-contributor PR — review + verification only, per repo policy I am not pushing to your branch) Fetched head ① Original-issue direction check (verified against master source):
② Regression audit (existing behaviors on the touched path):
③ Code: one-line fix at the extraction site — the decision point, not a mask. The 5-line comment documenting why the bind is required (TS structurally cannot express the receiver requirement) is a justified exception to the no-comments rule. ④ Test validity — verified both directions locally:
⑤ Diff hygiene: clean, except one cosmetic nit — two comment lines in the new test contain a literal TAB that splits the word "this": CI at review time: 12/14 check runs green, including the full e2e set (dsh headless lane, codex, pi, opencode, hermetic registry) + build + version-guard; 2 test-matrix jobs still running at the time of writing. 中文结构化结论(七问)
判定:可合(待最后 2 个 test-matrix CI 任务转绿;tab 注释小疵可选修,不阻塞)。合并由人执行。 |
[bot] 🏷 CI 全绿确认 — head 结论维持:可合,无回归。合并由人执行;tab 注释小疵仍为可选修,不阻塞。 |
…ot exist on the host (#1961) pi v0.99.1 ModelRegistry exposes find(provider, modelId) (delegating to the private runtime.getModel); there is no public getModel, so ctx.modelRegistry?.getModel?.(...) always short-circuited to undefined — tier ① (the only tier that can resolve ownership in the issue's own lane: manual /bili/ wrapping, no env, no rewrite manifest) was dead code on the real host. Tests passed because the stubs invented the same non-existent method; they are now shaped like the real registry surface, and a mutation check confirms the #1961 repro test fails against the old call. Same failure class as #1943: object-literal stubs cannot catch host-API drift.
Root cause
refreshModelInfoinsrc/agent/dsh-native.tsreads the resolver off the host'sllmservice object and then calls it detached:dsh-llmregistersresolveModelInfoas a class method whose first statement isreturn this.resolveModelInfoFor(this.registration(provider), model, signal). With no receiver,thisisundefined, so every resolve rejects with:This is unconditional — every model, every provider, every process start. There is no configuration that avoids it.
The failure is then absorbed by the failure-shaped cache (
modelInfo.cached = { provider, model }, no window), soheadersFornever stampsx-bili-plugin-context-window. The proxy then sizes the session against its unconfigured fallback and logs:Why the existing fixes do not cover it
#1812 / #1836 added a retry cadence so a transient failure heals after a 30s cooldown. That cannot help here: the call fails deterministically, so every retry fails identically. The symptom is timing-independent, which is also why the error is easy to misread as a boot race.
The type declaration at
dsh-native.ts:84declaresllmas a structural object with an optional method property. It reads like a plain function, but in production it is a class instance whose method needs its receiver — TypeScript cannot catch this, because the declared shape says nothing about the runtime receiver.Note that the error text names
resolveModelInfoFor, an innerdsh-llmmethod. That points a reader at the wrong module, which is why searching for the error text (or forresolveModelInfo) surfaces #1929 / #1849 but nothing matching this.The fix
One line, at the extraction site:
No signature change, no config-surface change, no wire change.
Regression test
tests/dsh-native.test.ts—apply() runtime-info (#1942): binds resolveModelInfo to its service receiver, so a class-shaped llm service still stamps the window headerThe stub is a real class whose
resolveModelInforeaches its own state throughthis, mirroringdsh-llm. A plain object literal cannot detect this bug (it does not depend onthis), which is why the #955 / #956 / #1812 suites all pass against the broken code today.resolveModelInfo lost its service receiver: Cannot read properties of undefined (reading 'capacity')x-bili-plugin-model,x-bili-plugin-context-window: 1000000andx-bili-plugin-max-outputVerification
npm run typecheck— cleannode --import tsx --test tests/dsh-native.test.ts— 43 tests, 43 pass, 0 fail (3.3s). This is the file holding the new test; the rest of the suite was not run. The change is confined torefreshModelInfo, whose only callers areheadersForin this same file, so this file is the enclosing blast radius.git diff --check— cleanImpact
The dsh client now reports each model's real window through
POST /__bili/plugin/runtime-infoon its own, taken from the host model catalog. A per-modelmodelContextLimitworkaround in the proxy config stops being necessary, and a newly added model needs no entry anywhere.Note on scope
The boot-order race described in the follow-up comment is a separate defect with a different root cause (host initialization order) and a different fix (invalidate the cache on
llm/adapters-updated). It is deliberately not addressed here.