Skip to content

fix(#2101): dsh-native — clear stale toolsReady latch on fresh-context re-apply - #2103

Closed
ranxianglei wants to merge 4 commits into
masterfrom
2026-10-04_dsh-reactivate-toolsready
Closed

ranxianglei wants to merge 4 commits into
masterfrom
2026-10-04_dsh-reactivate-toolsready

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Closes #2101

Stacked on #2097 (release v0.1.184). This branch is based on 2026-10-04_release-v0.1.184 because the code under fix (activeCtx, from commit 028bb2f) only exists there. The diff vs master therefore also shows #2097's commits; once #2097 merges it collapses to the two files below. Please merge #2097 first (or rebase this onto master afterwards).

What & why

apply() (the #2082 fix) resets register.dead and refreshes activeCtx, but leaves register.toolsReady untouched. After a SUCCESSFUL registration into ctx1, a same-instance apply(ctx2) (dsh deactivates ctx1 on profile switch / settings toggle / desktop copy swap) short-circuits registerTools for the new context while headersFor keeps stamping x-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(): clear toolsReady when the context identity genuinely changed (prevCtx !== undefined && prevCtx !== ctx). Everything downstream is handled by existing machinery:

  • the state.toolsReady gate 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/maybeRetry drive the re-registration; an in-flight pending flight lands on the NEW activeCtx (landing-time resolution from 028bb2f);
  • same-context re-apply keeps the latch (no gratuitous re-registration churn); a host module re-import is a no-op (fresh state).

Behavior change (disclosed)

  • Old: fresh-context re-apply kept the stale toolsReady=true → no re-registration while headers kept stamping → permanent tool loss until dsh restart.
  • New: fresh-context re-apply clears the latch → one manifest fetch + re-registration; the [Enhancement] E2E native lane: real dsh + bili profile vs deterministic fake upstream (from #1239) #1268 gate holds the first request across that window, so the model never sees plugin mode without local tools (and even an ungated request rides wire mode with proxy-injected tools — strictly better than zero tools).

Evidence

  • New regression test #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.
  • Local targeted: npm run typecheck clean; 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.

ework-agent and others added 4 commits October 4, 2026 20:43
…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.
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-04_dsh-reactivate-toolsready (1e7ee31)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2146-pr.2103.cf6fdfa

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2103.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei closed this Oct 4, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

Closing as superseded by commit fbc7f03d folded into the v0.1.184 release PR #2097 (per owner, 2026-10-04).

This PR implemented the same fix independently (clear register.toolsReady on context change in apply()); #2097's version additionally clears retryAt on the same transition (fresh-activation rule, #1783) and ships with its own regression suite (tests/issue2101-dsh-reactivation.test.ts) plus the release-notes entry. Both implementations verified green locally against their respective trees; no behavioral divergence between them.

Issue closes via #2097.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dsh-native: apply() on a re-activated context doesn't reset register.toolsReady — tools stay registered only on the dead context

1 participant