Repository navigation
fix(coderd/x/chatd): reject damaged and animated images in view_image, and document it - #310
Conversation
The tool reads a PNG, JPEG, GIF or WebP file from the workspace and returns it to the model as an image tool result. It detects the type by content, checks the per-provider size limit and the 8000 pixel side limit, and fails with the model and provider named when the route accepts no image input. Part of #250.
limitViewedImages keeps the newest view_image results as images, at most 8 of them, 20 images in the prompt and 10 MiB of media, and turns older ones into a text note. The stored conversation keeps every image. A compaction override model gets the same bound with its own size limit. Part of #250.
…, and document it view_image checks the structure of the whole file, decodes PNG, JPEG and GIF pixels one at a time under a 25 megapixel cap, rejects animated GIFs and runs at most 8 times per response. docs/fork/pstack-adapter.md and the chatd architecture notes describe the tool, its limits and the experiment. Closes #250.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 823c46480a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # coderd/apidoc/docs.go # coderd/apidoc/swagger.json # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_tools.go # coderd/x/chatd/fork_view_image.go # coderd/x/chatd/fork_view_image_internal_test.go # codersdk/fork_experiments.go # docs/reference/api/schemas.md # site/src/api/typesGenerated.ts
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Merged as 3a79dd3 (squash) at 07:18Z. Before the merge, the server was confirmed on the previous deploy, 667f057. Gates on head 27d7546:
Not exercised:
This closes #250. |
Closes #250
Last PR of a three-PR stack that replaces #284. #308 and #309 are merged, and this PR is now based on
main. Head 27d7546 mergesmain667f057 with a merge commit. In the conflicted files I tookmain's version, which holds the squashed #308 and #309, and reapplied this PR's own diff on top.Two changes from the merge:
coderd/x/chatd/ARCHITECTURE.mdkeepsmain's "Chat notes (fork-token-budget)" bullet and adds "Viewing images" after it.docs/fork/pstack-adapter.mdpoints tofork_tools.go:122-124for the view_image append. The token budget work moved it from lines 119-121.Declined review findings worth doing later are collected in #291.
What
View_image checks more than the header, limits its calls per response, and the docs describe the feature.
imageCompletewalks the PNG chunks and their CRCs up toIEND, requires a JPEG end marker after the last scan, a GIF trailer, and WebP chunks that fit the RIFF size and the file, with a VP8, VP8L or ANMF image chunk. A VP8 chunk must hold the first partition its frame tag names. A truncated or damaged file, such as a screenshot still being written, fails with... is not a valid image/png image: ..., so a broken image never gets stored and replayed.imageDecodesfully decodes a PNG, a JPEG or the first GIF frame with the stdlib decoders, so damaged image data behind an intact structure fails too, for example a PNG with noIDAT. A total of 25,000,000 pixels (viewImageMaxPixels) bounds the memory of one decode to about 200 MB, andviewImageDecodeSlotruns one decode at a time.... is an animated GIF with N frames, and view_image accepts only still images, because OpenAI rejects them.gifFrameswalks the GIF blocks without decoding the frames.view_imagecalls per model response.buildTurnEnvironmentbuilds the tools for each step, so a counter in the tool value counts one response's calls, which chatloop runs concurrently. The ninth and later fail withview_image runs at most 8 times per response.Docs
docs/fork/pstack-adapter.md: a Tools table row, a "View images" section with the limits, errors, the openai-compat, OpenRouter and Vercel gap, the prompt bound and access, thereadonlyandReadnotes, the worktree path list, and source references. The line references match this head.coderd/x/chatd/ARCHITECTURE.md:view_imagein the list of fork tools and a "Viewing images" bullet. The repository rule says agents leave TODOs there for the human author. The lead asked this workstream to write the update itself and leave no TODOs.Size
373 added and 3 removed lines, of which 105 are tests and 53 are docs. No generated files.
Tests
TestViewImageTool/InvalidImages: cut PNG, bad PNG CRC, cut JPEG, GIF and WebP, a WebP chunk past the file end, a VP8 chunk shorter than its first partition, a WebP with no image chunk, a PNG with onlyIHDRandIEND, and a JPEG and a GIF with damaged data and a restored end marker.TestViewImageTool/DimensionLimit: the total-pixel limit.TestViewImageTool/AnimatedGIFand/CallsPerResponse.imageDecodes, the frame check or the call counter disabled,TestViewImageTool/InvalidImages,/AnimatedGIFand/CallsPerResponsefail. With the chunk walk removed,/InvalidImagesfails.Commands run, all under
flock ~/.fork-go.lock:go test ./coderd/x/chatd/ -run 'TestViewImage|TestLimitViewedImages|ForkTools|TestForkWorktreeBinding|AgentToolPolicy|CustomAgent|MediaSanitize|ReplaceUnsupportedMedia|DynamicTool|CompactionModelOverride|ChatNotes|TokenBudget' -count=1 -v: passgo test ./codersdk -run 'TestExperimentDisplayNames|TestForkExperiments': passgo vet ./coderd/x/chatd/andgolangci-lint run --fix=false --config=.golangci.new-code.yaml --new-from-merge-base=origin/main ./coderd/x/chatd/: 0 issuesmake lint/emdashand markdownlint ondocs/fork/pstack-adapter.md: passThe PR is based on
main, so fork-ci runs on this head.Not verified
fork-view-imagefor the tool to appear.