Skip to content

fix(dsh-native): three-state gate refusal logging with cumulative counts (#1158 L2) - #1193

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-23_dsh-gate-three-state-log
Sep 24, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-23_dsh-gate-three-state-log

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

The follow-up agreed in the #1158 thread (L2): make takeover-gate refusals diagnosable at a glance. The gate's old bare catch swallowed currentInitiator() exceptions (disposed/closing agent scope) as plain "no attribution" — a throwing ALS boundary was indistinguishable from a legitimate agentless lane, and each endpoint produced exactly one flat line with no way to see a "dozens refused, one passed" distribution.

Complements #1187 (L1, merged): that one made "evicted from the fetch chain by a third party" visible; this one makes "gate refused to claim the request" visible. No file overlap (dsh-native.ts vs native-intercept.ts).

Changes

  • src/agent/dsh-native.ts
    • New attributionOf(ctx): three states — ok / none (initiator present-or-absent, no session id) / threw (+ exception message). sessionIdOf becomes a thin wrapper; statusOutcome/headersFor behavior unchanged.
    • Gate refusal log: first refusal per endpoint prints exactly as before plus — refusals so far: N; same-state refusals accumulate silently; re-print only on a state transition, marked (state none→threw) / (state threw→none). Bounded noise — 「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117's per-request silence preserved. The 256-endpoint cap now clears only when a NEW endpoint would overflow (existing counts survive).
    • Every printed line is additionally appended to bili.log via persistClientEvent ([warn] [dsh-client] …) — GUI hosts swallow stderr, which is exactly how the reported zero-traffic case stayed invisible.
  • tests/dsh-native.test.ts: +1 three-state test (silent counting over 4 refusals, both transition directions with accumulated counts, attributed-silent claim, durable bili.log copy); the two pre-existing gate tests now redirect XDG_STATE_HOME so their durable copies land in temp dirs, not the real state file.

Behavior change disclosure (old → new)

Verification (head b36c496, based on master incl. merged #1187)

  • npm run typecheck: clean
  • npm test: 2359 total, 2357 pass, 0 fail, 2 skipped (gated E2E); dsh-native 31/31
  • npm run build: success

References #1158 (L2). The issue stays open pending the reporter's retest on a released build containing both #1187 (L1) and this change.

ework-agent added 2 commits September 23, 2026 22:54
…nts (#1158 L2)

The takeover gate's bare catch swallowed currentInitiator() exceptions
(disposed/closing agent scope) as plain 'no attribution', so a throwing ALS
boundary looked identical to a legitimate agentless lane — one flat log line
per endpoint, no way to see a 'dozens refused, one passed' distribution.

- attributionOf(): three states (ok / none / threw-with-message); sessionIdOf
  becomes a thin wrapper, behavior unchanged for statusOutcome/headersFor
- gate refusal log: first refusal per endpoint prints once (unchanged format,
  plus cumulative 'refusals so far: N'); same-state refusals accumulate
  silently; re-print only on state transition with '(state none→threw)'
  marker — bounded noise, #1117 per-request silence preserved
- durable copy of each printed line via persistClientEvent into bili.log
  ([dsh-client]-marked): GUI hosts swallow stderr, which is exactly how the
  reported zero-traffic case stayed invisible
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-23_dsh-gate-three-state-log (b36c496)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1193

Each push to this PR publishes a new version under the pr-1193 npm tag.

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Reviewed PR #1193 (head b36c496). Verdict: mergeable — code matches the stated design, all checks reproduce locally, and the tree merges cleanly into current master.

Evidence (re-ran everything, didn't take the claims on faith):

  • CI on head: all 8 checks green (ubuntu/windows × node 22/24 test matrices, build-artifact, version-guard, codex zero-token e2e).
  • Local on PR head: npm run typecheck clean; npm test → 2359 total / 2357 pass / 0 fail / 2 skipped (gated E2E) — exactly as claimed; npm run build success.
  • Against live master (§7.2 stale-base check): master has moved past this branch's base only by the release v0.1.140 commit (release v0.1.140 #1191). I test-merged origin/master (75fbeb22) onto the branch head: clean merge touching only package.json/package-lock.json (master's version bump), result keeps 0.1.140, full suite green on the merged tree (2357/2359, 2 skipped). So the 0.1.140 → 0.1.139 you see in the GitHub diff view is purely a stale-base artifact — neither PR commit touches package.json, and merging cannot regress the version. No action needed.

Existing-behavior audit (what the diff touches and the verdict per item):

  • Gate decision logic — unchanged. Claim iff attribution is ok (non-empty session id); sessionIdOf is now a thin wrapper over attributionOf, so statusOutcome/headersFor keep identical semantics. Preserved.
  • Refusal log format — intentional, disclosed: first refusal gains — refusals so far: 1; new lines only on none↔threw transitions carrying the accumulated count. Matches spec and tests verbatim.
  • 256-endpoint cap — behavior change, disclosed, and an improvement: the old code cleared the whole set on every refusal once ≥256 endpoints had been seen (which actually re-logged known endpoints after saturation); the new code clears only when a NEW endpoint would overflow. Strictly less noise, 「BUG」native-intercept 进程级 globalThis.fetch 补丁按 URL 形状接管所有模型流量,无关调用者(如 MemOS)被卷入宿主压缩流程 #1117 silence preserved.
  • Durable bili.log copy — routes through the existing persistClientEvent helper (src/agent/dsh-native.ts:186), best-effort appendFileSync, can't break the host, same shape as its five other call sites. New surface, disclosed.
  • Wire shapes / config schema / persistence format / cross-repo deps — untouched.
  • Tests — the new L2 test is deterministic (mock proxy on ephemeral port, mkdtemp homes) and asserts the full matrix: 4 silent same-state refusals → 1 line, both transition directions with accumulated counts (5, then 7), attributed-silent claim, and the durable [warn] [dsh-client] copy in $XDG_STATE_HOME/billion-context/bili.log. The two pre-existing gate tests now redirect XDG_STATE_HOME so their durable copies stop landing in the real state file — good hygiene fix.

One minor nit (non-blocking, no commit needed): the PR body's parenthetical "(existing counts survive)" for the 256-cap is slightly overstated — when clear() actually fires on the 257th distinct endpoint, all existing entries do get wiped and the new key restarts at 1. Practically unreachable (256+ distinct model endpoints in one dsh process lifetime), but the sentence reads like counts always survive.

After merge, the reporter can retest on a release containing both #1187 (L1) and this L2 — or immediately against the already-published billion-context@pr-1193 tag.

中文摘要:核对了 dsh 接管门三态拒绝日志(累计计数+状态迁移重打印+持久化 bili.log)的代码与测试,本地复跑 typecheck/全量测试/构建全部通过,对当前 master 试合并干净且版本保持 0.1.140(GitHub diff 里的版本变化只是分支落后于 v0.1.140 发布的假象),可以合并。

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.

1 participant