Repository navigation
fix(#2101): dsh-native — clear stale toolsReady latch on fresh-context re-apply - #2103
ranxianglei wants to merge 4 commits into
Conversation
…ation must not be re-poisoned by a stale ctx capture The #2082 fix reset register.dead on re-activation and armed a detached recovery timer, but two async paths still resolved their PluginContext from a capture taken when the retry was armed or started: the timer tick (armRecoveryTimer captured the first ctx that saw the broken state) and an in-flight registration landing after a mid-fetch re-activation (registerTools captured ctx at call time). If dsh deactivated that context in between (profile switch / settings toggle / desktop copy swap), the stale path registered into it, cordis threw 'inactive context', and register.dead was re-poisoned until dsh restarted — exactly the failure this fix removes, in a narrow interleaving. Track the latest context in module state (apply() + maybeRetry update it; _resetRegisterForTest clears it). The timer tick and the single-flight registration landing now resolve activeCtx ?? ctx at landing time. Regression tests pin both facets: they fail on the pre-fix code and pass with the fix.
…INTERVAL_MS in CONFIGURATION.md en+zh The #2091 recovery knobs shipped without CONFIGURATION.md entries while every sibling dsh-plugin knob (incl. the adjacent BILI_MODEL_INFO_RETRY_MS) is documented — 'document or don't ship' (env-var discipline #2030, hard rule 4). Both are test/ops hooks with unchanged defaults; production behavior is untouched.
…uccessful registration into a dead context must not block re-registration apply() reset register.dead but not register.toolsReady, so after a SUCCESSFUL registration into ctx1, a same-instance re-apply(ctx2) (profile switch / settings toggle / desktop copy swap) short-circuited registerTools for the new context while headersFor kept stamping x-bili-plugin — plugin mode suppresses wire tool injection, so the model lost the bili tools until dsh restarts (the #2082 symptom via a different route). The fix clears toolsReady only when the context identity genuinely changed (prevCtx !== ctx); same-context re-apply keeps the latch (no churn), and the state.toolsReady gate re-arms to hold the first request until the new registration lands. Regression test: red pre-fix on the no-stamp assertion, green post-fix.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2146-pr.2103.cf6fdfaThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2103.tgz
npm install -g packageInstall instructions are refreshed on each push. |
|
Closing as superseded by commit This PR implemented the same fix independently (clear Issue closes via #2097. |
Closes #2101
What & why
apply()(the #2082 fix) resetsregister.deadand refreshesactiveCtx, but leavesregister.toolsReadyuntouched. After a SUCCESSFUL registration into ctx1, a same-instanceapply(ctx2)(dsh deactivates ctx1 on profile switch / settings toggle / desktop copy swap) short-circuitsregisterToolsfor the new context whileheadersForkeeps stampingx-bili-plugin→ the proxy suppresses wire tool injection → the model loses the bili tools until dsh restarts (#2082 symptom via a different route).Fix at the source — the activation decision point in
apply(): cleartoolsReadywhen the context identity genuinely changed (prevCtx !== undefined && prevCtx !== ctx). Everything downstream is handled by existing machinery:state.toolsReadygate re-arms on re-apply and holds the first model request until the new registration attempt finishes (same [Enhancement] E2E native lane: real dsh + bili profile vs deterministic fake upstream (from #1239) #1268 boot-time discipline: never stamp plugin headers before local tools exist);headersFor/maybeRetrydrive the re-registration; an in-flight pending flight lands on the NEWactiveCtx(landing-time resolution from 028bb2f);Behavior change (disclosed)
toolsReady=true→ no re-registration while headers kept stamping → permanent tool loss until dsh restart.Evidence
#2101 apply() on a fresh context clears the stale toolsReady latch …(tests/issue2082-dsh-recovery.test.ts): RED pre-fix (fails exactly on the "no x-bili-plugin stamp while the fresh context lacks tools" assertion — the reported defect), green post-fix.npm run typecheckclean; tests/issue2082-dsh-recovery.test.ts 5/5; tests/dsh-native.test.ts 43/43. Full suite left to CI.No config surface changes (no new env/config/fields).
CI status (head 1e7ee31)
15/16 green: full test matrix (ubuntu/windows × node 22/24), build, all e2e lanes. The one red check is
version-guard, an EXPECTED consequence of stacking: the guard forbids version-field changes in PRs from non-*_release-v*branches, and this branch carries #2097’s bump commit until #2097 merges. After #2097 lands, this branch gets rebased onto master and re-run — all checks then green.