The philosophy of DeepSeek Harness (DSH) is “everything is a plugin.” When using the zhixiaohang provider, users typically face two specific issues: first, high-frequency requests easily trigger rate limiting; second, when accessing from off-campus, the massive HTML or base64 data returned by the gateway pollutes the model context and logs.
dsh-zhixiaohang-guard is a host plugin designed to solve these two problems: it applies a 10 RPM sliding window throttle exclusively to the zhixiaohang provider, and intercepts off-campus garbled data at the request entry point, replacing it with a short notice. It has zero impact on other providers (such as deepseek-account).
Core Features¶
The plugin primarily includes the following verified features:
- Zhixiaohang-specific 10 RPM Throttling: Uses a sliding window algorithm to rate limit only
provider = zhixiaohang(falling back to hosttoken.nuaa.edu.cn), allowing zero-latency pass-through for other providers. - Off-campus Garbled Input Blocking: When accessing from off-campus, the full-page HTML or base64 returned by the gateway is replaced with a short notice (<200 characters) before being written to disk. The original text does not enter session records, model context, or logs.
- Blank Stream Identification and Retry: Identifies blank streams and classifies them as insufficient upstream capacity (429), triggering automatic retries or a notice after retry, rather than a simple connection interruption.
- Self-check and Observability: Provides a status file (
status.json) and a read-only status page (/api/status) to confirm whether the plugin is loaded correctly and its working status. - Forced IPv4 Support: Modifies the
undiciglobal dispatcher to force specific hosts to use the IPv4 link (v1.3.0). - Fix for 429 retry_after_seconds: Fixes the issue where the
retry_after_secondsfield returned by the gateway was not being populated intofailure.providerRetryAfterMs.
Observability¶
Since the host main process logs are not written to disk, and the dsh --dump-config command is rejected, it is impossible to directly view plugin loading records from the outside. Therefore, the plugin provides two self-check signals:
- Status File: Written to
<DSH_HOME>/zhixiaohang-guard/status.json(default path) upon mounting. IncludesmountedAt,pid,module(load path),listeners(hook registration status),selfTest(self-test results), andstats(counters). - Read-only Status Page: Access
http://127.0.0.1:19387/zhixiaohang-guard/api/statusto obtain status information in JSON format.
Criteria for determining if the plugin is active:
* The status file exists, and selfTest.ok === true, listeners['llm/stream'] === true, listeners['agent/request-error'] === true.
* module points to index.mjs within the plugin directory, not a workspace copy.
Technical Implementation Details¶
Mount Point Selection¶
The plugin mounts on the llm/stream hook. This is because when the agent/request-error hook is triggered, the finish fragment has already been recorded verbatim into the compact stream (assistant-stream); at this point, modifying the message cannot intercept the disk write. It is necessary to intercept and rewrite finish.reason.failure at llm/stream.
Blank Stream Handling¶
A blank stream is essentially another manifestation of insufficient gateway upstream capacity. The plugin distinguishes between “insufficient capacity” (429) and “stream cut off” (no finish reason) by parsing the retry_after_seconds field:
* Insufficient Capacity: Rewritten as a RATE_LIMIT code and passed to the retry plugin.
* Stream Cut Off: Automatically resends once; if it fails, displays a neutral notice.
Forced IPv4¶
By replacing the Symbol.for('undici.globalDispatcher.1') global dispatcher, it sets connect.family = 4 for specific hosts. The mechanism has been verified to be effective, but in the current network environment, getaddrinfo returns only IPv4 for zhixiaohang, so this feature may currently be a harmless no-op.
Configuration¶
Configuration is written into the config field of cordis.patch.yml. All parameters have default values.
- insert:
- id: zhixiaohang-guard
name: 'file:///C:/Users/<your_username>/.dsh/plugins/zhixiaohang-guard/index.mjs'
config:
pace: true
rpm: 10
windowMs: 60000
providers: [zhixiaohang]
hosts: [token.nuaa.edu.cn]
sanitize: true
notice: '⚠️ Zhixiaohang: Currently not on the campus network/VPN, access refused by internal system. Please connect to campus VPN and try again. Service Hotline (025)84890123'
reminderKeys: [仅限校内访问, 校内访问, 综合服务门户, 校园网]
weakReminderKeys: [VPN, vpn, 校外]
weakKeysRequireCorroboration: true
maxNoticeChars: 200
offCampusCode: ZHIXIAOHANG_OFF_CAMPUS
maxWaiters: 512
emptyStreamRetries: 1
emptyStreamBackoffMs: 1500
emptyStreamNotice: '⚠️ Zhixiaohang: Gateway streaming response interrupted (no finish reason returned), automatic retry failed to recover. If this persists, please try again later; if off-campus, please connect to campus VPN first.'
emptyStreamAsRateLimit: true
capacityHintTtlMs: 180000
honorRetryAfterSeconds: true
precheck: false
precheckTtlMs: 60000
forceIpv4: true
forceIpv4Hosts: [token.nuaa.edu.cn]
forceIpv4Mode: auto
forceIpv4Probe: true
Installation and Verification¶
This plugin is pure JS, zero-dependency, and a single-file ESM (index.mjs). For installation instructions, please refer to the plugin directory page:
GitHub: https://github.com/2277533612/dsh-zhixiaohang-guard
After installation, verify activation by accessing the status page or checking the status file.