Skip to content

server: opt-in auto-reduction of over-budget image histories (DS4_VISION_KEEP_IMAGES) - #1022

Open
nazerim wants to merge 1 commit into
antirez:mainfrom
nazerim:feat/vision-image-budget
Open

server: opt-in auto-reduction of over-budget image histories (DS4_VISION_KEEP_IMAGES)#1022
nazerim wants to merge 1 commit into
antirez:mainfrom
nazerim:feat/vision-image-budget

Conversation

@nazerim

@nazerim nazerim commented Sep 10, 2026

Copy link
Copy Markdown

Supersedes #971 (rebased onto current main as fa0af86; the encode-loop hunk auto-merged with 81a7658, only the doc moved from README to docs/SERVER.md).

Why. Coding agents that screenshot per tool round accumulate image histories past the 16-image default and get hard 400s at exactly the moments the context matters most. Dropping the oldest images is what the model's own context window would do anyway - but that's a lossy policy change, so it stays strictly opt-in: unset env = today's reject-400 behavior verbatim (with an error message that now hints at the knob).

What. DS4_VISION_KEEP_IMAGES=N (1..1024, validated once; invalid values log a warning and fall back to reject): keep the last N images, splice a fixed visible note over each dropped sentinel in the prompt text so the transcript stays coherent ([oldest image omitted to fit the vision budget]), and serve. Cache identity is unaffected (markers are canonicalized, and the reduction is deterministic for a given history length, so disk tiers key consistently).

Validation (this head): clean optimized build, ds4-server unit suite green; live on M5 Max: keep=16 with a 20-image request served with kept 16 / omitted 4, invalid env value warned and rejected, 17 rejected by default with the hint, keep=2 worked, and the production session ran 128-image-budget turns for a week (130 -> kept 128 / omitted 2 on the largest replay).

Agent loops that attach a screenshot per tool round accumulate images
without bound and today hard-fail past the limit. Dropping older images
is intentionally lossy API policy, so this is opt-in: with the
environment variable DS4_VISION_KEEP_IMAGES=N (1 <= N <= 1024) set at
server start, a request whose history carries more than N images is
served by keeping the last N (the freshest views matter most to the
agent) and replacing each dropped image sentinel in the rendered
transcript with a fixed text note, so the model still sees an honest
history, marker/span counts stay consistent for the vision sync, and
the reduced text remains a deterministic cache key. Unset preserves
current behavior exactly: requests over 16 images are rejected, and the
error message now names the opt-in. A 1024 hard guard still fails absurd
requests before any work. Sliding-window note: as the keep-window
advances, the newly omitted image's text changes, invalidating cached
prefixes only back to the previous retained image.
nazerim added a commit to nazerim/ds4 that referenced this pull request Sep 10, 2026
 on rebased heads), 1M soak watchlist, bridge-tagger removal candidate
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