Skip to main content
G

dsh-bili-probe

gituser-520/dsh-bili-probe

Finds out where a slow assistant response actually goes. Four read-only probes report billion-context kernel patch state, log-derived stream truncation rate and local request-rebuild cost, and time a streaming request against the configured gateway with connect, time-to-first-token and total reported separately; two more apply or roll back the kernel hardening, dry-run by default, with timestamped backups and a syntax gate.

Install

dsh plugin --profile web add github:gituser-520/dsh-bili-probe

README

Billion-context probe

Turns "the model takes minutes to answer" into a number you can act on, and re-applies the kernel patches that a reinstall silently wipes.

The problem this addresses

billion-context ships one ~6.5 MB minified bundle per agent flavour (dist/index.js, dist/agent/dsh-native.js, omp-native.js, opencode-native.js, opencode.js, pi-native.js). Two independent defects were measured on the machine this was written on:

1. trae's stream is judged truncated almost every turn. trae's SOLO endpoint (/api/agent/v3/llm_utils_chat) closes a turn with a flat data:{"finish_reason":"stop"} frame — no type, no choices. The kernel only sets sawTerminal for type === "message_stop" (Anthropic) or a choices[].finish_reason (OpenAI). A flat frame matches neither, so the turn ends with sawTerminal === false; the kernel calls the stream truncated, discards the round and emits an in-band error. Measured over one 4 MiB log tail:

endpointrequeststruncatedrate
/api/agent/v3/llm_utils_chat (trae)29429399.7%
/v2/chat/completions (buddy etc.)12700%

Every truncation carried the same diagnosis: classification=no-terminal-seen, cause=eof, upstreamStatus=200, upstreamContentType=text/event-stream, visibleChars=0. The upstream was fine; the terminal frame was not recognised.

2. A package reinstall erases hand patches. pnpm/npm unpack a pristine bundle, so anything applied by hand vanishes. That happened on 2026-11-30 at 09:54 on this machine (dist/agent/dsh-native.js mtime 09:54:49, dist/index.js 10:09:13), and time-to-first-token climbed on the same model and account from that day on. Five of the six kernel copies had no patches at all when this was written.

What the plugin does

Six tools, all inspectable, every write reversible:

ToolWrites?Purpose
bili_doctornoProfiles, kernel files, per-patch state, store size, a log scan, and a verdict
bili_logscannoTurns bili.log into truncation rate per endpoint, local rebuild cost, ingest cost, WAL pressure, fold drift
bili_latency_probenoTimes a minimal streaming request so "slow upstream" and "slow local rebuild" stop being guesses
bili_patchopt-inRe-applies the five anchors. Dry run by default; writes only when allowApply: true
bili_restoreopt-inPuts the newest .bak-<ts> back
bili_patch_catalognoLists the five patches and their exact anchors

It never reads or writes billion-context's own config file, the session store, or the attachment library.

The five patches

idFixes
sse-flat-terminalRecognises a flat finish_reason frame as a turn terminal
sse-flat-usageReads prompt_tokens / cache_read_input_tokens sent without a usage wrapper
toolcalls-guardTolerates tool_calls[].function being rewritten to function_call
normalize-guardGuards normalizeStrictEchoReasoning against a non-array message list
catch-fallbackFalls back to parsed.messages when request preparation throws

Why anchor counting, not line numbers

A minified bundle has no stable line numbers and no stable offsets. Each patch is an exact byte-substring replacement guarded by a cardinality check with four outcomes, not two:

  • applied — the marker is already there; skip.
  • missing — the anchor occurs exactly once; safe to patch now.
  • absent — the anchor occurs zero times. This flavour simply has no such code (omp-native.js and pi-native.js have no tool_calls rebuild loop). Skip it; it is not an error.
  • drift — the anchor occurs more than once. The bundle changed shape and a blind replacement would hit the wrong site. The whole file is refused.

Collapsing absent into drift (the obvious first implementation) makes a doctor run on a healthy machine report a fault that does not exist.

Safety

  • Every write is preceded by <file>.bak-<yyyyMMddHHmmss> next to the kernel.
  • Every write is followed by node --check; a syntax failure copies the backup straight back.
  • allowApply defaults to false, so the tools only ever plan until you say otherwise.
  • If any anchor is duplicated anywhere in a file, that file is not touched at all. A half-patched bundle is worse than an unpatched one.

Reading the log scan

localMs is the time billion-context spends rebuilding the request before it dials out. It is pure local cost and it does not shrink with a faster network. Measured on this machine: p50 3250 ms, p90 7693 ms, p99 12923 ms, max 16524 ms. If bili_latency_probe reports a fast first token while localMs sits in the seconds, the cost is request rebuilding, not the model.

compression (inbound bytes ÷ outbound bytes) tells you whether the proxy is doing its job at all. 53× here means it is.

Install

This plugin is packaged, not installed. To use it on a machine:

dsh plugin --profile desktop add file:/absolute/path/to/dsh-bili-probe

Then add the package name to dsh.profile.bundles in that profile's package.json and restart DSH.

Dependency resolution

@deepseek-ai/schemastery and @deepseek-ai/dsh-tools are peer dependencies, not bundled ones — the host already has both, and shipping a second copy would give the tool registry two different defineTool identities. Node resolves them by walking up from lib/index.js, so an in-tree install at <profiles>\<name>\node_modules\dsh-bili-probe\ finds schemastery in its own node_modules and dsh-tools one level higher, in <profiles>\node_modules\. Verified by building that exact directory shape as a temporary junction tree and importing the real entry point.

Two contract details that are easy to get wrong

  • Every type: 'object' inside an output.schema needs an explicit additionalProperties. Omitting it makes defineTool throw JsonSchemaError: schema.properties.<name>.additionalProperties must be explicitly true or false — at registration time, so the whole plugin fails to load.
  • import { apply } from './kernel.js' collides with export function apply(ctx, config), the host entry point. node --check reports SyntaxError: Identifier 'apply' has already been declared. Alias the import (apply as applyPatches).

Requirements

  • DSH >=0.2.1-rc.1 <0.3.0
  • billion-context installed in the profile
  • Node 18+ for node:fetch (used only by the latency probe)

Related plugins