Introduction¶
At the bottom of the DeepSeek Harness (DSH) composer, the context-usage ring sits in the same row as the session stats capsule, reflecting the current session’s contextPressure projection. When a model call fails due to rate limiting, timeout, or transport errors and is automatically retried by @deepseek-ai/dsh-llm-retry, the host may still receive an “all-zero” usage chunk. The projection treats this as the latest sample, causing the ring to briefly display 0%, even though the context has not been cleared. Meanwhile, due to a 1px font size difference between the meter trigger and StatsPills in the bundled stylesheet, the percentage on the ring is slightly larger than the numbers in the same row, making it visually resemble a different font. Below, we introduce the community plugin dsh-context-usage-guard (maintainer icrefin), which applies minimal patches on both the host and browser sides without adding burdens beyond new pages or persistent configuration.
What is this¶
dsh-context-usage-guard is a client-side Cordis plugin for DSH 0.2.0-rc.2 (npm package name dsh-context-usage-guard, current release version v0.2.0, MIT License). It fixes two issues with the composer’s Context Usage Ring: during retry storms, the ring is no longer forced to 0% by empty usage samples; and the font size of the percentage on the ring matches other numbers in the footer. The plugin does not replace the meter component, does not modify the projection registry, and does not fabricate usage numbers.
Two Symptoms and Fix Strategies¶
Ring Collapses to 0% During Retries¶
The ring renders the session projection contextPressure, where:
pressureTokens = usage.inputTokens + cacheReadTokens + cacheWriteTokens
projectedTokens = max(0, pressureTokens + surfaceTokens - sampledSurfaceTokens)
When a provider does not report valid metrics, a failed attempt may still end with a stream like this (example: RATE_LIMIT):
[ { "type": "chunk", "chunk": { "type": "usage", "usage": { "inputTokens": 0, "outputTokens": 0, "totalTokens": 0 } } },
{ "type": "chunk", "chunk": { "type": "finish", "reason": { "kind": "error",
"failure": { "code": "RATE_LIMIT", "message": "429: token_capacity_exceeded" } } } } ]
This sample has all-zero counts but is treated as the “latest sample.” Without protection, both pressureTokens and projectedTokens become 0, and the ring displays 0%. The README comparison against real session replays (test/fold.spec.ts) shows: the ring is 6% after the last successful call; it becomes 0% without interception of the failed attempt, but remains 6% with interception.
Percentage is 1px Larger Than Numbers in the Same Row¶
The StatsPills in @deepseek-ai/dsh-client-ui-chat and the ContextMeter trigger in @deepseek-ai/dsh-client-ui-conversation handle the secondary font size with a 1px difference (the former uses calc(... - 1px), while the latter uses the variable directly). Consequently, the 30% on the ring appears approximately 8% larger than 182 steps, Cache hit 94%, etc. (approx. 13px vs 12px cap height).
Core Functions¶
The plugin consists of two halves, neither of which adds routes, settings pages, or files on disk (configuration is via the config field in the Cordis patch only):
| Half | Location | Function |
|---|---|---|
| Host | llm/stream waterfall |
Listen to the chunk stream; withhold usage samples that belong to error / aborted endings and have all-zero counts, allowing the projection to retain the last real reading |
| Browser | Document head |
Inject a self-marked style to make the meter percentage the same font size as the stats pills |
The host side declares inject: ['llm'], registering a listener in ctx.effect, which is cleaned up by cordis when unloading or closing the config line. Key rules:
- Usage reported by successful completions (
stop,tool-calls,max-tokens, etc.) passes through as-is, even if zero; - Partial calls that fail but already have non-zero counts are not discarded;
- Stream order and terminating
finishchunks remain unchanged; only that specific usage chunk may be withheld.
The browser side uses structural selectors (not relying on content-hashed class names):
button[aria-haspopup="dialog"]:has(> svg > circle) {
font-size: calc(var(--dsh-content-font-size-secondary,13px) - 1px);
}
If upstream unifies the font size, test/meter-typography.spec.ts in the repository will fail, and this workaround should be removed at that time.
Environment Requirements¶
| Requirement | Version |
|---|---|
| DeepSeek Harness | 0.2.0-rc.2 |
| Node.js | >=22.17.0 |
| Peer Dependencies | @deepseek-ai/cordis ^4.0.1, @deepseek-ai/dsh-llm 0.2.0-rc.2, @deepseek-ai/schemastery ^3.18.3 |
Build artifacts are committed in lib/, so installing the plugin itself does not require running pnpm build on the target machine.
Installation and Activation¶
The installation steps provided in the official README are as follows. First, clone the repository and run the installation script; the script will generate a tarball and print the path:
git clone https://github.com/icrefin/dsh-context-usage-guard.git
cd dsh-context-usage-guard
sh scripts/install.sh
scripts/install.sh will output dist/dsh-context-usage-guard-0.2.0.tgz. Desktop profiles are owned by the Electron app and cannot use dsh plugin add for that profile; you should install this tarball in Settings → Plugins (or use a plugin manager tool) and then restart the harness. When installing into a bundle of a running profile, the current process cannot import it; the browser side also requires a page refresh.
Operationally, note that pnpm may reuse the extracted package when reinstalling the same version number. To force an update of the tarball, remove the bundle before installing or bump the version. The host-side listener is loaded at process startup; subsequent changes to only the client bundle allow hot-updating the browser half, but host-side changes require a restart to take effect.
Uninstallation: Remove the bundle from Settings → Plugins and restart; the plugin does not write additional persistent state.
Configuration¶
Write the following into the config of the corresponding plugin line in the profile’s cordis.patch.yml:
- id: dsh-context-usage-guard
config:
enabled: true
logHeldSamples: false
| Field | Type | Default | Meaning |
|---|---|---|---|
enabled |
boolean | true |
When false, all streams pass through as-is |
logHeldSamples |
boolean | false |
When true, each withholding of an empty sample logs to the host (including route and failure code) |
Both items are volatile and take effect on the next request without needing to reload the profile.
Typical Usage and Verification¶
In daily use, no extra operation is needed: when enabled: true, the ring should maintain the percentage from before the failure during scenarios like rate limit retries, rather than displaying 0% for a long time. To confirm if the host side is intercepting, set logHeldSamples to true. The log example format is:
[dsh-context-usage-guard] held an empty usage sample from a failed request
(example-provider/example-model-v1, RATE_LIMIT); the context reading stays at its last value
Developers can run self-checks within the repository (requires pnpm, for developing this plugin only):
pnpm install
pnpm check
pnpm check performs TypeScript checks on both the host and client halves and runs 5 suites with a total of 40 tests.
Use Cases and Notes¶
Suitable for developers who rely on the context usage ring in the DSH composer to judge “whether the window limit is being approached”: especially in long sessions with frequent retries (429, timeouts, etc.), it avoids misinterpreting 0% and performing unnecessary compression or starting new conversations.
Be aware of the following:
- The plugin runs with the current DSH process permissions. Before installation, please read the GitHub Source and the MIT License to assess the trust boundary yourself.
- The host side only covers calls via the LLM Service
llm/stream; paths that bypass this service to connect directly to providers are not affected by this plugin. - The browser-side font size fix is a workaround existing due to upstream declaration differences; it should be deleted after upstream merges the fix.
- If the ring is still
0%, first checkenabled; usage reported by successful completions with all zeros by the provider will not be intercepted—that is the bundled semantics, not a guard failure.
The plugin will not freeze the reading: after the next successful call reports real usage, the ring will advance normally; it will not display a fabricated percentage when there is no measurable data (the ring remains hidden when there is no data, consistent with bundled behavior).
Conclusion¶
dsh-context-usage-guard uses one stream filter rule and one CSS declaration to stabilize the context reading during retries and align the footer typography, respectively. The DSH ecosystem emphasizes “everything is a plugin”; the community directory SkillHub Plugin Page and the GitHub repository are maintained by the community and have no official affiliation with DeepSeek / High-Flyer. Source code, Issues, and release notes are available at: https://github.com/icrefin/dsh-context-usage-guard.