Introduction¶
After switching to a vision model in DSH, if the session history has accumulated many screenshots or attachments, requests may sometimes be rejected directly at the upstream gateway: the error commonly contains messages like “at most N images per request”. The dsh-llm-pi-ai adapter budgets by base64 size by default (maxRequestImageBytes, commonly defaulting to 20 MiB) rather than rate-limiting by count, so it can happen that “the total bytes are still within budget, but the number of images has already exceeded the gateway’s hard limit”. The official dsh-compaction-image-offload mainly recognizes IMAGE_OFFLOAD_REQUIRED and is often of little help for INVALID_REQUEST-style count errors, so the session gradually deadlocks — sending “continue” again will fail at every step.
The following introduces the community plugin dsh-image-count-guard (maintainer: MacilyDots, category: workflow): when the gateway rejects a request by image count, it offloads the oldest images as placeholder text and retries, reusing the official image/offload projection to recover a deadlocked vision-model session as much as possible.
What Is This¶
dsh-image-count-guard is a fallback-style workflow plugin for DeepSeek Harness (npm package name dsh-image-count-guard, version 0.1.0 in the current documentation, MIT license). It hooks into the agent/request-error waterfall: when the failure message matches English phrasing of the “image count limit” kind, it counts the occurrences of images currently in scope that have not yet been omitted, selects the oldest batch according to model request order, writes an image/offload decision, and returns { kind: 'retry' } to retry the step (without consuming the provider’s retry budget).
The division of labor with the official offload plugin is as follows (table from the original documentation):
| Situation | Handled by |
|---|---|
Adapter rejects on its own due to byte budget (IMAGE_OFFLOAD_REQUIRED) |
Official dsh-compaction-image-offload |
Upstream gateway rejects due to image count (e.g. INVALID_REQUEST, etc.) |
This plugin |
Both write the same kind of image/offload event; semantics and behavior regarding placeholders, replay, tokens, and KV cache are consistent with the official offload. This plugin does not depend on the registration order of the official handler; it only requires that the image/offload projection has been registered.
The Specific Problem It Solves¶
The documentation uses OpenCode Go as an example: the gateway’s hard limit per request is 20 images. Yet when dsh-llm-pi-ai only budgets by base64 bytes, the following can happen:
- Images keep accumulating in the session history (one measured example in the documentation: 36 images, about 11.79 MiB originally, about 15.72 MiB in base64);
- After switching to a vision model (e.g.
opencode-go/deepseek-v4.1-flash), 15.72 MiB is still below the default 20 MiB budget, so the adapter considers it sendable and sends all 36 images inline; - The gateway returns
400 INVALID_REQUEST:a request may include at most 20 images; - The official image-offload does not recognize this error → the step fails;
- From then on every step of that session fails, and the session is completely deadlocked.
Upon matching the count-limit wording, this plugin offloads max(1, total - (limit - safetyMargin)) oldest occurrence positions (total is the number of currently non-omitted image occurrences). Each retry omits at least one position, so the recovery process terminates: either the request passes, or there are no more images to offload and the original failure remains a terminal state (no infinite retries).
The error text match requires containing both image and a quantity phrase; patterns listed in the documentation include: at most N images, maximum of N images, no more than N images, up to N images, too many images, etc.
Installation and Activation¶
The installation method comes from the repository README: in the plugin source directory, run the PowerShell installation script (the script manually modifies three places in the profile: dependencies, dsh.profile.bundles, pnpm-lock.yaml, and copies a node_modules copy without running pnpm install; before making changes it backs up to .backup\<timestamp>\, keeping only the latest 5). The DSH home directory is taken from $env:DSH_HOME, otherwise ~\.dsh.
DSH must be restarted after installation.
# Run in the plugin source directory
pwsh -File .\install.ps1 # Install into the desktop profile (default)
pwsh -File .\install.ps1 -Profile web # Install into the specified profile
Uninstallation:
pwsh -File .\install.ps1 -Uninstall
Note: this plugin runs with the permissions of the current DSH process; before installing, please review the GitHub source and LICENSE yourself to confirm they meet your environment and compliance requirements. The DeepSeek Harness ecosystem emphasizes “everything is a plugin”; community directory sites (such as SkillHub) have no official affiliation with DeepSeek / High-Flyer, and this article does not describe the installation source in the tone of an “official app store”.
At the end of installation, install.ps1 prints four static checks: deps / bundles / node_modules / lock.
Optional Configuration¶
No configuration is needed by default. If you need to override, write into the profile’s cordis.patch.yml by id:
- id: image-count-guard
config:
defaultImageLimit: 20 # The assumed limit when the error text does not give a number
safetyMargin: 2 # Margin kept after offloading, to avoid failure again once another image is added
maxOffloadPerRetry: 80 # Maximum number of image occurrences to omit in a single retry
Typical Usage and Verification¶
Recovering a deadlocked session (integration verification)
- Install the plugin and restart DSH;
- Open the previously deadlocked session caused by exceeding the image count limit, and send “continue”;
- When the plugin takes effect, the session should record an
image/offloadevent, and the next request should succeed.
Offline unit tests
Run in the plugin directory:
node --test test/guard.test.mjs
The documentation states there are 11 test cases in total, covering matching, selection, upper bound on convergence rounds, no-side-effect boundaries, etc.
Optional assembly check
After hooking the plugin into a temporary profile, run --dump-config; the output should contain # == dsh-image-count-guard and - id: image-count-guard, and the exit code should be 0.
Diagnostics: image statistics within a session
PowerShell examples (adjust the paths according to your DSH session directory):
# Single session: count, omitted count, original bytes, base64 estimate, average image size
node tools\session-image-report.mjs `
"$env:USERPROFILE\.dsh\sessions\<workspace>\session-<id>\session.v4.jsonl.zstd"
# Scan recent sessions, sorted by image count
node tools\session-image-report.mjs "$env:USERPROFILE\.dsh\sessions" --limit 20
Two sessions in the documentation illustrate that “a byte budget alone cannot align with the count limit”: session-c312057f has 36 images, about 15.72 MiB in base64 (even below the default 20 MiB budget it would still be rejected due to the 20-image limit); session-b15b99cb has 25 images, only about 1.52 MiB in base64. This is exactly the scenario that needs to be handled by count rather than relying solely on maxRequestImageBytes.
Applicable Scenarios and Notes¶
Who it is for
- DSH users who use vision models long-term and have many screenshots/attachments in sessions;
- Cases where the upstream gateway has a hard limit on the number of images per request, while the local adapter still lets them through based on size budget;
- Those who have installed or plan to install the official
dsh-compaction-image-offload(it requires theimage/offloadprojection it registers); if the official plugin is disabled and the projection is not registered, this plugin will catch the failure onappendand hand it back downstream, with no side effects.
Known limitations (from the original documentation)
- Offload is irreversible: omitted images are subsequently presented as placeholder text (including the read-only attachment path), consistent with the official
image/offload; if you need to see the image again, you must ask the model to callread_imageagain. - The error text must be in English and contain both
imageand a quantity phrase; when new gateway phrasing appears, entries need to be added toLIMIT_PATTERNSinsrc/index.js. - After modifying
src/index.js, you must reruninstall.ps1to sync the node_modules copy, otherwise DSH will still load the old code.
Links¶
- Community directory page: https://www.skillhub.cn/plugins/MacilyDots/dsh-image-count-guard
- Source and documentation: https://github.com/MacilyDots/dsh-image-count-guard
When the gateway rejects a request due to image count and the official byte offload cannot recognize the error code, dsh-image-count-guard offloads the oldest images using the same image/offload semantics and retries. It is a fallback plugin in the workflow that specifically fills the “count limit” gap; installation follows install.ps1 in the README, configuration changes go through cordis.patch.yml, and integration testing and diagnostics can be reproduced using the commands above.